tstyche 7.2.1 → 7.2.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/api.d.ts +5 -5
- package/dist/api.js +211 -242
- package/package.json +5 -5
package/dist/api.d.ts
CHANGED
|
@@ -79,14 +79,14 @@ declare class TestTree {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
declare class DiagnosticOrigin {
|
|
82
|
-
|
|
82
|
+
expectNode: ExpectNode | undefined;
|
|
83
83
|
end: number;
|
|
84
84
|
sourceFile: ts.SourceFile | JsonSourceFile;
|
|
85
85
|
start: number;
|
|
86
|
-
constructor(start: number, end: number, sourceFile: ts.SourceFile | JsonSourceFile,
|
|
87
|
-
static fromAbilityDiagnostic(diagnostic: ts.DiagnosticWithLocation,
|
|
88
|
-
static fromAssertion(
|
|
89
|
-
static fromNode(node: ts.Node,
|
|
86
|
+
constructor(start: number, end: number, sourceFile: ts.SourceFile | JsonSourceFile, expectNode?: ExpectNode);
|
|
87
|
+
static fromAbilityDiagnostic(diagnostic: ts.DiagnosticWithLocation, expectNode: ExpectNode): DiagnosticOrigin;
|
|
88
|
+
static fromAssertion(expectNode: ExpectNode): DiagnosticOrigin;
|
|
89
|
+
static fromNode(node: ts.Node, expectNode?: ExpectNode): DiagnosticOrigin;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
declare class Diagnostic {
|
package/dist/api.js
CHANGED
|
@@ -112,25 +112,25 @@ function isDiagnosticWithLocation(diagnostic) {
|
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
class DiagnosticOrigin {
|
|
115
|
-
|
|
115
|
+
expectNode;
|
|
116
116
|
end;
|
|
117
117
|
sourceFile;
|
|
118
118
|
start;
|
|
119
|
-
constructor(start, end, sourceFile,
|
|
119
|
+
constructor(start, end, sourceFile, expectNode) {
|
|
120
120
|
this.start = start;
|
|
121
121
|
this.end = end;
|
|
122
122
|
this.sourceFile = sourceFile;
|
|
123
|
-
this.
|
|
123
|
+
this.expectNode = expectNode;
|
|
124
124
|
}
|
|
125
|
-
static fromAbilityDiagnostic(diagnostic,
|
|
126
|
-
return new DiagnosticOrigin(diagnostic.start, getTextSpanEnd(diagnostic), diagnostic.file,
|
|
125
|
+
static fromAbilityDiagnostic(diagnostic, expectNode) {
|
|
126
|
+
return new DiagnosticOrigin(diagnostic.start, getTextSpanEnd(diagnostic), diagnostic.file, expectNode);
|
|
127
127
|
}
|
|
128
|
-
static fromAssertion(
|
|
129
|
-
const node =
|
|
130
|
-
return new DiagnosticOrigin(node.getStart(), node.getEnd(), node.getSourceFile(),
|
|
128
|
+
static fromAssertion(expectNode) {
|
|
129
|
+
const node = expectNode.matcherNameNode.name;
|
|
130
|
+
return new DiagnosticOrigin(node.getStart(), node.getEnd(), node.getSourceFile(), expectNode);
|
|
131
131
|
}
|
|
132
|
-
static fromNode(node,
|
|
133
|
-
return new DiagnosticOrigin(node.getStart(), node.getEnd(), node.getSourceFile(),
|
|
132
|
+
static fromNode(node, expectNode) {
|
|
133
|
+
return new DiagnosticOrigin(node.getStart(), node.getEnd(), node.getSourceFile(), expectNode);
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -517,17 +517,20 @@ class Environment {
|
|
|
517
517
|
return Path.resolve(os.homedir(), ".local", "share", "TSTyche");
|
|
518
518
|
}
|
|
519
519
|
static #resolveTypeScriptModule() {
|
|
520
|
-
let specifier = "typescript";
|
|
521
520
|
if (process.env["TSTYCHE_TYPESCRIPT_MODULE"] != null) {
|
|
522
|
-
specifier = process.env["TSTYCHE_TYPESCRIPT_MODULE"];
|
|
521
|
+
const specifier = process.env["TSTYCHE_TYPESCRIPT_MODULE"];
|
|
522
|
+
if (specifier !== "") {
|
|
523
|
+
return import.meta.resolve(specifier);
|
|
524
|
+
}
|
|
525
|
+
return;
|
|
523
526
|
}
|
|
524
527
|
let resolvedModule;
|
|
525
528
|
try {
|
|
526
|
-
resolvedModule = import.meta.resolve(
|
|
529
|
+
resolvedModule = import.meta.resolve("typescript");
|
|
527
530
|
}
|
|
528
531
|
catch {
|
|
529
532
|
}
|
|
530
|
-
return resolvedModule;
|
|
533
|
+
return resolvedModule?.endsWith("lib/typescript.js") ? resolvedModule : undefined;
|
|
531
534
|
}
|
|
532
535
|
}
|
|
533
536
|
|
|
@@ -609,7 +612,7 @@ class Fetcher {
|
|
|
609
612
|
}
|
|
610
613
|
async get(request, diagnostic, options) {
|
|
611
614
|
let delay = 3000;
|
|
612
|
-
request.headers.set("User-Agent", `tstyche
|
|
615
|
+
request.headers.set("User-Agent", `tstyche/7.2.3 ${process.platform} ${process.arch}`);
|
|
613
616
|
for (let attempt = 0; attempt <= this.#retries; attempt++) {
|
|
614
617
|
const isLastAttempt = attempt === this.#retries;
|
|
615
618
|
const suppressErrors = options?.suppressErrors || !isLastAttempt;
|
|
@@ -2357,8 +2360,8 @@ function CodeFrameText({ diagnosticCategory, diagnosticOrigin, options }) {
|
|
|
2357
2360
|
}
|
|
2358
2361
|
}
|
|
2359
2362
|
let breadcrumbs;
|
|
2360
|
-
if (showBreadcrumbs && diagnosticOrigin.
|
|
2361
|
-
breadcrumbs = jsx(BreadcrumbsText, { ancestor: diagnosticOrigin.
|
|
2363
|
+
if (showBreadcrumbs && diagnosticOrigin.expectNode != null) {
|
|
2364
|
+
breadcrumbs = jsx(BreadcrumbsText, { ancestor: diagnosticOrigin.expectNode.parent });
|
|
2362
2365
|
}
|
|
2363
2366
|
const location = (jsx(Line, { children: [" ".repeat(gutterWidth + 2), jsx(Text, { color: "90", children: " at " }), jsx(Text, { color: "36", children: Path.relative("", diagnosticOrigin.sourceFile.fileName) }), jsx(Text, { color: "90", children: `:${firstMarkedLine + 1}:${firstMarkedCharacter + 1}` }), breadcrumbs] }));
|
|
2364
2367
|
return (jsx(Text, { children: [codeFrame, jsx(Line, {}), location] }));
|
|
@@ -3382,12 +3385,21 @@ function deepCompareKeys(a, b, keys) {
|
|
|
3382
3385
|
}
|
|
3383
3386
|
return true;
|
|
3384
3387
|
}
|
|
3385
|
-
function
|
|
3386
|
-
return
|
|
3388
|
+
function isCapitaizedIdentifierLike(node, compiler) {
|
|
3389
|
+
return isIdentifierLike(node, compiler) && /^[A-Z_$]/.test(node.getText()[0]);
|
|
3387
3390
|
}
|
|
3388
|
-
function
|
|
3391
|
+
function isChildOfExpressionStatement(node, compiler) {
|
|
3389
3392
|
return compiler.isExpressionStatement(node.parent);
|
|
3390
3393
|
}
|
|
3394
|
+
function isIdentifierLike(node, compiler) {
|
|
3395
|
+
return (compiler.isIdentifier(node) ||
|
|
3396
|
+
compiler.isPropertyAccessExpression(node) ||
|
|
3397
|
+
compiler.isTypeReferenceNode(node) ||
|
|
3398
|
+
compiler.isExpressionWithTypeArguments(node));
|
|
3399
|
+
}
|
|
3400
|
+
function belongsToArgumentList(node, compiler) {
|
|
3401
|
+
return compiler.isCallExpression(node.parent) && node.parent.arguments.some((argument) => argument === node);
|
|
3402
|
+
}
|
|
3391
3403
|
|
|
3392
3404
|
class AbilityLayer {
|
|
3393
3405
|
#compiler;
|
|
@@ -3397,26 +3409,21 @@ class AbilityLayer {
|
|
|
3397
3409
|
this.#compiler = compiler;
|
|
3398
3410
|
this.#editor = editor;
|
|
3399
3411
|
}
|
|
3400
|
-
#belongsToNode(node, diagnostic) {
|
|
3401
|
-
return diagnosticBelongsToNode(diagnostic, node.matcherNode) || diagnosticBelongsToNode(diagnostic, node.source);
|
|
3402
|
-
}
|
|
3403
3412
|
close(diagnostics) {
|
|
3404
3413
|
if (diagnostics.length > 0 && this.#nodes.length > 0) {
|
|
3405
3414
|
this.#nodes.reverse();
|
|
3406
3415
|
for (const diagnostic of diagnostics) {
|
|
3407
|
-
this.#
|
|
3416
|
+
for (const node of this.#nodes) {
|
|
3417
|
+
if (diagnosticBelongsToNode(diagnostic, node.matcherNode) ||
|
|
3418
|
+
diagnosticBelongsToNode(diagnostic, node.source)) {
|
|
3419
|
+
node.abilityDiagnostics.add(diagnostic);
|
|
3420
|
+
break;
|
|
3421
|
+
}
|
|
3422
|
+
}
|
|
3408
3423
|
}
|
|
3409
3424
|
}
|
|
3410
3425
|
this.#nodes = [];
|
|
3411
3426
|
}
|
|
3412
|
-
#mapToNodes(diagnostic) {
|
|
3413
|
-
for (const node of this.#nodes) {
|
|
3414
|
-
if (this.#belongsToNode(node, diagnostic)) {
|
|
3415
|
-
node.abilityDiagnostics.add(diagnostic);
|
|
3416
|
-
break;
|
|
3417
|
-
}
|
|
3418
|
-
}
|
|
3419
|
-
}
|
|
3420
3427
|
visitExpect(expect) {
|
|
3421
3428
|
const expectStart = expect.node.getStart();
|
|
3422
3429
|
const expectExpressionEnd = expect.node.expression.getEnd();
|
|
@@ -3430,11 +3437,7 @@ class AbilityLayer {
|
|
|
3430
3437
|
const targetNode = expect.target?.[0];
|
|
3431
3438
|
if (!sourceNode ||
|
|
3432
3439
|
!targetNode ||
|
|
3433
|
-
!(this.#compiler
|
|
3434
|
-
this.#compiler.isPropertyAccessExpression(sourceNode) ||
|
|
3435
|
-
this.#compiler.isTypeReferenceNode(sourceNode) ||
|
|
3436
|
-
this.#compiler.isExpressionWithTypeArguments(sourceNode)) ||
|
|
3437
|
-
!/^[A-Z_$]/.test(sourceNode.getText()[0]) ||
|
|
3440
|
+
!isCapitaizedIdentifierLike(sourceNode, this.#compiler) ||
|
|
3438
3441
|
!this.#compiler.isObjectLiteralExpression(targetNode) ||
|
|
3439
3442
|
!targetNode.properties.every((property) => (this.#compiler.isPropertyAssignment(property) &&
|
|
3440
3443
|
(this.#compiler.isIdentifier(property.name) || this.#compiler.isStringLiteral(property.name))) ||
|
|
@@ -3442,18 +3445,18 @@ class AbilityLayer {
|
|
|
3442
3445
|
return;
|
|
3443
3446
|
}
|
|
3444
3447
|
const sourceText = sourceNode.getText();
|
|
3445
|
-
if (
|
|
3448
|
+
if (belongsToArgumentList(sourceNode, this.#compiler)) {
|
|
3446
3449
|
this.#editor
|
|
3447
3450
|
.eraseTrailingComma(expect.source)
|
|
3448
3451
|
.erase(expectStart, matcherNodeEnd)
|
|
3449
|
-
.update(expectStart, matcherNameEnd,
|
|
3452
|
+
.update(expectStart, matcherNameEnd, isChildOfExpressionStatement(expect.matcherNode, this.#compiler) ? ";" : "")
|
|
3450
3453
|
.update(sourceNode.getStart() - 1, sourceNode.getEnd(), `<${sourceText}`);
|
|
3451
3454
|
}
|
|
3452
3455
|
else {
|
|
3453
3456
|
const id = ["SC", expectStart, Date.now().toString(36)].join("_");
|
|
3454
3457
|
this.#editor
|
|
3455
3458
|
.erase(expectStart, matcherNodeEnd)
|
|
3456
|
-
.update(expectStart, matcherNameEnd,
|
|
3459
|
+
.update(expectStart, matcherNameEnd, isChildOfExpressionStatement(expect.matcherNode, this.#compiler)
|
|
3457
3460
|
? `;const ${id} = undefined as any as ${sourceText};<${id}`
|
|
3458
3461
|
: `const ${id} = undefined as any as ${sourceText};<${id}`);
|
|
3459
3462
|
}
|
|
@@ -3488,15 +3491,15 @@ class AbilityLayer {
|
|
|
3488
3491
|
if (!sourceNode) {
|
|
3489
3492
|
return;
|
|
3490
3493
|
}
|
|
3491
|
-
if (
|
|
3494
|
+
if (belongsToArgumentList(sourceNode, this.#compiler)) {
|
|
3492
3495
|
this.#editor
|
|
3493
3496
|
.eraseTrailingComma(expect.source)
|
|
3494
|
-
.update(expectStart, expectExpressionEnd,
|
|
3497
|
+
.update(expectStart, expectExpressionEnd, isChildOfExpressionStatement(expect.matcherNode, this.#compiler) ? ";" : "")
|
|
3495
3498
|
.erase(expectEnd, matcherNameEnd);
|
|
3496
3499
|
}
|
|
3497
3500
|
else {
|
|
3498
3501
|
const sourceText = sourceNode.getFullText();
|
|
3499
|
-
this.#editor.update(expectStart, matcherNameEnd,
|
|
3502
|
+
this.#editor.update(expectStart, matcherNameEnd, isChildOfExpressionStatement(expect.matcherNode, this.#compiler)
|
|
3500
3503
|
? `;(undefined as any as ${sourceText})`
|
|
3501
3504
|
: `(undefined as any as ${sourceText})`);
|
|
3502
3505
|
}
|
|
@@ -3508,15 +3511,15 @@ class AbilityLayer {
|
|
|
3508
3511
|
if (!sourceNode) {
|
|
3509
3512
|
return;
|
|
3510
3513
|
}
|
|
3511
|
-
if (
|
|
3514
|
+
if (belongsToArgumentList(sourceNode, this.#compiler)) {
|
|
3512
3515
|
this.#editor
|
|
3513
3516
|
.eraseTrailingComma(expect.source)
|
|
3514
|
-
.update(expectStart, expectExpressionEnd,
|
|
3517
|
+
.update(expectStart, expectExpressionEnd, isChildOfExpressionStatement(expect.matcherNode, this.#compiler) ? "; new" : "new")
|
|
3515
3518
|
.erase(expectEnd, matcherNameEnd);
|
|
3516
3519
|
}
|
|
3517
3520
|
else {
|
|
3518
3521
|
const sourceText = sourceNode.getFullText();
|
|
3519
|
-
this.#editor.update(expectStart, matcherNameEnd,
|
|
3522
|
+
this.#editor.update(expectStart, matcherNameEnd, isChildOfExpressionStatement(expect.matcherNode, this.#compiler)
|
|
3520
3523
|
? `;new (undefined as any as ${sourceText})`
|
|
3521
3524
|
: `new (undefined as any as ${sourceText})`);
|
|
3522
3525
|
}
|
|
@@ -3526,13 +3529,13 @@ class AbilityLayer {
|
|
|
3526
3529
|
this.#nodes.push(expect);
|
|
3527
3530
|
const sourceNode = expect.source[0];
|
|
3528
3531
|
const targetNode = expect.target?.[0];
|
|
3529
|
-
if (!sourceNode) {
|
|
3532
|
+
if (!sourceNode || !targetNode || !isIdentifierLike(sourceNode, this.#compiler)) {
|
|
3530
3533
|
return;
|
|
3531
3534
|
}
|
|
3532
|
-
if (
|
|
3535
|
+
if (belongsToArgumentList(sourceNode, this.#compiler)) {
|
|
3533
3536
|
this.#editor
|
|
3534
3537
|
.eraseTrailingComma(expect.source)
|
|
3535
|
-
.update(expectStart, expectExpressionEnd,
|
|
3538
|
+
.update(expectStart, expectExpressionEnd, isChildOfExpressionStatement(expect.matcherNode, this.#compiler) ? ";" : "")
|
|
3536
3539
|
.erase(expectEnd, matcherNodeEnd);
|
|
3537
3540
|
if (this.#compiler.isExpressionWithTypeArguments(sourceNode)) {
|
|
3538
3541
|
this.#editor.erase(sourceNode.expression.getEnd(), sourceNode.getEnd());
|
|
@@ -3542,15 +3545,13 @@ class AbilityLayer {
|
|
|
3542
3545
|
const sourceText = this.#compiler.isTypeReferenceNode(sourceNode)
|
|
3543
3546
|
? sourceNode.typeName.getFullText()
|
|
3544
3547
|
: sourceNode.getFullText();
|
|
3545
|
-
this.#editor.update(expectStart, matcherNodeEnd,
|
|
3548
|
+
this.#editor.update(expectStart, matcherNodeEnd, isChildOfExpressionStatement(expect.matcherNode, this.#compiler)
|
|
3546
3549
|
? `;undefined as any as ${sourceText}`
|
|
3547
3550
|
: `undefined as any as ${sourceText}`);
|
|
3548
3551
|
}
|
|
3549
|
-
|
|
3550
|
-
|
|
3551
|
-
|
|
3552
|
-
this.#editor.update(targetNode.getFullStart(), targetNode.getEnd(), `<${targetText}>`.padStart(targetNode.getFullWidth()));
|
|
3553
|
-
}
|
|
3552
|
+
const targetText = targetNode.getText().slice(1, -1);
|
|
3553
|
+
if (targetText.trim().length > 0) {
|
|
3554
|
+
this.#editor.update(targetNode.getFullStart(), targetNode.getEnd(), `<${targetText}>`.padStart(targetNode.getFullWidth()));
|
|
3554
3555
|
}
|
|
3555
3556
|
break;
|
|
3556
3557
|
}
|
|
@@ -3561,15 +3562,15 @@ class AbilityLayer {
|
|
|
3561
3562
|
if (!sourceNode || !targetNode) {
|
|
3562
3563
|
return;
|
|
3563
3564
|
}
|
|
3564
|
-
if (
|
|
3565
|
+
if (belongsToArgumentList(sourceNode, this.#compiler)) {
|
|
3565
3566
|
this.#editor
|
|
3566
3567
|
.eraseTrailingComma(expect.source)
|
|
3567
|
-
.update(expectStart, expectExpressionEnd,
|
|
3568
|
+
.update(expectStart, expectExpressionEnd, isChildOfExpressionStatement(expect.matcherNode, this.#compiler) ? ";" : "")
|
|
3568
3569
|
.erase(expectEnd, matcherNodeEnd);
|
|
3569
3570
|
}
|
|
3570
3571
|
else {
|
|
3571
3572
|
const sourceText = sourceNode.getFullText();
|
|
3572
|
-
this.#editor.update(expectStart, matcherNodeEnd,
|
|
3573
|
+
this.#editor.update(expectStart, matcherNodeEnd, isChildOfExpressionStatement(expect.matcherNode, this.#compiler)
|
|
3573
3574
|
? `;(undefined as any as ${sourceText})`
|
|
3574
3575
|
: `(undefined as any as ${sourceText})`);
|
|
3575
3576
|
}
|
|
@@ -4402,7 +4403,7 @@ class Reject {
|
|
|
4402
4403
|
}
|
|
4403
4404
|
if (this.#typeChecker.getTypeAtLocation(node).flags & this.#compiler.TypeFlags[capitalize(rejectedType)]) {
|
|
4404
4405
|
const text = [
|
|
4405
|
-
|
|
4406
|
+
belongsToArgumentList(node, this.#compiler)
|
|
4406
4407
|
? RejectDiagnosticText.argumentCannotBeOfType(rejectedType)
|
|
4407
4408
|
: RejectDiagnosticText.typeArgumentCannotBeOfType(rejectedType),
|
|
4408
4409
|
...RejectDiagnosticText.typeWasRejected(rejectedType),
|
|
@@ -4423,7 +4424,7 @@ class Ensure {
|
|
|
4423
4424
|
this.#compiler = compiler;
|
|
4424
4425
|
}
|
|
4425
4426
|
argument(node, enclosingNode, onDiagnostics) {
|
|
4426
|
-
if (!node || !
|
|
4427
|
+
if (!node || !belongsToArgumentList(node, this.#compiler)) {
|
|
4427
4428
|
this.#emitDiagnostic("An argument must be provided.", enclosingNode, onDiagnostics);
|
|
4428
4429
|
return false;
|
|
4429
4430
|
}
|
|
@@ -4451,7 +4452,7 @@ class Ensure {
|
|
|
4451
4452
|
return true;
|
|
4452
4453
|
}
|
|
4453
4454
|
typeArgument(node, enclosingNode, onDiagnostics) {
|
|
4454
|
-
if (!node ||
|
|
4455
|
+
if (!node || belongsToArgumentList(node, this.#compiler)) {
|
|
4455
4456
|
this.#emitDiagnostic("A type argument must be provided.", enclosingNode, onDiagnostics);
|
|
4456
4457
|
return false;
|
|
4457
4458
|
}
|
|
@@ -4554,45 +4555,22 @@ class ExpectDiagnosticText {
|
|
|
4554
4555
|
}
|
|
4555
4556
|
}
|
|
4556
4557
|
|
|
4557
|
-
class
|
|
4558
|
-
|
|
4559
|
-
#compiler;
|
|
4558
|
+
class MatcherBase {
|
|
4559
|
+
compiler;
|
|
4560
4560
|
typeChecker;
|
|
4561
|
-
constructor(compiler, program
|
|
4562
|
-
this
|
|
4561
|
+
constructor(compiler, program) {
|
|
4562
|
+
this.compiler = compiler;
|
|
4563
4563
|
this.typeChecker = program.getTypeChecker();
|
|
4564
|
-
this.assertionNode = assertionNode;
|
|
4565
|
-
}
|
|
4566
|
-
checkIsAssignableFrom(sourceNode, targetNode) {
|
|
4567
|
-
return this.#checkIsRelatedTo(targetNode, sourceNode);
|
|
4568
|
-
}
|
|
4569
|
-
checkIsAssignableTo(sourceNode, targetNode) {
|
|
4570
|
-
return this.#checkIsRelatedTo(sourceNode, targetNode);
|
|
4571
|
-
}
|
|
4572
|
-
#checkIsRelatedTo(sourceNode, targetNode) {
|
|
4573
|
-
const sourceType = this.getType(sourceNode);
|
|
4574
|
-
const targetType = this.getType(targetNode);
|
|
4575
|
-
return this.typeChecker.isTypeAssignableTo(sourceType, targetType);
|
|
4576
|
-
}
|
|
4577
|
-
extendsObjectType(type) {
|
|
4578
|
-
const nonPrimitiveType = "getNonPrimitiveType" in this.typeChecker
|
|
4579
|
-
? this.typeChecker.getNonPrimitiveType()
|
|
4580
|
-
: { flags: this.#compiler.TypeFlags.NonPrimitive };
|
|
4581
|
-
return this.typeChecker.isTypeAssignableTo(type, nonPrimitiveType);
|
|
4582
|
-
}
|
|
4583
|
-
getTypeText(node) {
|
|
4584
|
-
return this.typeChecker.typeToString(this.getType(node));
|
|
4585
4564
|
}
|
|
4586
4565
|
getType(node) {
|
|
4587
4566
|
return this.typeChecker.getTypeAtLocation(node);
|
|
4588
4567
|
}
|
|
4568
|
+
getTypeText(node, typeChecker) {
|
|
4569
|
+
return typeChecker.typeToString(typeChecker.getTypeAtLocation(node));
|
|
4570
|
+
}
|
|
4589
4571
|
}
|
|
4590
4572
|
|
|
4591
|
-
class AbilityMatcherBase {
|
|
4592
|
-
compiler;
|
|
4593
|
-
constructor(compiler) {
|
|
4594
|
-
this.compiler = compiler;
|
|
4595
|
-
}
|
|
4573
|
+
class AbilityMatcherBase extends MatcherBase {
|
|
4596
4574
|
getArgumentCountText(nodes) {
|
|
4597
4575
|
if (nodes.length === 0) {
|
|
4598
4576
|
return "without arguments";
|
|
@@ -4608,19 +4586,19 @@ class AbilityMatcherBase {
|
|
|
4608
4586
|
}
|
|
4609
4587
|
return `with the given type argument${targetNode.elements.length === 1 ? "" : "s"}`;
|
|
4610
4588
|
}
|
|
4611
|
-
explain(
|
|
4612
|
-
const isExpression =
|
|
4589
|
+
explain(expectNode, sourceNode, targetNode, getArgumentCountText) {
|
|
4590
|
+
const isExpression = belongsToArgumentList(sourceNode, this.compiler);
|
|
4613
4591
|
const argumentCountText = getArgumentCountText?.();
|
|
4614
4592
|
const diagnostics = [];
|
|
4615
|
-
if (
|
|
4616
|
-
for (const diagnostic of
|
|
4593
|
+
if (expectNode.abilityDiagnostics.size > 0) {
|
|
4594
|
+
for (const diagnostic of expectNode.abilityDiagnostics) {
|
|
4617
4595
|
const text = [this.explainNotText(isExpression, argumentCountText), getDiagnosticMessageText(diagnostic)];
|
|
4618
4596
|
let origin;
|
|
4619
4597
|
if (isDiagnosticWithLocation(diagnostic) && diagnosticBelongsToNode(diagnostic, targetNode)) {
|
|
4620
|
-
origin = DiagnosticOrigin.fromAbilityDiagnostic(diagnostic,
|
|
4598
|
+
origin = DiagnosticOrigin.fromAbilityDiagnostic(diagnostic, expectNode);
|
|
4621
4599
|
}
|
|
4622
4600
|
else {
|
|
4623
|
-
origin = DiagnosticOrigin.fromAssertion(
|
|
4601
|
+
origin = DiagnosticOrigin.fromAssertion(expectNode);
|
|
4624
4602
|
}
|
|
4625
4603
|
let related;
|
|
4626
4604
|
if (diagnostic.relatedInformation != null) {
|
|
@@ -4630,7 +4608,7 @@ class AbilityMatcherBase {
|
|
|
4630
4608
|
}
|
|
4631
4609
|
}
|
|
4632
4610
|
else {
|
|
4633
|
-
const origin = DiagnosticOrigin.fromAssertion(
|
|
4611
|
+
const origin = DiagnosticOrigin.fromAssertion(expectNode);
|
|
4634
4612
|
diagnostics.push(Diagnostic.error(this.explainText(isExpression, argumentCountText), origin));
|
|
4635
4613
|
}
|
|
4636
4614
|
return diagnostics;
|
|
@@ -4640,24 +4618,15 @@ class AbilityMatcherBase {
|
|
|
4640
4618
|
class ToAcceptProps extends AbilityMatcherBase {
|
|
4641
4619
|
explainText = ExpectDiagnosticText.acceptsProps;
|
|
4642
4620
|
explainNotText = ExpectDiagnosticText.doesNotAcceptProps;
|
|
4643
|
-
match(
|
|
4621
|
+
match(expectNode, sourceNode, targetNode, onDiagnostics) {
|
|
4644
4622
|
const diagnostics = [];
|
|
4645
|
-
const sourceType =
|
|
4646
|
-
if (!(this.compiler
|
|
4647
|
-
this.compiler.isPropertyAccessExpression(sourceNode) ||
|
|
4648
|
-
this.compiler.isTypeReferenceNode(sourceNode) ||
|
|
4649
|
-
this.compiler.isExpressionWithTypeArguments(sourceNode)) ||
|
|
4623
|
+
const sourceType = this.getType(sourceNode);
|
|
4624
|
+
if (!isCapitaizedIdentifierLike(sourceNode, this.compiler) ||
|
|
4650
4625
|
!(sourceType.getCallSignatures().length > 0 || sourceType.getConstructSignatures().length > 0)) {
|
|
4651
|
-
const expectedText =
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
const origin = DiagnosticOrigin.fromNode(sourceNode);
|
|
4656
|
-
diagnostics.push(Diagnostic.error(text, origin));
|
|
4657
|
-
}
|
|
4658
|
-
else if (!/^[A-Z_$]/.test(sourceNode.getText()[0])) {
|
|
4659
|
-
const expectedText = "an identifier that begins with an uppercase letter";
|
|
4660
|
-
const text = nodeBelongsToArgumentList(this.compiler, sourceNode)
|
|
4626
|
+
const expectedText = !isIdentifierLike(sourceNode, this.compiler)
|
|
4627
|
+
? "an identifier of a JSX component"
|
|
4628
|
+
: "an identifier that begins with an uppercase letter";
|
|
4629
|
+
const text = belongsToArgumentList(sourceNode, this.compiler)
|
|
4661
4630
|
? ExpectDiagnosticText.argumentMustBe(expectedText)
|
|
4662
4631
|
: ExpectDiagnosticText.typeArgumentMustBe(expectedText);
|
|
4663
4632
|
const origin = DiagnosticOrigin.fromNode(sourceNode);
|
|
@@ -4690,8 +4659,8 @@ class ToAcceptProps extends AbilityMatcherBase {
|
|
|
4690
4659
|
return;
|
|
4691
4660
|
}
|
|
4692
4661
|
return {
|
|
4693
|
-
explain: () => this.explain(
|
|
4694
|
-
isMatch:
|
|
4662
|
+
explain: () => this.explain(expectNode, sourceNode, targetNode),
|
|
4663
|
+
isMatch: expectNode.abilityDiagnostics.size === 0,
|
|
4695
4664
|
};
|
|
4696
4665
|
}
|
|
4697
4666
|
}
|
|
@@ -4706,6 +4675,13 @@ function getIndexSignatures(type, compiler, typeChecker) {
|
|
|
4706
4675
|
}
|
|
4707
4676
|
return typeChecker.getIndexInfosOfType(type);
|
|
4708
4677
|
}
|
|
4678
|
+
function getReducedType(type, typeChecker) {
|
|
4679
|
+
typeChecker.typeToString(type);
|
|
4680
|
+
if ("resolvedReducedType" in type) {
|
|
4681
|
+
return type.resolvedReducedType;
|
|
4682
|
+
}
|
|
4683
|
+
return type;
|
|
4684
|
+
}
|
|
4709
4685
|
function getSignatures(type, kind, compiler, typeChecker) {
|
|
4710
4686
|
if (type.flags & compiler.TypeFlags.Intersection) {
|
|
4711
4687
|
return type.types.flatMap((type) => getSignatures(type, kind, compiler, typeChecker));
|
|
@@ -5184,7 +5160,7 @@ class Structure {
|
|
|
5184
5160
|
return result;
|
|
5185
5161
|
}
|
|
5186
5162
|
#memoize(a, b, compare) {
|
|
5187
|
-
const key = [a.id, b.id].sort().join(":");
|
|
5163
|
+
const key = [a.id, b.id].sort((a, b) => a - b).join(":");
|
|
5188
5164
|
const result = this.#memoizeCache.get(key);
|
|
5189
5165
|
if (result !== undefined) {
|
|
5190
5166
|
return result !== 2;
|
|
@@ -5195,6 +5171,7 @@ class Structure {
|
|
|
5195
5171
|
return isSame;
|
|
5196
5172
|
}
|
|
5197
5173
|
#normalize(type) {
|
|
5174
|
+
type = getReducedType(type, this.#typeChecker);
|
|
5198
5175
|
if (type.flags & this.#compiler.TypeFlags.Freshable && type.freshType === type) {
|
|
5199
5176
|
return type.regularType;
|
|
5200
5177
|
}
|
|
@@ -5208,14 +5185,14 @@ class Structure {
|
|
|
5208
5185
|
}
|
|
5209
5186
|
}
|
|
5210
5187
|
|
|
5211
|
-
class RelationMatcherBase {
|
|
5212
|
-
explain(
|
|
5213
|
-
const sourceTypeText =
|
|
5214
|
-
const targetTypeText =
|
|
5215
|
-
const text =
|
|
5188
|
+
class RelationMatcherBase extends MatcherBase {
|
|
5189
|
+
explain(expectNode, sourceNode, targetNode) {
|
|
5190
|
+
const sourceTypeText = this.getTypeText(sourceNode, this.typeChecker);
|
|
5191
|
+
const targetTypeText = this.getTypeText(targetNode, this.typeChecker);
|
|
5192
|
+
const text = expectNode.isNot
|
|
5216
5193
|
? this.explainText(sourceTypeText, targetTypeText)
|
|
5217
5194
|
: this.explainNotText(sourceTypeText, targetTypeText);
|
|
5218
|
-
const origin = DiagnosticOrigin.fromNode(targetNode,
|
|
5195
|
+
const origin = DiagnosticOrigin.fromNode(targetNode, expectNode);
|
|
5219
5196
|
return [Diagnostic.error(text, origin)];
|
|
5220
5197
|
}
|
|
5221
5198
|
}
|
|
@@ -5223,42 +5200,38 @@ class RelationMatcherBase {
|
|
|
5223
5200
|
class ToBe extends RelationMatcherBase {
|
|
5224
5201
|
#structure;
|
|
5225
5202
|
constructor(compiler, program) {
|
|
5226
|
-
super();
|
|
5203
|
+
super(compiler, program);
|
|
5227
5204
|
this.#structure = new Structure(compiler, program);
|
|
5228
5205
|
}
|
|
5229
5206
|
explainText = ExpectDiagnosticText.isTheSame;
|
|
5230
5207
|
explainNotText = ExpectDiagnosticText.isNotTheSame;
|
|
5231
|
-
match(
|
|
5208
|
+
match(expectNode, sourceNode, targetNode) {
|
|
5232
5209
|
return {
|
|
5233
|
-
explain: () => this.explain(
|
|
5234
|
-
isMatch: this.#structure.compare(
|
|
5210
|
+
explain: () => this.explain(expectNode, sourceNode, targetNode),
|
|
5211
|
+
isMatch: this.#structure.compare(this.getType(sourceNode), this.getType(targetNode)),
|
|
5235
5212
|
};
|
|
5236
5213
|
}
|
|
5237
5214
|
}
|
|
5238
5215
|
|
|
5239
|
-
class ToBeApplicable {
|
|
5240
|
-
#compiler;
|
|
5241
|
-
constructor(compiler) {
|
|
5242
|
-
this.#compiler = compiler;
|
|
5243
|
-
}
|
|
5216
|
+
class ToBeApplicable extends MatcherBase {
|
|
5244
5217
|
#resolveTargetText(node) {
|
|
5245
5218
|
let text = "";
|
|
5246
5219
|
switch (node.kind) {
|
|
5247
|
-
case this
|
|
5220
|
+
case this.compiler.SyntaxKind.ClassDeclaration:
|
|
5248
5221
|
text = "class";
|
|
5249
5222
|
break;
|
|
5250
|
-
case this
|
|
5223
|
+
case this.compiler.SyntaxKind.MethodDeclaration:
|
|
5251
5224
|
text = "method";
|
|
5252
5225
|
break;
|
|
5253
|
-
case this
|
|
5254
|
-
text = node.modifiers?.some((modifier) => modifier.kind === this
|
|
5226
|
+
case this.compiler.SyntaxKind.PropertyDeclaration:
|
|
5227
|
+
text = node.modifiers?.some((modifier) => modifier.kind === this.compiler.SyntaxKind.AccessorKeyword)
|
|
5255
5228
|
? "accessor"
|
|
5256
5229
|
: "field";
|
|
5257
5230
|
break;
|
|
5258
|
-
case this
|
|
5231
|
+
case this.compiler.SyntaxKind.GetAccessor:
|
|
5259
5232
|
text = "getter";
|
|
5260
5233
|
break;
|
|
5261
|
-
case this
|
|
5234
|
+
case this.compiler.SyntaxKind.SetAccessor:
|
|
5262
5235
|
text = "setter";
|
|
5263
5236
|
break;
|
|
5264
5237
|
}
|
|
@@ -5267,12 +5240,12 @@ class ToBeApplicable {
|
|
|
5267
5240
|
}
|
|
5268
5241
|
return text;
|
|
5269
5242
|
}
|
|
5270
|
-
#explain(
|
|
5271
|
-
const targetText = this.#resolveTargetText(
|
|
5243
|
+
#explain(expectNode) {
|
|
5244
|
+
const targetText = this.#resolveTargetText(expectNode.matcherNode.parent);
|
|
5272
5245
|
const diagnostics = [];
|
|
5273
|
-
if (
|
|
5274
|
-
const origin = DiagnosticOrigin.fromAssertion(
|
|
5275
|
-
for (const diagnostic of
|
|
5246
|
+
if (expectNode.abilityDiagnostics.size > 0) {
|
|
5247
|
+
const origin = DiagnosticOrigin.fromAssertion(expectNode);
|
|
5248
|
+
for (const diagnostic of expectNode.abilityDiagnostics) {
|
|
5276
5249
|
const text = [ExpectDiagnosticText.cannotBeApplied(targetText), getDiagnosticMessageText(diagnostic)];
|
|
5277
5250
|
let related;
|
|
5278
5251
|
if (diagnostic.relatedInformation != null) {
|
|
@@ -5282,16 +5255,16 @@ class ToBeApplicable {
|
|
|
5282
5255
|
}
|
|
5283
5256
|
}
|
|
5284
5257
|
else {
|
|
5285
|
-
const origin = DiagnosticOrigin.fromAssertion(
|
|
5258
|
+
const origin = DiagnosticOrigin.fromAssertion(expectNode);
|
|
5286
5259
|
diagnostics.push(Diagnostic.error(ExpectDiagnosticText.canBeApplied(targetText), origin));
|
|
5287
5260
|
}
|
|
5288
5261
|
return diagnostics;
|
|
5289
5262
|
}
|
|
5290
|
-
match(
|
|
5291
|
-
const type =
|
|
5263
|
+
match(expectNode, sourceNode, onDiagnostics) {
|
|
5264
|
+
const type = this.getType(sourceNode);
|
|
5292
5265
|
if (type.getCallSignatures().length === 0) {
|
|
5293
5266
|
const expectedText = "of a function type";
|
|
5294
|
-
const text =
|
|
5267
|
+
const text = belongsToArgumentList(sourceNode, this.compiler)
|
|
5295
5268
|
? ExpectDiagnosticText.argumentMustBe(expectedText)
|
|
5296
5269
|
: ExpectDiagnosticText.typeArgumentMustBe(expectedText);
|
|
5297
5270
|
const origin = DiagnosticOrigin.fromNode(sourceNode);
|
|
@@ -5299,8 +5272,8 @@ class ToBeApplicable {
|
|
|
5299
5272
|
return;
|
|
5300
5273
|
}
|
|
5301
5274
|
return {
|
|
5302
|
-
explain: () => this.#explain(
|
|
5303
|
-
isMatch:
|
|
5275
|
+
explain: () => this.#explain(expectNode),
|
|
5276
|
+
isMatch: expectNode.abilityDiagnostics.size === 0,
|
|
5304
5277
|
};
|
|
5305
5278
|
}
|
|
5306
5279
|
}
|
|
@@ -5308,10 +5281,10 @@ class ToBeApplicable {
|
|
|
5308
5281
|
class ToBeAssignableFrom extends RelationMatcherBase {
|
|
5309
5282
|
explainText = ExpectDiagnosticText.isAssignableFrom;
|
|
5310
5283
|
explainNotText = ExpectDiagnosticText.isNotAssignableFrom;
|
|
5311
|
-
match(
|
|
5284
|
+
match(expectNode, sourceNode, targetNode) {
|
|
5312
5285
|
return {
|
|
5313
|
-
explain: () => this.explain(
|
|
5314
|
-
isMatch:
|
|
5286
|
+
explain: () => this.explain(expectNode, sourceNode, targetNode),
|
|
5287
|
+
isMatch: this.typeChecker.isTypeAssignableTo(this.getType(targetNode), this.getType(sourceNode)),
|
|
5315
5288
|
};
|
|
5316
5289
|
}
|
|
5317
5290
|
}
|
|
@@ -5319,10 +5292,10 @@ class ToBeAssignableFrom extends RelationMatcherBase {
|
|
|
5319
5292
|
class ToBeAssignableTo extends RelationMatcherBase {
|
|
5320
5293
|
explainText = ExpectDiagnosticText.isAssignableTo;
|
|
5321
5294
|
explainNotText = ExpectDiagnosticText.isNotAssignableTo;
|
|
5322
|
-
match(
|
|
5295
|
+
match(expectNode, sourceNode, targetNode) {
|
|
5323
5296
|
return {
|
|
5324
|
-
explain: () => this.explain(
|
|
5325
|
-
isMatch:
|
|
5297
|
+
explain: () => this.explain(expectNode, sourceNode, targetNode),
|
|
5298
|
+
isMatch: this.typeChecker.isTypeAssignableTo(this.getType(sourceNode), this.getType(targetNode)),
|
|
5326
5299
|
};
|
|
5327
5300
|
}
|
|
5328
5301
|
}
|
|
@@ -5330,11 +5303,11 @@ class ToBeAssignableTo extends RelationMatcherBase {
|
|
|
5330
5303
|
class ToBeCallableWith extends AbilityMatcherBase {
|
|
5331
5304
|
explainText = ExpectDiagnosticText.isCallable;
|
|
5332
5305
|
explainNotText = ExpectDiagnosticText.isNotCallable;
|
|
5333
|
-
match(
|
|
5334
|
-
const sourceType =
|
|
5306
|
+
match(expectNode, sourceNode, targetNodes, onDiagnostics) {
|
|
5307
|
+
const sourceType = this.getType(sourceNode);
|
|
5335
5308
|
if (sourceType.getCallSignatures().length === 0) {
|
|
5336
5309
|
const text = [];
|
|
5337
|
-
if (
|
|
5310
|
+
if (belongsToArgumentList(sourceNode, this.compiler)) {
|
|
5338
5311
|
text.push(ExpectDiagnosticText.argumentMustBe("a callable expression"));
|
|
5339
5312
|
}
|
|
5340
5313
|
else {
|
|
@@ -5348,8 +5321,8 @@ class ToBeCallableWith extends AbilityMatcherBase {
|
|
|
5348
5321
|
return;
|
|
5349
5322
|
}
|
|
5350
5323
|
return {
|
|
5351
|
-
explain: () => this.explain(
|
|
5352
|
-
isMatch:
|
|
5324
|
+
explain: () => this.explain(expectNode, sourceNode, targetNodes, () => this.getArgumentCountText(targetNodes)),
|
|
5325
|
+
isMatch: expectNode.abilityDiagnostics.size === 0,
|
|
5353
5326
|
};
|
|
5354
5327
|
}
|
|
5355
5328
|
}
|
|
@@ -5357,11 +5330,11 @@ class ToBeCallableWith extends AbilityMatcherBase {
|
|
|
5357
5330
|
class ToBeConstructableWith extends AbilityMatcherBase {
|
|
5358
5331
|
explainText = ExpectDiagnosticText.isConstructable;
|
|
5359
5332
|
explainNotText = ExpectDiagnosticText.isNotConstructable;
|
|
5360
|
-
match(
|
|
5361
|
-
const sourceType =
|
|
5333
|
+
match(expectNode, sourceNode, targetNodes, onDiagnostics) {
|
|
5334
|
+
const sourceType = this.getType(sourceNode);
|
|
5362
5335
|
if (sourceType.getConstructSignatures().length === 0) {
|
|
5363
5336
|
const text = [];
|
|
5364
|
-
if (
|
|
5337
|
+
if (belongsToArgumentList(sourceNode, this.compiler)) {
|
|
5365
5338
|
text.push(ExpectDiagnosticText.argumentMustBe("a constructable expression"));
|
|
5366
5339
|
}
|
|
5367
5340
|
else {
|
|
@@ -5375,8 +5348,8 @@ class ToBeConstructableWith extends AbilityMatcherBase {
|
|
|
5375
5348
|
return;
|
|
5376
5349
|
}
|
|
5377
5350
|
return {
|
|
5378
|
-
explain: () => this.explain(
|
|
5379
|
-
isMatch:
|
|
5351
|
+
explain: () => this.explain(expectNode, sourceNode, targetNodes, () => this.getArgumentCountText(targetNodes)),
|
|
5352
|
+
isMatch: expectNode.abilityDiagnostics.size === 0,
|
|
5380
5353
|
};
|
|
5381
5354
|
}
|
|
5382
5355
|
}
|
|
@@ -5384,13 +5357,10 @@ class ToBeConstructableWith extends AbilityMatcherBase {
|
|
|
5384
5357
|
class ToBeInstantiableWith extends AbilityMatcherBase {
|
|
5385
5358
|
explainText = ExpectDiagnosticText.isInstantiable;
|
|
5386
5359
|
explainNotText = ExpectDiagnosticText.isNotInstantiable;
|
|
5387
|
-
match(
|
|
5388
|
-
if (!(this.compiler
|
|
5389
|
-
this.compiler.isPropertyAccessExpression(sourceNode) ||
|
|
5390
|
-
this.compiler.isTypeReferenceNode(sourceNode) ||
|
|
5391
|
-
this.compiler.isExpressionWithTypeArguments(sourceNode))) {
|
|
5360
|
+
match(expectNode, sourceNode, targetNode, onDiagnostics) {
|
|
5361
|
+
if (!isIdentifierLike(sourceNode, this.compiler)) {
|
|
5392
5362
|
let text;
|
|
5393
|
-
if (
|
|
5363
|
+
if (belongsToArgumentList(sourceNode, this.compiler)) {
|
|
5394
5364
|
text = ExpectDiagnosticText.argumentMustBe("an instantiable expression");
|
|
5395
5365
|
}
|
|
5396
5366
|
else {
|
|
@@ -5407,49 +5377,51 @@ class ToBeInstantiableWith extends AbilityMatcherBase {
|
|
|
5407
5377
|
return;
|
|
5408
5378
|
}
|
|
5409
5379
|
return {
|
|
5410
|
-
explain: () => this.explain(
|
|
5411
|
-
isMatch:
|
|
5380
|
+
explain: () => this.explain(expectNode, sourceNode, targetNode, () => this.getTypeArgumentCountText(targetNode)),
|
|
5381
|
+
isMatch: expectNode.abilityDiagnostics.size === 0,
|
|
5412
5382
|
};
|
|
5413
5383
|
}
|
|
5414
5384
|
}
|
|
5415
5385
|
|
|
5416
|
-
class ToHaveProperty {
|
|
5417
|
-
#
|
|
5418
|
-
|
|
5419
|
-
|
|
5420
|
-
}
|
|
5421
|
-
#explain(matchWorker, sourceNode, targetNode) {
|
|
5422
|
-
const sourceTypeText = matchWorker.getTypeText(sourceNode);
|
|
5423
|
-
const targetType = matchWorker.getType(targetNode);
|
|
5386
|
+
class ToHaveProperty extends MatcherBase {
|
|
5387
|
+
#explain(expectNode, sourceNode, targetNode) {
|
|
5388
|
+
const sourceTypeText = this.getTypeText(sourceNode, this.typeChecker);
|
|
5389
|
+
const targetType = this.getType(targetNode);
|
|
5424
5390
|
let propertyNameText;
|
|
5425
|
-
if (targetType.flags & (this
|
|
5391
|
+
if (targetType.flags & (this.compiler.TypeFlags.StringLiteral | this.compiler.TypeFlags.NumberLiteral)) {
|
|
5426
5392
|
propertyNameText = targetType.value.toString();
|
|
5427
5393
|
}
|
|
5428
5394
|
else {
|
|
5429
|
-
propertyNameText = `[${this
|
|
5395
|
+
propertyNameText = `[${this.compiler.unescapeLeadingUnderscores(targetType.symbol.escapedName)}]`;
|
|
5430
5396
|
}
|
|
5431
|
-
const origin = DiagnosticOrigin.fromNode(targetNode,
|
|
5432
|
-
return
|
|
5397
|
+
const origin = DiagnosticOrigin.fromNode(targetNode, expectNode);
|
|
5398
|
+
return expectNode.isNot
|
|
5433
5399
|
? [Diagnostic.error(ExpectDiagnosticText.hasProperty(sourceTypeText, propertyNameText), origin)]
|
|
5434
5400
|
: [Diagnostic.error(ExpectDiagnosticText.doesNotHaveProperty(sourceTypeText, propertyNameText), origin)];
|
|
5435
5401
|
}
|
|
5436
|
-
|
|
5402
|
+
#extendsObjectType(type) {
|
|
5403
|
+
const nonPrimitiveType = "getNonPrimitiveType" in this.typeChecker
|
|
5404
|
+
? this.typeChecker.getNonPrimitiveType()
|
|
5405
|
+
: { flags: this.compiler.TypeFlags.NonPrimitive };
|
|
5406
|
+
return this.typeChecker.isTypeAssignableTo(type, nonPrimitiveType);
|
|
5407
|
+
}
|
|
5408
|
+
match(expectNode, sourceNode, targetNode, onDiagnostics) {
|
|
5437
5409
|
const diagnostics = [];
|
|
5438
|
-
const sourceType =
|
|
5439
|
-
if (sourceType.flags & (this
|
|
5440
|
-
!
|
|
5410
|
+
const sourceType = this.getType(sourceNode);
|
|
5411
|
+
if (sourceType.flags & (this.compiler.TypeFlags.Any | this.compiler.TypeFlags.Never) ||
|
|
5412
|
+
!this.#extendsObjectType(sourceType)) {
|
|
5441
5413
|
const expectedText = "of an object type";
|
|
5442
|
-
const text =
|
|
5414
|
+
const text = belongsToArgumentList(sourceNode, this.compiler)
|
|
5443
5415
|
? ExpectDiagnosticText.argumentMustBe(expectedText)
|
|
5444
5416
|
: ExpectDiagnosticText.typeArgumentMustBe(expectedText);
|
|
5445
5417
|
const origin = DiagnosticOrigin.fromNode(sourceNode);
|
|
5446
5418
|
diagnostics.push(Diagnostic.error(text, origin));
|
|
5447
5419
|
}
|
|
5448
|
-
const targetType =
|
|
5420
|
+
const targetType = this.getType(targetNode);
|
|
5449
5421
|
if (!(targetType.flags &
|
|
5450
|
-
(this
|
|
5451
|
-
this
|
|
5452
|
-
this
|
|
5422
|
+
(this.compiler.TypeFlags.StringLiteral |
|
|
5423
|
+
this.compiler.TypeFlags.NumberLiteral |
|
|
5424
|
+
this.compiler.TypeFlags.UniqueESSymbol))) {
|
|
5453
5425
|
const expectedText = "a string, number or symbol";
|
|
5454
5426
|
const text = ExpectDiagnosticText.argumentMustBe(expectedText);
|
|
5455
5427
|
const origin = DiagnosticOrigin.fromNode(targetNode);
|
|
@@ -5460,8 +5432,8 @@ class ToHaveProperty {
|
|
|
5460
5432
|
return;
|
|
5461
5433
|
}
|
|
5462
5434
|
return {
|
|
5463
|
-
explain: () => this.#explain(
|
|
5464
|
-
isMatch:
|
|
5435
|
+
explain: () => this.#explain(expectNode, sourceNode, targetNode),
|
|
5436
|
+
isMatch: expectNode.abilityDiagnostics.size === 0,
|
|
5465
5437
|
};
|
|
5466
5438
|
}
|
|
5467
5439
|
}
|
|
@@ -5471,30 +5443,30 @@ class ToRaiseError {
|
|
|
5471
5443
|
constructor(compiler) {
|
|
5472
5444
|
this.#compiler = compiler;
|
|
5473
5445
|
}
|
|
5474
|
-
#explain(
|
|
5475
|
-
const isExpression =
|
|
5476
|
-
const origin = DiagnosticOrigin.fromAssertion(
|
|
5477
|
-
if (
|
|
5446
|
+
#explain(expectNode, sourceNode, targetNodes) {
|
|
5447
|
+
const isExpression = belongsToArgumentList(sourceNode, this.#compiler);
|
|
5448
|
+
const origin = DiagnosticOrigin.fromAssertion(expectNode);
|
|
5449
|
+
if (expectNode.diagnostics.size === 0) {
|
|
5478
5450
|
const text = ExpectDiagnosticText.didNotRaiseError(isExpression);
|
|
5479
5451
|
return [Diagnostic.error(text, origin)];
|
|
5480
5452
|
}
|
|
5481
|
-
if (
|
|
5482
|
-
const count =
|
|
5453
|
+
if (expectNode.diagnostics.size !== targetNodes.length) {
|
|
5454
|
+
const count = expectNode.diagnostics.size;
|
|
5483
5455
|
const text = ExpectDiagnosticText.raisedError(isExpression, count, targetNodes.length);
|
|
5484
5456
|
const related = [
|
|
5485
5457
|
Diagnostic.error(ExpectDiagnosticText.raisedTypeError(count)),
|
|
5486
|
-
...Diagnostic.fromDiagnostics([...
|
|
5458
|
+
...Diagnostic.fromDiagnostics([...expectNode.diagnostics]),
|
|
5487
5459
|
];
|
|
5488
5460
|
return [Diagnostic.error(text, origin).add({ related })];
|
|
5489
5461
|
}
|
|
5490
|
-
return [...
|
|
5462
|
+
return [...expectNode.diagnostics].reduce((accumulator, diagnostic, index) => {
|
|
5491
5463
|
const targetNode = targetNodes[index];
|
|
5492
5464
|
const isMatch = this.#matchExpectedError(diagnostic, targetNode);
|
|
5493
|
-
if (
|
|
5494
|
-
const text =
|
|
5465
|
+
if (expectNode.isNot ? isMatch : !isMatch) {
|
|
5466
|
+
const text = expectNode.isNot
|
|
5495
5467
|
? ExpectDiagnosticText.raisedMatchingError(isExpression)
|
|
5496
5468
|
: ExpectDiagnosticText.didNotRaiseMatchingError(isExpression);
|
|
5497
|
-
const origin = DiagnosticOrigin.fromNode(targetNode,
|
|
5469
|
+
const origin = DiagnosticOrigin.fromNode(targetNode, expectNode);
|
|
5498
5470
|
const related = [
|
|
5499
5471
|
Diagnostic.error(ExpectDiagnosticText.raisedTypeError()),
|
|
5500
5472
|
...Diagnostic.fromDiagnostics([diagnostic]),
|
|
@@ -5504,7 +5476,7 @@ class ToRaiseError {
|
|
|
5504
5476
|
return accumulator;
|
|
5505
5477
|
}, []);
|
|
5506
5478
|
}
|
|
5507
|
-
match(
|
|
5479
|
+
match(expectNode, sourceNode, targetNodes, onDiagnostics) {
|
|
5508
5480
|
const diagnostics = [];
|
|
5509
5481
|
for (const targetNode of targetNodes) {
|
|
5510
5482
|
if (!(this.#compiler.isStringLiteralLike(targetNode) ||
|
|
@@ -5522,15 +5494,15 @@ class ToRaiseError {
|
|
|
5522
5494
|
}
|
|
5523
5495
|
let isMatch;
|
|
5524
5496
|
if (targetNodes.length === 0) {
|
|
5525
|
-
isMatch =
|
|
5497
|
+
isMatch = expectNode.diagnostics.size > 0;
|
|
5526
5498
|
}
|
|
5527
5499
|
else {
|
|
5528
5500
|
isMatch =
|
|
5529
|
-
|
|
5530
|
-
[...
|
|
5501
|
+
expectNode.diagnostics.size === targetNodes.length &&
|
|
5502
|
+
[...expectNode.diagnostics].every((diagnostic, index) => this.#matchExpectedError(diagnostic, targetNodes[index]));
|
|
5531
5503
|
}
|
|
5532
5504
|
return {
|
|
5533
|
-
explain: () => this.#explain(
|
|
5505
|
+
explain: () => this.#explain(expectNode, sourceNode, targetNodes),
|
|
5534
5506
|
isMatch,
|
|
5535
5507
|
};
|
|
5536
5508
|
}
|
|
@@ -5551,7 +5523,6 @@ class ToRaiseError {
|
|
|
5551
5523
|
}
|
|
5552
5524
|
|
|
5553
5525
|
class ExpectService {
|
|
5554
|
-
#compiler;
|
|
5555
5526
|
#ensure;
|
|
5556
5527
|
#program;
|
|
5557
5528
|
#reject;
|
|
@@ -5566,69 +5537,67 @@ class ExpectService {
|
|
|
5566
5537
|
toHaveProperty;
|
|
5567
5538
|
toRaiseError;
|
|
5568
5539
|
constructor(compiler, program, resolvedConfig) {
|
|
5569
|
-
this.#compiler = compiler;
|
|
5570
5540
|
this.#program = program;
|
|
5571
5541
|
this.#ensure = new Ensure(compiler);
|
|
5572
5542
|
this.#reject = new Reject(compiler, program, resolvedConfig);
|
|
5573
|
-
this.toAcceptProps = new ToAcceptProps(compiler);
|
|
5543
|
+
this.toAcceptProps = new ToAcceptProps(compiler, program);
|
|
5574
5544
|
this.toBe = new ToBe(compiler, program);
|
|
5575
|
-
this.toBeApplicable = new ToBeApplicable(compiler);
|
|
5576
|
-
this.toBeAssignableFrom = new ToBeAssignableFrom();
|
|
5577
|
-
this.toBeAssignableTo = new ToBeAssignableTo();
|
|
5578
|
-
this.toBeCallableWith = new ToBeCallableWith(compiler);
|
|
5579
|
-
this.toBeConstructableWith = new ToBeConstructableWith(compiler);
|
|
5580
|
-
this.toBeInstantiableWith = new ToBeInstantiableWith(compiler);
|
|
5581
|
-
this.toHaveProperty = new ToHaveProperty(compiler);
|
|
5545
|
+
this.toBeApplicable = new ToBeApplicable(compiler, program);
|
|
5546
|
+
this.toBeAssignableFrom = new ToBeAssignableFrom(compiler, program);
|
|
5547
|
+
this.toBeAssignableTo = new ToBeAssignableTo(compiler, program);
|
|
5548
|
+
this.toBeCallableWith = new ToBeCallableWith(compiler, program);
|
|
5549
|
+
this.toBeConstructableWith = new ToBeConstructableWith(compiler, program);
|
|
5550
|
+
this.toBeInstantiableWith = new ToBeInstantiableWith(compiler, program);
|
|
5551
|
+
this.toHaveProperty = new ToHaveProperty(compiler, program);
|
|
5582
5552
|
this.toRaiseError = new ToRaiseError(compiler);
|
|
5583
5553
|
}
|
|
5584
|
-
match(
|
|
5585
|
-
const matcherNameText =
|
|
5554
|
+
match(expectNode, onDiagnostics) {
|
|
5555
|
+
const matcherNameText = expectNode.matcherNameNode.name.text;
|
|
5586
5556
|
if (matcherNameText === "toAcceptProps" &&
|
|
5587
|
-
!this.#ensure.jsxSetup(this.#program,
|
|
5557
|
+
!this.#ensure.jsxSetup(this.#program, expectNode.matcherNameNode.name, onDiagnostics)) {
|
|
5588
5558
|
return;
|
|
5589
5559
|
}
|
|
5590
|
-
if (!this.#ensure.argumentOrTypeArgument(
|
|
5560
|
+
if (!this.#ensure.argumentOrTypeArgument(expectNode.source[0], expectNode.node.expression, onDiagnostics)) {
|
|
5591
5561
|
return;
|
|
5592
5562
|
}
|
|
5593
|
-
if (!(matcherNameText === "toBeInstantiableWith" || (matcherNameText === "toRaiseError" && !
|
|
5594
|
-
this.#reject.argumentType([
|
|
5563
|
+
if (!(matcherNameText === "toBeInstantiableWith" || (matcherNameText === "toRaiseError" && !expectNode.isNot)) &&
|
|
5564
|
+
this.#reject.argumentType([expectNode.source[0], expectNode.target?.[0]], onDiagnostics)) {
|
|
5595
5565
|
return;
|
|
5596
5566
|
}
|
|
5597
|
-
const matchWorker = new MatchWorker(this.#compiler, this.#program, assertionNode);
|
|
5598
5567
|
switch (matcherNameText) {
|
|
5599
5568
|
case "toAcceptProps":
|
|
5600
5569
|
case "toBe":
|
|
5601
5570
|
case "toBeAssignableFrom":
|
|
5602
5571
|
case "toBeAssignableTo":
|
|
5603
|
-
if (!this.#ensure.argumentOrTypeArgument(
|
|
5572
|
+
if (!this.#ensure.argumentOrTypeArgument(expectNode.target?.[0], expectNode.matcherNameNode.name, onDiagnostics)) {
|
|
5604
5573
|
return;
|
|
5605
5574
|
}
|
|
5606
|
-
return this[matcherNameText].match(
|
|
5575
|
+
return this[matcherNameText].match(expectNode, expectNode.source[0], expectNode.target[0], onDiagnostics);
|
|
5607
5576
|
case "toBeApplicable":
|
|
5608
|
-
return this.toBeApplicable.match(
|
|
5577
|
+
return this.toBeApplicable.match(expectNode, expectNode.source[0], onDiagnostics);
|
|
5609
5578
|
case "toBeCallableWith":
|
|
5610
5579
|
case "toBeConstructableWith":
|
|
5611
5580
|
case "toRaiseError":
|
|
5612
|
-
return this[matcherNameText].match(
|
|
5581
|
+
return this[matcherNameText].match(expectNode, expectNode.source[0], expectNode.target, onDiagnostics);
|
|
5613
5582
|
case "toBeInstantiableWith": {
|
|
5614
|
-
if (!this.#ensure.typeArgument(
|
|
5583
|
+
if (!this.#ensure.typeArgument(expectNode.target?.[0], expectNode.matcherNameNode.name, onDiagnostics)) {
|
|
5615
5584
|
return;
|
|
5616
5585
|
}
|
|
5617
|
-
return this.toBeInstantiableWith.match(
|
|
5586
|
+
return this.toBeInstantiableWith.match(expectNode, expectNode.source[0], expectNode.target[0], onDiagnostics);
|
|
5618
5587
|
}
|
|
5619
5588
|
case "toHaveProperty":
|
|
5620
|
-
if (!this.#ensure.argument(
|
|
5589
|
+
if (!this.#ensure.argument(expectNode.target?.[0], expectNode.matcherNameNode.name, onDiagnostics)) {
|
|
5621
5590
|
return;
|
|
5622
5591
|
}
|
|
5623
|
-
return this.toHaveProperty.match(
|
|
5592
|
+
return this.toHaveProperty.match(expectNode, expectNode.source[0], expectNode.target[0], onDiagnostics);
|
|
5624
5593
|
default:
|
|
5625
|
-
this.#onMatcherIsNotSupported(matcherNameText,
|
|
5594
|
+
this.#onMatcherIsNotSupported(matcherNameText, expectNode, onDiagnostics);
|
|
5626
5595
|
}
|
|
5627
5596
|
return;
|
|
5628
5597
|
}
|
|
5629
|
-
#onMatcherIsNotSupported(matcherNameText,
|
|
5598
|
+
#onMatcherIsNotSupported(matcherNameText, expectNode, onDiagnostics) {
|
|
5630
5599
|
const text = ExpectDiagnosticText.matcherIsNotSupported(matcherNameText);
|
|
5631
|
-
const origin = DiagnosticOrigin.fromNode(
|
|
5600
|
+
const origin = DiagnosticOrigin.fromNode(expectNode.matcherNameNode.name);
|
|
5632
5601
|
onDiagnostics(Diagnostic.error(text, origin));
|
|
5633
5602
|
}
|
|
5634
5603
|
}
|
|
@@ -5940,7 +5909,7 @@ class FileRunner {
|
|
|
5940
5909
|
class Runner {
|
|
5941
5910
|
#eventEmitter = new EventEmitter();
|
|
5942
5911
|
#resolvedConfig;
|
|
5943
|
-
static version = "7.2.
|
|
5912
|
+
static version = "7.2.3";
|
|
5944
5913
|
constructor(resolvedConfig) {
|
|
5945
5914
|
this.#resolvedConfig = resolvedConfig;
|
|
5946
5915
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tstyche",
|
|
3
|
-
"version": "7.2.
|
|
3
|
+
"version": "7.2.3",
|
|
4
4
|
"description": "Everything You Need for Type Testing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -36,15 +36,15 @@
|
|
|
36
36
|
"dist/**/*",
|
|
37
37
|
"schemas/*.json"
|
|
38
38
|
],
|
|
39
|
-
"
|
|
40
|
-
"
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=22"
|
|
41
41
|
},
|
|
42
42
|
"peerDependenciesMeta": {
|
|
43
43
|
"typescript": {
|
|
44
44
|
"optional": true
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
|
-
"
|
|
48
|
-
"
|
|
47
|
+
"peerDependencies": {
|
|
48
|
+
"typescript": ">=5.4"
|
|
49
49
|
}
|
|
50
50
|
}
|