From 310269da8dd48bc0805e29db223e22b046c4cd55 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Wed, 27 May 2020 17:02:54 +0100 Subject: [PATCH 1/4] Add type definitions for acorn.mjs For TypeScript projects that use the acorn.mjs distribution bundle, a separate `.mjs.d.ts` needs to be added to the folder. This was suggested in https://github.com/microsoft/TypeScript/issues/27957#issuecomment-623631119 In DevTools, we use this in https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2218015 to make it compile with TypeScript --- .gitignore | 4 +- acorn/dist/acorn.mjs.d.ts | 204 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 acorn/dist/acorn.mjs.d.ts diff --git a/.gitignore b/.gitignore index 1052d7d8a..983986903 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,9 @@ /.tern-port /local /bin/_acorn.js -/acorn/dist +/acorn/dist/* /acorn-loose/dist /acorn-walk/dist /yarn.lock +!/acorn/dist/acorn.d.ts +!/acorn/dist/acorn.mjs.d.ts \ No newline at end of file diff --git a/acorn/dist/acorn.mjs.d.ts b/acorn/dist/acorn.mjs.d.ts new file mode 100644 index 000000000..f9decb4fd --- /dev/null +++ b/acorn/dist/acorn.mjs.d.ts @@ -0,0 +1,204 @@ +export function parse(input: string, options?: Options): Node + +export function parseExpressionAt(input: string, pos?: number, options?: Options): Node + +export function tokenizer(input: string, options?: Options): { + getToken(): Token + [Symbol.iterator](): Iterator +} + +export interface Options { + ecmaVersion?: 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 + sourceType?: 'script' | 'module' + onInsertedSemicolon?: (lastTokEnd: number, lastTokEndLoc?: Position) => void + onTrailingComma?: (lastTokEnd: number, lastTokEndLoc?: Position) => void + allowReserved?: boolean | 'never' + allowReturnOutsideFunction?: boolean + allowImportExportEverywhere?: boolean + allowAwaitOutsideFunction?: boolean + allowHashBang?: boolean + locations?: boolean + onToken?: ((token: Token) => any) | Token[] + onComment?: (( + isBlock: boolean, text: string, start: number, end: number, startLoc?: Position, + endLoc?: Position + ) => void) | Comment[] + ranges?: boolean + program?: Node + sourceFile?: string + directSourceFile?: string + preserveParens?: boolean +} + +export class Parser { + constructor(options: Options, input: string, startPos?: number) + parse(this: Parser): Node + static parse(this: typeof Parser, input: string, options?: Options): Node + static parseExpressionAt(this: typeof Parser, input: string, pos: number, options?: Options): Node + static tokenizer(this: typeof Parser, input: string, options?: Options): { + getToken(): Token + [Symbol.iterator](): Iterator + } + static extend(this: typeof Parser, ...plugins: ((BaseParser: typeof Parser) => typeof Parser)[]): typeof Parser +} + +export interface Position { line: number; column: number; offset: number } + +export const defaultOptions: Options + +export function getLineInfo(input: string, offset: number): Position + +export class SourceLocation { + start: Position + end: Position + source?: string | null + constructor(p: Parser, start: Position, end: Position) +} + +export class Node { + type: string + start: number + end: number + loc?: SourceLocation + sourceFile?: string + range?: [number, number] + constructor(parser: Parser, pos: number, loc?: SourceLocation) +} + +export class TokenType { + label: string + keyword: string + beforeExpr: boolean + startsExpr: boolean + isLoop: boolean + isAssign: boolean + prefix: boolean + postfix: boolean + binop: number + updateContext?: (prevType: TokenType) => void + constructor(label: string, conf?: any) +} + +export const tokTypes: { + num: TokenType + regexp: TokenType + string: TokenType + name: TokenType + eof: TokenType + bracketL: TokenType + bracketR: TokenType + braceL: TokenType + braceR: TokenType + parenL: TokenType + parenR: TokenType + comma: TokenType + semi: TokenType + colon: TokenType + dot: TokenType + question: TokenType + arrow: TokenType + template: TokenType + ellipsis: TokenType + backQuote: TokenType + dollarBraceL: TokenType + eq: TokenType + assign: TokenType + incDec: TokenType + prefix: TokenType + logicalOR: TokenType + logicalAND: TokenType + bitwiseOR: TokenType + bitwiseXOR: TokenType + bitwiseAND: TokenType + equality: TokenType + relational: TokenType + bitShift: TokenType + plusMin: TokenType + modulo: TokenType + star: TokenType + slash: TokenType + starstar: TokenType + _break: TokenType + _case: TokenType + _catch: TokenType + _continue: TokenType + _debugger: TokenType + _default: TokenType + _do: TokenType + _else: TokenType + _finally: TokenType + _for: TokenType + _function: TokenType + _if: TokenType + _return: TokenType + _switch: TokenType + _throw: TokenType + _try: TokenType + _var: TokenType + _const: TokenType + _while: TokenType + _with: TokenType + _new: TokenType + _this: TokenType + _super: TokenType + _class: TokenType + _extends: TokenType + _export: TokenType + _import: TokenType + _null: TokenType + _true: TokenType + _false: TokenType + _in: TokenType + _instanceof: TokenType + _typeof: TokenType + _void: TokenType + _delete: TokenType +} + +export class TokContext { + constructor(token: string, isExpr: boolean, preserveSpace: boolean, override?: (p: Parser) => void) +} + +export const tokContexts: { + b_stat: TokContext + b_expr: TokContext + b_tmpl: TokContext + p_stat: TokContext + p_expr: TokContext + q_tmpl: TokContext + f_expr: TokContext +} + +export function isIdentifierStart(code: number, astral?: boolean): boolean + +export function isIdentifierChar(code: number, astral?: boolean): boolean + +export interface AbstractToken { +} + +export interface Comment extends AbstractToken { + type: string + value: string + start: number + end: number + loc?: SourceLocation + range?: [number, number] +} + +export class Token { + type: TokenType + value: any + start: number + end: number + loc?: SourceLocation + range?: [number, number] + constructor(p: Parser) +} + +export function isNewLine(code: number): boolean + +export const lineBreak: RegExp + +export const lineBreakG: RegExp + +export const version: string From e09c938d196ad2f808a0794e0954b763ae4974b4 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Thu, 28 May 2020 16:17:03 +0100 Subject: [PATCH 2/4] Fix duplication of types --- acorn/dist/acorn.d.ts | 211 +----------------------------------------- 1 file changed, 3 insertions(+), 208 deletions(-) diff --git a/acorn/dist/acorn.d.ts b/acorn/dist/acorn.d.ts index bda5f803c..3c292519c 100644 --- a/acorn/dist/acorn.d.ts +++ b/acorn/dist/acorn.d.ts @@ -1,209 +1,4 @@ -export as namespace acorn -export = acorn - -declare namespace acorn { - function parse(input: string, options?: Options): Node - - function parseExpressionAt(input: string, pos?: number, options?: Options): Node - - function tokenizer(input: string, options?: Options): { - getToken(): Token - [Symbol.iterator](): Iterator - } - - interface Options { - ecmaVersion?: 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 - sourceType?: 'script' | 'module' - onInsertedSemicolon?: (lastTokEnd: number, lastTokEndLoc?: Position) => void - onTrailingComma?: (lastTokEnd: number, lastTokEndLoc?: Position) => void - allowReserved?: boolean | 'never' - allowReturnOutsideFunction?: boolean - allowImportExportEverywhere?: boolean - allowAwaitOutsideFunction?: boolean - allowHashBang?: boolean - locations?: boolean - onToken?: ((token: Token) => any) | Token[] - onComment?: (( - isBlock: boolean, text: string, start: number, end: number, startLoc?: Position, - endLoc?: Position - ) => void) | Comment[] - ranges?: boolean - program?: Node - sourceFile?: string - directSourceFile?: string - preserveParens?: boolean - } - - class Parser { - constructor(options: Options, input: string, startPos?: number) - parse(this: Parser): Node - static parse(this: typeof Parser, input: string, options?: Options): Node - static parseExpressionAt(this: typeof Parser, input: string, pos: number, options?: Options): Node - static tokenizer(this: typeof Parser, input: string, options?: Options): { - getToken(): Token - [Symbol.iterator](): Iterator - } - static extend(this: typeof Parser, ...plugins: ((BaseParser: typeof Parser) => typeof Parser)[]): typeof Parser - } - - interface Position { line: number; column: number; offset: number } - - const defaultOptions: Options - - function getLineInfo(input: string, offset: number): Position - - class SourceLocation { - start: Position - end: Position - source?: string | null - constructor(p: Parser, start: Position, end: Position) - } - - class Node { - type: string - start: number - end: number - loc?: SourceLocation - sourceFile?: string - range?: [number, number] - constructor(parser: Parser, pos: number, loc?: SourceLocation) - } - - class TokenType { - label: string - keyword: string - beforeExpr: boolean - startsExpr: boolean - isLoop: boolean - isAssign: boolean - prefix: boolean - postfix: boolean - binop: number - updateContext?: (prevType: TokenType) => void - constructor(label: string, conf?: any) - } +import * as Acorn from './acorn.mjs' - const tokTypes: { - num: TokenType - regexp: TokenType - string: TokenType - name: TokenType - eof: TokenType - bracketL: TokenType - bracketR: TokenType - braceL: TokenType - braceR: TokenType - parenL: TokenType - parenR: TokenType - comma: TokenType - semi: TokenType - colon: TokenType - dot: TokenType - question: TokenType - arrow: TokenType - template: TokenType - ellipsis: TokenType - backQuote: TokenType - dollarBraceL: TokenType - eq: TokenType - assign: TokenType - incDec: TokenType - prefix: TokenType - logicalOR: TokenType - logicalAND: TokenType - bitwiseOR: TokenType - bitwiseXOR: TokenType - bitwiseAND: TokenType - equality: TokenType - relational: TokenType - bitShift: TokenType - plusMin: TokenType - modulo: TokenType - star: TokenType - slash: TokenType - starstar: TokenType - _break: TokenType - _case: TokenType - _catch: TokenType - _continue: TokenType - _debugger: TokenType - _default: TokenType - _do: TokenType - _else: TokenType - _finally: TokenType - _for: TokenType - _function: TokenType - _if: TokenType - _return: TokenType - _switch: TokenType - _throw: TokenType - _try: TokenType - _var: TokenType - _const: TokenType - _while: TokenType - _with: TokenType - _new: TokenType - _this: TokenType - _super: TokenType - _class: TokenType - _extends: TokenType - _export: TokenType - _import: TokenType - _null: TokenType - _true: TokenType - _false: TokenType - _in: TokenType - _instanceof: TokenType - _typeof: TokenType - _void: TokenType - _delete: TokenType - } - - class TokContext { - constructor(token: string, isExpr: boolean, preserveSpace: boolean, override?: (p: Parser) => void) - } - - const tokContexts: { - b_stat: TokContext - b_expr: TokContext - b_tmpl: TokContext - p_stat: TokContext - p_expr: TokContext - q_tmpl: TokContext - f_expr: TokContext - } - - function isIdentifierStart(code: number, astral?: boolean): boolean - - function isIdentifierChar(code: number, astral?: boolean): boolean - - interface AbstractToken { - } - - interface Comment extends AbstractToken { - type: string - value: string - start: number - end: number - loc?: SourceLocation - range?: [number, number] - } - - class Token { - type: TokenType - value: any - start: number - end: number - loc?: SourceLocation - range?: [number, number] - constructor(p: Parser) - } - - function isNewLine(code: number): boolean - - const lineBreak: RegExp - - const lineBreakG: RegExp - - const version: string -} +export as namespace acorn +export = Acorn From 3f9f277125284fd34d2e41fbb10ebf25d9f2b6a0 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Fri, 29 May 2020 14:43:52 +0100 Subject: [PATCH 3/4] Reverse import where .mjs.d.ts imports the .d.ts --- acorn/dist/acorn.d.ts | 211 +++++++++++++++++++++++++++++++++++++- acorn/dist/acorn.mjs.d.ts | 206 +------------------------------------ 2 files changed, 210 insertions(+), 207 deletions(-) diff --git a/acorn/dist/acorn.d.ts b/acorn/dist/acorn.d.ts index 3c292519c..bda5f803c 100644 --- a/acorn/dist/acorn.d.ts +++ b/acorn/dist/acorn.d.ts @@ -1,4 +1,209 @@ -import * as Acorn from './acorn.mjs' - export as namespace acorn -export = Acorn +export = acorn + +declare namespace acorn { + function parse(input: string, options?: Options): Node + + function parseExpressionAt(input: string, pos?: number, options?: Options): Node + + function tokenizer(input: string, options?: Options): { + getToken(): Token + [Symbol.iterator](): Iterator + } + + interface Options { + ecmaVersion?: 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 + sourceType?: 'script' | 'module' + onInsertedSemicolon?: (lastTokEnd: number, lastTokEndLoc?: Position) => void + onTrailingComma?: (lastTokEnd: number, lastTokEndLoc?: Position) => void + allowReserved?: boolean | 'never' + allowReturnOutsideFunction?: boolean + allowImportExportEverywhere?: boolean + allowAwaitOutsideFunction?: boolean + allowHashBang?: boolean + locations?: boolean + onToken?: ((token: Token) => any) | Token[] + onComment?: (( + isBlock: boolean, text: string, start: number, end: number, startLoc?: Position, + endLoc?: Position + ) => void) | Comment[] + ranges?: boolean + program?: Node + sourceFile?: string + directSourceFile?: string + preserveParens?: boolean + } + + class Parser { + constructor(options: Options, input: string, startPos?: number) + parse(this: Parser): Node + static parse(this: typeof Parser, input: string, options?: Options): Node + static parseExpressionAt(this: typeof Parser, input: string, pos: number, options?: Options): Node + static tokenizer(this: typeof Parser, input: string, options?: Options): { + getToken(): Token + [Symbol.iterator](): Iterator + } + static extend(this: typeof Parser, ...plugins: ((BaseParser: typeof Parser) => typeof Parser)[]): typeof Parser + } + + interface Position { line: number; column: number; offset: number } + + const defaultOptions: Options + + function getLineInfo(input: string, offset: number): Position + + class SourceLocation { + start: Position + end: Position + source?: string | null + constructor(p: Parser, start: Position, end: Position) + } + + class Node { + type: string + start: number + end: number + loc?: SourceLocation + sourceFile?: string + range?: [number, number] + constructor(parser: Parser, pos: number, loc?: SourceLocation) + } + + class TokenType { + label: string + keyword: string + beforeExpr: boolean + startsExpr: boolean + isLoop: boolean + isAssign: boolean + prefix: boolean + postfix: boolean + binop: number + updateContext?: (prevType: TokenType) => void + constructor(label: string, conf?: any) + } + + const tokTypes: { + num: TokenType + regexp: TokenType + string: TokenType + name: TokenType + eof: TokenType + bracketL: TokenType + bracketR: TokenType + braceL: TokenType + braceR: TokenType + parenL: TokenType + parenR: TokenType + comma: TokenType + semi: TokenType + colon: TokenType + dot: TokenType + question: TokenType + arrow: TokenType + template: TokenType + ellipsis: TokenType + backQuote: TokenType + dollarBraceL: TokenType + eq: TokenType + assign: TokenType + incDec: TokenType + prefix: TokenType + logicalOR: TokenType + logicalAND: TokenType + bitwiseOR: TokenType + bitwiseXOR: TokenType + bitwiseAND: TokenType + equality: TokenType + relational: TokenType + bitShift: TokenType + plusMin: TokenType + modulo: TokenType + star: TokenType + slash: TokenType + starstar: TokenType + _break: TokenType + _case: TokenType + _catch: TokenType + _continue: TokenType + _debugger: TokenType + _default: TokenType + _do: TokenType + _else: TokenType + _finally: TokenType + _for: TokenType + _function: TokenType + _if: TokenType + _return: TokenType + _switch: TokenType + _throw: TokenType + _try: TokenType + _var: TokenType + _const: TokenType + _while: TokenType + _with: TokenType + _new: TokenType + _this: TokenType + _super: TokenType + _class: TokenType + _extends: TokenType + _export: TokenType + _import: TokenType + _null: TokenType + _true: TokenType + _false: TokenType + _in: TokenType + _instanceof: TokenType + _typeof: TokenType + _void: TokenType + _delete: TokenType + } + + class TokContext { + constructor(token: string, isExpr: boolean, preserveSpace: boolean, override?: (p: Parser) => void) + } + + const tokContexts: { + b_stat: TokContext + b_expr: TokContext + b_tmpl: TokContext + p_stat: TokContext + p_expr: TokContext + q_tmpl: TokContext + f_expr: TokContext + } + + function isIdentifierStart(code: number, astral?: boolean): boolean + + function isIdentifierChar(code: number, astral?: boolean): boolean + + interface AbstractToken { + } + + interface Comment extends AbstractToken { + type: string + value: string + start: number + end: number + loc?: SourceLocation + range?: [number, number] + } + + class Token { + type: TokenType + value: any + start: number + end: number + loc?: SourceLocation + range?: [number, number] + constructor(p: Parser) + } + + function isNewLine(code: number): boolean + + const lineBreak: RegExp + + const lineBreakG: RegExp + + const version: string +} diff --git a/acorn/dist/acorn.mjs.d.ts b/acorn/dist/acorn.mjs.d.ts index f9decb4fd..ff1b4241a 100644 --- a/acorn/dist/acorn.mjs.d.ts +++ b/acorn/dist/acorn.mjs.d.ts @@ -1,204 +1,2 @@ -export function parse(input: string, options?: Options): Node - -export function parseExpressionAt(input: string, pos?: number, options?: Options): Node - -export function tokenizer(input: string, options?: Options): { - getToken(): Token - [Symbol.iterator](): Iterator -} - -export interface Options { - ecmaVersion?: 3 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 2015 | 2016 | 2017 | 2018 | 2019 | 2020 - sourceType?: 'script' | 'module' - onInsertedSemicolon?: (lastTokEnd: number, lastTokEndLoc?: Position) => void - onTrailingComma?: (lastTokEnd: number, lastTokEndLoc?: Position) => void - allowReserved?: boolean | 'never' - allowReturnOutsideFunction?: boolean - allowImportExportEverywhere?: boolean - allowAwaitOutsideFunction?: boolean - allowHashBang?: boolean - locations?: boolean - onToken?: ((token: Token) => any) | Token[] - onComment?: (( - isBlock: boolean, text: string, start: number, end: number, startLoc?: Position, - endLoc?: Position - ) => void) | Comment[] - ranges?: boolean - program?: Node - sourceFile?: string - directSourceFile?: string - preserveParens?: boolean -} - -export class Parser { - constructor(options: Options, input: string, startPos?: number) - parse(this: Parser): Node - static parse(this: typeof Parser, input: string, options?: Options): Node - static parseExpressionAt(this: typeof Parser, input: string, pos: number, options?: Options): Node - static tokenizer(this: typeof Parser, input: string, options?: Options): { - getToken(): Token - [Symbol.iterator](): Iterator - } - static extend(this: typeof Parser, ...plugins: ((BaseParser: typeof Parser) => typeof Parser)[]): typeof Parser -} - -export interface Position { line: number; column: number; offset: number } - -export const defaultOptions: Options - -export function getLineInfo(input: string, offset: number): Position - -export class SourceLocation { - start: Position - end: Position - source?: string | null - constructor(p: Parser, start: Position, end: Position) -} - -export class Node { - type: string - start: number - end: number - loc?: SourceLocation - sourceFile?: string - range?: [number, number] - constructor(parser: Parser, pos: number, loc?: SourceLocation) -} - -export class TokenType { - label: string - keyword: string - beforeExpr: boolean - startsExpr: boolean - isLoop: boolean - isAssign: boolean - prefix: boolean - postfix: boolean - binop: number - updateContext?: (prevType: TokenType) => void - constructor(label: string, conf?: any) -} - -export const tokTypes: { - num: TokenType - regexp: TokenType - string: TokenType - name: TokenType - eof: TokenType - bracketL: TokenType - bracketR: TokenType - braceL: TokenType - braceR: TokenType - parenL: TokenType - parenR: TokenType - comma: TokenType - semi: TokenType - colon: TokenType - dot: TokenType - question: TokenType - arrow: TokenType - template: TokenType - ellipsis: TokenType - backQuote: TokenType - dollarBraceL: TokenType - eq: TokenType - assign: TokenType - incDec: TokenType - prefix: TokenType - logicalOR: TokenType - logicalAND: TokenType - bitwiseOR: TokenType - bitwiseXOR: TokenType - bitwiseAND: TokenType - equality: TokenType - relational: TokenType - bitShift: TokenType - plusMin: TokenType - modulo: TokenType - star: TokenType - slash: TokenType - starstar: TokenType - _break: TokenType - _case: TokenType - _catch: TokenType - _continue: TokenType - _debugger: TokenType - _default: TokenType - _do: TokenType - _else: TokenType - _finally: TokenType - _for: TokenType - _function: TokenType - _if: TokenType - _return: TokenType - _switch: TokenType - _throw: TokenType - _try: TokenType - _var: TokenType - _const: TokenType - _while: TokenType - _with: TokenType - _new: TokenType - _this: TokenType - _super: TokenType - _class: TokenType - _extends: TokenType - _export: TokenType - _import: TokenType - _null: TokenType - _true: TokenType - _false: TokenType - _in: TokenType - _instanceof: TokenType - _typeof: TokenType - _void: TokenType - _delete: TokenType -} - -export class TokContext { - constructor(token: string, isExpr: boolean, preserveSpace: boolean, override?: (p: Parser) => void) -} - -export const tokContexts: { - b_stat: TokContext - b_expr: TokContext - b_tmpl: TokContext - p_stat: TokContext - p_expr: TokContext - q_tmpl: TokContext - f_expr: TokContext -} - -export function isIdentifierStart(code: number, astral?: boolean): boolean - -export function isIdentifierChar(code: number, astral?: boolean): boolean - -export interface AbstractToken { -} - -export interface Comment extends AbstractToken { - type: string - value: string - start: number - end: number - loc?: SourceLocation - range?: [number, number] -} - -export class Token { - type: TokenType - value: any - start: number - end: number - loc?: SourceLocation - range?: [number, number] - constructor(p: Parser) -} - -export function isNewLine(code: number): boolean - -export const lineBreak: RegExp - -export const lineBreakG: RegExp - -export const version: string +import acorn from "./acorn.js"; +export = acorn; \ No newline at end of file From ef06652c67d851140252fb2627e6aabaa9577b75 Mon Sep 17 00:00:00 2001 From: Tim van der Lippe Date: Fri, 29 May 2020 16:19:24 +0100 Subject: [PATCH 4/4] Use import * as This removes the need for an extra tsconfig flag --- acorn/dist/acorn.mjs.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acorn/dist/acorn.mjs.d.ts b/acorn/dist/acorn.mjs.d.ts index ff1b4241a..5f633595e 100644 --- a/acorn/dist/acorn.mjs.d.ts +++ b/acorn/dist/acorn.mjs.d.ts @@ -1,2 +1,2 @@ -import acorn from "./acorn.js"; +import * as acorn from "./acorn"; export = acorn; \ No newline at end of file