Skip to content

Commit 3dcca6d

Browse files
committed
test: isCustomElement snap
1 parent 117b25a commit 3dcca6d

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,7 @@ export const checkIsComponent = (path: NodePath<t.JSXOpeningElement>, state: Sta
5050

5151
const tag = (namePath as NodePath<t.JSXIdentifier>).node.name;
5252

53-
if (state.opts.isCustomElement && state.opts.isCustomElement(tag)) {
54-
return false;
55-
}
56-
57-
return shouldTransformedToSlots(tag) && !htmlTags.includes(tag) && !svgTags.includes(tag);
53+
return !state.opts.isCustomElement?.(tag) && shouldTransformedToSlots(tag) && !htmlTags.includes(tag) && !svgTags.includes(tag);
5854
};
5955

6056
/**

packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ _withDirectives(_createVNode(\\"input\\", {
115115
}, null, 8, [\\"onUpdate:modelValue\\"]), [[_vModelText, test]]);"
116116
`;
117117

118+
exports[`isCustomElement: isCustomElement 1`] = `
119+
"import { createVNode as _createVNode, createTextVNode as _createTextVNode } from \\"vue\\";
120+
121+
_createVNode(\\"foo\\", null, [_createVNode(\\"span\\", null, [_createTextVNode(\\"foo\\")])]);"
122+
`;
123+
118124
exports[`named import specifier \`Keep Alive\`: named import specifier \`Keep Alive\` 1`] = `
119125
"import { createVNode as _createVNode, createTextVNode as _createTextVNode } from \\"vue\\";
120126
import { KeepAlive } from 'vue';

packages/babel-plugin-jsx/test/snapshot.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,17 @@ pragmaTests.forEach(({
304304
},
305305
);
306306
});
307+
308+
const isCustomElementTests = [{
309+
name: 'isCustomElement',
310+
from: '<foo><span>foo</span></foo>'
311+
}]
312+
313+
isCustomElementTests.forEach(({name, from }) => {
314+
test(
315+
name,
316+
async () => {
317+
expect(await transpile(from, { isCustomElement: tag => tag === 'foo' })).toMatchSnapshot(name);
318+
}
319+
)
320+
})

0 commit comments

Comments
 (0)