Skip to content

Commit

Permalink
prevent argument hoisting for import stmt
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Nov 29, 2022
1 parent abb3ebc commit 6bf4778
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/utils/src/defaultImportFn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export async function defaultImportFn(path: string) {
// TODO: investigate why problematic behaviour introduced with argument hoisting on https://github.com/microsoft/TypeScript/pull/49663.
// to test, export the function directly (`export async function defaultImportFn`) and try `mesh build` in `examples/json-schema-example`

async function defaultImportFn(path: string) {
let module = await import(/* @vite-ignore */ path).catch(e => {
if (e.code === 'ERR_REQUIRE_ESM') {
// eslint-disable-next-line no-new-func
Expand All @@ -21,3 +24,4 @@ export async function defaultImportFn(path: string) {
}
return module;
}
export { defaultImportFn };

0 comments on commit 6bf4778

Please sign in to comment.