Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Mar 16, 2023
1 parent fd64e5c commit 187c4a8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
12 changes: 6 additions & 6 deletions packages/ts-morph/src/compiler/ast/base/AwaitableNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Constructor } from "../../../types";
import { callBaseSet } from "../callBaseSet";
import { Node } from "../common";

export type AwaitableNodeExtensionType = Node<ts.Node & { awaitModifier?: ts.AwaitKeywordToken }>;
export type AwaitableNodeExtensionType = Node<ts.Node & { awaitModifier?: ts.AwaitKeyword }>;

export interface AwaitableNode {
/**
Expand All @@ -15,11 +15,11 @@ export interface AwaitableNode {
/**
* Gets the await token or undefined if none exists.
*/
getAwaitKeyword(): Node<ts.AwaitKeywordToken> | undefined;
getAwaitKeyword(): Node<ts.AwaitKeyword> | undefined;
/**
* Gets the await token or throws if none exists.
*/
getAwaitKeywordOrThrow(message?: string | (() => string)): Node<ts.AwaitKeywordToken>;
getAwaitKeywordOrThrow(message?: string | (() => string)): Node<ts.AwaitKeyword>;
/**
* Sets if the node is awaited.
* @param value - If it should be awaited or not.
Expand All @@ -33,13 +33,13 @@ export function AwaitableNode<T extends Constructor<AwaitableNodeExtensionType>>
return this.compilerNode.awaitModifier != null;
}

getAwaitKeyword(): Node<ts.AwaitKeywordToken> | undefined {
getAwaitKeyword(): Node<ts.AwaitKeyword> | undefined {
const awaitModifier = this.compilerNode.awaitModifier;
return this._getNodeFromCompilerNodeIfExists(awaitModifier);
}

getAwaitKeywordOrThrow(message?: string | (() => string)): Node<ts.AwaitKeywordToken> {
return errors.throwIfNullOrUndefined(this.getAwaitKeyword(), "Expected to find an await token.");
getAwaitKeywordOrThrow(message?: string | (() => string)): Node<ts.AwaitKeyword> {
return errors.throwIfNullOrUndefined(this.getAwaitKeyword(), message ?? "Expected to find an await token.");
}

setIsAwaited(value: boolean) {
Expand Down
4 changes: 2 additions & 2 deletions packages/ts-morph/src/compiler/ast/base/ModifierableNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ export function ModifierableNode<T extends Constructor<ModifierableNodeExtension
return true;
}

private getCompilerModifiers() {
return this.compilerNode.modifiers || ([] as any as ts.NodeArray<ts.Modifier>);
private getCompilerModifiers(): ts.NodeArray<ts.ModifierLike> {
return (this.compilerNode as any).modifiers || [];
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export abstract class CompilerCommentNode implements ts.Node {
}

export class CompilerCommentStatement extends CompilerCommentNode implements ts.Statement {
_jsdocContainerBrand: any;
_statementBrand: any;
/** @internal */
_commentKind = CommentNodeKind.Statement;
Expand Down
6 changes: 4 additions & 2 deletions packages/ts-morph/src/fileSystem/Directory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -891,13 +891,14 @@ export class Directory {

function getPathForDirectory(dir: Directory) {
switch (moduleResolution) {
case ModuleResolutionKind.NodeJs:
case ModuleResolutionKind.Node10:
if (dir === thisDirectory)
return FileUtils.pathJoin(dir.getPath(), "index.ts");
return dir.getPath();
case ModuleResolutionKind.Classic:
case ModuleResolutionKind.Node16:
case ModuleResolutionKind.NodeNext:
case ModuleResolutionKind.Bundler:
return FileUtils.pathJoin(dir.getPath(), "index.ts");
default:
return errors.throwNotImplementedForNeverValueError(moduleResolution);
Expand All @@ -907,13 +908,14 @@ export class Directory {
function getPathForFilePath(filePath: StandardizedFilePath) {
const dirPath = FileUtils.getDirPath(filePath);
switch (moduleResolution) {
case ModuleResolutionKind.NodeJs:
case ModuleResolutionKind.Node10:
if (dirPath === thisDirectory.getPath())
return filePath;
return filePath.replace(/\/index?(\.d\.ts|\.ts|\.js)$/i, "") as StandardizedFilePath;
case ModuleResolutionKind.Classic:
case ModuleResolutionKind.Node16:
case ModuleResolutionKind.NodeNext:
case ModuleResolutionKind.Bundler:
return filePath;
default:
return errors.throwNotImplementedForNeverValueError(moduleResolution);
Expand Down

0 comments on commit 187c4a8

Please sign in to comment.