componentid be compatible preview mode incremental compilation

Signed-off-by: yfwang6 <wangyongfei6@huawei.com>
Change-Id: If2722ad6b95bd8edc496f47998d910e0b16368bb
This commit is contained in:
yfwang6
2022-08-18 14:21:32 +08:00
parent 30ae813155
commit 1cdf627ecc
2 changed files with 34 additions and 18 deletions
+23 -17
View File
@@ -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<string, string | number> = 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<string, string | number> = 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));
}
}
}
+11 -1
View File
@@ -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