Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: not log _Fragment (swc of playground) #542

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -709,14 +709,45 @@ describe('utils', () => {
)
}`);

const logMock = spyOn(console, 'log');
const outputAst = transformToReactiveArrays(input);
const output = toOutputCode(outputAst);
const expected = normalizeHTML(`
export default function MyComponent({error}) {
return [null, {}, [[null, {}, "Test"], [null, {}, () => error.value ? [null, {}, [[null, {}, () => \`Error: \${error.value.message}\`], [null, {}, " "], ["pre", {}, () => error.value.stack]]] : ""]]];
}
`);
expect(logMock).not.toBeCalled();
expect(output).toBe(expected);
logMock.mockRestore();
});

it('should not log _Fragment', () => {
const input = parseCodeToAST(`
export default function MyComponent() {
return (
<_Fragment>
<div>foo</div>
<span>bar</span>
</_Fragment>
)
}
`);

const logMock = spyOn(console, 'log');
logMock.mockImplementation(() => {});
const outputAst = transformToReactiveArrays(input);
const output = toOutputCode(outputAst);
const expected = normalizeHTML(`
export default function MyComponent() {
return [null, {}, [['div', {}, 'foo'], ['span', {}, 'bar']]];
}
`);
const logs = logMock.mock.calls.slice(0);

logMock.mockRestore();
expect(output).toBe(expected);
expect(logs).toEqual([]);
});

it('should keep the "key" attribute', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { logError, logWarning } from '@/utils/log/log-build';
import { JSX_NAME } from '@/utils/ast/constants';
import { BOOLEANS_IN_HTML } from '@/public-constants';

const fragmentNames = new Set(['Fragment', '_Fragment']);
export const logsPerFile = new Set<string | undefined>();

export default function transformToReactiveArrays(
Expand Down Expand Up @@ -42,7 +43,7 @@ export default function transformToReactiveArrays(

if (
value.arguments[0].type === 'Identifier' &&
value.arguments[0].name !== 'Fragment'
!fragmentNames.has(value.arguments[0].name)
) {
const errorMessages = [
`You can't use "${value.arguments[0].name}" variable as a tag name.`,
Expand Down
Loading