From 990fab6c45772782f6908acdbc32f99f07905806 Mon Sep 17 00:00:00 2001 From: yfwang6 Date: Wed, 13 Jul 2022 18:23:20 +0800 Subject: [PATCH 1/7] wangyongfei6@huawei.com add unique id of component tip Signed-off-by: yfwang6 Change-Id: I89171075f34bc52d52cdf612abe9a231a9e1eb69 --- compiler/src/component_map.ts | 2 ++ compiler/src/process_component_build.ts | 36 ++++++++++++++++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/compiler/src/component_map.ts b/compiler/src/component_map.ts index cc9dc4a..c8c3900 100644 --- a/compiler/src/component_map.ts +++ b/compiler/src/component_map.ts @@ -47,6 +47,8 @@ export const GESTURE_ATTRS: Set = new Set([ 'gesture', 'parallelGesture', 'priorityGesture' ]); +export const ID_ATTRS: Map> = new Map(); + export const forbiddenUseStateType: Set = new Set(['Scroller', 'SwiperScroller', 'VideoController', 'WebController', 'CustomDialogController', 'SwiperController', 'TabsController', 'CalendarController', 'AbilityController', 'XComponentController', diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 79e6a03..ab45745 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -77,7 +77,8 @@ import { CUSTOM_BUILDER_PROPERTIES, BUILDER_MIX_EXTEND, BUILDER_MIX_EXTEND_RESPECTIVE, - BUILDER_MIX_STYLES + BUILDER_MIX_STYLES, + ID_ATTRS } from './component_map'; import { componentCollection, @@ -986,6 +987,39 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, statements: ts.Statement[], identifierNode: ts.Identifier, log: LogInfo[], isStylesAttr: boolean, isGlobalStyles: boolean): void { const propName: string = node.getText(); + 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$/, ''); + } + + if (propName === 'id') { + const literalString = temp.arguments[0].text; + const rLine: number = posOfNode.line + line; + const rCol: number = posOfNode.character + col; + const projectPath: string = projectConfig.projectPath; + const rPath: string = path.resolve(projectPath, curFileName).replace(/\\+/g, '/'); + if (ID_ATTRS.has(literalString)) { + log.push({ + type: LogType.ERROR, + message: `There should have a unique id at ${rPath} ${rLine}:${rCol}.`, + pos: node.pos + }); + } else { + ID_ATTRS.set(literalString, new Set([rLine, rCol, rPath])); + } + } + if (propName === ATTRIBUTE_ANIMATION) { if (!lastStatement.statement) { if (!(temp.arguments.length === 1 && From efca4a5f15879ea5bdc6cacdee2dbce3e58dba77 Mon Sep 17 00:00:00 2001 From: yfwang6 Date: Wed, 13 Jul 2022 18:29:43 +0800 Subject: [PATCH 2/7] wangyongfei6@huawei.com add unique id of component tip Signed-off-by: yfwang6 Change-Id: Iac1bcc14c1ebab085f66e1113a28397ae513b4b6 --- compiler/src/process_component_build.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index ab45745..df2a2a0 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -1004,7 +1004,7 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, } if (propName === 'id') { - const literalString = temp.arguments[0].text; + const literalString: string = temp.arguments[0].text; const rLine: number = posOfNode.line + line; const rCol: number = posOfNode.character + col; const projectPath: string = projectConfig.projectPath; From 6d39d61e69f5108de77351cccc87b84a75308915 Mon Sep 17 00:00:00 2001 From: yfwang6 Date: Thu, 14 Jul 2022 17:08:22 +0800 Subject: [PATCH 3/7] wangyongfei6@huawei.com add unique id of component tip Signed-off-by: yfwang6 Change-Id: Ie45d3210ef8277a37da466d982fc9da93478c61d --- compiler/src/component_map.ts | 2 +- compiler/src/process_component_build.ts | 31 ++++++++----------------- 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/compiler/src/component_map.ts b/compiler/src/component_map.ts index c8c3900..e1105cd 100644 --- a/compiler/src/component_map.ts +++ b/compiler/src/component_map.ts @@ -47,7 +47,7 @@ export const GESTURE_ATTRS: Set = new Set([ 'gesture', 'parallelGesture', 'priorityGesture' ]); -export const ID_ATTRS: Map> = new Map(); +export const ID_ATTRS: Map> = new Map(); export const forbiddenUseStateType: Set = new Set(['Scroller', 'SwiperScroller', 'VideoController', 'WebController', 'CustomDialogController', 'SwiperController', diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index df2a2a0..e81f4f2 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -987,36 +987,25 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, statements: ts.Statement[], identifierNode: ts.Identifier, log: LogInfo[], isStylesAttr: boolean, isGlobalStyles: boolean): void { const propName: string = node.getText(); - 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$/, ''); - } if (propName === 'id') { const literalString: string = temp.arguments[0].text; - const rLine: number = posOfNode.line + line; - const rCol: number = posOfNode.character + col; - const projectPath: string = projectConfig.projectPath; - const rPath: string = path.resolve(projectPath, curFileName).replace(/\\+/g, '/'); + 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: `There should have a unique id at ${rPath} ${rLine}:${rCol}.`, + message: `The current component id at ${rPath}:${rLine}:${rCol} is duplicate with ` + + `${errInfo.get('path')}:${errInfo.get('line')}:${errInfo.get('col')}.`, pos: node.pos }); } else { - ID_ATTRS.set(literalString, new Set([rLine, rCol, rPath])); + ID_ATTRS.set(literalString, new Map().set('path', rPath).set('line', rLine).set('col', rCol)); } } From b3289806e1fbb9a63cec6d77ea57497e262e8fa8 Mon Sep 17 00:00:00 2001 From: yfwang6 Date: Thu, 14 Jul 2022 18:10:30 +0800 Subject: [PATCH 4/7] 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)); } } From 987947463ab6819024aca617a1b66794be2d8cc7 Mon Sep 17 00:00:00 2001 From: yfwang6 Date: Fri, 15 Jul 2022 16:03:51 +0800 Subject: [PATCH 5/7] wangyongfei6@huawei.com add unique id of component tip Signed-off-by: yfwang6 Change-Id: I54133c68fb85f5ede305bb954d23638686f1a3dd --- compiler/src/process_component_build.ts | 48 ++++++++++--------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index ab88242..2db3380 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -989,36 +989,26 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, isStylesAttr: boolean, isGlobalStyles: boolean): void { const propName: string = node.getText(); - 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; + if (!newsupplement.isAcceleratePreview) { + if (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 + }); + } 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, '/'); + const rLine: number = posOfNode.line + 1; + const rCol: number = posOfNode.character + 1; + ID_ATTRS.set(literalString, new Map().set('path', rPath).set('line', rLine).set('col', rCol)); } - line = newsupplement.line; - } else { - posOfNode = transformLog.sourceFile.getLineAndCharacterOfPosition(getRealNodePos(node)); - curFileName = transformLog.sourceFile.fileName.replace(/\.ts$/, ''); - } - 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 - }); - } 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)); } } From 9e73decf11776fba6df51b663cbb0e5bb0e57202 Mon Sep 17 00:00:00 2001 From: yfwang6 Date: Mon, 18 Jul 2022 10:32:00 +0800 Subject: [PATCH 6/7] wangyongfei6@huawei.com add unique id of component tip Signed-off-by: yfwang6 Change-Id: I99bd5b9448aaecde6b6eff90e4438768c57b30aa --- compiler/src/process_component_build.ts | 39 +++++++++++-------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 2db3380..142d201 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -988,30 +988,25 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, statements: ts.Statement[], identifierNode: ts.Identifier, log: LogInfo[], isStylesAttr: boolean, isGlobalStyles: boolean): void { const propName: string = node.getText(); - - if (!newsupplement.isAcceleratePreview) { - if (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 - }); - } 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, '/'); - const rLine: number = posOfNode.line + 1; - const rCol: number = posOfNode.character + 1; - ID_ATTRS.set(literalString, new Map().set('path', rPath).set('line', rLine).set('col', rCol)); - } + 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 + }); + } 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)); } } - if (propName === ATTRIBUTE_ANIMATION) { if (!lastStatement.statement) { if (!(temp.arguments.length === 1 && From 77ba0d5da9e6f9c6e42fd1fc058d57d5ad388bef Mon Sep 17 00:00:00 2001 From: yfwang6 Date: Mon, 18 Jul 2022 10:49:40 +0800 Subject: [PATCH 7/7] wangyongfei6@huawei.com add unique id of component tip Signed-off-by: yfwang6 Change-Id: Ie852bdeed92986ad714ee085be2bde729ffb13fb --- compiler/src/process_component_build.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/compiler/src/process_component_build.ts b/compiler/src/process_component_build.ts index 142d201..347ab88 100644 --- a/compiler/src/process_component_build.ts +++ b/compiler/src/process_component_build.ts @@ -984,10 +984,8 @@ function updateArgumentFor$$(argument: any): ts.Expression { } } -function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, - statements: ts.Statement[], identifierNode: ts.Identifier, log: LogInfo[], - isStylesAttr: boolean, isGlobalStyles: boolean): void { - const propName: string = node.getText(); +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)) { @@ -1002,11 +1000,20 @@ function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, 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) + 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)); } } +} + +function addComponentAttr(temp: any, node: ts.Identifier, lastStatement: any, + statements: ts.Statement[], identifierNode: ts.Identifier, log: LogInfo[], + isStylesAttr: boolean, isGlobalStyles: boolean): void { + const propName: string = node.getText(); + verifyComponentId(temp, node, propName, log); if (propName === ATTRIBUTE_ANIMATION) { if (!lastStatement.statement) { if (!(temp.arguments.length === 1 &&