Merge branch 'main' into next

# Conflicts:
#	docs/browser.md
#	package.json
#	src/language-js/parse/postprocess/typescript.js
#	tests/format/typescript/type-arguments-bit-shift-left-like/jsfmt.spec.js
#	yarn.lock
This commit is contained in:
fisker committed 2023-03-21 16:31:06 +08:00
commit cfc8bbc662
15 files changed
+139 -128

No files matched your search

+2
View File
@@ -5,6 +5,8 @@
# See https://git-scm.com/docs/git-blame#Documentation/git-blame.txt---ignore-revs-fileltfilegt
# Prettier bump after release
# 2.8.6
0461cdd8149f0bb9bb95dfac5faed75b47f77689
# 2.8.5
c1808e86a3c7c2c8f43093f99e78fce3b6d0a97d
# 2.8.4
+1 -1
View File
@@ -26,7 +26,7 @@ Don't fill the form below manually! Let a program create a report for you:
-->
**Prettier 2.8.5**
**Prettier 2.8.6**
[Playground link](https://prettier.io/playground/#.....)
```sh
+1 -1
View File
@@ -20,7 +20,7 @@ BEFORE SUBMITTING AN ISSUE:
**Environments:**
- Prettier Version: 2.8.5
- Prettier Version: 2.8.6
- Running Prettier via: <!-- CLI, Node.js API, Browser API, etc. -->
- Runtime: <!-- Node.js v14, Chrome v83, etc. -->
- Operating System: <!-- Windows, Linux, macOS, etc. -->
+29
View File
@@ -1,3 +1,32 @@
# 2.8.6
[diff](https://github.com/prettier/prettier/compare/2.8.5...2.8.6)
#### Allow decorators on private members and class expressions ([#14548](https://github.com/prettier/prettier/pull/14548) by [@fisker](https://github.com/fisker))
<!-- prettier-ignore -->
```ts
// Input
class A {
@decorator()
#privateMethod () {}
}
// Prettier 2.8.5
SyntaxError: Decorators are not valid here. (2:3)
1 | class A {
> 2 | @decorator()
| ^^^^^^^^^^^^
3 | #privateMethod () {}
4 | }
// Prettier 2.8.6
class A {
@decorator()
#privateMethod() {}
}
```
# 2.8.5
[diff](https://github.com/prettier/prettier/compare/2.8.4...2.8.5)
+14 -14
View File
@@ -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 <https://unpkg.com/browse/prettier@2.8.5/plugins/>
- **`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 <https://unpkg.com/browse/prettier@2.8.6/plugins/>
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
<script src="https://unpkg.com/prettier@2.8.5/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.8.5/plugins/graphql.js"></script>
<script src="https://unpkg.com/prettier@2.8.6/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.8.6/plugins/graphql.js"></script>
<script>
(async () => {
const formatted = await prettier.format("type Query { hello: String }", {
@@ -47,8 +47,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack
```html
<script type="module">
import * as prettier from "https://unpkg.com/prettier@2.8.5/standalone.mjs";
import pluginGraphql from "https://unpkg.com/prettier@2.8.5/plugins/graphql.mjs";
import * as prettier from "https://unpkg.com/prettier@2.8.6/standalone.mjs";
import pluginGraphql from "https://unpkg.com/prettier@2.8.6/plugins/graphql.mjs";
const formatted = await prettier.format("type Query { hello: String }", {
parser: "graphql",
@@ -61,8 +61,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack
```js
define([
"https://unpkg.com/prettier@2.8.5/standalone.js",
"https://unpkg.com/prettier@2.8.5/plugins/graphql.js",
"https://unpkg.com/prettier@2.8.6/standalone.js",
"https://unpkg.com/prettier@2.8.6/plugins/graphql.js",
], async (prettier, ...plugins) => {
const formatted = await prettier.format("type Query { hello: String }", {
parser: "graphql",
@@ -89,8 +89,8 @@ This syntax doesn’t necessarily work in the browser, but it can be used when b
### Worker
```js
importScripts("https://unpkg.com/prettier@2.8.5/standalone.js");
importScripts("https://unpkg.com/prettier@2.8.5/plugins/graphql.js");
importScripts("https://unpkg.com/prettier@2.8.6/standalone.js");
importScripts("https://unpkg.com/prettier@2.8.6/plugins/graphql.js");
(async () => {
const formatted = await prettier.format("type Query { hello: String }", {
parser: "graphql",
@@ -105,8 +105,8 @@ If you want to format [embedded code](options.md#embedded-language-formatting),
```html
<script type="module">
import * as prettier from "https://unpkg.com/prettier@2.8.5/standalone.mjs";
import pluginBabel from "https://unpkg.com/prettier@2.8.5/plugins/babel.mjs";
import * as prettier from "https://unpkg.com/prettier@2.8.6/standalone.mjs";
import pluginBabel from "https://unpkg.com/prettier@2.8.6/plugins/babel.mjs";
console.log(
await prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
@@ -122,9 +122,9 @@ The HTML code embedded in JavaScript stays unformatted because the `html` parser
```html
<script type="module">
import * as prettier from "https://unpkg.com/prettier@2.8.5/standalone.mjs";
import pluginBabel from "https://unpkg.com/prettier@2.8.5/plugins/babel.mjs";
import pluginHtml from "https://unpkg.com/prettier@2.8.5/plugins/html.mjs";
import * as prettier from "https://unpkg.com/prettier@2.8.6/standalone.mjs";
import pluginBabel from "https://unpkg.com/prettier@2.8.6/plugins/babel.mjs";
import pluginHtml from "https://unpkg.com/prettier@2.8.6/plugins/html.mjs";
console.log(
await prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
+1 -1
View File
@@ -142,7 +142,7 @@
"magic-string": "0.30.0",
"npm-run-all": "4.1.5",
"path-browserify": "1.0.1",
"prettier": "2.8.5",
"prettier": "2.8.6",
"pretty-bytes": "6.1.0",
"rollup-plugin-license": "3.0.1",
"semver": "7.3.8",
+15 -13
View File
@@ -45,6 +45,18 @@ function throwErrorForInvalidAbstractProperty(tsNode, esTreeNode) {
);
}
function nodeCanBeDecorated(node) {
return [true, false].some((useLegacyDecorators) =>
// @ts-expect-error -- internal?
ts.nodeCanBeDecorated(
useLegacyDecorators,
node,
node.parent,
node.parent.parent
)
);
}
// Based on `checkGrammarModifiers` function in `typescript`
function throwErrorForInvalidModifier(node) {
const { modifiers } = node;
@@ -56,16 +68,7 @@ function throwErrorForInvalidModifier(node) {
for (const modifier of modifiers) {
if (ts.isDecorator(modifier)) {
const legacyDecorators = true;
if (
// @ts-expect-error -- internal?
!ts.nodeCanBeDecorated(
legacyDecorators,
node,
node.parent,
node.parent.parent
)
) {
if (!nodeCanBeDecorated(node)) {
if (
node.kind === SyntaxKind.MethodDeclaration &&
// @ts-expect-error -- internal?
@@ -79,9 +82,8 @@ function throwErrorForInvalidModifier(node) {
throwErrorOnTsNode(modifier, "Decorators are not valid here.");
}
} else if (
legacyDecorators &&
(node.kind === SyntaxKind.GetAccessor ||
node.kind === SyntaxKind.SetAccessor)
node.kind === SyntaxKind.GetAccessor ||
node.kind === SyntaxKind.SetAccessor
) {
// @ts-expect-error -- internal?
const accessors = ts.getAllAccessorDeclarations(
@@ -24,14 +24,6 @@ exports[`arguments.js [flow] format 1`] = `
3 |"
`;
exports[`arguments.js [typescript] format 1`] = `
"Decorators are not valid here. (1:13)
> 1 | console.log(@deco class Foo {})
| ^^^^^
2 | console.log(@deco class {})
3 |"
`;
exports[`arguments.js - {"semi":false} [acorn] format 1`] = `
"Unexpected character '@' (1:13)
> 1 | console.log(@deco class Foo {})
@@ -56,14 +48,6 @@ exports[`arguments.js - {"semi":false} [flow] format 1`] = `
3 |"
`;
exports[`arguments.js - {"semi":false} [typescript] format 1`] = `
"Decorators are not valid here. (1:13)
> 1 | console.log(@deco class Foo {})
| ^^^^^
2 | console.log(@deco class {})
3 |"
`;
exports[`arguments.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
@@ -136,15 +120,6 @@ exports[`class-expression.js [flow] format 1`] = `
4 | (@deco class Foo {});"
`;
exports[`class-expression.js [typescript] format 1`] = `
"Decorators are not valid here. (1:13)
> 1 | const a1 = (@deco class Foo {});
| ^^^^^
2 | const a2 = (@deco class {});
3 |
4 | (@deco class Foo {});"
`;
exports[`class-expression.js - {"semi":false} [acorn] format 1`] = `
"Unexpected character '@' (1:13)
> 1 | const a1 = (@deco class Foo {});
@@ -172,15 +147,6 @@ exports[`class-expression.js - {"semi":false} [flow] format 1`] = `
4 | (@deco class Foo {});"
`;
exports[`class-expression.js - {"semi":false} [typescript] format 1`] = `
"Decorators are not valid here. (1:13)
> 1 | const a1 = (@deco class Foo {});
| ^^^^^
2 | const a2 = (@deco class {});
3 |
4 | (@deco class Foo {});"
`;
exports[`class-expression.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
@@ -320,14 +286,6 @@ exports[`member-expression.js [flow] format 1`] = `
3 |"
`;
exports[`member-expression.js [typescript] format 1`] = `
"Decorators are not valid here. (1:2)
> 1 | (@deco class Foo {}).name;
| ^^^^^
2 | (@deco class {}).name;
3 |"
`;
exports[`member-expression.js - {"semi":false} [acorn] format 1`] = `
"Unexpected character '@' (1:2)
> 1 | (@deco class Foo {}).name;
@@ -352,14 +310,6 @@ exports[`member-expression.js - {"semi":false} [flow] format 1`] = `
3 |"
`;
exports[`member-expression.js - {"semi":false} [typescript] format 1`] = `
"Decorators are not valid here. (1:2)
> 1 | (@deco class Foo {}).name;
| ^^^^^
2 | (@deco class {}).name;
3 |"
`;
exports[`member-expression.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
@@ -432,15 +382,6 @@ exports[`super-class.js [flow] format 1`] = `
4 |"
`;
exports[`super-class.js [typescript] format 1`] = `
"Decorators are not valid here. (1:20)
> 1 | class Foo extends (@deco class Foo {}){}
| ^^^^^
2 |
3 | class Foo extends (@deco class {}){}
4 |"
`;
exports[`super-class.js - {"semi":false} [acorn] format 1`] = `
"Unexpected character '@' (1:20)
> 1 | class Foo extends (@deco class Foo {}){}
@@ -468,15 +409,6 @@ exports[`super-class.js - {"semi":false} [flow] format 1`] = `
4 |"
`;
exports[`super-class.js - {"semi":false} [typescript] format 1`] = `
"Decorators are not valid here. (1:20)
> 1 | class Foo extends (@deco class Foo {}){}
| ^^^^^
2 |
3 | class Foo extends (@deco class {}){}
4 |"
`;
exports[`super-class.js - {"semi":false} format 1`] = `
====================================options=====================================
parsers: ["babel", "flow", "typescript"]
@@ -1,6 +1,5 @@
const errors = {
flow: true,
typescript: true,
acorn: true,
espree: true,
};
@@ -497,6 +497,48 @@ class MyContainerComponent {
================================================================================
`;
exports[`legacy.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
| printWidth
=====================================input======================================
[
@decorator() class {},
@decorator() class A {},
];
class A {
@decorator() accessor #field;
}
class B {
@decorator() #field () {}
}
=====================================output=====================================
[
(
@decorator()
class {}
),
(
@decorator()
class A {}
),
];
class A {
@decorator() accessor #field;
}
class B {
@decorator() #field() {}
}
================================================================================
`;
exports[`mobx.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
@@ -0,0 +1,12 @@
[
@decorator() class {},
@decorator() class A {},
];
class A {
@decorator() accessor #field;
}
class B {
@decorator() #field () {}
}
@@ -49,7 +49,7 @@ exports[`3.ts [typescript] format 1`] = `
2 |"
`;
exports[`4.ts [babel-ts] format 1`] = `
exports[`4.ts format 1`] = `
====================================options=====================================
parsers: ["typescript"]
printWidth: 80
@@ -66,13 +66,6 @@ printWidth: 80
================================================================================
`;
exports[`4.ts [typescript] format 1`] = `
"Decorators are not valid here. (1:2)
> 1 | (@f<<T>(v: T) => void>() class {});
| ^^^^^^^^^^^^^^^^^^^^^^^
2 |"
`;
exports[`5.tsx [babel-ts] format 1`] = `
====================================options=====================================
parsers: ["typescript"]
@@ -1,3 +1,3 @@
run_spec(import.meta, ["typescript"], {
errors: { typescript: ["3.ts", "4.ts", "5.tsx"] },
errors: { typescript: ["3.ts", "5.tsx"] },
});
@@ -21,8 +21,8 @@ Required options:
- **`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 named
- `parser-*.js` in <https://unpkg.com/browse/prettier@2.8.5/> and
- `parser-*.mjs` in <https://unpkg.com/browse/prettier@2.8.5/esm/>
- `parser-*.js` in <https://unpkg.com/browse/prettier@2.8.6/> and
- `parser-*.mjs` in <https://unpkg.com/browse/prettier@2.8.6/esm/>
You need to load the ones that you’re going to use and pass them to `prettier.format` using the `plugins` option.
@@ -33,8 +33,8 @@ See below for examples.
### Global
```html
<script src="https://unpkg.com/prettier@2.8.5/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.8.5/parser-graphql.js"></script>
<script src="https://unpkg.com/prettier@2.8.6/standalone.js"></script>
<script src="https://unpkg.com/prettier@2.8.6/parser-graphql.js"></script>
<script>
prettier.format("type Query { hello: String }", {
parser: "graphql",
@@ -49,8 +49,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack
```html
<script type="module">
import prettier from "https://unpkg.com/prettier@2.8.5/esm/standalone.mjs";
import parserGraphql from "https://unpkg.com/prettier@2.8.5/esm/parser-graphql.mjs";
import prettier from "https://unpkg.com/prettier@2.8.6/esm/standalone.mjs";
import parserGraphql from "https://unpkg.com/prettier@2.8.6/esm/parser-graphql.mjs";
prettier.format("type Query { hello: String }", {
parser: "graphql",
@@ -63,8 +63,8 @@ Note that the [`unpkg` field](https://unpkg.com/#examples) in Prettier’s `pack
```js
define([
"https://unpkg.com/prettier@2.8.5/standalone.js",
"https://unpkg.com/prettier@2.8.5/parser-graphql.js",
"https://unpkg.com/prettier@2.8.6/standalone.js",
"https://unpkg.com/prettier@2.8.6/parser-graphql.js",
], (prettier, ...plugins) => {
prettier.format("type Query { hello: String }", {
parser: "graphql",
@@ -89,8 +89,8 @@ This syntax doesn’t necessarily work in the browser, but it can be used when b
### Worker
```js
importScripts("https://unpkg.com/prettier@2.8.5/standalone.js");
importScripts("https://unpkg.com/prettier@2.8.5/parser-graphql.js");
importScripts("https://unpkg.com/prettier@2.8.6/standalone.js");
importScripts("https://unpkg.com/prettier@2.8.6/parser-graphql.js");
prettier.format("type Query { hello: String }", {
parser: "graphql",
plugins: prettierPlugins,
@@ -103,8 +103,8 @@ If you want to format [embedded code](options.md#embedded-language-formatting),
```html
<script type="module">
import prettier from "https://unpkg.com/prettier@2.8.5/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.8.5/esm/parser-babel.mjs";
import prettier from "https://unpkg.com/prettier@2.8.6/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.8.6/esm/parser-babel.mjs";
console.log(
prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
@@ -120,9 +120,9 @@ The HTML code embedded in JavaScript stays unformatted because the `html` parser
```html
<script type="module">
import prettier from "https://unpkg.com/prettier@2.8.5/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.8.5/esm/parser-babel.mjs";
import parserHtml from "https://unpkg.com/prettier@2.8.5/esm/parser-html.mjs";
import prettier from "https://unpkg.com/prettier@2.8.6/esm/standalone.mjs";
import parserBabel from "https://unpkg.com/prettier@2.8.6/esm/parser-babel.mjs";
import parserHtml from "https://unpkg.com/prettier@2.8.6/esm/parser-html.mjs";
console.log(
prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
+5 -5
View File
@@ -6698,12 +6698,12 @@ __metadata:
languageName: node
linkType: hard
"prettier@npm:2.8.5":
version: 2.8.5
resolution: "prettier@npm:2.8.5"
"prettier@npm:2.8.6":
version: 2.8.6
resolution: "prettier@npm:2.8.6"
bin:
prettier: bin-prettier.js
checksum: b7f8d30e14061e0478bc5a59d4d889688d804c173a0daa91b1b85dc08eef5eb6956d1b59f4037770776fda5b967f6c9ca3b7a8a43c50bedb4c7b182029f865aa
checksum: 8ac94fa67aec0e65743ea15ebf954ef2f1e52638abd129dc04e8b49e8bb3224c0233c98df6b5c98efd31bd2a43866590486559438ee4ead09dc81be389068572
languageName: node
linkType: hard
@@ -6807,7 +6807,7 @@ __metadata:
postcss-scss: 4.0.6
postcss-selector-parser: 2.2.3
postcss-values-parser: 2.0.1
prettier: 2.8.5
prettier: 2.8.6
pretty-bytes: 6.1.0
regexp-util: 1.2.2
remark-footnotes: 2.0.0