Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/babel-plugin-jsx/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const isDirective = (src: string): boolean => src.startsWith('v-')
* @param tag string
* @returns boolean
*/
export const shouldTransformedToSlots = (tag: string) => !(tag.endsWith(FRAGMENT) || tag === KEEP_ALIVE);
// if _Fragment is already imported, it will end with number
export const shouldTransformedToSlots = (tag: string) => !(tag.match(RegExp(`^_?${FRAGMENT}\\d*$`)) || tag === KEEP_ALIVE);

/**
* Check if a Node is a component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`_Fragment already imported: _Fragment already imported 1`] = `
"import { createVNode as _createVNode, createTextVNode as _createTextVNode, Fragment as _Fragment2 } from \\"vue\\";
import _Fragment from 'example';

const Root1 = () => _createVNode(_Fragment2, null, [_createTextVNode(\\"root1\\")]);

const Root2 = () => _createVNode(_Fragment2, null, [_createTextVNode(\\"root2\\")]);"
`;

exports[`MereProps Order: MereProps Order 1`] = `
"import { createVNode as _createVNode, mergeProps as _mergeProps, createTextVNode as _createTextVNode } from \\"vue\\";

Expand Down
20 changes: 19 additions & 1 deletion packages/babel-plugin-jsx/test/snapshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,4 +317,22 @@ isCustomElementTests.forEach(({name, from }) => {
expect(await transpile(from, { isCustomElement: tag => tag === 'foo' })).toMatchSnapshot(name);
}
)
})
})

const fragmentTests = [{
name: '_Fragment already imported',
from: `
import _Fragment from 'example'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import _Fragment from 'example'
import { Fragment } from 'vue'

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样没改前也能通过测试,因为_Fragment是编译SFC多根节点模板时生成的

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import { Fragment as _Fragment } from 'vue' 这样吧

const Root1=() => <>root1</>
const Root2=() => <Fragment>root2</Fragment>
`
}];

fragmentTests.forEach(({ name, from}) => {
test(
name,
async () => {
expect(await transpile(from)).toMatchSnapshot(name);
},
);
});