Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a603015

Browse files
authored
fix(typescript-estree): fix decorator regression for pre TS4.8 (typescript-eslint#5574)
1 parent 60b6c11 commit a603015

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
"typescript": ">=3.3.1 <4.9.0"
109109
},
110110
"resolutions": {
111-
"typescript": "4.8.2",
111+
"typescript": "~4.8.2",
112112
"@types/node": "^17.0.31",
113113
"pretty-format": "^28.1.0",
114114
"//": "Pin jest to v28 across the repo",

packages/typescript-estree/src/convert.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,15 +1056,11 @@ export class Converter {
10561056

10571057
/**
10581058
* Semantically, decorators are not allowed on variable declarations,
1059-
* but the TypeScript compiler will parse them and produce a valid AST,
1060-
* so we handle them here too.
1059+
* Pre 4.8 TS would include them in the AST, so we did as well.
1060+
* However as of 4.8 TS no longer includes it (as it is, well, invalid).
1061+
*
1062+
* So for consistency across versions, we no longer include it either.
10611063
*/
1062-
const decorators = getDecorators(node);
1063-
if (decorators) {
1064-
(result as any).decorators = decorators.map(el =>
1065-
this.convertChild(el),
1066-
);
1067-
}
10681064

10691065
if (hasModifier(SyntaxKind.DeclareKeyword, node)) {
10701066
result.declare = true;

packages/typescript-estree/src/getModifiers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,6 @@ export function getDecorators(
4747

4848
return (
4949
// eslint-disable-next-line deprecation/deprecation -- intentional fallback for older TS versions
50-
node.modifiers?.filter(ts.isDecorator)
50+
node.decorators?.filter(ts.isDecorator)
5151
);
5252
}

patches/typescript+4.8.2.patch

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/node_modules/typescript/lib/typescript.d.ts b/node_modules/typescript/lib/typescript.d.ts
2-
index 0fd60ae..b3610b8 100644
2+
index 0fd60ae..8bce90e 100644
33
--- a/node_modules/typescript/lib/typescript.d.ts
44
+++ b/node_modules/typescript/lib/typescript.d.ts
55
@@ -425,8 +425,8 @@ declare namespace ts {
@@ -40,3 +40,12 @@ index 0fd60ae..b3610b8 100644
4040
function canHaveDecorators(node: Node): node is HasDecorators;
4141
}
4242
declare namespace ts {
43+
@@ -7924,7 +7936,7 @@ declare namespace ts {
44+
* const decorators = ts.canHaveDecorators(node) ? ts.getDecorators(node) : undefined;
45+
* ```
46+
*/
47+
- readonly decorators?: undefined;
48+
+ readonly decorators?: NodeArray<Decorator> | undefined;
49+
/**
50+
* @deprecated `modifiers` has been removed from `Node` and moved to the `Node` subtypes that support them.
51+
* Use `ts.canHaveModifiers()` to test whether a `Node` can have modifiers.

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14177,7 +14177,7 @@ typedarray@^0.0.6:
1417714177
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"
1417814178
integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=
1417914179

14180-
typescript@*, [email protected], "typescript@>=3.3.1 <4.9.0", typescript@^4.5.3, typescript@next, typescript@~4.7.4:
14180+
typescript@*, "typescript@>=3.3.1 <4.9.0", typescript@^4.5.3, typescript@next, typescript@~4.7.4, typescript@~4.8.2:
1418114181
version "4.8.2"
1418214182
resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.8.2.tgz#e3b33d5ccfb5914e4eeab6699cf208adee3fd790"
1418314183
integrity sha512-C0I1UsrrDHo2fYI5oaCGbSejwX4ch+9Y5jTQELvovfmFkK3HHSZJB8MSJcWLmCUBzQBchCrZ9rMRV6GuNrvGtw==

0 commit comments

Comments
 (0)