diff --git a/ts2panda/src/addVariable2Scope.ts b/ts2panda/src/addVariable2Scope.ts index a4981ce76c0df394459c704b545314f7ca2ab898..be9f499286e14cc2821701740aa51d985dbb77d7 100644 --- a/ts2panda/src/addVariable2Scope.ts +++ b/ts2panda/src/addVariable2Scope.ts @@ -14,7 +14,7 @@ */ import * as ts from "typescript"; -import { isBindingPattern } from "./base/util"; +import { isBindingPattern, getScopeOfNodeOrMappingNode } from "./base/util"; import { CmdOptions } from "./cmdOptions"; import * as jshelpers from "./jshelpers"; import { Recorder } from "./recorder"; @@ -147,7 +147,7 @@ export function addVariableToScope(recorder: Recorder, enableTypeRecord: boolean if (ts.isFunctionDeclaration(funcNode)) { v = scope.add(decl, VarDeclarationKind.FUNCTION); } else if (ts.isFunctionExpression(funcNode)) { - let functionScope = recorder.getScopeOfNode(funcNode); + let functionScope = getScopeOfNodeOrMappingNode(funcNode, recorder); v = functionScope.add(decl, VarDeclarationKind.FUNCTION); } } else if (decl instanceof CatchParameter) { @@ -157,7 +157,7 @@ export function addVariableToScope(recorder: Recorder, enableTypeRecord: boolean if (ts.isClassDeclaration(classNode)) { v = scope.add(decl, VarDeclarationKind.CLASS, InitStatus.UNINITIALIZED); } else { - let classScope = recorder.getScopeOfNode(classNode); + let classScope = getScopeOfNodeOrMappingNode(classNode, recorder); v = classScope.add(decl, VarDeclarationKind.CLASS, InitStatus.UNINITIALIZED); } } else { diff --git a/ts2panda/src/base/util.ts b/ts2panda/src/base/util.ts index 3662772e19f0748b2c4bfe4e39561ea0957afe0f..c35f76af6b9b7fd8bddc8a421b67a5fb584a81dc 100644 --- a/ts2panda/src/base/util.ts +++ b/ts2panda/src/base/util.ts @@ -28,6 +28,7 @@ import { LOGD } from "../log"; import { isFunctionLikeDeclaration } from "../syntaxCheckHelper"; import { CmdOptions } from "../cmdOptions"; import { CompilerDriver } from "../compilerDriver"; +import { Recorder } from "src/recorder"; export function containSpreadElement(args?: ts.NodeArray): boolean { if (!args) { @@ -338,4 +339,15 @@ export function transformCommonjsModule(sourceFile: ts.SourceFile) { ))]; return ts.factory.updateSourceFile(sourceFile, newStatements); +} + +export function getScopeOfNodeOrMappingNode(node: ts.Node, recorder: Recorder) { + let nodeScope = null; + if (node == ts.getOriginalNode(node)) { + let mapNearestFunc = recorder.getMappingNode(node); + nodeScope = recorder.getScopeOfNode(mapNearestFunc!); + } else { + nodeScope = recorder.getScopeOfNode(node!); + } + return nodeScope; } \ No newline at end of file diff --git a/ts2panda/src/compiler.ts b/ts2panda/src/compiler.ts index 59cd1d776e4b8f12eee2ec123589307599e8cb86..a56e82749fd5893dfc89ac04f9169f03b2567c4c 100644 --- a/ts2panda/src/compiler.ts +++ b/ts2panda/src/compiler.ts @@ -29,6 +29,7 @@ import { LReference } from "./base/lreference"; import { hasExportKeywordModifier, isBindingPattern, + getScopeOfNodeOrMappingNode, } from "./base/util"; import { CacheList, getVregisterCache } from "./base/vregisterCache"; import { CmdOptions } from "./cmdOptions"; @@ -235,7 +236,7 @@ export class Compiler { if (!ts.isFunctionExpression(rootNode) && !ts.isMethodDeclaration(rootNode)) { return; } - let functionScope = this.recorder.getScopeOfNode(rootNode); + let functionScope = getScopeOfNodeOrMappingNode(rootNode, this.recorder); if ((rootNode).name) { let funcName = jshelpers.getTextOfIdentifierOrLiteral((rootNode).name); let v = functionScope.find(funcName); @@ -737,7 +738,7 @@ export class Compiler { // Finally after normal try tryBuilder.compileFinallyBlockIfExisted(); if (ts.isForOfStatement(node)) { - let loopScope = this.getRecorder().getScopeOfNode(node); + let loopScope = getScopeOfNodeOrMappingNode(node, this.getRecorder()); let needCreateLoopEnv = loopScope.need2CreateLexEnv(); if (needCreateLoopEnv) { pandaGen.popLexicalEnv(node); @@ -1412,7 +1413,7 @@ export class Compiler { } pushScope(node: ts.Node) { - let scope = this.recorder.getScopeOfNode(node); + let scope = getScopeOfNodeOrMappingNode(node, this.recorder); this.scope = scope; // for debug info DebugInfo.addDebugIns(scope, this.pandaGen, true); diff --git a/ts2panda/src/compilerDriver.ts b/ts2panda/src/compilerDriver.ts index a5b3543ef547b6601821157176bd915acc119bd4..8ac0500c91192e319691159d24dfb55c007e3c27 100644 --- a/ts2panda/src/compilerDriver.ts +++ b/ts2panda/src/compilerDriver.ts @@ -17,7 +17,7 @@ import { writeFileSync } from "fs"; import * as ts from "typescript"; import { addVariableToScope } from "./addVariable2Scope"; import { AssemblyDumper } from "./assemblyDumper"; -import { hasDefaultKeywordModifier, hasExportKeywordModifier, initiateTs2abc, listenChildExit, listenErrorEvent, terminateWritePipe, getRecordTypeFlag } from "./base/util"; +import { hasDefaultKeywordModifier, hasExportKeywordModifier, initiateTs2abc, listenChildExit, listenErrorEvent, terminateWritePipe, getRecordTypeFlag, getScopeOfNodeOrMappingNode } from "./base/util"; import { CmdOptions } from "./cmdOptions"; import { Compiler @@ -348,7 +348,7 @@ export class CompilerDriver { name = this.getInternalNameForCtor(classNode, node); } else { let funcNode = node; - name = (recorder.getScopeOfNode(funcNode)).getFuncName(); + name = (getScopeOfNodeOrMappingNode(funcNode, recorder)).getFuncName(); if (name == '') { if ((ts.isFunctionDeclaration(node) && hasExportKeywordModifier(node) && hasDefaultKeywordModifier(node)) || ts.isExportAssignment(findOuterNodeOfParenthesis(node))) { diff --git a/ts2panda/src/function/generatorFunctionBuilder.ts b/ts2panda/src/function/generatorFunctionBuilder.ts index b7297aebd1462233cc4ef8002c0448c3d4f006cc..3afc291ec228abe565089a2024d3ec59d3c80e91 100644 --- a/ts2panda/src/function/generatorFunctionBuilder.ts +++ b/ts2panda/src/function/generatorFunctionBuilder.ts @@ -24,6 +24,7 @@ import { import { PandaGen } from "../pandagen"; import { Recorder } from "../recorder"; import { IteratorRecord, IteratorType, getIteratorRecord } from "../statement/forOfStatement"; +import { getScopeOfNodeOrMappingNode } from "../base/util" enum ResumeMode { Return = 0, Throw, Next }; @@ -48,7 +49,7 @@ export class GeneratorFunctionBuilder { prepare(node: ts.Node, recorder: Recorder) { let pandaGen = this.pandaGen; // @ts-ignore - let scope = recorder.getScopeOfNode(node); + let scope = getScopeOfNodeOrMappingNode(node, recorder); // backend handle funcobj, frontend set undefined pandaGen.createGeneratorObj(node, getVregisterCache(pandaGen, CacheList.FUNC)); diff --git a/ts2panda/src/hoisting.ts b/ts2panda/src/hoisting.ts index 4fca6459120954f8acc9fd561a50a67ad8880c1f..5352b2abb732d3d51d0c8cda822261fe164297ba 100644 --- a/ts2panda/src/hoisting.ts +++ b/ts2panda/src/hoisting.ts @@ -31,10 +31,11 @@ import { VarDecl, VariableScope } from "./scope"; +import { getScopeOfNodeOrMappingNode } from "./base/util"; export function hoisting(rootNode: ts.SourceFile | ts.FunctionLikeDeclaration, pandaGen: PandaGen, recorder: Recorder, compiler: Compiler) { - let variableScope = recorder.getScopeOfNode(rootNode); + let variableScope = getScopeOfNodeOrMappingNode(rootNode, recorder); let hoistDecls = recorder.getHoistDeclsOfScope(variableScope); hoistDecls ?.forEach((decl) => { diff --git a/ts2panda/src/ignoreSyntaxError.ts b/ts2panda/src/ignoreSyntaxError.ts new file mode 100644 index 0000000000000000000000000000000000000000..a0b647a8387f678b312923ef24f5d17209c9dc51 --- /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 7b77bb16b40c8ecba0f9461c1530b4bb290b1fc2..187330d9e7f65135dbfec516a0d91117704f55b5 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,10 +125,31 @@ 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); }); } +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; +} + function getOutputBinName(node: ts.SourceFile) { let outputBinName = CmdOptions.getOutputBinName(); let fileName = node.fileName.substring(0, node.fileName.lastIndexOf('.')); diff --git a/ts2panda/src/recorder.ts b/ts2panda/src/recorder.ts index e3ba10ca90838821142f396a2929c62704838865..9c76b3ea49ae592f78cf80cafd9617c48770e2db 100644 --- a/ts2panda/src/recorder.ts +++ b/ts2panda/src/recorder.ts @@ -18,7 +18,8 @@ import * as astutils from "./astutils"; import { hasDefaultKeywordModifier, hasExportKeywordModifier, - isAnonymousFunctionDefinition + isAnonymousFunctionDefinition, + getScopeOfNodeOrMappingNode } from "./base/util"; import { CmdOptions } from "./cmdOptions"; import { CompilerDriver } from "./compilerDriver"; @@ -73,6 +74,7 @@ export class Recorder { private importStmts: Array = []; private exportStmts: Array = []; private syntaxCheckStatus: boolean; + private mappingOriginNode: Map = new Map(); constructor(node: ts.Node, scope: Scope, compilerDriver: CompilerDriver, recordType: boolean, isTsFile: boolean, syntaxCheckStatus: boolean) { this.node = node; @@ -88,6 +90,10 @@ export class Recorder { record() { this.setParent(this.node); this.setScopeMap(this.node, this.scope); + if (ts.getOriginalNode(this.node)) { + this.setMappingNode(this.node, ts.getOriginalNode(this.node)); + this.setMappingNode(ts.getOriginalNode(this.node), this.node); + } this.recordInfo(this.node, this.scope); return this.node; } @@ -132,6 +138,10 @@ export class Recorder { } case ts.SyntaxKind.FunctionDeclaration: { let functionScope = this.buildVariableScope(scope, childNode); + if (ts.getOriginalNode(node)) { + this.setMappingNode(childNode, ts.getOriginalNode(childNode)); + this.setMappingNode(ts.getOriginalNode(childNode), childNode); + } let isExport: boolean = false; if (hasExportKeywordModifier(childNode)) { if (!CmdOptions.isModules()) { @@ -158,6 +168,10 @@ export class Recorder { case ts.SyntaxKind.CatchClause: { let localScope = new LocalScope(scope); this.setScopeMap(childNode, localScope); + if (ts.getOriginalNode(childNode)) { + this.setMappingNode(childNode, ts.getOriginalNode(childNode)); + this.setMappingNode(ts.getOriginalNode(childNode), childNode); + } this.recordInfo(childNode, localScope); break; } @@ -166,8 +180,13 @@ export class Recorder { case ts.SyntaxKind.ForStatement: case ts.SyntaxKind.ForInStatement: case ts.SyntaxKind.ForOfStatement: { - let loopScope: LoopScope = new LoopScope(scope);; + let loopScope: LoopScope = new LoopScope(scope); + this.setMappingNode(childNode, ts.getOriginalNode(childNode)); this.setScopeMap(childNode, loopScope); + if (ts.getOriginalNode(childNode)) { + this.setMappingNode(childNode, ts.getOriginalNode(childNode)); + this.setMappingNode(ts.getOriginalNode(childNode), childNode); + } this.recordInfo(childNode, loopScope); break; } @@ -261,6 +280,10 @@ export class Recorder { private recordClassInfo(childNode: ts.ClassLikeDeclaration, scope: Scope, isExport: boolean) { let localScope = new LocalScope(scope); this.setScopeMap(childNode, localScope); + if (ts.getOriginalNode(childNode)) { + this.setMappingNode(childNode, ts.getOriginalNode(childNode)); + this.setMappingNode(ts.getOriginalNode(childNode), childNode); + } let ctor = extractCtorOfClass(childNode); if (!ctor) { AddCtor2Class(this, childNode, localScope); @@ -282,6 +305,10 @@ export class Recorder { functionScope.setParentVariableScope(parentVariableScope); parentVariableScope.addChildVariableScope(functionScope); this.setScopeMap(node, functionScope); + if (ts.getOriginalNode(node)) { + this.setMappingNode(node, ts.getOriginalNode(node)); + this.setMappingNode(ts.getOriginalNode(node), node); + } return functionScope; } @@ -626,7 +653,7 @@ export class Recorder { this.collectHoistDecls(node, hoistScope, funcDecl); } else if (scope instanceof LocalScope) { hoistScope = scope.getNearestVariableScope(); - let expectHoistScope = this.getScopeOfNode(node.parent.parent); + let expectHoistScope = getScopeOfNodeOrMappingNode(node.parent.parent, this); if ((hoistScope == expectHoistScope) && (hoistScope instanceof FunctionScope)) { need2AddDecls = this.collectHoistDecls(node, hoistScope, funcDecl); } @@ -694,7 +721,7 @@ export class Recorder { } } - (this.getScopeOfNode(node)).setFuncName(name); + (getScopeOfNodeOrMappingNode(node, this)).setFuncName(name); if (name != '') { let funcNameMap = this.funcNameMap; @@ -731,7 +758,7 @@ export class Recorder { } }); } - (this.getScopeOfNode(node)).setParameterLength(length); + (getScopeOfNodeOrMappingNode(node, this)).setParameterLength(length); this.setParametersMap(node, funcParams); } @@ -832,4 +859,12 @@ export class Recorder { getFuncNameMap() { return this.funcNameMap; } + + setMappingNode(currentNode: ts.Node, originNode: ts.Node) { + this.mappingOriginNode.set(originNode, currentNode); + } + + getMappingNode(node: ts.Node) { + return this.mappingOriginNode.get(node) + } } diff --git a/ts2panda/src/statement/classStatement.ts b/ts2panda/src/statement/classStatement.ts index ed9498afbf8359bcb57673c151c9b11f60caad3e..bdd0069f1d7b34a626543fd0d63e1bb503cdebdd 100644 --- a/ts2panda/src/statement/classStatement.ts +++ b/ts2panda/src/statement/classStatement.ts @@ -28,7 +28,8 @@ import { getParamLengthOfFunc, hasDefaultKeywordModifier, hasExportKeywordModifier, - isUndefinedIdentifier + isUndefinedIdentifier, + getScopeOfNodeOrMappingNode } from "../base/util"; import { CacheList, getVregisterCache } from "../base/vregisterCache"; import { Compiler } from "../compiler"; @@ -118,7 +119,7 @@ export function compileClassDeclaration(compiler: Compiler, stmt: ts.ClassLikeDe compileUnCompiledProperty(compiler, properties, classReg); pandaGen.loadAccumulator(stmt, classReg); - let classScope = compiler.getRecorder().getScopeOfNode(stmt); + let classScope = getScopeOfNodeOrMappingNode(stmt, compiler.getRecorder()); if (hasExportKeywordModifier(stmt)) { if (stmt.name) { let className = jshelpers.getTextOfIdentifierOrLiteral(stmt.name); @@ -169,7 +170,7 @@ export function AddCtor2Class(recorder: Recorder, classNode: ts.ClassLikeDeclara ctorNode = jshelpers.setParent(ctorNode, classNode)!; ctorNode = ts.setTextRange(ctorNode, classNode); - let parentScope = recorder.getScopeOfNode(classNode); + let parentScope = getScopeOfNodeOrMappingNode(classNode, recorder); let funcScope = recorder.buildVariableScope(scope, ctorNode); funcScope.setParent(parentScope); @@ -177,7 +178,15 @@ export function AddCtor2Class(recorder: Recorder, classNode: ts.ClassLikeDeclara ctorBodyScope.setParent(funcScope); recorder.setScopeMap(ctorNode, funcScope); + if (ts.getOriginalNode(ctorNode)) { + recorder.setMappingNode(ctorNode, ts.getOriginalNode(ctorNode)); + recorder.setMappingNode(ts.getOriginalNode(ctorNode), ctorNode); + } recorder.setScopeMap(ctorNode.body!, ctorBodyScope); + if (ts.getOriginalNode(ctorNode.body!)) { + recorder.setMappingNode(ctorNode.body!, ts.getOriginalNode(ctorNode.body!)); + recorder.setMappingNode(ts.getOriginalNode(ctorNode.body!), ctorNode.body!); + } recorder.recordFuncName(ctorNode); recorder.recordFunctionParameters(ctorNode); @@ -416,7 +425,7 @@ function loadCtorObj(node: ts.CallExpression, compiler: Compiler) { return; } - let nearestFuncScope = recorder.getScopeOfNode(nearestFunc); + let nearestFuncScope = getScopeOfNodeOrMappingNode(nearestFunc, recorder); if (!nearestFuncScope) { return; } @@ -425,7 +434,7 @@ function loadCtorObj(node: ts.CallExpression, compiler: Compiler) { pandaGen.loadAccumulator(node, getVregisterCache(pandaGen, CacheList.FUNC)); } else { let outerFunc = jshelpers.getContainingFunctionDeclaration(nearestFunc); - let outerFuncScope = recorder.getScopeOfNode(outerFunc!); + let outerFuncScope = getScopeOfNodeOrMappingNode(outerFunc, recorder); outerFuncScope.pendingCreateEnv(); let level = 1; while (!ts.isConstructorDeclaration(outerFunc!)) { diff --git a/ts2panda/src/statement/forOfStatement.ts b/ts2panda/src/statement/forOfStatement.ts index ca3fb6a40c00363f97f0935b2960ae995bbd5beb..4921badbc14b7271b8d2e9232d41fa3ac19c7a2f 100644 --- a/ts2panda/src/statement/forOfStatement.ts +++ b/ts2panda/src/statement/forOfStatement.ts @@ -24,6 +24,7 @@ import { Label, VReg } from "../irnodes"; import { TryBuilderWithForOf } from "./tryStatement"; import { PandaGen } from "src/pandagen"; import { LoopScope } from "src/scope"; +import { getScopeOfNodeOrMappingNode } from "../base/util"; export enum IteratorType { Normal, Async } @@ -63,7 +64,7 @@ export function compileForOfStatement(stmt: ts.ForOfStatement, compiler: Compile let method = pandaGen.getTemp(); let object = pandaGen.getTemp(); - let loopScope = compiler.getRecorder().getScopeOfNode(stmt); + let loopScope = getScopeOfNodeOrMappingNode(stmt, compiler.getRecorder()); let needCreateLoopEnv: boolean = loopScope.need2CreateLexEnv(); let loopEnv = pandaGen.getTemp(); diff --git a/ts2panda/src/statement/loopStatement.ts b/ts2panda/src/statement/loopStatement.ts index f7e1bd0d8fa5e74caf7f899ead52cc6f577b81fb..2e1a676b1829a7f93f87c300bdf3b2edfc3a90b8 100644 --- a/ts2panda/src/statement/loopStatement.ts +++ b/ts2panda/src/statement/loopStatement.ts @@ -31,12 +31,13 @@ import { Compiler } from "../compiler"; import { Label, VReg } from "../irnodes"; import { LoopScope, Scope } from "../scope"; import { LabelTarget } from "./labelTarget"; +import { getScopeOfNodeOrMappingNode } from "../base/util"; export function compileDoStatement(stmt: ts.DoStatement, compiler: Compiler) { compiler.pushScope(stmt); let pandaGen = compiler.getPandaGen(); - let loopScope = compiler.getRecorder().getScopeOfNode(stmt); + let loopScope = getScopeOfNodeOrMappingNode(stmt, compiler.getRecorder()); let needCreateLoopEnv: boolean = loopScope.need2CreateLexEnv() ? true : false; let loopStartLabel = new Label(); @@ -79,7 +80,7 @@ export function compileWhileStatement(stmt: ts.WhileStatement, compiler: Compile compiler.pushScope(stmt); let pandaGen = compiler.getPandaGen(); - let loopScope = compiler.getRecorder().getScopeOfNode(stmt); + let loopScope = getScopeOfNodeOrMappingNode(stmt, compiler.getRecorder()); let needCreateLoopEnv: boolean = loopScope.need2CreateLexEnv() ? true : false; let loopStartLabel = new Label(); @@ -121,7 +122,7 @@ export function compileForStatement(stmt: ts.ForStatement, compiler: Compiler) { let pandaGen = compiler.getPandaGen(); // determine if loopenv need to be created - let loopScope = compiler.getRecorder().getScopeOfNode(stmt); + let loopScope = getScopeOfNodeOrMappingNode(stmt, compiler.getRecorder()); let needCreateLoopEnv: boolean = loopScope.need2CreateLexEnv(); let loopEnv = pandaGen.getTemp(); let createEnvAtBegining: boolean = false; @@ -254,7 +255,7 @@ export function compileForInStatement(stmt: ts.ForInStatement, compiler: Compile let pandaGen = compiler.getPandaGen(); // determine the location where env should be created - let loopScope = compiler.getRecorder().getScopeOfNode(stmt); + let loopScope = getScopeOfNodeOrMappingNode(stmt, compiler.getRecorder()); let needCreateLexEnv: boolean = loopScope.need2CreateLexEnv() ? true : false; let loopEnv = pandaGen.getTemp(); diff --git a/ts2panda/src/statement/tryStatement.ts b/ts2panda/src/statement/tryStatement.ts index bdc0a632df752d4ff1aebc9de86e470c10add869..025aacfb7bd30822a345e136f0d790e479236a07 100644 --- a/ts2panda/src/statement/tryStatement.ts +++ b/ts2panda/src/statement/tryStatement.ts @@ -29,18 +29,23 @@ import { IteratorRecord } from "./forOfStatement"; import * as astutils from "../astutils"; import { VarDeclarationKind } from "../variable"; import * as jshelpers from "../jshelpers"; +import { getScopeOfNodeOrMappingNode } from "../base/util"; // adjust the try...catch...finally into nested try(try...catch) finally export function transformTryCatchFinally(tryStmt: ts.TryStatement, recorder: Recorder): ts.TryStatement { // after create new try block node, mapped with new scope, and adjust parent node - let tryStmtScope = recorder.getScopeOfNode(tryStmt); + let tryStmtScope = getScopeOfNodeOrMappingNode(tryStmt, recorder); let newTryBlockScope = new LocalScope(tryStmtScope); let newTryStmtScope = new LocalScope(newTryBlockScope); - (recorder.getScopeOfNode(tryStmt.tryBlock)).setParent(newTryStmtScope); - (recorder.getScopeOfNode(tryStmt.catchClause!)).setParent(newTryStmtScope); + (getScopeOfNodeOrMappingNode(tryStmt, recorder)).setParent(newTryStmtScope); + (getScopeOfNodeOrMappingNode(tryStmt.catchClause!, recorder)).setParent(newTryStmtScope); const newTryStmt = ts.factory.createTryStatement(tryStmt.tryBlock, tryStmt.catchClause, undefined); recorder.setScopeMap(newTryStmt, newTryStmtScope); + if (ts.getOriginalNode(newTryStmt)) { + recorder.setMappingNode(newTryStmt, ts.getOriginalNode(newTryStmt)); + recorder.setMappingNode(ts.getOriginalNode(newTryStmt), newTryStmt); + } const newTryBlock = [newTryStmt]; newTryBlock[0] = jshelpers.setParent(newTryBlock[0], tryStmt)!; @@ -48,6 +53,11 @@ export function transformTryCatchFinally(tryStmt: ts.TryStatement, recorder: Rec let tryBlock = ts.factory.updateBlock(tryStmt.tryBlock, newTryBlock); tryStmt = ts.factory.updateTryStatement(tryStmt, tryBlock, undefined, tryStmt.finallyBlock); recorder.setScopeMap(tryStmt.tryBlock, newTryBlockScope); + if (ts.getOriginalNode(tryStmt.tryBlock)) { + recorder.setMappingNode(tryStmt.tryBlock, ts.getOriginalNode(tryStmt.tryBlock)); + recorder.setMappingNode(ts.getOriginalNode(tryStmt.tryBlock), tryStmt.tryBlock); + } + return tryStmt; } @@ -266,7 +276,7 @@ export class TryBuilderWithForOf extends TryBuilderBase { let resultReg = this.pandaGen.getTemp(); let isDeclaration: boolean = false; - let loopScope = compiler.getRecorder().getScopeOfNode(stmt); + let loopScope = getScopeOfNodeOrMappingNode(stmt, compiler.getRecorder()); pandaGen.loadAccumulator(stmt, getVregisterCache(pandaGen, CacheList.True)); pandaGen.storeAccumulator(stmt, this.doneReg);