From fab4ca2a18f89c44fc54a90b65b23e1c5a8fbe1b Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Wed, 22 Feb 2017 07:19:42 -0800 Subject: [PATCH 01/18] Fix flow type-parameter-declaration test with unintended semantic (#361) --- .../default/actual.js | 8 +- .../default/expected.json | 1597 +++++++++-------- 2 files changed, 847 insertions(+), 758 deletions(-) diff --git a/test/fixtures/flow/type-parameter-declaration/default/actual.js b/test/fixtures/flow/type-parameter-declaration/default/actual.js index a894895809..faa1bc88ae 100644 --- a/test/fixtures/flow/type-parameter-declaration/default/actual.js +++ b/test/fixtures/flow/type-parameter-declaration/default/actual.js @@ -7,10 +7,10 @@ class A {} class A {} class A {} class A {} -(class A {}) -(class A {}) -(class A {}) -(class A {}) +;(class A {}) +;(class A {}) +;(class A {}) +;(class A {}) declare class A {} declare class A {} declare class A {} diff --git a/test/fixtures/flow/type-parameter-declaration/default/expected.json b/test/fixtures/flow/type-parameter-declaration/default/expected.json index 32f556fd7e..65e1d32891 100644 --- a/test/fixtures/flow/type-parameter-declaration/default/expected.json +++ b/test/fixtures/flow/type-parameter-declaration/default/expected.json @@ -1,7 +1,7 @@ { "type": "File", "start": 0, - "end": 764, + "end": 768, "loc": { "start": { "line": 1, @@ -15,7 +15,7 @@ "program": { "type": "Program", "start": 0, - "end": 764, + "end": 768, "loc": { "start": { "line": 1, @@ -54,7 +54,8 @@ "end": { "line": 1, "column": 6 - } + }, + "identifierName": "A" }, "name": "A" }, @@ -88,6 +89,7 @@ } }, "name": "T", + "variance": null, "default": { "type": "StringTypeAnnotation", "start": 11, @@ -133,7 +135,8 @@ "end": { "line": 1, "column": 22 - } + }, + "identifierName": "T" }, "name": "T" } @@ -165,7 +168,8 @@ "end": { "line": 2, "column": 6 - } + }, + "identifierName": "A" }, "name": "A" }, @@ -199,6 +203,7 @@ } }, "name": "T", + "variance": null, "default": { "type": "ExistentialTypeParam", "start": 34, @@ -244,7 +249,8 @@ "end": { "line": 2, "column": 17 - } + }, + "identifierName": "T" }, "name": "T" } @@ -276,7 +282,8 @@ "end": { "line": 3, "column": 6 - } + }, + "identifierName": "A" }, "name": "A" }, @@ -310,6 +317,7 @@ } }, "name": "T", + "variance": null, "bound": { "type": "TypeAnnotation", "start": 49, @@ -400,7 +408,8 @@ "end": { "line": 3, "column": 31 - } + }, + "identifierName": "T" }, "name": "T" } @@ -432,7 +441,8 @@ "end": { "line": 4, "column": 6 - } + }, + "identifierName": "A" }, "name": "A" }, @@ -465,7 +475,8 @@ "column": 8 } }, - "name": "S" + "name": "S", + "variance": null }, { "type": "TypeParameter", @@ -482,6 +493,7 @@ } }, "name": "T", + "variance": null, "bound": { "type": "TypeAnnotation", "start": 84, @@ -572,7 +584,8 @@ "end": { "line": 4, "column": 34 - } + }, + "identifierName": "T" }, "name": "T" } @@ -604,7 +617,8 @@ "end": { "line": 5, "column": 6 - } + }, + "identifierName": "A" }, "name": "A" }, @@ -638,6 +652,7 @@ } }, "name": "S", + "variance": null, "default": { "type": "NumberTypeAnnotation", "start": 119, @@ -669,6 +684,7 @@ } }, "name": "T", + "variance": null, "bound": { "type": "TypeAnnotation", "start": 128, @@ -759,7 +775,8 @@ "end": { "line": 5, "column": 43 - } + }, + "identifierName": "T" }, "name": "T" } @@ -791,7 +808,8 @@ "end": { "line": 6, "column": 7 - } + }, + "identifierName": "A" }, "name": "A" }, @@ -825,6 +843,7 @@ } }, "name": "T", + "variance": null, "default": { "type": "StringTypeAnnotation", "start": 164, @@ -887,7 +906,8 @@ "end": { "line": 7, "column": 7 - } + }, + "identifierName": "A" }, "name": "A" }, @@ -921,6 +941,7 @@ } }, "name": "T", + "variance": null, "bound": { "type": "TypeAnnotation", "start": 184, @@ -1028,7 +1049,8 @@ "end": { "line": 8, "column": 7 - } + }, + "identifierName": "A" }, "name": "A" }, @@ -1061,7 +1083,8 @@ "column": 9 } }, - "name": "S" + "name": "S", + "variance": null }, { "type": "TypeParameter", @@ -1078,6 +1101,7 @@ } }, "name": "T", + "variance": null, "bound": { "type": "TypeAnnotation", "start": 219, @@ -1185,7 +1209,8 @@ "end": { "line": 9, "column": 7 - } + }, + "identifierName": "A" }, "name": "A" }, @@ -1219,6 +1244,7 @@ } }, "name": "S", + "variance": null, "default": { "type": "NumberTypeAnnotation", "start": 254, @@ -1250,6 +1276,7 @@ } }, "name": "T", + "variance": null, "bound": { "type": "TypeAnnotation", "start": 263, @@ -1332,645 +1359,676 @@ } }, { - "type": "ExpressionStatement", + "type": "EmptyStatement", "start": 286, - "end": 427, + "end": 287, "loc": { "start": { "line": 10, "column": 0 }, "end": { - "line": 13, - "column": 45 + "line": 10, + "column": 1 + } + } + }, + { + "type": "ExpressionStatement", + "start": 287, + "end": 313, + "loc": { + "start": { + "line": 10, + "column": 1 + }, + "end": { + "line": 11, + "column": 1 } }, "expression": { - "type": "CallExpression", - "start": 286, - "end": 427, + "type": "ClassExpression", + "start": 288, + "end": 310, "loc": { "start": { "line": 10, - "column": 0 + "column": 2 }, "end": { - "line": 13, - "column": 45 + "line": 10, + "column": 24 } }, - "callee": { - "type": "CallExpression", - "start": 286, - "end": 381, + "id": { + "type": "Identifier", + "start": 294, + "end": 295, "loc": { "start": { "line": 10, - "column": 0 + "column": 8 + }, + "end": { + "line": 10, + "column": 9 + }, + "identifierName": "A" + }, + "name": "A" + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 295, + "end": 307, + "loc": { + "start": { + "line": 10, + "column": 9 + }, + "end": { + "line": 10, + "column": 21 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 296, + "end": 306, + "loc": { + "start": { + "line": 10, + "column": 10 + }, + "end": { + "line": 10, + "column": 20 + } + }, + "name": "T", + "variance": null, + "default": { + "type": "StringTypeAnnotation", + "start": 300, + "end": 306, + "loc": { + "start": { + "line": 10, + "column": 14 + }, + "end": { + "line": 10, + "column": 20 + } + } + } + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 308, + "end": 310, + "loc": { + "start": { + "line": 10, + "column": 22 + }, + "end": { + "line": 10, + "column": 24 + } + }, + "body": [] + }, + "extra": { + "parenthesized": true, + "parenStart": 287 + } + } + }, + { + "type": "ExpressionStatement", + "start": 313, + "end": 348, + "loc": { + "start": { + "line": 11, + "column": 1 + }, + "end": { + "line": 12, + "column": 1 + } + }, + "expression": { + "type": "ClassExpression", + "start": 314, + "end": 345, + "loc": { + "start": { + "line": 11, + "column": 2 + }, + "end": { + "line": 11, + "column": 33 + } + }, + "id": { + "type": "Identifier", + "start": 320, + "end": 321, + "loc": { + "start": { + "line": 11, + "column": 8 + }, + "end": { + "line": 11, + "column": 9 + }, + "identifierName": "A" + }, + "name": "A" + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 321, + "end": 342, + "loc": { + "start": { + "line": 11, + "column": 9 + }, + "end": { + "line": 11, + "column": 30 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 322, + "end": 341, + "loc": { + "start": { + "line": 11, + "column": 10 + }, + "end": { + "line": 11, + "column": 29 + } + }, + "name": "T", + "variance": null, + "bound": { + "type": "TypeAnnotation", + "start": 323, + "end": 332, + "loc": { + "start": { + "line": 11, + "column": 11 + }, + "end": { + "line": 11, + "column": 20 + } + }, + "typeAnnotation": { + "type": "NullableTypeAnnotation", + "start": 325, + "end": 332, + "loc": { + "start": { + "line": 11, + "column": 13 + }, + "end": { + "line": 11, + "column": 20 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 326, + "end": 332, + "loc": { + "start": { + "line": 11, + "column": 14 + }, + "end": { + "line": 11, + "column": 20 + } + } + } + } + }, + "default": { + "type": "StringTypeAnnotation", + "start": 335, + "end": 341, + "loc": { + "start": { + "line": 11, + "column": 23 + }, + "end": { + "line": 11, + "column": 29 + } + } + } + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 343, + "end": 345, + "loc": { + "start": { + "line": 11, + "column": 31 + }, + "end": { + "line": 11, + "column": 33 + } + }, + "body": [] + }, + "extra": { + "parenthesized": true, + "parenStart": 313 + } + } + }, + { + "type": "ExpressionStatement", + "start": 348, + "end": 386, + "loc": { + "start": { + "line": 12, + "column": 1 + }, + "end": { + "line": 13, + "column": 1 + } + }, + "expression": { + "type": "ClassExpression", + "start": 349, + "end": 383, + "loc": { + "start": { + "line": 12, + "column": 2 + }, + "end": { + "line": 12, + "column": 36 + } + }, + "id": { + "type": "Identifier", + "start": 355, + "end": 356, + "loc": { + "start": { + "line": 12, + "column": 8 + }, + "end": { + "line": 12, + "column": 9 + }, + "identifierName": "A" + }, + "name": "A" + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 356, + "end": 380, + "loc": { + "start": { + "line": 12, + "column": 9 + }, + "end": { + "line": 12, + "column": 33 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 357, + "end": 358, + "loc": { + "start": { + "line": 12, + "column": 10 + }, + "end": { + "line": 12, + "column": 11 + } + }, + "name": "S", + "variance": null + }, + { + "type": "TypeParameter", + "start": 360, + "end": 379, + "loc": { + "start": { + "line": 12, + "column": 13 + }, + "end": { + "line": 12, + "column": 32 + } + }, + "name": "T", + "variance": null, + "bound": { + "type": "TypeAnnotation", + "start": 361, + "end": 370, + "loc": { + "start": { + "line": 12, + "column": 14 + }, + "end": { + "line": 12, + "column": 23 + } + }, + "typeAnnotation": { + "type": "NullableTypeAnnotation", + "start": 363, + "end": 370, + "loc": { + "start": { + "line": 12, + "column": 16 + }, + "end": { + "line": 12, + "column": 23 + } + }, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start": 364, + "end": 370, + "loc": { + "start": { + "line": 12, + "column": 17 + }, + "end": { + "line": 12, + "column": 23 + } + } + } + } + }, + "default": { + "type": "StringTypeAnnotation", + "start": 373, + "end": 379, + "loc": { + "start": { + "line": 12, + "column": 26 + }, + "end": { + "line": 12, + "column": 32 + } + } + } + } + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 381, + "end": 383, + "loc": { + "start": { + "line": 12, + "column": 34 }, "end": { "line": 12, "column": 36 } }, - "callee": { - "type": "CallExpression", - "start": 286, - "end": 344, - "loc": { - "start": { - "line": 10, - "column": 0 - }, - "end": { - "line": 11, - "column": 33 - } + "body": [] + }, + "extra": { + "parenthesized": true, + "parenStart": 348 + } + } + }, + { + "type": "ExpressionStatement", + "start": 386, + "end": 431, + "loc": { + "start": { + "line": 13, + "column": 1 + }, + "end": { + "line": 13, + "column": 46 + } + }, + "expression": { + "type": "ClassExpression", + "start": 387, + "end": 430, + "loc": { + "start": { + "line": 13, + "column": 2 + }, + "end": { + "line": 13, + "column": 45 + } + }, + "id": { + "type": "Identifier", + "start": 393, + "end": 394, + "loc": { + "start": { + "line": 13, + "column": 8 }, - "callee": { - "type": "ClassExpression", - "start": 287, - "end": 309, + "end": { + "line": 13, + "column": 9 + }, + "identifierName": "A" + }, + "name": "A" + }, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start": 394, + "end": 427, + "loc": { + "start": { + "line": 13, + "column": 9 + }, + "end": { + "line": 13, + "column": 42 + } + }, + "params": [ + { + "type": "TypeParameter", + "start": 395, + "end": 405, "loc": { "start": { - "line": 10, - "column": 1 + "line": 13, + "column": 10 }, "end": { - "line": 10, - "column": 23 + "line": 13, + "column": 20 } }, - "id": { - "type": "Identifier", - "start": 293, - "end": 294, + "name": "S", + "variance": null, + "default": { + "type": "NumberTypeAnnotation", + "start": 399, + "end": 405, "loc": { "start": { - "line": 10, - "column": 7 + "line": 13, + "column": 14 }, "end": { - "line": 10, - "column": 8 - } - }, - "name": "A" - }, - "typeParameters": { - "type": "TypeParameterDeclaration", - "start": 294, - "end": 306, - "loc": { - "start": { - "line": 10, - "column": 8 - }, - "end": { - "line": 10, + "line": 13, "column": 20 } - }, - "params": [ - { - "type": "TypeParameter", - "start": 295, - "end": 305, - "loc": { - "start": { - "line": 10, - "column": 9 - }, - "end": { - "line": 10, - "column": 19 - } - }, - "name": "T", - "default": { - "type": "StringTypeAnnotation", - "start": 299, - "end": 305, - "loc": { - "start": { - "line": 10, - "column": 13 - }, - "end": { - "line": 10, - "column": 19 - } - } - } - } - ] - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start": 307, - "end": 309, - "loc": { - "start": { - "line": 10, - "column": 21 - }, - "end": { - "line": 10, - "column": 23 - } - }, - "body": [] - }, - "extra": { - "parenthesized": true, - "parenStart": 286 - } - }, - "arguments": [ - { - "type": "ClassExpression", - "start": 312, - "end": 343, - "loc": { - "start": { - "line": 11, - "column": 1 - }, - "end": { - "line": 11, - "column": 32 - } - }, - "id": { - "type": "Identifier", - "start": 318, - "end": 319, - "loc": { - "start": { - "line": 11, - "column": 7 - }, - "end": { - "line": 11, - "column": 8 - } - }, - "name": "A" - }, - "typeParameters": { - "type": "TypeParameterDeclaration", - "start": 319, - "end": 340, - "loc": { - "start": { - "line": 11, - "column": 8 - }, - "end": { - "line": 11, - "column": 29 - } - }, - "params": [ - { - "type": "TypeParameter", - "start": 320, - "end": 339, - "loc": { - "start": { - "line": 11, - "column": 9 - }, - "end": { - "line": 11, - "column": 28 - } - }, - "name": "T", - "bound": { - "type": "TypeAnnotation", - "start": 321, - "end": 330, - "loc": { - "start": { - "line": 11, - "column": 10 - }, - "end": { - "line": 11, - "column": 19 - } - }, - "typeAnnotation": { - "type": "NullableTypeAnnotation", - "start": 323, - "end": 330, - "loc": { - "start": { - "line": 11, - "column": 12 - }, - "end": { - "line": 11, - "column": 19 - } - }, - "typeAnnotation": { - "type": "StringTypeAnnotation", - "start": 324, - "end": 330, - "loc": { - "start": { - "line": 11, - "column": 13 - }, - "end": { - "line": 11, - "column": 19 - } - } - } - } - }, - "default": { - "type": "StringTypeAnnotation", - "start": 333, - "end": 339, - "loc": { - "start": { - "line": 11, - "column": 22 - }, - "end": { - "line": 11, - "column": 28 - } - } - } - } - ] - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start": 341, - "end": 343, - "loc": { - "start": { - "line": 11, - "column": 30 - }, - "end": { - "line": 11, - "column": 32 - } - }, - "body": [] } } - ] - }, - "arguments": [ + }, { - "type": "ClassExpression", - "start": 346, - "end": 380, - "loc": { - "start": { - "line": 12, - "column": 1 - }, - "end": { - "line": 12, - "column": 35 - } - }, - "id": { - "type": "Identifier", - "start": 352, - "end": 353, - "loc": { - "start": { - "line": 12, - "column": 7 - }, - "end": { - "line": 12, - "column": 8 - } - }, - "name": "A" - }, - "typeParameters": { - "type": "TypeParameterDeclaration", - "start": 353, - "end": 377, - "loc": { - "start": { - "line": 12, - "column": 8 - }, - "end": { - "line": 12, - "column": 32 - } - }, - "params": [ - { - "type": "TypeParameter", - "start": 354, - "end": 355, - "loc": { - "start": { - "line": 12, - "column": 9 - }, - "end": { - "line": 12, - "column": 10 - } - }, - "name": "S" - }, - { - "type": "TypeParameter", - "start": 357, - "end": 376, - "loc": { - "start": { - "line": 12, - "column": 12 - }, - "end": { - "line": 12, - "column": 31 - } - }, - "name": "T", - "bound": { - "type": "TypeAnnotation", - "start": 358, - "end": 367, - "loc": { - "start": { - "line": 12, - "column": 13 - }, - "end": { - "line": 12, - "column": 22 - } - }, - "typeAnnotation": { - "type": "NullableTypeAnnotation", - "start": 360, - "end": 367, - "loc": { - "start": { - "line": 12, - "column": 15 - }, - "end": { - "line": 12, - "column": 22 - } - }, - "typeAnnotation": { - "type": "StringTypeAnnotation", - "start": 361, - "end": 367, - "loc": { - "start": { - "line": 12, - "column": 16 - }, - "end": { - "line": 12, - "column": 22 - } - } - } - } - }, - "default": { - "type": "StringTypeAnnotation", - "start": 370, - "end": 376, - "loc": { - "start": { - "line": 12, - "column": 25 - }, - "end": { - "line": 12, - "column": 31 - } - } - } - } - ] - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start": 378, - "end": 380, - "loc": { - "start": { - "line": 12, - "column": 33 - }, - "end": { - "line": 12, - "column": 35 - } - }, - "body": [] - } - } - ] - }, - "arguments": [ - { - "type": "ClassExpression", - "start": 383, - "end": 426, - "loc": { - "start": { - "line": 13, - "column": 1 - }, - "end": { - "line": 13, - "column": 44 - } - }, - "id": { - "type": "Identifier", - "start": 389, - "end": 390, + "type": "TypeParameter", + "start": 407, + "end": 426, "loc": { "start": { "line": 13, - "column": 7 - }, - "end": { - "line": 13, - "column": 8 - } - }, - "name": "A" - }, - "typeParameters": { - "type": "TypeParameterDeclaration", - "start": 390, - "end": 423, - "loc": { - "start": { - "line": 13, - "column": 8 + "column": 22 }, "end": { "line": 13, "column": 41 } }, - "params": [ - { - "type": "TypeParameter", - "start": 391, - "end": 401, - "loc": { - "start": { - "line": 13, - "column": 9 - }, - "end": { - "line": 13, - "column": 19 - } + "name": "T", + "variance": null, + "bound": { + "type": "TypeAnnotation", + "start": 408, + "end": 417, + "loc": { + "start": { + "line": 13, + "column": 23 }, - "name": "S", - "default": { - "type": "NumberTypeAnnotation", - "start": 395, - "end": 401, - "loc": { - "start": { - "line": 13, - "column": 13 - }, - "end": { - "line": 13, - "column": 19 - } - } + "end": { + "line": 13, + "column": 32 } }, - { - "type": "TypeParameter", - "start": 403, - "end": 422, + "typeAnnotation": { + "type": "NullableTypeAnnotation", + "start": 410, + "end": 417, "loc": { "start": { "line": 13, - "column": 21 + "column": 25 }, "end": { "line": 13, - "column": 40 + "column": 32 } }, - "name": "T", - "bound": { - "type": "TypeAnnotation", - "start": 404, - "end": 413, - "loc": { - "start": { - "line": 13, - "column": 22 - }, - "end": { - "line": 13, - "column": 31 - } - }, - "typeAnnotation": { - "type": "NullableTypeAnnotation", - "start": 406, - "end": 413, - "loc": { - "start": { - "line": 13, - "column": 24 - }, - "end": { - "line": 13, - "column": 31 - } - }, - "typeAnnotation": { - "type": "StringTypeAnnotation", - "start": 407, - "end": 413, - "loc": { - "start": { - "line": 13, - "column": 25 - }, - "end": { - "line": 13, - "column": 31 - } - } - } - } - }, - "default": { + "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 416, - "end": 422, + "start": 411, + "end": 417, "loc": { "start": { "line": 13, - "column": 34 + "column": 26 }, "end": { "line": 13, - "column": 40 + "column": 32 } } } } - ] - }, - "superClass": null, - "body": { - "type": "ClassBody", - "start": 424, - "end": 426, - "loc": { - "start": { - "line": 13, - "column": 42 - }, - "end": { - "line": 13, - "column": 44 - } }, - "body": [] + "default": { + "type": "StringTypeAnnotation", + "start": 420, + "end": 426, + "loc": { + "start": { + "line": 13, + "column": 35 + }, + "end": { + "line": 13, + "column": 41 + } + } + } } - } - ] + ] + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 428, + "end": 430, + "loc": { + "start": { + "line": 13, + "column": 43 + }, + "end": { + "line": 13, + "column": 45 + } + }, + "body": [] + }, + "extra": { + "parenthesized": true, + "parenStart": 386 + } } }, { "type": "DeclareClass", - "start": 428, - "end": 458, + "start": 432, + "end": 462, "loc": { "start": { "line": 14, @@ -1983,8 +2041,8 @@ }, "id": { "type": "Identifier", - "start": 442, - "end": 443, + "start": 446, + "end": 447, "loc": { "start": { "line": 14, @@ -1993,14 +2051,15 @@ "end": { "line": 14, "column": 15 - } + }, + "identifierName": "A" }, "name": "A" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 443, - "end": 455, + "start": 447, + "end": 459, "loc": { "start": { "line": 14, @@ -2014,8 +2073,8 @@ "params": [ { "type": "TypeParameter", - "start": 444, - "end": 454, + "start": 448, + "end": 458, "loc": { "start": { "line": 14, @@ -2027,10 +2086,11 @@ } }, "name": "T", + "variance": null, "default": { "type": "StringTypeAnnotation", - "start": 448, - "end": 454, + "start": 452, + "end": 458, "loc": { "start": { "line": 14, @@ -2049,8 +2109,8 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 456, - "end": 458, + "start": 460, + "end": 462, "loc": { "start": { "line": 14, @@ -2063,13 +2123,14 @@ }, "callProperties": [], "properties": [], - "indexers": [] + "indexers": [], + "exact": false } }, { "type": "DeclareClass", - "start": 459, - "end": 498, + "start": 463, + "end": 502, "loc": { "start": { "line": 15, @@ -2082,8 +2143,8 @@ }, "id": { "type": "Identifier", - "start": 473, - "end": 474, + "start": 477, + "end": 478, "loc": { "start": { "line": 15, @@ -2092,14 +2153,15 @@ "end": { "line": 15, "column": 15 - } + }, + "identifierName": "A" }, "name": "A" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 474, - "end": 495, + "start": 478, + "end": 499, "loc": { "start": { "line": 15, @@ -2113,8 +2175,8 @@ "params": [ { "type": "TypeParameter", - "start": 475, - "end": 494, + "start": 479, + "end": 498, "loc": { "start": { "line": 15, @@ -2126,10 +2188,11 @@ } }, "name": "T", + "variance": null, "bound": { "type": "TypeAnnotation", - "start": 476, - "end": 485, + "start": 480, + "end": 489, "loc": { "start": { "line": 15, @@ -2142,8 +2205,8 @@ }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 478, - "end": 485, + "start": 482, + "end": 489, "loc": { "start": { "line": 15, @@ -2156,8 +2219,8 @@ }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 479, - "end": 485, + "start": 483, + "end": 489, "loc": { "start": { "line": 15, @@ -2173,8 +2236,8 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 488, - "end": 494, + "start": 492, + "end": 498, "loc": { "start": { "line": 15, @@ -2193,8 +2256,8 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 496, - "end": 498, + "start": 500, + "end": 502, "loc": { "start": { "line": 15, @@ -2207,13 +2270,14 @@ }, "callProperties": [], "properties": [], - "indexers": [] + "indexers": [], + "exact": false } }, { "type": "DeclareClass", - "start": 499, - "end": 541, + "start": 503, + "end": 545, "loc": { "start": { "line": 16, @@ -2226,8 +2290,8 @@ }, "id": { "type": "Identifier", - "start": 513, - "end": 514, + "start": 517, + "end": 518, "loc": { "start": { "line": 16, @@ -2236,14 +2300,15 @@ "end": { "line": 16, "column": 15 - } + }, + "identifierName": "A" }, "name": "A" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 514, - "end": 538, + "start": 518, + "end": 542, "loc": { "start": { "line": 16, @@ -2257,8 +2322,8 @@ "params": [ { "type": "TypeParameter", - "start": 515, - "end": 516, + "start": 519, + "end": 520, "loc": { "start": { "line": 16, @@ -2269,12 +2334,13 @@ "column": 17 } }, - "name": "S" + "name": "S", + "variance": null }, { "type": "TypeParameter", - "start": 518, - "end": 537, + "start": 522, + "end": 541, "loc": { "start": { "line": 16, @@ -2286,10 +2352,11 @@ } }, "name": "T", + "variance": null, "bound": { "type": "TypeAnnotation", - "start": 519, - "end": 528, + "start": 523, + "end": 532, "loc": { "start": { "line": 16, @@ -2302,8 +2369,8 @@ }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 521, - "end": 528, + "start": 525, + "end": 532, "loc": { "start": { "line": 16, @@ -2316,8 +2383,8 @@ }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 522, - "end": 528, + "start": 526, + "end": 532, "loc": { "start": { "line": 16, @@ -2333,8 +2400,8 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 531, - "end": 537, + "start": 535, + "end": 541, "loc": { "start": { "line": 16, @@ -2353,8 +2420,8 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 539, - "end": 541, + "start": 543, + "end": 545, "loc": { "start": { "line": 16, @@ -2367,13 +2434,14 @@ }, "callProperties": [], "properties": [], - "indexers": [] + "indexers": [], + "exact": false } }, { "type": "DeclareClass", - "start": 542, - "end": 593, + "start": 546, + "end": 597, "loc": { "start": { "line": 17, @@ -2386,8 +2454,8 @@ }, "id": { "type": "Identifier", - "start": 556, - "end": 557, + "start": 560, + "end": 561, "loc": { "start": { "line": 17, @@ -2396,14 +2464,15 @@ "end": { "line": 17, "column": 15 - } + }, + "identifierName": "A" }, "name": "A" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 557, - "end": 590, + "start": 561, + "end": 594, "loc": { "start": { "line": 17, @@ -2417,8 +2486,8 @@ "params": [ { "type": "TypeParameter", - "start": 558, - "end": 568, + "start": 562, + "end": 572, "loc": { "start": { "line": 17, @@ -2430,10 +2499,11 @@ } }, "name": "S", + "variance": null, "default": { "type": "NumberTypeAnnotation", - "start": 562, - "end": 568, + "start": 566, + "end": 572, "loc": { "start": { "line": 17, @@ -2448,8 +2518,8 @@ }, { "type": "TypeParameter", - "start": 570, - "end": 589, + "start": 574, + "end": 593, "loc": { "start": { "line": 17, @@ -2461,10 +2531,11 @@ } }, "name": "T", + "variance": null, "bound": { "type": "TypeAnnotation", - "start": 571, - "end": 580, + "start": 575, + "end": 584, "loc": { "start": { "line": 17, @@ -2477,8 +2548,8 @@ }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 573, - "end": 580, + "start": 577, + "end": 584, "loc": { "start": { "line": 17, @@ -2491,8 +2562,8 @@ }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 574, - "end": 580, + "start": 578, + "end": 584, "loc": { "start": { "line": 17, @@ -2508,8 +2579,8 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 583, - "end": 589, + "start": 587, + "end": 593, "loc": { "start": { "line": 17, @@ -2528,8 +2599,8 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 591, - "end": 593, + "start": 595, + "end": 597, "loc": { "start": { "line": 17, @@ -2542,13 +2613,14 @@ }, "callProperties": [], "properties": [], - "indexers": [] + "indexers": [], + "exact": false } }, { "type": "InterfaceDeclaration", - "start": 594, - "end": 620, + "start": 598, + "end": 624, "loc": { "start": { "line": 18, @@ -2561,8 +2633,8 @@ }, "id": { "type": "Identifier", - "start": 604, - "end": 605, + "start": 608, + "end": 609, "loc": { "start": { "line": 18, @@ -2571,14 +2643,15 @@ "end": { "line": 18, "column": 11 - } + }, + "identifierName": "A" }, "name": "A" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 605, - "end": 617, + "start": 609, + "end": 621, "loc": { "start": { "line": 18, @@ -2592,8 +2665,8 @@ "params": [ { "type": "TypeParameter", - "start": 606, - "end": 616, + "start": 610, + "end": 620, "loc": { "start": { "line": 18, @@ -2605,10 +2678,11 @@ } }, "name": "T", + "variance": null, "default": { "type": "StringTypeAnnotation", - "start": 610, - "end": 616, + "start": 614, + "end": 620, "loc": { "start": { "line": 18, @@ -2627,8 +2701,8 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 618, - "end": 620, + "start": 622, + "end": 624, "loc": { "start": { "line": 18, @@ -2641,13 +2715,14 @@ }, "callProperties": [], "properties": [], - "indexers": [] + "indexers": [], + "exact": false } }, { "type": "InterfaceDeclaration", - "start": 621, - "end": 656, + "start": 625, + "end": 660, "loc": { "start": { "line": 19, @@ -2660,8 +2735,8 @@ }, "id": { "type": "Identifier", - "start": 631, - "end": 632, + "start": 635, + "end": 636, "loc": { "start": { "line": 19, @@ -2670,14 +2745,15 @@ "end": { "line": 19, "column": 11 - } + }, + "identifierName": "A" }, "name": "A" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 632, - "end": 653, + "start": 636, + "end": 657, "loc": { "start": { "line": 19, @@ -2691,8 +2767,8 @@ "params": [ { "type": "TypeParameter", - "start": 633, - "end": 652, + "start": 637, + "end": 656, "loc": { "start": { "line": 19, @@ -2704,10 +2780,11 @@ } }, "name": "T", + "variance": null, "bound": { "type": "TypeAnnotation", - "start": 634, - "end": 643, + "start": 638, + "end": 647, "loc": { "start": { "line": 19, @@ -2720,8 +2797,8 @@ }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 636, - "end": 643, + "start": 640, + "end": 647, "loc": { "start": { "line": 19, @@ -2734,8 +2811,8 @@ }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 637, - "end": 643, + "start": 641, + "end": 647, "loc": { "start": { "line": 19, @@ -2751,8 +2828,8 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 646, - "end": 652, + "start": 650, + "end": 656, "loc": { "start": { "line": 19, @@ -2771,8 +2848,8 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 654, - "end": 656, + "start": 658, + "end": 660, "loc": { "start": { "line": 19, @@ -2785,13 +2862,14 @@ }, "callProperties": [], "properties": [], - "indexers": [] + "indexers": [], + "exact": false } }, { "type": "InterfaceDeclaration", - "start": 657, - "end": 695, + "start": 661, + "end": 699, "loc": { "start": { "line": 20, @@ -2804,8 +2882,8 @@ }, "id": { "type": "Identifier", - "start": 667, - "end": 668, + "start": 671, + "end": 672, "loc": { "start": { "line": 20, @@ -2814,14 +2892,15 @@ "end": { "line": 20, "column": 11 - } + }, + "identifierName": "A" }, "name": "A" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 668, - "end": 692, + "start": 672, + "end": 696, "loc": { "start": { "line": 20, @@ -2835,8 +2914,8 @@ "params": [ { "type": "TypeParameter", - "start": 669, - "end": 670, + "start": 673, + "end": 674, "loc": { "start": { "line": 20, @@ -2847,12 +2926,13 @@ "column": 13 } }, - "name": "S" + "name": "S", + "variance": null }, { "type": "TypeParameter", - "start": 672, - "end": 691, + "start": 676, + "end": 695, "loc": { "start": { "line": 20, @@ -2864,10 +2944,11 @@ } }, "name": "T", + "variance": null, "bound": { "type": "TypeAnnotation", - "start": 673, - "end": 682, + "start": 677, + "end": 686, "loc": { "start": { "line": 20, @@ -2880,8 +2961,8 @@ }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 675, - "end": 682, + "start": 679, + "end": 686, "loc": { "start": { "line": 20, @@ -2894,8 +2975,8 @@ }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 676, - "end": 682, + "start": 680, + "end": 686, "loc": { "start": { "line": 20, @@ -2911,8 +2992,8 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 685, - "end": 691, + "start": 689, + "end": 695, "loc": { "start": { "line": 20, @@ -2931,8 +3012,8 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 693, - "end": 695, + "start": 697, + "end": 699, "loc": { "start": { "line": 20, @@ -2945,13 +3026,14 @@ }, "callProperties": [], "properties": [], - "indexers": [] + "indexers": [], + "exact": false } }, { "type": "InterfaceDeclaration", - "start": 696, - "end": 743, + "start": 700, + "end": 747, "loc": { "start": { "line": 21, @@ -2964,8 +3046,8 @@ }, "id": { "type": "Identifier", - "start": 706, - "end": 707, + "start": 710, + "end": 711, "loc": { "start": { "line": 21, @@ -2974,14 +3056,15 @@ "end": { "line": 21, "column": 11 - } + }, + "identifierName": "A" }, "name": "A" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 707, - "end": 740, + "start": 711, + "end": 744, "loc": { "start": { "line": 21, @@ -2995,8 +3078,8 @@ "params": [ { "type": "TypeParameter", - "start": 708, - "end": 718, + "start": 712, + "end": 722, "loc": { "start": { "line": 21, @@ -3008,10 +3091,11 @@ } }, "name": "S", + "variance": null, "default": { "type": "NumberTypeAnnotation", - "start": 712, - "end": 718, + "start": 716, + "end": 722, "loc": { "start": { "line": 21, @@ -3026,8 +3110,8 @@ }, { "type": "TypeParameter", - "start": 720, - "end": 739, + "start": 724, + "end": 743, "loc": { "start": { "line": 21, @@ -3039,10 +3123,11 @@ } }, "name": "T", + "variance": null, "bound": { "type": "TypeAnnotation", - "start": 721, - "end": 730, + "start": 725, + "end": 734, "loc": { "start": { "line": 21, @@ -3055,8 +3140,8 @@ }, "typeAnnotation": { "type": "NullableTypeAnnotation", - "start": 723, - "end": 730, + "start": 727, + "end": 734, "loc": { "start": { "line": 21, @@ -3069,8 +3154,8 @@ }, "typeAnnotation": { "type": "StringTypeAnnotation", - "start": 724, - "end": 730, + "start": 728, + "end": 734, "loc": { "start": { "line": 21, @@ -3086,8 +3171,8 @@ }, "default": { "type": "StringTypeAnnotation", - "start": 733, - "end": 739, + "start": 737, + "end": 743, "loc": { "start": { "line": 21, @@ -3106,8 +3191,8 @@ "mixins": [], "body": { "type": "ObjectTypeAnnotation", - "start": 741, - "end": 743, + "start": 745, + "end": 747, "loc": { "start": { "line": 21, @@ -3120,13 +3205,14 @@ }, "callProperties": [], "properties": [], - "indexers": [] + "indexers": [], + "exact": false } }, { "type": "TypeAlias", - "start": 744, - "end": 764, + "start": 748, + "end": 768, "loc": { "start": { "line": 22, @@ -3139,8 +3225,8 @@ }, "id": { "type": "Identifier", - "start": 749, - "end": 750, + "start": 753, + "end": 754, "loc": { "start": { "line": 22, @@ -3149,14 +3235,15 @@ "end": { "line": 22, "column": 6 - } + }, + "identifierName": "A" }, "name": "A" }, "typeParameters": { "type": "TypeParameterDeclaration", - "start": 750, - "end": 760, + "start": 754, + "end": 764, "loc": { "start": { "line": 22, @@ -3170,8 +3257,8 @@ "params": [ { "type": "TypeParameter", - "start": 751, - "end": 759, + "start": 755, + "end": 763, "loc": { "start": { "line": 22, @@ -3183,10 +3270,11 @@ } }, "name": "T", + "variance": null, "default": { "type": "VoidTypeAnnotation", - "start": 755, - "end": 759, + "start": 759, + "end": 763, "loc": { "start": { "line": 22, @@ -3203,8 +3291,8 @@ }, "right": { "type": "GenericTypeAnnotation", - "start": 763, - "end": 764, + "start": 767, + "end": 768, "loc": { "start": { "line": 22, @@ -3218,8 +3306,8 @@ "typeParameters": null, "id": { "type": "Identifier", - "start": 763, - "end": 764, + "start": 767, + "end": 768, "loc": { "start": { "line": 22, @@ -3228,7 +3316,8 @@ "end": { "line": 22, "column": 20 - } + }, + "identifierName": "T" }, "name": "T" } From 94eda1254ef47facc92bf8d400cdec89e115310d Mon Sep 17 00:00:00 2001 From: Alex Rattray Date: Wed, 22 Feb 2017 07:21:44 -0800 Subject: [PATCH 02/18] Fix generator-method-with-computed-name spec (#360) --- .../actual.js | 2 +- .../expected.json | 197 ++++++++++++++++++ .../options.json | 3 - 3 files changed, 198 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/esprima/es2015-generator/generator-method-with-computed-name/expected.json delete mode 100644 test/fixtures/esprima/es2015-generator/generator-method-with-computed-name/options.json diff --git a/test/fixtures/esprima/es2015-generator/generator-method-with-computed-name/actual.js b/test/fixtures/esprima/es2015-generator/generator-method-with-computed-name/actual.js index 0739904dc1..6dce46a214 100644 --- a/test/fixtures/esprima/es2015-generator/generator-method-with-computed-name/actual.js +++ b/test/fixtures/esprima/es2015-generator/generator-method-with-computed-name/actual.js @@ -1,3 +1,3 @@ (function*() { - { *[yield iter]() {} } + return { *[yield iter]() {} } }) diff --git a/test/fixtures/esprima/es2015-generator/generator-method-with-computed-name/expected.json b/test/fixtures/esprima/es2015-generator/generator-method-with-computed-name/expected.json new file mode 100644 index 0000000000..820bf5831b --- /dev/null +++ b/test/fixtures/esprima/es2015-generator/generator-method-with-computed-name/expected.json @@ -0,0 +1,197 @@ +{ + "type": "File", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "sourceType": "script", + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 51, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 2 + } + }, + "expression": { + "type": "FunctionExpression", + "start": 1, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": null, + "generator": true, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 13, + "end": 50, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 19, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "argument": { + "type": "ObjectExpression", + "start": 26, + "end": 48, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 33 + } + }, + "properties": [ + { + "type": "ObjectMethod", + "start": 28, + "end": 46, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "method": true, + "shorthand": false, + "computed": true, + "key": { + "type": "YieldExpression", + "start": 30, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 25 + } + }, + "delegate": false, + "argument": { + "type": "Identifier", + "start": 36, + "end": 40, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 25 + }, + "identifierName": "iter" + }, + "name": "iter" + } + }, + "kind": "method", + "id": null, + "generator": true, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 44, + "end": 46, + "loc": { + "start": { + "line": 2, + "column": 29 + }, + "end": { + "line": 2, + "column": 31 + } + }, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + }, + "extra": { + "parenthesized": true, + "parenStart": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/esprima/es2015-generator/generator-method-with-computed-name/options.json b/test/fixtures/esprima/es2015-generator/generator-method-with-computed-name/options.json deleted file mode 100644 index f86bbd48e9..0000000000 --- a/test/fixtures/esprima/es2015-generator/generator-method-with-computed-name/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "Unexpected token (2:6)" -} \ No newline at end of file From ad8d520406263340e33c2e153d42e46f4dca23f3 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Wed, 22 Feb 2017 09:22:38 -0600 Subject: [PATCH 03/18] Ensure takeDecorators is called on exported class (#358) --- src/parser/statement.js | 2 +- .../actual.js | 7 + .../expected.json | 240 ++++++++++++++++++ .../options.json | 3 + 4 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/experimental/decorators/export-default-with-nested-class/actual.js create mode 100644 test/fixtures/experimental/decorators/export-default-with-nested-class/expected.json create mode 100644 test/fixtures/experimental/decorators/export-default-with-nested-class/options.json diff --git a/src/parser/statement.js b/src/parser/statement.js index 179be68b76..aa0d6abf66 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -76,7 +76,6 @@ pp.parseStatement = function (declaration, topLevel) { case tt._class: if (!declaration) this.unexpected(); - this.takeDecorators(node); return this.parseClass(node, true); case tt._if: return this.parseIfStatement(node); @@ -618,6 +617,7 @@ pp.parseFunctionParams = function (node) { pp.parseClass = function (node, isStatement, optionalId) { this.next(); + this.takeDecorators(node); this.parseClassId(node, isStatement, optionalId); this.parseClassSuper(node); this.parseClassBody(node); diff --git a/test/fixtures/experimental/decorators/export-default-with-nested-class/actual.js b/test/fixtures/experimental/decorators/export-default-with-nested-class/actual.js new file mode 100644 index 0000000000..d0d8d6c4ec --- /dev/null +++ b/test/fixtures/experimental/decorators/export-default-with-nested-class/actual.js @@ -0,0 +1,7 @@ +@ParentDecorator +export default class ParentClass { + makeNestedClass() { + class NestedClass { + } + } +} diff --git a/test/fixtures/experimental/decorators/export-default-with-nested-class/expected.json b/test/fixtures/experimental/decorators/export-default-with-nested-class/expected.json new file mode 100644 index 0000000000..8fc784a7a3 --- /dev/null +++ b/test/fixtures/experimental/decorators/export-default-with-nested-class/expected.json @@ -0,0 +1,240 @@ +{ + "type": "File", + "start": 0, + "end": 109, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 109, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ExportDefaultDeclaration", + "start": 17, + "end": 109, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "declaration": { + "type": "ClassDeclaration", + "start": 32, + "end": 109, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 38, + "end": 49, + "loc": { + "start": { + "line": 2, + "column": 21 + }, + "end": { + "line": 2, + "column": 32 + }, + "identifierName": "ParentClass" + }, + "name": "ParentClass" + }, + "decorators": [ + { + "type": "Decorator", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "expression": { + "type": "Identifier", + "start": 1, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "ParentDecorator" + }, + "name": "ParentDecorator" + } + } + ], + "superClass": null, + "body": { + "type": "ClassBody", + "start": 50, + "end": 109, + "loc": { + "start": { + "line": 2, + "column": 33 + }, + "end": { + "line": 7, + "column": 1 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 54, + "end": 107, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 54, + "end": 69, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 17 + }, + "identifierName": "makeNestedClass" + }, + "name": "makeNestedClass" + }, + "static": false, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 72, + "end": 107, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 6, + "column": 3 + } + }, + "body": [ + { + "type": "ClassDeclaration", + "start": 78, + "end": 103, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "id": { + "type": "Identifier", + "start": 84, + "end": 95, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 21 + }, + "identifierName": "NestedClass" + }, + "name": "NestedClass" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 96, + "end": 103, + "loc": { + "start": { + "line": 4, + "column": 22 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "body": [] + } + } + ], + "directives": [] + } + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/experimental/decorators/export-default-with-nested-class/options.json b/test/fixtures/experimental/decorators/export-default-with-nested-class/options.json new file mode 100644 index 0000000000..2104ca4328 --- /dev/null +++ b/test/fixtures/experimental/decorators/export-default-with-nested-class/options.json @@ -0,0 +1,3 @@ +{ + "sourceType": "module" +} From 561d4f74b09613c3edfe659d382fac5abab827ba Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Wed, 22 Feb 2017 07:24:40 -0800 Subject: [PATCH 04/18] Forbid semicolons after decorators in classes (#352) --- src/parser/statement.js | 3 +++ test/fixtures/experimental/decorators/no-semi/actual.js | 4 ++++ test/fixtures/experimental/decorators/no-semi/options.json | 3 +++ 3 files changed, 10 insertions(+) create mode 100644 test/fixtures/experimental/decorators/no-semi/actual.js create mode 100644 test/fixtures/experimental/decorators/no-semi/options.json diff --git a/src/parser/statement.js b/src/parser/statement.js index aa0d6abf66..d7073ef1bd 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -648,6 +648,9 @@ pp.parseClassBody = function (node) { while (!this.eat(tt.braceR)) { if (this.eat(tt.semi)) { + if (decorators.length > 0) { + this.raise(this.state.lastTokEnd, "Decorators must not be followed by a semicolon"); + } continue; } diff --git a/test/fixtures/experimental/decorators/no-semi/actual.js b/test/fixtures/experimental/decorators/no-semi/actual.js new file mode 100644 index 0000000000..6138e9c6f9 --- /dev/null +++ b/test/fixtures/experimental/decorators/no-semi/actual.js @@ -0,0 +1,4 @@ +class A { + @a; + m(){} +} diff --git a/test/fixtures/experimental/decorators/no-semi/options.json b/test/fixtures/experimental/decorators/no-semi/options.json new file mode 100644 index 0000000000..ffac21b695 --- /dev/null +++ b/test/fixtures/experimental/decorators/no-semi/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Decorators must not be followed by a semicolon (2:5)" +} From c6c4222789ec36cad1e6a17cf7a29a49c7eb1d75 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Thu, 23 Feb 2017 13:50:41 +0100 Subject: [PATCH 05/18] Changelog 6.16 (#371) * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Update CHANGELOG.md * Address review comments * Update CHANGELOG.md --- CHANGELOG.md | 158 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 158 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d78294a4c8..cff6ffd7be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,164 @@ _Note: Gaps between patch versions are faulty, broken or test releases._ See the [Babel Changelog](https://github.com/babel/babel/blob/master/CHANGELOG.md) for the pre-6.8.0 version Changelog. +## 6.16.0 (2017-02-22) + +### :rocket: New Feature + +***ESTree*** compatibility as plugin ([#277](https://github.com/babel/babylon/pull/277)) (Daniel Tschinder) + +We finally introduce a new compatibility layer for ESTree. To put babylon into ESTree-compatible mode the new plugin `estree` can be enabled. In this mode the parser will output an AST that is compliant to the specs of [ESTree](https://github.com/estree/estree/) + +We highly recommend everyone who uses babylon outside of babel to use this plugin. This will make it much easier for users to switch between different ESTree-compatible parsers. We so far tested several projects with different parsers and exchanged their parser to babylon and in neraly all cases it worked out of the box. Some other estree-compatible parsers include `acorn`, `esprima`, `espree`, `flow-parser`, etc. + +To enable `estree` mode simply add the plugin in the config: +```json +{ + "plugins": [ "estree" ] +} +``` + +If you want to migrate your project from non-ESTree mode to ESTree, have a look at our [Readme](https://github.com/babel/babylon/#output), where all deviations are mentioned. + +Add a parseExpression public method ([#213](https://github.com/babel/babylon/pull/213)) (jeromew) + +Babylon exports a new function to parse a single expression + +```js +import { parseExpression } from 'babylon'; + +const ast = parseExpression('x || y && z', options); +``` + +The returned AST will only consist of the expression. The options are the same as for `parse()`; + +Add startLine option ([#346](https://github.com/babel/babylon/pull/346)) (Raphael Mu) + +A new option was added to babylon allowing to change the intial linenumber for the first line which is usually `1`. +Changing this for example to `100` will make line `1` of the input source to be marked as line `100`, line `2` as `101`, line `3` as `102`, ... + +Function predicate declaration ([#103](https://github.com/babel/babylon/pull/103)) (Panagiotis Vekris) + +Added support for function predicates which flow introduced in version 0.33.0 + +```js +declare function is_number(x: mixed): boolean %checks(typeof x === "number"); +``` + +Allow imports in declare module ([#315](https://github.com/babel/babylon/pull/315)) (Daniel Tschinder) + +Added support for imports within module declarations which flow introduced in version 0.37.0 + +```js +declare module "C" { + import type { DT } from "D"; + declare export type CT = { D: DT }; +} +``` + +### :eyeglasses: Spec Compliancy + +Forbid semicolons after decorators in classes ([#352](https://github.com/babel/babylon/pull/352)) (Kevin Gibbons) + +This example now correctly throws an error when there is a semicolon after the decorator: + +```js +class A { +@a; +foo(){} +} +``` + +Keywords are not allowed as local specifier ([#307](https://github.com/babel/babylon/pull/307)) (Daniel Tschinder) + +Using keywords in imports is not allowed anymore: + +```js +import { default } from "foo"; +import { a as debugger } from "foo"; +``` + +Do not allow overwritting of primitive types ([#314](https://github.com/babel/babylon/pull/314)) (Daniel Tschinder) + +In flow it is now forbidden to overwrite the primitve types `"any"`, `"mixed"`, `"empty"`, `"bool"`, `"boolean"`, `"number"`, `"string"`, `"void"` and `"null"` with your own type declaration. + +Disallow import type { type a } from … ([#305](https://github.com/babel/babylon/pull/305)) (Daniel Tschinder) + +The following code now correctly throws an error + +```js +import type { type a } from "foo"; +``` + +Don't parse class properties without initializers when classProperties is disabled and Flow is enabled ([#300](https://github.com/babel/babylon/pull/300)) (Andrew Levine) + +Ensure that you enable the `classProperties` plugin in order to enable correct parsing of class properties. Prior to this version it was possible to parse them by enabling the `flow` plugin but this was not intended the behaviour. + +If you enable the flow plugin you can only define the type of the class properties, but not initialize them. + +Fix export default async function to be FunctionDeclaration ([#324](https://github.com/babel/babylon/pull/324)) (Daniel Tschinder) + +Parsing the following code now returns a `FunctionDeclaration` AST node instead of `FunctionExpression`. + +```js +export default async function bar() {}; +``` + +### :nail_care: Polish + +Improve error message on attempt to destructure named import ([#288](https://github.com/babel/babylon/pull/288)) (Brian Ng) + +### :bug: Bug Fix + +Fix negative number literal typeannotations ([#366](https://github.com/babel/babylon/pull/366)) (Daniel Tschinder) + +Ensure takeDecorators is called on exported class ([#358](https://github.com/babel/babylon/pull/358)) (Brian Ng) + +ESTree: correctly change literals in all cases ([#368](https://github.com/babel/babylon/pull/368)) (Daniel Tschinder) + +Correctly convert RestProperty to Assignable ([#339](https://github.com/babel/babylon/pull/339)) (Daniel Tschinder) + +Fix #321 by allowing question marks in type params ([#338](https://github.com/babel/babylon/pull/338)) (Daniel Tschinder) + +Fix #336 by correctly setting arrow-param ([#337](https://github.com/babel/babylon/pull/337)) (Daniel Tschinder) + +Fix parse error when destructuring `set` with default value ([#317](https://github.com/babel/babylon/pull/317)) (Brian Ng) + +Fix ObjectTypeCallProperty static ([#298](https://github.com/babel/babylon/pull/298)) (Dan Harper) + + +### :house: Internal + +Fix generator-method-with-computed-name spec ([#360](https://github.com/babel/babylon/pull/360)) (Alex Rattray) + +Fix flow type-parameter-declaration test with unintended semantic ([#361](https://github.com/babel/babylon/pull/361)) (Alex Rattray) + +Cleanup and splitup parser functions ([#295](https://github.com/babel/babylon/pull/295)) (Daniel Tschinder) + +chore(package): update flow-bin to version 0.38.0 ([#313](https://github.com/babel/babylon/pull/313)) (greenkeeper[bot]) + +Call inner function instead of 1:1 copy to plugin ([#294](https://github.com/babel/babylon/pull/294)) (Daniel Tschinder) + +Update eslint-config-babel to the latest version 🚀 ([#299](https://github.com/babel/babylon/pull/299)) (greenkeeper[bot]) + +Update eslint-config-babel to the latest version 🚀 ([#293](https://github.com/babel/babylon/pull/293)) (greenkeeper[bot]) + +devDeps: remove eslint-plugin-babel ([#292](https://github.com/babel/babylon/pull/292)) (Kai Cataldo) + +Correct indent eslint rule config ([#276](https://github.com/babel/babylon/pull/276)) (Daniel Tschinder) + +Fail tests that have expected.json and throws-option ([#285](https://github.com/babel/babylon/pull/285)) (Daniel Tschinder) + +### :memo: Documentation + +Update contributing with more test info [skip ci] ([#355](https://github.com/babel/babylon/pull/355)) (Brian Ng) + +Update API documentation ([#330](https://github.com/babel/babylon/pull/330)) (Timothy Gu) + +Added keywords to package.json ([#323](https://github.com/babel/babylon/pull/323)) (Dmytro) + +AST spec: fix casing of `RegExpLiteral` ([#318](https://github.com/babel/babylon/pull/318)) [skip ci] (Mathias Bynens) + ## 6.15.0 (2017-01-10) ### :eyeglasses: Spec Compliancy From 8dbdeff762131bae8bf95d23783dbafce558a69f Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Thu, 23 Feb 2017 13:51:44 +0100 Subject: [PATCH 06/18] Fix typo [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cff6ffd7be..ae66441cde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ See the [Babel Changelog](https://github.com/babel/babel/blob/master/CHANGELOG.m We finally introduce a new compatibility layer for ESTree. To put babylon into ESTree-compatible mode the new plugin `estree` can be enabled. In this mode the parser will output an AST that is compliant to the specs of [ESTree](https://github.com/estree/estree/) -We highly recommend everyone who uses babylon outside of babel to use this plugin. This will make it much easier for users to switch between different ESTree-compatible parsers. We so far tested several projects with different parsers and exchanged their parser to babylon and in neraly all cases it worked out of the box. Some other estree-compatible parsers include `acorn`, `esprima`, `espree`, `flow-parser`, etc. +We highly recommend everyone who uses babylon outside of babel to use this plugin. This will make it much easier for users to switch between different ESTree-compatible parsers. We so far tested several projects with different parsers and exchanged their parser to babylon and in nearly all cases it worked out of the box. Some other estree-compatible parsers include `acorn`, `esprima`, `espree`, `flow-parser`, etc. To enable `estree` mode simply add the plugin in the config: ```json From 99484d4c392ec635947ac22b62a1cf752c6ed245 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Thu, 23 Feb 2017 13:52:53 +0100 Subject: [PATCH 07/18] Fix typo [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae66441cde..6203f4606c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,7 +44,7 @@ import { parseExpression } from 'babylon'; const ast = parseExpression('x || y && z', options); ``` -The returned AST will only consist of the expression. The options are the same as for `parse()`; +The returned AST will only consist of the expression. The options are the same as for `parse()` Add startLine option ([#346](https://github.com/babel/babylon/pull/346)) (Raphael Mu) From 76c7f55fb5e8e9be7548bad33032bd4fca474532 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Thu, 23 Feb 2017 13:56:22 +0100 Subject: [PATCH 08/18] Fix date [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6203f4606c..5f136b0040 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ _Note: Gaps between patch versions are faulty, broken or test releases._ See the [Babel Changelog](https://github.com/babel/babel/blob/master/CHANGELOG.md) for the pre-6.8.0 version Changelog. -## 6.16.0 (2017-02-22) +## 6.16.0 (2017-02-23) ### :rocket: New Feature From b301d436da489067db5f4ea1585822f06ad2a3a0 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Thu, 23 Feb 2017 14:00:35 +0100 Subject: [PATCH 09/18] 6.16.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 22c0c62ca6..01da0c384e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "babylon", - "version": "6.15.0", + "version": "6.16.0", "description": "A JavaScript parser", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", From 9ed026df0866b7e3f2ae36da2d6f9a6eb9678971 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Thu, 23 Feb 2017 14:04:25 +0100 Subject: [PATCH 10/18] Fix error in changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f136b0040..bb482fc5c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -171,7 +171,7 @@ Update API documentation ([#330](https://github.com/babel/babylon/pull/330)) (Ti Added keywords to package.json ([#323](https://github.com/babel/babylon/pull/323)) (Dmytro) -AST spec: fix casing of `RegExpLiteral` ([#318](https://github.com/babel/babylon/pull/318)) [skip ci] (Mathias Bynens) +AST spec: fix casing of `RegExpLiteral` ([#318](https://github.com/babel/babylon/pull/318)) (Mathias Bynens) ## 6.15.0 (2017-01-10) From b0f8405b523551f124dbfd13cb840e9bb9017a62 Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Thu, 23 Feb 2017 09:50:25 -0500 Subject: [PATCH 11/18] Revert "Don't parse class properties without initializers when classProperties plugin is disabled, and Flow is enabled" (#376) --- src/parser/statement.js | 7 +------ .../with-initializer-and-type-no-plugin/actual.js | 3 --- .../with-initializer-and-type-no-plugin/options.json | 4 ---- .../with-initializer-missing-plugin/actual.js | 3 --- .../with-initializer-missing-plugin/options.json | 3 --- .../without-initializer-missing-plugin/actual.js | 3 --- .../without-initializer-missing-plugin/options.json | 3 --- 7 files changed, 1 insertion(+), 25 deletions(-) delete mode 100644 test/fixtures/experimental/class-properties/with-initializer-and-type-no-plugin/actual.js delete mode 100644 test/fixtures/experimental/class-properties/with-initializer-and-type-no-plugin/options.json delete mode 100644 test/fixtures/experimental/class-properties/with-initializer-missing-plugin/actual.js delete mode 100644 test/fixtures/experimental/class-properties/with-initializer-missing-plugin/options.json delete mode 100644 test/fixtures/experimental/class-properties/without-initializer-missing-plugin/actual.js delete mode 100644 test/fixtures/experimental/class-properties/without-initializer-missing-plugin/options.json diff --git a/src/parser/statement.js b/src/parser/statement.js index d7073ef1bd..42a01b1866 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -766,13 +766,8 @@ pp.parseClassBody = function (node) { }; pp.parseClassProperty = function (node) { - const noPluginMsg = "You can only use Class Properties when the 'classProperties' plugin is enabled."; - if (!node.typeAnnotation && !this.hasPlugin("classProperties")) { - this.raise(node.start, noPluginMsg); - } - if (this.match(tt.eq)) { - if (!this.hasPlugin("classProperties")) this.raise(this.state.start, noPluginMsg); + if (!this.hasPlugin("classProperties")) this.unexpected(); this.next(); node.value = this.parseMaybeAssign(); } else { diff --git a/test/fixtures/experimental/class-properties/with-initializer-and-type-no-plugin/actual.js b/test/fixtures/experimental/class-properties/with-initializer-and-type-no-plugin/actual.js deleted file mode 100644 index f82f8d51d7..0000000000 --- a/test/fixtures/experimental/class-properties/with-initializer-and-type-no-plugin/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -class Foo { - bar: string = 'bizz'; -} diff --git a/test/fixtures/experimental/class-properties/with-initializer-and-type-no-plugin/options.json b/test/fixtures/experimental/class-properties/with-initializer-and-type-no-plugin/options.json deleted file mode 100644 index e185feb80a..0000000000 --- a/test/fixtures/experimental/class-properties/with-initializer-and-type-no-plugin/options.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "plugins": ["flow"], - "throws": "You can only use Class Properties when the 'classProperties' plugin is enabled. (2:14)" -} diff --git a/test/fixtures/experimental/class-properties/with-initializer-missing-plugin/actual.js b/test/fixtures/experimental/class-properties/with-initializer-missing-plugin/actual.js deleted file mode 100644 index fa80e3af68..0000000000 --- a/test/fixtures/experimental/class-properties/with-initializer-missing-plugin/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -class Foo { - bar = 'bizz'; -} diff --git a/test/fixtures/experimental/class-properties/with-initializer-missing-plugin/options.json b/test/fixtures/experimental/class-properties/with-initializer-missing-plugin/options.json deleted file mode 100644 index af38bd1530..0000000000 --- a/test/fixtures/experimental/class-properties/with-initializer-missing-plugin/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "You can only use Class Properties when the 'classProperties' plugin is enabled. (2:2)" -} diff --git a/test/fixtures/experimental/class-properties/without-initializer-missing-plugin/actual.js b/test/fixtures/experimental/class-properties/without-initializer-missing-plugin/actual.js deleted file mode 100644 index a36cdd975c..0000000000 --- a/test/fixtures/experimental/class-properties/without-initializer-missing-plugin/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -class Foo { - bar; -} diff --git a/test/fixtures/experimental/class-properties/without-initializer-missing-plugin/options.json b/test/fixtures/experimental/class-properties/without-initializer-missing-plugin/options.json deleted file mode 100644 index af38bd1530..0000000000 --- a/test/fixtures/experimental/class-properties/without-initializer-missing-plugin/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "throws": "You can only use Class Properties when the 'classProperties' plugin is enabled. (2:2)" -} From 2dd57d17b9014902b8121c393524dd9cfd4807fe Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Thu, 23 Feb 2017 09:50:33 -0500 Subject: [PATCH 12/18] Revert "Fix export default async function to be FunctionDeclaration" (#375) --- src/parser/statement.js | 2 - .../es2017/async-functions/export/actual.js | 2 - .../async-functions/export/expected.json | 172 ------------------ .../async-functions/export/options.json | 3 - 4 files changed, 179 deletions(-) delete mode 100644 test/fixtures/es2017/async-functions/export/actual.js delete mode 100644 test/fixtures/es2017/async-functions/export/expected.json delete mode 100644 test/fixtures/es2017/async-functions/export/options.json diff --git a/src/parser/statement.js b/src/parser/statement.js index 42a01b1866..f7f950574a 100644 --- a/src/parser/statement.js +++ b/src/parser/statement.js @@ -835,8 +835,6 @@ pp.parseExport = function (node) { let needsSemi = false; if (this.eat(tt._function)) { expr = this.parseFunction(expr, true, false, false, true); - } else if (this.eatContextual("async") && this.eat(tt._function)) { - expr = this.parseFunction(expr, true, false, true, true); } else if (this.match(tt._class)) { expr = this.parseClass(expr, true, true); } else { diff --git a/test/fixtures/es2017/async-functions/export/actual.js b/test/fixtures/es2017/async-functions/export/actual.js deleted file mode 100644 index 3f043e6176..0000000000 --- a/test/fixtures/es2017/async-functions/export/actual.js +++ /dev/null @@ -1,2 +0,0 @@ -export async function foo() {} -export default async function bar() {} diff --git a/test/fixtures/es2017/async-functions/export/expected.json b/test/fixtures/es2017/async-functions/export/expected.json deleted file mode 100644 index a19d6f157b..0000000000 --- a/test/fixtures/es2017/async-functions/export/expected.json +++ /dev/null @@ -1,172 +0,0 @@ -{ - "type": "File", - "start": 0, - "end": 69, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 38 - } - }, - "program": { - "type": "Program", - "start": 0, - "end": 69, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 2, - "column": 38 - } - }, - "sourceType": "module", - "body": [ - { - "type": "ExportNamedDeclaration", - "start": 0, - "end": 30, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 30 - } - }, - "specifiers": [], - "source": null, - "declaration": { - "type": "FunctionDeclaration", - "start": 7, - "end": 30, - "loc": { - "start": { - "line": 1, - "column": 7 - }, - "end": { - "line": 1, - "column": 30 - } - }, - "id": { - "type": "Identifier", - "start": 22, - "end": 25, - "loc": { - "start": { - "line": 1, - "column": 22 - }, - "end": { - "line": 1, - "column": 25 - }, - "identifierName": "foo" - }, - "name": "foo" - }, - "generator": false, - "expression": false, - "async": true, - "params": [], - "body": { - "type": "BlockStatement", - "start": 28, - "end": 30, - "loc": { - "start": { - "line": 1, - "column": 28 - }, - "end": { - "line": 1, - "column": 30 - } - }, - "body": [], - "directives": [] - } - } - }, - { - "type": "ExportDefaultDeclaration", - "start": 31, - "end": 69, - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 38 - } - }, - "declaration": { - "type": "FunctionDeclaration", - "start": 46, - "end": 69, - "loc": { - "start": { - "line": 2, - "column": 15 - }, - "end": { - "line": 2, - "column": 38 - } - }, - "id": { - "type": "Identifier", - "start": 61, - "end": 64, - "loc": { - "start": { - "line": 2, - "column": 30 - }, - "end": { - "line": 2, - "column": 33 - }, - "identifierName": "bar" - }, - "name": "bar" - }, - "generator": false, - "expression": false, - "async": true, - "params": [], - "body": { - "type": "BlockStatement", - "start": 67, - "end": 69, - "loc": { - "start": { - "line": 2, - "column": 36 - }, - "end": { - "line": 2, - "column": 38 - } - }, - "body": [], - "directives": [] - } - } - } - ], - "directives": [] - } -} diff --git a/test/fixtures/es2017/async-functions/export/options.json b/test/fixtures/es2017/async-functions/export/options.json deleted file mode 100644 index 2104ca4328..0000000000 --- a/test/fixtures/es2017/async-functions/export/options.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "sourceType": "module" -} From 539d345d9b23ae1331a4beb13e2de91b0a9020e6 Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Thu, 23 Feb 2017 09:53:50 -0500 Subject: [PATCH 13/18] 6.16.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 01da0c384e..b068ce7aee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "babylon", - "version": "6.16.0", + "version": "6.16.1", "description": "A JavaScript parser", "author": "Sebastian McKenzie ", "homepage": "https://babeljs.io/", From 1e747835db51ce145b90f69b27220b64cbbbbe2f Mon Sep 17 00:00:00 2001 From: Henry Zhu Date: Thu, 23 Feb 2017 18:12:30 -0500 Subject: [PATCH 14/18] add estree to docs [skip ci] (#372) --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index cbe528885b..6836b8f84e 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,8 @@ mind. When in doubt, use `.parse()`. Babylon generates AST according to [Babel AST format][]. It is based on [ESTree spec][] with the following deviations: +> There is now an `estree` plugin which reverts these deviations + - [Literal][] token is replaced with [StringLiteral][], [NumericLiteral][], [BooleanLiteral][], [NullLiteral][], [RegExpLiteral][] - [Property][] token is replaced with [ObjectProperty][] and [ObjectMethod][] - [MethodDefinition][] is replaced with [ClassMethod][] @@ -117,6 +119,7 @@ require("babylon").parse("code", { ### Plugins + - `estree` - `jsx` - `flow` - `doExpressions` From 9a5d93fa612a9c2bdacbbfae2052e55a085337db Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Mon, 27 Feb 2017 12:08:56 +0100 Subject: [PATCH 15/18] chore(package): update flow-bin to version 0.40.0 (#380) https://greenkeeper.io/ --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b068ce7aee..231b143315 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "eslint": "^3.7.1", "eslint-config-babel": "^6.0.0", "eslint-plugin-flowtype": "^2.20.0", - "flow-bin": "^0.38.0", + "flow-bin": "^0.40.0", "nyc": "^10.0.0", "rimraf": "^2.5.4", "rollup": "^0.41.0", From cd133ff8e14beba681cdf4d2a0337aad3d983931 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Tue, 28 Feb 2017 05:56:56 -0600 Subject: [PATCH 16/18] Ensure consistent start args for parseParenItem (#386) --- src/parser/expression.js | 2 +- src/plugins/flow.js | 6 +- test/fixtures/flow/comment/spread/actual.js | 4 + .../flow/comment/spread/expected.json | 275 ++++++++++++++++++ 4 files changed, 283 insertions(+), 4 deletions(-) create mode 100644 test/fixtures/flow/comment/spread/actual.js create mode 100644 test/fixtures/flow/comment/spread/expected.json diff --git a/src/parser/expression.js b/src/parser/expression.js index 54d48e01ab..bf5dda237d 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -595,7 +595,7 @@ pp.parseParenAndDistinguishExpression = function (startPos, startLoc, canBeArrow const spreadNodeStartPos = this.state.start; const spreadNodeStartLoc = this.state.startLoc; spreadStart = this.state.start; - exprList.push(this.parseParenItem(this.parseRest(), spreadNodeStartLoc, spreadNodeStartPos)); + exprList.push(this.parseParenItem(this.parseRest(), spreadNodeStartPos, spreadNodeStartLoc)); break; } else { exprList.push(this.parseMaybeAssign(false, refShorthandDefaultPos, this.parseParenItem, refNeedsArrowPos)); diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 04579ae047..330a5f3591 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -940,14 +940,14 @@ export default function (instance) { }); instance.extend("parseParenItem", function (inner) { - return function (node, startLoc, startPos) { - node = inner.call(this, node, startLoc, startPos); + return function (node, startPos, startLoc) { + node = inner.call(this, node, startPos, startLoc); if (this.eat(tt.question)) { node.optional = true; } if (this.match(tt.colon)) { - const typeCastNode = this.startNodeAt(startLoc, startPos); + const typeCastNode = this.startNodeAt(startPos, startLoc); typeCastNode.expression = node; typeCastNode.typeAnnotation = this.flowParseTypeAnnotation(); diff --git a/test/fixtures/flow/comment/spread/actual.js b/test/fixtures/flow/comment/spread/actual.js new file mode 100644 index 0000000000..4c4266c5ca --- /dev/null +++ b/test/fixtures/flow/comment/spread/actual.js @@ -0,0 +1,4 @@ +/* hi */ +function commentsAttachedToIdentifier() { + var x = (...args: any) => {}; +} diff --git a/test/fixtures/flow/comment/spread/expected.json b/test/fixtures/flow/comment/spread/expected.json new file mode 100644 index 0000000000..313e33c4ac --- /dev/null +++ b/test/fixtures/flow/comment/spread/expected.json @@ -0,0 +1,275 @@ +{ + "type": "File", + "start": 0, + "end": 84, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 84, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "module", + "body": [ + { + "type": "FunctionDeclaration", + "start": 9, + "end": 84, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 18, + "end": 46, + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 37 + }, + "identifierName": "commentsAttachedToIdentifier" + }, + "name": "commentsAttachedToIdentifier", + "leadingComments": null + }, + "generator": false, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 49, + "end": 84, + "loc": { + "start": { + "line": 2, + "column": 40 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "VariableDeclaration", + "start": 53, + "end": 82, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 31 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 57, + "end": 81, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 30 + } + }, + "id": { + "type": "Identifier", + "start": 57, + "end": 58, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 7 + }, + "identifierName": "x" + }, + "name": "x" + }, + "init": { + "type": "ArrowFunctionExpression", + "start": 61, + "end": 81, + "loc": { + "start": { + "line": 3, + "column": 10 + }, + "end": { + "line": 3, + "column": 30 + } + }, + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "RestElement", + "start": 62, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 11 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "argument": { + "type": "Identifier", + "start": 65, + "end": 69, + "loc": { + "start": { + "line": 3, + "column": 14 + }, + "end": { + "line": 3, + "column": 18 + }, + "identifierName": "args" + }, + "name": "args" + }, + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 69, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 18 + }, + "end": { + "line": 3, + "column": 23 + } + }, + "typeAnnotation": { + "type": "AnyTypeAnnotation", + "start": 71, + "end": 74, + "loc": { + "start": { + "line": 3, + "column": 20 + }, + "end": { + "line": 3, + "column": 23 + } + } + } + } + } + ], + "body": { + "type": "BlockStatement", + "start": 79, + "end": 81, + "loc": { + "start": { + "line": 3, + "column": 28 + }, + "end": { + "line": 3, + "column": 30 + } + }, + "body": [], + "directives": [] + } + } + } + ], + "kind": "var" + } + ], + "directives": [] + }, + "leadingComments": [ + { + "type": "CommentBlock", + "value": " hi ", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentBlock", + "value": " hi ", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + } + } + ] +} \ No newline at end of file From 09bb9bc6be3a4722d9684c12492513ea0320c89c Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Tue, 28 Feb 2017 11:43:34 -0600 Subject: [PATCH 17/18] Fix parsing yield with dynamicImport (#383) --- src/parser/expression.js | 8 +- src/tokenizer/types.js | 2 +- .../dynamic-import/generator/actual.js | 3 + .../dynamic-import/generator/expected.json | 171 ++++++++++++++++++ 4 files changed, 181 insertions(+), 3 deletions(-) create mode 100644 test/fixtures/experimental/dynamic-import/generator/actual.js create mode 100644 test/fixtures/experimental/dynamic-import/generator/expected.json diff --git a/src/parser/expression.js b/src/parser/expression.js index bf5dda237d..f336e896b7 100644 --- a/src/parser/expression.js +++ b/src/parser/expression.js @@ -61,7 +61,7 @@ pp.getExpression = function() { // the AST node that the inner parser gave them in another node. // Parse a full expression. The optional arguments are used to -// forbid the `in` operator (in for loops initalization expressions) +// forbid the `in` operator (in for loops initialization expressions) // and provide reference for storing '=' operator inside shorthand // property assignment in contexts where both object expression // and object pattern might appear (so it's possible to raise @@ -1095,7 +1095,11 @@ pp.parseAwait = function (node) { pp.parseYield = function () { const node = this.startNode(); this.next(); - if (this.match(tt.semi) || this.canInsertSemicolon() || (!this.match(tt.star) && !this.state.type.startsExpr)) { + if ( + this.match(tt.semi) || + this.canInsertSemicolon() || + (!this.match(tt.star) && !this.state.type.startsExpr) + ) { node.delegate = false; node.argument = null; } else { diff --git a/src/tokenizer/types.js b/src/tokenizer/types.js index b82dfe0902..1d78aabb40 100644 --- a/src/tokenizer/types.js +++ b/src/tokenizer/types.js @@ -143,7 +143,7 @@ export const keywords = { "class": new KeywordTokenType("class"), "extends": new KeywordTokenType("extends", { beforeExpr }), "export": new KeywordTokenType("export"), - "import": new KeywordTokenType("import"), + "import": new KeywordTokenType("import", { startsExpr }), "yield": new KeywordTokenType("yield", { beforeExpr, startsExpr }), "null": new KeywordTokenType("null", { startsExpr }), "true": new KeywordTokenType("true", { startsExpr }), diff --git a/test/fixtures/experimental/dynamic-import/generator/actual.js b/test/fixtures/experimental/dynamic-import/generator/actual.js new file mode 100644 index 0000000000..5b09c31e6f --- /dev/null +++ b/test/fixtures/experimental/dynamic-import/generator/actual.js @@ -0,0 +1,3 @@ +function* a() { + yield import('http'); +} diff --git a/test/fixtures/experimental/dynamic-import/generator/expected.json b/test/fixtures/experimental/dynamic-import/generator/expected.json new file mode 100644 index 0000000000..e2aff25e73 --- /dev/null +++ b/test/fixtures/experimental/dynamic-import/generator/expected.json @@ -0,0 +1,171 @@ +{ + "type": "File", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "id": { + "type": "Identifier", + "start": 10, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 11 + }, + "identifierName": "a" + }, + "name": "a" + }, + "generator": true, + "expression": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 14, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ExpressionStatement", + "start": 18, + "end": 39, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 23 + } + }, + "expression": { + "type": "YieldExpression", + "start": 18, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "delegate": false, + "argument": { + "type": "CallExpression", + "start": 24, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 22 + } + }, + "callee": { + "type": "Import", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 14 + } + } + }, + "arguments": [ + { + "type": "StringLiteral", + "start": 31, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "extra": { + "rawValue": "http", + "raw": "'http'" + }, + "value": "http" + } + ] + } + } + } + ], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file From d9e946635096f82d21071b01ca715145f1602c9a Mon Sep 17 00:00:00 2001 From: Alex Kuzmenko Date: Tue, 28 Feb 2017 19:45:25 +0200 Subject: [PATCH 18/18] Update spec.md [skip ci] (#367) --- ast/spec.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ast/spec.md b/ast/spec.md index 346b7b95aa..9e2e094b9f 100644 --- a/ast/spec.md +++ b/ast/spec.md @@ -1152,7 +1152,7 @@ interface ExportNamedDeclaration <: ModuleDeclaration { } ``` -An export named declaration, e.g., `export {foo, bar};`, `export {foo} from "mod";` or `export var foo = 1;`. +An export named declaration, e.g., `export {foo, bar};`, `export {foo} from "mod";`, `export var foo = 1;` or `export * as foo from "bar";`. _Note: Having `declaration` populated with non-empty `specifiers` or non-null `source` results in an invalid state._