From b058934a994df1f0440c09a013076b4534ec515c Mon Sep 17 00:00:00 2001 From: xuegan Date: Mon, 23 Dec 2024 20:44:44 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20processShowStyle=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=98=AF=E5=90=A6=E4=B8=BA=20virtualHost=20=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/template-compiler/compiler.js | 6 +++++- .../webpack-plugin/lib/utils/pre-process-json.js | 14 +++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/webpack-plugin/lib/template-compiler/compiler.js b/packages/webpack-plugin/lib/template-compiler/compiler.js index dbe300bf09..0ef6604340 100644 --- a/packages/webpack-plugin/lib/template-compiler/compiler.js +++ b/packages/webpack-plugin/lib/template-compiler/compiler.js @@ -2189,6 +2189,10 @@ function isComponentNode (el, options) { return usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component' } +function isVirtualHostNode (el, options) { + return options.usingComponentsInfo[el.tag]?.hvh +} + function isReactComponent (el, options) { return !isComponentNode(el, options) && isRealNode(el) && !el.isBuiltIn } @@ -2416,7 +2420,7 @@ function processShow (el, options, root) { show = has ? `{{${parseMustacheWithContext(show).result}&&mpxShow}}` : '{{mpxShow}}' } if (show === undefined) return - if (isComponentNode(el, options)) { + if (isComponentNode(el, options) && isVirtualHostNode(el, options)) { if (show === '') { show = '{{false}}' } diff --git a/packages/webpack-plugin/lib/utils/pre-process-json.js b/packages/webpack-plugin/lib/utils/pre-process-json.js index 0510cccf15..118afaf8e6 100644 --- a/packages/webpack-plugin/lib/utils/pre-process-json.js +++ b/packages/webpack-plugin/lib/utils/pre-process-json.js @@ -6,6 +6,7 @@ const addQuery = require('./add-query') const resolve = require('./resolve') const getJSONContent = require('./get-json-content') const getRulesRunner = require('../platform') +const { matchCondition } = require('./match-condition') const async = require('async') module.exports = function ({ @@ -19,8 +20,7 @@ module.exports = function ({ }, callback) { const mpx = loaderContext.getMpx() const context = loaderContext.context - const mode = mpx.mode - const pagesMap = mpx.pagesMap + const { mode, pagesMap, autoVirtualHostRules } = mpx async.waterfall([ (callback) => { getJSONContent(json, null, loaderContext, callback) @@ -78,8 +78,11 @@ module.exports = function ({ componentGenerics = Object.assign({}, ret.componentGenerics) } if (usingComponents) { - const setUsingComponentInfo = (name, moduleId) => { - usingComponentsInfo[name] = { mid: moduleId } + const setUsingComponentInfo = (name, moduleId, hasVirtualHost) => { + usingComponentsInfo[name] = { + mid: moduleId, + hvh: hasVirtualHost + } } async.eachOf(usingComponents, (component, name, callback) => { if (ctorType === 'app') { @@ -96,7 +99,8 @@ module.exports = function ({ if (err) return callback(err) const { rawResourcePath } = parseRequest(resource) const moduleId = mpx.getModuleId(rawResourcePath, ctorType === 'app') - setUsingComponentInfo(name, moduleId) + const hasVirtualHost = matchCondition(rawResourcePath, autoVirtualHostRules) + setUsingComponentInfo(name, moduleId, hasVirtualHost) callback() }) }, (err) => { From 730b39e31bc13841aea482f460d8e3927cedbaf2 Mon Sep 17 00:00:00 2001 From: xuegan Date: Tue, 24 Dec 2024 14:15:31 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9virtualHost?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E4=B8=BAgetCompnoentInfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/template-compiler/compiler.js | 21 ++++++++++--------- .../lib/utils/pre-process-json.js | 12 +++++------ 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/packages/webpack-plugin/lib/template-compiler/compiler.js b/packages/webpack-plugin/lib/template-compiler/compiler.js index 0ef6604340..022d5fc01a 100644 --- a/packages/webpack-plugin/lib/template-compiler/compiler.js +++ b/packages/webpack-plugin/lib/template-compiler/compiler.js @@ -117,6 +117,7 @@ let hasOptionalChaining = false let processingTemplate = false const rulesResultMap = new Map() let usingComponents = [] +let usingComponentsInfo = {} function updateForScopesMap () { forScopesMap = {} @@ -636,6 +637,7 @@ function parse (template, options) { if (typeof options.usingComponentsInfo === 'string') options.usingComponentsInfo = JSON.parse(options.usingComponentsInfo) usingComponents = Object.keys(options.usingComponentsInfo) + usingComponentsInfo = options.usingComponentsInfo const _warn = content => { const currentElementRuleResult = rulesResultMap.get(currentEl) || rulesResultMap.set(currentEl, { @@ -2185,20 +2187,20 @@ function isRealNode (el) { return !virtualNodeTagMap[el.tag] } -function isComponentNode (el, options) { +function isComponentNode (el) { return usingComponents.indexOf(el.tag) !== -1 || el.tag === 'component' } -function isVirtualHostNode (el, options) { - return options.usingComponentsInfo[el.tag]?.hvh +function getComponentInfo (el) { + return usingComponentsInfo[el.tag] || {} } -function isReactComponent (el, options) { - return !isComponentNode(el, options) && isRealNode(el) && !el.isBuiltIn +function isReactComponent (el) { + return !isComponentNode(el) && isRealNode(el) && !el.isBuiltIn } function processExternalClasses (el, options) { - const isComponent = isComponentNode(el, options) + const isComponent = isComponentNode(el) const classLikeAttrNames = isComponent ? ['class'].concat(options.externalClasses) : ['class'] classLikeAttrNames.forEach((classLikeAttrName) => { @@ -2312,8 +2314,7 @@ function postProcessAliComponentRootView (el, options, meta) { { condition: /^style$/, action: 'move' }, { condition: /^slot$/, action: 'move' } ] - const tagName = el.tag - const mid = options.usingComponentsInfo[tagName]?.mid || moduleId + const mid = getComponentInfo(el).mid const processAppendAttrsRules = [ { name: 'class', value: `${MPX_ROOT_VIEW} host-${mid}` } ] @@ -2420,7 +2421,7 @@ function processShow (el, options, root) { show = has ? `{{${parseMustacheWithContext(show).result}&&mpxShow}}` : '{{mpxShow}}' } if (show === undefined) return - if (isComponentNode(el, options) && isVirtualHostNode(el, options)) { + if (isComponentNode(el) && getComponentInfo(el).hasVirtualHost) { if (show === '') { show = '{{false}}' } @@ -2719,7 +2720,7 @@ function closeElement (el, options, meta) { } }) } - if (isComponentNode(el, options) && !hasVirtualHost && mode === 'ali' && el.tag !== 'component') { + if (isComponentNode(el) && !hasVirtualHost && mode === 'ali' && el.tag !== 'component') { postProcessAliComponentRootView(el, options, meta) } } diff --git a/packages/webpack-plugin/lib/utils/pre-process-json.js b/packages/webpack-plugin/lib/utils/pre-process-json.js index 118afaf8e6..6454a6553b 100644 --- a/packages/webpack-plugin/lib/utils/pre-process-json.js +++ b/packages/webpack-plugin/lib/utils/pre-process-json.js @@ -78,11 +78,8 @@ module.exports = function ({ componentGenerics = Object.assign({}, ret.componentGenerics) } if (usingComponents) { - const setUsingComponentInfo = (name, moduleId, hasVirtualHost) => { - usingComponentsInfo[name] = { - mid: moduleId, - hvh: hasVirtualHost - } + const setUsingComponentInfo = (name, info) => { + usingComponentsInfo[name] = info } async.eachOf(usingComponents, (component, name, callback) => { if (ctorType === 'app') { @@ -100,7 +97,10 @@ module.exports = function ({ const { rawResourcePath } = parseRequest(resource) const moduleId = mpx.getModuleId(rawResourcePath, ctorType === 'app') const hasVirtualHost = matchCondition(rawResourcePath, autoVirtualHostRules) - setUsingComponentInfo(name, moduleId, hasVirtualHost) + setUsingComponentInfo(name, { + mid: moduleId, + hasVirtualHost + }) callback() }) }, (err) => { From 3f65f98cd55a3f16e6b54c7ceceb1d3de8b30c50 Mon Sep 17 00:00:00 2001 From: xuegan Date: Fri, 3 Jan 2025 11:33:14 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E8=BE=93=E5=87=BAali=E5=8C=85?= =?UTF-8?q?=E8=A3=B9root-view=20virtualHost=E5=88=A4=E6=96=AD=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/webpack-plugin/lib/template-compiler/compiler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webpack-plugin/lib/template-compiler/compiler.js b/packages/webpack-plugin/lib/template-compiler/compiler.js index 022d5fc01a..2c565454b5 100644 --- a/packages/webpack-plugin/lib/template-compiler/compiler.js +++ b/packages/webpack-plugin/lib/template-compiler/compiler.js @@ -2713,14 +2713,14 @@ function closeElement (el, options, meta) { if (!isTemplate) { if (!isNative) { postProcessComponentIs(el, (child) => { - if (!hasVirtualHost && mode === 'ali') { + if (!getComponentInfo(el).hasVirtualHost && mode === 'ali') { postProcessAliComponentRootView(child, options) } else { postProcessIf(child) } }) } - if (isComponentNode(el) && !hasVirtualHost && mode === 'ali' && el.tag !== 'component') { + if (isComponentNode(el) && !getComponentInfo(el).hasVirtualHost && mode === 'ali' && el.tag !== 'component') { postProcessAliComponentRootView(el, options, meta) } }