-
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.
- Loading branch information
Showing
13 changed files
with
288 additions
and
173 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 |
---|---|---|
|
@@ -17,4 +17,5 @@ | |
/dist-scripts | ||
/dist-declarations | ||
/.nyc_output | ||
/npm-debug.log | ||
/npm-debug.log | ||
/yarn-error.log |
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
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
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,32 @@ | ||
import { ts } from "../../../typescript"; | ||
import { RenameableNode } from "../base"; | ||
import { Node } from "../common"; | ||
|
||
export const NamespaceImportBase = RenameableNode(Node); | ||
export class NamespaceImport extends NamespaceImportBase<ts.NamespaceImport> { | ||
/** | ||
* Sets the name of the namespace import. | ||
*/ | ||
setName(name: string) { | ||
const nameNode = this.getNameNode(); | ||
if (nameNode.getText() === name) | ||
return this; | ||
|
||
nameNode.replaceWithText(name); | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets the name of the namespace import. | ||
*/ | ||
getName() { | ||
return this.getNameNode().getText(); | ||
} | ||
|
||
/** | ||
* Gets the namespace import's name node. | ||
*/ | ||
getNameNode() { | ||
return this.getNodeFromCompilerNode(this.compilerNode.name); | ||
} | ||
} |
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,52 @@ | ||
import { expect } from "chai"; | ||
import { NamespaceImport } from "../../../compiler"; | ||
import { SyntaxKind } from "../../../typescript"; | ||
import { getInfoFromText, getInfoFromTextWithDescendant } from "../testHelpers"; | ||
|
||
describe(nameof(NamespaceImport), () => { | ||
function getNamespaceImport(text: string) { | ||
return getInfoFromTextWithDescendant<NamespaceImport>(text, SyntaxKind.NamespaceImport); | ||
} | ||
|
||
describe(nameof<NamespaceImport>(n => n.setName), () => { | ||
it("should only change what's imported", () => { | ||
const { descendant, sourceFile, project } = getNamespaceImport("import * as ts from './file'; const t = ts;"); | ||
const otherSourceFile = project.createSourceFile("file.ts", "export class name {}\nexport class newName {}"); | ||
descendant.setName("tsNew"); | ||
expect(sourceFile.getText()).to.equal("import * as tsNew from './file'; const t = ts;"); | ||
expect(otherSourceFile.getText()).to.equal("export class name {}\nexport class newName {}"); | ||
}); | ||
}); | ||
|
||
describe(nameof<NamespaceImport>(n => n.rename), () => { | ||
it("should rename what's imported", () => { | ||
const { descendant, sourceFile, project } = getNamespaceImport("import * as ts from './file'; const t = ts;"); | ||
const otherSourceFile = project.createSourceFile("file.ts", "export class name {}\nexport class newName {}"); | ||
descendant.rename("tsNew"); | ||
expect(sourceFile.getText()).to.equal("import * as tsNew from './file'; const t = tsNew;"); | ||
expect(otherSourceFile.getText()).to.equal("export class name {}\nexport class newName {}"); | ||
}); | ||
}); | ||
|
||
describe(nameof<NamespaceImport>(n => n.getNameNode), () => { | ||
function doTest(text: string, name: string) { | ||
const { descendant } = getNamespaceImport(text); | ||
expect(descendant.getNameNode().getText()).to.equal(name); | ||
} | ||
|
||
it("should get the name", () => { | ||
doTest(`import * as name from "./test";`, "name"); | ||
}); | ||
}); | ||
|
||
describe(nameof<NamespaceImport>(n => n.getName), () => { | ||
function doTest(text: string, name: string) { | ||
const { descendant } = getNamespaceImport(text); | ||
expect(descendant.getName()).to.equal(name); | ||
} | ||
|
||
it("should get the name", () => { | ||
doTest(`import * as name from "./test";`, "name"); | ||
}); | ||
}); | ||
}); |
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.