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 1 commit
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
3 changes: 3 additions & 0 deletions packages/babel-parser/src/parser/statement.js
Expand Up @@ -1824,6 +1824,9 @@ export default class StatementParser extends ExpressionParser {

if (isFromRequired || hasSpecifiers || hasDeclaration) {
this.checkExport(node, true, false, !!node.source);
if (this.hasPlugin("importAssertions") && node.assertions == null) {
node.assertions = [];
}
sosukesuzuki marked this conversation as resolved.
Show resolved Hide resolved
return this.finishNode(node, "ExportNamedDeclaration");
}

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