add unique id of component tip

Signed-off-by: yfwang6 <wangyongfei6@huawei.com>
Change-Id: Ie45d3210ef8277a37da466d982fc9da93478c61d
This commit is contained in:
yfwang6
2022-07-14 17:08:22 +08:00
parent efca4a5f15
commit 6d39d61e69
2 changed files with 11 additions and 22 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ export const GESTURE_ATTRS: Set<string> = new Set([
'gesture', 'parallelGesture', 'priorityGesture'
]);
export const ID_ATTRS: Map<string, Set<string | number>> = new Map();
export const ID_ATTRS: Map<string, Map<string, string | number>> = new Map();
export const forbiddenUseStateType: Set<string> = new Set(['Scroller', 'SwiperScroller',
'VideoController', 'WebController', 'CustomDialogController', 'SwiperController',
+10 -21
View File
@@ -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<string, string | number> = 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));
}
}