diff --git a/testTs/instype/recordexport.ts b/testTs/instype/recordexport.ts index 5328134355b26623feed8a8e7b24c58730b8ca72..105a82b844d54b63748db35a91e7b43f17b8d237 100644 --- a/testTs/instype/recordexport.ts +++ b/testTs/instype/recordexport.ts @@ -1,4 +1,4 @@ -export default function hello(str: string) { +export default function hello(str: string): string { return str; } @@ -9,11 +9,11 @@ export let d: string = "world"; export class Calculator{} -export function add(x: number, y: number) { +export function add(x: number, y: number): number { return x + y; } -export function minus(x: number, y: number) { +export function minus(x: number, y: number): number { return x - y; } diff --git a/testTs/instype/recordthis.ts b/testTs/instype/recordthis.ts index c032ae27be269f1d72cf5815cd4651fce77f79ff..7ddec1decf85b472a0b2010196e8eefd3b476fdd 100644 --- a/testTs/instype/recordthis.ts +++ b/testTs/instype/recordthis.ts @@ -19,7 +19,7 @@ class A { get getName(): string { return this.name; } - get getId() { + get getId(): number { return this.id; } set setName(name: string) { @@ -37,13 +37,13 @@ class A { } static a: number = 1; a: number = 2; - static stest() { + static stest(): void { console.log(this.a); } - test() { + test(): void { console.log(this.a); } - testwiththis(this: A) { + testwiththis(this: A): void { console.log(this.a); } } diff --git a/ts2panda/src/addVariable2Scope.ts b/ts2panda/src/addVariable2Scope.ts index 0f64f618bd98e704a544007959ff3287c266fc62..3fe655309599ea24c7033a9077047513894aea0d 100644 --- a/ts2panda/src/addVariable2Scope.ts +++ b/ts2panda/src/addVariable2Scope.ts @@ -42,7 +42,7 @@ import { Variable } from "./variable"; -function setVariableOrParameterType(node: ts.Node, v: Variable | undefined) { +function setVariableOrParameterType(node: ts.Node, v: Variable | undefined): void { if (v) { let typeIndex = TypeRecorder.getInstance().tryGetVariable2Type(ts.getOriginalNode(node)); if (typeIndex === PrimitiveType.ANY) { @@ -52,14 +52,14 @@ function setVariableOrParameterType(node: ts.Node, v: Variable | undefined) { } } -function setClassOrFunctionType(node: ts.Node, v: Variable | undefined) { +function setClassOrFunctionType(node: ts.Node, v: Variable | undefined): void { if (v) { let typeIndex = TypeRecorder.getInstance().tryGetTypeIndex(ts.getOriginalNode(node)); v.setTypeIndex(typeIndex); } } -function setTypeIndex(node: ts.Node, v: Variable | undefined, isClassOrFunction: boolean) { +function setTypeIndex(node: ts.Node, v: Variable | undefined, isClassOrFunction: boolean): void { if (isClassOrFunction) { setClassOrFunctionType(node, v); } else { @@ -107,7 +107,7 @@ function addInnerArgs(node: ts.Node, scope: VariableScope, enableTypeRecord: boo } } -export function addVariableToScope(recorder: Recorder, enableTypeRecord: boolean) { +export function addVariableToScope(recorder: Recorder, enableTypeRecord: boolean): void { let scopeMap = recorder.getScopeMap(); let hoistMap = recorder.getHoistMap(); @@ -210,7 +210,7 @@ function addParameters(node: ts.FunctionLikeDeclaration, scope: VariableScope, e } } -function addPatternParamterElements(pattern: ts.BindingPattern, scope: VariableScope) { +function addPatternParamterElements(pattern: ts.BindingPattern, scope: VariableScope): void { let name: string = ''; pattern.elements.forEach(bindingElement => { if (ts.isOmittedExpression(bindingElement)) { diff --git a/ts2panda/src/base/bcGenUtil.ts b/ts2panda/src/base/bcGenUtil.ts index 22ae1ca7dbcc873c90b8ea4c1b06042631445ee5..66d6e72f04306a3264910e99dff3940d70be5535 100644 --- a/ts2panda/src/base/bcGenUtil.ts +++ b/ts2panda/src/base/bcGenUtil.ts @@ -161,23 +161,23 @@ export function throwException(): IRNode { return new Throw(); } -export function throwConstAssignment(name: VReg) { +export function throwConstAssignment(name: VReg): IRNode { return new ThrowConstassignment(name); } -export function throwUndefinedIfHole(name: string) { +export function throwUndefinedIfHole(name: string): IRNode { return new ThrowUndefinedifholewithname(name); } -export function throwThrowNotExists() { +export function throwThrowNotExists(): IRNode { return new ThrowNotexists(); } -export function throwDeleteSuperProperty() { +export function throwDeleteSuperProperty(): IRNode { return new ThrowDeletesuperproperty(); } -export function newLexicalEnv(numVars: number, scopeInfoId: string | undefined) { +export function newLexicalEnv(numVars: number, scopeInfoId: string | undefined): IRNode { if (scopeInfoId == undefined) { return numVars <= MAX_INT8 ? new Newlexenv(new Imm(numVars)) : new WideNewlexenv(new Imm(numVars)); @@ -186,54 +186,54 @@ export function newLexicalEnv(numVars: number, scopeInfoId: string | undefined) new WideNewlexenvwithname(new Imm(numVars), scopeInfoId); } -export function popLexicalEnv() { +export function popLexicalEnv(): IRNode { return new Poplexenv(); } -export function loadLexicalVar(level: number, slot: number) { +export function loadLexicalVar(level: number, slot: number): IRNode { if ((level > MAX_INT8) || (slot > MAX_INT8)) { return new WideLdlexvar(new Imm(level), new Imm(slot)); } return new Ldlexvar(new Imm(level), new Imm(slot)); } -export function storeLexicalVar(level: number, slot: number) { +export function storeLexicalVar(level: number, slot: number): IRNode { if ((level > MAX_INT8) || (slot > MAX_INT8)) { return new WideStlexvar(new Imm(level), new Imm(slot)); } return new Stlexvar(new Imm(level), new Imm(slot)); } -export function tryLoadGlobalByName(key: string) { +export function tryLoadGlobalByName(key: string): IRNode { return new Tryldglobalbyname(new Imm(0), key); } -export function tryStoreGlobalByName(key: string) { +export function tryStoreGlobalByName(key: string): IRNode { return new Trystglobalbyname(new Imm(0), key); } -export function loadGlobalVar(name: string) { +export function loadGlobalVar(name: string): IRNode { return new Ldglobalvar(new Imm(0), name); } -export function storeGlobalVar(name: string) { +export function storeGlobalVar(name: string): IRNode { return new Stglobalvar(new Imm(0), name); } -export function loadObjByName(key: string) { +export function loadObjByName(key: string): IRNode { return new Ldobjbyname(new Imm(0), key); } -export function storeObjByName(obj: VReg, key: string) { +export function storeObjByName(obj: VReg, key: string): IRNode { return new Stobjbyname(new Imm(0), key, obj); } -export function loadObjByIndex(index: number) { +export function loadObjByIndex(index: number): IRNode { return index <= MAX_INT16 ? new Ldobjbyindex(new Imm(0), new Imm(index)) : new WideLdobjbyindex(new Imm(index)); } -export function storeObjByIndex(obj: VReg, index: number) { +export function storeObjByIndex(obj: VReg, index: number): IRNode { return index <= MAX_INT16 ? new Stobjbyindex(new Imm(0), obj, new Imm(index)) : new WideStobjbyindex(obj, new Imm(index)); } @@ -251,21 +251,21 @@ export function storeOwnByName(obj: VReg, key: string, nameSetting: boolean): IR new Stownbyname(new Imm(0), key, obj); } -export function storeOwnByIndex(obj: VReg, index: number) { +export function storeOwnByIndex(obj: VReg, index: number): IRNode { return index <= MAX_INT16 ? new Stownbyindex(new Imm(0), obj, new Imm(index)) : new WideStownbyindex(obj, new Imm(index)); } -export function storeOwnByValue(obj: VReg, value: VReg, nameSetting: boolean) { +export function storeOwnByValue(obj: VReg, value: VReg, nameSetting: boolean): IRNode { return nameSetting ? new Stownbyvaluewithnameset(new Imm(0), obj, value) : new Stownbyvalue(new Imm(0), obj, value); } -export function throwIfSuperNotCorrectCall(num: number) { +export function throwIfSuperNotCorrectCall(num: number): IRNode { return new ThrowIfsupernotcorrectcall(new Imm(num)); } -export function call(args: VReg[], passThis: boolean) { +export function call(args: VReg[], passThis: boolean): IRNode { let length = args.length; let insn: IRNode; if (!passThis) { @@ -293,7 +293,7 @@ export function call(args: VReg[], passThis: boolean) { return insn; } -function callThis(args: Array) { +function callThis(args: Array): IRNode { let insn: IRNode; let thisReg: VReg = args[0]; let length = args.length; @@ -323,105 +323,105 @@ function callThis(args: Array) { return insn; } -export function newObject(args: VReg[]) { +export function newObject(args: VReg[]): IRNode { let length = args.length; return length <= MAX_INT8 ? new Newobjrange(new Imm(0), new Imm(length), args) : new WideNewobjrange(new Imm(length), args); } -export function getPropIterator() { +export function getPropIterator(): IRNode { return new Getpropiterator(); } -export function getNextPropName(iter: VReg) { +export function getNextPropName(iter: VReg): IRNode { return new Getnextpropname(iter); } -export function returnUndefined() { +export function returnUndefined(): IRNode { return new Returnundefined(); } -export function createEmptyObject() { +export function createEmptyObject(): IRNode { return new Createemptyobject(); } -export function createObjectWithBuffer(bufferId: string) { +export function createObjectWithBuffer(bufferId: string): IRNode { return new Createobjectwithbuffer(new Imm(0), bufferId); } -export function setObjectWithProto(proto: VReg) { +export function setObjectWithProto(proto: VReg): IRNode { return new Setobjectwithproto(new Imm(0), proto); } -export function copyDataProperties(dstObj: VReg) { +export function copyDataProperties(dstObj: VReg): IRNode { return new Copydataproperties(dstObj); } -export function defineGetterSetterByValue(obj: VReg, name: VReg, getter: VReg, setter: VReg) { +export function defineGetterSetterByValue(obj: VReg, name: VReg, getter: VReg, setter: VReg): IRNode { return new Definegettersetterbyvalue(obj, name, getter, setter); } -export function createEmptyArray() { +export function createEmptyArray(): IRNode { return new Createemptyarray(new Imm(0)); } -export function createArrayWithBuffer(bufferId: string) { +export function createArrayWithBuffer(bufferId: string): IRNode { return new Createarraywithbuffer(new Imm(0), bufferId); } -export function storeArraySpread(array: VReg, index: VReg) { +export function storeArraySpread(array: VReg, index: VReg): IRNode { return new Starrayspread(array, index); } -export function defineClassWithBuffer(id: string, litId: string, parameterLength: number, base: VReg) { +export function defineClassWithBuffer(id: string, litId: string, parameterLength: number, base: VReg): IRNode { return new Defineclasswithbuffer(new Imm(0), id, litId, new Imm(parameterLength), base); } -export function createObjectWithExcludedKeys(obj: VReg, args: VReg[]) { +export function createObjectWithExcludedKeys(obj: VReg, args: VReg[]): IRNode { let followedArgs = args.length - 1; return followedArgs <= MAX_INT8 ? new Createobjectwithexcludedkeys(new Imm(followedArgs), obj, args) : new WideCreateobjectwithexcludedkeys(new Imm(followedArgs), obj, args); } -export function throwObjectNonCoercible() { +export function throwObjectNonCoercible(): IRNode { return new ThrowPatternnoncoercible(); } -export function throwIfNotObject(v: VReg) { +export function throwIfNotObject(v: VReg): IRNode { return new ThrowIfnotobject(v); } -export function getIterator() { +export function getIterator(): IRNode { return new Getiterator(new Imm(0)); } -export function closeIterator(iter: VReg) { +export function closeIterator(iter: VReg): IRNode { return new Closeiterator(new Imm(0), iter); } -export function superCall(num: number, args: Array) { +export function superCall(num: number, args: Array): IRNode { return num <= MAX_INT8 ? new Supercallthisrange(new Imm(0), new Imm(num), args) : new WideSupercallthisrange(new Imm(num), args); } -export function superCallInArrow(num: number, args: Array) { +export function superCallInArrow(num: number, args: Array): IRNode { return num <= MAX_INT8 ? new Supercallarrowrange(new Imm(0), new Imm(num), args) : new WideSupercallarrowrange(new Imm(num), args); } -export function superCallSpread(vs: VReg) { +export function superCallSpread(vs: VReg): IRNode { return new Supercallspread(new Imm(0), vs); } -export function ldSuperByName(key: string) { +export function ldSuperByName(key: string): IRNode { return new Ldsuperbyname(new Imm(0), key); // obj is in acc } -export function stSuperByName(obj: VReg, key: string) { +export function stSuperByName(obj: VReg, key: string): IRNode { return new Stsuperbyname(new Imm(0), key, obj); } -export function stSuperByValue(obj: VReg, prop: VReg) { +export function stSuperByValue(obj: VReg, prop: VReg): IRNode { return new Stsuperbyvalue(new Imm(0), obj, prop); } @@ -429,11 +429,11 @@ export function ldSuperByValue(obj: VReg): IRNode { return new Ldsuperbyvalue(new Imm(0), obj); // prop is in acc } -export function loadLocalModuleVariable(index: number) { +export function loadLocalModuleVariable(index: number): IRNode { return index <= MAX_INT8 ? new Ldlocalmodulevar(new Imm(index)) : new WideLdlocalmodulevar(new Imm(index)); } -export function loadExternalModuleVariable(index: number) { +export function loadExternalModuleVariable(index: number): IRNode { return index <= MAX_INT8 ? new Ldexternalmodulevar(new Imm(index)) : new WideLdexternalmodulevar(new Imm(index)); } @@ -442,40 +442,40 @@ export function dynamicImport() { return new Dynamicimport(); } -export function storeModuleVariable(index: number) { +export function storeModuleVariable(index: number): IRNode { return index <= MAX_INT8 ? new Stmodulevar(new Imm(index)) : new WideStmodulevar(new Imm(index)); } -export function getModuleNamespace(moduleRequestIdx: number) { +export function getModuleNamespace(moduleRequestIdx: number): IRNode { return moduleRequestIdx <= MAX_INT8 ? new Getmodulenamespace(new Imm(moduleRequestIdx)) : new WideGetmodulenamespace(new Imm(moduleRequestIdx)); } -export function defineFunc(name: string, paramLength: number) { +export function defineFunc(name: string, paramLength: number): IRNode { return new Definefunc(new Imm(0), name, new Imm(paramLength)); } -export function defineMethod(name: string, paramLength: number) { +export function defineMethod(name: string, paramLength: number): IRNode { return new Definemethod(new Imm(0), name, new Imm(paramLength)); } -export function isTrue() { +export function isTrue(): IRNode { return new Istrue(); } -export function isFalse() { +export function isFalse(): IRNode { return new Isfalse(); } -export function createRegExpWithLiteral(pattern: string, flags: number) { +export function createRegExpWithLiteral(pattern: string, flags: number): IRNode { return new Createregexpwithliteral(new Imm(0), pattern, new Imm(flags)); } -export function stLetOrClassToGlobalRecord(name: string) { +export function stLetOrClassToGlobalRecord(name: string): IRNode { return new Sttoglobalrecord(new Imm(0), name); } -export function stConstToGlobalRecord(name: string) { +export function stConstToGlobalRecord(name: string): IRNode { return new Stconsttoglobalrecord(new Imm(0), name); } diff --git a/ts2panda/src/base/iterator.ts b/ts2panda/src/base/iterator.ts index 1eed765d3f815de023b4494f1591293a7b8d6495..8e899b59a5cf94d00ea68fdc44c329e914e99452 100644 --- a/ts2panda/src/base/iterator.ts +++ b/ts2panda/src/base/iterator.ts @@ -50,7 +50,7 @@ export class Iterator { } } - getIterator() { + getIterator(): void { let pandaGen = this.pandaGen; let iterator = this.iterRecord.iterator; @@ -67,7 +67,7 @@ export class Iterator { return this.iterRecord.nextMethod; } - getMethod(id: string) { + getMethod(id: string): void { this.pandaGen.loadObjProperty(this.node, this.iterRecord.iterator, id); this.pandaGen.storeAccumulator(this.node, this.iterRecord.nextMethod); } @@ -78,26 +78,26 @@ export class Iterator { * throw TypeError * } */ - callNext(iterResult: VReg) { + callNext(iterResult: VReg): void { this.pandaGen.call(this.node, [this.iterRecord.nextMethod, this.iterRecord.iterator], true); this.pandaGen.storeAccumulator(this.node, iterResult); } - callMethodwithValue(value: VReg) { + callMethodwithValue(value: VReg): void { this.pandaGen.call(this.node, [this.iterRecord.nextMethod, this.iterRecord.iterator, value], true); } - iteratorComplete(iterResult: VReg) { + iteratorComplete(iterResult: VReg): void { this.pandaGen.loadObjProperty(this.node, iterResult, "done"); this.pandaGen.storeAccumulator(this.node, this.iterDone); } - iteratorValue(iterResult: VReg) { + iteratorValue(iterResult: VReg): void { this.pandaGen.loadObjProperty(this.node, iterResult, "value"); this.pandaGen.storeAccumulator(this.node, this.iterValue); } - close() { + close(): void { let pg = this.pandaGen; if (this.kind == IteratorType.Normal) { pg.closeIterator(this.node, this.iterRecord.iterator); @@ -164,11 +164,11 @@ export class Iterator { pg.freeTemps(completion, res, exception) } - getCurrentValue() { + getCurrentValue(): VReg { return this.iterValue; } - getCurrrentDone() { + getCurrrentDone(): VReg { return this.iterDone; } } \ No newline at end of file diff --git a/ts2panda/src/base/literal.ts b/ts2panda/src/base/literal.ts index 2cfb24623694f2d639513a3d2b40c1ad4ee24fe8..eaf817abb720d62a39ad27ff2e8d3e29ae975ba6 100644 --- a/ts2panda/src/base/literal.ts +++ b/ts2panda/src/base/literal.ts @@ -39,11 +39,11 @@ export class Literal { this.v = v; } - getTag() { + getTag(): LiteralTag { return this.t; } - getValue() { + getValue(): any { return this.v; } } @@ -58,22 +58,22 @@ export class LiteralBuffer { this.lb.push(...literals); } - getLiterals() { + getLiterals(): Literal[] { return this.lb; } - isEmpty() { + isEmpty(): boolean { return this.lb.length == 0; } - getLiteral(index: number) { + getLiteral(index: number): Literal { if (index >= this.lb.length || this.lb.length <=0) { return ; } return this.lb[index]; } - setKey(key: string) { + setKey(key: string): void { this.k = key; } } diff --git a/ts2panda/src/base/lreference.ts b/ts2panda/src/base/lreference.ts index f51dc6f7748ada6c976bfe43a4d542dba3ce8004..4deb1597ddac761ecdcba69a5b4d0873ddc0a05a 100644 --- a/ts2panda/src/base/lreference.ts +++ b/ts2panda/src/base/lreference.ts @@ -59,7 +59,7 @@ export class LReference { } } - getValue() { + getValue(): void { let pandaGen = this.compiler.getPandaGen(); switch (this.refKind) { case ReferenceKind.MemberAccess: @@ -81,7 +81,7 @@ export class LReference { } } - setValue() { + setValue(): void { let pandaGen = this.compiler.getPandaGen(); switch (this.refKind) { case ReferenceKind.MemberAccess: { @@ -113,7 +113,7 @@ export class LReference { } } - setObjectAndProperty(pandaGen: PandaGen, obj: VReg, prop: VReg | number | string) { + setObjectAndProperty(pandaGen: PandaGen, obj: VReg, prop: VReg | number | string): void { if (!jshelpers.isSuperProperty(this.node)) { pandaGen.moveVreg(this.node, this.obj, obj); } diff --git a/ts2panda/src/base/properties.ts b/ts2panda/src/base/properties.ts index cd11acf7e4c1b6f0d0ae040d03163acf15a6df61..38c3dc89be5206f7ecda9ff205465c8b96513560 100644 --- a/ts2panda/src/base/properties.ts +++ b/ts2panda/src/base/properties.ts @@ -42,55 +42,55 @@ export class Property { } } - setCompiled() { + setCompiled(): void { this.compiled = true; } - setRedeclared() { + setRedeclared(): void { this.redeclared = true; } - isCompiled() { + isCompiled(): boolean { return this.compiled; } - isRedeclared() { + isRedeclared(): boolean { return this.redeclared; } - getName() { + getName(): string | number | ts.ComputedPropertyName { if (typeof (this.name) == 'undefined') { throw new Error("this property doesn't have a name"); } return this.name; } - getKind() { + getKind(): PropertyKind { return this.propKind; } - getValue() { + getValue(): ts.Node { if (this.propKind == PropertyKind.Accessor) { throw new Error("Accessor doesn't have valueNode") } return this.valueNode!; } - getGetter() { + getGetter(): ts.GetAccessorDeclaration { return this.getterNode; } - getSetter() { + getSetter(): ts.SetAccessorDeclaration { return this.setterNode; } - setValue(valueNode: ts.Node) { + setValue(valueNode: ts.Node): void { this.valueNode = valueNode; this.getterNode = undefined; this.setterNode = undefined; } - setGetter(getter: ts.GetAccessorDeclaration) { + setGetter(getter: ts.GetAccessorDeclaration): void { if (this.propKind != PropertyKind.Accessor) { this.valueNode = undefined; this.setterNode = undefined; @@ -99,7 +99,7 @@ export class Property { this.getterNode = getter; } - setSetter(setter: ts.SetAccessorDeclaration) { + setSetter(setter: ts.SetAccessorDeclaration): void { if (this.propKind != PropertyKind.Accessor) { this.valueNode = undefined; this.getterNode = undefined; @@ -108,7 +108,7 @@ export class Property { this.setterNode = setter; } - setKind(propKind: PropertyKind) { + setKind(propKind: PropertyKind): void { this.propKind = propKind; } } @@ -187,7 +187,7 @@ function defineProperty( propValue: ts.Node, propKind: PropertyKind, properties: Property[], - namedPropertyMap: Map) { + namedPropertyMap: Map): void { if (propKind == PropertyKind.Computed || propKind == PropertyKind.Spread) { let prop = new Property(propKind, propName); prop.setValue(propValue); @@ -244,14 +244,14 @@ export function isConstantExpr(node: ts.Node): boolean { } } -export function propertyKeyAsString(propName: string | number) { +export function propertyKeyAsString(propName: string | number): string { if (typeof (propName) == 'number') { return propName.toString(); } return propName; } -export function getPropName(propertyName: ts.PropertyName) { +export function getPropName(propertyName: ts.PropertyName): string | number | ts.ComputedPropertyName { if (ts.isComputedPropertyName(propertyName)) { return propertyName; } diff --git a/ts2panda/src/base/typeSystem.ts b/ts2panda/src/base/typeSystem.ts index 5c1cc93f53643ea4903fb597f912b087133cbd4a..f863546c2769f6b2f7b3021db39fe0c66b9c4fbc 100644 --- a/ts2panda/src/base/typeSystem.ts +++ b/ts2panda/src/base/typeSystem.ts @@ -169,23 +169,23 @@ export abstract class BaseType { } } - protected addCurrentType(node: ts.Node, index: number) { + protected addCurrentType(node: ts.Node, index: number): void { this.typeRecorder.addType2Index(node, index); } - protected setVariable2Type(variableNode: ts.Node, index: number) { + protected setVariable2Type(variableNode: ts.Node, index: number): void { this.typeRecorder.setVariable2Type(variableNode, index); } - protected tryGetTypeIndex(typeNode: ts.Node) { + protected tryGetTypeIndex(typeNode: ts.Node): number { return this.typeRecorder.tryGetTypeIndex(typeNode); } - protected getOrCreateRecordForDeclNode(typeNode: ts.Node, variableNode?: ts.Node) { + protected getOrCreateRecordForDeclNode(typeNode: ts.Node, variableNode?: ts.Node): PrimitiveType { return this.typeChecker.getOrCreateRecordForDeclNode(typeNode, variableNode); } - protected getOrCreateRecordForTypeNode(typeNode: ts.TypeNode | undefined, variableNode?: ts.Node) { + protected getOrCreateRecordForTypeNode(typeNode: ts.TypeNode | undefined, variableNode?: ts.Node): PrimitiveType { return this.typeChecker.getOrCreateRecordForTypeNode(typeNode, variableNode); } @@ -193,11 +193,11 @@ export abstract class BaseType { return PandaGen.appendTypeArrayBuffer(type); } - protected setTypeArrayBuffer(type: BaseType, index: number) { + protected setTypeArrayBuffer(type: BaseType, index: number): void { PandaGen.setTypeArrayBuffer(type, index); } - protected calculateIndex(builtinTypeIdx) { + protected calculateIndex(builtinTypeIdx): { typeIndex: number; shiftedTypeIndex: number; } { let typeIndex: number; let shiftedTypeIndex: number; let recordBuiltin = builtinTypeIdx && CmdOptions.needRecordBuiltinDtsType(); @@ -238,7 +238,7 @@ export class TypeSummary extends BaseType { } } - public setInfo(userDefinedClassNum: number, anonymousRedirect: Array) { + public setInfo(userDefinedClassNum: number, anonymousRedirect: Array): void { this.userDefinedClassNum = userDefinedClassNum; this.anonymousRedirect = anonymousRedirect; this.setTypeArrayBuffer(this, this.preservedIndex); @@ -308,7 +308,7 @@ export class ClassType extends BaseType { } } - private fillInModifiers(node: ts.ClassDeclaration | ts.ClassExpression) { + private fillInModifiers(node: ts.ClassDeclaration | ts.ClassExpression): void { if (node.modifiers) { for (let modifier of node.modifiers) { switch (modifier.kind) { @@ -324,7 +324,7 @@ export class ClassType extends BaseType { } } - private fillInHeritages(node: ts.ClassDeclaration | ts.ClassExpression) { + private fillInHeritages(node: ts.ClassDeclaration | ts.ClassExpression): void { if (node.heritageClauses) { for (let heritage of node.heritageClauses) { let heritageFullName = heritage.getText(); @@ -341,7 +341,7 @@ export class ClassType extends BaseType { } } - private fillInFields(member: ts.PropertyDeclaration) { + private fillInFields(member: ts.PropertyDeclaration): void { let fieldName = jshelpers.getTextOfIdentifierOrLiteral(member.name); let fieldInfo = Array(PrimitiveType.ANY, AccessFlag.PUBLIC, ModifierReadonly.NONREADONLY); let isStatic: boolean = false; @@ -385,7 +385,7 @@ export class ClassType extends BaseType { } } - private fillInMethods(member: ClassMemberFunction) { + private fillInMethods(member: ClassMemberFunction): void { /** * a method like declaration in a new class must be a new type, * create this type and add it into typeRecorder if it's not from tsc's library @@ -412,7 +412,7 @@ export class ClassType extends BaseType { } } - private fillInFieldsAndMethods(node: ts.ClassDeclaration | ts.ClassExpression) { + private fillInFieldsAndMethods(node: ts.ClassDeclaration | ts.ClassExpression): void { if (node.members) { for (let member of node.members) { switch (member.kind) { @@ -434,7 +434,7 @@ export class ClassType extends BaseType { } } - transfer2LiteralBuffer() { + transfer2LiteralBuffer(): LiteralBuffer { if (!this.typeIndex) { return; } @@ -462,7 +462,7 @@ export class ClassType extends BaseType { return classTypeBuf; } - private transferFields2Literal(classTypeLiterals: Array, isStatic: boolean) { + private transferFields2Literal(classTypeLiterals: Array, isStatic: boolean): void { let transferredTarget: Map> = isStatic ? this.staticFields : this.fields; classTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.size)); @@ -474,7 +474,7 @@ export class ClassType extends BaseType { }); } - private transferMethods2Literal(classTypeLiterals: Array, isStatic: boolean) { + private transferMethods2Literal(classTypeLiterals: Array, isStatic: boolean): void { let transferredTarget: Map = isStatic ? this.staticMethods : this.methods; classTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.size)); @@ -547,11 +547,11 @@ export class FunctionType extends BaseType { this.setTypeArrayBuffer(this, this.typeIndex); } - public getFunctionName() { + public getFunctionName(): string { return this.name; } - private fillInModifiers(node: ts.FunctionLikeDeclaration | ts.MethodSignature) { + private fillInModifiers(node: ts.FunctionLikeDeclaration | ts.MethodSignature): void { if (node.modifiers) { for (let modifier of node.modifiers) { switch (modifier.kind) { @@ -586,7 +586,7 @@ export class FunctionType extends BaseType { } } - private fillInParameters(node: ts.FunctionLikeDeclaration | ts.MethodSignature) { + private fillInParameters(node: ts.FunctionLikeDeclaration | ts.MethodSignature): void { if (node.parameters) { for (let parameter of node.parameters) { let typeNode = parameter.type; @@ -600,17 +600,17 @@ export class FunctionType extends BaseType { } } - private fillInReturn(node: ts.FunctionLikeDeclaration | ts.MethodSignature) { + private fillInReturn(node: ts.FunctionLikeDeclaration | ts.MethodSignature): void { let typeNode = node.type; let typeIndex = this.getOrCreateRecordForTypeNode(typeNode, typeNode); this.returnType = typeIndex; } - getModifier() { + getModifier(): number { return this.modifiers; } - hasModifier(modifier: MethodModifier) { + hasModifier(modifier: MethodModifier): boolean { return (this.modifiers & modifier) ? true : false; } @@ -673,7 +673,7 @@ export class UnionType extends BaseType { this.setOrReadFromArrayRecord(typeNode); } - setOrReadFromArrayRecord(typeNode: ts.Node) { + setOrReadFromArrayRecord(typeNode: ts.Node): void { let unionStr = typeNode.getText(); if (this.hasUnionTypeMapping(unionStr)) { this.shiftedTypeIndex = this.getFromUnionTypeMap(unionStr)!; @@ -686,19 +686,19 @@ export class UnionType extends BaseType { this.setTypeArrayBuffer(this, this.typeIndex); } - hasUnionTypeMapping(unionStr: string) { + hasUnionTypeMapping(unionStr: string): boolean { return this.typeRecorder.hasUnionTypeMapping(unionStr); } - getFromUnionTypeMap(unionStr: string) { + getFromUnionTypeMap(unionStr: string): number { return this.typeRecorder.getFromUnionTypeMap(unionStr); } - setUnionTypeMap(unionStr: string, shiftedTypeIndex: number) { + setUnionTypeMap(unionStr: string, shiftedTypeIndex: number): void { return this.typeRecorder.setUnionTypeMap(unionStr, shiftedTypeIndex); } - fillInUnionArray(typeNode: ts.Node, unionedTypeArray: Array) { + fillInUnionArray(typeNode: ts.Node, unionedTypeArray: Array): void { for (let element of (typeNode).types) { let elementNode = element; let typeIndex = this.getOrCreateRecordForTypeNode(elementNode, elementNode); @@ -730,7 +730,7 @@ export class ArrayType extends BaseType { this.setOrReadFromArrayRecord(); } - setOrReadFromArrayRecord() { + setOrReadFromArrayRecord(): void { if (this.hasArrayTypeMapping(this.referedTypeIndex)) { this.shiftedTypeIndex = this.getFromArrayTypeMap(this.referedTypeIndex)!; } else { @@ -741,15 +741,15 @@ export class ArrayType extends BaseType { } } - hasArrayTypeMapping(referedTypeIndex: number) { + hasArrayTypeMapping(referedTypeIndex: number): boolean { return this.typeRecorder.hasArrayTypeMapping(referedTypeIndex); } - getFromArrayTypeMap(referedTypeIndex: number) { + getFromArrayTypeMap(referedTypeIndex: number): number { return this.typeRecorder.getFromArrayTypeMap(referedTypeIndex); } - setArrayTypeMap(referedTypeIndex: number, shiftedTypeIndex: number) { + setArrayTypeMap(referedTypeIndex: number, shiftedTypeIndex: number): void { return this.typeRecorder.setArrayTypeMap(referedTypeIndex, shiftedTypeIndex); } @@ -776,7 +776,7 @@ export class ObjectType extends BaseType { this.setTypeArrayBuffer(this, this.typeIndex); } - fillInMembers(objNode: ts.TypeLiteralNode) { + fillInMembers(objNode: ts.TypeLiteralNode): void { for (let member of objNode.members) { let propertySig = member; let name = member.name ? member.name.getText() : "#undefined"; @@ -819,7 +819,7 @@ export class InterfaceType extends BaseType { this.setTypeArrayBuffer(this, this.typeIndex); } - private fillInHeritages(node: ts.InterfaceDeclaration) { + private fillInHeritages(node: ts.InterfaceDeclaration): void { if (node.heritageClauses) { for (let heritage of node.heritageClauses) { for (let heritageType of heritage.types) { @@ -831,7 +831,7 @@ export class InterfaceType extends BaseType { } } - private fillInFields(member: ts.PropertySignature) { + private fillInFields(member: ts.PropertySignature): void { let fieldName = jshelpers.getTextOfIdentifierOrLiteral(member.name); let fieldInfo = Array(PrimitiveType.ANY, AccessFlag.PUBLIC, ModifierReadonly.NONREADONLY); if (member.modifiers) { @@ -860,7 +860,7 @@ export class InterfaceType extends BaseType { this.fields.set(fieldName, fieldInfo); } - private fillInMethods(member: ts.MethodSignature) { + private fillInMethods(member: ts.MethodSignature): void { /** * a method like declaration in a new class must be a new type, * create this type and add it into typeRecorder if it's not from tsc's library @@ -878,7 +878,7 @@ export class InterfaceType extends BaseType { this.methods.push(typeIndex!); } - private fillInFieldsAndMethods(node: ts.InterfaceDeclaration) { + private fillInFieldsAndMethods(node: ts.InterfaceDeclaration): void { if (node.members) { for (let member of node.members) { switch (member.kind) { @@ -897,7 +897,7 @@ export class InterfaceType extends BaseType { } } - transfer2LiteralBuffer() { + transfer2LiteralBuffer(): LiteralBuffer { let interfaceTypeBuf = new LiteralBuffer(); let interfaceTypeLiterals: Array = new Array(); // the first element is to determine the L2 type @@ -916,7 +916,7 @@ export class InterfaceType extends BaseType { return interfaceTypeBuf; } - private transferFields2Literal(interfaceTypeLiterals: Array) { + private transferFields2Literal(interfaceTypeLiterals: Array): void { let transferredTarget: Map> = this.fields; interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.size)); @@ -928,7 +928,7 @@ export class InterfaceType extends BaseType { }); } - private transferMethods2Literal(interfaceTypeLiterals: Array) { + private transferMethods2Literal(interfaceTypeLiterals: Array): void { let transferredTarget: Array = this.methods; interfaceTypeLiterals.push(new Literal(LiteralTag.INTEGER, transferredTarget.length)); @@ -953,7 +953,7 @@ export class BuiltinContainerType extends BaseType { this.setBuiltinContainer2InstanceMap(builtinContainerSignature, this.shiftedTypeIndex); } - setBuiltinContainer2InstanceMap(builtinContainerSignature: object, index: number) { + setBuiltinContainer2InstanceMap(builtinContainerSignature: object, index: number): void { return this.typeRecorder.setBuiltinContainer2InstanceMap(builtinContainerSignature, index); } diff --git a/ts2panda/src/base/util.ts b/ts2panda/src/base/util.ts index 24bd25e9a95cce0259a850dfee3faf6802983472..711f26befd4bd475a1d740f56b6d6b6a6f694bce 100644 --- a/ts2panda/src/base/util.ts +++ b/ts2panda/src/base/util.ts @@ -77,7 +77,7 @@ export function hasDefaultKeywordModifier(node: ts.Node): boolean { return hasDefault; } -export function execute(cmd: string, args: Array) { +export function execute(cmd: string, args: Array): number { var spawn = require('child_process').spawn; let child = spawn(cmd, [...args], { @@ -96,7 +96,7 @@ export function execute(cmd: string, args: Array) { return 1; } -export function addUnicodeEscape(text: string) { +export function addUnicodeEscape(text: string): string { let firstIdx = 0; let secondIdx = 0; let len = text.length; @@ -122,23 +122,23 @@ export function addUnicodeEscape(text: string) { return newText; } -export function isBindingPattern(node: ts.Node) { +export function isBindingPattern(node: ts.Node): boolean { return ts.isArrayBindingPattern(node) || ts.isObjectBindingPattern(node); } -export function isObjectBindingOrAssignmentPattern(node: ts.Node) { +export function isObjectBindingOrAssignmentPattern(node: ts.Node): boolean { return ts.isObjectLiteralExpression(node) || ts.isObjectBindingPattern(node); } -export function isArrayBindingOrAssignmentPattern(node: ts.Node) { +export function isArrayBindingOrAssignmentPattern(node: ts.Node): boolean { return ts.isArrayLiteralExpression(node) || ts.isArrayBindingPattern(node); } -export function isBindingOrAssignmentPattern(node: ts.Node) { +export function isBindingOrAssignmentPattern(node: ts.Node): boolean { return isArrayBindingOrAssignmentPattern(node) || isObjectBindingOrAssignmentPattern(node); } -export function isMemberExpression(node: ts.Node) { +export function isMemberExpression(node: ts.Node): boolean { if (ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) { return true; @@ -147,7 +147,7 @@ export function isMemberExpression(node: ts.Node) { return false; } -export function isUndefinedIdentifier(node: ts.Node) { +export function isUndefinedIdentifier(node: ts.Node): boolean { if (!ts.isIdentifier(node)) { return false; } @@ -159,7 +159,7 @@ export function isUndefinedIdentifier(node: ts.Node) { return true; } -export function isAnonymousFunctionDefinition(node: ts.Node) { +export function isAnonymousFunctionDefinition(node: ts.Node): boolean { if (!isFunctionLikeDeclaration(node)) { return false; } @@ -171,7 +171,7 @@ export function isAnonymousFunctionDefinition(node: ts.Node) { } } -export function escapeUnicode(data: string) { +export function escapeUnicode(data: string): string { let char = '\n'; let i = 0; let j = 0; @@ -189,7 +189,7 @@ export function escapeUnicode(data: string) { return new_data } -export function initiateTs2abc(args: Array) { +export function initiateTs2abc(args: Array): any { let js2abc = path.join(path.resolve(__dirname, '../bin'), "js2abc"); args.unshift("--compile-by-pipe"); // @ts-ignore @@ -201,7 +201,7 @@ export function initiateTs2abc(args: Array) { return child; } -export function terminateWritePipe(ts2abc: any) { +export function terminateWritePipe(ts2abc: any): void { if (!ts2abc) { LOGD("ts2abc is not a valid object"); } @@ -209,7 +209,7 @@ export function terminateWritePipe(ts2abc: any) { ts2abc.stdio[3].end(); } -export function listenChildExit(child: any) { +export function listenChildExit(child: any): void { if (!child) { LOGD("child is not a valid object"); } @@ -222,7 +222,7 @@ export function listenChildExit(child: any) { }); } -export function listenErrorEvent(child: any) { +export function listenErrorEvent(child: any): void { if (!child) { LOGD("child is not a valid object"); } @@ -232,7 +232,7 @@ export function listenErrorEvent(child: any) { }); } -export function isRangeInst(ins: IRNode) { +export function isRangeInst(ins: IRNode): boolean { if (ins instanceof Callthisrange || ins instanceof WideCallthisrange || ins instanceof Callrange || @@ -281,11 +281,11 @@ export function getRangeExplicitVregNums(ins: IRNode): number { return ins instanceof Createobjectwithexcludedkeys ? 2 : 1; } -export function isRestParameter(parameter: ts.ParameterDeclaration) { +export function isRestParameter(parameter: ts.ParameterDeclaration): boolean { return parameter.dotDotDotToken ? true : false; } -export function getParamLengthOfFunc(node: ts.FunctionLikeDeclaration) { +export function getParamLengthOfFunc(node: ts.FunctionLikeDeclaration): number { let length = 0; let validLengthRange = true; let parameters = node.parameters; @@ -304,7 +304,7 @@ export function getParamLengthOfFunc(node: ts.FunctionLikeDeclaration) { return length; } -export function getParameterLength4Ctor(node: ts.ClassLikeDeclaration) { +export function getParameterLength4Ctor(node: ts.ClassLikeDeclaration): number { if (!extractCtorOfClass(node)) { return 0; } @@ -321,7 +321,7 @@ export function getParameterLength4Ctor(node: ts.ClassLikeDeclaration) { return getParamLengthOfFunc(ctorNode!); } -export function setPos(node: ts.Node) { +export function setPos(node: ts.Node): ts.Node { ts.setTextRange(node, {pos:-1, end:-1}); node.forEachChild(childNode => { setPos(childNode); @@ -329,7 +329,7 @@ export function setPos(node: ts.Node) { return node; } -export function getRecordTypeFlag(recordType: boolean) { +export function getRecordTypeFlag(recordType: boolean): boolean { return recordType && CmdOptions.needRecordType() && CompilerDriver.isTsFile; } @@ -340,7 +340,7 @@ export function isBase64Str(input: string): boolean { return Buffer.from(Buffer.from(input, 'base64').toString()).toString('base64') == input; } -export function transformCommonjsModule(sourceFile: ts.SourceFile) { +export function transformCommonjsModule(sourceFile: ts.SourceFile): ts.SourceFile { /* * Transform the commonjs module's AST by wrap the sourceCode & use Reflect.apply to invoke this wrapper with [this] * pointing to [exports] object @@ -402,7 +402,7 @@ export function hasAbstractModifier(node: ts.Node): boolean { export const MAX_INT8 = 127; export const MAX_INT16 = 32767; -export function getOutputBinName(node: ts.SourceFile) { +export function getOutputBinName(node: ts.SourceFile): string { let outputBinName = CmdOptions.getOutputBinName(); let fileName = node.fileName.substring(0, node.fileName.lastIndexOf('.')); let inputFileName = CmdOptions.getInputFileName(); @@ -437,7 +437,7 @@ export function getLiteralKey(node: ts.SourceFile, idx:number): string { */ function getNodeForGeneratedName( // @ts-ignore - name: ts.GeneratedIdentifier) { + name: ts.GeneratedIdentifier): ts.Node { const autoGenerateId = name.autoGenerateId; let node = name as ts.Node; // @ts-ignore @@ -501,11 +501,11 @@ function generateNameForTempAndLoopVariable(node: ts.Node): string { return generatedName; } -export function resetUniqueNameIndex() { +export function resetUniqueNameIndex(): void { uniqueNameIndex = 0; } -export function makeNameForGeneratedNode(node: ts.Node) { +export function makeNameForGeneratedNode(node: ts.Node): void { node.forEachChild(childNode => { switch (childNode.kind) { case ts.SyntaxKind.Identifier: { diff --git a/ts2panda/src/base/vregisterCache.ts b/ts2panda/src/base/vregisterCache.ts index 4bbb061f742c8ecf6d4253e1b36814e94a14237c..67a270ac9f199fe2ea96b0353defccaf0bddedb5 100644 --- a/ts2panda/src/base/vregisterCache.ts +++ b/ts2panda/src/base/vregisterCache.ts @@ -70,7 +70,7 @@ class CacheItem { private flag: boolean; private vreg: VReg | undefined; private expander: Function; - isNeeded() { + isNeeded(): boolean { return this.flag; } getCache(): VReg { @@ -80,7 +80,7 @@ class CacheItem { } return this.vreg; } - getExpander() { + getExpander(): Function { return this.expander; } } @@ -96,7 +96,7 @@ export class VregisterCache { this.cache[i] = new CacheItem(handler); } } - getCache(index: CacheList) { + getCache(index: CacheList): CacheItem { if (index < CacheList.MIN || index > CacheList.MAX) { throw new Error("invalid builtin index"); } @@ -104,7 +104,7 @@ export class VregisterCache { } } -export function getVregisterCache(pandaGen: PandaGen, index: CacheList) { +export function getVregisterCache(pandaGen: PandaGen, index: CacheList): VReg { let cache = pandaGen.getVregisterCache(); let cacheItem = cache.getCache(index); diff --git a/ts2panda/src/cmdOptions.ts b/ts2panda/src/cmdOptions.ts index ff02ad83b28dcce341b9126eb024f3734da9b7d7..510f80f4fcf8172d738bf6d75f28e961a06da15d 100644 --- a/ts2panda/src/cmdOptions.ts +++ b/ts2panda/src/cmdOptions.ts @@ -93,7 +93,7 @@ export class CmdOptions { return this.options["debug"]; } - static setWatchEvaluateExpressionArgs(watchArgs: string[]) { + static setWatchEvaluateExpressionArgs(watchArgs: string[]): void { this.options["debug-add-watch"] = watchArgs; } diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index 4818a0fd771cee14fc0bef2ed1999c23ae0a81d5..91d69f2796c50003dafdf797656fd69ecbce589c 100644 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -159,7 +159,7 @@ export class Compiler { this.pandaGen.loadAccFromArgs(this.rootNode); } - compile() { + compile(): void { this.storeFuncObj2LexEnvIfNeeded(); this.compileLexicalBindingForArrowFunction(); @@ -170,19 +170,19 @@ export class Compiler { } } - pushEnv(env: VReg) { + pushEnv(env: VReg): void { this.envUnion.push(env); } - popEnv() { + popEnv(): void { this.envUnion.pop(); } - getCurrentEnv() { + getCurrentEnv(): VReg { return this.envUnion[this.envUnion.length - 1]; } - private storeFuncObj2LexEnvIfNeeded() { + private storeFuncObj2LexEnvIfNeeded(): void { let rootNode = this.rootNode; if (!ts.isFunctionExpression(rootNode) && !ts.isMethodDeclaration(rootNode)) { return; @@ -199,7 +199,7 @@ export class Compiler { } } - private compileLexicalBindingForArrowFunction() { + private compileLexicalBindingForArrowFunction(): void { let rootNode = this.rootNode; if (ts.isArrowFunction(rootNode)) { return; @@ -215,7 +215,7 @@ export class Compiler { } } - private storeMandatoryArgToLexEnv(arg: string) { + private storeMandatoryArgToLexEnv(arg: string): void { let v = this.scope.findLocal(arg); if (!v) { throw new Error("Mandatory Arguments should be found locally"); @@ -229,7 +229,7 @@ export class Compiler { this.pandaGen.storeLexicalVar(this.rootNode, 0, v.lexIndex(), vreg); } - private compileSourceFileOrBlock(body: ts.SourceFile | ts.Block) { + private compileSourceFileOrBlock(body: ts.SourceFile | ts.Block): void { let statements = body.statements; let unreachableFlag = false; @@ -381,7 +381,7 @@ export class Compiler { } - compileStatement(stmt: ts.Statement) { + compileStatement(stmt: ts.Statement): void { // for debug info this.pandaGen.setFirstStmt(stmt); @@ -464,7 +464,7 @@ export class Compiler { } } - private compileBlock(block: ts.Block) { + private compileBlock(block: ts.Block): void { this.pushScope(block); hoistFunctionInBlock(this.scope, this.pandaGen, isStrictMode(block), this); @@ -473,14 +473,14 @@ export class Compiler { this.popScope(); } - private compileVariableStatement(stmt: ts.VariableStatement) { + private compileVariableStatement(stmt: ts.VariableStatement): void { let declList = stmt.declarationList; declList.declarations.forEach((decl) => { this.compileVariableDeclaration(decl) }); } - compileVariableDeclaration(decl: ts.VariableDeclaration) { + compileVariableDeclaration(decl: ts.VariableDeclaration): void { let lref = LReference.generateLReference(this, decl.name, true); if (decl.initializer) { this.compileExpression(decl.initializer); @@ -498,7 +498,7 @@ export class Compiler { lref.setValue(); } - private compileIfStatement(stmt: ts.IfStatement) { + private compileIfStatement(stmt: ts.IfStatement): void { this.pushScope(stmt); let ifElseLabel = new Label(); let ifEndLabel = new Label(); @@ -514,13 +514,13 @@ export class Compiler { this.popScope(); } - private popLoopEnv(node: ts.Node, times: number) { + private popLoopEnv(node: ts.Node, times: number): void { while(times--) { this.pandaGen.popLexicalEnv(node); } } - private popLoopEnvWhenContinueOrBreak(labelTarget: LabelTarget, isContinue: boolean) { + private popLoopEnvWhenContinueOrBreak(labelTarget: LabelTarget, isContinue: boolean): void { let node: ts.Node = labelTarget.getCorrespondingNode(); let loopEnvLevel = labelTarget.getLoopEnvLevel(); switch (node.kind) { @@ -553,7 +553,7 @@ export class Compiler { } } - private compileContinueStatement(stmt: ts.ContinueStatement) { + private compileContinueStatement(stmt: ts.ContinueStatement): void { let continueLabelTarget = LabelTarget.getLabelTarget(stmt); this.compileFinallyBeforeCFC( @@ -570,7 +570,7 @@ export class Compiler { this.pandaGen.branch(stmt, continueLabelTarget.getContinueTargetLabel()!); } - private compileBreakStatement(stmt: ts.BreakStatement) { + private compileBreakStatement(stmt: ts.BreakStatement): void { let breakLabelTarget = LabelTarget.getLabelTarget(stmt); this.compileFinallyBeforeCFC( @@ -587,7 +587,7 @@ export class Compiler { this.pandaGen.branch(stmt, breakLabelTarget.getBreakTargetLabel()); } - private compileLabeledStatement(stmt: ts.LabeledStatement) { + private compileLabeledStatement(stmt: ts.LabeledStatement): void { this.pushScope(stmt); let labelName: string = jshelpers.getTextOfIdentifierOrLiteral(stmt.label); let blockEndLabel = undefined; @@ -612,7 +612,7 @@ export class Compiler { this.popScope(); } - private compileThrowStatement(stmt: ts.ThrowStatement) { + private compileThrowStatement(stmt: ts.ThrowStatement): void { let pandaGen = this.pandaGen; if (stmt.expression) { this.compileExpression(stmt.expression); @@ -627,7 +627,7 @@ export class Compiler { pandaGen.throw(stmt); } - compileFinallyBeforeCFC(endTry: TryStatement | undefined, cfc: ControlFlowChange, continueTargetLabel: Label | undefined) {// compile finally before control flow change + compileFinallyBeforeCFC(endTry: TryStatement | undefined, cfc: ControlFlowChange, continueTargetLabel: Label | undefined): void {// compile finally before control flow change let startTry = TryStatement.getCurrentTryStatement(); let originTry = startTry; let currentScope = this.scope; @@ -673,7 +673,7 @@ export class Compiler { this.scope = currentScope; } - constructTry(node: ts.Node, tryBuilder: TryBuilderBase, endLabel?: Label) { + constructTry(node: ts.Node, tryBuilder: TryBuilderBase, endLabel?: Label): void { let pandaGen = this.pandaGen; let tryBeginLabel = new Label(); let tryEndLabel = new Label(); @@ -709,7 +709,7 @@ export class Compiler { } } - private compileTryStatement(stmt: ts.TryStatement) { + private compileTryStatement(stmt: ts.TryStatement): void { this.pushScope(stmt); // try-catch-finally statements must have been transformed into // two nested try statements with only "catch" or "finally" each. @@ -722,7 +722,7 @@ export class Compiler { this.popScope(); } - private compileFunctionDeclaration(decl: ts.FunctionDeclaration) { + private compileFunctionDeclaration(decl: ts.FunctionDeclaration): void { if (!decl.name) { if (hasExportKeywordModifier(decl) && this.scope instanceof ModuleScope) { return; @@ -731,13 +731,13 @@ export class Compiler { } } - private compileExportAssignment(stmt: ts.ExportAssignment) { + private compileExportAssignment(stmt: ts.ExportAssignment): void { this.compileExpression(stmt.expression); let defaultV: ModuleVariable = (this.pandaGen.getScope().findLocal("*default*")); this.pandaGen.storeModuleVariable(stmt, defaultV); } - compileCondition(expr: ts.Expression, ifFalseLabel: Label) { + compileCondition(expr: ts.Expression, ifFalseLabel: Label): void { let pandaGen = this.pandaGen; if (expr.kind == ts.SyntaxKind.BinaryExpression) { let binExpr = expr; @@ -790,7 +790,7 @@ export class Compiler { pandaGen.jumpIfFalse(expr, ifFalseLabel); } - compileExpression(expr: ts.Expression) { + compileExpression(expr: ts.Expression): void { // Please keep order of cases the same as in types.ts LOGD(this.debugTag, "compile expr: " + ts.SyntaxKind[expr.kind] + " " + expr.kind); switch (expr.kind) { @@ -903,7 +903,7 @@ export class Compiler { } } - private compileIdentifier(id: ts.Identifier) { + private compileIdentifier(id: ts.Identifier): void { let name = jshelpers.getTextOfIdentifierOrLiteral(id); let { scope, level, v } = this.scope.find(name); if (!v) { @@ -915,7 +915,7 @@ export class Compiler { } } - private compileUnscopedIdentifier(id: ts.Identifier) { + private compileUnscopedIdentifier(id: ts.Identifier): void { let name = jshelpers.getTextOfIdentifierOrLiteral(id); let pandaGen = this.pandaGen; switch (name) { @@ -947,7 +947,7 @@ export class Compiler { } } - private compileBooleanLiteral(lit: ts.BooleanLiteral) { + private compileBooleanLiteral(lit: ts.BooleanLiteral): void { if (lit.kind == ts.SyntaxKind.TrueKeyword) { this.pandaGen.loadAccumulator(lit, getVregisterCache(this.pandaGen, CacheList.True)); } else { @@ -977,7 +977,7 @@ export class Compiler { return false; } - private compileThisKeyword(node: ts.Node) { + private compileThisKeyword(node: ts.Node): void { let pandaGen = this.pandaGen; checkValidUseSuperBeforeSuper(this, node); @@ -1001,12 +1001,12 @@ export class Compiler { throw new Error("\"this\" must be a local variable"); } - private compileFunctionExpression(expr: ts.FunctionExpression) { + private compileFunctionExpression(expr: ts.FunctionExpression): void { let internalName = this.compilerDriver.getFuncInternalName(expr, this.recorder); this.pandaGen.defineFunction(expr, expr, internalName); } - private compileDeleteExpression(expr: ts.DeleteExpression) { + private compileDeleteExpression(expr: ts.DeleteExpression): void { let pandaGen = this.pandaGen; let objReg: VReg; let propReg: VReg; @@ -1067,13 +1067,13 @@ export class Compiler { } } - private compileTypeOfExpression(expr: ts.TypeOfExpression) { + private compileTypeOfExpression(expr: ts.TypeOfExpression): void { // expr -> acc this.compileExpression(expr.expression); this.pandaGen.typeOf(expr); } - private compileVoidExpression(expr: ts.VoidExpression) { + private compileVoidExpression(expr: ts.VoidExpression): void { let pandaGen = this.pandaGen; // compileExpression() must be called even though its value is not used // because it may have observable sideeffects. @@ -1081,7 +1081,7 @@ export class Compiler { pandaGen.loadAccumulator(expr, getVregisterCache(pandaGen, CacheList.undefined)); } - private compileAwaitExpression(expr: ts.AwaitExpression) { + private compileAwaitExpression(expr: ts.AwaitExpression): void { let pandaGen = this.pandaGen; if (!(this.funcBuilder instanceof AsyncFunctionBuilder || this.funcBuilder instanceof AsyncGeneratorFunctionBuilder)) { @@ -1097,7 +1097,7 @@ export class Compiler { } } - private compilePrefixUnaryExpression(expr: ts.PrefixUnaryExpression) { + private compilePrefixUnaryExpression(expr: ts.PrefixUnaryExpression): void { let pandaGen = this.pandaGen; let operandReg = pandaGen.getTemp(); // acc -> op(acc) @@ -1127,7 +1127,7 @@ export class Compiler { pandaGen.freeTemps(operandReg); } - private compilePostfixUnaryExpression(expr: ts.PostfixUnaryExpression) { + private compilePostfixUnaryExpression(expr: ts.PostfixUnaryExpression): void { let pandaGen = this.pandaGen; let operandReg = pandaGen.getTemp(); // expr -> acc @@ -1151,7 +1151,7 @@ export class Compiler { pandaGen.freeTemps(operandReg); } - private compileLogicalExpression(expr: ts.BinaryExpression) { + private compileLogicalExpression(expr: ts.BinaryExpression): void { let pandaGen = this.pandaGen; let lhs = pandaGen.getTemp(); switch (expr.operatorToken.kind) { @@ -1218,7 +1218,7 @@ export class Compiler { pandaGen.freeTemps(lhs); } - private compileBinaryExpression(expr: ts.BinaryExpression) { + private compileBinaryExpression(expr: ts.BinaryExpression): void { if (isAssignmentOperator(expr.operatorToken.kind)) { this.compileAssignmentExpression(expr.left, expr.right, expr.operatorToken.kind); return; @@ -1244,7 +1244,7 @@ export class Compiler { pandaGen.freeTemps(lhs); } - private compileConditionalExpression(expr: ts.ConditionalExpression) { + private compileConditionalExpression(expr: ts.ConditionalExpression): void { let falseLabel = new Label(); let endLabel = new Label(); @@ -1256,12 +1256,12 @@ export class Compiler { this.pandaGen.label(expr, endLabel); } - private compileArrowFunction(expr: ts.ArrowFunction) { + private compileArrowFunction(expr: ts.ArrowFunction): void { let internalName = this.compilerDriver.getFuncInternalName(expr, this.recorder); this.pandaGen.defineFunction(expr, expr, internalName); } - private compileTemplateSpan(expr: ts.TemplateSpan) { + private compileTemplateSpan(expr: ts.TemplateSpan): void { let span = expr.expression; this.compileExpression(span); let literal = expr.literal; @@ -1277,7 +1277,7 @@ export class Compiler { this.pandaGen.freeTemps(lrh); } - private compileTemplateExpression(expr: ts.TemplateExpression) { + private compileTemplateExpression(expr: ts.TemplateExpression): void { let pandaGen = this.pandaGen; let head = expr.head; let spans = expr.templateSpans; @@ -1296,12 +1296,12 @@ export class Compiler { pandaGen.freeTemps(lrh); } - private compileNoSubstitutionTemplateLiteral(expr: ts.NoSubstitutionTemplateLiteral) { + private compileNoSubstitutionTemplateLiteral(expr: ts.NoSubstitutionTemplateLiteral): void { let text = expr.text; this.pandaGen.loadAccumulatorString(expr, text); } - private compileTaggedTemplateExpression(expr: ts.TaggedTemplateExpression) { + private compileTaggedTemplateExpression(expr: ts.TaggedTemplateExpression): void { let pandaGen = this.pandaGen; let spans = undefined; if (ts.isTemplateExpression(expr.template)) { @@ -1329,7 +1329,7 @@ export class Compiler { return; } - private compileAssignmentExpression(lhs: ts.Expression, rhs: ts.Expression, operator: AssignmentOperator) { + private compileAssignmentExpression(lhs: ts.Expression, rhs: ts.Expression, operator: AssignmentOperator): void { let lref = LReference.generateLReference(this, lhs, false); if (operator != ts.SyntaxKind.EqualsToken) { @@ -1347,14 +1347,14 @@ export class Compiler { lref.setValue(); } - pushScope(node: ts.Node) { + pushScope(node: ts.Node): void { let scope = this.recorder.getScopeOfNode(node); this.scope = scope; // for debug info DebugInfo.addDebugIns(scope, this.pandaGen, true); } - popScope() { + popScope(): void { // for debug info DebugInfo.addDebugIns(this.scope, this.pandaGen, false); this.scope = this.scope.getParent(); @@ -1364,7 +1364,7 @@ export class Compiler { return ts.SyntaxKind[node.kind]; } - getThis(node: ts.Node, res: VReg) { + getThis(node: ts.Node, res: VReg): void { let pandaGen = this.pandaGen; let thisInfo = this.getCurrentScope().find(MandatoryThis); let level = thisInfo.level; @@ -1379,7 +1379,7 @@ export class Compiler { } } - setThis(node: ts.Node) { + setThis(node: ts.Node): void { let pandaGen = this.pandaGen; let thisInfo = this.getCurrentScope().find(MandatoryThis); @@ -1394,29 +1394,29 @@ export class Compiler { } } - getPandaGen() { + getPandaGen(): PandaGen { return this.pandaGen; } - getCurrentScope() { + getCurrentScope(): Scope { return this.scope; } - getCompilerDriver() { + getCompilerDriver(): CompilerDriver { return this.compilerDriver; } - getRecorder() { + getRecorder(): Recorder { return this.recorder; } - getFuncBuilder() { + getFuncBuilder(): FunctionBuilder { return this.funcBuilder; } storeTarget(node: ts.Node, variable: { scope: Scope | undefined, level: number, v: Variable | undefined }, - isDeclaration: boolean) { + isDeclaration: boolean): void { if (variable.v instanceof LocalVariable) { if (isDeclaration && variable.v.isLetOrConst()) { variable.v.initialize(); @@ -1472,7 +1472,7 @@ export class Compiler { } } - loadTarget(node: ts.Node, variable: { scope: Scope | undefined, level: number, v: Variable | undefined }) { + loadTarget(node: ts.Node, variable: { scope: Scope | undefined, level: number, v: Variable | undefined }): void { if (variable.v instanceof LocalVariable) { if (!CmdOptions.isCommonJs() && (variable.v.isLetOrConst() || variable.v.isClass())) { if (variable.scope instanceof GlobalScope) { diff --git a/ts2panda/src/compilerDriver.ts b/ts2panda/src/compilerDriver.ts index ca2e9f1f622909742de8f667ce63683fb90698c8..c58f06c68795dcf0c9397b93eab2f8a30cdabba2 100644 --- a/ts2panda/src/compilerDriver.ts +++ b/ts2panda/src/compilerDriver.ts @@ -95,7 +95,7 @@ export class CompilerDriver { } } - initiateTs2abcChildProcess(args: Array) { + initiateTs2abcChildProcess(args: Array): void { this.ts2abcProcess = initiateTs2abc(args); listenChildExit(this.getTs2abcProcess()); listenErrorEvent(this.getTs2abcProcess()); @@ -108,11 +108,11 @@ export class CompilerDriver { return this.ts2abcProcess; } - getStatistics() { + getStatistics(): CompilerStatistics { return this.statistics; } - setCustomPasses(passes: Pass[]) { + setCustomPasses(passes: Pass[]): void { this.passes = passes; } @@ -124,15 +124,15 @@ export class CompilerDriver { return internalName; } - getCompilationUnits() { + getCompilationUnits(): PandaGen[] { return this.compilationUnits; } - kind2String(kind: ts.SyntaxKind) { + kind2String(kind: ts.SyntaxKind): string { return ts.SyntaxKind[kind]; } - getASTStatistics(node: ts.Node, statics: number[]) { + getASTStatistics(node: ts.Node, statics: number[]): void { node.forEachChild(childNode => { statics[childNode.kind] = statics[childNode.kind] + 1; this.getASTStatistics(childNode, statics); @@ -306,7 +306,7 @@ export class CompilerDriver { } private compileUnitTestImpl(node: ts.SourceFile | ts.FunctionLikeDeclaration, scope: Scope, - internalName: string, recorder: Recorder) { + internalName: string, recorder: Recorder): void { let pandaGen = new PandaGen(internalName, node, this.getParametersCount(node), scope); IRNode.pg = pandaGen; if (CmdOptions.needRecordSourceCode() && !ts.isSourceFile(node)) { @@ -323,7 +323,7 @@ export class CompilerDriver { this.compilationUnits.push(pandaGen); } - static isTypeScriptSourceFile(node: ts.SourceFile) { + static isTypeScriptSourceFile(node: ts.SourceFile): boolean { let fileName = node.fileName; if (fileName && fileName.endsWith(".ts")) { return true; @@ -332,7 +332,7 @@ export class CompilerDriver { } } - private compilePrologue(node: ts.SourceFile, recordType: boolean, syntaxCheckStatus: boolean) { + private compilePrologue(node: ts.SourceFile, recordType: boolean, syntaxCheckStatus: boolean): Recorder { let topLevelScope: GlobalScope | ModuleScope; if (CmdOptions.isModules()) { topLevelScope = new ModuleScope(node); @@ -386,7 +386,7 @@ export class CompilerDriver { return idx; } - getFormatedRecordName() { + getFormatedRecordName(): string { let formatedRecordName: string = ''; if (CmdOptions.isMergeAbc()) { formatedRecordName = this.recordName + '.'; @@ -437,7 +437,7 @@ export class CompilerDriver { return `${this.getFormatedRecordName()}${name}`; } - getInternalNameForCtor(node: ts.ClassLikeDeclaration, ctor: ts.ConstructorDeclaration) { + getInternalNameForCtor(node: ts.ClassLikeDeclaration, ctor: ts.ConstructorDeclaration): string { let name = getClassNameForConstructor(node); name = `#${this.getFuncId(ctor)}#${name}` if (name.lastIndexOf(".") != -1) { @@ -446,7 +446,7 @@ export class CompilerDriver { return `${this.getFormatedRecordName()}${name}`; } - writeBinaryFile(pandaGen: PandaGen) { + writeBinaryFile(pandaGen: PandaGen): void { if (this.needDumpHeader) { AssemblyDumper.dumpHeader(); this.needDumpHeader = false; @@ -472,13 +472,13 @@ export class CompilerDriver { return parametersCount; } - private setTypeInfoBeforeRecord(enableTypeRecord: boolean) { + private setTypeInfoBeforeRecord(enableTypeRecord: boolean): void { if (enableTypeRecord) { TypeRecorder.createInstance(); } } - private setTypeInfoAfterRecord(enableTypeRecord: boolean) { + private setTypeInfoAfterRecord(enableTypeRecord: boolean): void { if (enableTypeRecord) { TypeRecorder.getInstance().setTypeSummary(); if (CmdOptions.enableTypeLog()) { diff --git a/ts2panda/src/compilerStatistics.ts b/ts2panda/src/compilerStatistics.ts index e94a3e1543b540ca754b80f912c74a132ac20014..e902c579e4eb988dd0a3ed47aad0e1a5a0395a8c 100644 --- a/ts2panda/src/compilerStatistics.ts +++ b/ts2panda/src/compilerStatistics.ts @@ -37,37 +37,37 @@ class ItemValue { } } - add(num: number) { + add(num: number): void { this.count += num; this.relatedInsns.forEach(relatedInsn => { relatedInsn.num += num }); } - set(num: number) { + set(num: number): void { this.count = num; this.relatedInsns.forEach(relatedInsn => { relatedInsn.num = num }); } - getCount() { + getCount(): number { return this.count; } - getInstSize() { + getInstSize(): number { return this.instSize; } - getTotalSize() { + getTotalSize(): number { return this.count * this.instSize; } - getRelatedInsns() { + getRelatedInsns(): { name: string, num: number }[] { return this.relatedInsns; } - getNodeMap() { + getNodeMap(): Map { return this.nodeMap; } - updateNodeMap(nodeName: string) { + updateNodeMap(nodeName: string): void { if (!this.nodeMap.has(nodeName)) { this.nodeMap.set(nodeName, 1); } else { @@ -76,7 +76,7 @@ class ItemValue { } } - unionNodeMap(nodeMap: Map) { + unionNodeMap(nodeMap: Map): void { nodeMap.forEach((value: number, key: string) => { if (!this.nodeMap.has(key)) { this.nodeMap.set(key, value); @@ -88,7 +88,7 @@ class ItemValue { }); } - getSavedSizeIfRemoved(Histogram: HistogramStatistics) { + getSavedSizeIfRemoved(Histogram: HistogramStatistics): number { let savedSize = this.getTotalSize(); this.relatedInsns.forEach(relatedInsn => { let histogram = Histogram.getStatistics(); @@ -167,7 +167,7 @@ class HistogramStatistics { return this.insHistogram; } - getTotal() { + getTotal(): number[] { let totalInsnsNum: number = 0; let totalSize: number = 0; // @ts-ignore @@ -231,22 +231,22 @@ export class CompilerStatistics { } - addHoistingRelatedInsnNum(num: number) { + addHoistingRelatedInsnNum(num: number): void { this.hoistingRelatedInsnNum += num; } - addNumOfHoistCases(type: HoistingType) { + addNumOfHoistCases(type: HoistingType): void { this.numOfHoistingCases[type]++; } - getInsHistogramStatistics(pg: PandaGen) { + getInsHistogramStatistics(pg: PandaGen): void { let histogram = new HistogramStatistics(pg.internalName); histogram.catchStatistics(pg); this.histogramMap.set(pg.internalName, histogram); } - printHistogram(verbose: boolean) { + printHistogram(verbose: boolean): void { let totalHistogram = new HistogramStatistics("Total"); // @ts-ignore diff --git a/ts2panda/src/compilerUtils.ts b/ts2panda/src/compilerUtils.ts index 1d406d114bdd00c1d5406f382975d09e1a2cd9ff..ff724807192c8ba0806f28461728d341bdb001af 100644 --- a/ts2panda/src/compilerUtils.ts +++ b/ts2panda/src/compilerUtils.ts @@ -36,7 +36,7 @@ import { } from "./statement/tryStatement"; import { Iterator } from "./base/iterator"; -export function compileDestructuring(pattern: ts.BindingOrAssignmentPattern, pandaGen: PandaGen, compiler: Compiler) { +export function compileDestructuring(pattern: ts.BindingOrAssignmentPattern, pandaGen: PandaGen, compiler: Compiler): void { let rhs = pandaGen.getTemp(); pandaGen.storeAccumulator(pattern, rhs); @@ -52,7 +52,7 @@ export function compileDestructuring(pattern: ts.BindingOrAssignmentPattern, pan pandaGen.freeTemps(rhs); } -function compileArrayDestructuring(arr: ts.ArrayBindingOrAssignmentPattern, pandaGen: PandaGen, compiler: Compiler) { +function compileArrayDestructuring(arr: ts.ArrayBindingOrAssignmentPattern, pandaGen: PandaGen, compiler: Compiler): void { let iter = pandaGen.getTemp(); let nextMethod = pandaGen.getTemp(); let iterDone = pandaGen.getTemp(); @@ -197,7 +197,7 @@ function compileArrayDestructuring(arr: ts.ArrayBindingOrAssignmentPattern, pand } function emitRestElement(restElement: ts.BindingName | ts.Expression, iterator: Iterator, iterResult: VReg, - pandaGen: PandaGen, compiler: Compiler, isDeclaration: boolean) { + pandaGen: PandaGen, compiler: Compiler, isDeclaration: boolean): void { let arrayObj = pandaGen.getTemp(); let index = pandaGen.getTemp(); @@ -247,7 +247,7 @@ function emitRestElement(restElement: ts.BindingName | ts.Expression, iterator: pandaGen.freeTemps(arrayObj, index); } -function compileObjectDestructuring(obj: ts.ObjectBindingOrAssignmentPattern, pandaGen: PandaGen, compiler: Compiler) { +function compileObjectDestructuring(obj: ts.ObjectBindingOrAssignmentPattern, pandaGen: PandaGen, compiler: Compiler): void { let value = pandaGen.getTemp(); pandaGen.storeAccumulator(obj, value); @@ -390,7 +390,7 @@ function compileObjectDestructuring(obj: ts.ObjectBindingOrAssignmentPattern, pa } function emitRestProperty(restProperty: ts.BindingElement | ts.SpreadAssignment, excludedProp: Array, - obj: VReg, pandaGen: PandaGen, compiler: Compiler) { + obj: VReg, pandaGen: PandaGen, compiler: Compiler): void { let isDeclaration = ts.isBindingElement(restProperty) ? true : false; let target = isDeclaration ? (restProperty).name : (restProperty).expression; let lRef = LReference.generateLReference(compiler, target, true); @@ -419,7 +419,7 @@ function emitRestProperty(restProperty: ts.BindingElement | ts.SpreadAssignment, pandaGen.freeTemps(...namedPropRegs); } -function isRestElement(node: ts.BindingElement) { +function isRestElement(node: ts.BindingElement): boolean { if (node.dotDotDotToken) { return true; } diff --git a/ts2panda/src/debuginfo.ts b/ts2panda/src/debuginfo.ts index 7e95232598f43762bf4c96f32041774cf20cba93..47b4696abbaa6042151d7e510bbd53106b639b7f 100644 --- a/ts2panda/src/debuginfo.ts +++ b/ts2panda/src/debuginfo.ts @@ -138,7 +138,7 @@ export class DebugInfo { private static lastNode: ts.Node; constructor() { } - public static isNode(extendedNode: ts.Node | NodeKind) { + public static isNode(extendedNode: ts.Node | NodeKind): boolean { if (extendedNode != NodeKind.Invalid && extendedNode != NodeKind.FirstNodeOfFunction && extendedNode != NodeKind.Normal) { @@ -148,7 +148,7 @@ export class DebugInfo { return false; } - public static updateLastNode(lastNode: ts.Node | NodeKind) { + public static updateLastNode(lastNode: ts.Node | NodeKind): void { if (DebugInfo.isNode(lastNode)) { DebugInfo.lastNode = lastNode; } @@ -181,7 +181,7 @@ export class DebugInfo { } } - public static setPosInfoForUninitializeIns(posInfo: DebugPosInfo, pandaGen: PandaGen) { + public static setPosInfoForUninitializeIns(posInfo: DebugPosInfo, pandaGen: PandaGen): void { let firstStmt = pandaGen.getFirstStmt(); if (firstStmt) { let res = this.searchForPos(firstStmt); @@ -193,7 +193,7 @@ export class DebugInfo { } } - public static setInvalidPosInfoForUninitializeIns(posInfo: DebugPosInfo, pandaGen: PandaGen) { + public static setInvalidPosInfoForUninitializeIns(posInfo: DebugPosInfo, pandaGen: PandaGen): void { posInfo.setSourecLineNum(-1); posInfo.setSourecColumnNum(-1); } @@ -275,7 +275,7 @@ export class DebugInfo { return length; } - private static setPosDebugInfo(pandaGen: PandaGen) { + private static setPosDebugInfo(pandaGen: PandaGen): void { let insns: IRNode[] = pandaGen.getInsns(); let offset = 0; @@ -301,7 +301,7 @@ export class DebugInfo { } } - private static setVariablesDebugInfo(pandaGen: PandaGen) { + private static setVariablesDebugInfo(pandaGen: PandaGen): void { let insns = pandaGen.getInsns(); for (let i = 0; i < insns.length; i++) { @@ -341,7 +341,7 @@ export class DebugInfo { }); } - public static setDebugInfo(pandaGen: PandaGen) { + public static setDebugInfo(pandaGen: PandaGen): void { // set position debug info DebugInfo.setPosDebugInfo(pandaGen); if (CmdOptions.isDebugMode()) { @@ -354,7 +354,7 @@ export class DebugInfo { } } - public static setSourceFileDebugInfo(pandaGen: PandaGen, node: ts.SourceFile | ts.FunctionLikeDeclaration) { + public static setSourceFileDebugInfo(pandaGen: PandaGen, node: ts.SourceFile | ts.FunctionLikeDeclaration): void { let sourceFile = jshelpers.getSourceFileOfNode(node); if (CmdOptions.getSourceFile().length > 0) { pandaGen.setSourceFileDebugInfo(CmdOptions.getSourceFile()); @@ -367,11 +367,11 @@ export class DebugInfo { } } - public static copyDebugInfo(insn: IRNode, expansion: IRNode[]) { + public static copyDebugInfo(insn: IRNode, expansion: IRNode[]): void { expansion.forEach(irNode => irNode.debugPosInfo = insn.debugPosInfo); } - public static addDebugIns(scope: Scope, pandaGen: PandaGen, isStart: boolean) { + public static addDebugIns(scope: Scope, pandaGen: PandaGen, isStart: boolean): void { if (!CmdOptions.isDebugMode()) { return; } diff --git a/ts2panda/src/ecmaModule.ts b/ts2panda/src/ecmaModule.ts index d69254de3850114bc903de52c3c177b9bba4d653..23dff77ae21dab69bb788a8b2d29daa7939eb52b 100644 --- a/ts2panda/src/ecmaModule.ts +++ b/ts2panda/src/ecmaModule.ts @@ -70,7 +70,7 @@ export class SourceTextModuleRecord { // Targetcase 2: import {x} from 'test.js'; // Targetcase 3: import {x as y} from 'test.js'; // Targetcase 4: import defaultExport from 'test.js' - addImportEntry(node: ts.Node, importName: string, localName: string, moduleRequest: string) { + addImportEntry(node: ts.Node, importName: string, localName: string, moduleRequest: string): void { let importEntry: Entry = new Entry(node, undefined, localName, importName, this.addModuleRequest(moduleRequest)); // We don't care if there's already an entry for this local name, as in that // case we will report an error when declaring the variable. @@ -85,7 +85,7 @@ export class SourceTextModuleRecord { } // Targetcase 1: import * as x from 'test.js'; - addStarImportEntry(node: ts.Node, localName: string, moduleRequest: string) { + addStarImportEntry(node: ts.Node, localName: string, moduleRequest: string): void { let starImportEntry: Entry = new Entry(node, undefined, localName, undefined, this.addModuleRequest(moduleRequest)); this.namespaceImportEntries.push(starImportEntry); } @@ -95,7 +95,7 @@ export class SourceTextModuleRecord { // Targetcase 3: export VariableStatement // Targetcase 4: export Declaration // Targetcase 5: export default ... - addLocalExportEntry(node: ts.Node, exportName: string, localName: string) { + addLocalExportEntry(node: ts.Node, exportName: string, localName: string): void { let localExportEntry: Entry = new Entry(node, exportName, localName, undefined); if (this.localExportEntries.has(localName)) { this.localExportEntries.get(localName)!.push(localExportEntry); @@ -107,46 +107,46 @@ export class SourceTextModuleRecord { // Targetcase 1: export {x} from 'test.js'; // Targetcase 2: export {x as y} from 'test.js'; // Targetcase 3: import { x } from 'test.js'; export { x } - addIndirectExportEntry(node: ts.Node, importName: string, exportName: string, moduleRequest: string) { + addIndirectExportEntry(node: ts.Node, importName: string, exportName: string, moduleRequest: string): void { let indirectExportEntry: Entry = new Entry(node, exportName, undefined, importName, this.addModuleRequest(moduleRequest)); this.indirectExportEntries.push(indirectExportEntry); } // Targetcase 1: export * from 'test.js'; - addStarExportEntry(node: ts.Node, moduleRequest: string) { + addStarExportEntry(node: ts.Node, moduleRequest: string): void { let starExportEntry: Entry = new Entry(node, undefined, undefined, undefined, this.addModuleRequest(moduleRequest)); this.starExportEntries.push(starExportEntry); } - getModuleName() { + getModuleName(): string { return this.moduleName; } - getModuleRequests() { + getModuleRequests(): string[] { return this.moduleRequests; } - getRegularImportEntries() { + getRegularImportEntries(): Map { return this.regularImportEntries; } - getNamespaceImportEntries() { + getNamespaceImportEntries(): Entry[] { return this.namespaceImportEntries; } - getLocalExportEntries() { + getLocalExportEntries(): Map { return this.localExportEntries; } - getStarExportEntries() { + getStarExportEntries(): Entry[] { return this.starExportEntries; } - getIndirectExportEntries() { + getIndirectExportEntries(): Entry[] { return this.indirectExportEntries; } - makeIndirectExportsExplicit() { + makeIndirectExportsExplicit(): void { // @ts-ignore this.localExportEntries.forEach((entries: Array, localName: string) => { let importEntry: Entry | undefined = this.regularImportEntries.get(localName); @@ -163,7 +163,7 @@ export class SourceTextModuleRecord { }); } - nextDuplicateExportEntry(candidate: Entry, exportNameEntry: Map, currentCandidate: Entry | undefined) { + nextDuplicateExportEntry(candidate: Entry, exportNameEntry: Map, currentCandidate: Entry | undefined): Entry { if (!exportNameEntry.has(candidate.exportName!)) { exportNameEntry.set(candidate.exportName!, candidate); return currentCandidate; @@ -194,7 +194,7 @@ export class SourceTextModuleRecord { return duplicateEntry; } - validateModuleRecordEntries(moduleScope: ModuleScope) { + validateModuleRecordEntries(moduleScope: ModuleScope): void { // check module is well-formed and report errors if not { let dupExportEntry: Entry | undefined = this.searchDuplicateExport(); @@ -212,20 +212,20 @@ export class SourceTextModuleRecord { this.makeIndirectExportsExplicit(); } - setExportedDecls(moduleScope: ModuleScope) { + setExportedDecls(moduleScope: ModuleScope): void { // @ts-ignore this.localExportEntries.forEach((entry: Array, localName: string) => { moduleScope.setExportDecl(localName); }) } - setModuleEnvironment(moduleScope: ModuleScope) { + setModuleEnvironment(moduleScope: ModuleScope): void { this.validateModuleRecordEntries(moduleScope); this.setExportedDecls(moduleScope); } } -export function setModuleNamespaceImports(compiler: Compiler, moduleScope: Scope, pandagen: PandaGen) { +export function setModuleNamespaceImports(compiler: Compiler, moduleScope: Scope, pandagen: PandaGen): void { if (!(moduleScope instanceof ModuleScope)) { return; } @@ -237,7 +237,7 @@ export function setModuleNamespaceImports(compiler: Compiler, moduleScope: Scope }); } -export function assignIndexToModuleVariable(moduleScope: Scope) { +export function assignIndexToModuleVariable(moduleScope: Scope): void { if (!(moduleScope instanceof ModuleScope)) { return; } diff --git a/ts2panda/src/expression/arrayLiteralExpression.ts b/ts2panda/src/expression/arrayLiteralExpression.ts index 3ce4a7df271c73ecd05f8bce0510b1a296c981ef..a7e7258799f012ebccd0a155173a10373057d381 100644 --- a/ts2panda/src/expression/arrayLiteralExpression.ts +++ b/ts2panda/src/expression/arrayLiteralExpression.ts @@ -22,14 +22,14 @@ import { PandaGen } from "../pandagen"; import { isInteger } from "./numericLiteral"; import { VReg } from "../irnodes"; -export function compileArrayLiteralExpression(compiler: Compiler, node: ts.ArrayLiteralExpression) { +export function compileArrayLiteralExpression(compiler: Compiler, node: ts.ArrayLiteralExpression): void { let pandaGen = compiler.getPandaGen(); let arrayObj = pandaGen.getTemp(); createArrayFromElements(node, compiler, node.elements, arrayObj); pandaGen.freeTemps(arrayObj); } -export function createArrayFromElements(node: ts.Node, compiler: Compiler, elements: ts.NodeArray, arrayObj: VReg) { +export function createArrayFromElements(node: ts.Node, compiler: Compiler, elements: ts.NodeArray, arrayObj: VReg): void { let pandaGen = compiler.getPandaGen(); // empty Array if (elements.length == 0) { @@ -158,7 +158,7 @@ function parseConstantExpr(element: ts.Expression): Literal { return elem; } -function emitCreateArrayWithBuffer(pandaGen: PandaGen, literalBuffer: LiteralBuffer, element: ts.Expression) { +function emitCreateArrayWithBuffer(pandaGen: PandaGen, literalBuffer: LiteralBuffer, element: ts.Expression): void { if (literalBuffer.isEmpty()) { pandaGen.createEmptyArray(element); } else { @@ -167,13 +167,13 @@ function emitCreateArrayWithBuffer(pandaGen: PandaGen, literalBuffer: LiteralBuf } } -function storeElementIfSpreadExisted(pandaGen: PandaGen, element: ts.Expression, arrayObj: VReg, indexReg: VReg) { +function storeElementIfSpreadExisted(pandaGen: PandaGen, element: ts.Expression, arrayObj: VReg, indexReg: VReg): void { pandaGen.storeOwnProperty(element, arrayObj, indexReg); pandaGen.unary(element, ts.SyntaxKind.PlusPlusToken, indexReg); pandaGen.storeAccumulator(element, indexReg); } -function storeSpreadElement(compiler: Compiler, pandaGen: PandaGen, element: ts.SpreadElement, arrayObj: VReg, indexReg: VReg) { +function storeSpreadElement(compiler: Compiler, pandaGen: PandaGen, element: ts.SpreadElement, arrayObj: VReg, indexReg: VReg): void { compiler.compileExpression(element.expression); pandaGen.storeArraySpreadElement(element, arrayObj, indexReg); pandaGen.storeAccumulator(element, indexReg); diff --git a/ts2panda/src/expression/bigIntLiteral.ts b/ts2panda/src/expression/bigIntLiteral.ts index 912769c0934134345fe57b3b7972faefcce93f7c..5e4d7d9d047b3971abb28b9342f7c8af0a4b63d4 100644 --- a/ts2panda/src/expression/bigIntLiteral.ts +++ b/ts2panda/src/expression/bigIntLiteral.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; import * as jshelpers from "../jshelpers"; import { PandaGen } from "../pandagen"; -export function compileBigIntLiteral(pandaGen: PandaGen, lit: ts.BigIntLiteral) { +export function compileBigIntLiteral(pandaGen: PandaGen, lit: ts.BigIntLiteral): void { let text = jshelpers.getTextOfIdentifierOrLiteral(lit); text = text.substring(0, text.length-1); pandaGen.loadAccumulatorBigInt(lit, text); diff --git a/ts2panda/src/expression/callExpression.ts b/ts2panda/src/expression/callExpression.ts index a42cb042966a940f5cd3ee0ea3c31830da101a39..8bacae36938a18fa102b4e2aea305965f4bd42c3 100644 --- a/ts2panda/src/expression/callExpression.ts +++ b/ts2panda/src/expression/callExpression.ts @@ -24,7 +24,7 @@ import { getObjAndProp } from "./memberAccessExpression"; // @ts-ignore -export function compileCallExpression(expr: ts.CallExpression, compiler: Compiler, inTailPos?: boolean) { +export function compileCallExpression(expr: ts.CallExpression, compiler: Compiler, inTailPos?: boolean): void { let pandaGen = compiler.getPandaGen(); let innerExpression = ts.skipPartiallyEmittedExpressions(expr.expression); @@ -90,7 +90,7 @@ export function getHiddenParameters(expr: ts.Expression, compiler: Compiler) { return { arguments: args, passThis: passThis }; } -function emitCallArguments(compiler: Compiler, expr: ts.CallExpression, args: VReg[]) { +function emitCallArguments(compiler: Compiler, expr: ts.CallExpression, args: VReg[]): boolean { let pandaGen = compiler.getPandaGen(); let hasSpread = false; for (let i = 0; i < expr.arguments.length; i++) { @@ -113,7 +113,7 @@ function emitCallArguments(compiler: Compiler, expr: ts.CallExpression, args: VR return hasSpread; } -export function emitCall(expr: ts.CallExpression, args: VReg[], passThis: boolean, compiler: Compiler) { +export function emitCall(expr: ts.CallExpression, args: VReg[], passThis: boolean, compiler: Compiler): void { let pandaGen = compiler.getPandaGen(); let hasSpread = emitCallArguments(compiler, expr, args); let callee = expr.expression; diff --git a/ts2panda/src/expression/compileCommaListExpression.ts b/ts2panda/src/expression/compileCommaListExpression.ts index 4f1ab59b648eb701c6d8af65e5608b8f9ce080a9..5394ff5d476470f13e28a6671f65944825bb6d10 100644 --- a/ts2panda/src/expression/compileCommaListExpression.ts +++ b/ts2panda/src/expression/compileCommaListExpression.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; import { Compiler } from "../compiler"; -export function compileCommaListExpression(compiler: Compiler, exprList: ts.CommaListExpression) { +export function compileCommaListExpression(compiler: Compiler, exprList: ts.CommaListExpression): void { exprList.elements.forEach(expr => { compiler.compileExpression(expr); }) diff --git a/ts2panda/src/expression/memberAccessExpression.ts b/ts2panda/src/expression/memberAccessExpression.ts index 1183bb7befba05e6fae1b876048ae497a445408f..486659c9df469ef5434b0652e4f1bb779f058296 100644 --- a/ts2panda/src/expression/memberAccessExpression.ts +++ b/ts2panda/src/expression/memberAccessExpression.ts @@ -21,7 +21,7 @@ import { compileSuperProperty } from "../statement/classStatement"; const MAX_LENGTH = 2 ** 32 - 1; -export function compileMemberAccessExpression(node: ts.ElementAccessExpression | ts.PropertyAccessExpression, compiler: Compiler) { +export function compileMemberAccessExpression(node: ts.ElementAccessExpression | ts.PropertyAccessExpression, compiler: Compiler): void { let pandaGen = compiler.getPandaGen(); let objReg = pandaGen.getTemp(); let propReg = pandaGen.getTemp(); @@ -44,7 +44,8 @@ export function compileMemberAccessExpression(node: ts.ElementAccessExpression | pandaGen.freeTemps(objReg, propReg); } -export function getObjAndProp(node: ts.ElementAccessExpression | ts.PropertyAccessExpression, objReg: VReg, propReg: VReg, compiler: Compiler) { +export function getObjAndProp(node: ts.ElementAccessExpression | ts.PropertyAccessExpression, + objReg: VReg, propReg: VReg, compiler: Compiler): { obj: VReg; prop: any; } { let pandaGen = compiler.getPandaGen(); let obj = objReg; let prop: VReg | string | number = propReg; @@ -97,7 +98,7 @@ export function getObjAndProp(node: ts.ElementAccessExpression | ts.PropertyAcce return { obj: obj, prop: prop }; } -export function isValidIndex(num: number) { +export function isValidIndex(num: number): boolean { if ((num >= 0) && (num < MAX_LENGTH) && (Number.isInteger(num))) { return true; } diff --git a/ts2panda/src/expression/metaProperty.ts b/ts2panda/src/expression/metaProperty.ts index f9c7447409c802d6c496807641400d750fd3e7b1..60afa85d04b6d8901d058d333edd62206db7c68d 100644 --- a/ts2panda/src/expression/metaProperty.ts +++ b/ts2panda/src/expression/metaProperty.ts @@ -18,7 +18,7 @@ import * as ts from "typescript"; import { Compiler } from "../compiler"; import * as jshelpers from "../jshelpers"; -export function compileMetaProperty(expr: ts.MetaProperty, compiler: Compiler) { +export function compileMetaProperty(expr: ts.MetaProperty, compiler: Compiler): void { let curScope = compiler.getCurrentScope(); let id = jshelpers.getTextOfIdentifierOrLiteral(expr.name); if (id == "target") { diff --git a/ts2panda/src/expression/newExpression.ts b/ts2panda/src/expression/newExpression.ts index 4f05d929dbb3792dbcb1c4d982e5f61b34468426..68fc2f5f2e28d40311fa1022a2409c6e49be104e 100644 --- a/ts2panda/src/expression/newExpression.ts +++ b/ts2panda/src/expression/newExpression.ts @@ -19,7 +19,7 @@ import { VReg } from "../irnodes"; import { containSpreadElement } from "../base/util"; import { createArrayFromElements } from "./arrayLiteralExpression"; -export function compileNewExpression(expr: ts.NewExpression, compiler: Compiler) { +export function compileNewExpression(expr: ts.NewExpression, compiler: Compiler): void { let pandaGen = compiler.getPandaGen(); let ctorReg = pandaGen.getTemp(); diff --git a/ts2panda/src/expression/numericLiteral.ts b/ts2panda/src/expression/numericLiteral.ts index b20056c5d2e81b7937dfc182b084dc385f9719be..5c5a60fa3f85fecdf630c2e0b3e203c502b6388d 100644 --- a/ts2panda/src/expression/numericLiteral.ts +++ b/ts2panda/src/expression/numericLiteral.ts @@ -35,7 +35,7 @@ export function isInteger(value: number): Boolean { return true; } -export function compileNumericLiteral(pandaGen: PandaGen, lit: ts.NumericLiteral) { +export function compileNumericLiteral(pandaGen: PandaGen, lit: ts.NumericLiteral): void { let text = jshelpers.getTextOfIdentifierOrLiteral(lit); let value = Number.parseFloat(text); // check whether value is a NaN diff --git a/ts2panda/src/expression/objectLiteralExpression.ts b/ts2panda/src/expression/objectLiteralExpression.ts index 1d6af9384c4f132e56561f2e59e14493848057c9..0fd4568191fefb9750f3dd6ba5ece49a71fbea34 100644 --- a/ts2panda/src/expression/objectLiteralExpression.ts +++ b/ts2panda/src/expression/objectLiteralExpression.ts @@ -25,7 +25,7 @@ import { VReg } from "../irnodes"; import { PropertyKind, Property, generatePropertyFromExpr } from "../base/properties"; import { LiteralTag, Literal, LiteralBuffer } from "../base/literal"; -export function compileObjectLiteralExpression(compiler: Compiler, expr: ts.ObjectLiteralExpression) { +export function compileObjectLiteralExpression(compiler: Compiler, expr: ts.ObjectLiteralExpression): void { let pandaGen = compiler.getPandaGen(); // traverse the properties entries and store the useful information @@ -108,7 +108,7 @@ function compileProperties(compiler: Compiler, properties: Property[], literalBu } function createObject(expr: ts.ObjectLiteralExpression, pandaGen: PandaGen, objReg: VReg, - literalBuffer: LiteralBuffer, hasMethod: boolean, compiler: Compiler) { + literalBuffer: LiteralBuffer, hasMethod: boolean, compiler: Compiler): void { if (literalBuffer.isEmpty()) { pandaGen.createEmptyObject(expr); } else { @@ -144,7 +144,7 @@ function createConstantLiteral(prop: Property): Literal { return valLiteral; } -function compileAccessorProperty(pandaGen: PandaGen, compiler: Compiler, objReg: VReg, prop: Property) { +function compileAccessorProperty(pandaGen: PandaGen, compiler: Compiler, objReg: VReg, prop: Property): void { let getterReg = pandaGen.getTemp(); let setterReg = pandaGen.getTemp(); let propReg = pandaGen.getTemp(); @@ -178,7 +178,7 @@ function compileAccessorProperty(pandaGen: PandaGen, compiler: Compiler, objReg: pandaGen.freeTemps(getterReg, setterReg, propReg); } -function compileSpreadProperty(compiler: Compiler, prop: Property, objReg: VReg) { +function compileSpreadProperty(compiler: Compiler, prop: Property, objReg: VReg): void { let pandaGen = compiler.getPandaGen(); compiler.compileExpression(prop.getValue()); @@ -186,7 +186,7 @@ function compileSpreadProperty(compiler: Compiler, prop: Property, objReg: VReg) pandaGen.copyDataProperties(prop.getValue().parent, objReg); } -function compileComputedProperty(compiler: Compiler, prop: Property, objReg: VReg) { +function compileComputedProperty(compiler: Compiler, prop: Property, objReg: VReg): void { // Computed can't know its key in compile time, create Object now. let pandaGen = compiler.getPandaGen(); @@ -230,7 +230,7 @@ function compileComputedProperty(compiler: Compiler, prop: Property, objReg: VRe pandaGen.freeTemps(keyReg); } -function compileProtoProperty(compiler: Compiler, prop: Property, objReg: VReg) { +function compileProtoProperty(compiler: Compiler, prop: Property, objReg: VReg): void { let pandaGen = compiler.getPandaGen(); let protoReg = pandaGen.getTemp(); @@ -240,7 +240,7 @@ function compileProtoProperty(compiler: Compiler, prop: Property, objReg: VReg) pandaGen.freeTemps(protoReg); } -function setUncompiledProperties(compiler: Compiler, pandaGen: PandaGen, properties: Property[], objReg: VReg) { +function setUncompiledProperties(compiler: Compiler, pandaGen: PandaGen, properties: Property[], objReg: VReg): void { for (let prop of properties) { if (!prop.isCompiled()) { switch (prop.getKind()) { diff --git a/ts2panda/src/expression/regularExpression.ts b/ts2panda/src/expression/regularExpression.ts index bb7d2e649beb01d22be1c05e87d492023e7601c2..8853f1b7501162184d59477d5bed722fa1a5228c 100644 --- a/ts2panda/src/expression/regularExpression.ts +++ b/ts2panda/src/expression/regularExpression.ts @@ -31,7 +31,7 @@ export enum RegExpFlags { } -export function compileRegularExpressionLiteral(compiler: Compiler, regexp: ts.RegularExpressionLiteral) { +export function compileRegularExpressionLiteral(compiler: Compiler, regexp: ts.RegularExpressionLiteral): void { let pandaGen = compiler.getPandaGen(); let regexpText = regexp.text; let regexpPattern = regexpText; @@ -50,7 +50,7 @@ export function compileRegularExpressionLiteral(compiler: Compiler, regexp: ts.R } -function updateExpressionFlags(regexpFlags: string, regexp: ts.RegularExpressionLiteral) { +function updateExpressionFlags(regexpFlags: string, regexp: ts.RegularExpressionLiteral): number { let flagsBits: number = 0; let flagsBitsTemp: number = 0; for (let idx = 0; idx < regexpFlags.length; idx++) { diff --git a/ts2panda/src/expression/stringLiteral.ts b/ts2panda/src/expression/stringLiteral.ts index 415300db1bb304062a22e4846f947e52c7376ed1..4bcd10d5b7d6f0a14ad34c256d812684ec6a7a07 100644 --- a/ts2panda/src/expression/stringLiteral.ts +++ b/ts2panda/src/expression/stringLiteral.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; import * as jshelpers from "../jshelpers"; import { PandaGen } from "../pandagen"; -export function compileStringLiteral(pandaGen: PandaGen, lit: ts.StringLiteral) { +export function compileStringLiteral(pandaGen: PandaGen, lit: ts.StringLiteral): void { let text = jshelpers.getTextOfIdentifierOrLiteral(lit); pandaGen.loadAccumulatorString(lit, text); } diff --git a/ts2panda/src/expression/templateExpression.ts b/ts2panda/src/expression/templateExpression.ts index a6315cb7248067459057b1aa39d1cb8f51728dc5..61c6dd64b93a710f62c88e68199942926c856087 100644 --- a/ts2panda/src/expression/templateExpression.ts +++ b/ts2panda/src/expression/templateExpression.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; import { PandaGen } from "../pandagen"; import { VReg } from "../irnodes"; -function genRawString(pandaGen: PandaGen, expr: ts.TemplateExpression | ts.NoSubstitutionTemplateLiteral) { +function genRawString(pandaGen: PandaGen, expr: ts.TemplateExpression | ts.NoSubstitutionTemplateLiteral): void { let text = "" if (ts.isTemplateExpression(expr)) { text = expr.head.rawText!; @@ -29,7 +29,7 @@ function genRawString(pandaGen: PandaGen, expr: ts.TemplateExpression | ts.NoSub pandaGen.loadAccumulatorString(expr, text); } -function genCookedString(pandaGen: PandaGen, expr: ts.TemplateExpression | ts.NoSubstitutionTemplateLiteral) { +function genCookedString(pandaGen: PandaGen, expr: ts.TemplateExpression | ts.NoSubstitutionTemplateLiteral): void { let text = "" if (ts.isTemplateExpression(expr)) { text = expr.head.text; @@ -45,7 +45,7 @@ function genCookedString(pandaGen: PandaGen, expr: ts.TemplateExpression | ts.No pandaGen.loadAccumulatorString(expr, text); } -function genTemplateArrayArg(pandaGen: PandaGen, expr: ts.TemplateExpression | ts.NoSubstitutionTemplateLiteral, rawArr: VReg, cookedArr: VReg) { +function genTemplateArrayArg(pandaGen: PandaGen, expr: ts.TemplateExpression | ts.NoSubstitutionTemplateLiteral, rawArr: VReg, cookedArr: VReg): void { let spans = undefined; if (ts.isTemplateExpression(expr)) { spans = expr.templateSpans; @@ -88,7 +88,7 @@ function genTemplateArrayArg(pandaGen: PandaGen, expr: ts.TemplateExpression | t pandaGen.freeTemps(indexReg, rawArrTmp, cookedArrTmp); } -export function getTemplateObject(pandaGen: PandaGen, expr: ts.TaggedTemplateExpression) { +export function getTemplateObject(pandaGen: PandaGen, expr: ts.TaggedTemplateExpression): void { let templateArgs = pandaGen.getTemp(); let indexReg = pandaGen.getTemp(); let rawArr = pandaGen.getTemp(); diff --git a/ts2panda/src/expression/yieldExpression.ts b/ts2panda/src/expression/yieldExpression.ts index 4280d68c28539865acdcd3e2ba0e8a881de54127..9a04af15cdec7d5754353173dc45c2b52d783a13 100644 --- a/ts2panda/src/expression/yieldExpression.ts +++ b/ts2panda/src/expression/yieldExpression.ts @@ -20,7 +20,7 @@ import { CacheList, getVregisterCache } from "../base/vregisterCache"; import { AsyncGeneratorFunctionBuilder } from "../function/asyncGeneratorFunctionBuilder"; import { Compiler } from "../compiler"; -export function compileYieldExpression(compiler: Compiler, expr: ts.YieldExpression) { +export function compileYieldExpression(compiler: Compiler, expr: ts.YieldExpression): void { if (!(compiler.getFuncBuilder() instanceof GeneratorFunctionBuilder || compiler.getFuncBuilder() instanceof AsyncGeneratorFunctionBuilder)) { throw new DiagnosticError(expr.parent, DiagnosticCode.A_yield_expression_is_only_allowed_in_a_generator_body); } @@ -28,7 +28,7 @@ export function compileYieldExpression(compiler: Compiler, expr: ts.YieldExpress expr.asteriskToken ? genYieldStarExpr(compiler, expr) : genYieldExpr(compiler, expr); } -function genYieldExpr(compiler: Compiler, expr: ts.YieldExpression) { +function genYieldExpr(compiler: Compiler, expr: ts.YieldExpression): void { let pandaGen = compiler.getPandaGen(); let funcBuilder = compiler.getFuncBuilder(); if (expr.expression) { @@ -40,7 +40,7 @@ function genYieldExpr(compiler: Compiler, expr: ts.YieldExpression) { } } -function genYieldStarExpr(compiler: Compiler, expr: ts.YieldExpression) { +function genYieldStarExpr(compiler: Compiler, expr: ts.YieldExpression): void { let funcBuilder = compiler.getFuncBuilder(); if (!expr.expression) { throw new Error("yield* must have an expression!"); diff --git a/ts2panda/src/function/asyncFunctionBuilder.ts b/ts2panda/src/function/asyncFunctionBuilder.ts index 3dc968aff000078695cf897406feacd0409de805..aaf7d8ebdc108cfbe8893fffe66e40487ca34ff2 100644 --- a/ts2panda/src/function/asyncFunctionBuilder.ts +++ b/ts2panda/src/function/asyncFunctionBuilder.ts @@ -71,7 +71,7 @@ export class AsyncFunctionBuilder extends FunctionBuilder { this.pg.return(node); } - private handleMode(node: ts.Node) { + private handleMode(node: ts.Node): void { let pandaGen = this.pg; let modeType = pandaGen.getTemp(); @@ -95,7 +95,7 @@ export class AsyncFunctionBuilder extends FunctionBuilder { pandaGen.loadAccumulator(node, this.resumeVal); } - resolve(node: ts.Node | NodeKind, value: VReg) { + resolve(node: ts.Node | NodeKind, value: VReg): void { let pandaGen = this.pg; pandaGen.loadAccumulator(node, value); pandaGen.asyncFunctionResolve(node, this.funcObj); diff --git a/ts2panda/src/function/asyncGeneratorFunctionBuilder.ts b/ts2panda/src/function/asyncGeneratorFunctionBuilder.ts index 4484fb628c5be8fc5fa4a0886179de4aba1518f0..41e1093adc4f21f7fa139be35cb566fb9f86c6c6 100644 --- a/ts2panda/src/function/asyncGeneratorFunctionBuilder.ts +++ b/ts2panda/src/function/asyncGeneratorFunctionBuilder.ts @@ -55,7 +55,7 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { this.compiler = compiler; } - prepare(node: ts.Node) { + prepare(node: ts.Node): void { let pg = this.pg; // backend handle funcobj, frontend set undefined @@ -100,7 +100,7 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { this.directReturn(node); } - yield(node: ts.Node) { + yield(node: ts.Node): void { let pg = this.pg; // 27.6.3.8.5 Set value to ? Await(value). @@ -120,7 +120,7 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { this.handleAsyncYieldResume(node); } - yieldStar(node: ts.Node) { + yieldStar(node: ts.Node): void { let pg = this.pg; let method = pg.getTemp(); let iterator = pg.getTemp(); @@ -264,7 +264,7 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { pg.freeTemps(method, iterator, nextResult, value, done, nextMethod, exitReturn); } - private handleAsyncYieldResume(node: ts.Node) { + private handleAsyncYieldResume(node: ts.Node): void { let pg = this.pg; let notRet = new Label(); let normalCompletion = new Label(); @@ -310,7 +310,7 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { pg.loadAccumulator(node, this.resumeVal); } - private handleMode(node: ts.Node) { + private handleMode(node: ts.Node): void { let pandaGen = this.pg; pandaGen.getResumeMode(node, this.funcObj); @@ -330,12 +330,12 @@ export class AsyncGeneratorFunctionBuilder extends FunctionBuilder { pandaGen.loadAccumulator(node, this.resumeVal); } - resolve(node: ts.Node | NodeKind, value: VReg) { + resolve(node: ts.Node | NodeKind, value: VReg): void { let pandaGen = this.pg; pandaGen.asyncgeneratorresolve(node, this.funcObj, value, getVregisterCache(pandaGen, CacheList.True)); } - cleanUp(node: ts.Node) { + cleanUp(node: ts.Node): void { let pandaGen = this.pg; pandaGen.label(node, this.endLabel); // catch diff --git a/ts2panda/src/function/functionBuilder.ts b/ts2panda/src/function/functionBuilder.ts index 23a32bcc1ac35227e48ccd4221dace4be4293913..21ea0297faf83a8ac331533b9c45228434513bd8 100644 --- a/ts2panda/src/function/functionBuilder.ts +++ b/ts2panda/src/function/functionBuilder.ts @@ -61,7 +61,7 @@ export class FunctionBuilder { pg.storeAccumulator(node, this.resumeVal); } - resumeGenerator(node: ts.Node | NodeKind) { + resumeGenerator(node: ts.Node | NodeKind): void { let pg = this.pg; pg.resumeGenerator(node, this.funcObj); pg.storeAccumulator(node, this.resumeVal); @@ -69,11 +69,11 @@ export class FunctionBuilder { pg.storeAccumulator(node, this.resumeType); } - explicitReturn(node: ts.Node | NodeKind, empty ? : boolean) { + explicitReturn(node: ts.Node | NodeKind, empty ? : boolean): void { this.pg.return(node); } - implicitReturn(node: ts.Node | NodeKind) { + implicitReturn(node: ts.Node | NodeKind): void { CmdOptions.isWatchEvaluateExpressionMode() ? this.pg.return(NodeKind.Invalid) : this.pg.returnUndefined(node); } diff --git a/ts2panda/src/function/generatorFunctionBuilder.ts b/ts2panda/src/function/generatorFunctionBuilder.ts index bbbd621c70831dab558bd35efa3bd321b6be36a8..75db78c3cebb2175b30a759d6df5123bd5ab77de 100644 --- a/ts2panda/src/function/generatorFunctionBuilder.ts +++ b/ts2panda/src/function/generatorFunctionBuilder.ts @@ -43,7 +43,7 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { this.compiler = compiler; } - prepare(node: ts.Node) { + prepare(node: ts.Node): void { let pandaGen = this.pg; // backend handle funcobj, frontend set undefined @@ -57,15 +57,15 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { this.handleMode(node); } - explicitReturn(node: ts.Node | NodeKind, empty ? : boolean) { + explicitReturn(node: ts.Node | NodeKind, empty ? : boolean): void { this.pg.return(node); } - implicitReturn(node: ts.Node | NodeKind) { + implicitReturn(node: ts.Node | NodeKind): void { CmdOptions.isWatchEvaluateExpressionMode() ? this.pg.return(NodeKind.Invalid) : this.pg.returnUndefined(node); } - yield(node: ts.Node) { + yield(node: ts.Node): void { let pandaGen = this.pg; let iterRslt = pandaGen.getTemp(); let value = pandaGen.getTemp(); @@ -81,7 +81,7 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { this.handleMode(node); } - yieldStar(expr: ts.YieldExpression) { + yieldStar(expr: ts.YieldExpression): void { let pandaGen = this.pg; let method = pandaGen.getTemp(); let object = pandaGen.getTemp(); @@ -217,7 +217,7 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { pandaGen.freeTemps(method, object, receivedValue, modeType, outputResult); } - private handleMode(node: ts.Node) { + private handleMode(node: ts.Node): void { let pandaGen = this.pg; let modeType = pandaGen.getTemp(); @@ -260,7 +260,7 @@ export class GeneratorFunctionBuilder extends FunctionBuilder { pandaGen.loadAccumulator(node, this.resumeVal); } - cleanUp() { + cleanUp(): void { this.pg.freeTemps(this.funcObj, this.resumeVal); } } diff --git a/ts2panda/src/hoisting.ts b/ts2panda/src/hoisting.ts index e544b95c25568d21b38e409e2c2fcc74426d9850..a48144c5cf90eac7901447efda01b4c832f83562 100644 --- a/ts2panda/src/hoisting.ts +++ b/ts2panda/src/hoisting.ts @@ -34,7 +34,7 @@ import { import { ModuleVariable } from "./variable"; export function hoisting(rootNode: ts.SourceFile | ts.FunctionLikeDeclaration, pandaGen: PandaGen, - recorder: Recorder, compiler: Compiler) { + recorder: Recorder, compiler: Compiler): void { let variableScope = recorder.getScopeOfNode(rootNode); let hoistDecls = recorder.getHoistDeclsOfScope(variableScope); @@ -50,7 +50,7 @@ export function hoisting(rootNode: ts.SourceFile | ts.FunctionLikeDeclaration, p }); } -export function hoistVar(decl: VarDecl, scope: Scope, pandaGen: PandaGen) { +export function hoistVar(decl: VarDecl, scope: Scope, pandaGen: PandaGen): void { let name = decl.name; if (scope instanceof GlobalScope) { @@ -69,7 +69,7 @@ export function hoistVar(decl: VarDecl, scope: Scope, pandaGen: PandaGen) { } } -export function hoistFunction(decl: FuncDecl, scope: Scope, pandaGen: PandaGen, compiler: Compiler, compilerDriver: CompilerDriver) { +export function hoistFunction(decl: FuncDecl, scope: Scope, pandaGen: PandaGen, compiler: Compiler, compilerDriver: CompilerDriver): void { let funcName = decl.name; let internalName = compilerDriver.getFuncInternalName(decl.node, compiler.getRecorder()); let env = compiler.getCurrentEnv(); @@ -91,7 +91,7 @@ export function hoistFunction(decl: FuncDecl, scope: Scope, pandaGen: PandaGen, } // this function is called when hoisting function inside blocks -export function hoistFunctionInBlock(scope: Scope, pandaGen: PandaGen, strictMode: boolean, compiler: Compiler) { +export function hoistFunctionInBlock(scope: Scope, pandaGen: PandaGen, strictMode: boolean, compiler: Compiler): void { let decls = scope.getDecls(); let funcToHoist = new Array(); for (let i = 0; i < decls.length; i++) { diff --git a/ts2panda/src/index.ts b/ts2panda/src/index.ts index 92648846c011785777998c2f64069c04d057cb4e..c4c240b313e8f6e66ed926dcb2bd870fc3e028ad 100644 --- a/ts2panda/src/index.ts +++ b/ts2panda/src/index.ts @@ -42,7 +42,7 @@ import { resetUniqueNameIndex } from "./base/util"; -function checkIsGlobalDeclaration(sourceFile: ts.SourceFile) { +function checkIsGlobalDeclaration(sourceFile: ts.SourceFile): boolean { for (let statement of sourceFile.statements) { if (statement.modifiers) { for (let modifier of statement.modifiers) { @@ -59,7 +59,7 @@ function checkIsGlobalDeclaration(sourceFile: ts.SourceFile) { return true; } -function generateDTs(node: ts.SourceFile, options: ts.CompilerOptions) { +function generateDTs(node: ts.SourceFile, options: ts.CompilerOptions): void { let outputBinName = getOutputBinName(node); let compilerDriver = new CompilerDriver(outputBinName, getRecordName(node)); CompilerDriver.srcNode = node; @@ -68,7 +68,7 @@ function generateDTs(node: ts.SourceFile, options: ts.CompilerOptions) { compilerDriver.showStatistics(); } -function main(fileNames: string[], options: ts.CompilerOptions, inputJsonFiles?: string[], cmdArgsSet?: Map) { +function main(fileNames: string[], options: ts.CompilerOptions, inputJsonFiles?: string[], cmdArgsSet?: Map): void { const host = ts.createCompilerHost(options); if (!CmdOptions.needGenerateTmpFile()) { host.writeFile = () => {}; @@ -211,7 +211,7 @@ function main(fileNames: string[], options: ts.CompilerOptions, inputJsonFiles?: }); } -function transformSourcefilesList(parsed: ts.ParsedCommandLine | undefined) { +function transformSourcefilesList(parsed: ts.ParsedCommandLine | undefined): void { let inputFile = CmdOptions.getCompileFilesList(); let sourceFileInfoArray = []; try { @@ -283,7 +283,7 @@ function getDtsFiles(libDir: string): string[] { return dtsFiles; } -function specifyCustomLib(customLib) { +function specifyCustomLib(customLib): void { Compiler.Options.Default["lib"] = customLib; let curFiles = fs.readdirSync(__dirname); const { execSync } = require('child_process'); @@ -318,7 +318,7 @@ const es2abcDebuggerEvaluateFlag = "--debugger-evaluate-expression"; const es2abcBase64Output = "--base64Output"; // need to specify the record name as 'Base64Output' in es2abc's commandline; cancel the opMergeAbc option -function callEs2pandaToolChain(ideInputStr: string) { +function callEs2pandaToolChain(ideInputStr: string): void { let commandLine = "\"" + es2abcBinaryPath + es2abcBinaryName + "\" " + es2abcBase64Input + " \"" + ideInputStr + "\" " + es2abcDebuggerEvaluateFlag + " " + es2abcBase64Output; var exec = require('child_process').exec; @@ -331,7 +331,7 @@ function callEs2pandaToolChain(ideInputStr: string) { }); } -function updateWatchJsFile() { +function updateWatchJsFile(): void { let ideInputStr = CmdOptions.getEvaluateExpression(); if (CmdOptions.watchViaEs2pandaToolchain()) { callEs2pandaToolChain(ideInputStr); @@ -385,7 +385,7 @@ function updateWatchJsFile() { } function compileWatchExpression(jsFileName: string, errorMsgFileName: string, options: ts.CompilerOptions, - watchedProgram: ts.Program) { + watchedProgram: ts.Program): void { CmdOptions.setWatchEvaluateExpressionArgs(['','']); let fileName = watchFileName + ".js"; let errorMsgRecordFlag = false; @@ -453,7 +453,7 @@ function compileWatchExpression(jsFileName: string, errorMsgFileName: string, op ); } -function launchWatchEvaluateDeamon(parsed: ts.ParsedCommandLine | undefined) { +function launchWatchEvaluateDeamon(parsed: ts.ParsedCommandLine | undefined): void { if (CmdOptions.watchViaEs2pandaToolchain()) { console.log("startWatchingSuccess supportTimeout"); return; @@ -495,7 +495,7 @@ function launchWatchEvaluateDeamon(parsed: ts.ParsedCommandLine | undefined) { }); } -function checkDiagnosticsError(program: ts.Program) { +function checkDiagnosticsError(program: ts.Program): boolean { let diagnosticsFlag = false; let allDiagnostics = ts .getPreEmitDiagnostics(program); diff --git a/ts2panda/src/lexenv.ts b/ts2panda/src/lexenv.ts index 0b9ab61236053577fe8527f70cf3098e0ba4d5fe..fae0b870b16e166f24cbaff29b96fec89f682da8 100644 --- a/ts2panda/src/lexenv.ts +++ b/ts2panda/src/lexenv.ts @@ -49,7 +49,7 @@ abstract class VariableAccessBase { this.level = level; } - isLexVar() { + isLexVar(): boolean { return this.variable.isLexVar; } @@ -187,7 +187,7 @@ export class VariableAcessStore extends VariableAccessBase { } } -function checkConstAssignment(pg: PandaGen, v: Variable, expansion: IRNode[], node: ts.Node | NodeKind) { +function checkConstAssignment(pg: PandaGen, v: Variable, expansion: IRNode[], node: ts.Node | NodeKind): void { let nameReg = pg.getTemp(); if (v.isConst()) { expansion.push(loadAccumulatorString(v.getName())); diff --git a/ts2panda/src/lexicalBinder.ts b/ts2panda/src/lexicalBinder.ts index 37aaa5809a9a1ec5454793c618aef879b06dcab5..bfa8b1d0e72a92162d294b89d2dee4f25b05f323 100644 --- a/ts2panda/src/lexicalBinder.ts +++ b/ts2panda/src/lexicalBinder.ts @@ -41,11 +41,11 @@ export class LexicalBinder { this.recorder = recorder; } - resolve() { + resolve(): void { this.resolveIdentReference(this.srcFile, this.recorder.getScopeOfNode(this.srcFile)); } - resolveIdentReference(node: ts.Node, scope: Scope) { + resolveIdentReference(node: ts.Node, scope: Scope): void { node.forEachChild((child) => { let tmp = this.recorder.getScopeOfNode(child); let newScope = tmp ? tmp : scope; @@ -135,7 +135,7 @@ export class LexicalBinder { }); } - lookUpLexicalReference(name: string, scope: Scope) { + lookUpLexicalReference(name: string, scope: Scope): void { let declPosInfo = scope.resolveDeclPos(name); if (!declPosInfo.isLexical) { // if find declaration position in the current function return; @@ -154,7 +154,7 @@ export class LexicalBinder { declPosInfo.v.setLexVar(declPosInfo.defLexicalScope); } - setMandatoryParamLexical(name: string, scope: VariableScope) { + setMandatoryParamLexical(name: string, scope: VariableScope): void { if (ts.isArrowFunction(scope.getBindingNode())) { throw new Error("Arrow function should not be processed"); } @@ -163,7 +163,7 @@ export class LexicalBinder { v.setLexVar(scope); } - setMandatoryParamLexicalForNCFuncInDebug(scope: VariableScope) { + setMandatoryParamLexicalForNCFuncInDebug(scope: VariableScope): void { if (!ts.isArrowFunction(scope.getBindingNode())) { throw new Error("Non-ArrowFunction should not be processed"); } @@ -222,7 +222,7 @@ export class LexicalBinder { return false; } - isPropertyName(id: ts.Identifier) { + isPropertyName(id: ts.Identifier): boolean { let parent = id.parent; if (ts.isPropertyAccessExpression(parent) && (parent.name == id)) { // eg. a.b -> b is the property name return true; diff --git a/ts2panda/src/log.ts b/ts2panda/src/log.ts index 88a49b074c7ca75aa0e423fdc53cc98df0237798..5feb926f403598fe1347f7edaf7062697cf12075 100644 --- a/ts2panda/src/log.ts +++ b/ts2panda/src/log.ts @@ -17,7 +17,7 @@ import * as ts from "typescript"; import { CmdOptions } from "./cmdOptions"; -export function LOGD(tag: any, ...args: any[]) { +export function LOGD(tag: any, ...args: any[]): void { if (CmdOptions.isEnableDebugLog()) { if (tag) { console.log(tag + ": " + args); @@ -27,7 +27,7 @@ export function LOGD(tag: any, ...args: any[]) { } } -export function LOGE(tag: any, ...args: any[]) { +export function LOGE(tag: any, ...args: any[]): void { if (tag) { console.error(tag + ": " + args); } else { @@ -35,7 +35,7 @@ export function LOGE(tag: any, ...args: any[]) { } } -export function printAstRecursively(node: ts.Node, indentLevel: number, sourceFile: ts.SourceFile) { +export function printAstRecursively(node: ts.Node, indentLevel: number, sourceFile: ts.SourceFile): void { if (CmdOptions.isEnableDebugLog()) { const indentation = "-".repeat(indentLevel); let nodeContent = ts.SyntaxKind[node.kind] + ": "; diff --git a/ts2panda/src/modules.ts b/ts2panda/src/modules.ts index ddb83fa5f66b384e1b908eabbc7591be3c84a84d..3fa914bd662e61146cd5764d6fd52fa5f5ade714 100644 --- a/ts2panda/src/modules.ts +++ b/ts2panda/src/modules.ts @@ -31,38 +31,38 @@ export class ModuleStmt { this.moduleRequest = moduleRequest; } - getNode() { + getNode(): ts.Node { return this.node; } - getModuleRequest() { + getModuleRequest(): string { return this.moduleRequest; } - addLocalName(localName: string, importName: string) { + addLocalName(localName: string, importName: string): void { if (this.bingdingNameMap.has(localName)) { throw new DiagnosticError(this.node, DiagnosticCode.Duplicate_identifier_0, jshelpers.getSourceFileOfNode(this.node), [localName]); } this.bingdingNameMap.set(localName, importName); } - getBindingNameMap() { + getBindingNameMap(): Map { return this.bingdingNameMap; } - addNodeMap(name: ts.Node, propertyName: ts.Node) { + addNodeMap(name: ts.Node, propertyName: ts.Node): void { this.bingdingNodeMap.set(name, propertyName); } - getBindingNodeMap() { + getBindingNodeMap(): Map { return this.bingdingNodeMap; } - setNameSpace(namespace: string) { + setNameSpace(namespace: string): void { this.namespace = namespace; } - getNameSpace() { + getNameSpace(): string { return this.namespace; } @@ -70,7 +70,7 @@ export class ModuleStmt { this.isCopy = isCopy; } - getCopyFlag() { + getCopyFlag(): boolean { return this.isCopy; } } diff --git a/ts2panda/src/pandagen.ts b/ts2panda/src/pandagen.ts index dd46cd8f7a4f3b3b5c72ae8854053b2c36d9a271..38df9c1e241aa223b6c76dce2bdf264d88493e67 100644 --- a/ts2panda/src/pandagen.ts +++ b/ts2panda/src/pandagen.ts @@ -397,22 +397,22 @@ export class PandaGen { PandaGen.literalArrayBuffer[index] = typeBuf; } - getFirstStmt() { + getFirstStmt(): ts.Statement { return this.firstStmt; } - setFirstStmt(firstStmt: ts.Statement) { + setFirstStmt(firstStmt: ts.Statement): void { if (this.firstStmt) { return; } this.firstStmt = firstStmt; } - getVregisterCache() { + getVregisterCache(): VregisterCache { return this.vregisterCache; } - getCatchMap() { + getCatchMap(): Map { return this.catchMap; } @@ -424,7 +424,7 @@ export class PandaGen { return this.variableDebugInfoArray; } - addDebugVariableInfo(variable: VariableDebugInfo) { + addDebugVariableInfo(variable: VariableDebugInfo): void { this.variableDebugInfoArray.push(variable); } @@ -454,7 +454,7 @@ export class PandaGen { return retval; } - freeTemps(...temps: VReg[]) { + freeTemps(...temps: VReg[]): void { this.temps.unshift(...temps); } @@ -462,11 +462,11 @@ export class PandaGen { return this.insns; } - setInsns(insns: IRNode[]) { + setInsns(insns: IRNode[]): void { this.insns = insns; } - printInsns() { + printInsns(): void { LOGE("function " + this.internalName + "() {"); this.getInsns().forEach(ins => { LOGE(ins.toString()); @@ -474,7 +474,7 @@ export class PandaGen { LOGE("}"); } - setTotalRegsNum(num: number) { + setTotalRegsNum(num: number): void { this.totalRegsNum = num; } @@ -482,7 +482,7 @@ export class PandaGen { return this.totalRegsNum; } - setParametersCount(count: number) { + setParametersCount(count: number): void { this.parametersCount = count; } @@ -490,7 +490,7 @@ export class PandaGen { return this.parametersCount; } - setLocals(locals: VReg[]) { + setLocals(locals: VReg[]): void { this.locals = locals; } @@ -502,19 +502,19 @@ export class PandaGen { return this.temps; } - getInstTypeMap() { + getInstTypeMap(): Map { return this.instTypeMap; } - getNode() { + getNode(): ts.SourceFile | ts.FunctionLikeDeclaration { return this.node; } - storeAccumulator(node: ts.Node | NodeKind, vreg: VReg) { + storeAccumulator(node: ts.Node | NodeKind, vreg: VReg): void { this.add(node, storeAccumulator(vreg)); } - generatorYield(node: ts.Node, genObj: VReg) { + generatorYield(node: ts.Node, genObj: VReg): void { this.add( node, loadAccumulator(genObj), @@ -522,7 +522,7 @@ export class PandaGen { ) } - generatorComplete(node: ts.Node | NodeKind, genObj: VReg) { + generatorComplete(node: ts.Node | NodeKind, genObj: VReg): void { this.add( node, loadAccumulator(genObj), @@ -530,7 +530,7 @@ export class PandaGen { ) } - loadAccFromArgs(node: ts.Node) { + loadAccFromArgs(node: ts.Node): void { if ((this.scope).getUseArgs()) { let v = this.scope!.findLocal(MandatoryArguments); if (this.scope instanceof FunctionScope) { @@ -546,15 +546,15 @@ export class PandaGen { } } - deleteObjProperty(node: ts.Node, obj: VReg) { + deleteObjProperty(node: ts.Node, obj: VReg): void { this.add(node, deleteObjProperty(obj)); } - loadAccumulator(node: ts.Node | NodeKind, vreg: VReg) { + loadAccumulator(node: ts.Node | NodeKind, vreg: VReg): void { this.add(node, loadAccumulator(vreg)); } - createLexEnv(node: ts.Node, scope: VariableScope | LoopScope) { + createLexEnv(node: ts.Node, scope: VariableScope | LoopScope): void { let numVars = scope.getNumLexEnv(); let scopeInfoId: string | undefined = undefined; let lexVarInfo = scope.getLexVarInfo(); @@ -568,21 +568,21 @@ export class PandaGen { ) } - newLexicalEnv(node, numVars: number) { + newLexicalEnv(node, numVars: number): void { this.add( node, newLexicalEnv(numVars, undefined), ) } - popLexicalEnv(node: ts.Node) { + popLexicalEnv(node: ts.Node): void { this.add( node, popLexicalEnv() ) } - loadAccFromLexEnv(node: ts.Node, scope: Scope, level: number, v: Variable) { + loadAccFromLexEnv(node: ts.Node, scope: Scope, level: number, v: Variable): void { let expander = new VariableAccessLoad(scope, level, v); let insns = expander.expand(this); this.add( @@ -591,7 +591,7 @@ export class PandaGen { ); } - storeAccToLexEnv(node: ts.Node | NodeKind, scope: Scope, level: number, v: Variable, isDeclaration: boolean) { + storeAccToLexEnv(node: ts.Node | NodeKind, scope: Scope, level: number, v: Variable, isDeclaration: boolean): void { let expander = new VariableAcessStore(scope, level, v, isDeclaration, node); let insns = expander.expand(this); this.add( @@ -600,7 +600,7 @@ export class PandaGen { ) } - loadObjProperty(node: ts.Node, obj: VReg, prop: VReg | string | number) { + loadObjProperty(node: ts.Node, obj: VReg, prop: VReg | string | number): void { switch (typeof (prop)) { case "number": { if (isInteger(prop)) { @@ -625,7 +625,7 @@ export class PandaGen { } } - storeObjProperty(node: ts.Node | NodeKind, obj: VReg, prop: VReg | string | number) { + storeObjProperty(node: ts.Node | NodeKind, obj: VReg, prop: VReg | string | number): void { switch (typeof (prop)) { case "number": if (isInteger(prop)) { @@ -652,7 +652,7 @@ export class PandaGen { } } - storeOwnProperty(node: ts.Node | NodeKind, obj: VReg, prop: VReg | string | number, nameSetting: boolean = false) { + storeOwnProperty(node: ts.Node | NodeKind, obj: VReg, prop: VReg | string | number, nameSetting: boolean = false): void { switch (typeof prop) { case "number": { if (isInteger(prop)) { @@ -680,7 +680,7 @@ export class PandaGen { } } - private loadObjByName(node: ts.Node, obj: VReg, string_id: string) { + private loadObjByName(node: ts.Node, obj: VReg, string_id: string): void { this.add( node, loadAccumulator(obj), @@ -688,14 +688,14 @@ export class PandaGen { ); } - private storeObjByName(node: ts.Node | NodeKind, obj: VReg, string_id: string) { + private storeObjByName(node: ts.Node | NodeKind, obj: VReg, string_id: string): void { this.add( node, storeObjByName(obj, string_id) ); } - private loadObjByIndex(node: ts.Node, obj: VReg, index: number) { + private loadObjByIndex(node: ts.Node, obj: VReg, index: number): void { this.add( node, loadAccumulator(obj), @@ -703,7 +703,7 @@ export class PandaGen { ) } - private storeObjByIndex(node: ts.Node | NodeKind, obj: VReg, index: number) { + private storeObjByIndex(node: ts.Node | NodeKind, obj: VReg, index: number): void { this.add( node, storeObjByIndex(obj, index) @@ -711,7 +711,7 @@ export class PandaGen { } - private loadObjByValue(node: ts.Node, obj: VReg, value: VReg) { + private loadObjByValue(node: ts.Node, obj: VReg, value: VReg): void { this.add( node, loadAccumulator(value), @@ -719,26 +719,26 @@ export class PandaGen { ) } - private storeObjByValue(node: ts.Node | NodeKind, obj: VReg, prop: VReg) { + private storeObjByValue(node: ts.Node | NodeKind, obj: VReg, prop: VReg): void { this.add( node, storeObjByValue(obj, prop) ) } - private stOwnByName(node: ts.Node | NodeKind, obj: VReg, string_id: string, nameSetting: boolean) { + private stOwnByName(node: ts.Node | NodeKind, obj: VReg, string_id: string, nameSetting: boolean): void { this.add(node, storeOwnByName(obj, string_id, nameSetting)); } - private stOwnByIndex(node: ts.Node | NodeKind, obj: VReg, index: number) { + private stOwnByIndex(node: ts.Node | NodeKind, obj: VReg, index: number): void { this.add(node, storeOwnByIndex(obj, index)); } - private stOwnByValue(node: ts.Node | NodeKind, obj: VReg, value: VReg, nameSetting: boolean) { + private stOwnByValue(node: ts.Node | NodeKind, obj: VReg, value: VReg, nameSetting: boolean): void { this.add(node, storeOwnByValue(obj, value, nameSetting)); } - loadByNameViaDebugger(node: ts.Node, string_id: string, boolVal: CacheList) { + loadByNameViaDebugger(node: ts.Node, string_id: string, boolVal: CacheList): void { this.loadObjProperty(node, getVregisterCache(this, CacheList.Global), "debuggerGetValue"); let getValueReg = this.getTemp(); this.storeAccumulator(node, getValueReg); @@ -752,12 +752,12 @@ export class PandaGen { } // eg. print - tryLoadGlobalByName(node: ts.Node, string_id: string) { + tryLoadGlobalByName(node: ts.Node, string_id: string): void { CmdOptions.isWatchEvaluateExpressionMode() ? this.loadByNameViaDebugger(node, string_id, CacheList.True) : this.add(node, tryLoadGlobalByName(string_id)); } - storeByNameViaDebugger(node: ts.Node, string_id: string) { + storeByNameViaDebugger(node: ts.Node, string_id: string): void { let valueReg = this.getTemp(); this.storeAccumulator(node, valueReg); this.loadObjProperty(node, getVregisterCache(this, CacheList.Global), "debuggerSetValue"); @@ -771,68 +771,68 @@ export class PandaGen { } // eg. a = 1 - tryStoreGlobalByName(node: ts.Node, string_id: string) { + tryStoreGlobalByName(node: ts.Node, string_id: string): void { CmdOptions.isWatchEvaluateExpressionMode() ? this.storeByNameViaDebugger(node, string_id) : this.add(node, tryStoreGlobalByName(string_id)); } // eg. var n; n; - loadGlobalVar(node: ts.Node, string_id: string) { + loadGlobalVar(node: ts.Node, string_id: string): void { this.add( node, loadGlobalVar(string_id)); } // var n = 1; - storeGlobalVar(node: ts.Node | NodeKind, string_id: string) { + storeGlobalVar(node: ts.Node | NodeKind, string_id: string): void { this.add( node, storeGlobalVar(string_id)); } - loadAccumulatorString(node: ts.Node | NodeKind, str: string) { + loadAccumulatorString(node: ts.Node | NodeKind, str: string): void { this.add(node, loadAccumulatorString(str)); } - loadAccumulatorFloat(node: ts.Node, num: number) { + loadAccumulatorFloat(node: ts.Node, num: number): void { this.add(node, loadAccumulatorFloat(num)); } - loadAccumulatorInt(node: ts.Node, num: number) { + loadAccumulatorInt(node: ts.Node, num: number): void { this.add(node, loadAccumulatorInt(num)); } - moveVreg(node: ts.Node | NodeKind, vd: VReg, vs: VReg) { + moveVreg(node: ts.Node | NodeKind, vd: VReg, vs: VReg): void { this.add(node, moveVreg(vd, vs)); } // @ts-ignore - label(node: ts.Node, label: Label) { + label(node: ts.Node, label: Label): void { this.add(NodeKind.Invalid, label); } - branch(node: ts.Node | NodeKind, target: Label) { + branch(node: ts.Node | NodeKind, target: Label): void { this.add(node, jumpTarget(target)); } - branchIfNotUndefined(node: ts.Node, target: Label) { + branchIfNotUndefined(node: ts.Node, target: Label): void { // the compared value is in acc this.condition(node, ts.SyntaxKind.EqualsEqualsToken, getVregisterCache(this, CacheList.undefined), target); } - branchIfUndefined(node: ts.Node, target: Label) { + branchIfUndefined(node: ts.Node, target: Label): void { // the compared value is in acc this.condition(node, ts.SyntaxKind.ExclamationEqualsToken, getVregisterCache(this, CacheList.undefined), target) } - isTrue(node: ts.Node) { + isTrue(node: ts.Node): void { this.add( node, isTrue() ) } - jumpIfTrue(node: ts.Node, target: Label) { + jumpIfTrue(node: ts.Node, target: Label): void { this.isFalse(node); this.add( node, @@ -840,14 +840,14 @@ export class PandaGen { ) } - isFalse(node: ts.Node) { + isFalse(node: ts.Node): void { this.add( node, isFalse() ) } - jumpIfFalse(node: ts.Node, target: Label) { + jumpIfFalse(node: ts.Node, target: Label): void { this.isTrue(node); this.add( node, @@ -855,46 +855,46 @@ export class PandaGen { ) } - debugger(node: ts.Node) { + debugger(node: ts.Node): void { this.add(node, creatDebugger()); } - throwUndefinedIfHole(node: ts.Node, name: string) { + throwUndefinedIfHole(node: ts.Node, name: string): void { this.add( node, throwUndefinedIfHole(name) ) } - less(node: ts.Node, lhs: VReg) { + less(node: ts.Node, lhs: VReg): void { this.add(node, new Less(new Imm(0), lhs)); } - greater(node: ts.Node, lhs: VReg) { + greater(node: ts.Node, lhs: VReg): void { this.add(node, new Greater(new Imm(0), lhs)); } - greaterEq(node: ts.Node, lhs: VReg) { + greaterEq(node: ts.Node, lhs: VReg): void { this.add(node, new Greatereq(new Imm(0), lhs)); } - lessEq(node: ts.Node, lhs: VReg) { + lessEq(node: ts.Node, lhs: VReg): void { this.add(node, new Lesseq(new Imm(0), lhs)); } - equal(node: ts.Node, lhs: VReg) { + equal(node: ts.Node, lhs: VReg): void { this.add(node, new Eq(new Imm(0), lhs)); } - notEqual(node: ts.Node, lhs: VReg) { + notEqual(node: ts.Node, lhs: VReg): void { this.add(node, new Noteq(new Imm(0), lhs)); } - strictEqual(node: ts.Node, lhs: VReg) { + strictEqual(node: ts.Node, lhs: VReg): void { this.add(node, new Stricteq(new Imm(0), lhs)); } - strictNotEqual(node: ts.Node, lhs: VReg) { + strictNotEqual(node: ts.Node, lhs: VReg): void { this.add(node, new Strictnoteq(new Imm(0), lhs)); } @@ -903,7 +903,7 @@ export class PandaGen { * if (lhs OP acc) {...} * ifFalse: ... */ - condition(node: ts.Node, op: SyntaxKind, lhs: VReg, ifFalse: Label) { + condition(node: ts.Node, op: SyntaxKind, lhs: VReg, ifFalse: Label): void { // Please keep order of cases the same as in types.ts switch (op) { case SyntaxKind.LessThanToken: // line 57 @@ -943,7 +943,7 @@ export class PandaGen { } } - unary(node: ts.Node, op: PrefixUnaryOperator, operand: VReg) { + unary(node: ts.Node, op: PrefixUnaryOperator, operand: VReg): void { switch (op) { case SyntaxKind.PlusToken: this.toNumber(node, operand); @@ -989,7 +989,7 @@ export class PandaGen { } } - binary(node: ts.Node, op: BinaryOperator, lhs: VReg) { + binary(node: ts.Node, op: BinaryOperator, lhs: VReg): void { switch (op) { case SyntaxKind.LessThanToken: // line 57 case SyntaxKind.GreaterThanToken: // line 59 @@ -1066,30 +1066,30 @@ export class PandaGen { // throw needs argument of exceptionVreg // to ensure rethrow the exception after finally - throw(node: ts.Node) { + throw(node: ts.Node): void { this.add( node, throwException() ); } - throwThrowNotExist(node: ts.Node) { + throwThrowNotExist(node: ts.Node): void { this.add(node, throwThrowNotExists()); } - throwDeleteSuperProperty(node: ts.Node) { + throwDeleteSuperProperty(node: ts.Node): void { this.add(node, throwDeleteSuperProperty()); } - throwConstAssignment(node: ts.Node, nameReg: VReg) { + throwConstAssignment(node: ts.Node, nameReg: VReg): void { this.add(node, throwConstAssignment(nameReg)); } - return(node: ts.Node | NodeKind) { + return(node: ts.Node | NodeKind): void { this.add(node, new Return()); } - call(node: ts.Node, args: VReg[], passThis: boolean) { + call(node: ts.Node, args: VReg[], passThis: boolean): void { this.add( node, loadAccumulator(args[0]), // callee is stored in acc @@ -1097,21 +1097,21 @@ export class PandaGen { ) } - returnUndefined(node: ts.Node | NodeKind) { + returnUndefined(node: ts.Node | NodeKind): void { this.add( node, returnUndefined() ) } - newObject(node: ts.Node, args: VReg[]) { + newObject(node: ts.Node, args: VReg[]): void { this.add( node, newObject(args) ); } - defineMethod(node: ts.FunctionLikeDeclaration, name: string, objReg: VReg) { + defineMethod(node: ts.FunctionLikeDeclaration, name: string, objReg: VReg): void { let paramLength = getParamLengthOfFunc(node); this.add( node, @@ -1120,7 +1120,7 @@ export class PandaGen { ); } - defineFunction(node: ts.FunctionLikeDeclaration | NodeKind, realNode: ts.FunctionLikeDeclaration, name: string) { + defineFunction(node: ts.FunctionLikeDeclaration | NodeKind, realNode: ts.FunctionLikeDeclaration, name: string): void { let paramLength = getParamLengthOfFunc(realNode); this.add( node, @@ -1128,125 +1128,125 @@ export class PandaGen { ); } - typeOf(node: ts.Node) { + typeOf(node: ts.Node): void { this.add(node, new Typeof(new Imm(0))); } - callSpread(node: ts.Node, func: VReg, thisReg: VReg, args: VReg) { + callSpread(node: ts.Node, func: VReg, thisReg: VReg, args: VReg): void { this.loadAccumulator(node, func); this.add(node, new Apply(new Imm(0), thisReg, args)); } - newObjSpread(node: ts.Node, obj: VReg) { + newObjSpread(node: ts.Node, obj: VReg): void { this.add(node, new Newobjapply(new Imm(0), obj)); } - getUnmappedArgs(node: ts.Node) { + getUnmappedArgs(node: ts.Node): void { this.add(node, new Getunmappedargs()); } - toNumber(node: ts.Node, arg: VReg) { + toNumber(node: ts.Node, arg: VReg): void { this.loadAccumulator(node, arg); this.add(node, new Tonumber(new Imm(0))); } - toNumeric(node: ts.Node, arg: VReg) { + toNumeric(node: ts.Node, arg: VReg): void { this.loadAccumulator(node, arg); this.add(node, new Tonumeric(new Imm(0))); } - createGeneratorObj(node: ts.Node, funcObj: VReg) { + createGeneratorObj(node: ts.Node, funcObj: VReg): void { this.add(node, new Creategeneratorobj(funcObj)); } - createAsyncGeneratorObj(node: ts.Node, funcObj: VReg) { + createAsyncGeneratorObj(node: ts.Node, funcObj: VReg): void { this.add(node, new Createasyncgeneratorobj(funcObj)); } - Createiterresultobj(node: ts.Node, value: VReg, done: VReg) { + Createiterresultobj(node: ts.Node, value: VReg, done: VReg): void { this.add(node, new Createiterresultobj(value, done)); } - asyncgeneratorresolve(node: ts.Node | NodeKind, genObj: VReg, value: VReg, done: VReg) { + asyncgeneratorresolve(node: ts.Node | NodeKind, genObj: VReg, value: VReg, done: VReg): void { this.add(node, new Asyncgeneratorresolve(genObj, value, done)); } - asyncgeneratorreject(node: ts.Node, genObj: VReg) { + asyncgeneratorreject(node: ts.Node, genObj: VReg): void { this.add(node, new Asyncgeneratorreject(genObj)); } - suspendGenerator(node: ts.Node | NodeKind, genObj: VReg) { + suspendGenerator(node: ts.Node | NodeKind, genObj: VReg): void { this.add(node, new Suspendgenerator(genObj)); // promise obj is in acc } - resumeGenerator(node: ts.Node | NodeKind, genObj: VReg) { + resumeGenerator(node: ts.Node | NodeKind, genObj: VReg): void { this.add( node, loadAccumulator(genObj), new Resumegenerator()); } - getResumeMode(node: ts.Node | NodeKind, genObj: VReg) { + getResumeMode(node: ts.Node | NodeKind, genObj: VReg): void { this.add( node, loadAccumulator(genObj), new Getresumemode()); } - asyncFunctionEnter(node: ts.Node | NodeKind) { + asyncFunctionEnter(node: ts.Node | NodeKind): void { this.add(node, new Asyncfunctionenter()); } - asyncFunctionAwaitUncaught(node: ts.Node | NodeKind, asynFuncObj: VReg) { + asyncFunctionAwaitUncaught(node: ts.Node | NodeKind, asynFuncObj: VReg): void { this.add(node, new Asyncfunctionawaituncaught(asynFuncObj)); // received value is in acc } - asyncFunctionResolve(node: ts.Node | NodeKind, asyncObj: VReg) { + asyncFunctionResolve(node: ts.Node | NodeKind, asyncObj: VReg): void { this.add(node, new Asyncfunctionresolve(asyncObj)); // use retVal in acc } - asyncFunctionReject(node: ts.Node | NodeKind, asyncObj: VReg) { + asyncFunctionReject(node: ts.Node | NodeKind, asyncObj: VReg): void { this.add(node, new Asyncfunctionreject(asyncObj)); // exception is in acc } - getTemplateObject(node: ts.Node | NodeKind, value: VReg) { + getTemplateObject(node: ts.Node | NodeKind, value: VReg): void { this.loadAccumulator(node, value); this.add(node, new Gettemplateobject(new Imm(0))); } - copyRestArgs(node: ts.Node, index: number) { + copyRestArgs(node: ts.Node, index: number): void { this.add(node, index <= MAX_INT8 ? new Copyrestargs(new Imm(index)) : new WideCopyrestargs(new Imm(index))); } - getPropIterator(node: ts.Node) { + getPropIterator(node: ts.Node): void { this.add(node, getPropIterator()); } - getNextPropName(node: ts.Node, iter: VReg) { + getNextPropName(node: ts.Node, iter: VReg): void { this.add(node, getNextPropName(iter)); } - createEmptyObject(node: ts.Node) { + createEmptyObject(node: ts.Node): void { this.add(node, createEmptyObject()); } - createObjectWithBuffer(node: ts.Node, bufferId: string) { + createObjectWithBuffer(node: ts.Node, bufferId: string): void { this.add(node, createObjectWithBuffer(bufferId)); } - setObjectWithProto(node: ts.Node, proto: VReg, object: VReg) { + setObjectWithProto(node: ts.Node, proto: VReg, object: VReg): void { this.add( node, loadAccumulator(object), setObjectWithProto(proto)); } - copyDataProperties(node: ts.Node, dstObj: VReg) { + copyDataProperties(node: ts.Node, dstObj: VReg): void { this.add(node, copyDataProperties(dstObj)); } - defineGetterSetterByValue(node: ts.Node, obj: VReg, name: VReg, getter: VReg, setter: VReg, isComputedPropertyName: boolean) { + defineGetterSetterByValue(node: ts.Node, obj: VReg, name: VReg, getter: VReg, setter: VReg, isComputedPropertyName: boolean): void { if (isComputedPropertyName) { this.add(node, loadAccumulator(getVregisterCache(this, CacheList.True))); } else { @@ -1255,19 +1255,19 @@ export class PandaGen { this.add(node, defineGetterSetterByValue(obj, name, getter, setter)); } - createEmptyArray(node: ts.Node) { + createEmptyArray(node: ts.Node): void { this.add(node, createEmptyArray()); } - createArrayWithBuffer(node: ts.Node, bufferId: string) { + createArrayWithBuffer(node: ts.Node, bufferId: string): void { this.add(node, createArrayWithBuffer(bufferId)); } - storeArraySpreadElement(node: ts.Node, array: VReg, index: VReg) { + storeArraySpreadElement(node: ts.Node, array: VReg, index: VReg): void { this.add(node, storeArraySpread(array, index)); } - storeLexicalVar(node: ts.Node, level: number, slot: number, value: VReg) { + storeLexicalVar(node: ts.Node, level: number, slot: number, value: VReg): void { this.loadAccumulator(node, value); // value is load to acc this.add( node, @@ -1275,14 +1275,14 @@ export class PandaGen { ); } - loadLexicalVar(node: ts.Node, level: number, slot: number) { + loadLexicalVar(node: ts.Node, level: number, slot: number): void { this.add( node, loadLexicalVar(level, slot) ) } - loadModuleVariable(node: ts.Node, v: ModuleVariable, isLocal: boolean) { + loadModuleVariable(node: ts.Node, v: ModuleVariable, isLocal: boolean): void { let index: number = v.getIndex(); let typeIndex: number = v.getTypeIndex(); // For local module variable, we bind type with storeModuleVariable instruction @@ -1298,7 +1298,7 @@ export class PandaGen { } } - storeModuleVariable(node: ts.Node | NodeKind, v: ModuleVariable) { + storeModuleVariable(node: ts.Node | NodeKind, v: ModuleVariable): void { let index: number = v.getIndex(); let typeIndex: number = v.getTypeIndex(); let stModuleVarInst: IRNode = storeModuleVariable(index); @@ -1306,64 +1306,64 @@ export class PandaGen { this.add(node, stModuleVarInst); } - getModuleNamespace(node: ts.Node, moduleRequestIdx: number) { + getModuleNamespace(node: ts.Node, moduleRequestIdx: number): void { this.add(node, getModuleNamespace(moduleRequestIdx)); } - dynamicImportCall(node: ts.Node) { + dynamicImportCall(node: ts.Node): void { this.add(node, dynamicImport()); } - defineClassWithBuffer(node: ts.Node, name: string, litId: string, parameterLength: number, base: VReg) { + defineClassWithBuffer(node: ts.Node, name: string, litId: string, parameterLength: number, base: VReg): void { this.add( node, defineClassWithBuffer(name, litId, parameterLength, base) ) } - createObjectWithExcludedKeys(node: ts.Node, obj: VReg, args: VReg[]) { + createObjectWithExcludedKeys(node: ts.Node, obj: VReg, args: VReg[]): void { this.add( node, createObjectWithExcludedKeys(obj, args) ); } - throwObjectNonCoercible(node: ts.Node) { + throwObjectNonCoercible(node: ts.Node): void { this.add( node, throwObjectNonCoercible() ); } - getIterator(node: ts.Node) { + getIterator(node: ts.Node): void { this.add( node, getIterator() ); } - getAsyncIterator(node: ts.Node) { + getAsyncIterator(node: ts.Node): void { this.add( node, new Getasynciterator(new Imm(0)) ) } - closeIterator(node: ts.Node, iter: VReg) { + closeIterator(node: ts.Node, iter: VReg): void { this.add( node, closeIterator(iter) ) } - throwIfNotObject(node: ts.Node, obj: VReg) { + throwIfNotObject(node: ts.Node, obj: VReg): void { this.add( node, throwIfNotObject(obj) ); } - superCall(node: ts.Node, num: number, args: Array) { + superCall(node: ts.Node, num: number, args: Array): void { if (ts.isArrowFunction(jshelpers.getContainingFunction(node))) { this.add( node, @@ -1378,11 +1378,11 @@ export class PandaGen { ) } - superCallSpread(node: ts.Node, vs: VReg) { + superCallSpread(node: ts.Node, vs: VReg): void { this.add(node, superCallSpread(vs)); } - ldSuperByName(node: ts.Node, obj: VReg, key: string) { + ldSuperByName(node: ts.Node, obj: VReg, key: string): void { this.add( node, loadAccumulator(obj), @@ -1390,28 +1390,28 @@ export class PandaGen { ) } - stSuperByName(node: ts.Node, obj: VReg, key: string) { + stSuperByName(node: ts.Node, obj: VReg, key: string): void { this.add( node, stSuperByName(obj, key) ) } - ldSuperByValue(node: ts.Node, obj: VReg) { + ldSuperByValue(node: ts.Node, obj: VReg): void { this.add( node, ldSuperByValue(obj) ) } - stSuperByValue(node: ts.Node, obj: VReg, prop: VReg) { + stSuperByValue(node: ts.Node, obj: VReg, prop: VReg): void { this.add( node, stSuperByValue(obj, prop) ) } - loadSuperProperty(node: ts.Node, obj: VReg, prop: VReg | string | number) { + loadSuperProperty(node: ts.Node, obj: VReg, prop: VReg | string | number): void { switch (typeof (prop)) { case "string": this.ldSuperByName(node, obj, prop); @@ -1426,11 +1426,11 @@ export class PandaGen { } } - throwIfSuperNotCorrectCall(node: ts.Node, num: number) { + throwIfSuperNotCorrectCall(node: ts.Node, num: number): void { this.add(node, throwIfSuperNotCorrectCall(num)); } - storeSuperProperty(node: ts.Node, obj: VReg, prop: VReg | string | number) { + storeSuperProperty(node: ts.Node, obj: VReg, prop: VReg | string | number): void { switch (typeof (prop)) { case "string": this.stSuperByName(node, obj, prop); @@ -1447,37 +1447,37 @@ export class PandaGen { } } - createRegExpWithLiteral(node: ts.Node, pattern: string, flags: number) { + createRegExpWithLiteral(node: ts.Node, pattern: string, flags: number): void { this.add( node, createRegExpWithLiteral(pattern, flags) ) } - stLetOrClassToGlobalRecord(node: ts.Node, string_id: string) { + stLetOrClassToGlobalRecord(node: ts.Node, string_id: string): void { this.add( node, stLetOrClassToGlobalRecord(string_id)); } - stConstToGlobalRecord(node: ts.Node, string_id: string) { + stConstToGlobalRecord(node: ts.Node, string_id: string): void { this.add( node, stConstToGlobalRecord(string_id)); } - loadAccumulatorBigInt(node: ts.Node | NodeKind, str: string) { + loadAccumulatorBigInt(node: ts.Node | NodeKind, str: string): void { this.add( node, loadAccumulatorBigInt(str)); } - storeConst(node: ts.Node | NodeKind, dst: VReg, value: CacheList) { + storeConst(node: ts.Node | NodeKind, dst: VReg, value: CacheList): void { this.loadAccumulator(node, getVregisterCache(this, value)); this.storeAccumulator(node, dst); } - private binaryRelation(node: ts.Node, op: BinaryOperator, lhs: VReg) { + private binaryRelation(node: ts.Node, op: BinaryOperator, lhs: VReg): void { let falseLabel = new Label(); let endLabel = new Label(); switch (op) { diff --git a/ts2panda/src/recorder.ts b/ts2panda/src/recorder.ts index eea7f7f0fa18068c33872c643091466eadc5dc60..b16bbf06f19e1fc8ebc555017a599b77b679442b 100644 --- a/ts2panda/src/recorder.ts +++ b/ts2panda/src/recorder.ts @@ -82,24 +82,24 @@ export class Recorder { this.syntaxCheckStatus = syntaxCheckStatus; } - record() { + record(): ts.Node { this.setParent(this.node); this.setScopeMap(this.node, this.scope); this.recordInfo(this.node, this.scope); return this.node; } - getCtorOfClass(node: ts.ClassLikeDeclaration) { + getCtorOfClass(node: ts.ClassLikeDeclaration): ts.ConstructorDeclaration { return this.class2Ctor.get(node); } - setCtorOfClass(node: ts.ClassLikeDeclaration, ctor: ts.ConstructorDeclaration) { + setCtorOfClass(node: ts.ClassLikeDeclaration, ctor: ts.ConstructorDeclaration): void { if (!this.class2Ctor.has(node)) { this.class2Ctor.set(node, ctor); } } - private setParent(node: ts.Node) { + private setParent(node: ts.Node): void { node.forEachChild(childNode => { if (!this.isTsFile || childNode!.parent == undefined || childNode.parent.kind != node.kind) { childNode = jshelpers.setParent(childNode, node)!; @@ -110,7 +110,7 @@ export class Recorder { }); } - private recordInfo(node: ts.Node, scope: Scope) { + private recordInfo(node: ts.Node, scope: Scope): void { node.forEachChild(childNode => { if (this.syntaxCheckStatus) { checkSyntaxError(childNode, scope); @@ -255,7 +255,7 @@ export class Recorder { }); } - private recordClassInfo(childNode: ts.ClassLikeDeclaration, scope: Scope, isExport: boolean) { + private recordClassInfo(childNode: ts.ClassLikeDeclaration, scope: Scope, isExport: boolean): void { let localScope = new LocalScope(scope); this.setScopeMap(childNode, localScope); let ctor = extractCtorOfClass(childNode); @@ -273,7 +273,7 @@ export class Recorder { this.recordInfo(childNode, localScope); } - buildVariableScope(curScope: Scope, node: ts.FunctionLikeDeclaration) { + buildVariableScope(curScope: Scope, node: ts.FunctionLikeDeclaration): FunctionScope { let functionScope = new FunctionScope(curScope, node); let parentVariableScope = curScope.getNearestVariableScope(); functionScope.setParentVariableScope(parentVariableScope); @@ -282,7 +282,7 @@ export class Recorder { return functionScope; } - private recordVariableDecl(id: ts.Identifier, scope: Scope) { + private recordVariableDecl(id: ts.Identifier, scope: Scope): void { let name = jshelpers.getTextOfIdentifierOrLiteral(id); let parent = this.getDeclarationNodeOfId(id); @@ -487,7 +487,7 @@ export class Recorder { } } - private recordEcmaImportClause(importClause: ts.ImportClause, scope: ModuleScope, moduleRequest: string) { + private recordEcmaImportClause(importClause: ts.ImportClause, scope: ModuleScope, moduleRequest: string): void { // import defaultExport from "a.js" if (importClause.name) { let localName = jshelpers.getTextOfIdentifierOrLiteral(importClause.name); @@ -500,7 +500,7 @@ export class Recorder { } } - private recordEcmaImportInfo(node: ts.ImportDeclaration, scope: Scope) { + private recordEcmaImportInfo(node: ts.ImportDeclaration, scope: Scope): void { if (!(scope instanceof ModuleScope)) { return; } @@ -516,7 +516,7 @@ export class Recorder { } } - private recordEcmaExportDecl(node: ts.ExportDeclaration, scope: ModuleScope) { + private recordEcmaExportDecl(node: ts.ExportDeclaration, scope: ModuleScope): void { if (node.moduleSpecifier) { let moduleRequest: string = this.getModuleSpecifier(node.moduleSpecifier); @@ -555,7 +555,8 @@ export class Recorder { } } - private recordEcmaExportInfo(node: ts.ExportDeclaration | ts.ExportAssignment | ts.VariableStatement | ts.FunctionDeclaration | ts.ClassDeclaration, scope: Scope) { + private recordEcmaExportInfo(node: ts.ExportDeclaration | ts.ExportAssignment | ts.VariableStatement | ts.FunctionDeclaration | ts.ClassDeclaration, + scope: Scope): void { if (!(scope instanceof ModuleScope)) { return; } @@ -606,7 +607,7 @@ export class Recorder { } } - private recordFuncDecl(node: ts.FunctionDeclaration, scope: Scope, isExport: boolean) { + private recordFuncDecl(node: ts.FunctionDeclaration, scope: Scope, isExport: boolean): void { this.recordFuncInfo(node); let funcId = (node).name; @@ -635,7 +636,7 @@ export class Recorder { } } - private recordOtherFunc(node: ts.FunctionLikeDeclaration, scope: Scope) { // functionlikedecalration except function declaration + private recordOtherFunc(node: ts.FunctionLikeDeclaration, scope: Scope): void { // functionlikedecalration except function declaration this.recordFuncInfo(node); if (!ts.isFunctionExpression(node) && !ts.isMethodDeclaration(node)) { return; @@ -648,12 +649,12 @@ export class Recorder { } } - private recordFuncInfo(node: ts.FunctionLikeDeclaration) { + private recordFuncInfo(node: ts.FunctionLikeDeclaration): void { this.recordFunctionParameters(node); this.recordFuncName(node); } - recordFuncName(node: ts.FunctionLikeDeclaration) { + recordFuncName(node: ts.FunctionLikeDeclaration): void { let name: string = ''; if (ts.isConstructorDeclaration(node)) { let classNode = node.parent; @@ -704,7 +705,7 @@ export class Recorder { } } - recordFunctionParameters(node: ts.FunctionLikeDeclaration) { + recordFunctionParameters(node: ts.FunctionLikeDeclaration): void { let parameters = node.parameters; let funcParams: FunctionParameter[] = []; let length = 0; @@ -732,7 +733,7 @@ export class Recorder { this.setParametersMap(node, funcParams); } - recordPatternParameter(pattern: ts.BindingPattern, funcParams: Array) { + recordPatternParameter(pattern: ts.BindingPattern, funcParams: Array): void { let name: string = ''; pattern.elements.forEach(bindingElement => { if (ts.isOmittedExpression(bindingElement)) { @@ -751,7 +752,7 @@ export class Recorder { } - isRestParameter(parameter: ts.ParameterDeclaration) { + isRestParameter(parameter: ts.ParameterDeclaration): boolean { return parameter.dotDotDotToken ? true : false; } @@ -780,19 +781,19 @@ export class Recorder { return false; } - setScopeMap(node: ts.Node, scope: Scope) { + setScopeMap(node: ts.Node, scope: Scope): void { this.scopeMap.set(node, scope); } - getScopeMap() { + getScopeMap(): Map { return this.scopeMap; } - getScopeOfNode(node: ts.Node) { + getScopeOfNode(node: ts.Node): Scope { return this.scopeMap.get(node); } - setHoistMap(scope: VariableScope, decl: Decl) { + setHoistMap(scope: VariableScope, decl: Decl): void { if (!this.hoistMap.has(scope)) { this.hoistMap.set(scope, [decl]); return; @@ -810,23 +811,23 @@ export class Recorder { hoistDecls.push(decl); } - getHoistMap() { + getHoistMap(): Map { return this.hoistMap; } - getHoistDeclsOfScope(scope: VariableScope) { + getHoistDeclsOfScope(scope: VariableScope): Decl[] { return this.hoistMap.get(scope); } - setParametersMap(node: ts.FunctionLikeDeclaration, parameters: FunctionParameter[]) { + setParametersMap(node: ts.FunctionLikeDeclaration, parameters: FunctionParameter[]): void { this.parametersMap.set(node, parameters); } - getParametersOfFunction(node: ts.FunctionLikeDeclaration) { + getParametersOfFunction(node: ts.FunctionLikeDeclaration): FunctionParameter[] { return this.parametersMap.get(node); } - getFuncNameMap() { + getFuncNameMap(): Map { return this.funcNameMap; } } diff --git a/ts2panda/src/regAllocator.ts b/ts2panda/src/regAllocator.ts index 790745246c363ea5f208adb7aff516a322dc875f..a563edbb7f93a4df450a061247a5586592590a68 100644 --- a/ts2panda/src/regAllocator.ts +++ b/ts2panda/src/regAllocator.ts @@ -41,7 +41,7 @@ class RegAllocator { this.vRegsId = 0; } - allocIndexForVreg(vreg: VReg) { + allocIndexForVreg(vreg: VReg): void { let num = this.getFreeVreg(); vreg.num = num; } @@ -77,7 +77,7 @@ class RegAllocator { return num; } - doRealAdjustment(operands: OperandType[], format: Format, index: number, irNodes: IRNode[]) { + doRealAdjustment(operands: OperandType[], format: Format, index: number, irNodes: IRNode[]): void { let head: IRNode[] = []; let tail: IRNode[] = []; @@ -143,7 +143,7 @@ class RegAllocator { return false; } - adjustDynRangeInstruction(irNodes: IRNode[], index: number) { + adjustDynRangeInstruction(irNodes: IRNode[], index: number): void { let head: IRNode[] = []; let operands = irNodes[index].operands; diff --git a/ts2panda/src/scope.ts b/ts2panda/src/scope.ts index 616d899360330fc4ab5c764d190131241c2eb79a..118212c5fdaf9974f7cd3eb703181af2ca9c60a8 100644 --- a/ts2panda/src/scope.ts +++ b/ts2panda/src/scope.ts @@ -106,7 +106,7 @@ export abstract class Scope { return this.name2variable; } - getScopeStartInsIdx() { + getScopeStartInsIdx(): number { return this.startInsIdx; } @@ -118,11 +118,11 @@ export abstract class Scope { this.endInsIdx = endInsIdx; } - getScopeEndInsIdx() { + getScopeEndInsIdx(): number { return this.endInsIdx; } - setParent(parentScope: Scope | undefined) { + setParent(parentScope: Scope | undefined): void { this.parent = parentScope; } @@ -254,7 +254,7 @@ export abstract class Scope { return {isLexical: false, scope: undefined, defLexicalScope: undefined, v: undefined}; } - setDecls(decl: Decl) { + setDecls(decl: Decl): void { this.decls.push(decl); } @@ -280,11 +280,11 @@ export abstract class Scope { return undefined; } - getDecls() { + getDecls(): Decl[] { return this.decls; } - public setArgumentsOrRestargs() { + public setArgumentsOrRestargs(): void { this.isArgumentsOrRestargs = true; } @@ -292,7 +292,7 @@ export abstract class Scope { return this.isArgumentsOrRestargs; } - isLexicalScope() { + isLexicalScope(): boolean { let scope = this; return ((scope instanceof VariableScope) || (scope instanceof LoopScope)); } @@ -308,31 +308,31 @@ export abstract class VariableScope extends Scope { protected childVariableScope: VariableScope[] = []; protected lexVarInfo: Map = new Map(); - getLexVarInfo() { + getLexVarInfo(): Map { return this.lexVarInfo; } - addLexVarInfo(name: string, slot: number) { + addLexVarInfo(name: string, slot: number): void { this.lexVarInfo.set(name, slot); } - getBindingNode() { + getBindingNode(): ts.Node { return this.node; } - setParentVariableScope(scope: VariableScope) { + setParentVariableScope(scope: VariableScope): void { this.parentVariableScope = scope; } - getParentVariableScope() { + getParentVariableScope(): VariableScope { return this.parentVariableScope; } - getChildVariableScope() { + getChildVariableScope(): VariableScope[] { return this.childVariableScope; } - addChildVariableScope(scope: VariableScope) { + addChildVariableScope(scope: VariableScope): void { this.childVariableScope.push(scope); } @@ -346,7 +346,7 @@ export abstract class VariableScope extends Scope { return v; } - addFuncName(funcName: string) { + addFuncName(funcName: string): void { let funcObj = this.name2variable.get(MandatoryFuncObj); this.name2variable.set(funcName, funcObj!); } @@ -355,7 +355,7 @@ export abstract class VariableScope extends Scope { return this.needCreateLexEnv; } - pendingCreateEnv() { + pendingCreateEnv(): void { this.needCreateLexEnv = true; } @@ -371,7 +371,7 @@ export abstract class VariableScope extends Scope { return this.parameters; } - getLexVarIdx() { + getLexVarIdx(): number { this.needCreateLexEnv = true; return this.startLexIdx++; } @@ -425,14 +425,14 @@ export class ModuleScope extends VariableScope { this.moduleRecord = new SourceTextModuleRecord(node.fileName); } - setExportDecl(exportedLocalName: string) { + setExportDecl(exportedLocalName: string): void { let decl = this.getDecl(exportedLocalName); if (decl && decl.isModule != ModuleVarKind.IMPORTED) { decl.isModule = ModuleVarKind.EXPORTED; } } - module() { + module(): SourceTextModuleRecord { return this.moduleRecord; } @@ -470,7 +470,7 @@ export class FunctionScope extends VariableScope { this.node = node ? node : undefined; } - setParameterLength(length: number) { + setParameterLength(length: number): void { this.parameterLength = length; } @@ -478,11 +478,11 @@ export class FunctionScope extends VariableScope { return this.parameterLength; } - setFuncName(name: string) { + setFuncName(name: string): void { this.funcName = name; } - getFuncName() { + getFuncName(): string { return this.funcName; } @@ -550,11 +550,11 @@ export class LoopScope extends LocalScope { super(parent); } - getLexVarInfo() { + getLexVarInfo(): Map { return this.lexVarInfo; } - addLexVarInfo(name: string, slot: number) { + addLexVarInfo(name: string, slot: number): void { this.lexVarInfo.set(name, slot); } @@ -562,11 +562,11 @@ export class LoopScope extends LocalScope { return this.needCreateLexEnv; } - pendingCreateEnv() { + pendingCreateEnv(): void { this.needCreateLexEnv = true; } - getLexVarIdx() { + getLexVarIdx(): number { this.needCreateLexEnv = true; return this.startLexIdx++; } diff --git a/ts2panda/src/statement/classStatement.ts b/ts2panda/src/statement/classStatement.ts index e455b1a3aec5fefd714f375439a291a7115a1ca5..b658a1777018918c52093bb8bd25840bbab1fdd3 100644 --- a/ts2panda/src/statement/classStatement.ts +++ b/ts2panda/src/statement/classStatement.ts @@ -56,7 +56,7 @@ import { Variable } from "../variable"; -export function compileClassDeclaration(compiler: Compiler, stmt: ts.ClassLikeDeclaration) { +export function compileClassDeclaration(compiler: Compiler, stmt: ts.ClassLikeDeclaration): void { compiler.pushScope(stmt); let pandaGen = compiler.getPandaGen(); @@ -161,7 +161,7 @@ export function compileClassDeclaration(compiler: Compiler, stmt: ts.ClassLikeDe compiler.popScope(); } -export function AddCtor2Class(recorder: Recorder, classNode: ts.ClassLikeDeclaration, scope: Scope) { +export function AddCtor2Class(recorder: Recorder, classNode: ts.ClassLikeDeclaration, scope: Scope): void { let ctorNode; if (jshelpers.getClassExtendsHeritageElement(classNode)) { let parameter = ts.factory.createParameterDeclaration(undefined, undefined, ts.factory.createToken(ts.SyntaxKind.DotDotDotToken), "args"); @@ -197,7 +197,7 @@ export function AddCtor2Class(recorder: Recorder, classNode: ts.ClassLikeDeclara recorder.setCtorOfClass(classNode, ctorNode); } -export function compileDefaultConstructor(compiler: Compiler, ctrNode: ts.ConstructorDeclaration) { +export function compileDefaultConstructor(compiler: Compiler, ctrNode: ts.ConstructorDeclaration): void { let callNode = ts.factory.createCallExpression(ts.factory.createSuper(), undefined, [ts.factory.createSpreadElement(ts.factory.createIdentifier("args"))]); @@ -208,7 +208,7 @@ export function compileDefaultConstructor(compiler: Compiler, ctrNode: ts.Constr compileConstructor(compiler, ctrNode, false); } -function compileUnCompiledProperty(compiler: Compiler, properties: Property[], classReg: VReg) { +function compileUnCompiledProperty(compiler: Compiler, properties: Property[], classReg: VReg): void { let pandaGen = compiler.getPandaGen(); for (let propertyIndex = 0; propertyIndex < properties.length; propertyIndex++) { let prop = properties[propertyIndex]; @@ -239,7 +239,7 @@ function compileUnCompiledProperty(compiler: Compiler, properties: Property[], c } } -function compileUnCompiledVariable(compiler: Compiler, prop: Property, classReg: VReg) { +function compileUnCompiledVariable(compiler: Compiler, prop: Property, classReg: VReg): void { let pandaGen = compiler.getPandaGen(); let proptoReg = pandaGen.getTemp(); let tmpReg = pandaGen.getTemp(); @@ -259,7 +259,7 @@ function compileUnCompiledVariable(compiler: Compiler, prop: Property, classReg: } function createClassLiteralBuf(compiler: Compiler, classBuffer: LiteralBuffer, - stmt: ts.ClassLikeDeclaration, vregs: VReg[]) { + stmt: ts.ClassLikeDeclaration, vregs: VReg[]): void { let litId: string = PandaGen.appendLiteralArrayBuffer(classBuffer); let ctorNode = compiler.getRecorder().getCtorOfClass(stmt); @@ -271,7 +271,7 @@ function createClassLiteralBuf(compiler: Compiler, classBuffer: LiteralBuffer, pandaGen.storeAccumulator(stmt, vregs[1]); } -export function compileDefaultInitClassMembers(compiler: Compiler, node: ts.ConstructorDeclaration) { +export function compileDefaultInitClassMembers(compiler: Compiler, node: ts.ConstructorDeclaration): void { let pandaGen = compiler.getPandaGen(); let members = node.parent!.members; for (let index = 0; index < members.length; index++) { @@ -319,7 +319,7 @@ export function compileDefaultInitClassMembers(compiler: Compiler, node: ts.Cons } } -export function compileReturnThis4Ctor(compiler: Compiler, node: ts.ConstructorDeclaration, unreachableFlag: boolean) { +export function compileReturnThis4Ctor(compiler: Compiler, node: ts.ConstructorDeclaration, unreachableFlag: boolean): void { let pandaGen = compiler.getPandaGen(); if (unreachableFlag) { @@ -336,7 +336,7 @@ export function compileReturnThis4Ctor(compiler: Compiler, node: ts.ConstructorD pandaGen.freeTemps(thisReg); } -export function compileConstructor(compiler: Compiler, node: ts.ConstructorDeclaration, unreachableFlag: boolean) { +export function compileConstructor(compiler: Compiler, node: ts.ConstructorDeclaration, unreachableFlag: boolean): void { let pandaGen = compiler.getPandaGen(); let members = node.parent!.members; @@ -365,7 +365,7 @@ export function compileConstructor(compiler: Compiler, node: ts.ConstructorDecla pandaGen.freeTemps(thisReg); } -export function compileSuperCall(compiler: Compiler, node: ts.CallExpression, args: VReg[], hasSpread: boolean) { +export function compileSuperCall(compiler: Compiler, node: ts.CallExpression, args: VReg[], hasSpread: boolean): void { let pandaGen = compiler.getPandaGen(); if (hasSpread) { @@ -391,7 +391,7 @@ export function compileSuperCall(compiler: Compiler, node: ts.CallExpression, ar compiler.setThis(node); } -function loadCtorObj(node: ts.CallExpression, compiler: Compiler) { +function loadCtorObj(node: ts.CallExpression, compiler: Compiler): void { let recorder = compiler.getRecorder(); let pandaGen = compiler.getPandaGen(); let nearestFunc = jshelpers.getContainingFunctionDeclaration(node); @@ -423,7 +423,7 @@ function loadCtorObj(node: ts.CallExpression, compiler: Compiler) { } -export function extractCtorOfClass(stmt: ts.ClassLikeDeclaration) { +export function extractCtorOfClass(stmt: ts.ClassLikeDeclaration): ts.ConstructorDeclaration { let members = stmt.members; for (let index = 0; index < members.length; index++) { let member = members[index]; @@ -440,7 +440,7 @@ export function defineClassMember( propValue: ts.Node, propKind: PropertyKind, properties: Property[], - namedPropertyMap: Map) { + namedPropertyMap: Map): boolean { let staticFlag = false; if (propKind == PropertyKind.Computed || propKind == PropertyKind.Spread) { let prop = new Property(propKind, propName); @@ -476,7 +476,7 @@ export function defineClassMember( return staticFlag; } -function compileHeritageClause(compiler: Compiler, node: ts.ClassLikeDeclaration) { +function compileHeritageClause(compiler: Compiler, node: ts.ClassLikeDeclaration): VReg { let pandaGen = compiler.getPandaGen(); let baseVreg = pandaGen.getTemp(); if (node.heritageClauses && node.heritageClauses.length) { @@ -493,7 +493,7 @@ function compileHeritageClause(compiler: Compiler, node: ts.ClassLikeDeclaration return baseVreg; } -export function getClassNameForConstructor(classNode: ts.ClassLikeDeclaration) { +export function getClassNameForConstructor(classNode: ts.ClassLikeDeclaration): string { let className = ""; if (!isAnonymousClass(classNode)) { @@ -528,11 +528,11 @@ export function getClassNameForConstructor(classNode: ts.ClassLikeDeclaration) { return className; } -function isAnonymousClass(node: ts.ClassLikeDeclaration) { +function isAnonymousClass(node: ts.ClassLikeDeclaration): boolean { return node.name ? false : true; } -function generatePropertyFromExpr(node: ts.ClassLikeDeclaration, classFields: Array, namedPropertyMap: Map) { +function generatePropertyFromExpr(node: ts.ClassLikeDeclaration, classFields: Array, namedPropertyMap: Map): Property[] { let properties: Array = []; let staticNum = 0; let constructNode: any; @@ -626,7 +626,7 @@ function generatePropertyFromExpr(node: ts.ClassLikeDeclaration, classFields: Ar return properties; } -function compileComputedProperty(compiler: Compiler, prop: Property, classReg: VReg, keyReg: VReg) { +function compileComputedProperty(compiler: Compiler, prop: Property, classReg: VReg, keyReg: VReg): void { let pandaGen = compiler.getPandaGen(); switch (prop.getValue().kind) { case ts.SyntaxKind.PropertyDeclaration: { @@ -669,7 +669,7 @@ function compileComputedProperty(compiler: Compiler, prop: Property, classReg: V pandaGen.freeTemps(keyReg); } -function setClassAccessor(pandaGen: PandaGen, compiler: Compiler, objReg: VReg, prop: Property) { +function setClassAccessor(pandaGen: PandaGen, compiler: Compiler, objReg: VReg, prop: Property): void { let getterReg = pandaGen.getTemp(); let setterReg = pandaGen.getTemp(); @@ -705,7 +705,7 @@ function setClassAccessor(pandaGen: PandaGen, compiler: Compiler, objReg: VReg, } function createClassMethodOrAccessor(compiler: Compiler, classReg: VReg, propReg: VReg, storeReg: VReg, - node: ts.MethodDeclaration | ts.GetAccessorDeclaration | ts.SetAccessorDeclaration | ts.ConstructorDeclaration) { + node: ts.MethodDeclaration | ts.GetAccessorDeclaration | ts.SetAccessorDeclaration | ts.ConstructorDeclaration): boolean { let pandaGen = compiler.getPandaGen(); if (jshelpers.hasStaticModifier(node)) { createMethodOrAccessor(pandaGen, compiler, classReg, node); @@ -721,7 +721,7 @@ function createClassMethodOrAccessor(compiler: Compiler, classReg: VReg, propReg return true; } -function scalarArrayEquals(node1: ts.Node | undefined, node2: ts.Node | undefined) { +function scalarArrayEquals(node1: ts.Node | undefined, node2: ts.Node | undefined): boolean { if (node1 && node2) { let val1Modifs = node1.modifiers; let val2Modifs = node2.modifiers; @@ -739,7 +739,7 @@ function scalarArrayEquals(node1: ts.Node | undefined, node2: ts.Node | undefine return false; } -export function setPrototypeAttributes(compiler: Compiler, node: ts.Node, classReg: VReg, propReg: VReg, storeReg: VReg) { +export function setPrototypeAttributes(compiler: Compiler, node: ts.Node, classReg: VReg, propReg: VReg, storeReg: VReg): boolean { let pandaGen = compiler.getPandaGen(); pandaGen.storeAccumulator(node, storeReg); if (jshelpers.hasStaticModifier(node)) { @@ -792,7 +792,7 @@ export function shouldReturnThisForConstruct(stmt: ts.ReturnStatement): boolean return false; } -export function compileSuperProperty(compiler: Compiler, expr: ts.Expression, thisReg: VReg, prop: VReg | string | number) { +export function compileSuperProperty(compiler: Compiler, expr: ts.Expression, thisReg: VReg, prop: VReg | string | number): void { checkValidUseSuperBeforeSuper(compiler, expr); let pandaGen = compiler.getPandaGen(); compiler.getThis(expr, thisReg); @@ -800,7 +800,7 @@ export function compileSuperProperty(compiler: Compiler, expr: ts.Expression, th pandaGen.loadSuperProperty(expr, thisReg, prop); } -export function checkValidUseSuperBeforeSuper(compiler: Compiler, node: ts.Node) { +export function checkValidUseSuperBeforeSuper(compiler: Compiler, node: ts.Node): void { let pandaGen = compiler.getPandaGen(); let ctorNode = jshelpers.findAncestor(node, ts.isConstructorDeclaration); diff --git a/ts2panda/src/statement/forOfStatement.ts b/ts2panda/src/statement/forOfStatement.ts index d4f1dede5a7244a7aa076b3309a530e3f9052868..61e58aac20dd9c57c4202dd27adb1846c8b039b7 100644 --- a/ts2panda/src/statement/forOfStatement.ts +++ b/ts2panda/src/statement/forOfStatement.ts @@ -38,21 +38,21 @@ export class IteratorRecord { this.nextMethod = nextMethod; } - getType() { + getType(): IteratorType { return this.type; } - getObject() { + getObject(): VReg { return this.object; } - getNextMethod() { + getNextMethod(): VReg { return this.nextMethod; } } -export function compileForOfStatement(stmt: ts.ForOfStatement, compiler: Compiler) { +export function compileForOfStatement(stmt: ts.ForOfStatement, compiler: Compiler): void { compiler.pushScope(stmt); let pandaGen = compiler.getPandaGen(); @@ -107,7 +107,7 @@ export function compileForOfStatement(stmt: ts.ForOfStatement, compiler: Compile compiler.popScope(); } -export function getIteratorRecord(pandagen: PandaGen, node: ts.Node, nextMethod: VReg, object: VReg, type: IteratorType) { +export function getIteratorRecord(pandagen: PandaGen, node: ts.Node, nextMethod: VReg, object: VReg, type: IteratorType): IteratorRecord { getIterator(pandagen, node, type); pandagen.storeAccumulator(node, object); @@ -117,7 +117,7 @@ export function getIteratorRecord(pandagen: PandaGen, node: ts.Node, nextMethod: return new IteratorRecord(object, nextMethod, type); } -function getIterator(pandagen: PandaGen, node: ts.Node, type: IteratorType) { +function getIterator(pandagen: PandaGen, node: ts.Node, type: IteratorType): void { if (type == IteratorType.Async) { pandagen.getAsyncIterator(node); } else { diff --git a/ts2panda/src/statement/labelTarget.ts b/ts2panda/src/statement/labelTarget.ts index bfd71326a865e3aedc3d1bc36e800d1b28167497..7ddd2049f83122ff72eae0d4a5de54e26e6041e4 100644 --- a/ts2panda/src/statement/labelTarget.ts +++ b/ts2panda/src/statement/labelTarget.ts @@ -44,39 +44,39 @@ export class LabelTarget { } } - containLoopEnv() { + containLoopEnv(): boolean { return this.hasLoopEnv; } - getBreakTargetLabel() { + getBreakTargetLabel(): Label { return this.breakTargetLabel; } - getContinueTargetLabel() { + getContinueTargetLabel(): any { return this.continueTargetLabel; } - getLoopEnvLevel() { + getLoopEnvLevel(): number { return this.loopEnvLevel; } - getTryStatement() { + getTryStatement(): TryStatement { return this.tryStatement; } - getPreLoopLabelTarget() { + getPreLoopLabelTarget(): LabelTarget { return this.preLoopLabelTarget; } - getCorrespondingNode() { + getCorrespondingNode(): ts.Node { return this.node; } - private increaseLoopEnvLevel() { + private increaseLoopEnvLevel(): void { this.loopEnvLevel += 1; } - private decreaseLoopEnvLevel() { + private decreaseLoopEnvLevel(): void { this.loopEnvLevel -= 1; } @@ -94,7 +94,7 @@ export class LabelTarget { return undefined; } - static pushLabelTarget(labelTarget: LabelTarget) { + static pushLabelTarget(labelTarget: LabelTarget): void { if (labelTarget.hasLoopEnv) { if (TryStatement.getCurrentTryStatement()) { TryStatement.getCurrentTryStatement().increaseLoopEnvLevel(); @@ -104,7 +104,7 @@ export class LabelTarget { LabelTarget.labelTargetStack.push(labelTarget); } - static popLabelTarget() { + static popLabelTarget(): void { if (!LabelTarget.isLabelTargetsEmpty()) { let popedLabelTarget = LabelTarget.labelTargetStack.pop(); if (popedLabelTarget.containLoopEnv()) { @@ -119,7 +119,7 @@ export class LabelTarget { } } - static updateName2LabelTarget(node: ts.Node, labelTarget: LabelTarget) { + static updateName2LabelTarget(node: ts.Node, labelTarget: LabelTarget): void { while (node.kind == ts.SyntaxKind.LabeledStatement) { let labeledStmt = node; let labelName = jshelpers.getTextOfIdentifierOrLiteral(labeledStmt.label); @@ -134,11 +134,11 @@ export class LabelTarget { } } - static deleteName2LabelTarget(labelName: string) { + static deleteName2LabelTarget(labelName: string): void { LabelTarget.name2LabelTarget.delete(labelName); } - static getCurLoopLabelTarget() { + static getCurLoopLabelTarget(): LabelTarget { return LabelTarget.curLoopLabelTarget; } diff --git a/ts2panda/src/statement/loopStatement.ts b/ts2panda/src/statement/loopStatement.ts index e1c02b44e8854479632dea16ade67113b185e87f..93d53983e7ebae420866c7b2b68408915499a6e3 100644 --- a/ts2panda/src/statement/loopStatement.ts +++ b/ts2panda/src/statement/loopStatement.ts @@ -32,7 +32,7 @@ import { Label, VReg } from "../irnodes"; import { LoopScope, Scope } from "../scope"; import { LabelTarget } from "./labelTarget"; -export function compileDoStatement(stmt: ts.DoStatement, compiler: Compiler) { +export function compileDoStatement(stmt: ts.DoStatement, compiler: Compiler): void { compiler.pushScope(stmt); let pandaGen = compiler.getPandaGen(); @@ -72,7 +72,7 @@ export function compileDoStatement(stmt: ts.DoStatement, compiler: Compiler) { compiler.popScope(); } -export function compileWhileStatement(stmt: ts.WhileStatement, compiler: Compiler) { +export function compileWhileStatement(stmt: ts.WhileStatement, compiler: Compiler): void { compiler.pushScope(stmt); let pandaGen = compiler.getPandaGen(); @@ -109,7 +109,7 @@ export function compileWhileStatement(stmt: ts.WhileStatement, compiler: Compile compiler.popScope(); } -export function compileForStatement(stmt: ts.ForStatement, compiler: Compiler) { +export function compileForStatement(stmt: ts.ForStatement, compiler: Compiler): void { compiler.pushScope(stmt); let pandaGen = compiler.getPandaGen(); @@ -247,7 +247,7 @@ export function compileForStatement(stmt: ts.ForStatement, compiler: Compiler) { compiler.popScope(); } -export function compileForInStatement(stmt: ts.ForInStatement, compiler: Compiler) { +export function compileForInStatement(stmt: ts.ForInStatement, compiler: Compiler): void { compiler.pushScope(stmt); let pandaGen = compiler.getPandaGen(); diff --git a/ts2panda/src/statement/returnStatement.ts b/ts2panda/src/statement/returnStatement.ts index 6b4365aa7a508965b4d5a4eee5210e68af1f4407..992222adca96bfb594b651250a231459ab7fa208 100644 --- a/ts2panda/src/statement/returnStatement.ts +++ b/ts2panda/src/statement/returnStatement.ts @@ -22,7 +22,7 @@ import { Label, VReg } from "../irnodes"; import * as jshelpers from "../jshelpers"; import { checkValidUseSuperBeforeSuper } from "./classStatement"; -export function compileReturnStatement(stmt: ts.ReturnStatement, compiler: Compiler) { +export function compileReturnStatement(stmt: ts.ReturnStatement, compiler: Compiler): void { let pandaGen = compiler.getPandaGen(); let returnValue = pandaGen.getTemp(); @@ -34,7 +34,7 @@ export function compileReturnStatement(stmt: ts.ReturnStatement, compiler: Compi pandaGen.freeTemps(returnValue); } -function compileReturnInDerivedCtor(stmt: ts.ReturnStatement, returnValue: VReg, compiler: Compiler) { +function compileReturnInDerivedCtor(stmt: ts.ReturnStatement, returnValue: VReg, compiler: Compiler): void { let pandaGen = compiler.getPandaGen(); let expr = stmt.expression; @@ -104,7 +104,7 @@ function compileReturnInDerivedCtor(stmt: ts.ReturnStatement, returnValue: VReg, pandaGen.freeTemps(need2CheckSuper, thisReg); } -function compileNormalReturn(stmt: ts.ReturnStatement, returnValue: VReg, compiler: Compiler) { +function compileNormalReturn(stmt: ts.ReturnStatement, returnValue: VReg, compiler: Compiler): void { let expr = stmt.expression; let pandaGen = compiler.getPandaGen(); let empty : boolean = false; @@ -127,7 +127,7 @@ function compileNormalReturn(stmt: ts.ReturnStatement, returnValue: VReg, compil compiler.getFuncBuilder().explicitReturn(stmt, empty); } -function isReturnInDerivedCtor(stmt: ts.ReturnStatement) { +function isReturnInDerivedCtor(stmt: ts.ReturnStatement): boolean { let funcNode = jshelpers.getContainingFunctionDeclaration(stmt); if (!funcNode || !ts.isConstructorDeclaration(funcNode)) { return false; diff --git a/ts2panda/src/statement/tryStatement.ts b/ts2panda/src/statement/tryStatement.ts index f20de8ef20cc03a08432970f331e0edd12647949..fe65fe597ee2ba0bbbfefb8fa83d0bc822722128 100644 --- a/ts2panda/src/statement/tryStatement.ts +++ b/ts2panda/src/statement/tryStatement.ts @@ -81,20 +81,20 @@ export class CatchTable { pandaGen.getCatchMap().set(catchBeginLabel, this); } - getLabelPairs() { + getLabelPairs(): LabelPair[] { return this.labelPairs; } - getCatchBeginLabel() { + getCatchBeginLabel(): Label { return this.catchBeginLabel; } - getDepth() { + getDepth(): number { return this.depth; } // split the last labelPair after inline finally. - splitLabelPair(inlinedLabelPair: LabelPair) { + splitLabelPair(inlinedLabelPair: LabelPair): void { let lastLabelPair = this.labelPairs.pop(); if (lastLabelPair) { this.labelPairs.push(new LabelPair(lastLabelPair.getBeginLabel(), inlinedLabelPair.getBeginLabel())); @@ -139,44 +139,44 @@ export class TryStatement { TryStatement.currentTryStatement = this; } - destroy() { + destroy(): void { TryStatement.currentTryStatementDepth--; TryStatement.currentTryStatement = this.outer; } - static setCurrentTryStatement(tryStatement: TryStatement | undefined) { + static setCurrentTryStatement(tryStatement: TryStatement | undefined): void { TryStatement.currentTryStatement = tryStatement; } - static getCurrentTryStatement() { + static getCurrentTryStatement(): TryStatement { return TryStatement.currentTryStatement; } - static getcurrentTryStatementDepth() { + static getcurrentTryStatementDepth(): number { return TryStatement.currentTryStatementDepth; } - getOuterTryStatement() { + getOuterTryStatement(): TryStatement { return this.outer; } - getStatement() { + getStatement(): ts.Statement { return this.stmt; } - getCatchTable() { + getCatchTable(): CatchTable { return this.catchTable; } - getLoopEnvLevel() { + getLoopEnvLevel(): number { return this.loopEnvLevel; } - increaseLoopEnvLevel() { + increaseLoopEnvLevel(): void { this.loopEnvLevel += 1; } - decreaseLoopEnvLevel() { + decreaseLoopEnvLevel(): void { this.loopEnvLevel -= 1; } } @@ -207,7 +207,7 @@ export class TryBuilder extends TryBuilderBase { super(compiler, pandaGen, tryStmt) } - compileTryBlock(catchTable: CatchTable) { + compileTryBlock(catchTable: CatchTable): void { if ((this.stmt).finallyBlock) { this.tryStatement = new TryStatement(this.stmt, catchTable, this); } else { @@ -220,13 +220,13 @@ export class TryBuilder extends TryBuilderBase { this.tryStatement.destroy(); } - compileFinallyBlockIfExisted() { + compileFinallyBlockIfExisted(): void { if ((this.stmt).finallyBlock) { this.compiler.compileStatement((this.stmt).finallyBlock!); } } - compileExceptionHandler() { + compileExceptionHandler(): void { let catchClause = (this.stmt).catchClause; if (catchClause) { this.compiler.pushScope(catchClause); @@ -248,7 +248,7 @@ export class TryBuilder extends TryBuilderBase { } // @ts-ignore - compileFinalizer(cfc: ControlFlowChange, continueTargetLabel: Label) { + compileFinalizer(cfc: ControlFlowChange, continueTargetLabel: Label): void { this.compiler.compileStatement((this.stmt).finallyBlock!); } } @@ -270,7 +270,7 @@ export class TryBuilderWithForOf extends TryBuilderBase { this.loopEnv = loopEnv ? loopEnv : undefined; } - compileTryBlock(catchTable: CatchTable) { + compileTryBlock(catchTable: CatchTable): void { let stmt = this.stmt; let compiler = this.compiler; let pandaGen = this.pandaGen; @@ -309,9 +309,9 @@ export class TryBuilderWithForOf extends TryBuilderBase { pandaGen.freeTemps(resultReg); } - compileFinallyBlockIfExisted() { } + compileFinallyBlockIfExisted(): void { } - compileExceptionHandler() { + compileExceptionHandler(): void { let pandaGen = this.pandaGen; let noReturn = new Label(); let exceptionVreg = pandaGen.getTemp(); @@ -339,7 +339,7 @@ export class TryBuilderWithForOf extends TryBuilderBase { pandaGen.freeTemps(exceptionVreg); } - compileFinalizer(cfc: ControlFlowChange, continueTargetLabel: Label) { + compileFinalizer(cfc: ControlFlowChange, continueTargetLabel: Label): void { if (cfc == ControlFlowChange.Break || continueTargetLabel != this.labelTarget.getContinueTargetLabel()) { let noReturn = new Label(); let innerResult = this.pandaGen.getTemp(); @@ -356,7 +356,7 @@ export class TryBuilderWithForOf extends TryBuilderBase { } } - private compileIteratorNext(stmt: ts.ForOfStatement, pandagen: PandaGen, iterator: IteratorRecord, resultObj: VReg) { + private compileIteratorNext(stmt: ts.ForOfStatement, pandagen: PandaGen, iterator: IteratorRecord, resultObj: VReg): void { pandagen.call(stmt, [iterator.getNextMethod(), iterator.getObject()], true); if (iterator.getType() == IteratorType.Async) { ((this.compiler.getFuncBuilder())).await(this.stmt); @@ -366,13 +366,13 @@ export class TryBuilderWithForOf extends TryBuilderBase { } } -function compileCatchClauseVariableDeclaration(compiler: Compiler, param: ts.VariableDeclaration | undefined) { +function compileCatchClauseVariableDeclaration(compiler: Compiler, param: ts.VariableDeclaration | undefined): void { if (param) { compiler.compileVariableDeclaration(param); } } -export function updateCatchTables(inlinedTry: TryStatement | undefined, targetTry: TryStatement, inlinedLabelPair: LabelPair) { +export function updateCatchTables(inlinedTry: TryStatement | undefined, targetTry: TryStatement, inlinedLabelPair: LabelPair): void { for (; inlinedTry != targetTry; inlinedTry = inlinedTry?.getOuterTryStatement()) { inlinedTry!.getCatchTable().splitLabelPair(inlinedLabelPair); } diff --git a/ts2panda/src/strictMode.ts b/ts2panda/src/strictMode.ts index a3b0bc1e24055691c8cf86fc4dfd297a499aeb9e..b8b3e108435eb69596efdb73638a8dc8ed2af39a 100644 --- a/ts2panda/src/strictMode.ts +++ b/ts2panda/src/strictMode.ts @@ -80,7 +80,7 @@ function getGlobalStrict(): boolean { return globalStrict; } -export function setGlobalStrict(flag: boolean) { +export function setGlobalStrict(flag: boolean): void { globalStrict = flag; } @@ -92,10 +92,10 @@ export function isStrictMode(node: ts.Node): boolean { return checkStrictMode(node); } -export function setGlobalDeclare(flag: boolean) { +export function setGlobalDeclare(flag: boolean): void { globalDeclare = flag; } -export function isGlobalDeclare() { +export function isGlobalDeclare(): boolean { return globalDeclare; } \ No newline at end of file diff --git a/ts2panda/src/syntaxCheckHelper.ts b/ts2panda/src/syntaxCheckHelper.ts index 38a785e6e9699662729b1c736befc4af1ac937f1..0e1268951b23843dfa5422b8327b30f880c7fb5d 100644 --- a/ts2panda/src/syntaxCheckHelper.ts +++ b/ts2panda/src/syntaxCheckHelper.ts @@ -34,7 +34,7 @@ export function isNewOrCallExpression(node: ts.Node): boolean { return node.kind === ts.SyntaxKind.NewExpression || node.kind === ts.SyntaxKind.CallExpression; } -export function stringLiteralIsInRegExp(node: ts.Node) { +export function stringLiteralIsInRegExp(node: ts.Node): boolean { let parent = node.parent; if (parent && isNewOrCallExpression(parent)) { let expression = (parent).expression; @@ -74,7 +74,7 @@ export function isEvalOrArgumentsIdentifier(node: ts.Node): boolean { return ts.isIdentifier(node) && (node.escapedText === "eval" || node.escapedText === MandatoryArguments); } -export function isLeftHandSideExpressionKind(kind: ts.SyntaxKind) { +export function isLeftHandSideExpressionKind(kind: ts.SyntaxKind): boolean { switch (kind) { case ts.SyntaxKind.NumericLiteral: case ts.SyntaxKind.BigIntLiteral: @@ -110,11 +110,11 @@ export function isLeftHandSideExpressionKind(kind: ts.SyntaxKind) { } } -export function isLeftHandSideExpression(node: ts.Node) { +export function isLeftHandSideExpression(node: ts.Node): boolean { return isLeftHandSideExpressionKind(ts.skipPartiallyEmittedExpressions(node).kind); } -export function isAssignmentOperator(token: ts.SyntaxKind) { +export function isAssignmentOperator(token: ts.SyntaxKind): boolean { return token >= ts.SyntaxKind.FirstAssignment && token <= ts.SyntaxKind.LastAssignment; } @@ -168,7 +168,7 @@ export function allowLetAndConstDeclarations(node: ts.Node): boolean { return true; } -export function isGlobalIdentifier(name: string) { +export function isGlobalIdentifier(name: string): boolean { switch (name) { case "NaN": case "undefined": @@ -269,7 +269,7 @@ export function isOptionalParameter(node: ts.ParameterDeclaration): boolean { return false; } -export function isStatement(kind: ts.SyntaxKind) { +export function isStatement(kind: ts.SyntaxKind): boolean { if (kind >= ts.SyntaxKind.FirstStatement && kind <= ts.SyntaxKind.LastStatement) { return true; } diff --git a/ts2panda/src/syntaxChecker.ts b/ts2panda/src/syntaxChecker.ts index 69750aa96d705382192db70eb4b59774d1edd5f5..a7bbe598ebefe59f9d19e2bc0b2cd7613db9d144 100644 --- a/ts2panda/src/syntaxChecker.ts +++ b/ts2panda/src/syntaxChecker.ts @@ -56,7 +56,7 @@ import { import { MandatoryArguments } from "./variable"; //*************************************Part 1: Implement early check of declarations*******************************// -export function checkDuplicateDeclaration(recorder: Recorder) { +export function checkDuplicateDeclaration(recorder: Recorder): void { let scopeMap = recorder.getScopeMap(); scopeMap.forEach((scope, node) => { // implement functionParameter-related duplicate-entry check @@ -93,7 +93,7 @@ export function checkDuplicateDeclaration(recorder: Recorder) { }) } -function checkDuplicateEntryAcrossScope(scope: Scope, index: number) { +function checkDuplicateEntryAcrossScope(scope: Scope, index: number): void { let decls = scope.getDecls(); let parentScope: Scope | undefined = scope; if (decls[index] instanceof VarDecl) { @@ -113,7 +113,7 @@ function checkDuplicateEntryAcrossScope(scope: Scope, index: number) { } } -function checkDuplicateEntryInScope(scope: Scope, index: number) { +function checkDuplicateEntryInScope(scope: Scope, index: number): void { let decls = scope.getDecls(); for (let i = index + 1; i < decls.length; i++) { if (hasDuplicateEntryInScope(decls[index], decls[i], scope)) { @@ -122,7 +122,7 @@ function checkDuplicateEntryInScope(scope: Scope, index: number) { } } -function hasDuplicateExportedFuncDecl(decl: FuncDecl, exportFuncMap: Map) { +function hasDuplicateExportedFuncDecl(decl: FuncDecl, exportFuncMap: Map): void { if (!exportFuncMap.has(decl.name)) { exportFuncMap.set(decl.name, hasExportKeywordModifier(decl.node)); } else { @@ -132,13 +132,13 @@ function hasDuplicateExportedFuncDecl(decl: FuncDecl, exportFuncMap: Map(decl.node).name; @@ -269,14 +269,14 @@ function throwDupIdError(decl: Decl) { } //**********************************Part 2: Implementing syntax check except declaration******************************************// -export function checkSyntaxError(node: ts.Node, scope:Scope) { +export function checkSyntaxError(node: ts.Node, scope:Scope): void { checkSyntaxErrorForSloppyAndStrictMode(node); if (isStrictMode(node) || CmdOptions.isModules()) { checkSyntaxErrorForStrictMode(node, scope); } } -function checkBreakOrContinueStatement(node: ts.BreakOrContinueStatement) { +function checkBreakOrContinueStatement(node: ts.BreakOrContinueStatement): boolean { let curNode: ts.Node = node; while (curNode) { if (ts.isFunctionLike(curNode)) { @@ -340,7 +340,7 @@ function checkBreakOrContinueStatement(node: ts.BreakOrContinueStatement) { throw new DiagnosticError(node, diagnosticCode, jshelpers.getSourceFileOfNode(node)); } -function checkReturnStatement(node: ts.ReturnStatement) { +function checkReturnStatement(node: ts.ReturnStatement): void { let func = jshelpers.getContainingFunction(node); if (!func) { let file = jshelpers.getSourceFileOfNode(node); @@ -348,7 +348,7 @@ function checkReturnStatement(node: ts.ReturnStatement) { } } -function checkMetaProperty(node: ts.MetaProperty) { +function checkMetaProperty(node: ts.MetaProperty): void { let text = jshelpers.getTextOfIdentifierOrLiteral(node.name); let file = jshelpers.getSourceFileOfNode(node); switch (node.keywordToken) { @@ -383,7 +383,7 @@ function checkMetaProperty(node: ts.MetaProperty) { } } -function checkNameInLetOrConstDeclarations(name: ts.Identifier | ts.BindingPattern) { +function checkNameInLetOrConstDeclarations(name: ts.Identifier | ts.BindingPattern): void { if (name.kind === ts.SyntaxKind.Identifier) { if (name.originalKeywordKind === ts.SyntaxKind.LetKeyword) { let file = jshelpers.getSourceFileOfNode(name); @@ -399,7 +399,7 @@ function checkNameInLetOrConstDeclarations(name: ts.Identifier | ts.BindingPatte } } -function checkDisallowedLetOrConstStatement(node: ts.VariableStatement) { +function checkDisallowedLetOrConstStatement(node: ts.VariableStatement): void { if (allowLetAndConstDeclarations(node.parent)) { return; } @@ -413,7 +413,7 @@ function checkDisallowedLetOrConstStatement(node: ts.VariableStatement) { } } -function checkVariableDeclaration(node: ts.VariableDeclaration) { +function checkVariableDeclaration(node: ts.VariableDeclaration): void { let file = jshelpers.getSourceFileOfNode(node); if (!ts.isForInStatement(node.parent.parent) && !ts.isForOfStatement(node.parent.parent) && !ts.isCatchClause(node.parent)) { if (!node.initializer) { @@ -446,7 +446,7 @@ function checkVariableDeclaration(node: ts.VariableDeclaration) { } } -function checkDecorators(node: ts.Node) { +function checkDecorators(node: ts.Node): void { if (!node.decorators) { return; } @@ -466,7 +466,7 @@ function checkDecorators(node: ts.Node) { } } -function checkAsyncModifier(node: ts.Node, asyncModifier: ts.Node) { +function checkAsyncModifier(node: ts.Node, asyncModifier: ts.Node): void { switch (node.kind) { case ts.SyntaxKind.ArrowFunction: case ts.SyntaxKind.FunctionDeclaration: @@ -480,7 +480,7 @@ function checkAsyncModifier(node: ts.Node, asyncModifier: ts.Node) { throw new DiagnosticError(asyncModifier, DiagnosticCode._0_modifier_cannot_be_used_here, file, ["async"]) } -function checkModifiers(node: ts.Node) { +function checkModifiers(node: ts.Node): void { if (!node.modifiers) { return; } @@ -678,7 +678,7 @@ function checkModifiers(node: ts.Node) { } } -function checkVariableDeclarationList(declarationList: ts.VariableDeclarationList) { +function checkVariableDeclarationList(declarationList: ts.VariableDeclarationList): void { let declarations = declarationList.declarations; if (!declarations.length) { throw new DiagnosticError(declarationList, DiagnosticCode.Identifier_expected); @@ -690,14 +690,14 @@ function checkVariableDeclarationList(declarationList: ts.VariableDeclarationLis } } -function checkVariableStatement(node: ts.VariableStatement) { +function checkVariableStatement(node: ts.VariableStatement): void { checkDecorators(node); checkModifiers(node); checkVariableDeclarationList(node.declarationList); checkDisallowedLetOrConstStatement(node); } -function checkForInOrForOfStatement(stmt: ts.ForInOrOfStatement) { +function checkForInOrForOfStatement(stmt: ts.ForInOrOfStatement): void { let file = jshelpers.getSourceFileOfNode(stmt); let leftExpr = stmt.initializer; if (ts.isParenthesizedExpression(leftExpr)) { @@ -740,7 +740,7 @@ function checkForInOrForOfStatement(stmt: ts.ForInOrOfStatement) { } } -function checkForInOrForOfVariableDeclaration(iterationStatement: ts.ForInOrOfStatement) { +function checkForInOrForOfVariableDeclaration(iterationStatement: ts.ForInOrOfStatement): void { let variableDeclarationList = iterationStatement.initializer; // checkGrammarForInOrForOfStatement will check that there is exactly one declaration. if (variableDeclarationList.declarations.length >= 1) { @@ -748,7 +748,7 @@ function checkForInOrForOfVariableDeclaration(iterationStatement: ts.ForInOrOfSt } } -function checkForInStatement(node: ts.ForInStatement) { +function checkForInStatement(node: ts.ForInStatement): void { checkForInOrForOfStatement(node); let file = jshelpers.getSourceFileOfNode(node); @@ -772,7 +772,7 @@ const enum OuterExpressionKinds { All = Parentheses | Assertions | PartiallyEmittedExpressions } -function checkReferenceExpression(expr: ts.Expression, invalidReferenceCode: DiagnosticCode, invalidOptionalChainCode: DiagnosticCode) { +function checkReferenceExpression(expr: ts.Expression, invalidReferenceCode: DiagnosticCode, invalidOptionalChainCode: DiagnosticCode): void { let node = jshelpers.skipOuterExpressions(expr, OuterExpressionKinds.Assertions | OuterExpressionKinds.Parentheses); if (node.kind !== ts.SyntaxKind.Identifier && node.kind !== ts.SyntaxKind.PropertyAccessExpression && node.kind !== ts.SyntaxKind.ElementAccessExpression) { throw new DiagnosticError(expr, invalidReferenceCode); @@ -783,7 +783,7 @@ function checkReferenceExpression(expr: ts.Expression, invalidReferenceCode: Dia } } -function checkReferenceAssignment(node: ts.Expression) { +function checkReferenceAssignment(node: ts.Expression): void { let invalidReferenceCode: DiagnosticCode; let invalidOptionalChainCode: DiagnosticCode; @@ -798,7 +798,7 @@ function checkReferenceAssignment(node: ts.Expression) { checkReferenceExpression(node, invalidReferenceCode, invalidOptionalChainCode); } -function checkDestructuringAssignment(node: ts.Expression | ts.ShorthandPropertyAssignment) { +function checkDestructuringAssignment(node: ts.Expression | ts.ShorthandPropertyAssignment): void { let target: ts.Expression; if (ts.isShorthandPropertyAssignment(node)) { let prop = node; @@ -820,7 +820,7 @@ function checkDestructuringAssignment(node: ts.Expression | ts.ShorthandProperty } -function checkForOfStatement(node: ts.ForOfStatement) { +function checkForOfStatement(node: ts.ForOfStatement): void { checkForInOrForOfStatement(node); if (ts.isVariableDeclarationList(node.initializer)) { @@ -839,7 +839,7 @@ function checkForOfStatement(node: ts.ForOfStatement) { } } -function checkClassDeclaration(node: ts.ClassLikeDeclaration) { +function checkClassDeclaration(node: ts.ClassLikeDeclaration): void { checkClassDeclarationHeritageClauses(node); let hasConstructorImplementation = false; let file = jshelpers.getSourceFileOfNode(node); @@ -872,7 +872,7 @@ function checkClassDeclaration(node: ts.ClassLikeDeclaration) { } -function checkClassDeclarationHeritageClauses(node: ts.ClassLikeDeclaration) { +function checkClassDeclarationHeritageClauses(node: ts.ClassLikeDeclaration): void { let hasExtendsKeyWords = false; checkDecorators(node); checkModifiers(node); @@ -895,7 +895,7 @@ function checkClassDeclarationHeritageClauses(node: ts.ClassLikeDeclaration) { } } -function checkBinaryExpression(node: ts.BinaryExpression) { +function checkBinaryExpression(node: ts.BinaryExpression): void { // AssignmentExpression if (isAssignmentOperator(node.operatorToken.kind)) { let leftExpr: ts.Expression = node.left; @@ -913,7 +913,7 @@ function checkBinaryExpression(node: ts.BinaryExpression) { } } -function isInVaildAssignmentLeftSide(leftExpr: ts.Expression) { +function isInVaildAssignmentLeftSide(leftExpr: ts.Expression): void { if (jshelpers.isKeyword(leftExpr.kind) || leftExpr.kind == ts.SyntaxKind.NumericLiteral || leftExpr.kind == ts.SyntaxKind.StringLiteral) { @@ -922,7 +922,7 @@ function isInVaildAssignmentLeftSide(leftExpr: ts.Expression) { } -function checkContextualIdentifier(node: ts.Identifier) { +function checkContextualIdentifier(node: ts.Identifier): void { if (jshelpers.isIdentifierName(node)) { return; } @@ -939,7 +939,7 @@ function checkContextualIdentifier(node: ts.Identifier) { } } -function checkComputedPropertyName(node: ts.Node) { +function checkComputedPropertyName(node: ts.Node): void { if (!ts.isComputedPropertyName(node)) { return; } @@ -960,7 +960,7 @@ const enum DeclarationMeaning { PropertyAssignmentOrMethod = PropertyAssignment | Method, } -function checkObjectLiteralExpression(node: ts.ObjectLiteralExpression) { +function checkObjectLiteralExpression(node: ts.ObjectLiteralExpression): void { let inDestructuring = jshelpers.isAssignmentTarget(node); let file = jshelpers.getSourceFileOfNode(node); let seen = new Map(); @@ -1020,14 +1020,14 @@ function checkObjectLiteralExpression(node: ts.ObjectLiteralExpression) { } } -function checkInvalidExclamationToken(exclamationToken: ts.ExclamationToken | undefined) { +function checkInvalidExclamationToken(exclamationToken: ts.ExclamationToken | undefined): void { if (!!exclamationToken) { let file = jshelpers.getSourceFileOfNode(exclamationToken); throw new DiagnosticError(exclamationToken, DiagnosticCode.A_definite_assignment_assertion_is_not_permitted_in_this_context, file); } } -function checkInvalidQuestionMark(questionToken: ts.QuestionToken | undefined) { +function checkInvalidQuestionMark(questionToken: ts.QuestionToken | undefined): void { if (!!questionToken) { let file = jshelpers.getSourceFileOfNode(questionToken); throw new DiagnosticError(questionToken, DiagnosticCode.An_object_member_cannot_be_declared_optional, file); @@ -1035,7 +1035,7 @@ function checkInvalidQuestionMark(questionToken: ts.QuestionToken | undefined) { } // @ts-ignore -function getPropertieDeclaration(node: ts.Node, name: ts.Node) { +function getPropertieDeclaration(node: ts.Node, name: ts.Node): any { let decl = undefined; if (ts.isShorthandPropertyAssignment(node)) { checkInvalidExclamationToken(node.exclamationToken); @@ -1055,14 +1055,14 @@ function getPropertieDeclaration(node: ts.Node, name: ts.Node) { return decl; } -function checkDisallowedTrailingComma(list: ts.NodeArray | undefined) { +function checkDisallowedTrailingComma(list: ts.NodeArray | undefined): void { if (list && list.hasTrailingComma) { let file = jshelpers.getSourceFileOfNode(list[0]); throw new DiagnosticError(list[0], DiagnosticCode.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma, file); } } -function checkParameters(parameters: ts.NodeArray) { +function checkParameters(parameters: ts.NodeArray): void { let count = parameters.length; let optionalParameter = false; @@ -1096,7 +1096,7 @@ function checkParameters(parameters: ts.NodeArray) { } } -function checkArrowFunction(node: ts.Node) { +function checkArrowFunction(node: ts.Node): void { if (!ts.isArrowFunction(node)) { return; } @@ -1110,14 +1110,14 @@ function checkArrowFunction(node: ts.Node) { } } -function checkFunctionLikeDeclaration(node: ts.FunctionLikeDeclaration | ts.MethodSignature) { +function checkFunctionLikeDeclaration(node: ts.FunctionLikeDeclaration | ts.MethodSignature): void { checkDecorators(node); checkModifiers(node); checkParameters(node.parameters); checkArrowFunction(node); } -function checkLabeledStatement(node: ts.LabeledStatement) { +function checkLabeledStatement(node: ts.LabeledStatement): void { let file = jshelpers.getSourceFileOfNode(node); jshelpers.findAncestor(node.parent, current => { if (jshelpers.isFunctionLike(current)) { @@ -1143,7 +1143,7 @@ function checkLabeledStatement(node: ts.LabeledStatement) { } } -function checkGetAccessor(node: ts.GetAccessorDeclaration) { +function checkGetAccessor(node: ts.GetAccessorDeclaration): void { checkFunctionLikeDeclaration(node); if (node.parameters.length != 0) { throw new DiagnosticError(node, DiagnosticCode.Getter_must_not_have_any_formal_parameters); @@ -1167,7 +1167,7 @@ function isValidUseSuperExpression(node: ts.Node, isCallExpression: boolean): bo ts.isPropertyDeclaration(node) || ts.isPropertySignature(node) || ts.isConstructorDeclaration(node); } -function checkSuperExpression(node: ts.SuperExpression) { +function checkSuperExpression(node: ts.SuperExpression): void { let file = jshelpers.getSourceFileOfNode(node); let isCallExpression = false; if (ts.isCallExpression(node.parent) && (node.parent).expression === node) { @@ -1205,7 +1205,7 @@ function checkSuperExpression(node: ts.SuperExpression) { } } -function checkImportExpression(node: ts.ImportExpression) { +function checkImportExpression(node: ts.ImportExpression): void { let args = (node.parent).arguments; if (args.length != 1) { throw new DiagnosticError(node, DiagnosticCode.Dynamic_imports_can_only_accept_a_module_specifier_optional_assertion_is_not_supported_yet); @@ -1218,19 +1218,19 @@ function checkImportExpression(node: ts.ImportExpression) { }); } -function checkRegularExpression(regexp: ts.RegularExpressionLiteral) { +function checkRegularExpression(regexp: ts.RegularExpressionLiteral): void { let regexpText = regexp.text; let regexpParse = require("regexpp").RegExpParser; new regexpParse().parseLiteral(regexpText); } -function checkThrowStatement(node: ts.ThrowStatement) { +function checkThrowStatement(node: ts.ThrowStatement): void { if (ts.isIdentifier(node.expression) && (node.expression).text === '') { throw new DiagnosticError(node, DiagnosticCode.Line_break_not_permitted_here, jshelpers.getSourceFileOfNode(node)); } } -function checkSyntaxErrorForSloppyAndStrictMode(node: ts.Node) { +function checkSyntaxErrorForSloppyAndStrictMode(node: ts.Node): void { switch (node.kind) { case ts.SyntaxKind.BreakStatement: case ts.SyntaxKind.ContinueStatement: @@ -1306,7 +1306,7 @@ function checkSyntaxErrorForSloppyAndStrictMode(node: ts.Node) { } } -function checkDestructuringAssignmentLhs(lhs: ts.Expression) { +function checkDestructuringAssignmentLhs(lhs: ts.Expression): void { let file = getSourceFileOfNode(lhs); if (ts.isArrayLiteralExpression(lhs)) { let elements = lhs.elements; @@ -1418,7 +1418,7 @@ function checkDestructuringAssignmentLhs(lhs: ts.Expression) { } } -function checkBindingPattern(node: ts.BindingPattern) { +function checkBindingPattern(node: ts.BindingPattern): void { let elements = node.elements; for (let i = 0; i < elements.length; i++) { diff --git a/ts2panda/src/syntaxCheckerForStrcitMode.ts b/ts2panda/src/syntaxCheckerForStrcitMode.ts index 5747aadad83abe31dff2bc620c5ba9675742ca25..a6a8eab07de4fe67fb5427f7052e3e1f26cec63f 100644 --- a/ts2panda/src/syntaxCheckerForStrcitMode.ts +++ b/ts2panda/src/syntaxCheckerForStrcitMode.ts @@ -32,14 +32,14 @@ import { stringLiteralIsInRegExp } from "./syntaxCheckHelper"; -function checkDeleteStatement(node: ts.DeleteExpression) { +function checkDeleteStatement(node: ts.DeleteExpression): void { let unaryExpr = node.expression; if (ts.isIdentifier(unaryExpr)) { throw new DiagnosticError(unaryExpr, DiagnosticCode.A_delete_cannot_be_called_on_an_identifier_in_strict_mode); } } -function checkNumericLiteral(node: ts.NumericLiteral) { +function checkNumericLiteral(node: ts.NumericLiteral): void { let num = jshelpers.getTextOfNode(node); if (!isOctalNumber(num)) { return; @@ -48,7 +48,7 @@ function checkNumericLiteral(node: ts.NumericLiteral) { throw new DiagnosticError(node, DiagnosticCode.Octal_literals_are_not_allowed_in_strict_mode); } -function checkString(node: ts.Node, text: string) { +function checkString(node: ts.Node, text: string): void { if (isIncludeOctalEscapeSequence(text)) { throw new DiagnosticError(node, DiagnosticCode.Octal_escape_sequences_are_not_allowed_in_strict_mode); @@ -59,7 +59,7 @@ function checkString(node: ts.Node, text: string) { } } -function checkStringLiteral(node: ts.StringLiteral) { +function checkStringLiteral(node: ts.StringLiteral): void { // Octal escape has been deprecated in ES5, but it can be used in regular expressions if (stringLiteralIsInRegExp(node)) { return; @@ -69,7 +69,7 @@ function checkStringLiteral(node: ts.StringLiteral) { checkString(node, text); } -function checkEvalOrArgumentsOrOriginalKeyword(contextNode: ts.Node, name: ts.Node | undefined) { +function checkEvalOrArgumentsOrOriginalKeyword(contextNode: ts.Node, name: ts.Node | undefined): void { if (!name || !ts.isIdentifier(name)) { return; } @@ -85,7 +85,7 @@ function checkEvalOrArgumentsOrOriginalKeyword(contextNode: ts.Node, name: ts.No } -function getStrictModeEvalOrArgumentsDiagnosticCode(node: ts.Node) { +function getStrictModeEvalOrArgumentsDiagnosticCode(node: ts.Node): any { if (jshelpers.getContainingClass(node)) { return DiagnosticCode.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode; } @@ -93,7 +93,7 @@ function getStrictModeEvalOrArgumentsDiagnosticCode(node: ts.Node) { return DiagnosticCode.Invalid_use_of_0_in_strict_mode; } -function getStrictModeIdentifierDiagnosticCode(node: ts.Node) { +function getStrictModeIdentifierDiagnosticCode(node: ts.Node): any { if (jshelpers.getContainingClass(node)) { return DiagnosticCode.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode; } @@ -101,7 +101,7 @@ function getStrictModeIdentifierDiagnosticCode(node: ts.Node) { return DiagnosticCode.Identifier_expected_0_is_a_reserved_word_in_strict_mode; } -function checkBinaryExpression(node: ts.BinaryExpression) { +function checkBinaryExpression(node: ts.BinaryExpression): void { if (!isLeftHandSideExpression(node.left) || !isAssignmentOperator(node.operatorToken.kind)) { return; } @@ -122,7 +122,7 @@ function checkBinaryExpression(node: ts.BinaryExpression) { checkEvalOrArgumentsOrOriginalKeyword(contextNode, name); } -function checkContextualIdentifier(node: ts.Identifier) { +function checkContextualIdentifier(node: ts.Identifier): void { let file = jshelpers.getSourceFileOfNode(node); if (jshelpers.getTextOfIdentifierOrLiteral(node) == 'await' && CmdOptions.isModules()) { throw new DiagnosticError(node, DiagnosticCode.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module, file, ['await']); @@ -138,7 +138,7 @@ function checkContextualIdentifier(node: ts.Identifier) { } -function checkParameters(decl: ts.FunctionLikeDeclaration | ts.FunctionExpression) { +function checkParameters(decl: ts.FunctionLikeDeclaration | ts.FunctionExpression): void { let parameters: ts.NodeArray = decl.parameters; let obj = new Map(); for (let i = 0; i < parameters.length; i++) { @@ -162,17 +162,17 @@ function checkParameters(decl: ts.FunctionLikeDeclaration | ts.FunctionExpressio } } -function checkWithStatement(node: ts.WithStatement) { +function checkWithStatement(node: ts.WithStatement): void { let file = jshelpers.getSourceFileOfNode(node); throw new DiagnosticError(node, DiagnosticCode.A_with_statements_are_not_allowed_in_strict_mode, file); } -function checkNoSubstitutionTemplateLiteral(expr: ts.NoSubstitutionTemplateLiteral) { +function checkNoSubstitutionTemplateLiteral(expr: ts.NoSubstitutionTemplateLiteral): void { let text = jshelpers.getTextOfNode(expr); checkString(expr, text.substring(1, text.length - 1)); } -function checkFunctionDeclaration(node: ts.FunctionDeclaration) { +function checkFunctionDeclaration(node: ts.FunctionDeclaration): void { checkEvalOrArgumentsOrOriginalKeyword(node, node.name); checkParameters(node); if (!isInBlockScope(node.parent!)) { @@ -180,7 +180,7 @@ function checkFunctionDeclaration(node: ts.FunctionDeclaration) { } } -function checkClassDeclaration(node: ts.ClassDeclaration) { +function checkClassDeclaration(node: ts.ClassDeclaration): void { if (!hasExportKeywordModifier(node) && !node.name) { if (!node.name && !hasDefaultKeywordModifier(node)) { throw new DiagnosticError(node, DiagnosticCode.Identifier_expected); @@ -188,7 +188,7 @@ function checkClassDeclaration(node: ts.ClassDeclaration) { } } -function checkImportDeclaration(node: ts.ImportDeclaration, scope: Scope) { +function checkImportDeclaration(node: ts.ImportDeclaration, scope: Scope): void { if (!(scope instanceof ModuleScope)) { throw new DiagnosticError(node, DiagnosticCode.An_import_declaration_can_only_be_used_in_a_namespace_or_module); } @@ -210,7 +210,7 @@ function checkImportDeclaration(node: ts.ImportDeclaration, scope: Scope) { } } -function checkExportAssignment(node: ts.ExportAssignment, scope: Scope) { +function checkExportAssignment(node: ts.ExportAssignment, scope: Scope): void { if (!(scope instanceof ModuleScope)) { throw new DiagnosticError(node, DiagnosticCode.An_export_assignment_must_be_at_the_top_level_of_a_file_or_module_declaration); } @@ -220,7 +220,7 @@ function checkExportAssignment(node: ts.ExportAssignment, scope: Scope) { } } -function checkExportDeclaration(node: ts.ExportDeclaration, scope: Scope) { +function checkExportDeclaration(node: ts.ExportDeclaration, scope: Scope): void { if (!(scope instanceof ModuleScope)) { throw new DiagnosticError(node, DiagnosticCode.An_export_declaration_can_only_be_used_in_a_module); } @@ -230,7 +230,7 @@ function checkExportDeclaration(node: ts.ExportDeclaration, scope: Scope) { } } -export function checkSyntaxErrorForStrictMode(node: ts.Node, scope: Scope) { +export function checkSyntaxErrorForStrictMode(node: ts.Node, scope: Scope): void { switch (node.kind) { case ts.SyntaxKind.NumericLiteral: checkNumericLiteral(node); diff --git a/ts2panda/src/ts2panda.ts b/ts2panda/src/ts2panda.ts index f6d17a09f2e198a277d59755a337f5bf718caf38..2ab5edbf6537c4d0bee9d68aa877ff4d9fff7c7d 100644 --- a/ts2panda/src/ts2panda.ts +++ b/ts2panda/src/ts2panda.ts @@ -85,7 +85,7 @@ export class Ts2Panda { return new Signature(pg.getParametersCount()); } - static getFuncInsnsAndRegsNum(pg: PandaGen) { + static getFuncInsnsAndRegsNum(pg: PandaGen): { insns: Ins[]; regsNum: number; labels: string[]; } { let insns: Array = []; let labels: Array = []; @@ -179,7 +179,7 @@ export class Ts2Panda { ts2abc.stdio[3].write(jsonStrUnicode + '\n'); } - static dumpTypeLiteralArrayBuffer() { + static dumpTypeLiteralArrayBuffer(): string { let literalArrays = PandaGen.getLiteralArrayBuffer(); let countType: LiteralBuffer = literalArrays[0]; let jsonTypeString: string = "" @@ -526,7 +526,7 @@ export class Ts2Panda { ts2abc.stdio[3].write("*" + '\n'); } - static clearDumpData() { + static clearDumpData(): void { Ts2Panda.strings.clear(); Ts2Panda.jsonString = ""; Ts2Panda.moduleRecordlist = []; diff --git a/ts2panda/src/typeChecker.ts b/ts2panda/src/typeChecker.ts index 85764ad230978c4d07f81b6e5dc1a15d5c549cb1..de2e363ef5dd82ff362213780ba5b263749ba5c9 100644 --- a/ts2panda/src/typeChecker.ts +++ b/ts2panda/src/typeChecker.ts @@ -47,7 +47,7 @@ export class TypeChecker { return TypeChecker.instance; } - public setTypeChecker(typeChecker: ts.TypeChecker) { + public setTypeChecker(typeChecker: ts.TypeChecker): void { this.compiledTypeChecker = typeChecker; } @@ -55,7 +55,7 @@ export class TypeChecker { return this.compiledTypeChecker; } - public getTypeAtLocation(node: ts.Node) { + public getTypeAtLocation(node: ts.Node): any { if (!node) { return undefined; } @@ -67,7 +67,7 @@ export class TypeChecker { } } - public getTypeDeclForIdentifier(node: ts.Node) { + public getTypeDeclForIdentifier(node: ts.Node): any { if (!node) { return undefined; } @@ -106,7 +106,7 @@ export class TypeChecker { return false; } - public getDeclNodeForInitializer(initializer: ts.Node) { + public getDeclNodeForInitializer(initializer: ts.Node): any { switch (initializer.kind) { case ts.SyntaxKind.Identifier: return this.getTypeDeclForIdentifier(initializer); @@ -147,7 +147,7 @@ export class TypeChecker { return classTypeIndex; } - public getTypeForPropertyAccessExpression(typeDeclNode: ts.Node) { + public getTypeForPropertyAccessExpression(typeDeclNode: ts.Node): number { let propertyAccessExpression = typeDeclNode; let localName = jshelpers.getTextOfIdentifierOrLiteral(propertyAccessExpression.expression); let externalName = jshelpers.getTextOfIdentifierOrLiteral(propertyAccessExpression.name); @@ -160,7 +160,7 @@ export class TypeChecker { return PrimitiveType.ANY; } - public getInterfaceDeclaration(typeDeclNode: ts.Node) { + public getInterfaceDeclaration(typeDeclNode: ts.Node): number { if (this.isFromDefaultLib(typeDeclNode)) { return PrimitiveType.ANY; } @@ -197,7 +197,7 @@ export class TypeChecker { } } - public getTypeForLiteralTypeNode(node: ts.Node) { + public getTypeForLiteralTypeNode(node: ts.Node): PrimitiveType.ANY | PrimitiveType.NUMBER | PrimitiveType.BOOLEAN | PrimitiveType.STRING | PrimitiveType.NULL { switch (node.kind) { case ts.SyntaxKind.NumericLiteral: return PrimitiveType.NUMBER; @@ -213,7 +213,7 @@ export class TypeChecker { } } - public getTypeFromAnotation(typeNode: ts.TypeNode | undefined) { + public getTypeFromAnotation(typeNode: ts.TypeNode | undefined): any { if (!typeNode) { return PrimitiveType.ANY; } @@ -265,16 +265,16 @@ export class TypeChecker { } } - isBuiltinType(expr: ts.NewExpression) { + isBuiltinType(expr: ts.NewExpression): boolean { let name = expr.expression.getFullText().replace(/\s/g, ""); return name in BuiltinType; } - isFromDefaultLib(node: ts.Node) { + isFromDefaultLib(node: ts.Node): boolean { return node.getSourceFile().hasNoDefaultLib; } - getOrCreateInstanceType(classTypeIdx: number) { + getOrCreateInstanceType(classTypeIdx: number): number { let typeRec = TypeRecorder.getInstance(); if (typeRec.hasClass2InstanceMap(classTypeIdx)) { return typeRec.getClass2InstanceMap(classTypeIdx); @@ -283,7 +283,7 @@ export class TypeChecker { return instanceType.shiftedTypeIndex; } - getOrCreateInstanceTypeForBuiltinContainer(builtinContainerSignature: object) { + getOrCreateInstanceTypeForBuiltinContainer(builtinContainerSignature: object): number { let typeRec = TypeRecorder.getInstance(); if (typeRec.hasBuiltinContainer2InstanceMap(builtinContainerSignature)) { return typeRec.getBuiltinContainer2InstanceMap(builtinContainerSignature); @@ -293,7 +293,7 @@ export class TypeChecker { return this.getOrCreateInstanceType(builtinContainerTypeIdx); } - getBuiltinTypeIndex(node: ts.NewExpression | ts.TypeReferenceNode, name: string) { + getBuiltinTypeIndex(node: ts.NewExpression | ts.TypeReferenceNode, name: string): number { let typeArguments = node.typeArguments; if (typeArguments && this.needRecordBuiltinContainer) { let typeArgIdxs = new Array(); @@ -310,13 +310,13 @@ export class TypeChecker { return this.getOrCreateInstanceType(BuiltinType[name]); } - getBuiltinTypeIndexForExpr(expr: ts.NewExpression) { + getBuiltinTypeIndexForExpr(expr: ts.NewExpression): number { let origExprNode = ts.getOriginalNode(expr); let name = origExprNode.expression.getFullText().replace(/\s/g, ""); return this.getBuiltinTypeIndex(origExprNode, name); } - public getOrCreateRecordForDeclNode(initializer: ts.Node | undefined, variableNode?: ts.Node) { + public getOrCreateRecordForDeclNode(initializer: ts.Node | undefined, variableNode?: ts.Node): PrimitiveType { if (!initializer) { return PrimitiveType.ANY; } @@ -335,7 +335,7 @@ export class TypeChecker { return typeIndex; } - public getOrCreateRecordForTypeNode(typeNode: ts.TypeNode | undefined, variableNode?: ts.Node) { + public getOrCreateRecordForTypeNode(typeNode: ts.TypeNode | undefined, variableNode?: ts.Node): PrimitiveType { if (!typeNode) { return PrimitiveType.ANY; } @@ -352,7 +352,7 @@ export class TypeChecker { return typeIndex; } - public formatVariableStatement(variableStatementNode: ts.VariableStatement) { + public formatVariableStatement(variableStatementNode: ts.VariableStatement): void { let decList = variableStatementNode.declarationList; decList.declarations.forEach(declaration => { let variableNode = declaration.name; @@ -369,7 +369,7 @@ export class TypeChecker { }); } - public formatClassDeclaration(classDeclNode: ts.ClassDeclaration) { + public formatClassDeclaration(classDeclNode: ts.ClassDeclaration): void { if (this.isFromDefaultLib(classDeclNode)) { return; } @@ -393,7 +393,7 @@ export class TypeChecker { } // Entry for type recording - public formatNodeType(node: ts.Node, importOrExportStmt?: ModuleStmt) { + public formatNodeType(node: ts.Node, importOrExportStmt?: ModuleStmt): void { if (this.compiledTypeChecker === null) { return; } diff --git a/ts2panda/src/typeRecorder.ts b/ts2panda/src/typeRecorder.ts index a760ffc08c2b5bb409c42a1a88ee9cc4a14c70d5..02a180dec04f860c2117ee2cdd593c2b8f7ae844 100644 --- a/ts2panda/src/typeRecorder.ts +++ b/ts2panda/src/typeRecorder.ts @@ -50,15 +50,15 @@ export class TypeRecorder { return TypeRecorder.instance; } - public setTypeSummary() { + public setTypeSummary(): void { this.typeSummary.setInfo(this.countUserDefinedTypeSet(), this.anonymousReExport); } - public getTypeSummaryIndex() { + public getTypeSummaryIndex(): number { return this.typeSummary.getPreservedIndex(); } - public addUserDefinedTypeSet(index: number) { + public addUserDefinedTypeSet(index: number): void { if (index > userDefinedTypeStartIndex) { this.userDefinedTypeSet.add(index); } @@ -68,12 +68,12 @@ export class TypeRecorder { return this.userDefinedTypeSet.size; } - public addType2Index(typeNode: ts.Node, index: number) { + public addType2Index(typeNode: ts.Node, index: number): void { this.type2Index.set(typeNode, index); this.addUserDefinedTypeSet(index); } - public setVariable2Type(variableNode: ts.Node, index: number) { + public setVariable2Type(variableNode: ts.Node, index: number): void { this.variable2Type.set(variableNode, index); this.addUserDefinedTypeSet(index); } @@ -98,56 +98,56 @@ export class TypeRecorder { } } - public setArrayTypeMap(contentTypeIndex: number, arrayTypeIndex: number) { + public setArrayTypeMap(contentTypeIndex: number, arrayTypeIndex: number): void { this.arrayTypeMap.set(contentTypeIndex, arrayTypeIndex) } - public hasArrayTypeMapping(contentTypeIndex: number) { + public hasArrayTypeMapping(contentTypeIndex: number): boolean { return this.arrayTypeMap.has(contentTypeIndex); } - public getFromArrayTypeMap(contentTypeIndex: number) { + public getFromArrayTypeMap(contentTypeIndex: number): number { return this.arrayTypeMap.get(contentTypeIndex); } - public setUnionTypeMap(unionStr: string, unionTypeIndex: number) { + public setUnionTypeMap(unionStr: string, unionTypeIndex: number): void { this.unionTypeMap.set(unionStr, unionTypeIndex) } - public hasUnionTypeMapping(unionStr: string) { + public hasUnionTypeMapping(unionStr: string): boolean { return this.unionTypeMap.has(unionStr); } - public getFromUnionTypeMap(unionStr: string) { + public getFromUnionTypeMap(unionStr: string): number { return this.unionTypeMap.get(unionStr); } - public setClass2InstanceMap(classIndex: number, instanceIndex: number) { + public setClass2InstanceMap(classIndex: number, instanceIndex: number): void { this.class2InstanceMap.set(classIndex, instanceIndex) } - public hasClass2InstanceMap(classIndex: number) { + public hasClass2InstanceMap(classIndex: number): boolean { return this.class2InstanceMap.has(classIndex); } - public getClass2InstanceMap(classIndex: number) { + public getClass2InstanceMap(classIndex: number): number { return this.class2InstanceMap.get(classIndex); } - public setBuiltinContainer2InstanceMap(builtinContainer: object, instanceIndex: number) { + public setBuiltinContainer2InstanceMap(builtinContainer: object, instanceIndex: number): void { this.builtinContainer2InstanceMap.set(builtinContainer, instanceIndex) } - public hasBuiltinContainer2InstanceMap(builtinContainer: object) { + public hasBuiltinContainer2InstanceMap(builtinContainer: object): boolean { return this.builtinContainer2InstanceMap.has(builtinContainer); } - public getBuiltinContainer2InstanceMap(builtinContainer: object) { + public getBuiltinContainer2InstanceMap(builtinContainer: object): number { return this.builtinContainer2InstanceMap.get(builtinContainer); } // exported/imported - public addImportedType(moduleStmt: ModuleStmt) { + public addImportedType(moduleStmt: ModuleStmt): void { moduleStmt.getBindingNodeMap().forEach((externalNode, localNode) => { let externalName = jshelpers.getTextOfIdentifierOrLiteral(externalNode); let importDeclNode = TypeChecker.getInstance().getTypeDeclForIdentifier(localNode); @@ -164,7 +164,7 @@ export class TypeRecorder { } } - public addExportedType(moduleStmt: ModuleStmt) { + public addExportedType(moduleStmt: ModuleStmt): void { if (moduleStmt.getModuleRequest() != "") { // re-export, no need to search in typeRecord cause it must not be there if (moduleStmt.getNameSpace() != "") { @@ -198,7 +198,7 @@ export class TypeRecorder { } } - public addNonReExportedType(exportedName: string, typeNode: ts.Node, localNode: ts.Node) { + public addNonReExportedType(exportedName: string, typeNode: ts.Node, localNode: ts.Node): void { // Check if type of localName was already stroed in typeRecord // Imported type should already be stored in typeRecord by design let typeIndexForType = this.tryGetTypeIndex(typeNode); @@ -215,27 +215,27 @@ export class TypeRecorder { } } - public setExportedType(exportedName: string, typeIndex: number) { + public setExportedType(exportedName: string, typeIndex: number): void { this.exportedType.set(exportedName, typeIndex); } - public setDeclaredType(exportedName: string, typeIndex: number) { + public setDeclaredType(exportedName: string, typeIndex: number): void { this.declaredType.set(exportedName, typeIndex); } - public addAnonymousReExport(redirectName: string) { + public addAnonymousReExport(redirectName: string): void { this.anonymousReExport.push(redirectName); } - public setNamespaceMap(namespace: string, filePath: string) { + public setNamespaceMap(namespace: string, filePath: string): void { this.namespaceMap.set(namespace, filePath); } - public inNampespaceMap(targetName: string) { + public inNampespaceMap(targetName: string): boolean { return this.namespaceMap.has(targetName); } - public getPathForNamespace(targetName: string) { + public getPathForNamespace(targetName: string): string { return this.namespaceMap.get(targetName); } @@ -248,39 +248,39 @@ export class TypeRecorder { return this.variable2Type; } - public getTypeSet() { + public getTypeSet(): Set { return this.userDefinedTypeSet; } - public getExportedType() { + public getExportedType(): Map { return this.exportedType; } - public getDeclaredType() { + public getDeclaredType(): Map { return this.declaredType; } - public getAnonymousReExport() { + public getAnonymousReExport(): string[] { return this.anonymousReExport; } - public getNamespaceMap() { + public getNamespaceMap(): Map { return this.namespaceMap; } - public printNodeMap(map: Map) { + public printNodeMap(map: Map): void { map.forEach((value, key) => { console.log(jshelpers.getTextOfNode(key) + ": " + value); }); } - public printExportMap(map: Map) { + public printExportMap(map: Map): void { map.forEach((value, key) => { console.log(key + " : " + value); }); } - public printReExportMap(map: Map) { + public printReExportMap(map: Map): void { map.forEach((value, key) => { console.log(key + " : " + value); }); diff --git a/ts2panda/src/variable.ts b/ts2panda/src/variable.ts index 4f51d0af8b5bbfbc4567256641ebfd995f7f6f11..1e1471aaaabc87019736a673fd08fc48143f8cd5 100644 --- a/ts2panda/src/variable.ts +++ b/ts2panda/src/variable.ts @@ -44,7 +44,7 @@ export abstract class Variable { this.typeIndex = 0; } - bindVreg(vreg: VReg) { + bindVreg(vreg: VReg): void { this.vreg = vreg; this.vreg.setTypeIndex(this.typeIndex); this.vreg.setVariableName(this.name); @@ -61,19 +61,19 @@ export abstract class Variable { return this.vreg; } - getName() { + getName(): string { return this.name; } - getTypeIndex() { + getTypeIndex(): number { return this.typeIndex; } - setTypeIndex(typeIndex: number) { + setTypeIndex(typeIndex: number): number { return this.typeIndex = typeIndex; } - setLexVar(scope: VariableScope | LoopScope) { + setLexVar(scope: VariableScope | LoopScope): number { if (this.lexical()) { return; } @@ -84,7 +84,7 @@ export abstract class Variable { return this.idxLex; } - clearLexVar() { + clearLexVar(): void { this.isLexVar = false; this.idxLex = 0; } @@ -93,7 +93,7 @@ export abstract class Variable { return this.isLexVar; } - lexIndex() { + lexIndex(): number { return this.idxLex; } @@ -130,11 +130,11 @@ export class LocalVariable extends Variable { this.status = status ? status : null; } - initialize() { + initialize(): void { this.status = InitStatus.INITIALIZED; } - isInitialized() { + isInitialized(): boolean { if (this.status != null) { return this.status == InitStatus.INITIALIZED; } @@ -153,30 +153,30 @@ export class ModuleVariable extends Variable { this.status = status ? status : null; } - initialize() { + initialize(): void { this.status = InitStatus.INITIALIZED; } - isInitialized() { + isInitialized(): boolean { if (this.status != null) { return this.status == InitStatus.INITIALIZED; } return true; } - setExport() { + setExport(): void { this.isExport = true; } - isExportVar() { + isExportVar(): boolean { return this.isExport; } - assignIndex(index: number) { + assignIndex(index: number): void { this.index = index; } - getIndex() { + getIndex(): number { return this.index; } } @@ -192,7 +192,7 @@ export const MandatoryNewTarget = "4newTarget"; export const MandatoryThis = "this"; export const MandatoryArguments = "arguments"; -export function isMandatoryParam(name: string) { +export function isMandatoryParam(name: string): boolean { if (name == MandatoryFuncObj || name == MandatoryArguments || name == MandatoryNewTarget || name == MandatoryThis) { return true; diff --git a/ts2panda/tests/expression/templateExpression.test.ts b/ts2panda/tests/expression/templateExpression.test.ts index 5752c6c3df11720dc6f68b9b6540dffb5417359d..42330c6105d4cabc687295eb5a446843ed4b8454 100644 --- a/ts2panda/tests/expression/templateExpression.test.ts +++ b/ts2panda/tests/expression/templateExpression.test.ts @@ -41,7 +41,7 @@ import { checkInstructions, compileMainSnippet } from "../utils/base"; import { creatAstFromSnippet } from "../utils/asthelper" import { PandaGen } from '../../src/pandagen'; -function MicroCreateAddInsns(leftVal: number, rightVal: number, icSize: number) { +function MicroCreateAddInsns(leftVal: number, rightVal: number, icSize: number): { insns: any[]; nextIc: number; } { let insns = []; let lhs = new VReg(); @@ -55,7 +55,7 @@ function MicroCreateAddInsns(leftVal: number, rightVal: number, icSize: number) return {insns: insns, nextIc: nextIc}; } -function MicroCreateObjAndPropInsns(icSize: number) { +function MicroCreateObjAndPropInsns(icSize: number): { insns: any[]; nextIc: number; } { let insns = []; let obj = new VReg(); let val = new VReg(); @@ -71,7 +71,7 @@ function MicroCreateObjAndPropInsns(icSize: number) { return {insns: insns, nextIc: nextIc}; } -function MicroGetTemplateObject(rawArr: VReg, cookedArr: VReg, icSize: number) { +function MicroGetTemplateObject(rawArr: VReg, cookedArr: VReg, icSize: number): { insns: any[]; nextIc: number; } { let insns = []; let objReg = new VReg(); let indexReg = new VReg(); diff --git a/ts2panda/tests/types/typeUtils.ts b/ts2panda/tests/types/typeUtils.ts index 88fafdb37693297badcb3b48c4f7a32ca66ee3fb..fa269a95e02548b263bca7a515407967fa573128 100644 --- a/ts2panda/tests/types/typeUtils.ts +++ b/ts2panda/tests/types/typeUtils.ts @@ -41,7 +41,7 @@ let options = { alwaysStrict: true } -export function compileTsWithType(fileName: string) { +export function compileTsWithType(fileName: string): { literalBufferArray: LiteralBuffer[]; snippetCompiler: SnippetCompiler; } { CmdOptions.parseUserCmd([""]); let filePath = [fileName]; @@ -62,7 +62,7 @@ export function compileTsWithType(fileName: string) { } } -export function createVRegTypePair(input: any) { +export function createVRegTypePair(input: any): Map { let id2TypeIndex: Map = new Map(); for (let rol of input) { id2TypeIndex.set(rol[0], rol[1]); @@ -92,7 +92,7 @@ export function compareVReg2Type(expectedMap: Map, generated: VR return true; } -export function createLiteralBufferArray(input: any) { +export function createLiteralBufferArray(input: any): LiteralBuffer[] { let literalBufferArray: Array = new Array(); for (let i = 0; i < input.length; i++) { let buff = input[i]; @@ -107,7 +107,7 @@ export function createLiteralBufferArray(input: any) { return literalBufferArray; } -function printLiteralLog(expected: Literal, generated: Literal) { +function printLiteralLog(expected: Literal, generated: Literal): void { console.log("expected literals:"); console.log(expected); console.log("unmatched literals:"); diff --git a/ts2panda/tests/utils/base.ts b/ts2panda/tests/utils/base.ts index 82def1690766050c31dc3763de237c9cea7c9653..870acacff227b9514322bc6a245827e3e9797d47 100644 --- a/ts2panda/tests/utils/base.ts +++ b/ts2panda/tests/utils/base.ts @@ -185,7 +185,7 @@ export function compileMainSnippet(snippet: string, pandaGen?: PandaGen, scope?: return compileUnits[0].getInsns(); } -export function compileAfterSnippet(snippet: string, name:string, isCommonJs: boolean = false) { +export function compileAfterSnippet(snippet: string, name:string, isCommonJs: boolean = false): any { let compileUnits = null; CmdOptions.parseUserCmd([""]); CmdOptions.setMergeAbc(true); @@ -230,17 +230,17 @@ export function getCompileOptions(): ts.CompilerOptions { export class SnippetCompiler { pandaGens: PandaGen[] = []; - compile(snippet: string, passes?: Pass[], literalBufferArray?: Array) { + compile(snippet: string, passes?: Pass[], literalBufferArray?: Array): PandaGen[] { this.pandaGens = compileAllSnippet(snippet, passes, literalBufferArray); return this.pandaGens; } - compileAfter(snippet: string, name: string, passes?: Pass[], literalBufferArray?: Array) { + compileAfter(snippet: string, name: string, passes?: Pass[], literalBufferArray?: Array): PandaGen[] { this.pandaGens = compileAfterSnippet(snippet, name); return this.pandaGens; } - compileCommonjs(snippet: string, name: string) { + compileCommonjs(snippet: string, name: string): PandaGen[] { this.pandaGens = compileAfterSnippet(snippet, name, true); return this.pandaGens; } diff --git a/ts2panda/tests/utils/example_asthelper.ts b/ts2panda/tests/utils/example_asthelper.ts index 3daf8024213a0b924f694c6df376305b083f0b9d..7d2c04698e408440fdf2d20de9f792967d00ed65 100644 --- a/ts2panda/tests/utils/example_asthelper.ts +++ b/ts2panda/tests/utils/example_asthelper.ts @@ -15,11 +15,11 @@ import * as asthelper from "./asthelper"; -function testCreateAstFromSnippet() { +function testCreateAstFromSnippet(): void { let ast = asthelper.creatAstFromSnippet("var aaa = 10"); console.log(ast.getText()); } -function testCreateAstFromFile() { +function testCreateAstFromFile(): void { const absolutePath = __dirname + "/example_asthelper.js" let ast = asthelper.creatAstFromFile(absolutePath); console.log(ast.getText());