diff --git a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts index f4cf60e595075e2ec4abce2f57082105a178addb..8f0e19096c58b10c7b25eb675f08ef6a2a1f9f3f 100644 --- a/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts +++ b/compiler/src/fast_build/ets_ui/rollup-plugin-ets-typescript.ts @@ -233,7 +233,7 @@ export function etsTransform() { const eventEtsTransformAfterBuildEnd = createAndStartEvent(hookEventFactory, 'etsTransformafterBuildEnd'); const harIntentDataObj: object = parseIntent.getHarData(); if (parseIntent.intentData.length > 0 || parseIntent.isUpdateCompile || Object.keys(harIntentDataObj).length !== 0) { - parseIntent.writeUserIntentJsonFile(harIntentDataObj); + parseIntent.writeUserIntentJsonFile(harIntentDataObj, this.share); } // Copy the cache files in the compileArkTS directory to the loader_out directory if (projectConfig.compileHar && !projectConfig.byteCodeHar) { diff --git a/compiler/src/hvigor_error_code/hvigor_error_info.ts b/compiler/src/hvigor_error_code/hvigor_error_info.ts index bb70bbae954ccb57d590ca9a7b6512cc4399058b..2f58c2e1c943609d18bc87b84ace13c852898e6c 100644 --- a/compiler/src/hvigor_error_code/hvigor_error_info.ts +++ b/compiler/src/hvigor_error_code/hvigor_error_info.ts @@ -16,6 +16,7 @@ export const ERROR_DESCRIPTION = 'ArkTS Compiler Error'; export const ARKUI_SUBSYSTEM_CODE = '109'; // ArkUI subsystem coding export const LINTER_SUBSYSTEM_CODE = '106'; // Linter subsystem coding +export const ABILITY_SUBSYSTEM_CODE = '101'; // Ability subsystem coding export const ERROR_TYPE_CODE = '05'; // Error Type Code export const EXTENSION_CODE = '999'; // Extended Codes Defined by Various Subsystems diff --git a/compiler/src/interop/src/ets_checker.ts b/compiler/src/interop/src/ets_checker.ts index 2c07e13e11cb360830882ad409d246166cae95bc..60e976613f7cb21764c33968c2fedf97c5f4fb91 100644 --- a/compiler/src/interop/src/ets_checker.ts +++ b/compiler/src/interop/src/ets_checker.ts @@ -330,7 +330,7 @@ function createHash(str: string): string { export function getFileContentWithHash(fileName: string): string { let fileContent: string | undefined = fileCache.get(fileName); - if (fileContent === undefined) { + if (fileContent === undefined) { fileContent = fs.readFileSync(fileName).toString(); fileCache.set(fileName, fileContent); // Provide the hash value for hvigor's remote cache, and let them handle the cleanup. @@ -368,7 +368,7 @@ let setHashValueByFilePath: Function | undefined = undefined; let getHashByFilePath: Function | undefined = undefined; export function createLanguageService(rootFileNames: string[], resolveModulePaths: string[], - parentEvent?: CompileEvent, rollupShareObject?: any): ts.LanguageService { + parentEvent?: CompileEvent, rollupShareObject?: Object): ts.LanguageService { setHashValueByFilePath = rollupShareObject?.setHashValueByFilePath; getHashByFilePath = rollupShareObject?.getHashByFilePath; setCompilerOptions(resolveModulePaths); @@ -469,9 +469,9 @@ function getOrCreateLanguageService(servicesHost: ts.LanguageServiceHost, rootFi const tsImportSendableDiff: boolean = (cache?.preTsImportSendable === undefined && !tsImportSendable) ? false : cache?.preTsImportSendable !== tsImportSendable; - const skipOhModulesLintDiff: boolean = (cache?.preSkipOhModulesLint === undefined && !skipOhModulesLint) ? + const skipOhModulesLintDiff: boolean = (cache?.preSkipOhModulesLint === undefined && !skipOhModulesLint) ? false : cache?.preSkipOhModulesLint !== skipOhModulesLint; - const mixCompileDiff: boolean = (cache?.preMixCompile === undefined && !mixCompile) ? + const mixCompileDiff: boolean = (cache?.preMixCompile === undefined && !mixCompile) ? false : cache?.preMixCompile !== mixCompile; const shouldRebuild: boolean | undefined = shouldRebuildForDepDiffers || targetESVersionDiffers || tsImportSendableDiff || maxFlowDepthDiffers || skipOhModulesLintDiff || mixCompileDiff; @@ -633,7 +633,7 @@ export function serviceChecker(rootFileNames: string[], newLogger: Object = null maxMemoryInServiceChecker = process.memoryUsage().heapUsed; // Release the typeChecker early and perform GC in the following scenarios: - // In memory-priority mode or default mode, when the preview mode is disabled in a full compilation scenario, + // In memory-priority mode or default mode, when the preview mode is disabled in a full compilation scenario, // and it is not a preview, hot reload, or cold reload scenario. The typeChecker is not released early in performance-priority mode. let shouldReleaseTypeChecker: boolean = rollupShareObject?.projectConfig?.executionMode !== 'performance' && globalProgram.program && process.env.watchMode !== 'true' && !projectConfig.isPreview && !projectConfig.hotReload && !projectConfig.coldReload; @@ -955,7 +955,7 @@ function printErrorCode(diagnostic: ts.Diagnostic, etsCheckerLogger: Object, } // Check for TSC error codes - if (flag === ErrorCodeModule.TSC && + if (flag === ErrorCodeModule.TSC && validateUseErrorCodeLogger(ErrorCodeModule.TSC, diagnostic.code)) { const errorCode = ts.getErrorCode(diagnostic); errorCodeLogger.printError(errorCode); @@ -963,7 +963,7 @@ function printErrorCode(diagnostic: ts.Diagnostic, etsCheckerLogger: Object, } // Check for LINTER error codes - if (flag === ErrorCodeModule.LINTER || (flag === ErrorCodeModule.TSC && + if (flag === ErrorCodeModule.LINTER || (flag === ErrorCodeModule.TSC && validateUseErrorCodeLogger(ErrorCodeModule.LINTER, diagnostic.code))) { const linterErrorInfo: HvigorErrorInfo = transfromErrorCode(diagnostic.code, positionMessage, message); errorCodeLogger.printError(linterErrorInfo); @@ -971,7 +971,7 @@ function printErrorCode(diagnostic: ts.Diagnostic, etsCheckerLogger: Object, } // Check for ArkUI error codes - if (flag === ErrorCodeModule.UI || (flag === ErrorCodeModule.TSC && + if (flag === ErrorCodeModule.UI || (flag === ErrorCodeModule.TSC && validateUseErrorCodeLogger(ErrorCodeModule.UI, diagnostic.code))) { const uiErrorInfo: HvigorErrorInfo | undefined = buildErrorInfoFromDiagnostic( diagnostic.code, positionMessage, message); diff --git a/compiler/src/interop/src/process_kit_import.ts b/compiler/src/interop/src/process_kit_import.ts index 8ffeabec5d9db06895bd2338a6300e45495a3a09..f5c445e0fb77edf872bdbf5d45c399736097de25 100644 --- a/compiler/src/interop/src/process_kit_import.ts +++ b/compiler/src/interop/src/process_kit_import.ts @@ -40,8 +40,8 @@ import { createAndStartEvent, stopEvent } from './performance'; -import { - ArkTSErrorDescription, +import { + ArkTSErrorDescription, ErrorCode } from './fast_build/ark_compiler/error_code'; import { @@ -225,10 +225,10 @@ class SpecificerInfo { const errInfo: LogData = LogDataFactory.newInstance( ErrorCode.ETS2BUNDLE_EXTERNAL_IDENTIFIER_IMPORT_NOT_ALLOWED_IN_TS_FILE, ArkTSErrorDescription, - `Identifier '${this.importName}' comes from '${this.symbol.source}' ` + + `Identifier '${this.importName}' comes from '${this.symbol.source}' ` + 'which can not be imported in .ts file.', '', - ["Please remove the import statement or change the file extension to .ets."] + ['Please remove the import statement or change the file extension to .ets.'] ); kitTransformLog.errors.push({ type: LogType.ERROR, @@ -501,7 +501,7 @@ class NameSpaceKitInfo extends KitInfo { ArkTSErrorDescription, 'Namespace import or export of Kit is not supported currently.', '', - ['Please namespace import or export of Kit replace it with named import or export instead. ' + + ['Please namespace import or export of Kit replace it with named import or export instead. ' + 'For example, import * as ArkTS from "@kit.ArkUI"; -> import { AlertDialog } from "@kit.ArkUI";'] ); kitTransformLog.errors.push({ @@ -583,10 +583,10 @@ class EmptyImportKitInfo extends KitInfo { const errInfo: LogData = LogDataFactory.newInstance( ErrorCode.ETS2BUNDLE_EXTERNAL_EMPTY_IMPORT_NOT_ALLOWED_WITH_KIT, ArkTSErrorDescription, - `Can not use empty import(side-effect import) statement with Kit ` + + `Can not use empty import(side-effect import) statement with Kit ` + `'${(kitNode.moduleSpecifier as ts.StringLiteral).text.replace(/'|"/g, '')}'.`, '', - ['Please specify imported symbols explicitly. ' + + ['Please specify imported symbols explicitly. ' + 'For example, import "@kit.ArkUI"; -> import { lang } from "@kit.ArkUI";'] ); kitTransformLog.errors.push({ diff --git a/compiler/src/process_kit_import.ts b/compiler/src/process_kit_import.ts index 8ffeabec5d9db06895bd2338a6300e45495a3a09..f5c445e0fb77edf872bdbf5d45c399736097de25 100644 --- a/compiler/src/process_kit_import.ts +++ b/compiler/src/process_kit_import.ts @@ -40,8 +40,8 @@ import { createAndStartEvent, stopEvent } from './performance'; -import { - ArkTSErrorDescription, +import { + ArkTSErrorDescription, ErrorCode } from './fast_build/ark_compiler/error_code'; import { @@ -225,10 +225,10 @@ class SpecificerInfo { const errInfo: LogData = LogDataFactory.newInstance( ErrorCode.ETS2BUNDLE_EXTERNAL_IDENTIFIER_IMPORT_NOT_ALLOWED_IN_TS_FILE, ArkTSErrorDescription, - `Identifier '${this.importName}' comes from '${this.symbol.source}' ` + + `Identifier '${this.importName}' comes from '${this.symbol.source}' ` + 'which can not be imported in .ts file.', '', - ["Please remove the import statement or change the file extension to .ets."] + ['Please remove the import statement or change the file extension to .ets.'] ); kitTransformLog.errors.push({ type: LogType.ERROR, @@ -501,7 +501,7 @@ class NameSpaceKitInfo extends KitInfo { ArkTSErrorDescription, 'Namespace import or export of Kit is not supported currently.', '', - ['Please namespace import or export of Kit replace it with named import or export instead. ' + + ['Please namespace import or export of Kit replace it with named import or export instead. ' + 'For example, import * as ArkTS from "@kit.ArkUI"; -> import { AlertDialog } from "@kit.ArkUI";'] ); kitTransformLog.errors.push({ @@ -583,10 +583,10 @@ class EmptyImportKitInfo extends KitInfo { const errInfo: LogData = LogDataFactory.newInstance( ErrorCode.ETS2BUNDLE_EXTERNAL_EMPTY_IMPORT_NOT_ALLOWED_WITH_KIT, ArkTSErrorDescription, - `Can not use empty import(side-effect import) statement with Kit ` + + `Can not use empty import(side-effect import) statement with Kit ` + `'${(kitNode.moduleSpecifier as ts.StringLiteral).text.replace(/'|"/g, '')}'.`, '', - ['Please specify imported symbols explicitly. ' + + ['Please specify imported symbols explicitly. ' + 'For example, import "@kit.ArkUI"; -> import { lang } from "@kit.ArkUI";'] ); kitTransformLog.errors.push({ diff --git a/compiler/src/userIntents_parser/parseUserIntents.ts b/compiler/src/userIntents_parser/parseUserIntents.ts index 0c15514a707210c30badc9884c8ceae7b3194580..591a93599b2f99837431e585969e84e30f29cbed 100644 --- a/compiler/src/userIntents_parser/parseUserIntents.ts +++ b/compiler/src/userIntents_parser/parseUserIntents.ts @@ -43,7 +43,9 @@ import { COMPONENT_USER_INTENTS_DECORATOR_FORM } from '../pre_define'; import { CompileEvent, createAndStartEvent, stopEvent } from '../performance'; -import { LogInfo, LogType } from '../utils'; +import {emitLogInfo, getTransformLog, LogInfo, LogType} from '../utils'; +import {ABILITY_SUBSYSTEM_CODE} from '../../lib/hvigor_error_code/hvigor_error_info'; +import {resetLog, transformLog} from '../process_ui_syntax'; type StaticValue = string | number | boolean | null | undefined | StaticValue[] | { [key: string]: StaticValue }; @@ -1617,7 +1619,7 @@ class ParseIntent { } // This method writes the parsed data to a file. - public writeUserIntentJsonFile(harIntentDataObj: object): void { + public writeUserIntentJsonFile(harIntentDataObj: object, share: object): void { const cachePath: string = path.join(projectConfig.cachePath, 'insight_compile_cache.json'); // Compiled cache file if (!(fs.existsSync(cachePath) || this.intentData.length > 0 || Object.keys(harIntentDataObj).length !== 0)) { @@ -1657,6 +1659,12 @@ class ParseIntent { }); return; } + const logger = share.getLogger('etsTransform'); + const hvigorLogger = share.getHvigorConsoleLogger?.(ABILITY_SUBSYSTEM_CODE); + if (transformLog && transformLog.errors.length && !projectConfig.ignoreWarning) { + emitLogInfo(logger, getTransformLog(transformLog), true, this.currentFilePath, hvigorLogger); + resetLog(); + } } private processIntentData(harIntentDataObj: object): object { diff --git a/compiler/test/ark_compiler_ut/common/process_kit_import.test.ts b/compiler/test/ark_compiler_ut/common/process_kit_import.test.ts index 2c9bc8c69585c5b581696e8c0d85ae7c56916d58..7e4d2ac85c199c4fde7a82cfb7d504c21702fd16 100644 --- a/compiler/test/ark_compiler_ut/common/process_kit_import.test.ts +++ b/compiler/test/ark_compiler_ut/common/process_kit_import.test.ts @@ -25,7 +25,7 @@ import { KitInfo } from '../../../lib/process_kit_import'; import { findImportSpecifier } from '../utils/utils'; -import { +import { ArkTSErrorDescription, ErrorCode } from '../../../lib/fast_build/ark_compiler/error_code'; @@ -78,14 +78,14 @@ const KIT_STAR_EXPORT_CODE_EXPECT: string = const KIT_IMPORT_ERROR_CODE: string = 'import { Ability } from "@kit.Kit";' -const KIT_UNUSED_TYPE_IMPROT_CODE: string = +const KIT_UNUSED_TYPE_IMPROT_CODE: string = 'import { BusinessError } from "@kit.BasicServicesKit";' const KIT_UNUSED_TYPE_IMPROT_CODE_EXPECT: string = 'export {};\n' + '//# sourceMappingURL=kitTest.js.map' -const KIT_USED_TYPE_IMPROT_CODE: string = +const KIT_USED_TYPE_IMPROT_CODE: string = 'import { BusinessError } from "@kit.BasicServicesKit";\n' + 'let e: BusinessError = undefined'; @@ -392,7 +392,7 @@ mocha.describe('process Kit Imports tests', function () { ArkTSErrorDescription, "Can not use empty import(side-effect import) statement with Kit '@kit.ArkUI'.", '', - ['Please specify imported symbols explicitly. ' + + ['Please specify imported symbols explicitly. ' + 'For example, import "@kit.ArkUI"; -> import { lang } from "@kit.ArkUI";'] ); const hasError = kitTransformLog.errors.some(error => @@ -434,7 +434,7 @@ mocha.describe('process Kit Imports tests', function () { ArkTSErrorDescription, 'Namespace import or export of Kit is not supported currently.', '', - ['Please namespace import or export of Kit replace it with named import or export instead. ' + + ['Please namespace import or export of Kit replace it with named import or export instead. ' + 'For example, import * as ArkTS from "@kit.ArkUI"; -> import { AlertDialog } from "@kit.ArkUI";'] ); const hasError = kitTransformLog.errors.some(error => @@ -464,10 +464,10 @@ mocha.describe('process Kit Imports tests', function () { const errInfo: LogData = LogDataFactory.newInstance( ErrorCode.ETS2BUNDLE_EXTERNAL_IDENTIFIER_IMPORT_NOT_ALLOWED_IN_TS_FILE, ArkTSErrorDescription, - "Identifier 'test' comes from '@ohos.test.d.ets' " + + "Identifier 'test' comes from '@ohos.test.d.ets' " + 'which can not be imported in .ts file.', '', - ["Please remove the import statement or change the file extension to .ets."] + ['Please remove the import statement or change the file extension to .ets.'] ); const hasError = kitTransformLog.errors.some(error => error.message.includes(errInfo.toString())