Skip to content

Commit

Permalink
fix: bug where babel presets are stripped from final bundle
Browse files Browse the repository at this point in the history
Signed-off-by: Yoriyasu Yano <[email protected]>
  • Loading branch information
yorinasub17 committed Oct 3, 2023
1 parent f6c72e6 commit bd91f70
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 3 additions & 0 deletions decs.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
declare module "JS-Interpreter/acorn.js";
declare module "@babel/preset-env";
declare module "@babel/preset-typescript";
declare module "babel-preset-minify";
9 changes: 6 additions & 3 deletions src/engine/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
// SPDX-License-Identifier: AGPL-3.0-or-later OR BUSL-1.1

import * as babel from "@babel/core";
import babelPresetEnv from "@babel/preset-env";
import babelPresetTypescript from "@babel/preset-typescript";
import babelPresetMinify from "babel-preset-minify";

const minifyCfg = {
mangle: { exclude: "main" },
Expand Down Expand Up @@ -32,7 +35,7 @@ export function compileRuleFn(
): string {
if (!srcLang || srcLang == RuleFnSourceLang.ES5) {
return babelTransform(ruleFn, {
presets: [["babel-preset-minify", minifyCfg]],
presets: [[babelPresetMinify, minifyCfg]],
});
}

Expand All @@ -42,14 +45,14 @@ export function compileRuleFn(
// We also remove any lines surrounding the keyword "fensak remove-start" and "fensak remove-end" to support type imports.
ruleFn = removeCommentSurroundedKeyword(ruleFn);
ruleFn = babelTransform(ruleFn, {
presets: ["@babel/preset-typescript"],
presets: [babelPresetTypescript],
filename: "rule.ts",
});
}

// ruleFn is assumed to be in ES6 at this point.
return babelTransform(ruleFn, {
presets: ["@babel/preset-env", ["babel-preset-minify", minifyCfg]],
presets: [babelPresetEnv, [babelPresetMinify, minifyCfg]],
});
}

Expand Down

0 comments on commit bd91f70

Please sign in to comment.