Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TypeScript 4.1 via typescript-estree #9636

Merged
merged 44 commits into from Nov 18, 2020
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5d5a4f0
Update typescript and typescript-estree
sosukesuzuki Nov 10, 2020
0e801c9
Add AST transformation for TSTemplateLiteralType
sosukesuzuki Nov 10, 2020
a04127a
Update tests for template-literal-types
sosukesuzuki Nov 10, 2020
599f5f1
Fix transformChainExpression
sosukesuzuki Nov 10, 2020
ca42089
Update tests for key-remapping-in-mapped-types
sosukesuzuki Nov 10, 2020
27e7b46
Implement recoverInvalidDecorators
sosukesuzuki Nov 10, 2020
a918330
Update changelog
sosukesuzuki Nov 10, 2020
589a689
Avoid typecheck error
sosukesuzuki Nov 10, 2020
cd545a8
Add os.platform() shim
sosukesuzuki Nov 10, 2020
8cb07ca
Update config.js
fisker Nov 11, 2020
c31a3df
Update config.js
fisker Nov 11, 2020
c563159
Shim os.cpus
fisker Nov 11, 2020
6c20946
Update `process.versions.node`
fisker Nov 11, 2020
4fc37c7
Attempt to fix build
fisker Nov 11, 2020
27a4473
Update ts parserOptions
fisker Nov 11, 2020
5b15eb2
Fix code style
fisker Nov 11, 2020
1484a2e
Remove `errorOnUnknownASTType`, fix code style
fisker Nov 11, 2020
9a94c6b
Use `[] ||` instead of `[] //`
fisker Nov 11, 2020
1209987
Fix hack
fisker Nov 11, 2020
9571318
Add invalid tests
fisker Nov 12, 2020
a760c59
checkMissingDecorators
fisker Nov 12, 2020
53fff41
Update tests
fisker Nov 12, 2020
5978c26
Fix tests
fisker Nov 12, 2020
6ba07e0
Add comment
fisker Nov 12, 2020
4f693ed
Revert "Implement recoverInvalidDecorators"
fisker Nov 12, 2020
ae8071d
Add ref pr link
fisker Nov 12, 2020
9de9bc7
Simplify logic
fisker Nov 12, 2020
80cf659
Merge branch 'master' into update-ts-estree
fisker Nov 12, 2020
07ed145
Don't transform `TSTemplateLiteralType`
fisker Nov 12, 2020
768e593
Add `TSTemplateLiteralType` as simple type
fisker Nov 12, 2020
93a44d7
Fix tests
fisker Nov 12, 2020
b048b0b
Update comments
fisker Nov 12, 2020
ff1ed80
Add comment
fisker Nov 12, 2020
24cfed1
Fix logic
fisker Nov 12, 2020
beae5e1
Minor tweak
fisker Nov 12, 2020
1b7d159
Merge branch 'master' into update-ts-estree
sosukesuzuki Nov 16, 2020
109aa25
Merge branch 'master' into update-ts-estree
fisker Nov 16, 2020
b4dd8c8
use multiple parsers
fisker Nov 16, 2020
4f35ff3
Update @typescript-eslint/typescript-estree to v4.8.0
fisker Nov 17, 2020
7c65de6
Switch to `parseWithNodeMaps`
fisker Nov 17, 2020
be58419
Rename `esNode` -> `esTreeNode`
fisker Nov 17, 2020
e06ae5e
Update @typescript-eslint/typescript-estree to 4.8.1-alpha.1
fisker Nov 17, 2020
42913c2
Merge branch 'master' into update-ts-estree
fisker Nov 17, 2020
702aeeb
Use @typescript-eslint/typescript-estree 4.8.1
sosukesuzuki Nov 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions changelog_unreleased/typescript/pr-9473.md
@@ -1,6 +1,4 @@
#### [HIGHLIGHT]Support TypeScript 4.1 via Babel (#9473 by @sosukesuzuki)

`--parser=babel-ts` is required.
#### [HIGHLIGHT]Support TypeScript 4.1 (#9473, #9636 by @sosukesuzuki)

##### Key Remapping In Mapped Types

Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -25,7 +25,7 @@
"@babel/parser": "7.12.5",
"@glimmer/syntax": "0.63.4",
"@iarna/toml": "2.2.5",
"@typescript-eslint/typescript-estree": "3.10.1",
"@typescript-eslint/typescript-estree": "4.7.0",
"angular-estree-parser": "2.2.1",
"angular-html-parser": "1.7.1",
"camelcase": "6.2.0",
Expand Down Expand Up @@ -78,7 +78,7 @@
"resolve": "1.18.1",
"semver": "7.3.2",
"string-width": "4.2.0",
"typescript": "4.0.5",
"typescript": "4.1.1-rc",
"unicode-regex": "3.0.0",
"unified": "9.2.0",
"vnopts": "1.0.2",
Expand Down
11 changes: 2 additions & 9 deletions src/language-graphql/printer-graphql.js
@@ -1,15 +1,8 @@
"use strict";

