Skip to content

Commit 87fc2e7

Browse files
authored
Add assertions to ExportNamedDeclaration without from (#13957)
1 parent 966387d commit 87fc2e7

File tree

10 files changed

+195
-7
lines changed

10 files changed

+195
-7
lines changed

packages/babel-parser/src/parser/statement.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,9 @@ export default class StatementParser extends ExpressionParser {
18931893

18941894
node.source = null;
18951895
node.declaration = null;
1896+
if (this.hasPlugin("importAssertions")) {
1897+
node.assertions = [];
1898+
}
18961899

18971900
return true;
18981901
}
@@ -1903,6 +1906,9 @@ export default class StatementParser extends ExpressionParser {
19031906
if (this.shouldParseExportDeclaration()) {
19041907
node.specifiers = [];
19051908
node.source = null;
1909+
if (this.hasPlugin("importAssertions")) {
1910+
node.assertions = [];
1911+
}
19061912
node.declaration = this.parseExportDeclaration(node);
19071913
return true;
19081914
}
@@ -2015,12 +2021,8 @@ export default class StatementParser extends ExpressionParser {
20152021
if (assertions) {
20162022
node.assertions = assertions;
20172023
}
2018-
} else {
2019-
if (expect) {
2020-
this.unexpected();
2021-
} else {
2022-
node.source = null;
2023-
}
2024+
} else if (expect) {
2025+
this.unexpected();
20242026
}
20252027

20262028
this.semicolon();

packages/babel-parser/test/fixtures/experimental/import-assertions/invalid-export-without-from/output.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656
}
5757
],
5858
"source": null,
59-
"declaration": null
59+
"declaration": null,
60+
"assertions": []
6061
},
6162
{
6263
"type": "ExpressionStatement",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export class Foo {}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"type": "File",
3+
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
4+
"program": {
5+
"type": "Program",
6+
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
7+
"sourceType": "module",
8+
"interpreter": null,
9+
"body": [
10+
{
11+
"type": "ExportNamedDeclaration",
12+
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
13+
"specifiers": [],
14+
"source": null,
15+
"declaration": {
16+
"type": "ClassDeclaration",
17+
"start":7,"end":19,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":19}},
18+
"id": {
19+
"type": "Identifier",
20+
"start":13,"end":16,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":16},"identifierName":"Foo"},
21+
"name": "Foo"
22+
},
23+
"superClass": null,
24+
"body": {
25+
"type": "ClassBody",
26+
"start":17,"end":19,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":19}},
27+
"body": []
28+
}
29+
},
30+
"assertions": []
31+
}
32+
],
33+
"directives": []
34+
}
35+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export function foo() {}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"type": "File",
3+
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}},
4+
"program": {
5+
"type": "Program",
6+
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}},
7+
"sourceType": "module",
8+
"interpreter": null,
9+
"body": [
10+
{
11+
"type": "ExportNamedDeclaration",
12+
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}},
13+
"specifiers": [],
14+
"source": null,
15+
"declaration": {
16+
"type": "FunctionDeclaration",
17+
"start":7,"end":24,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":24}},
18+
"id": {
19+
"type": "Identifier",
20+
"start":16,"end":19,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":19},"identifierName":"foo"},
21+
"name": "foo"
22+
},
23+
"generator": false,
24+
"async": false,
25+
"params": [],
26+
"body": {
27+
"type": "BlockStatement",
28+
"start":22,"end":24,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":24}},
29+
"body": [],
30+
"directives": []
31+
}
32+
},
33+
"assertions": []
34+
}
35+
],
36+
"directives": []
37+
}
38+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const foo = "";
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"type": "File",
3+
"start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}},
4+
"program": {
5+
"type": "Program",
6+
"start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}},
7+
"sourceType": "module",
8+
"interpreter": null,
9+
"body": [
10+
{
11+
"type": "ExportNamedDeclaration",
12+
"start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}},
13+
"specifiers": [],
14+
"source": null,
15+
"declaration": {
16+
"type": "VariableDeclaration",
17+
"start":7,"end":22,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":22}},
18+
"declarations": [
19+
{
20+
"type": "VariableDeclarator",
21+
"start":13,"end":21,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":21}},
22+
"id": {
23+
"type": "Identifier",
24+
"start":13,"end":16,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":16},"identifierName":"foo"},
25+
"name": "foo"
26+
},
27+
"init": {
28+
"type": "StringLiteral",
29+
"start":19,"end":21,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":21}},
30+
"extra": {
31+
"rawValue": "",
32+
"raw": "\"\""
33+
},
34+
"value": ""
35+
}
36+
}
37+
],
38+
"kind": "const"
39+
},
40+
"assertions": []
41+
}
42+
],
43+
"directives": []
44+
}
45+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const foo = "";
2+
3+
export { foo };
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"type": "File",
3+
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":15}},
4+
"program": {
5+
"type": "Program",
6+
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":15}},
7+
"sourceType": "module",
8+
"interpreter": null,
9+
"body": [
10+
{
11+
"type": "VariableDeclaration",
12+
"start":0,"end":15,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":15}},
13+
"declarations": [
14+
{
15+
"type": "VariableDeclarator",
16+
"start":6,"end":14,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":14}},
17+
"id": {
18+
"type": "Identifier",
19+
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"foo"},
20+
"name": "foo"
21+
},
22+
"init": {
23+
"type": "StringLiteral",
24+
"start":12,"end":14,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":14}},
25+
"extra": {
26+
"rawValue": "",
27+
"raw": "\"\""
28+
},
29+
"value": ""
30+
}
31+
}
32+
],
33+
"kind": "const"
34+
},
35+
{
36+
"type": "ExportNamedDeclaration",
37+
"start":17,"end":32,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":15}},
38+
"specifiers": [
39+
{
40+
"type": "ExportSpecifier",
41+
"start":26,"end":29,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":12}},
42+
"local": {
43+
"type": "Identifier",
44+
"start":26,"end":29,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":12},"identifierName":"foo"},
45+
"name": "foo"
46+
},
47+
"exported": {
48+
"type": "Identifier",
49+
"start":26,"end":29,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":12},"identifierName":"foo"},
50+
"name": "foo"
51+
}
52+
}
53+
],
54+
"source": null,
55+
"declaration": null,
56+
"assertions": []
57+
}
58+
],
59+
"directives": []
60+
}
61+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy