mirror of
https://github.com/vuejs/babel-plugin-jsx.git
synced 2024-11-10 09:39:14 +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 { parentPath } = path;
|
||||
if (t.isAssignmentExpression(parentPath)) {
|
||||
@ -222,7 +215,7 @@ const buildIIFE = (path: NodePath<t.JSXElement>, children: t.Expression[]) => {
|
||||
if (t.isIdentifier(left)) {
|
||||
return children.map((child) => {
|
||||
if (t.isIdentifier(child) && child.name === left.name) {
|
||||
const insertName = createInsertName(parentPath, `_${child.name}`);
|
||||
const insertName = path.scope.generateUidIdentifier(child.name);
|
||||
parentPath.insertBefore(
|
||||
t.variableDeclaration('const', [
|
||||
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;
|
||||
}();
|
||||
|
||||
a = createVNode(A, null, {
|
||||
default: () => [__a],
|
||||
default: () => [_a],
|
||||
_: 2
|
||||
});"
|
||||
`;
|
||||
|
@ -481,9 +481,8 @@ test('reassign variable as component should work', () => {
|
||||
|
||||
/* eslint-disable */
|
||||
// @ts-ignore
|
||||
const _a = 1;
|
||||
// @ts-ignore
|
||||
const __a = 2;
|
||||
const _a2 = 2;
|
||||
a = _a2;
|
||||
/* eslint-enable */
|
||||
|
||||
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>;
|
||||
`,
|
||||
|
Loading…
Reference in New Issue
Block a user