Parse import-assertions (#12139)

Co-authored-by: Huáng Jùnliàng <jlhwung@gmail.com>
Co-authored-by: Nicolò Ribaudo <nicolo.ribaudo@gmail.com>
This commit is contained in:
Sven Sauleau
2020-10-14 20:18:16 +01:00
committed by GitHub
parent 59d97d9bca
commit af8e0facc1
71 changed files with 1199 additions and 112 deletions

View File

@@ -1,5 +1,5 @@
{
"throws": "This experimental syntax requires enabling the parser plugin: 'moduleAttributes' (1:24)",
"throws": "This experimental syntax requires enabling the parser plugin: 'importAssertions' (1:24)",
"sourceType": "module",
"plugins": []
}

View File

@@ -0,0 +1 @@
import foo from "foo.json" assert { type: "json" };

View File

@@ -0,0 +1,5 @@
{
"throws": "This experimental syntax requires enabling the parser plugin: 'importAssertions' (1:27)",
"sourceType": "module",
"plugins": []
}

View File

@@ -1,5 +1,3 @@
{
"throws": "This experimental syntax requires enabling the parser plugin: 'moduleAttributes' (1:27)",
"sourceType": "module",
"plugins": []
}
"throws": "This experimental syntax requires enabling the parser plugin: 'moduleAttributes' (1:27)"
}

View File

@@ -0,0 +1 @@
import("foo.json", { assert: { type: "json" } })

View File

@@ -0,0 +1,81 @@
{
"type": "File",
"start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":48}},
"program": {
"type": "Program",
"start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":48}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExpressionStatement",
"start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":48}},
"expression": {
"type": "CallExpression",
"start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":48}},
"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":47,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":47}},
"properties": [
{
"type": "ObjectProperty",
"start":21,"end":45,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":45}},
"method": false,
"key": {
"type": "Identifier",
"start":21,"end":27,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":27},"identifierName":"assert"},
"name": "assert"
},
"computed": false,
"shorthand": false,
"value": {
"type": "ObjectExpression",
"start":29,"end":45,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":45}},
"properties": [
{
"type": "ObjectProperty",
"start":31,"end":43,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":43}},
"method": false,
"key": {
"type": "Identifier",
"start":31,"end":35,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":35},"identifierName":"type"},
"name": "type"
},
"computed": false,
"shorthand": false,
"value": {
"type": "StringLiteral",
"start":37,"end":43,"loc":{"start":{"line":1,"column":37},"end":{"line":1,"column":43}},
"extra": {
"rawValue": "json",
"raw": "\"json\""
},
"value": "json"
}
}
]
}
}
]
}
]
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1,2 @@
import "x"
assert ({});

View File

@@ -0,0 +1,48 @@
{
"type": "File",
"start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":12}},
"program": {
"type": "Program",
"start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":12}},
"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": "StringLiteral",
"start":7,"end":10,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":10}},
"extra": {
"rawValue": "x",
"raw": "\"x\""
},
"value": "x"
},
"assertions": []
},
{
"type": "ExpressionStatement",
"start":11,"end":23,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":12}},
"expression": {
"type": "CallExpression",
"start":11,"end":22,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":11}},
"callee": {
"type": "Identifier",
"start":11,"end":17,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":6},"identifierName":"assert"},
"name": "assert"
},
"arguments": [
{
"type": "ObjectExpression",
"start":19,"end":21,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":10}},
"properties": []
}
]
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1,2 @@
import();
import("./foo.json", { assert: { type: "json"} }, "unsupported");

View File

@@ -0,0 +1,107 @@
{
"type": "File",
"start":0,"end":75,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":65}},
"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":75,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":65}},
"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":75,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":65}},
"expression": {
"type": "CallExpression",
"start":10,"end":74,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":64}},
"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":58,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":48}},
"properties": [
{
"type": "ObjectProperty",
"start":33,"end":56,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":46}},
"method": false,
"key": {
"type": "Identifier",
"start":33,"end":39,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":29},"identifierName":"assert"},
"name": "assert"
},
"computed": false,
"shorthand": false,
"value": {
"type": "ObjectExpression",
"start":41,"end":56,"loc":{"start":{"line":2,"column":31},"end":{"line":2,"column":46}},
"properties": [
{
"type": "ObjectProperty",
"start":43,"end":55,"loc":{"start":{"line":2,"column":33},"end":{"line":2,"column":45}},
"method": false,
"key": {
"type": "Identifier",
"start":43,"end":47,"loc":{"start":{"line":2,"column":33},"end":{"line":2,"column":37},"identifierName":"type"},
"name": "type"
},
"computed": false,
"shorthand": false,
"value": {
"type": "StringLiteral",
"start":49,"end":55,"loc":{"start":{"line":2,"column":39},"end":{"line":2,"column":45}},
"extra": {
"rawValue": "json",
"raw": "\"json\""
},
"value": "json"
}
}
]
}
}
]
},
{
"type": "StringLiteral",
"start":60,"end":73,"loc":{"start":{"line":2,"column":50},"end":{"line":2,"column":63}},
"extra": {
"rawValue": "unsupported",
"raw": "\"unsupported\""
},
"value": "unsupported"
}
]
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1 @@
import("./foo.json", ...[]);

View File

@@ -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": []
}
}

