file_path
stringlengths
3
280
file_language
stringclasses
66 values
content
stringlengths
1
1.04M
repo_name
stringlengths
5
92
repo_stars
int64
0
154k
repo_description
stringlengths
0
402
repo_primary_language
stringclasses
108 values
developer_username
stringlengths
1
25
developer_name
stringlengths
0
30
developer_company
stringlengths
0
82
crates/swc_ecma_parser/tests/tsc/parserMethodSignature1.ts
TypeScript
interface I { A(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserMethodSignature10.ts
TypeScript
interface I { 1?(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserMethodSignature11.ts
TypeScript
interface I { 2<T>(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserMethodSignature12.ts
TypeScript
interface I { 3?<T>(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserMethodSignature2.ts
TypeScript
interface I { B?(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserMethodSignature3.ts
TypeScript
interface I { C<T>(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserMethodSignature4.ts
TypeScript
interface I { D?<T>(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserMethodSignature5.ts
TypeScript
interface I { "E"(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserMethodSignature6.ts
TypeScript
interface I { "F"?(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserMethodSignature7.ts
TypeScript
interface I { "G"<T>(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserMethodSignature8.ts
TypeScript
interface I { "H"?<T>(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserMethodSignature9.ts
TypeScript
interface I { 0(); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserModifierOnPropertySignature2.ts
TypeScript
interface Foo{ public biz; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserModule1.ts
TypeScript
export module CompilerDiagnostics { export var debug = false; export interface IDiagnosticWriter { Alert(output: string): void; } export var diagnosticWriter: IDiagnosticWriter = null; export var analysisPass: number = 0; export function Alert(output: string) { if (diagnosticWriter) { diagnosticWriter.Alert(output); } } export function debugPrint(s: string) { if (debug) { Alert(s); } } export function assert(condition: boolean, s: string) { if (debug) { if (!condition) { Alert(s); } } } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserModuleDeclaration10.ts
TypeScript
function data(): string; function next(): string;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserModuleDeclaration11.ts
TypeScript
declare module string { interface X { } export function foo(s: string); } string.foo("abc"); var x: string.X;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserModuleDeclaration12.ts
TypeScript
module A.string { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserModuleDeclaration2.ts
TypeScript
declare module "Foo" { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserModuleDeclaration3.d.ts
TypeScript
declare module M { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserModuleDeclaration4.ts
TypeScript
module M { declare module M1 { module M2 { } } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserModuleDeclaration6.ts
TypeScript
module number { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserModuleDeclaration7.ts
TypeScript
module number.a { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserModuleDeclaration8.ts
TypeScript
module a.number { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserModuleDeclaration9.ts
TypeScript
module a.number.b { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserNoASIOnCallAfterFunctionExpression1.ts
TypeScript
var x = function () { } (<any>window).foo;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserNotHexLiteral1.ts
TypeScript
var x = {e0: 'cat', x0: 'dog'}; console.info (x.x0); // tsc dies on this next line with "bug.ts (5,16): Expected ')'" // tsc seems to be parsing the e0 as a hex constant. console.info (x.e0);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserNotRegex2.ts
TypeScript
declare const A: any; declare const B: any; declare const C: any; const x = (A / 2); B( C(), () => { }, () => { } );
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserObjectCreation1.ts
TypeScript
var autoToken: number[] = new Array<number[]>(1);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserObjectCreation2.ts
TypeScript
new new Foo()()
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserObjectCreationArrayLiteral2.ts
TypeScript
new Foo[1];
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserObjectCreationArrayLiteral4.ts
TypeScript
new Foo[1]();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserObjectLiterals1.ts
TypeScript
var v = { a: 1, b: 2 };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserObjectType1.ts
TypeScript
var v: {};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserObjectType2.ts
TypeScript
var v: { x: number };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserObjectType3.ts
TypeScript
var v: { x; y };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserObjectType4.ts
TypeScript
var v: { x y };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserOptionalTypeMembers1.ts
TypeScript
interface PropertyDescriptor2 { configurable?: boolean; enumerable?: boolean; value?: any; writable?: boolean; get?(): any; set?(v: any): void; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserOverloadOnConstants1.ts
TypeScript
interface Document { createElement(tagName: string): HTMLElement; createElement(tagName: 'canvas'): HTMLCanvasElement; createElement(tagName: 'div'): HTMLDivElement; createElement(tagName: 'span'): HTMLSpanElement; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserParameterList12.ts
TypeScript
function F(a,) { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserParameterList13.ts
TypeScript
interface I { new (public x); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserParameterList14.ts
TypeScript
declare class C { foo(a = 1): void; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserParameterList15.ts
TypeScript
function foo(a = 4); function foo(a, b) {}
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserParameterList16.ts
TypeScript
class C { foo(a = 4); foo(a, b) { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserParameterList17.ts
TypeScript
class C { constructor(a = 4); constructor(a, b) { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserParameterList4.ts
TypeScript
function F(public A) { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserParameterList5.ts
TypeScript
function A(): (public B) => C { }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserParameterList6.ts
TypeScript
class C { constructor(C: (public A) => any) { } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserParameterList7.ts
TypeScript
class C1 { constructor(public p1:string); // ERROR constructor(private p2:number); // ERROR constructor(public p3:any) {} // OK }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserParameterList8.ts
TypeScript
declare class C2 { constructor(public p1:string); // ERROR constructor(private p2:number); // ERROR constructor(public p3:any); // ERROR }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserParenthesizedVariableAndFunctionInTernary.ts
TypeScript
let a: any; const c = true ? (a) : function() {};
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserParenthesizedVariableAndParenthesizedFunctionInTernary.ts
TypeScript
let a: any; const c = true ? (a) : (function() {}); const d = true ? (a) : ((function() {}));
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserPropertySignature1.ts
TypeScript
interface I { A; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserPropertySignature10.ts
TypeScript
interface I { 1?; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserPropertySignature11.ts
TypeScript
interface I { 2:any; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserPropertySignature12.ts
TypeScript
interface I { 3?:any; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserPropertySignature2.ts
TypeScript
interface I { B?; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserPropertySignature3.ts
TypeScript
interface I { C:any; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserPropertySignature4.ts
TypeScript
interface I { D?:any; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserPropertySignature5.ts
TypeScript
interface I { "E"; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserPropertySignature6.ts
TypeScript
interface I { "F"?; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserPropertySignature7.ts
TypeScript
interface I { "G":any; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserPropertySignature8.ts
TypeScript
interface I { "H"?:any; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserPropertySignature9.ts
TypeScript
interface I { 0; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRealSource1.ts
TypeScript
// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. ///<reference path='typescript.ts' /> module TypeScript { export module CompilerDiagnostics { export var debug = false; export interface IDiagnosticWriter { Alert(output: string): void; } export var diagnosticWriter: IDiagnosticWriter = null; export var analysisPass: number = 0; export function Alert(output: string) { if (diagnosticWriter) { diagnosticWriter.Alert(output); } } export function debugPrint(s: string) { if (debug) { Alert(s); } } export function assert(condition: boolean, s: string) { if (debug) { if (!condition) { Alert(s); } } } } export interface ILogger { information(): boolean; debug(): boolean; warning(): boolean; error(): boolean; fatal(): boolean; log(s: string): void; } export class NullLogger implements ILogger { public information(): boolean { return false; } public debug(): boolean { return false; } public warning(): boolean { return false; } public error(): boolean { return false; } public fatal(): boolean { return false; } public log(s: string): void { } } export class LoggerAdapter implements ILogger { private _information: boolean; private _debug: boolean; private _warning: boolean; private _error: boolean; private _fatal: boolean; constructor (public logger: ILogger) { this._information = this.logger.information(); this._debug = this.logger.debug(); this._warning = this.logger.warning(); this._error = this.logger.error(); this._fatal = this.logger.fatal(); } public information(): boolean { return this._information; } public debug(): boolean { return this._debug; } public warning(): boolean { return this._warning; } public error(): boolean { return this._error; } public fatal(): boolean { return this._fatal; } public log(s: string): void { this.logger.log(s); } } export class BufferedLogger implements ILogger { public logContents = []; public information(): boolean { return false; } public debug(): boolean { return false; } public warning(): boolean { return false; } public error(): boolean { return false; } public fatal(): boolean { return false; } public log(s: string): void { this.logContents.push(s); } } export function timeFunction(logger: ILogger, funcDescription: string, func: () =>any): any { var start = +new Date(); var result = func(); var end = +new Date(); logger.log(funcDescription + " completed in " + (end - start) + " msec"); return result; } export function stringToLiteral(value: string, length: number): string { var result = ""; var addChar = (index: number) => { var ch = value.charCodeAt(index); switch (ch) { case 0x09: // tab result += "\\t"; break; case 0x0a: // line feed result += "\\n"; break; case 0x0b: // vertical tab result += "\\v"; break; case 0x0c: // form feed result += "\\f"; break; case 0x0d: // carriage return result += "\\r"; break; case 0x22: // double quote result += "\\\""; break; case 0x27: // single quote result += "\\\'"; break; case 0x5c: // Backslash result += "\\"; break; default: result += value.charAt(index); } } var tooLong = (value.length > length); if (tooLong) { var mid = length >> 1; for (var i = 0; i < mid; i++) addChar(i); result += "(...)"; for (var i = value.length - mid; i < value.length; i++) addChar(i); } else { length = value.length; for (var i = 0; i < length; i++) addChar(i); } return result; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRealSource12.ts
TypeScript
// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. ///<reference path='typescript.ts' /> module TypeScript { export interface IAstWalker { walk(ast: AST, parent: AST): AST; options: AstWalkOptions; state: any; // user state object } export class AstWalkOptions { public goChildren = true; public goNextSibling = true; public reverseSiblings = false; // visit siblings in reverse execution order public stopWalk(stop:boolean = true) { this.goChildren = !stop; this.goNextSibling = !stop; } } export interface IAstWalkCallback { (ast: AST, parent: AST, walker: IAstWalker): AST; } export interface IAstWalkChildren { (preAst: AST, parent: AST, walker: IAstWalker): void; } class AstWalker implements IAstWalker { constructor ( private childrenWalkers: IAstWalkChildren[], private pre: IAstWalkCallback, private post: IAstWalkCallback, public options: AstWalkOptions, public state: any) { } public walk(ast: AST, parent: AST): AST { var preAst = this.pre(ast, parent, this); if (preAst === undefined) { preAst = ast; } if (this.options.goChildren) { var svGoSib = this.options.goNextSibling; this.options.goNextSibling = true; // Call the "walkChildren" function corresponding to "nodeType". this.childrenWalkers[ast.nodeType](ast, parent, this); this.options.goNextSibling = svGoSib; } else { // no go only applies to children of node issuing it this.options.goChildren = true; } if (this.post) { var postAst = this.post(preAst, parent, this); if (postAst === undefined) { postAst = preAst; } return postAst; } else { return preAst; } } } export class AstWalkerFactory { private childrenWalkers: IAstWalkChildren[] = []; constructor () { this.initChildrenWalkers(); } public walk(ast: AST, pre: IAstWalkCallback, post?: IAstWalkCallback, options?: AstWalkOptions, state?: any): AST { return this.getWalker(pre, post, options, state).walk(ast, null) } public getWalker(pre: IAstWalkCallback, post?: IAstWalkCallback, options?: AstWalkOptions, state?: any): IAstWalker { return this.getSlowWalker(pre, post, options, state); } private getSlowWalker(pre: IAstWalkCallback, post?: IAstWalkCallback, options?: AstWalkOptions, state?: any): IAstWalker { if (!options) { options = new AstWalkOptions(); } return new AstWalker(this.childrenWalkers, pre, post, options, state); } private initChildrenWalkers(): void { this.childrenWalkers[NodeType.None] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.Empty] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.EmptyExpr] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.True] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.False] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.This] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.Super] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.QString] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.Regex] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.Null] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.ArrayLit] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.ObjectLit] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.Void] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.Comma] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Pos] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.Neg] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.Delete] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.Await] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.In] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Dot] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.From] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Is] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.InstOf] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Typeof] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.NumberLit] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.Name] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.TypeRef] = ChildrenWalkers.walkTypeReferenceChildren; this.childrenWalkers[NodeType.Index] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Call] = ChildrenWalkers.walkCallExpressionChildren; this.childrenWalkers[NodeType.New] = ChildrenWalkers.walkCallExpressionChildren; this.childrenWalkers[NodeType.Asg] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.AsgAdd] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.AsgSub] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.AsgDiv] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.AsgMul] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.AsgMod] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.AsgAnd] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.AsgXor] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.AsgOr] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.AsgLsh] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.AsgRsh] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.AsgRs2] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.ConditionalExpression] = ChildrenWalkers.walkTrinaryExpressionChildren; this.childrenWalkers[NodeType.LogOr] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.LogAnd] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Or] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Xor] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.And] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Eq] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Ne] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Eqv] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.NEqv] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Lt] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Le] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Gt] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Ge] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Add] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Sub] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Mul] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Div] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Mod] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Lsh] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Rsh] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Rs2] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.Not] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.LogNot] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.IncPre] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.DecPre] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.IncPost] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.DecPost] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.TypeAssertion] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.FuncDecl] = ChildrenWalkers.walkFuncDeclChildren; this.childrenWalkers[NodeType.Member] = ChildrenWalkers.walkBinaryExpressionChildren; this.childrenWalkers[NodeType.VarDecl] = ChildrenWalkers.walkBoundDeclChildren; this.childrenWalkers[NodeType.ArgDecl] = ChildrenWalkers.walkBoundDeclChildren; this.childrenWalkers[NodeType.Return] = ChildrenWalkers.walkReturnStatementChildren; this.childrenWalkers[NodeType.Break] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.Continue] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.Throw] = ChildrenWalkers.walkUnaryExpressionChildren; this.childrenWalkers[NodeType.For] = ChildrenWalkers.walkForStatementChildren; this.childrenWalkers[NodeType.ForIn] = ChildrenWalkers.walkForInStatementChildren; this.childrenWalkers[NodeType.If] = ChildrenWalkers.walkIfStatementChildren; this.childrenWalkers[NodeType.While] = ChildrenWalkers.walkWhileStatementChildren; this.childrenWalkers[NodeType.DoWhile] = ChildrenWalkers.walkDoWhileStatementChildren; this.childrenWalkers[NodeType.Block] = ChildrenWalkers.walkBlockChildren; this.childrenWalkers[NodeType.Case] = ChildrenWalkers.walkCaseStatementChildren; this.childrenWalkers[NodeType.Switch] = ChildrenWalkers.walkSwitchStatementChildren; this.childrenWalkers[NodeType.Try] = ChildrenWalkers.walkTryChildren; this.childrenWalkers[NodeType.TryCatch] = ChildrenWalkers.walkTryCatchChildren; this.childrenWalkers[NodeType.TryFinally] = ChildrenWalkers.walkTryFinallyChildren; this.childrenWalkers[NodeType.Finally] = ChildrenWalkers.walkFinallyChildren; this.childrenWalkers[NodeType.Catch] = ChildrenWalkers.walkCatchChildren; this.childrenWalkers[NodeType.List] = ChildrenWalkers.walkListChildren; this.childrenWalkers[NodeType.Script] = ChildrenWalkers.walkScriptChildren; this.childrenWalkers[NodeType.ClassDeclaration] = ChildrenWalkers.walkClassDeclChildren; this.childrenWalkers[NodeType.InterfaceDeclaration] = ChildrenWalkers.walkTypeDeclChildren; this.childrenWalkers[NodeType.ModuleDeclaration] = ChildrenWalkers.walkModuleDeclChildren; this.childrenWalkers[NodeType.ImportDeclaration] = ChildrenWalkers.walkImportDeclChildren; this.childrenWalkers[NodeType.With] = ChildrenWalkers.walkWithStatementChildren; this.childrenWalkers[NodeType.Label] = ChildrenWalkers.walkLabelChildren; this.childrenWalkers[NodeType.LabeledStatement] = ChildrenWalkers.walkLabeledStatementChildren; this.childrenWalkers[NodeType.EBStart] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.GotoEB] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.EndCode] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.Error] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.Comment] = ChildrenWalkers.walkNone; this.childrenWalkers[NodeType.Debugger] = ChildrenWalkers.walkNone; // Verify the code is up to date with the enum for (var e in (<any>NodeType)._map) { if ((<any>this.childrenWalkers)[e] === undefined) { throw new Error("initWalkers function is not up to date with enum content!"); } } } } var globalAstWalkerFactory: AstWalkerFactory; export function getAstWalkerFactory(): AstWalkerFactory { if (!globalAstWalkerFactory) { globalAstWalkerFactory = new AstWalkerFactory(); } return globalAstWalkerFactory; } module ChildrenWalkers { export function walkNone(preAst: ASTList, parent: AST, walker: IAstWalker): void { // Nothing to do } export function walkListChildren(preAst: ASTList, parent: AST, walker: IAstWalker): void { var len = preAst.members.length; if (walker.options.reverseSiblings) { for (var i = len - 1; i >= 0; i--) { if (walker.options.goNextSibling) { preAst.members[i] = walker.walk(preAst.members[i], preAst); } } } else { for (var i = 0; i < len; i++) { if (walker.options.goNextSibling) { preAst.members[i] = walker.walk(preAst.members[i], preAst); } } } } export function walkUnaryExpressionChildren(preAst: UnaryExpression, parent: AST, walker: IAstWalker): void { if (preAst.castTerm) { preAst.castTerm = walker.walk(preAst.castTerm, preAst); } if (preAst.operand) { preAst.operand = walker.walk(preAst.operand, preAst); } } export function walkBinaryExpressionChildren(preAst: BinaryExpression, parent: AST, walker: IAstWalker): void { if (walker.options.reverseSiblings) { if (preAst.operand2) { preAst.operand2 = walker.walk(preAst.operand2, preAst); } if ((preAst.operand1) && (walker.options.goNextSibling)) { preAst.operand1 = walker.walk(preAst.operand1, preAst); } } else { if (preAst.operand1) { preAst.operand1 = walker.walk(preAst.operand1, preAst); } if ((preAst.operand2) && (walker.options.goNextSibling)) { preAst.operand2 = walker.walk(preAst.operand2, preAst); } } } export function walkTypeReferenceChildren(preAst: TypeReference, parent: AST, walker: IAstWalker): void { if (preAst.term) { preAst.term = walker.walk(preAst.term, preAst); } } export function walkCallExpressionChildren(preAst: CallExpression, parent: AST, walker: IAstWalker): void { if (!walker.options.reverseSiblings) { preAst.target = walker.walk(preAst.target, preAst); } if (preAst.arguments && (walker.options.goNextSibling)) { preAst.arguments = <ASTList> walker.walk(preAst.arguments, preAst); } if ((walker.options.reverseSiblings) && (walker.options.goNextSibling)) { preAst.target = walker.walk(preAst.target, preAst); } } export function walkTrinaryExpressionChildren(preAst: ConditionalExpression, parent: AST, walker: IAstWalker): void { if (preAst.operand1) { preAst.operand1 = walker.walk(preAst.operand1, preAst); } if (preAst.operand2 && (walker.options.goNextSibling)) { preAst.operand2 = walker.walk(preAst.operand2, preAst); } if (preAst.operand3 && (walker.options.goNextSibling)) { preAst.operand3 = walker.walk(preAst.operand3, preAst); } } export function walkFuncDeclChildren(preAst: FuncDecl, parent: AST, walker: IAstWalker): void { if (preAst.name) { preAst.name = <Identifier>walker.walk(preAst.name, preAst); } if (preAst.arguments && (preAst.arguments.members.length > 0) && (walker.options.goNextSibling)) { preAst.arguments = <ASTList>walker.walk(preAst.arguments, preAst); } if (preAst.returnTypeAnnotation && (walker.options.goNextSibling)) { preAst.returnTypeAnnotation = walker.walk(preAst.returnTypeAnnotation, preAst); } if (preAst.bod && (preAst.bod.members.length > 0) && (walker.options.goNextSibling)) { preAst.bod = <ASTList>walker.walk(preAst.bod, preAst); } } export function walkBoundDeclChildren(preAst: BoundDecl, parent: AST, walker: IAstWalker): void { if (preAst.id) { preAst.id = <Identifier>walker.walk(preAst.id, preAst); } if (preAst.init) { preAst.init = walker.walk(preAst.init, preAst); } if ((preAst.typeExpr) && (walker.options.goNextSibling)) { preAst.typeExpr = walker.walk(preAst.typeExpr, preAst); } } export function walkReturnStatementChildren(preAst: ReturnStatement, parent: AST, walker: IAstWalker): void { if (preAst.returnExpression) { preAst.returnExpression = walker.walk(preAst.returnExpression, preAst); } } export function walkForStatementChildren(preAst: ForStatement, parent: AST, walker: IAstWalker): void { if (preAst.init) { preAst.init = walker.walk(preAst.init, preAst); } if (preAst.cond && walker.options.goNextSibling) { preAst.cond = walker.walk(preAst.cond, preAst); } if (preAst.incr && walker.options.goNextSibling) { preAst.incr = walker.walk(preAst.incr, preAst); } if (preAst.body && walker.options.goNextSibling) { preAst.body = walker.walk(preAst.body, preAst); } } export function walkForInStatementChildren(preAst: ForInStatement, parent: AST, walker: IAstWalker): void { preAst.lval = walker.walk(preAst.lval, preAst); if (walker.options.goNextSibling) { preAst.obj = walker.walk(preAst.obj, preAst); } if (preAst.body && (walker.options.goNextSibling)) { preAst.body = walker.walk(preAst.body, preAst); } } export function walkIfStatementChildren(preAst: IfStatement, parent: AST, walker: IAstWalker): void { preAst.cond = walker.walk(preAst.cond, preAst); if (preAst.thenBod && (walker.options.goNextSibling)) { preAst.thenBod = walker.walk(preAst.thenBod, preAst); } if (preAst.elseBod && (walker.options.goNextSibling)) { preAst.elseBod = walker.walk(preAst.elseBod, preAst); } } export function walkWhileStatementChildren(preAst: WhileStatement, parent: AST, walker: IAstWalker): void { preAst.cond = walker.walk(preAst.cond, preAst); if (preAst.body && (walker.options.goNextSibling)) { preAst.body = walker.walk(preAst.body, preAst); } } export function walkDoWhileStatementChildren(preAst: DoWhileStatement, parent: AST, walker: IAstWalker): void { preAst.cond = walker.walk(preAst.cond, preAst); if (preAst.body && (walker.options.goNextSibling)) { preAst.body = walker.walk(preAst.body, preAst); } } export function walkBlockChildren(preAst: Block, parent: AST, walker: IAstWalker): void { if (preAst.statements) { preAst.statements = <ASTList>walker.walk(preAst.statements, preAst); } } export function walkCaseStatementChildren(preAst: CaseStatement, parent: AST, walker: IAstWalker): void { if (preAst.expr) { preAst.expr = walker.walk(preAst.expr, preAst); } if (preAst.body && walker.options.goNextSibling) { preAst.body = <ASTList>walker.walk(preAst.body, preAst); } } export function walkSwitchStatementChildren(preAst: SwitchStatement, parent: AST, walker: IAstWalker): void { if (preAst.val) { preAst.val = walker.walk(preAst.val, preAst); } if ((preAst.caseList) && walker.options.goNextSibling) { preAst.caseList = <ASTList>walker.walk(preAst.caseList, preAst); } } export function walkTryChildren(preAst: Try, parent: AST, walker: IAstWalker): void { if (preAst.body) { preAst.body = walker.walk(preAst.body, preAst); } } export function walkTryCatchChildren(preAst: TryCatch, parent: AST, walker: IAstWalker): void { if (preAst.tryNode) { preAst.tryNode = <Try>walker.walk(preAst.tryNode, preAst); } if ((preAst.catchNode) && walker.options.goNextSibling) { preAst.catchNode = <Catch>walker.walk(preAst.catchNode, preAst); } } export function walkTryFinallyChildren(preAst: TryFinally, parent: AST, walker: IAstWalker): void { if (preAst.tryNode) { preAst.tryNode = walker.walk(preAst.tryNode, preAst); } if (preAst.finallyNode && walker.options.goNextSibling) { preAst.finallyNode = <Finally>walker.walk(preAst.finallyNode, preAst); } } export function walkFinallyChildren(preAst: Finally, parent: AST, walker: IAstWalker): void { if (preAst.body) { preAst.body = walker.walk(preAst.body, preAst); } } export function walkCatchChildren(preAst: Catch, parent: AST, walker: IAstWalker): void { if (preAst.param) { preAst.param = <VarDecl>walker.walk(preAst.param, preAst); } if ((preAst.body) && walker.options.goNextSibling) { preAst.body = walker.walk(preAst.body, preAst); } } export function walkRecordChildren(preAst: NamedDeclaration, parent: AST, walker: IAstWalker): void { preAst.name = <Identifier>walker.walk(preAst.name, preAst); if (walker.options.goNextSibling && preAst.members) { preAst.members = <ASTList>walker.walk(preAst.members, preAst); } } export function walkNamedTypeChildren(preAst: TypeDeclaration, parent: AST, walker: IAstWalker): void { walkRecordChildren(preAst, parent, walker); } export function walkClassDeclChildren(preAst: ClassDeclaration, parent: AST, walker: IAstWalker): void { walkNamedTypeChildren(preAst, parent, walker); if (walker.options.goNextSibling && preAst.extendsList) { preAst.extendsList = <ASTList>walker.walk(preAst.extendsList, preAst); } if (walker.options.goNextSibling && preAst.implementsList) { preAst.implementsList = <ASTList>walker.walk(preAst.implementsList, preAst); } } export function walkScriptChildren(preAst: Script, parent: AST, walker: IAstWalker): void { if (preAst.bod) { preAst.bod = <ASTList>walker.walk(preAst.bod, preAst); } } export function walkTypeDeclChildren(preAst: InterfaceDeclaration, parent: AST, walker: IAstWalker): void { walkNamedTypeChildren(preAst, parent, walker); // walked arguments as part of members if (walker.options.goNextSibling && preAst.extendsList) { preAst.extendsList = <ASTList>walker.walk(preAst.extendsList, preAst); } if (walker.options.goNextSibling && preAst.implementsList) { preAst.implementsList = <ASTList>walker.walk(preAst.implementsList, preAst); } } export function walkModuleDeclChildren(preAst: ModuleDeclaration, parent: AST, walker: IAstWalker): void { walkRecordChildren(preAst, parent, walker); } export function walkImportDeclChildren(preAst: ImportDeclaration, parent: AST, walker: IAstWalker): void { if (preAst.id) { preAst.id = <Identifier>walker.walk(preAst.id, preAst); } if (preAst.alias) { preAst.alias = walker.walk(preAst.alias, preAst); } } export function walkWithStatementChildren(preAst: WithStatement, parent: AST, walker: IAstWalker): void { if (preAst.expr) { preAst.expr = walker.walk(preAst.expr, preAst); } if (preAst.body && walker.options.goNextSibling) { preAst.body = walker.walk(preAst.body, preAst); } } export function walkLabelChildren(preAst: Label, parent: AST, walker: IAstWalker): void { //TODO: Walk "id"? } export function walkLabeledStatementChildren(preAst: LabeledStatement, parent: AST, walker: IAstWalker): void { preAst.labels = <ASTList>walker.walk(preAst.labels, preAst); if (walker.options.goNextSibling) { preAst.stmt = walker.walk(preAst.stmt, preAst); } } } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRealSource13.ts
TypeScript
// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. ///<reference path='typescript.ts' /> module TypeScript.AstWalkerWithDetailCallback { export interface AstWalkerDetailCallback { EmptyCallback? (pre, ast: AST): boolean; EmptyExprCallback? (pre, ast: AST): boolean; TrueCallback? (pre, ast: AST): boolean; FalseCallback? (pre, ast: AST): boolean; ThisCallback? (pre, ast: AST): boolean; SuperCallback? (pre, ast: AST): boolean; QStringCallback? (pre, ast: AST): boolean; RegexCallback? (pre, ast: AST): boolean; NullCallback? (pre, ast: AST): boolean; ArrayLitCallback? (pre, ast: AST): boolean; ObjectLitCallback? (pre, ast: AST): boolean; VoidCallback? (pre, ast: AST): boolean; CommaCallback? (pre, ast: AST): boolean; PosCallback? (pre, ast: AST): boolean; NegCallback? (pre, ast: AST): boolean; DeleteCallback? (pre, ast: AST): boolean; AwaitCallback? (pre, ast: AST): boolean; InCallback? (pre, ast: AST): boolean; DotCallback? (pre, ast: AST): boolean; FromCallback? (pre, ast: AST): boolean; IsCallback? (pre, ast: AST): boolean; InstOfCallback? (pre, ast: AST): boolean; TypeofCallback? (pre, ast: AST): boolean; NumberLitCallback? (pre, ast: AST): boolean; NameCallback? (pre, identifierAst: Identifier): boolean; TypeRefCallback? (pre, ast: AST): boolean; IndexCallback? (pre, ast: AST): boolean; CallCallback? (pre, ast: AST): boolean; NewCallback? (pre, ast: AST): boolean; AsgCallback? (pre, ast: AST): boolean; AsgAddCallback? (pre, ast: AST): boolean; AsgSubCallback? (pre, ast: AST): boolean; AsgDivCallback? (pre, ast: AST): boolean; AsgMulCallback? (pre, ast: AST): boolean; AsgModCallback? (pre, ast: AST): boolean; AsgAndCallback? (pre, ast: AST): boolean; AsgXorCallback? (pre, ast: AST): boolean; AsgOrCallback? (pre, ast: AST): boolean; AsgLshCallback? (pre, ast: AST): boolean; AsgRshCallback? (pre, ast: AST): boolean; AsgRs2Callback? (pre, ast: AST): boolean; QMarkCallback? (pre, ast: AST): boolean; LogOrCallback? (pre, ast: AST): boolean; LogAndCallback? (pre, ast: AST): boolean; OrCallback? (pre, ast: AST): boolean; XorCallback? (pre, ast: AST): boolean; AndCallback? (pre, ast: AST): boolean; EqCallback? (pre, ast: AST): boolean; NeCallback? (pre, ast: AST): boolean; EqvCallback? (pre, ast: AST): boolean; NEqvCallback? (pre, ast: AST): boolean; LtCallback? (pre, ast: AST): boolean; LeCallback? (pre, ast: AST): boolean; GtCallback? (pre, ast: AST): boolean; GeCallback? (pre, ast: AST): boolean; AddCallback? (pre, ast: AST): boolean; SubCallback? (pre, ast: AST): boolean; MulCallback? (pre, ast: AST): boolean; DivCallback? (pre, ast: AST): boolean; ModCallback? (pre, ast: AST): boolean; LshCallback? (pre, ast: AST): boolean; RshCallback? (pre, ast: AST): boolean; Rs2Callback? (pre, ast: AST): boolean; NotCallback? (pre, ast: AST): boolean; LogNotCallback? (pre, ast: AST): boolean; IncPreCallback? (pre, ast: AST): boolean; DecPreCallback? (pre, ast: AST): boolean; IncPostCallback? (pre, ast: AST): boolean; DecPostCallback? (pre, ast: AST): boolean; TypeAssertionCallback? (pre, ast: AST): boolean; FuncDeclCallback? (pre, funcDecl: FuncDecl): boolean; MemberCallback? (pre, ast: AST): boolean; VarDeclCallback? (pre, varDecl: VarDecl): boolean; ArgDeclCallback? (pre, ast: AST): boolean; ReturnCallback? (pre, ast: AST): boolean; BreakCallback? (pre, ast: AST): boolean; ContinueCallback? (pre, ast: AST): boolean; ThrowCallback? (pre, ast: AST): boolean; ForCallback? (pre, ast: AST): boolean; ForInCallback? (pre, ast: AST): boolean; IfCallback? (pre, ast: AST): boolean; WhileCallback? (pre, ast: AST): boolean; DoWhileCallback? (pre, ast: AST): boolean; BlockCallback? (pre, block: Block): boolean; CaseCallback? (pre, ast: AST): boolean; SwitchCallback? (pre, ast: AST): boolean; TryCallback? (pre, ast: AST): boolean; TryCatchCallback? (pre, ast: AST): boolean; TryFinallyCallback? (pre, ast: AST): boolean; FinallyCallback? (pre, ast: AST): boolean; CatchCallback? (pre, ast: AST): boolean; ListCallback? (pre, astList: ASTList): boolean; ScriptCallback? (pre, script: Script): boolean; ClassDeclarationCallback? (pre, ast: AST): boolean; InterfaceDeclarationCallback? (pre, interfaceDecl: InterfaceDeclaration): boolean; ModuleDeclarationCallback? (pre, moduleDecl: ModuleDeclaration): boolean; ImportDeclarationCallback? (pre, ast: AST): boolean; WithCallback? (pre, ast: AST): boolean; LabelCallback? (pre, labelAST: AST): boolean; LabeledStatementCallback? (pre, ast: AST): boolean; EBStartCallback? (pre, ast: AST): boolean; GotoEBCallback? (pre, ast: AST): boolean; EndCodeCallback? (pre, ast: AST): boolean; ErrorCallback? (pre, ast: AST): boolean; CommentCallback? (pre, ast: AST): boolean; DebuggerCallback? (pre, ast: AST): boolean; DefaultCallback? (pre, ast: AST): boolean; } export function walk(script: Script, callback: AstWalkerDetailCallback): void { var pre = (cur: AST, parent: AST) => { walker.options.goChildren = AstWalkerCallback(true, cur, callback); return cur; } var post = (cur: AST, parent: AST) => { AstWalkerCallback(false, cur, callback); return cur; } var walker = TypeScript.getAstWalkerFactory().getWalker(pre, post); walker.walk(script, null); } function AstWalkerCallback(pre: boolean, ast: AST, callback: AstWalkerDetailCallback): boolean { // See if the Callback needs to be handled using specific one or default one var nodeType = ast.nodeType; var callbackString = (<any>NodeType)._map[nodeType] + "Callback"; if (callback[callbackString]) { return callback[callbackString](pre, ast); } if (callback.DefaultCallback) { return callback.DefaultCallback(pre, ast); } return true; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRealSource14.ts
TypeScript
// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. ///<reference path='typescript.ts' /> module TypeScript { export function lastOf(items: any[]): any { return (items === null || items.length === 0) ? null : items[items.length - 1]; } export function max(a: number, b: number): number { return a >= b ? a : b; } export function min(a: number, b: number): number { return a <= b ? a : b; } // // Helper class representing a path from a root ast node to a (grand)child ast node. // This is helpful as our tree don't have parents. // export class AstPath { public asts: TypeScript.AST[] = []; public top: number = -1; static reverseIndexOf(items: any[], index: number): any { return (items === null || items.length <= index) ? null : items[items.length - index - 1]; } public clone(): AstPath { var clone = new AstPath(); clone.asts = this.asts.map((value) => { return value; }); clone.top = this.top; return clone; } public pop(): TypeScript.AST { var head = this.ast(); this.up(); while (this.asts.length > this.count()) { this.asts.pop(); } return head; } public push(ast: TypeScript.AST) { while (this.asts.length > this.count()) { this.asts.pop(); } this.top = this.asts.length; this.asts.push(ast); } public up() { if (this.top <= -1) throw new Error("Invalid call to 'up'"); this.top--; } public down() { if (this.top == this.ast.length - 1) throw new Error("Invalid call to 'down'"); this.top++; } public nodeType(): TypeScript.NodeType { if (this.ast() == null) return TypeScript.NodeType.None; return this.ast().nodeType; } public ast() { return <TypeScript.AST>AstPath.reverseIndexOf(this.asts, this.asts.length - (this.top + 1)); } public parent() { return <TypeScript.AST>AstPath.reverseIndexOf(this.asts, this.asts.length - this.top); } public count() { return this.top + 1; } public get(index: number): TypeScript.AST { return this.asts[index]; } public isNameOfClass(): boolean { if (this.ast() === null || this.parent() === null) return false; return (this.ast().nodeType === TypeScript.NodeType.Name) && (this.parent().nodeType === TypeScript.NodeType.ClassDeclaration) && ((<TypeScript.InterfaceDeclaration>this.parent()).name === this.ast()); } public isNameOfInterface(): boolean { if (this.ast() === null || this.parent() === null) return false; return (this.ast().nodeType === TypeScript.NodeType.Name) && (this.parent().nodeType === TypeScript.NodeType.InterfaceDeclaration) && ((<TypeScript.InterfaceDeclaration>this.parent()).name === this.ast()); } public isNameOfArgument(): boolean { if (this.ast() === null || this.parent() === null) return false; return (this.ast().nodeType === TypeScript.NodeType.Name) && (this.parent().nodeType === TypeScript.NodeType.ArgDecl) && ((<TypeScript.ArgDecl>this.parent()).id === this.ast()); } public isNameOfVariable(): boolean { if (this.ast() === null || this.parent() === null) return false; return (this.ast().nodeType === TypeScript.NodeType.Name) && (this.parent().nodeType === TypeScript.NodeType.VarDecl) && ((<TypeScript.VarDecl>this.parent()).id === this.ast()); } public isNameOfModule(): boolean { if (this.ast() === null || this.parent() === null) return false; return (this.ast().nodeType === TypeScript.NodeType.Name) && (this.parent().nodeType === TypeScript.NodeType.ModuleDeclaration) && ((<TypeScript.ModuleDeclaration>this.parent()).name === this.ast()); } public isNameOfFunction(): boolean { if (this.ast() === null || this.parent() === null) return false; return (this.ast().nodeType === TypeScript.NodeType.Name) && (this.parent().nodeType === TypeScript.NodeType.FuncDecl) && ((<TypeScript.FuncDecl>this.parent()).name === this.ast()); } public isChildOfScript(): boolean { var ast = lastOf(this.asts); return this.count() >= 3 && this.asts[this.top] === ast && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && this.asts[this.top - 2].nodeType === TypeScript.NodeType.Script; } public isChildOfModule(): boolean { var ast = lastOf(this.asts); return this.count() >= 3 && this.asts[this.top] === ast && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && this.asts[this.top - 2].nodeType === TypeScript.NodeType.ModuleDeclaration; } public isChildOfClass(): boolean { var ast = lastOf(this.asts); return this.count() >= 3 && this.asts[this.top] === ast && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && this.asts[this.top - 2].nodeType === TypeScript.NodeType.ClassDeclaration; } public isArgumentOfClassConstructor(): boolean { var ast = lastOf(this.asts); return this.count() >= 5 && this.asts[this.top] === ast && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && this.asts[this.top - 2].nodeType === TypeScript.NodeType.FuncDecl && this.asts[this.top - 3].nodeType === TypeScript.NodeType.List && this.asts[this.top - 4].nodeType === TypeScript.NodeType.ClassDeclaration && ((<TypeScript.FuncDecl>this.asts[this.top - 2]).isConstructor) && ((<TypeScript.FuncDecl>this.asts[this.top - 2]).arguments === this.asts[this.top - 1]) && ((<TypeScript.ClassDeclaration>this.asts[this.top - 4]).constructorDecl === this.asts[this.top - 2]); } public isChildOfInterface(): boolean { var ast = lastOf(this.asts); return this.count() >= 3 && this.asts[this.top] === ast && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && this.asts[this.top - 2].nodeType === TypeScript.NodeType.InterfaceDeclaration; } public isTopLevelImplicitModule() { return this.count() >= 1 && this.asts[this.top].nodeType === TypeScript.NodeType.ModuleDeclaration && TypeScript.hasFlag((<TypeScript.ModuleDeclaration>this.asts[this.top]).modFlags, TypeScript.ModuleFlags.IsWholeFile); } public isBodyOfTopLevelImplicitModule() { return this.count() >= 2 && this.asts[this.top - 0].nodeType === TypeScript.NodeType.List && this.asts[this.top - 1].nodeType === TypeScript.NodeType.ModuleDeclaration && (<TypeScript.ModuleDeclaration>this.asts[this.top - 1]).members == this.asts[this.top - 0] && TypeScript.hasFlag((<TypeScript.ModuleDeclaration>this.asts[this.top - 1]).modFlags, TypeScript.ModuleFlags.IsWholeFile); } public isBodyOfScript(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Script && (<TypeScript.Script>this.asts[this.top - 1]).bod == this.asts[this.top - 0]; } public isBodyOfSwitch(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Switch && (<TypeScript.SwitchStatement>this.asts[this.top - 1]).caseList == this.asts[this.top - 0]; } public isBodyOfModule(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.ModuleDeclaration && (<TypeScript.ModuleDeclaration>this.asts[this.top - 1]).members == this.asts[this.top - 0]; } public isBodyOfClass(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.ClassDeclaration && (<TypeScript.ClassDeclaration>this.asts[this.top - 1]).members == this.asts[this.top - 0]; } public isBodyOfFunction(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.FuncDecl && (<TypeScript.FuncDecl>this.asts[this.top - 1]).bod == this.asts[this.top - 0]; } public isBodyOfInterface(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.InterfaceDeclaration && (<TypeScript.InterfaceDeclaration>this.asts[this.top - 1]).members == this.asts[this.top - 0]; } public isBodyOfBlock(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Block && (<TypeScript.Block>this.asts[this.top - 1]).statements == this.asts[this.top - 0]; } public isBodyOfFor(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.For && (<TypeScript.ForStatement>this.asts[this.top - 1]).body == this.asts[this.top - 0]; } public isBodyOfCase(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Case && (<TypeScript.CaseStatement>this.asts[this.top - 1]).body == this.asts[this.top - 0]; } public isBodyOfTry(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Try && (<TypeScript.Try>this.asts[this.top - 1]).body == this.asts[this.top - 0]; } public isBodyOfCatch(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Catch && (<TypeScript.Catch>this.asts[this.top - 1]).body == this.asts[this.top - 0]; } public isBodyOfDoWhile(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.DoWhile && (<TypeScript.DoWhileStatement>this.asts[this.top - 1]).body == this.asts[this.top - 0]; } public isBodyOfWhile(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.While && (<TypeScript.WhileStatement>this.asts[this.top - 1]).body == this.asts[this.top - 0]; } public isBodyOfForIn(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.ForIn && (<TypeScript.ForInStatement>this.asts[this.top - 1]).body == this.asts[this.top - 0]; } public isBodyOfWith(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.With && (<TypeScript.WithStatement>this.asts[this.top - 1]).body == this.asts[this.top - 0]; } public isBodyOfFinally(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Finally && (<TypeScript.Finally>this.asts[this.top - 1]).body == this.asts[this.top - 0]; } public isCaseOfSwitch(): boolean { return this.count() >= 3 && this.asts[this.top - 2].nodeType === TypeScript.NodeType.Switch && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && (<TypeScript.SwitchStatement>this.asts[this.top - 2]).caseList == this.asts[this.top - 1]; } public isDefaultCaseOfSwitch(): boolean { return this.count() >= 3 && this.asts[this.top - 2].nodeType === TypeScript.NodeType.Switch && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && (<TypeScript.SwitchStatement>this.asts[this.top - 2]).caseList == this.asts[this.top - 1] && (<TypeScript.SwitchStatement>this.asts[this.top - 2]).defaultCase == this.asts[this.top - 0]; } public isListOfObjectLit(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.ObjectLit && this.asts[this.top - 0].nodeType === TypeScript.NodeType.List && (<TypeScript.UnaryExpression>this.asts[this.top - 1]).operand == this.asts[this.top - 0]; } public isBodyOfObjectLit(): boolean { return this.isListOfObjectLit(); } public isEmptyListOfObjectLit(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.ObjectLit && this.asts[this.top - 0].nodeType === TypeScript.NodeType.List && (<TypeScript.UnaryExpression>this.asts[this.top - 1]).operand == this.asts[this.top - 0] && (<TypeScript.ASTList>this.asts[this.top - 0]).members.length == 0; } public isMemberOfObjectLit(): boolean { return this.count() >= 3 && this.asts[this.top - 2].nodeType === TypeScript.NodeType.ObjectLit && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && this.asts[this.top - 0].nodeType === TypeScript.NodeType.Member && (<TypeScript.UnaryExpression>this.asts[this.top - 2]).operand == this.asts[this.top - 1]; } public isNameOfMemberOfObjectLit(): boolean { return this.count() >= 4 && this.asts[this.top - 3].nodeType === TypeScript.NodeType.ObjectLit && this.asts[this.top - 2].nodeType === TypeScript.NodeType.List && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Member && this.asts[this.top - 0].nodeType === TypeScript.NodeType.Name && (<TypeScript.UnaryExpression>this.asts[this.top - 3]).operand == this.asts[this.top - 2]; } public isListOfArrayLit(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.ArrayLit && this.asts[this.top - 0].nodeType === TypeScript.NodeType.List && (<TypeScript.UnaryExpression>this.asts[this.top - 1]).operand == this.asts[this.top - 0]; } public isTargetOfMember(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Member && (<TypeScript.BinaryExpression>this.asts[this.top - 1]).operand1 === this.asts[this.top - 0]; } public isMemberOfMember(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Member && (<TypeScript.BinaryExpression>this.asts[this.top - 1]).operand2 === this.asts[this.top - 0]; } public isItemOfList(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List; //(<Tools.ASTList>this.asts[this.top - 1]).operand2 === this.asts[this.top - 0]; } public isThenOfIf(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.If && (<TypeScript.IfStatement>this.asts[this.top - 1]).thenBod == this.asts[this.top - 0]; } public isElseOfIf(): boolean { return this.count() >= 2 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.If && (<TypeScript.IfStatement>this.asts[this.top - 1]).elseBod == this.asts[this.top - 0]; } public isBodyOfDefaultCase(): boolean { return this.isBodyOfCase(); } public isSingleStatementList(): boolean { return this.count() >= 1 && this.asts[this.top].nodeType === TypeScript.NodeType.List && (<TypeScript.ASTList>this.asts[this.top]).members.length === 1; } public isArgumentListOfFunction(): boolean { return this.count() >= 2 && this.asts[this.top - 0].nodeType === TypeScript.NodeType.List && this.asts[this.top - 1].nodeType === TypeScript.NodeType.FuncDecl && (<TypeScript.FuncDecl>this.asts[this.top - 1]).arguments === this.asts[this.top - 0]; } public isArgumentOfFunction(): boolean { return this.count() >= 3 && this.asts[this.top - 1].nodeType === TypeScript.NodeType.List && this.asts[this.top - 2].nodeType === TypeScript.NodeType.FuncDecl && (<TypeScript.FuncDecl>this.asts[this.top - 2]).arguments === this.asts[this.top - 1]; } public isArgumentListOfCall(): boolean { return this.count() >= 2 && this.asts[this.top - 0].nodeType === TypeScript.NodeType.List && this.asts[this.top - 1].nodeType === TypeScript.NodeType.Call && (<TypeScript.CallExpression>this.asts[this.top - 1]).arguments === this.asts[this.top - 0]; } public isArgumentListOfNew(): boolean { return this.count() >= 2 && this.asts[this.top - 0].nodeType === TypeScript.NodeType.List && this.asts[this.top - 1].nodeType === TypeScript.NodeType.New && (<TypeScript.CallExpression>this.asts[this.top - 1]).arguments === this.asts[this.top - 0]; } public isSynthesizedBlock(): boolean { return this.count() >= 1 && this.asts[this.top - 0].nodeType === TypeScript.NodeType.Block && (<TypeScript.Block>this.asts[this.top - 0]).isStatementBlock === false; } } export function isValidAstNode(ast: TypeScript.ASTSpan): boolean { if (ast === null) return false; if (ast.minChar === -1 || ast.limChar === -1) return false; return true; } export class AstPathContext { public path = new TypeScript.AstPath(); } export enum GetAstPathOptions { Default = 0, EdgeInclusive = 1, //We need this options dealing with an AST coming from an incomplete AST. For example: // class foo { // r // If we ask for the AST at the position after the "r" character, we won't see we are // inside a comment, because the "class" AST node has a limChar corresponding to the position of // the "{" character, meaning we don't traverse the tree down to the stmt list of the class, meaning // we don't find the "precomment" attached to the errorneous empty stmt. //TODO: It would be nice to be able to get rid of this. DontPruneSearchBasedOnPosition = 1 << 1, } /// /// Return the stack of AST nodes containing "position" /// export function getAstPathToPosition(script: TypeScript.AST, pos: number, options = GetAstPathOptions.Default): TypeScript.AstPath { var lookInComments = (comments: TypeScript.Comment[]) => { if (comments && comments.length > 0) { for (var i = 0; i < comments.length; i++) { var minChar = comments[i].minChar; var limChar = comments[i].limChar; if (!comments[i].isBlockComment) { limChar++; // For single line comments, include 1 more character (for the newline) } if (pos >= minChar && pos < limChar) { ctx.path.push(comments[i]); } } } } var pre = function (cur: TypeScript.AST, parent: TypeScript.AST, walker: IAstWalker) { if (isValidAstNode(cur)) { // Add "cur" to the stack if it contains our position // For "identifier" nodes, we need a special case: A position equal to "limChar" is // valid, since the position corresponds to a caret position (in between characters) // For example: // bar // 0123 // If "position == 3", the caret is at the "right" of the "r" character, which should be considered valid var inclusive = hasFlag(options, GetAstPathOptions.EdgeInclusive) || cur.nodeType === TypeScript.NodeType.Name || pos === script.limChar; // Special "EOF" case var minChar = cur.minChar; var limChar = cur.limChar + (inclusive ? 1 : 0) if (pos >= minChar && pos < limChar) { // TODO: Since AST is sometimes not correct wrt to position, only add "cur" if it's better // than top of the stack. var previous = ctx.path.ast(); if (previous == null || (cur.minChar >= previous.minChar && cur.limChar <= previous.limChar)) { ctx.path.push(cur); } else { //logger.log("TODO: Ignoring node because minChar, limChar not better than previous node in stack"); } } // The AST walker skips comments, but we might be in one, so check the pre/post comments for this node manually if (pos < limChar) { lookInComments(cur.preComments); } if (pos >= minChar) { lookInComments(cur.postComments); } if (!hasFlag(options, GetAstPathOptions.DontPruneSearchBasedOnPosition)) { // Don't go further down the tree if pos is outside of [minChar, limChar] walker.options.goChildren = (minChar <= pos && pos <= limChar); } } return cur; } var ctx = new AstPathContext(); TypeScript.getAstWalkerFactory().walk(script, pre, null, null, ctx); return ctx.path; } // // Find a source text offset that is safe for lexing tokens at the given position. // This is used when "position" might be inside a comment or string, etc. // export function getTokenizationOffset(script: TypeScript.Script, position: number): number { var bestOffset = 0; var pre = (cur: TypeScript.AST, parent: TypeScript.AST, walker: TypeScript.IAstWalker): TypeScript.AST => { if (TypeScript.isValidAstNode(cur)) { // Did we find a closer offset? if (cur.minChar <= position) { bestOffset = max(bestOffset, cur.minChar); } // Stop the walk if this node is not related to "minChar" if (cur.minChar > position || cur.limChar < bestOffset) { walker.options.goChildren = false; } } return cur; } TypeScript.getAstWalkerFactory().walk(script, pre); return bestOffset; } /// /// Simple function to Walk an AST using a simple callback function. /// export function walkAST(ast: TypeScript.AST, callback: (path: AstPath, walker: TypeScript.IAstWalker) => void ): void { var pre = function (cur: TypeScript.AST, parent: TypeScript.AST, walker: TypeScript.IAstWalker) { var path: TypeScript.AstPath = walker.state; path.push(cur); callback(path, walker); return cur; } var post = function (cur: TypeScript.AST, parent: TypeScript.AST, walker: TypeScript.IAstWalker) { var path: TypeScript.AstPath = walker.state; path.pop(); return cur; } var path = new AstPath(); TypeScript.getAstWalkerFactory().walk(ast, pre, post, null, path); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRealSource2.ts
TypeScript
// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. ///<reference path='typescript.ts' /> module TypeScript { export function hasFlag(val: number, flag: number) { return (val & flag) != 0; } export enum ErrorRecoverySet { None = 0, Comma = 1, // Comma SColon = 1 << 1, // SColon Asg = 1 << 2, // Asg BinOp = 1 << 3, // Lsh, Rsh, Rs2, Le, Ge, INSTANCEOF, EQ, NE, Eqv, NEqv, LogAnd, LogOr, AsgMul, AsgDiv // AsgMod, AsgAdd, AsgSub, AsgLsh, AsgRsh, AsgRs2, AsgAnd, AsgXor, AsgOr, QMark, Mult, Div, // Pct, GT, LT, And, Xor, Or RBrack = 1 << 4, // RBrack RCurly = 1 << 5, // RCurly RParen = 1 << 6, // RParen Dot = 1 << 7, // Dot Colon = 1 << 8, // Colon PrimType = 1 << 9, // number, string, boolean AddOp = 1 << 10, // Add, Sub LCurly = 1 << 11, // LCurly PreOp = 1 << 12, // Tilde, Bang, Inc, Dec RegExp = 1 << 13, // RegExp LParen = 1 << 14, // LParen LBrack = 1 << 15, // LBrack Scope = 1 << 16, // Scope In = 1 << 17, // IN SCase = 1 << 18, // CASE, DEFAULT Else = 1 << 19, // ELSE Catch = 1 << 20, // CATCH, FINALLY Var = 1 << 21, // Stmt = 1 << 22, // BREAK, RETURN, THROW, DEBUGGER, FOR, SWITCH, DO, IF, TRY, WITH While = 1 << 23, // WHILE ID = 1 << 24, // ID Prefix = 1 << 25, // VOID, DELETE, TYPEOF, AWAIT Literal = 1 << 26, // IntCon, FltCon, StrCon RLit = 1 << 27, // THIS, TRUE, FALSE, NULL Func = 1 << 28, // FUNCTION EOF = 1 << 29, // EOF // REVIEW: Name this something clearer. TypeScriptS = 1 << 30, // PROPERTY, PRIVATE, STATIC, INTERFACE, CLASS, MODULE, EXPORT, IMPORT ExprStart = SColon | AddOp | LCurly | PreOp | RegExp | LParen | LBrack | ID | Prefix | RLit | Func | Literal, StmtStart = ExprStart | SColon | Var | Stmt | While | TypeScriptS, Postfix = Dot | LParen | LBrack, } export enum AllowedElements { None = 0, ModuleDeclarations = 1 << 2, ClassDeclarations = 1 << 3, InterfaceDeclarations = 1 << 4, AmbientDeclarations = 1 << 10, Properties = 1 << 11, Global = ModuleDeclarations | ClassDeclarations | InterfaceDeclarations | AmbientDeclarations, QuickParse = Global | Properties, } export enum Modifiers { None = 0, Private = 1, Public = 1 << 1, Readonly = 1 << 2, Ambient = 1 << 3, Exported = 1 << 4, Getter = 1 << 5, Setter = 1 << 6, Static = 1 << 7, } export enum ASTFlags { None = 0, ExplicitSemicolon = 1, // statment terminated by an explicit semicolon AutomaticSemicolon = 1 << 1, // statment terminated by an automatic semicolon Writeable = 1 << 2, // node is lhs that can be modified Error = 1 << 3, // node has an error DotLHSPartial = 1 << 4, // node is the lhs of an incomplete dot expr at cursor DotLHS = 1 << 5, // node is the lhs of a dot expr IsStatement = 1 << 6, // node is a statement StrictMode = 1 << 7, // node is in the strict mode environment PossibleOptionalParameter = 1 << 8, ClassBaseConstructorCall = 1 << 9, OptionalName = 1 << 10, // REVIEW: This flag is to mark lambda nodes to note that the LParen of an expression has already been matched in the lambda header. // The flag is used to communicate this piece of information to the calling parseTerm, which intern will remove it. // Once we have a better way to associate information with nodes, this flag should not be used. SkipNextRParen = 1 << 11, } export enum DeclFlags { None = 0, Exported = 1, Private = 1 << 1, Public = 1 << 2, Ambient = 1 << 3, Static = 1 << 4, LocalStatic = 1 << 5, GetAccessor = 1 << 6, SetAccessor = 1 << 7, } export enum ModuleFlags { None = 0, Exported = 1, Private = 1 << 1, Public = 1 << 2, Ambient = 1 << 3, Static = 1 << 4, LocalStatic = 1 << 5, GetAccessor = 1 << 6, SetAccessor = 1 << 7, IsEnum = 1 << 8, ShouldEmitModuleDecl = 1 << 9, IsWholeFile = 1 << 10, IsDynamic = 1 << 11, MustCaptureThis = 1 << 12, } export enum SymbolFlags { None = 0, Exported = 1, Private = 1 << 1, Public = 1 << 2, Ambient = 1 << 3, Static = 1 << 4, LocalStatic = 1 << 5, GetAccessor = 1 << 6, SetAccessor = 1 << 7, Property = 1 << 8, Readonly = 1 << 9, ModuleMember = 1 << 10, InterfaceMember = 1 << 11, ClassMember = 1 << 12, BuiltIn = 1 << 13, TypeSetDuringScopeAssignment = 1 << 14, Constant = 1 << 15, Optional = 1 << 16, RecursivelyReferenced = 1 << 17, Bound = 1 << 18, CompilerGenerated = 1 << 19, } export enum VarFlags { None = 0, Exported = 1, Private = 1 << 1, Public = 1 << 2, Ambient = 1 << 3, Static = 1 << 4, LocalStatic = 1 << 5, GetAccessor = 1 << 6, SetAccessor = 1 << 7, AutoInit = 1 << 8, Property = 1 << 9, Readonly = 1 << 10, Class = 1 << 11, ClassProperty = 1 << 12, ClassBodyProperty = 1 << 13, ClassConstructorProperty = 1 << 14, ClassSuperMustBeFirstCallInConstructor = 1 << 15, Constant = 1 << 16, MustCaptureThis = 1 << 17, } export enum FncFlags { None = 0, Exported = 1, Private = 1 << 1, Public = 1 << 2, Ambient = 1 << 3, Static = 1 << 4, LocalStatic = 1 << 5, GetAccessor = 1 << 6, SetAccessor = 1 << 7, Definition = 1 << 8, Signature = 1 << 9, Method = 1 << 10, HasReturnExpression = 1 << 11, CallMember = 1 << 12, ConstructMember = 1 << 13, HasSelfReference = 1 << 14, IsFatArrowFunction = 1 << 15, IndexerMember = 1 << 16, IsFunctionExpression = 1 << 17, ClassMethod = 1 << 18, ClassPropertyMethodExported = 1 << 19, } export enum SignatureFlags { None = 0, IsIndexer = 1, IsStringIndexer = 1 << 1, IsNumberIndexer = 1 << 2, } export function ToDeclFlags(fncFlags: FncFlags) : DeclFlags; export function ToDeclFlags(varFlags: VarFlags) : DeclFlags; export function ToDeclFlags(symFlags: SymbolFlags): DeclFlags; export function ToDeclFlags(moduleFlags: ModuleFlags): DeclFlags; export function ToDeclFlags(fncOrVarOrSymbolOrModuleFlags: any) { return <DeclFlags>fncOrVarOrSymbolOrModuleFlags; } export enum TypeFlags { None = 0, HasImplementation = 1, HasSelfReference = 1 << 1, MergeResult = 1 << 2, IsEnum = 1 << 3, BuildingName = 1 << 4, HasBaseType = 1 << 5, HasBaseTypeOfObject = 1 << 6, IsClass = 1 << 7, } export enum TypeRelationshipFlags { SuccessfulComparison = 0, SourceIsNullTargetIsVoidOrUndefined = 1, RequiredPropertyIsMissing = 1 << 1, IncompatibleSignatures = 1 << 2, SourceSignatureHasTooManyParameters = 3, IncompatibleReturnTypes = 1 << 4, IncompatiblePropertyTypes = 1 << 5, IncompatibleParameterTypes = 1 << 6, } export enum CodeGenTarget { ES3 = 0, ES5 = 1, } export enum ModuleGenTarget { Synchronous = 0, Asynchronous = 1, Local = 1 << 1, } // Compiler defaults to generating ES5-compliant code for // - getters and setters export var codeGenTarget: CodeGenTarget = CodeGenTarget.ES3; export var moduleGenTarget: ModuleGenTarget = ModuleGenTarget.Synchronous; export var optimizeModuleCodeGen = true; export function flagsToString(e, flags: number): string { var builder = ""; for (var i = 1; i < (1 << 31) ; i = i << 1) { if ((flags & i) != 0) { for (var k in e) { if (e[k] == i) { if (builder.length > 0) { builder += "|"; } builder += k; break; } } } } return builder; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRealSource3.ts
TypeScript
// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. ///<reference path='typescript.ts' /> module TypeScript { // Note: Any addition to the NodeType should also be supported with addition to AstWalkerDetailCallback export enum NodeType { None, Empty, EmptyExpr, True, False, This, Super, QString, Regex, Null, ArrayLit, ObjectLit, Void, Comma, Pos, Neg, Delete, Await, In, Dot, From, Is, InstOf, Typeof, NumberLit, Name, TypeRef, Index, Call, New, Asg, AsgAdd, AsgSub, AsgDiv, AsgMul, AsgMod, AsgAnd, AsgXor, AsgOr, AsgLsh, AsgRsh, AsgRs2, ConditionalExpression, LogOr, LogAnd, Or, Xor, And, Eq, Ne, Eqv, NEqv, Lt, Le, Gt, Ge, Add, Sub, Mul, Div, Mod, Lsh, Rsh, Rs2, Not, LogNot, IncPre, DecPre, IncPost, DecPost, TypeAssertion, FuncDecl, Member, VarDecl, ArgDecl, Return, Break, Continue, Throw, For, ForIn, If, While, DoWhile, Block, Case, Switch, Try, TryCatch, TryFinally, Finally, Catch, List, Script, ClassDeclaration, InterfaceDeclaration, ModuleDeclaration, ImportDeclaration, With, Label, LabeledStatement, EBStart, GotoEB, EndCode, Error, Comment, Debugger, GeneralNode = FuncDecl, LastAsg = AsgRs2, } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRealSource5.ts
TypeScript
// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. ///<reference path='typescript.ts' /> module TypeScript { // TODO: refactor indent logic for use in emit export class PrintContext { public builder = ""; public indent1 = " "; public indentStrings: string[] = []; public indentAmt = 0; constructor (public outfile: ITextWriter, public parser: Parser) { } public increaseIndent() { this.indentAmt++; } public decreaseIndent() { this.indentAmt--; } public startLine() { if (this.builder.length > 0) { CompilerDiagnostics.Alert(this.builder); } var indentString = this.indentStrings[this.indentAmt]; if (indentString === undefined) { indentString = ""; for (var i = 0; i < this.indentAmt; i++) { indentString += this.indent1; } this.indentStrings[this.indentAmt] = indentString; } this.builder += indentString; } public write(s) { this.builder += s; } public writeLine(s) { this.builder += s; this.outfile.WriteLine(this.builder); this.builder = ""; } } export function prePrintAST(ast: AST, parent: AST, walker: IAstWalker) { var pc: PrintContext = <PrintContext>walker.state; ast.print(pc); pc.increaseIndent(); return ast; } export function postPrintAST(ast: AST, parent: AST, walker: IAstWalker) { var pc: PrintContext = <PrintContext>walker.state; pc.decreaseIndent(); return ast; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRealSource6.ts
TypeScript
// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. ///<reference path='typescript.ts' /> module TypeScript { export class TypeCollectionContext { public script: Script = null; constructor (public scopeChain: ScopeChain, public checker: TypeChecker) { } } export class MemberScopeContext { public type: Type = null; public ast: AST = null; public scope: SymbolScope; public options = new AstWalkOptions(); constructor (public flow: TypeFlow, public pos: number, public matchFlag: ASTFlags) { } } export class EnclosingScopeContext { public scopeGetter: () => SymbolScope = null; public objectLiteralScopeGetter: () => SymbolScope = null; public scopeStartAST: AST = null; public skipNextFuncDeclForClass = false; public deepestModuleDecl: ModuleDeclaration = null; public enclosingClassDecl: TypeDeclaration = null; public enclosingObjectLit: UnaryExpression = null; public publicsOnly = true; public useFullAst = false; private scriptFragment: Script; constructor (public logger: ILogger, public script: Script, public text: ISourceText, public pos: number, public isMemberCompletion: boolean) { } public getScope(): SymbolScope { return this.scopeGetter(); } public getObjectLiteralScope(): SymbolScope { return this.objectLiteralScopeGetter(); } public getScopeAST() { return this.scopeStartAST; } public getScopePosition() { return this.scopeStartAST.minChar; } public getScriptFragmentStartAST(): AST { return this.scopeStartAST; } public getScriptFragmentPosition(): number { return this.getScriptFragmentStartAST().minChar; } public getScriptFragment(): Script { if (this.scriptFragment == null) { var ast = this.getScriptFragmentStartAST(); var minChar = ast.minChar; var limChar = (this.isMemberCompletion ? this.pos : this.pos + 1); this.scriptFragment = TypeScript.quickParse(this.logger, ast, this.text, minChar, limChar, null/*errorCapture*/).Script; } return this.scriptFragment; } } export function preFindMemberScope(ast: AST, parent: AST, walker: IAstWalker) { var memScope: MemberScopeContext = walker.state; if (hasFlag(ast.flags, memScope.matchFlag) && ((memScope.pos < 0) || (memScope.pos == ast.limChar))) { memScope.ast = ast; if ((ast.type == null) && (memScope.pos >= 0)) { memScope.flow.inScopeTypeCheck(ast, memScope.scope); } memScope.type = ast.type; memScope.options.stopWalk(); } return ast; } export function pushTypeCollectionScope(container: Symbol, valueMembers: ScopedMembers, ambientValueMembers: ScopedMembers, enclosedTypes: ScopedMembers, ambientEnclosedTypes: ScopedMembers, context: TypeCollectionContext, thisType: Type, classType: Type, moduleDecl: ModuleDeclaration) { var builder = new SymbolScopeBuilder(valueMembers, ambientValueMembers, enclosedTypes, ambientEnclosedTypes, null, container); var chain: ScopeChain = new ScopeChain(container, context.scopeChain, builder); chain.thisType = thisType; chain.classType = classType; chain.moduleDecl = moduleDecl; context.scopeChain = chain; } export function popTypeCollectionScope(context: TypeCollectionContext) { context.scopeChain = context.scopeChain.previous; } export function preFindEnclosingScope(ast: AST, parent: AST, walker: IAstWalker) { var context: EnclosingScopeContext = walker.state; var minChar = ast.minChar; var limChar = ast.limChar; // Account for the fact completion list may be called at the end of a file which // is has not been fully re-parsed yet. if (ast.nodeType == NodeType.Script && context.pos > limChar) limChar = context.pos; if ((minChar <= context.pos) && (limChar >= context.pos)) { switch (ast.nodeType) { case NodeType.Script: var script = <Script>ast; context.scopeGetter = function () { return script.bod === null ? null : script.bod.enclosingScope; }; context.scopeStartAST = script; break; case NodeType.ClassDeclaration: context.scopeGetter = function () { return (ast.type === null || ast.type.instanceType.containedScope === null) ? null : ast.type.instanceType.containedScope; }; context.scopeStartAST = ast; context.enclosingClassDecl = <TypeDeclaration>ast; break; case NodeType.ObjectLit: var objectLit = <UnaryExpression>ast; // Only consider target-typed object literals if (objectLit.targetType) { context.scopeGetter = function () { return objectLit.targetType.containedScope; }; context.objectLiteralScopeGetter = function () { return objectLit.targetType.memberScope; } context.enclosingObjectLit = objectLit; } break; case NodeType.ModuleDeclaration: context.deepestModuleDecl = <ModuleDeclaration>ast; context.scopeGetter = function () { return ast.type === null ? null : ast.type.containedScope; }; context.scopeStartAST = ast; break; case NodeType.InterfaceDeclaration: context.scopeGetter = function () { return (ast.type === null) ? null : ast.type.containedScope; }; context.scopeStartAST = ast; break; case NodeType.FuncDecl: { var funcDecl = <FuncDecl>ast; if (context.skipNextFuncDeclForClass) { context.skipNextFuncDeclForClass = false; } else { context.scopeGetter = function () { // The scope of a class constructor is hidden somewhere we don't expect :-S if (funcDecl.isConstructor && hasFlag(funcDecl.fncFlags, FncFlags.ClassMethod)) { if (ast.type && ast.type.enclosingType) { return ast.type.enclosingType.constructorScope; } } if (funcDecl.scopeType) { return funcDecl.scopeType.containedScope; } if (funcDecl.type) { return funcDecl.type.containedScope; } return null; }; context.scopeStartAST = ast; } } break; } walker.options.goChildren = true; } else { walker.options.goChildren = false; } return ast; } // // Find the enclosing scope context from a position inside a script AST. // The "scopeStartAST" of the returned scope is always valid. // Return "null" if the enclosing scope can't be found. // export function findEnclosingScopeAt(logger: ILogger, script: Script, text: ISourceText, pos: number, isMemberCompletion: boolean): EnclosingScopeContext { var context = new EnclosingScopeContext(logger, script, text, pos, isMemberCompletion); TypeScript.getAstWalkerFactory().walk(script, preFindEnclosingScope, null, null, context); if (context.scopeStartAST === null) return null; return context; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRealSource8.ts
TypeScript
// Copyright (c) Microsoft. All rights reserved. Licensed under the Apache License, Version 2.0. // See LICENSE.txt in the project root for complete license information. ///<reference path='typescript.ts' /> module TypeScript { export class AssignScopeContext { constructor (public scopeChain: ScopeChain, public typeFlow: TypeFlow, public modDeclChain: ModuleDeclaration[]) { } } export function pushAssignScope(scope: SymbolScope, context: AssignScopeContext, type: Type, classType: Type, fnc: FuncDecl) { var chain = new ScopeChain(null, context.scopeChain, scope); chain.thisType = type; chain.classType = classType; chain.fnc = fnc; context.scopeChain = chain; } export function popAssignScope(context: AssignScopeContext) { context.scopeChain = context.scopeChain.previous; } export function instanceCompare(a: Symbol, b: Symbol) { if (((a == null) || (!a.isInstanceProperty()))) { return b; } else { return a; } } export function instanceFilterStop(s: Symbol) { return s.isInstanceProperty(); } export class ScopeSearchFilter { constructor (public select: (a: Symbol, b: Symbol) =>Symbol, public stop: (s: Symbol) =>boolean) { } public result: Symbol = null; public reset() { this.result = null; } public update(b: Symbol): boolean { this.result = this.select(this.result, b); if (this.result) { return this.stop(this.result); } else { return false; } } } export var instanceFilter = new ScopeSearchFilter(instanceCompare, instanceFilterStop); export function preAssignModuleScopes(ast: AST, context: AssignScopeContext) { var moduleDecl = <ModuleDeclaration>ast; var memberScope: SymbolTableScope = null; var aggScope: SymbolAggregateScope = null; if (moduleDecl.name && moduleDecl.mod) { moduleDecl.name.sym = moduleDecl.mod.symbol; } var mod = moduleDecl.mod; // We're likely here because of error recovery if (!mod) { return; } memberScope = new SymbolTableScope(mod.members, mod.ambientMembers, mod.enclosedTypes, mod.ambientEnclosedTypes, mod.symbol); mod.memberScope = memberScope; context.modDeclChain.push(moduleDecl); context.typeFlow.checker.currentModDecl = moduleDecl; aggScope = new SymbolAggregateScope(mod.symbol); aggScope.addParentScope(memberScope); aggScope.addParentScope(context.scopeChain.scope); pushAssignScope(aggScope, context, null, null, null); mod.containedScope = aggScope; if (mod.symbol) { context.typeFlow.addLocalsFromScope(mod.containedScope, mod.symbol, moduleDecl.vars, mod.members.privateMembers, true); } } export function preAssignClassScopes(ast: AST, context: AssignScopeContext) { var classDecl = <InterfaceDeclaration>ast; var memberScope: SymbolTableScope = null; var aggScope: SymbolAggregateScope = null; if (classDecl.name && classDecl.type) { classDecl.name.sym = classDecl.type.symbol; } var classType = ast.type; if (classType) { var classSym = classType.symbol; memberScope = <SymbolTableScope>context.typeFlow.checker.scopeOf(classType); aggScope = new SymbolAggregateScope(classType.symbol); aggScope.addParentScope(memberScope); aggScope.addParentScope(context.scopeChain.scope); classType.containedScope = aggScope; classType.memberScope = memberScope; var instanceType = classType.instanceType; memberScope = <SymbolTableScope>context.typeFlow.checker.scopeOf(instanceType); instanceType.memberScope = memberScope; aggScope = new SymbolAggregateScope(instanceType.symbol); aggScope.addParentScope(context.scopeChain.scope); pushAssignScope(aggScope, context, instanceType, classType, null); instanceType.containedScope = aggScope; } else { ast.type = context.typeFlow.anyType; } } export function preAssignInterfaceScopes(ast: AST, context: AssignScopeContext) { var interfaceDecl = <InterfaceDeclaration>ast; var memberScope: SymbolTableScope = null; var aggScope: SymbolAggregateScope = null; if (interfaceDecl.name && interfaceDecl.type) { interfaceDecl.name.sym = interfaceDecl.type.symbol; } var interfaceType = ast.type; memberScope = <SymbolTableScope>context.typeFlow.checker.scopeOf(interfaceType); interfaceType.memberScope = memberScope; aggScope = new SymbolAggregateScope(interfaceType.symbol); aggScope.addParentScope(memberScope); aggScope.addParentScope(context.scopeChain.scope); pushAssignScope(aggScope, context, null, null, null); interfaceType.containedScope = aggScope; } export function preAssignWithScopes(ast: AST, context: AssignScopeContext) { var withStmt = <WithStatement>ast; var withType = withStmt.type; var members = new ScopedMembers(new DualStringHashTable(new StringHashTable(), new StringHashTable())); var ambientMembers = new ScopedMembers(new DualStringHashTable(new StringHashTable(), new StringHashTable())); var withType = new Type(); var withSymbol = new WithSymbol(withStmt.minChar, context.typeFlow.checker.locationInfo.unitIndex, withType); withType.members = members; withType.ambientMembers = ambientMembers; withType.symbol = withSymbol; withType.setHasImplementation(); withStmt.type = withType; var withScope = new TypeScript.SymbolScopeBuilder(withType.members, withType.ambientMembers, null, null, context.scopeChain.scope, withType.symbol); pushAssignScope(withScope, context, null, null, null); withType.containedScope = withScope; } export function preAssignFuncDeclScopes(ast: AST, context: AssignScopeContext) { var funcDecl = <FuncDecl>ast; var container: Symbol = null; var localContainer: Symbol = null; if (funcDecl.type) { localContainer = ast.type.symbol; } var isStatic = hasFlag(funcDecl.fncFlags, FncFlags.Static); var isInnerStatic = isStatic && context.scopeChain.fnc != null; // for inner static functions, use the parent's member scope, so local vars cannot be captured var parentScope = isInnerStatic ? context.scopeChain.fnc.type.memberScope : context.scopeChain.scope; // if this is not a method, but enclosed by class, use constructor as // the enclosing scope // REVIEW: Some twisted logic here - this needs to be cleaned up once old classes are removed // - if it's a new class, always use the contained scope, since we initialize the constructor scope below if (context.scopeChain.thisType && (!funcDecl.isConstructor || hasFlag(funcDecl.fncFlags, FncFlags.ClassMethod))) { var instType = context.scopeChain.thisType; if (!(instType.typeFlags & TypeFlags.IsClass) && !hasFlag(funcDecl.fncFlags, FncFlags.ClassMethod)) { if (!funcDecl.isMethod() || isStatic) { parentScope = instType.constructorScope; } else { // use constructor scope if a method as well parentScope = instType.containedScope; } } else { if (context.scopeChain.previous.scope.container && context.scopeChain.previous.scope.container.declAST && context.scopeChain.previous.scope.container.declAST.nodeType == NodeType.FuncDecl && (<FuncDecl>context.scopeChain.previous.scope.container.declAST).isConstructor) { // if the parent is the class constructor, use the constructor scope parentScope = instType.constructorScope; } else if (isStatic && context.scopeChain.classType) { parentScope = context.scopeChain.classType.containedScope; } else { // else, use the contained scope parentScope = instType.containedScope; } } container = instType.symbol; } else if (funcDecl.isConstructor && context.scopeChain.thisType) { // sets the container to the class type's symbol (which is shared by the instance type) container = context.scopeChain.thisType.symbol; } if (funcDecl.type == null || hasFlag(funcDecl.type.symbol.flags, SymbolFlags.TypeSetDuringScopeAssignment)) { if (context.scopeChain.fnc && context.scopeChain.fnc.type) { container = context.scopeChain.fnc.type.symbol; } var funcScope = null; var outerFnc: FuncDecl = context.scopeChain.fnc; var nameText = funcDecl.name ? funcDecl.name.actualText : null; var fgSym: TypeSymbol = null; if (isStatic) { // In the case of function-nested statics, no member list will have bee initialized for the function, so we need // to copy it over. We don't set this by default because having a non-null member list will throw off assignment // compatibility tests if (outerFnc.type.members == null && container.getType().memberScope) { outerFnc.type.members = (<SymbolScopeBuilder>(<TypeSymbol>container).type.memberScope).valueMembers; } funcScope = context.scopeChain.fnc.type.memberScope; outerFnc.innerStaticFuncs[outerFnc.innerStaticFuncs.length] = funcDecl; } else { if (!funcDecl.isConstructor && container && container.declAST && container.declAST.nodeType == NodeType.FuncDecl && (<FuncDecl>container.declAST).isConstructor && !funcDecl.isMethod()) { funcScope = context.scopeChain.thisType.constructorScope;//locals; } else { funcScope = context.scopeChain.scope; } } // REVIEW: We don't search for another sym for accessors to prevent us from // accidentally coalescing function signatures with the same name (E.g., a function // 'f' the outer scope and a setter 'f' in an object literal within that scope) if (nameText && nameText != "__missing" && !funcDecl.isAccessor()) { if (isStatic) { fgSym = funcScope.findLocal(nameText, false, false); } else { // REVIEW: This logic should be symmetric with preCollectClassTypes fgSym = funcScope.findLocal(nameText, false, false); } } context.typeFlow.checker.createFunctionSignature(funcDecl, container, funcScope, fgSym, fgSym == null); // it's a getter or setter for a class property if (!funcDecl.accessorSymbol && (funcDecl.fncFlags & FncFlags.ClassMethod) && container && ((!fgSym || fgSym.declAST.nodeType != NodeType.FuncDecl) && funcDecl.isAccessor()) || (fgSym && fgSym.isAccessor())) { funcDecl.accessorSymbol = context.typeFlow.checker.createAccessorSymbol(funcDecl, fgSym, container.getType(), (funcDecl.isMethod() && isStatic), true, funcScope, container); } funcDecl.type.symbol.flags |= SymbolFlags.TypeSetDuringScopeAssignment; } // Set the symbol for functions and their overloads if (funcDecl.name && funcDecl.type) { funcDecl.name.sym = funcDecl.type.symbol; } // Keep track of the original scope type, because target typing might override // the "type" member. We need the original "Scope type" for completion list, etc. funcDecl.scopeType = funcDecl.type; // Overloads have no scope, so bail here if (funcDecl.isOverload) { return; } var funcTable = new StringHashTable(); var funcMembers = new ScopedMembers(new DualStringHashTable(funcTable, new StringHashTable())); var ambientFuncTable = new StringHashTable(); var ambientFuncMembers = new ScopedMembers(new DualStringHashTable(ambientFuncTable, new StringHashTable())); var funcStaticTable = new StringHashTable(); var funcStaticMembers = new ScopedMembers(new DualStringHashTable(funcStaticTable, new StringHashTable())); var ambientFuncStaticTable = new StringHashTable(); var ambientFuncStaticMembers = new ScopedMembers(new DualStringHashTable(ambientFuncStaticTable, new StringHashTable())); // REVIEW: Is it a problem that this is being set twice for properties and constructors? funcDecl.unitIndex = context.typeFlow.checker.locationInfo.unitIndex; var locals = new SymbolScopeBuilder(funcMembers, ambientFuncMembers, null, null, parentScope, localContainer); var statics = new SymbolScopeBuilder(funcStaticMembers, ambientFuncStaticMembers, null, null, parentScope, null); if (funcDecl.isConstructor && context.scopeChain.thisType) { context.scopeChain.thisType.constructorScope = locals; } // basically, there are two problems // - Above, for new classes, we were overwriting the constructor scope with the containing scope. This caused constructor params to be // in scope everywhere // - Below, we're setting the contained scope table to the same table we were overwriting the constructor scope with, which we need to // fish lambda params, etc, out (see funcTable below) // // A good first approach to solving this would be to change addLocalsFromScope to take a scope instead of a table, and add to the // constructor scope as appropriate funcDecl.symbols = funcTable; if (!funcDecl.isSpecialFn()) { var group = funcDecl.type; var signature = funcDecl.signature; if (!funcDecl.isConstructor) { group.containedScope = locals; locals.container = group.symbol; group.memberScope = statics; statics.container = group.symbol; } funcDecl.enclosingFnc = context.scopeChain.fnc; group.enclosingType = isStatic ? context.scopeChain.classType : context.scopeChain.thisType; // for mapping when type checking var fgSym = <TypeSymbol>ast.type.symbol; if (((funcDecl.fncFlags & FncFlags.Signature) == FncFlags.None) && funcDecl.vars) { context.typeFlow.addLocalsFromScope(locals, fgSym, funcDecl.vars, funcTable, false); context.typeFlow.addLocalsFromScope(statics, fgSym, funcDecl.statics, funcStaticTable, false); } if (signature.parameters) { var len = signature.parameters.length; for (var i = 0; i < len; i++) { var paramSym: ParameterSymbol = signature.parameters[i]; context.typeFlow.checker.resolveTypeLink(locals, paramSym.parameter.typeLink, true); } } context.typeFlow.checker.resolveTypeLink(locals, signature.returnType, funcDecl.isSignature()); } if (!funcDecl.isConstructor || hasFlag(funcDecl.fncFlags, FncFlags.ClassMethod)) { var thisType = (funcDecl.isConstructor && hasFlag(funcDecl.fncFlags, FncFlags.ClassMethod)) ? context.scopeChain.thisType : null; pushAssignScope(locals, context, thisType, null, funcDecl); } } export function preAssignCatchScopes(ast: AST, context: AssignScopeContext) { var catchBlock = <Catch>ast; if (catchBlock.param) { var catchTable = new ScopedMembers(new DualStringHashTable(new StringHashTable(), new StringHashTable())); // REVIEW: Should we be allocating a public table instead of a private one? var catchLocals = new SymbolScopeBuilder(catchTable, null, null, null, context.scopeChain.scope, context.scopeChain.scope.container); catchBlock.containedScope = catchLocals; pushAssignScope(catchLocals, context, context.scopeChain.thisType, context.scopeChain.classType, context.scopeChain.fnc); } } export function preAssignScopes(ast: AST, parent: AST, walker: IAstWalker) { var context:AssignScopeContext = walker.state; var go = true; if (ast) { if (ast.nodeType == NodeType.List) { var list = <ASTList>ast; list.enclosingScope = context.scopeChain.scope; } else if (ast.nodeType == NodeType.ModuleDeclaration) { preAssignModuleScopes(ast, context); } else if (ast.nodeType == NodeType.ClassDeclaration) { preAssignClassScopes(ast, context); } else if (ast.nodeType == NodeType.InterfaceDeclaration) { preAssignInterfaceScopes(ast, context); } else if (ast.nodeType == NodeType.With) { preAssignWithScopes(ast, context); } else if (ast.nodeType == NodeType.FuncDecl) { preAssignFuncDeclScopes(ast, context); } else if (ast.nodeType == NodeType.Catch) { preAssignCatchScopes(ast, context); } else if (ast.nodeType == NodeType.TypeRef) { go = false; } } walker.options.goChildren = go; return ast; } export function postAssignScopes(ast: AST, parent: AST, walker: IAstWalker) { var context:AssignScopeContext = walker.state; var go = true; if (ast) { if (ast.nodeType == NodeType.ModuleDeclaration) { var prevModDecl = <ModuleDeclaration>ast; popAssignScope(context); context.modDeclChain.pop(); if (context.modDeclChain.length >= 1) { context.typeFlow.checker.currentModDecl = context.modDeclChain[context.modDeclChain.length - 1]; } } else if (ast.nodeType == NodeType.ClassDeclaration) { popAssignScope(context); } else if (ast.nodeType == NodeType.InterfaceDeclaration) { popAssignScope(context); } else if (ast.nodeType == NodeType.With) { popAssignScope(context); } else if (ast.nodeType == NodeType.FuncDecl) { var funcDecl = <FuncDecl>ast; if ((!funcDecl.isConstructor || hasFlag(funcDecl.fncFlags, FncFlags.ClassMethod)) && !funcDecl.isOverload) { popAssignScope(context); } } else if (ast.nodeType == NodeType.Catch) { var catchBlock = <Catch>ast; if (catchBlock.param) { popAssignScope(context); } } else { go = false; } } walker.options.goChildren = go; return ast; } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRegularExpression2.ts
TypeScript
href.match(/:\/\/(.[^/]+)/)[1];
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRegularExpression3.ts
TypeScript
Foo(!/(\\?|&)adurl=/);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRegularExpression4.ts
TypeScript
if (Ca.test(c.href) || Ba.test(c.href) && /(\\?|&)adurl=/.test(c.href) && !/(\\?|&)q=/.test(c.href)) / (\\ ? | & ) rct = j / .test(c.href) || (d += "&rct=j"), /(\\?|&)q=/.test(c.href) || (d += "&q=" + encodeURIComponent(W("q") || W("as_q") || A), d = d.substring(0, 1948 - c.href.length)), b = !0;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRegularExpression5.ts
TypeScript
if (a) / (\\ ? | & ) rct = j / .test(c.href);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRegularExpressionDivideAmbiguity1.ts
TypeScript
1 /notregexp/a.foo();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRegularExpressionDivideAmbiguity2.ts
TypeScript
(1) /notregexp/a.foo();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRegularExpressionDivideAmbiguity3.ts
TypeScript
if (1) /regexp/a.foo();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRegularExpressionDivideAmbiguity5.ts
TypeScript
model.rotate(0, rotateY * Math.PI / 180, rotateZ * Math.PI / 180);
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserRegularExpressionDivideAmbiguity6.ts
TypeScript
function c255lsqr8h(a7, a6, a5, a4, a3, a2, a1, a0) { let r = []; let v; r[0] = (v = a0*a0) & 0xFFFF; r[1] = (v = ((v / 0x10000) | 0) + 2*a0*a1) & 0xFFFF; r[2] = (v = ((v / 0x10000) | 0) + 2*a0*a2 + a1*a1) & 0xFFFF; r[3] = (v = ((v / 0x10000) | 0) + 2*a0*a3 + 2*a1*a2) & 0xFFFF; r[4] = (v = ((v / 0x10000) | 0) + 2*a0*a4 + 2*a1*a3 + a2*a2) & 0xFFFF; r[5] = (v = ((v / 0x10000) | 0) + 2*a0*a5 + 2*a1*a4 + 2*a2*a3) & 0xFFFF; r[6] = (v = ((v / 0x10000) | 0) + 2*a0*a6 + 2*a1*a5 + 2*a2*a4 + a3*a3) & 0xFFFF; r[7] = (v = ((v / 0x10000) | 0) + 2*a0*a7 + 2*a1*a6 + 2*a2*a5 + 2*a3*a4) & 0xFFFF; r[8] = (v = ((v / 0x10000) | 0) + 2*a1*a7 + 2*a2*a6 + 2*a3*a5 + a4*a4) & 0xFFFF; r[9] = (v = ((v / 0x10000) | 0) + 2*a2*a7 + 2*a3*a6 + 2*a4*a5) & 0xFFFF; r[10] = (v = ((v / 0x10000) | 0) + 2*a3*a7 + 2*a4*a6 + a5*a5) & 0xFFFF; r[11] = (v = ((v / 0x10000) | 0) + 2*a4*a7 + 2*a5*a6) & 0xFFFF; r[12] = (v = ((v / 0x10000) | 0) + 2*a5*a7 + a6*a6) & 0xFFFF; r[13] = (v = ((v / 0x10000) | 0) + 2*a6*a7) & 0xFFFF; r[14] = (v = ((v / 0x10000) | 0) + a7*a7) & 0xFFFF; r[15] = ((v / 0x10000) | 0); return r; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserReturnStatement3.ts
TypeScript
function f() { return; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserReturnStatement4.js
JavaScript
var v = { get foo() { return; } };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserReturnStatement4.ts
TypeScript
var v = { get foo() { return } };
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserS7.2_A1.5_T2.ts
TypeScript
// Copyright 2009 the Sputnik authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /** * NO-BREAK SPACE (U+00A0) between any two tokens is allowed * * @path ch07/7.2/S7.2_A1.5_T2.js * @description Insert real NO-BREAK SPACE between tokens of var x=1 */ //CHECK#1 eval("\u00A0var x\u00A0= 1\u00A0"); if (x !== 1) { $ERROR('#1: eval("\\u00A0var x\\u00A0= 1\\u00A0"); x === 1. Actual: ' + (x)); } //CHECK#2  var x = 1 ; if (x !== 1) { $ERROR('#2:  var x = 1 ; x === 1. Actual: ' + (x)); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserS7.3_A1.1_T2.ts
TypeScript
// Copyright 2009 the Sputnik authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /** * LINE FEED (U+000A) may occur between any two tokens * * @path ch07/7.3/S7.3_A1.1_T2.js * @description Insert real LINE FEED between tokens of var x=1 */ //CHECK#1 var x = 1; if (x !== 1) { $ERROR('#1: var\\nx\\n=\\n1\\n; x === 1. Actual: ' + (x)); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserS7.6.1.1_A1.10.ts
TypeScript
// Copyright 2009 the Sputnik authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /** * The "for" token can not be used as identifier * * @path ch07/7.6/7.6.1/7.6.1.1/S7.6.1.1_A1.10.js * @description Checking if execution of "for=1" fails * @negative */ //for = 1;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserS7.6_A4.2_T1.ts
TypeScript
// Copyright 2009 the Sputnik authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /** * Correct interpretation of RUSSIAN ALPHABET * * @path ch07/7.6/S7.6_A4.2_T1.js * @description Check RUSSIAN CAPITAL ALPHABET */ //CHECK#А-Я var \u0410 = 1; if (А !== 1) { $ERROR('#А'); } var \u0411 = 1; if (Б !== 1) { $ERROR('#Б'); } var \u0412 = 1; if (В !== 1) { $ERROR('#В'); } var \u0413 = 1; if (Г !== 1) { $ERROR('#Г'); } var \u0414 = 1; if (Д !== 1) { $ERROR('#Д'); } var \u0415 = 1; if (Е !== 1) { $ERROR('#Е'); } var \u0416 = 1; if (Ж !== 1) { $ERROR('#Ж'); } var \u0417 = 1; if (З !== 1) { $ERROR('#З'); } var \u0418 = 1; if (И !== 1) { $ERROR('#И'); } var \u0419 = 1; if (Й !== 1) { $ERROR('#Й'); } var \u041A = 1; if (К !== 1) { $ERROR('#К'); } var \u041B = 1; if (Л !== 1) { $ERROR('#Л'); } var \u041C = 1; if (М !== 1) { $ERROR('#М'); } var \u041D = 1; if (Н !== 1) { $ERROR('#Н'); } var \u041E = 1; if (О !== 1) { $ERROR('#О'); } var \u041F = 1; if (П !== 1) { $ERROR('#П'); } var \u0420 = 1; if (Р !== 1) { $ERROR('#Р'); } var \u0421 = 1; if (С !== 1) { $ERROR('#С'); } var \u0422 = 1; if (Т !== 1) { $ERROR('#Т'); } var \u0423 = 1; if (У !== 1) { $ERROR('#У'); } var \u0424 = 1; if (Ф !== 1) { $ERROR('#Ф'); } var \u0425 = 1; if (Х !== 1) { $ERROR('#Х'); } var \u0426 = 1; if (Ц !== 1) { $ERROR('#Ц'); } var \u0427 = 1; if (Ч !== 1) { $ERROR('#Ч'); } var \u0428 = 1; if (Ш !== 1) { $ERROR('#Ш'); } var \u0429 = 1; if (Щ !== 1) { $ERROR('#Щ'); } var \u042A = 1; if (Ъ !== 1) { $ERROR('#Ъ'); } var \u042B = 1; if (Ы !== 1) { $ERROR('#Ы'); } var \u042C = 1; if (Ь !== 1) { $ERROR('#Ь'); } var \u042D = 1; if (Э !== 1) { $ERROR('#Э'); } var \u042E = 1; if (Ю !== 1) { $ERROR('#Ю'); } var \u042F = 1; if (Я !== 1) { $ERROR('#Я'); } var \u0401 = 1; if (Ё !== 1) { $ERROR('#Ё'); }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserSbp_7.9_A9_T3.ts
TypeScript
// Copyright 2009 the Sputnik authors. All rights reserved. // This code is governed by the BSD license found in the LICENSE file. /** * Check Do-While Statement for automatic semicolon insertion * * @path bestPractice/Sbp_7.9_A9_T3.js * @description Execute do { \n ; \n }while(false) true */ //CHECK#1 do { ; } while (false) true
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserStrictMode1.ts
TypeScript
foo1(); foo1(); foo1(); static();
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserStrictMode15-negative.ts
TypeScript
"use strict"; delete a[b];
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserStrictMode16.ts
TypeScript
"use strict"; delete this; delete 1; delete null; delete "a";
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserStrictMode3-negative.ts
TypeScript
eval = 1;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserStrictMode6-negative.ts
TypeScript
eval++;
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserSuperExpression1.ts
TypeScript
class C { private foo() { super.foo(); } } module M1.M2 { class C { private foo() { super.foo(); } } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserSuperExpression2.ts
TypeScript
class C { M() { super<T>(0); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserSuperExpression3.ts
TypeScript
class C { M() { this.super<T>(0); } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserSuperExpression4.ts
TypeScript
class C { private foo() { super.foo = 1 } } module M1.M2 { class C { private foo() { super.foo = 1 } } }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserSymbolIndexer1.ts
TypeScript
//@target: ES6 interface I { [s: symbol]: string; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University
crates/swc_ecma_parser/tests/tsc/parserSymbolIndexer2.ts
TypeScript
//@target: ES6 class C { [s: symbol]: string; }
willcrichton/ilc-swc
1
Rust
willcrichton
Will Crichton
Brown University