Skip to content

Commit

Permalink
Update dependency typescript to v4.8.2 (#13381)
Browse files Browse the repository at this point in the history
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: fisker Cheung <lionkay@gmail.com>
  • Loading branch information
renovate[bot] and fisker committed Sep 7, 2022
1 parent 1142cf0 commit bd5f915
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 127 deletions.
8 changes: 4 additions & 4 deletions package.json
Expand Up @@ -28,8 +28,8 @@
"@babel/types": "7.18.13",
"@glimmer/syntax": "0.84.2",
"@iarna/toml": "2.2.5",
"@typescript-eslint/typescript-estree": "5.35.1",
"@typescript-eslint/visitor-keys": "5.35.1",
"@typescript-eslint/typescript-estree": "5.36.2",
"@typescript-eslint/visitor-keys": "5.36.2",
"acorn": "8.8.0",
"acorn-jsx": "5.3.2",
"angular-estree-parser": "2.5.1",
Expand Down Expand Up @@ -90,7 +90,7 @@
"string-width": "5.0.1",
"strip-ansi": "7.0.1",
"to-fast-properties": "4.0.0",
"typescript": "4.7.4",
"typescript": "4.8.2",
"unicode-regex": "3.0.0",
"unified": "9.2.2",
"vnopts": "1.0.2",
Expand All @@ -104,7 +104,7 @@
"@types/file-entry-cache": "5.0.2",
"@types/find-cache-dir": "3.2.1",
"@types/jest": "29.0.0",
"@typescript-eslint/eslint-plugin": "5.35.1",
"@typescript-eslint/eslint-plugin": "5.36.2",
"benchmark": "2.1.4",
"browserslist-to-esbuild": "1.2.0",
"c8": "7.12.0",
Expand Down
14 changes: 6 additions & 8 deletions scripts/build/modify-typescript-module.mjs
Expand Up @@ -47,14 +47,12 @@ function removeSubmodule(text, testFunction) {
function replaceSubmodule(text, testFunction, replacement) {
const modules = getSubmodules(text, testFunction);
if (modules.length !== 1) {
return text;
// TODO: Enable this check when merge to `next` branch
// throw Object.assign(
// new Error(
// `Expect exactly one submodule to be found, got ${modules.length} submodules.`
// ),
// { modules }
// );
throw Object.assign(
new Error(
`Expect exactly one submodule to be found, got ${modules.length} submodules.`
),
{ modules }
);
}

const [{ start, end, before, after }] = modules;
Expand Down
48 changes: 26 additions & 22 deletions src/language-js/parse/postprocess/typescript.js
@@ -1,31 +1,34 @@
import isNonEmptyArray from "../../../utils/is-non-empty-array.js";
import visitNode from "./visit-node.js";
import throwTsSyntaxError from "./throw-ts-syntax-error.js";

// Copied from https://unpkg.com/typescript@4.8.2/lib/typescript.js
function getSourceFileOfNode(node) {
while (node && node.kind !== 305 /* SyntaxKind.SourceFile */) {
node = node.parent;
}
return node;
}

// Invalid decorators are removed since `@typescript-eslint/typescript-estree` v4
// https://github.com/typescript-eslint/typescript-eslint/pull/2375
function throwErrorForInvalidDecorator(
tsNode,
esTreeNode,
tsNodeToESTreeNodeMap
) {
const tsDecorators = tsNode.decorators;
if (!Array.isArray(tsDecorators)) {
// There is a `checkGrammarDecorators` in `typescript` package, consider use it directly in future
function throwErrorForInvalidDecorator(tsNode) {
const { illegalDecorators } = tsNode;
if (!isNonEmptyArray(illegalDecorators)) {
return;
}
const esTreeDecorators = esTreeNode.decorators;
if (
!Array.isArray(esTreeDecorators) ||
esTreeDecorators.length !== tsDecorators.length ||
tsDecorators.some((tsDecorator) => {
const esTreeDecorator = tsNodeToESTreeNodeMap.get(tsDecorator);
return !esTreeDecorator || !esTreeDecorators.includes(esTreeDecorator);
})
) {
throwTsSyntaxError(
esTreeNode,
"Leading decorators must be attached to a class declaration"
);
}

const [{ expression }] = illegalDecorators;

const sourceFile = getSourceFileOfNode(expression);
const [start, end] = [expression.pos, expression.end].map((position) => {
const { line, character: column } =
sourceFile.getLineAndCharacterOfPosition(position);
return { line: line + 1, column };
});

throwTsSyntaxError({ loc: { start, end } }, "Decorators are not valid here.");
}

// Values of abstract property is removed since `@typescript-eslint/typescript-estree` v5
Expand Down Expand Up @@ -59,12 +62,13 @@ function throwErrorForInvalidNodes(ast, options) {
if (!tsNode) {
return;
}

const esTreeNode = tsNodeToESTreeNodeMap.get(tsNode);
if (esTreeNode !== node) {
return;
}

throwErrorForInvalidDecorator(tsNode, esTreeNode, tsNodeToESTreeNodeMap);
throwErrorForInvalidDecorator(tsNode);
throwErrorForInvalidAbstractProperty(tsNode, esTreeNode);
});
}
Expand Down
5 changes: 1 addition & 4 deletions tests/config/format-test.js
Expand Up @@ -78,10 +78,7 @@ const meriyahDisabledTests = new Set([
),
]);
const babelTsDisabledTest = new Set(
[
// Disabled temporarily https://github.com/babel/babel/issues/14777#issuecomment-1191474632
"instantiation-expression",
].map((directory) => path.join(__dirname, "../format/typescript", directory))
[].map((directory) => path.join(__dirname, "../format/typescript", directory))
);

const isUnstable = (filename, options) => {
Expand Down
Expand Up @@ -10,13 +10,12 @@ exports[`decorator.ts [babel-ts] format 1`] = `
`;

exports[`decorator.ts [typescript] format 1`] = `
"Leading decorators must be attached to a class declaration (3:1)
"Decorators are not valid here. (3:2)
1 | declare function dec<T>(target: T): T;
2 |
> 3 | @dec
| ^^^^
> 4 | enum E {}
| ^^^^^^^^^^
| ^^^
4 | enum E {}
5 |"
`;
Expand All @@ -32,24 +31,14 @@ exports[`enums.ts [babel-ts] format 1`] = `
`;
exports[`enums.ts [typescript] format 1`] = `
"Leading decorators must be attached to a class declaration (3:1)
1 | // https://github.com/typescript-eslint/typescript-eslint/pull/2375
2 |
> 3 | @decorator()
| ^^^^^^^^^^^^
> 4 | enum Direction {
| ^^^^^^^^^^^^^^^^
> 5 | Up = 1,
| ^^^^^^^^^^^^^^^^
> 6 | Down,
| ^^^^^^^^^^^^^^^^
> 7 | Left,
| ^^^^^^^^^^^^^^^^
> 8 | Right
| ^^^^^^^^^^^^^^^^
> 9 | }
| ^^
10 |"
"Decorators are not valid here. (3:2)
1 | // https://github.com/typescript-eslint/typescript-eslint/pull/2375
2 |
> 3 | @decorator()
| ^^^^^^^^^^^
4 | enum Direction {
5 | Up = 1,
6 | Down,"
`;
exports[`function.ts [babel-ts] format 1`] = `
Expand All @@ -62,13 +51,12 @@ exports[`function.ts [babel-ts] format 1`] = `
`;
exports[`function.ts [typescript] format 1`] = `
"Leading decorators must be attached to a class declaration (3:1)
"Decorators are not valid here. (3:2)
1 | // https://github.com/typescript-eslint/typescript-eslint/pull/2375
2 |
> 3 | @decorator()
| ^^^^^^^^^^^^
> 4 | function foo( ){}
| ^^^^^^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^
4 | function foo( ){}
5 |"
`;
Expand All @@ -83,15 +71,13 @@ exports[`interface.ts [babel-ts] format 1`] = `
`;
exports[`interface.ts [typescript] format 1`] = `
"Leading decorators must be attached to a class declaration (4:1)
"Decorators are not valid here. (4:2)
2 | // #4632
3 |
> 4 | @hello()
| ^^^^^^^^
> 5 | interface MyInterface {id: string;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 6 | }
| ^^
| ^^^^^^^
5 | interface MyInterface {id: string;
6 | }
7 |"
`;
Expand All @@ -105,11 +91,10 @@ exports[`issue-9102.ts [babel-ts] format 1`] = `
`;
exports[`issue-9102.ts [typescript] format 1`] = `
"Leading decorators must be attached to a class declaration (1:1)
"Decorators are not valid here. (1:2)
> 1 | @Decorator()
| ^^^^^^^^^^^^
> 2 | type T = 1;
| ^^^^^^^^^^^^
| ^^^^^^^^^^^
2 | type T = 1;
3 | class C {}
4 |"
`;
Expand Up @@ -26,7 +26,8 @@ new A < B >
C
=====================================output=====================================
new A() < B > C;
new A<B>();
C;
================================================================================
`;
Expand Down

0 comments on commit bd5f915

Please sign in to comment.