View File

@@ -0,0 +1,2 @@
import "x" assert
{ type: "json" }

View File

@@ -0,0 +1,47 @@
{
"type": "File",
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":16}},
"program": {
"type": "Program",
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":16}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ImportDeclaration",
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":16}},
"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"
},
"assertions": [
{
"type": "ImportAttribute",
"start":20,"end":32,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":14}},
"key": {
"type": "Identifier",
"start":20,"end":24,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":6},"identifierName":"type"},
"name": "type"
},
"value": {
"type": "StringLiteral",
"start":26,"end":32,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":14}},
"extra": {
"rawValue": "json",
"raw": "\"json\""
},
"value": "json"
}
}
]
}
],
"directives": []
}
}

View File

@@ -0,0 +1,9 @@
{
"plugins": [
[
"importAssertions"
]
],
"sourceType": "module",
"throws": "Unexpected token (1:17)"
}

View File

@@ -0,0 +1,8 @@
{
"plugins": [
[
"importAssertions"
]
],
"sourceType": "module"
}

View File

@@ -0,0 +1 @@
import foo from "foo.json" assert { for: "for" }

View File

@@ -0,0 +1,60 @@
{
"type": "File",
"start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":48}},
"errors": [
"SyntaxError: The only accepted module attribute is `type` (1:36)"
],
"program": {
"type": "Program",
"start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":48}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ImportDeclaration",
"start":0,"end":48,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":48}},
"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"
},
"assertions": [
{
"type": "ImportAttribute",
"start":36,"end":46,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":46}},
"key": {
"type": "Identifier",
"start":36,"end":39,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":39},"identifierName":"for"},
"name": "for"
},
"value": {
"type": "StringLiteral",
"start":41,"end":46,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":46}},
"extra": {
"rawValue": "for",
"raw": "\"for\""
},
"value": "for"
}
}
]
}
],
"directives": []
}
}

View File

@@ -0,0 +1,2 @@
import("foo.js",);
import("foo.json", { assert: { type: "json" } },);

View File

