-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Constructor Visibility #6885
Merged
mhegazy
merged 18 commits into
microsoft:master
from
AbubakerB:constructorAccessibility
Feb 17, 2016
+1,184
−135
Merged
Constructor Visibility #6885
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
f869b41
Added private and protected modifiers to constructors
AbubakerB c351ffc
Added and updated tests for constructor visibility
AbubakerB bbf92ce
Added constructor visibility in the declaration emitter
AbubakerB 3d529a8
Update baselines
AbubakerB 4200051
Addressed PR feedback.
AbubakerB 4c93eb2
Accept baselines
AbubakerB 5ce0202
Refactored visibility text on modifier grammar check
AbubakerB 16b54e0
Addressed PR. Diagnostic messages
AbubakerB 037b657
Accept baselines
AbubakerB a6a5a22
Addressed PR
AbubakerB d0843e1
Merge branch 'ts-master' into constructorAccessibility
AbubakerB 8ef9599
Allow extending and instantiating a private or protected class within…
AbubakerB ec7e80e
Added tests and accept baselines
AbubakerB 91ea83c
Addressed PR
AbubakerB 208830e
Updated tests and accepted baseline
AbubakerB 2d7a0f4
Merge branch 'master' into constructorAccessibility
AbubakerB ba8b168
Included previously ignored baseline .js file and slight refactoring
AbubakerB de23e2f
Merge branch 'master' into constructorAccessibility
AbubakerB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
=== tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts === | ||
class C { | ||
>C : Symbol(C, Decl(Protected3.ts, 0, 0)) | ||
|
||
protected constructor() { } | ||
} |
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,6 @@ | ||
=== tests/cases/conformance/parser/ecmascript5/Protected/Protected3.ts === | ||
class C { | ||
>C : C | ||
|
||
protected constructor() { } | ||
} |
41 changes: 21 additions & 20 deletions
41
tests/baselines/reference/classConstructorAccessibility.errors.txt
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,49 +1,50 @@ | ||
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(6,5): error TS1089: 'private' modifier cannot appear on a constructor declaration. | ||
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(10,5): error TS1089: 'protected' modifier cannot appear on a constructor declaration. | ||
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(23,9): error TS1089: 'private' modifier cannot appear on a constructor declaration. | ||
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(27,9): error TS1089: 'protected' modifier cannot appear on a constructor declaration. | ||
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(15,9): error TS2673: Constructor of class 'D' is private and only accessible within the class declaration. | ||
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(16,9): error TS2674: Constructor of class 'E' is protected and only accessible within the class declaration. | ||
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(32,13): error TS2673: Constructor of class 'D<T>' is private and only accessible within the class declaration. | ||
tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(33,13): error TS2674: Constructor of class 'E<T>' is protected and only accessible within the class declaration. | ||
|
||
|
||
==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts (4 errors) ==== | ||
|
||
class C { | ||
public constructor(public x: number) { } | ||
} | ||
|
||
class D { | ||
private constructor(public x: number) { } // error | ||
~~~~~~~ | ||
!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. | ||
private constructor(public x: number) { } | ||
} | ||
|
||
class E { | ||
protected constructor(public x: number) { } // error | ||
~~~~~~~~~ | ||
!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration. | ||
protected constructor(public x: number) { } | ||
} | ||
|
||
var c = new C(1); | ||
var d = new D(1); | ||
var e = new E(1); | ||
var d = new D(1); // error | ||
~~~~~~~~ | ||
!!! error TS2673: Constructor of class 'D' is private and only accessible within the class declaration. | ||
var e = new E(1); // error | ||
~~~~~~~~ | ||
!!! error TS2674: Constructor of class 'E' is protected and only accessible within the class declaration. | ||
|
||
module Generic { | ||
class C<T> { | ||
public constructor(public x: T) { } | ||
} | ||
|
||
class D<T> { | ||
private constructor(public x: T) { } // error | ||
~~~~~~~ | ||
!!! error TS1089: 'private' modifier cannot appear on a constructor declaration. | ||
private constructor(public x: T) { } | ||
} | ||
|
||
class E<T> { | ||
protected constructor(public x: T) { } // error | ||
~~~~~~~~~ | ||
!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration. | ||
protected constructor(public x: T) { } | ||
} | ||
|
||
var c = new C(1); | ||
var d = new D(1); | ||
var e = new E(1); | ||
var d = new D(1); // error | ||
~~~~~~~~ | ||
!!! error TS2673: Constructor of class 'D<T>' is private and only accessible within the class declaration. | ||
var e = new E(1); // error | ||
~~~~~~~~ | ||
!!! error TS2674: Constructor of class 'E<T>' is protected and only accessible within the class declaration. | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't get rid of the
if
, please add an explicitreturn
statement.