solid-refresh 0.7.1 → 0.7.3

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 (57) hide show
  1. package/dist/babel.cjs +377 -367
  2. package/dist/babel.cjs.map +1 -0
  3. package/dist/babel.mjs +377 -367
  4. package/dist/babel.mjs.map +1 -0
  5. package/dist/solid-refresh.cjs +1 -0
  6. package/dist/solid-refresh.cjs.map +1 -0
  7. package/dist/solid-refresh.mjs +1 -0
  8. package/dist/solid-refresh.mjs.map +1 -0
  9. package/dist/src/babel/core/checks.d.ts +4 -0
  10. package/dist/src/babel/core/checks.d.ts.map +1 -0
  11. package/dist/src/babel/core/constants.d.ts +8 -0
  12. package/dist/src/babel/core/constants.d.ts.map +1 -0
  13. package/dist/src/babel/core/create-registry.d.ts +5 -0
  14. package/dist/src/babel/core/create-registry.d.ts.map +1 -0
  15. package/dist/src/babel/core/generate-unique-name.d.ts +4 -0
  16. package/dist/src/babel/core/generate-unique-name.d.ts.map +1 -0
  17. package/dist/src/babel/core/generator.d.ts +3 -0
  18. package/dist/src/babel/core/generator.d.ts.map +1 -0
  19. package/dist/src/babel/core/get-descriptive-name.d.ts +3 -0
  20. package/dist/src/babel/core/get-descriptive-name.d.ts.map +1 -0
  21. package/dist/src/babel/core/get-foreign-bindings.d.ts +4 -0
  22. package/dist/src/babel/core/get-foreign-bindings.d.ts.map +1 -0
  23. package/dist/src/babel/core/get-hmr-decline-call.d.ts +4 -0
  24. package/dist/src/babel/core/get-hmr-decline-call.d.ts.map +1 -0
  25. package/dist/src/babel/core/get-hot-identifier.d.ts +4 -0
  26. package/dist/src/babel/core/get-hot-identifier.d.ts.map +1 -0
  27. package/dist/src/babel/core/get-import-identifier.d.ts +5 -0
  28. package/dist/src/babel/core/get-import-identifier.d.ts.map +1 -0
  29. package/dist/src/babel/core/get-root-statement-path.d.ts +3 -0
  30. package/dist/src/babel/core/get-root-statement-path.d.ts.map +1 -0
  31. package/dist/src/babel/core/get-statement-path.d.ts +3 -0
  32. package/dist/src/babel/core/get-statement-path.d.ts.map +1 -0
  33. package/dist/src/babel/core/get-vite-hmr-requirement.d.ts +4 -0
  34. package/dist/src/babel/core/get-vite-hmr-requirement.d.ts.map +1 -0
  35. package/dist/src/babel/core/is-valid-callee.d.ts +5 -0
  36. package/dist/src/babel/core/is-valid-callee.d.ts.map +1 -0
  37. package/dist/src/babel/core/register-import-specifiers.d.ts +5 -0
  38. package/dist/src/babel/core/register-import-specifiers.d.ts.map +1 -0
  39. package/dist/src/babel/core/transform-jsx.d.ts +4 -0
  40. package/dist/src/babel/core/transform-jsx.d.ts.map +1 -0
  41. package/dist/src/babel/core/types.d.ts +40 -0
  42. package/dist/src/babel/core/types.d.ts.map +1 -0
  43. package/dist/src/babel/core/unwrap.d.ts +11 -0
  44. package/dist/src/babel/core/unwrap.d.ts.map +1 -0
  45. package/dist/src/babel/core/xxhash32.d.ts +7 -0
  46. package/dist/src/babel/core/xxhash32.d.ts.map +1 -0
  47. package/dist/src/babel/index.d.ts +4 -21
  48. package/dist/src/babel/index.d.ts.map +1 -0
  49. package/dist/src/runtime/create-proxy.d.ts +2 -1
  50. package/dist/src/runtime/create-proxy.d.ts.map +1 -0
  51. package/dist/src/runtime/index.d.ts +14 -5
  52. package/dist/src/runtime/index.d.ts.map +1 -0
  53. package/dist/src/runtime/is-list-updated.d.ts +1 -0
  54. package/dist/src/runtime/is-list-updated.d.ts.map +1 -0
  55. package/dist/src/shared/types.d.ts +1 -0
  56. package/dist/src/shared/types.d.ts.map +1 -0
  57. package/package.json +9 -12
package/dist/babel.cjs CHANGED
@@ -1,8 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var path = require('path');
4
3
  var t = require('@babel/types');
5
- var helperModuleImports = require('@babel/helper-module-imports');
4
+ var path = require('path');
6
5
  var _generator = require('@babel/generator');
7
6
 