@@ -0,0 +1,110 @@
{
"type": "File",
"start":0,"end":69,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":50}},
"program": {
"type": "Program",
"start":0,"end":69,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":50}},
"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":69,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":50}},
"expression": {
"type": "CallExpression",
"start":19,"end":68,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":49}},
"callee": {
"type": "Import",
"start":19,"end":25,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":6}}
},
"extra": {
"trailingComma": 66
},
"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":66,"loc":{"start":{"line":2,"column":19},"end":{"line":2,"column":47}},
"properties": [
{
"type": "ObjectProperty",
"start":40,"end":64,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":45}},
"method": false,
"key": {
"type": "Identifier",
"start":40,"end":46,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":27},"identifierName":"assert"},
"name": "assert"
},
"computed": false,
"shorthand": false,
"value": {
"type": "ObjectExpression",
"start":48,"end":64,"loc":{"start":{"line":2,"column":29},"end":{"line":2,"column":45}},
"properties": [
{
"type": "ObjectProperty",
"start":50,"end":62,"loc":{"start":{"line":2,"column":31},"end":{"line":2,"column":43}},
"method": false,
"key": {
"type": "Identifier",
"start":50,"end":54,"loc":{"start":{"line":2,"column":31},"end":{"line":2,"column":35},"identifierName":"type"},
"name": "type"
},
"computed": false,
"shorthand": false,
"value": {
"type": "StringLiteral",
"start":56,"end":62,"loc":{"start":{"line":2,"column":37},"end":{"line":2,"column":43}},
"extra": {
"rawValue": "json",
"raw": "\"json\""
},
"value": "json"
}
}
]
}
}
]
}
]
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1 @@
import foo from "foo" assert { type: "json", }

View File

@@ -0,0 +1,57 @@
{
"type": "File",
"start":0,"end":46,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":46}},
"program": {
"type": "Program",
"start":0,"end":46,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":46}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ImportDeclaration",
"start":0,"end":46,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":46}},
"specifiers": [
{
"type": "ImportDefaultSpecifier",
"start":7,"end":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":21,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":21}},
"extra": {
"rawValue": "foo",
"raw": "\"foo\""
},
"value": "foo"
},
"assertions": [
{
"type": "ImportAttribute",
"start":31,"end":43,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":43}},
"key": {
"type": "Identifier",
"start":31,"end":35,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":35},"identifierName":"type"},
"name": "type"
},
"value": {
"type": "StringLiteral",
"start":37,"end":43,"loc":{"start":{"line":1,"column":37},"end":{"line":1,"column":43}},
"extra": {
"rawValue": "json",
"raw": "\"json\""
},
"value": "json"
}
}
]
}
],
"directives": []
}
}

View File

@@ -0,0 +1,2 @@
import "x" assert { type: "json" }
[0]

View File

@@ -0,0 +1,66 @@
{
"type": "File",
"start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":3}},
"program": {
"type": "Program",
"start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":3}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ImportDeclaration",
"start":0,"end":34,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":34}},
"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"
},
"assertions": [
{
"type": "ImportAttribute",
"start":20,"end":32,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":32}},
"key": {
"type": "Identifier",
"start":20,"end":24,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":24},"identifierName":"type"},
"name": "type"
},
"value": {
"type": "StringLiteral",
"start":26,"end":32,"loc":{"start":{"line":1,"column":26},"end":{"line":1,"column":32}},
"extra": {
"rawValue": "json",
"raw": "\"json\""
},
"value": "json"
}
}
]
},
{
"type": "ExpressionStatement",
"start":35,"end":38,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":3}},
"expression": {
"type": "ArrayExpression",
"start":35,"end":38,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":3}},
"elements": [
{
"type": "NumericLiteral",
"start":36,"end":37,"loc":{"start":{"line":2,"column":1},"end":{"line":2,"column":2}},
"extra": {
"rawValue": 0,
"raw": "0"
},
"value": 0
}
]
}
}
],
"directives": []
}
}

View File

@@ -0,0 +1 @@
import foo from "foo.json" assert { type: "json" };

View File

@@ -0,0 +1,57 @@
{
"type": "File",
"start":0,"end":51,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":51}},
"program": {
"type": "Program",
"start":0,"end":51,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":51}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ImportDeclaration",
"start":0,"end":51,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":51}},
"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"
},
"assertions": [
{
"type": "ImportAttribute",
"start":36,"end":48,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":48}},
"key": {
"type": "Identifier",
"start":36,"end":40,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":40},"identifierName":"type"},
"name": "type"
},
"value": {
"type": "StringLiteral",
"start":42,"end":48,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":48}},
"extra": {
"rawValue": "json",
"raw": "\"json\""
},
"value": "json"
}
}
]
}
],
"directives": []
}
}

View File

@@ -0,0 +1 @@
import foo from "foo.json" assert { type: "json", lazy: true, startAtLine: 1 };

View File

@@ -0,0 +1,9 @@
{
"plugins": [
[
"importAssertions"
]
],
"sourceType": "module",
"throws": "Only string literals are allowed as module attribute values (1:56)"
}

View File

@@ -0,0 +1 @@
import foo from "foo.json" assert { lazy: "true" };

View File

