Skip to content

Commit

Permalink
feat: upgrade to TypeScript 5.2 (#1450)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Sep 11, 2023
1 parent 7207de1 commit 9bb94b0
Show file tree
Hide file tree
Showing 36 changed files with 12,567 additions and 9,904 deletions.
40 changes: 26 additions & 14 deletions deno/common/ts_morph_common.js

Large diffs are not rendered by default.

523 changes: 274 additions & 249 deletions deno/common/typescript.d.ts

Large diffs are not rendered by default.

20,947 changes: 11,696 additions & 9,251 deletions deno/common/typescript.js

Large diffs are not rendered by default.

24 changes: 19 additions & 5 deletions deno/ts_morph.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4127,6 +4127,8 @@ export declare class Node<NodeType extends ts.Node = ts.Node> {
static isReferenceFindable<T extends Node>(node: T | undefined): node is ReferenceFindableNode & ReferenceFindableNodeExtensionType & T;
/** Gets if the node is a RenameableNode. */
static isRenameable<T extends Node>(node: T | undefined): node is RenameableNode & RenameableNodeExtensionType & T;
/** Gets if the node is a RestTypeNode. */
static isRestTypeNode(node: Node | undefined): node is RestTypeNode;
/** Gets if the node is a ReturnTypedNode. */
static isReturnTyped<T extends Node>(node: T | undefined): node is ReturnTypedNode & ReturnTypedNodeExtensionType & T;
/** Gets if the node is a ScopeableNode. */
Expand Down Expand Up @@ -6418,6 +6420,7 @@ export interface ImplementedKindToNodeMappings {
[SyntaxKind.PropertyDeclaration]: PropertyDeclaration;
[SyntaxKind.PropertySignature]: PropertySignature;
[SyntaxKind.RegularExpressionLiteral]: RegularExpressionLiteral;
[SyntaxKind.RestType]: RestTypeNode;
[SyntaxKind.ReturnStatement]: ReturnStatement;
[SyntaxKind.SatisfiesExpression]: SatisfiesExpression;
[SyntaxKind.SetAccessor]: SetAccessorDeclaration;
Expand Down Expand Up @@ -8386,8 +8389,8 @@ export declare class VariableStatement extends VariableStatementBase<ts.Variable
getDeclarations(): VariableDeclaration[];
/** Gets the variable declaration kind. */
getDeclarationKind(): VariableDeclarationKind;
/** Gets the variable declaration kind keyword. */
getDeclarationKindKeyword(): Node<ts.Node>;
/** Gets the variable declaration kind keywords. */
getDeclarationKindKeywords(): Node<ts.Node>[];
/**
* Sets the variable declaration kind.
* @param type - Type to set.
Expand Down Expand Up @@ -8664,6 +8667,15 @@ export declare class ParenthesizedTypeNode extends TypeNode<ts.ParenthesizedType
getParentOrThrow(message?: string | (() => string)): NonNullable<NodeParentType<ts.ParenthesizedTypeNode>>;
}

export declare class RestTypeNode extends TypeNode<ts.RestTypeNode> {
/** Gets the rest type node's inner type. */
getTypeNode(): TypeNode<ts.TypeNode>;
/** @inheritdoc **/
getParent(): NodeParentType<ts.RestTypeNode>;
/** @inheritdoc **/
getParentOrThrow(message?: string | (() => string)): NonNullable<NodeParentType<ts.RestTypeNode>>;
}

export declare class TemplateLiteralTypeNode extends TypeNode<ts.TemplateLiteralTypeNode> {
/** Gets the template head. */
getHead(): TemplateHead;
Expand Down Expand Up @@ -8881,7 +8893,9 @@ export declare class VariableDeclaration extends VariableDeclarationBase<ts.Vari
export declare enum VariableDeclarationKind {
Var = "var",
Let = "let",
Const = "const"
Const = "const",
AwaitUsing = "await using",
Using = "using"
}

declare const VariableDeclarationListBase: Constructor<ModifierableNode> & typeof Node;
Expand All @@ -8891,8 +8905,8 @@ export declare class VariableDeclarationList extends VariableDeclarationListBase
getDeclarations(): VariableDeclaration[];
/** Gets the variable declaration kind. */
getDeclarationKind(): VariableDeclarationKind;
/** Gets the variable declaration kind keyword. */
getDeclarationKindKeyword(): Node;
/** Gets the variable declaration kind keywords. */
getDeclarationKindKeywords(): Node[];
/**
* Sets the variable declaration kind.
* @param type - Type to set.
Expand Down
74 changes: 52 additions & 22 deletions deno/ts_morph.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/details/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Certain nodes can have JS docs. For example:
* @param person - Person to get the name from.
*/
function getName(person: Person) {
// ...
// ...
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/details/exports.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ default: 5
Export declarations look like this:

```ts setup: class OtherClass {}
export { MyClass } from "./other-file";
export * from "./some-file";
export {MyClass} from "./other-file";
export {OtherClass};
export { OtherClass };
```

Get the export declarations by calling:
Expand Down
8 changes: 4 additions & 4 deletions docs/details/modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ moduleDeclaration.getDeclarationKindKeyword();

```ts ignore-error: 2664, 2669
declare module "my-library" {
// this is a global namespace declaration
global {
const foo: string;
}
// this is a global namespace declaration
global {
const foo: string;
}
}
```

Expand Down
26 changes: 13 additions & 13 deletions docs/manipulation/performance.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ For example, instead of writing code like this:

```ts setup: const classStructures: ClassDeclarationStructure[];
for (const classStructure of classStructures)
sourceFile.addClass(classStructure);
sourceFile.addClass(classStructure);
```

Write this instead:
Expand All @@ -74,30 +74,30 @@ For example, given the following code:

```ts setup: const sourceFiles: SourceFile[]; const someCheckOnSymbol: any;
for (const sourceFile of sourceFiles) {
for (const classDec of sourceFile.getClasses()) {
if (someCheckOnSymbol(classDec.getSymbolOrThrow()))
classDec.remove();
}
for (const classDec of sourceFile.getClasses()) {
if (someCheckOnSymbol(classDec.getSymbolOrThrow()))
classDec.remove();
}
}
```

Write it this way instead:

```ts setup: const sourceFiles: SourceFile[]; const someCheckOnSymbol: any;
for (const classDec of getClassesToRemove())
classDec.remove();
classDec.remove();

function getClassesToRemove() {
const classesToRemove: ClassDeclaration[] = [];
const classesToRemove: ClassDeclaration[] = [];

for (const sourceFile of sourceFiles) {
for (const classDec of sourceFile.getClasses()) {
if (someCheckOnSymbol(classDec.getSymbolOrThrow()))
classesToRemove.push(classDec);
}
for (const sourceFile of sourceFiles) {
for (const classDec of sourceFile.getClasses()) {
if (someCheckOnSymbol(classDec.getSymbolOrThrow()))
classesToRemove.push(classDec);
}
}

return classesToRemove;
return classesToRemove;
}
```

Expand Down
6 changes: 3 additions & 3 deletions docs/manipulation/renaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ Set the `renameInComments` and `renameInStrings` options to `true` (they are `fa

```ts setup: let myEnum: EnumDeclaration;
myEnum.rename("SomeOtherName", {
renameInComments: true,
renameInStrings: true
renameInComments: true,
renameInStrings: true,
});
```

Expand Down Expand Up @@ -80,7 +80,7 @@ This behaviour change can be specified when renaming:

```ts setup: let varA: VariableDeclaration;
varA.rename("SomeOtherName", {
usePrefixAndSuffixText: true
usePrefixAndSuffixText: true,
});
```

Expand Down
5 changes: 2 additions & 3 deletions docs/manipulation/structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ import { Structure } from "ts-morph";
// ...etc...

if (Structure.isExportable(structure))
structure.isExported = false;
structure.isExported = false;
```

#### `forEachStructureChild`
Expand Down Expand Up @@ -113,6 +113,5 @@ Some structures have optional kinds. For example, in `parameters: [{ name: "myPa
Note that unlike ts-morph's `forEachChild`, this function acts like the `forEachChild` in the compiler API and will return any truthy value returned in the second argument's function:

```ts setup: const structure: SourceFileStructure;
const firstClassDecStructure = forEachStructureChild(structure,
child => Structure.isClass(child) ? child : undefined);
const firstClassDecStructure = forEachStructureChild(structure, child => Structure.isClass(child) ? child : undefined);
```
4 changes: 2 additions & 2 deletions docs/navigation/directories.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ const childDirs = directory.getDirectories();
Check if a directory is an ancestor or descendant of another directory:

```ts setup: let grandParentDir: Directory, childDir: Directory;
grandParentDir.isAncestorOf(childDir); // true
grandParentDir.isAncestorOf(childDir); // true
childDir.isDescendantOf(grandParentDir); // true
```

Or if a directory is an ancestor of a source file:

```ts setup: let grandParentDir: Directory, parentDir: Directory, childSourceFile: SourceFile;
grandParentDir.isAncestorOf(childSourceFile); // true
parentDir.isAncestorOf(childSourceFile); // true
parentDir.isAncestorOf(childSourceFile); // true
```

### Source files
Expand Down
20 changes: 10 additions & 10 deletions docs/setup/file-system.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ This is because, the `lib` compiler option must be specified, similar to when yo

```ts setup: let mySetDecl: Node;
const project = new Project({
useInMemoryFileSystem: true,
compilerOptions: {
lib: ["lib.es2015.d.ts"],
},
useInMemoryFileSystem: true,
compilerOptions: {
lib: ["lib.es2015.d.ts"],
},
});
/// ...omitted... same as above...
console.log(mySetDecl.getType().getText()); // Set<string>, good
Expand All @@ -70,10 +70,10 @@ Or you may specify a target that will implicitly load in the lib files that you
import { Project, ts } from "ts-morph";

const project = new Project({
useInMemoryFileSystem: true,
compilerOptions: {
target: ts.ScriptTarget.ES2015,
},
useInMemoryFileSystem: true,
compilerOptions: {
target: ts.ScriptTarget.ES2015,
},
});
/// ...omitted... same as above...
console.log(mySetDecl.getType().getText()); // Set<string>, good
Expand All @@ -95,10 +95,10 @@ const project = new Project({
It's possible to use your own custom file system by implementing the `FileSystemHost` interface then passing in an instance of this when creating a new `Project` instance:

```ts ignore-error: 2420, 2345, 2740
import { Project, FileSystemHost } from "ts-morph";
import { FileSystemHost, Project } from "ts-morph";

class MyCustomFileSystem implements FileSystemHost {
// implement it
// implement it
}

const fs = new MyCustomFileSystem();
Expand Down
4 changes: 2 additions & 2 deletions dprint.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
"dist-deno"
],
"plugins": [
"https://plugins.dprint.dev/typescript-0.85.0.wasm",
"https://plugins.dprint.dev/typescript-0.87.1.wasm",
"https://plugins.dprint.dev/json-0.7.2.wasm",
"https://plugins.dprint.dev/markdown-0.15.3.wasm"
"https://plugins.dprint.dev/markdown-0.16.0.wasm"
]
}
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/bootstrap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"rollup": "=3.20.2",
"ts-node": "^10.9.1",
"tslib": "^2.5.0",
"typescript": "~5.1.3"
"typescript": "~5.2.2"
},
"publishConfig": {
"access": "public"
Expand Down

0 comments on commit 9bb94b0

Please sign in to comment.