From 17a579e44db1643471b28e27745932d3c5992309 Mon Sep 17 00:00:00 2001 From: houhaoyu Date: Wed, 20 Oct 2021 14:24:00 +0800 Subject: [PATCH] fixed f97c99a from https://gitee.com/houhaoyu/third_party_weex-loader/pulls/13 houhaoyu@huawei.com fix function more than 50 lines Signed-off-by: houhaoyu Change-Id: Ifa8187ee77360fda6e36a653db33f315c05d7a0f --- src/util.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/util.js b/src/util.js index b636b13..c2813cb 100644 --- a/src/util.js +++ b/src/util.js @@ -221,13 +221,13 @@ export function loadBabelModule (moduleName) { } } -export function parseRequireModule (source) { - const requireMethod = process.env.DEVICE_LEVEL === DEVICE_LEVEL.LITE ? +const methodForLite = ` function requireModule(moduleName) { return requireNative(moduleName.slice(1)); } -` : +` +const methodForOthers = ` function requireModule(moduleName) { const systemList = ['system.router', 'system.app', 'system.prompt', 'system.configuration', @@ -238,6 +238,10 @@ function requireModule(moduleName) { return target; } var shortName = moduleName.replace(/@[^.]+\.([^.]+)/, '$1'); + target = requireNapi(shortName); + if (target !== 'undefined' && /@ohos/.test(moduleName)) { + return target; + } if (typeof ohosplugin !== 'undefined' && /@ohos/.test(moduleName)) { target = ohosplugin; for (let key of shortName.split('.')) { @@ -262,11 +266,11 @@ function requireModule(moduleName) { return target; } } - target = requireNapi(shortName); return target; } ` - +export function parseRequireModule (source) { + const requireMethod = process.env.DEVICE_LEVEL === DEVICE_LEVEL.LITE ? methodForLite : methodForOthers source = `${source}\n${requireMethod}` const requireReg = /require\(['"]([^()]+)['"]\)/g const libReg = /^lib(.+)\.so$/ -- Gitee