@barefootjs/test 0.35.4 → 0.35.5
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 +112 -7
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -191466,6 +191466,7 @@ function collectInitStatement(node, ctx) {
|
|
|
191466
191466
|
loc: getSourceLocation(node, ctx.sourceFile, ctx.filePath),
|
|
191467
191467
|
freeIdentifiers: extractFreeIdentifiersFromNode(node),
|
|
191468
191468
|
assignedIdentifiers: extractAssignedIdentifiersFromNode(node),
|
|
191469
|
+
mutatedIdentifiers: extractMutatedIdentifiersFromNode(node),
|
|
191469
191470
|
origin: { phase: "hydrate", scope: "init", effect: "pure" },
|
|
191470
191471
|
needsLeadingSemi: leadsWithAsiHazard(body)
|
|
191471
191472
|
});
|
|
@@ -191525,11 +191526,8 @@ function extractAssignedIdentifiersFromNode(node) {
|
|
|
191525
191526
|
if (import_typescript11.default.isArrowFunction(n) || import_typescript11.default.isFunctionExpression(n) || import_typescript11.default.isFunctionDeclaration(n) || import_typescript11.default.isMethodDeclaration(n) || import_typescript11.default.isGetAccessorDeclaration(n) || import_typescript11.default.isSetAccessorDeclaration(n) || import_typescript11.default.isConstructorDeclaration(n)) {
|
|
191526
191527
|
return;
|
|
191527
191528
|
}
|
|
191528
|
-
if (import_typescript11.default.isBinaryExpression(n)) {
|
|
191529
|
-
|
|
191530
|
-
if (op === import_typescript11.default.SyntaxKind.EqualsToken || op === import_typescript11.default.SyntaxKind.PlusEqualsToken || op === import_typescript11.default.SyntaxKind.MinusEqualsToken || op === import_typescript11.default.SyntaxKind.AsteriskEqualsToken || op === import_typescript11.default.SyntaxKind.SlashEqualsToken || op === import_typescript11.default.SyntaxKind.PercentEqualsToken || op === import_typescript11.default.SyntaxKind.AsteriskAsteriskEqualsToken || op === import_typescript11.default.SyntaxKind.AmpersandEqualsToken || op === import_typescript11.default.SyntaxKind.BarEqualsToken || op === import_typescript11.default.SyntaxKind.CaretEqualsToken || op === import_typescript11.default.SyntaxKind.LessThanLessThanEqualsToken || op === import_typescript11.default.SyntaxKind.GreaterThanGreaterThanEqualsToken || op === import_typescript11.default.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken || op === import_typescript11.default.SyntaxKind.AmpersandAmpersandEqualsToken || op === import_typescript11.default.SyntaxKind.BarBarEqualsToken || op === import_typescript11.default.SyntaxKind.QuestionQuestionEqualsToken) {
|
|
191531
|
-
addFromTarget(n.left);
|
|
191532
|
-
}
|
|
191529
|
+
if (import_typescript11.default.isBinaryExpression(n) && isAssignmentOperator(n.operatorToken.kind)) {
|
|
191530
|
+
addFromTarget(n.left);
|
|
191533
191531
|
}
|
|
191534
191532
|
if (import_typescript11.default.isPrefixUnaryExpression(n) || import_typescript11.default.isPostfixUnaryExpression(n)) {
|
|
191535
191533
|
if (n.operator === import_typescript11.default.SyntaxKind.PlusPlusToken || n.operator === import_typescript11.default.SyntaxKind.MinusMinusToken) {
|
|
@@ -191544,6 +191542,87 @@ function extractAssignedIdentifiersFromNode(node) {
|
|
|
191544
191542
|
ids.delete(name);
|
|
191545
191543
|
return ids;
|
|
191546
191544
|
}
|
|
191545
|
+
var MUTATING_METHOD_NAMES = new Set([
|
|
191546
|
+
"push",
|
|
191547
|
+
"pop",
|
|
191548
|
+
"shift",
|
|
191549
|
+
"unshift",
|
|
191550
|
+
"splice",
|
|
191551
|
+
"sort",
|
|
191552
|
+
"reverse",
|
|
191553
|
+
"fill",
|
|
191554
|
+
"copyWithin",
|
|
191555
|
+
"set",
|
|
191556
|
+
"add",
|
|
191557
|
+
"delete",
|
|
191558
|
+
"clear"
|
|
191559
|
+
]);
|
|
191560
|
+
function extractMutatedIdentifiersFromNode(node) {
|
|
191561
|
+
const ids = new Set;
|
|
191562
|
+
function rootIdentifierOf(expr) {
|
|
191563
|
+
let current = expr;
|
|
191564
|
+
while (true) {
|
|
191565
|
+
if (import_typescript11.default.isIdentifier(current))
|
|
191566
|
+
return current.text;
|
|
191567
|
+
if (import_typescript11.default.isParenthesizedExpression(current)) {
|
|
191568
|
+
current = current.expression;
|
|
191569
|
+
continue;
|
|
191570
|
+
}
|
|
191571
|
+
if (import_typescript11.default.isNonNullExpression(current)) {
|
|
191572
|
+
current = current.expression;
|
|
191573
|
+
continue;
|
|
191574
|
+
}
|
|
191575
|
+
if (import_typescript11.default.isPropertyAccessExpression(current)) {
|
|
191576
|
+
current = current.expression;
|
|
191577
|
+
continue;
|
|
191578
|
+
}
|
|
191579
|
+
if (import_typescript11.default.isElementAccessExpression(current)) {
|
|
191580
|
+
current = current.expression;
|
|
191581
|
+
continue;
|
|
191582
|
+
}
|
|
191583
|
+
return null;
|
|
191584
|
+
}
|
|
191585
|
+
}
|
|
191586
|
+
function visit2(n) {
|
|
191587
|
+
if (import_typescript11.default.isArrowFunction(n) || import_typescript11.default.isFunctionExpression(n) || import_typescript11.default.isFunctionDeclaration(n) || import_typescript11.default.isMethodDeclaration(n) || import_typescript11.default.isGetAccessorDeclaration(n) || import_typescript11.default.isSetAccessorDeclaration(n) || import_typescript11.default.isConstructorDeclaration(n)) {
|
|
191588
|
+
return;
|
|
191589
|
+
}
|
|
191590
|
+
if (import_typescript11.default.isBinaryExpression(n) && isAssignmentOperator(n.operatorToken.kind)) {
|
|
191591
|
+
if (import_typescript11.default.isPropertyAccessExpression(n.left) || import_typescript11.default.isElementAccessExpression(n.left)) {
|
|
191592
|
+
const root = rootIdentifierOf(n.left);
|
|
191593
|
+
if (root)
|
|
191594
|
+
ids.add(root);
|
|
191595
|
+
}
|
|
191596
|
+
} else if (import_typescript11.default.isPrefixUnaryExpression(n) || import_typescript11.default.isPostfixUnaryExpression(n)) {
|
|
191597
|
+
const isIncDec = n.operator === import_typescript11.default.SyntaxKind.PlusPlusToken || n.operator === import_typescript11.default.SyntaxKind.MinusMinusToken;
|
|
191598
|
+
if (isIncDec && (import_typescript11.default.isPropertyAccessExpression(n.operand) || import_typescript11.default.isElementAccessExpression(n.operand))) {
|
|
191599
|
+
const root = rootIdentifierOf(n.operand);
|
|
191600
|
+
if (root)
|
|
191601
|
+
ids.add(root);
|
|
191602
|
+
}
|
|
191603
|
+
} else if (import_typescript11.default.isCallExpression(n)) {
|
|
191604
|
+
const callee = n.expression;
|
|
191605
|
+
if (import_typescript11.default.isPropertyAccessExpression(callee)) {
|
|
191606
|
+
const methodName = callee.name.text;
|
|
191607
|
+
if (MUTATING_METHOD_NAMES.has(methodName)) {
|
|
191608
|
+
const root = rootIdentifierOf(callee.expression);
|
|
191609
|
+
if (root)
|
|
191610
|
+
ids.add(root);
|
|
191611
|
+
} else if (methodName === "assign" && import_typescript11.default.isIdentifier(callee.expression) && callee.expression.text === "Object" && n.arguments.length > 0) {
|
|
191612
|
+
const root = rootIdentifierOf(n.arguments[0]);
|
|
191613
|
+
if (root)
|
|
191614
|
+
ids.add(root);
|
|
191615
|
+
}
|
|
191616
|
+
}
|
|
191617
|
+
}
|
|
191618
|
+
import_typescript11.default.forEachChild(n, visit2);
|
|
191619
|
+
}
|
|
191620
|
+
visit2(node);
|
|
191621
|
+
return ids;
|
|
191622
|
+
}
|
|
191623
|
+
function isAssignmentOperator(kind) {
|
|
191624
|
+
return kind === import_typescript11.default.SyntaxKind.EqualsToken || kind === import_typescript11.default.SyntaxKind.PlusEqualsToken || kind === import_typescript11.default.SyntaxKind.MinusEqualsToken || kind === import_typescript11.default.SyntaxKind.AsteriskEqualsToken || kind === import_typescript11.default.SyntaxKind.SlashEqualsToken || kind === import_typescript11.default.SyntaxKind.PercentEqualsToken || kind === import_typescript11.default.SyntaxKind.AsteriskAsteriskEqualsToken || kind === import_typescript11.default.SyntaxKind.AmpersandEqualsToken || kind === import_typescript11.default.SyntaxKind.BarEqualsToken || kind === import_typescript11.default.SyntaxKind.CaretEqualsToken || kind === import_typescript11.default.SyntaxKind.LessThanLessThanEqualsToken || kind === import_typescript11.default.SyntaxKind.GreaterThanGreaterThanEqualsToken || kind === import_typescript11.default.SyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken || kind === import_typescript11.default.SyntaxKind.AmpersandAmpersandEqualsToken || kind === import_typescript11.default.SyntaxKind.BarBarEqualsToken || kind === import_typescript11.default.SyntaxKind.QuestionQuestionEqualsToken;
|
|
191625
|
+
}
|
|
191547
191626
|
function collectLocalDeclarations(root) {
|
|
191548
191627
|
const names = new Set;
|
|
191549
191628
|
function addBindingName(name) {
|
|
@@ -192701,6 +192780,7 @@ function validateContext(ctx) {
|
|
|
192701
192780
|
}));
|
|
192702
192781
|
}
|
|
192703
192782
|
}
|
|
192783
|
+
markMutatedConstants(ctx);
|
|
192704
192784
|
validateInitStatementReferences(ctx);
|
|
192705
192785
|
validateReactiveFactoryCalls(ctx);
|
|
192706
192786
|
validateNamespaceQualifiedPrimitives(ctx);
|
|
@@ -192864,6 +192944,25 @@ function fileHasUseClientDirective(filePath) {
|
|
|
192864
192944
|
visit2(sf);
|
|
192865
192945
|
return found;
|
|
192866
192946
|
}
|
|
192947
|
+
function markMutatedConstants(ctx) {
|
|
192948
|
+
if (ctx.initStatements.length === 0 || ctx.localConstants.length === 0)
|
|
192949
|
+
return;
|
|
192950
|
+
const mutatedNames = new Set;
|
|
192951
|
+
for (const stmt of ctx.initStatements) {
|
|
192952
|
+
if (stmt.mutatedIdentifiers)
|
|
192953
|
+
for (const name of stmt.mutatedIdentifiers)
|
|
192954
|
+
mutatedNames.add(name);
|
|
192955
|
+
if (stmt.assignedIdentifiers)
|
|
192956
|
+
for (const name of stmt.assignedIdentifiers)
|
|
192957
|
+
mutatedNames.add(name);
|
|
192958
|
+
}
|
|
192959
|
+
if (mutatedNames.size === 0)
|
|
192960
|
+
return;
|
|
192961
|
+
for (const constant of ctx.localConstants) {
|
|
192962
|
+
if (mutatedNames.has(constant.name))
|
|
192963
|
+
constant.mutatedAfterDeclaration = true;
|
|
192964
|
+
}
|
|
192965
|
+
}
|
|
192867
192966
|
function validateInitStatementReferences(ctx) {
|
|
192868
192967
|
if (ctx.initStatements.length === 0)
|
|
192869
192968
|
return;
|
|
@@ -194113,7 +194212,7 @@ function findAssignedNames(bodyText, candidates) {
|
|
|
194113
194212
|
}
|
|
194114
194213
|
};
|
|
194115
194214
|
const visit2 = (node) => {
|
|
194116
|
-
if (import_typescript12.default.isBinaryExpression(node) &&
|
|
194215
|
+
if (import_typescript12.default.isBinaryExpression(node) && isAssignmentOperator2(node.operatorToken.kind)) {
|
|
194117
194216
|
record(node.left);
|
|
194118
194217
|
} else if ((import_typescript12.default.isPrefixUnaryExpression(node) || import_typescript12.default.isPostfixUnaryExpression(node)) && (node.operator === import_typescript12.default.SyntaxKind.PlusPlusToken || node.operator === import_typescript12.default.SyntaxKind.MinusMinusToken)) {
|
|
194119
194218
|
record(node.operand);
|
|
@@ -194142,7 +194241,7 @@ function closeOverWritersOfMutableBindings(primaryRefs, declarations, mutableNam
|
|
|
194142
194241
|
}
|
|
194143
194242
|
return reachable;
|
|
194144
194243
|
}
|
|
194145
|
-
function
|
|
194244
|
+
function isAssignmentOperator2(kind) {
|
|
194146
194245
|
return kind >= import_typescript12.default.SyntaxKind.FirstAssignment && kind <= import_typescript12.default.SyntaxKind.LastAssignment;
|
|
194147
194246
|
}
|
|
194148
194247
|
|
|
@@ -198150,6 +198249,8 @@ function tryResolveTemplateSpanFromConst(expr, ctx) {
|
|
|
198150
198249
|
const constInfo = findLocalConst(expr.text, ctx.analyzer);
|
|
198151
198250
|
if (!constInfo)
|
|
198152
198251
|
return null;
|
|
198252
|
+
if (constInfo.mutatedAfterDeclaration)
|
|
198253
|
+
return null;
|
|
198153
198254
|
const ast = parseConstInitializer(constInfo);
|
|
198154
198255
|
if (!ast)
|
|
198155
198256
|
return null;
|
|
@@ -198166,6 +198267,8 @@ function tryResolveTemplateSpanFromConst(expr, ctx) {
|
|
|
198166
198267
|
const constInfo = findLocalConst(expr.expression.text, ctx.analyzer);
|
|
198167
198268
|
if (!constInfo)
|
|
198168
198269
|
return null;
|
|
198270
|
+
if (constInfo.mutatedAfterDeclaration)
|
|
198271
|
+
return null;
|
|
198169
198272
|
const ast = parseConstInitializer(constInfo);
|
|
198170
198273
|
if (!ast || !import_typescript14.default.isObjectLiteralExpression(ast))
|
|
198171
198274
|
return null;
|
|
@@ -198245,6 +198348,8 @@ function tryResolveIdentifierAsTemplateLiteral(ident, ctx) {
|
|
|
198245
198348
|
const constInfo = findLocalConst(ident.text, ctx.analyzer);
|
|
198246
198349
|
if (!constInfo)
|
|
198247
198350
|
return null;
|
|
198351
|
+
if (constInfo.mutatedAfterDeclaration)
|
|
198352
|
+
return null;
|
|
198248
198353
|
const ast = parseConstInitializer(constInfo);
|
|
198249
198354
|
if (!ast)
|
|
198250
198355
|
return null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@barefootjs/test",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.5",
|
|
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.35.
|
|
42
|
+
"@barefootjs/jsx": "0.35.5"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"typescript": "^5.0.0"
|