@typescript-eslint/typescript-estree 8.45.1-alpha.8 → 8.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2 @@
1
+ import * as ts from 'typescript';
2
+ export declare function checkModifiers(node: ts.Node): void;
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.checkModifiers = checkModifiers;
37
+ const ts = __importStar(require("typescript"));
38
+ const getModifiers_1 = require("./getModifiers");
39
+ const node_utils_1 = require("./node-utils");
40
+ const SyntaxKind = ts.SyntaxKind;
41
+ // `ts.nodeIsMissing`
42
+ function nodeIsMissing(node) {
43
+ if (node == null) {
44
+ return true;
45
+ }
46
+ return (node.pos === node.end &&
47
+ node.pos >= 0 &&
48
+ node.kind !== SyntaxKind.EndOfFileToken);
49
+ }
50
+ // `ts.nodeIsPresent`
51
+ function nodeIsPresent(node) {
52
+ return !nodeIsMissing(node);
53
+ }
54
+ // `ts.hasAbstractModifier`
55
+ function hasAbstractModifier(node) {
56
+ return (0, node_utils_1.hasModifier)(SyntaxKind.AbstractKeyword, node);
57
+ }
58
+ // `ts.getThisParameter`
59
+ function getThisParameter(signature) {
60
+ if (signature.parameters.length && !ts.isJSDocSignature(signature)) {
61
+ const thisParameter = signature.parameters[0];
62
+ if (parameterIsThisKeyword(thisParameter)) {
63
+ return thisParameter;
64
+ }
65
+ }
66
+ return null;
67
+ }
68
+ // `ts.parameterIsThisKeyword`
69
+ function parameterIsThisKeyword(parameter) {
70
+ return (0, node_utils_1.isThisIdentifier)(parameter.name);
71
+ }
72
+ // `ts.getContainingFunction`
73
+ function getContainingFunction(node) {
74
+ return ts.findAncestor(node.parent, ts.isFunctionLike);
75
+ }
76
+ // Rewrite version of `ts.nodeCanBeDecorated`
77
+ // Returns `true` for both `useLegacyDecorators: true` and `useLegacyDecorators: false`
78
+ function nodeCanBeDecorated(node) {
79
+ switch (node.kind) {
80
+ case SyntaxKind.ClassDeclaration:
81
+ return true;
82
+ case SyntaxKind.ClassExpression:
83
+ // `ts.nodeCanBeDecorated` returns `false` if `useLegacyDecorators: true`
84
+ return true;
85
+ case SyntaxKind.PropertyDeclaration: {
86
+ const { parent } = node;
87
+ // `ts.nodeCanBeDecorated` uses this if `useLegacyDecorators: true`
88
+ if (ts.isClassDeclaration(parent)) {
89
+ return true;
90
+ }
91
+ // `ts.nodeCanBeDecorated` uses this if `useLegacyDecorators: false`
92
+ if (ts.isClassLike(parent) && !hasAbstractModifier(node)) {
93
+ return true;
94
+ }
95
+ return false;
96
+ }
97
+ case SyntaxKind.GetAccessor:
98
+ case SyntaxKind.SetAccessor:
99
+ case SyntaxKind.MethodDeclaration: {
100
+ const { parent } = node;
101
+ // In `ts.nodeCanBeDecorated`
102
+ // when `useLegacyDecorators: true` uses `ts.isClassDeclaration`
103
+ // when `useLegacyDecorators: true` uses `ts.isClassLike`
104
+ return (Boolean(node.body) &&
105
+ (ts.isClassDeclaration(parent) || ts.isClassLike(parent)));
106
+ }
107
+ case SyntaxKind.Parameter: {
108
+ // `ts.nodeCanBeDecorated` returns `false` if `useLegacyDecorators: false`
109
+ const { parent } = node;
110
+ const grandparent = parent.parent;
111
+ return (Boolean(parent) &&
112
+ 'body' in parent &&
113
+ Boolean(parent.body) &&
114
+ (parent.kind === SyntaxKind.Constructor ||
115
+ parent.kind === SyntaxKind.MethodDeclaration ||
116
+ parent.kind === SyntaxKind.SetAccessor) &&
117
+ getThisParameter(parent) !== node &&
118
+ Boolean(grandparent) &&
119
+ grandparent.kind === SyntaxKind.ClassDeclaration);
120
+ }
121
+ }
122
+ return false;
123
+ }
124
+ function nodeHasIllegalDecorators(node) {
125
+ return !!('illegalDecorators' in node &&
126
+ node.illegalDecorators?.length);
127
+ }
128
+ function throwError(node, message) {
129
+ const ast = node.getSourceFile();
130
+ const start = node.getStart(ast);
131
+ const end = node.getEnd();
132
+ throw (0, node_utils_1.createError)(message, ast, start, end);
133
+ }
134
+ function checkModifiers(node) {
135
+ // typescript<5.0.0
136
+ if (nodeHasIllegalDecorators(node)) {
137
+ throwError(node.illegalDecorators[0], 'Decorators are not valid here.');
138
+ }
139
+ for (const decorator of (0, getModifiers_1.getDecorators)(node,
140
+ /* includeIllegalDecorators */ true) ?? []) {
141
+ // `checkGrammarModifiers` function in typescript
142
+ if (!nodeCanBeDecorated(node)) {
143
+ if (ts.isMethodDeclaration(node) && !nodeIsPresent(node.body)) {
144
+ throwError(decorator, 'A decorator can only decorate a method implementation, not an overload.');
145
+ }
146
+ else {
147
+ throwError(decorator, 'Decorators are not valid here.');
148
+ }
149
+ }
150
+ }
151
+ for (const modifier of (0, getModifiers_1.getModifiers)(node,
152
+ /* includeIllegalModifiers */ true) ?? []) {
153
+ if (modifier.kind !== SyntaxKind.ReadonlyKeyword) {
154
+ if (node.kind === SyntaxKind.PropertySignature ||
155
+ node.kind === SyntaxKind.MethodSignature) {
156
+ throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a type member`);
157
+ }
158
+ if (node.kind === SyntaxKind.IndexSignature &&
159
+ (modifier.kind !== SyntaxKind.StaticKeyword ||
160
+ !ts.isClassLike(node.parent))) {
161
+ throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on an index signature`);
162
+ }
163
+ }
164
+ if (modifier.kind !== SyntaxKind.InKeyword &&
165
+ modifier.kind !== SyntaxKind.OutKeyword &&
166
+ modifier.kind !== SyntaxKind.ConstKeyword &&
167
+ node.kind === SyntaxKind.TypeParameter) {
168
+ throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a type parameter`);
169
+ }
170
+ if ((modifier.kind === SyntaxKind.InKeyword ||
171
+ modifier.kind === SyntaxKind.OutKeyword) &&
172
+ (node.kind !== SyntaxKind.TypeParameter ||
173
+ !(ts.isInterfaceDeclaration(node.parent) ||
174
+ ts.isClassLike(node.parent) ||
175
+ ts.isTypeAliasDeclaration(node.parent)))) {
176
+ throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier can only appear on a type parameter of a class, interface or type alias`);
177
+ }
178
+ if (modifier.kind === SyntaxKind.ReadonlyKeyword &&
179
+ node.kind !== SyntaxKind.PropertyDeclaration &&
180
+ node.kind !== SyntaxKind.PropertySignature &&
181
+ node.kind !== SyntaxKind.IndexSignature &&
182
+ node.kind !== SyntaxKind.Parameter) {
183
+ throwError(modifier, "'readonly' modifier can only appear on a property declaration or index signature.");
184
+ }
185
+ if (modifier.kind === SyntaxKind.DeclareKeyword &&
186
+ ts.isClassLike(node.parent) &&
187
+ !ts.isPropertyDeclaration(node)) {
188
+ throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on class elements of this kind.`);
189
+ }
190
+ if (modifier.kind === SyntaxKind.DeclareKeyword &&
191
+ ts.isVariableStatement(node)) {
192
+ const declarationKind = (0, node_utils_1.getDeclarationKind)(node.declarationList);
193
+ if (declarationKind === 'using' || declarationKind === 'await using') {
194
+ throwError(modifier, `'declare' modifier cannot appear on a '${declarationKind}' declaration.`);
195
+ }
196
+ }
197
+ if (modifier.kind === SyntaxKind.AbstractKeyword &&
198
+ node.kind !== SyntaxKind.ClassDeclaration &&
199
+ node.kind !== SyntaxKind.ConstructorType &&
200
+ node.kind !== SyntaxKind.MethodDeclaration &&
201
+ node.kind !== SyntaxKind.PropertyDeclaration &&
202
+ node.kind !== SyntaxKind.GetAccessor &&
203
+ node.kind !== SyntaxKind.SetAccessor) {
204
+ throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier can only appear on a class, method, or property declaration.`);
205
+ }
206
+ if ((modifier.kind === SyntaxKind.StaticKeyword ||
207
+ modifier.kind === SyntaxKind.PublicKeyword ||
208
+ modifier.kind === SyntaxKind.ProtectedKeyword ||
209
+ modifier.kind === SyntaxKind.PrivateKeyword) &&
210
+ (node.parent.kind === SyntaxKind.ModuleBlock ||
211
+ node.parent.kind === SyntaxKind.SourceFile)) {
212
+ throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a module or namespace element.`);
213
+ }
214
+ if (modifier.kind === SyntaxKind.AccessorKeyword &&
215
+ node.kind !== SyntaxKind.PropertyDeclaration) {
216
+ throwError(modifier, "'accessor' modifier can only appear on a property declaration.");
217
+ }
218
+ // `checkGrammarAsyncModifier` function in `typescript`
219
+ if (modifier.kind === SyntaxKind.AsyncKeyword &&
220
+ node.kind !== SyntaxKind.MethodDeclaration &&
221
+ node.kind !== SyntaxKind.FunctionDeclaration &&
222
+ node.kind !== SyntaxKind.FunctionExpression &&
223
+ node.kind !== SyntaxKind.ArrowFunction) {
224
+ throwError(modifier, "'async' modifier cannot be used here.");
225
+ }
226
+ // `checkGrammarModifiers` function in `typescript`
227
+ if (node.kind === SyntaxKind.Parameter &&
228
+ (modifier.kind === SyntaxKind.StaticKeyword ||
229
+ modifier.kind === SyntaxKind.ExportKeyword ||
230
+ modifier.kind === SyntaxKind.DeclareKeyword ||
231
+ modifier.kind === SyntaxKind.AsyncKeyword)) {
232
+ throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a parameter.`);
233
+ }
234
+ // `checkGrammarModifiers` function in `typescript`
235
+ if (modifier.kind === SyntaxKind.PublicKeyword ||
236
+ modifier.kind === SyntaxKind.ProtectedKeyword ||
237
+ modifier.kind === SyntaxKind.PrivateKeyword) {
238
+ for (const anotherModifier of (0, getModifiers_1.getModifiers)(node) ?? []) {
239
+ if (anotherModifier !== modifier &&
240
+ (anotherModifier.kind === SyntaxKind.PublicKeyword ||
241
+ anotherModifier.kind === SyntaxKind.ProtectedKeyword ||
242
+ anotherModifier.kind === SyntaxKind.PrivateKeyword)) {
243
+ throwError(anotherModifier, `Accessibility modifier already seen.`);
244
+ }
245
+ }
246
+ }
247
+ // `checkParameter` function in `typescript`
248
+ if (node.kind === SyntaxKind.Parameter &&
249
+ // In `typescript` package, it's `ts.hasSyntacticModifier(node, ts.ModifierFlags.ParameterPropertyModifier)`
250
+ // https://github.com/typescript-eslint/typescript-eslint/pull/6615#discussion_r1136489935
251
+ (modifier.kind === SyntaxKind.PublicKeyword ||
252
+ modifier.kind === SyntaxKind.PrivateKeyword ||
253
+ modifier.kind === SyntaxKind.ProtectedKeyword ||
254
+ modifier.kind === SyntaxKind.ReadonlyKeyword ||
255
+ modifier.kind === SyntaxKind.OverrideKeyword)) {
256
+ const func = getContainingFunction(node);
257
+ if (!(func?.kind === SyntaxKind.Constructor && nodeIsPresent(func.body))) {
258
+ throwError(modifier, 'A parameter property is only allowed in a constructor implementation.');
259
+ }
260
+ }
261
+ // There are more cases in `checkGrammarObjectLiteralExpression` in TypeScript.
262
+ // We may add more validations for them here in the future.
263
+ if (modifier.kind === SyntaxKind.AbstractKeyword &&
264
+ node.kind === SyntaxKind.MethodDeclaration &&
265
+ node.parent.kind === SyntaxKind.ObjectLiteralExpression) {
266
+ throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot be used here.`);
267
+ }
268
+ }
269
+ }
package/dist/convert.js CHANGED
@@ -38,6 +38,7 @@ exports.convertError = convertError;
38
38
  // There's lots of funny stuff due to the typing of ts.Node
39
39
  /* eslint-disable @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access */
40
40
  const ts = __importStar(require("typescript"));
41
+ const check_modifiers_1 = require("./check-modifiers");
41
42
  const getModifiers_1 = require("./getModifiers");
42
43
  const node_utils_1 = require("./node-utils");
43
44
  const ts_estree_1 = require("./ts-estree");
@@ -103,133 +104,7 @@ class Converter {
103
104
  if (this.options.allowInvalidAST) {
104
105
  return;
105
106
  }
106
- // typescript<5.0.0
107
- if ((0, node_utils_1.nodeHasIllegalDecorators)(node)) {
108
- this.#throwError(node.illegalDecorators[0], 'Decorators are not valid here.');
109
- }
110
- for (const decorator of (0, getModifiers_1.getDecorators)(node,
111
- /* includeIllegalDecorators */ true) ?? []) {
112
- // `checkGrammarModifiers` function in typescript
113
- if (!(0, node_utils_1.nodeCanBeDecorated)(node)) {
114
- if (ts.isMethodDeclaration(node) && !(0, node_utils_1.nodeIsPresent)(node.body)) {
115
- this.#throwError(decorator, 'A decorator can only decorate a method implementation, not an overload.');
116
- }
117
- else {
118
- this.#throwError(decorator, 'Decorators are not valid here.');
119
- }
120
- }
121
- }
122
- for (const modifier of (0, getModifiers_1.getModifiers)(node,
123
- /* includeIllegalModifiers */ true) ?? []) {
124
- if (modifier.kind !== SyntaxKind.ReadonlyKeyword) {
125
- if (node.kind === SyntaxKind.PropertySignature ||
126
- node.kind === SyntaxKind.MethodSignature) {
127
- this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a type member`);
128
- }
129
- if (node.kind === SyntaxKind.IndexSignature &&
130
- (modifier.kind !== SyntaxKind.StaticKeyword ||
131
- !ts.isClassLike(node.parent))) {
132
- this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on an index signature`);
133
- }
134
- }
135
- if (modifier.kind !== SyntaxKind.InKeyword &&
136
- modifier.kind !== SyntaxKind.OutKeyword &&
137
- modifier.kind !== SyntaxKind.ConstKeyword &&
138
- node.kind === SyntaxKind.TypeParameter) {
139
- this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a type parameter`);
140
- }
141
- if ((modifier.kind === SyntaxKind.InKeyword ||
142
- modifier.kind === SyntaxKind.OutKeyword) &&
143
- (node.kind !== SyntaxKind.TypeParameter ||
144
- !(ts.isInterfaceDeclaration(node.parent) ||
145
- ts.isClassLike(node.parent) ||
146
- ts.isTypeAliasDeclaration(node.parent)))) {
147
- this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier can only appear on a type parameter of a class, interface or type alias`);
148
- }
149
- if (modifier.kind === SyntaxKind.ReadonlyKeyword &&
150
- node.kind !== SyntaxKind.PropertyDeclaration &&
151
- node.kind !== SyntaxKind.PropertySignature &&
152
- node.kind !== SyntaxKind.IndexSignature &&
153
- node.kind !== SyntaxKind.Parameter) {
154
- this.#throwError(modifier, "'readonly' modifier can only appear on a property declaration or index signature.");
155
- }
156
- if (modifier.kind === SyntaxKind.DeclareKeyword &&
157
- ts.isClassLike(node.parent) &&
158
- !ts.isPropertyDeclaration(node)) {
159
- this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on class elements of this kind.`);
160
- }
161
- if (modifier.kind === SyntaxKind.DeclareKeyword &&
162
- ts.isVariableStatement(node)) {
163
- const declarationKind = (0, node_utils_1.getDeclarationKind)(node.declarationList);
164
- if (declarationKind === 'using' || declarationKind === 'await using') {
165
- this.#throwError(modifier, `'declare' modifier cannot appear on a '${declarationKind}' declaration.`);
166
- }
167
- }
168
- if (modifier.kind === SyntaxKind.AbstractKeyword &&
169
- node.kind !== SyntaxKind.ClassDeclaration &&
170
- node.kind !== SyntaxKind.ConstructorType &&
171
- node.kind !== SyntaxKind.MethodDeclaration &&
172
- node.kind !== SyntaxKind.PropertyDeclaration &&
173
- node.kind !== SyntaxKind.GetAccessor &&
174
- node.kind !== SyntaxKind.SetAccessor) {
175
- this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier can only appear on a class, method, or property declaration.`);
176
- }
177
- if ((modifier.kind === SyntaxKind.StaticKeyword ||
178
- modifier.kind === SyntaxKind.PublicKeyword ||
179
- modifier.kind === SyntaxKind.ProtectedKeyword ||
180
- modifier.kind === SyntaxKind.PrivateKeyword) &&
181
- (node.parent.kind === SyntaxKind.ModuleBlock ||
182
- node.parent.kind === SyntaxKind.SourceFile)) {
183
- this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a module or namespace element.`);
184
- }
185
- if (modifier.kind === SyntaxKind.AccessorKeyword &&
186
- node.kind !== SyntaxKind.PropertyDeclaration) {
187
- this.#throwError(modifier, "'accessor' modifier can only appear on a property declaration.");
188
- }
189
- // `checkGrammarAsyncModifier` function in `typescript`
190
- if (modifier.kind === SyntaxKind.AsyncKeyword &&
191
- node.kind !== SyntaxKind.MethodDeclaration &&
192
- node.kind !== SyntaxKind.FunctionDeclaration &&
193
- node.kind !== SyntaxKind.FunctionExpression &&
194
- node.kind !== SyntaxKind.ArrowFunction) {
195
- this.#throwError(modifier, "'async' modifier cannot be used here.");
196
- }
197
- // `checkGrammarModifiers` function in `typescript`
198
- if (node.kind === SyntaxKind.Parameter &&
199
- (modifier.kind === SyntaxKind.StaticKeyword ||
200
- modifier.kind === SyntaxKind.ExportKeyword ||
201
- modifier.kind === SyntaxKind.DeclareKeyword ||
202
- modifier.kind === SyntaxKind.AsyncKeyword)) {
203
- this.#throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a parameter.`);
204
- }
205
- // `checkGrammarModifiers` function in `typescript`
206
- if (modifier.kind === SyntaxKind.PublicKeyword ||
207
- modifier.kind === SyntaxKind.ProtectedKeyword ||
208
- modifier.kind === SyntaxKind.PrivateKeyword) {
209
- for (const anotherModifier of (0, getModifiers_1.getModifiers)(node) ?? []) {
210
- if (anotherModifier !== modifier &&
211
- (anotherModifier.kind === SyntaxKind.PublicKeyword ||
212
- anotherModifier.kind === SyntaxKind.ProtectedKeyword ||
213
- anotherModifier.kind === SyntaxKind.PrivateKeyword)) {
214
- this.#throwError(anotherModifier, `Accessibility modifier already seen.`);
215
- }
216
- }
217
- }
218
- // `checkParameter` function in `typescript`
219
- if (node.kind === SyntaxKind.Parameter &&
220
- // In `typescript` package, it's `ts.hasSyntacticModifier(node, ts.ModifierFlags.ParameterPropertyModifier)`
221
- // https://github.com/typescript-eslint/typescript-eslint/pull/6615#discussion_r1136489935
222
- (modifier.kind === SyntaxKind.PublicKeyword ||
223
- modifier.kind === SyntaxKind.PrivateKeyword ||
224
- modifier.kind === SyntaxKind.ProtectedKeyword ||
225
- modifier.kind === SyntaxKind.ReadonlyKeyword ||
226
- modifier.kind === SyntaxKind.OverrideKeyword)) {
227
- const func = (0, node_utils_1.getContainingFunction)(node);
228
- if (!(func.kind === SyntaxKind.Constructor && (0, node_utils_1.nodeIsPresent)(func.body))) {
229
- this.#throwError(modifier, 'A parameter property is only allowed in a constructor implementation.');
230
- }
231
- }
232
- }
107
+ (0, check_modifiers_1.checkModifiers)(node);
233
108
  }
