Merge branch 'main' into next
# Conflicts: # docs/browser.md # package.json # tests/format/typescript/decorators/jsfmt.spec.js # yarn.lock
This commit is contained in:
commit
9329924de4
15 files changed
+193
-92
No files matched your search
@@ -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.7
|
||||
0e26a75ebf0cb5b436f6a2d26a7bb88d04f23b90
|
||||
# 2.8.6
|
||||
0461cdd8149f0bb9bb95dfac5faed75b47f77689
|
||||
# 2.8.5
|
||||
|
||||
@@ -26,7 +26,7 @@ Don't fill the form below manually! Let a program create a report for you:
|
||||
|
||||
-->
|
||||
|
||||
**Prettier 2.8.6**
|
||||
**Prettier 2.8.7**
|
||||
[Playground link](https://prettier.io/playground/#.....)
|
||||
|
||||
```sh
|
||||
|
||||
@@ -20,7 +20,7 @@ BEFORE SUBMITTING AN ISSUE:
|
||||
|
||||
**Environments:**
|
||||
|
||||
- Prettier Version: 2.8.6
|
||||
- Prettier Version: 2.8.7
|
||||
- Running Prettier via: <!-- CLI, Node.js API, Browser API, etc. -->
|
||||
- Runtime: <!-- Node.js v14, Chrome v83, etc. -->
|
||||
- Operating System: <!-- Windows, Linux, macOS, etc. -->
|
||||
|
||||
@@ -1,3 +1,39 @@
|
||||
# 2.8.7
|
||||
|
||||
[diff](https://github.com/prettier/prettier/compare/2.8.6...2.8.7)
|
||||
|
||||
#### Allow multiple decorators on same getter/setter ([#14584](https://github.com/prettier/prettier/pull/14584) by [@fisker](https://github.com/fisker))
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```ts
|
||||
// Input
|
||||
class A {
|
||||
@decorator()
|
||||
get foo () {}
|
||||
|
||||
@decorator()
|
||||
set foo (value) {}
|
||||
}
|
||||
|
||||
// Prettier 2.8.6
|
||||
SyntaxError: Decorators cannot be applied to multiple get/set accessors of the same name. (5:3)
|
||||
3 | get foo () {}
|
||||
4 |
|
||||
> 5 | @decorator()
|
||||
| ^^^^^^^^^^^^
|
||||
6 | set foo (value) {}
|
||||
7 | }
|
||||
|
||||
// Prettier 2.8.7
|
||||
class A {
|
||||
@decorator()
|
||||
get foo() {}
|
||||
|
||||
@decorator()
|
||||
set foo(value) {}
|
||||
}
|
||||
```
|
||||
|
||||
# 2.8.6
|
||||
|
||||
[diff](https://github.com/prettier/prettier/compare/2.8.5...2.8.6)
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#### Format TS expressions when any script tag has `lang="ts"` (#14587 by @seiyab)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```vue
|
||||
<!-- Input -->
|
||||
<script></script>
|
||||
<script setup lang="ts"></script>
|
||||
<template>
|
||||
{{ (x as number).toFixed(2) }}
|
||||
</template>
|
||||
|
||||
<!-- Prettier stable -->
|
||||
<script></script>
|
||||
<script setup lang="ts"></script>
|
||||
<template>
|
||||
{{ (x as number).toFixed(2) }}
|
||||
</template>
|
||||
|
||||
<!-- Prettier main -->
|
||||
<script></script>
|
||||
<script setup lang="ts"></script>
|
||||
<template>
|
||||
{{ (x as number).toFixed(2) }}
|
||||
</template>
|
||||
```
|
||||
+14
-14
@@ -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.6/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.7/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.6/standalone.js"></script>
|
||||
<script src="https://unpkg.com/prettier@2.8.6/plugins/graphql.js"></script>
|
||||
<script src="https://unpkg.com/prettier@2.8.7/standalone.js"></script>
|
||||
<script src="https://unpkg.com/prettier@2.8.7/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.6/standalone.mjs";
|
||||
import pluginGraphql from "https://unpkg.com/prettier@2.8.6/plugins/graphql.mjs";
|
||||
import * as prettier from "https://unpkg.com/prettier@2.8.7/standalone.mjs";
|
||||
import pluginGraphql from "https://unpkg.com/prettier@2.8.7/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.6/standalone.js",
|
||||
"https://unpkg.com/prettier@2.8.6/plugins/graphql.js",
|
||||
"https://unpkg.com/prettier@2.8.7/standalone.js",
|
||||
"https://unpkg.com/prettier@2.8.7/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.6/standalone.js");
|
||||
importScripts("https://unpkg.com/prettier@2.8.6/plugins/graphql.js");
|
||||
importScripts("https://unpkg.com/prettier@2.8.7/standalone.js");
|
||||
importScripts("https://unpkg.com/prettier@2.8.7/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.6/standalone.mjs";
|
||||
import pluginBabel from "https://unpkg.com/prettier@2.8.6/plugins/babel.mjs";
|
||||
import * as prettier from "https://unpkg.com/prettier@2.8.7/standalone.mjs";
|
||||
import pluginBabel from "https://unpkg.com/prettier@2.8.7/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.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";
|
||||
import * as prettier from "https://unpkg.com/prettier@2.8.7/standalone.mjs";
|
||||
import pluginBabel from "https://unpkg.com/prettier@2.8.7/plugins/babel.mjs";
|
||||
import pluginHtml from "https://unpkg.com/prettier@2.8.7/plugins/html.mjs";
|
||||
|
||||
console.log(
|
||||
await prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
|
||||
|
||||
+1
-1
@@ -142,7 +142,7 @@
|
||||
"magic-string": "0.30.0",
|
||||
"npm-run-all": "4.1.5",
|
||||
"path-browserify": "1.0.1",
|
||||
"prettier": "2.8.6",
|
||||
"prettier": "2.8.7",
|
||||
"pretty-bytes": "6.1.0",
|
||||
"rollup-plugin-license": "3.0.1",
|
||||
"semver": "7.3.8",
|
||||
|
||||
@@ -404,18 +404,13 @@ function addIsSpaceSensitive(ast, options) {
|
||||
}
|
||||
|
||||
function markTsScript(ast, options) {
|
||||
if (options.parser === "vue") {
|
||||
const vueScriptTag = ast.children.find((child) =>
|
||||
isVueScriptTag(child, options)
|
||||
options.__should_parse_vue_template_with_ts =
|
||||
options.parser === "vue" &&
|
||||
ast.children.some(
|
||||
(child) =>
|
||||
isVueScriptTag(child, options) &&
|
||||
["ts", "typescript"].includes(child.attrMap.lang)
|
||||
);
|
||||
if (!vueScriptTag) {
|
||||
return;
|
||||
}
|
||||
const { lang } = vueScriptTag.attrMap;
|
||||
if (lang === "ts" || lang === "typescript") {
|
||||
options.__should_parse_vue_template_with_ts = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default preprocess;
|
||||
@@ -67,40 +67,19 @@ function throwErrorForInvalidModifier(node) {
|
||||
const { SyntaxKind } = ts;
|
||||
|
||||
for (const modifier of modifiers) {
|
||||
if (ts.isDecorator(modifier)) {
|
||||
if (!nodeCanBeDecorated(node)) {
|
||||
if (
|
||||
node.kind === SyntaxKind.MethodDeclaration &&
|
||||
// @ts-expect-error -- internal?
|
||||
!ts.nodeIsPresent(node.body)
|
||||
) {
|
||||
throwErrorOnTsNode(
|
||||
modifier,
|
||||
"A decorator can only decorate a method implementation, not an overload."
|
||||
);
|
||||
} else {
|
||||
throwErrorOnTsNode(modifier, "Decorators are not valid here.");
|
||||
}
|
||||
} else if (
|
||||
node.kind === SyntaxKind.GetAccessor ||
|
||||
node.kind === SyntaxKind.SetAccessor
|
||||
) {
|
||||
if (ts.isDecorator(modifier) && !nodeCanBeDecorated(node)) {
|
||||
if (
|
||||
node.kind === SyntaxKind.MethodDeclaration &&
|
||||
// @ts-expect-error -- internal?
|
||||
const accessors = ts.getAllAccessorDeclarations(
|
||||
node.parent.members,
|
||||
node
|
||||
!ts.nodeIsPresent(node.body)
|
||||
) {
|
||||
throwErrorOnTsNode(
|
||||
modifier,
|
||||
"A decorator can only decorate a method implementation, not an overload."
|
||||
);
|
||||
if (
|
||||
// @ts-expect-error -- internal?
|
||||
ts.hasDecorators(accessors.firstAccessor) &&
|
||||
node === accessors.secondAccessor
|
||||
) {
|
||||
throwErrorOnTsNode(
|
||||
modifier,
|
||||
"Decorators cannot be applied to multiple get/set accessors of the same name."
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
throwErrorOnTsNode(modifier, "Decorators are not valid here.");
|
||||
}
|
||||
|
||||
if (modifier.kind !== SyntaxKind.ReadonlyKeyword) {
|
||||
|
||||
@@ -30,7 +30,7 @@ exports[`abstract-method.ts [typescript] format 1`] = `
|
||||
5 |"
|
||||
`;
|
||||
|
||||
exports[`accessor.ts [babel-ts] format 1`] = `
|
||||
exports[`accessor.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
@@ -56,17 +56,6 @@ class A {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`accessor.ts [typescript] format 1`] = `
|
||||
"Decorators cannot be applied to multiple get/set accessors of the same name. (4:5)
|
||||
2 | @foo()
|
||||
3 | get a() {return 1}
|
||||
> 4 | @bar()
|
||||
| ^^^^^^
|
||||
5 | set a(v) {}
|
||||
6 | }
|
||||
7 |"
|
||||
`;
|
||||
|
||||
exports[`argument-list-preserve-line.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
run_spec(import.meta, ["typescript"], {
|
||||
errors: {
|
||||
typescript: ["abstract-method.ts", "accessor.ts"],
|
||||
typescript: ["abstract-method.ts"],
|
||||
"babel-ts": ["issue-9102.ts"],
|
||||
},
|
||||
});
|
||||
@@ -70,6 +70,60 @@ export default {
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`lang-ts-multiple-script-tags.vue format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["vue"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script setup lang="ts">
|
||||
let x: string | number = 1
|
||||
</script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<template>
|
||||
<span
|
||||
v-if=" (x as string).length > 0"
|
||||
v-for="a in [1,2, 3,4,5].map( (x : number) => x * x)"
|
||||
:foo=" (x as number).toFixed( 2) "
|
||||
>
|
||||
{{ (x as number).toFixed(2) }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
=====================================output=====================================
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script setup lang="ts">
|
||||
let x: string | number = 1;
|
||||
</script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<template>
|
||||
<span
|
||||
v-if=" (x as string).length > 0"
|
||||
v-for="a in [1,2, 3,4,5].map( (x : number) => x * x)"
|
||||
:foo=" (x as number).toFixed( 2) "
|
||||
>
|
||||
{{ (x as number).toFixed(2) }}
|
||||
</span>
|
||||
</template>
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`lang-tsx.vue format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["vue"]
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script setup lang="ts">
|
||||
let x: string | number = 1
|
||||
</script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<script></script>
|
||||
<template>
|
||||
<span
|
||||
v-if=" (x as string).length > 0"
|
||||
v-for="a in [1,2, 3,4,5].map( (x : number) => x * x)"
|
||||
:foo=" (x as number).toFixed( 2) "
|
||||
>
|
||||
{{ (x as number).toFixed(2) }}
|
||||
</span>
|
||||
</template>
|
||||
@@ -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.6/> and
|
||||
- `parser-*.mjs` in <https://unpkg.com/browse/prettier@2.8.6/esm/>
|
||||
- `parser-*.js` in <https://unpkg.com/browse/prettier@2.8.7/> and
|
||||
- `parser-*.mjs` in <https://unpkg.com/browse/prettier@2.8.7/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.6/standalone.js"></script>
|
||||
<script src="https://unpkg.com/prettier@2.8.6/parser-graphql.js"></script>
|
||||
<script src="https://unpkg.com/prettier@2.8.7/standalone.js"></script>
|
||||
<script src="https://unpkg.com/prettier@2.8.7/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.6/esm/standalone.mjs";
|
||||
import parserGraphql from "https://unpkg.com/prettier@2.8.6/esm/parser-graphql.mjs";
|
||||
import prettier from "https://unpkg.com/prettier@2.8.7/esm/standalone.mjs";
|
||||
import parserGraphql from "https://unpkg.com/prettier@2.8.7/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.6/standalone.js",
|
||||
"https://unpkg.com/prettier@2.8.6/parser-graphql.js",
|
||||
"https://unpkg.com/prettier@2.8.7/standalone.js",
|
||||
"https://unpkg.com/prettier@2.8.7/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.6/standalone.js");
|
||||
importScripts("https://unpkg.com/prettier@2.8.6/parser-graphql.js");
|
||||
importScripts("https://unpkg.com/prettier@2.8.7/standalone.js");
|
||||
importScripts("https://unpkg.com/prettier@2.8.7/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.6/esm/standalone.mjs";
|
||||
import parserBabel from "https://unpkg.com/prettier@2.8.6/esm/parser-babel.mjs";
|
||||
import prettier from "https://unpkg.com/prettier@2.8.7/esm/standalone.mjs";
|
||||
import parserBabel from "https://unpkg.com/prettier@2.8.7/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.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";
|
||||
import prettier from "https://unpkg.com/prettier@2.8.7/esm/standalone.mjs";
|
||||
import parserBabel from "https://unpkg.com/prettier@2.8.7/esm/parser-babel.mjs";
|
||||
import parserHtml from "https://unpkg.com/prettier@2.8.7/esm/parser-html.mjs";
|
||||
|
||||
console.log(
|
||||
prettier.format("const html=/* HTML */ `<DIV> </DIV>`", {
|
||||
|
||||
@@ -6698,12 +6698,12 @@ __metadata:
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
"prettier@npm:2.8.6":
|
||||
version: 2.8.6
|
||||
resolution: "prettier@npm:2.8.6"
|
||||
"prettier@npm:2.8.7":
|
||||
version: 2.8.7
|
||||
resolution: "prettier@npm:2.8.7"
|
||||
bin:
|
||||
prettier: bin-prettier.js
|
||||
checksum: 8ac94fa67aec0e65743ea15ebf954ef2f1e52638abd129dc04e8b49e8bb3224c0233c98df6b5c98efd31bd2a43866590486559438ee4ead09dc81be389068572
|
||||
checksum: fdc8f2616f099f5f0d685907f4449a70595a0fc1d081a88919604375989e0d5e9168d6121d8cc6861f21990b31665828e00472544d785d5940ea08a17660c3a6
|
||||
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.6
|
||||
prettier: 2.8.7
|
||||
pretty-bytes: 6.1.0
|
||||
regexp-util: 1.2.2
|
||||
remark-footnotes: 2.0.0
|
||||
|
||||
Reference in new issue
Block a user