Skip to content
Merged
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
23 changes: 14 additions & 9 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 @@ -2708,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, options) && !hasVirtualHost && mode === 'ali' && el.tag !== 'component') {
if (isComponentNode(el) && !getComponentInfo(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