diff --git a/package.json b/package.json index 29e657cbf..7634ff71e 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "dependencies": { "@angular/compiler": "12.1.4", "@babel/code-frame": "7.14.5", - "@babel/parser": "7.14.8", + "@babel/parser": "7.15.0", "@glimmer/syntax": "0.80.0", "@iarna/toml": "2.2.5", "@typescript-eslint/typescript-estree": "4.28.5", diff --git a/src/language-js/parse/babel.js b/src/language-js/parse/babel.js index b2221f39a..59b8d8df9 100644 --- a/src/language-js/parse/babel.js +++ b/src/language-js/parse/babel.js @@ -12,7 +12,6 @@ const jsonParsers = require("./json.js"); const parseOptions = { sourceType: "module", - allowAwaitOutsideFunction: true, allowImportExportEverywhere: true, allowReturnOutsideFunction: true, allowSuperOutsideMethod: true, @@ -30,9 +29,7 @@ const parseOptions = { "v8intrinsic", "partialApplication", ["decorators", { decoratorsBeforeExport: false }], - "privateIn", "importAssertions", - ["recordAndTuple", { syntaxType: "hash" }], "decimal", "classStaticBlock", "moduleBlocks", @@ -41,14 +38,15 @@ const parseOptions = { tokens: true, ranges: true, }; +const recordAndTuplePlugin = ["recordAndTuple", { syntaxType: "hash" }]; const pipelineOperatorPlugins = [ ["pipelineOperator", { proposal: "smart" }], ["pipelineOperator", { proposal: "minimal" }], ["pipelineOperator", { proposal: "fsharp" }], ]; -const appendPlugins = (plugins) => ({ - ...parseOptions, - plugins: [...parseOptions.plugins, ...plugins], +const appendPlugins = (plugins, options = parseOptions) => ({ + ...options, + plugins: [...options.plugins, ...plugins], }); // Similar to babel @@ -107,12 +105,17 @@ function createParse(parseMethod, ...optionsCombinations) { })); } + if (text.includes("#{") || text.includes("#[")) { + combinations = combinations.map((options) => + appendPlugins([recordAndTuplePlugin], options) + ); + } + if (text.includes("|>")) { combinations = pipelineOperatorPlugins.flatMap((pipelineOperatorPlugin) => - combinations.map((options) => ({ - ...options, - plugins: [...options.plugins, pipelineOperatorPlugin], - })) + combinations.map((options) => + appendPlugins([pipelineOperatorPlugin], options) + ) ); } diff --git a/tests/format/misc/errors/js/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/js/__snapshots__/jsfmt.spec.js.snap index 25604bc3c..e63c49c23 100644 --- a/tests/format/misc/errors/js/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/errors/js/__snapshots__/jsfmt.spec.js.snap @@ -126,9 +126,9 @@ exports[`snippet: #8 [babel] format 1`] = ` `; exports[`snippet: #9 [babel] format 1`] = ` -"Tuple expressions starting with '[|' are only allowed when the 'syntaxType' option of the 'recordAndTuple' plugin is set to 'bar'. (1:1) +"Unexpected token (1:2) > 1 | [| 1 |] - | ^" + | ^" `; exports[`snippet: #10 [babel] format 1`] = ` diff --git a/tests/format/misc/errors/js/smart-pipeline/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/js/smart-pipeline/__snapshots__/jsfmt.spec.js.snap index 511af6d84..837b6d721 100644 --- a/tests/format/misc/errors/js/smart-pipeline/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/errors/js/smart-pipeline/__snapshots__/jsfmt.spec.js.snap @@ -55,7 +55,7 @@ exports[`snippet: #8 [babel] format 1`] = ` `; exports[`snippet: #9 [babel] format 1`] = ` -"Can not use 'yield' as identifier inside a generator. (1:39) +"Unexpected yield after pipeline body; any yield expression acting as Hack-style pipe body must be parenthesized due to its loose operator precedence. (1:39) > 1 | async function * a() { a |> foo(#) |> yield} | ^" `; diff --git a/tests/format/typescript/custom/abstract/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/custom/abstract/__snapshots__/jsfmt.spec.js.snap index 6537e2311..3a32bd484 100644 --- a/tests/format/typescript/custom/abstract/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/custom/abstract/__snapshots__/jsfmt.spec.js.snap @@ -87,6 +87,16 @@ abstract class Foo { ================================================================================ `; +exports[`abstractPropertiesWithBreaks.ts [babel-ts] format 1`] = ` +"Property 'foobar' cannot have an initializer because it is marked abstract. (2:29) + 1 | abstract class Foo { +> 2 | abstract private foobar = + | ^ + 3 | // comment to break + 4 | 1 + + 5 | // another comment to break" +`; + exports[`abstractPropertiesWithBreaks.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/format/typescript/custom/abstract/jsfmt.spec.js b/tests/format/typescript/custom/abstract/jsfmt.spec.js index f261adac9..76de64b5b 100644 --- a/tests/format/typescript/custom/abstract/jsfmt.spec.js +++ b/tests/format/typescript/custom/abstract/jsfmt.spec.js @@ -1,5 +1,5 @@ run_spec(__dirname, ["typescript"], { errors: { - "babel-ts": ["abstractProperties.ts"], + "babel-ts": ["abstractProperties.ts", "abstractPropertiesWithBreaks.ts"], }, }); diff --git a/tests/format/typescript/namespace/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/namespace/__snapshots__/jsfmt.spec.js.snap index 83c1f7ab6..4138f8288 100644 --- a/tests/format/typescript/namespace/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/namespace/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,14 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`invalid-await.ts [babel-ts] format 1`] = ` +"'await' is only allowed within async functions and at the top levels of modules. (2:13) + 1 | namespace N { +> 2 | const x = await 42; + | ^ + 3 | } + 4 |" +`; + exports[`invalid-await.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] diff --git a/tests/format/typescript/namespace/jsfmt.spec.js b/tests/format/typescript/namespace/jsfmt.spec.js index 2ea3bb6eb..4c48f7a81 100644 --- a/tests/format/typescript/namespace/jsfmt.spec.js +++ b/tests/format/typescript/namespace/jsfmt.spec.js @@ -1 +1 @@ -run_spec(__dirname, ["typescript"]); +run_spec(__dirname, ["typescript"], { errors: { "babel-ts": true } }); diff --git a/yarn.lock b/yarn.lock index 2d6be8896..2ba0dba10 100644 --- a/yarn.lock +++ b/yarn.lock @@ -288,7 +288,12 @@ chalk "^2.0.0" js-tokens "^4.0.0" -"@babel/parser@7.14.8", "@babel/parser@^7.1.0", "@babel/parser@^7.14.5", "@babel/parser@^7.14.8", "@babel/parser@^7.7.2": +"@babel/parser@7.15.0": + version "7.15.0" + resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.15.0.tgz#b6d6e29058ca369127b0eeca2a1c4b5794f1b6b9" + integrity sha512-0v7oNOjr6YT9Z2RAOTv4T9aP+ubfx4Q/OhVtAet7PFDt0t9Oy6Jn+/rfC6b8HJ5zEqrQCiMxJfgtHpmIminmJQ== + +"@babel/parser@^7.1.0", "@babel/parser@^7.14.5", "@babel/parser@^7.14.8", "@babel/parser@^7.7.2": version "7.14.8" resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.14.8.tgz#66fd41666b2d7b840bd5ace7f7416d5ac60208d4" integrity sha512-syoCQFOoo/fzkWDeM0dLEZi5xqurb5vuyzwIMNZRNun+N/9A4cUZeQaE7dTrB8jGaKuJRBtEOajtnmw0I5hvvA==