@barefootjs/jsx 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/builtin-lowering-plugins.d.ts.map +1 -1
- package/dist/date-lowering.d.ts +33 -0
- package/dist/date-lowering.d.ts.map +1 -0
- package/dist/index.js +441 -285
- package/dist/ir-to-client-js/emit-reactive.d.ts.map +1 -1
- package/dist/ir-to-client-js/imports.d.ts +2 -2
- package/dist/ir-to-client-js/imports.d.ts.map +1 -1
- package/dist/ir-to-client-js/types.d.ts +14 -1
- package/dist/ir-to-client-js/types.d.ts.map +1 -1
- package/dist/jsx-to-ir.d.ts.map +1 -1
- package/dist/rich-type-evidence.d.ts +11 -0
- package/dist/rich-type-evidence.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/date-lowering.test.ts +232 -0
- package/src/__tests__/rich-type-method-refusal.test.ts +21 -1
- package/src/analyzer.ts +19 -2
- package/src/builtin-lowering-plugins.ts +2 -1
- package/src/date-lowering.ts +117 -0
- package/src/ir-to-client-js/emit-reactive.ts +103 -2
- package/src/ir-to-client-js/imports.ts +4 -0
- package/src/ir-to-client-js/index.ts +2 -0
- package/src/ir-to-client-js/types.ts +15 -0
- package/src/jsx-to-ir.ts +128 -3
- package/src/rich-type-evidence.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -5302,6 +5302,135 @@ function internalInvariant(cond, message) {
|
|
|
5302
5302
|
}
|
|
5303
5303
|
}
|
|
5304
5304
|
|
|
5305
|
+
// src/rich-type-evidence.ts
|
|
5306
|
+
var HOST_RICH_TYPE_NAMES = new Set([
|
|
5307
|
+
"Date",
|
|
5308
|
+
"Map",
|
|
5309
|
+
"Set",
|
|
5310
|
+
"WeakMap",
|
|
5311
|
+
"WeakSet",
|
|
5312
|
+
"URL",
|
|
5313
|
+
"URLSearchParams",
|
|
5314
|
+
"RegExp",
|
|
5315
|
+
"Promise",
|
|
5316
|
+
"Error",
|
|
5317
|
+
"Symbol",
|
|
5318
|
+
"BigInt",
|
|
5319
|
+
"Function"
|
|
5320
|
+
]);
|
|
5321
|
+
function baseTypeName(raw) {
|
|
5322
|
+
const idx = raw.indexOf("<");
|
|
5323
|
+
return (idx === -1 ? raw : raw.slice(0, idx)).trim();
|
|
5324
|
+
}
|
|
5325
|
+
function isNullishArm(t) {
|
|
5326
|
+
if (t.kind === "primitive" && (t.primitive === "null" || t.primitive === "undefined"))
|
|
5327
|
+
return true;
|
|
5328
|
+
return t.kind === "unknown" && (t.raw === "null" || t.raw === "undefined");
|
|
5329
|
+
}
|
|
5330
|
+
function stripUnion(type) {
|
|
5331
|
+
if (!type || type.kind !== "union" || !type.unionTypes)
|
|
5332
|
+
return type;
|
|
5333
|
+
const nonNullish = type.unionTypes.filter((t) => !isNullishArm(t));
|
|
5334
|
+
return nonNullish.length === 1 ? stripUnion(nonNullish[0]) : type;
|
|
5335
|
+
}
|
|
5336
|
+
function derefNamedType(type, meta) {
|
|
5337
|
+
if (type.kind !== "interface")
|
|
5338
|
+
return type;
|
|
5339
|
+
if (type.properties && type.properties.length > 0)
|
|
5340
|
+
return type;
|
|
5341
|
+
const name = baseTypeName(type.raw);
|
|
5342
|
+
const def = meta.typeDefinitions.find((d) => d.name === name);
|
|
5343
|
+
if (!def?.properties)
|
|
5344
|
+
return type;
|
|
5345
|
+
return { ...type, properties: def.properties };
|
|
5346
|
+
}
|
|
5347
|
+
function lookupProperty(objType, propName, meta) {
|
|
5348
|
+
const stripped = stripUnion(objType);
|
|
5349
|
+
if (!stripped)
|
|
5350
|
+
return null;
|
|
5351
|
+
const deref = derefNamedType(stripped, meta);
|
|
5352
|
+
const prop = deref.properties?.find((p) => p.name === propName);
|
|
5353
|
+
return prop ? stripUnion(prop.type) : null;
|
|
5354
|
+
}
|
|
5355
|
+
function resolveReceiverType(expr, meta, bindings) {
|
|
5356
|
+
if (expr.kind === "identifier") {
|
|
5357
|
+
if (bindings.has(expr.name))
|
|
5358
|
+
return stripUnion(bindings.get(expr.name) ?? null);
|
|
5359
|
+
if (meta.propsObjectName !== null) {
|
|
5360
|
+
return expr.name === meta.propsObjectName ? stripUnion(meta.propsType) : null;
|
|
5361
|
+
}
|
|
5362
|
+
const param = meta.propsParams.find((p) => p.name === expr.name && !p.isRest);
|
|
5363
|
+
if (!param)
|
|
5364
|
+
return null;
|
|
5365
|
+
return lookupProperty(meta.propsType, param.sourceName ?? param.name, meta);
|
|
5366
|
+
}
|
|
5367
|
+
if (expr.kind === "member" && !expr.computed) {
|
|
5368
|
+
const objType = resolveReceiverType(expr.object, meta, bindings);
|
|
5369
|
+
return lookupProperty(objType, expr.property, meta);
|
|
5370
|
+
}
|
|
5371
|
+
return null;
|
|
5372
|
+
}
|
|
5373
|
+
|
|
5374
|
+
// src/date-lowering.ts
|
|
5375
|
+
var CATALOGUED_RICH_TYPE_NAMES = new Set(["Date"]);
|
|
5376
|
+
var DATE_METHODS = new Set([
|
|
5377
|
+
"getUTCFullYear",
|
|
5378
|
+
"getUTCMonth",
|
|
5379
|
+
"getUTCDate",
|
|
5380
|
+
"getUTCHours",
|
|
5381
|
+
"getUTCMinutes",
|
|
5382
|
+
"getUTCSeconds",
|
|
5383
|
+
"getTime",
|
|
5384
|
+
"toISOString"
|
|
5385
|
+
]);
|
|
5386
|
+
var EMPTY_BINDINGS = new Map;
|
|
5387
|
+
function typeReachesDate(type, meta, seen) {
|
|
5388
|
+
const stripped = stripUnion(type);
|
|
5389
|
+
if (!stripped)
|
|
5390
|
+
return false;
|
|
5391
|
+
if (stripped.kind === "interface") {
|
|
5392
|
+
const name = baseTypeName(stripped.raw);
|
|
5393
|
+
if (name === "Date")
|
|
5394
|
+
return true;
|
|
5395
|
+
if (seen.has(name))
|
|
5396
|
+
return false;
|
|
5397
|
+
seen.add(name);
|
|
5398
|
+
} else if (stripped.kind !== "object") {
|
|
5399
|
+
return false;
|
|
5400
|
+
}
|
|
5401
|
+
const deref = derefNamedType(stripped, meta);
|
|
5402
|
+
if (!deref.properties)
|
|
5403
|
+
return false;
|
|
5404
|
+
return deref.properties.some((p) => typeReachesDate(p.type, meta, seen));
|
|
5405
|
+
}
|
|
5406
|
+
function matchDateCall(callee, args, metadata) {
|
|
5407
|
+
if (callee.kind !== "member" || callee.computed)
|
|
5408
|
+
return null;
|
|
5409
|
+
if (args.length !== 0 || !DATE_METHODS.has(callee.property))
|
|
5410
|
+
return null;
|
|
5411
|
+
const receiverType = resolveReceiverType(callee.object, metadata, EMPTY_BINDINGS);
|
|
5412
|
+
if (!receiverType || receiverType.kind !== "interface")
|
|
5413
|
+
return null;
|
|
5414
|
+
const typeName = baseTypeName(receiverType.raw);
|
|
5415
|
+
if (typeName !== "Date")
|
|
5416
|
+
return null;
|
|
5417
|
+
if (metadata.typeDefinitions.some((d) => d.name === typeName))
|
|
5418
|
+
return null;
|
|
5419
|
+
return {
|
|
5420
|
+
kind: "helper-call",
|
|
5421
|
+
helper: "date",
|
|
5422
|
+
args: [callee.object, { kind: "literal", value: callee.property, literalType: "string" }]
|
|
5423
|
+
};
|
|
5424
|
+
}
|
|
5425
|
+
var datePlugin = {
|
|
5426
|
+
name: "date",
|
|
5427
|
+
prepare(metadata) {
|
|
5428
|
+
if (!metadata.propsType || !typeReachesDate(metadata.propsType, metadata, new Set))
|
|
5429
|
+
return null;
|
|
5430
|
+
return (callee, args) => matchDateCall(callee, args, metadata);
|
|
5431
|
+
}
|
|
5432
|
+
};
|
|
5433
|
+
|
|
5305
5434
|
// src/analyzer.ts
|
|
5306
5435
|
var { default: fs} = (() => ({}));
|
|
5307
5436
|
var REACTIVE_BRAND_PACKAGES = [
|
|
@@ -7150,7 +7279,7 @@ function collectKeysFromMembers(members, ctx) {
|
|
|
7150
7279
|
return keys;
|
|
7151
7280
|
}
|
|
7152
7281
|
function collectMemberTypes(typeNode, ctx) {
|
|
7153
|
-
const isResolvablePrimitive = (info) => info.kind === "primitive" && (info.primitive === "string" || info.primitive === "number" || info.primitive === "boolean");
|
|
7282
|
+
const isResolvablePrimitive = (info) => info.kind === "primitive" && (info.primitive === "string" || info.primitive === "number" || info.primitive === "boolean") || info.kind === "interface" && CATALOGUED_RICH_TYPE_NAMES.has(baseTypeName(info.raw));
|
|
7154
7283
|
const fromMembers = (members) => {
|
|
7155
7284
|
const map = new Map;
|
|
7156
7285
|
for (const member of members) {
|
|
@@ -8387,18 +8516,60 @@ function exprHasFunctionCalls(expr) {
|
|
|
8387
8516
|
visit2(expr);
|
|
8388
8517
|
return found;
|
|
8389
8518
|
}
|
|
8519
|
+
function getDateLoweringMatcher(ctx) {
|
|
8520
|
+
if (ctx._dateLoweringMatcher === undefined) {
|
|
8521
|
+
const a = ctx.analyzer;
|
|
8522
|
+
const metadataSlice = {
|
|
8523
|
+
propsType: a.propsType,
|
|
8524
|
+
propsObjectName: a.propsObjectName,
|
|
8525
|
+
propsParams: a.propsParams,
|
|
8526
|
+
typeDefinitions: a.typeDefinitions
|
|
8527
|
+
};
|
|
8528
|
+
ctx._dateLoweringMatcher = datePlugin.prepare(metadataSlice);
|
|
8529
|
+
}
|
|
8530
|
+
return ctx._dateLoweringMatcher;
|
|
8531
|
+
}
|
|
8532
|
+
function lowerDateCalls(text, expr, ctx) {
|
|
8533
|
+
const matcher = getDateLoweringMatcher(ctx);
|
|
8534
|
+
if (!matcher)
|
|
8535
|
+
return text;
|
|
8536
|
+
const candidates = [];
|
|
8537
|
+
function visit2(n) {
|
|
8538
|
+
if (ts11.isCallExpression(n) && n.arguments.length === 0 && ts11.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
|
|
8539
|
+
candidates.push(n);
|
|
8540
|
+
}
|
|
8541
|
+
ts11.forEachChild(n, visit2);
|
|
8542
|
+
}
|
|
8543
|
+
visit2(expr);
|
|
8544
|
+
if (candidates.length === 0)
|
|
8545
|
+
return text;
|
|
8546
|
+
const { protect, restore } = createTemplateAwareStringProtector();
|
|
8547
|
+
let result = protect(text);
|
|
8548
|
+
for (const call of candidates) {
|
|
8549
|
+
const propAccess = call.expression;
|
|
8550
|
+
const node = matcher(tsNodeToParsedExpr(propAccess), []);
|
|
8551
|
+
if (!node || node.kind !== "helper-call" || node.helper !== "date")
|
|
8552
|
+
continue;
|
|
8553
|
+
const op = propAccess.name.text;
|
|
8554
|
+
const receiverText = ctx.getJS(propAccess.expression);
|
|
8555
|
+
const matchText = ctx.getJS(call);
|
|
8556
|
+
result = result.replace(matchText, () => `date(${receiverText}, "${op}")`);
|
|
8557
|
+
}
|
|
8558
|
+
return restore(result);
|
|
8559
|
+
}
|
|
8390
8560
|
function rewriteBarePropRefs2(text, expr, ctx) {
|
|
8561
|
+
const dateLowered = lowerDateCalls(text, expr, ctx);
|
|
8391
8562
|
let propNames = getDestructuredPropNames(ctx);
|
|
8392
8563
|
if (!propNames)
|
|
8393
|
-
return;
|
|
8564
|
+
return dateLowered === text ? undefined : dateLowered;
|
|
8394
8565
|
if (ctx.loopParams.size > 0) {
|
|
8395
8566
|
const filtered = new Set([...propNames].filter((n) => !ctx.loopParams.has(n)));
|
|
8396
8567
|
if (filtered.size === 0)
|
|
8397
|
-
return;
|
|
8568
|
+
return dateLowered === text ? undefined : dateLowered;
|
|
8398
8569
|
propNames = filtered;
|
|
8399
8570
|
}
|
|
8400
8571
|
const extraPropRefs = collectBranchLocalPropRefsViaSubstitution(expr, ctx);
|
|
8401
|
-
return rewriteBarePropRefs(
|
|
8572
|
+
return rewriteBarePropRefs(dateLowered, expr, propNames, extraPropRefs);
|
|
8402
8573
|
}
|
|
8403
8574
|
function collectBranchLocalPropRefsViaSubstitution(node, ctx) {
|
|
8404
8575
|
const propDepsMap = ctx._branchScopePropDeps;
|
|
@@ -13232,7 +13403,8 @@ var RUNTIME_IMPORT_CANDIDATES = [
|
|
|
13232
13403
|
"__bfText",
|
|
13233
13404
|
"tAfter",
|
|
13234
13405
|
"beginTurn",
|
|
13235
|
-
"endTurn"
|
|
13406
|
+
"endTurn",
|
|
13407
|
+
"date"
|
|
13236
13408
|
];
|
|
13237
13409
|
var RUNTIME_MODULE = "@barefootjs/client/runtime";
|
|
13238
13410
|
var IMPORT_PLACEHOLDER = "/* __BAREFOOTJS_DOM_IMPORTS__ */";
|
|
@@ -16327,6 +16499,7 @@ function buildArmBody(branch, options) {
|
|
|
16327
16499
|
}
|
|
16328
16500
|
|
|
16329
16501
|
// src/ir-to-client-js/emit-reactive.ts
|
|
16502
|
+
import ts14 from "typescript";
|
|
16330
16503
|
function bindingIdArg(ctx, slotId) {
|
|
16331
16504
|
if (!ctx.profile || !slotId)
|
|
16332
16505
|
return "";
|
|
@@ -16386,7 +16559,56 @@ function rewriteDestructuredPropsInExpr(expr, ctx) {
|
|
|
16386
16559
|
}
|
|
16387
16560
|
return restore(result);
|
|
16388
16561
|
}
|
|
16562
|
+
function getReactiveDateLoweringMatcher(ctx) {
|
|
16563
|
+
if (!ctx.propsType)
|
|
16564
|
+
return null;
|
|
16565
|
+
const metadataSlice = {
|
|
16566
|
+
propsType: ctx.propsType,
|
|
16567
|
+
propsObjectName: ctx.propsObjectName,
|
|
16568
|
+
propsParams: ctx.propsParams,
|
|
16569
|
+
typeDefinitions: ctx.typeDefinitions ?? []
|
|
16570
|
+
};
|
|
16571
|
+
return datePlugin.prepare(metadataSlice);
|
|
16572
|
+
}
|
|
16573
|
+
function lowerDateCallsInReactiveExpr(expr, matcher) {
|
|
16574
|
+
if (!matcher)
|
|
16575
|
+
return expr;
|
|
16576
|
+
let sourceFile;
|
|
16577
|
+
try {
|
|
16578
|
+
sourceFile = ts14.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts14.ScriptTarget.Latest, true, ts14.ScriptKind.TS);
|
|
16579
|
+
} catch {
|
|
16580
|
+
return expr;
|
|
16581
|
+
}
|
|
16582
|
+
const stmt = sourceFile.statements[0];
|
|
16583
|
+
if (!stmt || !ts14.isExpressionStatement(stmt))
|
|
16584
|
+
return expr;
|
|
16585
|
+
const root = ts14.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
16586
|
+
const candidates = [];
|
|
16587
|
+
const visit3 = (n) => {
|
|
16588
|
+
if (ts14.isCallExpression(n) && n.arguments.length === 0 && ts14.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
|
|
16589
|
+
candidates.push(n);
|
|
16590
|
+
}
|
|
16591
|
+
ts14.forEachChild(n, visit3);
|
|
16592
|
+
};
|
|
16593
|
+
visit3(root);
|
|
16594
|
+
if (candidates.length === 0)
|
|
16595
|
+
return expr;
|
|
16596
|
+
const { protect, restore } = createTemplateAwareStringProtector();
|
|
16597
|
+
let result = protect(expr);
|
|
16598
|
+
for (const call of candidates) {
|
|
16599
|
+
const propAccess = call.expression;
|
|
16600
|
+
const node = matcher(tsNodeToParsedExpr(propAccess), []);
|
|
16601
|
+
if (!node || node.kind !== "helper-call" || node.helper !== "date")
|
|
16602
|
+
continue;
|
|
16603
|
+
const op = propAccess.name.text;
|
|
16604
|
+
const receiverText = propAccess.expression.getText(sourceFile);
|
|
16605
|
+
const matchText = call.getText(sourceFile);
|
|
16606
|
+
result = result.replace(matchText, () => `date(${receiverText}, "${op}")`);
|
|
16607
|
+
}
|
|
16608
|
+
return restore(result);
|
|
16609
|
+
}
|
|
16389
16610
|
function emitDynamicTextUpdates(lines, ctx) {
|
|
16611
|
+
const dateLoweringMatcher = getReactiveDateLoweringMatcher(ctx);
|
|
16390
16612
|
const byExpression = new Map;
|
|
16391
16613
|
for (const elem of ctx.dynamicElements) {
|
|
16392
16614
|
const key = elem.expression;
|
|
@@ -16395,7 +16617,8 @@ function emitDynamicTextUpdates(lines, ctx) {
|
|
|
16395
16617
|
}
|
|
16396
16618
|
byExpression.get(key).push(elem);
|
|
16397
16619
|
}
|
|
16398
|
-
for (const [
|
|
16620
|
+
for (const [rawExpr, elems] of byExpression) {
|
|
16621
|
+
const expr = lowerDateCallsInReactiveExpr(rawExpr, dateLoweringMatcher);
|
|
16399
16622
|
const conditionalElems = elems.filter((e) => e.insideConditional);
|
|
16400
16623
|
const normalElems = elems.filter((e) => !e.insideConditional);
|
|
16401
16624
|
if (normalElems.length > 0 || conditionalElems.length > 0) {
|
|
@@ -17895,20 +18118,20 @@ var PHASES = [
|
|
|
17895
18118
|
];
|
|
17896
18119
|
|
|
17897
18120
|
// src/ir-to-client-js/rewrite-props-object.ts
|
|
17898
|
-
import
|
|
18121
|
+
import ts15 from "typescript";
|
|
17899
18122
|
function rewritePropsObjectRef(code, propsObjectName) {
|
|
17900
18123
|
const srcPropsName = propsObjectName ?? "props";
|
|
17901
18124
|
if (srcPropsName === PROPS_PARAM)
|
|
17902
18125
|
return code;
|
|
17903
18126
|
if (!new RegExp(`\\b${srcPropsName}\\b`).test(code))
|
|
17904
18127
|
return code;
|
|
17905
|
-
const sourceFile =
|
|
18128
|
+
const sourceFile = ts15.createSourceFile("init-body.ts", code, ts15.ScriptTarget.Latest, true, ts15.ScriptKind.TS);
|
|
17906
18129
|
const spans = [];
|
|
17907
18130
|
function visit3(node) {
|
|
17908
|
-
if (
|
|
18131
|
+
if (ts15.isIdentifier(node) && node.text === srcPropsName && shouldRewrite(node)) {
|
|
17909
18132
|
spans.push([node.getStart(sourceFile), node.getEnd()]);
|
|
17910
18133
|
}
|
|
17911
|
-
|
|
18134
|
+
ts15.forEachChild(node, visit3);
|
|
17912
18135
|
}
|
|
17913
18136
|
visit3(sourceFile);
|
|
17914
18137
|
if (spans.length === 0)
|
|
@@ -17924,17 +18147,17 @@ function shouldRewrite(node) {
|
|
|
17924
18147
|
const parent = node.parent;
|
|
17925
18148
|
if (!parent)
|
|
17926
18149
|
return true;
|
|
17927
|
-
if (
|
|
18150
|
+
if (ts15.isPropertyAccessExpression(parent) && parent.name === node)
|
|
17928
18151
|
return false;
|
|
17929
|
-
if (
|
|
18152
|
+
if (ts15.isPropertyAssignment(parent) && parent.name === node)
|
|
17930
18153
|
return false;
|
|
17931
|
-
if (
|
|
18154
|
+
if (ts15.isShorthandPropertyAssignment(parent) && parent.name === node)
|
|
17932
18155
|
return false;
|
|
17933
|
-
if (
|
|
18156
|
+
if (ts15.isPropertySignature(parent) && parent.name === node)
|
|
17934
18157
|
return false;
|
|
17935
|
-
if (
|
|
18158
|
+
if (ts15.isPropertyDeclaration(parent) && parent.name === node)
|
|
17936
18159
|
return false;
|
|
17937
|
-
if (
|
|
18160
|
+
if (ts15.isBindingElement(parent) && parent.name === node)
|
|
17938
18161
|
return false;
|
|
17939
18162
|
return true;
|
|
17940
18163
|
}
|
|
@@ -18222,6 +18445,8 @@ function createContext(ir, scope, adapterCapabilities, profile) {
|
|
|
18222
18445
|
propsParams: ir.metadata.propsParams,
|
|
18223
18446
|
propsObjectName: ir.metadata.propsObjectName,
|
|
18224
18447
|
restPropsName: ir.metadata.restPropsName,
|
|
18448
|
+
propsType: ir.metadata.propsType,
|
|
18449
|
+
typeDefinitions: ir.metadata.typeDefinitions,
|
|
18225
18450
|
interactiveElements: [],
|
|
18226
18451
|
dynamicElements: [],
|
|
18227
18452
|
conditionalElements: [],
|
|
@@ -18457,7 +18682,7 @@ function walkIR2(node, visitor) {
|
|
|
18457
18682
|
}
|
|
18458
18683
|
|
|
18459
18684
|
// src/preprocess-inline-jsx-callbacks.ts
|
|
18460
|
-
import
|
|
18685
|
+
import ts16 from "typescript";
|
|
18461
18686
|
var SYNTHETIC_PREFIX = "BFInlineJsxCallback";
|
|
18462
18687
|
var MAX_FIXPOINT_ITERATIONS = 16;
|
|
18463
18688
|
function preprocessInlineJsxCallbacks(source, filePath) {
|
|
@@ -18479,8 +18704,8 @@ function preprocessInlineJsxCallbacks(source, filePath) {
|
|
|
18479
18704
|
return { source: current, errors, syntheticNames };
|
|
18480
18705
|
}
|
|
18481
18706
|
function runSinglePass(source, filePath, startingCounter) {
|
|
18482
|
-
const sourceFile =
|
|
18483
|
-
const hasUseClient = sourceFile.statements.some((stmt) =>
|
|
18707
|
+
const sourceFile = ts16.createSourceFile(filePath, source, ts16.ScriptTarget.Latest, true, ts16.ScriptKind.TSX);
|
|
18708
|
+
const hasUseClient = sourceFile.statements.some((stmt) => ts16.isExpressionStatement(stmt) && ts16.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'"));
|
|
18484
18709
|
if (!hasUseClient) {
|
|
18485
18710
|
return { source, errors: [], syntheticNames: [], counterAfter: startingCounter };
|
|
18486
18711
|
}
|
|
@@ -18502,22 +18727,22 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
18502
18727
|
}
|
|
18503
18728
|
}
|
|
18504
18729
|
function visit3(node) {
|
|
18505
|
-
if (
|
|
18730
|
+
if (ts16.isJsxAttribute(node) && node.initializer && ts16.isJsxExpression(node.initializer) && node.initializer.expression) {
|
|
18506
18731
|
if (tryHandleArrowValue(node.initializer.expression)) {
|
|
18507
18732
|
return;
|
|
18508
18733
|
}
|
|
18509
18734
|
}
|
|
18510
|
-
if (
|
|
18735
|
+
if (ts16.isPropertyAssignment(node) && node.initializer) {
|
|
18511
18736
|
if (tryHandleArrowValue(node.initializer))
|
|
18512
18737
|
return;
|
|
18513
18738
|
}
|
|
18514
|
-
|
|
18739
|
+
ts16.forEachChild(node, visit3);
|
|
18515
18740
|
}
|
|
18516
18741
|
function tryHandleArrowValue(initializer) {
|
|
18517
18742
|
let expr = initializer;
|
|
18518
|
-
while (
|
|
18743
|
+
while (ts16.isParenthesizedExpression(expr))
|
|
18519
18744
|
expr = expr.expression;
|
|
18520
|
-
if (
|
|
18745
|
+
if (ts16.isArrowFunction(expr) && arrowBodyContainsJsx(expr)) {
|
|
18521
18746
|
return handleInlineArrow(expr);
|
|
18522
18747
|
}
|
|
18523
18748
|
return false;
|
|
@@ -18554,7 +18779,7 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
18554
18779
|
replacements.push({ start: arrowStart, end: arrowEnd, text: name });
|
|
18555
18780
|
return true;
|
|
18556
18781
|
}
|
|
18557
|
-
|
|
18782
|
+
ts16.forEachChild(sourceFile, visit3);
|
|
18558
18783
|
if (replacements.length === 0) {
|
|
18559
18784
|
return { source, errors, syntheticNames, counterAfter: counter };
|
|
18560
18785
|
}
|
|
@@ -18577,11 +18802,11 @@ function errorMessageForCapture(captures) {
|
|
|
18577
18802
|
return `Inline JSX-returning arrow function captures non-module identifier(s): ` + `${captures.sort().join(", ")}. ` + `Extract the callback into a top-level '\\'use client\\'' component (e.g. ` + `\`function MyNode(n) { return <div/> }\` then \`renderNode={MyNode}\`) ` + `or pass captured values via component props.`;
|
|
18578
18803
|
}
|
|
18579
18804
|
function arrowBodyContainsJsx(arrow) {
|
|
18580
|
-
if (
|
|
18805
|
+
if (ts16.isBlock(arrow.body)) {
|
|
18581
18806
|
return blockReturnsJsx(arrow.body);
|
|
18582
18807
|
}
|
|
18583
18808
|
let body = arrow.body;
|
|
18584
|
-
while (
|
|
18809
|
+
while (ts16.isParenthesizedExpression(body))
|
|
18585
18810
|
body = body.expression;
|
|
18586
18811
|
return isJsxLike(body);
|
|
18587
18812
|
}
|
|
@@ -18590,24 +18815,24 @@ function blockReturnsJsx(block) {
|
|
|
18590
18815
|
function visit3(n) {
|
|
18591
18816
|
if (found)
|
|
18592
18817
|
return;
|
|
18593
|
-
if (
|
|
18818
|
+
if (ts16.isReturnStatement(n) && n.expression) {
|
|
18594
18819
|
let e = n.expression;
|
|
18595
|
-
while (
|
|
18820
|
+
while (ts16.isParenthesizedExpression(e))
|
|
18596
18821
|
e = e.expression;
|
|
18597
18822
|
if (isJsxLike(e)) {
|
|
18598
18823
|
found = true;
|
|
18599
18824
|
return;
|
|
18600
18825
|
}
|
|
18601
18826
|
}
|
|
18602
|
-
if (
|
|
18827
|
+
if (ts16.isArrowFunction(n) || ts16.isFunctionDeclaration(n) || ts16.isFunctionExpression(n))
|
|
18603
18828
|
return;
|
|
18604
|
-
|
|
18829
|
+
ts16.forEachChild(n, visit3);
|
|
18605
18830
|
}
|
|
18606
|
-
|
|
18831
|
+
ts16.forEachChild(block, visit3);
|
|
18607
18832
|
return found;
|
|
18608
18833
|
}
|
|
18609
18834
|
function isJsxLike(expr) {
|
|
18610
|
-
return
|
|
18835
|
+
return ts16.isJsxElement(expr) || ts16.isJsxSelfClosingElement(expr) || ts16.isJsxFragment(expr);
|
|
18611
18836
|
}
|
|
18612
18837
|
function collectArrowParamNames(arrow) {
|
|
18613
18838
|
const names = new Set;
|
|
@@ -18617,13 +18842,13 @@ function collectArrowParamNames(arrow) {
|
|
|
18617
18842
|
}
|
|
18618
18843
|
function collectBindingNames(name, out) {
|
|
18619
18844
|
const push = Array.isArray(out) ? (n) => out.push(n) : (n) => out.add(n);
|
|
18620
|
-
if (
|
|
18845
|
+
if (ts16.isIdentifier(name)) {
|
|
18621
18846
|
push(name.text);
|
|
18622
|
-
} else if (
|
|
18847
|
+
} else if (ts16.isObjectBindingPattern(name)) {
|
|
18623
18848
|
name.elements.forEach((el) => collectBindingNames(el.name, out));
|
|
18624
|
-
} else if (
|
|
18849
|
+
} else if (ts16.isArrayBindingPattern(name)) {
|
|
18625
18850
|
name.elements.forEach((el) => {
|
|
18626
|
-
if (!
|
|
18851
|
+
if (!ts16.isOmittedExpression(el))
|
|
18627
18852
|
collectBindingNames(el.name, out);
|
|
18628
18853
|
});
|
|
18629
18854
|
}
|
|
@@ -18650,48 +18875,48 @@ function collectFreeIdentifiers(arrow) {
|
|
|
18650
18875
|
return bound.includes(name);
|
|
18651
18876
|
}
|
|
18652
18877
|
function visit3(node) {
|
|
18653
|
-
if (
|
|
18878
|
+
if (ts16.isIdentifier(node)) {
|
|
18654
18879
|
const parent = node.parent;
|
|
18655
|
-
if (parent &&
|
|
18880
|
+
if (parent && ts16.isPropertyAccessExpression(parent) && parent.name === node)
|
|
18656
18881
|
return;
|
|
18657
|
-
if (parent &&
|
|
18882
|
+
if (parent && ts16.isPropertyAssignment(parent) && parent.name === node)
|
|
18658
18883
|
return;
|
|
18659
|
-
if (parent &&
|
|
18884
|
+
if (parent && ts16.isPropertySignature(parent) && parent.name === node)
|
|
18660
18885
|
return;
|
|
18661
|
-
if (parent &&
|
|
18886
|
+
if (parent && ts16.isPropertyDeclaration(parent) && parent.name === node)
|
|
18662
18887
|
return;
|
|
18663
|
-
if (parent &&
|
|
18888
|
+
if (parent && ts16.isMethodDeclaration(parent) && parent.name === node)
|
|
18664
18889
|
return;
|
|
18665
|
-
if (parent &&
|
|
18890
|
+
if (parent && ts16.isMethodSignature(parent) && parent.name === node)
|
|
18666
18891
|
return;
|
|
18667
|
-
if (parent &&
|
|
18892
|
+
if (parent && ts16.isGetAccessorDeclaration(parent) && parent.name === node)
|
|
18668
18893
|
return;
|
|
18669
|
-
if (parent &&
|
|
18894
|
+
if (parent && ts16.isSetAccessorDeclaration(parent) && parent.name === node)
|
|
18670
18895
|
return;
|
|
18671
|
-
if (parent &&
|
|
18896
|
+
if (parent && ts16.isEnumMember(parent) && parent.name === node)
|
|
18672
18897
|
return;
|
|
18673
|
-
if (parent &&
|
|
18898
|
+
if (parent && ts16.isBindingElement(parent) && parent.propertyName === node)
|
|
18674
18899
|
return;
|
|
18675
|
-
if (parent &&
|
|
18900
|
+
if (parent && ts16.isShorthandPropertyAssignment(parent) && parent.name === node) {
|
|
18676
18901
|
if (!isBound(node.text))
|
|
18677
18902
|
ids.add(node.text);
|
|
18678
18903
|
return;
|
|
18679
18904
|
}
|
|
18680
|
-
if (parent &&
|
|
18905
|
+
if (parent && ts16.isParameter(parent) && parent.name === node)
|
|
18681
18906
|
return;
|
|
18682
|
-
if (parent &&
|
|
18907
|
+
if (parent && ts16.isVariableDeclaration(parent) && parent.name === node)
|
|
18683
18908
|
return;
|
|
18684
|
-
if (parent &&
|
|
18909
|
+
if (parent && ts16.isFunctionDeclaration(parent) && parent.name === node)
|
|
18685
18910
|
return;
|
|
18686
|
-
if (parent &&
|
|
18911
|
+
if (parent && ts16.isClassDeclaration(parent) && parent.name === node)
|
|
18687
18912
|
return;
|
|
18688
|
-
if (parent &&
|
|
18913
|
+
if (parent && ts16.isJsxAttribute(parent) && parent.name === node)
|
|
18689
18914
|
return;
|
|
18690
|
-
if (parent &&
|
|
18915
|
+
if (parent && ts16.isJsxOpeningElement(parent) && parent.tagName === node) {
|
|
18691
18916
|
if (/^[a-z]/.test(node.text))
|
|
18692
18917
|
return;
|
|
18693
18918
|
}
|
|
18694
|
-
if (parent &&
|
|
18919
|
+
if (parent && ts16.isJsxClosingElement(parent) && parent.tagName === node) {
|
|
18695
18920
|
if (/^[a-z]/.test(node.text))
|
|
18696
18921
|
return;
|
|
18697
18922
|
}
|
|
@@ -18700,43 +18925,43 @@ function collectFreeIdentifiers(arrow) {
|
|
|
18700
18925
|
ids.add(node.text);
|
|
18701
18926
|
return;
|
|
18702
18927
|
}
|
|
18703
|
-
if (
|
|
18928
|
+
if (ts16.isVariableDeclaration(node)) {
|
|
18704
18929
|
const declared = pushBindings(node.name);
|
|
18705
18930
|
if (node.initializer)
|
|
18706
18931
|
visit3(node.initializer);
|
|
18707
18932
|
return;
|
|
18708
18933
|
}
|
|
18709
|
-
if (
|
|
18934
|
+
if (ts16.isFunctionDeclaration(node)) {
|
|
18710
18935
|
if (node.name)
|
|
18711
18936
|
bound.push(node.name.text);
|
|
18712
18937
|
visitInsideNewScope(node);
|
|
18713
18938
|
return;
|
|
18714
18939
|
}
|
|
18715
|
-
if (
|
|
18940
|
+
if (ts16.isClassDeclaration(node)) {
|
|
18716
18941
|
if (node.name)
|
|
18717
18942
|
bound.push(node.name.text);
|
|
18718
|
-
|
|
18943
|
+
ts16.forEachChild(node, visit3);
|
|
18719
18944
|
return;
|
|
18720
18945
|
}
|
|
18721
|
-
if (
|
|
18946
|
+
if (ts16.isArrowFunction(node) || ts16.isFunctionExpression(node)) {
|
|
18722
18947
|
visitInsideNewScope(node);
|
|
18723
18948
|
return;
|
|
18724
18949
|
}
|
|
18725
|
-
if (
|
|
18950
|
+
if (ts16.isCatchClause(node)) {
|
|
18726
18951
|
const before = bound.length;
|
|
18727
18952
|
if (node.variableDeclaration)
|
|
18728
18953
|
pushBindings(node.variableDeclaration.name);
|
|
18729
|
-
|
|
18954
|
+
ts16.forEachChild(node, visit3);
|
|
18730
18955
|
popN(bound.length - before);
|
|
18731
18956
|
return;
|
|
18732
18957
|
}
|
|
18733
|
-
if (
|
|
18958
|
+
if (ts16.isBlock(node)) {
|
|
18734
18959
|
const before = bound.length;
|
|
18735
|
-
|
|
18960
|
+
ts16.forEachChild(node, visit3);
|
|
18736
18961
|
popN(bound.length - before);
|
|
18737
18962
|
return;
|
|
18738
18963
|
}
|
|
18739
|
-
|
|
18964
|
+
ts16.forEachChild(node, visit3);
|
|
18740
18965
|
}
|
|
18741
18966
|
function visitInsideNewScope(fn) {
|
|
18742
18967
|
const before = bound.length;
|
|
@@ -18759,29 +18984,29 @@ function collectFreeIdentifiers(arrow) {
|
|
|
18759
18984
|
function collectModuleScopeNames(sourceFile) {
|
|
18760
18985
|
const names = new Set;
|
|
18761
18986
|
for (const stmt of sourceFile.statements) {
|
|
18762
|
-
if (
|
|
18987
|
+
if (ts16.isFunctionDeclaration(stmt) && stmt.name)
|
|
18763
18988
|
names.add(stmt.name.text);
|
|
18764
|
-
else if (
|
|
18989
|
+
else if (ts16.isClassDeclaration(stmt) && stmt.name)
|
|
18765
18990
|
names.add(stmt.name.text);
|
|
18766
|
-
else if (
|
|
18991
|
+
else if (ts16.isVariableStatement(stmt)) {
|
|
18767
18992
|
for (const decl of stmt.declarationList.declarations)
|
|
18768
18993
|
collectBindingNames(decl.name, names);
|
|
18769
|
-
} else if (
|
|
18994
|
+
} else if (ts16.isImportDeclaration(stmt) && stmt.importClause) {
|
|
18770
18995
|
const ic = stmt.importClause;
|
|
18771
18996
|
if (ic.name)
|
|
18772
18997
|
names.add(ic.name.text);
|
|
18773
18998
|
if (ic.namedBindings) {
|
|
18774
|
-
if (
|
|
18999
|
+
if (ts16.isNamespaceImport(ic.namedBindings))
|
|
18775
19000
|
names.add(ic.namedBindings.name.text);
|
|
18776
19001
|
else
|
|
18777
19002
|
for (const e of ic.namedBindings.elements)
|
|
18778
19003
|
names.add(e.name.text);
|
|
18779
19004
|
}
|
|
18780
|
-
} else if (
|
|
19005
|
+
} else if (ts16.isTypeAliasDeclaration(stmt))
|
|
18781
19006
|
names.add(stmt.name.text);
|
|
18782
|
-
else if (
|
|
19007
|
+
else if (ts16.isInterfaceDeclaration(stmt))
|
|
18783
19008
|
names.add(stmt.name.text);
|
|
18784
|
-
else if (
|
|
19009
|
+
else if (ts16.isEnumDeclaration(stmt))
|
|
18785
19010
|
names.add(stmt.name.text);
|
|
18786
19011
|
}
|
|
18787
19012
|
return names;
|
|
@@ -18789,7 +19014,7 @@ function collectModuleScopeNames(sourceFile) {
|
|
|
18789
19014
|
function buildSyntheticDeclaration(name, arrow, sourceFile) {
|
|
18790
19015
|
const paramsText = arrow.parameters.length === 0 ? "" : arrow.parameters.map((p) => p.getText(sourceFile)).join(", ");
|
|
18791
19016
|
let bodyText;
|
|
18792
|
-
if (
|
|
19017
|
+
if (ts16.isBlock(arrow.body)) {
|
|
18793
19018
|
bodyText = arrow.body.getText(sourceFile);
|
|
18794
19019
|
} else {
|
|
18795
19020
|
const expr = arrow.body.getText(sourceFile);
|
|
@@ -18799,7 +19024,7 @@ function buildSyntheticDeclaration(name, arrow, sourceFile) {
|
|
|
18799
19024
|
}
|
|
18800
19025
|
|
|
18801
19026
|
// src/ssr-defaults.ts
|
|
18802
|
-
import
|
|
19027
|
+
import ts17 from "typescript";
|
|
18803
19028
|
var UNRESOLVED = Symbol("unresolved");
|
|
18804
19029
|
var NO_RETURN = Symbol("no-return");
|
|
18805
19030
|
function extractSsrDefaults(metadata) {
|
|
@@ -18875,11 +19100,11 @@ function collectPropRefs(expr, propsObjectName, out) {
|
|
|
18875
19100
|
if (!node)
|
|
18876
19101
|
return;
|
|
18877
19102
|
const visit3 = (n) => {
|
|
18878
|
-
if (
|
|
19103
|
+
if (ts17.isPropertyAccessExpression(n) && ts17.isIdentifier(n.expression) && n.expression.text === propsObjectName && ts17.isIdentifier(n.name)) {
|
|
18879
19104
|
out.add(n.name.text);
|
|
18880
19105
|
return;
|
|
18881
19106
|
}
|
|
18882
|
-
|
|
19107
|
+
ts17.forEachChild(n, visit3);
|
|
18883
19108
|
};
|
|
18884
19109
|
visit3(node);
|
|
18885
19110
|
}
|
|
@@ -18900,23 +19125,23 @@ function tryStaticEval(expr, ctx) {
|
|
|
18900
19125
|
}
|
|
18901
19126
|
function evalStatementsForReturn(statements, ctx) {
|
|
18902
19127
|
for (const stmt of statements) {
|
|
18903
|
-
if (
|
|
19128
|
+
if (ts17.isVariableStatement(stmt)) {
|
|
18904
19129
|
for (const d of stmt.declarationList.declarations) {
|
|
18905
|
-
if (!
|
|
19130
|
+
if (!ts17.isIdentifier(d.name) || !d.initializer)
|
|
18906
19131
|
continue;
|
|
18907
19132
|
const v = evalNode(d.initializer, ctx);
|
|
18908
19133
|
if (v !== UNRESOLVED)
|
|
18909
19134
|
ctx.bindings[d.name.text] = v;
|
|
18910
19135
|
}
|
|
18911
|
-
} else if (
|
|
19136
|
+
} else if (ts17.isReturnStatement(stmt)) {
|
|
18912
19137
|
return stmt.expression ? evalNode(stmt.expression, ctx) : UNRESOLVED;
|
|
18913
|
-
} else if (
|
|
19138
|
+
} else if (ts17.isIfStatement(stmt)) {
|
|
18914
19139
|
const cond = evalNode(stmt.expression, ctx);
|
|
18915
19140
|
if (cond === UNRESOLVED)
|
|
18916
19141
|
return UNRESOLVED;
|
|
18917
19142
|
const branch = cond ? stmt.thenStatement : stmt.elseStatement;
|
|
18918
19143
|
if (branch) {
|
|
18919
|
-
const taken = evalStatementsForReturn(
|
|
19144
|
+
const taken = evalStatementsForReturn(ts17.isBlock(branch) ? branch.statements : [branch], ctx);
|
|
18920
19145
|
if (taken !== NO_RETURN)
|
|
18921
19146
|
return taken;
|
|
18922
19147
|
}
|
|
@@ -18927,45 +19152,45 @@ function evalStatementsForReturn(statements, ctx) {
|
|
|
18927
19152
|
return NO_RETURN;
|
|
18928
19153
|
}
|
|
18929
19154
|
function parseExpression2(expr) {
|
|
18930
|
-
const sf =
|
|
19155
|
+
const sf = ts17.createSourceFile("__ssr_default__.ts", `(${expr})`, ts17.ScriptTarget.Latest, false, ts17.ScriptKind.TS);
|
|
18931
19156
|
const stmt = sf.statements[0];
|
|
18932
|
-
if (!stmt || !
|
|
19157
|
+
if (!stmt || !ts17.isExpressionStatement(stmt))
|
|
18933
19158
|
return null;
|
|
18934
|
-
const inner =
|
|
19159
|
+
const inner = ts17.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
18935
19160
|
return inner;
|
|
18936
19161
|
}
|
|
18937
19162
|
function evalNode(node, ctx) {
|
|
18938
|
-
if (
|
|
19163
|
+
if (ts17.isParenthesizedExpression(node))
|
|
18939
19164
|
return evalNode(node.expression, ctx);
|
|
18940
|
-
if (
|
|
19165
|
+
if (ts17.isAsExpression(node))
|
|
18941
19166
|
return evalNode(node.expression, ctx);
|
|
18942
|
-
if (
|
|
19167
|
+
if (ts17.isSatisfiesExpression(node))
|
|
18943
19168
|
return evalNode(node.expression, ctx);
|
|
18944
|
-
if (
|
|
19169
|
+
if (ts17.isTypeAssertionExpression(node))
|
|
18945
19170
|
return evalNode(node.expression, ctx);
|
|
18946
|
-
if (
|
|
19171
|
+
if (ts17.isNonNullExpression(node))
|
|
18947
19172
|
return evalNode(node.expression, ctx);
|
|
18948
|
-
if (
|
|
19173
|
+
if (ts17.isArrowFunction(node)) {
|
|
18949
19174
|
if (node.parameters.length !== 0)
|
|
18950
19175
|
return UNRESOLVED;
|
|
18951
|
-
if (!
|
|
19176
|
+
if (!ts17.isBlock(node.body))
|
|
18952
19177
|
return evalNode(node.body, ctx);
|
|
18953
19178
|
const localBindings = { ...ctx.bindings };
|
|
18954
19179
|
const localCtx = { ...ctx, bindings: localBindings };
|
|
18955
19180
|
const result = evalStatementsForReturn(node.body.statements, localCtx);
|
|
18956
19181
|
return result === NO_RETURN ? UNRESOLVED : result;
|
|
18957
19182
|
}
|
|
18958
|
-
if (
|
|
19183
|
+
if (ts17.isNumericLiteral(node))
|
|
18959
19184
|
return Number(node.text);
|
|
18960
|
-
if (
|
|
19185
|
+
if (ts17.isStringLiteralLike(node))
|
|
18961
19186
|
return node.text;
|
|
18962
|
-
if (node.kind ===
|
|
19187
|
+
if (node.kind === ts17.SyntaxKind.TrueKeyword)
|
|
18963
19188
|
return true;
|
|
18964
|
-
if (node.kind ===
|
|
19189
|
+
if (node.kind === ts17.SyntaxKind.FalseKeyword)
|
|
18965
19190
|
return false;
|
|
18966
|
-
if (node.kind ===
|
|
19191
|
+
if (node.kind === ts17.SyntaxKind.NullKeyword)
|
|
18967
19192
|
return null;
|
|
18968
|
-
if (
|
|
19193
|
+
if (ts17.isIdentifier(node)) {
|
|
18969
19194
|
if (node.text === "undefined")
|
|
18970
19195
|
return;
|
|
18971
19196
|
if (node.text in ctx.bindings)
|
|
@@ -18974,29 +19199,29 @@ function evalNode(node, ctx) {
|
|
|
18974
19199
|
return;
|
|
18975
19200
|
return UNRESOLVED;
|
|
18976
19201
|
}
|
|
18977
|
-
if (
|
|
19202
|
+
if (ts17.isPrefixUnaryExpression(node)) {
|
|
18978
19203
|
const arg = evalNode(node.operand, ctx);
|
|
18979
19204
|
if (arg === UNRESOLVED)
|
|
18980
19205
|
return UNRESOLVED;
|
|
18981
19206
|
switch (node.operator) {
|
|
18982
|
-
case
|
|
19207
|
+
case ts17.SyntaxKind.MinusToken:
|
|
18983
19208
|
return typeof arg === "number" ? -arg : UNRESOLVED;
|
|
18984
|
-
case
|
|
19209
|
+
case ts17.SyntaxKind.PlusToken:
|
|
18985
19210
|
return typeof arg === "number" ? +arg : UNRESOLVED;
|
|
18986
|
-
case
|
|
19211
|
+
case ts17.SyntaxKind.ExclamationToken:
|
|
18987
19212
|
return !arg;
|
|
18988
19213
|
}
|
|
18989
19214
|
return UNRESOLVED;
|
|
18990
19215
|
}
|
|
18991
|
-
if (
|
|
19216
|
+
if (ts17.isObjectLiteralExpression(node)) {
|
|
18992
19217
|
const obj = {};
|
|
18993
19218
|
for (const prop of node.properties) {
|
|
18994
|
-
if (!
|
|
19219
|
+
if (!ts17.isPropertyAssignment(prop))
|
|
18995
19220
|
return UNRESOLVED;
|
|
18996
19221
|
let key;
|
|
18997
|
-
if (
|
|
19222
|
+
if (ts17.isIdentifier(prop.name) || ts17.isStringLiteralLike(prop.name)) {
|
|
18998
19223
|
key = prop.name.text;
|
|
18999
|
-
} else if (
|
|
19224
|
+
} else if (ts17.isNumericLiteral(prop.name)) {
|
|
19000
19225
|
key = prop.name.text;
|
|
19001
19226
|
} else {
|
|
19002
19227
|
return UNRESOLVED;
|
|
@@ -19008,10 +19233,10 @@ function evalNode(node, ctx) {
|
|
|
19008
19233
|
}
|
|
19009
19234
|
return obj;
|
|
19010
19235
|
}
|
|
19011
|
-
if (
|
|
19236
|
+
if (ts17.isArrayLiteralExpression(node)) {
|
|
19012
19237
|
const arr = [];
|
|
19013
19238
|
for (const elem of node.elements) {
|
|
19014
|
-
if (
|
|
19239
|
+
if (ts17.isOmittedExpression(elem))
|
|
19015
19240
|
return UNRESOLVED;
|
|
19016
19241
|
const v = evalNode(elem, ctx);
|
|
19017
19242
|
if (v === UNRESOLVED)
|
|
@@ -19020,7 +19245,7 @@ function evalNode(node, ctx) {
|
|
|
19020
19245
|
}
|
|
19021
19246
|
return arr;
|
|
19022
19247
|
}
|
|
19023
|
-
if (
|
|
19248
|
+
if (ts17.isElementAccessExpression(node)) {
|
|
19024
19249
|
const base = evalNode(node.expression, ctx);
|
|
19025
19250
|
if (base === undefined)
|
|
19026
19251
|
return;
|
|
@@ -19034,17 +19259,17 @@ function evalNode(node, ctx) {
|
|
|
19034
19259
|
const k = String(key);
|
|
19035
19260
|
return Object.prototype.hasOwnProperty.call(base, k) ? base[k] : undefined;
|
|
19036
19261
|
}
|
|
19037
|
-
if (
|
|
19262
|
+
if (ts17.isPropertyAccessExpression(node)) {
|
|
19038
19263
|
const baseResult = evalNode(node.expression, ctx);
|
|
19039
19264
|
if (baseResult === undefined)
|
|
19040
19265
|
return;
|
|
19041
19266
|
return UNRESOLVED;
|
|
19042
19267
|
}
|
|
19043
|
-
if (
|
|
19044
|
-
if (node.arguments.length === 0 &&
|
|
19268
|
+
if (ts17.isCallExpression(node)) {
|
|
19269
|
+
if (node.arguments.length === 0 && ts17.isIdentifier(node.expression) && node.expression.text in ctx.bindings) {
|
|
19045
19270
|
return ctx.bindings[node.expression.text];
|
|
19046
19271
|
}
|
|
19047
|
-
if (
|
|
19272
|
+
if (ts17.isPropertyAccessExpression(node.expression) && node.expression.name.text === "join") {
|
|
19048
19273
|
const recv = evalNode(node.expression.expression, ctx);
|
|
19049
19274
|
if (Array.isArray(recv)) {
|
|
19050
19275
|
let sep2 = ",";
|
|
@@ -19060,27 +19285,27 @@ function evalNode(node, ctx) {
|
|
|
19060
19285
|
}
|
|
19061
19286
|
return UNRESOLVED;
|
|
19062
19287
|
}
|
|
19063
|
-
if (
|
|
19288
|
+
if (ts17.isConditionalExpression(node)) {
|
|
19064
19289
|
const cond = evalNode(node.condition, ctx);
|
|
19065
19290
|
if (cond === UNRESOLVED)
|
|
19066
19291
|
return UNRESOLVED;
|
|
19067
19292
|
return cond ? evalNode(node.whenTrue, ctx) : evalNode(node.whenFalse, ctx);
|
|
19068
19293
|
}
|
|
19069
|
-
if (
|
|
19294
|
+
if (ts17.isBinaryExpression(node)) {
|
|
19070
19295
|
const op = node.operatorToken.kind;
|
|
19071
|
-
if (op ===
|
|
19296
|
+
if (op === ts17.SyntaxKind.QuestionQuestionToken) {
|
|
19072
19297
|
const l2 = evalNode(node.left, ctx);
|
|
19073
19298
|
if (l2 !== UNRESOLVED && l2 !== null && l2 !== undefined)
|
|
19074
19299
|
return l2;
|
|
19075
19300
|
return evalNode(node.right, ctx);
|
|
19076
19301
|
}
|
|
19077
|
-
if (op ===
|
|
19302
|
+
if (op === ts17.SyntaxKind.BarBarToken) {
|
|
19078
19303
|
const l2 = evalNode(node.left, ctx);
|
|
19079
19304
|
if (l2 !== UNRESOLVED && l2)
|
|
19080
19305
|
return l2;
|
|
19081
19306
|
return evalNode(node.right, ctx);
|
|
19082
19307
|
}
|
|
19083
|
-
if (op ===
|
|
19308
|
+
if (op === ts17.SyntaxKind.AmpersandAmpersandToken) {
|
|
19084
19309
|
const l2 = evalNode(node.left, ctx);
|
|
19085
19310
|
if (l2 === UNRESOLVED)
|
|
19086
19311
|
return UNRESOLVED;
|
|
@@ -19093,30 +19318,30 @@ function evalNode(node, ctx) {
|
|
|
19093
19318
|
if (l === UNRESOLVED || r === UNRESOLVED)
|
|
19094
19319
|
return UNRESOLVED;
|
|
19095
19320
|
switch (op) {
|
|
19096
|
-
case
|
|
19321
|
+
case ts17.SyntaxKind.PlusToken:
|
|
19097
19322
|
if (typeof l === "string" || typeof r === "string")
|
|
19098
19323
|
return `${l}${r}`;
|
|
19099
19324
|
if (typeof l === "number" && typeof r === "number")
|
|
19100
19325
|
return l + r;
|
|
19101
19326
|
return UNRESOLVED;
|
|
19102
|
-
case
|
|
19327
|
+
case ts17.SyntaxKind.MinusToken:
|
|
19103
19328
|
return typeof l === "number" && typeof r === "number" ? l - r : UNRESOLVED;
|
|
19104
|
-
case
|
|
19329
|
+
case ts17.SyntaxKind.AsteriskToken:
|
|
19105
19330
|
return typeof l === "number" && typeof r === "number" ? l * r : UNRESOLVED;
|
|
19106
|
-
case
|
|
19331
|
+
case ts17.SyntaxKind.SlashToken:
|
|
19107
19332
|
return typeof l === "number" && typeof r === "number" && r !== 0 ? l / r : UNRESOLVED;
|
|
19108
|
-
case
|
|
19333
|
+
case ts17.SyntaxKind.PercentToken:
|
|
19109
19334
|
return typeof l === "number" && typeof r === "number" && r !== 0 ? l % r : UNRESOLVED;
|
|
19110
|
-
case
|
|
19111
|
-
case
|
|
19335
|
+
case ts17.SyntaxKind.EqualsEqualsEqualsToken:
|
|
19336
|
+
case ts17.SyntaxKind.EqualsEqualsToken:
|
|
19112
19337
|
return l === r;
|
|
19113
|
-
case
|
|
19114
|
-
case
|
|
19338
|
+
case ts17.SyntaxKind.ExclamationEqualsEqualsToken:
|
|
19339
|
+
case ts17.SyntaxKind.ExclamationEqualsToken:
|
|
19115
19340
|
return l !== r;
|
|
19116
19341
|
}
|
|
19117
19342
|
return UNRESOLVED;
|
|
19118
19343
|
}
|
|
19119
|
-
if (
|
|
19344
|
+
if (ts17.isTemplateExpression(node)) {
|
|
19120
19345
|
if (node.templateSpans.length === 0)
|
|
19121
19346
|
return node.head.text;
|
|
19122
19347
|
let acc = node.head.text;
|
|
@@ -19128,13 +19353,13 @@ function evalNode(node, ctx) {
|
|
|
19128
19353
|
}
|
|
19129
19354
|
return acc;
|
|
19130
19355
|
}
|
|
19131
|
-
if (
|
|
19356
|
+
if (ts17.isNoSubstitutionTemplateLiteral(node))
|
|
19132
19357
|
return node.text;
|
|
19133
19358
|
return UNRESOLVED;
|
|
19134
19359
|
}
|
|
19135
19360
|
|
|
19136
19361
|
// src/augment-inherited-props.ts
|
|
19137
|
-
import
|
|
19362
|
+
import ts18 from "typescript";
|
|
19138
19363
|
function collectContextConsumers(metadata) {
|
|
19139
19364
|
const constants = metadata.localConstants ?? [];
|
|
19140
19365
|
const contextDefaults = new Map;
|
|
@@ -19166,47 +19391,47 @@ function collectContextConsumers(metadata) {
|
|
|
19166
19391
|
}
|
|
19167
19392
|
function parseUseContextArg(source) {
|
|
19168
19393
|
const expr = parseSingleExpression(source);
|
|
19169
|
-
if (!expr || !
|
|
19394
|
+
if (!expr || !ts18.isCallExpression(expr))
|
|
19170
19395
|
return null;
|
|
19171
|
-
if (!
|
|
19396
|
+
if (!ts18.isIdentifier(expr.expression) || expr.expression.text !== "useContext")
|
|
19172
19397
|
return null;
|
|
19173
19398
|
if (expr.arguments.length !== 1)
|
|
19174
19399
|
return null;
|
|
19175
19400
|
const arg = expr.arguments[0];
|
|
19176
|
-
return
|
|
19401
|
+
return ts18.isIdentifier(arg) ? arg.text : null;
|
|
19177
19402
|
}
|
|
19178
19403
|
function parseCreateContextDefault(source) {
|
|
19179
19404
|
const expr = parseSingleExpression(source);
|
|
19180
|
-
if (!expr || !
|
|
19405
|
+
if (!expr || !ts18.isCallExpression(expr))
|
|
19181
19406
|
return null;
|
|
19182
19407
|
if (expr.arguments.length === 0)
|
|
19183
19408
|
return null;
|
|
19184
19409
|
const arg = expr.arguments[0];
|
|
19185
|
-
if (
|
|
19410
|
+
if (ts18.isStringLiteral(arg) || ts18.isNoSubstitutionTemplateLiteral(arg))
|
|
19186
19411
|
return arg.text;
|
|
19187
|
-
if (
|
|
19412
|
+
if (ts18.isNumericLiteral(arg))
|
|
19188
19413
|
return Number(arg.text);
|
|
19189
|
-
if (arg.kind ===
|
|
19414
|
+
if (arg.kind === ts18.SyntaxKind.TrueKeyword)
|
|
19190
19415
|
return true;
|
|
19191
|
-
if (arg.kind ===
|
|
19416
|
+
if (arg.kind === ts18.SyntaxKind.FalseKeyword)
|
|
19192
19417
|
return false;
|
|
19193
19418
|
return null;
|
|
19194
19419
|
}
|
|
19195
19420
|
function isObjectLiteralCreateContextDefault(source) {
|
|
19196
19421
|
const expr = parseSingleExpression(source);
|
|
19197
|
-
if (!expr || !
|
|
19422
|
+
if (!expr || !ts18.isCallExpression(expr))
|
|
19198
19423
|
return false;
|
|
19199
19424
|
if (expr.arguments.length === 0)
|
|
19200
19425
|
return false;
|
|
19201
|
-
return
|
|
19426
|
+
return ts18.isObjectLiteralExpression(expr.arguments[0]);
|
|
19202
19427
|
}
|
|
19203
19428
|
function parseSingleExpression(source) {
|
|
19204
|
-
const sf =
|
|
19429
|
+
const sf = ts18.createSourceFile("__ctx.ts", `(${source})`, ts18.ScriptTarget.Latest, false);
|
|
19205
19430
|
const stmt = sf.statements[0];
|
|
19206
|
-
if (!stmt || !
|
|
19431
|
+
if (!stmt || !ts18.isExpressionStatement(stmt))
|
|
19207
19432
|
return null;
|
|
19208
19433
|
let e = stmt.expression;
|
|
19209
|
-
while (
|
|
19434
|
+
while (ts18.isParenthesizedExpression(e))
|
|
19210
19435
|
e = e.expression;
|
|
19211
19436
|
return e;
|
|
19212
19437
|
}
|
|
@@ -19231,25 +19456,25 @@ function augmentInheritedPropAccesses(ir) {
|
|
|
19231
19456
|
const pinCoalesceLiterals = (s) => {
|
|
19232
19457
|
if (!s || !s.includes(propsObj))
|
|
19233
19458
|
return;
|
|
19234
|
-
const sf =
|
|
19459
|
+
const sf = ts18.createSourceFile("__aug.ts", `(${s})`, ts18.ScriptTarget.Latest, false);
|
|
19235
19460
|
const visit3 = (n) => {
|
|
19236
|
-
if (
|
|
19461
|
+
if (ts18.isBinaryExpression(n) && (n.operatorToken.kind === ts18.SyntaxKind.QuestionQuestionToken || n.operatorToken.kind === ts18.SyntaxKind.BarBarToken)) {
|
|
19237
19462
|
let left = n.left;
|
|
19238
|
-
while (
|
|
19463
|
+
while (ts18.isParenthesizedExpression(left))
|
|
19239
19464
|
left = left.expression;
|
|
19240
|
-
if (
|
|
19465
|
+
if (ts18.isPropertyAccessExpression(left) && ts18.isIdentifier(left.expression) && left.expression.text === propsObj) {
|
|
19241
19466
|
const name = left.name.text;
|
|
19242
19467
|
let right = n.right;
|
|
19243
|
-
while (
|
|
19468
|
+
while (ts18.isParenthesizedExpression(right))
|
|
19244
19469
|
right = right.expression;
|
|
19245
|
-
if (
|
|
19470
|
+
if (ts18.isPrefixUnaryExpression(right))
|
|
19246
19471
|
right = right.operand;
|
|
19247
|
-
const kind =
|
|
19472
|
+
const kind = ts18.isNumericLiteral(right) ? "number" : right.kind === ts18.SyntaxKind.TrueKeyword || right.kind === ts18.SyntaxKind.FalseKeyword ? "boolean" : ts18.isStringLiteralLike(right) ? "string" : null;
|
|
19248
19473
|
if (kind && !coalesceLiteralTypes.has(name))
|
|
19249
19474
|
coalesceLiteralTypes.set(name, kind);
|
|
19250
19475
|
}
|
|
19251
19476
|
}
|
|
19252
|
-
|
|
19477
|
+
ts18.forEachChild(n, visit3);
|
|
19253
19478
|
};
|
|
19254
19479
|
visit3(sf);
|
|
19255
19480
|
};
|
|
@@ -19360,33 +19585,33 @@ function augmentInheritedPropAccesses(ir) {
|
|
|
19360
19585
|
}
|
|
19361
19586
|
}
|
|
19362
19587
|
function parseStaticStringConst(source) {
|
|
19363
|
-
const sf =
|
|
19588
|
+
const sf = ts18.createSourceFile("__const.ts", `const __x = (${source});`, ts18.ScriptTarget.Latest, false);
|
|
19364
19589
|
const stmt = sf.statements[0];
|
|
19365
|
-
if (!stmt || !
|
|
19590
|
+
if (!stmt || !ts18.isVariableStatement(stmt))
|
|
19366
19591
|
return null;
|
|
19367
19592
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
19368
|
-
while (init &&
|
|
19593
|
+
while (init && ts18.isParenthesizedExpression(init))
|
|
19369
19594
|
init = init.expression;
|
|
19370
19595
|
if (!init)
|
|
19371
19596
|
return null;
|
|
19372
|
-
if (
|
|
19597
|
+
if (ts18.isStringLiteral(init) || ts18.isNoSubstitutionTemplateLiteral(init)) {
|
|
19373
19598
|
return init.text;
|
|
19374
19599
|
}
|
|
19375
19600
|
return evalStringArrayJoin(source);
|
|
19376
19601
|
}
|
|
19377
19602
|
function evalTemplateOfStringConsts(source, resolved) {
|
|
19378
|
-
const sf =
|
|
19603
|
+
const sf = ts18.createSourceFile("__const.ts", `const __x = (${source});`, ts18.ScriptTarget.Latest, false);
|
|
19379
19604
|
const stmt = sf.statements[0];
|
|
19380
|
-
if (!stmt || !
|
|
19605
|
+
if (!stmt || !ts18.isVariableStatement(stmt))
|
|
19381
19606
|
return null;
|
|
19382
19607
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
19383
|
-
while (init &&
|
|
19608
|
+
while (init && ts18.isParenthesizedExpression(init))
|
|
19384
19609
|
init = init.expression;
|
|
19385
|
-
if (!init || !
|
|
19610
|
+
if (!init || !ts18.isTemplateExpression(init))
|
|
19386
19611
|
return null;
|
|
19387
19612
|
let out = init.head.text;
|
|
19388
19613
|
for (const span of init.templateSpans) {
|
|
19389
|
-
if (!
|
|
19614
|
+
if (!ts18.isIdentifier(span.expression))
|
|
19390
19615
|
return null;
|
|
19391
19616
|
const value = resolved.get(span.expression.text);
|
|
19392
19617
|
if (value === undefined)
|
|
@@ -19417,30 +19642,30 @@ function lookupStaticRecordLiteral(objectName, key, constants) {
|
|
|
19417
19642
|
const constInfo = (constants ?? []).find((c) => c.name === objectName && c.isModule);
|
|
19418
19643
|
if (constInfo?.value === undefined)
|
|
19419
19644
|
return null;
|
|
19420
|
-
const sf =
|
|
19645
|
+
const sf = ts18.createSourceFile("__rec.ts", `(${constInfo.value})`, ts18.ScriptTarget.Latest, true);
|
|
19421
19646
|
if (sf.statements.length !== 1)
|
|
19422
19647
|
return null;
|
|
19423
19648
|
const stmt = sf.statements[0];
|
|
19424
|
-
if (!
|
|
19649
|
+
if (!ts18.isExpressionStatement(stmt))
|
|
19425
19650
|
return null;
|
|
19426
19651
|
let parsed = stmt.expression;
|
|
19427
|
-
while (
|
|
19652
|
+
while (ts18.isParenthesizedExpression(parsed))
|
|
19428
19653
|
parsed = parsed.expression;
|
|
19429
|
-
if (!
|
|
19654
|
+
if (!ts18.isObjectLiteralExpression(parsed))
|
|
19430
19655
|
return null;
|
|
19431
19656
|
for (const prop of parsed.properties) {
|
|
19432
|
-
if (!
|
|
19657
|
+
if (!ts18.isPropertyAssignment(prop))
|
|
19433
19658
|
continue;
|
|
19434
19659
|
const name = prop.name;
|
|
19435
|
-
const propKey =
|
|
19660
|
+
const propKey = ts18.isIdentifier(name) || ts18.isStringLiteral(name) || ts18.isNoSubstitutionTemplateLiteral(name) ? name.text : null;
|
|
19436
19661
|
if (propKey !== key)
|
|
19437
19662
|
continue;
|
|
19438
19663
|
let v = prop.initializer;
|
|
19439
|
-
while (
|
|
19664
|
+
while (ts18.isParenthesizedExpression(v))
|
|
19440
19665
|
v = v.expression;
|
|
19441
|
-
if (
|
|
19666
|
+
if (ts18.isNumericLiteral(v))
|
|
19442
19667
|
return { kind: "number", text: v.text };
|
|
19443
|
-
if (
|
|
19668
|
+
if (ts18.isStringLiteral(v) || ts18.isNoSubstitutionTemplateLiteral(v)) {
|
|
19444
19669
|
return { kind: "string", text: v.text };
|
|
19445
19670
|
}
|
|
19446
19671
|
return null;
|
|
@@ -19448,28 +19673,28 @@ function lookupStaticRecordLiteral(objectName, key, constants) {
|
|
|
19448
19673
|
return null;
|
|
19449
19674
|
}
|
|
19450
19675
|
function evalStringArrayJoin(source) {
|
|
19451
|
-
const sf =
|
|
19676
|
+
const sf = ts18.createSourceFile("__join.ts", `const __x = (${source});`, ts18.ScriptTarget.Latest, false);
|
|
19452
19677
|
const stmt = sf.statements[0];
|
|
19453
|
-
if (!stmt || !
|
|
19678
|
+
if (!stmt || !ts18.isVariableStatement(stmt))
|
|
19454
19679
|
return null;
|
|
19455
19680
|
let node = stmt.declarationList.declarations[0]?.initializer;
|
|
19456
|
-
while (node &&
|
|
19681
|
+
while (node && ts18.isParenthesizedExpression(node))
|
|
19457
19682
|
node = node.expression;
|
|
19458
|
-
if (!node || !
|
|
19683
|
+
if (!node || !ts18.isCallExpression(node))
|
|
19459
19684
|
return null;
|
|
19460
19685
|
const callee = node.expression;
|
|
19461
|
-
if (!
|
|
19686
|
+
if (!ts18.isPropertyAccessExpression(callee))
|
|
19462
19687
|
return null;
|
|
19463
19688
|
if (callee.name.text !== "join")
|
|
19464
19689
|
return null;
|
|
19465
19690
|
let recv = callee.expression;
|
|
19466
|
-
while (
|
|
19691
|
+
while (ts18.isParenthesizedExpression(recv))
|
|
19467
19692
|
recv = recv.expression;
|
|
19468
|
-
if (!
|
|
19693
|
+
if (!ts18.isArrayLiteralExpression(recv))
|
|
19469
19694
|
return null;
|
|
19470
19695
|
const parts = [];
|
|
19471
19696
|
for (const el of recv.elements) {
|
|
19472
|
-
if (
|
|
19697
|
+
if (ts18.isStringLiteral(el) || ts18.isNoSubstitutionTemplateLiteral(el)) {
|
|
19473
19698
|
parts.push(el.text);
|
|
19474
19699
|
} else {
|
|
19475
19700
|
return null;
|
|
@@ -19478,7 +19703,7 @@ function evalStringArrayJoin(source) {
|
|
|
19478
19703
|
let sep2 = ",";
|
|
19479
19704
|
if (node.arguments.length >= 1) {
|
|
19480
19705
|
const arg = node.arguments[0];
|
|
19481
|
-
if (
|
|
19706
|
+
if (ts18.isStringLiteral(arg) || ts18.isNoSubstitutionTemplateLiteral(arg))
|
|
19482
19707
|
sep2 = arg.text;
|
|
19483
19708
|
else
|
|
19484
19709
|
return null;
|
|
@@ -19486,11 +19711,11 @@ function evalStringArrayJoin(source) {
|
|
|
19486
19711
|
return parts.join(sep2);
|
|
19487
19712
|
}
|
|
19488
19713
|
function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
|
|
19489
|
-
if (!
|
|
19714
|
+
if (!ts18.isElementAccessExpression(val))
|
|
19490
19715
|
return null;
|
|
19491
19716
|
const obj = val.expression;
|
|
19492
19717
|
const arg = val.argumentExpression;
|
|
19493
|
-
if (!
|
|
19718
|
+
if (!ts18.isIdentifier(obj) || !ts18.isIdentifier(arg))
|
|
19494
19719
|
return null;
|
|
19495
19720
|
let indexPropName;
|
|
19496
19721
|
let defaultKey;
|
|
@@ -19506,35 +19731,35 @@ function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
|
|
|
19506
19731
|
const constInfo = localConstants.find((c) => c.name === obj.text && c.isModule);
|
|
19507
19732
|
if (constInfo?.value === undefined)
|
|
19508
19733
|
return null;
|
|
19509
|
-
const sf =
|
|
19734
|
+
const sf = ts18.createSourceFile("__rec.ts", `(${constInfo.value})`, ts18.ScriptTarget.Latest, true);
|
|
19510
19735
|
if (sf.statements.length !== 1)
|
|
19511
19736
|
return null;
|
|
19512
19737
|
const stmt = sf.statements[0];
|
|
19513
|
-
if (!
|
|
19738
|
+
if (!ts18.isExpressionStatement(stmt))
|
|
19514
19739
|
return null;
|
|
19515
19740
|
let parsed = stmt.expression;
|
|
19516
|
-
while (
|
|
19741
|
+
while (ts18.isParenthesizedExpression(parsed))
|
|
19517
19742
|
parsed = parsed.expression;
|
|
19518
|
-
if (!
|
|
19743
|
+
if (!ts18.isObjectLiteralExpression(parsed))
|
|
19519
19744
|
return null;
|
|
19520
19745
|
const entries = [];
|
|
19521
19746
|
for (const prop of parsed.properties) {
|
|
19522
|
-
if (!
|
|
19747
|
+
if (!ts18.isPropertyAssignment(prop))
|
|
19523
19748
|
return null;
|
|
19524
19749
|
let key;
|
|
19525
|
-
if (
|
|
19750
|
+
if (ts18.isIdentifier(prop.name)) {
|
|
19526
19751
|
key = prop.name.text;
|
|
19527
|
-
} else if (
|
|
19752
|
+
} else if (ts18.isStringLiteral(prop.name) || ts18.isNoSubstitutionTemplateLiteral(prop.name)) {
|
|
19528
19753
|
key = prop.name.text;
|
|
19529
19754
|
} else {
|
|
19530
19755
|
return null;
|
|
19531
19756
|
}
|
|
19532
19757
|
let v = prop.initializer;
|
|
19533
|
-
while (
|
|
19758
|
+
while (ts18.isParenthesizedExpression(v))
|
|
19534
19759
|
v = v.expression;
|
|
19535
|
-
if (
|
|
19760
|
+
if (ts18.isNumericLiteral(v)) {
|
|
19536
19761
|
entries.push({ key, value: { kind: "number", text: v.text } });
|
|
19537
|
-
} else if (
|
|
19762
|
+
} else if (ts18.isStringLiteral(v) || ts18.isNoSubstitutionTemplateLiteral(v)) {
|
|
19538
19763
|
entries.push({ key, value: { kind: "string", text: v.text } });
|
|
19539
19764
|
} else {
|
|
19540
19765
|
return null;
|
|
@@ -19587,83 +19812,14 @@ function computeSsrSeedPlan(metadata) {
|
|
|
19587
19812
|
return { baseScope, steps };
|
|
19588
19813
|
}
|
|
19589
19814
|
|
|
19590
|
-
// src/rich-type-evidence.ts
|
|
19591
|
-
var HOST_RICH_TYPE_NAMES = new Set([
|
|
19592
|
-
"Date",
|
|
19593
|
-
"Map",
|
|
19594
|
-
"Set",
|
|
19595
|
-
"WeakMap",
|
|
19596
|
-
"WeakSet",
|
|
19597
|
-
"URL",
|
|
19598
|
-
"URLSearchParams",
|
|
19599
|
-
"RegExp",
|
|
19600
|
-
"Promise",
|
|
19601
|
-
"Error",
|
|
19602
|
-
"Symbol",
|
|
19603
|
-
"BigInt",
|
|
19604
|
-
"Function"
|
|
19605
|
-
]);
|
|
19606
|
-
function baseTypeName(raw) {
|
|
19607
|
-
const idx = raw.indexOf("<");
|
|
19608
|
-
return (idx === -1 ? raw : raw.slice(0, idx)).trim();
|
|
19609
|
-
}
|
|
19610
|
-
function isNullishArm(t) {
|
|
19611
|
-
if (t.kind === "primitive" && (t.primitive === "null" || t.primitive === "undefined"))
|
|
19612
|
-
return true;
|
|
19613
|
-
return t.kind === "unknown" && (t.raw === "null" || t.raw === "undefined");
|
|
19614
|
-
}
|
|
19615
|
-
function stripUnion(type) {
|
|
19616
|
-
if (!type || type.kind !== "union" || !type.unionTypes)
|
|
19617
|
-
return type;
|
|
19618
|
-
const nonNullish = type.unionTypes.filter((t) => !isNullishArm(t));
|
|
19619
|
-
return nonNullish.length === 1 ? stripUnion(nonNullish[0]) : type;
|
|
19620
|
-
}
|
|
19621
|
-
function derefNamedType(type, meta) {
|
|
19622
|
-
if (type.kind !== "interface")
|
|
19623
|
-
return type;
|
|
19624
|
-
if (type.properties && type.properties.length > 0)
|
|
19625
|
-
return type;
|
|
19626
|
-
const name = baseTypeName(type.raw);
|
|
19627
|
-
const def = meta.typeDefinitions.find((d) => d.name === name);
|
|
19628
|
-
if (!def?.properties)
|
|
19629
|
-
return type;
|
|
19630
|
-
return { ...type, properties: def.properties };
|
|
19631
|
-
}
|
|
19632
|
-
function lookupProperty(objType, propName, meta) {
|
|
19633
|
-
const stripped = stripUnion(objType);
|
|
19634
|
-
if (!stripped)
|
|
19635
|
-
return null;
|
|
19636
|
-
const deref = derefNamedType(stripped, meta);
|
|
19637
|
-
const prop = deref.properties?.find((p) => p.name === propName);
|
|
19638
|
-
return prop ? stripUnion(prop.type) : null;
|
|
19639
|
-
}
|
|
19640
|
-
function resolveReceiverType(expr, meta, bindings) {
|
|
19641
|
-
if (expr.kind === "identifier") {
|
|
19642
|
-
if (bindings.has(expr.name))
|
|
19643
|
-
return stripUnion(bindings.get(expr.name) ?? null);
|
|
19644
|
-
if (meta.propsObjectName !== null) {
|
|
19645
|
-
return expr.name === meta.propsObjectName ? stripUnion(meta.propsType) : null;
|
|
19646
|
-
}
|
|
19647
|
-
const param = meta.propsParams.find((p) => p.name === expr.name && !p.isRest);
|
|
19648
|
-
if (!param)
|
|
19649
|
-
return null;
|
|
19650
|
-
return lookupProperty(meta.propsType, param.sourceName ?? param.name, meta);
|
|
19651
|
-
}
|
|
19652
|
-
if (expr.kind === "member" && !expr.computed) {
|
|
19653
|
-
const objType = resolveReceiverType(expr.object, meta, bindings);
|
|
19654
|
-
return lookupProperty(objType, expr.property, meta);
|
|
19655
|
-
}
|
|
19656
|
-
return null;
|
|
19657
|
-
}
|
|
19658
|
-
|
|
19659
19815
|
// src/rich-type-refusal.ts
|
|
19660
|
-
var
|
|
19816
|
+
var EMPTY_BINDINGS2 = new Map;
|
|
19661
19817
|
function checkRichTypeMethodCalls(root, metadata, errors) {
|
|
19662
19818
|
if (!metadata.propsType)
|
|
19663
19819
|
return;
|
|
19664
19820
|
const matchers = prepareLoweringMatchers(metadata);
|
|
19665
19821
|
const seen = new Set;
|
|
19666
|
-
walkNode(root, metadata,
|
|
19822
|
+
walkNode(root, metadata, EMPTY_BINDINGS2, matchers, errors, seen);
|
|
19667
19823
|
}
|
|
19668
19824
|
function isLoweringClaimed(matchers, callee, args) {
|
|
19669
19825
|
return matchers.some((m) => m(callee, args) !== null);
|
|
@@ -20375,7 +20531,7 @@ function compileJSX(source, filePath, options) {
|
|
|
20375
20531
|
return { files, errors };
|
|
20376
20532
|
}
|
|
20377
20533
|
// src/shared-program.ts
|
|
20378
|
-
import
|
|
20534
|
+
import ts19 from "typescript";
|
|
20379
20535
|
function commonParent(paths) {
|
|
20380
20536
|
if (paths.length === 0)
|
|
20381
20537
|
return process.cwd();
|
|
@@ -20396,10 +20552,10 @@ function commonParent(paths) {
|
|
|
20396
20552
|
function createProgramForCorpus(files, options = {}) {
|
|
20397
20553
|
const baseUrl = options.baseUrl ?? commonParent(files);
|
|
20398
20554
|
const compilerOptions = {
|
|
20399
|
-
target:
|
|
20400
|
-
module:
|
|
20401
|
-
moduleResolution:
|
|
20402
|
-
jsx:
|
|
20555
|
+
target: ts19.ScriptTarget.Latest,
|
|
20556
|
+
module: ts19.ModuleKind.ESNext,
|
|
20557
|
+
moduleResolution: ts19.ModuleResolutionKind.Bundler,
|
|
20558
|
+
jsx: ts19.JsxEmit.ReactJSX,
|
|
20403
20559
|
strict: true,
|
|
20404
20560
|
skipLibCheck: true,
|
|
20405
20561
|
noEmit: true,
|
|
@@ -20409,7 +20565,7 @@ function createProgramForCorpus(files, options = {}) {
|
|
|
20409
20565
|
...options.compilerOptions
|
|
20410
20566
|
};
|
|
20411
20567
|
const absolute = files.map((f) => path_default.resolve(f));
|
|
20412
|
-
return
|
|
20568
|
+
return ts19.createProgram(absolute, compilerOptions, undefined, options.oldProgram);
|
|
20413
20569
|
}
|
|
20414
20570
|
// src/adapters/interface.ts
|
|
20415
20571
|
class BaseAdapter {
|
|
@@ -21222,7 +21378,7 @@ var queryHrefPlugin = {
|
|
|
21222
21378
|
};
|
|
21223
21379
|
}
|
|
21224
21380
|
};
|
|
21225
|
-
var BUILTIN_LOWERING_PLUGINS = [queryHrefPlugin];
|
|
21381
|
+
var BUILTIN_LOWERING_PLUGINS = [queryHrefPlugin, datePlugin];
|
|
21226
21382
|
function registerBuiltinLoweringPlugins() {
|
|
21227
21383
|
for (const plugin of BUILTIN_LOWERING_PLUGINS)
|
|
21228
21384
|
registerLoweringPlugin(plugin);
|
|
@@ -21348,7 +21504,7 @@ function dangerousInnerHtmlDiagnostic(expr, loc, reason) {
|
|
|
21348
21504
|
};
|
|
21349
21505
|
}
|
|
21350
21506
|
// src/combine-client-js.ts
|
|
21351
|
-
import
|
|
21507
|
+
import ts20 from "typescript";
|
|
21352
21508
|
var CHILD_PLACEHOLDER_RE = /import '\/\* @bf-child:(\w+) \*\/'/g;
|
|
21353
21509
|
function combineParentChildClientJs(files) {
|
|
21354
21510
|
const result = new Map;
|
|
@@ -21405,10 +21561,10 @@ function combineParentChildClientJs(files) {
|
|
|
21405
21561
|
return result;
|
|
21406
21562
|
}
|
|
21407
21563
|
function parseAndMerge(content, importsBySource, otherImports, codeSections) {
|
|
21408
|
-
const sourceFile =
|
|
21564
|
+
const sourceFile = ts20.createSourceFile("combine.js", content, ts20.ScriptTarget.Latest, false, ts20.ScriptKind.JS);
|
|
21409
21565
|
const importSpans = [];
|
|
21410
21566
|
for (const stmt of sourceFile.statements) {
|
|
21411
|
-
if (!
|
|
21567
|
+
if (!ts20.isImportDeclaration(stmt))
|
|
21412
21568
|
continue;
|
|
21413
21569
|
const start = stmt.getStart(sourceFile);
|
|
21414
21570
|
const end = stmt.getEnd();
|
|
@@ -21418,8 +21574,8 @@ function parseAndMerge(content, importsBySource, otherImports, codeSections) {
|
|
|
21418
21574
|
continue;
|
|
21419
21575
|
const clause = stmt.importClause;
|
|
21420
21576
|
const bindings = clause?.namedBindings;
|
|
21421
|
-
const specifier =
|
|
21422
|
-
if (clause && !clause.name && bindings &&
|
|
21577
|
+
const specifier = ts20.isStringLiteral(stmt.moduleSpecifier) ? stmt.moduleSpecifier.text : "";
|
|
21578
|
+
if (clause && !clause.name && bindings && ts20.isNamedImports(bindings)) {
|
|
21423
21579
|
if (!importsBySource.has(specifier)) {
|
|
21424
21580
|
importsBySource.set(specifier, new Set);
|
|
21425
21581
|
}
|
|
@@ -21582,7 +21738,7 @@ function escapeRe(s) {
|
|
|
21582
21738
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
21583
21739
|
}
|
|
21584
21740
|
// src/debug.ts
|
|
21585
|
-
import
|
|
21741
|
+
import ts21 from "typescript";
|
|
21586
21742
|
function buildComponentGraph(source, filePath, componentName) {
|
|
21587
21743
|
const ctx = analyzeComponent(source, filePath, componentName);
|
|
21588
21744
|
if (!ctx.jsxReturn) {
|
|
@@ -22867,7 +23023,7 @@ function truncateExpr(expr, max = 40) {
|
|
|
22867
23023
|
function exprReadsPropMember(expr, propsObjectName) {
|
|
22868
23024
|
let sf;
|
|
22869
23025
|
try {
|
|
22870
|
-
sf =
|
|
23026
|
+
sf = ts21.createSourceFile("__attr.tsx", `(${expr})`, ts21.ScriptTarget.Latest, true, ts21.ScriptKind.TSX);
|
|
22871
23027
|
} catch {
|
|
22872
23028
|
return false;
|
|
22873
23029
|
}
|
|
@@ -22875,11 +23031,11 @@ function exprReadsPropMember(expr, propsObjectName) {
|
|
|
22875
23031
|
const visit3 = (n) => {
|
|
22876
23032
|
if (found)
|
|
22877
23033
|
return;
|
|
22878
|
-
if (
|
|
23034
|
+
if (ts21.isPropertyAccessExpression(n) && ts21.isIdentifier(n.expression) && n.expression.text === propsObjectName && n.name.text !== "children") {
|
|
22879
23035
|
found = true;
|
|
22880
23036
|
return;
|
|
22881
23037
|
}
|
|
22882
|
-
|
|
23038
|
+
ts21.forEachChild(n, visit3);
|
|
22883
23039
|
};
|
|
22884
23040
|
visit3(sf);
|
|
22885
23041
|
return found;
|
|
@@ -22949,7 +23105,7 @@ function findSourceFile2(meta) {
|
|
|
22949
23105
|
return null;
|
|
22950
23106
|
}
|
|
22951
23107
|
// src/profiler.ts
|
|
22952
|
-
import
|
|
23108
|
+
import ts22 from "typescript";
|
|
22953
23109
|
var PROFILE_SCHEMA_VERSION = 1;
|
|
22954
23110
|
var DEFAULT_FANOUT_THRESHOLD = 8;
|
|
22955
23111
|
function buildStaticBudget(source, filePath, componentName, options = {}) {
|
|
@@ -23219,15 +23375,15 @@ function joinProfilerEvents(events, index) {
|
|
|
23219
23375
|
return { joined, unattributed, diagnostics };
|
|
23220
23376
|
}
|
|
23221
23377
|
function findUninstrumentedEffects(source, filePath, instrumentedLines) {
|
|
23222
|
-
const sf =
|
|
23378
|
+
const sf = ts22.createSourceFile(filePath, source, ts22.ScriptTarget.Latest, true, ts22.ScriptKind.TSX);
|
|
23223
23379
|
const out = [];
|
|
23224
23380
|
const visit3 = (node) => {
|
|
23225
|
-
if (
|
|
23381
|
+
if (ts22.isCallExpression(node) && ts22.isIdentifier(node.expression) && node.expression.text === "createEffect") {
|
|
23226
23382
|
const line = sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;
|
|
23227
23383
|
if (!instrumentedLines.has(line))
|
|
23228
23384
|
out.push({ file: filePath, line });
|
|
23229
23385
|
}
|
|
23230
|
-
|
|
23386
|
+
ts22.forEachChild(node, visit3);
|
|
23231
23387
|
};
|
|
23232
23388
|
visit3(sf);
|
|
23233
23389
|
out.sort((a, b) => a.line - b.line);
|
|
@@ -23535,13 +23691,13 @@ function assessBatchSafety(args) {
|
|
|
23535
23691
|
const signalGetters = new Set(args.graph.signals.map((s) => s.name));
|
|
23536
23692
|
let sf;
|
|
23537
23693
|
try {
|
|
23538
|
-
sf =
|
|
23694
|
+
sf = ts22.createSourceFile("__h.ts", `const __h = ${args.handler}`, ts22.ScriptTarget.Latest, true);
|
|
23539
23695
|
} catch {
|
|
23540
23696
|
return "unverified";
|
|
23541
23697
|
}
|
|
23542
23698
|
const calls = [];
|
|
23543
23699
|
const visit3 = (node) => {
|
|
23544
|
-
if (
|
|
23700
|
+
if (ts22.isCallExpression(node) && ts22.isIdentifier(node.expression)) {
|
|
23545
23701
|
const name = node.expression.text;
|
|
23546
23702
|
if (setters.has(name))
|
|
23547
23703
|
calls.push({ pos: node.getStart(sf), kind: "write" });
|
|
@@ -23550,7 +23706,7 @@ function assessBatchSafety(args) {
|
|
|
23550
23706
|
else if (!signalGetters.has(name) && !memoNames.has(name))
|
|
23551
23707
|
calls.push({ pos: node.getStart(sf), kind: "risky" });
|
|
23552
23708
|
}
|
|
23553
|
-
|
|
23709
|
+
ts22.forEachChild(node, visit3);
|
|
23554
23710
|
};
|
|
23555
23711
|
visit3(sf);
|
|
23556
23712
|
calls.sort((a, b) => a.pos - b.pos);
|