From 262999cc896935a616f360f6a503f9f4df9a843a Mon Sep 17 00:00:00 2001 From: laibo102 Date: Thu, 20 Jan 2022 16:34:31 +0800 Subject: [PATCH 1/2] 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/2] 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