diff --git a/packages/babel-generator/test/fixtures/types/ImportAssertion/input.js b/packages/babel-generator/test/fixtures/types/ImportAssertion/input.js index 0ebcdd146cca..5b61a1938855 100644 --- a/packages/babel-generator/test/fixtures/types/ImportAssertion/input.js +++ b/packages/babel-generator/test/fixtures/types/ImportAssertion/input.js @@ -1,4 +1,4 @@ import foo1 from "foo.json" assert { type: "json" }; -export { foo2 } from "foo.json" assert { type: "json" }; +export { default as foo2 } from "foo.json" assert { type: "json" }; export * from "foo.json" assert { type: "json" }; export * as foo3 from "foo.json" assert { type: "json" }; diff --git a/packages/babel-generator/test/fixtures/types/ImportAssertion/output.js b/packages/babel-generator/test/fixtures/types/ImportAssertion/output.js index 973863a3e4d8..a18a731b09d0 100644 --- a/packages/babel-generator/test/fixtures/types/ImportAssertion/output.js +++ b/packages/babel-generator/test/fixtures/types/ImportAssertion/output.js @@ -1,4 +1,4 @@ import foo1 from "foo.json" assert { type: "json" }; -export { foo2 } from "foo.json" assert { type: "json" }; +export { default as foo2 } from "foo.json" assert { type: "json" }; export * from "foo.json" assert { type: "json" }; export * as foo3 from "foo.json" assert { type: "json" }; \ No newline at end of file diff --git a/packages/babel-parser/src/parse-error/standard-errors.js b/packages/babel-parser/src/parse-error/standard-errors.js index b17d6bfc2ef0..3f9747ce1d38 100644 --- a/packages/babel-parser/src/parse-error/standard-errors.js +++ b/packages/babel-parser/src/parse-error/standard-errors.js @@ -129,6 +129,9 @@ export default (_: typeof toParseErrorCredentials) => ({ ), ImportCallNotNewExpression: _("Cannot use new with import(...)."), ImportCallSpreadArgument: _("`...` is not allowed in `import()`."), + ImportJSONBindingNotDefault: _( + "A JSON module can only be imported with `default`.", + ), IncompatibleRegExpUVFlags: _( "The 'u' and 'v' regular expression flags cannot be enabled at the same time.", ), diff --git a/packages/babel-parser/src/parser/statement.js b/packages/babel-parser/src/parser/statement.js index 968c48261f76..6ab4c73daa37 100644 --- a/packages/babel-parser/src/parser/statement.js +++ b/packages/babel-parser/src/parser/statement.js @@ -2182,6 +2182,7 @@ export default class StatementParser extends ExpressionParser { const assertions = this.maybeParseImportAssertions(); if (assertions) { node.assertions = assertions; + this.checkJSONModuleImport(node); } } else if (expect) { this.unexpected(); @@ -2399,6 +2400,56 @@ export default class StatementParser extends ExpressionParser { return this.parseIdentifier(true); } + isJSONModuleImport( + node: + | N.ExportAllDeclaration + | N.ExportNamedDeclaration + | N.ImportDeclaration, + ): boolean { + if (node.assertions != null) { + return node.assertions.some(({ key, value }) => { + return ( + value.value === "json" && + (key.type === "Identifier" + ? key.name === "type" + : key.value === "type") + ); + }); + } + return false; + } + + checkJSONModuleImport( + node: + | N.ExportAllDeclaration + | N.ExportNamedDeclaration + | N.ImportDeclaration, + ) { + if (this.isJSONModuleImport(node) && node.type !== "ExportAllDeclaration") { + const { specifiers } = node; + if (node.specifiers != null) { + const nonDefaultNamedSpecifier = specifiers.find(specifier => { + let imported; + if (specifier.type === "ExportSpecifier") { + imported = specifier.local; + } else if (specifier.type === "ImportSpecifier") { + imported = specifier.imported; + } + if (imported !== undefined) { + return imported.type === "Identifier" + ? imported.name !== "default" + : imported.value !== "default"; + } + }); + if (nonDefaultNamedSpecifier !== undefined) { + this.raise(Errors.ImportJSONBindingNotDefault, { + at: nonDefaultNamedSpecifier.loc.start, + }); + } + } + } + } + // Parses import declaration. // https://tc39.es/ecma262/#prod-ImportDeclaration @@ -2437,6 +2488,7 @@ export default class StatementParser extends ExpressionParser { node.attributes = attributes; } } + this.checkJSONModuleImport(node); this.semicolon(); return this.finishNode(node, "ImportDeclaration"); diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/invalid-syntax-export-with-repeated-type/input.js b/packages/babel-parser/test/fixtures/experimental/import-assertions/invalid-syntax-export-with-repeated-type/input.js new file mode 100644 index 000000000000..1e421736cffd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/invalid-syntax-export-with-repeated-type/input.js @@ -0,0 +1 @@ +export { default as foo } from "foo.json" assert { type: "json", type: "html" }; diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/invalid-syntax-export-with-repeated-type/output.json b/packages/babel-parser/test/fixtures/experimental/import-assertions/invalid-syntax-export-with-repeated-type/output.json new file mode 100644 index 000000000000..70cab9f66df6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/invalid-syntax-export-with-repeated-type/output.json @@ -0,0 +1,84 @@ +{ + "type": "File", + "start":0,"end":80,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":80,"index":80}}, + "errors": [ + "SyntaxError: Duplicate key \"type\" is not allowed in module attributes. (1:65)" + ], + "program": { + "type": "Program", + "start":0,"end":80,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":80,"index":80}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start":0,"end":80,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":80,"index":80}}, + "specifiers": [ + { + "type": "ExportSpecifier", + "start":9,"end":23,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":23,"index":23}}, + "local": { + "type": "Identifier", + "start":9,"end":16,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":16,"index":16},"identifierName":"default"}, + "name": "default" + }, + "exported": { + "type": "Identifier", + "start":20,"end":23,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":23,"index":23},"identifierName":"foo"}, + "name": "foo" + } + } + ], + "source": { + "type": "StringLiteral", + "start":31,"end":41,"loc":{"start":{"line":1,"column":31,"index":31},"end":{"line":1,"column":41,"index":41}}, + "extra": { + "rawValue": "foo.json", + "raw": "\"foo.json\"" + }, + "value": "foo.json" + }, + "declaration": null, + "assertions": [ + { + "type": "ImportAttribute", + "start":51,"end":63,"loc":{"start":{"line":1,"column":51,"index":51},"end":{"line":1,"column":63,"index":63}}, + "key": { + "type": "Identifier", + "start":51,"end":55,"loc":{"start":{"line":1,"column":51,"index":51},"end":{"line":1,"column":55,"index":55},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":57,"end":63,"loc":{"start":{"line":1,"column":57,"index":57},"end":{"line":1,"column":63,"index":63}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + }, + { + "type": "ImportAttribute", + "start":65,"end":77,"loc":{"start":{"line":1,"column":65,"index":65},"end":{"line":1,"column":77,"index":77}}, + "key": { + "type": "Identifier", + "start":65,"end":69,"loc":{"start":{"line":1,"column":65,"index":65},"end":{"line":1,"column":69,"index":69},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":71,"end":77,"loc":{"start":{"line":1,"column":71,"index":71},"end":{"line":1,"column":77,"index":77}}, + "extra": { + "rawValue": "html", + "raw": "\"html\"" + }, + "value": "html" + } + } + ] + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/trailing-comma/input.js b/packages/babel-parser/test/fixtures/experimental/import-assertions/trailing-comma/input.js index 910b9aa32d84..077d150d81ae 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/trailing-comma/input.js +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/trailing-comma/input.js @@ -1,2 +1,2 @@ import foo from "foo" assert { type: "json", } -export { foo } from "foo" assert { type: "json", } +export { default as foo } from "foo" assert { type: "json", } diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/trailing-comma/output.json b/packages/babel-parser/test/fixtures/experimental/import-assertions/trailing-comma/output.json index 6be046eed1b2..77f11f2c63a2 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/trailing-comma/output.json +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/trailing-comma/output.json @@ -1,9 +1,9 @@ { "type": "File", - "start":0,"end":97,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":50,"index":97}}, + "start":0,"end":108,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":61,"index":108}}, "program": { "type": "Program", - "start":0,"end":97,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":50,"index":97}}, + "start":0,"end":108,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":61,"index":108}}, "sourceType": "module", "interpreter": null, "body": [ @@ -53,26 +53,26 @@ }, { "type": "ExportNamedDeclaration", - "start":47,"end":97,"loc":{"start":{"line":2,"column":0,"index":47},"end":{"line":2,"column":50,"index":97}}, + "start":47,"end":108,"loc":{"start":{"line":2,"column":0,"index":47},"end":{"line":2,"column":61,"index":108}}, "specifiers": [ { "type": "ExportSpecifier", - "start":56,"end":59,"loc":{"start":{"line":2,"column":9,"index":56},"end":{"line":2,"column":12,"index":59}}, + "start":56,"end":70,"loc":{"start":{"line":2,"column":9,"index":56},"end":{"line":2,"column":23,"index":70}}, "local": { "type": "Identifier", - "start":56,"end":59,"loc":{"start":{"line":2,"column":9,"index":56},"end":{"line":2,"column":12,"index":59},"identifierName":"foo"}, - "name": "foo" + "start":56,"end":63,"loc":{"start":{"line":2,"column":9,"index":56},"end":{"line":2,"column":16,"index":63},"identifierName":"default"}, + "name": "default" }, "exported": { "type": "Identifier", - "start":56,"end":59,"loc":{"start":{"line":2,"column":9,"index":56},"end":{"line":2,"column":12,"index":59},"identifierName":"foo"}, + "start":67,"end":70,"loc":{"start":{"line":2,"column":20,"index":67},"end":{"line":2,"column":23,"index":70},"identifierName":"foo"}, "name": "foo" } } ], "source": { "type": "StringLiteral", - "start":67,"end":72,"loc":{"start":{"line":2,"column":20,"index":67},"end":{"line":2,"column":25,"index":72}}, + "start":78,"end":83,"loc":{"start":{"line":2,"column":31,"index":78},"end":{"line":2,"column":36,"index":83}}, "extra": { "rawValue": "foo", "raw": "\"foo\"" @@ -83,15 +83,15 @@ "assertions": [ { "type": "ImportAttribute", - "start":82,"end":94,"loc":{"start":{"line":2,"column":35,"index":82},"end":{"line":2,"column":47,"index":94}}, + "start":93,"end":105,"loc":{"start":{"line":2,"column":46,"index":93},"end":{"line":2,"column":58,"index":105}}, "key": { "type": "Identifier", - "start":82,"end":86,"loc":{"start":{"line":2,"column":35,"index":82},"end":{"line":2,"column":39,"index":86},"identifierName":"type"}, + "start":93,"end":97,"loc":{"start":{"line":2,"column":46,"index":93},"end":{"line":2,"column":50,"index":97},"identifierName":"type"}, "name": "type" }, "value": { "type": "StringLiteral", - "start":88,"end":94,"loc":{"start":{"line":2,"column":41,"index":88},"end":{"line":2,"column":47,"index":94}}, + "start":99,"end":105,"loc":{"start":{"line":2,"column":52,"index":99},"end":{"line":2,"column":58,"index":105}}, "extra": { "rawValue": "json", "raw": "\"json\"" diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-empty-assertion/input.js b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-empty-assertion/input.js new file mode 100644 index 000000000000..758659de4037 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-empty-assertion/input.js @@ -0,0 +1,4 @@ +import foo, { bar } from "foo" assert {}; +import * as ns from "foo" assert {}; +export { quux } from "foo" assert {}; +export * as ns2 from "foo" assert {}; diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-empty-assertion/output.json b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-empty-assertion/output.json new file mode 100644 index 000000000000..7bb565c095bc --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-empty-assertion/output.json @@ -0,0 +1,133 @@ +{ + "type": "File", + "start":0,"end":154,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":37,"index":154}}, + "program": { + "type": "Program", + "start":0,"end":154,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":4,"column":37,"index":154}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start":0,"end":41,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":41,"index":41}}, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":10,"index":10}}, + "local": { + "type": "Identifier", + "start":7,"end":10,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":10,"index":10},"identifierName":"foo"}, + "name": "foo" + } + }, + { + "type": "ImportSpecifier", + "start":14,"end":17,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":17,"index":17}}, + "imported": { + "type": "Identifier", + "start":14,"end":17,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":17,"index":17},"identifierName":"bar"}, + "name": "bar" + }, + "local": { + "type": "Identifier", + "start":14,"end":17,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":17,"index":17},"identifierName":"bar"}, + "name": "bar" + } + } + ], + "source": { + "type": "StringLiteral", + "start":25,"end":30,"loc":{"start":{"line":1,"column":25,"index":25},"end":{"line":1,"column":30,"index":30}}, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "assertions": [] + }, + { + "type": "ImportDeclaration", + "start":42,"end":78,"loc":{"start":{"line":2,"column":0,"index":42},"end":{"line":2,"column":36,"index":78}}, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "start":49,"end":56,"loc":{"start":{"line":2,"column":7,"index":49},"end":{"line":2,"column":14,"index":56}}, + "local": { + "type": "Identifier", + "start":54,"end":56,"loc":{"start":{"line":2,"column":12,"index":54},"end":{"line":2,"column":14,"index":56},"identifierName":"ns"}, + "name": "ns" + } + } + ], + "source": { + "type": "StringLiteral", + "start":62,"end":67,"loc":{"start":{"line":2,"column":20,"index":62},"end":{"line":2,"column":25,"index":67}}, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "assertions": [] + }, + { + "type": "ExportNamedDeclaration", + "start":79,"end":116,"loc":{"start":{"line":3,"column":0,"index":79},"end":{"line":3,"column":37,"index":116}}, + "specifiers": [ + { + "type": "ExportSpecifier", + "start":88,"end":92,"loc":{"start":{"line":3,"column":9,"index":88},"end":{"line":3,"column":13,"index":92}}, + "local": { + "type": "Identifier", + "start":88,"end":92,"loc":{"start":{"line":3,"column":9,"index":88},"end":{"line":3,"column":13,"index":92},"identifierName":"quux"}, + "name": "quux" + }, + "exported": { + "type": "Identifier", + "start":88,"end":92,"loc":{"start":{"line":3,"column":9,"index":88},"end":{"line":3,"column":13,"index":92},"identifierName":"quux"}, + "name": "quux" + } + } + ], + "source": { + "type": "StringLiteral", + "start":100,"end":105,"loc":{"start":{"line":3,"column":21,"index":100},"end":{"line":3,"column":26,"index":105}}, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "declaration": null, + "assertions": [] + }, + { + "type": "ExportNamedDeclaration", + "start":117,"end":154,"loc":{"start":{"line":4,"column":0,"index":117},"end":{"line":4,"column":37,"index":154}}, + "specifiers": [ + { + "type": "ExportNamespaceSpecifier", + "start":124,"end":132,"loc":{"start":{"line":4,"column":7,"index":124},"end":{"line":4,"column":15,"index":132}}, + "exported": { + "type": "Identifier", + "start":129,"end":132,"loc":{"start":{"line":4,"column":12,"index":129},"end":{"line":4,"column":15,"index":132},"identifierName":"ns2"}, + "name": "ns2" + } + } + ], + "source": { + "type": "StringLiteral", + "start":138,"end":143,"loc":{"start":{"line":4,"column":21,"index":138},"end":{"line":4,"column":26,"index":143}}, + "extra": { + "rawValue": "foo", + "raw": "\"foo\"" + }, + "value": "foo" + }, + "assertions": [] + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-and-attributes-multiple-lines/input.js b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-and-attributes-multiple-lines/input.js index 6af100604f2a..a3830551716f 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-and-attributes-multiple-lines/input.js +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-and-attributes-multiple-lines/input.js @@ -1,2 +1,2 @@ -export { x } from "foo" assert +export { default as x } from "foo" assert { type: "json" } diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-and-attributes-multiple-lines/output.json b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-and-attributes-multiple-lines/output.json index aebe93aaf1c9..88f1415f189c 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-and-attributes-multiple-lines/output.json +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-and-attributes-multiple-lines/output.json @@ -1,34 +1,34 @@ { "type": "File", - "start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":16,"index":47}}, + "start":0,"end":58,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":16,"index":58}}, "program": { "type": "Program", - "start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":16,"index":47}}, + "start":0,"end":58,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":16,"index":58}}, "sourceType": "module", "interpreter": null, "body": [ { "type": "ExportNamedDeclaration", - "start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":16,"index":47}}, + "start":0,"end":58,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":16,"index":58}}, "specifiers": [ { "type": "ExportSpecifier", - "start":9,"end":10,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":10,"index":10}}, + "start":9,"end":21,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":21,"index":21}}, "local": { "type": "Identifier", - "start":9,"end":10,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":10,"index":10},"identifierName":"x"}, - "name": "x" + "start":9,"end":16,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":16,"index":16},"identifierName":"default"}, + "name": "default" }, "exported": { "type": "Identifier", - "start":9,"end":10,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":10,"index":10},"identifierName":"x"}, + "start":20,"end":21,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":21,"index":21},"identifierName":"x"}, "name": "x" } } ], "source": { "type": "StringLiteral", - "start":18,"end":23,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":23,"index":23}}, + "start":29,"end":34,"loc":{"start":{"line":1,"column":29,"index":29},"end":{"line":1,"column":34,"index":34}}, "extra": { "rawValue": "foo", "raw": "\"foo\"" @@ -39,15 +39,15 @@ "assertions": [ { "type": "ImportAttribute", - "start":33,"end":45,"loc":{"start":{"line":2,"column":2,"index":33},"end":{"line":2,"column":14,"index":45}}, + "start":44,"end":56,"loc":{"start":{"line":2,"column":2,"index":44},"end":{"line":2,"column":14,"index":56}}, "key": { "type": "Identifier", - "start":33,"end":37,"loc":{"start":{"line":2,"column":2,"index":33},"end":{"line":2,"column":6,"index":37},"identifierName":"type"}, + "start":44,"end":48,"loc":{"start":{"line":2,"column":2,"index":44},"end":{"line":2,"column":6,"index":48},"identifierName":"type"}, "name": "type" }, "value": { "type": "StringLiteral", - "start":39,"end":45,"loc":{"start":{"line":2,"column":8,"index":39},"end":{"line":2,"column":14,"index":45}}, + "start":50,"end":56,"loc":{"start":{"line":2,"column":8,"index":50},"end":{"line":2,"column":14,"index":56}}, "extra": { "rawValue": "json", "raw": "\"json\"" diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes-and-value/input.js b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes-and-value/input.js index 92c6eae4f07b..567f6335c84c 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes-and-value/input.js +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes-and-value/input.js @@ -1,2 +1,2 @@ -export { x } from "foo" assert { type: "json" } +export { "default" as x } from "foo" assert { type: "json" } [0] diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes-and-value/output.json b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes-and-value/output.json index f1d2151e381f..c947ca3ee8d4 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes-and-value/output.json +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes-and-value/output.json @@ -1,34 +1,38 @@ { "type": "File", - "start":0,"end":51,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":3,"index":51}}, + "start":0,"end":64,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":3,"index":64}}, "program": { "type": "Program", - "start":0,"end":51,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":3,"index":51}}, + "start":0,"end":64,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":3,"index":64}}, "sourceType": "module", "interpreter": null, "body": [ { "type": "ExportNamedDeclaration", - "start":0,"end":47,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":47,"index":47}}, + "start":0,"end":60,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":60,"index":60}}, "specifiers": [ { "type": "ExportSpecifier", - "start":9,"end":10,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":10,"index":10}}, + "start":9,"end":23,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":23,"index":23}}, "local": { - "type": "Identifier", - "start":9,"end":10,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":10,"index":10},"identifierName":"x"}, - "name": "x" + "type": "StringLiteral", + "start":9,"end":18,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":18,"index":18}}, + "extra": { + "rawValue": "default", + "raw": "\"default\"" + }, + "value": "default" }, "exported": { "type": "Identifier", - "start":9,"end":10,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":10,"index":10},"identifierName":"x"}, + "start":22,"end":23,"loc":{"start":{"line":1,"column":22,"index":22},"end":{"line":1,"column":23,"index":23},"identifierName":"x"}, "name": "x" } } ], "source": { "type": "StringLiteral", - "start":18,"end":23,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":23,"index":23}}, + "start":31,"end":36,"loc":{"start":{"line":1,"column":31,"index":31},"end":{"line":1,"column":36,"index":36}}, "extra": { "rawValue": "foo", "raw": "\"foo\"" @@ -39,15 +43,15 @@ "assertions": [ { "type": "ImportAttribute", - "start":33,"end":45,"loc":{"start":{"line":1,"column":33,"index":33},"end":{"line":1,"column":45,"index":45}}, + "start":46,"end":58,"loc":{"start":{"line":1,"column":46,"index":46},"end":{"line":1,"column":58,"index":58}}, "key": { "type": "Identifier", - "start":33,"end":37,"loc":{"start":{"line":1,"column":33,"index":33},"end":{"line":1,"column":37,"index":37},"identifierName":"type"}, + "start":46,"end":50,"loc":{"start":{"line":1,"column":46,"index":46},"end":{"line":1,"column":50,"index":50},"identifierName":"type"}, "name": "type" }, "value": { "type": "StringLiteral", - "start":39,"end":45,"loc":{"start":{"line":1,"column":39,"index":39},"end":{"line":1,"column":45,"index":45}}, + "start":52,"end":58,"loc":{"start":{"line":1,"column":52,"index":52},"end":{"line":1,"column":58,"index":58}}, "extra": { "rawValue": "json", "raw": "\"json\"" @@ -59,14 +63,14 @@ }, { "type": "ExpressionStatement", - "start":48,"end":51,"loc":{"start":{"line":2,"column":0,"index":48},"end":{"line":2,"column":3,"index":51}}, + "start":61,"end":64,"loc":{"start":{"line":2,"column":0,"index":61},"end":{"line":2,"column":3,"index":64}}, "expression": { "type": "ArrayExpression", - "start":48,"end":51,"loc":{"start":{"line":2,"column":0,"index":48},"end":{"line":2,"column":3,"index":51}}, + "start":61,"end":64,"loc":{"start":{"line":2,"column":0,"index":61},"end":{"line":2,"column":3,"index":64}}, "elements": [ { "type": "NumericLiteral", - "start":49,"end":50,"loc":{"start":{"line":2,"column":1,"index":49},"end":{"line":2,"column":2,"index":50}}, + "start":62,"end":63,"loc":{"start":{"line":2,"column":1,"index":62},"end":{"line":2,"column":2,"index":63}}, "extra": { "rawValue": 0, "raw": "0" diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes/input.js b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes/input.js index 598db769da88..08775ba22ed4 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes/input.js +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes/input.js @@ -1 +1 @@ -export { foo } from "foo.json" assert { type: "json" }; +export { default as foo } from "foo.json" assert { type: "json" }; diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes/output.json b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes/output.json index fa00c3031691..ef4f180d3be1 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes/output.json +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-attributes/output.json @@ -1,34 +1,34 @@ { "type": "File", - "start":0,"end":55,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":55,"index":55}}, + "start":0,"end":66,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":66,"index":66}}, "program": { "type": "Program", - "start":0,"end":55,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":55,"index":55}}, + "start":0,"end":66,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":66,"index":66}}, "sourceType": "module", "interpreter": null, "body": [ { "type": "ExportNamedDeclaration", - "start":0,"end":55,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":55,"index":55}}, + "start":0,"end":66,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":66,"index":66}}, "specifiers": [ { "type": "ExportSpecifier", - "start":9,"end":12,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":12,"index":12}}, + "start":9,"end":23,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":23,"index":23}}, "local": { "type": "Identifier", - "start":9,"end":12,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":12,"index":12},"identifierName":"foo"}, - "name": "foo" + "start":9,"end":16,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":16,"index":16},"identifierName":"default"}, + "name": "default" }, "exported": { "type": "Identifier", - "start":9,"end":12,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":12,"index":12},"identifierName":"foo"}, + "start":20,"end":23,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":23,"index":23},"identifierName":"foo"}, "name": "foo" } } ], "source": { "type": "StringLiteral", - "start":20,"end":30,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":30,"index":30}}, + "start":31,"end":41,"loc":{"start":{"line":1,"column":31,"index":31},"end":{"line":1,"column":41,"index":41}}, "extra": { "rawValue": "foo.json", "raw": "\"foo.json\"" @@ -39,15 +39,15 @@ "assertions": [ { "type": "ImportAttribute", - "start":40,"end":52,"loc":{"start":{"line":1,"column":40,"index":40},"end":{"line":1,"column":52,"index":52}}, + "start":51,"end":63,"loc":{"start":{"line":1,"column":51,"index":51},"end":{"line":1,"column":63,"index":63}}, "key": { "type": "Identifier", - "start":40,"end":44,"loc":{"start":{"line":1,"column":40,"index":40},"end":{"line":1,"column":44,"index":44},"identifierName":"type"}, + "start":51,"end":55,"loc":{"start":{"line":1,"column":51,"index":51},"end":{"line":1,"column":55,"index":55},"identifierName":"type"}, "name": "type" }, "value": { "type": "StringLiteral", - "start":46,"end":52,"loc":{"start":{"line":1,"column":46,"index":46},"end":{"line":1,"column":52,"index":52}}, + "start":57,"end":63,"loc":{"start":{"line":1,"column":57,"index":57},"end":{"line":1,"column":63,"index":63}}, "extra": { "rawValue": "json", "raw": "\"json\"" diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-invalid-value/input.js b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-invalid-value/input.js index c2aec91e1bec..23710fef0b6d 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-invalid-value/input.js +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-invalid-value/input.js @@ -1 +1 @@ -export { foo } from "foo.json" assert { type: "json", lazy: true, startAtLine: 1 }; +export { default } from "foo.json" assert { type: "json", lazy: true, startAtLine: 1 }; diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-invalid-value/options.json b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-invalid-value/options.json index 274b43a4b5c8..75cee0d1de51 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-invalid-value/options.json +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-invalid-value/options.json @@ -5,5 +5,5 @@ ] ], "sourceType": "module", - "throws": "Only string literals are allowed as module attribute values. (1:60)" -} \ No newline at end of file + "throws": "Only string literals are allowed as module attribute values. (1:64)" +} diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-no-type-attribute/input.js b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-no-type-attribute/input.js index 49542fec11e2..5dbd2c429901 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-no-type-attribute/input.js +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-no-type-attribute/input.js @@ -1 +1 @@ -export { foo } from "foo.json" assert { lazy: "true" }; +export { default } from "foo.json" assert { lazy: "true" }; diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-no-type-attribute/output.json b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-no-type-attribute/output.json index 5bfe7e133313..3342a818b5fb 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-no-type-attribute/output.json +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-no-type-attribute/output.json @@ -1,34 +1,34 @@ { "type": "File", - "start":0,"end":55,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":55,"index":55}}, + "start":0,"end":59,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":59,"index":59}}, "program": { "type": "Program", - "start":0,"end":55,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":55,"index":55}}, + "start":0,"end":59,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":59,"index":59}}, "sourceType": "module", "interpreter": null, "body": [ { "type": "ExportNamedDeclaration", - "start":0,"end":55,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":55,"index":55}}, + "start":0,"end":59,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":59,"index":59}}, "specifiers": [ { "type": "ExportSpecifier", - "start":9,"end":12,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":12,"index":12}}, + "start":9,"end":16,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":16,"index":16}}, "local": { "type": "Identifier", - "start":9,"end":12,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":12,"index":12},"identifierName":"foo"}, - "name": "foo" + "start":9,"end":16,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":16,"index":16},"identifierName":"default"}, + "name": "default" }, "exported": { "type": "Identifier", - "start":9,"end":12,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":12,"index":12},"identifierName":"foo"}, - "name": "foo" + "start":9,"end":16,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":16,"index":16},"identifierName":"default"}, + "name": "default" } } ], "source": { "type": "StringLiteral", - "start":20,"end":30,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":30,"index":30}}, + "start":24,"end":34,"loc":{"start":{"line":1,"column":24,"index":24},"end":{"line":1,"column":34,"index":34}}, "extra": { "rawValue": "foo.json", "raw": "\"foo.json\"" @@ -39,15 +39,15 @@ "assertions": [ { "type": "ImportAttribute", - "start":40,"end":52,"loc":{"start":{"line":1,"column":40,"index":40},"end":{"line":1,"column":52,"index":52}}, + "start":44,"end":56,"loc":{"start":{"line":1,"column":44,"index":44},"end":{"line":1,"column":56,"index":56}}, "key": { "type": "Identifier", - "start":40,"end":44,"loc":{"start":{"line":1,"column":40,"index":40},"end":{"line":1,"column":44,"index":44},"identifierName":"lazy"}, + "start":44,"end":48,"loc":{"start":{"line":1,"column":44,"index":44},"end":{"line":1,"column":48,"index":48},"identifierName":"lazy"}, "name": "lazy" }, "value": { "type": "StringLiteral", - "start":46,"end":52,"loc":{"start":{"line":1,"column":46,"index":46},"end":{"line":1,"column":52,"index":52}}, + "start":50,"end":56,"loc":{"start":{"line":1,"column":50,"index":50},"end":{"line":1,"column":56,"index":56}}, "extra": { "rawValue": "true", "raw": "\"true\"" diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-object-method-attribute/input.js b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-object-method-attribute/input.js index 408a6c237aa8..8acdf464a395 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-object-method-attribute/input.js +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-object-method-attribute/input.js @@ -1 +1 @@ -export { foo } from "foo.json" assert { type: "json", hasOwnProperty: "true" }; +export { default } from "foo.json" assert { type: "json", hasOwnProperty: "true" }; diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-object-method-attribute/output.json b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-object-method-attribute/output.json index bf0067fbade0..4a4a18b389c0 100644 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-object-method-attribute/output.json +++ b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-object-method-attribute/output.json @@ -1,34 +1,34 @@ { "type": "File", - "start":0,"end":79,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":79,"index":79}}, + "start":0,"end":83,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":83,"index":83}}, "program": { "type": "Program", - "start":0,"end":79,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":79,"index":79}}, + "start":0,"end":83,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":83,"index":83}}, "sourceType": "module", "interpreter": null, "body": [ { "type": "ExportNamedDeclaration", - "start":0,"end":79,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":79,"index":79}}, + "start":0,"end":83,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":83,"index":83}}, "specifiers": [ { "type": "ExportSpecifier", - "start":9,"end":12,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":12,"index":12}}, + "start":9,"end":16,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":16,"index":16}}, "local": { "type": "Identifier", - "start":9,"end":12,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":12,"index":12},"identifierName":"foo"}, - "name": "foo" + "start":9,"end":16,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":16,"index":16},"identifierName":"default"}, + "name": "default" }, "exported": { "type": "Identifier", - "start":9,"end":12,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":12,"index":12},"identifierName":"foo"}, - "name": "foo" + "start":9,"end":16,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":16,"index":16},"identifierName":"default"}, + "name": "default" } } ], "source": { "type": "StringLiteral", - "start":20,"end":30,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":30,"index":30}}, + "start":24,"end":34,"loc":{"start":{"line":1,"column":24,"index":24},"end":{"line":1,"column":34,"index":34}}, "extra": { "rawValue": "foo.json", "raw": "\"foo.json\"" @@ -39,15 +39,15 @@ "assertions": [ { "type": "ImportAttribute", - "start":40,"end":52,"loc":{"start":{"line":1,"column":40,"index":40},"end":{"line":1,"column":52,"index":52}}, + "start":44,"end":56,"loc":{"start":{"line":1,"column":44,"index":44},"end":{"line":1,"column":56,"index":56}}, "key": { "type": "Identifier", - "start":40,"end":44,"loc":{"start":{"line":1,"column":40,"index":40},"end":{"line":1,"column":44,"index":44},"identifierName":"type"}, + "start":44,"end":48,"loc":{"start":{"line":1,"column":44,"index":44},"end":{"line":1,"column":48,"index":48},"identifierName":"type"}, "name": "type" }, "value": { "type": "StringLiteral", - "start":46,"end":52,"loc":{"start":{"line":1,"column":46,"index":46},"end":{"line":1,"column":52,"index":52}}, + "start":50,"end":56,"loc":{"start":{"line":1,"column":50,"index":50},"end":{"line":1,"column":56,"index":56}}, "extra": { "rawValue": "json", "raw": "\"json\"" @@ -57,15 +57,15 @@ }, { "type": "ImportAttribute", - "start":54,"end":76,"loc":{"start":{"line":1,"column":54,"index":54},"end":{"line":1,"column":76,"index":76}}, + "start":58,"end":80,"loc":{"start":{"line":1,"column":58,"index":58},"end":{"line":1,"column":80,"index":80}}, "key": { "type": "Identifier", - "start":54,"end":68,"loc":{"start":{"line":1,"column":54,"index":54},"end":{"line":1,"column":68,"index":68},"identifierName":"hasOwnProperty"}, + "start":58,"end":72,"loc":{"start":{"line":1,"column":58,"index":58},"end":{"line":1,"column":72,"index":72},"identifierName":"hasOwnProperty"}, "name": "hasOwnProperty" }, "value": { "type": "StringLiteral", - "start":70,"end":76,"loc":{"start":{"line":1,"column":70,"index":70},"end":{"line":1,"column":76,"index":76}}, + "start":74,"end":80,"loc":{"start":{"line":1,"column":74,"index":74},"end":{"line":1,"column":80,"index":80}}, "extra": { "rawValue": "true", "raw": "\"true\"" diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-repeated-type/input.js b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-repeated-type/input.js deleted file mode 100644 index 26c046c2e8a1..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-repeated-type/input.js +++ /dev/null @@ -1 +0,0 @@ -export { foo } from "foo.json" assert { type: "json", type: "html" }; diff --git a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-repeated-type/output.json b/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-repeated-type/output.json deleted file mode 100644 index 193329253554..000000000000 --- a/packages/babel-parser/test/fixtures/experimental/import-assertions/valid-syntax-export-with-repeated-type/output.json +++ /dev/null @@ -1,84 +0,0 @@ -{ - "type": "File", - "start":0,"end":69,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":69,"index":69}}, - "errors": [ - "SyntaxError: Duplicate key \"type\" is not allowed in module attributes. (1:54)" - ], - "program": { - "type": "Program", - "start":0,"end":69,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":69,"index":69}}, - "sourceType": "module", - "interpreter": null, - "body": [ - { - "type": "ExportNamedDeclaration", - "start":0,"end":69,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":69,"index":69}}, - "specifiers": [ - { - "type": "ExportSpecifier", - "start":9,"end":12,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":12,"index":12}}, - "local": { - "type": "Identifier", - "start":9,"end":12,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":12,"index":12},"identifierName":"foo"}, - "name": "foo" - }, - "exported": { - "type": "Identifier", - "start":9,"end":12,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":12,"index":12},"identifierName":"foo"}, - "name": "foo" - } - } - ], - "source": { - "type": "StringLiteral", - "start":20,"end":30,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":30,"index":30}}, - "extra": { - "rawValue": "foo.json", - "raw": "\"foo.json\"" - }, - "value": "foo.json" - }, - "declaration": null, - "assertions": [ - { - "type": "ImportAttribute", - "start":40,"end":52,"loc":{"start":{"line":1,"column":40,"index":40},"end":{"line":1,"column":52,"index":52}}, - "key": { - "type": "Identifier", - "start":40,"end":44,"loc":{"start":{"line":1,"column":40,"index":40},"end":{"line":1,"column":44,"index":44},"identifierName":"type"}, - "name": "type" - }, - "value": { - "type": "StringLiteral", - "start":46,"end":52,"loc":{"start":{"line":1,"column":46,"index":46},"end":{"line":1,"column":52,"index":52}}, - "extra": { - "rawValue": "json", - "raw": "\"json\"" - }, - "value": "json" - } - }, - { - "type": "ImportAttribute", - "start":54,"end":66,"loc":{"start":{"line":1,"column":54,"index":54},"end":{"line":1,"column":66,"index":66}}, - "key": { - "type": "Identifier", - "start":54,"end":58,"loc":{"start":{"line":1,"column":54,"index":54},"end":{"line":1,"column":58,"index":58},"identifierName":"type"}, - "name": "type" - }, - "value": { - "type": "StringLiteral", - "start":60,"end":66,"loc":{"start":{"line":1,"column":60,"index":60},"end":{"line":1,"column":66,"index":66}}, - "extra": { - "rawValue": "html", - "raw": "\"html\"" - }, - "value": "html" - } - } - ] - } - ], - "directives": [] - } -} diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-default-and-named-exports/input.mjs b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-default-and-named-exports/input.mjs new file mode 100644 index 000000000000..212c63290c2f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-default-and-named-exports/input.mjs @@ -0,0 +1 @@ +export fixture, { named } from "./fixture.json" assert { type: "json" } diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-default-and-named-exports/options.json b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-default-and-named-exports/options.json new file mode 100644 index 000000000000..44ff060e42a7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-default-and-named-exports/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["importAssertions", "exportDefaultFrom"], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-default-and-named-exports/output.json b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-default-and-named-exports/output.json new file mode 100644 index 000000000000..db2af548e9f8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-default-and-named-exports/output.json @@ -0,0 +1,75 @@ +{ + "type": "File", + "start":0,"end":71,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":71,"index":71}}, + "errors": [ + "SyntaxError: A JSON module can only be imported with `default`. (1:18)" + ], + "program": { + "type": "Program", + "start":0,"end":71,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":71,"index":71}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start":0,"end":71,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":71,"index":71}}, + "specifiers": [ + { + "type": "ExportDefaultSpecifier", + "start":7,"end":14,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":14,"index":14}}, + "exported": { + "type": "Identifier", + "start":7,"end":14,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":14,"index":14},"identifierName":"fixture"}, + "name": "fixture" + } + }, + { + "type": "ExportSpecifier", + "start":18,"end":23,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":23,"index":23}}, + "local": { + "type": "Identifier", + "start":18,"end":23,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":23,"index":23},"identifierName":"named"}, + "name": "named" + }, + "exported": { + "type": "Identifier", + "start":18,"end":23,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":23,"index":23},"identifierName":"named"}, + "name": "named" + } + } + ], + "source": { + "type": "StringLiteral", + "start":31,"end":47,"loc":{"start":{"line":1,"column":31,"index":31},"end":{"line":1,"column":47,"index":47}}, + "extra": { + "rawValue": "./fixture.json", + "raw": "\"./fixture.json\"" + }, + "value": "./fixture.json" + }, + "declaration": null, + "assertions": [ + { + "type": "ImportAttribute", + "start":57,"end":69,"loc":{"start":{"line":1,"column":57,"index":57},"end":{"line":1,"column":69,"index":69}}, + "key": { + "type": "Identifier", + "start":57,"end":61,"loc":{"start":{"line":1,"column":57,"index":57},"end":{"line":1,"column":61,"index":61},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":63,"end":69,"loc":{"start":{"line":1,"column":63,"index":63},"end":{"line":1,"column":69,"index":69}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + } + ] + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-default-and-named-imports/input.mjs b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-default-and-named-imports/input.mjs new file mode 100644 index 000000000000..223108f2b18c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-default-and-named-imports/input.mjs @@ -0,0 +1 @@ +import fixture, { named } from "./fixture.json" assert { type: "json" } diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-default-and-named-imports/output.json b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-default-and-named-imports/output.json new file mode 100644 index 000000000000..c249ab738bcf --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-default-and-named-imports/output.json @@ -0,0 +1,74 @@ +{ + "type": "File", + "start":0,"end":71,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":71,"index":71}}, + "errors": [ + "SyntaxError: A JSON module can only be imported with `default`. (1:18)" + ], + "program": { + "type": "Program", + "start":0,"end":71,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":71,"index":71}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start":0,"end":71,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":71,"index":71}}, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start":7,"end":14,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":14,"index":14}}, + "local": { + "type": "Identifier", + "start":7,"end":14,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":14,"index":14},"identifierName":"fixture"}, + "name": "fixture" + } + }, + { + "type": "ImportSpecifier", + "start":18,"end":23,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":23,"index":23}}, + "imported": { + "type": "Identifier", + "start":18,"end":23,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":23,"index":23},"identifierName":"named"}, + "name": "named" + }, + "local": { + "type": "Identifier", + "start":18,"end":23,"loc":{"start":{"line":1,"column":18,"index":18},"end":{"line":1,"column":23,"index":23},"identifierName":"named"}, + "name": "named" + } + } + ], + "source": { + "type": "StringLiteral", + "start":31,"end":47,"loc":{"start":{"line":1,"column":31,"index":31},"end":{"line":1,"column":47,"index":47}}, + "extra": { + "rawValue": "./fixture.json", + "raw": "\"./fixture.json\"" + }, + "value": "./fixture.json" + }, + "assertions": [ + { + "type": "ImportAttribute", + "start":57,"end":69,"loc":{"start":{"line":1,"column":57,"index":57},"end":{"line":1,"column":69,"index":69}}, + "key": { + "type": "Identifier", + "start":57,"end":61,"loc":{"start":{"line":1,"column":57,"index":57},"end":{"line":1,"column":61,"index":61},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":63,"end":69,"loc":{"start":{"line":1,"column":63,"index":63},"end":{"line":1,"column":69,"index":69}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + } + ] + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-named-exports/input.mjs b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-named-exports/input.mjs new file mode 100644 index 000000000000..ef0a80587deb --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-named-exports/input.mjs @@ -0,0 +1 @@ +export { named } from "./fixture.json" assert { type: "json" } diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-named-exports/output.json b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-named-exports/output.json new file mode 100644 index 000000000000..0967435867ab --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-named-exports/output.json @@ -0,0 +1,66 @@ +{ + "type": "File", + "start":0,"end":62,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":62,"index":62}}, + "errors": [ + "SyntaxError: A JSON module can only be imported with `default`. (1:9)" + ], + "program": { + "type": "Program", + "start":0,"end":62,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":62,"index":62}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start":0,"end":62,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":62,"index":62}}, + "specifiers": [ + { + "type": "ExportSpecifier", + "start":9,"end":14,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":14,"index":14}}, + "local": { + "type": "Identifier", + "start":9,"end":14,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":14,"index":14},"identifierName":"named"}, + "name": "named" + }, + "exported": { + "type": "Identifier", + "start":9,"end":14,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":14,"index":14},"identifierName":"named"}, + "name": "named" + } + } + ], + "source": { + "type": "StringLiteral", + "start":22,"end":38,"loc":{"start":{"line":1,"column":22,"index":22},"end":{"line":1,"column":38,"index":38}}, + "extra": { + "rawValue": "./fixture.json", + "raw": "\"./fixture.json\"" + }, + "value": "./fixture.json" + }, + "declaration": null, + "assertions": [ + { + "type": "ImportAttribute", + "start":48,"end":60,"loc":{"start":{"line":1,"column":48,"index":48},"end":{"line":1,"column":60,"index":60}}, + "key": { + "type": "Identifier", + "start":48,"end":52,"loc":{"start":{"line":1,"column":48,"index":48},"end":{"line":1,"column":52,"index":52},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":54,"end":60,"loc":{"start":{"line":1,"column":54,"index":54},"end":{"line":1,"column":60,"index":60}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + } + ] + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-named-imports/input.mjs b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-named-imports/input.mjs new file mode 100644 index 000000000000..3ad06d5ed81f --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-named-imports/input.mjs @@ -0,0 +1 @@ +import { named } from "./fixture.json" assert { type: "json" } diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-named-imports/output.json b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-named-imports/output.json new file mode 100644 index 000000000000..51eb315165af --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/invalid-named-imports/output.json @@ -0,0 +1,65 @@ +{ + "type": "File", + "start":0,"end":62,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":62,"index":62}}, + "errors": [ + "SyntaxError: A JSON module can only be imported with `default`. (1:9)" + ], + "program": { + "type": "Program", + "start":0,"end":62,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":62,"index":62}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start":0,"end":62,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":62,"index":62}}, + "specifiers": [ + { + "type": "ImportSpecifier", + "start":9,"end":14,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":14,"index":14}}, + "imported": { + "type": "Identifier", + "start":9,"end":14,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":14,"index":14},"identifierName":"named"}, + "name": "named" + }, + "local": { + "type": "Identifier", + "start":9,"end":14,"loc":{"start":{"line":1,"column":9,"index":9},"end":{"line":1,"column":14,"index":14},"identifierName":"named"}, + "name": "named" + } + } + ], + "source": { + "type": "StringLiteral", + "start":22,"end":38,"loc":{"start":{"line":1,"column":22,"index":22},"end":{"line":1,"column":38,"index":38}}, + "extra": { + "rawValue": "./fixture.json", + "raw": "\"./fixture.json\"" + }, + "value": "./fixture.json" + }, + "assertions": [ + { + "type": "ImportAttribute", + "start":48,"end":60,"loc":{"start":{"line":1,"column":48,"index":48},"end":{"line":1,"column":60,"index":60}}, + "key": { + "type": "Identifier", + "start":48,"end":52,"loc":{"start":{"line":1,"column":48,"index":48},"end":{"line":1,"column":52,"index":52},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":54,"end":60,"loc":{"start":{"line":1,"column":54,"index":54},"end":{"line":1,"column":60,"index":60}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + } + ] + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/options.json b/packages/babel-parser/test/fixtures/experimental/json-modules/options.json new file mode 100644 index 000000000000..51a9e56a5cbd --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["importAssertions"], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/valid-all-exports/input.mjs b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-all-exports/input.mjs new file mode 100644 index 000000000000..5ea10bff219d --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-all-exports/input.mjs @@ -0,0 +1 @@ +export * from "./fixture.json" assert { type: "json" } diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/valid-all-exports/output.json b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-all-exports/output.json new file mode 100644 index 000000000000..ef41ee07b33c --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-all-exports/output.json @@ -0,0 +1,46 @@ +{ + "type": "File", + "start":0,"end":54,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":54,"index":54}}, + "program": { + "type": "Program", + "start":0,"end":54,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":54,"index":54}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportAllDeclaration", + "start":0,"end":54,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":54,"index":54}}, + "source": { + "type": "StringLiteral", + "start":14,"end":30,"loc":{"start":{"line":1,"column":14,"index":14},"end":{"line":1,"column":30,"index":30}}, + "extra": { + "rawValue": "./fixture.json", + "raw": "\"./fixture.json\"" + }, + "value": "./fixture.json" + }, + "assertions": [ + { + "type": "ImportAttribute", + "start":40,"end":52,"loc":{"start":{"line":1,"column":40,"index":40},"end":{"line":1,"column":52,"index":52}}, + "key": { + "type": "Identifier", + "start":40,"end":44,"loc":{"start":{"line":1,"column":40,"index":40},"end":{"line":1,"column":44,"index":44},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":46,"end":52,"loc":{"start":{"line":1,"column":46,"index":46},"end":{"line":1,"column":52,"index":52}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + } + ] + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/valid-default-and-namespace-exports/input.mjs b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-default-and-namespace-exports/input.mjs new file mode 100644 index 000000000000..ccd28c9af5c7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-default-and-namespace-exports/input.mjs @@ -0,0 +1 @@ +export fixture, * as ns from "./fixture.json" assert { type: "json" } diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/valid-default-and-namespace-exports/options.json b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-default-and-namespace-exports/options.json new file mode 100644 index 000000000000..44ff060e42a7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-default-and-namespace-exports/options.json @@ -0,0 +1,4 @@ +{ + "plugins": ["importAssertions", "exportDefaultFrom"], + "sourceType": "module" +} diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/valid-default-and-namespace-exports/output.json b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-default-and-namespace-exports/output.json new file mode 100644 index 000000000000..f62519cc3122 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-default-and-namespace-exports/output.json @@ -0,0 +1,66 @@ +{ + "type": "File", + "start":0,"end":69,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":69,"index":69}}, + "program": { + "type": "Program", + "start":0,"end":69,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":69,"index":69}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start":0,"end":69,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":69,"index":69}}, + "specifiers": [ + { + "type": "ExportDefaultSpecifier", + "start":7,"end":14,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":14,"index":14}}, + "exported": { + "type": "Identifier", + "start":7,"end":14,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":14,"index":14},"identifierName":"fixture"}, + "name": "fixture" + } + }, + { + "type": "ExportNamespaceSpecifier", + "start":16,"end":23,"loc":{"start":{"line":1,"column":16,"index":16},"end":{"line":1,"column":23,"index":23}}, + "exported": { + "type": "Identifier", + "start":21,"end":23,"loc":{"start":{"line":1,"column":21,"index":21},"end":{"line":1,"column":23,"index":23},"identifierName":"ns"}, + "name": "ns" + } + } + ], + "source": { + "type": "StringLiteral", + "start":29,"end":45,"loc":{"start":{"line":1,"column":29,"index":29},"end":{"line":1,"column":45,"index":45}}, + "extra": { + "rawValue": "./fixture.json", + "raw": "\"./fixture.json\"" + }, + "value": "./fixture.json" + }, + "assertions": [ + { + "type": "ImportAttribute", + "start":55,"end":67,"loc":{"start":{"line":1,"column":55,"index":55},"end":{"line":1,"column":67,"index":67}}, + "key": { + "type": "Identifier", + "start":55,"end":59,"loc":{"start":{"line":1,"column":55,"index":55},"end":{"line":1,"column":59,"index":59},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":61,"end":67,"loc":{"start":{"line":1,"column":61,"index":61},"end":{"line":1,"column":67,"index":67}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + } + ] + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/valid-default-and-namespace-imports/input.mjs b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-default-and-namespace-imports/input.mjs new file mode 100644 index 000000000000..59eb81f48a18 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-default-and-namespace-imports/input.mjs @@ -0,0 +1 @@ +import fixture, * as ns from "./fixture.json" assert { type: "json" } diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/valid-default-and-namespace-imports/output.json b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-default-and-namespace-imports/output.json new file mode 100644 index 000000000000..c3b74bde7926 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-default-and-namespace-imports/output.json @@ -0,0 +1,66 @@ +{ + "type": "File", + "start":0,"end":69,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":69,"index":69}}, + "program": { + "type": "Program", + "start":0,"end":69,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":69,"index":69}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start":0,"end":69,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":69,"index":69}}, + "specifiers": [ + { + "type": "ImportDefaultSpecifier", + "start":7,"end":14,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":14,"index":14}}, + "local": { + "type": "Identifier", + "start":7,"end":14,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":14,"index":14},"identifierName":"fixture"}, + "name": "fixture" + } + }, + { + "type": "ImportNamespaceSpecifier", + "start":16,"end":23,"loc":{"start":{"line":1,"column":16,"index":16},"end":{"line":1,"column":23,"index":23}}, + "local": { + "type": "Identifier", + "start":21,"end":23,"loc":{"start":{"line":1,"column":21,"index":21},"end":{"line":1,"column":23,"index":23},"identifierName":"ns"}, + "name": "ns" + } + } + ], + "source": { + "type": "StringLiteral", + "start":29,"end":45,"loc":{"start":{"line":1,"column":29,"index":29},"end":{"line":1,"column":45,"index":45}}, + "extra": { + "rawValue": "./fixture.json", + "raw": "\"./fixture.json\"" + }, + "value": "./fixture.json" + }, + "assertions": [ + { + "type": "ImportAttribute", + "start":55,"end":67,"loc":{"start":{"line":1,"column":55,"index":55},"end":{"line":1,"column":67,"index":67}}, + "key": { + "type": "Identifier", + "start":55,"end":59,"loc":{"start":{"line":1,"column":55,"index":55},"end":{"line":1,"column":59,"index":59},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":61,"end":67,"loc":{"start":{"line":1,"column":61,"index":61},"end":{"line":1,"column":67,"index":67}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + } + ] + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/valid-namespace-exports/input.mjs b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-namespace-exports/input.mjs new file mode 100644 index 000000000000..b687807d35b8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-namespace-exports/input.mjs @@ -0,0 +1 @@ +export * as ns from "./fixture.json" assert { type: "json" } diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/valid-namespace-exports/output.json b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-namespace-exports/output.json new file mode 100644 index 000000000000..8d6700a299cc --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-namespace-exports/output.json @@ -0,0 +1,57 @@ +{ + "type": "File", + "start":0,"end":60,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":60,"index":60}}, + "program": { + "type": "Program", + "start":0,"end":60,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":60,"index":60}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExportNamedDeclaration", + "start":0,"end":60,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":60,"index":60}}, + "specifiers": [ + { + "type": "ExportNamespaceSpecifier", + "start":7,"end":14,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":14,"index":14}}, + "exported": { + "type": "Identifier", + "start":12,"end":14,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":14,"index":14},"identifierName":"ns"}, + "name": "ns" + } + } + ], + "source": { + "type": "StringLiteral", + "start":20,"end":36,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":36,"index":36}}, + "extra": { + "rawValue": "./fixture.json", + "raw": "\"./fixture.json\"" + }, + "value": "./fixture.json" + }, + "assertions": [ + { + "type": "ImportAttribute", + "start":46,"end":58,"loc":{"start":{"line":1,"column":46,"index":46},"end":{"line":1,"column":58,"index":58}}, + "key": { + "type": "Identifier", + "start":46,"end":50,"loc":{"start":{"line":1,"column":46,"index":46},"end":{"line":1,"column":50,"index":50},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":52,"end":58,"loc":{"start":{"line":1,"column":52,"index":52},"end":{"line":1,"column":58,"index":58}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + } + ] + } + ], + "directives": [] + } +} diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/valid-namespace-imports/input.mjs b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-namespace-imports/input.mjs new file mode 100644 index 000000000000..24331874b0c9 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-namespace-imports/input.mjs @@ -0,0 +1 @@ +import * as ns from "./fixture.json" assert { type: "json" } diff --git a/packages/babel-parser/test/fixtures/experimental/json-modules/valid-namespace-imports/output.json b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-namespace-imports/output.json new file mode 100644 index 000000000000..ea6e41eb2c15 --- /dev/null +++ b/packages/babel-parser/test/fixtures/experimental/json-modules/valid-namespace-imports/output.json @@ -0,0 +1,57 @@ +{ + "type": "File", + "start":0,"end":60,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":60,"index":60}}, + "program": { + "type": "Program", + "start":0,"end":60,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":60,"index":60}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ImportDeclaration", + "start":0,"end":60,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":1,"column":60,"index":60}}, + "specifiers": [ + { + "type": "ImportNamespaceSpecifier", + "start":7,"end":14,"loc":{"start":{"line":1,"column":7,"index":7},"end":{"line":1,"column":14,"index":14}}, + "local": { + "type": "Identifier", + "start":12,"end":14,"loc":{"start":{"line":1,"column":12,"index":12},"end":{"line":1,"column":14,"index":14},"identifierName":"ns"}, + "name": "ns" + } + } + ], + "source": { + "type": "StringLiteral", + "start":20,"end":36,"loc":{"start":{"line":1,"column":20,"index":20},"end":{"line":1,"column":36,"index":36}}, + "extra": { + "rawValue": "./fixture.json", + "raw": "\"./fixture.json\"" + }, + "value": "./fixture.json" + }, + "assertions": [ + { + "type": "ImportAttribute", + "start":46,"end":58,"loc":{"start":{"line":1,"column":46,"index":46},"end":{"line":1,"column":58,"index":58}}, + "key": { + "type": "Identifier", + "start":46,"end":50,"loc":{"start":{"line":1,"column":46,"index":46},"end":{"line":1,"column":50,"index":50},"identifierName":"type"}, + "name": "type" + }, + "value": { + "type": "StringLiteral", + "start":52,"end":58,"loc":{"start":{"line":1,"column":52,"index":52},"end":{"line":1,"column":58,"index":58}}, + "extra": { + "rawValue": "json", + "raw": "\"json\"" + }, + "value": "json" + } + } + ] + } + ], + "directives": [] + } +} diff --git a/packages/babel-preset-env/test/fixtures/shipped-proposals/import-assertions/input.mjs b/packages/babel-preset-env/test/fixtures/shipped-proposals/import-assertions/input.mjs index 436061f3afdb..9f63fa2fdab9 100644 --- a/packages/babel-preset-env/test/fixtures/shipped-proposals/import-assertions/input.mjs +++ b/packages/babel-preset-env/test/fixtures/shipped-proposals/import-assertions/input.mjs @@ -1 +1 @@ -import { version } from "./package.json" assert { type: "json" } +import packageJson from "./package.json" assert { type: "json" } diff --git a/packages/babel-preset-env/test/fixtures/shipped-proposals/import-assertions/output.js b/packages/babel-preset-env/test/fixtures/shipped-proposals/import-assertions/output.js index 0a0ea4fde67c..bcee0b0e767a 100644 --- a/packages/babel-preset-env/test/fixtures/shipped-proposals/import-assertions/output.js +++ b/packages/babel-preset-env/test/fixtures/shipped-proposals/import-assertions/output.js @@ -1,3 +1,3 @@ "use strict"; -var _package = require("./package.json"); +var _package = babelHelpers.interopRequireDefault(require("./package.json")); diff --git a/packages/babel-template/test/index.js b/packages/babel-template/test/index.js index 4a7f97b164c1..dcb77b38539e 100644 --- a/packages/babel-template/test/index.js +++ b/packages/babel-template/test/index.js @@ -231,7 +231,7 @@ describe("@babel/template", function () { it("should return assertions in ExportNamedDeclaration when using .ast", () => { const result = template.ast( - `export { foo2 } from "foo.json" assert { type: "json" };`, + `export { default as foo2 } from "foo.json" assert { type: "json" };`, { plugins: ["importAssertions"], }, diff --git a/scripts/parser-tests/test262/allowlist.txt b/scripts/parser-tests/test262/allowlist.txt index 8d3adcaa48fa..f2ad1620f3d6 100644 --- a/scripts/parser-tests/test262/allowlist.txt +++ b/scripts/parser-tests/test262/allowlist.txt @@ -4,8 +4,6 @@ language/expressions/class/decorator/syntax/valid/decorator-member-expr-decorato language/expressions/class/decorator/syntax/valid/decorator-member-expr-decorator-member-expr.js(strict mode) language/import/json-invalid.js(default) language/import/json-invalid.js(strict mode) -language/import/json-named-bindings.js(default) -language/import/json-named-bindings.js(strict mode) language/statements/class/decorator/syntax/class-valid/decorator-member-expr-private-identifier.js(default) language/statements/class/decorator/syntax/class-valid/decorator-member-expr-private-identifier.js(strict mode) language/statements/class/decorator/syntax/valid/decorator-member-expr-decorator-member-expr.js(default)