@typescript-eslint/typescript-estree 8.48.1-alpha.0 → 8.48.1-alpha.10

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.
@@ -125,26 +125,20 @@ function nodeHasIllegalDecorators(node) {
125
125
  return !!('illegalDecorators' in node &&
126
126
  node.illegalDecorators?.length);
127
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
128
  function checkModifiers(node) {
135
129
  // typescript<5.0.0
136
130
  if (nodeHasIllegalDecorators(node)) {
137
- throwError(node.illegalDecorators[0], 'Decorators are not valid here.');
131
+ throw (0, node_utils_1.createError)(node.illegalDecorators[0], 'Decorators are not valid here.');
138
132
  }
139
133
  for (const decorator of (0, getModifiers_1.getDecorators)(node,
140
134
  /* includeIllegalDecorators */ true) ?? []) {
141
135
  // `checkGrammarModifiers` function in typescript
142
136
  if (!nodeCanBeDecorated(node)) {
143
137
  if (ts.isMethodDeclaration(node) && !nodeIsPresent(node.body)) {
144
- throwError(decorator, 'A decorator can only decorate a method implementation, not an overload.');
138
+ throw (0, node_utils_1.createError)(decorator, 'A decorator can only decorate a method implementation, not an overload.');
145
139
  }
146
140
  else {
147
- throwError(decorator, 'Decorators are not valid here.');
141
+ throw (0, node_utils_1.createError)(decorator, 'Decorators are not valid here.');
148
142
  }
149
143
  }
150
144
  }
@@ -153,19 +147,19 @@ function checkModifiers(node) {
153
147
  if (modifier.kind !== SyntaxKind.ReadonlyKeyword) {
154
148
  if (node.kind === SyntaxKind.PropertySignature ||
155
149
  node.kind === SyntaxKind.MethodSignature) {
156
- throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a type member`);
150
+ throw (0, node_utils_1.createError)(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a type member`);
157
151
  }
158
152
  if (node.kind === SyntaxKind.IndexSignature &&
159
153
  (modifier.kind !== SyntaxKind.StaticKeyword ||
160
154
  !ts.isClassLike(node.parent))) {
161
- throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on an index signature`);
155
+ throw (0, node_utils_1.createError)(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on an index signature`);
162
156
  }
163
157
  }
164
158
  if (modifier.kind !== SyntaxKind.InKeyword &&
165
159
  modifier.kind !== SyntaxKind.OutKeyword &&
166
160
  modifier.kind !== SyntaxKind.ConstKeyword &&
167
161
  node.kind === SyntaxKind.TypeParameter) {
168
- throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a type parameter`);
162
+ throw (0, node_utils_1.createError)(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a type parameter`);
169
163
  }
