Support TypeScript 4.5 syntax (#11813)
* Update dependencies * Add tests for type-only module specifiers * Add tests for ts import assertions * Add tests for ts private-fields-in-in * Update changelog * Update misc tests * Update SYNTAX_KIND_PROPERTY_DEFINITION * List typescript from error list
This commit is contained in:
1 parent
711f38132e
commit
9e1038c0eb
19 files changed
+175
-90
No files matched your search
@@ -1,11 +1,9 @@
|
||||
#### Support TypeScript 4.5 (#11721, #11723 by @sosukesuzuki)
|
||||
#### Support TypeScript 4.5 (#11721, #11723, #11813 by @sosukesuzuki)
|
||||
|
||||
Support new TypeScript 4.5 features.
|
||||
|
||||
##### [`type` Modifiers on Import Names](https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-beta/#type-on-import-names)
|
||||
|
||||
Only supported by `babel-ts`.
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```ts
|
||||
// Input
|
||||
@@ -19,6 +17,56 @@ import { type A } from "mod";
|
||||
|
||||
```
|
||||
|
||||
##### [Private Field Presence Checks](https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-rc/#private-field-presence-checks)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```ts
|
||||
// Input
|
||||
class Foo {
|
||||
#prop1;
|
||||
method() {
|
||||
return #prop1 in this;
|
||||
}
|
||||
}
|
||||
|
||||
// Prettier stable
|
||||
SyntaxError: Private identifiers are not allowed outside class bodies. (4:12)
|
||||
2 | #prop1;
|
||||
3 | method() {
|
||||
> 4 | return #prop1 in this;
|
||||
| ^
|
||||
5 | }
|
||||
6 | }
|
||||
7 |
|
||||
|
||||
// Prettier main
|
||||
class Foo {
|
||||
#prop1;
|
||||
method() {
|
||||
return #prop1 in this;
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
##### [Import Assertions](https://devblogs.microsoft.com/typescript/announcing-typescript-4-5-rc/#import-assertions)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```ts
|
||||
// Input
|
||||
import obj from "./something.json" assert { type: "json" };
|
||||
|
||||
// Prettier stable
|
||||
SyntaxError: ';' expected. (1:36)
|
||||
> 1 | import obj from "./something.json" assert { type: "json" };
|
||||
| ^
|
||||
2 |
|
||||
|
||||
// Prettier main
|
||||
import obj from "./something.json" assert { type: "json" };
|
||||
|
||||
```
|
||||
|
||||
##### Handle `.mts` and `.cts`
|
||||
|
||||
Handle new file extensions `.mts` and `.cts`.
|
||||
+2
-2
@@ -25,7 +25,7 @@
|
||||
"@babel/parser": "7.16.3",
|
||||
"@glimmer/syntax": "0.83.1",
|
||||
"@iarna/toml": "2.2.5",
|
||||
"@typescript-eslint/typescript-estree": "5.3.1",
|
||||
"@typescript-eslint/typescript-estree": "5.4.0",
|
||||
"angular-estree-parser": "2.5.0",
|
||||
"angular-html-parser": "1.8.0",
|
||||
"camelcase": "6.2.0",
|
||||
@@ -79,7 +79,7 @@
|
||||
"semver": "7.3.5",
|
||||
"string-width": "4.2.2",
|
||||
"strip-ansi": "6.0.0",
|
||||
"typescript": "4.4.4",
|
||||
"typescript": "4.5.1-rc",
|
||||
"unicode-regex": "3.0.0",
|
||||
"unified": "9.2.1",
|
||||
"vnopts": "1.0.2",
|
||||
|
||||
@@ -41,7 +41,7 @@ function throwErrorForInvalidDecorator(
|
||||
// Values of abstract property is removed since `@typescript-eslint/typescript-estree` v5
|
||||
// https://github.com/typescript-eslint/typescript-eslint/releases/tag/v5.0.0
|
||||
function throwErrorForInvalidAbstractProperty(tsNode, esTreeNode) {
|
||||
const SYNTAX_KIND_PROPERTY_DEFINITION = 165;
|
||||
const SYNTAX_KIND_PROPERTY_DEFINITION = 166;
|
||||
const SYNTAX_KIND_ABSTRACT_KEYWORD = 126;
|
||||
if (
|
||||
tsNode.kind !== SYNTAX_KIND_PROPERTY_DEFINITION ||
|
||||
|
||||
@@ -21,13 +21,6 @@ exports[`assertions.js [meriyah] format 1`] = `
|
||||
2 |"
|
||||
`;
|
||||
|
||||
exports[`assertions.js [typescript] format 1`] = `
|
||||
"Dynamic import must have one specifier as an argument. (1:8)
|
||||
> 1 | import(\\"./foo.json\\", { assert: { type: \\"json\\" } });
|
||||
| ^
|
||||
2 |"
|
||||
`;
|
||||
|
||||
exports[`assertions.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel", "flow", "typescript"]
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
run_spec(__dirname, ["babel", "flow", "typescript"], {
|
||||
errors: {
|
||||
flow: ["assertions.js"],
|
||||
typescript: ["assertions.js"],
|
||||
espree: ["assertions.js"],
|
||||
meriyah: ["assertions.js"],
|
||||
},
|
||||
|
||||
@@ -16,7 +16,7 @@ exports[`dynamic-import.js [meriyah] format 1`] = `
|
||||
|
||||
exports[`dynamic-import.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
parsers: ["babel", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
@@ -50,7 +50,7 @@ exports[`empty.js [meriyah] format 1`] = `
|
||||
|
||||
exports[`empty.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
parsers: ["babel", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
@@ -89,7 +89,7 @@ exports[`multi-types.js [meriyah] format 1`] = `
|
||||
|
||||
exports[`multi-types.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
parsers: ["babel", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
@@ -117,7 +117,7 @@ exports[`non-type.js [meriyah] format 1`] = `
|
||||
|
||||
exports[`non-type.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
parsers: ["babel", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
@@ -131,7 +131,7 @@ import foo from "foo.json" assert { lazy: "true" };
|
||||
|
||||
exports[`not-import-assertions.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
parsers: ["babel", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
@@ -165,7 +165,7 @@ exports[`re-export.js [meriyah] format 1`] = `
|
||||
|
||||
exports[`re-export.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
parsers: ["babel", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
@@ -197,7 +197,7 @@ exports[`static-import.js [meriyah] format 1`] = `
|
||||
|
||||
exports[`static-import.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
parsers: ["babel", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
@@ -225,7 +225,7 @@ exports[`without-from.js [meriyah] format 1`] = `
|
||||
|
||||
exports[`without-from.js format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel"]
|
||||
parsers: ["babel", "typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
run_spec(__dirname, ["babel"], {
|
||||
run_spec(__dirname, ["babel", "typescript"], {
|
||||
errors: {
|
||||
espree: [
|
||||
"dynamic-import.js",
|
||||
|
||||
@@ -37,7 +37,7 @@ exports[`snippet: #0 [meriyah] format 1`] = `
|
||||
`;
|
||||
|
||||
exports[`snippet: #0 [typescript] format 1`] = `
|
||||
"Dynamic import must have one specifier as an argument. (1:8)
|
||||
"Dynamic import requires exactly one or two arguments. (1:8)
|
||||
> 1 | import();
|
||||
| ^"
|
||||
`;
|
||||
@@ -79,7 +79,7 @@ exports[`snippet: #1 [meriyah] format 1`] = `
|
||||
`;
|
||||
|
||||
exports[`snippet: #1 [typescript] format 1`] = `
|
||||
"Dynamic import must have one specifier as an argument. (1:8)
|
||||
"Dynamic import requires exactly one or two arguments. (1:8)
|
||||
> 1 | import(/* comment */);
|
||||
| ^"
|
||||
`;
|
||||
|
||||
@@ -7,13 +7,6 @@ exports[`default-escaped.ts [typescript] format 1`] = `
|
||||
2 |"
|
||||
`;
|
||||
|
||||
exports[`dynamic-import.ts [typescript] format 1`] = `
|
||||
"Dynamic import must have one specifier as an argument. (1:8)
|
||||
> 1 | import('./prettier.mjs', {})
|
||||
| ^
|
||||
2 |"
|
||||
`;
|
||||
|
||||
exports[`export-declare.ts [typescript] format 1`] = `
|
||||
"Declaration or statement expected. (1:1)
|
||||
> 1 | export declare foo;
|
||||
@@ -32,13 +25,6 @@ exports[`invalid-jsx-1.ts [typescript] format 1`] = `
|
||||
|
||||
exports[`issue-8773.ts [typescript] format 1`] = `"Comment \\"comment\\" was not printed. Please report this error!"`;
|
||||
|
||||
exports[`module-attributes-dynamic.ts [typescript] format 1`] = `
|
||||
"Dynamic import must have one specifier as an argument. (1:8)
|
||||
> 1 | import(\\"foo.json\\", { with: { type: \\"json\\" } })
|
||||
| ^
|
||||
2 |"
|
||||
`;
|
||||
|
||||
exports[`module-attributes-static.ts [typescript] format 1`] = `
|
||||
"';' expected. (1:28)
|
||||
> 1 | import foo from \\"foo.json\\" with type: \\"json\\";
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
import('./prettier.mjs', {})
|
||||
@@ -1 +0,0 @@
|
||||
import("foo.json", { with: { type: "json" } })
|
||||
@@ -189,33 +189,3 @@ type T = [x<y>: A];
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`type-only-module-specifiers.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["babel-ts"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
import { type A } from "foo";
|
||||
import { type B, C } from "foo";
|
||||
import { type D, type E } from "foo";
|
||||
import { type E as F } from "foo";
|
||||
|
||||
export { type A } from "foo";
|
||||
export { type B, C } from "foo";
|
||||
export { type D, type E } from "foo";
|
||||
export { type E as F } from "foo";
|
||||
|
||||
=====================================output=====================================
|
||||
import { type A } from "foo";
|
||||
import { type B, C } from "foo";
|
||||
import { type D, type E } from "foo";
|
||||
import { type E as F } from "foo";
|
||||
|
||||
export { type A } from "foo";
|
||||
export { type B, C } from "foo";
|
||||
export { type D, type E } from "foo";
|
||||
export { type E as F } from "foo";
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1,43 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`basic.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
class Person {
|
||||
#name: string;
|
||||
constructor(name: string) {
|
||||
this.#name = name;
|
||||
}
|
||||
|
||||
equals(other: unknown) {
|
||||
return (
|
||||
other &&
|
||||
typeof other === "object" &&
|
||||
#name in other && // <- this is new!
|
||||
this.#name === other.#name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
=====================================output=====================================
|
||||
class Person {
|
||||
#name: string;
|
||||
constructor(name: string) {
|
||||
this.#name = name;
|
||||
}
|
||||
|
||||
equals(other: unknown) {
|
||||
return (
|
||||
other &&
|
||||
typeof other === "object" &&
|
||||
#name in other && // <- this is new!
|
||||
this.#name === other.#name
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1,15 @@
|
||||
class Person {
|
||||
#name: string;
|
||||
constructor(name: string) {
|
||||
this.#name = name;
|
||||
}
|
||||
|
||||
equals(other: unknown) {
|
||||
return (
|
||||
other &&
|
||||
typeof other === "object" &&
|
||||
#name in other && // <- this is new!
|
||||
this.#name === other.#name
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
run_spec(__dirname, ["typescript"]);
|
||||
@@ -0,0 +1,31 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`basic.ts format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["typescript"]
|
||||
printWidth: 80
|
||||
| printWidth
|
||||
=====================================input======================================
|
||||
import { type A } from "foo";
|
||||
import { type B, C } from "foo";
|
||||
import { type D, type E } from "foo";
|
||||
import { type E as F } from "foo";
|
||||
|
||||
export { type A } from "foo";
|
||||
export { type B, C } from "foo";
|
||||
export { type D, type E } from "foo";
|
||||
export { type E as F } from "foo";
|
||||
|
||||
=====================================output=====================================
|
||||
import { type A } from "foo";
|
||||
import { type B, C } from "foo";
|
||||
import { type D, type E } from "foo";
|
||||
import { type E as F } from "foo";
|
||||
|
||||
export { type A } from "foo";
|
||||
export { type B, C } from "foo";
|
||||
export { type D, type E } from "foo";
|
||||
export { type E as F } from "foo";
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
File renamed without changes.
@@ -0,0 +1 @@
|
||||
run_spec(__dirname, ["typescript"]);
|
||||
@@ -1773,10 +1773,10 @@
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.0.0.tgz#25d93f6d269b2d25fdc51a0407eb81ccba60eb0f"
|
||||
integrity sha512-dU/pKBUpehdEqYuvkojmlv0FtHuZnLXFBn16zsDmlFF3LXkOpkAQ2vrKc3BidIIve9EMH2zfTlxqw9XM0fFN5w==
|
||||
|
||||
"@typescript-eslint/types@5.3.1":
|
||||
version "5.3.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.3.1.tgz#afaa715b69ebfcfde3af8b0403bf27527912f9b7"
|
||||
integrity sha512-bG7HeBLolxKHtdHG54Uac750eXuQQPpdJfCYuw4ZI3bZ7+GgKClMWM8jExBtp7NSP4m8PmLRM8+lhzkYnSmSxQ==
|
||||
"@typescript-eslint/types@5.4.0":
|
||||
version "5.4.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.4.0.tgz#b1c130f4b381b77bec19696c6e3366f9781ce8f2"
|
||||
integrity sha512-GjXNpmn+n1LvnttarX+sPD6+S7giO+9LxDIGlRl4wK3a7qMWALOHYuVSZpPTfEIklYjaWuMtfKdeByx0AcaThA==
|
||||
|
||||
"@typescript-eslint/typescript-estree@5.0.0":
|
||||
version "5.0.0"
|
||||
@@ -1791,13 +1791,13 @@
|
||||
semver "^7.3.5"
|
||||
tsutils "^3.21.0"
|
||||
|
||||
"@typescript-eslint/typescript-estree@5.3.1":
|
||||
version "5.3.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.3.1.tgz#50cc4bfb93dc31bc75e08ae52e29fcb786d606ec"
|
||||
integrity sha512-PwFbh/PKDVo/Wct6N3w+E4rLZxUDgsoII/GrWM2A62ETOzJd4M6s0Mu7w4CWsZraTbaC5UQI+dLeyOIFF1PquQ==
|
||||
"@typescript-eslint/typescript-estree@5.4.0":
|
||||
version "5.4.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.4.0.tgz#fe524fb308973c68ebeb7428f3b64499a6ba5fc0"
|
||||
integrity sha512-nhlNoBdhKuwiLMx6GrybPT3SFILm5Gij2YBdPEPFlYNFAXUJWX6QRgvi/lwVoadaQEFsizohs6aFRMqsXI2ewA==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "5.3.1"
|
||||
"@typescript-eslint/visitor-keys" "5.3.1"
|
||||
"@typescript-eslint/types" "5.4.0"
|
||||
"@typescript-eslint/visitor-keys" "5.4.0"
|
||||
debug "^4.3.2"
|
||||
globby "^11.0.4"
|
||||
is-glob "^4.0.3"
|
||||
@@ -1812,12 +1812,12 @@
|
||||
"@typescript-eslint/types" "5.0.0"
|
||||
eslint-visitor-keys "^3.0.0"
|
||||
|
||||
"@typescript-eslint/visitor-keys@5.3.1":
|
||||
version "5.3.1"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.3.1.tgz#c2860ff22939352db4f3806f34b21d8ad00588ba"
|
||||
integrity sha512-3cHUzUuVTuNHx0Gjjt5pEHa87+lzyqOiHXy/Gz+SJOCW1mpw9xQHIIEwnKn+Thph1mgWyZ90nboOcSuZr/jTTQ==
|
||||
"@typescript-eslint/visitor-keys@5.4.0":
|
||||
version "5.4.0"
|
||||
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.4.0.tgz#09bc28efd3621f292fe88c86eef3bf4893364c8c"
|
||||
integrity sha512-PVbax7MeE7tdLfW5SA0fs8NGVVr+buMPrcj+CWYWPXsZCH8qZ1THufDzbXm1xrZ2b2PA1iENJ0sRq5fuUtvsJg==
|
||||
dependencies:
|
||||
"@typescript-eslint/types" "5.3.1"
|
||||
"@typescript-eslint/types" "5.4.0"
|
||||
eslint-visitor-keys "^3.0.0"
|
||||
|
||||
"@webassemblyjs/ast@1.11.1":
|
||||
@@ -6554,10 +6554,10 @@ typedarray-to-buffer@^3.1.5:
|
||||
dependencies:
|
||||
is-typedarray "^1.0.0"
|
||||
|
||||
typescript@4.4.4:
|
||||
version "4.4.4"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.4.4.tgz#2cd01a1a1f160704d3101fd5a58ff0f9fcb8030c"
|
||||
integrity sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==
|
||||
typescript@4.5.1-rc:
|
||||
version "4.5.1-rc"
|
||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.5.1-rc.tgz#02155eaa0579d11babb2a55dcbd796948a994bb3"
|
||||
integrity sha512-tQBWW1DCFqweyhSzsAUSFgssJ3uuRBh0zyOkRV4CaFF2rMBkGU0I+MqPMch0qhGCUGXjOW7FgMrbQLS6PE3Z6Q==
|
||||
|
||||
unbox-primitive@^1.0.1:
|
||||
version "1.0.1"
|
||||
|
||||
Reference in new issue
Block a user