From 1cdf627ecc034e06d6261d93198266ca04f5d47c Mon Sep 17 00:00:00 2001 From: yfwang6 Date: Thu, 18 Aug 2022 14:21:32 +0800 Subject: [PATCH] wangyongfei6@huawei.com componentid be compatible preview mode incremental compilation Signed-off-by: yfwang6 Change-Id: If2722ad6b95bd8edc496f47998d910e0b16368bb --- compiler/src/process_component_build.ts | 40 ++++++++++++++----------- compiler/src/process_ui_syntax.ts | 12 +++++++- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 931b56a..122cfaa 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -944,24 +944,30 @@ function updateArgumentFor$$(argument: any): ts.Expression { function verifyComponentId(temp: any, node: ts.Identifier, propName: string, log: LogInfo[]): void { if (!newsupplement.isAcceleratePreview && propName === ATTRIBUTE_ID) { - const literalString: string = temp.arguments[0].text; - if (ID_ATTRS.has(literalString)) { - const errInfo: Map = ID_ATTRS.get(literalString); - log.push({ - type: LogType.ERROR, - message: `The current component id "${literalString}" is duplicate with ` + - `${errInfo.get('path')}:${errInfo.get('line')}:${errInfo.get('col')}.`, - pos: node.pos - }); + const id: string = temp.arguments[0].text; + const posOfNode: ts.LineAndCharacter = transformLog.sourceFile + .getLineAndCharacterOfPosition(getRealNodePos(node)); + const curFileName: string = transformLog.sourceFile.fileName.replace(/\.ts$/, ''); + const rPath: string = path.resolve(projectConfig.projectPath, curFileName) + .replace(/\\+/g, '/'); + const rLine: number = posOfNode.line + 1; + const rCol: number = posOfNode.character + 1; + if (ID_ATTRS.has(id)) { + const idInfo: Map = ID_ATTRS.get(id); + if (!(idInfo.get('path') === rPath && + idInfo.get('line') === rLine && + idInfo.get('col') === rCol)) { + log.push({ + type: LogType.WARN, + message: `The current component id "${id}" is duplicate with ` + + `${idInfo.get('path')}:${idInfo.get('line')}:${idInfo.get('col')}.`, + pos: node.pos + }); + } } else { - const posOfNode: ts.LineAndCharacter = transformLog.sourceFile - .getLineAndCharacterOfPosition(getRealNodePos(node)); - const curFileName: string = transformLog.sourceFile.fileName.replace(/\.ts$/, ''); - const rPath: string = path.resolve(projectConfig.projectPath, curFileName) - .replace(/\\+/g, '/'); - ID_ATTRS.set(literalString, new Map().set('path', rPath) - .set('line', posOfNode.line + 1) - .set('col', posOfNode.character + 1)); + ID_ATTRS.set(id, new Map().set('path', rPath) + .set('line', rLine) + .set('col', rCol)); } } } diff --git a/compiler/src/process_ui_syntax.ts b/compiler/src/process_ui_syntax.ts index ab29538..233f4cf 100644 --- a/compiler/src/process_ui_syntax.ts +++ b/compiler/src/process_ui_syntax.ts @@ -75,7 +75,8 @@ import { EXTEND_ATTRIBUTE, INNER_STYLE_FUNCTION, GLOBAL_STYLE_FUNCTION, - INTERFACE_NODE_SET + INTERFACE_NODE_SET, + ID_ATTRS } from './component_map'; import { localStorageLinkCollection, @@ -98,6 +99,7 @@ export function processUISyntax(program: ts.Program, ut = false): Function { pagesDir = path.resolve(path.dirname(node.fileName)); if (process.env.compiler === BUILD_ON) { transformLog.sourceFile = node; + preprocessIdAttrs(node.fileName); if (!ut && (path.basename(node.fileName) === 'app.ets' || /\.ts$/.test(node.fileName))) { node = ts.visitEachChild(node, processResourceNode, context); if (projectConfig.compileMode === ESMODULE && projectConfig.processTs === true @@ -216,6 +218,14 @@ function generateId(statements: ts.Statement[], node: ts.SourceFile): void { ) } +function preprocessIdAttrs(fileName: string): void { + for (const [id, idInfo] of ID_ATTRS) { + if (fileName === idInfo.get('path')) { + ID_ATTRS.delete(id); + } + } +} + function isCustomDialogController(node: ts.Expression) { const tempParent: ts.Node = node.parent; // @ts-ignore