-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix removing class elements on object literal expressions.
Previously this would incorrectly throw.
- Loading branch information
Showing
4 changed files
with
33 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
import { removeClassMember } from "../../../manipulation"; | ||
import * as errors from "../../../errors"; | ||
import { removeClassMember, removeCommaSeparatedChild } from "../../../manipulation"; | ||
import { ts } from "../../../typescript"; | ||
import { TypeGuards } from "../../../utils"; | ||
import { Node } from "../common"; | ||
|
||
export class ClassElement<T extends ts.ClassElement = ts.ClassElement> extends Node<T> { | ||
/** | ||
* Removes the class member. | ||
*/ | ||
remove() { | ||
removeClassMember(this); | ||
const parent = this.getParent(); | ||
if (TypeGuards.isClassDeclaration(parent) || TypeGuards.isClassExpression(parent)) | ||
removeClassMember(this); | ||
else if (TypeGuards.isObjectLiteralExpression(parent)) | ||
removeCommaSeparatedChild(this); | ||
else | ||
errors.throwNotImplementedForSyntaxKindError(parent.getKind()); | ||
} | ||
} |
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