@remix-run/assets 0.0.0 → 0.2.0
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/LICENSE +21 -0
- package/README.md +325 -2
- package/dist/assets.d.ts +3 -0
- package/dist/assets.d.ts.map +1 -0
- package/dist/assets.js +1 -0
- package/dist/lib/access.d.ts +10 -0
- package/dist/lib/access.d.ts.map +1 -0
- package/dist/lib/access.js +14 -0
- package/dist/lib/asset-server.d.ts +139 -0
- package/dist/lib/asset-server.d.ts.map +1 -0
- package/dist/lib/asset-server.js +338 -0
- package/dist/lib/compilation-error.d.ts +33 -0
- package/dist/lib/compilation-error.d.ts.map +1 -0
- package/dist/lib/compilation-error.js +32 -0
- package/dist/lib/file-matcher.d.ts +6 -0
- package/dist/lib/file-matcher.d.ts.map +1 -0
- package/dist/lib/file-matcher.js +44 -0
- package/dist/lib/fingerprint.d.ts +12 -0
- package/dist/lib/fingerprint.d.ts.map +1 -0
- package/dist/lib/fingerprint.js +49 -0
- package/dist/lib/module-store.d.ts +41 -0
- package/dist/lib/module-store.d.ts.map +1 -0
- package/dist/lib/module-store.js +230 -0
- package/dist/lib/paths.d.ts +8 -0
- package/dist/lib/paths.d.ts.map +1 -0
- package/dist/lib/paths.js +50 -0
- package/dist/lib/routes.d.ts +13 -0
- package/dist/lib/routes.d.ts.map +1 -0
- package/dist/lib/routes.js +94 -0
- package/dist/lib/scripts/cjs-check.d.ts +3 -0
- package/dist/lib/scripts/cjs-check.d.ts.map +1 -0
- package/dist/lib/scripts/cjs-check.js +398 -0
- package/dist/lib/scripts/compiler.d.ts +62 -0
- package/dist/lib/scripts/compiler.d.ts.map +1 -0
- package/dist/lib/scripts/compiler.js +439 -0
- package/dist/lib/scripts/emit.d.ts +25 -0
- package/dist/lib/scripts/emit.d.ts.map +1 -0
- package/dist/lib/scripts/emit.js +63 -0
- package/dist/lib/scripts/resolve.d.ts +50 -0
- package/dist/lib/scripts/resolve.d.ts.map +1 -0
- package/dist/lib/scripts/resolve.js +236 -0
- package/dist/lib/scripts/transform.d.ts +64 -0
- package/dist/lib/scripts/transform.d.ts.map +1 -0
- package/dist/lib/scripts/transform.js +373 -0
- package/dist/lib/source-maps.d.ts +4 -0
- package/dist/lib/source-maps.d.ts.map +1 -0
- package/dist/lib/source-maps.js +62 -0
- package/dist/lib/styles/compiler.d.ts +52 -0
- package/dist/lib/styles/compiler.d.ts.map +1 -0
- package/dist/lib/styles/compiler.js +272 -0
- package/dist/lib/styles/emit.d.ts +25 -0
- package/dist/lib/styles/emit.d.ts.map +1 -0
- package/dist/lib/styles/emit.js +78 -0
- package/dist/lib/styles/resolve.d.ts +48 -0
- package/dist/lib/styles/resolve.d.ts.map +1 -0
- package/dist/lib/styles/resolve.js +188 -0
- package/dist/lib/styles/transform.d.ts +47 -0
- package/dist/lib/styles/transform.d.ts.map +1 -0
- package/dist/lib/styles/transform.js +131 -0
- package/dist/lib/target.d.ts +21 -0
- package/dist/lib/target.d.ts.map +1 -0
- package/dist/lib/target.js +127 -0
- package/dist/lib/watch.d.ts +22 -0
- package/dist/lib/watch.d.ts.map +1 -0
- package/dist/lib/watch.js +96 -0
- package/package.json +55 -12
- package/src/assets.ts +2 -0
- package/src/lib/access.ts +24 -0
- package/src/lib/asset-server.ts +537 -0
- package/src/lib/compilation-error.ts +61 -0
- package/src/lib/file-matcher.ts +63 -0
- package/src/lib/fingerprint.ts +65 -0
- package/src/lib/module-store.ts +340 -0
- package/src/lib/paths.ts +66 -0
- package/src/lib/routes.ts +164 -0
- package/src/lib/scripts/cjs-check.ts +476 -0
- package/src/lib/scripts/compiler.ts +640 -0
- package/src/lib/scripts/emit.ts +122 -0
- package/src/lib/scripts/resolve.ts +433 -0
- package/src/lib/scripts/transform.ts +609 -0
- package/src/lib/source-maps.ts +75 -0
- package/src/lib/styles/compiler.ts +400 -0
- package/src/lib/styles/emit.ts +137 -0
- package/src/lib/styles/resolve.ts +316 -0
- package/src/lib/styles/transform.ts +226 -0
- package/src/lib/target.ts +196 -0
- package/src/lib/watch.ts +136 -0
|
@@ -0,0 +1,398 @@
|
|
|
1
|
+
import { parseSync, visitorKeys } from 'oxc-parser';
|
|
2
|
+
const suspiciousCommonJSPattern = /\brequire\s*(?:\(|\.|\[)|\bmodule\s*(?:\.\s*exports|\[\s*['"`]exports['"`]\s*\])|\bexports\s*(?:\.|=|\[)/;
|
|
3
|
+
export function mayContainCommonJSModuleGlobals(source) {
|
|
4
|
+
return suspiciousCommonJSPattern.test(source);
|
|
5
|
+
}
|
|
6
|
+
// Detects CommonJS module globals that cannot be served as ES modules.
|
|
7
|
+
export function isCommonJS(source) {
|
|
8
|
+
try {
|
|
9
|
+
let result = parseSync('module.js', source, {
|
|
10
|
+
lang: 'js',
|
|
11
|
+
sourceType: 'module',
|
|
12
|
+
});
|
|
13
|
+
if (result.errors.length > 0) {
|
|
14
|
+
return suspiciousCommonJSPattern.test(source);
|
|
15
|
+
}
|
|
16
|
+
return containsCommonJSModuleGlobals(result.program);
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
return suspiciousCommonJSPattern.test(source);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function containsCommonJSModuleGlobals(program) {
|
|
23
|
+
let moduleScope = createScope(null, 'module');
|
|
24
|
+
let nodeScopes = new WeakMap();
|
|
25
|
+
nodeScopes.set(program, moduleScope);
|
|
26
|
+
collectScopeBindings(program, moduleScope, nodeScopes);
|
|
27
|
+
return walkForCommonJS(program, nodeScopes, moduleScope);
|
|
28
|
+
}
|
|
29
|
+
function walkForCommonJS(node, nodeScopes, currentScope, parent = null, key) {
|
|
30
|
+
let nextScope = nodeScopes.get(node) ?? currentScope;
|
|
31
|
+
switch (node.type) {
|
|
32
|
+
case 'ImportDeclaration':
|
|
33
|
+
return false;
|
|
34
|
+
case 'VariableDeclarator':
|
|
35
|
+
if (isAstNode(node.init) && walkForCommonJS(node.init, nodeScopes, nextScope, node, 'init')) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
return walkPatternForCommonJS(node.id, nodeScopes, nextScope);
|
|
39
|
+
case 'FunctionDeclaration':
|
|
40
|
+
case 'FunctionExpression':
|
|
41
|
+
case 'ArrowFunctionExpression':
|
|
42
|
+
for (let param of getNodeArray(node.params)) {
|
|
43
|
+
if (walkPatternForCommonJS(param, nodeScopes, nextScope))
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
return isAstNode(node.body)
|
|
47
|
+
? walkForCommonJS(node.body, nodeScopes, nextScope, node, 'body')
|
|
48
|
+
: false;
|
|
49
|
+
case 'CatchClause':
|
|
50
|
+
if (walkPatternForCommonJS(node.param, nodeScopes, nextScope))
|
|
51
|
+
return true;
|
|
52
|
+
return isAstNode(node.body)
|
|
53
|
+
? walkForCommonJS(node.body, nodeScopes, nextScope, node, 'body')
|
|
54
|
+
: false;
|
|
55
|
+
case 'Property':
|
|
56
|
+
if (node.computed &&
|
|
57
|
+
isAstNode(node.key) &&
|
|
58
|
+
walkForCommonJS(node.key, nodeScopes, nextScope, node, 'key')) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return isAstNode(node.value)
|
|
62
|
+
? walkForCommonJS(node.value, nodeScopes, nextScope, node, 'value')
|
|
63
|
+
: false;
|
|
64
|
+
case 'MemberExpression':
|
|
65
|
+
if (isAstNode(node.object) &&
|
|
66
|
+
walkForCommonJS(node.object, nodeScopes, nextScope, node, 'object')) {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return (!!node.computed &&
|
|
70
|
+
isAstNode(node.property) &&
|
|
71
|
+
walkForCommonJS(node.property, nodeScopes, nextScope, node, 'property'));
|
|
72
|
+
case 'ExportSpecifier':
|
|
73
|
+
return isAstNode(node.local)
|
|
74
|
+
? walkForCommonJS(node.local, nodeScopes, nextScope, node, 'local')
|
|
75
|
+
: false;
|
|
76
|
+
case 'Identifier':
|
|
77
|
+
if (!isIdentifier(node) || !isReferenceIdentifier(node, parent, key))
|
|
78
|
+
return false;
|
|
79
|
+
if (resolveBindingKind(node.name, nextScope) !== null)
|
|
80
|
+
return false;
|
|
81
|
+
return isCommonJSReference(node, parent, key);
|
|
82
|
+
}
|
|
83
|
+
for (let child of getChildNodes(node)) {
|
|
84
|
+
if (walkForCommonJS(child.node, nodeScopes, nextScope, node, child.key)) {
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
function walkPatternForCommonJS(node, nodeScopes, currentScope) {
|
|
91
|
+
if (!isAstNode(node))
|
|
92
|
+
return false;
|
|
93
|
+
switch (node.type) {
|
|
94
|
+
case 'Identifier':
|
|
95
|
+
return false;
|
|
96
|
+
case 'AssignmentPattern':
|
|
97
|
+
return (walkPatternForCommonJS(node.left, nodeScopes, currentScope) ||
|
|
98
|
+
(isAstNode(node.right) && walkForCommonJS(node.right, nodeScopes, currentScope)));
|
|
99
|
+
case 'RestElement':
|
|
100
|
+
return walkPatternForCommonJS(node.argument, nodeScopes, currentScope);
|
|
101
|
+
case 'ArrayPattern':
|
|
102
|
+
return getNodeArray(node.elements).some((element) => walkPatternForCommonJS(element, nodeScopes, currentScope));
|
|
103
|
+
case 'ObjectPattern':
|
|
104
|
+
return getNodeArray(node.properties).some((property) => {
|
|
105
|
+
if (property.type === 'Property') {
|
|
106
|
+
return ((property.computed &&
|
|
107
|
+
isAstNode(property.key) &&
|
|
108
|
+
walkForCommonJS(property.key, nodeScopes, currentScope, property, 'key')) ||
|
|
109
|
+
walkPatternForCommonJS(property.value, nodeScopes, currentScope));
|
|
110
|
+
}
|
|
111
|
+
return walkPatternForCommonJS(property.argument, nodeScopes, currentScope);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
function collectScopeBindings(node, currentScope, nodeScopes) {
|
|
117
|
+
switch (node.type) {
|
|
118
|
+
case 'Program':
|
|
119
|
+
forEachChildNode(node, (child) => collectScopeBindings(child, currentScope, nodeScopes));
|
|
120
|
+
return;
|
|
121
|
+
case 'ImportDeclaration':
|
|
122
|
+
for (let specifier of getNodeArray(node.specifiers)) {
|
|
123
|
+
if (isAstNode(specifier) && isIdentifier(specifier.local)) {
|
|
124
|
+
currentScope.bindings.add(specifier.local.name);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return;
|
|
128
|
+
case 'VariableDeclaration': {
|
|
129
|
+
let targetScope = node.kind === 'var' ? getFunctionScope(currentScope) : currentScope;
|
|
130
|
+
for (let declaration of getNodeArray(node.declarations)) {
|
|
131
|
+
collectPatternBindings(declaration.id, targetScope);
|
|
132
|
+
if (isAstNode(declaration.init)) {
|
|
133
|
+
collectScopeBindings(declaration.init, currentScope, nodeScopes);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
case 'FunctionDeclaration': {
|
|
139
|
+
if (isIdentifier(node.id)) {
|
|
140
|
+
currentScope.bindings.add(node.id.name);
|
|
141
|
+
}
|
|
142
|
+
let functionScope = createScope(currentScope, 'function');
|
|
143
|
+
nodeScopes.set(node, functionScope);
|
|
144
|
+
if (isIdentifier(node.id)) {
|
|
145
|
+
functionScope.bindings.add(node.id.name);
|
|
146
|
+
}
|
|
147
|
+
for (let param of getNodeArray(node.params)) {
|
|
148
|
+
collectPatternBindings(param, functionScope);
|
|
149
|
+
collectPatternScopeBindings(param, functionScope, nodeScopes);
|
|
150
|
+
}
|
|
151
|
+
if (isAstNode(node.body)) {
|
|
152
|
+
collectScopeBindings(node.body, functionScope, nodeScopes);
|
|
153
|
+
}
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
case 'FunctionExpression':
|
|
157
|
+
case 'ArrowFunctionExpression': {
|
|
158
|
+
let functionScope = createScope(currentScope, 'function');
|
|
159
|
+
nodeScopes.set(node, functionScope);
|
|
160
|
+
if (node.type === 'FunctionExpression' && isIdentifier(node.id)) {
|
|
161
|
+
functionScope.bindings.add(node.id.name);
|
|
162
|
+
}
|
|
163
|
+
for (let param of getNodeArray(node.params)) {
|
|
164
|
+
collectPatternBindings(param, functionScope);
|
|
165
|
+
collectPatternScopeBindings(param, functionScope, nodeScopes);
|
|
166
|
+
}
|
|
167
|
+
if (isAstNode(node.body)) {
|
|
168
|
+
collectScopeBindings(node.body, functionScope, nodeScopes);
|
|
169
|
+
}
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
case 'ClassDeclaration':
|
|
173
|
+
if (isIdentifier(node.id)) {
|
|
174
|
+
currentScope.bindings.add(node.id.name);
|
|
175
|
+
}
|
|
176
|
+
break;
|
|
177
|
+
case 'ClassExpression':
|
|
178
|
+
if (isIdentifier(node.id)) {
|
|
179
|
+
let classScope = createScope(currentScope, 'block');
|
|
180
|
+
classScope.bindings.add(node.id.name);
|
|
181
|
+
nodeScopes.set(node, classScope);
|
|
182
|
+
forEachChildNode(node, (child, key) => {
|
|
183
|
+
if (key !== 'id') {
|
|
184
|
+
collectScopeBindings(child, classScope, nodeScopes);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
break;
|
|
190
|
+
case 'BlockStatement':
|
|
191
|
+
case 'ForStatement':
|
|
192
|
+
case 'ForInStatement':
|
|
193
|
+
case 'ForOfStatement':
|
|
194
|
+
case 'SwitchStatement': {
|
|
195
|
+
let blockScope = createScope(currentScope, 'block');
|
|
196
|
+
nodeScopes.set(node, blockScope);
|
|
197
|
+
forEachChildNode(node, (child) => collectScopeBindings(child, blockScope, nodeScopes));
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
case 'CatchClause': {
|
|
201
|
+
let catchScope = createScope(currentScope, 'block');
|
|
202
|
+
nodeScopes.set(node, catchScope);
|
|
203
|
+
collectPatternBindings(node.param, catchScope);
|
|
204
|
+
collectPatternScopeBindings(node.param, catchScope, nodeScopes);
|
|
205
|
+
if (isAstNode(node.body)) {
|
|
206
|
+
collectScopeBindings(node.body, catchScope, nodeScopes);
|
|
207
|
+
}
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
forEachChildNode(node, (child) => collectScopeBindings(child, currentScope, nodeScopes));
|
|
212
|
+
}
|
|
213
|
+
function collectPatternBindings(node, scope) {
|
|
214
|
+
if (!isAstNode(node))
|
|
215
|
+
return;
|
|
216
|
+
switch (node.type) {
|
|
217
|
+
case 'Identifier':
|
|
218
|
+
if (isIdentifier(node)) {
|
|
219
|
+
scope.bindings.add(node.name);
|
|
220
|
+
}
|
|
221
|
+
return;
|
|
222
|
+
case 'RestElement':
|
|
223
|
+
collectPatternBindings(node.argument, scope);
|
|
224
|
+
return;
|
|
225
|
+
case 'AssignmentPattern':
|
|
226
|
+
collectPatternBindings(node.left, scope);
|
|
227
|
+
return;
|
|
228
|
+
case 'ArrayPattern':
|
|
229
|
+
for (let element of getNodeArray(node.elements)) {
|
|
230
|
+
collectPatternBindings(element, scope);
|
|
231
|
+
}
|
|
232
|
+
return;
|
|
233
|
+
case 'ObjectPattern':
|
|
234
|
+
for (let property of getNodeArray(node.properties)) {
|
|
235
|
+
if (property.type === 'Property') {
|
|
236
|
+
collectPatternBindings(property.value, scope);
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
collectPatternBindings(property.argument, scope);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function collectPatternScopeBindings(node, currentScope, nodeScopes) {
|
|
246
|
+
if (!isAstNode(node))
|
|
247
|
+
return;
|
|
248
|
+
switch (node.type) {
|
|
249
|
+
case 'AssignmentPattern':
|
|
250
|
+
collectPatternScopeBindings(node.left, currentScope, nodeScopes);
|
|
251
|
+
if (isAstNode(node.right)) {
|
|
252
|
+
collectScopeBindings(node.right, currentScope, nodeScopes);
|
|
253
|
+
}
|
|
254
|
+
return;
|
|
255
|
+
case 'ArrayPattern':
|
|
256
|
+
for (let element of getNodeArray(node.elements)) {
|
|
257
|
+
collectPatternScopeBindings(element, currentScope, nodeScopes);
|
|
258
|
+
}
|
|
259
|
+
return;
|
|
260
|
+
case 'ObjectPattern':
|
|
261
|
+
for (let property of getNodeArray(node.properties)) {
|
|
262
|
+
if (property.type === 'Property') {
|
|
263
|
+
if (property.computed && isAstNode(property.key)) {
|
|
264
|
+
collectScopeBindings(property.key, currentScope, nodeScopes);
|
|
265
|
+
}
|
|
266
|
+
collectPatternScopeBindings(property.value, currentScope, nodeScopes);
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
collectPatternScopeBindings(property.argument, currentScope, nodeScopes);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return;
|
|
273
|
+
case 'RestElement':
|
|
274
|
+
collectPatternScopeBindings(node.argument, currentScope, nodeScopes);
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function isCommonJSReference(node, parent, key) {
|
|
279
|
+
if (parent === null)
|
|
280
|
+
return false;
|
|
281
|
+
if (node.name === 'require') {
|
|
282
|
+
return ((parent.type === 'CallExpression' && key === 'callee') ||
|
|
283
|
+
(parent.type === 'MemberExpression' && key === 'object'));
|
|
284
|
+
}
|
|
285
|
+
if (node.name === 'exports') {
|
|
286
|
+
return ((parent.type === 'AssignmentExpression' && key === 'left') ||
|
|
287
|
+
(parent.type === 'MemberExpression' && key === 'object'));
|
|
288
|
+
}
|
|
289
|
+
return (node.name === 'module' &&
|
|
290
|
+
parent.type === 'MemberExpression' &&
|
|
291
|
+
key === 'object' &&
|
|
292
|
+
isMemberPropertyNamed(parent.property, 'exports'));
|
|
293
|
+
}
|
|
294
|
+
function resolveBindingKind(name, currentScope) {
|
|
295
|
+
let scope = currentScope;
|
|
296
|
+
while (scope !== null) {
|
|
297
|
+
if (scope.bindings.has(name))
|
|
298
|
+
return 'local';
|
|
299
|
+
scope = scope.parent;
|
|
300
|
+
}
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
function createScope(parent, kind) {
|
|
304
|
+
return {
|
|
305
|
+
bindings: new Set(),
|
|
306
|
+
kind,
|
|
307
|
+
parent,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
function getFunctionScope(scope) {
|
|
311
|
+
let current = scope;
|
|
312
|
+
while (current.kind === 'block' && current.parent !== null) {
|
|
313
|
+
current = current.parent;
|
|
314
|
+
}
|
|
315
|
+
return current;
|
|
316
|
+
}
|
|
317
|
+
function isReferenceIdentifier(node, parent, key) {
|
|
318
|
+
if (parent === null)
|
|
319
|
+
return false;
|
|
320
|
+
if (parent.type === 'ClassDeclaration' || parent.type === 'ClassExpression') {
|
|
321
|
+
return key !== 'id';
|
|
322
|
+
}
|
|
323
|
+
if (parent.type === 'Property' && key === 'key' && !parent.computed) {
|
|
324
|
+
return false;
|
|
325
|
+
}
|
|
326
|
+
if ((parent.type === 'PropertyDefinition' || parent.type === 'MethodDefinition') &&
|
|
327
|
+
key === 'key' &&
|
|
328
|
+
!parent.computed) {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
if (parent.type === 'MemberExpression' && key === 'property' && !parent.computed) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
if (parent.type === 'MetaProperty')
|
|
335
|
+
return false;
|
|
336
|
+
if ((parent.type === 'LabeledStatement' ||
|
|
337
|
+
parent.type === 'BreakStatement' ||
|
|
338
|
+
parent.type === 'ContinueStatement') &&
|
|
339
|
+
key === 'label') {
|
|
340
|
+
return false;
|
|
341
|
+
}
|
|
342
|
+
if (parent.type === 'ExportSpecifier' && key === 'exported')
|
|
343
|
+
return false;
|
|
344
|
+
return true;
|
|
345
|
+
}
|
|
346
|
+
function getChildNodes(node) {
|
|
347
|
+
let children = [];
|
|
348
|
+
forEachChildNode(node, (child, key) => {
|
|
349
|
+
children.push({ key, node: child });
|
|
350
|
+
});
|
|
351
|
+
return children;
|
|
352
|
+
}
|
|
353
|
+
function forEachChildNode(node, callback) {
|
|
354
|
+
for (let key of visitorKeys[node.type] ?? []) {
|
|
355
|
+
let value = node[key];
|
|
356
|
+
if (Array.isArray(value)) {
|
|
357
|
+
for (let child of value) {
|
|
358
|
+
if (isAstNode(child)) {
|
|
359
|
+
callback(child, key);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
if (isAstNode(value)) {
|
|
365
|
+
callback(value, key);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
function getNodeArray(value) {
|
|
370
|
+
return Array.isArray(value) ? value.filter(isAstNode) : [];
|
|
371
|
+
}
|
|
372
|
+
function isMemberPropertyNamed(node, name) {
|
|
373
|
+
if (isIdentifier(node))
|
|
374
|
+
return node.name === name;
|
|
375
|
+
return isStaticStringValue(node, name);
|
|
376
|
+
}
|
|
377
|
+
function isStaticStringValue(node, value) {
|
|
378
|
+
if (!isAstNode(node))
|
|
379
|
+
return false;
|
|
380
|
+
if (node.type === 'Literal')
|
|
381
|
+
return node.value === value;
|
|
382
|
+
return (node.type === 'TemplateLiteral' &&
|
|
383
|
+
Array.isArray(node.expressions) &&
|
|
384
|
+
node.expressions.length === 0 &&
|
|
385
|
+
Array.isArray(node.quasis) &&
|
|
386
|
+
node.quasis.length === 1 &&
|
|
387
|
+
isAstNode(node.quasis[0]) &&
|
|
388
|
+
!!node.quasis[0].value &&
|
|
389
|
+
typeof node.quasis[0].value === 'object' &&
|
|
390
|
+
'raw' in node.quasis[0].value &&
|
|
391
|
+
node.quasis[0].value.raw === value);
|
|
392
|
+
}
|
|
393
|
+
function isAstNode(node) {
|
|
394
|
+
return !!node && typeof node === 'object' && 'type' in node && typeof node.type === 'string';
|
|
395
|
+
}
|
|
396
|
+
function isIdentifier(node) {
|
|
397
|
+
return isAstNode(node) && node.type === 'Identifier' && typeof node.name === 'string';
|
|
398
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { CompiledRoutes } from '../routes.ts';
|
|
2
|
+
import type { ResolvedScriptTarget } from '../target.ts';
|
|
3
|
+
import type { ModuleWatchEvent } from '../module-store.ts';
|
|
4
|
+
import type { EmittedAsset } from './emit.ts';
|
|
5
|
+
type ScriptCompileResult = {
|
|
6
|
+
code: EmittedAsset;
|
|
7
|
+
fingerprint: string | null;
|
|
8
|
+
sourceMap: EmittedAsset | null;
|
|
9
|
+
};
|
|
10
|
+
type ScriptGetResult = {
|
|
11
|
+
script: ScriptCompileResult;
|
|
12
|
+
type: 'script';
|
|
13
|
+
} | {
|
|
14
|
+
type: 'not-modified';
|
|
15
|
+
etag: string;
|
|
16
|
+
};
|
|
17
|
+
type ScriptGetOptions = {
|
|
18
|
+
ifNoneMatch: string | null;
|
|
19
|
+
isSourceMapRequest: boolean;
|
|
20
|
+
requestedFingerprint: string | null;
|
|
21
|
+
};
|
|
22
|
+
type ScriptCompilerOptions = {
|
|
23
|
+
buildId?: string;
|
|
24
|
+
define?: Record<string, string>;
|
|
25
|
+
external: string[];
|
|
26
|
+
fingerprintAssets: boolean;
|
|
27
|
+
isAllowed(absolutePath: string): boolean;
|
|
28
|
+
minify: boolean;
|
|
29
|
+
onWatchDirectoriesChange?: (delta: {
|
|
30
|
+
add: string[];
|
|
31
|
+
remove: string[];
|
|
32
|
+
}) => void;
|
|
33
|
+
rootDir: string;
|
|
34
|
+
routes: CompiledRoutes;
|
|
35
|
+
sourceMapSourcePaths: 'absolute' | 'url';
|
|
36
|
+
sourceMaps?: 'external' | 'inline';
|
|
37
|
+
target?: ResolvedScriptTarget;
|
|
38
|
+
watchIgnore?: readonly string[];
|
|
39
|
+
watchMode: boolean;
|
|
40
|
+
};
|
|
41
|
+
type ScriptCompiler = {
|
|
42
|
+
getScript(filePath: string, options: ScriptGetOptions): Promise<ScriptGetResult>;
|
|
43
|
+
getPreloadLayers(filePath: string | readonly string[]): Promise<string[][]>;
|
|
44
|
+
getHref(filePath: string): Promise<string>;
|
|
45
|
+
handleFileEvent(filePath: string, event: ModuleWatchEvent): Promise<void>;
|
|
46
|
+
parseRequestPathname(pathname: string): ParsedRequestPathname | null;
|
|
47
|
+
};
|
|
48
|
+
type ParsedRequestPathname = {
|
|
49
|
+
cacheControl: string;
|
|
50
|
+
filePath: string;
|
|
51
|
+
isSourceMapRequest: boolean;
|
|
52
|
+
requestedFingerprint: string | null;
|
|
53
|
+
};
|
|
54
|
+
export declare function createScriptCompiler(options: ScriptCompilerOptions): ScriptCompiler;
|
|
55
|
+
export declare function createResponseForScript(result: ScriptCompileResult, options: {
|
|
56
|
+
cacheControl: string;
|
|
57
|
+
ifNoneMatch: string | null;
|
|
58
|
+
isSourceMapRequest: boolean;
|
|
59
|
+
method: string;
|
|
60
|
+
}): Response;
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../../../src/lib/scripts/compiler.ts"],"names":[],"mappings":"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"}
|