提交 2e64d756 编写于 作者: Q qiang

fix(mp-toutiao): 修复同名文件内引用同一个组件作用域插槽渲染错误的问题 question/127962

上级 3b0831eb
const compiler = require('@dcloudio/uni-mp-weixin/lib/uni.compiler.js')
const path = require('path')
const t = require('@babel/types')
const crypto = require('crypto')
function generateJsCode (properties = '{}') {
return `
......@@ -18,6 +19,15 @@ function generateCssCode (filename) {
`
}
function getBaseName (ownerName, parentName, slotName, resourcePath) {
const str = `${resourcePath}/${parentName}/${slotName}`
const md5 = crypto.createHash('md5').update(str).digest('hex')
if (process.env.NODE_ENV !== 'development') {
return `m${md5.substring(0, 8)}`
}
return `${ownerName}--${parentName}--${slotName}--${md5.substring(0, 4)}`
}
function hasOwn (obj, key) {
return Object.prototype.hasOwnProperty.call(obj, key)
}
......@@ -38,7 +48,7 @@ module.exports = Object.assign({}, compiler, {
if (!state.scopedSlots) {
state.scopedSlots = {}
}
const baseName = `${ownerName}-${parentName}-${slotName}`
const baseName = getBaseName(ownerName, parentName, slotName, resourcePath)
let componentName = baseName
if (!hasOwn(state.scopedSlots, baseName)) {
state.scopedSlots[baseName] = 0
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册