fix: dynamic slot flag not working

This commit is contained in:
Amour1688 2021-03-15 23:37:01 +08:00
parent de17052e7d
commit 3a83e668f4
2 changed files with 33 additions and 33 deletions

View File

@ -49,11 +49,11 @@ const transformJSXSpreadAttribute = (
mergeProps: boolean,
args: (t.ObjectProperty | t.Expression | t.SpreadElement)[],
) => {
const argument = path.get('argument') as NodePath<t.ObjectExpression>;
const { properties } = argument.node;
const argument = path.get('argument') as NodePath<t.ObjectExpression | t.Identifier>;
const properties = t.isObjectExpression(argument.node) ? argument.node.properties : undefined;
if (!properties) {
if (argument.isIdentifier()) {
walksScope(nodePath, (argument as any).name, SlotFlags.DYNAMIC);
walksScope(nodePath, (argument.node as t.Identifier).name, SlotFlags.DYNAMIC);
}
args.push(mergeProps ? argument.node : t.spreadElement(argument.node));
} else if (mergeProps) {

View File

@ -414,37 +414,37 @@ describe('variables outside slots', () => {
A.inheritAttrs = false;
// test('internal', async () => {
// const wrapper = mount(defineComponent({
// data() {
// return {
// val: 0,
// };
// },
// methods: {
// inc() {
// this.val += 1;
// },
// },
// render() {
// const attrs = {
// innerHTML: `${this.val}`,
// };
// return (
// <A inc={this.inc}>
// <div>
// <textarea id="textarea" {...attrs} />
// </div>
// <button id="button" onClick={this.inc}>+1</button>
// </A>
// );
// },
// }));
test('internal', async () => {
const wrapper = mount(defineComponent({
data() {
return {
val: 0,
};
},
methods: {
inc() {
this.val += 1;
},
},
render() {
const attrs = {
innerHTML: `${this.val}`,
};
return (
<A inc={this.inc}>
<div>
<textarea id="textarea" {...attrs} />
</div>
<button id="button" onClick={this.inc}>+1</button>
</A>
);
},
}));
// expect(wrapper.get('#textarea').element.innerHTML).toBe('0');
// await wrapper.get('#button').trigger('click');
// expect(wrapper.get('#textarea').element.innerHTML).toBe('1');
// });
expect(wrapper.get('#textarea').element.innerHTML).toBe('0');
await wrapper.get('#button').trigger('click');
expect(wrapper.get('#textarea').element.innerHTML).toBe('1');
});
test('forwarded', async () => {
const wrapper = mount({