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

fix: JSON modules disable named exports #13035

Merged
merged 1 commit into from Jun 22, 2022
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
Expand Up @@ -69,23 +69,23 @@ export * as bar from "bar.json";
`;

exports[`re-export.js - {"bracketSpacing":false} [acorn] format 1`] = `
"Unexpected token (1:33)
> 1 | export { foo2 } from "foo.json" assert { type: "json" };
| ^
"Unexpected token (1:44)
> 1 | export { default as foo2 } from "foo.json" assert { type: "json" };
| ^
2 |"
`;

exports[`re-export.js - {"bracketSpacing":false} [espree] format 1`] = `
"Unexpected token assert (1:33)
> 1 | export { foo2 } from "foo.json" assert { type: "json" };
| ^
"Unexpected token assert (1:44)
> 1 | export { default as foo2 } from "foo.json" assert { type: "json" };
| ^
2 |"
`;

exports[`re-export.js - {"bracketSpacing":false} [meriyah] format 1`] = `
"Unexpected token: 'identifier' (1:38)
> 1 | export { foo2 } from "foo.json" assert { type: "json" };
| ^
"Unexpected token: 'identifier' (1:49)
> 1 | export { default as foo2 } from "foo.json" assert { type: "json" };
| ^
2 |"
`;

Expand All @@ -96,10 +96,10 @@ parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
export { foo2 } from "foo.json" assert { type: "json" };
export { default as foo2 } from "foo.json" assert { type: "json" };

=====================================output=====================================
export {foo2} from "foo.json" assert {type: "json"};
export {default as foo2} from "foo.json" assert {type: "json"};

================================================================================
`;
Expand Down
@@ -1 +1 @@
export { foo2 } from "foo.json" assert { type: "json" };
export { default as foo2 } from "foo.json" assert { type: "json" };
6 changes: 3 additions & 3 deletions tests/format/misc/errors/js/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -12,9 +12,9 @@ exports[`html-like-comments.js [babel] format 1`] = `
`;

exports[`import-assertions-for-export-without-from.js [babel] format 1`] = `
"Missing semicolon. (1:15)
> 1 | export { foo } assert { type: "json" };
| ^
"Missing semicolon. (1:26)
> 1 | export { default as foo } assert { type: "json" };
| ^
2 |"
`;

Expand Down
@@ -1 +1 @@
export { foo } assert { type: "json" };
export { default as foo } assert { type: "json" };
Copy link
Member

Choose a reason for hiding this comment

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

Can you revert this one? So we can have one test for named export.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could preserve this test as-is, but for the same reason mentioned in #13035, this test will block babel/babel#14668 because that PR proposes to align Babel's behaviour with Node.js and the spec. To recap, in that PR Babel will forbid export { foo } from a JSON module, so the test will be passing (incorrectly) on older Babel versions and throwing (expectedly) on latest versions.

I suggest we add export { foo } and other tests after babel/babel#14668 is landed.

BTW technically, export { default as foo } is still a named export.

Copy link
Member

Choose a reason for hiding this comment

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

Okay, thanks for the explanation.