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: 解构 props 后,如果作用域中不包含 children, 其他 renderProps 可能识别失败 close #7315 #7326

Open
wants to merge 1 commit into
base: 2.x
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
31 changes: 31 additions & 0 deletions packages/taro-transformer-wx/__tests__/render-props.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,35 @@ describe('render props', () => {
`)
)
})

test('fix #7315', () => {
const { template, ast, code } = transform({
...baseOptions,
isRoot: true,
code: buildComponent(`
const {renderHeader, renderFooter} = this.props

return (
<View>
<Block>{renderHeader}</Block>
<Block>{renderFooter}</Block>
</View>
)
`, ``)
})
expect(template).toMatch(
prettyPrint(`
<block>
<view>
<block>
<slot name="header"></slot>
</block>
<block>
<slot name="footer"></slot>
</block>
</view>
</block>
`)
)
})
})
2 changes: 1 addition & 1 deletion packages/taro-transformer-wx/src/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ class Transformer {
}
}
} else if (path.isReferencedIdentifier()) {
if (isDerivedFromProps(path.scope, 'children')) {
if (isDerivedFromProps(path.scope, path.node.name)) {
parentPath.replaceWith(slot)
}
}
Expand Down