const {
concat,
join,
hardline,
line,
softline,
group,
indent,
ifBreak,
} = require("../document").builders;
builders: { concat, join, hardline, line, softline, group, indent, ifBreak },
} = require("../document");
Comment on lines 3 to +5
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why, but this change removes the TypeScript typecheck error. Why...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe #9207

const { isNextLineEmpty } = require("../common/util");
const { insertPragma } = require("./pragma");
const { locStart, locEnd } = require("./loc");
Expand Down
11 changes: 2 additions & 9 deletions src/language-handlebars/printer-glimmer.js
@@ -1,15 +1,8 @@
"use strict";

const {
concat,
group,
hardline,
ifBreak,
indent,
join,
line,
softline,
} = require("../document").builders;
builders: { concat, group, hardline, ifBreak, indent, join, line, softline },
} = require("../document");
const locationToOffset = require("../utils/line-column-to-index");

const clean = require("./clean");
Expand Down
15 changes: 15 additions & 0 deletions src/language-js/postprocess.js
Expand Up @@ -129,6 +129,19 @@ function postprocess(ast, options) {
node.optional = true;
}
break;
case "TSTemplateLiteralType": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should print this, not transform it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no strong opinion. Out of curiosity, why?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we'll support formatAST()

const { types, quasis, ...rest } = node;
return {
...rest,
type: "TSLiteralType",
literal: {
...rest,
type: "TemplateLiteral",
expressions: types,
quasis,
},
};
}
}
});

Expand Down Expand Up @@ -157,6 +170,8 @@ function transformChainExpression(node) {
} else if (node.type === "MemberExpression") {
node.type = "OptionalMemberExpression";
node.object = transformChainExpression(node.object);
} else if (node.type === "TSNonNullExpression") {
node.expression = transformChainExpression(node.expression);
}
return node;
}
Expand Down
4 changes: 3 additions & 1 deletion src/language-js/printer-estree-json.js
@@ -1,6 +1,8 @@
"use strict";

const { concat, hardline, indent, join } = require("../document").builders;
const {
builders: { concat, hardline, indent, join },
} = require("../document");
const preprocess = require("./preprocess");

function genericPrint(path, options, print) {
Expand Down
20 changes: 11 additions & 9 deletions src/main/comments.js
Expand Up @@ -4,15 +4,17 @@
const assert = require("assert");

const {
concat,
line,
hardline,
breakParent,
indent,
lineSuffix,
join,
cursor,
} = require("../document").builders;
builders: {
concat,
line,
hardline,
breakParent,
indent,
lineSuffix,
join,
cursor,
},
} = require("../document");

