test: isCustomElement snap

This commit is contained in:
Amour1688 2021-05-20 20:46:06 +08:00
parent 117b25a56a
commit 3dcca6d06d
3 changed files with 21 additions and 5 deletions

View File

@ -50,11 +50,7 @@ export const checkIsComponent = (path: NodePath<t.JSXOpeningElement>, state: Sta
const tag = (namePath as NodePath<t.JSXIdentifier>).node.name; const tag = (namePath as NodePath<t.JSXIdentifier>).node.name;
if (state.opts.isCustomElement && state.opts.isCustomElement(tag)) { return !state.opts.isCustomElement?.(tag) && shouldTransformedToSlots(tag) && !htmlTags.includes(tag) && !svgTags.includes(tag);
return false;
}
return shouldTransformedToSlots(tag) && !htmlTags.includes(tag) && !svgTags.includes(tag);
}; };
/** /**

View File

@ -115,6 +115,12 @@ _withDirectives(_createVNode(\\"input\\", {
}, null, 8, [\\"onUpdate:modelValue\\"]), [[_vModelText, test]]);" }, 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`] = ` exports[`named import specifier \`Keep Alive\`: named import specifier \`Keep Alive\` 1`] = `
"import { createVNode as _createVNode, createTextVNode as _createTextVNode } from \\"vue\\"; "import { createVNode as _createVNode, createTextVNode as _createTextVNode } from \\"vue\\";
import { KeepAlive } from 'vue'; import { KeepAlive } from 'vue';

View File

@ -304,3 +304,17 @@ pragmaTests.forEach(({
}, },
); );
}); });
const isCustomElementTests = [{
name: 'isCustomElement',
from: '<foo><span>foo</span></foo>'
}]
isCustomElementTests.forEach(({name, from }) => {
test(
name,
async () => {
expect(await transpile(from, { isCustomElement: tag => tag === 'foo' })).toMatchSnapshot(name);
}
)
})