From bf41770993c31bee1f3a299ab24a09669c96a614 Mon Sep 17 00:00:00 2001 From: lihong Date: Sat, 18 Sep 2021 10:44:21 +0800 Subject: [PATCH] lihong67@huawei.com fix get pos for ForEach component Signed-off-by: lihong Change-Id: I11382de0ff8a82996ef2699b17acf828c43cb0b1 --- compiler/src/process_component_build.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index fad16c3b0..e784300f4 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -179,7 +179,7 @@ function processInnerComponent(node: ts.ExpressionStatement, index: number, arr: newStatements.push(res.newNode); if (projectConfig.isPreview) { const posOfNode: ts.LineAndCharacter = - transformLog.sourceFile.getLineAndCharacterOfPosition(node.getStart()); + transformLog.sourceFile.getLineAndCharacterOfPosition(getRealNodePos(node)); const projectPath: string = projectConfig.projectPath; const curFileName: string = transformLog.sourceFile.fileName.replace(/.ts$/, ''); const debugInfo: string = @@ -212,6 +212,16 @@ function processInnerComponent(node: ts.ExpressionStatement, index: number, arr: } } +function getRealNodePos(node: ts.Node): number { + // @ts-ignore + if (node.pos === -1 && node.expression) { + // @ts-ignore + return getRealNodePos(node.expression); + } else { + return node.getStart(); + } +} + function processForEachComponent(node: ts.ExpressionStatement, newStatements: ts.Statement[], log: LogInfo[]): void { const popNode: ts.ExpressionStatement = ts.factory.createExpressionStatement(createFunction( -- Gitee