From 7a37093198867cf390d151f12757ac2046df2ab3 Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Sun, 13 Mar 2022 18:16:02 +0800 Subject: [PATCH] houhaoyu@huawei.com ignore module error Signed-off-by: houhaoyu Change-Id: Id97e6c2e7a0aafbde07d0683f7ba4a54b835b2bf --- compiler/src/compile_info.ts | 12 ++++++++++-- compiler/src/ets_checker.ts | 1 + compiler/src/pre_define.ts | 2 +- compiler/src/validate_ui_syntax.ts | 4 ++++ 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/compiler/src/compile_info.ts b/compiler/src/compile_info.ts index a086d8a40..50cf43f1d 100644 --- a/compiler/src/compile_info.ts +++ b/compiler/src/compile_info.ts @@ -38,7 +38,8 @@ import { dollarCollection, appComponentCollection, decoratorParamsCollection, - extendCollection + extendCollection, + importModuleCollection } from './ets_checker'; configure({ @@ -286,13 +287,20 @@ export class ResultStates { private validateError(message: string): boolean { const propInfoReg: RegExp = /Cannot find name\s*'(\$?\$?[_a-zA-Z0-9]+)'/; const stateInfoReg: RegExp = /Property\s*'(\$?[_a-zA-Z0-9]+)' does not exist on type/; + const importInfoReg: RegExp = /Cannot find namespace\s*'([_a-zA-Z0-9]+)'\./; if (this.matchMessage(message, props, propInfoReg) || - this.matchMessage(message, props, stateInfoReg)) { + this.matchMessage(message, props, stateInfoReg) || + this.matchMessage(message, [...importModuleCollection], importInfoReg)) { return false; } return true; } private matchMessage(message: string, nameArr: any, reg: RegExp): boolean { + importModuleCollection.forEach(item => { + if (message.includes(item)) { + return true; + } + }) if (reg.test(message)) { const match: string[] = message.match(reg); if (match[1] && nameArr.includes(match[1])) { diff --git a/compiler/src/ets_checker.ts b/compiler/src/ets_checker.ts index cab0eead8..21f32f5bf 100644 --- a/compiler/src/ets_checker.ts +++ b/compiler/src/ets_checker.ts @@ -134,6 +134,7 @@ export const dollarCollection: Set = new Set(); export const appComponentCollection: Set = new Set(); export const decoratorParamsCollection: Set = new Set(); export const extendCollection: Set = new Set(); +export const importModuleCollection: Set = new Set(); function checkUISyntax(source: string, fileName: string): void { if (/\.ets$/.test(fileName)) { diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index ff3a07212..d746eedd0 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -17,7 +17,7 @@ import path from 'path'; export const NATIVE_MODULE: Set = new Set( ['system.app', 'ohos.app', 'system.router', 'system.curves', 'ohos.curves', 'system.matrix4', 'ohos.matrix4']); -export const VALIDATE_MODULE: string[] = ['application', 'util', 'screen']; +export const VALIDATE_MODULE: string[] = ['application', 'util', 'screen', 'mediaquery']; export const SYSTEM_PLUGIN: string = 'system'; export const OHOS_PLUGIN: string = 'ohos'; diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index f47383a0a..882859c5f 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -61,6 +61,7 @@ import { } from './utils'; import { projectConfig } from '../main'; import { collectExtend } from './process_ui_syntax'; +import { importModuleCollection } from "./ets_checker"; export interface ComponentCollection { entryComponent: string; @@ -748,6 +749,9 @@ export function processSystemApi(content: string, isProcessWhiteList: boolean = let moduleType: string = item2 || item5; let systemKey: string = item3 || item6; let systemValue: string = item1 || item4; + if (!VALIDATE_MODULE.includes(systemValue)){ + importModuleCollection.add(systemValue); + } if (!isProcessWhiteList && validateWhiteListModule(moduleType, systemKey)) { return item; } else if (isProcessWhiteList) { -- Gitee