From ab4e8129d5c94ff96e6c85d0d2b66a04a052b4e5 Mon Sep 17 00:00:00 2001
From: HelenHuang <LinHuang@pollex.com.tw>
Date: 星期四, 09 六月 2022 15:26:15 +0800
Subject: [PATCH] TODO#139888 嚴選配對 - 文案修改

---
 PAMapp/node_modules/@babel/helpers/scripts/generate-helpers.js |   55 ++++++++++++++++++++++++++++---------------------------
 1 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/PAMapp/node_modules/@babel/helpers/scripts/generate-helpers.js b/PAMapp/node_modules/@babel/helpers/scripts/generate-helpers.js
index cdc02f2..1c59746 100644
--- a/PAMapp/node_modules/@babel/helpers/scripts/generate-helpers.js
+++ b/PAMapp/node_modules/@babel/helpers/scripts/generate-helpers.js
@@ -1,18 +1,27 @@
 import fs from "fs";
 import { join } from "path";
 import { URL, fileURLToPath } from "url";
+import { minify } from "terser"; // eslint-disable-line
 
 const HELPERS_FOLDER = new URL("../src/helpers", import.meta.url);
 const IGNORED_FILES = new Set(["package.json"]);
 
-export default async function generateAsserts() {
+export default async function generateHelpers() {
   let output = `/*
  * This file is auto-generated! Do not modify it directly.
- * To re-generate run 'make build'
+ * To re-generate run 'yarn gulp generate-runtime-helpers'
  */
 
 import template from "@babel/template";
 
+function helper(minVersion, source) {
+  return Object.freeze({
+    minVersion,
+    ast: () => template.program.ast(source),
+  })
+}
+
+export default Object.freeze({
 `;
 
   for (const file of (await fs.promises.readdir(HELPERS_FOLDER)).sort()) {
@@ -20,10 +29,13 @@
     if (file.startsWith(".")) continue; // ignore e.g. vim swap files
 
     const [helperName] = file.split(".");
-    const isValidId = isValidBindingIdentifier(helperName);
-    const varName = isValidId ? helperName : `_${helperName}`;
 
     const filePath = join(fileURLToPath(HELPERS_FOLDER), file);
+    if (!file.endsWith(".js")) {
+      console.error("ignoring", filePath);
+      continue;
+    }
+
     const fileContents = await fs.promises.readFile(filePath, "utf8");
     const minVersionMatch = fileContents.match(
       /^\s*\/\*\s*@minVersion\s+(?<minVersion>\S+)\s*\*\/\s*$/m
@@ -33,31 +45,20 @@
     }
     const { minVersion } = minVersionMatch.groups;
 
-    // TODO: We can minify the helpers in production
-    const source = fileContents
-      // Remove comments
-      .replace(/\/\*[^]*?\*\/|\/\/.*/g, "")
-      // Remove multiple newlines
-      .replace(/\n{2,}/g, "\n");
+    const source = await minify(fileContents, {
+      mangle: false,
+      // The _typeof helper has a custom directive that we must keep
+      compress: { directives: false },
+    });
 
-    const intro = isValidId
-      ? "export "
-      : `export { ${varName} as ${helperName} }\n`;
-
-    output += `\n${intro}const ${varName} = {
-  minVersion: ${JSON.stringify(minVersion)},
-  ast: () => template.program.ast(${JSON.stringify(source)})
-};\n`;
+    output += `\
+  ${JSON.stringify(helperName)}: helper(
+    ${JSON.stringify(minVersion)},
+    ${JSON.stringify(source.code)},
+  ),
+`;
   }
 
+  output += "});";
   return output;
-}
-
-function isValidBindingIdentifier(name) {
-  try {
-    Function(`var ${name}`);
-    return true;
-  } catch {
-    return false;
-  }
 }

--
Gitblit v1.8.0