Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix: 修复支付宝组件无法接受动态传递props的问题
Browse files Browse the repository at this point in the history
微信由于打包大小的限制,性能限制,先不支持
  • Loading branch information
Darmody authored and yesmeck committed Sep 2, 2019
1 parent 4630ff4 commit 9d26dd2
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions packages/remax-cli/src/build/plugins/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ interface Component {

const components: { [id: string]: Component } = {};

function shouldRegisterAllProps(
adapter: Adapter,
node: t.JSXElement,
componentName: string
) {
if (adapter.name === 'alipay') {
return true;
}

if (
node.openingElement.attributes.find(a => a.type === 'JSXSpreadAttribute')
) {
return true;
}

return false;
}

export default (adapter: Adapter) => () => ({
visitor: {
JSXElement(path: NodePath) {
Expand All @@ -36,19 +54,6 @@ export default (adapter: Adapter) => () => ({
const componentName = componentPath.node.imported.name;
const id = kebabCase(componentName);

let usedProps = adapter.hostComponents(id).props;

const usedAllProps = node.openingElement.attributes.find(
attr => attr.type === 'JSXSpreadAttribute'
);

if (!usedAllProps) {
usedProps = node.openingElement.attributes.map(e => {
const propName = get(e, 'name.name') as string;
return propName;
});
}

if (id === 'swiper-item') {
return;
}
Expand All @@ -57,6 +62,15 @@ export default (adapter: Adapter) => () => ({
return;
}

let usedProps = adapter.hostComponents(id).props;

if (!shouldRegisterAllProps(adapter, node, componentName)) {
usedProps = node.openingElement.attributes.map(e => {
const propName = get(e, 'name.name') as string;
return propName;
});
}

const props = usedProps
.filter(prop => !!prop)
.map(prop => adapter.getNativePropName(prop as string));
Expand Down

0 comments on commit 9d26dd2

Please sign in to comment.