@teleporthq/teleport-plugin-common 0.45.3-alpha.0 → 0.45.13

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.
Files changed (200) hide show
  1. package/__tests__/builders/html-builders.ts +9 -2
  2. package/__tests__/builders/style-builders.ts +135 -1
  3. package/__tests__/node-handlers/node-to-html/index.ts +2 -0
  4. package/__tests__/node-handlers/node-to-jsx/attribute-value-mapper.ts +77 -0
  5. package/__tests__/node-handlers/node-to-jsx/calendar-events-reviver.ts +176 -0
  6. package/__tests__/node-handlers/node-to-jsx/chart-data-guard.ts +101 -0
  7. package/__tests__/node-handlers/node-to-jsx/cms-list-repeater-ecommerce-source.ts +79 -0
  8. package/__tests__/node-handlers/node-to-jsx/cms-list-repeater-loading.ts +122 -0
  9. package/__tests__/node-handlers/node-to-jsx/index.ts +719 -3
  10. package/__tests__/node-handlers/node-to-jsx/url-search-params-expression.ts +59 -0
  11. package/__tests__/node-handlers/node-to-jsx/utils.ts +635 -3
  12. package/__tests__/utils/ast-utils.ts +188 -0
  13. package/__tests__/utils/content-property-sanitiser.ts +156 -0
  14. package/__tests__/utils/page-seeds-state-from-data-source.ts +70 -0
  15. package/__tests__/utils/parse-string-with-template-expressions.ts +82 -0
  16. package/__tests__/utils/resource-auth-scheme.ts +55 -0
  17. package/__tests__/utils/route-utils.ts +118 -0
  18. package/__tests__/utils/style-utils.ts +59 -0
  19. package/__tests__/utils/template-expression-balance.ts +83 -0
  20. package/__tests__/utils/url-query-writer.ts +239 -0
  21. package/__tests__/utils/url-search-param-sync.ts +138 -0
  22. package/__tests__/utils/url-search-params.ts +48 -0
  23. package/dist/cjs/builders/ast-builders.d.ts +2 -0
  24. package/dist/cjs/builders/ast-builders.d.ts.map +1 -1
  25. package/dist/cjs/builders/ast-builders.js +41 -3
  26. package/dist/cjs/builders/ast-builders.js.map +1 -1
  27. package/dist/cjs/builders/hast-builders.d.ts +1 -0
  28. package/dist/cjs/builders/hast-builders.d.ts.map +1 -1
  29. package/dist/cjs/builders/hast-builders.js +11 -1
  30. package/dist/cjs/builders/hast-builders.js.map +1 -1
  31. package/dist/cjs/builders/style-builders.d.ts +8 -2
  32. package/dist/cjs/builders/style-builders.d.ts.map +1 -1
  33. package/dist/cjs/builders/style-builders.js +80 -33
  34. package/dist/cjs/builders/style-builders.js.map +1 -1
  35. package/dist/cjs/index.d.ts +5 -1
  36. package/dist/cjs/index.d.ts.map +1 -1
  37. package/dist/cjs/index.js +10 -1
  38. package/dist/cjs/index.js.map +1 -1
  39. package/dist/cjs/node-handlers/node-to-html/constants.d.ts.map +1 -1
  40. package/dist/cjs/node-handlers/node-to-html/constants.js +2 -0
  41. package/dist/cjs/node-handlers/node-to-html/constants.js.map +1 -1
  42. package/dist/cjs/node-handlers/node-to-html/index.d.ts.map +1 -1
  43. package/dist/cjs/node-handlers/node-to-html/index.js +69 -1
  44. package/dist/cjs/node-handlers/node-to-html/index.js.map +1 -1
  45. package/dist/cjs/node-handlers/node-to-html/types.d.ts +5 -1
  46. package/dist/cjs/node-handlers/node-to-html/types.d.ts.map +1 -1
  47. package/dist/cjs/node-handlers/node-to-html/utils.d.ts +2 -1
  48. package/dist/cjs/node-handlers/node-to-html/utils.d.ts.map +1 -1
  49. package/dist/cjs/node-handlers/node-to-html/utils.js +174 -13
  50. package/dist/cjs/node-handlers/node-to-html/utils.js.map +1 -1
  51. package/dist/cjs/node-handlers/node-to-jsx/index.d.ts.map +1 -1
  52. package/dist/cjs/node-handlers/node-to-jsx/index.js +1443 -45
  53. package/dist/cjs/node-handlers/node-to-jsx/index.js.map +1 -1
  54. package/dist/cjs/node-handlers/node-to-jsx/types.d.ts +60 -6
  55. package/dist/cjs/node-handlers/node-to-jsx/types.d.ts.map +1 -1
  56. package/dist/cjs/node-handlers/node-to-jsx/utils.d.ts +80 -7
  57. package/dist/cjs/node-handlers/node-to-jsx/utils.d.ts.map +1 -1
  58. package/dist/cjs/node-handlers/node-to-jsx/utils.js +883 -72
  59. package/dist/cjs/node-handlers/node-to-jsx/utils.js.map +1 -1
  60. package/dist/cjs/tsconfig.tsbuildinfo +1 -1
  61. package/dist/cjs/utils/ast-utils.d.ts +163 -11
  62. package/dist/cjs/utils/ast-utils.d.ts.map +1 -1
  63. package/dist/cjs/utils/ast-utils.js +1013 -75
  64. package/dist/cjs/utils/ast-utils.js.map +1 -1
  65. package/dist/cjs/utils/hast-utils.d.ts +8 -6
  66. package/dist/cjs/utils/hast-utils.d.ts.map +1 -1
  67. package/dist/cjs/utils/hast-utils.js +28 -4
  68. package/dist/cjs/utils/hast-utils.js.map +1 -1
  69. package/dist/cjs/utils/nested-selector-commas.d.ts +2 -0
  70. package/dist/cjs/utils/nested-selector-commas.d.ts.map +1 -0
  71. package/dist/cjs/utils/nested-selector-commas.js +81 -0
  72. package/dist/cjs/utils/nested-selector-commas.js.map +1 -0
  73. package/dist/cjs/utils/route-utils.d.ts +117 -0
  74. package/dist/cjs/utils/route-utils.d.ts.map +1 -0
  75. package/dist/cjs/utils/route-utils.js +212 -0
  76. package/dist/cjs/utils/route-utils.js.map +1 -0
  77. package/dist/cjs/utils/style-utils.d.ts +1 -0
  78. package/dist/cjs/utils/style-utils.d.ts.map +1 -1
  79. package/dist/cjs/utils/style-utils.js +181 -2
  80. package/dist/cjs/utils/style-utils.js.map +1 -1
  81. package/dist/cjs/utils/template-expression-balance.d.ts +58 -0
  82. package/dist/cjs/utils/template-expression-balance.d.ts.map +1 -0
  83. package/dist/cjs/utils/template-expression-balance.js +181 -0
  84. package/dist/cjs/utils/template-expression-balance.js.map +1 -0
  85. package/dist/cjs/utils/types.d.ts +3 -0
  86. package/dist/cjs/utils/types.d.ts.map +1 -0
  87. package/dist/cjs/utils/types.js +3 -0
  88. package/dist/cjs/utils/types.js.map +1 -0
  89. package/dist/cjs/utils/url-query-writer.d.ts +123 -0
  90. package/dist/cjs/utils/url-query-writer.d.ts.map +1 -0
  91. package/dist/cjs/utils/url-query-writer.js +260 -0
  92. package/dist/cjs/utils/url-query-writer.js.map +1 -0
  93. package/dist/cjs/utils/url-search-param-sync.d.ts +4 -0
  94. package/dist/cjs/utils/url-search-param-sync.d.ts.map +1 -0
  95. package/dist/cjs/utils/url-search-param-sync.js +241 -0
  96. package/dist/cjs/utils/url-search-param-sync.js.map +1 -0
  97. package/dist/cjs/utils/url-search-params.d.ts +48 -0
  98. package/dist/cjs/utils/url-search-params.d.ts.map +1 -0
  99. package/dist/cjs/utils/url-search-params.js +109 -0
  100. package/dist/cjs/utils/url-search-params.js.map +1 -0
  101. package/dist/esm/builders/ast-builders.d.ts +2 -0
  102. package/dist/esm/builders/ast-builders.d.ts.map +1 -1
  103. package/dist/esm/builders/ast-builders.js +40 -4
  104. package/dist/esm/builders/ast-builders.js.map +1 -1
  105. package/dist/esm/builders/hast-builders.d.ts +1 -0
  106. package/dist/esm/builders/hast-builders.d.ts.map +1 -1
  107. package/dist/esm/builders/hast-builders.js +9 -0
  108. package/dist/esm/builders/hast-builders.js.map +1 -1
  109. package/dist/esm/builders/style-builders.d.ts +8 -2
  110. package/dist/esm/builders/style-builders.d.ts.map +1 -1
  111. package/dist/esm/builders/style-builders.js +78 -32
  112. package/dist/esm/builders/style-builders.js.map +1 -1
  113. package/dist/esm/index.d.ts +5 -1
  114. package/dist/esm/index.d.ts.map +1 -1
  115. package/dist/esm/index.js +5 -1
  116. package/dist/esm/index.js.map +1 -1
  117. package/dist/esm/node-handlers/node-to-html/constants.d.ts.map +1 -1
  118. package/dist/esm/node-handlers/node-to-html/constants.js +2 -0
  119. package/dist/esm/node-handlers/node-to-html/constants.js.map +1 -1
  120. package/dist/esm/node-handlers/node-to-html/index.d.ts.map +1 -1
  121. package/dist/esm/node-handlers/node-to-html/index.js +71 -3
  122. package/dist/esm/node-handlers/node-to-html/index.js.map +1 -1
  123. package/dist/esm/node-handlers/node-to-html/types.d.ts +5 -1
  124. package/dist/esm/node-handlers/node-to-html/types.d.ts.map +1 -1
  125. package/dist/esm/node-handlers/node-to-html/utils.d.ts +2 -1
  126. package/dist/esm/node-handlers/node-to-html/utils.d.ts.map +1 -1
  127. package/dist/esm/node-handlers/node-to-html/utils.js +170 -13
  128. package/dist/esm/node-handlers/node-to-html/utils.js.map +1 -1
  129. package/dist/esm/node-handlers/node-to-jsx/index.d.ts.map +1 -1
  130. package/dist/esm/node-handlers/node-to-jsx/index.js +1442 -47
  131. package/dist/esm/node-handlers/node-to-jsx/index.js.map +1 -1
  132. package/dist/esm/node-handlers/node-to-jsx/types.d.ts +60 -6
  133. package/dist/esm/node-handlers/node-to-jsx/types.d.ts.map +1 -1
  134. package/dist/esm/node-handlers/node-to-jsx/utils.d.ts +80 -7
  135. package/dist/esm/node-handlers/node-to-jsx/utils.d.ts.map +1 -1
  136. package/dist/esm/node-handlers/node-to-jsx/utils.js +875 -70
  137. package/dist/esm/node-handlers/node-to-jsx/utils.js.map +1 -1
  138. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  139. package/dist/esm/utils/ast-utils.d.ts +163 -11
  140. package/dist/esm/utils/ast-utils.d.ts.map +1 -1
  141. package/dist/esm/utils/ast-utils.js +989 -75
  142. package/dist/esm/utils/ast-utils.js.map +1 -1
  143. package/dist/esm/utils/hast-utils.d.ts +8 -6
  144. package/dist/esm/utils/hast-utils.d.ts.map +1 -1
  145. package/dist/esm/utils/hast-utils.js +26 -3
  146. package/dist/esm/utils/hast-utils.js.map +1 -1
  147. package/dist/esm/utils/nested-selector-commas.d.ts +2 -0
  148. package/dist/esm/utils/nested-selector-commas.d.ts.map +1 -0
  149. package/dist/esm/utils/nested-selector-commas.js +77 -0
  150. package/dist/esm/utils/nested-selector-commas.js.map +1 -0
  151. package/dist/esm/utils/route-utils.d.ts +117 -0
  152. package/dist/esm/utils/route-utils.d.ts.map +1 -0
  153. package/dist/esm/utils/route-utils.js +179 -0
  154. package/dist/esm/utils/route-utils.js.map +1 -0
  155. package/dist/esm/utils/style-utils.d.ts +1 -0
  156. package/dist/esm/utils/style-utils.d.ts.map +1 -1
  157. package/dist/esm/utils/style-utils.js +179 -1
  158. package/dist/esm/utils/style-utils.js.map +1 -1
  159. package/dist/esm/utils/template-expression-balance.d.ts +58 -0
  160. package/dist/esm/utils/template-expression-balance.d.ts.map +1 -0
  161. package/dist/esm/utils/template-expression-balance.js +174 -0
  162. package/dist/esm/utils/template-expression-balance.js.map +1 -0
  163. package/dist/esm/utils/types.d.ts +3 -0
  164. package/dist/esm/utils/types.d.ts.map +1 -0
  165. package/dist/esm/utils/types.js +2 -0
  166. package/dist/esm/utils/types.js.map +1 -0
  167. package/dist/esm/utils/url-query-writer.d.ts +123 -0
  168. package/dist/esm/utils/url-query-writer.d.ts.map +1 -0
  169. package/dist/esm/utils/url-query-writer.js +229 -0
  170. package/dist/esm/utils/url-query-writer.js.map +1 -0
  171. package/dist/esm/utils/url-search-param-sync.d.ts +4 -0
  172. package/dist/esm/utils/url-search-param-sync.d.ts.map +1 -0
  173. package/dist/esm/utils/url-search-param-sync.js +213 -0
  174. package/dist/esm/utils/url-search-param-sync.js.map +1 -0
  175. package/dist/esm/utils/url-search-params.d.ts +48 -0
  176. package/dist/esm/utils/url-search-params.d.ts.map +1 -0
  177. package/dist/esm/utils/url-search-params.js +81 -0
  178. package/dist/esm/utils/url-search-params.js.map +1 -0
  179. package/package.json +4 -4
  180. package/src/builders/ast-builders.ts +80 -3
  181. package/src/builders/hast-builders.ts +11 -0
  182. package/src/builders/style-builders.ts +121 -43
  183. package/src/index.ts +22 -1
  184. package/src/node-handlers/node-to-html/constants.ts +2 -0
  185. package/src/node-handlers/node-to-html/index.ts +126 -6
  186. package/src/node-handlers/node-to-html/types.ts +6 -0
  187. package/src/node-handlers/node-to-html/utils.ts +228 -14
  188. package/src/node-handlers/node-to-jsx/index.ts +2135 -62
  189. package/src/node-handlers/node-to-jsx/types.ts +75 -32
  190. package/src/node-handlers/node-to-jsx/utils.ts +1173 -84
  191. package/src/utils/ast-utils.ts +1316 -127
  192. package/src/utils/hast-utils.ts +37 -9
  193. package/src/utils/nested-selector-commas.ts +88 -0
  194. package/src/utils/route-utils.ts +214 -0
  195. package/src/utils/style-utils.ts +183 -1
  196. package/src/utils/template-expression-balance.ts +196 -0
  197. package/src/utils/types.ts +25 -0
  198. package/src/utils/url-query-writer.ts +318 -0
  199. package/src/utils/url-search-param-sync.ts +303 -0
  200. package/src/utils/url-search-params.ts +122 -0