8
7
  function _interopNamespaceDefault(e) {
@@ -24,193 +23,6 @@ function _interopNamespaceDefault(e) {
24
23
 
25
24
  var t__namespace = /*#__PURE__*/_interopNamespaceDefault(t);
26
25
 
27
- /**
28
- * Copyright (c) 2019 Jason Dent
29
- * https://github.com/Jason3S/xxhash
30
- */
31
- const PRIME32_1 = 2654435761;
32
- const PRIME32_2 = 2246822519;
33
- const PRIME32_3 = 3266489917;
34
- const PRIME32_4 = 668265263;
35
- const PRIME32_5 = 374761393;
36
- function toUtf8(text) {
37
- const bytes = [];
38
- for (let i = 0, n = text.length; i < n; ++i) {
39
- const c = text.charCodeAt(i);
40
- if (c < 0x80) {
41
- bytes.push(c);
42
- }
43
- else if (c < 0x800) {
44
- bytes.push(0xc0 | (c >> 6), 0x80 | (c & 0x3f));
45
- }
46
- else if (c < 0xd800 || c >= 0xe000) {
47
- bytes.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));
48
- }
49
- else {
50
- const cp = 0x10000 + (((c & 0x3ff) << 10) | (text.charCodeAt(++i) & 0x3ff));
51
- bytes.push(0xf0 | ((cp >> 18) & 0x7), 0x80 | ((cp >> 12) & 0x3f), 0x80 | ((cp >> 6) & 0x3f), 0x80 | (cp & 0x3f));
52
- }
53
- }
54
- return new Uint8Array(bytes);
55
- }
56
- /**
57
- *
58
- * @param buffer - byte array or string
59
- * @param seed - optional seed (32-bit unsigned);
60
- */
61
- function xxHash32(buffer, seed = 0) {
62
- buffer = typeof buffer === 'string' ? toUtf8(buffer) : buffer;
63
- const b = buffer;
64
- /*
65
- Step 1. Initialize internal accumulators
66
- Each accumulator gets an initial value based on optional seed input. Since the seed is optional, it can be 0.
67
- ```
68
- u32 acc1 = seed + PRIME32_1 + PRIME32_2;
69
- u32 acc2 = seed + PRIME32_2;
70
- u32 acc3 = seed + 0;
71
- u32 acc4 = seed - PRIME32_1;
72
- ```
73
- Special case : input is less than 16 bytes
74
- When input is too small (< 16 bytes), the algorithm will not process any stripe. Consequently, it will not
75
- make use of parallel accumulators.
76
- In which case, a simplified initialization is performed, using a single accumulator :
77
- u32 acc = seed + PRIME32_5;
78
- The algorithm then proceeds directly to step 4.
79
- */
80
- let acc = (seed + PRIME32_5) & 0xffffffff;
81
- let offset = 0;
82
- if (b.length >= 16) {
83
- const accN = [
84
- (seed + PRIME32_1 + PRIME32_2) & 0xffffffff,
85
- (seed + PRIME32_2) & 0xffffffff,
86
- (seed + 0) & 0xffffffff,
87
- (seed - PRIME32_1) & 0xffffffff,
88
- ];
89
- /*
90
- Step 2. Process stripes
91
- A stripe is a contiguous segment of 16 bytes. It is evenly divided into 4 lanes, of 4 bytes each.
92
- The first lane is used to update accumulator 1, the second lane is used to update accumulator 2, and so on.
93
- Each lane read its associated 32-bit value using little-endian convention.
94
- For each {lane, accumulator}, the update process is called a round, and applies the following formula :
95
- ```
96
- accN = accN + (laneN * PRIME32_2);
97
- accN = accN <<< 13;
98
- accN = accN * PRIME32_1;
99
- ```
100
- This shuffles the bits so that any bit from input lane impacts several bits in output accumulator.
101
- All operations are performed modulo 2^32.
102
- Input is consumed one full stripe at a time. Step 2 is looped as many times as necessary to consume
103
- the whole input, except the last remaining bytes which cannot form a stripe (< 16 bytes). When that
104
- happens, move to step 3.
105
- */
106
- const b = buffer;
107
- const limit = b.length - 16;
108
- let lane = 0;
109
- for (offset = 0; (offset & 0xfffffff0) <= limit; offset += 4) {
110
- const i = offset;
111
- const laneN0 = b[i + 0] + (b[i + 1] << 8);
112
- const laneN1 = b[i + 2] + (b[i + 3] << 8);
113
- const laneNP = laneN0 * PRIME32_2 + ((laneN1 * PRIME32_2) << 16);
114
- let acc = (accN[lane] + laneNP) & 0xffffffff;
115
- acc = (acc << 13) | (acc >>> 19);
116
- const acc0 = acc & 0xffff;
117
- const acc1 = acc >>> 16;
118
- accN[lane] = (acc0 * PRIME32_1 + ((acc1 * PRIME32_1) << 16)) & 0xffffffff;
119
- lane = (lane + 1) & 0x3;
120
- }
121
- /*
122
- Step 3. Accumulator convergence
123
- All 4 lane accumulators from previous steps are merged to produce a single remaining accumulator
124
- of same width (32-bit). The associated formula is as follows :
125
- ```
126
- acc = (acc1 <<< 1) + (acc2 <<< 7) + (acc3 <<< 12) + (acc4 <<< 18);
127
- ```
128
- */
129
- acc =
130
- (((accN[0] << 1) | (accN[0] >>> 31)) +
131
- ((accN[1] << 7) | (accN[1] >>> 25)) +
132
- ((accN[2] << 12) | (accN[2] >>> 20)) +
133
- ((accN[3] << 18) | (accN[3] >>> 14))) &
134
- 0xffffffff;
135
- }
136
- /*
137
- Step 4. Add input length
138
- The input total length is presumed known at this stage. This step is just about adding the length to
139
- accumulator, so that it participates to final mixing.
140
- ```
141
- acc = acc + (u32)inputLength;
142
- ```
143
- */
144
- acc = (acc + buffer.length) & 0xffffffff;
145
- /*
146
- Step 5. Consume remaining input
147
- There may be up to 15 bytes remaining to consume from the input. The final stage will digest them according
148
- to following pseudo-code :
149
- ```
150
- while (remainingLength >= 4) {
151
- lane = read_32bit_little_endian(input_ptr);
152
- acc = acc + lane * PRIME32_3;
153
- acc = (acc <<< 17) * PRIME32_4;
154
- input_ptr += 4; remainingLength -= 4;
155
- }
156
- ```
157
- This process ensures that all input bytes are present in the final mix.
158
- */
159
- const limit = buffer.length - 4;
160
- for (; offset <= limit; offset += 4) {
161
- const i = offset;
162
- const laneN0 = b[i + 0] + (b[i + 1] << 8);
163
- const laneN1 = b[i + 2] + (b[i + 3] << 8);
164
- const laneP = laneN0 * PRIME32_3 + ((laneN1 * PRIME32_3) << 16);
165
- acc = (acc + laneP) & 0xffffffff;
166
- acc = (acc << 17) | (acc >>> 15);
167
- acc =
168
- ((acc & 0xffff) * PRIME32_4 + (((acc >>> 16) * PRIME32_4) << 16)) &
169
- 0xffffffff;
170
- }
171
- /*
172
- ```
173
- while (remainingLength >= 1) {
174
- lane = read_byte(input_ptr);
175
- acc = acc + lane * PRIME32_5;
176
- acc = (acc <<< 11) * PRIME32_1;
177
- input_ptr += 1; remainingLength -= 1;
178
- }
179
- ```
180
- */
181
- for (; offset < b.length; ++offset) {
182
- const lane = b[offset];
183
- acc = acc + lane * PRIME32_5;
184
- acc = (acc << 11) | (acc >>> 21);
185
- acc =
186
- ((acc & 0xffff) * PRIME32_1 + (((acc >>> 16) * PRIME32_1) << 16)) &
187
- 0xffffffff;
188
- }
189
- /*
190
- Step 6. Final mix (avalanche)
191
- The final mix ensures that all input bits have a chance to impact any bit in the output digest,
192
- resulting in an unbiased distribution. This is also called avalanche effect.
193
- ```
194
- acc = acc xor (acc >> 15);
195
- acc = acc * PRIME32_2;
196
- acc = acc xor (acc >> 13);
197
- acc = acc * PRIME32_3;
198
- acc = acc xor (acc >> 16);
199
- ```
200
- */
201
- acc = acc ^ (acc >>> 15);
202
- acc =
203
- (((acc & 0xffff) * PRIME32_2) & 0xffffffff) +
204
- (((acc >>> 16) * PRIME32_2) << 16);
205
- acc = acc ^ (acc >>> 13);
206
- acc =
207
- (((acc & 0xffff) * PRIME32_3) & 0xffffffff) +
208
- (((acc >>> 16) * PRIME32_3) << 16);
209
- acc = acc ^ (acc >>> 16);
210
- // turn any negatives back into a positive number;
211
- return acc < 0 ? acc + 4294967296 : acc;
212
- }
213
-
214
26
  // This is just a Pascal heuristic
