Skip to content

Commit

Permalink
fix: not log _Fragment (swc of playground) (#542)
Browse files Browse the repository at this point in the history
  • Loading branch information
aralroca authored Oct 10, 2024
1 parent a97caf0 commit bfa490d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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

0 comments on commit bfa490d

Please sign in to comment.