Skip to content

Update AST typings to es2022 #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 94 additions & 14 deletions src/ast/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ export type ESLintNode =
| ESLintPattern
| ESLintClassBody
| ESLintMethodDefinition
| ESLintPropertyDefinition
| ESLintStaticBlock
| ESLintPrivateIdentifier
| ESLintModuleDeclaration
| ESLintModuleSpecifier
| ESLintImportExpression
| ESLintLegacyRestProperty

/**
Expand Down Expand Up @@ -165,6 +169,7 @@ export interface ESLintForOfStatement extends HasLocation, HasParent {
left: ESLintVariableDeclaration | ESLintPattern
right: ESLintExpression
body: ESLintStatement
await: boolean
}

export interface ESLintLabeledStatement extends HasLocation, HasParent {
Expand Down Expand Up @@ -202,7 +207,7 @@ export interface ESLintTryStatement extends HasLocation, HasParent {

export interface ESLintCatchClause extends HasLocation, HasParent {
type: "CatchClause"
param: ESLintPattern
param: ESLintPattern | null
body: ESLintBlockStatement
}

Expand Down Expand Up @@ -251,17 +256,41 @@ export interface ESLintClassDeclaration extends HasLocation, HasParent {

export interface ESLintClassBody extends HasLocation, HasParent {
type: "ClassBody"
body: ESLintMethodDefinition[]
body: (
| ESLintMethodDefinition
| ESLintPropertyDefinition
| ESLintStaticBlock
)[]
}

export interface ESLintMethodDefinition extends HasLocation, HasParent {
type: "MethodDefinition"
kind: "constructor" | "method" | "get" | "set"
computed: boolean
static: boolean
key: ESLintExpression
key: ESLintExpression | ESLintPrivateIdentifier
value: ESLintFunctionExpression
}
export interface ESLintPropertyDefinition extends HasLocation, HasParent {
type: "PropertyDefinition"
computed: boolean
static: boolean
key: ESLintExpression | ESLintPrivateIdentifier
value: ESLintExpression | null
}

export interface ESLintStaticBlock
extends HasLocation,
HasParent,
Omit<ESLintBlockStatement, "type"> {
type: "StaticBlock"
body: ESLintStatement[]
}

export interface ESLintPrivateIdentifier extends HasLocation, HasParent {
type: "PrivateIdentifier"
name: string
}

export type ESLintModuleDeclaration =
| ESLintImportDeclaration
Expand All @@ -287,7 +316,7 @@ export interface ESLintImportDeclaration extends HasLocation, HasParent {

export interface ESLintImportSpecifier extends HasLocation, HasParent {
type: "ImportSpecifier"
imported: ESLintIdentifier
imported: ESLintIdentifier | ESLintStringLiteral
local: ESLintIdentifier
}

Expand All @@ -301,6 +330,11 @@ export interface ESLintImportNamespaceSpecifier extends HasLocation, HasParent {
local: ESLintIdentifier
}

export interface ESLintImportExpression extends HasLocation, HasParent {
type: "ImportExpression"
source: ESLintExpression
}

export interface ESLintExportNamedDeclaration extends HasLocation, HasParent {
type: "ExportNamedDeclaration"
declaration?: ESLintDeclaration | null
Expand All @@ -310,8 +344,8 @@ export interface ESLintExportNamedDeclaration extends HasLocation, HasParent {

export interface ESLintExportSpecifier extends HasLocation, HasParent {
type: "ExportSpecifier"
local: ESLintIdentifier
exported: ESLintIdentifier
local: ESLintIdentifier | ESLintStringLiteral
exported: ESLintIdentifier | ESLintStringLiteral
}

export interface ESLintExportDefaultDeclaration extends HasLocation, HasParent {
Expand All @@ -321,6 +355,7 @@ export interface ESLintExportDefaultDeclaration extends HasLocation, HasParent {

export interface ESLintExportAllDeclaration extends HasLocation, HasParent {
type: "ExportAllDeclaration"
exported: ESLintIdentifier | ESLintStringLiteral | null
source: ESLintLiteral
}

Expand Down Expand Up @@ -354,15 +389,55 @@ export interface ESLintIdentifier extends HasLocation, HasParent {
type: "Identifier"
name: string
}

export interface ESLintLiteral extends HasLocation, HasParent {
interface ESLintLiteralBase extends HasLocation, HasParent {
type: "Literal"
value: string | boolean | null | number | RegExp
value: string | boolean | null | number | RegExp | bigint
regex?: {
pattern: string
flags: string
}
bigint?: string
}
export interface ESLintStringLiteral extends ESLintLiteralBase {
value: string
regex?: undefined
bigint?: undefined
}
export interface ESLintBooleanLiteral extends ESLintLiteralBase {
value: boolean
regex?: undefined
bigint?: undefined
}
export interface ESLintNullLiteral extends ESLintLiteralBase {
value: null
regex?: undefined
bigint?: undefined
}
export interface ESLintNumberLiteral extends ESLintLiteralBase {
value: number
regex?: undefined
bigint?: undefined
}
export interface ESLintRegExpLiteral extends ESLintLiteralBase {
value: null | RegExp
regex: {
pattern: string
flags: string
}
bigint?: undefined
}
export interface ESLintBigIntLiteral extends ESLintLiteralBase {
value: null | bigint
regex?: undefined
bigint: string
}
export type ESLintLiteral =
| ESLintStringLiteral
| ESLintBooleanLiteral
| ESLintNullLiteral
| ESLintNumberLiteral
| ESLintRegExpLiteral
| ESLintBigIntLiteral

export interface ESLintThisExpression extends HasLocation, HasParent {
type: "ThisExpression"
Expand Down Expand Up @@ -447,7 +522,7 @@ export interface ESLintBinaryExpression extends HasLocation, HasParent {
| "&"
| "in"
| "instanceof"
left: ESLintExpression
left: ESLintExpression | ESLintPrivateIdentifier
right: ESLintExpression
}

Expand All @@ -467,6 +542,9 @@ export interface ESLintAssignmentExpression extends HasLocation, HasParent {
| "|="
| "^="
| "&="
| "||="
| "&&="
| "??="
left: ESLintPattern
right: ESLintExpression
}
Expand All @@ -480,7 +558,7 @@ export interface ESLintUpdateExpression extends HasLocation, HasParent {

export interface ESLintLogicalExpression extends HasLocation, HasParent {
type: "LogicalExpression"
operator: "||" | "&&"
operator: "||" | "&&" | "??"
left: ESLintExpression
right: ESLintExpression
}
Expand Down Expand Up @@ -514,7 +592,7 @@ export interface ESLintMemberExpression extends HasLocation, HasParent {
optional: boolean
computed: boolean
object: ESLintExpression | ESLintSuper
property: ESLintExpression
property: ESLintExpression | ESLintPrivateIdentifier
}

export interface ESLintYieldExpression extends HasLocation, HasParent {
Expand Down Expand Up @@ -544,7 +622,7 @@ export interface ESLintTemplateElement extends HasLocation, HasParent {
type: "TemplateElement"
tail: boolean
value: {
cooked: string
cooked: string | null
raw: string
}
}
Expand Down Expand Up @@ -607,9 +685,11 @@ export interface ESLintAssignmentPattern extends HasLocation, HasParent {
right: ESLintExpression
}

export type ESLintChainElement = ESLintCallExpression | ESLintMemberExpression

export interface ESLintChainExpression extends HasLocation, HasParent {
type: "ChainExpression"
expression: ESLintExpression
expression: ESLintChainElement
}

/**
Expand Down
15 changes: 12 additions & 3 deletions src/script-setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,18 @@ function getScriptSetupCodeBlocks(
(t) => t.range[0] === spec.local.range[0],
exportTokenIndex,
)
checkToken(tokens[localTokenIndex], spec.local.name)
checkToken(
tokens[localTokenIndex],
(spec.local as ESLintIdentifier).name,
)
const asToken = tokens[localTokenIndex + 1]
checkToken(asToken, "as")
restoreTokens.push(asToken)
const exportedToken = tokens[localTokenIndex + 2]
checkToken(exportedToken, spec.exported.name)
checkToken(
exportedToken,
(spec.exported as ESLintIdentifier).name,
)
restoreTokens.push(exportedToken)
processAppend(
statementCodeBlocks,
Expand Down Expand Up @@ -687,7 +693,10 @@ function getScriptSetupCodeBlocks(
) {
const spec = body.specifiers[index]
const local = locals[index]
if (spec.local.name !== local.name) {
if (
(spec.local as ESLintIdentifier).name !==
local.name
) {
return null
}
map.set(spec, local)
Expand Down