@barefootjs/test 0.30.0 → 0.30.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +114 -15
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -189319,20 +189319,115 @@ var SKELETON_PATH_FORCE_CLOSE_GROUPS = [
|
|
|
189319
189319
|
];
|
|
189320
189320
|
|
|
189321
189321
|
// ../jsx/src/prop-rewrite.ts
|
|
189322
|
+
function collectBindingNames(name, out) {
|
|
189323
|
+
if (import_typescript5.default.isIdentifier(name)) {
|
|
189324
|
+
out.add(name.text);
|
|
189325
|
+
return;
|
|
189326
|
+
}
|
|
189327
|
+
for (const el of name.elements) {
|
|
189328
|
+
if (import_typescript5.default.isBindingElement(el))
|
|
189329
|
+
collectBindingNames(el.name, out);
|
|
189330
|
+
}
|
|
189331
|
+
}
|
|
189332
|
+
function scopeFrameOf(n) {
|
|
189333
|
+
if (import_typescript5.default.isFunctionLike(n)) {
|
|
189334
|
+
const frame = new Set;
|
|
189335
|
+
for (const p of n.parameters)
|
|
189336
|
+
collectBindingNames(p.name, frame);
|
|
189337
|
+
if ((import_typescript5.default.isFunctionExpression(n) || import_typescript5.default.isFunctionDeclaration(n)) && n.name)
|
|
189338
|
+
frame.add(n.name.text);
|
|
189339
|
+
return frame.size > 0 ? frame : null;
|
|
189340
|
+
}
|
|
189341
|
+
if (import_typescript5.default.isBlock(n)) {
|
|
189342
|
+
const frame = new Set;
|
|
189343
|
+
for (const st of n.statements) {
|
|
189344
|
+
if (import_typescript5.default.isVariableStatement(st)) {
|
|
189345
|
+
for (const d of st.declarationList.declarations)
|
|
189346
|
+
collectBindingNames(d.name, frame);
|
|
189347
|
+
} else if (import_typescript5.default.isFunctionDeclaration(st) && st.name) {
|
|
189348
|
+
frame.add(st.name.text);
|
|
189349
|
+
}
|
|
189350
|
+
}
|
|
189351
|
+
return frame.size > 0 ? frame : null;
|
|
189352
|
+
}
|
|
189353
|
+
if (import_typescript5.default.isCatchClause(n) && n.variableDeclaration) {
|
|
189354
|
+
const frame = new Set;
|
|
189355
|
+
collectBindingNames(n.variableDeclaration.name, frame);
|
|
189356
|
+
return frame.size > 0 ? frame : null;
|
|
189357
|
+
}
|
|
189358
|
+
return null;
|
|
189359
|
+
}
|
|
189360
|
+
function walkWithScope(root, visit) {
|
|
189361
|
+
const scopeStack = [];
|
|
189362
|
+
const isShadowed = (name) => scopeStack.some((frame) => frame.has(name));
|
|
189363
|
+
function rec(n, parent) {
|
|
189364
|
+
const frame = scopeFrameOf(n);
|
|
189365
|
+
if (frame)
|
|
189366
|
+
scopeStack.push(frame);
|
|
189367
|
+
if (import_typescript5.default.isIdentifier(n))
|
|
189368
|
+
visit(n, parent, isShadowed(n.text));
|
|
189369
|
+
import_typescript5.default.forEachChild(n, (child) => rec(child, n));
|
|
189370
|
+
if (frame)
|
|
189371
|
+
scopeStack.pop();
|
|
189372
|
+
}
|
|
189373
|
+
rec(root);
|
|
189374
|
+
}
|
|
189375
|
+
function isNonValuePosition(n, parent) {
|
|
189376
|
+
if (!parent)
|
|
189377
|
+
return false;
|
|
189378
|
+
if (import_typescript5.default.isPropertyAssignment(parent) && parent.name === n)
|
|
189379
|
+
return true;
|
|
189380
|
+
if (import_typescript5.default.isPropertyAccessExpression(parent) && parent.name === n)
|
|
189381
|
+
return true;
|
|
189382
|
+
if (import_typescript5.default.isQualifiedName(parent) && parent.right === n)
|
|
189383
|
+
return true;
|
|
189384
|
+
if ((import_typescript5.default.isParameter(parent) || import_typescript5.default.isVariableDeclaration(parent) || import_typescript5.default.isBindingElement(parent)) && parent.name === n)
|
|
189385
|
+
return true;
|
|
189386
|
+
if (import_typescript5.default.isTypeReferenceNode(parent))
|
|
189387
|
+
return true;
|
|
189388
|
+
return false;
|
|
189389
|
+
}
|
|
189322
189390
|
function collectAstPropRefs(node, propNames, out) {
|
|
189323
|
-
|
|
189324
|
-
if (
|
|
189325
|
-
|
|
189326
|
-
|
|
189327
|
-
|
|
189328
|
-
|
|
189329
|
-
|
|
189330
|
-
|
|
189331
|
-
|
|
189391
|
+
walkWithScope(node, (n, parent, shadowed) => {
|
|
189392
|
+
if (shadowed || !propNames.has(n.text))
|
|
189393
|
+
return;
|
|
189394
|
+
if (parent && import_typescript5.default.isShorthandPropertyAssignment(parent) && parent.name === n)
|
|
189395
|
+
return;
|
|
189396
|
+
if (isNonValuePosition(n, parent))
|
|
189397
|
+
return;
|
|
189398
|
+
out.add(n.text);
|
|
189399
|
+
});
|
|
189400
|
+
}
|
|
189401
|
+
function applyScopedPropRefRewrite(text, propRefs) {
|
|
189402
|
+
const prefix = "(";
|
|
189403
|
+
const sf = import_typescript5.default.createSourceFile("__bf_prop_rewrite.ts", `${prefix}${text}
|
|
189404
|
+
)`, import_typescript5.default.ScriptTarget.Latest, true);
|
|
189405
|
+
const parseDiagnostics = sf.parseDiagnostics;
|
|
189406
|
+
if (parseDiagnostics && parseDiagnostics.length > 0)
|
|
189407
|
+
return null;
|
|
189408
|
+
const edits = [];
|
|
189409
|
+
walkWithScope(sf, (n, parent, shadowed) => {
|
|
189410
|
+
if (shadowed || !propRefs.has(n.text))
|
|
189411
|
+
return;
|
|
189412
|
+
if (isNonValuePosition(n, parent))
|
|
189413
|
+
return;
|
|
189414
|
+
const start = n.getStart(sf) - prefix.length;
|
|
189415
|
+
const end = n.getEnd() - prefix.length;
|
|
189416
|
+
if (start < 0 || end > text.length)
|
|
189417
|
+
return;
|
|
189418
|
+
if (parent && import_typescript5.default.isShorthandPropertyAssignment(parent) && parent.name === n) {
|
|
189419
|
+
edits.push({ start, end, replacement: `${n.text}: ${PROPS_PARAM}.${n.text}` });
|
|
189420
|
+
return;
|
|
189332
189421
|
}
|
|
189333
|
-
|
|
189422
|
+
edits.push({ start, end, replacement: `${PROPS_PARAM}.${n.text}` });
|
|
189423
|
+
});
|
|
189424
|
+
if (edits.length === 0)
|
|
189425
|
+
return text;
|
|
189426
|
+
let result = text;
|
|
189427
|
+
for (const edit of edits.sort((a, b) => b.start - a.start)) {
|
|
189428
|
+
result = result.slice(0, edit.start) + edit.replacement + result.slice(edit.end);
|
|
189334
189429
|
}
|
|
189335
|
-
|
|
189430
|
+
return result;
|
|
189336
189431
|
}
|
|
189337
189432
|
function applyRegexPropRefRewrite(text, propRefs) {
|
|
189338
189433
|
const { protect, restore } = createTemplateAwareStringProtector();
|
|
@@ -189362,7 +189457,7 @@ function rewriteBarePropRefs(text, node, propNames, extraPropRefs) {
|
|
|
189362
189457
|
}
|
|
189363
189458
|
if (foundPropRefs.size === 0)
|
|
189364
189459
|
return;
|
|
189365
|
-
return applyRegexPropRefRewrite(text, foundPropRefs);
|
|
189460
|
+
return applyScopedPropRefRewrite(text, foundPropRefs) ?? applyRegexPropRefRewrite(text, foundPropRefs);
|
|
189366
189461
|
}
|
|
189367
189462
|
|
|
189368
189463
|
// ../jsx/src/instrumentation.ts
|
|
@@ -196903,20 +196998,20 @@ function attrValueText(value) {
|
|
|
196903
196998
|
}
|
|
196904
196999
|
return out.join(" ");
|
|
196905
197000
|
}
|
|
196906
|
-
function
|
|
197001
|
+
function collectBindingNames2(name, out) {
|
|
196907
197002
|
if (import_typescript11.default.isIdentifier(name)) {
|
|
196908
197003
|
out.add(name.text);
|
|
196909
197004
|
return;
|
|
196910
197005
|
}
|
|
196911
197006
|
for (const el of name.elements) {
|
|
196912
197007
|
if (import_typescript11.default.isBindingElement(el))
|
|
196913
|
-
|
|
197008
|
+
collectBindingNames2(el.name, out);
|
|
196914
197009
|
}
|
|
196915
197010
|
}
|
|
196916
197011
|
function collectPreambleDeclaredNames(stmt, out) {
|
|
196917
197012
|
if (import_typescript11.default.isVariableStatement(stmt)) {
|
|
196918
197013
|
for (const decl of stmt.declarationList.declarations) {
|
|
196919
|
-
|
|
197014
|
+
collectBindingNames2(decl.name, out);
|
|
196920
197015
|
}
|
|
196921
197016
|
} else if (import_typescript11.default.isFunctionDeclaration(stmt) && stmt.name) {
|
|
196922
197017
|
out.add(stmt.name.text);
|
|
@@ -197309,6 +197404,8 @@ function parseTemplateLiteral(expr, ctx) {
|
|
|
197309
197404
|
}
|
|
197310
197405
|
function tryResolveTemplateSpanFromConst(expr, ctx) {
|
|
197311
197406
|
if (import_typescript11.default.isIdentifier(expr)) {
|
|
197407
|
+
if (ctx.loopParams.has(expr.text))
|
|
197408
|
+
return null;
|
|
197312
197409
|
const constInfo = findLocalConst(expr.text, ctx.analyzer);
|
|
197313
197410
|
if (!constInfo)
|
|
197314
197411
|
return null;
|
|
@@ -197323,6 +197420,8 @@ function tryResolveTemplateSpanFromConst(expr, ctx) {
|
|
|
197323
197420
|
if (import_typescript11.default.isElementAccessExpression(expr)) {
|
|
197324
197421
|
if (!import_typescript11.default.isIdentifier(expr.expression))
|
|
197325
197422
|
return null;
|
|
197423
|
+
if (ctx.loopParams.has(expr.expression.text))
|
|
197424
|
+
return null;
|
|
197326
197425
|
const constInfo = findLocalConst(expr.expression.text, ctx.analyzer);
|
|
197327
197426
|
if (!constInfo)
|
|
197328
197427
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/test",
|
|
3
|
-
"version": "0.30.
|
|
3
|
+
"version": "0.30.3",
|
|
4
4
|
"description": "Test utilities for BarefootJS - IR-based component testing without a browser",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"directory": "packages/test"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@barefootjs/jsx": "0.30.
|
|
42
|
+
"@barefootjs/jsx": "0.30.3"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^5.0.0"
|