Skip to content

Commit

Permalink
chore: bumped minimum TypeScript version to 4.3 (#207)
Browse files Browse the repository at this point in the history
## PR Checklist

- [x] Addresses an existing open issue: fixes #206
- [x] That issue was marked as [`status: accepting
prs`](https://github.com/JoshuaKGoldberg/ts-api-utils/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22)
- [x] Steps in
[CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/ts-api-utils/blob/main/.github/CONTRIBUTING.md)
were taken

## Overview

Raises the lowest tested version to 4.3 and removes code that supports
earlier versions (i.e. 4.2). Bumps the version to ~0.1.0~ 0.2.0
accordingly.

---------

Co-authored-by: Rebecca Stevens <rebecca.stevens@outlook.co.nz>
  • Loading branch information
JoshuaKGoldberg and RebeccaStevens authored Jun 15, 2023
1 parent e11775e commit 279f843
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 27 deletions.
8 changes: 4 additions & 4 deletions .github/actions/protect-main/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ runs:
{ context: "packages" },
{ context: "prettier" },
{ context: "spelling" },
{ context: "test (16.13.0, 4.2.4)" },
{ context: "test (16.13.0, 4.3.5)" },
{ context: "test (16.13.0, 4.4.4)" },
{ context: "test (16.13.0, 4.6.4)" },
{ context: "test (16.13.0, 4.9.5)" },
{ context: "test (16.13.0, latest)" },
{ context: "test (18.x, 4.2.4)" },
{ context: "test (18.x, 4.3.5)" },
{ context: "test (18.x, 4.4.4)" },
{ context: "test (18.x, 4.6.4)" },
{ context: "test (18.x, 4.9.5)" },
{ context: "test (18.x, latest)" },
{ context: "type-check" },
],
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ jobs:
fail-fast: false
matrix:
node_version:
- "16.13.0"
- "18.x"
- "16.13.0"
ts_version:
- "latest"
- "4.4.4"
- "4.9.5"
- "4.6.4"
- "4.3.5"
- "4.2.4"
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/prepare
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ts-api-utils",
"version": "0.1.0",
"version": "0.2.0",
"description": "Utility functions for working with TypeScript's API. Successor to the wonderful tsutils.",
"repository": {
"type": "git",
Expand Down
6 changes: 1 addition & 5 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import ts from "typescript";

import { isTsVersionAtLeast } from "./utils";

/**
* Callback type used for {@link forEachToken}.
*
Expand Down Expand Up @@ -35,11 +33,9 @@ export function forEachToken(
callback: ForEachTokenCallback,
sourceFile: ts.SourceFile = node.getSourceFile()
): void {
const isTS4dot3 = isTsVersionAtLeast(4, 3);

const queue = [];
while (true) {
if (isTS4dot3 && ts.isTokenKind(node.kind)) {
if (ts.isTokenKind(node.kind)) {
callback(node);
} else if (
// eslint-disable-next-line deprecation/deprecation -- need for support of TS < 4.7
Expand Down
25 changes: 11 additions & 14 deletions src/types/getters.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import ts from "typescript";
import { describe, expect, it } from "vitest";

import { createSourceFileAndTypeChecker } from "../test/utils";
import { isTsVersionAtLeast } from "../utils";
import {
getCallSignaturesOfType,
getWellKnownSymbolPropertyOfType,
Expand Down Expand Up @@ -77,25 +76,23 @@ describe("getWellKnownSymbolPropertyOfType", () => {
});
});

if (isTsVersionAtLeast(4, 3)) {
// https://github.com/JoshuaKGoldberg/ts-api-tools/issues/15
it("finds the symbol for an `asyncIterator` property when that property isn't directly on the type", () => {
const { sourceFile, typeChecker } = createSourceFileAndTypeChecker(`
// https://github.com/JoshuaKGoldberg/ts-api-tools/issues/15
it("finds the symbol for an `asyncIterator` property when that property isn't directly on the type", () => {
const { sourceFile, typeChecker } = createSourceFileAndTypeChecker(`
declare const x: Omit<{
[Symbol.asyncIterator](): AsyncIterator<any>;
}, 'z'>
`);

const node = (sourceFile.statements[0] as ts.VariableStatement)
.declarationList.declarations[0].name;
const node = (sourceFile.statements[0] as ts.VariableStatement)
.declarationList.declarations[0].name;

const type = typeChecker.getTypeAtLocation(node);
const type = typeChecker.getTypeAtLocation(node);

expect(
getWellKnownSymbolPropertyOfType(type, "asyncIterator", typeChecker)
).toMatchObject({
name: /^__@asyncIterator/,
});
expect(
getWellKnownSymbolPropertyOfType(type, "asyncIterator", typeChecker)
).toMatchObject({
name: /^__@asyncIterator/,
});
}
});
});

0 comments on commit 279f843

Please sign in to comment.