const {
hasNewline,
Expand Down
18 changes: 18 additions & 0 deletions src/main/core.js
Expand Up @@ -36,6 +36,20 @@ function attachComments(text, ast, opts) {
return astComments;
}

// For typescript-estree 4.x breaking change
// https://github.com/prettier/prettier/pull/9119#issuecomment-684410127
function recoverInvalidDecorators(originalText, formattedText) {
const originalTextAtSignCount = (originalText.match(/@/g) || []).length;
if (originalTextAtSignCount === 0) {
return formattedText;
}
const formattedTextAtSignCount = (formattedText.match(/@/g) || []).length;
if (originalTextAtSignCount > formattedTextAtSignCount) {
return originalText;
}
return formattedText;
}

function coreFormat(originalText, opts, addAlignmentSize) {
if (!originalText || !originalText.trim().length) {
return { formatted: "", cursorOffset: -1 };
Expand Down Expand Up @@ -69,6 +83,10 @@ function coreFormat(originalText, opts, addAlignmentSize) {
result.formatted = trimmed + convertEndOfLineToChars(opts.endOfLine);
}

if (opts.parser === "typescript") {
result.formatted = recoverInvalidDecorators(originalText, result.formatted);
}

if (opts.cursorOffset >= 0) {
let oldCursorNodeStart;
let oldCursorNodeText;
Expand Down
@@ -1,15 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`key-remapping.ts [typescript] format 1`] = `
"']' expected. (2:17)
1 | type MappedTypeWithNewKeys<T> = {
> 2 | [K in keyof T as NewKeyType]: T[K]
| ^
3 | };
4 |
5 | type RemoveKindField<T> = {"
`;

exports[`key-remapping.ts format 1`] = `
====================================options=====================================
parsers: ["babel-ts", "typescript"]
Expand Down
4 changes: 1 addition & 3 deletions tests/typescript/key-remapping-in-mapped-types/jsfmt.spec.js
@@ -1,3 +1 @@
run_spec(__dirname, ["babel-ts", "typescript"], {
errors: { typescript: true },
});
run_spec(__dirname, ["babel-ts", "typescript"]);
@@ -1,14 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`template-literal-types.ts [typescript] format 1`] = `
"Type expected. (1:8)
> 1 | let x: \`foo-\${infer bar}\`;
| ^
2 | type HelloWorld = \`\${Hello}, \${World}\`
3 | type SeussFish = \`\${Quantity | Color} fish\`;
4 | declare function setAlignment(value: \`\${VerticalAlignment}-\${HorizontalAlignment}\`): void;"
`;

exports[`template-literal-types.ts format 1`] = `
====================================options=====================================
parsers: ["babel-ts", "typescript"]
Expand Down
4 changes: 1 addition & 3 deletions tests/typescript/template-literal-types/jsfmt.spec.js
@@ -1,3 +1 @@
run_spec(__dirname, ["babel-ts", "typescript"], {
errors: { typescript: true },
});
run_spec(__dirname, ["babel-ts", "typescript"]);
50 changes: 28 additions & 22 deletions yarn.lock
Expand Up @@ -1465,19 +1465,10 @@
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.0.1.tgz#1cf72582f764931f085cb8230ff215980fe467b2"
integrity sha512-S+gD3fgbkZYW2rnbjugNMqibm9HpEjqZBZkTiI3PwbbNGWmAcxolWIUwZ0SKeG4Dy2ktpKKaI/6+HGYVH8Qrlg==

"@typescript-eslint/typescript-estree@3.10.1":
version "3.10.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-3.10.1.tgz#fd0061cc38add4fad45136d654408569f365b853"
integrity sha512-QbcXOuq6WYvnB3XPsZpIwztBoquEYLXh2MtwVU+kO8jgYCiv4G5xrSP/1wg4tkvrEE+esZVquIPX/dxPlePk1w==
dependencies:
"@typescript-eslint/types" "3.10.1"
"@typescript-eslint/visitor-keys" "3.10.1"
debug "^4.1.1"
glob "^7.1.6"
is-glob "^4.0.1"
lodash "^4.17.15"
semver "^7.3.2"
tsutils "^3.17.1"
"@typescript-eslint/types@4.7.0":
version "4.7.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-4.7.0.tgz#5e95ef5c740f43d942542b35811f87b62fccca69"
integrity sha512-uLszFe0wExJc+I7q0Z/+BnP7wao/kzX0hB5vJn4LIgrfrMLgnB2UXoReV19lkJQS1a1mHWGGODSxnBx6JQC3Sg==

"@typescript-eslint/typescript-estree@4.0.1":
version "4.0.1"
Expand All @@ -1493,12 +1484,19 @@
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/visitor-keys@3.10.1":
version "3.10.1"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-3.10.1.tgz#cd4274773e3eb63b2e870ac602274487ecd1e931"
integrity sha512-9JgC82AaQeglebjZMgYR5wgmfUdUc+EitGUUMW8u2nDckaeimzW+VsoLV6FoimPv2id3VQzfjwBxEMVz08ameQ==
"@typescript-eslint/typescript-estree@4.7.0":
version "4.7.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-4.7.0.tgz#539531167f05ba20eb0b6785567076679e29d393"
integrity sha512-5XZRQznD1MfUmxu1t8/j2Af4OxbA7EFU2rbo0No7meb46eHgGkSieFdfV6omiC/DGIBhH9H9gXn7okBbVOm8jw==
dependencies:
eslint-visitor-keys "^1.1.0"
"@typescript-eslint/types" "4.7.0"
"@typescript-eslint/visitor-keys" "4.7.0"
debug "^4.1.1"
globby "^11.0.1"
is-glob "^4.0.1"
lodash "^4.17.15"
semver "^7.3.2"
tsutils "^3.17.1"

"@typescript-eslint/visitor-keys@4.0.1":
version "4.0.1"
Expand All @@ -1508,6 +1506,14 @@
"@typescript-eslint/types" "4.0.1"
eslint-visitor-keys "^2.0.0"

"@typescript-eslint/visitor-keys@4.7.0":
version "4.7.0"
resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-4.7.0.tgz#6783824f22acfc49e754970ed21b88ac03b80e6f"
integrity sha512-aDJDWuCRsf1lXOtignlfiPODkzSxxop7D0rZ91L6ZuMlcMCSh0YyK+gAfo5zN/ih6WxMwhoXgJWC3cWQdaKC+A==
dependencies:
"@typescript-eslint/types" "4.7.0"
eslint-visitor-keys "^2.0.0"

"@webassemblyjs/ast@1.9.0":
version "1.9.0"
resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.9.0.tgz#bd850604b4042459a5a41cd7d338cbed695ed964"
Expand Down Expand Up @@ -7167,10 +7173,10 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"

typescript@4.0.5:
version "4.0.5"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.0.5.tgz#ae9dddfd1069f1cb5beb3ef3b2170dd7c1332389"
integrity sha512-ywmr/VrTVCmNTJ6iV2LwIrfG1P+lv6luD8sUJs+2eI9NLGigaN+nUQc13iHqisq7bra9lnmUSYqbJvegraBOPQ==
typescript@4.1.1-rc:
version "4.1.1-rc"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.1.1-rc.tgz#4a335244b9b2754995849ca4b607c74d6ee73719"
integrity sha512-tgNcFrLIjlaMWEc7bKC0bxLNIt8BIAauY/HLUOQDyTP75HGskETtXOt46x4EKAHRKhWVLMc7yM02puTHa/yhCA==

unherit@^1.0.4:
version "1.1.3"
Expand Down