From a0898e8ce311d5838c52a77dd5e47974e21016ac Mon Sep 17 00:00:00 2001 From: Jovi De Croock Date: Sat, 13 Feb 2021 11:34:35 +0100 Subject: [PATCH] fix(node-swc): Don't remove plugin from options (#1390) --- node-swc/src/index.ts | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/node-swc/src/index.ts b/node-swc/src/index.ts index 4be2a09a46e7..05e35e394b42 100644 --- a/node-swc/src/index.ts +++ b/node-swc/src/index.ts @@ -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 { @@ -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), ) } @@ -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 { @@ -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)); } @@ -302,4 +298,4 @@ export const DEFAULT_EXTENSIONS = Object.freeze([ function toBuffer(t: any): Buffer { return Buffer.from(JSON.stringify(t)) -} \ No newline at end of file +}