Skip to content

Commit

Permalink
feat: ImportDeclaration.setDefaultImport should remove the default im…
Browse files Browse the repository at this point in the history
…port when providing an empty string.
  • Loading branch information
dsherret committed Sep 20, 2018
1 parent 87dd9cf commit f81f90a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/compiler/file/ImportDeclaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ export class ImportDeclaration extends Statement<ts.ImportDeclaration> {
* @param text - Text to set as the default import.
*/
setDefaultImport(text: string) {
errors.throwIfWhitespaceOrNotString(text, nameof(text));
if (StringUtils.isNullOrWhitespace(text))
return this.removeDefaultImport();

const defaultImport = this.getDefaultImport();
if (defaultImport != null) {
Expand Down
5 changes: 2 additions & 3 deletions src/tests/compiler/file/importDeclarationTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,8 @@ describe(nameof(ImportDeclaration), () => {
expect(sourceFile.getText()).to.equal(expected);
}

it("should throw when whitespace", () => {
const { firstChild, sourceFile } = getInfoFromText<ImportDeclaration>("import d from './file';");
expect(() => firstChild.setDefaultImport(" ")).to.throw(errors.ArgumentNullOrWhitespaceError);
it("should remove when empty", () => {
doTest(`import identifier from './file'; const t = identifier;`, "", `import './file'; const t = newName;`);
});

it("should rename when exists", () => {
Expand Down

0 comments on commit f81f90a

Please sign in to comment.