@absolutejs/absolute 0.19.0-beta.1078 → 0.19.0-beta.1079

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.
@@ -1,17 +1,19 @@
1
1
  /** Shields non-code spans from the regex/text-based import rewriters.
2
2
  *
3
- * The import rewriters (rewriteReactImports, rewriteImportsPlugin, and the
4
- * native Zig scanner) replace `from "X"` / `import "X"` / `import("X")` across
5
- * the whole file text. That text scan can't tell a real import from the *text*
6
- * `from 'X'` sitting inside a TEMPLATE LITERAL (an example-code snippet a page
7
- * renders) or a comment so it rewrites the snippet's specifier too. The
8
- * server pre-render keeps the snippet verbatim while the browser bundle gets it
9
- * rewritten, so the two diverge → React hydration mismatch on the code block.
3
+ * The import rewriters (rewriteReactImports, rewriteImportsPlugin, the native
4
+ * Zig scanner, and compile's runtime-specifier rewrite) replace `from "X"` /
5
+ * `import "X"` / `import("X")` / `require("X")` across the whole file text. That
6
+ * text scan can't tell a real import from the *text* `from 'X'` sitting inside a
7
+ * template literal / data string (an example-code snippet a page renders) or a
8
+ * comment so it rewrites the snippet's specifier too. The browser bundle then
9
+ * diverges from the SSR pre-render → React hydration mismatch on the code block.
10
10
  *
11
- * Fix: before rewriting, replace template literals and comment bodies with
12
- * opaque placeholders; rewrite; then restore them verbatim. Regular string
13
- * literals (where real import specifiers live) and regex literals pass through
14
- * untouched, so real import rewriting is completely unaffected.
11
+ * Fix: before rewriting, replace template literals, comments, and non-specifier
12
+ * string literals with opaque placeholders; rewrite; then restore them verbatim.
13
+ * String literals that ARE real import specifiers (those right after
14
+ * `from`/`import`, or inside `import(`/`require(`) are left untouched, so real
15
+ * import rewriting is unaffected. Regex literals are skipped (copied verbatim)
16
+ * so their contents can't be misread as strings/templates.
15
17
  *
16
18
  * Usage: `const { masked, restore } = maskLiterals(src)`, run the existing
17
19
  * rewriter on `masked`, then `restore(rewritten)`.
@@ -2761,16 +2761,39 @@ var init_islandSsr = __esm(() => {
2761
2761
  });
2762
2762
 
2763
2763
  // src/build/maskLiterals.ts
2764
- var SENTINEL = "\uE000", isIdentChar = (c) => /[A-Za-z0-9_$]/.test(c), REGEX_OK_AFTER_CHAR, REGEX_OK_AFTER_WORD, maskLiterals = (src) => {
2764
+ var SENTINEL, isIdentChar = (c) => /[A-Za-z0-9_$]/.test(c), REGEX_OK_AFTER_CHAR, REGEX_OK_AFTER_WORD, maskLiterals = (src) => {
2765
2765
  const n = src.length;
2766
2766
  const pieces = [];
2767
2767
  let out = "";
2768
2768
  let i = 0;
2769
2769
  let prevChar = "";
2770
2770
  let prevWord = "";
2771
+ let prevWasSpace = false;
2772
+ let wordBeforeParen = "";
2771
2773
  const mask = (text) => {
2772
2774
  out += SENTINEL + pieces.length + SENTINEL;
2773
2775
  pieces.push(text);
2776
+ prevChar = ")";
2777
+ prevWord = "";
2778
+ prevWasSpace = false;
2779
+ };
2780
+ const endOfString = (start) => {
2781
+ const q = src[start];
2782
+ let j = start + 1;
2783
+ while (j < n) {
2784
+ const c = src[j];
2785
+ if (c === "\\") {
2786
+ j += 2;
2787
+ continue;
2788
+ }
2789
+ if (c === q)
2790
+ return j + 1;
2791
+ if (c === `
2792
+ `)
2793
+ return j;
2794
+ j++;
2795
+ }
2796
+ return j;
2774
2797
  };
2775
2798
  const endOfInterp = (start) => {
2776
2799
  let j = start;
@@ -2826,24 +2849,6 @@ var SENTINEL = "\uE000", isIdentChar = (c) => /[A-Za-z0-9_$]/.test(c), REGEX_OK_
2826
2849
  }
2827
2850
  return j;
2828
2851
  }
2829
- function endOfString(start) {
2830
- const q = src[start];
2831
- let j = start + 1;
2832
- while (j < n) {
2833
- const c = src[j];
2834
- if (c === "\\") {
2835
- j += 2;
2836
- continue;
2837
- }
2838
- if (c === q)
2839
- return j + 1;
2840
- if (c === `
2841
- `)
2842
- return j;
2843
- j++;
2844
- }
2845
- return j;
2846
- }
2847
2852
  const endOfRegex = (start) => {
2848
2853
  let j = start + 1;
2849
2854
  let inClass = false;
@@ -2881,8 +2886,6 @@ var SENTINEL = "\uE000", isIdentChar = (c) => /[A-Za-z0-9_$]/.test(c), REGEX_OK_
2881
2886
  `)
2882
2887
  i++;
2883
2888
  mask(src.slice(s, i));
2884
- prevChar = "";
2885
- prevWord = "";
2886
2889
  continue;
2887
2890
  }
2888
2891
  if (c === "/" && c2 === "*") {
@@ -2900,16 +2903,20 @@ var SENTINEL = "\uE000", isIdentChar = (c) => /[A-Za-z0-9_$]/.test(c), REGEX_OK_
2900
2903
  const end = endOfTemplate(i);
2901
2904
  mask(src.slice(i, end));
2902
2905
  i = end;
2903
- prevChar = "`";
2904
- prevWord = "";
2905
2906
  continue;
2906
2907
  }
2907
2908
  if (c === '"' || c === "'") {
2908
2909
  const end = endOfString(i);
2909
- out += src.slice(i, end);
2910
+ const isSpecifier = prevWord === "from" || prevWord === "import" || prevChar === "(" && (wordBeforeParen === "import" || wordBeforeParen === "require");
2911
+ if (isSpecifier) {
2912
+ out += src.slice(i, end);
2913
+ prevChar = '"';
2914
+ prevWord = "";
2915
+ prevWasSpace = false;
2916
+ } else {
2917
+ mask(src.slice(i, end));
2918
+ }
2910
2919
  i = end;
2911
- prevChar = '"';
2912
- prevWord = "";
2913
2920
  continue;
2914
2921
  }
2915
2922
  if (c === "/" && (prevChar === "" || REGEX_OK_AFTER_CHAR.has(prevChar) || REGEX_OK_AFTER_WORD.has(prevWord))) {
@@ -2917,25 +2924,36 @@ var SENTINEL = "\uE000", isIdentChar = (c) => /[A-Za-z0-9_$]/.test(c), REGEX_OK_
2917
2924
  if (end > 0) {
2918
2925
  out += src.slice(i, end);
2919
2926
  i = end;
2920
- prevChar = "/";
2927
+ prevChar = ")";
2921
2928
  prevWord = "";
2929
+ prevWasSpace = false;
2922
2930
  continue;
2923
2931
  }
2924
2932
  }
2925
2933
  out += c;
2926
2934
  i++;
2927
2935
  if (c === " " || c === "\t" || c === "\r" || c === `
2928
- `)
2936
+ `) {
2937
+ prevWasSpace = true;
2929
2938
  continue;
2930
- const wasIdent = isIdentChar(prevChar);
2939
+ }
2940
+ if (isIdentChar(c)) {
2941
+ const contiguous = isIdentChar(prevChar) && !prevWasSpace;
2942
+ prevWord = contiguous ? prevWord + c : c;
2943
+ } else {
2944
+ if (c === "(")
2945
+ wordBeforeParen = prevWord;
2946
+ prevWord = "";
2947
+ }
2931
2948
  prevChar = c;
2932
- prevWord = isIdentChar(c) ? wasIdent ? prevWord + c : c : "";
2949
+ prevWasSpace = false;
2933
2950
  }
2934
2951
  const restoreRegex = new RegExp(`${SENTINEL}(\\d+)${SENTINEL}`, "g");
2935
2952
  const restore = (rewritten) => rewritten.replace(restoreRegex, (_m, d) => pieces[Number(d)] ?? "");
2936
2953
  return { masked: out, restore };
2937
2954
  };
2938
2955
  var init_maskLiterals = __esm(() => {
2956
+ SENTINEL = String.fromCharCode(57344);
2939
2957
  REGEX_OK_AFTER_CHAR = new Set([
2940
2958
  "(",
2941
2959
  ",",
@@ -4631,5 +4649,5 @@ export {
4631
4649
  createTypedIsland
4632
4650
  };
4633
4651
 
4634
- //# debugId=7AC08283E912BA6564756E2164756E21
4652
+ //# debugId=60861DEB9D7F3C6864756E2164756E21
4635
4653
  //# sourceMappingURL=index.js.map