@barefootjs/vite 0.35.0 → 0.35.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +731 -691
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { relative as relative2, resolve as resolve7, sep as sep3 } from "node:pa
|
|
|
6
6
|
import ts25 from "typescript";
|
|
7
7
|
|
|
8
8
|
// ../jsx/src/analyzer.ts
|
|
9
|
-
import
|
|
9
|
+
import ts11 from "typescript";
|
|
10
10
|
|
|
11
11
|
// ../jsx/src/expression-parser.ts
|
|
12
12
|
import ts from "typescript";
|
|
@@ -3743,7 +3743,7 @@ function irToHtmlTemplate(node, restSpreadNames, loopDepth = 0, loopParams, bran
|
|
|
3743
3743
|
case "expression":
|
|
3744
3744
|
case "template":
|
|
3745
3745
|
case "spread": {
|
|
3746
|
-
const expr = attrValueToString(p.value, { useTemplate: true }) ?? "undefined";
|
|
3746
|
+
const expr = wrapExpr(attrValueToString(p.value, { useTemplate: true }) ?? "undefined");
|
|
3747
3747
|
return `${quotePropName(p.name)}: ${expr}`;
|
|
3748
3748
|
}
|
|
3749
3749
|
}
|
|
@@ -4916,7 +4916,7 @@ function incrementCounter(key) {
|
|
|
4916
4916
|
}
|
|
4917
4917
|
|
|
4918
4918
|
// ../jsx/src/analyzer-context.ts
|
|
4919
|
-
import
|
|
4919
|
+
import ts10 from "typescript";
|
|
4920
4920
|
|
|
4921
4921
|
// ../jsx/src/strip-types.ts
|
|
4922
4922
|
import ts8 from "typescript";
|
|
@@ -5133,6 +5133,140 @@ function findAngleBracketAfter(lastTypeArg, fullText) {
|
|
|
5133
5133
|
return -1;
|
|
5134
5134
|
}
|
|
5135
5135
|
|
|
5136
|
+
// ../jsx/src/reactivity-checker.ts
|
|
5137
|
+
import ts9 from "typescript";
|
|
5138
|
+
var REACTIVE_BRAND = "__reactive";
|
|
5139
|
+
function queryType(checker, node) {
|
|
5140
|
+
incrementCounter("typeCheckerQueries");
|
|
5141
|
+
return checker.getTypeAtLocation(node);
|
|
5142
|
+
}
|
|
5143
|
+
function isReactiveType(type) {
|
|
5144
|
+
return type.getProperty(REACTIVE_BRAND) !== undefined;
|
|
5145
|
+
}
|
|
5146
|
+
var NOT_REACTIVE = { isReactive: false, reason: { kind: "not-reactive" } };
|
|
5147
|
+
function safeGetText(node) {
|
|
5148
|
+
try {
|
|
5149
|
+
return node.getText();
|
|
5150
|
+
} catch {
|
|
5151
|
+
return "";
|
|
5152
|
+
}
|
|
5153
|
+
}
|
|
5154
|
+
function analyze(node, checker) {
|
|
5155
|
+
if (ts9.isPropertyAccessExpression(node)) {
|
|
5156
|
+
try {
|
|
5157
|
+
const type = queryType(checker, node);
|
|
5158
|
+
if (isReactiveType(type)) {
|
|
5159
|
+
return {
|
|
5160
|
+
isReactive: true,
|
|
5161
|
+
reason: { kind: "brand", via: "property-access", nodeText: safeGetText(node) }
|
|
5162
|
+
};
|
|
5163
|
+
}
|
|
5164
|
+
} catch {}
|
|
5165
|
+
const sub = analyze(node.expression, checker);
|
|
5166
|
+
if (sub.isReactive) {
|
|
5167
|
+
return {
|
|
5168
|
+
isReactive: true,
|
|
5169
|
+
reason: {
|
|
5170
|
+
kind: "child",
|
|
5171
|
+
via: "property-access-object",
|
|
5172
|
+
childText: safeGetText(node.expression),
|
|
5173
|
+
childReason: sub.reason
|
|
5174
|
+
}
|
|
5175
|
+
};
|
|
5176
|
+
}
|
|
5177
|
+
return NOT_REACTIVE;
|
|
5178
|
+
}
|
|
5179
|
+
if (ts9.isIdentifier(node)) {
|
|
5180
|
+
try {
|
|
5181
|
+
const type = queryType(checker, node);
|
|
5182
|
+
if (isReactiveType(type)) {
|
|
5183
|
+
return {
|
|
5184
|
+
isReactive: true,
|
|
5185
|
+
reason: { kind: "brand", via: "identifier", nodeText: safeGetText(node) }
|
|
5186
|
+
};
|
|
5187
|
+
}
|
|
5188
|
+
} catch {}
|
|
5189
|
+
return NOT_REACTIVE;
|
|
5190
|
+
}
|
|
5191
|
+
if (ts9.isCallExpression(node)) {
|
|
5192
|
+
try {
|
|
5193
|
+
const calleeType = queryType(checker, node.expression);
|
|
5194
|
+
if (isReactiveType(calleeType)) {
|
|
5195
|
+
return {
|
|
5196
|
+
isReactive: true,
|
|
5197
|
+
reason: { kind: "brand", via: "callee", nodeText: safeGetText(node) }
|
|
5198
|
+
};
|
|
5199
|
+
}
|
|
5200
|
+
} catch {}
|
|
5201
|
+
}
|
|
5202
|
+
let foundChild;
|
|
5203
|
+
let foundChildText = "";
|
|
5204
|
+
ts9.forEachChild(node, (child) => {
|
|
5205
|
+
if (foundChild?.isReactive)
|
|
5206
|
+
return;
|
|
5207
|
+
const result = analyze(child, checker);
|
|
5208
|
+
if (result.isReactive) {
|
|
5209
|
+
foundChild = result;
|
|
5210
|
+
foundChildText = safeGetText(child);
|
|
5211
|
+
}
|
|
5212
|
+
});
|
|
5213
|
+
if (foundChild?.isReactive) {
|
|
5214
|
+
return {
|
|
5215
|
+
isReactive: true,
|
|
5216
|
+
reason: {
|
|
5217
|
+
kind: "child",
|
|
5218
|
+
via: "sub-expression",
|
|
5219
|
+
childText: foundChildText,
|
|
5220
|
+
childReason: foundChild.reason
|
|
5221
|
+
}
|
|
5222
|
+
};
|
|
5223
|
+
}
|
|
5224
|
+
return NOT_REACTIVE;
|
|
5225
|
+
}
|
|
5226
|
+
var brandTypeReactivityAnalyzer = { analyze };
|
|
5227
|
+
function containsReactiveExpression(node, checker) {
|
|
5228
|
+
incrementCounter("reactivityChecks");
|
|
5229
|
+
return brandTypeReactivityAnalyzer.analyze(node, checker).isReactive;
|
|
5230
|
+
}
|
|
5231
|
+
function nodeContainsJsx(node) {
|
|
5232
|
+
if (ts9.isJsxElement(node) || ts9.isJsxSelfClosingElement(node) || ts9.isJsxFragment(node))
|
|
5233
|
+
return true;
|
|
5234
|
+
return ts9.forEachChild(node, nodeContainsJsx) ?? false;
|
|
5235
|
+
}
|
|
5236
|
+
function collectReactiveBrandLeaves(node, checker) {
|
|
5237
|
+
const leaves = [];
|
|
5238
|
+
const visit = (n) => {
|
|
5239
|
+
if (ts9.isPropertyAccessExpression(n)) {
|
|
5240
|
+
try {
|
|
5241
|
+
if (isReactiveType(queryType(checker, n))) {
|
|
5242
|
+
leaves.push(n);
|
|
5243
|
+
return;
|
|
5244
|
+
}
|
|
5245
|
+
} catch {}
|
|
5246
|
+
visit(n.expression);
|
|
5247
|
+
return;
|
|
5248
|
+
}
|
|
5249
|
+
if (ts9.isIdentifier(n)) {
|
|
5250
|
+
try {
|
|
5251
|
+
if (isReactiveType(queryType(checker, n)))
|
|
5252
|
+
leaves.push(n);
|
|
5253
|
+
} catch {}
|
|
5254
|
+
return;
|
|
5255
|
+
}
|
|
5256
|
+
if (ts9.isCallExpression(n)) {
|
|
5257
|
+
try {
|
|
5258
|
+
if (isReactiveType(queryType(checker, n.expression))) {
|
|
5259
|
+
leaves.push(nodeContainsJsx(n) ? n.expression : n);
|
|
5260
|
+
return;
|
|
5261
|
+
}
|
|
5262
|
+
} catch {}
|
|
5263
|
+
}
|
|
5264
|
+
ts9.forEachChild(n, visit);
|
|
5265
|
+
};
|
|
5266
|
+
visit(node);
|
|
5267
|
+
return leaves;
|
|
5268
|
+
}
|
|
5269
|
+
|
|
5136
5270
|
// ../jsx/src/analyzer-context.ts
|
|
5137
5271
|
function createAnalyzerContext(sourceFile, filePath, acceptsCallbackBody) {
|
|
5138
5272
|
return {
|
|
@@ -5184,7 +5318,7 @@ function createAnalyzerContext(sourceFile, filePath, acceptsCallbackBody) {
|
|
|
5184
5318
|
} catch {
|
|
5185
5319
|
ownSourceFile = undefined;
|
|
5186
5320
|
}
|
|
5187
|
-
if (process.env.BF_ASSERT_NO_JSX_IN_GETJS === "1" && this.errors.
|
|
5321
|
+
if (process.env.BF_ASSERT_NO_JSX_IN_GETJS === "1" && !this.errors.some((e) => e.severity === "error") && nodeContainsJsx(node)) {
|
|
5188
5322
|
throw new Error("getJS() called on a JSX-bearing node — raw JSX must never be spliced " + "into emitted output. Carry mixed content as structured segments " + "(MapCallbackPreamble / FlatMapCallback) instead.");
|
|
5189
5323
|
}
|
|
5190
5324
|
if (ownSourceFile && ownSourceFile !== sourceFile) {
|
|
@@ -5194,11 +5328,6 @@ function createAnalyzerContext(sourceFile, filePath, acceptsCallbackBody) {
|
|
|
5194
5328
|
}
|
|
5195
5329
|
};
|
|
5196
5330
|
}
|
|
5197
|
-
function nodeContainsJsx(node) {
|
|
5198
|
-
if (ts9.isJsxElement(node) || ts9.isJsxSelfClosingElement(node) || ts9.isJsxFragment(node))
|
|
5199
|
-
return true;
|
|
5200
|
-
return ts9.forEachChild(node, nodeContainsJsx) ?? false;
|
|
5201
|
-
}
|
|
5202
5331
|
function getSourceLocation(node, sourceFile, filePath) {
|
|
5203
5332
|
const start = sourceFile.getLineAndCharacterOfPosition(node.getStart());
|
|
5204
5333
|
const end = sourceFile.getLineAndCharacterOfPosition(node.getEnd());
|
|
@@ -5215,20 +5344,20 @@ function getSourceLocation(node, sourceFile, filePath) {
|
|
|
5215
5344
|
};
|
|
5216
5345
|
}
|
|
5217
5346
|
function membersToProperties(members, sourceFile) {
|
|
5218
|
-
return members.filter(
|
|
5347
|
+
return members.filter(ts10.isPropertySignature).map((member) => ({
|
|
5219
5348
|
name: propertyNameText(member.name, sourceFile),
|
|
5220
5349
|
type: typeNodeToTypeInfo(member.type, sourceFile) ?? {
|
|
5221
5350
|
kind: "unknown",
|
|
5222
5351
|
raw: "unknown"
|
|
5223
5352
|
},
|
|
5224
5353
|
optional: !!member.questionToken,
|
|
5225
|
-
readonly: !!member.modifiers?.some((m) => m.kind ===
|
|
5354
|
+
readonly: !!member.modifiers?.some((m) => m.kind === ts10.SyntaxKind.ReadonlyKeyword)
|
|
5226
5355
|
}));
|
|
5227
5356
|
}
|
|
5228
5357
|
function propertyNameText(name, sourceFile) {
|
|
5229
5358
|
if (!name)
|
|
5230
5359
|
return "";
|
|
5231
|
-
if (
|
|
5360
|
+
if (ts10.isStringLiteral(name) || ts10.isNumericLiteral(name))
|
|
5232
5361
|
return name.text;
|
|
5233
5362
|
return name.getText(sourceFile);
|
|
5234
5363
|
}
|
|
@@ -5239,56 +5368,56 @@ function typeNodeToTypeInfo(typeNode, sourceFile, rawOf) {
|
|
|
5239
5368
|
const raw = rawOf ? rawOf(typeNode) : typeNode.getText(sourceFile);
|
|
5240
5369
|
const recurse = (n) => typeNodeToTypeInfo(n, sourceFile, rawOf) ?? { kind: "unknown", raw: "unknown" };
|
|
5241
5370
|
switch (typeNode.kind) {
|
|
5242
|
-
case
|
|
5371
|
+
case ts10.SyntaxKind.StringKeyword:
|
|
5243
5372
|
return { kind: "primitive", raw, primitive: "string" };
|
|
5244
|
-
case
|
|
5373
|
+
case ts10.SyntaxKind.NumberKeyword:
|
|
5245
5374
|
return { kind: "primitive", raw, primitive: "number" };
|
|
5246
|
-
case
|
|
5375
|
+
case ts10.SyntaxKind.BooleanKeyword:
|
|
5247
5376
|
return { kind: "primitive", raw, primitive: "boolean" };
|
|
5248
|
-
case
|
|
5377
|
+
case ts10.SyntaxKind.NullKeyword:
|
|
5249
5378
|
return { kind: "primitive", raw, primitive: "null" };
|
|
5250
|
-
case
|
|
5379
|
+
case ts10.SyntaxKind.UndefinedKeyword:
|
|
5251
5380
|
return { kind: "primitive", raw, primitive: "undefined" };
|
|
5252
5381
|
}
|
|
5253
|
-
if (
|
|
5382
|
+
if (ts10.isArrayTypeNode(typeNode)) {
|
|
5254
5383
|
return { kind: "array", raw, elementType: recurse(typeNode.elementType) };
|
|
5255
5384
|
}
|
|
5256
|
-
if (
|
|
5385
|
+
if (ts10.isLiteralTypeNode(typeNode)) {
|
|
5257
5386
|
const lit = typeNode.literal;
|
|
5258
|
-
if (
|
|
5387
|
+
if (ts10.isStringLiteral(lit) || ts10.isNoSubstitutionTemplateLiteral(lit)) {
|
|
5259
5388
|
return { kind: "primitive", raw, primitive: "string", literalValue: lit.text };
|
|
5260
5389
|
}
|
|
5261
|
-
if (
|
|
5390
|
+
if (ts10.isNumericLiteral(lit)) {
|
|
5262
5391
|
return { kind: "primitive", raw, primitive: "number", literalValue: lit.text };
|
|
5263
5392
|
}
|
|
5264
|
-
if (
|
|
5393
|
+
if (ts10.isPrefixUnaryExpression(lit) && lit.operator === ts10.SyntaxKind.MinusToken && ts10.isNumericLiteral(lit.operand)) {
|
|
5265
5394
|
return { kind: "primitive", raw, primitive: "number", literalValue: `-${lit.operand.text}` };
|
|
5266
5395
|
}
|
|
5267
|
-
if (lit.kind ===
|
|
5396
|
+
if (lit.kind === ts10.SyntaxKind.TrueKeyword || lit.kind === ts10.SyntaxKind.FalseKeyword) {
|
|
5268
5397
|
return {
|
|
5269
5398
|
kind: "primitive",
|
|
5270
5399
|
raw,
|
|
5271
5400
|
primitive: "boolean",
|
|
5272
|
-
literalValue: lit.kind ===
|
|
5401
|
+
literalValue: lit.kind === ts10.SyntaxKind.TrueKeyword ? "true" : "false"
|
|
5273
5402
|
};
|
|
5274
5403
|
}
|
|
5275
|
-
if (lit.kind ===
|
|
5404
|
+
if (lit.kind === ts10.SyntaxKind.NullKeyword) {
|
|
5276
5405
|
return { kind: "primitive", raw, primitive: "null" };
|
|
5277
5406
|
}
|
|
5278
5407
|
return { kind: "unknown", raw };
|
|
5279
5408
|
}
|
|
5280
|
-
if (
|
|
5409
|
+
if (ts10.isUnionTypeNode(typeNode)) {
|
|
5281
5410
|
return { kind: "union", raw, unionTypes: typeNode.types.map(recurse) };
|
|
5282
5411
|
}
|
|
5283
|
-
if (
|
|
5412
|
+
if (ts10.isTypeLiteralNode(typeNode)) {
|
|
5284
5413
|
return {
|
|
5285
5414
|
kind: "object",
|
|
5286
5415
|
raw,
|
|
5287
5416
|
...synthetic ? {} : { properties: membersToProperties(typeNode.members, sourceFile) }
|
|
5288
5417
|
};
|
|
5289
5418
|
}
|
|
5290
|
-
if (
|
|
5291
|
-
const refName =
|
|
5419
|
+
if (ts10.isTypeReferenceNode(typeNode)) {
|
|
5420
|
+
const refName = ts10.isIdentifier(typeNode.typeName) ? typeNode.typeName.text : "";
|
|
5292
5421
|
if ((refName === "Array" || refName === "ReadonlyArray") && typeNode.typeArguments?.length === 1) {
|
|
5293
5422
|
return { kind: "array", raw, elementType: recurse(typeNode.typeArguments[0]) };
|
|
5294
5423
|
}
|
|
@@ -5297,7 +5426,7 @@ function typeNodeToTypeInfo(typeNode, sourceFile, rawOf) {
|
|
|
5297
5426
|
raw
|
|
5298
5427
|
};
|
|
5299
5428
|
}
|
|
5300
|
-
if (
|
|
5429
|
+
if (ts10.isFunctionTypeNode(typeNode)) {
|
|
5301
5430
|
if (synthetic)
|
|
5302
5431
|
return { kind: "function", raw };
|
|
5303
5432
|
return {
|
|
@@ -5317,15 +5446,15 @@ function typeNodeToTypeInfo(typeNode, sourceFile, rawOf) {
|
|
|
5317
5446
|
}
|
|
5318
5447
|
return { kind: "unknown", raw };
|
|
5319
5448
|
}
|
|
5320
|
-
var _typePrinter =
|
|
5321
|
-
var _blankTypeSourceFile =
|
|
5449
|
+
var _typePrinter = ts10.createPrinter({ removeComments: true, omitTrailingSemicolon: true });
|
|
5450
|
+
var _blankTypeSourceFile = ts10.createSourceFile("__bf_types__.ts", "", ts10.ScriptTarget.Latest);
|
|
5322
5451
|
function tsTypeToTypeInfo(type, checker) {
|
|
5323
|
-
const node = checker.typeToTypeNode(type, undefined,
|
|
5452
|
+
const node = checker.typeToTypeNode(type, undefined, ts10.NodeBuilderFlags.NoTruncation);
|
|
5324
5453
|
if (!node)
|
|
5325
5454
|
return null;
|
|
5326
5455
|
const rawOf = (n) => {
|
|
5327
5456
|
try {
|
|
5328
|
-
return _typePrinter.printNode(
|
|
5457
|
+
return _typePrinter.printNode(ts10.EmitHint.Unspecified, n, _blankTypeSourceFile);
|
|
5329
5458
|
} catch {
|
|
5330
5459
|
return "unknown";
|
|
5331
5460
|
}
|
|
@@ -5336,16 +5465,16 @@ function isPascalCase(name) {
|
|
|
5336
5465
|
return /^[A-Z][a-zA-Z0-9]*$/.test(name);
|
|
5337
5466
|
}
|
|
5338
5467
|
function isComponentFunction(node) {
|
|
5339
|
-
return
|
|
5468
|
+
return ts10.isFunctionDeclaration(node) && !!node.name && isPascalCase(node.name.text) && !!node.body;
|
|
5340
5469
|
}
|
|
5341
5470
|
function isArrowComponentFunction(node) {
|
|
5342
|
-
if (!
|
|
5471
|
+
if (!ts10.isVariableDeclaration(node))
|
|
5343
5472
|
return false;
|
|
5344
|
-
if (!
|
|
5473
|
+
if (!ts10.isIdentifier(node.name))
|
|
5345
5474
|
return false;
|
|
5346
5475
|
if (!isPascalCase(node.name.text))
|
|
5347
5476
|
return false;
|
|
5348
|
-
if (!node.initializer || !
|
|
5477
|
+
if (!node.initializer || !ts10.isArrowFunction(node.initializer))
|
|
5349
5478
|
return false;
|
|
5350
5479
|
return true;
|
|
5351
5480
|
}
|
|
@@ -5672,9 +5801,9 @@ function needsTypeBasedDetection(source) {
|
|
|
5672
5801
|
}
|
|
5673
5802
|
function findBrandPackageImportLoc(sourceFile, filePath) {
|
|
5674
5803
|
for (const stmt of sourceFile.statements) {
|
|
5675
|
-
if (!
|
|
5804
|
+
if (!ts11.isImportDeclaration(stmt))
|
|
5676
5805
|
continue;
|
|
5677
|
-
if (!
|
|
5806
|
+
if (!ts11.isStringLiteral(stmt.moduleSpecifier))
|
|
5678
5807
|
continue;
|
|
5679
5808
|
if (!REACTIVE_BRAND_PACKAGES.includes(stmt.moduleSpecifier.text))
|
|
5680
5809
|
continue;
|
|
@@ -5693,21 +5822,21 @@ function createProgramForFile(source, filePath) {
|
|
|
5693
5822
|
try {
|
|
5694
5823
|
const normalizedPath = path2.resolve(filePath);
|
|
5695
5824
|
const compilerOptions = {
|
|
5696
|
-
target:
|
|
5697
|
-
module:
|
|
5698
|
-
moduleResolution:
|
|
5699
|
-
jsx:
|
|
5825
|
+
target: ts11.ScriptTarget.Latest,
|
|
5826
|
+
module: ts11.ModuleKind.ESNext,
|
|
5827
|
+
moduleResolution: ts11.ModuleResolutionKind.Bundler,
|
|
5828
|
+
jsx: ts11.JsxEmit.ReactJSX,
|
|
5700
5829
|
strict: true,
|
|
5701
5830
|
skipLibCheck: true,
|
|
5702
5831
|
noEmit: true,
|
|
5703
5832
|
baseUrl: path2.dirname(normalizedPath)
|
|
5704
5833
|
};
|
|
5705
|
-
const defaultHost =
|
|
5834
|
+
const defaultHost = ts11.createCompilerHost(compilerOptions);
|
|
5706
5835
|
const virtualHost = {
|
|
5707
5836
|
...defaultHost,
|
|
5708
5837
|
getSourceFile(fileName, languageVersion) {
|
|
5709
5838
|
if (path2.resolve(fileName) === normalizedPath) {
|
|
5710
|
-
return
|
|
5839
|
+
return ts11.createSourceFile(fileName, source, languageVersion, true, ts11.ScriptKind.TSX);
|
|
5711
5840
|
}
|
|
5712
5841
|
return defaultHost.getSourceFile(fileName, languageVersion);
|
|
5713
5842
|
},
|
|
@@ -5722,7 +5851,7 @@ function createProgramForFile(source, filePath) {
|
|
|
5722
5851
|
return defaultHost.readFile(fileName);
|
|
5723
5852
|
}
|
|
5724
5853
|
};
|
|
5725
|
-
const program =
|
|
5854
|
+
const program = ts11.createProgram([normalizedPath], compilerOptions, virtualHost);
|
|
5726
5855
|
const sourceFile = program.getSourceFile(normalizedPath);
|
|
5727
5856
|
if (!sourceFile)
|
|
5728
5857
|
return null;
|
|
@@ -5755,7 +5884,7 @@ function analyzeComponent(source, filePath, targetComponentName, program, accept
|
|
|
5755
5884
|
}
|
|
5756
5885
|
}
|
|
5757
5886
|
if (!sourceFile) {
|
|
5758
|
-
sourceFile =
|
|
5887
|
+
sourceFile = ts11.createSourceFile(filePath, source, ts11.ScriptTarget.Latest, true, ts11.ScriptKind.TSX);
|
|
5759
5888
|
}
|
|
5760
5889
|
if (!checker && needsTypeBasedDetection(source)) {
|
|
5761
5890
|
const result = createProgramForFile(source, filePath);
|
|
@@ -5801,23 +5930,23 @@ function analyzeComponent(source, filePath, targetComponentName, program, accept
|
|
|
5801
5930
|
function findDefaultExportedComponent(sourceFile) {
|
|
5802
5931
|
let defaultExportName;
|
|
5803
5932
|
function findDefaultExport(node) {
|
|
5804
|
-
if (
|
|
5805
|
-
if (
|
|
5933
|
+
if (ts11.isExportAssignment(node) && !node.isExportEquals) {
|
|
5934
|
+
if (ts11.isIdentifier(node.expression)) {
|
|
5806
5935
|
defaultExportName = node.expression.text;
|
|
5807
5936
|
}
|
|
5808
5937
|
}
|
|
5809
|
-
if (
|
|
5938
|
+
if (ts11.isFunctionDeclaration(node) && node.name && node.modifiers?.some((m) => m.kind === ts11.SyntaxKind.DefaultKeyword)) {
|
|
5810
5939
|
defaultExportName = node.name.text;
|
|
5811
5940
|
}
|
|
5812
|
-
|
|
5941
|
+
ts11.forEachChild(node, findDefaultExport);
|
|
5813
5942
|
}
|
|
5814
|
-
|
|
5943
|
+
ts11.forEachChild(sourceFile, findDefaultExport);
|
|
5815
5944
|
return defaultExportName;
|
|
5816
5945
|
}
|
|
5817
5946
|
function collectNamedExports(sourceFile) {
|
|
5818
5947
|
const exported = new Set;
|
|
5819
5948
|
for (const stmt of sourceFile.statements) {
|
|
5820
|
-
if (
|
|
5949
|
+
if (ts11.isExportDeclaration(stmt) && stmt.exportClause && ts11.isNamedExports(stmt.exportClause)) {
|
|
5821
5950
|
for (const spec of stmt.exportClause.elements) {
|
|
5822
5951
|
const local = (spec.propertyName ?? spec.name).text;
|
|
5823
5952
|
exported.add(local);
|
|
@@ -5827,22 +5956,22 @@ function collectNamedExports(sourceFile) {
|
|
|
5827
5956
|
return exported;
|
|
5828
5957
|
}
|
|
5829
5958
|
function visit(node, ctx, targetComponentName, namedExports) {
|
|
5830
|
-
if (
|
|
5959
|
+
if (ts11.isExpressionStatement(node) && ts11.isStringLiteral(node.expression)) {
|
|
5831
5960
|
if (node.expression.text === "use client" || node.expression.text === "'use client'") {
|
|
5832
5961
|
ctx.hasUseClientDirective = true;
|
|
5833
5962
|
}
|
|
5834
5963
|
}
|
|
5835
|
-
if (
|
|
5964
|
+
if (ts11.isImportDeclaration(node)) {
|
|
5836
5965
|
collectImport(node, ctx);
|
|
5837
5966
|
}
|
|
5838
|
-
if (
|
|
5967
|
+
if (ts11.isInterfaceDeclaration(node)) {
|
|
5839
5968
|
collectInterfaceDefinition(node, ctx);
|
|
5840
5969
|
}
|
|
5841
|
-
if (
|
|
5970
|
+
if (ts11.isTypeAliasDeclaration(node)) {
|
|
5842
5971
|
collectTypeAliasDefinition(node, ctx);
|
|
5843
5972
|
}
|
|
5844
|
-
if (!ctx.hasUseClientDirective &&
|
|
5845
|
-
const hasInlineExport = node.modifiers?.some((m) => m.kind ===
|
|
5973
|
+
if (!ctx.hasUseClientDirective && ts11.isFunctionDeclaration(node) && node.name && node.body && isMultiReturnJsxFunctionBody(node.body)) {
|
|
5974
|
+
const hasInlineExport = node.modifiers?.some((m) => m.kind === ts11.SyntaxKind.ExportKeyword) ?? false;
|
|
5846
5975
|
const hasNamedExport = namedExports?.has(node.name.text) ?? false;
|
|
5847
5976
|
if (!hasInlineExport && !hasNamedExport) {
|
|
5848
5977
|
collectFunction(node, ctx, true, false);
|
|
@@ -5857,9 +5986,9 @@ function visit(node, ctx, targetComponentName, namedExports) {
|
|
|
5857
5986
|
if (!ctx.componentName) {
|
|
5858
5987
|
ctx.componentName = node.name.text;
|
|
5859
5988
|
ctx.componentNode = node;
|
|
5860
|
-
ctx.isExported = node.modifiers?.some((m) => m.kind ===
|
|
5989
|
+
ctx.isExported = node.modifiers?.some((m) => m.kind === ts11.SyntaxKind.ExportKeyword) ?? false;
|
|
5861
5990
|
analyzeComponentBody(node, ctx);
|
|
5862
|
-
if (node.modifiers?.some((m) => m.kind ===
|
|
5991
|
+
if (node.modifiers?.some((m) => m.kind === ts11.SyntaxKind.DefaultKeyword)) {
|
|
5863
5992
|
ctx.hasDefaultExport = true;
|
|
5864
5993
|
}
|
|
5865
5994
|
}
|
|
@@ -5873,10 +6002,10 @@ function visit(node, ctx, targetComponentName, namedExports) {
|
|
|
5873
6002
|
ctx.componentName = node.name.text;
|
|
5874
6003
|
ctx.componentNode = node.initializer;
|
|
5875
6004
|
const parentStatement = node.parent;
|
|
5876
|
-
if (
|
|
6005
|
+
if (ts11.isVariableDeclarationList(parentStatement)) {
|
|
5877
6006
|
const varStatement = parentStatement.parent;
|
|
5878
|
-
if (
|
|
5879
|
-
ctx.isExported = varStatement.modifiers?.some((m) => m.kind ===
|
|
6007
|
+
if (ts11.isVariableStatement(varStatement)) {
|
|
6008
|
+
ctx.isExported = varStatement.modifiers?.some((m) => m.kind === ts11.SyntaxKind.ExportKeyword) ?? false;
|
|
5880
6009
|
}
|
|
5881
6010
|
}
|
|
5882
6011
|
analyzeComponentBody(node.initializer, ctx);
|
|
@@ -5888,10 +6017,10 @@ function visit(node, ctx, targetComponentName, namedExports) {
|
|
|
5888
6017
|
if (!ctx.componentNode) {
|
|
5889
6018
|
collectAmbientGlobals(node, ctx);
|
|
5890
6019
|
}
|
|
5891
|
-
const isDeclareStatement =
|
|
5892
|
-
if (
|
|
5893
|
-
const isExported = node.modifiers?.some((m) => m.kind ===
|
|
5894
|
-
const isLet = (node.declarationList.flags &
|
|
6020
|
+
const isDeclareStatement = ts11.isVariableStatement(node) && (node.modifiers?.some((m) => m.kind === ts11.SyntaxKind.DeclareKeyword) ?? false);
|
|
6021
|
+
if (ts11.isVariableStatement(node) && !ctx.componentNode && !isDeclareStatement) {
|
|
6022
|
+
const isExported = node.modifiers?.some((m) => m.kind === ts11.SyntaxKind.ExportKeyword) ?? false;
|
|
6023
|
+
const isLet = (node.declarationList.flags & ts11.NodeFlags.Let) !== 0;
|
|
5895
6024
|
const isModuleClientDirective = hasLeadingClientDirectiveOnStatement(node, ctx.sourceFile);
|
|
5896
6025
|
for (const decl of node.declarationList.declarations) {
|
|
5897
6026
|
if (declarationIsReactiveFactoryCall(decl, ctx)) {
|
|
@@ -5902,19 +6031,19 @@ function visit(node, ctx, targetComponentName, namedExports) {
|
|
|
5902
6031
|
}
|
|
5903
6032
|
continue;
|
|
5904
6033
|
}
|
|
5905
|
-
if (
|
|
6034
|
+
if (ts11.isIdentifier(decl.name) && (decl.initializer || isLet) && !isArrowComponentFunction(decl)) {
|
|
5906
6035
|
collectConstant(decl, ctx, true, isLet ? "let" : "const", isExported);
|
|
5907
6036
|
}
|
|
5908
6037
|
}
|
|
5909
6038
|
}
|
|
5910
|
-
if (
|
|
5911
|
-
const isExported = node.modifiers?.some((m) => m.kind ===
|
|
6039
|
+
if (ts11.isFunctionDeclaration(node) && node.name && !isComponentFunction(node)) {
|
|
6040
|
+
const isExported = node.modifiers?.some((m) => m.kind === ts11.SyntaxKind.ExportKeyword) ?? false;
|
|
5912
6041
|
collectFunction(node, ctx, true, isExported);
|
|
5913
6042
|
return;
|
|
5914
6043
|
}
|
|
5915
|
-
if (
|
|
6044
|
+
if (ts11.isExportDeclaration(node) && node.exportClause && ts11.isNamedExports(node.exportClause)) {
|
|
5916
6045
|
const isFromReexport = !!node.moduleSpecifier;
|
|
5917
|
-
const sourceSpec = node.moduleSpecifier &&
|
|
6046
|
+
const sourceSpec = node.moduleSpecifier && ts11.isStringLiteral(node.moduleSpecifier) ? node.moduleSpecifier.text : null;
|
|
5918
6047
|
const exportSpecifiers = node.exportClause.elements.map((spec) => ({
|
|
5919
6048
|
name: (spec.propertyName ?? spec.name).text,
|
|
5920
6049
|
alias: spec.propertyName ? spec.name.text : null,
|
|
@@ -5942,24 +6071,24 @@ function visit(node, ctx, targetComponentName, namedExports) {
|
|
|
5942
6071
|
}
|
|
5943
6072
|
}
|
|
5944
6073
|
}
|
|
5945
|
-
if (
|
|
6074
|
+
if (ts11.isExportAssignment(node) && !node.isExportEquals) {
|
|
5946
6075
|
const expr = node.expression;
|
|
5947
|
-
if (
|
|
6076
|
+
if (ts11.isIdentifier(expr)) {
|
|
5948
6077
|
if (ctx.componentName && expr.text === ctx.componentName) {
|
|
5949
6078
|
ctx.hasDefaultExport = true;
|
|
5950
6079
|
ctx.isExported = true;
|
|
5951
6080
|
}
|
|
5952
6081
|
}
|
|
5953
6082
|
}
|
|
5954
|
-
|
|
6083
|
+
ts11.forEachChild(node, (child) => visit(child, ctx, targetComponentName, namedExports));
|
|
5955
6084
|
}
|
|
5956
6085
|
function analyzeComponentBody(node, ctx) {
|
|
5957
6086
|
if (node.parameters.length > 0) {
|
|
5958
6087
|
extractProps(node.parameters[0], ctx);
|
|
5959
6088
|
}
|
|
5960
|
-
const body =
|
|
6089
|
+
const body = ts11.isFunctionDeclaration(node) ? node.body : getArrowFunctionBody(node);
|
|
5961
6090
|
if (body) {
|
|
5962
|
-
ctx.componentBodyBlock =
|
|
6091
|
+
ctx.componentBodyBlock = ts11.isBlock(body) ? body : null;
|
|
5963
6092
|
if (!ctx.componentBodyBlock) {
|
|
5964
6093
|
ctx.jsxReturn = unwrapJsxTransparent(body);
|
|
5965
6094
|
}
|
|
@@ -5969,14 +6098,14 @@ function analyzeComponentBody(node, ctx) {
|
|
|
5969
6098
|
}
|
|
5970
6099
|
}
|
|
5971
6100
|
function getArrowFunctionBody(node) {
|
|
5972
|
-
if (
|
|
6101
|
+
if (ts11.isBlock(node.body)) {
|
|
5973
6102
|
return node.body;
|
|
5974
6103
|
}
|
|
5975
6104
|
return node.body;
|
|
5976
6105
|
}
|
|
5977
6106
|
function visitComponentBody(node, ctx) {
|
|
5978
6107
|
const isTopLevel = ctx.componentBodyBlock !== null && node.parent === ctx.componentBodyBlock;
|
|
5979
|
-
if (
|
|
6108
|
+
if (ts11.isVariableStatement(node)) {
|
|
5980
6109
|
for (const decl of node.declarationList.declarations) {
|
|
5981
6110
|
if (isSignalDeclaration(decl, ctx)) {
|
|
5982
6111
|
collectSignal(decl, ctx);
|
|
@@ -5999,16 +6128,16 @@ function visitComponentBody(node, ctx) {
|
|
|
5999
6128
|
collectEffect(decl.initializer, ctx, decl.name.text);
|
|
6000
6129
|
continue;
|
|
6001
6130
|
}
|
|
6002
|
-
if (
|
|
6003
|
-
const isLet = (node.declarationList.flags &
|
|
6131
|
+
if (ts11.isIdentifier(decl.name)) {
|
|
6132
|
+
const isLet = (node.declarationList.flags & ts11.NodeFlags.Let) !== 0;
|
|
6004
6133
|
collectConstant(decl, ctx, false, isLet ? "let" : "const");
|
|
6005
|
-
} else if (
|
|
6006
|
-
const isLet = (node.declarationList.flags &
|
|
6134
|
+
} else if (ts11.isObjectBindingPattern(decl.name) && decl.initializer && ts11.isIdentifier(decl.initializer) && ctx.propsObjectName === decl.initializer.text) {
|
|
6135
|
+
const isLet = (node.declarationList.flags & ts11.NodeFlags.Let) !== 0;
|
|
6007
6136
|
collectConstant(decl, ctx, false, isLet ? "let" : "const");
|
|
6008
6137
|
}
|
|
6009
6138
|
}
|
|
6010
6139
|
}
|
|
6011
|
-
if (
|
|
6140
|
+
if (ts11.isExpressionStatement(node)) {
|
|
6012
6141
|
if (isEffectCall(node.expression, ctx)) {
|
|
6013
6142
|
collectEffect(node.expression, ctx);
|
|
6014
6143
|
return;
|
|
@@ -6022,10 +6151,10 @@ function visitComponentBody(node, ctx) {
|
|
|
6022
6151
|
return;
|
|
6023
6152
|
}
|
|
6024
6153
|
}
|
|
6025
|
-
if (
|
|
6154
|
+
if (ts11.isFunctionDeclaration(node) && node.name) {
|
|
6026
6155
|
collectFunction(node, ctx, false);
|
|
6027
6156
|
}
|
|
6028
|
-
if (
|
|
6157
|
+
if (ts11.isIfStatement(node)) {
|
|
6029
6158
|
const jsxReturn = findJsxReturnInBlock(node.thenStatement);
|
|
6030
6159
|
if (jsxReturn) {
|
|
6031
6160
|
const scopeVars = collectScopeVariables(node.thenStatement, ctx);
|
|
@@ -6044,8 +6173,8 @@ function visitComponentBody(node, ctx) {
|
|
|
6044
6173
|
return;
|
|
6045
6174
|
}
|
|
6046
6175
|
}
|
|
6047
|
-
if (isTopLevel && (
|
|
6048
|
-
if (
|
|
6176
|
+
if (isTopLevel && (ts11.isTryStatement(node) || ts11.isSwitchStatement(node) || ts11.isForStatement(node) || ts11.isForInStatement(node) || ts11.isForOfStatement(node) || ts11.isWhileStatement(node) || ts11.isDoStatement(node) || ts11.isThrowStatement(node) || ts11.isBlock(node) && node.parent === ctx.componentBodyBlock)) {
|
|
6177
|
+
if (ts11.isBlock(node)) {
|
|
6049
6178
|
const returnedLocal = findBlockBodyReturnedJsxLocalName(node);
|
|
6050
6179
|
if (returnedLocal) {
|
|
6051
6180
|
ctx.errors.push(createError(ErrorCodes.RETURN_VALUE_NOT_JSX, getSourceLocation(node, ctx.sourceFile, ctx.filePath), {
|
|
@@ -6056,34 +6185,34 @@ function visitComponentBody(node, ctx) {
|
|
|
6056
6185
|
collectInitStatement(node, ctx);
|
|
6057
6186
|
return;
|
|
6058
6187
|
}
|
|
6059
|
-
if (
|
|
6188
|
+
if (ts11.isReturnStatement(node) && node.expression) {
|
|
6060
6189
|
ctx.jsxReturn = unwrapJsxTransparent(node.expression);
|
|
6061
6190
|
}
|
|
6062
|
-
|
|
6063
|
-
if (
|
|
6191
|
+
ts11.forEachChild(node, (child) => {
|
|
6192
|
+
if (ts11.isArrowFunction(child) || ts11.isFunctionExpression(child) || ts11.isFunctionDeclaration(child)) {
|
|
6064
6193
|
return;
|
|
6065
6194
|
}
|
|
6066
6195
|
visitComponentBody(child, ctx);
|
|
6067
6196
|
});
|
|
6068
6197
|
}
|
|
6069
6198
|
function findJsxReturnInBlock(node) {
|
|
6070
|
-
if (
|
|
6199
|
+
if (ts11.isBlock(node)) {
|
|
6071
6200
|
for (const stmt of node.statements) {
|
|
6072
|
-
if (
|
|
6201
|
+
if (ts11.isReturnStatement(stmt) && stmt.expression) {
|
|
6073
6202
|
const jsx = extractJsxFromExpression(stmt.expression);
|
|
6074
6203
|
if (jsx)
|
|
6075
6204
|
return jsx;
|
|
6076
6205
|
}
|
|
6077
6206
|
}
|
|
6078
6207
|
}
|
|
6079
|
-
if (
|
|
6208
|
+
if (ts11.isReturnStatement(node) && node.expression) {
|
|
6080
6209
|
return extractJsxFromExpression(node.expression);
|
|
6081
6210
|
}
|
|
6082
6211
|
return null;
|
|
6083
6212
|
}
|
|
6084
6213
|
function unwrapJsxTransparent(expr) {
|
|
6085
6214
|
let current = expr;
|
|
6086
|
-
while (
|
|
6215
|
+
while (ts11.isParenthesizedExpression(current) || ts11.isAsExpression(current) || ts11.isSatisfiesExpression(current) || ts11.isNonNullExpression(current) || ts11.isTypeAssertionExpression(current) || current.kind === ts11.SyntaxKind.PartiallyEmittedExpression) {
|
|
6087
6216
|
current = current.expression;
|
|
6088
6217
|
}
|
|
6089
6218
|
return current;
|
|
@@ -6091,22 +6220,22 @@ function unwrapJsxTransparent(expr) {
|
|
|
6091
6220
|
function findBlockBodyReturnedJsxLocalName(block) {
|
|
6092
6221
|
const stmts = block.statements;
|
|
6093
6222
|
const last = stmts[stmts.length - 1];
|
|
6094
|
-
if (!last || !
|
|
6223
|
+
if (!last || !ts11.isReturnStatement(last) || !last.expression)
|
|
6095
6224
|
return null;
|
|
6096
6225
|
const returned = unwrapJsxTransparent(last.expression);
|
|
6097
|
-
if (!
|
|
6226
|
+
if (!ts11.isIdentifier(returned))
|
|
6098
6227
|
return null;
|
|
6099
6228
|
const name = returned.text;
|
|
6100
6229
|
for (const stmt of stmts) {
|
|
6101
|
-
if (!
|
|
6230
|
+
if (!ts11.isVariableStatement(stmt))
|
|
6102
6231
|
continue;
|
|
6103
6232
|
for (const decl of stmt.declarationList.declarations) {
|
|
6104
|
-
if (!
|
|
6233
|
+
if (!ts11.isIdentifier(decl.name) || decl.name.text !== name || !decl.initializer)
|
|
6105
6234
|
continue;
|
|
6106
6235
|
let init = decl.initializer;
|
|
6107
|
-
while (
|
|
6236
|
+
while (ts11.isParenthesizedExpression(init))
|
|
6108
6237
|
init = init.expression;
|
|
6109
|
-
if (
|
|
6238
|
+
if (ts11.isJsxElement(init) || ts11.isJsxSelfClosingElement(init) || ts11.isJsxFragment(init) || initializerShapeContainsJsx(init) || isMapLikeCallWithJsx(init)) {
|
|
6110
6239
|
return name;
|
|
6111
6240
|
}
|
|
6112
6241
|
}
|
|
@@ -6115,16 +6244,16 @@ function findBlockBodyReturnedJsxLocalName(block) {
|
|
|
6115
6244
|
}
|
|
6116
6245
|
function extractJsxFromExpression(expr) {
|
|
6117
6246
|
const inner = unwrapJsxTransparent(expr);
|
|
6118
|
-
if (
|
|
6247
|
+
if (ts11.isJsxElement(inner) || ts11.isJsxFragment(inner) || ts11.isJsxSelfClosingElement(inner)) {
|
|
6119
6248
|
return inner;
|
|
6120
6249
|
}
|
|
6121
6250
|
return null;
|
|
6122
6251
|
}
|
|
6123
6252
|
function collectScopeVariables(node, ctx) {
|
|
6124
6253
|
const variables = [];
|
|
6125
|
-
if (
|
|
6254
|
+
if (ts11.isBlock(node)) {
|
|
6126
6255
|
for (const stmt of node.statements) {
|
|
6127
|
-
if (
|
|
6256
|
+
if (ts11.isVariableStatement(stmt)) {
|
|
6128
6257
|
for (const decl of stmt.declarationList.declarations) {
|
|
6129
6258
|
variables.push(decl);
|
|
6130
6259
|
}
|
|
@@ -6136,13 +6265,13 @@ function collectScopeVariables(node, ctx) {
|
|
|
6136
6265
|
function collectParamBindingNames(params) {
|
|
6137
6266
|
const out = new Set;
|
|
6138
6267
|
const addBindingNames = (name) => {
|
|
6139
|
-
if (
|
|
6268
|
+
if (ts11.isIdentifier(name)) {
|
|
6140
6269
|
out.add(name.text);
|
|
6141
|
-
} else if (
|
|
6270
|
+
} else if (ts11.isObjectBindingPattern(name)) {
|
|
6142
6271
|
name.elements.forEach((e) => addBindingNames(e.name));
|
|
6143
|
-
} else if (
|
|
6272
|
+
} else if (ts11.isArrayBindingPattern(name)) {
|
|
6144
6273
|
name.elements.forEach((e) => {
|
|
6145
|
-
if (!
|
|
6274
|
+
if (!ts11.isOmittedExpression(e))
|
|
6146
6275
|
addBindingNames(e.name);
|
|
6147
6276
|
});
|
|
6148
6277
|
}
|
|
@@ -6159,7 +6288,7 @@ function collectEnclosingBranchVars(node, ctx) {
|
|
|
6159
6288
|
if (cr.ifStatement.thenStatement !== current)
|
|
6160
6289
|
continue;
|
|
6161
6290
|
for (const decl of cr.scopeVariables) {
|
|
6162
|
-
if (!
|
|
6291
|
+
if (!ts11.isIdentifier(decl.name) || !decl.initializer)
|
|
6163
6292
|
continue;
|
|
6164
6293
|
const varName = decl.name.text;
|
|
6165
6294
|
if (result.has(varName))
|
|
@@ -6174,10 +6303,10 @@ function collectEnclosingBranchVars(node, ctx) {
|
|
|
6174
6303
|
return result;
|
|
6175
6304
|
}
|
|
6176
6305
|
function collectBranchSignals(thenStatement, ctx, branchCondition) {
|
|
6177
|
-
if (!
|
|
6306
|
+
if (!ts11.isBlock(thenStatement))
|
|
6178
6307
|
return;
|
|
6179
6308
|
for (const stmt of thenStatement.statements) {
|
|
6180
|
-
if (!
|
|
6309
|
+
if (!ts11.isVariableStatement(stmt))
|
|
6181
6310
|
continue;
|
|
6182
6311
|
for (const decl of stmt.declarationList.declarations) {
|
|
6183
6312
|
if (!isSignalDeclaration(decl, ctx))
|
|
@@ -6203,13 +6332,13 @@ var ENV_SIGNAL_FACTORIES = {
|
|
|
6203
6332
|
createSearchParams: "search"
|
|
6204
6333
|
};
|
|
6205
6334
|
function resolvePrimitiveKind(callExpr, ctx) {
|
|
6206
|
-
if (
|
|
6335
|
+
if (ts11.isIdentifier(callExpr.expression)) {
|
|
6207
6336
|
const hit = PRIMITIVE_CANONICAL_NAMES[callExpr.expression.text];
|
|
6208
6337
|
if (hit)
|
|
6209
6338
|
return hit;
|
|
6210
6339
|
return resolveCalleeViaChecker(callExpr.expression, ctx);
|
|
6211
6340
|
}
|
|
6212
|
-
if (
|
|
6341
|
+
if (ts11.isPropertyAccessExpression(callExpr.expression)) {
|
|
6213
6342
|
const propName = callExpr.expression.name.text;
|
|
6214
6343
|
const hit = PRIMITIVE_CANONICAL_NAMES[propName];
|
|
6215
6344
|
if (!hit)
|
|
@@ -6236,7 +6365,7 @@ function resolveCanonicalClientExportName(ident, ctx) {
|
|
|
6236
6365
|
if (!symbol)
|
|
6237
6366
|
return null;
|
|
6238
6367
|
let target = symbol;
|
|
6239
|
-
if (symbol.flags &
|
|
6368
|
+
if (symbol.flags & ts11.SymbolFlags.Alias) {
|
|
6240
6369
|
try {
|
|
6241
6370
|
target = ctx.checker.getAliasedSymbol(symbol);
|
|
6242
6371
|
} catch {
|
|
@@ -6252,14 +6381,14 @@ function resolveCanonicalClientExportName(ident, ctx) {
|
|
|
6252
6381
|
return null;
|
|
6253
6382
|
}
|
|
6254
6383
|
function resolveEnvSignalKey(callExpr, ctx) {
|
|
6255
|
-
if (
|
|
6384
|
+
if (ts11.isIdentifier(callExpr.expression)) {
|
|
6256
6385
|
const key = ENV_SIGNAL_FACTORIES[callExpr.expression.text];
|
|
6257
6386
|
if (key)
|
|
6258
6387
|
return key;
|
|
6259
6388
|
const canonical = resolveCanonicalClientExportName(callExpr.expression, ctx);
|
|
6260
6389
|
return canonical ? ENV_SIGNAL_FACTORIES[canonical] ?? null : null;
|
|
6261
6390
|
}
|
|
6262
|
-
if (
|
|
6391
|
+
if (ts11.isPropertyAccessExpression(callExpr.expression)) {
|
|
6263
6392
|
const key = ENV_SIGNAL_FACTORIES[callExpr.expression.name.text];
|
|
6264
6393
|
if (key && isBarefootClientNamespace(callExpr.expression.expression, ctx))
|
|
6265
6394
|
return key;
|
|
@@ -6267,7 +6396,7 @@ function resolveEnvSignalKey(callExpr, ctx) {
|
|
|
6267
6396
|
return null;
|
|
6268
6397
|
}
|
|
6269
6398
|
function isBarefootClientNamespace(expr, ctx) {
|
|
6270
|
-
if (!
|
|
6399
|
+
if (!ts11.isIdentifier(expr))
|
|
6271
6400
|
return false;
|
|
6272
6401
|
if (!ctx.checker)
|
|
6273
6402
|
return false;
|
|
@@ -6280,22 +6409,22 @@ function isBarefootClientNamespace(expr, ctx) {
|
|
|
6280
6409
|
if (!symbol)
|
|
6281
6410
|
return false;
|
|
6282
6411
|
for (const decl of symbol.declarations ?? []) {
|
|
6283
|
-
if (!
|
|
6412
|
+
if (!ts11.isNamespaceImport(decl))
|
|
6284
6413
|
continue;
|
|
6285
6414
|
const importDecl = decl.parent.parent;
|
|
6286
|
-
if (!
|
|
6415
|
+
if (!ts11.isImportDeclaration(importDecl))
|
|
6287
6416
|
continue;
|
|
6288
6417
|
const mod = importDecl.moduleSpecifier;
|
|
6289
|
-
if (
|
|
6418
|
+
if (ts11.isStringLiteral(mod) && mod.text === "@barefootjs/client") {
|
|
6290
6419
|
return true;
|
|
6291
6420
|
}
|
|
6292
6421
|
}
|
|
6293
6422
|
return false;
|
|
6294
6423
|
}
|
|
6295
6424
|
function isSignalDeclaration(node, ctx) {
|
|
6296
|
-
if (!
|
|
6425
|
+
if (!ts11.isArrayBindingPattern(node.name))
|
|
6297
6426
|
return false;
|
|
6298
|
-
if (!node.initializer || !
|
|
6427
|
+
if (!node.initializer || !ts11.isCallExpression(node.initializer))
|
|
6299
6428
|
return false;
|
|
6300
6429
|
return resolvePrimitiveKind(node.initializer, ctx) === "signal";
|
|
6301
6430
|
}
|
|
@@ -6303,14 +6432,14 @@ function collectSignal(node, ctx) {
|
|
|
6303
6432
|
const pattern = node.name;
|
|
6304
6433
|
const callExpr = node.initializer;
|
|
6305
6434
|
const elements = pattern.elements;
|
|
6306
|
-
const getterElided = elements.length === 2 &&
|
|
6307
|
-
if (elements.length < 1 || elements.length > 2 || !getterElided && (!
|
|
6435
|
+
const getterElided = elements.length === 2 && ts11.isOmittedExpression(elements[0]);
|
|
6436
|
+
if (elements.length < 1 || elements.length > 2 || !getterElided && (!ts11.isBindingElement(elements[0]) || !ts11.isIdentifier(elements[0].name))) {
|
|
6308
6437
|
return;
|
|
6309
6438
|
}
|
|
6310
|
-
if (elements.length === 2 && (!
|
|
6439
|
+
if (elements.length === 2 && (!ts11.isBindingElement(elements[1]) || !ts11.isIdentifier(elements[1].name))) {
|
|
6311
6440
|
return;
|
|
6312
6441
|
}
|
|
6313
|
-
const setter = elements.length === 2 &&
|
|
6442
|
+
const setter = elements.length === 2 && ts11.isBindingElement(elements[1]) && ts11.isIdentifier(elements[1].name) ? elements[1].name.text : null;
|
|
6314
6443
|
if (getterElided && !setter)
|
|
6315
6444
|
return;
|
|
6316
6445
|
const getter = getterElided ? `__bfGet_${setter}` : elements[0].name.text;
|
|
@@ -6347,33 +6476,33 @@ function collectSignal(node, ctx) {
|
|
|
6347
6476
|
});
|
|
6348
6477
|
}
|
|
6349
6478
|
function isSignalTupleDeclaration(node) {
|
|
6350
|
-
if (!
|
|
6479
|
+
if (!ts11.isIdentifier(node.name))
|
|
6351
6480
|
return false;
|
|
6352
|
-
if (!node.initializer || !
|
|
6481
|
+
if (!node.initializer || !ts11.isCallExpression(node.initializer))
|
|
6353
6482
|
return false;
|
|
6354
6483
|
const callExpr = node.initializer;
|
|
6355
|
-
return
|
|
6484
|
+
return ts11.isIdentifier(callExpr.expression) && callExpr.expression.text === "createSignal";
|
|
6356
6485
|
}
|
|
6357
6486
|
function isSignalIndexAccess(node, ctx) {
|
|
6358
|
-
if (!
|
|
6487
|
+
if (!ts11.isIdentifier(node.name))
|
|
6359
6488
|
return null;
|
|
6360
|
-
if (!node.initializer || !
|
|
6489
|
+
if (!node.initializer || !ts11.isElementAccessExpression(node.initializer))
|
|
6361
6490
|
return null;
|
|
6362
6491
|
const access = node.initializer;
|
|
6363
|
-
if (!
|
|
6492
|
+
if (!ts11.isNumericLiteral(access.argumentExpression))
|
|
6364
6493
|
return null;
|
|
6365
6494
|
const indexValue = Number(access.argumentExpression.text);
|
|
6366
6495
|
if (indexValue !== 0 && indexValue !== 1)
|
|
6367
6496
|
return null;
|
|
6368
6497
|
const index = indexValue;
|
|
6369
|
-
if (
|
|
6498
|
+
if (ts11.isCallExpression(access.expression)) {
|
|
6370
6499
|
const call = access.expression;
|
|
6371
|
-
if (
|
|
6500
|
+
if (ts11.isIdentifier(call.expression) && call.expression.text === "createSignal") {
|
|
6372
6501
|
return { kind: "direct", index, callExpr: call };
|
|
6373
6502
|
}
|
|
6374
6503
|
return null;
|
|
6375
6504
|
}
|
|
6376
|
-
if (
|
|
6505
|
+
if (ts11.isIdentifier(access.expression)) {
|
|
6377
6506
|
const tupleName = access.expression.text;
|
|
6378
6507
|
if (ctx.signalTupleRefs.has(tupleName)) {
|
|
6379
6508
|
return { kind: "tupleRef", index, tupleName };
|
|
@@ -6468,30 +6597,30 @@ function flushPendingSignalTuples(ctx) {
|
|
|
6468
6597
|
ctx.signalTupleRefs.clear();
|
|
6469
6598
|
}
|
|
6470
6599
|
function isMemoDeclaration(node, ctx) {
|
|
6471
|
-
if (!
|
|
6600
|
+
if (!ts11.isIdentifier(node.name))
|
|
6472
6601
|
return false;
|
|
6473
|
-
if (!node.initializer || !
|
|
6602
|
+
if (!node.initializer || !ts11.isCallExpression(node.initializer))
|
|
6474
6603
|
return false;
|
|
6475
6604
|
return resolvePrimitiveKind(node.initializer, ctx) === "memo";
|
|
6476
6605
|
}
|
|
6477
6606
|
function memoBodyIsTemplateLiteral(memoArrow) {
|
|
6478
6607
|
let node = memoArrow;
|
|
6479
|
-
while (node &&
|
|
6608
|
+
while (node && ts11.isParenthesizedExpression(node))
|
|
6480
6609
|
node = node.expression;
|
|
6481
|
-
if (!node || !
|
|
6610
|
+
if (!node || !ts11.isArrowFunction(node))
|
|
6482
6611
|
return false;
|
|
6483
6612
|
let body = node.body;
|
|
6484
|
-
while (
|
|
6613
|
+
while (ts11.isParenthesizedExpression(body))
|
|
6485
6614
|
body = body.expression;
|
|
6486
|
-
if (
|
|
6487
|
-
const ret = body.statements.find(
|
|
6615
|
+
if (ts11.isBlock(body)) {
|
|
6616
|
+
const ret = body.statements.find(ts11.isReturnStatement);
|
|
6488
6617
|
if (!ret || !ret.expression)
|
|
6489
6618
|
return false;
|
|
6490
6619
|
body = ret.expression;
|
|
6491
|
-
while (
|
|
6620
|
+
while (ts11.isParenthesizedExpression(body))
|
|
6492
6621
|
body = body.expression;
|
|
6493
6622
|
}
|
|
6494
|
-
return
|
|
6623
|
+
return ts11.isTemplateExpression(body) || ts11.isNoSubstitutionTemplateLiteral(body);
|
|
6495
6624
|
}
|
|
6496
6625
|
function collectMemo(node, ctx) {
|
|
6497
6626
|
const name = node.name.text;
|
|
@@ -6508,7 +6637,7 @@ function collectMemo(node, ctx) {
|
|
|
6508
6637
|
type = inferTypeFromValue(arrowBody);
|
|
6509
6638
|
}
|
|
6510
6639
|
}
|
|
6511
|
-
if (ctx.checker && (type.kind === "unknown" || type.kind === "object") && callExpr.arguments[0] && (
|
|
6640
|
+
if (ctx.checker && (type.kind === "unknown" || type.kind === "object") && callExpr.arguments[0] && (ts11.isArrowFunction(callExpr.arguments[0]) || ts11.isFunctionExpression(callExpr.arguments[0]))) {
|
|
6512
6641
|
const fnType = ctx.checker.getTypeAtLocation(callExpr.arguments[0]);
|
|
6513
6642
|
const sig = fnType.getCallSignatures()[0];
|
|
6514
6643
|
if (sig) {
|
|
@@ -6518,12 +6647,12 @@ function collectMemo(node, ctx) {
|
|
|
6518
6647
|
}
|
|
6519
6648
|
}
|
|
6520
6649
|
const memoArrow = callExpr.arguments[0];
|
|
6521
|
-
const parsedBody = memoArrow &&
|
|
6650
|
+
const parsedBody = memoArrow && ts11.isArrowFunction(memoArrow) && !ts11.isBlock(memoArrow.body) ? parseExpression(ctx.getJS(memoArrow.body)) : undefined;
|
|
6522
6651
|
const parsed = parsedBody && parsedBody.kind !== "unsupported" && parsedBody.kind !== "object-literal" ? parsedBody : undefined;
|
|
6523
6652
|
let arrowNode = memoArrow;
|
|
6524
|
-
while (arrowNode &&
|
|
6653
|
+
while (arrowNode && ts11.isParenthesizedExpression(arrowNode))
|
|
6525
6654
|
arrowNode = arrowNode.expression;
|
|
6526
|
-
const blockBody = arrowNode &&
|
|
6655
|
+
const blockBody = arrowNode && ts11.isArrowFunction(arrowNode) && ts11.isBlock(arrowNode.body) ? arrowNode.body : undefined;
|
|
6527
6656
|
const parsedBlock = blockBody ? parseBlockBodyTolerant(blockBody, ctx.sourceFile, (node2) => ctx.getJS(node2)) : undefined;
|
|
6528
6657
|
const parsedBlockComplete = parsedBlock && blockBody ? parsedBlock.length === blockBody.statements.length : undefined;
|
|
6529
6658
|
let templateComputation;
|
|
@@ -6550,14 +6679,14 @@ function collectMemo(node, ctx) {
|
|
|
6550
6679
|
});
|
|
6551
6680
|
}
|
|
6552
6681
|
function isEffectCall(node, ctx) {
|
|
6553
|
-
if (!
|
|
6682
|
+
if (!ts11.isCallExpression(node))
|
|
6554
6683
|
return false;
|
|
6555
6684
|
return resolvePrimitiveKind(node, ctx) === "effect";
|
|
6556
6685
|
}
|
|
6557
6686
|
function isEffectDisposerCapture(node, ctx) {
|
|
6558
|
-
if (!
|
|
6687
|
+
if (!ts11.isIdentifier(node.name))
|
|
6559
6688
|
return false;
|
|
6560
|
-
if (!node.initializer || !
|
|
6689
|
+
if (!node.initializer || !ts11.isCallExpression(node.initializer))
|
|
6561
6690
|
return false;
|
|
6562
6691
|
return resolvePrimitiveKind(node.initializer, ctx) === "effect";
|
|
6563
6692
|
}
|
|
@@ -6572,7 +6701,7 @@ function collectEffect(node, ctx, captureName) {
|
|
|
6572
6701
|
});
|
|
6573
6702
|
}
|
|
6574
6703
|
function isOnMountCall(node, ctx) {
|
|
6575
|
-
if (!
|
|
6704
|
+
if (!ts11.isCallExpression(node))
|
|
6576
6705
|
return false;
|
|
6577
6706
|
return resolvePrimitiveKind(node, ctx) === "onMount";
|
|
6578
6707
|
}
|
|
@@ -6607,19 +6736,19 @@ function leadsWithAsiHazard(body) {
|
|
|
6607
6736
|
function extractAssignedIdentifiersFromNode(node) {
|
|
6608
6737
|
const ids = new Set;
|
|
6609
6738
|
function addFromTarget(target) {
|
|
6610
|
-
if (
|
|
6739
|
+
if (ts11.isIdentifier(target)) {
|
|
6611
6740
|
ids.add(target.text);
|
|
6612
6741
|
return;
|
|
6613
6742
|
}
|
|
6614
|
-
if (
|
|
6743
|
+
if (ts11.isParenthesizedExpression(target)) {
|
|
6615
6744
|
addFromTarget(target.expression);
|
|
6616
6745
|
return;
|
|
6617
6746
|
}
|
|
6618
|
-
if (
|
|
6747
|
+
if (ts11.isArrayLiteralExpression(target)) {
|
|
6619
6748
|
for (const el of target.elements) {
|
|
6620
|
-
if (
|
|
6749
|
+
if (ts11.isOmittedExpression(el))
|
|
6621
6750
|
continue;
|
|
6622
|
-
if (
|
|
6751
|
+
if (ts11.isSpreadElement(el)) {
|
|
6623
6752
|
addFromTarget(el.expression);
|
|
6624
6753
|
continue;
|
|
6625
6754
|
}
|
|
@@ -6627,17 +6756,17 @@ function extractAssignedIdentifiersFromNode(node) {
|
|
|
6627
6756
|
}
|
|
6628
6757
|
return;
|
|
6629
6758
|
}
|
|
6630
|
-
if (
|
|
6759
|
+
if (ts11.isObjectLiteralExpression(target)) {
|
|
6631
6760
|
for (const prop of target.properties) {
|
|
6632
|
-
if (
|
|
6761
|
+
if (ts11.isShorthandPropertyAssignment(prop)) {
|
|
6633
6762
|
ids.add(prop.name.text);
|
|
6634
6763
|
continue;
|
|
6635
6764
|
}
|
|
6636
|
-
if (
|
|
6765
|
+
if (ts11.isPropertyAssignment(prop)) {
|
|
6637
6766
|
addFromTarget(prop.initializer);
|
|
6638
6767
|
continue;
|
|
6639
6768
|
}
|
|
6640
|
-
if (
|
|
6769
|
+
if (ts11.isSpreadAssignment(prop)) {
|
|
6641
6770
|
addFromTarget(prop.expression);
|
|
6642
6771
|
continue;
|
|
6643
6772
|
}
|
|
@@ -6646,21 +6775,21 @@ function extractAssignedIdentifiersFromNode(node) {
|
|
|
6646
6775
|
}
|
|
6647
6776
|
}
|
|
6648
6777
|
function visit2(n) {
|
|
6649
|
-
if (
|
|
6778
|
+
if (ts11.isArrowFunction(n) || ts11.isFunctionExpression(n) || ts11.isFunctionDeclaration(n) || ts11.isMethodDeclaration(n) || ts11.isGetAccessorDeclaration(n) || ts11.isSetAccessorDeclaration(n) || ts11.isConstructorDeclaration(n)) {
|
|
6650
6779
|
return;
|
|
6651
6780
|
}
|
|
6652
|
-
if (
|
|
6781
|
+
if (ts11.isBinaryExpression(n)) {
|
|
6653
6782
|
const op = n.operatorToken.kind;
|
|
6654
|
-
if (op ===
|
|
6783
|
+
if (op === ts11.SyntaxKind.EqualsToken || op === ts11.SyntaxKind.PlusEqualsToken || op === ts11.SyntaxKind.MinusEqualsToken || op === ts11.SyntaxKind.AsteriskEqualsToken || op === ts11.SyntaxKind.SlashEqualsToken || op === ts11.SyntaxKind.PercentEqualsToken || op === ts11.SyntaxKind.AsteriskAsteriskEqualsToken || op === ts11.SyntaxKind.AmpersandEqualsToken || op === ts11.SyntaxKind.BarEqualsToken || op === ts11.SyntaxKind.CaretEqualsToken || op === ts11.SyntaxKind.LessThanLessThanEqualsToken || op === ts11.SyntaxKind.GreaterThanGreaterThanEqualsToken || op === ts11.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken || op === ts11.SyntaxKind.AmpersandAmpersandEqualsToken || op === ts11.SyntaxKind.BarBarEqualsToken || op === ts11.SyntaxKind.QuestionQuestionEqualsToken) {
|
|
6655
6784
|
addFromTarget(n.left);
|
|
6656
6785
|
}
|
|
6657
6786
|
}
|
|
6658
|
-
if (
|
|
6659
|
-
if (n.operator ===
|
|
6787
|
+
if (ts11.isPrefixUnaryExpression(n) || ts11.isPostfixUnaryExpression(n)) {
|
|
6788
|
+
if (n.operator === ts11.SyntaxKind.PlusPlusToken || n.operator === ts11.SyntaxKind.MinusMinusToken) {
|
|
6660
6789
|
addFromTarget(n.operand);
|
|
6661
6790
|
}
|
|
6662
6791
|
}
|
|
6663
|
-
|
|
6792
|
+
ts11.forEachChild(n, visit2);
|
|
6664
6793
|
}
|
|
6665
6794
|
visit2(node);
|
|
6666
6795
|
const localDecls = collectLocalDeclarations(node);
|
|
@@ -6671,30 +6800,30 @@ function extractAssignedIdentifiersFromNode(node) {
|
|
|
6671
6800
|
function collectLocalDeclarations(root) {
|
|
6672
6801
|
const names = new Set;
|
|
6673
6802
|
function addBindingName(name) {
|
|
6674
|
-
if (
|
|
6803
|
+
if (ts11.isIdentifier(name)) {
|
|
6675
6804
|
names.add(name.text);
|
|
6676
6805
|
return;
|
|
6677
6806
|
}
|
|
6678
|
-
if (
|
|
6807
|
+
if (ts11.isArrayBindingPattern(name)) {
|
|
6679
6808
|
for (const el of name.elements) {
|
|
6680
|
-
if (
|
|
6809
|
+
if (ts11.isBindingElement(el))
|
|
6681
6810
|
addBindingName(el.name);
|
|
6682
6811
|
}
|
|
6683
6812
|
return;
|
|
6684
6813
|
}
|
|
6685
|
-
if (
|
|
6814
|
+
if (ts11.isObjectBindingPattern(name)) {
|
|
6686
6815
|
for (const el of name.elements) {
|
|
6687
6816
|
addBindingName(el.name);
|
|
6688
6817
|
}
|
|
6689
6818
|
}
|
|
6690
6819
|
}
|
|
6691
6820
|
function visit2(n) {
|
|
6692
|
-
if (
|
|
6821
|
+
if (ts11.isArrowFunction(n) || ts11.isFunctionExpression(n) || ts11.isFunctionDeclaration(n))
|
|
6693
6822
|
return;
|
|
6694
|
-
if (
|
|
6823
|
+
if (ts11.isVariableDeclaration(n)) {
|
|
6695
6824
|
addBindingName(n.name);
|
|
6696
6825
|
}
|
|
6697
|
-
|
|
6826
|
+
ts11.forEachChild(n, visit2);
|
|
6698
6827
|
}
|
|
6699
6828
|
visit2(root);
|
|
6700
6829
|
return names;
|
|
@@ -6729,35 +6858,35 @@ var CLIENT_EXPORTS = new Set([
|
|
|
6729
6858
|
"Region"
|
|
6730
6859
|
]);
|
|
6731
6860
|
function collectAmbientGlobals(node, ctx) {
|
|
6732
|
-
if (
|
|
6733
|
-
const isDeclare = node.modifiers?.some((m) => m.kind ===
|
|
6861
|
+
if (ts11.isVariableStatement(node)) {
|
|
6862
|
+
const isDeclare = node.modifiers?.some((m) => m.kind === ts11.SyntaxKind.DeclareKeyword) ?? false;
|
|
6734
6863
|
if (!isDeclare)
|
|
6735
6864
|
return;
|
|
6736
6865
|
for (const decl of node.declarationList.declarations) {
|
|
6737
|
-
if (
|
|
6866
|
+
if (ts11.isIdentifier(decl.name))
|
|
6738
6867
|
ctx.ambientGlobals.add(decl.name.text);
|
|
6739
6868
|
}
|
|
6740
6869
|
return;
|
|
6741
6870
|
}
|
|
6742
|
-
if (
|
|
6743
|
-
const isDeclare = node.modifiers?.some((m) => m.kind ===
|
|
6871
|
+
if (ts11.isFunctionDeclaration(node) && node.name) {
|
|
6872
|
+
const isDeclare = node.modifiers?.some((m) => m.kind === ts11.SyntaxKind.DeclareKeyword) ?? false;
|
|
6744
6873
|
if (isDeclare)
|
|
6745
6874
|
ctx.ambientGlobals.add(node.name.text);
|
|
6746
6875
|
return;
|
|
6747
6876
|
}
|
|
6748
|
-
if (
|
|
6749
|
-
const isGlobalAugmentation = (node.flags &
|
|
6877
|
+
if (ts11.isModuleDeclaration(node)) {
|
|
6878
|
+
const isGlobalAugmentation = (node.flags & ts11.NodeFlags.GlobalAugmentation) !== 0;
|
|
6750
6879
|
if (!isGlobalAugmentation)
|
|
6751
6880
|
return;
|
|
6752
|
-
if (!node.body || !
|
|
6881
|
+
if (!node.body || !ts11.isModuleBlock(node.body))
|
|
6753
6882
|
return;
|
|
6754
6883
|
for (const inner of node.body.statements) {
|
|
6755
|
-
if (
|
|
6884
|
+
if (ts11.isVariableStatement(inner)) {
|
|
6756
6885
|
for (const decl of inner.declarationList.declarations) {
|
|
6757
|
-
if (
|
|
6886
|
+
if (ts11.isIdentifier(decl.name))
|
|
6758
6887
|
ctx.ambientGlobals.add(decl.name.text);
|
|
6759
6888
|
}
|
|
6760
|
-
} else if (
|
|
6889
|
+
} else if (ts11.isFunctionDeclaration(inner) && inner.name) {
|
|
6761
6890
|
ctx.ambientGlobals.add(inner.name.text);
|
|
6762
6891
|
}
|
|
6763
6892
|
}
|
|
@@ -6768,7 +6897,7 @@ function collectImport(node, ctx) {
|
|
|
6768
6897
|
const specifiers = [];
|
|
6769
6898
|
const isTypeOnly = !!node.importClause?.isTypeOnly;
|
|
6770
6899
|
const loc = getSourceLocation(node, ctx.sourceFile, ctx.filePath);
|
|
6771
|
-
if (source === "@barefootjs/client" && !isTypeOnly && node.importClause?.namedBindings &&
|
|
6900
|
+
if (source === "@barefootjs/client" && !isTypeOnly && node.importClause?.namedBindings && ts11.isNamedImports(node.importClause.namedBindings)) {
|
|
6772
6901
|
const wrongImports = [];
|
|
6773
6902
|
for (const element of node.importClause.namedBindings.elements) {
|
|
6774
6903
|
const name = element.propertyName?.text ?? element.name.text;
|
|
@@ -6796,7 +6925,7 @@ function collectImport(node, ctx) {
|
|
|
6796
6925
|
});
|
|
6797
6926
|
}
|
|
6798
6927
|
if (node.importClause.namedBindings) {
|
|
6799
|
-
if (
|
|
6928
|
+
if (ts11.isNamedImports(node.importClause.namedBindings)) {
|
|
6800
6929
|
for (const element of node.importClause.namedBindings.elements) {
|
|
6801
6930
|
specifiers.push({
|
|
6802
6931
|
name: element.propertyName?.text ?? element.name.text,
|
|
@@ -6807,7 +6936,7 @@ function collectImport(node, ctx) {
|
|
|
6807
6936
|
});
|
|
6808
6937
|
}
|
|
6809
6938
|
}
|
|
6810
|
-
if (
|
|
6939
|
+
if (ts11.isNamespaceImport(node.importClause.namedBindings)) {
|
|
6811
6940
|
specifiers.push({
|
|
6812
6941
|
name: node.importClause.namedBindings.name.text,
|
|
6813
6942
|
alias: null,
|
|
@@ -6834,7 +6963,7 @@ function collectInterfaceDefinition(node, ctx) {
|
|
|
6834
6963
|
});
|
|
6835
6964
|
}
|
|
6836
6965
|
function collectTypeAliasDefinition(node, ctx) {
|
|
6837
|
-
const properties =
|
|
6966
|
+
const properties = ts11.isTypeLiteralNode(node.type) ? membersToProperties(node.type.members, ctx.sourceFile) : undefined;
|
|
6838
6967
|
ctx.typeDefinitions.push({
|
|
6839
6968
|
kind: "type",
|
|
6840
6969
|
name: node.name.text,
|
|
@@ -6847,20 +6976,20 @@ function extractSingleJsxReturn(body) {
|
|
|
6847
6976
|
let jsxReturn = null;
|
|
6848
6977
|
let returnCount = 0;
|
|
6849
6978
|
function visit2(node) {
|
|
6850
|
-
if (
|
|
6979
|
+
if (ts11.isFunctionDeclaration(node) || ts11.isFunctionExpression(node) || ts11.isArrowFunction(node))
|
|
6851
6980
|
return;
|
|
6852
|
-
if (
|
|
6981
|
+
if (ts11.isReturnStatement(node)) {
|
|
6853
6982
|
returnCount++;
|
|
6854
6983
|
if (node.expression) {
|
|
6855
6984
|
const expr = unwrapJsxTransparent(node.expression);
|
|
6856
|
-
if (
|
|
6985
|
+
if (ts11.isJsxElement(expr) || ts11.isJsxSelfClosingElement(expr) || ts11.isJsxFragment(expr)) {
|
|
6857
6986
|
jsxReturn = expr;
|
|
6858
6987
|
}
|
|
6859
6988
|
}
|
|
6860
6989
|
}
|
|
6861
|
-
|
|
6990
|
+
ts11.forEachChild(node, visit2);
|
|
6862
6991
|
}
|
|
6863
|
-
|
|
6992
|
+
ts11.forEachChild(body, visit2);
|
|
6864
6993
|
if (returnCount !== 1)
|
|
6865
6994
|
return null;
|
|
6866
6995
|
return jsxReturn;
|
|
@@ -6877,9 +7006,9 @@ function extractMultiReturnJsxBranches(body, allowPreamble = false) {
|
|
|
6877
7006
|
const stmts = body.statements;
|
|
6878
7007
|
for (let i = 0;i < stmts.length; i++) {
|
|
6879
7008
|
const stmt = stmts[i];
|
|
6880
|
-
if (
|
|
7009
|
+
if (ts11.isIfStatement(stmt)) {
|
|
6881
7010
|
let current = stmt;
|
|
6882
|
-
while (
|
|
7011
|
+
while (ts11.isIfStatement(current)) {
|
|
6883
7012
|
const ifStmt = current;
|
|
6884
7013
|
if (!isDirectReturnBlock(ifStmt.thenStatement))
|
|
6885
7014
|
return null;
|
|
@@ -6889,7 +7018,7 @@ function extractMultiReturnJsxBranches(body, allowPreamble = false) {
|
|
|
6889
7018
|
return null;
|
|
6890
7019
|
branches.push({ condition: ifStmt.expression, jsxReturn: jsxReturn ?? null });
|
|
6891
7020
|
if (ifStmt.elseStatement) {
|
|
6892
|
-
if (
|
|
7021
|
+
if (ts11.isIfStatement(ifStmt.elseStatement)) {
|
|
6893
7022
|
current = ifStmt.elseStatement;
|
|
6894
7023
|
continue;
|
|
6895
7024
|
}
|
|
@@ -6911,18 +7040,18 @@ function extractMultiReturnJsxBranches(body, allowPreamble = false) {
|
|
|
6911
7040
|
}
|
|
6912
7041
|
continue;
|
|
6913
7042
|
}
|
|
6914
|
-
if (
|
|
7043
|
+
if (ts11.isSwitchStatement(stmt)) {
|
|
6915
7044
|
if (branches.length > 0)
|
|
6916
7045
|
return null;
|
|
6917
|
-
if (!
|
|
7046
|
+
if (!ts11.isIdentifier(stmt.expression) && !ts11.isPropertyAccessExpression(stmt.expression)) {
|
|
6918
7047
|
return null;
|
|
6919
7048
|
}
|
|
6920
|
-
const hasDefault = stmt.caseBlock.clauses.some((c) =>
|
|
7049
|
+
const hasDefault = stmt.caseBlock.clauses.some((c) => ts11.isDefaultClause(c));
|
|
6921
7050
|
if (!hasDefault)
|
|
6922
7051
|
return null;
|
|
6923
7052
|
let pendingCases = [];
|
|
6924
7053
|
for (const clause of stmt.caseBlock.clauses) {
|
|
6925
|
-
if (
|
|
7054
|
+
if (ts11.isCaseClause(clause) && clause.statements.length === 0) {
|
|
6926
7055
|
pendingCases.push(clause.expression);
|
|
6927
7056
|
continue;
|
|
6928
7057
|
}
|
|
@@ -6932,7 +7061,7 @@ function extractMultiReturnJsxBranches(body, allowPreamble = false) {
|
|
|
6932
7061
|
return null;
|
|
6933
7062
|
if (!caseClauseIsDirectReturn(clause))
|
|
6934
7063
|
return null;
|
|
6935
|
-
if (
|
|
7064
|
+
if (ts11.isCaseClause(clause)) {
|
|
6936
7065
|
branches.push({
|
|
6937
7066
|
condition: clause.expression,
|
|
6938
7067
|
jsxReturn: jsxReturn ?? null,
|
|
@@ -6953,18 +7082,18 @@ function extractMultiReturnJsxBranches(body, allowPreamble = false) {
|
|
|
6953
7082
|
return null;
|
|
6954
7083
|
return { branches, fallback, switchDiscriminant: stmt.expression, preamble };
|
|
6955
7084
|
}
|
|
6956
|
-
if (
|
|
7085
|
+
if (ts11.isReturnStatement(stmt) && stmt.expression) {
|
|
6957
7086
|
const expr = unwrapJsxTransparent(stmt.expression);
|
|
6958
|
-
if (
|
|
7087
|
+
if (ts11.isJsxElement(expr) || ts11.isJsxSelfClosingElement(expr) || ts11.isJsxFragment(expr)) {
|
|
6959
7088
|
fallback = expr;
|
|
6960
|
-
} else if (expr.kind ===
|
|
7089
|
+
} else if (expr.kind === ts11.SyntaxKind.NullKeyword) {} else {
|
|
6961
7090
|
return null;
|
|
6962
7091
|
}
|
|
6963
7092
|
continue;
|
|
6964
7093
|
}
|
|
6965
|
-
if (
|
|
7094
|
+
if (ts11.isVariableStatement(stmt)) {
|
|
6966
7095
|
const declFlags = stmt.declarationList.flags;
|
|
6967
|
-
const isConstOrLet = (declFlags &
|
|
7096
|
+
const isConstOrLet = (declFlags & ts11.NodeFlags.Const) !== 0 || (declFlags & ts11.NodeFlags.Let) !== 0;
|
|
6968
7097
|
if (allowPreamble && isConstOrLet && branches.length === 0 && fallback === null) {
|
|
6969
7098
|
preamble.push(stmt);
|
|
6970
7099
|
continue;
|
|
@@ -6980,12 +7109,12 @@ function extractMultiReturnJsxBranches(body, allowPreamble = false) {
|
|
|
6980
7109
|
return { branches, fallback, preamble };
|
|
6981
7110
|
}
|
|
6982
7111
|
function isDirectReturnBlock(node) {
|
|
6983
|
-
if (
|
|
7112
|
+
if (ts11.isReturnStatement(node))
|
|
6984
7113
|
return true;
|
|
6985
|
-
if (
|
|
7114
|
+
if (ts11.isBlock(node)) {
|
|
6986
7115
|
let returnCount = 0;
|
|
6987
7116
|
for (const stmt of node.statements) {
|
|
6988
|
-
if (
|
|
7117
|
+
if (ts11.isReturnStatement(stmt)) {
|
|
6989
7118
|
returnCount++;
|
|
6990
7119
|
continue;
|
|
6991
7120
|
}
|
|
@@ -6996,25 +7125,25 @@ function isDirectReturnBlock(node) {
|
|
|
6996
7125
|
return false;
|
|
6997
7126
|
}
|
|
6998
7127
|
function findNullReturnInBlock(node) {
|
|
6999
|
-
if (
|
|
7128
|
+
if (ts11.isBlock(node)) {
|
|
7000
7129
|
for (const stmt of node.statements) {
|
|
7001
|
-
if (
|
|
7130
|
+
if (ts11.isReturnStatement(stmt) && stmt.expression) {
|
|
7002
7131
|
const expr = unwrapJsxTransparent(stmt.expression);
|
|
7003
|
-
if (expr.kind ===
|
|
7132
|
+
if (expr.kind === ts11.SyntaxKind.NullKeyword)
|
|
7004
7133
|
return true;
|
|
7005
7134
|
}
|
|
7006
7135
|
}
|
|
7007
7136
|
}
|
|
7008
|
-
if (
|
|
7137
|
+
if (ts11.isReturnStatement(node) && node.expression) {
|
|
7009
7138
|
const expr = unwrapJsxTransparent(node.expression);
|
|
7010
|
-
if (expr.kind ===
|
|
7139
|
+
if (expr.kind === ts11.SyntaxKind.NullKeyword)
|
|
7011
7140
|
return true;
|
|
7012
7141
|
}
|
|
7013
7142
|
return false;
|
|
7014
7143
|
}
|
|
7015
7144
|
function findJsxReturnInCaseClause(clause) {
|
|
7016
7145
|
for (const stmt of clause.statements) {
|
|
7017
|
-
if (
|
|
7146
|
+
if (ts11.isReturnStatement(stmt) && stmt.expression) {
|
|
7018
7147
|
return extractJsxFromExpression(stmt.expression);
|
|
7019
7148
|
}
|
|
7020
7149
|
}
|
|
@@ -7024,12 +7153,12 @@ function caseClauseIsDirectReturn(clause) {
|
|
|
7024
7153
|
let returnCount = 0;
|
|
7025
7154
|
let seenReturn = false;
|
|
7026
7155
|
for (const stmt of clause.statements) {
|
|
7027
|
-
if (
|
|
7156
|
+
if (ts11.isReturnStatement(stmt)) {
|
|
7028
7157
|
returnCount++;
|
|
7029
7158
|
seenReturn = true;
|
|
7030
7159
|
continue;
|
|
7031
7160
|
}
|
|
7032
|
-
if (
|
|
7161
|
+
if (ts11.isBreakStatement(stmt)) {
|
|
7033
7162
|
if (!seenReturn)
|
|
7034
7163
|
return false;
|
|
7035
7164
|
continue;
|
|
@@ -7040,9 +7169,9 @@ function caseClauseIsDirectReturn(clause) {
|
|
|
7040
7169
|
}
|
|
7041
7170
|
function findNullReturnInCaseClause(clause) {
|
|
7042
7171
|
for (const stmt of clause.statements) {
|
|
7043
|
-
if (
|
|
7172
|
+
if (ts11.isReturnStatement(stmt) && stmt.expression) {
|
|
7044
7173
|
const expr = unwrapJsxTransparent(stmt.expression);
|
|
7045
|
-
if (expr.kind ===
|
|
7174
|
+
if (expr.kind === ts11.SyntaxKind.NullKeyword)
|
|
7046
7175
|
return true;
|
|
7047
7176
|
}
|
|
7048
7177
|
}
|
|
@@ -7053,26 +7182,26 @@ function isMultiReturnJsxFunctionBody(body) {
|
|
|
7053
7182
|
let hasJsxReturn = false;
|
|
7054
7183
|
let allReturnsAreJsxOrNull = true;
|
|
7055
7184
|
function visit2(node) {
|
|
7056
|
-
if (
|
|
7185
|
+
if (ts11.isFunctionDeclaration(node) || ts11.isFunctionExpression(node) || ts11.isArrowFunction(node))
|
|
7057
7186
|
return;
|
|
7058
|
-
if (
|
|
7187
|
+
if (ts11.isReturnStatement(node)) {
|
|
7059
7188
|
returnCount++;
|
|
7060
7189
|
if (!node.expression) {
|
|
7061
7190
|
allReturnsAreJsxOrNull = false;
|
|
7062
7191
|
return;
|
|
7063
7192
|
}
|
|
7064
7193
|
const expr = unwrapJsxTransparent(node.expression);
|
|
7065
|
-
const isJsx =
|
|
7066
|
-
const isNull = expr.kind ===
|
|
7194
|
+
const isJsx = ts11.isJsxElement(expr) || ts11.isJsxSelfClosingElement(expr) || ts11.isJsxFragment(expr);
|
|
7195
|
+
const isNull = expr.kind === ts11.SyntaxKind.NullKeyword;
|
|
7067
7196
|
if (isJsx)
|
|
7068
7197
|
hasJsxReturn = true;
|
|
7069
7198
|
if (!isJsx && !isNull)
|
|
7070
7199
|
allReturnsAreJsxOrNull = false;
|
|
7071
7200
|
return;
|
|
7072
7201
|
}
|
|
7073
|
-
|
|
7202
|
+
ts11.forEachChild(node, visit2);
|
|
7074
7203
|
}
|
|
7075
|
-
|
|
7204
|
+
ts11.forEachChild(body, visit2);
|
|
7076
7205
|
return returnCount > 1 && hasJsxReturn && allReturnsAreJsxOrNull;
|
|
7077
7206
|
}
|
|
7078
7207
|
function collectFunction(node, ctx, _isModule, isExported = false) {
|
|
@@ -7142,7 +7271,7 @@ function collectFunction(node, ctx, _isModule, isExported = false) {
|
|
|
7142
7271
|
}
|
|
7143
7272
|
}
|
|
7144
7273
|
}
|
|
7145
|
-
const isAsync = node.modifiers?.some((m) => m.kind ===
|
|
7274
|
+
const isAsync = node.modifiers?.some((m) => m.kind === ts11.SyntaxKind.AsyncKeyword) ?? false;
|
|
7146
7275
|
const isGenerator = !!node.asteriskToken;
|
|
7147
7276
|
ctx.localFunctions.push({
|
|
7148
7277
|
name,
|
|
@@ -7163,10 +7292,10 @@ function collectFunction(node, ctx, _isModule, isExported = false) {
|
|
|
7163
7292
|
});
|
|
7164
7293
|
}
|
|
7165
7294
|
function extractValueBranches(node, ctx) {
|
|
7166
|
-
if (
|
|
7295
|
+
if (ts11.isParenthesizedExpression(node)) {
|
|
7167
7296
|
return extractValueBranches(node.expression, ctx);
|
|
7168
7297
|
}
|
|
7169
|
-
if (
|
|
7298
|
+
if (ts11.isConditionalExpression(node)) {
|
|
7170
7299
|
return [
|
|
7171
7300
|
...extractValueBranches(node.whenTrue, ctx),
|
|
7172
7301
|
...extractValueBranches(node.whenFalse, ctx)
|
|
@@ -7178,46 +7307,46 @@ function extractFreeIdentifiersFromNode(node) {
|
|
|
7178
7307
|
const ids = new Set;
|
|
7179
7308
|
const boundNames = new Set;
|
|
7180
7309
|
function addBindingNames(name, out) {
|
|
7181
|
-
if (
|
|
7310
|
+
if (ts11.isIdentifier(name))
|
|
7182
7311
|
out.push(name.text);
|
|
7183
|
-
else if (
|
|
7312
|
+
else if (ts11.isObjectBindingPattern(name))
|
|
7184
7313
|
name.elements.forEach((e) => addBindingNames(e.name, out));
|
|
7185
|
-
else if (
|
|
7314
|
+
else if (ts11.isArrayBindingPattern(name))
|
|
7186
7315
|
name.elements.forEach((e) => {
|
|
7187
|
-
if (!
|
|
7316
|
+
if (!ts11.isOmittedExpression(e))
|
|
7188
7317
|
addBindingNames(e.name, out);
|
|
7189
7318
|
});
|
|
7190
7319
|
}
|
|
7191
7320
|
function visit2(n) {
|
|
7192
|
-
if (
|
|
7321
|
+
if (ts11.isTypeNode(n))
|
|
7193
7322
|
return;
|
|
7194
|
-
if (
|
|
7323
|
+
if (ts11.isIdentifier(n)) {
|
|
7195
7324
|
const parent = n.parent;
|
|
7196
|
-
if (parent &&
|
|
7325
|
+
if (parent && ts11.isPropertyAccessExpression(parent) && parent.name === n)
|
|
7197
7326
|
return;
|
|
7198
|
-
if (parent &&
|
|
7327
|
+
if (parent && ts11.isPropertyAssignment(parent) && parent.name === n)
|
|
7199
7328
|
return;
|
|
7200
|
-
if (parent &&
|
|
7329
|
+
if (parent && ts11.isParameter(parent) && parent.name === n)
|
|
7201
7330
|
return;
|
|
7202
|
-
if (parent &&
|
|
7331
|
+
if (parent && ts11.isVariableDeclaration(parent) && parent.name === n)
|
|
7203
7332
|
return;
|
|
7204
7333
|
if (boundNames.has(n.text))
|
|
7205
7334
|
return;
|
|
7206
7335
|
ids.add(n.text);
|
|
7207
7336
|
return;
|
|
7208
7337
|
}
|
|
7209
|
-
if (
|
|
7338
|
+
if (ts11.isArrowFunction(n)) {
|
|
7210
7339
|
const params = [];
|
|
7211
7340
|
for (const p of n.parameters)
|
|
7212
7341
|
addBindingNames(p.name, params);
|
|
7213
7342
|
for (const name of params)
|
|
7214
7343
|
boundNames.add(name);
|
|
7215
|
-
|
|
7344
|
+
ts11.forEachChild(n, visit2);
|
|
7216
7345
|
for (const name of params)
|
|
7217
7346
|
boundNames.delete(name);
|
|
7218
7347
|
return;
|
|
7219
7348
|
}
|
|
7220
|
-
|
|
7349
|
+
ts11.forEachChild(n, visit2);
|
|
7221
7350
|
}
|
|
7222
7351
|
visit2(node);
|
|
7223
7352
|
return ids;
|
|
@@ -7226,29 +7355,29 @@ function extractFreeTypeIdentifiersFromNode(node) {
|
|
|
7226
7355
|
const ids = new Set;
|
|
7227
7356
|
const boundTypeParams = new Set;
|
|
7228
7357
|
function rootName(name) {
|
|
7229
|
-
return
|
|
7358
|
+
return ts11.isQualifiedName(name) ? rootName(name.left) : name;
|
|
7230
7359
|
}
|
|
7231
7360
|
function visit2(n) {
|
|
7232
|
-
if (
|
|
7361
|
+
if (ts11.isTypeReferenceNode(n)) {
|
|
7233
7362
|
const name = rootName(n.typeName).text;
|
|
7234
7363
|
if (!boundTypeParams.has(name))
|
|
7235
7364
|
ids.add(name);
|
|
7236
7365
|
}
|
|
7237
|
-
if (
|
|
7366
|
+
if (ts11.isTypeQueryNode(n)) {
|
|
7238
7367
|
const name = rootName(n.exprName).text;
|
|
7239
7368
|
if (!boundTypeParams.has(name))
|
|
7240
7369
|
ids.add(name);
|
|
7241
7370
|
}
|
|
7242
|
-
if (
|
|
7371
|
+
if (ts11.isFunctionLike(n) && n.typeParameters && n.typeParameters.length > 0) {
|
|
7243
7372
|
const names = n.typeParameters.map((p) => p.name.text);
|
|
7244
7373
|
for (const p of names)
|
|
7245
7374
|
boundTypeParams.add(p);
|
|
7246
|
-
|
|
7375
|
+
ts11.forEachChild(n, visit2);
|
|
7247
7376
|
for (const p of names)
|
|
7248
7377
|
boundTypeParams.delete(p);
|
|
7249
7378
|
return;
|
|
7250
7379
|
}
|
|
7251
|
-
|
|
7380
|
+
ts11.forEachChild(n, visit2);
|
|
7252
7381
|
}
|
|
7253
7382
|
visit2(node);
|
|
7254
7383
|
return ids;
|
|
@@ -7258,22 +7387,22 @@ function initializerShapeContainsJsx(node) {
|
|
|
7258
7387
|
function visit2(n) {
|
|
7259
7388
|
if (found)
|
|
7260
7389
|
return;
|
|
7261
|
-
if (
|
|
7390
|
+
if (ts11.isJsxElement(n) || ts11.isJsxSelfClosingElement(n) || ts11.isJsxFragment(n)) {
|
|
7262
7391
|
found = true;
|
|
7263
7392
|
return;
|
|
7264
7393
|
}
|
|
7265
|
-
if (
|
|
7394
|
+
if (ts11.isFunctionDeclaration(n) || ts11.isFunctionExpression(n) || ts11.isArrowFunction(n)) {
|
|
7266
7395
|
return;
|
|
7267
7396
|
}
|
|
7268
|
-
|
|
7397
|
+
ts11.forEachChild(n, visit2);
|
|
7269
7398
|
}
|
|
7270
7399
|
visit2(node);
|
|
7271
7400
|
return found;
|
|
7272
7401
|
}
|
|
7273
7402
|
function isMapLikeCallWithJsx(node) {
|
|
7274
|
-
if (!
|
|
7403
|
+
if (!ts11.isCallExpression(node))
|
|
7275
7404
|
return false;
|
|
7276
|
-
if (!
|
|
7405
|
+
if (!ts11.isPropertyAccessExpression(node.expression))
|
|
7277
7406
|
return false;
|
|
7278
7407
|
const method = node.expression.name.text;
|
|
7279
7408
|
if (method !== "map" && method !== "flatMap")
|
|
@@ -7281,12 +7410,12 @@ function isMapLikeCallWithJsx(node) {
|
|
|
7281
7410
|
const callback = node.arguments[0];
|
|
7282
7411
|
if (!callback)
|
|
7283
7412
|
return false;
|
|
7284
|
-
if (!
|
|
7413
|
+
if (!ts11.isArrowFunction(callback) && !ts11.isFunctionExpression(callback))
|
|
7285
7414
|
return false;
|
|
7286
7415
|
return containsJsxDeep(callback.body);
|
|
7287
7416
|
}
|
|
7288
7417
|
function containsJsxDeep(node) {
|
|
7289
|
-
if (
|
|
7418
|
+
if (ts11.isJsxElement(node) || ts11.isJsxSelfClosingElement(node) || ts11.isJsxFragment(node))
|
|
7290
7419
|
return true;
|
|
7291
7420
|
let found = false;
|
|
7292
7421
|
node.forEachChild((child) => {
|
|
@@ -7300,11 +7429,11 @@ function nodeContainsArrow(node) {
|
|
|
7300
7429
|
function visit2(n) {
|
|
7301
7430
|
if (found)
|
|
7302
7431
|
return;
|
|
7303
|
-
if (
|
|
7432
|
+
if (ts11.isArrowFunction(n) || ts11.isFunctionExpression(n)) {
|
|
7304
7433
|
found = true;
|
|
7305
7434
|
return;
|
|
7306
7435
|
}
|
|
7307
|
-
|
|
7436
|
+
ts11.forEachChild(n, visit2);
|
|
7308
7437
|
}
|
|
7309
7438
|
visit2(node);
|
|
7310
7439
|
return found;
|
|
@@ -7352,20 +7481,20 @@ function collectModuleScopeReactive(decl, ctx, isExported) {
|
|
|
7352
7481
|
}));
|
|
7353
7482
|
}
|
|
7354
7483
|
function getSystemConstructKind(node) {
|
|
7355
|
-
if (
|
|
7484
|
+
if (ts11.isCallExpression(node) && ts11.isIdentifier(node.expression) && node.expression.text === "createContext")
|
|
7356
7485
|
return "createContext";
|
|
7357
|
-
if (
|
|
7486
|
+
if (ts11.isNewExpression(node) && ts11.isIdentifier(node.expression) && node.expression.text === "WeakMap")
|
|
7358
7487
|
return "weakMap";
|
|
7359
7488
|
return;
|
|
7360
7489
|
}
|
|
7361
7490
|
function collectConstant(node, ctx, _isModule, declarationKind = "const", isExported = false) {
|
|
7362
|
-
if (!_isModule &&
|
|
7491
|
+
if (!_isModule && ts11.isObjectBindingPattern(node.name) && node.initializer && ts11.isIdentifier(node.initializer) && ctx.propsObjectName === node.initializer.text) {
|
|
7363
7492
|
const propsName = node.initializer.text;
|
|
7364
7493
|
for (const el of node.name.elements) {
|
|
7365
|
-
if (!
|
|
7494
|
+
if (!ts11.isBindingElement(el) || !ts11.isIdentifier(el.name) || el.dotDotDotToken)
|
|
7366
7495
|
continue;
|
|
7367
7496
|
const localName = el.name.text;
|
|
7368
|
-
const sourceKey = el.propertyName &&
|
|
7497
|
+
const sourceKey = el.propertyName && ts11.isIdentifier(el.propertyName) ? el.propertyName.text : localName;
|
|
7369
7498
|
const defaultValueExpr = el.initializer ? ctx.getJS(el.initializer) : undefined;
|
|
7370
7499
|
const baseValue = `${propsName}.${sourceKey}`;
|
|
7371
7500
|
const value2 = defaultValueExpr ? `${baseValue} ?? ${defaultValueExpr}` : baseValue;
|
|
@@ -7387,7 +7516,7 @@ function collectConstant(node, ctx, _isModule, declarationKind = "const", isExpo
|
|
|
7387
7516
|
}
|
|
7388
7517
|
return;
|
|
7389
7518
|
}
|
|
7390
|
-
if (!
|
|
7519
|
+
if (!ts11.isIdentifier(node.name))
|
|
7391
7520
|
return;
|
|
7392
7521
|
if (isSignalDeclaration(node, ctx) || isMemoDeclaration(node, ctx))
|
|
7393
7522
|
return;
|
|
@@ -7405,9 +7534,9 @@ function collectConstant(node, ctx, _isModule, declarationKind = "const", isExpo
|
|
|
7405
7534
|
let isJsxFunction = false;
|
|
7406
7535
|
if (node.initializer) {
|
|
7407
7536
|
let init = node.initializer;
|
|
7408
|
-
while (
|
|
7537
|
+
while (ts11.isParenthesizedExpression(init))
|
|
7409
7538
|
init = init.expression;
|
|
7410
|
-
if (
|
|
7539
|
+
if (ts11.isJsxElement(init) || ts11.isJsxSelfClosingElement(init) || ts11.isJsxFragment(init)) {
|
|
7411
7540
|
isJsx = true;
|
|
7412
7541
|
ctx.jsxConstants.set(name, init);
|
|
7413
7542
|
} else if (initializerShapeContainsJsx(init)) {
|
|
@@ -7415,9 +7544,9 @@ function collectConstant(node, ctx, _isModule, declarationKind = "const", isExpo
|
|
|
7415
7544
|
} else if (isMapLikeCallWithJsx(init)) {
|
|
7416
7545
|
ctx.inlineableJsxConsts.set(name, init);
|
|
7417
7546
|
}
|
|
7418
|
-
if (
|
|
7547
|
+
if (ts11.isArrowFunction(init)) {
|
|
7419
7548
|
const arrowBody = init.body;
|
|
7420
|
-
if (
|
|
7549
|
+
if (ts11.isBlock(arrowBody)) {
|
|
7421
7550
|
const jsxReturn = extractSingleJsxReturn(arrowBody);
|
|
7422
7551
|
if (jsxReturn) {
|
|
7423
7552
|
isJsxFunction = true;
|
|
@@ -7437,9 +7566,9 @@ function collectConstant(node, ctx, _isModule, declarationKind = "const", isExpo
|
|
|
7437
7566
|
}
|
|
7438
7567
|
} else {
|
|
7439
7568
|
let body = arrowBody;
|
|
7440
|
-
while (
|
|
7569
|
+
while (ts11.isParenthesizedExpression(body))
|
|
7441
7570
|
body = body.expression;
|
|
7442
|
-
if (
|
|
7571
|
+
if (ts11.isJsxElement(body) || ts11.isJsxSelfClosingElement(body) || ts11.isJsxFragment(body)) {
|
|
7443
7572
|
isJsxFunction = true;
|
|
7444
7573
|
ctx.jsxFunctions.set(name, {
|
|
7445
7574
|
jsxReturn: body,
|
|
@@ -7452,9 +7581,9 @@ function collectConstant(node, ctx, _isModule, declarationKind = "const", isExpo
|
|
|
7452
7581
|
let valueBranches;
|
|
7453
7582
|
if (node.initializer) {
|
|
7454
7583
|
let inner = node.initializer;
|
|
7455
|
-
while (
|
|
7584
|
+
while (ts11.isParenthesizedExpression(inner))
|
|
7456
7585
|
inner = inner.expression;
|
|
7457
|
-
if (
|
|
7586
|
+
if (ts11.isConditionalExpression(inner)) {
|
|
7458
7587
|
valueBranches = extractValueBranches(node.initializer, ctx);
|
|
7459
7588
|
}
|
|
7460
7589
|
}
|
|
@@ -7532,7 +7661,7 @@ function collectConstant(node, ctx, _isModule, declarationKind = "const", isExpo
|
|
|
7532
7661
|
function hasIgnoreDirective(node, sourceFile, ruleId) {
|
|
7533
7662
|
const checkComments = (targetNode) => {
|
|
7534
7663
|
const fullStart = targetNode.getFullStart();
|
|
7535
|
-
const leadingComments =
|
|
7664
|
+
const leadingComments = ts11.getLeadingCommentRanges(sourceFile.getFullText(), fullStart);
|
|
7536
7665
|
if (!leadingComments)
|
|
7537
7666
|
return false;
|
|
7538
7667
|
for (const range of leadingComments) {
|
|
@@ -7545,10 +7674,10 @@ function hasIgnoreDirective(node, sourceFile, ruleId) {
|
|
|
7545
7674
|
};
|
|
7546
7675
|
if (checkComments(node))
|
|
7547
7676
|
return true;
|
|
7548
|
-
if (
|
|
7677
|
+
if (ts11.isArrowFunction(node)) {
|
|
7549
7678
|
let current = node.parent;
|
|
7550
7679
|
while (current) {
|
|
7551
|
-
if (
|
|
7680
|
+
if (ts11.isVariableStatement(current)) {
|
|
7552
7681
|
if (checkComments(current))
|
|
7553
7682
|
return true;
|
|
7554
7683
|
break;
|
|
@@ -7559,7 +7688,7 @@ function hasIgnoreDirective(node, sourceFile, ruleId) {
|
|
|
7559
7688
|
return false;
|
|
7560
7689
|
}
|
|
7561
7690
|
function extractProps(param, ctx) {
|
|
7562
|
-
if (
|
|
7691
|
+
if (ts11.isObjectBindingPattern(param.name)) {
|
|
7563
7692
|
const componentNode = ctx.componentNode;
|
|
7564
7693
|
const ignored = !!(componentNode && hasIgnoreDirective(componentNode, ctx.sourceFile, "props-destructuring"));
|
|
7565
7694
|
ctx.propsDestructuring = {
|
|
@@ -7568,14 +7697,14 @@ function extractProps(param, ctx) {
|
|
|
7568
7697
|
};
|
|
7569
7698
|
const memberTypes = param.type ? collectMemberTypes(param.type, ctx) : null;
|
|
7570
7699
|
for (const element of param.name.elements) {
|
|
7571
|
-
if (
|
|
7700
|
+
if (ts11.isBindingElement(element) && ts11.isIdentifier(element.name)) {
|
|
7572
7701
|
const localName = element.name.text;
|
|
7573
7702
|
const defaultValue = element.initializer ? ctx.getJS(element.initializer) : undefined;
|
|
7574
7703
|
if (element.dotDotDotToken) {
|
|
7575
7704
|
ctx.restPropsName = localName;
|
|
7576
7705
|
continue;
|
|
7577
7706
|
}
|
|
7578
|
-
const sourcePropName = element.propertyName &&
|
|
7707
|
+
const sourcePropName = element.propertyName && ts11.isIdentifier(element.propertyName) ? element.propertyName.text : localName;
|
|
7579
7708
|
const member = memberTypes?.get(sourcePropName);
|
|
7580
7709
|
const resolvedType = member?.type ?? { kind: "unknown", raw: "unknown" };
|
|
7581
7710
|
const defaultContainsArrow = element.initializer ? nodeContainsArrow(element.initializer) : false;
|
|
@@ -7599,7 +7728,7 @@ function extractProps(param, ctx) {
|
|
|
7599
7728
|
}
|
|
7600
7729
|
}
|
|
7601
7730
|
}
|
|
7602
|
-
if (
|
|
7731
|
+
if (ts11.isIdentifier(param.name)) {
|
|
7603
7732
|
ctx.propsObjectName = param.name.text;
|
|
7604
7733
|
if (param.type) {
|
|
7605
7734
|
extractPropsFromType(param.type, ctx);
|
|
@@ -7610,24 +7739,24 @@ function extractProps(param, ctx) {
|
|
|
7610
7739
|
}
|
|
7611
7740
|
}
|
|
7612
7741
|
function collectTypeKeys(typeNode, ctx) {
|
|
7613
|
-
if (
|
|
7742
|
+
if (ts11.isTypeLiteralNode(typeNode)) {
|
|
7614
7743
|
return collectKeysFromMembers(typeNode.members, ctx);
|
|
7615
7744
|
}
|
|
7616
|
-
if (
|
|
7745
|
+
if (ts11.isTypeReferenceNode(typeNode)) {
|
|
7617
7746
|
const typeName = typeNode.typeName.getText(ctx.sourceFile);
|
|
7618
7747
|
const typeDecl = findTypeDeclaration(typeName, ctx.sourceFile);
|
|
7619
7748
|
if (!typeDecl)
|
|
7620
7749
|
return null;
|
|
7621
|
-
if (
|
|
7750
|
+
if (ts11.isInterfaceDeclaration(typeDecl)) {
|
|
7622
7751
|
if (typeDecl.heritageClauses && typeDecl.heritageClauses.length > 0)
|
|
7623
7752
|
return null;
|
|
7624
7753
|
return collectKeysFromMembers(typeDecl.members, ctx);
|
|
7625
7754
|
}
|
|
7626
|
-
if (
|
|
7627
|
-
if (
|
|
7755
|
+
if (ts11.isTypeAliasDeclaration(typeDecl)) {
|
|
7756
|
+
if (ts11.isTypeLiteralNode(typeDecl.type)) {
|
|
7628
7757
|
return collectKeysFromMembers(typeDecl.type.members, ctx);
|
|
7629
7758
|
}
|
|
7630
|
-
if (
|
|
7759
|
+
if (ts11.isIntersectionTypeNode(typeDecl.type)) {
|
|
7631
7760
|
return null;
|
|
7632
7761
|
}
|
|
7633
7762
|
}
|
|
@@ -7637,9 +7766,9 @@ function collectTypeKeys(typeNode, ctx) {
|
|
|
7637
7766
|
function collectKeysFromMembers(members, ctx) {
|
|
7638
7767
|
const keys = [];
|
|
7639
7768
|
for (const member of members) {
|
|
7640
|
-
if (
|
|
7769
|
+
if (ts11.isIndexSignatureDeclaration(member))
|
|
7641
7770
|
return null;
|
|
7642
|
-
if (
|
|
7771
|
+
if (ts11.isPropertySignature(member) && member.name) {
|
|
7643
7772
|
keys.push(member.name.getText(ctx.sourceFile));
|
|
7644
7773
|
}
|
|
7645
7774
|
}
|
|
@@ -7663,7 +7792,7 @@ function collectMemberTypes(typeNode, ctx) {
|
|
|
7663
7792
|
const fromMembers = (members) => {
|
|
7664
7793
|
const map = new Map;
|
|
7665
7794
|
for (const member of members) {
|
|
7666
|
-
if (
|
|
7795
|
+
if (ts11.isPropertySignature(member) && member.name) {
|
|
7667
7796
|
const info = member.type ? typeNodeToTypeInfo(member.type, ctx.sourceFile) : null;
|
|
7668
7797
|
map.set(member.name.getText(ctx.sourceFile), {
|
|
7669
7798
|
type: info && isResolvableMemberType(info) ? info : null,
|
|
@@ -7673,35 +7802,35 @@ function collectMemberTypes(typeNode, ctx) {
|
|
|
7673
7802
|
}
|
|
7674
7803
|
return map;
|
|
7675
7804
|
};
|
|
7676
|
-
if (
|
|
7805
|
+
if (ts11.isTypeLiteralNode(typeNode)) {
|
|
7677
7806
|
return fromMembers(typeNode.members);
|
|
7678
7807
|
}
|
|
7679
|
-
if (
|
|
7808
|
+
if (ts11.isTypeReferenceNode(typeNode)) {
|
|
7680
7809
|
const typeName = typeNode.typeName.getText(ctx.sourceFile);
|
|
7681
7810
|
const typeDecl = findTypeDeclaration(typeName, ctx.sourceFile);
|
|
7682
7811
|
if (!typeDecl)
|
|
7683
7812
|
return null;
|
|
7684
|
-
if (
|
|
7813
|
+
if (ts11.isInterfaceDeclaration(typeDecl)) {
|
|
7685
7814
|
return fromMembers(typeDecl.members);
|
|
7686
7815
|
}
|
|
7687
|
-
if (
|
|
7816
|
+
if (ts11.isTypeAliasDeclaration(typeDecl) && ts11.isTypeLiteralNode(typeDecl.type)) {
|
|
7688
7817
|
return fromMembers(typeDecl.type.members);
|
|
7689
7818
|
}
|
|
7690
7819
|
}
|
|
7691
7820
|
return null;
|
|
7692
7821
|
}
|
|
7693
7822
|
function extractPropsFromType(typeNode, ctx) {
|
|
7694
|
-
if (
|
|
7823
|
+
if (ts11.isTypeLiteralNode(typeNode)) {
|
|
7695
7824
|
extractPropsFromTypeMembers(typeNode.members, ctx);
|
|
7696
7825
|
return;
|
|
7697
7826
|
}
|
|
7698
|
-
if (
|
|
7827
|
+
if (ts11.isTypeReferenceNode(typeNode)) {
|
|
7699
7828
|
const typeName = typeNode.typeName.getText(ctx.sourceFile);
|
|
7700
7829
|
const typeDecl = findTypeDeclaration(typeName, ctx.sourceFile);
|
|
7701
7830
|
if (typeDecl) {
|
|
7702
|
-
if (
|
|
7831
|
+
if (ts11.isInterfaceDeclaration(typeDecl)) {
|
|
7703
7832
|
extractPropsFromTypeMembers(typeDecl.members, ctx);
|
|
7704
|
-
} else if (
|
|
7833
|
+
} else if (ts11.isTypeAliasDeclaration(typeDecl) && ts11.isTypeLiteralNode(typeDecl.type)) {
|
|
7705
7834
|
extractPropsFromTypeMembers(typeDecl.type.members, ctx);
|
|
7706
7835
|
}
|
|
7707
7836
|
}
|
|
@@ -7709,7 +7838,7 @@ function extractPropsFromType(typeNode, ctx) {
|
|
|
7709
7838
|
}
|
|
7710
7839
|
function extractPropsFromTypeMembers(members, ctx) {
|
|
7711
7840
|
for (const member of members) {
|
|
7712
|
-
if (
|
|
7841
|
+
if (ts11.isPropertySignature(member) && member.name) {
|
|
7713
7842
|
const propName = member.name.getText(ctx.sourceFile);
|
|
7714
7843
|
const isOptional = !!member.questionToken;
|
|
7715
7844
|
const propType = member.type ? typeNodeToTypeInfo(member.type, ctx.sourceFile) : { kind: "unknown", raw: "unknown" };
|
|
@@ -7725,17 +7854,17 @@ function extractPropsFromTypeMembers(members, ctx) {
|
|
|
7725
7854
|
function findTypeDeclaration(typeName, sourceFile) {
|
|
7726
7855
|
let result;
|
|
7727
7856
|
function visit2(node) {
|
|
7728
|
-
if (
|
|
7857
|
+
if (ts11.isInterfaceDeclaration(node) && node.name.text === typeName) {
|
|
7729
7858
|
result = node;
|
|
7730
7859
|
return;
|
|
7731
7860
|
}
|
|
7732
|
-
if (
|
|
7861
|
+
if (ts11.isTypeAliasDeclaration(node) && node.name.text === typeName) {
|
|
7733
7862
|
result = node;
|
|
7734
7863
|
return;
|
|
7735
7864
|
}
|
|
7736
|
-
|
|
7865
|
+
ts11.forEachChild(node, visit2);
|
|
7737
7866
|
}
|
|
7738
|
-
|
|
7867
|
+
ts11.forEachChild(sourceFile, visit2);
|
|
7739
7868
|
return result;
|
|
7740
7869
|
}
|
|
7741
7870
|
function inferTypeFromValue(value) {
|
|
@@ -7781,12 +7910,12 @@ function inferTypeFromValue(value) {
|
|
|
7781
7910
|
}
|
|
7782
7911
|
function collectCalledIdentifiers(code) {
|
|
7783
7912
|
const called = new Set;
|
|
7784
|
-
const sf =
|
|
7913
|
+
const sf = ts11.createSourceFile("__deps__.tsx", code, ts11.ScriptTarget.Latest, false, ts11.ScriptKind.TSX);
|
|
7785
7914
|
const visit2 = (node) => {
|
|
7786
|
-
if (
|
|
7915
|
+
if (ts11.isCallExpression(node) && ts11.isIdentifier(node.expression)) {
|
|
7787
7916
|
called.add(node.expression.text);
|
|
7788
7917
|
}
|
|
7789
|
-
|
|
7918
|
+
ts11.forEachChild(node, visit2);
|
|
7790
7919
|
};
|
|
7791
7920
|
visit2(sf);
|
|
7792
7921
|
return called;
|
|
@@ -7884,16 +8013,16 @@ function isResolvableComponentSource(source) {
|
|
|
7884
8013
|
function collectJsxComponentTags(sourceFile) {
|
|
7885
8014
|
const tags = new Set;
|
|
7886
8015
|
function visit2(node) {
|
|
7887
|
-
if (
|
|
8016
|
+
if (ts11.isJsxOpeningElement(node) || ts11.isJsxSelfClosingElement(node)) {
|
|
7888
8017
|
const tagName = node.tagName;
|
|
7889
|
-
if (
|
|
8018
|
+
if (ts11.isIdentifier(tagName)) {
|
|
7890
8019
|
const first = tagName.text.charAt(0);
|
|
7891
8020
|
if (first >= "A" && first <= "Z") {
|
|
7892
8021
|
tags.add(tagName.text);
|
|
7893
8022
|
}
|
|
7894
8023
|
}
|
|
7895
8024
|
}
|
|
7896
|
-
|
|
8025
|
+
ts11.forEachChild(node, visit2);
|
|
7897
8026
|
}
|
|
7898
8027
|
visit2(sourceFile);
|
|
7899
8028
|
return tags;
|
|
@@ -7972,18 +8101,18 @@ function fileHasUseClientDirective(filePath) {
|
|
|
7972
8101
|
} catch {
|
|
7973
8102
|
return true;
|
|
7974
8103
|
}
|
|
7975
|
-
const sf =
|
|
8104
|
+
const sf = ts11.createSourceFile(filePath, content, ts11.ScriptTarget.Latest, false, ts11.ScriptKind.TSX);
|
|
7976
8105
|
let found = false;
|
|
7977
8106
|
function visit2(node) {
|
|
7978
8107
|
if (found)
|
|
7979
8108
|
return;
|
|
7980
|
-
if (
|
|
8109
|
+
if (ts11.isExpressionStatement(node) && ts11.isStringLiteral(node.expression)) {
|
|
7981
8110
|
if (node.expression.text === "use client") {
|
|
7982
8111
|
found = true;
|
|
7983
8112
|
return;
|
|
7984
8113
|
}
|
|
7985
8114
|
}
|
|
7986
|
-
|
|
8115
|
+
ts11.forEachChild(node, visit2);
|
|
7987
8116
|
}
|
|
7988
8117
|
visit2(sf);
|
|
7989
8118
|
return found;
|
|
@@ -8061,11 +8190,11 @@ function importsBrowserOnlyClientApi(ctx) {
|
|
|
8061
8190
|
return false;
|
|
8062
8191
|
}
|
|
8063
8192
|
function listComponentFunctions(source, filePath) {
|
|
8064
|
-
const sourceFile =
|
|
8193
|
+
const sourceFile = ts11.createSourceFile(filePath, source, ts11.ScriptTarget.Latest, true, ts11.ScriptKind.TSX);
|
|
8065
8194
|
return listComponentFunctionsFromSourceFile(sourceFile);
|
|
8066
8195
|
}
|
|
8067
8196
|
function scanComponentFile(source, filePath) {
|
|
8068
|
-
const sourceFile =
|
|
8197
|
+
const sourceFile = ts11.createSourceFile(filePath, source, ts11.ScriptTarget.Latest, true, ts11.ScriptKind.TSX);
|
|
8069
8198
|
return {
|
|
8070
8199
|
exports: listComponentFunctionsFromSourceFile(sourceFile),
|
|
8071
8200
|
referencedComponents: [...collectJsxComponentTags(sourceFile)]
|
|
@@ -8073,11 +8202,11 @@ function scanComponentFile(source, filePath) {
|
|
|
8073
8202
|
}
|
|
8074
8203
|
function listComponentFunctionsFromSourceFile(sourceFile) {
|
|
8075
8204
|
const componentNames = [];
|
|
8076
|
-
const hasUseClient = sourceFile.statements.some((stmt) =>
|
|
8205
|
+
const hasUseClient = sourceFile.statements.some((stmt) => ts11.isExpressionStatement(stmt) && ts11.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'"));
|
|
8077
8206
|
const namedExports = collectNamedExports(sourceFile);
|
|
8078
8207
|
function collectComponents(node) {
|
|
8079
8208
|
if (isComponentFunction(node)) {
|
|
8080
|
-
const hasInlineExport = node.modifiers?.some((m) => m.kind ===
|
|
8209
|
+
const hasInlineExport = node.modifiers?.some((m) => m.kind === ts11.SyntaxKind.ExportKeyword) ?? false;
|
|
8081
8210
|
const hasNamedExport = namedExports.has(node.name.text);
|
|
8082
8211
|
const isExported = hasInlineExport || hasNamedExport;
|
|
8083
8212
|
if (!hasUseClient && !isExported && node.body && isMultiReturnJsxFunctionBody(node.body)) {} else {
|
|
@@ -8087,9 +8216,9 @@ function listComponentFunctionsFromSourceFile(sourceFile) {
|
|
|
8087
8216
|
if (isArrowComponentFunction(node)) {
|
|
8088
8217
|
componentNames.push(node.name.text);
|
|
8089
8218
|
}
|
|
8090
|
-
|
|
8219
|
+
ts11.forEachChild(node, collectComponents);
|
|
8091
8220
|
}
|
|
8092
|
-
|
|
8221
|
+
ts11.forEachChild(sourceFile, collectComponents);
|
|
8093
8222
|
return componentNames;
|
|
8094
8223
|
}
|
|
8095
8224
|
var REACTIVE_PRIMITIVES = new Set([
|
|
@@ -8101,13 +8230,13 @@ var REACTIVE_PRIMITIVES = new Set([
|
|
|
8101
8230
|
"onCleanup"
|
|
8102
8231
|
]);
|
|
8103
8232
|
function prescanReactiveFactoriesInSource(source, filePath) {
|
|
8104
|
-
const sourceFile =
|
|
8233
|
+
const sourceFile = ts11.createSourceFile(filePath + ".prescan", source, ts11.ScriptTarget.Latest, true, ts11.ScriptKind.TSX);
|
|
8105
8234
|
const factories = new Map;
|
|
8106
8235
|
const declined = new Map;
|
|
8107
8236
|
const reactiveShaped = new Set;
|
|
8108
8237
|
const cleanFactoryImports = new Set;
|
|
8109
8238
|
function visitTop(node) {
|
|
8110
|
-
if (
|
|
8239
|
+
if (ts11.isFunctionDeclaration(node) && node.name && node.body) {
|
|
8111
8240
|
const det = detectReactiveFactory(node, sourceFile, filePath);
|
|
8112
8241
|
if (!det)
|
|
8113
8242
|
return;
|
|
@@ -8124,7 +8253,7 @@ function prescanReactiveFactoriesInSource(source, filePath) {
|
|
|
8124
8253
|
}
|
|
8125
8254
|
}
|
|
8126
8255
|
}
|
|
8127
|
-
|
|
8256
|
+
ts11.forEachChild(sourceFile, visitTop);
|
|
8128
8257
|
const result = { factories, declined, reactiveShaped, cleanFactoryImports, sourceFile };
|
|
8129
8258
|
prescanImportedReactiveFactories(sourceFile, filePath, result);
|
|
8130
8259
|
return result;
|
|
@@ -8141,15 +8270,15 @@ function toComponentRelativeSpecifier(resolvedAbs, componentFilePath) {
|
|
|
8141
8270
|
function buildEntryImportIndex(sf, filePath) {
|
|
8142
8271
|
const index = new Map;
|
|
8143
8272
|
for (const stmt of sf.statements) {
|
|
8144
|
-
if (!
|
|
8273
|
+
if (!ts11.isImportDeclaration(stmt))
|
|
8145
8274
|
continue;
|
|
8146
|
-
if (!
|
|
8275
|
+
if (!ts11.isStringLiteral(stmt.moduleSpecifier))
|
|
8147
8276
|
continue;
|
|
8148
8277
|
const src = stmt.moduleSpecifier.text;
|
|
8149
8278
|
const targetKey = src.startsWith("./") || src.startsWith("../") ? resolveRelativeImportToFile(src, filePath) ?? "unresolved:" + src : src;
|
|
8150
8279
|
const wholeTypeOnly = stmt.importClause?.isTypeOnly === true;
|
|
8151
8280
|
const namedBindings = stmt.importClause?.namedBindings;
|
|
8152
|
-
if (namedBindings &&
|
|
8281
|
+
if (namedBindings && ts11.isNamedImports(namedBindings)) {
|
|
8153
8282
|
for (const el of namedBindings.elements) {
|
|
8154
8283
|
index.set(el.name.text, {
|
|
8155
8284
|
targetKey,
|
|
@@ -8164,31 +8293,31 @@ function buildEntryImportIndex(sf, filePath) {
|
|
|
8164
8293
|
function collectEntryBindingNames(sf) {
|
|
8165
8294
|
const names = new Set;
|
|
8166
8295
|
function visit2(node) {
|
|
8167
|
-
if (
|
|
8296
|
+
if (ts11.isImportDeclaration(node) && node.importClause) {
|
|
8168
8297
|
if (node.importClause.name)
|
|
8169
8298
|
names.add(node.importClause.name.text);
|
|
8170
8299
|
const namedBindings = node.importClause.namedBindings;
|
|
8171
|
-
if (namedBindings &&
|
|
8300
|
+
if (namedBindings && ts11.isNamedImports(namedBindings)) {
|
|
8172
8301
|
for (const el of namedBindings.elements)
|
|
8173
8302
|
names.add(el.name.text);
|
|
8174
8303
|
}
|
|
8175
|
-
if (namedBindings &&
|
|
8304
|
+
if (namedBindings && ts11.isNamespaceImport(namedBindings)) {
|
|
8176
8305
|
names.add(namedBindings.name.text);
|
|
8177
8306
|
}
|
|
8178
8307
|
}
|
|
8179
|
-
if (
|
|
8308
|
+
if (ts11.isVariableDeclaration(node)) {
|
|
8180
8309
|
const out = [];
|
|
8181
8310
|
addBindingNames(node.name, out);
|
|
8182
8311
|
for (const n of out)
|
|
8183
8312
|
names.add(n);
|
|
8184
8313
|
}
|
|
8185
|
-
if ((
|
|
8314
|
+
if ((ts11.isFunctionDeclaration(node) || ts11.isClassDeclaration(node) || ts11.isEnumDeclaration(node)) && node.name) {
|
|
8186
8315
|
names.add(node.name.text);
|
|
8187
8316
|
}
|
|
8188
|
-
if ((
|
|
8317
|
+
if ((ts11.isTypeAliasDeclaration(node) || ts11.isInterfaceDeclaration(node)) && node.name) {
|
|
8189
8318
|
names.add(node.name.text);
|
|
8190
8319
|
}
|
|
8191
|
-
if (
|
|
8320
|
+
if (ts11.isFunctionLike(node)) {
|
|
8192
8321
|
for (const p of node.parameters) {
|
|
8193
8322
|
const out = [];
|
|
8194
8323
|
addBindingNames(p.name, out);
|
|
@@ -8196,7 +8325,7 @@ function collectEntryBindingNames(sf) {
|
|
|
8196
8325
|
names.add(n);
|
|
8197
8326
|
}
|
|
8198
8327
|
}
|
|
8199
|
-
|
|
8328
|
+
ts11.forEachChild(node, visit2);
|
|
8200
8329
|
}
|
|
8201
8330
|
visit2(sf);
|
|
8202
8331
|
return names;
|
|
@@ -8205,19 +8334,19 @@ var MAX_REEXPORT_HOPS = 1;
|
|
|
8205
8334
|
function prescanImportedReactiveFactories(entrySourceFile, filePath, result) {
|
|
8206
8335
|
const candidateCallees = new Set;
|
|
8207
8336
|
function collectCandidates(node) {
|
|
8208
|
-
if (
|
|
8337
|
+
if (ts11.isVariableDeclaration(node) && (ts11.isArrayBindingPattern(node.name) || ts11.isObjectBindingPattern(node.name)) && node.initializer && ts11.isCallExpression(node.initializer) && ts11.isIdentifier(node.initializer.expression)) {
|
|
8209
8338
|
candidateCallees.add(node.initializer.expression.text);
|
|
8210
8339
|
}
|
|
8211
|
-
|
|
8340
|
+
ts11.forEachChild(node, collectCandidates);
|
|
8212
8341
|
}
|
|
8213
8342
|
collectCandidates(entrySourceFile);
|
|
8214
8343
|
if (candidateCallees.size === 0)
|
|
8215
8344
|
return;
|
|
8216
8345
|
const importsToCheck = [];
|
|
8217
8346
|
for (const stmt of entrySourceFile.statements) {
|
|
8218
|
-
if (!
|
|
8347
|
+
if (!ts11.isImportDeclaration(stmt))
|
|
8219
8348
|
continue;
|
|
8220
|
-
if (!
|
|
8349
|
+
if (!ts11.isStringLiteral(stmt.moduleSpecifier))
|
|
8221
8350
|
continue;
|
|
8222
8351
|
const src = stmt.moduleSpecifier.text;
|
|
8223
8352
|
if (!src.startsWith("./") && !src.startsWith("../"))
|
|
@@ -8225,7 +8354,7 @@ function prescanImportedReactiveFactories(entrySourceFile, filePath, result) {
|
|
|
8225
8354
|
if (stmt.importClause?.isTypeOnly)
|
|
8226
8355
|
continue;
|
|
8227
8356
|
const namedBindings = stmt.importClause?.namedBindings;
|
|
8228
|
-
if (!namedBindings || !
|
|
8357
|
+
if (!namedBindings || !ts11.isNamedImports(namedBindings))
|
|
8229
8358
|
continue;
|
|
8230
8359
|
const specs = [];
|
|
8231
8360
|
for (const el of namedBindings.elements) {
|
|
@@ -8263,14 +8392,14 @@ function prescanImportedReactiveFactories(entrySourceFile, filePath, result) {
|
|
|
8263
8392
|
helperCache.set(abs, "clean");
|
|
8264
8393
|
return "clean";
|
|
8265
8394
|
}
|
|
8266
|
-
const sf =
|
|
8395
|
+
const sf = ts11.createSourceFile(abs + ".prescan", content, ts11.ScriptTarget.Latest, true, ts11.ScriptKind.TSX);
|
|
8267
8396
|
const localFns = new Map;
|
|
8268
8397
|
const exportedFns = new Map;
|
|
8269
8398
|
for (const stmt of sf.statements) {
|
|
8270
|
-
if (
|
|
8399
|
+
if (ts11.isFunctionDeclaration(stmt) && stmt.name && stmt.body) {
|
|
8271
8400
|
localFns.set(stmt.name.text, stmt);
|
|
8272
|
-
const hasExportModifier = stmt.modifiers?.some((m) => m.kind ===
|
|
8273
|
-
const hasDefaultModifier = stmt.modifiers?.some((m) => m.kind ===
|
|
8401
|
+
const hasExportModifier = stmt.modifiers?.some((m) => m.kind === ts11.SyntaxKind.ExportKeyword) ?? false;
|
|
8402
|
+
const hasDefaultModifier = stmt.modifiers?.some((m) => m.kind === ts11.SyntaxKind.DefaultKeyword) ?? false;
|
|
8274
8403
|
if (hasExportModifier && !hasDefaultModifier) {
|
|
8275
8404
|
exportedFns.set(stmt.name.text, stmt);
|
|
8276
8405
|
}
|
|
@@ -8279,10 +8408,10 @@ function prescanImportedReactiveFactories(entrySourceFile, filePath, result) {
|
|
|
8279
8408
|
const reexports = new Map;
|
|
8280
8409
|
let hasStarReexport = false;
|
|
8281
8410
|
for (const stmt of sf.statements) {
|
|
8282
|
-
if (!
|
|
8411
|
+
if (!ts11.isExportDeclaration(stmt) || stmt.isTypeOnly)
|
|
8283
8412
|
continue;
|
|
8284
8413
|
if (!stmt.moduleSpecifier) {
|
|
8285
|
-
if (stmt.exportClause &&
|
|
8414
|
+
if (stmt.exportClause && ts11.isNamedExports(stmt.exportClause)) {
|
|
8286
8415
|
for (const el of stmt.exportClause.elements) {
|
|
8287
8416
|
if (el.isTypeOnly)
|
|
8288
8417
|
continue;
|
|
@@ -8293,9 +8422,9 @@ function prescanImportedReactiveFactories(entrySourceFile, filePath, result) {
|
|
|
8293
8422
|
}
|
|
8294
8423
|
continue;
|
|
8295
8424
|
}
|
|
8296
|
-
if (!
|
|
8425
|
+
if (!ts11.isStringLiteral(stmt.moduleSpecifier))
|
|
8297
8426
|
continue;
|
|
8298
|
-
if (stmt.exportClause &&
|
|
8427
|
+
if (stmt.exportClause && ts11.isNamedExports(stmt.exportClause)) {
|
|
8299
8428
|
for (const el of stmt.exportClause.elements) {
|
|
8300
8429
|
if (el.isTypeOnly)
|
|
8301
8430
|
continue;
|
|
@@ -8445,7 +8574,7 @@ function collectHelperModuleValueBindings(sf) {
|
|
|
8445
8574
|
const importedTypes = new Map;
|
|
8446
8575
|
const imported = new Map;
|
|
8447
8576
|
for (const stmt of sf.statements) {
|
|
8448
|
-
if (
|
|
8577
|
+
if (ts11.isVariableStatement(stmt)) {
|
|
8449
8578
|
const out = [];
|
|
8450
8579
|
for (const decl of stmt.declarationList.declarations) {
|
|
8451
8580
|
addBindingNames(decl.name, out);
|
|
@@ -8454,16 +8583,16 @@ function collectHelperModuleValueBindings(sf) {
|
|
|
8454
8583
|
local.add(n);
|
|
8455
8584
|
continue;
|
|
8456
8585
|
}
|
|
8457
|
-
if ((
|
|
8586
|
+
if ((ts11.isFunctionDeclaration(stmt) || ts11.isClassDeclaration(stmt) || ts11.isEnumDeclaration(stmt)) && stmt.name) {
|
|
8458
8587
|
local.add(stmt.name.text);
|
|
8459
8588
|
continue;
|
|
8460
8589
|
}
|
|
8461
|
-
if ((
|
|
8590
|
+
if ((ts11.isTypeAliasDeclaration(stmt) || ts11.isInterfaceDeclaration(stmt)) && stmt.name) {
|
|
8462
8591
|
localTypes.add(stmt.name.text);
|
|
8463
8592
|
continue;
|
|
8464
8593
|
}
|
|
8465
|
-
if (
|
|
8466
|
-
if (!
|
|
8594
|
+
if (ts11.isImportDeclaration(stmt)) {
|
|
8595
|
+
if (!ts11.isStringLiteral(stmt.moduleSpecifier))
|
|
8467
8596
|
continue;
|
|
8468
8597
|
const src = stmt.moduleSpecifier.text;
|
|
8469
8598
|
if (src === "@barefootjs/client" || src === "@barefootjs/client/runtime")
|
|
@@ -8472,7 +8601,7 @@ function collectHelperModuleValueBindings(sf) {
|
|
|
8472
8601
|
if (stmt.importClause?.name)
|
|
8473
8602
|
(wholeTypeOnly ? localTypes : local).add(stmt.importClause.name.text);
|
|
8474
8603
|
const namedBindings = stmt.importClause?.namedBindings;
|
|
8475
|
-
if (namedBindings &&
|
|
8604
|
+
if (namedBindings && ts11.isNamedImports(namedBindings)) {
|
|
8476
8605
|
for (const el of namedBindings.elements) {
|
|
8477
8606
|
const entry = { source: src, exportedName: (el.propertyName ?? el.name).text };
|
|
8478
8607
|
if (wholeTypeOnly || el.isTypeOnly)
|
|
@@ -8481,7 +8610,7 @@ function collectHelperModuleValueBindings(sf) {
|
|
|
8481
8610
|
imported.set(el.name.text, entry);
|
|
8482
8611
|
}
|
|
8483
8612
|
}
|
|
8484
|
-
if (namedBindings &&
|
|
8613
|
+
if (namedBindings && ts11.isNamespaceImport(namedBindings)) {
|
|
8485
8614
|
(wholeTypeOnly ? localTypes : local).add(namedBindings.name.text);
|
|
8486
8615
|
}
|
|
8487
8616
|
}
|
|
@@ -8548,11 +8677,11 @@ function detectReactiveFactory(node, sourceFile, filePath) {
|
|
|
8548
8677
|
function checkForReactive(n) {
|
|
8549
8678
|
if (hasReactiveCall)
|
|
8550
8679
|
return;
|
|
8551
|
-
if (
|
|
8680
|
+
if (ts11.isCallExpression(n) && ts11.isIdentifier(n.expression) && REACTIVE_PRIMITIVES.has(n.expression.text)) {
|
|
8552
8681
|
hasReactiveCall = true;
|
|
8553
8682
|
return;
|
|
8554
8683
|
}
|
|
8555
|
-
|
|
8684
|
+
ts11.forEachChild(n, checkForReactive);
|
|
8556
8685
|
}
|
|
8557
8686
|
checkForReactive(node.body);
|
|
8558
8687
|
if (!hasReactiveCall)
|
|
@@ -8560,29 +8689,29 @@ function detectReactiveFactory(node, sourceFile, filePath) {
|
|
|
8560
8689
|
const loc = getSourceLocation(node, sourceFile, filePath);
|
|
8561
8690
|
let totalReturnCount = 0;
|
|
8562
8691
|
function countReturns(n) {
|
|
8563
|
-
if (
|
|
8692
|
+
if (ts11.isFunctionLike(n))
|
|
8564
8693
|
return;
|
|
8565
|
-
if (
|
|
8694
|
+
if (ts11.isReturnStatement(n)) {
|
|
8566
8695
|
totalReturnCount++;
|
|
8567
8696
|
return;
|
|
8568
8697
|
}
|
|
8569
|
-
|
|
8698
|
+
ts11.forEachChild(n, countReturns);
|
|
8570
8699
|
}
|
|
8571
|
-
|
|
8700
|
+
ts11.forEachChild(node.body, countReturns);
|
|
8572
8701
|
let returnExpr = null;
|
|
8573
8702
|
let returnCount = 0;
|
|
8574
8703
|
for (const stmt of node.body.statements) {
|
|
8575
|
-
if (!
|
|
8704
|
+
if (!ts11.isReturnStatement(stmt))
|
|
8576
8705
|
continue;
|
|
8577
8706
|
returnCount++;
|
|
8578
8707
|
if (!stmt.expression)
|
|
8579
8708
|
return { kind: "reactive-shaped" };
|
|
8580
8709
|
let expr = stmt.expression;
|
|
8581
|
-
while (
|
|
8710
|
+
while (ts11.isParenthesizedExpression(expr))
|
|
8582
8711
|
expr = expr.expression;
|
|
8583
|
-
if (
|
|
8712
|
+
if (ts11.isAsExpression(expr))
|
|
8584
8713
|
expr = expr.expression;
|
|
8585
|
-
if (
|
|
8714
|
+
if (ts11.isTypeAssertionExpression(expr))
|
|
8586
8715
|
expr = expr.expression;
|
|
8587
8716
|
returnExpr = expr;
|
|
8588
8717
|
}
|
|
@@ -8590,18 +8719,18 @@ function detectReactiveFactory(node, sourceFile, filePath) {
|
|
|
8590
8719
|
return { kind: "reactive-shaped" };
|
|
8591
8720
|
const returnTupleIdentifiers = [];
|
|
8592
8721
|
let returnKind;
|
|
8593
|
-
if (
|
|
8722
|
+
if (ts11.isArrayLiteralExpression(returnExpr)) {
|
|
8594
8723
|
returnKind = "tuple";
|
|
8595
8724
|
for (const el of returnExpr.elements) {
|
|
8596
|
-
if (!
|
|
8725
|
+
if (!ts11.isIdentifier(el))
|
|
8597
8726
|
return { kind: "reactive-shaped" };
|
|
8598
8727
|
returnTupleIdentifiers.push(el.text);
|
|
8599
8728
|
}
|
|
8600
8729
|
if (returnTupleIdentifiers.length === 0)
|
|
8601
8730
|
return { kind: "reactive-shaped" };
|
|
8602
|
-
} else if (
|
|
8731
|
+
} else if (ts11.isObjectLiteralExpression(returnExpr)) {
|
|
8603
8732
|
returnKind = "object";
|
|
8604
|
-
const hasNonShorthand = returnExpr.properties.some((p) => !
|
|
8733
|
+
const hasNonShorthand = returnExpr.properties.some((p) => !ts11.isShorthandPropertyAssignment(p));
|
|
8605
8734
|
if (hasNonShorthand) {
|
|
8606
8735
|
return {
|
|
8607
8736
|
kind: "declined",
|
|
@@ -8622,7 +8751,7 @@ function detectReactiveFactory(node, sourceFile, filePath) {
|
|
|
8622
8751
|
}
|
|
8623
8752
|
const params = [];
|
|
8624
8753
|
for (const p of node.parameters) {
|
|
8625
|
-
if (
|
|
8754
|
+
if (ts11.isIdentifier(p.name)) {
|
|
8626
8755
|
params.push(p.name.text);
|
|
8627
8756
|
continue;
|
|
8628
8757
|
}
|
|
@@ -8630,11 +8759,11 @@ function detectReactiveFactory(node, sourceFile, filePath) {
|
|
|
8630
8759
|
}
|
|
8631
8760
|
const localBindings = [];
|
|
8632
8761
|
for (const stmt of node.body.statements) {
|
|
8633
|
-
if (
|
|
8762
|
+
if (ts11.isVariableStatement(stmt)) {
|
|
8634
8763
|
for (const decl of stmt.declarationList.declarations) {
|
|
8635
8764
|
addBindingNames(decl.name, localBindings);
|
|
8636
8765
|
}
|
|
8637
|
-
} else if (
|
|
8766
|
+
} else if (ts11.isFunctionDeclaration(stmt) && stmt.name) {
|
|
8638
8767
|
localBindings.push(stmt.name.text);
|
|
8639
8768
|
}
|
|
8640
8769
|
}
|
|
@@ -8654,47 +8783,47 @@ function detectReactiveFactory(node, sourceFile, filePath) {
|
|
|
8654
8783
|
if (!relevantNames.has(id.text))
|
|
8655
8784
|
return;
|
|
8656
8785
|
const p = id.parent;
|
|
8657
|
-
if (
|
|
8786
|
+
if (ts11.isPropertyAccessExpression(p) && p.name === id)
|
|
8658
8787
|
return;
|
|
8659
|
-
if (
|
|
8788
|
+
if (ts11.isPropertyAssignment(p) && p.name === id)
|
|
8660
8789
|
return;
|
|
8661
|
-
if (
|
|
8790
|
+
if (ts11.isBindingElement(p) && p.propertyName === id)
|
|
8662
8791
|
return;
|
|
8663
|
-
if ((
|
|
8792
|
+
if ((ts11.isMethodDeclaration(p) || ts11.isGetAccessorDeclaration(p) || ts11.isSetAccessorDeclaration(p) || ts11.isPropertyDeclaration(p) || ts11.isEnumMember(p)) && p.name === id)
|
|
8664
8793
|
return;
|
|
8665
|
-
if (
|
|
8794
|
+
if (ts11.isJsxAttribute(p) && p.name === id)
|
|
8666
8795
|
return;
|
|
8667
|
-
if (
|
|
8796
|
+
if (ts11.isLabeledStatement(p) && p.label === id || (ts11.isBreakStatement(p) || ts11.isContinueStatement(p)) && p.label === id)
|
|
8668
8797
|
return;
|
|
8669
|
-
if ((
|
|
8798
|
+
if ((ts11.isJsxOpeningElement(p) || ts11.isJsxSelfClosingElement(p) || ts11.isJsxClosingElement(p)) && p.tagName === id && /^[a-z]/.test(id.text))
|
|
8670
8799
|
return;
|
|
8671
|
-
if (
|
|
8800
|
+
if (ts11.isShorthandPropertyAssignment(p) && p.name === id) {
|
|
8672
8801
|
push(id, "shorthand");
|
|
8673
8802
|
return;
|
|
8674
8803
|
}
|
|
8675
|
-
if (
|
|
8804
|
+
if (ts11.isBindingElement(p) && p.name === id && !p.propertyName && ts11.isObjectBindingPattern(p.parent)) {
|
|
8676
8805
|
if (params.includes(id.text))
|
|
8677
8806
|
shadowedParam = id.text;
|
|
8678
8807
|
push(id, "shorthand");
|
|
8679
8808
|
return;
|
|
8680
8809
|
}
|
|
8681
|
-
const isDecl = (
|
|
8810
|
+
const isDecl = (ts11.isVariableDeclaration(p) || ts11.isParameter(p) || ts11.isBindingElement(p) || ts11.isFunctionDeclaration(p) || ts11.isFunctionExpression(p) || ts11.isClassDeclaration(p) || ts11.isClassExpression(p)) && p.name === id;
|
|
8682
8811
|
if (isDecl && params.includes(id.text))
|
|
8683
8812
|
shadowedParam = id.text;
|
|
8684
8813
|
push(id, "plain");
|
|
8685
8814
|
}
|
|
8686
8815
|
function visit2(n) {
|
|
8687
|
-
if (
|
|
8816
|
+
if (ts11.isTypeNode(n) || ts11.isTypeParameterDeclaration(n) || ts11.isTypeAliasDeclaration(n) || ts11.isInterfaceDeclaration(n))
|
|
8688
8817
|
return;
|
|
8689
|
-
if (
|
|
8818
|
+
if (ts11.isIdentifier(n)) {
|
|
8690
8819
|
classify(n);
|
|
8691
8820
|
return;
|
|
8692
8821
|
}
|
|
8693
|
-
|
|
8822
|
+
ts11.forEachChild(n, visit2);
|
|
8694
8823
|
}
|
|
8695
8824
|
visit2(root);
|
|
8696
8825
|
}
|
|
8697
|
-
const keptStatements = node.body.statements.filter((s) => !
|
|
8826
|
+
const keptStatements = node.body.statements.filter((s) => !ts11.isReturnStatement(s));
|
|
8698
8827
|
const pieces = [];
|
|
8699
8828
|
let base = 0;
|
|
8700
8829
|
for (const stmt of keptStatements) {
|
|
@@ -8742,18 +8871,18 @@ function detectReactiveFactory(node, sourceFile, filePath) {
|
|
|
8742
8871
|
};
|
|
8743
8872
|
}
|
|
8744
8873
|
function addBindingNames(name, out) {
|
|
8745
|
-
if (
|
|
8874
|
+
if (ts11.isIdentifier(name)) {
|
|
8746
8875
|
out.push(name.text);
|
|
8747
8876
|
return;
|
|
8748
8877
|
}
|
|
8749
|
-
if (
|
|
8878
|
+
if (ts11.isObjectBindingPattern(name)) {
|
|
8750
8879
|
for (const el of name.elements)
|
|
8751
8880
|
addBindingNames(el.name, out);
|
|
8752
8881
|
return;
|
|
8753
8882
|
}
|
|
8754
|
-
if (
|
|
8883
|
+
if (ts11.isArrayBindingPattern(name)) {
|
|
8755
8884
|
for (const el of name.elements) {
|
|
8756
|
-
if (
|
|
8885
|
+
if (ts11.isOmittedExpression(el))
|
|
8757
8886
|
continue;
|
|
8758
8887
|
addBindingNames(el.name, out);
|
|
8759
8888
|
}
|
|
@@ -8765,33 +8894,33 @@ function rewriteFactoryCallsInSource(source, prescan) {
|
|
|
8765
8894
|
let callSiteIndex = 0;
|
|
8766
8895
|
const inlinedFactories = new Set;
|
|
8767
8896
|
function visitStmt(node, inComponent) {
|
|
8768
|
-
if (
|
|
8897
|
+
if (ts11.isVariableStatement(node) && inComponent) {
|
|
8769
8898
|
for (const decl of node.declarationList.declarations) {
|
|
8770
8899
|
maybeRewriteDecl(node, decl);
|
|
8771
8900
|
}
|
|
8772
8901
|
}
|
|
8773
|
-
|
|
8774
|
-
if (
|
|
8902
|
+
ts11.forEachChild(node, (child) => {
|
|
8903
|
+
if (ts11.isFunctionDeclaration(child) && child.name && factories.has(child.name.text))
|
|
8775
8904
|
return;
|
|
8776
8905
|
visitStmt(child, inComponent || isPascalCaseComponentFn(child));
|
|
8777
8906
|
});
|
|
8778
8907
|
}
|
|
8779
8908
|
function maybeRewriteDecl(stmt, decl) {
|
|
8780
|
-
if (!decl.initializer || !
|
|
8909
|
+
if (!decl.initializer || !ts11.isCallExpression(decl.initializer))
|
|
8781
8910
|
return;
|
|
8782
|
-
if (!
|
|
8911
|
+
if (!ts11.isIdentifier(decl.initializer.expression))
|
|
8783
8912
|
return;
|
|
8784
8913
|
const factoryName = decl.initializer.expression.text;
|
|
8785
8914
|
const factory = factories.get(factoryName);
|
|
8786
8915
|
if (!factory)
|
|
8787
8916
|
return;
|
|
8788
|
-
if (
|
|
8917
|
+
if (ts11.isArrayBindingPattern(decl.name)) {
|
|
8789
8918
|
if (factory.returnKind !== "tuple")
|
|
8790
8919
|
return;
|
|
8791
8920
|
rewriteTupleDecl(stmt, decl.name, decl.initializer, factory);
|
|
8792
8921
|
return;
|
|
8793
8922
|
}
|
|
8794
|
-
if (
|
|
8923
|
+
if (ts11.isObjectBindingPattern(decl.name)) {
|
|
8795
8924
|
if (factory.returnKind !== "object")
|
|
8796
8925
|
return;
|
|
8797
8926
|
rewriteObjectDecl(stmt, decl.name, decl.initializer, factory);
|
|
@@ -8804,7 +8933,7 @@ function rewriteFactoryCallsInSource(source, prescan) {
|
|
|
8804
8933
|
return;
|
|
8805
8934
|
const callerNames = [];
|
|
8806
8935
|
for (const el of elements) {
|
|
8807
|
-
if (
|
|
8936
|
+
if (ts11.isOmittedExpression(el) || !ts11.isIdentifier(el.name))
|
|
8808
8937
|
return;
|
|
8809
8938
|
callerNames.push(el.name.text);
|
|
8810
8939
|
}
|
|
@@ -8826,7 +8955,7 @@ function rewriteFactoryCallsInSource(source, prescan) {
|
|
|
8826
8955
|
return;
|
|
8827
8956
|
if (el.initializer)
|
|
8828
8957
|
return;
|
|
8829
|
-
if (!
|
|
8958
|
+
if (!ts11.isIdentifier(el.name))
|
|
8830
8959
|
return;
|
|
8831
8960
|
if (!factory.returnTupleIdentifiers.includes(el.name.text))
|
|
8832
8961
|
return;
|
|
@@ -8935,21 +9064,21 @@ function factoryImportInsertionOffset(sf) {
|
|
|
8935
9064
|
let lastImportEnd = -1;
|
|
8936
9065
|
let directiveEnd = -1;
|
|
8937
9066
|
for (const stmt of sf.statements) {
|
|
8938
|
-
if (
|
|
9067
|
+
if (ts11.isImportDeclaration(stmt)) {
|
|
8939
9068
|
lastImportEnd = stmt.getEnd();
|
|
8940
9069
|
continue;
|
|
8941
9070
|
}
|
|
8942
|
-
if (directiveEnd === -1 &&
|
|
9071
|
+
if (directiveEnd === -1 && ts11.isExpressionStatement(stmt) && ts11.isStringLiteral(stmt.expression) && stmt.expression.text === "use client") {
|
|
8943
9072
|
directiveEnd = stmt.getEnd();
|
|
8944
9073
|
}
|
|
8945
9074
|
}
|
|
8946
9075
|
return lastImportEnd >= 0 ? lastImportEnd : directiveEnd >= 0 ? directiveEnd : 0;
|
|
8947
9076
|
}
|
|
8948
9077
|
function isPascalCaseComponentFn(node) {
|
|
8949
|
-
if (
|
|
9078
|
+
if (ts11.isFunctionDeclaration(node) && node.name) {
|
|
8950
9079
|
return /^[A-Z]/.test(node.name.text);
|
|
8951
9080
|
}
|
|
8952
|
-
if (
|
|
9081
|
+
if (ts11.isVariableDeclaration(node) && ts11.isIdentifier(node.name) && node.initializer && ts11.isArrowFunction(node.initializer)) {
|
|
8953
9082
|
return /^[A-Z]/.test(node.name.text);
|
|
8954
9083
|
}
|
|
8955
9084
|
return false;
|
|
@@ -8978,20 +9107,20 @@ function declinedFactoryErrorCode(code) {
|
|
|
8978
9107
|
function validateReactiveFactoryCalls(ctx) {
|
|
8979
9108
|
if (!ctx.componentNode)
|
|
8980
9109
|
return;
|
|
8981
|
-
const body =
|
|
9110
|
+
const body = ts11.isFunctionDeclaration(ctx.componentNode) ? ctx.componentNode.body : ts11.isBlock(ctx.componentNode.body) ? ctx.componentNode.body : null;
|
|
8982
9111
|
if (!body)
|
|
8983
9112
|
return;
|
|
8984
9113
|
for (const stmt of body.statements) {
|
|
8985
|
-
if (!
|
|
9114
|
+
if (!ts11.isVariableStatement(stmt))
|
|
8986
9115
|
continue;
|
|
8987
9116
|
for (const decl of stmt.declarationList.declarations) {
|
|
8988
|
-
if (!decl.initializer || !
|
|
9117
|
+
if (!decl.initializer || !ts11.isCallExpression(decl.initializer))
|
|
8989
9118
|
continue;
|
|
8990
|
-
if (!
|
|
9119
|
+
if (!ts11.isIdentifier(decl.initializer.expression))
|
|
8991
9120
|
continue;
|
|
8992
9121
|
const callee = decl.initializer.expression.text;
|
|
8993
9122
|
const loc = getSourceLocation(stmt, ctx.sourceFile, ctx.filePath);
|
|
8994
|
-
if (
|
|
9123
|
+
if (ts11.isArrayBindingPattern(decl.name)) {
|
|
8995
9124
|
if (callee === "createSignal" || callee === "createMemo")
|
|
8996
9125
|
continue;
|
|
8997
9126
|
if (resolveEnvSignalKey(decl.initializer, ctx))
|
|
@@ -9018,7 +9147,7 @@ function validateReactiveFactoryCalls(ctx) {
|
|
|
9018
9147
|
}));
|
|
9019
9148
|
continue;
|
|
9020
9149
|
}
|
|
9021
|
-
if (
|
|
9150
|
+
if (ts11.isObjectBindingPattern(decl.name)) {
|
|
9022
9151
|
validateObjectFactoryDestructure(ctx, decl.name, callee, loc);
|
|
9023
9152
|
}
|
|
9024
9153
|
}
|
|
@@ -9027,25 +9156,25 @@ function validateReactiveFactoryCalls(ctx) {
|
|
|
9027
9156
|
function validateNamespaceQualifiedPrimitives(ctx) {
|
|
9028
9157
|
if (!ctx.componentNode)
|
|
9029
9158
|
return;
|
|
9030
|
-
const body =
|
|
9159
|
+
const body = ts11.isFunctionDeclaration(ctx.componentNode) ? ctx.componentNode.body : ts11.isBlock(ctx.componentNode.body) ? ctx.componentNode.body : null;
|
|
9031
9160
|
if (!body)
|
|
9032
9161
|
return;
|
|
9033
9162
|
for (const stmt of body.statements) {
|
|
9034
9163
|
const calls = [];
|
|
9035
|
-
if (
|
|
9164
|
+
if (ts11.isVariableStatement(stmt)) {
|
|
9036
9165
|
for (const decl of stmt.declarationList.declarations) {
|
|
9037
9166
|
let init = decl.initializer;
|
|
9038
|
-
if (init &&
|
|
9167
|
+
if (init && ts11.isElementAccessExpression(init))
|
|
9039
9168
|
init = init.expression;
|
|
9040
|
-
if (init &&
|
|
9169
|
+
if (init && ts11.isCallExpression(init))
|
|
9041
9170
|
calls.push(init);
|
|
9042
9171
|
}
|
|
9043
|
-
} else if (
|
|
9172
|
+
} else if (ts11.isExpressionStatement(stmt) && ts11.isCallExpression(stmt.expression)) {
|
|
9044
9173
|
calls.push(stmt.expression);
|
|
9045
9174
|
}
|
|
9046
9175
|
for (const call of calls) {
|
|
9047
9176
|
const callee = call.expression;
|
|
9048
|
-
if (!
|
|
9177
|
+
if (!ts11.isPropertyAccessExpression(callee) || !ts11.isIdentifier(callee.expression))
|
|
9049
9178
|
continue;
|
|
9050
9179
|
const primitive = callee.name.text;
|
|
9051
9180
|
if (!(primitive in PRIMITIVE_CANONICAL_NAMES))
|
|
@@ -9078,11 +9207,11 @@ function isNamespaceNameShadowedAtComponentTopLevel(name, body, ctx) {
|
|
|
9078
9207
|
if (ctx.propsParams.some((p) => p.name === name))
|
|
9079
9208
|
return true;
|
|
9080
9209
|
for (const stmt of body.statements) {
|
|
9081
|
-
if (
|
|
9210
|
+
if (ts11.isFunctionDeclaration(stmt) && stmt.name?.text === name)
|
|
9082
9211
|
return true;
|
|
9083
|
-
if (
|
|
9212
|
+
if (ts11.isVariableStatement(stmt)) {
|
|
9084
9213
|
for (const decl of stmt.declarationList.declarations) {
|
|
9085
|
-
if (
|
|
9214
|
+
if (ts11.isIdentifier(decl.name) && decl.name.text === name)
|
|
9086
9215
|
return true;
|
|
9087
9216
|
}
|
|
9088
9217
|
}
|
|
@@ -9099,7 +9228,7 @@ function validateObjectFactoryDestructure(ctx, pattern, callee, loc) {
|
|
|
9099
9228
|
}));
|
|
9100
9229
|
return;
|
|
9101
9230
|
}
|
|
9102
|
-
const hasUnsupportedElement = pattern.elements.some((el) => !!el.propertyName || !!el.initializer || !!el.dotDotDotToken || !
|
|
9231
|
+
const hasUnsupportedElement = pattern.elements.some((el) => !!el.propertyName || !!el.initializer || !!el.dotDotDotToken || !ts11.isIdentifier(el.name));
|
|
9103
9232
|
if (hasUnsupportedElement) {
|
|
9104
9233
|
ctx.errors.push(createError(ErrorCodes.REACTIVE_FACTORY_RENAME_UNSUPPORTED, loc, {
|
|
9105
9234
|
severity: "error",
|
|
@@ -9107,7 +9236,7 @@ function validateObjectFactoryDestructure(ctx, pattern, callee, loc) {
|
|
|
9107
9236
|
}));
|
|
9108
9237
|
return;
|
|
9109
9238
|
}
|
|
9110
|
-
const unknown = pattern.elements.map((el) =>
|
|
9239
|
+
const unknown = pattern.elements.map((el) => ts11.isIdentifier(el.name) ? el.name.text : "").filter((name) => name && !factory.returnTupleIdentifiers.includes(name));
|
|
9111
9240
|
if (unknown.length > 0) {
|
|
9112
9241
|
const label = unknown.length === 1 ? "property" : "properties";
|
|
9113
9242
|
ctx.errors.push(createError(ErrorCodes.UNRECOGNIZED_REACTIVE_FACTORY, loc, {
|
|
@@ -9250,7 +9379,7 @@ function pickAttrMetaFromIR(src) {
|
|
|
9250
9379
|
}
|
|
9251
9380
|
|
|
9252
9381
|
// ../jsx/src/module-exports.ts
|
|
9253
|
-
import
|
|
9382
|
+
import ts12 from "typescript";
|
|
9254
9383
|
function generateModuleExports(ir, extraInlineExported = new Set, rewriteRelativeImport, options) {
|
|
9255
9384
|
const lines = [];
|
|
9256
9385
|
for (const constant of options?.skipValueDeclarations ? [] : ir.metadata.localConstants) {
|
|
@@ -9351,21 +9480,21 @@ function findAssignedNames(bodyText, candidates) {
|
|
|
9351
9480
|
const assigned = new Set;
|
|
9352
9481
|
if (candidates.size === 0)
|
|
9353
9482
|
return assigned;
|
|
9354
|
-
const sf =
|
|
9483
|
+
const sf = ts12.createSourceFile("bf-assignment-scan.tsx", bodyText, ts12.ScriptTarget.Latest, false, ts12.ScriptKind.TSX);
|
|
9355
9484
|
const record = (target) => {
|
|
9356
|
-
if (
|
|
9485
|
+
if (ts12.isIdentifier(target) && candidates.has(target.text)) {
|
|
9357
9486
|
assigned.add(target.text);
|
|
9358
9487
|
}
|
|
9359
9488
|
};
|
|
9360
9489
|
const visit2 = (node) => {
|
|
9361
|
-
if (
|
|
9490
|
+
if (ts12.isBinaryExpression(node) && isAssignmentOperator(node.operatorToken.kind)) {
|
|
9362
9491
|
record(node.left);
|
|
9363
|
-
} else if ((
|
|
9492
|
+
} else if ((ts12.isPrefixUnaryExpression(node) || ts12.isPostfixUnaryExpression(node)) && (node.operator === ts12.SyntaxKind.PlusPlusToken || node.operator === ts12.SyntaxKind.MinusMinusToken)) {
|
|
9364
9493
|
record(node.operand);
|
|
9365
9494
|
}
|
|
9366
|
-
|
|
9495
|
+
ts12.forEachChild(node, visit2);
|
|
9367
9496
|
};
|
|
9368
|
-
|
|
9497
|
+
ts12.forEachChild(sf, visit2);
|
|
9369
9498
|
return assigned;
|
|
9370
9499
|
}
|
|
9371
9500
|
function closeOverWritersOfMutableBindings(primaryRefs, declarations, mutableNames) {
|
|
@@ -9388,7 +9517,7 @@ function closeOverWritersOfMutableBindings(primaryRefs, declarations, mutableNam
|
|
|
9388
9517
|
return reachable;
|
|
9389
9518
|
}
|
|
9390
9519
|
function isAssignmentOperator(kind) {
|
|
9391
|
-
return kind >=
|
|
9520
|
+
return kind >= ts12.SyntaxKind.FirstAssignment && kind <= ts12.SyntaxKind.LastAssignment;
|
|
9392
9521
|
}
|
|
9393
9522
|
|
|
9394
9523
|
// ../jsx/src/builtins.ts
|
|
@@ -9411,102 +9540,6 @@ function stripClientBuiltinImports(imports) {
|
|
|
9411
9540
|
return result;
|
|
9412
9541
|
}
|
|
9413
9542
|
|
|
9414
|
-
// ../jsx/src/reactivity-checker.ts
|
|
9415
|
-
import ts12 from "typescript";
|
|
9416
|
-
var REACTIVE_BRAND = "__reactive";
|
|
9417
|
-
function queryType(checker, node) {
|
|
9418
|
-
incrementCounter("typeCheckerQueries");
|
|
9419
|
-
return checker.getTypeAtLocation(node);
|
|
9420
|
-
}
|
|
9421
|
-
function isReactiveType(type) {
|
|
9422
|
-
return type.getProperty(REACTIVE_BRAND) !== undefined;
|
|
9423
|
-
}
|
|
9424
|
-
var NOT_REACTIVE = { isReactive: false, reason: { kind: "not-reactive" } };
|
|
9425
|
-
function safeGetText(node) {
|
|
9426
|
-
try {
|
|
9427
|
-
return node.getText();
|
|
9428
|
-
} catch {
|
|
9429
|
-
return "";
|
|
9430
|
-
}
|
|
9431
|
-
}
|
|
9432
|
-
function analyze(node, checker) {
|
|
9433
|
-
if (ts12.isPropertyAccessExpression(node)) {
|
|
9434
|
-
try {
|
|
9435
|
-
const type = queryType(checker, node);
|
|
9436
|
-
if (isReactiveType(type)) {
|
|
9437
|
-
return {
|
|
9438
|
-
isReactive: true,
|
|
9439
|
-
reason: { kind: "brand", via: "property-access", nodeText: safeGetText(node) }
|
|
9440
|
-
};
|
|
9441
|
-
}
|
|
9442
|
-
} catch {}
|
|
9443
|
-
const sub = analyze(node.expression, checker);
|
|
9444
|
-
if (sub.isReactive) {
|
|
9445
|
-
return {
|
|
9446
|
-
isReactive: true,
|
|
9447
|
-
reason: {
|
|
9448
|
-
kind: "child",
|
|
9449
|
-
via: "property-access-object",
|
|
9450
|
-
childText: safeGetText(node.expression),
|
|
9451
|
-
childReason: sub.reason
|
|
9452
|
-
}
|
|
9453
|
-
};
|
|
9454
|
-
}
|
|
9455
|
-
return NOT_REACTIVE;
|
|
9456
|
-
}
|
|
9457
|
-
if (ts12.isIdentifier(node)) {
|
|
9458
|
-
try {
|
|
9459
|
-
const type = queryType(checker, node);
|
|
9460
|
-
if (isReactiveType(type)) {
|
|
9461
|
-
return {
|
|
9462
|
-
isReactive: true,
|
|
9463
|
-
reason: { kind: "brand", via: "identifier", nodeText: safeGetText(node) }
|
|
9464
|
-
};
|
|
9465
|
-
}
|
|
9466
|
-
} catch {}
|
|
9467
|
-
return NOT_REACTIVE;
|
|
9468
|
-
}
|
|
9469
|
-
if (ts12.isCallExpression(node)) {
|
|
9470
|
-
try {
|
|
9471
|
-
const calleeType = queryType(checker, node.expression);
|
|
9472
|
-
if (isReactiveType(calleeType)) {
|
|
9473
|
-
return {
|
|
9474
|
-
isReactive: true,
|
|
9475
|
-
reason: { kind: "brand", via: "callee", nodeText: safeGetText(node) }
|
|
9476
|
-
};
|
|
9477
|
-
}
|
|
9478
|
-
} catch {}
|
|
9479
|
-
}
|
|
9480
|
-
let foundChild;
|
|
9481
|
-
let foundChildText = "";
|
|
9482
|
-
ts12.forEachChild(node, (child) => {
|
|
9483
|
-
if (foundChild?.isReactive)
|
|
9484
|
-
return;
|
|
9485
|
-
const result = analyze(child, checker);
|
|
9486
|
-
if (result.isReactive) {
|
|
9487
|
-
foundChild = result;
|
|
9488
|
-
foundChildText = safeGetText(child);
|
|
9489
|
-
}
|
|
9490
|
-
});
|
|
9491
|
-
if (foundChild?.isReactive) {
|
|
9492
|
-
return {
|
|
9493
|
-
isReactive: true,
|
|
9494
|
-
reason: {
|
|
9495
|
-
kind: "child",
|
|
9496
|
-
via: "sub-expression",
|
|
9497
|
-
childText: foundChildText,
|
|
9498
|
-
childReason: foundChild.reason
|
|
9499
|
-
}
|
|
9500
|
-
};
|
|
9501
|
-
}
|
|
9502
|
-
return NOT_REACTIVE;
|
|
9503
|
-
}
|
|
9504
|
-
var brandTypeReactivityAnalyzer = { analyze };
|
|
9505
|
-
function containsReactiveExpression(node, checker) {
|
|
9506
|
-
incrementCounter("reactivityChecks");
|
|
9507
|
-
return brandTypeReactivityAnalyzer.analyze(node, checker).isReactive;
|
|
9508
|
-
}
|
|
9509
|
-
|
|
9510
9543
|
// ../jsx/src/free-refs.ts
|
|
9511
9544
|
import ts13 from "typescript";
|
|
9512
9545
|
var _bindingMapCache = new WeakMap;
|
|
@@ -11183,7 +11216,7 @@ function transformExpressionInner(expr, ctx, node, isClientOnly) {
|
|
|
11183
11216
|
}
|
|
11184
11217
|
const ir = transformJsxExpression(expr, ctx, isClientOnly);
|
|
11185
11218
|
if (ir !== null) {
|
|
11186
|
-
if ((isClientOnly || shouldAutoDeferReactiveBrand(expr, ctx))
|
|
11219
|
+
if (ir.type === "conditional" && (isClientOnly || shouldAutoDeferReactiveBrand(expr, ctx))) {
|
|
11187
11220
|
ir.clientOnly = true;
|
|
11188
11221
|
if (!ir.slotId) {
|
|
11189
11222
|
ir.slotId = generateSlotId(ctx);
|
|
@@ -14130,9 +14163,10 @@ function shouldAutoDeferReactiveBrand(expr, ctx) {
|
|
|
14130
14163
|
const checker = ctx.analyzer.checker;
|
|
14131
14164
|
if (!checker)
|
|
14132
14165
|
return false;
|
|
14133
|
-
|
|
14166
|
+
const leaves = collectReactiveBrandLeaves(expr, checker);
|
|
14167
|
+
if (leaves.length === 0)
|
|
14134
14168
|
return false;
|
|
14135
|
-
if (isSignalOrMemoReference(ctx.getJS(
|
|
14169
|
+
if (leaves.some((leaf) => isSignalOrMemoReference(ctx.getJS(leaf), ctx)))
|
|
14136
14170
|
return false;
|
|
14137
14171
|
return true;
|
|
14138
14172
|
}
|
|
@@ -14515,10 +14549,10 @@ function getControlledPropName(signal, propsParams, propsObjectName = null) {
|
|
|
14515
14549
|
}
|
|
14516
14550
|
|
|
14517
14551
|
// ../jsx/src/ir-to-client-js/reactivity.ts
|
|
14518
|
-
function buildLoopRowScope(loopParam, loopParamBindings, preambleNames, loopIndex) {
|
|
14552
|
+
function buildLoopRowScope(loopParam, loopParamBindings, preambleNames, loopIndex, parentScope) {
|
|
14519
14553
|
if (!loopParam)
|
|
14520
14554
|
return;
|
|
14521
|
-
return BindingScope.EMPTY.enterLoopRow({
|
|
14555
|
+
return (parentScope ?? BindingScope.EMPTY).enterLoopRow({
|
|
14522
14556
|
param: loopParam,
|
|
14523
14557
|
paramBindings: loopParamBindings,
|
|
14524
14558
|
index: loopIndex,
|
|
@@ -14592,16 +14626,22 @@ function needsEffectWrapperCore(expr, ctx, freeIdentifiers2, visitedConstants) {
|
|
|
14592
14626
|
}
|
|
14593
14627
|
return false;
|
|
14594
14628
|
}
|
|
14595
|
-
function classifyReactivity(expr, ctx,
|
|
14629
|
+
function classifyReactivity(expr, ctx, scope, freeIdentifiers2) {
|
|
14596
14630
|
const has = (name) => freeIdentifiers2 ? freeIdentifiers2.has(name) : tokenContainsIdent(expr, name);
|
|
14597
|
-
if (
|
|
14598
|
-
|
|
14599
|
-
|
|
14600
|
-
|
|
14631
|
+
if (scope) {
|
|
14632
|
+
let indexHit;
|
|
14633
|
+
for (const name of scope.valueBoundNames()) {
|
|
14634
|
+
if (!has(name))
|
|
14635
|
+
continue;
|
|
14636
|
+
const source = scope.lookup(name)?.binding.source;
|
|
14637
|
+
if (source === "index") {
|
|
14638
|
+
indexHit ??= name;
|
|
14639
|
+
continue;
|
|
14601
14640
|
}
|
|
14641
|
+
return { kind: "loop-param", param: name };
|
|
14602
14642
|
}
|
|
14603
|
-
|
|
14604
|
-
|
|
14643
|
+
if (indexHit)
|
|
14644
|
+
return { kind: "loop-index", param: indexHit };
|
|
14605
14645
|
}
|
|
14606
14646
|
if (needsEffectWrapper(expr, ctx, freeIdentifiers2)) {
|
|
14607
14647
|
return { kind: "signal-or-memo-or-prop" };
|
|
@@ -14764,9 +14804,9 @@ function traverseForComponents(node, components, skipConditionals = false) {
|
|
|
14764
14804
|
}
|
|
14765
14805
|
});
|
|
14766
14806
|
}
|
|
14767
|
-
function collectLoopChildReactiveTexts(node, ctx, loopParam, loopParamBindings, stopAtReactiveConditionals = false, preambleNames, loopIndex) {
|
|
14807
|
+
function collectLoopChildReactiveTexts(node, ctx, loopParam, loopParamBindings, stopAtReactiveConditionals = false, preambleNames, loopIndex, parentScope) {
|
|
14768
14808
|
const texts = [];
|
|
14769
|
-
const scope = buildLoopRowScope(loopParam, loopParamBindings, preambleNames, loopIndex);
|
|
14809
|
+
const scope = buildLoopRowScope(loopParam, loopParamBindings, preambleNames, loopIndex, parentScope);
|
|
14770
14810
|
walkIR(node, false, {
|
|
14771
14811
|
...stopAt("loop", "async", "ifStatement"),
|
|
14772
14812
|
expression: ({ node: n, scope: insideConditional }) => {
|
|
@@ -14776,7 +14816,7 @@ function collectLoopChildReactiveTexts(node, ctx, loopParam, loopParamBindings,
|
|
|
14776
14816
|
return;
|
|
14777
14817
|
const originFreeIds = freeIdsFromRefs(n.origin?.freeRefs);
|
|
14778
14818
|
const expanded = expandConstantForReactivity(n.expr, ctx, originFreeIds, scope);
|
|
14779
|
-
const reactive = classifyReactivity(expanded.expr, ctx,
|
|
14819
|
+
const reactive = classifyReactivity(expanded.expr, ctx, scope, expanded.freeIds).kind !== "none" || decideWrapFromAstFlags(n).wrap;
|
|
14780
14820
|
if (!reactive)
|
|
14781
14821
|
return;
|
|
14782
14822
|
texts.push({
|
|
@@ -14799,9 +14839,9 @@ function anyNameIn(names, set) {
|
|
|
14799
14839
|
return true;
|
|
14800
14840
|
return false;
|
|
14801
14841
|
}
|
|
14802
|
-
function collectLoopChildReactiveAttrs(node, ctx, loopParam, loopParamBindings, stopAtReactiveConditionals = false, preambleNames, loopIndex) {
|
|
14842
|
+
function collectLoopChildReactiveAttrs(node, ctx, loopParam, loopParamBindings, stopAtReactiveConditionals = false, preambleNames, loopIndex, parentScope) {
|
|
14803
14843
|
const attrs = [];
|
|
14804
|
-
const scope = buildLoopRowScope(loopParam, loopParamBindings, preambleNames, loopIndex);
|
|
14844
|
+
const scope = buildLoopRowScope(loopParam, loopParamBindings, preambleNames, loopIndex, parentScope);
|
|
14805
14845
|
traverseElements(node, (el) => {
|
|
14806
14846
|
if (el.slotId) {
|
|
14807
14847
|
for (const attr of el.attrs) {
|
|
@@ -14816,7 +14856,7 @@ function collectLoopChildReactiveAttrs(node, ctx, loopParam, loopParamBindings,
|
|
|
14816
14856
|
continue;
|
|
14817
14857
|
const expanded = expandConstantForReactivity(valueStr, ctx, attr.freeIdentifiers, scope);
|
|
14818
14858
|
const readsPreamble = preambleNames !== undefined && preambleNames.size > 0 && anyNameIn(expanded.freeIds ?? extractFreeIdentifiersFromText(expanded.expr), preambleNames);
|
|
14819
|
-
const reactive = classifyReactivity(expanded.expr, ctx,
|
|
14859
|
+
const reactive = classifyReactivity(expanded.expr, ctx, scope, expanded.freeIds).kind !== "none" || readsPreamble || attr.callsReactiveGetters || attr.hasFunctionCalls;
|
|
14820
14860
|
if (!attr.clientOnly && !reactive)
|
|
14821
14861
|
continue;
|
|
14822
14862
|
attrs.push({
|
|
@@ -15155,7 +15195,9 @@ function collectInnerLoops(nodes, siblingOffsets, outerLoopParam, ctx, options)
|
|
|
15155
15195
|
const flat = options?.flatBranchMode === true;
|
|
15156
15196
|
const fixedDepth = options?.templateDepth;
|
|
15157
15197
|
const collectBindings = options?.collectItemBindings === true;
|
|
15158
|
-
const
|
|
15198
|
+
const outerSpec = typeof outerLoopParam === "string" ? { param: outerLoopParam } : outerLoopParam;
|
|
15199
|
+
const outerScope = buildLoopRowScope(outerSpec?.param, outerSpec?.bindings, undefined, outerSpec?.index);
|
|
15200
|
+
const initialScope = { parentSlotId: null, depth: 0, insideCond: false, bindingScope: outerScope };
|
|
15159
15201
|
for (const root of nodes) {
|
|
15160
15202
|
walkIR(root, initialScope, {
|
|
15161
15203
|
element: ({ node: el, scope, descend }) => {
|
|
@@ -15171,18 +15213,17 @@ function collectInnerLoops(nodes, siblingOffsets, outerLoopParam, ctx, options)
|
|
|
15171
15213
|
},
|
|
15172
15214
|
loop: ({ node: n, scope, descend }) => {
|
|
15173
15215
|
const emitDepth = fixedDepth ?? scope.depth + 1;
|
|
15174
|
-
const loopParamsForTemplate =
|
|
15216
|
+
const loopParamsForTemplate = outerSpec ? [outerSpec, { param: n.param, bindings: n.paramBindings, index: n.index }] : undefined;
|
|
15175
15217
|
const template = n.children.map((c) => irToPlaceholderTemplate(c, undefined, emitDepth, loopParamsForTemplate)).join("");
|
|
15176
|
-
const refsOuter = outerLoopParam ? identifierPattern(outerLoopParam).test(n.array) : false;
|
|
15177
15218
|
const bindings = emptyLoopChildBindings();
|
|
15178
15219
|
const innerPreambleNames = preambleNamesOf(n);
|
|
15179
15220
|
if (ctx) {
|
|
15180
15221
|
for (const child of n.children) {
|
|
15181
|
-
bindings.reactiveTexts.push(...collectLoopChildReactiveTexts(child, ctx, n.param, n.paramBindings, true, innerPreambleNames, n.index));
|
|
15182
|
-
bindings.reactiveAttrs.push(...collectLoopChildReactiveAttrs(child, ctx, n.param, n.paramBindings, true, innerPreambleNames, n.index));
|
|
15222
|
+
bindings.reactiveTexts.push(...collectLoopChildReactiveTexts(child, ctx, n.param, n.paramBindings, true, innerPreambleNames, n.index, scope.bindingScope));
|
|
15223
|
+
bindings.reactiveAttrs.push(...collectLoopChildReactiveAttrs(child, ctx, n.param, n.paramBindings, true, innerPreambleNames, n.index, scope.bindingScope));
|
|
15183
15224
|
bindings.refs.push(...collectLoopChildRefs(child));
|
|
15184
15225
|
}
|
|
15185
|
-
bindings.conditionals.push(...collectLoopChildConditionals({ type: "fragment", children: n.children, loc: n.loc }, ctx, siblingOffsets, n.param, n.paramBindings, innerPreambleNames, n.index));
|
|
15226
|
+
bindings.conditionals.push(...collectLoopChildConditionals({ type: "fragment", children: n.children, loc: n.loc }, ctx, siblingOffsets, n.param, n.paramBindings, innerPreambleNames, n.index, loopParamsForTemplate, scope.bindingScope));
|
|
15186
15227
|
}
|
|
15187
15228
|
let childComponents;
|
|
15188
15229
|
if (collectBindings) {
|
|
@@ -15224,14 +15265,17 @@ function collectInnerLoops(nodes, siblingOffsets, outerLoopParam, ctx, options)
|
|
|
15224
15265
|
containerSlotId: scope.parentSlotId,
|
|
15225
15266
|
template,
|
|
15226
15267
|
preamble: n.preamble,
|
|
15227
|
-
refsOuterParam: refsOuter,
|
|
15228
15268
|
childComponents,
|
|
15229
15269
|
insideConditional: !flat && scope.insideCond ? true : undefined,
|
|
15230
15270
|
offset: flat ? undefined : resolveLoopOffset(siblingOffsets.get(n)),
|
|
15231
15271
|
bindings
|
|
15232
15272
|
});
|
|
15233
15273
|
if (!flat) {
|
|
15234
|
-
descend({
|
|
15274
|
+
descend({
|
|
15275
|
+
...scope,
|
|
15276
|
+
depth: scope.depth + 1,
|
|
15277
|
+
bindingScope: buildLoopRowScope(n.param, n.paramBindings, innerPreambleNames, n.index, scope.bindingScope)
|
|
15278
|
+
});
|
|
15235
15279
|
}
|
|
15236
15280
|
}
|
|
15237
15281
|
});
|
|
@@ -15240,7 +15284,7 @@ function collectInnerLoops(nodes, siblingOffsets, outerLoopParam, ctx, options)
|
|
|
15240
15284
|
}
|
|
15241
15285
|
function decideLoopRendering(loop, siblingOffsets, ctx) {
|
|
15242
15286
|
const hasNestedComps = (loop.nestedComponents?.length ?? 0) > 0;
|
|
15243
|
-
const innerLoops = collectInnerLoops(loop.children, siblingOffsets, loop.param, ctx);
|
|
15287
|
+
const innerLoops = collectInnerLoops(loop.children, siblingOffsets, { param: loop.param, bindings: loop.paramBindings, index: loop.index }, ctx);
|
|
15244
15288
|
const hasInnerLoops = (innerLoops?.length ?? 0) > 0;
|
|
15245
15289
|
const useElementReconciliation = !loop.childComponent && !loop.isStaticArray && (hasNestedComps || hasInnerLoops);
|
|
15246
15290
|
return { useElementReconciliation, innerLoops };
|
|
@@ -15408,6 +15452,7 @@ function collectElements(node, ctx, siblingOffsets, insideConditional = false) {
|
|
|
15408
15452
|
}
|
|
15409
15453
|
const { useElementReconciliation, innerLoops } = projectionInner ? { useElementReconciliation: false, innerLoops: undefined } : decideLoopRendering(l, siblingOffsets, ctx);
|
|
15410
15454
|
let template = "";
|
|
15455
|
+
let templateIndexed;
|
|
15411
15456
|
let staticItemTemplate;
|
|
15412
15457
|
let skeletonTemplate;
|
|
15413
15458
|
let skeletonPaths;
|
|
@@ -15419,6 +15464,10 @@ function collectElements(node, ctx, siblingOffsets, insideConditional = false) {
|
|
|
15419
15464
|
} else if (l.children[0] && !projectionInner) {
|
|
15420
15465
|
const loopParamSpec = [{ param: l.param, bindings: l.paramBindings }];
|
|
15421
15466
|
template = useElementReconciliation ? irToPlaceholderTemplate(l.children[0], resolveRestSpreadNames(ctx), 0, loopParamSpec) : irToHtmlTemplate(l.children[0], resolveRestSpreadNames(ctx), 0, loopParamSpec);
|
|
15467
|
+
if (l.index) {
|
|
15468
|
+
const loopParamSpecIndexed = [{ param: l.param, bindings: l.paramBindings, index: l.index }];
|
|
15469
|
+
templateIndexed = useElementReconciliation ? irToPlaceholderTemplate(l.children[0], resolveRestSpreadNames(ctx), 0, loopParamSpecIndexed) : irToHtmlTemplate(l.children[0], resolveRestSpreadNames(ctx), 0, loopParamSpecIndexed);
|
|
15470
|
+
}
|
|
15422
15471
|
if (l.isStaticArray) {
|
|
15423
15472
|
staticItemTemplate = useElementReconciliation ? irToPlaceholderTemplate(l.children[0], resolveRestSpreadNames(ctx), 0) : irToHtmlTemplate(l.children[0], resolveRestSpreadNames(ctx), 0);
|
|
15424
15473
|
} else if (!useElementReconciliation && !l.bodyIsMultiRoot && !l.bodyIsItemConditional) {
|
|
@@ -15447,6 +15496,7 @@ function collectElements(node, ctx, siblingOffsets, insideConditional = false) {
|
|
|
15447
15496
|
iterationShape: l.iterationShape,
|
|
15448
15497
|
objectIteration: l.objectIteration,
|
|
15449
15498
|
template,
|
|
15499
|
+
templateIndexed,
|
|
15450
15500
|
staticItemTemplate,
|
|
15451
15501
|
skeletonTemplate,
|
|
15452
15502
|
skeletonPaths,
|
|
@@ -15637,6 +15687,7 @@ function collectBranchLoops(node, ctx, siblingOffsets) {
|
|
|
15637
15687
|
const projectionInner = n.method === "flatMap" && n.children.length === 1 && n.children[0].type === "loop" ? n.children[0] : undefined;
|
|
15638
15688
|
const { useElementReconciliation, innerLoops: innerLoopsCollected } = projectionInner ? { useElementReconciliation: false, innerLoops: undefined } : decideLoopRendering(n, siblingOffsets, undefined);
|
|
15639
15689
|
let childTemplate;
|
|
15690
|
+
let childTemplateIndexed;
|
|
15640
15691
|
const branchLoopParamSpec = [{ param: n.param, bindings: n.paramBindings }];
|
|
15641
15692
|
if (projectionInner) {
|
|
15642
15693
|
childTemplate = "";
|
|
@@ -15645,6 +15696,10 @@ function collectBranchLoops(node, ctx, siblingOffsets) {
|
|
|
15645
15696
|
} else {
|
|
15646
15697
|
childTemplate = n.children.map((c) => irToHtmlTemplate(c, undefined, 0, branchLoopParamSpec)).join("");
|
|
15647
15698
|
}
|
|
15699
|
+
if (n.index && !projectionInner) {
|
|
15700
|
+
const branchLoopParamSpecIndexed = [{ param: n.param, bindings: n.paramBindings, index: n.index }];
|
|
15701
|
+
childTemplateIndexed = useElementReconciliation && n.children[0] ? irToPlaceholderTemplate(n.children[0], restNames, 0, branchLoopParamSpecIndexed) : n.children.map((c) => irToHtmlTemplate(c, undefined, 0, branchLoopParamSpecIndexed)).join("");
|
|
15702
|
+
}
|
|
15648
15703
|
const branchBindings = ctx && !projectionInner ? collectLoopChildBindings(n.children, ctx, siblingOffsets, n.param, n.paramBindings, preambleNamesOf(n), n.index) : emptyLoopChildBindings();
|
|
15649
15704
|
loops.push({
|
|
15650
15705
|
kind: "branch",
|
|
@@ -15660,6 +15715,7 @@ function collectBranchLoops(node, ctx, siblingOffsets) {
|
|
|
15660
15715
|
iterationShape: n.iterationShape,
|
|
15661
15716
|
objectIteration: n.objectIteration,
|
|
15662
15717
|
template: childTemplate,
|
|
15718
|
+
templateIndexed: childTemplateIndexed,
|
|
15663
15719
|
containerSlotId: containerSlot,
|
|
15664
15720
|
preamble: n.preamble,
|
|
15665
15721
|
preambleRegions: n.preambleRegions,
|
|
@@ -15742,19 +15798,10 @@ function collectLoopChildBindings(children, ctx, siblingOffsets, loopParam, loop
|
|
|
15742
15798
|
}
|
|
15743
15799
|
return bindings;
|
|
15744
15800
|
}
|
|
15745
|
-
function collectLoopChildConditionals(node, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex) {
|
|
15801
|
+
function collectLoopChildConditionals(node, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex, loopParams, parentScope) {
|
|
15746
15802
|
const conditionals = [];
|
|
15747
|
-
const scope = buildLoopRowScope(loopParam, loopParamBindings, preambleNames, loopIndex);
|
|
15748
|
-
const refsAnyBindingViaFreeIds = (freeIds) =>
|
|
15749
|
-
if (loopParamBindings && loopParamBindings.length > 0) {
|
|
15750
|
-
for (const b of loopParamBindings) {
|
|
15751
|
-
if (freeIds.has(b.name))
|
|
15752
|
-
return true;
|
|
15753
|
-
}
|
|
15754
|
-
return false;
|
|
15755
|
-
}
|
|
15756
|
-
return loopParam ? freeIds.has(loopParam) : false;
|
|
15757
|
-
};
|
|
15803
|
+
const scope = buildLoopRowScope(loopParam, loopParamBindings, preambleNames, loopIndex, parentScope);
|
|
15804
|
+
const refsAnyBindingViaFreeIds = (freeIds) => scope !== undefined && anyNameIn(scope.valueBoundNames(), freeIds);
|
|
15758
15805
|
walkIR(node, null, {
|
|
15759
15806
|
...stopAt("loop", "async", "ifStatement"),
|
|
15760
15807
|
conditional: ({ node: n }) => {
|
|
@@ -15766,9 +15813,9 @@ function collectLoopChildConditionals(node, ctx, siblingOffsets, loopParam, loop
|
|
|
15766
15813
|
return;
|
|
15767
15814
|
const expanded = expandConstantForReactivity(n.condition, ctx, sourceFreeIds, scope);
|
|
15768
15815
|
const readsPreamble = preambleNames !== undefined && preambleNames.size > 0 && anyNameIn(expanded.freeIds ?? extractFreeIdentifiersFromText(expanded.expr), preambleNames);
|
|
15769
|
-
if (!readsPreamble && classifyReactivity(expanded.expr, ctx,
|
|
15816
|
+
if (!readsPreamble && classifyReactivity(expanded.expr, ctx, scope, expanded.freeIds).kind === "none")
|
|
15770
15817
|
return;
|
|
15771
|
-
const loopParamsForCond = loopParam ? [{ param: loopParam, bindings: loopParamBindings, index: loopIndex }] : undefined;
|
|
15818
|
+
const loopParamsForCond = loopParams ?? (loopParam ? [{ param: loopParam, bindings: loopParamBindings, index: loopIndex }] : undefined);
|
|
15772
15819
|
const whenTrueHtml = irToHtmlTemplate(n.whenTrue, undefined, 0, loopParamsForCond, "__slots");
|
|
15773
15820
|
const whenFalseHtml = irToHtmlTemplate(n.whenFalse, undefined, 0, loopParamsForCond, "__slots");
|
|
15774
15821
|
conditionals.push({
|
|
@@ -15786,7 +15833,7 @@ function collectLoopChildConditionals(node, ctx, siblingOffsets, loopParam, loop
|
|
|
15786
15833
|
return conditionals;
|
|
15787
15834
|
}
|
|
15788
15835
|
function summarizeLoopChildBranch(node, ctx, siblingOffsets, loopParam, loopParamBindings, preambleNames, loopIndex) {
|
|
15789
|
-
const inner = collectInnerLoops([node], siblingOffsets, loopParam, ctx, branchInnerLoopOptions);
|
|
15836
|
+
const inner = collectInnerLoops([node], siblingOffsets, loopParam ? { param: loopParam, bindings: loopParamBindings, index: loopIndex } : undefined, ctx, branchInnerLoopOptions);
|
|
15790
15837
|
return {
|
|
15791
15838
|
childComponents: collectConditionalBranchChildComponents(node),
|
|
15792
15839
|
innerLoops: inner.length > 0 ? inner : undefined,
|
|
@@ -18909,6 +18956,7 @@ function buildBranchInnerLoopsPlan(args) {
|
|
|
18909
18956
|
condSlotId,
|
|
18910
18957
|
outerLoopParam,
|
|
18911
18958
|
outerLoopParamBindings,
|
|
18959
|
+
outerLoopIndex,
|
|
18912
18960
|
wrapOuter
|
|
18913
18961
|
} = args;
|
|
18914
18962
|
if (!innerLoops || innerLoops.length === 0)
|
|
@@ -18916,7 +18964,7 @@ function buildBranchInnerLoopsPlan(args) {
|
|
|
18916
18964
|
const plan = [];
|
|
18917
18965
|
for (let i = 0;i < innerLoops.length; i++) {
|
|
18918
18966
|
const inner = innerLoops[i];
|
|
18919
|
-
if (!inner.
|
|
18967
|
+
if (!inner.template)
|
|
18920
18968
|
continue;
|
|
18921
18969
|
const wrapInner = (expr) => wrapLoopParamAsAccessor(expr, inner.param, inner.paramBindings, inner.index);
|
|
18922
18970
|
const wrapBoth = (expr) => wrapLoopParamAsAccessor(wrapOuter(expr), inner.param, inner.paramBindings, inner.index);
|
|
@@ -18979,18 +19027,20 @@ function buildBranchInnerLoopsPlan(args) {
|
|
|
18979
19027
|
scopeVar: `__belbr_${i}`,
|
|
18980
19028
|
wrap: wrapBoth,
|
|
18981
19029
|
loopParam: inner.param,
|
|
18982
|
-
loopParamBindings: inner.paramBindings
|
|
19030
|
+
loopParamBindings: inner.paramBindings,
|
|
19031
|
+
loopIndex: inner.index
|
|
18983
19032
|
}),
|
|
18984
19033
|
innerLoopParam: inner.param,
|
|
18985
19034
|
innerLoopParamBindings: inner.paramBindings,
|
|
18986
19035
|
outerLoopParam,
|
|
18987
|
-
outerLoopParamBindings
|
|
19036
|
+
outerLoopParamBindings,
|
|
19037
|
+
outerLoopIndex
|
|
18988
19038
|
});
|
|
18989
19039
|
}
|
|
18990
19040
|
return plan;
|
|
18991
19041
|
}
|
|
18992
19042
|
function buildLoopChildConditionalsPlan(args) {
|
|
18993
|
-
const { conditionals, scopeVar, wrap, loopParam, loopParamBindings } = args;
|
|
19043
|
+
const { conditionals, scopeVar, wrap, loopParam, loopParamBindings, loopIndex } = args;
|
|
18994
19044
|
if (!conditionals || conditionals.length === 0)
|
|
18995
19045
|
return [];
|
|
18996
19046
|
const plans = [];
|
|
@@ -18999,13 +19049,14 @@ function buildLoopChildConditionalsPlan(args) {
|
|
|
18999
19049
|
slotId: cond.slotId,
|
|
19000
19050
|
scopeVar,
|
|
19001
19051
|
wrappedCondition: wrap(cond.condition),
|
|
19002
|
-
whenTrueTemplateHtml: addCondAttrToTemplate(
|
|
19003
|
-
whenFalseTemplateHtml: addCondAttrToTemplate(
|
|
19052
|
+
whenTrueTemplateHtml: addCondAttrToTemplate(cond.whenTrueHtml, cond.slotId),
|
|
19053
|
+
whenFalseTemplateHtml: addCondAttrToTemplate(cond.whenFalseHtml, cond.slotId),
|
|
19004
19054
|
whenTrueArm: buildLoopChildArmPlan({
|
|
19005
19055
|
branch: cond.whenTrue,
|
|
19006
19056
|
wrap,
|
|
19007
19057
|
loopParam,
|
|
19008
19058
|
loopParamBindings,
|
|
19059
|
+
loopIndex,
|
|
19009
19060
|
condId: cond.slotId
|
|
19010
19061
|
}),
|
|
19011
19062
|
whenFalseArm: buildLoopChildArmPlan({
|
|
@@ -19013,8 +19064,10 @@ function buildLoopChildConditionalsPlan(args) {
|
|
|
19013
19064
|
wrap,
|
|
19014
19065
|
loopParam,
|
|
19015
19066
|
loopParamBindings,
|
|
19067
|
+
loopIndex,
|
|
19016
19068
|
condId: cond.slotId
|
|
19017
|
-
})
|
|
19069
|
+
}),
|
|
19070
|
+
...cond.readsPreamble && { readsPreamble: true }
|
|
19018
19071
|
});
|
|
19019
19072
|
}
|
|
19020
19073
|
return plans;
|
|
@@ -19038,7 +19091,8 @@ function buildArmAttrsPlan(attrs, wrap) {
|
|
|
19038
19091
|
attrs: slotAttrs.map((attr) => ({
|
|
19039
19092
|
attrName: attr.attrName,
|
|
19040
19093
|
wrappedExpression: wrap(attr.expression),
|
|
19041
|
-
meta: pickAttrMeta(attr)
|
|
19094
|
+
meta: pickAttrMeta(attr),
|
|
19095
|
+
...attr.readsPreamble && { readsPreamble: true }
|
|
19042
19096
|
}))
|
|
19043
19097
|
});
|
|
19044
19098
|
}
|
|
@@ -19053,7 +19107,7 @@ function buildArmTextsPlan(texts, wrap) {
|
|
|
19053
19107
|
}));
|
|
19054
19108
|
}
|
|
19055
19109
|
function buildLoopChildArmPlan(args) {
|
|
19056
|
-
const { branch, wrap, loopParam, loopParamBindings, condId } = args;
|
|
19110
|
+
const { branch, wrap, loopParam, loopParamBindings, loopIndex, condId } = args;
|
|
19057
19111
|
return {
|
|
19058
19112
|
events: buildBranchEventBindingsPlan({
|
|
19059
19113
|
events: branch.events,
|
|
@@ -19069,6 +19123,7 @@ function buildLoopChildArmPlan(args) {
|
|
|
19069
19123
|
condSlotId: condId,
|
|
19070
19124
|
outerLoopParam: loopParam,
|
|
19071
19125
|
outerLoopParamBindings: loopParamBindings,
|
|
19126
|
+
outerLoopIndex: loopIndex,
|
|
19072
19127
|
wrapOuter: wrap
|
|
19073
19128
|
}),
|
|
19074
19129
|
nestedConditionals: buildLoopChildConditionalsPlan({
|
|
@@ -19076,7 +19131,8 @@ function buildLoopChildArmPlan(args) {
|
|
|
19076
19131
|
scopeVar: "__branchScope",
|
|
19077
19132
|
wrap,
|
|
19078
19133
|
loopParam,
|
|
19079
|
-
loopParamBindings
|
|
19134
|
+
loopParamBindings,
|
|
19135
|
+
loopIndex
|
|
19080
19136
|
}),
|
|
19081
19137
|
attrs: buildArmAttrsPlan(branch.reactiveAttrs, wrap),
|
|
19082
19138
|
texts: buildArmTextsPlan(branch.reactiveTexts, wrap)
|
|
@@ -19118,10 +19174,10 @@ function buildReactiveEffectsPlan(args) {
|
|
|
19118
19174
|
conditionalPlans.push({
|
|
19119
19175
|
slotId: cond.slotId,
|
|
19120
19176
|
wrappedCondition: wrap(cond.condition),
|
|
19121
|
-
whenTrueTemplateHtml: addCondAttrToTemplate(
|
|
19122
|
-
whenFalseTemplateHtml: addCondAttrToTemplate(
|
|
19123
|
-
whenTrueArm: buildOuterArm(cond.whenTrue, wrap, loopParam, loopParamBindings, cond.slotId, profileComponentName),
|
|
19124
|
-
whenFalseArm: buildOuterArm(cond.whenFalse, wrap, loopParam, loopParamBindings, cond.slotId, profileComponentName),
|
|
19177
|
+
whenTrueTemplateHtml: addCondAttrToTemplate(cond.whenTrueHtml, cond.slotId),
|
|
19178
|
+
whenFalseTemplateHtml: addCondAttrToTemplate(cond.whenFalseHtml, cond.slotId),
|
|
19179
|
+
whenTrueArm: buildOuterArm(cond.whenTrue, wrap, loopParam, loopParamBindings, loopIndex, cond.slotId, profileComponentName),
|
|
19180
|
+
whenFalseArm: buildOuterArm(cond.whenFalse, wrap, loopParam, loopParamBindings, loopIndex, cond.slotId, profileComponentName),
|
|
19125
19181
|
...cond.readsPreamble && { readsPreamble: true }
|
|
19126
19182
|
});
|
|
19127
19183
|
}
|
|
@@ -19133,7 +19189,7 @@ function buildReactiveEffectsPlan(args) {
|
|
|
19133
19189
|
profileComponentName
|
|
19134
19190
|
};
|
|
19135
19191
|
}
|
|
19136
|
-
function buildOuterArm(branch, wrap, loopParam, loopParamBindings, condSlotId, profileComponentName) {
|
|
19192
|
+
function buildOuterArm(branch, wrap, loopParam, loopParamBindings, loopIndex, condSlotId, profileComponentName) {
|
|
19137
19193
|
return {
|
|
19138
19194
|
events: buildBranchEventBindingsPlan({
|
|
19139
19195
|
events: branch.events,
|
|
@@ -19150,6 +19206,7 @@ function buildOuterArm(branch, wrap, loopParam, loopParamBindings, condSlotId, p
|
|
|
19150
19206
|
condSlotId,
|
|
19151
19207
|
outerLoopParam: loopParam,
|
|
19152
19208
|
outerLoopParamBindings: loopParamBindings,
|
|
19209
|
+
outerLoopIndex: loopIndex,
|
|
19153
19210
|
wrapOuter: wrap
|
|
19154
19211
|
}),
|
|
19155
19212
|
nestedConditionals: buildLoopChildConditionalsPlan({
|
|
@@ -19157,7 +19214,8 @@ function buildOuterArm(branch, wrap, loopParam, loopParamBindings, condSlotId, p
|
|
|
19157
19214
|
scopeVar: "__branchScope",
|
|
19158
19215
|
wrap,
|
|
19159
19216
|
loopParam,
|
|
19160
|
-
loopParamBindings
|
|
19217
|
+
loopParamBindings,
|
|
19218
|
+
loopIndex
|
|
19161
19219
|
}),
|
|
19162
19220
|
attrs: buildArmAttrsPlan(branch.reactiveAttrs, wrap),
|
|
19163
19221
|
texts: buildArmTextsPlan(branch.reactiveTexts, wrap)
|
|
@@ -19197,8 +19255,8 @@ function wrapAttrValueExpression2(value, wrap) {
|
|
|
19197
19255
|
}
|
|
19198
19256
|
}
|
|
19199
19257
|
function buildInnerLoopsPlan(args) {
|
|
19200
|
-
const { levels, parentElVar, outerLoopParam, outerLoopParamBindings } = args;
|
|
19201
|
-
const wrapOuter = outerLoopParam ? (expr) => wrapLoopParamAsAccessor(expr, outerLoopParam, outerLoopParamBindings) : (expr) => expr;
|
|
19258
|
+
const { levels, parentElVar, outerLoopParam, outerLoopParamBindings, outerLoopIndex } = args;
|
|
19259
|
+
const wrapOuter = outerLoopParam ? (expr) => wrapLoopParamAsAccessor(expr, outerLoopParam, outerLoopParamBindings, outerLoopIndex) : (expr) => expr;
|
|
19202
19260
|
const plan = [];
|
|
19203
19261
|
let i = 0;
|
|
19204
19262
|
while (i < levels.length) {
|
|
@@ -19220,15 +19278,14 @@ function buildInnerLoopsPlan(args) {
|
|
|
19220
19278
|
}
|
|
19221
19279
|
const uidSuffix = `${inner.depth}_${i}`;
|
|
19222
19280
|
const containerExpr = inner.containerSlotId ? `qsa(${parentElVar}, '[bf="${inner.containerSlotId}"]')` : parentElVar;
|
|
19223
|
-
const
|
|
19224
|
-
const
|
|
19225
|
-
const emit = useReactive ? buildReactiveEmit(inner, level, wrapOuter, uidSuffix, outerLoopParam, outerLoopParamBindings) : buildStaticEmit(inner, level, uidSuffix);
|
|
19226
|
-
const arrayExpr = useReactive ? wrapOuter(inner.array) : inner.array;
|
|
19281
|
+
const emit = buildReactiveEmit(inner, level, wrapOuter, uidSuffix, outerLoopParam, outerLoopParamBindings, outerLoopIndex);
|
|
19282
|
+
const arrayExpr = wrapOuter(inner.array);
|
|
19227
19283
|
const childLevelsPlan = childLevels.length > 0 ? buildInnerLoopsPlan({
|
|
19228
19284
|
levels: childLevels,
|
|
19229
19285
|
parentElVar: `__innerEl${uidSuffix}`,
|
|
19230
19286
|
outerLoopParam: inner.param,
|
|
19231
|
-
outerLoopParamBindings: inner.paramBindings
|
|
19287
|
+
outerLoopParamBindings: inner.paramBindings,
|
|
19288
|
+
outerLoopIndex: inner.index
|
|
19232
19289
|
}) : [];
|
|
19233
19290
|
plan.push({
|
|
19234
19291
|
uidSuffix,
|
|
@@ -19242,13 +19299,14 @@ function buildInnerLoopsPlan(args) {
|
|
|
19242
19299
|
emit,
|
|
19243
19300
|
childLevels: childLevelsPlan,
|
|
19244
19301
|
outerLoopParam,
|
|
19245
|
-
outerLoopParamBindings
|
|
19302
|
+
outerLoopParamBindings,
|
|
19303
|
+
outerLoopIndex
|
|
19246
19304
|
});
|
|
19247
19305
|
i = j;
|
|
19248
19306
|
}
|
|
19249
19307
|
return plan;
|
|
19250
19308
|
}
|
|
19251
|
-
function buildReactiveEmit(inner, level, wrapOuter, uidSuffix, outerLoopParam, outerLoopParamBindings) {
|
|
19309
|
+
function buildReactiveEmit(inner, level, wrapOuter, uidSuffix, outerLoopParam, outerLoopParamBindings, outerLoopIndex) {
|
|
19252
19310
|
const wrapInner = (expr) => wrapLoopParamAsAccessor(expr, inner.param, inner.paramBindings, inner.index);
|
|
19253
19311
|
const wrapBoth = (expr) => wrapLoopParamAsAccessor(wrapOuter(expr), inner.param, inner.paramBindings, inner.index);
|
|
19254
19312
|
const { head: paramHead, unwrap: paramUnwrap } = destructureLoopParam(inner.param, inner.paramBindings);
|
|
@@ -19303,7 +19361,7 @@ function buildReactiveEmit(inner, level, wrapOuter, uidSuffix, outerLoopParam, o
|
|
|
19303
19361
|
preludeStatements.push(paramUnwrap);
|
|
19304
19362
|
if (inner.preamble) {
|
|
19305
19363
|
const leafLoopParams = outerLoopParam ? [
|
|
19306
|
-
{ param: outerLoopParam, bindings: outerLoopParamBindings },
|
|
19364
|
+
{ param: outerLoopParam, bindings: outerLoopParamBindings, index: outerLoopIndex },
|
|
19307
19365
|
{ param: inner.param, bindings: inner.paramBindings, index: inner.index }
|
|
19308
19366
|
] : [{ param: inner.param, bindings: inner.paramBindings, index: inner.index }];
|
|
19309
19367
|
preludeStatements.push(renderPreamble(inner.preamble, {
|
|
@@ -19317,7 +19375,8 @@ function buildReactiveEmit(inner, level, wrapOuter, uidSuffix, outerLoopParam, o
|
|
|
19317
19375
|
scopeVar: `__innerEl${uidSuffix}`,
|
|
19318
19376
|
wrap: wrapBoth,
|
|
19319
19377
|
loopParam: inner.param,
|
|
19320
|
-
loopParamBindings: inner.paramBindings
|
|
19378
|
+
loopParamBindings: inner.paramBindings,
|
|
19379
|
+
loopIndex: inner.index
|
|
19321
19380
|
});
|
|
19322
19381
|
return {
|
|
19323
19382
|
mode: "reactive",
|
|
@@ -19335,25 +19394,6 @@ function buildReactiveEmit(inner, level, wrapOuter, uidSuffix, outerLoopParam, o
|
|
|
19335
19394
|
childRefs
|
|
19336
19395
|
};
|
|
19337
19396
|
}
|
|
19338
|
-
function buildStaticEmit(inner, level, uidSuffix) {
|
|
19339
|
-
const preludeStatements = [];
|
|
19340
|
-
const indexAlias = nestedLoopIndexAlias(inner, `__innerIdx${uidSuffix}`, inner.param, level.comps, level.events);
|
|
19341
|
-
if (indexAlias)
|
|
19342
|
-
preludeStatements.push(indexAlias);
|
|
19343
|
-
if (inner.preamble) {
|
|
19344
|
-
preludeStatements.push(renderPreamble(inner.preamble, {
|
|
19345
|
-
renderLeaf: (ir) => irToHtmlTemplate(ir, undefined, 1, undefined, undefined)
|
|
19346
|
-
}));
|
|
19347
|
-
}
|
|
19348
|
-
return {
|
|
19349
|
-
mode: "static",
|
|
19350
|
-
rawKey: inner.key ?? null,
|
|
19351
|
-
preludeStatements,
|
|
19352
|
-
components: level.comps,
|
|
19353
|
-
events: level.events,
|
|
19354
|
-
childRefs: buildStaticChildRefBindings(inner.bindings.refs)
|
|
19355
|
-
};
|
|
19356
|
-
}
|
|
19357
19397
|
|
|
19358
19398
|
// ../jsx/src/ir-to-client-js/control-flow/plan/build-composite-loop.ts
|
|
19359
19399
|
function buildTopLevelCompositePlan(elem, profileComponentName) {
|
|
@@ -19384,7 +19424,8 @@ function buildTopLevelCompositePlan(elem, profileComponentName) {
|
|
|
19384
19424
|
levels: depthLevels,
|
|
19385
19425
|
parentElVar: "__el",
|
|
19386
19426
|
outerLoopParam: elem.param,
|
|
19387
|
-
outerLoopParamBindings: elem.paramBindings
|
|
19427
|
+
outerLoopParamBindings: elem.paramBindings,
|
|
19428
|
+
outerLoopIndex: elem.index
|
|
19388
19429
|
}),
|
|
19389
19430
|
loopParam: elem.param,
|
|
19390
19431
|
loopParamBindings: elem.paramBindings,
|
|
@@ -19436,7 +19477,8 @@ function buildBranchCompositePlan(loop, cv, profileComponentName) {
|
|
|
19436
19477
|
levels: depthLevels,
|
|
19437
19478
|
parentElVar: "__el",
|
|
19438
19479
|
outerLoopParam: loop.param,
|
|
19439
|
-
outerLoopParamBindings: loop.paramBindings
|
|
19480
|
+
outerLoopParamBindings: loop.paramBindings,
|
|
19481
|
+
outerLoopIndex: loop.index
|
|
19440
19482
|
}),
|
|
19441
19483
|
loopParam: loop.param,
|
|
19442
19484
|
loopParamBindings: loop.paramBindings,
|
|
@@ -19949,8 +19991,8 @@ function decideLazyRow(args) {
|
|
|
19949
19991
|
let conditionalRefusal = null;
|
|
19950
19992
|
for (const cond of rawConditionals) {
|
|
19951
19993
|
const verdict = analyzeLazyConditional(cond, {
|
|
19952
|
-
whenTrueHtml: addCondAttrToTemplate(
|
|
19953
|
-
whenFalseHtml: addCondAttrToTemplate(
|
|
19994
|
+
whenTrueHtml: addCondAttrToTemplate(cond.whenTrueHtml, cond.slotId),
|
|
19995
|
+
whenFalseHtml: addCondAttrToTemplate(cond.whenFalseHtml, cond.slotId)
|
|
19954
19996
|
});
|
|
19955
19997
|
if (!verdict.lazySafe) {
|
|
19956
19998
|
conditionalRefusal = verdict.reason;
|
|
@@ -20166,7 +20208,7 @@ function buildPlainRowCore(inputs) {
|
|
|
20166
20208
|
scope
|
|
20167
20209
|
}) ?? undefined;
|
|
20168
20210
|
const mapPreambleWrappedFinal = !lazyRow && loop.index ? wrapIndexParamAsAccessor(mapPreambleWrapped, loop.index) : mapPreambleWrapped;
|
|
20169
|
-
const templateFinal = !lazyRow && loop.index ?
|
|
20211
|
+
const templateFinal = !lazyRow && loop.index ? loop.templateIndexed ?? loop.template : loop.template;
|
|
20170
20212
|
return {
|
|
20171
20213
|
indexParam,
|
|
20172
20214
|
paramHead,
|
|
@@ -20355,6 +20397,24 @@ function emitAttrUpdate(target, attrName, expression, meta) {
|
|
|
20355
20397
|
`{ const __v = ${expression}; if (__v != null) ${target}.setAttribute('${htmlName}', String(__v)); else ${target}.removeAttribute('${htmlName}') }`
|
|
20356
20398
|
];
|
|
20357
20399
|
}
|
|
20400
|
+
var DEDUP_STORE_DECL = "const __l = []";
|
|
20401
|
+
function dedupGuard(ordinal) {
|
|
20402
|
+
return `!(${ordinal} in __l) || !Object.is(__l[${ordinal}], __x)`;
|
|
20403
|
+
}
|
|
20404
|
+
function emitDedupedAttrUpdate(target, attrName, expression, meta, ordinal, guard = dedupGuard(ordinal)) {
|
|
20405
|
+
const write = emitAttrUpdate(target, attrName, "__x", meta);
|
|
20406
|
+
const lines = [`{ const __x = ${expression}`];
|
|
20407
|
+
if (guard) {
|
|
20408
|
+
lines.push(`if (${guard}) {`);
|
|
20409
|
+
for (const stmt of write)
|
|
20410
|
+
lines.push(` ${stmt}`);
|
|
20411
|
+
lines.push(`}`);
|
|
20412
|
+
} else {
|
|
20413
|
+
lines.push(...write);
|
|
20414
|
+
}
|
|
20415
|
+
lines.push(`__l[${ordinal}] = __x }`);
|
|
20416
|
+
return lines;
|
|
20417
|
+
}
|
|
20358
20418
|
function rewriteDestructuredPropsInExpr(expr, ctx) {
|
|
20359
20419
|
if (ctx.propsObjectName)
|
|
20360
20420
|
return expr;
|
|
@@ -20569,16 +20629,18 @@ function emitReactiveAttributeUpdates(lines, ctx) {
|
|
|
20569
20629
|
}
|
|
20570
20630
|
for (const [slotId, attrs] of attrsBySlot) {
|
|
20571
20631
|
const v = varSlotId(slotId);
|
|
20632
|
+
lines.push(` { ${DEDUP_STORE_DECL}`);
|
|
20572
20633
|
lines.push(` createEffect(() => {`);
|
|
20573
20634
|
lines.push(` if (_${v}) {`);
|
|
20635
|
+
let ordinal = 0;
|
|
20574
20636
|
for (const attr of attrs) {
|
|
20575
20637
|
const expression = rewriteDestructuredPropsInExpr(lower(attr.expression), ctx);
|
|
20576
|
-
for (const stmt of
|
|
20638
|
+
for (const stmt of emitDedupedAttrUpdate(`_${v}`, attr.attrName, expression, attr, ordinal++)) {
|
|
20577
20639
|
lines.push(` ${stmt}`);
|
|
20578
20640
|
}
|
|
20579
20641
|
}
|
|
20580
20642
|
lines.push(` }`);
|
|
20581
|
-
lines.push(` }${bindingIdArg(ctx, slotId)})`);
|
|
20643
|
+
lines.push(` }${bindingIdArg(ctx, slotId)}) }`);
|
|
20582
20644
|
lines.push("");
|
|
20583
20645
|
}
|
|
20584
20646
|
}
|
|
@@ -20631,6 +20693,7 @@ function emitReactiveChildProps(lines, ctx) {
|
|
|
20631
20693
|
if (ctx.reactiveChildProps.length > 0) {
|
|
20632
20694
|
lines.push("");
|
|
20633
20695
|
lines.push(` // Reactive child component props`);
|
|
20696
|
+
lines.push(` { ${DEDUP_STORE_DECL}`);
|
|
20634
20697
|
lines.push(` createEffect(() => {`);
|
|
20635
20698
|
const propsByComponent = new Map;
|
|
20636
20699
|
for (const prop of ctx.reactiveChildProps) {
|
|
@@ -20640,6 +20703,7 @@ function emitReactiveChildProps(lines, ctx) {
|
|
|
20640
20703
|
}
|
|
20641
20704
|
propsByComponent.get(key).push(prop);
|
|
20642
20705
|
}
|
|
20706
|
+
let ordinal = 0;
|
|
20643
20707
|
for (const [, props] of propsByComponent) {
|
|
20644
20708
|
const first = props[0];
|
|
20645
20709
|
const isCommentRoot = first.slotId !== null && first.slotId === ctx.commentScopeRootSlotId;
|
|
@@ -20651,26 +20715,31 @@ function emitReactiveChildProps(lines, ctx) {
|
|
|
20651
20715
|
}
|
|
20652
20716
|
lines.push(` if (${varName}) {`);
|
|
20653
20717
|
for (const prop of props) {
|
|
20654
|
-
const stmts = toHTMLAttrName(prop.attrName) === "value" ? emitChildValueMirrorStatements(varName, prop.expression) :
|
|
20718
|
+
const stmts = toHTMLAttrName(prop.attrName) === "value" ? emitChildValueMirrorStatements(varName, prop.expression) : emitDedupedAttrUpdate(varName, prop.attrName, prop.expression, prop, ordinal++);
|
|
20655
20719
|
for (const stmt of stmts) {
|
|
20656
20720
|
lines.push(` ${stmt}`);
|
|
20657
20721
|
}
|
|
20658
20722
|
}
|
|
20659
20723
|
lines.push(` }`);
|
|
20660
20724
|
}
|
|
20661
|
-
lines.push(` }${bindingIdArg(ctx, ctx.reactiveChildProps[0]?.slotId ?? undefined)})`);
|
|
20725
|
+
lines.push(` }${bindingIdArg(ctx, ctx.reactiveChildProps[0]?.slotId ?? undefined)}) }`);
|
|
20662
20726
|
}
|
|
20663
20727
|
}
|
|
20664
20728
|
|
|
20665
20729
|
// ../jsx/src/ir-to-client-js/control-flow/stringify/loop-child-arm.ts
|
|
20666
|
-
function stringifyBranchReactiveAttrs(lines, plan, indent, pc) {
|
|
20730
|
+
function stringifyBranchReactiveAttrs(lines, plan, indent, pc, mapPreambleWrapped) {
|
|
20667
20731
|
for (const slot of plan) {
|
|
20668
20732
|
const varName = `__ra_${varSlotId(slot.slotId)}`;
|
|
20669
20733
|
lines.push(`${indent}{ const ${varName} = qsa(__branchScope, '[bf="${slot.slotId}"]')`);
|
|
20734
|
+
lines.push(`${indent}${DEDUP_STORE_DECL}`);
|
|
20670
20735
|
lines.push(`${indent}if (${varName}) {`);
|
|
20736
|
+
let ordinal = 0;
|
|
20671
20737
|
for (const attr of slot.attrs) {
|
|
20672
20738
|
lines.push(`${indent} __disposers.push(createDisposableEffect(() => {`);
|
|
20673
|
-
|
|
20739
|
+
if (attr.readsPreamble && mapPreambleWrapped) {
|
|
20740
|
+
lines.push(`${indent} ${mapPreambleWrapped}`);
|
|
20741
|
+
}
|
|
20742
|
+
for (const stmt of emitDedupedAttrUpdate(varName, attr.attrName, attr.wrappedExpression, attr.meta, ordinal++)) {
|
|
20674
20743
|
lines.push(`${indent} ${stmt}`);
|
|
20675
20744
|
}
|
|
20676
20745
|
lines.push(`${indent} }${profileBindingId(pc, slot.slotId)}))`);
|
|
@@ -20713,7 +20782,7 @@ function stringifyBranchInnerLoops(lines, plan, indent, pc) {
|
|
|
20713
20782
|
lines.push(`${indent} __bel${uid}.setAttribute('${keyAttrName2(inner.keyDepth)}', String(${inner.wrappedKey}))`);
|
|
20714
20783
|
}
|
|
20715
20784
|
if (inner.legacyComponents.length > 0 || inner.legacyEvents.length > 0) {
|
|
20716
|
-
emitComponentAndEventSetup(lines, `${indent} `, `__bel${uid}`, [...inner.legacyComponents], [...inner.legacyEvents], inner.outerLoopParam, inner.outerLoopParamBindings);
|
|
20785
|
+
emitComponentAndEventSetup(lines, `${indent} `, `__bel${uid}`, [...inner.legacyComponents], [...inner.legacyEvents], inner.outerLoopParam, inner.outerLoopParamBindings, false, inner.outerLoopIndex);
|
|
20717
20786
|
}
|
|
20718
20787
|
const conditionalTexts = inner.reactiveTexts.filter((t) => t.insideConditional);
|
|
20719
20788
|
const plainTexts = inner.reactiveTexts.filter((t) => !t.insideConditional);
|
|
@@ -20730,32 +20799,35 @@ function stringifyBranchInnerLoops(lines, plan, indent, pc) {
|
|
|
20730
20799
|
}
|
|
20731
20800
|
}
|
|
20732
20801
|
if (inner.nestedConditionals.length > 0) {
|
|
20733
|
-
stringifyLoopChildConditionals(lines, inner.nestedConditionals, `${indent} `, pc);
|
|
20802
|
+
stringifyLoopChildConditionals(lines, inner.nestedConditionals, `${indent} `, pc, undefined);
|
|
20734
20803
|
}
|
|
20735
20804
|
lines.push(`${indent} return __bel${uid}`);
|
|
20736
20805
|
lines.push(`${indent}}, '${inner.markerId}'${mapArrayKeyArgs(profileBindingId(pc, inner.slotId), !!inner.wrappedKey, inner.keyDepth)}) }`);
|
|
20737
20806
|
}
|
|
20738
20807
|
}
|
|
20739
|
-
function stringifyLoopChildConditionals(lines, conditionals, indent, pc) {
|
|
20808
|
+
function stringifyLoopChildConditionals(lines, conditionals, indent, pc, mapPreambleWrapped) {
|
|
20740
20809
|
for (const cond of conditionals) {
|
|
20741
|
-
stringifyLoopChildConditional(lines, cond, indent, pc);
|
|
20810
|
+
stringifyLoopChildConditional(lines, cond, indent, pc, mapPreambleWrapped);
|
|
20742
20811
|
}
|
|
20743
20812
|
}
|
|
20744
|
-
function
|
|
20813
|
+
function conditionGetterExpr(wrappedCondition, readsPreamble, mapPreambleWrapped) {
|
|
20814
|
+
return readsPreamble && mapPreambleWrapped ? `() => { ${mapPreambleWrapped}; return (${wrappedCondition}) }` : `() => ${wrappedCondition}`;
|
|
20815
|
+
}
|
|
20816
|
+
function stringifyLoopChildConditional(lines, cond, indent, pc, mapPreambleWrapped) {
|
|
20745
20817
|
const armIndent = `${indent} `;
|
|
20746
|
-
lines.push(`${indent}insert(${cond.scopeVar}, '${cond.slotId}',
|
|
20818
|
+
lines.push(`${indent}insert(${cond.scopeVar}, '${cond.slotId}', ${conditionGetterExpr(cond.wrappedCondition, cond.readsPreamble, mapPreambleWrapped)}, {`);
|
|
20747
20819
|
lines.push(`${indent} template: () => { const __slots = []; return { html: \`${cond.whenTrueTemplateHtml}\`, slots: __slots } },`);
|
|
20748
20820
|
lines.push(`${indent} bindEvents: (__branchScope, { isFirstRun: __bfFirstRun = false } = {}) => {`);
|
|
20749
|
-
stringifyLoopChildArm(lines, cond.whenTrueArm, armIndent, pc);
|
|
20821
|
+
stringifyLoopChildArm(lines, cond.whenTrueArm, armIndent, pc, mapPreambleWrapped);
|
|
20750
20822
|
lines.push(`${indent} }`);
|
|
20751
20823
|
lines.push(`${indent}}, {`);
|
|
20752
20824
|
lines.push(`${indent} template: () => { const __slots = []; return { html: \`${cond.whenFalseTemplateHtml}\`, slots: __slots } },`);
|
|
20753
20825
|
lines.push(`${indent} bindEvents: (__branchScope, { isFirstRun: __bfFirstRun = false } = {}) => {`);
|
|
20754
|
-
stringifyLoopChildArm(lines, cond.whenFalseArm, armIndent, pc);
|
|
20826
|
+
stringifyLoopChildArm(lines, cond.whenFalseArm, armIndent, pc, mapPreambleWrapped);
|
|
20755
20827
|
lines.push(`${indent} }`);
|
|
20756
20828
|
lines.push(`${indent}}${profileBindingId(pc, cond.slotId)})`);
|
|
20757
20829
|
}
|
|
20758
|
-
function stringifyLoopChildArm(lines, arm, armIndent, pc) {
|
|
20830
|
+
function stringifyLoopChildArm(lines, arm, armIndent, pc, mapPreambleWrapped) {
|
|
20759
20831
|
stringifyBranchEventBindings(lines, arm.events, armIndent);
|
|
20760
20832
|
stringifyBranchChildComponentInits(lines, arm.childComponents, armIndent);
|
|
20761
20833
|
stringifyBranchInnerLoops(lines, arm.innerLoops, armIndent, pc);
|
|
@@ -20763,10 +20835,10 @@ function stringifyLoopChildArm(lines, arm, armIndent, pc) {
|
|
|
20763
20835
|
if (!hasDisposables)
|
|
20764
20836
|
return;
|
|
20765
20837
|
lines.push(`${armIndent}const __disposers = []`);
|
|
20766
|
-
stringifyBranchReactiveAttrs(lines, arm.attrs, armIndent, pc);
|
|
20838
|
+
stringifyBranchReactiveAttrs(lines, arm.attrs, armIndent, pc, mapPreambleWrapped);
|
|
20767
20839
|
for (const cond of arm.nestedConditionals) {
|
|
20768
20840
|
lines.push(`${armIndent}__disposers.push(createDisposableEffect(() => {`);
|
|
20769
|
-
stringifyLoopChildConditional(lines, cond, `${armIndent} `, pc);
|
|
20841
|
+
stringifyLoopChildConditional(lines, cond, `${armIndent} `, pc, mapPreambleWrapped);
|
|
20770
20842
|
lines.push(`${armIndent}}))`);
|
|
20771
20843
|
}
|
|
20772
20844
|
if (arm.texts.length > 0) {
|
|
@@ -20805,13 +20877,15 @@ function emitAttrSlotsGranular(lines, indent, elVar, lookup, attrSlots, elementI
|
|
|
20805
20877
|
const varName = `__ra_${varSlotId(slot.slotId)}`;
|
|
20806
20878
|
const lookupExpr = attrLookupExpr(slot.slotId, varName, elVar, lookup, elementIndexBySlot);
|
|
20807
20879
|
lines.push(`${indent}{ const ${varName} = ${lookupExpr}`);
|
|
20880
|
+
lines.push(`${indent}${DEDUP_STORE_DECL}`);
|
|
20808
20881
|
lines.push(`${indent}if (${varName}) {`);
|
|
20882
|
+
let ordinal = 0;
|
|
20809
20883
|
for (const attr of slot.attrs) {
|
|
20810
20884
|
lines.push(`${indent} createEffect(() => {`);
|
|
20811
20885
|
if (attr.readsPreamble && mapPreambleWrapped) {
|
|
20812
20886
|
lines.push(`${indent} ${mapPreambleWrapped}`);
|
|
20813
20887
|
}
|
|
20814
|
-
for (const stmt of
|
|
20888
|
+
for (const stmt of emitDedupedAttrUpdate(varName, attr.attrName, attr.wrappedExpression, attr.meta, ordinal++)) {
|
|
20815
20889
|
lines.push(`${indent} ${stmt}`);
|
|
20816
20890
|
}
|
|
20817
20891
|
lines.push(`${indent} }${bindingBfId(slot.slotId)})`);
|
|
@@ -20847,6 +20921,8 @@ function emitConsolidatedRowEffect(lines, indent, elVar, lookup, attrSlots, oute
|
|
|
20847
20921
|
const varName = `__ra_${varSlotId(slot.slotId)}`;
|
|
20848
20922
|
lines.push(`${indent}const ${varName} = ${attrLookupExpr(slot.slotId, varName, elVar, lookup, elementIndexBySlot)}`);
|
|
20849
20923
|
}
|
|
20924
|
+
if (attrSlots.length > 0)
|
|
20925
|
+
lines.push(`${indent}${DEDUP_STORE_DECL}`);
|
|
20850
20926
|
const claimSlots = [
|
|
20851
20927
|
...outerTexts.map((t) => ({ id: t.slotId, kind: "text", path: [], pathExpr: textClaimPathExprs?.get(t.slotId) })),
|
|
20852
20928
|
...preambleRegions.map((r) => ({ id: r.slotId, kind: "markup", path: [] }))
|
|
@@ -20864,15 +20940,14 @@ function emitConsolidatedRowEffect(lines, indent, elVar, lookup, attrSlots, oute
|
|
|
20864
20940
|
if (mapPreambleWrapped && (preambleRegions.length > 0 || attrsReadPreamble(attrSlots))) {
|
|
20865
20941
|
lines.push(`${indent} ${mapPreambleWrapped}`);
|
|
20866
20942
|
}
|
|
20943
|
+
let ordinal = 0;
|
|
20867
20944
|
for (const slot of attrSlots) {
|
|
20868
20945
|
const varName = `__ra_${varSlotId(slot.slotId)}`;
|
|
20869
20946
|
lines.push(`${indent} if (${varName}) {`);
|
|
20870
20947
|
for (const attr of slot.attrs) {
|
|
20871
|
-
|
|
20872
|
-
|
|
20873
|
-
lines.push(`${indent} ${stmt}`);
|
|
20948
|
+
for (const stmt of emitDedupedAttrUpdate(varName, attr.attrName, attr.wrappedExpression, attr.meta, ordinal++)) {
|
|
20949
|
+
lines.push(`${indent} ${stmt}`);
|
|
20874
20950
|
}
|
|
20875
|
-
lines.push(`${indent} }`);
|
|
20876
20951
|
}
|
|
20877
20952
|
lines.push(`${indent} }`);
|
|
20878
20953
|
}
|
|
@@ -20901,16 +20976,16 @@ function emitOuterTexts(lines, indent, elVar, texts, bindingBfId, textClaimPathE
|
|
|
20901
20976
|
}
|
|
20902
20977
|
function emitOuterConditional(lines, indent, elVar, cond, pc, mapPreambleWrapped) {
|
|
20903
20978
|
const armIndent = `${indent} `;
|
|
20904
|
-
const conditionGetter = cond.readsPreamble
|
|
20979
|
+
const conditionGetter = conditionGetterExpr(cond.wrappedCondition, cond.readsPreamble, mapPreambleWrapped);
|
|
20905
20980
|
lines.push(`${indent}insert(${elVar}, '${cond.slotId}', ${conditionGetter}, {`);
|
|
20906
20981
|
lines.push(`${indent} template: () => { const __slots = []; return { html: \`${cond.whenTrueTemplateHtml}\`, slots: __slots } },`);
|
|
20907
20982
|
lines.push(`${indent} bindEvents: (__branchScope, { isFirstRun: __bfFirstRun = false } = {}) => {`);
|
|
20908
|
-
stringifyLoopChildArm(lines, cond.whenTrueArm, armIndent, pc);
|
|
20983
|
+
stringifyLoopChildArm(lines, cond.whenTrueArm, armIndent, pc, mapPreambleWrapped);
|
|
20909
20984
|
lines.push(`${indent} }`);
|
|
20910
20985
|
lines.push(`${indent}}, {`);
|
|
20911
20986
|
lines.push(`${indent} template: () => { const __slots = []; return { html: \`${cond.whenFalseTemplateHtml}\`, slots: __slots } },`);
|
|
20912
20987
|
lines.push(`${indent} bindEvents: (__branchScope, { isFirstRun: __bfFirstRun = false } = {}) => {`);
|
|
20913
|
-
stringifyLoopChildArm(lines, cond.whenFalseArm, armIndent, pc);
|
|
20988
|
+
stringifyLoopChildArm(lines, cond.whenFalseArm, armIndent, pc, mapPreambleWrapped);
|
|
20914
20989
|
lines.push(`${indent} }`);
|
|
20915
20990
|
lines.push(`${indent}}${profileBindingId(pc, cond.slotId)})`);
|
|
20916
20991
|
}
|
|
@@ -21179,24 +21254,14 @@ function emitConditional(lines, ind, mid, c, mode) {
|
|
|
21179
21254
|
lines.push(`${ind} __l[${c.ordinal}] = __x`);
|
|
21180
21255
|
lines.push(`${ind}} }`);
|
|
21181
21256
|
}
|
|
21182
|
-
function dedupGuard(ordinal) {
|
|
21183
|
-
return `!(${ordinal} in __l) || !Object.is(__l[${ordinal}], __x)`;
|
|
21184
|
-
}
|
|
21185
21257
|
function emitAttrBinding(lines, ind, a, mode) {
|
|
21186
21258
|
const target = mode === "create" ? `__r[${a.refIndex}]` : elementAccess(a);
|
|
21259
|
+
const guard = mode === "create" ? null : mode === "item" ? dedupGuard(a.ordinal) : `__seed ? (${seedDiffersExpr("__t", a)}) : (${dedupGuard(a.ordinal)})`;
|
|
21187
21260
|
lines.push(`${ind}{ const __t = ${target}`);
|
|
21188
21261
|
lines.push(`${ind}if (__t) {`);
|
|
21189
|
-
|
|
21190
|
-
|
|
21191
|
-
|
|
21192
|
-
if (guard)
|
|
21193
|
-
lines.push(`${ind} if (${guard}) {`);
|
|
21194
|
-
for (const stmt of emitAttrUpdate("__t", a.attrName, "__x", a.meta)) {
|
|
21195
|
-
lines.push(`${writeIndent}${stmt}`);
|
|
21196
|
-
}
|
|
21197
|
-
if (guard)
|
|
21198
|
-
lines.push(`${ind} }`);
|
|
21199
|
-
lines.push(`${ind} __l[${a.ordinal}] = __x`);
|
|
21262
|
+
for (const stmt of emitDedupedAttrUpdate("__t", a.attrName, a.wrappedExpression, a.meta, a.ordinal, guard)) {
|
|
21263
|
+
lines.push(`${ind} ${stmt}`);
|
|
21264
|
+
}
|
|
21200
21265
|
lines.push(`${ind}} }`);
|
|
21201
21266
|
}
|
|
21202
21267
|
function emitTextBinding(lines, ind, t, doorExpr, mode, rwDoor) {
|
|
@@ -21486,13 +21551,16 @@ function stringifyStaticLoop(lines, plan) {
|
|
|
21486
21551
|
lines.push(` }`);
|
|
21487
21552
|
}
|
|
21488
21553
|
lines.push(` if (__iterEl) {`);
|
|
21554
|
+
if (attrsBySlot.length > 0)
|
|
21555
|
+
lines.push(` ${DEDUP_STORE_DECL}`);
|
|
21556
|
+
let ordinal = 0;
|
|
21489
21557
|
for (const [slotId, attrs] of attrsBySlot) {
|
|
21490
21558
|
const varName = `__t_${varSlotId(slotId)}`;
|
|
21491
21559
|
lines.push(` const ${varName} = qsa(__iterEl, '[bf="${slotId}"]')`);
|
|
21492
21560
|
lines.push(` if (${varName}) {`);
|
|
21493
21561
|
for (const attr of attrs) {
|
|
21494
21562
|
lines.push(` createEffect(() => {`);
|
|
21495
|
-
for (const stmt of
|
|
21563
|
+
for (const stmt of emitDedupedAttrUpdate(varName, attr.attrName, attr.expression, attr, ordinal++)) {
|
|
21496
21564
|
lines.push(` ${stmt}`);
|
|
21497
21565
|
}
|
|
21498
21566
|
lines.push(` }${profileBindingId(pc, slotId)})`);
|
|
@@ -21517,18 +21585,12 @@ function stringifyStaticLoop(lines, plan) {
|
|
|
21517
21585
|
// ../jsx/src/ir-to-client-js/control-flow/stringify/inner-loop.ts
|
|
21518
21586
|
function stringifyInnerLoops(lines, plan, indent, pc) {
|
|
21519
21587
|
for (const inner of plan) {
|
|
21520
|
-
|
|
21521
|
-
emitReactive(lines, inner, indent, pc);
|
|
21522
|
-
} else {
|
|
21523
|
-
emitStatic(lines, inner, indent, pc);
|
|
21524
|
-
}
|
|
21588
|
+
emitReactive(lines, inner, indent, pc);
|
|
21525
21589
|
}
|
|
21526
21590
|
}
|
|
21527
21591
|
function emitReactive(lines, inner, indent, pc) {
|
|
21528
21592
|
const uid = inner.uidSuffix;
|
|
21529
21593
|
const emit = inner.emit;
|
|
21530
|
-
if (emit.mode !== "reactive")
|
|
21531
|
-
return;
|
|
21532
21594
|
lines.push(`${indent}// Reactive inner loop: ${inner.arraySrc}`);
|
|
21533
21595
|
lines.push(`${indent}{ const __ic${uid} = ${inner.containerExpr}`);
|
|
21534
21596
|
lines.push(`${indent}if (__ic${uid}) mapArray(() => ${inner.arrayExpr} || [], __ic${uid}, ${emit.keyFn}, (${emit.paramHead}, __innerIdx${uid}, __existing) => {`);
|
|
@@ -21554,7 +21616,7 @@ function emitReactive(lines, inner, indent, pc) {
|
|
|
21554
21616
|
lines.push(`${indent} __innerEl${uid}.setAttribute('${keyAttrName2(inner.keyDepth)}', String(${emit.wrappedKey}))`);
|
|
21555
21617
|
}
|
|
21556
21618
|
if (emit.components.length > 0 || emit.events.length > 0) {
|
|
21557
|
-
emitComponentAndEventSetup(lines, `${indent} `, `__innerEl${uid}`, [...emit.components], [...emit.events], inner.outerLoopParam, inner.outerLoopParamBindings);
|
|
21619
|
+
emitComponentAndEventSetup(lines, `${indent} `, `__innerEl${uid}`, [...emit.components], [...emit.events], inner.outerLoopParam, inner.outerLoopParamBindings, false, inner.outerLoopIndex);
|
|
21558
21620
|
}
|
|
21559
21621
|
if (inner.childLevels.length > 0) {
|
|
21560
21622
|
stringifyInnerLoops(lines, inner.childLevels, `${indent} `, pc);
|
|
@@ -21573,17 +21635,20 @@ function emitReactive(lines, inner, indent, pc) {
|
|
|
21573
21635
|
lines.push(`${indent} createEffect(() => { ${writer}('${text.slotId}', String(${text.wrappedExpression})) }${profileBindingId(pc, text.slotId)})`);
|
|
21574
21636
|
}
|
|
21575
21637
|
}
|
|
21638
|
+
if (emit.reactiveAttrs.length > 0)
|
|
21639
|
+
lines.push(`${indent} ${DEDUP_STORE_DECL}`);
|
|
21640
|
+
let attrOrdinal = 0;
|
|
21576
21641
|
for (const attr of emit.reactiveAttrs) {
|
|
21577
21642
|
const targetVar = `__ta_${attr.slotId.replace(/[^a-zA-Z0-9]/g, "_")}`;
|
|
21578
21643
|
lines.push(`${indent} { const ${targetVar} = qsa(__innerEl${uid}, '[bf="${attr.slotId}"]')`);
|
|
21579
21644
|
lines.push(`${indent} if (${targetVar}) createEffect(() => {`);
|
|
21580
|
-
for (const stmt of
|
|
21645
|
+
for (const stmt of emitDedupedAttrUpdate(targetVar, attr.attrName, attr.wrappedExpression, attr.meta, attrOrdinal++)) {
|
|
21581
21646
|
lines.push(`${indent} ${stmt}`);
|
|
21582
21647
|
}
|
|
21583
21648
|
lines.push(`${indent} }${profileBindingId(pc, attr.slotId)}) }`);
|
|
21584
21649
|
}
|
|
21585
21650
|
if (emit.conditionals.length > 0) {
|
|
21586
|
-
stringifyLoopChildConditionals(lines, emit.conditionals, `${indent} `, pc);
|
|
21651
|
+
stringifyLoopChildConditionals(lines, emit.conditionals, `${indent} `, pc, undefined);
|
|
21587
21652
|
}
|
|
21588
21653
|
emitLoopChildRefs(lines, emit.childRefs, {
|
|
21589
21654
|
indent: `${indent} `,
|
|
@@ -21593,33 +21658,6 @@ function emitReactive(lines, inner, indent, pc) {
|
|
|
21593
21658
|
lines.push(`${indent} return __innerEl${uid}`);
|
|
21594
21659
|
lines.push(`${indent}}, '${inner.markerId}'${mapArrayKeyArgs(profileBindingId(pc, inner.slotId), !!emit.wrappedKey, inner.keyDepth)}) }`);
|
|
21595
21660
|
}
|
|
21596
|
-
function emitStatic(lines, inner, indent, pc) {
|
|
21597
|
-
const uid = inner.uidSuffix;
|
|
21598
|
-
const emit = inner.emit;
|
|
21599
|
-
if (emit.mode !== "static")
|
|
21600
|
-
return;
|
|
21601
|
-
lines.push(`${indent}// Initialize ${inner.arraySrc} loop components and events`);
|
|
21602
|
-
lines.push(`${indent}{ const __ic${uid} = ${inner.containerExpr}`);
|
|
21603
|
-
lines.push(`${indent}if (__ic${uid} && ${inner.arrayExpr}) ${inner.arrayExpr}.forEach((${inner.param}, __innerIdx${uid}) => {`);
|
|
21604
|
-
lines.push(`${indent} const __innerEl${uid} = __ic${uid}.children[__innerIdx${uid}]`);
|
|
21605
|
-
lines.push(`${indent} if (!__innerEl${uid}) return`);
|
|
21606
|
-
for (const stmt of emit.preludeStatements) {
|
|
21607
|
-
lines.push(`${indent} ${stmt}`);
|
|
21608
|
-
}
|
|
21609
|
-
if (emit.rawKey) {
|
|
21610
|
-
lines.push(`${indent} __innerEl${uid}.setAttribute('${keyAttrName2(inner.keyDepth)}', String(${emit.rawKey}))`);
|
|
21611
|
-
}
|
|
21612
|
-
emitComponentAndEventSetup(lines, `${indent} `, `__innerEl${uid}`, [...emit.components], [...emit.events], inner.outerLoopParam, inner.outerLoopParamBindings);
|
|
21613
|
-
if (inner.childLevels.length > 0) {
|
|
21614
|
-
stringifyInnerLoops(lines, inner.childLevels, `${indent} `, pc);
|
|
21615
|
-
}
|
|
21616
|
-
emitLoopChildRefs(lines, emit.childRefs, {
|
|
21617
|
-
indent: `${indent} `,
|
|
21618
|
-
elVar: `__innerEl${uid}`,
|
|
21619
|
-
bodyIsMultiRoot: false
|
|
21620
|
-
});
|
|
21621
|
-
lines.push(`${indent}}) }`);
|
|
21622
|
-
}
|
|
21623
21661
|
|
|
21624
21662
|
// ../jsx/src/ir-to-client-js/control-flow/stringify/composite-loop.ts
|
|
21625
21663
|
function stringifyCompositeLoop(lines, plan) {
|
|
@@ -22048,10 +22086,12 @@ function emitArmBody(lines, body, mode, indent, profileComponentName) {
|
|
|
22048
22086
|
const v = varSlotId(slotId);
|
|
22049
22087
|
const elVar = `__ra_${v}`;
|
|
22050
22088
|
lines.push(`${indent}{ const ${elVar} = qsa(__branchScope, '[bf="${slotId}"]')`);
|
|
22089
|
+
lines.push(`${indent}${DEDUP_STORE_DECL}`);
|
|
22051
22090
|
lines.push(`${indent}if (${elVar}) {`);
|
|
22091
|
+
let ordinal = 0;
|
|
22052
22092
|
for (const attr of attrs) {
|
|
22053
22093
|
lines.push(`${indent} __disposers.push(createDisposableEffect(() => {`);
|
|
22054
|
-
for (const stmt of
|
|
22094
|
+
for (const stmt of emitDedupedAttrUpdate(elVar, attr.attrName, attr.expression, attr, ordinal++)) {
|
|
22055
22095
|
lines.push(`${indent} ${stmt}`);
|
|
22056
22096
|
}
|
|
22057
22097
|
lines.push(`${indent} }${bindingBfId(slotId)}))`);
|