-
Notifications
You must be signed in to change notification settings - Fork 397
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
Add babel macros as a replacement for transform plugins #193
Conversation
…t correctly index.js only exports for tests... seems I needed to use src/index.js to export
This is amazing! I'm going to review it asap |
I've just got back from holiday, so let me know if you're fine with how
I've done the first macro and I'll implement the next part ( js macro))
…On Wed, 18 Apr. 2018, 7:15 am Tomáš Ehrlich, ***@***.***> wrote:
This is amazing! I'm going to review it asap
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#193 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AASEqhIltieYnJcBvUiR6jZ_GuRW2PAAks5tpmJcgaJpZM4SvcEs>
.
|
@tricoder42 any comments? |
Hey @mlabrum, I can't believe I left this PR without attention for so long. This is awesome! Are you still interested in writing js macro? I'm thinking that this method should be the default one. After all, there's a lot of confusion how i18n components and methods work and it would be easier to comprehend if all these helpers were macros
Let me know if I can help with anything and please accept my apology for such a late response |
@mlabrum I merged This is pretty good, thank you again! I would like to release it soon and we can work on |
Codecov Report
@@ Coverage Diff @@
## stable-2.x #193 +/- ##
=============================================
+ Coverage 91.39% 91.49% +0.1%
=============================================
Files 41 49 +8
Lines 953 1023 +70
=============================================
+ Hits 871 936 +65
- Misses 82 87 +5
Continue to review full report at Codecov.
|
React macros looks solid. There's an example with integration tests and everything works fine. Thinking about Option 1: i18n in scope (hackish)If we simply assume, there's an const i18n = setupI18n()
t`Hello ${name}`
// becomes
// i18n._("Hello {name}", { name }) Option 2: Macro wrapped in i18n._ (ugly)Another option is more explicit - pass output of macro to const i18n = setupI18n()
i18n._(t`Hello ${name}`)
// should become
// i18n._("Hello {name}", { name }) First, I'm not sure if it's even possible. We're taking a single AST node and returning a list. It may also be a bit confusing, but after all, this is exactly what Option 3: Object member as a macro? (ideal)This would be ideal, but don't think it's possible
but still we need to cover another usecase - custom message ID:
but that could be e.g.:
where |
Final step is to add "dummy" components/methods with proptypes/flowtypes so the auto-completition works correctly even for macros. |
Hey,
I've written an
babel-plugin-macros
implementation of@lingui/babel-plugin-transform-react
based on this issue #86 I'm opening this PR for early feedback to ensure this is the direction that you wanted to go in :)I've taken a few shortcuts as I figured that we would want to support both the
macros
andbabel-plugin-transform-react
implementations, somacros
currently calls the transformer withinbabel-plugin-transform-react
so there's only one implementation of the transformer.Example from one of the test files....
to
TODO:
babel-plugin-transform-react
so the transformer doesn't depend on Import Declarations so I don't needsetImportDeclarations
method... which breaks the babel plugin (and fails the tests :))babel-plugin-lingui-extract-messages
package detectionbabel-plugin-transform-react
to use ES6 modules again ( I changed this when I had some errors in macro, I should be able to revert this change as @lingui has a buildstep to compile this out )react-macro
to build bundlesbabel-plugin-transform-js
@lingui-react
and copy the proptypes overCheers,