-
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.
feat: Add ExternalModuleReference and ImportEqualsDeclaration.
Closes #225.
- Loading branch information
Showing
14 changed files
with
167 additions
and
13 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
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,20 @@ | ||
import * as ts from "typescript"; | ||
import * as errors from "./../../errors"; | ||
import {Node} from "./../common"; | ||
import {Expression} from "./../expression"; | ||
|
||
export class ExternalModuleReference extends Node<ts.ExternalModuleReference> { | ||
/** | ||
* Gets the expression or undefined of the yield expression. | ||
*/ | ||
getExpression() { | ||
return this.getNodeFromCompilerNodeIfExists(this.compilerNode.expression) as Expression | undefined; | ||
} | ||
|
||
/** | ||
* Gets the expression of the yield expression or throws if it does not exist. | ||
*/ | ||
getExpressionOrThrow() { | ||
return errors.throwIfNullOrUndefined(this.getExpression(), "Expected to find an expression."); | ||
} | ||
} |
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,15 @@ | ||
import * as ts from "typescript"; | ||
import {ModuleReference} from "./../aliases"; | ||
import {JSDocableNode, NamedNode} from "./../base"; | ||
import {Node} from "./../common"; | ||
import {Statement} from "./../statement"; | ||
|
||
export const ImportEqualsDeclarationBase = JSDocableNode(NamedNode(Statement)); | ||
export class ImportEqualsDeclaration extends ImportEqualsDeclarationBase<ts.ImportEqualsDeclaration> { | ||
/** | ||
* Gets the module reference of the import equals declaration. | ||
*/ | ||
getModuleReference(): ModuleReference { | ||
return this.getNodeFromCompilerNode(this.compilerNode.moduleReference) as ModuleReference; | ||
} | ||
} |
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,7 +1,9 @@ | ||
export * from "./ExportAssignment"; | ||
export * from "./ExportDeclaration"; | ||
export * from "./ExportSpecifier"; | ||
export * from "./ExternalModuleReference"; | ||
export * from "./FileSystemRefreshResult"; | ||
export * from "./ImportDeclaration"; | ||
export * from "./ImportEqualsDeclaration"; | ||
export * from "./ImportSpecifier"; | ||
export * from "./SourceFile"; |
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,27 @@ | ||
import {expect} from "chai"; | ||
import * as ts from "typescript"; | ||
import {ExternalModuleReference} from "./../../../compiler"; | ||
import * as errors from "./../../../errors"; | ||
import {getInfoFromTextWithDescendant} from "./../testHelpers"; | ||
|
||
describe(nameof(ExternalModuleReference), () => { | ||
function getNode(text: string) { | ||
return getInfoFromTextWithDescendant<ExternalModuleReference>(text, ts.SyntaxKind.ExternalModuleReference); | ||
} | ||
|
||
// I'm not sure how to make expression null | ||
|
||
describe(nameof<ExternalModuleReference>(n => n.getExpression), () => { | ||
it("should get the expression", () => { | ||
const {descendant} = getNode("import test = require('expression');"); | ||
expect(descendant.getExpression()!.getText()).to.equal("'expression'"); | ||
}); | ||
}); | ||
|
||
describe(nameof<ExternalModuleReference>(n => n.getExpressionOrThrow), () => { | ||
it("should get the expression", () => { | ||
const {descendant} = getNode("import test = require('expression');"); | ||
expect(descendant.getExpressionOrThrow().getText()).to.equal("'expression'"); | ||
}); | ||
}); | ||
}); |
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,43 @@ | ||
import {expect} from "chai"; | ||
import {ImportEqualsDeclaration} from "./../../../compiler"; | ||
import {getInfoFromText} from "./../testHelpers"; | ||
|
||
describe(nameof(ImportEqualsDeclaration), () => { | ||
describe(nameof<ImportEqualsDeclaration>(n => n.getName), () => { | ||
function doTest(text: string, expected: string) { | ||
const {firstChild} = getInfoFromText<ImportEqualsDeclaration>(text); | ||
expect(firstChild.getName()).to.equal(expected); | ||
} | ||
|
||
it("should get the name", () => { | ||
doTest("import test = Namespace.Test;", "test"); | ||
}); | ||
}); | ||
|
||
describe(nameof<ImportEqualsDeclaration>(n => n.getModuleReference), () => { | ||
function doTest(text: string, expected: string) { | ||
const {firstChild} = getInfoFromText<ImportEqualsDeclaration>(text); | ||
expect(firstChild.getModuleReference().getText()).to.equal(expected); | ||
} | ||
|
||
it("should get the module reference when specifying an entity", () => { | ||
doTest("import test = Namespace.Test;", "Namespace.Test"); | ||
}); | ||
|
||
it("should get the module specifier when importing a require", () => { | ||
doTest(`import test = require("testing");`, `require("testing")`); | ||
}); | ||
}); | ||
|
||
describe(nameof<ImportEqualsDeclaration>(d => d.remove), () => { | ||
function doTest(text: string, index: number, expectedText: string) { | ||
const {sourceFile} = getInfoFromText(text); | ||
(sourceFile.getStatements()[index] as ImportEqualsDeclaration).remove(); | ||
expect(sourceFile.getFullText()).to.equal(expectedText); | ||
} | ||
|
||
it("should remove the import equals declaration", () => { | ||
doTest("import test = Namespace.Test;", 0, ""); | ||
}); | ||
}); | ||
}); |
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