From 53f95f35005777a4b569d609cda46f0491bca6ac Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sun, 15 Aug 2021 01:16:13 +0900 Subject: [PATCH] Support hack-style pipeline (#11335) * Avoid to conflicts to v8intrinsic plugin * Support hack-style pipeline * Update tests for hask-style pipeline * Update tests 2 * Add changelog * Update misc tests * Address reviews * Fix type error * Copy plugin array * Add tests * Address review * Add error tests --- changelog_unreleased/javascript/11335.md | 20 ++ src/language-js/parse/babel.js | 16 +- src/language-js/printer-estree.js | 9 +- .../__snapshots__/jsfmt.spec.js.snap | 108 ++++--- tests/format/js/babel-plugins/jsfmt.spec.js | 4 +- .../babel-plugins/pipeline-operator-hack.js | 8 + .../babel-plugins/pipeline-operator-smart.js | 13 - .../__snapshots__/jsfmt.spec.js.snap | 264 +++++++++--------- .../hack_pipeline_operator.js | 52 ++++ .../smart_pipeline_operator.js | 52 ---- .../__snapshots__/jsfmt.spec.js.snap | 32 +++ .../avoid-conflicts-to-pipeline.js | 2 + .../__snapshots__/jsfmt.spec.js.snap | 68 +++++ .../jsfmt.spec.js | 2 +- .../errors/js/hack-pipeline/v8intrinsic.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 61 ---- 16 files changed, 382 insertions(+), 330 deletions(-) create mode 100644 changelog_unreleased/javascript/11335.md create mode 100644 tests/format/js/babel-plugins/pipeline-operator-hack.js delete mode 100644 tests/format/js/babel-plugins/pipeline-operator-smart.js create mode 100644 tests/format/js/pipeline-operator/hack_pipeline_operator.js delete mode 100644 tests/format/js/pipeline-operator/smart_pipeline_operator.js create mode 100644 tests/format/js/v8_intrinsic/avoid-conflicts-to-pipeline.js create mode 100644 tests/format/misc/errors/js/hack-pipeline/__snapshots__/jsfmt.spec.js.snap rename tests/format/misc/errors/js/{smart-pipeline => hack-pipeline}/jsfmt.spec.js (79%) create mode 100644 tests/format/misc/errors/js/hack-pipeline/v8intrinsic.js delete mode 100644 tests/format/misc/errors/js/smart-pipeline/__snapshots__/jsfmt.spec.js.snap diff --git a/changelog_unreleased/javascript/11335.md b/changelog_unreleased/javascript/11335.md new file mode 100644 index 000000000000..ee81f936e772 --- /dev/null +++ b/changelog_unreleased/javascript/11335.md @@ -0,0 +1,20 @@ +#### Support hack-style pipeline proposal (#11335 by @sosukesuzuki) + +Support new [hack-style pipeline proposal](https://github.com/js-choi/proposal-hack-pipes). We chose `%` as the topic token, following the official explainer. + +Also, [smart-style pipeline proposal](https://github.com/js-choi/proposal-smart-pipelines) is removed. See https://prettier.io/docs/en/rationale.html#disclaimer-about-non-standard-syntax for the rationale behind this decision. + +```js +// Input +const foo = fn() |> fn1(%) |> fn2(%); + +// Prettier stable +SyntaxError: Unexpected token (1:25) +> 1 | const foo = fn() |> fn1(%) |> fn2(%); + | ^ + 2 | + +// Prettier main +const foo = fn() |> fn1(%) |> fn(%); + +``` diff --git a/src/language-js/parse/babel.js b/src/language-js/parse/babel.js index 55067f6578ee..2f2fa48ae24f 100644 --- a/src/language-js/parse/babel.js +++ b/src/language-js/parse/babel.js @@ -33,7 +33,6 @@ const parseOptions = { "functionBind", "functionSent", "throwExpressions", - "v8intrinsic", "partialApplication", ["decorators", { decoratorsBeforeExport: false }], "importAssertions", @@ -49,9 +48,12 @@ const parseOptions = { /** @type {ParserPlugin} */ const recordAndTuplePlugin = ["recordAndTuple", { syntaxType: "hash" }]; +/** @type {ParserPlugin} */ +const v8intrinsicPlugin = "v8intrinsic"; + /** @type {Array} */ const pipelineOperatorPlugins = [ - ["pipelineOperator", { proposal: "smart" }], + ["pipelineOperator", { proposal: "hack", topicToken: "%" }], ["pipelineOperator", { proposal: "minimal" }], ["pipelineOperator", { proposal: "fsharp" }], ]; @@ -121,12 +123,20 @@ function createParse(parseMethod, ...optionsCombinations) { ); } + const shouldEnableV8intrinsicPlugin = /%[A-Z]/.test(text); if (text.includes("|>")) { - combinations = pipelineOperatorPlugins.flatMap((pipelineOperatorPlugin) => + const conflictsPlugins = shouldEnableV8intrinsicPlugin + ? [...pipelineOperatorPlugins, v8intrinsicPlugin] + : pipelineOperatorPlugins; + combinations = conflictsPlugins.flatMap((pipelineOperatorPlugin) => combinations.map((options) => appendPlugins([pipelineOperatorPlugin], options) ) ); + } else if (shouldEnableV8intrinsicPlugin) { + combinations = combinations.map((options) => + appendPlugins([v8intrinsicPlugin], options) + ); } const { result: ast, error } = tryCombinations( diff --git a/src/language-js/printer-estree.js b/src/language-js/printer-estree.js index 2d016cb83825..2db75d1e2d04 100644 --- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -737,12 +737,9 @@ function printPathNoParens(path, options, print, args) { return parts; - case "PipelineBareFunction": - return print("callee"); - case "PipelineTopicExpression": - return print("expression"); - case "PipelinePrimaryTopicReference": - return "#"; + // For hack-style pipeline + case "TopicReference": + return "%"; case "ArgumentPlaceholder": return "?"; 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 2f181ce7da7a..d8882499f3ad 100644 --- a/tests/format/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/babel-plugins/__snapshots__/jsfmt.spec.js.snap @@ -1612,6 +1612,54 @@ let newScore = boundScore(0, 100, add(7, double(person.score))); ================================================================================ `; +exports[`pipeline-operator-hack.js [espree] format 1`] = ` +"Unexpected token > (5:3) + 3 | + 4 | return list +> 5 | |> take(prefix.length, %) + | ^ + 6 | |> equals(%, prefix); + 7 | + 8 | // (The % token isn't final; it might instead be @ or ? or #.)" +`; + +exports[`pipeline-operator-hack.js [meriyah] format 1`] = ` +"[5:3]: Unexpected token: '>' (5:3) + 3 | + 4 | return list +> 5 | |> take(prefix.length, %) + | ^ + 6 | |> equals(%, prefix); + 7 | + 8 | // (The % token isn't final; it might instead be @ or ? or #.)" +`; + +exports[`pipeline-operator-hack.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "babel-ts", "babel-flow"] +printWidth: 80 + | printWidth +=====================================input====================================== +// https://babeljs.io/docs/en/babel-plugin-proposal-pipeline-operator +// https://github.com/js-choi/proposal-hack-pipes + +return list + |> take(prefix.length, %) + |> equals(%, prefix); + +// (The % token isn't final; it might instead be @ or ? or #.) + +=====================================output===================================== +// https://babeljs.io/docs/en/babel-plugin-proposal-pipeline-operator +// https://github.com/js-choi/proposal-hack-pipes + +return list |> take(prefix.length, %) |> equals(%, prefix); + +// (The % token isn't final; it might instead be @ or ? or #.) + +================================================================================ +`; + exports[`pipeline-operator-minimal.js [espree] format 1`] = ` "Identifier 'result' has already been declared (7:5) 5 | result //=> \\"Hello, hello!\\" @@ -1667,66 +1715,6 @@ result; //=> "Hello, hello!" ================================================================================ `; -exports[`pipeline-operator-smart.js [espree] format 1`] = ` -"Unexpected token > (5:2) - 3 | - 4 | value -> 5 | |> await # - | ^ - 6 | |> doubleSay(#, ', ') - 7 | |> capitalize // This is a function call. - 8 | |> # + '!'" -`; - -exports[`pipeline-operator-smart.js [meriyah] format 1`] = ` -"[5:2]: Unexpected token: '>' (5:2) - 3 | - 4 | value -> 5 | |> await # - | ^ - 6 | |> doubleSay(#, ', ') - 7 | |> capitalize // This is a function call. - 8 | |> # + '!'" -`; - -exports[`pipeline-operator-smart.js format 1`] = ` -====================================options===================================== -parsers: ["babel", "babel-ts", "babel-flow"] -printWidth: 80 - | printWidth -=====================================input====================================== -// https://babeljs.io/docs/en/babel-plugin-proposal-pipeline-operator -// https://github.com/js-choi/proposal-smart-pipelines - -value -|> await # -|> doubleSay(#, ', ') -|> capitalize // This is a function call. -|> # + '!' -|> new User.Message(#) -|> await # -|> console.log; // This is a method call. - -// (The # token isn't final; it might instead be @ or ? or %.) - -=====================================output===================================== -// https://babeljs.io/docs/en/babel-plugin-proposal-pipeline-operator -// https://github.com/js-choi/proposal-smart-pipelines - -value - |> await # - |> doubleSay(#, ", ") - |> capitalize // This is a function call. - |> # + "!" - |> new User.Message(#) - |> await # - |> console.log; // This is a method call. - -// (The # token isn't final; it might instead be @ or ? or %.) - -================================================================================ -`; - exports[`private-fields-in-in.js [espree] format 1`] = ` "Unexpected token #brand (44:12) 42 | diff --git a/tests/format/js/babel-plugins/jsfmt.spec.js b/tests/format/js/babel-plugins/jsfmt.spec.js index b4b9e45ac422..0dd3ad00e92f 100644 --- a/tests/format/js/babel-plugins/jsfmt.spec.js +++ b/tests/format/js/babel-plugins/jsfmt.spec.js @@ -16,7 +16,7 @@ run_spec(__dirname, ["babel", "babel-ts", "babel-flow"], { "partial-application.js", "pipeline-operator-fsharp.js", "pipeline-operator-minimal.js", - "pipeline-operator-smart.js", + "pipeline-operator-hack.js", "private-fields-in-in.js", "record-tuple-record.js", "record-tuple-tuple.js", @@ -40,7 +40,7 @@ run_spec(__dirname, ["babel", "babel-ts", "babel-flow"], { "partial-application.js", "pipeline-operator-fsharp.js", "pipeline-operator-minimal.js", - "pipeline-operator-smart.js", + "pipeline-operator-hack.js", "record-tuple-record.js", "record-tuple-tuple.js", "throw-expressions.js", diff --git a/tests/format/js/babel-plugins/pipeline-operator-hack.js b/tests/format/js/babel-plugins/pipeline-operator-hack.js new file mode 100644 index 000000000000..553e20358126 --- /dev/null +++ b/tests/format/js/babel-plugins/pipeline-operator-hack.js @@ -0,0 +1,8 @@ +// https://babeljs.io/docs/en/babel-plugin-proposal-pipeline-operator +// https://github.com/js-choi/proposal-hack-pipes + +return list + |> take(prefix.length, %) + |> equals(%, prefix); + +// (The % token isn't final; it might instead be @ or ? or #.) diff --git a/tests/format/js/babel-plugins/pipeline-operator-smart.js b/tests/format/js/babel-plugins/pipeline-operator-smart.js deleted file mode 100644 index f28849169608..000000000000 --- a/tests/format/js/babel-plugins/pipeline-operator-smart.js +++ /dev/null @@ -1,13 +0,0 @@ -// https://babeljs.io/docs/en/babel-plugin-proposal-pipeline-operator -// https://github.com/js-choi/proposal-smart-pipelines - -value -|> await # -|> doubleSay(#, ', ') -|> capitalize // This is a function call. -|> # + '!' -|> new User.Message(#) -|> await # -|> console.log; // This is a method call. - -// (The # token isn't final; it might instead be @ or ? or %.) diff --git a/tests/format/js/pipeline-operator/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/pipeline-operator/__snapshots__/jsfmt.spec.js.snap index ac20d6f79b52..8737def386c6 100644 --- a/tests/format/js/pipeline-operator/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/pipeline-operator/__snapshots__/jsfmt.spec.js.snap @@ -159,6 +159,138 @@ const f = x |> (f) => f |> f; ================================================================================ `; +exports[`hack_pipeline_operator.js [espree] format 1`] = ` +"Unexpected token > (1:4) +> 1 | a |> await % |> % * 3; + | ^ + 2 | + 3 | foo + 4 | |> await %" +`; + +exports[`hack_pipeline_operator.js [meriyah] format 1`] = ` +"[1:4]: Unexpected token: '>' (1:4) +> 1 | a |> await % |> % * 3; + | ^ + 2 | + 3 | foo + 4 | |> await %" +`; + +exports[`hack_pipeline_operator.js format 1`] = ` +====================================options===================================== +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +a |> await % |> % * 3; + +foo + |> await % + |> % || throw new Error(\`foo \${bar1}\`) + |> bar2(%, ", ") + |> bar3(%) + |> % + "!" + |> new Bar.Foo(%) + |> await bar.bar(%) + |> console.log(%); + +const result = "hello" + |> doubleSay(%) + |> capitalize(%, "foo") + |> exclaim(%); + +function createPerson (attrs) { + attrs + |> foo(%) + |> foo(%) + |> Person.insertIntoDatabase(%); +} + +const result = [1,2,3] + |> %.map(a => a * 2 ) + |> %.filter(a => a > 5) + |> %.reduce((sum, a) => a+sum, 0) + |> increment(%) + |> add(%, 3) + +const searchResults$ = fromEvent(document.querySelector('input'), 'input') + |> map(%, event => event.target.value) + |> filter(%, searchText => searchText.length > 2) + |> debounce(%, 300) + |> distinctUntilChanged(%) + |> switchMap(%, searchText => queryApi(searchText) |> retry(%, 3)) + |> share(%); + +v |> %.method() |> f(%); + +async function * f () { + return x + |> (yield %) + |> (await %) + |> y(%) + |> a.b(%) + |> (a.b(%)) + |> a.b(%) + |> (a.b?.(%)) + |> a.b?.(%); +} + +=====================================output===================================== +a |> (await %) |> % * 3; + +foo + |> (await %) + |> % || throw new Error(\`foo \${bar1}\`) + |> bar2(%, ", ") + |> bar3(%) + |> % + "!" + |> new Bar.Foo(%) + |> (await bar.bar(%)) + |> console.log(%); + +const result = "hello" |> doubleSay(%) |> capitalize(%, "foo") |> exclaim(%); + +function createPerson(attrs) { + attrs |> foo(%) |> foo(%) |> Person.insertIntoDatabase(%); +} + +const result = + [1, 2, 3] + |> %.map((a) => a * 2) + |> %.filter((a) => a > 5) + |> %.reduce((sum, a) => a + sum, 0) + |> increment(%) + |> add(%, 3); + +const searchResults$ = + fromEvent(document.querySelector("input"), "input") + |> map(%, (event) => event.target.value) + |> filter(%, (searchText) => searchText.length > 2) + |> debounce(%, 300) + |> distinctUntilChanged(%) + |> switchMap(%, (searchText) => queryApi(searchText) |> retry(%, 3)) + |> share(%); + +v |> %.method() |> f(%); + +async function* f() { + return ( + x + |> (yield %) + |> (await %) + |> y(%) + |> a.b(%) + |> a.b(%) + |> a.b(%) + |> a.b?.(%) + |> a.b?.(%) + ); +} + +================================================================================ +`; + exports[`minimal_pipeline_operator.js [espree] format 1`] = ` "Unexpected token > (1:4) > 1 | a |> b |> c; @@ -287,135 +419,3 @@ const result2 = [4, 9].map((x) => x |> inc |> double); ================================================================================ `; - -exports[`smart_pipeline_operator.js [espree] format 1`] = ` -"Unexpected token > (1:4) -> 1 | a |> await # |> # * 3; - | ^ - 2 | - 3 | foo - 4 | |> await #" -`; - -exports[`smart_pipeline_operator.js [meriyah] format 1`] = ` -"[1:4]: Unexpected token: '>' (1:4) -> 1 | a |> await # |> # * 3; - | ^ - 2 | - 3 | foo - 4 | |> await #" -`; - -exports[`smart_pipeline_operator.js format 1`] = ` -====================================options===================================== -parsers: ["babel"] -printWidth: 80 - | printWidth -=====================================input====================================== -a |> await # |> # * 3; - -foo - |> await # - |> # || throw new Error(\`foo \${bar1}\`) - |> bar2(#, ", ") - |> bar3 - |> # + "!" - |> new Bar.Foo(#) - |> await bar.bar(#) - |> console.log; - -const result = "hello" - |> doubleSay - |> capitalize(#, "foo") - |> exclaim; - -function createPerson (attrs) { - attrs - |> foo - |> foo - |> Person.insertIntoDatabase; -} - -const result = [1,2,3] - |> #.map(a => a * 2 ) - |> #.filter(a => a > 5) - |> #.reduce((sum, a) => a+sum, 0) - |> increment - |> add(#, 3) - -const searchResults$ = fromEvent(document.querySelector('input'), 'input') - |> map(#, event => event.target.value) - |> filter(#, searchText => searchText.length > 2) - |> debounce(#, 300) - |> distinctUntilChanged - |> switchMap(#, searchText => queryApi(searchText) |> retry(#, 3)) - |> share; - -v |> #.method() |> f; - -async function * f () { - return x - |> (yield #) - |> (await #) - |> y - |> a.b - |> (a.b(#)) - |> a.b(#) - |> (a.b?.(#)) - |> a.b?.(#); -} - -=====================================output===================================== -a |> await # |> # * 3; - -foo - |> await # - |> # || throw new Error(\`foo \${bar1}\`) - |> bar2(#, ", ") - |> bar3 - |> # + "!" - |> new Bar.Foo(#) - |> await bar.bar(#) - |> console.log; - -const result = "hello" |> doubleSay |> capitalize(#, "foo") |> exclaim; - -function createPerson(attrs) { - attrs |> foo |> foo |> Person.insertIntoDatabase; -} - -const result = - [1, 2, 3] - |> #.map((a) => a * 2) - |> #.filter((a) => a > 5) - |> #.reduce((sum, a) => a + sum, 0) - |> increment - |> add(#, 3); - -const searchResults$ = - fromEvent(document.querySelector("input"), "input") - |> map(#, (event) => event.target.value) - |> filter(#, (searchText) => searchText.length > 2) - |> debounce(#, 300) - |> distinctUntilChanged - |> switchMap(#, (searchText) => queryApi(searchText) |> retry(#, 3)) - |> share; - -v |> #.method() |> f; - -async function* f() { - return ( - x - |> (yield #) - |> await # - |> y - |> a.b - |> a.b(#) - |> a.b(#) - |> a.b?.(#) - |> a.b?.(#) - ); -} - -================================================================================ -`; diff --git a/tests/format/js/pipeline-operator/hack_pipeline_operator.js b/tests/format/js/pipeline-operator/hack_pipeline_operator.js new file mode 100644 index 000000000000..7a6ebc607803 --- /dev/null +++ b/tests/format/js/pipeline-operator/hack_pipeline_operator.js @@ -0,0 +1,52 @@ +a |> await % |> % * 3; + +foo + |> await % + |> % || throw new Error(`foo ${bar1}`) + |> bar2(%, ", ") + |> bar3(%) + |> % + "!" + |> new Bar.Foo(%) + |> await bar.bar(%) + |> console.log(%); + +const result = "hello" + |> doubleSay(%) + |> capitalize(%, "foo") + |> exclaim(%); + +function createPerson (attrs) { + attrs + |> foo(%) + |> foo(%) + |> Person.insertIntoDatabase(%); +} + +const result = [1,2,3] + |> %.map(a => a * 2 ) + |> %.filter(a => a > 5) + |> %.reduce((sum, a) => a+sum, 0) + |> increment(%) + |> add(%, 3) + +const searchResults$ = fromEvent(document.querySelector('input'), 'input') + |> map(%, event => event.target.value) + |> filter(%, searchText => searchText.length > 2) + |> debounce(%, 300) + |> distinctUntilChanged(%) + |> switchMap(%, searchText => queryApi(searchText) |> retry(%, 3)) + |> share(%); + +v |> %.method() |> f(%); + +async function * f () { + return x + |> (yield %) + |> (await %) + |> y(%) + |> a.b(%) + |> (a.b(%)) + |> a.b(%) + |> (a.b?.(%)) + |> a.b?.(%); +} diff --git a/tests/format/js/pipeline-operator/smart_pipeline_operator.js b/tests/format/js/pipeline-operator/smart_pipeline_operator.js deleted file mode 100644 index 47cfe5b9bc43..000000000000 --- a/tests/format/js/pipeline-operator/smart_pipeline_operator.js +++ /dev/null @@ -1,52 +0,0 @@ -a |> await # |> # * 3; - -foo - |> await # - |> # || throw new Error(`foo ${bar1}`) - |> bar2(#, ", ") - |> bar3 - |> # + "!" - |> new Bar.Foo(#) - |> await bar.bar(#) - |> console.log; - -const result = "hello" - |> doubleSay - |> capitalize(#, "foo") - |> exclaim; - -function createPerson (attrs) { - attrs - |> foo - |> foo - |> Person.insertIntoDatabase; -} - -const result = [1,2,3] - |> #.map(a => a * 2 ) - |> #.filter(a => a > 5) - |> #.reduce((sum, a) => a+sum, 0) - |> increment - |> add(#, 3) - -const searchResults$ = fromEvent(document.querySelector('input'), 'input') - |> map(#, event => event.target.value) - |> filter(#, searchText => searchText.length > 2) - |> debounce(#, 300) - |> distinctUntilChanged - |> switchMap(#, searchText => queryApi(searchText) |> retry(#, 3)) - |> share; - -v |> #.method() |> f; - -async function * f () { - return x - |> (yield #) - |> (await #) - |> y - |> a.b - |> (a.b(#)) - |> a.b(#) - |> (a.b?.(#)) - |> a.b?.(#); -} diff --git a/tests/format/js/v8_intrinsic/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/v8_intrinsic/__snapshots__/jsfmt.spec.js.snap index e9919cda5177..e9849078ca4b 100644 --- a/tests/format/js/v8_intrinsic/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/v8_intrinsic/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,37 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`avoid-conflicts-to-pipeline.js [espree] format 1`] = ` +"Unexpected token % (2:16) + 1 | // |> +> 2 | const status = %GetOptimizationStatus(fn); + | ^ + 3 |" +`; + +exports[`avoid-conflicts-to-pipeline.js [meriyah] format 1`] = ` +"[2:16]: Unexpected token: '%' (2:16) + 1 | // |> +> 2 | const status = %GetOptimizationStatus(fn); + | ^ + 3 |" +`; + +exports[`avoid-conflicts-to-pipeline.js format 1`] = ` +====================================options===================================== +parsers: ["babel"] +printWidth: 80 + | printWidth +=====================================input====================================== +// |> +const status = %GetOptimizationStatus(fn); + +=====================================output===================================== +// |> +const status = %GetOptimizationStatus(fn); + +================================================================================ +`; + exports[`intrinsic_call.js [espree] format 1`] = ` "Unexpected token % (2:13) 1 | function doSmth() { diff --git a/tests/format/js/v8_intrinsic/avoid-conflicts-to-pipeline.js b/tests/format/js/v8_intrinsic/avoid-conflicts-to-pipeline.js new file mode 100644 index 000000000000..daa5e2cf5f85 --- /dev/null +++ b/tests/format/js/v8_intrinsic/avoid-conflicts-to-pipeline.js @@ -0,0 +1,2 @@ +// |> +const status = %GetOptimizationStatus(fn); diff --git a/tests/format/misc/errors/js/hack-pipeline/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/js/hack-pipeline/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..b24df4183c40 --- /dev/null +++ b/tests/format/misc/errors/js/hack-pipeline/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,68 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`snippet: #0 [babel] format 1`] = ` +"Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:39) +> 1 | async function * a() { a |> foo(%) |> (yield y)} + | ^" +`; + +exports[`snippet: #1 [babel] format 1`] = ` +"Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:39) +> 1 | async function * a() { a |> foo(%) |> (yield)} + | ^" +`; + +exports[`snippet: #2 [babel] format 1`] = ` +"Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:39) +> 1 | async function * a() { a |> foo(%) |> (await y)} + | ^" +`; + +exports[`snippet: #3 [babel] format 1`] = ` +"Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:39) +> 1 | async function * a() { a |> foo(%) |> (a?.b)} + | ^" +`; + +exports[`snippet: #4 [babel] format 1`] = ` +"Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:39) +> 1 | async function * a() { a |> foo(%) |> a?.b} + | ^" +`; + +exports[`snippet: #5 [babel] format 1`] = ` +"Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:39) +> 1 | async function * a() { a |> foo(%) |> (a.b())} + | ^" +`; + +exports[`snippet: #6 [babel] format 1`] = ` +"Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:39) +> 1 | async function * a() { a |> foo(%) |> a.b()} + | ^" +`; + +exports[`snippet: #7 [babel] format 1`] = ` +"Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:39) +> 1 | async function * a() { a |> foo(%) |> (a.b?.())} + | ^" +`; + +exports[`snippet: #8 [babel] format 1`] = ` +"Hack-style pipe body does not contain a topic reference; Hack-style pipes must use topic at least once. (1:39) +> 1 | async function * a() { a |> foo(%) |> a.b?.()} + | ^" +`; + +exports[`snippet: #9 [babel] format 1`] = ` +"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} + | ^" +`; + +exports[`v8intrinsic.js [babel] format 1`] = ` +"Topic reference is unbound; it must be inside a pipe body. (1:16) +> 1 | const status = %GetOptimizationStatus(fn) |> console.log(%); + | ^ + 2 |" +`; diff --git a/tests/format/misc/errors/js/smart-pipeline/jsfmt.spec.js b/tests/format/misc/errors/js/hack-pipeline/jsfmt.spec.js similarity index 79% rename from tests/format/misc/errors/js/smart-pipeline/jsfmt.spec.js rename to tests/format/misc/errors/js/hack-pipeline/jsfmt.spec.js index 5a8dd0bfbf55..2f512c8f28be 100644 --- a/tests/format/misc/errors/js/smart-pipeline/jsfmt.spec.js +++ b/tests/format/misc/errors/js/hack-pipeline/jsfmt.spec.js @@ -12,7 +12,7 @@ run_spec( "(a.b?.())", "a.b?.()", "yield", - ].map((code) => `async function * a() { a |> foo(#) |> ${code}}`), + ].map((code) => `async function * a() { a |> foo(%) |> ${code}}`), }, ["babel"] ); diff --git a/tests/format/misc/errors/js/hack-pipeline/v8intrinsic.js b/tests/format/misc/errors/js/hack-pipeline/v8intrinsic.js new file mode 100644 index 000000000000..a3bd3bb45f25 --- /dev/null +++ b/tests/format/misc/errors/js/hack-pipeline/v8intrinsic.js @@ -0,0 +1 @@ +const status = %GetOptimizationStatus(fn) |> console.log(%); 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 deleted file mode 100644 index 837b6d721aaf..000000000000 --- a/tests/format/misc/errors/js/smart-pipeline/__snapshots__/jsfmt.spec.js.snap +++ /dev/null @@ -1,61 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`snippet: #0 [babel] format 1`] = ` -"Pipeline is in topic style but does not use topic reference. (1:39) -> 1 | async function * a() { a |> foo(#) |> (yield y)} - | ^" -`; - -exports[`snippet: #1 [babel] format 1`] = ` -"Pipeline is in topic style but does not use topic reference. (1:39) -> 1 | async function * a() { a |> foo(#) |> (yield)} - | ^" -`; - -exports[`snippet: #2 [babel] format 1`] = ` -"Pipeline is in topic style but does not use topic reference. (1:39) -> 1 | async function * a() { a |> foo(#) |> (await y)} - | ^" -`; - -exports[`snippet: #3 [babel] format 1`] = ` -"Pipeline is in topic style but does not use topic reference. (1:39) -> 1 | async function * a() { a |> foo(#) |> (a?.b)} - | ^" -`; - -exports[`snippet: #4 [babel] format 1`] = ` -"Pipeline is in topic style but does not use topic reference. (1:39) -> 1 | async function * a() { a |> foo(#) |> a?.b} - | ^" -`; - -exports[`snippet: #5 [babel] format 1`] = ` -"Pipeline is in topic style but does not use topic reference. (1:39) -> 1 | async function * a() { a |> foo(#) |> (a.b())} - | ^" -`; - -exports[`snippet: #6 [babel] format 1`] = ` -"Pipeline is in topic style but does not use topic reference. (1:39) -> 1 | async function * a() { a |> foo(#) |> a.b()} - | ^" -`; - -exports[`snippet: #7 [babel] format 1`] = ` -"Pipeline is in topic style but does not use topic reference. (1:39) -> 1 | async function * a() { a |> foo(#) |> (a.b?.())} - | ^" -`; - -exports[`snippet: #8 [babel] format 1`] = ` -"Pipeline is in topic style but does not use topic reference. (1:39) -> 1 | async function * a() { a |> foo(#) |> a.b?.()} - | ^" -`; - -exports[`snippet: #9 [babel] format 1`] = ` -"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} - | ^" -`;