diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 659f618b2fba39cacda6310276cc74e5581dd233..17a17436894f528acf11d9db873feb4adc773c5b 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -66,6 +66,12 @@ export const REUSABLE_V2_INNER_DECORATOR: string = '__ReusableV2_Inner_Decorator export const REUSE_ATTRIBUTE: string = 'reuse'; export const COMPONENT_USER_INTENTS_DECORATOR_PAGE: string = '@InsightIntentPage'; +export const COMPONENT_USER_INTENTS_DECORATOR_LINK: string = '@InsightIntentLink'; +export const COMPONENT_USER_INTENTS_DECORATOR_ENTRY: string = '@InsightIntentEntry'; +export const COMPONENT_USER_INTENTS_DECORATOR_FUNCTION: string = '@InsightIntentFunction'; +export const COMPONENT_USER_INTENTS_DECORATOR_METHOD: string = '@InsightIntentFunctionMethod'; +export const COMPONENT_USER_INTENTS_DECORATOR_ENTITY: string = '@InsightIntentEntity'; +export const COMPONENT_USER_INTENTS_DECORATOR_FORM: string = '@InsightIntentForm'; export const COMPONENT_DECORATORS_PARAMS: Set = new Set([COMPONENT_CONSUME_DECORATOR, COMPONENT_STORAGE_PROP_DECORATOR, COMPONENT_STORAGE_LINK_DECORATOR, COMPONENT_PROVIDE_DECORATOR, @@ -95,12 +101,6 @@ export const COMPONENT_STYLES_DECORATOR: string = '@Styles'; export const COMPONENT_ANIMATABLE_EXTEND_DECORATOR: string = '@AnimatableExtend'; export const COMPONENT_CONCURRENT_DECORATOR: string = '@Concurrent'; export const COMPONENT_SENDABLE_DECORATOR: string = '@Sendable'; -export const COMPONENT_USER_INTENTS_DECORATOR: string = '@InsightIntentLink'; -export const COMPONENT_USER_INTENTS_DECORATOR_ENTRY: string = '@InsightIntentEntry'; -export const COMPONENT_USER_INTENTS_DECORATOR_FUNCTION: string = '@InsightIntentFunction'; -export const COMPONENT_USER_INTENTS_DECORATOR_METHOD: string = '@InsightIntentFunctionMethod'; -export const COMPONENT_USER_INTENTS_DECORATOR_ENTITY: string = '@InsightIntentEntity'; -export const COMPONENT_USER_INTENTS_DECORATOR_FORM: string = '@InsightIntentForm'; export const CHECK_COMPONENT_EXTEND_DECORATOR: string = 'Extend'; export const STRUCT_CONTEXT_METHOD_DECORATORS: Set = new Set([COMPONENT_BUILDER_DECORATOR, COMPONENT_STYLES_DECORATOR, COMPONENT_LOCAL_BUILDER_DECORATOR]); diff --git a/compiler/src/userIntents_parser/intentType.ts b/compiler/src/userIntents_parser/intentType.ts index 9ac1f7fdf9ac0088ef700ed0779fd5fd378761ed..4babcbd76d86532a45b4eeed328ab18fd3a89cb2 100644 --- a/compiler/src/userIntents_parser/intentType.ts +++ b/compiler/src/userIntents_parser/intentType.ts @@ -227,13 +227,14 @@ intentEntryInfoChecker.paramValidators = { executeMode(v: ts.Expression): boolean { return v !== undefined && v !== null && ts.isArrayLiteralExpression(v) && v.elements.every(e => { + const enumValue: string = e?.getText().split('.').pop(); const validModes = [ - 'insightIntent.ExecuteMode.UI_ABILITY_FOREGROUND', - 'insightIntent.ExecuteMode.UI_ABILITY_BACKGROUND', - 'insightIntent.ExecuteMode.UI_EXTENSION_ABILITY', - 'insightIntent.ExecuteMode.SERVICE_EXTENSION_ABILITY' + 'UI_ABILITY_FOREGROUND', + 'UI_ABILITY_BACKGROUND', + 'UI_EXTENSION_ABILITY', + 'SERVICE_EXTENSION_ABILITY' ]; - return (ts.isNumericLiteral(e) && [0, 1, 2, 3].includes(Number(e.text))) || validModes.includes(e.getText()); + return (ts.isNumericLiteral(e) && [0, 1, 2, 3].includes(Number(e.text))) || validModes.includes(enumValue); }); }, intentName: validateRequiredString, diff --git a/compiler/src/userIntents_parser/parseUserIntents.ts b/compiler/src/userIntents_parser/parseUserIntents.ts index 1b8e021778f9541fc141709da7fa848686dbace0..418b9804dd16ef162aeb259f2182ace4e4819817 100644 --- a/compiler/src/userIntents_parser/parseUserIntents.ts +++ b/compiler/src/userIntents_parser/parseUserIntents.ts @@ -34,7 +34,7 @@ import fs from 'fs'; import json5 from 'json5'; import { ProjectCollections } from 'arkguard'; import { - COMPONENT_USER_INTENTS_DECORATOR, + COMPONENT_USER_INTENTS_DECORATOR_LINK, COMPONENT_USER_INTENTS_DECORATOR_ENTITY, COMPONENT_USER_INTENTS_DECORATOR_ENTRY, COMPONENT_USER_INTENTS_DECORATOR_FUNCTION, @@ -44,7 +44,7 @@ import { } from '../pre_define'; import { CompileEvent, createAndStartEvent, stopEvent } from '../performance'; import {emitLogInfo, getTransformLog, LogInfo, LogType} from '../utils'; -import {ABILITY_SUBSYSTEM_CODE} from '../../lib/hvigor_error_code/hvigor_error_info'; +import {ABILITY_SUBSYSTEM_CODE} from '../hvigor_error_code/hvigor_error_info'; import {resetLog, transformLog} from '../process_ui_syntax'; type StaticValue = string | number | boolean | null | undefined | StaticValue[] | { [key: string]: StaticValue }; @@ -110,7 +110,7 @@ class ParseIntent { node: ts.ClassDeclaration, metaInfo: object, filePath: string, eventOrEventFactory: CompileEvent | undefined, transformLog: LogInfo[]): ts.Node { this.initInsightIntent(node, metaInfo, transformLog, filePath); const eventParseIntentTime: CompileEvent | undefined = createAndStartEvent(eventOrEventFactory, 'parseIntentTime'); - const definedDecorators: string[] = [COMPONENT_USER_INTENTS_DECORATOR, COMPONENT_USER_INTENTS_DECORATOR_ENTRY, + const definedDecorators: string[] = [COMPONENT_USER_INTENTS_DECORATOR_LINK, COMPONENT_USER_INTENTS_DECORATOR_ENTRY, COMPONENT_USER_INTENTS_DECORATOR_FUNCTION, COMPONENT_USER_INTENTS_DECORATOR_PAGE, COMPONENT_USER_INTENTS_DECORATOR_ENTITY, COMPONENT_USER_INTENTS_DECORATOR_FORM]; if (ts.isClassDeclaration(node) && !this.hasDecorator(node, [COMPONENT_USER_INTENTS_DECORATOR_FUNCTION])) { @@ -183,6 +183,16 @@ class ParseIntent { }); return; } + if (!projectConfig.pkgContextInfo) { + const errorMessage: string = 'Failed to generate standard OHMUrl.'; + this.transformLog.push({ + type: LogType.ERROR, message: errorMessage, pos: this.currentNode.getStart(), + code: '10111027', + description: 'InsightIntent Compiler Error', + solutions: ['Set useNormalizedOHMUrl to true in build-profile.json5'] + }); + return; + } const pkgParams: object = { pkgName: metaInfo.pkgName, pkgPath: metaInfo.pkgPath @@ -211,16 +221,6 @@ class ParseIntent { if (!isGlobalPathFlag) { return; } - if (!projectConfig.pkgContextInfo) { - const errorMessage: string = 'Failed to generate standard OHMUrl.'; - this.transformLog.push({ - type: LogType.ERROR, message: errorMessage, pos: this.currentNode.getStart(), - code: '10111027', - description: 'InsightIntent Compiler Error', - solutions: ['Set useNormalizedOHMUrl to true in build-profile.json5'] - }); - return; - } const Logger: IntentLogger = IntentLogger.getInstance(); const recordName: string = getNormalizedOhmUrlByFilepath(filepath, projectConfig, Logger, pkgParams, null); const intentObj: object = { @@ -228,7 +228,7 @@ class ParseIntent { 'decoratorClass': node.name.text }; const originalDecorator: string = '@' + decorator.expression.expression.getText(); - if (originalDecorator === COMPONENT_USER_INTENTS_DECORATOR) { + if (originalDecorator === COMPONENT_USER_INTENTS_DECORATOR_LINK) { this.handleLinkDecorator(intentObj, node, decorator); } else if (originalDecorator === COMPONENT_USER_INTENTS_DECORATOR_ENTRY) { this.handleEntryDecorator(intentObj, node, decorator, pkgParams); @@ -427,7 +427,7 @@ class ParseIntent { Object.assign(intentObj, { 'bundleName': projectConfig.bundleName, 'moduleName': projectConfig.moduleName, - 'decoratorType': COMPONENT_USER_INTENTS_DECORATOR + 'decoratorType': COMPONENT_USER_INTENTS_DECORATOR_LINK }); this.createObfuscation(node); if (this.isUpdateCompile) { @@ -572,14 +572,14 @@ class ParseIntent { if (!projectConfig.modulePathMap) { return; } - const jsonStr: string = fs.readFileSync(moduleJsonPath, 'utf8'); - const obj: object = json5.parse(jsonStr); - if (obj.module?.abilities) { - this.moduleJsonInfo.set('abilities', obj.module.abilities); - } - if (obj.module?.extensionAbilities) { - this.moduleJsonInfo.set('extensionAbilities', obj.module.extensionAbilities); - } + const jsonStr: string = fs.readFileSync(moduleJsonPath, 'utf8'); + const obj: object = json5.parse(jsonStr); + if (obj.module?.abilities) { + this.moduleJsonInfo.set('abilities', obj.module.abilities); + } + if (obj.module?.extensionAbilities) { + this.moduleJsonInfo.set('extensionAbilities', obj.module.extensionAbilities); + } } private validatePagePath(intentObj: object, pkgParams: object): void { @@ -1675,7 +1675,7 @@ class ParseIntent { } } catch (e) { const errorMessage: string = `Failed to write to the intent configuration file.`; - this.transformLog.push({ + transformLog.errors.push({ type: LogType.ERROR, message: errorMessage, pos: this.currentNode.getStart(), code: '10110025', description: 'InsightIntent Compiler Error', @@ -1836,7 +1836,7 @@ class ParseIntent { writeJsonData.extractInsightIntents?.forEach(item => { if (duplicates.has(item.intentName)) { const errorMessage: string = `Duplicate intentName definitions found.`; - this.transformLog.push({ + transformLog.errors.push({ type: LogType.ERROR, message: errorMessage, pos: this.currentNode.getStart(),