@absolutejs/absolute 0.19.0-beta.18 → 0.19.0-beta.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -202214,29 +202214,90 @@ var SRC_PREFIX = "/@src/", jsTranspiler2, TRANSPILABLE, REACT_EXTENSIONS, escape
202214
202214
  return `${prefix}${SRC_PREFIX}${srcPath.replace(/\\/g, "/")}${suffix}`;
202215
202215
  });
202216
202216
  return result;
202217
- }, COMPONENT_RE, injectRefreshRegistration = (code, filePath) => {
202217
+ }, HOOK_NAMES, findComponents = (code) => {
202218
202218
  const components = [];
202219
+ const exportRe = /(?:export\s+(?:default\s+)?(?:function\s+|(?:const|let|var)\s+))([A-Z][a-zA-Z0-9]*)/g;
202219
202220
  let match;
202220
- COMPONENT_RE.lastIndex = 0;
202221
- while ((match = COMPONENT_RE.exec(code)) !== null) {
202222
- if (match[1])
202223
- components.push(match[1]);
202224
- }
202221
+ while ((match = exportRe.exec(code)) !== null) {
202222
+ const name = match[1];
202223
+ if (!name)
202224
+ continue;
202225
+ const startIdx = match.index;
202226
+ const bodySlice = code.slice(startIdx, startIdx + 2000);
202227
+ const hasHooks = Array.from(HOOK_NAMES).some((hook) => bodySlice.includes(hook + "("));
202228
+ components.push({ hasHooks, name });
202229
+ }
202230
+ return components;
202231
+ }, computeHookSignature = (code, componentName) => {
202232
+ const startIdx = code.indexOf(componentName);
202233
+ if (startIdx === -1)
202234
+ return "";
202235
+ const bodySlice = code.slice(startIdx, startIdx + 2000);
202236
+ const hooks = [];
202237
+ for (const hook of HOOK_NAMES) {
202238
+ if (bodySlice.includes(hook + "("))
202239
+ hooks.push(hook);
202240
+ }
202241
+ return Buffer.from(hooks.join(",")).toString("base64").slice(0, 12);
202242
+ }, REFRESH_PREAMBLE, injectRefreshRegistration = (code, filePath, projectRoot) => {
202243
+ const components = findComponents(code);
202225
202244
  if (components.length === 0)
202226
202245
  return code;
202227
- const registrations = components.map((name) => `$RefreshReg$(${name}, ${JSON.stringify(name)});`).join(`
202246
+ const hasAnyHooks = components.some((c) => c.hasHooks);
202247
+ const sigSetup = hasAnyHooks ? `
202248
+ var _s = $RefreshSig$();` : "";
202249
+ let result = `${REFRESH_PREAMBLE}${sigSetup}
202250
+ ${code}`;
202251
+ const exportedNames = [];
202252
+ for (const comp of components) {
202253
+ if (!comp.hasHooks)
202254
+ continue;
202255
+ const sig = computeHookSignature(result, comp.name);
202256
+ result = result.replace(new RegExp(`export\\s+(?:const|let)\\s+(${comp.name}\\s*=)`), `var $1`);
202257
+ exportedNames.push(comp.name);
202258
+ result += `
202259
+ ${comp.name} = _s(${comp.name}, ${JSON.stringify(sig)});`;
202260
+ }
202261
+ if (exportedNames.length > 0) {
202262
+ result += `
202263
+ export { ${exportedNames.join(", ")} };`;
202264
+ }
202265
+ const relPath = relative6(projectRoot, filePath).replace(/\\/g, "/");
202266
+ const registrations = components.map((c) => `$RefreshReg$(${c.name}, ${JSON.stringify(`${relPath}:${c.name}`)});`).join(`
202228
202267
  `);
202229
- const sigSetup = "var _s = $RefreshSig$();";
202230
- return `${sigSetup}
202231
- ${code}
202268
+ return `${result}
202232
202269
  ${registrations}
202233
202270
  `;
202271
+ }, JSX_AUTO_RE, JSXS_AUTO_RE, JSX_PROD_RE, FRAGMENT_RE, addJsxImport = (code) => {
202272
+ const imports = [];
202273
+ const jsxDevMatch = JSX_AUTO_RE.exec(code);
202274
+ if (jsxDevMatch) {
202275
+ imports.push(`import { jsxDEV as ${jsxDevMatch[1]} } from "react/jsx-dev-runtime";`);
202276
+ }
202277
+ const jsxsMatch = JSXS_AUTO_RE.exec(code);
202278
+ if (jsxsMatch && (!jsxDevMatch || jsxsMatch[1] !== jsxDevMatch[1])) {
202279
+ imports.push(`import { jsxs as ${jsxsMatch[1]} } from "react/jsx-runtime";`);
202280
+ }
202281
+ const jsxProdMatch = JSX_PROD_RE.exec(code);
202282
+ if (jsxProdMatch) {
202283
+ imports.push(`import { jsx as ${jsxProdMatch[1]} } from "react/jsx-runtime";`);
202284
+ }
202285
+ const fragmentMatch = FRAGMENT_RE.exec(code);
202286
+ if (fragmentMatch) {
202287
+ imports.push(`import { Fragment as ${fragmentMatch[1]} } from "react";`);
202288
+ }
202289
+ if (imports.length === 0)
202290
+ return code;
202291
+ return imports.join(`
202292
+ `) + `
202293
+ ` + code;
202234
202294
  }, transformReactFile = (filePath, projectRoot, rewriter) => {
202235
202295
  const raw = readFileSync9(filePath, "utf-8");
202236
202296
  const transpiled = new Bun.Transpiler({
202237
202297
  loader: extname3(filePath) === ".jsx" ? "jsx" : "tsx"
202238
202298
  }).transformSync(raw);
202239
- const withRefresh = injectRefreshRegistration(transpiled, filePath);
202299
+ const withJsx = addJsxImport(transpiled);
202300
+ const withRefresh = injectRefreshRegistration(withJsx, filePath, projectRoot);
202240
202301
  return rewriteImports2(withRefresh, filePath, projectRoot, rewriter);
202241
202302
  }, transformPlainFile = (filePath, projectRoot, rewriter) => {
202242
202303
  const raw = readFileSync9(filePath, "utf-8");
@@ -202312,7 +202373,35 @@ var init_moduleServer = __esm(() => {
202312
202373
  jsTranspiler2 = new Bun.Transpiler({ loader: "js" });
202313
202374
  TRANSPILABLE = new Set([".ts", ".tsx", ".js", ".jsx", ".mjs"]);
202314
202375
  REACT_EXTENSIONS = new Set([".tsx", ".jsx"]);
202315
- COMPONENT_RE = /(?:export\s+(?:default\s+)?(?:function|const|let|var)\s+)([A-Z][a-zA-Z0-9]*)/g;
202376
+ HOOK_NAMES = new Set([
202377
+ "useState",
202378
+ "useReducer",
202379
+ "useEffect",
202380
+ "useLayoutEffect",
202381
+ "useMemo",
202382
+ "useCallback",
202383
+ "useRef",
202384
+ "useContext",
202385
+ "useImperativeHandle",
202386
+ "useDebugValue",
202387
+ "useDeferredValue",
202388
+ "useTransition",
202389
+ "useId",
202390
+ "useSyncExternalStore",
202391
+ "useInsertionEffect",
202392
+ "useOptimistic",
202393
+ "useFormStatus",
202394
+ "useActionState"
202395
+ ]);
202396
+ REFRESH_PREAMBLE = [
202397
+ "var $RefreshReg$ = window.$RefreshReg$ || function(){};",
202398
+ "var $RefreshSig$ = window.$RefreshSig$ || function(){ return function(t){ return t; }; };"
202399
+ ].join(`
202400
+ `);
202401
+ JSX_AUTO_RE = /\b(jsxDEV_[a-z0-9]+)\b/;
202402
+ JSXS_AUTO_RE = /\b(jsxs_[a-z0-9]+)\b/;
202403
+ JSX_PROD_RE = /\b(jsx_[a-z0-9]+)\b/;
202404
+ FRAGMENT_RE = /\b(Fragment_[a-z0-9]+)\b/;
202316
202405
  invalidateModule = invalidate;
202317
202406
  SRC_URL_PREFIX = SRC_PREFIX;
202318
202407
  });
@@ -204252,5 +204341,5 @@ export {
204252
204341
  ANGULAR_INIT_TIMEOUT_MS
204253
204342
  };
204254
204343
 
204255
- //# debugId=73726C58C12FA9FD64756E2164756E21
204344
+ //# debugId=03961D5A04FB822E64756E2164756E21
204256
204345
  //# sourceMappingURL=index.js.map