From 363559f9296200f076aed3d6873372dfc8430221 Mon Sep 17 00:00:00 2001 From: jiangkaiwen Date: Tue, 4 Apr 2023 15:25:25 +0800 Subject: [PATCH] Fix codecheck warnings of master branch Issue:I6SY11 Signed-off-by: jiangkaiwen Change-Id: I6436d017b053cc00063bc80b4803cd399659e6b7 --- testTs/instype/recordexport.ts | 6 +- testTs/instype/recordthis.ts | 8 +- ts2panda/src/addVariable2Scope.ts | 12 +- ts2panda/src/assemblyDumper.ts | 36 +-- ts2panda/src/astutils.ts | 4 +- ts2panda/src/base/bcGenUtil.ts | 114 +++---- ts2panda/src/base/builtIn.ts | 16 +- ts2panda/src/base/iterator.ts | 22 +- ts2panda/src/base/lexEnv.ts | 2 +- ts2panda/src/base/literal.ts | 14 +- ts2panda/src/base/lreference.ts | 38 +-- ts2panda/src/base/properties.ts | 106 +++--- ts2panda/src/base/typeSystem.ts | 114 +++---- ts2panda/src/base/util.ts | 92 +++--- ts2panda/src/base/vregisterCache.ts | 44 +-- ts2panda/src/cmdOptions.ts | 14 +- ts2panda/src/compiler.ts | 225 ++++++------- ts2panda/src/compilerDriver.ts | 48 +-- ts2panda/src/compilerStatistics.ts | 49 +-- ts2panda/src/compilerUtils.ts | 38 +-- ts2panda/src/debuginfo.ts | 42 +-- ts2panda/src/ecmaModule.ts | 50 +-- .../src/expression/arrayLiteralExpression.ts | 16 +- ts2panda/src/expression/bigIntLiteral.ts | 2 +- ts2panda/src/expression/callExpression.ts | 14 +- .../expression/compileCommaListExpression.ts | 2 +- .../src/expression/memberAccessExpression.ts | 15 +- ts2panda/src/expression/metaProperty.ts | 4 +- ts2panda/src/expression/newExpression.ts | 2 +- ts2panda/src/expression/numericLiteral.ts | 6 +- .../src/expression/objectLiteralExpression.ts | 60 ++-- .../src/expression/parenthesizedExpression.ts | 4 +- ts2panda/src/expression/regularExpression.ts | 10 +- ts2panda/src/expression/stringLiteral.ts | 2 +- ts2panda/src/expression/templateExpression.ts | 16 +- ts2panda/src/expression/yieldExpression.ts | 8 +- ts2panda/src/function/asyncFunctionBuilder.ts | 22 +- .../function/asyncGeneratorFunctionBuilder.ts | 36 +-- ts2panda/src/function/functionBuilder.ts | 8 +- .../src/function/generatorFunctionBuilder.ts | 60 ++-- ts2panda/src/hoisting.ts | 26 +- ts2panda/src/index.ts | 32 +- ts2panda/src/jshelpers.d.ts | 3 +- ts2panda/src/lexenv.ts | 12 +- ts2panda/src/lexicalBinder.ts | 18 +- ts2panda/src/log.ts | 8 +- ts2panda/src/modules.ts | 20 +- ts2panda/src/pandagen.ts | 306 +++++++++--------- ts2panda/src/recorder.ts | 94 +++--- ts2panda/src/regAllocator.ts | 18 +- ts2panda/src/scope.ts | 84 ++--- ts2panda/src/statement/classStatement.ts | 124 +++---- ts2panda/src/statement/forOfStatement.ts | 16 +- ts2panda/src/statement/labelTarget.ts | 32 +- ts2panda/src/statement/loopStatement.ts | 12 +- ts2panda/src/statement/returnStatement.ts | 26 +- ts2panda/src/statement/switchStatement.ts | 2 +- ts2panda/src/statement/tryStatement.ts | 73 ++--- ts2panda/src/strictMode.ts | 12 +- ts2panda/src/syntaxCheckHelper.ts | 22 +- ts2panda/src/syntaxChecker.ts | 286 ++++++++-------- ts2panda/src/syntaxCheckerForStrcitMode.ts | 42 +-- ts2panda/src/ts2panda.ts | 47 +-- ts2panda/src/typeChecker.ts | 74 ++--- ts2panda/src/typeRecorder.ts | 80 ++--- ts2panda/src/variable.ts | 56 ++-- ts2panda/templates/irnodes.ts.erb | 8 +- ts2panda/tests/builtIns.test.ts | 2 +- ts2panda/tests/expression/binary.test.ts | 2 +- ts2panda/tests/expression/conditions.test.ts | 2 +- .../expression/functionExpression.test.ts | 42 +-- .../tests/expression/prefixOperations.test.ts | 6 +- .../tests/expression/propertyAccess.test.ts | 10 +- .../expression/templateExpression.test.ts | 6 +- ts2panda/tests/lexenv.test.ts | 44 +-- ts2panda/tests/regAllocator.test.ts | 4 +- .../statements/functionDeclaration.test.ts | 20 +- .../statements/variableDeclaration.test.ts | 2 +- ts2panda/tests/strictmode/function.js | 6 +- ts2panda/tests/strictmode/function_nest1.js | 4 +- ts2panda/tests/strictmode/function_nest2.js | 6 +- ts2panda/tests/strictmode/strictmode.test.ts | 4 +- ts2panda/tests/types/class.test.ts | 8 +- ts2panda/tests/types/class/class_abstract.ts | 6 +- .../tests/types/class/class_implements.ts | 6 +- ts2panda/tests/types/function.test.ts | 2 +- .../types/function/function_multi_para.ts | 2 +- ts2panda/tests/types/typeUtils.ts | 14 +- ts2panda/tests/utils/base.ts | 20 +- ts2panda/tests/utils/example_asthelper.ts | 6 +- .../tests/watch_expression/addWatch.test.ts | 12 +- ts2panda/tools/astPrinter.ts | 23 +- ts2panda/webpack.config.js | 2 +- 93 files changed, 1613 insertions(+), 1562 deletions(-) diff --git a/testTs/instype/recordexport.ts b/testTs/instype/recordexport.ts index 5328134355..105a82b844 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 c032ae27be..7ddec1decf 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 0f64f618bd..b35414a189 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 { @@ -72,7 +72,7 @@ function addInnerArgs(node: ts.Node, scope: VariableScope, enableTypeRecord: boo scope.addParameter(MandatoryFuncObj, VarDeclarationKind.CONST, -1); // the second argument for newTarget - if (node.kind == ts.SyntaxKind.ArrowFunction) { + if (node.kind === ts.SyntaxKind.ArrowFunction) { scope.addParameter("0newTarget", VarDeclarationKind.CONST, -1); scope.addParameter("0this", VarDeclarationKind.CONST, 0); } 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/assemblyDumper.ts b/ts2panda/src/assemblyDumper.ts index 6b2fc9d793..88ad92d34a 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,31 +96,31 @@ 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) { + if (outputRangeVregNum === 0) { break; } let format = formats[0]; let kind = format[j][0]; let op = operands[j]; - if (kind == OperandKind.Imm) { + if (kind === OperandKind.Imm) { let imm = op; this.output += imm.value.toString(); - } else if (kind == OperandKind.Id) { + } else if (kind === OperandKind.Id) { this.output += op; - } else if (kind == OperandKind.StringId) { + } else if (kind === OperandKind.StringId) { 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"); @@ -131,7 +131,7 @@ export class AssemblyDumper { outputRangeVregNum--; continue; } - } else if (kind == OperandKind.Label) { + } else if (kind === OperandKind.Label) { this.output += this.getLabelName(