Skip to content
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

Merged

Conversation

timofei-iatsenko
Copy link
Collaborator

No description provided.

@vercel
Copy link

vercel bot commented Jan 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
js-lingui ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 25, 2023 at 10:52AM (UTC)

@github-actions
Copy link

github-actions bot commented Jan 22, 2023

size-limit report 📦

Path Size
./packages/core/build/esm/index.js 2.89 KB (0%)
./packages/detect-locale/build/esm/index.js 804 B (0%)
./packages/react/build/esm/index.js 2.61 KB (0%)
./packages/remote-loader/build/esm/index.js 7.37 KB (0%)

Comment on lines 153 to 166
const macros = [
'defineMessage',
'arg',
't',
'plural',
'select',
'selectOrdinal',

// jsx
'Trans',
'Plural',
'Select',
'SelectOrdinal',
];
Copy link
Contributor

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.

@@ -149,3 +149,29 @@ function getMacroType(tagName: string): string {
}

export default createMacro(macro)
Copy link
Contributor

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.

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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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`

@timofei-iatsenko
Copy link
Collaborator Author

@Martin005 done

@Martin005 Martin005 merged commit 7d55904 into lingui:main Jan 25, 2023
@timofei-iatsenko timofei-iatsenko deleted the feature/throw-error-from-macro branch January 25, 2023 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants