@barefootjs/jsx 0.30.6 → 0.31.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/adapters/interface.d.ts +61 -20
- package/dist/adapters/interface.d.ts.map +1 -1
- package/dist/analyzer.d.ts +1 -1
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/index.d.ts +0 -120
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +322 -263
- package/dist/ir-to-client-js/emit-registration.d.ts.map +1 -1
- package/dist/ir-to-client-js/generate-init.d.ts.map +1 -1
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts +7 -0
- package/dist/ir-to-client-js/prune-unused-prop-extractions.d.ts.map +1 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/value-references.d.ts +7 -7
- package/dist/value-references.d.ts.map +1 -1
- package/package.json +3 -7
- package/src/__tests__/__snapshots__/doc-examples.test.ts.snap +183 -312
- package/src/__tests__/bf050-single-multi-symmetry.test.ts +118 -0
- package/src/__tests__/client-js-generation.test.ts +5 -1
- package/src/__tests__/doc-examples.test.ts +5 -1
- package/src/__tests__/prune-unused-prop-extractions.test.ts +78 -0
- package/src/adapters/interface.ts +61 -20
- package/src/analyzer.ts +16 -5
- package/src/compiler.ts +41 -3
- package/src/index.ts +0 -123
- package/src/ir-to-client-js/emit-registration.ts +9 -0
- package/src/ir-to-client-js/generate-init.ts +4 -1
- package/src/ir-to-client-js/index.ts +5 -1
- package/src/ir-to-client-js/prune-unused-prop-extractions.ts +108 -0
- package/src/types.ts +25 -0
- package/src/value-references.ts +7 -7
- package/dist/import-map.d.ts +0 -56
- package/dist/import-map.d.ts.map +0 -1
- package/dist/import-map.js +0 -18
- package/src/__tests__/import-map.test.ts +0 -75
- package/src/import-map.ts +0 -72
package/dist/index.js
CHANGED
|
@@ -176,22 +176,6 @@ function findTopLevelTemplateLiterals(code) {
|
|
|
176
176
|
return out;
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
// src/import-map.ts
|
|
180
|
-
function escapeHtmlAttr(value) {
|
|
181
|
-
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<");
|
|
182
|
-
}
|
|
183
|
-
function renderImportMapHtml(manifest) {
|
|
184
|
-
const imports = manifest.importmap?.imports ?? {};
|
|
185
|
-
const json = JSON.stringify({ imports }).replace(/</g, "\\u003c");
|
|
186
|
-
const lines = [`<script type="importmap">${json}</script>`];
|
|
187
|
-
for (const href of manifest.preloads ?? []) {
|
|
188
|
-
lines.push(`<link rel="modulepreload" href="${escapeHtmlAttr(href)}" crossorigin>`);
|
|
189
|
-
}
|
|
190
|
-
return lines.join(`
|
|
191
|
-
`) + `
|
|
192
|
-
`;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
179
|
// src/analyzer.ts
|
|
196
180
|
import ts8 from "typescript";
|
|
197
181
|
|
|
@@ -5822,9 +5806,9 @@ function createProgramForFile(source, filePath) {
|
|
|
5822
5806
|
return null;
|
|
5823
5807
|
}
|
|
5824
5808
|
}
|
|
5825
|
-
function analyzeComponent(source, filePath, targetComponentName, program, acceptsCallbackBody) {
|
|
5809
|
+
function analyzeComponent(source, filePath, targetComponentName, program, acceptsCallbackBody, programIsShared) {
|
|
5826
5810
|
incrementCounter("filesAnalyzed");
|
|
5827
|
-
const hadSharedProgram = program !== undefined;
|
|
5811
|
+
const hadSharedProgram = programIsShared ?? program !== undefined;
|
|
5828
5812
|
const prescan = prescanReactiveFactoriesInSource(source, filePath);
|
|
5829
5813
|
const rewritten = prescan.factories.size > 0 ? rewriteFactoryCallsInSource(source, prescan) : null;
|
|
5830
5814
|
if (rewritten) {
|
|
@@ -16738,6 +16722,9 @@ function emitRegistrationAndHydration(lines, ctx, _ir, graph, inlinability) {
|
|
|
16738
16722
|
defParts.push("comment: true");
|
|
16739
16723
|
}
|
|
16740
16724
|
const registryKey = nameForRegistryRef(name);
|
|
16725
|
+
if (registryKey !== name) {
|
|
16726
|
+
defParts.push(`name: '${name}'`);
|
|
16727
|
+
}
|
|
16741
16728
|
const hydrateLine = `hydrate('${registryKey}', { ${defParts.join(", ")} })`;
|
|
16742
16729
|
const shimLine = `export function ${name}(${PROPS_PARAM}, __bfKey) { return createComponent('${registryKey}', ${PROPS_PARAM}, __bfKey) }`;
|
|
16743
16730
|
return `${hydrateLine}
|
|
@@ -17448,6 +17435,59 @@ function resolveFinalImports(generatedCode, ir, localImportPrefixes) {
|
|
|
17448
17435
|
`);
|
|
17449
17436
|
}
|
|
17450
17437
|
|
|
17438
|
+
// src/ir-to-client-js/prune-unused-prop-extractions.ts
|
|
17439
|
+
import ts15 from "typescript";
|
|
17440
|
+
function propExtractionName(stmt) {
|
|
17441
|
+
if (!ts15.isVariableStatement(stmt))
|
|
17442
|
+
return null;
|
|
17443
|
+
const decls = stmt.declarationList.declarations;
|
|
17444
|
+
if (decls.length !== 1)
|
|
17445
|
+
return null;
|
|
17446
|
+
const decl = decls[0];
|
|
17447
|
+
if (!ts15.isIdentifier(decl.name) || !decl.initializer)
|
|
17448
|
+
return null;
|
|
17449
|
+
let core = decl.initializer;
|
|
17450
|
+
if (ts15.isBinaryExpression(core) && core.operatorToken.kind === ts15.SyntaxKind.QuestionQuestionToken) {
|
|
17451
|
+
core = core.left;
|
|
17452
|
+
}
|
|
17453
|
+
if (!ts15.isPropertyAccessExpression(core))
|
|
17454
|
+
return null;
|
|
17455
|
+
if (!ts15.isIdentifier(core.expression) || core.expression.text !== PROPS_PARAM)
|
|
17456
|
+
return null;
|
|
17457
|
+
if (core.name.text !== decl.name.text)
|
|
17458
|
+
return null;
|
|
17459
|
+
return decl.name.text;
|
|
17460
|
+
}
|
|
17461
|
+
function pruneUnusedPropExtractions(code) {
|
|
17462
|
+
for (let round = 0;round < 10; round++) {
|
|
17463
|
+
const referenced = collectValueReferencedNames(code);
|
|
17464
|
+
if (referenced === null) {
|
|
17465
|
+
console.warn("[barefootjs] pruneUnusedPropExtractions: generated code did not parse; skipping prune");
|
|
17466
|
+
return code;
|
|
17467
|
+
}
|
|
17468
|
+
const sourceFile = ts15.createSourceFile("generated.js", code, ts15.ScriptTarget.Latest, false, ts15.ScriptKind.JS);
|
|
17469
|
+
const spans = [];
|
|
17470
|
+
for (const stmt of sourceFile.statements) {
|
|
17471
|
+
if (!ts15.isFunctionDeclaration(stmt) || !stmt.name?.text.startsWith("init") || !stmt.body)
|
|
17472
|
+
continue;
|
|
17473
|
+
for (const inner of stmt.body.statements) {
|
|
17474
|
+
const name = propExtractionName(inner);
|
|
17475
|
+
if (name !== null && !referenced.has(name)) {
|
|
17476
|
+
spans.push({ start: inner.getFullStart(), end: inner.getEnd() });
|
|
17477
|
+
}
|
|
17478
|
+
}
|
|
17479
|
+
}
|
|
17480
|
+
if (spans.length === 0)
|
|
17481
|
+
return code;
|
|
17482
|
+
let next = code;
|
|
17483
|
+
for (const { start, end } of spans.sort((a, b) => b.start - a.start)) {
|
|
17484
|
+
next = next.slice(0, start) + next.slice(end);
|
|
17485
|
+
}
|
|
17486
|
+
code = next;
|
|
17487
|
+
}
|
|
17488
|
+
return code;
|
|
17489
|
+
}
|
|
17490
|
+
|
|
17451
17491
|
// src/ir-to-client-js/phases/conditional-slot-ids.ts
|
|
17452
17492
|
function collectConditionalSlotIds(ctx) {
|
|
17453
17493
|
const slots = new Set;
|
|
@@ -18872,7 +18912,7 @@ function analyzeLazyConditional(cond, indexParam, arms) {
|
|
|
18872
18912
|
}
|
|
18873
18913
|
|
|
18874
18914
|
// src/ir-to-client-js/control-flow/plan/lazy-preamble.ts
|
|
18875
|
-
import
|
|
18915
|
+
import ts16 from "typescript";
|
|
18876
18916
|
var NO_PREAMBLE = {
|
|
18877
18917
|
lazySafe: true,
|
|
18878
18918
|
facts: { declaredNames: new Set, freeNames: new Set }
|
|
@@ -18892,12 +18932,12 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
|
|
|
18892
18932
|
if (text.trim().length === 0)
|
|
18893
18933
|
return NO_PREAMBLE;
|
|
18894
18934
|
const declaredNames = new Set;
|
|
18895
|
-
const sf =
|
|
18935
|
+
const sf = ts16.createSourceFile("__lazy_preamble__.ts", text, ts16.ScriptTarget.Latest, true, ts16.ScriptKind.TS);
|
|
18896
18936
|
for (const stmt of sf.statements) {
|
|
18897
|
-
if (!
|
|
18898
|
-
return NO2(`map-callback preamble has a non-declaration statement (${
|
|
18937
|
+
if (!ts16.isVariableStatement(stmt)) {
|
|
18938
|
+
return NO2(`map-callback preamble has a non-declaration statement (${ts16.SyntaxKind[stmt.kind]})`);
|
|
18899
18939
|
}
|
|
18900
|
-
const isConst = (stmt.declarationList.flags &
|
|
18940
|
+
const isConst = (stmt.declarationList.flags & ts16.NodeFlags.Const) !== 0;
|
|
18901
18941
|
if (!isConst)
|
|
18902
18942
|
return NO2("map-callback preamble declares a mutable binding (let/var)");
|
|
18903
18943
|
for (const decl of stmt.declarationList.declarations) {
|
|
@@ -18926,12 +18966,12 @@ function analyzeLazyPreamble(preamble, indexParam, primableNames) {
|
|
|
18926
18966
|
return { lazySafe: true, facts: { declaredNames, freeNames } };
|
|
18927
18967
|
}
|
|
18928
18968
|
function collectBindingNames3(name, out) {
|
|
18929
|
-
if (
|
|
18969
|
+
if (ts16.isIdentifier(name)) {
|
|
18930
18970
|
out.add(name.text);
|
|
18931
18971
|
return;
|
|
18932
18972
|
}
|
|
18933
18973
|
for (const element of name.elements) {
|
|
18934
|
-
if (
|
|
18974
|
+
if (ts16.isOmittedExpression(element))
|
|
18935
18975
|
continue;
|
|
18936
18976
|
collectBindingNames3(element.name, out);
|
|
18937
18977
|
}
|
|
@@ -18941,56 +18981,56 @@ function findImpureNode(root, primableNames) {
|
|
|
18941
18981
|
const visit3 = (node) => {
|
|
18942
18982
|
if (found)
|
|
18943
18983
|
return;
|
|
18944
|
-
if (
|
|
18984
|
+
if (ts16.isCallExpression(node)) {
|
|
18945
18985
|
const callee = node.expression;
|
|
18946
|
-
const isSignalRead =
|
|
18986
|
+
const isSignalRead = ts16.isIdentifier(callee) && primableNames.has(callee.text) && node.arguments.length === 0 && node.questionDotToken === undefined;
|
|
18947
18987
|
if (!isSignalRead) {
|
|
18948
18988
|
found = `call to ${callee.getText(callee.getSourceFile())}`;
|
|
18949
18989
|
return;
|
|
18950
18990
|
}
|
|
18951
18991
|
}
|
|
18952
|
-
if (
|
|
18992
|
+
if (ts16.isNewExpression(node)) {
|
|
18953
18993
|
found = "new expression";
|
|
18954
18994
|
return;
|
|
18955
18995
|
}
|
|
18956
|
-
if (
|
|
18996
|
+
if (ts16.isTaggedTemplateExpression(node)) {
|
|
18957
18997
|
found = "tagged template";
|
|
18958
18998
|
return;
|
|
18959
18999
|
}
|
|
18960
|
-
if (
|
|
19000
|
+
if (ts16.isAwaitExpression(node)) {
|
|
18961
19001
|
found = "await";
|
|
18962
19002
|
return;
|
|
18963
19003
|
}
|
|
18964
|
-
if (
|
|
19004
|
+
if (ts16.isYieldExpression(node)) {
|
|
18965
19005
|
found = "yield";
|
|
18966
19006
|
return;
|
|
18967
19007
|
}
|
|
18968
|
-
if (
|
|
19008
|
+
if (ts16.isPrefixUnaryExpression(node) || ts16.isPostfixUnaryExpression(node)) {
|
|
18969
19009
|
const op = node.operator;
|
|
18970
|
-
if (op ===
|
|
19010
|
+
if (op === ts16.SyntaxKind.PlusPlusToken || op === ts16.SyntaxKind.MinusMinusToken) {
|
|
18971
19011
|
found = "increment/decrement";
|
|
18972
19012
|
return;
|
|
18973
19013
|
}
|
|
18974
19014
|
}
|
|
18975
|
-
if (
|
|
19015
|
+
if (ts16.isDeleteExpression(node)) {
|
|
18976
19016
|
found = "delete";
|
|
18977
19017
|
return;
|
|
18978
19018
|
}
|
|
18979
|
-
if (
|
|
19019
|
+
if (ts16.isFunctionExpression(node) || ts16.isArrowFunction(node) || ts16.isClassExpression(node)) {
|
|
18980
19020
|
found = "function or class expression";
|
|
18981
19021
|
return;
|
|
18982
19022
|
}
|
|
18983
|
-
if (
|
|
19023
|
+
if (ts16.isBinaryExpression(node) && isAssignmentOperator(node.operatorToken.kind)) {
|
|
18984
19024
|
found = "assignment";
|
|
18985
19025
|
return;
|
|
18986
19026
|
}
|
|
18987
|
-
|
|
19027
|
+
ts16.forEachChild(node, visit3);
|
|
18988
19028
|
};
|
|
18989
19029
|
visit3(root);
|
|
18990
19030
|
return found;
|
|
18991
19031
|
}
|
|
18992
19032
|
function isAssignmentOperator(kind) {
|
|
18993
|
-
return kind >=
|
|
19033
|
+
return kind >= ts16.SyntaxKind.FirstAssignment && kind <= ts16.SyntaxKind.LastAssignment;
|
|
18994
19034
|
}
|
|
18995
19035
|
|
|
18996
19036
|
// src/ir-to-client-js/control-flow/plan/lazy-row-eligibility.ts
|
|
@@ -19520,7 +19560,7 @@ function buildArmBody(branch, options) {
|
|
|
19520
19560
|
}
|
|
19521
19561
|
|
|
19522
19562
|
// src/ir-to-client-js/emit-reactive.ts
|
|
19523
|
-
import
|
|
19563
|
+
import ts17 from "typescript";
|
|
19524
19564
|
|
|
19525
19565
|
// src/ir-to-client-js/control-flow/stringify/claim-plan.ts
|
|
19526
19566
|
function slotSpecLiteral(slot) {
|
|
@@ -19623,20 +19663,20 @@ function lowerToLocaleCallsInReactiveExpr(expr, matcher) {
|
|
|
19623
19663
|
return expr;
|
|
19624
19664
|
let sourceFile;
|
|
19625
19665
|
try {
|
|
19626
|
-
sourceFile =
|
|
19666
|
+
sourceFile = ts17.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts17.ScriptTarget.Latest, true, ts17.ScriptKind.TS);
|
|
19627
19667
|
} catch {
|
|
19628
19668
|
return expr;
|
|
19629
19669
|
}
|
|
19630
19670
|
const stmt = sourceFile.statements[0];
|
|
19631
|
-
if (!stmt || !
|
|
19671
|
+
if (!stmt || !ts17.isExpressionStatement(stmt))
|
|
19632
19672
|
return expr;
|
|
19633
|
-
const root =
|
|
19673
|
+
const root = ts17.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
19634
19674
|
const candidates = [];
|
|
19635
19675
|
const visit3 = (n) => {
|
|
19636
|
-
if (
|
|
19676
|
+
if (ts17.isCallExpression(n) && n.arguments.length === 2 && ts17.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && n.expression.name.text === "toLocaleDateString") {
|
|
19637
19677
|
candidates.push(n);
|
|
19638
19678
|
}
|
|
19639
|
-
|
|
19679
|
+
ts17.forEachChild(n, visit3);
|
|
19640
19680
|
};
|
|
19641
19681
|
visit3(root);
|
|
19642
19682
|
if (candidates.length === 0)
|
|
@@ -19672,20 +19712,20 @@ function lowerDateCallsInReactiveExpr(expr, matcher) {
|
|
|
19672
19712
|
return expr;
|
|
19673
19713
|
let sourceFile;
|
|
19674
19714
|
try {
|
|
19675
|
-
sourceFile =
|
|
19715
|
+
sourceFile = ts17.createSourceFile("__reactive_expr__.ts", `(${expr});`, ts17.ScriptTarget.Latest, true, ts17.ScriptKind.TS);
|
|
19676
19716
|
} catch {
|
|
19677
19717
|
return expr;
|
|
19678
19718
|
}
|
|
19679
19719
|
const stmt = sourceFile.statements[0];
|
|
19680
|
-
if (!stmt || !
|
|
19720
|
+
if (!stmt || !ts17.isExpressionStatement(stmt))
|
|
19681
19721
|
return expr;
|
|
19682
|
-
const root =
|
|
19722
|
+
const root = ts17.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
19683
19723
|
const candidates = [];
|
|
19684
19724
|
const visit3 = (n) => {
|
|
19685
|
-
if (
|
|
19725
|
+
if (ts17.isCallExpression(n) && n.arguments.length === 0 && ts17.isPropertyAccessExpression(n.expression) && !n.expression.questionDotToken && DATE_METHODS.has(n.expression.name.text)) {
|
|
19686
19726
|
candidates.push(n);
|
|
19687
19727
|
}
|
|
19688
|
-
|
|
19728
|
+
ts17.forEachChild(n, visit3);
|
|
19689
19729
|
};
|
|
19690
19730
|
visit3(root);
|
|
19691
19731
|
if (candidates.length === 0)
|
|
@@ -21688,20 +21728,20 @@ var PHASES = [
|
|
|
21688
21728
|
];
|
|
21689
21729
|
|
|
21690
21730
|
// src/ir-to-client-js/rewrite-props-object.ts
|
|
21691
|
-
import
|
|
21731
|
+
import ts18 from "typescript";
|
|
21692
21732
|
function rewritePropsObjectRef(code, propsObjectName) {
|
|
21693
21733
|
const srcPropsName = propsObjectName ?? "props";
|
|
21694
21734
|
if (srcPropsName === PROPS_PARAM)
|
|
21695
21735
|
return code;
|
|
21696
21736
|
if (!new RegExp(`\\b${srcPropsName}\\b`).test(code))
|
|
21697
21737
|
return code;
|
|
21698
|
-
const sourceFile =
|
|
21738
|
+
const sourceFile = ts18.createSourceFile("init-body.ts", code, ts18.ScriptTarget.Latest, true, ts18.ScriptKind.TS);
|
|
21699
21739
|
const spans = [];
|
|
21700
21740
|
function visit3(node) {
|
|
21701
|
-
if (
|
|
21741
|
+
if (ts18.isIdentifier(node) && node.text === srcPropsName && shouldRewrite(node)) {
|
|
21702
21742
|
spans.push([node.getStart(sourceFile), node.getEnd()]);
|
|
21703
21743
|
}
|
|
21704
|
-
|
|
21744
|
+
ts18.forEachChild(node, visit3);
|
|
21705
21745
|
}
|
|
21706
21746
|
visit3(sourceFile);
|
|
21707
21747
|
if (spans.length === 0)
|
|
@@ -21717,17 +21757,17 @@ function shouldRewrite(node) {
|
|
|
21717
21757
|
const parent = node.parent;
|
|
21718
21758
|
if (!parent)
|
|
21719
21759
|
return true;
|
|
21720
|
-
if (
|
|
21760
|
+
if (ts18.isPropertyAccessExpression(parent) && parent.name === node)
|
|
21721
21761
|
return false;
|
|
21722
|
-
if (
|
|
21762
|
+
if (ts18.isPropertyAssignment(parent) && parent.name === node)
|
|
21723
21763
|
return false;
|
|
21724
|
-
if (
|
|
21764
|
+
if (ts18.isShorthandPropertyAssignment(parent) && parent.name === node)
|
|
21725
21765
|
return false;
|
|
21726
|
-
if (
|
|
21766
|
+
if (ts18.isPropertySignature(parent) && parent.name === node)
|
|
21727
21767
|
return false;
|
|
21728
|
-
if (
|
|
21768
|
+
if (ts18.isPropertyDeclaration(parent) && parent.name === node)
|
|
21729
21769
|
return false;
|
|
21730
|
-
if (
|
|
21770
|
+
if (ts18.isBindingElement(parent) && parent.name === node)
|
|
21731
21771
|
return false;
|
|
21732
21772
|
return true;
|
|
21733
21773
|
}
|
|
@@ -21765,7 +21805,7 @@ function generateInitFunction(ir, ctx, siblingComponents, localImportPrefixes) {
|
|
|
21765
21805
|
generatedCode += `
|
|
21766
21806
|
` + hydrateLine;
|
|
21767
21807
|
const moduleConstantsCode = emitModuleLevelDeclarations(classification.moduleLevelConstants, classification.moduleLevelFunctions, classification.moduleLevelSignals, classification.moduleLevelMemos);
|
|
21768
|
-
const codeWithModuleConstants = generatedCode.replace(MODULE_CONSTANTS_PLACEHOLDER, () => moduleConstantsCode);
|
|
21808
|
+
const codeWithModuleConstants = pruneUnusedPropExtractions(generatedCode.replace(MODULE_CONSTANTS_PLACEHOLDER, () => moduleConstantsCode));
|
|
21769
21809
|
const allImportLines = resolveFinalImports(codeWithModuleConstants, ir, localImportPrefixes);
|
|
21770
21810
|
return codeWithModuleConstants.replace(IMPORT_PLACEHOLDER, () => allImportLines);
|
|
21771
21811
|
}
|
|
@@ -22083,7 +22123,8 @@ function generateTemplateOnlyMount(ir, ctx) {
|
|
|
22083
22123
|
lines.push("");
|
|
22084
22124
|
lines.push(`function init${name}() {}`);
|
|
22085
22125
|
lines.push("");
|
|
22086
|
-
|
|
22126
|
+
const nameField = registryKey !== name ? `, name: '${name}'` : "";
|
|
22127
|
+
lines.push(`hydrate('${registryKey}', { init: init${name}, template: (${PROPS_PARAM}) => \`${templateHtml}\`${nameField} })`);
|
|
22087
22128
|
lines.push(`export function ${name}(${PROPS_PARAM}, __bfKey) { return createComponent('${registryKey}', ${PROPS_PARAM}, __bfKey) }`);
|
|
22088
22129
|
const generatedCode = lines.join(`
|
|
22089
22130
|
`);
|
|
@@ -22357,7 +22398,7 @@ function walkIR2(node, visitor) {
|
|
|
22357
22398
|
}
|
|
22358
22399
|
|
|
22359
22400
|
// src/preprocess-inline-jsx-callbacks.ts
|
|
22360
|
-
import
|
|
22401
|
+
import ts19 from "typescript";
|
|
22361
22402
|
var SYNTHETIC_PREFIX = "BFInlineJsxCallback";
|
|
22362
22403
|
var MAX_FIXPOINT_ITERATIONS = 16;
|
|
22363
22404
|
function preprocessInlineJsxCallbacks(source, filePath) {
|
|
@@ -22379,8 +22420,8 @@ function preprocessInlineJsxCallbacks(source, filePath) {
|
|
|
22379
22420
|
return { source: current, errors, syntheticNames };
|
|
22380
22421
|
}
|
|
22381
22422
|
function runSinglePass(source, filePath, startingCounter) {
|
|
22382
|
-
const sourceFile =
|
|
22383
|
-
const hasUseClient = sourceFile.statements.some((stmt) =>
|
|
22423
|
+
const sourceFile = ts19.createSourceFile(filePath, source, ts19.ScriptTarget.Latest, true, ts19.ScriptKind.TSX);
|
|
22424
|
+
const hasUseClient = sourceFile.statements.some((stmt) => ts19.isExpressionStatement(stmt) && ts19.isStringLiteral(stmt.expression) && (stmt.expression.text === "use client" || stmt.expression.text === "'use client'"));
|
|
22384
22425
|
if (!hasUseClient) {
|
|
22385
22426
|
return { source, errors: [], syntheticNames: [], counterAfter: startingCounter };
|
|
22386
22427
|
}
|
|
@@ -22402,22 +22443,22 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
22402
22443
|
}
|
|
22403
22444
|
}
|
|
22404
22445
|
function visit3(node) {
|
|
22405
|
-
if (
|
|
22446
|
+
if (ts19.isJsxAttribute(node) && node.initializer && ts19.isJsxExpression(node.initializer) && node.initializer.expression) {
|
|
22406
22447
|
if (tryHandleArrowValue(node.initializer.expression)) {
|
|
22407
22448
|
return;
|
|
22408
22449
|
}
|
|
22409
22450
|
}
|
|
22410
|
-
if (
|
|
22451
|
+
if (ts19.isPropertyAssignment(node) && node.initializer) {
|
|
22411
22452
|
if (tryHandleArrowValue(node.initializer))
|
|
22412
22453
|
return;
|
|
22413
22454
|
}
|
|
22414
|
-
|
|
22455
|
+
ts19.forEachChild(node, visit3);
|
|
22415
22456
|
}
|
|
22416
22457
|
function tryHandleArrowValue(initializer) {
|
|
22417
22458
|
let expr = initializer;
|
|
22418
|
-
while (
|
|
22459
|
+
while (ts19.isParenthesizedExpression(expr))
|
|
22419
22460
|
expr = expr.expression;
|
|
22420
|
-
if (
|
|
22461
|
+
if (ts19.isArrowFunction(expr) && arrowBodyContainsJsx(expr)) {
|
|
22421
22462
|
return handleInlineArrow(expr);
|
|
22422
22463
|
}
|
|
22423
22464
|
return false;
|
|
@@ -22454,7 +22495,7 @@ function runSinglePass(source, filePath, startingCounter) {
|
|
|
22454
22495
|
replacements.push({ start: arrowStart, end: arrowEnd, text: name });
|
|
22455
22496
|
return true;
|
|
22456
22497
|
}
|
|
22457
|
-
|
|
22498
|
+
ts19.forEachChild(sourceFile, visit3);
|
|
22458
22499
|
if (replacements.length === 0) {
|
|
22459
22500
|
return { source, errors, syntheticNames, counterAfter: counter };
|
|
22460
22501
|
}
|
|
@@ -22477,11 +22518,11 @@ function errorMessageForCapture(captures) {
|
|
|
22477
22518
|
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.`;
|
|
22478
22519
|
}
|
|
22479
22520
|
function arrowBodyContainsJsx(arrow) {
|
|
22480
|
-
if (
|
|
22521
|
+
if (ts19.isBlock(arrow.body)) {
|
|
22481
22522
|
return blockReturnsJsx(arrow.body);
|
|
22482
22523
|
}
|
|
22483
22524
|
let body = arrow.body;
|
|
22484
|
-
while (
|
|
22525
|
+
while (ts19.isParenthesizedExpression(body))
|
|
22485
22526
|
body = body.expression;
|
|
22486
22527
|
return isJsxLike(body);
|
|
22487
22528
|
}
|
|
@@ -22490,24 +22531,24 @@ function blockReturnsJsx(block) {
|
|
|
22490
22531
|
function visit3(n) {
|
|
22491
22532
|
if (found)
|
|
22492
22533
|
return;
|
|
22493
|
-
if (
|
|
22534
|
+
if (ts19.isReturnStatement(n) && n.expression) {
|
|
22494
22535
|
let e = n.expression;
|
|
22495
|
-
while (
|
|
22536
|
+
while (ts19.isParenthesizedExpression(e))
|
|
22496
22537
|
e = e.expression;
|
|
22497
22538
|
if (isJsxLike(e)) {
|
|
22498
22539
|
found = true;
|
|
22499
22540
|
return;
|
|
22500
22541
|
}
|
|
22501
22542
|
}
|
|
22502
|
-
if (
|
|
22543
|
+
if (ts19.isArrowFunction(n) || ts19.isFunctionDeclaration(n) || ts19.isFunctionExpression(n))
|
|
22503
22544
|
return;
|
|
22504
|
-
|
|
22545
|
+
ts19.forEachChild(n, visit3);
|
|
22505
22546
|
}
|
|
22506
|
-
|
|
22547
|
+
ts19.forEachChild(block, visit3);
|
|
22507
22548
|
return found;
|
|
22508
22549
|
}
|
|
22509
22550
|
function isJsxLike(expr) {
|
|
22510
|
-
return
|
|
22551
|
+
return ts19.isJsxElement(expr) || ts19.isJsxSelfClosingElement(expr) || ts19.isJsxFragment(expr);
|
|
22511
22552
|
}
|
|
22512
22553
|
function collectArrowParamNames(arrow) {
|
|
22513
22554
|
const names = new Set;
|
|
@@ -22517,13 +22558,13 @@ function collectArrowParamNames(arrow) {
|
|
|
22517
22558
|
}
|
|
22518
22559
|
function collectBindingNames4(name, out) {
|
|
22519
22560
|
const push = Array.isArray(out) ? (n) => out.push(n) : (n) => out.add(n);
|
|
22520
|
-
if (
|
|
22561
|
+
if (ts19.isIdentifier(name)) {
|
|
22521
22562
|
push(name.text);
|
|
22522
|
-
} else if (
|
|
22563
|
+
} else if (ts19.isObjectBindingPattern(name)) {
|
|
22523
22564
|
name.elements.forEach((el) => collectBindingNames4(el.name, out));
|
|
22524
|
-
} else if (
|
|
22565
|
+
} else if (ts19.isArrayBindingPattern(name)) {
|
|
22525
22566
|
name.elements.forEach((el) => {
|
|
22526
|
-
if (!
|
|
22567
|
+
if (!ts19.isOmittedExpression(el))
|
|
22527
22568
|
collectBindingNames4(el.name, out);
|
|
22528
22569
|
});
|
|
22529
22570
|
}
|
|
@@ -22550,48 +22591,48 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22550
22591
|
return bound.includes(name);
|
|
22551
22592
|
}
|
|
22552
22593
|
function visit3(node) {
|
|
22553
|
-
if (
|
|
22594
|
+
if (ts19.isIdentifier(node)) {
|
|
22554
22595
|
const parent = node.parent;
|
|
22555
|
-
if (parent &&
|
|
22596
|
+
if (parent && ts19.isPropertyAccessExpression(parent) && parent.name === node)
|
|
22556
22597
|
return;
|
|
22557
|
-
if (parent &&
|
|
22598
|
+
if (parent && ts19.isPropertyAssignment(parent) && parent.name === node)
|
|
22558
22599
|
return;
|
|
22559
|
-
if (parent &&
|
|
22600
|
+
if (parent && ts19.isPropertySignature(parent) && parent.name === node)
|
|
22560
22601
|
return;
|
|
22561
|
-
if (parent &&
|
|
22602
|
+
if (parent && ts19.isPropertyDeclaration(parent) && parent.name === node)
|
|
22562
22603
|
return;
|
|
22563
|
-
if (parent &&
|
|
22604
|
+
if (parent && ts19.isMethodDeclaration(parent) && parent.name === node)
|
|
22564
22605
|
return;
|
|
22565
|
-
if (parent &&
|
|
22606
|
+
if (parent && ts19.isMethodSignature(parent) && parent.name === node)
|
|
22566
22607
|
return;
|
|
22567
|
-
if (parent &&
|
|
22608
|
+
if (parent && ts19.isGetAccessorDeclaration(parent) && parent.name === node)
|
|
22568
22609
|
return;
|
|
22569
|
-
if (parent &&
|
|
22610
|
+
if (parent && ts19.isSetAccessorDeclaration(parent) && parent.name === node)
|
|
22570
22611
|
return;
|
|
22571
|
-
if (parent &&
|
|
22612
|
+
if (parent && ts19.isEnumMember(parent) && parent.name === node)
|
|
22572
22613
|
return;
|
|
22573
|
-
if (parent &&
|
|
22614
|
+
if (parent && ts19.isBindingElement(parent) && parent.propertyName === node)
|
|
22574
22615
|
return;
|
|
22575
|
-
if (parent &&
|
|
22616
|
+
if (parent && ts19.isShorthandPropertyAssignment(parent) && parent.name === node) {
|
|
22576
22617
|
if (!isBound(node.text))
|
|
22577
22618
|
ids.add(node.text);
|
|
22578
22619
|
return;
|
|
22579
22620
|
}
|
|
22580
|
-
if (parent &&
|
|
22621
|
+
if (parent && ts19.isParameter(parent) && parent.name === node)
|
|
22581
22622
|
return;
|
|
22582
|
-
if (parent &&
|
|
22623
|
+
if (parent && ts19.isVariableDeclaration(parent) && parent.name === node)
|
|
22583
22624
|
return;
|
|
22584
|
-
if (parent &&
|
|
22625
|
+
if (parent && ts19.isFunctionDeclaration(parent) && parent.name === node)
|
|
22585
22626
|
return;
|
|
22586
|
-
if (parent &&
|
|
22627
|
+
if (parent && ts19.isClassDeclaration(parent) && parent.name === node)
|
|
22587
22628
|
return;
|
|
22588
|
-
if (parent &&
|
|
22629
|
+
if (parent && ts19.isJsxAttribute(parent) && parent.name === node)
|
|
22589
22630
|
return;
|
|
22590
|
-
if (parent &&
|
|
22631
|
+
if (parent && ts19.isJsxOpeningElement(parent) && parent.tagName === node) {
|
|
22591
22632
|
if (/^[a-z]/.test(node.text))
|
|
22592
22633
|
return;
|
|
22593
22634
|
}
|
|
22594
|
-
if (parent &&
|
|
22635
|
+
if (parent && ts19.isJsxClosingElement(parent) && parent.tagName === node) {
|
|
22595
22636
|
if (/^[a-z]/.test(node.text))
|
|
22596
22637
|
return;
|
|
22597
22638
|
}
|
|
@@ -22600,43 +22641,43 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22600
22641
|
ids.add(node.text);
|
|
22601
22642
|
return;
|
|
22602
22643
|
}
|
|
22603
|
-
if (
|
|
22644
|
+
if (ts19.isVariableDeclaration(node)) {
|
|
22604
22645
|
const declared = pushBindings(node.name);
|
|
22605
22646
|
if (node.initializer)
|
|
22606
22647
|
visit3(node.initializer);
|
|
22607
22648
|
return;
|
|
22608
22649
|
}
|
|
22609
|
-
if (
|
|
22650
|
+
if (ts19.isFunctionDeclaration(node)) {
|
|
22610
22651
|
if (node.name)
|
|
22611
22652
|
bound.push(node.name.text);
|
|
22612
22653
|
visitInsideNewScope(node);
|
|
22613
22654
|
return;
|
|
22614
22655
|
}
|
|
22615
|
-
if (
|
|
22656
|
+
if (ts19.isClassDeclaration(node)) {
|
|
22616
22657
|
if (node.name)
|
|
22617
22658
|
bound.push(node.name.text);
|
|
22618
|
-
|
|
22659
|
+
ts19.forEachChild(node, visit3);
|
|
22619
22660
|
return;
|
|
22620
22661
|
}
|
|
22621
|
-
if (
|
|
22662
|
+
if (ts19.isArrowFunction(node) || ts19.isFunctionExpression(node)) {
|
|
22622
22663
|
visitInsideNewScope(node);
|
|
22623
22664
|
return;
|
|
22624
22665
|
}
|
|
22625
|
-
if (
|
|
22666
|
+
if (ts19.isCatchClause(node)) {
|
|
22626
22667
|
const before = bound.length;
|
|
22627
22668
|
if (node.variableDeclaration)
|
|
22628
22669
|
pushBindings(node.variableDeclaration.name);
|
|
22629
|
-
|
|
22670
|
+
ts19.forEachChild(node, visit3);
|
|
22630
22671
|
popN(bound.length - before);
|
|
22631
22672
|
return;
|
|
22632
22673
|
}
|
|
22633
|
-
if (
|
|
22674
|
+
if (ts19.isBlock(node)) {
|
|
22634
22675
|
const before = bound.length;
|
|
22635
|
-
|
|
22676
|
+
ts19.forEachChild(node, visit3);
|
|
22636
22677
|
popN(bound.length - before);
|
|
22637
22678
|
return;
|
|
22638
22679
|
}
|
|
22639
|
-
|
|
22680
|
+
ts19.forEachChild(node, visit3);
|
|
22640
22681
|
}
|
|
22641
22682
|
function visitInsideNewScope(fn) {
|
|
22642
22683
|
const before = bound.length;
|
|
@@ -22659,29 +22700,29 @@ function collectFreeIdentifiers(arrow) {
|
|
|
22659
22700
|
function collectModuleScopeNames(sourceFile) {
|
|
22660
22701
|
const names = new Set;
|
|
22661
22702
|
for (const stmt of sourceFile.statements) {
|
|
22662
|
-
if (
|
|
22703
|
+
if (ts19.isFunctionDeclaration(stmt) && stmt.name)
|
|
22663
22704
|
names.add(stmt.name.text);
|
|
22664
|
-
else if (
|
|
22705
|
+
else if (ts19.isClassDeclaration(stmt) && stmt.name)
|
|
22665
22706
|
names.add(stmt.name.text);
|
|
22666
|
-
else if (
|
|
22707
|
+
else if (ts19.isVariableStatement(stmt)) {
|
|
22667
22708
|
for (const decl of stmt.declarationList.declarations)
|
|
22668
22709
|
collectBindingNames4(decl.name, names);
|
|
22669
|
-
} else if (
|
|
22710
|
+
} else if (ts19.isImportDeclaration(stmt) && stmt.importClause) {
|
|
22670
22711
|
const ic = stmt.importClause;
|
|
22671
22712
|
if (ic.name)
|
|
22672
22713
|
names.add(ic.name.text);
|
|
22673
22714
|
if (ic.namedBindings) {
|
|
22674
|
-
if (
|
|
22715
|
+
if (ts19.isNamespaceImport(ic.namedBindings))
|
|
22675
22716
|
names.add(ic.namedBindings.name.text);
|
|
22676
22717
|
else
|
|
22677
22718
|
for (const e of ic.namedBindings.elements)
|
|
22678
22719
|
names.add(e.name.text);
|
|
22679
22720
|
}
|
|
22680
|
-
} else if (
|
|
22721
|
+
} else if (ts19.isTypeAliasDeclaration(stmt))
|
|
22681
22722
|
names.add(stmt.name.text);
|
|
22682
|
-
else if (
|
|
22723
|
+
else if (ts19.isInterfaceDeclaration(stmt))
|
|
22683
22724
|
names.add(stmt.name.text);
|
|
22684
|
-
else if (
|
|
22725
|
+
else if (ts19.isEnumDeclaration(stmt))
|
|
22685
22726
|
names.add(stmt.name.text);
|
|
22686
22727
|
}
|
|
22687
22728
|
return names;
|
|
@@ -22689,7 +22730,7 @@ function collectModuleScopeNames(sourceFile) {
|
|
|
22689
22730
|
function buildSyntheticDeclaration(name, arrow, sourceFile) {
|
|
22690
22731
|
const paramsText = arrow.parameters.length === 0 ? "" : arrow.parameters.map((p) => p.getText(sourceFile)).join(", ");
|
|
22691
22732
|
let bodyText;
|
|
22692
|
-
if (
|
|
22733
|
+
if (ts19.isBlock(arrow.body)) {
|
|
22693
22734
|
bodyText = arrow.body.getText(sourceFile);
|
|
22694
22735
|
} else {
|
|
22695
22736
|
const expr = arrow.body.getText(sourceFile);
|
|
@@ -22699,7 +22740,7 @@ function buildSyntheticDeclaration(name, arrow, sourceFile) {
|
|
|
22699
22740
|
}
|
|
22700
22741
|
|
|
22701
22742
|
// src/ssr-defaults.ts
|
|
22702
|
-
import
|
|
22743
|
+
import ts20 from "typescript";
|
|
22703
22744
|
var UNRESOLVED = Symbol("unresolved");
|
|
22704
22745
|
var NO_RETURN = Symbol("no-return");
|
|
22705
22746
|
function extractSsrDefaults(metadata) {
|
|
@@ -22776,11 +22817,11 @@ function collectPropRefs(expr, propsObjectName, out) {
|
|
|
22776
22817
|
if (!node)
|
|
22777
22818
|
return;
|
|
22778
22819
|
const visit3 = (n) => {
|
|
22779
|
-
if (
|
|
22820
|
+
if (ts20.isPropertyAccessExpression(n) && ts20.isIdentifier(n.expression) && n.expression.text === propsObjectName && ts20.isIdentifier(n.name)) {
|
|
22780
22821
|
out.add(n.name.text);
|
|
22781
22822
|
return;
|
|
22782
22823
|
}
|
|
22783
|
-
|
|
22824
|
+
ts20.forEachChild(n, visit3);
|
|
22784
22825
|
};
|
|
22785
22826
|
visit3(node);
|
|
22786
22827
|
}
|
|
@@ -22801,23 +22842,23 @@ function tryStaticEval(expr, ctx) {
|
|
|
22801
22842
|
}
|
|
22802
22843
|
function evalStatementsForReturn(statements, ctx) {
|
|
22803
22844
|
for (const stmt of statements) {
|
|
22804
|
-
if (
|
|
22845
|
+
if (ts20.isVariableStatement(stmt)) {
|
|
22805
22846
|
for (const d of stmt.declarationList.declarations) {
|
|
22806
|
-
if (!
|
|
22847
|
+
if (!ts20.isIdentifier(d.name) || !d.initializer)
|
|
22807
22848
|
continue;
|
|
22808
22849
|
const v = evalNode(d.initializer, ctx);
|
|
22809
22850
|
if (v !== UNRESOLVED)
|
|
22810
22851
|
ctx.bindings[d.name.text] = v;
|
|
22811
22852
|
}
|
|
22812
|
-
} else if (
|
|
22853
|
+
} else if (ts20.isReturnStatement(stmt)) {
|
|
22813
22854
|
return stmt.expression ? evalNode(stmt.expression, ctx) : UNRESOLVED;
|
|
22814
|
-
} else if (
|
|
22855
|
+
} else if (ts20.isIfStatement(stmt)) {
|
|
22815
22856
|
const cond = evalNode(stmt.expression, ctx);
|
|
22816
22857
|
if (cond === UNRESOLVED)
|
|
22817
22858
|
return UNRESOLVED;
|
|
22818
22859
|
const branch = cond ? stmt.thenStatement : stmt.elseStatement;
|
|
22819
22860
|
if (branch) {
|
|
22820
|
-
const taken = evalStatementsForReturn(
|
|
22861
|
+
const taken = evalStatementsForReturn(ts20.isBlock(branch) ? branch.statements : [branch], ctx);
|
|
22821
22862
|
if (taken !== NO_RETURN)
|
|
22822
22863
|
return taken;
|
|
22823
22864
|
}
|
|
@@ -22828,45 +22869,45 @@ function evalStatementsForReturn(statements, ctx) {
|
|
|
22828
22869
|
return NO_RETURN;
|
|
22829
22870
|
}
|
|
22830
22871
|
function parseExpression2(expr) {
|
|
22831
|
-
const sf =
|
|
22872
|
+
const sf = ts20.createSourceFile("__ssr_default__.ts", `(${expr})`, ts20.ScriptTarget.Latest, false, ts20.ScriptKind.TS);
|
|
22832
22873
|
const stmt = sf.statements[0];
|
|
22833
|
-
if (!stmt || !
|
|
22874
|
+
if (!stmt || !ts20.isExpressionStatement(stmt))
|
|
22834
22875
|
return null;
|
|
22835
|
-
const inner =
|
|
22876
|
+
const inner = ts20.isParenthesizedExpression(stmt.expression) ? stmt.expression.expression : stmt.expression;
|
|
22836
22877
|
return inner;
|
|
22837
22878
|
}
|
|
22838
22879
|
function evalNode(node, ctx) {
|
|
22839
|
-
if (
|
|
22880
|
+
if (ts20.isParenthesizedExpression(node))
|
|
22840
22881
|
return evalNode(node.expression, ctx);
|
|
22841
|
-
if (
|
|
22882
|
+
if (ts20.isAsExpression(node))
|
|
22842
22883
|
return evalNode(node.expression, ctx);
|
|
22843
|
-
if (
|
|
22884
|
+
if (ts20.isSatisfiesExpression(node))
|
|
22844
22885
|
return evalNode(node.expression, ctx);
|
|
22845
|
-
if (
|
|
22886
|
+
if (ts20.isTypeAssertionExpression(node))
|
|
22846
22887
|
return evalNode(node.expression, ctx);
|
|
22847
|
-
if (
|
|
22888
|
+
if (ts20.isNonNullExpression(node))
|
|
22848
22889
|
return evalNode(node.expression, ctx);
|
|
22849
|
-
if (
|
|
22890
|
+
if (ts20.isArrowFunction(node)) {
|
|
22850
22891
|
if (node.parameters.length !== 0)
|
|
22851
22892
|
return UNRESOLVED;
|
|
22852
|
-
if (!
|
|
22893
|
+
if (!ts20.isBlock(node.body))
|
|
22853
22894
|
return evalNode(node.body, ctx);
|
|
22854
22895
|
const localBindings = { ...ctx.bindings };
|
|
22855
22896
|
const localCtx = { ...ctx, bindings: localBindings };
|
|
22856
22897
|
const result = evalStatementsForReturn(node.body.statements, localCtx);
|
|
22857
22898
|
return result === NO_RETURN ? UNRESOLVED : result;
|
|
22858
22899
|
}
|
|
22859
|
-
if (
|
|
22900
|
+
if (ts20.isNumericLiteral(node))
|
|
22860
22901
|
return Number(node.text);
|
|
22861
|
-
if (
|
|
22902
|
+
if (ts20.isStringLiteralLike(node))
|
|
22862
22903
|
return node.text;
|
|
22863
|
-
if (node.kind ===
|
|
22904
|
+
if (node.kind === ts20.SyntaxKind.TrueKeyword)
|
|
22864
22905
|
return true;
|
|
22865
|
-
if (node.kind ===
|
|
22906
|
+
if (node.kind === ts20.SyntaxKind.FalseKeyword)
|
|
22866
22907
|
return false;
|
|
22867
|
-
if (node.kind ===
|
|
22908
|
+
if (node.kind === ts20.SyntaxKind.NullKeyword)
|
|
22868
22909
|
return null;
|
|
22869
|
-
if (
|
|
22910
|
+
if (ts20.isIdentifier(node)) {
|
|
22870
22911
|
if (node.text === "undefined")
|
|
22871
22912
|
return;
|
|
22872
22913
|
if (node.text in ctx.bindings)
|
|
@@ -22875,29 +22916,29 @@ function evalNode(node, ctx) {
|
|
|
22875
22916
|
return;
|
|
22876
22917
|
return UNRESOLVED;
|
|
22877
22918
|
}
|
|
22878
|
-
if (
|
|
22919
|
+
if (ts20.isPrefixUnaryExpression(node)) {
|
|
22879
22920
|
const arg = evalNode(node.operand, ctx);
|
|
22880
22921
|
if (arg === UNRESOLVED)
|
|
22881
22922
|
return UNRESOLVED;
|
|
22882
22923
|
switch (node.operator) {
|
|
22883
|
-
case
|
|
22924
|
+
case ts20.SyntaxKind.MinusToken:
|
|
22884
22925
|
return typeof arg === "number" ? -arg : UNRESOLVED;
|
|
22885
|
-
case
|
|
22926
|
+
case ts20.SyntaxKind.PlusToken:
|
|
22886
22927
|
return typeof arg === "number" ? +arg : UNRESOLVED;
|
|
22887
|
-
case
|
|
22928
|
+
case ts20.SyntaxKind.ExclamationToken:
|
|
22888
22929
|
return !arg;
|
|
22889
22930
|
}
|
|
22890
22931
|
return UNRESOLVED;
|
|
22891
22932
|
}
|
|
22892
|
-
if (
|
|
22933
|
+
if (ts20.isObjectLiteralExpression(node)) {
|
|
22893
22934
|
const obj = {};
|
|
22894
22935
|
for (const prop of node.properties) {
|
|
22895
|
-
if (!
|
|
22936
|
+
if (!ts20.isPropertyAssignment(prop))
|
|
22896
22937
|
return UNRESOLVED;
|
|
22897
22938
|
let key;
|
|
22898
|
-
if (
|
|
22939
|
+
if (ts20.isIdentifier(prop.name) || ts20.isStringLiteralLike(prop.name)) {
|
|
22899
22940
|
key = prop.name.text;
|
|
22900
|
-
} else if (
|
|
22941
|
+
} else if (ts20.isNumericLiteral(prop.name)) {
|
|
22901
22942
|
key = prop.name.text;
|
|
22902
22943
|
} else {
|
|
22903
22944
|
return UNRESOLVED;
|
|
@@ -22909,10 +22950,10 @@ function evalNode(node, ctx) {
|
|
|
22909
22950
|
}
|
|
22910
22951
|
return obj;
|
|
22911
22952
|
}
|
|
22912
|
-
if (
|
|
22953
|
+
if (ts20.isArrayLiteralExpression(node)) {
|
|
22913
22954
|
const arr = [];
|
|
22914
22955
|
for (const elem of node.elements) {
|
|
22915
|
-
if (
|
|
22956
|
+
if (ts20.isOmittedExpression(elem))
|
|
22916
22957
|
return UNRESOLVED;
|
|
22917
22958
|
const v = evalNode(elem, ctx);
|
|
22918
22959
|
if (v === UNRESOLVED)
|
|
@@ -22921,7 +22962,7 @@ function evalNode(node, ctx) {
|
|
|
22921
22962
|
}
|
|
22922
22963
|
return arr;
|
|
22923
22964
|
}
|
|
22924
|
-
if (
|
|
22965
|
+
if (ts20.isElementAccessExpression(node)) {
|
|
22925
22966
|
const base = evalNode(node.expression, ctx);
|
|
22926
22967
|
if (base === undefined)
|
|
22927
22968
|
return;
|
|
@@ -22935,17 +22976,17 @@ function evalNode(node, ctx) {
|
|
|
22935
22976
|
const k = String(key);
|
|
22936
22977
|
return Object.prototype.hasOwnProperty.call(base, k) ? base[k] : undefined;
|
|
22937
22978
|
}
|
|
22938
|
-
if (
|
|
22979
|
+
if (ts20.isPropertyAccessExpression(node)) {
|
|
22939
22980
|
const baseResult = evalNode(node.expression, ctx);
|
|
22940
22981
|
if (baseResult === undefined)
|
|
22941
22982
|
return;
|
|
22942
22983
|
return UNRESOLVED;
|
|
22943
22984
|
}
|
|
22944
|
-
if (
|
|
22945
|
-
if (node.arguments.length === 0 &&
|
|
22985
|
+
if (ts20.isCallExpression(node)) {
|
|
22986
|
+
if (node.arguments.length === 0 && ts20.isIdentifier(node.expression) && node.expression.text in ctx.bindings) {
|
|
22946
22987
|
return ctx.bindings[node.expression.text];
|
|
22947
22988
|
}
|
|
22948
|
-
if (
|
|
22989
|
+
if (ts20.isPropertyAccessExpression(node.expression) && node.expression.name.text === "join") {
|
|
22949
22990
|
const recv = evalNode(node.expression.expression, ctx);
|
|
22950
22991
|
if (Array.isArray(recv)) {
|
|
22951
22992
|
let sep2 = ",";
|
|
@@ -22961,27 +23002,27 @@ function evalNode(node, ctx) {
|
|
|
22961
23002
|
}
|
|
22962
23003
|
return UNRESOLVED;
|
|
22963
23004
|
}
|
|
22964
|
-
if (
|
|
23005
|
+
if (ts20.isConditionalExpression(node)) {
|
|
22965
23006
|
const cond = evalNode(node.condition, ctx);
|
|
22966
23007
|
if (cond === UNRESOLVED)
|
|
22967
23008
|
return UNRESOLVED;
|
|
22968
23009
|
return cond ? evalNode(node.whenTrue, ctx) : evalNode(node.whenFalse, ctx);
|
|
22969
23010
|
}
|
|
22970
|
-
if (
|
|
23011
|
+
if (ts20.isBinaryExpression(node)) {
|
|
22971
23012
|
const op = node.operatorToken.kind;
|
|
22972
|
-
if (op ===
|
|
23013
|
+
if (op === ts20.SyntaxKind.QuestionQuestionToken) {
|
|
22973
23014
|
const l2 = evalNode(node.left, ctx);
|
|
22974
23015
|
if (l2 !== UNRESOLVED && l2 !== null && l2 !== undefined)
|
|
22975
23016
|
return l2;
|
|
22976
23017
|
return evalNode(node.right, ctx);
|
|
22977
23018
|
}
|
|
22978
|
-
if (op ===
|
|
23019
|
+
if (op === ts20.SyntaxKind.BarBarToken) {
|
|
22979
23020
|
const l2 = evalNode(node.left, ctx);
|
|
22980
23021
|
if (l2 !== UNRESOLVED && l2)
|
|
22981
23022
|
return l2;
|
|
22982
23023
|
return evalNode(node.right, ctx);
|
|
22983
23024
|
}
|
|
22984
|
-
if (op ===
|
|
23025
|
+
if (op === ts20.SyntaxKind.AmpersandAmpersandToken) {
|
|
22985
23026
|
const l2 = evalNode(node.left, ctx);
|
|
22986
23027
|
if (l2 === UNRESOLVED)
|
|
22987
23028
|
return UNRESOLVED;
|
|
@@ -22994,30 +23035,30 @@ function evalNode(node, ctx) {
|
|
|
22994
23035
|
if (l === UNRESOLVED || r === UNRESOLVED)
|
|
22995
23036
|
return UNRESOLVED;
|
|
22996
23037
|
switch (op) {
|
|
22997
|
-
case
|
|
23038
|
+
case ts20.SyntaxKind.PlusToken:
|
|
22998
23039
|
if (typeof l === "string" || typeof r === "string")
|
|
22999
23040
|
return `${l}${r}`;
|
|
23000
23041
|
if (typeof l === "number" && typeof r === "number")
|
|
23001
23042
|
return l + r;
|
|
23002
23043
|
return UNRESOLVED;
|
|
23003
|
-
case
|
|
23044
|
+
case ts20.SyntaxKind.MinusToken:
|
|
23004
23045
|
return typeof l === "number" && typeof r === "number" ? l - r : UNRESOLVED;
|
|
23005
|
-
case
|
|
23046
|
+
case ts20.SyntaxKind.AsteriskToken:
|
|
23006
23047
|
return typeof l === "number" && typeof r === "number" ? l * r : UNRESOLVED;
|
|
23007
|
-
case
|
|
23048
|
+
case ts20.SyntaxKind.SlashToken:
|
|
23008
23049
|
return typeof l === "number" && typeof r === "number" && r !== 0 ? l / r : UNRESOLVED;
|
|
23009
|
-
case
|
|
23050
|
+
case ts20.SyntaxKind.PercentToken:
|
|
23010
23051
|
return typeof l === "number" && typeof r === "number" && r !== 0 ? l % r : UNRESOLVED;
|
|
23011
|
-
case
|
|
23012
|
-
case
|
|
23052
|
+
case ts20.SyntaxKind.EqualsEqualsEqualsToken:
|
|
23053
|
+
case ts20.SyntaxKind.EqualsEqualsToken:
|
|
23013
23054
|
return l === r;
|
|
23014
|
-
case
|
|
23015
|
-
case
|
|
23055
|
+
case ts20.SyntaxKind.ExclamationEqualsEqualsToken:
|
|
23056
|
+
case ts20.SyntaxKind.ExclamationEqualsToken:
|
|
23016
23057
|
return l !== r;
|
|
23017
23058
|
}
|
|
23018
23059
|
return UNRESOLVED;
|
|
23019
23060
|
}
|
|
23020
|
-
if (
|
|
23061
|
+
if (ts20.isTemplateExpression(node)) {
|
|
23021
23062
|
if (node.templateSpans.length === 0)
|
|
23022
23063
|
return node.head.text;
|
|
23023
23064
|
let acc = node.head.text;
|
|
@@ -23029,13 +23070,13 @@ function evalNode(node, ctx) {
|
|
|
23029
23070
|
}
|
|
23030
23071
|
return acc;
|
|
23031
23072
|
}
|
|
23032
|
-
if (
|
|
23073
|
+
if (ts20.isNoSubstitutionTemplateLiteral(node))
|
|
23033
23074
|
return node.text;
|
|
23034
23075
|
return UNRESOLVED;
|
|
23035
23076
|
}
|
|
23036
23077
|
|
|
23037
23078
|
// src/augment-inherited-props.ts
|
|
23038
|
-
import
|
|
23079
|
+
import ts21 from "typescript";
|
|
23039
23080
|
function collectContextConsumers(metadata) {
|
|
23040
23081
|
const constants = metadata.localConstants ?? [];
|
|
23041
23082
|
const contextDefaults = new Map;
|
|
@@ -23067,47 +23108,47 @@ function collectContextConsumers(metadata) {
|
|
|
23067
23108
|
}
|
|
23068
23109
|
function parseUseContextArg(source) {
|
|
23069
23110
|
const expr = parseSingleExpression(source);
|
|
23070
|
-
if (!expr || !
|
|
23111
|
+
if (!expr || !ts21.isCallExpression(expr))
|
|
23071
23112
|
return null;
|
|
23072
|
-
if (!
|
|
23113
|
+
if (!ts21.isIdentifier(expr.expression) || expr.expression.text !== "useContext")
|
|
23073
23114
|
return null;
|
|
23074
23115
|
if (expr.arguments.length !== 1)
|
|
23075
23116
|
return null;
|
|
23076
23117
|
const arg = expr.arguments[0];
|
|
23077
|
-
return
|
|
23118
|
+
return ts21.isIdentifier(arg) ? arg.text : null;
|
|
23078
23119
|
}
|
|
23079
23120
|
function parseCreateContextDefault(source) {
|
|
23080
23121
|
const expr = parseSingleExpression(source);
|
|
23081
|
-
if (!expr || !
|
|
23122
|
+
if (!expr || !ts21.isCallExpression(expr))
|
|
23082
23123
|
return null;
|
|
23083
23124
|
if (expr.arguments.length === 0)
|
|
23084
23125
|
return null;
|
|
23085
23126
|
const arg = expr.arguments[0];
|
|
23086
|
-
if (
|
|
23127
|
+
if (ts21.isStringLiteral(arg) || ts21.isNoSubstitutionTemplateLiteral(arg))
|
|
23087
23128
|
return arg.text;
|
|
23088
|
-
if (
|
|
23129
|
+
if (ts21.isNumericLiteral(arg))
|
|
23089
23130
|
return Number(arg.text);
|
|
23090
|
-
if (arg.kind ===
|
|
23131
|
+
if (arg.kind === ts21.SyntaxKind.TrueKeyword)
|
|
23091
23132
|
return true;
|
|
23092
|
-
if (arg.kind ===
|
|
23133
|
+
if (arg.kind === ts21.SyntaxKind.FalseKeyword)
|
|
23093
23134
|
return false;
|
|
23094
23135
|
return null;
|
|
23095
23136
|
}
|
|
23096
23137
|
function isObjectLiteralCreateContextDefault(source) {
|
|
23097
23138
|
const expr = parseSingleExpression(source);
|
|
23098
|
-
if (!expr || !
|
|
23139
|
+
if (!expr || !ts21.isCallExpression(expr))
|
|
23099
23140
|
return false;
|
|
23100
23141
|
if (expr.arguments.length === 0)
|
|
23101
23142
|
return false;
|
|
23102
|
-
return
|
|
23143
|
+
return ts21.isObjectLiteralExpression(expr.arguments[0]);
|
|
23103
23144
|
}
|
|
23104
23145
|
function parseSingleExpression(source) {
|
|
23105
|
-
const sf =
|
|
23146
|
+
const sf = ts21.createSourceFile("__ctx.ts", `(${source})`, ts21.ScriptTarget.Latest, false);
|
|
23106
23147
|
const stmt = sf.statements[0];
|
|
23107
|
-
if (!stmt || !
|
|
23148
|
+
if (!stmt || !ts21.isExpressionStatement(stmt))
|
|
23108
23149
|
return null;
|
|
23109
23150
|
let e = stmt.expression;
|
|
23110
|
-
while (
|
|
23151
|
+
while (ts21.isParenthesizedExpression(e))
|
|
23111
23152
|
e = e.expression;
|
|
23112
23153
|
return e;
|
|
23113
23154
|
}
|
|
@@ -23132,25 +23173,25 @@ function augmentInheritedPropAccesses(ir) {
|
|
|
23132
23173
|
const pinCoalesceLiterals = (s) => {
|
|
23133
23174
|
if (!s || !s.includes(propsObj))
|
|
23134
23175
|
return;
|
|
23135
|
-
const sf =
|
|
23176
|
+
const sf = ts21.createSourceFile("__aug.ts", `(${s})`, ts21.ScriptTarget.Latest, false);
|
|
23136
23177
|
const visit3 = (n) => {
|
|
23137
|
-
if (
|
|
23178
|
+
if (ts21.isBinaryExpression(n) && (n.operatorToken.kind === ts21.SyntaxKind.QuestionQuestionToken || n.operatorToken.kind === ts21.SyntaxKind.BarBarToken)) {
|
|
23138
23179
|
let left = n.left;
|
|
23139
|
-
while (
|
|
23180
|
+
while (ts21.isParenthesizedExpression(left))
|
|
23140
23181
|
left = left.expression;
|
|
23141
|
-
if (
|
|
23182
|
+
if (ts21.isPropertyAccessExpression(left) && ts21.isIdentifier(left.expression) && left.expression.text === propsObj) {
|
|
23142
23183
|
const name = left.name.text;
|
|
23143
23184
|
let right = n.right;
|
|
23144
|
-
while (
|
|
23185
|
+
while (ts21.isParenthesizedExpression(right))
|
|
23145
23186
|
right = right.expression;
|
|
23146
|
-
if (
|
|
23187
|
+
if (ts21.isPrefixUnaryExpression(right))
|
|
23147
23188
|
right = right.operand;
|
|
23148
|
-
const kind =
|
|
23189
|
+
const kind = ts21.isNumericLiteral(right) ? "number" : right.kind === ts21.SyntaxKind.TrueKeyword || right.kind === ts21.SyntaxKind.FalseKeyword ? "boolean" : ts21.isStringLiteralLike(right) ? "string" : null;
|
|
23149
23190
|
if (kind && !coalesceLiteralTypes.has(name))
|
|
23150
23191
|
coalesceLiteralTypes.set(name, kind);
|
|
23151
23192
|
}
|
|
23152
23193
|
}
|
|
23153
|
-
|
|
23194
|
+
ts21.forEachChild(n, visit3);
|
|
23154
23195
|
};
|
|
23155
23196
|
visit3(sf);
|
|
23156
23197
|
};
|
|
@@ -23261,33 +23302,33 @@ function augmentInheritedPropAccesses(ir) {
|
|
|
23261
23302
|
}
|
|
23262
23303
|
}
|
|
23263
23304
|
function parseStaticStringConst(source) {
|
|
23264
|
-
const sf =
|
|
23305
|
+
const sf = ts21.createSourceFile("__const.ts", `const __x = (${source});`, ts21.ScriptTarget.Latest, false);
|
|
23265
23306
|
const stmt = sf.statements[0];
|
|
23266
|
-
if (!stmt || !
|
|
23307
|
+
if (!stmt || !ts21.isVariableStatement(stmt))
|
|
23267
23308
|
return null;
|
|
23268
23309
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
23269
|
-
while (init &&
|
|
23310
|
+
while (init && ts21.isParenthesizedExpression(init))
|
|
23270
23311
|
init = init.expression;
|
|
23271
23312
|
if (!init)
|
|
23272
23313
|
return null;
|
|
23273
|
-
if (
|
|
23314
|
+
if (ts21.isStringLiteral(init) || ts21.isNoSubstitutionTemplateLiteral(init)) {
|
|
23274
23315
|
return init.text;
|
|
23275
23316
|
}
|
|
23276
23317
|
return evalStringArrayJoin(source);
|
|
23277
23318
|
}
|
|
23278
23319
|
function evalTemplateOfStringConsts(source, resolved) {
|
|
23279
|
-
const sf =
|
|
23320
|
+
const sf = ts21.createSourceFile("__const.ts", `const __x = (${source});`, ts21.ScriptTarget.Latest, false);
|
|
23280
23321
|
const stmt = sf.statements[0];
|
|
23281
|
-
if (!stmt || !
|
|
23322
|
+
if (!stmt || !ts21.isVariableStatement(stmt))
|
|
23282
23323
|
return null;
|
|
23283
23324
|
let init = stmt.declarationList.declarations[0]?.initializer;
|
|
23284
|
-
while (init &&
|
|
23325
|
+
while (init && ts21.isParenthesizedExpression(init))
|
|
23285
23326
|
init = init.expression;
|
|
23286
|
-
if (!init || !
|
|
23327
|
+
if (!init || !ts21.isTemplateExpression(init))
|
|
23287
23328
|
return null;
|
|
23288
23329
|
let out = init.head.text;
|
|
23289
23330
|
for (const span of init.templateSpans) {
|
|
23290
|
-
if (!
|
|
23331
|
+
if (!ts21.isIdentifier(span.expression))
|
|
23291
23332
|
return null;
|
|
23292
23333
|
const value = resolved.get(span.expression.text);
|
|
23293
23334
|
if (value === undefined)
|
|
@@ -23318,30 +23359,30 @@ function lookupStaticRecordLiteral(objectName, key, constants) {
|
|
|
23318
23359
|
const constInfo = (constants ?? []).find((c) => c.name === objectName && c.isModule);
|
|
23319
23360
|
if (constInfo?.value === undefined)
|
|
23320
23361
|
return null;
|
|
23321
|
-
const sf =
|
|
23362
|
+
const sf = ts21.createSourceFile("__rec.ts", `(${constInfo.value})`, ts21.ScriptTarget.Latest, true);
|
|
23322
23363
|
if (sf.statements.length !== 1)
|
|
23323
23364
|
return null;
|
|
23324
23365
|
const stmt = sf.statements[0];
|
|
23325
|
-
if (!
|
|
23366
|
+
if (!ts21.isExpressionStatement(stmt))
|
|
23326
23367
|
return null;
|
|
23327
23368
|
let parsed = stmt.expression;
|
|
23328
|
-
while (
|
|
23369
|
+
while (ts21.isParenthesizedExpression(parsed))
|
|
23329
23370
|
parsed = parsed.expression;
|
|
23330
|
-
if (!
|
|
23371
|
+
if (!ts21.isObjectLiteralExpression(parsed))
|
|
23331
23372
|
return null;
|
|
23332
23373
|
for (const prop of parsed.properties) {
|
|
23333
|
-
if (!
|
|
23374
|
+
if (!ts21.isPropertyAssignment(prop))
|
|
23334
23375
|
continue;
|
|
23335
23376
|
const name = prop.name;
|
|
23336
|
-
const propKey =
|
|
23377
|
+
const propKey = ts21.isIdentifier(name) || ts21.isStringLiteral(name) || ts21.isNoSubstitutionTemplateLiteral(name) ? name.text : null;
|
|
23337
23378
|
if (propKey !== key)
|
|
23338
23379
|
continue;
|
|
23339
23380
|
let v = prop.initializer;
|
|
23340
|
-
while (
|
|
23381
|
+
while (ts21.isParenthesizedExpression(v))
|
|
23341
23382
|
v = v.expression;
|
|
23342
|
-
if (
|
|
23383
|
+
if (ts21.isNumericLiteral(v))
|
|
23343
23384
|
return { kind: "number", text: v.text };
|
|
23344
|
-
if (
|
|
23385
|
+
if (ts21.isStringLiteral(v) || ts21.isNoSubstitutionTemplateLiteral(v)) {
|
|
23345
23386
|
return { kind: "string", text: v.text };
|
|
23346
23387
|
}
|
|
23347
23388
|
return null;
|
|
@@ -23349,28 +23390,28 @@ function lookupStaticRecordLiteral(objectName, key, constants) {
|
|
|
23349
23390
|
return null;
|
|
23350
23391
|
}
|
|
23351
23392
|
function evalStringArrayJoin(source) {
|
|
23352
|
-
const sf =
|
|
23393
|
+
const sf = ts21.createSourceFile("__join.ts", `const __x = (${source});`, ts21.ScriptTarget.Latest, false);
|
|
23353
23394
|
const stmt = sf.statements[0];
|
|
23354
|
-
if (!stmt || !
|
|
23395
|
+
if (!stmt || !ts21.isVariableStatement(stmt))
|
|
23355
23396
|
return null;
|
|
23356
23397
|
let node = stmt.declarationList.declarations[0]?.initializer;
|
|
23357
|
-
while (node &&
|
|
23398
|
+
while (node && ts21.isParenthesizedExpression(node))
|
|
23358
23399
|
node = node.expression;
|
|
23359
|
-
if (!node || !
|
|
23400
|
+
if (!node || !ts21.isCallExpression(node))
|
|
23360
23401
|
return null;
|
|
23361
23402
|
const callee = node.expression;
|
|
23362
|
-
if (!
|
|
23403
|
+
if (!ts21.isPropertyAccessExpression(callee))
|
|
23363
23404
|
return null;
|
|
23364
23405
|
if (callee.name.text !== "join")
|
|
23365
23406
|
return null;
|
|
23366
23407
|
let recv = callee.expression;
|
|
23367
|
-
while (
|
|
23408
|
+
while (ts21.isParenthesizedExpression(recv))
|
|
23368
23409
|
recv = recv.expression;
|
|
23369
|
-
if (!
|
|
23410
|
+
if (!ts21.isArrayLiteralExpression(recv))
|
|
23370
23411
|
return null;
|
|
23371
23412
|
const parts = [];
|
|
23372
23413
|
for (const el of recv.elements) {
|
|
23373
|
-
if (
|
|
23414
|
+
if (ts21.isStringLiteral(el) || ts21.isNoSubstitutionTemplateLiteral(el)) {
|
|
23374
23415
|
parts.push(el.text);
|
|
23375
23416
|
} else {
|
|
23376
23417
|
return null;
|
|
@@ -23379,7 +23420,7 @@ function evalStringArrayJoin(source) {
|
|
|
23379
23420
|
let sep2 = ",";
|
|
23380
23421
|
if (node.arguments.length >= 1) {
|
|
23381
23422
|
const arg = node.arguments[0];
|
|
23382
|
-
if (
|
|
23423
|
+
if (ts21.isStringLiteral(arg) || ts21.isNoSubstitutionTemplateLiteral(arg))
|
|
23383
23424
|
sep2 = arg.text;
|
|
23384
23425
|
else
|
|
23385
23426
|
return null;
|
|
@@ -23387,11 +23428,11 @@ function evalStringArrayJoin(source) {
|
|
|
23387
23428
|
return parts.join(sep2);
|
|
23388
23429
|
}
|
|
23389
23430
|
function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
|
|
23390
|
-
if (!
|
|
23431
|
+
if (!ts21.isElementAccessExpression(val))
|
|
23391
23432
|
return null;
|
|
23392
23433
|
const obj = val.expression;
|
|
23393
23434
|
const arg = val.argumentExpression;
|
|
23394
|
-
if (!
|
|
23435
|
+
if (!ts21.isIdentifier(obj) || !ts21.isIdentifier(arg))
|
|
23395
23436
|
return null;
|
|
23396
23437
|
let indexPropName;
|
|
23397
23438
|
let defaultKey;
|
|
@@ -23407,35 +23448,35 @@ function parseRecordIndexAccess(val, localConstants, propsParams, resolveKey) {
|
|
|
23407
23448
|
const constInfo = localConstants.find((c) => c.name === obj.text && c.isModule);
|
|
23408
23449
|
if (constInfo?.value === undefined)
|
|
23409
23450
|
return null;
|
|
23410
|
-
const sf =
|
|
23451
|
+
const sf = ts21.createSourceFile("__rec.ts", `(${constInfo.value})`, ts21.ScriptTarget.Latest, true);
|
|
23411
23452
|
if (sf.statements.length !== 1)
|
|
23412
23453
|
return null;
|
|
23413
23454
|
const stmt = sf.statements[0];
|
|
23414
|
-
if (!
|
|
23455
|
+
if (!ts21.isExpressionStatement(stmt))
|
|
23415
23456
|
return null;
|
|
23416
23457
|
let parsed = stmt.expression;
|
|
23417
|
-
while (
|
|
23458
|
+
while (ts21.isParenthesizedExpression(parsed))
|
|
23418
23459
|
parsed = parsed.expression;
|
|
23419
|
-
if (!
|
|
23460
|
+
if (!ts21.isObjectLiteralExpression(parsed))
|
|
23420
23461
|
return null;
|
|
23421
23462
|
const entries = [];
|
|
23422
23463
|
for (const prop of parsed.properties) {
|
|
23423
|
-
if (!
|
|
23464
|
+
if (!ts21.isPropertyAssignment(prop))
|
|
23424
23465
|
return null;
|
|
23425
23466
|
let key;
|
|
23426
|
-
if (
|
|
23467
|
+
if (ts21.isIdentifier(prop.name)) {
|
|
23427
23468
|
key = prop.name.text;
|
|
23428
|
-
} else if (
|
|
23469
|
+
} else if (ts21.isStringLiteral(prop.name) || ts21.isNoSubstitutionTemplateLiteral(prop.name)) {
|
|
23429
23470
|
key = prop.name.text;
|
|
23430
23471
|
} else {
|
|
23431
23472
|
return null;
|
|
23432
23473
|
}
|
|
23433
23474
|
let v = prop.initializer;
|
|
23434
|
-
while (
|
|
23475
|
+
while (ts21.isParenthesizedExpression(v))
|
|
23435
23476
|
v = v.expression;
|
|
23436
|
-
if (
|
|
23477
|
+
if (ts21.isNumericLiteral(v)) {
|
|
23437
23478
|
entries.push({ key, value: { kind: "number", text: v.text } });
|
|
23438
|
-
} else if (
|
|
23479
|
+
} else if (ts21.isStringLiteral(v) || ts21.isNoSubstitutionTemplateLiteral(v)) {
|
|
23439
23480
|
entries.push({ key, value: { kind: "string", text: v.text } });
|
|
23440
23481
|
} else {
|
|
23441
23482
|
return null;
|
|
@@ -23751,9 +23792,11 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
23751
23792
|
const errors = [];
|
|
23752
23793
|
const adapter = options.adapter;
|
|
23753
23794
|
const entries = [];
|
|
23754
|
-
const
|
|
23795
|
+
const callerProgram = options.program?.getSourceFile(filePath)?.text === source ? options.program : undefined;
|
|
23796
|
+
const program = callerProgram ?? (needsTypeBasedDetection(source) ? createProgramForFile(source, filePath)?.program : undefined);
|
|
23797
|
+
const programIsShared = options.program !== undefined;
|
|
23755
23798
|
for (const componentName of componentNames) {
|
|
23756
|
-
const ctx = analyzeComponent(source, filePath, componentName, program, adapter.acceptsCallbackBody);
|
|
23799
|
+
const ctx = analyzeComponent(source, filePath, componentName, program, adapter.acceptsCallbackBody, programIsShared);
|
|
23757
23800
|
if (!ctx.jsxReturn) {
|
|
23758
23801
|
errors.push(...ctx.errors);
|
|
23759
23802
|
continue;
|
|
@@ -23776,6 +23819,19 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
23776
23819
|
}
|
|
23777
23820
|
entries.push({ componentIR, ctx });
|
|
23778
23821
|
}
|
|
23822
|
+
{
|
|
23823
|
+
let seenBf050 = false;
|
|
23824
|
+
const deduped = errors.filter((e) => {
|
|
23825
|
+
if (e.code !== ErrorCodes.SHARED_PROGRAM_REQUIRED)
|
|
23826
|
+
return true;
|
|
23827
|
+
if (seenBf050)
|
|
23828
|
+
return false;
|
|
23829
|
+
seenBf050 = true;
|
|
23830
|
+
return true;
|
|
23831
|
+
});
|
|
23832
|
+
errors.length = 0;
|
|
23833
|
+
errors.push(...deduped);
|
|
23834
|
+
}
|
|
23779
23835
|
if (options.outputIR) {
|
|
23780
23836
|
for (const { componentIR } of entries) {
|
|
23781
23837
|
const componentName = componentIR.metadata.componentName;
|
|
@@ -23814,7 +23870,9 @@ function compileMultipleComponents(source, filePath, componentNames, options) {
|
|
|
23814
23870
|
const adapterOutput = adapter.generate(componentIR, {
|
|
23815
23871
|
scriptBaseName,
|
|
23816
23872
|
siblingTemplatesRegistered: options.siblingTemplatesRegistered,
|
|
23817
|
-
rewriteRelativeImport: options.rewriteRelativeImport
|
|
23873
|
+
rewriteRelativeImport: options.rewriteRelativeImport,
|
|
23874
|
+
scriptAssets: options.scriptAssets,
|
|
23875
|
+
preloadAssets: options.preloadAssets
|
|
23818
23876
|
});
|
|
23819
23877
|
const moduleExports = generateModuleExports(componentIR, fileWideInlineExported, options.rewriteRelativeImport);
|
|
23820
23878
|
const s = adapterOutput.sections;
|
|
@@ -24146,7 +24204,9 @@ function compileJSX(source, filePath, options) {
|
|
|
24146
24204
|
const adapterOutput = adapter.generate(componentIR, {
|
|
24147
24205
|
scriptBaseName: options.scriptBaseName,
|
|
24148
24206
|
siblingTemplatesRegistered: options.siblingTemplatesRegistered,
|
|
24149
|
-
rewriteRelativeImport: options.rewriteRelativeImport
|
|
24207
|
+
rewriteRelativeImport: options.rewriteRelativeImport,
|
|
24208
|
+
scriptAssets: options.scriptAssets,
|
|
24209
|
+
preloadAssets: options.preloadAssets
|
|
24150
24210
|
});
|
|
24151
24211
|
const s = adapterOutput.sections;
|
|
24152
24212
|
let content;
|
|
@@ -24218,7 +24278,7 @@ function compileJSX(source, filePath, options) {
|
|
|
24218
24278
|
return { files, errors };
|
|
24219
24279
|
}
|
|
24220
24280
|
// src/shared-program.ts
|
|
24221
|
-
import
|
|
24281
|
+
import ts22 from "typescript";
|
|
24222
24282
|
function commonParent(paths) {
|
|
24223
24283
|
if (paths.length === 0)
|
|
24224
24284
|
return process.cwd();
|
|
@@ -24239,10 +24299,10 @@ function commonParent(paths) {
|
|
|
24239
24299
|
function createProgramForCorpus(files, options = {}) {
|
|
24240
24300
|
const baseUrl = options.baseUrl ?? commonParent(files);
|
|
24241
24301
|
const compilerOptions = {
|
|
24242
|
-
target:
|
|
24243
|
-
module:
|
|
24244
|
-
moduleResolution:
|
|
24245
|
-
jsx:
|
|
24302
|
+
target: ts22.ScriptTarget.Latest,
|
|
24303
|
+
module: ts22.ModuleKind.ESNext,
|
|
24304
|
+
moduleResolution: ts22.ModuleResolutionKind.Bundler,
|
|
24305
|
+
jsx: ts22.JsxEmit.ReactJSX,
|
|
24246
24306
|
strict: true,
|
|
24247
24307
|
skipLibCheck: true,
|
|
24248
24308
|
noEmit: true,
|
|
@@ -24252,7 +24312,7 @@ function createProgramForCorpus(files, options = {}) {
|
|
|
24252
24312
|
...options.compilerOptions
|
|
24253
24313
|
};
|
|
24254
24314
|
const absolute = files.map((f) => path_default.resolve(f));
|
|
24255
|
-
return
|
|
24315
|
+
return ts22.createProgram(absolute, compilerOptions, undefined, options.oldProgram);
|
|
24256
24316
|
}
|
|
24257
24317
|
// src/adapters/interface.ts
|
|
24258
24318
|
class BaseAdapter {
|
|
@@ -25236,7 +25296,7 @@ function dangerousInnerHtmlDiagnostic(expr, loc, reason) {
|
|
|
25236
25296
|
};
|
|
25237
25297
|
}
|
|
25238
25298
|
// src/combine-client-js.ts
|
|
25239
|
-
import
|
|
25299
|
+
import ts23 from "typescript";
|
|
25240
25300
|
var CHILD_PLACEHOLDER_RE = /import '\/\* @bf-child:(\w+) \*\/'/g;
|
|
25241
25301
|
function combineParentChildClientJs(files) {
|
|
25242
25302
|
const result = new Map;
|
|
@@ -25293,10 +25353,10 @@ function combineParentChildClientJs(files) {
|
|
|
25293
25353
|
return result;
|
|
25294
25354
|
}
|
|
25295
25355
|
function parseAndMerge(content, importsBySource, otherImports, codeSections) {
|
|
25296
|
-
const sourceFile =
|
|
25356
|
+
const sourceFile = ts23.createSourceFile("combine.js", content, ts23.ScriptTarget.Latest, false, ts23.ScriptKind.JS);
|
|
25297
25357
|
const importSpans = [];
|
|
25298
25358
|
for (const stmt of sourceFile.statements) {
|
|
25299
|
-
if (!
|
|
25359
|
+
if (!ts23.isImportDeclaration(stmt))
|
|
25300
25360
|
continue;
|
|
25301
25361
|
const start = stmt.getStart(sourceFile);
|
|
25302
25362
|
const end = stmt.getEnd();
|
|
@@ -25306,8 +25366,8 @@ function parseAndMerge(content, importsBySource, otherImports, codeSections) {
|
|
|
25306
25366
|
continue;
|
|
25307
25367
|
const clause = stmt.importClause;
|
|
25308
25368
|
const bindings = clause?.namedBindings;
|
|
25309
|
-
const specifier =
|
|
25310
|
-
if (clause && !clause.name && bindings &&
|
|
25369
|
+
const specifier = ts23.isStringLiteral(stmt.moduleSpecifier) ? stmt.moduleSpecifier.text : "";
|
|
25370
|
+
if (clause && !clause.name && bindings && ts23.isNamedImports(bindings)) {
|
|
25311
25371
|
if (!importsBySource.has(specifier)) {
|
|
25312
25372
|
importsBySource.set(specifier, new Set);
|
|
25313
25373
|
}
|
|
@@ -25474,7 +25534,7 @@ function escapeRe(s) {
|
|
|
25474
25534
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
25475
25535
|
}
|
|
25476
25536
|
// src/debug.ts
|
|
25477
|
-
import
|
|
25537
|
+
import ts24 from "typescript";
|
|
25478
25538
|
function buildComponentGraph(source, filePath, componentName) {
|
|
25479
25539
|
const ctx = analyzeComponent(source, filePath, componentName);
|
|
25480
25540
|
if (!ctx.jsxReturn) {
|
|
@@ -26759,7 +26819,7 @@ function truncateExpr(expr, max = 40) {
|
|
|
26759
26819
|
function exprReadsPropMember(expr, propsObjectName) {
|
|
26760
26820
|
let sf;
|
|
26761
26821
|
try {
|
|
26762
|
-
sf =
|
|
26822
|
+
sf = ts24.createSourceFile("__attr.tsx", `(${expr})`, ts24.ScriptTarget.Latest, true, ts24.ScriptKind.TSX);
|
|
26763
26823
|
} catch {
|
|
26764
26824
|
return false;
|
|
26765
26825
|
}
|
|
@@ -26767,11 +26827,11 @@ function exprReadsPropMember(expr, propsObjectName) {
|
|
|
26767
26827
|
const visit3 = (n) => {
|
|
26768
26828
|
if (found)
|
|
26769
26829
|
return;
|
|
26770
|
-
if (
|
|
26830
|
+
if (ts24.isPropertyAccessExpression(n) && ts24.isIdentifier(n.expression) && n.expression.text === propsObjectName && n.name.text !== "children") {
|
|
26771
26831
|
found = true;
|
|
26772
26832
|
return;
|
|
26773
26833
|
}
|
|
26774
|
-
|
|
26834
|
+
ts24.forEachChild(n, visit3);
|
|
26775
26835
|
};
|
|
26776
26836
|
visit3(sf);
|
|
26777
26837
|
return found;
|
|
@@ -26841,7 +26901,7 @@ function findSourceFile2(meta) {
|
|
|
26841
26901
|
return null;
|
|
26842
26902
|
}
|
|
26843
26903
|
// src/profiler.ts
|
|
26844
|
-
import
|
|
26904
|
+
import ts25 from "typescript";
|
|
26845
26905
|
var PROFILE_SCHEMA_VERSION = 1;
|
|
26846
26906
|
var DEFAULT_FANOUT_THRESHOLD = 8;
|
|
26847
26907
|
function buildStaticBudget(source, filePath, componentName, options = {}) {
|
|
@@ -27111,15 +27171,15 @@ function joinProfilerEvents(events, index) {
|
|
|
27111
27171
|
return { joined, unattributed, diagnostics };
|
|
27112
27172
|
}
|
|
27113
27173
|
function findUninstrumentedEffects(source, filePath, instrumentedLines) {
|
|
27114
|
-
const sf =
|
|
27174
|
+
const sf = ts25.createSourceFile(filePath, source, ts25.ScriptTarget.Latest, true, ts25.ScriptKind.TSX);
|
|
27115
27175
|
const out = [];
|
|
27116
27176
|
const visit3 = (node) => {
|
|
27117
|
-
if (
|
|
27177
|
+
if (ts25.isCallExpression(node) && ts25.isIdentifier(node.expression) && node.expression.text === "createEffect") {
|
|
27118
27178
|
const line = sf.getLineAndCharacterOfPosition(node.getStart(sf)).line + 1;
|
|
27119
27179
|
if (!instrumentedLines.has(line))
|
|
27120
27180
|
out.push({ file: filePath, line });
|
|
27121
27181
|
}
|
|
27122
|
-
|
|
27182
|
+
ts25.forEachChild(node, visit3);
|
|
27123
27183
|
};
|
|
27124
27184
|
visit3(sf);
|
|
27125
27185
|
out.sort((a, b) => a.line - b.line);
|
|
@@ -27427,13 +27487,13 @@ function assessBatchSafety(args) {
|
|
|
27427
27487
|
const signalGetters = new Set(args.graph.signals.map((s) => s.name));
|
|
27428
27488
|
let sf;
|
|
27429
27489
|
try {
|
|
27430
|
-
sf =
|
|
27490
|
+
sf = ts25.createSourceFile("__h.ts", `const __h = ${args.handler}`, ts25.ScriptTarget.Latest, true);
|
|
27431
27491
|
} catch {
|
|
27432
27492
|
return "unverified";
|
|
27433
27493
|
}
|
|
27434
27494
|
const calls = [];
|
|
27435
27495
|
const visit3 = (node) => {
|
|
27436
|
-
if (
|
|
27496
|
+
if (ts25.isCallExpression(node) && ts25.isIdentifier(node.expression)) {
|
|
27437
27497
|
const name = node.expression.text;
|
|
27438
27498
|
if (setters.has(name))
|
|
27439
27499
|
calls.push({ pos: node.getStart(sf), kind: "write" });
|
|
@@ -27442,7 +27502,7 @@ function assessBatchSafety(args) {
|
|
|
27442
27502
|
else if (!signalGetters.has(name) && !memoNames.has(name))
|
|
27443
27503
|
calls.push({ pos: node.getStart(sf), kind: "risky" });
|
|
27444
27504
|
}
|
|
27445
|
-
|
|
27505
|
+
ts25.forEachChild(node, visit3);
|
|
27446
27506
|
};
|
|
27447
27507
|
visit3(sf);
|
|
27448
27508
|
calls.sort((a, b) => a.pos - b.pos);
|
|
@@ -28092,7 +28152,6 @@ export {
|
|
|
28092
28152
|
resolveSetters,
|
|
28093
28153
|
resolveDangerousInnerHtml,
|
|
28094
28154
|
resetCompilerCounters,
|
|
28095
|
-
renderImportMapHtml,
|
|
28096
28155
|
registerLoweringPlugin,
|
|
28097
28156
|
registerBuiltinLoweringPlugins,
|
|
28098
28157
|
queryHrefPlugin,
|