Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assertions to ExportNamedDeclaration without from #13957

Merged
merged 4 commits into from Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 8 additions & 6 deletions packages/babel-parser/src/parser/statement.js
Expand Up @@ -1883,6 +1883,9 @@ export default class StatementParser extends ExpressionParser {

node.source = null;
node.declaration = null;
if (this.hasPlugin("importAssertions")) {
node.assertions = [];
}

return true;
}
Expand All @@ -1893,6 +1896,9 @@ export default class StatementParser extends ExpressionParser {
if (this.shouldParseExportDeclaration()) {
node.specifiers = [];
node.source = null;
if (this.hasPlugin("importAssertions")) {
node.assertions = [];
}
node.declaration = this.parseExportDeclaration(node);
return true;
}
Expand Down Expand Up @@ -2005,12 +2011,8 @@ export default class StatementParser extends ExpressionParser {
if (assertions) {
node.assertions = assertions;
}
} else {
if (expect) {
this.unexpected();
} else {
node.source = null;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, node.source = null is called in maybeParseExportNamedSpecifiers and maybeParseExportDeclaration. So we can remove this from here.

}
} else if (expect) {
this.unexpected();
}

this.semicolon();
Expand Down
Expand Up @@ -56,7 +56,8 @@
}
],
"source": null,
"declaration": null
"declaration": null,
"assertions": []
},
{
"type": "ExpressionStatement",
Expand Down
@@ -0,0 +1 @@
export class Foo {}
@@ -0,0 +1,35 @@
{
"type": "File",
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
"program": {
"type": "Program",
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExportNamedDeclaration",
"start":0,"end":19,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":19}},
"specifiers": [],
"source": null,
"declaration": {
"type": "ClassDeclaration",
"start":7,"end":19,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":19}},
"id": {
"type": "Identifier",
"start":13,"end":16,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":16},"identifierName":"Foo"},
"name": "Foo"
},
"superClass": null,
"body": {
"type": "ClassBody",
"start":17,"end":19,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":19}},
"body": []
}
},
"assertions": []
}
],
"directives": []
}
}
@@ -0,0 +1 @@
export function foo() {}
@@ -0,0 +1,38 @@
{
"type": "File",
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}},
"program": {
"type": "Program",
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExportNamedDeclaration",
"start":0,"end":24,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":24}},
"specifiers": [],
"source": null,
"declaration": {
"type": "FunctionDeclaration",
"start":7,"end":24,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":24}},
"id": {
"type": "Identifier",
"start":16,"end":19,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":19},"identifierName":"foo"},
"name": "foo"
},
"generator": false,
"async": false,
"params": [],
"body": {
"type": "BlockStatement",
"start":22,"end":24,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":24}},
"body": [],
"directives": []
}
},
"assertions": []
}
],
"directives": []
}
}
@@ -0,0 +1 @@
export const foo = "";
@@ -0,0 +1,45 @@
{
"type": "File",
"start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}},
"program": {
"type": "Program",
"start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "ExportNamedDeclaration",
"start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}},
"specifiers": [],
"source": null,
"declaration": {
"type": "VariableDeclaration",
"start":7,"end":22,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":22}},
"declarations": [
{
"type": "VariableDeclarator",
"start":13,"end":21,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":21}},
"id": {
"type": "Identifier",
"start":13,"end":16,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":16},"identifierName":"foo"},
"name": "foo"
},
"init": {
"type": "StringLiteral",
"start":19,"end":21,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":21}},
"extra": {
"rawValue": "",
"raw": "\"\""
},
"value": ""
}
}
],
"kind": "const"
},
"assertions": []
}
],
"directives": []
}
}
@@ -0,0 +1,3 @@
const foo = "";

export { foo };
@@ -0,0 +1,61 @@
{
"type": "File",
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":15}},
"program": {
"type": "Program",
"start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":15}},
"sourceType": "module",
"interpreter": null,
"body": [
{
"type": "VariableDeclaration",
"start":0,"end":15,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":15}},
"declarations": [
{
"type": "VariableDeclarator",
"start":6,"end":14,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":14}},
"id": {
"type": "Identifier",
"start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"foo"},
"name": "foo"
},
"init": {
"type": "StringLiteral",
"start":12,"end":14,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":14}},
"extra": {
"rawValue": "",
"raw": "\"\""
},
"value": ""
}
}
],
"kind": "const"
},
{
"type": "ExportNamedDeclaration",
"start":17,"end":32,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":15}},
"specifiers": [
{
"type": "ExportSpecifier",
"start":26,"end":29,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":12}},
"local": {
"type": "Identifier",
"start":26,"end":29,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":12},"identifierName":"foo"},
"name": "foo"
},
"exported": {
"type": "Identifier",
"start":26,"end":29,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":12},"identifierName":"foo"},
"name": "foo"
}
}
],
"source": null,
"declaration": null,
"assertions": []
}
],
"directives": []
}
}