solid-refresh 0.7.2 → 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.
package/dist/babel.mjs CHANGED
@@ -1,195 +1,7 @@
1
- import path from 'path';
2
1
  import * as t from '@babel/types';
3
- import { addNamed, addDefault } from '@babel/helper-module-imports';
2
+ import path from 'path';
4
3
  import _generator from '@babel/generator';
5
4
 
6
- /**
7
- * Copyright (c) 2019 Jason Dent
8
- * https://github.com/Jason3S/xxhash
9
- */
10
- const PRIME32_1 = 2654435761;
11
- const PRIME32_2 = 2246822519;
12
- const PRIME32_3 = 3266489917;
13
- const PRIME32_4 = 668265263;
14
- const PRIME32_5 = 374761393;
15
- function toUtf8(text) {
16
- const bytes = [];
17
- for (let i = 0, n = text.length; i < n; ++i) {
18
- const c = text.charCodeAt(i);
19
- if (c < 0x80) {
20
- bytes.push(c);
21
- }
22
- else if (c < 0x800) {
23
- bytes.push(0xc0 | (c >> 6), 0x80 | (c & 0x3f));
24
- }
25
- else if (c < 0xd800 || c >= 0xe000) {
26
- bytes.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));
27
- }
28
- else {
29
- const cp = 0x10000 + (((c & 0x3ff) << 10) | (text.charCodeAt(++i) & 0x3ff));
30
- bytes.push(0xf0 | ((cp >> 18) & 0x7), 0x80 | ((cp >> 12) & 0x3f), 0x80 | ((cp >> 6) & 0x3f), 0x80 | (cp & 0x3f));
31
- }
32
- }
33
- return new Uint8Array(bytes);
34
- }
35
- /**
36
- *
37
- * @param buffer - byte array or string
38
- * @param seed - optional seed (32-bit unsigned);
39
- */
40
- function xxHash32(buffer, seed = 0) {
41
- buffer = typeof buffer === 'string' ? toUtf8(buffer) : buffer;
42
- const b = buffer;
43
- /*
44
- Step 1. Initialize internal accumulators
45
- Each accumulator gets an initial value based on optional seed input. Since the seed is optional, it can be 0.
46
- ```
47
- u32 acc1 = seed + PRIME32_1 + PRIME32_2;
48
- u32 acc2 = seed + PRIME32_2;
49
- u32 acc3 = seed + 0;
50
- u32 acc4 = seed - PRIME32_1;
51
- ```
52
- Special case : input is less than 16 bytes
53
- When input is too small (< 16 bytes), the algorithm will not process any stripe. Consequently, it will not
54
- make use of parallel accumulators.
55
- In which case, a simplified initialization is performed, using a single accumulator :
56
- u32 acc = seed + PRIME32_5;
57
- The algorithm then proceeds directly to step 4.
58
- */
59
- let acc = (seed + PRIME32_5) & 0xffffffff;
60
- let offset = 0;
61
- if (b.length >= 16) {
62
- const accN = [
63
- (seed + PRIME32_1 + PRIME32_2) & 0xffffffff,
64
- (seed + PRIME32_2) & 0xffffffff,
65
- (seed + 0) & 0xffffffff,
66
- (seed - PRIME32_1) & 0xffffffff,
67
- ];
68
- /*
69
- Step 2. Process stripes
70
- A stripe is a contiguous segment of 16 bytes. It is evenly divided into 4 lanes, of 4 bytes each.
71
- The first lane is used to update accumulator 1, the second lane is used to update accumulator 2, and so on.
72
- Each lane read its associated 32-bit value using little-endian convention.
73
- For each {lane, accumulator}, the update process is called a round, and applies the following formula :
74
- ```
75
- accN = accN + (laneN * PRIME32_2);
76
- accN = accN <<< 13;
77
- accN = accN * PRIME32_1;
78
- ```
79
- This shuffles the bits so that any bit from input lane impacts several bits in output accumulator.
80
- All operations are performed modulo 2^32.
81
- Input is consumed one full stripe at a time. Step 2 is looped as many times as necessary to consume
82
- the whole input, except the last remaining bytes which cannot form a stripe (< 16 bytes). When that
83
- happens, move to step 3.
84
- */
85
- const b = buffer;
86
- const limit = b.length - 16;
87
- let lane = 0;
88
- for (offset = 0; (offset & 0xfffffff0) <= limit; offset += 4) {
89
- const i = offset;
90
- const laneN0 = b[i + 0] + (b[i + 1] << 8);
91
- const laneN1 = b[i + 2] + (b[i + 3] << 8);
92
- const laneNP = laneN0 * PRIME32_2 + ((laneN1 * PRIME32_2) << 16);
93
- let acc = (accN[lane] + laneNP) & 0xffffffff;
94
- acc = (acc << 13) | (acc >>> 19);
95
- const acc0 = acc & 0xffff;
96
- const acc1 = acc >>> 16;
97
- accN[lane] = (acc0 * PRIME32_1 + ((acc1 * PRIME32_1) << 16)) & 0xffffffff;
98
- lane = (lane + 1) & 0x3;
99
- }
100
- /*
101
- Step 3. Accumulator convergence
102
- All 4 lane accumulators from previous steps are merged to produce a single remaining accumulator
103
- of same width (32-bit). The associated formula is as follows :
104
- ```
105
- acc = (acc1 <<< 1) + (acc2 <<< 7) + (acc3 <<< 12) + (acc4 <<< 18);
106
- ```
107
- */
108
- acc =
109
- (((accN[0] << 1) | (accN[0] >>> 31)) +
110
- ((accN[1] << 7) | (accN[1] >>> 25)) +
111
- ((accN[2] << 12) | (accN[2] >>> 20)) +
112
- ((accN[3] << 18) | (accN[3] >>> 14))) &
113
- 0xffffffff;
114
- }
115
- /*
116
- Step 4. Add input length
117
- The input total length is presumed known at this stage. This step is just about adding the length to
118
- accumulator, so that it participates to final mixing.
119
- ```
120
- acc = acc + (u32)inputLength;
121
- ```
122
- */
123
- acc = (acc + buffer.length) & 0xffffffff;
124
- /*
125
- Step 5. Consume remaining input
126
- There may be up to 15 bytes remaining to consume from the input. The final stage will digest them according
127
- to following pseudo-code :
128
- ```
129
- while (remainingLength >= 4) {
130
- lane = read_32bit_little_endian(input_ptr);
131
- acc = acc + lane * PRIME32_3;
132
- acc = (acc <<< 17) * PRIME32_4;
133
- input_ptr += 4; remainingLength -= 4;
134
- }
135
- ```
136
- This process ensures that all input bytes are present in the final mix.
137
- */
138
- const limit = buffer.length - 4;
139
- for (; offset <= limit; offset += 4) {
140
- const i = offset;
141
- const laneN0 = b[i + 0] + (b[i + 1] << 8);
142
- const laneN1 = b[i + 2] + (b[i + 3] << 8);
143
- const laneP = laneN0 * PRIME32_3 + ((laneN1 * PRIME32_3) << 16);
144
- acc = (acc + laneP) & 0xffffffff;
145
- acc = (acc << 17) | (acc >>> 15);
146
- acc =
147
- ((acc & 0xffff) * PRIME32_4 + (((acc >>> 16) * PRIME32_4) << 16)) &
148
- 0xffffffff;
149
- }
150
- /*
151
- ```
152
- while (remainingLength >= 1) {
153
- lane = read_byte(input_ptr);
154
- acc = acc + lane * PRIME32_5;
155
- acc = (acc <<< 11) * PRIME32_1;
156
- input_ptr += 1; remainingLength -= 1;
157
- }
158
- ```
159
- */
160
- for (; offset < b.length; ++offset) {
161
- const lane = b[offset];
162
- acc = acc + lane * PRIME32_5;
163
- acc = (acc << 11) | (acc >>> 21);
164
- acc =
165
- ((acc & 0xffff) * PRIME32_1 + (((acc >>> 16) * PRIME32_1) << 16)) &
166
- 0xffffffff;
167
- }
168
- /*
169
- Step 6. Final mix (avalanche)
170
- The final mix ensures that all input bits have a chance to impact any bit in the output digest,
171
- resulting in an unbiased distribution. This is also called avalanche effect.
172
- ```
173
- acc = acc xor (acc >> 15);
174
- acc = acc * PRIME32_2;
175
- acc = acc xor (acc >> 13);
176
- acc = acc * PRIME32_3;
177
- acc = acc xor (acc >> 16);
178
- ```
179
- */
180
- acc = acc ^ (acc >>> 15);
181
- acc =
182
- (((acc & 0xffff) * PRIME32_2) & 0xffffffff) +
183
- (((acc >>> 16) * PRIME32_2) << 16);
184
- acc = acc ^ (acc >>> 13);
185
- acc =
186
- (((acc & 0xffff) * PRIME32_3) & 0xffffffff) +
187
- (((acc >>> 16) * PRIME32_3) << 16);
188
- acc = acc ^ (acc >>> 16);
189
- // turn any negatives back into a positive number;
190
- return acc < 0 ? acc + 4294967296 : acc;
191
- }
192
-
193
5
  // This is just a Pascal heuristic
