revert(context): plain {} registers and getRegister ||

Registers are only mutated by tag implementations, not templates; keep null-prototype scopes/createScope for push frames.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Yang Jun
2026-05-13 00:40:49 +08:00
co-authored by Cursor
parent a69c3ea2a6
commit 8a3634a3cb
5 changed files with 8 additions and 8 deletions
+2 -2
View File
@@ -13,7 +13,7 @@ export class Context {
* for tags like `{% capture %}` `{% assign %}` to operate
*/
private scopes: Scope[] = [createScope()]
private registers: Record<string, any> = Object.create(null)
private registers = {}
/**
* user passed in scope
* `{% increment %}`, `{% decrement %}` changes this scope,
@@ -49,7 +49,7 @@ export class Context {
this.renderLimit = renderLimit ?? new Limiter('template render', getPerformance().now() + (renderOptions.renderLimit ?? opts.renderLimit))
}
public getRegister<T> (key: string, defaultValue: T = undefined as T): T {
return (this.registers[key] = this.registers[key] ?? defaultValue)
return (this.registers[key] = this.registers[key] || defaultValue)
}
public setRegister (key: string, value: any) {
return (this.registers[key] = value)