@svelte-vitals/core 0.37.0 → 0.38.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/index.d.ts +1 -3
- package/dist/index.js +40 -49
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1643,13 +1643,11 @@ declare const APP_SCRIPT: string;
|
|
|
1643
1643
|
declare function renderAppShell(snapshot: AppSnapshot): string;
|
|
1644
1644
|
/**
|
|
1645
1645
|
* Static (non-live) document over a prebuilt JsonReport — kept as the public name the
|
|
1646
|
-
* html reporter has always exported.
|
|
1646
|
+
* html reporter has always exported.
|
|
1647
1647
|
*/
|
|
1648
1648
|
declare function buildHtmlDocument(report: JsonReport, meta: {
|
|
1649
1649
|
version: string;
|
|
1650
1650
|
coreVersion?: string;
|
|
1651
|
-
}, opts?: {
|
|
1652
|
-
routeBadges?: Record<string, RouteBadge>;
|
|
1653
1651
|
}): string;
|
|
1654
1652
|
/** Render results as the self-contained HTML report (the CLI's `--reporter html`). */
|
|
1655
1653
|
declare function formatHtmlReport(results: Result[], config: Config, meta: {
|
package/dist/index.js
CHANGED
|
@@ -167,17 +167,9 @@ function collectEachBlocks(node, source, acc) {
|
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
var WALK_IGNORED_KEYS = /* @__PURE__ */ new Set(["type", "start", "end", "loc", "range"]);
|
|
170
|
+
var NO_BOUNDARIES = /* @__PURE__ */ new Set();
|
|
170
171
|
function walkEstree(node, visit) {
|
|
171
|
-
|
|
172
|
-
for (const child of node) walkEstree(child, visit);
|
|
173
|
-
return;
|
|
174
|
-
}
|
|
175
|
-
if (!node || typeof node !== "object" || typeof node.type !== "string") return;
|
|
176
|
-
visit(node);
|
|
177
|
-
for (const key of Object.keys(node)) {
|
|
178
|
-
if (WALK_IGNORED_KEYS.has(key)) continue;
|
|
179
|
-
walkEstree(node[key], visit);
|
|
180
|
-
}
|
|
172
|
+
walkEvalScope(node, (n) => void visit(n), /* @__PURE__ */ new Set(), NO_BOUNDARIES);
|
|
181
173
|
}
|
|
182
174
|
function isEffectCall(node) {
|
|
183
175
|
const c = node?.callee;
|
|
@@ -280,18 +272,7 @@ function scopeIntroducedNames(node) {
|
|
|
280
272
|
return introduced;
|
|
281
273
|
}
|
|
282
274
|
function walkScoped(node, visit, shadowed = /* @__PURE__ */ new Set()) {
|
|
283
|
-
|
|
284
|
-
for (const child of node) walkScoped(child, visit, shadowed);
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
if (!node || typeof node !== "object" || typeof node.type !== "string") return;
|
|
288
|
-
const introduced = scopeIntroducedNames(node);
|
|
289
|
-
const scope = introduced.size > 0 ? /* @__PURE__ */ new Set([...shadowed, ...introduced]) : shadowed;
|
|
290
|
-
visit(node, scope);
|
|
291
|
-
for (const key of Object.keys(node)) {
|
|
292
|
-
if (WALK_IGNORED_KEYS.has(key)) continue;
|
|
293
|
-
walkScoped(node[key], visit, scope);
|
|
294
|
-
}
|
|
275
|
+
walkEvalScope(node, (n, scope) => void visit(n, scope), shadowed, NO_BOUNDARIES);
|
|
295
276
|
}
|
|
296
277
|
function collectStateWrites(root, stateNames, acc, kinds) {
|
|
297
278
|
const record = (name, kind) => {
|
|
@@ -769,7 +750,7 @@ function collectPropNames(program, includeBindable) {
|
|
|
769
750
|
let seen = 0;
|
|
770
751
|
let ambiguous = false;
|
|
771
752
|
walkEstree(program, (n) => {
|
|
772
|
-
if (n.type !== "VariableDeclarator" || !n.init || !isPropsCall(n.init)) return;
|
|
753
|
+
if (n.type !== "VariableDeclarator" || !n.init || !isPropsCall(unwrapTs(n.init))) return;
|
|
773
754
|
seen++;
|
|
774
755
|
if (n.id?.type === "Identifier") {
|
|
775
756
|
names.add(n.id.name);
|
|
@@ -842,7 +823,7 @@ function countProps(program) {
|
|
|
842
823
|
let seen = 0;
|
|
843
824
|
let uncountable = false;
|
|
844
825
|
walkEstree(program, (n) => {
|
|
845
|
-
if (n.type !== "VariableDeclarator" || !n.init || !isPropsCall(n.init)) return;
|
|
826
|
+
if (n.type !== "VariableDeclarator" || !n.init || !isPropsCall(unwrapTs(n.init))) return;
|
|
846
827
|
seen++;
|
|
847
828
|
const props = n.id?.type === "ObjectPattern" ? n.id.properties : void 0;
|
|
848
829
|
if (!Array.isArray(props) || props.some((p) => p?.type === "RestElement")) {
|
|
@@ -958,19 +939,19 @@ var EVAL_SCOPE_BOUNDARIES = /* @__PURE__ */ new Set([
|
|
|
958
939
|
"ClassDeclaration",
|
|
959
940
|
"ClassExpression"
|
|
960
941
|
]);
|
|
961
|
-
function walkEvalScope(node, visit, shadowed = /* @__PURE__ */ new Set()) {
|
|
942
|
+
function walkEvalScope(node, visit, shadowed = /* @__PURE__ */ new Set(), boundaries = EVAL_SCOPE_BOUNDARIES) {
|
|
962
943
|
if (Array.isArray(node)) {
|
|
963
|
-
for (const child of node) walkEvalScope(child, visit, shadowed);
|
|
944
|
+
for (const child of node) walkEvalScope(child, visit, shadowed, boundaries);
|
|
964
945
|
return;
|
|
965
946
|
}
|
|
966
947
|
if (!node || typeof node !== "object" || typeof node.type !== "string") return;
|
|
967
948
|
const introduced = scopeIntroducedNames(node);
|
|
968
949
|
const scope = introduced.size > 0 ? /* @__PURE__ */ new Set([...shadowed, ...introduced]) : shadowed;
|
|
969
950
|
if (visit(node, scope)) return;
|
|
970
|
-
if (
|
|
951
|
+
if (boundaries.has(node.type)) return;
|
|
971
952
|
for (const key of Object.keys(node)) {
|
|
972
953
|
if (WALK_IGNORED_KEYS.has(key)) continue;
|
|
973
|
-
walkEvalScope(node[key], visit, scope);
|
|
954
|
+
walkEvalScope(node[key], visit, scope, boundaries);
|
|
974
955
|
}
|
|
975
956
|
}
|
|
976
957
|
function collectEvalScopeCalls(root, source, matcher, skipSubtree, initialShadowed) {
|
|
@@ -1261,13 +1242,13 @@ function collectModuleStateDecls(program, source) {
|
|
|
1261
1242
|
const decl = unwrapExport(stmt);
|
|
1262
1243
|
if (decl?.type === "VariableDeclaration") {
|
|
1263
1244
|
for (const d of decl.declarations ?? []) {
|
|
1264
|
-
if (d?.id?.type === "Identifier" && d.init && isStateDeclaration(d.init)) {
|
|
1245
|
+
if (d?.id?.type === "Identifier" && d.init && isStateDeclaration(unwrapTs(d.init))) {
|
|
1265
1246
|
out.push({ name: d.id.name, line: lineOf(source, d.start) });
|
|
1266
1247
|
}
|
|
1267
1248
|
}
|
|
1268
1249
|
} else if (decl?.type === "ClassDeclaration" && decl.id?.type === "Identifier") {
|
|
1269
1250
|
const hasStateField = (decl.body?.body ?? []).some(
|
|
1270
|
-
(m) => m?.type === "PropertyDefinition" && m.value && isStateDeclaration(m.value)
|
|
1251
|
+
(m) => m?.type === "PropertyDefinition" && m.value && isStateDeclaration(unwrapTs(m.value))
|
|
1271
1252
|
);
|
|
1272
1253
|
if (hasStateField) statefulClasses.add(decl.id.name);
|
|
1273
1254
|
}
|
|
@@ -1303,6 +1284,17 @@ function parseModuleFacts(source, filename) {
|
|
|
1303
1284
|
for (const l of raw) basePathLinks.push({ ...l, line: shift(l.line) });
|
|
1304
1285
|
basePathLinks.sort((a, b) => a.line - b.line);
|
|
1305
1286
|
}
|
|
1287
|
+
const importSpans = [];
|
|
1288
|
+
const namespaceImports = [];
|
|
1289
|
+
if (program) {
|
|
1290
|
+
const rawImportSpans = [];
|
|
1291
|
+
collectImportSources(program, wrapped, rawImportSpans);
|
|
1292
|
+
for (const s of rawImportSpans) importSpans.push({ ...s, line: shift(s.line) });
|
|
1293
|
+
const rawNamespaceImports = [];
|
|
1294
|
+
collectNamespaceImports(program, wrapped, rawNamespaceImports);
|
|
1295
|
+
for (const n of rawNamespaceImports) namespaceImports.push({ ...n, line: shift(n.line) });
|
|
1296
|
+
}
|
|
1297
|
+
const imports = importSpans.map((s) => s.source);
|
|
1306
1298
|
return {
|
|
1307
1299
|
eachBlocks: [],
|
|
1308
1300
|
effects: [],
|
|
@@ -1310,9 +1302,9 @@ function parseModuleFacts(source, filename) {
|
|
|
1310
1302
|
javascriptUrls: [],
|
|
1311
1303
|
loc: 0,
|
|
1312
1304
|
propCount: 0,
|
|
1313
|
-
imports
|
|
1314
|
-
importSpans
|
|
1315
|
-
namespaceImports
|
|
1305
|
+
imports,
|
|
1306
|
+
importSpans,
|
|
1307
|
+
namespaceImports,
|
|
1316
1308
|
constableStates: [],
|
|
1317
1309
|
mutatedProps: [],
|
|
1318
1310
|
stalePropDerivations: [],
|
|
@@ -1409,11 +1401,12 @@ function parseComponentFacts(source, filename) {
|
|
|
1409
1401
|
const stateDecls = [];
|
|
1410
1402
|
walkEstree(program, (n) => {
|
|
1411
1403
|
if (n.type !== "VariableDeclarator" || !n.init) return;
|
|
1412
|
-
|
|
1404
|
+
const init = unwrapTs(n.init);
|
|
1405
|
+
if (isStateDeclaration(init) && n.id?.type === "Identifier") {
|
|
1413
1406
|
stateNames.add(n.id.name);
|
|
1414
1407
|
stateDecls.push({ name: n.id.name, line: lineOf(source, n.start) });
|
|
1415
1408
|
}
|
|
1416
|
-
if (isStateDeclaration(
|
|
1409
|
+
if (isStateDeclaration(init) || isDerivedDeclaration(init) || isPropsCall(init))
|
|
1417
1410
|
addBoundNames(n.id, reactiveNames);
|
|
1418
1411
|
});
|
|
1419
1412
|
walkEstree(program, (n) => {
|
|
@@ -1440,8 +1433,10 @@ function parseComponentFacts(source, filename) {
|
|
|
1440
1433
|
for (const stmt of program.body ?? []) {
|
|
1441
1434
|
if (stmt?.type !== "VariableDeclaration") continue;
|
|
1442
1435
|
for (const d of stmt.declarations ?? []) {
|
|
1443
|
-
if (d?.id?.type !== "Identifier" || !d.init
|
|
1444
|
-
const
|
|
1436
|
+
if (d?.id?.type !== "Identifier" || !d.init) continue;
|
|
1437
|
+
const init = unwrapTs(d.init);
|
|
1438
|
+
if (!isPlainStateCall(init)) continue;
|
|
1439
|
+
const arg = unwrapTs(init.arguments?.[0]);
|
|
1445
1440
|
if (arg?.type === "ObjectExpression" || arg?.type === "ArrayExpression") {
|
|
1446
1441
|
rawableCandidates.push({ name: d.id.name, line: lineOf(source, d.start) });
|
|
1447
1442
|
}
|
|
@@ -1475,8 +1470,10 @@ function parseComponentFacts(source, filename) {
|
|
|
1475
1470
|
for (const stmt of program.body ?? []) {
|
|
1476
1471
|
if (stmt?.type !== "VariableDeclaration") continue;
|
|
1477
1472
|
for (const d of stmt.declarations ?? []) {
|
|
1478
|
-
if (d?.id?.type !== "Identifier" || !d.init
|
|
1479
|
-
const
|
|
1473
|
+
if (d?.id?.type !== "Identifier" || !d.init) continue;
|
|
1474
|
+
const init = unwrapTs(d.init);
|
|
1475
|
+
if (!isPlainStateCall(init)) continue;
|
|
1476
|
+
const arg = unwrapTs(init.arguments?.[0]);
|
|
1480
1477
|
if (arg?.type === "NewExpression" && arg.callee?.type === "Identifier" && BUILTIN_STATE_TYPES.has(arg.callee.name)) {
|
|
1481
1478
|
builtinCandidates.set(d.id.name, { type: arg.callee.name, line: lineOf(source, d.start) });
|
|
1482
1479
|
}
|
|
@@ -3514,7 +3511,6 @@ var PLACEHOLDER_RES = [
|
|
|
3514
3511
|
/yourcompany/i,
|
|
3515
3512
|
/your name here/i
|
|
3516
3513
|
];
|
|
3517
|
-
var PLACEHOLDERS = PLACEHOLDER_RES.map((r) => r.source);
|
|
3518
3514
|
function hasPlaceholder(s) {
|
|
3519
3515
|
return PLACEHOLDER_RES.some((re) => re.test(s));
|
|
3520
3516
|
}
|
|
@@ -3746,14 +3742,12 @@ var seoJsonLdRequiredProps = jsonldRule({
|
|
|
3746
3742
|
});
|
|
3747
3743
|
|
|
3748
3744
|
// src/rules/seo/text-metrics.ts
|
|
3749
|
-
var segmenter =
|
|
3745
|
+
var segmenter = new Intl.Segmenter();
|
|
3750
3746
|
function collapseWhitespace(s) {
|
|
3751
3747
|
return s.trim().replace(/\s+/g, " ");
|
|
3752
3748
|
}
|
|
3753
3749
|
function visibleLength(s) {
|
|
3754
|
-
|
|
3755
|
-
if (!segmenter) return [...collapsed].length;
|
|
3756
|
-
return [...segmenter.segment(collapsed)].length;
|
|
3750
|
+
return [...segmenter.segment(collapseWhitespace(s))].length;
|
|
3757
3751
|
}
|
|
3758
3752
|
|
|
3759
3753
|
// src/rules/seo/length-rule.ts
|
|
@@ -7202,13 +7196,10 @@ function renderAppShell(snapshot) {
|
|
|
7202
7196
|
const title = snapshot.live ? "svelte-vitals dashboard" : "svelte-vitals report";
|
|
7203
7197
|
return `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>${title}</title><style>${APP_STYLE}</style></head><body><div class="dv-app" id="dv-app"><header class="dv-topbar" id="dv-topbar"></header><nav class="dv-sidebar" id="dv-sidebar"></nav><main class="dv-detail" id="dv-detail"></main></div><script type="application/json" id="svelte-vitals-data">${embedJson(safe)}</script><script>${APP_SCRIPT}</script></body></html>`;
|
|
7204
7198
|
}
|
|
7205
|
-
function buildHtmlDocument(report, meta
|
|
7206
|
-
const badges = Object.fromEntries(
|
|
7207
|
-
Object.entries(opts?.routeBadges ?? {}).filter(([, b]) => b === "measured" || b === "static")
|
|
7208
|
-
);
|
|
7199
|
+
function buildHtmlDocument(report, meta) {
|
|
7209
7200
|
return renderAppShell({
|
|
7210
7201
|
report,
|
|
7211
|
-
badges,
|
|
7202
|
+
badges: {},
|
|
7212
7203
|
analyzing: false,
|
|
7213
7204
|
sequence: 0,
|
|
7214
7205
|
live: false,
|