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, mergeProps: boolean,
args: (t.ObjectProperty | t.Expression | t.SpreadElement)[], args: (t.ObjectProperty | t.Expression | t.SpreadElement)[],
) => { ) => {
const argument = path.get('argument') as NodePath<t.ObjectExpression>; const argument = path.get('argument') as NodePath<t.ObjectExpression | t.Identifier>;
const { properties } = argument.node; const properties = t.isObjectExpression(argument.node) ? argument.node.properties : undefined;
if (!properties) { if (!properties) {
if (argument.isIdentifier()) { 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)); args.push(mergeProps ? argument.node : t.spreadElement(argument.node));
} else if (mergeProps) { } else if (mergeProps) {

View File

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