-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support renaming a property to a private identifier
Closes #1198
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 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
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 { expect } from "chai"; | ||
import { Project } from "../../Project"; | ||
|
||
describe.only("tests for issue #1198", () => { | ||
it("should not have issues when renaming private identifier", () => { | ||
const project = new Project({ useInMemoryFileSystem: true }); | ||
const sourceFile = project.createSourceFile("mod.ts", `class Foo { | ||
private one: string; | ||
private two: string; | ||
}`); | ||
const classDecl = sourceFile.getClasses()[0]; | ||
for (const property of classDecl.getInstanceProperties()) { | ||
const name = property.getName(); | ||
property.toggleModifier("private", false); | ||
property.rename(`#${name}`); | ||
} | ||
|
||
expect(sourceFile.getText()).to.equal(`class Foo { | ||
#one: string; | ||
#two: string; | ||
}`); | ||
|
||
// now swap them back | ||
for (const property of classDecl.getInstanceProperties()) { | ||
const name = property.getName().replace(/^#/, ""); | ||
property.rename(`${name}`); | ||
property.toggleModifier("private", true); | ||
} | ||
|
||
expect(sourceFile.getText()).to.equal(`class Foo { | ||
private one: string; | ||
private two: string; | ||
}`); | ||
}); | ||
}); |