From 262999cc896935a616f360f6a503f9f4df9a843a Mon Sep 17 00:00:00 2001 From: laibo102 Date: Thu, 20 Jan 2022 16:34:31 +0800 Subject: [PATCH 1/6] laibo2@huawei.com Signed-off-by: laibo102 Change-Id: I4b388ae2f970ce47ae96beb44b8acadb85323995 --- compiler/src/validate_ui_syntax.ts | 33 +++++++++++++++++++++++++----- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index c57d75f02..4020ea607 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -802,11 +802,17 @@ function collectExtend(component: string, attribute: string, parameter: string): export function processSystemApi(content: string, isProcessWhiteList: boolean = false): string { let REG_SYSTEM: RegExp; - REG_SYSTEM = - /import\s+(.+)\s+from\s+['"]@(system|ohos)\.(\S+)['"]|import\s+(.+)\s*=\s*require\(\s*['"]@(system|ohos)\.(\S+)['"]\s*\)/g; + if (isProcessWhiteList) { + REG_SYSTEM = + /(import|const)\s+(.+)\s*=\s*(\_\_importDefault\()?require\(\s*['"]@(system|ohos)\.(\S+)['"]\s*\)(\))?/g; + } else { + REG_SYSTEM = + /import\s+(.+)\s+from\s+['"]@(system|ohos)\.(\S+)['"]|import\s+(.+)\s*=\s*require\(\s*['"]@(system|ohos)\.(\S+)['"]\s*\)/g; + } const REG_LIB_SO: RegExp = /import\s+(.+)\s+from\s+['"]lib(\S+)\.so['"]|import\s+(.+)\s*=\s*require\(\s*['"]lib(\S+)\.so['"]\s*\)/g; - return content.replace(REG_LIB_SO, (_, item1, item2, item3, item4) => { + const systemValueCollection: Set = new Set(); + let newContent = content.replace(REG_LIB_SO, (_, item1, item2, item3, item4) => { const libSoValue: string = item1 || item3; const libSoKey: string = item2 || item4; return `var ${libSoValue} = globalThis.requireNapi("${libSoKey}", true);`; @@ -814,6 +820,14 @@ export function processSystemApi(content: string, isProcessWhiteList: boolean = let moduleType: string = item2 || item5; let systemKey: string = item3 || item6; let systemValue: string = item1 || item4; + if (!isProcessWhiteList && validateWhiteListModule(moduleType, systemKey)) { + return item; + } else if (isProcessWhiteList) { + systemValue = item2; + moduleType = item4; + systemKey = item5; + systemValueCollection.add(systemValue) + } moduleCollection.add(`${moduleType}.${systemKey}`); if (NATIVE_MODULE.has(`${moduleType}.${systemKey}`)) { item = `var ${systemValue} = globalThis.requireNativeModule('${moduleType}.${systemKey}')`; @@ -827,11 +841,20 @@ export function processSystemApi(content: string, isProcessWhiteList: boolean = `? globalThis.systemplugin.${systemKey} : undefined)`; } return item; - }); + }) + + systemValueCollection.forEach(element => { + let target: string = element.trim()+'.default' + console.log(target); + while(newContent.includes(target)) { + newContent = newContent.replace(target,element.trim()) + } + }); + return newContent } function validateWhiteListModule(moduleType: string, systemKey: string): boolean { - return moduleType === 'ohos' && /^application\./g.test(systemKey); + return moduleType === 'ohos' && /^(application|util)\./g.test(systemKey); } export function resetComponentCollection() { -- Gitee From de91ac33320bdbaee563c27be582b136a6205b64 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Thu, 20 Jan 2022 16:44:54 +0800 Subject: [PATCH 2/6] laibo2@huawei.com Signed-off-by: laibo102 Change-Id: I4e3b2c95bba4f2c74b3616315ba48c92d52ee118 --- compiler/src/validate_ui_syntax.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index 4020ea607..4778eccfd 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -845,7 +845,6 @@ export function processSystemApi(content: string, isProcessWhiteList: boolean = systemValueCollection.forEach(element => { let target: string = element.trim()+'.default' - console.log(target); while(newContent.includes(target)) { newContent = newContent.replace(target,element.trim()) } -- Gitee From 1b9fe5b3556292d418a22dbf23f5034daada4f7f Mon Sep 17 00:00:00 2001 From: laibo102 Date: Fri, 21 Jan 2022 16:21:33 +0800 Subject: [PATCH 3/6] laibo2@huawei.com Signed-off-by: laibo102 Change-Id: Ie07f1cd722c572f2c4bcae55ca4b4d4a53e4f7d7 --- compiler/src/pre_define.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index 33f4f2115..f25e53687 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -17,6 +17,8 @@ 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: Set = new Set( + ['application', 'util']); export const SYSTEM_PLUGIN: string = 'system'; export const OHOS_PLUGIN: string = 'ohos'; @@ -193,3 +195,4 @@ export const $$_VALUE: string = 'value'; export const $$_CHANGE_EVENT: string = 'changeEvent'; export const $$_THIS: string = '$$this'; export const $$_NEW_VALUE: string = 'newValue'; + -- Gitee From 6e188ea7046f07c2d164c35442f3d2afde500176 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Fri, 21 Jan 2022 16:21:45 +0800 Subject: [PATCH 4/6] laibo2@huawei.com Signed-off-by: laibo102 Change-Id: Ice73cc30b98e5eb25e7ac41aa58c8ee15813b448 --- compiler/src/validate_ui_syntax.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index 4778eccfd..01213dbf3 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -43,7 +43,8 @@ import { COMPONENT_CONSTRUCTOR_PARAMS, COMPONENT_EXTEND_DECORATOR, COMPONENT_OBSERVED_DECORATOR, - STYLES + STYLES, + VALIDATE_MODULE } from './pre_define'; import { INNER_COMPONENT_NAMES, @@ -853,7 +854,12 @@ export function processSystemApi(content: string, isProcessWhiteList: boolean = } function validateWhiteListModule(moduleType: string, systemKey: string): boolean { - return moduleType === 'ohos' && /^(application|util)\./g.test(systemKey); + let validateTypeStr: string = '' + VALIDATE_MODULE.forEach(validate => { + validateTypeStr = validateTypeStr + validate + '|' + }) + let REG_SUFFIX = new RegExp('^(' + validateTypeStr + ')') + return moduleType === 'ohos' && REG_SUFFIX.test(systemKey); } export function resetComponentCollection() { -- Gitee From 5db36a1b82e61ff40328ca5ef0fce6cd24b3725e Mon Sep 17 00:00:00 2001 From: laibo102 Date: Fri, 21 Jan 2022 17:16:39 +0800 Subject: [PATCH 5/6] laibo2@huawei.com Signed-off-by: laibo102 Change-Id: I3ba0d4a620e32dcec50acb668cee5827ab284127 --- compiler/src/pre_define.ts | 3 +-- compiler/src/validate_ui_syntax.ts | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/compiler/src/pre_define.ts b/compiler/src/pre_define.ts index f25e53687..cca5bc3e1 100644 --- a/compiler/src/pre_define.ts +++ b/compiler/src/pre_define.ts @@ -17,8 +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: Set = new Set( - ['application', 'util']); +export const VALIDATE_MODULE: Set = new Set(['application', 'util']); 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 01213dbf3..d5547388a 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -845,21 +845,21 @@ export function processSystemApi(content: string, isProcessWhiteList: boolean = }) systemValueCollection.forEach(element => { - let target: string = element.trim()+'.default' + let target: string = element.trim()+'.default'; while(newContent.includes(target)) { - newContent = newContent.replace(target,element.trim()) - } + newContent = newContent.replace(target,element.trim()); + }; }); - return newContent + return newContent; } function validateWhiteListModule(moduleType: string, systemKey: string): boolean { - let validateTypeStr: string = '' - VALIDATE_MODULE.forEach(validate => { - validateTypeStr = validateTypeStr + validate + '|' - }) - let REG_SUFFIX = new RegExp('^(' + validateTypeStr + ')') - return moduleType === 'ohos' && REG_SUFFIX.test(systemKey); + let checkModuleStr: string = ''; + VALIDATE_MODULE.forEach(module => { + checkModuleStr = checkModuleStr + module + '|'; + }); + let REG_SUFFIX = new RegExp('^(' + checkModuleStr + ')'); + return moduleType === 'ohos' && REG_SUFFIX.test(systemKey ); } export function resetComponentCollection() { -- Gitee From dc9280e0495e86d573ede18bd92676d78d465c60 Mon Sep 17 00:00:00 2001 From: laibo102 Date: Fri, 21 Jan 2022 17:18:10 +0800 Subject: [PATCH 6/6] laibo2@huawei.com Signed-off-by: laibo102 Change-Id: I1c5086e70de937023dedabdd158c99a1e1d0718a --- compiler/src/validate_ui_syntax.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/validate_ui_syntax.ts b/compiler/src/validate_ui_syntax.ts index d5547388a..f6083625c 100644 --- a/compiler/src/validate_ui_syntax.ts +++ b/compiler/src/validate_ui_syntax.ts @@ -859,7 +859,7 @@ function validateWhiteListModule(moduleType: string, systemKey: string): boolean checkModuleStr = checkModuleStr + module + '|'; }); let REG_SUFFIX = new RegExp('^(' + checkModuleStr + ')'); - return moduleType === 'ohos' && REG_SUFFIX.test(systemKey ); + return moduleType === 'ohos' && REG_SUFFIX.test(systemKey); } export function resetComponentCollection() { -- Gitee