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

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.
@@ -0,0 +1,23 @@
1
+ /** Shields non-code spans from the regex/text-based import rewriters.
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.
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.
15
+ *
16
+ * Usage: `const { masked, restore } = maskLiterals(src)`, run the existing
17
+ * rewriter on `masked`, then `restore(rewritten)`.
18
+ */
19
+ export type MaskedSource = {
20
+ masked: string;
21
+ restore: (rewritten: string) => string;
22
+ };
23
+ export declare const maskLiterals: (src: string) => MaskedSource;
@@ -2760,6 +2760,222 @@ var init_islandSsr = __esm(() => {
2760
2760
  LEADING_HOISTED_RESOURCE_RE = /^\s*(?:<link\b[^>]*\/?>|<meta\b[^>]*\/?>|<title\b[^>]*>[\s\S]*?<\/title>|<style\b[^>]*>[\s\S]*?<\/style>|<script\b[^>]*>[\s\S]*?<\/script>)/i;
2761
2761
  });
2762
2762
 
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) => {
2765
+ const n = src.length;
2766
+ const pieces = [];
2767
+ let out = "";
2768
+ let i = 0;
2769
+ let prevChar = "";
2770
+ let prevWord = "";
2771
+ const mask = (text) => {
2772
+ out += SENTINEL + pieces.length + SENTINEL;
2773
+ pieces.push(text);
2774
+ };
2775
+ const endOfInterp = (start) => {
2776
+ let j = start;
2777
+ let depth = 1;
2778
+ while (j < n && depth > 0) {
2779
+ const c = src[j];
2780
+ if (c === "\\") {
2781
+ j += 2;
2782
+ continue;
2783
+ }
2784
+ if (c === "`") {
2785
+ j = endOfTemplate(j);
2786
+ continue;
2787
+ }
2788
+ if (c === '"' || c === "'") {
2789
+ j = endOfString(j);
2790
+ continue;
2791
+ }
2792
+ if (c === "/" && src[j + 1] === "/") {
2793
+ const nl = src.indexOf(`
2794
+ `, j);
2795
+ j = nl < 0 ? n : nl;
2796
+ continue;
2797
+ }
2798
+ if (c === "/" && src[j + 1] === "*") {
2799
+ const e = src.indexOf("*/", j + 2);
2800
+ j = e < 0 ? n : e + 2;
2801
+ continue;
2802
+ }
2803
+ if (c === "{")
2804
+ depth++;
2805
+ else if (c === "}")
2806
+ depth--;
2807
+ j++;
2808
+ }
2809
+ return j;
2810
+ };
2811
+ function endOfTemplate(start) {
2812
+ let j = start + 1;
2813
+ while (j < n) {
2814
+ const c = src[j];
2815
+ if (c === "\\") {
2816
+ j += 2;
2817
+ continue;
2818
+ }
2819
+ if (c === "`")
2820
+ return j + 1;
2821
+ if (c === "$" && src[j + 1] === "{") {
2822
+ j = endOfInterp(j + 2);
2823
+ continue;
2824
+ }
2825
+ j++;
2826
+ }
2827
+ return j;
2828
+ }
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
+ const endOfRegex = (start) => {
2848
+ let j = start + 1;
2849
+ let inClass = false;
2850
+ while (j < n) {
2851
+ const c = src[j];
2852
+ if (c === "\\") {
2853
+ j += 2;
2854
+ continue;
2855
+ }
2856
+ if (c === `
2857
+ `)
2858
+ return -1;
2859
+ if (c === "[")
2860
+ inClass = true;
2861
+ else if (c === "]")
2862
+ inClass = false;
2863
+ else if (c === "/" && !inClass) {
2864
+ j++;
2865
+ break;
2866
+ }
2867
+ j++;
2868
+ }
2869
+ while (j < n && /[a-z]/i.test(src[j] ?? ""))
2870
+ j++;
2871
+ return j;
2872
+ };
2873
+ while (i < n) {
2874
+ const c = src[i];
2875
+ const c2 = src[i + 1];
2876
+ if (c === "/" && c2 === "/") {
2877
+ out += "//";
2878
+ i += 2;
2879
+ const s = i;
2880
+ while (i < n && src[i] !== `
2881
+ `)
2882
+ i++;
2883
+ mask(src.slice(s, i));
2884
+ prevChar = "";
2885
+ prevWord = "";
2886
+ continue;
2887
+ }
2888
+ if (c === "/" && c2 === "*") {
2889
+ out += "/*";
2890
+ i += 2;
2891
+ const e = src.indexOf("*/", i);
2892
+ const end = e < 0 ? n : e;
2893
+ mask(src.slice(i, end));
2894
+ i = end < n ? end + 2 : n;
2895
+ if (end < n)
2896
+ out += "*/";
2897
+ continue;
2898
+ }
2899
+ if (c === "`") {
2900
+ const end = endOfTemplate(i);
2901
+ mask(src.slice(i, end));
2902
+ i = end;
2903
+ prevChar = "`";
2904
+ prevWord = "";
2905
+ continue;
2906
+ }
2907
+ if (c === '"' || c === "'") {
2908
+ const end = endOfString(i);
2909
+ out += src.slice(i, end);
2910
+ i = end;
2911
+ prevChar = '"';
2912
+ prevWord = "";
2913
+ continue;
2914
+ }
2915
+ if (c === "/" && (prevChar === "" || REGEX_OK_AFTER_CHAR.has(prevChar) || REGEX_OK_AFTER_WORD.has(prevWord))) {
2916
+ const end = endOfRegex(i);
2917
+ if (end > 0) {
2918
+ out += src.slice(i, end);
2919
+ i = end;
2920
+ prevChar = "/";
2921
+ prevWord = "";
2922
+ continue;
2923
+ }
2924
+ }
2925
+ out += c;
2926
+ i++;
2927
+ if (c === " " || c === "\t" || c === "\r" || c === `
2928
+ `)
2929
+ continue;
2930
+ const wasIdent = isIdentChar(prevChar);
2931
+ prevChar = c;
2932
+ prevWord = isIdentChar(c) ? wasIdent ? prevWord + c : c : "";
2933
+ }
2934
+ const restoreRegex = new RegExp(`${SENTINEL}(\\d+)${SENTINEL}`, "g");
2935
+ const restore = (rewritten) => rewritten.replace(restoreRegex, (_m, d) => pieces[Number(d)] ?? "");
2936
+ return { masked: out, restore };
2937
+ };
2938
+ var init_maskLiterals = __esm(() => {
2939
+ REGEX_OK_AFTER_CHAR = new Set([
2940
+ "(",
2941
+ ",",
2942
+ "=",
2943
+ ":",
2944
+ "[",
2945
+ "!",
2946
+ "&",
2947
+ "|",
2948
+ "?",
2949
+ "{",
2950
+ "}",
2951
+ ";",
2952
+ "+",
2953
+ "-",
2954
+ "*",
2955
+ "/",
2956
+ "%",
2957
+ "^",
2958
+ "~",
2959
+ "<",
2960
+ ">"
2961
+ ]);
2962
+ REGEX_OK_AFTER_WORD = new Set([
2963
+ "return",
2964
+ "typeof",
2965
+ "instanceof",
2966
+ "in",
2967
+ "of",
2968
+ "new",
2969
+ "delete",
2970
+ "void",
2971
+ "do",
2972
+ "else",
2973
+ "yield",
2974
+ "await",
2975
+ "case"
2976
+ ]);
2977
+ });
2978
+
2763
2979
  // src/build/nativeRewrite.ts
