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

Disallows specifiers after export * as ns #15385

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * as foo, { bar } from "foo";
export * as default from "foo";

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * as foo, { bar } from "foo";
export * as default from "foo";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ExportSpecifier4 is removed, then I renamed ExportSpecifier16 into ExportSpecifier4 to fill the hole.

9 changes: 5 additions & 4 deletions packages/babel-parser/src/parser/statement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2305,13 +2305,14 @@ export default abstract class StatementParser extends ExpressionParser {
node,
);

if (
(hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) ||
(hasNamespace && parseAfterNamespace && !hasSpecifiers)
) {
if (hasDefault && parseAfterDefault && !hasStar && !hasSpecifiers) {
throw this.unexpected(null, tt.braceL);
}

if (hasNamespace && parseAfterNamespace) {
throw this.unexpected(null, tt._from);
}

let hasDeclaration;
if (isFromRequired || hasSpecifiers) {
hasDeclaration = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected \"from\" (1:25)"
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"throws": "Unexpected token, expected \"{\" (1:16)"
"throws": "Unexpected token, expected \"from\" (1:16)"
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import { "foo" as bar, "default" as qux } from "module-a";
export * as "foo", { default as "quux" } from "module-b";
export * as "foo" from "module-b";
export { default as "quux" } from "module-b";
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "File",
"start":0,"end":116,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":57,"index":116}},
"start":0,"end":139,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":45,"index":139}},
"program": {
"type": "Program",
"start":0,"end":116,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":57,"index":116}},
"start":0,"end":139,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":45,"index":139}},
"sourceType": "module",
"interpreter": null,
"body": [
Expand Down Expand Up @@ -60,7 +60,7 @@
},
{
"type": "ExportNamedDeclaration",
"start":59,"end":116,"loc":{"start":{"line":2,"column":0,"index":59},"end":{"line":2,"column":57,"index":116}},
"start":59,"end":93,"loc":{"start":{"line":2,"column":0,"index":59},"end":{"line":2,"column":34,"index":93}},
"specifiers": [
{
"type": "ExportNamespaceSpecifier",
Expand All @@ -74,18 +74,33 @@
},
"value": "foo"
}
}
],
"source": {
"type": "StringLiteral",
"start":82,"end":92,"loc":{"start":{"line":2,"column":23,"index":82},"end":{"line":2,"column":33,"index":92}},
"extra": {
"rawValue": "module-b",
"raw": "\"module-b\""
},
"value": "module-b"
}
},
{
"type": "ExportNamedDeclaration",
"start":94,"end":139,"loc":{"start":{"line":3,"column":0,"index":94},"end":{"line":3,"column":45,"index":139}},
"specifiers": [
{
"type": "ExportSpecifier",
"start":80,"end":97,"loc":{"start":{"line":2,"column":21,"index":80},"end":{"line":2,"column":38,"index":97}},
"start":103,"end":120,"loc":{"start":{"line":3,"column":9,"index":103},"end":{"line":3,"column":26,"index":120}},
"local": {
"type": "Identifier",
"start":80,"end":87,"loc":{"start":{"line":2,"column":21,"index":80},"end":{"line":2,"column":28,"index":87},"identifierName":"default"},
"start":103,"end":110,"loc":{"start":{"line":3,"column":9,"index":103},"end":{"line":3,"column":16,"index":110},"identifierName":"default"},
"name": "default"
},
"exported": {
"type": "StringLiteral",
"start":91,"end":97,"loc":{"start":{"line":2,"column":32,"index":91},"end":{"line":2,"column":38,"index":97}},
"start":114,"end":120,"loc":{"start":{"line":3,"column":20,"index":114},"end":{"line":3,"column":26,"index":120}},
"extra": {
"rawValue": "quux",
"raw": "\"quux\""
Expand All @@ -96,7 +111,7 @@
],
"source": {
"type": "StringLiteral",
"start":105,"end":115,"loc":{"start":{"line":2,"column":46,"index":105},"end":{"line":2,"column":56,"index":115}},
"start":128,"end":138,"loc":{"start":{"line":3,"column":34,"index":128},"end":{"line":3,"column":44,"index":138}},
"extra": {
"rawValue": "module-b",
"raw": "\"module-b\""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import { "foo" as bar, "default" as qux } from "module-a";
export * as "foo", { default as "quux" } from "module-b";
export * as "foo" from "module-b";
export { default as "quux" } from "module-b";
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "File",
"start":0,"end":116,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":57}},
"start":0,"end":139,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":45}},
"program": {
"type": "Program",
"start":0,"end":116,"loc":{"start":{"line":1,"column":0},"end":{"line":2,"column":57}},
"start":0,"end":139,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":45}},
"sourceType": "module",
"interpreter": null,
"body": [
Expand Down Expand Up @@ -52,39 +52,46 @@
"raw": "\"module-a\""
}
},
{
"type": "ExportAllDeclaration",
"start":59,"end":93,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":34}},
"source": {
"type": "Literal",
"start":82,"end":92,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":33}},
"value": "module-b",
"raw": "\"module-b\""
},
"exported": {
"type": "Literal",
"start":71,"end":76,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":17}},
"value": "foo",
"raw": "\"foo\""
},
"exportKind": "value"
},
{
"type": "ExportNamedDeclaration",
"start":59,"end":116,"loc":{"start":{"line":2,"column":0},"end":{"line":2,"column":57}},
"start":94,"end":139,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":45}},
"specifiers": [
{
"type": "ExportNamespaceSpecifier",
"start":66,"end":76,"loc":{"start":{"line":2,"column":7},"end":{"line":2,"column":17}},
"exported": {
"type": "Literal",
"start":71,"end":76,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":17}},
"value": "foo",
"raw": "\"foo\""
}
},
{
"type": "ExportSpecifier",
"start":80,"end":97,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":38}},
"start":103,"end":120,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":26}},
"local": {
"type": "Identifier",
"start":80,"end":87,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":28},"identifierName":"default"},
"start":103,"end":110,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":16},"identifierName":"default"},
"name": "default"
},
"exported": {
"type": "Literal",
"start":91,"end":97,"loc":{"start":{"line":2,"column":32},"end":{"line":2,"column":38}},
"start":114,"end":120,"loc":{"start":{"line":3,"column":20},"end":{"line":3,"column":26}},
"value": "quux",
"raw": "\"quux\""
}
}
],
"source": {
"type": "Literal",
"start":105,"end":115,"loc":{"start":{"line":2,"column":46},"end":{"line":2,"column":56}},
"start":128,"end":138,"loc":{"start":{"line":3,"column":34},"end":{"line":3,"column":44}},
"value": "module-b",
"raw": "\"module-b\""
},
Expand All @@ -93,4 +100,4 @@
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import { "foo" as bar, "default" as qux } from "module-a";
export * as "foo", { default as "quux" } from "module-b";
export * as "foo" from "module-b";
export { default as "quux" } from "module-b";
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"type": "File",
"start":0,"end":116,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":57,"index":116}},
"start":0,"end":139,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":45,"index":139}},
"program": {
"type": "Program",
"start":0,"end":116,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":2,"column":57,"index":116}},
"start":0,"end":139,"loc":{"start":{"line":1,"column":0,"index":0},"end":{"line":3,"column":45,"index":139}},
"sourceType": "module",
"interpreter": null,
"body": [
Expand Down Expand Up @@ -63,7 +63,7 @@
},
{
"type": "ExportNamedDeclaration",
"start":59,"end":116,"loc":{"start":{"line":2,"column":0,"index":59},"end":{"line":2,"column":57,"index":116}},
"start":59,"end":93,"loc":{"start":{"line":2,"column":0,"index":59},"end":{"line":2,"column":34,"index":93}},
"specifiers": [
{
"type": "ExportNamespaceSpecifier",
Expand All @@ -77,18 +77,34 @@
},
"value": "foo"
}
}
],
"source": {
"type": "StringLiteral",
"start":82,"end":92,"loc":{"start":{"line":2,"column":23,"index":82},"end":{"line":2,"column":33,"index":92}},
"extra": {
"rawValue": "module-b",
"raw": "\"module-b\""
},
"value": "module-b"
},
"exportKind": "value"
},
{
"type": "ExportNamedDeclaration",
"start":94,"end":139,"loc":{"start":{"line":3,"column":0,"index":94},"end":{"line":3,"column":45,"index":139}},
"specifiers": [
{
"type": "ExportSpecifier",
"start":80,"end":97,"loc":{"start":{"line":2,"column":21,"index":80},"end":{"line":2,"column":38,"index":97}},
"start":103,"end":120,"loc":{"start":{"line":3,"column":9,"index":103},"end":{"line":3,"column":26,"index":120}},
"local": {
"type": "Identifier",
"start":80,"end":87,"loc":{"start":{"line":2,"column":21,"index":80},"end":{"line":2,"column":28,"index":87},"identifierName":"default"},
"start":103,"end":110,"loc":{"start":{"line":3,"column":9,"index":103},"end":{"line":3,"column":16,"index":110},"identifierName":"default"},
"name": "default"
},
"exported": {
"type": "StringLiteral",
"start":91,"end":97,"loc":{"start":{"line":2,"column":32,"index":91},"end":{"line":2,"column":38,"index":97}},
"start":114,"end":120,"loc":{"start":{"line":3,"column":20,"index":114},"end":{"line":3,"column":26,"index":120}},
"extra": {
"rawValue": "quux",
"raw": "\"quux\""
Expand All @@ -99,7 +115,7 @@
],
"source": {
"type": "StringLiteral",
"start":105,"end":115,"loc":{"start":{"line":2,"column":46,"index":105},"end":{"line":2,"column":56,"index":115}},
"start":128,"end":138,"loc":{"start":{"line":3,"column":34,"index":128},"end":{"line":3,"column":44,"index":138}},
"extra": {
"rawValue": "module-b",
"raw": "\"module-b\""
Expand Down

This file was deleted.

This file was deleted.

4 changes: 4 additions & 0 deletions scripts/integration-tests/e2e-prettier.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ yarn lint:typecheck
# https://github.com/babel/babel/pull/14892#issuecomment-1233180626
echo "export default () => () => {}" > src/main/create-print-pre-check-function.js

# https://github.com/babel/babel/pull/15385#issuecomment-1409840781
# Ignore this test until prettier update the snapshot
rm tests/format/js/exports/jsfmt.spec.js
JLHwung marked this conversation as resolved.
Show resolved Hide resolved

yarn test "tests/format/(jsx?|misc|typescript|flow|flow-repo)/" --update-snapshot --runInBand

cleanup