Skip to content

Commit

Permalink
chore: remove unnecessary fallback arguments (#44)
Browse files Browse the repository at this point in the history
And updates types accordingly
Looking at the docs, there's no 3rd argument to the fallback and it doesn't really make sense to pass fallback itself.

https://nodejs.org/api/esm.html#loadurl-context-nextload
  • Loading branch information
saitonakamura committed Jun 27, 2023
1 parent 7880796 commit 833ed94
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ type Transform = (
fallback: Transform
) => Promisable<{ source: Source }>;

type Load = (
url: string,
context: { format?: Format },
fallback: Load
) => Promisable<{
type LoadResult = Promisable<{
format: Format;
shortCircuit: boolean;
source: Source;
}>;
}>

type Load = (
url: string,
context: { format?: Format },
fallback: (url: string, context: { format?: Format }) => LoadResult
) => LoadResult;

async function toConfig(): Promise<Config> {
let mod = await setup;
Expand Down Expand Up @@ -136,7 +138,7 @@ export const resolve: Resolve = async function (ident, context, fallback) {
export const load: Load = async function (uri, context, fallback) {
// note: inline `getFormat`
let options = await toOptions(uri);
if (options == null) return fallback(uri, context, fallback);
if (options == null) return fallback(uri, context);
let format: Format = options.format === 'cjs' ? 'commonjs' : 'module';

// TODO: decode SAB/U8 correctly
Expand Down

0 comments on commit 833ed94

Please sign in to comment.