diff options
author | 2023-04-21 18:02:29 -0700 | |
---|---|---|
committer | 2023-04-21 18:02:29 -0700 | |
commit | 8b9462fde5cfa17cc20f59f0f92372a1484a4e48 (patch) | |
tree | 163ea5aaf7c29148bbb9566a7b76aad29c933272 /src | |
parent | caa90ba98e878aa277a404219c7ad45f524b0db9 (diff) | |
download | bun-8b9462fde5cfa17cc20f59f0f92372a1484a4e48.tar.gz bun-8b9462fde5cfa17cc20f59f0f92372a1484a4e48.tar.zst bun-8b9462fde5cfa17cc20f59f0f92372a1484a4e48.zip |
Add `minify` option to Bun.Transpiler
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/api/JSTranspiler.zig | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/bun.js/api/JSTranspiler.zig b/src/bun.js/api/JSTranspiler.zig index ea3ea6d56..c68fc75a0 100644 --- a/src/bun.js/api/JSTranspiler.zig +++ b/src/bun.js/api/JSTranspiler.zig @@ -74,6 +74,7 @@ const TranspilerOptions = struct { minify_whitespace: bool = false, minify_identifiers: bool = false, + minify_syntax: bool = false, }; // Mimalloc gets unstable if we try to move this to a different thread @@ -534,6 +535,27 @@ fn transformOptionsFromJSC(globalObject: JSC.C.JSContextRef, temp_allocator: std transpiler.minify_whitespace = flag.toBoolean(); } + if (object.getTruthy(globalThis, "minify")) |hot| { + if (hot.isBoolean()) { + transpiler.minify_whitespace = hot.coerce(bool, globalThis); + transpiler.minify_syntax = transpiler.minify_whitespace; + transpiler.minify_identifiers = transpiler.minify_syntax; + } else if (hot.isObject()) { + if (try hot.getOptional(globalThis, "whitespace", bool)) |whitespace| { + transpiler.minify_whitespace = whitespace; + } + if (try hot.getOptional(globalThis, "syntax", bool)) |syntax| { + transpiler.minify_syntax = syntax; + } + if (try hot.getOptional(globalThis, "identifiers", bool)) |syntax| { + transpiler.minify_identifiers = syntax; + } + } else { + JSC.throwInvalidArguments("Expected minify to be a boolean or an object", .{}, globalObject, exception); + return transpiler; + } + } + if (object.get(globalThis, "sourcemap")) |flag| { if (flag.isBoolean() or flag.isUndefinedOrNull()) { if (flag.toBoolean()) { @@ -774,6 +796,14 @@ pub fn constructor( } bundler.options.minify_whitespace = transpiler_options.minify_whitespace; + + // Keep defaults for these + if (transpiler_options.minify_syntax) + bundler.options.minify_syntax = true; + + if (transpiler_options.minify_identifiers) + bundler.options.minify_identifiers = true; + bundler.options.tree_shaking = transpiler_options.tree_shaking; bundler.options.trim_unused_imports = transpiler_options.trim_unused_imports; bundler.options.allow_runtime = transpiler_options.runtime.allow_runtime; |