Skip to content

Commit

Permalink
refactor: Node.isXNode(node) static type guard methods are now `Nod…
Browse files Browse the repository at this point in the history
…e.isX(node)`

BREAKING CHANGE: `Node.isXNode(node)` static type guard methods are now `Node.isX(node)` to reduce verbosity.

Closes #1166
  • Loading branch information
dsherret committed Nov 20, 2021
1 parent 519b139 commit e5bcba9
Show file tree
Hide file tree
Showing 24 changed files with 305 additions and 305 deletions.
118 changes: 59 additions & 59 deletions deno/ts_morph.d.ts

Large diffs are not rendered by default.

180 changes: 90 additions & 90 deletions deno/ts_morph.js

Large diffs are not rendered by default.

118 changes: 59 additions & 59 deletions packages/ts-morph/lib/ts-morph.d.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function createNodeTypeGuards(inspector: TsMorphInspector, tsInspector: T
getMethodInfos().filter(n => isAllowedClass(n.name.replace(/^is/, ""))).forEach(method => {
const description = `Gets if the node is ${(method.name[0] === "A" || method.name[0] === "E") ? "an" : "a"} ${method.name}.`;
const common = {
name: `is${method.name}`,
name: `is${method.name.endsWith("TypeNode") ? method.name : method.name.replace(/Node$/, "")}`,
isStatic: true,
};
const isImplementedNodeName = implementedNodeNames.has(method.name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function ExclamationTokenableNode<T extends Constructor<ExclamationTokena
return this;

if (value) {
if (Node.isQuestionTokenableNode(this))
if (Node.isQuestionTokenable(this))
this.setHasQuestionToken(false);

const colonNode = this.getFirstChildByKind(SyntaxKind.ColonToken);
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-morph/src/compiler/ast/base/ModuledNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ export function ModuledNode<T extends Constructor<ModuledNodeExtensionType>>(Bas
const declaration = defaultExportSymbol.getDeclarations()[0];
if (declaration.compilerNode.kind === SyntaxKind.ExportAssignment)
removeChildrenWithFormatting({ children: [declaration], getSiblingFormatting: () => FormattingKind.Newline });
else if (Node.isModifierableNode(declaration)) {
else if (Node.isModifierable(declaration)) {
declaration.toggleModifier("default", false);
declaration.toggleModifier("export", false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export function QuestionTokenableNode<T extends Constructor<QuestionTokenableNod
return this;

if (value) {
if (Node.isExclamationTokenableNode(this))
if (Node.isExclamationTokenable(this))
this.setHasExclamationToken(false);

insertIntoParentTextRange({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function ExportGetableNode<T extends Constructor<ExportGetableNodeExtensi
const variableStatement = this.getVariableStatement();
return variableStatement?.getExportKeyword();
}
if (!Node.isModifierableNode(this))
if (!Node.isModifierable(this))
return throwForNotModifierableNode();
return this.getFirstModifierByKind(SyntaxKind.ExportKeyword);
}
Expand All @@ -73,7 +73,7 @@ export function ExportGetableNode<T extends Constructor<ExportGetableNodeExtensi
const variableStatement = this.getVariableStatement();
return variableStatement?.getDefaultKeyword();
}
if (!Node.isModifierableNode(this))
if (!Node.isModifierable(this))
return throwForNotModifierableNode();
return this.getFirstModifierByKind(SyntaxKind.DefaultKeyword);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function apply<T extends Constructor<ExportableNodeExtensionType & ExportGetable
function shouldWriteAsSeparateStatement(this: Node) {
if (Node.isEnumDeclaration(this) || Node.isModuleDeclaration(this) || Node.isTypeAliasDeclaration(this))
return true;
if (Node.isAmbientableNode(this) && this.isAmbient())
if (Node.isAmbientable(this) && this.isAmbient())
return true;
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function getNodeForReferences(node: ReferenceFindableNodeExtensionType) {
const nameNode = node.getNodeProperty("name");
if (nameNode != null)
return nameNode;
if (Node.isExportableNode(node))
if (Node.isExportable(node))
return node.getDefaultKeyword() || node;
return node;
}
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ export function ClassLikeDeclarationBaseSpecific<T extends Constructor<ClassLike
index,
parent: this,
write: (writer, info) => {
const previousMemberHasBody = !isAmbient && info.previousMember != null && Node.isBodyableNode(info.previousMember)
const previousMemberHasBody = !isAmbient && info.previousMember != null && Node.isBodyable(info.previousMember)
&& info.previousMember.hasBody();
const firstStructureHasBody = !isAmbient && members instanceof Array && structureHasBody(members[0]);

Expand All @@ -693,7 +693,7 @@ export function ClassLikeDeclarationBaseSpecific<T extends Constructor<ClassLike
writer.write(memberWriter.toString());

const lastStructureHasBody = !isAmbient && members instanceof Array && structureHasBody(members[members.length - 1]);
const nextMemberHasBody = !isAmbient && info.nextMember != null && Node.isBodyableNode(info.nextMember) && info.nextMember.hasBody();
const nextMemberHasBody = !isAmbient && info.nextMember != null && Node.isBodyable(info.nextMember) && info.nextMember.hasBody();

if (info.nextMember != null && lastStructureHasBody || nextMemberHasBody)
writer.blankLineIfLastNot();
Expand Down
Loading

0 comments on commit e5bcba9

Please sign in to comment.