added basic support for module attributes and tests updated (#10962)
Co-Authored-By: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
parent
c5ba345ac2
commit
66b86e088c
@ -765,12 +765,22 @@ export default class ExpressionParser extends LValParser {
|
|||||||
optional: boolean,
|
optional: boolean,
|
||||||
): N.Expression {
|
): N.Expression {
|
||||||
if (node.callee.type === "Import") {
|
if (node.callee.type === "Import") {
|
||||||
if (node.arguments.length !== 1) {
|
if (node.arguments.length === 2) {
|
||||||
this.raise(node.start, Errors.ImportCallArity);
|
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 {
|
} else {
|
||||||
const importArg = node.arguments[0];
|
for (const arg of node.arguments) {
|
||||||
if (importArg?.type === "SpreadElement") {
|
if (arg.type === "SpreadElement") {
|
||||||
this.raise(importArg.start, Errors.ImportCallSpreadArgument);
|
this.raise(arg.start, Errors.ImportCallSpreadArgument);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -799,7 +809,7 @@ export default class ExpressionParser extends LValParser {
|
|||||||
} else {
|
} else {
|
||||||
this.expect(tt.comma);
|
this.expect(tt.comma);
|
||||||
if (this.match(close)) {
|
if (this.match(close)) {
|
||||||
if (dynamicImport) {
|
if (dynamicImport && !this.hasPlugin("moduleAttributes")) {
|
||||||
this.raise(
|
this.raise(
|
||||||
this.state.lastTokStart,
|
this.state.lastTokStart,
|
||||||
Errors.ImportCallArgumentTrailingComma,
|
Errors.ImportCallArgumentTrailingComma,
|
||||||
|
|||||||
@ -67,7 +67,7 @@ export const Errors = Object.freeze({
|
|||||||
IllegalReturn: "'return' outside of function",
|
IllegalReturn: "'return' outside of function",
|
||||||
ImportCallArgumentTrailingComma:
|
ImportCallArgumentTrailingComma:
|
||||||
"Trailing comma is disallowed inside import(...) arguments",
|
"Trailing comma is disallowed inside import(...) arguments",
|
||||||
ImportCallArity: "import() requires exactly one argument",
|
ImportCallArity: "import() requires exactly %0",
|
||||||
ImportCallNotNewExpression: "Cannot use new with import(...)",
|
ImportCallNotNewExpression: "Cannot use new with import(...)",
|
||||||
ImportCallSpreadArgument: "... is not allowed in import()",
|
ImportCallSpreadArgument: "... is not allowed in import()",
|
||||||
ImportMetaOutsideModule: `import.meta may appear only with 'sourceType: "module"'`,
|
ImportMetaOutsideModule: `import.meta may appear only with 'sourceType: "module"'`,
|
||||||
@ -96,6 +96,12 @@ export const Errors = Object.freeze({
|
|||||||
MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX",
|
MissingUnicodeEscape: "Expecting Unicode escape sequence \\uXXXX",
|
||||||
MixingCoalesceWithLogical:
|
MixingCoalesceWithLogical:
|
||||||
"Nullish coalescing operator(??) requires parens when mixing with logical operators",
|
"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",
|
ModuleExportUndefined: "Export '%0' is not defined",
|
||||||
MultipleDefaultsInSwitch: "Multiple default clauses",
|
MultipleDefaultsInSwitch: "Multiple default clauses",
|
||||||
NewlineAfterThrow: "Illegal newline after throw",
|
NewlineAfterThrow: "Illegal newline after throw",
|
||||||
|
|||||||
@ -2038,13 +2038,31 @@ export default class StatementParser extends ExpressionParser {
|
|||||||
// import '...'
|
// import '...'
|
||||||
node.specifiers = [];
|
node.specifiers = [];
|
||||||
if (!this.match(tt.string)) {
|
if (!this.match(tt.string)) {
|
||||||
|
// check if we have a default import like
|
||||||
|
// import React from "react";
|
||||||
const hasDefault = this.maybeParseDefaultImportSpecifier(node);
|
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);
|
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);
|
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);
|
if (parseNext && !hasStar) this.parseNamedImportSpecifiers(node);
|
||||||
this.expectContextual("from");
|
this.expectContextual("from");
|
||||||
}
|
}
|
||||||
node.source = this.parseImportSource();
|
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();
|
this.semicolon();
|
||||||
return this.finishNode(node, "ImportDeclaration");
|
return this.finishNode(node, "ImportDeclaration");
|
||||||
}
|
}
|
||||||
@ -2075,6 +2093,59 @@ export default class StatementParser extends ExpressionParser {
|
|||||||
node.specifiers.push(this.finishNode(specifier, type));
|
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 {
|
maybeParseDefaultImportSpecifier(node: N.ImportDeclaration): boolean {
|
||||||
if (this.shouldParseDefaultImport(node)) {
|
if (this.shouldParseDefaultImport(node)) {
|
||||||
// import defaultObj, { x, y as z } from '...'
|
// import defaultObj, { x, y as z } from '...'
|
||||||
|
|||||||
@ -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 (
|
if (
|
||||||
hasPlugin(plugins, "recordAndTuple") &&
|
hasPlugin(plugins, "recordAndTuple") &&
|
||||||
!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(
|
!RECORD_AND_TUPLE_SYNTAX_TYPES.includes(
|
||||||
|
|||||||
@ -1,111 +1,33 @@
|
|||||||
{
|
{
|
||||||
"type": "File",
|
"type": "File",
|
||||||
"start": 0,
|
"start":0,"end":47,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}},
|
||||||
"end": 47,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 5,
|
|
||||||
"column": 2
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"program": {
|
"program": {
|
||||||
"type": "Program",
|
"type": "Program",
|
||||||
"start": 0,
|
"start":0,"end":47,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}},
|
||||||
"end": 47,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 5,
|
|
||||||
"column": 2
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"sourceType": "script",
|
"sourceType": "script",
|
||||||
"interpreter": null,
|
"interpreter": null,
|
||||||
"body": [
|
"body": [
|
||||||
{
|
{
|
||||||
"type": "ClassDeclaration",
|
"type": "ClassDeclaration",
|
||||||
"start": 0,
|
"start":0,"end":10,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":10}},
|
||||||
"end": 10,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 10
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"id": {
|
"id": {
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start": 6,
|
"start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"X"},
|
||||||
"end": 7,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 6
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 7
|
|
||||||
},
|
|
||||||
"identifierName": "X"
|
|
||||||
},
|
|
||||||
"name": "X"
|
"name": "X"
|
||||||
},
|
},
|
||||||
"superClass": null,
|
"superClass": null,
|
||||||
"body": {
|
"body": {
|
||||||
"type": "ClassBody",
|
"type": "ClassBody",
|
||||||
"start": 8,
|
"start":8,"end":10,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":10}},
|
||||||
"end": 10,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 8
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 1,
|
|
||||||
"column": 10
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"body": []
|
"body": []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "ExpressionStatement",
|
"type": "ExpressionStatement",
|
||||||
"start": 11,
|
"start":11,"end":13,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":2}},
|
||||||
"end": 13,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 2,
|
|
||||||
"column": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 2,
|
|
||||||
"column": 2
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"expression": {
|
"expression": {
|
||||||
"type": "NumericLiteral",
|
"type": "NumericLiteral",
|
||||||
"start": 11,
|
"start":11,"end":13,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":2}},
|
||||||
"end": 13,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 2,
|
|
||||||
"column": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 2,
|
|
||||||
"column": 2
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"extra": {
|
"extra": {
|
||||||
"rawValue": 5,
|
"rawValue": 5,
|
||||||
"raw": "05"
|
"raw": "05"
|
||||||
@ -115,33 +37,10 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "FunctionDeclaration",
|
"type": "FunctionDeclaration",
|
||||||
"start": 15,
|
"start":15,"end":44,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":29}},
|
||||||
"end": 44,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 4,
|
|
||||||
"column": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 4,
|
|
||||||
"column": 29
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"id": {
|
"id": {
|
||||||
"type": "Identifier",
|
"type": "Identifier",
|
||||||
"start": 24,
|
"start":24,"end":25,"loc":{"start":{"line":4,"column":9},"end":{"line":4,"column":10},"identifierName":"x"},
|
||||||
"end": 25,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 4,
|
|
||||||
"column": 9
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 4,
|
|
||||||
"column": 10
|
|
||||||
},
|
|
||||||
"identifierName": "x"
|
|
||||||
},
|
|
||||||
"name": "x"
|
"name": "x"
|
||||||
},
|
},
|
||||||
"generator": false,
|
"generator": false,
|
||||||
@ -149,48 +48,15 @@
|
|||||||
"params": [],
|
"params": [],
|
||||||
"body": {
|
"body": {
|
||||||
"type": "BlockStatement",
|
"type": "BlockStatement",
|
||||||
"start": 28,
|
"start":28,"end":44,"loc":{"start":{"line":4,"column":13},"end":{"line":4,"column":29}},
|
||||||
"end": 44,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 4,
|
|
||||||
"column": 13
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 4,
|
|
||||||
"column": 29
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"body": [],
|
"body": [],
|
||||||
"directives": [
|
"directives": [
|
||||||
{
|
{
|
||||||
"type": "Directive",
|
"type": "Directive",
|
||||||
"start": 30,
|
"start":30,"end":42,"loc":{"start":{"line":4,"column":15},"end":{"line":4,"column":27}},
|
||||||
"end": 42,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 4,
|
|
||||||
"column": 15
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 4,
|
|
||||||
"column": 27
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"value": {
|
"value": {
|
||||||
"type": "DirectiveLiteral",
|
"type": "DirectiveLiteral",
|
||||||
"start": 30,
|
"start":30,"end":42,"loc":{"start":{"line":4,"column":15},"end":{"line":4,"column":27}},
|
||||||
"end": 42,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 4,
|
|
||||||
"column": 15
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 4,
|
|
||||||
"column": 27
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"value": "use strict",
|
"value": "use strict",
|
||||||
"extra": {
|
"extra": {
|
||||||
"raw": "'use strict'",
|
"raw": "'use strict'",
|
||||||
@ -203,32 +69,10 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "ExpressionStatement",
|
"type": "ExpressionStatement",
|
||||||
"start": 45,
|
"start":45,"end":47,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":2}},
|
||||||
"end": 47,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 5,
|
|
||||||
"column": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 5,
|
|
||||||
"column": 2
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"expression": {
|
"expression": {
|
||||||
"type": "NumericLiteral",
|
"type": "NumericLiteral",
|
||||||
"start": 45,
|
"start":45,"end":47,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":2}},
|
||||||
"end": 47,
|
|
||||||
"loc": {
|
|
||||||
"start": {
|
|
||||||
"line": 5,
|
|
||||||
"column": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 5,
|
|
||||||
"column": 2
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"extra": {
|
"extra": {
|
||||||
"rawValue": 5,
|
"rawValue": 5,
|
||||||
"raw": "05"
|
"raw": "05"
|
||||||
|
|||||||
@ -1 +1 @@
|
|||||||
import('hello', 'world');
|
import('hello', 'world', '!');
|
||||||
|
|||||||
@ -1,21 +1,21 @@
|
|||||||
{
|
{
|
||||||
"type": "File",
|
"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": [
|
"errors": [
|
||||||
"SyntaxError: import() requires exactly one argument (1:0)"
|
"SyntaxError: import() requires exactly one argument (1:0)"
|
||||||
],
|
],
|
||||||
"program": {
|
"program": {
|
||||||
"type": "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",
|
"sourceType": "script",
|
||||||
"interpreter": null,
|
"interpreter": null,
|
||||||
"body": [
|
"body": [
|
||||||
{
|
{
|
||||||
"type": "ExpressionStatement",
|
"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": {
|
"expression": {
|
||||||
"type": "CallExpression",
|
"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": {
|
"callee": {
|
||||||
"type": "Import",
|
"type": "Import",
|
||||||
"start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}}
|
"start":0,"end":6,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":6}}
|
||||||
@ -38,6 +38,15 @@
|
|||||||
"raw": "'world'"
|
"raw": "'world'"
|
||||||
},
|
},
|
||||||
"value": "world"
|
"value": "world"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "StringLiteral",
|
||||||
|
"start":25,"end":28,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":28}},
|
||||||
|
"extra": {
|
||||||
|
"rawValue": "!",
|
||||||
|
"raw": "'!'"
|
||||||
|
},
|
||||||
|
"value": "!"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1 @@
|
|||||||
|
import('hello', 'world');
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"throws": "This experimental syntax requires enabling the parser plugin: 'moduleAttributes' (1:24)",
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": []
|
||||||
|
}
|
||||||
1
packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
import foo from "foo.json" with type: "json";
|
||||||
5
packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes/options.json
vendored
Normal file
5
packages/babel-parser/test/fixtures/experimental/_no-plugin/module-attributes/options.json
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"throws": "This experimental syntax requires enabling the parser plugin: 'moduleAttributes' (1:27)",
|
||||||
|
"sourceType": "module",
|
||||||
|
"plugins": []
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
import("foo.json", { with: { type: "json" } })
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"moduleAttributes",
|
||||||
|
{
|
||||||
|
"version": "may-2020"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sourceType": "module"
|
||||||
|
}
|
||||||
@ -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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
import "x"
|
||||||
|
with ({});
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"moduleAttributes",
|
||||||
|
{
|
||||||
|
"version": "may-2020"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"estree"
|
||||||
|
],
|
||||||
|
"sourceType": "module"
|
||||||
|
}
|
||||||
@ -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}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
2
packages/babel-parser/test/fixtures/experimental/module-attributes/incorrect-arity/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/experimental/module-attributes/incorrect-arity/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import();
|
||||||
|
import("./foo.json", { with: { type: "json"} }, "unsupported");
|
||||||
11
packages/babel-parser/test/fixtures/experimental/module-attributes/incorrect-arity/options.json
vendored
Normal file
11
packages/babel-parser/test/fixtures/experimental/module-attributes/incorrect-arity/options.json
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"moduleAttributes",
|
||||||
|
{
|
||||||
|
"version": "may-2020"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sourceType": "module"
|
||||||
|
}
|
||||||
107
packages/babel-parser/test/fixtures/experimental/module-attributes/incorrect-arity/output.json
vendored
Normal file
107
packages/babel-parser/test/fixtures/experimental/module-attributes/incorrect-arity/output.json
vendored
Normal file
@ -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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
import("./foo.json", ...[]);
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"moduleAttributes",
|
||||||
|
{
|
||||||
|
"version": "may-2020"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sourceType": "module"
|
||||||
|
}
|
||||||
@ -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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
import "x" with
|
||||||
|
type: "json"
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"moduleAttributes",
|
||||||
|
{
|
||||||
|
"version": "may-2020"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sourceType": "module"
|
||||||
|
}
|
||||||
@ -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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
import "x" with;
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"throws": "Unexpected token (1:15)",
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"moduleAttributes",
|
||||||
|
{
|
||||||
|
"version": "may-2020"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sourceType": "module"
|
||||||
|
}
|
||||||
2
packages/babel-parser/test/fixtures/experimental/module-attributes/trailing-comma/input.js
vendored
Normal file
2
packages/babel-parser/test/fixtures/experimental/module-attributes/trailing-comma/input.js
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
import("foo.js",);
|
||||||
|
import("foo.json", { with: { type: "json" } },);
|
||||||
11
packages/babel-parser/test/fixtures/experimental/module-attributes/trailing-comma/options.json
vendored
Normal file
11
packages/babel-parser/test/fixtures/experimental/module-attributes/trailing-comma/options.json
vendored
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"moduleAttributes",
|
||||||
|
{
|
||||||
|
"version": "may-2020"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sourceType": "module"
|
||||||
|
}
|
||||||
110
packages/babel-parser/test/fixtures/experimental/module-attributes/trailing-comma/output.json
vendored
Normal file
110
packages/babel-parser/test/fixtures/experimental/module-attributes/trailing-comma/output.json
vendored
Normal file
@ -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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,2 @@
|
|||||||
|
import "x" with type: "json"
|
||||||
|
[0]
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"moduleAttributes",
|
||||||
|
{
|
||||||
|
"version": "may-2020"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sourceType": "module"
|
||||||
|
}
|
||||||
@ -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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
import foo from "foo.json" with type: "json";
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"moduleAttributes",
|
||||||
|
{
|
||||||
|
"version": "may-2020"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sourceType": "module"
|
||||||
|
}
|
||||||
@ -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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
import foo from "foo.json" with type: "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'."
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
import foo from "foo.json" with type: "json", lazy: true, startAtLine: 1;
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"moduleAttributes",
|
||||||
|
{
|
||||||
|
"version": "may-2020"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sourceType": "module",
|
||||||
|
"throws": "Only string literals are allowed as module attribute values (1:52)"
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
import foo from "foo.json" with lazy: "true";
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"moduleAttributes",
|
||||||
|
{
|
||||||
|
"version": "may-2020"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sourceType": "module"
|
||||||
|
}
|
||||||
@ -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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
import foo from "foo.json" with type: "json", hasOwnProperty: "true";
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"moduleAttributes",
|
||||||
|
{
|
||||||
|
"version": "may-2020"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sourceType": "module"
|
||||||
|
}
|
||||||
@ -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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
import foo from "foo.json" with type: "json", type: "html";
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"moduleAttributes",
|
||||||
|
{
|
||||||
|
"version": "may-2020"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sourceType": "module"
|
||||||
|
}
|
||||||
@ -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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1 @@
|
|||||||
|
import foo from "foo.json";
|
||||||
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"plugins": [
|
||||||
|
[
|
||||||
|
"moduleAttributes",
|
||||||
|
{
|
||||||
|
"version": "may-2020"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"sourceType": "module"
|
||||||
|
}
|
||||||
@ -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": []
|
||||||
|
}
|
||||||
|
}
|
||||||
1
packages/babel-parser/test/fixtures/experimental/module-attributes/without-plugin/input.js
vendored
Normal file
1
packages/babel-parser/test/fixtures/experimental/module-attributes/without-plugin/input.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
import foo from "foo.json" with type: "json";
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"throws": "This experimental syntax requires enabling the parser plugin: 'moduleAttributes' (1:27)",
|
||||||
|
"plugins": []
|
||||||
|
}
|
||||||
@ -114,6 +114,7 @@ export type ParserPlugin =
|
|||||||
'importMeta' |
|
'importMeta' |
|
||||||
'jsx' |
|
'jsx' |
|
||||||
'logicalAssignment' |
|
'logicalAssignment' |
|
||||||
|
'moduleAttributes' |
|
||||||
'nullishCoalescingOperator' |
|
'nullishCoalescingOperator' |
|
||||||
'numericSeparator' |
|
'numericSeparator' |
|
||||||
'objectRestSpread' |
|
'objectRestSpread' |
|
||||||
|
|||||||
@ -0,0 +1,3 @@
|
|||||||
|
*.log
|
||||||
|
src
|
||||||
|
test
|
||||||
19
packages/babel-plugin-syntax-module-attributes/README.md
Normal file
19
packages/babel-plugin-syntax-module-attributes/README.md
Normal file
@ -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
|
||||||
|
```
|
||||||
23
packages/babel-plugin-syntax-module-attributes/package.json
Normal file
23
packages/babel-plugin-syntax-module-attributes/package.json
Normal file
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
21
packages/babel-plugin-syntax-module-attributes/src/index.js
Normal file
21
packages/babel-plugin-syntax-module-attributes/src/index.js
Normal file
@ -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 }]);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
@ -44,6 +44,7 @@
|
|||||||
"@babel/plugin-syntax-function-sent": "^7.8.3",
|
"@babel/plugin-syntax-function-sent": "^7.8.3",
|
||||||
"@babel/plugin-syntax-import-meta": "^7.8.3",
|
"@babel/plugin-syntax-import-meta": "^7.8.3",
|
||||||
"@babel/plugin-syntax-jsx": "^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-object-rest-spread": "^7.8.0",
|
||||||
"@babel/plugin-syntax-optional-catch-binding": "^7.8.0",
|
"@babel/plugin-syntax-optional-catch-binding": "^7.8.0",
|
||||||
"@babel/plugin-syntax-pipeline-operator": "^7.8.3",
|
"@babel/plugin-syntax-pipeline-operator": "^7.8.3",
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
"syntax-function-sent",
|
"syntax-function-sent",
|
||||||
"syntax-import-meta",
|
"syntax-import-meta",
|
||||||
"syntax-jsx",
|
"syntax-jsx",
|
||||||
|
"syntax-module-attributes",
|
||||||
"syntax-object-rest-spread",
|
"syntax-object-rest-spread",
|
||||||
"syntax-optional-catch-binding",
|
"syntax-optional-catch-binding",
|
||||||
"syntax-pipeline-operator",
|
"syntax-pipeline-operator",
|
||||||
|
|||||||
@ -14,6 +14,7 @@ import syntaxFunctionBind from "@babel/plugin-syntax-function-bind";
|
|||||||
import syntaxFunctionSent from "@babel/plugin-syntax-function-sent";
|
import syntaxFunctionSent from "@babel/plugin-syntax-function-sent";
|
||||||
import syntaxImportMeta from "@babel/plugin-syntax-import-meta";
|
import syntaxImportMeta from "@babel/plugin-syntax-import-meta";
|
||||||
import syntaxJsx from "@babel/plugin-syntax-jsx";
|
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 syntaxObjectRestSpread from "@babel/plugin-syntax-object-rest-spread";
|
||||||
import syntaxOptionalCatchBinding from "@babel/plugin-syntax-optional-catch-binding";
|
import syntaxOptionalCatchBinding from "@babel/plugin-syntax-optional-catch-binding";
|
||||||
import syntaxPipelineOperator from "@babel/plugin-syntax-pipeline-operator";
|
import syntaxPipelineOperator from "@babel/plugin-syntax-pipeline-operator";
|
||||||
@ -103,6 +104,7 @@ export {
|
|||||||
syntaxFunctionSent,
|
syntaxFunctionSent,
|
||||||
syntaxImportMeta,
|
syntaxImportMeta,
|
||||||
syntaxJsx,
|
syntaxJsx,
|
||||||
|
syntaxModuleAttributes,
|
||||||
syntaxObjectRestSpread,
|
syntaxObjectRestSpread,
|
||||||
syntaxOptionalCatchBinding,
|
syntaxOptionalCatchBinding,
|
||||||
syntaxPipelineOperator,
|
syntaxPipelineOperator,
|
||||||
@ -193,6 +195,7 @@ export const all = {
|
|||||||
"syntax-function-sent": syntaxFunctionSent,
|
"syntax-function-sent": syntaxFunctionSent,
|
||||||
"syntax-import-meta": syntaxImportMeta,
|
"syntax-import-meta": syntaxImportMeta,
|
||||||
"syntax-jsx": syntaxJsx,
|
"syntax-jsx": syntaxJsx,
|
||||||
|
"syntax-module-attributes": syntaxModuleAttributes,
|
||||||
"syntax-object-rest-spread": syntaxObjectRestSpread,
|
"syntax-object-rest-spread": syntaxObjectRestSpread,
|
||||||
"syntax-optional-catch-binding": syntaxOptionalCatchBinding,
|
"syntax-optional-catch-binding": syntaxOptionalCatchBinding,
|
||||||
"syntax-pipeline-operator": syntaxPipelineOperator,
|
"syntax-pipeline-operator": syntaxPipelineOperator,
|
||||||
|
|||||||
@ -10,6 +10,7 @@ export default (_: any, opts: Object = {}) => {
|
|||||||
decoratorsBeforeExport,
|
decoratorsBeforeExport,
|
||||||
pipelineProposal = "minimal",
|
pipelineProposal = "minimal",
|
||||||
recordAndTupleSyntax: recordAndTupleSyntax = "hash",
|
recordAndTupleSyntax: recordAndTupleSyntax = "hash",
|
||||||
|
moduleAttributesVersion = "may-2020",
|
||||||
} = opts;
|
} = opts;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -20,6 +21,10 @@ export default (_: any, opts: Object = {}) => {
|
|||||||
],
|
],
|
||||||
],
|
],
|
||||||
plugins: [
|
plugins: [
|
||||||
|
[
|
||||||
|
babelPlugins.syntaxModuleAttributes,
|
||||||
|
{ version: moduleAttributesVersion },
|
||||||
|
],
|
||||||
[babelPlugins.syntaxRecordAndTuple, { syntaxType: recordAndTupleSyntax }],
|
[babelPlugins.syntaxRecordAndTuple, { syntaxType: recordAndTupleSyntax }],
|
||||||
babelPlugins.proposalExportDefaultFrom,
|
babelPlugins.proposalExportDefaultFrom,
|
||||||
[babelPlugins.proposalPipelineOperator, { proposal: pipelineProposal }],
|
[babelPlugins.proposalPipelineOperator, { proposal: pipelineProposal }],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user