-
Notifications
You must be signed in to change notification settings - Fork 382
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
feat(macro): throw useful error message if macro used without a plugin #1355
feat(macro): throw useful error message if macro used without a plugin #1355
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
packages/macro/src/index.ts
Outdated
const macros = [ | ||
'defineMessage', | ||
'arg', | ||
't', | ||
'plural', | ||
'select', | ||
'selectOrdinal', | ||
|
||
// jsx | ||
'Trans', | ||
'Plural', | ||
'Select', | ||
'SelectOrdinal', | ||
]; |
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 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.
packages/macro/src/index.ts
Outdated
@@ -149,3 +149,29 @@ function getMacroType(tagName: string): string { | |||
} | |||
|
|||
export default createMacro(macro) |
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 think that this export statement should be at the end of file.
packages/macro/src/index.ts
Outdated
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'); |
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.
+ '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'); |
packages/macro/test/index.ts
Outdated
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` |
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.
`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
@Martin005 done |
No description provided.