mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2025-01-11 00:39:10 +08:00
chore: use generateUidIdentifier
This commit is contained in:
parent
06c92a2733
commit
ad8c3cbfe6
@ -208,13 +208,6 @@ const walksScope = (path: NodePath, name: string, slotFlag: SlotFlags): void =>
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const createInsertName = (path: NodePath, name: string): t.Identifier => {
|
|
||||||
if (path.scope.hasBinding(name)) {
|
|
||||||
return createInsertName(path, `_${name}`);
|
|
||||||
}
|
|
||||||
return t.identifier(name);
|
|
||||||
};
|
|
||||||
|
|
||||||
const buildIIFE = (path: NodePath<t.JSXElement>, children: t.Expression[]) => {
|
const buildIIFE = (path: NodePath<t.JSXElement>, children: t.Expression[]) => {
|
||||||
const { parentPath } = path;
|
const { parentPath } = path;
|
||||||
if (t.isAssignmentExpression(parentPath)) {
|
if (t.isAssignmentExpression(parentPath)) {
|
||||||
@ -222,7 +215,7 @@ const buildIIFE = (path: NodePath<t.JSXElement>, children: t.Expression[]) => {
|
|||||||
if (t.isIdentifier(left)) {
|
if (t.isIdentifier(left)) {
|
||||||
return children.map((child) => {
|
return children.map((child) => {
|
||||||
if (t.isIdentifier(child) && child.name === left.name) {
|
if (t.isIdentifier(child) && child.name === left.name) {
|
||||||
const insertName = createInsertName(parentPath, `_${child.name}`);
|
const insertName = path.scope.generateUidIdentifier(child.name);
|
||||||
parentPath.insertBefore(
|
parentPath.insertBefore(
|
||||||
t.variableDeclaration('const', [
|
t.variableDeclaration('const', [
|
||||||
t.variableDeclarator(
|
t.variableDeclarator(
|
||||||
|
@ -105,14 +105,15 @@ const A = defineComponent({
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
const _a = 1;
|
const _a2 = 2;
|
||||||
|
a = _a2;
|
||||||
|
|
||||||
const __a = function () {
|
const _a = function () {
|
||||||
return a;
|
return a;
|
||||||
}();
|
}();
|
||||||
|
|
||||||
a = createVNode(A, null, {
|
a = createVNode(A, null, {
|
||||||
default: () => [__a],
|
default: () => [_a],
|
||||||
_: 2
|
_: 2
|
||||||
});"
|
});"
|
||||||
`;
|
`;
|
||||||
|
@ -481,9 +481,8 @@ test('reassign variable as component should work', () => {
|
|||||||
|
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const _a = 1;
|
const _a2 = 2;
|
||||||
// @ts-ignore
|
a = _a2;
|
||||||
const __a = 2;
|
|
||||||
/* eslint-enable */
|
/* eslint-enable */
|
||||||
|
|
||||||
a = <A>{a}</A>;
|
a = <A>{a}</A>;
|
||||||
@ -494,5 +493,5 @@ test('reassign variable as component should work', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(wrapper.html()).toBe('<span>1</span>');
|
expect(wrapper.html()).toBe('<span>2</span>');
|
||||||
});
|
});
|
||||||
|
@ -127,7 +127,9 @@ const tests = [
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const _a = 1;
|
const _a2 = 2;
|
||||||
|
|
||||||
|
a = _a2;
|
||||||
|
|
||||||
a = <A>{a}</A>;
|
a = <A>{a}</A>;
|
||||||
`,
|
`,
|
||||||
|
Loading…
Reference in New Issue
Block a user