mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2024-11-10 09:39:14 +08:00
fix: force update on forwarded slots (#33)
This commit is contained in:
parent
a34ff99277
commit
b3ea528a6e
@ -354,7 +354,17 @@ const getChildren = (
|
|||||||
return transformedText;
|
return transformedText;
|
||||||
}
|
}
|
||||||
if (path.isJSXExpressionContainer()) {
|
if (path.isJSXExpressionContainer()) {
|
||||||
return transformJSXExpressionContainer(path);
|
const expression = transformJSXExpressionContainer(path);
|
||||||
|
|
||||||
|
if (t.isIdentifier(expression)) {
|
||||||
|
const { name } = expression as t.Identifier;
|
||||||
|
const { referencePaths } = path.scope.getBinding(name) || {};
|
||||||
|
referencePaths?.forEach(referencePath => {
|
||||||
|
walksScope(referencePath, name);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return expression;
|
||||||
}
|
}
|
||||||
if (t.isJSXSpreadChild(path)) {
|
if (t.isJSXSpreadChild(path)) {
|
||||||
return transformJSXSpreadChild(path as NodePath<t.JSXSpreadChild>);
|
return transformJSXSpreadChild(path as NodePath<t.JSXSpreadChild>);
|
||||||
|
@ -171,7 +171,9 @@ const transformJSXSpreadChild = (
|
|||||||
|
|
||||||
const walksScope = (path: NodePath, name: string) => {
|
const walksScope = (path: NodePath, name: string) => {
|
||||||
if (path.scope.hasBinding(name) && path.parentPath) {
|
if (path.scope.hasBinding(name) && path.parentPath) {
|
||||||
path.parentPath.setData('optimize', false);
|
if (t.isJSXElement(path.parentPath.node)) {
|
||||||
|
path.parentPath.setData('optimize', false);
|
||||||
|
}
|
||||||
walksScope(path.parentPath, name);
|
walksScope(path.parentPath, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -353,16 +353,18 @@ describe('PatchFlags', () => {
|
|||||||
|
|
||||||
expect(wrapper.classes().sort()).toEqual(['b', 'static'].sort());
|
expect(wrapper.classes().sort()).toEqual(['b', 'static'].sort());
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('variables outside slot', async () => {
|
describe('variables outside slots', async () => {
|
||||||
const A = {
|
const A = {
|
||||||
render() {
|
render() {
|
||||||
return this.$slots.default();
|
return this.$slots.default();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
A.inheritAttrs = false;
|
A.inheritAttrs = false;
|
||||||
|
|
||||||
|
test('internal', async () => {
|
||||||
const wrapper = mount({
|
const wrapper = mount({
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -390,7 +392,39 @@ describe('PatchFlags', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
expect(wrapper.get('#textarea').element.innerHTML).toBe('0');
|
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({
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
val: 0,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
inc() {
|
||||||
|
this.val += 1;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
render() {
|
||||||
|
const attrs = {
|
||||||
|
innerHTML: this.val,
|
||||||
|
};
|
||||||
|
const textarea = <textarea id="textarea" {...attrs} />;
|
||||||
|
return (
|
||||||
|
<A inc={this.inc}>
|
||||||
|
<div>
|
||||||
|
{textarea}
|
||||||
|
</div>
|
||||||
|
<button id="button" onClick={this.inc}>+1</button>
|
||||||
|
</A>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
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');
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user