@@ -0,0 +1,60 @@
{
"type": "File",
"start":0,"end":51,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":51}},
"errors": [
"SyntaxError: The only accepted module attribute is `type` (1:36)"
],
"program": {
"type": "Program",
"start":0,"end":51,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":51}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ImportDeclaration",
"start":0,"end":51,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":51}},
"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"
},
"assertions": [
{
"type": "ImportAttribute",
"start":36,"end":48,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":48}},
"key": {
"type": "Identifier",
"start":36,"end":40,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":40},"identifierName":"lazy"},
"name": "lazy"
},
"value": {
"type": "StringLiteral",
"start":42,"end":48,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":48}},
"extra": {
"rawValue": "true",
"raw": "\"true\""
},
"value": "true"
}
}
]
}
],
"directives": []
}
}

View File

@@ -0,0 +1 @@
import foo from "foo.json" assert { type: "json", hasOwnProperty: "true" };

View File

@@ -0,0 +1,78 @@
{
"type": "File",
"start":0,"end":75,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":75}},
"errors": [
"SyntaxError: The only accepted module attribute is `type` (1:50)"
],
"program": {
"type": "Program",
"start":0,"end":75,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":75}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ImportDeclaration",
"start":0,"end":75,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":75}},
"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"
},
"assertions": [
{
"type": "ImportAttribute",
"start":36,"end":48,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":48}},
"key": {
"type": "Identifier",
"start":36,"end":40,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":40},"identifierName":"type"},
"name": "type"
},
"value": {
"type": "StringLiteral",
"start":42,"end":48,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":48}},
"extra": {
"rawValue": "json",
"raw": "\"json\""
},
"value": "json"
}
},
{
"type": "ImportAttribute",
"start":50,"end":72,"loc":{"start":{"line":1,"column":50},"end":{"line":1,"column":72}},
"key": {
"type": "Identifier",
"start":50,"end":64,"loc":{"start":{"line":1,"column":50},"end":{"line":1,"column":64},"identifierName":"hasOwnProperty"},
"name": "hasOwnProperty"
},
"value": {
"type": "StringLiteral",
"start":66,"end":72,"loc":{"start":{"line":1,"column":66},"end":{"line":1,"column":72}},
"extra": {
"rawValue": "true",
"raw": "\"true\""
},
"value": "true"
}
}
]
}
],
"directives": []
}
}

View File

@@ -0,0 +1 @@
import foo from "foo.json" assert { type: "json", type: "html" };

View File

@@ -0,0 +1,78 @@
{
"type": "File",
"start":0,"end":65,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":65}},
"errors": [
"SyntaxError: Duplicate key \"type\" is not allowed in module attributes (1:50)"
],
"program": {
"type": "Program",
"start":0,"end":65,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":65}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ImportDeclaration",
"start":0,"end":65,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":65}},
"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"
},
"assertions": [
{
"type": "ImportAttribute",
"start":36,"end":48,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":48}},
"key": {
"type": "Identifier",
"start":36,"end":40,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":40},"identifierName":"type"},
"name": "type"
},
"value": {
"type": "StringLiteral",
"start":42,"end":48,"loc":{"start":{"line":1,"column":42},"end":{"line":1,"column":48}},
"extra": {
"rawValue": "json",
"raw": "\"json\""
},
"value": "json"
}
},
{
"type": "ImportAttribute",
"start":50,"end":62,"loc":{"start":{"line":1,"column":50},"end":{"line":1,"column":62}},
"key": {
"type": "Identifier",
"start":50,"end":54,"loc":{"start":{"line":1,"column":50},"end":{"line":1,"column":54},"identifierName":"type"},
"name": "type"
},
"value": {
"type": "StringLiteral",
"start":56,"end":62,"loc":{"start":{"line":1,"column":56},"end":{"line":1,"column":62}},
"extra": {
"rawValue": "html",
"raw": "\"html\""
},
"value": "html"
}
}
]
}
],
"directives": []
}
}

View File

@@ -0,0 +1 @@
import foo from "foo.json";

View File

@@ -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"
},
"assertions": []
}
],
"directives": []
}
}

View File

@@ -0,0 +1 @@
import foo from "foo.json" assert { type: "json" };

View File

@@ -0,0 +1,4 @@
{
"throws": "This experimental syntax requires enabling the parser plugin: 'importAssertions' (1:27)",
"plugins": []
}