提交 9efe0eae 编写于 作者: fxy060608's avatar fxy060608

fix(v3): slots

上级 a4159e89
......@@ -231,8 +231,6 @@ function getSpecialMethods (name) {
return componentSpecialMethods[name] || []
}
const pagesJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'pages.json')
const cacheTypes = ['babel-loader', 'css-loader', 'uni-template-compiler', 'vue-loader']
function clearCache () {
......@@ -262,7 +260,8 @@ module.exports = {
// 先简单处理,该方案不好,
// 后续为 pages-loader 增加 cache-loader,
// 然后其他修改 json 的地方也要定制 cache-loader
store () {
store () {
const pagesJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'pages.json')
const filepath = path.resolve(
process.env.UNI_CLI_CONTEXT,
'node_modules/.cache/uni-pages-loader/' + process.env.UNI_PLATFORM,
......@@ -294,7 +293,8 @@ module.exports = {
clearCache()
} catch (e) {}
return
}
}
const pagesJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'pages.json')
const mtimeMs = fs.statSync(pagesJsonPath).mtimeMs
const jsonCache = require(filepath)
if (jsonCache.mtimeMs !== mtimeMs) {
......
......@@ -71,6 +71,10 @@ describe('codegen', () => {
'<current-user v-slot="{ user }">{{ user.firstName }}</current-user>',
`with(this){return _c('current-user',{attrs:{"_i":0},scopedSlots:_u([{key:"default",fn:function({ user }){return [_v((_$s(0,'t0',_s(user.firstName))))]}}])})}`
)
assertCodegen(
'<current-user>ABCD</current-user>',
`with(this){return _c('current-user',{attrs:{"_i":0}},[_v("")])}`
)
})
it('generate keep-alive', () => {
......
const compiler = require('../lib')
const res = compiler.compile(
`
<p :change:prop="swipe.sizeReady" :prop="pos" @touchstart="swipe.touchstart" @touchmove="swipe.touchmove" @touchend="swipe.touchend" @change="change"></p>
<current-user>ABCD</current-user>
`, {
resourcePath: '/User/fxy/Documents/test.wxml',
isReservedTag: function (tag) {
......@@ -14,8 +14,8 @@ const res = compiler.compile(
platform: 'app-plus'
},
filterModules: ['swipe'],
// service: true,
view: true
service: true
// view: true
})
console.log(require('util').inspect(res, {
......
......@@ -43,6 +43,7 @@ function isStatic (node) {
function markStatic (node) {
if (isStatic(node)) { // 静态节点且仅包含 ID 属性
if (
node.attrs &&
node.attrs.length === 1 &&
!node.key &&
!node.ref &&
......@@ -56,13 +57,17 @@ function markStatic (node) {
delete node.staticClass
delete node.staticStyle
if (node.attrs && !isComponent(node.tag) && node.tag !== 'keep-alive') { // 移除静态属性
const isCustomComponent = isComponent(node.tag)
if (node.attrs && !isCustomComponent && node.tag !== 'keep-alive') { // 移除静态属性
node.attrs = node.attrs.filter(attr => attr.name === ID || isVar(attr.value))
}
node.children = node.children.filter(child => { // 移除静态文本
if (child.type === 3) { // ASTText
return false
if (!isCustomComponent) {
return false
}
child.text = '' // slot <custom>ABCD</custom>
}
return true
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册