From 365e5ecec3a498bb61e6791c2c56494849ec5b03 Mon Sep 17 00:00:00 2001 From: lihong Date: Sat, 18 Sep 2021 10:32:41 +0800 Subject: [PATCH] lihong67@huawei.com fix get pos for ForEach component Signed-off-by: lihong Change-Id: I2d07b6d07ed92f31439e3bd5f722733f417fc2eb --- 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