Skip to content
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 @@ -47,5 +47,33 @@ describeBuilder(buildApplication, APPLICATION_BUILDER_INFO, (harness) => {

expect(result?.success).toBe(true);
});

it('supports TSX files with isolated modules enabled and enabled optimizations', async () => {
// Enable tsconfig isolatedModules option in tsconfig
await harness.modifyFile('tsconfig.json', (content) => {
const tsconfig = JSON.parse(content);
tsconfig.compilerOptions.isolatedModules = true;
tsconfig.compilerOptions.jsx = 'react-jsx';

return JSON.stringify(tsconfig);
});

await harness.writeFile('src/types.d.ts', `declare module 'react/jsx-runtime' { jsx: any }`);
await harness.writeFile('src/abc.tsx', `export function hello() { return <h1>Hello</h1>; }`);
await harness.modifyFile(
'src/main.ts',
(content) => content + `import { hello } from './abc'; console.log(hello());`,
);

harness.useTarget('build', {
...BASE_OPTIONS,
optimization: true,
externalDependencies: ['react'],
});

const { result } = await harness.executeOnce();

expect(result?.success).toBe(true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import type {
BuildFailure,
Loader,
Metafile,
OnStartResult,
OutputFile,
Expand Down Expand Up @@ -456,9 +457,21 @@ export function createCompilerPlugin(
typeScriptFileCache.set(request, contents);
}

let loader: Loader;
if (useTypeScriptTranspilation || isJS) {
// TypeScript has transpiled to JS or is already JS
loader = 'js';
} else if (request.at(-1) === 'x') {
// TSX and TS have different syntax rules. Only set if input is a TSX file.
loader = 'tsx';
} else {
// Otherwise, directly bundle TS
loader = 'ts';
}

return {
contents,
loader: useTypeScriptTranspilation || isJS ? 'js' : 'ts',
loader,
};
});

Expand Down