215
27
  // we only assume a function is a component
216
28
  // if the first character is in uppercase
@@ -224,71 +36,6 @@ function getImportSpecifierName(specifier) {
224
36
  return specifier.imported.value;
225
37
  }
226
38
 
227
- function registerImportSpecifier(state, id, specifier) {
228
- if (t__namespace.isImportDefaultSpecifier(specifier)) {
229
- if (id.definition.kind === 'default') {
230
- state.registrations.identifiers.set(specifier.local, id);
231
- }
232
- return;
233
- }
234
- if (t__namespace.isImportSpecifier(specifier)) {
235
- if ((id.definition.kind === 'named' &&
236
- getImportSpecifierName(specifier) === id.definition.name) ||
237
- (id.definition.kind === 'default' &&
238
- getImportSpecifierName(specifier) === 'default')) {
239
- state.registrations.identifiers.set(specifier.local, id);
240
- }
241
- return;
242
- }
243
- let current = state.registrations.namespaces.get(specifier.local);
244
- if (!current) {
245
- current = [];
246
- }
247
- current.push(id);
248
- state.registrations.namespaces.set(specifier.local, current);
249
- }
250
- function registerImportSpecifiers(state, path, definitions) {
251
- for (let i = 0, len = definitions.length; i < len; i++) {
252
- const id = definitions[i];
253
- if (path.node.source.value === id.definition.source) {
254
- for (let k = 0, klen = path.node.specifiers.length; k < klen; k++) {
255
- registerImportSpecifier(state, id, path.node.specifiers[k]);
256
- }
257
- }
258
- }
259
- }
260
-
261
- function getHotIdentifier(state) {
262
- switch (state.bundler) {
263
- // vite/esm uses `import.meta.hot`
264
- case 'esm':
265
- case 'vite':
266
- return t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier('import'), t__namespace.identifier('meta')), t__namespace.identifier('hot'));
267
- // webpack 5 uses `import.meta.webpackHot`
268
- // rspack does as well
269
- case 'webpack5':
270
- case 'rspack-esm':
271
- return t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier('import'), t__namespace.identifier('meta')), t__namespace.identifier('webpackHot'));
272
- default:
273
- // `module.hot` is the default.
274
- return t__namespace.memberExpression(t__namespace.identifier('module'), t__namespace.identifier('hot'));
275
- }
276
- }
277
-
278
- function getImportIdentifier(state, path, registration) {
279
- const name = registration.kind === 'named' ? registration.name : 'default';
280
- const target = `${registration.source}[${name}]`;
281
- const current = state.imports.get(target);
282
- if (current) {
283
- return current;
284
- }
285
- const newID = registration.kind === 'named'
286
- ? helperModuleImports.addNamed(path, registration.name, registration.source)
287
- : helperModuleImports.addDefault(path, registration.source);
288
- state.imports.set(target, newID);
289
- return newID;
290
- }
291
-
292
39
  // Source of solid-refresh (for import)
