@barefootjs/jsx 0.31.4 → 0.31.5
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.js +765 -649
- 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 +41 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- 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__/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/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 +5 -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 +41 -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";
|
|
@@ -9230,7 +9230,7 @@ function validateObjectFactoryDestructure(ctx, pattern, callee, loc) {
|
|
|
9230
9230
|
}
|
|
9231
9231
|
|
|
9232
9232
|
// src/jsx-to-ir.ts
|
|
9233
|
-
import
|
|
9233
|
+
import ts13 from "typescript";
|
|
9234
9234
|
|
|
9235
9235
|
// src/types.ts
|
|
9236
9236
|
var SCOPE_FORBIDDEN = {
|
|
@@ -9336,6 +9336,7 @@ function pickAttrMetaFromIR(src) {
|
|
|
9336
9336
|
}
|
|
9337
9337
|
|
|
9338
9338
|
// src/module-exports.ts
|
|
9339
|
+
import ts10 from "typescript";
|
|
9339
9340
|
function generateModuleExports(ir, extraInlineExported = new Set, rewriteRelativeImport, options) {
|
|
9340
9341
|
const lines = [];
|
|
9341
9342
|
for (const constant of options?.skipValueDeclarations ? [] : ir.metadata.localConstants) {
|
|
@@ -9432,6 +9433,49 @@ function findReachableNames(primaryRefs, declarations) {
|
|
|
9432
9433
|
}
|
|
9433
9434
|
return reachable;
|
|
9434
9435
|
}
|
|
9436
|
+
function findAssignedNames(bodyText, candidates) {
|
|
9437
|
+
const assigned = new Set;
|
|
9438
|
+
if (candidates.size === 0)
|
|
9439
|
+
return assigned;
|
|
9440
|
+
const sf = ts10.createSourceFile("bf-assignment-scan.tsx", bodyText, ts10.ScriptTarget.Latest, false, ts10.ScriptKind.TSX);
|
|
9441
|
+
const record = (target) => {
|
|
9442
|
+
if (ts10.isIdentifier(target) && candidates.has(target.text)) {
|
|
9443
|
+
assigned.add(target.text);
|
|
9444
|
+
}
|
|
9445
|
+
};
|
|
9446
|
+
const visit2 = (node) => {
|
|
9447
|
+
if (ts10.isBinaryExpression(node) && isAssignmentOperator(node.operatorToken.kind)) {
|
|
9448
|
+
record(node.left);
|
|
9449
|
+
} else if ((ts10.isPrefixUnaryExpression(node) || ts10.isPostfixUnaryExpression(node)) && (node.operator === ts10.SyntaxKind.PlusPlusToken || node.operator === ts10.SyntaxKind.MinusMinusToken)) {
|
|
9450
|
+
record(node.operand);
|
|
9451
|
+
}
|
|
9452
|
+
ts10.forEachChild(node, visit2);
|
|
9453
|
+
};
|
|
9454
|
+
ts10.forEachChild(sf, visit2);
|
|
9455
|
+
return assigned;
|
|
9456
|
+
}
|
|
9457
|
+
function closeOverWritersOfMutableBindings(primaryRefs, declarations, mutableNames) {
|
|
9458
|
+
let reachable = findReachableNames(primaryRefs, declarations);
|
|
9459
|
+
if (mutableNames.size === 0)
|
|
9460
|
+
return reachable;
|
|
9461
|
+
let seedText = primaryRefs;
|
|
9462
|
+
for (let round = 0;round <= declarations.length; round++) {
|
|
9463
|
+
const survivingMutables = new Set([...reachable].filter((name) => mutableNames.has(name)));
|
|
9464
|
+
if (survivingMutables.size === 0)
|
|
9465
|
+
return reachable;
|
|
9466
|
+
const added = declarations.filter((d) => !reachable.has(d.name)).filter((d) => findAssignedNames(d.body, survivingMutables).size > 0).map((d) => d.name);
|
|
9467
|
+
if (added.length === 0)
|
|
9468
|
+
return reachable;
|
|
9469
|
+
seedText += `
|
|
9470
|
+
` + added.join(`
|
|
9471
|
+
`);
|
|
9472
|
+
reachable = findReachableNames(seedText, declarations);
|
|
9473
|
+
}
|
|
9474
|
+
return reachable;
|
|
9475
|
+
}
|
|
9476
|
+
function isAssignmentOperator(kind) {
|
|
9477
|
+
return kind >= ts10.SyntaxKind.FirstAssignment && kind <= ts10.SyntaxKind.LastAssignment;
|
|
9478
|
+
}
|
|
9435
9479
|
function extractFunctionParams(value) {
|
|
9436
9480
|
const arrowMatch = value.match(/^(?:async\s*)?\(([^)]*)\)\s*(?::\s*[^=]+)?\s*=>/);
|
|
9437
9481
|
if (arrowMatch) {
|
|
@@ -9469,7 +9513,7 @@ function stripClientBuiltinImports(imports) {
|
|
|
9469
9513
|
}
|
|
9470
9514
|
|
|
9471
9515
|
// src/reactivity-checker.ts
|
|
9472
|
-
import
|
|
9516
|
+
import ts11 from "typescript";
|
|
9473
9517
|
var REACTIVE_BRAND = "__reactive";
|
|
9474
9518
|
function queryType(checker, node) {
|
|
9475
9519
|
incrementCounter("typeCheckerQueries");
|
|
@@ -9487,7 +9531,7 @@ function safeGetText(node) {
|
|
|
9487
9531
|
}
|
|
9488
9532
|
}
|
|
9489
9533
|
function analyze(node, checker) {
|
|
9490
|
-
if (
|
|
9534
|
+
if (ts11.isPropertyAccessExpression(node)) {
|
|
9491
9535
|
try {
|
|
9492
9536
|
const type = queryType(checker, node);
|
|
9493
9537
|
if (isReactiveType(type)) {
|
|
@@ -9511,7 +9555,7 @@ function analyze(node, checker) {
|
|
|
9511
9555
|
}
|
|
9512
9556
|
return NOT_REACTIVE;
|
|
9513
9557
|
}
|
|
9514
|
-
if (
|
|
9558
|
+
if (ts11.isIdentifier(node)) {
|
|
9515
9559
|
try {
|
|
9516
9560
|
const type = queryType(checker, node);
|
|
9517
9561
|
if (isReactiveType(type)) {
|
|
@@ -9523,7 +9567,7 @@ function analyze(node, checker) {
|
|
|
9523
9567
|
} catch {}
|
|
9524
9568
|
return NOT_REACTIVE;
|
|
9525
9569
|
}
|
|
9526
|
-
if (
|
|
9570
|
+
if (ts11.isCallExpression(node)) {
|
|
9527
9571
|
try {
|
|
9528
9572
|
const calleeType = queryType(checker, node.expression);
|
|
9529
9573
|
if (isReactiveType(calleeType)) {
|
|
@@ -9536,7 +9580,7 @@ function analyze(node, checker) {
|
|
|
9536
9580
|
}
|
|
9537
9581
|
let foundChild;
|
|
9538
9582
|
let foundChildText = "";
|
|
9539
|
-
|
|
9583
|
+
ts11.forEachChild(node, (child) => {
|
|
9540
9584
|
if (foundChild?.isReactive)
|
|
9541
9585
|
return;
|
|
9542
9586
|
const result = analyze(child, checker);
|
|
@@ -9565,7 +9609,7 @@ function containsReactiveExpression(node, checker) {
|
|
|
9565
9609
|
}
|
|
9566
9610
|
|
|
9567
9611
|
// src/free-refs.ts
|
|
9568
|
-
import
|
|
9612
|
+
import ts12 from "typescript";
|
|
9569
9613
|
var _bindingMapCache = new WeakMap;
|
|
9570
9614
|
function buildBindingMap(env) {
|
|
9571
9615
|
const cached = _bindingMapCache.get(env);
|
|
@@ -9603,8 +9647,8 @@ function buildBindingMap(env) {
|
|
|
9603
9647
|
for (const m of env.memos) {
|
|
9604
9648
|
map.set(m.name, "memo-getter");
|
|
9605
9649
|
}
|
|
9606
|
-
if (env.
|
|
9607
|
-
for (const name of env.
|
|
9650
|
+
if (env.loopValueBoundNames) {
|
|
9651
|
+
for (const name of env.loopValueBoundNames)
|
|
9608
9652
|
map.set(name, "render-item");
|
|
9609
9653
|
}
|
|
9610
9654
|
_bindingMapCache.set(env, map);
|
|
@@ -9633,20 +9677,20 @@ function defaultBindingScope(kind) {
|
|
|
9633
9677
|
function collectIdentifiers2(node) {
|
|
9634
9678
|
const out = [];
|
|
9635
9679
|
const visit2 = (n, parent) => {
|
|
9636
|
-
if (
|
|
9637
|
-
if (parent &&
|
|
9680
|
+
if (ts12.isIdentifier(n)) {
|
|
9681
|
+
if (parent && ts12.isPropertyAccessExpression(parent) && parent.name === n)
|
|
9638
9682
|
return;
|
|
9639
|
-
if (parent &&
|
|
9683
|
+
if (parent && ts12.isPropertyAssignment(parent) && parent.name === n)
|
|
9640
9684
|
return;
|
|
9641
|
-
if (parent && (
|
|
9685
|
+
if (parent && (ts12.isJsxOpeningElement(parent) || ts12.isJsxClosingElement(parent) || ts12.isJsxSelfClosingElement(parent)) && parent.tagName === n) {
|
|
9642
9686
|
return;
|
|
9643
9687
|
}
|
|
9644
|
-
if (parent &&
|
|
9688
|
+
if (parent && ts12.isJsxAttribute(parent) && parent.name === n)
|
|
9645
9689
|
return;
|
|
9646
9690
|
out.push(n);
|
|
9647
9691
|
return;
|
|
9648
9692
|
}
|
|
9649
|
-
|
|
9693
|
+
ts12.forEachChild(n, (child) => visit2(child, n));
|
|
9650
9694
|
};
|
|
9651
9695
|
visit2(node);
|
|
9652
9696
|
return out;
|
|
@@ -9655,7 +9699,7 @@ function collectReactiveBrandRefs(node, checker) {
|
|
|
9655
9699
|
const out = [];
|
|
9656
9700
|
const seen = new Set;
|
|
9657
9701
|
const visit2 = (n) => {
|
|
9658
|
-
if (
|
|
9702
|
+
if (ts12.isPropertyAccessExpression(n)) {
|
|
9659
9703
|
try {
|
|
9660
9704
|
const type = checker.getTypeAtLocation(n);
|
|
9661
9705
|
if (isReactiveType(type)) {
|
|
@@ -9673,7 +9717,7 @@ function collectReactiveBrandRefs(node, checker) {
|
|
|
9673
9717
|
incrementCounter("freeRefsTypeLookupFailures");
|
|
9674
9718
|
}
|
|
9675
9719
|
}
|
|
9676
|
-
|
|
9720
|
+
ts12.forEachChild(n, visit2);
|
|
9677
9721
|
};
|
|
9678
9722
|
visit2(node);
|
|
9679
9723
|
return out;
|
|
@@ -9683,14 +9727,14 @@ function resolveConstantInitializerRefs(c, env, visited) {
|
|
|
9683
9727
|
return [];
|
|
9684
9728
|
if (c.containsArrow)
|
|
9685
9729
|
return [];
|
|
9686
|
-
const sf =
|
|
9730
|
+
const sf = ts12.createSourceFile("__const_init.ts", `const __probe = (${c.value});`, ts12.ScriptTarget.Latest, true);
|
|
9687
9731
|
const stmt = sf.statements[0];
|
|
9688
|
-
if (!stmt || !
|
|
9732
|
+
if (!stmt || !ts12.isVariableStatement(stmt))
|
|
9689
9733
|
return [];
|
|
9690
9734
|
const decl = stmt.declarationList.declarations[0];
|
|
9691
9735
|
if (!decl || !decl.initializer)
|
|
9692
9736
|
return [];
|
|
9693
|
-
const expr =
|
|
9737
|
+
const expr = ts12.isParenthesizedExpression(decl.initializer) ? decl.initializer.expression : decl.initializer;
|
|
9694
9738
|
return resolveFreeRefsInternal(expr, env, visited);
|
|
9695
9739
|
}
|
|
9696
9740
|
function resolveFreeRefsInternal(node, env, visited) {
|
|
@@ -9702,7 +9746,7 @@ function resolveFreeRefsInternal(node, env, visited) {
|
|
|
9702
9746
|
const name = ident.text;
|
|
9703
9747
|
if (env.propsObjectName === name) {
|
|
9704
9748
|
const parent = ident.parent;
|
|
9705
|
-
if (parent &&
|
|
9749
|
+
if (parent && ts12.isPropertyAccessExpression(parent) && parent.expression === ident && parent.name.text === "children") {
|
|
9706
9750
|
continue;
|
|
9707
9751
|
}
|
|
9708
9752
|
}
|
|
@@ -10131,13 +10175,13 @@ function exprCallsReactiveGetters(expr, ctx) {
|
|
|
10131
10175
|
function visit2(n) {
|
|
10132
10176
|
if (found)
|
|
10133
10177
|
return;
|
|
10134
|
-
if (
|
|
10178
|
+
if (ts13.isCallExpression(n) && ts13.isIdentifier(n.expression)) {
|
|
10135
10179
|
if (names.has(n.expression.text)) {
|
|
10136
10180
|
found = true;
|
|
10137
10181
|
return;
|
|
10138
10182
|
}
|
|
10139
10183
|
}
|
|
10140
|
-
|
|
10184
|
+
ts13.forEachChild(n, visit2);
|
|
10141
10185
|
}
|
|
10142
10186
|
visit2(expr);
|
|
10143
10187
|
return found;
|
|
@@ -10164,11 +10208,11 @@ function exprReferencesModuleClientSignal(expr, ctx) {
|
|
|
10164
10208
|
function visit2(n) {
|
|
10165
10209
|
if (found)
|
|
10166
10210
|
return;
|
|
10167
|
-
if (
|
|
10211
|
+
if (ts13.isCallExpression(n) && ts13.isIdentifier(n.expression) && names.has(n.expression.text)) {
|
|
10168
10212
|
found = true;
|
|
10169
10213
|
return;
|
|
10170
10214
|
}
|
|
10171
|
-
|
|
10215
|
+
ts13.forEachChild(n, visit2);
|
|
10172
10216
|
}
|
|
10173
10217
|
visit2(expr);
|
|
10174
10218
|
return found;
|
|
@@ -10178,11 +10222,11 @@ function exprHasFunctionCalls(expr) {
|
|
|
10178
10222
|
function visit2(n) {
|
|
10179
10223
|
if (found)
|
|
10180
10224
|
return;
|
|
10181
|
-
if (
|
|
10225
|
+
if (ts13.isCallExpression(n)) {
|
|
10182
10226
|
found = true;
|
|
10183
10227
|
return;
|
|
10184
10228
|
}
|
|
10185
|
-
|
|
10229
|
+
ts13.forEachChild(n, visit2);
|
|
10186
10230
|
}
|
|
10187
10231
|
visit2(expr);
|
|
10188
10232
|
return found;
|
|
@@ -10219,10 +10263,10 @@ function lowerDateCalls(text, expr, ctx) {
|
|
|
10219
10263
|
return text;
|
|
10220
10264
|
const candidates = [];
|
|
10221
10265
|
function visit2(n) {
|
|
10222
|
-
if (
|
|
10266
|
+
if (ts13.isCallExpression(n) && n.arguments.length === 0 && ts13.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
|
|
10223
10267
|
candidates.push(n);
|
|
10224
10268
|
}
|
|
10225
|
-
|
|
10269
|
+
ts13.forEachChild(n, visit2);
|
|
10226
10270
|
}
|
|
10227
10271
|
visit2(expr);
|
|
10228
10272
|
if (candidates.length === 0)
|
|
@@ -10247,10 +10291,10 @@ function lowerToLocaleDateCalls(text, expr, ctx) {
|
|
|
10247
10291
|
return text;
|
|
10248
10292
|
const candidates = [];
|
|
10249
10293
|
function visit2(n) {
|
|
10250
|
-
if (
|
|
10294
|
+
if (ts13.isCallExpression(n) && n.arguments.length === 2 && ts13.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && n.expression.name.text === "toLocaleDateString") {
|
|
10251
10295
|
candidates.push(n);
|
|
10252
10296
|
}
|
|
10253
|
-
|
|
10297
|
+
ts13.forEachChild(n, visit2);
|
|
10254
10298
|
}
|
|
10255
10299
|
visit2(expr);
|
|
10256
10300
|
if (candidates.length === 0)
|
|
@@ -10304,10 +10348,10 @@ function collectBranchLocalPropRefsViaSubstitution(node, ctx) {
|
|
|
10304
10348
|
return;
|
|
10305
10349
|
let acc;
|
|
10306
10350
|
function visit2(n, parent) {
|
|
10307
|
-
if (
|
|
10308
|
-
const isObjectKey = parent &&
|
|
10309
|
-
const isShorthand = parent &&
|
|
10310
|
-
const isAccessName = parent &&
|
|
10351
|
+
if (ts13.isIdentifier(n) && propDepsMap.has(n.text)) {
|
|
10352
|
+
const isObjectKey = parent && ts13.isPropertyAssignment(parent) && parent.name === n;
|
|
10353
|
+
const isShorthand = parent && ts13.isShorthandPropertyAssignment(parent) && parent.name === n;
|
|
10354
|
+
const isAccessName = parent && ts13.isPropertyAccessExpression(parent) && parent.name === n;
|
|
10311
10355
|
if (!isObjectKey && !isShorthand && !isAccessName) {
|
|
10312
10356
|
const deps = propDepsMap.get(n.text);
|
|
10313
10357
|
if (deps && deps.size > 0) {
|
|
@@ -10318,7 +10362,7 @@ function collectBranchLocalPropRefsViaSubstitution(node, ctx) {
|
|
|
10318
10362
|
}
|
|
10319
10363
|
}
|
|
10320
10364
|
}
|
|
10321
|
-
|
|
10365
|
+
ts13.forEachChild(n, (child) => visit2(child, n));
|
|
10322
10366
|
}
|
|
10323
10367
|
visit2(node);
|
|
10324
10368
|
return acc;
|
|
@@ -10394,21 +10438,21 @@ function createTransformContext(analyzer) {
|
|
|
10394
10438
|
function buildComponentNamespaces(ctx) {
|
|
10395
10439
|
const result = new Map;
|
|
10396
10440
|
for (const stmt of ctx.sourceFile.statements) {
|
|
10397
|
-
if (!
|
|
10441
|
+
if (!ts13.isVariableStatement(stmt))
|
|
10398
10442
|
continue;
|
|
10399
10443
|
for (const decl of stmt.declarationList.declarations) {
|
|
10400
|
-
if (!decl.initializer || !
|
|
10444
|
+
if (!decl.initializer || !ts13.isIdentifier(decl.name))
|
|
10401
10445
|
continue;
|
|
10402
10446
|
let init = decl.initializer;
|
|
10403
|
-
while (
|
|
10447
|
+
while (ts13.isParenthesizedExpression(init))
|
|
10404
10448
|
init = init.expression;
|
|
10405
|
-
if (!
|
|
10449
|
+
if (!ts13.isObjectLiteralExpression(init))
|
|
10406
10450
|
continue;
|
|
10407
10451
|
const members = new Map;
|
|
10408
10452
|
for (const prop of init.properties) {
|
|
10409
|
-
if (
|
|
10453
|
+
if (ts13.isShorthandPropertyAssignment(prop)) {
|
|
10410
10454
|
members.set(prop.name.text, prop.name.text);
|
|
10411
|
-
} else if (
|
|
10455
|
+
} else if (ts13.isPropertyAssignment(prop) && (ts13.isIdentifier(prop.name) || ts13.isStringLiteral(prop.name)) && ts13.isIdentifier(prop.initializer)) {
|
|
10412
10456
|
members.set(prop.name.text, prop.initializer.text);
|
|
10413
10457
|
}
|
|
10414
10458
|
}
|
|
@@ -10420,11 +10464,11 @@ function buildComponentNamespaces(ctx) {
|
|
|
10420
10464
|
return result;
|
|
10421
10465
|
}
|
|
10422
10466
|
function resolveMemberExpressionTag(tagNode, ctx) {
|
|
10423
|
-
if (!
|
|
10467
|
+
if (!ts13.isPropertyAccessExpression(tagNode))
|
|
10424
10468
|
return null;
|
|
10425
|
-
if (!
|
|
10469
|
+
if (!ts13.isIdentifier(tagNode.expression))
|
|
10426
10470
|
return null;
|
|
10427
|
-
if (!
|
|
10471
|
+
if (!ts13.isIdentifier(tagNode.name))
|
|
10428
10472
|
return null;
|
|
10429
10473
|
if (!ctx._componentNamespaces) {
|
|
10430
10474
|
ctx._componentNamespaces = buildComponentNamespaces(ctx);
|
|
@@ -10457,7 +10501,7 @@ function makeBindingEnv(ctx) {
|
|
|
10457
10501
|
localFunctions: a.localFunctions,
|
|
10458
10502
|
imports: a.imports,
|
|
10459
10503
|
ambientGlobals: a.ambientGlobals,
|
|
10460
|
-
|
|
10504
|
+
loopValueBoundNames: boundNames,
|
|
10461
10505
|
checker: a.checker
|
|
10462
10506
|
};
|
|
10463
10507
|
ctx._bindingEnv = env;
|
|
@@ -10581,7 +10625,7 @@ function buildIRRoot(analyzer) {
|
|
|
10581
10625
|
return null;
|
|
10582
10626
|
const ctx = createTransformContext(analyzer);
|
|
10583
10627
|
const jsxReturn = analyzer.jsxReturn;
|
|
10584
|
-
if (
|
|
10628
|
+
if (ts13.isJsxElement(jsxReturn) || ts13.isJsxSelfClosingElement(jsxReturn) || ts13.isJsxFragment(jsxReturn)) {
|
|
10585
10629
|
const ir2 = transformNode(jsxReturn, ctx);
|
|
10586
10630
|
if (ir2 && needsScopeWrapper(ir2)) {
|
|
10587
10631
|
return wrapInScopeElement(ir2);
|
|
@@ -10637,22 +10681,22 @@ function wrapInScopeElement(node) {
|
|
|
10637
10681
|
};
|
|
10638
10682
|
}
|
|
10639
10683
|
function transformNode(node, ctx) {
|
|
10640
|
-
if (
|
|
10684
|
+
if (ts13.isJsxElement(node)) {
|
|
10641
10685
|
return transformJsxElement(node, ctx);
|
|
10642
10686
|
}
|
|
10643
|
-
if (
|
|
10687
|
+
if (ts13.isJsxSelfClosingElement(node)) {
|
|
10644
10688
|
return transformSelfClosingElement(node, ctx);
|
|
10645
10689
|
}
|
|
10646
|
-
if (
|
|
10690
|
+
if (ts13.isJsxFragment(node)) {
|
|
10647
10691
|
return transformFragment(node, ctx);
|
|
10648
10692
|
}
|
|
10649
|
-
if (
|
|
10693
|
+
if (ts13.isJsxText(node)) {
|
|
10650
10694
|
return transformText(node, ctx);
|
|
10651
10695
|
}
|
|
10652
|
-
if (
|
|
10696
|
+
if (ts13.isJsxExpression(node)) {
|
|
10653
10697
|
return transformExpression(node, ctx);
|
|
10654
10698
|
}
|
|
10655
|
-
if (
|
|
10699
|
+
if (ts13.isConditionalExpression(node)) {
|
|
10656
10700
|
return transformConditional(node, ctx);
|
|
10657
10701
|
}
|
|
10658
10702
|
return null;
|
|
@@ -11009,7 +11053,7 @@ function transformSelfClosingComponent(node, ctx, name) {
|
|
|
11009
11053
|
}
|
|
11010
11054
|
function isTransparentFragment(node, ctx) {
|
|
11011
11055
|
const children = node.children.filter((child2) => {
|
|
11012
|
-
if (
|
|
11056
|
+
if (ts13.isJsxText(child2)) {
|
|
11013
11057
|
return child2.text.trim() !== "";
|
|
11014
11058
|
}
|
|
11015
11059
|
return true;
|
|
@@ -11017,7 +11061,7 @@ function isTransparentFragment(node, ctx) {
|
|
|
11017
11061
|
if (children.length !== 1)
|
|
11018
11062
|
return false;
|
|
11019
11063
|
const child = children[0];
|
|
11020
|
-
if (!
|
|
11064
|
+
if (!ts13.isJsxExpression(child))
|
|
11021
11065
|
return false;
|
|
11022
11066
|
if (!child.expression)
|
|
11023
11067
|
return false;
|
|
@@ -11061,7 +11105,7 @@ function transformChildren(children, ctx) {
|
|
|
11061
11105
|
const result = [];
|
|
11062
11106
|
for (let i = 0;i < children.length; i++) {
|
|
11063
11107
|
const child = children[i];
|
|
11064
|
-
if (
|
|
11108
|
+
if (ts13.isJsxExpression(child) && !child.expression) {
|
|
11065
11109
|
continue;
|
|
11066
11110
|
}
|
|
11067
11111
|
const transformed = transformNode(child, ctx);
|
|
@@ -11076,10 +11120,10 @@ function transformChildren(children, ctx) {
|
|
|
11076
11120
|
}
|
|
11077
11121
|
function isRenderNothingLiteral(expr, ctx) {
|
|
11078
11122
|
let e = expr;
|
|
11079
|
-
while (
|
|
11123
|
+
while (ts13.isParenthesizedExpression(e) || ts13.isAsExpression(e) || ts13.isSatisfiesExpression(e) || ts13.isNonNullExpression(e)) {
|
|
11080
11124
|
e = e.expression;
|
|
11081
11125
|
}
|
|
11082
|
-
return e.kind ===
|
|
11126
|
+
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
11127
|
}
|
|
11084
11128
|
function transformText(node, ctx) {
|
|
11085
11129
|
const text = node.text.replace(/\s+/g, " ");
|
|
@@ -11105,7 +11149,7 @@ function transformExpressionInner(expr, ctx, node, isClientOnly) {
|
|
|
11105
11149
|
return null;
|
|
11106
11150
|
}
|
|
11107
11151
|
checkBareSignalOrMemoIdentifier(expr, ctx);
|
|
11108
|
-
if (
|
|
11152
|
+
if (ts13.isIdentifier(expr)) {
|
|
11109
11153
|
const jsxNode = ctx.analyzer.jsxConstants.get(expr.text);
|
|
11110
11154
|
if (jsxNode) {
|
|
11111
11155
|
return transformNode(jsxNode, ctx);
|
|
@@ -11384,38 +11428,38 @@ function transformLogicalAnd(node, ctx) {
|
|
|
11384
11428
|
};
|
|
11385
11429
|
}
|
|
11386
11430
|
function containsJsxInExpression(node) {
|
|
11387
|
-
if (
|
|
11431
|
+
if (ts13.isJsxElement(node) || ts13.isJsxSelfClosingElement(node) || ts13.isJsxFragment(node)) {
|
|
11388
11432
|
return true;
|
|
11389
11433
|
}
|
|
11390
|
-
return
|
|
11434
|
+
return ts13.forEachChild(node, containsJsxInExpression) ?? false;
|
|
11391
11435
|
}
|
|
11392
11436
|
function callsJsxHelper(node, ctx) {
|
|
11393
11437
|
let found = false;
|
|
11394
11438
|
const visit2 = (n) => {
|
|
11395
11439
|
if (found)
|
|
11396
11440
|
return;
|
|
11397
|
-
if (
|
|
11441
|
+
if (ts13.isCallExpression(n) && ts13.isIdentifier(n.expression)) {
|
|
11398
11442
|
const name = n.expression.text;
|
|
11399
11443
|
if (ctx.analyzer.jsxFunctions.has(name) || ctx.analyzer.jsxMultiReturnFunctions.has(name)) {
|
|
11400
11444
|
found = true;
|
|
11401
11445
|
return;
|
|
11402
11446
|
}
|
|
11403
11447
|
}
|
|
11404
|
-
|
|
11448
|
+
ts13.forEachChild(n, visit2);
|
|
11405
11449
|
};
|
|
11406
11450
|
visit2(node);
|
|
11407
11451
|
return found;
|
|
11408
11452
|
}
|
|
11409
11453
|
function containsAwaitExpression(node) {
|
|
11410
|
-
if (
|
|
11454
|
+
if (ts13.isAwaitExpression(node))
|
|
11411
11455
|
return true;
|
|
11412
|
-
if (
|
|
11456
|
+
if (ts13.isFunctionDeclaration(node) || ts13.isFunctionExpression(node) || ts13.isArrowFunction(node))
|
|
11413
11457
|
return false;
|
|
11414
|
-
return
|
|
11458
|
+
return ts13.forEachChild(node, containsAwaitExpression) ?? false;
|
|
11415
11459
|
}
|
|
11416
11460
|
function transformNullishCoalescing(node, ctx) {
|
|
11417
11461
|
const leftText = ctx.getJS(node.left);
|
|
11418
|
-
const isNullish = node.operatorToken.kind ===
|
|
11462
|
+
const isNullish = node.operatorToken.kind === ts13.SyntaxKind.QuestionQuestionToken;
|
|
11419
11463
|
const condition = isNullish ? `${leftText} != null` : leftText;
|
|
11420
11464
|
const leftOrigin = {
|
|
11421
11465
|
phase: "tick",
|
|
@@ -11461,36 +11505,36 @@ function transformNullishCoalescing(node, ctx) {
|
|
|
11461
11505
|
}
|
|
11462
11506
|
function assertNever2(expr) {
|
|
11463
11507
|
const kind = expr?.kind;
|
|
11464
|
-
throw new Error(`transformJsxExpression: unhandled ts.SyntaxKind ${kind !== undefined ?
|
|
11508
|
+
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
11509
|
}
|
|
11466
11510
|
function transformJsxExpression(expr, ctx, isClientOnly = false) {
|
|
11467
11511
|
const node = expr;
|
|
11468
11512
|
switch (node.kind) {
|
|
11469
|
-
case
|
|
11470
|
-
case
|
|
11471
|
-
case
|
|
11472
|
-
case
|
|
11473
|
-
case
|
|
11474
|
-
case
|
|
11513
|
+
case ts13.SyntaxKind.ParenthesizedExpression:
|
|
11514
|
+
case ts13.SyntaxKind.AsExpression:
|
|
11515
|
+
case ts13.SyntaxKind.SatisfiesExpression:
|
|
11516
|
+
case ts13.SyntaxKind.NonNullExpression:
|
|
11517
|
+
case ts13.SyntaxKind.TypeAssertionExpression:
|
|
11518
|
+
case ts13.SyntaxKind.PartiallyEmittedExpression:
|
|
11475
11519
|
return transformJsxExpression(node.expression, ctx, isClientOnly);
|
|
11476
|
-
case
|
|
11520
|
+
case ts13.SyntaxKind.JsxElement:
|
|
11477
11521
|
return transformJsxElement(node, ctx);
|
|
11478
|
-
case
|
|
11522
|
+
case ts13.SyntaxKind.JsxFragment:
|
|
11479
11523
|
return transformFragment(node, ctx);
|
|
11480
|
-
case
|
|
11524
|
+
case ts13.SyntaxKind.JsxSelfClosingElement:
|
|
11481
11525
|
return transformSelfClosingElement(node, ctx);
|
|
11482
|
-
case
|
|
11526
|
+
case ts13.SyntaxKind.ConditionalExpression:
|
|
11483
11527
|
return transformConditional(node, ctx);
|
|
11484
|
-
case
|
|
11485
|
-
if (node.operatorToken.kind ===
|
|
11528
|
+
case ts13.SyntaxKind.BinaryExpression: {
|
|
11529
|
+
if (node.operatorToken.kind === ts13.SyntaxKind.AmpersandAmpersandToken) {
|
|
11486
11530
|
return transformLogicalAnd(node, ctx);
|
|
11487
11531
|
}
|
|
11488
|
-
if ((node.operatorToken.kind ===
|
|
11532
|
+
if ((node.operatorToken.kind === ts13.SyntaxKind.QuestionQuestionToken || node.operatorToken.kind === ts13.SyntaxKind.BarBarToken) && (containsJsxInExpression(node.right) || callsJsxHelper(node.right, ctx))) {
|
|
11489
11533
|
return transformNullishCoalescing(node, ctx);
|
|
11490
11534
|
}
|
|
11491
11535
|
return null;
|
|
11492
11536
|
}
|
|
11493
|
-
case
|
|
11537
|
+
case ts13.SyntaxKind.CallExpression: {
|
|
11494
11538
|
const mapMethod = getMapLikeMethod(node);
|
|
11495
11539
|
if (mapMethod) {
|
|
11496
11540
|
const mapResult = transformMapCall(node, ctx, isClientOnly, mapMethod);
|
|
@@ -11498,7 +11542,7 @@ function transformJsxExpression(expr, ctx, isClientOnly = false) {
|
|
|
11498
11542
|
return mapResult;
|
|
11499
11543
|
}
|
|
11500
11544
|
const callee = node.expression;
|
|
11501
|
-
if (
|
|
11545
|
+
if (ts13.isIdentifier(callee)) {
|
|
11502
11546
|
const jsxFunc = ctx.analyzer.jsxFunctions.get(callee.text);
|
|
11503
11547
|
if (jsxFunc) {
|
|
11504
11548
|
return transformJsxFunctionCall(node, jsxFunc, ctx, isClientOnly);
|
|
@@ -11510,39 +11554,39 @@ function transformJsxExpression(expr, ctx, isClientOnly = false) {
|
|
|
11510
11554
|
}
|
|
11511
11555
|
return null;
|
|
11512
11556
|
}
|
|
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
|
|
11557
|
+
case ts13.SyntaxKind.Identifier:
|
|
11558
|
+
case ts13.SyntaxKind.StringLiteral:
|
|
11559
|
+
case ts13.SyntaxKind.NumericLiteral:
|
|
11560
|
+
case ts13.SyntaxKind.BigIntLiteral:
|
|
11561
|
+
case ts13.SyntaxKind.RegularExpressionLiteral:
|
|
11562
|
+
case ts13.SyntaxKind.NoSubstitutionTemplateLiteral:
|
|
11563
|
+
case ts13.SyntaxKind.TemplateExpression:
|
|
11564
|
+
case ts13.SyntaxKind.TaggedTemplateExpression:
|
|
11565
|
+
case ts13.SyntaxKind.TrueKeyword:
|
|
11566
|
+
case ts13.SyntaxKind.FalseKeyword:
|
|
11567
|
+
case ts13.SyntaxKind.NullKeyword:
|
|
11568
|
+
case ts13.SyntaxKind.ThisKeyword:
|
|
11569
|
+
case ts13.SyntaxKind.SuperKeyword:
|
|
11570
|
+
case ts13.SyntaxKind.ImportKeyword:
|
|
11571
|
+
case ts13.SyntaxKind.PropertyAccessExpression:
|
|
11572
|
+
case ts13.SyntaxKind.ElementAccessExpression:
|
|
11573
|
+
case ts13.SyntaxKind.PrefixUnaryExpression:
|
|
11574
|
+
case ts13.SyntaxKind.PostfixUnaryExpression:
|
|
11575
|
+
case ts13.SyntaxKind.TypeOfExpression:
|
|
11576
|
+
case ts13.SyntaxKind.VoidExpression:
|
|
11577
|
+
case ts13.SyntaxKind.DeleteExpression:
|
|
11578
|
+
case ts13.SyntaxKind.NewExpression:
|
|
11579
|
+
case ts13.SyntaxKind.ObjectLiteralExpression:
|
|
11580
|
+
case ts13.SyntaxKind.ArrowFunction:
|
|
11581
|
+
case ts13.SyntaxKind.FunctionExpression:
|
|
11582
|
+
case ts13.SyntaxKind.ClassExpression:
|
|
11583
|
+
case ts13.SyntaxKind.MetaProperty:
|
|
11584
|
+
case ts13.SyntaxKind.ExpressionWithTypeArguments:
|
|
11585
|
+
case ts13.SyntaxKind.CommaListExpression:
|
|
11586
|
+
case ts13.SyntaxKind.SyntheticExpression:
|
|
11587
|
+
case ts13.SyntaxKind.ArrayLiteralExpression:
|
|
11544
11588
|
return null;
|
|
11545
|
-
case
|
|
11589
|
+
case ts13.SyntaxKind.AwaitExpression:
|
|
11546
11590
|
ctx.analyzer.errors.push(createError(ErrorCodes.STAGE_AWAIT_IN_TEMPLATE, getSourceLocation(node, ctx.sourceFile, ctx.filePath)));
|
|
11547
11591
|
return {
|
|
11548
11592
|
type: "expression",
|
|
@@ -11553,16 +11597,16 @@ function transformJsxExpression(expr, ctx, isClientOnly = false) {
|
|
|
11553
11597
|
loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath),
|
|
11554
11598
|
origin: { phase: "tick", scope: "template", effect: "pure", freeRefs: [] }
|
|
11555
11599
|
};
|
|
11556
|
-
case
|
|
11600
|
+
case ts13.SyntaxKind.YieldExpression:
|
|
11557
11601
|
return null;
|
|
11558
|
-
case
|
|
11559
|
-
case
|
|
11560
|
-
case
|
|
11561
|
-
case
|
|
11562
|
-
case
|
|
11563
|
-
case
|
|
11564
|
-
case
|
|
11565
|
-
case
|
|
11602
|
+
case ts13.SyntaxKind.SpreadElement:
|
|
11603
|
+
case ts13.SyntaxKind.OmittedExpression:
|
|
11604
|
+
case ts13.SyntaxKind.JsxExpression:
|
|
11605
|
+
case ts13.SyntaxKind.JsxOpeningElement:
|
|
11606
|
+
case ts13.SyntaxKind.JsxOpeningFragment:
|
|
11607
|
+
case ts13.SyntaxKind.JsxClosingFragment:
|
|
11608
|
+
case ts13.SyntaxKind.JsxAttributes:
|
|
11609
|
+
case ts13.SyntaxKind.MissingDeclaration:
|
|
11566
11610
|
return null;
|
|
11567
11611
|
default:
|
|
11568
11612
|
return assertNever2(node);
|
|
@@ -11599,7 +11643,7 @@ function transformConditionalBranch(node, ctx) {
|
|
|
11599
11643
|
};
|
|
11600
11644
|
}
|
|
11601
11645
|
function getMapLikeMethod(node) {
|
|
11602
|
-
if (!
|
|
11646
|
+
if (!ts13.isPropertyAccessExpression(node.expression))
|
|
11603
11647
|
return null;
|
|
11604
11648
|
const name = node.expression.name.text;
|
|
11605
11649
|
if (name === "map")
|
|
@@ -11609,9 +11653,9 @@ function getMapLikeMethod(node) {
|
|
|
11609
11653
|
return null;
|
|
11610
11654
|
}
|
|
11611
11655
|
function isFilterCall(node) {
|
|
11612
|
-
if (!
|
|
11656
|
+
if (!ts13.isCallExpression(node))
|
|
11613
11657
|
return null;
|
|
11614
|
-
if (!
|
|
11658
|
+
if (!ts13.isPropertyAccessExpression(node.expression))
|
|
11615
11659
|
return null;
|
|
11616
11660
|
if (node.expression.name.text !== "filter")
|
|
11617
11661
|
return null;
|
|
@@ -11623,9 +11667,9 @@ function isFilterCall(node) {
|
|
|
11623
11667
|
};
|
|
11624
11668
|
}
|
|
11625
11669
|
function isSortCall(node) {
|
|
11626
|
-
if (!
|
|
11670
|
+
if (!ts13.isCallExpression(node))
|
|
11627
11671
|
return null;
|
|
11628
|
-
if (!
|
|
11672
|
+
if (!ts13.isPropertyAccessExpression(node.expression))
|
|
11629
11673
|
return null;
|
|
11630
11674
|
const methodName = node.expression.name.text;
|
|
11631
11675
|
if (methodName !== "sort" && methodName !== "toSorted")
|
|
@@ -11639,9 +11683,9 @@ function isSortCall(node) {
|
|
|
11639
11683
|
};
|
|
11640
11684
|
}
|
|
11641
11685
|
function isIteratorShapeCall(node) {
|
|
11642
|
-
if (!
|
|
11686
|
+
if (!ts13.isCallExpression(node))
|
|
11643
11687
|
return null;
|
|
11644
|
-
if (!
|
|
11688
|
+
if (!ts13.isPropertyAccessExpression(node.expression))
|
|
11645
11689
|
return null;
|
|
11646
11690
|
if (node.arguments.length !== 0)
|
|
11647
11691
|
return null;
|
|
@@ -11651,11 +11695,11 @@ function isIteratorShapeCall(node) {
|
|
|
11651
11695
|
return { array: node.expression.expression, shape: name };
|
|
11652
11696
|
}
|
|
11653
11697
|
function isObjectIteratorCall(node) {
|
|
11654
|
-
if (!
|
|
11698
|
+
if (!ts13.isCallExpression(node))
|
|
11655
11699
|
return null;
|
|
11656
|
-
if (!
|
|
11700
|
+
if (!ts13.isPropertyAccessExpression(node.expression))
|
|
11657
11701
|
return null;
|
|
11658
|
-
if (!
|
|
11702
|
+
if (!ts13.isIdentifier(node.expression.expression))
|
|
11659
11703
|
return null;
|
|
11660
11704
|
if (node.expression.expression.text !== "Object")
|
|
11661
11705
|
return null;
|
|
@@ -11680,7 +11724,7 @@ function extractSortComparator(callback, _method, ctx) {
|
|
|
11680
11724
|
` + `(reverse the operands for descending order).`
|
|
11681
11725
|
});
|
|
11682
11726
|
let resolvedNode = callback;
|
|
11683
|
-
if (
|
|
11727
|
+
if (ts13.isIdentifier(callback)) {
|
|
11684
11728
|
const resolved = resolveSortComparatorIdentifier(callback.text, ctx);
|
|
11685
11729
|
if (!resolved) {
|
|
11686
11730
|
return {
|
|
@@ -11690,7 +11734,7 @@ function extractSortComparator(callback, _method, ctx) {
|
|
|
11690
11734
|
}
|
|
11691
11735
|
resolvedNode = resolved;
|
|
11692
11736
|
}
|
|
11693
|
-
if (!
|
|
11737
|
+
if (!ts13.isArrowFunction(resolvedNode) && !ts13.isFunctionExpression(resolvedNode)) {
|
|
11694
11738
|
return {
|
|
11695
11739
|
result: null,
|
|
11696
11740
|
unsupportedReason: "Sort comparator must be an arrow function or function expression"
|
|
@@ -11717,11 +11761,11 @@ function resolveSortComparatorIdentifier(name, ctx) {
|
|
|
11717
11761
|
return null;
|
|
11718
11762
|
if (constInfo) {
|
|
11719
11763
|
const ast = parseConstInitializer(constInfo);
|
|
11720
|
-
return ast && (
|
|
11764
|
+
return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
|
|
11721
11765
|
}
|
|
11722
11766
|
if (fnInfo) {
|
|
11723
11767
|
const ast = parseFunctionInfoAsExpr(fnInfo);
|
|
11724
|
-
return ast && (
|
|
11768
|
+
return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
|
|
11725
11769
|
}
|
|
11726
11770
|
return null;
|
|
11727
11771
|
}
|
|
@@ -11732,11 +11776,11 @@ function resolveCallbackMethodFunctionReferenceIdentifier(name, analyzer) {
|
|
|
11732
11776
|
return null;
|
|
11733
11777
|
if (constInfo) {
|
|
11734
11778
|
const ast = parseConstInitializer(constInfo);
|
|
11735
|
-
return ast && (
|
|
11779
|
+
return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
|
|
11736
11780
|
}
|
|
11737
11781
|
if (fnInfo) {
|
|
11738
11782
|
const ast = parseFunctionInfoAsExpr(fnInfo);
|
|
11739
|
-
return ast && (
|
|
11783
|
+
return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
|
|
11740
11784
|
}
|
|
11741
11785
|
return null;
|
|
11742
11786
|
}
|
|
@@ -11792,13 +11836,13 @@ function resolveCallbackMethodFunctionReferences(expr, analyzer, bound = EMPTY_B
|
|
|
11792
11836
|
return visit2(expr, bound);
|
|
11793
11837
|
}
|
|
11794
11838
|
function extractFilterPredicate(callback, ctx) {
|
|
11795
|
-
if (!
|
|
11839
|
+
if (!ts13.isArrowFunction(callback))
|
|
11796
11840
|
return { result: null };
|
|
11797
11841
|
if (callback.parameters.length < 1)
|
|
11798
11842
|
return { result: null };
|
|
11799
11843
|
const firstParam = callback.parameters[0];
|
|
11800
|
-
if (!
|
|
11801
|
-
if (
|
|
11844
|
+
if (!ts13.isIdentifier(firstParam.name)) {
|
|
11845
|
+
if (ts13.isBlock(callback.body)) {
|
|
11802
11846
|
return {
|
|
11803
11847
|
result: null,
|
|
11804
11848
|
unsupportedReason: "Block body in a destructured filter param is not supported. Workaround: use an expression-body arrow, or add /* @client */."
|
|
@@ -11818,7 +11862,7 @@ function extractFilterPredicate(callback, ctx) {
|
|
|
11818
11862
|
return { result: null };
|
|
11819
11863
|
}
|
|
11820
11864
|
const param = firstParam.name.getText(ctx.sourceFile);
|
|
11821
|
-
if (
|
|
11865
|
+
if (ts13.isBlock(callback.body)) {
|
|
11822
11866
|
const raw2 = ctx.getJS(callback.body);
|
|
11823
11867
|
const statements = parseBlockBody(callback.body, ctx.sourceFile, (n) => ctx.getJS(n));
|
|
11824
11868
|
if (!statements) {
|
|
@@ -11844,7 +11888,7 @@ function extractFilterPredicate(callback, ctx) {
|
|
|
11844
11888
|
return { result: { param, predicate, raw } };
|
|
11845
11889
|
}
|
|
11846
11890
|
function extractLoopParamBindings(pattern) {
|
|
11847
|
-
if (
|
|
11891
|
+
if (ts13.isIdentifier(pattern))
|
|
11848
11892
|
return null;
|
|
11849
11893
|
const bindings = [];
|
|
11850
11894
|
let unsupported = false;
|
|
@@ -11853,7 +11897,7 @@ function extractLoopParamBindings(pattern) {
|
|
|
11853
11897
|
return false;
|
|
11854
11898
|
for (let i = 0;i < key.length; ) {
|
|
11855
11899
|
const cp = key.codePointAt(i);
|
|
11856
|
-
const ok = i === 0 ?
|
|
11900
|
+
const ok = i === 0 ? ts13.isIdentifierStart(cp, ts13.ScriptTarget.Latest) : ts13.isIdentifierPart(cp, ts13.ScriptTarget.Latest);
|
|
11857
11901
|
if (!ok)
|
|
11858
11902
|
return false;
|
|
11859
11903
|
i += cp > 65535 ? 2 : 1;
|
|
@@ -11866,17 +11910,17 @@ function extractLoopParamBindings(pattern) {
|
|
|
11866
11910
|
const walk = (p, prefix, segments) => {
|
|
11867
11911
|
if (unsupported)
|
|
11868
11912
|
return;
|
|
11869
|
-
if (
|
|
11913
|
+
if (ts13.isArrayBindingPattern(p)) {
|
|
11870
11914
|
const elements2 = p.elements;
|
|
11871
11915
|
for (let index = 0;index < elements2.length; index++) {
|
|
11872
11916
|
if (unsupported)
|
|
11873
11917
|
return;
|
|
11874
11918
|
const el = elements2[index];
|
|
11875
|
-
if (
|
|
11919
|
+
if (ts13.isOmittedExpression(el))
|
|
11876
11920
|
continue;
|
|
11877
11921
|
if (el.dotDotDotToken) {
|
|
11878
11922
|
internalInvariant(index === elements2.length - 1, "extractLoopParamBindings: array rest token in non-final position (parser should reject)");
|
|
11879
|
-
internalInvariant(
|
|
11923
|
+
internalInvariant(ts13.isIdentifier(el.name), "extractLoopParamBindings: array rest target is not an identifier (parser should reject)");
|
|
11880
11924
|
bindings.push({
|
|
11881
11925
|
name: el.name.text,
|
|
11882
11926
|
path: prefix,
|
|
@@ -11887,7 +11931,7 @@ function extractLoopParamBindings(pattern) {
|
|
|
11887
11931
|
}
|
|
11888
11932
|
const path = `${prefix}[${index}]`;
|
|
11889
11933
|
const nextSegments = [...segments, { kind: "index", index }];
|
|
11890
|
-
if (
|
|
11934
|
+
if (ts13.isIdentifier(el.name)) {
|
|
11891
11935
|
bindings.push({ name: el.name.text, path, segments: nextSegments });
|
|
11892
11936
|
} else {
|
|
11893
11937
|
walk(el.name, path, nextSegments);
|
|
@@ -11903,7 +11947,7 @@ function extractLoopParamBindings(pattern) {
|
|
|
11903
11947
|
const el = elements[i];
|
|
11904
11948
|
if (el.dotDotDotToken) {
|
|
11905
11949
|
internalInvariant(i === elements.length - 1, "extractLoopParamBindings: object rest token in non-final position (parser should reject)");
|
|
11906
|
-
internalInvariant(
|
|
11950
|
+
internalInvariant(ts13.isIdentifier(el.name), "extractLoopParamBindings: object rest target is not an identifier (parser should reject)");
|
|
11907
11951
|
bindings.push({
|
|
11908
11952
|
name: el.name.text,
|
|
11909
11953
|
path: prefix,
|
|
@@ -11915,17 +11959,17 @@ function extractLoopParamBindings(pattern) {
|
|
|
11915
11959
|
let keyText = null;
|
|
11916
11960
|
if (el.propertyName) {
|
|
11917
11961
|
const pn = el.propertyName;
|
|
11918
|
-
if (
|
|
11962
|
+
if (ts13.isIdentifier(pn))
|
|
11919
11963
|
keyText = pn.text;
|
|
11920
|
-
else if (
|
|
11964
|
+
else if (ts13.isStringLiteral(pn))
|
|
11921
11965
|
keyText = pn.text;
|
|
11922
|
-
else if (
|
|
11966
|
+
else if (ts13.isNumericLiteral(pn))
|
|
11923
11967
|
keyText = pn.text;
|
|
11924
11968
|
else {
|
|
11925
11969
|
unsupported = true;
|
|
11926
11970
|
return;
|
|
11927
11971
|
}
|
|
11928
|
-
} else if (
|
|
11972
|
+
} else if (ts13.isIdentifier(el.name)) {
|
|
11929
11973
|
keyText = el.name.text;
|
|
11930
11974
|
} else {
|
|
11931
11975
|
unsupported = true;
|
|
@@ -11935,14 +11979,14 @@ function extractLoopParamBindings(pattern) {
|
|
|
11935
11979
|
collectedKeys.push({ key: keyText, isIdent: keyIsIdent });
|
|
11936
11980
|
const path = appendDotAccess(prefix, keyText);
|
|
11937
11981
|
const nextSegments = [...segments, { kind: "field", key: keyText, isIdent: keyIsIdent }];
|
|
11938
|
-
if (
|
|
11982
|
+
if (ts13.isIdentifier(el.name)) {
|
|
11939
11983
|
bindings.push({ name: el.name.text, path, segments: nextSegments });
|
|
11940
11984
|
} else {
|
|
11941
11985
|
walk(el.name, path, nextSegments);
|
|
11942
11986
|
}
|
|
11943
11987
|
}
|
|
11944
11988
|
};
|
|
11945
|
-
if (
|
|
11989
|
+
if (ts13.isArrayBindingPattern(pattern) || ts13.isObjectBindingPattern(pattern)) {
|
|
11946
11990
|
walk(pattern, "", []);
|
|
11947
11991
|
if (unsupported)
|
|
11948
11992
|
return { unsupported: true };
|
|
@@ -11952,7 +11996,7 @@ function extractLoopParamBindings(pattern) {
|
|
|
11952
11996
|
}
|
|
11953
11997
|
function findKeyJsxAttribute(opening) {
|
|
11954
11998
|
for (const prop of opening.attributes.properties) {
|
|
11955
|
-
if (
|
|
11999
|
+
if (ts13.isJsxAttribute(prop) && prop.name.getText() === "key") {
|
|
11956
12000
|
return prop;
|
|
11957
12001
|
}
|
|
11958
12002
|
}
|
|
@@ -11997,7 +12041,7 @@ function keyAttrValueToExpr(v) {
|
|
|
11997
12041
|
function normalizeKeyExpr(expr) {
|
|
11998
12042
|
let out = "";
|
|
11999
12043
|
for (const tok of iterateJsTokens(expr)) {
|
|
12000
|
-
if (tok.kind ===
|
|
12044
|
+
if (tok.kind === ts13.SyntaxKind.WhitespaceTrivia || tok.kind === ts13.SyntaxKind.NewLineTrivia) {
|
|
12001
12045
|
continue;
|
|
12002
12046
|
}
|
|
12003
12047
|
out += expr.slice(tok.pos, tok.end);
|
|
@@ -12009,13 +12053,13 @@ function conditionalHasExplicitNullishBranch(cond) {
|
|
|
12009
12053
|
}
|
|
12010
12054
|
function branchHasExplicitNullish(branch) {
|
|
12011
12055
|
let b = branch;
|
|
12012
|
-
while (
|
|
12056
|
+
while (ts13.isParenthesizedExpression(b))
|
|
12013
12057
|
b = b.expression;
|
|
12014
|
-
if (b.kind ===
|
|
12058
|
+
if (b.kind === ts13.SyntaxKind.NullKeyword)
|
|
12015
12059
|
return true;
|
|
12016
|
-
if (
|
|
12060
|
+
if (ts13.isIdentifier(b) && b.text === "undefined")
|
|
12017
12061
|
return true;
|
|
12018
|
-
if (
|
|
12062
|
+
if (ts13.isConditionalExpression(b))
|
|
12019
12063
|
return conditionalHasExplicitNullishBranch(b);
|
|
12020
12064
|
return false;
|
|
12021
12065
|
}
|
|
@@ -12024,26 +12068,26 @@ function classifyKeyProblem(keyAttr, checker) {
|
|
|
12024
12068
|
return "missing";
|
|
12025
12069
|
if (!keyAttr.initializer)
|
|
12026
12070
|
return "missing";
|
|
12027
|
-
if (
|
|
12071
|
+
if (ts13.isJsxExpression(keyAttr.initializer) && !keyAttr.initializer.expression) {
|
|
12028
12072
|
return "missing";
|
|
12029
12073
|
}
|
|
12030
12074
|
let expr;
|
|
12031
|
-
if (
|
|
12075
|
+
if (ts13.isStringLiteral(keyAttr.initializer)) {
|
|
12032
12076
|
return null;
|
|
12033
|
-
} else if (
|
|
12077
|
+
} else if (ts13.isJsxExpression(keyAttr.initializer)) {
|
|
12034
12078
|
expr = keyAttr.initializer.expression;
|
|
12035
12079
|
}
|
|
12036
12080
|
if (!expr)
|
|
12037
12081
|
return null;
|
|
12038
|
-
if (expr.kind ===
|
|
12082
|
+
if (expr.kind === ts13.SyntaxKind.NullKeyword)
|
|
12039
12083
|
return null;
|
|
12040
|
-
if (
|
|
12084
|
+
if (ts13.isIdentifier(expr) && expr.text === "undefined")
|
|
12041
12085
|
return null;
|
|
12042
|
-
if (
|
|
12086
|
+
if (ts13.isConditionalExpression(expr) && conditionalHasExplicitNullishBranch(expr))
|
|
12043
12087
|
return null;
|
|
12044
12088
|
if (checker) {
|
|
12045
12089
|
const type = checker.getTypeAtLocation(expr);
|
|
12046
|
-
const isNullable = type.isUnion() ? type.types.some((t) => (t.flags & (
|
|
12090
|
+
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
12091
|
if (isNullable)
|
|
12048
12092
|
return "nullable-type";
|
|
12049
12093
|
}
|
|
@@ -12069,81 +12113,81 @@ function checkLoopKey(callback, ctx, isNested) {
|
|
|
12069
12113
|
ctx.analyzer.errors.push(createError(errorCode, getSourceLocation(locNode, ctx.sourceFile, ctx.filePath), { suggestion: { message: keyErrorSuggestion(problem) } }));
|
|
12070
12114
|
}
|
|
12071
12115
|
let body = callback.body;
|
|
12072
|
-
if (
|
|
12073
|
-
const ret = body.statements.find((s) =>
|
|
12116
|
+
if (ts13.isBlock(body)) {
|
|
12117
|
+
const ret = body.statements.find((s) => ts13.isReturnStatement(s) && s.expression != null);
|
|
12074
12118
|
if (!ret?.expression)
|
|
12075
12119
|
return;
|
|
12076
12120
|
body = ret.expression;
|
|
12077
12121
|
}
|
|
12078
|
-
while (
|
|
12122
|
+
while (ts13.isParenthesizedExpression(body))
|
|
12079
12123
|
body = body.expression;
|
|
12080
12124
|
function checkJsxOperand(node) {
|
|
12081
12125
|
let n = node;
|
|
12082
|
-
while (
|
|
12126
|
+
while (ts13.isParenthesizedExpression(n))
|
|
12083
12127
|
n = n.expression;
|
|
12084
|
-
if (
|
|
12128
|
+
if (ts13.isJsxElement(n))
|
|
12085
12129
|
checkOpening(n.openingElement);
|
|
12086
|
-
else if (
|
|
12130
|
+
else if (ts13.isJsxSelfClosingElement(n))
|
|
12087
12131
|
checkOpening(n);
|
|
12088
12132
|
}
|
|
12089
|
-
if (
|
|
12133
|
+
if (ts13.isConditionalExpression(body)) {
|
|
12090
12134
|
checkJsxOperand(body.whenTrue);
|
|
12091
12135
|
checkJsxOperand(body.whenFalse);
|
|
12092
12136
|
return;
|
|
12093
12137
|
}
|
|
12094
|
-
if (
|
|
12138
|
+
if (ts13.isBinaryExpression(body) && (body.operatorToken.kind === ts13.SyntaxKind.AmpersandAmpersandToken || body.operatorToken.kind === ts13.SyntaxKind.BarBarToken || body.operatorToken.kind === ts13.SyntaxKind.QuestionQuestionToken)) {
|
|
12095
12139
|
checkJsxOperand(body.left);
|
|
12096
12140
|
checkJsxOperand(body.right);
|
|
12097
12141
|
return;
|
|
12098
12142
|
}
|
|
12099
|
-
if (
|
|
12143
|
+
if (ts13.isJsxElement(body)) {
|
|
12100
12144
|
checkOpening(body.openingElement);
|
|
12101
12145
|
return;
|
|
12102
12146
|
}
|
|
12103
|
-
if (
|
|
12147
|
+
if (ts13.isJsxSelfClosingElement(body)) {
|
|
12104
12148
|
checkOpening(body);
|
|
12105
12149
|
return;
|
|
12106
12150
|
}
|
|
12107
12151
|
}
|
|
12108
12152
|
function flatMapProjectionCall(body) {
|
|
12109
12153
|
let expr;
|
|
12110
|
-
if (
|
|
12154
|
+
if (ts13.isBlock(body)) {
|
|
12111
12155
|
const real = body.statements;
|
|
12112
|
-
if (real.length !== 1 || !
|
|
12156
|
+
if (real.length !== 1 || !ts13.isReturnStatement(real[0]) || !real[0].expression)
|
|
12113
12157
|
return null;
|
|
12114
12158
|
expr = real[0].expression;
|
|
12115
12159
|
} else {
|
|
12116
12160
|
expr = body;
|
|
12117
12161
|
}
|
|
12118
|
-
while (
|
|
12162
|
+
while (ts13.isParenthesizedExpression(expr))
|
|
12119
12163
|
expr = expr.expression;
|
|
12120
|
-
if (!
|
|
12164
|
+
if (!ts13.isCallExpression(expr))
|
|
12121
12165
|
return null;
|
|
12122
12166
|
if (!getMapLikeMethod(expr))
|
|
12123
12167
|
return null;
|
|
12124
12168
|
const cb = expr.arguments[0];
|
|
12125
|
-
if (!cb || !
|
|
12169
|
+
if (!cb || !ts13.isArrowFunction(cb) && !ts13.isFunctionExpression(cb))
|
|
12126
12170
|
return null;
|
|
12127
12171
|
for (const p of cb.parameters) {
|
|
12128
|
-
if (!
|
|
12172
|
+
if (!ts13.isIdentifier(p.name))
|
|
12129
12173
|
return null;
|
|
12130
12174
|
}
|
|
12131
12175
|
let innerBody = cb.body;
|
|
12132
|
-
if (
|
|
12133
|
-
const ret = innerBody.statements.find((s) =>
|
|
12176
|
+
if (ts13.isBlock(innerBody)) {
|
|
12177
|
+
const ret = innerBody.statements.find((s) => ts13.isReturnStatement(s) && s.expression != null);
|
|
12134
12178
|
if (innerBody.statements.length !== 1 || !ret?.expression)
|
|
12135
12179
|
return null;
|
|
12136
12180
|
innerBody = ret.expression;
|
|
12137
12181
|
}
|
|
12138
|
-
while (
|
|
12182
|
+
while (ts13.isParenthesizedExpression(innerBody))
|
|
12139
12183
|
innerBody = innerBody.expression;
|
|
12140
12184
|
const isElementish = (n) => {
|
|
12141
12185
|
let m = n;
|
|
12142
|
-
while (
|
|
12186
|
+
while (ts13.isParenthesizedExpression(m))
|
|
12143
12187
|
m = m.expression;
|
|
12144
|
-
if (
|
|
12188
|
+
if (ts13.isJsxElement(m) || ts13.isJsxSelfClosingElement(m))
|
|
12145
12189
|
return leafIsWirelessElement(m);
|
|
12146
|
-
if (
|
|
12190
|
+
if (ts13.isConditionalExpression(m))
|
|
12147
12191
|
return isElementish(m.whenTrue) && isElementish(m.whenFalse);
|
|
12148
12192
|
return false;
|
|
12149
12193
|
};
|
|
@@ -12156,19 +12200,19 @@ function leafIsWirelessElement(el) {
|
|
|
12156
12200
|
const visit2 = (n) => {
|
|
12157
12201
|
if (!ok)
|
|
12158
12202
|
return;
|
|
12159
|
-
if (
|
|
12203
|
+
if (ts13.isJsxOpeningElement(n) || ts13.isJsxSelfClosingElement(n)) {
|
|
12160
12204
|
const tagNode = n.tagName;
|
|
12161
|
-
const isIntrinsic =
|
|
12205
|
+
const isIntrinsic = ts13.isIdentifier(tagNode) ? !/^[A-Z]/.test(tagNode.text) : ts13.isJsxNamespacedName(tagNode);
|
|
12162
12206
|
if (!isIntrinsic) {
|
|
12163
12207
|
ok = false;
|
|
12164
12208
|
return;
|
|
12165
12209
|
}
|
|
12166
12210
|
for (const attr of n.attributes.properties) {
|
|
12167
|
-
if (
|
|
12211
|
+
if (ts13.isJsxSpreadAttribute(attr)) {
|
|
12168
12212
|
ok = false;
|
|
12169
12213
|
return;
|
|
12170
12214
|
}
|
|
12171
|
-
if (
|
|
12215
|
+
if (ts13.isJsxAttribute(attr)) {
|
|
12172
12216
|
const name = attr.name.getText();
|
|
12173
12217
|
if (/^on[A-Z]/.test(name)) {
|
|
12174
12218
|
ok = false;
|
|
@@ -12177,11 +12221,11 @@ function leafIsWirelessElement(el) {
|
|
|
12177
12221
|
}
|
|
12178
12222
|
}
|
|
12179
12223
|
}
|
|
12180
|
-
if (
|
|
12224
|
+
if (ts13.isCallExpression(n) && getMapLikeMethod(n) && containsJsxInExpression(n)) {
|
|
12181
12225
|
ok = false;
|
|
12182
12226
|
return;
|
|
12183
12227
|
}
|
|
12184
|
-
|
|
12228
|
+
ts13.forEachChild(n, visit2);
|
|
12185
12229
|
};
|
|
12186
12230
|
visit2(el);
|
|
12187
12231
|
return ok;
|
|
@@ -12361,7 +12405,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12361
12405
|
let children = [];
|
|
12362
12406
|
let paramBindings;
|
|
12363
12407
|
let flatMapCallback;
|
|
12364
|
-
if (
|
|
12408
|
+
if (ts13.isArrowFunction(callback)) {
|
|
12365
12409
|
if (callback.parameters.length > 0) {
|
|
12366
12410
|
const firstParam = callback.parameters[0];
|
|
12367
12411
|
param = firstParam.name.getText(ctx.sourceFile);
|
|
@@ -12369,9 +12413,9 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12369
12413
|
paramType = firstParam.type.getText(ctx.sourceFile);
|
|
12370
12414
|
}
|
|
12371
12415
|
const isEntriesShape = iterationShape === "entries" || objectIteration === "entries";
|
|
12372
|
-
if (isEntriesShape &&
|
|
12373
|
-
const elements = firstParam.name.elements.filter((el) => !
|
|
12374
|
-
if (elements.length === 2 &&
|
|
12416
|
+
if (isEntriesShape && ts13.isArrayBindingPattern(firstParam.name)) {
|
|
12417
|
+
const elements = firstParam.name.elements.filter((el) => !ts13.isOmittedExpression(el));
|
|
12418
|
+
if (elements.length === 2 && ts13.isBindingElement(elements[0]) && ts13.isIdentifier(elements[0].name) && ts13.isBindingElement(elements[1]) && ts13.isIdentifier(elements[1].name)) {
|
|
12375
12419
|
index = elements[0].name.text;
|
|
12376
12420
|
param = elements[1].name.text;
|
|
12377
12421
|
} else {
|
|
@@ -12402,10 +12446,10 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12402
12446
|
ctx.scope = ctx.scope.enterLoopRow({ param, index, paramBindings });
|
|
12403
12447
|
ctx.loopDepth++;
|
|
12404
12448
|
const tryTransformRenderableBody = (expr) => {
|
|
12405
|
-
if (!
|
|
12449
|
+
if (!ts13.isBinaryExpression(expr))
|
|
12406
12450
|
return;
|
|
12407
12451
|
const op = expr.operatorToken.kind;
|
|
12408
|
-
if (op !==
|
|
12452
|
+
if (op !== ts13.SyntaxKind.AmpersandAmpersandToken && op !== ts13.SyntaxKind.BarBarToken && op !== ts13.SyntaxKind.QuestionQuestionToken) {
|
|
12409
12453
|
return;
|
|
12410
12454
|
}
|
|
12411
12455
|
if (!containsJsxInExpression(expr) && !callsJsxHelper(expr, ctx))
|
|
@@ -12415,33 +12459,33 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12415
12459
|
children = [transformed];
|
|
12416
12460
|
};
|
|
12417
12461
|
const body = callback.body;
|
|
12418
|
-
if (
|
|
12462
|
+
if (ts13.isJsxElement(body) || ts13.isJsxSelfClosingElement(body) || ts13.isJsxFragment(body)) {
|
|
12419
12463
|
const transformed = transformNode(body, ctx);
|
|
12420
12464
|
if (transformed) {
|
|
12421
12465
|
children = [transformed];
|
|
12422
12466
|
}
|
|
12423
|
-
} else if (
|
|
12467
|
+
} else if (ts13.isConditionalExpression(body)) {
|
|
12424
12468
|
children = [transformConditional(body, ctx)];
|
|
12425
|
-
} else if (
|
|
12469
|
+
} else if (ts13.isParenthesizedExpression(body)) {
|
|
12426
12470
|
let inner = body.expression;
|
|
12427
|
-
while (
|
|
12471
|
+
while (ts13.isParenthesizedExpression(inner)) {
|
|
12428
12472
|
inner = inner.expression;
|
|
12429
12473
|
}
|
|
12430
|
-
if (
|
|
12474
|
+
if (ts13.isJsxElement(inner) || ts13.isJsxSelfClosingElement(inner) || ts13.isJsxFragment(inner)) {
|
|
12431
12475
|
const transformed = transformNode(inner, ctx);
|
|
12432
12476
|
if (transformed) {
|
|
12433
12477
|
children = [transformed];
|
|
12434
12478
|
}
|
|
12435
|
-
} else if (
|
|
12479
|
+
} else if (ts13.isConditionalExpression(inner)) {
|
|
12436
12480
|
children = [transformConditional(inner, ctx)];
|
|
12437
|
-
} else if (method === "flatMap" &&
|
|
12481
|
+
} else if (method === "flatMap" && ts13.isArrayLiteralExpression(inner)) {
|
|
12438
12482
|
children = transformArrayLiteralChildren(inner, ctx);
|
|
12439
12483
|
} else {
|
|
12440
12484
|
tryTransformRenderableBody(inner);
|
|
12441
12485
|
}
|
|
12442
|
-
} else if (method === "flatMap" &&
|
|
12486
|
+
} else if (method === "flatMap" && ts13.isArrayLiteralExpression(body)) {
|
|
12443
12487
|
children = transformArrayLiteralChildren(body, ctx);
|
|
12444
|
-
} else if (
|
|
12488
|
+
} else if (ts13.isBlock(body)) {
|
|
12445
12489
|
const multiReturn = method !== "flatMap" ? extractMultiReturnJsxBranches(body, true) : null;
|
|
12446
12490
|
if (multiReturn && multiReturn.branches.length > 0) {
|
|
12447
12491
|
const loc = getSourceLocation(body, ctx.sourceFile, ctx.filePath);
|
|
@@ -12459,7 +12503,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12459
12503
|
}
|
|
12460
12504
|
}
|
|
12461
12505
|
}
|
|
12462
|
-
const returnStmt = children.length === 0 ? body.statements.find((s) =>
|
|
12506
|
+
const returnStmt = children.length === 0 ? body.statements.find((s) => ts13.isReturnStatement(s) && s.expression != null) : undefined;
|
|
12463
12507
|
let rowScopeBeforePreamble = null;
|
|
12464
12508
|
if (returnStmt) {
|
|
12465
12509
|
const preambleNames = new Set;
|
|
@@ -12480,10 +12524,10 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12480
12524
|
}
|
|
12481
12525
|
if (returnStmt && returnStmt.expression) {
|
|
12482
12526
|
let returnExpr = returnStmt.expression;
|
|
12483
|
-
while (
|
|
12527
|
+
while (ts13.isParenthesizedExpression(returnExpr)) {
|
|
12484
12528
|
returnExpr = returnExpr.expression;
|
|
12485
12529
|
}
|
|
12486
|
-
if (
|
|
12530
|
+
if (ts13.isJsxElement(returnExpr) || ts13.isJsxSelfClosingElement(returnExpr) || ts13.isJsxFragment(returnExpr)) {
|
|
12487
12531
|
const transformed = transformNode(returnExpr, ctx);
|
|
12488
12532
|
if (transformed) {
|
|
12489
12533
|
children = [transformed];
|
|
@@ -12565,7 +12609,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12565
12609
|
}
|
|
12566
12610
|
}
|
|
12567
12611
|
}
|
|
12568
|
-
if (method === "flatMap" && children.length === 0 && !flatMapCallback && !
|
|
12612
|
+
if (method === "flatMap" && children.length === 0 && !flatMapCallback && !ts13.isBlock(body)) {
|
|
12569
12613
|
flatMapCallback = buildFlatMapCallback(callback, body, ctx);
|
|
12570
12614
|
}
|
|
12571
12615
|
if (flatMapCallback)
|
|
@@ -12583,7 +12627,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12583
12627
|
}
|
|
12584
12628
|
if (children.length === 0 && !flatMapCallback) {
|
|
12585
12629
|
const cb = node.arguments[0];
|
|
12586
|
-
const cbBody = cb && (
|
|
12630
|
+
const cbBody = cb && (ts13.isArrowFunction(cb) || ts13.isFunctionExpression(cb)) ? cb.body : undefined;
|
|
12587
12631
|
if (cbBody && containsJsxInExpression(cbBody) && ctx.analyzer.errors.length === diagCountAtEntry) {
|
|
12588
12632
|
ctx.analyzer.errors.push(createError(ErrorCodes.UNSUPPORTED_JSX_PATTERN, getSourceLocation(cbBody, ctx.sourceFile, ctx.filePath), {
|
|
12589
12633
|
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 +12638,7 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12594
12638
|
}
|
|
12595
12639
|
return null;
|
|
12596
12640
|
}
|
|
12597
|
-
if (
|
|
12641
|
+
if (ts13.isArrowFunction(node.arguments[0]) && children.length > 0) {
|
|
12598
12642
|
checkLoopKey(node.arguments[0], ctx, isNested);
|
|
12599
12643
|
}
|
|
12600
12644
|
const itemConditional = children.length > 0 ? loopBodyItemConditional(children) : null;
|
|
@@ -12648,6 +12692,9 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12648
12692
|
const preambleRegions = preamble && !isStaticArray ? collectPreambleRegions(children, new Set(preamble.declaredNames), ctx) : undefined;
|
|
12649
12693
|
if (preamble && !isStaticArray) {
|
|
12650
12694
|
markPreambleAttrSlots(children, new Set(preamble.declaredNames), ctx);
|
|
12695
|
+
if (preamble.reactiveNames && preamble.reactiveNames.length > 0) {
|
|
12696
|
+
markPreambleConditionalReactivity(children, new Set(preamble.reactiveNames), ctx);
|
|
12697
|
+
}
|
|
12651
12698
|
}
|
|
12652
12699
|
const nestedComponents = collectNestedComponents(children).filter((c) => c.name !== childComponent?.name);
|
|
12653
12700
|
return {
|
|
@@ -12691,12 +12738,12 @@ function transformMapCall(node, ctx, isClientOnly = false, method = "map") {
|
|
|
12691
12738
|
function transformArrayLiteralChildren(arrayLiteral, ctx) {
|
|
12692
12739
|
const children = [];
|
|
12693
12740
|
for (const element of arrayLiteral.elements) {
|
|
12694
|
-
if (
|
|
12741
|
+
if (ts13.isSpreadElement(element))
|
|
12695
12742
|
continue;
|
|
12696
12743
|
let inner = element;
|
|
12697
|
-
while (
|
|
12744
|
+
while (ts13.isParenthesizedExpression(inner))
|
|
12698
12745
|
inner = inner.expression;
|
|
12699
|
-
if (
|
|
12746
|
+
if (ts13.isJsxElement(inner) || ts13.isJsxSelfClosingElement(inner) || ts13.isJsxFragment(inner)) {
|
|
12700
12747
|
const transformed = transformNode(inner, ctx);
|
|
12701
12748
|
if (transformed)
|
|
12702
12749
|
children.push(transformed);
|
|
@@ -12705,7 +12752,7 @@ function transformArrayLiteralChildren(arrayLiteral, ctx) {
|
|
|
12705
12752
|
return children;
|
|
12706
12753
|
}
|
|
12707
12754
|
function containsJsx(node) {
|
|
12708
|
-
if (
|
|
12755
|
+
if (ts13.isJsxElement(node) || ts13.isJsxSelfClosingElement(node) || ts13.isJsxFragment(node))
|
|
12709
12756
|
return true;
|
|
12710
12757
|
let found = false;
|
|
12711
12758
|
node.forEachChild((child) => {
|
|
@@ -12721,7 +12768,7 @@ function buildFlatMapCallback(callback, body, ctx) {
|
|
|
12721
12768
|
const leafIrs = [];
|
|
12722
12769
|
let refusalNode;
|
|
12723
12770
|
const collectJsx = (n, underTemplate) => {
|
|
12724
|
-
if (
|
|
12771
|
+
if (ts13.isJsxElement(n) || ts13.isJsxSelfClosingElement(n) || ts13.isJsxFragment(n)) {
|
|
12725
12772
|
if (underTemplate)
|
|
12726
12773
|
refusalNode ??= n;
|
|
12727
12774
|
leafSpans.push({ start: n.getStart(ctx.sourceFile), end: n.getEnd() });
|
|
@@ -12729,7 +12776,7 @@ function buildFlatMapCallback(callback, body, ctx) {
|
|
|
12729
12776
|
leafIrs.push(ir ?? { type: "text", value: "", loc: getSourceLocation(n, ctx.sourceFile, ctx.filePath) });
|
|
12730
12777
|
return;
|
|
12731
12778
|
}
|
|
12732
|
-
const inTemplate = underTemplate ||
|
|
12779
|
+
const inTemplate = underTemplate || ts13.isTemplateExpression(n) || ts13.isTaggedTemplateExpression(n);
|
|
12733
12780
|
n.forEachChild((c) => collectJsx(c, inTemplate));
|
|
12734
12781
|
};
|
|
12735
12782
|
collectJsx(body, false);
|
|
@@ -12905,6 +12952,33 @@ function markPreambleAttrSlots(nodes, declared, ctx) {
|
|
|
12905
12952
|
};
|
|
12906
12953
|
visit2(nodes);
|
|
12907
12954
|
}
|
|
12955
|
+
function markPreambleConditionalReactivity(nodes, reactiveNames, ctx) {
|
|
12956
|
+
if (reactiveNames.size === 0)
|
|
12957
|
+
return;
|
|
12958
|
+
const visit2 = (list) => {
|
|
12959
|
+
for (const node of list) {
|
|
12960
|
+
switch (node.type) {
|
|
12961
|
+
case "element":
|
|
12962
|
+
case "fragment":
|
|
12963
|
+
visit2(node.children);
|
|
12964
|
+
break;
|
|
12965
|
+
case "conditional": {
|
|
12966
|
+
if (!node.reactive) {
|
|
12967
|
+
const refs = extractFreeIdentifiersFromText(node.condition);
|
|
12968
|
+
if ([...refs].some((r) => reactiveNames.has(r))) {
|
|
12969
|
+
node.reactive = true;
|
|
12970
|
+
if (!node.slotId)
|
|
12971
|
+
node.slotId = generateSlotId(ctx);
|
|
12972
|
+
}
|
|
12973
|
+
}
|
|
12974
|
+
visit2([node.whenTrue, ...node.whenFalse ? [node.whenFalse] : []]);
|
|
12975
|
+
break;
|
|
12976
|
+
}
|
|
12977
|
+
}
|
|
12978
|
+
}
|
|
12979
|
+
};
|
|
12980
|
+
visit2(nodes);
|
|
12981
|
+
}
|
|
12908
12982
|
function attrValueText(value) {
|
|
12909
12983
|
if (value.kind === "expression")
|
|
12910
12984
|
return value.expr;
|
|
@@ -12920,24 +12994,46 @@ function attrValueText(value) {
|
|
|
12920
12994
|
return out.join(" ");
|
|
12921
12995
|
}
|
|
12922
12996
|
function collectBindingNames2(name, out) {
|
|
12923
|
-
if (
|
|
12997
|
+
if (ts13.isIdentifier(name)) {
|
|
12924
12998
|
out.add(name.text);
|
|
12925
12999
|
return;
|
|
12926
13000
|
}
|
|
12927
13001
|
for (const el of name.elements) {
|
|
12928
|
-
if (
|
|
13002
|
+
if (ts13.isBindingElement(el))
|
|
12929
13003
|
collectBindingNames2(el.name, out);
|
|
12930
13004
|
}
|
|
12931
13005
|
}
|
|
12932
13006
|
function collectPreambleDeclaredNames(stmt, out) {
|
|
12933
|
-
if (
|
|
13007
|
+
if (ts13.isVariableStatement(stmt)) {
|
|
12934
13008
|
for (const decl of stmt.declarationList.declarations) {
|
|
12935
13009
|
collectBindingNames2(decl.name, out);
|
|
12936
13010
|
}
|
|
12937
|
-
} else if (
|
|
13011
|
+
} else if (ts13.isFunctionDeclaration(stmt) && stmt.name) {
|
|
12938
13012
|
out.add(stmt.name.text);
|
|
12939
13013
|
}
|
|
12940
13014
|
}
|
|
13015
|
+
function computePreambleReactiveNames(statements, ctx) {
|
|
13016
|
+
const reactiveNames = new Set;
|
|
13017
|
+
for (const stmt of statements) {
|
|
13018
|
+
if (!ts13.isVariableStatement(stmt))
|
|
13019
|
+
continue;
|
|
13020
|
+
for (const decl of stmt.declarationList.declarations) {
|
|
13021
|
+
if (!decl.initializer)
|
|
13022
|
+
continue;
|
|
13023
|
+
const boundNames = new Set;
|
|
13024
|
+
collectBindingNames2(decl.name, boundNames);
|
|
13025
|
+
const initText = ctx.getJS(decl.initializer);
|
|
13026
|
+
const initFreeRefs = extractFreeIdentifiersFromNode(decl.initializer);
|
|
13027
|
+
const readsEarlierReactive = [...initFreeRefs].some((r) => reactiveNames.has(r));
|
|
13028
|
+
const isReactive = readsEarlierReactive || isReactiveExpression(initText, ctx, decl.initializer);
|
|
13029
|
+
if (isReactive) {
|
|
13030
|
+
for (const n of boundNames)
|
|
13031
|
+
reactiveNames.add(n);
|
|
13032
|
+
}
|
|
13033
|
+
}
|
|
13034
|
+
}
|
|
13035
|
+
return reactiveNames;
|
|
13036
|
+
}
|
|
12941
13037
|
function preambleFromValueStatements(statements, ctx) {
|
|
12942
13038
|
const segments = [];
|
|
12943
13039
|
const typedParts = [];
|
|
@@ -12952,21 +13048,23 @@ function preambleFromValueStatements(statements, ctx) {
|
|
|
12952
13048
|
typedParts.push(raw0.endsWith(";") ? raw0 : raw0 + ";");
|
|
12953
13049
|
segments.push(tjs !== js ? { kind: "js", text: js, templateText: tjs } : { kind: "js", text: js });
|
|
12954
13050
|
}
|
|
13051
|
+
const reactiveNames = computePreambleReactiveNames(statements, ctx);
|
|
12955
13052
|
return {
|
|
12956
13053
|
segments: trimPreambleSegments(segments),
|
|
12957
13054
|
ssrText: tsxSourceText(typedParts.join(" ")),
|
|
12958
13055
|
declaredNames: [...declared],
|
|
12959
13056
|
builderNames: [],
|
|
12960
|
-
declarations: neutralPreambleDeclarations(statements, ctx) ?? undefined
|
|
13057
|
+
declarations: neutralPreambleDeclarations(statements, ctx) ?? undefined,
|
|
13058
|
+
reactiveNames: reactiveNames.size > 0 ? [...reactiveNames] : undefined
|
|
12961
13059
|
};
|
|
12962
13060
|
}
|
|
12963
13061
|
function neutralPreambleDeclarations(statements, ctx) {
|
|
12964
13062
|
const out = [];
|
|
12965
13063
|
for (const stmt of statements) {
|
|
12966
|
-
if (!
|
|
13064
|
+
if (!ts13.isVariableStatement(stmt))
|
|
12967
13065
|
return null;
|
|
12968
13066
|
for (const decl of stmt.declarationList.declarations) {
|
|
12969
|
-
if (!
|
|
13067
|
+
if (!ts13.isIdentifier(decl.name))
|
|
12970
13068
|
return null;
|
|
12971
13069
|
if (!decl.initializer)
|
|
12972
13070
|
return null;
|
|
@@ -12999,11 +13097,11 @@ function buildPreambleSegments(statements, returnStmt, ctx) {
|
|
|
12999
13097
|
let refusalNode;
|
|
13000
13098
|
const recordBuilderTarget = (leaf, stmt) => {
|
|
13001
13099
|
for (let n = leaf.parent;n && n !== stmt.parent; n = n.parent) {
|
|
13002
|
-
if (
|
|
13100
|
+
if (ts13.isCallExpression(n) && ts13.isPropertyAccessExpression(n.expression) && (n.expression.name.text === "push" || n.expression.name.text === "unshift") && ts13.isIdentifier(n.expression.expression)) {
|
|
13003
13101
|
builders.add(n.expression.expression.text);
|
|
13004
13102
|
return;
|
|
13005
13103
|
}
|
|
13006
|
-
if (
|
|
13104
|
+
if (ts13.isVariableDeclaration(n) && ts13.isIdentifier(n.name)) {
|
|
13007
13105
|
builders.add(n.name.text);
|
|
13008
13106
|
return;
|
|
13009
13107
|
}
|
|
@@ -13016,7 +13114,7 @@ function buildPreambleSegments(statements, returnStmt, ctx) {
|
|
|
13016
13114
|
const leafSpans = [];
|
|
13017
13115
|
const leafIrs = [];
|
|
13018
13116
|
const collect = (n, underTemplate) => {
|
|
13019
|
-
if (
|
|
13117
|
+
if (ts13.isJsxElement(n) || ts13.isJsxSelfClosingElement(n) || ts13.isJsxFragment(n)) {
|
|
13020
13118
|
if (underTemplate)
|
|
13021
13119
|
refusalNode ??= n;
|
|
13022
13120
|
recordBuilderTarget(n, stmt);
|
|
@@ -13027,7 +13125,7 @@ function buildPreambleSegments(statements, returnStmt, ctx) {
|
|
|
13027
13125
|
leafIrs.push(ir ?? { type: "text", value: "", loc: getSourceLocation(n, ctx.sourceFile, ctx.filePath) });
|
|
13028
13126
|
return;
|
|
13029
13127
|
}
|
|
13030
|
-
const inTemplate = underTemplate ||
|
|
13128
|
+
const inTemplate = underTemplate || ts13.isTemplateExpression(n) || ts13.isTaggedTemplateExpression(n);
|
|
13031
13129
|
n.forEachChild((c) => collect(c, inTemplate));
|
|
13032
13130
|
};
|
|
13033
13131
|
collect(stmt, false);
|
|
@@ -13131,13 +13229,13 @@ function expandSpreadAttribute(attr, ctx) {
|
|
|
13131
13229
|
}];
|
|
13132
13230
|
}
|
|
13133
13231
|
function attrFreeIdentifiers(attr) {
|
|
13134
|
-
if (!attr.initializer || !
|
|
13232
|
+
if (!attr.initializer || !ts13.isJsxExpression(attr.initializer) || !attr.initializer.expression) {
|
|
13135
13233
|
return;
|
|
13136
13234
|
}
|
|
13137
13235
|
return extractFreeIdentifiersFromNode(attr.initializer.expression);
|
|
13138
13236
|
}
|
|
13139
13237
|
function computeReactivityFlags(attr, ctx) {
|
|
13140
|
-
if (!attr.initializer || !
|
|
13238
|
+
if (!attr.initializer || !ts13.isJsxExpression(attr.initializer) || !attr.initializer.expression) {
|
|
13141
13239
|
return {};
|
|
13142
13240
|
}
|
|
13143
13241
|
const expr = attr.initializer.expression;
|
|
@@ -13163,22 +13261,22 @@ function processAttributes(attributes, ctx) {
|
|
|
13163
13261
|
const events = [];
|
|
13164
13262
|
let ref = null;
|
|
13165
13263
|
for (const attr of attributes.properties) {
|
|
13166
|
-
if (
|
|
13264
|
+
if (ts13.isJsxSpreadAttribute(attr)) {
|
|
13167
13265
|
attrs.push(...expandSpreadAttribute(attr, ctx));
|
|
13168
13266
|
continue;
|
|
13169
13267
|
}
|
|
13170
|
-
if (!
|
|
13268
|
+
if (!ts13.isJsxAttribute(attr))
|
|
13171
13269
|
continue;
|
|
13172
13270
|
const rawName = attr.name.getText(ctx.sourceFile);
|
|
13173
13271
|
if (rawName === "ref") {
|
|
13174
|
-
if (attr.initializer &&
|
|
13272
|
+
if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
13175
13273
|
reportJsxBranchLocalInCallback(attr.initializer.expression, ctx);
|
|
13176
13274
|
ref = ctx.getJS(attr.initializer.expression);
|
|
13177
13275
|
}
|
|
13178
13276
|
continue;
|
|
13179
13277
|
}
|
|
13180
13278
|
if (/^on[A-Z]/.test(rawName)) {
|
|
13181
|
-
if (attr.initializer &&
|
|
13279
|
+
if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
13182
13280
|
const eventName = rawName.slice(2).toLowerCase();
|
|
13183
13281
|
reportJsxBranchLocalInCallback(attr.initializer.expression, ctx);
|
|
13184
13282
|
events.push({
|
|
@@ -13193,7 +13291,7 @@ function processAttributes(attributes, ctx) {
|
|
|
13193
13291
|
const name = toHTMLAttrName(rawName);
|
|
13194
13292
|
let value = getAttributeValue(attr, ctx);
|
|
13195
13293
|
let clientOnly;
|
|
13196
|
-
if (attr.initializer &&
|
|
13294
|
+
if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
13197
13295
|
if (value.kind === "expression" && value.templateExpr === undefined) {
|
|
13198
13296
|
const rewritten = rewriteBarePropRefs2(value.expr, attr.initializer.expression, ctx);
|
|
13199
13297
|
if (rewritten !== value.expr) {
|
|
@@ -13220,55 +13318,55 @@ function getAttributeValue(attr, ctx) {
|
|
|
13220
13318
|
if (!attr.initializer) {
|
|
13221
13319
|
return AttrValueOf.booleanAttr();
|
|
13222
13320
|
}
|
|
13223
|
-
if (
|
|
13321
|
+
if (ts13.isStringLiteral(attr.initializer)) {
|
|
13224
13322
|
return AttrValueOf.literal(decodeEntities(attr.initializer.text));
|
|
13225
13323
|
}
|
|
13226
|
-
if (
|
|
13324
|
+
if (ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
13227
13325
|
let expr = attr.initializer.expression;
|
|
13228
|
-
if (
|
|
13326
|
+
if (ts13.isIdentifier(expr)) {
|
|
13229
13327
|
const branchInit = ctx._branchScopeVars?.get(expr.text);
|
|
13230
13328
|
if (branchInit && !initializerShapeContainsJsx(branchInit)) {
|
|
13231
13329
|
expr = branchInit;
|
|
13232
13330
|
}
|
|
13233
13331
|
}
|
|
13234
13332
|
expr = tryDesugarInterleaveTaggedTemplate(expr, ctx);
|
|
13235
|
-
if (
|
|
13333
|
+
if (ts13.isAwaitExpression(expr)) {
|
|
13236
13334
|
ctx.analyzer.errors.push(createError(ErrorCodes.STAGE_AWAIT_IN_TEMPLATE, getSourceLocation(expr, ctx.sourceFile, ctx.filePath)));
|
|
13237
13335
|
return AttrValueOf.expression("undefined");
|
|
13238
13336
|
}
|
|
13239
13337
|
checkBareSignalOrMemoIdentifier(expr, ctx);
|
|
13240
|
-
if (attr.name.getText(ctx.sourceFile) === "style" &&
|
|
13338
|
+
if (attr.name.getText(ctx.sourceFile) === "style" && ts13.isObjectLiteralExpression(expr)) {
|
|
13241
13339
|
const cssString = tryStaticStyleObjectToCss(expr);
|
|
13242
13340
|
if (cssString !== null) {
|
|
13243
13341
|
return AttrValueOf.literal(cssString);
|
|
13244
13342
|
}
|
|
13245
13343
|
}
|
|
13246
|
-
if (
|
|
13344
|
+
if (ts13.isTemplateExpression(expr)) {
|
|
13247
13345
|
const parts = parseTemplateLiteral(expr, ctx);
|
|
13248
13346
|
if (parts.some((p) => p.type === "ternary" || p.type === "lookup")) {
|
|
13249
13347
|
return AttrValueOf.template(parts);
|
|
13250
13348
|
}
|
|
13251
13349
|
}
|
|
13252
|
-
if (
|
|
13350
|
+
if (ts13.isElementAccessExpression(expr) && !ts13.isStringLiteralLike(expr.argumentExpression) && !ts13.isNumericLiteral(expr.argumentExpression)) {
|
|
13253
13351
|
const parts = tryResolveTemplateSpanFromConst(expr, ctx);
|
|
13254
13352
|
if (parts) {
|
|
13255
13353
|
return AttrValueOf.template(parts);
|
|
13256
13354
|
}
|
|
13257
13355
|
}
|
|
13258
|
-
if (
|
|
13356
|
+
if (ts13.isIdentifier(expr)) {
|
|
13259
13357
|
const resolved = tryResolveIdentifierAsTemplateLiteral(expr, ctx);
|
|
13260
13358
|
if (resolved) {
|
|
13261
13359
|
return AttrValueOf.template(resolved);
|
|
13262
13360
|
}
|
|
13263
13361
|
}
|
|
13264
|
-
if (
|
|
13362
|
+
if (ts13.isConditionalExpression(expr)) {
|
|
13265
13363
|
const ternary = parseTernary(expr, ctx);
|
|
13266
13364
|
if (ternary) {
|
|
13267
13365
|
return AttrValueOf.template([ternary]);
|
|
13268
13366
|
}
|
|
13269
13367
|
}
|
|
13270
|
-
if (
|
|
13271
|
-
if (
|
|
13368
|
+
if (ts13.isBinaryExpression(expr) && expr.operatorToken.kind === ts13.SyntaxKind.BarBarToken) {
|
|
13369
|
+
if (ts13.isIdentifier(expr.right) && expr.right.text === "undefined") {
|
|
13272
13370
|
const baseExpr = ctx.getJS(expr.left);
|
|
13273
13371
|
return AttrValueOf.expression(baseExpr, { presenceOrUndefined: true });
|
|
13274
13372
|
}
|
|
@@ -13281,11 +13379,11 @@ function getAttributeValue(attr, ctx) {
|
|
|
13281
13379
|
function tryStaticStyleObjectToCss(expr) {
|
|
13282
13380
|
const parts = [];
|
|
13283
13381
|
for (const prop of expr.properties) {
|
|
13284
|
-
if (!
|
|
13382
|
+
if (!ts13.isPropertyAssignment(prop))
|
|
13285
13383
|
return null;
|
|
13286
|
-
if (!
|
|
13384
|
+
if (!ts13.isIdentifier(prop.name) && !ts13.isStringLiteral(prop.name))
|
|
13287
13385
|
return null;
|
|
13288
|
-
if (!
|
|
13386
|
+
if (!ts13.isStringLiteral(prop.initializer))
|
|
13289
13387
|
return null;
|
|
13290
13388
|
const key = cssKebabCase(prop.name.text);
|
|
13291
13389
|
parts.push(`${key}:${prop.initializer.text}`);
|
|
@@ -13298,7 +13396,7 @@ function parseTemplateLiteral(expr, ctx) {
|
|
|
13298
13396
|
parts.push({ type: "string", value: expr.head.text });
|
|
13299
13397
|
}
|
|
13300
13398
|
for (const span of expr.templateSpans) {
|
|
13301
|
-
if (
|
|
13399
|
+
if (ts13.isConditionalExpression(span.expression)) {
|
|
13302
13400
|
const ternary = parseTernary(span.expression, ctx);
|
|
13303
13401
|
if (ternary) {
|
|
13304
13402
|
parts.push(ternary);
|
|
@@ -13324,7 +13422,7 @@ function parseTemplateLiteral(expr, ctx) {
|
|
|
13324
13422
|
return parts;
|
|
13325
13423
|
}
|
|
13326
13424
|
function tryResolveTemplateSpanFromConst(expr, ctx) {
|
|
13327
|
-
if (
|
|
13425
|
+
if (ts13.isIdentifier(expr)) {
|
|
13328
13426
|
if (ctx.scope.isBound(expr.text))
|
|
13329
13427
|
return null;
|
|
13330
13428
|
const constInfo = findLocalConst(expr.text, ctx.analyzer);
|
|
@@ -13333,13 +13431,13 @@ function tryResolveTemplateSpanFromConst(expr, ctx) {
|
|
|
13333
13431
|
const ast = parseConstInitializer(constInfo);
|
|
13334
13432
|
if (!ast)
|
|
13335
13433
|
return null;
|
|
13336
|
-
if (
|
|
13434
|
+
if (ts13.isStringLiteral(ast) || ts13.isNoSubstitutionTemplateLiteral(ast)) {
|
|
13337
13435
|
return [{ type: "string", value: ast.text }];
|
|
13338
13436
|
}
|
|
13339
13437
|
return null;
|
|
13340
13438
|
}
|
|
13341
|
-
if (
|
|
13342
|
-
if (!
|
|
13439
|
+
if (ts13.isElementAccessExpression(expr)) {
|
|
13440
|
+
if (!ts13.isIdentifier(expr.expression))
|
|
13343
13441
|
return null;
|
|
13344
13442
|
if (ctx.scope.isBound(expr.expression.text))
|
|
13345
13443
|
return null;
|
|
@@ -13347,17 +13445,17 @@ function tryResolveTemplateSpanFromConst(expr, ctx) {
|
|
|
13347
13445
|
if (!constInfo)
|
|
13348
13446
|
return null;
|
|
13349
13447
|
const ast = parseConstInitializer(constInfo);
|
|
13350
|
-
if (!ast || !
|
|
13448
|
+
if (!ast || !ts13.isObjectLiteralExpression(ast))
|
|
13351
13449
|
return null;
|
|
13352
13450
|
const cases = {};
|
|
13353
13451
|
for (const prop of ast.properties) {
|
|
13354
|
-
if (!
|
|
13452
|
+
if (!ts13.isPropertyAssignment(prop))
|
|
13355
13453
|
return null;
|
|
13356
|
-
const keyName = prop.name && (
|
|
13454
|
+
const keyName = prop.name && (ts13.isStringLiteral(prop.name) || ts13.isIdentifier(prop.name)) ? prop.name.text : null;
|
|
13357
13455
|
if (!keyName)
|
|
13358
13456
|
return null;
|
|
13359
13457
|
const value = prop.initializer;
|
|
13360
|
-
if (
|
|
13458
|
+
if (ts13.isStringLiteral(value) || ts13.isNoSubstitutionTemplateLiteral(value)) {
|
|
13361
13459
|
cases[keyName] = value.text;
|
|
13362
13460
|
} else {
|
|
13363
13461
|
return null;
|
|
@@ -13404,17 +13502,17 @@ function hasDynamicTagBinding(name, sourceFile) {
|
|
|
13404
13502
|
const visit2 = (node) => {
|
|
13405
13503
|
if (found)
|
|
13406
13504
|
return;
|
|
13407
|
-
if (
|
|
13505
|
+
if (ts13.isVariableDeclaration(node) && ts13.isIdentifier(node.name) && node.name.text === name && node.initializer) {
|
|
13408
13506
|
let init = node.initializer;
|
|
13409
|
-
while (
|
|
13507
|
+
while (ts13.isAsExpression(init) || ts13.isSatisfiesExpression(init) || ts13.isParenthesizedExpression(init) || ts13.isNonNullExpression(init)) {
|
|
13410
13508
|
init = init.expression;
|
|
13411
13509
|
}
|
|
13412
|
-
if (
|
|
13510
|
+
if (ts13.isPropertyAccessExpression(init) && init.name.text === "tag") {
|
|
13413
13511
|
found = true;
|
|
13414
13512
|
return;
|
|
13415
13513
|
}
|
|
13416
13514
|
}
|
|
13417
|
-
|
|
13515
|
+
ts13.forEachChild(node, visit2);
|
|
13418
13516
|
};
|
|
13419
13517
|
visit2(sourceFile);
|
|
13420
13518
|
return found;
|
|
@@ -13428,13 +13526,13 @@ function tryResolveIdentifierAsTemplateLiteral(ident, ctx) {
|
|
|
13428
13526
|
const ast = parseConstInitializer(constInfo);
|
|
13429
13527
|
if (!ast)
|
|
13430
13528
|
return null;
|
|
13431
|
-
if (
|
|
13529
|
+
if (ts13.isNoSubstitutionTemplateLiteral(ast) || ts13.isStringLiteral(ast)) {
|
|
13432
13530
|
return [{ type: "string", value: ast.text }];
|
|
13433
13531
|
}
|
|
13434
|
-
if (
|
|
13532
|
+
if (ts13.isElementAccessExpression(ast) && !ts13.isStringLiteralLike(ast.argumentExpression) && !ts13.isNumericLiteral(ast.argumentExpression)) {
|
|
13435
13533
|
return tryResolveTemplateSpanFromConst(ast, ctx);
|
|
13436
13534
|
}
|
|
13437
|
-
if (!
|
|
13535
|
+
if (!ts13.isTemplateExpression(ast))
|
|
13438
13536
|
return null;
|
|
13439
13537
|
let resolvedAny = false;
|
|
13440
13538
|
const parts = [];
|
|
@@ -13472,14 +13570,14 @@ function parseConstInitializerImpl(c) {
|
|
|
13472
13570
|
if (!c.value)
|
|
13473
13571
|
return null;
|
|
13474
13572
|
const wrapped = `const __bf_resolve__ = (${c.value})`;
|
|
13475
|
-
const sf =
|
|
13573
|
+
const sf = ts13.createSourceFile("__bf_resolve.ts", wrapped, ts13.ScriptTarget.Latest, true, ts13.ScriptKind.TS);
|
|
13476
13574
|
const stmt = sf.statements[0];
|
|
13477
|
-
if (!stmt || !
|
|
13575
|
+
if (!stmt || !ts13.isVariableStatement(stmt))
|
|
13478
13576
|
return null;
|
|
13479
13577
|
const decl = stmt.declarationList.declarations[0];
|
|
13480
13578
|
if (!decl?.initializer)
|
|
13481
13579
|
return null;
|
|
13482
|
-
return
|
|
13580
|
+
return ts13.isParenthesizedExpression(decl.initializer) ? decl.initializer.expression : decl.initializer;
|
|
13483
13581
|
}
|
|
13484
13582
|
function astText(node) {
|
|
13485
13583
|
return node.getText(node.getSourceFile());
|
|
@@ -13499,9 +13597,9 @@ function parseFunctionInfoAsExprImpl(fn) {
|
|
|
13499
13597
|
const params = fn.typedParams !== undefined ? fn.typedParams : fn.params.map(formatParamWithType).join(", ");
|
|
13500
13598
|
const body = fn.typedBody ?? fn.body;
|
|
13501
13599
|
const wrapped = `const __bf_resolve_fn__ = function(${params}) ${body}`;
|
|
13502
|
-
const sf =
|
|
13600
|
+
const sf = ts13.createSourceFile("__bf_resolve_fn.ts", wrapped, ts13.ScriptTarget.Latest, true, ts13.ScriptKind.TS);
|
|
13503
13601
|
const stmt = sf.statements[0];
|
|
13504
|
-
if (!stmt || !
|
|
13602
|
+
if (!stmt || !ts13.isVariableStatement(stmt))
|
|
13505
13603
|
return null;
|
|
13506
13604
|
const decl = stmt.declarationList.declarations[0];
|
|
13507
13605
|
if (!decl?.initializer)
|
|
@@ -13509,9 +13607,9 @@ function parseFunctionInfoAsExprImpl(fn) {
|
|
|
13509
13607
|
return decl.initializer;
|
|
13510
13608
|
}
|
|
13511
13609
|
function tryDesugarInterleaveTaggedTemplate(expr, ctx) {
|
|
13512
|
-
if (!
|
|
13610
|
+
if (!ts13.isTaggedTemplateExpression(expr))
|
|
13513
13611
|
return expr;
|
|
13514
|
-
if (!
|
|
13612
|
+
if (!ts13.isIdentifier(expr.tag))
|
|
13515
13613
|
return expr;
|
|
13516
13614
|
const resolvedTag = resolveInterleaveTagIdentifier(expr.tag.text, ctx);
|
|
13517
13615
|
if (!resolvedTag)
|
|
@@ -13528,23 +13626,23 @@ function resolveInterleaveTagIdentifier(name, ctx) {
|
|
|
13528
13626
|
return null;
|
|
13529
13627
|
if (constInfo) {
|
|
13530
13628
|
const ast = parseConstInitializer(constInfo);
|
|
13531
|
-
return ast && (
|
|
13629
|
+
return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
|
|
13532
13630
|
}
|
|
13533
13631
|
if (fnInfo) {
|
|
13534
13632
|
const ast = parseFunctionInfoAsExpr(fnInfo);
|
|
13535
|
-
return ast && (
|
|
13633
|
+
return ast && (ts13.isArrowFunction(ast) || ts13.isFunctionExpression(ast)) ? ast : null;
|
|
13536
13634
|
}
|
|
13537
13635
|
return null;
|
|
13538
13636
|
}
|
|
13539
13637
|
function isInterleaveTagFunction(fn) {
|
|
13540
|
-
if (!
|
|
13638
|
+
if (!ts13.isArrowFunction(fn) && !ts13.isFunctionExpression(fn))
|
|
13541
13639
|
return false;
|
|
13542
13640
|
if (fn.parameters.length !== 2)
|
|
13543
13641
|
return false;
|
|
13544
13642
|
const [partsParam, argsParam] = fn.parameters;
|
|
13545
|
-
if (!
|
|
13643
|
+
if (!ts13.isIdentifier(partsParam.name) || partsParam.dotDotDotToken)
|
|
13546
13644
|
return false;
|
|
13547
|
-
if (!
|
|
13645
|
+
if (!ts13.isIdentifier(argsParam.name) || !argsParam.dotDotDotToken)
|
|
13548
13646
|
return false;
|
|
13549
13647
|
const parsed = tsNodeToParsedExpr(fn);
|
|
13550
13648
|
if (parsed.kind !== "arrow")
|
|
@@ -13601,7 +13699,7 @@ function isInterleaveSpanExpr(expr, i, argsName) {
|
|
|
13601
13699
|
function buildUntaggedTemplateLiteral(node, ctx) {
|
|
13602
13700
|
const template = node.template;
|
|
13603
13701
|
let text;
|
|
13604
|
-
if (
|
|
13702
|
+
if (ts13.isNoSubstitutionTemplateLiteral(template)) {
|
|
13605
13703
|
text = "`" + (template.rawText ?? template.text) + "`";
|
|
13606
13704
|
} else {
|
|
13607
13705
|
let body = template.head.rawText ?? template.head.text;
|
|
@@ -13613,15 +13711,15 @@ function buildUntaggedTemplateLiteral(node, ctx) {
|
|
|
13613
13711
|
text = "`" + body + "`";
|
|
13614
13712
|
}
|
|
13615
13713
|
const wrapped = `const __bf_resolve_tagged__ = (${text})`;
|
|
13616
|
-
const sf =
|
|
13714
|
+
const sf = ts13.createSourceFile("__bf_resolve_tagged.tsx", wrapped, ts13.ScriptTarget.Latest, true, ts13.ScriptKind.TSX);
|
|
13617
13715
|
const stmt = sf.statements[0];
|
|
13618
|
-
if (!stmt || !
|
|
13716
|
+
if (!stmt || !ts13.isVariableStatement(stmt))
|
|
13619
13717
|
return null;
|
|
13620
13718
|
const decl = stmt.declarationList.declarations[0];
|
|
13621
13719
|
if (!decl?.initializer)
|
|
13622
13720
|
return null;
|
|
13623
|
-
const result =
|
|
13624
|
-
if (!
|
|
13721
|
+
const result = ts13.isParenthesizedExpression(decl.initializer) ? decl.initializer.expression : decl.initializer;
|
|
13722
|
+
if (!ts13.isTemplateExpression(result) && !ts13.isNoSubstitutionTemplateLiteral(result))
|
|
13625
13723
|
return null;
|
|
13626
13724
|
return result;
|
|
13627
13725
|
}
|
|
@@ -13641,10 +13739,10 @@ function parseTernary(expr, ctx) {
|
|
|
13641
13739
|
return null;
|
|
13642
13740
|
}
|
|
13643
13741
|
function getStringValue(node) {
|
|
13644
|
-
if (
|
|
13742
|
+
if (ts13.isStringLiteral(node)) {
|
|
13645
13743
|
return node.text;
|
|
13646
13744
|
}
|
|
13647
|
-
if (
|
|
13745
|
+
if (ts13.isNoSubstitutionTemplateLiteral(node)) {
|
|
13648
13746
|
return node.text;
|
|
13649
13747
|
}
|
|
13650
13748
|
return null;
|
|
@@ -13652,19 +13750,19 @@ function getStringValue(node) {
|
|
|
13652
13750
|
function processComponentProps(attributes, ctx) {
|
|
13653
13751
|
const props = [];
|
|
13654
13752
|
for (const attr of attributes.properties) {
|
|
13655
|
-
if (
|
|
13753
|
+
if (ts13.isJsxSpreadAttribute(attr)) {
|
|
13656
13754
|
props.push(...expandSpreadAttribute(attr, ctx));
|
|
13657
13755
|
continue;
|
|
13658
13756
|
}
|
|
13659
|
-
if (!
|
|
13757
|
+
if (!ts13.isJsxAttribute(attr))
|
|
13660
13758
|
continue;
|
|
13661
13759
|
const name = attr.name.getText(ctx.sourceFile);
|
|
13662
|
-
if (attr.initializer &&
|
|
13760
|
+
if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
13663
13761
|
let jsxExpr = attr.initializer.expression;
|
|
13664
|
-
while (
|
|
13762
|
+
while (ts13.isParenthesizedExpression(jsxExpr)) {
|
|
13665
13763
|
jsxExpr = jsxExpr.expression;
|
|
13666
13764
|
}
|
|
13667
|
-
if (
|
|
13765
|
+
if (ts13.isJsxElement(jsxExpr) || ts13.isJsxSelfClosingElement(jsxExpr) || ts13.isJsxFragment(jsxExpr)) {
|
|
13668
13766
|
const prevInsideComponentChildren = ctx.insideComponentChildren;
|
|
13669
13767
|
ctx.insideComponentChildren = true;
|
|
13670
13768
|
const irNode = transformNode(jsxExpr, ctx);
|
|
@@ -13691,7 +13789,7 @@ function processComponentProps(attributes, ctx) {
|
|
|
13691
13789
|
value = AttrValueOf.booleanShorthand();
|
|
13692
13790
|
}
|
|
13693
13791
|
let clientOnly;
|
|
13694
|
-
if (attr.initializer &&
|
|
13792
|
+
if (attr.initializer && ts13.isJsxExpression(attr.initializer) && attr.initializer.expression) {
|
|
13695
13793
|
if (value.kind === "expression" && value.templateExpr === undefined) {
|
|
13696
13794
|
const rewritten = rewriteBarePropRefs2(value.expr, attr.initializer.expression, ctx);
|
|
13697
13795
|
if (rewritten !== value.expr) {
|
|
@@ -13715,7 +13813,7 @@ function processComponentProps(attributes, ctx) {
|
|
|
13715
13813
|
return props;
|
|
13716
13814
|
}
|
|
13717
13815
|
function checkBareSignalOrMemoIdentifier(expr, ctx) {
|
|
13718
|
-
if (!
|
|
13816
|
+
if (!ts13.isIdentifier(expr))
|
|
13719
13817
|
return;
|
|
13720
13818
|
const name = expr.text;
|
|
13721
13819
|
for (const signal of ctx.analyzer.signals) {
|
|
@@ -13746,12 +13844,12 @@ function checkBareSignalOrMemoIdentifier(expr, ctx) {
|
|
|
13746
13844
|
function isArrayExprDirectPropRef(arrayExpr, ctx) {
|
|
13747
13845
|
const propNames = new Set(ctx.patterns.props.map((p) => p.name));
|
|
13748
13846
|
const propsObjName = ctx.analyzer.propsObjectName;
|
|
13749
|
-
if (
|
|
13847
|
+
if (ts13.isIdentifier(arrayExpr)) {
|
|
13750
13848
|
return propNames.has(arrayExpr.text);
|
|
13751
13849
|
}
|
|
13752
|
-
if (
|
|
13850
|
+
if (ts13.isPropertyAccessExpression(arrayExpr) && propsObjName) {
|
|
13753
13851
|
const obj = arrayExpr.expression;
|
|
13754
|
-
if (
|
|
13852
|
+
if (ts13.isIdentifier(obj) && obj.text === propsObjName) {
|
|
13755
13853
|
return true;
|
|
13756
13854
|
}
|
|
13757
13855
|
}
|
|
@@ -13946,7 +14044,7 @@ function buildIfStatementChain(analyzer, ctx, opts) {
|
|
|
13946
14044
|
jsxBranchLocalNames.add(n);
|
|
13947
14045
|
}
|
|
13948
14046
|
for (const decl of condReturn.scopeVariables) {
|
|
13949
|
-
if (
|
|
14047
|
+
if (ts13.isIdentifier(decl.name) && decl.initializer) {
|
|
13950
14048
|
branchScopeVars.set(decl.name.text, decl.initializer);
|
|
13951
14049
|
if (initializerShapeContainsJsx(decl.initializer)) {
|
|
13952
14050
|
jsxBranchLocalNames.add(decl.name.text);
|
|
@@ -14013,7 +14111,7 @@ function buildIfStatementChain(analyzer, ctx, opts) {
|
|
|
14013
14111
|
}
|
|
14014
14112
|
const scopeVariables = [];
|
|
14015
14113
|
for (const decl of condReturn.scopeVariables) {
|
|
14016
|
-
if (
|
|
14114
|
+
if (ts13.isIdentifier(decl.name) && decl.initializer) {
|
|
14017
14115
|
const init = ctx.getJS(decl.initializer);
|
|
14018
14116
|
const typedInit = decl.initializer.getText(ctx.sourceFile);
|
|
14019
14117
|
scopeVariables.push({
|
|
@@ -15304,7 +15402,8 @@ function collectLoopChildConditionals(node, ctx, siblingOffsets, loopParam, loop
|
|
|
15304
15402
|
if (!n.reactive && !refsLoopParamInSource)
|
|
15305
15403
|
return;
|
|
15306
15404
|
const expanded = expandConstantForReactivity(n.condition, ctx, sourceFreeIds, scope);
|
|
15307
|
-
|
|
15405
|
+
const readsPreamble = preambleNames !== undefined && preambleNames.size > 0 && anyNameIn(expanded.freeIds ?? extractFreeIdentifiersFromText(expanded.expr), preambleNames);
|
|
15406
|
+
if (!readsPreamble && classifyReactivity(expanded.expr, ctx, loopParam, loopParamBindings, expanded.freeIds).kind === "none")
|
|
15308
15407
|
return;
|
|
15309
15408
|
const loopParamsForCond = loopParam ? [{ param: loopParam, bindings: loopParamBindings }] : undefined;
|
|
15310
15409
|
const whenTrueHtml = irToHtmlTemplate(n.whenTrue, undefined, 0, loopParamsForCond, "__slots");
|
|
@@ -15316,7 +15415,8 @@ function collectLoopChildConditionals(node, ctx, siblingOffsets, loopParam, loop
|
|
|
15316
15415
|
whenFalseHtml,
|
|
15317
15416
|
whenTrue: summarizeLoopChildBranch(n.whenTrue, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex),
|
|
15318
15417
|
whenFalse: summarizeLoopChildBranch(n.whenFalse, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex),
|
|
15319
|
-
...expanded.freeIds !== undefined && { conditionFreeIdentifiers: expanded.freeIds }
|
|
15418
|
+
...expanded.freeIds !== undefined && { conditionFreeIdentifiers: expanded.freeIds },
|
|
15419
|
+
...readsPreamble && { readsPreamble: true }
|
|
15320
15420
|
});
|
|
15321
15421
|
}
|
|
15322
15422
|
});
|
|
@@ -15692,7 +15792,7 @@ function graphDeclarationReferences(graph, kind, name) {
|
|
|
15692
15792
|
}
|
|
15693
15793
|
|
|
15694
15794
|
// src/ir-to-client-js/walk-prop-accesses.ts
|
|
15695
|
-
import
|
|
15795
|
+
import ts14 from "typescript";
|
|
15696
15796
|
function collectPropAccesses(source, propNames, out) {
|
|
15697
15797
|
if (propNames.size === 0)
|
|
15698
15798
|
return;
|
|
@@ -15706,7 +15806,7 @@ function collectPropAccesses(source, propNames, out) {
|
|
|
15706
15806
|
if (!anyMentioned)
|
|
15707
15807
|
return;
|
|
15708
15808
|
for (const expr of normaliseExpressionParts(source)) {
|
|
15709
|
-
const sourceFile =
|
|
15809
|
+
const sourceFile = ts14.createSourceFile("p.ts", expr, ts14.ScriptTarget.Latest, false, ts14.ScriptKind.TS);
|
|
15710
15810
|
visit2(sourceFile, propNames, out);
|
|
15711
15811
|
}
|
|
15712
15812
|
}
|
|
@@ -15716,15 +15816,15 @@ function normaliseExpressionParts(source) {
|
|
|
15716
15816
|
return extractTemplateExpressions(source);
|
|
15717
15817
|
}
|
|
15718
15818
|
function visit2(node, propNames, out) {
|
|
15719
|
-
if (
|
|
15819
|
+
if (ts14.isPropertyAccessExpression(node)) {
|
|
15720
15820
|
recordIfPropAccess(node.expression, "property", propNames, out);
|
|
15721
|
-
} else if (
|
|
15821
|
+
} else if (ts14.isElementAccessExpression(node)) {
|
|
15722
15822
|
recordIfPropAccess(node.expression, "index", propNames, out);
|
|
15723
15823
|
}
|
|
15724
|
-
|
|
15824
|
+
ts14.forEachChild(node, (child) => visit2(child, propNames, out));
|
|
15725
15825
|
}
|
|
15726
15826
|
function recordIfPropAccess(receiver, kind, propNames, out) {
|
|
15727
|
-
if (!
|
|
15827
|
+
if (!ts14.isIdentifier(receiver))
|
|
15728
15828
|
return;
|
|
15729
15829
|
const name = receiver.text;
|
|
15730
15830
|
if (!propNames.has(name))
|
|
@@ -15777,56 +15877,56 @@ function propHasPropertyAccess(u) {
|
|
|
15777
15877
|
}
|
|
15778
15878
|
|
|
15779
15879
|
// src/value-references.ts
|
|
15780
|
-
import
|
|
15880
|
+
import ts15 from "typescript";
|
|
15781
15881
|
function isValueReferenceIdentifier(id) {
|
|
15782
15882
|
const parent = id.parent;
|
|
15783
15883
|
if (!parent)
|
|
15784
15884
|
return false;
|
|
15785
|
-
if (
|
|
15885
|
+
if (ts15.isPropertyAccessExpression(parent) && parent.name === id)
|
|
15786
15886
|
return false;
|
|
15787
|
-
if (
|
|
15887
|
+
if (ts15.isPropertyAssignment(parent) && parent.name === id)
|
|
15788
15888
|
return false;
|
|
15789
|
-
if ((
|
|
15889
|
+
if ((ts15.isMethodDeclaration(parent) || ts15.isGetAccessorDeclaration(parent) || ts15.isSetAccessorDeclaration(parent)) && parent.name === id) {
|
|
15790
15890
|
return false;
|
|
15791
15891
|
}
|
|
15792
|
-
if (
|
|
15892
|
+
if (ts15.isPropertyDeclaration(parent) && parent.name === id)
|
|
15793
15893
|
return false;
|
|
15794
|
-
if (
|
|
15894
|
+
if (ts15.isMetaProperty(parent) && parent.name === id)
|
|
15795
15895
|
return false;
|
|
15796
|
-
if (
|
|
15896
|
+
if (ts15.isVariableDeclaration(parent) && parent.name === id)
|
|
15797
15897
|
return false;
|
|
15798
|
-
if (
|
|
15898
|
+
if (ts15.isFunctionDeclaration(parent) && parent.name === id)
|
|
15799
15899
|
return false;
|
|
15800
|
-
if (
|
|
15900
|
+
if (ts15.isFunctionExpression(parent) && parent.name === id)
|
|
15801
15901
|
return false;
|
|
15802
|
-
if (
|
|
15902
|
+
if (ts15.isClassDeclaration(parent) && parent.name === id)
|
|
15803
15903
|
return false;
|
|
15804
|
-
if (
|
|
15904
|
+
if (ts15.isClassExpression(parent) && parent.name === id)
|
|
15805
15905
|
return false;
|
|
15806
|
-
if (
|
|
15906
|
+
if (ts15.isParameter(parent) && parent.name === id)
|
|
15807
15907
|
return false;
|
|
15808
|
-
if (
|
|
15908
|
+
if (ts15.isBindingElement(parent) && (parent.name === id || parent.propertyName === id))
|
|
15809
15909
|
return false;
|
|
15810
|
-
if (
|
|
15910
|
+
if (ts15.isLabeledStatement(parent) && parent.label === id)
|
|
15811
15911
|
return false;
|
|
15812
|
-
if (
|
|
15912
|
+
if (ts15.isBreakOrContinueStatement(parent) && parent.label === id)
|
|
15813
15913
|
return false;
|
|
15814
|
-
if (
|
|
15914
|
+
if (ts15.isImportSpecifier(parent) && (parent.name === id || parent.propertyName === id))
|
|
15815
15915
|
return false;
|
|
15816
|
-
if (
|
|
15916
|
+
if (ts15.isExportSpecifier(parent) && (parent.name === id || parent.propertyName === id))
|
|
15817
15917
|
return false;
|
|
15818
|
-
if (
|
|
15918
|
+
if (ts15.isImportClause(parent) && parent.name === id)
|
|
15819
15919
|
return false;
|
|
15820
|
-
if (
|
|
15920
|
+
if (ts15.isNamespaceImport(parent) && parent.name === id)
|
|
15821
15921
|
return false;
|
|
15822
|
-
if (
|
|
15922
|
+
if (ts15.isQualifiedName(parent) && parent.right === id)
|
|
15823
15923
|
return false;
|
|
15824
15924
|
return true;
|
|
15825
15925
|
}
|
|
15826
15926
|
function collectValueReferencedNames(code) {
|
|
15827
15927
|
let sourceFile;
|
|
15828
15928
|
try {
|
|
15829
|
-
sourceFile =
|
|
15929
|
+
sourceFile = ts15.createSourceFile("generated.js", code, ts15.ScriptTarget.Latest, true, ts15.ScriptKind.JS);
|
|
15830
15930
|
} catch {
|
|
15831
15931
|
return null;
|
|
15832
15932
|
}
|
|
@@ -15835,10 +15935,10 @@ function collectValueReferencedNames(code) {
|
|
|
15835
15935
|
return null;
|
|
15836
15936
|
const names = new Set;
|
|
15837
15937
|
function visit3(node) {
|
|
15838
|
-
if (
|
|
15938
|
+
if (ts15.isIdentifier(node) && isValueReferenceIdentifier(node)) {
|
|
15839
15939
|
names.add(node.text);
|
|
15840
15940
|
}
|
|
15841
|
-
|
|
15941
|
+
ts15.forEachChild(node, visit3);
|
|
15842
15942
|
}
|
|
15843
15943
|
visit3(sourceFile);
|
|
15844
15944
|
return names;
|
|
@@ -16006,7 +16106,7 @@ function collectComponentNames(node) {
|
|
|
16006
16106
|
}
|
|
16007
16107
|
|
|
16008
16108
|
// src/relocate.ts
|
|
16009
|
-
import
|
|
16109
|
+
import ts16 from "typescript";
|
|
16010
16110
|
|
|
16011
16111
|
// src/lowering-registry.ts
|
|
16012
16112
|
var plugins = [];
|
|
@@ -16052,19 +16152,19 @@ function classify(name, env) {
|
|
|
16052
16152
|
function collectFreeRefs(node) {
|
|
16053
16153
|
const refs = new Map;
|
|
16054
16154
|
function visit3(n, parent) {
|
|
16055
|
-
if (
|
|
16056
|
-
if (parent &&
|
|
16155
|
+
if (ts16.isIdentifier(n)) {
|
|
16156
|
+
if (parent && ts16.isPropertyAccessExpression(parent) && parent.name === n)
|
|
16057
16157
|
return;
|
|
16058
|
-
if (parent &&
|
|
16158
|
+
if (parent && ts16.isPropertyAssignment(parent) && parent.name === n)
|
|
16059
16159
|
return;
|
|
16060
|
-
if (parent &&
|
|
16160
|
+
if (parent && ts16.isShorthandPropertyAssignment(parent) && parent.name === n)
|
|
16061
16161
|
return;
|
|
16062
16162
|
const list = refs.get(n.text) ?? [];
|
|
16063
16163
|
list.push(n);
|
|
16064
16164
|
refs.set(n.text, list);
|
|
16065
16165
|
return;
|
|
16066
16166
|
}
|
|
16067
|
-
|
|
16167
|
+
ts16.forEachChild(n, (child) => visit3(child, n));
|
|
16068
16168
|
}
|
|
16069
16169
|
visit3(node);
|
|
16070
16170
|
return refs;
|
|
@@ -16168,11 +16268,11 @@ function isInlinableInTemplate(value, env) {
|
|
|
16168
16268
|
return { ok: true, rewrittenValue: r.text, decisions: r.decisions };
|
|
16169
16269
|
}
|
|
16170
16270
|
function getCalleeIdentifierPath(callee) {
|
|
16171
|
-
if (
|
|
16271
|
+
if (ts16.isParenthesizedExpression(callee))
|
|
16172
16272
|
return getCalleeIdentifierPath(callee.expression);
|
|
16173
|
-
if (
|
|
16273
|
+
if (ts16.isIdentifier(callee))
|
|
16174
16274
|
return callee.text;
|
|
16175
|
-
if (
|
|
16275
|
+
if (ts16.isPropertyAccessExpression(callee)) {
|
|
16176
16276
|
const left = getCalleeIdentifierPath(callee.expression);
|
|
16177
16277
|
if (left === null)
|
|
16178
16278
|
return null;
|
|
@@ -16181,11 +16281,11 @@ function getCalleeIdentifierPath(callee) {
|
|
|
16181
16281
|
return null;
|
|
16182
16282
|
}
|
|
16183
16283
|
function getCalleeLeftmostIdentifier(callee) {
|
|
16184
|
-
if (
|
|
16284
|
+
if (ts16.isParenthesizedExpression(callee))
|
|
16185
16285
|
return getCalleeLeftmostIdentifier(callee.expression);
|
|
16186
|
-
if (
|
|
16286
|
+
if (ts16.isIdentifier(callee))
|
|
16187
16287
|
return callee.text;
|
|
16188
|
-
if (
|
|
16288
|
+
if (ts16.isPropertyAccessExpression(callee)) {
|
|
16189
16289
|
return getCalleeLeftmostIdentifier(callee.expression);
|
|
16190
16290
|
}
|
|
16191
16291
|
return null;
|
|
@@ -16233,12 +16333,12 @@ function isCallAcceptedByAdapter(call, env) {
|
|
|
16233
16333
|
}
|
|
16234
16334
|
function parseExpressionNode(text) {
|
|
16235
16335
|
try {
|
|
16236
|
-
const sf =
|
|
16336
|
+
const sf = ts16.createSourceFile("__inline_check__.ts", `(${text});`, ts16.ScriptTarget.Latest, false, ts16.ScriptKind.TS);
|
|
16237
16337
|
const stmt = sf.statements[0];
|
|
16238
|
-
if (!stmt || !
|
|
16338
|
+
if (!stmt || !ts16.isExpressionStatement(stmt))
|
|
16239
16339
|
return null;
|
|
16240
16340
|
const inner = stmt.expression;
|
|
16241
|
-
return
|
|
16341
|
+
return ts16.isParenthesizedExpression(inner) ? inner.expression : inner;
|
|
16242
16342
|
} catch {
|
|
16243
16343
|
return null;
|
|
16244
16344
|
}
|
|
@@ -16255,8 +16355,8 @@ function hasCallWithBridgedArg(node, decisions, env) {
|
|
|
16255
16355
|
function visit3(n) {
|
|
16256
16356
|
if (found)
|
|
16257
16357
|
return;
|
|
16258
|
-
if (
|
|
16259
|
-
const accepted =
|
|
16358
|
+
if (ts16.isCallExpression(n) || ts16.isNewExpression(n)) {
|
|
16359
|
+
const accepted = ts16.isCallExpression(n) && isCallAcceptedByAdapter(n, env);
|
|
16260
16360
|
if (!accepted) {
|
|
16261
16361
|
const args = n.arguments;
|
|
16262
16362
|
if (args) {
|
|
@@ -16269,7 +16369,7 @@ function hasCallWithBridgedArg(node, decisions, env) {
|
|
|
16269
16369
|
}
|
|
16270
16370
|
}
|
|
16271
16371
|
}
|
|
16272
|
-
|
|
16372
|
+
ts16.forEachChild(n, visit3);
|
|
16273
16373
|
}
|
|
16274
16374
|
visit3(node);
|
|
16275
16375
|
return found;
|
|
@@ -16279,13 +16379,13 @@ function hasZeroArgCall(node, env) {
|
|
|
16279
16379
|
function visit3(n) {
|
|
16280
16380
|
if (found)
|
|
16281
16381
|
return;
|
|
16282
|
-
if (
|
|
16382
|
+
if (ts16.isCallExpression(n) && n.arguments.length === 0) {
|
|
16283
16383
|
if (!isCallAcceptedByAdapter(n, env)) {
|
|
16284
16384
|
found = true;
|
|
16285
16385
|
return;
|
|
16286
16386
|
}
|
|
16287
16387
|
}
|
|
16288
|
-
|
|
16388
|
+
ts16.forEachChild(n, visit3);
|
|
16289
16389
|
}
|
|
16290
16390
|
visit3(node);
|
|
16291
16391
|
return found;
|
|
@@ -16295,25 +16395,25 @@ function containsAnyIdentifier(node, names) {
|
|
|
16295
16395
|
function visit3(n) {
|
|
16296
16396
|
if (found)
|
|
16297
16397
|
return;
|
|
16298
|
-
if (
|
|
16398
|
+
if (ts16.isPropertyAccessExpression(n)) {
|
|
16299
16399
|
visit3(n.expression);
|
|
16300
16400
|
return;
|
|
16301
16401
|
}
|
|
16302
|
-
if (
|
|
16402
|
+
if (ts16.isPropertyAssignment(n)) {
|
|
16303
16403
|
visit3(n.initializer);
|
|
16304
16404
|
return;
|
|
16305
16405
|
}
|
|
16306
|
-
if (
|
|
16307
|
-
if (
|
|
16406
|
+
if (ts16.isShorthandPropertyAssignment(n)) {
|
|
16407
|
+
if (ts16.isIdentifier(n.name) && names.has(n.name.text)) {
|
|
16308
16408
|
found = true;
|
|
16309
16409
|
}
|
|
16310
16410
|
return;
|
|
16311
16411
|
}
|
|
16312
|
-
if (
|
|
16412
|
+
if (ts16.isIdentifier(n) && names.has(n.text)) {
|
|
16313
16413
|
found = true;
|
|
16314
16414
|
return;
|
|
16315
16415
|
}
|
|
16316
|
-
|
|
16416
|
+
ts16.forEachChild(n, visit3);
|
|
16317
16417
|
}
|
|
16318
16418
|
visit3(node);
|
|
16319
16419
|
return found;
|
|
@@ -17616,23 +17716,23 @@ function resolveFinalImports(generatedCode, ir, localImportPrefixes) {
|
|
|
17616
17716
|
}
|
|
17617
17717
|
|
|
17618
17718
|
// src/ir-to-client-js/prune-unused-prop-extractions.ts
|
|
17619
|
-
import
|
|
17719
|
+
import ts17 from "typescript";
|
|
17620
17720
|
function propExtractionName(stmt) {
|
|
17621
|
-
if (!
|
|
17721
|
+
if (!ts17.isVariableStatement(stmt))
|
|
17622
17722
|
return null;
|
|
17623
17723
|
const decls = stmt.declarationList.declarations;
|
|
17624
17724
|
if (decls.length !== 1)
|
|
17625
17725
|
return null;
|
|
17626
17726
|
const decl = decls[0];
|
|
17627
|
-
if (!
|
|
17727
|
+
if (!ts17.isIdentifier(decl.name) || !decl.initializer)
|
|
17628
17728
|
return null;
|
|
17629
17729
|
let core = decl.initializer;
|
|
17630
|
-
if (
|
|
17730
|
+
if (ts17.isBinaryExpression(core) && core.operatorToken.kind === ts17.SyntaxKind.QuestionQuestionToken) {
|
|
17631
17731
|
core = core.left;
|
|
17632
17732
|
}
|
|
17633
|
-
if (!
|
|
17733
|
+
if (!ts17.isPropertyAccessExpression(core))
|
|
17634
17734
|
return null;
|
|
17635
|
-
if (!
|
|
17735
|
+
if (!ts17.isIdentifier(core.expression) || core.expression.text !== PROPS_PARAM)
|
|
17636
17736
|
return null;
|
|
17637
17737
|
if (core.name.text !== decl.name.text)
|
|
17638
17738
|
return null;
|
|
@@ -17645,10 +17745,10 @@ function pruneUnusedPropExtractions(code) {
|
|
|
17645
17745
|
console.warn("[barefootjs] pruneUnusedPropExtractions: generated code did not parse; skipping prune");
|
|
17646
17746
|
return code;
|
|
17647
17747
|
}
|
|
17648
|
-
const sourceFile =
|
|
17748
|
+
const sourceFile = ts17.createSourceFile("generated.js", code, ts17.ScriptTarget.Latest, false, ts17.ScriptKind.JS);
|
|
17649
17749
|
const spans = [];
|
|
17650
17750
|
for (const stmt of sourceFile.statements) {
|
|
17651
|
-
if (!
|
|
17751
|
+
if (!ts17.isFunctionDeclaration(stmt) || !stmt.name?.text.startsWith("init") || !stmt.body)
|
|
17652
17752
|
continue;
|
|
17653
17753
|
for (const inner of stmt.body.statements) {
|
|
17654
17754
|
const name = propExtractionName(inner);
|
|
@@ -18612,7 +18712,8 @@ function buildReactiveEffectsPlan(args) {
|
|
|
18612
18712
|
whenTrueTemplateHtml: addCondAttrToTemplate(wrap(cond.whenTrueHtml), cond.slotId),
|
|
18613
18713
|
whenFalseTemplateHtml: addCondAttrToTemplate(wrap(cond.whenFalseHtml), cond.slotId),
|
|
18614
18714
|
whenTrueArm: buildOuterArm(cond.whenTrue, wrap, loopParam, loopParamBindings, profileComponentName),
|
|
18615
|
-
whenFalseArm: buildOuterArm(cond.whenFalse, wrap, loopParam, loopParamBindings, profileComponentName)
|
|
18715
|
+
whenFalseArm: buildOuterArm(cond.whenFalse, wrap, loopParam, loopParamBindings, profileComponentName),
|
|
18716
|
+
...cond.readsPreamble && { readsPreamble: true }
|
|
18616
18717
|
});
|
|
18617
18718
|
}
|
|
18618
18719
|
}
|
|
@@ -19093,7 +19194,7 @@ function analyzeLazyConditional(cond, indexParam, arms) {
|
|
|
19093
19194
|
}
|
|
19094
19195
|
|
|
19095
19196
|
// src/ir-to-client-js/control-flow/plan/lazy-preamble.ts
|
|
19096
|
-
import
|
|
19197
|
+
import ts18 from "typescript";
|
|
19097
19198
|
var NO_PREAMBLE = {
|
|
19098
19199
|
lazySafe: true,
|
|
19099
19200
|
facts: { declaredNames: new Set, freeNames: new Set }
|
|
@@ -19113,12 +19214,12 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
|
|
|
19113
19214
|
if (text.trim().length === 0)
|
|
19114
19215
|
return NO_PREAMBLE;
|
|
19115
19216
|
const declaredNames = new Set;
|
|
19116
|
-
const sf =
|
|
19217
|
+
const sf = ts18.createSourceFile("__lazy_preamble__.ts", text, ts18.ScriptTarget.Latest, true, ts18.ScriptKind.TS);
|
|
19117
19218
|
for (const stmt of sf.statements) {
|
|
19118
|
-
if (!
|
|
19119
|
-
return NO2(`map-callback preamble has a non-declaration statement (${
|
|
19219
|
+
if (!ts18.isVariableStatement(stmt)) {
|
|
19220
|
+
return NO2(`map-callback preamble has a non-declaration statement (${ts18.SyntaxKind[stmt.kind]})`);
|
|
19120
19221
|
}
|
|
19121
|
-
const isConst = (stmt.declarationList.flags &
|
|
19222
|
+
const isConst = (stmt.declarationList.flags & ts18.NodeFlags.Const) !== 0;
|
|
19122
19223
|
if (!isConst)
|
|
19123
19224
|
return NO2("map-callback preamble declares a mutable binding (let/var)");
|
|
19124
19225
|
for (const decl of stmt.declarationList.declarations) {
|
|
@@ -19147,12 +19248,12 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
|
|
|
19147
19248
|
return { lazySafe: true, facts: { declaredNames, freeNames } };
|
|
19148
19249
|
}
|
|
19149
19250
|
function collectBindingNames3(name, out) {
|
|
19150
|
-
if (
|
|
19251
|
+
if (ts18.isIdentifier(name)) {
|
|
19151
19252
|
out.add(name.text);
|
|
19152
19253
|
return;
|
|
19153
19254
|
}
|
|
19154
19255
|
for (const element of name.elements) {
|
|
19155
|
-
if (
|
|
19256
|
+
if (ts18.isOmittedExpression(element))
|
|
19156
19257
|
continue;
|
|
19157
19258
|
collectBindingNames3(element.name, out);
|
|
19158
19259
|
}
|
|
@@ -19162,56 +19263,56 @@ function findImpureNode(root, primableNames) {
|
|
|
19162
19263
|
const visit3 = (node) => {
|
|
19163
19264
|
if (found)
|
|
19164
19265
|
return;
|
|
19165
|
-
if (
|
|
19266
|
+
if (ts18.isCallExpression(node)) {
|
|
19166
19267
|
const callee = node.expression;
|
|
19167
|
-
const isSignalRead =
|
|
19268
|
+
const isSignalRead = ts18.isIdentifier(callee) && primableNames.has(callee.text) && node.arguments.length === 0 && node.questionDotToken === undefined;
|
|
19168
19269
|
if (!isSignalRead) {
|
|
19169
19270
|
found = `call to ${callee.getText(callee.getSourceFile())}`;
|
|
19170
19271
|
return;
|
|
19171
19272
|
}
|
|
19172
19273
|
}
|
|
19173
|
-
if (
|
|
19274
|
+
if (ts18.isNewExpression(node)) {
|
|
19174
19275
|
found = "new expression";
|
|
19175
19276
|
return;
|
|
19176
19277
|
}
|
|
19177
|
-
if (
|
|
19278
|
+
if (ts18.isTaggedTemplateExpression(node)) {
|
|
19178
19279
|
found = "tagged template";
|
|
19179
19280
|
return;
|
|
19180
19281
|
}
|
|
19181
|
-
if (
|
|
19282
|
+
if (ts18.isAwaitExpression(node)) {
|
|
19182
19283
|
found = "await";
|
|
19183
19284
|
return;
|
|
19184
19285
|
}
|
|
19185
|
-
if (
|
|
19286
|
+
if (ts18.isYieldExpression(node)) {
|
|
19186
19287
|
found = "yield";
|
|
19187
19288
|
return;
|
|
19188
19289
|
}
|
|
19189
|
-
if (
|
|
19290
|
+
if (ts18.isPrefixUnaryExpression(node) || ts18.isPostfixUnaryExpression(node)) {
|
|
19190
19291
|
const op = node.operator;
|
|
19191
|
-
if (op ===
|
|
19292
|
+
if (op === ts18.SyntaxKind.PlusPlusToken || op === ts18.SyntaxKind.MinusMinusToken) {
|
|
19192
19293
|
found = "increment/decrement";
|
|
19193
19294
|
return;
|
|
19194
19295
|
}
|
|
19195
19296
|
}
|
|
19196
|
-
if (
|
|
19297
|
+
if (ts18.isDeleteExpression(node)) {
|
|
19197
19298
|
found = "delete";
|
|
19198
19299
|
return;
|
|
19199
19300
|
}
|
|
19200
|
-
if (
|
|
19301
|
+
if (ts18.isFunctionExpression(node) || ts18.isArrowFunction(node) || ts18.isClassExpression(node)) {
|
|
19201
19302
|
found = "function or class expression";
|
|
19202
19303
|
return;
|
|
19203
19304
|
}
|
|
19204
|
-
if (
|
|
19305
|
+
if (ts18.isBinaryExpression(node) && isAssignmentOperator2(node.operatorToken.kind)) {
|
|
19205
19306
|
found = "assignment";
|
|
19206
19307
|
return;
|
|
19207
19308
|
}
|
|
19208
|
-
|
|
19309
|
+
ts18.forEachChild(node, visit3);
|
|
19209
19310
|
};
|
|
19210
19311
|
visit3(root);
|
|
19211
19312
|
return found;
|
|
19212
19313
|
}
|
|
19213
|
-
function
|
|
19214
|
-
return kind >=
|
|
19314
|
+
function isAssignmentOperator2(kind) {
|
|
19315
|
+
return kind >= ts18.SyntaxKind.FirstAssignment && kind <= ts18.SyntaxKind.LastAssignment;
|
|
19215
19316
|
}
|
|
19216
19317
|
|
|
19217
19318
|
// src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts
|
|
@@ -19741,7 +19842,7 @@ function buildArmBody(branch, options) {
|
|
|
19741
19842
|
}
|
|
19742
19843
|
|
|
19743
19844
|
// src/ir-to-client-js/emit-reactive.ts
|
|
19744
|
-
import
|
|
19845
|
+
import ts19 from "typescript";
|
|
19745
19846
|
|
|
19746
19847
|
// src/ir-to-client-js/control-flow/stringify/claim-plan.ts
|
|
19747
19848
|
function slotSpecLiteral(slot) {
|
|
@@ -19845,20 +19946,20 @@ function lowerToLocaleCallsInReactiveExpr(expr, matcher) {
|
|
|
19845
19946
|
return expr;
|
|
19846
19947
|
let sourceFile;
|
|
19847
19948
|
try {
|
|
19848
|
-
sourceFile =
|
|
19949
|
+
sourceFile = ts19.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts19.ScriptTarget.Latest, true, ts19.ScriptKind.TS);
|
|
19849
19950
|
} catch {
|
|
19850
19951
|
return expr;
|
|
19851
19952
|
}
|
|
19852
19953
|
const stmt = sourceFile.statements[0];
|
|
19853
|
-
if (!stmt || !
|
|
19954
|
+
if (!stmt || !ts19.isExpressionStatement(stmt))
|
|
19854
19955
|
return expr;
|
|
19855
|
-
const root =
|
|
19956
|
+
const root = ts19.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
19856
19957
|
const candidates = [];
|
|
19857
19958
|
const visit3 = (n) => {
|
|
19858
|
-
if (
|
|
19959
|
+
if (ts19.isCallExpression(n) && n.arguments.length === 2 && ts19.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && n.expression.name.text === "toLocaleDateString") {
|
|
19859
19960
|
candidates.push(n);
|
|
19860
19961
|
}
|
|
19861
|
-
|
|
19962
|
+
ts19.forEachChild(n, visit3);
|
|
19862
19963
|
};
|
|
19863
19964
|
visit3(root);
|
|
19864
19965
|
if (candidates.length === 0)
|
|
@@ -19894,20 +19995,20 @@ function lowerDateCallsInReactiveExpr(expr, matcher) {
|
|
|
19894
19995
|
return expr;
|
|
19895
19996
|
let sourceFile;
|
|
19896
19997
|
try {
|
|
19897
|
-
sourceFile =
|
|
19998
|
+
sourceFile = ts19.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts19.ScriptTarget.Latest, true, ts19.ScriptKind.TS);
|
|
19898
19999
|
} catch {
|
|
19899
20000
|
return expr;
|
|
19900
20001
|
}
|
|
19901
20002
|
const stmt = sourceFile.statements[0];
|
|
19902
|
-
if (!stmt || !
|
|
20003
|
+
if (!stmt || !ts19.isExpressionStatement(stmt))
|
|
19903
20004
|
return expr;
|
|
19904
|
-
const root =
|
|
20005
|
+
const root = ts19.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
19905
20006
|
const candidates = [];
|
|
19906
20007
|
const visit3 = (n) => {
|
|
19907
|
-
if (
|
|
20008
|
+
if (ts19.isCallExpression(n) && n.arguments.length === 0 && ts19.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
|
|
19908
20009
|
candidates.push(n);
|
|
19909
20010
|
}
|
|
19910
|
-
|
|
20011
|
+
ts19.forEachChild(n, visit3);
|
|
19911
20012
|
};
|
|
19912
20013
|
visit3(root);
|
|
19913
20014
|
if (candidates.length === 0)
|
|
@@ -20222,7 +20323,7 @@ function stringifyReactiveEffects(lines, plan, opts) {
|
|
|
20222
20323
|
emitConsolidatedRowEffect(lines, indent, elVar, lookup, attrSlots, outerTexts, elementIndexBySlot, textClaimPathExprs, preambleRegions, mapPreambleWrapped);
|
|
20223
20324
|
}
|
|
20224
20325
|
for (const cond of conditionals) {
|
|
20225
|
-
emitOuterConditional(lines, indent, elVar, cond, pc);
|
|
20326
|
+
emitOuterConditional(lines, indent, elVar, cond, pc, mapPreambleWrapped);
|
|
20226
20327
|
}
|
|
20227
20328
|
}
|
|
20228
20329
|
function emitAttrSlotsGranular(lines, indent, elVar, lookup, attrSlots, elementIndexBySlot, bindingBfId, mapPreambleWrapped) {
|
|
@@ -20324,9 +20425,10 @@ function emitOuterTexts(lines, indent, elVar, texts, bindingBfId, textClaimPathE
|
|
|
20324
20425
|
lines.push(`${indent}createEffect(() => { ${writer}('${text.slotId}', String(${text.wrappedExpression})) }${bindingBfId(text.slotId)})`);
|
|
20325
20426
|
}
|
|
20326
20427
|
}
|
|
20327
|
-
function emitOuterConditional(lines, indent, elVar, cond, pc) {
|
|
20428
|
+
function emitOuterConditional(lines, indent, elVar, cond, pc, mapPreambleWrapped) {
|
|
20328
20429
|
const armIndent = `${indent} `;
|
|
20329
|
-
|
|
20430
|
+
const conditionGetter = cond.readsPreamble && mapPreambleWrapped ? `() => { ${mapPreambleWrapped}; return (${cond.wrappedCondition}) }` : `() => ${cond.wrappedCondition}`;
|
|
20431
|
+
lines.push(`${indent}insert(${elVar}, '${cond.slotId}', ${conditionGetter}, {`);
|
|
20330
20432
|
lines.push(`${indent} template: () => { const __slots = []; return { html: \`${cond.whenTrueTemplateHtml}\`, slots: __slots } },`);
|
|
20331
20433
|
lines.push(`${indent} bindEvents: (__branchScope, { isFirstRun: __bfFirstRun = false } = {}) => {`);
|
|
20332
20434
|
stringifyLoopChildArm(lines, cond.whenTrueArm, armIndent, pc);
|
|
@@ -21910,20 +22012,20 @@ var PHASES = [
|
|
|
21910
22012
|
];
|
|
21911
22013
|
|
|
21912
22014
|
// src/ir-to-client-js/rewrite-props-object.ts
|
|
21913
|
-
import
|
|
22015
|
+
import ts20 from "typescript";
|
|
21914
22016
|
function rewritePropsObjectRef(code, propsObjectName) {
|
|
21915
22017
|
const srcPropsName = propsObjectName ?? "props";
|
|
21916
22018
|
if (srcPropsName === PROPS_PARAM)
|
|
21917
22019
|
return code;
|
|
21918
22020
|
if (!identifierPattern(srcPropsName).test(code))
|
|
21919
22021
|
return code;
|
|
21920
|
-
const sourceFile =
|
|
22022
|
+
const sourceFile = ts20.createSourceFile("init-body.ts", code, ts20.ScriptTarget.Latest, true, ts20.ScriptKind.TS);
|
|
21921
22023
|
const spans = [];
|
|
21922
22024
|
function visit3(node) {
|
|
21923
|
-
if (
|
|
22025
|
+
if (ts20.isIdentifier(node) && node.text === srcPropsName && shouldRewrite(node)) {
|
|
21924
22026
|
spans.push([node.getStart(sourceFile), node.getEnd()]);
|
|
21925
22027
|
}
|
|
21926
|
-
|
|
22028
|
+
ts20.forEachChild(node, visit3);
|
|
21927
22029
|
}
|
|
21928
22030
|
visit3(sourceFile);
|
|
21929
22031
|
if (spans.length === 0)
|
|
@@ -21939,17 +22041,17 @@ function shouldRewrite(node) {
|
|
|
21939
22041
|
const parent = node.parent;
|
|
21940
22042
|
if (!parent)
|
|
21941
22043
|
return true;
|
|
21942
|
-
if (
|
|
22044
|
+
if (ts20.isPropertyAccessExpression(parent) && parent.name === node)
|
|
21943
22045
|
return false;
|
|
21944
|
-
if (
|
|
22046
|
+
if (ts20.isPropertyAssignment(parent) && parent.name === node)
|
|
21945
22047
|
return false;
|
|
21946
|
-
if (
|
|
22048
|
+
if (ts20.isShorthandPropertyAssignment(parent) && parent.name === node)
|
|
21947
22049
|
return false;
|
|
21948
|
-
if (
|
|
22050
|
+
if (ts20.isPropertySignature(parent) && parent.name === node)
|
|
21949
22051
|
return false;
|
|
21950
|
-
if (
|
|
22052
|
+
if (ts20.isPropertyDeclaration(parent) && parent.name === node)
|
|
21951
22053
|
return false;
|
|
21952
|
-
if (
|
|
22054
|
+
if (ts20.isBindingElement(parent) && parent.name === node)
|
|
21953
22055
|
return false;
|
|
21954
22056
|
return true;
|
|
21955
22057
|
}
|
|
@@ -22601,7 +22703,7 @@ function walkIR2(node, visitor) {
|
|
|
22601
22703
|
}
|
|
22602
22704
|
|
|
22603
22705
|
// src/preprocess-inline-jsx-callbacks.ts
|
|
22604
|
-
import
|
|
22706
|
+
import ts21 from "typescript";
|
|
22605
22707
|
var SYNTHETIC_PREFIX = "BFInlineJsxCallback";
|
|
22606
22708
|
var MAX_FIXPOINT_ITERATIONS = 16;
|
|
22607
22709
|
function preprocessInlineJsxCallbacks(source, filePath) {
|
|
@@ -22623,8 +22725,8 @@ function preprocessInlineJsxCallbacks(source, filePath) {
|
|
|
22623
22725
|
return { source: current, errors, syntheticNames };
|
|
22624
22726
|
}
|
|
22625
22727
|
function runSinglePass(source, filePath, startingCounter) {
|
|
22626
|
-
const sourceFile =
|
|
22627
|
-
const hasUseClient = sourceFile.statements.some((stmt) =>
|
|
22728
|
+
const sourceFile = ts21.createSourceFile(filePath, source, ts21.ScriptTarget.Latest, true, ts21.ScriptKind.TSX);
|
|
22729
|
+
const hasUseClient = sourceFile.statements.some((stmt) => ts21.isExpressionStatement(stmt) && ts21.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'"));
|
|
22628
22730
|
if (!hasUseClient) {
|
|
22629
22731
|
return { source, errors: [], syntheticNames: [], counterAfter: startingCounter };
|
|
22630
22732
|
}
|
|
@@ -22646,22 +22748,22 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
22646
22748
|
}
|
|
22647
22749
|
}
|
|
22648
22750
|
function visit3(node) {
|
|
22649
|
-
if (
|
|
22751
|
+
if (ts21.isJsxAttribute(node) && node.initializer && ts21.isJsxExpression(node.initializer) && node.initializer.expression) {
|
|
22650
22752
|
if (tryHandleArrowValue(node.initializer.expression)) {
|
|
22651
22753
|
return;
|
|
22652
22754
|
}
|
|
22653
22755
|
}
|
|
22654
|
-
if (
|
|
22756
|
+
if (ts21.isPropertyAssignment(node) && node.initializer) {
|
|
22655
22757
|
if (tryHandleArrowValue(node.initializer))
|
|
22656
22758
|
return;
|
|
22657
22759
|
}
|
|
22658
|
-
|
|
22760
|
+
ts21.forEachChild(node, visit3);
|
|
22659
22761
|
}
|
|
22660
22762
|
function tryHandleArrowValue(initializer) {
|
|
22661
22763
|
let expr = initializer;
|
|
22662
|
-
while (
|
|
22764
|
+
while (ts21.isParenthesizedExpression(expr))
|
|
22663
22765
|
expr = expr.expression;
|
|
22664
|
-
if (
|
|
22766
|
+
if (ts21.isArrowFunction(expr) && arrowBodyContainsJsx(expr)) {
|
|
22665
22767
|
return handleInlineArrow(expr);
|
|
22666
22768
|
}
|
|
22667
22769
|
return false;
|
|
@@ -22698,7 +22800,7 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
22698
22800
|
replacements.push({ start: arrowStart, end: arrowEnd, text: name });
|
|
22699
22801
|
return true;
|
|
22700
22802
|
}
|
|
22701
|
-
|
|
22803
|
+
ts21.forEachChild(sourceFile, visit3);
|
|
22702
22804
|
if (replacements.length === 0) {
|
|
22703
22805
|
return { source, errors, syntheticNames, counterAfter: counter };
|
|
22704
22806
|
}
|
|
@@ -22721,11 +22823,11 @@ function errorMessageForCapture(captures) {
|
|
|
22721
22823
|
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
22824
|
}
|
|
22723
22825
|
function arrowBodyContainsJsx(arrow) {
|
|
22724
|
-
if (
|
|
22826
|
+
if (ts21.isBlock(arrow.body)) {
|
|
22725
22827
|
return blockReturnsJsx(arrow.body);
|
|
22726
22828
|
}
|
|
22727
22829
|
let body = arrow.body;
|
|
22728
|
-
while (
|
|
22830
|
+
while (ts21.isParenthesizedExpression(body))
|
|
22729
22831
|
body = body.expression;
|
|
22730
22832
|
return isJsxLike(body);
|
|
22731
22833
|
}
|
|
@@ -22734,24 +22836,24 @@ function blockReturnsJsx(block) {
|
|
|
22734
22836
|
function visit3(n) {
|
|
22735
22837
|
if (found)
|
|
22736
22838
|
return;
|
|
22737
|
-
if (
|
|
22839
|
+
if (ts21.isReturnStatement(n) && n.expression) {
|
|
22738
22840
|
let e = n.expression;
|
|
22739
|
-
while (
|
|
22841
|
+
while (ts21.isParenthesizedExpression(e))
|
|
22740
22842
|
e = e.expression;
|
|
22741
22843
|
if (isJsxLike(e)) {
|
|
22742
22844
|
found = true;
|
|
22743
22845
|
return;
|
|
22744
22846
|
}
|
|
22745
22847
|
}
|
|
22746
|
-
if (
|
|
22848
|
+
if (ts21.isArrowFunction(n) || ts21.isFunctionDeclaration(n) || ts21.isFunctionExpression(n))
|
|
22747
22849
|
return;
|
|
22748
|
-
|
|
22850
|
+
ts21.forEachChild(n, visit3);
|
|
22749
22851
|
}
|
|
22750
|
-
|
|
22852
|
+
ts21.forEachChild(block, visit3);
|
|
22751
22853
|
return found;
|
|
22752
22854
|
}
|
|
22753
22855
|
function isJsxLike(expr) {
|
|
22754
|
-
return
|
|
22856
|
+
return ts21.isJsxElement(expr) || ts21.isJsxSelfClosingElement(expr) || ts21.isJsxFragment(expr);
|
|
22755
22857
|
}
|
|
22756
22858
|
function collectArrowParamNames(arrow) {
|
|
22757
22859
|
const names = new Set;
|
|
@@ -22761,13 +22863,13 @@ function collectArrowParamNames(arrow) {
|
|
|
22761
22863
|
}
|
|
22762
22864
|
function collectBindingNames4(name, out) {
|
|
22763
22865
|
const push = Array.isArray(out) ? (n) => out.push(n) : (n) => out.add(n);
|
|
22764
|
-
if (
|
|
22866
|
+
if (ts21.isIdentifier(name)) {
|
|
22765
22867
|
push(name.text);
|
|
22766
|
-
} else if (
|
|
22868
|
+
} else if (ts21.isObjectBindingPattern(name)) {
|
|
22767
22869
|
name.elements.forEach((el) => collectBindingNames4(el.name, out));
|
|
22768
|
-
} else if (
|
|
22870
|
+
} else if (ts21.isArrayBindingPattern(name)) {
|
|
22769
22871
|
name.elements.forEach((el) => {
|
|
22770
|
-
if (!
|
|
22872
|
+
if (!ts21.isOmittedExpression(el))
|
|
22771
22873
|
collectBindingNames4(el.name, out);
|
|
22772
22874
|
});
|
|
22773
22875
|
}
|
|
@@ -22794,48 +22896,48 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22794
22896
|
return bound.includes(name);
|
|
22795
22897
|
}
|
|
22796
22898
|
function visit3(node) {
|
|
22797
|
-
if (
|
|
22899
|
+
if (ts21.isIdentifier(node)) {
|
|
22798
22900
|
const parent = node.parent;
|
|
22799
|
-
if (parent &&
|
|
22901
|
+
if (parent && ts21.isPropertyAccessExpression(parent) && parent.name === node)
|
|
22800
22902
|
return;
|
|
22801
|
-
if (parent &&
|
|
22903
|
+
if (parent && ts21.isPropertyAssignment(parent) && parent.name === node)
|
|
22802
22904
|
return;
|
|
22803
|
-
if (parent &&
|
|
22905
|
+
if (parent && ts21.isPropertySignature(parent) && parent.name === node)
|
|
22804
22906
|
return;
|
|
22805
|
-
if (parent &&
|
|
22907
|
+
if (parent && ts21.isPropertyDeclaration(parent) && parent.name === node)
|
|
22806
22908
|
return;
|
|
22807
|
-
if (parent &&
|
|
22909
|
+
if (parent && ts21.isMethodDeclaration(parent) && parent.name === node)
|
|
22808
22910
|
return;
|
|
22809
|
-
if (parent &&
|
|
22911
|
+
if (parent && ts21.isMethodSignature(parent) && parent.name === node)
|
|
22810
22912
|
return;
|
|
22811
|
-
if (parent &&
|
|
22913
|
+
if (parent && ts21.isGetAccessorDeclaration(parent) && parent.name === node)
|
|
22812
22914
|
return;
|
|
22813
|
-
if (parent &&
|
|
22915
|
+
if (parent && ts21.isSetAccessorDeclaration(parent) && parent.name === node)
|
|
22814
22916
|
return;
|
|
22815
|
-
if (parent &&
|
|
22917
|
+
if (parent && ts21.isEnumMember(parent) && parent.name === node)
|
|
22816
22918
|
return;
|
|
22817
|
-
if (parent &&
|
|
22919
|
+
if (parent && ts21.isBindingElement(parent) && parent.propertyName === node)
|
|
22818
22920
|
return;
|
|
22819
|
-
if (parent &&
|
|
22921
|
+
if (parent && ts21.isShorthandPropertyAssignment(parent) && parent.name === node) {
|
|
22820
22922
|
if (!isBound(node.text))
|
|
22821
22923
|
ids.add(node.text);
|
|
22822
22924
|
return;
|
|
22823
22925
|
}
|
|
22824
|
-
if (parent &&
|
|
22926
|
+
if (parent && ts21.isParameter(parent) && parent.name === node)
|
|
22825
22927
|
return;
|
|
22826
|
-
if (parent &&
|
|
22928
|
+
if (parent && ts21.isVariableDeclaration(parent) && parent.name === node)
|
|
22827
22929
|
return;
|
|
22828
|
-
if (parent &&
|
|
22930
|
+
if (parent && ts21.isFunctionDeclaration(parent) && parent.name === node)
|
|
22829
22931
|
return;
|
|
22830
|
-
if (parent &&
|
|
22932
|
+
if (parent && ts21.isClassDeclaration(parent) && parent.name === node)
|
|
22831
22933
|
return;
|
|
22832
|
-
if (parent &&
|
|
22934
|
+
if (parent && ts21.isJsxAttribute(parent) && parent.name === node)
|
|
22833
22935
|
return;
|
|
22834
|
-
if (parent &&
|
|
22936
|
+
if (parent && ts21.isJsxOpeningElement(parent) && parent.tagName === node) {
|
|
22835
22937
|
if (/^[a-z]/.test(node.text))
|
|
22836
22938
|
return;
|
|
22837
22939
|
}
|
|
22838
|
-
if (parent &&
|
|
22940
|
+
if (parent && ts21.isJsxClosingElement(parent) && parent.tagName === node) {
|
|
22839
22941
|
if (/^[a-z]/.test(node.text))
|
|
22840
22942
|
return;
|
|
22841
22943
|
}
|
|
@@ -22844,43 +22946,43 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22844
22946
|
ids.add(node.text);
|
|
22845
22947
|
return;
|
|
22846
22948
|
}
|
|
22847
|
-
if (
|
|
22949
|
+
if (ts21.isVariableDeclaration(node)) {
|
|
22848
22950
|
const declared = pushBindings(node.name);
|
|
22849
22951
|
if (node.initializer)
|
|
22850
22952
|
visit3(node.initializer);
|
|
22851
22953
|
return;
|
|
22852
22954
|
}
|
|
22853
|
-
if (
|
|
22955
|
+
if (ts21.isFunctionDeclaration(node)) {
|
|
22854
22956
|
if (node.name)
|
|
22855
22957
|
bound.push(node.name.text);
|
|
22856
22958
|
visitInsideNewScope(node);
|
|
22857
22959
|
return;
|
|
22858
22960
|
}
|
|
22859
|
-
if (
|
|
22961
|
+
if (ts21.isClassDeclaration(node)) {
|
|
22860
22962
|
if (node.name)
|
|
22861
22963
|
bound.push(node.name.text);
|
|
22862
|
-
|
|
22964
|
+
ts21.forEachChild(node, visit3);
|
|
22863
22965
|
return;
|
|
22864
22966
|
}
|
|
22865
|
-
if (
|
|
22967
|
+
if (ts21.isArrowFunction(node) || ts21.isFunctionExpression(node)) {
|
|
22866
22968
|
visitInsideNewScope(node);
|
|
22867
22969
|
return;
|
|
22868
22970
|
}
|
|
22869
|
-
if (
|
|
22971
|
+
if (ts21.isCatchClause(node)) {
|
|
22870
22972
|
const before = bound.length;
|
|
22871
22973
|
if (node.variableDeclaration)
|
|
22872
22974
|
pushBindings(node.variableDeclaration.name);
|
|
22873
|
-
|
|
22975
|
+
ts21.forEachChild(node, visit3);
|
|
22874
22976
|
popN(bound.length - before);
|
|
22875
22977
|
return;
|
|
22876
22978
|
}
|
|
22877
|
-
if (
|
|
22979
|
+
if (ts21.isBlock(node)) {
|
|
22878
22980
|
const before = bound.length;
|
|
22879
|
-
|
|
22981
|
+
ts21.forEachChild(node, visit3);
|
|
22880
22982
|
popN(bound.length - before);
|
|
22881
22983
|
return;
|
|
22882
22984
|
}
|
|
22883
|
-
|
|
22985
|
+
ts21.forEachChild(node, visit3);
|
|
22884
22986
|
}
|
|
22885
22987
|
function visitInsideNewScope(fn) {
|
|
22886
22988
|
const before = bound.length;
|
|
@@ -22903,29 +23005,29 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22903
23005
|
function collectModuleScopeNames(sourceFile) {
|
|
22904
23006
|
const names = new Set;
|
|
22905
23007
|
for (const stmt of sourceFile.statements) {
|
|
22906
|
-
if (
|
|
23008
|
+
if (ts21.isFunctionDeclaration(stmt) && stmt.name)
|
|
22907
23009
|
names.add(stmt.name.text);
|
|
22908
|
-
else if (
|
|
23010
|
+
else if (ts21.isClassDeclaration(stmt) && stmt.name)
|
|
22909
23011
|
names.add(stmt.name.text);
|
|
22910
|
-
else if (
|
|
23012
|
+
else if (ts21.isVariableStatement(stmt)) {
|
|
22911
23013
|
for (const decl of stmt.declarationList.declarations)
|
|
22912
23014
|
collectBindingNames4(decl.name, names);
|
|
22913
|
-
} else if (
|
|
23015
|
+
} else if (ts21.isImportDeclaration(stmt) && stmt.importClause) {
|
|
22914
23016
|
const ic = stmt.importClause;
|
|
22915
23017
|
if (ic.name)
|
|
22916
23018
|
names.add(ic.name.text);
|
|
22917
23019
|
if (ic.namedBindings) {
|
|
22918
|
-
if (
|
|
23020
|
+
if (ts21.isNamespaceImport(ic.namedBindings))
|
|
22919
23021
|
names.add(ic.namedBindings.name.text);
|
|
22920
23022
|
else
|
|
22921
23023
|
for (const e of ic.namedBindings.elements)
|
|
22922
23024
|
names.add(e.name.text);
|
|
22923
23025
|
}
|
|
22924
|
-
} else if (
|
|
23026
|
+
} else if (ts21.isTypeAliasDeclaration(stmt))
|
|
22925
23027
|
names.add(stmt.name.text);
|
|
22926
|
-
else if (
|
|
23028
|
+
else if (ts21.isInterfaceDeclaration(stmt))
|
|
22927
23029
|
names.add(stmt.name.text);
|
|
22928
|
-
else if (
|
|
23030
|
+
else if (ts21.isEnumDeclaration(stmt))
|
|
22929
23031
|
names.add(stmt.name.text);
|
|
22930
23032
|
}
|
|
22931
23033
|
return names;
|
|
@@ -22933,7 +23035,7 @@ function collectModuleScopeNames(sourceFile) {
|
|
|
22933
23035
|
function buildSyntheticDeclaration(name, arrow, sourceFile) {
|
|
22934
23036
|
const paramsText = arrow.parameters.length === 0 ? "" : arrow.parameters.map((p) => p.getText(sourceFile)).join(", ");
|
|
22935
23037
|
let bodyText;
|
|
22936
|
-
if (
|
|
23038
|
+
if (ts21.isBlock(arrow.body)) {
|
|
22937
23039
|
bodyText = arrow.body.getText(sourceFile);
|
|
22938
23040
|
} else {
|
|
22939
23041
|
const expr = arrow.body.getText(sourceFile);
|
|
@@ -22943,7 +23045,7 @@ function buildSyntheticDeclaration(name, arrow, sourceFile) {
|
|
|
22943
23045
|
}
|
|
22944
23046
|
|
|
22945
23047
|
// src/ssr-defaults.ts
|
|
22946
|
-
import
|
|
23048
|
+
import ts22 from "typescript";
|
|
22947
23049
|
function deriveStashFromDefaults(defaults, props) {
|
|
22948
23050
|
const extra = {};
|
|
22949
23051
|
for (const [name, d] of Object.entries(defaults)) {
|
|
@@ -23039,11 +23141,11 @@ function collectPropRefs(expr, propsObjectName, out) {
|
|
|
23039
23141
|
if (!node)
|
|
23040
23142
|
return;
|
|
23041
23143
|
const visit3 = (n) => {
|
|
23042
|
-
if (
|
|
23144
|
+
if (ts22.isPropertyAccessExpression(n) && ts22.isIdentifier(n.expression) && n.expression.text === propsObjectName && ts22.isIdentifier(n.name)) {
|
|
23043
23145
|
out.add(n.name.text);
|
|
23044
23146
|
return;
|
|
23045
23147
|
}
|
|
23046
|
-
|
|
23148
|
+
ts22.forEachChild(n, visit3);
|
|
23047
23149
|
};
|
|
23048
23150
|
visit3(node);
|
|
23049
23151
|
}
|
|
@@ -23064,23 +23166,23 @@ function tryStaticEval(expr, ctx) {
|
|
|
23064
23166
|
}
|
|
23065
23167
|
function evalStatementsForReturn(statements, ctx) {
|
|
23066
23168
|
for (const stmt of statements) {
|
|
23067
|
-
if (
|
|
23169
|
+
if (ts22.isVariableStatement(stmt)) {
|
|
23068
23170
|
for (const d of stmt.declarationList.declarations) {
|
|
23069
|
-
if (!
|
|
23171
|
+
if (!ts22.isIdentifier(d.name) || !d.initializer)
|
|
23070
23172
|
continue;
|
|
23071
23173
|
const v = evalNode(d.initializer, ctx);
|
|
23072
23174
|
if (v !== UNRESOLVED)
|
|
23073
23175
|
ctx.bindings[d.name.text] = v;
|
|
23074
23176
|
}
|
|
23075
|
-
} else if (
|
|
23177
|
+
} else if (ts22.isReturnStatement(stmt)) {
|
|
23076
23178
|
return stmt.expression ? evalNode(stmt.expression, ctx) : UNRESOLVED;
|
|
23077
|
-
} else if (
|
|
23179
|
+
} else if (ts22.isIfStatement(stmt)) {
|
|
23078
23180
|
const cond = evalNode(stmt.expression, ctx);
|
|
23079
23181
|
if (cond === UNRESOLVED)
|
|
23080
23182
|
return UNRESOLVED;
|
|
23081
23183
|
const branch = cond ? stmt.thenStatement : stmt.elseStatement;
|
|
23082
23184
|
if (branch) {
|
|
23083
|
-
const taken = evalStatementsForReturn(
|
|
23185
|
+
const taken = evalStatementsForReturn(ts22.isBlock(branch) ? branch.statements : [branch], ctx);
|
|
23084
23186
|
if (taken !== NO_RETURN)
|
|
23085
23187
|
return taken;
|
|
23086
23188
|
}
|
|
@@ -23091,45 +23193,45 @@ function evalStatementsForReturn(statements, ctx) {
|
|
|
23091
23193
|
return NO_RETURN;
|
|
23092
23194
|
}
|
|
23093
23195
|
function parseExpression2(expr) {
|
|
23094
|
-
const sf =
|
|
23196
|
+
const sf = ts22.createSourceFile("__ssr_default__.ts", `(${expr})`, ts22.ScriptTarget.Latest, false, ts22.ScriptKind.TS);
|
|
23095
23197
|
const stmt = sf.statements[0];
|
|
23096
|
-
if (!stmt || !
|
|
23198
|
+
if (!stmt || !ts22.isExpressionStatement(stmt))
|
|
23097
23199
|
return null;
|
|
23098
|
-
const inner =
|
|
23200
|
+
const inner = ts22.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
23099
23201
|
return inner;
|
|
23100
23202
|
}
|
|
23101
23203
|
function evalNode(node, ctx) {
|
|
23102
|
-
if (
|
|
23204
|
+
if (ts22.isParenthesizedExpression(node))
|
|
23103
23205
|
return evalNode(node.expression, ctx);
|
|
23104
|
-
if (
|
|
23206
|
+
if (ts22.isAsExpression(node))
|
|
23105
23207
|
return evalNode(node.expression, ctx);
|
|
23106
|
-
if (
|
|
23208
|
+
if (ts22.isSatisfiesExpression(node))
|
|
23107
23209
|
return evalNode(node.expression, ctx);
|
|
23108
|
-
if (
|
|
23210
|
+
if (ts22.isTypeAssertionExpression(node))
|
|
23109
23211
|
return evalNode(node.expression, ctx);
|
|
23110
|
-
if (
|
|
23212
|
+
if (ts22.isNonNullExpression(node))
|
|
23111
23213
|
return evalNode(node.expression, ctx);
|
|
23112
|
-
if (
|
|
23214
|
+
if (ts22.isArrowFunction(node)) {
|
|
23113
23215
|
if (node.parameters.length !== 0)
|
|
23114
23216
|
return UNRESOLVED;
|
|
23115
|
-
if (!
|
|
23217
|
+
if (!ts22.isBlock(node.body))
|
|
23116
23218
|
return evalNode(node.body, ctx);
|
|
23117
23219
|
const localBindings = { ...ctx.bindings };
|
|
23118
23220
|
const localCtx = { ...ctx, bindings: localBindings };
|
|
23119
23221
|
const result = evalStatementsForReturn(node.body.statements, localCtx);
|
|
23120
23222
|
return result === NO_RETURN ? UNRESOLVED : result;
|
|
23121
23223
|
}
|
|
23122
|
-
if (
|
|
23224
|
+
if (ts22.isNumericLiteral(node))
|
|
23123
23225
|
return Number(node.text);
|
|
23124
|
-
if (
|
|
23226
|
+
if (ts22.isStringLiteralLike(node))
|
|
23125
23227
|
return node.text;
|
|
23126
|
-
if (node.kind ===
|
|
23228
|
+
if (node.kind === ts22.SyntaxKind.TrueKeyword)
|
|
23127
23229
|
return true;
|
|
23128
|
-
if (node.kind ===
|
|
23230
|
+
if (node.kind === ts22.SyntaxKind.FalseKeyword)
|
|
23129
23231
|
return false;
|
|
23130
|
-
if (node.kind ===
|
|
23232
|
+
if (node.kind === ts22.SyntaxKind.NullKeyword)
|
|
23131
23233
|
return null;
|
|
23132
|
-
if (
|
|
23234
|
+
if (ts22.isIdentifier(node)) {
|
|
23133
23235
|
if (node.text === "undefined")
|
|
23134
23236
|
return;
|
|
23135
23237
|
if (node.text in ctx.bindings)
|
|
@@ -23138,29 +23240,29 @@ function evalNode(node, ctx) {
|
|
|
23138
23240
|
return;
|
|
23139
23241
|
return UNRESOLVED;
|
|
23140
23242
|
}
|
|
23141
|
-
if (
|
|
23243
|
+
if (ts22.isPrefixUnaryExpression(node)) {
|
|
23142
23244
|
const arg = evalNode(node.operand, ctx);
|
|
23143
23245
|
if (arg === UNRESOLVED)
|
|
23144
23246
|
return UNRESOLVED;
|
|
23145
23247
|
switch (node.operator) {
|
|
23146
|
-
case
|
|
23248
|
+
case ts22.SyntaxKind.MinusToken:
|
|
23147
23249
|
return typeof arg === "number" ? -arg : UNRESOLVED;
|
|
23148
|
-
case
|
|
23250
|
+
case ts22.SyntaxKind.PlusToken:
|
|
23149
23251
|
return typeof arg === "number" ? +arg : UNRESOLVED;
|
|
23150
|
-
case
|
|
23252
|
+
case ts22.SyntaxKind.ExclamationToken:
|
|
23151
23253
|
return !arg;
|
|
23152
23254
|
}
|
|
23153
23255
|
return UNRESOLVED;
|
|
23154
23256
|
}
|
|
23155
|
-
if (
|
|
23257
|
+
if (ts22.isObjectLiteralExpression(node)) {
|
|
23156
23258
|
const obj = {};
|
|
23157
23259
|
for (const prop of node.properties) {
|
|
23158
|
-
if (!
|
|
23260
|
+
if (!ts22.isPropertyAssignment(prop))
|
|
23159
23261
|
return UNRESOLVED;
|
|
23160
23262
|
let key;
|
|
23161
|
-
if (
|
|
23263
|
+
if (ts22.isIdentifier(prop.name) || ts22.isStringLiteralLike(prop.name)) {
|
|
23162
23264
|
key = prop.name.text;
|
|
23163
|
-
} else if (
|
|
23265
|
+
} else if (ts22.isNumericLiteral(prop.name)) {
|
|
23164
23266
|
key = prop.name.text;
|
|
23165
23267
|
} else {
|
|
23166
23268
|
return UNRESOLVED;
|
|
@@ -23172,10 +23274,10 @@ function evalNode(node, ctx) {
|
|
|
23172
23274
|
}
|
|
23173
23275
|
return obj;
|
|
23174
23276
|
}
|
|
23175
|
-
if (
|
|
23277
|
+
if (ts22.isArrayLiteralExpression(node)) {
|
|
23176
23278
|
const arr = [];
|
|
23177
23279
|
for (const elem of node.elements) {
|
|
23178
|
-
if (
|
|
23280
|
+
if (ts22.isOmittedExpression(elem))
|
|
23179
23281
|
return UNRESOLVED;
|
|
23180
23282
|
const v = evalNode(elem, ctx);
|
|
23181
23283
|
if (v === UNRESOLVED)
|
|
@@ -23184,7 +23286,7 @@ function evalNode(node, ctx) {
|
|
|
23184
23286
|
}
|
|
23185
23287
|
return arr;
|
|
23186
23288
|
}
|
|
23187
|
-
if (
|
|
23289
|
+
if (ts22.isElementAccessExpression(node)) {
|
|
23188
23290
|
const base = evalNode(node.expression, ctx);
|
|
23189
23291
|
if (base === undefined)
|
|
23190
23292
|
return;
|
|
@@ -23198,17 +23300,17 @@ function evalNode(node, ctx) {
|
|
|
23198
23300
|
const k = String(key);
|
|
23199
23301
|
return Object.prototype.hasOwnProperty.call(base, k) ? base[k] : undefined;
|
|
23200
23302
|
}
|
|
23201
|
-
if (
|
|
23303
|
+
if (ts22.isPropertyAccessExpression(node)) {
|
|
23202
23304
|
const baseResult = evalNode(node.expression, ctx);
|
|
23203
23305
|
if (baseResult === undefined)
|
|
23204
23306
|
return;
|
|
23205
23307
|
return UNRESOLVED;
|
|
23206
23308
|
}
|
|
23207
|
-
if (
|
|
23208
|
-
if (node.arguments.length === 0 &&
|
|
23309
|
+
if (ts22.isCallExpression(node)) {
|
|
23310
|
+
if (node.arguments.length === 0 && ts22.isIdentifier(node.expression) && node.expression.text in ctx.bindings) {
|
|
23209
23311
|
return ctx.bindings[node.expression.text];
|
|
23210
23312
|
}
|
|
23211
|
-
if (
|
|
23313
|
+
if (ts22.isPropertyAccessExpression(node.expression) && node.expression.name.text === "join") {
|
|
23212
23314
|
const recv = evalNode(node.expression.expression, ctx);
|
|
23213
23315
|
if (Array.isArray(recv)) {
|
|
23214
23316
|
let sep2 = ",";
|
|
@@ -23224,27 +23326,27 @@ function evalNode(node, ctx) {
|
|
|
23224
23326
|
}
|
|
23225
23327
|
return UNRESOLVED;
|
|
23226
23328
|
}
|
|
23227
|
-
if (
|
|
23329
|
+
if (ts22.isConditionalExpression(node)) {
|
|
23228
23330
|
const cond = evalNode(node.condition, ctx);
|
|
23229
23331
|
if (cond === UNRESOLVED)
|
|
23230
23332
|
return UNRESOLVED;
|
|
23231
23333
|
return cond ? evalNode(node.whenTrue, ctx) : evalNode(node.whenFalse, ctx);
|
|
23232
23334
|
}
|
|
23233
|
-
if (
|
|
23335
|
+
if (ts22.isBinaryExpression(node)) {
|
|
23234
23336
|
const op = node.operatorToken.kind;
|
|
23235
|
-
if (op ===
|
|
23337
|
+
if (op === ts22.SyntaxKind.QuestionQuestionToken) {
|
|
23236
23338
|
const l2 = evalNode(node.left, ctx);
|
|
23237
23339
|
if (l2 !== UNRESOLVED && l2 !== null && l2 !== undefined)
|
|
23238
23340
|
return l2;
|
|
23239
23341
|
return evalNode(node.right, ctx);
|
|
23240
23342
|
}
|
|
23241
|
-
if (op ===
|
|
23343
|
+
if (op === ts22.SyntaxKind.BarBarToken) {
|
|
23242
23344
|
const l2 = evalNode(node.left, ctx);
|
|
23243
23345
|
if (l2 !== UNRESOLVED && l2)
|
|
23244
23346
|
return l2;
|
|
23245
23347
|
return evalNode(node.right, ctx);
|
|
23246
23348
|
}
|
|
23247
|
-
if (op ===
|
|
23349
|
+
if (op === ts22.SyntaxKind.AmpersandAmpersandToken) {
|
|
23248
23350
|
const l2 = evalNode(node.left, ctx);
|
|
23249
23351
|
if (l2 === UNRESOLVED)
|
|
23250
23352
|
return UNRESOLVED;
|
|
@@ -23257,30 +23359,30 @@ function evalNode(node, ctx) {
|
|
|
23257
23359
|
if (l === UNRESOLVED || r === UNRESOLVED)
|
|
23258
23360
|
return UNRESOLVED;
|
|
23259
23361
|
switch (op) {
|
|
23260
|
-
case
|
|
23362
|
+
case ts22.SyntaxKind.PlusToken:
|
|
23261
23363
|
if (typeof l === "string" || typeof r === "string")
|
|
23262
23364
|
return `${l}${r}`;
|
|
23263
23365
|
if (typeof l === "number" && typeof r === "number")
|
|
23264
23366
|
return l + r;
|
|
23265
23367
|
return UNRESOLVED;
|
|
23266
|
-
case
|
|
23368
|
+
case ts22.SyntaxKind.MinusToken:
|
|
23267
23369
|
return typeof l === "number" && typeof r === "number" ? l - r : UNRESOLVED;
|
|
23268
|
-
case
|
|
23370
|
+
case ts22.SyntaxKind.AsteriskToken:
|
|
23269
23371
|
return typeof l === "number" && typeof r === "number" ? l * r : UNRESOLVED;
|
|
23270
|
-
case
|
|
23372
|
+
case ts22.SyntaxKind.SlashToken:
|
|
23271
23373
|
return typeof l === "number" && typeof r === "number" && r !== 0 ? l / r : UNRESOLVED;
|
|
23272
|
-
case
|
|
23374
|
+
case ts22.SyntaxKind.PercentToken:
|
|
23273
23375
|
return typeof l === "number" && typeof r === "number" && r !== 0 ? l % r : UNRESOLVED;
|
|
23274
|
-
case
|
|
23275
|
-
case
|
|
23376
|
+
case ts22.SyntaxKind.EqualsEqualsEqualsToken:
|
|
23377
|
+
case ts22.SyntaxKind.EqualsEqualsToken:
|
|
23276
23378
|
return l === r;
|
|
23277
|
-
case
|
|
23278
|
-
case
|
|
23379
|
+
case ts22.SyntaxKind.ExclamationEqualsEqualsToken:
|
|
23380
|
+
case ts22.SyntaxKind.ExclamationEqualsToken:
|
|
23279
23381
|
return l !== r;
|
|
23280
23382
|
}
|
|
23281
23383
|
return UNRESOLVED;
|
|
23282
23384
|
}
|
|
23283
|
-
if (
|
|
23385
|
+
if (ts22.isTemplateExpression(node)) {
|
|
23284
23386
|
if (node.templateSpans.length === 0)
|
|
23285
23387
|
return node.head.text;
|
|
23286
23388
|
let acc = node.head.text;
|
|
@@ -23292,13 +23394,13 @@ function evalNode(node, ctx) {
|
|
|
23292
23394
|
}
|
|
23293
23395
|
return acc;
|
|
23294
23396
|
}
|
|
23295
|
-
if (
|
|
23397
|
+
if (ts22.isNoSubstitutionTemplateLiteral(node))
|
|
23296
23398
|
return node.text;
|
|
23297
23399
|
return UNRESOLVED;
|
|
23298
23400
|
}
|
|
23299
23401
|
|
|
23300
23402
|
// src/augment-inherited-props.ts
|
|
23301
|
-
import
|
|
23403
|
+
import ts23 from "typescript";
|
|
23302
23404
|
function collectContextConsumers(metadata) {
|
|
23303
23405
|
const constants = metadata.localConstants ?? [];
|
|
23304
23406
|
const contextDefaults = new Map;
|
|
@@ -23330,47 +23432,47 @@ function collectContextConsumers(metadata) {
|
|
|
23330
23432
|
}
|
|
23331
23433
|
function parseUseContextArg(source) {
|
|
23332
23434
|
const expr = parseSingleExpression(source);
|
|
23333
|
-
if (!expr || !
|
|
23435
|
+
if (!expr || !ts23.isCallExpression(expr))
|
|
23334
23436
|
return null;
|
|
23335
|
-
if (!
|
|
23437
|
+
if (!ts23.isIdentifier(expr.expression) || expr.expression.text !== "useContext")
|
|
23336
23438
|
return null;
|
|
23337
23439
|
if (expr.arguments.length !== 1)
|
|
23338
23440
|
return null;
|
|
23339
23441
|
const arg = expr.arguments[0];
|
|
23340
|
-
return
|
|
23442
|
+
return ts23.isIdentifier(arg) ? arg.text : null;
|
|
23341
23443
|
}
|
|
23342
23444
|
function parseCreateContextDefault(source) {
|
|
23343
23445
|
const expr = parseSingleExpression(source);
|
|
23344
|
-
if (!expr || !
|
|
23446
|
+
if (!expr || !ts23.isCallExpression(expr))
|
|
23345
23447
|
return null;
|
|
23346
23448
|
if (expr.arguments.length === 0)
|
|
23347
23449
|
return null;
|
|
23348
23450
|
const arg = expr.arguments[0];
|
|
23349
|
-
if (
|
|
23451
|
+
if (ts23.isStringLiteral(arg) || ts23.isNoSubstitutionTemplateLiteral(arg))
|
|
23350
23452
|
return arg.text;
|
|
23351
|
-
if (
|
|
23453
|
+
if (ts23.isNumericLiteral(arg))
|
|
23352
23454
|
return Number(arg.text);
|
|
23353
|
-
if (arg.kind ===
|
|
23455
|
+
if (arg.kind === ts23.SyntaxKind.TrueKeyword)
|
|
23354
23456
|
return true;
|
|
23355
|
-
if (arg.kind ===
|
|
23457
|
+
if (arg.kind === ts23.SyntaxKind.FalseKeyword)
|
|
23356
23458
|
return false;
|
|
23357
23459
|
return null;
|
|
23358
23460
|
}
|
|
23359
23461
|
function isObjectLiteralCreateContextDefault(source) {
|
|
23360
23462
|
const expr = parseSingleExpression(source);
|
|
23361
|
-
if (!expr || !
|
|
23463
|
+
if (!expr || !ts23.isCallExpression(expr))
|
|
23362
23464
|
return false;
|
|
23363
23465
|
if (expr.arguments.length === 0)
|
|
23364
23466
|
return false;
|
|
23365
|
-
return
|
|
23467
|
+
return ts23.isObjectLiteralExpression(expr.arguments[0]);
|
|
23366
23468
|
}
|
|
23367
23469
|
function parseSingleExpression(source) {
|
|
23368
|
-
const sf =
|
|
23470
|
+
const sf = ts23.createSourceFile("__ctx.ts", `(${source})`, ts23.ScriptTarget.Latest, false);
|
|
23369
23471
|
const stmt = sf.statements[0];
|
|
23370
|
-
if (!stmt || !
|
|
23472
|
+
if (!stmt || !ts23.isExpressionStatement(stmt))
|
|
23371
23473
|
return null;
|
|
23372
23474
|
let e = stmt.expression;
|
|
23373
|
-
while (
|
|
23475
|
+
while (ts23.isParenthesizedExpression(e))
|
|
23374
23476
|
e = e.expression;
|
|
23375
23477
|
return e;
|
|
23376
23478
|
}
|
|
@@ -23395,25 +23497,25 @@ function augmentInheritedPropAccesses(ir) {
|
|
|
23395
23497
|
const pinCoalesceLiterals = (s) => {
|
|
23396
23498
|
if (!s || !s.includes(propsObj))
|
|
23397
23499
|
return;
|
|
23398
|
-
const sf =
|
|
23500
|
+
const sf = ts23.createSourceFile("__aug.ts", `(${s})`, ts23.ScriptTarget.Latest, false);
|
|
23399
23501
|
const visit3 = (n) => {
|
|
23400
|
-
if (
|
|
23502
|
+
if (ts23.isBinaryExpression(n) && (n.operatorToken.kind === ts23.SyntaxKind.QuestionQuestionToken || n.operatorToken.kind === ts23.SyntaxKind.BarBarToken)) {
|
|
23401
23503
|
let left = n.left;
|
|
23402
|
-
while (
|
|
23504
|
+
while (ts23.isParenthesizedExpression(left))
|
|
23403
23505
|
left = left.expression;
|
|
23404
|
-
if (
|
|
23506
|
+
if (ts23.isPropertyAccessExpression(left) && ts23.isIdentifier(left.expression) && left.expression.text === propsObj) {
|
|
23405
23507
|
const name = left.name.text;
|
|
23406
23508
|
let right = n.right;
|
|
23407
|
-
while (
|
|
23509
|
+
while (ts23.isParenthesizedExpression(right))
|
|
23408
23510
|
right = right.expression;
|
|
23409
|
-
if (
|
|
23511
|
+
if (ts23.isPrefixUnaryExpression(right))
|
|
23410
23512
|
right = right.operand;
|
|
23411
|
-
const kind =
|
|
23513
|
+
const kind = ts23.isNumericLiteral(right) ? "number" : right.kind === ts23.SyntaxKind.TrueKeyword || right.kind === ts23.SyntaxKind.FalseKeyword ? "boolean" : ts23.isStringLiteralLike(right) ? "string" : null;
|
|
23412
23514
|
if (kind && !coalesceLiteralTypes.has(name))
|
|
23413
23515
|
coalesceLiteralTypes.set(name, kind);
|
|
23414
23516
|
}
|
|
23415
23517
|
}
|
|
23416
|
-
|
|
23518
|
+
ts23.forEachChild(n, visit3);
|
|
23417
23519
|
};
|
|
23418
23520
|
visit3(sf);
|
|
23419
23521
|
};
|
|
@@ -23524,33 +23626,33 @@ function augmentInheritedPropAccesses(ir) {
|
|
|
23524
23626
|
}
|
|
23525
23627
|
}
|
|
23526
23628
|
function parseStaticStringConst(source) {
|
|
23527
|
-
const sf =
|
|
23629
|
+
const sf = ts23.createSourceFile("__const.ts", `const __x = (${source});`, ts23.ScriptTarget.Latest, false);
|
|
23528
23630
|
const stmt = sf.statements[0];
|
|
23529
|
-
if (!stmt || !
|
|
23631
|
+
if (!stmt || !ts23.isVariableStatement(stmt))
|
|
23530
23632
|
return null;
|
|
23531
23633
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
23532
|
-
while (init &&
|
|
23634
|
+
while (init && ts23.isParenthesizedExpression(init))
|
|
23533
23635
|
init = init.expression;
|
|
23534
23636
|
if (!init)
|
|
23535
23637
|
return null;
|
|
23536
|
-
if (
|
|
23638
|
+
if (ts23.isStringLiteral(init) || ts23.isNoSubstitutionTemplateLiteral(init)) {
|
|
23537
23639
|
return init.text;
|
|
23538
23640
|
}
|
|
23539
23641
|
return evalStringArrayJoin(source);
|
|
23540
23642
|
}
|
|
23541
23643
|
function evalTemplateOfStringConsts(source, resolved) {
|
|
23542
|
-
const sf =
|
|
23644
|
+
const sf = ts23.createSourceFile("__const.ts", `const __x = (${source});`, ts23.ScriptTarget.Latest, false);
|
|
23543
23645
|
const stmt = sf.statements[0];
|
|
23544
|
-
if (!stmt || !
|
|
23646
|
+
if (!stmt || !ts23.isVariableStatement(stmt))
|
|
23545
23647
|
return null;
|
|
23546
23648
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
23547
|
-
while (init &&
|
|
23649
|
+
while (init && ts23.isParenthesizedExpression(init))
|
|
23548
23650
|
init = init.expression;
|
|
23549
|
-
if (!init || !
|
|
23651
|
+
if (!init || !ts23.isTemplateExpression(init))
|
|
23550
23652
|
return null;
|
|
23551
23653
|
let out = init.head.text;
|
|
23552
23654
|
for (const span of init.templateSpans) {
|
|
23553
|
-
if (!
|
|
23655
|
+
if (!ts23.isIdentifier(span.expression))
|
|
23554
23656
|
return null;
|
|
23555
23657
|
const value = resolved.get(span.expression.text);
|
|
23556
23658
|
if (value === undefined)
|
|
@@ -23577,34 +23679,36 @@ function collectModuleStringConsts(constants) {
|
|
|
23577
23679
|
}
|
|
23578
23680
|
return map;
|
|
23579
23681
|
}
|
|
23580
|
-
function lookupStaticRecordLiteral(objectName, key, constants) {
|
|
23682
|
+
function lookupStaticRecordLiteral(objectName, key, constants, isShadowed) {
|
|
23683
|
+
if (isShadowed(objectName))
|
|
23684
|
+
return null;
|
|
23581
23685
|
const constInfo = (constants ?? []).find((c) => c.name === objectName && c.isModule);
|
|
23582
23686
|
if (constInfo?.value === undefined)
|
|
23583
23687
|
return null;
|
|
23584
|
-
const sf =
|
|
23688
|
+
const sf = ts23.createSourceFile("__rec.ts", `(${constInfo.value})`, ts23.ScriptTarget.Latest, true);
|
|
23585
23689
|
if (sf.statements.length !== 1)
|
|
23586
23690
|
return null;
|
|
23587
23691
|
const stmt = sf.statements[0];
|
|
23588
|
-
if (!
|
|
23692
|
+
if (!ts23.isExpressionStatement(stmt))
|
|
23589
23693
|
return null;
|
|
23590
23694
|
let parsed = stmt.expression;
|
|
23591
|
-
while (
|
|
23695
|
+
while (ts23.isParenthesizedExpression(parsed))
|
|
23592
23696
|
parsed = parsed.expression;
|
|
23593
|
-
if (!
|
|
23697
|
+
if (!ts23.isObjectLiteralExpression(parsed))
|
|
23594
23698
|
return null;
|
|
23595
23699
|
for (const prop of parsed.properties) {
|
|
23596
|
-
if (!
|
|
23700
|
+
if (!ts23.isPropertyAssignment(prop))
|
|
23597
23701
|
continue;
|
|
23598
23702
|
const name = prop.name;
|
|
23599
|
-
const propKey =
|
|
23703
|
+
const propKey = ts23.isIdentifier(name) || ts23.isStringLiteral(name) || ts23.isNoSubstitutionTemplateLiteral(name) ? name.text : null;
|
|
23600
23704
|
if (propKey !== key)
|
|
23601
23705
|
continue;
|
|
23602
23706
|
let v = prop.initializer;
|
|
23603
|
-
while (
|
|
23707
|
+
while (ts23.isParenthesizedExpression(v))
|
|
23604
23708
|
v = v.expression;
|
|
23605
|
-
if (
|
|
23709
|
+
if (ts23.isNumericLiteral(v))
|
|
23606
23710
|
return { kind: "number", text: v.text };
|
|
23607
|
-
if (
|
|
23711
|
+
if (ts23.isStringLiteral(v) || ts23.isNoSubstitutionTemplateLiteral(v)) {
|
|
23608
23712
|
return { kind: "string", text: v.text };
|
|
23609
23713
|
}
|
|
23610
23714
|
return null;
|
|
@@ -23612,28 +23716,28 @@ function lookupStaticRecordLiteral(objectName, key, constants) {
|
|
|
23612
23716
|
return null;
|
|
23613
23717
|
}
|
|
23614
23718
|
function evalStringArrayJoin(source) {
|
|
23615
|
-
const sf =
|
|
23719
|
+
const sf = ts23.createSourceFile("__join.ts", `const __x = (${source});`, ts23.ScriptTarget.Latest, false);
|
|
23616
23720
|
const stmt = sf.statements[0];
|
|
23617
|
-
if (!stmt || !
|
|
23721
|
+
if (!stmt || !ts23.isVariableStatement(stmt))
|
|
23618
23722
|
return null;
|
|
23619
23723
|
let node = stmt.declarationList.declarations[0]?.initializer;
|
|
23620
|
-
while (node &&
|
|
23724
|
+
while (node && ts23.isParenthesizedExpression(node))
|
|
23621
23725
|
node = node.expression;
|
|
23622
|
-
if (!node || !
|
|
23726
|
+
if (!node || !ts23.isCallExpression(node))
|
|
23623
23727
|
return null;
|
|
23624
23728
|
const callee = node.expression;
|
|
23625
|
-
if (!
|
|
23729
|
+
if (!ts23.isPropertyAccessExpression(callee))
|
|
23626
23730
|
return null;
|
|
23627
23731
|
if (callee.name.text !== "join")
|
|
23628
23732
|
return null;
|
|
23629
23733
|
let recv = callee.expression;
|
|
23630
|
-
while (
|
|
23734
|
+
while (ts23.isParenthesizedExpression(recv))
|
|
23631
23735
|
recv = recv.expression;
|
|
23632
|
-
if (!
|
|
23736
|
+
if (!ts23.isArrayLiteralExpression(recv))
|
|
23633
23737
|
return null;
|
|
23634
23738
|
const parts = [];
|
|
23635
23739
|
for (const el of recv.elements) {
|
|
23636
|
-
if (
|
|
23740
|
+
if (ts23.isStringLiteral(el) || ts23.isNoSubstitutionTemplateLiteral(el)) {
|
|
23637
23741
|
parts.push(el.text);
|
|
23638
23742
|
} else {
|
|
23639
23743
|
return null;
|
|
@@ -23642,7 +23746,7 @@ function evalStringArrayJoin(source) {
|
|
|
23642
23746
|
let sep2 = ",";
|
|
23643
23747
|
if (node.arguments.length >= 1) {
|
|
23644
23748
|
const arg = node.arguments[0];
|
|
23645
|
-
if (
|
|
23749
|
+
if (ts23.isStringLiteral(arg) || ts23.isNoSubstitutionTemplateLiteral(arg))
|
|
23646
23750
|
sep2 = arg.text;
|
|
23647
23751
|
else
|
|
23648
23752
|
return null;
|
|
@@ -23650,11 +23754,11 @@ function evalStringArrayJoin(source) {
|
|
|
23650
23754
|
return parts.join(sep2);
|
|
23651
23755
|
}
|
|
23652
23756
|
function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
|
|
23653
|
-
if (!
|
|
23757
|
+
if (!ts23.isElementAccessExpression(val))
|
|
23654
23758
|
return null;
|
|
23655
23759
|
const obj = val.expression;
|
|
23656
23760
|
const arg = val.argumentExpression;
|
|
23657
|
-
if (!
|
|
23761
|
+
if (!ts23.isIdentifier(obj) || !ts23.isIdentifier(arg))
|
|
23658
23762
|
return null;
|
|
23659
23763
|
let indexPropName;
|
|
23660
23764
|
let defaultKey;
|
|
@@ -23670,35 +23774,35 @@ function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
|
|
|
23670
23774
|
const constInfo = localConstants.find((c) => c.name === obj.text && c.isModule);
|
|
23671
23775
|
if (constInfo?.value === undefined)
|
|
23672
23776
|
return null;
|
|
23673
|
-
const sf =
|
|
23777
|
+
const sf = ts23.createSourceFile("__rec.ts", `(${constInfo.value})`, ts23.ScriptTarget.Latest, true);
|
|
23674
23778
|
if (sf.statements.length !== 1)
|
|
23675
23779
|
return null;
|
|
23676
23780
|
const stmt = sf.statements[0];
|
|
23677
|
-
if (!
|
|
23781
|
+
if (!ts23.isExpressionStatement(stmt))
|
|
23678
23782
|
return null;
|
|
23679
23783
|
let parsed = stmt.expression;
|
|
23680
|
-
while (
|
|
23784
|
+
while (ts23.isParenthesizedExpression(parsed))
|
|
23681
23785
|
parsed = parsed.expression;
|
|
23682
|
-
if (!
|
|
23786
|
+
if (!ts23.isObjectLiteralExpression(parsed))
|
|
23683
23787
|
return null;
|
|
23684
23788
|
const entries = [];
|
|
23685
23789
|
for (const prop of parsed.properties) {
|
|
23686
|
-
if (!
|
|
23790
|
+
if (!ts23.isPropertyAssignment(prop))
|
|
23687
23791
|
return null;
|
|
23688
23792
|
let key;
|
|
23689
|
-
if (
|
|
23793
|
+
if (ts23.isIdentifier(prop.name)) {
|
|
23690
23794
|
key = prop.name.text;
|
|
23691
|
-
} else if (
|
|
23795
|
+
} else if (ts23.isStringLiteral(prop.name) || ts23.isNoSubstitutionTemplateLiteral(prop.name)) {
|
|
23692
23796
|
key = prop.name.text;
|
|
23693
23797
|
} else {
|
|
23694
23798
|
return null;
|
|
23695
23799
|
}
|
|
23696
23800
|
let v = prop.initializer;
|
|
23697
|
-
while (
|
|
23801
|
+
while (ts23.isParenthesizedExpression(v))
|
|
23698
23802
|
v = v.expression;
|
|
23699
|
-
if (
|
|
23803
|
+
if (ts23.isNumericLiteral(v)) {
|
|
23700
23804
|
entries.push({ key, value: { kind: "number", text: v.text } });
|
|
23701
|
-
} else if (
|
|
23805
|
+
} else if (ts23.isStringLiteral(v) || ts23.isNoSubstitutionTemplateLiteral(v)) {
|
|
23702
23806
|
entries.push({ key, value: { kind: "string", text: v.text } });
|
|
23703
23807
|
} else {
|
|
23704
23808
|
return null;
|
|
@@ -24041,13 +24145,13 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
24041
24145
|
if (entries.some((e) => e.componentIR.metadata.isClientComponent)) {
|
|
24042
24146
|
const topLevelNames = new Set;
|
|
24043
24147
|
{
|
|
24044
|
-
const sf =
|
|
24148
|
+
const sf = ts24.createSourceFile(filePath, source, ts24.ScriptTarget.Latest, true, ts24.ScriptKind.TSX);
|
|
24045
24149
|
for (const stmt of sf.statements) {
|
|
24046
|
-
if (
|
|
24150
|
+
if (ts24.isFunctionDeclaration(stmt) && stmt.name)
|
|
24047
24151
|
topLevelNames.add(stmt.name.text);
|
|
24048
|
-
else if (
|
|
24152
|
+
else if (ts24.isVariableStatement(stmt)) {
|
|
24049
24153
|
for (const d of stmt.declarationList.declarations) {
|
|
24050
|
-
if (
|
|
24154
|
+
if (ts24.isIdentifier(d.name))
|
|
24051
24155
|
topLevelNames.add(d.name.text);
|
|
24052
24156
|
}
|
|
24053
24157
|
}
|
|
@@ -24106,7 +24210,7 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
24106
24210
|
const moduleStatementSeen = new Set;
|
|
24107
24211
|
const moduleStatementsOrdered = [];
|
|
24108
24212
|
const collectModuleStatements = (block) => {
|
|
24109
|
-
const sf =
|
|
24213
|
+
const sf = ts24.createSourceFile("__bf_module_decls.tsx", block, ts24.ScriptTarget.Latest, false, ts24.ScriptKind.TSX);
|
|
24110
24214
|
for (const stmt of sf.statements) {
|
|
24111
24215
|
const text = stmt.getText(sf);
|
|
24112
24216
|
if (moduleStatementSeen.has(text))
|
|
@@ -24343,6 +24447,12 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
24343
24447
|
}
|
|
24344
24448
|
return { files, errors };
|
|
24345
24449
|
}
|
|
24450
|
+
function componentTypeParametersText(componentNode, sourceFile) {
|
|
24451
|
+
const typeParameters = componentNode?.typeParameters;
|
|
24452
|
+
if (!typeParameters || typeParameters.length === 0)
|
|
24453
|
+
return null;
|
|
24454
|
+
return `<${typeParameters.map((p) => p.getText(sourceFile)).join(", ")}>`;
|
|
24455
|
+
}
|
|
24346
24456
|
function buildMetadata(ctx) {
|
|
24347
24457
|
const metadata = {
|
|
24348
24458
|
componentName: ctx.componentName || "Unknown",
|
|
@@ -24351,6 +24461,7 @@ function buildMetadata(ctx) {
|
|
|
24351
24461
|
isClientComponent: ctx.hasUseClientDirective,
|
|
24352
24462
|
typeDefinitions: ctx.typeDefinitions,
|
|
24353
24463
|
propsType: ctx.propsType,
|
|
24464
|
+
typeParameters: componentTypeParametersText(ctx.componentNode, ctx.sourceFile),
|
|
24354
24465
|
propsParams: ctx.propsParams,
|
|
24355
24466
|
propsObjectName: ctx.propsObjectName,
|
|
24356
24467
|
restPropsName: ctx.restPropsName,
|
|
@@ -24541,7 +24652,7 @@ function compileJSX(source, filePath, options) {
|
|
|
24541
24652
|
return { files, errors };
|
|
24542
24653
|
}
|
|
24543
24654
|
// src/shared-program.ts
|
|
24544
|
-
import
|
|
24655
|
+
import ts25 from "typescript";
|
|
24545
24656
|
function commonParent(paths) {
|
|
24546
24657
|
if (paths.length === 0)
|
|
24547
24658
|
return process.cwd();
|
|
@@ -24562,10 +24673,10 @@ function commonParent(paths) {
|
|
|
24562
24673
|
function createProgramForCorpus(files, options = {}) {
|
|
24563
24674
|
const baseUrl = options.baseUrl ?? commonParent(files);
|
|
24564
24675
|
const compilerOptions = {
|
|
24565
|
-
target:
|
|
24566
|
-
module:
|
|
24567
|
-
moduleResolution:
|
|
24568
|
-
jsx:
|
|
24676
|
+
target: ts25.ScriptTarget.Latest,
|
|
24677
|
+
module: ts25.ModuleKind.ESNext,
|
|
24678
|
+
moduleResolution: ts25.ModuleResolutionKind.Bundler,
|
|
24679
|
+
jsx: ts25.JsxEmit.ReactJSX,
|
|
24569
24680
|
strict: true,
|
|
24570
24681
|
skipLibCheck: true,
|
|
24571
24682
|
noEmit: true,
|
|
@@ -24575,7 +24686,7 @@ function createProgramForCorpus(files, options = {}) {
|
|
|
24575
24686
|
...options.compilerOptions
|
|
24576
24687
|
};
|
|
24577
24688
|
const absolute = files.map((f) => path_default.resolve(f));
|
|
24578
|
-
return
|
|
24689
|
+
return ts25.createProgram(absolute, compilerOptions, undefined, options.oldProgram);
|
|
24579
24690
|
}
|
|
24580
24691
|
// src/adapters/interface.ts
|
|
24581
24692
|
class BaseAdapter {
|
|
@@ -24630,7 +24741,7 @@ class JsxAdapter extends BaseAdapter {
|
|
|
24630
24741
|
...localFunctions.map((f) => ({ name: f.name, body: f.body })),
|
|
24631
24742
|
...localConstants.map((c) => ({ name: c.name, body: c.value }))
|
|
24632
24743
|
];
|
|
24633
|
-
const reachable =
|
|
24744
|
+
const reachable = closeOverWritersOfMutableBindings(primaryRefText, declarations, new Set(ir.metadata.localConstants.filter((c) => (c.declarationKind ?? "const") !== "const").map((c) => c.name)));
|
|
24634
24745
|
const reachableBodies = [...reachable].map((name) => {
|
|
24635
24746
|
const func = localFunctions.find((f) => f.name === name);
|
|
24636
24747
|
if (func)
|
|
@@ -24662,7 +24773,8 @@ class JsxAdapter extends BaseAdapter {
|
|
|
24662
24773
|
if (signal.setter) {
|
|
24663
24774
|
const setterUsed = identifierPattern(signal.setter).test(setterRefText);
|
|
24664
24775
|
if (setterUsed) {
|
|
24665
|
-
|
|
24776
|
+
const setterType = preserveTypes && signal.type.kind !== "unknown" ? `(valueOrFn: ${signal.type.raw} | ((prev: ${signal.type.raw}) => ${signal.type.raw})) => void` : null;
|
|
24777
|
+
lines.push(setterType ? ` const ${signal.setter}: ${setterType} = () => {}` : ` const ${signal.setter} = (..._args: any[]) => {}`);
|
|
24666
24778
|
}
|
|
24667
24779
|
}
|
|
24668
24780
|
}
|
|
@@ -24858,7 +24970,7 @@ class JsxAdapter extends BaseAdapter {
|
|
|
24858
24970
|
}
|
|
24859
24971
|
|
|
24860
24972
|
// src/adapters/template-imports.ts
|
|
24861
|
-
import
|
|
24973
|
+
import ts26 from "typescript";
|
|
24862
24974
|
var CLIENT_PACKAGE_SOURCES = new Set([
|
|
24863
24975
|
"@barefootjs/client",
|
|
24864
24976
|
"@barefootjs/client/runtime"
|
|
@@ -24908,18 +25020,18 @@ function specKey(s) {
|
|
|
24908
25020
|
function rewriteDynamicImportsInSource(sourceText, rewriteRelative) {
|
|
24909
25021
|
if (!sourceText.includes("import"))
|
|
24910
25022
|
return sourceText;
|
|
24911
|
-
const sf =
|
|
25023
|
+
const sf = ts26.createSourceFile("bf-template-fragment.tsx", sourceText, ts26.ScriptTarget.Latest, false, ts26.ScriptKind.TSX);
|
|
24912
25024
|
const edits = [];
|
|
24913
25025
|
const visit3 = (node) => {
|
|
24914
|
-
if (
|
|
25026
|
+
if (ts26.isCallExpression(node) && node.expression.kind === ts26.SyntaxKind.ImportKeyword && node.arguments.length > 0 && ts26.isStringLiteralLike(node.arguments[0])) {
|
|
24915
25027
|
collect(node.arguments[0]);
|
|
24916
25028
|
}
|
|
24917
|
-
if (
|
|
25029
|
+
if (ts26.isImportTypeNode(node) && ts26.isLiteralTypeNode(node.argument)) {
|
|
24918
25030
|
const literal = node.argument.literal;
|
|
24919
|
-
if (
|
|
25031
|
+
if (ts26.isStringLiteralLike(literal))
|
|
24920
25032
|
collect(literal);
|
|
24921
25033
|
}
|
|
24922
|
-
|
|
25034
|
+
ts26.forEachChild(node, visit3);
|
|
24923
25035
|
};
|
|
24924
25036
|
const collect = (literal) => {
|
|
24925
25037
|
const specifier = literal.text;
|
|
@@ -24934,7 +25046,7 @@ function rewriteDynamicImportsInSource(sourceText, rewriteRelative) {
|
|
|
24934
25046
|
text: `'${next}'`
|
|
24935
25047
|
});
|
|
24936
25048
|
};
|
|
24937
|
-
|
|
25049
|
+
ts26.forEachChild(sf, visit3);
|
|
24938
25050
|
if (edits.length === 0)
|
|
24939
25051
|
return sourceText;
|
|
24940
25052
|
let out = sourceText;
|
|
@@ -25035,7 +25147,8 @@ export default ${this.componentName}` : "";
|
|
|
25035
25147
|
const noArgDefault = hasRequiredProps ? "" : ` = {} as ${propsTypeExpr}`;
|
|
25036
25148
|
const lines = [];
|
|
25037
25149
|
const exportPrefix = ir.metadata.isExported === false ? "" : "export ";
|
|
25038
|
-
|
|
25150
|
+
const typeParameters = ir.metadata.typeParameters ?? "";
|
|
25151
|
+
lines.push(`${exportPrefix}function ${name}${typeParameters}(${fullPropsDestructure}${typeAnnotation}${noArgDefault}) {`);
|
|
25039
25152
|
if (hasClientInteractivity) {
|
|
25040
25153
|
lines.push(` const __scopeId = (/_s\\d/.test(__bfScope || '') ? __bfScope : null) || __instanceId || \`${name}_\${Math.random().toString(36).slice(2, 8)}\``);
|
|
25041
25154
|
} else {
|
|
@@ -25729,7 +25842,7 @@ function dangerousInnerHtmlDiagnostic(expr, loc, reason) {
|
|
|
25729
25842
|
};
|
|
25730
25843
|
}
|
|
25731
25844
|
// src/combine-client-js.ts
|
|
25732
|
-
import
|
|
25845
|
+
import ts27 from "typescript";
|
|
25733
25846
|
var CHILD_PLACEHOLDER_RE = /import '\/\* @bf-child:(\w+) \*\/'/g;
|
|
25734
25847
|
function combineParentChildClientJs(files) {
|
|
25735
25848
|
const result = new Map;
|
|
@@ -25786,10 +25899,10 @@ function combineParentChildClientJs(files) {
|
|
|
25786
25899
|
return result;
|
|
25787
25900
|
}
|
|
25788
25901
|
function parseAndMerge(content, importsBySource, otherImports, codeSections) {
|
|
25789
|
-
const sourceFile =
|
|
25902
|
+
const sourceFile = ts27.createSourceFile("combine.js", content, ts27.ScriptTarget.Latest, false, ts27.ScriptKind.JS);
|
|
25790
25903
|
const importSpans = [];
|
|
25791
25904
|
for (const stmt of sourceFile.statements) {
|
|
25792
|
-
if (!
|
|
25905
|
+
if (!ts27.isImportDeclaration(stmt))
|
|
25793
25906
|
continue;
|
|
25794
25907
|
const start = stmt.getStart(sourceFile);
|
|
25795
25908
|
const end = stmt.getEnd();
|
|
@@ -25799,8 +25912,8 @@ function parseAndMerge(content, importsBySource, otherImports, codeSections) {
|
|
|
25799
25912
|
continue;
|
|
25800
25913
|
const clause = stmt.importClause;
|
|
25801
25914
|
const bindings = clause?.namedBindings;
|
|
25802
|
-
const specifier =
|
|
25803
|
-
if (clause && !clause.name && bindings &&
|
|
25915
|
+
const specifier = ts27.isStringLiteral(stmt.moduleSpecifier) ? stmt.moduleSpecifier.text : "";
|
|
25916
|
+
if (clause && !clause.name && bindings && ts27.isNamedImports(bindings)) {
|
|
25804
25917
|
if (!importsBySource.has(specifier)) {
|
|
25805
25918
|
importsBySource.set(specifier, new Set);
|
|
25806
25919
|
}
|
|
@@ -25967,7 +26080,7 @@ function escapeRe(s) {
|
|
|
25967
26080
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
25968
26081
|
}
|
|
25969
26082
|
// src/debug.ts
|
|
25970
|
-
import
|
|
26083
|
+
import ts28 from "typescript";
|
|
25971
26084
|
function buildComponentGraph(source, filePath, componentName) {
|
|
25972
26085
|
const ctx = analyzeComponent(source, filePath, componentName);
|
|
25973
26086
|
if (!ctx.jsxReturn) {
|
|
@@ -26046,7 +26159,7 @@ function buildGraphFromIR(ir) {
|
|
|
26046
26159
|
return propsObjectName ? exprReadsPropMember(expr, propsObjectName) : false;
|
|
26047
26160
|
};
|
|
26048
26161
|
const domBindings = [];
|
|
26049
|
-
collectDomBindings(ir.root, domBindings, signalGetters, memoNames, undefined,
|
|
26162
|
+
collectDomBindings(ir.root, domBindings, signalGetters, memoNames, undefined, BindingScope.EMPTY, exprReadsProp);
|
|
26050
26163
|
const signalConsumers = new Map;
|
|
26051
26164
|
for (const s of meta.signals)
|
|
26052
26165
|
signalConsumers.set(s.getter, []);
|
|
@@ -27072,15 +27185,22 @@ function inferWrapReasonForAttrLike(hasStringReactive, hasPropsRef, flags) {
|
|
|
27072
27185
|
const decision = decideWrapFromAstFlags(flags);
|
|
27073
27186
|
return decision.wrap ? decision.reason : undefined;
|
|
27074
27187
|
}
|
|
27075
|
-
function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
27076
|
-
const
|
|
27077
|
-
const
|
|
27188
|
+
function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag, scope = BindingScope.EMPTY, readsProp = () => false) {
|
|
27189
|
+
const boundNames = scope.valueBoundNames();
|
|
27190
|
+
const setSomeIn = (names, other) => {
|
|
27191
|
+
for (const n of names)
|
|
27192
|
+
if (other.has(n))
|
|
27193
|
+
return true;
|
|
27194
|
+
return false;
|
|
27195
|
+
};
|
|
27196
|
+
const exprReadsLoopParam = (n) => boundNames.size > 0 && (n.origin?.freeRefs?.some((r) => boundNames.has(r.name)) ?? false);
|
|
27197
|
+
const attrReadsLoopParam = (free) => boundNames.size > 0 && free !== undefined && setSomeIn(boundNames, free);
|
|
27078
27198
|
switch (node.type) {
|
|
27079
27199
|
case "element": {
|
|
27080
27200
|
for (const attr of node.attrs) {
|
|
27081
27201
|
if (attr.value.kind !== "expression" && attr.value.kind !== "template" && attr.value.kind !== "spread")
|
|
27082
27202
|
continue;
|
|
27083
|
-
if (attr.name === "key" &&
|
|
27203
|
+
if (attr.name === "key" && boundNames.size > 0)
|
|
27084
27204
|
continue;
|
|
27085
27205
|
const expr = attrValueToString2(attr.value);
|
|
27086
27206
|
if (!expr)
|
|
@@ -27117,7 +27237,7 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
27117
27237
|
});
|
|
27118
27238
|
}
|
|
27119
27239
|
for (const child of node.children) {
|
|
27120
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, node.tag,
|
|
27240
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, node.tag, scope, readsProp);
|
|
27121
27241
|
}
|
|
27122
27242
|
break;
|
|
27123
27243
|
}
|
|
@@ -27144,7 +27264,7 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
27144
27264
|
}
|
|
27145
27265
|
case "conditional": {
|
|
27146
27266
|
const decision = decideWrapFromAstFlags(node);
|
|
27147
|
-
const loopReactive =
|
|
27267
|
+
const loopReactive = boundNames.size > 0 && (node.origin?.freeRefs?.some((r) => boundNames.has(r.name)) ?? false);
|
|
27148
27268
|
if ((decision.wrap || loopReactive) && node.slotId) {
|
|
27149
27269
|
const deps = extractReactiveDeps(node.condition, signalGetters, memoNames);
|
|
27150
27270
|
bindings.push({
|
|
@@ -27160,14 +27280,14 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
27160
27280
|
jsxPreview: `{${truncateExpr(node.condition)} ? ... : ...}`
|
|
27161
27281
|
});
|
|
27162
27282
|
}
|
|
27163
|
-
collectDomBindings(node.whenTrue, bindings, signalGetters, memoNames, parentTag,
|
|
27164
|
-
collectDomBindings(node.whenFalse, bindings, signalGetters, memoNames, parentTag,
|
|
27283
|
+
collectDomBindings(node.whenTrue, bindings, signalGetters, memoNames, parentTag, scope, readsProp);
|
|
27284
|
+
collectDomBindings(node.whenFalse, bindings, signalGetters, memoNames, parentTag, scope, readsProp);
|
|
27165
27285
|
break;
|
|
27166
27286
|
}
|
|
27167
27287
|
case "loop": {
|
|
27168
27288
|
if (node.slotId) {
|
|
27169
27289
|
const deps = extractReactiveDeps(node.array, signalGetters, memoNames);
|
|
27170
|
-
const loopReactive =
|
|
27290
|
+
const loopReactive = boundNames.size > 0 && node.arrayFreeIdentifiers !== undefined && setSomeIn(boundNames, node.arrayFreeIdentifiers);
|
|
27171
27291
|
const isReactive = deps.length > 0 || node.callsReactiveGetters === true || loopReactive;
|
|
27172
27292
|
const isFallback = !isReactive && node.hasFunctionCalls === true;
|
|
27173
27293
|
if (isReactive || isFallback) {
|
|
@@ -27186,13 +27306,9 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
27186
27306
|
});
|
|
27187
27307
|
}
|
|
27188
27308
|
}
|
|
27189
|
-
const
|
|
27190
|
-
for (const p of extractLoopParamNames(node.param, node))
|
|
27191
|
-
childLoopParams.add(p);
|
|
27192
|
-
if (node.index)
|
|
27193
|
-
childLoopParams.add(node.index);
|
|
27309
|
+
const childScope = scope.enterLoopRow(node);
|
|
27194
27310
|
for (const child of node.children) {
|
|
27195
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag,
|
|
27311
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, childScope, readsProp);
|
|
27196
27312
|
}
|
|
27197
27313
|
break;
|
|
27198
27314
|
}
|
|
@@ -27225,21 +27341,21 @@ function collectDomBindings(node, bindings, signalGetters, memoNames, parentTag,
|
|
|
27225
27341
|
}
|
|
27226
27342
|
}
|
|
27227
27343
|
for (const child of node.children) {
|
|
27228
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag,
|
|
27344
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, readsProp);
|
|
27229
27345
|
}
|
|
27230
27346
|
break;
|
|
27231
27347
|
}
|
|
27232
27348
|
case "fragment":
|
|
27233
27349
|
case "provider": {
|
|
27234
27350
|
for (const child of node.children) {
|
|
27235
|
-
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag,
|
|
27351
|
+
collectDomBindings(child, bindings, signalGetters, memoNames, parentTag, scope, readsProp);
|
|
27236
27352
|
}
|
|
27237
27353
|
break;
|
|
27238
27354
|
}
|
|
27239
27355
|
case "if-statement": {
|
|
27240
|
-
collectDomBindings(node.consequent, bindings, signalGetters, memoNames, parentTag,
|
|
27356
|
+
collectDomBindings(node.consequent, bindings, signalGetters, memoNames, parentTag, scope, readsProp);
|
|
27241
27357
|
if (node.alternate) {
|
|
27242
|
-
collectDomBindings(node.alternate, bindings, signalGetters, memoNames, parentTag,
|
|
27358
|
+
collectDomBindings(node.alternate, bindings, signalGetters, memoNames, parentTag, scope, readsProp);
|
|
27243
27359
|
}
|
|
27244
27360
|
break;
|
|
27245
27361
|
}
|
|
@@ -27252,7 +27368,7 @@ function truncateExpr(expr, max = 40) {
|
|
|
27252
27368
|
function exprReadsPropMember(expr, propsObjectName) {
|
|
27253
27369
|
let sf;
|
|
27254
27370
|
try {
|
|
27255
|
-
sf =
|
|
27371
|
+
sf = ts28.createSourceFile("__attr.tsx", `(${expr})`, ts28.ScriptTarget.Latest, true, ts28.ScriptKind.TSX);
|
|
27256
27372
|
} catch {
|
|
27257
27373
|
return false;
|
|
27258
27374
|
}
|
|
@@ -27260,11 +27376,11 @@ function exprReadsPropMember(expr, propsObjectName) {
|
|
|
27260
27376
|
const visit3 = (n) => {
|
|
27261
27377
|
if (found)
|
|
27262
27378
|
return;
|
|
27263
|
-
if (
|
|
27379
|
+
if (ts28.isPropertyAccessExpression(n) && ts28.isIdentifier(n.expression) && n.expression.text === propsObjectName && n.name.text !== "children") {
|
|
27264
27380
|
found = true;
|
|
27265
27381
|
return;
|
|
27266
27382
|
}
|
|
27267
|
-
|
|
27383
|
+
ts28.forEachChild(n, visit3);
|
|
27268
27384
|
};
|
|
27269
27385
|
visit3(sf);
|
|
27270
27386
|
return found;
|
|
@@ -27334,7 +27450,7 @@ function findSourceFile2(meta) {
|
|
|
27334
27450
|
return null;
|
|
27335
27451
|
}
|
|
27336
27452
|
// src/profiler.ts
|
|
27337
|
-
import
|
|
27453
|
+
import ts29 from "typescript";
|
|
27338
27454
|
var PROFILE_SCHEMA_VERSION = 1;
|
|
27339
27455
|
var DEFAULT_FANOUT_THRESHOLD = 8;
|
|
27340
27456
|
function buildStaticBudget(source, filePath, componentName, options = {}) {
|
|
@@ -27604,15 +27720,15 @@ function joinProfilerEvents(events, index) {
|
|
|
27604
27720
|
return { joined, unattributed, diagnostics };
|
|
27605
27721
|
}
|
|
27606
27722
|
function findUninstrumentedEffects(source, filePath, instrumentedLines) {
|
|
27607
|
-
const sf =
|
|
27723
|
+
const sf = ts29.createSourceFile(filePath, source, ts29.ScriptTarget.Latest, true, ts29.ScriptKind.TSX);
|
|
27608
27724
|
const out = [];
|
|
27609
27725
|
const visit3 = (node) => {
|
|
27610
|
-
if (
|
|
27726
|
+
if (ts29.isCallExpression(node) && ts29.isIdentifier(node.expression) && node.expression.text === "createEffect") {
|
|
27611
27727
|
const line = sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;
|
|
27612
27728
|
if (!instrumentedLines.has(line))
|
|
27613
27729
|
out.push({ file: filePath, line });
|
|
27614
27730
|
}
|
|
27615
|
-
|
|
27731
|
+
ts29.forEachChild(node, visit3);
|
|
27616
27732
|
};
|
|
27617
27733
|
visit3(sf);
|
|
27618
27734
|
out.sort((a, b) => a.line - b.line);
|
|
@@ -27920,13 +28036,13 @@ function assessBatchSafety(args) {
|
|
|
27920
28036
|
const signalGetters = new Set(args.graph.signals.map((s) => s.name));
|
|
27921
28037
|
let sf;
|
|
27922
28038
|
try {
|
|
27923
|
-
sf =
|
|
28039
|
+
sf = ts29.createSourceFile("__h.ts", `const __h = ${args.handler}`, ts29.ScriptTarget.Latest, true);
|
|
27924
28040
|
} catch {
|
|
27925
28041
|
return "unverified";
|
|
27926
28042
|
}
|
|
27927
28043
|
const calls = [];
|
|
27928
28044
|
const visit3 = (node) => {
|
|
27929
|
-
if (
|
|
28045
|
+
if (ts29.isCallExpression(node) && ts29.isIdentifier(node.expression)) {
|
|
27930
28046
|
const name = node.expression.text;
|
|
27931
28047
|
if (setters.has(name))
|
|
27932
28048
|
calls.push({ pos: node.getStart(sf), kind: "write" });
|
|
@@ -27935,7 +28051,7 @@ function assessBatchSafety(args) {
|
|
|
27935
28051
|
else if (!signalGetters.has(name) && !memoNames.has(name))
|
|
27936
28052
|
calls.push({ pos: node.getStart(sf), kind: "risky" });
|
|
27937
28053
|
}
|
|
27938
|
-
|
|
28054
|
+
ts29.forEachChild(node, visit3);
|
|
27939
28055
|
};
|
|
27940
28056
|
visit3(sf);
|
|
27941
28057
|
calls.sort((a, b) => a.pos - b.pos);
|