diff --git a/ts2panda/src/base/util.ts b/ts2panda/src/base/util.ts index c9a2177cadbb3a7a5f9ef364c1abc81d3f0cbc01..81280902a1a5ce06509b3842f9fbb430fa770440 100755 --- a/ts2panda/src/base/util.ts +++ b/ts2panda/src/base/util.ts @@ -296,3 +296,13 @@ export function getRangeStartVregPos(ins: IRNode): number { } return ins instanceof EcmaCreateobjectwithexcludedkeys ? 2 : 1; } + +export function getModuleRequest(node: ts.Node, moduleSpecifier: string): string { + if (path.isAbsolute(moduleSpecifier)) { + return moduleSpecifier; + } + + // relative path resolving + let currentFileName = jshelpers.getSourceFileOfNode(node).fileName; + return path.resolve(path.dirname(currentFileName), moduleSpecifier); +} \ No newline at end of file diff --git a/ts2panda/src/recorder.ts b/ts2panda/src/recorder.ts index d74afb9d1c3378feb0bff1e318a1e1610b83215a..5fbe35ba51f6c899b1250d27add402854dc851aa 100644 --- a/ts2panda/src/recorder.ts +++ b/ts2panda/src/recorder.ts @@ -15,7 +15,7 @@ import ts from "typescript"; import * as astutils from "./astutils"; -import { isAnonymousFunctionDefinition } from "./base/util"; +import { isAnonymousFunctionDefinition, getModuleRequest } from "./base/util"; import { CmdOptions } from "./cmdOptions"; import { CompilerDriver } from "./compilerDriver"; import { DiagnosticCode, DiagnosticError } from "./diagnostic"; @@ -283,7 +283,7 @@ export class Recorder { if (!ts.isStringLiteral(node.moduleSpecifier)) { throw new Error("moduleSpecifier must be a stringLiteral"); } - let moduleRequest = jshelpers.getTextOfIdentifierOrLiteral(node.moduleSpecifier); + let moduleRequest = getModuleRequest(node, jshelpers.getTextOfIdentifierOrLiteral(node.moduleSpecifier)); let importStmt = new ModuleStmt(node, moduleRequest); if (node.importClause) { @@ -329,7 +329,7 @@ export class Recorder { if (!ts.isStringLiteral(node.moduleSpecifier)) { throw new Error("moduleSpecifier must be a stringLiteral"); } - exportStmt = new ModuleStmt(node, jshelpers.getTextOfIdentifierOrLiteral(node.moduleSpecifier)); + exportStmt = new ModuleStmt(node, getModuleRequest(node, jshelpers.getTextOfIdentifierOrLiteral(node.moduleSpecifier))); } else { exportStmt = new ModuleStmt(node); }