Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: processShowStyle 添加是否为 virtualHost 的判断 #1777

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions packages/webpack-plugin/lib/template-compiler/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ let hasOptionalChaining = false
let processingTemplate = false
const rulesResultMap = new Map()
let usingComponents = []
let usingComponentsInfo = {}

function updateForScopesMap () {
forScopesMap = {}
Expand Down Expand Up @@ -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, {
Expand Down Expand Up @@ -2185,16 +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 isReactComponent (el, options) {
return !isComponentNode(el, options) && isRealNode(el) && !el.isBuiltIn
function getComponentInfo (el) {
return usingComponentsInfo[el.tag] || {}
}

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) => {
Expand Down Expand Up @@ -2308,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}` }
]
Expand Down Expand Up @@ -2416,7 +2421,7 @@ function processShow (el, options, root) {
show = has ? `{{${parseMustacheWithContext(show).result}&&mpxShow}}` : '{{mpxShow}}'
}
if (show === undefined) return
if (isComponentNode(el, options)) {
if (isComponentNode(el) && getComponentInfo(el).hasVirtualHost) {
if (show === '') {
show = '{{false}}'
}
Expand Down Expand Up @@ -2715,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)
}
}
Expand Down
14 changes: 9 additions & 5 deletions packages/webpack-plugin/lib/utils/pre-process-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ({
Expand All @@ -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)
Expand Down Expand Up @@ -78,8 +78,8 @@ module.exports = function ({
componentGenerics = Object.assign({}, ret.componentGenerics)
}
if (usingComponents) {
const setUsingComponentInfo = (name, moduleId) => {
usingComponentsInfo[name] = { mid: moduleId }
const setUsingComponentInfo = (name, info) => {
usingComponentsInfo[name] = info
}
async.eachOf(usingComponents, (component, name, callback) => {
if (ctorType === 'app') {
Expand All @@ -96,7 +96,11 @@ 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, {
mid: moduleId,
hasVirtualHost
})
callback()
})
}, (err) => {
Expand Down
Loading