diff --git a/packages/babel-parser/src/parser/expression.js b/packages/babel-parser/src/parser/expression.js index b813574ede3d..74f951645162 100644 --- a/packages/babel-parser/src/parser/expression.js +++ b/packages/babel-parser/src/parser/expression.js @@ -765,12 +765,22 @@ export default class ExpressionParser extends LValParser { optional: boolean, ): N.Expression { if (node.callee.type === "Import") { - if (node.arguments.length !== 1) { - this.raise(node.start, Errors.ImportCallArity); + if (node.arguments.length === 2) { + this.expectPlugin("moduleAttributes"); + } + if (node.arguments.length === 0 || node.arguments.length > 2) { + this.raise( + node.start, + Errors.ImportCallArity, + this.hasPlugin("moduleAttributes") + ? "one or two arguments" + : "one argument", + ); } else { - const importArg = node.arguments[0]; - if (importArg?.type === "SpreadElement") { - this.raise(importArg.start, Errors.ImportCallSpreadArgument); + for (const arg of node.arguments) { + if (arg.type === "SpreadElement") { + this.raise(arg.start, Errors.ImportCallSpreadArgument); + } } } } @@ -799,7 +809,7 @@ export default class ExpressionParser extends LValParser { } else { this.expect(tt.comma); if (this.match(close)) { - if (dynamicImport) { + if (dynamicImport && !this.hasPlugin("moduleAttributes")) { this.raise( this.state.lastTokStart, Errors.ImportCallArgumentTrailingComma, diff --git a/packages/babel-parser/src/parser/location.js b/packages/babel-parser/src/parser/location.js index e2760f1691fa..1120c0d3c98c 100644 --- a/packages/babel-parser/src/parser/location.js +++ b/packages/babel-parser/src/parser/location.js @@ -67,7 +67,7 @@ export const Errors = Object.freeze({ IllegalReturn: "'return' outside of function", ImportCallArgumentTrailingComma: "Trailing comma is disallowed inside import(...) arguments", - ImportCallArity: "import() requires exactly one argument", + ImportCallArity: "import() requires exactly %0", ImportCallNotNewExpression: "Cannot use new with import(...)", ImportCallSpreadArgument: "... is not allowed in import()", ImportMetaOutsideModule: `import.meta may appear only with 'sourceType: "module"'`, @@ -96,6 +96,12 @@ export const Errors = Object.freeze({ MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX", MixingCoalesceWithLogical: "Nullish coalescing operator(??) requires parens when mixing with logical operators", + ModuleAttributeDifferentFromType: + "The only accepted module attribute is `type`", + ModuleAttributeInvalidValue: + "Only string literals are allowed as module attribute values", + ModuleAttributesWithDuplicateKeys: + 'Duplicate key "%0" is not allowed in module attributes', ModuleExportUndefined: "Export '%0' is not defined", MultipleDefaultsInSwitch: "Multiple default clauses", NewlineAfterThrow: "Illegal newline after throw", diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index 9684a3242aea..13f693c3d593 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -2038,13 +2038,31 @@ export default class StatementParser extends ExpressionParser { // import '...' node.specifiers = []; if (!this.match(tt.string)) { + // check if we have a default import like + // import React from "react"; const hasDefault = this.maybeParseDefaultImportSpecifier(node); + /* we are checking if we do not have a default import, then it is obvious that we need named imports + * import { get } from "axios"; + * but if we do have a default import + * we need to check if we have a comma after that and + * that is where this `|| this.eat` condition comes into play + */ const parseNext = !hasDefault || this.eat(tt.comma); + // if we do have to parse the next set of specifiers, we first check for star imports + // import React, * from "react"; const hasStar = parseNext && this.maybeParseStarImportSpecifier(node); + // now we check if we need to parse the next imports + // but only if they are not importing * (everything) if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node); this.expectContextual("from"); } node.source = this.parseImportSource(); + // https://github.com/tc39/proposal-module-attributes + // parse module attributes if the next token is `with` or ignore and finish the ImportDeclaration node. + const attributes = this.maybeParseModuleAttributes(); + if (attributes) { + node.attributes = attributes; + } this.semicolon(); return this.finishNode(node, "ImportDeclaration"); } @@ -2075,6 +2093,59 @@ export default class StatementParser extends ExpressionParser { node.specifiers.push(this.finishNode(specifier, type)); } + maybeParseModuleAttributes() { + if (this.match(tt._with) && !this.hasPrecedingLineBreak()) { + this.expectPlugin("moduleAttributes"); + this.next(); + } else { + if (this.hasPlugin("moduleAttributes")) return []; + return null; + } + const attrs = []; + const attributes = new Set(); + do { + // we are trying to parse a node which has the following syntax + // with type: "json" + // [with -> keyword], [type -> Identifier], [":" -> token for colon], ["json" -> StringLiteral] + const node = this.startNode(); + node.key = this.parseIdentifier(true); + + // for now we are only allowing `type` as the only allowed module attribute + if (node.key.name !== "type") { + this.raise( + node.key.start, + Errors.ModuleAttributeDifferentFromType, + node.key.name, + ); + } + + // check if we already have an entry for an attribute + // if a duplicate entry is found, throw an error + // for now this logic will come into play only when someone declares `type` twice + if (attributes.has(node.key.name)) { + this.raise( + node.key.start, + Errors.ModuleAttributesWithDuplicateKeys, + node.key.name, + ); + } + attributes.add(node.key.name); + this.expect(tt.colon); + // check if the value set to the module attribute is a string as we only allow string literals + if (!this.match(tt.string)) { + throw this.unexpected( + this.state.start, + Errors.ModuleAttributeInvalidValue, + ); + } + node.value = this.parseLiteral(this.state.value, "StringLiteral"); + this.finishNode(node, "ImportAttribute"); + attrs.push(node); + } while (this.eat(tt.comma)); + + return attrs; + } + maybeParseDefaultImportSpecifier(node: N.ImportDeclaration): boolean { if (this.shouldParseDefaultImport(node)) { // import defaultObj, { x, y as z } from '...' diff --git a/packages/babel-parser/src/plugin-utils.js b/packages/babel-parser/src/plugin-utils.js index 021f98f1c083..f87f37fe3449 100644 --- a/packages/babel-parser/src/plugin-utils.js +++ b/packages/babel-parser/src/plugin-utils.js @@ -86,6 +86,20 @@ export function validatePlugins(plugins: PluginList) { ); } + if (hasPlugin(plugins, "moduleAttributes")) { + const moduleAttributesVerionPluginOption = getPluginOption( + plugins, + "moduleAttributes", + "version", + ); + if (moduleAttributesVerionPluginOption !== "may-2020") { + throw new Error( + "The 'moduleAttributes' plugin requires a 'version' option," + + " representing the last proposal update. Currently, the" + + " only supported value is 'may-2020'.", + ); + } + } if ( hasPlugin(plugins, "recordAndTuple") && !RECORD_AND_TUPLE_SYNTAX_TYPES.includes( diff --git a/packages/babel-parser/test/fixtures/es2015/regression/11183/output.json b/packages/babel-parser/test/fixtures/es2015/regression/11183/output.json index ea1e5e19d850..8f8a462425e7 100644 --- a/packages/babel-parser/test/fixtures/es2015/regression/11183/output.json +++ b/packages/babel-parser/test/fixtures/es2015/regression/11183/output.json @@ -1,111 +1,33 @@ { "type": "File", - "start": 0, - "end": 47, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 5, - "column": 2 - } - }, + "start":0,"end":47,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}}, "program": { "type": "Program", - "start": 0, - "end": 47, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 5, - "column": 2 - } - }, + "start":0,"end":47,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}}, "sourceType": "script", "interpreter": null, "body": [ { "type": "ClassDeclaration", - "start": 0, - "end": 10, - "loc": { - "start": { - "line": 1, - "column": 0 - }, - "end": { - "line": 1, - "column": 10 - } - }, + "start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, "id": { "type": "Identifier", - "start": 6, - "end": 7, - "loc": { - "start": { - "line": 1, - "column": 6 - }, - "end": { - "line": 1, - "column": 7 - }, - "identifierName": "X" - }, + "start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"X"}, "name": "X" }, "superClass": null, "body": { "type": "ClassBody", - "start": 8, - "end": 10, - "loc": { - "start": { - "line": 1, - "column": 8 - }, - "end": { - "line": 1, - "column": 10 - } - }, + "start":8,"end":10,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":10}}, "body": [] } }, { "type": "ExpressionStatement", - "start": 11, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 2 - } - }, + "start":11,"end":13,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":2}}, "expression": { "type": "NumericLiteral", - "start": 11, - "end": 13, - "loc": { - "start": { - "line": 2, - "column": 0 - }, - "end": { - "line": 2, - "column": 2 - } - }, + "start":11,"end":13,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":2}}, "extra": { "rawValue": 5, "raw": "05" @@ -115,33 +37,10 @@ }, { "type": "FunctionDeclaration", - "start": 15, - "end": 44, - "loc": { - "start": { - "line": 4, - "column": 0 - }, - "end": { - "line": 4, - "column": 29 - } - }, + "start":15,"end":44,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":29}}, "id": { "type": "Identifier", - "start": 24, - "end": 25, - "loc": { - "start": { - "line": 4, - "column": 9 - }, - "end": { - "line": 4, - "column": 10 - }, - "identifierName": "x" - }, + "start":24,"end":25,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":10},"identifierName":"x"}, "name": "x" }, "generator": false, @@ -149,48 +48,15 @@ "params": [], "body": { "type": "BlockStatement", - "start": 28, - "end": 44, - "loc": { - "start": { - "line": 4, - "column": 13 - }, - "end": { - "line": 4, - "column": 29 - } - }, + "start":28,"end":44,"loc":{"start":{"line":4,"column":13},"end":{"line":4,"column":29}}, "body": [], "directives": [ { "type": "Directive", - "start": 30, - "end": 42, - "loc": { - "start": { - "line": 4, - "column": 15 - }, - "end": { - "line": 4, - "column": 27 - } - }, + "start":30,"end":42,"loc":{"start":{"line":4,"column":15},"end":{"line":4,"column":27}}, "value": { "type": "DirectiveLiteral", - "start": 30, - "end": 42, - "loc": { - "start": { - "line": 4, - "column": 15 - }, - "end": { - "line": 4, - "column": 27 - } - }, + "start":30,"end":42,"loc":{"start":{"line":4,"column":15},"end":{"line":4,"column":27}}, "value": "use strict", "extra": { "raw": "'use strict'", @@ -203,32 +69,10 @@ }, { "type": "ExpressionStatement", - "start": 45, - "end": 47, - "loc": { - "start": { - "line": 5, - "column": 0 - }, - "end": { - "line": 5, - "column": 2 - } - }, + "start":45,"end":47,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":2}}, "expression": { "type": "NumericLiteral", - "start": 45, - "end": 47, - "loc": { - "start": { - "line": 5, - "column": 0 - }, - "end": { - "line": 5, - "column": 2 - } - }, + "start":45,"end":47,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":2}}, "extra": { "rawValue": 5, "raw": "05" diff --git a/packages/babel-parser/test/fixtures/es2020/dynamic-import/multiple-args/input.js b/packages/babel-parser/test/fixtures/es2020/dynamic-import/multiple-args/input.js index 0f1447dbe608..94e059c54bac 100644 --- a/packages/babel-parser/test/fixtures/es2020/dynamic-import/multiple-args/input.js +++ b/packages/babel-parser/test/fixtures/es2020/dynamic-import/multiple-args/input.js @@ -1 +1 @@ -import('hello', 'world'); +import('hello', 'world', '!'); diff --git a/packages/babel-parser/test/fixtures/es2020/dynamic-import/multiple-args/output.json b/packages/babel-parser/test/fixtures/es2020/dynamic-import/multiple-args/output.json index 46409dca7a6b..0c67a4f67b22 100644 --- a/packages/babel-parser/test/fixtures/es2020/dynamic-import/multiple-args/output.json +++ b/packages/babel-parser/test/fixtures/es2020/dynamic-import/multiple-args/output.json @@ -1,21 +1,21 @@ { "type": "File", - "start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":25}}, + "start":0,"end":30,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":30}}, "errors": [ "SyntaxError: import() requires exactly one argument (1:0)" ], "program": { "type": "Program", - "start":0,"end":25,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":25}}, + "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":25,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":25}}, + "start":0,"end":30,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":30}}, "expression": { "type": "CallExpression", - "start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}}, + "start":0,"end":29,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":29}}, "callee": { "type": "Import", "start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}} @@ -38,6 +38,15 @@ "raw": "'world'" }, "value": "world" + }, + { + "type": "StringLiteral", + "start":25,"end":28,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":28}}, + "extra": { + "rawValue": "!", + "raw": "'!'" + }, + "value": "!" } ] } diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes-dynamic/input.js b/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes-dynamic/input.js new file mode 100644 index 000000000000..0f1447dbe608 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes-dynamic/input.js @@ -0,0 +1 @@ +import('hello', 'world'); diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes-dynamic/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes-dynamic/options.json new file mode 100644 index 000000000000..6b7622b8eeb2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes-dynamic/options.json @@ -0,0 +1,5 @@ +{ + "throws": "This experimental syntax requires enabling the parser plugin: 'moduleAttributes' (1:24)", + "sourceType": "module", + "plugins": [] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes/input.js b/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes/input.js new file mode 100644 index 000000000000..fb31508a0860 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes/input.js @@ -0,0 +1 @@ +import foo from "foo.json" with type: "json"; diff --git a/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes/options.json b/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes/options.json new file mode 100644 index 000000000000..3f9b696c8de9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes/options.json @@ -0,0 +1,5 @@ +{ + "throws": "This experimental syntax requires enabling the parser plugin: 'moduleAttributes' (1:27)", + "sourceType": "module", + "plugins": [] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/dynamic-import-with-valid-syntax/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/dynamic-import-with-valid-syntax/input.js new file mode 100644 index 000000000000..baa60fc43c5f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/dynamic-import-with-valid-syntax/input.js @@ -0,0 +1 @@ +import("foo.json", { with: { type: "json" } }) diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/dynamic-import-with-valid-syntax/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/dynamic-import-with-valid-syntax/options.json new file mode 100644 index 000000000000..14244aa04de3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/dynamic-import-with-valid-syntax/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "moduleAttributes", + { + "version": "may-2020" + } + ] + ], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/dynamic-import-with-valid-syntax/output.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/dynamic-import-with-valid-syntax/output.json new file mode 100644 index 000000000000..eef6b877df49 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/dynamic-import-with-valid-syntax/output.json @@ -0,0 +1,81 @@ +{ + "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": "ExpressionStatement", + "start":0,"end":46,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":46}}, + "expression": { + "type": "CallExpression", + "start":0,"end":46,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":46}}, + "callee": { + "type": "Import", + "start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}} + }, + "arguments": [ + { + "type": "StringLiteral", + "start":7,"end":17,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":17}}, + "extra": { + "rawValue": "foo.json", + "raw": "\"foo.json\"" + }, + "value": "foo.json" + }, + { + "type": "ObjectExpression", + "start":19,"end":45,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":45}}, + "properties": [ + { + "type": "ObjectProperty", + "start":21,"end":43,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":43}}, + "method": false, + "key": { + "type": "Identifier", + "start":21,"end":25,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":25},"identifierName":"with"}, + "name": "with" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "ObjectExpression", + "start":27,"end":43,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":43}}, + "properties": [ + { + "type": "ObjectProperty", + "start":29,"end":41,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":41}}, + "method": false, + "key": { + "type": "Identifier", + "start":29,"end":33,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":33},"identifierName":"type"}, + "name": "type" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "StringLiteral", + "start":35,"end":41,"loc":{"start":{"line":1,"column":35},"end":{"line":1,"column":41}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + } + ] + } + } + ] + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/import-with-statement/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/import-with-statement/input.js new file mode 100644 index 000000000000..bfa86f1acde6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/import-with-statement/input.js @@ -0,0 +1,2 @@ +import "x" +with ({}); diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/import-with-statement/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/import-with-statement/options.json new file mode 100644 index 000000000000..54d338484c57 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/import-with-statement/options.json @@ -0,0 +1,12 @@ +{ + "plugins": [ + [ + "moduleAttributes", + { + "version": "may-2020" + } + ], + "estree" + ], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/import-with-statement/output.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/import-with-statement/output.json new file mode 100644 index 000000000000..cccb9e1b329d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/import-with-statement/output.json @@ -0,0 +1,40 @@ +{ + "type": "File", + "start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":10}}, + "errors": [ + "SyntaxError: 'with' in strict mode (2:0)" + ], + "program": { + "type": "Program", + "start":0,"end":21,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":10}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}}, + "specifiers": [], + "source": { + "type": "Literal", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}}, + "value": "x", + "raw": "\"x\"" + }, + "attributes": [] + }, + { + "type": "WithStatement", + "start":11,"end":21,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":10}}, + "object": { + "type": "ObjectExpression", + "start":17,"end":19,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":8}}, + "properties": [] + }, + "body": { + "type": "EmptyStatement", + "start":20,"end":21,"loc":{"start":{"line":2,"column":9},"end":{"line":2,"column":10}} + } + } + ] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/incorrect-arity/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/incorrect-arity/input.js new file mode 100644 index 000000000000..7f6df49300e8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/incorrect-arity/input.js @@ -0,0 +1,2 @@ +import(); +import("./foo.json", { with: { type: "json"} }, "unsupported"); diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/incorrect-arity/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/incorrect-arity/options.json new file mode 100644 index 000000000000..14244aa04de3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/incorrect-arity/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "moduleAttributes", + { + "version": "may-2020" + } + ] + ], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/incorrect-arity/output.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/incorrect-arity/output.json new file mode 100644 index 000000000000..fbc2d14ad598 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/incorrect-arity/output.json @@ -0,0 +1,107 @@ +{ + "type": "File", + "start":0,"end":73,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":63}}, + "errors": [ + "SyntaxError: import() requires exactly one or two arguments (1:0)", + "SyntaxError: import() requires exactly one or two arguments (2:0)" + ], + "program": { + "type": "Program", + "start":0,"end":73,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":63}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":9,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":9}}, + "expression": { + "type": "CallExpression", + "start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}}, + "callee": { + "type": "Import", + "start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}} + }, + "arguments": [] + } + }, + { + "type": "ExpressionStatement", + "start":10,"end":73,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":63}}, + "expression": { + "type": "CallExpression", + "start":10,"end":72,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":62}}, + "callee": { + "type": "Import", + "start":10,"end":16,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":6}} + }, + "arguments": [ + { + "type": "StringLiteral", + "start":17,"end":29,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":19}}, + "extra": { + "rawValue": "./foo.json", + "raw": "\"./foo.json\"" + }, + "value": "./foo.json" + }, + { + "type": "ObjectExpression", + "start":31,"end":56,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":46}}, + "properties": [ + { + "type": "ObjectProperty", + "start":33,"end":54,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":44}}, + "method": false, + "key": { + "type": "Identifier", + "start":33,"end":37,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":27},"identifierName":"with"}, + "name": "with" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "ObjectExpression", + "start":39,"end":54,"loc":{"start":{"line":2,"column":29},"end":{"line":2,"column":44}}, + "properties": [ + { + "type": "ObjectProperty", + "start":41,"end":53,"loc":{"start":{"line":2,"column":31},"end":{"line":2,"column":43}}, + "method": false, + "key": { + "type": "Identifier", + "start":41,"end":45,"loc":{"start":{"line":2,"column":31},"end":{"line":2,"column":35},"identifierName":"type"}, + "name": "type" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "StringLiteral", + "start":47,"end":53,"loc":{"start":{"line":2,"column":37},"end":{"line":2,"column":43}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + } + ] + } + } + ] + }, + { + "type": "StringLiteral", + "start":58,"end":71,"loc":{"start":{"line":2,"column":48},"end":{"line":2,"column":61}}, + "extra": { + "rawValue": "unsupported", + "raw": "\"unsupported\"" + }, + "value": "unsupported" + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-spread-element-import-call/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-spread-element-import-call/input.js new file mode 100644 index 000000000000..0a9420c378f9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-spread-element-import-call/input.js @@ -0,0 +1 @@ +import("./foo.json", ...[]); diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-spread-element-import-call/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-spread-element-import-call/options.json new file mode 100644 index 000000000000..14244aa04de3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-spread-element-import-call/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "moduleAttributes", + { + "version": "may-2020" + } + ] + ], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-spread-element-import-call/output.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-spread-element-import-call/output.json new file mode 100644 index 000000000000..f016f97336e9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-spread-element-import-call/output.json @@ -0,0 +1,48 @@ +{ + "type": "File", + "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, + "errors": [ + "SyntaxError: ... is not allowed in import() (1:21)" + ], + "program": { + "type": "Program", + "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, + "expression": { + "type": "CallExpression", + "start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, + "callee": { + "type": "Import", + "start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}} + }, + "arguments": [ + { + "type": "StringLiteral", + "start":7,"end":19,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":19}}, + "extra": { + "rawValue": "./foo.json", + "raw": "\"./foo.json\"" + }, + "value": "./foo.json" + }, + { + "type": "SpreadElement", + "start":21,"end":26,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":26}}, + "argument": { + "type": "ArrayExpression", + "start":24,"end":26,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":26}}, + "elements": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-syntax-with-attributes-multiple-lines/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-syntax-with-attributes-multiple-lines/input.js new file mode 100644 index 000000000000..4fb4f13bf6f9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-syntax-with-attributes-multiple-lines/input.js @@ -0,0 +1,2 @@ +import "x" with +type: "json" diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-syntax-with-attributes-multiple-lines/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-syntax-with-attributes-multiple-lines/options.json new file mode 100644 index 000000000000..14244aa04de3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-syntax-with-attributes-multiple-lines/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "moduleAttributes", + { + "version": "may-2020" + } + ] + ], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-syntax-with-attributes-multiple-lines/output.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-syntax-with-attributes-multiple-lines/output.json new file mode 100644 index 000000000000..9dcc39ab57b9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-syntax-with-attributes-multiple-lines/output.json @@ -0,0 +1,47 @@ +{ + "type": "File", + "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":12}}, + "program": { + "type": "Program", + "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":12}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":12}}, + "specifiers": [], + "source": { + "type": "StringLiteral", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}}, + "extra": { + "rawValue": "x", + "raw": "\"x\"" + }, + "value": "x" + }, + "attributes": [ + { + "type": "ImportAttribute", + "start":16,"end":28,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":12}}, + "key": { + "type": "Identifier", + "start":16,"end":20,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":4},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":22,"end":28,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":12}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-syntax-without-attributes-identifier/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-syntax-without-attributes-identifier/input.js new file mode 100644 index 000000000000..af54005dade7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-syntax-without-attributes-identifier/input.js @@ -0,0 +1 @@ +import "x" with; diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-syntax-without-attributes-identifier/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-syntax-without-attributes-identifier/options.json new file mode 100644 index 000000000000..49737184d7fd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/invalid-syntax-without-attributes-identifier/options.json @@ -0,0 +1,12 @@ +{ + "throws": "Unexpected token (1:15)", + "plugins": [ + [ + "moduleAttributes", + { + "version": "may-2020" + } + ] + ], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/trailing-comma/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/trailing-comma/input.js new file mode 100644 index 000000000000..0be461789922 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/trailing-comma/input.js @@ -0,0 +1,2 @@ +import("foo.js",); +import("foo.json", { with: { type: "json" } },); diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/trailing-comma/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/trailing-comma/options.json new file mode 100644 index 000000000000..14244aa04de3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/trailing-comma/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "moduleAttributes", + { + "version": "may-2020" + } + ] + ], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/trailing-comma/output.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/trailing-comma/output.json new file mode 100644 index 000000000000..599f4fe5488d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/trailing-comma/output.json @@ -0,0 +1,110 @@ +{ + "type": "File", + "start":0,"end":67,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":48}}, + "program": { + "type": "Program", + "start":0,"end":67,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":48}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":0,"end":18,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":18}}, + "expression": { + "type": "CallExpression", + "start":0,"end":17,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":17}}, + "callee": { + "type": "Import", + "start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}} + }, + "extra": { + "trailingComma": 15 + }, + "arguments": [ + { + "type": "StringLiteral", + "start":7,"end":15,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":15}}, + "extra": { + "rawValue": "foo.js", + "raw": "\"foo.js\"" + }, + "value": "foo.js" + } + ] + } + }, + { + "type": "ExpressionStatement", + "start":19,"end":67,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":48}}, + "expression": { + "type": "CallExpression", + "start":19,"end":66,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":47}}, + "callee": { + "type": "Import", + "start":19,"end":25,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":6}} + }, + "extra": { + "trailingComma": 64 + }, + "arguments": [ + { + "type": "StringLiteral", + "start":26,"end":36,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":17}}, + "extra": { + "rawValue": "foo.json", + "raw": "\"foo.json\"" + }, + "value": "foo.json" + }, + { + "type": "ObjectExpression", + "start":38,"end":64,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":45}}, + "properties": [ + { + "type": "ObjectProperty", + "start":40,"end":62,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":43}}, + "method": false, + "key": { + "type": "Identifier", + "start":40,"end":44,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":25},"identifierName":"with"}, + "name": "with" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "ObjectExpression", + "start":46,"end":62,"loc":{"start":{"line":2,"column":27},"end":{"line":2,"column":43}}, + "properties": [ + { + "type": "ObjectProperty", + "start":48,"end":60,"loc":{"start":{"line":2,"column":29},"end":{"line":2,"column":41}}, + "method": false, + "key": { + "type": "Identifier", + "start":48,"end":52,"loc":{"start":{"line":2,"column":29},"end":{"line":2,"column":33},"identifierName":"type"}, + "name": "type" + }, + "computed": false, + "shorthand": false, + "value": { + "type": "StringLiteral", + "start":54,"end":60,"loc":{"start":{"line":2,"column":35},"end":{"line":2,"column":41}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + } + ] + } + } + ] + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes-and-value/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes-and-value/input.js new file mode 100644 index 000000000000..ec62816617cd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes-and-value/input.js @@ -0,0 +1,2 @@ +import "x" with type: "json" +[0] diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes-and-value/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes-and-value/options.json new file mode 100644 index 000000000000..14244aa04de3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes-and-value/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "moduleAttributes", + { + "version": "may-2020" + } + ] + ], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes-and-value/output.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes-and-value/output.json new file mode 100644 index 000000000000..e830da53a1c5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes-and-value/output.json @@ -0,0 +1,66 @@ +{ + "type": "File", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":3}}, + "program": { + "type": "Program", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":3}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, + "specifiers": [], + "source": { + "type": "StringLiteral", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}}, + "extra": { + "rawValue": "x", + "raw": "\"x\"" + }, + "value": "x" + }, + "attributes": [ + { + "type": "ImportAttribute", + "start":16,"end":28,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":28}}, + "key": { + "type": "Identifier", + "start":16,"end":20,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":20},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":22,"end":28,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":28}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + } + ] + }, + { + "type": "ExpressionStatement", + "start":29,"end":32,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":3}}, + "expression": { + "type": "ArrayExpression", + "start":29,"end":32,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":3}}, + "elements": [ + { + "type": "NumericLiteral", + "start":30,"end":31,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":2}}, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes/input.js new file mode 100644 index 000000000000..fb31508a0860 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes/input.js @@ -0,0 +1 @@ +import foo from "foo.json" with type: "json"; diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes/options.json new file mode 100644 index 000000000000..14244aa04de3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "moduleAttributes", + { + "version": "may-2020" + } + ] + ], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes/output.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes/output.json new file mode 100644 index 000000000000..dd150dd9dbb1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-attributes/output.json @@ -0,0 +1,57 @@ +{ + "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": "ImportDeclaration", + "start":0,"end":45,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":45}}, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}}, + "local": { + "type": "Identifier", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10},"identifierName":"foo"}, + "name": "foo" + } + } + ], + "source": { + "type": "StringLiteral", + "start":16,"end":26,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":26}}, + "extra": { + "rawValue": "foo.json", + "raw": "\"foo.json\"" + }, + "value": "foo.json" + }, + "attributes": [ + { + "type": "ImportAttribute", + "start":32,"end":44,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":44}}, + "key": { + "type": "Identifier", + "start":32,"end":36,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":36},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":38,"end":44,"loc":{"start":{"line":1,"column":38},"end":{"line":1,"column":44}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-invalid-plugin-option/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-invalid-plugin-option/input.js new file mode 100644 index 000000000000..fb31508a0860 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-invalid-plugin-option/input.js @@ -0,0 +1 @@ +import foo from "foo.json" with type: "json"; diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-invalid-plugin-option/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-invalid-plugin-option/options.json new file mode 100644 index 000000000000..a8be45900fa0 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-invalid-plugin-option/options.json @@ -0,0 +1,12 @@ +{ + "plugins": [ + [ + "moduleAttributes", + { + "version": "jan-2020" + } + ] + ], + "sourceType": "module", + "throws": "The 'moduleAttributes' plugin requires a 'version' option, representing the last proposal update. Currently, the only supported value is 'may-2020'." +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-invalid-value/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-invalid-value/input.js new file mode 100644 index 000000000000..cfb5372f6b12 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-invalid-value/input.js @@ -0,0 +1 @@ +import foo from "foo.json" with type: "json", lazy: true, startAtLine: 1; diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-invalid-value/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-invalid-value/options.json new file mode 100644 index 000000000000..f21e649b0f1d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-invalid-value/options.json @@ -0,0 +1,12 @@ +{ + "plugins": [ + [ + "moduleAttributes", + { + "version": "may-2020" + } + ] + ], + "sourceType": "module", + "throws": "Only string literals are allowed as module attribute values (1:52)" +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-no-type-attribute/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-no-type-attribute/input.js new file mode 100644 index 000000000000..c2ae7496dcb7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-no-type-attribute/input.js @@ -0,0 +1 @@ +import foo from "foo.json" with lazy: "true"; diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-no-type-attribute/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-no-type-attribute/options.json new file mode 100644 index 000000000000..14244aa04de3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-no-type-attribute/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "moduleAttributes", + { + "version": "may-2020" + } + ] + ], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-no-type-attribute/output.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-no-type-attribute/output.json new file mode 100644 index 000000000000..a3bbfd621562 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-no-type-attribute/output.json @@ -0,0 +1,60 @@ +{ + "type": "File", + "start":0,"end":45,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":45}}, + "errors": [ + "SyntaxError: The only accepted module attribute is `type` (1:32)" + ], + "program": { + "type": "Program", + "start":0,"end":45,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":45}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start":0,"end":45,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":45}}, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}}, + "local": { + "type": "Identifier", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10},"identifierName":"foo"}, + "name": "foo" + } + } + ], + "source": { + "type": "StringLiteral", + "start":16,"end":26,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":26}}, + "extra": { + "rawValue": "foo.json", + "raw": "\"foo.json\"" + }, + "value": "foo.json" + }, + "attributes": [ + { + "type": "ImportAttribute", + "start":32,"end":44,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":44}}, + "key": { + "type": "Identifier", + "start":32,"end":36,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":36},"identifierName":"lazy"}, + "name": "lazy" + }, + "value": { + "type": "StringLiteral", + "start":38,"end":44,"loc":{"start":{"line":1,"column":38},"end":{"line":1,"column":44}}, + "extra": { + "rawValue": "true", + "raw": "\"true\"" + }, + "value": "true" + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-object-method-attribute/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-object-method-attribute/input.js new file mode 100644 index 000000000000..d027b991db49 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-object-method-attribute/input.js @@ -0,0 +1 @@ +import foo from "foo.json" with type: "json", hasOwnProperty: "true"; diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-object-method-attribute/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-object-method-attribute/options.json new file mode 100644 index 000000000000..14244aa04de3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-object-method-attribute/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "moduleAttributes", + { + "version": "may-2020" + } + ] + ], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-object-method-attribute/output.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-object-method-attribute/output.json new file mode 100644 index 000000000000..12af675ae8b5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-object-method-attribute/output.json @@ -0,0 +1,78 @@ +{ + "type": "File", + "start":0,"end":69,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":69}}, + "errors": [ + "SyntaxError: The only accepted module attribute is `type` (1:46)" + ], + "program": { + "type": "Program", + "start":0,"end":69,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":69}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start":0,"end":69,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":69}}, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}}, + "local": { + "type": "Identifier", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10},"identifierName":"foo"}, + "name": "foo" + } + } + ], + "source": { + "type": "StringLiteral", + "start":16,"end":26,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":26}}, + "extra": { + "rawValue": "foo.json", + "raw": "\"foo.json\"" + }, + "value": "foo.json" + }, + "attributes": [ + { + "type": "ImportAttribute", + "start":32,"end":44,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":44}}, + "key": { + "type": "Identifier", + "start":32,"end":36,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":36},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":38,"end":44,"loc":{"start":{"line":1,"column":38},"end":{"line":1,"column":44}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + }, + { + "type": "ImportAttribute", + "start":46,"end":68,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":68}}, + "key": { + "type": "Identifier", + "start":46,"end":60,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":60},"identifierName":"hasOwnProperty"}, + "name": "hasOwnProperty" + }, + "value": { + "type": "StringLiteral", + "start":62,"end":68,"loc":{"start":{"line":1,"column":62},"end":{"line":1,"column":68}}, + "extra": { + "rawValue": "true", + "raw": "\"true\"" + }, + "value": "true" + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-repeated-type/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-repeated-type/input.js new file mode 100644 index 000000000000..856373edcf34 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-repeated-type/input.js @@ -0,0 +1 @@ +import foo from "foo.json" with type: "json", type: "html"; diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-repeated-type/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-repeated-type/options.json new file mode 100644 index 000000000000..14244aa04de3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-repeated-type/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "moduleAttributes", + { + "version": "may-2020" + } + ] + ], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-repeated-type/output.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-repeated-type/output.json new file mode 100644 index 000000000000..ad53ece6e4dc --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-with-repeated-type/output.json @@ -0,0 +1,78 @@ +{ + "type": "File", + "start":0,"end":59,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":59}}, + "errors": [ + "SyntaxError: Duplicate key \"type\" is not allowed in module attributes (1:46)" + ], + "program": { + "type": "Program", + "start":0,"end":59,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":59}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start":0,"end":59,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":59}}, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}}, + "local": { + "type": "Identifier", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10},"identifierName":"foo"}, + "name": "foo" + } + } + ], + "source": { + "type": "StringLiteral", + "start":16,"end":26,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":26}}, + "extra": { + "rawValue": "foo.json", + "raw": "\"foo.json\"" + }, + "value": "foo.json" + }, + "attributes": [ + { + "type": "ImportAttribute", + "start":32,"end":44,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":44}}, + "key": { + "type": "Identifier", + "start":32,"end":36,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":36},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":38,"end":44,"loc":{"start":{"line":1,"column":38},"end":{"line":1,"column":44}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + }, + { + "type": "ImportAttribute", + "start":46,"end":58,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":58}}, + "key": { + "type": "Identifier", + "start":46,"end":50,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":50},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":52,"end":58,"loc":{"start":{"line":1,"column":52},"end":{"line":1,"column":58}}, + "extra": { + "rawValue": "html", + "raw": "\"html\"" + }, + "value": "html" + } + } + ] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-without-attributes/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-without-attributes/input.js new file mode 100644 index 000000000000..92901ed56b38 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-without-attributes/input.js @@ -0,0 +1 @@ +import foo from "foo.json"; diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-without-attributes/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-without-attributes/options.json new file mode 100644 index 000000000000..14244aa04de3 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-without-attributes/options.json @@ -0,0 +1,11 @@ +{ + "plugins": [ + [ + "moduleAttributes", + { + "version": "may-2020" + } + ] + ], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-without-attributes/output.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-without-attributes/output.json new file mode 100644 index 000000000000..9a295afe63f1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/valid-syntax-without-attributes/output.json @@ -0,0 +1,38 @@ +{ + "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": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start":0,"end":27,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":27}}, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}}, + "local": { + "type": "Identifier", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10},"identifierName":"foo"}, + "name": "foo" + } + } + ], + "source": { + "type": "StringLiteral", + "start":16,"end":26,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":26}}, + "extra": { + "rawValue": "foo.json", + "raw": "\"foo.json\"" + }, + "value": "foo.json" + }, + "attributes": [] + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/without-plugin/input.js b/packages/babel-parser/test/fixtures/experimental/module-attributes/without-plugin/input.js new file mode 100644 index 000000000000..fb31508a0860 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/without-plugin/input.js @@ -0,0 +1 @@ +import foo from "foo.json" with type: "json"; diff --git a/packages/babel-parser/test/fixtures/experimental/module-attributes/without-plugin/options.json b/packages/babel-parser/test/fixtures/experimental/module-attributes/without-plugin/options.json new file mode 100644 index 000000000000..8645af2af8c7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/module-attributes/without-plugin/options.json @@ -0,0 +1,4 @@ +{ + "throws": "This experimental syntax requires enabling the parser plugin: 'moduleAttributes' (1:27)", + "plugins": [] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-generics/anonymous-function-generator/output.json b/packages/babel-parser/test/fixtures/flow/type-generics/anonymous-function-generator/output.json index 064d5577f360..b02c4bbd98fa 100644 --- a/packages/babel-parser/test/fixtures/flow/type-generics/anonymous-function-generator/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-generics/anonymous-function-generator/output.json @@ -115,4 +115,4 @@ ], "directives": [] } -} +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator/output.json b/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator/output.json index 937ca57900ca..b48b432ce19a 100644 --- a/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator/output.json +++ b/packages/babel-parser/test/fixtures/typescript/tsx/anonymous-function-generator/output.json @@ -112,4 +112,4 @@ ], "directives": [] } -} +} \ No newline at end of file diff --git a/packages/babel-parser/typings/babel-parser.d.ts b/packages/babel-parser/typings/babel-parser.d.ts index 40161080996b..99aac0c1efd7 100644 --- a/packages/babel-parser/typings/babel-parser.d.ts +++ b/packages/babel-parser/typings/babel-parser.d.ts @@ -114,6 +114,7 @@ export type ParserPlugin = 'importMeta' | 'jsx' | 'logicalAssignment' | + 'moduleAttributes' | 'nullishCoalescingOperator' | 'numericSeparator' | 'objectRestSpread' | diff --git a/packages/babel-plugin-syntax-module-attributes/.npmignore b/packages/babel-plugin-syntax-module-attributes/.npmignore new file mode 100644 index 000000000000..2b1fceba679b --- /dev/null +++ b/packages/babel-plugin-syntax-module-attributes/.npmignore @@ -0,0 +1,3 @@ +*.log +src +test diff --git a/packages/babel-plugin-syntax-module-attributes/README.md b/packages/babel-plugin-syntax-module-attributes/README.md new file mode 100644 index 000000000000..3ae0f5a00927 --- /dev/null +++ b/packages/babel-plugin-syntax-module-attributes/README.md @@ -0,0 +1,19 @@ +# @babel/plugin-syntax-module-attributes + +> Allow parsing of the module attributes in the import statements + +See our website [@babel/plugin-syntax-module-attributes](https://babeljs.io/docs/en/next/babel-plugin-syntax-module-attributes.html) for more information. + +## Install + +Using npm: + +```sh +npm install --save-dev @babel/plugin-syntax-module-attributes +``` + +or using yarn: + +```sh +yarn add @babel/plugin-syntax-module-attributes --dev +``` diff --git a/packages/babel-plugin-syntax-module-attributes/package.json b/packages/babel-plugin-syntax-module-attributes/package.json new file mode 100644 index 000000000000..3a828f67decd --- /dev/null +++ b/packages/babel-plugin-syntax-module-attributes/package.json @@ -0,0 +1,23 @@ +{ + "name": "@babel/plugin-syntax-module-attributes", + "version": "7.8.3", + "description": "Allow parsing of the module attributes in the import statement", + "repository": "https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-module-attributes", + "license": "MIT", + "publishConfig": { + "access": "public" + }, + "main": "lib/index.js", + "keywords": [ + "babel-plugin" + ], + "dependencies": { + "@babel/helper-plugin-utils": "^7.8.3" + }, + "peerDependencies": { + "@babel/core": "^7.0.0-0" + }, + "devDependencies": { + "@babel/core": "^7.8.3" + } +} diff --git a/packages/babel-plugin-syntax-module-attributes/src/index.js b/packages/babel-plugin-syntax-module-attributes/src/index.js new file mode 100644 index 000000000000..b0aa860d78b1 --- /dev/null +++ b/packages/babel-plugin-syntax-module-attributes/src/index.js @@ -0,0 +1,21 @@ +import { declare } from "@babel/helper-plugin-utils"; + +export default declare((api, { version }) => { + api.assertVersion(7); + + if (typeof version !== "string" || version !== "apr-2020") { + throw new Error( + "The 'moduleAttributes' plugin requires a 'version' option," + + " representing the last proposal update. Currently, the" + + " only supported value is 'apr-2020'.", + ); + } + + return { + name: "syntax-module-attributes", + + manipulateOptions(opts, parserOpts) { + parserOpts.plugins.push(["moduleAttributes", { version }]); + }, + }; +}); diff --git a/packages/babel-standalone/package.json b/packages/babel-standalone/package.json index a95c4a5d0e24..b78155175010 100644 --- a/packages/babel-standalone/package.json +++ b/packages/babel-standalone/package.json @@ -44,6 +44,7 @@ "@babel/plugin-syntax-function-sent": "^7.8.3", "@babel/plugin-syntax-import-meta": "^7.8.3", "@babel/plugin-syntax-jsx": "^7.8.3", + "@babel/plugin-syntax-module-attributes": "^7.8.3", "@babel/plugin-syntax-object-rest-spread": "^7.8.0", "@babel/plugin-syntax-optional-catch-binding": "^7.8.0", "@babel/plugin-syntax-pipeline-operator": "^7.8.3", diff --git a/packages/babel-standalone/scripts/pluginConfig.json b/packages/babel-standalone/scripts/pluginConfig.json index 856d0869b5e5..9d54879e20c0 100644 --- a/packages/babel-standalone/scripts/pluginConfig.json +++ b/packages/babel-standalone/scripts/pluginConfig.json @@ -10,6 +10,7 @@ "syntax-function-sent", "syntax-import-meta", "syntax-jsx", + "syntax-module-attributes", "syntax-object-rest-spread", "syntax-optional-catch-binding", "syntax-pipeline-operator", diff --git a/packages/babel-standalone/src/generated/plugins.js b/packages/babel-standalone/src/generated/plugins.js index 0b55279003db..ffbe499a13d2 100644 --- a/packages/babel-standalone/src/generated/plugins.js +++ b/packages/babel-standalone/src/generated/plugins.js @@ -14,6 +14,7 @@ import syntaxFunctionBind from "@babel/plugin-syntax-function-bind"; import syntaxFunctionSent from "@babel/plugin-syntax-function-sent"; import syntaxImportMeta from "@babel/plugin-syntax-import-meta"; import syntaxJsx from "@babel/plugin-syntax-jsx"; +import syntaxModuleAttributes from "@babel/plugin-syntax-module-attributes"; import syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread"; import syntaxOptionalCatchBinding from "@babel/plugin-syntax-optional-catch-binding"; import syntaxPipelineOperator from "@babel/plugin-syntax-pipeline-operator"; @@ -103,6 +104,7 @@ export { syntaxFunctionSent, syntaxImportMeta, syntaxJsx, + syntaxModuleAttributes, syntaxObjectRestSpread, syntaxOptionalCatchBinding, syntaxPipelineOperator, @@ -193,6 +195,7 @@ export const all = { "syntax-function-sent": syntaxFunctionSent, "syntax-import-meta": syntaxImportMeta, "syntax-jsx": syntaxJsx, + "syntax-module-attributes": syntaxModuleAttributes, "syntax-object-rest-spread": syntaxObjectRestSpread, "syntax-optional-catch-binding": syntaxOptionalCatchBinding, "syntax-pipeline-operator": syntaxPipelineOperator, diff --git a/packages/babel-standalone/src/preset-stage-1.js b/packages/babel-standalone/src/preset-stage-1.js index 2d8aba73a2db..eaff6973106f 100644 --- a/packages/babel-standalone/src/preset-stage-1.js +++ b/packages/babel-standalone/src/preset-stage-1.js @@ -10,6 +10,7 @@ export default (_: any, opts: Object = {}) => { decoratorsBeforeExport, pipelineProposal = "minimal", recordAndTupleSyntax: recordAndTupleSyntax = "hash", + moduleAttributesVersion = "may-2020", } = opts; return { @@ -20,6 +21,10 @@ export default (_: any, opts: Object = {}) => { ], ], plugins: [ + [ + babelPlugins.syntaxModuleAttributes, + { version: moduleAttributesVersion }, + ], [babelPlugins.syntaxRecordAndTuple, { syntaxType: recordAndTupleSyntax }], babelPlugins.proposalExportDefaultFrom, [babelPlugins.proposalPipelineOperator, { proposal: pipelineProposal }],