From dd30feab85fecb27a9c909057e66dfafd2f8494e Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Feb 2023 09:48:59 +0800 Subject: [PATCH 01/15] Update dependencies --- package.json | 6 +++--- yarn.lock | 49 +++++++++++++++++++++++++------------------------ 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/package.json b/package.json index 67a7b9e17fc7..3ec05f2edb7f 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,8 @@ "dependencies": { "@angular/compiler": "15.1.5", "@babel/code-frame": "7.18.6", - "@babel/parser": "7.20.15", - "@babel/types": "7.20.7", + "@babel/parser": "7.21.1", + "@babel/types": "7.21.0", "@glimmer/syntax": "0.84.2", "@iarna/toml": "2.2.5", "@prettier/is-es5-identifier-name": "0.1.0", @@ -104,7 +104,7 @@ "yaml-unist-parser": "2.0.1" }, "devDependencies": { - "@babel/generator": "7.20.14", + "@babel/generator": "7.21.1", "@esbuild-plugins/node-modules-polyfill": "0.2.2", "@glimmer/reference": "0.84.2", "@types/estree": "1.0.0", diff --git a/yarn.lock b/yarn.lock index 6431019a1485..64bcb2cd4bc1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -84,14 +84,15 @@ __metadata: languageName: node linkType: hard -"@babel/generator@npm:7.20.14, @babel/generator@npm:^7.18.10, @babel/generator@npm:^7.7.2": - version: 7.20.14 - resolution: "@babel/generator@npm:7.20.14" +"@babel/generator@npm:7.21.1, @babel/generator@npm:^7.18.10, @babel/generator@npm:^7.7.2": + version: 7.21.1 + resolution: "@babel/generator@npm:7.21.1" dependencies: - "@babel/types": ^7.20.7 + "@babel/types": ^7.21.0 "@jridgewell/gen-mapping": ^0.3.2 + "@jridgewell/trace-mapping": ^0.3.17 jsesc: ^2.5.1 - checksum: 5f6aa2d86af26e76d276923a5c34191124a119b16ee9ccc34aef654a7dec84fbd7d2daed2e6458a6a06bf87f3661deb77c9fea59b8f67faff5c90793c96d76d6 + checksum: 69085a211ff91a7a608ee3f86e6fcb9cf5e724b756d792a713b0c328a671cd3e423e1ef1b12533f366baba0616caffe0a7ba9d328727eab484de5961badbef00 languageName: node linkType: hard @@ -228,12 +229,12 @@ __metadata: languageName: node linkType: hard -"@babel/parser@npm:7.20.15, @babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.18.10, @babel/parser@npm:^7.18.11": - version: 7.20.15 - resolution: "@babel/parser@npm:7.20.15" +"@babel/parser@npm:7.21.1, @babel/parser@npm:^7.1.0, @babel/parser@npm:^7.14.7, @babel/parser@npm:^7.18.10, @babel/parser@npm:^7.18.11": + version: 7.21.1 + resolution: "@babel/parser@npm:7.21.1" bin: parser: ./bin/babel-parser.js - checksum: 1d0f47ca67ff2652f1c0ff1570bed8deccbc4b53509e7cd73476af9cc7ed23480c99f1179bd6d0be01612368b92b39e206d330ad6054009d699934848a89298b + checksum: a564cff6dec4201a611d1f2ae5af8d7436ce80550e75a77ee72dca6b094df6188b5a4ccfae6a98c85991b56a51e6c48159e466cc5a374c7a37af706fcb5a6bc2 languageName: node linkType: hard @@ -420,14 +421,14 @@ __metadata: languageName: node linkType: hard -"@babel/types@npm:7.20.7, @babel/types@npm:^7.0.0, @babel/types@npm:^7.18.10, @babel/types@npm:^7.18.6, @babel/types@npm:^7.18.9, @babel/types@npm:^7.20.7, @babel/types@npm:^7.3.0, @babel/types@npm:^7.3.3, @babel/types@npm:^7.8.3": - version: 7.20.7 - resolution: "@babel/types@npm:7.20.7" +"@babel/types@npm:7.21.0, @babel/types@npm:^7.0.0, @babel/types@npm:^7.18.10, @babel/types@npm:^7.18.6, @babel/types@npm:^7.18.9, @babel/types@npm:^7.21.0, @babel/types@npm:^7.3.0, @babel/types@npm:^7.3.3, @babel/types@npm:^7.8.3": + version: 7.21.0 + resolution: "@babel/types@npm:7.21.0" dependencies: "@babel/helper-string-parser": ^7.19.4 "@babel/helper-validator-identifier": ^7.19.1 to-fast-properties: ^2.0.0 - checksum: b39af241f0b72bba67fd6d0d23914f6faec8c0eba8015c181cbd5ea92e59fc91a52a1ab490d3520c7dbd19ddb9ebb76c476308f6388764f16d8201e37fae6811 + checksum: dbcdda202b3a2bfd59e4de880ce38652f1f8957893a9751be069ac86e47ad751222070fe6cd92220214d77973f1474e4e1111c16dc48199dfca1489c0ee8c0c5 languageName: node linkType: hard @@ -1433,7 +1434,7 @@ __metadata: languageName: node linkType: hard -"@jridgewell/resolve-uri@npm:^3.0.3": +"@jridgewell/resolve-uri@npm:3.1.0": version: 3.1.0 resolution: "@jridgewell/resolve-uri@npm:3.1.0" checksum: b5ceaaf9a110fcb2780d1d8f8d4a0bfd216702f31c988d8042e5f8fbe353c55d9b0f55a1733afdc64806f8e79c485d2464680ac48a0d9fcadb9548ee6b81d267 @@ -1447,20 +1448,20 @@ __metadata: languageName: node linkType: hard -"@jridgewell/sourcemap-codec@npm:^1.4.10, @jridgewell/sourcemap-codec@npm:^1.4.13": +"@jridgewell/sourcemap-codec@npm:1.4.14, @jridgewell/sourcemap-codec@npm:^1.4.10, @jridgewell/sourcemap-codec@npm:^1.4.13": version: 1.4.14 resolution: "@jridgewell/sourcemap-codec@npm:1.4.14" checksum: 61100637b6d173d3ba786a5dff019e1a74b1f394f323c1fee337ff390239f053b87266c7a948777f4b1ee68c01a8ad0ab61e5ff4abb5a012a0b091bec391ab97 languageName: node linkType: hard -"@jridgewell/trace-mapping@npm:^0.3.12, @jridgewell/trace-mapping@npm:^0.3.15, @jridgewell/trace-mapping@npm:^0.3.9": - version: 0.3.15 - resolution: "@jridgewell/trace-mapping@npm:0.3.15" +"@jridgewell/trace-mapping@npm:^0.3.12, @jridgewell/trace-mapping@npm:^0.3.15, @jridgewell/trace-mapping@npm:^0.3.17, @jridgewell/trace-mapping@npm:^0.3.9": + version: 0.3.17 + resolution: "@jridgewell/trace-mapping@npm:0.3.17" dependencies: - "@jridgewell/resolve-uri": ^3.0.3 - "@jridgewell/sourcemap-codec": ^1.4.10 - checksum: 38917e9c2b014d469a9f51c016ed506acbe44dd16ec2f6f99b553ebf3764d22abadbf992f2367b6d2b3511f3eae8ed3a8963f6c1030093fda23efd35ecab2bae + "@jridgewell/resolve-uri": 3.1.0 + "@jridgewell/sourcemap-codec": 1.4.14 + checksum: 9d703b859cff5cd83b7308fd457a431387db5db96bd781a63bf48e183418dd9d3d44e76b9e4ae13237f6abeeb25d739ec9215c1d5bfdd08f66f750a50074a339 languageName: node linkType: hard @@ -6702,9 +6703,9 @@ __metadata: dependencies: "@angular/compiler": 15.1.5 "@babel/code-frame": 7.18.6 - "@babel/generator": 7.20.14 - "@babel/parser": 7.20.15 - "@babel/types": 7.20.7 + "@babel/generator": 7.21.1 + "@babel/parser": 7.21.1 + "@babel/types": 7.21.0 "@esbuild-plugins/node-modules-polyfill": 0.2.2 "@glimmer/reference": 0.84.2 "@glimmer/syntax": 0.84.2 From f11969e68a28819ec08f39390746e2d6ae1c1554 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Feb 2023 09:59:59 +0800 Subject: [PATCH 02/15] Enable `allowNewTargetOutsideFunction` --- src/language-js/parse/babel.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 98 +++++++++++++++++++ tests/format/js/new-target/jsfmt.spec.js | 8 ++ .../format/js/new-target/outside-functions.js | 1 + tests/format/js/new-target/range.js | 6 ++ 5 files changed, 114 insertions(+) create mode 100644 tests/format/js/new-target/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/js/new-target/jsfmt.spec.js create mode 100644 tests/format/js/new-target/outside-functions.js create mode 100644 tests/format/js/new-target/range.js diff --git a/src/language-js/parse/babel.js b/src/language-js/parse/babel.js index 3862af1f3514..6051355dac70 100644 --- a/src/language-js/parse/babel.js +++ b/src/language-js/parse/babel.js @@ -23,6 +23,7 @@ const parseOptions = { sourceType: "module", allowImportExportEverywhere: true, allowReturnOutsideFunction: true, + allowNewTargetOutsideFunction: true, allowSuperOutsideMethod: true, allowUndeclaredExports: true, errorRecovery: true, diff --git a/tests/format/js/new-target/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/new-target/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..5afd170cc882 --- /dev/null +++ b/tests/format/js/new-target/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,98 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`outside-functions.js [acorn] format 1`] = ` +"'new.target' can only be used in functions and class static block (1:11) +> 1 | const x = new.target; + | ^ + 2 |" +`; + +exports[`outside-functions.js [espree] format 1`] = ` +"'new.target' can only be used in functions and class static block (1:11) +> 1 | const x = new.target; + | ^ + 2 |" +`; + +exports[`outside-functions.js [flow] format 1`] = ` +"Unexpected token \`.\` (1:14) +> 1 | const x = new.target; + | ^ + 2 |" +`; + +exports[`outside-functions.js [meriyah] format 1`] = ` +"new.target only allowed within functions (1:20) +> 1 | const x = new.target; + | ^ + 2 |" +`; + +exports[`outside-functions.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +const x = new.target; + +=====================================output===================================== +const x = new.target; + +================================================================================ +`; + +exports[`range.js [acorn] format 1`] = ` +"'new.target' can only be used in functions and class static block (2:1) + 1 | const x = +> 2 | new.target; + | ^" +`; + +exports[`range.js [espree] format 1`] = ` +"'new.target' can only be used in functions and class static block (2:1) + 1 | const x = +> 2 | new.target; + | ^" +`; + +exports[`range.js [flow] format 1`] = ` +"Unexpected token \`.\` (2:4) + 1 | const x = +> 2 | new.target; + | ^" +`; + +exports[`range.js [meriyah] format 1`] = ` +"new.target only allowed within functions (2:10) + 1 | const x = +> 2 | new.target; + | ^" +`; + +exports[`range.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 +rangeEnd: 52 +rangeStart: 38 + | | printWidth +=====================================input====================================== + 1 | class A { + 2 | constructor() { +> 3 | const x = + | ^^^ +> 4 | new.target; + | ^^^^^^^^^^ + 5 | } + 6 | } + 7 | +=====================================output===================================== +class A { + constructor() { + const x = new.target; + } +} + +================================================================================ +`; diff --git a/tests/format/js/new-target/jsfmt.spec.js b/tests/format/js/new-target/jsfmt.spec.js new file mode 100644 index 000000000000..316d1641c1d1 --- /dev/null +++ b/tests/format/js/new-target/jsfmt.spec.js @@ -0,0 +1,8 @@ +run_spec(import.meta, ["babel", "flow", "typescript"], { + errors: { + acorn: true, + espree: true, + meriyah: true, + flow: true, + }, +}); diff --git a/tests/format/js/new-target/outside-functions.js b/tests/format/js/new-target/outside-functions.js new file mode 100644 index 000000000000..85f7e4833373 --- /dev/null +++ b/tests/format/js/new-target/outside-functions.js @@ -0,0 +1 @@ +const x = new.target; diff --git a/tests/format/js/new-target/range.js b/tests/format/js/new-target/range.js new file mode 100644 index 000000000000..57c38b877018 --- /dev/null +++ b/tests/format/js/new-target/range.js @@ -0,0 +1,6 @@ +class A { + constructor() { + const <<>>x = +new.target<<>>; + } +} From d2bd7e37d1dab97c19cbcbacf2b9e80cb2eac7a6 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Feb 2023 10:03:21 +0800 Subject: [PATCH 03/15] Ignore an parse error --- .../flow-repo/async/__snapshots__/jsfmt.spec.js.snap | 10 ---------- tests/format/flow-repo/async/jsfmt.spec.js | 4 +--- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/tests/format/flow-repo/async/__snapshots__/jsfmt.spec.js.snap b/tests/format/flow-repo/async/__snapshots__/jsfmt.spec.js.snap index f6484f36b6ec..e13262d9971b 100644 --- a/tests/format/flow-repo/async/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/flow-repo/async/__snapshots__/jsfmt.spec.js.snap @@ -491,16 +491,6 @@ async function baz() { ================================================================================ `; -exports[`await_parse.js [babel-flow] format 1`] = ` -"Can not use 'await' as identifier inside an async function. (23:5) - 21 | console.log(x.await); - 22 | -> 23 | var await = 3; - | ^ - 24 | var y = { await }; - 25 |" -`; - exports[`await_parse.js format 1`] = ` ====================================options===================================== parsers: ["flow"] diff --git a/tests/format/flow-repo/async/jsfmt.spec.js b/tests/format/flow-repo/async/jsfmt.spec.js index b278b5df4529..c89f3cc86abe 100644 --- a/tests/format/flow-repo/async/jsfmt.spec.js +++ b/tests/format/flow-repo/async/jsfmt.spec.js @@ -1,3 +1 @@ -run_spec(import.meta, ["flow"], { - errors: { "babel-flow": ["await_parse.js"] }, -}); +run_spec(import.meta, ["flow"]); From b9db266144b12d0ac458940a8a946c46a9a0e673 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Feb 2023 10:08:19 +0800 Subject: [PATCH 04/15] Support `export type * from ` --- .../export/__snapshots__/jsfmt.spec.js.snap | 43 +++++++++++++++++++ .../export/export-type-star-from-2.ts | 3 ++ .../export/export-type-star-from.ts | 2 + tests/format/typescript/export/jsfmt.spec.js | 4 +- 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 tests/format/typescript/export/export-type-star-from-2.ts create mode 100644 tests/format/typescript/export/export-type-star-from.ts diff --git a/tests/format/typescript/export/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/export/__snapshots__/jsfmt.spec.js.snap index 440294152e25..f71a5c3bccfb 100644 --- a/tests/format/typescript/export/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/export/__snapshots__/jsfmt.spec.js.snap @@ -93,3 +93,46 @@ export default abstract class D {} ================================================================================ `; + +exports[`export-type-star-from.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +export type * from './mod'; +export type * as ns from './mod'; + +=====================================output===================================== +export type * from "./mod"; +export type * as ns from "./mod"; + +================================================================================ +`; + +exports[`export-type-star-from-2.ts [babel-ts] format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +// Note: TSC doesn't support string module specifiers yet, +// but it's easier for us to support them than not. +export type * as "ns2" from './mod'; + +=====================================output===================================== +// Note: TSC doesn't support string module specifiers yet, +// but it's easier for us to support them than not. +export type * as "ns2" from "./mod"; + +================================================================================ +`; + +exports[`export-type-star-from-2.ts [typescript] format 1`] = ` +"Identifier expected. (3:18) + 1 | // Note: TSC doesn't support string module specifiers yet, + 2 | // but it's easier for us to support them than not. +> 3 | export type * as "ns2" from './mod'; + | ^ + 4 |" +`; diff --git a/tests/format/typescript/export/export-type-star-from-2.ts b/tests/format/typescript/export/export-type-star-from-2.ts new file mode 100644 index 000000000000..4f99f5f56ba7 --- /dev/null +++ b/tests/format/typescript/export/export-type-star-from-2.ts @@ -0,0 +1,3 @@ +// Note: TSC doesn't support string module specifiers yet, +// but it's easier for us to support them than not. +export type * as "ns2" from './mod'; diff --git a/tests/format/typescript/export/export-type-star-from.ts b/tests/format/typescript/export/export-type-star-from.ts new file mode 100644 index 000000000000..467b9869f96b --- /dev/null +++ b/tests/format/typescript/export/export-type-star-from.ts @@ -0,0 +1,2 @@ +export type * from './mod'; +export type * as ns from './mod'; diff --git a/tests/format/typescript/export/jsfmt.spec.js b/tests/format/typescript/export/jsfmt.spec.js index 29084a9c8a10..ed7ee414875f 100644 --- a/tests/format/typescript/export/jsfmt.spec.js +++ b/tests/format/typescript/export/jsfmt.spec.js @@ -1 +1,3 @@ -run_spec(import.meta, ["typescript"]); +run_spec(import.meta, ["typescript"], { + errors: { typescript: ["export-type-star-from-2.ts"] }, +}); From 3381386d0f133494eab284d4f78ae27531c8ebd0 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Feb 2023 10:16:49 +0800 Subject: [PATCH 05/15] Support `const` modifier in type parameters --- src/language-js/print/type-parameters.js | 7 +- .../__snapshots__/jsfmt.spec.js.snap | 85 +++++++++++++++++++ tests/format/typescript/typeparams/const.ts | 32 +++++++ .../typescript/typeparams/jsfmt.spec.js | 2 +- 4 files changed, 122 insertions(+), 4 deletions(-) create mode 100644 tests/format/typescript/typeparams/const.ts diff --git a/src/language-js/print/type-parameters.js b/src/language-js/print/type-parameters.js index 4e24ee86b9f7..f5891b8819c5 100644 --- a/src/language-js/print/type-parameters.js +++ b/src/language-js/print/type-parameters.js @@ -111,9 +111,10 @@ function printDanglingCommentsForInline(path, options) { } function printTypeParameter(path, options, print) { - const { node } = path; - const parts = []; - const { parent } = path; + const { node, parent } = path; + const parts = [ + node.type === "TSTypeParameter" && node.const ? "const " : "" + ]; const name = node.type === "TSTypeParameter" ? print("name") : node.name; diff --git a/tests/format/typescript/typeparams/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/typeparams/__snapshots__/jsfmt.spec.js.snap index 81e7fc067679..faf9848e007e 100644 --- a/tests/format/typescript/typeparams/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/typeparams/__snapshots__/jsfmt.spec.js.snap @@ -286,6 +286,91 @@ const appIDs = createSelector( ================================================================================ `; +exports[`const.ts [babel-ts] format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +function a() {} +function b() {} +function c() {} +declare function d(); +() => {}; +() => {}; +(function () {}); +(function () {}); +(function () {}); + +class A {} +class B {} +class C {} +class D {} +class E {} +(class {}); +(class {}); +(class {}); +(class {}); +(class {}); + +interface I {} +interface J {} +interface K {} +interface L {} +interface M {} + +class _ { + method() {} + method() {} + method() {} +} + +=====================================output===================================== +function a() {} +function b() {} +function c() {} +declare function d(); +() => {}; +() => {}; +(function () {}); +(function () {}); +(function () {}); + +class A {} +class B {} +class C {} +class D {} +class E {} +(class {}); +(class {}); +(class {}); +(class {}); +(class {}); + +interface I {} +interface J {} +interface K {} +interface L {} +interface M {} + +class _ { + method() {} + method() {} + method() {} +} + +================================================================================ +`; + +exports[`const.ts [typescript] format 1`] = ` +"Type parameter declaration expected. (1:12) +> 1 | function a() {} + | ^ + 2 | function b() {} + 3 | function c() {} + 4 | declare function d();" +`; + exports[`long-function-arg.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/format/typescript/typeparams/const.ts b/tests/format/typescript/typeparams/const.ts new file mode 100644 index 000000000000..8134608f85e4 --- /dev/null +++ b/tests/format/typescript/typeparams/const.ts @@ -0,0 +1,32 @@ +function a() {} +function b() {} +function c() {} +declare function d(); +() => {}; +() => {}; +(function () {}); +(function () {}); +(function () {}); + +class A {} +class B {} +class C {} +class D {} +class E {} +(class {}); +(class {}); +(class {}); +(class {}); +(class {}); + +interface I {} +interface J {} +interface K {} +interface L {} +interface M {} + +class _ { + method() {} + method() {} + method() {} +} diff --git a/tests/format/typescript/typeparams/jsfmt.spec.js b/tests/format/typescript/typeparams/jsfmt.spec.js index 29084a9c8a10..69f076cd5f85 100644 --- a/tests/format/typescript/typeparams/jsfmt.spec.js +++ b/tests/format/typescript/typeparams/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ["typescript"]); +run_spec(import.meta, ["typescript"], {errors: {typescript: ["const.ts"]}}); From d5690c3c52fe526ae1cbcb10e5061b6d409941b9 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Feb 2023 10:30:05 +0800 Subject: [PATCH 06/15] Support regexp modifiers proposal --- .../__snapshots__/jsfmt.spec.js.snap | 35 +++++++++++++++ tests/format/js/babel-plugins/jsfmt.spec.js | 3 ++ .../js/babel-plugins/regexp-modifiers.js | 1 + .../js/regex/__snapshots__/jsfmt.spec.js.snap | 45 +++++++++++++++++++ tests/format/js/regex/jsfmt.spec.js | 6 +-- tests/format/js/regex/regexp-modifiers.js | 3 ++ 6 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 tests/format/js/babel-plugins/regexp-modifiers.js create mode 100644 tests/format/js/regex/regexp-modifiers.js diff --git a/tests/format/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap index 6ae20966f749..b01b18d645a8 100644 --- a/tests/format/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap @@ -2362,6 +2362,41 @@ printWidth: 80 ================================================================================ `; +exports[`regexp-modifiers.js [acorn] format 1`] = ` +"Invalid regular expression: /^(?i:[a-z])[a-z]$/: Invalid group (1:13) +> 1 | const re = /^(?i:[a-z])[a-z]$/; + | ^ + 2 |" +`; + +exports[`regexp-modifiers.js [espree] format 1`] = ` +"Invalid regular expression: /^(?i:[a-z])[a-z]$/: Invalid group (1:13) +> 1 | const re = /^(?i:[a-z])[a-z]$/; + | ^ + 2 |" +`; + +exports[`regexp-modifiers.js [meriyah] format 1`] = ` +"Unterminated regular expression (1:30) +> 1 | const re = /^(?i:[a-z])[a-z]$/; + | ^ + 2 |" +`; + +exports[`regexp-modifiers.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "babel-ts", "babel-flow"] +printWidth: 80 + | printWidth +=====================================input====================================== +const re = /^(?i:[a-z])[a-z]$/; + +=====================================output===================================== +const re = /^(?i:[a-z])[a-z]$/; + +================================================================================ +`; + exports[`throw-expressions.js [acorn] format 1`] = ` "Unexpected token (3:23) 1 | // https://babeljs.io/docs/en/babel-plugin-proposal-throw-expressions diff --git a/tests/format/js/babel-plugins/jsfmt.spec.js b/tests/format/js/babel-plugins/jsfmt.spec.js index 0e12e31701f7..c4227da022f7 100644 --- a/tests/format/js/babel-plugins/jsfmt.spec.js +++ b/tests/format/js/babel-plugins/jsfmt.spec.js @@ -29,6 +29,7 @@ run_spec(import.meta, ["babel", "babel-ts", "babel-flow"], { "decorator-auto-accessors.js", "import-reflection.js", "explicit-resource-management.js", + "regexp-modifiers.js", ], espree: [ "decimal.js", @@ -56,6 +57,7 @@ run_spec(import.meta, ["babel", "babel-ts", "babel-flow"], { "decorator-auto-accessors.js", "import-reflection.js", "explicit-resource-management.js", + "regexp-modifiers.js", ], meriyah: [ "decimal.js", @@ -84,6 +86,7 @@ run_spec(import.meta, ["babel", "babel-ts", "babel-flow"], { "regex-v-flag.js", "import-reflection.js", "explicit-resource-management.js", + "regexp-modifiers.js", ], babel: ["flow.js", "typescript.js"], __babel_estree: ["flow.js", "typescript.js"], diff --git a/tests/format/js/babel-plugins/regexp-modifiers.js b/tests/format/js/babel-plugins/regexp-modifiers.js new file mode 100644 index 000000000000..21cfd8487fe6 --- /dev/null +++ b/tests/format/js/babel-plugins/regexp-modifiers.js @@ -0,0 +1 @@ +const re = /^(?i:[a-z])[a-z]$/; diff --git a/tests/format/js/regex/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/regex/__snapshots__/jsfmt.spec.js.snap index f458f7331116..2fb91801f3a7 100644 --- a/tests/format/js/regex/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/regex/__snapshots__/jsfmt.spec.js.snap @@ -30,6 +30,51 @@ printWidth: 80 ================================================================================ `; +exports[`regexp-modifiers.js [acorn] format 1`] = ` +"Invalid regular expression: /(?ims:^[a-z])/: Invalid group (1:2) +> 1 | /(?ims:^[a-z])/u; + | ^ + 2 | /(?-ims:^[a-z].)(^[a-z].)/uims; + 3 | /(?ims:^[a-z].1$)/; + 4 |" +`; + +exports[`regexp-modifiers.js [espree] format 1`] = ` +"Invalid regular expression: /(?ims:^[a-z])/: Invalid group (1:2) +> 1 | /(?ims:^[a-z])/u; + | ^ + 2 | /(?-ims:^[a-z].)(^[a-z].)/uims; + 3 | /(?ims:^[a-z].1$)/; + 4 |" +`; + +exports[`regexp-modifiers.js [meriyah] format 1`] = ` +"Unterminated regular expression (1:16) +> 1 | /(?ims:^[a-z])/u; + | ^ + 2 | /(?-ims:^[a-z].)(^[a-z].)/uims; + 3 | /(?ims:^[a-z].1$)/; + 4 |" +`; + +exports[`regexp-modifiers.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +/(?ims:^[a-z])/u; +/(?-ims:^[a-z].)(^[a-z].)/uims; +/(?ims:^[a-z].1$)/; + +=====================================output===================================== +/(?ims:^[a-z])/u; +/(?-ims:^[a-z].)(^[a-z].)/imsu; +/(?ims:^[a-z].1$)/; + +================================================================================ +`; + exports[`test.js format 1`] = ` ====================================options===================================== parsers: ["babel", "flow", "typescript"] diff --git a/tests/format/js/regex/jsfmt.spec.js b/tests/format/js/regex/jsfmt.spec.js index 10725f23fb2c..68874ba4e658 100644 --- a/tests/format/js/regex/jsfmt.spec.js +++ b/tests/format/js/regex/jsfmt.spec.js @@ -1,8 +1,8 @@ run_spec(import.meta, ["babel", "flow", "typescript"], { errors: { flow: ["v-flag.js"], - acorn: ["v-flag.js"], - espree: ["v-flag.js"], - meriyah: ["v-flag.js"], + acorn: ["v-flag.js", "regexp-modifiers.js"], + espree: ["v-flag.js", "regexp-modifiers.js"], + meriyah: ["v-flag.js", "regexp-modifiers.js"], }, }); diff --git a/tests/format/js/regex/regexp-modifiers.js b/tests/format/js/regex/regexp-modifiers.js new file mode 100644 index 000000000000..6d1d5144bec7 --- /dev/null +++ b/tests/format/js/regex/regexp-modifiers.js @@ -0,0 +1,3 @@ +/(?ims:^[a-z])/u; +/(?-ims:^[a-z].)(^[a-z].)/uims; +/(?ims:^[a-z].1$)/; From 15c2796f35c8c91dd889da7984ded40582bfea7d Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Feb 2023 10:57:41 +0800 Subject: [PATCH 07/15] Allow `const` --- .../parse/postprocess/typescript.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 434 +++++++++--------- .../errors/typescript/modifiers/jsfmt.spec.js | 5 +- 3 files changed, 215 insertions(+), 225 deletions(-) diff --git a/src/language-js/parse/postprocess/typescript.js b/src/language-js/parse/postprocess/typescript.js index 7dfa406c320a..ed43df05d053 100644 --- a/src/language-js/parse/postprocess/typescript.js +++ b/src/language-js/parse/postprocess/typescript.js @@ -103,6 +103,7 @@ function throwErrorForInvalidModifier(node) { if ( modifier.kind !== SyntaxKind.InKeyword && modifier.kind !== SyntaxKind.OutKeyword && + modifier.kind !== SyntaxKind.ConstKeyword && node.kind === SyntaxKind.TypeParameter ) { throwErrorOnTsNode( diff --git a/tests/format/misc/errors/typescript/modifiers/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/typescript/modifiers/__snapshots__/jsfmt.spec.js.snap index 0e0c95a33a8f..50bbd697bdef 100644 --- a/tests/format/misc/errors/typescript/modifiers/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/errors/typescript/modifiers/__snapshots__/jsfmt.spec.js.snap @@ -1105,126 +1105,114 @@ exports[`snippet: #72 [typescript] format 1`] = ` `; exports[`snippet: #73 [babel-ts] format 1`] = ` -"Unexpected token, expected "," (1:21) -> 1 | interface Foo {} - | ^" -`; - -exports[`snippet: #73 [typescript] format 1`] = ` -"Type parameter declaration expected. (1:15) -> 1 | interface Foo {} - | ^" -`; - -exports[`snippet: #74 [babel-ts] format 1`] = ` "'declare' modifier cannot appear on a type parameter. (1:15) > 1 | interface Foo {} | ^" `; -exports[`snippet: #74 [typescript] format 1`] = ` +exports[`snippet: #73 [typescript] format 1`] = ` "'declare' modifier cannot appear on a type parameter (1:15) > 1 | interface Foo {} | ^^^^^^^" `; -exports[`snippet: #75 [babel-ts] format 1`] = ` +exports[`snippet: #74 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:23) > 1 | interface Foo {} | ^" `; -exports[`snippet: #75 [typescript] format 1`] = ` +exports[`snippet: #74 [typescript] format 1`] = ` "Type parameter declaration expected. (1:15) > 1 | interface Foo {} | ^" `; -exports[`snippet: #76 [babel-ts] format 1`] = ` +exports[`snippet: #75 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:22) > 1 | interface Foo {} | ^" `; -exports[`snippet: #76 [typescript] format 1`] = ` +exports[`snippet: #75 [typescript] format 1`] = ` "Type parameter declaration expected. (1:15) > 1 | interface Foo {} | ^" `; -exports[`snippet: #77 [babel-ts] format 1`] = ` +exports[`snippet: #76 [babel-ts] format 1`] = ` "'override' modifier cannot appear on a type parameter. (1:15) > 1 | interface Foo {} | ^" `; -exports[`snippet: #77 [typescript] format 1`] = ` +exports[`snippet: #76 [typescript] format 1`] = ` "'override' modifier cannot appear on a type parameter (1:15) > 1 | interface Foo {} | ^^^^^^^^" `; -exports[`snippet: #78 [babel-ts] format 1`] = ` +exports[`snippet: #77 [babel-ts] format 1`] = ` "'private' modifier cannot appear on a type parameter. (1:15) > 1 | interface Foo {} | ^" `; -exports[`snippet: #78 [typescript] format 1`] = ` +exports[`snippet: #77 [typescript] format 1`] = ` "'private' modifier cannot appear on a type parameter (1:15) > 1 | interface Foo {} | ^^^^^^^" `; -exports[`snippet: #79 [babel-ts] format 1`] = ` +exports[`snippet: #78 [babel-ts] format 1`] = ` "'protected' modifier cannot appear on a type parameter. (1:15) > 1 | interface Foo {} | ^" `; -exports[`snippet: #79 [typescript] format 1`] = ` +exports[`snippet: #78 [typescript] format 1`] = ` "'protected' modifier cannot appear on a type parameter (1:15) > 1 | interface Foo {} | ^^^^^^^^^" `; -exports[`snippet: #80 [babel-ts] format 1`] = ` +exports[`snippet: #79 [babel-ts] format 1`] = ` "'public' modifier cannot appear on a type parameter. (1:15) > 1 | interface Foo {} | ^" `; -exports[`snippet: #80 [typescript] format 1`] = ` +exports[`snippet: #79 [typescript] format 1`] = ` "'public' modifier cannot appear on a type parameter (1:15) > 1 | interface Foo {} | ^^^^^^" `; -exports[`snippet: #81 [babel-ts] format 1`] = ` +exports[`snippet: #80 [babel-ts] format 1`] = ` "'readonly' modifier cannot appear on a type parameter. (1:15) > 1 | interface Foo {} | ^" `; -exports[`snippet: #81 [typescript] format 1`] = ` +exports[`snippet: #80 [typescript] format 1`] = ` "'readonly' modifier cannot appear on a type parameter (1:15) > 1 | interface Foo {} | ^^^^^^^^" `; -exports[`snippet: #82 [babel-ts] format 1`] = ` +exports[`snippet: #81 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:22) > 1 | interface Foo {} | ^" `; -exports[`snippet: #82 [typescript] format 1`] = ` +exports[`snippet: #81 [typescript] format 1`] = ` "'static' modifier cannot appear on a type parameter (1:15) > 1 | interface Foo {} | ^^^^^^" `; -exports[`snippet: #83 [babel-ts] format 1`] = ` +exports[`snippet: #82 [babel-ts] format 1`] = ` "Class methods cannot have the 'declare' modifier. (2:3) 1 | class Foo { > 2 | declare method() {} @@ -1232,7 +1220,7 @@ exports[`snippet: #83 [babel-ts] format 1`] = ` 3 | }" `; -exports[`snippet: #83 [typescript] format 1`] = ` +exports[`snippet: #82 [typescript] format 1`] = ` "'declare' modifier cannot appear on class elements of this kind. (2:3) 1 | class Foo { > 2 | declare method() {} @@ -1240,7 +1228,7 @@ exports[`snippet: #83 [typescript] format 1`] = ` 3 | }" `; -exports[`snippet: #84 [babel-ts] format 1`] = ` +exports[`snippet: #83 [babel-ts] format 1`] = ` "Class methods cannot have the 'readonly' modifier. (2:3) 1 | class Foo { > 2 | readonly method() {} @@ -1248,7 +1236,7 @@ exports[`snippet: #84 [babel-ts] format 1`] = ` 3 | }" `; -exports[`snippet: #84 [typescript] format 1`] = ` +exports[`snippet: #83 [typescript] format 1`] = ` "'readonly' modifier can only appear on a property declaration or index signature. (2:3) 1 | class Foo { > 2 | readonly method() {} @@ -1256,7 +1244,7 @@ exports[`snippet: #84 [typescript] format 1`] = ` 3 | }" `; -exports[`snippet: #85 [babel-ts] format 1`] = ` +exports[`snippet: #84 [babel-ts] format 1`] = ` "'declare' is not allowed in getters. (2:3) 1 | class Foo { > 2 | declare get getter() {} @@ -1264,7 +1252,7 @@ exports[`snippet: #85 [babel-ts] format 1`] = ` 3 | }" `; -exports[`snippet: #85 [typescript] format 1`] = ` +exports[`snippet: #84 [typescript] format 1`] = ` "'declare' modifier cannot appear on class elements of this kind. (2:3) 1 | class Foo { > 2 | declare get getter() {} @@ -1272,7 +1260,7 @@ exports[`snippet: #85 [typescript] format 1`] = ` 3 | }" `; -exports[`snippet: #86 [babel-ts] format 1`] = ` +exports[`snippet: #85 [babel-ts] format 1`] = ` "'declare' is not allowed in setters. (2:3) 1 | class Foo { > 2 | declare set setter(v) {} @@ -1280,7 +1268,7 @@ exports[`snippet: #86 [babel-ts] format 1`] = ` 3 | }" `; -exports[`snippet: #86 [typescript] format 1`] = ` +exports[`snippet: #85 [typescript] format 1`] = ` "'declare' modifier cannot appear on class elements of this kind. (2:3) 1 | class Foo { > 2 | declare set setter(v) {} @@ -1288,1111 +1276,1111 @@ exports[`snippet: #86 [typescript] format 1`] = ` 3 | }" `; -exports[`snippet: #87 [babel-ts] format 1`] = ` +exports[`snippet: #86 [babel-ts] format 1`] = ` "Unexpected token, expected "class" (1:10) > 1 | abstract module Foo {} | ^" `; -exports[`snippet: #87 [typescript] format 1`] = ` +exports[`snippet: #86 [typescript] format 1`] = ` "'abstract' modifier can only appear on a class, method, or property declaration. (1:1) > 1 | abstract module Foo {} | ^^^^^^^^" `; -exports[`snippet: #88 [babel-ts] format 1`] = ` +exports[`snippet: #87 [babel-ts] format 1`] = ` "Unexpected token, expected "class" (1:10) > 1 | abstract namespace Foo {} | ^" `; -exports[`snippet: #88 [typescript] format 1`] = ` +exports[`snippet: #87 [typescript] format 1`] = ` "'abstract' modifier can only appear on a class, method, or property declaration. (1:1) > 1 | abstract namespace Foo {} | ^^^^^^^^" `; -exports[`snippet: #89 [babel-ts] format 1`] = ` +exports[`snippet: #88 [babel-ts] format 1`] = ` "Missing semicolon. (1:9) > 1 | accessor module Foo {} | ^" `; -exports[`snippet: #89 [typescript] format 1`] = ` +exports[`snippet: #88 [typescript] format 1`] = ` "'accessor' modifier can only appear on a property declaration. (1:1) > 1 | accessor module Foo {} | ^^^^^^^^" `; -exports[`snippet: #90 [babel-ts] format 1`] = ` +exports[`snippet: #89 [babel-ts] format 1`] = ` "Missing semicolon. (1:9) > 1 | accessor namespace Foo {} | ^" `; -exports[`snippet: #90 [typescript] format 1`] = ` +exports[`snippet: #89 [typescript] format 1`] = ` "'accessor' modifier can only appear on a property declaration. (1:1) > 1 | accessor namespace Foo {} | ^^^^^^^^" `; -exports[`snippet: #91 [babel-ts] format 1`] = ` +exports[`snippet: #90 [babel-ts] format 1`] = ` "Missing semicolon. (1:6) > 1 | async module Foo {} | ^" `; -exports[`snippet: #91 [typescript] format 1`] = ` +exports[`snippet: #90 [typescript] format 1`] = ` "'async' modifier cannot be used here. (1:1) > 1 | async module Foo {} | ^^^^^" `; -exports[`snippet: #92 [babel-ts] format 1`] = ` +exports[`snippet: #91 [babel-ts] format 1`] = ` "Missing semicolon. (1:6) > 1 | async namespace Foo {} | ^" `; -exports[`snippet: #92 [typescript] format 1`] = ` +exports[`snippet: #91 [typescript] format 1`] = ` "'async' modifier cannot be used here. (1:1) > 1 | async namespace Foo {} | ^^^^^" `; -exports[`snippet: #93 [babel-ts] format 1`] = ` +exports[`snippet: #92 [babel-ts] format 1`] = ` "Missing initializer in const declaration. (1:13) > 1 | const module Foo {} | ^" `; -exports[`snippet: #93 [typescript] format 1`] = ` +exports[`snippet: #92 [typescript] format 1`] = ` "',' expected. (1:14) > 1 | const module Foo {} | ^" `; -exports[`snippet: #94 [babel-ts] format 1`] = ` +exports[`snippet: #93 [babel-ts] format 1`] = ` "Missing initializer in const declaration. (1:16) > 1 | const namespace Foo {} | ^" `; -exports[`snippet: #94 [typescript] format 1`] = ` +exports[`snippet: #93 [typescript] format 1`] = ` "',' expected. (1:17) > 1 | const namespace Foo {} | ^" `; -exports[`snippet: #95 [babel-ts] format 1`] = ` +exports[`snippet: #94 [babel-ts] format 1`] = ` "Unexpected token (1:1) > 1 | default module Foo {} | ^" `; -exports[`snippet: #95 [typescript] format 1`] = ` +exports[`snippet: #94 [typescript] format 1`] = ` "'export' expected. (1:1) > 1 | default module Foo {} | ^" `; -exports[`snippet: #96 [babel-ts] format 1`] = ` +exports[`snippet: #95 [babel-ts] format 1`] = ` "Unexpected token (1:1) > 1 | default namespace Foo {} | ^" `; -exports[`snippet: #96 [typescript] format 1`] = ` +exports[`snippet: #95 [typescript] format 1`] = ` "'export' expected. (1:1) > 1 | default namespace Foo {} | ^" `; -exports[`snippet: #97 [babel-ts] format 1`] = ` +exports[`snippet: #96 [babel-ts] format 1`] = ` "Unexpected token (1:1) > 1 | in module Foo {} | ^" `; -exports[`snippet: #97 [typescript] format 1`] = ` +exports[`snippet: #96 [typescript] format 1`] = ` "Expression expected. (1:1) > 1 | in module Foo {} | ^" `; -exports[`snippet: #98 [babel-ts] format 1`] = ` +exports[`snippet: #97 [babel-ts] format 1`] = ` "Unexpected token (1:1) > 1 | in namespace Foo {} | ^" `; -exports[`snippet: #98 [typescript] format 1`] = ` +exports[`snippet: #97 [typescript] format 1`] = ` "Expression expected. (1:1) > 1 | in namespace Foo {} | ^" `; -exports[`snippet: #99 [babel-ts] format 1`] = ` +exports[`snippet: #98 [babel-ts] format 1`] = ` "Missing semicolon. (1:4) > 1 | out module Foo {} | ^" `; -exports[`snippet: #99 [typescript] format 1`] = ` +exports[`snippet: #98 [typescript] format 1`] = ` "Unexpected keyword or identifier. (1:1) > 1 | out module Foo {} | ^" `; -exports[`snippet: #100 [babel-ts] format 1`] = ` +exports[`snippet: #99 [babel-ts] format 1`] = ` "Missing semicolon. (1:4) > 1 | out namespace Foo {} | ^" `; -exports[`snippet: #100 [typescript] format 1`] = ` +exports[`snippet: #99 [typescript] format 1`] = ` "Unexpected keyword or identifier. (1:1) > 1 | out namespace Foo {} | ^" `; -exports[`snippet: #101 [babel-ts] format 1`] = ` +exports[`snippet: #100 [babel-ts] format 1`] = ` "Missing semicolon. (1:9) > 1 | override module Foo {} | ^" `; -exports[`snippet: #101 [typescript] format 1`] = ` +exports[`snippet: #100 [typescript] format 1`] = ` "Unexpected keyword or identifier. (1:1) > 1 | override module Foo {} | ^" `; -exports[`snippet: #102 [babel-ts] format 1`] = ` +exports[`snippet: #101 [babel-ts] format 1`] = ` "Missing semicolon. (1:9) > 1 | override namespace Foo {} | ^" `; -exports[`snippet: #102 [typescript] format 1`] = ` +exports[`snippet: #101 [typescript] format 1`] = ` "Unexpected keyword or identifier. (1:1) > 1 | override namespace Foo {} | ^" `; -exports[`snippet: #103 [babel-ts] format 1`] = ` +exports[`snippet: #102 [babel-ts] format 1`] = ` "Missing semicolon. (1:8) > 1 | private module Foo {} | ^" `; -exports[`snippet: #103 [typescript] format 1`] = ` +exports[`snippet: #102 [typescript] format 1`] = ` "'private' modifier cannot appear on a module or namespace element. (1:1) > 1 | private module Foo {} | ^^^^^^^" `; -exports[`snippet: #104 [babel-ts] format 1`] = ` +exports[`snippet: #103 [babel-ts] format 1`] = ` "Missing semicolon. (1:8) > 1 | private namespace Foo {} | ^" `; -exports[`snippet: #104 [typescript] format 1`] = ` +exports[`snippet: #103 [typescript] format 1`] = ` "'private' modifier cannot appear on a module or namespace element. (1:1) > 1 | private namespace Foo {} | ^^^^^^^" `; -exports[`snippet: #105 [babel-ts] format 1`] = ` +exports[`snippet: #104 [babel-ts] format 1`] = ` "Missing semicolon. (1:10) > 1 | protected module Foo {} | ^" `; -exports[`snippet: #105 [typescript] format 1`] = ` +exports[`snippet: #104 [typescript] format 1`] = ` "'protected' modifier cannot appear on a module or namespace element. (1:1) > 1 | protected module Foo {} | ^^^^^^^^^" `; -exports[`snippet: #106 [babel-ts] format 1`] = ` +exports[`snippet: #105 [babel-ts] format 1`] = ` "Missing semicolon. (1:10) > 1 | protected namespace Foo {} | ^" `; -exports[`snippet: #106 [typescript] format 1`] = ` +exports[`snippet: #105 [typescript] format 1`] = ` "'protected' modifier cannot appear on a module or namespace element. (1:1) > 1 | protected namespace Foo {} | ^^^^^^^^^" `; -exports[`snippet: #107 [babel-ts] format 1`] = ` +exports[`snippet: #106 [babel-ts] format 1`] = ` "Missing semicolon. (1:7) > 1 | public module Foo {} | ^" `; -exports[`snippet: #107 [typescript] format 1`] = ` +exports[`snippet: #106 [typescript] format 1`] = ` "'public' modifier cannot appear on a module or namespace element. (1:1) > 1 | public module Foo {} | ^^^^^^" `; -exports[`snippet: #108 [babel-ts] format 1`] = ` +exports[`snippet: #107 [babel-ts] format 1`] = ` "Missing semicolon. (1:7) > 1 | public namespace Foo {} | ^" `; -exports[`snippet: #108 [typescript] format 1`] = ` +exports[`snippet: #107 [typescript] format 1`] = ` "'public' modifier cannot appear on a module or namespace element. (1:1) > 1 | public namespace Foo {} | ^^^^^^" `; -exports[`snippet: #109 [babel-ts] format 1`] = ` +exports[`snippet: #108 [babel-ts] format 1`] = ` "Missing semicolon. (1:9) > 1 | readonly module Foo {} | ^" `; -exports[`snippet: #109 [typescript] format 1`] = ` +exports[`snippet: #108 [typescript] format 1`] = ` "'readonly' modifier can only appear on a property declaration or index signature. (1:1) > 1 | readonly module Foo {} | ^^^^^^^^" `; -exports[`snippet: #110 [babel-ts] format 1`] = ` +exports[`snippet: #109 [babel-ts] format 1`] = ` "Missing semicolon. (1:9) > 1 | readonly namespace Foo {} | ^" `; -exports[`snippet: #110 [typescript] format 1`] = ` +exports[`snippet: #109 [typescript] format 1`] = ` "'readonly' modifier can only appear on a property declaration or index signature. (1:1) > 1 | readonly namespace Foo {} | ^^^^^^^^" `; -exports[`snippet: #111 [babel-ts] format 1`] = ` +exports[`snippet: #110 [babel-ts] format 1`] = ` "Missing semicolon. (1:7) > 1 | static module Foo {} | ^" `; -exports[`snippet: #111 [typescript] format 1`] = ` +exports[`snippet: #110 [typescript] format 1`] = ` "'static' modifier cannot appear on a module or namespace element. (1:1) > 1 | static module Foo {} | ^^^^^^" `; -exports[`snippet: #112 [babel-ts] format 1`] = ` +exports[`snippet: #111 [babel-ts] format 1`] = ` "Missing semicolon. (1:7) > 1 | static namespace Foo {} | ^" `; -exports[`snippet: #112 [typescript] format 1`] = ` +exports[`snippet: #111 [typescript] format 1`] = ` "'static' modifier cannot appear on a module or namespace element. (1:1) > 1 | static namespace Foo {} | ^^^^^^" `; -exports[`snippet: #113 [babel-ts] format 1`] = ` +exports[`snippet: #112 [babel-ts] format 1`] = ` "Unexpected token, expected "class" (1:10) > 1 | abstract enum Foo {} | ^" `; -exports[`snippet: #113 [typescript] format 1`] = ` +exports[`snippet: #112 [typescript] format 1`] = ` "'abstract' modifier can only appear on a class, method, or property declaration. (1:1) > 1 | abstract enum Foo {} | ^^^^^^^^" `; -exports[`snippet: #114 [babel-ts] format 1`] = ` +exports[`snippet: #113 [babel-ts] format 1`] = ` "Missing semicolon. (1:9) > 1 | accessor enum Foo {} | ^" `; -exports[`snippet: #114 [typescript] format 1`] = ` +exports[`snippet: #113 [typescript] format 1`] = ` "'accessor' modifier can only appear on a property declaration. (1:1) > 1 | accessor enum Foo {} | ^^^^^^^^" `; -exports[`snippet: #115 [babel-ts] format 1`] = ` +exports[`snippet: #114 [babel-ts] format 1`] = ` "Missing semicolon. (1:6) > 1 | async enum Foo {} | ^" `; -exports[`snippet: #115 [typescript] format 1`] = ` +exports[`snippet: #114 [typescript] format 1`] = ` "'async' modifier cannot be used here. (1:1) > 1 | async enum Foo {} | ^^^^^" `; -exports[`snippet: #116 [babel-ts] format 1`] = ` +exports[`snippet: #115 [babel-ts] format 1`] = ` "Unexpected token (1:1) > 1 | default enum Foo {} | ^" `; -exports[`snippet: #116 [typescript] format 1`] = ` +exports[`snippet: #115 [typescript] format 1`] = ` "'export' expected. (1:1) > 1 | default enum Foo {} | ^" `; -exports[`snippet: #117 [babel-ts] format 1`] = ` +exports[`snippet: #116 [babel-ts] format 1`] = ` "Unexpected token (1:1) > 1 | in enum Foo {} | ^" `; -exports[`snippet: #117 [typescript] format 1`] = ` +exports[`snippet: #116 [typescript] format 1`] = ` "Expression expected. (1:1) > 1 | in enum Foo {} | ^" `; -exports[`snippet: #118 [babel-ts] format 1`] = ` +exports[`snippet: #117 [babel-ts] format 1`] = ` "Missing semicolon. (1:4) > 1 | out enum Foo {} | ^" `; -exports[`snippet: #118 [typescript] format 1`] = ` +exports[`snippet: #117 [typescript] format 1`] = ` "Unexpected keyword or identifier. (1:1) > 1 | out enum Foo {} | ^" `; -exports[`snippet: #119 [babel-ts] format 1`] = ` +exports[`snippet: #118 [babel-ts] format 1`] = ` "Missing semicolon. (1:9) > 1 | override enum Foo {} | ^" `; -exports[`snippet: #119 [typescript] format 1`] = ` +exports[`snippet: #118 [typescript] format 1`] = ` "Unexpected keyword or identifier. (1:1) > 1 | override enum Foo {} | ^" `; -exports[`snippet: #120 [babel-ts] format 1`] = ` +exports[`snippet: #119 [babel-ts] format 1`] = ` "Missing semicolon. (1:8) > 1 | private enum Foo {} | ^" `; -exports[`snippet: #120 [typescript] format 1`] = ` +exports[`snippet: #119 [typescript] format 1`] = ` "'private' modifier cannot appear on a module or namespace element. (1:1) > 1 | private enum Foo {} | ^^^^^^^" `; -exports[`snippet: #121 [babel-ts] format 1`] = ` +exports[`snippet: #120 [babel-ts] format 1`] = ` "Missing semicolon. (1:10) > 1 | protected enum Foo {} | ^" `; -exports[`snippet: #121 [typescript] format 1`] = ` +exports[`snippet: #120 [typescript] format 1`] = ` "'protected' modifier cannot appear on a module or namespace element. (1:1) > 1 | protected enum Foo {} | ^^^^^^^^^" `; -exports[`snippet: #122 [babel-ts] format 1`] = ` +exports[`snippet: #121 [babel-ts] format 1`] = ` "Missing semicolon. (1:7) > 1 | public enum Foo {} | ^" `; -exports[`snippet: #122 [typescript] format 1`] = ` +exports[`snippet: #121 [typescript] format 1`] = ` "'public' modifier cannot appear on a module or namespace element. (1:1) > 1 | public enum Foo {} | ^^^^^^" `; -exports[`snippet: #123 [babel-ts] format 1`] = ` +exports[`snippet: #122 [babel-ts] format 1`] = ` "Missing semicolon. (1:9) > 1 | readonly enum Foo {} | ^" `; -exports[`snippet: #123 [typescript] format 1`] = ` +exports[`snippet: #122 [typescript] format 1`] = ` "'readonly' modifier can only appear on a property declaration or index signature. (1:1) > 1 | readonly enum Foo {} | ^^^^^^^^" `; -exports[`snippet: #124 [babel-ts] format 1`] = ` +exports[`snippet: #123 [babel-ts] format 1`] = ` "Missing semicolon. (1:7) > 1 | static enum Foo {} | ^" `; -exports[`snippet: #124 [typescript] format 1`] = ` +exports[`snippet: #123 [typescript] format 1`] = ` "'static' modifier cannot appear on a module or namespace element. (1:1) > 1 | static enum Foo {} | ^^^^^^" `; -exports[`snippet: #125 [babel-ts] format 1`] = ` +exports[`snippet: #124 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:23) > 1 | function foo(abstract parameter) {} | ^" `; -exports[`snippet: #125 [typescript] format 1`] = ` +exports[`snippet: #124 [typescript] format 1`] = ` "'abstract' modifier can only appear on a class, method, or property declaration. (1:14) > 1 | function foo(abstract parameter) {} | ^^^^^^^^" `; -exports[`snippet: #126 [babel-ts] format 1`] = ` +exports[`snippet: #125 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:29) > 1 | class Foo { method(abstract parameter) {} } | ^" `; -exports[`snippet: #126 [typescript] format 1`] = ` +exports[`snippet: #125 [typescript] format 1`] = ` "'abstract' modifier can only appear on a class, method, or property declaration. (1:20) > 1 | class Foo { method(abstract parameter) {} } | ^^^^^^^^" `; -exports[`snippet: #127 [babel-ts] format 1`] = ` +exports[`snippet: #126 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:23) > 1 | function foo(accessor parameter) {} | ^" `; -exports[`snippet: #127 [typescript] format 1`] = ` +exports[`snippet: #126 [typescript] format 1`] = ` "'accessor' modifier can only appear on a property declaration. (1:14) > 1 | function foo(accessor parameter) {} | ^^^^^^^^" `; -exports[`snippet: #128 [babel-ts] format 1`] = ` +exports[`snippet: #127 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:29) > 1 | class Foo { method(accessor parameter) {} } | ^" `; -exports[`snippet: #128 [typescript] format 1`] = ` +exports[`snippet: #127 [typescript] format 1`] = ` "'accessor' modifier can only appear on a property declaration. (1:20) > 1 | class Foo { method(accessor parameter) {} } | ^^^^^^^^" `; -exports[`snippet: #129 [babel-ts] format 1`] = ` +exports[`snippet: #128 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:20) > 1 | function foo(async parameter) {} | ^" `; -exports[`snippet: #129 [typescript] format 1`] = ` +exports[`snippet: #128 [typescript] format 1`] = ` "'async' modifier cannot be used here. (1:14) > 1 | function foo(async parameter) {} | ^^^^^" `; -exports[`snippet: #130 [babel-ts] format 1`] = ` +exports[`snippet: #129 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:26) > 1 | class Foo { method(async parameter) {} } | ^" `; -exports[`snippet: #130 [typescript] format 1`] = ` +exports[`snippet: #129 [typescript] format 1`] = ` "'async' modifier cannot be used here. (1:20) > 1 | class Foo { method(async parameter) {} } | ^^^^^" `; -exports[`snippet: #131 [babel-ts] format 1`] = ` +exports[`snippet: #130 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:20) > 1 | function foo(const parameter) {} | ^" `; -exports[`snippet: #131 [typescript] format 1`] = ` +exports[`snippet: #130 [typescript] format 1`] = ` "Identifier expected. 'const' is a reserved word that cannot be used here. (1:14) > 1 | function foo(const parameter) {} | ^" `; -exports[`snippet: #132 [babel-ts] format 1`] = ` +exports[`snippet: #131 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:26) > 1 | class Foo { method(const parameter) {} } | ^" `; -exports[`snippet: #132 [typescript] format 1`] = ` +exports[`snippet: #131 [typescript] format 1`] = ` "Identifier expected. 'const' is a reserved word that cannot be used here. (1:20) > 1 | class Foo { method(const parameter) {} } | ^" `; -exports[`snippet: #133 [babel-ts] format 1`] = ` +exports[`snippet: #132 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:22) > 1 | function foo(declare parameter) {} | ^" `; -exports[`snippet: #133 [typescript] format 1`] = ` +exports[`snippet: #132 [typescript] format 1`] = ` "'declare' modifier cannot appear on a parameter. (1:14) > 1 | function foo(declare parameter) {} | ^^^^^^^" `; -exports[`snippet: #134 [babel-ts] format 1`] = ` +exports[`snippet: #133 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:28) > 1 | class Foo { method(declare parameter) {} } | ^" `; -exports[`snippet: #134 [typescript] format 1`] = ` +exports[`snippet: #133 [typescript] format 1`] = ` "'declare' modifier cannot appear on a parameter. (1:20) > 1 | class Foo { method(declare parameter) {} } | ^^^^^^^" `; -exports[`snippet: #135 [babel-ts] format 1`] = ` +exports[`snippet: #134 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:22) > 1 | function foo(default parameter) {} | ^" `; -exports[`snippet: #135 [typescript] format 1`] = ` +exports[`snippet: #134 [typescript] format 1`] = ` "Identifier expected. 'default' is a reserved word that cannot be used here. (1:14) > 1 | function foo(default parameter) {} | ^" `; -exports[`snippet: #136 [babel-ts] format 1`] = ` +exports[`snippet: #135 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:28) > 1 | class Foo { method(default parameter) {} } | ^" `; -exports[`snippet: #136 [typescript] format 1`] = ` +exports[`snippet: #135 [typescript] format 1`] = ` "Identifier expected. 'default' is a reserved word that cannot be used here. (1:20) > 1 | class Foo { method(default parameter) {} } | ^" `; -exports[`snippet: #137 [babel-ts] format 1`] = ` +exports[`snippet: #136 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:21) > 1 | function foo(export parameter) {} | ^" `; -exports[`snippet: #137 [typescript] format 1`] = ` +exports[`snippet: #136 [typescript] format 1`] = ` "'export' modifier cannot appear on a parameter. (1:14) > 1 | function foo(export parameter) {} | ^^^^^^" `; -exports[`snippet: #138 [babel-ts] format 1`] = ` +exports[`snippet: #137 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:27) > 1 | class Foo { method(export parameter) {} } | ^" `; -exports[`snippet: #138 [typescript] format 1`] = ` +exports[`snippet: #137 [typescript] format 1`] = ` "'export' modifier cannot appear on a parameter. (1:20) > 1 | class Foo { method(export parameter) {} } | ^^^^^^" `; -exports[`snippet: #139 [babel-ts] format 1`] = ` +exports[`snippet: #138 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:17) > 1 | function foo(in parameter) {} | ^" `; -exports[`snippet: #139 [typescript] format 1`] = ` +exports[`snippet: #138 [typescript] format 1`] = ` "'in' modifier can only appear on a type parameter of a class, interface or type alias (1:14) > 1 | function foo(in parameter) {} | ^^" `; -exports[`snippet: #140 [babel-ts] format 1`] = ` +exports[`snippet: #139 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:23) > 1 | class Foo { method(in parameter) {} } | ^" `; -exports[`snippet: #140 [typescript] format 1`] = ` +exports[`snippet: #139 [typescript] format 1`] = ` "'in' modifier can only appear on a type parameter of a class, interface or type alias (1:20) > 1 | class Foo { method(in parameter) {} } | ^^" `; -exports[`snippet: #141 [babel-ts] format 1`] = ` +exports[`snippet: #140 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:18) > 1 | function foo(out parameter) {} | ^" `; -exports[`snippet: #141 [typescript] format 1`] = ` +exports[`snippet: #140 [typescript] format 1`] = ` "'out' modifier can only appear on a type parameter of a class, interface or type alias (1:14) > 1 | function foo(out parameter) {} | ^^^" `; -exports[`snippet: #142 [babel-ts] format 1`] = ` +exports[`snippet: #141 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:24) > 1 | class Foo { method(out parameter) {} } | ^" `; -exports[`snippet: #142 [typescript] format 1`] = ` +exports[`snippet: #141 [typescript] format 1`] = ` "'out' modifier can only appear on a type parameter of a class, interface or type alias (1:20) > 1 | class Foo { method(out parameter) {} } | ^^^" `; -exports[`snippet: #143 [babel-ts] format 1`] = ` +exports[`snippet: #142 [babel-ts] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:14) > 1 | function foo(override parameter) {} | ^" `; -exports[`snippet: #143 [typescript] format 1`] = ` +exports[`snippet: #142 [typescript] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:14) > 1 | function foo(override parameter) {} | ^^^^^^^^" `; -exports[`snippet: #144 [babel-ts] format 1`] = ` +exports[`snippet: #143 [babel-ts] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:20) > 1 | class Foo { method(override parameter) {} } | ^" `; -exports[`snippet: #144 [typescript] format 1`] = ` +exports[`snippet: #143 [typescript] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:20) > 1 | class Foo { method(override parameter) {} } | ^^^^^^^^" `; -exports[`snippet: #145 [babel-ts] format 1`] = ` +exports[`snippet: #144 [babel-ts] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:14) > 1 | function foo(private parameter) {} | ^" `; -exports[`snippet: #145 [typescript] format 1`] = ` +exports[`snippet: #144 [typescript] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:14) > 1 | function foo(private parameter) {} | ^^^^^^^" `; -exports[`snippet: #146 [babel-ts] format 1`] = ` +exports[`snippet: #145 [babel-ts] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:20) > 1 | class Foo { method(private parameter) {} } | ^" `; -exports[`snippet: #146 [typescript] format 1`] = ` +exports[`snippet: #145 [typescript] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:20) > 1 | class Foo { method(private parameter) {} } | ^^^^^^^" `; -exports[`snippet: #147 [babel-ts] format 1`] = ` +exports[`snippet: #146 [babel-ts] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:14) > 1 | function foo(protected parameter) {} | ^" `; -exports[`snippet: #147 [typescript] format 1`] = ` +exports[`snippet: #146 [typescript] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:14) > 1 | function foo(protected parameter) {} | ^^^^^^^^^" `; -exports[`snippet: #148 [babel-ts] format 1`] = ` +exports[`snippet: #147 [babel-ts] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:20) > 1 | class Foo { method(protected parameter) {} } | ^" `; -exports[`snippet: #148 [typescript] format 1`] = ` +exports[`snippet: #147 [typescript] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:20) > 1 | class Foo { method(protected parameter) {} } | ^^^^^^^^^" `; -exports[`snippet: #149 [babel-ts] format 1`] = ` +exports[`snippet: #148 [babel-ts] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:14) > 1 | function foo(public parameter) {} | ^" `; -exports[`snippet: #149 [typescript] format 1`] = ` +exports[`snippet: #148 [typescript] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:14) > 1 | function foo(public parameter) {} | ^^^^^^" `; -exports[`snippet: #150 [babel-ts] format 1`] = ` +exports[`snippet: #149 [babel-ts] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:20) > 1 | class Foo { method(public parameter) {} } | ^" `; -exports[`snippet: #150 [typescript] format 1`] = ` +exports[`snippet: #149 [typescript] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:20) > 1 | class Foo { method(public parameter) {} } | ^^^^^^" `; -exports[`snippet: #151 [babel-ts] format 1`] = ` +exports[`snippet: #150 [babel-ts] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:14) > 1 | function foo(readonly parameter) {} | ^" `; -exports[`snippet: #151 [typescript] format 1`] = ` +exports[`snippet: #150 [typescript] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:14) > 1 | function foo(readonly parameter) {} | ^^^^^^^^" `; -exports[`snippet: #152 [babel-ts] format 1`] = ` +exports[`snippet: #151 [babel-ts] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:20) > 1 | class Foo { method(readonly parameter) {} } | ^" `; -exports[`snippet: #152 [typescript] format 1`] = ` +exports[`snippet: #151 [typescript] format 1`] = ` "A parameter property is only allowed in a constructor implementation. (1:20) > 1 | class Foo { method(readonly parameter) {} } | ^^^^^^^^" `; -exports[`snippet: #153 [babel-ts] format 1`] = ` +exports[`snippet: #152 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:21) > 1 | function foo(static parameter) {} | ^" `; -exports[`snippet: #153 [typescript] format 1`] = ` +exports[`snippet: #152 [typescript] format 1`] = ` "'static' modifier cannot appear on a parameter. (1:14) > 1 | function foo(static parameter) {} | ^^^^^^" `; -exports[`snippet: #154 [babel-ts] format 1`] = ` +exports[`snippet: #153 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:27) > 1 | class Foo { method(static parameter) {} } | ^" `; -exports[`snippet: #154 [typescript] format 1`] = ` +exports[`snippet: #153 [typescript] format 1`] = ` "'static' modifier cannot appear on a parameter. (1:20) > 1 | class Foo { method(static parameter) {} } | ^^^^^^" `; -exports[`snippet: #155 [babel-ts] format 1`] = ` +exports[`snippet: #154 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:34) > 1 | class Foo { constructor(abstract parameter) {} } | ^" `; -exports[`snippet: #155 [typescript] format 1`] = ` +exports[`snippet: #154 [typescript] format 1`] = ` "'abstract' modifier can only appear on a class, method, or property declaration. (1:25) > 1 | class Foo { constructor(abstract parameter) {} } | ^^^^^^^^" `; -exports[`snippet: #156 [babel-ts] format 1`] = ` +exports[`snippet: #155 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:34) > 1 | class Foo { constructor(accessor parameter) {} } | ^" `; -exports[`snippet: #156 [typescript] format 1`] = ` +exports[`snippet: #155 [typescript] format 1`] = ` "'accessor' modifier can only appear on a property declaration. (1:25) > 1 | class Foo { constructor(accessor parameter) {} } | ^^^^^^^^" `; -exports[`snippet: #157 [babel-ts] format 1`] = ` +exports[`snippet: #156 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:31) > 1 | class Foo { constructor(async parameter) {} } | ^" `; -exports[`snippet: #157 [typescript] format 1`] = ` +exports[`snippet: #156 [typescript] format 1`] = ` "'async' modifier cannot be used here. (1:25) > 1 | class Foo { constructor(async parameter) {} } | ^^^^^" `; -exports[`snippet: #158 [babel-ts] format 1`] = ` +exports[`snippet: #157 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:31) > 1 | class Foo { constructor(const parameter) {} } | ^" `; -exports[`snippet: #158 [typescript] format 1`] = ` +exports[`snippet: #157 [typescript] format 1`] = ` "Identifier expected. 'const' is a reserved word that cannot be used here. (1:25) > 1 | class Foo { constructor(const parameter) {} } | ^" `; -exports[`snippet: #159 [babel-ts] format 1`] = ` +exports[`snippet: #158 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:33) > 1 | class Foo { constructor(declare parameter) {} } | ^" `; -exports[`snippet: #159 [typescript] format 1`] = ` +exports[`snippet: #158 [typescript] format 1`] = ` "'declare' modifier cannot appear on a parameter. (1:25) > 1 | class Foo { constructor(declare parameter) {} } | ^^^^^^^" `; -exports[`snippet: #160 [babel-ts] format 1`] = ` +exports[`snippet: #159 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:33) > 1 | class Foo { constructor(default parameter) {} } | ^" `; -exports[`snippet: #160 [typescript] format 1`] = ` +exports[`snippet: #159 [typescript] format 1`] = ` "Identifier expected. 'default' is a reserved word that cannot be used here. (1:25) > 1 | class Foo { constructor(default parameter) {} } | ^" `; -exports[`snippet: #161 [babel-ts] format 1`] = ` +exports[`snippet: #160 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:32) > 1 | class Foo { constructor(export parameter) {} } | ^" `; -exports[`snippet: #161 [typescript] format 1`] = ` +exports[`snippet: #160 [typescript] format 1`] = ` "'export' modifier cannot appear on a parameter. (1:25) > 1 | class Foo { constructor(export parameter) {} } | ^^^^^^" `; -exports[`snippet: #162 [babel-ts] format 1`] = ` +exports[`snippet: #161 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:28) > 1 | class Foo { constructor(in parameter) {} } | ^" `; -exports[`snippet: #162 [typescript] format 1`] = ` +exports[`snippet: #161 [typescript] format 1`] = ` "'in' modifier can only appear on a type parameter of a class, interface or type alias (1:25) > 1 | class Foo { constructor(in parameter) {} } | ^^" `; -exports[`snippet: #163 [babel-ts] format 1`] = ` +exports[`snippet: #162 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:29) > 1 | class Foo { constructor(out parameter) {} } | ^" `; -exports[`snippet: #163 [typescript] format 1`] = ` +exports[`snippet: #162 [typescript] format 1`] = ` "'out' modifier can only appear on a type parameter of a class, interface or type alias (1:25) > 1 | class Foo { constructor(out parameter) {} } | ^^^" `; -exports[`snippet: #164 [babel-ts] format 1`] = ` +exports[`snippet: #163 [babel-ts] format 1`] = ` "Unexpected token, expected "," (1:32) > 1 | class Foo { constructor(static parameter) {} } | ^" `; -exports[`snippet: #164 [typescript] format 1`] = ` +exports[`snippet: #163 [typescript] format 1`] = ` "'static' modifier cannot appear on a parameter. (1:25) > 1 | class Foo { constructor(static parameter) {} } | ^^^^^^" `; -exports[`snippet: #165 [babel-ts] format 1`] = ` +exports[`snippet: #164 [babel-ts] format 1`] = ` "'abstract' modifier cannot appear on a type member. (1:13) > 1 | type Foo = {abstract bar}; | ^" `; -exports[`snippet: #165 [typescript] format 1`] = ` +exports[`snippet: #164 [typescript] format 1`] = ` "'abstract' modifier cannot appear on a type member (1:13) > 1 | type Foo = {abstract bar}; | ^^^^^^^^" `; -exports[`snippet: #166 [babel-ts] format 1`] = ` +exports[`snippet: #165 [babel-ts] format 1`] = ` "Unexpected token, expected ";" (1:22) > 1 | type Foo = {accessor bar}; | ^" `; -exports[`snippet: #166 [typescript] format 1`] = ` +exports[`snippet: #165 [typescript] format 1`] = ` "'accessor' modifier cannot appear on a type member (1:13) > 1 | type Foo = {accessor bar}; | ^^^^^^^^" `; -exports[`snippet: #167 [babel-ts] format 1`] = ` +exports[`snippet: #166 [babel-ts] format 1`] = ` "Unexpected token, expected ";" (1:19) > 1 | type Foo = {async bar}; | ^" `; -exports[`snippet: #167 [typescript] format 1`] = ` +exports[`snippet: #166 [typescript] format 1`] = ` "'async' modifier cannot appear on a type member (1:13) > 1 | type Foo = {async bar}; | ^^^^^" `; -exports[`snippet: #168 [babel-ts] format 1`] = ` +exports[`snippet: #167 [babel-ts] format 1`] = ` "Unexpected token, expected ";" (1:19) > 1 | type Foo = {const bar}; | ^" `; -exports[`snippet: #168 [typescript] format 1`] = ` +exports[`snippet: #167 [typescript] format 1`] = ` "';' expected. (1:19) > 1 | type Foo = {const bar}; | ^" `; -exports[`snippet: #169 [babel-ts] format 1`] = ` +exports[`snippet: #168 [babel-ts] format 1`] = ` "'declare' modifier cannot appear on a type member. (1:13) > 1 | type Foo = {declare bar}; | ^" `; -exports[`snippet: #169 [typescript] format 1`] = ` +exports[`snippet: #168 [typescript] format 1`] = ` "'declare' modifier cannot appear on a type member (1:13) > 1 | type Foo = {declare bar}; | ^^^^^^^" `; -exports[`snippet: #170 [babel-ts] format 1`] = ` +exports[`snippet: #169 [babel-ts] format 1`] = ` "Unexpected token, expected ";" (1:21) > 1 | type Foo = {default bar}; | ^" `; -exports[`snippet: #170 [typescript] format 1`] = ` +exports[`snippet: #169 [typescript] format 1`] = ` "';' expected. (1:21) > 1 | type Foo = {default bar}; | ^" `; -exports[`snippet: #171 [babel-ts] format 1`] = ` +exports[`snippet: #170 [babel-ts] format 1`] = ` "Unexpected token, expected ";" (1:20) > 1 | type Foo = {export bar}; | ^" `; -exports[`snippet: #171 [typescript] format 1`] = ` +exports[`snippet: #170 [typescript] format 1`] = ` "'export' modifier cannot appear on a type member (1:13) > 1 | type Foo = {export bar}; | ^^^^^^" `; -exports[`snippet: #172 [babel-ts] format 1`] = ` +exports[`snippet: #171 [babel-ts] format 1`] = ` "Unexpected token, expected ";" (1:16) > 1 | type Foo = {in bar}; | ^" `; -exports[`snippet: #172 [typescript] format 1`] = ` +exports[`snippet: #171 [typescript] format 1`] = ` "'in' modifier cannot appear on a type member (1:13) > 1 | type Foo = {in bar}; | ^^" `; -exports[`snippet: #173 [babel-ts] format 1`] = ` +exports[`snippet: #172 [babel-ts] format 1`] = ` "Unexpected token, expected ";" (1:17) > 1 | type Foo = {out bar}; | ^" `; -exports[`snippet: #173 [typescript] format 1`] = ` +exports[`snippet: #172 [typescript] format 1`] = ` "'out' modifier cannot appear on a type member (1:13) > 1 | type Foo = {out bar}; | ^^^" `; -exports[`snippet: #174 [babel-ts] format 1`] = ` +exports[`snippet: #173 [babel-ts] format 1`] = ` "'override' modifier cannot appear on a type member. (1:13) > 1 | type Foo = {override bar}; | ^" `; -exports[`snippet: #174 [typescript] format 1`] = ` +exports[`snippet: #173 [typescript] format 1`] = ` "'override' modifier cannot appear on a type member (1:13) > 1 | type Foo = {override bar}; | ^^^^^^^^" `; -exports[`snippet: #175 [babel-ts] format 1`] = ` +exports[`snippet: #174 [babel-ts] format 1`] = ` "'private' modifier cannot appear on a type member. (1:13) > 1 | type Foo = {private bar}; | ^" `; -exports[`snippet: #175 [typescript] format 1`] = ` +exports[`snippet: #174 [typescript] format 1`] = ` "'private' modifier cannot appear on a type member (1:13) > 1 | type Foo = {private bar}; | ^^^^^^^" `; -exports[`snippet: #176 [babel-ts] format 1`] = ` +exports[`snippet: #175 [babel-ts] format 1`] = ` "'protected' modifier cannot appear on a type member. (1:13) > 1 | type Foo = {protected bar}; | ^" `; -exports[`snippet: #176 [typescript] format 1`] = ` +exports[`snippet: #175 [typescript] format 1`] = ` "'protected' modifier cannot appear on a type member (1:13) > 1 | type Foo = {protected bar}; | ^^^^^^^^^" `; -exports[`snippet: #177 [babel-ts] format 1`] = ` +exports[`snippet: #176 [babel-ts] format 1`] = ` "'public' modifier cannot appear on a type member. (1:13) > 1 | type Foo = {public bar}; | ^" `; -exports[`snippet: #177 [typescript] format 1`] = ` +exports[`snippet: #176 [typescript] format 1`] = ` "'public' modifier cannot appear on a type member (1:13) > 1 | type Foo = {public bar}; | ^^^^^^" `; -exports[`snippet: #178 [babel-ts] format 1`] = ` +exports[`snippet: #177 [babel-ts] format 1`] = ` "'static' modifier cannot appear on a type member. (1:13) > 1 | type Foo = {static bar}; | ^" `; -exports[`snippet: #178 [typescript] format 1`] = ` +exports[`snippet: #177 [typescript] format 1`] = ` "'static' modifier cannot appear on a type member (1:13) > 1 | type Foo = {static bar}; | ^^^^^^" `; -exports[`snippet: #179 [babel-ts] format 1`] = ` +exports[`snippet: #178 [babel-ts] format 1`] = ` "Index signatures cannot have the 'declare' modifier. (2:3) 1 | class Foo { > 2 | declare [index: string]: number @@ -2400,7 +2388,7 @@ exports[`snippet: #179 [babel-ts] format 1`] = ` 3 | }" `; -exports[`snippet: #179 [typescript] format 1`] = ` +exports[`snippet: #178 [typescript] format 1`] = ` "'declare' modifier cannot appear on an index signature (2:3) 1 | class Foo { > 2 | declare [index: string]: number diff --git a/tests/format/misc/errors/typescript/modifiers/jsfmt.spec.js b/tests/format/misc/errors/typescript/modifiers/jsfmt.spec.js index 25151ef55c28..083812419687 100644 --- a/tests/format/misc/errors/typescript/modifiers/jsfmt.spec.js +++ b/tests/format/misc/errors/typescript/modifiers/jsfmt.spec.js @@ -47,9 +47,10 @@ run_spec( ` ), - // `TSTypeParameter`, only `in` and `out` allowed in type parameter + // `TSTypeParameter`, only `in`, `out`, and `const` allowed in type parameter ...POSSIBLE_MODIFIERS.filter( - (modifier) => modifier !== "in" && modifier !== "out" + (modifier) => + modifier !== "in" && modifier !== "out" && modifier !== "const" ).map((modifier) => `interface Foo<${modifier} T> {}`), ...["declare", "readonly"].map( From 6b6f0047d244670476c9a73bfd5b1b5b969d6813 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Feb 2023 11:00:48 +0800 Subject: [PATCH 08/15] Ignore a parse error --- .../__snapshots__/jsfmt.spec.js.snap | 30 ------------------- .../invalid-using-binding-await.js | 6 ---- 2 files changed, 36 deletions(-) delete mode 100644 tests/format/misc/errors/js/explicit-resource-management/invalid-using-binding-await.js diff --git a/tests/format/misc/errors/js/explicit-resource-management/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/js/explicit-resource-management/__snapshots__/jsfmt.spec.js.snap index 404588582d6f..a7878c4d5a2a 100644 --- a/tests/format/misc/errors/js/explicit-resource-management/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/errors/js/explicit-resource-management/__snapshots__/jsfmt.spec.js.snap @@ -84,36 +84,6 @@ exports[`invalid-for-using-binding-of-of.js [typescript] format 1`] = ` 2 |" `; -exports[`invalid-using-binding-await.js [babel] format 1`] = ` -"Can not use 'await' as identifier inside an async function. (2:12) - 1 | { -> 2 | using x, await = h(); - | ^ - 3 | } - 4 | { - 5 | for (using await of []);" -`; - -exports[`invalid-using-binding-await.js [flow] format 1`] = ` -"Unexpected identifier, expected the end of an expression statement (\`;\`) (2:9) - 1 | { -> 2 | using x, await = h(); - | ^ - 3 | } - 4 | { - 5 | for (using await of []);" -`; - -exports[`invalid-using-binding-await.js [typescript] format 1`] = ` -"Unexpected keyword or identifier. (2:3) - 1 | { -> 2 | using x, await = h(); - | ^ - 3 | } - 4 | { - 5 | for (using await of []);" -`; - exports[`invalid-using-binding-let.js [babel] format 1`] = ` "'let' is not allowed to be used as a name in 'let' or 'const' declarations. (2:9) 1 | { diff --git a/tests/format/misc/errors/js/explicit-resource-management/invalid-using-binding-await.js b/tests/format/misc/errors/js/explicit-resource-management/invalid-using-binding-await.js deleted file mode 100644 index 35d3dbadcc81..000000000000 --- a/tests/format/misc/errors/js/explicit-resource-management/invalid-using-binding-await.js +++ /dev/null @@ -1,6 +0,0 @@ -{ - using x, await = h(); -} -{ - for (using await of []); -} From 231a0e95b166312cf5326fde12f9cfe6eb6ad76c Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Feb 2023 11:05:57 +0800 Subject: [PATCH 09/15] Add changelog --- changelog_unreleased/javascript/14391.md | 3 +++ changelog_unreleased/typescript/14391-2.md | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 changelog_unreleased/javascript/14391.md create mode 100644 changelog_unreleased/typescript/14391-2.md diff --git a/changelog_unreleased/javascript/14391.md b/changelog_unreleased/javascript/14391.md new file mode 100644 index 000000000000..4049a6c02f47 --- /dev/null +++ b/changelog_unreleased/javascript/14391.md @@ -0,0 +1,3 @@ +#### Support regexp modifiers proposal (#14391 by @fisker) + +See [Regular Expression Pattern Modifiers for ECMAScript](https://github.com/tc39/proposal-regexp-modifiers). diff --git a/changelog_unreleased/typescript/14391-2.md b/changelog_unreleased/typescript/14391-2.md new file mode 100644 index 000000000000..27723f97130a --- /dev/null +++ b/changelog_unreleased/typescript/14391-2.md @@ -0,0 +1,6 @@ +#### Support TypeScript 5.0 via `babel-ts` parser (#14391 by @fisker) + +TypeScript 5.0, introduces two new syntactic features: + +- `const` modifiers for type parameters +- `export type *` declarations From ac658ef304fabece11287e8c6023a9b8348f3604 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Feb 2023 11:06:42 +0800 Subject: [PATCH 10/15] Linting --- src/language-js/print/type-parameters.js | 4 +--- tests/format/typescript/typeparams/jsfmt.spec.js | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/language-js/print/type-parameters.js b/src/language-js/print/type-parameters.js index f5891b8819c5..deacd68e5b69 100644 --- a/src/language-js/print/type-parameters.js +++ b/src/language-js/print/type-parameters.js @@ -112,9 +112,7 @@ function printDanglingCommentsForInline(path, options) { function printTypeParameter(path, options, print) { const { node, parent } = path; - const parts = [ - node.type === "TSTypeParameter" && node.const ? "const " : "" - ]; + const parts = [node.type === "TSTypeParameter" && node.const ? "const " : ""]; const name = node.type === "TSTypeParameter" ? print("name") : node.name; diff --git a/tests/format/typescript/typeparams/jsfmt.spec.js b/tests/format/typescript/typeparams/jsfmt.spec.js index 69f076cd5f85..a77412048466 100644 --- a/tests/format/typescript/typeparams/jsfmt.spec.js +++ b/tests/format/typescript/typeparams/jsfmt.spec.js @@ -1 +1 @@ -run_spec(import.meta, ["typescript"], {errors: {typescript: ["const.ts"]}}); +run_spec(import.meta, ["typescript"], { errors: { typescript: ["const.ts"] } }); From 7b052e18d563b8c771dd4bc0b0a02f47d2f56620 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Feb 2023 11:18:48 +0800 Subject: [PATCH 11/15] Error test --- src/language-js/parse/babel.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 33 +++++++++++++++++++ .../misc/errors/js/decorators/jsfmt.spec.js | 21 ++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 tests/format/misc/errors/js/decorators/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/misc/errors/js/decorators/jsfmt.spec.js diff --git a/src/language-js/parse/babel.js b/src/language-js/parse/babel.js index 6051355dac70..35c40391245b 100644 --- a/src/language-js/parse/babel.js +++ b/src/language-js/parse/babel.js @@ -37,7 +37,8 @@ const parseOptions = { "functionSent", "throwExpressions", "partialApplication", - ["decorators", { decoratorsBeforeExport: false }], + // @ts-expect-error + ["decorators", { version: "2023-01", allowCallParenthesized: true }], "importAssertions", "decimal", "moduleBlocks", diff --git a/tests/format/misc/errors/js/decorators/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/js/decorators/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..0fa3393220df --- /dev/null +++ b/tests/format/misc/errors/js/decorators/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,33 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`snippet: #0 [babel] format 1`] = ` +"Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time. (2:8) + 1 | @decorator1 +> 2 | export @decorator2 class A{} + | ^" +`; + +exports[`snippet: #1 [babel] format 1`] = ` +"Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time. (2:16) + 1 | @decorator1 +> 2 | export default @decorator2 class A{} + | ^" +`; + +exports[`snippet: #2 [babel] format 1`] = ` +"Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time. (1:20) +> 1 | @decorator1 export @decorator2 class A {} + | ^" +`; + +exports[`snippet: #3 [babel] format 1`] = ` +"Decorators can be placed *either* before or after the 'export' keyword, but not in both locations at the same time. (1:28) +> 1 | @decorator1 export default @decorator2 class A {} + | ^" +`; + +exports[`snippet: #4 [babel] format 1`] = ` +"Leading decorators must be attached to a class declaration. (1:20) +> 1 | export @decorator2 default class A {} + | ^" +`; diff --git a/tests/format/misc/errors/js/decorators/jsfmt.spec.js b/tests/format/misc/errors/js/decorators/jsfmt.spec.js new file mode 100644 index 000000000000..3de851d7c5e3 --- /dev/null +++ b/tests/format/misc/errors/js/decorators/jsfmt.spec.js @@ -0,0 +1,21 @@ +import { outdent } from "outdent"; + +run_spec( + { + importMeta: import.meta, + snippets: [ + outdent` + @decorator1 + export @decorator2 class A{} + `, + outdent` + @decorator1 + export default @decorator2 class A{} + `, + "@decorator1 export @decorator2 class A {}", + "@decorator1 export default @decorator2 class A {}", + "export @decorator2 default class A {}" + ], + }, + ["babel"] +); From c263be50216c67069cb5c4d0af57eeecc177e24f Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Feb 2023 11:23:53 +0800 Subject: [PATCH 12/15] Update options for `decorators` plugin --- src/language-js/parse/babel.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/language-js/parse/babel.js b/src/language-js/parse/babel.js index 35c40391245b..1cdf32719afe 100644 --- a/src/language-js/parse/babel.js +++ b/src/language-js/parse/babel.js @@ -37,8 +37,7 @@ const parseOptions = { "functionSent", "throwExpressions", "partialApplication", - // @ts-expect-error - ["decorators", { version: "2023-01", allowCallParenthesized: true }], + ["decorators", { allowCallParenthesized: true }], "importAssertions", "decimal", "moduleBlocks", From b348908acc3b1a005a49941b9a5afbb04c9d4848 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Feb 2023 11:26:31 +0800 Subject: [PATCH 13/15] Update options for `decorators` plugin again --- src/language-js/parse/babel.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/language-js/parse/babel.js b/src/language-js/parse/babel.js index 1cdf32719afe..8d43170e2ba2 100644 --- a/src/language-js/parse/babel.js +++ b/src/language-js/parse/babel.js @@ -37,7 +37,7 @@ const parseOptions = { "functionSent", "throwExpressions", "partialApplication", - ["decorators", { allowCallParenthesized: true }], + "decorators", "importAssertions", "decimal", "moduleBlocks", From e580397ef7016f7c78631bc139b58f86595ebd90 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Feb 2023 11:27:51 +0800 Subject: [PATCH 14/15] Linting --- tests/format/misc/errors/js/decorators/jsfmt.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/format/misc/errors/js/decorators/jsfmt.spec.js b/tests/format/misc/errors/js/decorators/jsfmt.spec.js index 3de851d7c5e3..eeb0b6627bc4 100644 --- a/tests/format/misc/errors/js/decorators/jsfmt.spec.js +++ b/tests/format/misc/errors/js/decorators/jsfmt.spec.js @@ -14,7 +14,7 @@ run_spec( `, "@decorator1 export @decorator2 class A {}", "@decorator1 export default @decorator2 class A {}", - "export @decorator2 default class A {}" + "export @decorator2 default class A {}", ], }, ["babel"] From 97aa93fbf0fb5a2ad045e2ba15b726dd14dda036 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Feb 2023 11:31:08 +0800 Subject: [PATCH 15/15] Update 14391-2.md --- changelog_unreleased/typescript/14391-2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog_unreleased/typescript/14391-2.md b/changelog_unreleased/typescript/14391-2.md index 27723f97130a..0a026fadc824 100644 --- a/changelog_unreleased/typescript/14391-2.md +++ b/changelog_unreleased/typescript/14391-2.md @@ -1,6 +1,6 @@ #### Support TypeScript 5.0 via `babel-ts` parser (#14391 by @fisker) -TypeScript 5.0, introduces two new syntactic features: +TypeScript 5.0 introduces two new syntactic features: - `const` modifiers for type parameters - `export type *` declarations