Skip to content

Commit 81bcfe2

Browse files
committed
fix: match scriptRegex independently for each file
1 parent 244bfdf commit 81bcfe2

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎src/index.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ const solidLoader: LoaderDefinition<SolidLoaderOptions> = async function (
3333
const sourceFilename = this.resourcePath;
3434
const resourceFilename = options.transformFilename ?? sourceFilename;
3535

36-
if (options.scriptRegex && !options.scriptRegex.test(resourceFilename)) {
36+
if (
37+
options.scriptRegex &&
38+
resourceFilename.search(options.scriptRegex) === -1
39+
) {
3740
callback(null, source, sourceMap);
3841
return;
3942
}

‎test/basic/index.test.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ for (const compiler of ['native', 'babel']) {
1313
test(`renders typed SSR output with ${compiler}`, async () => {
1414
const cwd = await mkdtemp(path.join(playground, 'test-temp-'));
1515
try {
16+
await writeFile(
17+
path.join(cwd, 'Title.tsx'),
18+
'export const Title = () => <h1>Hello</h1>;',
19+
);
1620
await writeFile(
1721
path.join(cwd, 'app.tsx'),
1822
`
1923
import { renderToString } from '@solidjs/web';
20-
const title: string = 'Hello';
21-
export const html = renderToString(() => <h1>{title}</h1>);
24+
import { Title } from './Title.tsx';
25+
export const html: string = renderToString(() => <Title />);
2226
`,
2327
);
2428
await new Promise<void>((resolve, reject) => {
@@ -46,7 +50,11 @@ for (const compiler of ['native', 'babel']) {
4650
},
4751
{
4852
loader: 'solid-loader',
49-
options: { compiler, solid: { generate: 'ssr' } },
53+
options: {
54+
compiler,
55+
scriptRegex: /\.tsx$/g,
56+
solid: { generate: 'ssr' },
57+
},
5058
},
5159
],
5260
},

0 commit comments

Comments
 (0)