From 01d51216ded32bec8e9a2d77fdd9b3dda33bb078 Mon Sep 17 00:00:00 2001 From: yangbo <1442420648@qq.com> Date: Thu, 28 Oct 2021 15:32:59 +0800 Subject: [PATCH 1/2] add @Link variable validate and modify @Entry decorator validate message Signed-off-by: yangbo <1442420648@qq.com> Change-Id: I0859b37d20cb8e2b030b505b8ff95026a437d38a --- compiler/src/process_custom_component.ts | 24 ++++++++++++++++++------ compiler/src/validate_ui_syntax.ts | 3 ++- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/compiler/src/process_custom_component.ts b/compiler/src/process_custom_component.ts index 163e8cbb3..75a5fa295 100644 --- a/compiler/src/process_custom_component.ts +++ b/compiler/src/process_custom_component.ts @@ -160,7 +160,7 @@ function checkFromParentToChild(node: ts.ObjectLiteralElementLike, customCompone const propertyName: string = node.name.getText(); const curPropertyKind: string = getPropertyDecoratorKind(propertyName, customComponentName); if (curPropertyKind) { - if (isInitFromParent(node)) { + if (isInitFromParent(node, log)) { const parentPropertyName: string = getParentPropertyName(node as ts.PropertyAssignment, curPropertyKind, log); if (!parentPropertyName) { @@ -180,12 +180,16 @@ function checkFromParentToChild(node: ts.ObjectLiteralElementLike, customCompone } } -function isInitFromParent(node: ts.ObjectLiteralElementLike): boolean { +function isInitFromParent(node: ts.ObjectLiteralElementLike, log: LogInfo[]): boolean { if (ts.isPropertyAssignment(node) && node.initializer) { - if (ts.isPropertyAccessExpression(node.initializer) && node.initializer.expression && - node.initializer.expression.kind === ts.SyntaxKind.ThisKeyword && - ts.isIdentifier(node.initializer.name)) { - return true; + if (ts.isPropertyAccessExpression(node.initializer) && node.initializer.expression) { + if (node.initializer.expression.kind === ts.SyntaxKind.ThisKeyword && + ts.isIdentifier(node.initializer.name)) { + return true; + } else if (ts.isPropertyAccessExpression(node.initializer.expression)) { + validateLinkWithVariableProperty(node, log) + return false; + } } else if (ts.isIdentifier(node.initializer) && matchStartWithDollar(node.initializer.getText())) { return true; @@ -391,3 +395,11 @@ function validateNonLinkWithDollar(node: ts.PropertyAssignment, log: LogInfo[]): pos: node.initializer.getStart() }); } + +function validateLinkWithVariableProperty(node: ts.PropertyAssignment, log: LogInfo[]): void { + log.push({ + type: LogType.ERROR, + message: `'${node.initializer.getText()}' is seen as a regular variable.`, + pos: node.initializer.getStart() + }); +} diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index 575949633..e7fc689dd 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -189,7 +189,8 @@ function validateEntryCount(result: DecoratorResult, fileQuery: string, if (result.entryCount !== 1 && fileQuery === '?entry') { log.push({ type: LogType.ERROR, - message: `A page must have one and only one '@Entry' decorator with a struct.`, + message: `A page configured in 'config.json' must have one and only one '@Entry' ` + + `decorator with a struct.`, fileName: fileName }); } -- Gitee From 75bd6fe33f23859da7354a78e207495c8f828520 Mon Sep 17 00:00:00 2001 From: yangbo <1442420648@qq.com> Date: Fri, 29 Oct 2021 16:48:42 +0800 Subject: [PATCH 2/2] add custom component name validate Signed-off-by: yangbo <1442420648@qq.com> Change-Id: I1d5d8ce9dc6344f93fec5d458c4949a5bd8c9617 --- compiler/src/pre_process.ts | 4 ++-- compiler/src/validate_ui_syntax.ts | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler/src/pre_process.ts b/compiler/src/pre_process.ts index a95b88b51..01abceb1e 100644 --- a/compiler/src/pre_process.ts +++ b/compiler/src/pre_process.ts @@ -30,8 +30,8 @@ function preProcess(source: string): string { if (/\.ets$/.test(this.resourcePath)) { const result: ReplaceResult = sourceReplace(source, this.resourcePath); const newContent: string = result.content; - const log: LogInfo[] = result.log; - log.concat(validateUISyntax(source, newContent, this.resourcePath, this.resourceQuery)); + const log: LogInfo[] = result.log.concat(validateUISyntax(source, newContent, + this.resourcePath, this.resourceQuery)); if (log.length) { emitLogInfo(this, log); } diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index e7fc689dd..e60fcf575 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -267,8 +267,13 @@ function checkDecorators(node: ts.MissingDeclaration | ts.ExportAssignment, resu addLog(LogType.WARN, message, component.pos, log, sourceFile); } if (BUILDIN_STYLE_NAMES.has(componentName)) { - const message: string = - `The struct '${componentName}' cannot have the same name as the built-in attribute '${componentName}'.`; + const message: string = `The struct '${componentName}' cannot have the same name ` + + `as the built-in attribute '${componentName}'.`; + addLog(LogType.ERROR, message, component.pos, log, sourceFile); + } + if (INNER_COMPONENT_NAMES.has(componentName)) { + const message: string = `The struct '${componentName}' cannot have the same name ` + + `as the built-in component '${componentName}'.`; addLog(LogType.ERROR, message, component.pos, log, sourceFile); } } -- Gitee