From c7f361322cd1ba61305158ff1aa7e900ab4457e8 Mon Sep 17 00:00:00 2001 From: zhangrengao Date: Thu, 21 Jul 2022 16:14:40 +0800 Subject: [PATCH] Implement ignore error bigint syntaxerror and fix super error Signed-off-by: zhangrengao Change-Id: I3cc3cd8181d4e7010dd879eb6d78800617c7b47b --- ts2panda/src/ignoreSyntaxError.ts | 4 ++++ ts2panda/src/index.ts | 28 +++++++++++++++++++++++- ts2panda/src/statement/classStatement.ts | 9 ++++---- 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 ts2panda/src/ignoreSyntaxError.ts diff --git a/ts2panda/src/ignoreSyntaxError.ts b/ts2panda/src/ignoreSyntaxError.ts new file mode 100644 index 00000000000..de947ee61b9 --- /dev/null +++ b/ts2panda/src/ignoreSyntaxError.ts @@ -0,0 +1,4 @@ +const BigInt_literals_are_not_available_when_targeting_lower_than_ES2020: number = 2737; +export const IGNORE_ERROR_CODE: number[] = [ + BigInt_literals_are_not_available_when_targeting_lower_than_ES2020 +]; \ No newline at end of file diff --git a/ts2panda/src/index.ts b/ts2panda/src/index.ts index 866827b25dd..e1b34e285c1 100644 --- a/ts2panda/src/index.ts +++ b/ts2panda/src/index.ts @@ -24,6 +24,7 @@ import { LOGE } from "./log"; import { setGlobalDeclare, setGlobalStrict } from "./strictMode"; import { TypeChecker } from "./typeChecker"; import { setPos, isBase64Str, transformCommonjsModule } from "./base/util"; +import { IGNORE_ERROR_CODE } from './ignoreSyntaxError' function checkIsGlobalDeclaration(sourceFile: ts.SourceFile) { for (let statement of sourceFile.statements) { @@ -65,6 +66,10 @@ function main(fileNames: string[], options: ts.CompilerOptions) { } } + if (checkDiagnosticsError(program)) { + return; + } + let emitResult = program.emit( undefined, undefined, @@ -120,6 +125,10 @@ function main(fileNames: string[], options: ts.CompilerOptions) { .concat(emitResult.diagnostics); allDiagnostics.forEach(diagnostic => { + let ignoerErrorSet = new Set(IGNORE_ERROR_CODE); + if (ignoerErrorSet.has(diagnostic.code)) { + return; + } diag.printDiagnostic(diagnostic); }); } @@ -245,12 +254,29 @@ function keepWatchingFiles(filePath: string, parsed: ts.ParsedCommandLine | unde }); } +function checkDiagnosticsError(program: ts.Program) { + let diagnosticsFlag = false; + let allDiagnostics = ts + .getPreEmitDiagnostics(program); + allDiagnostics.forEach(diagnostic => { + let ignoerErrorSet = new Set(IGNORE_ERROR_CODE); + if (ignoerErrorSet.has(diagnostic.code)) { + diagnosticsFlag = false; + return; + } + diagnosticsFlag = true; + diag.printDiagnostic(diagnostic); + }); + + return diagnosticsFlag; +} + namespace Compiler { export namespace Options { export let Default: ts.CompilerOptions = { outDir: "../tmp/build", allowJs: true, - noEmitOnError: true, + noEmitOnError: false, noImplicitAny: true, target: ts.ScriptTarget.ES2017, module: ts.ModuleKind.ES2015, diff --git a/ts2panda/src/statement/classStatement.ts b/ts2panda/src/statement/classStatement.ts index ed9498afbf8..3b816f6be66 100644 --- a/ts2panda/src/statement/classStatement.ts +++ b/ts2panda/src/statement/classStatement.ts @@ -416,10 +416,11 @@ function loadCtorObj(node: ts.CallExpression, compiler: Compiler) { return; } - let nearestFuncScope = recorder.getScopeOfNode(nearestFunc); - if (!nearestFuncScope) { - return; - } + // TODO the design needs to be reconsidered + // let nearestFuncScope = recorder.getScopeOfNode(nearestFunc); + // if (!nearestFuncScope) { + // return; + // } if (ts.isConstructorDeclaration(nearestFunc)) { pandaGen.loadAccumulator(node, getVregisterCache(pandaGen, CacheList.FUNC)); -- Gitee