From 3dcca6d06d086742429014a142c54463d7f99568 Mon Sep 17 00:00:00 2001 From: Amour1688 Date: Thu, 20 May 2021 20:46:06 +0800 Subject: [PATCH] test: isCustomElement snap --- packages/babel-plugin-jsx/src/utils.ts | 6 +----- .../test/__snapshots__/snapshot.test.ts.snap | 6 ++++++ packages/babel-plugin-jsx/test/snapshot.test.ts | 14 ++++++++++++++ 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/packages/babel-plugin-jsx/src/utils.ts b/packages/babel-plugin-jsx/src/utils.ts index cca2af2..1480ac2 100644 --- a/packages/babel-plugin-jsx/src/utils.ts +++ b/packages/babel-plugin-jsx/src/utils.ts @@ -50,11 +50,7 @@ export const checkIsComponent = (path: NodePath, state: Sta const tag = (namePath as NodePath).node.name; - if (state.opts.isCustomElement && state.opts.isCustomElement(tag)) { - return false; - } - - return shouldTransformedToSlots(tag) && !htmlTags.includes(tag) && !svgTags.includes(tag); + return !state.opts.isCustomElement?.(tag) && shouldTransformedToSlots(tag) && !htmlTags.includes(tag) && !svgTags.includes(tag); }; /** diff --git a/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap b/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap index ede349a..bf1b665 100644 --- a/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap +++ b/packages/babel-plugin-jsx/test/__snapshots__/snapshot.test.ts.snap @@ -115,6 +115,12 @@ _withDirectives(_createVNode(\\"input\\", { }, null, 8, [\\"onUpdate:modelValue\\"]), [[_vModelText, test]]);" `; +exports[`isCustomElement: isCustomElement 1`] = ` +"import { createVNode as _createVNode, createTextVNode as _createTextVNode } from \\"vue\\"; + +_createVNode(\\"foo\\", null, [_createVNode(\\"span\\", null, [_createTextVNode(\\"foo\\")])]);" +`; + exports[`named import specifier \`Keep Alive\`: named import specifier \`Keep Alive\` 1`] = ` "import { createVNode as _createVNode, createTextVNode as _createTextVNode } from \\"vue\\"; import { KeepAlive } from 'vue'; diff --git a/packages/babel-plugin-jsx/test/snapshot.test.ts b/packages/babel-plugin-jsx/test/snapshot.test.ts index 64211fc..f94f300 100644 --- a/packages/babel-plugin-jsx/test/snapshot.test.ts +++ b/packages/babel-plugin-jsx/test/snapshot.test.ts @@ -304,3 +304,17 @@ pragmaTests.forEach(({ }, ); }); + +const isCustomElementTests = [{ + name: 'isCustomElement', + from: 'foo' +}] + +isCustomElementTests.forEach(({name, from }) => { + test( + name, + async () => { + expect(await transpile(from, { isCustomElement: tag => tag === 'foo' })).toMatchSnapshot(name); + } + ) +}) \ No newline at end of file