@barefootjs/jsx 0.31.4 → 0.31.6
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/adapters/jsx-adapter.d.ts.map +1 -1
- package/dist/adapters/loop-bound-names.d.ts +18 -0
- package/dist/adapters/loop-bound-names.d.ts.map +1 -1
- package/dist/adapters/test-adapter.d.ts.map +1 -1
- package/dist/augment-inherited-props.d.ts +12 -2
- package/dist/augment-inherited-props.d.ts.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/debug.d.ts.map +1 -1
- package/dist/free-refs.d.ts +11 -2
- package/dist/free-refs.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +773 -649
- package/dist/ir-to-client-js/client-only-elision.d.ts +11 -5
- package/dist/ir-to-client-js/client-only-elision.d.ts.map +1 -1
- package/dist/ir-to-client-js/collect-elements.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/build-reactive-effects.d.ts.map +1 -1
- package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts +7 -0
- package/dist/ir-to-client-js/control-flow/plan/reactive-effects.d.ts.map +1 -1
- package/dist/ir-to-client-js/html-template.d.ts.map +1 -1
- package/dist/ir-to-client-js/reactivity.d.ts +16 -0
- package/dist/ir-to-client-js/reactivity.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +16 -0
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/ir-to-client-js/utils.d.ts +15 -0
- package/dist/ir-to-client-js/utils.d.ts.map +1 -1
- package/dist/module-exports.d.ts +64 -0
- package/dist/module-exports.d.ts.map +1 -1
- package/dist/scope/binding-scope.d.ts +1 -1
- package/dist/types.d.ts +112 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +117 -17
- package/src/__tests__/binding-scope-ratchet.test.ts +146 -21
- package/src/__tests__/component-type-parameters.test.ts +70 -0
- package/src/__tests__/csr-materialize-loop-preamble-shadow.test.ts +10 -1
- package/src/__tests__/doc-examples.test.ts +1 -0
- package/src/__tests__/free-refs.test.ts +1 -1
- package/src/__tests__/mutable-binding-writers.test.ts +133 -0
- package/src/__tests__/preamble-conditional-reactivity.test.ts +191 -0
- package/src/__tests__/signal-setter-updater-type.test.ts +81 -0
- package/src/adapters/jsx-adapter.ts +29 -3
- package/src/adapters/loop-bound-names.ts +18 -0
- package/src/adapters/test-adapter.ts +4 -1
- package/src/augment-inherited-props.ts +13 -1
- package/src/compiler.ts +18 -0
- package/src/debug.ts +34 -21
- package/src/free-refs.ts +14 -5
- package/src/index.ts +6 -0
- package/src/ir-to-client-js/client-only-elision.ts +11 -5
- package/src/ir-to-client-js/collect-elements.ts +17 -2
- package/src/ir-to-client-js/control-flow/plan/build-reactive-effects.ts +1 -0
- package/src/ir-to-client-js/control-flow/plan/reactive-effects.ts +7 -0
- package/src/ir-to-client-js/control-flow/stringify/reactive-effects.ts +12 -2
- package/src/ir-to-client-js/html-template.ts +51 -0
- package/src/ir-to-client-js/reactivity.ts +4 -2
- package/src/ir-to-client-js/types.ts +16 -0
- package/src/ir-to-client-js/utils.ts +15 -0
- package/src/jsx-to-ir.ts +117 -1
- package/src/module-exports.ts +137 -0
- package/src/scope/binding-scope.ts +1 -1
- package/src/types.ts +118 -0
package/dist/index.js
CHANGED
|
@@ -177,7 +177,7 @@ function findTopLevelTemplateLiterals(code) {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
// src/compiler.ts
|
|
180
|
-
import
|
|
180
|
+
import ts24 from "typescript";
|
|
181
181
|
|
|
182
182
|
// src/analyzer.ts
|
|
183
183
|
import ts9 from "typescript";
|
|
@@ -4477,6 +4477,8 @@ function generateCsrTemplateWithOpts(node, opts) {
|
|
|
4477
4477
|
if (node.expr === "null" || node.expr === "undefined")
|
|
4478
4478
|
return "";
|
|
4479
4479
|
if (node.clientOnly && node.slotId) {
|
|
4480
|
+
if (node.markerless)
|
|
4481
|
+
return "";
|
|
4480
4482
|
return `<!--bf:${node.slotId}--><!--/-->`;
|
|
4481
4483
|
}
|
|
4482
4484
|
{
|
|
@@ -9230,7 +9232,7 @@ function validateObjectFactoryDestructure(ctx, pattern, callee, loc) {
|
|
|
9230
9232
|
}
|
|
9231
9233
|
|
|
9232
9234
|
// src/jsx-to-ir.ts
|
|
9233
|
-
import
|
|
9235
|
+
import ts13 from "typescript";
|
|
9234
9236
|
|
|
9235
9237
|
// src/types.ts
|
|
9236
9238
|
var SCOPE_FORBIDDEN = {
|
|
@@ -9334,8 +9336,14 @@ function pickAttrMetaFromIR(src) {
|
|
|
9334
9336
|
...src.freeIdentifiers !== undefined && { freeIdentifiers: src.freeIdentifiers }
|
|
9335
9337
|
};
|
|
9336
9338
|
}
|
|
9339
|
+
var ESCAPE_SSR_COST = {
|
|
9340
|
+
"client-directive": "client-render",
|
|
9341
|
+
"prop-precompute": "none",
|
|
9342
|
+
rewrite: "none"
|
|
9343
|
+
};
|
|
9337
9344
|
|
|
9338
9345
|
// src/module-exports.ts
|
|
9346
|
+
import ts10 from "typescript";
|
|
9339
9347
|
function generateModuleExports(ir, extraInlineExported = new Set, rewriteRelativeImport, options) {
|
|
9340
9348
|
const lines = [];
|
|
9341
9349
|
for (const constant of options?.skipValueDeclarations ? [] : ir.metadata.localConstants) {
|
|
@@ -9432,6 +9440,49 @@ function findReachableNames(primaryRefs, declarations) {
|
|
|
9432
9440
|
}
|
|
9433
9441
|
return reachable;
|
|
9434
9442
|
}
|
|
9443
|
+
function findAssignedNames(bodyText, candidates) {
|
|
9444
|
+
const assigned = new Set;
|
|
9445
|
+
if (candidates.size === 0)
|
|
9446
|
+
return assigned;
|
|
9447
|
+
const sf = ts10.createSourceFile("bf-assignment-scan.tsx", bodyText, ts10.ScriptTarget.Latest, false, ts10.ScriptKind.TSX);
|
|
9448
|
+
const record = (target) => {
|
|
9449
|
+
if (ts10.isIdentifier(target) && candidates.has(target.text)) {
|
|
9450
|
+
assigned.add(target.text);
|
|
9451
|
+
}
|
|
9452
|
+
};
|
|
9453
|
+
const visit2 = (node) => {
|
|
9454
|
+
if (ts10.isBinaryExpression(node) && isAssignmentOperator(node.operatorToken.kind)) {
|
|
9455
|
+
record(node.left);
|
|
9456
|
+
} else if ((ts10.isPrefixUnaryExpression(node) || ts10.isPostfixUnaryExpression(node)) && (node.operator === ts10.SyntaxKind.PlusPlusToken || node.operator === ts10.SyntaxKind.MinusMinusToken)) {
|
|
9457
|
+
record(node.operand);
|
|
9458
|
+
}
|
|
9459
|
+
ts10.forEachChild(node, visit2);
|
|
9460
|
+
};
|
|
9461
|
+
ts10.forEachChild(sf, visit2);
|
|
9462
|
+
return assigned;
|
|
9463
|
+
}
|
|
9464
|
+
function closeOverWritersOfMutableBindings(primaryRefs, declarations, mutableNames) {
|
|
9465
|
+
let reachable = findReachableNames(primaryRefs, declarations);
|
|
9466
|
+
if (mutableNames.size === 0)
|
|
9467
|
+
return reachable;
|
|
9468
|
+
let seedText = primaryRefs;
|
|
9469
|
+
for (let round = 0;round <= declarations.length; round++) {
|
|
9470
|
+
const survivingMutables = new Set([...reachable].filter((name) => mutableNames.has(name)));
|
|
9471
|
+
if (survivingMutables.size === 0)
|
|
9472
|
+
return reachable;
|
|
9473
|
+
const added = declarations.filter((d) => !reachable.has(d.name)).filter((d) => findAssignedNames(d.body, survivingMutables).size > 0).map((d) => d.name);
|
|
9474
|
+
if (added.length === 0)
|
|
9475
|
+
return reachable;
|
|
9476
|
+
seedText += `
|
|
9477
|
+
` + added.join(`
|
|
9478
|
+
`);
|
|
9479
|
+
reachable = findReachableNames(seedText, declarations);
|
|
9480
|
+
}
|
|
9481
|
+
return reachable;
|
|
9482
|
+
}
|
|
9483
|
+
function isAssignmentOperator(kind) {
|
|
9484
|
+
return kind >= ts10.SyntaxKind.FirstAssignment && kind <= ts10.SyntaxKind.LastAssignment;
|
|
9485
|
+
}
|
|
9435
9486
|
function extractFunctionParams(value) {
|
|
9436
9487
|
const arrowMatch = value.match(/^(?:async\s*)?\(([^)]*)\)\s*(?::\s*[^=]+)?\s*=>/);
|
|
9437
9488
|
if (arrowMatch) {
|
|
@@ -9469,7 +9520,7 @@ function stripClientBuiltinImports(imports) {
|
|
|
9469
9520
|
}
|
|
9470
9521
|
|
|
9471
9522
|
// src/reactivity-checker.ts
|
|
9472
|
-
import
|
|
9523
|
+
import ts11 from "typescript";
|
|
9473
9524
|
var REACTIVE_BRAND = "__reactive";
|
|
9474
9525
|
function queryType(checker, node) {
|
|
9475
9526
|
incrementCounter("typeCheckerQueries");
|
|
@@ -9487,7 +9538,7 @@ function safeGetText(node) {
|
|
|
9487
9538
|
}
|
|
9488
9539
|
}
|
|
9489
9540
|
function analyze(node, checker) {
|
|
9490
|
-
if (
|
|
9541
|
+
if (ts11.isPropertyAccessExpression(node)) {
|
|
9491
9542
|
try {
|
|
9492
9543
|
const type = queryType(checker, node);
|
|
9493
9544
|
if (isReactiveType(type)) {
|
|
@@ -9511,7 +9562,7 @@ function analyze(node, checker) {
|
|
|
9511
9562
|
}
|
|
9512
9563
|
return NOT_REACTIVE;
|
|
9513
9564
|
}
|
|
9514
|
-
if (
|
|
9565
|
+
if (ts11.isIdentifier(node)) {
|
|
9515
9566
|
try {
|
|
9516
9567
|
const type = queryType(checker, node);
|
|
9517
9568
|
if (isReactiveType(type)) {
|
|
@@ -9523,7 +9574,7 @@ function analyze(node, checker) {
|
|
|
9523
9574
|
} catch {}
|
|
9524
9575
|
return NOT_REACTIVE;
|
|
9525
9576
|
}
|
|
9526
|
-
if (
|
|
9577
|
+
if (ts11.isCallExpression(node)) {
|
|
9527
9578
|
try {
|
|
9528
9579
|
const calleeType = queryType(checker, node.expression);
|
|
9529
9580
|
if (isReactiveType(calleeType)) {
|
|
@@ -9536,7 +9587,7 @@ function analyze(node, checker) {
|
|
|
9536
9587
|
}
|
|
9537
9588
|
let foundChild;
|
|
9538
9589
|
let foundChildText = "";
|
|
9539
|
-
|
|
9590
|
+
ts11.forEachChild(node, (child) => {
|
|
9540
9591
|
if (foundChild?.isReactive)
|
|
9541
9592
|
return;
|
|
9542
9593
|
const result = analyze(child, checker);
|
|
@@ -9565,7 +9616,7 @@ function containsReactiveExpression(node, checker) {
|
|
|
9565
9616
|
}
|
|
9566
9617
|
|
|
9567
9618
|
// src/free-refs.ts
|
|
9568
|
-
import
|
|
9619
|
+
import ts12 from "typescript";
|
|
9569
9620
|
var _bindingMapCache = new WeakMap;
|
|
9570
9621
|
function buildBindingMap(env) {
|
|
9571
9622
|
const cached = _bindingMapCache.get(env);
|
|
@@ -9603,8 +9654,8 @@ function buildBindingMap(env) {
|
|
|
9603
9654
|
for (const m of env.memos) {
|
|
9604
9655
|
map.set(m.name, "memo-getter");
|
|
9605
9656
|
}
|
|
9606
|
-
if (env.
|
|
9607
|
-
for (const name of env.
|
|
9657
|
+
if (env.loopValueBoundNames) {
|
|
9658
|
+
for (const name of env.loopValueBoundNames)
|
|
9608
9659
|
map.set(name, "render-item");
|
|
9609
9660
|
}
|
|
9610
9661
|
_bindingMapCache.set(env, map);
|
|
@@ -9633,20 +9684,20 @@ function defaultBindingScope(kind) {
|
|
|
9633
9684
|
function collectIdentifiers2(node) {
|
|
9634
9685
|
const out = [];
|
|
9635
9686
|
const visit2 = (n, parent) => {
|
|
9636
|
-
if (
|
|
9637
|
-
if (parent &&
|
|
9687
|
+
if (ts12.isIdentifier(n)) {
|
|
9688
|
+
if (parent && ts12.isPropertyAccessExpression(parent) && parent.name === n)
|
|
9638
9689
|
return;
|
|
9639
|
-
if (parent &&
|
|
9690
|
+
if (parent && ts12.isPropertyAssignment(parent) && parent.name === n)
|
|
9640
9691
|
return;
|
|
9641
|
-
if (parent && (
|
|
9692
|
+
if (parent && (ts12.isJsxOpeningElement(parent) || ts12.isJsxClosingElement(parent) || ts12.isJsxSelfClosingElement(parent)) && parent.tagName === n) {
|
|
9642
9693
|
return;
|
|
9643
9694
|
}
|
|
9644
|
-
if (parent &&
|
|
9695
|
+
if (parent && ts12.isJsxAttribute(parent) && parent.name === n)
|
|
9645
9696
|
return;
|
|
9646
9697
|
out.push(n);
|
|
9647
9698
|
return;
|
|
9648
9699
|
}
|
|
9649
|
-
|
|
9700
|
+
ts12.forEachChild(n, (child) => visit2(child, n));
|
|
9650
9701
|
};
|
|
9651
9702
|
visit2(node);
|
|
9652
9703
|
return out;
|
|
@@ -9655,7 +9706,7 @@ function collectReactiveBrandRefs(node, checker) {
|
|
|
9655
9706
|
const out = [];
|
|
9656
9707
|
const seen = new Set;
|
|
9657
9708
|
const visit2 = (n) => {
|
|
9658
|
-
if (
|
|
9709
|
+
if (ts12.isPropertyAccessExpression(n)) {
|
|
9659
9710
|
try {
|
|
9660
9711
|
const type = checker.getTypeAtLocation(n);
|
|
9661
9712
|
if (isReactiveType(type)) {
|
|
@@ -9673,7 +9724,7 @@ function collectReactiveBrandRefs(node, checker) {
|
|
|
9673
9724
|
incrementCounter("freeRefsTypeLookupFailures");
|
|
9674
9725
|
}
|
|
9675
9726
|
}
|
|
9676
|
-
|
|
9727
|
+
ts12.forEachChild(n, visit2);
|
|
9677
9728
|
};
|
|
9678
9729
|
visit2(node);
|
|
9679
9730
|
return out;
|
|
@@ -9683,14 +9734,14 @@ function resolveConstantInitializerRefs(c, env, visited) {
|
|
|
9683
9734
|
return [];
|
|
9684
9735
|
if (c.containsArrow)
|
|
9685
9736
|
return [];
|
|
9686
|
-
const sf =
|
|
9737
|
+
const sf = ts12.createSourceFile("__const_init.ts", `const __probe = (${c.value});`, ts12.ScriptTarget.Latest, true);
|
|
9687
9738
|
const stmt = sf.statements[0];
|
|
9688
|
-
if (!stmt || !
|
|
9739
|
+
if (!stmt || !ts12.isVariableStatement(stmt))
|
|
9689
9740
|
return [];
|
|
9690
9741
|
const decl = stmt.declarationList.declarations[0];
|
|
9691
9742
|
if (!decl || !decl.initializer)
|
|
9692
9743
|
return [];
|
|
9693
|
-
const expr =
|
|
9744
|
+
const expr = ts12.isParenthesizedExpression(decl.initializer) ? decl.initializer.expression : decl.initializer;
|
|
9694
9745
|
return resolveFreeRefsInternal(expr, env, visited);
|
|
9695
9746
|
}
|
|
9696
9747
|
function resolveFreeRefsInternal(node, env, visited) {
|
|
@@ -9702,7 +9753,7 @@ function resolveFreeRefsInternal(node, env, visited) {
|
|
|
9702
9753
|
const name = ident.text;
|
|
9703
9754
|
if (env.propsObjectName === name) {
|
|
9704
9755
|
const parent = ident.parent;
|
|
9705
|
-
if (parent &&
|
|
9756
|
+
if (parent && ts12.isPropertyAccessExpression(parent) && parent.expression === ident && parent.name.text === "children") {
|
|
9706
9757
|
continue;
|
|
9707
9758
|
}
|
|
9708
9759
|
}
|
|
@@ -10131,13 +10182,13 @@ function exprCallsReactiveGetters(expr, ctx) {
|
|
|
10131
10182
|
function visit2(n) {
|
|
10132
10183
|
if (found)
|
|
10133
10184
|
return;
|
|
10134
|
-
if (
|
|
10185
|
+
if (ts13.isCallExpression(n) && ts13.isIdentifier(n.expression)) {
|
|
10135
10186
|
if (names.has(n.expression.text)) {
|
|
10136
10187
|
found = true;
|
|
10137
10188
|
return;
|
|
10138
10189
|
}
|
|
10139
10190
|
}
|
|
10140
|
-
|
|
10191
|
+
ts13.forEachChild(n, visit2);
|
|
10141
10192
|
}
|
|
10142
10193
|
visit2(expr);
|
|
10143
10194
|
return found;
|
|
@@ -10164,11 +10215,11 @@ function exprReferencesModuleClientSignal(expr, ctx) {
|
|
|
10164
10215
|
function visit2(n) {
|
|
10165
10216
|
if (found)
|
|
10166
10217
|
return;
|
|
10167
|
-
if (
|
|
10218
|
+
if (ts13.isCallExpression(n) && ts13.isIdentifier(n.expression) && names.has(n.expression.text)) {
|
|
10168
10219
|
found = true;
|
|
10169
10220
|
return;
|
|
10170
10221
|
}
|
|
10171
|
-
|
|
10222
|
+
ts13.forEachChild(n, visit2);
|
|
10172
10223
|
}
|
|
10173
10224
|
visit2(expr);
|
|
10174
10225
|
return found;
|
|
@@ -10178,11 +10229,11 @@ function exprHasFunctionCalls(expr) {
|
|
|
10178
10229
|
function visit2(n) {
|
|
10179
10230
|
if (found)
|
|
10180
10231
|
return;
|
|
10181
|
-
if (
|
|
10232
|
+
if (ts13.isCallExpression(n)) {
|
|
10182
10233
|
found = true;
|
|
10183
10234
|
return;
|
|
10184
10235
|
}
|
|
10185
|
-
|
|
10236
|
+
ts13.forEachChild(n, visit2);
|
|
10186
10237
|
}
|
|
10187
10238
|
visit2(expr);
|
|
10188
10239
|
return found;
|
|
@@ -10219,10 +10270,10 @@ function lowerDateCalls(text, expr, ctx) {
|
|
|
10219
10270
|
return text;
|
|
10220
10271
|
const candidates = [];
|
|
10221
10272
|
function visit2(n) {
|
|
10222
|
-
if (
|
|
10273
|
+
if (ts13.isCallExpression(n) && n.arguments.length === 0 && ts13.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
|
|
10223
10274
|
candidates.push(n);
|
|
10224
10275
|
}
|
|
10225
|
-
|
|
10276
|
+
ts13.forEachChild(n, visit2);
|
|
10226
10277
|
}
|
|
10227
10278
|
visit2(expr);
|
|
10228
10279
|
if (candidates.length === 0)
|
|
@@ -10247,10 +10298,10 @@ function lowerToLocaleDateCalls(text, expr, ctx) {
|
|
|
10247
10298
|
return text;
|
|
10248
10299
|
const candidates = [];
|
|
10249
10300
|
function visit2(n) {
|
|
10250
|
-
if (
|
|
10301
|
+
if (ts13.isCallExpression(n) && n.arguments.length === 2 && ts13.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && n.expression.name.text === "toLocaleDateString") {
|
|
10251
10302
|
candidates.push(n);
|
|
10252
10303
|
}
|
|
10253
|
-
|
|
10304
|
+
ts13.forEachChild(n, visit2);
|
|
10254
10305
|
}
|
|
10255
10306
|
visit2(expr);
|
|
10256
10307
|
if (candidates.length === 0)
|
|
@@ -10304,10 +10355,10 @@ function collectBranchLocalPropRefsViaSubstitution(node, ctx) {
|
|
|
10304
10355
|
return;
|
|
10305
10356
|
let acc;
|
|
10306
10357
|
function visit2(n, parent) {
|
|
10307
|
-
if (
|
|
10308
|
-
const isObjectKey = parent &&
|
|
10309
|
-
const isShorthand = parent &&
|
|
10310
|
-
const isAccessName = parent &&
|
|
10358
|
+
if (ts13.isIdentifier(n) && propDepsMap.has(n.text)) {
|
|
10359
|
+
const isObjectKey = parent && ts13.isPropertyAssignment(parent) && parent.name === n;
|
|
10360
|
+
const isShorthand = parent && ts13.isShorthandPropertyAssignment(parent) && parent.name === n;
|
|
10361
|
+
const isAccessName = parent && ts13.isPropertyAccessExpression(parent) && parent.name === n;
|
|
10311
10362
|
if (!isObjectKey && !isShorthand && !isAccessName) {
|
|
10312
10363
|
const deps = propDepsMap.get(n.text);
|
|
10313
10364
|
if (deps && deps.size > 0) {
|
|
@@ -10318,7 +10369,7 @@ function collectBranchLocalPropRefsViaSubstitution(node, ctx) {
|
|
|
10318
10369
|
}
|
|
10319
10370
|
}
|
|
10320
10371
|
}
|
|
10321
|
-
|
|
10372
|
+
ts13.forEachChild(n, (child) => visit2(child, n));
|
|
10322
10373
|
}
|
|
10323
10374
|
visit2(node);
|
|
10324
10375
|
return acc;
|
|
@@ -10394,21 +10445,21 @@ function createTransformContext(analyzer) {
|
|
|
10394
10445
|
function buildComponentNamespaces(ctx) {
|
|
10395
10446
|
const result = new Map;
|
|
10396
10447
|
for (const stmt of ctx.sourceFile.statements) {
|
|
10397
|
-
if (!
|
|
10448
|
+
if (!ts13.isVariableStatement(stmt))
|
|
10398
10449
|
continue;
|
|
10399
10450
|
for (const decl of stmt.declarationList.declarations) {
|
|
10400
|
-
if (!decl.initializer || !
|
|
10451
|
+
if (!decl.initializer || !ts13.isIdentifier(decl.name))
|
|
10401
10452
|
continue;
|
|
10402
10453
|
let init = decl.initializer;
|
|
10403
|
-
while (
|
|
10454
|
+
while (ts13.isParenthesizedExpression(init))
|
|
10404
10455
|
init = init.expression;
|
|
10405
|
-
if (!
|
|
10456
|
+
if (!ts13.isObjectLiteralExpression(init))
|
|
10406
10457
|
continue;
|
|
10407
10458
|
const members = new Map;
|
|
10408
10459
|
for (const prop of init.properties) {
|
|
10409
|
-
if (
|
|
10460
|
+
if (ts13.isShorthandPropertyAssignment(prop)) {
|
|
10410
10461
|
members.set(prop.name.text, prop.name.text);
|
|
10411
|
-
} else if (
|
|
10462
|
+
} else if (ts13.isPropertyAssignment(prop) && (ts13.isIdentifier(prop.name) || ts13.isStringLiteral(prop.name)) && ts13.isIdentifier(prop.initializer)) {
|
|
10412
10463
|
members.set(prop.name.text, prop.initializer.text);
|
|
10413
10464
|
}
|
|
10414
10465
|
}
|
|
@@ -10420,11 +10471,11 @@ function buildComponentNamespaces(ctx) {
|
|
|
10420
10471
|
return result;
|
|
10421
10472
|
}
|
|
10422
10473
|
function resolveMemberExpressionTag(tagNode, ctx) {
|
|
10423
|
-
if (!
|
|
10474
|
+
if (!ts13.isPropertyAccessExpression(tagNode))
|
|
10424
10475
|
return null;
|
|
10425
|
-
if (!
|
|
10476
|
+
if (!ts13.isIdentifier(tagNode.expression))
|
|
10426
10477
|
return null;
|
|
10427
|
-
if (!
|
|
10478
|
+
if (!ts13.isIdentifier(tagNode.name))
|
|
10428
10479
|
return null;
|
|
10429
10480
|
if (!ctx._componentNamespaces) {
|
|
10430
10481
|
ctx._componentNamespaces = buildComponentNamespaces(ctx);
|
|
@@ -10457,7 +10508,7 @@ function makeBindingEnv(ctx) {
|
|
|
10457
10508
|
localFunctions: a.localFunctions,
|
|
10458
10509
|
imports: a.imports,
|
|
10459
10510
|
ambientGlobals: a.ambientGlobals,
|
|
10460
|
-
|
|
10511
|
+
loopValueBoundNames: boundNames,
|
|
10461
10512
|
checker: a.checker
|
|
10462
10513
|
};
|
|
10463
10514
|
ctx._bindingEnv = env;
|
|
@@ -10581,7 +10632,7 @@ function buildIRRoot(analyzer) {
|
|
|
10581
10632
|
return null;
|
|
10582
10633
|
const ctx = createTransformContext(analyzer);
|
|
10583
10634
|
const jsxReturn = analyzer.jsxReturn;
|
|
10584
|
-
if (
|
|
10635
|
+
if (ts13.isJsxElement(jsxReturn) || ts13.isJsxSelfClosingElement(jsxReturn) || ts13.isJsxFragment(jsxReturn)) {
|
|
10585
10636
|
const ir2 = transformNode(jsxReturn, ctx);
|
|
10586
10637
|
if (ir2 && needsScopeWrapper(ir2)) {
|
|
10587
10638
|
return wrapInScopeElement(ir2);
|
|
@@ -10637,22 +10688,22 @@ function wrapInScopeElement(node) {
|
|
|
10637
10688
|
};
|
|
10638
10689
|
}
|
|
10639
10690
|
function transformNode(node, ctx) {
|
|
10640
|
-
if (
|
|
10691
|
+
if (ts13.isJsxElement(node)) {
|
|
10641
10692
|
return transformJsxElement(node, ctx);
|
|
10642
10693
|
}
|
|
10643
|
-
if (
|
|
10694
|
+
if (ts13.isJsxSelfClosingElement(node)) {
|
|
10644
10695
|
return transformSelfClosingElement(node, ctx);
|
|
10645
10696
|
}
|
|
10646
|
-
if (
|
|
10697
|
+
if (ts13.isJsxFragment(node)) {
|
|
10647
10698
|
return transformFragment(node, ctx);
|
|
10648
10699
|
}
|
|
10649
|
-
if (
|
|
10700
|
+
if (ts13.isJsxText(node)) {
|
|
10650
10701
|
return transformText(node, ctx);
|
|
10651
10702
|
}
|
|
10652
|
-
if (
|
|
10703
|
+
if (ts13.isJsxExpression(node)) {
|
|
10653
10704
|
return transformExpression(node, ctx);
|
|
10654
10705
|
}
|
|
10655
|
-
if (
|
|
10706
|
+
if (ts13.isConditionalExpression(node)) {
|
|
10656
10707
|
return transformConditional(node, ctx);
|
|
10657
10708
|
}
|
|
10658
10709
|
return null;
|
|
@@ -11009,7 +11060,7 @@ function transformSelfClosingComponent(node, ctx, name) {
|
|
|
11009
11060
|
}
|
|
11010
11061
|
function isTransparentFragment(node, ctx) {
|
|
11011
11062
|
const children = node.children.filter((child2) => {
|
|
11012
|
-
if (
|
|
11063
|
+
if (ts13.isJsxText(child2)) {
|
|
11013
11064
|
return child2.text.trim() !== "";
|
|
11014
11065
|
}
|
|
11015
11066
|
return true;
|
|
@@ -11017,7 +11068,7 @@ function isTransparentFragment(node, ctx) {
|
|
|
11017
11068
|
if (children.length !== 1)
|
|
11018
11069
|
return false;
|
|
11019
11070
|
const child = children[0];
|
|
11020
|
-
if (!
|
|
11071
|
+
if (!ts13.isJsxExpression(child))
|
|
11021
11072
|
return false;
|
|
11022
11073
|
if (!child.expression)
|
|
11023
11074
|
return false;
|
|
@@ -11061,7 +11112,7 @@ function transformChildren(children, ctx) {
|
|
|
11061
11112
|
const result = [];
|
|
11062
11113
|
for (let i = 0;i < children.length; i++) {
|
|
11063
11114
|
const child = children[i];
|
|
11064
|
-
if (
|
|
11115
|
+
if (ts13.isJsxExpression(child) && !child.expression) {
|
|
11065
11116
|
continue;
|
|
11066
11117
|
}
|
|
11067
11118
|
const transformed = transformNode(child, ctx);
|
|
@@ -11076,10 +11127,10 @@ function transformChildren(children, ctx) {
|
|
|
11076
11127
|
}
|
|
11077
11128
|
function isRenderNothingLiteral(expr, ctx) {
|
|
11078
11129
|
let e = expr;
|
|
11079
|
-
while (
|
|
11130
|
+
while (ts13.isParenthesizedExpression(e) || ts13.isAsExpression(e) || ts13.isSatisfiesExpression(e) || ts13.isNonNullExpression(e)) {
|
|
11080
11131
|
e = e.expression;
|
|
11081
11132
|
}
|
|
11082
|
-
return e.kind ===
|
|
11133
|
+
return e.kind === ts13.SyntaxKind.NullKeyword || e.kind === ts13.SyntaxKind.TrueKeyword || e.kind === ts13.SyntaxKind.FalseKeyword || ts13.isIdentifier(e) && e.text === "undefined" && !isNameBound("undefined", makeBindingEnv(ctx));
|
|
11083
11134
|
}
|
|
11084
11135
|
function transformText(node, ctx) {
|
|
11085
11136
|
const text = node.text.replace(/\s+/g, " ");
|
|
@@ -11105,7 +11156,7 @@ function transformExpressionInner(expr, ctx, node, isClientOnly) {
|
|
|
11105
11156
|
return null;
|
|
11106
11157
|
}
|
|
11107
11158
|
checkBareSignalOrMemoIdentifier(expr, ctx);
|
|
11108
|
-
if (
|
|
11159
|
+
if (ts13.isIdentifier(expr)) {
|
|
11109
11160
|
const jsxNode = ctx.analyzer.jsxConstants.get(expr.text);
|
|
11110
11161
|
if (jsxNode) {
|
|
11111
11162
|
return transformNode(jsxNode, ctx);
|
|
@@ -11384,38 +11435,38 @@ function transformLogicalAnd(node, ctx) {
|
|
|
11384
11435
|
};
|
|
11385
11436
|
}
|
|
11386
11437
|
function containsJsxInExpression(node) {
|
|
11387
|
-
if (
|
|
11438
|
+
if (ts13.isJsxElement(node) || ts13.isJsxSelfClosingElement(node) || ts13.isJsxFragment(node)) {
|
|
11388
11439
|
return true;
|
|
11389
11440
|
}
|
|
11390
|
-
return
|
|
11441
|
+
return ts13.forEachChild(node, containsJsxInExpression) ?? false;
|
|
11391
11442
|
}
|
|
11392
11443
|
function callsJsxHelper(node, ctx) {
|
|
11393
11444
|
let found = false;
|
|
11394
11445
|
const visit2 = (n) => {
|
|
11395
11446
|
if (found)
|
|
11396
11447
|
return;
|
|
11397
|
-
if (
|
|
11448
|
+
if (ts13.isCallExpression(n) && ts13.isIdentifier(n.expression)) {
|
|
11398
11449
|
const name = n.expression.text;
|
|
11399
11450
|
if (ctx.analyzer.jsxFunctions.has(name) || ctx.analyzer.jsxMultiReturnFunctions.has(name)) {
|
|
11400
11451
|
found = true;
|
|
11401
11452
|
return;
|
|
11402
11453
|
}
|
|
11403
11454
|
}
|
|
11404
|
-
|
|
11455
|
+
ts13.forEachChild(n, visit2);
|
|
11405
11456
|
};
|
|
11406
11457
|
visit2(node);
|
|
11407
11458
|
return found;
|
|
11408
11459
|
}
|
|
11409
11460
|
function containsAwaitExpression(node) {
|
|
11410
|
-
if (
|
|
11461
|
+
if (ts13.isAwaitExpression(node))
|
|
11411
11462
|
return true;
|
|
11412
|
-
if (
|
|
11463
|
+
if (ts13.isFunctionDeclaration(node) || ts13.isFunctionExpression(node) || ts13.isArrowFunction(node))
|
|
11413
11464
|
return false;
|
|
11414
|
-
return
|
|
11465
|
+
return ts13.forEachChild(node, containsAwaitExpression) ?? false;
|
|
11415
11466
|
}
|
|
11416
11467
|
function transformNullishCoalescing(node, ctx) {
|
|
11417
11468
|
const leftText = ctx.getJS(node.left);
|
|
11418
|
-
const isNullish = node.operatorToken.kind ===
|
|
11469
|
+
const isNullish = node.operatorToken.kind === ts13.SyntaxKind.QuestionQuestionToken;
|
|
11419
11470
|
const condition = isNullish ? `${leftText} != null` : leftText;
|
|
11420
11471
|
const leftOrigin = {
|
|
11421
11472
|
phase: "tick",
|
|
@@ -11461,36 +11512,36 @@ function transformNullishCoalescing(node, ctx) {
|
|
|
11461
11512
|
}
|
|
11462
11513
|
function assertNever2(expr) {
|
|
11463
11514
|
const kind = expr?.kind;
|
|
11464
|
-
throw new Error(`transformJsxExpression: unhandled ts.SyntaxKind ${kind !== undefined ?
|
|
11515
|
+
throw new Error(`transformJsxExpression: unhandled ts.SyntaxKind ${kind !== undefined ? ts13.SyntaxKind[kind] : "unknown"} ` + `(kind=${kind}). Update spec/compiler.md Appendix A and the switch in jsx-to-ir.ts.`);
|
|
11465
11516
|
}
|
|
11466
11517
|
function transformJsxExpression(expr, ctx, isClientOnly = false) {
|
|
11467
11518
|
const node = expr;
|
|
11468
11519
|
switch (node.kind) {
|
|
11469
|
-
case
|
|
11470
|
-
case
|
|
11471
|
-
case
|
|
11472
|
-
case
|
|
11473
|
-
case
|
|
11474
|
-
case
|
|
11520
|
+
case ts13.SyntaxKind.ParenthesizedExpression:
|
|
11521
|
+
case ts13.SyntaxKind.AsExpression:
|
|
11522
|
+
case ts13.SyntaxKind.SatisfiesExpression:
|
|
11523
|
+
case ts13.SyntaxKind.NonNullExpression:
|
|
11524
|
+
case ts13.SyntaxKind.TypeAssertionExpression:
|
|
11525
|
+
case ts13.SyntaxKind.PartiallyEmittedExpression:
|
|
11475
11526
|
return transformJsxExpression(node.expression, ctx, isClientOnly);
|
|
11476
|
-
case
|
|
11527
|
+
case ts13.SyntaxKind.JsxElement:
|
|
11477
11528
|
return transformJsxElement(node, ctx);
|
|
11478
|
-
case
|
|
11529
|
+
case ts13.SyntaxKind.JsxFragment:
|
|
11479
11530
|
return transformFragment(node, ctx);
|
|
11480
|
-
case
|
|
11531
|
+
case ts13.SyntaxKind.JsxSelfClosingElement:
|
|
11481
11532
|
return transformSelfClosingElement(node, ctx);
|
|
11482
|
-
case
|
|
11533
|
+
case ts13.SyntaxKind.ConditionalExpression:
|
|
11483
11534
|
return transformConditional(node, ctx);
|
|
11484
|
-
case
|
|
11485
|
-
if (node.operatorToken.kind ===
|
|
11535
|
+
case ts13.SyntaxKind.BinaryExpression: {
|
|
11536
|
+
if (node.operatorToken.kind === ts13.SyntaxKind.AmpersandAmpersandToken) {
|
|
11486
11537
|
return transformLogicalAnd(node, ctx);
|
|
11487
11538
|
}
|
|
11488
|
-
if ((node.operatorToken.kind ===
|
|
11539
|
+
if ((node.operatorToken.kind === ts13.SyntaxKind.QuestionQuestionToken || node.operatorToken.kind === ts13.SyntaxKind.BarBarToken) && (containsJsxInExpression(node.right) || callsJsxHelper(node.right, ctx))) {
|
|
11489
11540
|
return transformNullishCoalescing(node, ctx);
|
|
11490
11541
|
}
|
|
11491
11542
|
return null;
|
|
11492
11543
|
}
|
|
11493
|
-
case
|
|
11544
|
+
case ts13.SyntaxKind.CallExpression: {
|
|
11494
11545
|
const mapMethod = getMapLikeMethod(node);
|
|
11495
11546
|
if (mapMethod) {
|
|
11496
11547
|
const mapResult = transformMapCall(node, ctx, isClientOnly, mapMethod);
|
|
@@ -11498,7 +11549,7 @@ function transformJsxExpression(expr, ctx, isClientOnly = false) {
|
|
|
11498
11549
|
return mapResult;
|
|
11499
11550
|
}
|
|
11500
11551
|
const callee = node.expression;
|
|
11501
|
-
if (
|
|
11552
|
+
if (ts13.isIdentifier(callee)) {
|
|
11502
11553
|
const jsxFunc = ctx.analyzer.jsxFunctions.get(callee.text);
|
|
11503
11554
|
if (jsxFunc) {
|
|
11504
11555
|
return transformJsxFunctionCall(node, jsxFunc, ctx, isClientOnly);
|
|
@@ -11510,39 +11561,39 @@ function transformJsxExpression(expr, ctx, isClientOnly = false) {
|
|
|
11510
11561
|
}
|
|
11511
11562
|
return null;
|
|
11512
11563
|
}
|
|
11513
|
-
case
|
|
11514
|
-
case
|
|
11515
|
-
case
|
|
11516
|
-
case
|
|
11517
|
-
case
|
|
11518
|
-
case
|
|
11519
|
-
case
|
|
11520
|
-
case
|
|
11521
|
-
case
|
|
11522
|
-
case
|
|
11523
|
-
case
|
|
11524
|
-
case
|
|
11525
|
-
case
|
|
11526
|
-
case
|
|
11527
|
-
case
|
|
11528
|
-
case
|
|
11529
|
-
case
|
|
11530
|
-
case
|
|
11531
|
-
case
|
|
11532
|
-
case
|
|
11533
|
-
case
|
|
11534
|
-
case
|
|
11535
|
-
case
|
|
11536
|
-
case
|
|
11537
|
-
case
|
|
11538
|
-
case
|
|
11539
|
-
case
|
|
11540
|
-
case
|
|
11541
|
-
case
|
|
11542
|
-
case
|
|
11543
|
-
case
|
|
11564
|
+
case ts13.SyntaxKind.Identifier:
|
|
11565
|
+
case ts13.SyntaxKind.StringLiteral:
|
|
11566
|
+
case ts13.SyntaxKind.NumericLiteral:
|
|
11567
|
+
case ts13.SyntaxKind.BigIntLiteral:
|
|
11568
|
+
case ts13.SyntaxKind.RegularExpressionLiteral:
|
|
11569
|
+
case ts13.SyntaxKind.NoSubstitutionTemplateLiteral:
|
|
11570
|
+
case ts13.SyntaxKind.TemplateExpression:
|
|
11571
|
+
case ts13.SyntaxKind.TaggedTemplateExpression:
|
|
11572
|
+
case ts13.SyntaxKind.TrueKeyword:
|
|
11573
|
+
case ts13.SyntaxKind.FalseKeyword:
|
|
11574
|
+
case ts13.SyntaxKind.NullKeyword:
|
|
11575
|
+
case ts13.SyntaxKind.ThisKeyword:
|
|
11576
|
+
case ts13.SyntaxKind.SuperKeyword:
|
|
11577
|
+
case ts13.SyntaxKind.ImportKeyword:
|
|
11578
|
+
case ts13.SyntaxKind.PropertyAccessExpression:
|
|
11579
|
+
case ts13.SyntaxKind.ElementAccessExpression:
|
|
11580
|
+
case ts13.SyntaxKind.PrefixUnaryExpression:
|
|
11581
|
+
case ts13.SyntaxKind.PostfixUnaryExpression:
|
|
11582
|
+
case ts13.SyntaxKind.TypeOfExpression:
|
|
11583
|
+
case ts13.SyntaxKind.VoidExpression:
|
|
11584
|
+
case ts13.SyntaxKind.DeleteExpression:
|
|
11585
|
+
case ts13.SyntaxKind.NewExpression:
|
|
11586
|
+
case ts13.SyntaxKind.ObjectLiteralExpression:
|
|
11587
|
+
case ts13.SyntaxKind.ArrowFunction:
|
|
11588
|
+
case ts13.SyntaxKind.FunctionExpression:
|
|
11589
|
+
case ts13.SyntaxKind.ClassExpression:
|
|
11590
|
+
case ts13.SyntaxKind.MetaProperty:
|
|
11591
|
+
case ts13.SyntaxKind.ExpressionWithTypeArguments:
|
|
11592
|
+
case ts13.SyntaxKind.CommaListExpression:
|
|
11593
|
+
case ts13.SyntaxKind.SyntheticExpression:
|
|
11594
|
+
case ts13.SyntaxKind.ArrayLiteralExpression:
|
|
11544
11595
|
return null;
|
|
11545
|
-
case
|
|
11596
|
+
case ts13.SyntaxKind.AwaitExpression:
|
|
11546
11597
|
ctx.analyzer.errors.push(createError(ErrorCodes.STAGE_AWAIT_IN_TEMPLATE, getSourceLocation(node, ctx.sourceFile, ctx.filePath)));
|
|
11547
11598
|
return {
|
|
11548
11599
|
type: "expression",
|
|
@@ -11553,16 +11604,16 @@ function transformJsxExpression(expr, ctx, isClientOnly = false) {
|
|
|
11553
11604
|
loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath),
|
|
11554
11605
|
origin: { phase: "tick", scope: "template", effect: "pure", freeRefs: [] }
|
|
11555
11606
|
};
|
|
11556
|
-
case
|
|
11607
|
+
case ts13.SyntaxKind.YieldExpression:
|
|
11557
11608
|
return null;
|
|
11558
|
-
case
|
|
11559
|
-
case
|
|
11560
|
-
case
|
|
11561
|
-
case
|
|
11562
|
-
case
|
|
11563
|
-
case
|
|
11564
|
-
case
|
|
11565
|
-
case
|
|
11609
|
+
case ts13.SyntaxKind.SpreadElement:
|
|
11610
|
+
case ts13.SyntaxKind.OmittedExpression:
|
|
11611
|
+
case ts13.SyntaxKind.JsxExpression:
|
|
11612
|
+
case ts13.SyntaxKind.JsxOpeningElement:
|
|
11613
|
+
case ts13.SyntaxKind.JsxOpeningFragment:
|
|
11614
|
+
case ts13.SyntaxKind.JsxClosingFragment:
|
|
11615
|
+
case ts13.SyntaxKind.JsxAttributes:
|
|
11616
|
+
case ts13.SyntaxKind.MissingDeclaration:
|
|
11566
11617
|
return null;
|
|
11567
11618
|
default:
|
|
11568
11619
|
return assertNever2(node);
|
|
@@ -11599,7 +11650,7 @@ function transformConditionalBranch(node, ctx) {
|
|
|
11599
11650
|
};
|
|
11600
11651
|
}
|
|
11601
11652
|
function getMapLikeMethod(node) {
|
|
11602
|
-
if (!
|
|
11653
|
+
if (!ts13.isPropertyAccessExpression(node.expression))
|
|
11603
11654
|
return null;
|
|
11604
11655
|
const name = node.expression.name.text;
|
|
11605
11656
|
if (name === "map")
|
|
@@ -11609,9 +11660,9 @@ function getMapLikeMethod(node) {
|
|
|
11609
11660
|
return null;
|
|
11610
11661
|
}
|
|
11611
11662
|
function isFilterCall(node) {
|
|
11612
|
-
if (!
|
|
11663
|
+
if (!ts13.isCallExpression(node))
|
|
11613
11664
|
return null;
|
|
11614
|
-
if (!
|
|
11665
|
+
if (!ts13.isPropertyAccessExpression(node.expression))
|
|
11615
11666
|
return null;
|
|
11616
11667
|
if (node.expression.name.text !== "filter")
|
|
11617
11668
|
return null;
|
|
@@ -11623,9 +11674,9 @@ function isFilterCall(node) {
|
|
|
11623
11674
|
};
|
|
11624
11675
|
}
|
|
11625
11676
|
function isSortCall(node) {
|
|
11626
|
-
if (!
|
|
11677
|
+
if (!ts13.isCallExpression(node))
|
|
11627
11678
|
return null;
|
|
11628
|
-
if (!
|
|
11679
|
+
if (!ts13.isPropertyAccessExpression(node.expression))
|
|
11629
11680
|
return null;
|
|
11630
11681
|
const methodName = node.expression.name.text;
|
|
11631
11682
|
if (methodName !== "sort" && methodName !== "toSorted")
|
|
@@ -11639,9 +11690,9 @@ function isSortCall(node) {
|
|
|
11639
11690
|
};
|
|
11640
11691
|
}
|
|
11641
11692
|
function isIteratorShapeCall(node) {
|
|
11642
|
-
if (!
|
|
11693
|
+
if (!ts13.isCallExpression(node))
|
|
11643
11694
|
return null;
|
|
11644
|
-
if (!
|
|
11695
|
+
if (!ts13.isPropertyAccessExpression(node.expression))
|
|
11645
11696
|
return null;
|
|
11646
11697
|
if (node.arguments.length !== 0)
|
|
11647
11698
|
return null;
|
|
@@ -11651,11 +11702,11 @@ function isIteratorShapeCall(node) {
|
|
|
11651
11702
|
return { array: node.expression.expression, shape: name };
|
|
11652
11703
|
}
|
|
11653
11704
|
function isObjectIteratorCall(node) {
|
|
11654
|
-
if (!
|
|
11705
|
+
if (!ts13.isCallExpression(node))
|
|
11655
11706
|
return null;
|
|
11656
|
-
if (!
|
|
11707
|
+
if (!ts13.isPropertyAccessExpression(node.expression))
|
|
11657
11708
|
return null;
|
|
11658
|
-
if (!
|
|
11709
|
+
if (!ts13.isIdentifier(node.expression.expression))
|
|
11659
11710
|
return null;
|
|
11660
11711
|
if (node.expression.expression.text !== "Object")
|
|
11661
11712
|
return null;
|
|
@@ -11680,7 +11731,7 @@ function extractSortComparator(callback, _method, ctx) {
|
|
|
11680
11731
|
` + `(reverse the operands for descending order).`
|
|
11681
11732
|
});
|
|
11682
11733
|
let resolvedNode = callback;
|
|
11683
|
-
if (
|
|
11734
|
+
if (ts13.isIdentifier(callback)) {
|
|
11684
11735
|
const resolved = resolveSortComparatorIdentifier(callback.text, ctx);
|
|
11685
11736
|
if (!resolved) {
|
|
11686
11737
|
return {
|
|
@@ -11690,7 +11741,7 @@ function extractSortComparator(callback, _method, ctx) {
|
|
|
11690
11741
|
}
|
|
11691
11742
|
resolvedNode = resolved;
|
|
11692
11743
|
}
|
|
11693
|
-
if (!
|
|
11744
|
+
if (!ts13.isArrowFunction(resolvedNode) && !ts13.isFunctionExpression(resolvedNode)) {
|
|
11694
11745
|
return {
|
|
11695
11746
|
result: null,
|
|
11696
11747
|
unsupportedReason: "Sort comparator must be an arrow function or function expression"
|
|
@@ -11717,11 +11768,11 @@ function resolveSortComparatorIdentifier(name, ctx) {
|
|
|
11717
11768
|
return null;
|
|
11718
11769
|
if (constInfo) {
|
|
11719
11770
|
const ast = parseConstInitializer(constInfo);
|
|
11720
|
-
return ast && (
|
|
11771
|
+
return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
|
|
11721
11772
|
}
|
|
11722
11773
|
if (fnInfo) {
|
|
11723
11774
|
const ast = parseFunctionInfoAsExpr(fnInfo);
|
|
11724
|
-
return ast && (
|
|
11775
|
+
return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
|
|
11725
11776
|
}
|
|
11726
11777
|
return null;
|
|
11727
11778
|
}
|
|
@@ -11732,11 +11783,11 @@ function resolveCallbackMethodFunctionReferenceIdentifier(name, analyzer) {
|
|
|
11732
11783
|
return null;
|
|
11733
11784
|
if (constInfo) {
|
|
11734
11785
|
const ast = parseConstInitializer(constInfo);
|
|
11735
|
-
return ast && (
|
|
11786
|
+
return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
|
|
11736
11787
|
}
|
|
11737
11788
|
if (fnInfo) {
|
|
11738
11789
|
const ast = parseFunctionInfoAsExpr(fnInfo);
|
|
11739
|
-
return ast && (
|
|
11790
|
+
return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
|
|
11740
11791
|
}
|
|
11741
11792
|
return null;
|
|
11742
11793
|
}
|
|
@@ -11792,13 +11843,13 @@ function resolveCallbackMethodFunctionReferences(expr, analyzer, bound = EMPTY_B
|
|
|
11792
11843
|
return visit2(expr, bound);
|
|
11793
11844
|
}
|
|
11794
11845
|
function extractFilterPredicate(callback, ctx) {
|
|
11795
|
-
if (!
|
|
11846
|
+
if (!ts13.isArrowFunction(callback))
|
|
11796
11847
|
return { result: null };
|
|
11797
11848
|
if (callback.parameters.length < 1)
|
|
11798
11849
|
return { result: null };
|
|
11799
11850
|
const firstParam = callback.parameters[0];
|
|
11800
|
-
if (!
|
|
11801
|
-
if (
|
|
11851
|
+
if (!ts13.isIdentifier(firstParam.name)) {
|
|
11852
|
+
if (ts13.isBlock(callback.body)) {
|
|
11802
11853
|
return {
|
|
11803
11854
|
result: null,
|
|
11804
11855
|
unsupportedReason: "Block body in a destructured filter param is not supported. Workaround: use an expression-body arrow, or add /* @client */."
|
|
@@ -11818,7 +11869,7 @@ function extractFilterPredicate(callback, ctx) {
|
|
|
11818
11869
|
return { result: null };
|
|
11819
11870
|
}
|
|
11820
11871
|
const param = firstParam.name.getText(ctx.sourceFile);
|
|
11821
|
-
if (
|
|
11872
|
+
if (ts13.isBlock(callback.body)) {
|
|
11822
11873
|
const raw2 = ctx.getJS(callback.body);
|
|
11823
11874
|
const statements = parseBlockBody(callback.body, ctx.sourceFile, (n) => ctx.getJS(n));
|
|
11824
11875
|
if (!statements) {
|
|
@@ -11844,7 +11895,7 @@ function extractFilterPredicate(callback, ctx) {
|
|
|
11844
11895
|
return { result: { param, predicate, raw } };
|
|
11845
11896
|
}
|
|
11846
11897
|
function extractLoopParamBindings(pattern) {
|
|
11847
|
-
if (
|
|
11898
|
+
if (ts13.isIdentifier(pattern))
|
|
11848
11899
|
return null;
|
|
11849
11900
|
const bindings = [];
|
|
11850
11901
|
let unsupported = false;
|
|
@@ -11853,7 +11904,7 @@ function extractLoopParamBindings(pattern) {
|
|
|
11853
11904
|
return false;
|
|
11854
11905
|
for (let i = 0;i < key.length; ) {
|
|
11855
11906
|
const cp = key.codePointAt(i);
|
|
11856
|
-
const ok = i === 0 ?
|
|
11907
|
+
const ok = i === 0 ? ts13.isIdentifierStart(cp, ts13.ScriptTarget.Latest) : ts13.isIdentifierPart(cp, ts13.ScriptTarget.Latest);
|
|
11857
11908
|
if (!ok)
|
|
11858
11909
|
return false;
|
|
11859
11910
|
i += cp > 65535 ? 2 : 1;
|
|
@@ -11866,17 +11917,17 @@ function extractLoopParamBindings(pattern) {
|
|
|
11866
11917
|
const walk = (p, prefix, segments) => {
|
|
11867
11918
|
if (unsupported)
|
|
11868
11919
|
return;
|
|
11869
|
-
if (
|
|
11920
|
+
if (ts13.isArrayBindingPattern(p)) {
|
|
11870
11921
|
const elements2 = p.elements;
|
|
11871
11922
|
for (let index = 0;index < elements2.length; index++) {
|
|
11872
11923
|
if (unsupported)
|
|
11873
11924
|
return;
|
|
11874
11925
|
const el = elements2[index];
|
|
11875
|
-
if (
|
|
11926
|
+
if (ts13.isOmittedExpression(el))
|
|
11876
11927
|
continue;
|
|
11877
11928
|
if (el.dotDotDotToken) {
|
|
11878
11929
|
internalInvariant(index === elements2.length - 1, "extractLoopParamBindings: array rest token in non-final position (parser should reject)");
|
|
11879
|
-
internalInvariant(
|
|
11930
|
+
internalInvariant(ts13.isIdentifier(el.name), "extractLoopParamBindings: array rest target is not an identifier (parser should reject)");
|
|
11880
11931
|
bindings.push({
|
|
11881
11932
|
name: el.name.text,
|
|
11882
11933
|
path: prefix,
|
|
@@ -11887,7 +11938,7 @@ function extractLoopParamBindings(pattern) {
|
|
|
11887
11938
|
}
|
|
11888
11939
|
const path = `${prefix}[${index}]`;
|
|
11889
11940
|
const nextSegments = [...segments, { kind: "index", index }];
|
|
11890
|
-
if (
|
|
11941
|
+
if (ts13.isIdentifier(el.name)) {
|
|
11891
11942
|
bindings.push({ name: el.name.text, path, segments: nextSegments });
|
|
11892
11943
|
} else {
|
|
11893
11944
|
walk(el.name, path, nextSegments);
|
|
@@ -11903,7 +11954,7 @@ function extractLoopParamBindings(pattern) {
|
|
|
11903
11954
|
const el = elements[i];
|
|
11904
11955
|
if (el.dotDotDotToken) {
|
|
11905
11956
|
internalInvariant(i === elements.length - 1, "extractLoopParamBindings: object rest token in non-final position (parser should reject)");
|
|
11906
|
-
internalInvariant(
|
|
11957
|
+
internalInvariant(ts13.isIdentifier(el.name), "extractLoopParamBindings: object rest target is not an identifier (parser should reject)");
|
|
11907
11958
|
bindings.push({
|
|
11908
11959
|
name: el.name.text,
|
|
11909
11960
|
path: prefix,
|
|
@@ -11915,17 +11966,17 @@ function extractLoopParamBindings(pattern) {
|
|
|
11915
11966
|
let keyText = null;
|
|
11916
11967
|
if (el.propertyName) {
|
|
11917
11968
|
const pn = el.propertyName;
|
|
11918
|
-
if (
|
|
11969
|
+
if (ts13.isIdentifier(pn))
|
|
11919
11970
|
keyText = pn.text;
|
|
11920
|
-
else if (
|
|
11971
|
+
else if (ts13.isStringLiteral(pn))
|
|
11921
11972
|
keyText = pn.text;
|
|
11922
|
-
else if (
|
|
11973
|
+
else if (ts13.isNumericLiteral(pn))
|
|
11923
11974
|
keyText = pn.text;
|
|
11924
11975
|
else {
|
|
11925
11976
|
unsupported = true;
|
|
11926
11977
|
return;
|
|
11927
11978
|
}
|
|
11928
|
-
} else if (
|
|
11979
|
+
} else if (ts13.isIdentifier(el.name)) {
|
|
11929
11980
|
keyText = el.name.text;
|
|
11930
11981
|
} else {
|
|
11931
11982
|
unsupported = true;
|
|
@@ -11935,14 +11986,14 @@ function extractLoopParamBindings(pattern) {
|
|
|
11935
11986
|
collectedKeys.push({ key: keyText, isIdent: keyIsIdent });
|
|
11936
11987
|
const path = appendDotAccess(prefix, keyText);
|
|
11937
11988
|
const nextSegments = [...segments, { kind: "field", key: keyText, isIdent: keyIsIdent }];
|
|
11938
|
-
if (
|
|
11989
|
+
if (ts13.isIdentifier(el.name)) {
|
|
11939
11990
|
bindings.push({ name: el.name.text, path, segments: nextSegments });
|
|
11940
11991
|
} else {
|
|
11941
11992
|
walk(el.name, path, nextSegments);
|
|
11942
11993
|
}
|
|
11943
11994
|
}
|
|
11944
11995
|
};
|
|
11945
|
-
if (
|
|
11996
|
+
if (ts13.isArrayBindingPattern(pattern) || ts13.isObjectBindingPattern(pattern)) {
|
|
11946
11997
|
walk(pattern, "", []);
|
|
11947
11998
|
if (unsupported)
|
|
11948
11999
|
return { unsupported: true };
|
|
@@ -11952,7 +12003,7 @@ function extractLoopParamBindings(pattern) {
|
|
|
11952
12003
|
}
|
|
11953
12004
|
function findKeyJsxAttribute(opening) {
|
|
11954
12005
|
for (const prop of opening.attributes.properties) {
|
|
11955
|
-
if (
|
|
12006
|
+
if (ts13.isJsxAttribute(prop) && prop.name.getText() === "key") {
|
|
11956
12007
|
return prop;
|
|
11957
12008
|
}
|
|
11958
12009
|
}
|
|
@@ -11997,7 +12048,7 @@ function keyAttrValueToExpr(v) {
|
|
|
11997
12048
|
function normalizeKeyExpr(expr) {
|
|
11998
12049
|
let out = "";
|
|
11999
12050
|
for (const tok of iterateJsTokens(expr)) {
|
|
12000
|
-
if (tok.kind ===
|
|
12051
|
+
if (tok.kind === ts13.SyntaxKind.WhitespaceTrivia || tok.kind === ts13.SyntaxKind.NewLineTrivia) {
|
|
12001
12052
|
continue;
|
|
12002
12053
|
}
|
|
12003
12054
|
out += expr.slice(tok.pos, tok.end);
|
|
@@ -12009,13 +12060,13 @@ function conditionalHasExplicitNullishBranch(cond) {
|
|
|
12009
12060
|
}
|
|
12010
12061
|
function branchHasExplicitNullish(branch) {
|
|
12011
12062
|
let b = branch;
|
|
12012
|
-
while (
|
|
12063
|
+
while (ts13.isParenthesizedExpression(b))
|
|
12013
12064
|
b = b.expression;
|
|
12014
|
-
if (b.kind ===
|
|
12065
|
+
if (b.kind === ts13.SyntaxKind.NullKeyword)
|
|
12015
12066
|
return true;
|
|
12016
|
-
if (
|
|
12067
|
+
if (ts13.isIdentifier(b) && b.text === "undefined")
|
|
12017
12068
|
return true;
|
|
12018
|
-
if (
|
|
12069
|
+
if (ts13.isConditionalExpression(b))
|
|
12019
12070
|
return conditionalHasExplicitNullishBranch(b);
|
|
12020
12071
|
return false;
|
|
12021
12072
|
}
|
|
@@ -12024,26 +12075,26 @@ function classifyKeyProblem(keyAttr, checker) {
|
|
|
12024
12075
|
return "missing";
|
|
12025
12076
|
if (!keyAttr.initializer)
|
|
12026
12077
|
return "missing";
|
|
12027
|
-
if (
|
|
12078
|
+
if (ts13.isJsxExpression(keyAttr.initializer) && !keyAttr.initializer.expression) {
|
|
12028
12079
|
return "missing";
|
|
12029
12080
|
}
|
|
12030
12081
|
let expr;
|
|
12031
|
-
if (
|
|
12082
|
+
if (ts13.isStringLiteral(keyAttr.initializer)) {
|
|
12032
12083
|
return null;
|
|
12033
|
-
} else if (
|
|
12084
|
+
} else if (ts13.isJsxExpression(keyAttr.initializer)) {
|
|
12034
12085
|
expr = keyAttr.initializer.expression;
|
|
12035
12086
|
}
|
|
12036
12087
|
if (!expr)
|
|
12037
12088
|
return null;
|
|
12038
|
-
if (expr.kind ===
|
|
12089
|
+
if (expr.kind === ts13.SyntaxKind.NullKeyword)
|
|
12039
12090
|
return null;
|
|
12040
|
-
if (
|
|
12091
|
+
if (ts13.isIdentifier(expr) && expr.text === "undefined")
|
|
12041
12092
|
return null;
|
|
12042
|
-
if (
|
|
12093
|
+
if (ts13.isConditionalExpression(expr) && conditionalHasExplicitNullishBranch(expr))
|
|
12043
12094
|
return null;
|
|
12044
12095
|
if (checker) {
|
|
12045
12096
|
const type = checker.getTypeAtLocation(expr);
|
|
12046
|
-
const isNullable = type.isUnion() ? type.types.some((t) => (t.flags & (
|
|
12097
|
+
const isNullable = type.isUnion() ? type.types.some((t) => (t.flags & (ts13.TypeFlags.Null | ts13.TypeFlags.Undefined | ts13.TypeFlags.Void)) !== 0) : (type.flags & (ts13.TypeFlags.Null | ts13.TypeFlags.Undefined | ts13.TypeFlags.Void)) !== 0;
|
|
12047
12098
|
if (isNullable)
|
|
12048
12099
|
return "nullable-type";
|
|
12049
12100
|
}
|
|
@@ -12069,81 +12120,81 @@ function checkLoopKey(callback, ctx, isNested) {
|
|
|
12069
12120
|
ctx.analyzer.errors.push(createError(errorCode, getSourceLocation(locNode, ctx.sourceFile, ctx.filePath), { suggestion: { message: keyErrorSuggestion(problem) } }));
|
|
12070
12121
|
}
|
|
12071
12122
|
let body = callback.body;
|
|
12072
|
-
if (
|
|
12073
|
-
const ret = body.statements.find((s) =>
|
|
12123
|
+
if (ts13.isBlock(body)) {
|
|
12124
|
+
const ret = body.statements.find((s) => ts13.isReturnStatement(s) && s.expression != null);
|
|
12074
12125
|
if (!ret?.expression)
|
|
12075
12126
|
return;
|
|
12076
12127
|
body = ret.expression;
|
|
12077
12128
|
}
|
|
12078
|
-
while (
|
|
12129
|
+
while (ts13.isParenthesizedExpression(body))
|
|
12079
12130
|
body = body.expression;
|
|
12080
12131
|
function checkJsxOperand(node) {
|
|
12081
12132
|
let n = node;
|
|
12082
|
-
while (
|
|
12133
|
+
while (ts13.isParenthesizedExpression(n))
|
|
12083
12134
|
n = n.expression;
|
|
12084
|
-
if (
|
|
12135
|
+
if (ts13.isJsxElement(n))
|
|
12085
12136
|
checkOpening(n.openingElement);
|
|
12086
|
-
else if (
|
|
12137
|
+
else if (ts13.isJsxSelfClosingElement(n))
|
|
12087
12138
|
checkOpening(n);
|
|
12088
12139
|
}
|
|
12089
|
-
if (
|
|
12140
|
+
if (ts13.isConditionalExpression(body)) {
|
|
12090
12141
|
checkJsxOperand(body.whenTrue);
|
|
12091
12142
|
checkJsxOperand(body.whenFalse);
|
|
12092
12143
|
return;
|
|
12093
12144
|
}
|
|
12094
|
-
if (
|
|
12145
|
+
if (ts13.isBinaryExpression(body) && (body.operatorToken.kind === ts13.SyntaxKind.AmpersandAmpersandToken || body.operatorToken.kind === ts13.SyntaxKind.BarBarToken || body.operatorToken.kind === ts13.SyntaxKind.QuestionQuestionToken)) {
|
|
12095
12146
|
checkJsxOperand(body.left);
|
|
12096
12147
|
checkJsxOperand(body.right);
|
|
12097
12148
|
return;
|
|
12098
12149
|
}
|
|
12099
|
-
if (
|
|
12150
|
+
if (ts13.isJsxElement(body)) {
|
|
12100
12151
|
checkOpening(body.openingElement);
|
|
12101
12152
|
return;
|
|
12102
12153
|
}
|
|
12103
|
-
if (
|
|
12154
|
+
if (ts13.isJsxSelfClosingElement(body)) {
|
|
12104
12155
|
checkOpening(body);
|
|
12105
12156
|
return;
|
|
12106
12157
|
}
|
|
12107
12158
|
}
|
|
12108
12159
|
function flatMapProjectionCall(body) {
|
|
12109
12160
|
let expr;
|
|
12110
|
-
if (
|
|
12161
|
+
if (ts13.isBlock(body)) {
|
|
12111
12162
|
const real = body.statements;
|
|
12112
|
-
if (real.length !== 1 || !
|
|
12163
|
+
if (real.length !== 1 || !ts13.isReturnStatement(real[0]) || !real[0].expression)
|
|
12113
12164
|
return null;
|
|
12114
12165
|
expr = real[0].expression;
|
|
12115
12166
|
} else {
|
|
12116
12167
|
expr = body;
|
|
12117
12168
|
}
|
|
12118
|
-
while (
|
|
12169
|
+
while (ts13.isParenthesizedExpression(expr))
|
|
12119
12170
|
expr = expr.expression;
|
|
12120
|
-
if (!
|
|
12171
|
+
if (!ts13.isCallExpression(expr))
|
|
12121
12172
|
return null;
|
|
12122
12173
|
if (!getMapLikeMethod(expr))
|
|
12123
12174
|
return null;
|
|
12124
12175
|
const cb = expr.arguments[0];
|
|
12125
|
-
if (!cb || !
|
|
12176
|
+
if (!cb || !ts13.isArrowFunction(cb) && !ts13.isFunctionExpression(cb))
|
|
12126
12177
|
return null;
|
|
12127
12178
|
for (const p of cb.parameters) {
|
|
12128
|
-
if (!
|
|
12179
|
+
if (!ts13.isIdentifier(p.name))
|
|
12129
12180
|
return null;
|
|
12130
12181
|
}
|
|
12131
12182
|
let innerBody = cb.body;
|
|
12132
|
-
if (
|
|
12133
|
-
const ret = innerBody.statements.find((s) =>
|
|
12183
|
+
if (ts13.isBlock(innerBody)) {
|
|
12184
|
+
const ret = innerBody.statements.find((s) => ts13.isReturnStatement(s) && s.expression != null);
|
|
12134
12185
|
if (innerBody.statements.length !== 1 || !ret?.expression)
|
|
12135
12186
|
return null;
|
|
12136
12187
|
innerBody = ret.expression;
|
|
12137
12188
|
}
|
|
12138
|
-
while (
|
|
12189
|
+
while (ts13.isParenthesizedExpression(innerBody))
|
|
12139
12190
|
innerBody = innerBody.expression;
|
|
12140
12191
|
const isElementish = (n) => {
|
|
12141
12192
|
let m = n;
|
|
12142
|
-
while (
|
|
12193
|
+
while (ts13.isParenthesizedExpression(m))
|
|
12143
12194
|
m = m.expression;
|
|
12144
|
-
if (
|
|
12195
|
+
if (ts13.isJsxElement(m) || ts13.isJsxSelfClosingElement(m))
|
|
12145
12196
|
return leafIsWirelessElement(m);
|
|
12146
|
-
if (
|
|
12197
|
+
if (ts13.isConditionalExpression(m))
|
|
12147
12198
|
return isElementish(m.whenTrue) && isElementish(m.whenFalse);
|
|
12148
12199
|
return false;
|
|
12149
12200
|
};
|
|
@@ -12156,19 +12207,19 @@ function leafIsWirelessElement(el) {
|
|
|
12156
12207
|
const visit2 = (n) => {
|
|
12157
12208
|
if (!ok)
|
|
12158
12209
|
return;
|
|
12159
|
-
if (
|
|
12210
|
+
if (ts13.isJsxOpeningElement(n) || ts13.isJsxSelfClosingElement(n)) {
|
|
12160
12211
|
const tagNode = n.tagName;
|
|
12161
|
-
const isIntrinsic =
|
|
12212
|
+
const isIntrinsic = ts13.isIdentifier(tagNode) ? !/^[A-Z]/.test(tagNode.text) : ts13.isJsxNamespacedName(tagNode);
|
|
12162
12213
|
if (!isIntrinsic) {
|
|
12163
12214
|
ok = false;
|
|
12164
12215
|
return;
|
|
12165
12216
|
}
|
|
12166
12217
|
for (const attr of n.attributes.properties) {
|
|
12167
|
-
if (
|
|
12218
|
+
if (ts13.isJsxSpreadAttribute(attr)) {
|
|
12168
12219
|
ok = false;
|
|
12169
12220
|
return;
|
|
12170
12221
|
}
|
|
12171
|
-
if (
|
|
12222
|
+
if (ts13.isJsxAttribute(attr)) {
|
|
12172
12223
|
const name = attr.name.getText();
|
|
12173
12224
|
if (/^on[A-Z]/.test(name)) {
|
|
12174
12225
|
ok = false;
|
|
@@ -12177,11 +12228,11 @@ function leafIsWirelessElement(el) {
|
|
|
12177
12228
|
}
|
|
12178
12229
|
}
|
|
12179
12230
|
}
|
|
12180
|
-
if (
|
|
12231
|
+
if (ts13.isCallExpression(n) && getMapLikeMethod(n) && containsJsxInExpression(n)) {
|
|
12181
12232
|
ok = false;
|
|
12182
12233
|
return;
|
|
12183
12234
|
}
|
|
12184
|
-
|
|
12235
|
+
ts13.forEachChild(n, visit2);
|
|
12185
12236
|
};
|
|
12186
12237
|
visit2(el);
|
|
12187
12238
|
return ok;
|
|
@@ -12361,7 +12412,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12361
12412
|
let children = [];
|
|
12362
12413
|
let paramBindings;
|
|
12363
12414
|
let flatMapCallback;
|
|
12364
|
-
if (
|
|
12415
|
+
if (ts13.isArrowFunction(callback)) {
|
|
12365
12416
|
if (callback.parameters.length > 0) {
|
|
12366
12417
|
const firstParam = callback.parameters[0];
|
|
12367
12418
|
param = firstParam.name.getText(ctx.sourceFile);
|
|
@@ -12369,9 +12420,9 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12369
12420
|
paramType = firstParam.type.getText(ctx.sourceFile);
|
|
12370
12421
|
}
|
|
12371
12422
|
const isEntriesShape = iterationShape === "entries" || objectIteration === "entries";
|
|
12372
|
-
if (isEntriesShape &&
|
|
12373
|
-
const elements = firstParam.name.elements.filter((el) => !
|
|
12374
|
-
if (elements.length === 2 &&
|
|
12423
|
+
if (isEntriesShape && ts13.isArrayBindingPattern(firstParam.name)) {
|
|
12424
|
+
const elements = firstParam.name.elements.filter((el) => !ts13.isOmittedExpression(el));
|
|
12425
|
+
if (elements.length === 2 && ts13.isBindingElement(elements[0]) && ts13.isIdentifier(elements[0].name) && ts13.isBindingElement(elements[1]) && ts13.isIdentifier(elements[1].name)) {
|
|
12375
12426
|
index = elements[0].name.text;
|
|
12376
12427
|
param = elements[1].name.text;
|
|
12377
12428
|
} else {
|
|
@@ -12402,10 +12453,10 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12402
12453
|
ctx.scope = ctx.scope.enterLoopRow({ param, index, paramBindings });
|
|
12403
12454
|
ctx.loopDepth++;
|
|
12404
12455
|
const tryTransformRenderableBody = (expr) => {
|
|
12405
|
-
if (!
|
|
12456
|
+
if (!ts13.isBinaryExpression(expr))
|
|
12406
12457
|
return;
|
|
12407
12458
|
const op = expr.operatorToken.kind;
|
|
12408
|
-
if (op !==
|
|
12459
|
+
if (op !== ts13.SyntaxKind.AmpersandAmpersandToken && op !== ts13.SyntaxKind.BarBarToken && op !== ts13.SyntaxKind.QuestionQuestionToken) {
|
|
12409
12460
|
return;
|
|
12410
12461
|
}
|
|
12411
12462
|
if (!containsJsxInExpression(expr) && !callsJsxHelper(expr, ctx))
|
|
@@ -12415,33 +12466,33 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12415
12466
|
children = [transformed];
|
|
12416
12467
|
};
|
|
12417
12468
|
const body = callback.body;
|
|
12418
|
-
if (
|
|
12469
|
+
if (ts13.isJsxElement(body) || ts13.isJsxSelfClosingElement(body) || ts13.isJsxFragment(body)) {
|
|
12419
12470
|
const transformed = transformNode(body, ctx);
|
|
12420
12471
|
if (transformed) {
|
|
12421
12472
|
children = [transformed];
|
|
12422
12473
|
}
|
|
12423
|
-
} else if (
|
|
12474
|
+
} else if (ts13.isConditionalExpression(body)) {
|
|
12424
12475
|
children = [transformConditional(body, ctx)];
|
|
12425
|
-
} else if (
|
|
12476
|
+
} else if (ts13.isParenthesizedExpression(body)) {
|
|
12426
12477
|
let inner = body.expression;
|
|
12427
|
-
while (
|
|
12478
|
+
while (ts13.isParenthesizedExpression(inner)) {
|
|
12428
12479
|
inner = inner.expression;
|
|
12429
12480
|
}
|
|
12430
|
-
if (
|
|
12481
|
+
if (ts13.isJsxElement(inner) || ts13.isJsxSelfClosingElement(inner) || ts13.isJsxFragment(inner)) {
|
|
12431
12482
|
const transformed = transformNode(inner, ctx);
|
|
12432
12483
|
if (transformed) {
|
|
12433
12484
|
children = [transformed];
|
|
12434
12485
|
}
|
|
12435
|
-
} else if (
|
|
12486
|
+
} else if (ts13.isConditionalExpression(inner)) {
|
|
12436
12487
|
children = [transformConditional(inner, ctx)];
|
|
12437
|
-
} else if (method === "flatMap" &&
|
|
12488
|
+
} else if (method === "flatMap" && ts13.isArrayLiteralExpression(inner)) {
|
|
12438
12489
|
children = transformArrayLiteralChildren(inner, ctx);
|
|
12439
12490
|
} else {
|
|
12440
12491
|
tryTransformRenderableBody(inner);
|
|
12441
12492
|
}
|
|
12442
|
-
} else if (method === "flatMap" &&
|
|
12493
|
+
} else if (method === "flatMap" && ts13.isArrayLiteralExpression(body)) {
|
|
12443
12494
|
children = transformArrayLiteralChildren(body, ctx);
|
|
12444
|
-
} else if (
|
|
12495
|
+
} else if (ts13.isBlock(body)) {
|
|
12445
12496
|
const multiReturn = method !== "flatMap" ? extractMultiReturnJsxBranches(body, true) : null;
|
|
12446
12497
|
if (multiReturn && multiReturn.branches.length > 0) {
|
|
12447
12498
|
const loc = getSourceLocation(body, ctx.sourceFile, ctx.filePath);
|
|
@@ -12459,7 +12510,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12459
12510
|
}
|
|
12460
12511
|
}
|
|
12461
12512
|
}
|
|
12462
|
-
const returnStmt = children.length === 0 ? body.statements.find((s) =>
|
|
12513
|
+
const returnStmt = children.length === 0 ? body.statements.find((s) => ts13.isReturnStatement(s) && s.expression != null) : undefined;
|
|
12463
12514
|
let rowScopeBeforePreamble = null;
|
|
12464
12515
|
if (returnStmt) {
|
|
12465
12516
|
const preambleNames = new Set;
|
|
@@ -12480,10 +12531,10 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12480
12531
|
}
|
|
12481
12532
|
if (returnStmt && returnStmt.expression) {
|
|
12482
12533
|
let returnExpr = returnStmt.expression;
|
|
12483
|
-
while (
|
|
12534
|
+
while (ts13.isParenthesizedExpression(returnExpr)) {
|
|
12484
12535
|
returnExpr = returnExpr.expression;
|
|
12485
12536
|
}
|
|
12486
|
-
if (
|
|
12537
|
+
if (ts13.isJsxElement(returnExpr) || ts13.isJsxSelfClosingElement(returnExpr) || ts13.isJsxFragment(returnExpr)) {
|
|
12487
12538
|
const transformed = transformNode(returnExpr, ctx);
|
|
12488
12539
|
if (transformed) {
|
|
12489
12540
|
children = [transformed];
|
|
@@ -12565,7 +12616,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12565
12616
|
}
|
|
12566
12617
|
}
|
|
12567
12618
|
}
|
|
12568
|
-
if (method === "flatMap" && children.length === 0 && !flatMapCallback && !
|
|
12619
|
+
if (method === "flatMap" && children.length === 0 && !flatMapCallback && !ts13.isBlock(body)) {
|
|
12569
12620
|
flatMapCallback = buildFlatMapCallback(callback, body, ctx);
|
|
12570
12621
|
}
|
|
12571
12622
|
if (flatMapCallback)
|
|
@@ -12583,7 +12634,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12583
12634
|
}
|
|
12584
12635
|
if (children.length === 0 && !flatMapCallback) {
|
|
12585
12636
|
const cb = node.arguments[0];
|
|
12586
|
-
const cbBody = cb && (
|
|
12637
|
+
const cbBody = cb && (ts13.isArrowFunction(cb) || ts13.isFunctionExpression(cb)) ? cb.body : undefined;
|
|
12587
12638
|
if (cbBody && containsJsxInExpression(cbBody) && ctx.analyzer.errors.length === diagCountAtEntry) {
|
|
12588
12639
|
ctx.analyzer.errors.push(createError(ErrorCodes.UNSUPPORTED_JSX_PATTERN, getSourceLocation(cbBody, ctx.sourceFile, ctx.filePath), {
|
|
12589
12640
|
message: `A .${method}() callback that builds JSX in this shape cannot be ` + "compiled — the JSX would leak verbatim into the client bundle. " + "Recognized bodies: a JSX element/fragment, a ternary or " + "&& / || / ?? expression, an array literal (flatMap), or a block " + "body whose return the compiler can lower.",
|
|
@@ -12594,7 +12645,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12594
12645
|
}
|
|
12595
12646
|
return null;
|
|
12596
12647
|
}
|
|
12597
|
-
if (
|
|
12648
|
+
if (ts13.isArrowFunction(node.arguments[0]) && children.length > 0) {
|
|
12598
12649
|
checkLoopKey(node.arguments[0], ctx, isNested);
|
|
12599
12650
|
}
|
|
12600
12651
|
const itemConditional = children.length > 0 ? loopBodyItemConditional(children) : null;
|
|
@@ -12648,6 +12699,9 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12648
12699
|
const preambleRegions = preamble && !isStaticArray ? collectPreambleRegions(children, new Set(preamble.declaredNames), ctx) : undefined;
|
|
12649
12700
|
if (preamble && !isStaticArray) {
|
|
12650
12701
|
markPreambleAttrSlots(children, new Set(preamble.declaredNames), ctx);
|
|
12702
|
+
if (preamble.reactiveNames && preamble.reactiveNames.length > 0) {
|
|
12703
|
+
markPreambleConditionalReactivity(children, new Set(preamble.reactiveNames), ctx);
|
|
12704
|
+
}
|
|
12651
12705
|
}
|
|
12652
12706
|
const nestedComponents = collectNestedComponents(children).filter((c) => c.name !== childComponent?.name);
|
|
12653
12707
|
return {
|
|
@@ -12691,12 +12745,12 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12691
12745
|
function transformArrayLiteralChildren(arrayLiteral, ctx) {
|
|
12692
12746
|
const children = [];
|
|
12693
12747
|
for (const element of arrayLiteral.elements) {
|
|
12694
|
-
if (
|
|
12748
|
+
if (ts13.isSpreadElement(element))
|
|
12695
12749
|
continue;
|
|
12696
12750
|
let inner = element;
|
|
12697
|
-
while (
|
|
12751
|
+
while (ts13.isParenthesizedExpression(inner))
|
|
12698
12752
|
inner = inner.expression;
|
|
12699
|
-
if (
|
|
12753
|
+
if (ts13.isJsxElement(inner) || ts13.isJsxSelfClosingElement(inner) || ts13.isJsxFragment(inner)) {
|
|
12700
12754
|
const transformed = transformNode(inner, ctx);
|
|
12701
12755
|
if (transformed)
|
|
12702
12756
|
children.push(transformed);
|
|
@@ -12705,7 +12759,7 @@ function transformArrayLiteralChildren(arrayLiteral, ctx) {
|
|
|
12705
12759
|
return children;
|
|
12706
12760
|
}
|
|
12707
12761
|
function containsJsx(node) {
|
|
12708
|
-
if (
|
|
12762
|
+
if (ts13.isJsxElement(node) || ts13.isJsxSelfClosingElement(node) || ts13.isJsxFragment(node))
|
|
12709
12763
|
return true;
|
|
12710
12764
|
let found = false;
|
|
12711
12765
|
node.forEachChild((child) => {
|
|
@@ -12721,7 +12775,7 @@ function buildFlatMapCallback(callback, body, ctx) {
|
|
|
12721
12775
|
const leafIrs = [];
|
|
12722
12776
|
let refusalNode;
|
|
12723
12777
|
const collectJsx = (n, underTemplate) => {
|
|
12724
|
-
if (
|
|
12778
|
+
if (ts13.isJsxElement(n) || ts13.isJsxSelfClosingElement(n) || ts13.isJsxFragment(n)) {
|
|
12725
12779
|
if (underTemplate)
|
|
12726
12780
|
refusalNode ??= n;
|
|
12727
12781
|
leafSpans.push({ start: n.getStart(ctx.sourceFile), end: n.getEnd() });
|
|
@@ -12729,7 +12783,7 @@ function buildFlatMapCallback(callback, body, ctx) {
|
|
|
12729
12783
|
leafIrs.push(ir ?? { type: "text", value: "", loc: getSourceLocation(n, ctx.sourceFile, ctx.filePath) });
|
|
12730
12784
|
return;
|
|
12731
12785
|
}
|
|
12732
|
-
const inTemplate = underTemplate ||
|
|
12786
|
+
const inTemplate = underTemplate || ts13.isTemplateExpression(n) || ts13.isTaggedTemplateExpression(n);
|
|
12733
12787
|
n.forEachChild((c) => collectJsx(c, inTemplate));
|
|
12734
12788
|
};
|
|
12735
12789
|
collectJsx(body, false);
|
|
@@ -12905,6 +12959,33 @@ function markPreambleAttrSlots(nodes, declared, ctx) {
|
|
|
12905
12959
|
};
|
|
12906
12960
|
visit2(nodes);
|
|
12907
12961
|
}
|
|
12962
|
+
function markPreambleConditionalReactivity(nodes, reactiveNames, ctx) {
|
|
12963
|
+
if (reactiveNames.size === 0)
|
|
12964
|
+
return;
|
|
12965
|
+
const visit2 = (list) => {
|
|
12966
|
+
for (const node of list) {
|
|
12967
|
+
switch (node.type) {
|
|
12968
|
+
case "element":
|
|
12969
|
+
case "fragment":
|
|
12970
|
+
visit2(node.children);
|
|
12971
|
+
break;
|
|
12972
|
+
case "conditional": {
|
|
12973
|
+
if (!node.reactive) {
|
|
12974
|
+
const refs = extractFreeIdentifiersFromText(node.condition);
|
|
12975
|
+
if ([...refs].some((r) => reactiveNames.has(r))) {
|
|
12976
|
+
node.reactive = true;
|
|
12977
|
+
if (!node.slotId)
|
|
12978
|
+
node.slotId = generateSlotId(ctx);
|
|
12979
|
+
}
|
|
12980
|
+
}
|
|
12981
|
+
visit2([node.whenTrue, ...node.whenFalse ? [node.whenFalse] : []]);
|
|
12982
|
+
break;
|
|
12983
|
+
}
|
|
12984
|
+
}
|
|
12985
|
+
}
|
|
12986
|
+
};
|
|
12987
|
+
visit2(nodes);
|
|
12988
|
+
}
|
|
12908
12989
|
function attrValueText(value) {
|
|
12909
12990
|
if (value.kind === "expression")
|
|
12910
12991
|
return value.expr;
|
|
@@ -12920,24 +13001,46 @@ function attrValueText(value) {
|
|
|
12920
13001
|
return out.join(" ");
|
|
12921
13002
|
}
|
|
12922
13003
|
function collectBindingNames2(name, out) {
|
|
12923
|
-
if (
|
|
13004
|
+
if (ts13.isIdentifier(name)) {
|
|
12924
13005
|
out.add(name.text);
|
|
12925
13006
|
return;
|
|
12926
13007
|
}
|
|
12927
13008
|
for (const el of name.elements) {
|
|
12928
|
-
if (
|
|
13009
|
+
if (ts13.isBindingElement(el))
|
|
12929
13010
|
collectBindingNames2(el.name, out);
|
|
12930
13011
|
}
|
|
12931
13012
|
}
|
|
12932
13013
|
function collectPreambleDeclaredNames(stmt, out) {
|
|
12933
|
-
if (
|
|
13014
|
+
if (ts13.isVariableStatement(stmt)) {
|
|
12934
13015
|
for (const decl of stmt.declarationList.declarations) {
|
|
12935
13016
|
collectBindingNames2(decl.name, out);
|
|
12936
13017
|
}
|
|
12937
|
-
} else if (
|
|
13018
|
+
} else if (ts13.isFunctionDeclaration(stmt) && stmt.name) {
|
|
12938
13019
|
out.add(stmt.name.text);
|
|
12939
13020
|
}
|
|
12940
13021
|
}
|
|
13022
|
+
function computePreambleReactiveNames(statements, ctx) {
|
|
13023
|
+
const reactiveNames = new Set;
|
|
13024
|
+
for (const stmt of statements) {
|
|
13025
|
+
if (!ts13.isVariableStatement(stmt))
|
|
13026
|
+
continue;
|
|
13027
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
13028
|
+
if (!decl.initializer)
|
|
13029
|
+
continue;
|
|
13030
|
+
const boundNames = new Set;
|
|
13031
|
+
collectBindingNames2(decl.name, boundNames);
|
|
13032
|
+
const initText = ctx.getJS(decl.initializer);
|
|
13033
|
+
const initFreeRefs = extractFreeIdentifiersFromNode(decl.initializer);
|
|
13034
|
+
const readsEarlierReactive = [...initFreeRefs].some((r) => reactiveNames.has(r));
|
|
13035
|
+
const isReactive = readsEarlierReactive || isReactiveExpression(initText, ctx, decl.initializer);
|
|
13036
|
+
if (isReactive) {
|
|
13037
|
+
for (const n of boundNames)
|
|
13038
|
+
reactiveNames.add(n);
|
|
13039
|
+
}
|
|
13040
|
+
}
|
|
13041
|
+
}
|
|
13042
|
+
return reactiveNames;
|
|
13043
|
+
}
|
|
12941
13044
|
function preambleFromValueStatements(statements, ctx) {
|
|
12942
13045
|
const segments = [];
|
|
12943
13046
|
const typedParts = [];
|
|
@@ -12952,21 +13055,23 @@ function preambleFromValueStatements(statements, ctx) {
|
|
|
12952
13055
|
typedParts.push(raw0.endsWith(";") ? raw0 : raw0 + ";");
|
|
12953
13056
|
segments.push(tjs !== js ? { kind: "js", text: js, templateText: tjs } : { kind: "js", text: js });
|
|
12954
13057
|
}
|
|
13058
|
+
const reactiveNames = computePreambleReactiveNames(statements, ctx);
|
|
12955
13059
|
return {
|
|
12956
13060
|
segments: trimPreambleSegments(segments),
|
|
12957
13061
|
ssrText: tsxSourceText(typedParts.join(" ")),
|
|
12958
13062
|
declaredNames: [...declared],
|
|
12959
13063
|
builderNames: [],
|
|
12960
|
-
declarations: neutralPreambleDeclarations(statements, ctx) ?? undefined
|
|
13064
|
+
declarations: neutralPreambleDeclarations(statements, ctx) ?? undefined,
|
|
13065
|
+
reactiveNames: reactiveNames.size > 0 ? [...reactiveNames] : undefined
|
|
12961
13066
|
};
|
|
12962
13067
|
}
|
|
12963
13068
|
function neutralPreambleDeclarations(statements, ctx) {
|
|
12964
13069
|
const out = [];
|
|
12965
13070
|
for (const stmt of statements) {
|
|
12966
|
-
if (!
|
|
13071
|
+
if (!ts13.isVariableStatement(stmt))
|
|
12967
13072
|
return null;
|
|
12968
13073
|
for (const decl of stmt.declarationList.declarations) {
|
|
12969
|
-
if (!
|
|
13074
|
+
if (!ts13.isIdentifier(decl.name))
|
|
12970
13075
|
return null;
|
|
12971
13076
|
if (!decl.initializer)
|
|
12972
13077
|
return null;
|
|
@@ -12999,11 +13104,11 @@ function buildPreambleSegments(statements, returnStmt, ctx) {
|
|
|
12999
13104
|
let refusalNode;
|
|
13000
13105
|
const recordBuilderTarget = (leaf, stmt) => {
|
|
13001
13106
|
for (let n = leaf.parent;n && n !== stmt.parent; n = n.parent) {
|
|
13002
|
-
if (
|
|
13107
|
+
if (ts13.isCallExpression(n) && ts13.isPropertyAccessExpression(n.expression) && (n.expression.name.text === "push" || n.expression.name.text === "unshift") && ts13.isIdentifier(n.expression.expression)) {
|
|
13003
13108
|
builders.add(n.expression.expression.text);
|
|
13004
13109
|
return;
|
|
13005
13110
|
}
|
|
13006
|
-
if (
|
|
13111
|
+
if (ts13.isVariableDeclaration(n) && ts13.isIdentifier(n.name)) {
|
|
13007
13112
|
builders.add(n.name.text);
|
|
13008
13113
|
return;
|
|
13009
13114
|
}
|
|
@@ -13016,7 +13121,7 @@ function buildPreambleSegments(statements, returnStmt, ctx) {
|
|
|
13016
13121
|
const leafSpans = [];
|
|
13017
13122
|
const leafIrs = [];
|
|
13018
13123
|
const collect = (n, underTemplate) => {
|
|
13019
|
-
if (
|
|
13124
|
+
if (ts13.isJsxElement(n) || ts13.isJsxSelfClosingElement(n) || ts13.isJsxFragment(n)) {
|
|
13020
13125
|
if (underTemplate)
|
|
13021
13126
|
refusalNode ??= n;
|
|
13022
13127
|
recordBuilderTarget(n, stmt);
|
|
@@ -13027,7 +13132,7 @@ function buildPreambleSegments(statements, returnStmt, ctx) {
|
|
|
13027
13132
|
leafIrs.push(ir ?? { type: "text", value: "", loc: getSourceLocation(n, ctx.sourceFile, ctx.filePath) });
|
|
13028
13133
|
return;
|
|
13029
13134
|
}
|
|
13030
|
-
const inTemplate = underTemplate ||
|
|
13135
|
+
const inTemplate = underTemplate || ts13.isTemplateExpression(n) || ts13.isTaggedTemplateExpression(n);
|
|
13031
13136
|
n.forEachChild((c) => collect(c, inTemplate));
|
|
13032
13137
|
};
|
|
13033
13138
|
collect(stmt, false);
|
|
@@ -13131,13 +13236,13 @@ function expandSpreadAttribute(attr, ctx) {
|
|
|
13131
13236
|
}];
|
|
13132
13237
|
}
|
|
13133
13238
|
function attrFreeIdentifiers(attr) {
|
|
13134
|
-
if (!attr.initializer || !
|
|
13239
|
+
if (!attr.initializer || !ts13.isJsxExpression(attr.initializer) || !attr.initializer.expression) {
|
|
13135
13240
|
return;
|
|
13136
13241
|
}
|
|
13137
13242
|
return extractFreeIdentifiersFromNode(attr.initializer.expression);
|
|
13138
13243
|
}
|
|
13139
13244
|
function computeReactivityFlags(attr, ctx) {
|
|
13140
|
-
if (!attr.initializer || !
|
|
13245
|
+
if (!attr.initializer || !ts13.isJsxExpression(attr.initializer) || !attr.initializer.expression) {
|
|
13141
13246
|
return {};
|
|
13142
13247
|
}
|
|
13143
13248
|
const expr = attr.initializer.expression;
|
|
@@ -13163,22 +13268,22 @@ function processAttributes(attributes, ctx) {
|
|
|
13163
13268
|
const events = [];
|
|
13164
13269
|
let ref = null;
|
|
13165
13270
|
for (const attr of attributes.properties) {
|
|
13166
|
-
if (
|
|
13271
|
+
if (ts13.isJsxSpreadAttribute(attr)) {
|
|
13167
13272
|
attrs.push(...expandSpreadAttribute(attr, ctx));
|
|
13168
13273
|
continue;
|
|
13169
13274
|
}
|
|
13170
|
-
if (!
|
|
13275
|
+
if (!ts13.isJsxAttribute(attr))
|
|
13171
13276
|
continue;
|
|
13172
13277
|
const rawName = attr.name.getText(ctx.sourceFile);
|
|
13173
13278
|
if (rawName === "ref") {
|
|
13174
|
-
if (attr.initializer &&
|
|
13279
|
+
if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
13175
13280
|
reportJsxBranchLocalInCallback(attr.initializer.expression, ctx);
|
|
13176
13281
|
ref = ctx.getJS(attr.initializer.expression);
|
|
13177
13282
|
}
|
|
13178
13283
|
continue;
|
|
13179
13284
|
}
|
|
13180
13285
|
if (/^on[A-Z]/.test(rawName)) {
|
|
13181
|
-
if (attr.initializer &&
|
|
13286
|
+
if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
13182
13287
|
const eventName = rawName.slice(2).toLowerCase();
|
|
13183
13288
|
reportJsxBranchLocalInCallback(attr.initializer.expression, ctx);
|
|
13184
13289
|
events.push({
|
|
@@ -13193,7 +13298,7 @@ function processAttributes(attributes, ctx) {
|
|
|
13193
13298
|
const name = toHTMLAttrName(rawName);
|
|
13194
13299
|
let value = getAttributeValue(attr, ctx);
|
|
13195
13300
|
let clientOnly;
|
|
13196
|
-
if (attr.initializer &&
|
|
13301
|
+
if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
13197
13302
|
if (value.kind === "expression" && value.templateExpr === undefined) {
|
|
13198
13303
|
const rewritten = rewriteBarePropRefs2(value.expr, attr.initializer.expression, ctx);
|
|
13199
13304
|
if (rewritten !== value.expr) {
|
|
@@ -13220,55 +13325,55 @@ function getAttributeValue(attr, ctx) {
|
|
|
13220
13325
|
if (!attr.initializer) {
|
|
13221
13326
|
return AttrValueOf.booleanAttr();
|
|
13222
13327
|
}
|
|
13223
|
-
if (
|
|
13328
|
+
if (ts13.isStringLiteral(attr.initializer)) {
|
|
13224
13329
|
return AttrValueOf.literal(decodeEntities(attr.initializer.text));
|
|
13225
13330
|
}
|
|
13226
|
-
if (
|
|
13331
|
+
if (ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
13227
13332
|
let expr = attr.initializer.expression;
|
|
13228
|
-
if (
|
|
13333
|
+
if (ts13.isIdentifier(expr)) {
|
|
13229
13334
|
const branchInit = ctx._branchScopeVars?.get(expr.text);
|
|
13230
13335
|
if (branchInit && !initializerShapeContainsJsx(branchInit)) {
|
|
13231
13336
|
expr = branchInit;
|
|
13232
13337
|
}
|
|
13233
13338
|
}
|
|
13234
13339
|
expr = tryDesugarInterleaveTaggedTemplate(expr, ctx);
|
|
13235
|
-
if (
|
|
13340
|
+
if (ts13.isAwaitExpression(expr)) {
|
|
13236
13341
|
ctx.analyzer.errors.push(createError(ErrorCodes.STAGE_AWAIT_IN_TEMPLATE, getSourceLocation(expr, ctx.sourceFile, ctx.filePath)));
|
|
13237
13342
|
return AttrValueOf.expression("undefined");
|
|
13238
13343
|
}
|
|
13239
13344
|
checkBareSignalOrMemoIdentifier(expr, ctx);
|
|
13240
|
-
if (attr.name.getText(ctx.sourceFile) === "style" &&
|
|
13345
|
+
if (attr.name.getText(ctx.sourceFile) === "style" && ts13.isObjectLiteralExpression(expr)) {
|
|
13241
13346
|
const cssString = tryStaticStyleObjectToCss(expr);
|
|
13242
13347
|
if (cssString !== null) {
|
|
13243
13348
|
return AttrValueOf.literal(cssString);
|
|
13244
13349
|
}
|
|
13245
13350
|
}
|
|
13246
|
-
if (
|
|
13351
|
+
if (ts13.isTemplateExpression(expr)) {
|
|
13247
13352
|
const parts = parseTemplateLiteral(expr, ctx);
|
|
13248
13353
|
if (parts.some((p) => p.type === "ternary" || p.type === "lookup")) {
|
|
13249
13354
|
return AttrValueOf.template(parts);
|
|
13250
13355
|
}
|
|
13251
13356
|
}
|
|
13252
|
-
if (
|
|
13357
|
+
if (ts13.isElementAccessExpression(expr) && !ts13.isStringLiteralLike(expr.argumentExpression) && !ts13.isNumericLiteral(expr.argumentExpression)) {
|
|
13253
13358
|
const parts = tryResolveTemplateSpanFromConst(expr, ctx);
|
|
13254
13359
|
if (parts) {
|
|
13255
13360
|
return AttrValueOf.template(parts);
|
|
13256
13361
|
}
|
|
13257
13362
|
}
|
|
13258
|
-
if (
|
|
13363
|
+
if (ts13.isIdentifier(expr)) {
|
|
13259
13364
|
const resolved = tryResolveIdentifierAsTemplateLiteral(expr, ctx);
|
|
13260
13365
|
if (resolved) {
|
|
13261
13366
|
return AttrValueOf.template(resolved);
|
|
13262
13367
|
}
|
|
13263
13368
|
}
|
|
13264
|
-
if (
|
|
13369
|
+
if (ts13.isConditionalExpression(expr)) {
|
|
13265
13370
|
const ternary = parseTernary(expr, ctx);
|
|
13266
13371
|
if (ternary) {
|
|
13267
13372
|
return AttrValueOf.template([ternary]);
|
|
13268
13373
|
}
|
|
13269
13374
|
}
|
|
13270
|
-
if (
|
|
13271
|
-
if (
|
|
13375
|
+
if (ts13.isBinaryExpression(expr) && expr.operatorToken.kind === ts13.SyntaxKind.BarBarToken) {
|
|
13376
|
+
if (ts13.isIdentifier(expr.right) && expr.right.text === "undefined") {
|
|
13272
13377
|
const baseExpr = ctx.getJS(expr.left);
|
|
13273
13378
|
return AttrValueOf.expression(baseExpr, { presenceOrUndefined: true });
|
|
13274
13379
|
}
|
|
@@ -13281,11 +13386,11 @@ function getAttributeValue(attr, ctx) {
|
|
|
13281
13386
|
function tryStaticStyleObjectToCss(expr) {
|
|
13282
13387
|
const parts = [];
|
|
13283
13388
|
for (const prop of expr.properties) {
|
|
13284
|
-
if (!
|
|
13389
|
+
if (!ts13.isPropertyAssignment(prop))
|
|
13285
13390
|
return null;
|
|
13286
|
-
if (!
|
|
13391
|
+
if (!ts13.isIdentifier(prop.name) && !ts13.isStringLiteral(prop.name))
|
|
13287
13392
|
return null;
|
|
13288
|
-
if (!
|
|
13393
|
+
if (!ts13.isStringLiteral(prop.initializer))
|
|
13289
13394
|
return null;
|
|
13290
13395
|
const key = cssKebabCase(prop.name.text);
|
|
13291
13396
|
parts.push(`${key}:${prop.initializer.text}`);
|
|
@@ -13298,7 +13403,7 @@ function parseTemplateLiteral(expr, ctx) {
|
|
|
13298
13403
|
parts.push({ type: "string", value: expr.head.text });
|
|
13299
13404
|
}
|
|
13300
13405
|
for (const span of expr.templateSpans) {
|
|
13301
|
-
if (
|
|
13406
|
+
if (ts13.isConditionalExpression(span.expression)) {
|
|
13302
13407
|
const ternary = parseTernary(span.expression, ctx);
|
|
13303
13408
|
if (ternary) {
|
|
13304
13409
|
parts.push(ternary);
|
|
@@ -13324,7 +13429,7 @@ function parseTemplateLiteral(expr, ctx) {
|
|
|
13324
13429
|
return parts;
|
|
13325
13430
|
}
|
|
13326
13431
|
function tryResolveTemplateSpanFromConst(expr, ctx) {
|
|
13327
|
-
if (
|
|
13432
|
+
if (ts13.isIdentifier(expr)) {
|
|
13328
13433
|
if (ctx.scope.isBound(expr.text))
|
|
13329
13434
|
return null;
|
|
13330
13435
|
const constInfo = findLocalConst(expr.text, ctx.analyzer);
|
|
@@ -13333,13 +13438,13 @@ function tryResolveTemplateSpanFromConst(expr, ctx) {
|
|
|
13333
13438
|
const ast = parseConstInitializer(constInfo);
|
|
13334
13439
|
if (!ast)
|
|
13335
13440
|
return null;
|
|
13336
|
-
if (
|
|
13441
|
+
if (ts13.isStringLiteral(ast) || ts13.isNoSubstitutionTemplateLiteral(ast)) {
|
|
13337
13442
|
return [{ type: "string", value: ast.text }];
|
|
13338
13443
|
}
|
|
13339
13444
|
return null;
|
|
13340
13445
|
}
|
|
13341
|
-
if (
|
|
13342
|
-
if (!
|
|
13446
|
+
if (ts13.isElementAccessExpression(expr)) {
|
|
13447
|
+
if (!ts13.isIdentifier(expr.expression))
|
|
13343
13448
|
return null;
|
|
13344
13449
|
if (ctx.scope.isBound(expr.expression.text))
|
|
13345
13450
|
return null;
|
|
@@ -13347,17 +13452,17 @@ function tryResolveTemplateSpanFromConst(expr, ctx) {
|
|
|
13347
13452
|
if (!constInfo)
|
|
13348
13453
|
return null;
|
|
13349
13454
|
const ast = parseConstInitializer(constInfo);
|
|
13350
|
-
if (!ast || !
|
|
13455
|
+
if (!ast || !ts13.isObjectLiteralExpression(ast))
|
|
13351
13456
|
return null;
|
|
13352
13457
|
const cases = {};
|
|
13353
13458
|
for (const prop of ast.properties) {
|
|
13354
|
-
if (!
|
|
13459
|
+
if (!ts13.isPropertyAssignment(prop))
|
|
13355
13460
|
return null;
|
|
13356
|
-
const keyName = prop.name && (
|
|
13461
|
+
const keyName = prop.name && (ts13.isStringLiteral(prop.name) || ts13.isIdentifier(prop.name)) ? prop.name.text : null;
|
|
13357
13462
|
if (!keyName)
|
|
13358
13463
|
return null;
|
|
13359
13464
|
const value = prop.initializer;
|
|
13360
|
-
if (
|
|
13465
|
+
if (ts13.isStringLiteral(value) || ts13.isNoSubstitutionTemplateLiteral(value)) {
|
|
13361
13466
|
cases[keyName] = value.text;
|
|
13362
13467
|
} else {
|
|
13363
13468
|
return null;
|
|
@@ -13404,17 +13509,17 @@ function hasDynamicTagBinding(name, sourceFile) {
|
|
|
13404
13509
|
const visit2 = (node) => {
|
|
13405
13510
|
if (found)
|
|
13406
13511
|
return;
|
|
13407
|
-
if (
|
|
13512
|
+
if (ts13.isVariableDeclaration(node) && ts13.isIdentifier(node.name) && node.name.text === name && node.initializer) {
|
|
13408
13513
|
let init = node.initializer;
|
|
13409
|
-
while (
|
|
13514
|
+
while (ts13.isAsExpression(init) || ts13.isSatisfiesExpression(init) || ts13.isParenthesizedExpression(init) || ts13.isNonNullExpression(init)) {
|
|
13410
13515
|
init = init.expression;
|
|
13411
13516
|
}
|
|
13412
|
-
if (
|
|
13517
|
+
if (ts13.isPropertyAccessExpression(init) && init.name.text === "tag") {
|
|
13413
13518
|
found = true;
|
|
13414
13519
|
return;
|
|
13415
13520
|
}
|
|
13416
13521
|
}
|
|
13417
|
-
|
|
13522
|
+
ts13.forEachChild(node, visit2);
|
|
13418
13523
|
};
|
|
13419
13524
|
visit2(sourceFile);
|
|
13420
13525
|
return found;
|
|
@@ -13428,13 +13533,13 @@ function tryResolveIdentifierAsTemplateLiteral(ident, ctx) {
|
|
|
13428
13533
|
const ast = parseConstInitializer(constInfo);
|
|
13429
13534
|
if (!ast)
|
|
13430
13535
|
return null;
|
|
13431
|
-
if (
|
|
13536
|
+
if (ts13.isNoSubstitutionTemplateLiteral(ast) || ts13.isStringLiteral(ast)) {
|
|
13432
13537
|
return [{ type: "string", value: ast.text }];
|
|
13433
13538
|
}
|
|
13434
|
-
if (
|
|
13539
|
+
if (ts13.isElementAccessExpression(ast) && !ts13.isStringLiteralLike(ast.argumentExpression) && !ts13.isNumericLiteral(ast.argumentExpression)) {
|
|
13435
13540
|
return tryResolveTemplateSpanFromConst(ast, ctx);
|
|
13436
13541
|
}
|
|
13437
|
-
if (!
|
|
13542
|
+
if (!ts13.isTemplateExpression(ast))
|
|
13438
13543
|
return null;
|
|
13439
13544
|
let resolvedAny = false;
|
|
13440
13545
|
const parts = [];
|
|
@@ -13472,14 +13577,14 @@ function parseConstInitializerImpl(c) {
|
|
|
13472
13577
|
if (!c.value)
|
|
13473
13578
|
return null;
|
|
13474
13579
|
const wrapped = `const __bf_resolve__ = (${c.value})`;
|
|
13475
|
-
const sf =
|
|
13580
|
+
const sf = ts13.createSourceFile("__bf_resolve.ts", wrapped, ts13.ScriptTarget.Latest, true, ts13.ScriptKind.TS);
|
|
13476
13581
|
const stmt = sf.statements[0];
|
|
13477
|
-
if (!stmt || !
|
|
13582
|
+
if (!stmt || !ts13.isVariableStatement(stmt))
|
|
13478
13583
|
return null;
|
|
13479
13584
|
const decl = stmt.declarationList.declarations[0];
|
|
13480
13585
|
if (!decl?.initializer)
|
|
13481
13586
|
return null;
|
|
13482
|
-
return
|
|
13587
|
+
return ts13.isParenthesizedExpression(decl.initializer) ? decl.initializer.expression : decl.initializer;
|
|
13483
13588
|
}
|
|
13484
13589
|
function astText(node) {
|
|
13485
13590
|
return node.getText(node.getSourceFile());
|
|
@@ -13499,9 +13604,9 @@ function parseFunctionInfoAsExprImpl(fn) {
|
|
|
13499
13604
|
const params = fn.typedParams !== undefined ? fn.typedParams : fn.params.map(formatParamWithType).join(", ");
|
|
13500
13605
|
const body = fn.typedBody ?? fn.body;
|
|
13501
13606
|
const wrapped = `const __bf_resolve_fn__ = function(${params}) ${body}`;
|
|
13502
|
-
const sf =
|
|
13607
|
+
const sf = ts13.createSourceFile("__bf_resolve_fn.ts", wrapped, ts13.ScriptTarget.Latest, true, ts13.ScriptKind.TS);
|
|
13503
13608
|
const stmt = sf.statements[0];
|
|
13504
|
-
if (!stmt || !
|
|
13609
|
+
if (!stmt || !ts13.isVariableStatement(stmt))
|
|
13505
13610
|
return null;
|
|
13506
13611
|
const decl = stmt.declarationList.declarations[0];
|
|
13507
13612
|
if (!decl?.initializer)
|
|
@@ -13509,9 +13614,9 @@ function parseFunctionInfoAsExprImpl(fn) {
|
|
|
13509
13614
|
return decl.initializer;
|
|
13510
13615
|
}
|
|
13511
13616
|
function tryDesugarInterleaveTaggedTemplate(expr, ctx) {
|
|
13512
|
-
if (!
|
|
13617
|
+
if (!ts13.isTaggedTemplateExpression(expr))
|
|
13513
13618
|
return expr;
|
|
13514
|
-
if (!
|
|
13619
|
+
if (!ts13.isIdentifier(expr.tag))
|
|
13515
13620
|
return expr;
|
|
13516
13621
|
const resolvedTag = resolveInterleaveTagIdentifier(expr.tag.text, ctx);
|
|
13517
13622
|
if (!resolvedTag)
|
|
@@ -13528,23 +13633,23 @@ function resolveInterleaveTagIdentifier(name, ctx) {
|
|
|
13528
13633
|
return null;
|
|
13529
13634
|
if (constInfo) {
|
|
13530
13635
|
const ast = parseConstInitializer(constInfo);
|
|
13531
|
-
return ast && (
|
|
13636
|
+
return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
|
|
13532
13637
|
}
|
|
13533
13638
|
if (fnInfo) {
|
|
13534
13639
|
const ast = parseFunctionInfoAsExpr(fnInfo);
|
|
13535
|
-
return ast && (
|
|
13640
|
+
return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
|
|
13536
13641
|
}
|
|
13537
13642
|
return null;
|
|
13538
13643
|
}
|
|
13539
13644
|
function isInterleaveTagFunction(fn) {
|
|
13540
|
-
if (!
|
|
13645
|
+
if (!ts13.isArrowFunction(fn) && !ts13.isFunctionExpression(fn))
|
|
13541
13646
|
return false;
|
|
13542
13647
|
if (fn.parameters.length !== 2)
|
|
13543
13648
|
return false;
|
|
13544
13649
|
const [partsParam, argsParam] = fn.parameters;
|
|
13545
|
-
if (!
|
|
13650
|
+
if (!ts13.isIdentifier(partsParam.name) || partsParam.dotDotDotToken)
|
|
13546
13651
|
return false;
|
|
13547
|
-
if (!
|
|
13652
|
+
if (!ts13.isIdentifier(argsParam.name) || !argsParam.dotDotDotToken)
|
|
13548
13653
|
return false;
|
|
13549
13654
|
const parsed = tsNodeToParsedExpr(fn);
|
|
13550
13655
|
if (parsed.kind !== "arrow")
|
|
@@ -13601,7 +13706,7 @@ function isInterleaveSpanExpr(expr, i, argsName) {
|
|
|
13601
13706
|
function buildUntaggedTemplateLiteral(node, ctx) {
|
|
13602
13707
|
const template = node.template;
|
|
13603
13708
|
let text;
|
|
13604
|
-
if (
|
|
13709
|
+
if (ts13.isNoSubstitutionTemplateLiteral(template)) {
|
|
13605
13710
|
text = "`" + (template.rawText ?? template.text) + "`";
|
|
13606
13711
|
} else {
|
|
13607
13712
|
let body = template.head.rawText ?? template.head.text;
|
|
@@ -13613,15 +13718,15 @@ function buildUntaggedTemplateLiteral(node, ctx) {
|
|
|
13613
13718
|
text = "`" + body + "`";
|
|
13614
13719
|
}
|
|
13615
13720
|
const wrapped = `const __bf_resolve_tagged__ = (${text})`;
|
|
13616
|
-
const sf =
|
|
13721
|
+
const sf = ts13.createSourceFile("__bf_resolve_tagged.tsx", wrapped, ts13.ScriptTarget.Latest, true, ts13.ScriptKind.TSX);
|
|
13617
13722
|
const stmt = sf.statements[0];
|
|
13618
|
-
if (!stmt || !
|
|
13723
|
+
if (!stmt || !ts13.isVariableStatement(stmt))
|
|
13619
13724
|
return null;
|
|
13620
13725
|
const decl = stmt.declarationList.declarations[0];
|
|
13621
13726
|
if (!decl?.initializer)
|
|
13622
13727
|
return null;
|
|
13623
|
-
const result =
|
|
13624
|
-
if (!
|
|
13728
|
+
const result = ts13.isParenthesizedExpression(decl.initializer) ? decl.initializer.expression : decl.initializer;
|
|
13729
|
+
if (!ts13.isTemplateExpression(result) && !ts13.isNoSubstitutionTemplateLiteral(result))
|
|
13625
13730
|
return null;
|
|
13626
13731
|
return result;
|
|
13627
13732
|
}
|
|
@@ -13641,10 +13746,10 @@ function parseTernary(expr, ctx) {
|
|
|
13641
13746
|
return null;
|
|
13642
13747
|
}
|
|
13643
13748
|
function getStringValue(node) {
|
|
13644
|
-
if (
|
|
13749
|
+
if (ts13.isStringLiteral(node)) {
|
|
13645
13750
|
return node.text;
|
|
13646
13751
|
}
|
|
13647
|
-
if (
|
|
13752
|
+
if (ts13.isNoSubstitutionTemplateLiteral(node)) {
|
|
13648
13753
|
return node.text;
|
|
13649
13754
|
}
|
|
13650
13755
|
return null;
|
|
@@ -13652,19 +13757,19 @@ function getStringValue(node) {
|
|
|
13652
13757
|
function processComponentProps(attributes, ctx) {
|
|
13653
13758
|
const props = [];
|
|
13654
13759
|
for (const attr of attributes.properties) {
|
|
13655
|
-
if (
|
|
13760
|
+
if (ts13.isJsxSpreadAttribute(attr)) {
|
|
13656
13761
|
props.push(...expandSpreadAttribute(attr, ctx));
|
|
13657
13762
|
continue;
|
|
13658
13763
|
}
|
|
13659
|
-
if (!
|
|
13764
|
+
if (!ts13.isJsxAttribute(attr))
|
|
13660
13765
|
continue;
|
|
13661
13766
|
const name = attr.name.getText(ctx.sourceFile);
|
|
13662
|
-
if (attr.initializer &&
|
|
13767
|
+
if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
13663
13768
|
let jsxExpr = attr.initializer.expression;
|
|
13664
|
-
while (
|
|
13769
|
+
while (ts13.isParenthesizedExpression(jsxExpr)) {
|
|
13665
13770
|
jsxExpr = jsxExpr.expression;
|
|
13666
13771
|
}
|
|
13667
|
-
if (
|
|
13772
|
+
if (ts13.isJsxElement(jsxExpr) || ts13.isJsxSelfClosingElement(jsxExpr) || ts13.isJsxFragment(jsxExpr)) {
|
|
13668
13773
|
const prevInsideComponentChildren = ctx.insideComponentChildren;
|
|
13669
13774
|
ctx.insideComponentChildren = true;
|
|
13670
13775
|
const irNode = transformNode(jsxExpr, ctx);
|
|
@@ -13691,7 +13796,7 @@ function processComponentProps(attributes, ctx) {
|
|
|
13691
13796
|
value = AttrValueOf.booleanShorthand();
|
|
13692
13797
|
}
|
|
13693
13798
|
let clientOnly;
|
|
13694
|
-
if (attr.initializer &&
|
|
13799
|
+
if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
13695
13800
|
if (value.kind === "expression" && value.templateExpr === undefined) {
|
|
13696
13801
|
const rewritten = rewriteBarePropRefs2(value.expr, attr.initializer.expression, ctx);
|
|
13697
13802
|
if (rewritten !== value.expr) {
|
|
@@ -13715,7 +13820,7 @@ function processComponentProps(attributes, ctx) {
|
|
|
13715
13820
|
return props;
|
|
13716
13821
|
}
|
|
13717
13822
|
function checkBareSignalOrMemoIdentifier(expr, ctx) {
|
|
13718
|
-
if (!
|
|
13823
|
+
if (!ts13.isIdentifier(expr))
|
|
13719
13824
|
return;
|
|
13720
13825
|
const name = expr.text;
|
|
13721
13826
|
for (const signal of ctx.analyzer.signals) {
|
|
@@ -13746,12 +13851,12 @@ function checkBareSignalOrMemoIdentifier(expr, ctx) {
|
|
|
13746
13851
|
function isArrayExprDirectPropRef(arrayExpr, ctx) {
|
|
13747
13852
|
const propNames = new Set(ctx.patterns.props.map((p) => p.name));
|
|
13748
13853
|
const propsObjName = ctx.analyzer.propsObjectName;
|
|
13749
|
-
if (
|
|
13854
|
+
if (ts13.isIdentifier(arrayExpr)) {
|
|
13750
13855
|
return propNames.has(arrayExpr.text);
|
|
13751
13856
|
}
|
|
13752
|
-
if (
|
|
13857
|
+
if (ts13.isPropertyAccessExpression(arrayExpr) && propsObjName) {
|
|
13753
13858
|
const obj = arrayExpr.expression;
|
|
13754
|
-
if (
|
|
13859
|
+
if (ts13.isIdentifier(obj) && obj.text === propsObjName) {
|
|
13755
13860
|
return true;
|
|
13756
13861
|
}
|
|
13757
13862
|
}
|
|
@@ -13946,7 +14051,7 @@ function buildIfStatementChain(analyzer, ctx, opts) {
|
|
|
13946
14051
|
jsxBranchLocalNames.add(n);
|
|
13947
14052
|
}
|
|
13948
14053
|
for (const decl of condReturn.scopeVariables) {
|
|
13949
|
-
if (
|
|
14054
|
+
if (ts13.isIdentifier(decl.name) && decl.initializer) {
|
|
13950
14055
|
branchScopeVars.set(decl.name.text, decl.initializer);
|
|
13951
14056
|
if (initializerShapeContainsJsx(decl.initializer)) {
|
|
13952
14057
|
jsxBranchLocalNames.add(decl.name.text);
|
|
@@ -14013,7 +14118,7 @@ function buildIfStatementChain(analyzer, ctx, opts) {
|
|
|
14013
14118
|
}
|
|
14014
14119
|
const scopeVariables = [];
|
|
14015
14120
|
for (const decl of condReturn.scopeVariables) {
|
|
14016
|
-
if (
|
|
14121
|
+
if (ts13.isIdentifier(decl.name) && decl.initializer) {
|
|
14017
14122
|
const init = ctx.getJS(decl.initializer);
|
|
14018
14123
|
const typedInit = decl.initializer.getText(ctx.sourceFile);
|
|
14019
14124
|
scopeVariables.push({
|
|
@@ -15304,7 +15409,8 @@ function collectLoopChildConditionals(node, ctx, siblingOffsets, loopParam, loop
|
|
|
15304
15409
|
if (!n.reactive && !refsLoopParamInSource)
|
|
15305
15410
|
return;
|
|
15306
15411
|
const expanded = expandConstantForReactivity(n.condition, ctx, sourceFreeIds, scope);
|
|
15307
|
-
|
|
15412
|
+
const readsPreamble = preambleNames !== undefined && preambleNames.size > 0 && anyNameIn(expanded.freeIds ?? extractFreeIdentifiersFromText(expanded.expr), preambleNames);
|
|
15413
|
+
if (!readsPreamble && classifyReactivity(expanded.expr, ctx, loopParam, loopParamBindings, expanded.freeIds).kind === "none")
|
|
15308
15414
|
return;
|
|
15309
15415
|
const loopParamsForCond = loopParam ? [{ param: loopParam, bindings: loopParamBindings }] : undefined;
|
|
15310
15416
|
const whenTrueHtml = irToHtmlTemplate(n.whenTrue, undefined, 0, loopParamsForCond, "__slots");
|
|
@@ -15316,7 +15422,8 @@ function collectLoopChildConditionals(node, ctx, siblingOffsets, loopParam, loop
|
|
|
15316
15422
|
whenFalseHtml,
|
|
15317
15423
|
whenTrue: summarizeLoopChildBranch(n.whenTrue, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex),
|
|
15318
15424
|
whenFalse: summarizeLoopChildBranch(n.whenFalse, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex),
|
|
15319
|
-
...expanded.freeIds !== undefined && { conditionFreeIdentifiers: expanded.freeIds }
|
|
15425
|
+
...expanded.freeIds !== undefined && { conditionFreeIdentifiers: expanded.freeIds },
|
|
15426
|
+
...readsPreamble && { readsPreamble: true }
|
|
15320
15427
|
});
|
|
15321
15428
|
}
|
|
15322
15429
|
});
|
|
@@ -15692,7 +15799,7 @@ function graphDeclarationReferences(graph, kind, name) {
|
|
|
15692
15799
|
}
|
|
15693
15800
|
|
|
15694
15801
|
// src/ir-to-client-js/walk-prop-accesses.ts
|
|
15695
|
-
import
|
|
15802
|
+
import ts14 from "typescript";
|
|
15696
15803
|
function collectPropAccesses(source, propNames, out) {
|
|
15697
15804
|
if (propNames.size === 0)
|
|
15698
15805
|
return;
|
|
@@ -15706,7 +15813,7 @@ function collectPropAccesses(source, propNames, out) {
|
|
|
15706
15813
|
if (!anyMentioned)
|
|
15707
15814
|
return;
|
|
15708
15815
|
for (const expr of normaliseExpressionParts(source)) {
|
|
15709
|
-
const sourceFile =
|
|
15816
|
+
const sourceFile = ts14.createSourceFile("p.ts", expr, ts14.ScriptTarget.Latest, false, ts14.ScriptKind.TS);
|
|
15710
15817
|
visit2(sourceFile, propNames, out);
|
|
15711
15818
|
}
|
|
15712
15819
|
}
|
|
@@ -15716,15 +15823,15 @@ function normaliseExpressionParts(source) {
|
|
|
15716
15823
|
return extractTemplateExpressions(source);
|
|
15717
15824
|
}
|
|
15718
15825
|
function visit2(node, propNames, out) {
|
|
15719
|
-
if (
|
|
15826
|
+
if (ts14.isPropertyAccessExpression(node)) {
|
|
15720
15827
|
recordIfPropAccess(node.expression, "property", propNames, out);
|
|
15721
|
-
} else if (
|
|
15828
|
+
} else if (ts14.isElementAccessExpression(node)) {
|
|
15722
15829
|
recordIfPropAccess(node.expression, "index", propNames, out);
|
|
15723
15830
|
}
|
|
15724
|
-
|
|
15831
|
+
ts14.forEachChild(node, (child) => visit2(child, propNames, out));
|
|
15725
15832
|
}
|
|
15726
15833
|
function recordIfPropAccess(receiver, kind, propNames, out) {
|
|
15727
|
-
if (!
|
|
15834
|
+
if (!ts14.isIdentifier(receiver))
|
|
15728
15835
|
return;
|
|
15729
15836
|
const name = receiver.text;
|
|
15730
15837
|
if (!propNames.has(name))
|
|
@@ -15777,56 +15884,56 @@ function propHasPropertyAccess(u) {
|
|
|
15777
15884
|
}
|
|
15778
15885
|
|
|
15779
15886
|
// src/value-references.ts
|
|
15780
|
-
import
|
|
15887
|
+
import ts15 from "typescript";
|
|
15781
15888
|
function isValueReferenceIdentifier(id) {
|
|
15782
15889
|
const parent = id.parent;
|
|
15783
15890
|
if (!parent)
|
|
15784
15891
|
return false;
|
|
15785
|
-
if (
|
|
15892
|
+
if (ts15.isPropertyAccessExpression(parent) && parent.name === id)
|
|
15786
15893
|
return false;
|
|
15787
|
-
if (
|
|
15894
|
+
if (ts15.isPropertyAssignment(parent) && parent.name === id)
|
|
15788
15895
|
return false;
|
|
15789
|
-
if ((
|
|
15896
|
+
if ((ts15.isMethodDeclaration(parent) || ts15.isGetAccessorDeclaration(parent) || ts15.isSetAccessorDeclaration(parent)) && parent.name === id) {
|
|
15790
15897
|
return false;
|
|
15791
15898
|
}
|
|
15792
|
-
if (
|
|
15899
|
+
if (ts15.isPropertyDeclaration(parent) && parent.name === id)
|
|
15793
15900
|
return false;
|
|
15794
|
-
if (
|
|
15901
|
+
if (ts15.isMetaProperty(parent) && parent.name === id)
|
|
15795
15902
|
return false;
|
|
15796
|
-
if (
|
|
15903
|
+
if (ts15.isVariableDeclaration(parent) && parent.name === id)
|
|
15797
15904
|
return false;
|
|
15798
|
-
if (
|
|
15905
|
+
if (ts15.isFunctionDeclaration(parent) && parent.name === id)
|
|
15799
15906
|
return false;
|
|
15800
|
-
if (
|
|
15907
|
+
if (ts15.isFunctionExpression(parent) && parent.name === id)
|
|
15801
15908
|
return false;
|
|
15802
|
-
if (
|
|
15909
|
+
if (ts15.isClassDeclaration(parent) && parent.name === id)
|
|
15803
15910
|
return false;
|
|
15804
|
-
if (
|
|
15911
|
+
if (ts15.isClassExpression(parent) && parent.name === id)
|
|
15805
15912
|
return false;
|
|
15806
|
-
if (
|
|
15913
|
+
if (ts15.isParameter(parent) && parent.name === id)
|
|
15807
15914
|
return false;
|
|
15808
|
-
if (
|
|
15915
|
+
if (ts15.isBindingElement(parent) && (parent.name === id || parent.propertyName === id))
|
|
15809
15916
|
return false;
|
|
15810
|
-
if (
|
|
15917
|
+
if (ts15.isLabeledStatement(parent) && parent.label === id)
|
|
15811
15918
|
return false;
|
|
15812
|
-
if (
|
|
15919
|
+
if (ts15.isBreakOrContinueStatement(parent) && parent.label === id)
|
|
15813
15920
|
return false;
|
|
15814
|
-
if (
|
|
15921
|
+
if (ts15.isImportSpecifier(parent) && (parent.name === id || parent.propertyName === id))
|
|
15815
15922
|
return false;
|
|
15816
|
-
if (
|
|
15923
|
+
if (ts15.isExportSpecifier(parent) && (parent.name === id || parent.propertyName === id))
|
|
15817
15924
|
return false;
|
|
15818
|
-
if (
|
|
15925
|
+
if (ts15.isImportClause(parent) && parent.name === id)
|
|
15819
15926
|
return false;
|
|
15820
|
-
if (
|
|
15927
|
+
if (ts15.isNamespaceImport(parent) && parent.name === id)
|
|
15821
15928
|
return false;
|
|
15822
|
-
if (
|
|
15929
|
+
if (ts15.isQualifiedName(parent) && parent.right === id)
|
|
15823
15930
|
return false;
|
|
15824
15931
|
return true;
|
|
15825
15932
|
}
|
|
15826
15933
|
function collectValueReferencedNames(code) {
|
|
15827
15934
|
let sourceFile;
|
|
15828
15935
|
try {
|
|
15829
|
-
sourceFile =
|
|
15936
|
+
sourceFile = ts15.createSourceFile("generated.js", code, ts15.ScriptTarget.Latest, true, ts15.ScriptKind.JS);
|
|
15830
15937
|
} catch {
|
|
15831
15938
|
return null;
|
|
15832
15939
|
}
|
|
@@ -15835,10 +15942,10 @@ function collectValueReferencedNames(code) {
|
|
|
15835
15942
|
return null;
|
|
15836
15943
|
const names = new Set;
|
|
15837
15944
|
function visit3(node) {
|
|
15838
|
-
if (
|
|
15945
|
+
if (ts15.isIdentifier(node) && isValueReferenceIdentifier(node)) {
|
|
15839
15946
|
names.add(node.text);
|
|
15840
15947
|
}
|
|
15841
|
-
|
|
15948
|
+
ts15.forEachChild(node, visit3);
|
|
15842
15949
|
}
|
|
15843
15950
|
visit3(sourceFile);
|
|
15844
15951
|
return names;
|
|
@@ -16006,7 +16113,7 @@ function collectComponentNames(node) {
|
|
|
16006
16113
|
}
|
|
16007
16114
|
|
|
16008
16115
|
// src/relocate.ts
|
|
16009
|
-
import
|
|
16116
|
+
import ts16 from "typescript";
|
|
16010
16117
|
|
|
16011
16118
|
// src/lowering-registry.ts
|
|
16012
16119
|
var plugins = [];
|
|
@@ -16052,19 +16159,19 @@ function classify(name, env) {
|
|
|
16052
16159
|
function collectFreeRefs(node) {
|
|
16053
16160
|
const refs = new Map;
|
|
16054
16161
|
function visit3(n, parent) {
|
|
16055
|
-
if (
|
|
16056
|
-
if (parent &&
|
|
16162
|
+
if (ts16.isIdentifier(n)) {
|
|
16163
|
+
if (parent && ts16.isPropertyAccessExpression(parent) && parent.name === n)
|
|
16057
16164
|
return;
|
|
16058
|
-
if (parent &&
|
|
16165
|
+
if (parent && ts16.isPropertyAssignment(parent) && parent.name === n)
|
|
16059
16166
|
return;
|
|
16060
|
-
if (parent &&
|
|
16167
|
+
if (parent && ts16.isShorthandPropertyAssignment(parent) && parent.name === n)
|
|
16061
16168
|
return;
|
|
16062
16169
|
const list = refs.get(n.text) ?? [];
|
|
16063
16170
|
list.push(n);
|
|
16064
16171
|
refs.set(n.text, list);
|
|
16065
16172
|
return;
|
|
16066
16173
|
}
|
|
16067
|
-
|
|
16174
|
+
ts16.forEachChild(n, (child) => visit3(child, n));
|
|
16068
16175
|
}
|
|
16069
16176
|
visit3(node);
|
|
16070
16177
|
return refs;
|
|
@@ -16168,11 +16275,11 @@ function isInlinableInTemplate(value, env) {
|
|
|
16168
16275
|
return { ok: true, rewrittenValue: r.text, decisions: r.decisions };
|
|
16169
16276
|
}
|
|
16170
16277
|
function getCalleeIdentifierPath(callee) {
|
|
16171
|
-
if (
|
|
16278
|
+
if (ts16.isParenthesizedExpression(callee))
|
|
16172
16279
|
return getCalleeIdentifierPath(callee.expression);
|
|
16173
|
-
if (
|
|
16280
|
+
if (ts16.isIdentifier(callee))
|
|
16174
16281
|
return callee.text;
|
|
16175
|
-
if (
|
|
16282
|
+
if (ts16.isPropertyAccessExpression(callee)) {
|
|
16176
16283
|
const left = getCalleeIdentifierPath(callee.expression);
|
|
16177
16284
|
if (left === null)
|
|
16178
16285
|
return null;
|
|
@@ -16181,11 +16288,11 @@ function getCalleeIdentifierPath(callee) {
|
|
|
16181
16288
|
return null;
|
|
16182
16289
|
}
|
|
16183
16290
|
function getCalleeLeftmostIdentifier(callee) {
|
|
16184
|
-
if (
|
|
16291
|
+
if (ts16.isParenthesizedExpression(callee))
|
|
16185
16292
|
return getCalleeLeftmostIdentifier(callee.expression);
|
|
16186
|
-
if (
|
|
16293
|
+
if (ts16.isIdentifier(callee))
|
|
16187
16294
|
return callee.text;
|
|
16188
|
-
if (
|
|
16295
|
+
if (ts16.isPropertyAccessExpression(callee)) {
|
|
16189
16296
|
return getCalleeLeftmostIdentifier(callee.expression);
|
|
16190
16297
|
}
|
|
16191
16298
|
return null;
|
|
@@ -16233,12 +16340,12 @@ function isCallAcceptedByAdapter(call, env) {
|
|
|
16233
16340
|
}
|
|
16234
16341
|
function parseExpressionNode(text) {
|
|
16235
16342
|
try {
|
|
16236
|
-
const sf =
|
|
16343
|
+
const sf = ts16.createSourceFile("__inline_check__.ts", `(${text});`, ts16.ScriptTarget.Latest, false, ts16.ScriptKind.TS);
|
|
16237
16344
|
const stmt = sf.statements[0];
|
|
16238
|
-
if (!stmt || !
|
|
16345
|
+
if (!stmt || !ts16.isExpressionStatement(stmt))
|
|
16239
16346
|
return null;
|
|
16240
16347
|
const inner = stmt.expression;
|
|
16241
|
-
return
|
|
16348
|
+
return ts16.isParenthesizedExpression(inner) ? inner.expression : inner;
|
|
16242
16349
|
} catch {
|
|
16243
16350
|
return null;
|
|
16244
16351
|
}
|
|
@@ -16255,8 +16362,8 @@ function hasCallWithBridgedArg(node, decisions, env) {
|
|
|
16255
16362
|
function visit3(n) {
|
|
16256
16363
|
if (found)
|
|
16257
16364
|
return;
|
|
16258
|
-
if (
|
|
16259
|
-
const accepted =
|
|
16365
|
+
if (ts16.isCallExpression(n) || ts16.isNewExpression(n)) {
|
|
16366
|
+
const accepted = ts16.isCallExpression(n) && isCallAcceptedByAdapter(n, env);
|
|
16260
16367
|
if (!accepted) {
|
|
16261
16368
|
const args = n.arguments;
|
|
16262
16369
|
if (args) {
|
|
@@ -16269,7 +16376,7 @@ function hasCallWithBridgedArg(node, decisions, env) {
|
|
|
16269
16376
|
}
|
|
16270
16377
|
}
|
|
16271
16378
|
}
|
|
16272
|
-
|
|
16379
|
+
ts16.forEachChild(n, visit3);
|
|
16273
16380
|
}
|
|
16274
16381
|
visit3(node);
|
|
16275
16382
|
return found;
|
|
@@ -16279,13 +16386,13 @@ function hasZeroArgCall(node, env) {
|
|
|
16279
16386
|
function visit3(n) {
|
|
16280
16387
|
if (found)
|
|
16281
16388
|
return;
|
|
16282
|
-
if (
|
|
16389
|
+
if (ts16.isCallExpression(n) && n.arguments.length === 0) {
|
|
16283
16390
|
if (!isCallAcceptedByAdapter(n, env)) {
|
|
16284
16391
|
found = true;
|
|
16285
16392
|
return;
|
|
16286
16393
|
}
|
|
16287
16394
|
}
|
|
16288
|
-
|
|
16395
|
+
ts16.forEachChild(n, visit3);
|
|
16289
16396
|
}
|
|
16290
16397
|
visit3(node);
|
|
16291
16398
|
return found;
|
|
@@ -16295,25 +16402,25 @@ function containsAnyIdentifier(node, names) {
|
|
|
16295
16402
|
function visit3(n) {
|
|
16296
16403
|
if (found)
|
|
16297
16404
|
return;
|
|
16298
|
-
if (
|
|
16405
|
+
if (ts16.isPropertyAccessExpression(n)) {
|
|
16299
16406
|
visit3(n.expression);
|
|
16300
16407
|
return;
|
|
16301
16408
|
}
|
|
16302
|
-
if (
|
|
16409
|
+
if (ts16.isPropertyAssignment(n)) {
|
|
16303
16410
|
visit3(n.initializer);
|
|
16304
16411
|
return;
|
|
16305
16412
|
}
|
|
16306
|
-
if (
|
|
16307
|
-
if (
|
|
16413
|
+
if (ts16.isShorthandPropertyAssignment(n)) {
|
|
16414
|
+
if (ts16.isIdentifier(n.name) && names.has(n.name.text)) {
|
|
16308
16415
|
found = true;
|
|
16309
16416
|
}
|
|
16310
16417
|
return;
|
|
16311
16418
|
}
|
|
16312
|
-
if (
|
|
16419
|
+
if (ts16.isIdentifier(n) && names.has(n.text)) {
|
|
16313
16420
|
found = true;
|
|
16314
16421
|
return;
|
|
16315
16422
|
}
|
|
16316
|
-
|
|
16423
|
+
ts16.forEachChild(n, visit3);
|
|
16317
16424
|
}
|
|
16318
16425
|
visit3(node);
|
|
16319
16426
|
return found;
|
|
@@ -17616,23 +17723,23 @@ function resolveFinalImports(generatedCode, ir, localImportPrefixes) {
|
|
|
17616
17723
|
}
|
|
17617
17724
|
|
|
17618
17725
|
// src/ir-to-client-js/prune-unused-prop-extractions.ts
|
|
17619
|
-
import
|
|
17726
|
+
import ts17 from "typescript";
|
|
17620
17727
|
function propExtractionName(stmt) {
|
|
17621
|
-
if (!
|
|
17728
|
+
if (!ts17.isVariableStatement(stmt))
|
|
17622
17729
|
return null;
|
|
17623
17730
|
const decls = stmt.declarationList.declarations;
|
|
17624
17731
|
if (decls.length !== 1)
|
|
17625
17732
|
return null;
|
|
17626
17733
|
const decl = decls[0];
|
|
17627
|
-
if (!
|
|
17734
|
+
if (!ts17.isIdentifier(decl.name) || !decl.initializer)
|
|
17628
17735
|
return null;
|
|
17629
17736
|
let core = decl.initializer;
|
|
17630
|
-
if (
|
|
17737
|
+
if (ts17.isBinaryExpression(core) && core.operatorToken.kind === ts17.SyntaxKind.QuestionQuestionToken) {
|
|
17631
17738
|
core = core.left;
|
|
17632
17739
|
}
|
|
17633
|
-
if (!
|
|
17740
|
+
if (!ts17.isPropertyAccessExpression(core))
|
|
17634
17741
|
return null;
|
|
17635
|
-
if (!
|
|
17742
|
+
if (!ts17.isIdentifier(core.expression) || core.expression.text !== PROPS_PARAM)
|
|
17636
17743
|
return null;
|
|
17637
17744
|
if (core.name.text !== decl.name.text)
|
|
17638
17745
|
return null;
|
|
@@ -17645,10 +17752,10 @@ function pruneUnusedPropExtractions(code) {
|
|
|
17645
17752
|
console.warn("[barefootjs] pruneUnusedPropExtractions: generated code did not parse; skipping prune");
|
|
17646
17753
|
return code;
|
|
17647
17754
|
}
|
|
17648
|
-
const sourceFile =
|
|
17755
|
+
const sourceFile = ts17.createSourceFile("generated.js", code, ts17.ScriptTarget.Latest, false, ts17.ScriptKind.JS);
|
|
17649
17756
|
const spans = [];
|
|
17650
17757
|
for (const stmt of sourceFile.statements) {
|
|
17651
|
-
if (!
|
|
17758
|
+
if (!ts17.isFunctionDeclaration(stmt) || !stmt.name?.text.startsWith("init") || !stmt.body)
|
|
17652
17759
|
continue;
|
|
17653
17760
|
for (const inner of stmt.body.statements) {
|
|
17654
17761
|
const name = propExtractionName(inner);
|
|
@@ -18612,7 +18719,8 @@ function buildReactiveEffectsPlan(args) {
|
|
|
18612
18719
|
whenTrueTemplateHtml: addCondAttrToTemplate(wrap(cond.whenTrueHtml), cond.slotId),
|
|
18613
18720
|
whenFalseTemplateHtml: addCondAttrToTemplate(wrap(cond.whenFalseHtml), cond.slotId),
|
|
18614
18721
|
whenTrueArm: buildOuterArm(cond.whenTrue, wrap, loopParam, loopParamBindings, profileComponentName),
|
|
18615
|
-
whenFalseArm: buildOuterArm(cond.whenFalse, wrap, loopParam, loopParamBindings, profileComponentName)
|
|
18722
|
+
whenFalseArm: buildOuterArm(cond.whenFalse, wrap, loopParam, loopParamBindings, profileComponentName),
|
|
18723
|
+
...cond.readsPreamble && { readsPreamble: true }
|
|
18616
18724
|
});
|
|
18617
18725
|
}
|
|
18618
18726
|
}
|
|
@@ -19093,7 +19201,7 @@ function analyzeLazyConditional(cond, indexParam, arms) {
|
|
|
19093
19201
|
}
|
|
19094
19202
|
|
|
19095
19203
|
// src/ir-to-client-js/control-flow/plan/lazy-preamble.ts
|
|
19096
|
-
import
|
|
19204
|
+
import ts18 from "typescript";
|
|
19097
19205
|
var NO_PREAMBLE = {
|
|
19098
19206
|
lazySafe: true,
|
|
19099
19207
|
facts: { declaredNames: new Set, freeNames: new Set }
|
|
@@ -19113,12 +19221,12 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
|
|
|
19113
19221
|
if (text.trim().length === 0)
|
|
19114
19222
|
return NO_PREAMBLE;
|
|
19115
19223
|
const declaredNames = new Set;
|
|
19116
|
-
const sf =
|
|
19224
|
+
const sf = ts18.createSourceFile("__lazy_preamble__.ts", text, ts18.ScriptTarget.Latest, true, ts18.ScriptKind.TS);
|
|
19117
19225
|
for (const stmt of sf.statements) {
|
|
19118
|
-
if (!
|
|
19119
|
-
return NO2(`map-callback preamble has a non-declaration statement (${
|
|
19226
|
+
if (!ts18.isVariableStatement(stmt)) {
|
|
19227
|
+
return NO2(`map-callback preamble has a non-declaration statement (${ts18.SyntaxKind[stmt.kind]})`);
|
|
19120
19228
|
}
|
|
19121
|
-
const isConst = (stmt.declarationList.flags &
|
|
19229
|
+
const isConst = (stmt.declarationList.flags & ts18.NodeFlags.Const) !== 0;
|
|
19122
19230
|
if (!isConst)
|
|
19123
19231
|
return NO2("map-callback preamble declares a mutable binding (let/var)");
|
|
19124
19232
|
for (const decl of stmt.declarationList.declarations) {
|
|
@@ -19147,12 +19255,12 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
|
|
|
19147
19255
|
return { lazySafe: true, facts: { declaredNames, freeNames } };
|
|
19148
19256
|
}
|
|
19149
19257
|
function collectBindingNames3(name, out) {
|
|
19150
|
-
if (
|
|
19258
|
+
if (ts18.isIdentifier(name)) {
|
|
19151
19259
|
out.add(name.text);
|
|
19152
19260
|
return;
|
|
19153
19261
|
}
|
|
19154
19262
|
for (const element of name.elements) {
|
|
19155
|
-
if (
|
|
19263
|
+
if (ts18.isOmittedExpression(element))
|
|
19156
19264
|
continue;
|
|
19157
19265
|
collectBindingNames3(element.name, out);
|
|
19158
19266
|
}
|
|
@@ -19162,56 +19270,56 @@ function findImpureNode(root, primableNames) {
|
|
|
19162
19270
|
const visit3 = (node) => {
|
|
19163
19271
|
if (found)
|
|
19164
19272
|
return;
|
|
19165
|
-
if (
|
|
19273
|
+
if (ts18.isCallExpression(node)) {
|
|
19166
19274
|
const callee = node.expression;
|
|
19167
|
-
const isSignalRead =
|
|
19275
|
+
const isSignalRead = ts18.isIdentifier(callee) && primableNames.has(callee.text) && node.arguments.length === 0 && node.questionDotToken === undefined;
|
|
19168
19276
|
if (!isSignalRead) {
|
|
19169
19277
|
found = `call to ${callee.getText(callee.getSourceFile())}`;
|
|
19170
19278
|
return;
|
|
19171
19279
|
}
|
|
19172
19280
|
}
|
|
19173
|
-
if (
|
|
19281
|
+
if (ts18.isNewExpression(node)) {
|
|
19174
19282
|
found = "new expression";
|
|
19175
19283
|
return;
|
|
19176
19284
|
}
|
|
19177
|
-
if (
|
|
19285
|
+
if (ts18.isTaggedTemplateExpression(node)) {
|
|
19178
19286
|
found = "tagged template";
|
|
19179
19287
|
return;
|
|
19180
19288
|
}
|
|
19181
|
-
if (
|
|
19289
|
+
if (ts18.isAwaitExpression(node)) {
|
|
19182
19290
|
found = "await";
|
|
19183
19291
|
return;
|
|
19184
19292
|
}
|
|
19185
|
-
if (
|
|
19293
|
+
if (ts18.isYieldExpression(node)) {
|
|
19186
19294
|
found = "yield";
|
|
19187
19295
|
return;
|
|
19188
19296
|
}
|
|
19189
|
-
if (
|
|
19297
|
+
if (ts18.isPrefixUnaryExpression(node) || ts18.isPostfixUnaryExpression(node)) {
|
|
19190
19298
|
const op = node.operator;
|
|
19191
|
-
if (op ===
|
|
19299
|
+
if (op === ts18.SyntaxKind.PlusPlusToken || op === ts18.SyntaxKind.MinusMinusToken) {
|
|
19192
19300
|
found = "increment/decrement";
|
|
19193
19301
|
return;
|
|
19194
19302
|
}
|
|
19195
19303
|
}
|
|
19196
|
-
if (
|
|
19304
|
+
if (ts18.isDeleteExpression(node)) {
|
|
19197
19305
|
found = "delete";
|
|
19198
19306
|
return;
|
|
19199
19307
|
}
|
|
19200
|
-
if (
|
|
19308
|
+
if (ts18.isFunctionExpression(node) || ts18.isArrowFunction(node) || ts18.isClassExpression(node)) {
|
|
19201
19309
|
found = "function or class expression";
|
|
19202
19310
|
return;
|
|
19203
19311
|
}
|
|
19204
|
-
if (
|
|
19312
|
+
if (ts18.isBinaryExpression(node) && isAssignmentOperator2(node.operatorToken.kind)) {
|
|
19205
19313
|
found = "assignment";
|
|
19206
19314
|
return;
|
|
19207
19315
|
}
|
|
19208
|
-
|
|
19316
|
+
ts18.forEachChild(node, visit3);
|
|
19209
19317
|
};
|
|
19210
19318
|
visit3(root);
|
|
19211
19319
|
return found;
|
|
19212
19320
|
}
|
|
19213
|
-
function
|
|
19214
|
-
return kind >=
|
|
19321
|
+
function isAssignmentOperator2(kind) {
|
|
19322
|
+
return kind >= ts18.SyntaxKind.FirstAssignment && kind <= ts18.SyntaxKind.LastAssignment;
|
|
19215
19323
|
}
|
|
19216
19324
|
|
|
19217
19325
|
// src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts
|
|
@@ -19741,7 +19849,7 @@ function buildArmBody(branch, options) {
|
|
|
19741
19849
|
}
|
|
19742
19850
|
|
|
19743
19851
|
// src/ir-to-client-js/emit-reactive.ts
|
|
19744
|
-
import
|
|
19852
|
+
import ts19 from "typescript";
|
|
19745
19853
|
|
|
19746
19854
|
// src/ir-to-client-js/control-flow/stringify/claim-plan.ts
|
|
19747
19855
|
function slotSpecLiteral(slot) {
|
|
@@ -19845,20 +19953,20 @@ function lowerToLocaleCallsInReactiveExpr(expr, matcher) {
|
|
|
19845
19953
|
return expr;
|
|
19846
19954
|
let sourceFile;
|
|
19847
19955
|
try {
|
|
19848
|
-
sourceFile =
|
|
19956
|
+
sourceFile = ts19.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts19.ScriptTarget.Latest, true, ts19.ScriptKind.TS);
|
|
19849
19957
|
} catch {
|
|
19850
19958
|
return expr;
|
|
19851
19959
|
}
|
|
19852
19960
|
const stmt = sourceFile.statements[0];
|
|
19853
|
-
if (!stmt || !
|
|
19961
|
+
if (!stmt || !ts19.isExpressionStatement(stmt))
|
|
19854
19962
|
return expr;
|
|
19855
|
-
const root =
|
|
19963
|
+
const root = ts19.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
19856
19964
|
const candidates = [];
|
|
19857
19965
|
const visit3 = (n) => {
|
|
19858
|
-
if (
|
|
19966
|
+
if (ts19.isCallExpression(n) && n.arguments.length === 2 && ts19.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && n.expression.name.text === "toLocaleDateString") {
|
|
19859
19967
|
candidates.push(n);
|
|
19860
19968
|
}
|
|
19861
|
-
|
|
19969
|
+
ts19.forEachChild(n, visit3);
|
|
19862
19970
|
};
|
|
19863
19971
|
visit3(root);
|
|
19864
19972
|
if (candidates.length === 0)
|
|
@@ -19894,20 +20002,20 @@ function lowerDateCallsInReactiveExpr(expr, matcher) {
|
|
|
19894
20002
|
return expr;
|
|
19895
20003
|
let sourceFile;
|
|
19896
20004
|
try {
|
|
19897
|
-
sourceFile =
|
|
20005
|
+
sourceFile = ts19.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts19.ScriptTarget.Latest, true, ts19.ScriptKind.TS);
|
|
19898
20006
|
} catch {
|
|
19899
20007
|
return expr;
|
|
19900
20008
|
}
|
|
19901
20009
|
const stmt = sourceFile.statements[0];
|
|
19902
|
-
if (!stmt || !
|
|
20010
|
+
if (!stmt || !ts19.isExpressionStatement(stmt))
|
|
19903
20011
|
return expr;
|
|
19904
|
-
const root =
|
|
20012
|
+
const root = ts19.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
19905
20013
|
const candidates = [];
|
|
19906
20014
|
const visit3 = (n) => {
|
|
19907
|
-
if (
|
|
20015
|
+
if (ts19.isCallExpression(n) && n.arguments.length === 0 && ts19.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
|
|
19908
20016
|
candidates.push(n);
|
|
19909
20017
|
}
|
|
19910
|
-
|
|
20018
|
+
ts19.forEachChild(n, visit3);
|
|
19911
20019
|
};
|
|
19912
20020
|
visit3(root);
|
|
19913
20021
|
if (candidates.length === 0)
|
|
@@ -20222,7 +20330,7 @@ function stringifyReactiveEffects(lines, plan, opts) {
|
|
|
20222
20330
|
emitConsolidatedRowEffect(lines, indent, elVar, lookup, attrSlots, outerTexts, elementIndexBySlot, textClaimPathExprs, preambleRegions, mapPreambleWrapped);
|
|
20223
20331
|
}
|
|
20224
20332
|
for (const cond of conditionals) {
|
|
20225
|
-
emitOuterConditional(lines, indent, elVar, cond, pc);
|
|
20333
|
+
emitOuterConditional(lines, indent, elVar, cond, pc, mapPreambleWrapped);
|
|
20226
20334
|
}
|
|
20227
20335
|
}
|
|
20228
20336
|
function emitAttrSlotsGranular(lines, indent, elVar, lookup, attrSlots, elementIndexBySlot, bindingBfId, mapPreambleWrapped) {
|
|
@@ -20324,9 +20432,10 @@ function emitOuterTexts(lines, indent, elVar, texts, bindingBfId, textClaimPathE
|
|
|
20324
20432
|
lines.push(`${indent}createEffect(() => { ${writer}('${text.slotId}', String(${text.wrappedExpression})) }${bindingBfId(text.slotId)})`);
|
|
20325
20433
|
}
|
|
20326
20434
|
}
|
|
20327
|
-
function emitOuterConditional(lines, indent, elVar, cond, pc) {
|
|
20435
|
+
function emitOuterConditional(lines, indent, elVar, cond, pc, mapPreambleWrapped) {
|
|
20328
20436
|
const armIndent = `${indent} `;
|
|
20329
|
-
|
|
20437
|
+
const conditionGetter = cond.readsPreamble && mapPreambleWrapped ? `() => { ${mapPreambleWrapped}; return (${cond.wrappedCondition}) }` : `() => ${cond.wrappedCondition}`;
|
|
20438
|
+
lines.push(`${indent}insert(${elVar}, '${cond.slotId}', ${conditionGetter}, {`);
|
|
20330
20439
|
lines.push(`${indent} template: () => { const __slots = []; return { html: \`${cond.whenTrueTemplateHtml}\`, slots: __slots } },`);
|
|
20331
20440
|
lines.push(`${indent} bindEvents: (__branchScope, { isFirstRun: __bfFirstRun = false } = {}) => {`);
|
|
20332
20441
|
stringifyLoopChildArm(lines, cond.whenTrueArm, armIndent, pc);
|
|
@@ -21910,20 +22019,20 @@ var PHASES = [
|
|
|
21910
22019
|
];
|
|
21911
22020
|
|
|
21912
22021
|
// src/ir-to-client-js/rewrite-props-object.ts
|
|
21913
|
-
import
|
|
22022
|
+
import ts20 from "typescript";
|
|
21914
22023
|
function rewritePropsObjectRef(code, propsObjectName) {
|
|
21915
22024
|
const srcPropsName = propsObjectName ?? "props";
|
|
21916
22025
|
if (srcPropsName === PROPS_PARAM)
|
|
21917
22026
|
return code;
|
|
21918
22027
|
if (!identifierPattern(srcPropsName).test(code))
|
|
21919
22028
|
return code;
|
|
21920
|
-
const sourceFile =
|
|
22029
|
+
const sourceFile = ts20.createSourceFile("init-body.ts", code, ts20.ScriptTarget.Latest, true, ts20.ScriptKind.TS);
|
|
21921
22030
|
const spans = [];
|
|
21922
22031
|
function visit3(node) {
|
|
21923
|
-
if (
|
|
22032
|
+
if (ts20.isIdentifier(node) && node.text === srcPropsName && shouldRewrite(node)) {
|
|
21924
22033
|
spans.push([node.getStart(sourceFile), node.getEnd()]);
|
|
21925
22034
|
}
|
|
21926
|
-
|
|
22035
|
+
ts20.forEachChild(node, visit3);
|
|
21927
22036
|
}
|
|
21928
22037
|
visit3(sourceFile);
|
|
21929
22038
|
if (spans.length === 0)
|
|
@@ -21939,17 +22048,17 @@ function shouldRewrite(node) {
|
|
|
21939
22048
|
const parent = node.parent;
|
|
21940
22049
|
if (!parent)
|
|
21941
22050
|
return true;
|
|
21942
|
-
if (
|
|
22051
|
+
if (ts20.isPropertyAccessExpression(parent) && parent.name === node)
|
|
21943
22052
|
return false;
|
|
21944
|
-
if (
|
|
22053
|
+
if (ts20.isPropertyAssignment(parent) && parent.name === node)
|
|
21945
22054
|
return false;
|
|
21946
|
-
if (
|
|
22055
|
+
if (ts20.isShorthandPropertyAssignment(parent) && parent.name === node)
|
|
21947
22056
|
return false;
|
|
21948
|
-
if (
|
|
22057
|
+
if (ts20.isPropertySignature(parent) && parent.name === node)
|
|
21949
22058
|
return false;
|
|
21950
|
-
if (
|
|
22059
|
+
if (ts20.isPropertyDeclaration(parent) && parent.name === node)
|
|
21951
22060
|
return false;
|
|
21952
|
-
if (
|
|
22061
|
+
if (ts20.isBindingElement(parent) && parent.name === node)
|
|
21953
22062
|
return false;
|
|
21954
22063
|
return true;
|
|
21955
22064
|
}
|
|
@@ -22601,7 +22710,7 @@ function walkIR2(node, visitor) {
|
|
|
22601
22710
|
}
|
|
22602
22711
|
|
|
22603
22712
|
// src/preprocess-inline-jsx-callbacks.ts
|
|
22604
|
-
import
|
|
22713
|
+
import ts21 from "typescript";
|
|
22605
22714
|
var SYNTHETIC_PREFIX = "BFInlineJsxCallback";
|
|
22606
22715
|
var MAX_FIXPOINT_ITERATIONS = 16;
|
|
22607
22716
|
function preprocessInlineJsxCallbacks(source, filePath) {
|
|
@@ -22623,8 +22732,8 @@ function preprocessInlineJsxCallbacks(source, filePath) {
|
|
|
22623
22732
|
return { source: current, errors, syntheticNames };
|
|
22624
22733
|
}
|
|
22625
22734
|
function runSinglePass(source, filePath, startingCounter) {
|
|
22626
|
-
const sourceFile =
|
|
22627
|
-
const hasUseClient = sourceFile.statements.some((stmt) =>
|
|
22735
|
+
const sourceFile = ts21.createSourceFile(filePath, source, ts21.ScriptTarget.Latest, true, ts21.ScriptKind.TSX);
|
|
22736
|
+
const hasUseClient = sourceFile.statements.some((stmt) => ts21.isExpressionStatement(stmt) && ts21.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'"));
|
|
22628
22737
|
if (!hasUseClient) {
|
|
22629
22738
|
return { source, errors: [], syntheticNames: [], counterAfter: startingCounter };
|
|
22630
22739
|
}
|
|
@@ -22646,22 +22755,22 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
22646
22755
|
}
|
|
22647
22756
|
}
|
|
22648
22757
|
function visit3(node) {
|
|
22649
|
-
if (
|
|
22758
|
+
if (ts21.isJsxAttribute(node) && node.initializer && ts21.isJsxExpression(node.initializer) && node.initializer.expression) {
|
|
22650
22759
|
if (tryHandleArrowValue(node.initializer.expression)) {
|
|
22651
22760
|
return;
|
|
22652
22761
|
}
|
|
22653
22762
|
}
|
|
22654
|
-
if (
|
|
22763
|
+
if (ts21.isPropertyAssignment(node) && node.initializer) {
|
|
22655
22764
|
if (tryHandleArrowValue(node.initializer))
|
|
22656
22765
|
return;
|
|
22657
22766
|
}
|
|
22658
|
-
|
|
22767
|
+
ts21.forEachChild(node, visit3);
|
|
22659
22768
|
}
|
|
22660
22769
|
function tryHandleArrowValue(initializer) {
|
|
22661
22770
|
let expr = initializer;
|
|
22662
|
-
while (
|
|
22771
|
+
while (ts21.isParenthesizedExpression(expr))
|
|
22663
22772
|
expr = expr.expression;
|
|
22664
|
-
if (
|
|
22773
|
+
if (ts21.isArrowFunction(expr) && arrowBodyContainsJsx(expr)) {
|
|
22665
22774
|
return handleInlineArrow(expr);
|
|
22666
22775
|
}
|
|
22667
22776
|
return false;
|
|
@@ -22698,7 +22807,7 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
22698
22807
|
replacements.push({ start: arrowStart, end: arrowEnd, text: name });
|
|
22699
22808
|
return true;
|
|
22700
22809
|
}
|
|
22701
|
-
|
|
22810
|
+
ts21.forEachChild(sourceFile, visit3);
|
|
22702
22811
|
if (replacements.length === 0) {
|
|
22703
22812
|
return { source, errors, syntheticNames, counterAfter: counter };
|
|
22704
22813
|
}
|
|
@@ -22721,11 +22830,11 @@ function errorMessageForCapture(captures) {
|
|
|
22721
22830
|
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.`;
|
|
22722
22831
|
}
|
|
22723
22832
|
function arrowBodyContainsJsx(arrow) {
|
|
22724
|
-
if (
|
|
22833
|
+
if (ts21.isBlock(arrow.body)) {
|
|
22725
22834
|
return blockReturnsJsx(arrow.body);
|
|
22726
22835
|
}
|
|
22727
22836
|
let body = arrow.body;
|
|
22728
|
-
while (
|
|
22837
|
+
while (ts21.isParenthesizedExpression(body))
|
|
22729
22838
|
body = body.expression;
|
|
22730
22839
|
return isJsxLike(body);
|
|
22731
22840
|
}
|
|
@@ -22734,24 +22843,24 @@ function blockReturnsJsx(block) {
|
|
|
22734
22843
|
function visit3(n) {
|
|
22735
22844
|
if (found)
|
|
22736
22845
|
return;
|
|
22737
|
-
if (
|
|
22846
|
+
if (ts21.isReturnStatement(n) && n.expression) {
|
|
22738
22847
|
let e = n.expression;
|
|
22739
|
-
while (
|
|
22848
|
+
while (ts21.isParenthesizedExpression(e))
|
|
22740
22849
|
e = e.expression;
|
|
22741
22850
|
if (isJsxLike(e)) {
|
|
22742
22851
|
found = true;
|
|
22743
22852
|
return;
|
|
22744
22853
|
}
|
|
22745
22854
|
}
|
|
22746
|
-
if (
|
|
22855
|
+
if (ts21.isArrowFunction(n) || ts21.isFunctionDeclaration(n) || ts21.isFunctionExpression(n))
|
|
22747
22856
|
return;
|
|
22748
|
-
|
|
22857
|
+
ts21.forEachChild(n, visit3);
|
|
22749
22858
|
}
|
|
22750
|
-
|
|
22859
|
+
ts21.forEachChild(block, visit3);
|
|
22751
22860
|
return found;
|
|
22752
22861
|
}
|
|
22753
22862
|
function isJsxLike(expr) {
|
|
22754
|
-
return
|
|
22863
|
+
return ts21.isJsxElement(expr) || ts21.isJsxSelfClosingElement(expr) || ts21.isJsxFragment(expr);
|
|
22755
22864
|
}
|
|
22756
22865
|
function collectArrowParamNames(arrow) {
|
|
22757
22866
|
const names = new Set;
|
|
@@ -22761,13 +22870,13 @@ function collectArrowParamNames(arrow) {
|
|
|
22761
22870
|
}
|
|
22762
22871
|
function collectBindingNames4(name, out) {
|
|
22763
22872
|
const push = Array.isArray(out) ? (n) => out.push(n) : (n) => out.add(n);
|
|
22764
|
-
if (
|
|
22873
|
+
if (ts21.isIdentifier(name)) {
|
|
22765
22874
|
push(name.text);
|
|
22766
|
-
} else if (
|
|
22875
|
+
} else if (ts21.isObjectBindingPattern(name)) {
|
|
22767
22876
|
name.elements.forEach((el) => collectBindingNames4(el.name, out));
|
|
22768
|
-
} else if (
|
|
22877
|
+
} else if (ts21.isArrayBindingPattern(name)) {
|
|
22769
22878
|
name.elements.forEach((el) => {
|
|
22770
|
-
if (!
|
|
22879
|
+
if (!ts21.isOmittedExpression(el))
|
|
22771
22880
|
collectBindingNames4(el.name, out);
|
|
22772
22881
|
});
|
|
22773
22882
|
}
|
|
@@ -22794,48 +22903,48 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22794
22903
|
return bound.includes(name);
|
|
22795
22904
|
}
|
|
22796
22905
|
function visit3(node) {
|
|
22797
|
-
if (
|
|
22906
|
+
if (ts21.isIdentifier(node)) {
|
|
22798
22907
|
const parent = node.parent;
|
|
22799
|
-
if (parent &&
|
|
22908
|
+
if (parent && ts21.isPropertyAccessExpression(parent) && parent.name === node)
|
|
22800
22909
|
return;
|
|
22801
|
-
if (parent &&
|
|
22910
|
+
if (parent && ts21.isPropertyAssignment(parent) && parent.name === node)
|
|
22802
22911
|
return;
|
|
22803
|
-
if (parent &&
|
|
22912
|
+
if (parent && ts21.isPropertySignature(parent) && parent.name === node)
|
|
22804
22913
|
return;
|
|
22805
|
-
if (parent &&
|
|
22914
|
+
if (parent && ts21.isPropertyDeclaration(parent) && parent.name === node)
|
|
22806
22915
|
return;
|
|
22807
|
-
if (parent &&
|
|
22916
|
+
if (parent && ts21.isMethodDeclaration(parent) && parent.name === node)
|
|
22808
22917
|
return;
|
|
22809
|
-
if (parent &&
|
|
22918
|
+
if (parent && ts21.isMethodSignature(parent) && parent.name === node)
|
|
22810
22919
|
return;
|
|
22811
|
-
if (parent &&
|
|
22920
|
+
if (parent && ts21.isGetAccessorDeclaration(parent) && parent.name === node)
|
|
22812
22921
|
return;
|
|
22813
|
-
if (parent &&
|
|
22922
|
+
if (parent && ts21.isSetAccessorDeclaration(parent) && parent.name === node)
|
|
22814
22923
|
return;
|
|
22815
|
-
if (parent &&
|
|
22924
|
+
if (parent && ts21.isEnumMember(parent) && parent.name === node)
|
|
22816
22925
|
return;
|
|
22817
|
-
if (parent &&
|
|
22926
|
+
if (parent && ts21.isBindingElement(parent) && parent.propertyName === node)
|
|
22818
22927
|
return;
|
|
22819
|
-
if (parent &&
|
|
22928
|
+
if (parent && ts21.isShorthandPropertyAssignment(parent) && parent.name === node) {
|
|
22820
22929
|
if (!isBound(node.text))
|
|
22821
22930
|
ids.add(node.text);
|
|
22822
22931
|
return;
|
|
22823
22932
|
}
|
|
22824
|
-
if (parent &&
|
|
22933
|
+
if (parent && ts21.isParameter(parent) && parent.name === node)
|
|
22825
22934
|
return;
|
|
22826
|
-
if (parent &&
|
|
22935
|
+
if (parent && ts21.isVariableDeclaration(parent) && parent.name === node)
|
|
22827
22936
|
return;
|
|
22828
|
-
if (parent &&
|
|
22937
|
+
if (parent && ts21.isFunctionDeclaration(parent) && parent.name === node)
|
|
22829
22938
|
return;
|
|
22830
|
-
if (parent &&
|
|
22939
|
+
if (parent && ts21.isClassDeclaration(parent) && parent.name === node)
|
|
22831
22940
|
return;
|
|
22832
|
-
if (parent &&
|
|
22941
|
+
if (parent && ts21.isJsxAttribute(parent) && parent.name === node)
|
|
22833
22942
|
return;
|
|
22834
|
-
if (parent &&
|
|
22943
|
+
if (parent && ts21.isJsxOpeningElement(parent) && parent.tagName === node) {
|
|
22835
22944
|
if (/^[a-z]/.test(node.text))
|
|
22836
22945
|
return;
|
|
22837
22946
|
}
|
|
22838
|
-
if (parent &&
|
|
22947
|
+
if (parent && ts21.isJsxClosingElement(parent) && parent.tagName === node) {
|
|
22839
22948
|
if (/^[a-z]/.test(node.text))
|
|
22840
22949
|
return;
|
|
22841
22950
|
}
|
|
@@ -22844,43 +22953,43 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22844
22953
|
ids.add(node.text);
|
|
22845
22954
|
return;
|
|
22846
22955
|
}
|
|
22847
|
-
if (
|
|
22956
|
+
if (ts21.isVariableDeclaration(node)) {
|
|
22848
22957
|
const declared = pushBindings(node.name);
|
|
22849
22958
|
if (node.initializer)
|
|
22850
22959
|
visit3(node.initializer);
|
|
22851
22960
|
return;
|
|
22852
22961
|
}
|
|
22853
|
-
if (
|
|
22962
|
+
if (ts21.isFunctionDeclaration(node)) {
|
|
22854
22963
|
if (node.name)
|
|
22855
22964
|
bound.push(node.name.text);
|
|
22856
22965
|
visitInsideNewScope(node);
|
|
22857
22966
|
return;
|
|
22858
22967
|
}
|
|
22859
|
-
if (
|
|
22968
|
+
if (ts21.isClassDeclaration(node)) {
|
|
22860
22969
|
if (node.name)
|
|
22861
22970
|
bound.push(node.name.text);
|
|
22862
|
-
|
|
22971
|
+
ts21.forEachChild(node, visit3);
|
|
22863
22972
|
return;
|
|
22864
22973
|
}
|
|
22865
|
-
if (
|
|
22974
|
+
if (ts21.isArrowFunction(node) || ts21.isFunctionExpression(node)) {
|
|
22866
22975
|
visitInsideNewScope(node);
|
|
22867
22976
|
return;
|
|
22868
22977
|
}
|
|
22869
|
-
if (
|
|
22978
|
+
if (ts21.isCatchClause(node)) {
|
|
22870
22979
|
const before = bound.length;
|
|
22871
22980
|
if (node.variableDeclaration)
|
|
22872
22981
|
pushBindings(node.variableDeclaration.name);
|
|
22873
|
-
|
|
22982
|
+
ts21.forEachChild(node, visit3);
|
|
22874
22983
|
popN(bound.length - before);
|
|
22875
22984
|
return;
|
|
22876
22985
|
}
|
|
22877
|
-
if (
|
|
22986
|
+
if (ts21.isBlock(node)) {
|
|
22878
22987
|
const before = bound.length;
|
|
22879
|
-
|
|
22988
|
+
ts21.forEachChild(node, visit3);
|
|
22880
22989
|
popN(bound.length - before);
|
|
22881
22990
|
return;
|
|
22882
22991
|
}
|
|
22883
|
-
|
|
22992
|
+
ts21.forEachChild(node, visit3);
|
|
22884
22993
|
}
|
|
22885
22994
|
function visitInsideNewScope(fn) {
|
|
22886
22995
|
const before = bound.length;
|
|
@@ -22903,29 +23012,29 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22903
23012
|
function collectModuleScopeNames(sourceFile) {
|
|
22904
23013
|
const names = new Set;
|
|
22905
23014
|
for (const stmt of sourceFile.statements) {
|
|
22906
|
-
if (
|
|
23015
|
+
if (ts21.isFunctionDeclaration(stmt) && stmt.name)
|
|
22907
23016
|
names.add(stmt.name.text);
|
|
22908
|
-
else if (
|
|
23017
|
+
else if (ts21.isClassDeclaration(stmt) && stmt.name)
|
|
22909
23018
|
names.add(stmt.name.text);
|
|
22910
|
-
else if (
|
|
23019
|
+
else if (ts21.isVariableStatement(stmt)) {
|
|
22911
23020
|
for (const decl of stmt.declarationList.declarations)
|
|
22912
23021
|
collectBindingNames4(decl.name, names);
|
|
22913
|
-
} else if (
|
|
23022
|
+
} else if (ts21.isImportDeclaration(stmt) && stmt.importClause) {
|
|
22914
23023
|
const ic = stmt.importClause;
|
|
22915
23024
|
if (ic.name)
|
|
22916
23025
|
names.add(ic.name.text);
|
|
22917
23026
|
if (ic.namedBindings) {
|
|
22918
|
-
if (
|
|
23027
|
+
if (ts21.isNamespaceImport(ic.namedBindings))
|
|
22919
23028
|
names.add(ic.namedBindings.name.text);
|
|
22920
23029
|
else
|
|
22921
23030
|
for (const e of ic.namedBindings.elements)
|
|
22922
23031
|
names.add(e.name.text);
|
|
22923
23032
|
}
|
|
22924
|
-
} else if (
|
|
23033
|
+
} else if (ts21.isTypeAliasDeclaration(stmt))
|
|
22925
23034
|
names.add(stmt.name.text);
|
|
22926
|
-
else if (
|
|
23035
|
+
else if (ts21.isInterfaceDeclaration(stmt))
|
|
22927
23036
|
names.add(stmt.name.text);
|
|
22928
|
-
else if (
|
|
23037
|
+
else if (ts21.isEnumDeclaration(stmt))
|
|
22929
23038
|
names.add(stmt.name.text);
|
|
22930
23039
|
}
|
|
22931
23040
|
return names;
|
|
@@ -22933,7 +23042,7 @@ function collectModuleScopeNames(sourceFile) {
|
|
|
22933
23042
|
function buildSyntheticDeclaration(name, arrow, sourceFile) {
|
|
22934
23043
|
const paramsText = arrow.parameters.length === 0 ? "" : arrow.parameters.map((p) => p.getText(sourceFile)).join(", ");
|
|
22935
23044
|
let bodyText;
|
|
22936
|
-
if (
|
|
23045
|
+
if (ts21.isBlock(arrow.body)) {
|
|
22937
23046
|
bodyText = arrow.body.getText(sourceFile);
|
|
22938
23047
|
} else {
|
|
22939
23048
|
const expr = arrow.body.getText(sourceFile);
|
|
@@ -22943,7 +23052,7 @@ function buildSyntheticDeclaration(name, arrow, sourceFile) {
|
|
|
22943
23052
|
}
|
|
22944
23053
|
|
|
22945
23054
|
// src/ssr-defaults.ts
|
|
22946
|
-
import
|
|
23055
|
+
import ts22 from "typescript";
|
|
22947
23056
|
function deriveStashFromDefaults(defaults, props) {
|
|
22948
23057
|
const extra = {};
|
|
22949
23058
|
for (const [name, d] of Object.entries(defaults)) {
|
|
@@ -23039,11 +23148,11 @@ function collectPropRefs(expr, propsObjectName, out) {
|
|
|
23039
23148
|
if (!node)
|
|
23040
23149
|
return;
|
|
23041
23150
|
const visit3 = (n) => {
|
|
23042
|
-
if (
|
|
23151
|
+
if (ts22.isPropertyAccessExpression(n) && ts22.isIdentifier(n.expression) && n.expression.text === propsObjectName && ts22.isIdentifier(n.name)) {
|
|
23043
23152
|
out.add(n.name.text);
|
|
23044
23153
|
return;
|
|
23045
23154
|
}
|
|
23046
|
-
|
|
23155
|
+
ts22.forEachChild(n, visit3);
|
|
23047
23156
|
};
|
|
23048
23157
|
visit3(node);
|
|
23049
23158
|
}
|
|
@@ -23064,23 +23173,23 @@ function tryStaticEval(expr, ctx) {
|
|
|
23064
23173
|
}
|
|
23065
23174
|
function evalStatementsForReturn(statements, ctx) {
|
|
23066
23175
|
for (const stmt of statements) {
|
|
23067
|
-
if (
|
|
23176
|
+
if (ts22.isVariableStatement(stmt)) {
|
|
23068
23177
|
for (const d of stmt.declarationList.declarations) {
|
|
23069
|
-
if (!
|
|
23178
|
+
if (!ts22.isIdentifier(d.name) || !d.initializer)
|
|
23070
23179
|
continue;
|
|
23071
23180
|
const v = evalNode(d.initializer, ctx);
|
|
23072
23181
|
if (v !== UNRESOLVED)
|
|
23073
23182
|
ctx.bindings[d.name.text] = v;
|
|
23074
23183
|
}
|
|
23075
|
-
} else if (
|
|
23184
|
+
} else if (ts22.isReturnStatement(stmt)) {
|
|
23076
23185
|
return stmt.expression ? evalNode(stmt.expression, ctx) : UNRESOLVED;
|
|
23077
|
-
} else if (
|
|
23186
|
+
} else if (ts22.isIfStatement(stmt)) {
|
|
23078
23187
|
const cond = evalNode(stmt.expression, ctx);
|
|
23079
23188
|
if (cond === UNRESOLVED)
|
|
23080
23189
|
return UNRESOLVED;
|
|
23081
23190
|
const branch = cond ? stmt.thenStatement : stmt.elseStatement;
|
|
23082
23191
|
if (branch) {
|
|
23083
|
-
const taken = evalStatementsForReturn(
|
|
23192
|
+
const taken = evalStatementsForReturn(ts22.isBlock(branch) ? branch.statements : [branch], ctx);
|
|
23084
23193
|
if (taken !== NO_RETURN)
|
|
23085
23194
|
return taken;
|
|
23086
23195
|
}
|
|
@@ -23091,45 +23200,45 @@ function evalStatementsForReturn(statements, ctx) {
|
|
|
23091
23200
|
return NO_RETURN;
|
|
23092
23201
|
}
|
|
23093
23202
|
function parseExpression2(expr) {
|
|
23094
|
-
const sf =
|
|
23203
|
+
const sf = ts22.createSourceFile("__ssr_default__.ts", `(${expr})`, ts22.ScriptTarget.Latest, false, ts22.ScriptKind.TS);
|
|
23095
23204
|
const stmt = sf.statements[0];
|
|
23096
|
-
if (!stmt || !
|
|
23205
|
+
if (!stmt || !ts22.isExpressionStatement(stmt))
|
|
23097
23206
|
return null;
|
|
23098
|
-
const inner =
|
|
23207
|
+
const inner = ts22.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
23099
23208
|
return inner;
|
|
23100
23209
|
}
|
|
23101
23210
|
function evalNode(node, ctx) {
|
|
23102
|
-
if (
|
|
23211
|
+
if (ts22.isParenthesizedExpression(node))
|
|
23103
23212
|
return evalNode(node.expression, ctx);
|
|
23104
|
-
if (
|
|
23213
|
+
if (ts22.isAsExpression(node))
|
|
23105
23214
|
return evalNode(node.expression, ctx);
|
|
23106
|
-
if (
|
|
23215
|
+
if (ts22.isSatisfiesExpression(node))
|
|
23107
23216
|
return evalNode(node.expression, ctx);
|
|
23108
|
-
if (
|
|
23217
|
+
if (ts22.isTypeAssertionExpression(node))
|
|
23109
23218
|
return evalNode(node.expression, ctx);
|
|
23110
|
-
if (
|
|
23219
|
+
if (ts22.isNonNullExpression(node))
|
|
23111
23220
|
return evalNode(node.expression, ctx);
|
|
23112
|
-
if (
|
|
23221
|
+
if (ts22.isArrowFunction(node)) {
|
|
23113
23222
|
if (node.parameters.length !== 0)
|
|
23114
23223
|
return UNRESOLVED;
|
|
23115
|
-
if (!
|
|
23224
|
+
if (!ts22.isBlock(node.body))
|
|
23116
23225
|
return evalNode(node.body, ctx);
|
|
23117
23226
|
const localBindings = { ...ctx.bindings };
|
|
23118
23227
|
const localCtx = { ...ctx, bindings: localBindings };
|
|
23119
23228
|
const result = evalStatementsForReturn(node.body.statements, localCtx);
|
|
23120
23229
|
return result === NO_RETURN ? UNRESOLVED : result;
|
|
23121
23230
|
}
|
|
23122
|
-
if (
|
|
23231
|
+
if (ts22.isNumericLiteral(node))
|
|
23123
23232
|
return Number(node.text);
|
|
23124
|
-
if (
|
|
23233
|
+
if (ts22.isStringLiteralLike(node))
|
|
23125
23234
|
return node.text;
|
|
23126
|
-
if (node.kind ===
|
|
23235
|
+
if (node.kind === ts22.SyntaxKind.TrueKeyword)
|
|
23127
23236
|
return true;
|
|
23128
|
-
if (node.kind ===
|
|
23237
|
+
if (node.kind === ts22.SyntaxKind.FalseKeyword)
|
|
23129
23238
|
return false;
|
|
23130
|
-
if (node.kind ===
|
|
23239
|
+
if (node.kind === ts22.SyntaxKind.NullKeyword)
|
|
23131
23240
|
return null;
|
|
23132
|
-
if (
|
|
23241
|
+
if (ts22.isIdentifier(node)) {
|
|
23133
23242
|
if (node.text === "undefined")
|
|
23134
23243
|
return;
|
|
23135
23244
|
if (node.text in ctx.bindings)
|
|
@@ -23138,29 +23247,29 @@ function evalNode(node, ctx) {
|
|
|
23138
23247
|
return;
|
|
23139
23248
|
return UNRESOLVED;
|
|
23140
23249
|
}
|
|
23141
|
-
if (
|
|
23250
|
+
if (ts22.isPrefixUnaryExpression(node)) {
|
|
23142
23251
|
const arg = evalNode(node.operand, ctx);
|
|
23143
23252
|
if (arg === UNRESOLVED)
|
|
23144
23253
|
return UNRESOLVED;
|
|
23145
23254
|
switch (node.operator) {
|
|
23146
|
-
case
|
|
23255
|
+
case ts22.SyntaxKind.MinusToken:
|
|
23147
23256
|
return typeof arg === "number" ? -arg : UNRESOLVED;
|
|
23148
|
-
case
|
|
23257
|
+
case ts22.SyntaxKind.PlusToken:
|
|
23149
23258
|
return typeof arg === "number" ? +arg : UNRESOLVED;
|
|
23150
|
-
case
|
|
23259
|
+
case ts22.SyntaxKind.ExclamationToken:
|
|
23151
23260
|
return !arg;
|
|
23152
23261
|
}
|
|
23153
23262
|
return UNRESOLVED;
|
|
23154
23263
|
}
|
|
23155
|
-
if (
|
|
23264
|
+
if (ts22.isObjectLiteralExpression(node)) {
|
|
23156
23265
|
const obj = {};
|
|
23157
23266
|
for (const prop of node.properties) {
|
|
23158
|
-
if (!
|
|
23267
|
+
if (!ts22.isPropertyAssignment(prop))
|
|
23159
23268
|
return UNRESOLVED;
|
|
23160
23269
|
let key;
|
|
23161
|
-
if (
|
|
23270
|
+
if (ts22.isIdentifier(prop.name) || ts22.isStringLiteralLike(prop.name)) {
|
|
23162
23271
|
key = prop.name.text;
|
|
23163
|
-
} else if (
|
|
23272
|
+
} else if (ts22.isNumericLiteral(prop.name)) {
|
|
23164
23273
|
key = prop.name.text;
|
|
23165
23274
|
} else {
|
|
23166
23275
|
return UNRESOLVED;
|
|
@@ -23172,10 +23281,10 @@ function evalNode(node, ctx) {
|
|
|
23172
23281
|
}
|
|
23173
23282
|
return obj;
|
|
23174
23283
|
}
|
|
23175
|
-
if (
|
|
23284
|
+
if (ts22.isArrayLiteralExpression(node)) {
|
|
23176
23285
|
const arr = [];
|
|
23177
23286
|
for (const elem of node.elements) {
|
|
23178
|
-
if (
|
|
23287
|
+
if (ts22.isOmittedExpression(elem))
|
|
23179
23288
|
return UNRESOLVED;
|
|
23180
23289
|
const v = evalNode(elem, ctx);
|
|
23181
23290
|
if (v === UNRESOLVED)
|
|
@@ -23184,7 +23293,7 @@ function evalNode(node, ctx) {
|
|
|
23184
23293
|
}
|
|
23185
23294
|
return arr;
|
|
23186
23295
|
}
|
|
23187
|
-
if (
|
|
23296
|
+
if (ts22.isElementAccessExpression(node)) {
|
|
23188
23297
|
const base = evalNode(node.expression, ctx);
|
|
23189
23298
|
if (base === undefined)
|
|
23190
23299
|
return;
|
|
@@ -23198,17 +23307,17 @@ function evalNode(node, ctx) {
|
|
|
23198
23307
|
const k = String(key);
|
|
23199
23308
|
return Object.prototype.hasOwnProperty.call(base, k) ? base[k] : undefined;
|
|
23200
23309
|
}
|
|
23201
|
-
if (
|
|
23310
|
+
if (ts22.isPropertyAccessExpression(node)) {
|
|
23202
23311
|
const baseResult = evalNode(node.expression, ctx);
|
|
23203
23312
|
if (baseResult === undefined)
|
|
23204
23313
|
return;
|
|
23205
23314
|
return UNRESOLVED;
|
|
23206
23315
|
}
|
|
23207
|
-
if (
|
|
23208
|
-
if (node.arguments.length === 0 &&
|
|
23316
|
+
if (ts22.isCallExpression(node)) {
|
|
23317
|
+
if (node.arguments.length === 0 && ts22.isIdentifier(node.expression) && node.expression.text in ctx.bindings) {
|
|
23209
23318
|
return ctx.bindings[node.expression.text];
|
|
23210
23319
|
}
|
|
23211
|
-
if (
|
|
23320
|
+
if (ts22.isPropertyAccessExpression(node.expression) && node.expression.name.text === "join") {
|
|
23212
23321
|
const recv = evalNode(node.expression.expression, ctx);
|
|
23213
23322
|
if (Array.isArray(recv)) {
|
|
23214
23323
|
let sep2 = ",";
|
|
@@ -23224,27 +23333,27 @@ function evalNode(node, ctx) {
|
|
|
23224
23333
|
}
|
|
23225
23334
|
return UNRESOLVED;
|
|
23226
23335
|
}
|
|
23227
|
-
if (
|
|
23336
|
+
if (ts22.isConditionalExpression(node)) {
|
|
23228
23337
|
const cond = evalNode(node.condition, ctx);
|
|
23229
23338
|
if (cond === UNRESOLVED)
|
|
23230
23339
|
return UNRESOLVED;
|
|
23231
23340
|
return cond ? evalNode(node.whenTrue, ctx) : evalNode(node.whenFalse, ctx);
|
|
23232
23341
|
}
|
|
23233
|
-
if (
|
|
23342
|
+
if (ts22.isBinaryExpression(node)) {
|
|
23234
23343
|
const op = node.operatorToken.kind;
|
|
23235
|
-
if (op ===
|
|
23344
|
+
if (op === ts22.SyntaxKind.QuestionQuestionToken) {
|
|
23236
23345
|
const l2 = evalNode(node.left, ctx);
|
|
23237
23346
|
if (l2 !== UNRESOLVED && l2 !== null && l2 !== undefined)
|
|
23238
23347
|
return l2;
|
|
23239
23348
|
return evalNode(node.right, ctx);
|
|
23240
23349
|
}
|
|
23241
|
-
if (op ===
|
|
23350
|
+
if (op === ts22.SyntaxKind.BarBarToken) {
|
|
23242
23351
|
const l2 = evalNode(node.left, ctx);
|
|
23243
23352
|
if (l2 !== UNRESOLVED && l2)
|
|
23244
23353
|
return l2;
|
|
23245
23354
|
return evalNode(node.right, ctx);
|
|
23246
23355
|
}
|
|
23247
|
-
if (op ===
|
|
23356
|
+
if (op === ts22.SyntaxKind.AmpersandAmpersandToken) {
|
|
23248
23357
|
const l2 = evalNode(node.left, ctx);
|
|
23249
23358
|
if (l2 === UNRESOLVED)
|
|
23250
23359
|
return UNRESOLVED;
|
|
@@ -23257,30 +23366,30 @@ function evalNode(node, ctx) {
|
|
|
23257
23366
|
if (l === UNRESOLVED || r === UNRESOLVED)
|
|
23258
23367
|
return UNRESOLVED;
|
|
23259
23368
|
switch (op) {
|
|
23260
|
-
case
|
|
23369
|
+
case ts22.SyntaxKind.PlusToken:
|
|
23261
23370
|
if (typeof l === "string" || typeof r === "string")
|
|
23262
23371
|
return `${l}${r}`;
|
|
23263
23372
|
if (typeof l === "number" && typeof r === "number")
|
|
23264
23373
|
return l + r;
|
|
23265
23374
|
return UNRESOLVED;
|
|
23266
|
-
case
|
|
23375
|
+
case ts22.SyntaxKind.MinusToken:
|
|
23267
23376
|
return typeof l === "number" && typeof r === "number" ? l - r : UNRESOLVED;
|
|
23268
|
-
case
|
|
23377
|
+
case ts22.SyntaxKind.AsteriskToken:
|
|
23269
23378
|
return typeof l === "number" && typeof r === "number" ? l * r : UNRESOLVED;
|
|
23270
|
-
case
|
|
23379
|
+
case ts22.SyntaxKind.SlashToken:
|
|
23271
23380
|
return typeof l === "number" && typeof r === "number" && r !== 0 ? l / r : UNRESOLVED;
|
|
23272
|
-
case
|
|
23381
|
+
case ts22.SyntaxKind.PercentToken:
|
|
23273
23382
|
return typeof l === "number" && typeof r === "number" && r !== 0 ? l % r : UNRESOLVED;
|
|
23274
|
-
case
|
|
23275
|
-
case
|
|
23383
|
+
case ts22.SyntaxKind.EqualsEqualsEqualsToken:
|
|
23384
|
+
case ts22.SyntaxKind.EqualsEqualsToken:
|
|
23276
23385
|
return l === r;
|
|
23277
|
-
case
|
|
23278
|
-
case
|
|
23386
|
+
case ts22.SyntaxKind.ExclamationEqualsEqualsToken:
|
|
23387
|
+
case ts22.SyntaxKind.ExclamationEqualsToken:
|
|
23279
23388
|
return l !== r;
|
|
23280
23389
|
}
|
|
23281
23390
|
return UNRESOLVED;
|
|
23282
23391
|
}
|
|
23283
|
-
if (
|
|
23392
|
+
if (ts22.isTemplateExpression(node)) {
|
|
23284
23393
|
if (node.templateSpans.length === 0)
|
|
23285
23394
|
return node.head.text;
|
|
23286
23395
|
let acc = node.head.text;
|
|
@@ -23292,13 +23401,13 @@ function evalNode(node, ctx) {
|
|
|
23292
23401
|
}
|
|
23293
23402
|
return acc;
|
|
23294
23403
|
}
|
|
23295
|
-
if (
|
|
23404
|
+
if (ts22.isNoSubstitutionTemplateLiteral(node))
|
|
23296
23405
|
return node.text;
|
|
23297
23406
|
return UNRESOLVED;
|
|
23298
23407
|
}
|
|
23299
23408
|
|
|
23300
23409
|
// src/augment-inherited-props.ts
|
|
23301
|
-
import
|
|
23410
|
+
import ts23 from "typescript";
|
|
23302
23411
|
function collectContextConsumers(metadata) {
|
|
23303
23412
|
const constants = metadata.localConstants ?? [];
|
|
23304
23413
|
const contextDefaults = new Map;
|
|
@@ -23330,47 +23439,47 @@ function collectContextConsumers(metadata) {
|
|
|
23330
23439
|
}
|
|
23331
23440
|
function parseUseContextArg(source) {
|
|
23332
23441
|
const expr = parseSingleExpression(source);
|
|
23333
|
-
if (!expr || !
|
|
23442
|
+
if (!expr || !ts23.isCallExpression(expr))
|
|
23334
23443
|
return null;
|
|
23335
|
-
if (!
|
|
23444
|
+
if (!ts23.isIdentifier(expr.expression) || expr.expression.text !== "useContext")
|
|
23336
23445
|
return null;
|
|
23337
23446
|
if (expr.arguments.length !== 1)
|
|
23338
23447
|
return null;
|
|
23339
23448
|
const arg = expr.arguments[0];
|
|
23340
|
-
return
|
|
23449
|
+
return ts23.isIdentifier(arg) ? arg.text : null;
|
|
23341
23450
|
}
|
|
23342
23451
|
function parseCreateContextDefault(source) {
|
|
23343
23452
|
const expr = parseSingleExpression(source);
|
|
23344
|
-
if (!expr || !
|
|
23453
|
+
if (!expr || !ts23.isCallExpression(expr))
|
|
23345
23454
|
return null;
|
|
23346
23455
|
if (expr.arguments.length === 0)
|
|
23347
23456
|
return null;
|
|
23348
23457
|
const arg = expr.arguments[0];
|
|
23349
|
-
if (
|
|
23458
|
+
if (ts23.isStringLiteral(arg) || ts23.isNoSubstitutionTemplateLiteral(arg))
|
|
23350
23459
|
return arg.text;
|
|
23351
|
-
if (
|
|
23460
|
+
if (ts23.isNumericLiteral(arg))
|
|
23352
23461
|
return Number(arg.text);
|
|
23353
|
-
if (arg.kind ===
|
|
23462
|
+
if (arg.kind === ts23.SyntaxKind.TrueKeyword)
|
|
23354
23463
|
return true;
|
|
23355
|
-
if (arg.kind ===
|
|
23464
|
+
if (arg.kind === ts23.SyntaxKind.FalseKeyword)
|
|
23356
23465
|
return false;
|
|
23357
23466
|
return null;
|
|
23358
23467
|
}
|
|
23359
23468
|
function isObjectLiteralCreateContextDefault(source) {
|
|
23360
23469
|
const expr = parseSingleExpression(source);
|
|
23361
|
-
if (!expr || !
|
|
23470
|
+
if (!expr || !ts23.isCallExpression(expr))
|
|
23362
23471
|
return false;
|
|
23363
23472
|
if (expr.arguments.length === 0)
|
|
23364
23473
|
return false;
|
|
23365
|
-
return
|
|
23474
|
+
return ts23.isObjectLiteralExpression(expr.arguments[0]);
|
|
23366
23475
|
}
|
|
23367
23476
|
function parseSingleExpression(source) {
|
|
23368
|
-
const sf =
|
|
23477
|
+
const sf = ts23.createSourceFile("__ctx.ts", `(${source})`, ts23.ScriptTarget.Latest, false);
|
|
23369
23478
|
const stmt = sf.statements[0];
|
|
23370
|
-
if (!stmt || !
|
|
23479
|
+
if (!stmt || !ts23.isExpressionStatement(stmt))
|
|
23371
23480
|
return null;
|
|
23372
23481
|
let e = stmt.expression;
|
|
23373
|
-
while (
|
|
23482
|
+
while (ts23.isParenthesizedExpression(e))
|
|
23374
23483
|
e = e.expression;
|
|
23375
23484
|
return e;
|
|
23376
23485
|
}
|
|
@@ -23395,25 +23504,25 @@ function augmentInheritedPropAccesses(ir) {
|
|
|
23395
23504
|
const pinCoalesceLiterals = (s) => {
|
|
23396
23505
|
if (!s || !s.includes(propsObj))
|
|
23397
23506
|
return;
|
|
23398
|
-
const sf =
|
|
23507
|
+
const sf = ts23.createSourceFile("__aug.ts", `(${s})`, ts23.ScriptTarget.Latest, false);
|
|
23399
23508
|
const visit3 = (n) => {
|
|
23400
|
-
if (
|
|
23509
|
+
if (ts23.isBinaryExpression(n) && (n.operatorToken.kind === ts23.SyntaxKind.QuestionQuestionToken || n.operatorToken.kind === ts23.SyntaxKind.BarBarToken)) {
|
|
23401
23510
|
let left = n.left;
|
|
23402
|
-
while (
|
|
23511
|
+
while (ts23.isParenthesizedExpression(left))
|
|
23403
23512
|
left = left.expression;
|
|
23404
|
-
if (
|
|
23513
|
+
if (ts23.isPropertyAccessExpression(left) && ts23.isIdentifier(left.expression) && left.expression.text === propsObj) {
|
|
23405
23514
|
const name = left.name.text;
|
|
23406
23515
|
let right = n.right;
|
|
23407
|
-
while (
|
|
23516
|
+
while (ts23.isParenthesizedExpression(right))
|
|
23408
23517
|
right = right.expression;
|
|
23409
|
-
if (
|
|
23518
|
+
if (ts23.isPrefixUnaryExpression(right))
|
|
23410
23519
|
right = right.operand;
|
|
23411
|
-
const kind =
|
|
23520
|
+
const kind = ts23.isNumericLiteral(right) ? "number" : right.kind === ts23.SyntaxKind.TrueKeyword || right.kind === ts23.SyntaxKind.FalseKeyword ? "boolean" : ts23.isStringLiteralLike(right) ? "string" : null;
|
|
23412
23521
|
if (kind && !coalesceLiteralTypes.has(name))
|
|
23413
23522
|
coalesceLiteralTypes.set(name, kind);
|
|
23414
23523
|
}
|
|
23415
23524
|
}
|
|
23416
|
-
|
|
23525
|
+
ts23.forEachChild(n, visit3);
|
|
23417
23526
|
};
|
|
23418
23527
|
visit3(sf);
|
|
23419
23528
|
};
|
|
@@ -23524,33 +23633,33 @@ function augmentInheritedPropAccesses(ir) {
|
|
|
23524
23633
|
}
|
|
23525
23634
|
}
|
|
23526
23635
|
function parseStaticStringConst(source) {
|
|
23527
|
-
const sf =
|
|
23636
|
+
const sf = ts23.createSourceFile("__const.ts", `const __x = (${source});`, ts23.ScriptTarget.Latest, false);
|
|
23528
23637
|
const stmt = sf.statements[0];
|
|
23529
|
-
if (!stmt || !
|
|
23638
|
+
if (!stmt || !ts23.isVariableStatement(stmt))
|
|
23530
23639
|
return null;
|
|
23531
23640
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
23532
|
-
while (init &&
|
|
23641
|
+
while (init && ts23.isParenthesizedExpression(init))
|
|
23533
23642
|
init = init.expression;
|
|
23534
23643
|
if (!init)
|
|
23535
23644
|
return null;
|
|
23536
|
-
if (
|
|
23645
|
+
if (ts23.isStringLiteral(init) || ts23.isNoSubstitutionTemplateLiteral(init)) {
|
|
23537
23646
|
return init.text;
|
|
23538
23647
|
}
|
|
23539
23648
|
return evalStringArrayJoin(source);
|
|
23540
23649
|
}
|
|
23541
23650
|
function evalTemplateOfStringConsts(source, resolved) {
|
|
23542
|
-
const sf =
|
|
23651
|
+
const sf = ts23.createSourceFile("__const.ts", `const __x = (${source});`, ts23.ScriptTarget.Latest, false);
|
|
23543
23652
|
const stmt = sf.statements[0];
|
|
23544
|
-
if (!stmt || !
|
|
23653
|
+
if (!stmt || !ts23.isVariableStatement(stmt))
|
|
23545
23654
|
return null;
|
|
23546
23655
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
23547
|
-
while (init &&
|
|
23656
|
+
while (init && ts23.isParenthesizedExpression(init))
|
|
23548
23657
|
init = init.expression;
|
|
23549
|
-
if (!init || !
|
|
23658
|
+
if (!init || !ts23.isTemplateExpression(init))
|
|
23550
23659
|
return null;
|
|
23551
23660
|
let out = init.head.text;
|
|
23552
23661
|
for (const span of init.templateSpans) {
|
|
23553
|
-
if (!
|
|
23662
|
+
if (!ts23.isIdentifier(span.expression))
|
|
23554
23663
|
return null;
|
|
23555
23664
|
const value = resolved.get(span.expression.text);
|
|
23556
23665
|
if (value === undefined)
|
|
@@ -23577,34 +23686,36 @@ function collectModuleStringConsts(constants) {
|
|
|
23577
23686
|
}
|
|
23578
23687
|
return map;
|
|
23579
23688
|
}
|
|
23580
|
-
function lookupStaticRecordLiteral(objectName, key, constants) {
|
|
23689
|
+
function lookupStaticRecordLiteral(objectName, key, constants, isShadowed) {
|
|
23690
|
+
if (isShadowed(objectName))
|
|
23691
|
+
return null;
|
|
23581
23692
|
const constInfo = (constants ?? []).find((c) => c.name === objectName && c.isModule);
|
|
23582
23693
|
if (constInfo?.value === undefined)
|
|
23583
23694
|
return null;
|
|
23584
|
-
const sf =
|
|
23695
|
+
const sf = ts23.createSourceFile("__rec.ts", `(${constInfo.value})`, ts23.ScriptTarget.Latest, true);
|
|
23585
23696
|
if (sf.statements.length !== 1)
|
|
23586
23697
|
return null;
|
|
23587
23698
|
const stmt = sf.statements[0];
|
|
23588
|
-
if (!
|
|
23699
|
+
if (!ts23.isExpressionStatement(stmt))
|
|
23589
23700
|
return null;
|
|
23590
23701
|
let parsed = stmt.expression;
|
|
23591
|
-
while (
|
|
23702
|
+
while (ts23.isParenthesizedExpression(parsed))
|
|
23592
23703
|
parsed = parsed.expression;
|
|
23593
|
-
if (!
|
|
23704
|
+
if (!ts23.isObjectLiteralExpression(parsed))
|
|
23594
23705
|
return null;
|
|
23595
23706
|
for (const prop of parsed.properties) {
|
|
23596
|
-
if (!
|
|
23707
|
+
if (!ts23.isPropertyAssignment(prop))
|
|
23597
23708
|
continue;
|
|
23598
23709
|
const name = prop.name;
|
|
23599
|
-
const propKey =
|
|
23710
|
+
const propKey = ts23.isIdentifier(name) || ts23.isStringLiteral(name) || ts23.isNoSubstitutionTemplateLiteral(name) ? name.text : null;
|
|
23600
23711
|
if (propKey !== key)
|
|
23601
23712
|
continue;
|
|
23602
23713
|
let v = prop.initializer;
|
|
23603
|
-
while (
|
|
23714
|
+
while (ts23.isParenthesizedExpression(v))
|
|
23604
23715
|
v = v.expression;
|
|
23605
|
-
if (
|
|
23716
|
+
if (ts23.isNumericLiteral(v))
|
|
23606
23717
|
return { kind: "number", text: v.text };
|
|
23607
|
-
if (
|
|
23718
|
+
if (ts23.isStringLiteral(v) || ts23.isNoSubstitutionTemplateLiteral(v)) {
|
|
23608
23719
|
return { kind: "string", text: v.text };
|
|
23609
23720
|
}
|
|
23610
23721
|
return null;
|
|
@@ -23612,28 +23723,28 @@ function lookupStaticRecordLiteral(objectName, key, constants) {
|
|
|
23612
23723
|
return null;
|
|
23613
23724
|
}
|
|
23614
23725
|
function evalStringArrayJoin(source) {
|
|
23615
|
-
const sf =
|
|
23726
|
+
const sf = ts23.createSourceFile("__join.ts", `const __x = (${source});`, ts23.ScriptTarget.Latest, false);
|
|
23616
23727
|
const stmt = sf.statements[0];
|
|
23617
|
-
if (!stmt || !
|
|
23728
|
+
if (!stmt || !ts23.isVariableStatement(stmt))
|
|
23618
23729
|
return null;
|
|
23619
23730
|
let node = stmt.declarationList.declarations[0]?.initializer;
|
|
23620
|
-
while (node &&
|
|
23731
|
+
while (node && ts23.isParenthesizedExpression(node))
|
|
23621
23732
|
node = node.expression;
|
|
23622
|
-
if (!node || !
|
|
23733
|
+
if (!node || !ts23.isCallExpression(node))
|
|
23623
23734
|
return null;
|
|
23624
23735
|
const callee = node.expression;
|
|
23625
|
-
if (!
|
|
23736
|
+
if (!ts23.isPropertyAccessExpression(callee))
|
|
23626
23737
|
return null;
|
|
23627
23738
|
if (callee.name.text !== "join")
|
|
23628
23739
|
return null;
|
|
23629
23740
|
let recv = callee.expression;
|
|
23630
|
-
while (
|
|
23741
|
+
while (ts23.isParenthesizedExpression(recv))
|
|
23631
23742
|
recv = recv.expression;
|
|
23632
|
-
if (!
|
|
23743
|
+
if (!ts23.isArrayLiteralExpression(recv))
|
|
23633
23744
|
return null;
|
|
23634
23745
|
const parts = [];
|
|
23635
23746
|
for (const el of recv.elements) {
|
|
23636
|
-
if (
|
|
23747
|
+
if (ts23.isStringLiteral(el) || ts23.isNoSubstitutionTemplateLiteral(el)) {
|
|
23637
23748
|
parts.push(el.text);
|
|
23638
23749
|
} else {
|
|
23639
23750
|
return null;
|
|
@@ -23642,7 +23753,7 @@ function evalStringArrayJoin(source) {
|
|
|
23642
23753
|
let sep2 = ",";
|
|
23643
23754
|
if (node.arguments.length >= 1) {
|
|
23644
23755
|
const arg = node.arguments[0];
|
|
23645
|
-
if (
|
|
23756
|
+
if (ts23.isStringLiteral(arg) || ts23.isNoSubstitutionTemplateLiteral(arg))
|
|
23646
23757
|
sep2 = arg.text;
|
|
23647
23758
|
else
|
|
23648
23759
|
return null;
|
|
@@ -23650,11 +23761,11 @@ function evalStringArrayJoin(source) {
|
|
|
23650
23761
|
return parts.join(sep2);
|
|
23651
23762
|
}
|
|
23652
23763
|
function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
|
|
23653
|
-
if (!
|
|
23764
|
+
if (!ts23.isElementAccessExpression(val))
|
|
23654
23765
|
return null;
|
|
23655
23766
|
const obj = val.expression;
|
|
23656
23767
|
const arg = val.argumentExpression;
|
|
23657
|
-
if (!
|
|
23768
|
+
if (!ts23.isIdentifier(obj) || !ts23.isIdentifier(arg))
|
|
23658
23769
|
return null;
|
|
23659
23770
|
let indexPropName;
|
|
23660
23771
|
let defaultKey;
|
|
@@ -23670,35 +23781,35 @@ function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
|
|
|
23670
23781
|
const constInfo = localConstants.find((c) => c.name === obj.text && c.isModule);
|
|
23671
23782
|
if (constInfo?.value === undefined)
|
|
23672
23783
|
return null;
|
|
23673
|
-
const sf =
|
|
23784
|
+
const sf = ts23.createSourceFile("__rec.ts", `(${constInfo.value})`, ts23.ScriptTarget.Latest, true);
|
|
23674
23785
|
if (sf.statements.length !== 1)
|
|
23675
23786
|
return null;
|
|
23676
23787
|
const stmt = sf.statements[0];
|
|
23677
|
-
if (!
|
|
23788
|
+
if (!ts23.isExpressionStatement(stmt))
|
|
23678
23789
|
return null;
|
|
23679
23790
|
let parsed = stmt.expression;
|
|
23680
|
-
while (
|
|
23791
|
+
while (ts23.isParenthesizedExpression(parsed))
|
|
23681
23792
|
parsed = parsed.expression;
|
|
23682
|
-
if (!
|
|
23793
|
+
if (!ts23.isObjectLiteralExpression(parsed))
|
|
23683
23794
|
return null;
|
|
23684
23795
|
const entries = [];
|
|
23685
23796
|
for (const prop of parsed.properties) {
|
|
23686
|
-
if (!
|
|
23797
|
+
if (!ts23.isPropertyAssignment(prop))
|
|
23687
23798
|
return null;
|
|
23688
23799
|
let key;
|
|
23689
|
-
if (
|
|
23800
|
+
if (ts23.isIdentifier(prop.name)) {
|
|
23690
23801
|
key = prop.name.text;
|
|
23691
|
-
} else if (
|
|
23802
|
+
} else if (ts23.isStringLiteral(prop.name) || ts23.isNoSubstitutionTemplateLiteral(prop.name)) {
|
|
23692
23803
|
key = prop.name.text;
|
|
23693
23804
|
} else {
|
|
23694
23805
|
return null;
|
|
23695
23806
|
}
|
|
23696
23807
|
let v = prop.initializer;
|
|
23697
|
-
while (
|
|
23808
|
+
while (ts23.isParenthesizedExpression(v))
|
|
23698
23809
|
v = v.expression;
|
|
23699
|
-
if (
|
|
23810
|
+
if (ts23.isNumericLiteral(v)) {
|
|
23700
23811
|
entries.push({ key, value: { kind: "number", text: v.text } });
|
|
23701
|
-
} else if (
|
|
23812
|
+
} else if (ts23.isStringLiteral(v) || ts23.isNoSubstitutionTemplateLiteral(v)) {
|
|
23702
23813
|
entries.push({ key, value: { kind: "string", text: v.text } });
|
|
23703
23814
|
} else {
|
|
23704
23815
|
return null;
|
|
@@ -24041,13 +24152,13 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
24041
24152
|
if (entries.some((e) => e.componentIR.metadata.isClientComponent)) {
|
|
24042
24153
|
const topLevelNames = new Set;
|
|
24043
24154
|
{
|
|
24044
|
-
const sf =
|
|
24155
|
+
const sf = ts24.createSourceFile(filePath, source, ts24.ScriptTarget.Latest, true, ts24.ScriptKind.TSX);
|
|
24045
24156
|
for (const stmt of sf.statements) {
|
|
24046
|
-
if (
|
|
24157
|
+
if (ts24.isFunctionDeclaration(stmt) && stmt.name)
|
|
24047
24158
|
topLevelNames.add(stmt.name.text);
|
|
24048
|
-
else if (
|
|
24159
|
+
else if (ts24.isVariableStatement(stmt)) {
|
|
24049
24160
|
for (const d of stmt.declarationList.declarations) {
|
|
24050
|
-
if (
|
|
24161
|
+
if (ts24.isIdentifier(d.name))
|
|
24051
24162
|
topLevelNames.add(d.name.text);
|
|
24052
24163
|
}
|
|
24053
24164
|
}
|
|
@@ -24106,7 +24217,7 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
24106
24217
|
const moduleStatementSeen = new Set;
|
|
24107
24218
|
const moduleStatementsOrdered = [];
|
|
24108
24219
|
const collectModuleStatements = (block) => {
|
|
24109
|
-
const sf =
|
|
24220
|
+
const sf = ts24.createSourceFile("__bf_module_decls.tsx", block, ts24.ScriptTarget.Latest, false, ts24.ScriptKind.TSX);
|
|
24110
24221
|
for (const stmt of sf.statements) {
|
|
24111
24222
|
const text = stmt.getText(sf);
|
|
24112
24223
|
if (moduleStatementSeen.has(text))
|
|
@@ -24343,6 +24454,12 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
24343
24454
|
}
|
|
24344
24455
|
return { files, errors };
|
|
24345
24456
|
}
|
|
24457
|
+
function componentTypeParametersText(componentNode, sourceFile) {
|
|
24458
|
+
const typeParameters = componentNode?.typeParameters;
|
|
24459
|
+
if (!typeParameters || typeParameters.length === 0)
|
|
24460
|
+
return null;
|
|
24461
|
+
return `<${typeParameters.map((p) => p.getText(sourceFile)).join(", ")}>`;
|
|
24462
|
+
}
|
|
24346
24463
|
function buildMetadata(ctx) {
|
|
24347
24464
|
const metadata = {
|
|
24348
24465
|
componentName: ctx.componentName || "Unknown",
|
|
@@ -24351,6 +24468,7 @@ function buildMetadata(ctx) {
|
|
|
24351
24468
|
isClientComponent: ctx.hasUseClientDirective,
|
|
24352
24469
|
typeDefinitions: ctx.typeDefinitions,
|
|
24353
24470
|
propsType: ctx.propsType,
|
|
24471
|
+
typeParameters: componentTypeParametersText(ctx.componentNode, ctx.sourceFile),
|
|
24354
24472
|
propsParams: ctx.propsParams,
|
|
24355
24473
|
propsObjectName: ctx.propsObjectName,
|
|
24356
24474
|
restPropsName: ctx.restPropsName,
|
|
@@ -24541,7 +24659,7 @@ function compileJSX(source, filePath, options) {
|
|
|
24541
24659
|
return { files, errors };
|
|
24542
24660
|
}
|
|
24543
24661
|
// src/shared-program.ts
|
|
24544
|
-
import
|
|
24662
|
+
import ts25 from "typescript";
|
|
24545
24663
|
function commonParent(paths) {
|
|
24546
24664
|
if (paths.length === 0)
|
|
24547
24665
|
return process.cwd();
|
|
@@ -24562,10 +24680,10 @@ function commonParent(paths) {
|
|
|
24562
24680
|
function createProgramForCorpus(files, options = {}) {
|
|
24563
24681
|
const baseUrl = options.baseUrl ?? commonParent(files);
|
|
24564
24682
|
const compilerOptions = {
|
|
24565
|
-
target:
|
|
24566
|
-
module:
|
|
24567
|
-
moduleResolution:
|
|
24568
|
-
jsx:
|
|
24683
|
+
target: ts25.ScriptTarget.Latest,
|
|
24684
|
+
module: ts25.ModuleKind.ESNext,
|
|
24685
|
+
moduleResolution: ts25.ModuleResolutionKind.Bundler,
|
|
24686
|
+
jsx: ts25.JsxEmit.ReactJSX,
|
|
24569
24687
|
strict: true,
|
|
24570
24688
|
skipLibCheck: true,
|
|
24571
24689
|
noEmit: true,
|
|
@@ -24575,7 +24693,7 @@ function createProgramForCorpus(files, options = {}) {
|
|
|
24575
24693
|
...options.compilerOptions
|
|
24576
24694
|
};
|
|
24577
24695
|
const absolute = files.map((f) => path_default.resolve(f));
|
|
24578
|
-
return
|
|
24696
|
+
return ts25.createProgram(absolute, compilerOptions, undefined, options.oldProgram);
|
|
24579
24697
|
}
|
|
24580
24698
|
// src/adapters/interface.ts
|
|
24581
24699
|
class BaseAdapter {
|
|
@@ -24630,7 +24748,7 @@ class JsxAdapter extends BaseAdapter {
|
|
|
24630
24748
|
...localFunctions.map((f) => ({ name: f.name, body: f.body })),
|
|
24631
24749
|
...localConstants.map((c) => ({ name: c.name, body: c.value }))
|
|
24632
24750
|
];
|
|
24633
|
-
const reachable =
|
|
24751
|
+
const reachable = closeOverWritersOfMutableBindings(primaryRefText, declarations, new Set(ir.metadata.localConstants.filter((c) => (c.declarationKind ?? "const") !== "const").map((c) => c.name)));
|
|
24634
24752
|
const reachableBodies = [...reachable].map((name) => {
|
|
24635
24753
|
const func = localFunctions.find((f) => f.name === name);
|
|
24636
24754
|
if (func)
|
|
@@ -24662,7 +24780,8 @@ class JsxAdapter extends BaseAdapter {
|
|
|
24662
24780
|
if (signal.setter) {
|
|
24663
24781
|
const setterUsed = identifierPattern(signal.setter).test(setterRefText);
|
|
24664
24782
|
if (setterUsed) {
|
|
24665
|
-
|
|
24783
|
+
const setterType = preserveTypes && signal.type.kind !== "unknown" ? `(valueOrFn: ${signal.type.raw} | ((prev: ${signal.type.raw}) => ${signal.type.raw})) => void` : null;
|
|
24784
|
+
lines.push(setterType ? ` const ${signal.setter}: ${setterType} = () => {}` : ` const ${signal.setter} = (..._args: any[]) => {}`);
|
|
24666
24785
|
}
|
|
24667
24786
|
}
|
|
24668
24787
|
}
|
|
@@ -24858,7 +24977,7 @@ class JsxAdapter extends BaseAdapter {
|
|
|
24858
24977
|
}
|
|
24859
24978
|
|
|
24860
24979
|
// src/adapters/template-imports.ts
|
|
24861
|
-
import
|
|
24980
|
+
import ts26 from "typescript";
|
|
24862
24981
|
var CLIENT_PACKAGE_SOURCES = new Set([
|
|
24863
24982
|
"@barefootjs/client",
|
|
24864
24983
|
"@barefootjs/client/runtime"
|
|
@@ -24908,18 +25027,18 @@ function specKey(s) {
|
|
|
24908
25027
|
function rewriteDynamicImportsInSource(sourceText, rewriteRelative) {
|
|
24909
25028
|
if (!sourceText.includes("import"))
|
|
24910
25029
|
return sourceText;
|
|
24911
|
-
const sf =
|
|
25030
|
+
const sf = ts26.createSourceFile("bf-template-fragment.tsx", sourceText, ts26.ScriptTarget.Latest, false, ts26.ScriptKind.TSX);
|
|
24912
25031
|
const edits = [];
|
|
24913
25032
|
const visit3 = (node) => {
|
|
24914
|
-
if (
|
|
25033
|
+
if (ts26.isCallExpression(node) && node.expression.kind === ts26.SyntaxKind.ImportKeyword && node.arguments.length > 0 && ts26.isStringLiteralLike(node.arguments[0])) {
|
|
24915
25034
|
collect(node.arguments[0]);
|
|
24916
25035
|
}
|
|
24917
|
-
if (
|
|
25036
|
+
if (ts26.isImportTypeNode(node) && ts26.isLiteralTypeNode(node.argument)) {
|
|
24918
25037
|
const literal = node.argument.literal;
|
|
24919
|
-
if (
|
|
25038
|
+
if (ts26.isStringLiteralLike(literal))
|
|
24920
25039
|
collect(literal);
|
|
24921
25040
|
}
|
|
24922
|
-
|
|
25041
|
+
ts26.forEachChild(node, visit3);
|
|
24923
25042
|
};
|
|
24924
25043
|
const collect = (literal) => {
|
|
24925
25044
|
const specifier = literal.text;
|
|
@@ -24934,7 +25053,7 @@ function rewriteDynamicImportsInSource(sourceText, rewriteRelative) {
|
|
|
24934
25053
|
text: `'${next}'`
|
|
24935
25054
|
});
|
|
24936
25055
|
};
|
|
24937
|
-
|
|
25056
|
+
ts26.forEachChild(sf, visit3);
|
|
24938
25057
|
if (edits.length === 0)
|
|
24939
25058
|
return sourceText;
|
|
24940
25059
|
let out = sourceText;
|
|
@@ -25035,7 +25154,8 @@ export default ${this.componentName}` : "";
|
|
|
25035
25154
|
const noArgDefault = hasRequiredProps ? "" : ` = {} as ${propsTypeExpr}`;
|
|
25036
25155
|
const lines = [];
|
|
25037
25156
|
const exportPrefix = ir.metadata.isExported === false ? "" : "export ";
|
|
25038
|
-
|
|
25157
|
+
const typeParameters = ir.metadata.typeParameters ?? "";
|
|
25158
|
+
lines.push(`${exportPrefix}function ${name}${typeParameters}(${fullPropsDestructure}${typeAnnotation}${noArgDefault}) {`);
|
|
25039
25159
|
if (hasClientInteractivity) {
|
|
25040
25160
|
lines.push(` const __scopeId = (/_s\\d/.test(__bfScope || '') ? __bfScope : null) || __instanceId || \`${name}_\${Math.random().toString(36).slice(2, 8)}\``);
|
|
25041
25161
|
} else {
|
|
@@ -25729,7 +25849,7 @@ function dangerousInnerHtmlDiagnostic(expr, loc, reason) {
|
|
|
25729
25849
|
};
|
|
25730
25850
|
}
|
|
25731
25851
|
// src/combine-client-js.ts
|
|
25732
|
-
import
|
|
25852
|
+
import ts27 from "typescript";
|
|
25733
25853
|
var CHILD_PLACEHOLDER_RE = /import '\/\* @bf-child:(\w+) \*\/'/g;
|
|
25734
25854
|
function combineParentChildClientJs(files) {
|
|
25735
25855
|
const result = new Map;
|
|
@@ -25786,10 +25906,10 @@ function combineParentChildClientJs(files) {
|
|
|
25786
25906
|
return result;
|
|
25787
25907
|
}
|
|
25788
25908
|
function parseAndMerge(content, importsBySource, otherImports, codeSections) {
|
|
25789
|
-
const sourceFile =
|
|
25909
|
+
const sourceFile = ts27.createSourceFile("combine.js", content, ts27.ScriptTarget.Latest, false, ts27.ScriptKind.JS);
|
|
25790
25910
|
const importSpans = [];
|
|
25791
25911
|
for (const stmt of sourceFile.statements) {
|
|
25792
|
-
if (!
|
|
25912
|
+
if (!ts27.isImportDeclaration(stmt))
|
|
25793
25913
|
continue;
|
|
25794
25914
|
const start = stmt.getStart(sourceFile);
|
|
25795
25915
|
const end = stmt.getEnd();
|
|
@@ -25799,8 +25919,8 @@ function parseAndMerge(content, importsBySource, otherImports, codeSections) {
|
|
|
25799
25919
|
continue;
|
|
25800
25920
|
const clause = stmt.importClause;
|
|
25801
25921
|
const bindings = clause?.namedBindings;
|
|
25802
|
-
const specifier =
|
|
25803
|
-
if (clause && !clause.name && bindings &&
|
|
25922
|
+
const specifier = ts27.isStringLiteral(stmt.moduleSpecifier) ? stmt.moduleSpecifier.text : "";
|
|
25923
|
+
if (clause && !clause.name && bindings && ts27.isNamedImports(bindings)) {
|
|
25804
25924
|
if (!importsBySource.has(specifier)) {
|
|
25805
25925
|
importsBySource.set(specifier, new Set);
|
|
25806
25926
|
}
|
|
@@ -25967,7 +26087,7 @@ function escapeRe(s) {
|
|
|
25967
26087
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
25968
26088
|
}
|
|
25969
26089
|
// src/debug.ts
|
|
25970
|
-
import
|
|
26090
|
+
import ts28 from "typescript";
|
|
25971
26091
|
function buildComponentGraph(source, filePath, componentName) {
|
|
25972
26092
|
const ctx = analyzeComponent(source, filePath, componentName);
|
|
25973
26093
|
if (!ctx.jsxReturn) {
|
|
@@ -26046,7 +26166,7 @@ function buildGraphFromIR(ir) {
|
|
|
26046
26166
|
return propsObjectName ? exprReadsPropMember(expr, propsObjectName) : false;
|
|
26047
26167
|
};
|
|
26048
26168
|
const domBindings = [];
|
|
26049
|
-
collectDomBindings(ir.root, domBindings, signalGetters, memoNames, undefined,
|
|
26169
|
+
collectDomBindings(ir.root, domBindings, signalGetters, memoNames, undefined, BindingScope.EMPTY, exprReadsProp);
|
|
26050
26170
|
const signalConsumers = new Map;
|
|
26051
26171
|
for (const s of meta.signals)
|
|
26052
26172
|
signalConsumers.set(s.getter, []);
|
|
@@ -27072,15 +27192,22 @@ function inferWrapReasonForAttrLike(hasStringReactive, hasPropsRef, flags) {
|
|
|
27072
27192
|
const decision = decideWrapFromAstFlags(flags);
|
|
27073
27193
|
return decision.wrap ? decision.reason : undefined;
|
|
27074
27194
|
}
|
|
27075
|
-
function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
27076
|
-
const
|
|
27077
|
-
const
|
|
27195
|
+
function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag, scope = BindingScope.EMPTY, readsProp = () => false) {
|
|
27196
|
+
const boundNames = scope.valueBoundNames();
|
|
27197
|
+
const setSomeIn = (names, other) => {
|
|
27198
|
+
for (const n of names)
|
|
27199
|
+
if (other.has(n))
|
|
27200
|
+
return true;
|
|
27201
|
+
return false;
|
|
27202
|
+
};
|
|
27203
|
+
const exprReadsLoopParam = (n) => boundNames.size > 0 && (n.origin?.freeRefs?.some((r) => boundNames.has(r.name)) ?? false);
|
|
27204
|
+
const attrReadsLoopParam = (free) => boundNames.size > 0 && free !== undefined && setSomeIn(boundNames, free);
|
|
27078
27205
|
switch (node.type) {
|
|
27079
27206
|
case "element": {
|
|
27080
27207
|
for (const attr of node.attrs) {
|
|
27081
27208
|
if (attr.value.kind !== "expression" && attr.value.kind !== "template" && attr.value.kind !== "spread")
|
|
27082
27209
|
continue;
|
|
27083
|
-
if (attr.name === "key" &&
|
|
27210
|
+
if (attr.name === "key" && boundNames.size > 0)
|
|
27084
27211
|
continue;
|
|
27085
27212
|
const expr = attrValueToString2(attr.value);
|
|
27086
27213
|
if (!expr)
|
|
@@ -27117,7 +27244,7 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
27117
27244
|
});
|
|
27118
27245
|
}
|
|
27119
27246
|
for (const child of node.children) {
|
|
27120
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, node.tag,
|
|
27247
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, node.tag, scope, readsProp);
|
|
27121
27248
|
}
|
|
27122
27249
|
break;
|
|
27123
27250
|
}
|
|
@@ -27144,7 +27271,7 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
27144
27271
|
}
|
|
27145
27272
|
case "conditional": {
|
|
27146
27273
|
const decision = decideWrapFromAstFlags(node);
|
|
27147
|
-
const loopReactive =
|
|
27274
|
+
const loopReactive = boundNames.size > 0 && (node.origin?.freeRefs?.some((r) => boundNames.has(r.name)) ?? false);
|
|
27148
27275
|
if ((decision.wrap || loopReactive) && node.slotId) {
|
|
27149
27276
|
const deps = extractReactiveDeps(node.condition, signalGetters, memoNames);
|
|
27150
27277
|
bindings.push({
|
|
@@ -27160,14 +27287,14 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
27160
27287
|
jsxPreview: `{${truncateExpr(node.condition)} ? ... : ...}`
|
|
27161
27288
|
});
|
|
27162
27289
|
}
|
|
27163
|
-
collectDomBindings(node.whenTrue, bindings, signalGetters, memoNames, parentTag,
|
|
27164
|
-
collectDomBindings(node.whenFalse, bindings, signalGetters, memoNames, parentTag,
|
|
27290
|
+
collectDomBindings(node.whenTrue, bindings, signalGetters, memoNames, parentTag, scope, readsProp);
|
|
27291
|
+
collectDomBindings(node.whenFalse, bindings, signalGetters, memoNames, parentTag, scope, readsProp);
|
|
27165
27292
|
break;
|
|
27166
27293
|
}
|
|
27167
27294
|
case "loop": {
|
|
27168
27295
|
if (node.slotId) {
|
|
27169
27296
|
const deps = extractReactiveDeps(node.array, signalGetters, memoNames);
|
|
27170
|
-
const loopReactive =
|
|
27297
|
+
const loopReactive = boundNames.size > 0 && node.arrayFreeIdentifiers !== undefined && setSomeIn(boundNames, node.arrayFreeIdentifiers);
|
|
27171
27298
|
const isReactive = deps.length > 0 || node.callsReactiveGetters === true || loopReactive;
|
|
27172
27299
|
const isFallback = !isReactive && node.hasFunctionCalls === true;
|
|
27173
27300
|
if (isReactive || isFallback) {
|
|
@@ -27186,13 +27313,9 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
27186
27313
|
});
|
|
27187
27314
|
}
|
|
27188
27315
|
}
|
|
27189
|
-
const
|
|
27190
|
-
for (const p of extractLoopParamNames(node.param, node))
|
|
27191
|
-
childLoopParams.add(p);
|
|
27192
|
-
if (node.index)
|
|
27193
|
-
childLoopParams.add(node.index);
|
|
27316
|
+
const childScope = scope.enterLoopRow(node);
|
|
27194
27317
|
for (const child of node.children) {
|
|
27195
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag,
|
|
27318
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, childScope, readsProp);
|
|
27196
27319
|
}
|
|
27197
27320
|
break;
|
|
27198
27321
|
}
|
|
@@ -27225,21 +27348,21 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
27225
27348
|
}
|
|
27226
27349
|
}
|
|
27227
27350
|
for (const child of node.children) {
|
|
27228
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag,
|
|
27351
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, readsProp);
|
|
27229
27352
|
}
|
|
27230
27353
|
break;
|
|
27231
27354
|
}
|
|
27232
27355
|
case "fragment":
|
|
27233
27356
|
case "provider": {
|
|
27234
27357
|
for (const child of node.children) {
|
|
27235
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag,
|
|
27358
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, readsProp);
|
|
27236
27359
|
}
|
|
27237
27360
|
break;
|
|
27238
27361
|
}
|
|
27239
27362
|
case "if-statement": {
|
|
27240
|
-
collectDomBindings(node.consequent, bindings, signalGetters, memoNames, parentTag,
|
|
27363
|
+
collectDomBindings(node.consequent, bindings, signalGetters, memoNames, parentTag, scope, readsProp);
|
|
27241
27364
|
if (node.alternate) {
|
|
27242
|
-
collectDomBindings(node.alternate, bindings, signalGetters, memoNames, parentTag,
|
|
27365
|
+
collectDomBindings(node.alternate, bindings, signalGetters, memoNames, parentTag, scope, readsProp);
|
|
27243
27366
|
}
|
|
27244
27367
|
break;
|
|
27245
27368
|
}
|
|
@@ -27252,7 +27375,7 @@ function truncateExpr(expr, max = 40) {
|
|
|
27252
27375
|
function exprReadsPropMember(expr, propsObjectName) {
|
|
27253
27376
|
let sf;
|
|
27254
27377
|
try {
|
|
27255
|
-
sf =
|
|
27378
|
+
sf = ts28.createSourceFile("__attr.tsx", `(${expr})`, ts28.ScriptTarget.Latest, true, ts28.ScriptKind.TSX);
|
|
27256
27379
|
} catch {
|
|
27257
27380
|
return false;
|
|
27258
27381
|
}
|
|
@@ -27260,11 +27383,11 @@ function exprReadsPropMember(expr, propsObjectName) {
|
|
|
27260
27383
|
const visit3 = (n) => {
|
|
27261
27384
|
if (found)
|
|
27262
27385
|
return;
|
|
27263
|
-
if (
|
|
27386
|
+
if (ts28.isPropertyAccessExpression(n) && ts28.isIdentifier(n.expression) && n.expression.text === propsObjectName && n.name.text !== "children") {
|
|
27264
27387
|
found = true;
|
|
27265
27388
|
return;
|
|
27266
27389
|
}
|
|
27267
|
-
|
|
27390
|
+
ts28.forEachChild(n, visit3);
|
|
27268
27391
|
};
|
|
27269
27392
|
visit3(sf);
|
|
27270
27393
|
return found;
|
|
@@ -27334,7 +27457,7 @@ function findSourceFile2(meta) {
|
|
|
27334
27457
|
return null;
|
|
27335
27458
|
}
|
|
27336
27459
|
// src/profiler.ts
|
|
27337
|
-
import
|
|
27460
|
+
import ts29 from "typescript";
|
|
27338
27461
|
var PROFILE_SCHEMA_VERSION = 1;
|
|
27339
27462
|
var DEFAULT_FANOUT_THRESHOLD = 8;
|
|
27340
27463
|
function buildStaticBudget(source, filePath, componentName, options = {}) {
|
|
@@ -27604,15 +27727,15 @@ function joinProfilerEvents(events, index) {
|
|
|
27604
27727
|
return { joined, unattributed, diagnostics };
|
|
27605
27728
|
}
|
|
27606
27729
|
function findUninstrumentedEffects(source, filePath, instrumentedLines) {
|
|
27607
|
-
const sf =
|
|
27730
|
+
const sf = ts29.createSourceFile(filePath, source, ts29.ScriptTarget.Latest, true, ts29.ScriptKind.TSX);
|
|
27608
27731
|
const out = [];
|
|
27609
27732
|
const visit3 = (node) => {
|
|
27610
|
-
if (
|
|
27733
|
+
if (ts29.isCallExpression(node) && ts29.isIdentifier(node.expression) && node.expression.text === "createEffect") {
|
|
27611
27734
|
const line = sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;
|
|
27612
27735
|
if (!instrumentedLines.has(line))
|
|
27613
27736
|
out.push({ file: filePath, line });
|
|
27614
27737
|
}
|
|
27615
|
-
|
|
27738
|
+
ts29.forEachChild(node, visit3);
|
|
27616
27739
|
};
|
|
27617
27740
|
visit3(sf);
|
|
27618
27741
|
out.sort((a, b) => a.line - b.line);
|
|
@@ -27920,13 +28043,13 @@ function assessBatchSafety(args) {
|
|
|
27920
28043
|
const signalGetters = new Set(args.graph.signals.map((s) => s.name));
|
|
27921
28044
|
let sf;
|
|
27922
28045
|
try {
|
|
27923
|
-
sf =
|
|
28046
|
+
sf = ts29.createSourceFile("__h.ts", `const __h = ${args.handler}`, ts29.ScriptTarget.Latest, true);
|
|
27924
28047
|
} catch {
|
|
27925
28048
|
return "unverified";
|
|
27926
28049
|
}
|
|
27927
28050
|
const calls = [];
|
|
27928
28051
|
const visit3 = (node) => {
|
|
27929
|
-
if (
|
|
28052
|
+
if (ts29.isCallExpression(node) && ts29.isIdentifier(node.expression)) {
|
|
27930
28053
|
const name = node.expression.text;
|
|
27931
28054
|
if (setters.has(name))
|
|
27932
28055
|
calls.push({ pos: node.getStart(sf), kind: "write" });
|
|
@@ -27935,7 +28058,7 @@ function assessBatchSafety(args) {
|
|
|
27935
28058
|
else if (!signalGetters.has(name) && !memoNames.has(name))
|
|
27936
28059
|
calls.push({ pos: node.getStart(sf), kind: "risky" });
|
|
27937
28060
|
}
|
|
27938
|
-
|
|
28061
|
+
ts29.forEachChild(node, visit3);
|
|
27939
28062
|
};
|
|
27940
28063
|
visit3(sf);
|
|
27941
28064
|
calls.sort((a, b) => a.pos - b.pos);
|
|
@@ -28728,6 +28851,7 @@ export {
|
|
|
28728
28851
|
PARSED_EXPR_KINDS,
|
|
28729
28852
|
JsxAdapter,
|
|
28730
28853
|
ErrorCodes,
|
|
28854
|
+
ESCAPE_SSR_COST,
|
|
28731
28855
|
ENV_SIGNAL_READERS,
|
|
28732
28856
|
CALLBACK_METHODS,
|
|
28733
28857
|
BindingScope,
|