Skip to content

feat(macro): throw useful error message if macro used without a plugin#1355

Merged
Martin005 merged 1 commit into
lingui:mainfrom
timofei-iatsenko:feature/throw-error-from-macro
Jan 25, 2023
Merged

feat(macro): throw useful error message if macro used without a plugin#1355
Martin005 merged 1 commit into
lingui:mainfrom
timofei-iatsenko:feature/throw-error-from-macro

Conversation

@timofei-iatsenko
Copy link
Copy Markdown
Collaborator

No description provided.

@vercel
Copy link
Copy Markdown

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
Copy Markdown

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 thread packages/macro/src/index.ts Outdated
Comment on lines +153 to +166
const macros = [
'defineMessage',
'arg',
't',
'plural',
'select',
'selectOrdinal',

// jsx
'Trans',
'Plural',
'Select',
'SelectOrdinal',
];
Copy link
Copy Markdown
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.

Comment thread packages/macro/src/index.ts Outdated
@@ -149,3 +149,29 @@ function getMacroType(tagName: string): string {
}

export default createMacro(macro)
Copy link
Copy Markdown
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.

Comment thread 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');
Copy link
Copy Markdown
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');

Comment thread 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`
Copy link
Copy Markdown
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 timofei-iatsenko force-pushed the feature/throw-error-from-macro branch from b54270e to a1c77ff Compare January 25, 2023 10:51
@timofei-iatsenko
Copy link
Copy Markdown
Collaborator Author

@Martin005 done

Comment thread packages/macro/src/index.ts
@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