Skip to content
This repository has been archived by the owner on Feb 20, 2024. It is now read-only.

Commit

Permalink
fix: error on imports from 'tsd' package (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrazauskas committed Jun 18, 2023
1 parent 36da391 commit f70a73c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .yarn/versions/60ec5113.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
releases:
tsd-lite: patch
15 changes: 15 additions & 0 deletions source/parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as ts from "@tsd/typescript";
import { Assertion } from "./handleAssertions";
import { TsdError } from "./utils";

export type Location = {
fileName: string;
Expand All @@ -15,6 +16,20 @@ export function extractAssertions(program: ts.Program): {
const assertions = new Map<Assertion, Set<ts.CallExpression>>();

function visit(node: ts.Node) {
if (
ts.isImportDeclaration(node) &&
/^("|')tsd("|')$/.test(node.moduleSpecifier.getText())
) {
throw new TsdError("Usage Error", {
messageText:
"The assertions must be imported from 'tsd-lite' package, please refactor the type test. " +
"This is a precaution to prevent bugs and errors caused by differences between the testing APIs. " +
"You should also consider uninstalling 'tsd' to reduce the number of redundant dependencies.",
file: node.moduleSpecifier.getSourceFile(),
start: node.moduleSpecifier.getStart(),
});
}

if (ts.isCallExpression(node)) {
const identifier = node.expression.getText();

Expand Down

0 comments on commit f70a73c

Please sign in to comment.