-
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
15 changed files
with
132 additions
and
108 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,29 @@ | ||
import { ts } from "../../typescript"; | ||
import * as errors from "../../errors"; | ||
import { TypeArgumentedNode } from "../base"; | ||
import { QualifiedName } from "../common"; | ||
import { TypeNode } from "./TypeNode"; | ||
|
||
export const ImportTypeNodeBase = TypeArgumentedNode(TypeNode); | ||
export class ImportTypeNode extends ImportTypeNodeBase<ts.ImportTypeNode> { | ||
/** | ||
* Gets the argument passed into the import type. | ||
*/ | ||
getArgument() { | ||
return this.getNodeFromCompilerNode<TypeNode>(this.compilerNode.argument) | ||
} | ||
|
||
/** | ||
* Gets the qualifier of the import type if it exists or throws | ||
*/ | ||
getQualifierOrThrow() { | ||
return errors.throwIfNullOrUndefined(this.getQualifier(), () => `Expected to find a qualifier for the import type: ${this.getText()}`); | ||
} | ||
|
||
/** | ||
* Gets the qualifier of the import type if it exists or returns undefined. | ||
*/ | ||
getQualifier() { | ||
return this.getNodeFromCompilerNodeIfExists<QualifiedName>(this.compilerNode.qualifier) | ||
} | ||
} |
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,57 @@ | ||
import { expect } from "chai"; | ||
import { ts, SyntaxKind } from "../../../typescript"; | ||
import { ImportTypeNode } from "../../../compiler"; | ||
import { getInfoFromTextWithDescendant } from "../testHelpers"; | ||
|
||
describe(nameof(ImportTypeNode), () => { | ||
function getNode(text: string) { | ||
return getInfoFromTextWithDescendant<ImportTypeNode>(text, SyntaxKind.ImportType); | ||
} | ||
|
||
describe(nameof<ImportTypeNode>(d => d.getArgument), () => { | ||
function doTest(text: string, expected: string) { | ||
const {descendant} = getNode(text); | ||
expect(descendant.getArgument().getText()).to.equal(expected); | ||
} | ||
|
||
it("should get the argument", () => { | ||
doTest("var t: import('testing');", "'testing'"); | ||
}); | ||
}); | ||
|
||
describe(nameof<ImportTypeNode>(d => d.getQualifier), () => { | ||
function doTest(text: string, expected: string | undefined) { | ||
const {descendant} = getNode(text); | ||
if (expected == null) | ||
expect(descendant.getQualifier()).to.be.undefined; | ||
else | ||
expect(descendant.getQualifier()!.getText()).to.equal(expected); | ||
} | ||
|
||
it("should get the qualifier when it exists", () => { | ||
doTest("var t: import('testing').Test;", "Test"); | ||
}); | ||
|
||
it("should be undefined when it doesn't exist", () => { | ||
doTest("var t: import('testing');", undefined); | ||
}); | ||
}); | ||
|
||
describe(nameof<ImportTypeNode>(d => d.getQualifierOrThrow), () => { | ||
function doTest(text: string, expected: string | undefined) { | ||
const {descendant} = getNode(text); | ||
if (expected == null) | ||
expect(() => descendant.getQualifierOrThrow()).to.throw(); | ||
else | ||
expect(descendant.getQualifierOrThrow().getText()).to.equal(expected); | ||
} | ||
|
||
it("should get the qualifier when it exists", () => { | ||
doTest("var t: import('testing').Test;", "Test"); | ||
}); | ||
|
||
it("should be undefined when it doesn't exist", () => { | ||
doTest("var t: import('testing');", undefined); | ||
}); | ||
}); | ||
}); |
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.