feat(macro): throw useful error message if macro used without a plugin#1355
Merged
Martin005 merged 1 commit intoJan 25, 2023
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
Martin005
suggested changes
Jan 25, 2023
Comment on lines
+153
to
+166
| const macros = [ | ||
| 'defineMessage', | ||
| 'arg', | ||
| 't', | ||
| 'plural', | ||
| 'select', | ||
| 'selectOrdinal', | ||
|
|
||
| // jsx | ||
| 'Trans', | ||
| 'Plural', | ||
| 'Select', | ||
| 'SelectOrdinal', | ||
| ]; |
Contributor
There was a problem hiding this comment.
I don't think it is a good idea to have two identical lists of tag names (the other is in the getMacroType function). Please merge these two concepts into a dictionary, update the forEach below, remove the getMacroType function and update getting the macro type on the line 43.
| @@ -149,3 +149,29 @@ function getMacroType(tagName: string): string { | |||
| } | |||
|
|
|||
| export default createMacro(macro) | |||
Contributor
There was a problem hiding this comment.
I think that this export statement should be at the end of file.
| throw new Error(`The macro you imported from "@lingui/macro" is being executed outside the context of compilation with babel-plugin-macros. ` | ||
| + `This indicates that you don't have the babel plugin "babel-plugin-macros" configured correctly. ` | ||
| + `Please see the documentation for how to configure babel-plugin-macros properly: ` | ||
| + 'https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md'); |
Contributor
There was a problem hiding this comment.
Suggested change
| + 'https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md'); | |
| + 'https://github.com/kentcdodds/babel-plugin-macros/blob/main/other/docs/user.md'); |
| return (mod as unknown as typeof import('@lingui/macro')).Trans | ||
| } | ||
| ).rejects.toThrowErrorMatchingInlineSnapshot( | ||
| `The macro you imported from "@lingui/macro" is being executed outside the context of compilation with babel-plugin-macros. This indicates that you don't have the babel plugin "babel-plugin-macros" configured correctly. Please see the documentation for how to configure babel-plugin-macros properly: https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md` |
Contributor
There was a problem hiding this comment.
Suggested change
| `The macro you imported from "@lingui/macro" is being executed outside the context of compilation with babel-plugin-macros. This indicates that you don't have the babel plugin "babel-plugin-macros" configured correctly. Please see the documentation for how to configure babel-plugin-macros properly: https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/user.md` | |
| `The macro you imported from "@lingui/macro" is being executed outside the context of compilation with babel-plugin-macros. This indicates that you don't have the babel plugin "babel-plugin-macros" configured correctly. Please see the documentation for how to configure babel-plugin-macros properly: https://github.com/kentcdodds/babel-plugin-macros/blob/main/other/docs/user.md` |
8201664 to
b54270e
Compare
b54270e to
a1c77ff
Compare
Collaborator
Author
|
@Martin005 done |
Martin005
reviewed
Jan 25, 2023
Martin005
approved these changes
Jan 25, 2023
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No description provided.