diff --git a/compiler/src/pre_process.ts b/compiler/src/pre_process.ts index a95b88b51bed6b7fb6713ee4536117cc5ffd0a55..01abceb1ee2b8ecf59bf2d2da04677f6a6f524f7 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/process_custom_component.ts b/compiler/src/process_custom_component.ts index 163e8cbb3a3099176067d3c08cdcf7e6ea54e2be..75a5fa2952e88c040d13774526254b61b2046600 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 575949633a27f8f6c474fbdb818379a2680fc552..e60fcf575592d96fbf8317d07e3c897c1512d751 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 }); } @@ -266,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); } }