@barefootjs/cli 0.28.0 → 0.29.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/dist/index.js +525 -392
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -5553,6 +5553,13 @@ var init_errors = __esm({
|
|
|
5553
5553
|
// so an unimported tag with the built-in name is either a forgotten import
|
|
5554
5554
|
// or an undeclared component — fail loud with the import to add.
|
|
5555
5555
|
BUILTIN_REQUIRES_IMPORT: "BF054",
|
|
5556
|
+
// A relative `.ts` module inlined into a client bundle (`resolveRelativeImports`'s
|
|
5557
|
+
// top-level IIFE wrap) was asked for a name it does not export. The IIFE's
|
|
5558
|
+
// `return { … }` has no binding for that name, so the reference throws
|
|
5559
|
+
// `ReferenceError: <name> is not defined` at load — killing the page's
|
|
5560
|
+
// client JS before hydrate. Fail the build instead of shipping the
|
|
5561
|
+
// dangling reference (#2432).
|
|
5562
|
+
INLINED_IMPORT_MISSING_EXPORT: "BF055",
|
|
5556
5563
|
// Init statement errors (BF052)
|
|
5557
5564
|
UNDECLARED_INIT_STATEMENT_REFERENCE: "BF052",
|
|
5558
5565
|
// Stripped-import diagnostics (BF053) — a relative import was removed
|
|
@@ -5614,6 +5621,7 @@ var init_errors = __esm({
|
|
|
5614
5621
|
[ErrorCodes.BUILTIN_REQUIRES_IMPORT]: "Built-in <Async> / <Region> must be imported from '@barefootjs/client'. The compiler recognises these tags by their import (not by tag name), so an unimported tag with this name is treated as an undeclared component.",
|
|
5615
5622
|
[ErrorCodes.UNDECLARED_INIT_STATEMENT_REFERENCE]: "Init statement references an undeclared identifier. Declare it at module scope, inside the component, or import it \u2014 otherwise ESM strict mode throws ReferenceError at runtime.",
|
|
5616
5623
|
[ErrorCodes.STRIPPED_CLIENT_IMPORT_REFERENCED]: "Import was stripped from the client bundle but its binding is still referenced. Client components ('use client' .tsx) are not callable as plain functions from imperative .ts modules \u2014 render them as JSX from a 'use client' parent instead. If the flagged name is a local shadow rather than the stripped import, please file an issue.",
|
|
5624
|
+
[ErrorCodes.INLINED_IMPORT_MISSING_EXPORT]: "An inlined relative import requests a name the target module does not export. The client bundle would throw ReferenceError at load.",
|
|
5617
5625
|
[ErrorCodes.STAGE_REACTIVE_IN_TEMPLATE]: "Reactive binding (signal getter or memo) referenced from template scope. The template lambda runs at module scope without the reactive context, so the value cannot be evaluated at SSR. Wrap the JSX expression in /* @client */ to defer it to hydrate, or restructure so the template uses a prop or static value.",
|
|
5618
5626
|
[ErrorCodes.STAGE_INIT_LOCAL_IN_TEMPLATE]: "Init-scope local referenced from template scope. The template lambda runs at module scope (via render() / renderChild()) and cannot reach init-body locals. Wrap the JSX expression in /* @client */, or lift the value to a prop or module-scope const.",
|
|
5619
5627
|
[ErrorCodes.STAGE_AWAIT_IN_TEMPLATE]: "AwaitExpression in template scope. The generated template and init functions are synchronous \u2014 a bare `await` produces a SyntaxError at parse time. Move the await into the component body (before the return) or into an onMount/effect callback, and pass the resolved value to JSX.",
|
|
@@ -7874,6 +7882,7 @@ function importsBrowserOnlyClientApi(ctx2) {
|
|
|
7874
7882
|
if (imp.source !== "@barefootjs/client") continue;
|
|
7875
7883
|
if (imp.isTypeOnly) continue;
|
|
7876
7884
|
for (const spec of imp.specifiers) {
|
|
7885
|
+
if (spec.isTypeOnly) continue;
|
|
7877
7886
|
const importedName = spec.name;
|
|
7878
7887
|
if (BROWSER_ONLY_CLIENT_APIS.has(importedName)) return true;
|
|
7879
7888
|
}
|
|
@@ -13938,7 +13947,7 @@ function emitTemplateCloneLines(template, indent) {
|
|
|
13938
13947
|
];
|
|
13939
13948
|
}
|
|
13940
13949
|
function emitLoopItemElementSetup(lines, opts) {
|
|
13941
|
-
const { template, bodyIsMultiRoot, indent, singleRootLayout } = opts;
|
|
13950
|
+
const { template, bodyIsMultiRoot, indent, singleRootLayout, mountRow } = opts;
|
|
13942
13951
|
const innerIndent = indent + " ";
|
|
13943
13952
|
if (bodyIsMultiRoot) {
|
|
13944
13953
|
lines.push(`${indent}let __el, __extras`);
|
|
@@ -13949,17 +13958,19 @@ function emitLoopItemElementSetup(lines, opts) {
|
|
|
13949
13958
|
lines.push(ln);
|
|
13950
13959
|
}
|
|
13951
13960
|
lines.push(`${innerIndent}__el.__bfExtras = __extras`);
|
|
13961
|
+
if (mountRow) lines.push(`${innerIndent}mountRowRoot(__el)`);
|
|
13952
13962
|
lines.push(`${indent}}`);
|
|
13953
13963
|
return;
|
|
13954
13964
|
}
|
|
13955
13965
|
if (singleRootLayout === "inline") {
|
|
13956
13966
|
const cloneExpr = emitTemplateCloneInline(template);
|
|
13957
|
-
|
|
13967
|
+
const clone2 = `__existing ?? (() => { ${cloneExpr} })()`;
|
|
13968
|
+
lines.push(`${indent}const __el = ${mountRow ? `__existing ?? mountRowRoot((() => { ${cloneExpr} })())` : clone2}`);
|
|
13958
13969
|
return;
|
|
13959
13970
|
}
|
|
13960
|
-
lines.push(`${indent}const __el = __existing ?? (() => {`);
|
|
13971
|
+
lines.push(`${indent}const __el = __existing ?? ${mountRow ? "mountRowRoot(" : ""}(() => {`);
|
|
13961
13972
|
for (const ln of emitTemplateCloneLines(template, innerIndent)) lines.push(ln);
|
|
13962
|
-
lines.push(`${indent}})()`);
|
|
13973
|
+
lines.push(`${indent}})()${mountRow ? ")" : ""}`);
|
|
13963
13974
|
}
|
|
13964
13975
|
function emitMultiRootTemplateCloneLines(template, indent, varEl, varExtras) {
|
|
13965
13976
|
const isSvg = multiRootTemplateNeedsSvgWrap(template);
|
|
@@ -15274,6 +15285,66 @@ var init_compute_prop_usage = __esm({
|
|
|
15274
15285
|
}
|
|
15275
15286
|
});
|
|
15276
15287
|
|
|
15288
|
+
// ../jsx/src/value-references.ts
|
|
15289
|
+
import ts13 from "typescript";
|
|
15290
|
+
function isValueReferenceIdentifier(id2) {
|
|
15291
|
+
const parent2 = id2.parent;
|
|
15292
|
+
if (!parent2) return false;
|
|
15293
|
+
if (ts13.isPropertyAccessExpression(parent2) && parent2.name === id2) return false;
|
|
15294
|
+
if (ts13.isPropertyAssignment(parent2) && parent2.name === id2) return false;
|
|
15295
|
+
if ((ts13.isMethodDeclaration(parent2) || ts13.isGetAccessorDeclaration(parent2) || ts13.isSetAccessorDeclaration(parent2)) && parent2.name === id2) {
|
|
15296
|
+
return false;
|
|
15297
|
+
}
|
|
15298
|
+
if (ts13.isPropertyDeclaration(parent2) && parent2.name === id2) return false;
|
|
15299
|
+
if (ts13.isMetaProperty(parent2) && parent2.name === id2) return false;
|
|
15300
|
+
if (ts13.isVariableDeclaration(parent2) && parent2.name === id2) return false;
|
|
15301
|
+
if (ts13.isFunctionDeclaration(parent2) && parent2.name === id2) return false;
|
|
15302
|
+
if (ts13.isFunctionExpression(parent2) && parent2.name === id2) return false;
|
|
15303
|
+
if (ts13.isClassDeclaration(parent2) && parent2.name === id2) return false;
|
|
15304
|
+
if (ts13.isClassExpression(parent2) && parent2.name === id2) return false;
|
|
15305
|
+
if (ts13.isParameter(parent2) && parent2.name === id2) return false;
|
|
15306
|
+
if (ts13.isBindingElement(parent2) && (parent2.name === id2 || parent2.propertyName === id2)) return false;
|
|
15307
|
+
if (ts13.isLabeledStatement(parent2) && parent2.label === id2) return false;
|
|
15308
|
+
if (ts13.isBreakOrContinueStatement(parent2) && parent2.label === id2) return false;
|
|
15309
|
+
if (ts13.isImportSpecifier(parent2) && (parent2.name === id2 || parent2.propertyName === id2)) return false;
|
|
15310
|
+
if (ts13.isExportSpecifier(parent2) && (parent2.name === id2 || parent2.propertyName === id2)) return false;
|
|
15311
|
+
if (ts13.isImportClause(parent2) && parent2.name === id2) return false;
|
|
15312
|
+
if (ts13.isNamespaceImport(parent2) && parent2.name === id2) return false;
|
|
15313
|
+
if (ts13.isQualifiedName(parent2) && parent2.right === id2) return false;
|
|
15314
|
+
return true;
|
|
15315
|
+
}
|
|
15316
|
+
function collectValueReferencedNames(code) {
|
|
15317
|
+
let sourceFile;
|
|
15318
|
+
try {
|
|
15319
|
+
sourceFile = ts13.createSourceFile(
|
|
15320
|
+
"generated.js",
|
|
15321
|
+
code,
|
|
15322
|
+
ts13.ScriptTarget.Latest,
|
|
15323
|
+
/*setParentNodes*/
|
|
15324
|
+
true,
|
|
15325
|
+
ts13.ScriptKind.JS
|
|
15326
|
+
);
|
|
15327
|
+
} catch {
|
|
15328
|
+
return null;
|
|
15329
|
+
}
|
|
15330
|
+
const diagnostics = sourceFile.parseDiagnostics;
|
|
15331
|
+
if (diagnostics && diagnostics.length > 0) return null;
|
|
15332
|
+
const names = /* @__PURE__ */ new Set();
|
|
15333
|
+
function visit3(node) {
|
|
15334
|
+
if (ts13.isIdentifier(node) && isValueReferenceIdentifier(node)) {
|
|
15335
|
+
names.add(node.text);
|
|
15336
|
+
}
|
|
15337
|
+
ts13.forEachChild(node, visit3);
|
|
15338
|
+
}
|
|
15339
|
+
visit3(sourceFile);
|
|
15340
|
+
return names;
|
|
15341
|
+
}
|
|
15342
|
+
var init_value_references = __esm({
|
|
15343
|
+
"../jsx/src/value-references.ts"() {
|
|
15344
|
+
"use strict";
|
|
15345
|
+
}
|
|
15346
|
+
});
|
|
15347
|
+
|
|
15277
15348
|
// ../jsx/src/ir-to-client-js/imports.ts
|
|
15278
15349
|
function detectUsedImports(code) {
|
|
15279
15350
|
const used = /* @__PURE__ */ new Set();
|
|
@@ -15299,7 +15370,7 @@ function collectUserDomImports(ir) {
|
|
|
15299
15370
|
for (const imp of ir.metadata.imports) {
|
|
15300
15371
|
if (runtimeSources.has(imp.source) && !imp.isTypeOnly) {
|
|
15301
15372
|
for (const spec of imp.specifiers) {
|
|
15302
|
-
if (!spec.isDefault && !spec.isNamespace) {
|
|
15373
|
+
if (!spec.isDefault && !spec.isNamespace && !spec.isTypeOnly) {
|
|
15303
15374
|
if (isClientBuiltinName(spec.name)) continue;
|
|
15304
15375
|
userImports.push(spec.alias ? `${spec.name} as ${spec.alias}` : spec.name);
|
|
15305
15376
|
}
|
|
@@ -15308,9 +15379,22 @@ function collectUserDomImports(ir) {
|
|
|
15308
15379
|
}
|
|
15309
15380
|
return userImports;
|
|
15310
15381
|
}
|
|
15382
|
+
function makeValueUsageTest(generatedCode) {
|
|
15383
|
+
let referenced;
|
|
15384
|
+
return (localName2) => {
|
|
15385
|
+
if (referenced === void 0) {
|
|
15386
|
+
referenced = collectValueReferencedNames(generatedCode);
|
|
15387
|
+
}
|
|
15388
|
+
if (referenced !== null) {
|
|
15389
|
+
return referenced.has(localName2);
|
|
15390
|
+
}
|
|
15391
|
+
return generatedCode.includes(localName2);
|
|
15392
|
+
};
|
|
15393
|
+
}
|
|
15311
15394
|
function collectExternalImports(ir, generatedCode, localImportPrefixes) {
|
|
15312
15395
|
const componentNames = collectComponentNames(ir.root);
|
|
15313
15396
|
const importLines = [];
|
|
15397
|
+
const isUsedAsValue = makeValueUsageTest(generatedCode);
|
|
15314
15398
|
for (const imp of ir.metadata.imports) {
|
|
15315
15399
|
if (imp.isTypeOnly) continue;
|
|
15316
15400
|
if (imp.source === "@barefootjs/client" || imp.source === RUNTIME_MODULE) continue;
|
|
@@ -15321,9 +15405,10 @@ function collectExternalImports(ir, generatedCode, localImportPrefixes) {
|
|
|
15321
15405
|
}
|
|
15322
15406
|
const usedSpecs = [];
|
|
15323
15407
|
for (const spec of imp.specifiers) {
|
|
15408
|
+
if (spec.isTypeOnly) continue;
|
|
15324
15409
|
const localName2 = spec.alias || spec.name;
|
|
15325
15410
|
if (componentNames.has(localName2)) continue;
|
|
15326
|
-
if (
|
|
15411
|
+
if (isUsedAsValue(localName2)) {
|
|
15327
15412
|
usedSpecs.push(spec.alias ? `${spec.name} as ${spec.alias}` : spec.name);
|
|
15328
15413
|
}
|
|
15329
15414
|
}
|
|
@@ -15363,6 +15448,7 @@ var init_imports = __esm({
|
|
|
15363
15448
|
"../jsx/src/ir-to-client-js/imports.ts"() {
|
|
15364
15449
|
"use strict";
|
|
15365
15450
|
init_builtins();
|
|
15451
|
+
init_value_references();
|
|
15366
15452
|
RUNTIME_IMPORT_CANDIDATES = [
|
|
15367
15453
|
"createSignal",
|
|
15368
15454
|
"createMemo",
|
|
@@ -15384,6 +15470,11 @@ var init_imports = __esm({
|
|
|
15384
15470
|
"registerTemplate",
|
|
15385
15471
|
"initChild",
|
|
15386
15472
|
"upsertChild",
|
|
15473
|
+
// Connects a template-clone loop row before the body's tail runs, so a child
|
|
15474
|
+
// that inits inside it resolves context against real ancestors rather than
|
|
15475
|
+
// falling through to the global store. The clone-root counterpart of the
|
|
15476
|
+
// mount point `createComponent` consumes for component-root rows.
|
|
15477
|
+
"mountRowRoot",
|
|
15387
15478
|
"createPortal",
|
|
15388
15479
|
"provideContext",
|
|
15389
15480
|
"createContext",
|
|
@@ -15475,23 +15566,23 @@ var init_lowering_registry = __esm({
|
|
|
15475
15566
|
});
|
|
15476
15567
|
|
|
15477
15568
|
// ../jsx/src/relocate.ts
|
|
15478
|
-
import
|
|
15569
|
+
import ts14 from "typescript";
|
|
15479
15570
|
function classify(name2, env) {
|
|
15480
15571
|
return env.bindings.get(name2) ?? "global";
|
|
15481
15572
|
}
|
|
15482
15573
|
function collectFreeRefs(node) {
|
|
15483
15574
|
const refs = /* @__PURE__ */ new Map();
|
|
15484
15575
|
function visit3(n, parent2) {
|
|
15485
|
-
if (
|
|
15486
|
-
if (parent2 &&
|
|
15487
|
-
if (parent2 &&
|
|
15488
|
-
if (parent2 &&
|
|
15576
|
+
if (ts14.isIdentifier(n)) {
|
|
15577
|
+
if (parent2 && ts14.isPropertyAccessExpression(parent2) && parent2.name === n) return;
|
|
15578
|
+
if (parent2 && ts14.isPropertyAssignment(parent2) && parent2.name === n) return;
|
|
15579
|
+
if (parent2 && ts14.isShorthandPropertyAssignment(parent2) && parent2.name === n) return;
|
|
15489
15580
|
const list = refs.get(n.text) ?? [];
|
|
15490
15581
|
list.push(n);
|
|
15491
15582
|
refs.set(n.text, list);
|
|
15492
15583
|
return;
|
|
15493
15584
|
}
|
|
15494
|
-
|
|
15585
|
+
ts14.forEachChild(n, (child) => visit3(child, n));
|
|
15495
15586
|
}
|
|
15496
15587
|
visit3(node);
|
|
15497
15588
|
return refs;
|
|
@@ -15592,9 +15683,9 @@ function isInlinableInTemplate(value2, env) {
|
|
|
15592
15683
|
return { ok: true, rewrittenValue: r2.text, decisions: r2.decisions };
|
|
15593
15684
|
}
|
|
15594
15685
|
function getCalleeIdentifierPath(callee) {
|
|
15595
|
-
if (
|
|
15596
|
-
if (
|
|
15597
|
-
if (
|
|
15686
|
+
if (ts14.isParenthesizedExpression(callee)) return getCalleeIdentifierPath(callee.expression);
|
|
15687
|
+
if (ts14.isIdentifier(callee)) return callee.text;
|
|
15688
|
+
if (ts14.isPropertyAccessExpression(callee)) {
|
|
15598
15689
|
const left = getCalleeIdentifierPath(callee.expression);
|
|
15599
15690
|
if (left === null) return null;
|
|
15600
15691
|
return `${left}.${callee.name.text}`;
|
|
@@ -15602,9 +15693,9 @@ function getCalleeIdentifierPath(callee) {
|
|
|
15602
15693
|
return null;
|
|
15603
15694
|
}
|
|
15604
15695
|
function getCalleeLeftmostIdentifier(callee) {
|
|
15605
|
-
if (
|
|
15606
|
-
if (
|
|
15607
|
-
if (
|
|
15696
|
+
if (ts14.isParenthesizedExpression(callee)) return getCalleeLeftmostIdentifier(callee.expression);
|
|
15697
|
+
if (ts14.isIdentifier(callee)) return callee.text;
|
|
15698
|
+
if (ts14.isPropertyAccessExpression(callee)) {
|
|
15608
15699
|
return getCalleeLeftmostIdentifier(callee.expression);
|
|
15609
15700
|
}
|
|
15610
15701
|
return null;
|
|
@@ -15643,17 +15734,17 @@ function isCallAcceptedByAdapter(call, env) {
|
|
|
15643
15734
|
}
|
|
15644
15735
|
function parseExpressionNode(text) {
|
|
15645
15736
|
try {
|
|
15646
|
-
const sf =
|
|
15737
|
+
const sf = ts14.createSourceFile(
|
|
15647
15738
|
"__inline_check__.ts",
|
|
15648
15739
|
`(${text});`,
|
|
15649
|
-
|
|
15740
|
+
ts14.ScriptTarget.Latest,
|
|
15650
15741
|
false,
|
|
15651
|
-
|
|
15742
|
+
ts14.ScriptKind.TS
|
|
15652
15743
|
);
|
|
15653
15744
|
const stmt = sf.statements[0];
|
|
15654
|
-
if (!stmt || !
|
|
15745
|
+
if (!stmt || !ts14.isExpressionStatement(stmt)) return null;
|
|
15655
15746
|
const inner = stmt.expression;
|
|
15656
|
-
return
|
|
15747
|
+
return ts14.isParenthesizedExpression(inner) ? inner.expression : inner;
|
|
15657
15748
|
} catch {
|
|
15658
15749
|
return null;
|
|
15659
15750
|
}
|
|
@@ -15667,8 +15758,8 @@ function hasCallWithBridgedArg(node, decisions, env) {
|
|
|
15667
15758
|
let found = false;
|
|
15668
15759
|
function visit3(n) {
|
|
15669
15760
|
if (found) return;
|
|
15670
|
-
if (
|
|
15671
|
-
const accepted =
|
|
15761
|
+
if (ts14.isCallExpression(n) || ts14.isNewExpression(n)) {
|
|
15762
|
+
const accepted = ts14.isCallExpression(n) && isCallAcceptedByAdapter(n, env);
|
|
15672
15763
|
if (!accepted) {
|
|
15673
15764
|
const args2 = n.arguments;
|
|
15674
15765
|
if (args2) {
|
|
@@ -15681,7 +15772,7 @@ function hasCallWithBridgedArg(node, decisions, env) {
|
|
|
15681
15772
|
}
|
|
15682
15773
|
}
|
|
15683
15774
|
}
|
|
15684
|
-
|
|
15775
|
+
ts14.forEachChild(n, visit3);
|
|
15685
15776
|
}
|
|
15686
15777
|
visit3(node);
|
|
15687
15778
|
return found;
|
|
@@ -15690,13 +15781,13 @@ function hasZeroArgCall(node, env) {
|
|
|
15690
15781
|
let found = false;
|
|
15691
15782
|
function visit3(n) {
|
|
15692
15783
|
if (found) return;
|
|
15693
|
-
if (
|
|
15784
|
+
if (ts14.isCallExpression(n) && n.arguments.length === 0) {
|
|
15694
15785
|
if (!isCallAcceptedByAdapter(n, env)) {
|
|
15695
15786
|
found = true;
|
|
15696
15787
|
return;
|
|
15697
15788
|
}
|
|
15698
15789
|
}
|
|
15699
|
-
|
|
15790
|
+
ts14.forEachChild(n, visit3);
|
|
15700
15791
|
}
|
|
15701
15792
|
visit3(node);
|
|
15702
15793
|
return found;
|
|
@@ -15705,25 +15796,25 @@ function containsAnyIdentifier(node, names) {
|
|
|
15705
15796
|
let found = false;
|
|
15706
15797
|
function visit3(n) {
|
|
15707
15798
|
if (found) return;
|
|
15708
|
-
if (
|
|
15799
|
+
if (ts14.isPropertyAccessExpression(n)) {
|
|
15709
15800
|
visit3(n.expression);
|
|
15710
15801
|
return;
|
|
15711
15802
|
}
|
|
15712
|
-
if (
|
|
15803
|
+
if (ts14.isPropertyAssignment(n)) {
|
|
15713
15804
|
visit3(n.initializer);
|
|
15714
15805
|
return;
|
|
15715
15806
|
}
|
|
15716
|
-
if (
|
|
15717
|
-
if (
|
|
15807
|
+
if (ts14.isShorthandPropertyAssignment(n)) {
|
|
15808
|
+
if (ts14.isIdentifier(n.name) && names.has(n.name.text)) {
|
|
15718
15809
|
found = true;
|
|
15719
15810
|
}
|
|
15720
15811
|
return;
|
|
15721
15812
|
}
|
|
15722
|
-
if (
|
|
15813
|
+
if (ts14.isIdentifier(n) && names.has(n.text)) {
|
|
15723
15814
|
found = true;
|
|
15724
15815
|
return;
|
|
15725
15816
|
}
|
|
15726
|
-
|
|
15817
|
+
ts14.forEachChild(n, visit3);
|
|
15727
15818
|
}
|
|
15728
15819
|
visit3(node);
|
|
15729
15820
|
return found;
|
|
@@ -19042,7 +19133,7 @@ var init_claim_plan = __esm({
|
|
|
19042
19133
|
});
|
|
19043
19134
|
|
|
19044
19135
|
// ../jsx/src/ir-to-client-js/emit-reactive.ts
|
|
19045
|
-
import
|
|
19136
|
+
import ts15 from "typescript";
|
|
19046
19137
|
function bindingIdArg(ctx2, slotId) {
|
|
19047
19138
|
if (!ctx2.profile || !slotId) return "";
|
|
19048
19139
|
return `, ${JSON.stringify(`${ctx2.componentName}#binding:${slotId}`)}`;
|
|
@@ -19122,19 +19213,19 @@ function lowerToLocaleCallsInReactiveExpr(expr, matcher) {
|
|
|
19122
19213
|
if (!matcher) return expr;
|
|
19123
19214
|
let sourceFile;
|
|
19124
19215
|
try {
|
|
19125
|
-
sourceFile =
|
|
19216
|
+
sourceFile = ts15.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts15.ScriptTarget.Latest, true, ts15.ScriptKind.TS);
|
|
19126
19217
|
} catch {
|
|
19127
19218
|
return expr;
|
|
19128
19219
|
}
|
|
19129
19220
|
const stmt = sourceFile.statements[0];
|
|
19130
|
-
if (!stmt || !
|
|
19131
|
-
const root2 =
|
|
19221
|
+
if (!stmt || !ts15.isExpressionStatement(stmt)) return expr;
|
|
19222
|
+
const root2 = ts15.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
19132
19223
|
const candidates = [];
|
|
19133
19224
|
const visit3 = (n) => {
|
|
19134
|
-
if (
|
|
19225
|
+
if (ts15.isCallExpression(n) && n.arguments.length === 2 && ts15.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && n.expression.name.text === "toLocaleDateString") {
|
|
19135
19226
|
candidates.push(n);
|
|
19136
19227
|
}
|
|
19137
|
-
|
|
19228
|
+
ts15.forEachChild(n, visit3);
|
|
19138
19229
|
};
|
|
19139
19230
|
visit3(root2);
|
|
19140
19231
|
if (candidates.length === 0) return expr;
|
|
@@ -19171,19 +19262,19 @@ function lowerDateCallsInReactiveExpr(expr, matcher) {
|
|
|
19171
19262
|
if (!matcher) return expr;
|
|
19172
19263
|
let sourceFile;
|
|
19173
19264
|
try {
|
|
19174
|
-
sourceFile =
|
|
19265
|
+
sourceFile = ts15.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts15.ScriptTarget.Latest, true, ts15.ScriptKind.TS);
|
|
19175
19266
|
} catch {
|
|
19176
19267
|
return expr;
|
|
19177
19268
|
}
|
|
19178
19269
|
const stmt = sourceFile.statements[0];
|
|
19179
|
-
if (!stmt || !
|
|
19180
|
-
const root2 =
|
|
19270
|
+
if (!stmt || !ts15.isExpressionStatement(stmt)) return expr;
|
|
19271
|
+
const root2 = ts15.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
19181
19272
|
const candidates = [];
|
|
19182
19273
|
const visit3 = (n) => {
|
|
19183
|
-
if (
|
|
19274
|
+
if (ts15.isCallExpression(n) && n.arguments.length === 0 && ts15.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
|
|
19184
19275
|
candidates.push(n);
|
|
19185
19276
|
}
|
|
19186
|
-
|
|
19277
|
+
ts15.forEachChild(n, visit3);
|
|
19187
19278
|
};
|
|
19188
19279
|
visit3(root2);
|
|
19189
19280
|
if (candidates.length === 0) return expr;
|
|
@@ -20381,7 +20472,11 @@ function stringifyCompositeLoop(lines, plan) {
|
|
|
20381
20472
|
template,
|
|
20382
20473
|
bodyIsMultiRoot,
|
|
20383
20474
|
indent: bodyIndent,
|
|
20384
|
-
singleRootLayout: "multiline"
|
|
20475
|
+
singleRootLayout: "multiline",
|
|
20476
|
+
// Composite is exactly the variant that initialises something inside the
|
|
20477
|
+
// row — nested components, inner loops, or both — so it is exactly the
|
|
20478
|
+
// variant whose tail needs the row already connected.
|
|
20479
|
+
mountRow: true
|
|
20385
20480
|
});
|
|
20386
20481
|
emitComponentAndEventSetup(lines, bodyIndent, "__el", compsArr, eventsArr, loopParam, loopParamBindings, bodyIsMultiRoot);
|
|
20387
20482
|
if (innerLoops.length > 0) {
|
|
@@ -21318,25 +21413,25 @@ var init_phases = __esm({
|
|
|
21318
21413
|
});
|
|
21319
21414
|
|
|
21320
21415
|
// ../jsx/src/ir-to-client-js/rewrite-props-object.ts
|
|
21321
|
-
import
|
|
21416
|
+
import ts16 from "typescript";
|
|
21322
21417
|
function rewritePropsObjectRef(code, propsObjectName) {
|
|
21323
21418
|
const srcPropsName = propsObjectName ?? "props";
|
|
21324
21419
|
if (srcPropsName === PROPS_PARAM) return code;
|
|
21325
21420
|
if (!new RegExp(`\\b${srcPropsName}\\b`).test(code)) return code;
|
|
21326
|
-
const sourceFile =
|
|
21421
|
+
const sourceFile = ts16.createSourceFile(
|
|
21327
21422
|
"init-body.ts",
|
|
21328
21423
|
code,
|
|
21329
|
-
|
|
21424
|
+
ts16.ScriptTarget.Latest,
|
|
21330
21425
|
/*setParentNodes*/
|
|
21331
21426
|
true,
|
|
21332
|
-
|
|
21427
|
+
ts16.ScriptKind.TS
|
|
21333
21428
|
);
|
|
21334
21429
|
const spans = [];
|
|
21335
21430
|
function visit3(node) {
|
|
21336
|
-
if (
|
|
21431
|
+
if (ts16.isIdentifier(node) && node.text === srcPropsName && shouldRewrite(node)) {
|
|
21337
21432
|
spans.push([node.getStart(sourceFile), node.getEnd()]);
|
|
21338
21433
|
}
|
|
21339
|
-
|
|
21434
|
+
ts16.forEachChild(node, visit3);
|
|
21340
21435
|
}
|
|
21341
21436
|
visit3(sourceFile);
|
|
21342
21437
|
if (spans.length === 0) return code;
|
|
@@ -21350,12 +21445,12 @@ function rewritePropsObjectRef(code, propsObjectName) {
|
|
|
21350
21445
|
function shouldRewrite(node) {
|
|
21351
21446
|
const parent2 = node.parent;
|
|
21352
21447
|
if (!parent2) return true;
|
|
21353
|
-
if (
|
|
21354
|
-
if (
|
|
21355
|
-
if (
|
|
21356
|
-
if (
|
|
21357
|
-
if (
|
|
21358
|
-
if (
|
|
21448
|
+
if (ts16.isPropertyAccessExpression(parent2) && parent2.name === node) return false;
|
|
21449
|
+
if (ts16.isPropertyAssignment(parent2) && parent2.name === node) return false;
|
|
21450
|
+
if (ts16.isShorthandPropertyAssignment(parent2) && parent2.name === node) return false;
|
|
21451
|
+
if (ts16.isPropertySignature(parent2) && parent2.name === node) return false;
|
|
21452
|
+
if (ts16.isPropertyDeclaration(parent2) && parent2.name === node) return false;
|
|
21453
|
+
if (ts16.isBindingElement(parent2) && parent2.name === node) return false;
|
|
21359
21454
|
return true;
|
|
21360
21455
|
}
|
|
21361
21456
|
var init_rewrite_props_object = __esm({
|
|
@@ -22039,7 +22134,7 @@ var init_css_layer_prefixer = __esm({
|
|
|
22039
22134
|
});
|
|
22040
22135
|
|
|
22041
22136
|
// ../jsx/src/preprocess-inline-jsx-callbacks.ts
|
|
22042
|
-
import
|
|
22137
|
+
import ts17 from "typescript";
|
|
22043
22138
|
function preprocessInlineJsxCallbacks(source, filePath) {
|
|
22044
22139
|
const errors = [];
|
|
22045
22140
|
const syntheticNames = [];
|
|
@@ -22059,15 +22154,15 @@ function preprocessInlineJsxCallbacks(source, filePath) {
|
|
|
22059
22154
|
return { source: current, errors, syntheticNames };
|
|
22060
22155
|
}
|
|
22061
22156
|
function runSinglePass(source, filePath, startingCounter) {
|
|
22062
|
-
const sourceFile =
|
|
22157
|
+
const sourceFile = ts17.createSourceFile(
|
|
22063
22158
|
filePath,
|
|
22064
22159
|
source,
|
|
22065
|
-
|
|
22160
|
+
ts17.ScriptTarget.Latest,
|
|
22066
22161
|
true,
|
|
22067
|
-
|
|
22162
|
+
ts17.ScriptKind.TSX
|
|
22068
22163
|
);
|
|
22069
22164
|
const hasUseClient = sourceFile.statements.some(
|
|
22070
|
-
(stmt) =>
|
|
22165
|
+
(stmt) => ts17.isExpressionStatement(stmt) && ts17.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'")
|
|
22071
22166
|
);
|
|
22072
22167
|
if (!hasUseClient) {
|
|
22073
22168
|
return { source, errors: [], syntheticNames: [], counterAfter: startingCounter };
|
|
@@ -22090,20 +22185,20 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
22090
22185
|
}
|
|
22091
22186
|
}
|
|
22092
22187
|
function visit3(node) {
|
|
22093
|
-
if (
|
|
22188
|
+
if (ts17.isJsxAttribute(node) && node.initializer && ts17.isJsxExpression(node.initializer) && node.initializer.expression) {
|
|
22094
22189
|
if (tryHandleArrowValue(node.initializer.expression)) {
|
|
22095
22190
|
return;
|
|
22096
22191
|
}
|
|
22097
22192
|
}
|
|
22098
|
-
if (
|
|
22193
|
+
if (ts17.isPropertyAssignment(node) && node.initializer) {
|
|
22099
22194
|
if (tryHandleArrowValue(node.initializer)) return;
|
|
22100
22195
|
}
|
|
22101
|
-
|
|
22196
|
+
ts17.forEachChild(node, visit3);
|
|
22102
22197
|
}
|
|
22103
22198
|
function tryHandleArrowValue(initializer) {
|
|
22104
22199
|
let expr = initializer;
|
|
22105
|
-
while (
|
|
22106
|
-
if (
|
|
22200
|
+
while (ts17.isParenthesizedExpression(expr)) expr = expr.expression;
|
|
22201
|
+
if (ts17.isArrowFunction(expr) && arrowBodyContainsJsx(expr)) {
|
|
22107
22202
|
return handleInlineArrow(expr);
|
|
22108
22203
|
}
|
|
22109
22204
|
return false;
|
|
@@ -22138,7 +22233,7 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
22138
22233
|
replacements.push({ start: arrowStart, end: arrowEnd, text: name2 });
|
|
22139
22234
|
return true;
|
|
22140
22235
|
}
|
|
22141
|
-
|
|
22236
|
+
ts17.forEachChild(sourceFile, visit3);
|
|
22142
22237
|
if (replacements.length === 0) {
|
|
22143
22238
|
return { source, errors, syntheticNames, counterAfter: counter };
|
|
22144
22239
|
}
|
|
@@ -22157,33 +22252,33 @@ function errorMessageForCapture(captures) {
|
|
|
22157
22252
|
return `Inline JSX-returning arrow function captures non-module identifier(s): ${captures.sort().join(", ")}. Extract the callback into a top-level '\\'use client\\'' component (e.g. \`function MyNode(n) { return <div/> }\` then \`renderNode={MyNode}\`) or pass captured values via component props.`;
|
|
22158
22253
|
}
|
|
22159
22254
|
function arrowBodyContainsJsx(arrow) {
|
|
22160
|
-
if (
|
|
22255
|
+
if (ts17.isBlock(arrow.body)) {
|
|
22161
22256
|
return blockReturnsJsx(arrow.body);
|
|
22162
22257
|
}
|
|
22163
22258
|
let body2 = arrow.body;
|
|
22164
|
-
while (
|
|
22259
|
+
while (ts17.isParenthesizedExpression(body2)) body2 = body2.expression;
|
|
22165
22260
|
return isJsxLike(body2);
|
|
22166
22261
|
}
|
|
22167
22262
|
function blockReturnsJsx(block) {
|
|
22168
22263
|
let found = false;
|
|
22169
22264
|
function visit3(n) {
|
|
22170
22265
|
if (found) return;
|
|
22171
|
-
if (
|
|
22266
|
+
if (ts17.isReturnStatement(n) && n.expression) {
|
|
22172
22267
|
let e = n.expression;
|
|
22173
|
-
while (
|
|
22268
|
+
while (ts17.isParenthesizedExpression(e)) e = e.expression;
|
|
22174
22269
|
if (isJsxLike(e)) {
|
|
22175
22270
|
found = true;
|
|
22176
22271
|
return;
|
|
22177
22272
|
}
|
|
22178
22273
|
}
|
|
22179
|
-
if (
|
|
22180
|
-
|
|
22274
|
+
if (ts17.isArrowFunction(n) || ts17.isFunctionDeclaration(n) || ts17.isFunctionExpression(n)) return;
|
|
22275
|
+
ts17.forEachChild(n, visit3);
|
|
22181
22276
|
}
|
|
22182
|
-
|
|
22277
|
+
ts17.forEachChild(block, visit3);
|
|
22183
22278
|
return found;
|
|
22184
22279
|
}
|
|
22185
22280
|
function isJsxLike(expr) {
|
|
22186
|
-
return
|
|
22281
|
+
return ts17.isJsxElement(expr) || ts17.isJsxSelfClosingElement(expr) || ts17.isJsxFragment(expr);
|
|
22187
22282
|
}
|
|
22188
22283
|
function collectArrowParamNames(arrow) {
|
|
22189
22284
|
const names = /* @__PURE__ */ new Set();
|
|
@@ -22192,13 +22287,13 @@ function collectArrowParamNames(arrow) {
|
|
|
22192
22287
|
}
|
|
22193
22288
|
function collectBindingNames2(name2, out) {
|
|
22194
22289
|
const push = Array.isArray(out) ? (n) => out.push(n) : (n) => out.add(n);
|
|
22195
|
-
if (
|
|
22290
|
+
if (ts17.isIdentifier(name2)) {
|
|
22196
22291
|
push(name2.text);
|
|
22197
|
-
} else if (
|
|
22292
|
+
} else if (ts17.isObjectBindingPattern(name2)) {
|
|
22198
22293
|
name2.elements.forEach((el) => collectBindingNames2(el.name, out));
|
|
22199
|
-
} else if (
|
|
22294
|
+
} else if (ts17.isArrayBindingPattern(name2)) {
|
|
22200
22295
|
name2.elements.forEach((el) => {
|
|
22201
|
-
if (!
|
|
22296
|
+
if (!ts17.isOmittedExpression(el)) collectBindingNames2(el.name, out);
|
|
22202
22297
|
});
|
|
22203
22298
|
}
|
|
22204
22299
|
}
|
|
@@ -22223,71 +22318,71 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22223
22318
|
return bound.includes(name2);
|
|
22224
22319
|
}
|
|
22225
22320
|
function visit3(node) {
|
|
22226
|
-
if (
|
|
22321
|
+
if (ts17.isIdentifier(node)) {
|
|
22227
22322
|
const parent2 = node.parent;
|
|
22228
|
-
if (parent2 &&
|
|
22229
|
-
if (parent2 &&
|
|
22230
|
-
if (parent2 &&
|
|
22231
|
-
if (parent2 &&
|
|
22232
|
-
if (parent2 &&
|
|
22233
|
-
if (parent2 &&
|
|
22234
|
-
if (parent2 &&
|
|
22235
|
-
if (parent2 &&
|
|
22236
|
-
if (parent2 &&
|
|
22237
|
-
if (parent2 &&
|
|
22238
|
-
if (parent2 &&
|
|
22323
|
+
if (parent2 && ts17.isPropertyAccessExpression(parent2) && parent2.name === node) return;
|
|
22324
|
+
if (parent2 && ts17.isPropertyAssignment(parent2) && parent2.name === node) return;
|
|
22325
|
+
if (parent2 && ts17.isPropertySignature(parent2) && parent2.name === node) return;
|
|
22326
|
+
if (parent2 && ts17.isPropertyDeclaration(parent2) && parent2.name === node) return;
|
|
22327
|
+
if (parent2 && ts17.isMethodDeclaration(parent2) && parent2.name === node) return;
|
|
22328
|
+
if (parent2 && ts17.isMethodSignature(parent2) && parent2.name === node) return;
|
|
22329
|
+
if (parent2 && ts17.isGetAccessorDeclaration(parent2) && parent2.name === node) return;
|
|
22330
|
+
if (parent2 && ts17.isSetAccessorDeclaration(parent2) && parent2.name === node) return;
|
|
22331
|
+
if (parent2 && ts17.isEnumMember(parent2) && parent2.name === node) return;
|
|
22332
|
+
if (parent2 && ts17.isBindingElement(parent2) && parent2.propertyName === node) return;
|
|
22333
|
+
if (parent2 && ts17.isShorthandPropertyAssignment(parent2) && parent2.name === node) {
|
|
22239
22334
|
if (!isBound(node.text)) ids.add(node.text);
|
|
22240
22335
|
return;
|
|
22241
22336
|
}
|
|
22242
|
-
if (parent2 &&
|
|
22243
|
-
if (parent2 &&
|
|
22244
|
-
if (parent2 &&
|
|
22245
|
-
if (parent2 &&
|
|
22246
|
-
if (parent2 &&
|
|
22247
|
-
if (parent2 &&
|
|
22337
|
+
if (parent2 && ts17.isParameter(parent2) && parent2.name === node) return;
|
|
22338
|
+
if (parent2 && ts17.isVariableDeclaration(parent2) && parent2.name === node) return;
|
|
22339
|
+
if (parent2 && ts17.isFunctionDeclaration(parent2) && parent2.name === node) return;
|
|
22340
|
+
if (parent2 && ts17.isClassDeclaration(parent2) && parent2.name === node) return;
|
|
22341
|
+
if (parent2 && ts17.isJsxAttribute(parent2) && parent2.name === node) return;
|
|
22342
|
+
if (parent2 && ts17.isJsxOpeningElement(parent2) && parent2.tagName === node) {
|
|
22248
22343
|
if (/^[a-z]/.test(node.text)) return;
|
|
22249
22344
|
}
|
|
22250
|
-
if (parent2 &&
|
|
22345
|
+
if (parent2 && ts17.isJsxClosingElement(parent2) && parent2.tagName === node) {
|
|
22251
22346
|
if (/^[a-z]/.test(node.text)) return;
|
|
22252
22347
|
}
|
|
22253
22348
|
if (isBound(node.text)) return;
|
|
22254
22349
|
ids.add(node.text);
|
|
22255
22350
|
return;
|
|
22256
22351
|
}
|
|
22257
|
-
if (
|
|
22352
|
+
if (ts17.isVariableDeclaration(node)) {
|
|
22258
22353
|
const declared = pushBindings(node.name);
|
|
22259
22354
|
if (node.initializer) visit3(node.initializer);
|
|
22260
22355
|
declared;
|
|
22261
22356
|
return;
|
|
22262
22357
|
}
|
|
22263
|
-
if (
|
|
22358
|
+
if (ts17.isFunctionDeclaration(node)) {
|
|
22264
22359
|
if (node.name) bound.push(node.name.text);
|
|
22265
22360
|
visitInsideNewScope(node);
|
|
22266
22361
|
return;
|
|
22267
22362
|
}
|
|
22268
|
-
if (
|
|
22363
|
+
if (ts17.isClassDeclaration(node)) {
|
|
22269
22364
|
if (node.name) bound.push(node.name.text);
|
|
22270
|
-
|
|
22365
|
+
ts17.forEachChild(node, visit3);
|
|
22271
22366
|
return;
|
|
22272
22367
|
}
|
|
22273
|
-
if (
|
|
22368
|
+
if (ts17.isArrowFunction(node) || ts17.isFunctionExpression(node)) {
|
|
22274
22369
|
visitInsideNewScope(node);
|
|
22275
22370
|
return;
|
|
22276
22371
|
}
|
|
22277
|
-
if (
|
|
22372
|
+
if (ts17.isCatchClause(node)) {
|
|
22278
22373
|
const before = bound.length;
|
|
22279
22374
|
if (node.variableDeclaration) pushBindings(node.variableDeclaration.name);
|
|
22280
|
-
|
|
22375
|
+
ts17.forEachChild(node, visit3);
|
|
22281
22376
|
popN(bound.length - before);
|
|
22282
22377
|
return;
|
|
22283
22378
|
}
|
|
22284
|
-
if (
|
|
22379
|
+
if (ts17.isBlock(node)) {
|
|
22285
22380
|
const before = bound.length;
|
|
22286
|
-
|
|
22381
|
+
ts17.forEachChild(node, visit3);
|
|
22287
22382
|
popN(bound.length - before);
|
|
22288
22383
|
return;
|
|
22289
22384
|
}
|
|
22290
|
-
|
|
22385
|
+
ts17.forEachChild(node, visit3);
|
|
22291
22386
|
}
|
|
22292
22387
|
function visitInsideNewScope(fn) {
|
|
22293
22388
|
const before = bound.length;
|
|
@@ -22307,27 +22402,27 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22307
22402
|
function collectModuleScopeNames(sourceFile) {
|
|
22308
22403
|
const names = /* @__PURE__ */ new Set();
|
|
22309
22404
|
for (const stmt of sourceFile.statements) {
|
|
22310
|
-
if (
|
|
22311
|
-
else if (
|
|
22312
|
-
else if (
|
|
22405
|
+
if (ts17.isFunctionDeclaration(stmt) && stmt.name) names.add(stmt.name.text);
|
|
22406
|
+
else if (ts17.isClassDeclaration(stmt) && stmt.name) names.add(stmt.name.text);
|
|
22407
|
+
else if (ts17.isVariableStatement(stmt)) {
|
|
22313
22408
|
for (const decl of stmt.declarationList.declarations) collectBindingNames2(decl.name, names);
|
|
22314
|
-
} else if (
|
|
22409
|
+
} else if (ts17.isImportDeclaration(stmt) && stmt.importClause) {
|
|
22315
22410
|
const ic = stmt.importClause;
|
|
22316
22411
|
if (ic.name) names.add(ic.name.text);
|
|
22317
22412
|
if (ic.namedBindings) {
|
|
22318
|
-
if (
|
|
22413
|
+
if (ts17.isNamespaceImport(ic.namedBindings)) names.add(ic.namedBindings.name.text);
|
|
22319
22414
|
else for (const e of ic.namedBindings.elements) names.add(e.name.text);
|
|
22320
22415
|
}
|
|
22321
|
-
} else if (
|
|
22322
|
-
else if (
|
|
22323
|
-
else if (
|
|
22416
|
+
} else if (ts17.isTypeAliasDeclaration(stmt)) names.add(stmt.name.text);
|
|
22417
|
+
else if (ts17.isInterfaceDeclaration(stmt)) names.add(stmt.name.text);
|
|
22418
|
+
else if (ts17.isEnumDeclaration(stmt)) names.add(stmt.name.text);
|
|
22324
22419
|
}
|
|
22325
22420
|
return names;
|
|
22326
22421
|
}
|
|
22327
22422
|
function buildSyntheticDeclaration(name2, arrow, sourceFile) {
|
|
22328
22423
|
const paramsText = arrow.parameters.length === 0 ? "" : arrow.parameters.map((p) => p.getText(sourceFile)).join(", ");
|
|
22329
22424
|
let bodyText;
|
|
22330
|
-
if (
|
|
22425
|
+
if (ts17.isBlock(arrow.body)) {
|
|
22331
22426
|
bodyText = arrow.body.getText(sourceFile);
|
|
22332
22427
|
} else {
|
|
22333
22428
|
const expr = arrow.body.getText(sourceFile);
|
|
@@ -22346,7 +22441,7 @@ var init_preprocess_inline_jsx_callbacks = __esm({
|
|
|
22346
22441
|
});
|
|
22347
22442
|
|
|
22348
22443
|
// ../jsx/src/ssr-defaults.ts
|
|
22349
|
-
import
|
|
22444
|
+
import ts18 from "typescript";
|
|
22350
22445
|
function extractSsrDefaults(metadata) {
|
|
22351
22446
|
const out = {};
|
|
22352
22447
|
const propsLike = /* @__PURE__ */ new Set();
|
|
@@ -22406,11 +22501,11 @@ function collectPropRefs(expr, propsObjectName, out) {
|
|
|
22406
22501
|
const node = parseExpression2(expr);
|
|
22407
22502
|
if (!node) return;
|
|
22408
22503
|
const visit3 = (n) => {
|
|
22409
|
-
if (
|
|
22504
|
+
if (ts18.isPropertyAccessExpression(n) && ts18.isIdentifier(n.expression) && n.expression.text === propsObjectName && ts18.isIdentifier(n.name)) {
|
|
22410
22505
|
out.add(n.name.text);
|
|
22411
22506
|
return;
|
|
22412
22507
|
}
|
|
22413
|
-
|
|
22508
|
+
ts18.forEachChild(n, visit3);
|
|
22414
22509
|
};
|
|
22415
22510
|
visit3(node);
|
|
22416
22511
|
}
|
|
@@ -22427,21 +22522,21 @@ function tryStaticEval(expr, ctx2) {
|
|
|
22427
22522
|
}
|
|
22428
22523
|
function evalStatementsForReturn(statements, ctx2) {
|
|
22429
22524
|
for (const stmt of statements) {
|
|
22430
|
-
if (
|
|
22525
|
+
if (ts18.isVariableStatement(stmt)) {
|
|
22431
22526
|
for (const d of stmt.declarationList.declarations) {
|
|
22432
|
-
if (!
|
|
22527
|
+
if (!ts18.isIdentifier(d.name) || !d.initializer) continue;
|
|
22433
22528
|
const v = evalNode(d.initializer, ctx2);
|
|
22434
22529
|
if (v !== UNRESOLVED) ctx2.bindings[d.name.text] = v;
|
|
22435
22530
|
}
|
|
22436
|
-
} else if (
|
|
22531
|
+
} else if (ts18.isReturnStatement(stmt)) {
|
|
22437
22532
|
return stmt.expression ? evalNode(stmt.expression, ctx2) : UNRESOLVED;
|
|
22438
|
-
} else if (
|
|
22533
|
+
} else if (ts18.isIfStatement(stmt)) {
|
|
22439
22534
|
const cond = evalNode(stmt.expression, ctx2);
|
|
22440
22535
|
if (cond === UNRESOLVED) return UNRESOLVED;
|
|
22441
22536
|
const branch = cond ? stmt.thenStatement : stmt.elseStatement;
|
|
22442
22537
|
if (branch) {
|
|
22443
22538
|
const taken = evalStatementsForReturn(
|
|
22444
|
-
|
|
22539
|
+
ts18.isBlock(branch) ? branch.statements : [branch],
|
|
22445
22540
|
ctx2
|
|
22446
22541
|
);
|
|
22447
22542
|
if (taken !== NO_RETURN) return taken;
|
|
@@ -22453,64 +22548,64 @@ function evalStatementsForReturn(statements, ctx2) {
|
|
|
22453
22548
|
return NO_RETURN;
|
|
22454
22549
|
}
|
|
22455
22550
|
function parseExpression2(expr) {
|
|
22456
|
-
const sf =
|
|
22551
|
+
const sf = ts18.createSourceFile(
|
|
22457
22552
|
"__ssr_default__.ts",
|
|
22458
22553
|
`(${expr})`,
|
|
22459
|
-
|
|
22554
|
+
ts18.ScriptTarget.Latest,
|
|
22460
22555
|
false,
|
|
22461
|
-
|
|
22556
|
+
ts18.ScriptKind.TS
|
|
22462
22557
|
);
|
|
22463
22558
|
const stmt = sf.statements[0];
|
|
22464
|
-
if (!stmt || !
|
|
22465
|
-
const inner =
|
|
22559
|
+
if (!stmt || !ts18.isExpressionStatement(stmt)) return null;
|
|
22560
|
+
const inner = ts18.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
22466
22561
|
return inner;
|
|
22467
22562
|
}
|
|
22468
22563
|
function evalNode(node, ctx2) {
|
|
22469
|
-
if (
|
|
22470
|
-
if (
|
|
22471
|
-
if (
|
|
22472
|
-
if (
|
|
22473
|
-
if (
|
|
22474
|
-
if (
|
|
22564
|
+
if (ts18.isParenthesizedExpression(node)) return evalNode(node.expression, ctx2);
|
|
22565
|
+
if (ts18.isAsExpression(node)) return evalNode(node.expression, ctx2);
|
|
22566
|
+
if (ts18.isSatisfiesExpression(node)) return evalNode(node.expression, ctx2);
|
|
22567
|
+
if (ts18.isTypeAssertionExpression(node)) return evalNode(node.expression, ctx2);
|
|
22568
|
+
if (ts18.isNonNullExpression(node)) return evalNode(node.expression, ctx2);
|
|
22569
|
+
if (ts18.isArrowFunction(node)) {
|
|
22475
22570
|
if (node.parameters.length !== 0) return UNRESOLVED;
|
|
22476
|
-
if (!
|
|
22571
|
+
if (!ts18.isBlock(node.body)) return evalNode(node.body, ctx2);
|
|
22477
22572
|
const localBindings = { ...ctx2.bindings };
|
|
22478
22573
|
const localCtx = { ...ctx2, bindings: localBindings };
|
|
22479
22574
|
const result2 = evalStatementsForReturn(node.body.statements, localCtx);
|
|
22480
22575
|
return result2 === NO_RETURN ? UNRESOLVED : result2;
|
|
22481
22576
|
}
|
|
22482
|
-
if (
|
|
22483
|
-
if (
|
|
22484
|
-
if (node.kind ===
|
|
22485
|
-
if (node.kind ===
|
|
22486
|
-
if (node.kind ===
|
|
22487
|
-
if (
|
|
22577
|
+
if (ts18.isNumericLiteral(node)) return Number(node.text);
|
|
22578
|
+
if (ts18.isStringLiteralLike(node)) return node.text;
|
|
22579
|
+
if (node.kind === ts18.SyntaxKind.TrueKeyword) return true;
|
|
22580
|
+
if (node.kind === ts18.SyntaxKind.FalseKeyword) return false;
|
|
22581
|
+
if (node.kind === ts18.SyntaxKind.NullKeyword) return null;
|
|
22582
|
+
if (ts18.isIdentifier(node)) {
|
|
22488
22583
|
if (node.text === "undefined") return void 0;
|
|
22489
22584
|
if (node.text in ctx2.bindings) return ctx2.bindings[node.text];
|
|
22490
22585
|
if (ctx2.propsLike.has(node.text)) return void 0;
|
|
22491
22586
|
return UNRESOLVED;
|
|
22492
22587
|
}
|
|
22493
|
-
if (
|
|
22588
|
+
if (ts18.isPrefixUnaryExpression(node)) {
|
|
22494
22589
|
const arg = evalNode(node.operand, ctx2);
|
|
22495
22590
|
if (arg === UNRESOLVED) return UNRESOLVED;
|
|
22496
22591
|
switch (node.operator) {
|
|
22497
|
-
case
|
|
22592
|
+
case ts18.SyntaxKind.MinusToken:
|
|
22498
22593
|
return typeof arg === "number" ? -arg : UNRESOLVED;
|
|
22499
|
-
case
|
|
22594
|
+
case ts18.SyntaxKind.PlusToken:
|
|
22500
22595
|
return typeof arg === "number" ? +arg : UNRESOLVED;
|
|
22501
|
-
case
|
|
22596
|
+
case ts18.SyntaxKind.ExclamationToken:
|
|
22502
22597
|
return !arg;
|
|
22503
22598
|
}
|
|
22504
22599
|
return UNRESOLVED;
|
|
22505
22600
|
}
|
|
22506
|
-
if (
|
|
22601
|
+
if (ts18.isObjectLiteralExpression(node)) {
|
|
22507
22602
|
const obj = {};
|
|
22508
22603
|
for (const prop of node.properties) {
|
|
22509
|
-
if (!
|
|
22604
|
+
if (!ts18.isPropertyAssignment(prop)) return UNRESOLVED;
|
|
22510
22605
|
let key;
|
|
22511
|
-
if (
|
|
22606
|
+
if (ts18.isIdentifier(prop.name) || ts18.isStringLiteralLike(prop.name)) {
|
|
22512
22607
|
key = prop.name.text;
|
|
22513
|
-
} else if (
|
|
22608
|
+
} else if (ts18.isNumericLiteral(prop.name)) {
|
|
22514
22609
|
key = prop.name.text;
|
|
22515
22610
|
} else {
|
|
22516
22611
|
return UNRESOLVED;
|
|
@@ -22521,17 +22616,17 @@ function evalNode(node, ctx2) {
|
|
|
22521
22616
|
}
|
|
22522
22617
|
return obj;
|
|
22523
22618
|
}
|
|
22524
|
-
if (
|
|
22619
|
+
if (ts18.isArrayLiteralExpression(node)) {
|
|
22525
22620
|
const arr = [];
|
|
22526
22621
|
for (const elem of node.elements) {
|
|
22527
|
-
if (
|
|
22622
|
+
if (ts18.isOmittedExpression(elem)) return UNRESOLVED;
|
|
22528
22623
|
const v = evalNode(elem, ctx2);
|
|
22529
22624
|
if (v === UNRESOLVED) return UNRESOLVED;
|
|
22530
22625
|
arr.push(v === void 0 ? null : v);
|
|
22531
22626
|
}
|
|
22532
22627
|
return arr;
|
|
22533
22628
|
}
|
|
22534
|
-
if (
|
|
22629
|
+
if (ts18.isElementAccessExpression(node)) {
|
|
22535
22630
|
const base = evalNode(node.expression, ctx2);
|
|
22536
22631
|
if (base === void 0) return void 0;
|
|
22537
22632
|
if (base === UNRESOLVED || base === null || typeof base !== "object") return UNRESOLVED;
|
|
@@ -22541,16 +22636,16 @@ function evalNode(node, ctx2) {
|
|
|
22541
22636
|
const k = String(key);
|
|
22542
22637
|
return Object.prototype.hasOwnProperty.call(base, k) ? base[k] : void 0;
|
|
22543
22638
|
}
|
|
22544
|
-
if (
|
|
22639
|
+
if (ts18.isPropertyAccessExpression(node)) {
|
|
22545
22640
|
const baseResult = evalNode(node.expression, ctx2);
|
|
22546
22641
|
if (baseResult === void 0) return void 0;
|
|
22547
22642
|
return UNRESOLVED;
|
|
22548
22643
|
}
|
|
22549
|
-
if (
|
|
22550
|
-
if (node.arguments.length === 0 &&
|
|
22644
|
+
if (ts18.isCallExpression(node)) {
|
|
22645
|
+
if (node.arguments.length === 0 && ts18.isIdentifier(node.expression) && node.expression.text in ctx2.bindings) {
|
|
22551
22646
|
return ctx2.bindings[node.expression.text];
|
|
22552
22647
|
}
|
|
22553
|
-
if (
|
|
22648
|
+
if (ts18.isPropertyAccessExpression(node.expression) && node.expression.name.text === "join") {
|
|
22554
22649
|
const recv = evalNode(node.expression.expression, ctx2);
|
|
22555
22650
|
if (Array.isArray(recv)) {
|
|
22556
22651
|
let sep = ",";
|
|
@@ -22565,24 +22660,24 @@ function evalNode(node, ctx2) {
|
|
|
22565
22660
|
}
|
|
22566
22661
|
return UNRESOLVED;
|
|
22567
22662
|
}
|
|
22568
|
-
if (
|
|
22663
|
+
if (ts18.isConditionalExpression(node)) {
|
|
22569
22664
|
const cond = evalNode(node.condition, ctx2);
|
|
22570
22665
|
if (cond === UNRESOLVED) return UNRESOLVED;
|
|
22571
22666
|
return cond ? evalNode(node.whenTrue, ctx2) : evalNode(node.whenFalse, ctx2);
|
|
22572
22667
|
}
|
|
22573
|
-
if (
|
|
22668
|
+
if (ts18.isBinaryExpression(node)) {
|
|
22574
22669
|
const op = node.operatorToken.kind;
|
|
22575
|
-
if (op ===
|
|
22670
|
+
if (op === ts18.SyntaxKind.QuestionQuestionToken) {
|
|
22576
22671
|
const l2 = evalNode(node.left, ctx2);
|
|
22577
22672
|
if (l2 !== UNRESOLVED && l2 !== null && l2 !== void 0) return l2;
|
|
22578
22673
|
return evalNode(node.right, ctx2);
|
|
22579
22674
|
}
|
|
22580
|
-
if (op ===
|
|
22675
|
+
if (op === ts18.SyntaxKind.BarBarToken) {
|
|
22581
22676
|
const l2 = evalNode(node.left, ctx2);
|
|
22582
22677
|
if (l2 !== UNRESOLVED && l2) return l2;
|
|
22583
22678
|
return evalNode(node.right, ctx2);
|
|
22584
22679
|
}
|
|
22585
|
-
if (op ===
|
|
22680
|
+
if (op === ts18.SyntaxKind.AmpersandAmpersandToken) {
|
|
22586
22681
|
const l2 = evalNode(node.left, ctx2);
|
|
22587
22682
|
if (l2 === UNRESOLVED) return UNRESOLVED;
|
|
22588
22683
|
if (!l2) return l2;
|
|
@@ -22592,28 +22687,28 @@ function evalNode(node, ctx2) {
|
|
|
22592
22687
|
const r2 = evalNode(node.right, ctx2);
|
|
22593
22688
|
if (l === UNRESOLVED || r2 === UNRESOLVED) return UNRESOLVED;
|
|
22594
22689
|
switch (op) {
|
|
22595
|
-
case
|
|
22690
|
+
case ts18.SyntaxKind.PlusToken:
|
|
22596
22691
|
if (typeof l === "string" || typeof r2 === "string") return `${l}${r2}`;
|
|
22597
22692
|
if (typeof l === "number" && typeof r2 === "number") return l + r2;
|
|
22598
22693
|
return UNRESOLVED;
|
|
22599
|
-
case
|
|
22694
|
+
case ts18.SyntaxKind.MinusToken:
|
|
22600
22695
|
return typeof l === "number" && typeof r2 === "number" ? l - r2 : UNRESOLVED;
|
|
22601
|
-
case
|
|
22696
|
+
case ts18.SyntaxKind.AsteriskToken:
|
|
22602
22697
|
return typeof l === "number" && typeof r2 === "number" ? l * r2 : UNRESOLVED;
|
|
22603
|
-
case
|
|
22698
|
+
case ts18.SyntaxKind.SlashToken:
|
|
22604
22699
|
return typeof l === "number" && typeof r2 === "number" && r2 !== 0 ? l / r2 : UNRESOLVED;
|
|
22605
|
-
case
|
|
22700
|
+
case ts18.SyntaxKind.PercentToken:
|
|
22606
22701
|
return typeof l === "number" && typeof r2 === "number" && r2 !== 0 ? l % r2 : UNRESOLVED;
|
|
22607
|
-
case
|
|
22608
|
-
case
|
|
22702
|
+
case ts18.SyntaxKind.EqualsEqualsEqualsToken:
|
|
22703
|
+
case ts18.SyntaxKind.EqualsEqualsToken:
|
|
22609
22704
|
return l === r2;
|
|
22610
|
-
case
|
|
22611
|
-
case
|
|
22705
|
+
case ts18.SyntaxKind.ExclamationEqualsEqualsToken:
|
|
22706
|
+
case ts18.SyntaxKind.ExclamationEqualsToken:
|
|
22612
22707
|
return l !== r2;
|
|
22613
22708
|
}
|
|
22614
22709
|
return UNRESOLVED;
|
|
22615
22710
|
}
|
|
22616
|
-
if (
|
|
22711
|
+
if (ts18.isTemplateExpression(node)) {
|
|
22617
22712
|
if (node.templateSpans.length === 0) return node.head.text;
|
|
22618
22713
|
let acc = node.head.text;
|
|
22619
22714
|
for (const span of node.templateSpans) {
|
|
@@ -22623,7 +22718,7 @@ function evalNode(node, ctx2) {
|
|
|
22623
22718
|
}
|
|
22624
22719
|
return acc;
|
|
22625
22720
|
}
|
|
22626
|
-
if (
|
|
22721
|
+
if (ts18.isNoSubstitutionTemplateLiteral(node)) return node.text;
|
|
22627
22722
|
return UNRESOLVED;
|
|
22628
22723
|
}
|
|
22629
22724
|
var UNRESOLVED, NO_RETURN;
|
|
@@ -22636,7 +22731,7 @@ var init_ssr_defaults = __esm({
|
|
|
22636
22731
|
});
|
|
22637
22732
|
|
|
22638
22733
|
// ../jsx/src/augment-inherited-props.ts
|
|
22639
|
-
import
|
|
22734
|
+
import ts19 from "typescript";
|
|
22640
22735
|
function collectContextConsumers(metadata) {
|
|
22641
22736
|
const constants = metadata.localConstants ?? [];
|
|
22642
22737
|
const contextDefaults = /* @__PURE__ */ new Map();
|
|
@@ -22663,35 +22758,35 @@ function collectContextConsumers(metadata) {
|
|
|
22663
22758
|
}
|
|
22664
22759
|
function parseUseContextArg(source) {
|
|
22665
22760
|
const expr = parseSingleExpression(source);
|
|
22666
|
-
if (!expr || !
|
|
22667
|
-
if (!
|
|
22761
|
+
if (!expr || !ts19.isCallExpression(expr)) return null;
|
|
22762
|
+
if (!ts19.isIdentifier(expr.expression) || expr.expression.text !== "useContext") return null;
|
|
22668
22763
|
if (expr.arguments.length !== 1) return null;
|
|
22669
22764
|
const arg = expr.arguments[0];
|
|
22670
|
-
return
|
|
22765
|
+
return ts19.isIdentifier(arg) ? arg.text : null;
|
|
22671
22766
|
}
|
|
22672
22767
|
function parseCreateContextDefault(source) {
|
|
22673
22768
|
const expr = parseSingleExpression(source);
|
|
22674
|
-
if (!expr || !
|
|
22769
|
+
if (!expr || !ts19.isCallExpression(expr)) return null;
|
|
22675
22770
|
if (expr.arguments.length === 0) return null;
|
|
22676
22771
|
const arg = expr.arguments[0];
|
|
22677
|
-
if (
|
|
22678
|
-
if (
|
|
22679
|
-
if (arg.kind ===
|
|
22680
|
-
if (arg.kind ===
|
|
22772
|
+
if (ts19.isStringLiteral(arg) || ts19.isNoSubstitutionTemplateLiteral(arg)) return arg.text;
|
|
22773
|
+
if (ts19.isNumericLiteral(arg)) return Number(arg.text);
|
|
22774
|
+
if (arg.kind === ts19.SyntaxKind.TrueKeyword) return true;
|
|
22775
|
+
if (arg.kind === ts19.SyntaxKind.FalseKeyword) return false;
|
|
22681
22776
|
return null;
|
|
22682
22777
|
}
|
|
22683
22778
|
function isObjectLiteralCreateContextDefault(source) {
|
|
22684
22779
|
const expr = parseSingleExpression(source);
|
|
22685
|
-
if (!expr || !
|
|
22780
|
+
if (!expr || !ts19.isCallExpression(expr)) return false;
|
|
22686
22781
|
if (expr.arguments.length === 0) return false;
|
|
22687
|
-
return
|
|
22782
|
+
return ts19.isObjectLiteralExpression(expr.arguments[0]);
|
|
22688
22783
|
}
|
|
22689
22784
|
function parseSingleExpression(source) {
|
|
22690
|
-
const sf =
|
|
22785
|
+
const sf = ts19.createSourceFile("__ctx.ts", `(${source})`, ts19.ScriptTarget.Latest, false);
|
|
22691
22786
|
const stmt = sf.statements[0];
|
|
22692
|
-
if (!stmt || !
|
|
22787
|
+
if (!stmt || !ts19.isExpressionStatement(stmt)) return null;
|
|
22693
22788
|
let e = stmt.expression;
|
|
22694
|
-
while (
|
|
22789
|
+
while (ts19.isParenthesizedExpression(e)) e = e.expression;
|
|
22695
22790
|
return e;
|
|
22696
22791
|
}
|
|
22697
22792
|
function augmentInheritedPropAccesses(ir) {
|
|
@@ -22712,21 +22807,21 @@ function augmentInheritedPropAccesses(ir) {
|
|
|
22712
22807
|
const coalesceLiteralTypes = /* @__PURE__ */ new Map();
|
|
22713
22808
|
const pinCoalesceLiterals = (s) => {
|
|
22714
22809
|
if (!s || !s.includes(propsObj)) return;
|
|
22715
|
-
const sf =
|
|
22810
|
+
const sf = ts19.createSourceFile("__aug.ts", `(${s})`, ts19.ScriptTarget.Latest, false);
|
|
22716
22811
|
const visit3 = (n) => {
|
|
22717
|
-
if (
|
|
22812
|
+
if (ts19.isBinaryExpression(n) && (n.operatorToken.kind === ts19.SyntaxKind.QuestionQuestionToken || n.operatorToken.kind === ts19.SyntaxKind.BarBarToken)) {
|
|
22718
22813
|
let left = n.left;
|
|
22719
|
-
while (
|
|
22720
|
-
if (
|
|
22814
|
+
while (ts19.isParenthesizedExpression(left)) left = left.expression;
|
|
22815
|
+
if (ts19.isPropertyAccessExpression(left) && ts19.isIdentifier(left.expression) && left.expression.text === propsObj) {
|
|
22721
22816
|
const name2 = left.name.text;
|
|
22722
22817
|
let right = n.right;
|
|
22723
|
-
while (
|
|
22724
|
-
if (
|
|
22725
|
-
const kind2 =
|
|
22818
|
+
while (ts19.isParenthesizedExpression(right)) right = right.expression;
|
|
22819
|
+
if (ts19.isPrefixUnaryExpression(right)) right = right.operand;
|
|
22820
|
+
const kind2 = ts19.isNumericLiteral(right) ? "number" : right.kind === ts19.SyntaxKind.TrueKeyword || right.kind === ts19.SyntaxKind.FalseKeyword ? "boolean" : ts19.isStringLiteralLike(right) ? "string" : null;
|
|
22726
22821
|
if (kind2 && !coalesceLiteralTypes.has(name2)) coalesceLiteralTypes.set(name2, kind2);
|
|
22727
22822
|
}
|
|
22728
22823
|
}
|
|
22729
|
-
|
|
22824
|
+
ts19.forEachChild(n, visit3);
|
|
22730
22825
|
};
|
|
22731
22826
|
visit3(sf);
|
|
22732
22827
|
};
|
|
@@ -22822,39 +22917,39 @@ function augmentInheritedPropAccesses(ir) {
|
|
|
22822
22917
|
}
|
|
22823
22918
|
}
|
|
22824
22919
|
function parseStaticStringConst(source) {
|
|
22825
|
-
const sf =
|
|
22920
|
+
const sf = ts19.createSourceFile(
|
|
22826
22921
|
"__const.ts",
|
|
22827
22922
|
`const __x = (${source});`,
|
|
22828
|
-
|
|
22923
|
+
ts19.ScriptTarget.Latest,
|
|
22829
22924
|
/*setParentNodes*/
|
|
22830
22925
|
false
|
|
22831
22926
|
);
|
|
22832
22927
|
const stmt = sf.statements[0];
|
|
22833
|
-
if (!stmt || !
|
|
22928
|
+
if (!stmt || !ts19.isVariableStatement(stmt)) return null;
|
|
22834
22929
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
22835
|
-
while (init &&
|
|
22930
|
+
while (init && ts19.isParenthesizedExpression(init)) init = init.expression;
|
|
22836
22931
|
if (!init) return null;
|
|
22837
|
-
if (
|
|
22932
|
+
if (ts19.isStringLiteral(init) || ts19.isNoSubstitutionTemplateLiteral(init)) {
|
|
22838
22933
|
return init.text;
|
|
22839
22934
|
}
|
|
22840
22935
|
return evalStringArrayJoin(source);
|
|
22841
22936
|
}
|
|
22842
22937
|
function evalTemplateOfStringConsts(source, resolved) {
|
|
22843
|
-
const sf =
|
|
22938
|
+
const sf = ts19.createSourceFile(
|
|
22844
22939
|
"__const.ts",
|
|
22845
22940
|
`const __x = (${source});`,
|
|
22846
|
-
|
|
22941
|
+
ts19.ScriptTarget.Latest,
|
|
22847
22942
|
/*setParentNodes*/
|
|
22848
22943
|
false
|
|
22849
22944
|
);
|
|
22850
22945
|
const stmt = sf.statements[0];
|
|
22851
|
-
if (!stmt || !
|
|
22946
|
+
if (!stmt || !ts19.isVariableStatement(stmt)) return null;
|
|
22852
22947
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
22853
|
-
while (init &&
|
|
22854
|
-
if (!init || !
|
|
22948
|
+
while (init && ts19.isParenthesizedExpression(init)) init = init.expression;
|
|
22949
|
+
if (!init || !ts19.isTemplateExpression(init)) return null;
|
|
22855
22950
|
let out = init.head.text;
|
|
22856
22951
|
for (const span of init.templateSpans) {
|
|
22857
|
-
if (!
|
|
22952
|
+
if (!ts19.isIdentifier(span.expression)) return null;
|
|
22858
22953
|
const value2 = resolved.get(span.expression.text);
|
|
22859
22954
|
if (value2 === void 0) return null;
|
|
22860
22955
|
out += value2 + span.literal.text;
|
|
@@ -22883,28 +22978,28 @@ function collectModuleStringConsts(constants) {
|
|
|
22883
22978
|
function lookupStaticRecordLiteral(objectName, key, constants) {
|
|
22884
22979
|
const constInfo = (constants ?? []).find((c) => c.name === objectName && c.isModule);
|
|
22885
22980
|
if (constInfo?.value === void 0) return null;
|
|
22886
|
-
const sf =
|
|
22981
|
+
const sf = ts19.createSourceFile(
|
|
22887
22982
|
"__rec.ts",
|
|
22888
22983
|
`(${constInfo.value})`,
|
|
22889
|
-
|
|
22984
|
+
ts19.ScriptTarget.Latest,
|
|
22890
22985
|
/*setParentNodes*/
|
|
22891
22986
|
true
|
|
22892
22987
|
);
|
|
22893
22988
|
if (sf.statements.length !== 1) return null;
|
|
22894
22989
|
const stmt = sf.statements[0];
|
|
22895
|
-
if (!
|
|
22990
|
+
if (!ts19.isExpressionStatement(stmt)) return null;
|
|
22896
22991
|
let parsed = stmt.expression;
|
|
22897
|
-
while (
|
|
22898
|
-
if (!
|
|
22992
|
+
while (ts19.isParenthesizedExpression(parsed)) parsed = parsed.expression;
|
|
22993
|
+
if (!ts19.isObjectLiteralExpression(parsed)) return null;
|
|
22899
22994
|
for (const prop of parsed.properties) {
|
|
22900
|
-
if (!
|
|
22995
|
+
if (!ts19.isPropertyAssignment(prop)) continue;
|
|
22901
22996
|
const name2 = prop.name;
|
|
22902
|
-
const propKey =
|
|
22997
|
+
const propKey = ts19.isIdentifier(name2) || ts19.isStringLiteral(name2) || ts19.isNoSubstitutionTemplateLiteral(name2) ? name2.text : null;
|
|
22903
22998
|
if (propKey !== key) continue;
|
|
22904
22999
|
let v = prop.initializer;
|
|
22905
|
-
while (
|
|
22906
|
-
if (
|
|
22907
|
-
if (
|
|
23000
|
+
while (ts19.isParenthesizedExpression(v)) v = v.expression;
|
|
23001
|
+
if (ts19.isNumericLiteral(v)) return { kind: "number", text: v.text };
|
|
23002
|
+
if (ts19.isStringLiteral(v) || ts19.isNoSubstitutionTemplateLiteral(v)) {
|
|
22908
23003
|
return { kind: "string", text: v.text };
|
|
22909
23004
|
}
|
|
22910
23005
|
return null;
|
|
@@ -22912,27 +23007,27 @@ function lookupStaticRecordLiteral(objectName, key, constants) {
|
|
|
22912
23007
|
return null;
|
|
22913
23008
|
}
|
|
22914
23009
|
function evalStringArrayJoin(source) {
|
|
22915
|
-
const sf =
|
|
23010
|
+
const sf = ts19.createSourceFile(
|
|
22916
23011
|
"__join.ts",
|
|
22917
23012
|
`const __x = (${source});`,
|
|
22918
|
-
|
|
23013
|
+
ts19.ScriptTarget.Latest,
|
|
22919
23014
|
/*setParentNodes*/
|
|
22920
23015
|
false
|
|
22921
23016
|
);
|
|
22922
23017
|
const stmt = sf.statements[0];
|
|
22923
|
-
if (!stmt || !
|
|
23018
|
+
if (!stmt || !ts19.isVariableStatement(stmt)) return null;
|
|
22924
23019
|
let node = stmt.declarationList.declarations[0]?.initializer;
|
|
22925
|
-
while (node &&
|
|
22926
|
-
if (!node || !
|
|
23020
|
+
while (node && ts19.isParenthesizedExpression(node)) node = node.expression;
|
|
23021
|
+
if (!node || !ts19.isCallExpression(node)) return null;
|
|
22927
23022
|
const callee = node.expression;
|
|
22928
|
-
if (!
|
|
23023
|
+
if (!ts19.isPropertyAccessExpression(callee)) return null;
|
|
22929
23024
|
if (callee.name.text !== "join") return null;
|
|
22930
23025
|
let recv = callee.expression;
|
|
22931
|
-
while (
|
|
22932
|
-
if (!
|
|
23026
|
+
while (ts19.isParenthesizedExpression(recv)) recv = recv.expression;
|
|
23027
|
+
if (!ts19.isArrayLiteralExpression(recv)) return null;
|
|
22933
23028
|
const parts = [];
|
|
22934
23029
|
for (const el of recv.elements) {
|
|
22935
|
-
if (
|
|
23030
|
+
if (ts19.isStringLiteral(el) || ts19.isNoSubstitutionTemplateLiteral(el)) {
|
|
22936
23031
|
parts.push(el.text);
|
|
22937
23032
|
} else {
|
|
22938
23033
|
return null;
|
|
@@ -22941,16 +23036,16 @@ function evalStringArrayJoin(source) {
|
|
|
22941
23036
|
let sep = ",";
|
|
22942
23037
|
if (node.arguments.length >= 1) {
|
|
22943
23038
|
const arg = node.arguments[0];
|
|
22944
|
-
if (
|
|
23039
|
+
if (ts19.isStringLiteral(arg) || ts19.isNoSubstitutionTemplateLiteral(arg)) sep = arg.text;
|
|
22945
23040
|
else return null;
|
|
22946
23041
|
}
|
|
22947
23042
|
return parts.join(sep);
|
|
22948
23043
|
}
|
|
22949
23044
|
function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
|
|
22950
|
-
if (!
|
|
23045
|
+
if (!ts19.isElementAccessExpression(val)) return null;
|
|
22951
23046
|
const obj = val.expression;
|
|
22952
23047
|
const arg = val.argumentExpression;
|
|
22953
|
-
if (!
|
|
23048
|
+
if (!ts19.isIdentifier(obj) || !ts19.isIdentifier(arg)) return null;
|
|
22954
23049
|
let indexPropName;
|
|
22955
23050
|
let defaultKey;
|
|
22956
23051
|
const resolved = resolveKey?.(arg.text);
|
|
@@ -22964,35 +23059,35 @@ function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
|
|
|
22964
23059
|
}
|
|
22965
23060
|
const constInfo = localConstants.find((c) => c.name === obj.text && c.isModule);
|
|
22966
23061
|
if (constInfo?.value === void 0) return null;
|
|
22967
|
-
const sf =
|
|
23062
|
+
const sf = ts19.createSourceFile(
|
|
22968
23063
|
"__rec.ts",
|
|
22969
23064
|
`(${constInfo.value})`,
|
|
22970
|
-
|
|
23065
|
+
ts19.ScriptTarget.Latest,
|
|
22971
23066
|
/* setParentNodes */
|
|
22972
23067
|
true
|
|
22973
23068
|
);
|
|
22974
23069
|
if (sf.statements.length !== 1) return null;
|
|
22975
23070
|
const stmt = sf.statements[0];
|
|
22976
|
-
if (!
|
|
23071
|
+
if (!ts19.isExpressionStatement(stmt)) return null;
|
|
22977
23072
|
let parsed = stmt.expression;
|
|
22978
|
-
while (
|
|
22979
|
-
if (!
|
|
23073
|
+
while (ts19.isParenthesizedExpression(parsed)) parsed = parsed.expression;
|
|
23074
|
+
if (!ts19.isObjectLiteralExpression(parsed)) return null;
|
|
22980
23075
|
const entries2 = [];
|
|
22981
23076
|
for (const prop of parsed.properties) {
|
|
22982
|
-
if (!
|
|
23077
|
+
if (!ts19.isPropertyAssignment(prop)) return null;
|
|
22983
23078
|
let key;
|
|
22984
|
-
if (
|
|
23079
|
+
if (ts19.isIdentifier(prop.name)) {
|
|
22985
23080
|
key = prop.name.text;
|
|
22986
|
-
} else if (
|
|
23081
|
+
} else if (ts19.isStringLiteral(prop.name) || ts19.isNoSubstitutionTemplateLiteral(prop.name)) {
|
|
22987
23082
|
key = prop.name.text;
|
|
22988
23083
|
} else {
|
|
22989
23084
|
return null;
|
|
22990
23085
|
}
|
|
22991
23086
|
let v = prop.initializer;
|
|
22992
|
-
while (
|
|
22993
|
-
if (
|
|
23087
|
+
while (ts19.isParenthesizedExpression(v)) v = v.expression;
|
|
23088
|
+
if (ts19.isNumericLiteral(v)) {
|
|
22994
23089
|
entries2.push({ key, value: { kind: "number", text: v.text } });
|
|
22995
|
-
} else if (
|
|
23090
|
+
} else if (ts19.isStringLiteral(v) || ts19.isNoSubstitutionTemplateLiteral(v)) {
|
|
22996
23091
|
entries2.push({ key, value: { kind: "string", text: v.text } });
|
|
22997
23092
|
} else {
|
|
22998
23093
|
return null;
|
|
@@ -23627,6 +23722,7 @@ function compileJSX(source, filePath, options2) {
|
|
|
23627
23722
|
const sortedRuntimeImports = [...runtimeImports].sort();
|
|
23628
23723
|
const runtimeImportLine = sortedRuntimeImports.length > 0 ? `import { ${sortedRuntimeImports.join(", ")} } from '${RUNTIME_MODULE}'` : "";
|
|
23629
23724
|
const externalImportLines = [];
|
|
23725
|
+
const isUsedAsValue = makeValueUsageTest(body2);
|
|
23630
23726
|
for (const imp of ctx2.imports) {
|
|
23631
23727
|
if (imp.isTypeOnly) continue;
|
|
23632
23728
|
if (imp.source === "@barefootjs/client" || imp.source === RUNTIME_MODULE) continue;
|
|
@@ -23634,7 +23730,7 @@ function compileJSX(source, filePath, options2) {
|
|
|
23634
23730
|
externalImportLines.push(`import '${imp.source}'`);
|
|
23635
23731
|
continue;
|
|
23636
23732
|
}
|
|
23637
|
-
const used = imp.specifiers.filter((s2) => !s2.isDefault && !s2.isNamespace &&
|
|
23733
|
+
const used = imp.specifiers.filter((s2) => !s2.isDefault && !s2.isNamespace && !s2.isTypeOnly && isUsedAsValue(s2.alias || s2.name)).map((s2) => s2.alias ? `${s2.name} as ${s2.alias}` : s2.name);
|
|
23638
23734
|
if (used.length > 0) {
|
|
23639
23735
|
externalImportLines.push(`import { ${used.join(", ")} } from '${imp.source}'`);
|
|
23640
23736
|
}
|
|
@@ -23665,6 +23761,7 @@ function compileJSX(source, filePath, options2) {
|
|
|
23665
23761
|
if (imp.isTypeOnly) continue;
|
|
23666
23762
|
if (!imp.source.startsWith("./") && !imp.source.startsWith("../")) continue;
|
|
23667
23763
|
for (const spec of imp.specifiers) {
|
|
23764
|
+
if (spec.isTypeOnly) continue;
|
|
23668
23765
|
if (ctx2.importedClientSignalNames.has(spec.alias ?? spec.name)) {
|
|
23669
23766
|
sources.add(imp.source);
|
|
23670
23767
|
break;
|
|
@@ -23794,7 +23891,7 @@ var init_compiler = __esm({
|
|
|
23794
23891
|
});
|
|
23795
23892
|
|
|
23796
23893
|
// ../jsx/src/shared-program.ts
|
|
23797
|
-
import
|
|
23894
|
+
import ts20 from "typescript";
|
|
23798
23895
|
import path5 from "node:path";
|
|
23799
23896
|
function commonParent(paths) {
|
|
23800
23897
|
if (paths.length === 0) return process.cwd();
|
|
@@ -23812,10 +23909,10 @@ function commonParent(paths) {
|
|
|
23812
23909
|
function createProgramForCorpus(files2, options2 = {}) {
|
|
23813
23910
|
const baseUrl = options2.baseUrl ?? commonParent(files2);
|
|
23814
23911
|
const compilerOptions = {
|
|
23815
|
-
target:
|
|
23816
|
-
module:
|
|
23817
|
-
moduleResolution:
|
|
23818
|
-
jsx:
|
|
23912
|
+
target: ts20.ScriptTarget.Latest,
|
|
23913
|
+
module: ts20.ModuleKind.ESNext,
|
|
23914
|
+
moduleResolution: ts20.ModuleResolutionKind.Bundler,
|
|
23915
|
+
jsx: ts20.JsxEmit.ReactJSX,
|
|
23819
23916
|
strict: true,
|
|
23820
23917
|
skipLibCheck: true,
|
|
23821
23918
|
noEmit: true,
|
|
@@ -23825,7 +23922,7 @@ function createProgramForCorpus(files2, options2 = {}) {
|
|
|
23825
23922
|
...options2.compilerOptions
|
|
23826
23923
|
};
|
|
23827
23924
|
const absolute = files2.map((f) => path5.resolve(f));
|
|
23828
|
-
return
|
|
23925
|
+
return ts20.createProgram(absolute, compilerOptions, void 0, options2.oldProgram);
|
|
23829
23926
|
}
|
|
23830
23927
|
var init_shared_program = __esm({
|
|
23831
23928
|
"../jsx/src/shared-program.ts"() {
|
|
@@ -24894,7 +24991,7 @@ var init_dangerous_inner_html = __esm({
|
|
|
24894
24991
|
});
|
|
24895
24992
|
|
|
24896
24993
|
// ../jsx/src/combine-client-js.ts
|
|
24897
|
-
import
|
|
24994
|
+
import ts21 from "typescript";
|
|
24898
24995
|
function combineParentChildClientJs(files2) {
|
|
24899
24996
|
const result2 = /* @__PURE__ */ new Map();
|
|
24900
24997
|
const lookup = /* @__PURE__ */ new Map();
|
|
@@ -24951,17 +25048,17 @@ function combineParentChildClientJs(files2) {
|
|
|
24951
25048
|
return result2;
|
|
24952
25049
|
}
|
|
24953
25050
|
function parseAndMerge(content2, importsBySource, otherImports, codeSections) {
|
|
24954
|
-
const sourceFile =
|
|
25051
|
+
const sourceFile = ts21.createSourceFile(
|
|
24955
25052
|
"combine.js",
|
|
24956
25053
|
content2,
|
|
24957
|
-
|
|
25054
|
+
ts21.ScriptTarget.Latest,
|
|
24958
25055
|
/*setParentNodes*/
|
|
24959
25056
|
false,
|
|
24960
|
-
|
|
25057
|
+
ts21.ScriptKind.JS
|
|
24961
25058
|
);
|
|
24962
25059
|
const importSpans = [];
|
|
24963
25060
|
for (const stmt of sourceFile.statements) {
|
|
24964
|
-
if (!
|
|
25061
|
+
if (!ts21.isImportDeclaration(stmt)) continue;
|
|
24965
25062
|
const start2 = stmt.getStart(sourceFile);
|
|
24966
25063
|
const end2 = stmt.getEnd();
|
|
24967
25064
|
importSpans.push([start2, end2]);
|
|
@@ -24969,8 +25066,8 @@ function parseAndMerge(content2, importsBySource, otherImports, codeSections) {
|
|
|
24969
25066
|
if (stmtText.includes("@bf-child:")) continue;
|
|
24970
25067
|
const clause = stmt.importClause;
|
|
24971
25068
|
const bindings = clause?.namedBindings;
|
|
24972
|
-
const specifier =
|
|
24973
|
-
if (clause && !clause.name && bindings &&
|
|
25069
|
+
const specifier = ts21.isStringLiteral(stmt.moduleSpecifier) ? stmt.moduleSpecifier.text : "";
|
|
25070
|
+
if (clause && !clause.name && bindings && ts21.isNamedImports(bindings)) {
|
|
24974
25071
|
if (!importsBySource.has(specifier)) {
|
|
24975
25072
|
importsBySource.set(specifier, /* @__PURE__ */ new Set());
|
|
24976
25073
|
}
|
|
@@ -25164,7 +25261,7 @@ var init_loop_destructure = __esm({
|
|
|
25164
25261
|
});
|
|
25165
25262
|
|
|
25166
25263
|
// ../jsx/src/debug.ts
|
|
25167
|
-
import
|
|
25264
|
+
import ts22 from "typescript";
|
|
25168
25265
|
function buildComponentGraph(source, filePath, componentName) {
|
|
25169
25266
|
const ctx2 = analyzeComponent(source, filePath, componentName);
|
|
25170
25267
|
if (!ctx2.jsxReturn) {
|
|
@@ -26376,18 +26473,18 @@ function truncateExpr(expr, max = 40) {
|
|
|
26376
26473
|
function exprReadsPropMember(expr, propsObjectName) {
|
|
26377
26474
|
let sf;
|
|
26378
26475
|
try {
|
|
26379
|
-
sf =
|
|
26476
|
+
sf = ts22.createSourceFile("__attr.tsx", `(${expr})`, ts22.ScriptTarget.Latest, true, ts22.ScriptKind.TSX);
|
|
26380
26477
|
} catch {
|
|
26381
26478
|
return false;
|
|
26382
26479
|
}
|
|
26383
26480
|
let found = false;
|
|
26384
26481
|
const visit3 = (n) => {
|
|
26385
26482
|
if (found) return;
|
|
26386
|
-
if (
|
|
26483
|
+
if (ts22.isPropertyAccessExpression(n) && ts22.isIdentifier(n.expression) && n.expression.text === propsObjectName && n.name.text !== "children") {
|
|
26387
26484
|
found = true;
|
|
26388
26485
|
return;
|
|
26389
26486
|
}
|
|
26390
|
-
|
|
26487
|
+
ts22.forEachChild(n, visit3);
|
|
26391
26488
|
};
|
|
26392
26489
|
visit3(sf);
|
|
26393
26490
|
return found;
|
|
@@ -26464,7 +26561,7 @@ var init_debug = __esm({
|
|
|
26464
26561
|
});
|
|
26465
26562
|
|
|
26466
26563
|
// ../jsx/src/profiler.ts
|
|
26467
|
-
import
|
|
26564
|
+
import ts23 from "typescript";
|
|
26468
26565
|
function buildStaticBudget(source, filePath, componentName, options2 = {}) {
|
|
26469
26566
|
const threshold = options2.fanOutThreshold ?? DEFAULT_FANOUT_THRESHOLD;
|
|
26470
26567
|
const program = createProgramForFile(source, filePath)?.program;
|
|
@@ -26719,14 +26816,14 @@ function joinProfilerEvents(events, index) {
|
|
|
26719
26816
|
return { joined, unattributed, diagnostics };
|
|
26720
26817
|
}
|
|
26721
26818
|
function findUninstrumentedEffects(source, filePath, instrumentedLines) {
|
|
26722
|
-
const sf =
|
|
26819
|
+
const sf = ts23.createSourceFile(filePath, source, ts23.ScriptTarget.Latest, true, ts23.ScriptKind.TSX);
|
|
26723
26820
|
const out = [];
|
|
26724
26821
|
const visit3 = (node) => {
|
|
26725
|
-
if (
|
|
26822
|
+
if (ts23.isCallExpression(node) && ts23.isIdentifier(node.expression) && node.expression.text === "createEffect") {
|
|
26726
26823
|
const line = sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;
|
|
26727
26824
|
if (!instrumentedLines.has(line)) out.push({ file: filePath, line });
|
|
26728
26825
|
}
|
|
26729
|
-
|
|
26826
|
+
ts23.forEachChild(node, visit3);
|
|
26730
26827
|
};
|
|
26731
26828
|
visit3(sf);
|
|
26732
26829
|
out.sort((a, b) => a.line - b.line);
|
|
@@ -27012,19 +27109,19 @@ function assessBatchSafety(args2) {
|
|
|
27012
27109
|
const signalGetters = new Set(args2.graph.signals.map((s) => s.name));
|
|
27013
27110
|
let sf;
|
|
27014
27111
|
try {
|
|
27015
|
-
sf =
|
|
27112
|
+
sf = ts23.createSourceFile("__h.ts", `const __h = ${args2.handler}`, ts23.ScriptTarget.Latest, true);
|
|
27016
27113
|
} catch {
|
|
27017
27114
|
return "unverified";
|
|
27018
27115
|
}
|
|
27019
27116
|
const calls = [];
|
|
27020
27117
|
const visit3 = (node) => {
|
|
27021
|
-
if (
|
|
27118
|
+
if (ts23.isCallExpression(node) && ts23.isIdentifier(node.expression)) {
|
|
27022
27119
|
const name2 = node.expression.text;
|
|
27023
27120
|
if (setters.has(name2)) calls.push({ pos: node.getStart(sf), kind: "write" });
|
|
27024
27121
|
else if (D.has(name2) && node.arguments.length === 0) calls.push({ pos: node.getStart(sf), kind: "memoRead" });
|
|
27025
27122
|
else if (!signalGetters.has(name2) && !memoNames.has(name2)) calls.push({ pos: node.getStart(sf), kind: "risky" });
|
|
27026
27123
|
}
|
|
27027
|
-
|
|
27124
|
+
ts23.forEachChild(node, visit3);
|
|
27028
27125
|
};
|
|
27029
27126
|
visit3(sf);
|
|
27030
27127
|
calls.sort((a, b) => a.pos - b.pos);
|
|
@@ -27717,6 +27814,7 @@ __export(src_exports, {
|
|
|
27717
27814
|
collectContextConsumers: () => collectContextConsumers,
|
|
27718
27815
|
collectLoopBoundNames: () => collectLoopBoundNames,
|
|
27719
27816
|
collectModuleStringConsts: () => collectModuleStringConsts,
|
|
27817
|
+
collectValueReferencedNames: () => collectValueReferencedNames,
|
|
27720
27818
|
combineParentChildClientJs: () => combineParentChildClientJs,
|
|
27721
27819
|
compileJSX: () => compileJSX,
|
|
27722
27820
|
computeSsrSeedPlan: () => computeSsrSeedPlan,
|
|
@@ -27791,6 +27889,7 @@ __export(src_exports, {
|
|
|
27791
27889
|
isStringTypedOperand: () => isStringTypedOperand,
|
|
27792
27890
|
isSupported: () => isSupported,
|
|
27793
27891
|
isValidHelperId: () => isValidHelperId,
|
|
27892
|
+
isValueReferenceIdentifier: () => isValueReferenceIdentifier,
|
|
27794
27893
|
joinProfilerEvents: () => joinProfilerEvents,
|
|
27795
27894
|
jsxToIR: () => jsxToIR,
|
|
27796
27895
|
listComponentFunctions: () => listComponentFunctions,
|
|
@@ -27867,6 +27966,7 @@ var init_src2 = __esm({
|
|
|
27867
27966
|
init_css_layer_prefixer();
|
|
27868
27967
|
init_instrumentation();
|
|
27869
27968
|
init_errors();
|
|
27969
|
+
init_value_references();
|
|
27870
27970
|
init_expression_parser();
|
|
27871
27971
|
init_expression_parser();
|
|
27872
27972
|
init_loop_chain();
|
|
@@ -27941,7 +28041,7 @@ var init_runtime = __esm({
|
|
|
27941
28041
|
|
|
27942
28042
|
// src/lib/resolve-imports.ts
|
|
27943
28043
|
import { dirname as dirname2, resolve as resolve2 } from "node:path";
|
|
27944
|
-
import
|
|
28044
|
+
import ts24 from "typescript";
|
|
27945
28045
|
function shapeFromDecl(decl) {
|
|
27946
28046
|
const clause = decl.importClause;
|
|
27947
28047
|
if (!clause) return null;
|
|
@@ -27951,7 +28051,7 @@ function shapeFromDecl(decl) {
|
|
|
27951
28051
|
}
|
|
27952
28052
|
const bindings = clause.namedBindings;
|
|
27953
28053
|
if (bindings) {
|
|
27954
|
-
if (
|
|
28054
|
+
if (ts24.isNamespaceImport(bindings)) {
|
|
27955
28055
|
shape.namespace = bindings.name.text;
|
|
27956
28056
|
} else {
|
|
27957
28057
|
for (const el of bindings.elements) {
|
|
@@ -27963,60 +28063,85 @@ function shapeFromDecl(decl) {
|
|
|
27963
28063
|
}
|
|
27964
28064
|
return shape;
|
|
27965
28065
|
}
|
|
27966
|
-
function
|
|
27967
|
-
const
|
|
27968
|
-
const
|
|
28066
|
+
function collectExportInfo(source) {
|
|
28067
|
+
const localValueExports = /* @__PURE__ */ new Set();
|
|
28068
|
+
const otherValueExports = /* @__PURE__ */ new Set();
|
|
28069
|
+
const reExportedNames = /* @__PURE__ */ new Set();
|
|
28070
|
+
let hasStarReExport = false;
|
|
28071
|
+
const sourceFile = ts24.createSourceFile(
|
|
27969
28072
|
"mod.ts",
|
|
27970
28073
|
source,
|
|
27971
|
-
|
|
28074
|
+
ts24.ScriptTarget.Latest,
|
|
27972
28075
|
/*setParents*/
|
|
27973
28076
|
false,
|
|
27974
|
-
|
|
28077
|
+
ts24.ScriptKind.TS
|
|
27975
28078
|
);
|
|
27976
28079
|
function hasExport(node) {
|
|
27977
|
-
if (!
|
|
27978
|
-
const mods =
|
|
27979
|
-
return mods?.some((m) => m.kind ===
|
|
28080
|
+
if (!ts24.canHaveModifiers(node)) return false;
|
|
28081
|
+
const mods = ts24.getModifiers(node);
|
|
28082
|
+
return mods?.some((m) => m.kind === ts24.SyntaxKind.ExportKeyword) ?? false;
|
|
28083
|
+
}
|
|
28084
|
+
function isAmbient(node) {
|
|
28085
|
+
if (!ts24.canHaveModifiers(node)) return false;
|
|
28086
|
+
const mods = ts24.getModifiers(node);
|
|
28087
|
+
return mods?.some((m) => m.kind === ts24.SyntaxKind.DeclareKeyword) ?? false;
|
|
27980
28088
|
}
|
|
27981
28089
|
function collectFromBindingName(name2) {
|
|
27982
|
-
if (
|
|
27983
|
-
|
|
28090
|
+
if (ts24.isIdentifier(name2)) {
|
|
28091
|
+
localValueExports.add(name2.text);
|
|
27984
28092
|
return;
|
|
27985
28093
|
}
|
|
27986
28094
|
for (const el of name2.elements) {
|
|
27987
|
-
if (
|
|
28095
|
+
if (ts24.isBindingElement(el)) collectFromBindingName(el.name);
|
|
27988
28096
|
}
|
|
27989
28097
|
}
|
|
27990
28098
|
for (const stmt of sourceFile.statements) {
|
|
27991
|
-
if (
|
|
28099
|
+
if (ts24.isVariableStatement(stmt) && hasExport(stmt)) {
|
|
27992
28100
|
for (const d of stmt.declarationList.declarations) {
|
|
27993
28101
|
collectFromBindingName(d.name);
|
|
27994
28102
|
}
|
|
27995
|
-
} else if (
|
|
27996
|
-
|
|
27997
|
-
} else if (
|
|
27998
|
-
|
|
27999
|
-
} else if (
|
|
28103
|
+
} else if (ts24.isFunctionDeclaration(stmt) && hasExport(stmt) && stmt.name) {
|
|
28104
|
+
localValueExports.add(stmt.name.text);
|
|
28105
|
+
} else if (ts24.isClassDeclaration(stmt) && hasExport(stmt) && stmt.name) {
|
|
28106
|
+
localValueExports.add(stmt.name.text);
|
|
28107
|
+
} else if (ts24.isEnumDeclaration(stmt) && hasExport(stmt) && stmt.name) {
|
|
28108
|
+
otherValueExports.add(stmt.name.text);
|
|
28109
|
+
} else if (ts24.isModuleDeclaration(stmt) && hasExport(stmt) && ts24.isIdentifier(stmt.name)) {
|
|
28110
|
+
if (!isAmbient(stmt)) otherValueExports.add(stmt.name.text);
|
|
28111
|
+
} else if (ts24.isExportDeclaration(stmt)) {
|
|
28000
28112
|
if (stmt.isTypeOnly) continue;
|
|
28001
|
-
|
|
28002
|
-
if (
|
|
28003
|
-
|
|
28113
|
+
if (!stmt.moduleSpecifier) {
|
|
28114
|
+
if (stmt.exportClause && ts24.isNamedExports(stmt.exportClause)) {
|
|
28115
|
+
for (const el of stmt.exportClause.elements) {
|
|
28116
|
+
if (el.isTypeOnly) continue;
|
|
28117
|
+
localValueExports.add(el.name.text);
|
|
28118
|
+
}
|
|
28119
|
+
}
|
|
28120
|
+
} else if (!stmt.exportClause) {
|
|
28121
|
+
hasStarReExport = true;
|
|
28122
|
+
} else if (ts24.isNamespaceExport(stmt.exportClause)) {
|
|
28123
|
+
reExportedNames.add(stmt.exportClause.name.text);
|
|
28124
|
+
} else if (ts24.isNamedExports(stmt.exportClause)) {
|
|
28125
|
+
for (const el of stmt.exportClause.elements) {
|
|
28126
|
+
if (el.isTypeOnly) continue;
|
|
28127
|
+
reExportedNames.add(el.name.text);
|
|
28128
|
+
}
|
|
28004
28129
|
}
|
|
28005
28130
|
}
|
|
28006
28131
|
}
|
|
28007
|
-
return
|
|
28132
|
+
return { localValueExports, otherValueExports, reExportedNames, hasStarReExport };
|
|
28008
28133
|
}
|
|
28009
28134
|
function hasUseClientDirective(source) {
|
|
28010
|
-
const sourceFile =
|
|
28135
|
+
const sourceFile = ts24.createSourceFile(
|
|
28011
28136
|
"check.tsx",
|
|
28012
28137
|
source,
|
|
28013
|
-
|
|
28138
|
+
ts24.ScriptTarget.Latest,
|
|
28014
28139
|
/*setParents*/
|
|
28015
28140
|
false,
|
|
28016
|
-
|
|
28141
|
+
ts24.ScriptKind.TSX
|
|
28017
28142
|
);
|
|
28018
28143
|
for (const stmt of sourceFile.statements) {
|
|
28019
|
-
if (!
|
|
28144
|
+
if (!ts24.isExpressionStatement(stmt) || !ts24.isStringLiteral(stmt.expression)) {
|
|
28020
28145
|
return false;
|
|
28021
28146
|
}
|
|
28022
28147
|
if (stmt.expression.text === "use client") return true;
|
|
@@ -28025,53 +28150,53 @@ function hasUseClientDirective(source) {
|
|
|
28025
28150
|
}
|
|
28026
28151
|
function collectTopLevelBindings(source) {
|
|
28027
28152
|
const names = /* @__PURE__ */ new Set();
|
|
28028
|
-
const sourceFile =
|
|
28153
|
+
const sourceFile = ts24.createSourceFile(
|
|
28029
28154
|
"bundle.ts",
|
|
28030
28155
|
source,
|
|
28031
|
-
|
|
28156
|
+
ts24.ScriptTarget.Latest,
|
|
28032
28157
|
/*setParents*/
|
|
28033
28158
|
false,
|
|
28034
|
-
|
|
28159
|
+
ts24.ScriptKind.TS
|
|
28035
28160
|
);
|
|
28036
28161
|
function collectFromBindingName(name2) {
|
|
28037
|
-
if (
|
|
28162
|
+
if (ts24.isIdentifier(name2)) {
|
|
28038
28163
|
names.add(name2.text);
|
|
28039
28164
|
return;
|
|
28040
28165
|
}
|
|
28041
28166
|
for (const el of name2.elements) {
|
|
28042
|
-
if (
|
|
28167
|
+
if (ts24.isBindingElement(el)) collectFromBindingName(el.name);
|
|
28043
28168
|
}
|
|
28044
28169
|
}
|
|
28045
28170
|
for (const stmt of sourceFile.statements) {
|
|
28046
|
-
if (
|
|
28171
|
+
if (ts24.isVariableStatement(stmt)) {
|
|
28047
28172
|
for (const d of stmt.declarationList.declarations) {
|
|
28048
28173
|
collectFromBindingName(d.name);
|
|
28049
28174
|
}
|
|
28050
|
-
} else if (
|
|
28175
|
+
} else if (ts24.isFunctionDeclaration(stmt) && stmt.name) {
|
|
28051
28176
|
names.add(stmt.name.text);
|
|
28052
|
-
} else if (
|
|
28177
|
+
} else if (ts24.isClassDeclaration(stmt) && stmt.name) {
|
|
28053
28178
|
names.add(stmt.name.text);
|
|
28054
28179
|
}
|
|
28055
28180
|
}
|
|
28056
28181
|
return names;
|
|
28057
28182
|
}
|
|
28058
28183
|
function stripImportsAndExports(body2) {
|
|
28059
|
-
const sourceFile =
|
|
28184
|
+
const sourceFile = ts24.createSourceFile(
|
|
28060
28185
|
"body.ts",
|
|
28061
28186
|
body2,
|
|
28062
|
-
|
|
28187
|
+
ts24.ScriptTarget.Latest,
|
|
28063
28188
|
/*setParents*/
|
|
28064
28189
|
false,
|
|
28065
|
-
|
|
28190
|
+
ts24.ScriptKind.TS
|
|
28066
28191
|
);
|
|
28067
28192
|
const spans = [];
|
|
28068
28193
|
const hoistedImports = [];
|
|
28069
28194
|
for (const stmt of sourceFile.statements) {
|
|
28070
|
-
if (
|
|
28195
|
+
if (ts24.isImportDeclaration(stmt)) {
|
|
28071
28196
|
const start2 = stmt.getStart(sourceFile);
|
|
28072
28197
|
const end2 = stmt.getEnd();
|
|
28073
28198
|
const specifier = stmt.moduleSpecifier;
|
|
28074
|
-
if (
|
|
28199
|
+
if (ts24.isStringLiteral(specifier)) {
|
|
28075
28200
|
const path25 = specifier.text;
|
|
28076
28201
|
const isRelative = path25.startsWith("./") || path25.startsWith("../");
|
|
28077
28202
|
if (!isRelative) {
|
|
@@ -28081,24 +28206,24 @@ function stripImportsAndExports(body2) {
|
|
|
28081
28206
|
spans.push([start2, end2]);
|
|
28082
28207
|
continue;
|
|
28083
28208
|
}
|
|
28084
|
-
if (
|
|
28209
|
+
if (ts24.isExportDeclaration(stmt)) {
|
|
28085
28210
|
spans.push([stmt.getStart(sourceFile), stmt.getEnd()]);
|
|
28086
28211
|
continue;
|
|
28087
28212
|
}
|
|
28088
|
-
if (
|
|
28089
|
-
const exportKw = stmt.getChildren(sourceFile).find((c) => c.kind ===
|
|
28090
|
-
const defaultKw = stmt.getChildren(sourceFile).find((c) => c.kind ===
|
|
28091
|
-
const equalsKw = stmt.getChildren(sourceFile).find((c) => c.kind ===
|
|
28213
|
+
if (ts24.isExportAssignment(stmt)) {
|
|
28214
|
+
const exportKw = stmt.getChildren(sourceFile).find((c) => c.kind === ts24.SyntaxKind.ExportKeyword);
|
|
28215
|
+
const defaultKw = stmt.getChildren(sourceFile).find((c) => c.kind === ts24.SyntaxKind.DefaultKeyword);
|
|
28216
|
+
const equalsKw = stmt.getChildren(sourceFile).find((c) => c.kind === ts24.SyntaxKind.EqualsToken);
|
|
28092
28217
|
const start2 = exportKw?.getStart(sourceFile) ?? stmt.getStart(sourceFile);
|
|
28093
28218
|
const end2 = (defaultKw ?? equalsKw)?.getEnd() ?? exportKw?.getEnd() ?? stmt.getStart(sourceFile);
|
|
28094
28219
|
if (end2 > start2) spans.push([start2, end2]);
|
|
28095
28220
|
continue;
|
|
28096
28221
|
}
|
|
28097
|
-
if (
|
|
28098
|
-
const mods =
|
|
28222
|
+
if (ts24.canHaveModifiers(stmt)) {
|
|
28223
|
+
const mods = ts24.getModifiers(stmt);
|
|
28099
28224
|
if (!mods) continue;
|
|
28100
28225
|
for (const mod of mods) {
|
|
28101
|
-
if (mod.kind ===
|
|
28226
|
+
if (mod.kind === ts24.SyntaxKind.ExportKeyword) {
|
|
28102
28227
|
const start2 = mod.getStart(sourceFile);
|
|
28103
28228
|
let end2 = mod.getEnd();
|
|
28104
28229
|
while (end2 < body2.length && /\s/.test(body2[end2])) end2++;
|
|
@@ -28130,15 +28255,43 @@ function buildConsumerBinding(shape, topLevelId) {
|
|
|
28130
28255
|
);
|
|
28131
28256
|
return `const { ${entries2.join(", ")} } = ${topLevelId};`;
|
|
28132
28257
|
}
|
|
28133
|
-
function
|
|
28258
|
+
function buildMissingExportMessage(name2, modulePath) {
|
|
28259
|
+
return {
|
|
28260
|
+
message: `Import \`${name2}\` from '${modulePath}' has no matching export in that module. The client bundle would throw \`ReferenceError: ${name2} is not defined\` at load.`,
|
|
28261
|
+
suggestion: `Either \`${name2}\` is a TYPE \u2014 import it with \`import type { ${name2} }\` or \`import { type ${name2} }\` (the compiler no longer emits type-only specifiers into the client bundle as of #2432) \u2014 or it's a typo / removed export: check '${modulePath}' actually exports \`${name2}\`.`
|
|
28262
|
+
};
|
|
28263
|
+
}
|
|
28264
|
+
function buildTopLevelIIFE(topLevelId, body2, shapesNeeded, originalSource, modulePath) {
|
|
28134
28265
|
const { body: stripped, hoistedImports } = stripImportsAndExports(body2);
|
|
28135
28266
|
const wantsNamespace = shapesNeeded.some((s) => !!s.namespace);
|
|
28136
28267
|
const namesNeeded = /* @__PURE__ */ new Set();
|
|
28137
|
-
|
|
28138
|
-
for (const n of collectExportedNames(originalSource)) namesNeeded.add(n);
|
|
28139
|
-
}
|
|
28268
|
+
const namedRequests = /* @__PURE__ */ new Set();
|
|
28140
28269
|
for (const shape of shapesNeeded) {
|
|
28141
|
-
for (const { imported } of shape.named)
|
|
28270
|
+
for (const { imported } of shape.named) {
|
|
28271
|
+
namesNeeded.add(imported);
|
|
28272
|
+
namedRequests.add(imported);
|
|
28273
|
+
}
|
|
28274
|
+
}
|
|
28275
|
+
const errors = [];
|
|
28276
|
+
if (wantsNamespace || namedRequests.size > 0) {
|
|
28277
|
+
const info = collectExportInfo(originalSource);
|
|
28278
|
+
if (wantsNamespace) {
|
|
28279
|
+
for (const n of info.localValueExports) namesNeeded.add(n);
|
|
28280
|
+
}
|
|
28281
|
+
if (namedRequests.size > 0 && !info.hasStarReExport) {
|
|
28282
|
+
const surfaceNames = /* @__PURE__ */ new Set([...info.localValueExports, ...info.otherValueExports, ...info.reExportedNames]);
|
|
28283
|
+
const loc = { file: modulePath, start: { line: 1, column: 0 }, end: { line: 1, column: 0 } };
|
|
28284
|
+
for (const name2 of namedRequests) {
|
|
28285
|
+
if (surfaceNames.has(name2)) continue;
|
|
28286
|
+
const { message, suggestion } = buildMissingExportMessage(name2, modulePath);
|
|
28287
|
+
errors.push(
|
|
28288
|
+
createError(ErrorCodes.INLINED_IMPORT_MISSING_EXPORT, loc, {
|
|
28289
|
+
message,
|
|
28290
|
+
suggestion: { message: suggestion }
|
|
28291
|
+
})
|
|
28292
|
+
);
|
|
28293
|
+
}
|
|
28294
|
+
}
|
|
28142
28295
|
}
|
|
28143
28296
|
if (namesNeeded.size === 0) {
|
|
28144
28297
|
return {
|
|
@@ -28146,7 +28299,8 @@ function buildTopLevelIIFE(topLevelId, body2, shapesNeeded, originalSource) {
|
|
|
28146
28299
|
${stripped}
|
|
28147
28300
|
return {};
|
|
28148
28301
|
})();`,
|
|
28149
|
-
hoistedImports
|
|
28302
|
+
hoistedImports,
|
|
28303
|
+
errors
|
|
28150
28304
|
};
|
|
28151
28305
|
}
|
|
28152
28306
|
const ret = `{ ${[...namesNeeded].join(", ")} }`;
|
|
@@ -28155,7 +28309,8 @@ return {};
|
|
|
28155
28309
|
${stripped}
|
|
28156
28310
|
return ${ret};
|
|
28157
28311
|
})();`,
|
|
28158
|
-
hoistedImports
|
|
28312
|
+
hoistedImports,
|
|
28313
|
+
errors
|
|
28159
28314
|
};
|
|
28160
28315
|
}
|
|
28161
28316
|
async function resolveSourceFile(importPath, searchDirs) {
|
|
@@ -28204,51 +28359,27 @@ function buildDanglingReferenceMessage(binding, s) {
|
|
|
28204
28359
|
};
|
|
28205
28360
|
}
|
|
28206
28361
|
}
|
|
28207
|
-
function isValueReference(id2) {
|
|
28208
|
-
const parent2 = id2.parent;
|
|
28209
|
-
if (!parent2) return false;
|
|
28210
|
-
if (ts23.isPropertyAccessExpression(parent2) && parent2.name === id2) return false;
|
|
28211
|
-
if (ts23.isPropertyAssignment(parent2) && parent2.name === id2) return false;
|
|
28212
|
-
if ((ts23.isMethodDeclaration(parent2) || ts23.isGetAccessorDeclaration(parent2) || ts23.isSetAccessorDeclaration(parent2)) && parent2.name === id2) {
|
|
28213
|
-
return false;
|
|
28214
|
-
}
|
|
28215
|
-
if (ts23.isVariableDeclaration(parent2) && parent2.name === id2) return false;
|
|
28216
|
-
if (ts23.isFunctionDeclaration(parent2) && parent2.name === id2) return false;
|
|
28217
|
-
if (ts23.isFunctionExpression(parent2) && parent2.name === id2) return false;
|
|
28218
|
-
if (ts23.isClassDeclaration(parent2) && parent2.name === id2) return false;
|
|
28219
|
-
if (ts23.isClassExpression(parent2) && parent2.name === id2) return false;
|
|
28220
|
-
if (ts23.isParameter(parent2) && parent2.name === id2) return false;
|
|
28221
|
-
if (ts23.isBindingElement(parent2) && (parent2.name === id2 || parent2.propertyName === id2)) return false;
|
|
28222
|
-
if (ts23.isLabeledStatement(parent2) && parent2.label === id2) return false;
|
|
28223
|
-
if (ts23.isBreakOrContinueStatement(parent2) && parent2.label === id2) return false;
|
|
28224
|
-
if (ts23.isImportSpecifier(parent2) && (parent2.name === id2 || parent2.propertyName === id2)) return false;
|
|
28225
|
-
if (ts23.isExportSpecifier(parent2) && (parent2.name === id2 || parent2.propertyName === id2)) return false;
|
|
28226
|
-
if (ts23.isImportClause(parent2) && parent2.name === id2) return false;
|
|
28227
|
-
if (ts23.isNamespaceImport(parent2) && parent2.name === id2) return false;
|
|
28228
|
-
if (ts23.isQualifiedName(parent2) && parent2.right === id2) return false;
|
|
28229
|
-
return true;
|
|
28230
|
-
}
|
|
28231
28362
|
function detectStrippedReferences(bundleSource, stripped) {
|
|
28232
28363
|
if (stripped.length === 0) return [];
|
|
28233
28364
|
let sf;
|
|
28234
28365
|
try {
|
|
28235
|
-
sf =
|
|
28366
|
+
sf = ts24.createSourceFile(
|
|
28236
28367
|
"bundle.js",
|
|
28237
28368
|
bundleSource,
|
|
28238
|
-
|
|
28369
|
+
ts24.ScriptTarget.Latest,
|
|
28239
28370
|
/*setParents*/
|
|
28240
28371
|
true,
|
|
28241
|
-
|
|
28372
|
+
ts24.ScriptKind.JS
|
|
28242
28373
|
);
|
|
28243
28374
|
} catch {
|
|
28244
28375
|
return [];
|
|
28245
28376
|
}
|
|
28246
28377
|
const firstReference = /* @__PURE__ */ new Map();
|
|
28247
28378
|
function visit3(node) {
|
|
28248
|
-
if (
|
|
28379
|
+
if (ts24.isIdentifier(node) && isValueReferenceIdentifier(node)) {
|
|
28249
28380
|
if (!firstReference.has(node.text)) firstReference.set(node.text, node);
|
|
28250
28381
|
}
|
|
28251
|
-
|
|
28382
|
+
ts24.forEachChild(node, visit3);
|
|
28252
28383
|
}
|
|
28253
28384
|
visit3(sf);
|
|
28254
28385
|
const errors = [];
|
|
@@ -28278,18 +28409,18 @@ function detectStrippedReferences(bundleSource, stripped) {
|
|
|
28278
28409
|
return errors;
|
|
28279
28410
|
}
|
|
28280
28411
|
async function walkAndCollect(content2, searchDirs, modules2, visiting, loggingPath, stripped, stubDeps, nextId) {
|
|
28281
|
-
const sourceFile =
|
|
28412
|
+
const sourceFile = ts24.createSourceFile(
|
|
28282
28413
|
"walk.js",
|
|
28283
28414
|
content2,
|
|
28284
|
-
|
|
28415
|
+
ts24.ScriptTarget.Latest,
|
|
28285
28416
|
/*setParents*/
|
|
28286
28417
|
false,
|
|
28287
|
-
|
|
28418
|
+
ts24.ScriptKind.JS
|
|
28288
28419
|
);
|
|
28289
28420
|
const sites = [];
|
|
28290
28421
|
for (const stmt of sourceFile.statements) {
|
|
28291
|
-
if (!
|
|
28292
|
-
if (!
|
|
28422
|
+
if (!ts24.isImportDeclaration(stmt)) continue;
|
|
28423
|
+
if (!ts24.isStringLiteral(stmt.moduleSpecifier)) continue;
|
|
28293
28424
|
const spec = stmt.moduleSpecifier.text;
|
|
28294
28425
|
if (!spec.startsWith("./") && !spec.startsWith("../")) continue;
|
|
28295
28426
|
const start2 = stmt.getStart(sourceFile);
|
|
@@ -28438,14 +28569,16 @@ async function inlineRelativeImports(content2, searchDirs, loggingPath, hoistedA
|
|
|
28438
28569
|
const ordered = topoSort(modules2);
|
|
28439
28570
|
const iifes = [];
|
|
28440
28571
|
for (const mod of ordered) {
|
|
28441
|
-
const { wrapped, hoistedImports } = buildTopLevelIIFE(
|
|
28572
|
+
const { wrapped, hoistedImports, errors } = buildTopLevelIIFE(
|
|
28442
28573
|
mod.topLevelId,
|
|
28443
28574
|
mod.transpiledBody,
|
|
28444
28575
|
mod.consumerShapes,
|
|
28445
|
-
mod.originalSource
|
|
28576
|
+
mod.originalSource,
|
|
28577
|
+
mod.path
|
|
28446
28578
|
);
|
|
28447
28579
|
iifes.push(wrapped);
|
|
28448
28580
|
for (const h of hoistedImports) hoistedAcc.push(h);
|
|
28581
|
+
for (const err of errors) errorAcc.push(err);
|
|
28449
28582
|
}
|
|
28450
28583
|
const finalContent = iifes.join("\n") + "\n" + parentContent;
|
|
28451
28584
|
for (const err of detectStrippedReferences(finalContent, stripped)) errorAcc.push(err);
|
|
@@ -28741,7 +28874,7 @@ var init_assets_ignore = __esm({
|
|
|
28741
28874
|
});
|
|
28742
28875
|
|
|
28743
28876
|
// src/lib/runtime-treeshake.ts
|
|
28744
|
-
import
|
|
28877
|
+
import ts25 from "typescript";
|
|
28745
28878
|
import { basename, dirname as dirname3 } from "node:path";
|
|
28746
28879
|
import { build as esbuildBuild } from "esbuild";
|
|
28747
28880
|
function isBarefootClientSpecifier(spec) {
|
|
@@ -28758,13 +28891,13 @@ function collectUsedRuntimeExports(code, sourceLabel = "<input>") {
|
|
|
28758
28891
|
if (!code.includes("@barefootjs/client") && !code.includes("barefoot.js")) return result2;
|
|
28759
28892
|
let sourceFile;
|
|
28760
28893
|
try {
|
|
28761
|
-
sourceFile =
|
|
28894
|
+
sourceFile = ts25.createSourceFile(
|
|
28762
28895
|
sourceLabel,
|
|
28763
28896
|
code,
|
|
28764
|
-
|
|
28897
|
+
ts25.ScriptTarget.Latest,
|
|
28765
28898
|
/*setParentNodes*/
|
|
28766
28899
|
false,
|
|
28767
|
-
|
|
28900
|
+
ts25.ScriptKind.JS
|
|
28768
28901
|
);
|
|
28769
28902
|
} catch (err) {
|
|
28770
28903
|
result2.unsafe = true;
|
|
@@ -28772,13 +28905,13 @@ function collectUsedRuntimeExports(code, sourceLabel = "<input>") {
|
|
|
28772
28905
|
return result2;
|
|
28773
28906
|
}
|
|
28774
28907
|
const visit3 = (node) => {
|
|
28775
|
-
if (
|
|
28908
|
+
if (ts25.isImportDeclaration(node)) {
|
|
28776
28909
|
const spec = node.moduleSpecifier;
|
|
28777
|
-
if (
|
|
28910
|
+
if (ts25.isStringLiteral(spec) && isEmittedRuntimeSpecifier(spec.text)) {
|
|
28778
28911
|
const clause = node.importClause;
|
|
28779
28912
|
if (!clause) {
|
|
28780
28913
|
} else if (clause.isTypeOnly) {
|
|
28781
|
-
} else if (clause.namedBindings &&
|
|
28914
|
+
} else if (clause.namedBindings && ts25.isNamedImports(clause.namedBindings)) {
|
|
28782
28915
|
for (const el of clause.namedBindings.elements) {
|
|
28783
28916
|
if (el.isTypeOnly) continue;
|
|
28784
28917
|
const imported = (el.propertyName ?? el.name).text;
|
|
@@ -28788,7 +28921,7 @@ function collectUsedRuntimeExports(code, sourceLabel = "<input>") {
|
|
|
28788
28921
|
result2.unsafe = true;
|
|
28789
28922
|
result2.reasons.push(`default import of "${spec.text}" in ${sourceLabel}`);
|
|
28790
28923
|
}
|
|
28791
|
-
} else if (clause.namedBindings &&
|
|
28924
|
+
} else if (clause.namedBindings && ts25.isNamespaceImport(clause.namedBindings)) {
|
|
28792
28925
|
result2.unsafe = true;
|
|
28793
28926
|
result2.reasons.push(`namespace import (* as ${clause.namedBindings.name.text}) of "${spec.text}" in ${sourceLabel}`);
|
|
28794
28927
|
} else if (clause.name) {
|
|
@@ -28796,14 +28929,14 @@ function collectUsedRuntimeExports(code, sourceLabel = "<input>") {
|
|
|
28796
28929
|
result2.reasons.push(`default import of "${spec.text}" in ${sourceLabel}`);
|
|
28797
28930
|
}
|
|
28798
28931
|
}
|
|
28799
|
-
} else if (
|
|
28932
|
+
} else if (ts25.isCallExpression(node) && node.expression.kind === ts25.SyntaxKind.ImportKeyword) {
|
|
28800
28933
|
const arg = node.arguments[0];
|
|
28801
|
-
if (arg &&
|
|
28934
|
+
if (arg && ts25.isStringLiteral(arg) && isEmittedRuntimeSpecifier(arg.text)) {
|
|
28802
28935
|
result2.unsafe = true;
|
|
28803
28936
|
result2.reasons.push(`dynamic import("${arg.text}") in ${sourceLabel}`);
|
|
28804
28937
|
}
|
|
28805
28938
|
}
|
|
28806
|
-
|
|
28939
|
+
ts25.forEachChild(node, visit3);
|
|
28807
28940
|
};
|
|
28808
28941
|
visit3(sourceFile);
|
|
28809
28942
|
return result2;
|
|
@@ -28876,7 +29009,7 @@ var init_runtime_treeshake = __esm({
|
|
|
28876
29009
|
});
|
|
28877
29010
|
|
|
28878
29011
|
// src/lib/build.ts
|
|
28879
|
-
import
|
|
29012
|
+
import ts26 from "typescript";
|
|
28880
29013
|
import { mkdir, readdir, stat, unlink } from "node:fs/promises";
|
|
28881
29014
|
import { resolve as resolve6, basename as basename2, relative as relative2, dirname as dirname4, isAbsolute as isAbsolute2 } from "node:path";
|
|
28882
29015
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
@@ -29524,7 +29657,7 @@ async function build(config, options2 = {}) {
|
|
|
29524
29657
|
};
|
|
29525
29658
|
}
|
|
29526
29659
|
function extractBareImports(code) {
|
|
29527
|
-
const { importedFiles } =
|
|
29660
|
+
const { importedFiles } = ts26.preProcessFile(code, true, true);
|
|
29528
29661
|
const specifiers = /* @__PURE__ */ new Set();
|
|
29529
29662
|
for (const { fileName } of importedFiles) {
|
|
29530
29663
|
if (!fileName.startsWith(".") && !fileName.startsWith("/") && !fileName.includes("://")) {
|
|
@@ -29591,16 +29724,16 @@ function effectiveOutName(tplPath, entryBaseNoExt) {
|
|
|
29591
29724
|
}
|
|
29592
29725
|
function topLevelImportLines(content2) {
|
|
29593
29726
|
const lines = /* @__PURE__ */ new Set();
|
|
29594
|
-
const sourceFile =
|
|
29727
|
+
const sourceFile = ts26.createSourceFile(
|
|
29595
29728
|
"merge.js",
|
|
29596
29729
|
content2,
|
|
29597
|
-
|
|
29730
|
+
ts26.ScriptTarget.Latest,
|
|
29598
29731
|
/*setParentNodes*/
|
|
29599
29732
|
true,
|
|
29600
|
-
|
|
29733
|
+
ts26.ScriptKind.JS
|
|
29601
29734
|
);
|
|
29602
29735
|
for (const stmt of sourceFile.statements) {
|
|
29603
|
-
if (
|
|
29736
|
+
if (ts26.isImportDeclaration(stmt)) {
|
|
29604
29737
|
const { line } = sourceFile.getLineAndCharacterOfPosition(stmt.getStart(sourceFile));
|
|
29605
29738
|
lines.add(line);
|
|
29606
29739
|
}
|
|
@@ -29609,29 +29742,29 @@ function topLevelImportLines(content2) {
|
|
|
29609
29742
|
}
|
|
29610
29743
|
function rewriteBarefootClientSpecifiers(content2, rel) {
|
|
29611
29744
|
if (!content2.includes("@barefootjs/client")) return content2;
|
|
29612
|
-
const sourceFile =
|
|
29745
|
+
const sourceFile = ts26.createSourceFile(
|
|
29613
29746
|
"client.js",
|
|
29614
29747
|
content2,
|
|
29615
|
-
|
|
29748
|
+
ts26.ScriptTarget.Latest,
|
|
29616
29749
|
/*setParentNodes*/
|
|
29617
29750
|
true,
|
|
29618
|
-
|
|
29751
|
+
ts26.ScriptKind.JS
|
|
29619
29752
|
);
|
|
29620
29753
|
const isBarefootClient = (s) => s === "@barefootjs/client" || s.startsWith("@barefootjs/client/");
|
|
29621
29754
|
const spans = [];
|
|
29622
29755
|
const visit3 = (node) => {
|
|
29623
|
-
if (
|
|
29756
|
+
if (ts26.isImportDeclaration(node) || ts26.isExportDeclaration(node)) {
|
|
29624
29757
|
const ms = node.moduleSpecifier;
|
|
29625
|
-
if (ms &&
|
|
29758
|
+
if (ms && ts26.isStringLiteral(ms) && isBarefootClient(ms.text)) {
|
|
29626
29759
|
spans.push([ms.getStart(sourceFile), ms.getEnd()]);
|
|
29627
29760
|
}
|
|
29628
|
-
} else if (
|
|
29761
|
+
} else if (ts26.isCallExpression(node) && node.expression.kind === ts26.SyntaxKind.ImportKeyword) {
|
|
29629
29762
|
const arg = node.arguments[0];
|
|
29630
|
-
if (arg &&
|
|
29763
|
+
if (arg && ts26.isStringLiteral(arg) && isBarefootClient(arg.text)) {
|
|
29631
29764
|
spans.push([arg.getStart(sourceFile), arg.getEnd()]);
|
|
29632
29765
|
}
|
|
29633
29766
|
}
|
|
29634
|
-
|
|
29767
|
+
ts26.forEachChild(node, visit3);
|
|
29635
29768
|
};
|
|
29636
29769
|
visit3(sourceFile);
|
|
29637
29770
|
if (spans.length === 0) return content2;
|
|
@@ -110894,7 +111027,7 @@ __export(scenario_driver_exports, {
|
|
|
110894
111027
|
import { writeFileSync as writeFileSync9, mkdtempSync, rmSync, readFileSync as readFileSync19, existsSync as existsSync23, statSync as statSync3 } from "node:fs";
|
|
110895
111028
|
import { join as join2, dirname as dirname7, resolve as resolve11 } from "node:path";
|
|
110896
111029
|
import { tmpdir } from "node:os";
|
|
110897
|
-
import
|
|
111030
|
+
import ts27 from "typescript";
|
|
110898
111031
|
function externalRuntimeImport(clientJs) {
|
|
110899
111032
|
const chunks = Array.isArray(clientJs) ? clientJs : [clientJs];
|
|
110900
111033
|
for (const chunk of chunks) {
|
|
@@ -110964,11 +111097,11 @@ function resolveLocalFile(spec) {
|
|
|
110964
111097
|
}
|
|
110965
111098
|
function rewriteLocalImports(js, chunkPath, inlined) {
|
|
110966
111099
|
const chunkDir = dirname7(chunkPath);
|
|
110967
|
-
const sf =
|
|
111100
|
+
const sf = ts27.createSourceFile("chunk.mjs", js, ts27.ScriptTarget.Latest, false, ts27.ScriptKind.JS);
|
|
110968
111101
|
const edits = [];
|
|
110969
111102
|
for (const stmt of sf.statements) {
|
|
110970
|
-
if (!
|
|
110971
|
-
if (!
|
|
111103
|
+
if (!ts27.isImportDeclaration(stmt)) continue;
|
|
111104
|
+
if (!ts27.isStringLiteral(stmt.moduleSpecifier)) continue;
|
|
110972
111105
|
const spec = stmt.moduleSpecifier.text;
|
|
110973
111106
|
if (!spec.startsWith(".")) continue;
|
|
110974
111107
|
const resolved = resolveLocalFile(join2(chunkDir, spec.replace(/\.client\.js$/, "")));
|
|
@@ -110980,13 +111113,13 @@ function rewriteLocalImports(js, chunkPath, inlined) {
|
|
|
110980
111113
|
const abs = resolve11(resolved);
|
|
110981
111114
|
if (inlined.has(abs)) {
|
|
110982
111115
|
const clause = stmt.importClause;
|
|
110983
|
-
if (clause && (clause.name || clause.namedBindings &&
|
|
111116
|
+
if (clause && (clause.name || clause.namedBindings && ts27.isNamespaceImport(clause.namedBindings))) {
|
|
110984
111117
|
throw new Error(
|
|
110985
111118
|
`"${spec}" (imported by ${chunkPath}) uses a default or namespace import of a sibling client file, which the dynamic scenario runner cannot bind after inlining that file into the run. Import its exports by name, or use the static budget (\`bf debug profile <component>\`), which needs no run.`
|
|
110986
111119
|
);
|
|
110987
111120
|
}
|
|
110988
111121
|
const shims = [];
|
|
110989
|
-
if (clause?.namedBindings &&
|
|
111122
|
+
if (clause?.namedBindings && ts27.isNamedImports(clause.namedBindings)) {
|
|
110990
111123
|
for (const el of clause.namedBindings.elements) {
|
|
110991
111124
|
if (el.propertyName) shims.push(`var ${el.name.text} = ${el.propertyName.text}`);
|
|
110992
111125
|
}
|
|
@@ -111495,9 +111628,9 @@ function findProjectConfig(startDir) {
|
|
|
111495
111628
|
let dir = path.resolve(startDir);
|
|
111496
111629
|
const { root: fsRoot } = path.parse(dir);
|
|
111497
111630
|
while (true) {
|
|
111498
|
-
const
|
|
111499
|
-
if (existsSync2(
|
|
111500
|
-
return { dir, tsConfigPath:
|
|
111631
|
+
const ts28 = path.join(dir, "barefoot.config.ts");
|
|
111632
|
+
if (existsSync2(ts28)) {
|
|
111633
|
+
return { dir, tsConfigPath: ts28 };
|
|
111501
111634
|
}
|
|
111502
111635
|
if (dir === fsRoot) return null;
|
|
111503
111636
|
dir = path.dirname(dir);
|