mirror of
https://github.com/oxc-project/oxc.git
synced 2026-09-14 19:36:11 +08:00
d89ae8f012
Fixes #20700. Patch global `WeakMap` before loading plugins to make a `WeakMap` keyed by `context.sourceCode` act as if every file has a unique `context.sourceCode`. The runtime cost of this patch is very low - for the use case of `WeakMap` keyed by `SourceCode`, it should be *faster* than an actual `WeakMap`, as no methods do actual hash map lookups. The implementation takes care not to leak memory even if plugins use `WeakMap`s extensively or in pathological patterns. I rebased #20611 on top of this, and after this PR, 100% of `eslint-plugin-mocha`'s conformance tests pass. It's pretty hacky to be patching globals, but I believe the implementation to be robust. My rationale for this solution is explained in detail in #20700.
2.1 KiB
2.1 KiB
Exit code
1
stdout
x weakmap-cache-plugin(cache1): Rules which have accessed this file:
| filename: <fixture>/files/1.js
| ident names: a, a, a
| rule names: cache1, cache2, cache3
,-[files/1.js:1:1]
1 | let a;
: ^^^^^^^
`----
x weakmap-cache-plugin(cache2): Rules which have accessed this file:
| filename: <fixture>/files/1.js
| ident names: a, a, a
| rule names: cache1, cache2, cache3
,-[files/1.js:1:1]
1 | let a;
: ^^^^^^^
`----
x weakmap-cache-plugin(cache3): Rules which have accessed this file:
| filename: <fixture>/files/1.js
| ident names: a, a, a
| rule names: cache1, cache2, cache3
,-[files/1.js:1:1]
1 | let a;
: ^^^^^^^
`----
x weakmap-cache-plugin(cache1): Rules which have accessed this file:
| filename: <fixture>/files/2.js
| ident names: b, b, b
| rule names: cache1, cache2, cache3
,-[files/2.js:1:1]
1 | let b;
: ^^^^^^^
`----
x weakmap-cache-plugin(cache2): Rules which have accessed this file:
| filename: <fixture>/files/2.js
| ident names: b, b, b
| rule names: cache1, cache2, cache3
,-[files/2.js:1:1]
1 | let b;
: ^^^^^^^
`----
x weakmap-cache-plugin(cache3): Rules which have accessed this file:
| filename: <fixture>/files/2.js
| ident names: b, b, b
| rule names: cache1, cache2, cache3
,-[files/2.js:1:1]
1 | let b;
: ^^^^^^^
`----
x weakmap-cache-plugin(cache1): Rules which have accessed this file:
| filename: <fixture>/files/3.js
| ident names: c, c, c
| rule names: cache1, cache2, cache3
,-[files/3.js:1:1]
1 | let c;
: ^^^^^^^
`----
x weakmap-cache-plugin(cache2): Rules which have accessed this file:
| filename: <fixture>/files/3.js
| ident names: c, c, c
| rule names: cache1, cache2, cache3
,-[files/3.js:1:1]
1 | let c;
: ^^^^^^^
`----
x weakmap-cache-plugin(cache3): Rules which have accessed this file:
| filename: <fixture>/files/3.js
| ident names: c, c, c
| rule names: cache1, cache2, cache3
,-[files/3.js:1:1]
1 | let c;
: ^^^^^^^
`----
Found 0 warnings and 9 errors.
Finished in Xms on 3 files with 3 rules using X threads.
stderr