From feacf82892900b89b12ac0c10989f2f56a4193d3 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Thu, 25 Feb 2021 19:28:06 +0900 Subject: [PATCH] Update babel/parser to `v7.12.17` (#10345) --- package.json | 2 +- src/language-js/clean.js | 6 - src/language-js/parser-babel.js | 2 + src/language-js/print/class.js | 9 ++ src/language-js/print/typescript.js | 4 + .../await/__snapshots__/jsfmt.spec.js.snap | 85 +++++++++++++ tests/flow/await/await-keywords.js | 34 +++++ tests/flow/await/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 17 +++ tests/flow/declare-function/export.js | 2 + tests/flow/declare-function/jsfmt.spec.js | 1 + .../js/async/__snapshots__/jsfmt.spec.js.snap | 64 ++++++++++ tests/js/async/await-keyword.js | 11 ++ tests/js/async/jsfmt.spec.js | 8 +- .../__snapshots__/jsfmt.spec.js.snap | 70 +++++++++++ .../js/await-with-parens/await-with-parens.js | 18 +++ tests/js/await-with-parens/jsfmt.spec.js | 6 + .../js/await/__snapshots__/jsfmt.spec.js.snap | 119 ++++++++++++++++++ tests/js/await/in-sync-function.js | 12 ++ tests/js/await/jsfmt.spec.js | 3 + tests/js/await/out-of-function.js | 5 + .../__snapshots__/jsfmt.spec.js.snap | 70 +++++++++++ tests/js/class-static-block/await.js | 9 ++ .../jsx/jsx/__snapshots__/jsfmt.spec.js.snap | 64 ++++++++++ tests/jsx/jsx/ternary.js | 1 + .../babel-ts/__snapshots__/jsfmt.spec.js.snap | 41 ++++++ tests/misc/errors/babel-ts/export-declare.ts | 1 + .../multiline-declaration-abstract-class.ts | 2 + .../multiline-declaration-interface.ts | 3 + .../babel-ts/multiline-declaration-module.ts | 3 + .../babel-ts/multiline-declaration-type.ts | 2 + .../js/__snapshots__/jsfmt.spec.js.snap | 8 +- .../__snapshots__/jsfmt.spec.js.snap | 7 ++ .../misc/errors/typescript/export-declare.ts | 1 + .../__snapshots__/jsfmt.spec.js.snap | 42 +++++++ .../invalid-modifiers.ts | 15 +++ .../__snapshots__/jsfmt.spec.js.snap | 94 ++++++++++++++ .../misc/typescript-only/await-with-parens.ts | 18 +++ .../misc/typescript-only/invalid-modifiers.ts | 15 +++ tests/misc/typescript-only/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 17 +++ .../abstract-class/export-default.ts | 1 + tests/typescript/abstract-class/jsfmt.spec.js | 1 + .../class/__snapshots__/jsfmt.spec.js.snap | 64 +++++++++- tests/typescript/class/abstract-method.ts | 11 ++ .../class/duplicates-access-modifier.ts | 7 ++ .../compiler/__snapshots__/jsfmt.spec.js.snap | 10 +- tests/typescript/compiler/jsfmt.spec.js | 1 - .../__snapshots__/jsfmt.spec.js.snap | 8 +- .../__snapshots__/jsfmt.spec.js.snap | 7 -- .../types/abstractKeyword/jsfmt.spec.js | 2 +- .../enum/__snapshots__/jsfmt.spec.js.snap | 16 +++ tests/typescript/enum/multiline.ts | 3 + .../__snapshots__/jsfmt.spec.js.snap | 18 --- tests/typescript/interface/jsfmt.spec.js | 5 +- .../keywords/__snapshots__/jsfmt.spec.js.snap | 71 ++++++++--- tests/typescript/keywords/jsfmt.spec.js | 2 +- tests/typescript/keywords/keywords-2.ts | 3 - tests/typescript/keywords/module.ts | 12 ++ .../__snapshots__/jsfmt.spec.js.snap | 19 +++ tests/typescript/namespace/invalid-await.ts | 3 + tests/typescript/namespace/jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 15 +++ tests/typescript/optional-call/jsfmt.spec.js | 1 + .../optional-call/type-parameters.ts | 1 + tests_config/run_spec.js | 11 +- .../__snapshots__/syntax-error.js.snap | 2 +- .../__tests__/__snapshots__/write.js.snap | 4 +- yarn.lock | 9 +- 69 files changed, 1117 insertions(+), 84 deletions(-) create mode 100644 tests/flow/await/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/flow/await/await-keywords.js create mode 100644 tests/flow/await/jsfmt.spec.js create mode 100644 tests/flow/declare-function/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/flow/declare-function/export.js create mode 100644 tests/flow/declare-function/jsfmt.spec.js create mode 100644 tests/js/async/await-keyword.js create mode 100644 tests/js/await-with-parens/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/js/await-with-parens/await-with-parens.js create mode 100644 tests/js/await-with-parens/jsfmt.spec.js create mode 100644 tests/js/await/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/js/await/in-sync-function.js create mode 100644 tests/js/await/jsfmt.spec.js create mode 100644 tests/js/await/out-of-function.js create mode 100644 tests/js/class-static-block/await.js create mode 100644 tests/jsx/jsx/ternary.js create mode 100644 tests/misc/errors/babel-ts/export-declare.ts create mode 100644 tests/misc/errors/babel-ts/multiline-declaration-abstract-class.ts create mode 100644 tests/misc/errors/babel-ts/multiline-declaration-interface.ts create mode 100644 tests/misc/errors/babel-ts/multiline-declaration-module.ts create mode 100644 tests/misc/errors/babel-ts/multiline-declaration-type.ts create mode 100644 tests/misc/errors/typescript/export-declare.ts create mode 100644 tests/misc/typescript-babel-only/invalid-modifiers.ts create mode 100644 tests/misc/typescript-only/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/misc/typescript-only/await-with-parens.ts create mode 100644 tests/misc/typescript-only/invalid-modifiers.ts create mode 100644 tests/misc/typescript-only/jsfmt.spec.js create mode 100644 tests/typescript/abstract-class/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/typescript/abstract-class/export-default.ts create mode 100644 tests/typescript/abstract-class/jsfmt.spec.js create mode 100644 tests/typescript/class/abstract-method.ts create mode 100644 tests/typescript/class/duplicates-access-modifier.ts create mode 100644 tests/typescript/enum/multiline.ts create mode 100644 tests/typescript/keywords/module.ts create mode 100644 tests/typescript/namespace/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/typescript/namespace/invalid-await.ts create mode 100644 tests/typescript/namespace/jsfmt.spec.js create mode 100644 tests/typescript/optional-call/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/typescript/optional-call/jsfmt.spec.js create mode 100644 tests/typescript/optional-call/type-parameters.ts diff --git a/package.json b/package.json index f56d086589cd..aba976076c0b 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/language-js/clean.js b/src/language-js/clean.js index 16d37dd37597..60be0872ff59 100644 --- a/src/language-js/clean.js +++ b/src/language-js/clean.js @@ -197,12 +197,6 @@ function clean(ast, newObj, parent) { if (ast.type === "InterpreterDirective") { newObj.value = newObj.value.trimEnd(); } - - // TODO: Remove this when fixing #9760 - if (ast.type === "ClassMethod") { - delete newObj.declare; - delete newObj.readonly; - } } clean.ignoredProperties = ignoredProperties; diff --git a/src/language-js/parser-babel.js b/src/language-js/parser-babel.js index d219ed48d3b7..d7a9ac32734b 100644 --- a/src/language-js/parser-babel.js +++ b/src/language-js/parser-babel.js @@ -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) { diff --git a/src/language-js/print/class.js b/src/language-js/print/class.js index b5a173c87986..f56a4c7491ce 100644 --- a/src/language-js/print/class.js +++ b/src/language-js/print/class.js @@ -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 "); } diff --git a/src/language-js/print/typescript.js b/src/language-js/print/typescript.js index b88e4e1a6094..4ba8833d21c6 100644 --- a/src/language-js/print/typescript.js +++ b/src/language-js/print/typescript.js @@ -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 ? "]" : "", diff --git a/tests/flow/await/__snapshots__/jsfmt.spec.js.snap b/tests/flow/await/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..7b5c5e513e8d --- /dev/null +++ b/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); + +================================================================================ +`; diff --git a/tests/flow/await/await-keywords.js b/tests/flow/await/await-keywords.js new file mode 100644 index 000000000000..7cf399e3bb1a --- /dev/null +++ b/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); diff --git a/tests/flow/await/jsfmt.spec.js b/tests/flow/await/jsfmt.spec.js new file mode 100644 index 000000000000..b9a908981a50 --- /dev/null +++ b/tests/flow/await/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["flow"]); diff --git a/tests/flow/declare-function/__snapshots__/jsfmt.spec.js.snap b/tests/flow/declare-function/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..da449cf2a1db --- /dev/null +++ b/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 }; + +================================================================================ +`; diff --git a/tests/flow/declare-function/export.js b/tests/flow/declare-function/export.js new file mode 100644 index 000000000000..05b292825827 --- /dev/null +++ b/tests/flow/declare-function/export.js @@ -0,0 +1,2 @@ +declare function foo(): void; +export { foo }; diff --git a/tests/flow/declare-function/jsfmt.spec.js b/tests/flow/declare-function/jsfmt.spec.js new file mode 100644 index 000000000000..fbfa6501a049 --- /dev/null +++ b/tests/flow/declare-function/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["flow", "babel"]); diff --git a/tests/js/async/__snapshots__/jsfmt.spec.js.snap b/tests/js/async/__snapshots__/jsfmt.spec.js.snap index ce5478bba06c..0686207677a1 100644 --- a/tests/js/async/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/async/__snapshots__/jsfmt.spec.js.snap @@ -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"] diff --git a/tests/js/async/await-keyword.js b/tests/js/async/await-keyword.js new file mode 100644 index 000000000000..a6c62e5dfea5 --- /dev/null +++ b/tests/js/async/await-keyword.js @@ -0,0 +1,11 @@ +async function foo() { + function bar(x = await 2) {} +} + +async (x = await 2) => {}; + +async function foo() { + function bar(x = await (2)) {} +} + +async (x = await (2)) => {}; diff --git a/tests/js/async/jsfmt.spec.js b/tests/js/async/jsfmt.spec.js index eb85eda6bd02..87d77473abab 100644 --- a/tests/js/async/jsfmt.spec.js +++ b/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"], + }, +}); diff --git a/tests/js/await-with-parens/__snapshots__/jsfmt.spec.js.snap b/tests/js/await-with-parens/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..77bb2b58b801 --- /dev/null +++ b/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; + +================================================================================ +`; diff --git a/tests/js/await-with-parens/await-with-parens.js b/tests/js/await-with-parens/await-with-parens.js new file mode 100644 index 000000000000..a13cfda425be --- /dev/null +++ b/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); diff --git a/tests/js/await-with-parens/jsfmt.spec.js b/tests/js/await-with-parens/jsfmt.spec.js new file mode 100644 index 000000000000..c57dff579d65 --- /dev/null +++ b/tests/js/await-with-parens/jsfmt.spec.js @@ -0,0 +1,6 @@ +run_spec(__dirname, ["babel"], { + errors: { + espree: true, + meriyah: true, + }, +}); diff --git a/tests/js/await/__snapshots__/jsfmt.spec.js.snap b/tests/js/await/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..1e145b8ce172 --- /dev/null +++ b/tests/js/await/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,119 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`in-sync-function.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[`in-sync-function.js [flow] format 1`] = ` +"Unexpected identifier, expected the end of an expression statement (\`;\`) (1:31) +> 1 | function foo(promise) { await promise; } + | ^^^^^^^ + 2 | + 3 | function a() { + 4 | return await 1" +`; + +exports[`in-sync-function.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[`in-sync-function.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +function foo(promise) { await promise; } + +function a() { + return await 1 +} + +() => { await x }; + +function foo() { + await + foo; +} + +=====================================output===================================== +function foo(promise) { + await promise; +} + +function a() { + return await 1; +} + +() => { + await x; +}; + +function foo() { + await; + foo; +} + +================================================================================ +`; + +exports[`out-of-function.js [espree] format 1`] = ` +"Unexpected token = (2:5) + 1 | export class C { +> 2 | p = await 0; + | ^ + 3 | } + 4 | + 5 | await 0;" +`; + +exports[`out-of-function.js [flow] format 1`] = ` +"Unexpected number, expected the end of an expression statement (\`;\`) (5:7) + 3 | } + 4 | +> 5 | await 0; + | ^ + 6 |" +`; + +exports[`out-of-function.js [meriyah] format 1`] = ` +"[2:11]: 'Await' may not be used as an identifier in this context (2:11) + 1 | export class C { +> 2 | p = await 0; + | ^ + 3 | } + 4 | + 5 | await 0;" +`; + +exports[`out-of-function.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +export class C { + p = await 0; +} + +await 0; + +=====================================output===================================== +export class C { + p = await 0; +} + +await 0; + +================================================================================ +`; diff --git a/tests/js/await/in-sync-function.js b/tests/js/await/in-sync-function.js new file mode 100644 index 000000000000..8bc6fd89f6c2 --- /dev/null +++ b/tests/js/await/in-sync-function.js @@ -0,0 +1,12 @@ +function foo(promise) { await promise; } + +function a() { + return await 1 +} + +() => { await x }; + +function foo() { + await + foo; +} diff --git a/tests/js/await/jsfmt.spec.js b/tests/js/await/jsfmt.spec.js new file mode 100644 index 000000000000..45e4c1230904 --- /dev/null +++ b/tests/js/await/jsfmt.spec.js @@ -0,0 +1,3 @@ +run_spec(__dirname, ["babel", "flow", "typescript"], { + errors: { espree: true, meriyah: true, flow: true }, +}); diff --git a/tests/js/await/out-of-function.js b/tests/js/await/out-of-function.js new file mode 100644 index 000000000000..5d75cff21e5f --- /dev/null +++ b/tests/js/await/out-of-function.js @@ -0,0 +1,5 @@ +export class C { + p = await 0; +} + +await 0; diff --git a/tests/js/class-static-block/__snapshots__/jsfmt.spec.js.snap b/tests/js/class-static-block/__snapshots__/jsfmt.spec.js.snap index 70b25ea882e7..bbad601be7cf 100644 --- a/tests/js/class-static-block/__snapshots__/jsfmt.spec.js.snap +++ b/tests/js/class-static-block/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,75 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`await.js [espree] format 1`] = ` +"Unexpected token { (3:20) + 1 | var C; + 2 | +> 3 | C = class { static { function f() { await } } }; + | ^ + 4 | + 5 | C = class { static { function f(await) {} } }; + 6 |" +`; + +exports[`await.js [meriyah] format 1`] = ` +"[3:20]: Unexpected token: '{' (3:20) + 1 | var C; + 2 | +> 3 | C = class { static { function f() { await } } }; + | ^ + 4 | + 5 | C = class { static { function f(await) {} } }; + 6 |" +`; + +exports[`await.js format 1`] = ` +====================================options===================================== +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +var C; + +C = class { static { function f() { await } } }; + +C = class { static { function f(await) {} } }; + +C = class { static { function f(x = await) {} } }; + +C = class { static { function f({ [await]: x }) {} } }; + +=====================================output===================================== +var C; + +C = class { + static { + function f() { + await; + } + } +}; + +C = class { + static { + function f(await) {} + } +}; + +C = class { + static { + function f(x = await) {} + } +}; + +C = class { + static { + function f({ [await]: x }) {} + } +}; + +================================================================================ +`; + exports[`class-static-block.js [espree] format 1`] = ` "Unexpected character '#' (2:10) 1 | class C { diff --git a/tests/js/class-static-block/await.js b/tests/js/class-static-block/await.js new file mode 100644 index 000000000000..d35f8544e20c --- /dev/null +++ b/tests/js/class-static-block/await.js @@ -0,0 +1,9 @@ +var C; + +C = class { static { function f() { await } } }; + +C = class { static { function f(await) {} } }; + +C = class { static { function f(x = await) {} } }; + +C = class { static { function f({ [await]: x }) {} } }; diff --git a/tests/jsx/jsx/__snapshots__/jsfmt.spec.js.snap b/tests/jsx/jsx/__snapshots__/jsfmt.spec.js.snap index aab7a9747d7c..ceb48f0d2c92 100644 --- a/tests/jsx/jsx/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx/jsx/__snapshots__/jsfmt.spec.js.snap @@ -5499,3 +5499,67 @@ singleQuote: true ================================================================================ `; + +exports[`ternary.js - {"singleQuote":false,"jsxSingleQuote":false} format 1`] = ` +====================================options===================================== +jsxSingleQuote: false +parsers: ["flow", "babel", "typescript"] +printWidth: 80 +singleQuote: false + | printWidth +=====================================input====================================== +a == 3 ? (a =

123

) : (a =

abc

); + +=====================================output===================================== +a == 3 ? (a =

123

) : (a =

abc

); + +================================================================================ +`; + +exports[`ternary.js - {"singleQuote":false,"jsxSingleQuote":true} format 1`] = ` +====================================options===================================== +jsxSingleQuote: true +parsers: ["flow", "babel", "typescript"] +printWidth: 80 +singleQuote: false + | printWidth +=====================================input====================================== +a == 3 ? (a =

123

) : (a =

abc

); + +=====================================output===================================== +a == 3 ? (a =

123

) : (a =

abc

); + +================================================================================ +`; + +exports[`ternary.js - {"singleQuote":true,"jsxSingleQuote":false} format 1`] = ` +====================================options===================================== +jsxSingleQuote: false +parsers: ["flow", "babel", "typescript"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +a == 3 ? (a =

123

) : (a =

abc

); + +=====================================output===================================== +a == 3 ? (a =

123

) : (a =

abc

); + +================================================================================ +`; + +exports[`ternary.js - {"singleQuote":true,"jsxSingleQuote":true} format 1`] = ` +====================================options===================================== +jsxSingleQuote: true +parsers: ["flow", "babel", "typescript"] +printWidth: 80 +singleQuote: true + | printWidth +=====================================input====================================== +a == 3 ? (a =

123

) : (a =

abc

); + +=====================================output===================================== +a == 3 ? (a =

123

) : (a =

abc

); + +================================================================================ +`; diff --git a/tests/jsx/jsx/ternary.js b/tests/jsx/jsx/ternary.js new file mode 100644 index 000000000000..26efc1e8743a --- /dev/null +++ b/tests/jsx/jsx/ternary.js @@ -0,0 +1 @@ +a == 3 ? (a =

123

) : (a =

abc

); diff --git a/tests/misc/errors/babel-ts/__snapshots__/jsfmt.spec.js.snap b/tests/misc/errors/babel-ts/__snapshots__/jsfmt.spec.js.snap index 1c74c1a0d1aa..d02d906ea1df 100644 --- a/tests/misc/errors/babel-ts/__snapshots__/jsfmt.spec.js.snap +++ b/tests/misc/errors/babel-ts/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,46 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`export-declare.ts [babel-ts] format 1`] = ` +"'export declare' must be followed by an ambient declaration. (1:16) +> 1 | export declare foo; + | ^ + 2 |" +`; + +exports[`multiline-declaration-abstract-class.ts [babel-ts] format 1`] = ` +"Missing semicolon (1:8) +> 1 | declare abstract + | ^ + 2 | class A {} + 3 |" +`; + +exports[`multiline-declaration-interface.ts [babel-ts] format 1`] = ` +"Missing semicolon (1:8) +> 1 | declare interface + | ^ + 2 | I + 3 | {} + 4 |" +`; + +exports[`multiline-declaration-module.ts [babel-ts] format 1`] = ` +"Missing semicolon (1:8) +> 1 | declare module + | ^ + 2 | 'bar' + 3 | {} + 4 |" +`; + +exports[`multiline-declaration-type.ts [babel-ts] format 1`] = ` +"Missing semicolon (1:8) +> 1 | declare type + | ^ + 2 | T = number + 3 |" +`; + exports[`type-annotation-expr-statement.ts [babel-ts] format 1`] = ` "Did not expect a type annotation here. (1:3) > 1 | (a: T); diff --git a/tests/misc/errors/babel-ts/export-declare.ts b/tests/misc/errors/babel-ts/export-declare.ts new file mode 100644 index 000000000000..a4cb16b163d0 --- /dev/null +++ b/tests/misc/errors/babel-ts/export-declare.ts @@ -0,0 +1 @@ +export declare foo; diff --git a/tests/misc/errors/babel-ts/multiline-declaration-abstract-class.ts b/tests/misc/errors/babel-ts/multiline-declaration-abstract-class.ts new file mode 100644 index 000000000000..8c6c81cfafcc --- /dev/null +++ b/tests/misc/errors/babel-ts/multiline-declaration-abstract-class.ts @@ -0,0 +1,2 @@ +declare abstract +class A {} diff --git a/tests/misc/errors/babel-ts/multiline-declaration-interface.ts b/tests/misc/errors/babel-ts/multiline-declaration-interface.ts new file mode 100644 index 000000000000..2a075540d6ae --- /dev/null +++ b/tests/misc/errors/babel-ts/multiline-declaration-interface.ts @@ -0,0 +1,3 @@ +declare interface +I +{} diff --git a/tests/misc/errors/babel-ts/multiline-declaration-module.ts b/tests/misc/errors/babel-ts/multiline-declaration-module.ts new file mode 100644 index 000000000000..2df14a257d75 --- /dev/null +++ b/tests/misc/errors/babel-ts/multiline-declaration-module.ts @@ -0,0 +1,3 @@ +declare module +'bar' +{} diff --git a/tests/misc/errors/babel-ts/multiline-declaration-type.ts b/tests/misc/errors/babel-ts/multiline-declaration-type.ts new file mode 100644 index 000000000000..d8433232652d --- /dev/null +++ b/tests/misc/errors/babel-ts/multiline-declaration-type.ts @@ -0,0 +1,2 @@ +declare type +T = number diff --git a/tests/misc/errors/js/__snapshots__/jsfmt.spec.js.snap b/tests/misc/errors/js/__snapshots__/jsfmt.spec.js.snap index 669cf5366be9..8a30eae86585 100644 --- a/tests/misc/errors/js/__snapshots__/jsfmt.spec.js.snap +++ b/tests/misc/errors/js/__snapshots__/jsfmt.spec.js.snap @@ -12,9 +12,9 @@ exports[`html-like-comments.js [babel] format 1`] = ` `; exports[`import-assertions-for-export-without-from.js [babel] format 1`] = ` -"Unexpected token, expected \\";\\" (1:16) +"Missing semicolon (1:15) > 1 | export { foo } assert { type: \\"json\\" }; - | ^ + | ^ 2 |" `; @@ -41,9 +41,9 @@ exports[`invalid-escape-in-identifier-2.js [babel] format 1`] = ` `; exports[`module-attributes.js [babel] format 1`] = ` -"Unexpected token, expected \\";\\" (1:28) +"Unexpected token, expected \\"(\\" (1:33) > 1 | import foo from \\"foo.json\\" with type: \\"json\\"; - | ^ + | ^ 2 |" `; diff --git a/tests/misc/errors/typescript/__snapshots__/jsfmt.spec.js.snap b/tests/misc/errors/typescript/__snapshots__/jsfmt.spec.js.snap index 8c9016456e77..fedade34c1ad 100644 --- a/tests/misc/errors/typescript/__snapshots__/jsfmt.spec.js.snap +++ b/tests/misc/errors/typescript/__snapshots__/jsfmt.spec.js.snap @@ -14,6 +14,13 @@ exports[`dynamic-import.ts [typescript] format 1`] = ` 2 |" `; +exports[`export-declare.ts [typescript] format 1`] = ` +"Declaration or statement expected. (1:1) +> 1 | export declare foo; + | ^ + 2 |" +`; + exports[`invalid-jsx-1.ts [typescript] format 1`] = ` "Unexpected token. Did you mean \`{'>'}\` or \`>\`? (3:45) 1 | // https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html#-and--are-now-invalid-jsx-text-characters diff --git a/tests/misc/errors/typescript/export-declare.ts b/tests/misc/errors/typescript/export-declare.ts new file mode 100644 index 000000000000..a4cb16b163d0 --- /dev/null +++ b/tests/misc/errors/typescript/export-declare.ts @@ -0,0 +1 @@ +export declare foo; diff --git a/tests/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap b/tests/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap index 2d7dba38a3f5..d5e87823f09b 100644 --- a/tests/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap +++ b/tests/misc/typescript-babel-only/__snapshots__/jsfmt.spec.js.snap @@ -20,6 +20,48 @@ class C { ================================================================================ `; +exports[`invalid-modifiers.ts format 1`] = ` +====================================options===================================== +parsers: ["babel-ts"] +printWidth: 80 + | printWidth +=====================================input====================================== +interface Foo { + private a(); + public b(); + protected c(); + static d(); + declare e(); + abstract f(); + readonly g(); +} + +class Bar { + declare e() {}; + abstract f() {}; + readonly g() {}; +} + +=====================================output===================================== +interface Foo { + private a(); + public b(); + protected c(); + static d(); + declare e(); + abstract f(); + readonly g(); +} + +class Bar { + declare e() {} + abstract f() {} + readonly g() {} +} + +================================================================================ +`; + exports[`tuple-labeled-ts.ts format 1`] = ` ====================================options===================================== parsers: ["babel-ts"] diff --git a/tests/misc/typescript-babel-only/invalid-modifiers.ts b/tests/misc/typescript-babel-only/invalid-modifiers.ts new file mode 100644 index 000000000000..440e6268d1e3 --- /dev/null +++ b/tests/misc/typescript-babel-only/invalid-modifiers.ts @@ -0,0 +1,15 @@ +interface Foo { + private a(); + public b(); + protected c(); + static d(); + declare e(); + abstract f(); + readonly g(); +} + +class Bar { + declare e() {}; + abstract f() {}; + readonly g() {}; +} diff --git a/tests/misc/typescript-only/__snapshots__/jsfmt.spec.js.snap b/tests/misc/typescript-only/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..fec9b017c3d6 --- /dev/null +++ b/tests/misc/typescript-only/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,94 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`await-with-parens.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +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; + +================================================================================ +`; + +exports[`invalid-modifiers.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +interface Foo { + private a(); + public b(); + protected c(); + static d(); + declare e(); + abstract f(); + readonly g(); +} + +class Bar { + declare e() {}; + abstract f() {}; + readonly g() {}; +} + +=====================================output===================================== +interface Foo { + private a(); + public b(); + protected c(); + static d(); + e(); + f(); + readonly g(); +} + +class Bar { + e() {} + abstract f() {} + g() {} +} + +================================================================================ +`; diff --git a/tests/misc/typescript-only/await-with-parens.ts b/tests/misc/typescript-only/await-with-parens.ts new file mode 100644 index 000000000000..a13cfda425be --- /dev/null +++ b/tests/misc/typescript-only/await-with-parens.ts @@ -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); diff --git a/tests/misc/typescript-only/invalid-modifiers.ts b/tests/misc/typescript-only/invalid-modifiers.ts new file mode 100644 index 000000000000..440e6268d1e3 --- /dev/null +++ b/tests/misc/typescript-only/invalid-modifiers.ts @@ -0,0 +1,15 @@ +interface Foo { + private a(); + public b(); + protected c(); + static d(); + declare e(); + abstract f(); + readonly g(); +} + +class Bar { + declare e() {}; + abstract f() {}; + readonly g() {}; +} diff --git a/tests/misc/typescript-only/jsfmt.spec.js b/tests/misc/typescript-only/jsfmt.spec.js new file mode 100644 index 000000000000..2ea3bb6eb2e4 --- /dev/null +++ b/tests/misc/typescript-only/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["typescript"]); diff --git a/tests/typescript/abstract-class/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/abstract-class/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..5094e4e4f50c --- /dev/null +++ b/tests/typescript/abstract-class/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,17 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`export-default.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +export default abstract class C5 { abstract foo(): void; } + +=====================================output===================================== +export default abstract class C5 { + abstract foo(): void; +} + +================================================================================ +`; diff --git a/tests/typescript/abstract-class/export-default.ts b/tests/typescript/abstract-class/export-default.ts new file mode 100644 index 000000000000..20947d6fccce --- /dev/null +++ b/tests/typescript/abstract-class/export-default.ts @@ -0,0 +1 @@ +export default abstract class C5 { abstract foo(): void; } diff --git a/tests/typescript/abstract-class/jsfmt.spec.js b/tests/typescript/abstract-class/jsfmt.spec.js new file mode 100644 index 000000000000..2ea3bb6eb2e4 --- /dev/null +++ b/tests/typescript/abstract-class/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["typescript"]); diff --git a/tests/typescript/class/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/class/__snapshots__/jsfmt.spec.js.snap index 8179d2653ebc..af194720ed0a 100644 --- a/tests/typescript/class/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/class/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,39 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`abstract-method.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +class Foo { + abstract foo(); +} + +abstract class Bar { + method() { + return class { + abstract m(); + } + } +} + +=====================================output===================================== +class Foo { + abstract foo(); +} + +abstract class Bar { + method() { + return class { + abstract m(); + }; + } +} + +================================================================================ +`; + exports[`constructor.ts [babel-ts] format 1`] = ` "Unexpected token, expected \\",\\" (2:22) 1 | class foo { @@ -72,6 +106,32 @@ class F<__T> {} ================================================================================ `; +exports[`duplicates-access-modifier.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +class Foo { + public public a; + private public b; + protected private c; + public protected d; + public protected private e; +} + +=====================================output===================================== +class Foo { + public a; + private b; + protected c; + public d; + public e; +} + +================================================================================ +`; + exports[`empty-method-body.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] @@ -291,11 +351,11 @@ interface AudioBufferList { `; exports[`methods.ts [babel-ts] format 1`] = ` -"Unexpected token, expected \\";\\" (6:10) +"Missing semicolon (6:9) 4 | 5 | interface Iterable { > 6 | export [Symbol.iterator](): Iterator; - | ^ + | ^ 7 | } 8 | 9 | export class Check {" diff --git a/tests/typescript/class/abstract-method.ts b/tests/typescript/class/abstract-method.ts new file mode 100644 index 000000000000..28409d8142e6 --- /dev/null +++ b/tests/typescript/class/abstract-method.ts @@ -0,0 +1,11 @@ +class Foo { + abstract foo(); +} + +abstract class Bar { + method() { + return class { + abstract m(); + } + } +} diff --git a/tests/typescript/class/duplicates-access-modifier.ts b/tests/typescript/class/duplicates-access-modifier.ts new file mode 100644 index 000000000000..fa01be69f2c4 --- /dev/null +++ b/tests/typescript/class/duplicates-access-modifier.ts @@ -0,0 +1,7 @@ +class Foo { + public public a; + private public b; + protected private c; + public protected d; + public protected private e; +} diff --git a/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap index 12029569cc85..f3a59e32dc38 100644 --- a/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap @@ -428,7 +428,7 @@ const; `; exports[`errorOnInitializerInInterfaceProperty.ts [babel-ts] format 1`] = ` -"Unexpected token, expected \\";\\" (2:17) +"Unexpected token (2:17) 1 | interface Foo { > 2 | bar: number = 5; | ^ @@ -647,14 +647,6 @@ const shouldFail: { important: boolean } = output.x.children; ================================================================================ `; -exports[`modifiersOnInterfaceIndexSignature1.ts [babel-ts] format 1`] = ` -"Unexpected token, expected \\";\\" (2:10) - 1 | interface I { -> 2 | public [a: string]: number; - | ^ - 3 | }" -`; - exports[`modifiersOnInterfaceIndexSignature1.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/typescript/compiler/jsfmt.spec.js b/tests/typescript/compiler/jsfmt.spec.js index 4c97228f4977..100380aa1e7b 100644 --- a/tests/typescript/compiler/jsfmt.spec.js +++ b/tests/typescript/compiler/jsfmt.spec.js @@ -3,7 +3,6 @@ run_spec(__dirname, ["typescript"], { "babel-ts": [ "downlevelLetConst1.ts", "errorOnInitializerInInterfaceProperty.ts", - "modifiersOnInterfaceIndexSignature1.ts", ], }, }); diff --git a/tests/typescript/conformance/parser/ecmascript5/Statements/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/conformance/parser/ecmascript5/Statements/__snapshots__/jsfmt.spec.js.snap index 87fd2d2c9997..c3047d5cc5fc 100644 --- a/tests/typescript/conformance/parser/ecmascript5/Statements/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/conformance/parser/ecmascript5/Statements/__snapshots__/jsfmt.spec.js.snap @@ -1,10 +1,10 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`parserES5ForOfStatement2.ts [babel-ts] format 1`] = ` -"Unexpected token, expected \\";\\" (2:13) +"Missing semicolon (2:12) 1 | //@target: ES5 > 2 | for (var of X) { - | ^ + | ^ 3 | } 4 |" `; @@ -53,9 +53,9 @@ for (var of of) { `; exports[`parserForInStatement2.ts [babel-ts] format 1`] = ` -"Unexpected token, expected \\";\\" (1:13) +"Missing semicolon (1:12) > 1 | for (var in X) { - | ^ + | ^ 2 | } 3 |" `; diff --git a/tests/typescript/conformance/types/abstractKeyword/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/conformance/types/abstractKeyword/__snapshots__/jsfmt.spec.js.snap index 1d1d6d2258ed..5d8631a61c01 100644 --- a/tests/typescript/conformance/types/abstractKeyword/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/conformance/types/abstractKeyword/__snapshots__/jsfmt.spec.js.snap @@ -1,12 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`abstractKeyword.ts [babel-ts] format 1`] = ` -"Unexpected token, expected \\";\\" (1:10) -> 1 | abstract interface I {} - | ^ - 2 |" -`; - exports[`abstractKeyword.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/typescript/conformance/types/abstractKeyword/jsfmt.spec.js b/tests/typescript/conformance/types/abstractKeyword/jsfmt.spec.js index 4c48f7a811fd..2ea3bb6eb2e4 100644 --- a/tests/typescript/conformance/types/abstractKeyword/jsfmt.spec.js +++ b/tests/typescript/conformance/types/abstractKeyword/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["typescript"], { errors: { "babel-ts": true } }); +run_spec(__dirname, ["typescript"]); diff --git a/tests/typescript/enum/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/enum/__snapshots__/jsfmt.spec.js.snap index 995833522fdd..82de64f80d39 100644 --- a/tests/typescript/enum/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/enum/__snapshots__/jsfmt.spec.js.snap @@ -58,3 +58,19 @@ const enum Enum { ================================================================================ `; + +exports[`multiline.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +declare enum +E +{} + +=====================================output===================================== +declare enum E {} + +================================================================================ +`; diff --git a/tests/typescript/enum/multiline.ts b/tests/typescript/enum/multiline.ts new file mode 100644 index 000000000000..8ce2bd56c88a --- /dev/null +++ b/tests/typescript/enum/multiline.ts @@ -0,0 +1,3 @@ +declare enum +E +{} diff --git a/tests/typescript/interface/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/interface/__snapshots__/jsfmt.spec.js.snap index ec8b9168f3f8..6c3b914cd00c 100644 --- a/tests/typescript/interface/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/interface/__snapshots__/jsfmt.spec.js.snap @@ -1,23 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`abstract.ts [babel-ts] format 1`] = ` -"Unexpected token, expected \\";\\" (1:10) -> 1 | abstract interface I { - | ^ - 2 | - 3 | } - 4 |" -`; - -exports[`abstract.ts - {"semi":false} [babel-ts] format 1`] = ` -"Unexpected token, expected \\";\\" (1:10) -> 1 | abstract interface I { - | ^ - 2 | - 3 | } - 4 |" -`; - exports[`abstract.ts - {"semi":false} format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/typescript/interface/jsfmt.spec.js b/tests/typescript/interface/jsfmt.spec.js index 9f29824f7dfa..c75e14433bde 100644 --- a/tests/typescript/interface/jsfmt.spec.js +++ b/tests/typescript/interface/jsfmt.spec.js @@ -1,7 +1,4 @@ -run_spec(__dirname, ["typescript"], { - errors: { "babel-ts": ["abstract.ts"] }, -}); +run_spec(__dirname, ["typescript"], {}); run_spec(__dirname, ["typescript"], { semi: false, - errors: { "babel-ts": ["abstract.ts"] }, }); diff --git a/tests/typescript/keywords/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/keywords/__snapshots__/jsfmt.spec.js.snap index da283768a03c..cc2961ef208b 100644 --- a/tests/typescript/keywords/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/keywords/__snapshots__/jsfmt.spec.js.snap @@ -1,14 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`keywords.ts [babel-ts] format 1`] = ` -"Unexpected token, expected \\";\\" (4:12) - 2 | - 3 | module Y3 { -> 4 | public module Module { - | ^ - 5 | class A { s: string } - 6 | } - 7 |" +"Unexpected token, expected \\"{\\" (9:12) + 7 | + 8 | // Apparently this parses :P +> 9 | export private public protected static readonly abstract async enum X { } + | ^ + 10 | + 11 | interface x { + 12 | export private static readonly [x: any]: any;" `; exports[`keywords.ts format 1`] = ` @@ -126,9 +126,6 @@ class C { private *a() {} public *b() {} static *c() {} - abstract *d() {} - readonly *e() {} - declare *f() {} protected *g() {} } @@ -166,9 +163,6 @@ class C { private *a() {} public *b() {} static *c() {} - abstract *d() {} - *e() {} - *f() {} protected *g() {} } @@ -200,3 +194,52 @@ class G { ================================================================================ `; + +exports[`module.ts [babel-ts] format 1`] = ` +"Unexpected token, expected \\"{\\" (7:10) + 5 | + 6 | // Apparently this parses :P +> 7 | export private public protected static readonly abstract async enum X { } + | ^ + 8 | + 9 | interface x { + 10 | export private static readonly [x: any]: any;" +`; + +exports[`module.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +module Y3 { + public module Module { + class A { s: string } + } + + // Apparently this parses :P + export private public protected static readonly abstract async enum X { } + + interface x { + export private static readonly [x: any]: any; + } +} + +=====================================output===================================== +module Y3 { + public module Module { + class A { + s: string; + } + } + + // Apparently this parses :P + export private public protected static readonly abstract async enum X {} + + interface x { + export private static readonly [x: any]: any; + } +} + +================================================================================ +`; diff --git a/tests/typescript/keywords/jsfmt.spec.js b/tests/typescript/keywords/jsfmt.spec.js index 69e435854dd6..c8b902d7da97 100644 --- a/tests/typescript/keywords/jsfmt.spec.js +++ b/tests/typescript/keywords/jsfmt.spec.js @@ -1,3 +1,3 @@ run_spec(__dirname, ["typescript"], { - errors: { "babel-ts": ["keywords.ts"] }, + errors: { "babel-ts": ["module.ts", "keywords.ts"] }, }); diff --git a/tests/typescript/keywords/keywords-2.ts b/tests/typescript/keywords/keywords-2.ts index cc54a65ec429..e47335e803ab 100644 --- a/tests/typescript/keywords/keywords-2.ts +++ b/tests/typescript/keywords/keywords-2.ts @@ -4,9 +4,6 @@ class C { private *a() {} public *b() {} static *c() {} - abstract *d() {} - readonly *e() {} - declare *f() {} protected *g() {} } diff --git a/tests/typescript/keywords/module.ts b/tests/typescript/keywords/module.ts new file mode 100644 index 000000000000..f4bd5c9f5618 --- /dev/null +++ b/tests/typescript/keywords/module.ts @@ -0,0 +1,12 @@ +module Y3 { + public module Module { + class A { s: string } + } + + // Apparently this parses :P + export private public protected static readonly abstract async enum X { } + + interface x { + export private static readonly [x: any]: any; + } +} diff --git a/tests/typescript/namespace/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/namespace/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..83c1f7ab6ae2 --- /dev/null +++ b/tests/typescript/namespace/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,19 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`invalid-await.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +namespace N { + const x = await 42; +} + +=====================================output===================================== +namespace N { + const x = await 42; +} + +================================================================================ +`; diff --git a/tests/typescript/namespace/invalid-await.ts b/tests/typescript/namespace/invalid-await.ts new file mode 100644 index 000000000000..bc550ad3b94d --- /dev/null +++ b/tests/typescript/namespace/invalid-await.ts @@ -0,0 +1,3 @@ +namespace N { + const x = await 42; +} diff --git a/tests/typescript/namespace/jsfmt.spec.js b/tests/typescript/namespace/jsfmt.spec.js new file mode 100644 index 000000000000..2ea3bb6eb2e4 --- /dev/null +++ b/tests/typescript/namespace/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["typescript"]); diff --git a/tests/typescript/optional-call/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/optional-call/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..2c7f1dbb64bf --- /dev/null +++ b/tests/typescript/optional-call/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,15 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`type-parameters.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +foo?.foo(); + +=====================================output===================================== +foo?.foo(); + +================================================================================ +`; diff --git a/tests/typescript/optional-call/jsfmt.spec.js b/tests/typescript/optional-call/jsfmt.spec.js new file mode 100644 index 000000000000..2ea3bb6eb2e4 --- /dev/null +++ b/tests/typescript/optional-call/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, ["typescript"]); diff --git a/tests/typescript/optional-call/type-parameters.ts b/tests/typescript/optional-call/type-parameters.ts new file mode 100644 index 000000000000..666a0756abcc --- /dev/null +++ b/tests/typescript/optional-call/type-parameters.ts @@ -0,0 +1 @@ +foo?.foo(); diff --git a/tests_config/run_spec.js b/tests_config/run_spec.js index f417f02a7aa5..ea8baaed3d4c 100644 --- a/tests_config/run_spec.js +++ b/tests_config/run_spec.js @@ -103,6 +103,11 @@ function runSpec(fixtures, parsers, options) { options = { errors: true, ...options }; } + const IS_TYPESCRIPT_ONLY_TEST = isTestDirectory( + dirname, + "misc/typescript-only" + ); + if (IS_PARSER_INFERENCE_TESTS) { parsers = [undefined]; } @@ -151,7 +156,11 @@ function runSpec(fixtures, parsers, options) { const allParsers = [...parsers]; if (!IS_ERROR_TESTS) { - if (parsers.includes("typescript") && !parsers.includes("babel-ts")) { + if ( + parsers.includes("typescript") && + !parsers.includes("babel-ts") && + !IS_TYPESCRIPT_ONLY_TEST + ) { allParsers.push("babel-ts"); } diff --git a/tests_integration/__tests__/__snapshots__/syntax-error.js.snap b/tests_integration/__tests__/__snapshots__/syntax-error.js.snap index 06086355d8cf..5e2c5a6ff108 100644 --- a/tests_integration/__tests__/__snapshots__/syntax-error.js.snap +++ b/tests_integration/__tests__/__snapshots__/syntax-error.js.snap @@ -1,7 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`exits with non-zero code when input has a syntax error (stderr) 1`] = ` -"[error] stdin: SyntaxError: Unexpected token, expected \\";\\" (1:2) +"[error] stdin: SyntaxError: Missing semicolon (1:2) [error] > 1 | a.2 [error] | ^ " diff --git a/tests_integration/__tests__/__snapshots__/write.js.snap b/tests_integration/__tests__/__snapshots__/write.js.snap index 124bf8be3a23..5571d6b887b1 100644 --- a/tests_integration/__tests__/__snapshots__/write.js.snap +++ b/tests_integration/__tests__/__snapshots__/write.js.snap @@ -8,9 +8,9 @@ exports[`do not write file with --write + formatted file (stdout) 1`] = ` `; exports[`do not write file with --write + invalid file (stderr) 1`] = ` -"[error] invalid.js: SyntaxError: Unexpected token, expected \\";\\" (1:6) +"[error] invalid.js: SyntaxError: Unexpected token (1:17) [error] > 1 | this is invalid! -[error] | ^ +[error] | ^ " `; diff --git a/yarn.lock b/yarn.lock index 8f252a5baba2..2ecab2ab473c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -267,10 +267,10 @@ chalk "^2.0.0" js-tokens "^4.0.0" -"@babel/parser@7.12.11": - version "7.12.11" - resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.11.tgz#9ce3595bcd74bc5c466905e86c535b8b25011e79" - integrity sha512-N3UxG+uuF4CMYoNj8AhnbAcJF0PiuJ9KHuy1lQmkYsxTer/MAH9UBNHsBoAX/4s6NvlDD047No8mYVGGzLL4hg== +"@babel/parser@7.12.17": + version "7.12.17" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.12.17.tgz#bc85d2d47db38094e5bb268fc761716e7d693848" + integrity sha512-r1yKkiUTYMQ8LiEI0UcQx5ETw5dpTLn9wijn9hk6KkTtOK95FndDN10M+8/s6k/Ymlbivw0Av9q4SlgF80PtHg== "@babel/parser@^7.1.0", "@babel/parser@^7.12.13", "@babel/parser@^7.12.17", "@babel/parser@^7.7.0": version "7.12.17" @@ -3078,6 +3078,7 @@ eslint-plugin-jest@24.1.5: "eslint-plugin-prettier-internal-rules@link:scripts/tools/eslint-plugin-prettier-internal-rules": version "0.0.0" + uid "" eslint-plugin-react@7.22.0: version "7.22.0"