Skip to content

Commit

Permalink
fix(node-swc): Don't remove plugin from options (#1390)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Feb 13, 2021
1 parent 8ef78a9 commit a0898e8
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions node-swc/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,17 @@ export class Compiler {
}


const plugin = options.plugin;
delete options.plugin;
const { plugin, ...newOptions } = options;

if (plugin) {
const m =
typeof src === "string"
? await this.parse(src, options?.jsc?.parser)
: src;
return this.transform(plugin(m), options);
return this.transform(plugin(m), newOptions);
}

return bindings.transform(isModule ? JSON.stringify(src) : src, isModule, toBuffer(options))
return bindings.transform(isModule ? JSON.stringify(src) : src, isModule, toBuffer(newOptions))
}

transformSync(src: string | Program, options?: Options): Output {
Expand All @@ -129,19 +128,18 @@ export class Compiler {
}


const plugin = options.plugin;
delete options.plugin;
const { plugin, ...newOptions } = options;

if (plugin) {
const m =
typeof src === "string" ? this.parseSync(src, options?.jsc?.parser) : src;
return this.transformSync(plugin(m), options);
return this.transformSync(plugin(m), newOptions);
}

return bindings.transformSync(
isModule ? JSON.stringify(src) : src,
isModule,
toBuffer(options),
toBuffer(newOptions),
)
}

Expand All @@ -153,15 +151,14 @@ export class Compiler {
}


const plugin = options.plugin;
delete options.plugin;
const { plugin, ...newOptions } = options;

if (plugin) {
const m = await this.parseFile(path, options?.jsc?.parser);
return this.transform(plugin(m), options);
return this.transform(plugin(m), newOptions);
}

return bindings.transformFile(path, false, toBuffer(options))
return bindings.transformFile(path, false, toBuffer(newOptions))
}

transformFileSync(path: string, options?: Options): Output {
Expand All @@ -172,15 +169,14 @@ export class Compiler {
}


const plugin = options?.plugin;
delete options?.plugin;
const { plugin, ...newOptions } = options;

if (plugin) {
const m = this.parseFileSync(path, options?.jsc?.parser);
return this.transformSync(plugin(m), options);
return this.transformSync(plugin(m), newOptions);
}

return bindings.transformFileSync(path, /* isModule */ false, toBuffer(options));
return bindings.transformFileSync(path, /* isModule */ false, toBuffer(newOptions));
}


Expand Down Expand Up @@ -302,4 +298,4 @@ export const DEFAULT_EXTENSIONS = Object.freeze([

function toBuffer(t: any): Buffer {
return Buffer.from(JSON.stringify(t))
}
}

0 comments on commit a0898e8

Please sign in to comment.