Skip to content

Commit bf59811

Browse files
committed
fix: mergeProps order error
1 parent f519920 commit bf59811

File tree

1 file changed

+14
-30
lines changed

1 file changed

+14
-30
lines changed

packages/babel-plugin-jsx/src/buildProps.ts

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
} from './utils';
1313
import parseDirectives from './parseDirectives';
1414
import { PatchFlags } from './patchFlags';
15-
import { State, ExcludesBoolean } from '.';
15+
import { State } from '.';
1616
import { transformJSXElement } from './transform-vue-jsx';
1717
import SlotFlags from './slotFlags';
1818

@@ -136,7 +136,7 @@ const buildProps = (path: NodePath<t.JSXElement>, state: State) => {
136136
};
137137
}
138138

139-
const properties: t.ObjectProperty[] = [];
139+
let properties: t.ObjectProperty[] = [];
140140

141141
// patchFlag analysis
142142
let hasRef = false;
@@ -145,7 +145,7 @@ const buildProps = (path: NodePath<t.JSXElement>, state: State) => {
145145
let hasHydrationEventBinding = false;
146146
let hasDynamicKeys = false;
147147

148-
const mergeArgs: (t.CallExpression | t.ObjectProperty | t.Identifier)[] = [];
148+
const mergeArgs: (t.CallExpression | t.ObjectExpression | t.Identifier)[] = [];
149149
props
150150
.forEach((prop) => {
151151
if (prop.isJSXAttribute()) {
@@ -263,15 +263,17 @@ const buildProps = (path: NodePath<t.JSXElement>, state: State) => {
263263

264264
dynamicPropNames.add(`onUpdate:${propName}`);
265265
}
266-
return;
267-
}
268-
if (name.match(xlinkRE)) {
269-
name = name.replace(xlinkRE, (_, firstCharacter) => `xlink:${firstCharacter.toLowerCase()}`);
266+
} else {
267+
if (name.match(xlinkRE)) {
268+
name = name.replace(xlinkRE, (_, firstCharacter) => `xlink:${firstCharacter.toLowerCase()}`);
269+
}
270+
properties.push(t.objectProperty(
271+
t.stringLiteral(name),
272+
attributeValue || t.booleanLiteral(true),
273+
));
270274
}
271-
properties.push(t.objectProperty(
272-
t.stringLiteral(name),
273-
attributeValue || t.booleanLiteral(true),
274-
));
275+
mergeArgs.push(t.objectExpression(dedupeProperties(properties)));
276+
properties = [];
275277
} else {
276278
// JSXSpreadAttribute
277279
hasDynamicKeys = true;
@@ -284,7 +286,6 @@ const buildProps = (path: NodePath<t.JSXElement>, state: State) => {
284286
});
285287

286288
// patchFlag analysis
287-
// tslint:disable: no-bitwise
288289
if (hasDynamicKeys) {
289290
patchFlag |= PatchFlags.FULL_PROPS;
290291
} else {
@@ -312,32 +313,15 @@ const buildProps = (path: NodePath<t.JSXElement>, state: State) => {
312313
let propsExpression: t.Expression | t.ObjectProperty | t.Literal = t.nullLiteral();
313314

314315
if (mergeArgs.length) {
315-
if (properties.length) {
316-
mergeArgs.push(...dedupeProperties(properties));
317-
}
318316
if (mergeArgs.length > 1) {
319-
const exps: (t.CallExpression | t.Identifier)[] = [];
320-
const objectProperties: t.ObjectProperty[] = [];
321-
mergeArgs.forEach((arg) => {
322-
if (t.isIdentifier(arg) || t.isExpression(arg)) {
323-
exps.push(arg);
324-
} else {
325-
objectProperties.push(arg);
326-
}
327-
});
328317
propsExpression = t.callExpression(
329318
createIdentifier(state, 'mergeProps'),
330-
[
331-
...exps,
332-
!!objectProperties.length && t.objectExpression(objectProperties),
333-
].filter(Boolean as any as ExcludesBoolean),
319+
mergeArgs,
334320
);
335321
} else {
336322
// single no need for a mergeProps call
337323
propsExpression = mergeArgs[0];
338324
}
339-
} else if (properties.length) {
340-
propsExpression = t.objectExpression(dedupeProperties(properties));
341325
}
342326

343327
return {

0 commit comments

Comments
 (0)