Skip to content

Commit 25c6847

Browse files
authored
Update AST typings to es2022 (#141)
1 parent 108faa6 commit 25c6847

File tree

2 files changed

+106
-17
lines changed

2 files changed

+106
-17
lines changed

Diff for: src/ast/nodes.ts

+94-14
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,12 @@ export type ESLintNode =
5555
| ESLintPattern
5656
| ESLintClassBody
5757
| ESLintMethodDefinition
58+
| ESLintPropertyDefinition
59+
| ESLintStaticBlock
60+
| ESLintPrivateIdentifier
5861
| ESLintModuleDeclaration
5962
| ESLintModuleSpecifier
63+
| ESLintImportExpression
6064
| ESLintLegacyRestProperty
6165

6266
/**
@@ -165,6 +169,7 @@ export interface ESLintForOfStatement extends HasLocation, HasParent {
165169
left: ESLintVariableDeclaration | ESLintPattern
166170
right: ESLintExpression
167171
body: ESLintStatement
172+
await: boolean
168173
}
169174

170175
export interface ESLintLabeledStatement extends HasLocation, HasParent {
@@ -202,7 +207,7 @@ export interface ESLintTryStatement extends HasLocation, HasParent {
202207

203208
export interface ESLintCatchClause extends HasLocation, HasParent {
204209
type: "CatchClause"
205-
param: ESLintPattern
210+
param: ESLintPattern | null
206211
body: ESLintBlockStatement
207212
}
208213

@@ -251,17 +256,41 @@ export interface ESLintClassDeclaration extends HasLocation, HasParent {
251256

252257
export interface ESLintClassBody extends HasLocation, HasParent {
253258
type: "ClassBody"
254-
body: ESLintMethodDefinition[]
259+
body: (
260+
| ESLintMethodDefinition
261+
| ESLintPropertyDefinition
262+
| ESLintStaticBlock
263+
)[]
255264
}
256265

257266
export interface ESLintMethodDefinition extends HasLocation, HasParent {
258267
type: "MethodDefinition"
259268
kind: "constructor" | "method" | "get" | "set"
260269
computed: boolean
261270
static: boolean
262-
key: ESLintExpression
271+
key: ESLintExpression | ESLintPrivateIdentifier
263272
value: ESLintFunctionExpression
264273
}
274+
export interface ESLintPropertyDefinition extends HasLocation, HasParent {
275+
type: "PropertyDefinition"
276+
computed: boolean
277+
static: boolean
278+
key: ESLintExpression | ESLintPrivateIdentifier
279+
value: ESLintExpression | null
280+
}
281+
282+
export interface ESLintStaticBlock
283+
extends HasLocation,
284+
HasParent,
285+
Omit<ESLintBlockStatement, "type"> {
286+
type: "StaticBlock"
287+
body: ESLintStatement[]
288+
}
289+
290+
export interface ESLintPrivateIdentifier extends HasLocation, HasParent {
291+
type: "PrivateIdentifier"
292+
name: string
293+
}
265294

266295
export type ESLintModuleDeclaration =
267296
| ESLintImportDeclaration
@@ -287,7 +316,7 @@ export interface ESLintImportDeclaration extends HasLocation, HasParent {
287316

288317
export interface ESLintImportSpecifier extends HasLocation, HasParent {
289318
type: "ImportSpecifier"
290-
imported: ESLintIdentifier
319+
imported: ESLintIdentifier | ESLintStringLiteral
291320
local: ESLintIdentifier
292321
}
293322

@@ -301,6 +330,11 @@ export interface ESLintImportNamespaceSpecifier extends HasLocation, HasParent {
301330
local: ESLintIdentifier
302331
}
303332

333+
export interface ESLintImportExpression extends HasLocation, HasParent {
334+
type: "ImportExpression"
335+
source: ESLintExpression
336+
}
337+
304338
export interface ESLintExportNamedDeclaration extends HasLocation, HasParent {
305339
type: "ExportNamedDeclaration"
306340
declaration?: ESLintDeclaration | null
@@ -310,8 +344,8 @@ export interface ESLintExportNamedDeclaration extends HasLocation, HasParent {
310344

311345
export interface ESLintExportSpecifier extends HasLocation, HasParent {
312346
type: "ExportSpecifier"
313-
local: ESLintIdentifier
314-
exported: ESLintIdentifier
347+
local: ESLintIdentifier | ESLintStringLiteral
348+
exported: ESLintIdentifier | ESLintStringLiteral
315349
}
316350

317351
export interface ESLintExportDefaultDeclaration extends HasLocation, HasParent {
@@ -321,6 +355,7 @@ export interface ESLintExportDefaultDeclaration extends HasLocation, HasParent {
321355

322356
export interface ESLintExportAllDeclaration extends HasLocation, HasParent {
323357
type: "ExportAllDeclaration"
358+
exported: ESLintIdentifier | ESLintStringLiteral | null
324359
source: ESLintLiteral
325360
}
326361

@@ -354,15 +389,55 @@ export interface ESLintIdentifier extends HasLocation, HasParent {
354389
type: "Identifier"
355390
name: string
356391
}
357-
358-
export interface ESLintLiteral extends HasLocation, HasParent {
392+
interface ESLintLiteralBase extends HasLocation, HasParent {
359393
type: "Literal"
360-
value: string | boolean | null | number | RegExp
394+
value: string | boolean | null | number | RegExp | bigint
361395
regex?: {
362396
pattern: string
363397
flags: string
364398
}
399+
bigint?: string
365400
}
401+
export interface ESLintStringLiteral extends ESLintLiteralBase {
402+
value: string
403+
regex?: undefined
404+
bigint?: undefined
405+
}
406+
export interface ESLintBooleanLiteral extends ESLintLiteralBase {
407+
value: boolean
408+
regex?: undefined
409+
bigint?: undefined
410+
}
411+
export interface ESLintNullLiteral extends ESLintLiteralBase {
412+
value: null
413+
regex?: undefined
414+
bigint?: undefined
415+
}
416+
export interface ESLintNumberLiteral extends ESLintLiteralBase {
417+
value: number
418+
regex?: undefined
419+
bigint?: undefined
420+
}
421+
export interface ESLintRegExpLiteral extends ESLintLiteralBase {
422+
value: null | RegExp
423+
regex: {
424+
pattern: string
425+
flags: string
426+
}
427+
bigint?: undefined
428+
}
429+
export interface ESLintBigIntLiteral extends ESLintLiteralBase {
430+
value: null | bigint
431+
regex?: undefined
432+
bigint: string
433+
}
434+
export type ESLintLiteral =
435+
| ESLintStringLiteral
436+
| ESLintBooleanLiteral
437+
| ESLintNullLiteral
438+
| ESLintNumberLiteral
439+
| ESLintRegExpLiteral
440+
| ESLintBigIntLiteral
366441

367442
export interface ESLintThisExpression extends HasLocation, HasParent {
368443
type: "ThisExpression"
@@ -447,7 +522,7 @@ export interface ESLintBinaryExpression extends HasLocation, HasParent {
447522
| "&"
448523
| "in"
449524
| "instanceof"
450-
left: ESLintExpression
525+
left: ESLintExpression | ESLintPrivateIdentifier
451526
right: ESLintExpression
452527
}
453528

@@ -467,6 +542,9 @@ export interface ESLintAssignmentExpression extends HasLocation, HasParent {
467542
| "|="
468543
| "^="
469544
| "&="
545+
| "||="
546+
| "&&="
547+
| "??="
470548
left: ESLintPattern
471549
right: ESLintExpression
472550
}
@@ -480,7 +558,7 @@ export interface ESLintUpdateExpression extends HasLocation, HasParent {
480558

481559
export interface ESLintLogicalExpression extends HasLocation, HasParent {
482560
type: "LogicalExpression"
483-
operator: "||" | "&&"
561+
operator: "||" | "&&" | "??"
484562
left: ESLintExpression
485563
right: ESLintExpression
486564
}
@@ -514,7 +592,7 @@ export interface ESLintMemberExpression extends HasLocation, HasParent {
514592
optional: boolean
515593
computed: boolean
516594
object: ESLintExpression | ESLintSuper
517-
property: ESLintExpression
595+
property: ESLintExpression | ESLintPrivateIdentifier
518596
}
519597

520598
export interface ESLintYieldExpression extends HasLocation, HasParent {
@@ -544,7 +622,7 @@ export interface ESLintTemplateElement extends HasLocation, HasParent {
544622
type: "TemplateElement"
545623
tail: boolean
546624
value: {
547-
cooked: string
625+
cooked: string | null
548626
raw: string
549627
}
550628
}
@@ -607,9 +685,11 @@ export interface ESLintAssignmentPattern extends HasLocation, HasParent {
607685
right: ESLintExpression
608686
}
609687

688+
export type ESLintChainElement = ESLintCallExpression | ESLintMemberExpression
689+
610690
export interface ESLintChainExpression extends HasLocation, HasParent {
611691
type: "ChainExpression"
612-
expression: ESLintExpression
692+
expression: ESLintChainElement
613693
}
614694

615695
/**

Diff for: src/script-setup/index.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -627,12 +627,18 @@ function getScriptSetupCodeBlocks(
627627
(t) => t.range[0] === spec.local.range[0],
628628
exportTokenIndex,
629629
)
630-
checkToken(tokens[localTokenIndex], spec.local.name)
630+
checkToken(
631+
tokens[localTokenIndex],
632+
(spec.local as ESLintIdentifier).name,
633+
)
631634
const asToken = tokens[localTokenIndex + 1]
632635
checkToken(asToken, "as")
633636
restoreTokens.push(asToken)
634637
const exportedToken = tokens[localTokenIndex + 2]
635-
checkToken(exportedToken, spec.exported.name)
638+
checkToken(
639+
exportedToken,
640+
(spec.exported as ESLintIdentifier).name,
641+
)
636642
restoreTokens.push(exportedToken)
637643
processAppend(
638644
statementCodeBlocks,
@@ -687,7 +693,10 @@ function getScriptSetupCodeBlocks(
687693
) {
688694
const spec = body.specifiers[index]
689695
const local = locals[index]
690-
if (spec.local.name !== local.name) {
696+
if (
697+
(spec.local as ESLintIdentifier).name !==
698+
local.name
699+
) {
691700
return null
692701
}
693702
map.set(spec, local)

0 commit comments

Comments
 (0)