-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Gracefully handle accessor declarations in ambient classes. #256
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2902,7 +2902,16 @@ module ts { | |
| node.typeParameters = sig.typeParameters; | ||
| node.parameters = sig.parameters; | ||
| node.type = sig.type; | ||
| node.body = parseBody(/* ignoreMissingOpenBrace */ false); | ||
|
|
||
| // A common error is to try to declare an accessor in an ambient class. | ||
| if (inAmbientContext && canParseSemicolon()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when do you report the error for an accessor in an ambient context? That should be done in the parser yes (as it's not gramattically legal)?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, check parser.ts, line 2862 (just 45 lines above this). |
||
| parseSemicolon(); | ||
| node.body = createMissingNode(); | ||
| } | ||
| else { | ||
| node.body = parseBody(/* ignoreMissingOpenBrace */ false); | ||
| } | ||
|
|
||
| return finishNode(node); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,7 @@ | ||
| ==== tests/cases/conformance/parser/ecmascript5/Accessors/parserSetAccessorWithTypeAnnotation1.ts (2 errors) ==== | ||
| ==== tests/cases/conformance/parser/ecmascript5/Accessors/parserSetAccessorWithTypeAnnotation1.ts (1 errors) ==== | ||
| class C { | ||
| set foo(v): number { | ||
| ~~~ | ||
| !!! A 'set' accessor cannot have a return type annotation. | ||
| ~~~~~~ | ||
| !!! A function whose declared type is neither 'void' nor 'any' must return a value or consist of a single 'throw' statement. | ||
| } | ||
| } |
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.
Don't you still need to do this for setters?
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.
Setters don't need to have their bodies checked - they don't return anything.