194
6
  // we only assume a function is a component
195
7
  // if the first character is in uppercase
@@ -203,71 +15,6 @@ function getImportSpecifierName(specifier) {
203
15
  return specifier.imported.value;
204
16
  }
205
17
 
206
- function registerImportSpecifier(state, id, specifier) {
207
- if (t.isImportDefaultSpecifier(specifier)) {
208
- if (id.definition.kind === 'default') {
209
- state.registrations.identifiers.set(specifier.local, id);
210
- }
211
- return;
212
- }
213
- if (t.isImportSpecifier(specifier)) {
214
- if ((id.definition.kind === 'named' &&
215
- getImportSpecifierName(specifier) === id.definition.name) ||
216
- (id.definition.kind === 'default' &&
217
- getImportSpecifierName(specifier) === 'default')) {
218
- state.registrations.identifiers.set(specifier.local, id);
219
- }
220
- return;
221
- }
222
- let current = state.registrations.namespaces.get(specifier.local);
223
- if (!current) {
224
- current = [];
225
- }
226
- current.push(id);
227
- state.registrations.namespaces.set(specifier.local, current);
228
- }
229
- function registerImportSpecifiers(state, path, definitions) {
230
- for (let i = 0, len = definitions.length; i < len; i++) {
231
- const id = definitions[i];
232
- if (path.node.source.value === id.definition.source) {
233
- for (let k = 0, klen = path.node.specifiers.length; k < klen; k++) {
234
- registerImportSpecifier(state, id, path.node.specifiers[k]);
235
- }
236
- }
237
- }
238
- }
239
-
240
- function getHotIdentifier(state) {
241
- switch (state.bundler) {
242
- // vite/esm uses `import.meta.hot`
243
- case 'esm':
244
- case 'vite':
245
- return t.memberExpression(t.memberExpression(t.identifier('import'), t.identifier('meta')), t.identifier('hot'));
246
- // webpack 5 uses `import.meta.webpackHot`
247
- // rspack does as well
248
- case 'webpack5':
249
- case 'rspack-esm':
250
- return t.memberExpression(t.memberExpression(t.identifier('import'), t.identifier('meta')), t.identifier('webpackHot'));
251
- default:
252
- // `module.hot` is the default.
253
- return t.memberExpression(t.identifier('module'), t.identifier('hot'));
254
- }
255
- }
256
-
257
- function getImportIdentifier(state, path, registration) {
258
- const name = registration.kind === 'named' ? registration.name : 'default';
259
- const target = `${registration.source}[${name}]`;
260
- const current = state.imports.get(target);
261
- if (current) {
262
- return current;
263
- }
264
- const newID = registration.kind === 'named'
265
- ? addNamed(path, registration.name, registration.source)
266
- : addDefault(path, registration.source);
267
- state.imports.set(target, newID);
268
- return newID;
269
- }
270
-
271
18
  // Source of solid-refresh (for import)
