@navecss/core 0.3.0 → 0.4.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/README.md +21 -4
- package/dist/atom-names-2OreuBx9.d.ts +27 -0
- package/dist/atoms.d.ts +3 -13
- package/dist/atoms.js +2 -1
- package/dist/bin.js +6 -4
- package/dist/{chunk-IZQLFUQU.js → chunk-2A7IUZBH.js} +2 -1
- package/dist/{chunk-LIUB4EES.js → chunk-CUL5PLPI.js} +1 -5
- package/dist/chunk-E5F6YF7A.js +2428 -0
- package/dist/chunk-GZL2VW7C.js +57 -0
- package/dist/{chunk-S7DZUVV3.js → chunk-LADFXRWQ.js} +3 -300
- package/dist/{chunk-R6JJZGXC.js → chunk-LQSGQ2OA.js} +1 -1
- package/dist/chunk-SYNQJNVB.js +302 -0
- package/dist/collect.d.ts +279 -0
- package/dist/collect.js +4 -0
- package/dist/cx.d.ts +1 -1
- package/dist/cx.js +14 -1
- package/dist/lightningcss.d.ts +1 -0
- package/dist/lightningcss.js +6 -4
- package/dist/postcss.d.ts +1 -0
- package/dist/postcss.js +4 -2
- package/dist/standalone.css +2 -0
- package/dist/vite-options-D1-hGA9L.d.ts +86 -0
- package/dist/vite.d.ts +5 -67
- package/dist/vite.js +298 -2192
- package/package.json +6 -2
- package/skills/navecss/SKILL.md +2 -0
package/dist/vite.js
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { findingsInText, formatFinding } from './chunk-UANF3FGO.js';
|
|
2
|
-
import {
|
|
2
|
+
import { assertOptions, resolveUsedOptions, keptAtoms, atomsWrittenIn, applyEdits, compareText, withoutRemoved, CX_SOURCE, toSourceMap, isSecondHop, buildReport, moduleReport, isListableReexport, readModule, combinedMapOf, placerFor, cxModulesArray, nodeAt, staticStringOf, pushAll, childrenOf, nodesAt, LINE_UNKNOWN_WITHOUT_MAP, LINE_UNKNOWN_UNMAPPED, exportNameOf, atomOfClass, analyze, memberReadOf, patternDestructuring, stringAt, propertyNameOf } from './chunk-E5F6YF7A.js';
|
|
3
|
+
import { validateExtendAtomsHostFree } from './chunk-LQSGQ2OA.js';
|
|
3
4
|
import { resolveExtendSpecifier, applyExtendModule } from './chunk-NKUZNRF4.js';
|
|
4
|
-
import { snapshotExtendMap,
|
|
5
|
+
import { snapshotExtendMap, expandText, foldLocated } from './chunk-LADFXRWQ.js';
|
|
5
6
|
import { tokenize } from './chunk-NFS2REPQ.js';
|
|
6
|
-
import {
|
|
7
|
+
import { decodeIncomingMap, formatDiagnostic } from './chunk-SYNQJNVB.js';
|
|
8
|
+
import './chunk-CUL5PLPI.js';
|
|
9
|
+
import { atomClassMap } from './chunk-GZL2VW7C.js';
|
|
7
10
|
import { readFile } from 'fs/promises';
|
|
8
11
|
import path2 from 'path';
|
|
9
12
|
import { fileURLToPath } from 'url';
|
|
@@ -144,1544 +147,6 @@ function shareAcrossBuilds(assemble2) {
|
|
|
144
147
|
return [firstHalf(pickers, configure), secondHalf(pickers)];
|
|
145
148
|
}
|
|
146
149
|
|
|
147
|
-
// src/vite-ast.ts
|
|
148
|
-
function isNode(value) {
|
|
149
|
-
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
150
|
-
}
|
|
151
|
-
function nodeAt(node, key) {
|
|
152
|
-
const value = node[key];
|
|
153
|
-
return isNode(value) ? value : void 0;
|
|
154
|
-
}
|
|
155
|
-
function nodesAt(node, key) {
|
|
156
|
-
const value = node[key];
|
|
157
|
-
return Array.isArray(value) ? value.filter((item) => isNode(item)) : [];
|
|
158
|
-
}
|
|
159
|
-
function stringAt(node, key) {
|
|
160
|
-
const value = node[key];
|
|
161
|
-
return typeof value === "string" ? value : void 0;
|
|
162
|
-
}
|
|
163
|
-
function childrenOf(node) {
|
|
164
|
-
return Object.values(node).flatMap((value) => {
|
|
165
|
-
if (Array.isArray(value)) return value.filter((item) => isNode(item));
|
|
166
|
-
return isNode(value) ? [value] : [];
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
function staticStringOf(node) {
|
|
170
|
-
if (!node) return void 0;
|
|
171
|
-
if (node.type === "Literal") {
|
|
172
|
-
return typeof node.value === "string" ? node.value : void 0;
|
|
173
|
-
}
|
|
174
|
-
if (node.type !== "TemplateLiteral" || nodesAt(node, "expressions").length > 0) return void 0;
|
|
175
|
-
const quasi = nodesAt(node, "quasis")[0];
|
|
176
|
-
const value = quasi?.value;
|
|
177
|
-
if (typeof value !== "object" || value === null) return void 0;
|
|
178
|
-
const cooked = value.cooked;
|
|
179
|
-
return typeof cooked === "string" ? cooked : void 0;
|
|
180
|
-
}
|
|
181
|
-
function exportNameOf(node) {
|
|
182
|
-
if (!node) return void 0;
|
|
183
|
-
return node.type === "Identifier" ? stringAt(node, "name") : staticStringOf(node);
|
|
184
|
-
}
|
|
185
|
-
function propertyNameOf(key, isComputed) {
|
|
186
|
-
if (!key) return void 0;
|
|
187
|
-
if (!isComputed && key.type === "Identifier") return stringAt(key, "name");
|
|
188
|
-
return staticStringOf(key);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
// src/vite-atom-check.ts
|
|
192
|
-
function isBuiltInAtom(name) {
|
|
193
|
-
return Object.hasOwn(atomClassMap, name);
|
|
194
|
-
}
|
|
195
|
-
function hintFor(name) {
|
|
196
|
-
const text = formatDiagnostic({ code: "unknown-atom", name, offset: 0, endOffset: 0 });
|
|
197
|
-
const hint = text.slice(`@nave: unknown atom "${name}". `.length);
|
|
198
|
-
return hint.startsWith("Did you mean") ? hint : void 0;
|
|
199
|
-
}
|
|
200
|
-
function literal(text) {
|
|
201
|
-
return `'${text.replaceAll("\\", "\\\\").replaceAll("'", String.raw`\'`)}'`;
|
|
202
|
-
}
|
|
203
|
-
function whitespaceText(value) {
|
|
204
|
-
const names = value.split(/\s+/).filter(Boolean);
|
|
205
|
-
if (names.length < 2) {
|
|
206
|
-
return `"${value}" has whitespace around the atom name. Write it without: cx(${literal(names[0] ?? "")}).`;
|
|
207
|
-
}
|
|
208
|
-
const count = names.length === 2 ? "two" : String(names.length);
|
|
209
|
-
const call = names.map((name) => literal(name)).join(", ");
|
|
210
|
-
return `"${value}" is ${count} atom names in one string. Pass one per argument: cx(${call}).`;
|
|
211
|
-
}
|
|
212
|
-
function unknownText(name) {
|
|
213
|
-
return `unknown atom "${name}". cx() takes Nave atoms only; for a class of your own, use a CSS Module class or cx.raw(${literal(name)}).`;
|
|
214
|
-
}
|
|
215
|
-
function judgeAtom(value, own) {
|
|
216
|
-
if (/\s/.test(value)) return { kind: "whitespace", text: whitespaceText(value) };
|
|
217
|
-
if (isBuiltInAtom(value)) return { kind: "atom" };
|
|
218
|
-
if (own.has(value)) return { kind: "own" };
|
|
219
|
-
const hint = hintFor(value);
|
|
220
|
-
if (hint) return { kind: "unknown", text: `unknown atom "${value}". ${hint}`, hasHint: true };
|
|
221
|
-
return { kind: "unknown", text: unknownText(value), hasHint: false };
|
|
222
|
-
}
|
|
223
|
-
function availableLine() {
|
|
224
|
-
return `Available: ${Object.keys(atomClassMap).join(", ")}`;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
// src/vite-setup-member.ts
|
|
228
|
-
function setupMemberName(node) {
|
|
229
|
-
if (node.type !== "MemberExpression") return void 0;
|
|
230
|
-
const object = nodeAt(node, "object");
|
|
231
|
-
if (object?.type !== "Identifier" || stringAt(object, "name") !== "$setup") return void 0;
|
|
232
|
-
return propertyNameOf(nodeAt(node, "property"), node.computed === true);
|
|
233
|
-
}
|
|
234
|
-
var FUNCTION_TYPES = /* @__PURE__ */ new Set([
|
|
235
|
-
"ArrowFunctionExpression",
|
|
236
|
-
"FunctionDeclaration",
|
|
237
|
-
"FunctionExpression"
|
|
238
|
-
]);
|
|
239
|
-
function isOutsideFunctions(node, parentOf) {
|
|
240
|
-
for (let current = parentOf.get(node); current; current = parentOf.get(current)) {
|
|
241
|
-
if (FUNCTION_TYPES.has(current.type)) return false;
|
|
242
|
-
}
|
|
243
|
-
return true;
|
|
244
|
-
}
|
|
245
|
-
var SETUP_PARAMETER_POSITIONS = [3, 5];
|
|
246
|
-
function isSetupParameter(analysis, identifier) {
|
|
247
|
-
const binding = analysis.referenceOf(identifier)?.binding;
|
|
248
|
-
const owner = binding?.owner;
|
|
249
|
-
if (!owner || binding.kind !== "param" || binding.name !== "$setup") return false;
|
|
250
|
-
if (!isOutsideFunctions(owner, analysis.parentOf)) return false;
|
|
251
|
-
const params = nodesAt(owner, "params");
|
|
252
|
-
return SETUP_PARAMETER_POSITIONS.some((position) => {
|
|
253
|
-
const parameter = params[position];
|
|
254
|
-
return parameter?.type === "Identifier" && stringAt(parameter, "name") === binding.name;
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
function isSetupMethod(setup, parentOf) {
|
|
258
|
-
const property = setup && parentOf.get(setup);
|
|
259
|
-
if (setup?.type !== "FunctionExpression" || property?.type !== "Property") return false;
|
|
260
|
-
return propertyNameOf(nodeAt(property, "key"), property.computed === true) === "setup";
|
|
261
|
-
}
|
|
262
|
-
function isSetupReturn(declarator, parentOf) {
|
|
263
|
-
if (declarator?.type !== "VariableDeclarator") return false;
|
|
264
|
-
if (stringAt(nodeAt(declarator, "id") ?? declarator, "name") !== "__returned__") return false;
|
|
265
|
-
const declaration = parentOf.get(declarator);
|
|
266
|
-
const block = declaration && parentOf.get(declaration);
|
|
267
|
-
return block?.type === "BlockStatement" && isSetupMethod(parentOf.get(block), parentOf);
|
|
268
|
-
}
|
|
269
|
-
function mergedExposures(linked, own) {
|
|
270
|
-
if (own.size === 0) return linked;
|
|
271
|
-
return new Map([...own, ...linked ?? []]);
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// src/vite-cx-args.ts
|
|
275
|
-
function literalValue(node) {
|
|
276
|
-
const value = node.value;
|
|
277
|
-
if (value === null && node.raw === "null") return [];
|
|
278
|
-
return value === false ? [] : void 0;
|
|
279
|
-
}
|
|
280
|
-
function unaryValue(node) {
|
|
281
|
-
const argument = nodeAt(node, "argument");
|
|
282
|
-
const isNumber = (value) => argument?.type === "Literal" && argument.value === value;
|
|
283
|
-
const isFalse = node.operator === "!" && isNumber(1);
|
|
284
|
-
const isUndefined = node.operator === "void" && isNumber(0);
|
|
285
|
-
return isFalse || isUndefined ? [] : void 0;
|
|
286
|
-
}
|
|
287
|
-
function soleInitialiserBinding(binding) {
|
|
288
|
-
const isPlain = binding && ["const", "let", "var"].includes(binding.kind);
|
|
289
|
-
return isPlain && binding.init && binding.writes === 0 ? binding : void 0;
|
|
290
|
-
}
|
|
291
|
-
function operandOf(node) {
|
|
292
|
-
if (node?.type !== "Literal") return void 0;
|
|
293
|
-
const { value } = node;
|
|
294
|
-
return { isFalsy: !value, isNullish: value === null };
|
|
295
|
-
}
|
|
296
|
-
function setupValue(node, context) {
|
|
297
|
-
const object = nodeAt(node, "object");
|
|
298
|
-
if (!object || !isSetupParameter(context.analysis, object)) return void 0;
|
|
299
|
-
const name = setupMemberName(node);
|
|
300
|
-
const exposure = name === void 0 ? void 0 : context.setup?.get(name);
|
|
301
|
-
if (exposure?.kind !== "values") return void 0;
|
|
302
|
-
return exposure.values.filter((value) => value !== "").map((value) => ({ value, node }));
|
|
303
|
-
}
|
|
304
|
-
var RESOLVED = /* @__PURE__ */ new WeakMap();
|
|
305
|
-
function resolvedFor(analysis, setup) {
|
|
306
|
-
if (setup) return /* @__PURE__ */ new Map();
|
|
307
|
-
const found = RESOLVED.get(analysis) ?? /* @__PURE__ */ new Map();
|
|
308
|
-
RESOLVED.set(analysis, found);
|
|
309
|
-
return found;
|
|
310
|
-
}
|
|
311
|
-
function unionOf(parts) {
|
|
312
|
-
if (parts.includes(void 0)) return void 0;
|
|
313
|
-
const seen = /* @__PURE__ */ new Map();
|
|
314
|
-
const isNew = (possible) => {
|
|
315
|
-
const values = seen.get(possible.node) ?? /* @__PURE__ */ new Set();
|
|
316
|
-
seen.set(possible.node, values);
|
|
317
|
-
const before = values.size;
|
|
318
|
-
values.add(possible.value);
|
|
319
|
-
return values.size > before;
|
|
320
|
-
};
|
|
321
|
-
return parts.flatMap((part) => part.filter((possible) => isNew(possible)));
|
|
322
|
-
}
|
|
323
|
-
var first = (done) => done[0];
|
|
324
|
-
var leaf = (result) => ({ deps: [], combine: () => result });
|
|
325
|
-
function planOfName(node, context) {
|
|
326
|
-
const reference2 = context.analysis.referenceOf(node);
|
|
327
|
-
if (!reference2?.binding) return leaf(stringAt(node, "name") === "undefined" ? [] : void 0);
|
|
328
|
-
const binding = soleInitialiserBinding(reference2.binding);
|
|
329
|
-
if (!binding) return leaf(void 0);
|
|
330
|
-
if (context.resolved.has(binding)) return leaf(context.resolved.get(binding));
|
|
331
|
-
if (context.resolving.has(binding)) return leaf(void 0);
|
|
332
|
-
context.resolving.add(binding);
|
|
333
|
-
return {
|
|
334
|
-
deps: [binding.init],
|
|
335
|
-
combine: first,
|
|
336
|
-
finish(result) {
|
|
337
|
-
context.resolving.delete(binding);
|
|
338
|
-
context.resolved.set(binding, result);
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
function planOfLogical(node) {
|
|
343
|
-
const left = nodeAt(node, "left");
|
|
344
|
-
const right = nodeAt(node, "right");
|
|
345
|
-
const operand = operandOf(left);
|
|
346
|
-
if (node.operator === "&&") {
|
|
347
|
-
return operand?.isFalsy ? leaf([]) : { deps: [right], combine: first };
|
|
348
|
-
}
|
|
349
|
-
const isDecided = node.operator === "||" ? operand?.isFalsy : operand?.isNullish;
|
|
350
|
-
if (isDecided === false) return { deps: [left], combine: first };
|
|
351
|
-
return { deps: [left, right], combine: unionOf };
|
|
352
|
-
}
|
|
353
|
-
function planOf(node, context) {
|
|
354
|
-
const text = staticStringOf(node);
|
|
355
|
-
if (text !== void 0) return leaf(text === "" ? [] : [{ value: text, node }]);
|
|
356
|
-
switch (node.type) {
|
|
357
|
-
case "ConditionalExpression": {
|
|
358
|
-
return {
|
|
359
|
-
deps: [nodeAt(node, "consequent"), nodeAt(node, "alternate")],
|
|
360
|
-
combine: unionOf
|
|
361
|
-
};
|
|
362
|
-
}
|
|
363
|
-
case "Identifier": {
|
|
364
|
-
return planOfName(node, context);
|
|
365
|
-
}
|
|
366
|
-
case "Literal": {
|
|
367
|
-
return leaf(literalValue(node));
|
|
368
|
-
}
|
|
369
|
-
case "LogicalExpression": {
|
|
370
|
-
return planOfLogical(node);
|
|
371
|
-
}
|
|
372
|
-
case "MemberExpression": {
|
|
373
|
-
return leaf(setupValue(node, context));
|
|
374
|
-
}
|
|
375
|
-
case "ParenthesizedExpression": {
|
|
376
|
-
return { deps: [nodeAt(node, "expression")], combine: first };
|
|
377
|
-
}
|
|
378
|
-
case "UnaryExpression": {
|
|
379
|
-
return leaf(unaryValue(node));
|
|
380
|
-
}
|
|
381
|
-
default: {
|
|
382
|
-
return leaf(void 0);
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
function possibles(root, context) {
|
|
387
|
-
if (!root) return void 0;
|
|
388
|
-
const stack = [{ plan: planOf(root, context), done: [] }];
|
|
389
|
-
let result;
|
|
390
|
-
while (stack.length > 0) {
|
|
391
|
-
const top = stack.at(-1);
|
|
392
|
-
const next = top.plan.deps[top.done.length];
|
|
393
|
-
if (top.done.length < top.plan.deps.length) {
|
|
394
|
-
if (next) stack.push({ plan: planOf(next, context), done: [] });
|
|
395
|
-
else top.done.push(void 0);
|
|
396
|
-
continue;
|
|
397
|
-
}
|
|
398
|
-
result = top.plan.combine(top.done);
|
|
399
|
-
top.plan.finish?.(result);
|
|
400
|
-
stack.pop();
|
|
401
|
-
stack.at(-1)?.done.push(result);
|
|
402
|
-
}
|
|
403
|
-
return result;
|
|
404
|
-
}
|
|
405
|
-
function resolveArgument(node, analysis, setup) {
|
|
406
|
-
const resolved = resolvedFor(analysis, setup);
|
|
407
|
-
return possibles(node, { analysis, resolving: /* @__PURE__ */ new Set(), resolved, setup });
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// src/vite-cx-bindings.ts
|
|
411
|
-
function cxBindingsOf(analysis, sources) {
|
|
412
|
-
const found = /* @__PURE__ */ new Map();
|
|
413
|
-
for (const { binding } of analysis.references) {
|
|
414
|
-
if (binding?.kind !== "import" || !binding.source || !sources.has(binding.source)) continue;
|
|
415
|
-
if (binding.imported === "cx") found.set(binding, { binding, isNamespace: false });
|
|
416
|
-
else if (binding.imported === "*") found.set(binding, { binding, isNamespace: true });
|
|
417
|
-
}
|
|
418
|
-
return found;
|
|
419
|
-
}
|
|
420
|
-
function isImportingCx(program, sources) {
|
|
421
|
-
return nodesAt(program, "body").some((node) => {
|
|
422
|
-
const source = staticStringOf(nodeAt(node, "source"));
|
|
423
|
-
return node.type === "ImportDeclaration" && source !== void 0 && sources.has(source);
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
// src/vite-cx-refuse.ts
|
|
428
|
-
function textOf(reading, node) {
|
|
429
|
-
return reading.code.slice(node.start, node.end);
|
|
430
|
-
}
|
|
431
|
-
function calleeName(reading, call) {
|
|
432
|
-
const callee = nodeAt(call, "callee");
|
|
433
|
-
if (!callee) return "a function";
|
|
434
|
-
if (callee.type === "Identifier") return stringAt(callee, "name") ?? "a function";
|
|
435
|
-
const isPlainMember = callee.type === "MemberExpression" && callee.computed !== true;
|
|
436
|
-
const property = isPlainMember ? nodeAt(callee, "property") : void 0;
|
|
437
|
-
return stringAt(property ?? callee, "name") ?? textOf(reading, callee);
|
|
438
|
-
}
|
|
439
|
-
var assignedTo = (reading, parent, local) => {
|
|
440
|
-
const target = nodeAt(parent, "id") ?? nodeAt(parent, "left") ?? parent;
|
|
441
|
-
return `${local} is assigned to ${textOf(reading, target)}`;
|
|
442
|
-
};
|
|
443
|
-
var reexported = (reading, parent, local) => `${textOf(reading, parent)}: a re-export of ${local}, which the build follows only from a module listed in cxModules`;
|
|
444
|
-
var PHRASES = {
|
|
445
|
-
VariableDeclarator: assignedTo,
|
|
446
|
-
AssignmentExpression: assignedTo,
|
|
447
|
-
CallExpression: (reading, parent, local) => `${local} is passed to ${calleeName(reading, parent)}() as a value instead of being called`,
|
|
448
|
-
SpreadElement: (_reading, _parent, local) => `${local} is spread`,
|
|
449
|
-
ExportSpecifier: reexported,
|
|
450
|
-
ExportDefaultDeclaration: reexported
|
|
451
|
-
};
|
|
452
|
-
function phraseFor(reading, expression, local) {
|
|
453
|
-
const parent = reading.analysis.parentOf.get(expression);
|
|
454
|
-
const phrase = parent && PHRASES[parent.type];
|
|
455
|
-
return phrase && parent ? phrase(reading, parent, local) : `${local} is used as a value instead of being called`;
|
|
456
|
-
}
|
|
457
|
-
function isReexportOf(reading, expression) {
|
|
458
|
-
const parent = reading.analysis.parentOf.get(expression);
|
|
459
|
-
return parent?.type === "ExportSpecifier" || parent?.type === "ExportDefaultDeclaration";
|
|
460
|
-
}
|
|
461
|
-
function reexportNameOf(reading, expression) {
|
|
462
|
-
const parent = reading.analysis.parentOf.get(expression);
|
|
463
|
-
if (parent?.type === "ExportDefaultDeclaration") return "default";
|
|
464
|
-
return parent?.type === "ExportSpecifier" ? exportNameOf(nodeAt(parent, "exported")) : void 0;
|
|
465
|
-
}
|
|
466
|
-
function isRenamedReexportOf(reading, expression) {
|
|
467
|
-
const parent = reading.analysis.parentOf.get(expression);
|
|
468
|
-
if (parent?.type === "ExportDefaultDeclaration") return true;
|
|
469
|
-
return parent?.type === "ExportSpecifier" && exportNameOf(nodeAt(parent, "exported")) !== "cx";
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
// src/vite-cx-reference.ts
|
|
473
|
-
function isCallee(parent, node) {
|
|
474
|
-
return parent?.type === "CallExpression" && nodeAt(parent, "callee") === node;
|
|
475
|
-
}
|
|
476
|
-
function isOnlyRaw(pattern) {
|
|
477
|
-
const properties = nodesAt(pattern, "properties");
|
|
478
|
-
const only = properties[0];
|
|
479
|
-
if (properties.length !== 1 || only?.type !== "Property") return false;
|
|
480
|
-
const name = propertyNameOf(nodeAt(only, "key"), only.computed === true);
|
|
481
|
-
return name === "raw" && nodeAt(only, "value")?.type === "Identifier";
|
|
482
|
-
}
|
|
483
|
-
function refused(node, local, phrase) {
|
|
484
|
-
return { kind: "refused", node, local, phrase };
|
|
485
|
-
}
|
|
486
|
-
function rawMemberUse(parent, member, local) {
|
|
487
|
-
const isAlias = parent?.type === "VariableDeclarator" && nodeAt(parent, "init") === member && nodeAt(parent, "id")?.type === "Identifier";
|
|
488
|
-
if (isAlias || isCallee(parent, member)) return { kind: "raw", node: member, local };
|
|
489
|
-
return refused(member, local, `${local}.raw is used other than by calling it`);
|
|
490
|
-
}
|
|
491
|
-
function memberUse(reading, member, local) {
|
|
492
|
-
const parent = reading.analysis.parentOf.get(member);
|
|
493
|
-
const isComputed = member.computed === true;
|
|
494
|
-
const name = propertyNameOf(nodeAt(member, "property"), isComputed);
|
|
495
|
-
if (name === "raw") return rawMemberUse(parent, member, local);
|
|
496
|
-
if (name === "dynamic" && !isComputed) {
|
|
497
|
-
if (parent && isCallee(parent, member)) return { kind: "dynamic", node: parent, local };
|
|
498
|
-
return refused(member, local, `${local}.dynamic is referenced other than by a direct call`);
|
|
499
|
-
}
|
|
500
|
-
if (name === "call" || name === "apply") {
|
|
501
|
-
return refused(member, local, `${local} is called through .${name}()`);
|
|
502
|
-
}
|
|
503
|
-
if (isComputed) return refused(member, local, `${local} is read with a computed member`);
|
|
504
|
-
return refused(member, local, `${local}.${name ?? "?"} is not a member the build reads`);
|
|
505
|
-
}
|
|
506
|
-
function isVueUnref(reading, callee) {
|
|
507
|
-
if (callee?.type !== "Identifier") return false;
|
|
508
|
-
const binding = reading.analysis.referenceOf(callee)?.binding;
|
|
509
|
-
return binding?.kind === "import" && binding.source === "vue" && binding.imported === "unref";
|
|
510
|
-
}
|
|
511
|
-
function throughUnref(reading, expression) {
|
|
512
|
-
let current = expression;
|
|
513
|
-
for (; ; ) {
|
|
514
|
-
const call = reading.analysis.parentOf.get(current);
|
|
515
|
-
const args = call ? nodesAt(call, "arguments") : [];
|
|
516
|
-
const isUnref = call?.type === "CallExpression" && args.length === 1 && args[0] === current && isVueUnref(reading, nodeAt(call, "callee"));
|
|
517
|
-
if (!isUnref) return current;
|
|
518
|
-
current = call;
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
function ancestor(reading, node, levels) {
|
|
522
|
-
let current = node;
|
|
523
|
-
for (let level = 0; current && level < levels; level += 1) {
|
|
524
|
-
current = reading.analysis.parentOf.get(current);
|
|
525
|
-
}
|
|
526
|
-
return current;
|
|
527
|
-
}
|
|
528
|
-
function exposureName(reading, expression) {
|
|
529
|
-
if (reading.allowsExposure !== true) return void 0;
|
|
530
|
-
const getter = ancestor(reading, expression, 4);
|
|
531
|
-
const isGetter = getter?.type === "Property" && getter.kind === "get";
|
|
532
|
-
const isReturn = ancestor(reading, expression, 1)?.type === "ReturnStatement";
|
|
533
|
-
if (!isGetter || !isReturn || !isSetupReturn(ancestor(reading, expression, 6), reading.analysis.parentOf))
|
|
534
|
-
return void 0;
|
|
535
|
-
return propertyNameOf(nodeAt(getter, "key"), getter.computed === true);
|
|
536
|
-
}
|
|
537
|
-
function rawDestructuring(parent, expression, local) {
|
|
538
|
-
if (parent.type !== "VariableDeclarator" || nodeAt(parent, "init") !== expression)
|
|
539
|
-
return void 0;
|
|
540
|
-
const id = nodeAt(parent, "id");
|
|
541
|
-
if (id?.type !== "ObjectPattern" || !isOnlyRaw(id)) return void 0;
|
|
542
|
-
return { kind: "raw", node: id, local };
|
|
543
|
-
}
|
|
544
|
-
function readableUse(reading, expression, local) {
|
|
545
|
-
const parent = reading.analysis.parentOf.get(expression);
|
|
546
|
-
if (!parent) return void 0;
|
|
547
|
-
if (isCallee(parent, expression)) return { kind: "call", node: parent, local };
|
|
548
|
-
if (parent.type === "MemberExpression" && nodeAt(parent, "object") === expression) {
|
|
549
|
-
return memberUse(reading, parent, local);
|
|
550
|
-
}
|
|
551
|
-
return rawDestructuring(parent, expression, local);
|
|
552
|
-
}
|
|
553
|
-
function useOfExpression(reading, start, local) {
|
|
554
|
-
const expression = throughUnref(reading, start);
|
|
555
|
-
const readable = readableUse(reading, expression, local);
|
|
556
|
-
if (readable) return readable;
|
|
557
|
-
const exposedAs = exposureName(reading, expression);
|
|
558
|
-
if (exposedAs !== void 0) return { kind: "exposure", node: expression, local, exposedAs };
|
|
559
|
-
const phrase = phraseFor(reading, expression, local);
|
|
560
|
-
const isReexport = isReexportOf(reading, expression);
|
|
561
|
-
const isRenamed = isReexport && isRenamedReexportOf(reading, expression);
|
|
562
|
-
const exportedAs2 = reexportedAs(reading, expression);
|
|
563
|
-
return {
|
|
564
|
-
...refused(expression, local, phrase),
|
|
565
|
-
isReexport,
|
|
566
|
-
...isRenamed && { isRenamed },
|
|
567
|
-
...exportedAs2
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
function reexportedAs(reading, expression) {
|
|
571
|
-
const name = reexportNameOf(reading, expression);
|
|
572
|
-
return name === void 0 ? void 0 : { exportedAs: [name] };
|
|
573
|
-
}
|
|
574
|
-
function isOtherKey(property) {
|
|
575
|
-
if (property.type !== "Property") return false;
|
|
576
|
-
const name = propertyNameOf(nodeAt(property, "key"), property.computed === true);
|
|
577
|
-
return name !== void 0 && name !== "cx";
|
|
578
|
-
}
|
|
579
|
-
function isPatternAssignment(reading, node) {
|
|
580
|
-
if (node?.type === "AssignmentPattern") return true;
|
|
581
|
-
return node?.type === "AssignmentExpression" && node.operator === "=" && reading.analysis.parentOf.get(node)?.type === "ExpressionStatement";
|
|
582
|
-
}
|
|
583
|
-
function patternDestructuring(reading, expression) {
|
|
584
|
-
const parent = reading.analysis.parentOf.get(expression);
|
|
585
|
-
if (parent?.type === "VariableDeclarator" && nodeAt(parent, "init") === expression) {
|
|
586
|
-
return nodeAt(parent, "id");
|
|
587
|
-
}
|
|
588
|
-
return isPatternAssignment(reading, parent) && nodeAt(parent, "right") === expression ? nodeAt(parent, "left") : void 0;
|
|
589
|
-
}
|
|
590
|
-
function isOtherKeysDestructuring(reading, expression) {
|
|
591
|
-
const pattern = patternDestructuring(reading, expression);
|
|
592
|
-
return pattern?.type === "ObjectPattern" && nodesAt(pattern, "properties").every((p) => isOtherKey(p));
|
|
593
|
-
}
|
|
594
|
-
function memberReadOf(reading, expression) {
|
|
595
|
-
const member = reading.analysis.parentOf.get(expression);
|
|
596
|
-
if (member?.type !== "MemberExpression" || nodeAt(member, "object") !== expression) {
|
|
597
|
-
return void 0;
|
|
598
|
-
}
|
|
599
|
-
return { member, key: propertyNameOf(nodeAt(member, "property"), member.computed === true) };
|
|
600
|
-
}
|
|
601
|
-
function namespaceUse(reading, expression, cx) {
|
|
602
|
-
const local = cx.binding.name;
|
|
603
|
-
const read = memberReadOf(reading, expression);
|
|
604
|
-
if (read?.key === "cx") return useOfExpression(reading, read.member, `${local}.cx`);
|
|
605
|
-
const isListed2 = reading.declaredSources?.has(cx.binding.source ?? "") === true;
|
|
606
|
-
const isOtherExport = read ? read.key !== void 0 : isOtherKeysDestructuring(reading, expression);
|
|
607
|
-
if (isListed2 && isOtherExport) return void 0;
|
|
608
|
-
const use = refused(expression, local, `${local} is used other than as ${local}.cx`);
|
|
609
|
-
const exportedAs2 = reexportedAs(reading, expression);
|
|
610
|
-
return exportedAs2 ? { ...use, ...exportedAs2, isRenamed: true } : use;
|
|
611
|
-
}
|
|
612
|
-
function useOf(reading, reference2, cx) {
|
|
613
|
-
if (cx.isNamespace) return namespaceUse(reading, reference2.node, cx);
|
|
614
|
-
const local = cx.binding.name;
|
|
615
|
-
const use = useOfExpression(reading, reference2.node, local);
|
|
616
|
-
if (!use.isReexport) return use;
|
|
617
|
-
const isDeclaredSource = reading.declaredSources?.has(cx.binding.source ?? "") === true;
|
|
618
|
-
return { ...use, isListable: !isDeclaredSource };
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
// src/vite-cx-source-forms.ts
|
|
622
|
-
var REEXPORT_TEXT = "a re-export of cx, which the build follows only from a module listed in cxModules.";
|
|
623
|
-
var SECOND_HOP_TEXT = "a re-export of the cx of a module listed in cxModules, which the build follows one step only.";
|
|
624
|
-
var DYNAMIC_IMPORT_TEXT = "a dynamic import of cx, which the build cannot follow. Import it at the top of the module.";
|
|
625
|
-
function isExportingCx(node) {
|
|
626
|
-
if (node.type === "ExportAllDeclaration") return true;
|
|
627
|
-
return nodesAt(node, "specifiers").some((specifier) => {
|
|
628
|
-
const local = nodeAt(specifier, "local");
|
|
629
|
-
return (local?.type === "Identifier" ? stringAt(local, "name") : staticStringOf(local)) === "cx";
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
function isExportingRenamed(node) {
|
|
633
|
-
if (node.type === "ExportAllDeclaration") return nodeAt(node, "exported") !== void 0;
|
|
634
|
-
return nodesAt(node, "specifiers").some(
|
|
635
|
-
(specifier) => exportNameOf(nodeAt(specifier, "local")) === "cx" && exportNameOf(nodeAt(specifier, "exported")) !== "cx"
|
|
636
|
-
);
|
|
637
|
-
}
|
|
638
|
-
function exportedNamesOf(node) {
|
|
639
|
-
if (node.type === "ExportAllDeclaration") {
|
|
640
|
-
return [exportNameOf(nodeAt(node, "exported")) ?? "cx"];
|
|
641
|
-
}
|
|
642
|
-
return nodesAt(node, "specifiers").filter((specifier) => exportNameOf(nodeAt(specifier, "local")) === "cx").flatMap((specifier) => exportNameOf(nodeAt(specifier, "exported")) ?? []);
|
|
643
|
-
}
|
|
644
|
-
function reexportProblem(code, node, isListed2) {
|
|
645
|
-
if (isListed2 && !isExportingCx(node)) return void 0;
|
|
646
|
-
return {
|
|
647
|
-
kind: "reexport",
|
|
648
|
-
offset: node.start,
|
|
649
|
-
construct: code.slice(node.start, node.end),
|
|
650
|
-
text: isListed2 ? SECOND_HOP_TEXT : REEXPORT_TEXT,
|
|
651
|
-
isListable: !isListed2,
|
|
652
|
-
...!isListed2 && isExportingRenamed(node) && { isRenamed: true },
|
|
653
|
-
exportedAs: exportedNamesOf(node)
|
|
654
|
-
};
|
|
655
|
-
}
|
|
656
|
-
function sourceFormProblem(code, node, options) {
|
|
657
|
-
const source = staticStringOf(nodeAt(node, "source"));
|
|
658
|
-
if (source === void 0 || !options.cxSources.has(source)) return void 0;
|
|
659
|
-
if (node.type === "ExportNamedDeclaration" || node.type === "ExportAllDeclaration") {
|
|
660
|
-
if (options.isDeclared === true) return void 0;
|
|
661
|
-
return reexportProblem(code, node, options.declaredSources?.has(source) === true);
|
|
662
|
-
}
|
|
663
|
-
if (node.type !== "ImportExpression") return void 0;
|
|
664
|
-
const construct = code.slice(node.start, node.end);
|
|
665
|
-
return { kind: "reference", offset: node.start, construct, text: DYNAMIC_IMPORT_TEXT };
|
|
666
|
-
}
|
|
667
|
-
function sourceFormProblems(code, program, options) {
|
|
668
|
-
const problems = [];
|
|
669
|
-
const stack = [program];
|
|
670
|
-
while (stack.length > 0) {
|
|
671
|
-
const node = stack.pop();
|
|
672
|
-
const problem2 = sourceFormProblem(code, node, options);
|
|
673
|
-
if (problem2) problems.push(problem2);
|
|
674
|
-
stack.push(...childrenOf(node));
|
|
675
|
-
}
|
|
676
|
-
return problems;
|
|
677
|
-
}
|
|
678
|
-
|
|
679
|
-
// src/vite-declared-exports.ts
|
|
680
|
-
var DECLARED_TEXT = "listed in cxModules, but this export can give it a cx the build does not follow: the build follows a listed module one step, to Nave's cx re-exported from @navecss/core/cx under the name cx.";
|
|
681
|
-
function innerPatterns(pattern) {
|
|
682
|
-
switch (pattern.type) {
|
|
683
|
-
case "ArrayPattern": {
|
|
684
|
-
return nodesAt(pattern, "elements");
|
|
685
|
-
}
|
|
686
|
-
case "AssignmentPattern": {
|
|
687
|
-
return [nodeAt(pattern, "left")].filter((inner) => inner !== void 0);
|
|
688
|
-
}
|
|
689
|
-
case "ObjectPattern": {
|
|
690
|
-
return nodesAt(pattern, "properties").flatMap(
|
|
691
|
-
(property) => [nodeAt(property, property.type === "Property" ? "value" : "argument")].filter(
|
|
692
|
-
(inner) => inner !== void 0
|
|
693
|
-
)
|
|
694
|
-
);
|
|
695
|
-
}
|
|
696
|
-
case "RestElement": {
|
|
697
|
-
return [nodeAt(pattern, "argument")].filter((inner) => inner !== void 0);
|
|
698
|
-
}
|
|
699
|
-
default: {
|
|
700
|
-
return [];
|
|
701
|
-
}
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
function patternNames(pattern) {
|
|
705
|
-
const names = [];
|
|
706
|
-
const stack = pattern ? [pattern] : [];
|
|
707
|
-
while (stack.length > 0) {
|
|
708
|
-
const next = stack.pop();
|
|
709
|
-
if (next.type === "Identifier") names.push(stringAt(next, "name") ?? "");
|
|
710
|
-
stack.push(...innerPatterns(next));
|
|
711
|
-
}
|
|
712
|
-
return names;
|
|
713
|
-
}
|
|
714
|
-
function declaredNames(declaration) {
|
|
715
|
-
if (declaration.type !== "VariableDeclaration") {
|
|
716
|
-
return patternNames(nodeAt(declaration, "id"));
|
|
717
|
-
}
|
|
718
|
-
return nodesAt(declaration, "declarations").flatMap(
|
|
719
|
-
(declarator) => patternNames(nodeAt(declarator, "id"))
|
|
720
|
-
);
|
|
721
|
-
}
|
|
722
|
-
function problem(node) {
|
|
723
|
-
return { kind: "declared", offset: node.start, construct: "", text: DECLARED_TEXT };
|
|
724
|
-
}
|
|
725
|
-
function isPlainReExport(local, exported) {
|
|
726
|
-
return local === "cx" && exported === "cx";
|
|
727
|
-
}
|
|
728
|
-
function fromSourceProblems(node, source, input) {
|
|
729
|
-
const isNave = input.cxSources.has(source) && !input.declaredSources.has(source);
|
|
730
|
-
const isListed2 = input.declaredSources.has(source);
|
|
731
|
-
const isBad = nodesAt(node, "specifiers").some((specifier) => {
|
|
732
|
-
const local = exportNameOf(nodeAt(specifier, "local"));
|
|
733
|
-
const exported = exportNameOf(nodeAt(specifier, "exported"));
|
|
734
|
-
if (isNave) return !isPlainReExport(local, exported);
|
|
735
|
-
return exported === "cx" || isListed2 && local === "cx";
|
|
736
|
-
});
|
|
737
|
-
return isBad ? [problem(node)] : [];
|
|
738
|
-
}
|
|
739
|
-
function localProblems(node, input) {
|
|
740
|
-
const isBad = nodesAt(node, "specifiers").some((specifier) => {
|
|
741
|
-
const local = nodeAt(specifier, "local");
|
|
742
|
-
const binding = local && input.analysis.referenceOf(local)?.binding;
|
|
743
|
-
const cx = binding ? input.bindings.get(binding) : void 0;
|
|
744
|
-
if (exportNameOf(nodeAt(specifier, "exported")) !== "cx") return cx !== void 0;
|
|
745
|
-
const isNaves = cx !== void 0 && !cx.isNamespace && !input.declaredSources.has(binding?.source ?? "");
|
|
746
|
-
return !isNaves;
|
|
747
|
-
});
|
|
748
|
-
return isBad ? [problem(node)] : [];
|
|
749
|
-
}
|
|
750
|
-
function namedExportProblems(node, input) {
|
|
751
|
-
const declaration = nodeAt(node, "declaration");
|
|
752
|
-
if (declaration) return declaredNames(declaration).includes("cx") ? [problem(node)] : [];
|
|
753
|
-
const source = staticStringOf(nodeAt(node, "source"));
|
|
754
|
-
return source === void 0 ? localProblems(node, input) : fromSourceProblems(node, source, input);
|
|
755
|
-
}
|
|
756
|
-
function starExportProblems(node, input, hasNaveCx) {
|
|
757
|
-
const source = staticStringOf(nodeAt(node, "source"));
|
|
758
|
-
if (source === void 0) return [];
|
|
759
|
-
const exported = nodeAt(node, "exported");
|
|
760
|
-
if (!input.cxSources.has(source)) {
|
|
761
|
-
return exportNameOf(exported) === "cx" ? [problem(node)] : [];
|
|
762
|
-
}
|
|
763
|
-
if (exported !== void 0) return [problem(node)];
|
|
764
|
-
return !hasNaveCx && input.declaredSources.has(source) ? [problem(node)] : [];
|
|
765
|
-
}
|
|
766
|
-
function isNaveSource(source, input) {
|
|
767
|
-
return source !== void 0 && input.cxSources.has(source) && !input.declaredSources.has(source);
|
|
768
|
-
}
|
|
769
|
-
function isNaveLocalExport(local, exported, input) {
|
|
770
|
-
const binding = local && input.analysis.referenceOf(local)?.binding;
|
|
771
|
-
const cx = binding ? input.bindings.get(binding) : void 0;
|
|
772
|
-
const isListed2 = input.declaredSources.has(binding?.source ?? "");
|
|
773
|
-
return exported === "cx" && cx !== void 0 && !cx.isNamespace && !isListed2;
|
|
774
|
-
}
|
|
775
|
-
function isNaveSpecifier(specifier, source, input) {
|
|
776
|
-
const local = nodeAt(specifier, "local");
|
|
777
|
-
const exported = exportNameOf(nodeAt(specifier, "exported"));
|
|
778
|
-
if (source === void 0) return isNaveLocalExport(local, exported, input);
|
|
779
|
-
return isNaveSource(source, input) && isPlainReExport(exportNameOf(local), exported);
|
|
780
|
-
}
|
|
781
|
-
function isNaveCxExport(node, input) {
|
|
782
|
-
const source = staticStringOf(nodeAt(node, "source"));
|
|
783
|
-
if (node.type === "ExportAllDeclaration") {
|
|
784
|
-
return isNaveSource(source, input) && nodeAt(node, "exported") === void 0;
|
|
785
|
-
}
|
|
786
|
-
if (node.type !== "ExportNamedDeclaration" || nodeAt(node, "declaration")) return false;
|
|
787
|
-
return nodesAt(node, "specifiers").some((specifier) => isNaveSpecifier(specifier, source, input));
|
|
788
|
-
}
|
|
789
|
-
function unfollowedStarProblems(body, input) {
|
|
790
|
-
if (body.some((node) => isNaveCxExport(node, input))) return [];
|
|
791
|
-
const star = body.find((node) => {
|
|
792
|
-
const source = staticStringOf(nodeAt(node, "source"));
|
|
793
|
-
const isPlainStar = node.type === "ExportAllDeclaration" && nodeAt(node, "exported") === void 0;
|
|
794
|
-
return isPlainStar && source !== void 0 && !input.cxSources.has(source);
|
|
795
|
-
});
|
|
796
|
-
return star ? [problem(star)] : [];
|
|
797
|
-
}
|
|
798
|
-
function defaultExportProblems(node, input) {
|
|
799
|
-
const declaration = nodeAt(node, "declaration");
|
|
800
|
-
const binding = declaration && input.analysis.referenceOf(declaration)?.binding;
|
|
801
|
-
return binding && input.bindings.has(binding) ? [problem(node)] : [];
|
|
802
|
-
}
|
|
803
|
-
var EXPORT_PROBLEMS = {
|
|
804
|
-
ExportDefaultDeclaration: defaultExportProblems,
|
|
805
|
-
ExportNamedDeclaration: namedExportProblems
|
|
806
|
-
};
|
|
807
|
-
function declaredExportProblems(input) {
|
|
808
|
-
const body = nodesAt(input.program, "body");
|
|
809
|
-
const hasNaveCx = body.some((node) => isNaveCxExport(node, input));
|
|
810
|
-
const problems = [
|
|
811
|
-
...body.flatMap(
|
|
812
|
-
(node) => node.type === "ExportAllDeclaration" ? starExportProblems(node, input, hasNaveCx) : EXPORT_PROBLEMS[node.type]?.(node, input) ?? []
|
|
813
|
-
),
|
|
814
|
-
...unfollowedStarProblems(body, input)
|
|
815
|
-
];
|
|
816
|
-
return hasNaveCx ? problems.map((found) => ({ ...found, hasNaveCx })) : problems;
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
// src/vite-class-pieces.ts
|
|
820
|
-
function isIdentChar(char) {
|
|
821
|
-
if (char === void 0) return false;
|
|
822
|
-
return /[\w-]/.test(char) || char.codePointAt(0) >= 128;
|
|
823
|
-
}
|
|
824
|
-
function pieceOfText(node, text) {
|
|
825
|
-
let start = text.length;
|
|
826
|
-
while (start > 0 && isIdentChar(text[start - 1])) start -= 1;
|
|
827
|
-
return { node, head: text.slice(start, start + 5), isOpen: start === 0 };
|
|
828
|
-
}
|
|
829
|
-
function leafPiece(node) {
|
|
830
|
-
const whole = staticStringOf(node);
|
|
831
|
-
if (whole !== void 0) return pieceOfText(node, whole);
|
|
832
|
-
if (node.type !== "TemplateLiteral") return void 0;
|
|
833
|
-
const cooked = nodesAt(node, "quasis").at(-1)?.value?.cooked;
|
|
834
|
-
return cooked === void 0 ? void 0 : pieceOfText(node, cooked);
|
|
835
|
-
}
|
|
836
|
-
function isPlus(node) {
|
|
837
|
-
return node?.type === "BinaryExpression" && node.operator === "+";
|
|
838
|
-
}
|
|
839
|
-
function edgePiece(start, memo) {
|
|
840
|
-
const path10 = [];
|
|
841
|
-
let node = start;
|
|
842
|
-
while (isPlus(node) && !memo.edges.has(node)) {
|
|
843
|
-
path10.push(node);
|
|
844
|
-
node = nodeAt(node, "right");
|
|
845
|
-
}
|
|
846
|
-
let found;
|
|
847
|
-
if (node !== void 0) found = memo.edges.has(node) ? memo.edges.get(node) : leafPiece(node);
|
|
848
|
-
for (const visited of path10) memo.edges.set(visited, found);
|
|
849
|
-
return found;
|
|
850
|
-
}
|
|
851
|
-
function joinPieces(before, last) {
|
|
852
|
-
if (!last.isOpen) return { node: before.node, head: last.head, isOpen: false };
|
|
853
|
-
return {
|
|
854
|
-
node: before.node,
|
|
855
|
-
head: (before.head + last.head).slice(0, 5),
|
|
856
|
-
isOpen: before.isOpen
|
|
857
|
-
};
|
|
858
|
-
}
|
|
859
|
-
function pieceOfPlus(link, before, last) {
|
|
860
|
-
if (last === void 0) return void 0;
|
|
861
|
-
const isAdjacent = before !== void 0 && nodeAt(link, "right") === last.node;
|
|
862
|
-
return isAdjacent ? joinPieces(before, last) : last;
|
|
863
|
-
}
|
|
864
|
-
function rightmostPiece(start, memo) {
|
|
865
|
-
const spine = [];
|
|
866
|
-
let node = start;
|
|
867
|
-
while (isPlus(node) && !memo.rightmost.has(node)) {
|
|
868
|
-
spine.push(node);
|
|
869
|
-
node = nodeAt(node, "left");
|
|
870
|
-
}
|
|
871
|
-
let before;
|
|
872
|
-
if (node !== void 0) {
|
|
873
|
-
before = memo.rightmost.has(node) ? memo.rightmost.get(node) : edgePiece(node, memo);
|
|
874
|
-
}
|
|
875
|
-
for (const link of spine.toReversed()) {
|
|
876
|
-
before = pieceOfPlus(link, before, edgePiece(link, memo));
|
|
877
|
-
memo.rightmost.set(link, before);
|
|
878
|
-
}
|
|
879
|
-
return before;
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
// src/vite-string-values.ts
|
|
883
|
-
var none = () => [];
|
|
884
|
-
var leaf2 = (values) => ({ deps: none, combine: () => values });
|
|
885
|
-
function unionOf2(parts) {
|
|
886
|
-
if (parts.includes(void 0)) return void 0;
|
|
887
|
-
return [...new Set(parts.flat())];
|
|
888
|
-
}
|
|
889
|
-
function planOfFallback(node) {
|
|
890
|
-
const left = nodeAt(node, "left");
|
|
891
|
-
const right = nodeAt(node, "right");
|
|
892
|
-
const isOr = node.operator === "||";
|
|
893
|
-
return {
|
|
894
|
-
deps: (done) => {
|
|
895
|
-
if (done.length === 0) return [left];
|
|
896
|
-
const known = done[0];
|
|
897
|
-
return known && isOr && known.includes("") ? [left, right] : [left];
|
|
898
|
-
},
|
|
899
|
-
combine: (done) => {
|
|
900
|
-
const [known, other] = done;
|
|
901
|
-
if (!known || !isOr || !known.includes("")) return known;
|
|
902
|
-
return other && unionOf2([known.filter((value) => value !== ""), other]);
|
|
903
|
-
}
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
function planOfName2(node, analysis) {
|
|
907
|
-
const init = soleInitialiserBinding(analysis.referenceOf(node)?.binding)?.init;
|
|
908
|
-
if (!init) return leaf2(void 0);
|
|
909
|
-
return { deps: () => [init], combine: ([only]) => only };
|
|
910
|
-
}
|
|
911
|
-
function planOf2(node, analysis) {
|
|
912
|
-
const text = staticStringOf(node);
|
|
913
|
-
if (text !== void 0) return leaf2([text]);
|
|
914
|
-
switch (node.type) {
|
|
915
|
-
case "ConditionalExpression": {
|
|
916
|
-
const parts = [nodeAt(node, "consequent"), nodeAt(node, "alternate")];
|
|
917
|
-
return { deps: () => parts, combine: unionOf2 };
|
|
918
|
-
}
|
|
919
|
-
case "Identifier": {
|
|
920
|
-
return planOfName2(node, analysis);
|
|
921
|
-
}
|
|
922
|
-
case "LogicalExpression": {
|
|
923
|
-
return node.operator === "&&" ? leaf2(void 0) : planOfFallback(node);
|
|
924
|
-
}
|
|
925
|
-
case "ParenthesizedExpression": {
|
|
926
|
-
const inner = nodeAt(node, "expression");
|
|
927
|
-
return { deps: () => [inner], combine: ([only]) => only };
|
|
928
|
-
}
|
|
929
|
-
default: {
|
|
930
|
-
return leaf2(void 0);
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
function stringValues(root, analysis) {
|
|
935
|
-
if (!root) return void 0;
|
|
936
|
-
const memo = /* @__PURE__ */ new Map();
|
|
937
|
-
const active = /* @__PURE__ */ new Set([root]);
|
|
938
|
-
const stack = [{ node: root, plan: planOf2(root, analysis), done: [] }];
|
|
939
|
-
let result;
|
|
940
|
-
while (stack.length > 0) {
|
|
941
|
-
const top = stack.at(-1);
|
|
942
|
-
const deps = top.plan.deps(top.done);
|
|
943
|
-
if (top.done.length < deps.length) {
|
|
944
|
-
const child = deps[top.done.length];
|
|
945
|
-
if (!child) top.done.push(void 0);
|
|
946
|
-
else if (memo.has(child)) top.done.push(memo.get(child));
|
|
947
|
-
else if (active.has(child)) top.done.push(void 0);
|
|
948
|
-
else {
|
|
949
|
-
active.add(child);
|
|
950
|
-
stack.push({ node: child, plan: planOf2(child, analysis), done: [] });
|
|
951
|
-
}
|
|
952
|
-
continue;
|
|
953
|
-
}
|
|
954
|
-
result = top.plan.combine(top.done);
|
|
955
|
-
memo.set(top.node, result);
|
|
956
|
-
active.delete(top.node);
|
|
957
|
-
stack.pop();
|
|
958
|
-
stack.at(-1)?.done.push(result);
|
|
959
|
-
}
|
|
960
|
-
return result;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
// src/vite-class-endings.ts
|
|
964
|
-
function isEndingValue(value) {
|
|
965
|
-
return !(isIdentChar(value[0]) || value.startsWith("\\"));
|
|
966
|
-
}
|
|
967
|
-
function operandsOf(element) {
|
|
968
|
-
if (typeof element === "string") return void 0;
|
|
969
|
-
const inner = unwrap(element);
|
|
970
|
-
if (inner.type !== "BinaryExpression" || inner.operator !== "+") return void 0;
|
|
971
|
-
const left = nodeAt(inner, "left");
|
|
972
|
-
const right = nodeAt(inner, "right");
|
|
973
|
-
return left && right ? [left, right] : void 0;
|
|
974
|
-
}
|
|
975
|
-
function* sequenceOf(first2, rest) {
|
|
976
|
-
const pending = first2.toReversed();
|
|
977
|
-
for (; ; ) {
|
|
978
|
-
let element = pending.pop();
|
|
979
|
-
if (element === void 0) return;
|
|
980
|
-
const operands = operandsOf(element);
|
|
981
|
-
if (operands) pending.push(operands[1], operands[0]);
|
|
982
|
-
else yield element;
|
|
983
|
-
}
|
|
984
|
-
}
|
|
985
|
-
function verdictOf(elements, analysis) {
|
|
986
|
-
for (const element of elements) {
|
|
987
|
-
const values = typeof element === "string" ? [element] : stringValues(element, analysis);
|
|
988
|
-
if (!values?.every((value) => value === "" || isEndingValue(value))) return false;
|
|
989
|
-
if (!values.includes("")) return true;
|
|
990
|
-
}
|
|
991
|
-
return void 0;
|
|
992
|
-
}
|
|
993
|
-
function isEndingAfter(start, analysis, memo) {
|
|
994
|
-
const walked = [];
|
|
995
|
-
let link = start;
|
|
996
|
-
let verdict;
|
|
997
|
-
while (verdict === void 0) {
|
|
998
|
-
if (!link) {
|
|
999
|
-
verdict = true;
|
|
1000
|
-
} else if (memo.has(link)) {
|
|
1001
|
-
verdict = memo.get(link);
|
|
1002
|
-
} else {
|
|
1003
|
-
walked.push(link);
|
|
1004
|
-
verdict = verdictOf(sequenceOf([link.node]), analysis);
|
|
1005
|
-
link = link.next;
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
for (const walkedLink of walked) memo.set(walkedLink, verdict);
|
|
1009
|
-
return verdict;
|
|
1010
|
-
}
|
|
1011
|
-
function isEndingTheClass(first2, rest, analysis, memo) {
|
|
1012
|
-
return verdictOf(sequenceOf(first2), analysis) ?? isEndingAfter(rest, analysis, memo);
|
|
1013
|
-
}
|
|
1014
|
-
function unwrap(node) {
|
|
1015
|
-
let current = node;
|
|
1016
|
-
while (current.type === "ParenthesizedExpression")
|
|
1017
|
-
current = nodeAt(current, "expression") ?? current;
|
|
1018
|
-
return current;
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
// src/vite-literal-classes.ts
|
|
1022
|
-
var ATOM_OF_CLASS = new Map(
|
|
1023
|
-
Object.entries(atomClassMap).map(([atom, className]) => [className, atom])
|
|
1024
|
-
);
|
|
1025
|
-
function atomOfClass(className) {
|
|
1026
|
-
return ATOM_OF_CLASS.get(className);
|
|
1027
|
-
}
|
|
1028
|
-
function isBoundary(code, index) {
|
|
1029
|
-
if (index === 0 || !isIdentChar(code[index - 1])) return true;
|
|
1030
|
-
return code[index - 2] === "\\" && /[bfnrtv0]/.test(code[index - 1]);
|
|
1031
|
-
}
|
|
1032
|
-
function identifierAt(code, index) {
|
|
1033
|
-
let end = index;
|
|
1034
|
-
while (isIdentChar(code[end])) end += 1;
|
|
1035
|
-
return code.slice(index, end);
|
|
1036
|
-
}
|
|
1037
|
-
function atomsWrittenIn(code) {
|
|
1038
|
-
const found = /* @__PURE__ */ new Set();
|
|
1039
|
-
let index = code.indexOf("nave-");
|
|
1040
|
-
while (index !== -1) {
|
|
1041
|
-
if (isBoundary(code, index)) {
|
|
1042
|
-
const atom = ATOM_OF_CLASS.get(identifierAt(code, index));
|
|
1043
|
-
if (atom) found.add(atom);
|
|
1044
|
-
}
|
|
1045
|
-
index = code.indexOf("nave-", index + 5);
|
|
1046
|
-
}
|
|
1047
|
-
return found;
|
|
1048
|
-
}
|
|
1049
|
-
function isEndingInNavePrefix(text) {
|
|
1050
|
-
let start = text.length;
|
|
1051
|
-
while (start > 0 && isIdentChar(text[start - 1])) start -= 1;
|
|
1052
|
-
return text.slice(start).startsWith("nave-");
|
|
1053
|
-
}
|
|
1054
|
-
function isBreakingOut(node, analysis, ending) {
|
|
1055
|
-
if (node.type !== "TemplateLiteral") return false;
|
|
1056
|
-
const quasis = nodesAt(node, "quasis");
|
|
1057
|
-
const substitutions = nodesAt(node, "expressions");
|
|
1058
|
-
return quasis.slice(0, -1).some((quasi, index) => {
|
|
1059
|
-
const cooked = quasi.value?.cooked;
|
|
1060
|
-
if (cooked === void 0 || !isEndingInNavePrefix(cooked)) return false;
|
|
1061
|
-
const following = substitutions.slice(index).flatMap((substitution, offset) => {
|
|
1062
|
-
const next = quasis[index + 1 + offset];
|
|
1063
|
-
const text = next?.value?.cooked;
|
|
1064
|
-
return [substitution, ...next ? [text ?? next] : []];
|
|
1065
|
-
});
|
|
1066
|
-
return !isEndingTheClass(following, ending.after, analysis, ending.memo);
|
|
1067
|
-
});
|
|
1068
|
-
}
|
|
1069
|
-
function concatenatedPiece(node, memo, analysis, ending) {
|
|
1070
|
-
if (!isPlus(node)) return void 0;
|
|
1071
|
-
const piece = rightmostPiece(nodeAt(node, "left"), memo);
|
|
1072
|
-
if (piece?.head !== "nave-") return void 0;
|
|
1073
|
-
const right = nodeAt(node, "right");
|
|
1074
|
-
return isEndingTheClass(right ? [right] : [], ending.after, analysis, ending.memo) ? void 0 : piece;
|
|
1075
|
-
}
|
|
1076
|
-
function escapedText(node) {
|
|
1077
|
-
if (node.type === "Literal" && typeof node.value === "string") {
|
|
1078
|
-
return { raw: String(node.raw), decoded: node.value };
|
|
1079
|
-
}
|
|
1080
|
-
if (node.type !== "TemplateElement") return void 0;
|
|
1081
|
-
const { raw, cooked } = node.value;
|
|
1082
|
-
if (!cooked || !raw?.includes("\\")) return void 0;
|
|
1083
|
-
return { raw, decoded: cooked };
|
|
1084
|
-
}
|
|
1085
|
-
function atomsInEscapedStrings(program) {
|
|
1086
|
-
const found = /* @__PURE__ */ new Set();
|
|
1087
|
-
const stack = [program];
|
|
1088
|
-
while (stack.length > 0) {
|
|
1089
|
-
const node = stack.pop();
|
|
1090
|
-
const text = escapedText(node);
|
|
1091
|
-
if (text?.raw.includes("\\")) {
|
|
1092
|
-
for (const atom of atomsWrittenIn(text.decoded)) found.add(atom);
|
|
1093
|
-
}
|
|
1094
|
-
stack.push(...childrenOf(node));
|
|
1095
|
-
}
|
|
1096
|
-
return found;
|
|
1097
|
-
}
|
|
1098
|
-
var SENTENCE = "a Nave class built from pieces is invisible to the build, so its atom would not ship.";
|
|
1099
|
-
function concatenationProblems(program, code, analysis) {
|
|
1100
|
-
const problems = [];
|
|
1101
|
-
const memo = { edges: /* @__PURE__ */ new Map(), rightmost: /* @__PURE__ */ new Map() };
|
|
1102
|
-
const ends = /* @__PURE__ */ new Map();
|
|
1103
|
-
const stack = [{ node: program, after: void 0 }];
|
|
1104
|
-
while (stack.length > 0) {
|
|
1105
|
-
const { node, after } = stack.pop();
|
|
1106
|
-
const offset = concatenatedPiece(node, memo, analysis, { after, memo: ends })?.node.start ?? (isBreakingOut(node, analysis, { after, memo: ends }) ? node.start : -1);
|
|
1107
|
-
if (offset !== -1) {
|
|
1108
|
-
problems.push({
|
|
1109
|
-
kind: "concatenation",
|
|
1110
|
-
offset,
|
|
1111
|
-
construct: code.slice(node.start, node.end),
|
|
1112
|
-
text: SENTENCE
|
|
1113
|
-
});
|
|
1114
|
-
}
|
|
1115
|
-
stack.push(...childrenWithAfter(node, after));
|
|
1116
|
-
}
|
|
1117
|
-
return problems.toSorted((a, b) => a.offset - b.offset);
|
|
1118
|
-
}
|
|
1119
|
-
function childrenWithAfter(node, after) {
|
|
1120
|
-
const isOperands = node.type === "BinaryExpression" && node.operator === "+";
|
|
1121
|
-
if (isOperands) {
|
|
1122
|
-
const left = nodeAt(node, "left");
|
|
1123
|
-
const right = nodeAt(node, "right");
|
|
1124
|
-
return [
|
|
1125
|
-
...left ? [{ node: left, after: right ? { node: right, next: after } : after }] : [],
|
|
1126
|
-
...right ? [{ node: right, after }] : []
|
|
1127
|
-
];
|
|
1128
|
-
}
|
|
1129
|
-
const isWrapper = node.type === "ParenthesizedExpression";
|
|
1130
|
-
return childrenOf(node).map((child) => ({ node: child, after: isWrapper ? after : void 0 }));
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
// src/vite-scope-types.ts
|
|
1134
|
-
function newScope(parent, isFunction) {
|
|
1135
|
-
return { parent, isFunction, bindings: /* @__PURE__ */ new Map() };
|
|
1136
|
-
}
|
|
1137
|
-
function functionScopeOf(scope) {
|
|
1138
|
-
let current = scope;
|
|
1139
|
-
while (!current.isFunction && current.parent) current = current.parent;
|
|
1140
|
-
return current;
|
|
1141
|
-
}
|
|
1142
|
-
function declare(scope, binding, isAssigning = true) {
|
|
1143
|
-
const existing = scope.bindings.get(binding.name);
|
|
1144
|
-
if (existing) {
|
|
1145
|
-
if (isAssigning) existing.writes += 1;
|
|
1146
|
-
return existing;
|
|
1147
|
-
}
|
|
1148
|
-
scope.bindings.set(binding.name, binding);
|
|
1149
|
-
return binding;
|
|
1150
|
-
}
|
|
1151
|
-
function reference(walker, node, scope, isWrite = false) {
|
|
1152
|
-
walker.references.push({ node, scope, isWrite, binding: void 0 });
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
// src/vite-scope-pattern.ts
|
|
1156
|
-
function partsOf(pattern) {
|
|
1157
|
-
return nodesAt(pattern, pattern.type === "ArrayPattern" ? "elements" : "properties");
|
|
1158
|
-
}
|
|
1159
|
-
function targetOf(part) {
|
|
1160
|
-
return part.type === "Property" ? nodeAt(part, "value") : part;
|
|
1161
|
-
}
|
|
1162
|
-
function functionScopeOrHere(spec, scope) {
|
|
1163
|
-
return spec.kind === "var" ? functionScopeOf(scope) : scope;
|
|
1164
|
-
}
|
|
1165
|
-
function declarePattern(pattern, spec, scope, walker) {
|
|
1166
|
-
if (!pattern) return;
|
|
1167
|
-
const name = stringAt(pattern, "name");
|
|
1168
|
-
if (name !== void 0 && pattern.type === "Identifier") {
|
|
1169
|
-
const into = functionScopeOrHere(spec, scope);
|
|
1170
|
-
const isAssigning = spec.kind !== "var" || spec.init !== void 0 || spec.isAssigned === true;
|
|
1171
|
-
const binding = { name, kind: spec.kind, writes: 0 };
|
|
1172
|
-
if (spec.owner) binding.owner = spec.owner;
|
|
1173
|
-
const declared = declare(into, binding, isAssigning);
|
|
1174
|
-
if (spec.init) declared.init = spec.init;
|
|
1175
|
-
return;
|
|
1176
|
-
}
|
|
1177
|
-
DECLARE[pattern.type]?.(pattern, spec, scope, walker);
|
|
1178
|
-
}
|
|
1179
|
-
var DECLARE = {
|
|
1180
|
-
AssignmentPattern: (pattern, spec, scope, walker) => {
|
|
1181
|
-
declarePattern(nodeAt(pattern, "left"), spec, scope, walker);
|
|
1182
|
-
const right = nodeAt(pattern, "right");
|
|
1183
|
-
if (right) walker.parentOf.set(right, pattern);
|
|
1184
|
-
walker.visit(right, scope);
|
|
1185
|
-
},
|
|
1186
|
-
RestElement: (pattern, spec, scope, walker) => {
|
|
1187
|
-
declarePattern(nodeAt(pattern, "argument"), spec, scope, walker);
|
|
1188
|
-
},
|
|
1189
|
-
ArrayPattern: (pattern, spec, scope, walker) => {
|
|
1190
|
-
for (const part of partsOf(pattern)) declarePattern(part, spec, scope, walker);
|
|
1191
|
-
},
|
|
1192
|
-
ObjectPattern: (pattern, spec, scope, walker) => {
|
|
1193
|
-
for (const part of partsOf(pattern)) {
|
|
1194
|
-
if (part.computed === true) walker.visit(nodeAt(part, "key"), scope);
|
|
1195
|
-
declarePattern(targetOf(part), spec, scope, walker);
|
|
1196
|
-
}
|
|
1197
|
-
}
|
|
1198
|
-
};
|
|
1199
|
-
function writeTargets(target, scope, walker) {
|
|
1200
|
-
if (!target) return;
|
|
1201
|
-
if (target.type === "Identifier") {
|
|
1202
|
-
reference(walker, target, scope, true);
|
|
1203
|
-
return;
|
|
1204
|
-
}
|
|
1205
|
-
const write = WRITE[target.type];
|
|
1206
|
-
if (write) write(target, void 0, scope, walker);
|
|
1207
|
-
else walker.visit(target, scope);
|
|
1208
|
-
}
|
|
1209
|
-
var WRITE = {
|
|
1210
|
-
ArrayPattern: (target, _result, scope, walker) => {
|
|
1211
|
-
for (const part of partsOf(target)) writeTargets(part, scope, walker);
|
|
1212
|
-
},
|
|
1213
|
-
ObjectPattern: (target, _result, scope, walker) => {
|
|
1214
|
-
for (const part of partsOf(target)) {
|
|
1215
|
-
if (part.computed === true) walker.visit(nodeAt(part, "key"), scope);
|
|
1216
|
-
writeTargets(targetOf(part), scope, walker);
|
|
1217
|
-
}
|
|
1218
|
-
},
|
|
1219
|
-
AssignmentPattern: (target, _result, scope, walker) => {
|
|
1220
|
-
writeTargets(nodeAt(target, "left"), scope, walker);
|
|
1221
|
-
walker.visit(nodeAt(target, "right"), scope);
|
|
1222
|
-
},
|
|
1223
|
-
RestElement: (target, _result, scope, walker) => {
|
|
1224
|
-
writeTargets(nodeAt(target, "argument"), scope, walker);
|
|
1225
|
-
}
|
|
1226
|
-
};
|
|
1227
|
-
|
|
1228
|
-
// src/vite-scope-walk.ts
|
|
1229
|
-
function visit(node, scope, walker) {
|
|
1230
|
-
if (!node) return;
|
|
1231
|
-
const handler = HANDLERS[node.type];
|
|
1232
|
-
if (handler) handler(node, scope, walker);
|
|
1233
|
-
else visitChildren(node, scope, walker);
|
|
1234
|
-
}
|
|
1235
|
-
function visitChildren(node, scope, walker) {
|
|
1236
|
-
for (const child of childrenOf(node)) {
|
|
1237
|
-
walker.parentOf.set(child, node);
|
|
1238
|
-
visit(child, scope, walker);
|
|
1239
|
-
}
|
|
1240
|
-
}
|
|
1241
|
-
function visitKeys(node, keys, scope, walker) {
|
|
1242
|
-
const children = keys.flatMap((key) => {
|
|
1243
|
-
const value = node[key];
|
|
1244
|
-
return (Array.isArray(value) ? value : [value]).filter((child) => isNode(child));
|
|
1245
|
-
});
|
|
1246
|
-
for (const child of children) {
|
|
1247
|
-
walker.parentOf.set(child, node);
|
|
1248
|
-
visit(child, scope, walker);
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
function expressionKeys(node, others) {
|
|
1252
|
-
return node.computed === true ? ["key", ...others] : [...others];
|
|
1253
|
-
}
|
|
1254
|
-
function visitLoop(node, scope, walker) {
|
|
1255
|
-
const inner = newScope(scope, false);
|
|
1256
|
-
const left = nodeAt(node, "left");
|
|
1257
|
-
if (left?.type === "VariableDeclaration") {
|
|
1258
|
-
const kind = left.kind === "var" ? "var" : "loop";
|
|
1259
|
-
for (const declarator of nodesAt(left, "declarations")) {
|
|
1260
|
-
declarePattern(nodeAt(declarator, "id"), { kind, isAssigned: true }, inner, walker);
|
|
1261
|
-
}
|
|
1262
|
-
} else {
|
|
1263
|
-
writeTargets(left, inner, walker);
|
|
1264
|
-
}
|
|
1265
|
-
visitKeys(node, ["right"], scope, walker);
|
|
1266
|
-
visitKeys(node, ["body"], inner, walker);
|
|
1267
|
-
}
|
|
1268
|
-
function visitFunction(node, scope, walker) {
|
|
1269
|
-
let outer = scope;
|
|
1270
|
-
const id = nodeAt(node, "id");
|
|
1271
|
-
if (id && node.type === "FunctionExpression") {
|
|
1272
|
-
outer = newScope(scope, false);
|
|
1273
|
-
declare(outer, { name: stringAt(id, "name") ?? "", kind: "function", writes: 0 });
|
|
1274
|
-
}
|
|
1275
|
-
const parameters = newScope(outer, true);
|
|
1276
|
-
for (const param of nodesAt(node, "params")) {
|
|
1277
|
-
declarePattern(param, { kind: "param", owner: node }, parameters, walker);
|
|
1278
|
-
}
|
|
1279
|
-
const body = nodeAt(node, "body");
|
|
1280
|
-
if (body?.type === "BlockStatement") {
|
|
1281
|
-
walker.parentOf.set(body, node);
|
|
1282
|
-
visitChildren(body, newScope(parameters, true), walker);
|
|
1283
|
-
} else {
|
|
1284
|
-
visitKeys(node, ["body"], parameters, walker);
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
|
-
function visitClass(node, scope, walker) {
|
|
1288
|
-
const inner = newScope(scope, false);
|
|
1289
|
-
const name = stringAt(nodeAt(node, "id") ?? node, "name");
|
|
1290
|
-
if (name !== void 0) declare(inner, { name, kind: "class", writes: 0 });
|
|
1291
|
-
visitKeys(node, ["superClass", "body"], inner, walker);
|
|
1292
|
-
}
|
|
1293
|
-
function importedName(specifier) {
|
|
1294
|
-
if (specifier.type === "ImportNamespaceSpecifier") return "*";
|
|
1295
|
-
if (specifier.type !== "ImportSpecifier") return "default";
|
|
1296
|
-
const imported = nodeAt(specifier, "imported");
|
|
1297
|
-
return stringAt(imported ?? specifier, "name") ?? String(imported?.value);
|
|
1298
|
-
}
|
|
1299
|
-
function declareImport(node, scope) {
|
|
1300
|
-
const source = String(nodeAt(node, "source")?.value);
|
|
1301
|
-
for (const specifier of nodesAt(node, "specifiers")) {
|
|
1302
|
-
const local = stringAt(nodeAt(specifier, "local") ?? specifier, "name");
|
|
1303
|
-
if (local === void 0) continue;
|
|
1304
|
-
const imported = importedName(specifier);
|
|
1305
|
-
scope.bindings.set(local, { name: local, kind: "import", writes: 0, source, imported });
|
|
1306
|
-
}
|
|
1307
|
-
}
|
|
1308
|
-
function visitDeclaration(node, scope, walker) {
|
|
1309
|
-
const kind = node.kind;
|
|
1310
|
-
for (const declarator of nodesAt(node, "declarations")) {
|
|
1311
|
-
walker.parentOf.set(declarator, node);
|
|
1312
|
-
const id = nodeAt(declarator, "id");
|
|
1313
|
-
const init = nodeAt(declarator, "init");
|
|
1314
|
-
const hasPlainInit = id?.type === "Identifier" && init !== void 0;
|
|
1315
|
-
const spec = hasPlainInit ? { kind, init } : { kind, isAssigned: init !== void 0 };
|
|
1316
|
-
declarePattern(id, spec, scope, walker);
|
|
1317
|
-
if (id) walker.parentOf.set(id, declarator);
|
|
1318
|
-
visit(init, scope, walker);
|
|
1319
|
-
if (init) walker.parentOf.set(init, declarator);
|
|
1320
|
-
}
|
|
1321
|
-
}
|
|
1322
|
-
function visitExport(node, scope, walker) {
|
|
1323
|
-
if (node.source) return;
|
|
1324
|
-
visitKeys(node, ["declaration"], scope, walker);
|
|
1325
|
-
for (const specifier of nodesAt(node, "specifiers")) {
|
|
1326
|
-
const local = nodeAt(specifier, "local");
|
|
1327
|
-
if (!local) continue;
|
|
1328
|
-
walker.parentOf.set(specifier, node);
|
|
1329
|
-
walker.parentOf.set(local, specifier);
|
|
1330
|
-
reference(walker, local, scope);
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
function leaf3() {
|
|
1334
|
-
}
|
|
1335
|
-
function isDirectEval(node) {
|
|
1336
|
-
let callee = nodeAt(node, "callee");
|
|
1337
|
-
while (callee?.type === "ParenthesizedExpression") callee = nodeAt(callee, "expression");
|
|
1338
|
-
return callee?.type === "Identifier" && stringAt(callee, "name") === "eval";
|
|
1339
|
-
}
|
|
1340
|
-
function visitChain(node, scope, walker) {
|
|
1341
|
-
const spine = [];
|
|
1342
|
-
let current = node;
|
|
1343
|
-
while (current?.type === "BinaryExpression" || current?.type === "LogicalExpression") {
|
|
1344
|
-
spine.push(current);
|
|
1345
|
-
current = nodeAt(current, "left");
|
|
1346
|
-
}
|
|
1347
|
-
const links = [...spine, ...current ? [current] : []];
|
|
1348
|
-
for (let index = 1; index < links.length; index += 1) {
|
|
1349
|
-
walker.parentOf.set(links[index], links[index - 1]);
|
|
1350
|
-
}
|
|
1351
|
-
visit(current, scope, walker);
|
|
1352
|
-
for (const link of spine.toReversed()) visitKeys(link, ["right"], scope, walker);
|
|
1353
|
-
}
|
|
1354
|
-
var MEMBER_LIKE = (node, scope, walker) => {
|
|
1355
|
-
visitKeys(node, expressionKeys(node, ["value"]), scope, walker);
|
|
1356
|
-
};
|
|
1357
|
-
var HANDLERS = {
|
|
1358
|
-
Identifier: (node, scope, walker) => {
|
|
1359
|
-
reference(walker, node, scope);
|
|
1360
|
-
},
|
|
1361
|
-
MemberExpression: (node, scope, walker) => {
|
|
1362
|
-
visitKeys(node, node.computed === true ? ["object", "property"] : ["object"], scope, walker);
|
|
1363
|
-
},
|
|
1364
|
-
Property: MEMBER_LIKE,
|
|
1365
|
-
MethodDefinition: MEMBER_LIKE,
|
|
1366
|
-
PropertyDefinition: MEMBER_LIKE,
|
|
1367
|
-
LabeledStatement: (node, scope, walker) => {
|
|
1368
|
-
visitKeys(node, ["body"], scope, walker);
|
|
1369
|
-
},
|
|
1370
|
-
BreakStatement: leaf3,
|
|
1371
|
-
ContinueStatement: leaf3,
|
|
1372
|
-
MetaProperty: leaf3,
|
|
1373
|
-
ExportAllDeclaration: leaf3,
|
|
1374
|
-
CallExpression: (node, scope, walker) => {
|
|
1375
|
-
if (isDirectEval(node)) walker.evalScopes.push(scope);
|
|
1376
|
-
visitChildren(node, scope, walker);
|
|
1377
|
-
},
|
|
1378
|
-
BinaryExpression: visitChain,
|
|
1379
|
-
LogicalExpression: visitChain,
|
|
1380
|
-
AssignmentExpression: (node, scope, walker) => {
|
|
1381
|
-
writeTargets(nodeAt(node, "left"), scope, walker);
|
|
1382
|
-
visitKeys(node, ["right"], scope, walker);
|
|
1383
|
-
},
|
|
1384
|
-
UpdateExpression: (node, scope, walker) => {
|
|
1385
|
-
writeTargets(nodeAt(node, "argument"), scope, walker);
|
|
1386
|
-
},
|
|
1387
|
-
ImportDeclaration: (node, scope) => {
|
|
1388
|
-
declareImport(node, scope);
|
|
1389
|
-
},
|
|
1390
|
-
ExportNamedDeclaration: visitExport,
|
|
1391
|
-
VariableDeclaration: visitDeclaration,
|
|
1392
|
-
FunctionDeclaration: (node, scope, walker) => {
|
|
1393
|
-
const name = stringAt(nodeAt(node, "id") ?? node, "name");
|
|
1394
|
-
if (name !== void 0) declare(scope, { name, kind: "function", writes: 0 });
|
|
1395
|
-
visitFunction(node, scope, walker);
|
|
1396
|
-
},
|
|
1397
|
-
FunctionExpression: visitFunction,
|
|
1398
|
-
ArrowFunctionExpression: visitFunction,
|
|
1399
|
-
ClassDeclaration: (node, scope, walker) => {
|
|
1400
|
-
const name = stringAt(nodeAt(node, "id") ?? node, "name");
|
|
1401
|
-
if (name !== void 0) declare(scope, { name, kind: "class", writes: 0 });
|
|
1402
|
-
visitClass(node, scope, walker);
|
|
1403
|
-
},
|
|
1404
|
-
ClassExpression: visitClass,
|
|
1405
|
-
StaticBlock: (node, scope, walker) => {
|
|
1406
|
-
visitChildren(node, newScope(scope, true), walker);
|
|
1407
|
-
},
|
|
1408
|
-
BlockStatement: (node, scope, walker) => {
|
|
1409
|
-
visitChildren(node, newScope(scope, false), walker);
|
|
1410
|
-
},
|
|
1411
|
-
SwitchStatement: (node, scope, walker) => {
|
|
1412
|
-
visitKeys(node, ["discriminant"], scope, walker);
|
|
1413
|
-
visitKeys(node, ["cases"], newScope(scope, false), walker);
|
|
1414
|
-
},
|
|
1415
|
-
CatchClause: (node, scope, walker) => {
|
|
1416
|
-
const inner = newScope(scope, false);
|
|
1417
|
-
declarePattern(nodeAt(node, "param"), { kind: "catch" }, inner, walker);
|
|
1418
|
-
visitKeys(node, ["body"], inner, walker);
|
|
1419
|
-
},
|
|
1420
|
-
ForStatement: (node, scope, walker) => {
|
|
1421
|
-
visitChildren(node, newScope(scope, false), walker);
|
|
1422
|
-
},
|
|
1423
|
-
ForInStatement: visitLoop,
|
|
1424
|
-
ForOfStatement: visitLoop
|
|
1425
|
-
};
|
|
1426
|
-
|
|
1427
|
-
// src/vite-scope.ts
|
|
1428
|
-
function lookup(scope, name) {
|
|
1429
|
-
for (let current = scope; current; current = current.parent) {
|
|
1430
|
-
const found = current.bindings.get(name);
|
|
1431
|
-
if (found) return found;
|
|
1432
|
-
}
|
|
1433
|
-
return void 0;
|
|
1434
|
-
}
|
|
1435
|
-
function resolve(reference2) {
|
|
1436
|
-
const name = stringAt(reference2.node, "name");
|
|
1437
|
-
reference2.binding = name === void 0 ? void 0 : lookup(reference2.scope, name);
|
|
1438
|
-
if (reference2.binding && reference2.isWrite) reference2.binding.writes += 1;
|
|
1439
|
-
}
|
|
1440
|
-
var ASSIGNABLE = /* @__PURE__ */ new Set([
|
|
1441
|
-
"catch",
|
|
1442
|
-
"class",
|
|
1443
|
-
"function",
|
|
1444
|
-
"let",
|
|
1445
|
-
"loop",
|
|
1446
|
-
"param",
|
|
1447
|
-
"var"
|
|
1448
|
-
]);
|
|
1449
|
-
function assignable(scope) {
|
|
1450
|
-
return scope.bindings.values().filter((binding) => ASSIGNABLE.has(binding.kind)).toArray();
|
|
1451
|
-
}
|
|
1452
|
-
function markEvalWrites(scopes) {
|
|
1453
|
-
const marked = /* @__PURE__ */ new Set();
|
|
1454
|
-
for (const start of scopes) {
|
|
1455
|
-
for (let scope = start; scope && !marked.has(scope); scope = scope.parent) {
|
|
1456
|
-
marked.add(scope);
|
|
1457
|
-
for (const binding of assignable(scope)) binding.writes += 1;
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1460
|
-
}
|
|
1461
|
-
function analyze(program) {
|
|
1462
|
-
const walker = {
|
|
1463
|
-
references: [],
|
|
1464
|
-
parentOf: /* @__PURE__ */ new Map(),
|
|
1465
|
-
evalScopes: [],
|
|
1466
|
-
visit: (node, scope) => {
|
|
1467
|
-
visit(node, scope, walker);
|
|
1468
|
-
}
|
|
1469
|
-
};
|
|
1470
|
-
const module = newScope(void 0, true);
|
|
1471
|
-
for (const statement of nodesAt(program, "body")) {
|
|
1472
|
-
walker.parentOf.set(statement, program);
|
|
1473
|
-
visit(statement, module, walker);
|
|
1474
|
-
}
|
|
1475
|
-
const byNode = /* @__PURE__ */ new Map();
|
|
1476
|
-
for (const reference2 of walker.references) {
|
|
1477
|
-
resolve(reference2);
|
|
1478
|
-
byNode.set(reference2.node, reference2);
|
|
1479
|
-
}
|
|
1480
|
-
markEvalWrites(walker.evalScopes.filter((scope) => !lookup(scope, "eval")));
|
|
1481
|
-
return {
|
|
1482
|
-
references: walker.references,
|
|
1483
|
-
parentOf: walker.parentOf,
|
|
1484
|
-
referenceOf: (node) => byNode.get(node)
|
|
1485
|
-
};
|
|
1486
|
-
}
|
|
1487
|
-
|
|
1488
|
-
// src/vite-vue-setup.ts
|
|
1489
|
-
function returnedObject(analysis) {
|
|
1490
|
-
for (const [node] of analysis.parentOf) {
|
|
1491
|
-
if (!isSetupReturn(node, analysis.parentOf)) continue;
|
|
1492
|
-
const init = nodeAt(node, "init");
|
|
1493
|
-
if (init?.type === "ObjectExpression") return init;
|
|
1494
|
-
}
|
|
1495
|
-
return void 0;
|
|
1496
|
-
}
|
|
1497
|
-
function stringExposures(analysis) {
|
|
1498
|
-
const exposures = /* @__PURE__ */ new Map();
|
|
1499
|
-
const object = returnedObject(analysis);
|
|
1500
|
-
const properties = object ? nodesAt(object, "properties") : [];
|
|
1501
|
-
for (const property of properties) {
|
|
1502
|
-
const value = nodeAt(property, "value");
|
|
1503
|
-
const name = propertyNameOf(nodeAt(property, "key"), property.computed === true);
|
|
1504
|
-
if (name === void 0 || value?.type !== "Identifier" || property.kind === "get") continue;
|
|
1505
|
-
const possibles2 = resolveArgument(value, analysis);
|
|
1506
|
-
if (possibles2) exposures.set(name, { kind: "values", values: possibles2.map((p) => p.value) });
|
|
1507
|
-
}
|
|
1508
|
-
return exposures;
|
|
1509
|
-
}
|
|
1510
|
-
function cxReadsOnSetup(analysis, exposures) {
|
|
1511
|
-
const reads = [];
|
|
1512
|
-
for (const reference2 of analysis.references) {
|
|
1513
|
-
if (!isSetupParameter(analysis, reference2.node)) continue;
|
|
1514
|
-
const member = analysis.parentOf.get(reference2.node);
|
|
1515
|
-
const name = member && setupMemberName(member);
|
|
1516
|
-
if (member && name !== void 0 && exposures.get(name)?.kind === "cx") reads.push(member);
|
|
1517
|
-
}
|
|
1518
|
-
return reads;
|
|
1519
|
-
}
|
|
1520
|
-
|
|
1521
|
-
// src/vite-collect.ts
|
|
1522
|
-
var CX_SOURCE = "@navecss/core/cx";
|
|
1523
|
-
function report(reading, problem2) {
|
|
1524
|
-
const key = `${problem2.kind}:${problem2.offset}`;
|
|
1525
|
-
if (reading.seen.has(key)) return;
|
|
1526
|
-
reading.seen.add(key);
|
|
1527
|
-
reading.result.problems.push(problem2);
|
|
1528
|
-
}
|
|
1529
|
-
var COMPILER_PREFIX = /\$setup\.|\$\$props\./g;
|
|
1530
|
-
function quoteCall(reading, use, args, callee = use.local) {
|
|
1531
|
-
const first2 = args[0];
|
|
1532
|
-
const last = args.at(-1);
|
|
1533
|
-
const inner = first2 && last ? reading.code.slice(first2.start, last.end) : "";
|
|
1534
|
-
return `${callee}(${inner.replaceAll(COMPILER_PREFIX, "")})`;
|
|
1535
|
-
}
|
|
1536
|
-
function judgeString(reading, use, value, node) {
|
|
1537
|
-
const verdict = judgeAtom(value, reading.options.ownAtoms);
|
|
1538
|
-
switch (verdict.kind) {
|
|
1539
|
-
case "atom": {
|
|
1540
|
-
reading.result.atoms.add(value);
|
|
1541
|
-
break;
|
|
1542
|
-
}
|
|
1543
|
-
case "own": {
|
|
1544
|
-
report(reading, {
|
|
1545
|
-
kind: "own",
|
|
1546
|
-
offset: node.start,
|
|
1547
|
-
construct: `${use.local}()`,
|
|
1548
|
-
text: `"${value}" is an atom of your own, which has no class. Use @nave ${value} in a CSS rule instead.`
|
|
1549
|
-
});
|
|
1550
|
-
break;
|
|
1551
|
-
}
|
|
1552
|
-
case "whitespace": {
|
|
1553
|
-
report(reading, {
|
|
1554
|
-
kind: "argument",
|
|
1555
|
-
offset: node.start,
|
|
1556
|
-
construct: `${use.local}()`,
|
|
1557
|
-
text: verdict.text
|
|
1558
|
-
});
|
|
1559
|
-
break;
|
|
1560
|
-
}
|
|
1561
|
-
default: {
|
|
1562
|
-
report(reading, {
|
|
1563
|
-
kind: "unknown",
|
|
1564
|
-
offset: node.start,
|
|
1565
|
-
construct: `${use.local}()`,
|
|
1566
|
-
text: verdict.text,
|
|
1567
|
-
needsAvailable: !verdict.hasHint
|
|
1568
|
-
});
|
|
1569
|
-
}
|
|
1570
|
-
}
|
|
1571
|
-
}
|
|
1572
|
-
function readCall(reading, use, analysis) {
|
|
1573
|
-
const args = nodesAt(use.node, "arguments");
|
|
1574
|
-
for (const arg of args) {
|
|
1575
|
-
if (arg.type === "SpreadElement") {
|
|
1576
|
-
report(reading, {
|
|
1577
|
-
kind: "argument",
|
|
1578
|
-
offset: arg.start,
|
|
1579
|
-
construct: quoteCall(reading, use, args),
|
|
1580
|
-
text: "a spread argument."
|
|
1581
|
-
});
|
|
1582
|
-
continue;
|
|
1583
|
-
}
|
|
1584
|
-
const possibles2 = resolveArgument(arg, analysis, reading.options.setup);
|
|
1585
|
-
if (!possibles2) {
|
|
1586
|
-
report(reading, {
|
|
1587
|
-
kind: "argument",
|
|
1588
|
-
offset: arg.start,
|
|
1589
|
-
construct: quoteCall(reading, use, args),
|
|
1590
|
-
text: "the argument is not a literal atom name."
|
|
1591
|
-
});
|
|
1592
|
-
continue;
|
|
1593
|
-
}
|
|
1594
|
-
for (const { value, node } of possibles2) judgeString(reading, use, value, node);
|
|
1595
|
-
}
|
|
1596
|
-
}
|
|
1597
|
-
function refusedProblem(reading, use) {
|
|
1598
|
-
if (use.isReexport && reading.options.isDeclared === true) return void 0;
|
|
1599
|
-
return {
|
|
1600
|
-
kind: use.isReexport ? "reexport" : "reference",
|
|
1601
|
-
offset: use.node.start,
|
|
1602
|
-
construct: "",
|
|
1603
|
-
text: `${use.phrase ?? ""}.`,
|
|
1604
|
-
...use.isReexport && { isListable: use.isListable },
|
|
1605
|
-
...use.isRenamed === true && { isRenamed: true },
|
|
1606
|
-
...use.exportedAs && { exportedAs: use.exportedAs }
|
|
1607
|
-
};
|
|
1608
|
-
}
|
|
1609
|
-
function readUse(reading, use, analysis) {
|
|
1610
|
-
switch (use.kind) {
|
|
1611
|
-
case "call": {
|
|
1612
|
-
readCall(reading, use, analysis);
|
|
1613
|
-
break;
|
|
1614
|
-
}
|
|
1615
|
-
case "dynamic": {
|
|
1616
|
-
const args = nodesAt(use.node, "arguments");
|
|
1617
|
-
const construct = quoteCall(reading, use, args, `${use.local}.dynamic`);
|
|
1618
|
-
reading.result.dynamicCalls.push({ offset: use.node.start, construct });
|
|
1619
|
-
break;
|
|
1620
|
-
}
|
|
1621
|
-
case "exposure": {
|
|
1622
|
-
reading.result.exposes.set(use.exposedAs ?? use.local, { kind: "cx" });
|
|
1623
|
-
break;
|
|
1624
|
-
}
|
|
1625
|
-
case "refused": {
|
|
1626
|
-
const problem2 = refusedProblem(reading, use);
|
|
1627
|
-
if (problem2) report(reading, problem2);
|
|
1628
|
-
break;
|
|
1629
|
-
}
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
function readUses(reading, program) {
|
|
1633
|
-
const { code, options, result } = reading;
|
|
1634
|
-
const analysis = analyze(program);
|
|
1635
|
-
const bindings = cxBindingsOf(analysis, options.cxSources);
|
|
1636
|
-
const frame2 = {
|
|
1637
|
-
analysis,
|
|
1638
|
-
code,
|
|
1639
|
-
allowsExposure: options.isVueScript === true,
|
|
1640
|
-
declaredSources: options.declaredSources
|
|
1641
|
-
};
|
|
1642
|
-
for (const reference2 of analysis.references) {
|
|
1643
|
-
const cx = reference2.binding && bindings.get(reference2.binding);
|
|
1644
|
-
const use = cx && useOf(frame2, reference2, cx);
|
|
1645
|
-
if (use) readUse(reading, use, analysis);
|
|
1646
|
-
}
|
|
1647
|
-
for (const [name, exposure] of stringExposures(analysis)) result.exposes.set(name, exposure);
|
|
1648
|
-
const setup = mergedExposures(options.setup, result.exposes);
|
|
1649
|
-
const members = setup ? cxReadsOnSetup(analysis, setup) : [];
|
|
1650
|
-
const withSetup = { ...reading, options: { ...options, setup } };
|
|
1651
|
-
for (const member of members) {
|
|
1652
|
-
readUse(withSetup, useOfExpression(frame2, member, setupMemberName(member) ?? "cx"), analysis);
|
|
1653
|
-
}
|
|
1654
|
-
return { analysis, bindings };
|
|
1655
|
-
}
|
|
1656
|
-
function readModule(code, program, options) {
|
|
1657
|
-
const result = {
|
|
1658
|
-
atoms: /* @__PURE__ */ new Set(),
|
|
1659
|
-
classes: /* @__PURE__ */ new Set(),
|
|
1660
|
-
problems: [],
|
|
1661
|
-
dynamicCalls: [],
|
|
1662
|
-
exposes: /* @__PURE__ */ new Map(),
|
|
1663
|
-
usesCx: isImportingCx(program, options.cxSources)
|
|
1664
|
-
};
|
|
1665
|
-
const reading = { code, options, result, seen: /* @__PURE__ */ new Set() };
|
|
1666
|
-
const { analysis, bindings } = readUses(reading, program);
|
|
1667
|
-
const listed = options.isDeclared === true ? declaredExportProblems({
|
|
1668
|
-
program,
|
|
1669
|
-
analysis,
|
|
1670
|
-
bindings,
|
|
1671
|
-
cxSources: options.cxSources,
|
|
1672
|
-
declaredSources: options.declaredSources ?? /* @__PURE__ */ new Set()
|
|
1673
|
-
}) : [];
|
|
1674
|
-
for (const problem2 of [...sourceFormProblems(code, program, options), ...listed]) {
|
|
1675
|
-
report(reading, problem2);
|
|
1676
|
-
}
|
|
1677
|
-
for (const atom of atomsWrittenIn(code)) result.classes.add(atom);
|
|
1678
|
-
for (const atom of atomsInEscapedStrings(program)) result.classes.add(atom);
|
|
1679
|
-
if (result.usesCx || !options.isDependency) {
|
|
1680
|
-
for (const problem2 of concatenationProblems(program, code, analysis)) report(reading, problem2);
|
|
1681
|
-
}
|
|
1682
|
-
return result;
|
|
1683
|
-
}
|
|
1684
|
-
|
|
1685
150
|
// src/vite-css-id.ts
|
|
1686
151
|
var STYLESHEET = /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/;
|
|
1687
152
|
var SPECIAL_QUERY = /[?&](?:worker|sharedworker|raw|url)\b/;
|
|
@@ -1716,8 +181,8 @@ function textTestOf(names) {
|
|
|
1716
181
|
|
|
1717
182
|
// src/vite-cx-modules.ts
|
|
1718
183
|
function isRelative(text) {
|
|
1719
|
-
const
|
|
1720
|
-
const path10 =
|
|
184
|
+
const cut = text.search(/[#?]/);
|
|
185
|
+
const path10 = cut === -1 ? text : text.slice(0, cut);
|
|
1721
186
|
return path10 === "." || path10 === ".." || path10.startsWith("./") || path10.startsWith("../");
|
|
1722
187
|
}
|
|
1723
188
|
function fileOf(id) {
|
|
@@ -1783,8 +248,8 @@ function withoutTrailingSlashes(text) {
|
|
|
1783
248
|
return text.slice(0, end);
|
|
1784
249
|
}
|
|
1785
250
|
function lastSegmentOf(specifier) {
|
|
1786
|
-
const
|
|
1787
|
-
const bare = withoutTrailingSlashes(
|
|
251
|
+
const cut = specifier.slice(1).search(/[#?]/);
|
|
252
|
+
const bare = withoutTrailingSlashes(cut === -1 ? specifier : specifier.slice(0, cut + 1));
|
|
1788
253
|
const segment = bare.slice(bare.lastIndexOf("/") + 1);
|
|
1789
254
|
return segment === "." || segment === ".." ? "index" : segment;
|
|
1790
255
|
}
|
|
@@ -1850,32 +315,6 @@ function moduleLabel(root, id) {
|
|
|
1850
315
|
return path2.relative(root, file).replaceAll("\\", "/");
|
|
1851
316
|
}
|
|
1852
317
|
|
|
1853
|
-
// src/vite-problems.ts
|
|
1854
|
-
var PROBLEM_KINDS = [
|
|
1855
|
-
"argument",
|
|
1856
|
-
"reference",
|
|
1857
|
-
"reexport",
|
|
1858
|
-
"declared",
|
|
1859
|
-
"concatenation",
|
|
1860
|
-
"dynamic",
|
|
1861
|
-
"unknown",
|
|
1862
|
-
"own",
|
|
1863
|
-
"unreadable"
|
|
1864
|
-
];
|
|
1865
|
-
function compareText(a, b) {
|
|
1866
|
-
if (a === b) return 0;
|
|
1867
|
-
return a < b ? -1 : 1;
|
|
1868
|
-
}
|
|
1869
|
-
function cxModulesArray(configured, added) {
|
|
1870
|
-
const extra = [...new Set(added)].filter((entry) => !configured.includes(entry)).toSorted(compareText);
|
|
1871
|
-
if (extra.length === 0) return void 0;
|
|
1872
|
-
return `[${[...configured, ...extra].map((entry) => `'${entry}'`).join(", ")}]`;
|
|
1873
|
-
}
|
|
1874
|
-
function cut(text, limit = 40) {
|
|
1875
|
-
const oneLine = text.replaceAll(/\s+/g, " ");
|
|
1876
|
-
return oneLine.length > limit ? `${oneLine.slice(0, limit)}...` : oneLine;
|
|
1877
|
-
}
|
|
1878
|
-
|
|
1879
318
|
// src/vite-cx-importers.ts
|
|
1880
319
|
function importerIdsOf(ctx, cxId) {
|
|
1881
320
|
const info = ctx.getModuleInfo?.(cxId);
|
|
@@ -1901,7 +340,7 @@ function specifiersIn(program) {
|
|
|
1901
340
|
if (where !== void 0 && source !== void 0) {
|
|
1902
341
|
found.set(source, Math.min(found.get(source) ?? Infinity, where.start));
|
|
1903
342
|
}
|
|
1904
|
-
stack
|
|
343
|
+
pushAll(stack, childrenOf(node));
|
|
1905
344
|
}
|
|
1906
345
|
return [...found].toSorted(([, a], [, b]) => a - b).map(([source]) => source);
|
|
1907
346
|
}
|
|
@@ -1988,26 +427,91 @@ async function declaredReadingOf(context, resolver, declared, input) {
|
|
|
1988
427
|
);
|
|
1989
428
|
}
|
|
1990
429
|
return {
|
|
1991
|
-
declaredSources,
|
|
1992
|
-
isDeclared: isListedFile(declared, module.id),
|
|
1993
|
-
onlyVia: isOnlyListed && files.size > 0 ? files : void 0
|
|
430
|
+
declaredSources,
|
|
431
|
+
isDeclared: isListedFile(declared, module.id),
|
|
432
|
+
onlyVia: isOnlyListed && files.size > 0 ? files : void 0
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
async function listedFileFrom(resolver, declared, source, importer) {
|
|
436
|
+
const resolved = await resolveOrNull(resolver, source, importer);
|
|
437
|
+
const file = resolved ? fileOf(resolved.id) : void 0;
|
|
438
|
+
return file !== void 0 && declared.files.has(file) ? file : void 0;
|
|
439
|
+
}
|
|
440
|
+
async function listedFileOf(resolver, declared, source, importer) {
|
|
441
|
+
if (declared.entries.has(source)) {
|
|
442
|
+
const id = source.startsWith("#") ? void 0 : declared.ids.get(source);
|
|
443
|
+
if (id !== void 0) return { file: fileOf(id) };
|
|
444
|
+
const file2 = await listedFileFrom(resolver, declared, source, importer);
|
|
445
|
+
return file2 === void 0 && source.startsWith("#") ? void 0 : { file: file2 };
|
|
446
|
+
}
|
|
447
|
+
if (!isNamingListed(source, declared)) return void 0;
|
|
448
|
+
const file = await listedFileFrom(resolver, declared, source, importer);
|
|
449
|
+
return file === void 0 ? void 0 : { file };
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// src/vite-dev-keep.ts
|
|
453
|
+
var KEEP_CONSTANT = "__NAVE_KEEP_CLASSES__";
|
|
454
|
+
function keepMap(kept) {
|
|
455
|
+
return Object.fromEntries(
|
|
456
|
+
kept.filter((atom) => Object.hasOwn(atomClassMap, atom)).map((atom) => [atom, atomClassMap[atom]])
|
|
457
|
+
);
|
|
458
|
+
}
|
|
459
|
+
function devKeepMap(map, atoms) {
|
|
460
|
+
return new Proxy(map, {
|
|
461
|
+
getOwnPropertyDescriptor(target, key) {
|
|
462
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(target, key);
|
|
463
|
+
if (descriptor === void 0 && typeof key === "string") {
|
|
464
|
+
const quoted2 = JSON.stringify(key);
|
|
465
|
+
console.error(
|
|
466
|
+
atoms.includes(key) ? `[nave] cx.dynamic(${quoted2}) applied no class: ${quoted2} is not in keep or in a keepFor list, and navePlugin() gives cx.dynamic() only the atoms in those lists, in a build as in dev. Add ${quoted2} to keep in navePlugin(), or, when a dependency makes the call, to its list in keepFor.` : `[nave] cx.dynamic(${quoted2}) applied no class: ${quoted2} is not a Nave atom.`
|
|
467
|
+
);
|
|
468
|
+
}
|
|
469
|
+
return descriptor;
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
function devKeepExpression(map, atoms) {
|
|
474
|
+
return `(${devKeepMap.toString()})(${JSON.stringify(map)}, ${JSON.stringify(atoms)})`;
|
|
475
|
+
}
|
|
476
|
+
var installs = [];
|
|
477
|
+
var baseline = { held: false, value: void 0 };
|
|
478
|
+
function publish() {
|
|
479
|
+
const newest = installs.at(-1);
|
|
480
|
+
if (newest !== void 0) Object.assign(globalThis, { [KEEP_CONSTANT]: newest.map });
|
|
481
|
+
else if (baseline.held) Object.assign(globalThis, { [KEEP_CONSTANT]: baseline.value });
|
|
482
|
+
else Reflect.deleteProperty(globalThis, KEEP_CONSTANT);
|
|
483
|
+
}
|
|
484
|
+
function installServerKeepMap(context, owner) {
|
|
485
|
+
if (context.options.atomic !== "used") return;
|
|
486
|
+
const map = devKeepMap(keepMap(context.kept), Object.keys(atomClassMap));
|
|
487
|
+
if (installs.length === 0) {
|
|
488
|
+
baseline.held = Object.hasOwn(globalThis, KEEP_CONSTANT);
|
|
489
|
+
baseline.value = globalThis[KEEP_CONSTANT];
|
|
490
|
+
}
|
|
491
|
+
installs.push({ owner, map });
|
|
492
|
+
publish();
|
|
493
|
+
}
|
|
494
|
+
function removeServerKeepMap(owner) {
|
|
495
|
+
const index = installs.findIndex((install) => install.owner === owner);
|
|
496
|
+
if (index === -1) return;
|
|
497
|
+
installs.splice(index, 1);
|
|
498
|
+
publish();
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// src/vite-dev-reloads.ts
|
|
502
|
+
function freshReloads() {
|
|
503
|
+
return {
|
|
504
|
+
stale: /* @__PURE__ */ new Set(),
|
|
505
|
+
reloading: /* @__PURE__ */ new Map(),
|
|
506
|
+
listening: 0,
|
|
507
|
+
unheard: /* @__PURE__ */ new Set(),
|
|
508
|
+
reloadTimer: void 0,
|
|
509
|
+
readAhead: 0
|
|
1994
510
|
};
|
|
1995
511
|
}
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
return file !== void 0 && declared.files.has(file) ? file : void 0;
|
|
2000
|
-
}
|
|
2001
|
-
async function listedFileOf(resolver, declared, source, importer) {
|
|
2002
|
-
if (declared.entries.has(source)) {
|
|
2003
|
-
const id = source.startsWith("#") ? void 0 : declared.ids.get(source);
|
|
2004
|
-
if (id !== void 0) return { file: fileOf(id) };
|
|
2005
|
-
const file2 = await listedFileFrom(resolver, declared, source, importer);
|
|
2006
|
-
return file2 === void 0 && source.startsWith("#") ? void 0 : { file: file2 };
|
|
2007
|
-
}
|
|
2008
|
-
if (!isNamingListed(source, declared)) return void 0;
|
|
2009
|
-
const file = await listedFileFrom(resolver, declared, source, importer);
|
|
2010
|
-
return file === void 0 ? void 0 : { file };
|
|
512
|
+
function noteReloadSent(state, id) {
|
|
513
|
+
state.reloading.set(id, Date.now());
|
|
514
|
+
if (state.listening === 0) state.unheard.add(id);
|
|
2011
515
|
}
|
|
2012
516
|
|
|
2013
517
|
// src/vite-state.ts
|
|
@@ -2041,10 +545,7 @@ function freshState() {
|
|
|
2041
545
|
builtEnvironments: /* @__PURE__ */ new Set(),
|
|
2042
546
|
warned: /* @__PURE__ */ new Set(),
|
|
2043
547
|
served: /* @__PURE__ */ new Map(),
|
|
2044
|
-
|
|
2045
|
-
reloading: /* @__PURE__ */ new Map(),
|
|
2046
|
-
reloadTimer: void 0,
|
|
2047
|
-
readAhead: 0,
|
|
548
|
+
...freshReloads(),
|
|
2048
549
|
htmlRead: false,
|
|
2049
550
|
serverTransformed: false,
|
|
2050
551
|
directiveExpanded: false,
|
|
@@ -2116,61 +617,6 @@ async function setupExposuresFor(context, ctx, input) {
|
|
|
2116
617
|
return context.state.exposures.get(moduleKey(environment, owner));
|
|
2117
618
|
}
|
|
2118
619
|
|
|
2119
|
-
// src/vite-source-map.ts
|
|
2120
|
-
function toSourceMap(map) {
|
|
2121
|
-
return {
|
|
2122
|
-
version: 3,
|
|
2123
|
-
sources: map.sources,
|
|
2124
|
-
names: map.names ?? [],
|
|
2125
|
-
mappings: map.mappings,
|
|
2126
|
-
...map.sourceRoot !== void 0 && { sourceRoot: map.sourceRoot },
|
|
2127
|
-
...map.sourcesContent !== void 0 && { sourcesContent: map.sourcesContent }
|
|
2128
|
-
};
|
|
2129
|
-
}
|
|
2130
|
-
function combinedMapOf(ctx) {
|
|
2131
|
-
const map = ctx.getCombinedSourcemap();
|
|
2132
|
-
return map.mappings === "" ? void 0 : decodeIncomingMap(toSourceMap(map));
|
|
2133
|
-
}
|
|
2134
|
-
var LINE_TERMINATOR = /\r\n|[\n\r\u{2028}\u{2029}]/gu;
|
|
2135
|
-
function lineStartsOf(code) {
|
|
2136
|
-
const starts = [0];
|
|
2137
|
-
for (const match of code.matchAll(LINE_TERMINATOR)) starts.push(match.index + match[0].length);
|
|
2138
|
-
return starts;
|
|
2139
|
-
}
|
|
2140
|
-
function lineIndexOf(starts, offset) {
|
|
2141
|
-
let low = 0;
|
|
2142
|
-
let high = starts.length - 1;
|
|
2143
|
-
while (low < high) {
|
|
2144
|
-
const middle = Math.ceil((low + high) / 2);
|
|
2145
|
-
if (starts[middle] <= offset) low = middle;
|
|
2146
|
-
else high = middle - 1;
|
|
2147
|
-
}
|
|
2148
|
-
return low;
|
|
2149
|
-
}
|
|
2150
|
-
function positionIn(code) {
|
|
2151
|
-
let starts;
|
|
2152
|
-
return (offset) => {
|
|
2153
|
-
starts ??= lineStartsOf(code);
|
|
2154
|
-
const index = lineIndexOf(starts, offset);
|
|
2155
|
-
return { line: index + 1, column: offset - starts[index] + 1 };
|
|
2156
|
-
};
|
|
2157
|
-
}
|
|
2158
|
-
function normalized(text) {
|
|
2159
|
-
return text.replace(/^\u{FEFF}/u, "").replaceAll("\r\n", "\n");
|
|
2160
|
-
}
|
|
2161
|
-
function placerFor(code, map, authored) {
|
|
2162
|
-
const position = positionIn(code);
|
|
2163
|
-
const isAuthored = (index) => {
|
|
2164
|
-
const source = map?.sourcesContent?.[index];
|
|
2165
|
-
return authored === void 0 || typeof source !== "string" ? true : normalized(source) === normalized(authored);
|
|
2166
|
-
};
|
|
2167
|
-
return (offset) => {
|
|
2168
|
-
const generated = position(offset);
|
|
2169
|
-
const origin = map?.originalPositionFor({ line: generated.line, column: generated.column - 1 });
|
|
2170
|
-
return origin && isAuthored(origin.sourceIndex) ? { line: origin.line, column: origin.column + 1 } : void 0;
|
|
2171
|
-
};
|
|
2172
|
-
}
|
|
2173
|
-
|
|
2174
620
|
// src/vite-unread-record.ts
|
|
2175
621
|
function isListed(context, pkg) {
|
|
2176
622
|
return pkg !== void 0 && Object.hasOwn(context.options.keepFor, pkg);
|
|
@@ -2180,7 +626,7 @@ var TOO_DEEP = "the module could not be read, so the atoms it names would not sh
|
|
|
2180
626
|
function unreadableRecord(context, input, text) {
|
|
2181
627
|
const { code, id, pkg } = input;
|
|
2182
628
|
const file = moduleLabel(context.root, id);
|
|
2183
|
-
const
|
|
629
|
+
const problem = {
|
|
2184
630
|
kind: "unreadable",
|
|
2185
631
|
offset: 0,
|
|
2186
632
|
construct: "",
|
|
@@ -2194,8 +640,8 @@ function unreadableRecord(context, input, text) {
|
|
|
2194
640
|
return {
|
|
2195
641
|
// The classes written whole need no parse to be found.
|
|
2196
642
|
atoms: atomsWrittenIn(code),
|
|
2197
|
-
problems: isStandingIn ? [] : [
|
|
2198
|
-
suppressed: isStandingIn ? [
|
|
643
|
+
problems: isStandingIn ? [] : [problem],
|
|
644
|
+
suppressed: isStandingIn ? [problem] : [],
|
|
2199
645
|
dynamicCalls: [],
|
|
2200
646
|
pkg,
|
|
2201
647
|
file
|
|
@@ -2240,348 +686,6 @@ function textRecord(context, input) {
|
|
|
2240
686
|
};
|
|
2241
687
|
}
|
|
2242
688
|
|
|
2243
|
-
// src/vite-used-take-lines.ts
|
|
2244
|
-
var IDENTIFIER = /^[$\p{ID_Start}_][$\p{ID_Continue}]*$/u;
|
|
2245
|
-
function takenName(name) {
|
|
2246
|
-
if (name === "default") return "the default export";
|
|
2247
|
-
if (IDENTIFIER.test(name)) return name;
|
|
2248
|
-
return `'${name.replaceAll("\\", String.raw`\\`).replaceAll("'", String.raw`\'`)}'`;
|
|
2249
|
-
}
|
|
2250
|
-
function takeWhat(take) {
|
|
2251
|
-
const names = take.names.map((name) => takenName(name)).join(", ");
|
|
2252
|
-
switch (take.shape) {
|
|
2253
|
-
case "dynamic-import": {
|
|
2254
|
-
return names === "" ? "import()" : `import() reading ${names}`;
|
|
2255
|
-
}
|
|
2256
|
-
case "names": {
|
|
2257
|
-
return names;
|
|
2258
|
-
}
|
|
2259
|
-
case "namespace": {
|
|
2260
|
-
return names === "" ? "a namespace import" : `a namespace import reading ${names}`;
|
|
2261
|
-
}
|
|
2262
|
-
case "star": {
|
|
2263
|
-
return "export *";
|
|
2264
|
-
}
|
|
2265
|
-
case "unreadable": {
|
|
2266
|
-
return "a require() or other import the build cannot read";
|
|
2267
|
-
}
|
|
2268
|
-
}
|
|
2269
|
-
}
|
|
2270
|
-
var FIX = " The lasting fix is upstream: import cx from @navecss/core/cx where it is called, and re-export it from there, only under the name cx, in each module that gives it out.";
|
|
2271
|
-
function clausesOf(takes) {
|
|
2272
|
-
const entries = takes.map((take) => ({
|
|
2273
|
-
taker: take.taker,
|
|
2274
|
-
text: `${take.taker} (${takeWhat(take)})`,
|
|
2275
|
-
shape: take.shape
|
|
2276
|
-
})).toSorted((a, b) => compareText(a.taker, b.taker) || compareText(a.text, b.text));
|
|
2277
|
-
const listed = [...new Set(entries.map((entry) => entry.text))].join(", ");
|
|
2278
|
-
const files = new Set(entries.map((entry) => entry.taker)).size === 1 ? "in that file" : "in each of those files";
|
|
2279
|
-
const isWhole = entries.some((entry) => entry.shape !== "names");
|
|
2280
|
-
const wholeClause = isWhole ? "; where a file takes a module whole (a namespace import, export *, import() or an import the build cannot read), import by name what it uses from that module, and cx from @navecss/core/cx" : "";
|
|
2281
|
-
const passedOn = takes.some((take) => take.isPassedOn === true) ? "; where a file re-exports what it takes, import cx from @navecss/core/cx in the files that call it, call cx there in its place, and drop the re-export" : "";
|
|
2282
|
-
return { files, listed, whole: `${wholeClause}${passedOn}` };
|
|
2283
|
-
}
|
|
2284
|
-
function takenLine(pkg, takes, hasPackageFix) {
|
|
2285
|
-
const { files, listed, whole } = clausesOf(takes);
|
|
2286
|
-
const fix = hasPackageFix ? FIX : "";
|
|
2287
|
-
return `${pkg} re-exports cx, and your code takes that cx, from the package or through another package that re-exports it, in ${listed}. The build does not read calls made through what your code takes there, and the keepFor entry stands in only for the package's own calls: ${files}, import cx from @navecss/core/cx instead and call cx in its place${whole}. The build prints no cxModules entry for this, since it found none of these takes made, by an import it can read and a specifier that resolves from Vite's root, from a module that re-exports cx from @navecss/core/cx itself and only under the name cx. Once your code makes none of these takes, the keepFor entry clears this.${fix}`;
|
|
2288
|
-
}
|
|
2289
|
-
function forwardLine(pkg, takes) {
|
|
2290
|
-
const { files, listed, whole } = clausesOf(takes);
|
|
2291
|
-
return `${pkg} re-exports the cx of a module listed in cxModules, and your code takes that cx, from ${pkg} or through another package that re-exports it, in ${listed}. The build follows a listed module one step, so it does not read calls made through what your code takes there: ${files}, import cx from @navecss/core/cx instead and call cx in its place${whole}.${FIX}`;
|
|
2292
|
-
}
|
|
2293
|
-
function callsThroughLine(pkg, callers) {
|
|
2294
|
-
const [make, owner, its] = callers.length === 1 ? ["makes", "a dependency's", "its"] : ["make", "dependencies'", "their"];
|
|
2295
|
-
return `${pkg} re-exports the cx of a module listed in cxModules, and the build follows a listed module one step, so it does not read the calls that ${callers.join(", ")} ${make} through that re-export. That code is ${owner}, not yours to change: list the atoms those calls can produce, from ${its} documentation, under the name of ${pkg}, which holds the re-export, in navePlugin(): keepFor: { '${pkg}': ['<atom>'] }. The lasting fix is upstream: ${pkg} can re-export cx from @navecss/core/cx itself, or the code that calls through it can import cx from there.`;
|
|
2296
|
-
}
|
|
2297
|
-
|
|
2298
|
-
// src/vite-used-package-lines.ts
|
|
2299
|
-
function isListableReexport(problem2) {
|
|
2300
|
-
return problem2.kind === "reexport" && problem2.isListable !== false;
|
|
2301
|
-
}
|
|
2302
|
-
function isRenamedOrReached(problem2) {
|
|
2303
|
-
return problem2.isRenamed === true || problem2.kind === "reexport" && !isListableReexport(problem2);
|
|
2304
|
-
}
|
|
2305
|
-
function isSecondHop(problem2) {
|
|
2306
|
-
return problem2.kind === "reexport" && problem2.isListable === false && problem2.pkg !== void 0;
|
|
2307
|
-
}
|
|
2308
|
-
function callsLine(pkg, problems, keepFor) {
|
|
2309
|
-
if (problems.every((problem2) => problem2.kind === "own")) {
|
|
2310
|
-
return `${pkg} names atoms of your own, which have no class, so a keepFor entry cannot make its calls produce a Nave class. The fix is the package's: it must name atoms Nave ships.`;
|
|
2311
|
-
}
|
|
2312
|
-
const isOnlyDynamic = problems.every((problem2) => problem2.kind === "dynamic");
|
|
2313
|
-
if (isOnlyDynamic) {
|
|
2314
|
-
const count = problems.length;
|
|
2315
|
-
const places = count === 1 ? "1 place" : `${count} places`;
|
|
2316
|
-
return `${pkg} calls cx.dynamic() in ${places}, and keepFor lists no atoms for it, so none of them applies a class. List the atoms those calls can take, from its documentation, under its name in navePlugin(): ${keepFor}.`;
|
|
2317
|
-
}
|
|
2318
|
-
return `${pkg} is a dependency, so its code is not yours to change. List the atoms its calls can produce, from its documentation, under its name in navePlugin(): ${keepFor}. The lasting fix is the package's: names chosen at run time go through cx.dynamic().`;
|
|
2319
|
-
}
|
|
2320
|
-
var LASTING_FIX = "The lasting fix is the package's: import cx from @navecss/core/cx where it is called, or re-export it from the package's entry.";
|
|
2321
|
-
function listedLine(pkg, specifiers, configured) {
|
|
2322
|
-
const array = cxModulesArray(configured, specifiers);
|
|
2323
|
-
const named = specifiers.map((specifier) => `'${specifier}'`).join(", ");
|
|
2324
|
-
const it = specifiers.length === 1 ? "it" : "them";
|
|
2325
|
-
return array === void 0 ? void 0 : `${pkg} re-exports cx in ${named}. List ${it} in navePlugin(): cxModules: ${array}.`;
|
|
2326
|
-
}
|
|
2327
|
-
function internalLine(pkg, count, keepFor, hasKeepFor) {
|
|
2328
|
-
if (hasKeepFor) {
|
|
2329
|
-
return `${pkg} also re-exports cx in a file that only the package itself imports; the keepFor entry above clears that too. The build does not read calls made through that cx: where your code imports cx from ${pkg} or one of its subpaths, import it from @navecss/core/cx instead. The lasting fix there is the package's: import cx from @navecss/core/cx where it is called, or re-export it from the package's entry.`;
|
|
2330
|
-
}
|
|
2331
|
-
const [file, them] = count === 1 ? ["a file that only", "it"] : ["files that only", "them"];
|
|
2332
|
-
return `${pkg} re-exports cx in ${file} the package itself imports, so your code has no specifier for ${them} to list in cxModules, and the build does not read calls made through that cx. Where your code imports cx from ${pkg} or one of its subpaths, import it from @navecss/core/cx instead. For the package's own calls, list the atoms they can produce, from its documentation, under its name in navePlugin(): ${keepFor}. ${LASTING_FIX}`;
|
|
2333
|
-
}
|
|
2334
|
-
var RENAMED_FIX = "import cx from @navecss/core/cx where it is called, and re-export it only under the name cx.";
|
|
2335
|
-
var RENAMED_FORM = "other than under the name cx (renamed, as a default or inside a namespace)";
|
|
2336
|
-
function renamedLine(pkg, count, keepFor, hasKeepFor) {
|
|
2337
|
-
const [those, them, its] = count === 1 ? ["that export", "it", "its"] : ["those exports", "them", "their"];
|
|
2338
|
-
const act = `import cx from @navecss/core/cx instead and call cx in ${its} place`;
|
|
2339
|
-
if (hasKeepFor) {
|
|
2340
|
-
return `${pkg} also re-exports cx ${RENAMED_FORM}, and no cxModules entry clears an export of cx from a module that does, under the name cx or another; the keepFor entry above clears ${those} too. The build does not read calls made through ${them}: where your code imports ${them} from ${pkg} or one of its subpaths, ${act}. The lasting fix there is the package's: ${RENAMED_FIX}`;
|
|
2341
|
-
}
|
|
2342
|
-
return `${pkg} re-exports cx ${RENAMED_FORM}, which the build does not follow even from a module listed in cxModules. Listing a module that does fails the build, so no entry there clears an export of cx from it, under the name cx or another, and the build does not read calls made through ${those}. Where your code imports ${those} from ${pkg} or one of its subpaths, ${act}. For the package's own calls, list the atoms they can produce, from its documentation, under its name in navePlugin(): ${keepFor}. The lasting fix is the package's: ${RENAMED_FIX}`;
|
|
2343
|
-
}
|
|
2344
|
-
function declaredLine(pkg, entries, hasInternal) {
|
|
2345
|
-
const named = entries.map((entry) => `'${entry}'`).join(", ");
|
|
2346
|
-
const [is, it, module] = entries.length === 1 ? ["is", "it", "the module"] : ["are", "them", "each module"];
|
|
2347
|
-
const reader = hasInternal ? "" : `, and where your code imports cx from ${it}, import cx from @navecss/core/cx instead`;
|
|
2348
|
-
return `${pkg} exports a cx the build does not follow from ${named}, which ${is} listed in cxModules. Remove ${it} from cxModules in navePlugin()${reader}. The lasting fix is the package's: make export { cx } from '@navecss/core/cx' the only export of cx in ${module} you list.`;
|
|
2349
|
-
}
|
|
2350
|
-
function withoutRemoved(problems, configured) {
|
|
2351
|
-
const removed = new Set(
|
|
2352
|
-
problems.flatMap(
|
|
2353
|
-
(problem2) => problem2.pkg !== void 0 && problem2.kind === "declared" ? problem2.entries ?? [] : []
|
|
2354
|
-
)
|
|
2355
|
-
);
|
|
2356
|
-
return configured.filter((entry) => !removed.has(entry));
|
|
2357
|
-
}
|
|
2358
|
-
function takeLines(pkg, all) {
|
|
2359
|
-
const isTaken = (problem2) => (problem2.takes?.length ?? 0) > 0;
|
|
2360
|
-
const taken = all.filter((problem2) => isTaken(problem2));
|
|
2361
|
-
const plain = taken.filter((problem2) => !isSecondHop(problem2));
|
|
2362
|
-
const hops = taken.filter((problem2) => isSecondHop(problem2));
|
|
2363
|
-
const takes = plain.flatMap((problem2) => problem2.takes);
|
|
2364
|
-
const lines = [];
|
|
2365
|
-
if (takes.length > 0) {
|
|
2366
|
-
const hasPackageFix = plain.some((problem2) => isRenamedOrReached(problem2)) || takes.some((take) => take.isReached);
|
|
2367
|
-
lines.push(takenLine(pkg, takes, hasPackageFix));
|
|
2368
|
-
}
|
|
2369
|
-
if (hops.length > 0)
|
|
2370
|
-
lines.push(
|
|
2371
|
-
forwardLine(
|
|
2372
|
-
pkg,
|
|
2373
|
-
hops.flatMap((problem2) => problem2.takes)
|
|
2374
|
-
)
|
|
2375
|
-
);
|
|
2376
|
-
const callers = all.flatMap((problem2) => problem2.callers ?? []);
|
|
2377
|
-
if (callers.length > 0)
|
|
2378
|
-
lines.push(callsThroughLine(pkg, [...new Set(callers)].toSorted(compareText)));
|
|
2379
|
-
return lines;
|
|
2380
|
-
}
|
|
2381
|
-
function packageLines(pkg, all, configured) {
|
|
2382
|
-
const isTaken = (problem2) => (problem2.takes?.length ?? 0) > 0;
|
|
2383
|
-
const problems = all.filter((problem2) => !isTaken(problem2) && problem2.callers === void 0);
|
|
2384
|
-
const keepFor = `keepFor: { '${pkg}': ['<atom>'] }`;
|
|
2385
|
-
const reexports = problems.filter((problem2) => isListableReexport(problem2));
|
|
2386
|
-
const internal = reexports.filter(
|
|
2387
|
-
(problem2) => problem2.specifier === void 0 && problem2.isRenamed !== true
|
|
2388
|
-
);
|
|
2389
|
-
const renamed = reexports.filter((problem2) => problem2.isRenamed === true);
|
|
2390
|
-
const declared = problems.filter((problem2) => problem2.kind === "declared");
|
|
2391
|
-
const rest = problems.filter(
|
|
2392
|
-
(problem2) => !isListableReexport(problem2) && problem2.kind !== "declared"
|
|
2393
|
-
);
|
|
2394
|
-
const named = [...new Set(reexports.flatMap((problem2) => problem2.specifier ?? []))].toSorted(
|
|
2395
|
-
compareText
|
|
2396
|
-
);
|
|
2397
|
-
const lines = [];
|
|
2398
|
-
if (declared.length > 0) {
|
|
2399
|
-
const entries = [...new Set(declared.flatMap((problem2) => problem2.entries ?? []))];
|
|
2400
|
-
lines.push(declaredLine(pkg, entries.toSorted(compareText), internal.length > 0));
|
|
2401
|
-
}
|
|
2402
|
-
if (rest.length > 0) lines.push(callsLine(pkg, rest, keepFor));
|
|
2403
|
-
const listed = named.length > 0 ? listedLine(pkg, named, configured) : void 0;
|
|
2404
|
-
if (listed !== void 0) lines.push(listed);
|
|
2405
|
-
if (internal.length > 0) {
|
|
2406
|
-
const files = new Set(internal.map((problem2) => problem2.file)).size;
|
|
2407
|
-
const hasKeepFor = rest.some((problem2) => problem2.kind !== "own");
|
|
2408
|
-
lines.push(internalLine(pkg, files, keepFor, hasKeepFor));
|
|
2409
|
-
}
|
|
2410
|
-
if (renamed.length > 0) {
|
|
2411
|
-
const hasKeepFor = rest.some((problem2) => problem2.kind !== "own") || internal.length > 0;
|
|
2412
|
-
lines.push(renamedLine(pkg, renamed.length, keepFor, hasKeepFor));
|
|
2413
|
-
}
|
|
2414
|
-
lines.push(...takeLines(pkg, all));
|
|
2415
|
-
return lines;
|
|
2416
|
-
}
|
|
2417
|
-
|
|
2418
|
-
// src/vite-used-report.ts
|
|
2419
|
-
var LINE_UNKNOWN_WITHOUT_MAP = " (line unknown: this file's compiled code has no source map in this build; with build.sourcemap set in the Vite config, the report gives the line if the source maps then lead back to it)";
|
|
2420
|
-
var LINE_UNKNOWN_UNMAPPED = " (line unknown: no source map leads from the compiled code to this file)";
|
|
2421
|
-
var REPORT_CAUSE = "the build cannot tell which atoms these apply, and it ships only the atoms it can read.";
|
|
2422
|
-
var REMEDIES = {
|
|
2423
|
-
argument: [
|
|
2424
|
-
"Name the atoms at the call: a string literal, a const in the same file, or a condition choosing between them, as in cx(on ? 'flex' : 'grid').",
|
|
2425
|
-
"To choose by a value, call cx() once per case and pick between the results: ({ row: cx('flex'), grid: cx('grid') })[variant].",
|
|
2426
|
-
"If the name comes from data the build never sees, write cx.dynamic(name) and list every atom it can take in keep in navePlugin()."
|
|
2427
|
-
],
|
|
2428
|
-
reference: [
|
|
2429
|
-
"Call cx() where the classes are applied, with the atom names as its arguments: the build reads calls, not a cx that is assigned, passed or spread."
|
|
2430
|
-
],
|
|
2431
|
-
// Printed by `reexportRemedy`, which names the modules a `cxModules` entry would clear.
|
|
2432
|
-
reexport: [],
|
|
2433
|
-
declared: [
|
|
2434
|
-
"In a module listed in cxModules, make export { cx } from '@navecss/core/cx' its only export of cx, or remove the module from cxModules and import cx from @navecss/core/cx where it is called."
|
|
2435
|
-
],
|
|
2436
|
-
concatenation: [
|
|
2437
|
-
"Write cx() with the atom name, or cx.dynamic() with keep for a name chosen at run time."
|
|
2438
|
-
],
|
|
2439
|
-
dynamic: ["List the atoms those calls can take in keep in navePlugin()."],
|
|
2440
|
-
unknown: [],
|
|
2441
|
-
own: [],
|
|
2442
|
-
unreadable: []
|
|
2443
|
-
};
|
|
2444
|
-
function problemLine(problem2) {
|
|
2445
|
-
const where = problem2.unknownLine === void 0 ? `${problem2.file}:${problem2.line}:${problem2.column}: ` : `${problem2.file}: `;
|
|
2446
|
-
const ending = problem2.unknownLine ?? "";
|
|
2447
|
-
if (problem2.construct === "") return `${where}${problem2.text}${ending}`;
|
|
2448
|
-
const construct = cut(problem2.construct);
|
|
2449
|
-
return problem2.text === "" ? `${where}${construct}${ending}` : `${where}${construct}: ${problem2.text}${ending}`;
|
|
2450
|
-
}
|
|
2451
|
-
function reexportRemedy(problems, configured) {
|
|
2452
|
-
const modules = problems.filter((problem2) => isListableReexport(problem2)).map((problem2) => problem2.file.startsWith(".") ? problem2.file : `./${problem2.file}`);
|
|
2453
|
-
const array = cxModulesArray(configured, modules);
|
|
2454
|
-
const lines = array === void 0 ? [] : [
|
|
2455
|
-
`To keep a module that re-exports cx, list it in navePlugin() by its path from the project root: cxModules: ${array}. Files that import cx from it are then read as if they imported it from @navecss/core/cx. Or import cx from @navecss/core/cx directly where it is called.`
|
|
2456
|
-
];
|
|
2457
|
-
if (problems.some((problem2) => problem2.kind === "reexport" && !isListableReexport(problem2))) {
|
|
2458
|
-
lines.push(
|
|
2459
|
-
"Import cx where it is called, from @navecss/core/cx or from a module listed in cxModules, instead of re-exporting the cx of a listed module."
|
|
2460
|
-
);
|
|
2461
|
-
}
|
|
2462
|
-
return lines;
|
|
2463
|
-
}
|
|
2464
|
-
function remedyBlock(problems, listed) {
|
|
2465
|
-
const configured = withoutRemoved(problems, listed);
|
|
2466
|
-
const application = problems.filter((problem2) => problem2.pkg === void 0);
|
|
2467
|
-
const lines = [];
|
|
2468
|
-
for (const kind of PROBLEM_KINDS) {
|
|
2469
|
-
if (application.every((problem2) => problem2.kind !== kind)) continue;
|
|
2470
|
-
lines.push(...kind === "reexport" ? reexportRemedy(application, configured) : REMEDIES[kind]);
|
|
2471
|
-
}
|
|
2472
|
-
const byPackage = /* @__PURE__ */ new Map();
|
|
2473
|
-
for (const problem2 of problems) {
|
|
2474
|
-
if (problem2.pkg !== void 0)
|
|
2475
|
-
byPackage.set(problem2.pkg, [...byPackage.get(problem2.pkg) ?? [], problem2]);
|
|
2476
|
-
}
|
|
2477
|
-
for (const pkg of byPackage.keys().toArray().toSorted(compareText)) {
|
|
2478
|
-
lines.push(...packageLines(pkg, byPackage.get(pkg), configured));
|
|
2479
|
-
}
|
|
2480
|
-
if (application.some((problem2) => problem2.needsAvailable)) lines.push(availableLine());
|
|
2481
|
-
return lines;
|
|
2482
|
-
}
|
|
2483
|
-
function inReportOrder(problems) {
|
|
2484
|
-
const rank = (problem2) => problem2.pkg === void 0 ? 0 : 1;
|
|
2485
|
-
return problems.toSorted(
|
|
2486
|
-
(a, b) => rank(a) - rank(b) || compareText(a.file, b.file) || Number(a.unknownLine !== void 0) - Number(b.unknownLine !== void 0) || a.line - b.line || a.column - b.column
|
|
2487
|
-
);
|
|
2488
|
-
}
|
|
2489
|
-
function problemLines(problems) {
|
|
2490
|
-
const ordered = inReportOrder(problems);
|
|
2491
|
-
const isApplicationDynamic = (problem2) => problem2.kind === "dynamic" && problem2.pkg === void 0;
|
|
2492
|
-
const application = ordered.filter(
|
|
2493
|
-
(problem2) => problem2.pkg === void 0 && !isApplicationDynamic(problem2)
|
|
2494
|
-
);
|
|
2495
|
-
const dynamic = ordered.filter((problem2) => isApplicationDynamic(problem2));
|
|
2496
|
-
const dependencies = ordered.filter((problem2) => problem2.pkg !== void 0);
|
|
2497
|
-
const lines = application.map((problem2) => problemLine(problem2));
|
|
2498
|
-
if (dynamic.length > 0) {
|
|
2499
|
-
const places = dynamic.length === 1 ? "1 place" : `${dynamic.length} places`;
|
|
2500
|
-
lines.push(
|
|
2501
|
-
`cx.dynamic() is called in ${places} in your code, but keep is empty, so none of them applies a class.`,
|
|
2502
|
-
...dynamic.map((problem2) => problemLine(problem2))
|
|
2503
|
-
);
|
|
2504
|
-
}
|
|
2505
|
-
return [...lines, ...dependencies.map((problem2) => problemLine(problem2))];
|
|
2506
|
-
}
|
|
2507
|
-
function noun(count, word) {
|
|
2508
|
-
return `${count} ${word}${count === 1 ? "" : "s"}`;
|
|
2509
|
-
}
|
|
2510
|
-
function buildReport(problems, configured = []) {
|
|
2511
|
-
const files = new Set(problems.map((problem2) => problem2.file)).size;
|
|
2512
|
-
const first2 = `${noun(problems.length, "problem")} in ${noun(files, "file")}: ${REPORT_CAUSE}`;
|
|
2513
|
-
return [first2, ...problemLines(problems), ...remedyBlock(problems, configured)].join("\n");
|
|
2514
|
-
}
|
|
2515
|
-
function moduleReport(problems, configured = []) {
|
|
2516
|
-
return [...problemLines(problems), ...remedyBlock(problems, configured)].join("\n");
|
|
2517
|
-
}
|
|
2518
|
-
|
|
2519
|
-
// src/vite-options.ts
|
|
2520
|
-
function unknownAtomText(name) {
|
|
2521
|
-
const hint = hintFor(name);
|
|
2522
|
-
return hint ? ` ${hint}` : "";
|
|
2523
|
-
}
|
|
2524
|
-
function problemWithName(where, name, own) {
|
|
2525
|
-
if (typeof name === "string" && isBuiltInAtom(name)) return void 0;
|
|
2526
|
-
if (typeof name === "string" && own === void 0) return void 0;
|
|
2527
|
-
if (typeof name === "string" && own?.has(name)) {
|
|
2528
|
-
return `navePlugin(): ${where} names "${name}", an atom of your own; those have no class, so there is nothing to keep.`;
|
|
2529
|
-
}
|
|
2530
|
-
const spelled = typeof name === "string" ? name : String(name);
|
|
2531
|
-
return `navePlugin(): ${where} names an unknown atom "${spelled}".${unknownAtomText(spelled)}`;
|
|
2532
|
-
}
|
|
2533
|
-
function problemsInList(where, list, own) {
|
|
2534
|
-
if (!Array.isArray(list)) return [`navePlugin(): ${where} must be an array of atom names.`];
|
|
2535
|
-
return Array.from(list, (name) => problemWithName(where, name, own) ?? []).flat();
|
|
2536
|
-
}
|
|
2537
|
-
function problemsInKeepFor(keepFor, own) {
|
|
2538
|
-
if (typeof keepFor !== "object" || keepFor === null || Array.isArray(keepFor)) {
|
|
2539
|
-
return ["navePlugin(): keepFor must be an object from package names to arrays of atom names."];
|
|
2540
|
-
}
|
|
2541
|
-
const problems = [];
|
|
2542
|
-
for (const [pkg, list] of Object.entries(keepFor)) {
|
|
2543
|
-
problems.push(...problemsInList(`keepFor["${pkg}"]`, list, own));
|
|
2544
|
-
}
|
|
2545
|
-
return problems;
|
|
2546
|
-
}
|
|
2547
|
-
function problemsInCxModules(cxModules) {
|
|
2548
|
-
if (!Array.isArray(cxModules)) {
|
|
2549
|
-
return ["navePlugin(): cxModules must be an array of module paths or specifiers."];
|
|
2550
|
-
}
|
|
2551
|
-
return Array.from(
|
|
2552
|
-
cxModules,
|
|
2553
|
-
(entry, index) => typeof entry === "string" ? [] : `navePlugin(): cxModules[${index}] must be a string: a module path or a specifier.`
|
|
2554
|
-
).flat();
|
|
2555
|
-
}
|
|
2556
|
-
function problemsInOptions(options, own) {
|
|
2557
|
-
const problems = [];
|
|
2558
|
-
const { atomic, keep, keepFor, cxModules } = options;
|
|
2559
|
-
if (atomic !== void 0 && atomic !== "all" && atomic !== "used") {
|
|
2560
|
-
problems.push("navePlugin(): atomic must be 'used' or 'all'.");
|
|
2561
|
-
}
|
|
2562
|
-
if (keep !== void 0) problems.push(...problemsInList("keep", keep, own));
|
|
2563
|
-
if (keepFor !== void 0) problems.push(...problemsInKeepFor(keepFor, own));
|
|
2564
|
-
if (cxModules !== void 0) problems.push(...problemsInCxModules(cxModules));
|
|
2565
|
-
return problems;
|
|
2566
|
-
}
|
|
2567
|
-
function assertOptions(options, own) {
|
|
2568
|
-
const [first2] = problemsInOptions(options, own);
|
|
2569
|
-
if (first2 !== void 0) throw new Error(first2);
|
|
2570
|
-
}
|
|
2571
|
-
function resolveUsedOptions(options) {
|
|
2572
|
-
return {
|
|
2573
|
-
atomic: options.atomic ?? "used",
|
|
2574
|
-
keep: [...options.keep ?? []],
|
|
2575
|
-
keepFor: Object.fromEntries(
|
|
2576
|
-
Object.entries(options.keepFor ?? {}).map(([pkg, list]) => [pkg, [...list]])
|
|
2577
|
-
),
|
|
2578
|
-
cxModules: [...options.cxModules ?? []]
|
|
2579
|
-
};
|
|
2580
|
-
}
|
|
2581
|
-
function keptAtoms(options) {
|
|
2582
|
-
return [.../* @__PURE__ */ new Set([...options.keep, ...Object.values(options.keepFor).flat()])];
|
|
2583
|
-
}
|
|
2584
|
-
|
|
2585
689
|
// src/vite-used.ts
|
|
2586
690
|
function createUsedContext(options, extend) {
|
|
2587
691
|
return {
|
|
@@ -2637,10 +741,10 @@ function lineUnknownNote(context, id) {
|
|
|
2637
741
|
return isBuildWithoutMaps && !isInlineScript(id) ? LINE_UNKNOWN_WITHOUT_MAP : LINE_UNKNOWN_UNMAPPED;
|
|
2638
742
|
}
|
|
2639
743
|
function locate(problems, placing) {
|
|
2640
|
-
return problems.map((
|
|
2641
|
-
const place = placing.place(
|
|
744
|
+
return problems.map((problem) => {
|
|
745
|
+
const place = placing.place(problem.offset);
|
|
2642
746
|
const where = place ?? { ...NO_PLACE, unknownLine: placing.unknownLine };
|
|
2643
|
-
return { ...
|
|
747
|
+
return { ...problem, file: placing.file, pkg: placing.pkg, moduleId: placing.id, ...where };
|
|
2644
748
|
});
|
|
2645
749
|
}
|
|
2646
750
|
function locateDynamic(reading, placing) {
|
|
@@ -2693,7 +797,8 @@ async function recordOf(context, ctx, input, reading) {
|
|
|
2693
797
|
suppressed: isStandingIn ? locate(reading.problems, placing) : [],
|
|
2694
798
|
dynamicCalls: locateDynamic(reading, placing),
|
|
2695
799
|
pkg,
|
|
2696
|
-
file: placing.file
|
|
800
|
+
file: placing.file,
|
|
801
|
+
...reading.edits.length > 0 && { edits: reading.edits }
|
|
2697
802
|
};
|
|
2698
803
|
}
|
|
2699
804
|
function readOrUndefined(code, program, options) {
|
|
@@ -2719,7 +824,9 @@ async function recordParsed(context, ctx, input, key) {
|
|
|
2719
824
|
}),
|
|
2720
825
|
isDependency: isDependencyId(id),
|
|
2721
826
|
isVueScript: /\.vue(?:$|\?)/.test(id),
|
|
2722
|
-
setup: await setupExposuresFor(context, ctx, { program, code, id })
|
|
827
|
+
setup: await setupExposuresFor(context, ctx, { program, code, id }),
|
|
828
|
+
// A build turns each call into the string it returns; the dev server keeps the functions.
|
|
829
|
+
...context.command === "build" && { rewrite: { keep: keepMap(context.kept) } }
|
|
2723
830
|
});
|
|
2724
831
|
if (!reading) {
|
|
2725
832
|
context.state.exposures.delete(key);
|
|
@@ -2755,6 +862,47 @@ async function recordModule(context, ctx, module) {
|
|
|
2755
862
|
return record;
|
|
2756
863
|
}
|
|
2757
864
|
|
|
865
|
+
// src/vite-collect-problems.ts
|
|
866
|
+
function listedAtomsOf(record, context) {
|
|
867
|
+
if (record.pkg === void 0) return context.options.keep;
|
|
868
|
+
const { keepFor } = context.options;
|
|
869
|
+
return Object.hasOwn(keepFor, record.pkg) ? keepFor[record.pkg] : [];
|
|
870
|
+
}
|
|
871
|
+
function dynamicProblems(record, context) {
|
|
872
|
+
const isCovered = listedAtomsOf(record, context).length > 0;
|
|
873
|
+
if (isCovered) return [];
|
|
874
|
+
return record.dynamicCalls.map((call) => ({
|
|
875
|
+
kind: "dynamic",
|
|
876
|
+
offset: 0,
|
|
877
|
+
construct: call.construct,
|
|
878
|
+
text: "",
|
|
879
|
+
file: call.file,
|
|
880
|
+
line: call.line,
|
|
881
|
+
column: call.column,
|
|
882
|
+
pkg: record.pkg,
|
|
883
|
+
...call.unknownLine !== void 0 && { unknownLine: call.unknownLine }
|
|
884
|
+
}));
|
|
885
|
+
}
|
|
886
|
+
function problemsOf(record, context) {
|
|
887
|
+
return [...record.problems, ...dynamicProblems(record, context)];
|
|
888
|
+
}
|
|
889
|
+
function failModule(ctx, context, input) {
|
|
890
|
+
const { home, id, problems } = input;
|
|
891
|
+
const message = moduleReport(problems, context.options.cxModules, home);
|
|
892
|
+
const first = problems[0];
|
|
893
|
+
return ctx.error({
|
|
894
|
+
message,
|
|
895
|
+
id,
|
|
896
|
+
loc: { file: id, line: Math.max(first.line, 1), column: Math.max(first.column - 1, 0) }
|
|
897
|
+
});
|
|
898
|
+
}
|
|
899
|
+
function failDevModule(ctx, context, input) {
|
|
900
|
+
const { home, id, record } = input;
|
|
901
|
+
if (context.command !== "serve" || record.pkg !== void 0) return;
|
|
902
|
+
const problems = problemsOf(record, context);
|
|
903
|
+
if (problems.length > 0) failModule(ctx, context, { home, id, problems });
|
|
904
|
+
}
|
|
905
|
+
|
|
2758
906
|
// src/vite-cx-module-lines.ts
|
|
2759
907
|
function quoted(specifiers) {
|
|
2760
908
|
return specifiers.map((specifier) => `'${specifier}'`).join(", ");
|
|
@@ -2782,7 +930,7 @@ function dependencyLineOf(item) {
|
|
|
2782
930
|
var RELATIVE_REMEDY = "Adding a relative specifier to cxModules would not clear this: a relative entry is read from the project root. Instead of the rewrite";
|
|
2783
931
|
var TYPESCRIPT_CONDITION = "Where a rewrite ends in .ts, .tsx, .mts or .cts, TypeScript accepts it only if your tsconfig sets allowImportingTsExtensions or rewriteRelativeImportExtensions; if it sets neither, use the alias the line above describes instead.";
|
|
2784
932
|
var NO_SPECIFIER_REMEDY = "Where the build could not find the specifier, import the module there by a specifier ending in the listed file's name, or by an alias or package name added to cxModules.";
|
|
2785
|
-
function applicationRemedyOf(items, lines,
|
|
933
|
+
function applicationRemedyOf(items, lines, input) {
|
|
2786
934
|
const remedy = [];
|
|
2787
935
|
const relativeCount = lines.reduce((count, line) => count + line.relative.length, 0);
|
|
2788
936
|
if (relativeCount === 1) {
|
|
@@ -2804,40 +952,39 @@ function applicationRemedyOf(items, lines, configured) {
|
|
|
2804
952
|
items.flatMap((item) => item.specifiers.filter((specifier) => !isRelative(specifier)))
|
|
2805
953
|
)
|
|
2806
954
|
];
|
|
2807
|
-
const array = cxModulesArray(configured, added);
|
|
955
|
+
const array = cxModulesArray(input.configured, added);
|
|
2808
956
|
if (array !== void 0) {
|
|
2809
957
|
const each = added.length === 1 ? "the specifier" : "each specifier";
|
|
2810
|
-
remedy.push(`Add ${each}, as written, to cxModules in
|
|
958
|
+
remedy.push(`Add ${each}, as written, to cxModules in ${input.home}: cxModules: ${array}.`);
|
|
2811
959
|
}
|
|
2812
960
|
return remedy;
|
|
2813
961
|
}
|
|
2814
962
|
var LASTING_FIX_HERE = "The lasting fix there is the package's: import the module by a specifier ending in the listed file's name.";
|
|
2815
|
-
function packageRemedyOf(pkg, files,
|
|
2816
|
-
if (hasKeepFor) {
|
|
963
|
+
function packageRemedyOf(pkg, files, input) {
|
|
964
|
+
if (input.hasKeepFor) {
|
|
2817
965
|
const file = files === 1 ? "a file" : "files";
|
|
2818
966
|
return `${pkg} also imports a module listed in cxModules in ${file} the build did not read; the keepFor entry above clears that too. ${LASTING_FIX_HERE}`;
|
|
2819
967
|
}
|
|
2820
|
-
return `For ${pkg}, list the atoms its calls can produce, from its documentation, under its name in
|
|
968
|
+
return `For ${pkg}, list the atoms its calls can produce, from its documentation, under its name in ${input.home}: keepFor: { '${pkg}': ['<atom>'] }. Once the package is listed, its files no longer fail the build here, and the atoms you list stand in for the calls the build did not read. The lasting fix is the package's: import the module by a specifier ending in the listed file's name.`;
|
|
2821
969
|
}
|
|
2822
970
|
function importerErrorOf(found, input) {
|
|
2823
971
|
const application = found.filter((item) => item.pkg === void 0);
|
|
2824
972
|
const dependencies = found.filter((item) => item.pkg !== void 0);
|
|
2825
973
|
const count = new Set(found.map((item) => item.importer)).size;
|
|
2826
|
-
const
|
|
974
|
+
const first = count === 1 ? "1 file imports a module listed in cxModules through a specifier the build does not recognise, so the build did not read the cx() calls made through it." : `${count} files import a module listed in cxModules through a specifier the build does not recognise, so the build did not read the cx() calls made through those specifiers.`;
|
|
2827
975
|
const lines = application.map((item) => applicationLinesOf(item));
|
|
2828
976
|
const byPackage = Map.groupBy(dependencies, (item) => item.pkg);
|
|
2829
977
|
const packages = byPackage.keys().toArray().toSorted(compareText);
|
|
2830
978
|
return [
|
|
2831
|
-
|
|
979
|
+
first,
|
|
2832
980
|
...lines.flatMap((line) => [...line.relative, ...line.other, ...line.none]).toSorted(compareText),
|
|
2833
981
|
...dependencies.map((item) => dependencyLineOf(item)).toSorted(compareText),
|
|
2834
|
-
...applicationRemedyOf(application, lines, input
|
|
982
|
+
...applicationRemedyOf(application, lines, input),
|
|
2835
983
|
...packages.map(
|
|
2836
|
-
(pkg) => packageRemedyOf(
|
|
2837
|
-
pkg,
|
|
2838
|
-
|
|
2839
|
-
|
|
2840
|
-
)
|
|
984
|
+
(pkg) => packageRemedyOf(pkg, new Set(byPackage.get(pkg).map((item) => item.importer)).size, {
|
|
985
|
+
hasKeepFor: input.report?.includes(`keepFor: { '${pkg}'`) ?? false,
|
|
986
|
+
home: input.home
|
|
987
|
+
})
|
|
2841
988
|
)
|
|
2842
989
|
].join("\n");
|
|
2843
990
|
}
|
|
@@ -2899,18 +1046,18 @@ async function withClearingSpecifiers(ctx, context, problems) {
|
|
|
2899
1046
|
};
|
|
2900
1047
|
const renamed = new Set(
|
|
2901
1048
|
problems.flatMap(
|
|
2902
|
-
(
|
|
1049
|
+
(problem) => problem.isRenamed === true && problem.moduleId !== void 0 ? [problem.moduleId] : []
|
|
2903
1050
|
)
|
|
2904
1051
|
);
|
|
2905
1052
|
return await Promise.all(
|
|
2906
|
-
problems.map(async (
|
|
2907
|
-
const { moduleId, pkg } =
|
|
2908
|
-
if (pkg === void 0 || moduleId === void 0) return
|
|
2909
|
-
if (
|
|
2910
|
-
if (!isListableReexport(
|
|
2911
|
-
if (renamed.has(moduleId)) return { ...
|
|
1053
|
+
problems.map(async (problem) => {
|
|
1054
|
+
const { moduleId, pkg } = problem;
|
|
1055
|
+
if (pkg === void 0 || moduleId === void 0) return problem;
|
|
1056
|
+
if (problem.kind === "declared") return { ...problem, entries: await entriesOf(moduleId) };
|
|
1057
|
+
if (!isListableReexport(problem)) return problem;
|
|
1058
|
+
if (renamed.has(moduleId)) return { ...problem, isRenamed: true };
|
|
2912
1059
|
const specifier = await clearing(pkg, moduleId);
|
|
2913
|
-
return specifier === void 0 ?
|
|
1060
|
+
return specifier === void 0 ? problem : { ...problem, specifier };
|
|
2914
1061
|
})
|
|
2915
1062
|
);
|
|
2916
1063
|
}
|
|
@@ -3014,13 +1161,13 @@ function withoutEchoes(modules) {
|
|
|
3014
1161
|
const broken = new Set(
|
|
3015
1162
|
modules.flatMap(
|
|
3016
1163
|
(module) => module.problems.flatMap(
|
|
3017
|
-
(
|
|
1164
|
+
(problem) => problem.kind === "declared" && problem.moduleId !== void 0 && !problem.hasNaveCx ? [fileOf(problem.moduleId)] : []
|
|
3018
1165
|
)
|
|
3019
1166
|
)
|
|
3020
1167
|
);
|
|
3021
1168
|
const isEcho = (module) => module.onlyVia !== void 0 && [...module.onlyVia].every((file) => broken.has(file));
|
|
3022
1169
|
return modules.flatMap(
|
|
3023
|
-
(module) => isEcho(module) ? module.problems.filter((
|
|
1170
|
+
(module) => isEcho(module) ? module.problems.filter((problem) => !ECHO_KINDS.has(problem.kind)) : module.problems
|
|
3024
1171
|
);
|
|
3025
1172
|
}
|
|
3026
1173
|
|
|
@@ -3153,7 +1300,7 @@ function takeStaleModules(context, environment) {
|
|
|
3153
1300
|
for (const id of ids) {
|
|
3154
1301
|
const module = environment.moduleGraph.getModuleById(id);
|
|
3155
1302
|
if (!module) continue;
|
|
3156
|
-
state
|
|
1303
|
+
noteReloadSent(state, id);
|
|
3157
1304
|
sheets.push(module);
|
|
3158
1305
|
}
|
|
3159
1306
|
return sheets;
|
|
@@ -3386,19 +1533,19 @@ function isEmptyRegion(sheet, from, to) {
|
|
|
3386
1533
|
}
|
|
3387
1534
|
function pruneRule(sheet, statement, emitted) {
|
|
3388
1535
|
const { from, open, close } = statement;
|
|
3389
|
-
const
|
|
3390
|
-
const members = membersOf(sheet,
|
|
1536
|
+
const first = firstSignificant(sheet.tokens, from, open);
|
|
1537
|
+
const members = membersOf(sheet, first, open);
|
|
3391
1538
|
const kept = members.filter(([start, end]) => blockersOf(sheet, start, end, emitted).length === 0);
|
|
3392
1539
|
if (kept.length === members.length) return sheet.slice(from, close + 1);
|
|
3393
1540
|
if (kept.length === 0) return "";
|
|
3394
1541
|
let trailing = open;
|
|
3395
|
-
while (trailing >
|
|
1542
|
+
while (trailing > first && firstSignificant(sheet.tokens, trailing - 1, trailing) === trailing) {
|
|
3396
1543
|
trailing -= 1;
|
|
3397
1544
|
}
|
|
3398
|
-
const list = sheet.slice(
|
|
1545
|
+
const list = sheet.slice(first, trailing);
|
|
3399
1546
|
const separator = /,\s/.test(list) ? ", " : ",";
|
|
3400
1547
|
const text = kept.map(([start, end]) => sheet.slice(start, end).trim()).join(separator);
|
|
3401
|
-
return `${sheet.slice(from,
|
|
1548
|
+
return `${sheet.slice(from, first)}${text}${sheet.slice(trailing, open)}${sheet.slice(open, close + 1)}`;
|
|
3402
1549
|
}
|
|
3403
1550
|
function pruneRegion(sheet, from, to, emitted) {
|
|
3404
1551
|
const statements = sheet.statements(from, to);
|
|
@@ -3410,8 +1557,8 @@ function pruneRegion(sheet, from, to, emitted) {
|
|
|
3410
1557
|
function pruneStatement(sheet, statement, emitted) {
|
|
3411
1558
|
const { open, close } = statement;
|
|
3412
1559
|
if (open === void 0 || close === void 0) return sheet.slice(statement.from, statement.to);
|
|
3413
|
-
const
|
|
3414
|
-
const keyword = atKeywordAt(sheet,
|
|
1560
|
+
const first = firstSignificant(sheet.tokens, statement.from, open);
|
|
1561
|
+
const keyword = atKeywordAt(sheet, first);
|
|
3415
1562
|
if (keyword === void 0) return pruneRule(sheet, statement, emitted);
|
|
3416
1563
|
if (!GROUPS.has(keyword)) return sheet.slice(statement.from, close + 1);
|
|
3417
1564
|
if (isEmptyRegion(sheet, open + 1, close)) return sheet.slice(statement.from, close + 1);
|
|
@@ -3431,16 +1578,16 @@ function pruneAtomicLayer(css, emitted) {
|
|
|
3431
1578
|
}
|
|
3432
1579
|
return cursor === 0 ? css : out + sheet.slice(cursor, sheet.tokens.length);
|
|
3433
1580
|
}
|
|
3434
|
-
function visitMembers(sheet, from, to,
|
|
1581
|
+
function visitMembers(sheet, from, to, visit) {
|
|
3435
1582
|
for (const statement of sheet.statements(from, to)) {
|
|
3436
1583
|
const { open, close } = statement;
|
|
3437
1584
|
if (open === void 0 || close === void 0) continue;
|
|
3438
|
-
const
|
|
3439
|
-
const keyword = atKeywordAt(sheet,
|
|
1585
|
+
const first = firstSignificant(sheet.tokens, statement.from, open);
|
|
1586
|
+
const keyword = atKeywordAt(sheet, first);
|
|
3440
1587
|
if (keyword === void 0) {
|
|
3441
|
-
for (const [start, end] of membersOf(sheet,
|
|
1588
|
+
for (const [start, end] of membersOf(sheet, first, open)) visit(start, end);
|
|
3442
1589
|
} else if (GROUPS.has(keyword)) {
|
|
3443
|
-
visitMembers(sheet, open + 1, close,
|
|
1590
|
+
visitMembers(sheet, open + 1, close, visit);
|
|
3444
1591
|
}
|
|
3445
1592
|
}
|
|
3446
1593
|
}
|
|
@@ -3471,9 +1618,14 @@ function unprunedAtoms(css, emitted) {
|
|
|
3471
1618
|
// src/vite-dev.ts
|
|
3472
1619
|
var RELOAD_ANSWER_MS = 2e3;
|
|
3473
1620
|
var NO_MAP = JSON.stringify({ mappings: "" });
|
|
1621
|
+
var DIRECT = /[?&]direct\b/;
|
|
1622
|
+
function isInlinedInHtml(module) {
|
|
1623
|
+
return module.id !== null && /[?&]html-proxy\b/.test(module.id);
|
|
1624
|
+
}
|
|
3474
1625
|
async function reloadQuietly(environment, module) {
|
|
3475
1626
|
try {
|
|
3476
|
-
|
|
1627
|
+
if (isInlinedInHtml(module)) environment.hot.send({ type: "full-reload", path: "*" });
|
|
1628
|
+
else await environment.reloadModule(module);
|
|
3477
1629
|
} catch {
|
|
3478
1630
|
}
|
|
3479
1631
|
}
|
|
@@ -3486,7 +1638,7 @@ function reloadStale(context) {
|
|
|
3486
1638
|
const sheet = state.served.get(id);
|
|
3487
1639
|
const module = sheet?.environment.moduleGraph.getModuleById(id);
|
|
3488
1640
|
if (!sheet || !module) continue;
|
|
3489
|
-
state
|
|
1641
|
+
noteReloadSent(state, id);
|
|
3490
1642
|
void reloadQuietly(sheet.environment, module);
|
|
3491
1643
|
}
|
|
3492
1644
|
}
|
|
@@ -3494,12 +1646,26 @@ function isReloading(context, id) {
|
|
|
3494
1646
|
const sent = context.state.reloading.get(id);
|
|
3495
1647
|
return sent !== void 0 && Date.now() - sent < RELOAD_ANSWER_MS;
|
|
3496
1648
|
}
|
|
1649
|
+
function reloadOutgrown(context, ids) {
|
|
1650
|
+
const { state } = context;
|
|
1651
|
+
const atoms = servedAtoms(state, context.kept);
|
|
1652
|
+
for (const id of ids) {
|
|
1653
|
+
const sheet = state.served.get(id);
|
|
1654
|
+
if (sheet && !atoms.isSubsetOf(sheet.atoms) && !isReloading(context, id)) state.stale.add(id);
|
|
1655
|
+
}
|
|
1656
|
+
if (state.stale.size > 0 && state.reloadTimer === void 0 && state.readAhead === 0) {
|
|
1657
|
+
state.reloadTimer = setTimeout(() => {
|
|
1658
|
+
reloadStale(context);
|
|
1659
|
+
}, 0);
|
|
1660
|
+
state.reloadTimer.unref();
|
|
1661
|
+
}
|
|
1662
|
+
}
|
|
3497
1663
|
var devServing = {
|
|
3498
1664
|
modulesWithGrown: modulesWithGrownStylesheets,
|
|
3499
1665
|
async hold(environment, id) {
|
|
3500
1666
|
const module = environment.moduleGraph.getModuleById(id);
|
|
3501
1667
|
if (!module) return;
|
|
3502
|
-
if (module.importers.size === 0) return;
|
|
1668
|
+
if (module.importers.size === 0 && DIRECT.test(id)) return;
|
|
3503
1669
|
await environment.waitForRequestsIdle(id);
|
|
3504
1670
|
await transformReachable(environment, graphRoots(environment));
|
|
3505
1671
|
},
|
|
@@ -3514,19 +1680,22 @@ var devServing = {
|
|
|
3514
1680
|
}
|
|
3515
1681
|
devServing.noteGrowth(context);
|
|
3516
1682
|
},
|
|
3517
|
-
|
|
1683
|
+
noteConnect(context) {
|
|
3518
1684
|
const { state } = context;
|
|
3519
|
-
|
|
3520
|
-
|
|
3521
|
-
|
|
3522
|
-
|
|
3523
|
-
|
|
3524
|
-
|
|
3525
|
-
|
|
3526
|
-
|
|
3527
|
-
|
|
3528
|
-
|
|
3529
|
-
|
|
1685
|
+
state.listening += 1;
|
|
1686
|
+
if (state.unheard.size === 0) return;
|
|
1687
|
+
const ids = [...state.unheard];
|
|
1688
|
+
state.unheard.clear();
|
|
1689
|
+
for (const id of ids) state.reloading.delete(id);
|
|
1690
|
+
reloadOutgrown(context, ids);
|
|
1691
|
+
},
|
|
1692
|
+
noteDisconnect(context) {
|
|
1693
|
+
const { state } = context;
|
|
1694
|
+
state.listening = Math.max(0, state.listening - 1);
|
|
1695
|
+
},
|
|
1696
|
+
noteGrowth(context) {
|
|
1697
|
+
if (context.state.served.size === 0) return;
|
|
1698
|
+
reloadOutgrown(context, context.state.served.keys());
|
|
3530
1699
|
}
|
|
3531
1700
|
};
|
|
3532
1701
|
async function serveStylesheet(context, ctx, stylesheet) {
|
|
@@ -3685,7 +1854,7 @@ function checkServerInvocation(ctx, context) {
|
|
|
3685
1854
|
}
|
|
3686
1855
|
|
|
3687
1856
|
// src/vite-cx-reexported.ts
|
|
3688
|
-
function
|
|
1857
|
+
function declaredNames(pattern) {
|
|
3689
1858
|
const found = [];
|
|
3690
1859
|
const stack = pattern ? [pattern] : [];
|
|
3691
1860
|
while (stack.length > 0) {
|
|
@@ -3693,11 +1862,18 @@ function declaredNames2(pattern) {
|
|
|
3693
1862
|
if (node.type === "Identifier") {
|
|
3694
1863
|
found.push(stringAt(node, "name") ?? "");
|
|
3695
1864
|
} else if (node.type === "AssignmentPattern") {
|
|
3696
|
-
|
|
1865
|
+
pushAll(
|
|
1866
|
+
stack,
|
|
1867
|
+
[nodeAt(node, "left")].filter((part) => part !== void 0)
|
|
1868
|
+
);
|
|
3697
1869
|
} else {
|
|
3698
1870
|
const single = ["argument", "value"].map((key) => nodeAt(node, key));
|
|
3699
1871
|
const lists = ["properties", "elements"].flatMap((key) => nodesAt(node, key));
|
|
3700
|
-
|
|
1872
|
+
pushAll(
|
|
1873
|
+
stack,
|
|
1874
|
+
single.filter((part) => part !== void 0)
|
|
1875
|
+
);
|
|
1876
|
+
pushAll(stack, lists);
|
|
3701
1877
|
}
|
|
3702
1878
|
}
|
|
3703
1879
|
return found;
|
|
@@ -3710,9 +1886,9 @@ function ownExports(program) {
|
|
|
3710
1886
|
if (statement.type !== "ExportNamedDeclaration") continue;
|
|
3711
1887
|
const declaration = nodeAt(statement, "declaration");
|
|
3712
1888
|
const declared = nodesAt(declaration ?? statement, "declarations").flatMap(
|
|
3713
|
-
(declarator) =>
|
|
1889
|
+
(declarator) => declaredNames(nodeAt(declarator, "id"))
|
|
3714
1890
|
);
|
|
3715
|
-
for (const name of [...declared, ...
|
|
1891
|
+
for (const name of [...declared, ...declaredNames(declaration && nodeAt(declaration, "id"))]) {
|
|
3716
1892
|
found.add(name);
|
|
3717
1893
|
}
|
|
3718
1894
|
for (const specifier of nodesAt(statement, "specifiers")) {
|
|
@@ -3741,8 +1917,8 @@ function isImportedFrom(binding, source) {
|
|
|
3741
1917
|
if (!source.reaches.has(binding.source)) return false;
|
|
3742
1918
|
return binding.imported === "*" || source.names.has(binding.imported ?? "");
|
|
3743
1919
|
}
|
|
3744
|
-
function exportedAs(analysis,
|
|
3745
|
-
const parent = analysis.parentOf.get(
|
|
1920
|
+
function exportedAs(analysis, reference) {
|
|
1921
|
+
const parent = analysis.parentOf.get(reference.node);
|
|
3746
1922
|
if (parent?.type === "ExportDefaultDeclaration") return "default";
|
|
3747
1923
|
return parent?.type === "ExportSpecifier" ? exportNameOf(nodeAt(parent, "exported")) : void 0;
|
|
3748
1924
|
}
|
|
@@ -3762,11 +1938,11 @@ function reexportedNames(program, source) {
|
|
|
3762
1938
|
if (node.type === "ExportNamedDeclaration" || node.type === "ExportAllDeclaration") {
|
|
3763
1939
|
for (const name of exportedBy(node, source, own)) found.add(name);
|
|
3764
1940
|
}
|
|
3765
|
-
stack
|
|
1941
|
+
pushAll(stack, childrenOf(node));
|
|
3766
1942
|
}
|
|
3767
1943
|
const analysis = analyze(program);
|
|
3768
|
-
for (const
|
|
3769
|
-
const name = isImportedFrom(
|
|
1944
|
+
for (const reference of analysis.references) {
|
|
1945
|
+
const name = isImportedFrom(reference.binding, source) ? exportedAs(analysis, reference) : void 0;
|
|
3770
1946
|
if (name !== void 0) found.add(name);
|
|
3771
1947
|
}
|
|
3772
1948
|
return [...found];
|
|
@@ -3952,7 +2128,7 @@ function parameterTakes(analysis, callback, names) {
|
|
|
3952
2128
|
for (const { binding, node } of referencesToParameter(analysis, callback, name)) {
|
|
3953
2129
|
const taken = binding?.writes === 0 ? referenceTakes(analysis, node, names) : void 0;
|
|
3954
2130
|
if (taken === void 0) return void 0;
|
|
3955
|
-
found
|
|
2131
|
+
pushAll(found, taken);
|
|
3956
2132
|
}
|
|
3957
2133
|
return found;
|
|
3958
2134
|
}
|
|
@@ -3967,7 +2143,7 @@ function variableTakes(analysis, init, names) {
|
|
|
3967
2143
|
if (binding?.init !== init) continue;
|
|
3968
2144
|
const taken = binding.writes === 0 ? referenceTakes(analysis, node, names) : void 0;
|
|
3969
2145
|
if (taken === void 0) return void 0;
|
|
3970
|
-
found
|
|
2146
|
+
pushAll(found, taken);
|
|
3971
2147
|
}
|
|
3972
2148
|
return found;
|
|
3973
2149
|
}
|
|
@@ -3989,8 +2165,8 @@ function dynamicKeys(analysis, node, names) {
|
|
|
3989
2165
|
var UNREADABLE = { shape: "unreadable", names: [] };
|
|
3990
2166
|
function namespaceTakes(analysis, references, names) {
|
|
3991
2167
|
const found = /* @__PURE__ */ new Set();
|
|
3992
|
-
for (const
|
|
3993
|
-
const taken = referenceTakes(analysis,
|
|
2168
|
+
for (const reference of references) {
|
|
2169
|
+
const taken = referenceTakes(analysis, reference.node, names);
|
|
3994
2170
|
if (taken === void 0) return { shape: "namespace", names: [] };
|
|
3995
2171
|
for (const name of taken) found.add(name);
|
|
3996
2172
|
}
|
|
@@ -4008,8 +2184,8 @@ function usesOf(analysis, source, specifier) {
|
|
|
4008
2184
|
({ binding }) => binding?.kind === "import" && binding.source === source && binding.name === local
|
|
4009
2185
|
);
|
|
4010
2186
|
}
|
|
4011
|
-
function isExportOf(analysis,
|
|
4012
|
-
const parent = analysis.parentOf.get(
|
|
2187
|
+
function isExportOf(analysis, reference) {
|
|
2188
|
+
const parent = analysis.parentOf.get(reference.node);
|
|
4013
2189
|
return parent?.type === "ExportSpecifier" || parent?.type === "ExportDefaultDeclaration";
|
|
4014
2190
|
}
|
|
4015
2191
|
function passingOf(analysis, source, specifier) {
|
|
@@ -4069,8 +2245,8 @@ function takesIn(program, input) {
|
|
|
4069
2245
|
const stack = [program];
|
|
4070
2246
|
while (stack.length > 0) {
|
|
4071
2247
|
const node = stack.pop();
|
|
4072
|
-
found
|
|
4073
|
-
stack
|
|
2248
|
+
pushAll(found, takesOf(node, scan));
|
|
2249
|
+
pushAll(stack, childrenOf(node));
|
|
4074
2250
|
}
|
|
4075
2251
|
return found;
|
|
4076
2252
|
}
|
|
@@ -4164,9 +2340,9 @@ async function takesFrom(ctx, context, input) {
|
|
|
4164
2340
|
resolutions,
|
|
4165
2341
|
wantCalls
|
|
4166
2342
|
});
|
|
4167
|
-
entry
|
|
4168
|
-
told
|
|
4169
|
-
calls
|
|
2343
|
+
pushAll(entry, routes.entry);
|
|
2344
|
+
pushAll(told, routes.told);
|
|
2345
|
+
pushAll(calls, routes.calls);
|
|
4170
2346
|
}
|
|
4171
2347
|
return { entry: merged2(entry), told: merged2(told), calls: merged2(calls) };
|
|
4172
2348
|
}
|
|
@@ -4184,11 +2360,11 @@ function serverRoutes(holder, input) {
|
|
|
4184
2360
|
// src/vite-listed-takes.ts
|
|
4185
2361
|
async function prepareOne(ctx, context, input) {
|
|
4186
2362
|
const { isHop, problems, walk } = input;
|
|
4187
|
-
const
|
|
4188
|
-
const pkg =
|
|
4189
|
-
const names = new Set(problems.flatMap((
|
|
4190
|
-
const hasEntry = !isHop && problems.some((
|
|
4191
|
-
const holders = await holdersOf(ctx, { ...walk, id:
|
|
2363
|
+
const first = problems[0];
|
|
2364
|
+
const pkg = first.pkg;
|
|
2365
|
+
const names = new Set(problems.flatMap((problem) => problem.exportedAs ?? []));
|
|
2366
|
+
const hasEntry = !isHop && problems.some((problem) => problem.specifier !== void 0);
|
|
2367
|
+
const holders = await holdersOf(ctx, { ...walk, id: first.moduleId, names });
|
|
4192
2368
|
const routed = await Promise.all(
|
|
4193
2369
|
holders.map(
|
|
4194
2370
|
(holder) => takesFrom(ctx, context, {
|
|
@@ -4209,15 +2385,15 @@ function decideOne(prepared, serverImports) {
|
|
|
4209
2385
|
(holder) => serverRoutes(holder, { isEntry: hasEntry && !holder.isReached, serverImports })
|
|
4210
2386
|
);
|
|
4211
2387
|
const entry = [...routed.flatMap((route) => route.entry), ...fromServer.flatMap((r) => r.entry)];
|
|
4212
|
-
if (entry.length > 0) return problems.filter((
|
|
2388
|
+
if (entry.length > 0) return problems.filter((problem) => problem.specifier !== void 0);
|
|
4213
2389
|
const told = merged2([
|
|
4214
2390
|
...routed.flatMap((route) => route.told),
|
|
4215
2391
|
...fromServer.flatMap((route) => route.told)
|
|
4216
2392
|
]);
|
|
4217
2393
|
const callers = isHop && !isListed2 ? callersOf(routed) : [];
|
|
4218
2394
|
if (told.length === 0 && callers.length === 0) return [];
|
|
4219
|
-
return problems.map((
|
|
4220
|
-
...
|
|
2395
|
+
return problems.map((problem) => ({
|
|
2396
|
+
...problem,
|
|
4221
2397
|
...told.length > 0 && { takes: told },
|
|
4222
2398
|
...callers.length > 0 && { callers }
|
|
4223
2399
|
}));
|
|
@@ -4227,19 +2403,19 @@ function callersOf(routed) {
|
|
|
4227
2403
|
return [...callers].toSorted(compareText);
|
|
4228
2404
|
}
|
|
4229
2405
|
async function prepareReexports(ctx, context, standingIn) {
|
|
4230
|
-
const exporting = standingIn.filter((
|
|
2406
|
+
const exporting = standingIn.filter((problem) => problem.exportedAs !== void 0);
|
|
4231
2407
|
const located = await withClearingSpecifiers(ctx, context, exporting);
|
|
4232
2408
|
const byModule = /* @__PURE__ */ new Map();
|
|
4233
2409
|
const hops = /* @__PURE__ */ new Map();
|
|
4234
|
-
for (const
|
|
4235
|
-
if (
|
|
4236
|
-
const group = isSecondHop(
|
|
4237
|
-
group.set(
|
|
2410
|
+
for (const problem of located) {
|
|
2411
|
+
if (problem.moduleId === void 0 || problem.pkg === void 0) continue;
|
|
2412
|
+
const group = isSecondHop(problem) ? hops : byModule;
|
|
2413
|
+
group.set(problem.moduleId, [...group.get(problem.moduleId) ?? [], problem]);
|
|
4238
2414
|
}
|
|
4239
2415
|
const cxExports = new Map(
|
|
4240
2416
|
[...byModule.values(), ...hops.values()].map((problems) => [
|
|
4241
2417
|
fileOf(problems[0].moduleId),
|
|
4242
|
-
new Set(problems.flatMap((
|
|
2418
|
+
new Set(problems.flatMap((problem) => problem.exportedAs ?? []))
|
|
4243
2419
|
])
|
|
4244
2420
|
);
|
|
4245
2421
|
const walk = { cxExports, resolutions: /* @__PURE__ */ new Map() };
|
|
@@ -4391,8 +2567,8 @@ function parsed(ctx, id) {
|
|
|
4391
2567
|
function formatOf(ctx) {
|
|
4392
2568
|
const build = ctx.environment.config.build;
|
|
4393
2569
|
const output = build?.rolldownOptions?.output ?? build?.rollupOptions?.output;
|
|
4394
|
-
const
|
|
4395
|
-
return
|
|
2570
|
+
const first = Array.isArray(output) ? output[0] : output;
|
|
2571
|
+
return first?.format;
|
|
4396
2572
|
}
|
|
4397
2573
|
function conditionsOf(ctx) {
|
|
4398
2574
|
return ["node", formatOf(ctx) === "cjs" ? "require" : "import", "module-sync", "default"];
|
|
@@ -4525,39 +2701,7 @@ function warnUnknown(ctx, context, unknown) {
|
|
|
4525
2701
|
}
|
|
4526
2702
|
|
|
4527
2703
|
// src/vite-collect-plugin.ts
|
|
4528
|
-
|
|
4529
|
-
if (record.pkg === void 0) return context.options.keep;
|
|
4530
|
-
const { keepFor } = context.options;
|
|
4531
|
-
return Object.hasOwn(keepFor, record.pkg) ? keepFor[record.pkg] : [];
|
|
4532
|
-
}
|
|
4533
|
-
function dynamicProblems(record, context) {
|
|
4534
|
-
const isCovered = listedAtomsOf(record, context).length > 0;
|
|
4535
|
-
if (isCovered) return [];
|
|
4536
|
-
return record.dynamicCalls.map((call) => ({
|
|
4537
|
-
kind: "dynamic",
|
|
4538
|
-
offset: 0,
|
|
4539
|
-
construct: call.construct,
|
|
4540
|
-
text: "",
|
|
4541
|
-
file: call.file,
|
|
4542
|
-
line: call.line,
|
|
4543
|
-
column: call.column,
|
|
4544
|
-
pkg: record.pkg,
|
|
4545
|
-
...call.unknownLine !== void 0 && { unknownLine: call.unknownLine }
|
|
4546
|
-
}));
|
|
4547
|
-
}
|
|
4548
|
-
function problemsOf(record, context) {
|
|
4549
|
-
return [...record.problems, ...dynamicProblems(record, context)];
|
|
4550
|
-
}
|
|
4551
|
-
function failModule(ctx, context, input) {
|
|
4552
|
-
const { id, problems } = input;
|
|
4553
|
-
const message = moduleReport(problems, context.options.cxModules);
|
|
4554
|
-
const first2 = problems[0];
|
|
4555
|
-
return ctx.error({
|
|
4556
|
-
message,
|
|
4557
|
-
id,
|
|
4558
|
-
loc: { file: id, line: Math.max(first2.line, 1), column: Math.max(first2.column - 1, 0) }
|
|
4559
|
-
});
|
|
4560
|
-
}
|
|
2704
|
+
var OPTIONS_HOME = "navePlugin()";
|
|
4561
2705
|
function isReadable(context, id) {
|
|
4562
2706
|
return isUsed(context) && !isStylesheetId(id) && !isNaveOwn(id);
|
|
4563
2707
|
}
|
|
@@ -4571,34 +2715,35 @@ async function problemsOfBuild(ctx, context, serverImports) {
|
|
|
4571
2715
|
onlyVia: record.onlyVia,
|
|
4572
2716
|
problems: [
|
|
4573
2717
|
...problemsOf(record, context),
|
|
4574
|
-
...record.suppressed.filter((
|
|
2718
|
+
...record.suppressed.filter((problem) => problem.kind === "declared")
|
|
4575
2719
|
]
|
|
4576
2720
|
}))
|
|
4577
2721
|
)
|
|
4578
2722
|
);
|
|
4579
2723
|
const standingIn = [
|
|
4580
2724
|
...records.flatMap((record) => record.suppressed),
|
|
4581
|
-
...kept.filter((
|
|
2725
|
+
...kept.filter((problem) => isSecondHop(problem))
|
|
4582
2726
|
];
|
|
4583
|
-
const rest = kept.filter((
|
|
2727
|
+
const rest = kept.filter((problem) => !isSecondHop(problem));
|
|
4584
2728
|
const prepared = await prepareReexports(ctx, context, standingIn);
|
|
4585
2729
|
return { problems: [...rest, ...decideReexports(prepared, serverImports)], prepared };
|
|
4586
2730
|
}
|
|
4587
2731
|
function reportOf(context, problems) {
|
|
4588
|
-
const
|
|
4589
|
-
const recorded = problems.flatMap((
|
|
2732
|
+
const report = buildReport(problems, context.options.cxModules, OPTIONS_HOME);
|
|
2733
|
+
const recorded = problems.flatMap((problem) => problem.takes ?? []).filter((take) => take.isRecorded === true).map((take) => take.taker);
|
|
4590
2734
|
const note = recordedSentence(recorded);
|
|
4591
|
-
return note === void 0 ?
|
|
2735
|
+
return note === void 0 ? report : `${report}
|
|
4592
2736
|
${note}`;
|
|
4593
2737
|
}
|
|
4594
2738
|
async function failuresOf(ctx, context, serverImports) {
|
|
4595
2739
|
const { problems, prepared } = await problemsOfBuild(ctx, context, serverImports);
|
|
4596
|
-
const
|
|
2740
|
+
const report = problems.length > 0 ? reportOf(context, problems) : void 0;
|
|
4597
2741
|
const importers = await declaredImporterError(ctx, context, {
|
|
4598
2742
|
configured: withoutRemoved(problems, context.options.cxModules),
|
|
4599
|
-
|
|
2743
|
+
home: OPTIONS_HOME,
|
|
2744
|
+
report
|
|
4600
2745
|
});
|
|
4601
|
-
return { failures: [
|
|
2746
|
+
return { failures: [report, importers].filter((failure) => failure !== void 0), prepared };
|
|
4602
2747
|
}
|
|
4603
2748
|
function serverImportsForClient(ctx, context, graph) {
|
|
4604
2749
|
if (ctx.environment.config.consumer !== "client") return { known: [], unknown: [] };
|
|
@@ -4636,9 +2781,8 @@ function createCollectPlugin(context) {
|
|
|
4636
2781
|
if (this.environment?.config.consumer === "server") context.state.serverTransformed = true;
|
|
4637
2782
|
const record = await recordModule(context, this, { code, id, moduleType: meta?.moduleType });
|
|
4638
2783
|
if (context.command === "serve") devServing.noteGrowth(context);
|
|
4639
|
-
if (
|
|
4640
|
-
|
|
4641
|
-
if (problems.length > 0) failModule(this, context, { id, problems });
|
|
2784
|
+
if (record?.edits) return applyEdits(code, id, record.edits);
|
|
2785
|
+
if (record) failDevModule(this, context, { home: OPTIONS_HOME, id, record });
|
|
4642
2786
|
},
|
|
4643
2787
|
transformIndexHtml: {
|
|
4644
2788
|
order: "pre",
|
|
@@ -4673,55 +2817,6 @@ function createCollectPlugin(context) {
|
|
|
4673
2817
|
return plugin;
|
|
4674
2818
|
}
|
|
4675
2819
|
|
|
4676
|
-
// src/vite-dev-keep.ts
|
|
4677
|
-
var KEEP_CONSTANT = "__NAVE_KEEP_CLASSES__";
|
|
4678
|
-
function keepMap(kept) {
|
|
4679
|
-
return Object.fromEntries(
|
|
4680
|
-
kept.filter((atom) => Object.hasOwn(atomClassMap, atom)).map((atom) => [atom, atomClassMap[atom]])
|
|
4681
|
-
);
|
|
4682
|
-
}
|
|
4683
|
-
function devKeepMap(map, atoms) {
|
|
4684
|
-
return new Proxy(map, {
|
|
4685
|
-
getOwnPropertyDescriptor(target, key) {
|
|
4686
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(target, key);
|
|
4687
|
-
if (descriptor === void 0 && typeof key === "string") {
|
|
4688
|
-
const quoted2 = JSON.stringify(key);
|
|
4689
|
-
console.error(
|
|
4690
|
-
atoms.includes(key) ? `[nave] cx.dynamic(${quoted2}) applied no class: ${quoted2} is not in keep or in a keepFor list, and navePlugin() gives cx.dynamic() only the atoms in those lists, in a build as in dev. Add ${quoted2} to keep in navePlugin(), or, when a dependency makes the call, to its list in keepFor.` : `[nave] cx.dynamic(${quoted2}) applied no class: ${quoted2} is not a Nave atom.`
|
|
4691
|
-
);
|
|
4692
|
-
}
|
|
4693
|
-
return descriptor;
|
|
4694
|
-
}
|
|
4695
|
-
});
|
|
4696
|
-
}
|
|
4697
|
-
function devKeepExpression(map, atoms) {
|
|
4698
|
-
return `(${devKeepMap.toString()})(${JSON.stringify(map)}, ${JSON.stringify(atoms)})`;
|
|
4699
|
-
}
|
|
4700
|
-
var installs = [];
|
|
4701
|
-
var baseline = { held: false, value: void 0 };
|
|
4702
|
-
function publish() {
|
|
4703
|
-
const newest = installs.at(-1);
|
|
4704
|
-
if (newest !== void 0) Object.assign(globalThis, { [KEEP_CONSTANT]: newest.map });
|
|
4705
|
-
else if (baseline.held) Object.assign(globalThis, { [KEEP_CONSTANT]: baseline.value });
|
|
4706
|
-
else Reflect.deleteProperty(globalThis, KEEP_CONSTANT);
|
|
4707
|
-
}
|
|
4708
|
-
function installServerKeepMap(context, owner) {
|
|
4709
|
-
if (context.options.atomic !== "used") return;
|
|
4710
|
-
const map = devKeepMap(keepMap(context.kept), Object.keys(atomClassMap));
|
|
4711
|
-
if (installs.length === 0) {
|
|
4712
|
-
baseline.held = Object.hasOwn(globalThis, KEEP_CONSTANT);
|
|
4713
|
-
baseline.value = globalThis[KEEP_CONSTANT];
|
|
4714
|
-
}
|
|
4715
|
-
installs.push({ owner, map });
|
|
4716
|
-
publish();
|
|
4717
|
-
}
|
|
4718
|
-
function removeServerKeepMap(owner) {
|
|
4719
|
-
const index = installs.findIndex((install) => install.owner === owner);
|
|
4720
|
-
if (index === -1) return;
|
|
4721
|
-
installs.splice(index, 1);
|
|
4722
|
-
publish();
|
|
4723
|
-
}
|
|
4724
|
-
|
|
4725
2820
|
// src/vite-worker-collect.ts
|
|
4726
2821
|
function workerCollectPlugins(context) {
|
|
4727
2822
|
const plugin = {
|
|
@@ -4729,7 +2824,8 @@ function workerCollectPlugins(context) {
|
|
|
4729
2824
|
enforce: "post",
|
|
4730
2825
|
async transform(code, id, meta) {
|
|
4731
2826
|
if (!isReadable(context, id)) return;
|
|
4732
|
-
await recordModule(context, this, { code, id, moduleType: meta?.moduleType });
|
|
2827
|
+
const record = await recordModule(context, this, { code, id, moduleType: meta?.moduleType });
|
|
2828
|
+
if (record?.edits) return applyEdits(code, id, record.edits);
|
|
4733
2829
|
},
|
|
4734
2830
|
async buildEnd(error) {
|
|
4735
2831
|
if (error || !isUsed(context) || context.command !== "build") return;
|
|
@@ -4855,7 +2951,7 @@ function warnTextImports(ctx, chunk, context, emitted) {
|
|
|
4855
2951
|
);
|
|
4856
2952
|
}
|
|
4857
2953
|
}
|
|
4858
|
-
function
|
|
2954
|
+
function textOf(entry) {
|
|
4859
2955
|
const { source } = entry;
|
|
4860
2956
|
if (source === void 0) return "";
|
|
4861
2957
|
return typeof source === "string" ? source : decoder.decode(source);
|
|
@@ -4883,7 +2979,7 @@ function mismatchLines(assets, emitted) {
|
|
|
4883
2979
|
return lines;
|
|
4884
2980
|
}
|
|
4885
2981
|
function checkAtomicLayers(ctx, bundle, emitted) {
|
|
4886
|
-
const assets = Object.values(bundle).filter((entry) => entry.type === "asset" && entry.fileName.toLowerCase().endsWith(".css")).map((entry) => ({ fileName: entry.fileName, css:
|
|
2982
|
+
const assets = Object.values(bundle).filter((entry) => entry.type === "asset" && entry.fileName.toLowerCase().endsWith(".css")).map((entry) => ({ fileName: entry.fileName, css: textOf(entry) }));
|
|
4887
2983
|
const lines = mismatchLines(assets, emitted);
|
|
4888
2984
|
if (lines.length === 0) return;
|
|
4889
2985
|
ctx.error({
|
|
@@ -4956,22 +3052,22 @@ var decoder2 = new TextDecoder();
|
|
|
4956
3052
|
function isCssAsset(entry) {
|
|
4957
3053
|
return entry.type === "asset" && entry.fileName.toLowerCase().endsWith(".css");
|
|
4958
3054
|
}
|
|
4959
|
-
function
|
|
3055
|
+
function textOf2(entry) {
|
|
4960
3056
|
const { source } = entry;
|
|
4961
3057
|
if (source === void 0) return "";
|
|
4962
3058
|
return typeof source === "string" ? source : decoder2.decode(source);
|
|
4963
3059
|
}
|
|
4964
3060
|
function messageFor(findings, assetCount) {
|
|
4965
|
-
const
|
|
3061
|
+
const noun = assetCount === 1 ? "asset" : "assets";
|
|
4966
3062
|
return [
|
|
4967
3063
|
"@nave survived into the built CSS:",
|
|
4968
3064
|
...findings.map((finding) => formatFinding(finding)),
|
|
4969
|
-
`Scanned ${assetCount} CSS ${
|
|
3065
|
+
`Scanned ${assetCount} CSS ${noun} this build wrote.`
|
|
4970
3066
|
].join("\n");
|
|
4971
3067
|
}
|
|
4972
3068
|
function scanBundle(ctx, bundle) {
|
|
4973
3069
|
const assets = Object.values(bundle).filter((entry) => isCssAsset(entry));
|
|
4974
|
-
const findings = assets.flatMap((asset) => findingsInText(asset.fileName,
|
|
3070
|
+
const findings = assets.flatMap((asset) => findingsInText(asset.fileName, textOf2(asset)));
|
|
4975
3071
|
if (findings.length > 0) ctx.error({ message: messageFor(findings, assets.length) });
|
|
4976
3072
|
}
|
|
4977
3073
|
|
|
@@ -4988,8 +3084,18 @@ function serverHooks(context) {
|
|
|
4988
3084
|
const owner = devServer.environments.client;
|
|
4989
3085
|
installServerKeepMap(context, owner);
|
|
4990
3086
|
const close = devServer.close.bind(devServer);
|
|
3087
|
+
const noteConnect = () => {
|
|
3088
|
+
devServing.noteConnect(context);
|
|
3089
|
+
};
|
|
3090
|
+
const noteDisconnect = () => {
|
|
3091
|
+
devServing.noteDisconnect(context);
|
|
3092
|
+
};
|
|
3093
|
+
owner.hot.on("vite:client:connect", noteConnect);
|
|
3094
|
+
owner.hot.on("vite:client:disconnect", noteDisconnect);
|
|
4991
3095
|
devServer.close = () => {
|
|
4992
3096
|
removeServerKeepMap(owner);
|
|
3097
|
+
owner.hot.off("vite:client:connect", noteConnect);
|
|
3098
|
+
owner.hot.off("vite:client:disconnect", noteDisconnect);
|
|
4993
3099
|
return close();
|
|
4994
3100
|
};
|
|
4995
3101
|
noteStylesheetRequests(context, devServer);
|
|
@@ -5060,9 +3166,9 @@ function reportDiagnostics(input) {
|
|
|
5060
3166
|
}
|
|
5061
3167
|
return;
|
|
5062
3168
|
}
|
|
5063
|
-
const
|
|
5064
|
-
const message = withNoMapNote(`${frame(
|
|
5065
|
-
input.ctx.error(logFor(message, input,
|
|
3169
|
+
const first = located[0];
|
|
3170
|
+
const message = withNoMapNote(`${frame(first)}${foldLocated(located)}`, input, first);
|
|
3171
|
+
input.ctx.error(logFor(message, input, first));
|
|
5066
3172
|
}
|
|
5067
3173
|
|
|
5068
3174
|
// src/vite-transform.ts
|