Skip to content

Commit

Permalink
feat: 🚀complete parseMaybeDecoratorArguments and ts class
Browse files Browse the repository at this point in the history
TyrealHu committed Nov 17, 2022

Partially verified

This commit is signed with the committer’s verified signature.
gsmet’s contribution has been verified via GPG key.
We cannot verify signatures from co-authors, and some of the co-authors attributed to this commit require their commits to be signed.
1 parent 5a4cefa commit b5eb8c8
Showing 4 changed files with 1,702 additions and 522 deletions.
Binary file added .DS_Store
Binary file not shown.
2,107 changes: 1,600 additions & 507 deletions src/index.ts

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions src/parseutil.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
export class DestructuringErrors {
public shorthandAssign: number
public trailingComma: number
public parenthesizedAssign: number
public parenthesizedBind: number
public doubleProto: number

constructor() {
this.shorthandAssign =
this.trailingComma =
this.parenthesizedAssign =
this.parenthesizedBind =
this.doubleProto = -1
}
}

export function isPrivateNameConflicted(privateNameMap, element) {
const name = element.key.name
const curr = privateNameMap[name]

let next = "true"
if (element.type === "MethodDefinition" && (element.kind === "get" || element.kind === "set")) {
next = (element.static ? "s" : "i") + element.kind
}

// `class { get #a(){}; static set #a(_){} }` is also conflict.
if (
curr === "iget" && next === "iset" ||
curr === "iset" && next === "iget" ||
curr === "sget" && next === "sset" ||
curr === "sset" && next === "sget"
) {
privateNameMap[name] = "true"
return false
} else if (!curr) {
privateNameMap[name] = next
return false
} else {
return true
}
}

export function checkKeyName(node, name) {
const {computed, key} = node
return !computed && (
key.type === "Identifier" && key.name === name ||
key.type === "Literal" && key.value === name
)
}
68 changes: 53 additions & 15 deletions src/tokenType.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,70 @@
import { TokenType } from 'acorn'
// @ts-ignore
import { TokenType, keywordTypes } from 'acorn'

const startsExpr = true

// Succinct definitions of keyword token types
// @ts-ignore
function kw(name, options: any = {}) {
options.keyword = name
return new TokenType(name, options)
}

function kwLike(_name, options: any = {}) {
return new TokenType('name', options)
}

export const tsTokenType = {
as: kw('name', { startsExpr }),
from: kw('name', { startsExpr }),
require: kw('name', { startsExpr }),
abstract: kw('name', { startsExpr }),
declare: kw('name', { startsExpr }),
namespace: kw('name', { startsExpr }),
interface: kw('name', { startsExpr }),
type: kw('name', { startsExpr }),
asserts: kw('name', { startsExpr }),
is: kw("name", { startsExpr }),
let: kw("name", { startsExpr }),
enum: kw("name", { startsExpr }),
global: kw("name", { startsExpr }),
as: kwLike('name', { startsExpr }),
assert: kwLike('assert', { startsExpr }),
async: kwLike('async', { startsExpr }),
await: kwLike('await', { startsExpr }),
from: kwLike('from', { startsExpr }),
get: kwLike('get', { startsExpr }),
let: kwLike('let', { startsExpr }),
meta: kwLike('meta', { startsExpr }),
of: kwLike('of', { startsExpr }),
sent: kwLike('sent', { startsExpr }),
set: kwLike('set', { startsExpr }),
static: kwLike('static', { startsExpr }),
yield: kwLike('yield', { startsExpr }),

// Flow and TypeScript Keywordlike
asserts: kwLike('asserts', { startsExpr }),
checks: kwLike('checks', { startsExpr }),
exports: kwLike('exports', { startsExpr }),
global: kwLike('global', { startsExpr }),
implements: kwLike('implements', { startsExpr }),
intrinsic: kwLike('intrinsic', { startsExpr }),
infer: kwLike('infer', { startsExpr }),
is: kwLike('is', { startsExpr }),
mixins: kwLike('mixins', { startsExpr }),
proto: kwLike('proto', { startsExpr }),
require: kwLike('require', { startsExpr }),
// start: isTSTypeOperator
keyof: kwLike('keyof', { startsExpr }),
readonly: kwLike('readonly', { startsExpr }),
unique: kwLike('unique', { startsExpr }),
// end: isTSTypeOperator
// start: isTSDeclarationStart
abstract: kwLike('abstract', { startsExpr }),
declare: kwLike('declare', { startsExpr }),
enum: kwLike('enum', { startsExpr }),
module: kwLike('module', { startsExpr }),
namespace: kwLike('namespace', { startsExpr }),
// start: isFlowInterfaceOrTypeOrOpaque
interface: kwLike('interface', { startsExpr }),
type: kwLike('type', { startsExpr }),
// end: isTSDeclarationStart
opaque: kwLike('opaque', { startsExpr }),
// end: isFlowInterfaceOrTypeOrOpaque
}

export const jsxTokenType = {
// jsx
jsxTagStart: new TokenType('jsxTagStart', { startsExpr })
}

export const tsKeywordsRegExp = new RegExp(
'^(?:global|enum|let|is|asserts|declare|abstract|as|type|from|require|namespace|interface)$'
`^(?:${Object.keys(tsTokenType).join('|')})$`
)

0 comments on commit b5eb8c8

Please sign in to comment.