Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 30, 2025

  • Understand the repository structure and inject functionality
  • Locate relevant code in inject_global_variables.rs
  • Verify existing tests pass
  • Add test case for import.meta and import.meta.foo injection
  • Extend InjectImport to support import.meta as a special case
  • Update dot define replacement logic to handle MetaProperty expressions
  • Run tests and verify the fix works correctly
  • Ensure all existing tests still pass
  • Add comprehensive tests for nested properties and combined cases
  • Merge main branch and resolve conflicts
Original prompt

This section details on the original issue you should resolve

<issue_title>transformer(inject): import.meta and values starting from import.meta are not supported as a key</issue_title>
<issue_description>The following option does not work with inject.

  inject: {
    'import.meta': 'foo',
    'import.meta.foo': 'bar'
  },

Input

console.log(import.meta)
console.log(import.meta.foo)

Actual

console.log(import.meta)
console.log(import.meta.foo)

Expected

import $inject_import_meta from "foo";
import $inject_import_meta_foo from "bar";

console.log($inject_import_meta);
console.log($inject_import_meta_foo);

</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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.

@graphite-app
Copy link
Contributor

graphite-app bot commented Oct 30, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

Copilot AI and others added 2 commits October 30, 2025 10:03
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 AI changed the title [WIP] Fix support for import.meta in inject option feat(transformer): support import.meta injection in inject plugin Oct 30, 2025
Copilot AI requested a review from sapphi-red October 30, 2025 10:09
Copilot finished work on behalf of sapphi-red October 30, 2025 10:09
@github-actions github-actions bot added the C-enhancement Category - New feature or request label Oct 30, 2025
@sapphi-red
Copy link
Member

@copilot rebase the PR and resolve the conflict

Copy link
Contributor Author

Copilot AI commented Oct 30, 2025

@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 finished work on behalf of sapphi-red October 30, 2025 11:56
@sapphi-red
Copy link
Member

@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>
Copy link
Contributor Author

Copilot AI commented Oct 30, 2025

@copilot ok, then merge the main branch and resolve the conflict

Merge completed at c9a5c6d. The main branch has been merged into the PR, and conflicts with the new escaping tests have been resolved. All 23 inject_global_variables tests pass.

Copilot finished work on behalf of sapphi-red October 30, 2025 12:10
Signed-off-by: 翠 <green@sapphi.red>
@github-actions github-actions bot added the A-transformer Area - Transformer / Transpiler label Oct 30, 2025
@sapphi-red sapphi-red marked this pull request as ready for review October 30, 2025 16:10
@sapphi-red sapphi-red changed the title feat(transformer): support import.meta injection in inject plugin feat(transformer_plugins): support import.meta injection in inject plugin Oct 30, 2025
@sapphi-red sapphi-red changed the title feat(transformer_plugins): support import.meta injection in inject plugin feat(transformer_plugins): support import.meta injection in inject_global_variables Oct 30, 2025
Copy link
Contributor

Copilot AI left a 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_defines method in inject_global_variables.rs to handle Expression::MetaProperty nodes
  • Added logic in replace_global_defines.rs to properly match import.meta when checking dot defines
  • Added comprehensive test coverage for various import.meta usage 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.

@sapphi-red sapphi-red merged commit 9d568eb into main Oct 31, 2025
28 checks passed
@sapphi-red sapphi-red deleted the copilot/fix-import-meta-inject branch October 31, 2025 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-transformer Area - Transformer / Transpiler C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

transformer(inject): import.meta and values starting from import.meta are not supported as a key

3 participants