170
164
  if ((modifier.kind === SyntaxKind.InKeyword ||
171
165
  modifier.kind === SyntaxKind.OutKeyword) &&
@@ -173,25 +167,25 @@ function checkModifiers(node) {
173
167
  !(ts.isInterfaceDeclaration(node.parent) ||
174
168
  ts.isClassLike(node.parent) ||
175
169
  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`);
170
+ throw (0, node_utils_1.createError)(modifier, `'${ts.tokenToString(modifier.kind)}' modifier can only appear on a type parameter of a class, interface or type alias`);
177
171
  }
178
172
  if (modifier.kind === SyntaxKind.ReadonlyKeyword &&
179
173
  node.kind !== SyntaxKind.PropertyDeclaration &&
180
174
  node.kind !== SyntaxKind.PropertySignature &&
181
175
  node.kind !== SyntaxKind.IndexSignature &&
182
176
  node.kind !== SyntaxKind.Parameter) {
183
- throwError(modifier, "'readonly' modifier can only appear on a property declaration or index signature.");
177
+ throw (0, node_utils_1.createError)(modifier, "'readonly' modifier can only appear on a property declaration or index signature.");
184
178
  }
185
179
  if (modifier.kind === SyntaxKind.DeclareKeyword &&
186
180
  ts.isClassLike(node.parent) &&
187
181
  !ts.isPropertyDeclaration(node)) {
188
- throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on class elements of this kind.`);
182
+ throw (0, node_utils_1.createError)(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on class elements of this kind.`);
189
183
  }
190
184
  if (modifier.kind === SyntaxKind.DeclareKeyword &&
191
185
  ts.isVariableStatement(node)) {
192
186
  const declarationKind = (0, node_utils_1.getDeclarationKind)(node.declarationList);
193
187
  if (declarationKind === 'using' || declarationKind === 'await using') {
194
- throwError(modifier, `'declare' modifier cannot appear on a '${declarationKind}' declaration.`);
188
+ throw (0, node_utils_1.createError)(modifier, `'declare' modifier cannot appear on a '${declarationKind}' declaration.`);
195
189
  }
196
190
  }
197
191
  if (modifier.kind === SyntaxKind.AbstractKeyword &&
@@ -201,7 +195,7 @@ function checkModifiers(node) {
201
195
  node.kind !== SyntaxKind.PropertyDeclaration &&
202
196
  node.kind !== SyntaxKind.GetAccessor &&
203
197
  node.kind !== SyntaxKind.SetAccessor) {
204
- throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier can only appear on a class, method, or property declaration.`);
198
+ throw (0, node_utils_1.createError)(modifier, `'${ts.tokenToString(modifier.kind)}' modifier can only appear on a class, method, or property declaration.`);
205
199
  }
206
200
  if ((modifier.kind === SyntaxKind.StaticKeyword ||
207
201
  modifier.kind === SyntaxKind.PublicKeyword ||
@@ -209,11 +203,11 @@ function checkModifiers(node) {
209
203
  modifier.kind === SyntaxKind.PrivateKeyword) &&
210
204
  (node.parent.kind === SyntaxKind.ModuleBlock ||
211
205
  node.parent.kind === SyntaxKind.SourceFile)) {
212
- throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a module or namespace element.`);
206
+ throw (0, node_utils_1.createError)(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a module or namespace element.`);
213
207
  }
214
208
  if (modifier.kind === SyntaxKind.AccessorKeyword &&
215
209
  node.kind !== SyntaxKind.PropertyDeclaration) {
216
- throwError(modifier, "'accessor' modifier can only appear on a property declaration.");
210
+ throw (0, node_utils_1.createError)(modifier, "'accessor' modifier can only appear on a property declaration.");
217
211
  }
218
212
  // `checkGrammarAsyncModifier` function in `typescript`
219
213
  if (modifier.kind === SyntaxKind.AsyncKeyword &&
@@ -221,7 +215,7 @@ function checkModifiers(node) {
221
215
  node.kind !== SyntaxKind.FunctionDeclaration &&
222
216
  node.kind !== SyntaxKind.FunctionExpression &&
223
217
  node.kind !== SyntaxKind.ArrowFunction) {
224
- throwError(modifier, "'async' modifier cannot be used here.");
218
+ throw (0, node_utils_1.createError)(modifier, "'async' modifier cannot be used here.");
225
219
  }
226
220
  // `checkGrammarModifiers` function in `typescript`
227
221
  if (node.kind === SyntaxKind.Parameter &&
@@ -229,7 +223,7 @@ function checkModifiers(node) {
229
223
  modifier.kind === SyntaxKind.ExportKeyword ||
230
224
  modifier.kind === SyntaxKind.DeclareKeyword ||
231
225
  modifier.kind === SyntaxKind.AsyncKeyword)) {
232
- throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a parameter.`);
226
+ throw (0, node_utils_1.createError)(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot appear on a parameter.`);
233
227
  }
234
228
  // `checkGrammarModifiers` function in `typescript`
235
229
  if (modifier.kind === SyntaxKind.PublicKeyword ||
@@ -240,7 +234,7 @@ function checkModifiers(node) {
240
234
  (anotherModifier.kind === SyntaxKind.PublicKeyword ||
241
235
  anotherModifier.kind === SyntaxKind.ProtectedKeyword ||
242
236
  anotherModifier.kind === SyntaxKind.PrivateKeyword)) {
243
- throwError(anotherModifier, `Accessibility modifier already seen.`);
237
+ throw (0, node_utils_1.createError)(anotherModifier, `Accessibility modifier already seen.`);
244
238
  }
245
239
  }
246
240
  }
