@barefootjs/jsx 0.28.0 → 0.28.1
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/analyzer.d.ts.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/errors.d.ts +1 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +335 -247
- package/dist/ir-to-client-js/imports.d.ts +24 -0
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/value-references.d.ts +48 -0
- package/dist/value-references.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/ir-to-client-js/imports.test.ts +98 -1
- package/src/__tests__/type-only-import-leak.test.ts +60 -0
- package/src/analyzer.ts +3 -0
- package/src/compiler.ts +6 -2
- package/src/errors.ts +11 -0
- package/src/index.ts +4 -0
- package/src/ir-to-client-js/imports.ts +45 -2
- package/src/value-references.ts +108 -0
package/dist/index.js
CHANGED
|
@@ -5367,6 +5367,7 @@ var ErrorCodes = {
|
|
|
5367
5367
|
SHARED_PROGRAM_REQUIRED: "BF050",
|
|
5368
5368
|
WRONG_PACKAGE_IMPORT: "BF051",
|
|
5369
5369
|
BUILTIN_REQUIRES_IMPORT: "BF054",
|
|
5370
|
+
INLINED_IMPORT_MISSING_EXPORT: "BF055",
|
|
5370
5371
|
UNDECLARED_INIT_STATEMENT_REFERENCE: "BF052",
|
|
5371
5372
|
STRIPPED_CLIENT_IMPORT_REFERENCED: "BF053",
|
|
5372
5373
|
STAGE_REACTIVE_IN_TEMPLATE: "BF060",
|
|
@@ -5397,6 +5398,7 @@ var errorMessages = {
|
|
|
5397
5398
|
[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.",
|
|
5398
5399
|
[ErrorCodes.UNDECLARED_INIT_STATEMENT_REFERENCE]: "Init statement references an undeclared identifier. Declare it at module scope, inside the component, or import it — otherwise ESM strict mode throws ReferenceError at runtime.",
|
|
5399
5400
|
[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 — 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.",
|
|
5401
|
+
[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.",
|
|
5400
5402
|
[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.",
|
|
5401
5403
|
[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.",
|
|
5402
5404
|
[ErrorCodes.STAGE_AWAIT_IN_TEMPLATE]: "AwaitExpression in template scope. The generated template and init functions are synchronous — 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.",
|
|
@@ -7931,6 +7933,8 @@ function importsBrowserOnlyClientApi(ctx) {
|
|
|
7931
7933
|
if (imp.isTypeOnly)
|
|
7932
7934
|
continue;
|
|
7933
7935
|
for (const spec of imp.specifiers) {
|
|
7936
|
+
if (spec.isTypeOnly)
|
|
7937
|
+
continue;
|
|
7934
7938
|
const importedName = spec.name;
|
|
7935
7939
|
if (BROWSER_ONLY_CLIENT_APIS.has(importedName))
|
|
7936
7940
|
return true;
|
|
@@ -15279,6 +15283,70 @@ function propHasPropertyAccess(u) {
|
|
|
15279
15283
|
return u.accessKinds.has("property") || u.accessKinds.has("index");
|
|
15280
15284
|
}
|
|
15281
15285
|
|
|
15286
|
+
// src/value-references.ts
|
|
15287
|
+
import ts13 from "typescript";
|
|
15288
|
+
function isValueReferenceIdentifier(id) {
|
|
15289
|
+
const parent = id.parent;
|
|
15290
|
+
if (!parent)
|
|
15291
|
+
return false;
|
|
15292
|
+
if (ts13.isPropertyAccessExpression(parent) && parent.name === id)
|
|
15293
|
+
return false;
|
|
15294
|
+
if (ts13.isPropertyAssignment(parent) && parent.name === id)
|
|
15295
|
+
return false;
|
|
15296
|
+
if ((ts13.isMethodDeclaration(parent) || ts13.isGetAccessorDeclaration(parent) || ts13.isSetAccessorDeclaration(parent)) && parent.name === id) {
|
|
15297
|
+
return false;
|
|
15298
|
+
}
|
|
15299
|
+
if (ts13.isVariableDeclaration(parent) && parent.name === id)
|
|
15300
|
+
return false;
|
|
15301
|
+
if (ts13.isFunctionDeclaration(parent) && parent.name === id)
|
|
15302
|
+
return false;
|
|
15303
|
+
if (ts13.isFunctionExpression(parent) && parent.name === id)
|
|
15304
|
+
return false;
|
|
15305
|
+
if (ts13.isClassDeclaration(parent) && parent.name === id)
|
|
15306
|
+
return false;
|
|
15307
|
+
if (ts13.isClassExpression(parent) && parent.name === id)
|
|
15308
|
+
return false;
|
|
15309
|
+
if (ts13.isParameter(parent) && parent.name === id)
|
|
15310
|
+
return false;
|
|
15311
|
+
if (ts13.isBindingElement(parent) && (parent.name === id || parent.propertyName === id))
|
|
15312
|
+
return false;
|
|
15313
|
+
if (ts13.isLabeledStatement(parent) && parent.label === id)
|
|
15314
|
+
return false;
|
|
15315
|
+
if (ts13.isBreakOrContinueStatement(parent) && parent.label === id)
|
|
15316
|
+
return false;
|
|
15317
|
+
if (ts13.isImportSpecifier(parent) && (parent.name === id || parent.propertyName === id))
|
|
15318
|
+
return false;
|
|
15319
|
+
if (ts13.isExportSpecifier(parent) && (parent.name === id || parent.propertyName === id))
|
|
15320
|
+
return false;
|
|
15321
|
+
if (ts13.isImportClause(parent) && parent.name === id)
|
|
15322
|
+
return false;
|
|
15323
|
+
if (ts13.isNamespaceImport(parent) && parent.name === id)
|
|
15324
|
+
return false;
|
|
15325
|
+
if (ts13.isQualifiedName(parent) && parent.right === id)
|
|
15326
|
+
return false;
|
|
15327
|
+
return true;
|
|
15328
|
+
}
|
|
15329
|
+
function collectValueReferencedNames(code) {
|
|
15330
|
+
let sourceFile;
|
|
15331
|
+
try {
|
|
15332
|
+
sourceFile = ts13.createSourceFile("generated.js", code, ts13.ScriptTarget.Latest, true, ts13.ScriptKind.JS);
|
|
15333
|
+
} catch {
|
|
15334
|
+
return null;
|
|
15335
|
+
}
|
|
15336
|
+
const diagnostics = sourceFile.parseDiagnostics;
|
|
15337
|
+
if (diagnostics && diagnostics.length > 0)
|
|
15338
|
+
return null;
|
|
15339
|
+
const names = new Set;
|
|
15340
|
+
function visit3(node) {
|
|
15341
|
+
if (ts13.isIdentifier(node) && isValueReferenceIdentifier(node)) {
|
|
15342
|
+
names.add(node.text);
|
|
15343
|
+
}
|
|
15344
|
+
ts13.forEachChild(node, visit3);
|
|
15345
|
+
}
|
|
15346
|
+
visit3(sourceFile);
|
|
15347
|
+
return names;
|
|
15348
|
+
}
|
|
15349
|
+
|
|
15282
15350
|
// src/ir-to-client-js/imports.ts
|
|
15283
15351
|
var RUNTIME_IMPORT_CANDIDATES = [
|
|
15284
15352
|
"createSignal",
|
|
@@ -15357,7 +15425,7 @@ function collectUserDomImports(ir) {
|
|
|
15357
15425
|
for (const imp of ir.metadata.imports) {
|
|
15358
15426
|
if (runtimeSources.has(imp.source) && !imp.isTypeOnly) {
|
|
15359
15427
|
for (const spec of imp.specifiers) {
|
|
15360
|
-
if (!spec.isDefault && !spec.isNamespace) {
|
|
15428
|
+
if (!spec.isDefault && !spec.isNamespace && !spec.isTypeOnly) {
|
|
15361
15429
|
if (isClientBuiltinName(spec.name))
|
|
15362
15430
|
continue;
|
|
15363
15431
|
userImports.push(spec.alias ? `${spec.name} as ${spec.alias}` : spec.name);
|
|
@@ -15367,9 +15435,22 @@ function collectUserDomImports(ir) {
|
|
|
15367
15435
|
}
|
|
15368
15436
|
return userImports;
|
|
15369
15437
|
}
|
|
15438
|
+
function makeValueUsageTest(generatedCode) {
|
|
15439
|
+
let referenced;
|
|
15440
|
+
return (localName) => {
|
|
15441
|
+
if (referenced === undefined) {
|
|
15442
|
+
referenced = collectValueReferencedNames(generatedCode);
|
|
15443
|
+
}
|
|
15444
|
+
if (referenced !== null) {
|
|
15445
|
+
return referenced.has(localName);
|
|
15446
|
+
}
|
|
15447
|
+
return generatedCode.includes(localName);
|
|
15448
|
+
};
|
|
15449
|
+
}
|
|
15370
15450
|
function collectExternalImports(ir, generatedCode, localImportPrefixes) {
|
|
15371
15451
|
const componentNames = collectComponentNames(ir.root);
|
|
15372
15452
|
const importLines = [];
|
|
15453
|
+
const isUsedAsValue = makeValueUsageTest(generatedCode);
|
|
15373
15454
|
for (const imp of ir.metadata.imports) {
|
|
15374
15455
|
if (imp.isTypeOnly)
|
|
15375
15456
|
continue;
|
|
@@ -15383,10 +15464,12 @@ function collectExternalImports(ir, generatedCode, localImportPrefixes) {
|
|
|
15383
15464
|
}
|
|
15384
15465
|
const usedSpecs = [];
|
|
15385
15466
|
for (const spec of imp.specifiers) {
|
|
15467
|
+
if (spec.isTypeOnly)
|
|
15468
|
+
continue;
|
|
15386
15469
|
const localName = spec.alias || spec.name;
|
|
15387
15470
|
if (componentNames.has(localName))
|
|
15388
15471
|
continue;
|
|
15389
|
-
if (
|
|
15472
|
+
if (isUsedAsValue(localName)) {
|
|
15390
15473
|
usedSpecs.push(spec.alias ? `${spec.name} as ${spec.alias}` : spec.name);
|
|
15391
15474
|
}
|
|
15392
15475
|
}
|
|
@@ -15425,7 +15508,7 @@ function collectComponentNames(node) {
|
|
|
15425
15508
|
}
|
|
15426
15509
|
|
|
15427
15510
|
// src/relocate.ts
|
|
15428
|
-
import
|
|
15511
|
+
import ts14 from "typescript";
|
|
15429
15512
|
|
|
15430
15513
|
// src/lowering-registry.ts
|
|
15431
15514
|
var plugins = [];
|
|
@@ -15471,19 +15554,19 @@ function classify(name, env) {
|
|
|
15471
15554
|
function collectFreeRefs(node) {
|
|
15472
15555
|
const refs = new Map;
|
|
15473
15556
|
function visit3(n, parent) {
|
|
15474
|
-
if (
|
|
15475
|
-
if (parent &&
|
|
15557
|
+
if (ts14.isIdentifier(n)) {
|
|
15558
|
+
if (parent && ts14.isPropertyAccessExpression(parent) && parent.name === n)
|
|
15476
15559
|
return;
|
|
15477
|
-
if (parent &&
|
|
15560
|
+
if (parent && ts14.isPropertyAssignment(parent) && parent.name === n)
|
|
15478
15561
|
return;
|
|
15479
|
-
if (parent &&
|
|
15562
|
+
if (parent && ts14.isShorthandPropertyAssignment(parent) && parent.name === n)
|
|
15480
15563
|
return;
|
|
15481
15564
|
const list = refs.get(n.text) ?? [];
|
|
15482
15565
|
list.push(n);
|
|
15483
15566
|
refs.set(n.text, list);
|
|
15484
15567
|
return;
|
|
15485
15568
|
}
|
|
15486
|
-
|
|
15569
|
+
ts14.forEachChild(n, (child) => visit3(child, n));
|
|
15487
15570
|
}
|
|
15488
15571
|
visit3(node);
|
|
15489
15572
|
return refs;
|
|
@@ -15586,11 +15669,11 @@ function isInlinableInTemplate(value, env) {
|
|
|
15586
15669
|
return { ok: true, rewrittenValue: r.text, decisions: r.decisions };
|
|
15587
15670
|
}
|
|
15588
15671
|
function getCalleeIdentifierPath(callee) {
|
|
15589
|
-
if (
|
|
15672
|
+
if (ts14.isParenthesizedExpression(callee))
|
|
15590
15673
|
return getCalleeIdentifierPath(callee.expression);
|
|
15591
|
-
if (
|
|
15674
|
+
if (ts14.isIdentifier(callee))
|
|
15592
15675
|
return callee.text;
|
|
15593
|
-
if (
|
|
15676
|
+
if (ts14.isPropertyAccessExpression(callee)) {
|
|
15594
15677
|
const left = getCalleeIdentifierPath(callee.expression);
|
|
15595
15678
|
if (left === null)
|
|
15596
15679
|
return null;
|
|
@@ -15599,11 +15682,11 @@ function getCalleeIdentifierPath(callee) {
|
|
|
15599
15682
|
return null;
|
|
15600
15683
|
}
|
|
15601
15684
|
function getCalleeLeftmostIdentifier(callee) {
|
|
15602
|
-
if (
|
|
15685
|
+
if (ts14.isParenthesizedExpression(callee))
|
|
15603
15686
|
return getCalleeLeftmostIdentifier(callee.expression);
|
|
15604
|
-
if (
|
|
15687
|
+
if (ts14.isIdentifier(callee))
|
|
15605
15688
|
return callee.text;
|
|
15606
|
-
if (
|
|
15689
|
+
if (ts14.isPropertyAccessExpression(callee)) {
|
|
15607
15690
|
return getCalleeLeftmostIdentifier(callee.expression);
|
|
15608
15691
|
}
|
|
15609
15692
|
return null;
|
|
@@ -15651,12 +15734,12 @@ function isCallAcceptedByAdapter(call, env) {
|
|
|
15651
15734
|
}
|
|
15652
15735
|
function parseExpressionNode(text) {
|
|
15653
15736
|
try {
|
|
15654
|
-
const sf =
|
|
15737
|
+
const sf = ts14.createSourceFile("__inline_check__.ts", `(${text});`, ts14.ScriptTarget.Latest, false, ts14.ScriptKind.TS);
|
|
15655
15738
|
const stmt = sf.statements[0];
|
|
15656
|
-
if (!stmt || !
|
|
15739
|
+
if (!stmt || !ts14.isExpressionStatement(stmt))
|
|
15657
15740
|
return null;
|
|
15658
15741
|
const inner = stmt.expression;
|
|
15659
|
-
return
|
|
15742
|
+
return ts14.isParenthesizedExpression(inner) ? inner.expression : inner;
|
|
15660
15743
|
} catch {
|
|
15661
15744
|
return null;
|
|
15662
15745
|
}
|
|
@@ -15673,8 +15756,8 @@ function hasCallWithBridgedArg(node, decisions, env) {
|
|
|
15673
15756
|
function visit3(n) {
|
|
15674
15757
|
if (found)
|
|
15675
15758
|
return;
|
|
15676
|
-
if (
|
|
15677
|
-
const accepted =
|
|
15759
|
+
if (ts14.isCallExpression(n) || ts14.isNewExpression(n)) {
|
|
15760
|
+
const accepted = ts14.isCallExpression(n) && isCallAcceptedByAdapter(n, env);
|
|
15678
15761
|
if (!accepted) {
|
|
15679
15762
|
const args = n.arguments;
|
|
15680
15763
|
if (args) {
|
|
@@ -15687,7 +15770,7 @@ function hasCallWithBridgedArg(node, decisions, env) {
|
|
|
15687
15770
|
}
|
|
15688
15771
|
}
|
|
15689
15772
|
}
|
|
15690
|
-
|
|
15773
|
+
ts14.forEachChild(n, visit3);
|
|
15691
15774
|
}
|
|
15692
15775
|
visit3(node);
|
|
15693
15776
|
return found;
|
|
@@ -15697,13 +15780,13 @@ function hasZeroArgCall(node, env) {
|
|
|
15697
15780
|
function visit3(n) {
|
|
15698
15781
|
if (found)
|
|
15699
15782
|
return;
|
|
15700
|
-
if (
|
|
15783
|
+
if (ts14.isCallExpression(n) && n.arguments.length === 0) {
|
|
15701
15784
|
if (!isCallAcceptedByAdapter(n, env)) {
|
|
15702
15785
|
found = true;
|
|
15703
15786
|
return;
|
|
15704
15787
|
}
|
|
15705
15788
|
}
|
|
15706
|
-
|
|
15789
|
+
ts14.forEachChild(n, visit3);
|
|
15707
15790
|
}
|
|
15708
15791
|
visit3(node);
|
|
15709
15792
|
return found;
|
|
@@ -15713,25 +15796,25 @@ function containsAnyIdentifier(node, names) {
|
|
|
15713
15796
|
function visit3(n) {
|
|
15714
15797
|
if (found)
|
|
15715
15798
|
return;
|
|
15716
|
-
if (
|
|
15799
|
+
if (ts14.isPropertyAccessExpression(n)) {
|
|
15717
15800
|
visit3(n.expression);
|
|
15718
15801
|
return;
|
|
15719
15802
|
}
|
|
15720
|
-
if (
|
|
15803
|
+
if (ts14.isPropertyAssignment(n)) {
|
|
15721
15804
|
visit3(n.initializer);
|
|
15722
15805
|
return;
|
|
15723
15806
|
}
|
|
15724
|
-
if (
|
|
15725
|
-
if (
|
|
15807
|
+
if (ts14.isShorthandPropertyAssignment(n)) {
|
|
15808
|
+
if (ts14.isIdentifier(n.name) && names.has(n.name.text)) {
|
|
15726
15809
|
found = true;
|
|
15727
15810
|
}
|
|
15728
15811
|
return;
|
|
15729
15812
|
}
|
|
15730
|
-
if (
|
|
15813
|
+
if (ts14.isIdentifier(n) && names.has(n.text)) {
|
|
15731
15814
|
found = true;
|
|
15732
15815
|
return;
|
|
15733
15816
|
}
|
|
15734
|
-
|
|
15817
|
+
ts14.forEachChild(n, visit3);
|
|
15735
15818
|
}
|
|
15736
15819
|
visit3(node);
|
|
15737
15820
|
return found;
|
|
@@ -18854,7 +18937,7 @@ function buildArmBody(branch, options) {
|
|
|
18854
18937
|
}
|
|
18855
18938
|
|
|
18856
18939
|
// src/ir-to-client-js/emit-reactive.ts
|
|
18857
|
-
import
|
|
18940
|
+
import ts15 from "typescript";
|
|
18858
18941
|
|
|
18859
18942
|
// src/ir-to-client-js/control-flow/stringify/claim-plan.ts
|
|
18860
18943
|
function slotSpecLiteral(slot) {
|
|
@@ -18957,20 +19040,20 @@ function lowerToLocaleCallsInReactiveExpr(expr, matcher) {
|
|
|
18957
19040
|
return expr;
|
|
18958
19041
|
let sourceFile;
|
|
18959
19042
|
try {
|
|
18960
|
-
sourceFile =
|
|
19043
|
+
sourceFile = ts15.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts15.ScriptTarget.Latest, true, ts15.ScriptKind.TS);
|
|
18961
19044
|
} catch {
|
|
18962
19045
|
return expr;
|
|
18963
19046
|
}
|
|
18964
19047
|
const stmt = sourceFile.statements[0];
|
|
18965
|
-
if (!stmt || !
|
|
19048
|
+
if (!stmt || !ts15.isExpressionStatement(stmt))
|
|
18966
19049
|
return expr;
|
|
18967
|
-
const root =
|
|
19050
|
+
const root = ts15.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
18968
19051
|
const candidates = [];
|
|
18969
19052
|
const visit3 = (n) => {
|
|
18970
|
-
if (
|
|
19053
|
+
if (ts15.isCallExpression(n) && n.arguments.length === 2 && ts15.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && n.expression.name.text === "toLocaleDateString") {
|
|
18971
19054
|
candidates.push(n);
|
|
18972
19055
|
}
|
|
18973
|
-
|
|
19056
|
+
ts15.forEachChild(n, visit3);
|
|
18974
19057
|
};
|
|
18975
19058
|
visit3(root);
|
|
18976
19059
|
if (candidates.length === 0)
|
|
@@ -19006,20 +19089,20 @@ function lowerDateCallsInReactiveExpr(expr, matcher) {
|
|
|
19006
19089
|
return expr;
|
|
19007
19090
|
let sourceFile;
|
|
19008
19091
|
try {
|
|
19009
|
-
sourceFile =
|
|
19092
|
+
sourceFile = ts15.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts15.ScriptTarget.Latest, true, ts15.ScriptKind.TS);
|
|
19010
19093
|
} catch {
|
|
19011
19094
|
return expr;
|
|
19012
19095
|
}
|
|
19013
19096
|
const stmt = sourceFile.statements[0];
|
|
19014
|
-
if (!stmt || !
|
|
19097
|
+
if (!stmt || !ts15.isExpressionStatement(stmt))
|
|
19015
19098
|
return expr;
|
|
19016
|
-
const root =
|
|
19099
|
+
const root = ts15.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
19017
19100
|
const candidates = [];
|
|
19018
19101
|
const visit3 = (n) => {
|
|
19019
|
-
if (
|
|
19102
|
+
if (ts15.isCallExpression(n) && n.arguments.length === 0 && ts15.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
|
|
19020
19103
|
candidates.push(n);
|
|
19021
19104
|
}
|
|
19022
|
-
|
|
19105
|
+
ts15.forEachChild(n, visit3);
|
|
19023
19106
|
};
|
|
19024
19107
|
visit3(root);
|
|
19025
19108
|
if (candidates.length === 0)
|
|
@@ -20974,20 +21057,20 @@ var PHASES = [
|
|
|
20974
21057
|
];
|
|
20975
21058
|
|
|
20976
21059
|
// src/ir-to-client-js/rewrite-props-object.ts
|
|
20977
|
-
import
|
|
21060
|
+
import ts16 from "typescript";
|
|
20978
21061
|
function rewritePropsObjectRef(code, propsObjectName) {
|
|
20979
21062
|
const srcPropsName = propsObjectName ?? "props";
|
|
20980
21063
|
if (srcPropsName === PROPS_PARAM)
|
|
20981
21064
|
return code;
|
|
20982
21065
|
if (!new RegExp(`\\b${srcPropsName}\\b`).test(code))
|
|
20983
21066
|
return code;
|
|
20984
|
-
const sourceFile =
|
|
21067
|
+
const sourceFile = ts16.createSourceFile("init-body.ts", code, ts16.ScriptTarget.Latest, true, ts16.ScriptKind.TS);
|
|
20985
21068
|
const spans = [];
|
|
20986
21069
|
function visit3(node) {
|
|
20987
|
-
if (
|
|
21070
|
+
if (ts16.isIdentifier(node) && node.text === srcPropsName && shouldRewrite(node)) {
|
|
20988
21071
|
spans.push([node.getStart(sourceFile), node.getEnd()]);
|
|
20989
21072
|
}
|
|
20990
|
-
|
|
21073
|
+
ts16.forEachChild(node, visit3);
|
|
20991
21074
|
}
|
|
20992
21075
|
visit3(sourceFile);
|
|
20993
21076
|
if (spans.length === 0)
|
|
@@ -21003,17 +21086,17 @@ function shouldRewrite(node) {
|
|
|
21003
21086
|
const parent = node.parent;
|
|
21004
21087
|
if (!parent)
|
|
21005
21088
|
return true;
|
|
21006
|
-
if (
|
|
21089
|
+
if (ts16.isPropertyAccessExpression(parent) && parent.name === node)
|
|
21007
21090
|
return false;
|
|
21008
|
-
if (
|
|
21091
|
+
if (ts16.isPropertyAssignment(parent) && parent.name === node)
|
|
21009
21092
|
return false;
|
|
21010
|
-
if (
|
|
21093
|
+
if (ts16.isShorthandPropertyAssignment(parent) && parent.name === node)
|
|
21011
21094
|
return false;
|
|
21012
|
-
if (
|
|
21095
|
+
if (ts16.isPropertySignature(parent) && parent.name === node)
|
|
21013
21096
|
return false;
|
|
21014
|
-
if (
|
|
21097
|
+
if (ts16.isPropertyDeclaration(parent) && parent.name === node)
|
|
21015
21098
|
return false;
|
|
21016
|
-
if (
|
|
21099
|
+
if (ts16.isBindingElement(parent) && parent.name === node)
|
|
21017
21100
|
return false;
|
|
21018
21101
|
return true;
|
|
21019
21102
|
}
|
|
@@ -21643,7 +21726,7 @@ function walkIR2(node, visitor) {
|
|
|
21643
21726
|
}
|
|
21644
21727
|
|
|
21645
21728
|
// src/preprocess-inline-jsx-callbacks.ts
|
|
21646
|
-
import
|
|
21729
|
+
import ts17 from "typescript";
|
|
21647
21730
|
var SYNTHETIC_PREFIX = "BFInlineJsxCallback";
|
|
21648
21731
|
var MAX_FIXPOINT_ITERATIONS = 16;
|
|
21649
21732
|
function preprocessInlineJsxCallbacks(source, filePath) {
|
|
@@ -21665,8 +21748,8 @@ function preprocessInlineJsxCallbacks(source, filePath) {
|
|
|
21665
21748
|
return { source: current, errors, syntheticNames };
|
|
21666
21749
|
}
|
|
21667
21750
|
function runSinglePass(source, filePath, startingCounter) {
|
|
21668
|
-
const sourceFile =
|
|
21669
|
-
const hasUseClient = sourceFile.statements.some((stmt) =>
|
|
21751
|
+
const sourceFile = ts17.createSourceFile(filePath, source, ts17.ScriptTarget.Latest, true, ts17.ScriptKind.TSX);
|
|
21752
|
+
const hasUseClient = sourceFile.statements.some((stmt) => ts17.isExpressionStatement(stmt) && ts17.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'"));
|
|
21670
21753
|
if (!hasUseClient) {
|
|
21671
21754
|
return { source, errors: [], syntheticNames: [], counterAfter: startingCounter };
|
|
21672
21755
|
}
|
|
@@ -21688,22 +21771,22 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
21688
21771
|
}
|
|
21689
21772
|
}
|
|
21690
21773
|
function visit3(node) {
|
|
21691
|
-
if (
|
|
21774
|
+
if (ts17.isJsxAttribute(node) && node.initializer && ts17.isJsxExpression(node.initializer) && node.initializer.expression) {
|
|
21692
21775
|
if (tryHandleArrowValue(node.initializer.expression)) {
|
|
21693
21776
|
return;
|
|
21694
21777
|
}
|
|
21695
21778
|
}
|
|
21696
|
-
if (
|
|
21779
|
+
if (ts17.isPropertyAssignment(node) && node.initializer) {
|
|
21697
21780
|
if (tryHandleArrowValue(node.initializer))
|
|
21698
21781
|
return;
|
|
21699
21782
|
}
|
|
21700
|
-
|
|
21783
|
+
ts17.forEachChild(node, visit3);
|
|
21701
21784
|
}
|
|
21702
21785
|
function tryHandleArrowValue(initializer) {
|
|
21703
21786
|
let expr = initializer;
|
|
21704
|
-
while (
|
|
21787
|
+
while (ts17.isParenthesizedExpression(expr))
|
|
21705
21788
|
expr = expr.expression;
|
|
21706
|
-
if (
|
|
21789
|
+
if (ts17.isArrowFunction(expr) && arrowBodyContainsJsx(expr)) {
|
|
21707
21790
|
return handleInlineArrow(expr);
|
|
21708
21791
|
}
|
|
21709
21792
|
return false;
|
|
@@ -21740,7 +21823,7 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
21740
21823
|
replacements.push({ start: arrowStart, end: arrowEnd, text: name });
|
|
21741
21824
|
return true;
|
|
21742
21825
|
}
|
|
21743
|
-
|
|
21826
|
+
ts17.forEachChild(sourceFile, visit3);
|
|
21744
21827
|
if (replacements.length === 0) {
|
|
21745
21828
|
return { source, errors, syntheticNames, counterAfter: counter };
|
|
21746
21829
|
}
|
|
@@ -21763,11 +21846,11 @@ function errorMessageForCapture(captures) {
|
|
|
21763
21846
|
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.`;
|
|
21764
21847
|
}
|
|
21765
21848
|
function arrowBodyContainsJsx(arrow) {
|
|
21766
|
-
if (
|
|
21849
|
+
if (ts17.isBlock(arrow.body)) {
|
|
21767
21850
|
return blockReturnsJsx(arrow.body);
|
|
21768
21851
|
}
|
|
21769
21852
|
let body = arrow.body;
|
|
21770
|
-
while (
|
|
21853
|
+
while (ts17.isParenthesizedExpression(body))
|
|
21771
21854
|
body = body.expression;
|
|
21772
21855
|
return isJsxLike(body);
|
|
21773
21856
|
}
|
|
@@ -21776,24 +21859,24 @@ function blockReturnsJsx(block) {
|
|
|
21776
21859
|
function visit3(n) {
|
|
21777
21860
|
if (found)
|
|
21778
21861
|
return;
|
|
21779
|
-
if (
|
|
21862
|
+
if (ts17.isReturnStatement(n) && n.expression) {
|
|
21780
21863
|
let e = n.expression;
|
|
21781
|
-
while (
|
|
21864
|
+
while (ts17.isParenthesizedExpression(e))
|
|
21782
21865
|
e = e.expression;
|
|
21783
21866
|
if (isJsxLike(e)) {
|
|
21784
21867
|
found = true;
|
|
21785
21868
|
return;
|
|
21786
21869
|
}
|
|
21787
21870
|
}
|
|
21788
|
-
if (
|
|
21871
|
+
if (ts17.isArrowFunction(n) || ts17.isFunctionDeclaration(n) || ts17.isFunctionExpression(n))
|
|
21789
21872
|
return;
|
|
21790
|
-
|
|
21873
|
+
ts17.forEachChild(n, visit3);
|
|
21791
21874
|
}
|
|
21792
|
-
|
|
21875
|
+
ts17.forEachChild(block, visit3);
|
|
21793
21876
|
return found;
|
|
21794
21877
|
}
|
|
21795
21878
|
function isJsxLike(expr) {
|
|
21796
|
-
return
|
|
21879
|
+
return ts17.isJsxElement(expr) || ts17.isJsxSelfClosingElement(expr) || ts17.isJsxFragment(expr);
|
|
21797
21880
|
}
|
|
21798
21881
|
function collectArrowParamNames(arrow) {
|
|
21799
21882
|
const names = new Set;
|
|
@@ -21803,13 +21886,13 @@ function collectArrowParamNames(arrow) {
|
|
|
21803
21886
|
}
|
|
21804
21887
|
function collectBindingNames2(name, out) {
|
|
21805
21888
|
const push = Array.isArray(out) ? (n) => out.push(n) : (n) => out.add(n);
|
|
21806
|
-
if (
|
|
21889
|
+
if (ts17.isIdentifier(name)) {
|
|
21807
21890
|
push(name.text);
|
|
21808
|
-
} else if (
|
|
21891
|
+
} else if (ts17.isObjectBindingPattern(name)) {
|
|
21809
21892
|
name.elements.forEach((el) => collectBindingNames2(el.name, out));
|
|
21810
|
-
} else if (
|
|
21893
|
+
} else if (ts17.isArrayBindingPattern(name)) {
|
|
21811
21894
|
name.elements.forEach((el) => {
|
|
21812
|
-
if (!
|
|
21895
|
+
if (!ts17.isOmittedExpression(el))
|
|
21813
21896
|
collectBindingNames2(el.name, out);
|
|
21814
21897
|
});
|
|
21815
21898
|
}
|
|
@@ -21836,48 +21919,48 @@ function collectFreeIdentifiers(arrow) {
|
|
|
21836
21919
|
return bound.includes(name);
|
|
21837
21920
|
}
|
|
21838
21921
|
function visit3(node) {
|
|
21839
|
-
if (
|
|
21922
|
+
if (ts17.isIdentifier(node)) {
|
|
21840
21923
|
const parent = node.parent;
|
|
21841
|
-
if (parent &&
|
|
21924
|
+
if (parent && ts17.isPropertyAccessExpression(parent) && parent.name === node)
|
|
21842
21925
|
return;
|
|
21843
|
-
if (parent &&
|
|
21926
|
+
if (parent && ts17.isPropertyAssignment(parent) && parent.name === node)
|
|
21844
21927
|
return;
|
|
21845
|
-
if (parent &&
|
|
21928
|
+
if (parent && ts17.isPropertySignature(parent) && parent.name === node)
|
|
21846
21929
|
return;
|
|
21847
|
-
if (parent &&
|
|
21930
|
+
if (parent && ts17.isPropertyDeclaration(parent) && parent.name === node)
|
|
21848
21931
|
return;
|
|
21849
|
-
if (parent &&
|
|
21932
|
+
if (parent && ts17.isMethodDeclaration(parent) && parent.name === node)
|
|
21850
21933
|
return;
|
|
21851
|
-
if (parent &&
|
|
21934
|
+
if (parent && ts17.isMethodSignature(parent) && parent.name === node)
|
|
21852
21935
|
return;
|
|
21853
|
-
if (parent &&
|
|
21936
|
+
if (parent && ts17.isGetAccessorDeclaration(parent) && parent.name === node)
|
|
21854
21937
|
return;
|
|
21855
|
-
if (parent &&
|
|
21938
|
+
if (parent && ts17.isSetAccessorDeclaration(parent) && parent.name === node)
|
|
21856
21939
|
return;
|
|
21857
|
-
if (parent &&
|
|
21940
|
+
if (parent && ts17.isEnumMember(parent) && parent.name === node)
|
|
21858
21941
|
return;
|
|
21859
|
-
if (parent &&
|
|
21942
|
+
if (parent && ts17.isBindingElement(parent) && parent.propertyName === node)
|
|
21860
21943
|
return;
|
|
21861
|
-
if (parent &&
|
|
21944
|
+
if (parent && ts17.isShorthandPropertyAssignment(parent) && parent.name === node) {
|
|
21862
21945
|
if (!isBound(node.text))
|
|
21863
21946
|
ids.add(node.text);
|
|
21864
21947
|
return;
|
|
21865
21948
|
}
|
|
21866
|
-
if (parent &&
|
|
21949
|
+
if (parent && ts17.isParameter(parent) && parent.name === node)
|
|
21867
21950
|
return;
|
|
21868
|
-
if (parent &&
|
|
21951
|
+
if (parent && ts17.isVariableDeclaration(parent) && parent.name === node)
|
|
21869
21952
|
return;
|
|
21870
|
-
if (parent &&
|
|
21953
|
+
if (parent && ts17.isFunctionDeclaration(parent) && parent.name === node)
|
|
21871
21954
|
return;
|
|
21872
|
-
if (parent &&
|
|
21955
|
+
if (parent && ts17.isClassDeclaration(parent) && parent.name === node)
|
|
21873
21956
|
return;
|
|
21874
|
-
if (parent &&
|
|
21957
|
+
if (parent && ts17.isJsxAttribute(parent) && parent.name === node)
|
|
21875
21958
|
return;
|
|
21876
|
-
if (parent &&
|
|
21959
|
+
if (parent && ts17.isJsxOpeningElement(parent) && parent.tagName === node) {
|
|
21877
21960
|
if (/^[a-z]/.test(node.text))
|
|
21878
21961
|
return;
|
|
21879
21962
|
}
|
|
21880
|
-
if (parent &&
|
|
21963
|
+
if (parent && ts17.isJsxClosingElement(parent) && parent.tagName === node) {
|
|
21881
21964
|
if (/^[a-z]/.test(node.text))
|
|
21882
21965
|
return;
|
|
21883
21966
|
}
|
|
@@ -21886,43 +21969,43 @@ function collectFreeIdentifiers(arrow) {
|
|
|
21886
21969
|
ids.add(node.text);
|
|
21887
21970
|
return;
|
|
21888
21971
|
}
|
|
21889
|
-
if (
|
|
21972
|
+
if (ts17.isVariableDeclaration(node)) {
|
|
21890
21973
|
const declared = pushBindings(node.name);
|
|
21891
21974
|
if (node.initializer)
|
|
21892
21975
|
visit3(node.initializer);
|
|
21893
21976
|
return;
|
|
21894
21977
|
}
|
|
21895
|
-
if (
|
|
21978
|
+
if (ts17.isFunctionDeclaration(node)) {
|
|
21896
21979
|
if (node.name)
|
|
21897
21980
|
bound.push(node.name.text);
|
|
21898
21981
|
visitInsideNewScope(node);
|
|
21899
21982
|
return;
|
|
21900
21983
|
}
|
|
21901
|
-
if (
|
|
21984
|
+
if (ts17.isClassDeclaration(node)) {
|
|
21902
21985
|
if (node.name)
|
|
21903
21986
|
bound.push(node.name.text);
|
|
21904
|
-
|
|
21987
|
+
ts17.forEachChild(node, visit3);
|
|
21905
21988
|
return;
|
|
21906
21989
|
}
|
|
21907
|
-
if (
|
|
21990
|
+
if (ts17.isArrowFunction(node) || ts17.isFunctionExpression(node)) {
|
|
21908
21991
|
visitInsideNewScope(node);
|
|
21909
21992
|
return;
|
|
21910
21993
|
}
|
|
21911
|
-
if (
|
|
21994
|
+
if (ts17.isCatchClause(node)) {
|
|
21912
21995
|
const before = bound.length;
|
|
21913
21996
|
if (node.variableDeclaration)
|
|
21914
21997
|
pushBindings(node.variableDeclaration.name);
|
|
21915
|
-
|
|
21998
|
+
ts17.forEachChild(node, visit3);
|
|
21916
21999
|
popN(bound.length - before);
|
|
21917
22000
|
return;
|
|
21918
22001
|
}
|
|
21919
|
-
if (
|
|
22002
|
+
if (ts17.isBlock(node)) {
|
|
21920
22003
|
const before = bound.length;
|
|
21921
|
-
|
|
22004
|
+
ts17.forEachChild(node, visit3);
|
|
21922
22005
|
popN(bound.length - before);
|
|
21923
22006
|
return;
|
|
21924
22007
|
}
|
|
21925
|
-
|
|
22008
|
+
ts17.forEachChild(node, visit3);
|
|
21926
22009
|
}
|
|
21927
22010
|
function visitInsideNewScope(fn) {
|
|
21928
22011
|
const before = bound.length;
|
|
@@ -21945,29 +22028,29 @@ function collectFreeIdentifiers(arrow) {
|
|
|
21945
22028
|
function collectModuleScopeNames(sourceFile) {
|
|
21946
22029
|
const names = new Set;
|
|
21947
22030
|
for (const stmt of sourceFile.statements) {
|
|
21948
|
-
if (
|
|
22031
|
+
if (ts17.isFunctionDeclaration(stmt) && stmt.name)
|
|
21949
22032
|
names.add(stmt.name.text);
|
|
21950
|
-
else if (
|
|
22033
|
+
else if (ts17.isClassDeclaration(stmt) && stmt.name)
|
|
21951
22034
|
names.add(stmt.name.text);
|
|
21952
|
-
else if (
|
|
22035
|
+
else if (ts17.isVariableStatement(stmt)) {
|
|
21953
22036
|
for (const decl of stmt.declarationList.declarations)
|
|
21954
22037
|
collectBindingNames2(decl.name, names);
|
|
21955
|
-
} else if (
|
|
22038
|
+
} else if (ts17.isImportDeclaration(stmt) && stmt.importClause) {
|
|
21956
22039
|
const ic = stmt.importClause;
|
|
21957
22040
|
if (ic.name)
|
|
21958
22041
|
names.add(ic.name.text);
|
|
21959
22042
|
if (ic.namedBindings) {
|
|
21960
|
-
if (
|
|
22043
|
+
if (ts17.isNamespaceImport(ic.namedBindings))
|
|
21961
22044
|
names.add(ic.namedBindings.name.text);
|
|
21962
22045
|
else
|
|
21963
22046
|
for (const e of ic.namedBindings.elements)
|
|
21964
22047
|
names.add(e.name.text);
|
|
21965
22048
|
}
|
|
21966
|
-
} else if (
|
|
22049
|
+
} else if (ts17.isTypeAliasDeclaration(stmt))
|
|
21967
22050
|
names.add(stmt.name.text);
|
|
21968
|
-
else if (
|
|
22051
|
+
else if (ts17.isInterfaceDeclaration(stmt))
|
|
21969
22052
|
names.add(stmt.name.text);
|
|
21970
|
-
else if (
|
|
22053
|
+
else if (ts17.isEnumDeclaration(stmt))
|
|
21971
22054
|
names.add(stmt.name.text);
|
|
21972
22055
|
}
|
|
21973
22056
|
return names;
|
|
@@ -21975,7 +22058,7 @@ function collectModuleScopeNames(sourceFile) {
|
|
|
21975
22058
|
function buildSyntheticDeclaration(name, arrow, sourceFile) {
|
|
21976
22059
|
const paramsText = arrow.parameters.length === 0 ? "" : arrow.parameters.map((p) => p.getText(sourceFile)).join(", ");
|
|
21977
22060
|
let bodyText;
|
|
21978
|
-
if (
|
|
22061
|
+
if (ts17.isBlock(arrow.body)) {
|
|
21979
22062
|
bodyText = arrow.body.getText(sourceFile);
|
|
21980
22063
|
} else {
|
|
21981
22064
|
const expr = arrow.body.getText(sourceFile);
|
|
@@ -21985,7 +22068,7 @@ function buildSyntheticDeclaration(name, arrow, sourceFile) {
|
|
|
21985
22068
|
}
|
|
21986
22069
|
|
|
21987
22070
|
// src/ssr-defaults.ts
|
|
21988
|
-
import
|
|
22071
|
+
import ts18 from "typescript";
|
|
21989
22072
|
var UNRESOLVED = Symbol("unresolved");
|
|
21990
22073
|
var NO_RETURN = Symbol("no-return");
|
|
21991
22074
|
function extractSsrDefaults(metadata) {
|
|
@@ -22061,11 +22144,11 @@ function collectPropRefs(expr, propsObjectName, out) {
|
|
|
22061
22144
|
if (!node)
|
|
22062
22145
|
return;
|
|
22063
22146
|
const visit3 = (n) => {
|
|
22064
|
-
if (
|
|
22147
|
+
if (ts18.isPropertyAccessExpression(n) && ts18.isIdentifier(n.expression) && n.expression.text === propsObjectName && ts18.isIdentifier(n.name)) {
|
|
22065
22148
|
out.add(n.name.text);
|
|
22066
22149
|
return;
|
|
22067
22150
|
}
|
|
22068
|
-
|
|
22151
|
+
ts18.forEachChild(n, visit3);
|
|
22069
22152
|
};
|
|
22070
22153
|
visit3(node);
|
|
22071
22154
|
}
|
|
@@ -22086,23 +22169,23 @@ function tryStaticEval(expr, ctx) {
|
|
|
22086
22169
|
}
|
|
22087
22170
|
function evalStatementsForReturn(statements, ctx) {
|
|
22088
22171
|
for (const stmt of statements) {
|
|
22089
|
-
if (
|
|
22172
|
+
if (ts18.isVariableStatement(stmt)) {
|
|
22090
22173
|
for (const d of stmt.declarationList.declarations) {
|
|
22091
|
-
if (!
|
|
22174
|
+
if (!ts18.isIdentifier(d.name) || !d.initializer)
|
|
22092
22175
|
continue;
|
|
22093
22176
|
const v = evalNode(d.initializer, ctx);
|
|
22094
22177
|
if (v !== UNRESOLVED)
|
|
22095
22178
|
ctx.bindings[d.name.text] = v;
|
|
22096
22179
|
}
|
|
22097
|
-
} else if (
|
|
22180
|
+
} else if (ts18.isReturnStatement(stmt)) {
|
|
22098
22181
|
return stmt.expression ? evalNode(stmt.expression, ctx) : UNRESOLVED;
|
|
22099
|
-
} else if (
|
|
22182
|
+
} else if (ts18.isIfStatement(stmt)) {
|
|
22100
22183
|
const cond = evalNode(stmt.expression, ctx);
|
|
22101
22184
|
if (cond === UNRESOLVED)
|
|
22102
22185
|
return UNRESOLVED;
|
|
22103
22186
|
const branch = cond ? stmt.thenStatement : stmt.elseStatement;
|
|
22104
22187
|
if (branch) {
|
|
22105
|
-
const taken = evalStatementsForReturn(
|
|
22188
|
+
const taken = evalStatementsForReturn(ts18.isBlock(branch) ? branch.statements : [branch], ctx);
|
|
22106
22189
|
if (taken !== NO_RETURN)
|
|
22107
22190
|
return taken;
|
|
22108
22191
|
}
|
|
@@ -22113,45 +22196,45 @@ function evalStatementsForReturn(statements, ctx) {
|
|
|
22113
22196
|
return NO_RETURN;
|
|
22114
22197
|
}
|
|
22115
22198
|
function parseExpression2(expr) {
|
|
22116
|
-
const sf =
|
|
22199
|
+
const sf = ts18.createSourceFile("__ssr_default__.ts", `(${expr})`, ts18.ScriptTarget.Latest, false, ts18.ScriptKind.TS);
|
|
22117
22200
|
const stmt = sf.statements[0];
|
|
22118
|
-
if (!stmt || !
|
|
22201
|
+
if (!stmt || !ts18.isExpressionStatement(stmt))
|
|
22119
22202
|
return null;
|
|
22120
|
-
const inner =
|
|
22203
|
+
const inner = ts18.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
22121
22204
|
return inner;
|
|
22122
22205
|
}
|
|
22123
22206
|
function evalNode(node, ctx) {
|
|
22124
|
-
if (
|
|
22207
|
+
if (ts18.isParenthesizedExpression(node))
|
|
22125
22208
|
return evalNode(node.expression, ctx);
|
|
22126
|
-
if (
|
|
22209
|
+
if (ts18.isAsExpression(node))
|
|
22127
22210
|
return evalNode(node.expression, ctx);
|
|
22128
|
-
if (
|
|
22211
|
+
if (ts18.isSatisfiesExpression(node))
|
|
22129
22212
|
return evalNode(node.expression, ctx);
|
|
22130
|
-
if (
|
|
22213
|
+
if (ts18.isTypeAssertionExpression(node))
|
|
22131
22214
|
return evalNode(node.expression, ctx);
|
|
22132
|
-
if (
|
|
22215
|
+
if (ts18.isNonNullExpression(node))
|
|
22133
22216
|
return evalNode(node.expression, ctx);
|
|
22134
|
-
if (
|
|
22217
|
+
if (ts18.isArrowFunction(node)) {
|
|
22135
22218
|
if (node.parameters.length !== 0)
|
|
22136
22219
|
return UNRESOLVED;
|
|
22137
|
-
if (!
|
|
22220
|
+
if (!ts18.isBlock(node.body))
|
|
22138
22221
|
return evalNode(node.body, ctx);
|
|
22139
22222
|
const localBindings = { ...ctx.bindings };
|
|
22140
22223
|
const localCtx = { ...ctx, bindings: localBindings };
|
|
22141
22224
|
const result = evalStatementsForReturn(node.body.statements, localCtx);
|
|
22142
22225
|
return result === NO_RETURN ? UNRESOLVED : result;
|
|
22143
22226
|
}
|
|
22144
|
-
if (
|
|
22227
|
+
if (ts18.isNumericLiteral(node))
|
|
22145
22228
|
return Number(node.text);
|
|
22146
|
-
if (
|
|
22229
|
+
if (ts18.isStringLiteralLike(node))
|
|
22147
22230
|
return node.text;
|
|
22148
|
-
if (node.kind ===
|
|
22231
|
+
if (node.kind === ts18.SyntaxKind.TrueKeyword)
|
|
22149
22232
|
return true;
|
|
22150
|
-
if (node.kind ===
|
|
22233
|
+
if (node.kind === ts18.SyntaxKind.FalseKeyword)
|
|
22151
22234
|
return false;
|
|
22152
|
-
if (node.kind ===
|
|
22235
|
+
if (node.kind === ts18.SyntaxKind.NullKeyword)
|
|
22153
22236
|
return null;
|
|
22154
|
-
if (
|
|
22237
|
+
if (ts18.isIdentifier(node)) {
|
|
22155
22238
|
if (node.text === "undefined")
|
|
22156
22239
|
return;
|
|
22157
22240
|
if (node.text in ctx.bindings)
|
|
@@ -22160,29 +22243,29 @@ function evalNode(node, ctx) {
|
|
|
22160
22243
|
return;
|
|
22161
22244
|
return UNRESOLVED;
|
|
22162
22245
|
}
|
|
22163
|
-
if (
|
|
22246
|
+
if (ts18.isPrefixUnaryExpression(node)) {
|
|
22164
22247
|
const arg = evalNode(node.operand, ctx);
|
|
22165
22248
|
if (arg === UNRESOLVED)
|
|
22166
22249
|
return UNRESOLVED;
|
|
22167
22250
|
switch (node.operator) {
|
|
22168
|
-
case
|
|
22251
|
+
case ts18.SyntaxKind.MinusToken:
|
|
22169
22252
|
return typeof arg === "number" ? -arg : UNRESOLVED;
|
|
22170
|
-
case
|
|
22253
|
+
case ts18.SyntaxKind.PlusToken:
|
|
22171
22254
|
return typeof arg === "number" ? +arg : UNRESOLVED;
|
|
22172
|
-
case
|
|
22255
|
+
case ts18.SyntaxKind.ExclamationToken:
|
|
22173
22256
|
return !arg;
|
|
22174
22257
|
}
|
|
22175
22258
|
return UNRESOLVED;
|
|
22176
22259
|
}
|
|
22177
|
-
if (
|
|
22260
|
+
if (ts18.isObjectLiteralExpression(node)) {
|
|
22178
22261
|
const obj = {};
|
|
22179
22262
|
for (const prop of node.properties) {
|
|
22180
|
-
if (!
|
|
22263
|
+
if (!ts18.isPropertyAssignment(prop))
|
|
22181
22264
|
return UNRESOLVED;
|
|
22182
22265
|
let key;
|
|
22183
|
-
if (
|
|
22266
|
+
if (ts18.isIdentifier(prop.name) || ts18.isStringLiteralLike(prop.name)) {
|
|
22184
22267
|
key = prop.name.text;
|
|
22185
|
-
} else if (
|
|
22268
|
+
} else if (ts18.isNumericLiteral(prop.name)) {
|
|
22186
22269
|
key = prop.name.text;
|
|
22187
22270
|
} else {
|
|
22188
22271
|
return UNRESOLVED;
|
|
@@ -22194,10 +22277,10 @@ function evalNode(node, ctx) {
|
|
|
22194
22277
|
}
|
|
22195
22278
|
return obj;
|
|
22196
22279
|
}
|
|
22197
|
-
if (
|
|
22280
|
+
if (ts18.isArrayLiteralExpression(node)) {
|
|
22198
22281
|
const arr = [];
|
|
22199
22282
|
for (const elem of node.elements) {
|
|
22200
|
-
if (
|
|
22283
|
+
if (ts18.isOmittedExpression(elem))
|
|
22201
22284
|
return UNRESOLVED;
|
|
22202
22285
|
const v = evalNode(elem, ctx);
|
|
22203
22286
|
if (v === UNRESOLVED)
|
|
@@ -22206,7 +22289,7 @@ function evalNode(node, ctx) {
|
|
|
22206
22289
|
}
|
|
22207
22290
|
return arr;
|
|
22208
22291
|
}
|
|
22209
|
-
if (
|
|
22292
|
+
if (ts18.isElementAccessExpression(node)) {
|
|
22210
22293
|
const base = evalNode(node.expression, ctx);
|
|
22211
22294
|
if (base === undefined)
|
|
22212
22295
|
return;
|
|
@@ -22220,17 +22303,17 @@ function evalNode(node, ctx) {
|
|
|
22220
22303
|
const k = String(key);
|
|
22221
22304
|
return Object.prototype.hasOwnProperty.call(base, k) ? base[k] : undefined;
|
|
22222
22305
|
}
|
|
22223
|
-
if (
|
|
22306
|
+
if (ts18.isPropertyAccessExpression(node)) {
|
|
22224
22307
|
const baseResult = evalNode(node.expression, ctx);
|
|
22225
22308
|
if (baseResult === undefined)
|
|
22226
22309
|
return;
|
|
22227
22310
|
return UNRESOLVED;
|
|
22228
22311
|
}
|
|
22229
|
-
if (
|
|
22230
|
-
if (node.arguments.length === 0 &&
|
|
22312
|
+
if (ts18.isCallExpression(node)) {
|
|
22313
|
+
if (node.arguments.length === 0 && ts18.isIdentifier(node.expression) && node.expression.text in ctx.bindings) {
|
|
22231
22314
|
return ctx.bindings[node.expression.text];
|
|
22232
22315
|
}
|
|
22233
|
-
if (
|
|
22316
|
+
if (ts18.isPropertyAccessExpression(node.expression) && node.expression.name.text === "join") {
|
|
22234
22317
|
const recv = evalNode(node.expression.expression, ctx);
|
|
22235
22318
|
if (Array.isArray(recv)) {
|
|
22236
22319
|
let sep2 = ",";
|
|
@@ -22246,27 +22329,27 @@ function evalNode(node, ctx) {
|
|
|
22246
22329
|
}
|
|
22247
22330
|
return UNRESOLVED;
|
|
22248
22331
|
}
|
|
22249
|
-
if (
|
|
22332
|
+
if (ts18.isConditionalExpression(node)) {
|
|
22250
22333
|
const cond = evalNode(node.condition, ctx);
|
|
22251
22334
|
if (cond === UNRESOLVED)
|
|
22252
22335
|
return UNRESOLVED;
|
|
22253
22336
|
return cond ? evalNode(node.whenTrue, ctx) : evalNode(node.whenFalse, ctx);
|
|
22254
22337
|
}
|
|
22255
|
-
if (
|
|
22338
|
+
if (ts18.isBinaryExpression(node)) {
|
|
22256
22339
|
const op = node.operatorToken.kind;
|
|
22257
|
-
if (op ===
|
|
22340
|
+
if (op === ts18.SyntaxKind.QuestionQuestionToken) {
|
|
22258
22341
|
const l2 = evalNode(node.left, ctx);
|
|
22259
22342
|
if (l2 !== UNRESOLVED && l2 !== null && l2 !== undefined)
|
|
22260
22343
|
return l2;
|
|
22261
22344
|
return evalNode(node.right, ctx);
|
|
22262
22345
|
}
|
|
22263
|
-
if (op ===
|
|
22346
|
+
if (op === ts18.SyntaxKind.BarBarToken) {
|
|
22264
22347
|
const l2 = evalNode(node.left, ctx);
|
|
22265
22348
|
if (l2 !== UNRESOLVED && l2)
|
|
22266
22349
|
return l2;
|
|
22267
22350
|
return evalNode(node.right, ctx);
|
|
22268
22351
|
}
|
|
22269
|
-
if (op ===
|
|
22352
|
+
if (op === ts18.SyntaxKind.AmpersandAmpersandToken) {
|
|
22270
22353
|
const l2 = evalNode(node.left, ctx);
|
|
22271
22354
|
if (l2 === UNRESOLVED)
|
|
22272
22355
|
return UNRESOLVED;
|
|
@@ -22279,30 +22362,30 @@ function evalNode(node, ctx) {
|
|
|
22279
22362
|
if (l === UNRESOLVED || r === UNRESOLVED)
|
|
22280
22363
|
return UNRESOLVED;
|
|
22281
22364
|
switch (op) {
|
|
22282
|
-
case
|
|
22365
|
+
case ts18.SyntaxKind.PlusToken:
|
|
22283
22366
|
if (typeof l === "string" || typeof r === "string")
|
|
22284
22367
|
return `${l}${r}`;
|
|
22285
22368
|
if (typeof l === "number" && typeof r === "number")
|
|
22286
22369
|
return l + r;
|
|
22287
22370
|
return UNRESOLVED;
|
|
22288
|
-
case
|
|
22371
|
+
case ts18.SyntaxKind.MinusToken:
|
|
22289
22372
|
return typeof l === "number" && typeof r === "number" ? l - r : UNRESOLVED;
|
|
22290
|
-
case
|
|
22373
|
+
case ts18.SyntaxKind.AsteriskToken:
|
|
22291
22374
|
return typeof l === "number" && typeof r === "number" ? l * r : UNRESOLVED;
|
|
22292
|
-
case
|
|
22375
|
+
case ts18.SyntaxKind.SlashToken:
|
|
22293
22376
|
return typeof l === "number" && typeof r === "number" && r !== 0 ? l / r : UNRESOLVED;
|
|
22294
|
-
case
|
|
22377
|
+
case ts18.SyntaxKind.PercentToken:
|
|
22295
22378
|
return typeof l === "number" && typeof r === "number" && r !== 0 ? l % r : UNRESOLVED;
|
|
22296
|
-
case
|
|
22297
|
-
case
|
|
22379
|
+
case ts18.SyntaxKind.EqualsEqualsEqualsToken:
|
|
22380
|
+
case ts18.SyntaxKind.EqualsEqualsToken:
|
|
22298
22381
|
return l === r;
|
|
22299
|
-
case
|
|
22300
|
-
case
|
|
22382
|
+
case ts18.SyntaxKind.ExclamationEqualsEqualsToken:
|
|
22383
|
+
case ts18.SyntaxKind.ExclamationEqualsToken:
|
|
22301
22384
|
return l !== r;
|
|
22302
22385
|
}
|
|
22303
22386
|
return UNRESOLVED;
|
|
22304
22387
|
}
|
|
22305
|
-
if (
|
|
22388
|
+
if (ts18.isTemplateExpression(node)) {
|
|
22306
22389
|
if (node.templateSpans.length === 0)
|
|
22307
22390
|
return node.head.text;
|
|
22308
22391
|
let acc = node.head.text;
|
|
@@ -22314,13 +22397,13 @@ function evalNode(node, ctx) {
|
|
|
22314
22397
|
}
|
|
22315
22398
|
return acc;
|
|
22316
22399
|
}
|
|
22317
|
-
if (
|
|
22400
|
+
if (ts18.isNoSubstitutionTemplateLiteral(node))
|
|
22318
22401
|
return node.text;
|
|
22319
22402
|
return UNRESOLVED;
|
|
22320
22403
|
}
|
|
22321
22404
|
|
|
22322
22405
|
// src/augment-inherited-props.ts
|
|
22323
|
-
import
|
|
22406
|
+
import ts19 from "typescript";
|
|
22324
22407
|
function collectContextConsumers(metadata) {
|
|
22325
22408
|
const constants = metadata.localConstants ?? [];
|
|
22326
22409
|
const contextDefaults = new Map;
|
|
@@ -22352,47 +22435,47 @@ function collectContextConsumers(metadata) {
|
|
|
22352
22435
|
}
|
|
22353
22436
|
function parseUseContextArg(source) {
|
|
22354
22437
|
const expr = parseSingleExpression(source);
|
|
22355
|
-
if (!expr || !
|
|
22438
|
+
if (!expr || !ts19.isCallExpression(expr))
|
|
22356
22439
|
return null;
|
|
22357
|
-
if (!
|
|
22440
|
+
if (!ts19.isIdentifier(expr.expression) || expr.expression.text !== "useContext")
|
|
22358
22441
|
return null;
|
|
22359
22442
|
if (expr.arguments.length !== 1)
|
|
22360
22443
|
return null;
|
|
22361
22444
|
const arg = expr.arguments[0];
|
|
22362
|
-
return
|
|
22445
|
+
return ts19.isIdentifier(arg) ? arg.text : null;
|
|
22363
22446
|
}
|
|
22364
22447
|
function parseCreateContextDefault(source) {
|
|
22365
22448
|
const expr = parseSingleExpression(source);
|
|
22366
|
-
if (!expr || !
|
|
22449
|
+
if (!expr || !ts19.isCallExpression(expr))
|
|
22367
22450
|
return null;
|
|
22368
22451
|
if (expr.arguments.length === 0)
|
|
22369
22452
|
return null;
|
|
22370
22453
|
const arg = expr.arguments[0];
|
|
22371
|
-
if (
|
|
22454
|
+
if (ts19.isStringLiteral(arg) || ts19.isNoSubstitutionTemplateLiteral(arg))
|
|
22372
22455
|
return arg.text;
|
|
22373
|
-
if (
|
|
22456
|
+
if (ts19.isNumericLiteral(arg))
|
|
22374
22457
|
return Number(arg.text);
|
|
22375
|
-
if (arg.kind ===
|
|
22458
|
+
if (arg.kind === ts19.SyntaxKind.TrueKeyword)
|
|
22376
22459
|
return true;
|
|
22377
|
-
if (arg.kind ===
|
|
22460
|
+
if (arg.kind === ts19.SyntaxKind.FalseKeyword)
|
|
22378
22461
|
return false;
|
|
22379
22462
|
return null;
|
|
22380
22463
|
}
|
|
22381
22464
|
function isObjectLiteralCreateContextDefault(source) {
|
|
22382
22465
|
const expr = parseSingleExpression(source);
|
|
22383
|
-
if (!expr || !
|
|
22466
|
+
if (!expr || !ts19.isCallExpression(expr))
|
|
22384
22467
|
return false;
|
|
22385
22468
|
if (expr.arguments.length === 0)
|
|
22386
22469
|
return false;
|
|
22387
|
-
return
|
|
22470
|
+
return ts19.isObjectLiteralExpression(expr.arguments[0]);
|
|
22388
22471
|
}
|
|
22389
22472
|
function parseSingleExpression(source) {
|
|
22390
|
-
const sf =
|
|
22473
|
+
const sf = ts19.createSourceFile("__ctx.ts", `(${source})`, ts19.ScriptTarget.Latest, false);
|
|
22391
22474
|
const stmt = sf.statements[0];
|
|
22392
|
-
if (!stmt || !
|
|
22475
|
+
if (!stmt || !ts19.isExpressionStatement(stmt))
|
|
22393
22476
|
return null;
|
|
22394
22477
|
let e = stmt.expression;
|
|
22395
|
-
while (
|
|
22478
|
+
while (ts19.isParenthesizedExpression(e))
|
|
22396
22479
|
e = e.expression;
|
|
22397
22480
|
return e;
|
|
22398
22481
|
}
|
|
@@ -22417,25 +22500,25 @@ function augmentInheritedPropAccesses(ir) {
|
|
|
22417
22500
|
const pinCoalesceLiterals = (s) => {
|
|
22418
22501
|
if (!s || !s.includes(propsObj))
|
|
22419
22502
|
return;
|
|
22420
|
-
const sf =
|
|
22503
|
+
const sf = ts19.createSourceFile("__aug.ts", `(${s})`, ts19.ScriptTarget.Latest, false);
|
|
22421
22504
|
const visit3 = (n) => {
|
|
22422
|
-
if (
|
|
22505
|
+
if (ts19.isBinaryExpression(n) && (n.operatorToken.kind === ts19.SyntaxKind.QuestionQuestionToken || n.operatorToken.kind === ts19.SyntaxKind.BarBarToken)) {
|
|
22423
22506
|
let left = n.left;
|
|
22424
|
-
while (
|
|
22507
|
+
while (ts19.isParenthesizedExpression(left))
|
|
22425
22508
|
left = left.expression;
|
|
22426
|
-
if (
|
|
22509
|
+
if (ts19.isPropertyAccessExpression(left) && ts19.isIdentifier(left.expression) && left.expression.text === propsObj) {
|
|
22427
22510
|
const name = left.name.text;
|
|
22428
22511
|
let right = n.right;
|
|
22429
|
-
while (
|
|
22512
|
+
while (ts19.isParenthesizedExpression(right))
|
|
22430
22513
|
right = right.expression;
|
|
22431
|
-
if (
|
|
22514
|
+
if (ts19.isPrefixUnaryExpression(right))
|
|
22432
22515
|
right = right.operand;
|
|
22433
|
-
const kind =
|
|
22516
|
+
const kind = ts19.isNumericLiteral(right) ? "number" : right.kind === ts19.SyntaxKind.TrueKeyword || right.kind === ts19.SyntaxKind.FalseKeyword ? "boolean" : ts19.isStringLiteralLike(right) ? "string" : null;
|
|
22434
22517
|
if (kind && !coalesceLiteralTypes.has(name))
|
|
22435
22518
|
coalesceLiteralTypes.set(name, kind);
|
|
22436
22519
|
}
|
|
22437
22520
|
}
|
|
22438
|
-
|
|
22521
|
+
ts19.forEachChild(n, visit3);
|
|
22439
22522
|
};
|
|
22440
22523
|
visit3(sf);
|
|
22441
22524
|
};
|
|
@@ -22546,33 +22629,33 @@ function augmentInheritedPropAccesses(ir) {
|
|
|
22546
22629
|
}
|
|
22547
22630
|
}
|
|
22548
22631
|
function parseStaticStringConst(source) {
|
|
22549
|
-
const sf =
|
|
22632
|
+
const sf = ts19.createSourceFile("__const.ts", `const __x = (${source});`, ts19.ScriptTarget.Latest, false);
|
|
22550
22633
|
const stmt = sf.statements[0];
|
|
22551
|
-
if (!stmt || !
|
|
22634
|
+
if (!stmt || !ts19.isVariableStatement(stmt))
|
|
22552
22635
|
return null;
|
|
22553
22636
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
22554
|
-
while (init &&
|
|
22637
|
+
while (init && ts19.isParenthesizedExpression(init))
|
|
22555
22638
|
init = init.expression;
|
|
22556
22639
|
if (!init)
|
|
22557
22640
|
return null;
|
|
22558
|
-
if (
|
|
22641
|
+
if (ts19.isStringLiteral(init) || ts19.isNoSubstitutionTemplateLiteral(init)) {
|
|
22559
22642
|
return init.text;
|
|
22560
22643
|
}
|
|
22561
22644
|
return evalStringArrayJoin(source);
|
|
22562
22645
|
}
|
|
22563
22646
|
function evalTemplateOfStringConsts(source, resolved) {
|
|
22564
|
-
const sf =
|
|
22647
|
+
const sf = ts19.createSourceFile("__const.ts", `const __x = (${source});`, ts19.ScriptTarget.Latest, false);
|
|
22565
22648
|
const stmt = sf.statements[0];
|
|
22566
|
-
if (!stmt || !
|
|
22649
|
+
if (!stmt || !ts19.isVariableStatement(stmt))
|
|
22567
22650
|
return null;
|
|
22568
22651
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
22569
|
-
while (init &&
|
|
22652
|
+
while (init && ts19.isParenthesizedExpression(init))
|
|
22570
22653
|
init = init.expression;
|
|
22571
|
-
if (!init || !
|
|
22654
|
+
if (!init || !ts19.isTemplateExpression(init))
|
|
22572
22655
|
return null;
|
|
22573
22656
|
let out = init.head.text;
|
|
22574
22657
|
for (const span of init.templateSpans) {
|
|
22575
|
-
if (!
|
|
22658
|
+
if (!ts19.isIdentifier(span.expression))
|
|
22576
22659
|
return null;
|
|
22577
22660
|
const value = resolved.get(span.expression.text);
|
|
22578
22661
|
if (value === undefined)
|
|
@@ -22603,30 +22686,30 @@ function lookupStaticRecordLiteral(objectName, key, constants) {
|
|
|
22603
22686
|
const constInfo = (constants ?? []).find((c) => c.name === objectName && c.isModule);
|
|
22604
22687
|
if (constInfo?.value === undefined)
|
|
22605
22688
|
return null;
|
|
22606
|
-
const sf =
|
|
22689
|
+
const sf = ts19.createSourceFile("__rec.ts", `(${constInfo.value})`, ts19.ScriptTarget.Latest, true);
|
|
22607
22690
|
if (sf.statements.length !== 1)
|
|
22608
22691
|
return null;
|
|
22609
22692
|
const stmt = sf.statements[0];
|
|
22610
|
-
if (!
|
|
22693
|
+
if (!ts19.isExpressionStatement(stmt))
|
|
22611
22694
|
return null;
|
|
22612
22695
|
let parsed = stmt.expression;
|
|
22613
|
-
while (
|
|
22696
|
+
while (ts19.isParenthesizedExpression(parsed))
|
|
22614
22697
|
parsed = parsed.expression;
|
|
22615
|
-
if (!
|
|
22698
|
+
if (!ts19.isObjectLiteralExpression(parsed))
|
|
22616
22699
|
return null;
|
|
22617
22700
|
for (const prop of parsed.properties) {
|
|
22618
|
-
if (!
|
|
22701
|
+
if (!ts19.isPropertyAssignment(prop))
|
|
22619
22702
|
continue;
|
|
22620
22703
|
const name = prop.name;
|
|
22621
|
-
const propKey =
|
|
22704
|
+
const propKey = ts19.isIdentifier(name) || ts19.isStringLiteral(name) || ts19.isNoSubstitutionTemplateLiteral(name) ? name.text : null;
|
|
22622
22705
|
if (propKey !== key)
|
|
22623
22706
|
continue;
|
|
22624
22707
|
let v = prop.initializer;
|
|
22625
|
-
while (
|
|
22708
|
+
while (ts19.isParenthesizedExpression(v))
|
|
22626
22709
|
v = v.expression;
|
|
22627
|
-
if (
|
|
22710
|
+
if (ts19.isNumericLiteral(v))
|
|
22628
22711
|
return { kind: "number", text: v.text };
|
|
22629
|
-
if (
|
|
22712
|
+
if (ts19.isStringLiteral(v) || ts19.isNoSubstitutionTemplateLiteral(v)) {
|
|
22630
22713
|
return { kind: "string", text: v.text };
|
|
22631
22714
|
}
|
|
22632
22715
|
return null;
|
|
@@ -22634,28 +22717,28 @@ function lookupStaticRecordLiteral(objectName, key, constants) {
|
|
|
22634
22717
|
return null;
|
|
22635
22718
|
}
|
|
22636
22719
|
function evalStringArrayJoin(source) {
|
|
22637
|
-
const sf =
|
|
22720
|
+
const sf = ts19.createSourceFile("__join.ts", `const __x = (${source});`, ts19.ScriptTarget.Latest, false);
|
|
22638
22721
|
const stmt = sf.statements[0];
|
|
22639
|
-
if (!stmt || !
|
|
22722
|
+
if (!stmt || !ts19.isVariableStatement(stmt))
|
|
22640
22723
|
return null;
|
|
22641
22724
|
let node = stmt.declarationList.declarations[0]?.initializer;
|
|
22642
|
-
while (node &&
|
|
22725
|
+
while (node && ts19.isParenthesizedExpression(node))
|
|
22643
22726
|
node = node.expression;
|
|
22644
|
-
if (!node || !
|
|
22727
|
+
if (!node || !ts19.isCallExpression(node))
|
|
22645
22728
|
return null;
|
|
22646
22729
|
const callee = node.expression;
|
|
22647
|
-
if (!
|
|
22730
|
+
if (!ts19.isPropertyAccessExpression(callee))
|
|
22648
22731
|
return null;
|
|
22649
22732
|
if (callee.name.text !== "join")
|
|
22650
22733
|
return null;
|
|
22651
22734
|
let recv = callee.expression;
|
|
22652
|
-
while (
|
|
22735
|
+
while (ts19.isParenthesizedExpression(recv))
|
|
22653
22736
|
recv = recv.expression;
|
|
22654
|
-
if (!
|
|
22737
|
+
if (!ts19.isArrayLiteralExpression(recv))
|
|
22655
22738
|
return null;
|
|
22656
22739
|
const parts = [];
|
|
22657
22740
|
for (const el of recv.elements) {
|
|
22658
|
-
if (
|
|
22741
|
+
if (ts19.isStringLiteral(el) || ts19.isNoSubstitutionTemplateLiteral(el)) {
|
|
22659
22742
|
parts.push(el.text);
|
|
22660
22743
|
} else {
|
|
22661
22744
|
return null;
|
|
@@ -22664,7 +22747,7 @@ function evalStringArrayJoin(source) {
|
|
|
22664
22747
|
let sep2 = ",";
|
|
22665
22748
|
if (node.arguments.length >= 1) {
|
|
22666
22749
|
const arg = node.arguments[0];
|
|
22667
|
-
if (
|
|
22750
|
+
if (ts19.isStringLiteral(arg) || ts19.isNoSubstitutionTemplateLiteral(arg))
|
|
22668
22751
|
sep2 = arg.text;
|
|
22669
22752
|
else
|
|
22670
22753
|
return null;
|
|
@@ -22672,11 +22755,11 @@ function evalStringArrayJoin(source) {
|
|
|
22672
22755
|
return parts.join(sep2);
|
|
22673
22756
|
}
|
|
22674
22757
|
function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
|
|
22675
|
-
if (!
|
|
22758
|
+
if (!ts19.isElementAccessExpression(val))
|
|
22676
22759
|
return null;
|
|
22677
22760
|
const obj = val.expression;
|
|
22678
22761
|
const arg = val.argumentExpression;
|
|
22679
|
-
if (!
|
|
22762
|
+
if (!ts19.isIdentifier(obj) || !ts19.isIdentifier(arg))
|
|
22680
22763
|
return null;
|
|
22681
22764
|
let indexPropName;
|
|
22682
22765
|
let defaultKey;
|
|
@@ -22692,35 +22775,35 @@ function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
|
|
|
22692
22775
|
const constInfo = localConstants.find((c) => c.name === obj.text && c.isModule);
|
|
22693
22776
|
if (constInfo?.value === undefined)
|
|
22694
22777
|
return null;
|
|
22695
|
-
const sf =
|
|
22778
|
+
const sf = ts19.createSourceFile("__rec.ts", `(${constInfo.value})`, ts19.ScriptTarget.Latest, true);
|
|
22696
22779
|
if (sf.statements.length !== 1)
|
|
22697
22780
|
return null;
|
|
22698
22781
|
const stmt = sf.statements[0];
|
|
22699
|
-
if (!
|
|
22782
|
+
if (!ts19.isExpressionStatement(stmt))
|
|
22700
22783
|
return null;
|
|
22701
22784
|
let parsed = stmt.expression;
|
|
22702
|
-
while (
|
|
22785
|
+
while (ts19.isParenthesizedExpression(parsed))
|
|
22703
22786
|
parsed = parsed.expression;
|
|
22704
|
-
if (!
|
|
22787
|
+
if (!ts19.isObjectLiteralExpression(parsed))
|
|
22705
22788
|
return null;
|
|
22706
22789
|
const entries = [];
|
|
22707
22790
|
for (const prop of parsed.properties) {
|
|
22708
|
-
if (!
|
|
22791
|
+
if (!ts19.isPropertyAssignment(prop))
|
|
22709
22792
|
return null;
|
|
22710
22793
|
let key;
|
|
22711
|
-
if (
|
|
22794
|
+
if (ts19.isIdentifier(prop.name)) {
|
|
22712
22795
|
key = prop.name.text;
|
|
22713
|
-
} else if (
|
|
22796
|
+
} else if (ts19.isStringLiteral(prop.name) || ts19.isNoSubstitutionTemplateLiteral(prop.name)) {
|
|
22714
22797
|
key = prop.name.text;
|
|
22715
22798
|
} else {
|
|
22716
22799
|
return null;
|
|
22717
22800
|
}
|
|
22718
22801
|
let v = prop.initializer;
|
|
22719
|
-
while (
|
|
22802
|
+
while (ts19.isParenthesizedExpression(v))
|
|
22720
22803
|
v = v.expression;
|
|
22721
|
-
if (
|
|
22804
|
+
if (ts19.isNumericLiteral(v)) {
|
|
22722
22805
|
entries.push({ key, value: { kind: "number", text: v.text } });
|
|
22723
|
-
} else if (
|
|
22806
|
+
} else if (ts19.isStringLiteral(v) || ts19.isNoSubstitutionTemplateLiteral(v)) {
|
|
22724
22807
|
entries.push({ key, value: { kind: "string", text: v.text } });
|
|
22725
22808
|
} else {
|
|
22726
22809
|
return null;
|
|
@@ -23359,6 +23442,7 @@ function compileJSX(source, filePath, options) {
|
|
|
23359
23442
|
const sortedRuntimeImports = [...runtimeImports].sort();
|
|
23360
23443
|
const runtimeImportLine = sortedRuntimeImports.length > 0 ? `import { ${sortedRuntimeImports.join(", ")} } from '${RUNTIME_MODULE}'` : "";
|
|
23361
23444
|
const externalImportLines = [];
|
|
23445
|
+
const isUsedAsValue = makeValueUsageTest(body);
|
|
23362
23446
|
for (const imp of ctx.imports) {
|
|
23363
23447
|
if (imp.isTypeOnly)
|
|
23364
23448
|
continue;
|
|
@@ -23368,7 +23452,7 @@ function compileJSX(source, filePath, options) {
|
|
|
23368
23452
|
externalImportLines.push(`import '${imp.source}'`);
|
|
23369
23453
|
continue;
|
|
23370
23454
|
}
|
|
23371
|
-
const used = imp.specifiers.filter((s2) => !s2.isDefault && !s2.isNamespace &&
|
|
23455
|
+
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);
|
|
23372
23456
|
if (used.length > 0) {
|
|
23373
23457
|
externalImportLines.push(`import { ${used.join(", ")} } from '${imp.source}'`);
|
|
23374
23458
|
}
|
|
@@ -23404,6 +23488,8 @@ function compileJSX(source, filePath, options) {
|
|
|
23404
23488
|
if (!imp.source.startsWith("./") && !imp.source.startsWith("../"))
|
|
23405
23489
|
continue;
|
|
23406
23490
|
for (const spec of imp.specifiers) {
|
|
23491
|
+
if (spec.isTypeOnly)
|
|
23492
|
+
continue;
|
|
23407
23493
|
if (ctx.importedClientSignalNames.has(spec.alias ?? spec.name)) {
|
|
23408
23494
|
sources.add(imp.source);
|
|
23409
23495
|
break;
|
|
@@ -23500,7 +23586,7 @@ function compileJSX(source, filePath, options) {
|
|
|
23500
23586
|
return { files, errors };
|
|
23501
23587
|
}
|
|
23502
23588
|
// src/shared-program.ts
|
|
23503
|
-
import
|
|
23589
|
+
import ts20 from "typescript";
|
|
23504
23590
|
function commonParent(paths) {
|
|
23505
23591
|
if (paths.length === 0)
|
|
23506
23592
|
return process.cwd();
|
|
@@ -23521,10 +23607,10 @@ function commonParent(paths) {
|
|
|
23521
23607
|
function createProgramForCorpus(files, options = {}) {
|
|
23522
23608
|
const baseUrl = options.baseUrl ?? commonParent(files);
|
|
23523
23609
|
const compilerOptions = {
|
|
23524
|
-
target:
|
|
23525
|
-
module:
|
|
23526
|
-
moduleResolution:
|
|
23527
|
-
jsx:
|
|
23610
|
+
target: ts20.ScriptTarget.Latest,
|
|
23611
|
+
module: ts20.ModuleKind.ESNext,
|
|
23612
|
+
moduleResolution: ts20.ModuleResolutionKind.Bundler,
|
|
23613
|
+
jsx: ts20.JsxEmit.ReactJSX,
|
|
23528
23614
|
strict: true,
|
|
23529
23615
|
skipLibCheck: true,
|
|
23530
23616
|
noEmit: true,
|
|
@@ -23534,7 +23620,7 @@ function createProgramForCorpus(files, options = {}) {
|
|
|
23534
23620
|
...options.compilerOptions
|
|
23535
23621
|
};
|
|
23536
23622
|
const absolute = files.map((f) => path_default.resolve(f));
|
|
23537
|
-
return
|
|
23623
|
+
return ts20.createProgram(absolute, compilerOptions, undefined, options.oldProgram);
|
|
23538
23624
|
}
|
|
23539
23625
|
// src/adapters/interface.ts
|
|
23540
23626
|
class BaseAdapter {
|
|
@@ -24516,7 +24602,7 @@ function dangerousInnerHtmlDiagnostic(expr, loc, reason) {
|
|
|
24516
24602
|
};
|
|
24517
24603
|
}
|
|
24518
24604
|
// src/combine-client-js.ts
|
|
24519
|
-
import
|
|
24605
|
+
import ts21 from "typescript";
|
|
24520
24606
|
var CHILD_PLACEHOLDER_RE = /import '\/\* @bf-child:(\w+) \*\/'/g;
|
|
24521
24607
|
function combineParentChildClientJs(files) {
|
|
24522
24608
|
const result = new Map;
|
|
@@ -24573,10 +24659,10 @@ function combineParentChildClientJs(files) {
|
|
|
24573
24659
|
return result;
|
|
24574
24660
|
}
|
|
24575
24661
|
function parseAndMerge(content, importsBySource, otherImports, codeSections) {
|
|
24576
|
-
const sourceFile =
|
|
24662
|
+
const sourceFile = ts21.createSourceFile("combine.js", content, ts21.ScriptTarget.Latest, false, ts21.ScriptKind.JS);
|
|
24577
24663
|
const importSpans = [];
|
|
24578
24664
|
for (const stmt of sourceFile.statements) {
|
|
24579
|
-
if (!
|
|
24665
|
+
if (!ts21.isImportDeclaration(stmt))
|
|
24580
24666
|
continue;
|
|
24581
24667
|
const start = stmt.getStart(sourceFile);
|
|
24582
24668
|
const end = stmt.getEnd();
|
|
@@ -24586,8 +24672,8 @@ function parseAndMerge(content, importsBySource, otherImports, codeSections) {
|
|
|
24586
24672
|
continue;
|
|
24587
24673
|
const clause = stmt.importClause;
|
|
24588
24674
|
const bindings = clause?.namedBindings;
|
|
24589
|
-
const specifier =
|
|
24590
|
-
if (clause && !clause.name && bindings &&
|
|
24675
|
+
const specifier = ts21.isStringLiteral(stmt.moduleSpecifier) ? stmt.moduleSpecifier.text : "";
|
|
24676
|
+
if (clause && !clause.name && bindings && ts21.isNamedImports(bindings)) {
|
|
24591
24677
|
if (!importsBySource.has(specifier)) {
|
|
24592
24678
|
importsBySource.set(specifier, new Set);
|
|
24593
24679
|
}
|
|
@@ -24754,7 +24840,7 @@ function escapeRe(s) {
|
|
|
24754
24840
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
24755
24841
|
}
|
|
24756
24842
|
// src/debug.ts
|
|
24757
|
-
import
|
|
24843
|
+
import ts22 from "typescript";
|
|
24758
24844
|
function buildComponentGraph(source, filePath, componentName) {
|
|
24759
24845
|
const ctx = analyzeComponent(source, filePath, componentName);
|
|
24760
24846
|
if (!ctx.jsxReturn) {
|
|
@@ -26039,7 +26125,7 @@ function truncateExpr(expr, max = 40) {
|
|
|
26039
26125
|
function exprReadsPropMember(expr, propsObjectName) {
|
|
26040
26126
|
let sf;
|
|
26041
26127
|
try {
|
|
26042
|
-
sf =
|
|
26128
|
+
sf = ts22.createSourceFile("__attr.tsx", `(${expr})`, ts22.ScriptTarget.Latest, true, ts22.ScriptKind.TSX);
|
|
26043
26129
|
} catch {
|
|
26044
26130
|
return false;
|
|
26045
26131
|
}
|
|
@@ -26047,11 +26133,11 @@ function exprReadsPropMember(expr, propsObjectName) {
|
|
|
26047
26133
|
const visit3 = (n) => {
|
|
26048
26134
|
if (found)
|
|
26049
26135
|
return;
|
|
26050
|
-
if (
|
|
26136
|
+
if (ts22.isPropertyAccessExpression(n) && ts22.isIdentifier(n.expression) && n.expression.text === propsObjectName && n.name.text !== "children") {
|
|
26051
26137
|
found = true;
|
|
26052
26138
|
return;
|
|
26053
26139
|
}
|
|
26054
|
-
|
|
26140
|
+
ts22.forEachChild(n, visit3);
|
|
26055
26141
|
};
|
|
26056
26142
|
visit3(sf);
|
|
26057
26143
|
return found;
|
|
@@ -26121,7 +26207,7 @@ function findSourceFile2(meta) {
|
|
|
26121
26207
|
return null;
|
|
26122
26208
|
}
|
|
26123
26209
|
// src/profiler.ts
|
|
26124
|
-
import
|
|
26210
|
+
import ts23 from "typescript";
|
|
26125
26211
|
var PROFILE_SCHEMA_VERSION = 1;
|
|
26126
26212
|
var DEFAULT_FANOUT_THRESHOLD = 8;
|
|
26127
26213
|
function buildStaticBudget(source, filePath, componentName, options = {}) {
|
|
@@ -26391,15 +26477,15 @@ function joinProfilerEvents(events, index) {
|
|
|
26391
26477
|
return { joined, unattributed, diagnostics };
|
|
26392
26478
|
}
|
|
26393
26479
|
function findUninstrumentedEffects(source, filePath, instrumentedLines) {
|
|
26394
|
-
const sf =
|
|
26480
|
+
const sf = ts23.createSourceFile(filePath, source, ts23.ScriptTarget.Latest, true, ts23.ScriptKind.TSX);
|
|
26395
26481
|
const out = [];
|
|
26396
26482
|
const visit3 = (node) => {
|
|
26397
|
-
if (
|
|
26483
|
+
if (ts23.isCallExpression(node) && ts23.isIdentifier(node.expression) && node.expression.text === "createEffect") {
|
|
26398
26484
|
const line = sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;
|
|
26399
26485
|
if (!instrumentedLines.has(line))
|
|
26400
26486
|
out.push({ file: filePath, line });
|
|
26401
26487
|
}
|
|
26402
|
-
|
|
26488
|
+
ts23.forEachChild(node, visit3);
|
|
26403
26489
|
};
|
|
26404
26490
|
visit3(sf);
|
|
26405
26491
|
out.sort((a, b) => a.line - b.line);
|
|
@@ -26707,13 +26793,13 @@ function assessBatchSafety(args) {
|
|
|
26707
26793
|
const signalGetters = new Set(args.graph.signals.map((s) => s.name));
|
|
26708
26794
|
let sf;
|
|
26709
26795
|
try {
|
|
26710
|
-
sf =
|
|
26796
|
+
sf = ts23.createSourceFile("__h.ts", `const __h = ${args.handler}`, ts23.ScriptTarget.Latest, true);
|
|
26711
26797
|
} catch {
|
|
26712
26798
|
return "unverified";
|
|
26713
26799
|
}
|
|
26714
26800
|
const calls = [];
|
|
26715
26801
|
const visit3 = (node) => {
|
|
26716
|
-
if (
|
|
26802
|
+
if (ts23.isCallExpression(node) && ts23.isIdentifier(node.expression)) {
|
|
26717
26803
|
const name = node.expression.text;
|
|
26718
26804
|
if (setters.has(name))
|
|
26719
26805
|
calls.push({ pos: node.getStart(sf), kind: "write" });
|
|
@@ -26722,7 +26808,7 @@ function assessBatchSafety(args) {
|
|
|
26722
26808
|
else if (!signalGetters.has(name) && !memoNames.has(name))
|
|
26723
26809
|
calls.push({ pos: node.getStart(sf), kind: "risky" });
|
|
26724
26810
|
}
|
|
26725
|
-
|
|
26811
|
+
ts23.forEachChild(node, visit3);
|
|
26726
26812
|
};
|
|
26727
26813
|
visit3(sf);
|
|
26728
26814
|
calls.sort((a, b) => a.pos - b.pos);
|
|
@@ -27399,6 +27485,7 @@ export {
|
|
|
27399
27485
|
listComponentFunctions,
|
|
27400
27486
|
jsxToIR,
|
|
27401
27487
|
joinProfilerEvents,
|
|
27488
|
+
isValueReferenceIdentifier,
|
|
27402
27489
|
isValidHelperId,
|
|
27403
27490
|
isSupported,
|
|
27404
27491
|
isStringTypedOperand,
|
|
@@ -27473,6 +27560,7 @@ export {
|
|
|
27473
27560
|
computeSsrSeedPlan,
|
|
27474
27561
|
compileJSX,
|
|
27475
27562
|
combineParentChildClientJs,
|
|
27563
|
+
collectValueReferencedNames,
|
|
27476
27564
|
collectModuleStringConsts,
|
|
27477
27565
|
collectLoopBoundNames,
|
|
27478
27566
|
collectContextConsumers,
|