refactor(linter/plugins): convert global properties to vars with TSDown plugin, instead of manually#16961
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. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
This PR refactors the codebase to eliminate manual destructuring of global object properties in favor of an automated TSDown plugin transformation. The plugin converts direct usage of properties like Object.keys() into imports of optimized global variables (e.g., ObjectKeys) from a centralized utils/globals.ts file, improving both performance and bundle size.
Key changes:
- Implements a new TSDown plugin (
createReplaceGlobalsPlugin) that automatically transforms global property accesses - Creates a centralized
utils/globals.tsfile exporting commonly-used global properties as variables - Removes manual destructuring patterns from all source files
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| apps/oxlint/tsdown.config.ts | Adds the new createReplaceGlobalsPlugin with AST transformation logic and integrates it into the build pipeline |
| apps/oxlint/src-js/utils/globals.ts | New file centralizing exports of global object properties as optimized variables |
| apps/oxlint/src-js/plugins/visitor.ts | Removes manual ObjectKeys destructuring; reverts to direct Object.keys() usage |
| apps/oxlint/src-js/plugins/tokens.ts | Removes manual Math.max/min destructuring; reverts to direct usage |
| apps/oxlint/src-js/plugins/source_code.ts | Removes manual Math.max destructuring; reverts to direct usage |
| apps/oxlint/src-js/plugins/selector.ts | Removes manual ObjectKeys destructuring; reverts to direct usage |
| apps/oxlint/src-js/plugins/report.ts | Removes manual Object.hasOwn/keys destructuring; reverts to direct usage |
| apps/oxlint/src-js/plugins/options.ts | Removes manual destructuring of Object, Array, and Math methods; reverts to direct usage |
| apps/oxlint/src-js/plugins/location.ts | Removes manual Object.defineProperty and Array.isArray destructuring; reverts to direct usage |
| apps/oxlint/src-js/plugins/load.ts | Removes manual destructuring of Object.keys, Array.isArray, and JSON methods; reverts to direct usage |
| apps/oxlint/src-js/plugins/json.ts | Removes manual Array.isArray and Object.freeze destructuring; reverts to direct usage |
| apps/oxlint/src-js/plugins/globals.ts | Removes manual Object.freeze and Array.isArray destructuring; reverts to direct usage |
| apps/oxlint/src-js/plugins/fix.ts | Removes manual destructuring of Array, Object, Reflect, and Symbol properties; reverts to direct usage |
| apps/oxlint/src-js/plugins/context.ts | Removes manual destructuring of Object methods; reverts to direct usage |
| apps/oxlint/src-js/package/rule_tester.ts | Removes manual destructuring of Object.hasOwn, Array.isArray, and JSON.stringify; reverts to direct usage |
| apps/oxlint/src-js/package/define.ts | Removes manual destructuring of multiple Object methods; reverts to direct usage |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6a77d23 to
e88c42b
Compare
1abbb33 to
1351d60
Compare
1351d60 to
1a6536f
Compare
e88c42b to
0cbd88c
Compare
1a6536f to
d827a4a
Compare
Merge activity
|
…wn plugin, instead of manually (#16961) Previously we had a pattern of destructuring properties of global objects into top-level vars. e.g.: ```js const { keys: ObjectKeys, hasOwn } = Object, { isArray } = Array; ``` Doing this is more performant, but it makes the code harder to read. Instead, write code normally, and use a TSDown plugin to convert: ```js const keys = Object.keys(obj); ``` to: ```js import { ObjectKeys } from "../utils/globals.ts"; const keys = ObjectKeys(obj); ``` Defining all the destructured globals in a single file (`utils/globals.ts`) is advantageous for bundle size. If the TSDown plugin created top level `const ObjectKeys = Object.keys;` statements in each file, then you can end up with this in bundle as minifier doesn't de-duplicate: ```js const ObjectKeys = Object.keys; const ObjectKeys$1 = Object.keys; const ObjectKeys$2 = Object.keys; ``` The globals we use have to be manually added to `utils/globals.ts`, but TSDown plugin warns when this needs to be done, and doesn't generate a broken build in the meantime. This plugin is run in debug builds too, so that the tests will catch any bugs.
d827a4a to
da509be
Compare
Follow-on after #16961. Just fix a typo in a comment.
…wn plugin, instead of manually (oxc-project#16961) Previously we had a pattern of destructuring properties of global objects into top-level vars. e.g.: ```js const { keys: ObjectKeys, hasOwn } = Object, { isArray } = Array; ``` Doing this is more performant, but it makes the code harder to read. Instead, write code normally, and use a TSDown plugin to convert: ```js const keys = Object.keys(obj); ``` to: ```js import { ObjectKeys } from "../utils/globals.ts"; const keys = ObjectKeys(obj); ``` Defining all the destructured globals in a single file (`utils/globals.ts`) is advantageous for bundle size. If the TSDown plugin created top level `const ObjectKeys = Object.keys;` statements in each file, then you can end up with this in bundle as minifier doesn't de-duplicate: ```js const ObjectKeys = Object.keys; const ObjectKeys$1 = Object.keys; const ObjectKeys$2 = Object.keys; ``` The globals we use have to be manually added to `utils/globals.ts`, but TSDown plugin warns when this needs to be done, and doesn't generate a broken build in the meantime. This plugin is run in debug builds too, so that the tests will catch any bugs.
Follow-on after oxc-project#16961. Just fix a typo in a comment.

Previously we had a pattern of destructuring properties of global objects into top-level vars. e.g.:
Doing this is more performant, but it makes the code harder to read.
Instead, write code normally, and use a TSDown plugin to convert:
to:
Defining all the destructured globals in a single file (
utils/globals.ts) is advantageous for bundle size. If the TSDown plugin created top levelconst ObjectKeys = Object.keys;statements in each file, then you can end up with this in bundle as minifier doesn't de-duplicate:The globals we use have to be manually added to
utils/globals.ts, but TSDown plugin warns when this needs to be done, and doesn't generate a broken build in the meantime.This plugin is run in debug builds too, so that the tests will catch any bugs.