Commit 013205f
Remove globalThis for keyword resolution in runtime template() (#21254)
* Remove globalThis usage for keyword resolution in runtime template()
Instead of storing keywords on globalThis (which collides when multiple
ember-source instances exist on a page), provide keyword values through
the template evaluator:
- For the eval form: wrap the compiled source in a function that receives
keyword values as parameters while preserving access to the caller's
lexical scope via direct eval
- For the scope form: merge keywords into the resolved scope (already
worked, just needed the globalThis removal)
- For neither: inject keywords via new Function parameters
The auto-import-builtins AST plugin no longer rewrites keyword references
at runtime since lexicalScope now returns true for keywords, causing
hasLocal() to return true and skip the rewrite.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* Use WeakMap for compile state, fix lint issues
Replace module-level _compileState mutable with a WeakMap keyed on the
options object. This prevents state leaking between template() calls and
ensures entries are GC'd when the options object is no longer referenced.
Also removes unused EmberPrecompileOptions import and fixes prettier
formatting.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* Simplify: use auto-import-builtins rewrite with __keywords__ container
Instead of making lexicalScope return true for each keyword and tracking
which ones need injection, let auto-import-builtins rewrite keyword
references to __keywords__.on (pointing at our keywords object) and
inject a single __keywords__ container variable into the evaluation scope.
This eliminates the WeakMap side channel entirely and restores the
original buildEvaluator-before-compilation ordering. The only evaluator
change is injecting one extra scope variable (__keywords__) that holds
the keywords object.
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* Rename __keywords__ to __ember_keywords__
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* Rename KEYWORDS_VAR to RUNTIME_KEYWORDS_NAME
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
* Fix prettier formatting
Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
---------
Co-authored-by: NullVoxPopuli <[email protected]>
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>1 parent a5c1907 commit 013205f
3 files changed
Lines changed: 46 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
| 296 | + | |
296 | 297 | | |
297 | 298 | | |
298 | 299 | | |
| |||
384 | 385 | | |
385 | 386 | | |
386 | 387 | | |
387 | | - | |
| 388 | + | |
Lines changed: 24 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
20 | 27 | | |
21 | 28 | | |
22 | 29 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
| |||
45 | 49 | | |
46 | 50 | | |
47 | 51 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | 52 | | |
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
57 | 56 | | |
58 | 57 | | |
59 | | - | |
| 58 | + | |
60 | 59 | | |
61 | 60 | | |
62 | 61 | | |
| |||
65 | 64 | | |
66 | 65 | | |
67 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
68 | 73 | | |
69 | 74 | | |
70 | 75 | | |
| |||
82 | 87 | | |
83 | 88 | | |
84 | 89 | | |
85 | | - | |
| 90 | + | |
| 91 | + | |
86 | 92 | | |
87 | 93 | | |
88 | 94 | | |
89 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
90 | 102 | | |
91 | 103 | | |
92 | 104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
265 | 265 | | |
266 | 266 | | |
267 | 267 | | |
268 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
269 | 281 | | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | 282 | | |
275 | 283 | | |
276 | 284 | | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
277 | 290 | | |
278 | 291 | | |
279 | 292 | | |
280 | | - | |
| 293 | + | |
281 | 294 | | |
282 | 295 | | |
283 | 296 | | |
| |||
0 commit comments