From afc0a6b5fae11c86c18bbc345775821607d4d41d Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sun, 14 Jan 2024 12:09:15 +0900 Subject: [PATCH 01/17] Bump Prettier dependency to 3.2.2 --- package.json | 4 ++-- yarn.lock | 13 ++----------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index b2c5778acd47..200c07c100d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "prettier", - "version": "3.2.2", + "version": "3.3.0-dev", "description": "Prettier is an opinionated code formatter", "bin": "./bin/prettier.cjs", "repository": "prettier/prettier", @@ -147,7 +147,7 @@ "jest-watch-typeahead": "2.2.2", "magic-string": "0.30.5", "npm-run-all2": "6.1.1", - "prettier": "3.2.1", + "prettier": "3.2.2", "pretty-bytes": "6.1.1", "rollup-plugin-license": "3.2.0", "semver": "7.5.4", diff --git a/yarn.lock b/yarn.lock index 53222fc0f3f9..8f4154cae4dc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7317,16 +7317,7 @@ __metadata: languageName: node linkType: hard -"prettier@npm:3.2.1": - version: 3.2.1 - resolution: "prettier@npm:3.2.1" - bin: - prettier: bin/prettier.cjs - checksum: a26d26a74ba5cbf23a9741074ceef4f53a08ced03c42449dc9615ecd08ada9d19d5247ad2b0dfb15b2c8e57ec9f516074627b85b9f03270b08c184c64e7d8f64 - languageName: node - linkType: hard - -"prettier@workspace:.": +"prettier@npm:3.2.2, prettier@workspace:.": version: 0.0.0-use.local resolution: "prettier@workspace:." dependencies: @@ -7431,7 +7422,7 @@ __metadata: postcss-scss: "npm:4.0.9" postcss-selector-parser: "npm:2.2.3" postcss-values-parser: "npm:2.0.1" - prettier: "npm:3.2.1" + prettier: "npm:3.2.2" pretty-bytes: "npm:6.1.1" regexp-util: "npm:2.0.0" remark-footnotes: "npm:2.0.0" From 513dd0b7cc229434ef3d020d47f3fb516f07ab79 Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sun, 14 Jan 2024 12:09:15 +0900 Subject: [PATCH 02/17] Git blame ignore 3.2.2 --- .git-blame-ignore-revs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 7bf46148bb93..e211da2bfd44 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -5,6 +5,8 @@ # See https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-fileltfilegt # Prettier bump after release +# 3.2.2 +afc0a6b5fae11c86c18bbc345775821607d4d41d # 3.2.1 5811ad00705488365e0d0baf50c92965edddf58e # 3.2.0 From d3be642d3f82ee2ff4b533ed0355298a0a90d0ba Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sun, 14 Jan 2024 12:09:17 +0900 Subject: [PATCH 03/17] Clean changelog_unreleased --- changelog_unreleased/javascript/15896.md | 8 -------- changelog_unreleased/javascript/15920.md | 13 ------------- 2 files changed, 21 deletions(-) delete mode 100644 changelog_unreleased/javascript/15896.md delete mode 100644 changelog_unreleased/javascript/15920.md diff --git a/changelog_unreleased/javascript/15896.md b/changelog_unreleased/javascript/15896.md deleted file mode 100644 index 1ae1ed20c121..000000000000 --- a/changelog_unreleased/javascript/15896.md +++ /dev/null @@ -1,8 +0,0 @@ -#### Fix crash when parsing template literal CSS in a JSX style tag using a spread attribute (#15896 by @eelco) - -For example this code would crash before: - - -```jsx - -``` diff --git a/changelog_unreleased/javascript/15920.md b/changelog_unreleased/javascript/15920.md deleted file mode 100644 index b802807c5f1d..000000000000 --- a/changelog_unreleased/javascript/15920.md +++ /dev/null @@ -1,13 +0,0 @@ -#### Fix formatting error on optional call expression and member chain (#15920 by @sosukesuzuki) - - -```jsx -// Input -a(() => {}, c?.d()); - -// Prettier stable -TypeError: Cannot read properties of undefined (reading 'type') - -// Prettier main -a(() => {}, c?.d()); -``` From 56f5f4c736f35506e8a256131df2cb50d87391ab Mon Sep 17 00:00:00 2001 From: Sosuke Suzuki Date: Sun, 14 Jan 2024 13:02:29 +0900 Subject: [PATCH 04/17] Run `yarn` --- yarn.lock | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index 8f4154cae4dc..20b79f6455eb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7317,7 +7317,16 @@ __metadata: languageName: node linkType: hard -"prettier@npm:3.2.2, prettier@workspace:.": +"prettier@npm:3.2.2": + version: 3.2.2 + resolution: "prettier@npm:3.2.2" + bin: + prettier: bin/prettier.cjs + checksum: ab9470ff6cfd19f28bc424f22e58f2fc4a488d148b9384f6c3739235017c8350cae82b3697392c23d9b098b9d8dfaa1cc9ff4ef25fd45f54c97b95f9cc7a1f7d + languageName: node + linkType: hard + +"prettier@workspace:.": version: 0.0.0-use.local resolution: "prettier@workspace:." dependencies: From ff83d55d05e92ceef10ec0cb1c0272ab894a00a0 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Sun, 14 Jan 2024 18:03:16 +0800 Subject: [PATCH 05/17] Update documentation for `prettier.resolveConfig()` (#15910) --- docs/api.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api.md b/docs/api.md index 5d49e8e32e86..47be4ec4e803 100644 --- a/docs/api.md +++ b/docs/api.md @@ -35,7 +35,7 @@ await prettier.formatWithCursor(" 1", { cursorOffset: 2, parser: "babel" }); ## `prettier.resolveConfig(fileUrlOrPath [, options])` -`resolveConfig` can be used to resolve configuration for a given source file, passing its path or url as the first argument. The config search will start at the file location and continue to search up the directory (you can use `process.cwd()` to start searching from the current directory). Or you can pass directly the path of the config file as `options.config` if you don’t wish to search for it. A promise is returned which will resolve to: +`resolveConfig` can be used to resolve configuration for a given source file, passing its path or url as the first argument. The config search will start at the directory of the file location and continue to search up the directory. Or you can pass directly the path of the config file as `options.config` if you don’t wish to search for it. A promise is returned which will resolve to: - An options object, providing a [config file](configuration.md) was found. - `null`, if no file was found. From b4ed91bffb0a9140259f4190b77cce1b77284ca0 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Mon, 15 Jan 2024 14:42:44 +0800 Subject: [PATCH 06/17] chore(deps): update typescript-eslint to v6.18.1 (#15881) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: fisker --- changelog_unreleased/typescript/15881.md | 30 +++ cspell.json | 15 +- package.json | 6 +- .../__snapshots__/jsfmt.spec.js.snap | 23 ++ .../catch-clause-with-initializer.ts | 4 + .../jsfmt.spec.js | 1 + .../__snapshots__/jsfmt.spec.js.snap | 253 ++++++++++++++++++ .../jsfmt.spec.js | 33 +++ .../compiler/__snapshots__/jsfmt.spec.js.snap | 56 ---- .../decrementAndIncrementOperators.ts | 22 -- .../format/typescript/compiler/jsfmt.spec.js | 6 +- .../__snapshots__/jsfmt.spec.js.snap | 45 ++++ .../update-expression/jsfmt.spec.js | 1 + .../update-expression/update-expressions.ts | 16 ++ yarn.lock | 90 +++---- 15 files changed, 456 insertions(+), 145 deletions(-) create mode 100644 changelog_unreleased/typescript/15881.md create mode 100644 tests/format/misc/errors/typescript/catch-clause-with-initializer/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/misc/errors/typescript/catch-clause-with-initializer/catch-clause-with-initializer.ts create mode 100644 tests/format/misc/errors/typescript/catch-clause-with-initializer/jsfmt.spec.js create mode 100644 tests/format/misc/errors/typescript/decrement-and-increment-operators/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/misc/errors/typescript/decrement-and-increment-operators/jsfmt.spec.js create mode 100644 tests/format/typescript/update-expression/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/typescript/update-expression/jsfmt.spec.js create mode 100644 tests/format/typescript/update-expression/update-expressions.ts diff --git a/changelog_unreleased/typescript/15881.md b/changelog_unreleased/typescript/15881.md new file mode 100644 index 000000000000..ad68ab7619cf --- /dev/null +++ b/changelog_unreleased/typescript/15881.md @@ -0,0 +1,30 @@ +#### Throw errors for invalid code (#15881 by @fisker, @Josh-Cena, @auvred) + + +```ts +// Input +1++; + +// Prettier stable +1++; + +// Prettier main +SyntaxError: Invalid left-hand side expression in unary operation (1:1) +> 1 | 1++; + | ^ +``` + + +```ts +// Input +try {} catch (error = 1){} + +// Prettier stable +try { +} catch (error) {} + +// Prettier main +SyntaxError: Catch clause variable cannot have an initializer. (1:23) +> 1 | try {} catch (error = 1){} + | ^ +``` diff --git a/cspell.json b/cspell.json index 93da3c59ae59..9b1bcc420f20 100644 --- a/cspell.json +++ b/cspell.json @@ -50,7 +50,6 @@ "cliify", "cmds", "codebases", - "Codecov", "codemirror", "codemod", "codemods", @@ -80,10 +79,8 @@ "Dolzhykov", "Doshi", "dotfile", - "dotfiles", "duailibe", "Duperron", - "eastasianwidth", "Eemeli", "ekkhus", "elektronik", @@ -96,7 +93,6 @@ "eslump", "espree", "esproposal", - "estree", "execa", "Fabio", "fabiospampinato", @@ -107,14 +103,12 @@ "Filipe", "Fiorini", "Fisker", - "fizzbuzz", "flamegraph", "foldgutter", "formatprg", "Friedly", "frobble", "ftest", - "fuzzer", "Georgii", "gettin", "githook", @@ -171,14 +165,11 @@ "Kasturi", "kddnewton", "Kearney", - "keyframes", "keyof", "Khatri", "Konstantin", "l’objectif", - "lcov", "libdef", - "lilconfig", "linebreak", "linebreaks", "lintstaged", @@ -271,7 +262,6 @@ "Rects", "Redeclaration", "refmt", - "regexes", "rhengles", "Rubocop", "ruleset", @@ -303,7 +293,6 @@ "starturl", "stylefmt", "styleguides", - "stylelint", "stylelintrc", "Stylesheet", "subal", @@ -343,7 +332,6 @@ "unparenthesized", "unparseable", "Unrestrict", - "unstaged", "upvoted", "upvotes", "valourous", @@ -361,7 +349,6 @@ "webcompat", "webstorm", "Weixin", - "whitespaces", "withastro", "wxss", "xdescribe", @@ -374,7 +361,7 @@ "ignoreRegExpList": [ "\\n(`{3,})\\w*\\n[\\s\\S]+?\\1", "\\[(\\*{2})?@[-\\w]+?\\1\\]", - "by @[-\\w]+(?:, @[-\\w]+)?", + "by @[-\\w]+(?:, @[-\\w]+)*", "ve{2,}r{2,}y", "ve+r+y+long\\w*", "\\(https?://.*?\\)", diff --git a/package.json b/package.json index 200c07c100d8..a9a853826138 100644 --- a/package.json +++ b/package.json @@ -38,8 +38,8 @@ "@iarna/toml": "2.2.5", "@prettier/is-es5-identifier-name": "0.2.0", "@prettier/parse-srcset": "3.1.0", - "@typescript-eslint/typescript-estree": "6.17.0", - "@typescript-eslint/visitor-keys": "6.17.0", + "@typescript-eslint/typescript-estree": "6.18.1", + "@typescript-eslint/visitor-keys": "6.18.1", "acorn": "8.11.3", "acorn-jsx": "5.3.2", "angular-estree-parser": "9.0.0", @@ -116,7 +116,7 @@ "@types/file-entry-cache": "5.0.4", "@types/find-cache-dir": "3.2.1", "@types/jest": "29.5.8", - "@typescript-eslint/eslint-plugin": "6.17.0", + "@typescript-eslint/eslint-plugin": "6.18.1", "benchmark": "2.1.4", "browserslist": "4.22.2", "browserslist-to-esbuild": "2.1.0", diff --git a/tests/format/misc/errors/typescript/catch-clause-with-initializer/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/typescript/catch-clause-with-initializer/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..238793edec40 --- /dev/null +++ b/tests/format/misc/errors/typescript/catch-clause-with-initializer/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,23 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`catch-clause-with-initializer.ts [babel-ts] format 1`] = ` +"Unexpected token, expected ")" (3:10) + 1 | try { + 2 | } +> 3 | catch (e = 1) { + | ^ + 4 | } + 5 | +Cause: Unexpected token, expected ")" (3:9)" +`; + +exports[`catch-clause-with-initializer.ts [typescript] format 1`] = ` +"Catch clause variable cannot have an initializer. (3:12) + 1 | try { + 2 | } +> 3 | catch (e = 1) { + | ^ + 4 | } + 5 | +Cause: Catch clause variable cannot have an initializer." +`; diff --git a/tests/format/misc/errors/typescript/catch-clause-with-initializer/catch-clause-with-initializer.ts b/tests/format/misc/errors/typescript/catch-clause-with-initializer/catch-clause-with-initializer.ts new file mode 100644 index 000000000000..c323632adfe1 --- /dev/null +++ b/tests/format/misc/errors/typescript/catch-clause-with-initializer/catch-clause-with-initializer.ts @@ -0,0 +1,4 @@ +try { +} +catch (e = 1) { +} diff --git a/tests/format/misc/errors/typescript/catch-clause-with-initializer/jsfmt.spec.js b/tests/format/misc/errors/typescript/catch-clause-with-initializer/jsfmt.spec.js new file mode 100644 index 000000000000..d6e90943d2fc --- /dev/null +++ b/tests/format/misc/errors/typescript/catch-clause-with-initializer/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(import.meta, ["babel-ts", "typescript"]); diff --git a/tests/format/misc/errors/typescript/decrement-and-increment-operators/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/typescript/decrement-and-increment-operators/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..3490a208132a --- /dev/null +++ b/tests/format/misc/errors/typescript/decrement-and-increment-operators/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,253 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`snippet: #0 [babel-ts] format 1`] = ` +"Invalid left-hand side in postfix operation. (1:1) +> 1 | 1 ++ + | ^ +Cause: Invalid left-hand side in postfix operation. (1:0)" +`; + +exports[`snippet: #0 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:1) +> 1 | 1 ++ + | ^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #1 [babel-ts] format 1`] = ` +"Invalid left-hand side in postfix operation. (1:2) +> 1 | (1)++ + | ^ +Cause: Invalid left-hand side in postfix operation. (1:1)" +`; + +exports[`snippet: #1 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:1) +> 1 | (1)++ + | ^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #2 [babel-ts] format 1`] = ` +"Invalid left-hand side in postfix operation. (1:2) +> 1 | (1)-- + | ^ +Cause: Invalid left-hand side in postfix operation. (1:1)" +`; + +exports[`snippet: #2 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:1) +> 1 | (1)-- + | ^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #3 [babel-ts] format 1`] = ` +"Invalid left-hand side in prefix operation. (1:4) +> 1 | ++(1) + | ^ +Cause: Invalid left-hand side in prefix operation. (1:3)" +`; + +exports[`snippet: #3 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:3) +> 1 | ++(1) + | ^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #4 [babel-ts] format 1`] = ` +"Invalid left-hand side in prefix operation. (1:4) +> 1 | --(1) + | ^ +Cause: Invalid left-hand side in prefix operation. (1:3)" +`; + +exports[`snippet: #4 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:3) +> 1 | --(1) + | ^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #5 [babel-ts] format 1`] = ` +"Invalid left-hand side in postfix operation. (1:2) +> 1 | (1 + 2)++ + | ^ +Cause: Invalid left-hand side in postfix operation. (1:1)" +`; + +exports[`snippet: #5 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:1) +> 1 | (1 + 2)++ + | ^^^^^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #6 [babel-ts] format 1`] = ` +"Invalid left-hand side in postfix operation. (1:2) +> 1 | (1 + 2)-- + | ^ +Cause: Invalid left-hand side in postfix operation. (1:1)" +`; + +exports[`snippet: #6 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:1) +> 1 | (1 + 2)-- + | ^^^^^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #7 [babel-ts] format 1`] = ` +"Invalid left-hand side in prefix operation. (1:4) +> 1 | ++(1 + 2) + | ^ +Cause: Invalid left-hand side in prefix operation. (1:3)" +`; + +exports[`snippet: #7 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:3) +> 1 | ++(1 + 2) + | ^^^^^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #8 [babel-ts] format 1`] = ` +"Invalid left-hand side in prefix operation. (1:4) +> 1 | --(1 + 2) + | ^ +Cause: Invalid left-hand side in prefix operation. (1:3)" +`; + +exports[`snippet: #8 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:3) +> 1 | --(1 + 2) + | ^^^^^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #9 [babel-ts] format 1`] = ` +"Invalid left-hand side in postfix operation. (1:2) +> 1 | (x + x)++ + | ^ +Cause: Invalid left-hand side in postfix operation. (1:1)" +`; + +exports[`snippet: #9 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:1) +> 1 | (x + x)++ + | ^^^^^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #10 [babel-ts] format 1`] = ` +"Invalid left-hand side in postfix operation. (1:2) +> 1 | (x + x)-- + | ^ +Cause: Invalid left-hand side in postfix operation. (1:1)" +`; + +exports[`snippet: #10 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:1) +> 1 | (x + x)-- + | ^^^^^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #11 [babel-ts] format 1`] = ` +"Invalid left-hand side in prefix operation. (1:4) +> 1 | ++(x + x) + | ^ +Cause: Invalid left-hand side in prefix operation. (1:3)" +`; + +exports[`snippet: #11 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:3) +> 1 | ++(x + x) + | ^^^^^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #12 [babel-ts] format 1`] = ` +"Invalid left-hand side in prefix operation. (1:4) +> 1 | --(x + x) + | ^ +Cause: Invalid left-hand side in prefix operation. (1:3)" +`; + +exports[`snippet: #12 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:3) +> 1 | --(x + x) + | ^^^^^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #13 [babel-ts] format 1`] = ` +"Invalid left-hand side in postfix operation. (1:1) +> 1 | a()++ + | ^ +Cause: Invalid left-hand side in postfix operation. (1:0)" +`; + +exports[`snippet: #13 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:1) +> 1 | a()++ + | ^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #14 [babel-ts] format 1`] = ` +"Invalid optional chaining in the left-hand side of postfix operation. (1:1) +> 1 | x?.y++ + | ^ +Cause: Invalid optional chaining in the left-hand side of postfix operation. (1:0)" +`; + +exports[`snippet: #14 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:1) +> 1 | x?.y++ + | ^^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #15 [babel-ts] format 1`] = ` +"Invalid optional chaining in the left-hand side of postfix operation. (1:1) +> 1 | x?.y.z++ + | ^ +Cause: Invalid optional chaining in the left-hand side of postfix operation. (1:0)" +`; + +exports[`snippet: #15 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:1) +> 1 | x?.y.z++ + | ^^^^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #16 [babel-ts] format 1`] = ` +"Invalid optional chaining in the left-hand side of postfix operation. (1:1) +> 1 | x?.y().z++ + | ^ +Cause: Invalid optional chaining in the left-hand side of postfix operation. (1:0)" +`; + +exports[`snippet: #16 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:1) +> 1 | x?.y().z++ + | ^^^^^^^^ +Cause: Invalid left-hand side expression in unary operation" +`; + +exports[`snippet: #17 [babel-ts] format 1`] = ` +"Invalid left-hand side in postfix operation. (1:2) +> 1 | (a())++ + | ^ +Cause: Invalid left-hand side in postfix operation. (1:1)" +`; + +exports[`snippet: #17 [typescript] format 1`] = ` +"Invalid left-hand side expression in unary operation (1:1) +> 1 | (a())++ + | ^^^^^ +Cause: Invalid left-hand side expression in unary operation" +`; diff --git a/tests/format/misc/errors/typescript/decrement-and-increment-operators/jsfmt.spec.js b/tests/format/misc/errors/typescript/decrement-and-increment-operators/jsfmt.spec.js new file mode 100644 index 000000000000..16623c9a8f20 --- /dev/null +++ b/tests/format/misc/errors/typescript/decrement-and-increment-operators/jsfmt.spec.js @@ -0,0 +1,33 @@ +run_spec( + { + importMeta: import.meta, + snippets: [ + "1 ++", + + "(1)++", + "(1)--", + + "++(1)", + "--(1)", + + "(1 + 2)++", + "(1 + 2)--", + + "++(1 + 2)", + "--(1 + 2)", + + "(x + x)++", + "(x + x)--", + + "++(x + x)", + "--(x + x)", + + "a()++", + "x?.y++", + "x?.y.z++", + "x?.y().z++", + "(a())++", + ], + }, + ["babel-ts", "typescript"], +); diff --git a/tests/format/typescript/compiler/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/compiler/__snapshots__/jsfmt.spec.js.snap index 7ed63c3817af..6129577d6c67 100644 --- a/tests/format/typescript/compiler/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/compiler/__snapshots__/jsfmt.spec.js.snap @@ -325,18 +325,6 @@ module T.U { ================================================================================ `; -exports[`decrementAndIncrementOperators.ts [babel-ts] format 1`] = ` -"Invalid left-hand side in postfix operation. (4:1) - 2 | - 3 | // errors -> 4 | 1 ++; - | ^ - 5 | - 6 | (1)++; - 7 | (1)--; -Cause: Invalid left-hand side in postfix operation. (4:0)" -`; - exports[`decrementAndIncrementOperators.ts format 1`] = ` ====================================options===================================== parsers: ["typescript"] @@ -345,28 +333,6 @@ printWidth: 80 =====================================input====================================== var x = 0; -// errors -1 ++; - -(1)++; -(1)--; - -++(1); ---(1); - -(1 + 2)++; -(1 + 2)--; - -++(1 + 2); ---(1 + 2); - -(x + x)++; -(x + x)--; - -++(x + x); ---(x + x); - -//OK x++; x--; @@ -384,28 +350,6 @@ x[x++]++; =====================================output===================================== var x = 0; -// errors -1++; - -1++; -1--; - -++1; ---1; - -(1 + 2)++; -(1 + 2)--; - -++(1 + 2); ---(1 + 2); - -(x + x)++; -(x + x)--; - -++(x + x); ---(x + x); - -//OK x++; x--; diff --git a/tests/format/typescript/compiler/decrementAndIncrementOperators.ts b/tests/format/typescript/compiler/decrementAndIncrementOperators.ts index c8b34b361081..5441d4822e47 100644 --- a/tests/format/typescript/compiler/decrementAndIncrementOperators.ts +++ b/tests/format/typescript/compiler/decrementAndIncrementOperators.ts @@ -1,27 +1,5 @@ var x = 0; -// errors -1 ++; - -(1)++; -(1)--; - -++(1); ---(1); - -(1 + 2)++; -(1 + 2)--; - -++(1 + 2); ---(1 + 2); - -(x + x)++; -(x + x)--; - -++(x + x); ---(x + x); - -//OK x++; x--; diff --git a/tests/format/typescript/compiler/jsfmt.spec.js b/tests/format/typescript/compiler/jsfmt.spec.js index abb4b7640335..29084a9c8a10 100644 --- a/tests/format/typescript/compiler/jsfmt.spec.js +++ b/tests/format/typescript/compiler/jsfmt.spec.js @@ -1,5 +1 @@ -run_spec(import.meta, ["typescript"], { - errors: { - "babel-ts": ["decrementAndIncrementOperators.ts"], - }, -}); +run_spec(import.meta, ["typescript"]); diff --git a/tests/format/typescript/update-expression/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/update-expression/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..e5766386e623 --- /dev/null +++ b/tests/format/typescript/update-expression/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,45 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`update-expressions.ts format 1`] = ` +====================================options===================================== +parsers: ["typescript"] +printWidth: 80 + | printWidth +=====================================input====================================== +// https://github.com/typescript-eslint/typescript-eslint/blob/c3767edf65716be08df25723d7dbb770de0e7037/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/fixture.ts +class F { + #a; + + m() { + this.#a++; + this.m().a++; + this[1] = 1; + F++; + (this.#a)++; + (this.#a)++; + (this.#a satisfies number)++; + (this.#a as number)++; + this.#a!++; + } +} + +=====================================output===================================== +// https://github.com/typescript-eslint/typescript-eslint/blob/c3767edf65716be08df25723d7dbb770de0e7037/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/fixture.ts +class F { + #a; + + m() { + this.#a++; + this.m().a++; + this[1] = 1; + F++; + this.#a++; + (this.#a)++; + (this.#a satisfies number)++; + (this.#a as number)++; + this.#a!++; + } +} + +================================================================================ +`; diff --git a/tests/format/typescript/update-expression/jsfmt.spec.js b/tests/format/typescript/update-expression/jsfmt.spec.js new file mode 100644 index 000000000000..29084a9c8a10 --- /dev/null +++ b/tests/format/typescript/update-expression/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(import.meta, ["typescript"]); diff --git a/tests/format/typescript/update-expression/update-expressions.ts b/tests/format/typescript/update-expression/update-expressions.ts new file mode 100644 index 000000000000..18d495c9a555 --- /dev/null +++ b/tests/format/typescript/update-expression/update-expressions.ts @@ -0,0 +1,16 @@ +// https://github.com/typescript-eslint/typescript-eslint/blob/c3767edf65716be08df25723d7dbb770de0e7037/packages/ast-spec/src/expression/UpdateExpression/fixtures/valid-assignment/fixture.ts +class F { + #a; + + m() { + this.#a++; + this.m().a++; + this[1] = 1; + F++; + (this.#a)++; + (this.#a)++; + (this.#a satisfies number)++; + (this.#a as number)++; + this.#a!++; + } +} diff --git a/yarn.lock b/yarn.lock index 20b79f6455eb..617f802c6a02 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1966,15 +1966,15 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/eslint-plugin@npm:6.17.0": - version: 6.17.0 - resolution: "@typescript-eslint/eslint-plugin@npm:6.17.0" +"@typescript-eslint/eslint-plugin@npm:6.18.1": + version: 6.18.1 + resolution: "@typescript-eslint/eslint-plugin@npm:6.18.1" dependencies: "@eslint-community/regexpp": "npm:^4.5.1" - "@typescript-eslint/scope-manager": "npm:6.17.0" - "@typescript-eslint/type-utils": "npm:6.17.0" - "@typescript-eslint/utils": "npm:6.17.0" - "@typescript-eslint/visitor-keys": "npm:6.17.0" + "@typescript-eslint/scope-manager": "npm:6.18.1" + "@typescript-eslint/type-utils": "npm:6.18.1" + "@typescript-eslint/utils": "npm:6.18.1" + "@typescript-eslint/visitor-keys": "npm:6.18.1" debug: "npm:^4.3.4" graphemer: "npm:^1.4.0" ignore: "npm:^5.2.4" @@ -1987,7 +1987,7 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: f2a5774e9cc03e491a5a488501e5622c7eebd766f5a4fc2c30642864a3b89b0807946bde33a678f326ba7032f3f6a51aa0bf9c2d10adc823804fc9fb47db55a6 + checksum: 451abba1f784539ba38cbe40af26c461facd848e90cbf0c440a98ca2a770ff74a794bafe1df7240e52a97e7cd72bade97d5de751dffbac269643460ad65e3b19 languageName: node linkType: hard @@ -2001,22 +2001,22 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/scope-manager@npm:6.17.0": - version: 6.17.0 - resolution: "@typescript-eslint/scope-manager@npm:6.17.0" +"@typescript-eslint/scope-manager@npm:6.18.1": + version: 6.18.1 + resolution: "@typescript-eslint/scope-manager@npm:6.18.1" dependencies: - "@typescript-eslint/types": "npm:6.17.0" - "@typescript-eslint/visitor-keys": "npm:6.17.0" - checksum: fe09c628553c9336e6a36d32c1d34e78ebd20aa02130a6bf535329621ba5a98aaac171f607bc6e4d17b3478c42e7de6476376636897ce3f227c754eb99acd07e + "@typescript-eslint/types": "npm:6.18.1" + "@typescript-eslint/visitor-keys": "npm:6.18.1" + checksum: ab75663cda67a2c95267f240f2e062a0aafab0df6d625043a134c8e1d61e193c0d3cfa49c802bd554b3fd80f4b7df5ea3f86ef2eb6994ba8b5e0790cc9868c84 languageName: node linkType: hard -"@typescript-eslint/type-utils@npm:6.17.0": - version: 6.17.0 - resolution: "@typescript-eslint/type-utils@npm:6.17.0" +"@typescript-eslint/type-utils@npm:6.18.1": + version: 6.18.1 + resolution: "@typescript-eslint/type-utils@npm:6.18.1" dependencies: - "@typescript-eslint/typescript-estree": "npm:6.17.0" - "@typescript-eslint/utils": "npm:6.17.0" + "@typescript-eslint/typescript-estree": "npm:6.18.1" + "@typescript-eslint/utils": "npm:6.18.1" debug: "npm:^4.3.4" ts-api-utils: "npm:^1.0.1" peerDependencies: @@ -2024,7 +2024,7 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: dc7938429193acfda61b7282197ec046039e2c4da41cdcddf4daaf300d10229e4e23bb0fcf0503b19c0b99a874849c8a9f5bb35ce106260f56a14106d2b41d8c + checksum: f775011c35aef10b11e7cffde698fca8b06b313785cd44422c60a40b6643d85a38cbd9a3cbdef011d963680d65383c40988d983e9dfd01258ae50a2f37f6d293 languageName: node linkType: hard @@ -2035,10 +2035,10 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/types@npm:6.17.0": - version: 6.17.0 - resolution: "@typescript-eslint/types@npm:6.17.0" - checksum: 87ab1b5a3270ab34b917c22a2fb90a9ad7d9f3b19d73a337bc9efbe65f924da13482c97e8ccbe3bd3d081aa96039eeff50de41c1da2a2128066429b931cdb21d +"@typescript-eslint/types@npm:6.18.1": + version: 6.18.1 + resolution: "@typescript-eslint/types@npm:6.18.1" + checksum: e304620953257a5af3b323697845d3fb41ffbb7944df2f84559675ef8ad71cc33011be30149efd8d34c5dedcbe92c6abee67cb1b95cb3dd56f15b9393b3435a6 languageName: node linkType: hard @@ -2060,12 +2060,12 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/typescript-estree@npm:6.17.0": - version: 6.17.0 - resolution: "@typescript-eslint/typescript-estree@npm:6.17.0" +"@typescript-eslint/typescript-estree@npm:6.18.1": + version: 6.18.1 + resolution: "@typescript-eslint/typescript-estree@npm:6.18.1" dependencies: - "@typescript-eslint/types": "npm:6.17.0" - "@typescript-eslint/visitor-keys": "npm:6.17.0" + "@typescript-eslint/types": "npm:6.18.1" + "@typescript-eslint/visitor-keys": "npm:6.18.1" debug: "npm:^4.3.4" globby: "npm:^11.1.0" is-glob: "npm:^4.0.3" @@ -2075,24 +2075,24 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 1671b0d2f2fdf07074fb1e2524d61935cec173bd8db6e482cc5b2dcc77aed3ffa831396736ffa0ee2fdbddd8585ae9ca8d6c97bcaea1385b23907a1ec0508f83 + checksum: 33307bc87c3270f84f149545da79a15afaafacc5671e42f4aa827947f09c35ed114705f108ffa59d6ab175f8b838aa08cf10f9efe5b7793aca0792f879bbc7ca languageName: node linkType: hard -"@typescript-eslint/utils@npm:6.17.0": - version: 6.17.0 - resolution: "@typescript-eslint/utils@npm:6.17.0" +"@typescript-eslint/utils@npm:6.18.1": + version: 6.18.1 + resolution: "@typescript-eslint/utils@npm:6.18.1" dependencies: "@eslint-community/eslint-utils": "npm:^4.4.0" "@types/json-schema": "npm:^7.0.12" "@types/semver": "npm:^7.5.0" - "@typescript-eslint/scope-manager": "npm:6.17.0" - "@typescript-eslint/types": "npm:6.17.0" - "@typescript-eslint/typescript-estree": "npm:6.17.0" + "@typescript-eslint/scope-manager": "npm:6.18.1" + "@typescript-eslint/types": "npm:6.18.1" + "@typescript-eslint/typescript-estree": "npm:6.18.1" semver: "npm:^7.5.4" peerDependencies: eslint: ^7.0.0 || ^8.0.0 - checksum: 37c63afcf66124bf84808699997953b8c84a378aa2c490a771b611d82cdac8499c58fac8eeb8378528e97660b59563d99297bfec4b982cd68760b0ffe54aa714 + checksum: 967728f062ec7ef434b9d05af6b45ae59e0f8f314e4aa7cefc8e2c30a277cf269b7913f3e9f8d26a86c3faf8b2c9385ba1221cfcd856e9b228421fc6508b41bc languageName: node linkType: hard @@ -2124,13 +2124,13 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/visitor-keys@npm:6.17.0": - version: 6.17.0 - resolution: "@typescript-eslint/visitor-keys@npm:6.17.0" +"@typescript-eslint/visitor-keys@npm:6.18.1": + version: 6.18.1 + resolution: "@typescript-eslint/visitor-keys@npm:6.18.1" dependencies: - "@typescript-eslint/types": "npm:6.17.0" + "@typescript-eslint/types": "npm:6.18.1" eslint-visitor-keys: "npm:^3.4.1" - checksum: a2aed0e1437fdab8858ab9c7c8e355f8b72a5fa4b0adc54f28b8a2bbc29d4bb93214968ee940f83d013d0a4b83d00cd4eeeb05fb4c2c7d0ead324c6793f7d6d4 + checksum: 2d6c5ffa52e89caec0b4958d7079fb4ca9f17c19b5f5d5b8446b4eef0079fd59cd9959f469cc13c4e7d72ef4c47849e561fe323f3cebafa01bc916d43082e57b languageName: node linkType: hard @@ -7348,9 +7348,9 @@ __metadata: "@types/file-entry-cache": "npm:5.0.4" "@types/find-cache-dir": "npm:3.2.1" "@types/jest": "npm:29.5.8" - "@typescript-eslint/eslint-plugin": "npm:6.17.0" - "@typescript-eslint/typescript-estree": "npm:6.17.0" - "@typescript-eslint/visitor-keys": "npm:6.17.0" + "@typescript-eslint/eslint-plugin": "npm:6.18.1" + "@typescript-eslint/typescript-estree": "npm:6.18.1" + "@typescript-eslint/visitor-keys": "npm:6.18.1" acorn: "npm:8.11.3" acorn-jsx: "npm:5.3.2" angular-estree-parser: "npm:9.0.0" From 5f16b6b66c3d009571cc2beb2914d9e3f3a5a916 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 16 Jan 2024 10:26:09 +0800 Subject: [PATCH 07/17] Simplify loc.js (#15933) --- src/language-graphql/loc.js | 6 ++---- src/language-graphql/parser-graphql.js | 3 +-- src/language-js/loc.js | 12 +++++------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/language-graphql/loc.js b/src/language-graphql/loc.js index 6f6a7492bf44..9b6e8525b41a 100644 --- a/src/language-graphql/loc.js +++ b/src/language-graphql/loc.js @@ -1,11 +1,9 @@ function locStart(nodeOrToken) { - return nodeOrToken.kind === "Comment" - ? nodeOrToken.start - : nodeOrToken.loc.start; + return nodeOrToken.loc.start; } function locEnd(nodeOrToken) { - return nodeOrToken.kind === "Comment" ? nodeOrToken.end : nodeOrToken.loc.end; + return nodeOrToken.loc.end; } export { locEnd, locStart }; diff --git a/src/language-graphql/parser-graphql.js b/src/language-graphql/parser-graphql.js index 7ea39e4db13d..b20794341f76 100644 --- a/src/language-graphql/parser-graphql.js +++ b/src/language-graphql/parser-graphql.js @@ -9,7 +9,7 @@ function parseComments(ast) { const { startToken, endToken } = ast.loc; for (let token = startToken; token !== endToken; token = token.next) { if (token.kind === "Comment") { - comments.push(token); + comments.push({ ...token, loc: { start: token.start, end: token.end } }); } } @@ -34,7 +34,6 @@ function createParseError(error) { } function parse(text /*, options */) { - /** @type {any} */ let ast; try { ast = parseGraphql(text, parseOptions); diff --git a/src/language-js/loc.js b/src/language-js/loc.js index 72f45d6c459e..96323be8a50f 100644 --- a/src/language-js/loc.js +++ b/src/language-js/loc.js @@ -1,23 +1,21 @@ -import isNonEmptyArray from "../utils/is-non-empty-array.js"; - /** * @typedef {import("./types/estree.js").Node} Node */ function locStart(node) { - const start = node.range ? node.range[0] : node.start; + const start = node.range?.[0] ?? node.start; // Handle nodes with decorators. They should start at the first decorator - const decorators = node.declaration?.decorators ?? node.decorators; - if (isNonEmptyArray(decorators)) { - return Math.min(locStart(decorators[0]), start); + const firstDecorator = (node.declaration?.decorators ?? node.decorators)?.[0]; + if (firstDecorator) { + return Math.min(locStart(firstDecorator), start); } return start; } function locEnd(node) { - return node.range ? node.range[1] : node.end; + return node.range?.[1] ?? node.end; } /** From d386ff8f7c36b87482f525620824f7839d540730 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 16 Jan 2024 10:26:33 +0800 Subject: [PATCH 08/17] Simplify `printBinaryCastExpression` (#15932) --- src/language-js/print/cast-expression.js | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/language-js/print/cast-expression.js b/src/language-js/print/cast-expression.js index d67ad2411112..cccda40e3c03 100644 --- a/src/language-js/print/cast-expression.js +++ b/src/language-js/print/cast-expression.js @@ -2,31 +2,25 @@ import { group, indent, softline } from "../../document/builders.js"; import { isCallExpression, isMemberExpression } from "../utils/index.js"; function printBinaryCastExpression(path, options, print) { - const { parent, node } = path; - let parts = []; + const { parent, node, key } = path; + const parts = [print("expression")]; switch (node.type) { case "AsConstExpression": - parts = [print("expression"), " as const"]; + parts.push(" as const"); break; case "AsExpression": case "TSAsExpression": - parts = [print("expression"), " ", "as", " ", print("typeAnnotation")]; + parts.push(" as ", print("typeAnnotation")); break; case "SatisfiesExpression": case "TSSatisfiesExpression": - parts = [ - print("expression"), - " ", - "satisfies", - " ", - print("typeAnnotation"), - ]; + parts.push(" satisfies ", print("typeAnnotation")); break; } if ( - (isCallExpression(parent) && parent.callee === node) || - (isMemberExpression(parent) && parent.object === node) + (key === "callee" && isCallExpression(parent)) || + (key === "object" && isMemberExpression(parent)) ) { return group([indent([softline, ...parts]), softline]); } From 1e1942dc46062fc09ef5dfcbe8f57157b32eef69 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 16 Jan 2024 10:27:02 +0800 Subject: [PATCH 09/17] Remove outdated babel reasonCode (#15929) --- src/language-js/parse/babel.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/language-js/parse/babel.js b/src/language-js/parse/babel.js index 8cb96aed9ea5..a9d6e25f3005 100644 --- a/src/language-js/parse/babel.js +++ b/src/language-js/parse/babel.js @@ -99,7 +99,7 @@ function isFlowFile(text, options) { function parseWithOptions(parse, text, options) { const ast = parse(text, options); const error = ast.errors.find( - (error) => !allowedMessageCodes.has(error.reasonCode), + (error) => !allowedReasonCodes.has(error.reasonCode), ); if (error) { throw error; @@ -171,11 +171,11 @@ function createParse({ isExpression = false, optionsCombinations }) { } // Error codes are defined in -// - https://github.com/babel/babel/blob/v7.14.0/packages/babel-parser/src/parser/error-message.js -// - https://github.com/babel/babel/blob/v7.14.0/packages/babel-parser/src/plugins/typescript/index.js#L69-L153 -// - https://github.com/babel/babel/blob/v7.14.0/packages/babel-parser/src/plugins/flow/index.js#L51-L140 -// - https://github.com/babel/babel/blob/v7.14.0/packages/babel-parser/src/plugins/jsx/index.js#L23-L39 -const allowedMessageCodes = new Set([ +// - https://github.com/babel/babel/tree/v7.23.6/packages/babel-parser/src/parse-error +// - https://github.com/babel/babel/blob/v7.23.6/packages/babel-parser/src/plugins/typescript/index.ts#L73-L223 +// - https://github.com/babel/babel/blob/v7.23.6/packages/babel-parser/src/plugins/flow/index.ts#L47-L224 +// - https://github.com/babel/babel/blob/v7.23.6/packages/babel-parser/src/plugins/jsx/index.ts#L23-L44 +const allowedReasonCodes = new Set([ "StrictNumericEscape", "StrictWith", "StrictOctalLiteral", @@ -190,8 +190,6 @@ const allowedMessageCodes = new Set([ "UnsupportedParameterPropertyKind", - "MixedLabeledAndUnlabeledElements", - "DuplicateAccessibilityModifier", "DecoratorExportClass", From 70c9c56c67e6c3061187abed571ca43f1a7e0608 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 16 Jan 2024 10:27:49 +0800 Subject: [PATCH 10/17] Improve babel parse error message (#15928) --- .../parse/utils/create-babel-parse-error.js | 10 +++++- src/language-json/parser-json.js | 10 ------ .../__snapshots__/jsfmt.spec.js.snap | 7 ++++ .../babel-missing-plugins/jsfmt.spec.js | 10 ++++++ .../json/__snapshots__/jsfmt.spec.js.snap | 34 +++++++++---------- 5 files changed, 43 insertions(+), 28 deletions(-) create mode 100644 tests/format/misc/errors/babel-missing-plugins/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/format/misc/errors/babel-missing-plugins/jsfmt.spec.js diff --git a/src/language-js/parse/utils/create-babel-parse-error.js b/src/language-js/parse/utils/create-babel-parse-error.js index b39e1f498638..cbee21de4043 100644 --- a/src/language-js/parse/utils/create-babel-parse-error.js +++ b/src/language-js/parse/utils/create-babel-parse-error.js @@ -6,7 +6,15 @@ function createBabelParseError(error) { let { message, loc: { line, column }, + reasonCode, } = error; + + let cause = error; + if (reasonCode === "MissingPlugin" || reasonCode === "MissingOneOfPlugins") { + message = "Unexpected token."; + cause = undefined; + } + const suffix = ` (${line}:${column})`; if (message.endsWith(suffix)) { message = message.slice(0, -suffix.length); @@ -14,7 +22,7 @@ function createBabelParseError(error) { return createError(message, { loc: { start: { line, column: column + 1 } }, - cause: error, + cause, }); } diff --git a/src/language-json/parser-json.js b/src/language-json/parser-json.js index 595cdc205c68..d2e1234291f4 100644 --- a/src/language-json/parser-json.js +++ b/src/language-json/parser-json.js @@ -18,16 +18,6 @@ function createJsonParse(options = {}) { attachComment: false, }); } catch (/** @type {any} */ error) { - if ( - error?.reasonCode === "MissingPlugin" || - error?.reasonCode === "MissingOneOfPlugins" - ) { - throw createBabelParseError({ - message: "Unexpected token", - loc: error.loc, - }); - } - throw createBabelParseError(error); } diff --git a/tests/format/misc/errors/babel-missing-plugins/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/babel-missing-plugins/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000000..1d6081a6604d --- /dev/null +++ b/tests/format/misc/errors/babel-missing-plugins/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,7 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`snippet: #0 [babel] format 1`] = ` +"Unexpected token. (1:8) +> 1 | export type Foo = number; + | ^" +`; diff --git a/tests/format/misc/errors/babel-missing-plugins/jsfmt.spec.js b/tests/format/misc/errors/babel-missing-plugins/jsfmt.spec.js new file mode 100644 index 000000000000..2b0dd6a91337 --- /dev/null +++ b/tests/format/misc/errors/babel-missing-plugins/jsfmt.spec.js @@ -0,0 +1,10 @@ +run_spec( + { + importMeta: import.meta, + snippets: [ + // https://github.com/babel/babel/commit/a466f9c310ace91484d4087f077ee6d6c8cd8789 + "export type Foo = number;", + ], + }, + ["babel"], +); diff --git a/tests/format/misc/errors/json/__snapshots__/jsfmt.spec.js.snap b/tests/format/misc/errors/json/__snapshots__/jsfmt.spec.js.snap index a2afc863ca2b..d9dfa9d32dfb 100644 --- a/tests/format/misc/errors/json/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/misc/errors/json/__snapshots__/jsfmt.spec.js.snap @@ -82,7 +82,7 @@ exports[`snippet: #3 [json] format 1`] = ` `; exports[`snippet: #3 [json] format 2`] = ` -"Unexpected token (1:2) +"Unexpected token. (1:2) > 1 | [do {}] | ^" `; @@ -184,7 +184,7 @@ exports[`snippet: #7 [json] format 1`] = ` `; exports[`snippet: #7 [json] format 2`] = ` -"Unexpected token (1:24) +"Unexpected token. (1:24) > 1 | [function*() {function.sent}] | ^" `; @@ -208,7 +208,7 @@ exports[`snippet: #8 [json] format 1`] = ` `; exports[`snippet: #8 [json] format 2`] = ` -"Unexpected token (1:2) +"Unexpected token. (1:2) > 1 | [throw {}] | ^" `; @@ -232,7 +232,7 @@ exports[`snippet: #9 [json] format 1`] = ` `; exports[`snippet: #9 [json] format 2`] = ` -"Unexpected token (1:6) +"Unexpected token. (1:6) > 1 | [foo(?)] | ^" `; @@ -256,7 +256,7 @@ exports[`snippet: #10 [json] format 1`] = ` `; exports[`snippet: #10 [json] format 2`] = ` -"Unexpected token (1:2) +"Unexpected token. (1:2) > 1 | [@decorator class {}] | ^" `; @@ -280,7 +280,7 @@ exports[`snippet: #11 [json] format 1`] = ` `; exports[`snippet: #11 [json] format 2`] = ` -"Unexpected token (1:28) +"Unexpected token. (1:28) > 1 | [import('a', {type:'json'})] | ^" `; @@ -304,7 +304,7 @@ exports[`snippet: #12 [json] format 1`] = ` `; exports[`snippet: #12 [json] format 2`] = ` -"Unexpected token (1:3) +"Unexpected token. (1:3) > 1 | [1m] | ^" `; @@ -328,7 +328,7 @@ exports[`snippet: #13 [json] format 1`] = ` `; exports[`snippet: #13 [json] format 2`] = ` -"Unexpected token (1:2) +"Unexpected token. (1:2) > 1 | [module {}] | ^" `; @@ -352,7 +352,7 @@ exports[`snippet: #14 [json] format 1`] = ` `; exports[`snippet: #14 [json] format 2`] = ` -"Unexpected token (1:8) +"Unexpected token. (1:8) > 1 | [async do {}] | ^" `; @@ -400,7 +400,7 @@ exports[`snippet: #16 [json] format 1`] = ` `; exports[`snippet: #16 [json] format 2`] = ` -"Unexpected token (1:28) +"Unexpected token. (1:28) > 1 | [class {#foo;bar() {const {#foo: foo} = this;}}] | ^" `; @@ -424,7 +424,7 @@ exports[`snippet: #17 [json] format 1`] = ` `; exports[`snippet: #17 [json] format 2`] = ` -"Unexpected token (1:18) +"Unexpected token. (1:18) > 1 | [class {accessor foo = 1}] | ^" `; @@ -448,7 +448,7 @@ exports[`snippet: #18 [json] format 1`] = ` `; exports[`snippet: #18 [json] format 2`] = ` -"Unexpected token (1:34) +"Unexpected token. (1:34) > 1 | [import('a', {reflect: 'module'})] | ^" `; @@ -497,7 +497,7 @@ exports[`snippet: #20 [json] format 1`] = ` `; exports[`snippet: #20 [json] format 2`] = ` -"Unexpected token (1:16) +"Unexpected token. (1:16) > 1 | [function() { {using a = b} }] | ^" `; @@ -584,7 +584,7 @@ Cause: Unexpected token (1:13)" `; exports[`snippet: #23 [json] format 2`] = ` -"Unexpected token (1:2) +"Unexpected token. (1:2) > 1 | [#{}] | ^" `; @@ -637,7 +637,7 @@ exports[`snippet: #25 [json] format 1`] = ` `; exports[`snippet: #25 [json] format 2`] = ` -"Unexpected token (1:8) +"Unexpected token. (1:8) > 1 | ['foo' |> bar] | ^" `; @@ -661,7 +661,7 @@ exports[`snippet: #26 [json] format 1`] = ` `; exports[`snippet: #26 [json] format 2`] = ` -"Unexpected token (1:8) +"Unexpected token. (1:8) > 1 | ['foo' |> bar(%)] | ^" `; @@ -685,7 +685,7 @@ exports[`snippet: #27 [json] format 1`] = ` `; exports[`snippet: #27 [json] format 2`] = ` -"Unexpected token (1:2) +"Unexpected token. (1:2) > 1 | [] | ^" `; From 10762eeaa0c5af3bbcd12dddad213746cc8ff08f Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 16 Jan 2024 10:28:40 +0800 Subject: [PATCH 11/17] Improve keyword detection in `TSModuleDeclaration` (#15925) --- src/language-js/print/module.js | 32 +---------------- src/language-js/print/typescript.js | 7 ++-- .../utils/get-text-without-comments.js | 34 +++++++++++++++++++ .../module/__snapshots__/jsfmt.spec.js.snap | 8 +++++ tests/format/typescript/module/keyword.ts | 4 +++ 5 files changed, 51 insertions(+), 34 deletions(-) create mode 100644 src/language-js/utils/get-text-without-comments.js diff --git a/src/language-js/print/module.js b/src/language-js/print/module.js index 17251d80ada6..5a0c57034575 100644 --- a/src/language-js/print/module.js +++ b/src/language-js/print/module.js @@ -1,5 +1,3 @@ -import assert from "node:assert"; - import { group, hardline, @@ -13,6 +11,7 @@ import { printDanglingComments } from "../../main/comments/print.js"; import isNonEmptyArray from "../../utils/is-non-empty-array.js"; import UnexpectedNodeError from "../../utils/unexpected-node-error.js"; import { hasSameLoc, locEnd, locStart } from "../loc.js"; +import getTextWithoutComments from "../utils/get-text-without-comments.js"; import { CommentCheckFlags, createTypeCheckFunction, @@ -249,35 +248,6 @@ function shouldPrintSpecifiers(node, options) { return text.trimEnd().endsWith("from"); } -function getTextWithoutComments(options, start, end) { - let text = options.originalText.slice(start, end); - - for (const comment of options[Symbol.for("comments")]) { - const commentStart = locStart(comment); - // Comments are sorted, we can escape if the comment is after the range - if (commentStart > end) { - break; - } - - const commentEnd = locEnd(comment); - if (commentEnd < start) { - continue; - } - - const commentLength = commentEnd - commentStart; - text = - text.slice(0, commentStart - start) + - " ".repeat(commentLength) + - text.slice(commentEnd - start); - } - - if (process.env.NODE_ENV !== "production") { - assert(text.length === end - start); - } - - return text; -} - function getImportAttributesKeyword(node, options) { // Babel parser add this property to indicate the keyword is `assert` if (node.extra?.deprecatedAssertSyntax) { diff --git a/src/language-js/print/typescript.js b/src/language-js/print/typescript.js index fddc7bd51b84..0e7e7db71465 100644 --- a/src/language-js/print/typescript.js +++ b/src/language-js/print/typescript.js @@ -8,6 +8,7 @@ import { } from "../../document/builders.js"; import UnexpectedNodeError from "../../utils/unexpected-node-error.js"; import { locStart } from "../loc.js"; +import getTextWithoutComments from "../utils/get-text-without-comments.js"; import { isArrayOrTupleExpression, isObjectOrRecordExpression, @@ -311,9 +312,9 @@ function printTypescript(path, options, print) { node.kind ?? // TODO: Use `node.kind` when babel update AST (isStringLiteral(node.id) || - /(?:^|\s)module(?:\s|$)/.test( - options.originalText.slice(locStart(node), locStart(node.id)), - ) + getTextWithoutComments(options, locStart(node), locStart(node.id)) + .trim() + .endsWith("module") ? "module" : "namespace"); parts.push(kind, " "); diff --git a/src/language-js/utils/get-text-without-comments.js b/src/language-js/utils/get-text-without-comments.js new file mode 100644 index 000000000000..4d7d12aa6267 --- /dev/null +++ b/src/language-js/utils/get-text-without-comments.js @@ -0,0 +1,34 @@ +import assert from "node:assert"; + +import { locEnd, locStart } from "../loc.js"; + +function getTextWithoutComments(options, start, end) { + let text = options.originalText.slice(start, end); + + for (const comment of options[Symbol.for("comments")]) { + const commentStart = locStart(comment); + // Comments are sorted, we can escape if the comment is after the range + if (commentStart > end) { + break; + } + + const commentEnd = locEnd(comment); + if (commentEnd < start) { + continue; + } + + const commentLength = commentEnd - commentStart; + text = + text.slice(0, commentStart - start) + + " ".repeat(commentLength) + + text.slice(commentEnd - start); + } + + if (process.env.NODE_ENV !== "production") { + assert(text.length === end - start); + } + + return text; +} + +export default getTextWithoutComments; diff --git a/tests/format/typescript/module/__snapshots__/jsfmt.spec.js.snap b/tests/format/typescript/module/__snapshots__/jsfmt.spec.js.snap index fb0e3f097f3e..f2f567fb77f8 100644 --- a/tests/format/typescript/module/__snapshots__/jsfmt.spec.js.snap +++ b/tests/format/typescript/module/__snapshots__/jsfmt.spec.js.snap @@ -80,6 +80,10 @@ namespace X { } } +namespace /* module */ X {} +module /* namespace */ X {} +module /* namespace */ "x" {} + =====================================output===================================== module X {} @@ -113,6 +117,10 @@ namespace X { } } +namespace /* module */ X {} +module /* namespace */ X {} +module /* namespace */ "x" {} + ================================================================================ `; diff --git a/tests/format/typescript/module/keyword.ts b/tests/format/typescript/module/keyword.ts index d533a618796e..83792a6b8516 100644 --- a/tests/format/typescript/module/keyword.ts +++ b/tests/format/typescript/module/keyword.ts @@ -29,3 +29,7 @@ namespace X { const x = 1; } } + +namespace /* module */ X {} +module /* namespace */ X {} +module /* namespace */ "x" {} From be174056690dd1236c9dc3b4167c811245f8c584 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 16 Jan 2024 10:31:56 +0800 Subject: [PATCH 12/17] Simplify `isSimpleCallArgument` (#15923) --- src/language-js/utils/index.js | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/src/language-js/utils/index.js b/src/language-js/utils/index.js index 5b3b82899552..821b40f4a363 100644 --- a/src/language-js/utils/index.js +++ b/src/language-js/utils/index.js @@ -419,22 +419,6 @@ const isMemberExpression = skipChainExpression( createTypeCheckFunction(["MemberExpression", "OptionalMemberExpression"]), ); -/** - * Retrieves a property from a node, considering any ChainExpression. - * If the node is a ChainExpression, the property is obtained from its expression. - * Otherwise, the property is obtained directly from the node. - * - * @param {Node} node - The AST node to be processed. - * @param {string} property - The property name to retrieve. - * @returns The property value from the node or its expression. - */ -function getChainProp(node, property) { - if (node.type === "ChainExpression") { - return node.expression[property]; - } - return node[property]; -} - /** * * @param {any} node @@ -740,6 +724,10 @@ function isSimpleCallArgument(node, depth = 2) { return false; } + if (node.type === "ChainExpression" || node.type === "TSNonNullExpression") { + return isSimpleCallArgument(node.expression, depth); + } + const isChildSimple = (child) => isSimpleCallArgument(child, depth - 1); if (isRegExpLiteral(node)) { @@ -775,7 +763,7 @@ function isSimpleCallArgument(node, depth = 2) { if (isCallLikeExpression(node)) { if ( node.type === "ImportExpression" || - isSimpleCallArgument(getChainProp(node, "callee"), depth) + isSimpleCallArgument(node.callee, depth) ) { const args = getCallArguments(node); return args.length <= depth && args.every(isChildSimple); @@ -785,8 +773,8 @@ function isSimpleCallArgument(node, depth = 2) { if (isMemberExpression(node)) { return ( - isSimpleCallArgument(getChainProp(node, "object"), depth) && - isSimpleCallArgument(getChainProp(node, "property"), depth) + isSimpleCallArgument(node.object, depth) && + isSimpleCallArgument(node.property, depth) ); } @@ -798,10 +786,6 @@ function isSimpleCallArgument(node, depth = 2) { return isSimpleCallArgument(node.argument, depth); } - if (node.type === "TSNonNullExpression") { - return isSimpleCallArgument(node.expression, depth); - } - return false; } @@ -1238,7 +1222,6 @@ export { createTypeCheckFunction, getCallArguments, getCallArgumentSelector, - getChainProp, getComments, getFunctionParameters, getLeftSide, From c566c9df08936c1a8e32c61ba5760455ef43b575 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 16 Jan 2024 10:34:05 +0800 Subject: [PATCH 13/17] Fix parser inference (#15927) --- .prettierrc | 7 +++---- .vscode/extensions.json | 4 ++-- .vscode/settings.example.json | 8 ++++---- changelog_unreleased/api/15927.md | 12 ++++++++++++ src/utils/infer-parser.js | 19 +++++++++++-------- tests/integration/__tests__/file-info.js | 4 ++++ 6 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 changelog_unreleased/api/15927.md diff --git a/.prettierrc b/.prettierrc index 20c2d97a0926..bb34518270e9 100644 --- a/.prettierrc +++ b/.prettierrc @@ -5,7 +5,6 @@ overrides: - files: "bin/prettier.cjs" options: trailingComma: none - # TODO: Enable this after `jsonc` parser released - # - files: ".vscode/*.json" - # options: - # parser: jsonc + - files: ".vscode/*.json" + options: + parser: jsonc diff --git a/.vscode/extensions.json b/.vscode/extensions.json index a0ee92829b81..ebce3d3e0697 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -3,6 +3,6 @@ "esbenp.prettier-vscode", "editorconfig.editorconfig", "dbaeumer.vscode-eslint", - "streetsidesoftware.code-spell-checker" - ] + "streetsidesoftware.code-spell-checker", + ], } diff --git a/.vscode/settings.example.json b/.vscode/settings.example.json index a01541d57723..fca393e94753 100644 --- a/.vscode/settings.example.json +++ b/.vscode/settings.example.json @@ -2,14 +2,14 @@ "[javascript]": { "editor.defaultFormatter": "esbenp.prettier-vscode", "editor.formatOnSave": true, - "editor.codeActionsOnSave": ["source.fixAll.eslint"] + "editor.codeActionsOnSave": ["source.fixAll.eslint"], }, "editor.codeActionsOnSave": { - "source.fixAll.eslint": "explicit" + "source.fixAll.eslint": "explicit", }, "prettier.requireConfig": true, "eslint.experimental.useFlatConfig": true, "files.exclude": { - "dist*": true - } + "dist*": true, + }, } diff --git a/changelog_unreleased/api/15927.md b/changelog_unreleased/api/15927.md new file mode 100644 index 000000000000..36a468c81a28 --- /dev/null +++ b/changelog_unreleased/api/15927.md @@ -0,0 +1,12 @@ +#### Fix parser inference (#15927 by @fisker) + + +```console +// Prettier stable +prettier --file-info tsconfig.json +{ "ignored": false, "inferredParser": "json" } + +// Prettier main +prettier --file-info tsconfig.json +{ "ignored": false, "inferredParser": "jsonc" } +``` diff --git a/src/utils/infer-parser.js b/src/utils/infer-parser.js index 42923955404b..6762e47359fe 100644 --- a/src/utils/infer-parser.js +++ b/src/utils/infer-parser.js @@ -11,14 +11,17 @@ function getLanguageByFileName(languages, file) { const basename = getFileBasename(file).toLowerCase(); - return languages.find( - (language) => - language.extensions?.some((extension) => basename.endsWith(extension)) || - language.filenames?.some((name) => name.toLowerCase() === basename), + return ( + languages.find(({ filenames }) => + filenames?.some((name) => name.toLowerCase() === basename), + ) ?? + languages.find(({ extensions }) => + extensions?.some((extension) => basename.endsWith(extension)), + ) ); } -function getLanguageByName(languages, languageName) { +function getLanguageByLanguageName(languages, languageName) { if (!languageName) { return; } @@ -45,8 +48,8 @@ function getLanguageByInterpreter(languages, file) { return; } - return languages.find((language) => - language.interpreters?.includes(interpreter), + return languages.find(({ interpreters }) => + interpreters?.includes(interpreter), ); } @@ -66,7 +69,7 @@ function inferParser(options, fileInfo) { // interpreter in the shebang line, if any; but since this requires FS access, // do it last. const language = - getLanguageByName(languages, fileInfo.language) ?? + getLanguageByLanguageName(languages, fileInfo.language) ?? getLanguageByFileName(languages, fileInfo.physicalFile) ?? getLanguageByFileName(languages, fileInfo.file) ?? getLanguageByInterpreter(languages, fileInfo.physicalFile); diff --git a/tests/integration/__tests__/file-info.js b/tests/integration/__tests__/file-info.js index 74a65314c160..a05d3ee79f08 100644 --- a/tests/integration/__tests__/file-info.js +++ b/tests/integration/__tests__/file-info.js @@ -130,6 +130,10 @@ test("API getFileInfo with filepath only", async () => { ignored: false, inferredParser: "markdown", }); + await expect(prettier.getFileInfo("tsconfig.json")).resolves.toEqual({ + ignored: false, + inferredParser: "jsonc", + }); }); describe("API getFileInfo resolveConfig", () => { From 12ab5852fa32888c21e9de2c52d3c6952265457f Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 16 Jan 2024 10:34:53 +0800 Subject: [PATCH 14/17] chore(deps): update dependency browserslist-to-esbuild to v2.1.1 (#15930) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index a9a853826138..40ec79809aa7 100644 --- a/package.json +++ b/package.json @@ -119,7 +119,7 @@ "@typescript-eslint/eslint-plugin": "6.18.1", "benchmark": "2.1.4", "browserslist": "4.22.2", - "browserslist-to-esbuild": "2.1.0", + "browserslist-to-esbuild": "2.1.1", "c8": "9.0.0", "cross-env": "7.0.3", "cspell": "8.3.2", diff --git a/yarn.lock b/yarn.lock index 617f802c6a02..a9609976c04e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2599,16 +2599,16 @@ __metadata: languageName: node linkType: hard -"browserslist-to-esbuild@npm:2.1.0": - version: 2.1.0 - resolution: "browserslist-to-esbuild@npm:2.1.0" +"browserslist-to-esbuild@npm:2.1.1": + version: 2.1.1 + resolution: "browserslist-to-esbuild@npm:2.1.1" dependencies: meow: "npm:^13.0.0" peerDependencies: browserslist: "*" bin: browserslist-to-esbuild: cli/index.js - checksum: 67a710fb24c44540e46507a41278617be7d848d1fc4a815ce5dc025e2cd113af63cf117784a74df24e019f9d1c64190498853813e0259cd89b6ab517214f1c60 + checksum: 5e91b23ba5ac47412b7456bbb74ee11b35d1083163e9e8e001e48f3a975c65758a4559ab532812d8518877a1d8f68c5b649b88a08722b9543b38e633e6943f7d languageName: node linkType: hard @@ -7357,7 +7357,7 @@ __metadata: angular-html-parser: "npm:5.2.0" benchmark: "npm:2.1.4" browserslist: "npm:4.22.2" - browserslist-to-esbuild: "npm:2.1.0" + browserslist-to-esbuild: "npm:2.1.1" c8: "npm:9.0.0" camelcase: "npm:8.0.0" chalk: "npm:5.3.0" From 86fd77d9cd183a642f0429c9112fcebf9f9a8365 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 16 Jan 2024 10:35:16 +0800 Subject: [PATCH 15/17] chore(deps): update dependency flow-parser to v0.226.0 (#15931) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 2 +- yarn.lock | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 40ec79809aa7..b0f2bac3eae8 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "fast-json-stable-stringify": "2.1.0", "file-entry-cache": "7.0.2", "find-cache-dir": "5.0.0", - "flow-parser": "0.225.1", + "flow-parser": "0.226.0", "get-east-asian-width": "1.2.0", "get-stdin": "9.0.0", "graphql": "16.8.1", diff --git a/yarn.lock b/yarn.lock index a9609976c04e..eaf651bfaa75 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4375,10 +4375,10 @@ __metadata: languageName: node linkType: hard -"flow-parser@npm:0.225.1": - version: 0.225.1 - resolution: "flow-parser@npm:0.225.1" - checksum: 9de425b5f97bf25b632eafce5af5398fe04411d9f6247236801fd1a3709ba28b00c12d123e79fdb183952be135009f2594278cc3b7aea6d0b673397c7f4bfb26 +"flow-parser@npm:0.226.0": + version: 0.226.0 + resolution: "flow-parser@npm:0.226.0" + checksum: d92248658fbf963131d98a2b8438b948391d2e6bfe23243ef81a2017adb080257072e21fc69f060189f0bae57b4d6abcbf2b118a76c3ef626c4712917c2e9010 languageName: node linkType: hard @@ -7394,7 +7394,7 @@ __metadata: fast-json-stable-stringify: "npm:2.1.0" file-entry-cache: "npm:7.0.2" find-cache-dir: "npm:5.0.0" - flow-parser: "npm:0.225.1" + flow-parser: "npm:0.226.0" get-east-asian-width: "npm:1.2.0" get-stdin: "npm:9.0.0" graphql: "npm:16.8.1" From 99c873d4219f02f684ec8f3d200abee04e9bbe85 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Tue, 16 Jan 2024 19:07:27 +0800 Subject: [PATCH 16/17] chore(deps): update typescript-eslint to v6.19.0 (#15939) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> --- package.json | 6 ++-- yarn.lock | 90 ++++++++++++++++++++++++++-------------------------- 2 files changed, 48 insertions(+), 48 deletions(-) diff --git a/package.json b/package.json index b0f2bac3eae8..aaf0e10ef878 100644 --- a/package.json +++ b/package.json @@ -38,8 +38,8 @@ "@iarna/toml": "2.2.5", "@prettier/is-es5-identifier-name": "0.2.0", "@prettier/parse-srcset": "3.1.0", - "@typescript-eslint/typescript-estree": "6.18.1", - "@typescript-eslint/visitor-keys": "6.18.1", + "@typescript-eslint/typescript-estree": "6.19.0", + "@typescript-eslint/visitor-keys": "6.19.0", "acorn": "8.11.3", "acorn-jsx": "5.3.2", "angular-estree-parser": "9.0.0", @@ -116,7 +116,7 @@ "@types/file-entry-cache": "5.0.4", "@types/find-cache-dir": "3.2.1", "@types/jest": "29.5.8", - "@typescript-eslint/eslint-plugin": "6.18.1", + "@typescript-eslint/eslint-plugin": "6.19.0", "benchmark": "2.1.4", "browserslist": "4.22.2", "browserslist-to-esbuild": "2.1.1", diff --git a/yarn.lock b/yarn.lock index eaf651bfaa75..d05e3f013e86 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1966,15 +1966,15 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/eslint-plugin@npm:6.18.1": - version: 6.18.1 - resolution: "@typescript-eslint/eslint-plugin@npm:6.18.1" +"@typescript-eslint/eslint-plugin@npm:6.19.0": + version: 6.19.0 + resolution: "@typescript-eslint/eslint-plugin@npm:6.19.0" dependencies: "@eslint-community/regexpp": "npm:^4.5.1" - "@typescript-eslint/scope-manager": "npm:6.18.1" - "@typescript-eslint/type-utils": "npm:6.18.1" - "@typescript-eslint/utils": "npm:6.18.1" - "@typescript-eslint/visitor-keys": "npm:6.18.1" + "@typescript-eslint/scope-manager": "npm:6.19.0" + "@typescript-eslint/type-utils": "npm:6.19.0" + "@typescript-eslint/utils": "npm:6.19.0" + "@typescript-eslint/visitor-keys": "npm:6.19.0" debug: "npm:^4.3.4" graphemer: "npm:^1.4.0" ignore: "npm:^5.2.4" @@ -1987,7 +1987,7 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 451abba1f784539ba38cbe40af26c461facd848e90cbf0c440a98ca2a770ff74a794bafe1df7240e52a97e7cd72bade97d5de751dffbac269643460ad65e3b19 + checksum: 5ed8483d792c4bc6ed697159c84a47ba5c35cd124949883813f2053b972537de3900a7ae26d4d6f370194f2cc7929baa2d09268e0b90118f20ed961cf6c176b9 languageName: node linkType: hard @@ -2001,22 +2001,22 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/scope-manager@npm:6.18.1": - version: 6.18.1 - resolution: "@typescript-eslint/scope-manager@npm:6.18.1" +"@typescript-eslint/scope-manager@npm:6.19.0": + version: 6.19.0 + resolution: "@typescript-eslint/scope-manager@npm:6.19.0" dependencies: - "@typescript-eslint/types": "npm:6.18.1" - "@typescript-eslint/visitor-keys": "npm:6.18.1" - checksum: ab75663cda67a2c95267f240f2e062a0aafab0df6d625043a134c8e1d61e193c0d3cfa49c802bd554b3fd80f4b7df5ea3f86ef2eb6994ba8b5e0790cc9868c84 + "@typescript-eslint/types": "npm:6.19.0" + "@typescript-eslint/visitor-keys": "npm:6.19.0" + checksum: d36c51c05e14c51ce13181120eeea46d1edd59ed1ff16dc4ec1f5532a975b5faec5c10a373aaa90545f82a12330c6cba18ecedc734e18288f5874855c48ba808 languageName: node linkType: hard -"@typescript-eslint/type-utils@npm:6.18.1": - version: 6.18.1 - resolution: "@typescript-eslint/type-utils@npm:6.18.1" +"@typescript-eslint/type-utils@npm:6.19.0": + version: 6.19.0 + resolution: "@typescript-eslint/type-utils@npm:6.19.0" dependencies: - "@typescript-eslint/typescript-estree": "npm:6.18.1" - "@typescript-eslint/utils": "npm:6.18.1" + "@typescript-eslint/typescript-estree": "npm:6.19.0" + "@typescript-eslint/utils": "npm:6.19.0" debug: "npm:^4.3.4" ts-api-utils: "npm:^1.0.1" peerDependencies: @@ -2024,7 +2024,7 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: f775011c35aef10b11e7cffde698fca8b06b313785cd44422c60a40b6643d85a38cbd9a3cbdef011d963680d65383c40988d983e9dfd01258ae50a2f37f6d293 + checksum: f1f20ac28c03dd18546050b63ec0b0fd8c67780265ccb9ef566f16441c3de5deb2607a6046fefdebe8a43ac11fecdf0b009f8e5f70a3d15916d855be74b0f3bb languageName: node linkType: hard @@ -2035,10 +2035,10 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/types@npm:6.18.1": - version: 6.18.1 - resolution: "@typescript-eslint/types@npm:6.18.1" - checksum: e304620953257a5af3b323697845d3fb41ffbb7944df2f84559675ef8ad71cc33011be30149efd8d34c5dedcbe92c6abee67cb1b95cb3dd56f15b9393b3435a6 +"@typescript-eslint/types@npm:6.19.0": + version: 6.19.0 + resolution: "@typescript-eslint/types@npm:6.19.0" + checksum: 396ad2ad9f2d759dd87bc880a1ffc9d11fda04db8af9402abb4e8eccd58c01fa2d26e38b186526d0b457012f7c912e7afdab2a3798a73aa0ae34abaf50d617ae languageName: node linkType: hard @@ -2060,12 +2060,12 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/typescript-estree@npm:6.18.1": - version: 6.18.1 - resolution: "@typescript-eslint/typescript-estree@npm:6.18.1" +"@typescript-eslint/typescript-estree@npm:6.19.0": + version: 6.19.0 + resolution: "@typescript-eslint/typescript-estree@npm:6.19.0" dependencies: - "@typescript-eslint/types": "npm:6.18.1" - "@typescript-eslint/visitor-keys": "npm:6.18.1" + "@typescript-eslint/types": "npm:6.19.0" + "@typescript-eslint/visitor-keys": "npm:6.19.0" debug: "npm:^4.3.4" globby: "npm:^11.1.0" is-glob: "npm:^4.0.3" @@ -2075,24 +2075,24 @@ __metadata: peerDependenciesMeta: typescript: optional: true - checksum: 33307bc87c3270f84f149545da79a15afaafacc5671e42f4aa827947f09c35ed114705f108ffa59d6ab175f8b838aa08cf10f9efe5b7793aca0792f879bbc7ca + checksum: 06e24bb145a302299a6cf86b36652bd4d7080c4e88517ebc24bdc137c57425a68db256ba628ce16b568bfec8020ae2a748ccee93e304efeded329cb3292b17bf languageName: node linkType: hard -"@typescript-eslint/utils@npm:6.18.1": - version: 6.18.1 - resolution: "@typescript-eslint/utils@npm:6.18.1" +"@typescript-eslint/utils@npm:6.19.0": + version: 6.19.0 + resolution: "@typescript-eslint/utils@npm:6.19.0" dependencies: "@eslint-community/eslint-utils": "npm:^4.4.0" "@types/json-schema": "npm:^7.0.12" "@types/semver": "npm:^7.5.0" - "@typescript-eslint/scope-manager": "npm:6.18.1" - "@typescript-eslint/types": "npm:6.18.1" - "@typescript-eslint/typescript-estree": "npm:6.18.1" + "@typescript-eslint/scope-manager": "npm:6.19.0" + "@typescript-eslint/types": "npm:6.19.0" + "@typescript-eslint/typescript-estree": "npm:6.19.0" semver: "npm:^7.5.4" peerDependencies: eslint: ^7.0.0 || ^8.0.0 - checksum: 967728f062ec7ef434b9d05af6b45ae59e0f8f314e4aa7cefc8e2c30a277cf269b7913f3e9f8d26a86c3faf8b2c9385ba1221cfcd856e9b228421fc6508b41bc + checksum: 4080c36331204ffef9f218e29f43da767f17551fa4d3877c3d3b49194f7c7382dd9ae2124e7b5ebd47d5556946bb6ad195b47d7d215553efabacdebf81b9e74d languageName: node linkType: hard @@ -2124,13 +2124,13 @@ __metadata: languageName: node linkType: hard -"@typescript-eslint/visitor-keys@npm:6.18.1": - version: 6.18.1 - resolution: "@typescript-eslint/visitor-keys@npm:6.18.1" +"@typescript-eslint/visitor-keys@npm:6.19.0": + version: 6.19.0 + resolution: "@typescript-eslint/visitor-keys@npm:6.19.0" dependencies: - "@typescript-eslint/types": "npm:6.18.1" + "@typescript-eslint/types": "npm:6.19.0" eslint-visitor-keys: "npm:^3.4.1" - checksum: 2d6c5ffa52e89caec0b4958d7079fb4ca9f17c19b5f5d5b8446b4eef0079fd59cd9959f469cc13c4e7d72ef4c47849e561fe323f3cebafa01bc916d43082e57b + checksum: 8d51c0b8d94c5df044fde958f62741cef55be97c6a3a16c47e4df9af7b2ff13aa1ee03ca5240777481dca53f3b7a9b00b329e50aff5e3ad829d96bc5f63ca2c3 languageName: node linkType: hard @@ -7348,9 +7348,9 @@ __metadata: "@types/file-entry-cache": "npm:5.0.4" "@types/find-cache-dir": "npm:3.2.1" "@types/jest": "npm:29.5.8" - "@typescript-eslint/eslint-plugin": "npm:6.18.1" - "@typescript-eslint/typescript-estree": "npm:6.18.1" - "@typescript-eslint/visitor-keys": "npm:6.18.1" + "@typescript-eslint/eslint-plugin": "npm:6.19.0" + "@typescript-eslint/typescript-estree": "npm:6.19.0" + "@typescript-eslint/visitor-keys": "npm:6.19.0" acorn: "npm:8.11.3" acorn-jsx: "npm:5.3.2" angular-estree-parser: "npm:9.0.0" From 42ba4373f47a67a5d50756a76a57b2ce3a5524e5 Mon Sep 17 00:00:00 2001 From: fisker Date: Wed, 17 Jan 2024 11:27:30 +0800 Subject: [PATCH 17/17] Release 3.2.3 --- .github/ISSUE_TEMPLATE/formatting.md | 2 +- .github/ISSUE_TEMPLATE/integration.md | 2 +- CHANGELOG.md | 48 +++++++++++++++++++ docs/browser.md | 32 ++++++------- package.json | 2 +- website/versioned_docs/version-stable/api.md | 2 +- .../versioned_docs/version-stable/browser.md | 32 ++++++------- 7 files changed, 84 insertions(+), 36 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/formatting.md b/.github/ISSUE_TEMPLATE/formatting.md index 0df60bdedde0..e43296162df8 100644 --- a/.github/ISSUE_TEMPLATE/formatting.md +++ b/.github/ISSUE_TEMPLATE/formatting.md @@ -26,7 +26,7 @@ Don't fill the form below manually! Let a program create a report for you: --> -**Prettier 3.2.2** +**Prettier 3.2.3** [Playground link](https://prettier.io/playground/#.....) ```sh diff --git a/.github/ISSUE_TEMPLATE/integration.md b/.github/ISSUE_TEMPLATE/integration.md index b4a5566d9946..67991a89cf55 100644 --- a/.github/ISSUE_TEMPLATE/integration.md +++ b/.github/ISSUE_TEMPLATE/integration.md @@ -20,7 +20,7 @@ BEFORE SUBMITTING AN ISSUE: **Environments:** -- Prettier Version: 3.2.2 +- Prettier Version: 3.2.3 - Running Prettier via: - Runtime: - Operating System: diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a65d7de2430..9c3c1f0d64d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,51 @@ +# 3.2.3 + +[diff](https://github.com/prettier/prettier/compare/3.2.2...3.2.3) + +#### Throw errors for invalid code ([#15881](https://github.com/prettier/prettier/pull/15881) by [@fisker](https://github.com/fisker), [@Josh-Cena](https://github.com/Josh-Cena), [@auvred](https://github.com/auvred)) + + +```ts +// Input +1++; + +// Prettier 3.2.2 +1++; + +// Prettier 3.2.3 +SyntaxError: Invalid left-hand side expression in unary operation (1:1) +> 1 | 1++; + | ^ +``` + + +```ts +// Input +try {} catch (error = 1){} + +// Prettier 3.2.2 +try { +} catch (error) {} + +// Prettier 3.2.3 +SyntaxError: Catch clause variable cannot have an initializer. (1:23) +> 1 | try {} catch (error = 1){} + | ^ +``` + +#### Fix parser inference ([#15927](https://github.com/prettier/prettier/pull/15927) by [@fisker](https://github.com/fisker)) + + +```console +// Prettier 3.2.2 +prettier --file-info tsconfig.json +{ "ignored": false, "inferredParser": "json" } + +// Prettier 3.2.3 +prettier --file-info tsconfig.json +{ "ignored": false, "inferredParser": "jsonc" } +``` + # 3.2.2 [diff](https://github.com/prettier/prettier/compare/3.2.1...3.2.2) diff --git a/docs/browser.md b/docs/browser.md index ff257f9ad080..1a02c9cdb0ce 100644 --- a/docs/browser.md +++ b/docs/browser.md @@ -18,7 +18,7 @@ Required options: - **[`parser`](options.md#parser) (or [`filepath`](options.md#file-path))**: One of these options has to be specified for Prettier to know which parser to use. -- **`plugins`**: Unlike the `format` function from the [Node.js-based API](api.md#prettierformatsource--options), this function doesn’t load plugins automatically. The `plugins` option is required because all the parsers included in the Prettier package come as plugins (for reasons of file size). These plugins are files in . Note that `estree` plugin should be loaded when printing JavaScript, TypeScript, Flow, or JSON. +- **`plugins`**: Unlike the `format` function from the [Node.js-based API](api.md#prettierformatsource--options), this function doesn’t load plugins automatically. The `plugins` option is required because all the parsers included in the Prettier package come as plugins (for reasons of file size). These plugins are files in . Note that `estree` plugin should be loaded when printing JavaScript, TypeScript, Flow, or JSON. You need to load the ones that you’re going to use and pass them to `prettier.format` using the `plugins` option. @@ -29,8 +29,8 @@ See below for examples. ### Global ```html - - + + - + +