@kernlang/test 3.5.9-canary.220.1.c398cd95 → 4.0.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.js +50 -47
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -2569,18 +2569,18 @@ function runtimeHandlerLines(node, spaces = 4) {
|
|
|
2569
2569
|
return [];
|
|
2570
2570
|
return code.split('\n').map((line) => `${prefix}${line}`);
|
|
2571
2571
|
}
|
|
2572
|
-
function
|
|
2572
|
+
function runtimeClassFieldLines(node) {
|
|
2573
2573
|
const lines = [];
|
|
2574
2574
|
for (const field of getChildren(node, 'field')) {
|
|
2575
2575
|
const props = getProps(field);
|
|
2576
|
-
if (isTruthy(props.static))
|
|
2577
|
-
continue;
|
|
2578
2576
|
const name = str(props.name);
|
|
2579
2577
|
if (!isRuntimeBindingName(name))
|
|
2580
|
-
return
|
|
2578
|
+
return undefined;
|
|
2581
2579
|
const value = exprPropToRuntimeSource(field, 'value') || rawPropToRuntimeSource(field, 'default');
|
|
2582
|
-
if (value)
|
|
2583
|
-
|
|
2580
|
+
if (!value)
|
|
2581
|
+
continue;
|
|
2582
|
+
const staticKw = isTruthy(props.static) ? 'static ' : '';
|
|
2583
|
+
lines.push(` ${staticKw}${name} = (${value});`);
|
|
2584
2584
|
}
|
|
2585
2585
|
return lines;
|
|
2586
2586
|
}
|
|
@@ -2630,17 +2630,21 @@ function runtimeClassExpr(node) {
|
|
|
2630
2630
|
const name = str(getProps(node).name);
|
|
2631
2631
|
if (!isRuntimeBindingName(name))
|
|
2632
2632
|
return '';
|
|
2633
|
+
const baseName = str(getProps(node).extends);
|
|
2634
|
+
if (baseName && !isRuntimeBindingName(baseName))
|
|
2635
|
+
return '';
|
|
2633
2636
|
const ctorNode = getChildren(node, 'constructor')[0];
|
|
2634
2637
|
const ctorParams = ctorNode ? runtimeParamNames(ctorNode) : [];
|
|
2635
2638
|
if (!ctorParams.every(isRuntimeBindingName))
|
|
2636
2639
|
return '';
|
|
2637
|
-
const
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
+
const fieldLines = runtimeClassFieldLines(node);
|
|
2641
|
+
if (!fieldLines)
|
|
2642
|
+
return '';
|
|
2643
|
+
const lines = [`(class ${name}${baseName ? ` extends ${baseName}` : ''} {`];
|
|
2644
|
+
lines.push(...fieldLines);
|
|
2645
|
+
if (ctorNode) {
|
|
2640
2646
|
lines.push(` constructor(${ctorParams.join(', ')}) {`);
|
|
2641
|
-
lines.push(...
|
|
2642
|
-
if (ctorNode)
|
|
2643
|
-
lines.push(...runtimeHandlerLines(ctorNode));
|
|
2647
|
+
lines.push(...runtimeHandlerLines(ctorNode));
|
|
2644
2648
|
lines.push(' }');
|
|
2645
2649
|
}
|
|
2646
2650
|
for (const method of getChildren(node, 'method')) {
|
|
@@ -3940,7 +3944,7 @@ function orderRuntimeBindings(bindings, entryExpr) {
|
|
|
3940
3944
|
visiting.add(name);
|
|
3941
3945
|
stack.push(name);
|
|
3942
3946
|
for (const dep of depsIn(binding.expr)) {
|
|
3943
|
-
if (dep === name && binding.kind === 'fn')
|
|
3947
|
+
if (dep === name && (binding.kind === 'fn' || binding.kind === 'class'))
|
|
3944
3948
|
continue;
|
|
3945
3949
|
const error = visit(dep);
|
|
3946
3950
|
if (error)
|
|
@@ -5372,6 +5376,24 @@ function nativeInvariantFindings(node, target, context) {
|
|
|
5372
5376
|
const propName = 'has' in props ? 'has' : 'no';
|
|
5373
5377
|
return { message: `Unsupported native invariant: ${propName}=${str(props.has) || str(props.no)}` };
|
|
5374
5378
|
}
|
|
5379
|
+
function evaluateFindingsMatch(invariant, pattern, findings) {
|
|
5380
|
+
const message = findings.join('; ');
|
|
5381
|
+
try {
|
|
5382
|
+
const regex = new RegExp(pattern);
|
|
5383
|
+
return findings.some((finding) => regex.test(finding))
|
|
5384
|
+
? { passed: true }
|
|
5385
|
+
: {
|
|
5386
|
+
passed: false,
|
|
5387
|
+
message: `Expected ${invariant || '<missing>'} findings to match /${pattern}/, got: ${message || '<none>'}`,
|
|
5388
|
+
};
|
|
5389
|
+
}
|
|
5390
|
+
catch (error) {
|
|
5391
|
+
return {
|
|
5392
|
+
passed: false,
|
|
5393
|
+
message: `Native has assertion has invalid matches regex: ${error instanceof Error ? error.message : String(error)}`,
|
|
5394
|
+
};
|
|
5395
|
+
}
|
|
5396
|
+
}
|
|
5375
5397
|
function evaluateHasInvariant(node, target, context) {
|
|
5376
5398
|
const props = getProps(node);
|
|
5377
5399
|
const invariant = str(props.has);
|
|
@@ -5398,22 +5420,7 @@ function evaluateHasInvariant(node, target, context) {
|
|
|
5398
5420
|
}
|
|
5399
5421
|
if ('matches' in props) {
|
|
5400
5422
|
const pattern = runtimePatternValue(node, 'matches') || '';
|
|
5401
|
-
|
|
5402
|
-
try {
|
|
5403
|
-
const regex = new RegExp(pattern);
|
|
5404
|
-
return regex.test(message)
|
|
5405
|
-
? { passed: true }
|
|
5406
|
-
: {
|
|
5407
|
-
passed: false,
|
|
5408
|
-
message: `Expected ${invariant || '<missing>'} findings to match /${pattern}/, got: ${message || '<none>'}`,
|
|
5409
|
-
};
|
|
5410
|
-
}
|
|
5411
|
-
catch (error) {
|
|
5412
|
-
return {
|
|
5413
|
-
passed: false,
|
|
5414
|
-
message: `Native has assertion has invalid matches regex: ${error instanceof Error ? error.message : String(error)}`,
|
|
5415
|
-
};
|
|
5416
|
-
}
|
|
5423
|
+
return evaluateFindingsMatch(invariant, pattern, findings);
|
|
5417
5424
|
}
|
|
5418
5425
|
return { passed: true };
|
|
5419
5426
|
}
|
|
@@ -5422,6 +5429,20 @@ function evaluateHasInvariant(node, target, context) {
|
|
|
5422
5429
|
if (blocking)
|
|
5423
5430
|
return { passed: false, message: blocking };
|
|
5424
5431
|
}
|
|
5432
|
+
if ('matches' in props) {
|
|
5433
|
+
const collected = nativeInvariantFindings(node, target, context);
|
|
5434
|
+
if (collected.message)
|
|
5435
|
+
return { passed: false, message: collected.message };
|
|
5436
|
+
const findings = collected.findings || [];
|
|
5437
|
+
if (findings.length === 0) {
|
|
5438
|
+
return {
|
|
5439
|
+
passed: false,
|
|
5440
|
+
message: `Expected target to have ${invariant || '<missing>'}, but none was found`,
|
|
5441
|
+
};
|
|
5442
|
+
}
|
|
5443
|
+
const pattern = runtimePatternValue(node, 'matches') || '';
|
|
5444
|
+
return evaluateFindingsMatch(invariant, pattern, findings);
|
|
5445
|
+
}
|
|
5425
5446
|
const evaluated = evaluateNoInvariant(nodeWithProps(node, { ...props, no: invariant }), target, context);
|
|
5426
5447
|
if (isAssertionConfigurationFailure(evaluated.message)) {
|
|
5427
5448
|
return { passed: false, message: evaluated.message };
|
|
@@ -5432,24 +5453,6 @@ function evaluateHasInvariant(node, target, context) {
|
|
|
5432
5453
|
message: `Expected target to have ${invariant || '<missing>'}, but none was found`,
|
|
5433
5454
|
};
|
|
5434
5455
|
}
|
|
5435
|
-
if ('matches' in props) {
|
|
5436
|
-
const pattern = runtimePatternValue(node, 'matches') || '';
|
|
5437
|
-
try {
|
|
5438
|
-
const regex = new RegExp(pattern);
|
|
5439
|
-
return regex.test(evaluated.message || '')
|
|
5440
|
-
? { passed: true }
|
|
5441
|
-
: {
|
|
5442
|
-
passed: false,
|
|
5443
|
-
message: `Expected ${invariant || '<missing>'} message to match /${pattern}/, got: ${evaluated.message || '<none>'}`,
|
|
5444
|
-
};
|
|
5445
|
-
}
|
|
5446
|
-
catch (error) {
|
|
5447
|
-
return {
|
|
5448
|
-
passed: false,
|
|
5449
|
-
message: `Native has assertion has invalid matches regex: ${error instanceof Error ? error.message : String(error)}`,
|
|
5450
|
-
};
|
|
5451
|
-
}
|
|
5452
|
-
}
|
|
5453
5456
|
return { passed: true };
|
|
5454
5457
|
}
|
|
5455
5458
|
function evaluateMachineReachability(node, target) {
|