@@ -0,0 +1,181 @@
1
+ "use strict";
2
+ /**
3
+ * Delimiter balancing for `{{ … }}` binding expressions.
4
+ *
5
+ * THE DEFECT THIS EXISTS FOR. `parseStringWithTemplateExpressions` converted a
6
+ * UIDL string into a template literal and then handed the result straight to
7
+ * Babel. When the binding inside was unbalanced the produced source did not
8
+ * parse, `parse()` threw, and — because the inline-style caller has no
9
+ * try/catch — the SyntaxError escaped all the way out and killed the ENTIRE
10
+ * project build:
11
+ *
12
+ * const x = `translateX(${-(cameraX || ''}px) }px)`
13
+ * ^ Unexpected token, expected ","
14
+ *
15
+ * Two separate faults produced that line. The interpolated expression
16
+ * `-(cameraX || ''` was missing its closing paren, and the "re-close the CSS
17
+ * function" step counted parentheses across the WHOLE string — including the
18
+ * ones inside `${…}` — decided one was missing, and appended `px)` to the end,
19
+ * which could never help because the imbalance was inside the interpolation.
20
+ *
21
+ * One bad binding in one style property must never cost a project its build.
22
+ * These helpers make the imbalance repairable where it actually is, and let the
23
+ * caller degrade a single value instead of aborting.
24
+ */
25
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
26
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
27
+ if (ar || !(i in from)) {
28
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
29
+ ar[i] = from[i];
30
+ }
31
+ }
32
+ return to.concat(ar || Array.prototype.slice.call(from));
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.countUnclosedStaticParens = exports.balanceExpression = exports.isBalancedExpression = exports.scanExpression = void 0;
36
+ /** Closing delimiter for each opener that nests inside an expression. */
37
+ var CLOSER_FOR_OPENER = {
38
+ '(': ')',
39
+ '[': ']',
40
+ '{': '}',
41
+ };
42
+ var CLOSERS = new Set(Object.values(CLOSER_FOR_OPENER));
43
+ var QUOTES = new Set(["'", '"', '`']);
44
+ /**
45
+ * Single left-to-right pass over an expression, quote and escape aware.
46
+ * Characters inside a string literal never affect nesting.
47
+ */
48
+ var scanExpression = function (expression) {
49
+ var unclosed = [];
50
+ var strayCloserCount = 0;
51
+ var quote = null;
52
+ for (var index = 0; index < expression.length; index++) {
53
+ var char = expression[index];
54
+ if (char === '\\') {
55
+ index++;
56
+ continue;
57
+ }
58
+ if (quote !== null) {
59
+ if (char === quote) {
60
+ quote = null;
61
+ }
62
+ continue;
63
+ }
64
+ if (QUOTES.has(char)) {
65
+ quote = char;
66
+ continue;
67
+ }
68
+ if (CLOSER_FOR_OPENER[char]) {
69
+ unclosed.push(char);
70
+ continue;
71
+ }
72
+ if (CLOSERS.has(char)) {
73
+ var expected = unclosed.length > 0 ? CLOSER_FOR_OPENER[unclosed[unclosed.length - 1]] : null;
74
+ if (expected === char) {
75
+ unclosed.pop();
76
+ }
77
+ else {
78
+ strayCloserCount++;
79
+ }
80
+ }
81
+ }
82
+ return { unclosed: unclosed, strayCloserCount: strayCloserCount, unterminatedQuote: quote };
83
+ };
84
+ exports.scanExpression = scanExpression;
85
+ /** True when every quote and bracket closes and no closer is stray. */
86
+ var isBalancedExpression = function (expression) {
87
+ var scan = (0, exports.scanExpression)(expression);
88
+ return (scan.unclosed.length === 0 && scan.strayCloserCount === 0 && scan.unterminatedQuote === null);
89
+ };
90
+ exports.isBalancedExpression = isBalancedExpression;
91
+ /**
92
+ * Close an expression that ends mid-quote or mid-bracket:
93
+ * `-(cameraX || ''` → `-(cameraX || '')`.
94
+ *
95
+ * Returns the expression unchanged when it is already balanced, and when the
96
+ * imbalance is a STRAY CLOSER — appending cannot fix a missing opener, and
97
+ * inventing one would be a guess.
98
+ */
99
+ var balanceExpression = function (expression) {
100
+ var scan = (0, exports.scanExpression)(expression);
101
+ if (scan.strayCloserCount > 0) {
102
+ return expression;
103
+ }
104
+ if (scan.unclosed.length === 0 && scan.unterminatedQuote === null) {
105
+ return expression;
106
+ }
107
+ var suffix = __spreadArray([scan.unterminatedQuote || ''], unclosedInReverse(scan.unclosed), true).join('');
108
+ return expression + suffix;
109
+ };
110
+ exports.balanceExpression = balanceExpression;
111
+ var unclosedInReverse = function (unclosed) {
112
+ return unclosed
113
+ .slice()
114
+ .reverse()
115
+ .map(function (opener) { return CLOSER_FOR_OPENER[opener]; });
116
+ };
117
+ /**
118
+ * Parenthesis balance of the STATIC parts of a template string — everything
119
+ * outside `${…}`.
120
+ *
121
+ * This is the number the "re-close the CSS function" step needs. Counting over
122
+ * the whole string mixes in the expressions' own parentheses, so an imbalance
123
+ * INSIDE an interpolation reads as a missing close on the CSS function and the
124
+ * step appends a unit and a `)` that belong nowhere.
125
+ */
126
+ var countUnclosedStaticParens = function (templateStr) {
127
+ var depth = 0;
128
+ var index = 0;
129
+ while (index < templateStr.length) {
130
+ if (templateStr[index] === '$' && templateStr[index + 1] === '{') {
131
+ index = skipInterpolation(templateStr, index + 2);
132
+ continue;
133
+ }
134
+ if (templateStr[index] === '(') {
135
+ depth++;
136
+ }
137
+ else if (templateStr[index] === ')') {
138
+ depth--;
139
+ }
140
+ index++;
141
+ }
142
+ return depth > 0 ? depth : 0;
143
+ };
144
+ exports.countUnclosedStaticParens = countUnclosedStaticParens;
145
+ /**
146
+ * Index just past the `}` that closes an interpolation opened at `start`.
147
+ * Tracks nested braces and string literals so `${ {a:'}'} }` is skipped whole.
148
+ * An unterminated interpolation consumes the rest of the string.
149
+ */
150
+ var skipInterpolation = function (templateStr, start) {
151
+ var depth = 1;
152
+ var quote = null;
153
+ for (var index = start; index < templateStr.length; index++) {
154
+ var char = templateStr[index];
155
+ if (char === '\\') {
156
+ index++;
157
+ continue;
158
+ }
159
+ if (quote !== null) {
160
+ if (char === quote) {
161
+ quote = null;
162
+ }
163
+ continue;
164
+ }
165
+ if (QUOTES.has(char)) {
166
+ quote = char;
167
+ continue;
168
+ }
169
+ if (char === '{') {
170
+ depth++;
171
+ }
172
+ else if (char === '}') {
173
+ depth--;
174
+ if (depth === 0) {
175
+ return index + 1;
176
+ }
177
+ }
178
+ }
179
+ return templateStr.length;
180
+ };
181
+ //# sourceMappingURL=template-expression-balance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template-expression-balance.js","sourceRoot":"","sources":["../../../src/utils/template-expression-balance.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;;;;;;;;;;AAEH,yEAAyE;AACzE,IAAM,iBAAiB,GAA2B;IAChD,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;CACT,CAAA;AAED,IAAM,OAAO,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAA;AACzD,IAAM,MAAM,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CAAA;AAWvC;;;GAGG;AACI,IAAM,cAAc,GAAG,UAAC,UAAkB;IAC/C,IAAM,QAAQ,GAAa,EAAE,CAAA;IAC7B,IAAI,gBAAgB,GAAG,CAAC,CAAA;IACxB,IAAI,KAAK,GAAkB,IAAI,CAAA;IAE/B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,UAAU,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QACtD,IAAM,IAAI,GAAG,UAAU,CAAC,KAAK,CAAC,CAAA;QAE9B,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,KAAK,EAAE,CAAA;YACP,SAAQ;SACT;QAED,IAAI,KAAK,KAAK,IAAI,EAAE;YAClB,IAAI,IAAI,KAAK,KAAK,EAAE;gBAClB,KAAK,GAAG,IAAI,CAAA;aACb;YACD,SAAQ;SACT;QAED,IAAI,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,6BAkBrC;AAED;;;;GAIG;AACH,IAAM,iBAAiB,GAAG,UAAC,WAAmB,EAAE,KAAa;IAC3D,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,IAAI,KAAK,GAAkB,IAAI,CAAA;IAE/B,KAAK,IAAI,KAAK,GAAG,KAAK,EAAE,KAAK,GAAG,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAC3D,IAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,CAAA;QAE/B,IAAI,IAAI,KAAK,IAAI,EAAE;YACjB,KAAK,EAAE,CAAA;YACP,SAAQ;SACT;QAED,IAAI,KAAK,KAAK,IAAI,EAAE;YAClB,IAAI,IAAI,KAAK,KAAK,EAAE;gBAClB,KAAK,GAAG,IAAI,CAAA;aACb;YACD,SAAQ;SACT;QAED,IAAI,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE;YACpB,KAAK,GAAG,IAAI,CAAA;YACZ,SAAQ;SACT;QAED,IAAI,IAAI,KAAK,GAAG,EAAE;YAChB,KAAK,EAAE,CAAA;SACR;aAAM,IAAI,IAAI,KAAK,GAAG,EAAE;YACvB,KAAK,EAAE,CAAA;YACP,IAAI,KAAK,KAAK,CAAC,EAAE;gBACf,OAAO,KAAK,GAAG,CAAC,CAAA;aACjB;SACF;KACF;IAED,OAAO,WAAW,CAAC,MAAM,CAAA;AAC3B,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ export type BinaryOperator = '===' | '+' | '-' | '/' | '%' | '*' | '**' | '&' | '|' | '>>' | '>>>' | '<<' | '^' | '==' | '!=' | '!==' | 'in' | 'instanceof' | '>' | '<' | '>=' | '<=';
2
+ export type UnaryOperation = '+' | '-' | 'void' | 'throw' | 'delete' | '!' | '~' | 'typeof';
3
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/utils/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GACtB,KAAK,GACL,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,GAAG,GACH,IAAI,GACJ,GAAG,GACH,GAAG,GACH,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,GAAG,GACH,IAAI,GACJ,IAAI,GACJ,KAAK,GACL,IAAI,GACJ,YAAY,GACZ,GAAG,GACH,GAAG,GACH,IAAI,GACJ,IAAI,CAAA;AAER,MAAM,MAAM,cAAc,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,GAAG,GAAG,GAAG,GAAG,QAAQ,CAAA"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/utils/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,123 @@
1
+ import * as types from '@babel/types';
2
+ /**
3
+ * The ONE place a generated page is allowed to write `router.query` from.
4
+ *
5
+ * ## The defect this exists to make impossible
6
+ *
7
+ * Every URL-bound control used to own a `useEffect` that did
8
+ *
9
+ * const __nextQuery = { ...router.query } // its own snapshot
10
+ * __nextQuery.categoryFilter = 'Rings'
11
+ * router.replace({ pathname, query: __nextQuery }, undefined, { shallow: true })
12
+ *
13
+ * `router.query` is a per-render SHALLOW COPY that Next rebuilds only when the
14
+ * router itself re-renders (`makePublicRouterInstance` — "makes sure query is
15
+ * not stateful"), and `router.replace` updates it asynchronously. So two
16
+ * controls writing in the same flush both spread the SAME pre-change object,
17
+ * and whichever `replace` commits last silently drops the key the other had
18
+ * just added — or resurrects one it had just deleted.
19
+ *
20
+ * That is not a rare interleaving; it is the common one. Changing a filter
21
+ * resets the page, so the filter's write-back and the page's write-back always
22
+ * fire together.
23
+ *
24
+ * ⛔ And the damage does not stop at a wrong URL. Each control also has a
25
+ * READ-BACK effect that pushes `router.query` back into React state. Once a key
26
+ * is erased, the read-back clears that control's state, the write-back
27
+ * re-asserts it, the next landing erases it again — and because each round
28
+ * reads the other side's PRE-flush value, the pair computes
29
+ * `(state, url) -> (url, state)`: a swap. A swap has no fixed point off the
30
+ * diagonal, so it never converges. The observed symptom was a products list
31
+ * that re-fetched and flickered forever after picking a category while on
32
+ * page 5.
33
+ *
34
+ * ## The fix
35
+ *
36
+ * Nobody spreads `router.query` any more. All writers go through one function
37
+ * that merges into `pending` — the last query this component ASKED for —
38
+ * falling back to `router.query` only when nothing is in flight. The second
39
+ * write of a flush therefore builds on the first's payload instead of racing
40
+ * it, no key is ever lost, and with no key lost there is nothing for a
41
+ * read-back to disagree about.
42
+ *
43
+ * `pending` is dropped once every replace it was built from has settled, so an
44
+ * external navigation (a Link, browser back/forward) is never merged into a
45
+ * stale snapshot.
46
+ *
47
+ * @see `buildUrlWriteBackEffect` in `./url-search-param-sync` and
48
+ * `buildPageUrlSyncEffect` in `teleport-plugin-next-data-source` — the two
49
+ * callers, in two different packages, which is why this lives here.
50
+ */
51
+ /** `useRef` holding `{ pending, inFlight }`. Shared by every writer in a component. */
52
+ export declare const QUERY_SYNC_REF_ID = "__tqQuerySyncRef";
53
+ /** The write function every URL-bound control calls. */
54
+ export declare const QUERY_WRITER_ID = "__tqWriteQueryParam";
55
+ /**
56
+ * `__tqQuerySyncRef.current.inFlight === 0` — "the URL is settled".
57
+ *
58
+ * The page-URL effect uses it to gate its ADOPT branch: while a replace this
59
+ * component issued is still landing, `router.query` is a value the page is on
60
+ * its way OUT of, and adopting it would undo the move that is in flight.
61
+ */
62
+ export declare const buildQuerySettledExpr: () => types.BinaryExpression;
63
+ /** `__tqWriteQueryParam('<paramKey>', <valueExpr>)` — `undefined` removes the key. */
64
+ export declare const buildQueryWriteCall: (paramKey: string, valueExpr: types.Expression) => types.ExpressionStatement;
65
+ /**
66
+ * True when a previous plugin already emitted the declarations.
67
+ *
68
+ * Both `createNextUrlSearchParamsPlugin` and
69
+ * `createNextArrayMapperPaginationPlugin` can be the first to need them on the
70
+ * same component, and neither knows whether the other ran.
71
+ */
72
+ export declare const hasQuerySyncDeclarations: (body: types.Statement[]) => boolean;
73
+ /**
74
+ * Emitted shape:
75
+ *
76
+ * const __tqQuerySyncRef = useRef({ pending: null, inFlight: 0 })
77
+ * const __tqWriteQueryParam = (key, value) => {
78
+ * const base = __tqQuerySyncRef.current.pending || router.query
79
+ * const next = { ...base }
80
+ * if (value === undefined || value === null || value === '') { delete next[key] }
81
+ * else { next[key] = String(value) }
82
+ * if (next[key] === base[key]) return
83
+ * __tqQuerySyncRef.current.pending = next
84
+ * __tqQuerySyncRef.current.inFlight += 1
85
+ * const settle = () => {
86
+ * __tqQuerySyncRef.current.inFlight -= 1
87
+ * if (__tqQuerySyncRef.current.inFlight <= 0) {
88
+ * __tqQuerySyncRef.current.inFlight = 0
89
+ * __tqQuerySyncRef.current.pending = null
90
+ * }
91
+ * }
92
+ * Promise.resolve(
93
+ * router.replace({ pathname: router.pathname, query: next }, undefined, { shallow: true })
94
+ * ).then(settle, settle)
95
+ * }
96
+ *
97
+ * Notes on the details that are load-bearing:
98
+ *
99
+ * - `next[key] === base[key]` is the ONLY bail. Comparing against the pending
100
+ * query rather than `router.query` is what makes a re-render during an
101
+ * in-flight replace a no-op instead of a duplicate write.
102
+ * - Bracket access, so a URL key that is not a JS identifier (`foo-bar`) works
103
+ * without the callers having to care.
104
+ * - `String(value)` here rather than at each call site — a number page and a
105
+ * string category then serialise identically.
106
+ * - `Promise.resolve(...)` wraps the `replace` because a stubbed router in a
107
+ * test may return a plain value; `.then(settle, settle)` releases the pending
108
+ * query on a rejected (cancelled) navigation too, so one failed replace cannot
109
+ * freeze every later write against a stale base.
110
+ * - `shallow: true` keeps `getStaticProps` out of it: the data is driven by the
111
+ * params memo, not by the URL.
112
+ */
113
+ export declare const buildQuerySyncDeclarations: () => types.Statement[];
114
+ /**
115
+ * Inserts the declarations once, immediately after `const router = useRouter()`
116
+ * when that is already in the body (it is a plain closure over `router`, so the
117
+ * order only matters for readability — nothing reads it before an effect runs).
118
+ *
119
+ * @returns `true` when it inserted, so the caller can register the `useRef`
120
+ * import dependency only when it is actually needed.
121
+ */
122
+ export declare const ensureQuerySyncDeclarations: (body: types.Statement[]) => boolean;
123
+ //# sourceMappingURL=url-query-writer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-query-writer.d.ts","sourceRoot":"","sources":["../../../src/utils/url-query-writer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,uFAAuF;AACvF,eAAO,MAAM,iBAAiB,qBAAqB,CAAA;AAEnD,wDAAwD;AACxD,eAAO,MAAM,eAAe,wBAAwB,CAAA;AAQpD;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,QAAO,MAAM,gBAC+B,CAAA;AAE9E,sFAAsF;AACtF,eAAO,MAAM,mBAAmB,aACpB,MAAM,aACL,MAAM,UAAU,KAC1B,MAAM,mBAMN,CAAA;AAEH;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,SAAU,MAAM,SAAS,EAAE,KAAG,OAQhE,CAAA;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,eAAO,MAAM,0BAA0B,QAAO,MAAM,SAAS,EAkJ5D,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,SAAU,MAAM,SAAS,EAAE,KAAG,OAkBrE,CAAA"}
@@ -0,0 +1,260 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
26
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
27
+ if (ar || !(i in from)) {
28
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
29
+ ar[i] = from[i];
30
+ }
31
+ }
32
+ return to.concat(ar || Array.prototype.slice.call(from));
33
+ };
34
+ Object.defineProperty(exports, "__esModule", { value: true });
35
+ exports.ensureQuerySyncDeclarations = exports.buildQuerySyncDeclarations = exports.hasQuerySyncDeclarations = exports.buildQueryWriteCall = exports.buildQuerySettledExpr = exports.QUERY_WRITER_ID = exports.QUERY_SYNC_REF_ID = void 0;
36
+ var types = __importStar(require("@babel/types"));
37
+ /**
38
+ * The ONE place a generated page is allowed to write `router.query` from.
39
+ *
40
+ * ## The defect this exists to make impossible
41
+ *
42
+ * Every URL-bound control used to own a `useEffect` that did
43
+ *
44
+ * const __nextQuery = { ...router.query } // its own snapshot
45
+ * __nextQuery.categoryFilter = 'Rings'
46
+ * router.replace({ pathname, query: __nextQuery }, undefined, { shallow: true })
47
+ *
48
+ * `router.query` is a per-render SHALLOW COPY that Next rebuilds only when the
49
+ * router itself re-renders (`makePublicRouterInstance` — "makes sure query is
50
+ * not stateful"), and `router.replace` updates it asynchronously. So two
51
+ * controls writing in the same flush both spread the SAME pre-change object,
52
+ * and whichever `replace` commits last silently drops the key the other had
53
+ * just added — or resurrects one it had just deleted.
54
+ *
55
+ * That is not a rare interleaving; it is the common one. Changing a filter
56
+ * resets the page, so the filter's write-back and the page's write-back always
57
+ * fire together.
58
+ *
59
+ * ⛔ And the damage does not stop at a wrong URL. Each control also has a
60
+ * READ-BACK effect that pushes `router.query` back into React state. Once a key
61
+ * is erased, the read-back clears that control's state, the write-back
62
+ * re-asserts it, the next landing erases it again — and because each round
63
+ * reads the other side's PRE-flush value, the pair computes
64
+ * `(state, url) -> (url, state)`: a swap. A swap has no fixed point off the
65
+ * diagonal, so it never converges. The observed symptom was a products list
66
+ * that re-fetched and flickered forever after picking a category while on
67
+ * page 5.
68
+ *
69
+ * ## The fix
70
+ *
71
+ * Nobody spreads `router.query` any more. All writers go through one function
72
+ * that merges into `pending` — the last query this component ASKED for —
73
+ * falling back to `router.query` only when nothing is in flight. The second
74
+ * write of a flush therefore builds on the first's payload instead of racing
75
+ * it, no key is ever lost, and with no key lost there is nothing for a
76
+ * read-back to disagree about.
77
+ *
78
+ * `pending` is dropped once every replace it was built from has settled, so an
79
+ * external navigation (a Link, browser back/forward) is never merged into a
80
+ * stale snapshot.
81
+ *
82
+ * @see `buildUrlWriteBackEffect` in `./url-search-param-sync` and
83
+ * `buildPageUrlSyncEffect` in `teleport-plugin-next-data-source` — the two
84
+ * callers, in two different packages, which is why this lives here.
85
+ */
86
+ /** `useRef` holding `{ pending, inFlight }`. Shared by every writer in a component. */
87
+ exports.QUERY_SYNC_REF_ID = '__tqQuerySyncRef';
88
+ /** The write function every URL-bound control calls. */
89
+ exports.QUERY_WRITER_ID = '__tqWriteQueryParam';
90
+ var refCurrent = function () {
91
+ return types.memberExpression(types.identifier(exports.QUERY_SYNC_REF_ID), types.identifier('current'));
92
+ };
93
+ var refField = function (field) {
94
+ return types.memberExpression(refCurrent(), types.identifier(field));
95
+ };
96
+ /**
97
+ * `__tqQuerySyncRef.current.inFlight === 0` — "the URL is settled".
98
+ *
99
+ * The page-URL effect uses it to gate its ADOPT branch: while a replace this
100
+ * component issued is still landing, `router.query` is a value the page is on
101
+ * its way OUT of, and adopting it would undo the move that is in flight.
102
+ */
103
+ var buildQuerySettledExpr = function () {
104
+ return types.binaryExpression('===', refField('inFlight'), types.numericLiteral(0));
105
+ };
106
+ exports.buildQuerySettledExpr = buildQuerySettledExpr;
107
+ /** `__tqWriteQueryParam('<paramKey>', <valueExpr>)` — `undefined` removes the key. */
108
+ var buildQueryWriteCall = function (paramKey, valueExpr) {
109
+ return types.expressionStatement(types.callExpression(types.identifier(exports.QUERY_WRITER_ID), [
110
+ types.stringLiteral(paramKey),
111
+ valueExpr,
112
+ ]));
113
+ };
114
+ exports.buildQueryWriteCall = buildQueryWriteCall;
115
+ /**
116
+ * True when a previous plugin already emitted the declarations.
117
+ *
118
+ * Both `createNextUrlSearchParamsPlugin` and
119
+ * `createNextArrayMapperPaginationPlugin` can be the first to need them on the
120
+ * same component, and neither knows whether the other ran.
121
+ */
122
+ var hasQuerySyncDeclarations = function (body) {
123
+ return body.some(function (statement) {
124
+ return statement.type === 'VariableDeclaration' &&
125
+ statement.declarations.some(function (declarator) {
126
+ return declarator.id.type === 'Identifier' && declarator.id.name === exports.QUERY_SYNC_REF_ID;
127
+ });
128
+ });
129
+ };
130
+ exports.hasQuerySyncDeclarations = hasQuerySyncDeclarations;
131
+ /**
132
+ * Emitted shape:
133
+ *
134
+ * const __tqQuerySyncRef = useRef({ pending: null, inFlight: 0 })
135
+ * const __tqWriteQueryParam = (key, value) => {
136
+ * const base = __tqQuerySyncRef.current.pending || router.query
137
+ * const next = { ...base }
138
+ * if (value === undefined || value === null || value === '') { delete next[key] }
139
+ * else { next[key] = String(value) }
140
+ * if (next[key] === base[key]) return
141
+ * __tqQuerySyncRef.current.pending = next
142
+ * __tqQuerySyncRef.current.inFlight += 1
143
+ * const settle = () => {
144
+ * __tqQuerySyncRef.current.inFlight -= 1
145
+ * if (__tqQuerySyncRef.current.inFlight <= 0) {
146
+ * __tqQuerySyncRef.current.inFlight = 0
147
+ * __tqQuerySyncRef.current.pending = null
148
+ * }
149
+ * }
150
+ * Promise.resolve(
151
+ * router.replace({ pathname: router.pathname, query: next }, undefined, { shallow: true })
152
+ * ).then(settle, settle)
153
+ * }
154
+ *
155
+ * Notes on the details that are load-bearing:
156
+ *
157
+ * - `next[key] === base[key]` is the ONLY bail. Comparing against the pending
158
+ * query rather than `router.query` is what makes a re-render during an
159
+ * in-flight replace a no-op instead of a duplicate write.
160
+ * - Bracket access, so a URL key that is not a JS identifier (`foo-bar`) works
161
+ * without the callers having to care.
162
+ * - `String(value)` here rather than at each call site — a number page and a
163
+ * string category then serialise identically.
164
+ * - `Promise.resolve(...)` wraps the `replace` because a stubbed router in a
165
+ * test may return a plain value; `.then(settle, settle)` releases the pending
166
+ * query on a rejected (cancelled) navigation too, so one failed replace cannot
167
+ * freeze every later write against a stale base.
168
+ * - `shallow: true` keeps `getStaticProps` out of it: the data is driven by the
169
+ * params memo, not by the URL.
170
+ */
171
+ var buildQuerySyncDeclarations = function () {
172
+ var key = types.identifier('key');
173
+ var value = types.identifier('value');
174
+ var nextAtKey = function () {
175
+ return types.memberExpression(types.identifier('next'), types.cloneNode(key, true), true);
176
+ };
177
+ var settleBody = types.blockStatement([
178
+ types.expressionStatement(types.assignmentExpression('-=', refField('inFlight'), types.numericLiteral(1))),
179
+ types.ifStatement(types.binaryExpression('<=', refField('inFlight'), types.numericLiteral(0)), types.blockStatement([
180
+ types.expressionStatement(types.assignmentExpression('=', refField('inFlight'), types.numericLiteral(0))),
181
+ types.expressionStatement(types.assignmentExpression('=', refField('pending'), types.nullLiteral())),
182
+ ])),
183
+ ]);
184
+ var writerBody = types.blockStatement([
185
+ // const base = __tqQuerySyncRef.current.pending || router.query
186
+ types.variableDeclaration('const', [
187
+ types.variableDeclarator(types.identifier('base'), types.logicalExpression('||', refField('pending'), types.memberExpression(types.identifier('router'), types.identifier('query')))),
188
+ ]),
189
+ // const next = { ...base }
190
+ types.variableDeclaration('const', [
191
+ types.variableDeclarator(types.identifier('next'), types.objectExpression([types.spreadElement(types.identifier('base'))])),
192
+ ]),
193
+ types.ifStatement(types.logicalExpression('||', types.logicalExpression('||', types.binaryExpression('===', types.cloneNode(value, true), types.identifier('undefined')), types.binaryExpression('===', types.cloneNode(value, true), types.nullLiteral())), types.binaryExpression('===', types.cloneNode(value, true), types.stringLiteral(''))), types.blockStatement([
194
+ types.expressionStatement(types.unaryExpression('delete', nextAtKey())),
195
+ ]), types.blockStatement([
196
+ types.expressionStatement(types.assignmentExpression('=', nextAtKey(), types.callExpression(types.identifier('String'), [types.cloneNode(value, true)]))),
197
+ ])),
198
+ // if (next[key] === base[key]) return
199
+ types.ifStatement(types.binaryExpression('===', nextAtKey(), types.memberExpression(types.identifier('base'), types.cloneNode(key, true), true)), types.returnStatement(null)),
200
+ types.expressionStatement(types.assignmentExpression('=', refField('pending'), types.identifier('next'))),
201
+ types.expressionStatement(types.assignmentExpression('+=', refField('inFlight'), types.numericLiteral(1))),
202
+ types.variableDeclaration('const', [
203
+ types.variableDeclarator(types.identifier('settle'), types.arrowFunctionExpression([], settleBody)),
204
+ ]),
205
+ types.expressionStatement(types.callExpression(types.memberExpression(types.callExpression(types.memberExpression(types.identifier('Promise'), types.identifier('resolve')), [
206
+ types.callExpression(types.memberExpression(types.identifier('router'), types.identifier('replace')), [
207
+ types.objectExpression([
208
+ types.objectProperty(types.identifier('pathname'), types.memberExpression(types.identifier('router'), types.identifier('pathname'))),
209
+ types.objectProperty(types.identifier('query'), types.identifier('next')),
210
+ ]),
211
+ types.identifier('undefined'),
212
+ types.objectExpression([
213
+ types.objectProperty(types.identifier('shallow'), types.booleanLiteral(true)),
214
+ ]),
215
+ ]),
216
+ ]), types.identifier('then')), [types.identifier('settle'), types.identifier('settle')])),
217
+ ]);
218
+ return [
219
+ types.variableDeclaration('const', [
220
+ types.variableDeclarator(types.identifier(exports.QUERY_SYNC_REF_ID), types.callExpression(types.identifier('useRef'), [
221
+ types.objectExpression([
222
+ types.objectProperty(types.identifier('pending'), types.nullLiteral()),
223
+ types.objectProperty(types.identifier('inFlight'), types.numericLiteral(0)),
224
+ ]),
225
+ ])),
226
+ ]),
227
+ types.variableDeclaration('const', [
228
+ types.variableDeclarator(types.identifier(exports.QUERY_WRITER_ID), types.arrowFunctionExpression([key, value], writerBody)),
229
+ ]),
230
+ ];
231
+ };
232
+ exports.buildQuerySyncDeclarations = buildQuerySyncDeclarations;
233
+ /**
234
+ * Inserts the declarations once, immediately after `const router = useRouter()`
235
+ * when that is already in the body (it is a plain closure over `router`, so the
236
+ * order only matters for readability — nothing reads it before an effect runs).
237
+ *
238
+ * @returns `true` when it inserted, so the caller can register the `useRef`
239
+ * import dependency only when it is actually needed.
240
+ */
241
+ var ensureQuerySyncDeclarations = function (body) {
242
+ if ((0, exports.hasQuerySyncDeclarations)(body)) {
243
+ return false;
244
+ }
245
+ var routerIndex = body.findIndex(function (statement) {
246
+ return statement.type === 'VariableDeclaration' &&
247
+ statement.declarations.some(function (declarator) {
248
+ var _a;
249
+ return declarator.id.type === 'Identifier' &&
250
+ declarator.id.name === 'router' &&
251
+ ((_a = declarator.init) === null || _a === void 0 ? void 0 : _a.type) === 'CallExpression' &&
252
+ declarator.init.callee.type === 'Identifier' &&
253
+ declarator.init.callee.name === 'useRouter';
254
+ });
255
+ });
256
+ body.splice.apply(body, __spreadArray([routerIndex === -1 ? 0 : routerIndex + 1, 0], (0, exports.buildQuerySyncDeclarations)(), false));
257
+ return true;
258
+ };
259
+ exports.ensureQuerySyncDeclarations = ensureQuerySyncDeclarations;
260
+ //# sourceMappingURL=url-query-writer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-query-writer.js","sourceRoot":"","sources":["../../../src/utils/url-query-writer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAAqC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,GAAG,CAAC,EAAE,CAAC,GAAK,IAAA,kCAA0B,GAAE,UAAC;IACzF,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAlBY,QAAA,2BAA2B,+BAkBvC"}
@@ -0,0 +1,4 @@
1
+ import * as types from '@babel/types';
2
+ export declare const buildUrlWriteBackEffect: (paramKey: string, valueExpr: types.Expression, depExpr: types.Expression, defaultValueExpr?: types.Expression, adoptedRefName?: string) => types.ExpressionStatement;
3
+ export declare const buildUrlReadBackEffect: (paramKey: string, setterName: string, defaultValueExpr?: types.Expression, adoptedRefName?: string) => types.ExpressionStatement;
4
+ //# sourceMappingURL=url-search-param-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-search-param-sync.d.ts","sourceRoot":"","sources":["../../../src/utils/url-search-param-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAA;AAwGrC,eAAO,MAAM,uBAAuB,aACxB,MAAM,aACL,MAAM,UAAU,WAClB,MAAM,UAAU,qBACN,MAAM,UAAU,mBAClB,MAAM,KACtB,MAAM,mBA0DR,CAAA;AAyCD,eAAO,MAAM,sBAAsB,aACvB,MAAM,cACJ,MAAM,qBACC,MAAM,UAAU,mBAClB,MAAM,KACtB,MAAM,mBAwFR,CAAA"}