From d832c0f434f1c272ad7af3a333b306e6227aa720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Tue, 5 Mar 2019 00:45:42 +0100 Subject: [PATCH] Add parser support for placeholders (#9364) --- .../babel-parser/src/parser/expression.js | 13 +- packages/babel-parser/src/parser/statement.js | 45 +-- packages/babel-parser/src/parser/util.js | 7 + packages/babel-parser/src/plugin-utils.js | 9 +- .../babel-parser/src/plugins/placeholders.js | 315 ++++++++++++++++++ packages/babel-parser/src/types.js | 17 + .../failure-spaces/options.json | 2 +- .../failure-spaces/options.json | 2 +- .../placeholders/_errors/no-plugin/input.js | 1 + .../_errors/no-plugin/options.json | 4 + .../placeholders/_errors/space-after/input.js | 1 + .../_errors/space-after/options.json | 4 + .../_errors/space-before/input.js | 1 + .../_errors/space-before/options.json | 4 + .../arrow/async-parenless/input.js | 1 + .../arrow/async-parenless/options.json | 4 + .../placeholders/arrow/async/input.js | 1 + .../placeholders/arrow/async/output.json | 136 ++++++++ .../arrow/sync-parenless/input.js | 1 + .../arrow/sync-parenless/options.json | 4 + .../fixtures/placeholders/arrow/sync/input.js | 1 + .../placeholders/arrow/sync/output.json | 136 ++++++++ .../class/body_expression/input.js | 1 + .../class/body_expression/output.json | 116 +++++++ .../class/body_statement/input.js | 1 + .../class/body_statement/output.json | 101 ++++++ .../placeholders/class/decorators/input.js | 2 + .../class/decorators/options.json | 6 + .../placeholders/class/decorators/output.json | 134 ++++++++ .../placeholders/class/id-body/input.js | 1 + .../placeholders/class/id-body/output.json | 117 +++++++ .../placeholders/class/id-super-body/input.js | 1 + .../class/id-super-body/output.json | 149 +++++++++ .../placeholders/class/id-super/input.js | 1 + .../placeholders/class/id-super/output.json | 132 ++++++++ .../placeholders/class/id_expression/input.js | 1 + .../class/id_expression/output.json | 132 ++++++++ .../placeholders/class/id_statement/input.js | 1 + .../class/id_statement/output.json | 100 ++++++ .../placeholders/class/super/input.js | 1 + .../placeholders/class/super/output.json | 116 +++++++ .../placeholders/export/declaration/input.js | 1 + .../export/declaration/output.json | 100 ++++++ .../export/default-default-from/input.js | 1 + .../export/default-default-from/options.json | 7 + .../export/default-named-from-2/input.js | 1 + .../export/default-named-from-2/options.json | 7 + .../export/default-named-from-3/input.js | 1 + .../export/default-named-from-3/options.json | 7 + .../export/default-named-from/input.js | 1 + .../export/default-named-from/options.json | 7 + .../export/named-alias-2/input.js | 1 + .../export/named-alias-2/output.json | 119 +++++++ .../export/named-alias-3/input.js | 1 + .../export/named-alias-3/output.json | 135 ++++++++ .../placeholders/export/named-alias/input.js | 1 + .../export/named-alias/output.json | 119 +++++++ .../placeholders/export/named-from-2/input.js | 1 + .../export/named-from-2/output.json | 135 ++++++++ .../placeholders/export/named-from-3/input.js | 1 + .../export/named-from-3/output.json | 167 ++++++++++ .../export/named-from-alias-2/input.js | 1 + .../export/named-from-alias-2/output.json | 138 ++++++++ .../export/named-from-alias-3/input.js | 1 + .../export/named-from-alias-3/output.json | 154 +++++++++ .../export/named-from-alias/input.js | 1 + .../export/named-from-alias/output.json | 138 ++++++++ .../placeholders/export/named-from/input.js | 1 + .../export/named-from/output.json | 154 +++++++++ .../placeholders/export/named/input.js | 1 + .../placeholders/export/named/output.json | 135 ++++++++ .../fixtures/placeholders/export/options.json | 4 + .../placeholders/export/star-from-2/input.js | 1 + .../export/star-from-2/options.json | 7 + .../placeholders/export/star-from-3/input.js | 1 + .../export/star-from-3/options.json | 7 + .../placeholders/export/star-from/input.js | 1 + .../placeholders/export/star-from/output.json | 83 +++++ .../placeholders/expression/01/input.js | 1 + .../placeholders/expression/01/output.json | 182 ++++++++++ .../placeholders/expression/options.json | 3 + .../placeholders/function/body/input.js | 1 + .../placeholders/function/body/output.json | 103 ++++++ .../function/id-params-body/input.js | 1 + .../function/id-params-body/output.json | 186 +++++++++++ .../function/id_declaration/input.js | 1 + .../function/id_declaration/output.json | 103 ++++++ .../function/id_expression/input.js | 1 + .../function/id_expression/output.json | 135 ++++++++ .../placeholders/function/param/input.js | 1 + .../placeholders/function/param/output.json | 121 +++++++ .../import/default-file/input.mjs | 1 + .../import/default-file/output.json | 133 ++++++++ .../import/default-named-2/input.mjs | 1 + .../import/default-named-2/output.json | 169 ++++++++++ .../import/default-named-3/input.mjs | 1 + .../import/default-named-3/output.json | 201 +++++++++++ .../import/default-named/input.mjs | 1 + .../import/default-named/output.json | 185 ++++++++++ .../import/default-star-2/input.mjs | 1 + .../import/default-star-2/output.json | 152 +++++++++ .../import/default-star-3/input.mjs | 1 + .../import/default-star-3/output.json | 168 ++++++++++ .../import/default-star/input.mjs | 1 + .../import/default-star/output.json | 152 +++++++++ .../placeholders/import/default/input.mjs | 1 + .../placeholders/import/default/output.json | 120 +++++++ .../placeholders/import/file-empty/input.mjs | 1 + .../import/file-empty/output.json | 84 +++++ .../placeholders/import/file/input.mjs | 1 + .../placeholders/import/file/output.json | 84 +++++ .../import/named-alias-2/input.mjs | 1 + .../import/named-alias-2/output.json | 137 ++++++++ .../import/named-alias-3/input.mjs | 1 + .../import/named-alias-3/output.json | 153 +++++++++ .../placeholders/import/named-alias/input.mjs | 1 + .../import/named-alias/output.json | 137 ++++++++ .../placeholders/import/named/input.mjs | 1 + .../placeholders/import/named/output.json | 153 +++++++++ .../fixtures/placeholders/import/options.json | 4 + .../placeholders/import/star/input.mjs | 1 + .../placeholders/import/star/output.json | 120 +++++++ .../fixtures/placeholders/labels/asi/input.js | 4 + .../placeholders/labels/asi/output.json | 169 ++++++++++ .../placeholders/labels/break/input.js | 3 + .../placeholders/labels/break/output.json | 133 ++++++++ .../placeholders/labels/continue/input.js | 3 + .../placeholders/labels/continue/output.json | 168 ++++++++++ .../labels/labeled-statement/input.js | 1 + .../labels/labeled-statement/output.json | 118 +++++++ .../test/fixtures/placeholders/options.json | 3 + .../placeholders/statement/asi/input.js | 2 + .../placeholders/statement/asi/output.json | 101 ++++++ .../placeholders/statement/nested/input.js | 1 + .../placeholders/statement/nested/output.json | 104 ++++++ .../placeholders/statement/top-level/input.js | 1 + .../statement/top-level/output.json | 68 ++++ .../try/try-catch-finally/input.js | 1 + .../try/try-catch-finally/output.json | 166 +++++++++ .../try/with-catch-param/input.js | 1 + .../try/with-catch-param/output.json | 150 +++++++++ 141 files changed, 7630 insertions(+), 36 deletions(-) create mode 100644 packages/babel-parser/src/plugins/placeholders.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/_errors/no-plugin/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/_errors/no-plugin/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/_errors/space-after/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/_errors/space-after/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/_errors/space-before/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/_errors/space-before/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/arrow/async-parenless/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/arrow/async-parenless/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/arrow/async/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/arrow/async/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/arrow/sync-parenless/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/arrow/sync-parenless/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/arrow/sync/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/arrow/sync/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/body_expression/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/body_expression/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/body_statement/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/body_statement/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/decorators/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/decorators/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/decorators/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/id-body/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/id-body/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/id-super-body/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/id-super-body/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/id-super/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/id-super/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/id_expression/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/id_expression/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/id_statement/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/id_statement/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/super/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/class/super/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/declaration/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/declaration/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/default-default-from/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/default-default-from/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/default-named-from-2/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/default-named-from-2/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/default-named-from-3/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/default-named-from-3/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/default-named-from/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/default-named-from/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-alias-2/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-alias-2/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-alias-3/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-alias-3/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-alias/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-alias/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-from-2/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-from-2/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-from-3/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-from-3/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-2/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-2/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-3/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-3/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-from-alias/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-from-alias/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-from/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named-from/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/named/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/star-from-2/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/star-from-2/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/star-from-3/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/star-from-3/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/star-from/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/export/star-from/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/expression/01/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/expression/01/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/expression/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/function/body/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/function/body/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/function/id-params-body/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/function/id-params-body/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/function/id_declaration/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/function/id_declaration/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/function/id_expression/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/function/id_expression/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/function/param/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/function/param/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default-file/input.mjs create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default-file/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default-named-2/input.mjs create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default-named-2/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default-named-3/input.mjs create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default-named-3/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default-named/input.mjs create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default-named/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default-star-2/input.mjs create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default-star-2/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default-star-3/input.mjs create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default-star-3/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default-star/input.mjs create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default-star/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default/input.mjs create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/default/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/file-empty/input.mjs create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/file-empty/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/file/input.mjs create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/file/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/named-alias-2/input.mjs create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/named-alias-2/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/named-alias-3/input.mjs create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/named-alias-3/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/named-alias/input.mjs create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/named-alias/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/named/input.mjs create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/named/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/star/input.mjs create mode 100644 packages/babel-parser/test/fixtures/placeholders/import/star/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/labels/asi/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/labels/asi/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/labels/break/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/labels/break/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/labels/continue/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/labels/continue/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/labels/labeled-statement/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/labels/labeled-statement/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/options.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/statement/asi/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/statement/asi/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/statement/nested/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/statement/nested/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/statement/top-level/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/statement/top-level/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/try/try-catch-finally/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/try/try-catch-finally/output.json create mode 100644 packages/babel-parser/test/fixtures/placeholders/try/with-catch-param/input.js create mode 100644 packages/babel-parser/test/fixtures/placeholders/try/with-catch-param/output.json diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index 516aba3aa2..b9195c3a97 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -1048,19 +1048,8 @@ export default class ExpressionParser extends LValParser { if (isPrivate) { this.expectOnePlugin(["classPrivateProperties", "classPrivateMethods"]); const node = this.startNode(); - const columnHashEnd = this.state.end; this.next(); - const columnIdentifierStart = this.state.start; - - const spacesBetweenHashAndIdentifier = - columnIdentifierStart - columnHashEnd; - if (spacesBetweenHashAndIdentifier != 0) { - this.raise( - columnIdentifierStart, - "Unexpected space between # and identifier", - ); - } - + this.assertNoSpace("Unexpected space between # and identifier"); node.id = this.parseIdentifier(true); return this.finishNode(node, "PrivateName"); } else { diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index 22cc9b24a0..47b3c9f2c7 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -416,15 +416,24 @@ export default class StatementParser extends ExpressionParser { if (this.isLineTerminator()) { node.label = null; - } else if (!this.match(tt.name)) { - this.unexpected(); } else { node.label = this.parseIdentifier(); this.semicolon(); } - // Verify that there is an actual destination to break or - // continue to. + this.verifyBreakContinue(node, keyword); + + return this.finishNode( + node, + isBreak ? "BreakStatement" : "ContinueStatement", + ); + } + + verifyBreakContinue( + node: N.BreakStatement | N.ContinueStatement, + keyword: string, + ) { + const isBreak = keyword === "break"; let i; for (i = 0; i < this.state.labels.length; ++i) { const lab = this.state.labels[i]; @@ -436,10 +445,6 @@ export default class StatementParser extends ExpressionParser { if (i === this.state.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); } - return this.finishNode( - node, - isBreak ? "BreakStatement" : "ContinueStatement", - ); } parseDebuggerStatement(node: N.DebuggerStatement): N.DebuggerStatement { @@ -800,7 +805,7 @@ export default class StatementParser extends ExpressionParser { parseExpressionStatement( node: N.ExpressionStatement, expr: N.Expression, - ): N.ExpressionStatement { + ): N.Statement { node.expression = expr; this.semicolon(); return this.finishNode(node, "ExpressionStatement"); @@ -1024,6 +1029,7 @@ export default class StatementParser extends ExpressionParser { ): T { const isStatement = statement & FUNC_STATEMENT; const isHangingStatement = statement & FUNC_HANGING_STATEMENT; + const requireId = !!isStatement && !(statement & FUNC_NULLABLE_ID); this.initFunction(node, isAsync); @@ -1036,10 +1042,7 @@ export default class StatementParser extends ExpressionParser { node.generator = this.eat(tt.star); if (isStatement) { - node.id = - statement & FUNC_NULLABLE_ID && !this.match(tt.name) - ? null - : this.parseIdentifier(); + node.id = this.parseFunctionId(requireId); if (node.id && !isHangingStatement) { // If it is a regular function declaration in sloppy mode, then it is // subject to Annex B semantics (BIND_FUNCTION). Otherwise, the binding @@ -1067,7 +1070,7 @@ export default class StatementParser extends ExpressionParser { this.scope.enter(functionFlags(node.async, node.generator)); if (!isStatement) { - node.id = this.match(tt.name) ? this.parseIdentifier() : null; + node.id = this.parseFunctionId(); } this.parseFunctionParams(node); @@ -1090,6 +1093,10 @@ export default class StatementParser extends ExpressionParser { return node; } + parseFunctionId(requireId?: boolean): ?N.Identifier { + return requireId || this.match(tt.name) ? this.parseIdentifier() : null; + } + parseFunctionParams(node: N.Function, allowModifiers?: boolean): void { const oldInParameters = this.state.inParameters; this.state.inParameters = true; @@ -1122,7 +1129,7 @@ export default class StatementParser extends ExpressionParser { this.parseClassId(node, isStatement, optionalId); this.parseClassSuper(node); - this.parseClassBody(node); + node.body = this.parseClassBody(!!node.superClass); this.state.strict = oldStrict; @@ -1149,7 +1156,7 @@ export default class StatementParser extends ExpressionParser { ); } - parseClassBody(node: N.Class): void { + parseClassBody(constructorAllowsSuper: boolean): N.ClassBody { this.state.classLevel++; const state = { hadConstructor: false }; @@ -1159,8 +1166,6 @@ export default class StatementParser extends ExpressionParser { this.expect(tt.braceL); - const constructorAllowsSuper = node.superClass !== null; - // For the smartPipelines plugin: Disable topic references from outer // contexts within the class body. They are permitted in test expressions, // outside of the class body. @@ -1212,9 +1217,9 @@ export default class StatementParser extends ExpressionParser { ); } - node.body = this.finishNode(classBody, "ClassBody"); - this.state.classLevel--; + + return this.finishNode(classBody, "ClassBody"); } parseClassMember( diff --git a/packages/babel-parser/src/parser/util.js b/packages/babel-parser/src/parser/util.js index 6d5234793b..1681078d40 100644 --- a/packages/babel-parser/src/parser/util.js +++ b/packages/babel-parser/src/parser/util.js @@ -113,6 +113,13 @@ export default class UtilParser extends Tokenizer { this.eat(type) || this.unexpected(pos, type); } + // Throws if the current token and the prev one are separated by a space. + assertNoSpace(message: string = "Unexpected space."): void { + if (this.state.start > this.state.lastTokEnd) { + this.raise(this.state.lastTokEnd, message); + } + } + // Raise an unexpected token error. Can take the expected token type // instead of a message string. diff --git a/packages/babel-parser/src/plugin-utils.js b/packages/babel-parser/src/plugin-utils.js index d92800f464..d9e368e666 100644 --- a/packages/babel-parser/src/plugin-utils.js +++ b/packages/babel-parser/src/plugin-utils.js @@ -88,12 +88,17 @@ import estree from "./plugins/estree"; import flow from "./plugins/flow"; import jsx from "./plugins/jsx"; import typescript from "./plugins/typescript"; +import placeholders from "./plugins/placeholders"; -// NOTE: estree must load first; flow and typescript must load last. -export const mixinPluginNames = ["estree", "jsx", "flow", "typescript"]; +// NOTE: order is important. estree must come first; placeholders must come last. export const mixinPlugins: { [name: string]: MixinPlugin } = { estree, jsx, flow, typescript, + placeholders, }; + +export const mixinPluginNames: $ReadOnlyArray = Object.keys( + mixinPlugins, +); diff --git a/packages/babel-parser/src/plugins/placeholders.js b/packages/babel-parser/src/plugins/placeholders.js new file mode 100644 index 0000000000..50956c9bb8 --- /dev/null +++ b/packages/babel-parser/src/plugins/placeholders.js @@ -0,0 +1,315 @@ +// @flow + +import * as charCodes from "charcodes"; + +import { types as tt, TokenType } from "../tokenizer/types"; +import type Parser from "../parser"; +import * as N from "../types"; + +tt.placeholder = new TokenType("%%", { startsExpr: true }); + +export type PlaceholderTypes = + | "Identifier" + | "StringLiteral" + | "Expression" + | "Statement" + | "Declaration" + | "BlockStatement" + | "ClassBody" + | "Pattern"; + +// $PropertyType doesn't support enums. Use a fake "switch" (GetPlaceholderNode) +//type MaybePlaceholder = $PropertyType | N.Placeholder; + +type _Switch = $Call< + ( + $ElementType<$ElementType, 0>, + ) => $ElementType<$ElementType, 1>, + Value, +>; +type $Switch = _Switch; + +type NodeOf = $Switch< + T, + [ + ["Identifier", N.Identifier], + ["StringLiteral", N.StringLiteral], + ["Expression", N.Expression], + ["Statement", N.Statement], + ["Declaration", N.Declaration], + ["BlockStatement", N.BlockStatement], + ["ClassBody", N.ClassBody], + ["Pattern", N.Pattern], + ], +>; + +// Placeholder breaks everything, because its type is incompatible with +// the substituted nodes. +type MaybePlaceholder = NodeOf; // | Placeholder + +export default (superClass: Class): Class => + class extends superClass { + parsePlaceholder( + expectedNode: T, + ): /*?N.Placeholder*/ ?MaybePlaceholder { + if (this.match(tt.placeholder)) { + const node = this.startNode(); + this.next(); + this.assertNoSpace("Unexpected space in placeholder."); + + // We can't use this.parseIdentifier because + // we don't want nested placeholders. + node.name = super.parseIdentifier(/* liberal */ true); + + this.assertNoSpace("Unexpected space in placeholder."); + this.expect(tt.placeholder); + return this.finishPlaceholder(node, expectedNode); + } + } + + finishPlaceholder( + node: N.Node, + expectedNode: T, + ): /*N.Placeholder*/ MaybePlaceholder { + node.expectedNode = expectedNode; + return this.finishNode(node, "Placeholder"); + } + + /* ============================================================ * + * tokenizer/index.js * + * ============================================================ */ + + getTokenFromCode(code: number) { + if ( + code === charCodes.percentSign && + this.state.input.charCodeAt(this.state.pos + 1) === + charCodes.percentSign + ) { + return this.finishOp(tt.placeholder, 2); + } + + return super.getTokenFromCode(...arguments); + } + + /* ============================================================ * + * parser/expression.js * + * ============================================================ */ + + parseExprAtom(): MaybePlaceholder<"Expression"> { + return ( + this.parsePlaceholder("Expression") || super.parseExprAtom(...arguments) + ); + } + + parseIdentifier(): MaybePlaceholder<"Identifier"> { + // NOTE: This function only handles identifiers outside of + // expressions and binding patterns, since they are already + // handled by the parseExprAtom and parseBindingAtom functions. + // This is needed, for example, to parse "class %%NAME%% {}". + return ( + this.parsePlaceholder("Identifier") || + super.parseIdentifier(...arguments) + ); + } + + checkReservedWord(word: string): void { + // Sometimes we call #checkReservedWord(node.name), expecting + // that node is an Identifier. If it is a Placeholder, name + // will be undefined. + if (word !== undefined) super.checkReservedWord(...arguments); + } + + /* ============================================================ * + * parser/lval.js * + * ============================================================ */ + + parseBindingAtom(): MaybePlaceholder<"Pattern"> { + return ( + this.parsePlaceholder("Pattern") || super.parseBindingAtom(...arguments) + ); + } + + checkLVal(expr: N.Expression): void { + if (expr.type !== "Placeholder") super.checkLVal(...arguments); + } + + toAssignable(node: N.Node): N.Node { + if ( + node && + node.type === "Placeholder" && + node.expectedNode === "Expression" + ) { + node.expectedNode = "Pattern"; + return node; + } + return super.toAssignable(...arguments); + } + + /* ============================================================ * + * parser/statement.js * + * ============================================================ */ + + verifyBreakContinue(node: N.BreakStatement | N.ContinueStatement) { + if (node.label && node.label.type === "Placeholder") return; + super.verifyBreakContinue(...arguments); + } + + parseExpressionStatement( + node: MaybePlaceholder<"Statement">, + expr: N.Expression, + ): MaybePlaceholder<"Statement"> { + if ( + expr.type !== "Placeholder" || + (expr.extra && expr.extra.parenthesized) + ) { + return super.parseExpressionStatement(...arguments); + } + + if (this.match(tt.colon)) { + const stmt: N.LabeledStatement = node; + stmt.label = this.finishPlaceholder(expr, "Identifier"); + this.next(); + stmt.body = this.parseStatement("label"); + return this.finishNode(stmt, "LabeledStatement"); + } + + this.semicolon(); + + node.name = expr.name; + return this.finishPlaceholder(node, "Statement"); + } + + parseBlock(): MaybePlaceholder<"BlockStatement"> { + return ( + this.parsePlaceholder("BlockStatement") || + super.parseBlock(...arguments) + ); + } + + parseFunctionId(): ?MaybePlaceholder<"Identifier"> { + return ( + this.parsePlaceholder("Identifier") || + super.parseFunctionId(...arguments) + ); + } + + parseClass( + node: T, + isStatement: /* T === ClassDeclaration */ boolean, + optionalId?: boolean, + ): T { + const type = isStatement ? "ClassDeclaration" : "ClassExpression"; + + this.next(); + this.takeDecorators(node); + + const placeholder = this.parsePlaceholder("Identifier"); + if (placeholder) { + if ( + this.match(tt._extends) || + this.match(tt.placeholder) || + this.match(tt.braceL) + ) { + node.id = placeholder; + } else if (optionalId || !isStatement) { + node.id = null; + node.body = this.finishPlaceholder(placeholder, "ClassBody"); + return this.finishNode(node, type); + } else { + this.unexpected(null, "A class name is required"); + } + } else { + this.parseClassId(node, isStatement, optionalId); + } + + this.parseClassSuper(node); + node.body = + this.parsePlaceholder("ClassBody") || + this.parseClassBody(!!node.superClass); + return this.finishNode(node, type); + } + + parseExport(node: N.Node): N.Node { + const placeholder = this.parsePlaceholder("Identifier"); + if (!placeholder) return super.parseExport(...arguments); + + if (!this.isContextual("from") && !this.match(tt.comma)) { + // export %%DECL%%; + node.specifiers = []; + node.source = null; + node.declaration = this.finishPlaceholder(placeholder, "Declaration"); + return this.finishNode(node, "ExportNamedDeclaration"); + } + + // export %%NAME%% from "foo"; + this.expectPlugin("exportDefaultFrom"); + const specifier = this.startNode(); + specifier.exported = placeholder; + node.specifiers = [this.finishNode(specifier, "ExportDefaultSpecifier")]; + + return super.parseExport(node); + } + + maybeParseExportDefaultSpecifier(node: N.Node): boolean { + if (node.specifiers && node.specifiers.length > 0) { + // "export %%NAME%%" has already been parsed by #parseExport. + return true; + } + return super.maybeParseExportDefaultSpecifier(...arguments); + } + + checkExport(node: N.ExportNamedDeclaration): void { + const { specifiers } = node; + if (specifiers && specifiers.length) { + node.specifiers = specifiers.filter( + node => node.exported.type === "Placeholder", + ); + } + super.checkExport(node); + node.specifiers = specifiers; + } + + parseImport( + node: N.Node, + ): N.ImportDeclaration | N.TsImportEqualsDeclaration { + const placeholder = this.parsePlaceholder("Identifier"); + if (!placeholder) return super.parseImport(...arguments); + + node.specifiers = []; + + if (!this.isContextual("from") && !this.match(tt.comma)) { + // import %%STRING%%; + node.source = this.finishPlaceholder(placeholder, "StringLiteral"); + this.semicolon(); + return this.finishNode(node, "ImportDeclaration"); + } + + // import %%DEFAULT%% ... + const specifier = this.startNodeAtNode(placeholder); + specifier.local = placeholder; + this.finishNode(specifier, "ImportDefaultSpecifier"); + node.specifiers.push(specifier); + + if (this.eat(tt.comma)) { + // import %%DEFAULT%%, * as ... + const hasStarImport = this.maybeParseStarImportSpecifier(node); + + // import %%DEFAULT%%, { ... + if (!hasStarImport) this.parseNamedImportSpecifiers(node); + } + + this.expectContextual("from"); + node.source = this.parseImportSource(); + this.semicolon(); + return this.finishNode(node, "ImportDeclaration"); + } + + parseImportSource(): MaybePlaceholder<"StringLiteral"> { + // import ... from %%STRING%%; + + return ( + this.parsePlaceholder("StringLiteral") || + super.parseImportSource(...arguments) + ); + } + }; diff --git a/packages/babel-parser/src/types.js b/packages/babel-parser/src/types.js index 35d79c9ce9..e3a584ddc3 100644 --- a/packages/babel-parser/src/types.js +++ b/packages/babel-parser/src/types.js @@ -3,6 +3,7 @@ import type { SourceType } from "./options"; import type { Token } from "./tokenizer"; import type { SourceLocation } from "./util/location"; +import type { PlaceholderTypes } from "./plugins/placeholders"; /* * If making any changes to the AST, update: @@ -45,6 +46,7 @@ export type Pattern = | ArrayPattern | RestElement | AssignmentPattern; +//| Placeholder<"Pattern">; export type Declaration = | VariableDeclaration | ClassDeclaration @@ -53,6 +55,8 @@ export type Declaration = | TsTypeAliasDeclaration | TsEnumDeclaration | TsModuleDeclaration; +// | Placeholder<"Declaration">; + export type DeclarationBase = NodeBase & { // TypeScript allows declarations to be prefixed by `declare`. //TODO: a FunctionDeclaration is never "declare", because it's a TSDeclareFunction instead. @@ -78,6 +82,7 @@ export type Identifier = PatternBase & { // TypeScript only. Used in case of an optional parameter. optional?: ?true, }; +// | Placeholder<"Identifier">; export type PrivateName = NodeBase & { type: "PrivateName", @@ -188,6 +193,7 @@ export type BlockStatement = NodeBase & { body: Array, // TODO: $ReadOnlyArray directives: $ReadOnlyArray, }; +// | Placeholder<"BlockStatement">; export type EmptyStatement = NodeBase & { type: "EmptyStatement", @@ -682,6 +688,7 @@ export type ClassBody = NodeBase & { type: "ClassBody", body: Array, // TODO: $ReadOnlyArray }; +// | Placeholder<"ClassBody">; export type ClassMemberBase = NodeBase & HasDecorators & { @@ -1421,6 +1428,16 @@ export type TsNonNullExpression = NodeBase & { expression: Expression, }; +// ================ +// Babel placeholders %%foo%% +// ================ + +export type Placeholder = NodeBase & { + type: "Placeholder", + id: Identifier, + expectedNode: N, +}; + // ================ // Other // ================ diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-methods/failure-spaces/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-methods/failure-spaces/options.json index f8dba0c322..9914950b66 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-methods/failure-spaces/options.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-methods/failure-spaces/options.json @@ -1,4 +1,4 @@ { - "throws": "Unexpected space between # and identifier (2:5)", + "throws": "Unexpected space between # and identifier (2:3)", "plugins": ["classPrivateMethods"] } diff --git a/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-spaces/options.json b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-spaces/options.json index f8dba0c322..9914950b66 100644 --- a/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-spaces/options.json +++ b/packages/babel-parser/test/fixtures/experimental/class-private-properties/failure-spaces/options.json @@ -1,4 +1,4 @@ { - "throws": "Unexpected space between # and identifier (2:5)", + "throws": "Unexpected space between # and identifier (2:3)", "plugins": ["classPrivateMethods"] } diff --git a/packages/babel-parser/test/fixtures/placeholders/_errors/no-plugin/input.js b/packages/babel-parser/test/fixtures/placeholders/_errors/no-plugin/input.js new file mode 100644 index 0000000000..06d3e367d7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/_errors/no-plugin/input.js @@ -0,0 +1 @@ +%%FOO%% \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/_errors/no-plugin/options.json b/packages/babel-parser/test/fixtures/placeholders/_errors/no-plugin/options.json new file mode 100644 index 0000000000..550f9f8667 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/_errors/no-plugin/options.json @@ -0,0 +1,4 @@ +{ + "plugins": [], + "throws": "Unexpected token (1:0)" +} diff --git a/packages/babel-parser/test/fixtures/placeholders/_errors/space-after/input.js b/packages/babel-parser/test/fixtures/placeholders/_errors/space-after/input.js new file mode 100644 index 0000000000..f0c987242e --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/_errors/space-after/input.js @@ -0,0 +1 @@ +%%FOO %% \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/_errors/space-after/options.json b/packages/babel-parser/test/fixtures/placeholders/_errors/space-after/options.json new file mode 100644 index 0000000000..a307a35df6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/_errors/space-after/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["placeholders"], + "throws": "Unexpected space in placeholder. (1:5)" +} diff --git a/packages/babel-parser/test/fixtures/placeholders/_errors/space-before/input.js b/packages/babel-parser/test/fixtures/placeholders/_errors/space-before/input.js new file mode 100644 index 0000000000..a19d1a7dbf --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/_errors/space-before/input.js @@ -0,0 +1 @@ +%% FOO%% \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/_errors/space-before/options.json b/packages/babel-parser/test/fixtures/placeholders/_errors/space-before/options.json new file mode 100644 index 0000000000..2d76cfab7e --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/_errors/space-before/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["placeholders"], + "throws": "Unexpected space in placeholder. (1:2)" +} diff --git a/packages/babel-parser/test/fixtures/placeholders/arrow/async-parenless/input.js b/packages/babel-parser/test/fixtures/placeholders/arrow/async-parenless/input.js new file mode 100644 index 0000000000..ccc04f6163 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/arrow/async-parenless/input.js @@ -0,0 +1 @@ +async %%PARAM%% => %%BODY%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/arrow/async-parenless/options.json b/packages/babel-parser/test/fixtures/placeholders/arrow/async-parenless/options.json new file mode 100644 index 0000000000..91e2a8bf91 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/arrow/async-parenless/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["placeholders"], + "throws": "Unexpected token, expected \";\" (1:6)" +} diff --git a/packages/babel-parser/test/fixtures/placeholders/arrow/async/input.js b/packages/babel-parser/test/fixtures/placeholders/arrow/async/input.js new file mode 100644 index 0000000000..5620afc8e8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/arrow/async/input.js @@ -0,0 +1 @@ +async (%%PARAM%%) => %%BODY%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/arrow/async/output.json b/packages/babel-parser/test/fixtures/placeholders/arrow/async/output.json new file mode 100644 index 0000000000..4896328afd --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/arrow/async/output.json @@ -0,0 +1,136 @@ +{ + "type": "File", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "id": null, + "generator": false, + "async": true, + "params": [ + { + "type": "Placeholder", + "start": 7, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "name": { + "type": "Identifier", + "start": 9, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "PARAM" + }, + "name": "PARAM" + }, + "expectedNode": "Pattern" + } + ], + "body": { + "type": "Placeholder", + "start": 21, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "name": { + "type": "Identifier", + "start": 23, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 27 + }, + "identifierName": "BODY" + }, + "name": "BODY" + }, + "expectedNode": "Expression" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/arrow/sync-parenless/input.js b/packages/babel-parser/test/fixtures/placeholders/arrow/sync-parenless/input.js new file mode 100644 index 0000000000..03f6196a92 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/arrow/sync-parenless/input.js @@ -0,0 +1 @@ +%%PARAM%% => %%BODY%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/arrow/sync-parenless/options.json b/packages/babel-parser/test/fixtures/placeholders/arrow/sync-parenless/options.json new file mode 100644 index 0000000000..c2a8ef725f --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/arrow/sync-parenless/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["placeholders"], + "throws": "Unexpected token, expected \";\" (1:10)" +} diff --git a/packages/babel-parser/test/fixtures/placeholders/arrow/sync/input.js b/packages/babel-parser/test/fixtures/placeholders/arrow/sync/input.js new file mode 100644 index 0000000000..d8e462edb4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/arrow/sync/input.js @@ -0,0 +1 @@ +(%%PARAM%%) => %%BODY%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/arrow/sync/output.json b/packages/babel-parser/test/fixtures/placeholders/arrow/sync/output.json new file mode 100644 index 0000000000..6b0b16b70f --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/arrow/sync/output.json @@ -0,0 +1,136 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "expression": { + "type": "ArrowFunctionExpression", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Placeholder", + "start": 1, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 1 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "name": { + "type": "Identifier", + "start": 3, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 3 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "PARAM" + }, + "name": "PARAM" + }, + "expectedNode": "Pattern" + } + ], + "body": { + "type": "Placeholder", + "start": 15, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "name": { + "type": "Identifier", + "start": 17, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "BODY" + }, + "name": "BODY" + }, + "expectedNode": "Expression" + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/class/body_expression/input.js b/packages/babel-parser/test/fixtures/placeholders/class/body_expression/input.js new file mode 100644 index 0000000000..9789bed118 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/body_expression/input.js @@ -0,0 +1 @@ +void class %%BODY%% \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/class/body_expression/output.json b/packages/babel-parser/test/fixtures/placeholders/class/body_expression/output.json new file mode 100644 index 0000000000..6196640684 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/body_expression/output.json @@ -0,0 +1,116 @@ +{ + "type": "File", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "expression": { + "type": "UnaryExpression", + "start": 0, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "operator": "void", + "prefix": true, + "argument": { + "type": "ClassExpression", + "start": 5, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "id": null, + "body": { + "type": "Placeholder", + "start": 11, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "name": { + "type": "Identifier", + "start": 13, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 17 + }, + "identifierName": "BODY" + }, + "name": "BODY" + }, + "expectedNode": "ClassBody" + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/class/body_statement/input.js b/packages/babel-parser/test/fixtures/placeholders/class/body_statement/input.js new file mode 100644 index 0000000000..4447c2e48a --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/body_statement/input.js @@ -0,0 +1 @@ +class Cl %%BODY%% \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/class/body_statement/output.json b/packages/babel-parser/test/fixtures/placeholders/class/body_statement/output.json new file mode 100644 index 0000000000..70f4a63652 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/body_statement/output.json @@ -0,0 +1,101 @@ +{ + "type": "File", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "Cl" + }, + "name": "Cl" + }, + "superClass": null, + "body": { + "type": "Placeholder", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "BODY" + }, + "name": "BODY" + }, + "expectedNode": "ClassBody" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/class/decorators/input.js b/packages/babel-parser/test/fixtures/placeholders/class/decorators/input.js new file mode 100644 index 0000000000..3373242045 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/decorators/input.js @@ -0,0 +1,2 @@ +@(%%FOO%%) +class A {} diff --git a/packages/babel-parser/test/fixtures/placeholders/class/decorators/options.json b/packages/babel-parser/test/fixtures/placeholders/class/decorators/options.json new file mode 100644 index 0000000000..f453a9b6ab --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/decorators/options.json @@ -0,0 +1,6 @@ +{ + "plugins": [ + "placeholders", + ["decorators", { "decoratorsBeforeExport": true }] + ] +} diff --git a/packages/babel-parser/test/fixtures/placeholders/class/decorators/output.json b/packages/babel-parser/test/fixtures/placeholders/class/decorators/output.json new file mode 100644 index 0000000000..459dacb35f --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/decorators/output.json @@ -0,0 +1,134 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "decorators": [ + { + "type": "Decorator", + "start": 0, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "expression": { + "type": "Placeholder", + "start": 2, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "name": { + "type": "Identifier", + "start": 4, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 7 + }, + "identifierName": "FOO" + }, + "name": "FOO" + }, + "expectedNode": "Expression" + } + } + ], + "id": { + "type": "Identifier", + "start": 17, + "end": 18, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 7 + }, + "identifierName": "A" + }, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 19, + "end": 21, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 10 + } + }, + "body": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/class/id-body/input.js b/packages/babel-parser/test/fixtures/placeholders/class/id-body/input.js new file mode 100644 index 0000000000..e6b57a64de --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/id-body/input.js @@ -0,0 +1 @@ +class %%ID%% %%BODY%% diff --git a/packages/babel-parser/test/fixtures/placeholders/class/id-body/output.json b/packages/babel-parser/test/fixtures/placeholders/class/id-body/output.json new file mode 100644 index 0000000000..0fe8c71d47 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/id-body/output.json @@ -0,0 +1,117 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "id": { + "type": "Placeholder", + "start": 6, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "name": { + "type": "Identifier", + "start": 8, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "ID" + }, + "name": "ID" + }, + "expectedNode": "Identifier" + }, + "superClass": null, + "body": { + "type": "Placeholder", + "start": 13, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "name": { + "type": "Identifier", + "start": 15, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "BODY" + }, + "name": "BODY" + }, + "expectedNode": "ClassBody" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/class/id-super-body/input.js b/packages/babel-parser/test/fixtures/placeholders/class/id-super-body/input.js new file mode 100644 index 0000000000..30edd2cb7f --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/id-super-body/input.js @@ -0,0 +1 @@ +class %%ID%% extends %%SUPER%% %%BODY%% diff --git a/packages/babel-parser/test/fixtures/placeholders/class/id-super-body/output.json b/packages/babel-parser/test/fixtures/placeholders/class/id-super-body/output.json new file mode 100644 index 0000000000..b891fe7c30 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/id-super-body/output.json @@ -0,0 +1,149 @@ +{ + "type": "File", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "id": { + "type": "Placeholder", + "start": 6, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "name": { + "type": "Identifier", + "start": 8, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "ID" + }, + "name": "ID" + }, + "expectedNode": "Identifier" + }, + "superClass": { + "type": "Placeholder", + "start": 21, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "name": { + "type": "Identifier", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "SUPER" + }, + "name": "SUPER" + }, + "expectedNode": "Expression" + }, + "body": { + "type": "Placeholder", + "start": 31, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "name": { + "type": "Identifier", + "start": 33, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 33 + }, + "end": { + "line": 1, + "column": 37 + }, + "identifierName": "BODY" + }, + "name": "BODY" + }, + "expectedNode": "ClassBody" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/class/id-super/input.js b/packages/babel-parser/test/fixtures/placeholders/class/id-super/input.js new file mode 100644 index 0000000000..2f652c767e --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/id-super/input.js @@ -0,0 +1 @@ +class %%ID%% extends %%SUPER%% {} diff --git a/packages/babel-parser/test/fixtures/placeholders/class/id-super/output.json b/packages/babel-parser/test/fixtures/placeholders/class/id-super/output.json new file mode 100644 index 0000000000..cde4f271b7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/id-super/output.json @@ -0,0 +1,132 @@ +{ + "type": "File", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "id": { + "type": "Placeholder", + "start": 6, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "name": { + "type": "Identifier", + "start": 8, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "ID" + }, + "name": "ID" + }, + "expectedNode": "Identifier" + }, + "superClass": { + "type": "Placeholder", + "start": 21, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "name": { + "type": "Identifier", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "SUPER" + }, + "name": "SUPER" + }, + "expectedNode": "Expression" + }, + "body": { + "type": "ClassBody", + "start": 31, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 31 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "body": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/class/id_expression/input.js b/packages/babel-parser/test/fixtures/placeholders/class/id_expression/input.js new file mode 100644 index 0000000000..d6f2785faa --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/id_expression/input.js @@ -0,0 +1 @@ +void class %%ID%% {} diff --git a/packages/babel-parser/test/fixtures/placeholders/class/id_expression/output.json b/packages/babel-parser/test/fixtures/placeholders/class/id_expression/output.json new file mode 100644 index 0000000000..8ec0bdeaeb --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/id_expression/output.json @@ -0,0 +1,132 @@ +{ + "type": "File", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "expression": { + "type": "UnaryExpression", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "operator": "void", + "prefix": true, + "argument": { + "type": "ClassExpression", + "start": 5, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "id": { + "type": "Placeholder", + "start": 11, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "ID" + }, + "name": "ID" + }, + "expectedNode": "Identifier" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 18, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "body": [] + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/class/id_statement/input.js b/packages/babel-parser/test/fixtures/placeholders/class/id_statement/input.js new file mode 100644 index 0000000000..b56524d157 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/id_statement/input.js @@ -0,0 +1 @@ +class %%ID%% {} diff --git a/packages/babel-parser/test/fixtures/placeholders/class/id_statement/output.json b/packages/babel-parser/test/fixtures/placeholders/class/id_statement/output.json new file mode 100644 index 0000000000..61ecc899ae --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/id_statement/output.json @@ -0,0 +1,100 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "id": { + "type": "Placeholder", + "start": 6, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 12 + } + }, + "name": { + "type": "Identifier", + "start": 8, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "ID" + }, + "name": "ID" + }, + "expectedNode": "Identifier" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 13, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "body": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/class/super/input.js b/packages/babel-parser/test/fixtures/placeholders/class/super/input.js new file mode 100644 index 0000000000..ce315dbaa6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/super/input.js @@ -0,0 +1 @@ +class Cl extends %%SUPER%% {} diff --git a/packages/babel-parser/test/fixtures/placeholders/class/super/output.json b/packages/babel-parser/test/fixtures/placeholders/class/super/output.json new file mode 100644 index 0000000000..966639d5d3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/class/super/output.json @@ -0,0 +1,116 @@ +{ + "type": "File", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 8 + }, + "identifierName": "Cl" + }, + "name": "Cl" + }, + "superClass": { + "type": "Placeholder", + "start": 17, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "name": { + "type": "Identifier", + "start": 19, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 24 + }, + "identifierName": "SUPER" + }, + "name": "SUPER" + }, + "expectedNode": "Expression" + }, + "body": { + "type": "ClassBody", + "start": 27, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "body": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/declaration/input.js b/packages/babel-parser/test/fixtures/placeholders/export/declaration/input.js new file mode 100644 index 0000000000..e066474912 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/declaration/input.js @@ -0,0 +1 @@ +export %%DECL%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/declaration/output.json b/packages/babel-parser/test/fixtures/placeholders/export/declaration/output.json new file mode 100644 index 0000000000..a0cc4fb211 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/declaration/output.json @@ -0,0 +1,100 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "specifiers": [], + "source": null, + "declaration": { + "type": "Placeholder", + "start": 7, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "name": { + "type": "Identifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "DECL" + }, + "name": "DECL" + }, + "expectedNode": "Declaration" + } + }, + { + "type": "EmptyStatement", + "start": 15, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 16 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/default-default-from/input.js b/packages/babel-parser/test/fixtures/placeholders/export/default-default-from/input.js new file mode 100644 index 0000000000..e9e71b211a --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/default-default-from/input.js @@ -0,0 +1 @@ +export default from %%FILE%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/default-default-from/options.json b/packages/babel-parser/test/fixtures/placeholders/export/default-default-from/options.json new file mode 100644 index 0000000000..b3f883263b --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/default-default-from/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "placeholders" + ], + "sourceType": "module", + "throws": "This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom' (1:7)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/default-named-from-2/input.js b/packages/babel-parser/test/fixtures/placeholders/export/default-named-from-2/input.js new file mode 100644 index 0000000000..acd2d28ed6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/default-named-from-2/input.js @@ -0,0 +1 @@ +export %%NAME%% from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/default-named-from-2/options.json b/packages/babel-parser/test/fixtures/placeholders/export/default-named-from-2/options.json new file mode 100644 index 0000000000..404b94bc6c --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/default-named-from-2/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "placeholders" + ], + "sourceType": "module", + "throws": "This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom' (1:16)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/default-named-from-3/input.js b/packages/babel-parser/test/fixtures/placeholders/export/default-named-from-3/input.js new file mode 100644 index 0000000000..a2ac20ea9b --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/default-named-from-3/input.js @@ -0,0 +1 @@ +export %%NAME%% from %%FILE%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/default-named-from-3/options.json b/packages/babel-parser/test/fixtures/placeholders/export/default-named-from-3/options.json new file mode 100644 index 0000000000..404b94bc6c --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/default-named-from-3/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "placeholders" + ], + "sourceType": "module", + "throws": "This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom' (1:16)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/default-named-from/input.js b/packages/babel-parser/test/fixtures/placeholders/export/default-named-from/input.js new file mode 100644 index 0000000000..2ec55e24cc --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/default-named-from/input.js @@ -0,0 +1 @@ +export name from %%FILE%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/default-named-from/options.json b/packages/babel-parser/test/fixtures/placeholders/export/default-named-from/options.json new file mode 100644 index 0000000000..b3f883263b --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/default-named-from/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "placeholders" + ], + "sourceType": "module", + "throws": "This experimental syntax requires enabling the parser plugin: 'exportDefaultFrom' (1:7)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-alias-2/input.js b/packages/babel-parser/test/fixtures/placeholders/export/named-alias-2/input.js new file mode 100644 index 0000000000..ccc71c84d0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-alias-2/input.js @@ -0,0 +1 @@ +export { name as %%ALIAS%% }; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-alias-2/output.json b/packages/babel-parser/test/fixtures/placeholders/export/named-alias-2/output.json new file mode 100644 index 0000000000..3da7a5b3b5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-alias-2/output.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "local": { + "type": "Identifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "name" + }, + "name": "name" + }, + "exported": { + "type": "Placeholder", + "start": 17, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "name": { + "type": "Identifier", + "start": 19, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 24 + }, + "identifierName": "ALIAS" + }, + "name": "ALIAS" + }, + "expectedNode": "Identifier" + } + } + ], + "source": null, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-alias-3/input.js b/packages/babel-parser/test/fixtures/placeholders/export/named-alias-3/input.js new file mode 100644 index 0000000000..ebe9a78080 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-alias-3/input.js @@ -0,0 +1 @@ +export { %%NAME%% as %%ALIAS%% }; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-alias-3/output.json b/packages/babel-parser/test/fixtures/placeholders/export/named-alias-3/output.json new file mode 100644 index 0000000000..79bf65de11 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-alias-3/output.json @@ -0,0 +1,135 @@ +{ + "type": "File", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "local": { + "type": "Placeholder", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "NAME" + }, + "name": "NAME" + }, + "expectedNode": "Identifier" + }, + "exported": { + "type": "Placeholder", + "start": 21, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "name": { + "type": "Identifier", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "ALIAS" + }, + "name": "ALIAS" + }, + "expectedNode": "Identifier" + } + } + ], + "source": null, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-alias/input.js b/packages/babel-parser/test/fixtures/placeholders/export/named-alias/input.js new file mode 100644 index 0000000000..ff261bd263 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-alias/input.js @@ -0,0 +1 @@ +export { %%NAME%% as alias }; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-alias/output.json b/packages/babel-parser/test/fixtures/placeholders/export/named-alias/output.json new file mode 100644 index 0000000000..ddabad2b64 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-alias/output.json @@ -0,0 +1,119 @@ +{ + "type": "File", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "local": { + "type": "Placeholder", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "NAME" + }, + "name": "NAME" + }, + "expectedNode": "Identifier" + }, + "exported": { + "type": "Identifier", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "alias" + }, + "name": "alias" + } + } + ], + "source": null, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-from-2/input.js b/packages/babel-parser/test/fixtures/placeholders/export/named-from-2/input.js new file mode 100644 index 0000000000..3bf7f2ff4f --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-from-2/input.js @@ -0,0 +1 @@ +export { name } from %%FILE%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-from-2/output.json b/packages/babel-parser/test/fixtures/placeholders/export/named-from-2/output.json new file mode 100644 index 0000000000..5d7db268eb --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-from-2/output.json @@ -0,0 +1,135 @@ +{ + "type": "File", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + } + }, + "local": { + "type": "Identifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "name" + }, + "name": "name" + }, + "exported": { + "type": "Identifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "name" + }, + "name": "name" + } + } + ], + "source": { + "type": "Placeholder", + "start": 21, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "name": { + "type": "Identifier", + "start": 23, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 27 + }, + "identifierName": "FILE" + }, + "name": "FILE" + }, + "expectedNode": "StringLiteral" + }, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-from-3/input.js b/packages/babel-parser/test/fixtures/placeholders/export/named-from-3/input.js new file mode 100644 index 0000000000..0a86eaa83c --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-from-3/input.js @@ -0,0 +1 @@ +export { %%NAME%% } from %%FILE%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-from-3/output.json b/packages/babel-parser/test/fixtures/placeholders/export/named-from-3/output.json new file mode 100644 index 0000000000..f89643fc0a --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-from-3/output.json @@ -0,0 +1,167 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "local": { + "type": "Placeholder", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "NAME" + }, + "name": "NAME" + }, + "expectedNode": "Identifier" + }, + "exported": { + "type": "Placeholder", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "NAME" + }, + "name": "NAME" + }, + "expectedNode": "Identifier" + } + } + ], + "source": { + "type": "Placeholder", + "start": 25, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "name": { + "type": "Identifier", + "start": 27, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 31 + }, + "identifierName": "FILE" + }, + "name": "FILE" + }, + "expectedNode": "StringLiteral" + }, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-2/input.js b/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-2/input.js new file mode 100644 index 0000000000..7a9d409e87 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-2/input.js @@ -0,0 +1 @@ +export { name as %%ALIAS%% } from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-2/output.json b/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-2/output.json new file mode 100644 index 0000000000..637b5256b8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-2/output.json @@ -0,0 +1,138 @@ +{ + "type": "File", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "local": { + "type": "Identifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "name" + }, + "name": "name" + }, + "exported": { + "type": "Placeholder", + "start": 17, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "name": { + "type": "Identifier", + "start": 19, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 24 + }, + "identifierName": "ALIAS" + }, + "name": "ALIAS" + }, + "expectedNode": "Identifier" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 34, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + }, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-3/input.js b/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-3/input.js new file mode 100644 index 0000000000..0fc04b4a2f --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-3/input.js @@ -0,0 +1 @@ +export { %%NAME%% as %%ALIAS%% } from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-3/output.json b/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-3/output.json new file mode 100644 index 0000000000..2fd4cc6f3a --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias-3/output.json @@ -0,0 +1,154 @@ +{ + "type": "File", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "local": { + "type": "Placeholder", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "NAME" + }, + "name": "NAME" + }, + "expectedNode": "Identifier" + }, + "exported": { + "type": "Placeholder", + "start": 21, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "name": { + "type": "Identifier", + "start": 23, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "ALIAS" + }, + "name": "ALIAS" + }, + "expectedNode": "Identifier" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 38, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 44 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + }, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias/input.js b/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias/input.js new file mode 100644 index 0000000000..395bf89474 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias/input.js @@ -0,0 +1 @@ +export { %%NAME%% as alias } from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias/output.json b/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias/output.json new file mode 100644 index 0000000000..34e8dd6e3a --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-from-alias/output.json @@ -0,0 +1,138 @@ +{ + "type": "File", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "local": { + "type": "Placeholder", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "NAME" + }, + "name": "NAME" + }, + "expectedNode": "Identifier" + }, + "exported": { + "type": "Identifier", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "alias" + }, + "name": "alias" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 34, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 34 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + }, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-from/input.js b/packages/babel-parser/test/fixtures/placeholders/export/named-from/input.js new file mode 100644 index 0000000000..c74dfbf297 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-from/input.js @@ -0,0 +1 @@ +export { %%NAME%% } from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named-from/output.json b/packages/babel-parser/test/fixtures/placeholders/export/named-from/output.json new file mode 100644 index 0000000000..5c9ae8516d --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named-from/output.json @@ -0,0 +1,154 @@ +{ + "type": "File", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "local": { + "type": "Placeholder", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "NAME" + }, + "name": "NAME" + }, + "expectedNode": "Identifier" + }, + "exported": { + "type": "Placeholder", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "NAME" + }, + "name": "NAME" + }, + "expectedNode": "Identifier" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 25, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + }, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named/input.js b/packages/babel-parser/test/fixtures/placeholders/export/named/input.js new file mode 100644 index 0000000000..03cd701e26 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named/input.js @@ -0,0 +1 @@ +export { %%NAME%% }; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/named/output.json b/packages/babel-parser/test/fixtures/placeholders/export/named/output.json new file mode 100644 index 0000000000..67b0f0429f --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/named/output.json @@ -0,0 +1,135 @@ +{ + "type": "File", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "specifiers": [ + { + "type": "ExportSpecifier", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "local": { + "type": "Placeholder", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "NAME" + }, + "name": "NAME" + }, + "expectedNode": "Identifier" + }, + "exported": { + "type": "Placeholder", + "start": 9, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "NAME" + }, + "name": "NAME" + }, + "expectedNode": "Identifier" + } + } + ], + "source": null, + "declaration": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/options.json b/packages/babel-parser/test/fixtures/placeholders/export/options.json new file mode 100644 index 0000000000..e7ff26ae70 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["placeholders", "exportDefaultFrom", "exportNamespaceFrom"], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/placeholders/export/star-from-2/input.js b/packages/babel-parser/test/fixtures/placeholders/export/star-from-2/input.js new file mode 100644 index 0000000000..8a6343daed --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/star-from-2/input.js @@ -0,0 +1 @@ +export * as %%STAR%% from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/star-from-2/options.json b/packages/babel-parser/test/fixtures/placeholders/export/star-from-2/options.json new file mode 100644 index 0000000000..8c48e4fc0f --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/star-from-2/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "placeholders" + ], + "sourceType": "module", + "throws": "This experimental syntax requires enabling the parser plugin: 'exportNamespaceFrom' (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/star-from-3/input.js b/packages/babel-parser/test/fixtures/placeholders/export/star-from-3/input.js new file mode 100644 index 0000000000..cdb7248670 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/star-from-3/input.js @@ -0,0 +1 @@ +export * as %%STAR%% from %%FILE%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/star-from-3/options.json b/packages/babel-parser/test/fixtures/placeholders/export/star-from-3/options.json new file mode 100644 index 0000000000..8c48e4fc0f --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/star-from-3/options.json @@ -0,0 +1,7 @@ +{ + "plugins": [ + "placeholders" + ], + "sourceType": "module", + "throws": "This experimental syntax requires enabling the parser plugin: 'exportNamespaceFrom' (1:9)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/export/star-from/input.js b/packages/babel-parser/test/fixtures/placeholders/export/star-from/input.js new file mode 100644 index 0000000000..87fc3f0d36 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/star-from/input.js @@ -0,0 +1 @@ +export * from %%FILE%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/export/star-from/output.json b/packages/babel-parser/test/fixtures/placeholders/export/star-from/output.json new file mode 100644 index 0000000000..87a3012121 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/export/star-from/output.json @@ -0,0 +1,83 @@ +{ + "type": "File", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportAllDeclaration", + "start": 0, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "source": { + "type": "Placeholder", + "start": 14, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "name": { + "type": "Identifier", + "start": 16, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 20 + }, + "identifierName": "FILE" + }, + "name": "FILE" + }, + "expectedNode": "StringLiteral" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/expression/01/input.js b/packages/babel-parser/test/fixtures/placeholders/expression/01/input.js new file mode 100644 index 0000000000..1ca196c414 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/expression/01/input.js @@ -0,0 +1 @@ +%%FOO%% + %%BAR%%(%%BAZ%%); \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/expression/01/output.json b/packages/babel-parser/test/fixtures/placeholders/expression/01/output.json new file mode 100644 index 0000000000..9de9b6f77e --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/expression/01/output.json @@ -0,0 +1,182 @@ +{ + "type": "File", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "expression": { + "type": "BinaryExpression", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "left": { + "type": "Placeholder", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "name": { + "type": "Identifier", + "start": 2, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "FOO" + }, + "name": "FOO" + }, + "expectedNode": "Expression" + }, + "operator": "+", + "right": { + "type": "CallExpression", + "start": 10, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "callee": { + "type": "Placeholder", + "start": 10, + "end": 17, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 12, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "BAR" + }, + "name": "BAR" + }, + "expectedNode": "Expression" + }, + "arguments": [ + { + "type": "Placeholder", + "start": 18, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "name": { + "type": "Identifier", + "start": 20, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "BAZ" + }, + "name": "BAZ" + }, + "expectedNode": "Expression" + } + ] + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/expression/options.json b/packages/babel-parser/test/fixtures/placeholders/expression/options.json new file mode 100644 index 0000000000..92404e5012 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/expression/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["placeholders"] +} diff --git a/packages/babel-parser/test/fixtures/placeholders/function/body/input.js b/packages/babel-parser/test/fixtures/placeholders/function/body/input.js new file mode 100644 index 0000000000..09db19b409 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/function/body/input.js @@ -0,0 +1 @@ +function f() %%BODY%% diff --git a/packages/babel-parser/test/fixtures/placeholders/function/body/output.json b/packages/babel-parser/test/fixtures/placeholders/function/body/output.json new file mode 100644 index 0000000000..3139e31321 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/function/body/output.json @@ -0,0 +1,103 @@ +{ + "type": "File", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "f" + }, + "name": "f" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "Placeholder", + "start": 13, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "name": { + "type": "Identifier", + "start": 15, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 19 + }, + "identifierName": "BODY" + }, + "name": "BODY" + }, + "expectedNode": "BlockStatement" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/function/id-params-body/input.js b/packages/babel-parser/test/fixtures/placeholders/function/id-params-body/input.js new file mode 100644 index 0000000000..9f0f6607b3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/function/id-params-body/input.js @@ -0,0 +1 @@ +function %%ID%%(%%PARAM%%, %%PARAM%%) %%BODY%% diff --git a/packages/babel-parser/test/fixtures/placeholders/function/id-params-body/output.json b/packages/babel-parser/test/fixtures/placeholders/function/id-params-body/output.json new file mode 100644 index 0000000000..fd6205f7ab --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/function/id-params-body/output.json @@ -0,0 +1,186 @@ +{ + "type": "File", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "id": { + "type": "Placeholder", + "start": 9, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "ID" + }, + "name": "ID" + }, + "expectedNode": "Identifier" + }, + "generator": false, + "async": false, + "params": [ + { + "type": "Placeholder", + "start": 16, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "name": { + "type": "Identifier", + "start": 18, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "PARAM" + }, + "name": "PARAM" + }, + "expectedNode": "Pattern" + }, + { + "type": "Placeholder", + "start": 27, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 36 + } + }, + "name": { + "type": "Identifier", + "start": 29, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 29 + }, + "end": { + "line": 1, + "column": 34 + }, + "identifierName": "PARAM" + }, + "name": "PARAM" + }, + "expectedNode": "Pattern" + } + ], + "body": { + "type": "Placeholder", + "start": 38, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "name": { + "type": "Identifier", + "start": 40, + "end": 44, + "loc": { + "start": { + "line": 1, + "column": 40 + }, + "end": { + "line": 1, + "column": 44 + }, + "identifierName": "BODY" + }, + "name": "BODY" + }, + "expectedNode": "BlockStatement" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/function/id_declaration/input.js b/packages/babel-parser/test/fixtures/placeholders/function/id_declaration/input.js new file mode 100644 index 0000000000..8afee84ad0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/function/id_declaration/input.js @@ -0,0 +1 @@ +function %%ID%%() {} diff --git a/packages/babel-parser/test/fixtures/placeholders/function/id_declaration/output.json b/packages/babel-parser/test/fixtures/placeholders/function/id_declaration/output.json new file mode 100644 index 0000000000..a07531190e --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/function/id_declaration/output.json @@ -0,0 +1,103 @@ +{ + "type": "File", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "id": { + "type": "Placeholder", + "start": 9, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "ID" + }, + "name": "ID" + }, + "expectedNode": "Identifier" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 18, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/function/id_expression/input.js b/packages/babel-parser/test/fixtures/placeholders/function/id_expression/input.js new file mode 100644 index 0000000000..69db50cde0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/function/id_expression/input.js @@ -0,0 +1 @@ +void function %%ID%%() {}; diff --git a/packages/babel-parser/test/fixtures/placeholders/function/id_expression/output.json b/packages/babel-parser/test/fixtures/placeholders/function/id_expression/output.json new file mode 100644 index 0000000000..1bc90cefa7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/function/id_expression/output.json @@ -0,0 +1,135 @@ +{ + "type": "File", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start": 0, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "expression": { + "type": "UnaryExpression", + "start": 0, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "operator": "void", + "prefix": true, + "argument": { + "type": "FunctionExpression", + "start": 5, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 5 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "id": { + "type": "Placeholder", + "start": 14, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "name": { + "type": "Identifier", + "start": 16, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "ID" + }, + "name": "ID" + }, + "expectedNode": "Identifier" + }, + "generator": false, + "async": false, + "params": [], + "body": { + "type": "BlockStatement", + "start": 23, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 25 + } + }, + "body": [], + "directives": [] + } + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/function/param/input.js b/packages/babel-parser/test/fixtures/placeholders/function/param/input.js new file mode 100644 index 0000000000..f06bb04314 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/function/param/input.js @@ -0,0 +1 @@ +function f(%%PARAM%%) {} diff --git a/packages/babel-parser/test/fixtures/placeholders/function/param/output.json b/packages/babel-parser/test/fixtures/placeholders/function/param/output.json new file mode 100644 index 0000000000..9026f46c40 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/function/param/output.json @@ -0,0 +1,121 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + }, + "identifierName": "f" + }, + "name": "f" + }, + "generator": false, + "async": false, + "params": [ + { + "type": "Placeholder", + "start": 11, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "name": { + "type": "Identifier", + "start": 13, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "PARAM" + }, + "name": "PARAM" + }, + "expectedNode": "Pattern" + } + ], + "body": { + "type": "BlockStatement", + "start": 22, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default-file/input.mjs b/packages/babel-parser/test/fixtures/placeholders/import/default-file/input.mjs new file mode 100644 index 0000000000..d4e434f4cc --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default-file/input.mjs @@ -0,0 +1 @@ +import %%DEFAULT%% from %%FILE%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default-file/output.json b/packages/babel-parser/test/fixtures/placeholders/import/default-file/output.json new file mode 100644 index 0000000000..b4fdc7e984 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default-file/output.json @@ -0,0 +1,133 @@ +{ + "type": "File", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 7, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "local": { + "type": "Placeholder", + "start": 7, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": { + "type": "Identifier", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "DEFAULT" + }, + "name": "DEFAULT" + }, + "expectedNode": "Identifier" + } + } + ], + "source": { + "type": "Placeholder", + "start": 24, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "name": { + "type": "Identifier", + "start": 26, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 30 + }, + "identifierName": "FILE" + }, + "name": "FILE" + }, + "expectedNode": "StringLiteral" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default-named-2/input.mjs b/packages/babel-parser/test/fixtures/placeholders/import/default-named-2/input.mjs new file mode 100644 index 0000000000..aca97b71e5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default-named-2/input.mjs @@ -0,0 +1 @@ +import %%DEFAULT%%, { named } from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default-named-2/output.json b/packages/babel-parser/test/fixtures/placeholders/import/default-named-2/output.json new file mode 100644 index 0000000000..3ec417645b --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default-named-2/output.json @@ -0,0 +1,169 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 7, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "local": { + "type": "Placeholder", + "start": 7, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": { + "type": "Identifier", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "DEFAULT" + }, + "name": "DEFAULT" + }, + "expectedNode": "Identifier" + } + }, + { + "type": "ImportSpecifier", + "start": 22, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "imported": { + "type": "Identifier", + "start": 22, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 27 + }, + "identifierName": "named" + }, + "name": "named" + }, + "local": { + "type": "Identifier", + "start": 22, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 27 + }, + "identifierName": "named" + }, + "name": "named" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 35, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default-named-3/input.mjs b/packages/babel-parser/test/fixtures/placeholders/import/default-named-3/input.mjs new file mode 100644 index 0000000000..42d98a2cb7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default-named-3/input.mjs @@ -0,0 +1 @@ +import %%DEFAULT%%, { %%NAMED%% } from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default-named-3/output.json b/packages/babel-parser/test/fixtures/placeholders/import/default-named-3/output.json new file mode 100644 index 0000000000..e681ffb184 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default-named-3/output.json @@ -0,0 +1,201 @@ +{ + "type": "File", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 7, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "local": { + "type": "Placeholder", + "start": 7, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": { + "type": "Identifier", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "DEFAULT" + }, + "name": "DEFAULT" + }, + "expectedNode": "Identifier" + } + }, + { + "type": "ImportSpecifier", + "start": 22, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "imported": { + "type": "Placeholder", + "start": 22, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "name": { + "type": "Identifier", + "start": 24, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 29 + }, + "identifierName": "NAMED" + }, + "name": "NAMED" + }, + "expectedNode": "Identifier" + }, + "local": { + "type": "Placeholder", + "start": 22, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "name": { + "type": "Identifier", + "start": 24, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 29 + }, + "identifierName": "NAMED" + }, + "name": "NAMED" + }, + "expectedNode": "Identifier" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 39, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default-named/input.mjs b/packages/babel-parser/test/fixtures/placeholders/import/default-named/input.mjs new file mode 100644 index 0000000000..5857bed1cd --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default-named/input.mjs @@ -0,0 +1 @@ +import _default, { %%NAMED%% } from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default-named/output.json b/packages/babel-parser/test/fixtures/placeholders/import/default-named/output.json new file mode 100644 index 0000000000..62d764263d --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default-named/output.json @@ -0,0 +1,185 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 7, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "local": { + "type": "Identifier", + "start": 7, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "_default" + }, + "name": "_default" + } + }, + { + "type": "ImportSpecifier", + "start": 19, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "imported": { + "type": "Placeholder", + "start": 19, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "name": { + "type": "Identifier", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "NAMED" + }, + "name": "NAMED" + }, + "expectedNode": "Identifier" + }, + "local": { + "type": "Placeholder", + "start": 19, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 19 + }, + "end": { + "line": 1, + "column": 28 + } + }, + "name": { + "type": "Identifier", + "start": 21, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 21 + }, + "end": { + "line": 1, + "column": 26 + }, + "identifierName": "NAMED" + }, + "name": "NAMED" + }, + "expectedNode": "Identifier" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 36, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default-star-2/input.mjs b/packages/babel-parser/test/fixtures/placeholders/import/default-star-2/input.mjs new file mode 100644 index 0000000000..32a49347ad --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default-star-2/input.mjs @@ -0,0 +1 @@ +import _default, * as %%STAR%% from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default-star-2/output.json b/packages/babel-parser/test/fixtures/placeholders/import/default-star-2/output.json new file mode 100644 index 0000000000..6fd8a2dbed --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default-star-2/output.json @@ -0,0 +1,152 @@ +{ + "type": "File", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 7, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "local": { + "type": "Identifier", + "start": 7, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 15 + }, + "identifierName": "_default" + }, + "name": "_default" + } + }, + { + "type": "ImportNamespaceSpecifier", + "start": 17, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "local": { + "type": "Placeholder", + "start": 22, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "name": { + "type": "Identifier", + "start": 24, + "end": 28, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 28 + }, + "identifierName": "STAR" + }, + "name": "STAR" + }, + "expectedNode": "Identifier" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 36, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default-star-3/input.mjs b/packages/babel-parser/test/fixtures/placeholders/import/default-star-3/input.mjs new file mode 100644 index 0000000000..f2cafcebae --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default-star-3/input.mjs @@ -0,0 +1 @@ +import %%DEFAULT%%, * as %%STAR%% from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default-star-3/output.json b/packages/babel-parser/test/fixtures/placeholders/import/default-star-3/output.json new file mode 100644 index 0000000000..a92281d074 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default-star-3/output.json @@ -0,0 +1,168 @@ +{ + "type": "File", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 7, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "local": { + "type": "Placeholder", + "start": 7, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": { + "type": "Identifier", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "DEFAULT" + }, + "name": "DEFAULT" + }, + "expectedNode": "Identifier" + } + }, + { + "type": "ImportNamespaceSpecifier", + "start": 20, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "local": { + "type": "Placeholder", + "start": 25, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "name": { + "type": "Identifier", + "start": 27, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 31 + }, + "identifierName": "STAR" + }, + "name": "STAR" + }, + "expectedNode": "Identifier" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 39, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default-star/input.mjs b/packages/babel-parser/test/fixtures/placeholders/import/default-star/input.mjs new file mode 100644 index 0000000000..97bb0fbb20 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default-star/input.mjs @@ -0,0 +1 @@ +import %%DEFAULT%%, * as star from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default-star/output.json b/packages/babel-parser/test/fixtures/placeholders/import/default-star/output.json new file mode 100644 index 0000000000..3976944a46 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default-star/output.json @@ -0,0 +1,152 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 7, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "local": { + "type": "Placeholder", + "start": 7, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": { + "type": "Identifier", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "DEFAULT" + }, + "name": "DEFAULT" + }, + "expectedNode": "Identifier" + } + }, + { + "type": "ImportNamespaceSpecifier", + "start": 20, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 29 + } + }, + "local": { + "type": "Identifier", + "start": 25, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 29 + }, + "identifierName": "star" + }, + "name": "star" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 35, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default/input.mjs b/packages/babel-parser/test/fixtures/placeholders/import/default/input.mjs new file mode 100644 index 0000000000..cbfc52e13d --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default/input.mjs @@ -0,0 +1 @@ +import %%DEFAULT%% from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/import/default/output.json b/packages/babel-parser/test/fixtures/placeholders/import/default/output.json new file mode 100644 index 0000000000..4ff0689564 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/default/output.json @@ -0,0 +1,120 @@ +{ + "type": "File", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start": 7, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "local": { + "type": "Placeholder", + "start": 7, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": { + "type": "Identifier", + "start": 9, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "DEFAULT" + }, + "name": "DEFAULT" + }, + "expectedNode": "Identifier" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 24, + "end": 30, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 30 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/file-empty/input.mjs b/packages/babel-parser/test/fixtures/placeholders/import/file-empty/input.mjs new file mode 100644 index 0000000000..1412ce08fe --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/file-empty/input.mjs @@ -0,0 +1 @@ +import {} from %%FILE%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/import/file-empty/output.json b/packages/babel-parser/test/fixtures/placeholders/import/file-empty/output.json new file mode 100644 index 0000000000..5690ee81f0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/file-empty/output.json @@ -0,0 +1,84 @@ +{ + "type": "File", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "specifiers": [], + "source": { + "type": "Placeholder", + "start": 15, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 15 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "name": { + "type": "Identifier", + "start": 17, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "FILE" + }, + "name": "FILE" + }, + "expectedNode": "StringLiteral" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/file/input.mjs b/packages/babel-parser/test/fixtures/placeholders/import/file/input.mjs new file mode 100644 index 0000000000..634197cbb7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/file/input.mjs @@ -0,0 +1 @@ +import %%FILE%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/import/file/output.json b/packages/babel-parser/test/fixtures/placeholders/import/file/output.json new file mode 100644 index 0000000000..e33e48771a --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/file/output.json @@ -0,0 +1,84 @@ +{ + "type": "File", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 16 + } + }, + "specifiers": [], + "source": { + "type": "Placeholder", + "start": 7, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "name": { + "type": "Identifier", + "start": 9, + "end": 13, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 13 + }, + "identifierName": "FILE" + }, + "name": "FILE" + }, + "expectedNode": "StringLiteral" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/named-alias-2/input.mjs b/packages/babel-parser/test/fixtures/placeholders/import/named-alias-2/input.mjs new file mode 100644 index 0000000000..114cf3db23 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/named-alias-2/input.mjs @@ -0,0 +1 @@ +import { %%NAMED%% as alias } from "file"; \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/named-alias-2/output.json b/packages/babel-parser/test/fixtures/placeholders/import/named-alias-2/output.json new file mode 100644 index 0000000000..c7d936e96c --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/named-alias-2/output.json @@ -0,0 +1,137 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "start": 9, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "imported": { + "type": "Placeholder", + "start": 9, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "NAMED" + }, + "name": "NAMED" + }, + "expectedNode": "Identifier" + }, + "local": { + "type": "Identifier", + "start": 22, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 27 + }, + "identifierName": "alias" + }, + "name": "alias" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 35, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/named-alias-3/input.mjs b/packages/babel-parser/test/fixtures/placeholders/import/named-alias-3/input.mjs new file mode 100644 index 0000000000..0531ff7d03 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/named-alias-3/input.mjs @@ -0,0 +1 @@ +import { %%NAMED%% as %%ALIAS%% } from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/import/named-alias-3/output.json b/packages/babel-parser/test/fixtures/placeholders/import/named-alias-3/output.json new file mode 100644 index 0000000000..bfae4a0444 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/named-alias-3/output.json @@ -0,0 +1,153 @@ +{ + "type": "File", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 46 + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "start": 9, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "imported": { + "type": "Placeholder", + "start": 9, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "NAMED" + }, + "name": "NAMED" + }, + "expectedNode": "Identifier" + }, + "local": { + "type": "Placeholder", + "start": 22, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "name": { + "type": "Identifier", + "start": 24, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 24 + }, + "end": { + "line": 1, + "column": 29 + }, + "identifierName": "ALIAS" + }, + "name": "ALIAS" + }, + "expectedNode": "Identifier" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 39, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 45 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/named-alias/input.mjs b/packages/babel-parser/test/fixtures/placeholders/import/named-alias/input.mjs new file mode 100644 index 0000000000..cc0bfd46c5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/named-alias/input.mjs @@ -0,0 +1 @@ +import { named as %%ALIAS%% } from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/import/named-alias/output.json b/packages/babel-parser/test/fixtures/placeholders/import/named-alias/output.json new file mode 100644 index 0000000000..5477bef4ca --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/named-alias/output.json @@ -0,0 +1,137 @@ +{ + "type": "File", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 42, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 42 + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "start": 9, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "imported": { + "type": "Identifier", + "start": 9, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 14 + }, + "identifierName": "named" + }, + "name": "named" + }, + "local": { + "type": "Placeholder", + "start": 18, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "name": { + "type": "Identifier", + "start": 20, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 25 + }, + "identifierName": "ALIAS" + }, + "name": "ALIAS" + }, + "expectedNode": "Identifier" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 35, + "end": 41, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 41 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/named/input.mjs b/packages/babel-parser/test/fixtures/placeholders/import/named/input.mjs new file mode 100644 index 0000000000..24d0c9bc5a --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/named/input.mjs @@ -0,0 +1 @@ +import { %%NAMED%% } from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/import/named/output.json b/packages/babel-parser/test/fixtures/placeholders/import/named/output.json new file mode 100644 index 0000000000..9b3f08486a --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/named/output.json @@ -0,0 +1,153 @@ +{ + "type": "File", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "specifiers": [ + { + "type": "ImportSpecifier", + "start": 9, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "imported": { + "type": "Placeholder", + "start": 9, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "NAMED" + }, + "name": "NAMED" + }, + "expectedNode": "Identifier" + }, + "local": { + "type": "Placeholder", + "start": 9, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 18 + } + }, + "name": { + "type": "Identifier", + "start": 11, + "end": 16, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 16 + }, + "identifierName": "NAMED" + }, + "name": "NAMED" + }, + "expectedNode": "Identifier" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 26, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/import/options.json b/packages/babel-parser/test/fixtures/placeholders/import/options.json new file mode 100644 index 0000000000..986e9cefa9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["placeholders"], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/placeholders/import/star/input.mjs b/packages/babel-parser/test/fixtures/placeholders/import/star/input.mjs new file mode 100644 index 0000000000..df386a7c7b --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/star/input.mjs @@ -0,0 +1 @@ +import * as %%STAR%% from "file"; diff --git a/packages/babel-parser/test/fixtures/placeholders/import/star/output.json b/packages/babel-parser/test/fixtures/placeholders/import/star/output.json new file mode 100644 index 0000000000..7ff6bfd058 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/import/star/output.json @@ -0,0 +1,120 @@ +{ + "type": "File", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start": 0, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "start": 7, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "local": { + "type": "Placeholder", + "start": 12, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 20 + } + }, + "name": { + "type": "Identifier", + "start": 14, + "end": 18, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 18 + }, + "identifierName": "STAR" + }, + "name": "STAR" + }, + "expectedNode": "Identifier" + } + } + ], + "source": { + "type": "StringLiteral", + "start": 26, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 32 + } + }, + "extra": { + "rawValue": "file", + "raw": "\"file\"" + }, + "value": "file" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/labels/asi/input.js b/packages/babel-parser/test/fixtures/placeholders/labels/asi/input.js new file mode 100644 index 0000000000..9c5f9fcc13 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/labels/asi/input.js @@ -0,0 +1,4 @@ +loop: while (0) { + break + %%LABEL%%; +} diff --git a/packages/babel-parser/test/fixtures/placeholders/labels/asi/output.json b/packages/babel-parser/test/fixtures/placeholders/labels/asi/output.json new file mode 100644 index 0000000000..f1e2f16147 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/labels/asi/output.json @@ -0,0 +1,169 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "LabeledStatement", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": { + "type": "WhileStatement", + "start": 6, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "test": { + "type": "NumericLiteral", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + }, + "body": { + "type": "BlockStatement", + "start": 16, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 4, + "column": 1 + } + }, + "body": [ + { + "type": "BreakStatement", + "start": 20, + "end": 25, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "label": null + }, + { + "type": "Placeholder", + "start": 28, + "end": 38, + "loc": { + "start": { + "line": 3, + "column": 2 + }, + "end": { + "line": 3, + "column": 12 + } + }, + "name": { + "type": "Identifier", + "start": 30, + "end": 35, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 9 + }, + "identifierName": "LABEL" + }, + "name": "LABEL" + }, + "expectedNode": "Statement" + } + ], + "directives": [] + } + }, + "label": { + "type": "Identifier", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "loop" + }, + "name": "loop" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/labels/break/input.js b/packages/babel-parser/test/fixtures/placeholders/labels/break/input.js new file mode 100644 index 0000000000..bcc6f5bae9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/labels/break/input.js @@ -0,0 +1,3 @@ +block: { + break %%LABEL%%; +} diff --git a/packages/babel-parser/test/fixtures/placeholders/labels/break/output.json b/packages/babel-parser/test/fixtures/placeholders/labels/break/output.json new file mode 100644 index 0000000000..ab4488d5a0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/labels/break/output.json @@ -0,0 +1,133 @@ +{ + "type": "File", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "LabeledStatement", + "start": 0, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": { + "type": "BlockStatement", + "start": 7, + "end": 29, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "BreakStatement", + "start": 11, + "end": 27, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 18 + } + }, + "label": { + "type": "Placeholder", + "start": 17, + "end": 26, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 17 + } + }, + "name": { + "type": "Identifier", + "start": 19, + "end": 24, + "loc": { + "start": { + "line": 2, + "column": 10 + }, + "end": { + "line": 2, + "column": 15 + }, + "identifierName": "LABEL" + }, + "name": "LABEL" + }, + "expectedNode": "Identifier" + } + } + ], + "directives": [] + }, + "label": { + "type": "Identifier", + "start": 0, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "block" + }, + "name": "block" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/labels/continue/input.js b/packages/babel-parser/test/fixtures/placeholders/labels/continue/input.js new file mode 100644 index 0000000000..52fd9da0d2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/labels/continue/input.js @@ -0,0 +1,3 @@ +loop: while (0) { + continue %%LOOP%%; +} diff --git a/packages/babel-parser/test/fixtures/placeholders/labels/continue/output.json b/packages/babel-parser/test/fixtures/placeholders/labels/continue/output.json new file mode 100644 index 0000000000..b687697919 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/labels/continue/output.json @@ -0,0 +1,168 @@ +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "LabeledStatement", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": { + "type": "WhileStatement", + "start": 6, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "test": { + "type": "NumericLiteral", + "start": 13, + "end": 14, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 14 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + }, + "body": { + "type": "BlockStatement", + "start": 16, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 3, + "column": 1 + } + }, + "body": [ + { + "type": "ContinueStatement", + "start": 20, + "end": 38, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 20 + } + }, + "label": { + "type": "Placeholder", + "start": 29, + "end": 37, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 19 + } + }, + "name": { + "type": "Identifier", + "start": 31, + "end": 35, + "loc": { + "start": { + "line": 2, + "column": 13 + }, + "end": { + "line": 2, + "column": 17 + }, + "identifierName": "LOOP" + }, + "name": "LOOP" + }, + "expectedNode": "Identifier" + } + } + ], + "directives": [] + } + }, + "label": { + "type": "Identifier", + "start": 0, + "end": 4, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 4 + }, + "identifierName": "loop" + }, + "name": "loop" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/labels/labeled-statement/input.js b/packages/babel-parser/test/fixtures/placeholders/labels/labeled-statement/input.js new file mode 100644 index 0000000000..8bc65e46a7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/labels/labeled-statement/input.js @@ -0,0 +1 @@ +%%FOO%%: 0; diff --git a/packages/babel-parser/test/fixtures/placeholders/labels/labeled-statement/output.json b/packages/babel-parser/test/fixtures/placeholders/labels/labeled-statement/output.json new file mode 100644 index 0000000000..5974689885 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/labels/labeled-statement/output.json @@ -0,0 +1,118 @@ +{ + "type": "File", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "LabeledStatement", + "start": 0, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "label": { + "type": "Placeholder", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "name": { + "type": "Identifier", + "start": 2, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "FOO" + }, + "name": "FOO" + }, + "expectedNode": "Identifier" + }, + "body": { + "type": "ExpressionStatement", + "start": 9, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "expression": { + "type": "NumericLiteral", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/options.json b/packages/babel-parser/test/fixtures/placeholders/options.json new file mode 100644 index 0000000000..92404e5012 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/options.json @@ -0,0 +1,3 @@ +{ + "plugins": ["placeholders"] +} diff --git a/packages/babel-parser/test/fixtures/placeholders/statement/asi/input.js b/packages/babel-parser/test/fixtures/placeholders/statement/asi/input.js new file mode 100644 index 0000000000..deeb32f8f1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/statement/asi/input.js @@ -0,0 +1,2 @@ +%%FOO%% +%%BAR%% diff --git a/packages/babel-parser/test/fixtures/placeholders/statement/asi/output.json b/packages/babel-parser/test/fixtures/placeholders/statement/asi/output.json new file mode 100644 index 0000000000..9980b76f59 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/statement/asi/output.json @@ -0,0 +1,101 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "Placeholder", + "start": 0, + "end": 7, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 7 + } + }, + "name": { + "type": "Identifier", + "start": 2, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "FOO" + }, + "name": "FOO" + }, + "expectedNode": "Statement" + }, + { + "type": "Placeholder", + "start": 8, + "end": 15, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 7 + } + }, + "name": { + "type": "Identifier", + "start": 10, + "end": 13, + "loc": { + "start": { + "line": 2, + "column": 2 + }, + "end": { + "line": 2, + "column": 5 + }, + "identifierName": "BAR" + }, + "name": "BAR" + }, + "expectedNode": "Statement" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/statement/nested/input.js b/packages/babel-parser/test/fixtures/placeholders/statement/nested/input.js new file mode 100644 index 0000000000..6530842e22 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/statement/nested/input.js @@ -0,0 +1 @@ +if (0) %%FOO%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/statement/nested/output.json b/packages/babel-parser/test/fixtures/placeholders/statement/nested/output.json new file mode 100644 index 0000000000..1f071964bf --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/statement/nested/output.json @@ -0,0 +1,104 @@ +{ + "type": "File", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "IfStatement", + "start": 0, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "test": { + "type": "NumericLiteral", + "start": 4, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 5 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + }, + "consequent": { + "type": "Placeholder", + "start": 7, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "name": { + "type": "Identifier", + "start": 9, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "FOO" + }, + "name": "FOO" + }, + "expectedNode": "Statement" + }, + "alternate": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/statement/top-level/input.js b/packages/babel-parser/test/fixtures/placeholders/statement/top-level/input.js new file mode 100644 index 0000000000..34e9906e93 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/statement/top-level/input.js @@ -0,0 +1 @@ +%%FOO%%; diff --git a/packages/babel-parser/test/fixtures/placeholders/statement/top-level/output.json b/packages/babel-parser/test/fixtures/placeholders/statement/top-level/output.json new file mode 100644 index 0000000000..d5f19f4035 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/statement/top-level/output.json @@ -0,0 +1,68 @@ +{ + "type": "File", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "Placeholder", + "start": 0, + "end": 8, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 8 + } + }, + "name": { + "type": "Identifier", + "start": 2, + "end": 5, + "loc": { + "start": { + "line": 1, + "column": 2 + }, + "end": { + "line": 1, + "column": 5 + }, + "identifierName": "FOO" + }, + "name": "FOO" + }, + "expectedNode": "Statement" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/try/try-catch-finally/input.js b/packages/babel-parser/test/fixtures/placeholders/try/try-catch-finally/input.js new file mode 100644 index 0000000000..97af833dd2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/try/try-catch-finally/input.js @@ -0,0 +1 @@ +try %%TRY%% catch %%CATCH%% finally %%FINALLY%% diff --git a/packages/babel-parser/test/fixtures/placeholders/try/try-catch-finally/output.json b/packages/babel-parser/test/fixtures/placeholders/try/try-catch-finally/output.json new file mode 100644 index 0000000000..355f89df61 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/try/try-catch-finally/output.json @@ -0,0 +1,166 @@ +{ + "type": "File", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 47 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 47 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "TryStatement", + "start": 0, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 47 + } + }, + "block": { + "type": "Placeholder", + "start": 4, + "end": 11, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 11 + } + }, + "name": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + }, + "identifierName": "TRY" + }, + "name": "TRY" + }, + "expectedNode": "BlockStatement" + }, + "handler": { + "type": "CatchClause", + "start": 12, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "param": null, + "body": { + "type": "Placeholder", + "start": 18, + "end": 27, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 27 + } + }, + "name": { + "type": "Identifier", + "start": 20, + "end": 25, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 25 + }, + "identifierName": "CATCH" + }, + "name": "CATCH" + }, + "expectedNode": "BlockStatement" + } + }, + "guardedHandlers": [], + "finalizer": { + "type": "Placeholder", + "start": 36, + "end": 47, + "loc": { + "start": { + "line": 1, + "column": 36 + }, + "end": { + "line": 1, + "column": 47 + } + }, + "name": { + "type": "Identifier", + "start": 38, + "end": 45, + "loc": { + "start": { + "line": 1, + "column": 38 + }, + "end": { + "line": 1, + "column": 45 + }, + "identifierName": "FINALLY" + }, + "name": "FINALLY" + }, + "expectedNode": "BlockStatement" + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/placeholders/try/with-catch-param/input.js b/packages/babel-parser/test/fixtures/placeholders/try/with-catch-param/input.js new file mode 100644 index 0000000000..e47082a3bd --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/try/with-catch-param/input.js @@ -0,0 +1 @@ +try {} catch (%%PARAM%%) %%CATCH%% diff --git a/packages/babel-parser/test/fixtures/placeholders/try/with-catch-param/output.json b/packages/babel-parser/test/fixtures/placeholders/try/with-catch-param/output.json new file mode 100644 index 0000000000..cb39ff1418 --- /dev/null +++ b/packages/babel-parser/test/fixtures/placeholders/try/with-catch-param/output.json @@ -0,0 +1,150 @@ +{ + "type": "File", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "sourceType": "script", + "interpreter": null, + "body": [ + { + "type": "TryStatement", + "start": 0, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "block": { + "type": "BlockStatement", + "start": 4, + "end": 6, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 6 + } + }, + "body": [], + "directives": [] + }, + "handler": { + "type": "CatchClause", + "start": 7, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 7 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "param": { + "type": "Placeholder", + "start": 14, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 23 + } + }, + "name": { + "type": "Identifier", + "start": 16, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 16 + }, + "end": { + "line": 1, + "column": 21 + }, + "identifierName": "PARAM" + }, + "name": "PARAM" + }, + "expectedNode": "Pattern" + }, + "body": { + "type": "Placeholder", + "start": 25, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "name": { + "type": "Identifier", + "start": 27, + "end": 32, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 32 + }, + "identifierName": "CATCH" + }, + "name": "CATCH" + }, + "expectedNode": "BlockStatement" + } + }, + "guardedHandlers": [], + "finalizer": null + } + ], + "directives": [] + } +} \ No newline at end of file