diff --git a/changelog_unreleased/javascript/11750.md b/changelog_unreleased/javascript/11750.md index a63b9849c..e36df4ac2 100644 --- a/changelog_unreleased/javascript/11750.md +++ b/changelog_unreleased/javascript/11750.md @@ -1,4 +1,4 @@ -#### Ignore errors for non-strict mode features (#11750 by @fisker, #11778 by @sosukesuzuki) +#### Ignore errors for sloppy mode syntax (#11750 by @fisker, #11778 by @sosukesuzuki) ```jsx diff --git a/tests/format/js/sloppy-mode/__snapshots__/jsfmt.spec.js.snap b/tests/format/js/sloppy-mode/__snapshots__/jsfmt.spec.js.snap index d71b4a460..0da7ef0e8 100644 --- a/tests/format/js/sloppy-mode/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/js/sloppy-mode/__snapshots__/jsfmt.spec.js.snap @@ -59,6 +59,55 @@ function myfunc() { ================================================================================ `; +exports[`function-declaration-in-lf.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +if (false) function foo(){} + +=====================================output===================================== +if (false) function foo() {} + +================================================================================ +`; + +exports[`function-declaration-in-while.js [espree] format 1`] = ` +"Unexpected token function (1:15) +> 1 | while (false) function foo(){} + | ^ + 2 |" +`; + +exports[`function-declaration-in-while.js [flow] format 1`] = ` +"In non-strict mode code, functions can only be declared at top level, inside a block, or as the body of an if statement. (1:15) +> 1 | while (false) function foo(){} + | ^^^^^^^^^^^^^^^^ + 2 |" +`; + +exports[`function-declaration-in-while.js [meriyah] format 1`] = ` +"[1:22]: In strict mode code, functions can only be declared at top level or inside a block (1:22) +> 1 | while (false) function foo(){} + | ^ + 2 |" +`; + +exports[`function-declaration-in-while.js format 1`] = ` +====================================options===================================== +parsers: ["babel", "flow", "typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +while (false) function foo(){} + +=====================================output===================================== +while (false) function foo() {} + +================================================================================ +`; + exports[`labeled-function-declaration.js format 1`] = ` ====================================options===================================== parsers: ["babel", "flow", "typescript"] diff --git a/tests/format/js/sloppy-mode/function-declaration-in-lf.js b/tests/format/js/sloppy-mode/function-declaration-in-lf.js new file mode 100644 index 000000000..86b863d3e --- /dev/null +++ b/tests/format/js/sloppy-mode/function-declaration-in-lf.js @@ -0,0 +1 @@ +if (false) function foo(){} diff --git a/tests/format/js/sloppy-mode/function-declaration-in-while.js b/tests/format/js/sloppy-mode/function-declaration-in-while.js new file mode 100644 index 000000000..ce577f802 --- /dev/null +++ b/tests/format/js/sloppy-mode/function-declaration-in-while.js @@ -0,0 +1 @@ +while (false) function foo(){} diff --git a/tests/format/js/sloppy-mode/jsfmt.spec.js b/tests/format/js/sloppy-mode/jsfmt.spec.js index eb85eda6b..687600bb8 100644 --- a/tests/format/js/sloppy-mode/jsfmt.spec.js +++ b/tests/format/js/sloppy-mode/jsfmt.spec.js @@ -1 +1,7 @@ -run_spec(__dirname, ["babel", "flow", "typescript"]); +run_spec(__dirname, ["babel", "flow", "typescript"], { + errors: { + flow: ["function-declaration-in-while.js"], + espree: ["function-declaration-in-while.js"], + meriyah: ["function-declaration-in-while.js"], + }, +});