-
-
Notifications
You must be signed in to change notification settings - Fork 5.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
Allow context type annotation on getters/setters #9641
Merged
nicolo-ribaudo
merged 2 commits into
babel:master
from
matt-tingen:8069-typescript-getter-setter-this
Mar 6, 2019
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
6 changes: 6 additions & 0 deletions
6
packages/babel-parser/test/fixtures/typescript/function/getter-setter/input.js
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 @@ | ||
const g = { | ||
get m(this: {}) {} | ||
}; | ||
const s = { | ||
set m(this: {}, value) {} | ||
}; |
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.
When the first parameter is(EDIT: I was wrong)this
the new implementation doesn't check the parameters count because the} else if (method.params.length !== paramCount) {
branch is skipped://get prop(this: {}, foo, bar) {}
If we parsed
this
as a function parameter, then this plugin is already enabled (no need to assert). I would prefer to have as few as possible TypeScript-specific logic in theparser/*
files. WDYT about extractionsmethod.kind === "get" ? 0 : 1
to a newgetAccessorsExpectedParamCount(method)
function and overwrite it in the typescript plugin?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.
method.params.length === paramCount + 1
wouldn't be true in that case I guess?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.
Oh right 🤦♂️
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.
@nicolo-ribaudo I have pushed a change for
getGetterSetterExpectedParamCount
. Thanks for suggesting the separation. I hadn't noticed I had the first usage ofthis.expectPlugin("typescript")
.At first, it felt a little odd that the error messages directly reference the required number of params despite that number being abstracted away. I considered extracting a
checkGetterSetterExpectedParamCount
method instead, but didn't find a good way to do so without duplicating logic in the TypeScript plugin. However, I found that there's less of a dissonance if I look at it as the error messages being based on target language andgetGetterSetterExpectedParamCount
being based on the source language, so I'm on board now 😄