272
19
  const SOLID_REFRESH_MODULE = 'solid-refresh';
273
20
  // Exported names from solid-refresh that will be imported
@@ -323,6 +70,54 @@ const IMPORT_SPECIFIERS = [
323
70
  },
324
71
  ];
325
72
 
73
+ function getHotIdentifier(state) {
74
+ switch (state.bundler) {
75
+ // vite/esm uses `import.meta.hot`
76
+ case 'esm':
77
+ case 'vite':
78
+ return t.memberExpression(t.memberExpression(t.identifier('import'), t.identifier('meta')), t.identifier('hot'));
79
+ // webpack 5 uses `import.meta.webpackHot`
80
+ // rspack does as well
81
+ case 'webpack5':
82
+ case 'rspack-esm':
83
+ return t.memberExpression(t.memberExpression(t.identifier('import'), t.identifier('meta')), t.identifier('webpackHot'));
84
+ default:
85
+ // `module.hot` is the default.
86
+ return t.memberExpression(t.identifier('module'), t.identifier('hot'));
87
+ }
88
+ }
89
+
90
+ function getImportIdentifier(state, path, registration) {
91
+ const name = registration.kind === 'named' ? registration.name : 'default';
92
+ const target = `${registration.source}[${name}]`;
93
+ const current = state.imports.get(target);
94
+ if (current) {
95
+ return current;
96
+ }
97
+ const programParent = path.scope.getProgramParent();
98
+ const uid = programParent.generateUidIdentifier(registration.kind === 'named' ? registration.name : 'default');
99
+ const newPath = programParent.path.unshiftContainer('body', t.importDeclaration([
100
+ registration.kind === 'named'
101
+ ? t.importSpecifier(uid, t.identifier(registration.name))
102
+ : t.importDefaultSpecifier(uid),
103
+ ], t.stringLiteral(registration.source)))[0];
104
+ programParent.registerDeclaration(newPath);
105
+ state.imports.set(target, uid);
106
+ return uid;
107
+ }
108
+
109
+ function getRootStatementPath(path) {
110
+ let current = path.parentPath;
111
+ while (current) {
112
+ const next = current.parentPath;
113
+ if (next && t.isProgram(next.node)) {
114
+ return current;
115
+ }
116
+ current = next;
117
+ }
118
+ return path;
119
+ }
120
+
326
121
  function generateViteHMRRequirement(state, statements, pathToHot) {
327
122
  if (state.bundler === 'vite') {
328
123
  // Vite requires that the owner module has an `import.meta.hot.accept()` call
@@ -330,6 +125,87 @@ function generateViteHMRRequirement(state, statements, pathToHot) {
330
125
  }
331
126
  }
332
127
 
128
+ const REGISTRY = 'REGISTRY';
129
+ function createRegistry(state, path) {
130
+ const current = state.imports.get(REGISTRY);
131
+ if (current) {
132
+ return current;
133
+ }
134
+ const root = getRootStatementPath(path);
135
+ const identifier = path.scope.generateUidIdentifier(REGISTRY);
136
+ const [tmp] = root.insertBefore(t.variableDeclaration('const', [
137
+ t.variableDeclarator(identifier, t.callExpression(getImportIdentifier(state, path, IMPORT_REGISTRY), [])),
138
+ ]));
139
+ root.scope.registerDeclaration(tmp);
140
+ const pathToHot = getHotIdentifier(state);
141
+ const statements = [
142
+ t.expressionStatement(t.callExpression(getImportIdentifier(state, path, IMPORT_REFRESH), [
143
+ t.stringLiteral(state.bundler),
144
+ pathToHot,
145
+ identifier,
146
+ ])),
147
+ ];
148
+ generateViteHMRRequirement(state, statements, pathToHot);
149
+ path.scope.getProgramParent().path.pushContainer('body', [
150
+ t.ifStatement(pathToHot, t.blockStatement(statements)),
151
+ ]);
152
+ state.imports.set(REGISTRY, identifier);
153
+ return identifier;
154
+ }
155
+
156
+ // https://github.com/babel/babel/issues/15269
157
+ let generator;
158
+ if (typeof _generator !== 'function') {
159
+ generator = _generator.default;
160
+ }
161
+ else {
162
+ generator = _generator;
163
+ }
164
+ function generateCode(node) {
165
+ return generator(node).code;
166
+ }
167
+
168
+ function isForeignBinding(source, current, name) {
169
+ if (source === current) {
170
+ return true;
171
+ }
172
+ if (current.scope.hasOwnBinding(name)) {
173
+ return false;
174
+ }
175
+ if (current.parentPath) {
176
+ return isForeignBinding(source, current.parentPath, name);
177
+ }
178
+ return true;
179
+ }
180
+ function isInTypescript(path) {
181
+ let parent = path.parentPath;
182
+ while (parent) {
183
+ if (t.isTypeScript(parent.node) && !t.isExpression(parent.node)) {
184
+ return true;
185
+ }
186
+ parent = parent.parentPath;
187
+ }
188
+ return false;
189
+ }
190
+ function getForeignBindings(path) {
191
+ const identifiers = new Set();
192
+ path.traverse({
193
+ ReferencedIdentifier(p) {
194
+ // Check identifiers that aren't in a TS expression
195
+ if (!isInTypescript(p) && isForeignBinding(path, p, p.node.name)) {
196
+ if (p.isIdentifier() || p.parentPath.isJSXMemberExpression()) {
197
+ identifiers.add(p.node.name);
198
+ }
199
+ }
200
+ },
201
+ });
202
+ const collected = [];
203
+ for (const identifier of identifiers) {
204
+ collected.push(t.identifier(identifier));
205
+ }
206
+ return collected;
207
+ }
208
+
333
209
  function getHMRDeclineCall(state, path) {
334
210
  const pathToHot = getHotIdentifier(state);
335
211
  const statements = [
@@ -342,6 +218,16 @@ function getHMRDeclineCall(state, path) {
342
218
  return t.ifStatement(pathToHot, t.blockStatement(statements));
343
219
  }
344
220
 
221
+ function getStatementPath(path) {
222
+ if (t.isStatement(path.node)) {
223
+ return path;
224
+ }
225
+ if (path.parentPath) {
226
+ return getStatementPath(path.parentPath);
227
+ }
228
+ return null;
229
+ }
230
+
345
231
  function isPathValid(path, key) {
346
232
  return key(path.node);
347
233
  }
@@ -411,111 +297,57 @@ function isMemberExpressionValidCallee(state, path, member, target) {
411
297
  if (!result) {
412
298
  return false;
413
299
  }
414
- return isPropertyValidCallee(result, target, member.property.name);
415
- }
416
- function isValidCallee(state, path, { callee }, target) {
417
- if (t.isV8IntrinsicIdentifier(callee)) {
418
- return false;
419
- }
420
- const trueCallee = unwrapNode(callee, t.isIdentifier);
421
- if (trueCallee) {
422
- return isIdentifierValidCallee(state, path, trueCallee, target);
423
- }
424
- const trueMember = unwrapNode(callee, t.isMemberExpression);
425
- if (trueMember && !trueMember.computed) {
426
- return isMemberExpressionValidCallee(state, path, trueMember, target);
427
- }
428
- return false;
429
- }
430
-
431
- function getStatementPath(path) {
432
- if (t.isStatement(path.node)) {
433
- return path;
434
- }
435
- if (path.parentPath) {
436
- return getStatementPath(path.parentPath);
437
- }
438
- return null;
439
- }
440
-
441
- function getRootStatementPath(path) {
442
- let current = path.parentPath;
443
- while (current) {
444
- const next = current.parentPath;
445
- if (next && t.isProgram(next.node)) {
446
- return current;
447
- }
448
- current = next;
449
- }
450
- return path;
451
- }
452
-
453
- const REGISTRY = 'REGISTRY';
454
- function createRegistry(state, path) {
455
- const current = state.imports.get(REGISTRY);
456
- if (current) {
457
- return current;
458
- }
459
- const root = getRootStatementPath(path);
460
- const identifier = path.scope.generateUidIdentifier(REGISTRY);
461
- root.insertBefore(t.variableDeclaration('const', [
462
- t.variableDeclarator(identifier, t.callExpression(getImportIdentifier(state, path, IMPORT_REGISTRY), [])),
463
- ]));
464
- const pathToHot = getHotIdentifier(state);
465
- const statements = [
466
- t.expressionStatement(t.callExpression(getImportIdentifier(state, path, IMPORT_REFRESH), [
467
- t.stringLiteral(state.bundler),
468
- pathToHot,
469
- identifier,
470
- ])),
471
- ];
472
- generateViteHMRRequirement(state, statements, pathToHot);
473
- path.scope.getProgramParent().path.pushContainer('body', [
474
- t.ifStatement(pathToHot, t.blockStatement(statements)),
475
- ]);
476
- state.imports.set(REGISTRY, identifier);
477
- return identifier;
478
- }
479
-
480
- function isForeignBinding(source, current, name) {
481
- if (source === current) {
482
- return true;
483
- }
484
- if (current.scope.hasOwnBinding(name)) {
300
+ return isPropertyValidCallee(result, target, member.property.name);
301
+ }
302
+ function isValidCallee(state, path, { callee }, target) {
303
+ if (t.isV8IntrinsicIdentifier(callee)) {
485
304
  return false;
486
305
  }
487
- if (current.parentPath) {
488
- return isForeignBinding(source, current.parentPath, name);
306
+ const trueCallee = unwrapNode(callee, t.isIdentifier);
307
+ if (trueCallee) {
308
+ return isIdentifierValidCallee(state, path, trueCallee, target);
489
309
  }
490
- return true;
310
+ const trueMember = unwrapNode(callee, t.isMemberExpression);
311
+ if (trueMember && !trueMember.computed) {
312
+ return isMemberExpressionValidCallee(state, path, trueMember, target);
313
+ }
314
+ return false;
491
315
  }
492
- function isInTypescript(path) {
493
- let parent = path.parentPath;
494
- while (parent) {
495
- if (t.isTypeScript(parent.node) && !t.isExpression(parent.node)) {
496
- return true;
316
+
317
+ function registerImportSpecifier(state, id, specifier) {
318
+ if (t.isImportDefaultSpecifier(specifier)) {
319
+ if (id.definition.kind === 'default') {
320
+ state.registrations.identifiers.set(specifier.local, id);
497
321
  }
498
- parent = parent.parentPath;
322
+ return;
499
323
  }
500
- return false;
324
+ if (t.isImportSpecifier(specifier)) {
325
+ if (specifier.importKind === 'type' || specifier.importKind === 'typeof') {
326
+ return;
327
+ }
328
+ const name = getImportSpecifierName(specifier);
329
+ if ((id.definition.kind === 'named' && name === id.definition.name) ||
330
+ (id.definition.kind === 'default' && name === 'default')) {
331
+ state.registrations.identifiers.set(specifier.local, id);
332
+ }
333
+ return;
334
+ }
335
+ let current = state.registrations.namespaces.get(specifier.local);
336
+ if (!current) {
337
+ current = [];
338
+ }
339
+ current.push(id);
340
+ state.registrations.namespaces.set(specifier.local, current);
501
341
  }
502
- function getForeignBindings(path) {
503
- const identifiers = new Set();
504
- path.traverse({
505
- ReferencedIdentifier(p) {
506
- // Check identifiers that aren't in a TS expression
507
- if (!isInTypescript(p) && isForeignBinding(path, p, p.node.name)) {
508
- if (p.isIdentifier() || p.parentPath.isJSXMemberExpression()) {
509
- identifiers.add(p.node.name);
510
- }
342
+ function registerImportSpecifiers(state, path, definitions) {
343
+ for (let i = 0, len = definitions.length; i < len; i++) {
344
+ const id = definitions[i];
345
+ if (path.node.source.value === id.definition.source) {
346
+ for (let k = 0, klen = path.node.specifiers.length; k < klen; k++) {
347
+ registerImportSpecifier(state, id, path.node.specifiers[k]);
511
348
  }
512
- },
513
- });
514
- const collected = [];
515
- for (const identifier of identifiers) {
516
- collected.push(t.identifier(identifier));
349
+ }
517
350
  }
518
- return collected;
519
351
  }
520
352
 
521
353
  function getDescriptiveName(path, defaultName) {
@@ -744,20 +576,196 @@ function transformJSX(path) {
744
576
  if (path.node.loc) {
745
577
  templateComp.loc = path.node.loc;
746
578
  }
747
- rootPath.insertBefore(t.variableDeclaration('const', [t.variableDeclarator(id, templateComp)]));
579
+ const [tmp] = rootPath.insertBefore(t.variableDeclaration('const', [t.variableDeclarator(id, templateComp)]));
580
+ rootPath.scope.registerDeclaration(tmp);
748
581
  path.replaceWith(skippableJSX(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(id.name), [...state.attributes], true), t.jsxClosingElement(t.jsxIdentifier(id.name)), [], true)));
749
582
  }
750
583
 
751
- // https://github.com/babel/babel/issues/15269
752
- let generator;
753
- if (typeof _generator !== 'function') {
754
- generator = _generator.default;
755
- }
756
- else {
757
- generator = _generator;
584
+ /**
585
+ * Copyright (c) 2019 Jason Dent
586
+ * https://github.com/Jason3S/xxhash
587
+ */
588
+ const PRIME32_1 = 2654435761;
589
+ const PRIME32_2 = 2246822519;
590
+ const PRIME32_3 = 3266489917;
591
+ const PRIME32_4 = 668265263;
592
+ const PRIME32_5 = 374761393;
593
+ function toUtf8(text) {
594
+ const bytes = [];
595
+ for (let i = 0, n = text.length; i < n; ++i) {
596
+ const c = text.charCodeAt(i);
597
+ if (c < 0x80) {
598
+ bytes.push(c);
599
+ }
600
+ else if (c < 0x800) {
601
+ bytes.push(0xc0 | (c >> 6), 0x80 | (c & 0x3f));
602
+ }
603
+ else if (c < 0xd800 || c >= 0xe000) {
604
+ bytes.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));
605
+ }
606
+ else {
607
+ const cp = 0x10000 + (((c & 0x3ff) << 10) | (text.charCodeAt(++i) & 0x3ff));
608
+ bytes.push(0xf0 | ((cp >> 18) & 0x7), 0x80 | ((cp >> 12) & 0x3f), 0x80 | ((cp >> 6) & 0x3f), 0x80 | (cp & 0x3f));
609
+ }
610
+ }
611
+ return new Uint8Array(bytes);
758
612
  }
759
- function generateCode(node) {
760
- return generator(node).code;
613
+ /**
614
+ *
615
+ * @param buffer - byte array or string
616
+ * @param seed - optional seed (32-bit unsigned);
617
+ */
618
+ function xxHash32(buffer, seed = 0) {
619
+ buffer = typeof buffer === 'string' ? toUtf8(buffer) : buffer;
620
+ const b = buffer;
621
+ /*
622
+ Step 1. Initialize internal accumulators
623
+ Each accumulator gets an initial value based on optional seed input. Since the seed is optional, it can be 0.
624
+ ```
625
+ u32 acc1 = seed + PRIME32_1 + PRIME32_2;
626
+ u32 acc2 = seed + PRIME32_2;
627
+ u32 acc3 = seed + 0;
628
+ u32 acc4 = seed - PRIME32_1;
629
+ ```
630
+ Special case : input is less than 16 bytes
631
+ When input is too small (< 16 bytes), the algorithm will not process any stripe. Consequently, it will not
632
+ make use of parallel accumulators.
633
+ In which case, a simplified initialization is performed, using a single accumulator :
634
+ u32 acc = seed + PRIME32_5;
635
+ The algorithm then proceeds directly to step 4.
636
+ */
637
+ let acc = (seed + PRIME32_5) & 0xffffffff;
638
+ let offset = 0;
639
+ if (b.length >= 16) {
640
+ const accN = [
641
+ (seed + PRIME32_1 + PRIME32_2) & 0xffffffff,
642
+ (seed + PRIME32_2) & 0xffffffff,
643
+ (seed + 0) & 0xffffffff,
644
+ (seed - PRIME32_1) & 0xffffffff,
645
+ ];
646
+ /*
647
+ Step 2. Process stripes
648
+ A stripe is a contiguous segment of 16 bytes. It is evenly divided into 4 lanes, of 4 bytes each.
649
+ The first lane is used to update accumulator 1, the second lane is used to update accumulator 2, and so on.
650
+ Each lane read its associated 32-bit value using little-endian convention.
651
+ For each {lane, accumulator}, the update process is called a round, and applies the following formula :
652
+ ```
653
+ accN = accN + (laneN * PRIME32_2);
654
+ accN = accN <<< 13;
655
+ accN = accN * PRIME32_1;
656
+ ```
657
+ This shuffles the bits so that any bit from input lane impacts several bits in output accumulator.
658
+ All operations are performed modulo 2^32.
659
+ Input is consumed one full stripe at a time. Step 2 is looped as many times as necessary to consume
660
+ the whole input, except the last remaining bytes which cannot form a stripe (< 16 bytes). When that
661
+ happens, move to step 3.
662
+ */
663
+ const b = buffer;
664
+ const limit = b.length - 16;
665
+ let lane = 0;
666
+ for (offset = 0; (offset & 0xfffffff0) <= limit; offset += 4) {
667
+ const i = offset;
668
+ const laneN0 = b[i + 0] + (b[i + 1] << 8);
669
+ const laneN1 = b[i + 2] + (b[i + 3] << 8);
670
+ const laneNP = laneN0 * PRIME32_2 + ((laneN1 * PRIME32_2) << 16);
671
+ let acc = (accN[lane] + laneNP) & 0xffffffff;
672
+ acc = (acc << 13) | (acc >>> 19);
673
+ const acc0 = acc & 0xffff;
674
+ const acc1 = acc >>> 16;
675
+ accN[lane] = (acc0 * PRIME32_1 + ((acc1 * PRIME32_1) << 16)) & 0xffffffff;
676
+ lane = (lane + 1) & 0x3;
677
+ }
678
+ /*
679
+ Step 3. Accumulator convergence
680
+ All 4 lane accumulators from previous steps are merged to produce a single remaining accumulator
681
+ of same width (32-bit). The associated formula is as follows :
682
+ ```
683
+ acc = (acc1 <<< 1) + (acc2 <<< 7) + (acc3 <<< 12) + (acc4 <<< 18);
684
+ ```
685
+ */
686
+ acc =
687
+ (((accN[0] << 1) | (accN[0] >>> 31)) +
688
+ ((accN[1] << 7) | (accN[1] >>> 25)) +
689
+ ((accN[2] << 12) | (accN[2] >>> 20)) +
690
+ ((accN[3] << 18) | (accN[3] >>> 14))) &
691
+ 0xffffffff;
692
+ }
693
+ /*
694
+ Step 4. Add input length
695
+ The input total length is presumed known at this stage. This step is just about adding the length to
696
+ accumulator, so that it participates to final mixing.
697
+ ```
698
+ acc = acc + (u32)inputLength;
699
+ ```
700
+ */
701
+ acc = (acc + buffer.length) & 0xffffffff;
702
+ /*
703
+ Step 5. Consume remaining input
704
+ There may be up to 15 bytes remaining to consume from the input. The final stage will digest them according
705
+ to following pseudo-code :
706
+ ```
707
+ while (remainingLength >= 4) {
708
+ lane = read_32bit_little_endian(input_ptr);
709
+ acc = acc + lane * PRIME32_3;
710
+ acc = (acc <<< 17) * PRIME32_4;
711
+ input_ptr += 4; remainingLength -= 4;
712
+ }
713
+ ```
714
+ This process ensures that all input bytes are present in the final mix.
715
+ */
716
+ const limit = buffer.length - 4;
717
+ for (; offset <= limit; offset += 4) {
718
+ const i = offset;
719
+ const laneN0 = b[i + 0] + (b[i + 1] << 8);
720
+ const laneN1 = b[i + 2] + (b[i + 3] << 8);
721
+ const laneP = laneN0 * PRIME32_3 + ((laneN1 * PRIME32_3) << 16);
722
+ acc = (acc + laneP) & 0xffffffff;
723
+ acc = (acc << 17) | (acc >>> 15);
724
+ acc =
725
+ ((acc & 0xffff) * PRIME32_4 + (((acc >>> 16) * PRIME32_4) << 16)) &
726
+ 0xffffffff;
727
+ }
728
+ /*
729
+ ```
730
+ while (remainingLength >= 1) {
731
+ lane = read_byte(input_ptr);
732
+ acc = acc + lane * PRIME32_5;
733
+ acc = (acc <<< 11) * PRIME32_1;
734
+ input_ptr += 1; remainingLength -= 1;
735
+ }
736
+ ```
737
+ */
738
+ for (; offset < b.length; ++offset) {
739
+ const lane = b[offset];
740
+ acc = acc + lane * PRIME32_5;
741
+ acc = (acc << 11) | (acc >>> 21);
742
+ acc =
743
+ ((acc & 0xffff) * PRIME32_1 + (((acc >>> 16) * PRIME32_1) << 16)) &
744
+ 0xffffffff;
745
+ }
746
+ /*
747
+ Step 6. Final mix (avalanche)
748
+ The final mix ensures that all input bits have a chance to impact any bit in the output digest,
749
+ resulting in an unbiased distribution. This is also called avalanche effect.
750
+ ```
751
+ acc = acc xor (acc >> 15);
752
+ acc = acc * PRIME32_2;
753
+ acc = acc xor (acc >> 13);
754
+ acc = acc * PRIME32_3;
755
+ acc = acc xor (acc >> 16);
756
+ ```
757
+ */
758
+ acc = acc ^ (acc >>> 15);
759
+ acc =
760
+ (((acc & 0xffff) * PRIME32_2) & 0xffffffff) +
761
+ (((acc >>> 16) * PRIME32_2) << 16);
762
+ acc = acc ^ (acc >>> 13);
763
+ acc =
764
+ (((acc & 0xffff) * PRIME32_3) & 0xffffffff) +
765
+ (((acc >>> 16) * PRIME32_3) << 16);
766
+ acc = acc ^ (acc >>> 16);
767
+ // turn any negatives back into a positive number;
768
+ return acc < 0 ? acc + 4294967296 : acc;
761
769
  }
762
770
 
763
771
  const CWD = process.cwd();
@@ -772,7 +780,7 @@ function createSignatureValue(node) {
772
780
  function captureIdentifiers(state, path) {
773
781
  path.traverse({
774
782
  ImportDeclaration(p) {
775
- if (p.node.importKind === 'value') {
783
+ if (!(p.node.importKind === 'type' || p.node.importKind === 'typeof')) {
776
784
  registerImportSpecifiers(state, p, state.specifiers);
777
785
  }
778
786
  },
@@ -885,6 +893,9 @@ function isStatementTopLevel(path) {
885
893
  }
886
894
  return programParent === blockParent;
887
895
  }
896
+ function isValidFunction(node) {
897
+ return t.isArrowFunctionExpression(node) || t.isFunctionExpression(node);
898
+ }
888
899
  function transformVariableDeclarator(state, path) {
889
900
  if (path.parentPath.isVariableDeclaration() &&
890
901
  !isStatementTopLevel(path.parentPath)) {
@@ -896,8 +907,7 @@ function transformVariableDeclarator(state, path) {
896
907
  return;
897
908
  }
898
909
  if (isComponentishName(identifier.name)) {
899
- const trueFuncExpr = unwrapNode(init, t.isFunctionExpression) ||
900
- unwrapNode(init, t.isArrowFunctionExpression);
910
+ const trueFuncExpr = unwrapNode(init, isValidFunction);
901
911
  // Check for valid FunctionExpression or ArrowFunctionExpression
902
912
  if (trueFuncExpr &&
903
913
  // Must not be async or generator
@@ -929,9 +939,10 @@ function transformFunctionDeclaration(state, path) {
929
939
  // Might be component-like, but the only valid components
930
940
  // have zero or one parameter
931
941
  decl.params.length < 2) {
932
- path.replaceWith(t.variableDeclaration('const', [
942
+ const [tmp] = path.replaceWith(t.variableDeclaration('const', [
933
943
  t.variableDeclarator(decl.id, wrapComponent(state, path, decl.id, t.functionExpression(decl.id, decl.params, decl.body), decl)),
934
944
  ]));
945
+ path.scope.registerDeclaration(tmp);
935
946
  path.skip();
936
947
  }
937
948
  }
@@ -951,6 +962,7 @@ function bubbleFunctionDeclaration(program, path) {
951
962
  decl.params.length < 2) {
952
963
  const first = program.get('body')[0];
953
964
  const [tmp] = first.insertBefore(decl);
965
+ program.scope.registerDeclaration(tmp);
954
966
  tmp.skip();
955
967
  if (path.parentPath.isExportNamedDeclaration()) {
956
968
  path.parentPath.replaceWith(t.exportNamedDeclaration(undefined, [
@@ -993,7 +1005,6 @@ function solidRefreshPlugin() {
993
1005
  bubbleFunctionDeclaration(programPath, path);
994
1006
  },
995
1007
  });
996
- programPath.scope.crawl();
997
1008
  programPath.traverse({
998
1009
  JSXElement(path) {
999
1010
  transformJSX(path);
@@ -1002,7 +1013,6 @@ function solidRefreshPlugin() {
1002
1013
  transformJSX(path);
1003
1014
  },
1004
1015
  });
1005
- programPath.scope.crawl();
1006
1016
  programPath.traverse({
1007
1017
  VariableDeclarator(path) {
1008
1018
  transformVariableDeclarator(state, path);
@@ -1011,7 +1021,6 @@ function solidRefreshPlugin() {
1011
1021
  transformFunctionDeclaration(state, path);
1012
1022
  },
1013
1023
  });
1014
- programPath.scope.crawl();
1015
1024
  },
1016
1025
  },
1017
1026
  };