tstyche 7.2.1 → 7.2.2

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.
Files changed (3) hide show
  1. package/dist/api.d.ts +5 -5
  2. package/dist/api.js +203 -242
  3. 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
- assertionNode: ExpectNode | undefined;
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, assertionNode?: ExpectNode);
87
- static fromAbilityDiagnostic(diagnostic: ts.DiagnosticWithLocation, assertionNode: ExpectNode): DiagnosticOrigin;
88
- static fromAssertion(assertionNode: ExpectNode): DiagnosticOrigin;
89
- static fromNode(node: ts.Node, assertionNode?: ExpectNode): DiagnosticOrigin;
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
- assertionNode;
115
+ expectNode;
116
116
  end;
117
117
  sourceFile;
118
118
  start;
119
- constructor(start, end, sourceFile, assertionNode) {
119
+ constructor(start, end, sourceFile, expectNode) {
120
120
  this.start = start;
121
121
  this.end = end;
122
122
  this.sourceFile = sourceFile;
123
- this.assertionNode = assertionNode;
123
+ this.expectNode = expectNode;
124
124
  }
125
- static fromAbilityDiagnostic(diagnostic, assertionNode) {
126
- return new DiagnosticOrigin(diagnostic.start, getTextSpanEnd(diagnostic), diagnostic.file, assertionNode);
125
+ static fromAbilityDiagnostic(diagnostic, expectNode) {
126
+ return new DiagnosticOrigin(diagnostic.start, getTextSpanEnd(diagnostic), diagnostic.file, expectNode);
127
127
  }
128
- static fromAssertion(assertionNode) {
129
- const node = assertionNode.matcherNameNode.name;
130
- return new DiagnosticOrigin(node.getStart(), node.getEnd(), node.getSourceFile(), assertionNode);
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, assertionNode) {
133
- return new DiagnosticOrigin(node.getStart(), node.getEnd(), node.getSourceFile(), assertionNode);
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(specifier);
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/${"7.2.1"} ${process.platform} ${process.arch}`);
615
+ request.headers.set("User-Agent", `tstyche/7.2.2 ${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.assertionNode != null) {
2361
- breadcrumbs = jsx(BreadcrumbsText, { ancestor: diagnosticOrigin.assertionNode.parent });
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 nodeBelongsToArgumentList(compiler, node) {
3386
- return compiler.isCallExpression(node.parent) && node.parent.arguments.some((argument) => argument === node);
3388
+ function isCapitaizedIdentifierLike(node, compiler) {
3389
+ return isIdentifierLike(node, compiler) && /^[A-Z_$]/.test(node.getText()[0]);
3387
3390
  }
3388
- function nodeIsChildOfExpressionStatement(compiler, node) {
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.#mapToNodes(diagnostic);
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.isIdentifier(sourceNode) ||
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 (nodeBelongsToArgumentList(this.#compiler, sourceNode)) {
3448
+ if (belongsToArgumentList(sourceNode, this.#compiler)) {
3446
3449
  this.#editor
3447
3450
  .eraseTrailingComma(expect.source)
3448
3451
  .erase(expectStart, matcherNodeEnd)
3449
- .update(expectStart, matcherNameEnd, nodeIsChildOfExpressionStatement(this.#compiler, expect.matcherNode) ? ";" : "")
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, nodeIsChildOfExpressionStatement(this.#compiler, expect.matcherNode)
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 (nodeBelongsToArgumentList(this.#compiler, sourceNode)) {
3494
+ if (belongsToArgumentList(sourceNode, this.#compiler)) {
3492
3495
  this.#editor
3493
3496
  .eraseTrailingComma(expect.source)
3494
- .update(expectStart, expectExpressionEnd, nodeIsChildOfExpressionStatement(this.#compiler, expect.matcherNode) ? ";" : "")
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, nodeIsChildOfExpressionStatement(this.#compiler, expect.matcherNode)
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 (nodeBelongsToArgumentList(this.#compiler, sourceNode)) {
3514
+ if (belongsToArgumentList(sourceNode, this.#compiler)) {
3512
3515
  this.#editor
3513
3516
  .eraseTrailingComma(expect.source)
3514
- .update(expectStart, expectExpressionEnd, nodeIsChildOfExpressionStatement(this.#compiler, expect.matcherNode) ? "; new" : "new")
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, nodeIsChildOfExpressionStatement(this.#compiler, expect.matcherNode)
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 (nodeBelongsToArgumentList(this.#compiler, sourceNode)) {
3535
+ if (belongsToArgumentList(sourceNode, this.#compiler)) {
3533
3536
  this.#editor
3534
3537
  .eraseTrailingComma(expect.source)
3535
- .update(expectStart, expectExpressionEnd, nodeIsChildOfExpressionStatement(this.#compiler, expect.matcherNode) ? ";" : "")
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, nodeIsChildOfExpressionStatement(this.#compiler, expect.matcherNode)
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
- if (targetNode != null) {
3550
- const targetText = targetNode.getText().slice(1, -1);
3551
- if (targetText.trim().length > 0) {
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 (nodeBelongsToArgumentList(this.#compiler, sourceNode)) {
3565
+ if (belongsToArgumentList(sourceNode, this.#compiler)) {
3565
3566
  this.#editor
3566
3567
  .eraseTrailingComma(expect.source)
3567
- .update(expectStart, expectExpressionEnd, nodeIsChildOfExpressionStatement(this.#compiler, expect.matcherNode) ? ";" : "")
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, nodeIsChildOfExpressionStatement(this.#compiler, expect.matcherNode)
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
- nodeBelongsToArgumentList(this.#compiler, node)
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 || !nodeBelongsToArgumentList(this.#compiler, 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 || nodeBelongsToArgumentList(this.#compiler, 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 MatchWorker {
4558
- assertionNode;
4559
- #compiler;
4558
+ class MatcherBase {
4559
+ compiler;
4560
4560
  typeChecker;
4561
- constructor(compiler, program, assertionNode) {
4562
- this.#compiler = compiler;
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(matchWorker, sourceNode, targetNode, getArgumentCountText) {
4612
- const isExpression = nodeBelongsToArgumentList(this.compiler, sourceNode);
4589
+ explain(expectNode, sourceNode, targetNode, getArgumentCountText) {
4590
+ const isExpression = belongsToArgumentList(sourceNode, this.compiler);
4613
4591
  const argumentCountText = getArgumentCountText?.();
4614
4592
  const diagnostics = [];
4615
- if (matchWorker.assertionNode.abilityDiagnostics.size > 0) {
4616
- for (const diagnostic of matchWorker.assertionNode.abilityDiagnostics) {
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, matchWorker.assertionNode);
4598
+ origin = DiagnosticOrigin.fromAbilityDiagnostic(diagnostic, expectNode);
4621
4599
  }
4622
4600
  else {
4623
- origin = DiagnosticOrigin.fromAssertion(matchWorker.assertionNode);
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(matchWorker.assertionNode);
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(matchWorker, sourceNode, targetNode, onDiagnostics) {
4621
+ match(expectNode, sourceNode, targetNode, onDiagnostics) {
4644
4622
  const diagnostics = [];
4645
- const sourceType = matchWorker.getType(sourceNode);
4646
- if (!(this.compiler.isIdentifier(sourceNode) ||
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 = "an identifier of a JSX component";
4652
- const text = nodeBelongsToArgumentList(this.compiler, sourceNode)
4653
- ? ExpectDiagnosticText.argumentMustBe(expectedText)
4654
- : ExpectDiagnosticText.typeArgumentMustBe(expectedText);
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(matchWorker, sourceNode, targetNode),
4694
- isMatch: matchWorker.assertionNode.abilityDiagnostics.size === 0,
4662
+ explain: () => this.explain(expectNode, sourceNode, targetNode),
4663
+ isMatch: expectNode.abilityDiagnostics.size === 0,
4695
4664
  };
4696
4665
  }
4697
4666
  }
@@ -5184,7 +5153,7 @@ class Structure {
5184
5153
  return result;
5185
5154
  }
5186
5155
  #memoize(a, b, compare) {
5187
- const key = [a.id, b.id].sort().join(":");
5156
+ const key = [a.id, b.id].sort((a, b) => a - b).join(":");
5188
5157
  const result = this.#memoizeCache.get(key);
5189
5158
  if (result !== undefined) {
5190
5159
  return result !== 2;
@@ -5208,14 +5177,14 @@ class Structure {
5208
5177
  }
5209
5178
  }
5210
5179
 
5211
- class RelationMatcherBase {
5212
- explain(matchWorker, sourceNode, targetNode) {
5213
- const sourceTypeText = matchWorker.getTypeText(sourceNode);
5214
- const targetTypeText = matchWorker.getTypeText(targetNode);
5215
- const text = matchWorker.assertionNode.isNot
5180
+ class RelationMatcherBase extends MatcherBase {
5181
+ explain(expectNode, sourceNode, targetNode) {
5182
+ const sourceTypeText = this.getTypeText(sourceNode, this.typeChecker);
5183
+ const targetTypeText = this.getTypeText(targetNode, this.typeChecker);
5184
+ const text = expectNode.isNot
5216
5185
  ? this.explainText(sourceTypeText, targetTypeText)
5217
5186
  : this.explainNotText(sourceTypeText, targetTypeText);
5218
- const origin = DiagnosticOrigin.fromNode(targetNode, matchWorker.assertionNode);
5187
+ const origin = DiagnosticOrigin.fromNode(targetNode, expectNode);
5219
5188
  return [Diagnostic.error(text, origin)];
5220
5189
  }
5221
5190
  }
@@ -5223,42 +5192,38 @@ class RelationMatcherBase {
5223
5192
  class ToBe extends RelationMatcherBase {
5224
5193
  #structure;
5225
5194
  constructor(compiler, program) {
5226
- super();
5195
+ super(compiler, program);
5227
5196
  this.#structure = new Structure(compiler, program);
5228
5197
  }
5229
5198
  explainText = ExpectDiagnosticText.isTheSame;
5230
5199
  explainNotText = ExpectDiagnosticText.isNotTheSame;
5231
- match(matchWorker, sourceNode, targetNode) {
5200
+ match(expectNode, sourceNode, targetNode) {
5232
5201
  return {
5233
- explain: () => this.explain(matchWorker, sourceNode, targetNode),
5234
- isMatch: this.#structure.compare(matchWorker.getType(sourceNode), matchWorker.getType(targetNode)),
5202
+ explain: () => this.explain(expectNode, sourceNode, targetNode),
5203
+ isMatch: this.#structure.compare(this.getType(sourceNode), this.getType(targetNode)),
5235
5204
  };
5236
5205
  }
5237
5206
  }
5238
5207
 
5239
- class ToBeApplicable {
5240
- #compiler;
5241
- constructor(compiler) {
5242
- this.#compiler = compiler;
5243
- }
5208
+ class ToBeApplicable extends MatcherBase {
5244
5209
  #resolveTargetText(node) {
5245
5210
  let text = "";
5246
5211
  switch (node.kind) {
5247
- case this.#compiler.SyntaxKind.ClassDeclaration:
5212
+ case this.compiler.SyntaxKind.ClassDeclaration:
5248
5213
  text = "class";
5249
5214
  break;
5250
- case this.#compiler.SyntaxKind.MethodDeclaration:
5215
+ case this.compiler.SyntaxKind.MethodDeclaration:
5251
5216
  text = "method";
5252
5217
  break;
5253
- case this.#compiler.SyntaxKind.PropertyDeclaration:
5254
- text = node.modifiers?.some((modifier) => modifier.kind === this.#compiler.SyntaxKind.AccessorKeyword)
5218
+ case this.compiler.SyntaxKind.PropertyDeclaration:
5219
+ text = node.modifiers?.some((modifier) => modifier.kind === this.compiler.SyntaxKind.AccessorKeyword)
5255
5220
  ? "accessor"
5256
5221
  : "field";
5257
5222
  break;
5258
- case this.#compiler.SyntaxKind.GetAccessor:
5223
+ case this.compiler.SyntaxKind.GetAccessor:
5259
5224
  text = "getter";
5260
5225
  break;
5261
- case this.#compiler.SyntaxKind.SetAccessor:
5226
+ case this.compiler.SyntaxKind.SetAccessor:
5262
5227
  text = "setter";
5263
5228
  break;
5264
5229
  }
@@ -5267,12 +5232,12 @@ class ToBeApplicable {
5267
5232
  }
5268
5233
  return text;
5269
5234
  }
5270
- #explain(matchWorker) {
5271
- const targetText = this.#resolveTargetText(matchWorker.assertionNode.matcherNode.parent);
5235
+ #explain(expectNode) {
5236
+ const targetText = this.#resolveTargetText(expectNode.matcherNode.parent);
5272
5237
  const diagnostics = [];
5273
- if (matchWorker.assertionNode.abilityDiagnostics.size > 0) {
5274
- const origin = DiagnosticOrigin.fromAssertion(matchWorker.assertionNode);
5275
- for (const diagnostic of matchWorker.assertionNode.abilityDiagnostics) {
5238
+ if (expectNode.abilityDiagnostics.size > 0) {
5239
+ const origin = DiagnosticOrigin.fromAssertion(expectNode);
5240
+ for (const diagnostic of expectNode.abilityDiagnostics) {
5276
5241
  const text = [ExpectDiagnosticText.cannotBeApplied(targetText), getDiagnosticMessageText(diagnostic)];
5277
5242
  let related;
5278
5243
  if (diagnostic.relatedInformation != null) {
@@ -5282,16 +5247,16 @@ class ToBeApplicable {
5282
5247
  }
5283
5248
  }
5284
5249
  else {
5285
- const origin = DiagnosticOrigin.fromAssertion(matchWorker.assertionNode);
5250
+ const origin = DiagnosticOrigin.fromAssertion(expectNode);
5286
5251
  diagnostics.push(Diagnostic.error(ExpectDiagnosticText.canBeApplied(targetText), origin));
5287
5252
  }
5288
5253
  return diagnostics;
5289
5254
  }
5290
- match(matchWorker, sourceNode, onDiagnostics) {
5291
- const type = matchWorker.getType(sourceNode);
5255
+ match(expectNode, sourceNode, onDiagnostics) {
5256
+ const type = this.getType(sourceNode);
5292
5257
  if (type.getCallSignatures().length === 0) {
5293
5258
  const expectedText = "of a function type";
5294
- const text = nodeBelongsToArgumentList(this.#compiler, sourceNode)
5259
+ const text = belongsToArgumentList(sourceNode, this.compiler)
5295
5260
  ? ExpectDiagnosticText.argumentMustBe(expectedText)
5296
5261
  : ExpectDiagnosticText.typeArgumentMustBe(expectedText);
5297
5262
  const origin = DiagnosticOrigin.fromNode(sourceNode);
@@ -5299,8 +5264,8 @@ class ToBeApplicable {
5299
5264
  return;
5300
5265
  }
5301
5266
  return {
5302
- explain: () => this.#explain(matchWorker),
5303
- isMatch: matchWorker.assertionNode.abilityDiagnostics.size === 0,
5267
+ explain: () => this.#explain(expectNode),
5268
+ isMatch: expectNode.abilityDiagnostics.size === 0,
5304
5269
  };
5305
5270
  }
5306
5271
  }
@@ -5308,10 +5273,10 @@ class ToBeApplicable {
5308
5273
  class ToBeAssignableFrom extends RelationMatcherBase {
5309
5274
  explainText = ExpectDiagnosticText.isAssignableFrom;
5310
5275
  explainNotText = ExpectDiagnosticText.isNotAssignableFrom;
5311
- match(matchWorker, sourceNode, targetNode) {
5276
+ match(expectNode, sourceNode, targetNode) {
5312
5277
  return {
5313
- explain: () => this.explain(matchWorker, sourceNode, targetNode),
5314
- isMatch: matchWorker.checkIsAssignableFrom(sourceNode, targetNode),
5278
+ explain: () => this.explain(expectNode, sourceNode, targetNode),
5279
+ isMatch: this.typeChecker.isTypeAssignableTo(this.getType(targetNode), this.getType(sourceNode)),
5315
5280
  };
5316
5281
  }
5317
5282
  }
@@ -5319,10 +5284,10 @@ class ToBeAssignableFrom extends RelationMatcherBase {
5319
5284
  class ToBeAssignableTo extends RelationMatcherBase {
5320
5285
  explainText = ExpectDiagnosticText.isAssignableTo;
5321
5286
  explainNotText = ExpectDiagnosticText.isNotAssignableTo;
5322
- match(matchWorker, sourceNode, targetNode) {
5287
+ match(expectNode, sourceNode, targetNode) {
5323
5288
  return {
5324
- explain: () => this.explain(matchWorker, sourceNode, targetNode),
5325
- isMatch: matchWorker.checkIsAssignableTo(sourceNode, targetNode),
5289
+ explain: () => this.explain(expectNode, sourceNode, targetNode),
5290
+ isMatch: this.typeChecker.isTypeAssignableTo(this.getType(sourceNode), this.getType(targetNode)),
5326
5291
  };
5327
5292
  }
5328
5293
  }
@@ -5330,11 +5295,11 @@ class ToBeAssignableTo extends RelationMatcherBase {
5330
5295
  class ToBeCallableWith extends AbilityMatcherBase {
5331
5296
  explainText = ExpectDiagnosticText.isCallable;
5332
5297
  explainNotText = ExpectDiagnosticText.isNotCallable;
5333
- match(matchWorker, sourceNode, targetNodes, onDiagnostics) {
5334
- const sourceType = matchWorker.getType(sourceNode);
5298
+ match(expectNode, sourceNode, targetNodes, onDiagnostics) {
5299
+ const sourceType = this.getType(sourceNode);
5335
5300
  if (sourceType.getCallSignatures().length === 0) {
5336
5301
  const text = [];
5337
- if (nodeBelongsToArgumentList(this.compiler, sourceNode)) {
5302
+ if (belongsToArgumentList(sourceNode, this.compiler)) {
5338
5303
  text.push(ExpectDiagnosticText.argumentMustBe("a callable expression"));
5339
5304
  }
5340
5305
  else {
@@ -5348,8 +5313,8 @@ class ToBeCallableWith extends AbilityMatcherBase {
5348
5313
  return;
5349
5314
  }
5350
5315
  return {
5351
- explain: () => this.explain(matchWorker, sourceNode, targetNodes, () => this.getArgumentCountText(targetNodes)),
5352
- isMatch: matchWorker.assertionNode.abilityDiagnostics.size === 0,
5316
+ explain: () => this.explain(expectNode, sourceNode, targetNodes, () => this.getArgumentCountText(targetNodes)),
5317
+ isMatch: expectNode.abilityDiagnostics.size === 0,
5353
5318
  };
5354
5319
  }
5355
5320
  }
@@ -5357,11 +5322,11 @@ class ToBeCallableWith extends AbilityMatcherBase {
5357
5322
  class ToBeConstructableWith extends AbilityMatcherBase {
5358
5323
  explainText = ExpectDiagnosticText.isConstructable;
5359
5324
  explainNotText = ExpectDiagnosticText.isNotConstructable;
5360
- match(matchWorker, sourceNode, targetNodes, onDiagnostics) {
5361
- const sourceType = matchWorker.getType(sourceNode);
5325
+ match(expectNode, sourceNode, targetNodes, onDiagnostics) {
5326
+ const sourceType = this.getType(sourceNode);
5362
5327
  if (sourceType.getConstructSignatures().length === 0) {
5363
5328
  const text = [];
5364
- if (nodeBelongsToArgumentList(this.compiler, sourceNode)) {
5329
+ if (belongsToArgumentList(sourceNode, this.compiler)) {
5365
5330
  text.push(ExpectDiagnosticText.argumentMustBe("a constructable expression"));
5366
5331
  }
5367
5332
  else {
@@ -5375,8 +5340,8 @@ class ToBeConstructableWith extends AbilityMatcherBase {
5375
5340
  return;
5376
5341
  }
5377
5342
  return {
5378
- explain: () => this.explain(matchWorker, sourceNode, targetNodes, () => this.getArgumentCountText(targetNodes)),
5379
- isMatch: matchWorker.assertionNode.abilityDiagnostics.size === 0,
5343
+ explain: () => this.explain(expectNode, sourceNode, targetNodes, () => this.getArgumentCountText(targetNodes)),
5344
+ isMatch: expectNode.abilityDiagnostics.size === 0,
5380
5345
  };
5381
5346
  }
5382
5347
  }
@@ -5384,13 +5349,10 @@ class ToBeConstructableWith extends AbilityMatcherBase {
5384
5349
  class ToBeInstantiableWith extends AbilityMatcherBase {
5385
5350
  explainText = ExpectDiagnosticText.isInstantiable;
5386
5351
  explainNotText = ExpectDiagnosticText.isNotInstantiable;
5387
- match(matchWorker, sourceNode, targetNode, onDiagnostics) {
5388
- if (!(this.compiler.isIdentifier(sourceNode) ||
5389
- this.compiler.isPropertyAccessExpression(sourceNode) ||
5390
- this.compiler.isTypeReferenceNode(sourceNode) ||
5391
- this.compiler.isExpressionWithTypeArguments(sourceNode))) {
5352
+ match(expectNode, sourceNode, targetNode, onDiagnostics) {
5353
+ if (!isIdentifierLike(sourceNode, this.compiler)) {
5392
5354
  let text;
5393
- if (nodeBelongsToArgumentList(this.compiler, sourceNode)) {
5355
+ if (belongsToArgumentList(sourceNode, this.compiler)) {
5394
5356
  text = ExpectDiagnosticText.argumentMustBe("an instantiable expression");
5395
5357
  }
5396
5358
  else {
@@ -5407,49 +5369,51 @@ class ToBeInstantiableWith extends AbilityMatcherBase {
5407
5369
  return;
5408
5370
  }
5409
5371
  return {
5410
- explain: () => this.explain(matchWorker, sourceNode, targetNode, () => this.getTypeArgumentCountText(targetNode)),
5411
- isMatch: matchWorker.assertionNode.abilityDiagnostics.size === 0,
5372
+ explain: () => this.explain(expectNode, sourceNode, targetNode, () => this.getTypeArgumentCountText(targetNode)),
5373
+ isMatch: expectNode.abilityDiagnostics.size === 0,
5412
5374
  };
5413
5375
  }
5414
5376
  }
5415
5377
 
5416
- class ToHaveProperty {
5417
- #compiler;
5418
- constructor(compiler) {
5419
- this.#compiler = compiler;
5420
- }
5421
- #explain(matchWorker, sourceNode, targetNode) {
5422
- const sourceTypeText = matchWorker.getTypeText(sourceNode);
5423
- const targetType = matchWorker.getType(targetNode);
5378
+ class ToHaveProperty extends MatcherBase {
5379
+ #explain(expectNode, sourceNode, targetNode) {
5380
+ const sourceTypeText = this.getTypeText(sourceNode, this.typeChecker);
5381
+ const targetType = this.getType(targetNode);
5424
5382
  let propertyNameText;
5425
- if (targetType.flags & (this.#compiler.TypeFlags.StringLiteral | this.#compiler.TypeFlags.NumberLiteral)) {
5383
+ if (targetType.flags & (this.compiler.TypeFlags.StringLiteral | this.compiler.TypeFlags.NumberLiteral)) {
5426
5384
  propertyNameText = targetType.value.toString();
5427
5385
  }
5428
5386
  else {
5429
- propertyNameText = `[${this.#compiler.unescapeLeadingUnderscores(targetType.symbol.escapedName)}]`;
5387
+ propertyNameText = `[${this.compiler.unescapeLeadingUnderscores(targetType.symbol.escapedName)}]`;
5430
5388
  }
5431
- const origin = DiagnosticOrigin.fromNode(targetNode, matchWorker.assertionNode);
5432
- return matchWorker.assertionNode.isNot
5389
+ const origin = DiagnosticOrigin.fromNode(targetNode, expectNode);
5390
+ return expectNode.isNot
5433
5391
  ? [Diagnostic.error(ExpectDiagnosticText.hasProperty(sourceTypeText, propertyNameText), origin)]
5434
5392
  : [Diagnostic.error(ExpectDiagnosticText.doesNotHaveProperty(sourceTypeText, propertyNameText), origin)];
5435
5393
  }
5436
- match(matchWorker, sourceNode, targetNode, onDiagnostics) {
5394
+ #extendsObjectType(type) {
5395
+ const nonPrimitiveType = "getNonPrimitiveType" in this.typeChecker
5396
+ ? this.typeChecker.getNonPrimitiveType()
5397
+ : { flags: this.compiler.TypeFlags.NonPrimitive };
5398
+ return this.typeChecker.isTypeAssignableTo(type, nonPrimitiveType);
5399
+ }
5400
+ match(expectNode, sourceNode, targetNode, onDiagnostics) {
5437
5401
  const diagnostics = [];
5438
- const sourceType = matchWorker.getType(sourceNode);
5439
- if (sourceType.flags & (this.#compiler.TypeFlags.Any | this.#compiler.TypeFlags.Never) ||
5440
- !matchWorker.extendsObjectType(sourceType)) {
5402
+ const sourceType = this.getType(sourceNode);
5403
+ if (sourceType.flags & (this.compiler.TypeFlags.Any | this.compiler.TypeFlags.Never) ||
5404
+ !this.#extendsObjectType(sourceType)) {
5441
5405
  const expectedText = "of an object type";
5442
- const text = nodeBelongsToArgumentList(this.#compiler, sourceNode)
5406
+ const text = belongsToArgumentList(sourceNode, this.compiler)
5443
5407
  ? ExpectDiagnosticText.argumentMustBe(expectedText)
5444
5408
  : ExpectDiagnosticText.typeArgumentMustBe(expectedText);
5445
5409
  const origin = DiagnosticOrigin.fromNode(sourceNode);
5446
5410
  diagnostics.push(Diagnostic.error(text, origin));
5447
5411
  }
5448
- const targetType = matchWorker.getType(targetNode);
5412
+ const targetType = this.getType(targetNode);
5449
5413
  if (!(targetType.flags &
5450
- (this.#compiler.TypeFlags.StringLiteral |
5451
- this.#compiler.TypeFlags.NumberLiteral |
5452
- this.#compiler.TypeFlags.UniqueESSymbol))) {
5414
+ (this.compiler.TypeFlags.StringLiteral |
5415
+ this.compiler.TypeFlags.NumberLiteral |
5416
+ this.compiler.TypeFlags.UniqueESSymbol))) {
5453
5417
  const expectedText = "a string, number or symbol";
5454
5418
  const text = ExpectDiagnosticText.argumentMustBe(expectedText);
5455
5419
  const origin = DiagnosticOrigin.fromNode(targetNode);
@@ -5460,8 +5424,8 @@ class ToHaveProperty {
5460
5424
  return;
5461
5425
  }
5462
5426
  return {
5463
- explain: () => this.#explain(matchWorker, sourceNode, targetNode),
5464
- isMatch: matchWorker.assertionNode.abilityDiagnostics.size === 0,
5427
+ explain: () => this.#explain(expectNode, sourceNode, targetNode),
5428
+ isMatch: expectNode.abilityDiagnostics.size === 0,
5465
5429
  };
5466
5430
  }
5467
5431
  }
@@ -5471,30 +5435,30 @@ class ToRaiseError {
5471
5435
  constructor(compiler) {
5472
5436
  this.#compiler = compiler;
5473
5437
  }
5474
- #explain(matchWorker, sourceNode, targetNodes) {
5475
- const isExpression = nodeBelongsToArgumentList(this.#compiler, sourceNode);
5476
- const origin = DiagnosticOrigin.fromAssertion(matchWorker.assertionNode);
5477
- if (matchWorker.assertionNode.diagnostics.size === 0) {
5438
+ #explain(expectNode, sourceNode, targetNodes) {
5439
+ const isExpression = belongsToArgumentList(sourceNode, this.#compiler);
5440
+ const origin = DiagnosticOrigin.fromAssertion(expectNode);
5441
+ if (expectNode.diagnostics.size === 0) {
5478
5442
  const text = ExpectDiagnosticText.didNotRaiseError(isExpression);
5479
5443
  return [Diagnostic.error(text, origin)];
5480
5444
  }
5481
- if (matchWorker.assertionNode.diagnostics.size !== targetNodes.length) {
5482
- const count = matchWorker.assertionNode.diagnostics.size;
5445
+ if (expectNode.diagnostics.size !== targetNodes.length) {
5446
+ const count = expectNode.diagnostics.size;
5483
5447
  const text = ExpectDiagnosticText.raisedError(isExpression, count, targetNodes.length);
5484
5448
  const related = [
5485
5449
  Diagnostic.error(ExpectDiagnosticText.raisedTypeError(count)),
5486
- ...Diagnostic.fromDiagnostics([...matchWorker.assertionNode.diagnostics]),
5450
+ ...Diagnostic.fromDiagnostics([...expectNode.diagnostics]),
5487
5451
  ];
5488
5452
  return [Diagnostic.error(text, origin).add({ related })];
5489
5453
  }
5490
- return [...matchWorker.assertionNode.diagnostics].reduce((accumulator, diagnostic, index) => {
5454
+ return [...expectNode.diagnostics].reduce((accumulator, diagnostic, index) => {
5491
5455
  const targetNode = targetNodes[index];
5492
5456
  const isMatch = this.#matchExpectedError(diagnostic, targetNode);
5493
- if (matchWorker.assertionNode.isNot ? isMatch : !isMatch) {
5494
- const text = matchWorker.assertionNode.isNot
5457
+ if (expectNode.isNot ? isMatch : !isMatch) {
5458
+ const text = expectNode.isNot
5495
5459
  ? ExpectDiagnosticText.raisedMatchingError(isExpression)
5496
5460
  : ExpectDiagnosticText.didNotRaiseMatchingError(isExpression);
5497
- const origin = DiagnosticOrigin.fromNode(targetNode, matchWorker.assertionNode);
5461
+ const origin = DiagnosticOrigin.fromNode(targetNode, expectNode);
5498
5462
  const related = [
5499
5463
  Diagnostic.error(ExpectDiagnosticText.raisedTypeError()),
5500
5464
  ...Diagnostic.fromDiagnostics([diagnostic]),
@@ -5504,7 +5468,7 @@ class ToRaiseError {
5504
5468
  return accumulator;
5505
5469
  }, []);
5506
5470
  }
5507
- match(matchWorker, sourceNode, targetNodes, onDiagnostics) {
5471
+ match(expectNode, sourceNode, targetNodes, onDiagnostics) {
5508
5472
  const diagnostics = [];
5509
5473
  for (const targetNode of targetNodes) {
5510
5474
  if (!(this.#compiler.isStringLiteralLike(targetNode) ||
@@ -5522,15 +5486,15 @@ class ToRaiseError {
5522
5486
  }
5523
5487
  let isMatch;
5524
5488
  if (targetNodes.length === 0) {
5525
- isMatch = matchWorker.assertionNode.diagnostics.size > 0;
5489
+ isMatch = expectNode.diagnostics.size > 0;
5526
5490
  }
5527
5491
  else {
5528
5492
  isMatch =
5529
- matchWorker.assertionNode.diagnostics.size === targetNodes.length &&
5530
- [...matchWorker.assertionNode.diagnostics].every((diagnostic, index) => this.#matchExpectedError(diagnostic, targetNodes[index]));
5493
+ expectNode.diagnostics.size === targetNodes.length &&
5494
+ [...expectNode.diagnostics].every((diagnostic, index) => this.#matchExpectedError(diagnostic, targetNodes[index]));
5531
5495
  }
5532
5496
  return {
5533
- explain: () => this.#explain(matchWorker, sourceNode, targetNodes),
5497
+ explain: () => this.#explain(expectNode, sourceNode, targetNodes),
5534
5498
  isMatch,
5535
5499
  };
5536
5500
  }
@@ -5551,7 +5515,6 @@ class ToRaiseError {
5551
5515
  }
5552
5516
 
5553
5517
  class ExpectService {
5554
- #compiler;
5555
5518
  #ensure;
5556
5519
  #program;
5557
5520
  #reject;
@@ -5566,69 +5529,67 @@ class ExpectService {
5566
5529
  toHaveProperty;
5567
5530
  toRaiseError;
5568
5531
  constructor(compiler, program, resolvedConfig) {
5569
- this.#compiler = compiler;
5570
5532
  this.#program = program;
5571
5533
  this.#ensure = new Ensure(compiler);
5572
5534
  this.#reject = new Reject(compiler, program, resolvedConfig);
5573
- this.toAcceptProps = new ToAcceptProps(compiler);
5535
+ this.toAcceptProps = new ToAcceptProps(compiler, program);
5574
5536
  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);
5537
+ this.toBeApplicable = new ToBeApplicable(compiler, program);
5538
+ this.toBeAssignableFrom = new ToBeAssignableFrom(compiler, program);
5539
+ this.toBeAssignableTo = new ToBeAssignableTo(compiler, program);
5540
+ this.toBeCallableWith = new ToBeCallableWith(compiler, program);
5541
+ this.toBeConstructableWith = new ToBeConstructableWith(compiler, program);
5542
+ this.toBeInstantiableWith = new ToBeInstantiableWith(compiler, program);
5543
+ this.toHaveProperty = new ToHaveProperty(compiler, program);
5582
5544
  this.toRaiseError = new ToRaiseError(compiler);
5583
5545
  }
5584
- match(assertionNode, onDiagnostics) {
5585
- const matcherNameText = assertionNode.matcherNameNode.name.text;
5546
+ match(expectNode, onDiagnostics) {
5547
+ const matcherNameText = expectNode.matcherNameNode.name.text;
5586
5548
  if (matcherNameText === "toAcceptProps" &&
5587
- !this.#ensure.jsxSetup(this.#program, assertionNode.matcherNameNode.name, onDiagnostics)) {
5549
+ !this.#ensure.jsxSetup(this.#program, expectNode.matcherNameNode.name, onDiagnostics)) {
5588
5550
  return;
5589
5551
  }
5590
- if (!this.#ensure.argumentOrTypeArgument(assertionNode.source[0], assertionNode.node.expression, onDiagnostics)) {
5552
+ if (!this.#ensure.argumentOrTypeArgument(expectNode.source[0], expectNode.node.expression, onDiagnostics)) {
5591
5553
  return;
5592
5554
  }
5593
- if (!(matcherNameText === "toBeInstantiableWith" || (matcherNameText === "toRaiseError" && !assertionNode.isNot)) &&
5594
- this.#reject.argumentType([assertionNode.source[0], assertionNode.target?.[0]], onDiagnostics)) {
5555
+ if (!(matcherNameText === "toBeInstantiableWith" || (matcherNameText === "toRaiseError" && !expectNode.isNot)) &&
5556
+ this.#reject.argumentType([expectNode.source[0], expectNode.target?.[0]], onDiagnostics)) {
5595
5557
  return;
5596
5558
  }
5597
- const matchWorker = new MatchWorker(this.#compiler, this.#program, assertionNode);
5598
5559
  switch (matcherNameText) {
5599
5560
  case "toAcceptProps":
5600
5561
  case "toBe":
5601
5562
  case "toBeAssignableFrom":
5602
5563
  case "toBeAssignableTo":
5603
- if (!this.#ensure.argumentOrTypeArgument(assertionNode.target?.[0], assertionNode.matcherNameNode.name, onDiagnostics)) {
5564
+ if (!this.#ensure.argumentOrTypeArgument(expectNode.target?.[0], expectNode.matcherNameNode.name, onDiagnostics)) {
5604
5565
  return;
5605
5566
  }
5606
- return this[matcherNameText].match(matchWorker, assertionNode.source[0], assertionNode.target[0], onDiagnostics);
5567
+ return this[matcherNameText].match(expectNode, expectNode.source[0], expectNode.target[0], onDiagnostics);
5607
5568
  case "toBeApplicable":
5608
- return this.toBeApplicable.match(matchWorker, assertionNode.source[0], onDiagnostics);
5569
+ return this.toBeApplicable.match(expectNode, expectNode.source[0], onDiagnostics);
5609
5570
  case "toBeCallableWith":
5610
5571
  case "toBeConstructableWith":
5611
5572
  case "toRaiseError":
5612
- return this[matcherNameText].match(matchWorker, assertionNode.source[0], assertionNode.target, onDiagnostics);
5573
+ return this[matcherNameText].match(expectNode, expectNode.source[0], expectNode.target, onDiagnostics);
5613
5574
  case "toBeInstantiableWith": {
5614
- if (!this.#ensure.typeArgument(assertionNode.target?.[0], assertionNode.matcherNameNode.name, onDiagnostics)) {
5575
+ if (!this.#ensure.typeArgument(expectNode.target?.[0], expectNode.matcherNameNode.name, onDiagnostics)) {
5615
5576
  return;
5616
5577
  }
5617
- return this.toBeInstantiableWith.match(matchWorker, assertionNode.source[0], assertionNode.target[0], onDiagnostics);
5578
+ return this.toBeInstantiableWith.match(expectNode, expectNode.source[0], expectNode.target[0], onDiagnostics);
5618
5579
  }
5619
5580
  case "toHaveProperty":
5620
- if (!this.#ensure.argument(assertionNode.target?.[0], assertionNode.matcherNameNode.name, onDiagnostics)) {
5581
+ if (!this.#ensure.argument(expectNode.target?.[0], expectNode.matcherNameNode.name, onDiagnostics)) {
5621
5582
  return;
5622
5583
  }
5623
- return this.toHaveProperty.match(matchWorker, assertionNode.source[0], assertionNode.target[0], onDiagnostics);
5584
+ return this.toHaveProperty.match(expectNode, expectNode.source[0], expectNode.target[0], onDiagnostics);
5624
5585
  default:
5625
- this.#onMatcherIsNotSupported(matcherNameText, assertionNode, onDiagnostics);
5586
+ this.#onMatcherIsNotSupported(matcherNameText, expectNode, onDiagnostics);
5626
5587
  }
5627
5588
  return;
5628
5589
  }
5629
- #onMatcherIsNotSupported(matcherNameText, assertionNode, onDiagnostics) {
5590
+ #onMatcherIsNotSupported(matcherNameText, expectNode, onDiagnostics) {
5630
5591
  const text = ExpectDiagnosticText.matcherIsNotSupported(matcherNameText);
5631
- const origin = DiagnosticOrigin.fromNode(assertionNode.matcherNameNode.name);
5592
+ const origin = DiagnosticOrigin.fromNode(expectNode.matcherNameNode.name);
5632
5593
  onDiagnostics(Diagnostic.error(text, origin));
5633
5594
  }
5634
5595
  }
@@ -5940,7 +5901,7 @@ class FileRunner {
5940
5901
  class Runner {
5941
5902
  #eventEmitter = new EventEmitter();
5942
5903
  #resolvedConfig;
5943
- static version = "7.2.1";
5904
+ static version = "7.2.2";
5944
5905
  constructor(resolvedConfig) {
5945
5906
  this.#resolvedConfig = resolvedConfig;
5946
5907
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tstyche",
3
- "version": "7.2.1",
3
+ "version": "7.2.2",
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
- "peerDependencies": {
40
- "typescript": ">=5.4"
39
+ "engines": {
40
+ "node": ">=22"
41
41
  },
42
42
  "peerDependenciesMeta": {
43
43
  "typescript": {
44
44
  "optional": true
45
45
  }
46
46
  },
47
- "engines": {
48
- "node": ">=22"
47
+ "peerDependencies": {
48
+ "typescript": ">=5.4"
49
49
  }
50
50
  }