From 59838b4b2ca44b188dd49c5d420971ea6ad40031 Mon Sep 17 00:00:00 2001 From: hufeng Date: Fri, 15 Oct 2021 15:01:02 +0800 Subject: [PATCH 1/2] Support resolving relative path of imported module Signed-off-by: hufeng Change-Id: Ib550d943b58be3d8dd632d88fe1b6f4e0430c67a --- ts2panda/src/base/util.ts | 10 ++++++++++ ts2panda/src/recorder.ts | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ts2panda/src/base/util.ts b/ts2panda/src/base/util.ts index c9a2177cad..81280902a1 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 d74afb9d1c..9509fcb7dd 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) { -- Gitee From ce097f6d7906ff21b064ee4b827097b629d50d99 Mon Sep 17 00:00:00 2001 From: hufeng Date: Fri, 15 Oct 2021 17:40:00 +0800 Subject: [PATCH 2/2] fix case: export * from './a.js' Signed-off-by: hufeng Change-Id: I22edb376aafbfa8ec57ac491289bcf5b89fadf0f --- ts2panda/src/recorder.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ts2panda/src/recorder.ts b/ts2panda/src/recorder.ts index 9509fcb7dd..5fbe35ba51 100644 --- a/ts2panda/src/recorder.ts +++ b/ts2panda/src/recorder.ts @@ -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); } -- Gitee