293
40
  const SOLID_REFRESH_MODULE = 'solid-refresh';
294
41
  // Exported names from solid-refresh that will be imported
@@ -344,6 +91,54 @@ const IMPORT_SPECIFIERS = [
344
91
  },
345
92
  ];
346
93
 
94
+ function getHotIdentifier(state) {
95
+ switch (state.bundler) {
96
+ // vite/esm uses `import.meta.hot`
97
+ case 'esm':
98
+ case 'vite':
99
+ return t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier('import'), t__namespace.identifier('meta')), t__namespace.identifier('hot'));
100
+ // webpack 5 uses `import.meta.webpackHot`
101
+ // rspack does as well
102
+ case 'webpack5':
103
+ case 'rspack-esm':
104
+ return t__namespace.memberExpression(t__namespace.memberExpression(t__namespace.identifier('import'), t__namespace.identifier('meta')), t__namespace.identifier('webpackHot'));
105
+ default:
106
+ // `module.hot` is the default.
107
+ return t__namespace.memberExpression(t__namespace.identifier('module'), t__namespace.identifier('hot'));
108
+ }
109
+ }
110
+
111
+ function getImportIdentifier(state, path, registration) {
112
+ const name = registration.kind === 'named' ? registration.name : 'default';
113
+ const target = `${registration.source}[${name}]`;
114
+ const current = state.imports.get(target);
115
+ if (current) {
116
+ return current;
117
+ }
118
+ const programParent = path.scope.getProgramParent();
119
+ const uid = programParent.generateUidIdentifier(registration.kind === 'named' ? registration.name : 'default');
120
+ const newPath = programParent.path.unshiftContainer('body', t__namespace.importDeclaration([
121
+ registration.kind === 'named'
122
+ ? t__namespace.importSpecifier(uid, t__namespace.identifier(registration.name))
123
+ : t__namespace.importDefaultSpecifier(uid),
124
+ ], t__namespace.stringLiteral(registration.source)))[0];
125
+ programParent.registerDeclaration(newPath);
126
+ state.imports.set(target, uid);
127
+ return uid;
128
+ }
129
+
130
+ function getRootStatementPath(path) {
131
+ let current = path.parentPath;
132
+ while (current) {
133
+ const next = current.parentPath;
134
+ if (next && t__namespace.isProgram(next.node)) {
135
+ return current;
136
+ }
137
+ current = next;
138
+ }
139
+ return path;
140
+ }
141
+
347
142
  function generateViteHMRRequirement(state, statements, pathToHot) {
348
143
  if (state.bundler === 'vite') {
349
144
  // Vite requires that the owner module has an `import.meta.hot.accept()` call
@@ -351,6 +146,87 @@ function generateViteHMRRequirement(state, statements, pathToHot) {
351
146
  }
352
147
  }
353
148
 
149
+ const REGISTRY = 'REGISTRY';
150
+ function createRegistry(state, path) {
151
+ const current = state.imports.get(REGISTRY);
152
+ if (current) {
153
+ return current;
154
+ }
155
+ const root = getRootStatementPath(path);
156
+ const identifier = path.scope.generateUidIdentifier(REGISTRY);
157
+ const [tmp] = root.insertBefore(t__namespace.variableDeclaration('const', [
158
+ t__namespace.variableDeclarator(identifier, t__namespace.callExpression(getImportIdentifier(state, path, IMPORT_REGISTRY), [])),
159
+ ]));
160
+ root.scope.registerDeclaration(tmp);
161
+ const pathToHot = getHotIdentifier(state);
162
+ const statements = [
163
+ t__namespace.expressionStatement(t__namespace.callExpression(getImportIdentifier(state, path, IMPORT_REFRESH), [
164
+ t__namespace.stringLiteral(state.bundler),
165
+ pathToHot,
166
+ identifier,
167
+ ])),
168
+ ];
169
+ generateViteHMRRequirement(state, statements, pathToHot);
170
+ path.scope.getProgramParent().path.pushContainer('body', [
171
+ t__namespace.ifStatement(pathToHot, t__namespace.blockStatement(statements)),
172
+ ]);
173
+ state.imports.set(REGISTRY, identifier);
174
+ return identifier;
175
+ }
176
+
177
+ // https://github.com/babel/babel/issues/15269
178
+ let generator;
179
+ if (typeof _generator !== 'function') {
180
+ generator = _generator.default;
181
+ }
182
+ else {
183
+ generator = _generator;
184
+ }
185
+ function generateCode(node) {
186
+ return generator(node).code;
187
+ }
188
+
189
+ function isForeignBinding(source, current, name) {
190
+ if (source === current) {
191
+ return true;
192
+ }
193
+ if (current.scope.hasOwnBinding(name)) {
194
+ return false;
195
+ }
196
+ if (current.parentPath) {
197
+ return isForeignBinding(source, current.parentPath, name);
198
+ }
199
+ return true;
200
+ }
201
+ function isInTypescript(path) {
202
+ let parent = path.parentPath;
203
+ while (parent) {
204
+ if (t__namespace.isTypeScript(parent.node) && !t__namespace.isExpression(parent.node)) {
205
+ return true;
206
+ }
207
+ parent = parent.parentPath;
208
+ }
209
+ return false;
210
+ }
211
+ function getForeignBindings(path) {
212
+ const identifiers = new Set();
213
+ path.traverse({
214
+ ReferencedIdentifier(p) {
215
+ // Check identifiers that aren't in a TS expression
216
+ if (!isInTypescript(p) && isForeignBinding(path, p, p.node.name)) {
217
+ if (p.isIdentifier() || p.parentPath.isJSXMemberExpression()) {
218
+ identifiers.add(p.node.name);
219
+ }
220
+ }
221
+ },
222
+ });
223
+ const collected = [];
224
+ for (const identifier of identifiers) {
225
+ collected.push(t__namespace.identifier(identifier));
226
+ }
227
+ return collected;
228
+ }
229
+
354
230
  function getHMRDeclineCall(state, path) {
355
231
  const pathToHot = getHotIdentifier(state);
356
232
  const statements = [
@@ -363,6 +239,16 @@ function getHMRDeclineCall(state, path) {
363
239
  return t__namespace.ifStatement(pathToHot, t__namespace.blockStatement(statements));
364
240
  }
365
241
 
242
+ function getStatementPath(path) {
243
+ if (t__namespace.isStatement(path.node)) {
244
+ return path;
245
+ }
246
+ if (path.parentPath) {
247
+ return getStatementPath(path.parentPath);
248
+ }
249
+ return null;
250
+ }
251
+
366
252
  function isPathValid(path, key) {
367
253
  return key(path.node);
368
254
  }
@@ -432,111 +318,57 @@ function isMemberExpressionValidCallee(state, path, member, target) {
432
318
  if (!result) {
433
319
  return false;
434
320
  }
435
- return isPropertyValidCallee(result, target, member.property.name);
436
- }
437
- function isValidCallee(state, path, { callee }, target) {
438
- if (t__namespace.isV8IntrinsicIdentifier(callee)) {
439
- return false;
440
- }
441
- const trueCallee = unwrapNode(callee, t__namespace.isIdentifier);
442
- if (trueCallee) {
443
- return isIdentifierValidCallee(state, path, trueCallee, target);
444
- }
445
- const trueMember = unwrapNode(callee, t__namespace.isMemberExpression);
446
- if (trueMember && !trueMember.computed) {
447
- return isMemberExpressionValidCallee(state, path, trueMember, target);
448
- }
449
- return false;
450
- }
451
-
452
- function getStatementPath(path) {
453
- if (t__namespace.isStatement(path.node)) {
454
- return path;
455
- }
456
- if (path.parentPath) {
457
- return getStatementPath(path.parentPath);
458
- }
459
- return null;
460
- }
461
-
462
- function getRootStatementPath(path) {
463
- let current = path.parentPath;
464
- while (current) {
465
- const next = current.parentPath;
466
- if (next && t__namespace.isProgram(next.node)) {
467
- return current;
468
- }
469
- current = next;
470
- }
471
- return path;
472
- }
473
-
474
- const REGISTRY = 'REGISTRY';
475
- function createRegistry(state, path) {
476
- const current = state.imports.get(REGISTRY);
477
- if (current) {
478
- return current;
479
- }
480
- const root = getRootStatementPath(path);
481
- const identifier = path.scope.generateUidIdentifier(REGISTRY);
482
- root.insertBefore(t__namespace.variableDeclaration('const', [
483
- t__namespace.variableDeclarator(identifier, t__namespace.callExpression(getImportIdentifier(state, path, IMPORT_REGISTRY), [])),
484
- ]));
485
- const pathToHot = getHotIdentifier(state);
486
- const statements = [
487
- t__namespace.expressionStatement(t__namespace.callExpression(getImportIdentifier(state, path, IMPORT_REFRESH), [
488
- t__namespace.stringLiteral(state.bundler),
489
- pathToHot,
490
- identifier,
491
- ])),
492
- ];
493
- generateViteHMRRequirement(state, statements, pathToHot);
494
- path.scope.getProgramParent().path.pushContainer('body', [
495
- t__namespace.ifStatement(pathToHot, t__namespace.blockStatement(statements)),
496
- ]);
497
- state.imports.set(REGISTRY, identifier);
498
- return identifier;
499
- }
500
-
501
- function isForeignBinding(source, current, name) {
502
- if (source === current) {
503
- return true;
504
- }
505
- if (current.scope.hasOwnBinding(name)) {
321
+ return isPropertyValidCallee(result, target, member.property.name);
322
+ }
323
+ function isValidCallee(state, path, { callee }, target) {
324
+ if (t__namespace.isV8IntrinsicIdentifier(callee)) {
506
325
  return false;
507
326
  }
508
- if (current.parentPath) {
509
- return isForeignBinding(source, current.parentPath, name);
327
+ const trueCallee = unwrapNode(callee, t__namespace.isIdentifier);
328
+ if (trueCallee) {
329
+ return isIdentifierValidCallee(state, path, trueCallee, target);
510
330
  }
511
- return true;
331
+ const trueMember = unwrapNode(callee, t__namespace.isMemberExpression);
332
+ if (trueMember && !trueMember.computed) {
333
+ return isMemberExpressionValidCallee(state, path, trueMember, target);
334
+ }
335
+ return false;
512
336
  }
513
- function isInTypescript(path) {
514
- let parent = path.parentPath;
515
- while (parent) {
516
- if (t__namespace.isTypeScript(parent.node) && !t__namespace.isExpression(parent.node)) {
517
- return true;
337
+
338
+ function registerImportSpecifier(state, id, specifier) {
339
+ if (t__namespace.isImportDefaultSpecifier(specifier)) {
340
+ if (id.definition.kind === 'default') {
341
+ state.registrations.identifiers.set(specifier.local, id);
518
342
  }
519
- parent = parent.parentPath;
343
+ return;
520
344
  }
521
- return false;
345
+ if (t__namespace.isImportSpecifier(specifier)) {
346
+ if (specifier.importKind === 'type' || specifier.importKind === 'typeof') {
347
+ return;
348
+ }
349
+ const name = getImportSpecifierName(specifier);
350
+ if ((id.definition.kind === 'named' && name === id.definition.name) ||
351
+ (id.definition.kind === 'default' && name === 'default')) {
352
+ state.registrations.identifiers.set(specifier.local, id);
353
+ }
354
+ return;
355
+ }
356
+ let current = state.registrations.namespaces.get(specifier.local);
357
+ if (!current) {
358
+ current = [];
359
+ }
360
+ current.push(id);
361
+ state.registrations.namespaces.set(specifier.local, current);
522
362
  }
523
- function getForeignBindings(path) {
524
- const identifiers = new Set();
525
- path.traverse({
526
- ReferencedIdentifier(p) {
527
- // Check identifiers that aren't in a TS expression
528
- if (!isInTypescript(p) && isForeignBinding(path, p, p.node.name)) {
529
- if (p.isIdentifier() || p.parentPath.isJSXMemberExpression()) {
530
- identifiers.add(p.node.name);
531
- }
363
+ function registerImportSpecifiers(state, path, definitions) {
364
+ for (let i = 0, len = definitions.length; i < len; i++) {
365
+ const id = definitions[i];
366
+ if (path.node.source.value === id.definition.source) {
367
+ for (let k = 0, klen = path.node.specifiers.length; k < klen; k++) {
368
+ registerImportSpecifier(state, id, path.node.specifiers[k]);
532
369
  }
533
- },
534
- });
535
- const collected = [];
536
- for (const identifier of identifiers) {
537
- collected.push(t__namespace.identifier(identifier));
370
+ }
538
371
  }
539
- return collected;
540
372
  }
541
373
 
542
374
  function getDescriptiveName(path, defaultName) {
@@ -765,20 +597,196 @@ function transformJSX(path) {
765
597
  if (path.node.loc) {
766
598
  templateComp.loc = path.node.loc;
767
599
  }
768
- rootPath.insertBefore(t__namespace.variableDeclaration('const', [t__namespace.variableDeclarator(id, templateComp)]));
600
+ const [tmp] = rootPath.insertBefore(t__namespace.variableDeclaration('const', [t__namespace.variableDeclarator(id, templateComp)]));
601
+ rootPath.scope.registerDeclaration(tmp);
769
602
  path.replaceWith(skippableJSX(t__namespace.jsxElement(t__namespace.jsxOpeningElement(t__namespace.jsxIdentifier(id.name), [...state.attributes], true), t__namespace.jsxClosingElement(t__namespace.jsxIdentifier(id.name)), [], true)));
770
603
  }
771
604
 
772
- // https://github.com/babel/babel/issues/15269
773
- let generator;
774
- if (typeof _generator !== 'function') {
775
- generator = _generator.default;
776
- }
777
- else {
778
- generator = _generator;
605
+ /**
606
+ * Copyright (c) 2019 Jason Dent
607
+ * https://github.com/Jason3S/xxhash
608
+ */
609
+ const PRIME32_1 = 2654435761;
610
+ const PRIME32_2 = 2246822519;
611
+ const PRIME32_3 = 3266489917;
612
+ const PRIME32_4 = 668265263;
613
+ const PRIME32_5 = 374761393;
614
+ function toUtf8(text) {
615
+ const bytes = [];
616
+ for (let i = 0, n = text.length; i < n; ++i) {
617
+ const c = text.charCodeAt(i);
618
+ if (c < 0x80) {
619
+ bytes.push(c);
620
+ }
621
+ else if (c < 0x800) {
622
+ bytes.push(0xc0 | (c >> 6), 0x80 | (c & 0x3f));
623
+ }
624
+ else if (c < 0xd800 || c >= 0xe000) {
625
+ bytes.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));
626
+ }
627
+ else {
628
+ const cp = 0x10000 + (((c & 0x3ff) << 10) | (text.charCodeAt(++i) & 0x3ff));
629
+ bytes.push(0xf0 | ((cp >> 18) & 0x7), 0x80 | ((cp >> 12) & 0x3f), 0x80 | ((cp >> 6) & 0x3f), 0x80 | (cp & 0x3f));
630
+ }
631
+ }
632
+ return new Uint8Array(bytes);
779
633
  }
780
- function generateCode(node) {
781
- return generator(node).code;
634
+ /**
635
+ *
636
+ * @param buffer - byte array or string
637
+ * @param seed - optional seed (32-bit unsigned);
638
+ */
639
+ function xxHash32(buffer, seed = 0) {
640
+ buffer = typeof buffer === 'string' ? toUtf8(buffer) : buffer;
641
+ const b = buffer;
642
+ /*
643
+ Step 1. Initialize internal accumulators
644
+ Each accumulator gets an initial value based on optional seed input. Since the seed is optional, it can be 0.
645
+ ```
646
+ u32 acc1 = seed + PRIME32_1 + PRIME32_2;
647
+ u32 acc2 = seed + PRIME32_2;
648
+ u32 acc3 = seed + 0;
649
+ u32 acc4 = seed - PRIME32_1;
650
+ ```
651
+ Special case : input is less than 16 bytes
652
+ When input is too small (< 16 bytes), the algorithm will not process any stripe. Consequently, it will not
653
+ make use of parallel accumulators.
654
+ In which case, a simplified initialization is performed, using a single accumulator :
655
+ u32 acc = seed + PRIME32_5;
656
+ The algorithm then proceeds directly to step 4.
657
+ */
658
+ let acc = (seed + PRIME32_5) & 0xffffffff;
659
+ let offset = 0;
660
+ if (b.length >= 16) {
661
+ const accN = [
662
+ (seed + PRIME32_1 + PRIME32_2) & 0xffffffff,
663
+ (seed + PRIME32_2) & 0xffffffff,
664
+ (seed + 0) & 0xffffffff,
665
+ (seed - PRIME32_1) & 0xffffffff,
666
+ ];
667
+ /*
668
+ Step 2. Process stripes
669
+ A stripe is a contiguous segment of 16 bytes. It is evenly divided into 4 lanes, of 4 bytes each.
670
+ The first lane is used to update accumulator 1, the second lane is used to update accumulator 2, and so on.
671
+ Each lane read its associated 32-bit value using little-endian convention.
672
+ For each {lane, accumulator}, the update process is called a round, and applies the following formula :
673
+ ```
674
+ accN = accN + (laneN * PRIME32_2);
675
+ accN = accN <<< 13;
676
+ accN = accN * PRIME32_1;
677
+ ```
678
+ This shuffles the bits so that any bit from input lane impacts several bits in output accumulator.
679
+ All operations are performed modulo 2^32.
680
+ Input is consumed one full stripe at a time. Step 2 is looped as many times as necessary to consume
681
+ the whole input, except the last remaining bytes which cannot form a stripe (< 16 bytes). When that
682
+ happens, move to step 3.
683
+ */
684
+ const b = buffer;
685
+ const limit = b.length - 16;
686
+ let lane = 0;
687
+ for (offset = 0; (offset & 0xfffffff0) <= limit; offset += 4) {
688
+ const i = offset;
689
+ const laneN0 = b[i + 0] + (b[i + 1] << 8);
690
+ const laneN1 = b[i + 2] + (b[i + 3] << 8);
691
+ const laneNP = laneN0 * PRIME32_2 + ((laneN1 * PRIME32_2) << 16);
692
+ let acc = (accN[lane] + laneNP) & 0xffffffff;
693
+ acc = (acc << 13) | (acc >>> 19);
694
+ const acc0 = acc & 0xffff;
695
+ const acc1 = acc >>> 16;
696
+ accN[lane] = (acc0 * PRIME32_1 + ((acc1 * PRIME32_1) << 16)) & 0xffffffff;
697
+ lane = (lane + 1) & 0x3;
698
+ }
699
+ /*
700
+ Step 3. Accumulator convergence
701
+ All 4 lane accumulators from previous steps are merged to produce a single remaining accumulator
702
+ of same width (32-bit). The associated formula is as follows :
703
+ ```
704
+ acc = (acc1 <<< 1) + (acc2 <<< 7) + (acc3 <<< 12) + (acc4 <<< 18);
705
+ ```
706
+ */
707
+ acc =
708
+ (((accN[0] << 1) | (accN[0] >>> 31)) +
709
+ ((accN[1] << 7) | (accN[1] >>> 25)) +
710
+ ((accN[2] << 12) | (accN[2] >>> 20)) +
711
+ ((accN[3] << 18) | (accN[3] >>> 14))) &
712
+ 0xffffffff;
713
+ }
714
+ /*
715
+ Step 4. Add input length
716
+ The input total length is presumed known at this stage. This step is just about adding the length to
717
+ accumulator, so that it participates to final mixing.
718
+ ```
719
+ acc = acc + (u32)inputLength;
720
+ ```
721
+ */
722
+ acc = (acc + buffer.length) & 0xffffffff;
723
+ /*
724
+ Step 5. Consume remaining input
725
+ There may be up to 15 bytes remaining to consume from the input. The final stage will digest them according
726
+ to following pseudo-code :
727
+ ```
728
+ while (remainingLength >= 4) {
729
+ lane = read_32bit_little_endian(input_ptr);
730
+ acc = acc + lane * PRIME32_3;
731
+ acc = (acc <<< 17) * PRIME32_4;
732
+ input_ptr += 4; remainingLength -= 4;
733
+ }
734
+ ```
735
+ This process ensures that all input bytes are present in the final mix.
736
+ */
737
+ const limit = buffer.length - 4;
738
+ for (; offset <= limit; offset += 4) {
739
+ const i = offset;
740
+ const laneN0 = b[i + 0] + (b[i + 1] << 8);
741
+ const laneN1 = b[i + 2] + (b[i + 3] << 8);
742
+ const laneP = laneN0 * PRIME32_3 + ((laneN1 * PRIME32_3) << 16);
743
+ acc = (acc + laneP) & 0xffffffff;
744
+ acc = (acc << 17) | (acc >>> 15);
745
+ acc =
746
+ ((acc & 0xffff) * PRIME32_4 + (((acc >>> 16) * PRIME32_4) << 16)) &
747
+ 0xffffffff;
748
+ }
749
+ /*
750
+ ```
751
+ while (remainingLength >= 1) {
752
+ lane = read_byte(input_ptr);
753
+ acc = acc + lane * PRIME32_5;
754
+ acc = (acc <<< 11) * PRIME32_1;
755
+ input_ptr += 1; remainingLength -= 1;
756
+ }
757
+ ```
758
+ */
759
+ for (; offset < b.length; ++offset) {
760
+ const lane = b[offset];
761
+ acc = acc + lane * PRIME32_5;
762
+ acc = (acc << 11) | (acc >>> 21);
763
+ acc =
764
+ ((acc & 0xffff) * PRIME32_1 + (((acc >>> 16) * PRIME32_1) << 16)) &
765
+ 0xffffffff;
766
+ }
767
+ /*
768
+ Step 6. Final mix (avalanche)
769
+ The final mix ensures that all input bits have a chance to impact any bit in the output digest,
770
+ resulting in an unbiased distribution. This is also called avalanche effect.
771
+ ```
772
+ acc = acc xor (acc >> 15);
773
+ acc = acc * PRIME32_2;
774
+ acc = acc xor (acc >> 13);
775
+ acc = acc * PRIME32_3;
776
+ acc = acc xor (acc >> 16);
777
+ ```
778
+ */
779
+ acc = acc ^ (acc >>> 15);
780
+ acc =
781
+ (((acc & 0xffff) * PRIME32_2) & 0xffffffff) +
782
+ (((acc >>> 16) * PRIME32_2) << 16);
783
+ acc = acc ^ (acc >>> 13);
784
+ acc =
785
+ (((acc & 0xffff) * PRIME32_3) & 0xffffffff) +
786
+ (((acc >>> 16) * PRIME32_3) << 16);
787
+ acc = acc ^ (acc >>> 16);
788
+ // turn any negatives back into a positive number;
789
+ return acc < 0 ? acc + 4294967296 : acc;
782
790
  }
783
791
 
784
792
  const CWD = process.cwd();
@@ -793,7 +801,7 @@ function createSignatureValue(node) {
793
801
  function captureIdentifiers(state, path) {
794
802
  path.traverse({
795
803
  ImportDeclaration(p) {
796
- if (p.node.importKind === 'value') {
804
+ if (!(p.node.importKind === 'type' || p.node.importKind === 'typeof')) {
797
805
  registerImportSpecifiers(state, p, state.specifiers);
798
806
  }
799
807
  },
@@ -906,6 +914,9 @@ function isStatementTopLevel(path) {
906
914
  }
907
915
  return programParent === blockParent;
908
916
  }
917
+ function isValidFunction(node) {
918
+ return t__namespace.isArrowFunctionExpression(node) || t__namespace.isFunctionExpression(node);
919
+ }
909
920
  function transformVariableDeclarator(state, path) {
910
921
  if (path.parentPath.isVariableDeclaration() &&
911
922
  !isStatementTopLevel(path.parentPath)) {
@@ -917,8 +928,7 @@ function transformVariableDeclarator(state, path) {
917
928
  return;
918
929
  }
919
930
  if (isComponentishName(identifier.name)) {
920
- const trueFuncExpr = unwrapNode(init, t__namespace.isFunctionExpression) ||
921
- unwrapNode(init, t__namespace.isArrowFunctionExpression);
931
+ const trueFuncExpr = unwrapNode(init, isValidFunction);
922
932
  // Check for valid FunctionExpression or ArrowFunctionExpression
923
933
  if (trueFuncExpr &&
924
934
  // Must not be async or generator
@@ -950,9 +960,10 @@ function transformFunctionDeclaration(state, path) {
950
960
  // Might be component-like, but the only valid components
951
961
  // have zero or one parameter
952
962
  decl.params.length < 2) {
953
- path.replaceWith(t__namespace.variableDeclaration('const', [
963
+ const [tmp] = path.replaceWith(t__namespace.variableDeclaration('const', [
954
964
  t__namespace.variableDeclarator(decl.id, wrapComponent(state, path, decl.id, t__namespace.functionExpression(decl.id, decl.params, decl.body), decl)),
955
965
  ]));
966
+ path.scope.registerDeclaration(tmp);
956
967
  path.skip();
957
968
  }
958
969
  }
@@ -972,6 +983,7 @@ function bubbleFunctionDeclaration(program, path) {
972
983
  decl.params.length < 2) {
973
984
  const first = program.get('body')[0];
974
985
  const [tmp] = first.insertBefore(decl);
986
+ program.scope.registerDeclaration(tmp);
975
987
  tmp.skip();
976
988
  if (path.parentPath.isExportNamedDeclaration()) {
977
989
  path.parentPath.replaceWith(t__namespace.exportNamedDeclaration(undefined, [
@@ -1014,7 +1026,6 @@ function solidRefreshPlugin() {
1014
1026
  bubbleFunctionDeclaration(programPath, path);
1015
1027
  },
1016
1028
  });
1017
- programPath.scope.crawl();
1018
1029
  programPath.traverse({
1019
1030
  JSXElement(path) {
1020
1031
  transformJSX(path);
@@ -1023,7 +1034,6 @@ function solidRefreshPlugin() {
1023
1034
  transformJSX(path);
1024
1035
  },
1025
1036
  });
1026
- programPath.scope.crawl();
1027
1037
  programPath.traverse({
1028
1038
  VariableDeclarator(path) {
1029
1039
  transformVariableDeclarator(state, path);
@@ -1032,10 +1042,10 @@ function solidRefreshPlugin() {
1032
1042
  transformFunctionDeclaration(state, path);
1033
1043
  },
1034
1044
  });
1035
- programPath.scope.crawl();
1036
1045
  },
1037
1046
  },
1038
1047
  };
1039
1048
  }
1040
1049
 
1041
1050
  module.exports = solidRefreshPlugin;
1051
+ //# sourceMappingURL=babel.cjs.map