solid-refresh 0.7.2 → 0.7.4
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.cjs +398 -378
- package/dist/babel.cjs.map +1 -1
- package/dist/babel.mjs +398 -378
- package/dist/babel.mjs.map +1 -1
- package/dist/src/babel/core/create-registry.d.ts +1 -1
- package/dist/src/babel/core/create-registry.d.ts.map +1 -1
- package/dist/src/babel/core/get-foreign-bindings.d.ts +1 -1
- package/dist/src/babel/core/get-foreign-bindings.d.ts.map +1 -1
- package/dist/src/babel/core/get-import-identifier.d.ts +1 -1
- package/dist/src/babel/core/get-import-identifier.d.ts.map +1 -1
- package/dist/src/babel/core/is-statement-top-level.d.ts +4 -0
- package/dist/src/babel/core/is-statement-top-level.d.ts.map +1 -0
- package/dist/src/babel/core/register-import-specifiers.d.ts +2 -2
- package/dist/src/babel/core/register-import-specifiers.d.ts.map +1 -1
- package/dist/src/babel/core/transform-jsx.d.ts +1 -1
- package/dist/src/babel/core/transform-jsx.d.ts.map +1 -1
- package/dist/src/babel/index.d.ts.map +1 -1
- package/package.json +9 -12
package/dist/babel.mjs
CHANGED
|
@@ -1,195 +1,7 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
1
|
import * as t from '@babel/types';
|
|
3
|
-
import
|
|
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,16 +125,44 @@ function generateViteHMRRequirement(state, statements, pathToHot) {
|
|
|
330
125
|
}
|
|
331
126
|
}
|
|
332
127
|
|
|
333
|
-
|
|
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);
|
|
334
140
|
const pathToHot = getHotIdentifier(state);
|
|
335
141
|
const statements = [
|
|
336
|
-
t.expressionStatement(t.callExpression(getImportIdentifier(state, path,
|
|
142
|
+
t.expressionStatement(t.callExpression(getImportIdentifier(state, path, IMPORT_REFRESH), [
|
|
337
143
|
t.stringLiteral(state.bundler),
|
|
338
144
|
pathToHot,
|
|
145
|
+
identifier,
|
|
339
146
|
])),
|
|
340
147
|
];
|
|
341
148
|
generateViteHMRRequirement(state, statements, pathToHot);
|
|
342
|
-
|
|
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;
|
|
343
166
|
}
|
|
344
167
|
|
|
345
168
|
function isPathValid(path, key) {
|
|
@@ -369,6 +192,80 @@ function unwrapNode(node, key) {
|
|
|
369
192
|
return undefined;
|
|
370
193
|
}
|
|
371
194
|
|
|
195
|
+
function isForeignBinding(source, current, name) {
|
|
196
|
+
if (source === current) {
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
if (current.scope.hasOwnBinding(name)) {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
if (current.parentPath) {
|
|
203
|
+
return isForeignBinding(source, current.parentPath, name);
|
|
204
|
+
}
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
function isInTypescript(path) {
|
|
208
|
+
let parent = path.parentPath;
|
|
209
|
+
while (parent) {
|
|
210
|
+
if (t.isTypeScript(parent.node) && !t.isExpression(parent.node)) {
|
|
211
|
+
return true;
|
|
212
|
+
}
|
|
213
|
+
parent = parent.parentPath;
|
|
214
|
+
}
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
function getForeignBindings(path) {
|
|
218
|
+
const identifiers = new Set();
|
|
219
|
+
path.traverse({
|
|
220
|
+
ReferencedIdentifier(p) {
|
|
221
|
+
// Check identifiers that aren't in a TS expression
|
|
222
|
+
if (!isInTypescript(p) && isForeignBinding(path, p, p.node.name)) {
|
|
223
|
+
if (isPathValid(p, t.isIdentifier) ||
|
|
224
|
+
isPathValid(p.parentPath, t.isJSXMemberExpression)) {
|
|
225
|
+
identifiers.add(p.node.name);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
const collected = [];
|
|
231
|
+
for (const identifier of identifiers) {
|
|
232
|
+
collected.push(t.identifier(identifier));
|
|
233
|
+
}
|
|
234
|
+
return collected;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function getHMRDeclineCall(state, path) {
|
|
238
|
+
const pathToHot = getHotIdentifier(state);
|
|
239
|
+
const statements = [
|
|
240
|
+
t.expressionStatement(t.callExpression(getImportIdentifier(state, path, IMPORT_DECLINE), [
|
|
241
|
+
t.stringLiteral(state.bundler),
|
|
242
|
+
pathToHot,
|
|
243
|
+
])),
|
|
244
|
+
];
|
|
245
|
+
generateViteHMRRequirement(state, statements, pathToHot);
|
|
246
|
+
return t.ifStatement(pathToHot, t.blockStatement(statements));
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
function getStatementPath(path) {
|
|
250
|
+
if (t.isStatement(path.node)) {
|
|
251
|
+
return path;
|
|
252
|
+
}
|
|
253
|
+
if (path.parentPath) {
|
|
254
|
+
return getStatementPath(path.parentPath);
|
|
255
|
+
}
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function isStatementTopLevel(path) {
|
|
260
|
+
let blockParent = path.scope.getBlockParent();
|
|
261
|
+
const programParent = path.scope.getProgramParent();
|
|
262
|
+
// a FunctionDeclaration binding refers to itself as the block parent
|
|
263
|
+
if (blockParent.path === path) {
|
|
264
|
+
blockParent = blockParent.parent;
|
|
265
|
+
}
|
|
266
|
+
return programParent === blockParent;
|
|
267
|
+
}
|
|
268
|
+
|
|
372
269
|
function isIdentifierValidCallee(state, path, callee, target) {
|
|
373
270
|
const binding = path.scope.getBindingIdentifier(callee.name);
|
|
374
271
|
if (binding) {
|
|
@@ -428,94 +325,56 @@ function isValidCallee(state, path, { callee }, target) {
|
|
|
428
325
|
return false;
|
|
429
326
|
}
|
|
430
327
|
|
|
431
|
-
function
|
|
432
|
-
if (t.
|
|
433
|
-
|
|
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;
|
|
328
|
+
function registerImportSpecifier(state, id, specifier) {
|
|
329
|
+
if (t.isImportDefaultSpecifier(specifier)) {
|
|
330
|
+
if (id.definition.kind === 'default') {
|
|
331
|
+
state.registrations.identifiers.set(specifier.local, id);
|
|
447
332
|
}
|
|
448
|
-
|
|
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;
|
|
333
|
+
return;
|
|
483
334
|
}
|
|
484
|
-
if (
|
|
485
|
-
|
|
335
|
+
if (t.isImportSpecifier(specifier)) {
|
|
336
|
+
if (specifier.importKind === 'type' || specifier.importKind === 'typeof') {
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
const name = getImportSpecifierName(specifier);
|
|
340
|
+
if ((id.definition.kind === 'named' && name === id.definition.name) ||
|
|
341
|
+
(id.definition.kind === 'default' && name === 'default')) {
|
|
342
|
+
state.registrations.identifiers.set(specifier.local, id);
|
|
343
|
+
}
|
|
344
|
+
return;
|
|
486
345
|
}
|
|
487
|
-
|
|
488
|
-
|
|
346
|
+
let current = state.registrations.namespaces.get(specifier.local);
|
|
347
|
+
if (!current) {
|
|
348
|
+
current = [];
|
|
489
349
|
}
|
|
490
|
-
|
|
350
|
+
current.push(id);
|
|
351
|
+
state.registrations.namespaces.set(specifier.local, current);
|
|
491
352
|
}
|
|
492
|
-
function
|
|
493
|
-
let
|
|
494
|
-
|
|
495
|
-
if (
|
|
496
|
-
|
|
353
|
+
function registerImportSpecifiers(state, path, definitions) {
|
|
354
|
+
for (let i = 0, len = definitions.length; i < len; i++) {
|
|
355
|
+
const id = definitions[i];
|
|
356
|
+
if (path.node.source.value === id.definition.source) {
|
|
357
|
+
for (let k = 0, klen = path.node.specifiers.length; k < klen; k++) {
|
|
358
|
+
registerImportSpecifier(state, id, path.node.specifiers[k]);
|
|
359
|
+
}
|
|
497
360
|
}
|
|
498
|
-
parent = parent.parentPath;
|
|
499
361
|
}
|
|
500
|
-
return false;
|
|
501
362
|
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
}
|
|
518
|
-
return collected;
|
|
363
|
+
|
|
364
|
+
function generateUniqueName(path, name) {
|
|
365
|
+
let uid;
|
|
366
|
+
let i = 1;
|
|
367
|
+
do {
|
|
368
|
+
uid = name + '_' + i;
|
|
369
|
+
i++;
|
|
370
|
+
} while (path.scope.hasLabel(uid) ||
|
|
371
|
+
path.scope.hasBinding(uid) ||
|
|
372
|
+
path.scope.hasGlobal(uid) ||
|
|
373
|
+
path.scope.hasReference(uid));
|
|
374
|
+
const program = path.scope.getProgramParent();
|
|
375
|
+
program.references[uid] = true;
|
|
376
|
+
program.uids[uid] = true;
|
|
377
|
+
return t.identifier(uid);
|
|
519
378
|
}
|
|
520
379
|
|
|
521
380
|
function getDescriptiveName(path, defaultName) {
|
|
@@ -552,22 +411,6 @@ function getDescriptiveName(path, defaultName) {
|
|
|
552
411
|
return defaultName;
|
|
553
412
|
}
|
|
554
413
|
|
|
555
|
-
function generateUniqueName(path, name) {
|
|
556
|
-
let uid;
|
|
557
|
-
let i = 1;
|
|
558
|
-
do {
|
|
559
|
-
uid = name + '_' + i;
|
|
560
|
-
i++;
|
|
561
|
-
} while (path.scope.hasLabel(uid) ||
|
|
562
|
-
path.scope.hasBinding(uid) ||
|
|
563
|
-
path.scope.hasGlobal(uid) ||
|
|
564
|
-
path.scope.hasReference(uid));
|
|
565
|
-
const program = path.scope.getProgramParent();
|
|
566
|
-
program.references[uid] = true;
|
|
567
|
-
program.uids[uid] = true;
|
|
568
|
-
return t.identifier(uid);
|
|
569
|
-
}
|
|
570
|
-
|
|
571
414
|
const REFRESH_JSX_SKIP = /^\s*@refresh jsx-skip\s*$/;
|
|
572
415
|
function shouldSkipJSX(node) {
|
|
573
416
|
// Node without leading comments shouldn't be skipped
|
|
@@ -679,6 +522,15 @@ function extractJSXExpressionsFromJSXElement(state, path) {
|
|
|
679
522
|
if ((isPathValid(openingName, t.isJSXIdentifier) &&
|
|
680
523
|
/^[A-Z_]/.test(openingName.node.name)) ||
|
|
681
524
|
isPathValid(openingName, t.isJSXMemberExpression)) {
|
|
525
|
+
if (isPathValid(openingName, t.isJSXIdentifier)) {
|
|
526
|
+
const binding = path.scope.getBinding(openingName.node.name);
|
|
527
|
+
if (binding) {
|
|
528
|
+
const statementPath = binding.path.getStatementParent();
|
|
529
|
+
if (statementPath && isStatementTopLevel(statementPath)) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
682
534
|
const key = pushAttribute(state, convertJSXOpeningToExpression(openingName.node));
|
|
683
535
|
const replacement = t.jsxMemberExpression(t.jsxIdentifier(state.props.name), t.jsxIdentifier(key));
|
|
684
536
|
openingName.replaceWith(replacement);
|
|
@@ -744,20 +596,196 @@ function transformJSX(path) {
|
|
|
744
596
|
if (path.node.loc) {
|
|
745
597
|
templateComp.loc = path.node.loc;
|
|
746
598
|
}
|
|
747
|
-
rootPath.insertBefore(t.variableDeclaration('const', [t.variableDeclarator(id, templateComp)]));
|
|
599
|
+
const [tmp] = rootPath.insertBefore(t.variableDeclaration('const', [t.variableDeclarator(id, templateComp)]));
|
|
600
|
+
rootPath.scope.registerDeclaration(tmp);
|
|
748
601
|
path.replaceWith(skippableJSX(t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier(id.name), [...state.attributes], true), t.jsxClosingElement(t.jsxIdentifier(id.name)), [], true)));
|
|
749
602
|
}
|
|
750
603
|
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
604
|
+
/**
|
|
605
|
+
* Copyright (c) 2019 Jason Dent
|
|
606
|
+
* https://github.com/Jason3S/xxhash
|
|
607
|
+
*/
|
|
608
|
+
const PRIME32_1 = 2654435761;
|
|
609
|
+
const PRIME32_2 = 2246822519;
|
|
610
|
+
const PRIME32_3 = 3266489917;
|
|
611
|
+
const PRIME32_4 = 668265263;
|
|
612
|
+
const PRIME32_5 = 374761393;
|
|
613
|
+
function toUtf8(text) {
|
|
614
|
+
const bytes = [];
|
|
615
|
+
for (let i = 0, n = text.length; i < n; ++i) {
|
|
616
|
+
const c = text.charCodeAt(i);
|
|
617
|
+
if (c < 0x80) {
|
|
618
|
+
bytes.push(c);
|
|
619
|
+
}
|
|
620
|
+
else if (c < 0x800) {
|
|
621
|
+
bytes.push(0xc0 | (c >> 6), 0x80 | (c & 0x3f));
|
|
622
|
+
}
|
|
623
|
+
else if (c < 0xd800 || c >= 0xe000) {
|
|
624
|
+
bytes.push(0xe0 | (c >> 12), 0x80 | ((c >> 6) & 0x3f), 0x80 | (c & 0x3f));
|
|
625
|
+
}
|
|
626
|
+
else {
|
|
627
|
+
const cp = 0x10000 + (((c & 0x3ff) << 10) | (text.charCodeAt(++i) & 0x3ff));
|
|
628
|
+
bytes.push(0xf0 | ((cp >> 18) & 0x7), 0x80 | ((cp >> 12) & 0x3f), 0x80 | ((cp >> 6) & 0x3f), 0x80 | (cp & 0x3f));
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return new Uint8Array(bytes);
|
|
758
632
|
}
|
|
759
|
-
|
|
760
|
-
|
|
633
|
+
/**
|
|
634
|
+
*
|
|
635
|
+
* @param buffer - byte array or string
|
|
636
|
+
* @param seed - optional seed (32-bit unsigned);
|
|
637
|
+
*/
|
|
638
|
+
function xxHash32(buffer, seed = 0) {
|
|
639
|
+
buffer = typeof buffer === 'string' ? toUtf8(buffer) : buffer;
|
|
640
|
+
const b = buffer;
|
|
641
|
+
/*
|
|
642
|
+
Step 1. Initialize internal accumulators
|
|
643
|
+
Each accumulator gets an initial value based on optional seed input. Since the seed is optional, it can be 0.
|
|
644
|
+
```
|
|
645
|
+
u32 acc1 = seed + PRIME32_1 + PRIME32_2;
|
|
646
|
+
u32 acc2 = seed + PRIME32_2;
|
|
647
|
+
u32 acc3 = seed + 0;
|
|
648
|
+
u32 acc4 = seed - PRIME32_1;
|
|
649
|
+
```
|
|
650
|
+
Special case : input is less than 16 bytes
|
|
651
|
+
When input is too small (< 16 bytes), the algorithm will not process any stripe. Consequently, it will not
|
|
652
|
+
make use of parallel accumulators.
|
|
653
|
+
In which case, a simplified initialization is performed, using a single accumulator :
|
|
654
|
+
u32 acc = seed + PRIME32_5;
|
|
655
|
+
The algorithm then proceeds directly to step 4.
|
|
656
|
+
*/
|
|
657
|
+
let acc = (seed + PRIME32_5) & 0xffffffff;
|
|
658
|
+
let offset = 0;
|
|
659
|
+
if (b.length >= 16) {
|
|
660
|
+
const accN = [
|
|
661
|
+
(seed + PRIME32_1 + PRIME32_2) & 0xffffffff,
|
|
662
|
+
(seed + PRIME32_2) & 0xffffffff,
|
|
663
|
+
(seed + 0) & 0xffffffff,
|
|
664
|
+
(seed - PRIME32_1) & 0xffffffff,
|
|
665
|
+
];
|
|
666
|
+
/*
|
|
667
|
+
Step 2. Process stripes
|
|
668
|
+
A stripe is a contiguous segment of 16 bytes. It is evenly divided into 4 lanes, of 4 bytes each.
|
|
669
|
+
The first lane is used to update accumulator 1, the second lane is used to update accumulator 2, and so on.
|
|
670
|
+
Each lane read its associated 32-bit value using little-endian convention.
|
|
671
|
+
For each {lane, accumulator}, the update process is called a round, and applies the following formula :
|
|
672
|
+
```
|
|
673
|
+
accN = accN + (laneN * PRIME32_2);
|
|
674
|
+
accN = accN <<< 13;
|
|
675
|
+
accN = accN * PRIME32_1;
|
|
676
|
+
```
|
|
677
|
+
This shuffles the bits so that any bit from input lane impacts several bits in output accumulator.
|
|
678
|
+
All operations are performed modulo 2^32.
|
|
679
|
+
Input is consumed one full stripe at a time. Step 2 is looped as many times as necessary to consume
|
|
680
|
+
the whole input, except the last remaining bytes which cannot form a stripe (< 16 bytes). When that
|
|
681
|
+
happens, move to step 3.
|
|
682
|
+
*/
|
|
683
|
+
const b = buffer;
|
|
684
|
+
const limit = b.length - 16;
|
|
685
|
+
let lane = 0;
|
|
686
|
+
for (offset = 0; (offset & 0xfffffff0) <= limit; offset += 4) {
|
|
687
|
+
const i = offset;
|
|
688
|
+
const laneN0 = b[i + 0] + (b[i + 1] << 8);
|
|
689
|
+
const laneN1 = b[i + 2] + (b[i + 3] << 8);
|
|
690
|
+
const laneNP = laneN0 * PRIME32_2 + ((laneN1 * PRIME32_2) << 16);
|
|
691
|
+
let acc = (accN[lane] + laneNP) & 0xffffffff;
|
|
692
|
+
acc = (acc << 13) | (acc >>> 19);
|
|
693
|
+
const acc0 = acc & 0xffff;
|
|
694
|
+
const acc1 = acc >>> 16;
|
|
695
|
+
accN[lane] = (acc0 * PRIME32_1 + ((acc1 * PRIME32_1) << 16)) & 0xffffffff;
|
|
696
|
+
lane = (lane + 1) & 0x3;
|
|
697
|
+
}
|
|
698
|
+
/*
|
|
699
|
+
Step 3. Accumulator convergence
|
|
700
|
+
All 4 lane accumulators from previous steps are merged to produce a single remaining accumulator
|
|
701
|
+
of same width (32-bit). The associated formula is as follows :
|
|
702
|
+
```
|
|
703
|
+
acc = (acc1 <<< 1) + (acc2 <<< 7) + (acc3 <<< 12) + (acc4 <<< 18);
|
|
704
|
+
```
|
|
705
|
+
*/
|
|
706
|
+
acc =
|
|
707
|
+
(((accN[0] << 1) | (accN[0] >>> 31)) +
|
|
708
|
+
((accN[1] << 7) | (accN[1] >>> 25)) +
|
|
709
|
+
((accN[2] << 12) | (accN[2] >>> 20)) +
|
|
710
|
+
((accN[3] << 18) | (accN[3] >>> 14))) &
|
|
711
|
+
0xffffffff;
|
|
712
|
+
}
|
|
713
|
+
/*
|
|
714
|
+
Step 4. Add input length
|
|
715
|
+
The input total length is presumed known at this stage. This step is just about adding the length to
|
|
716
|
+
accumulator, so that it participates to final mixing.
|
|
717
|
+
```
|
|
718
|
+
acc = acc + (u32)inputLength;
|
|
719
|
+
```
|
|
720
|
+
*/
|
|
721
|
+
acc = (acc + buffer.length) & 0xffffffff;
|
|
722
|
+
/*
|
|
723
|
+
Step 5. Consume remaining input
|
|
724
|
+
There may be up to 15 bytes remaining to consume from the input. The final stage will digest them according
|
|
725
|
+
to following pseudo-code :
|
|
726
|
+
```
|
|
727
|
+
while (remainingLength >= 4) {
|
|
728
|
+
lane = read_32bit_little_endian(input_ptr);
|
|
729
|
+
acc = acc + lane * PRIME32_3;
|
|
730
|
+
acc = (acc <<< 17) * PRIME32_4;
|
|
731
|
+
input_ptr += 4; remainingLength -= 4;
|
|
732
|
+
}
|
|
733
|
+
```
|
|
734
|
+
This process ensures that all input bytes are present in the final mix.
|
|
735
|
+
*/
|
|
736
|
+
const limit = buffer.length - 4;
|
|
737
|
+
for (; offset <= limit; offset += 4) {
|
|
738
|
+
const i = offset;
|
|
739
|
+
const laneN0 = b[i + 0] + (b[i + 1] << 8);
|
|
740
|
+
const laneN1 = b[i + 2] + (b[i + 3] << 8);
|
|
741
|
+
const laneP = laneN0 * PRIME32_3 + ((laneN1 * PRIME32_3) << 16);
|
|
742
|
+
acc = (acc + laneP) & 0xffffffff;
|
|
743
|
+
acc = (acc << 17) | (acc >>> 15);
|
|
744
|
+
acc =
|
|
745
|
+
((acc & 0xffff) * PRIME32_4 + (((acc >>> 16) * PRIME32_4) << 16)) &
|
|
746
|
+
0xffffffff;
|
|
747
|
+
}
|
|
748
|
+
/*
|
|
749
|
+
```
|
|
750
|
+
while (remainingLength >= 1) {
|
|
751
|
+
lane = read_byte(input_ptr);
|
|
752
|
+
acc = acc + lane * PRIME32_5;
|
|
753
|
+
acc = (acc <<< 11) * PRIME32_1;
|
|
754
|
+
input_ptr += 1; remainingLength -= 1;
|
|
755
|
+
}
|
|
756
|
+
```
|
|
757
|
+
*/
|
|
758
|
+
for (; offset < b.length; ++offset) {
|
|
759
|
+
const lane = b[offset];
|
|
760
|
+
acc = acc + lane * PRIME32_5;
|
|
761
|
+
acc = (acc << 11) | (acc >>> 21);
|
|
762
|
+
acc =
|
|
763
|
+
((acc & 0xffff) * PRIME32_1 + (((acc >>> 16) * PRIME32_1) << 16)) &
|
|
764
|
+
0xffffffff;
|
|
765
|
+
}
|
|
766
|
+
/*
|
|
767
|
+
Step 6. Final mix (avalanche)
|
|
768
|
+
The final mix ensures that all input bits have a chance to impact any bit in the output digest,
|
|
769
|
+
resulting in an unbiased distribution. This is also called avalanche effect.
|
|
770
|
+
```
|
|
771
|
+
acc = acc xor (acc >> 15);
|
|
772
|
+
acc = acc * PRIME32_2;
|
|
773
|
+
acc = acc xor (acc >> 13);
|
|
774
|
+
acc = acc * PRIME32_3;
|
|
775
|
+
acc = acc xor (acc >> 16);
|
|
776
|
+
```
|
|
777
|
+
*/
|
|
778
|
+
acc = acc ^ (acc >>> 15);
|
|
779
|
+
acc =
|
|
780
|
+
(((acc & 0xffff) * PRIME32_2) & 0xffffffff) +
|
|
781
|
+
(((acc >>> 16) * PRIME32_2) << 16);
|
|
782
|
+
acc = acc ^ (acc >>> 13);
|
|
783
|
+
acc =
|
|
784
|
+
(((acc & 0xffff) * PRIME32_3) & 0xffffffff) +
|
|
785
|
+
(((acc >>> 16) * PRIME32_3) << 16);
|
|
786
|
+
acc = acc ^ (acc >>> 16);
|
|
787
|
+
// turn any negatives back into a positive number;
|
|
788
|
+
return acc < 0 ? acc + 4294967296 : acc;
|
|
761
789
|
}
|
|
762
790
|
|
|
763
791
|
const CWD = process.cwd();
|
|
@@ -772,7 +800,7 @@ function createSignatureValue(node) {
|
|
|
772
800
|
function captureIdentifiers(state, path) {
|
|
773
801
|
path.traverse({
|
|
774
802
|
ImportDeclaration(p) {
|
|
775
|
-
if (p.node.importKind === '
|
|
803
|
+
if (!(p.node.importKind === 'type' || p.node.importKind === 'typeof')) {
|
|
776
804
|
registerImportSpecifiers(state, p, state.specifiers);
|
|
777
805
|
}
|
|
778
806
|
},
|
|
@@ -876,14 +904,8 @@ function setupProgram(state, path, comments) {
|
|
|
876
904
|
}
|
|
877
905
|
return isDone;
|
|
878
906
|
}
|
|
879
|
-
function
|
|
880
|
-
|
|
881
|
-
const programParent = path.scope.getProgramParent();
|
|
882
|
-
// a FunctionDeclaration binding refers to itself as the block parent
|
|
883
|
-
if (blockParent.path === path) {
|
|
884
|
-
blockParent = blockParent.parent;
|
|
885
|
-
}
|
|
886
|
-
return programParent === blockParent;
|
|
907
|
+
function isValidFunction(node) {
|
|
908
|
+
return t.isArrowFunctionExpression(node) || t.isFunctionExpression(node);
|
|
887
909
|
}
|
|
888
910
|
function transformVariableDeclarator(state, path) {
|
|
889
911
|
if (path.parentPath.isVariableDeclaration() &&
|
|
@@ -896,8 +918,7 @@ function transformVariableDeclarator(state, path) {
|
|
|
896
918
|
return;
|
|
897
919
|
}
|
|
898
920
|
if (isComponentishName(identifier.name)) {
|
|
899
|
-
const trueFuncExpr = unwrapNode(init,
|
|
900
|
-
unwrapNode(init, t.isArrowFunctionExpression);
|
|
921
|
+
const trueFuncExpr = unwrapNode(init, isValidFunction);
|
|
901
922
|
// Check for valid FunctionExpression or ArrowFunctionExpression
|
|
902
923
|
if (trueFuncExpr &&
|
|
903
924
|
// Must not be async or generator
|
|
@@ -929,9 +950,10 @@ function transformFunctionDeclaration(state, path) {
|
|
|
929
950
|
// Might be component-like, but the only valid components
|
|
930
951
|
// have zero or one parameter
|
|
931
952
|
decl.params.length < 2) {
|
|
932
|
-
path.replaceWith(t.variableDeclaration('const', [
|
|
953
|
+
const [tmp] = path.replaceWith(t.variableDeclaration('const', [
|
|
933
954
|
t.variableDeclarator(decl.id, wrapComponent(state, path, decl.id, t.functionExpression(decl.id, decl.params, decl.body), decl)),
|
|
934
955
|
]));
|
|
956
|
+
path.scope.registerDeclaration(tmp);
|
|
935
957
|
path.skip();
|
|
936
958
|
}
|
|
937
959
|
}
|
|
@@ -951,6 +973,7 @@ function bubbleFunctionDeclaration(program, path) {
|
|
|
951
973
|
decl.params.length < 2) {
|
|
952
974
|
const first = program.get('body')[0];
|
|
953
975
|
const [tmp] = first.insertBefore(decl);
|
|
976
|
+
program.scope.registerDeclaration(tmp);
|
|
954
977
|
tmp.skip();
|
|
955
978
|
if (path.parentPath.isExportNamedDeclaration()) {
|
|
956
979
|
path.parentPath.replaceWith(t.exportNamedDeclaration(undefined, [
|
|
@@ -993,7 +1016,6 @@ function solidRefreshPlugin() {
|
|
|
993
1016
|
bubbleFunctionDeclaration(programPath, path);
|
|
994
1017
|
},
|
|
995
1018
|
});
|
|
996
|
-
programPath.scope.crawl();
|
|
997
1019
|
programPath.traverse({
|
|
998
1020
|
JSXElement(path) {
|
|
999
1021
|
transformJSX(path);
|
|
@@ -1002,7 +1024,6 @@ function solidRefreshPlugin() {
|
|
|
1002
1024
|
transformJSX(path);
|
|
1003
1025
|
},
|
|
1004
1026
|
});
|
|
1005
|
-
programPath.scope.crawl();
|
|
1006
1027
|
programPath.traverse({
|
|
1007
1028
|
VariableDeclarator(path) {
|
|
1008
1029
|
transformVariableDeclarator(state, path);
|
|
@@ -1011,7 +1032,6 @@ function solidRefreshPlugin() {
|
|
|
1011
1032
|
transformFunctionDeclaration(state, path);
|
|
1012
1033
|
},
|
|
1013
1034
|
});
|
|
1014
|
-
programPath.scope.crawl();
|
|
1015
1035
|
},
|
|
1016
1036
|
},
|
|
1017
1037
|
};
|