234
109
  #throwError(node, message) {
235
110
  let start;
@@ -1110,6 +985,13 @@ class Converter {
1110
985
  }
1111
986
  // otherwise, it is a non-type accessor - intentional fallthrough
1112
987
  case SyntaxKind.MethodDeclaration: {
988
+ const isAbstract = (0, node_utils_1.hasModifier)(SyntaxKind.AbstractKeyword, node);
989
+ if (isAbstract && node.body) {
990
+ this.#throwError(node.name, node.kind === SyntaxKind.GetAccessor ||
991
+ node.kind === SyntaxKind.SetAccessor
992
+ ? 'An abstract accessor cannot have an implementation.'
993
+ : `Method '${(0, node_utils_1.declarationNameToString)(node.name, this.ast)}' cannot have an implementation because it is marked abstract.`);
994
+ }
1113
995
  const method = this.createNode(node, {
1114
996
  type: !node.body
1115
997
  ? ts_estree_1.AST_NODE_TYPES.TSEmptyBodyFunctionExpression
@@ -1152,7 +1034,7 @@ class Converter {
1152
1034
  /**
1153
1035
  * TypeScript class methods can be defined as "abstract"
1154
1036
  */
1155
- const methodDefinitionType = (0, node_utils_1.hasModifier)(SyntaxKind.AbstractKeyword, node)
1037
+ const methodDefinitionType = isAbstract
1156
1038
  ? ts_estree_1.AST_NODE_TYPES.TSAbstractMethodDefinition
1157
1039
  : ts_estree_1.AST_NODE_TYPES.MethodDefinition;
1158
1040
  result = this.createNode(node, {
@@ -1719,6 +1601,13 @@ class Converter {
1719
1601
  });
1720
1602
  // Binary Operations
1721
1603
  case SyntaxKind.BinaryExpression: {
1604
+ if (node.operatorToken.kind !== SyntaxKind.InKeyword &&
1605
+ node.left.kind === SyntaxKind.PrivateIdentifier) {
1606
+ this.#throwError(node.left, "Private identifiers cannot appear on the right-hand-side of an 'in' expression.");
1607
+ }
1608
+ else if (node.right.kind === SyntaxKind.PrivateIdentifier) {
1609
+ this.#throwError(node.right, "Private identifiers are only allowed on the left-hand-side of an 'in' expression.");
1610
+ }
1722
1611
  // TypeScript uses BinaryExpression for sequences as well
1723
1612
  if ((0, node_utils_1.isComma)(node.operatorToken)) {
1724
1613
  const result = this.createNode(node, {
@@ -1,5 +1,5 @@
1
1
  import * as ts from 'typescript';
2
- import type { TSESTree, TSNode } from './ts-estree';
2
+ import type { TSESTree } from './ts-estree';
3
3
  import { AST_NODE_TYPES, AST_TOKEN_TYPES } from './ts-estree';
4
4
  declare const SyntaxKind: typeof ts.SyntaxKind;
5
5
  type LogicalOperatorKind = ts.SyntaxKind.AmpersandAmpersandToken | ts.SyntaxKind.BarBarToken | ts.SyntaxKind.QuestionQuestionToken;
@@ -172,9 +172,6 @@ export declare class TSError extends Error {
172
172
  get column(): number;
173
173
  }
174
174
  export declare function createError(message: string, ast: ts.SourceFile, startIndex: number, endIndex?: number): TSError;
175
- export declare function nodeHasIllegalDecorators(node: ts.Node): node is {
176
- illegalDecorators: ts.Node[];
177
- } & ts.Node;
178
175
  export declare function nodeHasTokens(n: ts.Node, ast: ts.SourceFile): boolean;
179
176
  /**
180
177
  * Like `forEach`, but suitable for use with numbers and strings (which may be falsy).
@@ -183,9 +180,7 @@ export declare function firstDefined<T, U>(array: readonly T[] | undefined, call
183
180
  export declare function identifierIsThisKeyword(id: ts.Identifier): boolean;
184
181
  export declare function isThisIdentifier(node: ts.Node | undefined): node is ts.Identifier;
185
182
  export declare function isThisInTypeQuery(node: ts.Node): boolean;
186
- export declare function nodeIsPresent(node: ts.Node | undefined): node is ts.Node;
187
- export declare function getContainingFunction(node: ts.Node): ts.SignatureDeclaration | undefined;
188
- export declare function nodeCanBeDecorated(node: TSNode): boolean;
189
183
  export declare function isValidAssignmentTarget(node: ts.Node): boolean;
190
184
  export declare function getNamespaceModifiers(node: ts.ModuleDeclaration): ts.Modifier[] | undefined;
185
+ export declare function declarationNameToString(name: ts.Node, ast: ts.SourceFile): string;
191
186
  export {};
@@ -62,17 +62,14 @@ exports.getTokenType = getTokenType;
62
62
  exports.convertToken = convertToken;
63
63
  exports.convertTokens = convertTokens;
64
64
  exports.createError = createError;
65
- exports.nodeHasIllegalDecorators = nodeHasIllegalDecorators;
66
65
  exports.nodeHasTokens = nodeHasTokens;
67
66
  exports.firstDefined = firstDefined;
68
67
  exports.identifierIsThisKeyword = identifierIsThisKeyword;
69
68
  exports.isThisIdentifier = isThisIdentifier;
70
69
  exports.isThisInTypeQuery = isThisInTypeQuery;
71
- exports.nodeIsPresent = nodeIsPresent;
72
- exports.getContainingFunction = getContainingFunction;
73
- exports.nodeCanBeDecorated = nodeCanBeDecorated;
74
70
  exports.isValidAssignmentTarget = isValidAssignmentTarget;
75
71
  exports.getNamespaceModifiers = getNamespaceModifiers;
72
+ exports.declarationNameToString = declarationNameToString;
76
73
  const ts = __importStar(require("typescript"));
77
74
  const getModifiers_1 = require("./getModifiers");
78
75
  const xhtml_entities_1 = require("./jsx/xhtml-entities");
@@ -567,10 +564,6 @@ function createError(message, ast, startIndex, endIndex = startIndex) {
567
564
  });
568
565
  return new TSError(message, ast.fileName, { end, start });
569
566
  }
570
- function nodeHasIllegalDecorators(node) {
571
- return !!('illegalDecorators' in node &&
572
- node.illegalDecorators?.length);
573
- }
574
567
  function nodeHasTokens(n, ast) {
575
568
  // If we have a token or node that has a non-zero width, it must have tokens.
576
569
  // Note: getWidth() does not take trivia into account.
@@ -615,89 +608,6 @@ function isThisInTypeQuery(node) {
615
608
  }
616
609
  return node.parent.kind === SyntaxKind.TypeQuery;
617
610
  }
618
- // `ts.nodeIsMissing`
619
- function nodeIsMissing(node) {
620
- if (node == null) {
621
- return true;
622
- }
623
- return (node.pos === node.end &&
624
- node.pos >= 0 &&
625
- node.kind !== SyntaxKind.EndOfFileToken);
626
- }
627
- // `ts.nodeIsPresent`
628
- function nodeIsPresent(node) {
629
- return !nodeIsMissing(node);
630
- }
631
- // `ts.getContainingFunction`
632
- function getContainingFunction(node) {
633
- return ts.findAncestor(node.parent, ts.isFunctionLike);
634
- }
635
- // `ts.hasAbstractModifier`
636
- function hasAbstractModifier(node) {
637
- return hasModifier(SyntaxKind.AbstractKeyword, node);
638
- }
639
- // `ts.getThisParameter`
640
- function getThisParameter(signature) {
641
- if (signature.parameters.length && !ts.isJSDocSignature(signature)) {
642
- const thisParameter = signature.parameters[0];
643
- if (parameterIsThisKeyword(thisParameter)) {
644
- return thisParameter;
645
- }
646
- }
647
- return null;
648
- }
649
- // `ts.parameterIsThisKeyword`
650
- function parameterIsThisKeyword(parameter) {
651
- return isThisIdentifier(parameter.name);
652
- }
653
- // Rewrite version of `ts.nodeCanBeDecorated`
654
- // Returns `true` for both `useLegacyDecorators: true` and `useLegacyDecorators: false`
655
- function nodeCanBeDecorated(node) {
656
- switch (node.kind) {
657
- case SyntaxKind.ClassDeclaration:
658
- return true;
659
- case SyntaxKind.ClassExpression:
660
- // `ts.nodeCanBeDecorated` returns `false` if `useLegacyDecorators: true`
661
- return true;
662
- case SyntaxKind.PropertyDeclaration: {
663
- const { parent } = node;
664
- // `ts.nodeCanBeDecorated` uses this if `useLegacyDecorators: true`
665
- if (ts.isClassDeclaration(parent)) {
666
- return true;
667
- }
668
- // `ts.nodeCanBeDecorated` uses this if `useLegacyDecorators: false`
669
- if (ts.isClassLike(parent) && !hasAbstractModifier(node)) {
670
- return true;
671
- }
672
- return false;
673
- }
674
- case SyntaxKind.GetAccessor:
675
- case SyntaxKind.SetAccessor:
676
- case SyntaxKind.MethodDeclaration: {
677
- const { parent } = node;
678
- // In `ts.nodeCanBeDecorated`
679
- // when `useLegacyDecorators: true` uses `ts.isClassDeclaration`
680
- // when `useLegacyDecorators: true` uses `ts.isClassLike`
681
- return (Boolean(node.body) &&
682
- (ts.isClassDeclaration(parent) || ts.isClassLike(parent)));
683
- }
684
- case SyntaxKind.Parameter: {
685
- // `ts.nodeCanBeDecorated` returns `false` if `useLegacyDecorators: false`
686
- const { parent } = node;
687
- const grandparent = parent.parent;
688
- return (Boolean(parent) &&
689
- 'body' in parent &&
690
- Boolean(parent.body) &&
691
- (parent.kind === SyntaxKind.Constructor ||
692
- parent.kind === SyntaxKind.MethodDeclaration ||
693
- parent.kind === SyntaxKind.SetAccessor) &&
694
- getThisParameter(parent) !== node &&
695
- Boolean(grandparent) &&
696
- grandparent.kind === SyntaxKind.ClassDeclaration);
697
- }
698
- }
699
- return false;
700
- }
701
611
  function isValidAssignmentTarget(node) {
702
612
  switch (node.kind) {
703
613
  case SyntaxKind.Identifier:
@@ -734,3 +644,8 @@ function getNamespaceModifiers(node) {
734
644
  }
735
645
  return modifiers;
736
646
  }
647
+ // `ts.declarationNameToString`
648
+ function declarationNameToString(name, ast) {
649
+ const text = ast.text.slice(name.pos, name.end).trimStart();
650
+ return text || '(Missing)';
651
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/typescript-estree",
3
- "version": "8.45.1-alpha.8",
3
+ "version": "8.46.0",
4
4
  "description": "A parser that converts TypeScript source code into an ESTree compatible form",
5
5
  "files": [
6
6
  "dist",
@@ -52,10 +52,10 @@
52
52
  "typecheck": "yarn run -BT nx typecheck"
53
53
  },
54
54
  "dependencies": {
55
- "@typescript-eslint/project-service": "8.45.1-alpha.8",
56
- "@typescript-eslint/tsconfig-utils": "8.45.1-alpha.8",
57
- "@typescript-eslint/types": "8.45.1-alpha.8",
58
- "@typescript-eslint/visitor-keys": "8.45.1-alpha.8",
55
+ "@typescript-eslint/project-service": "8.46.0",
56
+ "@typescript-eslint/tsconfig-utils": "8.46.0",
57
+ "@typescript-eslint/types": "8.46.0",
58
+ "@typescript-eslint/visitor-keys": "8.46.0",
59
59
  "debug": "^4.3.4",
60
60
  "fast-glob": "^3.3.2",
61
61
  "is-glob": "^4.0.3",