@@ -255,15 +249,15 @@ function checkModifiers(node) {
255
249
  modifier.kind === SyntaxKind.OverrideKeyword)) {
256
250
  const func = getContainingFunction(node);
257
251
  if (!(func?.kind === SyntaxKind.Constructor && nodeIsPresent(func.body))) {
258
- throwError(modifier, 'A parameter property is only allowed in a constructor implementation.');
252
+ throw (0, node_utils_1.createError)(modifier, 'A parameter property is only allowed in a constructor implementation.');
259
253
  }
260
254
  const param = node;
261
255
  if (param.dotDotDotToken) {
262
- throwError(modifier, 'A parameter property cannot be a rest parameter.');
256
+ throw (0, node_utils_1.createError)(modifier, 'A parameter property cannot be a rest parameter.');
263
257
  }
264
258
  if (param.name.kind === SyntaxKind.ArrayBindingPattern ||
265
259
  param.name.kind === SyntaxKind.ObjectBindingPattern) {
266
- throwError(modifier, 'A parameter property may not be declared using a binding pattern.');
260
+ throw (0, node_utils_1.createError)(modifier, 'A parameter property may not be declared using a binding pattern.');
267
261
  }
268
262
  }
269
263
  // There are more cases in `checkGrammarObjectLiteralExpression` in TypeScript.
