-
Notifications
You must be signed in to change notification settings - Fork 75
Conversation
Codecov Report
@@ Coverage Diff @@
## master #271 +/- ##
===========================================
+ Coverage 0 93.64% +93.64%
===========================================
Files 0 9 +9
Lines 0 614 +614
Branches 0 99 +99
===========================================
+ Hits 0 575 +575
- Misses 0 39 +39
|
@kevinbarabash Would you please check this out? 😃 |
@@ -2,6 +2,7 @@ test/fixtures/convert/formatting | |||
test/fixtures/convert/imports/named_import_specifier_kind/ | |||
test/fixtures/convert/function-types/predicate03 | |||
test/fixtures/convert/imports/dynamic_import | |||
test/fixtures/convert/decorator/ |
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.
Just for the record, this was added because prettier removed the @observable
from above the markersMapping
in the test when the parser is flow.
Fortunately, it works fine with TypeScript, which is what flow-to-ts uses in the end for formatting with prettier.
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.
Thanks for the PR. It's cool that transform.ts didn't need to be changed. There are maybe a few more test cases that might be worth adding:
- multiple decorators
- decorator on a class
- decorator factories
Just want to chime in that I would benefit quite a lot from this in the conversion of insomnia: Kong/insomnia#3266 For now, we'll be using a minimal implementation of this PR dimitropoulos@41a52dc (I made it a few days ago before this PR existed). We'll need to be using this code in our conversion so it'd be useful if it could be merged soon. I'd be happy to help however possible. |
@dimitropoulos Could you give us some simple examples of the decorators you use and the expected output so we can add them to the tests? |
Done! |
Thankfully we only have exactly one decorator, To pick a random example: https://github.com/Kong/insomnia/blob/develop/packages/insomnia-app/app/ui/components/editors/password-editor.js#L24 |
OK. I added the test for that one too. |
import { observable, computed, action } from "mobx"; | ||
export class Store { | ||
@observable | ||
markersMapping: Map<number, MarkerStore> = new Map(); | ||
|
||
@computed | ||
get filePath(): ?string { | ||
return "/file"; | ||
} | ||
|
||
@action | ||
newMarkerStore(editorId: number) { | ||
return 1; | ||
} | ||
} |
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.
Thanks for simplifying these examples. The could be simpler since the code doesn't have to be semantically valid (in this case the getter doesn't return a value, e.g.
class MyClass {
@property
num: number = 5;
@computed
get foo(): string {}
@action
doSomething() {}
}
What you have is fine for now. No action req'd.
@autoBindMethodsForReact(AUTOBIND_CFG) | ||
class PasswordEditor extends React.PureComponent<Props, State> { |
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.
It seems like the decorator-factory
example already covers this, unless I'm missing something.
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.
I can remove it if you prefer fewer tests, but usually, more tests are better 😄
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.
It's fine. It'd be a different story if the tests took a long time to run, but that isn't the case.
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.
LGTM. Thanks for adding this feature. 🙂
I've published 0.5.1 to npm. |
wow this is great news, now I don't have to publish a fork just for our use-case! thank you all so much! |
This adds decorators support such as for mobx. I have added the test which was taken from a real-world project.
Fixes #143