Skip to content

Commit

Permalink
feat(weapp): 支持 multipleSlots
Browse files Browse the repository at this point in the history
  • Loading branch information
yuche committed Nov 15, 2018
1 parent 2b87404 commit 2e4e8a4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/taro-transformer-wx/src/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,16 @@ class Transformer {
this.compile()
}

setMultipleSlots () {
const body = this.classPath.node.body.body
if (body.some(c => t.isClassProperty(c) && c.key.name === 'multipleSlots')) {
return
}
const multipleSlots: any = t.classProperty(t.identifier('multipleSlots'), t.booleanLiteral(true))
multipleSlots.static = true
body.push(multipleSlots)
}

createStringRef (componentName: string, id: string, refName: string) {
this.refs.push({
type: DEFAULT_Component_SET.has(componentName) ? 'dom' : 'component',
Expand Down Expand Up @@ -379,7 +389,7 @@ class Transformer {
}
}
},
MemberExpression (path) {
MemberExpression: (path) => {
const object = path.get('object')
const property = path.get('property')
if (
Expand All @@ -402,6 +412,7 @@ class Transformer {
parentPath.replaceWith(t.jSXElement(t.jSXOpeningElement(t.jSXIdentifier('slot'), [
t.jSXAttribute(t.jSXIdentifier('name'), t.stringLiteral(slotName))
], true), t.jSXClosingElement(t.jSXIdentifier('slot')), []))
this.setMultipleSlots()
} else {
self.componentProperies.add(siblingProp.node.name)
}
Expand Down
12 changes: 12 additions & 0 deletions packages/taro-weapp/src/create-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ function bindStaticOptions (weappComponentConf, ComponentClass) {
}
}

function bindMultipleSlots (weappComponentConf, ComponentClass) {
const multipleSlots = ComponentClass.multipleSlots
if (!multipleSlots) {
return
}
weappComponentConf.options = {
...weappComponentConf.options,
...{ multipleSlots }
}
}

function bindStaticFns (weappComponentConf, ComponentClass) {
for (const key in ComponentClass) {
typeof ComponentClass[key] === 'function' && (weappComponentConf[key] = ComponentClass[key])
Expand Down Expand Up @@ -384,6 +395,7 @@ function createComponent (ComponentClass, isPage) {
bindBehaviors(weappComponentConf, ComponentClass)
bindStaticFns(weappComponentConf, ComponentClass)
bindStaticOptions(weappComponentConf, ComponentClass)
bindMultipleSlots(weappComponentConf, ComponentClass)
ComponentClass['$$events'] && bindEvents(weappComponentConf, ComponentClass['$$events'], isPage)
if (ComponentClass['externalClasses'] && ComponentClass['externalClasses'].length) {
weappComponentConf['externalClasses'] = ComponentClass['externalClasses']
Expand Down

0 comments on commit 2e4e8a4

Please sign in to comment.