-
-
Notifications
You must be signed in to change notification settings - Fork 723
feat(transformer_plugins): support import.meta injection in inject_global_variables #15125
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
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. |
Add support for injecting import.meta and import.meta.* keys in the inject plugin.
This allows transforming code like:
console.log(import.meta)
console.log(import.meta.foo)
Into:
import { default as $inject_import_meta } from 'foo';
import { default as $inject_import_meta_foo } from 'bar';
console.log($inject_import_meta);
console.log($inject_import_meta_foo);
Changes:
- Extended replace_dot_defines in inject_global_variables.rs to handle MetaProperty expressions
- Updated is_dot_define in replace_global_defines.rs to recognize import.meta in the object chain
- Added test cases for import.meta and import.meta.foo injection
Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Add additional test cases to demonstrate support for: - import.meta.env.MODE (nested properties) - Combined import.meta and import.meta.foo injection All tests pass, confirming the implementation correctly handles: - Direct import.meta replacement - Single-level property access (import.meta.foo) - Multi-level property access (import.meta.env.MODE) - Multiple import.meta-based injections in the same file Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
|
@copilot rebase the PR and resolve the conflict |
Rebase completed. The branch has been rebased onto the latest main and conflicts with the new escaping tests have been resolved. All tests pass (23 inject_global_variables tests including 4 new import.meta tests). However, I cannot force-push the rebased branch as Git authentication is not available in this environment. The rebase is complete locally at commit 2ca7bb7, and the branch needs to be manually force-pushed to update the PR. |
|
@copilot ok, then merge the main branch and resolve the conflict |
Merged latest main branch into the PR. Resolved conflicts by keeping both the new escaping tests and our import.meta tests. All 23 inject_global_variables tests pass. Co-authored-by: sapphi-red <49056869+sapphi-red@users.noreply.github.com>
Signed-off-by: 翠 <green@sapphi.red>
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.
Pull Request Overview
This PR adds support for handling import.meta expressions in the inject global variables plugin. The changes enable replacement of import.meta and its property accesses (e.g., import.meta.foo, import.meta.env.MODE) with injected imports.
Key changes:
- Extended
replace_dot_definesmethod ininject_global_variables.rsto handleExpression::MetaPropertynodes - Added logic in
replace_global_defines.rsto properly matchimport.metawhen checking dot defines - Added comprehensive test coverage for various
import.metausage patterns
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/oxc_transformer_plugins/tests/integrations/inject_global_variables.rs | Added four test cases covering import.meta, import.meta.foo, import.meta.env.MODE, and combined scenarios |
| crates/oxc_transformer_plugins/src/replace_global_defines.rs | Added MetaProperty handling in the is_dot_define method to match import.meta patterns |
| crates/oxc_transformer_plugins/src/inject_global_variables.rs | Extended replace_dot_defines to handle MetaProperty expressions alongside existing StaticMemberExpression handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
inject_global_variables.rsimport.metaandimport.meta.fooinjectionInjectImportto supportimport.metaas a special caseMetaPropertyexpressionsOriginal prompt
import.metaand values starting fromimport.metaare not supported as a key #15124💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.