diff --git a/ts2panda/src/assemblyDumper.ts b/ts2panda/src/assemblyDumper.ts index 6b2fc9d7932499c3f87709cea21d47a4de824f3f..da3f11daa9628437836b724b875d1109ded0acec 100644 --- a/ts2panda/src/assemblyDumper.ts +++ b/ts2panda/src/assemblyDumper.ts @@ -41,7 +41,7 @@ export class IntrinsicInfo { } export class AssemblyDumper { - private labels: Map // Label.id : Label string name + private labels: Map; // Label.id : Label string name private labelId: number; private pg: PandaGen; readonly labelPrefix = "LABEL_"; @@ -62,7 +62,7 @@ export class AssemblyDumper { writeFunctionHeader(): void { let parametersCount = this.pg.getParametersCount(); - this.output += ".function any " + this.pg.internalName + "(" + this.output += ".function any " + this.pg.internalName + "("; for (let i = 0; i < parametersCount; ++i) { this.output += "any a" + i.toString(); if (i !== parametersCount - 1) { @@ -96,11 +96,11 @@ export class AssemblyDumper { continue; } - this.output += "\t" + this.output += "\t"; this.output += node.getMnemonic() + " "; let operands = node.operands; let formats = node.getFormats(); - var outputRangeVregNum = getRangeExplicitVregNums(node); + let outputRangeVregNum = getRangeExplicitVregNums(node); for (let j = 0; j < operands.length; ++j) { if (outputRangeVregNum == 0) { break; @@ -118,9 +118,9 @@ export class AssemblyDumper { let escapedOp = op.toString().replace(/\\/g, "\\\\").replace(/\t/g, "\\t") .replace(/\n/g, "\\n").replace(/\"/g, "\\\"") this.output += "\"" + escapedOp + "\""; - } else if (kind == OperandKind.DstVReg - || kind == OperandKind.SrcDstVReg - || kind == OperandKind.SrcVReg) { + } else if (kind == OperandKind.DstVReg || + kind == OperandKind.SrcDstVReg || + kind == OperandKind.SrcVReg) { let v = op; if (v.num < 0) { throw Error("invalid register, please check your insn!\n"); @@ -159,10 +159,10 @@ export class AssemblyDumper { let catchBeginLabel = catchTable.getCatchBeginLabel(); let labelPairs = catchTable.getLabelPairs(); labelPairs.forEach((labelPair) => { - this.output += ".catchall " + this.getLabelName(labelPair.getBeginLabel()) - + ", " + this.getLabelName(labelPair.getEndLabel()) - + ", " + this.getLabelName(catchBeginLabel) - + "\n" + this.output += ".catchall " + this.getLabelName(labelPair.getBeginLabel()) + + ", " + this.getLabelName(labelPair.getEndLabel()) + + ", " + this.getLabelName(catchBeginLabel) + + "\n"; }); }); } @@ -195,6 +195,6 @@ export class AssemblyDumper { static dumpHeader(): void { let out = { str: "" }; AssemblyDumper.writeLanguageTag(out); - console.log(out.str) + console.log(out.str); } } diff --git a/ts2panda/src/base/lreference.ts b/ts2panda/src/base/lreference.ts index f51dc6f7748ada6c976bfe43a4d542dba3ce8004..007144fd7978d805dd2711ad146d15d3f48af021 100644 --- a/ts2panda/src/base/lreference.ts +++ b/ts2panda/src/base/lreference.ts @@ -77,7 +77,7 @@ export class LReference { case ReferenceKind.Destructuring: throw new Error("Destructuring target can't be loaded"); default: - throw new Error("Invalid LReference kind to GetValue") + throw new Error("Invalid LReference kind to GetValue"); } } @@ -85,7 +85,7 @@ export class LReference { let pandaGen = this.compiler.getPandaGen(); switch (this.refKind) { case ReferenceKind.MemberAccess: { - let prop: VReg | number | string + let prop: VReg | number | string; if (this.propLiteral === undefined) { prop = this.prop!; } else { @@ -109,7 +109,7 @@ export class LReference { compileDestructuring(this.destructuringTarget, pandaGen, this.compiler); return; default: - throw new Error("Invalid LReference kind to SetValue") + throw new Error("Invalid LReference kind to SetValue"); } } diff --git a/ts2panda/src/base/properties.ts b/ts2panda/src/base/properties.ts index cd11acf7e4c1b6f0d0ae040d03163acf15a6df61..30e4c56a77470687e8ea2f2ce7ae78af95b761ae 100644 --- a/ts2panda/src/base/properties.ts +++ b/ts2panda/src/base/properties.ts @@ -71,7 +71,7 @@ export class Property { getValue() { if (this.propKind == PropertyKind.Accessor) { - throw new Error("Accessor doesn't have valueNode") + throw new Error("Accessor doesn't have valueNode"); } return this.valueNode!; } @@ -199,8 +199,8 @@ function defineProperty( if (namedPropertyMap.has(name_str)) { let prevProp = properties[namedPropertyMap.get(name_str)!]; - if ((prevProp.getKind() == PropertyKind.Accessor || prevProp.getKind() == PropertyKind.Constant) - && (propKind == PropertyKind.Accessor || propKind == PropertyKind.Constant)) { + if ((prevProp.getKind() == PropertyKind.Accessor || prevProp.getKind() == PropertyKind.Constant) && + (propKind == PropertyKind.Accessor || propKind == PropertyKind.Constant)) { if (propKind == PropertyKind.Accessor) { if (ts.isGetAccessorDeclaration(propValue)) { prevProp!.setGetter(propValue); diff --git a/ts2panda/src/base/typeSystem.ts b/ts2panda/src/base/typeSystem.ts index 18a04e51326805ea38334dfe9ec5af7fe4c5001e..c4c360ad6a78d93963297a8093183da669f7b77c 100644 --- a/ts2panda/src/base/typeSystem.ts +++ b/ts2panda/src/base/typeSystem.ts @@ -370,8 +370,8 @@ export class ClassType extends BaseType { } } - let typeNode = member.type - let memberName = member.name + let typeNode = member.type; + let memberName = member.name; fieldInfo[0] = this.getOrCreateRecordForTypeNode(typeNode, memberName); if (isStatic) { diff --git a/ts2panda/src/base/util.ts b/ts2panda/src/base/util.ts index 24bd25e9a95cce0259a850dfee3faf6802983472..7f1c840c1179eb555644c49ab4f7490c5904bb6e 100644 --- a/ts2panda/src/base/util.ts +++ b/ts2panda/src/base/util.ts @@ -78,7 +78,7 @@ export function hasDefaultKeywordModifier(node: ts.Node): boolean { } export function execute(cmd: string, args: Array) { - var spawn = require('child_process').spawn; + let spawn = require('child_process').spawn; let child = spawn(cmd, [...args], { stdio: ['pipe', 'inherit', 'inherit'] @@ -139,8 +139,8 @@ export function isBindingOrAssignmentPattern(node: ts.Node) { } export function isMemberExpression(node: ts.Node) { - if (ts.isPropertyAccessExpression(node) - || ts.isElementAccessExpression(node)) { + if (ts.isPropertyAccessExpression(node) || + ts.isElementAccessExpression(node)) { return true; } @@ -175,7 +175,7 @@ export function escapeUnicode(data: string) { let char = '\n'; let i = 0; let j = 0; - let new_data = "" + let new_data = ""; while ((j = data.indexOf(char, i)) !== -1) { let tmp = data.substring(i, j); if (tmp.indexOf("\\u") != -1) { @@ -186,14 +186,14 @@ export function escapeUnicode(data: string) { } new_data = new_data.concat("}\n"); - return new_data + return new_data; } export function initiateTs2abc(args: Array) { let js2abc = path.join(path.resolve(__dirname, '../bin'), "js2abc"); args.unshift("--compile-by-pipe"); // @ts-ignore - var spawn = require('child_process').spawn; + let spawn = require('child_process').spawn; let child = spawn(js2abc, [...args], { stdio: ['pipe', 'inherit', 'inherit', 'pipe'] }); @@ -407,7 +407,7 @@ export function getOutputBinName(node: ts.SourceFile) { let fileName = node.fileName.substring(0, node.fileName.lastIndexOf('.')); let inputFileName = CmdOptions.getInputFileName(); if (/^win/.test(require('os').platform())) { - var inputFileTmps = inputFileName.split(path.sep); + let inputFileTmps = inputFileName.split(path.sep); inputFileName = path.posix.join(...inputFileTmps); } @@ -446,11 +446,11 @@ function getNodeForGeneratedName( node = original; // if "node" is a different generated name (having a different "autoGenerateId"), use it and stop traversing. - if (ts.isIdentifier(node) + if (ts.isIdentifier(node) && // @ts-ignore - && !!(node.autoGenerateFlags! & ts.GeneratedIdentifierFlags.Node) + !!(node.autoGenerateFlags! & ts.GeneratedIdentifierFlags.Node) && // @ts-ignore - && node.autoGenerateId !== autoGenerateId) { + node.autoGenerateId !== autoGenerateId) { break; } // @ts-ignore diff --git a/ts2panda/src/cmdOptions.ts b/ts2panda/src/cmdOptions.ts index ff02ad83b28dcce341b9126eb024f3734da9b7d7..d243c1e5547006353bd79584532455afb9bd54b9 100644 --- a/ts2panda/src/cmdOptions.ts +++ b/ts2panda/src/cmdOptions.ts @@ -281,7 +281,7 @@ export class CmdOptions { static getVersion(isBcVersion: boolean = true): void { let js2abc = path.join(path.resolve(__dirname, '../bin'), "js2abc"); - let version_arg = isBcVersion ? "--bc-version" : "--bc-min-version" + let version_arg = isBcVersion ? "--bc-version" : "--bc-min-version"; execute(`${js2abc}`, [version_arg]); } diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index 4818a0fd771cee14fc0bef2ed1999c23ae0a81d5..8f04ad650beb470837ac4a614494cb52493539bb 100644 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -124,7 +124,7 @@ import { } from "./variable"; import { compileCommaListExpression -} from "./expression/compileCommaListExpression" +} from "./expression/compileCommaListExpression"; export enum ControlFlowChange { Continue, Break } export class Compiler { @@ -234,7 +234,7 @@ export class Compiler { let unreachableFlag = false; if (body.parent && ts.isConstructorDeclaration(body.parent)) { - compileDefaultInitClassMembers(this, body.parent) + compileDefaultInitClassMembers(this, body.parent); } statements.forEach((stmt) => { @@ -490,8 +490,8 @@ export class Compiler { return; } - if ((astutils.getVarDeclarationKind(decl) == VarDeclarationKind.LET) - && decl.parent.kind != ts.SyntaxKind.CatchClause) { + if ((astutils.getVarDeclarationKind(decl) == VarDeclarationKind.LET) && + decl.parent.kind != ts.SyntaxKind.CatchClause) { this.pandaGen.loadAccumulator(decl, getVregisterCache(this.pandaGen, CacheList.undefined)); } } @@ -627,7 +627,8 @@ export class Compiler { pandaGen.throw(stmt); } - compileFinallyBeforeCFC(endTry: TryStatement | undefined, cfc: ControlFlowChange, continueTargetLabel: Label | undefined) {// compile finally before control flow change + // compile finally before control flow change + compileFinallyBeforeCFC(endTry: TryStatement | undefined, cfc: ControlFlowChange, continueTargetLabel: Label | undefined) { let startTry = TryStatement.getCurrentTryStatement(); let originTry = startTry; let currentScope = this.scope; @@ -639,7 +640,7 @@ export class Compiler { let inlinedLabelPair = new LabelPair(inlineFinallyBegin, inlineFinallyEnd); // adjust the current tryStatement before inlining finallyBlock let saveTry = TryStatement.getCurrentTryStatement(); - TryStatement.setCurrentTryStatement(startTry.getOuterTryStatement()) + TryStatement.setCurrentTryStatement(startTry.getOuterTryStatement()); this.pandaGen.label(startTry.getStatement(), inlineFinallyBegin); startTry.trybuilder.compileFinalizer(cfc, continueTargetLabel); @@ -968,7 +969,7 @@ export class Compiler { if (arg.text.match(/ *return +this[;]? *$/) == null) { return false; } else { - this.pandaGen.loadAccumulator(expr, getVregisterCache(this.pandaGen, CacheList.Global)) + this.pandaGen.loadAccumulator(expr, getVregisterCache(this.pandaGen, CacheList.Global)); return true; } } @@ -1224,9 +1225,9 @@ export class Compiler { return; } // LogicAnd, LogicOr and Coalesce are Short-circuiting - if (expr.operatorToken.kind == ts.SyntaxKind.AmpersandAmpersandToken - || expr.operatorToken.kind == ts.SyntaxKind.BarBarToken - || expr.operatorToken.kind == ts.SyntaxKind.QuestionQuestionToken) { + if (expr.operatorToken.kind == ts.SyntaxKind.AmpersandAmpersandToken || + expr.operatorToken.kind == ts.SyntaxKind.BarBarToken || + expr.operatorToken.kind == ts.SyntaxKind.QuestionQuestionToken) { this.compileLogicalExpression(expr); return; } @@ -1311,7 +1312,7 @@ export class Compiler { let { arguments: argRegs, passThis: passThis } = getHiddenParameters(expr.tag, this); // +3 for function and this getTemplateObject(pandaGen, expr); let templateObj = pandaGen.getTemp(); - pandaGen.storeAccumulator(expr, templateObj) + pandaGen.storeAccumulator(expr, templateObj); argRegs.push(templateObj); if (spans && spans.length) { @@ -1390,7 +1391,7 @@ export class Compiler { pandaGen.storeLexicalVar(node, thisInfo.level, slot, value); pandaGen.freeTemps(value); } else { - pandaGen.storeAccumulator(node, pandaGen.getVregForVariable(thisInfo.v)) + pandaGen.storeAccumulator(node, pandaGen.getVregForVariable(thisInfo.v)); } } diff --git a/ts2panda/src/compilerDriver.ts b/ts2panda/src/compilerDriver.ts index ca2e9f1f622909742de8f667ce63683fb90698c8..b05912da7117f11ed6b23a1768e3c5ad3567e751 100644 --- a/ts2panda/src/compilerDriver.ts +++ b/ts2panda/src/compilerDriver.ts @@ -103,7 +103,7 @@ export class CompilerDriver { getTs2abcProcess(): any { if (this.ts2abcProcess === undefined) { - throw new Error("ts2abc hasn't been initiated") + throw new Error("ts2abc hasn't been initiated"); } return this.ts2abcProcess; } @@ -409,8 +409,8 @@ export class CompilerDriver { let funcNode = node; name = (recorder.getScopeOfNode(funcNode)).getFuncName(); if (name == '') { - if ((ts.isFunctionDeclaration(node) && hasExportKeywordModifier(node) && hasDefaultKeywordModifier(node)) - || ts.isExportAssignment(findOuterNodeOfParenthesis(node))) { + if ((ts.isFunctionDeclaration(node) && hasExportKeywordModifier(node) && hasDefaultKeywordModifier(node)) || + ts.isExportAssignment(findOuterNodeOfParenthesis(node))) { return `${this.getFormatedRecordName()}default`; } return `${this.getFormatedRecordName()}#${this.getFuncId(funcNode)}#`; @@ -431,7 +431,7 @@ export class CompilerDriver { } if (name.lastIndexOf(".") != -1 || name.lastIndexOf("\\") != -1) { - name = `#${this.getFuncId(funcNode)}#` + name = `#${this.getFuncId(funcNode)}#`; } } return `${this.getFormatedRecordName()}${name}`; @@ -439,9 +439,9 @@ export class CompilerDriver { getInternalNameForCtor(node: ts.ClassLikeDeclaration, ctor: ts.ConstructorDeclaration) { let name = getClassNameForConstructor(node); - name = `#${this.getFuncId(ctor)}#${name}` + name = `#${this.getFuncId(ctor)}#${name}`; if (name.lastIndexOf(".") != -1) { - name = `#${this.getFuncId(ctor)}#` + name = `#${this.getFuncId(ctor)}#`; } return `${this.getFormatedRecordName()}${name}`; } diff --git a/ts2panda/src/compilerStatistics.ts b/ts2panda/src/compilerStatistics.ts index e94a3e1543b540ca754b80f912c74a132ac20014..f65339684f87cea18f836feec2c73e9c17fb4a09 100644 --- a/ts2panda/src/compilerStatistics.ts +++ b/ts2panda/src/compilerStatistics.ts @@ -121,7 +121,7 @@ class HistogramStatistics { getInsName(ins: IRNode): string { if (ins.kind == IRNodeKind.LABEL) { - return "Label" + return "Label"; } return ins.getMnemonic(); @@ -187,14 +187,15 @@ class HistogramStatistics { LOGD("op code\t\t\tinsns number\tins size\ttotal size\tsize percentage"); this.insHistogram.forEach((value, key) => { if (key.length < 8) { // 8 indicates insn name length - LOGD(key + "\t\t\t" + value.getCount() + "\t\t"+ value.getInstSize() + "\t\t" + value.getTotalSize() + "\t\t" - + value.getSavedSizeIfRemoved(this) + "\t" + Math.round(value.getSavedSizeIfRemoved(this) / totalSize * 100) + "%"); // multiplying 100 is to calculate percentage data + // multiplying 100 is to calculate percentage data + LOGD(key + "\t\t\t" + value.getCount() + "\t\t"+ value.getInstSize() + "\t\t" + value.getTotalSize() + "\t\t" + + value.getSavedSizeIfRemoved(this) + "\t" + Math.round(value.getSavedSizeIfRemoved(this) / totalSize * 100) + "%"); } else if (key.length < 16) { // 16 indicates insn name length - LOGD(key + "\t\t" + value.getCount() + "\t\t" + value.getInstSize() + "\t\t" + value.getTotalSize() + "\t\t" - + value.getSavedSizeIfRemoved(this) + "\t" + Math.round(value.getSavedSizeIfRemoved(this) / totalSize * 100) + "%"); + LOGD(key + "\t\t" + value.getCount() + "\t\t" + value.getInstSize() + "\t\t" + value.getTotalSize() + "\t\t" + + value.getSavedSizeIfRemoved(this) + "\t" + Math.round(value.getSavedSizeIfRemoved(this) / totalSize * 100) + "%"); } else { - LOGD(key + "\t" + value.getCount() + "\t\t" + value.getInstSize() + "\t\t" + value.getTotalSize() + "\t\t" - + value.getSavedSizeIfRemoved(this) + "\t" + Math.round(value.getSavedSizeIfRemoved(this) / totalSize * 100) + "%"); + LOGD(key + "\t" + value.getCount() + "\t\t" + value.getInstSize() + "\t\t" + value.getTotalSize() + "\t\t" + + value.getSavedSizeIfRemoved(this) + "\t" + Math.round(value.getSavedSizeIfRemoved(this) / totalSize * 100) + "%"); } }); diff --git a/ts2panda/src/ecmaModule.ts b/ts2panda/src/ecmaModule.ts index d69254de3850114bc903de52c3c177b9bba4d653..97273f70086660fec826ca6c66e54c023c9f2c7c 100644 --- a/ts2panda/src/ecmaModule.ts +++ b/ts2panda/src/ecmaModule.ts @@ -199,13 +199,17 @@ export class SourceTextModuleRecord { { let dupExportEntry: Entry | undefined = this.searchDuplicateExport(); if (dupExportEntry !== undefined) { - throw new DiagnosticError(dupExportEntry.node, DiagnosticCode.Module_0_has_already_exported_a_member_named_1, getSourceFileOfNode(dupExportEntry.node), [getSourceFileOfNode(dupExportEntry.node).fileName, dupExportEntry.exportName]); + throw new DiagnosticError(dupExportEntry.node, DiagnosticCode.Module_0_has_already_exported_a_member_named_1, + getSourceFileOfNode(dupExportEntry.node), + [getSourceFileOfNode(dupExportEntry.node).fileName, dupExportEntry.exportName]); } } this.localExportEntries.forEach((entry: Array, localName: string) => { if (!moduleScope.hasDecl(localName) && localName != '*default*') { - throw new DiagnosticError(entry[0].node, DiagnosticCode.Module_0_has_no_exported_member_1, getSourceFileOfNode(entry[0].node), [getSourceFileOfNode(entry[0].node).fileName, localName]); + throw new DiagnosticError(entry[0].node, DiagnosticCode.Module_0_has_no_exported_member_1, + getSourceFileOfNode(entry[0].node), + [getSourceFileOfNode(entry[0].node).fileName, localName]); } }); diff --git a/ts2panda/src/expression/memberAccessExpression.ts b/ts2panda/src/expression/memberAccessExpression.ts index 1183bb7befba05e6fae1b876048ae497a445408f..7a5c27a104d78b32a31e05c722269b217d991ebc 100644 --- a/ts2panda/src/expression/memberAccessExpression.ts +++ b/ts2panda/src/expression/memberAccessExpression.ts @@ -26,7 +26,7 @@ export function compileMemberAccessExpression(node: ts.ElementAccessExpression | let objReg = pandaGen.getTemp(); let propReg = pandaGen.getTemp(); - let { obj: obj, prop: property } = getObjAndProp(node, objReg, propReg, compiler) + let { obj: obj, prop: property } = getObjAndProp(node, objReg, propReg, compiler); if (jshelpers.isSuperProperty(node)) { // make sure "this" is stored in lexical env if needed diff --git a/ts2panda/src/expression/objectLiteralExpression.ts b/ts2panda/src/expression/objectLiteralExpression.ts index 1d6af9384c4f132e56561f2e59e14493848057c9..001329c85247246bab808bb6b175d34185227233 100644 --- a/ts2panda/src/expression/objectLiteralExpression.ts +++ b/ts2panda/src/expression/objectLiteralExpression.ts @@ -263,8 +263,8 @@ function setUncompiledProperties(compiler: Compiler, pandaGen: PandaGen, propert createMethodOrAccessor(pandaGen, compiler, objReg, prop.getValue()); } else { compiler.compileExpression(prop.getValue()); - nameSetting = needSettingName(prop.getValue()) - && ((prop.getName())).toString().lastIndexOf('.') != -1; + nameSetting = needSettingName(prop.getValue()) && + ((prop.getName())).toString().lastIndexOf('.') != -1; } pandaGen.storeOwnProperty(prop.getValue().parent, objReg, (prop.getName()), nameSetting); break; diff --git a/ts2panda/src/expression/templateExpression.ts b/ts2panda/src/expression/templateExpression.ts index a6315cb7248067459057b1aa39d1cb8f51728dc5..aa5b7ac1a3baf47a8edff55b011438a920d16347 100644 --- a/ts2panda/src/expression/templateExpression.ts +++ b/ts2panda/src/expression/templateExpression.ts @@ -18,7 +18,7 @@ import { PandaGen } from "../pandagen"; import { VReg } from "../irnodes"; function genRawString(pandaGen: PandaGen, expr: ts.TemplateExpression | ts.NoSubstitutionTemplateLiteral) { - let text = "" + let text = ""; if (ts.isTemplateExpression(expr)) { text = expr.head.rawText!; } else { @@ -30,7 +30,7 @@ function genRawString(pandaGen: PandaGen, expr: ts.TemplateExpression | ts.NoSub } function genCookedString(pandaGen: PandaGen, expr: ts.TemplateExpression | ts.NoSubstitutionTemplateLiteral) { - let text = "" + let text = ""; if (ts.isTemplateExpression(expr)) { text = expr.head.text; } else { @@ -63,10 +63,10 @@ function genTemplateArrayArg(pandaGen: PandaGen, expr: ts.TemplateExpression | t pandaGen.loadAccumulatorInt(expr, elemIndex); pandaGen.storeAccumulator(expr, indexReg); - genRawString(pandaGen, expr) + genRawString(pandaGen, expr); pandaGen.storeObjProperty(expr, rawArrTmp, indexReg); - genCookedString(pandaGen, expr) + genCookedString(pandaGen, expr); pandaGen.storeObjProperty(expr, cookedArrTmp, indexReg); ++elemIndex; diff --git a/ts2panda/src/index.ts b/ts2panda/src/index.ts index 92648846c011785777998c2f64069c04d057cb4e..33ee004949f78fadfb830ae14c3ed7fe2dca5763 100644 --- a/ts2panda/src/index.ts +++ b/ts2panda/src/index.ts @@ -321,7 +321,7 @@ const es2abcBase64Output = "--base64Output"; function callEs2pandaToolChain(ideInputStr: string) { let commandLine = "\"" + es2abcBinaryPath + es2abcBinaryName + "\" " + es2abcBase64Input + " \"" + ideInputStr + "\" " + es2abcDebuggerEvaluateFlag + " " + es2abcBase64Output; - var exec = require('child_process').exec; + let exec = require('child_process').exec; exec(`${commandLine}`, function(error, stdout) { if (error) { console.log("generate abc file failed, please check the input string and syntax of the expression"); diff --git a/ts2panda/src/jshelpers.d.ts b/ts2panda/src/jshelpers.d.ts index 8e45aa39952a0a41f28fb7e4f52b92c4bbe77622..b572ca026fc9b41fb08c0a8147a78e98077fccb9 100644 --- a/ts2panda/src/jshelpers.d.ts +++ b/ts2panda/src/jshelpers.d.ts @@ -24,7 +24,8 @@ export function getFlowNode(stmt: ts.Statement): ts.Node; export function bindSourceFile(sourceFile: ts.SourceFile, options: ts.CompilerOptions); export function createDiagnosticForNode(node: ts.Node, message: ts.DiagnosticMessage, ...args: (string | number | undefined)[]): ts.DiagnosticWithLocation; export function createCompilerDiagnostic(message: ts.DiagnosticMessage, ...args: (string | number | undefined)[]): ts.Diagnostic; -export function createFileDiagnostic(file: ts.SourceFile, start: number, length: number, message: ts.DiagnosticMessage, ...args: (string | number | undefined)[]): ts.DiagnosticWithLocation; +export function createFileDiagnostic(file: ts.SourceFile, start: number, length: number, message: ts.DiagnosticMessage, + ...args: (string | number | undefined)[]): ts.DiagnosticWithLocation; export function isEffectiveStrictModeSourceFile(node: ts.SourceFile, compilerOptions: ts.CompilerOptions): boolean; export function getErrorSpanForNode(sourceFile: ts.SourceFile, node: ts.Node): ts.TextSpan; export function getSpanOfTokenAtPosition(sourceFile: ts.SourceFile, pos: number): ts.TextSpan; diff --git a/ts2panda/src/modules.ts b/ts2panda/src/modules.ts index ddb83fa5f66b384e1b908eabbc7591be3c84a84d..eaa00e620e499e6a48f95ec892cac56418509bbc 100644 --- a/ts2panda/src/modules.ts +++ b/ts2panda/src/modules.ts @@ -19,7 +19,7 @@ import * as jshelpers from "./jshelpers"; import { DiagnosticCode, DiagnosticError } from "./diagnostic"; export class ModuleStmt { - private node: ts.Node + private node: ts.Node; private moduleRequest: string; private namespace: string = ""; private bingdingNameMap: Map = new Map(); diff --git a/ts2panda/src/pandagen.ts b/ts2panda/src/pandagen.ts index dd46cd8f7a4f3b3b5c72ae8854053b2c36d9a271..7db8900b50ffe2243784b61cca876b064db5c141 100644 --- a/ts2panda/src/pandagen.ts +++ b/ts2panda/src/pandagen.ts @@ -753,8 +753,8 @@ export class PandaGen { // eg. print tryLoadGlobalByName(node: ts.Node, string_id: string) { - CmdOptions.isWatchEvaluateExpressionMode() ? this.loadByNameViaDebugger(node, string_id, CacheList.True) - : this.add(node, tryLoadGlobalByName(string_id)); + CmdOptions.isWatchEvaluateExpressionMode() ? this.loadByNameViaDebugger(node, string_id, CacheList.True) : + this.add(node, tryLoadGlobalByName(string_id)); } storeByNameViaDebugger(node: ts.Node, string_id: string) { @@ -772,8 +772,8 @@ export class PandaGen { // eg. a = 1 tryStoreGlobalByName(node: ts.Node, string_id: string) { - CmdOptions.isWatchEvaluateExpressionMode() ? this.storeByNameViaDebugger(node, string_id) - : this.add(node, tryStoreGlobalByName(string_id)); + CmdOptions.isWatchEvaluateExpressionMode() ? this.storeByNameViaDebugger(node, string_id) : + this.add(node, tryStoreGlobalByName(string_id)); } // eg. var n; n; @@ -1440,7 +1440,7 @@ export class PandaGen { this.loadAccumulatorInt(node, prop); this.storeAccumulator(node, propReg); this.stSuperByValue(node, obj, propReg); - this.freeTemps(propReg) + this.freeTemps(propReg); break; default: this.stSuperByValue(node, obj, prop); diff --git a/ts2panda/src/recorder.ts b/ts2panda/src/recorder.ts index eea7f7f0fa18068c33872c643091466eadc5dc60..d3194bf3e50f2fb4df1b72f450e17ae848b277e9 100644 --- a/ts2panda/src/recorder.ts +++ b/ts2panda/src/recorder.ts @@ -132,7 +132,8 @@ export class Recorder { let isExport: boolean = false; if (hasExportKeywordModifier(childNode)) { if (!CmdOptions.isModules()) { - throw new DiagnosticError(childNode, DiagnosticCode.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none, jshelpers.getSourceFileOfNode(childNode)); + throw new DiagnosticError(childNode, DiagnosticCode.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none, + jshelpers.getSourceFileOfNode(childNode)); } this.recordEcmaExportInfo(childNode, scope); isExport = true; @@ -172,7 +173,8 @@ export class Recorder { let isExport: boolean = false; if (hasExportKeywordModifier(childNode)) { if (!CmdOptions.isModules()) { - throw new DiagnosticError(childNode, DiagnosticCode.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none, jshelpers.getSourceFileOfNode(childNode)); + throw new DiagnosticError(childNode, DiagnosticCode.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none, + jshelpers.getSourceFileOfNode(childNode)); } this.recordEcmaExportInfo(childNode, scope); isExport = true; @@ -202,7 +204,8 @@ export class Recorder { } case ts.SyntaxKind.ImportDeclaration: { if (!CmdOptions.isModules()) { - throw new DiagnosticError(childNode, DiagnosticCode.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none, jshelpers.getSourceFileOfNode(childNode)); + throw new DiagnosticError(childNode, DiagnosticCode.Cannot_use_imports_exports_or_module_augmentations_when_module_is_none, + jshelpers.getSourceFileOfNode(childNode)); } this.recordEcmaImportInfo(childNode, scope); @@ -555,7 +558,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) { if (!(scope instanceof ModuleScope)) { return; } diff --git a/ts2panda/src/regAllocator.ts b/ts2panda/src/regAllocator.ts index 790745246c363ea5f208adb7aff516a322dc875f..1620cb8577d064a2d63868471849236a3d1f2ec8 100644 --- a/ts2panda/src/regAllocator.ts +++ b/ts2panda/src/regAllocator.ts @@ -90,10 +90,10 @@ class RegAllocator { if (format[j][0] == OperandKind.SrcVReg) { head.push(new Mov(spill, vOrigin)); } else if (format[j][0] == OperandKind.DstVReg) { - tail.push(new Mov(vOrigin, spill)) + tail.push(new Mov(vOrigin, spill)); } else if (format[j][0] == OperandKind.SrcDstVReg) { head.push(new Mov(spill, vOrigin)); - tail.push(new Mov(vOrigin, spill)) + tail.push(new Mov(vOrigin, spill)); } else { // here we do nothing } diff --git a/ts2panda/src/scope.ts b/ts2panda/src/scope.ts index 616d899360330fc4ab5c764d190131241c2eb79a..390b2bf8a74620e8cbe4ea38c5a1cfd4f0b6be13 100644 --- a/ts2panda/src/scope.ts +++ b/ts2panda/src/scope.ts @@ -514,7 +514,7 @@ export class FunctionScope extends VariableScope { export class LocalScope extends Scope { constructor(parent: Scope) { super(); - this.parent = parent + this.parent = parent; } add(decl: Decl | string, declKind: VarDeclarationKind, status?: InitStatus): Variable | undefined { diff --git a/ts2panda/src/statement/classStatement.ts b/ts2panda/src/statement/classStatement.ts index e455b1a3aec5fefd714f375439a291a7115a1ca5..d7113235ab047f9118c4cfe9d962ae94bda40b12 100644 --- a/ts2panda/src/statement/classStatement.ts +++ b/ts2panda/src/statement/classStatement.ts @@ -95,7 +95,9 @@ export function compileClassDeclaration(compiler: Compiler, stmt: ts.ClassLikeDe } if (ts.isMethodDeclaration(prop.getValue())) { - let methodLiteral = new Literal(LiteralTag.METHOD, compiler.getCompilerDriver().getFuncInternalName(prop.getValue(), compiler.getRecorder())); + let methodLiteral = new Literal(LiteralTag.METHOD, + compiler.getCompilerDriver().getFuncInternalName(prop.getValue(), + compiler.getRecorder())); let affiliateLiteral = new Literal(LiteralTag.METHODAFFILIATE, getParamLengthOfFunc(prop.getValue())); classBuffer.addLiterals(methodLiteral, affiliateLiteral); } else { @@ -202,7 +204,7 @@ export function compileDefaultConstructor(compiler: Compiler, ctrNode: ts.Constr [ts.factory.createSpreadElement(ts.factory.createIdentifier("args"))]); callNode = jshelpers.setParent(callNode, ctrNode)!; - callNode = ts.setTextRange(callNode, ctrNode)! + callNode = ts.setTextRange(callNode, ctrNode)!; compileSuperCall(compiler, callNode, [], true); compileConstructor(compiler, ctrNode, false); @@ -310,7 +312,7 @@ export function compileDefaultInitClassMembers(compiler: Compiler, node: ts.Cons break; } default: - throw new Error("Private Identifier has not been supported") + throw new Error("Private Identifier has not been supported"); } @@ -614,7 +616,7 @@ function generatePropertyFromExpr(node: ts.ClassLikeDeclaration, classFields: Ar * Need to reverse the order of non-static members */ - let staticItems = properties.slice(properties.length - staticNum) + let staticItems = properties.slice(properties.length - staticNum); properties = properties.slice(0, properties.length - staticNum); properties = properties.reverse(); properties.push(...staticItems); @@ -650,7 +652,8 @@ function compileComputedProperty(compiler: Compiler, prop: Property, classReg: V let getProtoReg = pandaGen.getTemp(); let getter = prop.getValue(); let getFlag = createClassMethodOrAccessor(compiler, classReg, getProtoReg, accessorReg, getter); - pandaGen.defineGetterSetterByValue(getter, getFlag ? getProtoReg : classReg, keyReg, accessorReg, getVregisterCache(pandaGen, CacheList.undefined), true); + pandaGen.defineGetterSetterByValue(getter, getFlag ? getProtoReg : classReg, keyReg, accessorReg, + getVregisterCache(pandaGen, CacheList.undefined), true); pandaGen.freeTemps(accessorReg, getProtoReg); break; } @@ -659,7 +662,8 @@ function compileComputedProperty(compiler: Compiler, prop: Property, classReg: V let setter = prop.getValue(); let setProtoReg = pandaGen.getTemp(); let setFlag = createClassMethodOrAccessor(compiler, classReg, setProtoReg, accesReg, setter); - pandaGen.defineGetterSetterByValue(setter, setFlag ? setProtoReg : classReg, keyReg, getVregisterCache(pandaGen, CacheList.undefined), accesReg, true); + pandaGen.defineGetterSetterByValue(setter, setFlag ? setProtoReg : classReg, keyReg, + getVregisterCache(pandaGen, CacheList.undefined), accesReg, true); pandaGen.freeTemps(accesReg, setProtoReg); break; } @@ -726,7 +730,7 @@ function scalarArrayEquals(node1: ts.Node | undefined, node2: ts.Node | undefine let val1Modifs = node1.modifiers; let val2Modifs = node2.modifiers; if (val1Modifs && val2Modifs) { - return val1Modifs.length == val2Modifs.length && val1Modifs.every(function (v, i) { return v === val2Modifs![i] });; + return val1Modifs.length == val2Modifs.length && val1Modifs.every(function (v, i) { return v === val2Modifs![i] }); } if (!val1Modifs && !val2Modifs) { diff --git a/ts2panda/src/statement/loopStatement.ts b/ts2panda/src/statement/loopStatement.ts index e1c02b44e8854479632dea16ade67113b185e87f..ccd301af5c7c7732ef7603e07aaf7d82efd83095 100644 --- a/ts2panda/src/statement/loopStatement.ts +++ b/ts2panda/src/statement/loopStatement.ts @@ -102,7 +102,7 @@ export function compileWhileStatement(stmt: ts.WhileStatement, compiler: Compile if (needCreateLoopEnv) { pandaGen.popLexicalEnv(stmt); - compiler.popEnv() + compiler.popEnv(); } LabelTarget.popLabelTarget(); diff --git a/ts2panda/src/statement/switchStatement.ts b/ts2panda/src/statement/switchStatement.ts index 180587a66bded2228c2a8d47aec5bccab386a50f..06768676fa165304c3729901c468ed32c4748829 100644 --- a/ts2panda/src/statement/switchStatement.ts +++ b/ts2panda/src/statement/switchStatement.ts @@ -23,7 +23,7 @@ import { Compiler } from "../compiler"; import { DiagnosticCode, DiagnosticError -} from "../diagnostic" +} from "../diagnostic"; import { LabelTarget } from "./labelTarget"; export class SwitchBase { private stmt: ts.SwitchStatement; diff --git a/ts2panda/src/statement/tryStatement.ts b/ts2panda/src/statement/tryStatement.ts index f20de8ef20cc03a08432970f331e0edd12647949..d0284b41b22345f81d97fef4c039a52482b50e5a 100644 --- a/ts2panda/src/statement/tryStatement.ts +++ b/ts2panda/src/statement/tryStatement.ts @@ -204,7 +204,7 @@ export abstract class TryBuilderBase { export class TryBuilder extends TryBuilderBase { constructor(compiler: Compiler, pandaGen: PandaGen, tryStmt: ts.TryStatement) { - super(compiler, pandaGen, tryStmt) + super(compiler, pandaGen, tryStmt); } compileTryBlock(catchTable: CatchTable) { @@ -260,7 +260,8 @@ export class TryBuilderWithForOf extends TryBuilderBase { private hasLoopEnv: boolean; private loopEnv: VReg | undefined; - constructor(compiler: Compiler, pandaGen: PandaGen, forOfStmt: ts.ForOfStatement, doneReg: VReg, iterator: IteratorRecord, labelTarget: LabelTarget, hasLoopEnv: boolean, loopEnv?: VReg) { + constructor(compiler: Compiler, pandaGen: PandaGen, forOfStmt: ts.ForOfStatement, doneReg: VReg, iterator: IteratorRecord, + labelTarget: LabelTarget, hasLoopEnv: boolean, loopEnv?: VReg) { super(compiler, pandaGen, forOfStmt); this.labelTarget = labelTarget; @@ -382,7 +383,7 @@ export function updateCatchTables(inlinedTry: TryStatement | undefined, targetTr export function generateCatchTables(catchMap: Map): CatchTable[] { let catchTableList: CatchTable[] = []; catchMap.forEach((catchTable) => { - catchTableList.push(catchTable) + catchTableList.push(catchTable); }); catchTableList.sort((a, b) => (b.getDepth() - a.getDepth())); return catchTableList; diff --git a/ts2panda/src/syntaxChecker.ts b/ts2panda/src/syntaxChecker.ts index 69750aa96d705382192db70eb4b59774d1edd5f5..fce6e1c518d4d213f17a660c048c13a194f0cd4f 100644 --- a/ts2panda/src/syntaxChecker.ts +++ b/ts2panda/src/syntaxChecker.ts @@ -256,7 +256,7 @@ function checkDeclareGlobalId(decl: Decl, scope: Scope) { if (isGlobalIdentifier(decl.name) && isDeclInGlobal(decl.node)) { let sourceNode = jshelpers.getSourceFileOfNode(decl.node); - throw new DiagnosticError(decl.node, DiagnosticCode.Declaration_name_conflicts_with_built_in_global_identifier_0, sourceNode, [decl.name]) + throw new DiagnosticError(decl.node, DiagnosticCode.Declaration_name_conflicts_with_built_in_global_identifier_0, sourceNode, [decl.name]); } } @@ -296,13 +296,14 @@ function checkBreakOrContinueStatement(node: ts.BreakOrContinueStatement) { // found matching label - verify that label usage is correct // continue can only target labels that are on iteration statements let isMisplacedContinueLabel = false; - if (node.kind === ts.SyntaxKind.ContinueStatement - && !jshelpers.isIterationStatement((curNode).statement, /*lookInLabeledStatement*/ true)) { + if (node.kind === ts.SyntaxKind.ContinueStatement && + !jshelpers.isIterationStatement((curNode).statement, /*lookInLabeledStatement*/ true)) { isMisplacedContinueLabel = true; } if (isMisplacedContinueLabel) { - throw new DiagnosticError(node, DiagnosticCode.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement, jshelpers.getSourceFileOfNode(curNode)); + throw new DiagnosticError(node, DiagnosticCode.A_continue_statement_can_only_jump_to_a_label_of_an_enclosing_iteration_statement, + jshelpers.getSourceFileOfNode(curNode)); } return; @@ -360,13 +361,16 @@ function checkMetaProperty(node: ts.MetaProperty) { let func = getContainingFunctionDeclaration(node); if (!func) { - throw new DiagnosticError(node, DiagnosticCode.Meta_property_0_is_only_allowed_in_the_body_of_a_function_declaration_function_expression_or_constructor, file, args); + throw new DiagnosticError(node, + DiagnosticCode.Meta_property_0_is_only_allowed_in_the_body_of_a_function_declaration_function_expression_or_constructor, file, args); } else { if (ts.isMethodDeclaration(func)) { - throw new DiagnosticError(node, DiagnosticCode.Meta_property_0_is_only_allowed_in_the_body_of_a_function_declaration_function_expression_or_constructor, file, args); + throw new DiagnosticError(node, + DiagnosticCode.Meta_property_0_is_only_allowed_in_the_body_of_a_function_declaration_function_expression_or_constructor, file, args); } if (ts.isArrowFunction(func) && !jshelpers.getNewTargetContainer(node)) { - throw new DiagnosticError(node, DiagnosticCode.Meta_property_0_is_only_allowed_in_the_body_of_a_function_declaration_function_expression_or_constructor, file, args); + throw new DiagnosticError(node, + DiagnosticCode.Meta_property_0_is_only_allowed_in_the_body_of_a_function_declaration_function_expression_or_constructor, file, args); } } break; @@ -429,18 +433,20 @@ function checkVariableDeclaration(node: ts.VariableDeclaration) { if (node.exclamationToken && (node.parent.parent.kind !== ts.SyntaxKind.VariableStatement || !node.type || node.initializer)) { if (node.initializer) { - throw new DiagnosticError(node.exclamationToken, DiagnosticCode.Declarations_with_initializers_cannot_also_have_definite_assignment_assertions, file); + throw new DiagnosticError(node.exclamationToken, + DiagnosticCode.Declarations_with_initializers_cannot_also_have_definite_assignment_assertions, file); } else { - throw new DiagnosticError(node.exclamationToken, DiagnosticCode.Declarations_with_definite_assignment_assertions_must_also_have_type_annotations, file); + throw new DiagnosticError(node.exclamationToken, + DiagnosticCode.Declarations_with_definite_assignment_assertions_must_also_have_type_annotations, file); } } if (jshelpers.isLet(node) || jshelpers.isVarConst(node)) { checkNameInLetOrConstDeclarations(node.name); - if (!isInBlockScope(node.parent.parent.parent) - && !ts.isForInStatement(node.parent.parent) - && !ts.isForOfStatement(node.parent.parent) - && !ts.isForStatement(node.parent.parent)) { + if (!isInBlockScope(node.parent.parent.parent) && + !ts.isForInStatement(node.parent.parent) && + !ts.isForOfStatement(node.parent.parent) && + !ts.isForStatement(node.parent.parent)) { throw new DiagnosticError(node, DiagnosticCode.const_and_let_declarations_not_allowed_in_statement_positions, file); } } @@ -477,7 +483,7 @@ function checkAsyncModifier(node: ts.Node, asyncModifier: ts.Node) { break; } let file = jshelpers.getSourceFileOfNode(node); - throw new DiagnosticError(asyncModifier, DiagnosticCode._0_modifier_cannot_be_used_here, file, ["async"]) + throw new DiagnosticError(asyncModifier, DiagnosticCode._0_modifier_cannot_be_used_here, file, ["async"]); } function checkModifiers(node: ts.Node) { @@ -495,16 +501,19 @@ function checkModifiers(node: ts.Node) { for (let modifier of node.modifiers!) { if (modifier.kind !== ts.SyntaxKind.ReadonlyKeyword) { if (ts.isPropertySignature(node) || ts.isMethodSignature(node)) { - throw new DiagnosticError(modifier, DiagnosticCode._0_modifier_cannot_appear_on_a_type_member, file, [jshelpers.tokenToString(modifier.kind)]); + throw new DiagnosticError(modifier, DiagnosticCode._0_modifier_cannot_appear_on_a_type_member, + file, [jshelpers.tokenToString(modifier.kind)]); } if (ts.isIndexSignatureDeclaration(node)) { - throw new DiagnosticError(modifier, DiagnosticCode._0_modifier_cannot_appear_on_an_index_signature, file, [jshelpers.tokenToString(modifier.kind)]); + throw new DiagnosticError(modifier, DiagnosticCode._0_modifier_cannot_appear_on_an_index_signature, + file, [jshelpers.tokenToString(modifier.kind)]); } } switch (modifier.kind) { case ts.SyntaxKind.ConstKeyword: { if (ts.isEnumDeclaration(node)) { - throw new DiagnosticError(node, DiagnosticCode.A_class_member_cannot_have_the_0_keyword, file, [jshelpers.tokenToString(ts.SyntaxKind.ConstKeyword)]); + throw new DiagnosticError(node, DiagnosticCode.A_class_member_cannot_have_the_0_keyword, + file, [jshelpers.tokenToString(ts.SyntaxKind.ConstKeyword)]); } break; } @@ -558,9 +567,11 @@ function checkModifiers(node: ts.Node) { case ts.SyntaxKind.ReadonlyKeyword: { if (flags & ts.ModifierFlags.Readonly) { throw new DiagnosticError(modifier, DiagnosticCode._0_modifier_already_seen, file, ["readonly"]); - } else if (!ts.isPropertyDeclaration(node) && !ts.isPropertySignature(node) && !ts.isIndexSignatureDeclaration(node) && !ts.isParameter(node)) { + } else if (!ts.isPropertyDeclaration(node) && !ts.isPropertySignature(node) && + !ts.isIndexSignatureDeclaration(node) && !ts.isParameter(node)) { // If node.kind === SyntaxKind.Parameter, checkParameter report an error if it's not a parameter property. - throw new DiagnosticError(modifier, DiagnosticCode.The_readonly_modifier_can_only_appear_on_a_property_declaration_or_index_signature, file); + throw new DiagnosticError(modifier, + DiagnosticCode.The_readonly_modifier_can_only_appear_on_a_property_declaration_or_index_signature, file); } flags |= ts.ModifierFlags.Readonly; lastReadonly = modifier; @@ -613,8 +624,10 @@ function checkModifiers(node: ts.Node) { throw new DiagnosticError(modifier, DiagnosticCode._0_modifier_already_seen, file, ["abstract"]); } if (ts.isClassDeclaration(node) && ts.isConstructorTypeNode(node)) { - if (!ts.isMethodDeclaration(node) && !ts.isPropertyDeclaration(node) && !ts.isGetAccessorDeclaration(node) && !ts.isSetAccessorDeclaration(node)) { - throw new DiagnosticError(modifier, DiagnosticCode.The_abstract_modifier_can_only_appear_on_a_class_method_or_property_declaration, file); + if (!ts.isMethodDeclaration(node) && !ts.isPropertyDeclaration(node) && + !ts.isGetAccessorDeclaration(node) && !ts.isSetAccessorDeclaration(node)) { + throw new DiagnosticError(modifier, + DiagnosticCode.The_abstract_modifier_can_only_appear_on_a_class_method_or_property_declaration, file); } if (flags & ts.ModifierFlags.Static) { throw new DiagnosticError(modifier, DiagnosticCode._0_modifier_cannot_be_used_with_1_modifier, file, ["static", "abstract"]); @@ -710,25 +723,31 @@ function checkForInOrForOfStatement(stmt: ts.ForInOrOfStatement) { if (declarations.length > 1) { if (ts.isForInStatement(stmt)) { - throw new DiagnosticError(variableList.declarations[1], DiagnosticCode.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement, file); + throw new DiagnosticError(variableList.declarations[1], + DiagnosticCode.Only_a_single_variable_declaration_is_allowed_in_a_for_in_statement, file); } else { - throw new DiagnosticError(variableList.declarations[1], DiagnosticCode.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement, file); + throw new DiagnosticError(variableList.declarations[1], + DiagnosticCode.Only_a_single_variable_declaration_is_allowed_in_a_for_of_statement, file); } } if (declarations[0].initializer) { if (ts.isForInStatement(stmt)) { - throw new DiagnosticError(declarations[0].name, DiagnosticCode.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer, file); + throw new DiagnosticError(declarations[0].name, + DiagnosticCode.The_variable_declaration_of_a_for_in_statement_cannot_have_an_initializer, file); } else { - throw new DiagnosticError(declarations[0].name, DiagnosticCode.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer, file); + throw new DiagnosticError(declarations[0].name, + DiagnosticCode.The_variable_declaration_of_a_for_of_statement_cannot_have_an_initializer, file); } } if (declarations[0].type) { if (ts.isForInStatement(stmt)) { - throw new DiagnosticError(declarations[0], DiagnosticCode.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation, file); + throw new DiagnosticError(declarations[0], + DiagnosticCode.The_left_hand_side_of_a_for_in_statement_cannot_use_a_type_annotation, file); } else { - throw new DiagnosticError(declarations[0], DiagnosticCode.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation, file); + throw new DiagnosticError(declarations[0], + DiagnosticCode.The_left_hand_side_of_a_for_of_statement_cannot_use_a_type_annotation, file); } } } else { @@ -774,7 +793,8 @@ const enum OuterExpressionKinds { function checkReferenceExpression(expr: ts.Expression, invalidReferenceCode: DiagnosticCode, invalidOptionalChainCode: DiagnosticCode) { 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) { + if (node.kind !== ts.SyntaxKind.Identifier && node.kind !== ts.SyntaxKind.PropertyAccessExpression && + node.kind !== ts.SyntaxKind.ElementAccessExpression) { throw new DiagnosticError(expr, invalidReferenceCode); } @@ -914,9 +934,9 @@ function checkBinaryExpression(node: ts.BinaryExpression) { } function isInVaildAssignmentLeftSide(leftExpr: ts.Expression) { - if (jshelpers.isKeyword(leftExpr.kind) - || leftExpr.kind == ts.SyntaxKind.NumericLiteral - || leftExpr.kind == ts.SyntaxKind.StringLiteral) { + if (jshelpers.isKeyword(leftExpr.kind) || + leftExpr.kind == ts.SyntaxKind.NumericLiteral || + leftExpr.kind == ts.SyntaxKind.StringLiteral) { throw new DiagnosticError(leftExpr, DiagnosticCode.The_left_hand_side_of_an_assignment_expression_must_be_a_variable_or_a_property_access); } } @@ -930,12 +950,15 @@ function checkContextualIdentifier(node: ts.Identifier) { let file = jshelpers.getSourceFileOfNode(node); if (node.originalKeywordKind === ts.SyntaxKind.AwaitKeyword) { if (jshelpers.isExternalOrCommonJsModule(file) && jshelpers.isInTopLevelContext(node)) { - throw new DiagnosticError(node, DiagnosticCode.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module, file, jshelpers.declarationNameToString(node)); + throw new DiagnosticError(node, DiagnosticCode.Identifier_expected_0_is_a_reserved_word_at_the_top_level_of_a_module, + file, jshelpers.declarationNameToString(node)); } else if (node.flags & ts.NodeFlags.AwaitContext) { - throw new DiagnosticError(node, DiagnosticCode.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, file, jshelpers.declarationNameToString(node)); + throw new DiagnosticError(node, DiagnosticCode.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, + file, jshelpers.declarationNameToString(node)); } } else if (node.originalKeywordKind === ts.SyntaxKind.YieldKeyword && node.flags & ts.NodeFlags.YieldContext) { - throw new DiagnosticError(node, DiagnosticCode.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, file, jshelpers.declarationNameToString(node)); + throw new DiagnosticError(node, DiagnosticCode.Identifier_expected_0_is_a_reserved_word_that_cannot_be_used_here, + file, jshelpers.declarationNameToString(node)); } } @@ -981,7 +1004,9 @@ function checkObjectLiteralExpression(node: ts.ObjectLiteralExpression) { } if (ts.isShorthandPropertyAssignment(prop) && !inDestructuring && prop.objectAssignmentInitializer) { - throw new DiagnosticError(prop.equalsToken!, DiagnosticCode.Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern, file); + throw new DiagnosticError(prop.equalsToken!, + DiagnosticCode.Did_you_mean_to_use_a_Colon_An_can_only_follow_a_property_name_when_the_containing_object_literal_is_part_of_a_destructuring_pattern, + file); } if (ts.isPrivateIdentifier(name)) { @@ -1002,10 +1027,14 @@ function checkObjectLiteralExpression(node: ts.ObjectLiteralExpression) { * PropertyDefinition : PropertyName : AssignmentExpression . */ let curKind = getPropertieDeclaration(prop, name); - if (!curKind) continue; + if (!curKind) { + continue; + } if (!inDestructuring) { let effectName = jshelpers.getPropertyNameForPropertyNameNode(name); - if (!effectName || ts.isComputedPropertyName(name)) continue; + if (!effectName || ts.isComputedPropertyName(name)) { + continue; + } let existKind = seen.get(effectName); if (!existKind) { seen.set(effectName, curKind); @@ -1194,14 +1223,17 @@ function checkSuperExpression(node: ts.SuperExpression) { return; } if (isCallExpression) { - throw new DiagnosticError(node, DiagnosticCode.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors, file); + throw new DiagnosticError(node, + DiagnosticCode.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors, file); } if (!container || !container.parent || !ts.isClassLike(container.parent) || ts.isObjectLiteralExpression(container.parent)) { - throw new DiagnosticError(node, DiagnosticCode.The_super_can_only_be_referenced_in_members_of_derived_classes_or_object_literal_expressions, file); + throw new DiagnosticError(node, + DiagnosticCode.The_super_can_only_be_referenced_in_members_of_derived_classes_or_object_literal_expressions, file); } - throw new DiagnosticError(node, DiagnosticCode.The_super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class, file); + throw new DiagnosticError(node, + DiagnosticCode.The_super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class, file); } } diff --git a/ts2panda/src/syntaxCheckerForStrcitMode.ts b/ts2panda/src/syntaxCheckerForStrcitMode.ts index 5747aadad83abe31dff2bc620c5ba9675742ca25..a538830ac44fded7741ce2341898fb3a1b735e31 100644 --- a/ts2panda/src/syntaxCheckerForStrcitMode.ts +++ b/ts2panda/src/syntaxCheckerForStrcitMode.ts @@ -201,8 +201,8 @@ function checkImportDeclaration(node: ts.ImportDeclaration, scope: Scope) { let namedBindings = node.importClause.namedBindings; if (ts.isNamedImports(namedBindings)) { namedBindings.elements.forEach((element: any) => { - if (jshelpers.getTextOfIdentifierOrLiteral(element.name) == 'arguments' - || jshelpers.getTextOfIdentifierOrLiteral(element.name) == 'eval') { + if (jshelpers.getTextOfIdentifierOrLiteral(element.name) == 'arguments' || + jshelpers.getTextOfIdentifierOrLiteral(element.name) == 'eval') { throw new DiagnosticError(node, DiagnosticCode.Unexpected_eval_or_arguments_in_strict_mode); } }); diff --git a/ts2panda/src/ts2panda.ts b/ts2panda/src/ts2panda.ts index f6d17a09f2e198a277d59755a337f5bf718caf38..5599d8be7071e334cf8e63eaa7e58e1f3056a23d 100644 --- a/ts2panda/src/ts2panda.ts +++ b/ts2panda/src/ts2panda.ts @@ -182,7 +182,7 @@ export class Ts2Panda { static dumpTypeLiteralArrayBuffer() { let literalArrays = PandaGen.getLiteralArrayBuffer(); let countType: LiteralBuffer = literalArrays[0]; - let jsonTypeString: string = "" + let jsonTypeString: string = ""; let typeCount = countType.getLiteral(0)?.getValue(); if (typeCount) { for (let i = 0; i < typeCount; i++) { @@ -393,7 +393,8 @@ export class Ts2Panda { ); } - let variables = undefined, sourceCode = undefined; + let variables = undefined; + let sourceCode = undefined; if (CmdOptions.needRecordSourceCode() || CmdOptions.isDebugMode()) { // function's sourceCode will be undefined in debugMode // if we don't need to record function-sourceCode diff --git a/ts2panda/src/typeChecker.ts b/ts2panda/src/typeChecker.ts index 85764ad230978c4d07f81b6e5dc1a15d5c549cb1..45b9521117afc8dac37f48ddee4418407dfc47fe 100644 --- a/ts2panda/src/typeChecker.ts +++ b/ts2panda/src/typeChecker.ts @@ -240,7 +240,7 @@ export class TypeChecker { let arrayType = new ArrayType(typeNode); return arrayType.shiftedTypeIndex; case ts.SyntaxKind.ParenthesizedType: - let subType = (typeNode).type + let subType = (typeNode).type; if (subType.kind == ts.SyntaxKind.UnionType) { let unionType = new UnionType(subType); return unionType.shiftedTypeIndex; diff --git a/ts2panda/src/typeRecorder.ts b/ts2panda/src/typeRecorder.ts index a760ffc08c2b5bb409c42a1a88ee9cc4a14c70d5..ce9eceb0a1e5a9799ea3daa8afbf2aa58f5e4c1c 100644 --- a/ts2panda/src/typeRecorder.ts +++ b/ts2panda/src/typeRecorder.ts @@ -99,7 +99,7 @@ export class TypeRecorder { } public setArrayTypeMap(contentTypeIndex: number, arrayTypeIndex: number) { - this.arrayTypeMap.set(contentTypeIndex, arrayTypeIndex) + this.arrayTypeMap.set(contentTypeIndex, arrayTypeIndex); } public hasArrayTypeMapping(contentTypeIndex: number) { @@ -123,7 +123,7 @@ export class TypeRecorder { } public setClass2InstanceMap(classIndex: number, instanceIndex: number) { - this.class2InstanceMap.set(classIndex, instanceIndex) + this.class2InstanceMap.set(classIndex, instanceIndex); } public hasClass2InstanceMap(classIndex: number) { @@ -135,7 +135,7 @@ export class TypeRecorder { } public setBuiltinContainer2InstanceMap(builtinContainer: object, instanceIndex: number) { - this.builtinContainer2InstanceMap.set(builtinContainer, instanceIndex) + this.builtinContainer2InstanceMap.set(builtinContainer, instanceIndex); } public hasBuiltinContainer2InstanceMap(builtinContainer: object) { diff --git a/ts2panda/src/variable.ts b/ts2panda/src/variable.ts index 4f51d0af8b5bbfbc4567256641ebfd995f7f6f11..764becfceccfdd7a850383eb841b69d3acbc280c 100644 --- a/ts2panda/src/variable.ts +++ b/ts2panda/src/variable.ts @@ -56,7 +56,7 @@ export abstract class Variable { getVreg(): VReg { if (!this.vreg) { - throw new Error("variable has not been binded") + throw new Error("variable has not been binded"); } return this.vreg; } @@ -77,7 +77,7 @@ export abstract class Variable { if (this.lexical()) { return; } - this.idxLex = scope.getLexVarIdx() + this.idxLex = scope.getLexVarIdx(); scope.pendingCreateEnv(); this.isLexVar = true; scope.addLexVarInfo(this.name, this.idxLex); diff --git a/ts2panda/tests/expression/binary.test.ts b/ts2panda/tests/expression/binary.test.ts index 7d36fa97a1bb8bfa7f78cfe5971353ec171505cf..c70dcf70452df102c89e4ae0c4c4272db89471cf 100644 --- a/ts2panda/tests/expression/binary.test.ts +++ b/ts2panda/tests/expression/binary.test.ts @@ -107,7 +107,7 @@ describe("BinaryOperationsTest", function () { expect(checkInstructions(insns, expected)).to.be.true; - let jumps = insns.filter(item => item instanceof Jeqz || item instanceof Jmp) + let jumps = insns.filter(item => item instanceof Jeqz || item instanceof Jmp); expect(jumps.length).to.equal(3); }); diff --git a/ts2panda/tests/expression/conditions.test.ts b/ts2panda/tests/expression/conditions.test.ts index 5d903f230eb7abb558f3d56a95c7c66766496d24..730b8d9535cecb1f3d50cbdb72921f5ad94ec159 100644 --- a/ts2panda/tests/expression/conditions.test.ts +++ b/ts2panda/tests/expression/conditions.test.ts @@ -115,7 +115,7 @@ describe("IfConditionTest", function () { endIfLabel, ]; insns = insns.slice(4, insns.length - 1); // skip let a = 1; let b = 2; and return. - expect(checkInstructions(insns, expected)).to.be.true + expect(checkInstructions(insns, expected)).to.be.true; }); it("if (a == b)", function () { diff --git a/ts2panda/tests/expression/templateExpression.test.ts b/ts2panda/tests/expression/templateExpression.test.ts index 5752c6c3df11720dc6f68b9b6540dffb5417359d..b07d77d12b42fe5bc84d9b1b142fac0e371909c5 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) { 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) { 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) { let insns = []; let objReg = new VReg(); let indexReg = new VReg(); diff --git a/ts2panda/tests/regAllocator.test.ts b/ts2panda/tests/regAllocator.test.ts index 185ebd3594afc137b880494157d04220fd31deed..42220bbfbb0cbe708b5a5a7c5184be215f001aae 100644 --- a/ts2panda/tests/regAllocator.test.ts +++ b/ts2panda/tests/regAllocator.test.ts @@ -253,7 +253,7 @@ describe("RegAllocator", function () { let para2 = pandaGen.getTemp(); let para3 = pandaGen.getTemp(); - pandaGen.getInsns().push(new Callrange(new Imm(0), new Imm(3), [para1, para2, para3])) + pandaGen.getInsns().push(new Callrange(new Imm(0), new Imm(3), [para1, para2, para3])); pandaGen.freeTemps(para1, para3, para2); diff --git a/ts2panda/tests/strictmode/function.js b/ts2panda/tests/strictmode/function.js index bde7776c4cf398c0e55079277c5b0f6c12d16c38..465bc4424c16c4e05b86c3e8c9550a8638943418 100644 --- a/ts2panda/tests/strictmode/function.js +++ b/ts2panda/tests/strictmode/function.js @@ -15,13 +15,13 @@ function add(a,b) { "use strict"; - var x = 12; + let x = 12; return a + b + x; } function sub(a,b) { - var y = 12; + let y = 12; return a + b - y; } -var z = 13; \ No newline at end of file +let z = 13; \ No newline at end of file diff --git a/ts2panda/tests/strictmode/function_nest1.js b/ts2panda/tests/strictmode/function_nest1.js index 3bdaaf42301b3ecd52526a8c16ed656c2e49dadd..223b5babb4897d189f2b361c1e689b5b7485b01d 100755 --- a/ts2panda/tests/strictmode/function_nest1.js +++ b/ts2panda/tests/strictmode/function_nest1.js @@ -15,9 +15,9 @@ function func(){ "use strict"; - var x = 10; + let x = 10; function add(a,b) { - var y = 12; + let y = 12; return a + b + y; } } diff --git a/ts2panda/tests/strictmode/function_nest2.js b/ts2panda/tests/strictmode/function_nest2.js index 59ae2a911d27a5ef2d24f4022c04c17cec3f9ce6..e76de3abef2a1308811455103e0a5c48bfa370ea 100755 --- a/ts2panda/tests/strictmode/function_nest2.js +++ b/ts2panda/tests/strictmode/function_nest2.js @@ -14,11 +14,11 @@ */ function func(){ - var x = 10; + let x = 10; function add(a,b) { "use strict"; - var y = 12; + let y = 12; return a+b+y; } - var z = 14; + let z = 14; } \ No newline at end of file diff --git a/ts2panda/tests/types/class.test.ts b/ts2panda/tests/types/class.test.ts index 0ee5e903a62d82f7313f36bcfc777ba15c8e72b6..4097b5c88f9d272c84e2ba3c75a19753242c27de 100644 --- a/ts2panda/tests/types/class.test.ts +++ b/ts2panda/tests/types/class.test.ts @@ -262,8 +262,8 @@ describe("class tests in class.test.ts", function () { let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ - ["#3#animal", shift + 1], - ["#4#dog", shift + 3], + ["#3#Animal", shift + 1], + ["#4#Dog", shift + 3], ["#5#d", shift + 5], ] let vreg2TypeMap = createVRegTypePair(extectedVRegTypePair); @@ -307,8 +307,8 @@ describe("class tests in class.test.ts", function () { let locals = functionPg!.getLocals(); // check vreg let extectedVRegTypePair = [ - ["#3#base1", shift + 1], - ["#4#base2", shift + 2], + ["#3#Base1", shift + 1], + ["#4#Base2", shift + 2], ["#5#A", shift + 3], ["#6#a", shift + 4], ] diff --git a/ts2panda/tests/types/class/class_abstract.ts b/ts2panda/tests/types/class/class_abstract.ts index a796345b6414954c3c2227500067f456670af37a..7d39bba77bbe5f7bf2b83945d79ba4bb2d04a93e 100644 --- a/ts2panda/tests/types/class/class_abstract.ts +++ b/ts2panda/tests/types/class/class_abstract.ts @@ -14,15 +14,15 @@ */ { - abstract class animal { + abstract class Animal { eat() { }; } - class dog extends animal { + class Dog extends Animal { constructor() { super(); } } - let d = new dog(); + let d = new Dog(); } \ No newline at end of file diff --git a/ts2panda/tests/types/class/class_implements.ts b/ts2panda/tests/types/class/class_implements.ts index 76f79672c91f810640f399f72930c79a5b5dc4c3..5dfcb1b9bd07523571b775a9d3ebc1bb1fc338da 100644 --- a/ts2panda/tests/types/class/class_implements.ts +++ b/ts2panda/tests/types/class/class_implements.ts @@ -14,8 +14,8 @@ */ { - class base1 { } - class base2 { } - class A implements base1, base2 { } + class Base1 { } + class Base2 { } + class A implements Base1, Base2 { } let a = new A(); } \ No newline at end of file diff --git a/ts2panda/tests/types/function.test.ts b/ts2panda/tests/types/function.test.ts index b6b640efcd0c629c8600323c6d8ab52a2a3a392c..b037a4e98479d52ad3b90d0a4ed2ff20b161cdba 100644 --- a/ts2panda/tests/types/function.test.ts +++ b/ts2panda/tests/types/function.test.ts @@ -77,7 +77,7 @@ describe("function tests in function.test.ts", function () { [2, 2], [24, "snippet_1"], [24, "snippet_2"], [2, 0] ], [ - [2, 3], [2, 0], [5, "multi_local"], + [2, 3], [2, 0], [5, "multiLocal"], [2, 0], [2, 0], [25, 0] ], [ diff --git a/ts2panda/tests/types/function/function_multi_para.ts b/ts2panda/tests/types/function/function_multi_para.ts index ef95661ff1986d8470fa5359c645c9f9c187ea00..9dc3362de27fc01a0ee618d98d664004c5324e52 100644 --- a/ts2panda/tests/types/function/function_multi_para.ts +++ b/ts2panda/tests/types/function/function_multi_para.ts @@ -13,7 +13,7 @@ * limitations under the License. */ -function multi_local() { +function multiLocal() { function emptyFunc(num: number, str:string): string { return str; } diff --git a/ts2panda/tests/types/typeUtils.ts b/ts2panda/tests/types/typeUtils.ts index 88fafdb37693297badcb3b48c4f7a32ca66ee3fb..c8944c97ec2ff2e275ac841a79142895242ed500 100644 --- a/ts2panda/tests/types/typeUtils.ts +++ b/ts2panda/tests/types/typeUtils.ts @@ -76,9 +76,9 @@ export function compareVReg2Type(expectedMap: Map, generated: VR if (name == "4funcObj" || name == "4newTarget" || name == "this") { continue; } - let vregMarker = "#" + vreg.num + "#" + vreg.getVariableName() + let vregMarker = "#" + vreg.num + "#" + vreg.getVariableName(); if (!expectedMap.has(vregMarker)) { - console.log("verg not found: ", vregMarker) + console.log("verg not found: ", vregMarker); return false; } if (expectedMap.get(vregMarker) != vreg.getTypeIndex()) { diff --git a/ts2panda/tests/utils/base.ts b/ts2panda/tests/utils/base.ts index 82def1690766050c31dc3763de237c9cea7c9653..91abbcbf2af1f71e62f10f63082fdad9c5e744ba 100644 --- a/ts2panda/tests/utils/base.ts +++ b/ts2panda/tests/utils/base.ts @@ -132,7 +132,7 @@ export function checkInstructions(actual: IRNode[], expected: IRNode[], checkFn? } if (actual.length !== expected.length) { - console.log("actual.length:" + actual.length + " expected.length:" + expected.length) + console.log("actual.length:" + actual.length + " expected.length:" + expected.length); return false; } @@ -154,8 +154,8 @@ export function compileAllSnippet(snippet: string, passes?: Pass[], literalBuffe CmdOptions.setWatchEvaluateExpressionArgs(['','']); } CmdOptions.setMergeAbc(true); - CmdOptions.isWatchEvaluateExpressionMode() ? setGlobalStrict(true) - : setGlobalStrict(jshelpers.isEffectiveStrictModeSourceFile(sourceFile, compileOptions)); + CmdOptions.isWatchEvaluateExpressionMode() ? setGlobalStrict(true) : + setGlobalStrict(jshelpers.isEffectiveStrictModeSourceFile(sourceFile, compileOptions)); let compilerDriver = new CompilerDriver('UnitTest', 'UnitTest'); CompilerDriver.srcNode = sourceFile; diff --git a/ts2panda/tests/utils/example_asthelper.ts b/ts2panda/tests/utils/example_asthelper.ts index 3daf8024213a0b924f694c6df376305b083f0b9d..5bed970a97d7929e1ec4221c7f9ac0b7e7ffd56b 100644 --- a/ts2panda/tests/utils/example_asthelper.ts +++ b/ts2panda/tests/utils/example_asthelper.ts @@ -20,7 +20,7 @@ function testCreateAstFromSnippet() { console.log(ast.getText()); } function testCreateAstFromFile() { - const absolutePath = __dirname + "/example_asthelper.js" + const absolutePath = __dirname + "/example_asthelper.js"; let ast = asthelper.creatAstFromFile(absolutePath); console.log(ast.getText()); } diff --git a/ts2panda/tools/astPrinter.ts b/ts2panda/tools/astPrinter.ts index 4a1a16be72af87731d7db1853684a7f46a643b2a..b8436134bfa0c6a507159048df122e967fe45142 100644 --- a/ts2panda/tools/astPrinter.ts +++ b/ts2panda/tools/astPrinter.ts @@ -80,7 +80,7 @@ export namespace AST { return ((typeof (node) === "object") && ("kind" in node) && (node.kind == ts.SyntaxKind.SourceFile)); } - function Array2String(name: (undefined | string), array: ts.Node[], tab: number): string { + function array2String(name: (undefined | string), array: ts.Node[], tab: number): string { const repeat = ' '.repeat(tab); let retVal = ""; let subStr = ""; @@ -90,7 +90,7 @@ export namespace AST { } for (const [key, value] of Object.entries(array)) { - subStr += Node2String(undefined, value, tab + tabSize); + subStr += node2String(undefined, value, tab + tabSize); } if (subStr) { @@ -104,7 +104,7 @@ export namespace AST { return retVal; } - function Node2String(name: (undefined | string), node: ts.Node, tab: number): string { + function node2String(name: (undefined | string), node: ts.Node, tab: number): string { if (!isNode(node)) { return ""; } @@ -119,17 +119,17 @@ export namespace AST { retVal += repeat + name + ':' + '\n'; } - subStr = kindNames.join('/') + subStr = kindNames.join('/'); retVal += repeat + subStr + ',' + ' ' + kind + '\n'; - subStr = "" + subStr = ""; for (const [key, value] of Object.entries(node)) { if (isArray(value)) { - subStr += Array2String(key, value, tab + tabSize); + subStr += array2String(key, value, tab + tabSize); } if (isNode(value)) { - subStr += Node2String(key, value, tab + tabSize); + subStr += node2String(key, value, tab + tabSize); } } @@ -155,7 +155,7 @@ export namespace AST { for (const value of file.statements) { if (isNode(value)) { - subStr += Node2String(undefined, value, tab + tabSize); + subStr += node2String(undefined, value, tab + tabSize); } } @@ -204,8 +204,9 @@ function run(args: string[], useDefault?: boolean): void { return path.resolve(file); }); - if (useDefault === true) - parsed.options = Object.assign(defaultOptions, parsed.options) + if (useDefault === true) { + parsed.options = Object.assign(defaultOptions, parsed.options); + } console.log(AST.Printer.Convert2String(parsed.fileNames, parsed.options)); } diff --git a/ts2panda/webpack.config.js b/ts2panda/webpack.config.js index fb1f01af299e360a04b3935633f762776328758e..5ad5cf8e8a5e8d4241f042efae40519725c9e798 100644 --- a/ts2panda/webpack.config.js +++ b/ts2panda/webpack.config.js @@ -27,7 +27,7 @@ let cleanOptions = { }; function initConfig(config, envArgs) { - console.log(envArgs.buildMode) + console.log(envArgs.buildMode); Object.assign(config, { optimization: { minimize: envArgs.buildMode !== 'debug'