From b3289806e1fbb9a63cec6d77ea57497e262e8fa8 Mon Sep 17 00:00:00 2001 From: yfwang6 Date: Thu, 14 Jul 2022 18:10:30 +0800 Subject: [PATCH] wangyongfei6@huawei.com add unique id of component tip Signed-off-by: yfwang6 Change-Id: I81d5356d255a627c521a3b1b6f8714257c089b92 --- compiler/src/pre_define.ts | 1 + compiler/src/process_component_build.ts | 31 ++++++++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 20dfabd..f4b4656 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -111,6 +111,7 @@ export const GLOBAL_CONTEXT: string = 'Context'; export const ATTRIBUTE_ANIMATION: string = 'animation'; export const ATTRIBUTE_ANIMATETO: string = 'animateTo'; export const ATTRIBUTE_STATESTYLES: string = 'stateStyles'; +export const ATTRIBUTE_ID: string = 'id'; export const COMPONENT_CONSTRUCTOR_ID: string = 'compilerAssignedUniqueChildId'; export const COMPONENT_CONSTRUCTOR_PARENT: string = 'parent'; diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index e81f4f2..ab88242 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -59,7 +59,8 @@ import { BIND_DRAG_SET, BIND_POPUP_SET, $$, - PROPERTIES_ADD_DOUBLE_DOLLAR + PROPERTIES_ADD_DOUBLE_DOLLAR, + ATTRIBUTE_ID } from './pre_define'; import { INNER_COMPONENT_NAMES, @@ -988,23 +989,35 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, isStylesAttr: boolean, isGlobalStyles: boolean): void { const propName: string = node.getText(); - if (propName === 'id') { + if (propName === ATTRIBUTE_ID) { + let posOfNode: ts.LineAndCharacter; + let curFileName: string; + let line: number = 1; + let col: number = 1; + if (newsupplement.isAcceleratePreview) { + posOfNode = sourceNode.getLineAndCharacterOfPosition(getRealNodePos(node)); + curFileName = newsupplement.fileName; + if (posOfNode.line === 0) { + col = newsupplement.column - 15; + } + line = newsupplement.line; + } else { + posOfNode = transformLog.sourceFile.getLineAndCharacterOfPosition(getRealNodePos(node)); + curFileName = transformLog.sourceFile.fileName.replace(/\.ts$/, ''); + } const literalString: string = temp.arguments[0].text; - const posOfNode: ts.LineAndCharacter = transformLog.sourceFile - .getLineAndCharacterOfPosition(getRealNodePos(node)); - const curFileName: string = transformLog.sourceFile.fileName.replace(/\.ts$/, ''); - const rLine: number = posOfNode.line + 1; - const rCol: number = posOfNode.character + 1; - const rPath: string = path.resolve(projectConfig.projectPath, curFileName).replace(/\\+/g, '/'); if (ID_ATTRS.has(literalString)) { const errInfo: Map = ID_ATTRS.get(literalString); log.push({ type: LogType.ERROR, - message: `The current component id at ${rPath}:${rLine}:${rCol} is duplicate with ` + + message: `The current component id "${literalString}" is duplicate with ` + `${errInfo.get('path')}:${errInfo.get('line')}:${errInfo.get('col')}.`, pos: node.pos }); } else { + const rLine: number = posOfNode.line + line; + const rCol: number = posOfNode.character + col; + const rPath: string = path.resolve(projectConfig.projectPath, curFileName).replace(/\\+/g, '/'); ID_ATTRS.set(literalString, new Map().set('path', rPath).set('line', rLine).set('col', rCol)); } }