Skip to content

Commit

Permalink
Merge pull request #112 from privatenumber/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber authored Feb 16, 2021
2 parents 6901b94 + d590d49 commit d948b44
Show file tree
Hide file tree
Showing 7 changed files with 1,508 additions and 1,015 deletions.
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/BUG_REPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Keep your reproductions minimal. Follow guidelines here: https://stackoverflow.c

## Environment

- `esbuild-loader` version:
- esbuild-loader version:
- Webpack version:
- Operating System:
- Node version:
- Package manager (npm/yarn/pnpm) and version:
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
],
"license": "MIT",
"repository": "privatenumber/esbuild-loader",
"funding": "https://github.com/privatenumber/esbuild-loader?sponsor=1",
"author": {
"name": "Hiroki Osame",
"email": "[email protected]"
Expand Down
25 changes: 11 additions & 14 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ joycon.addLoader({
},
});

const tsxTryTsLoaderPtrn = /Unexpected|Expected/;
const isTsExtensionPtrn = /\.ts$/i;
let tsConfig: LoadResult;

async function ESBuildLoader(
Expand Down Expand Up @@ -60,20 +60,17 @@ async function ESBuildLoader(
}
}

try {
const result = await service.transform(source, transformOptions).catch(async error => {
// Target might be a TS file accidentally parsed as TSX
if (transformOptions.loader === 'tsx' && tsxTryTsLoaderPtrn.test(error.message)) {
transformOptions.loader = 'ts';
return service.transform(source, transformOptions).catch(_ => {
throw error;
});
}

throw error;
});
// https://github.com/privatenumber/esbuild-loader/pull/107
if (
transformOptions.loader === 'tsx'
&& isTsExtensionPtrn.test(this.resourcePath)
) {
transformOptions.loader = 'ts';
}

done(null, result.code, result.map && JSON.parse(result.map));
try {
const { code, map } = await service.transform(source, transformOptions);
done(null, code, map && JSON.parse(map));
} catch (error: unknown) {
done(error as Error);
}
Expand Down
Loading

0 comments on commit d948b44

Please sign in to comment.