2764
2980
  import { dlopen, FFIType, ptr } from "bun:ffi";
2765
2981
  import { platform, arch } from "os";
@@ -2850,8 +3066,9 @@ var escapeRegex = (str) => str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), jsRewrite
2850
3066
  if (Object.keys(vendorPaths).length === 0)
2851
3067
  return content;
2852
3068
  const replacements = Object.entries(vendorPaths).sort(([keyA], [keyB]) => keyB.length - keyA.length);
2853
- const native = nativeRewriteImports(content, replacements);
2854
- return native ?? jsRewriteImports(content, replacements);
3069
+ const { masked, restore } = maskLiterals(content);
3070
+ const native = nativeRewriteImports(masked, replacements);
3071
+ return restore(native ?? jsRewriteImports(masked, replacements));
2855
3072
  }, fixMissingReExportNamespacesInContent = (content) => {
2856
3073
  const REEXPORT_PATTERN = /__reExport\(\s*[A-Za-z_$][\w$]*\s*,\s*([A-Za-z_$][\w$]*)\s*\)/g;
2857
3074
  REEXPORT_PATTERN.lastIndex = 0;
@@ -2997,6 +3214,7 @@ ${content}`;
2997
3214
  return result;
2998
3215
  };
2999
3216
  var init_rewriteImportsPlugin = __esm(() => {
3217
+ init_maskLiterals();
3000
3218
  init_nativeRewrite();
3001
3219
  });
3002
3220
 
@@ -4413,5 +4631,5 @@ export {
4413
4631
  createTypedIsland
4414
4632
  };
4415
4633
 
4416
- //# debugId=6FD656B7D1771C9464756E2164756E21
4634
+ //# debugId=7AC08283E912BA6564756E2164756E21
4417
4635
  //# sourceMappingURL=index.js.map