-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
1,086 additions
and
473 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
packages/ts-morph/src/compiler/ast/base/name/AssertionKeyNamedNode.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { ts } from "@ts-morph/common"; | ||
import { Constructor } from "../../../../types"; | ||
import { AssertionKey } from "../../aliases"; | ||
import { NamedNodeBase, NamedNodeBaseExtensionType, NamedNodeSpecificBase } from "./NamedNodeBase"; | ||
import { ReferenceFindableNode } from "./ReferenceFindableNode"; | ||
import { RenameableNode } from "./RenameableNode"; | ||
|
||
export type AssertionKeyNamedNodeExtensionType = NamedNodeBaseExtensionType<ts.AssertionKey>; | ||
|
||
export interface AssertionKeyNamedNode extends AssertionKeyNamedNodeSpecific, ReferenceFindableNode, RenameableNode { | ||
} | ||
|
||
export type AssertionKeyNamedNodeSpecific = NamedNodeSpecificBase<AssertionKey>; | ||
|
||
export function AssertionKeyNamedNode<T extends Constructor<AssertionKeyNamedNodeExtensionType>>(Base: T): Constructor<AssertionKeyNamedNode> & T { | ||
const base = ReferenceFindableNode(RenameableNode(Base)); | ||
return NamedNodeBase<ts.AssertionKey, typeof base>(base); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { ts } from "@ts-morph/common"; | ||
import { removeChildren } from "../../../manipulation"; | ||
import { AssertEntryStructure, OptionalKind } from "../../../structures"; | ||
import { Node } from "../common"; | ||
|
||
export const AssertClauseBase = Node; | ||
export class AssertClause extends AssertClauseBase<ts.AssertClause> { | ||
/** Sets the elements in the assert clause */ | ||
setElements(elements: ReadonlyArray<OptionalKind<AssertEntryStructure>>) { | ||
this.replaceWithText(writer => { | ||
const structurePrinter = this._context.structurePrinterFactory.forAssertEntry(); | ||
structurePrinter.printAssertClause(writer, elements); | ||
}); | ||
return this; | ||
} | ||
|
||
/** Gets the elements of the assert clause. */ | ||
getElements() { | ||
return this.compilerNode.elements.map(e => this._getNodeFromCompilerNode(e)); | ||
} | ||
|
||
/** Removes the assert clause. */ | ||
remove() { | ||
removeChildren({ | ||
children: [this], | ||
removePrecedingNewLines: true, | ||
removePrecedingSpaces: true, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { ts } from "@ts-morph/common"; | ||
import { AssertEntryStructure, AssertEntryStructureSpecificStructure, StructureKind } from "../../../structures"; | ||
import { AssertionKeyNamedNode } from "../base"; | ||
import { callBaseGetStructure } from "../callBaseGetStructure"; | ||
import { callBaseSet } from "../callBaseSet"; | ||
import { Node } from "../common"; | ||
import { StringLiteral } from "../literal"; | ||
|
||
export const AssertEntryBase = AssertionKeyNamedNode(Node); | ||
export class AssertEntry extends AssertEntryBase<ts.AssertEntry> { | ||
/** Gets the value of the assert entry. */ | ||
getValue(): StringLiteral { | ||
return this._getNodeFromCompilerNode(this.compilerNode.value); | ||
} | ||
|
||
/** Sets the name and value. */ | ||
set(structure: Partial<AssertEntryStructure>) { | ||
callBaseSet(AssertEntryBase.prototype, this, structure); | ||
|
||
if (structure.value) | ||
this.getValue().setLiteralValue(structure.value); | ||
|
||
return this; | ||
} | ||
|
||
/** | ||
* Gets the structure equivalent to this node. | ||
*/ | ||
getStructure(): AssertEntryStructure { | ||
return callBaseGetStructure<AssertEntryStructureSpecificStructure>(AssertEntryBase.prototype, this, { | ||
kind: StructureKind.AssertEntry, | ||
value: this.getValue().getLiteralValue(), | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.