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

Update babel/parser to v7.12.17 #10345

Merged
merged 22 commits into from Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from 21 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
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@angular/compiler": "11.2.1",
"@babel/code-frame": "7.12.13",
"@babel/parser": "7.12.11",
"@babel/parser": "7.12.17",
"@glimmer/syntax": "0.77.1",
"@iarna/toml": "2.2.5",
"@typescript-eslint/typescript-estree": "4.15.1",
Expand Down
2 changes: 2 additions & 0 deletions src/language-js/parser-babel.js
Expand Up @@ -172,6 +172,8 @@ const messagesShouldThrow = new Set([
"Invalid Unicode escape",
// ErrorMessages.MissingUnicodeEscape
"Expecting Unicode escape sequence \\uXXXX",
// ErrorMessages.MissingSemicolon
"Missing semicolon",
]);

function shouldRethrowRecoveredError(error) {
Expand Down
9 changes: 9 additions & 0 deletions src/language-js/print/class.js
Expand Up @@ -160,6 +160,15 @@ function printClassMethod(path, options, print) {
if (n.accessibility) {
parts.push(n.accessibility + " ");
}
// "readonly" and "declare" are supported by only "babel-ts"
// https://github.com/prettier/prettier/issues/9760
if (n.readonly) {
parts.push("readonly ");
}
if (n.declare) {
parts.push("declare ");
}

if (n.static) {
parts.push("static ");
}
Expand Down
4 changes: 4 additions & 0 deletions src/language-js/print/typescript.js
Expand Up @@ -358,6 +358,10 @@ function printTypescript(path, options, print) {
n.export ? "export " : "",
n.static ? "static " : "",
n.readonly ? "readonly " : "",
// "abstract" and "declare" are supported by only "babel-ts"
// https://github.com/prettier/prettier/issues/9760
n.abstract ? "abstract " : "",
n.declare ? "declare " : "",
n.computed ? "[" : "",
path.call(print, "key"),
n.computed ? "]" : "",
Expand Down
85 changes: 85 additions & 0 deletions tests/flow/await/__snapshots__/jsfmt.spec.js.snap
@@ -0,0 +1,85 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`await-keywords.js format 1`] = `
====================================options=====================================
parsers: ["flow"]
printWidth: 80
| printWidth
=====================================input======================================
export class C1 {
p = await (0);
}

await (0);

async function foo() {
function bar(x = await (2)) {}
}

async (x = await (2)) => {};

export class C2 {
p = await 0;
}

function foo(promise) { await (promise); }

function a() {
return await (1)
}

() => { await (x) };

function foo() {
await
(foo);
}

export class C {
p = await (0);
}

await (0);

=====================================output=====================================
export class C1 {
p = await(0);
}

await(0);

async function foo() {
function bar(x = await(2)) {}
}

async (x = await(2)) => {};

export class C2 {
p = await;
0;
}

function foo(promise) {
await(promise);
}

function a() {
return await(1);
}

() => {
await(x);
};

function foo() {
await(foo);
}

export class C {
p = await(0);
}

await(0);

================================================================================
`;
34 changes: 34 additions & 0 deletions tests/flow/await/await-keywords.js
@@ -0,0 +1,34 @@
export class C1 {
p = await (0);
}

await (0);

async function foo() {
function bar(x = await (2)) {}
}

async (x = await (2)) => {};

export class C2 {
p = await 0;
}

function foo(promise) { await (promise); }

function a() {
return await (1)
}

() => { await (x) };

function foo() {
await
(foo);
}

export class C {
p = await (0);
}

await (0);
1 change: 1 addition & 0 deletions tests/flow/await/jsfmt.spec.js
@@ -0,0 +1 @@
run_spec(__dirname, ["flow"]);
17 changes: 17 additions & 0 deletions tests/flow/declare-function/__snapshots__/jsfmt.spec.js.snap
@@ -0,0 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`export.js format 1`] = `
====================================options=====================================
parsers: ["flow", "babel"]
printWidth: 80
| printWidth
=====================================input======================================
declare function foo(): void;
export { foo };

=====================================output=====================================
declare function foo(): void;
export { foo };

================================================================================
`;
2 changes: 2 additions & 0 deletions tests/flow/declare-function/export.js
@@ -0,0 +1,2 @@
declare function foo(): void;
export { foo };
1 change: 1 addition & 0 deletions tests/flow/declare-function/jsfmt.spec.js
@@ -0,0 +1 @@
run_spec(__dirname, ["flow", "babel"]);
64 changes: 64 additions & 0 deletions tests/js/async/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -51,6 +51,70 @@ printWidth: 80
================================================================================
`;

exports[`await-keyword.js [espree] format 1`] = `
"Cannot use keyword 'await' outside an async function (2:20)
1 | async function foo() {
> 2 | function bar(x = await 2) {}
| ^
3 | }
4 |
5 | async (x = await 2) => {};"
`;

exports[`await-keyword.js [flow] format 1`] = `
"Unexpected number, expected the token \`,\` (2:26)
1 | async function foo() {
> 2 | function bar(x = await 2) {}
| ^
3 | }
4 |
5 | async (x = await 2) => {};"
`;

exports[`await-keyword.js [meriyah] format 1`] = `
"[2:24]: 'Await' may not be used as an identifier in this context (2:24)
1 | async function foo() {
> 2 | function bar(x = await 2) {}
| ^
3 | }
4 |
5 | async (x = await 2) => {};"
`;

exports[`await-keyword.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
printWidth: 80
| printWidth
=====================================input======================================
async function foo() {
function bar(x = await 2) {}
}

async (x = await 2) => {};

async function foo() {
function bar(x = await (2)) {}
}

async (x = await (2)) => {};

=====================================output=====================================
async function foo() {
function bar(x = await 2) {}
}

async (x = await 2) => {};

async function foo() {
function bar(x = await(2)) {}
}

async (x = await 2) => {};

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

exports[`await-parse.js format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
Expand Down
11 changes: 11 additions & 0 deletions tests/js/async/await-keyword.js
@@ -0,0 +1,11 @@
async function foo() {
function bar(x = await 2) {}
}

async (x = await 2) => {};
Copy link
Sponsor Member

@fisker fisker Feb 21, 2021

Choose a reason for hiding this comment

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

Can you also test this? (Note that flow parse this differently.)

Prettier pr-10345
Playground link

--parser babel

Input:

async function foo() {
  function bar(x = await (2)) {}
}

async (x = await (2)) => {};

Output:

async function foo() {
  function bar(x = await(2)) {}
}

async (x = await 2) => {};


async function foo() {
function bar(x = await (2)) {}
}

async (x = await (2)) => {};
8 changes: 7 additions & 1 deletion tests/js/async/jsfmt.spec.js
@@ -1 +1,7 @@
run_spec(__dirname, ["babel", "flow", "typescript"]);
run_spec(__dirname, ["babel", "flow", "typescript"], {
errors: {
flow: ["await-keyword.js"],
espree: ["await-keyword.js"],
meriyah: ["await-keyword.js"],
},
});
70 changes: 70 additions & 0 deletions tests/js/await-with-parens/__snapshots__/jsfmt.spec.js.snap
@@ -0,0 +1,70 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`await-with-parens.js [espree] format 1`] = `
"Cannot use keyword 'await' outside an async function (1:25)
> 1 | function foo(promise) { await (promise); }
| ^
2 |
3 | function a() {
4 | return await (1)"
`;

exports[`await-with-parens.js [meriyah] format 1`] = `
"[1:29]: 'Await' may not be used as an identifier in this context (1:29)
> 1 | function foo(promise) { await (promise); }
| ^
2 |
3 | function a() {
4 | return await (1)"
`;

exports[`await-with-parens.js format 1`] = `
====================================options=====================================
parsers: ["babel"]
printWidth: 80
| printWidth
=====================================input======================================
function foo(promise) { await (promise); }

function a() {
return await (1)
}

() => { await (x) };

function foo() {
await
(foo);
}

export class C {
p = await (0);
}

await (0);

=====================================output=====================================
function foo(promise) {
await(promise);
}

function a() {
return await(1);
}

() => {
await(x);
};

function foo() {
await(foo);
}

export class C {
p = await 0;
}

await 0;

================================================================================
`;
18 changes: 18 additions & 0 deletions tests/js/await-with-parens/await-with-parens.js
@@ -0,0 +1,18 @@
function foo(promise) { await (promise); }

function a() {
return await (1)
}

() => { await (x) };

function foo() {
await
(foo);
}

export class C {
p = await (0);
}

await (0);
6 changes: 6 additions & 0 deletions tests/js/await-with-parens/jsfmt.spec.js
@@ -0,0 +1,6 @@
run_spec(__dirname, ["babel"], {
errors: {
espree: true,
meriyah: true,
},
});