diff --git a/ts2panda/src/base/util.ts b/ts2panda/src/base/util.ts index e0f66130a02ba1ba5062e2d9730cea09134ec7b9..b985453a4b61b7be100b1a260e303858276ce86d 100755 --- a/ts2panda/src/base/util.ts +++ b/ts2panda/src/base/util.ts @@ -295,4 +295,12 @@ export function getRangeStartVregPos(ins: IRNode): number { return -1; } return ins instanceof EcmaCreateobjectwithexcludedkeys ? 2 : 1; +} + +export function setPos(node: ts.Node) { + ts.setTextRange(node, {pos:-1, end:-1}); + node.forEachChild(childNode => { + setPos(childNode); + }); + return node; } \ No newline at end of file diff --git a/ts2panda/src/debuginfo.ts b/ts2panda/src/debuginfo.ts index 8e3b5c8fed18353e0feaff1f4675b2eca1972a78..0eac8157e6c2df57d3045c98042328fda43a3371 100644 --- a/ts2panda/src/debuginfo.ts +++ b/ts2panda/src/debuginfo.ts @@ -174,23 +174,19 @@ export class DebugInfo { } let pos : number = 0; - let tempWholeLineText : string = "" if (node.pos === -1 || node.end === -1) { - let parent = node.parent; - while (parent) { - if (parent.pos !== -1 && parent.end !== -1) { - pos = parent.pos; - tempWholeLineText = parent.getText(); - break; - } - parent = parent.parent; + return { + loc: { + line : -1, + character : -1 + }, + wholeLineText: "" } - } else { - pos = node.getStart(); } + pos = node.getStart(); let loc = file.getLineAndCharacterOfPosition(pos); - let wholeLineText = tempWholeLineText || node.getText(); + let wholeLineText = node.getText(); return { loc: loc, wholeLineText: wholeLineText diff --git a/ts2panda/src/index.ts b/ts2panda/src/index.ts index 19cc5075fadb8af7c479d97f610eef1b8a076ac3..0c4ef703815165fb00d5b7a78df50858f7b434e6 100644 --- a/ts2panda/src/index.ts +++ b/ts2panda/src/index.ts @@ -27,6 +27,7 @@ import { TypeChecker } from "./typeChecker"; import { TypeRecorder } from "./typeRecorder"; import jshelpers = require("./jshelpers"); import path = require("path"); +import { setPos } from "./base/util"; function checkIsGlobalDeclaration(sourceFile: ts.SourceFile) { for (let statement of sourceFile.statements) { @@ -96,10 +97,18 @@ function main(fileNames: string[], options: ts.CompilerOptions) { (ctx: ts.TransformationContext) => { return (node: ts.SourceFile) => { if (ts.getEmitHelpers(node)) { - const printer: ts.Printer = ts.createPrinter({ newLine: ts.NewLineKind.LineFeed }); - const text: string = printer.printNode(ts.EmitHint.Unspecified, node, node); - let newNode = ts.createSourceFile(node.fileName, text, options.target!); - node = newNode; + let newStatements = []; + ts.getEmitHelpers(node)?.forEach( + item => { + let emitHelperSourceFile = ts.createSourceFile(node.fileName, item.text, options.target!, true, ts.ScriptKind.JS); + emitHelperSourceFile.statements.forEach(emitStatement => { + let emitNode = setPos(emitStatement); + newStatements.push(emitNode); + }); + } + ) + newStatements.push(...node.statements); + node = ts.factory.updateSourceFile(node, newStatements); } let outputBinName = getOutputBinName(node); let compilerDriver = new CompilerDriver(outputBinName);