@@ -271,7 +265,7 @@ function checkModifiers(node) {
271
265
  if (modifier.kind !== SyntaxKind.AsyncKeyword &&
272
266
  node.kind === SyntaxKind.MethodDeclaration &&
273
267
  node.parent.kind === SyntaxKind.ObjectLiteralExpression) {
274
- throwError(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot be used here.`);
268
+ throw (0, node_utils_1.createError)(modifier, `'${ts.tokenToString(modifier.kind)}' modifier cannot be used here.`);
275
269
  }
276
270
  }
277
271
  }
package/dist/convert.js CHANGED
@@ -49,7 +49,7 @@ const SyntaxKind = ts.SyntaxKind;
49
49
  * @returns converted error object
50
50
  */
51
51
  function convertError(error) {
52
- return (0, node_utils_1.createError)(('message' in error && error.message) || error.messageText, error.file, error.start);
52
+ return (0, node_utils_1.createError)(error.start, ('message' in error && error.message) || error.messageText, error.file);
53
53
  }
54
54
  function isPropertyAccessEntityNameExpression(node) {
55
55
  return (ts.isPropertyAccessExpression(node) &&
@@ -110,19 +110,7 @@ class Converter {
110
110
  if (this.options.allowInvalidAST) {
111
111
  return;
112
112
  }
113
- let start;
114
- let end;
115
- if (Array.isArray(node)) {
116
- [start, end] = node;
117
- }
118
- else if (typeof node === 'number') {
119
- start = end = node;
120
- }
121
- else {
122
- start = node.getStart(this.ast);
123
- end = node.getEnd();
124
- }
125
- throw (0, node_utils_1.createError)(message, this.ast, start, end);
113
+ throw (0, node_utils_1.createError)(node, message, this.ast);
126
114
  }
127
115
  /**
128
116
  * Creates a getter for a property under aliasKey that returns the value under
@@ -722,17 +710,16 @@ class Converter {
722
710
  }
723
711
  case SyntaxKind.VariableDeclaration: {
724
712
  const definite = !!node.exclamationToken;
725
- const init = this.convertChild(node.initializer);
726
- const id = this.convertBindingNameWithTypeAnnotation(node.name, node.type, node);
727
713
  if (definite) {
728
- if (init) {
714
+ if (node.initializer) {
729
715
  this.#throwError(node, 'Declarations with initializers cannot also have definite assignment assertions.');
730
716
  }
731
- else if (id.type !== ts_estree_1.AST_NODE_TYPES.Identifier ||
732
- !id.typeAnnotation) {
717
+ else if (node.name.kind !== SyntaxKind.Identifier || !node.type) {
733
718
  this.#throwError(node, 'Declarations with definite assignment assertions must also have type annotations.');
734
719
  }
735
720
  }
721
+ const init = this.convertChild(node.initializer);
722
+ const id = this.convertBindingNameWithTypeAnnotation(node.name, node.type, node);
736
723
  return this.createNode(node, {
737
724
  type: ts_estree_1.AST_NODE_TYPES.VariableDeclarator,
738
725
  definite,
@@ -155,6 +155,7 @@ export declare class TSError extends Error {
155
155
  offset: number;
156
156
  };
157
157
  };
158
+ name: string;
158
159
  constructor(message: string, fileName: string, location: {
159
160
  end: {
160
161
  column: number;
@@ -171,7 +172,8 @@ export declare class TSError extends Error {
171
172
  get lineNumber(): number;
172
173
  get column(): number;
173
174
  }
174
- export declare function createError(message: string, ast: ts.SourceFile, startIndex: number, endIndex?: number): TSError;
175
+ export declare function createError(node: ts.Node, message: string): TSError;
176
+ export declare function createError(node: number | ts.Node | TSESTree.Range, message: string, sourceFile: ts.SourceFile): TSError;
175
177
  export declare function nodeHasTokens(n: ts.Node, ast: ts.SourceFile): boolean;
176
178
  /**
177
179
  * Like `forEach`, but suitable for use with numbers and strings (which may be falsy).
@@ -533,15 +533,11 @@ function convertTokens(ast) {
533
533
  class TSError extends Error {
534
534
  fileName;
535
535
  location;
536
+ name = 'TSError';
536
537
  constructor(message, fileName, location) {
537
538
  super(message);
538
539
  this.fileName = fileName;
539
540
  this.location = location;
540
- Object.defineProperty(this, 'name', {
541
- configurable: true,
542
- enumerable: false,
543
- value: new.target.name,
544
- });
545
541
  }
546
542
  // For old version of ESLint https://github.com/typescript-eslint/typescript-eslint/pull/6556#discussion_r1123237311
547
543
  get index() {
@@ -557,12 +553,28 @@ class TSError extends Error {
557
553
  }
558
554
  }
559
555
  exports.TSError = TSError;
560
- function createError(message, ast, startIndex, endIndex = startIndex) {
556
+ function createError(node, message, sourceFile) {
557
+ let startIndex;
558
+ let endIndex;
559
+ if (Array.isArray(node)) {
560
+ [startIndex, endIndex] = node;
561
+ }
562
+ else if (typeof node === 'number') {
563
+ startIndex = endIndex = node;
564
+ }
565
+ else {
566
+ sourceFile ??= node.getSourceFile();
567
+ startIndex = node.getStart(sourceFile);
568
+ endIndex = node.getEnd();
569
+ }
570
+ if (!sourceFile) {
571
+ throw new Error('`sourceFile` is required.');
572
+ }
561
573
  const [start, end] = [startIndex, endIndex].map(offset => {
562
- const { character: column, line } = ast.getLineAndCharacterOfPosition(offset);
574
+ const { character: column, line } = sourceFile.getLineAndCharacterOfPosition(offset);
563
575
  return { column, line: line + 1, offset };
564
576
  });
565
- return new TSError(message, ast.fileName, { end, start });
577
+ return new TSError(message, sourceFile.fileName, { end, start });
566
578
  }
567
579
  function nodeHasTokens(n, ast) {
568
580
  // If we have a token or node that has a non-zero width, it must have tokens.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typescript-eslint/typescript-estree",
3
- "version": "8.48.1-alpha.0",
3
+ "version": "8.48.1-alpha.10",
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.48.1-alpha.0",
56
- "@typescript-eslint/tsconfig-utils": "8.48.1-alpha.0",
57
- "@typescript-eslint/types": "8.48.1-alpha.0",
58
- "@typescript-eslint/visitor-keys": "8.48.1-alpha.0",
55
+ "@typescript-eslint/project-service": "8.48.1-alpha.10",
56
+ "@typescript-eslint/tsconfig-utils": "8.48.1-alpha.10",
57
+ "@typescript-eslint/types": "8.48.1-alpha.10",
58
+ "@typescript-eslint/visitor-keys": "8.48.1-alpha.10",
59
59
  "debug": "^4.3.4",
60
60
  "minimatch": "^9.0.4",
61
61
  "semver": "^7.6.0",