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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build(deps): Bump @babel/parser from 7.12.3 to 7.12.5 #9597

Merged
merged 15 commits into from Nov 6, 2020
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
8 changes: 2 additions & 6 deletions changelog_unreleased/javascript/pr-9408.md
@@ -1,4 +1,4 @@
#### Update to `@babel/parser` 7.12 (#9408, #9476 by @sosukesuzuki)
#### Update to `@babel/parser` 7.12 (#9408, #9476, #9597 by @sosukesuzuki)

Updated the JavaScript parser to [`@babel/parser` 7.12](https://babeljs.io/blog/2020/10/15/7.12.0). This fixes several bugs and supports some new syntax.

Expand All @@ -7,15 +7,11 @@ Updated the JavaScript parser to [`@babel/parser` 7.12](https://babeljs.io/blog/
[The "module attributes" proposal supported on 2.1](https://prettier.io/blog/2020/08/24/2.1.0.html#support-es-module-attributes-and-json-modules-8436httpsgithubcomprettierprettierpull8436-by-fiskerhttpsgithubcomfisker) has been significantly changed and also renamed to "import assertions".

```js
import json from "./foo.json" assert { type: "json" };
import foo from "./foo.json" assert { type: "json" };
```

##### Support imports and exports with string names

<!-- TODO: Remove if the bug is fixed -->

Due to a [bug in `@babel/parser`](https://github.com/babel/babel/issues/12209), Prettier can only use exports, but that will be fixed.

```js
let happy = "happy";
export { happy as "馃槂" };
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@angular/compiler": "10.2.2",
"@babel/code-frame": "7.10.4",
"@babel/parser": "7.12.3",
"@babel/parser": "7.12.5",
"@glimmer/syntax": "0.62.4",
"@iarna/toml": "2.2.5",
"@typescript-eslint/typescript-estree": "3.10.1",
Expand Down
15 changes: 15 additions & 0 deletions src/language-js/print/module.js
Expand Up @@ -94,7 +94,22 @@ function printModuleSpecifiers(path, options, print) {
return concat(parts);
}

function printImportAssertions(path, options, print) {
fisker marked this conversation as resolved.
Show resolved Hide resolved
const node = path.getNode();
if (Array.isArray(node.assertions) && node.assertions.length !== 0) {
return concat([
" assert {",
options.bracketSpacing ? " " : "",
join(", ", path.map(print, "assertions")),
options.bracketSpacing ? " " : "",
"}",
]);
}
return "";
}
fisker marked this conversation as resolved.
Show resolved Hide resolved

module.exports = {
printModuleSource,
printModuleSpecifiers,
printImportAssertions,
};
21 changes: 12 additions & 9 deletions src/language-js/printer-estree.js
Expand Up @@ -117,7 +117,11 @@ const {
printMemberLookup,
printBindExpressionCallee,
} = require("./print/misc");
const { printModuleSource, printModuleSpecifiers } = require("./print/module");
const {
printModuleSource,
printModuleSpecifiers,
printImportAssertions,
} = require("./print/module");
const printTernaryOperator = require("./print/ternary");
const {
printFunctionParameters,
Expand Down Expand Up @@ -844,7 +848,11 @@ function printPathNoParens(path, options, print, args) {
parts.push(" as ", path.call(print, "exported"));
}

parts.push(printModuleSource(path, options, print), semi);
parts.push(
printModuleSource(path, options, print),
printImportAssertions(path, options, print),
semi
);

return concat(parts);

Expand Down Expand Up @@ -874,13 +882,7 @@ function printPathNoParens(path, options, print, args) {
parts.push(" ", path.call(print, "source"));
}

if (Array.isArray(n.assertions) && n.assertions.length !== 0) {
parts.push(
" assert { ",
join(", ", path.map(print, "assertions")),
" }"
);
}
parts.push(printImportAssertions(path, options, print));

parts.push(semi);

Expand Down Expand Up @@ -4003,6 +4005,7 @@ function printExportDeclaration(path, options, print) {
parts.push(decl.exportKind === "type" ? "type " : "");
parts.push(printModuleSpecifiers(path, options, print));
parts.push(printModuleSource(path, options, print));
parts.push(printImportAssertions(path, options, print));
parts.push(semi);
}

Expand Down
20 changes: 12 additions & 8 deletions tests/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -1052,17 +1052,19 @@ obj.a.b &&= c;
`;

exports[`module-string-names.js [espree] format 1`] = `
"Unexpected token \\"馃槃\\" (1:19)
> 1 | export { smile as \\"馃槃\\" } from \\"./emojis.js\\";
| ^
2 | "
"Unexpected token \\"馃槃\\" (1:10)
> 1 | import { \\"馃槃\\" as smile } from \\"./emojis.js\\";
| ^
2 | export { smile as \\"馃槃\\" } from \\"./emojis.js\\";
3 | "
`;

exports[`module-string-names.js [meriyah] format 1`] = `
"[1:22]: Only a identifier can be used to indicate alias (1:22)
> 1 | export { smile as \\"馃槃\\" } from \\"./emojis.js\\";
| ^
2 | "
"[1:13]: Expected '}' (1:13)
> 1 | import { \\"馃槃\\" as smile } from \\"./emojis.js\\";
| ^
2 | export { smile as \\"馃槃\\" } from \\"./emojis.js\\";
3 | "
`;

exports[`module-string-names.js format 1`] = `
Expand All @@ -1071,9 +1073,11 @@ parsers: ["babel", "babel-ts", "babel-flow"]
printWidth: 80
| printWidth
=====================================input======================================
import { "馃槃" as smile } from "./emojis.js";
export { smile as "馃槃" } from "./emojis.js";

=====================================output=====================================
import { "馃槃" as smile } from "./emojis.js";
export { smile as "馃槃" } from "./emojis.js";

================================================================================
Expand Down
1 change: 1 addition & 0 deletions tests/js/babel-plugins/module-string-names.js
@@ -1 +1,2 @@
import { "馃槃" as smile } from "./emojis.js";
export { smile as "馃槃" } from "./emojis.js";
21 changes: 21 additions & 0 deletions tests/js/binary-expressions/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -740,6 +740,27 @@ printWidth: 80
================================================================================
`;

exports[`like-regexp.js [espree] format 1`] = `
"Unterminated regular expression (1:19)
> 1 | 0 ? a : { b : 1 }/2;
| ^
2 | "
`;

exports[`like-regexp.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
0 ? a : { b : 1 }/2;

=====================================output=====================================
0 ? a : { b: 1 } / 2;

================================================================================
`;

exports[`math.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
Expand Down
4 changes: 3 additions & 1 deletion tests/js/binary-expressions/jsfmt.spec.js
@@ -1 +1,3 @@
run_spec(__dirname, ["babel", "flow", "typescript"]);
run_spec(__dirname, ["babel", "flow", "typescript"], {
errors: { espree: ["like-regexp.js"] },
Copy link
Member

Choose a reason for hiding this comment

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

Reported to acron repo acornjs/acorn#991

});
1 change: 1 addition & 0 deletions tests/js/binary-expressions/like-regexp.js
@@ -0,0 +1 @@
0 ? a : { b : 1 }/2;
137 changes: 123 additions & 14 deletions tests/js/import-assertions/__snapshots__/jsfmt.spec.js.snap
@@ -1,20 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`import-assertions-dynamic.js [espree] format 1`] = `
exports[`dynamic-import.js [espree] format 1`] = `
"Unexpected token , (1:20)
> 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } });
| ^
2 | "
`;

exports[`import-assertions-dynamic.js [meriyah] format 1`] = `
exports[`dynamic-import.js [meriyah] format 1`] = `
"[1:20]: Expected ')' (1:20)
> 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } });
| ^
2 | "
`;

exports[`import-assertions-dynamic.js format 1`] = `
exports[`dynamic-import.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
Expand All @@ -28,21 +28,66 @@ import("./foo.json", { assert: { type: "json" } });
================================================================================
`;

exports[`import-assertions-multi-types.js [espree] format 1`] = `
exports[`empty.js [espree] format 1`] = `
"Unexpected token assert (2:33)
1 | export * as foo from \\"foo.json\\"
> 2 | export * as bar from \\"bar.json\\" assert { }
| ^
3 | export * as baz from \\"baz.json\\" assert { /* comment */ }
4 |
5 | import * as foo from \\"foo.json\\""
`;

exports[`empty.js [meriyah] format 1`] = `
"[2:38]: Unexpected token: 'identifier' (2:38)
1 | export * as foo from \\"foo.json\\"
> 2 | export * as bar from \\"bar.json\\" assert { }
| ^
3 | export * as baz from \\"baz.json\\" assert { /* comment */ }
4 |
5 | import * as foo from \\"foo.json\\""
`;

exports[`empty.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
export * as foo from "foo.json"
export * as bar from "bar.json" assert { }
export * as baz from "baz.json" assert { /* comment */ }

import * as foo from "foo.json"
import * as bar from "bar.json" assert { }
import * as baz from "baz.json" assert { /* comment */ }
=====================================output=====================================
export * as foo from "foo.json";
export * as bar from "bar.json";
export * as baz from "baz.json" /* comment */;

import * as foo from "foo.json";
import * as bar from "bar.json";
import * as baz from "baz.json" /* comment */;

================================================================================
`;

exports[`multi-types.js [espree] format 1`] = `
"Unexpected token assert (1:31)
> 1 | import json from \\"./foo.json\\" assert { type: \\"json\\", type: \\"bar\\" };
| ^
2 | "
`;

exports[`import-assertions-multi-types.js [meriyah] format 1`] = `
exports[`multi-types.js [meriyah] format 1`] = `
"[1:36]: Unexpected token: 'identifier' (1:36)
> 1 | import json from \\"./foo.json\\" assert { type: \\"json\\", type: \\"bar\\" };
| ^
2 | "
`;

exports[`import-assertions-multi-types.js format 1`] = `
exports[`multi-types.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
Expand All @@ -56,21 +101,73 @@ import json from "./foo.json" assert { type: "json", type: "bar" };
================================================================================
`;

exports[`import-assertions-static.js [espree] format 1`] = `
exports[`not-import-assertions.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
import "x"
assert ({type: 'json'});

=====================================output=====================================
import "x";
assert({ type: "json" });

================================================================================
`;

exports[`re-export.js [espree] format 1`] = `
"Unexpected token assert (1:33)
> 1 | export { foo2 } from \\"foo.json\\" assert { type: \\"json\\" };
| ^
2 | export * from \\"foo.json\\" assert { type: \\"json\\" };
3 | export * as foo3 from \\"foo.json\\" assert { type: \\"json\\" };
4 | "
`;

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

exports[`re-export.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
export { foo2 } from "foo.json" assert { type: "json" };
export * from "foo.json" assert { type: "json" };
export * as foo3 from "foo.json" assert { type: "json" };

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

================================================================================
`;

exports[`static-import.js [espree] format 1`] = `
"Unexpected token assert (1:31)
> 1 | import json from \\"./foo.json\\" assert { type: \\"json\\" };
| ^
2 | "
`;

exports[`import-assertions-static.js [meriyah] format 1`] = `
exports[`static-import.js [meriyah] format 1`] = `
"[1:36]: Unexpected token: 'identifier' (1:36)
> 1 | import json from \\"./foo.json\\" assert { type: \\"json\\" };
| ^
2 | "
`;

exports[`import-assertions-static.js format 1`] = `
exports[`static-import.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
Expand All @@ -84,18 +181,30 @@ import json from "./foo.json" assert { type: "json" };
================================================================================
`;

exports[`not-import-assertions.js format 1`] = `
exports[`without-from.js [espree] format 1`] = `
"Unexpected token assert (1:14)
> 1 | import \\"foo\\" assert { type: \\"json\\" }
| ^
2 | "
`;

exports[`without-from.js [meriyah] format 1`] = `
"[1:19]: Unexpected token: 'identifier' (1:19)
> 1 | import \\"foo\\" assert { type: \\"json\\" }
| ^
2 | "
`;

exports[`without-from.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
import "x"
assert ({type: 'json'});
import "foo" assert { type: "json" }

=====================================output=====================================
import "x";
assert({ type: "json" });
import "foo" assert { type: "json" };

================================================================================
`;