UNPKG

dumi

Version:

📖 Documentation Generator of React Component

124 lines (122 loc) • 4.17 kB
var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/techStacks/utils.ts var utils_exports = {}; __export(utils_exports, { IDumiTechStack: () => import_types.IDumiTechStack, IDumiTechStackOnBlockLoadArgs: () => import_types.IDumiTechStackOnBlockLoadArgs, IDumiTechStackOnBlockLoadResult: () => import_types.IDumiTechStackOnBlockLoadResult, IDumiTechStackRuntimeOpts: () => import_types.IDumiTechStackRuntimeOpts, applyBabelPlugins: () => applyBabelPlugins, defineTechStack: () => defineTechStack, extractScript: () => extractScript, wrapDemoWithFn: () => wrapDemoWithFn }); module.exports = __toCommonJS(utils_exports); var import_core = require("@swc/core"); var import_types = require("../types"); function extractScript(htmlLike) { const htmlScriptReg = /<script\b(?:\s[^>]*>|>)(.*?)<\/script>/gims; let match = htmlScriptReg.exec(htmlLike); let scripts = ""; while (match) { scripts += match[1] + "\n"; match = htmlScriptReg.exec(htmlLike); } return scripts; } function applyBabelPlugins(code, opts) { const { filename, parserConfig, plugins } = opts; if (!plugins.length) return code; const babel = require("@umijs/bundler-utils/compiled/babel/core"); const parserPlugins = []; if (parserConfig.syntax === "typescript") { parserPlugins.push("typescript"); if (parserConfig.tsx) parserPlugins.push("jsx"); } else if (parserConfig.jsx) { parserPlugins.push("jsx"); } const result = babel.transformSync(code, { filename, babelrc: false, configFile: false, browserslistConfigFile: false, sourceType: "module", sourceMaps: false, compact: false, parserOpts: { plugins: parserPlugins }, plugins }); return (result == null ? void 0 : result.code) ?? code; } function wrapDemoWithFn(code, opts) { const { filename, parserConfig, babelPlugins } = opts; const source = (babelPlugins == null ? void 0 : babelPlugins.length) ? applyBabelPlugins(code, { filename, parserConfig, plugins: babelPlugins }) : code; const result = (0, import_core.transformSync)(source, { filename, jsc: { parser: parserConfig, target: "es2022", experimental: { cacheRoot: "node_modules/.cache/swc", plugins: [ [ require.resolve("../../compiled/crates/swc_plugin_react_demo.wasm"), {} ] ] } }, module: { type: "es6" } }); return `async function() { ${result.code} }`; } function defineTechStack(options) { return options; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { IDumiTechStack, IDumiTechStackOnBlockLoadArgs, IDumiTechStackOnBlockLoadResult, IDumiTechStackRuntimeOpts, applyBabelPlugins, defineTechStack, extractScript, wrapDemoWithFn });