Skip to content

Commit

Permalink
fix: #262 - Write public keyword when specified.
Browse files Browse the repository at this point in the history
This is a "fix" in the design.
  • Loading branch information
dsherret committed Mar 3, 2018
1 parent 1449cc3 commit 6258c0e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/compiler/base/ScopedNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export interface ScopedNode {
* Sets the scope.
* @param scope - Scope to set to.
*/
setScope(scope: Scope): this;
setScope(scope: Scope | undefined): this;
/**
* Gets if the node has a scope keyword.
*/
Expand All @@ -30,8 +30,8 @@ export function ScopedNode<T extends Constructor<ScopedNodeExtensionType>>(Base:
return scopeableNode.getScopeForNode(this) || Scope.Public;
}

setScope(scope: Scope) {
scopeableNode.setScopeForNode(this, scope === Scope.Public ? undefined : scope);
setScope(scope: Scope | undefined) {
scopeableNode.setScopeForNode(this, scope);
return this;
}

Expand Down
14 changes: 9 additions & 5 deletions src/tests/compiler/base/scopedNodeTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,22 @@ describe(nameof(ScopedNode), () => {
});

describe(nameof<ScopedNode>(d => d.setScope), () => {
function doTest(startText: string, scope: Scope, expectedText: string) {
function doTest(startText: string, scope: Scope | undefined, expectedText: string) {
const {firstChild, firstProperty} = getInfoWithFirstPropertyFromText(startText);
firstProperty.setScope(scope);
expect(firstChild.getText()).to.be.equal(expectedText);
}

it("should clear the scope keyword if set to public", () => {
doTest("class Identifier { private prop: string; }", Scope.Public, "class Identifier { prop: string; }");
it("should clear the scope keyword if set to undefined", () => {
doTest("class Identifier { private prop: string; }", undefined, "class Identifier { prop: string; }");
});

it("should clear the scope keyword if set to public even when public", () => {
doTest("class Identifier { public prop: string; }", Scope.Public, "class Identifier { prop: string; }");
it("should leave the scoppe as is if set to public even when public", () => {
doTest("class Identifier { public prop: string; }", Scope.Public, "class Identifier { public prop: string; }");
});

it("should set the scope keyword to public when specified", () => {
doTest("class Identifier { private prop: string; }", Scope.Public, "class Identifier { public prop: string; }");
});

it("should set the scope keyword to protected when specified", () => {
Expand Down

0 comments on commit 6258c0e

Please sign in to comment.