fix: <A {...{ a: 1 }} /> throw error when override props

This commit is contained in:
Amour1688 2020-10-17 10:29:08 +08:00
parent e9aa278b20
commit f50b9e37fd
3 changed files with 9 additions and 3 deletions

View File

@ -56,8 +56,10 @@ const transformJSXSpreadAttribute = (
walksScope(nodePath, (argument.node as t.Identifier).name, SlotFlags.DYNAMIC);
}
args.push(mergeProps ? argument.node : t.spreadElement(argument.node));
} else {
} else if (mergeProps) {
args.push(t.objectExpression(properties));
} else {
args.push(...(properties as t.ObjectProperty[]));
}
};

View File

@ -84,6 +84,10 @@ exports[`override props multiple: multiple 1`] = `
createVNode(resolveComponent(\\"A\\"), {
\\"loading\\": true,
...a,
b: 1,
c: {
d: 2
},
\\"class\\": \\"x\\",
\\"style\\": x
}, null);"

View File

@ -149,10 +149,10 @@ tests.forEach((
const overridePropsTests = [{
name: 'single',
from: '<div {...a}></div>',
from: '<div {...a} />',
}, {
name: 'multiple',
from: '<A loading {...a} class="x" style={x}></A>',
from: '<A loading {...a} {...{ b: 1, c: { d: 2 } }} class="x" style={x} />',
}];
overridePropsTests.forEach((