fix(context): use null-prototype scope and register objects

Add createScope(); use for bottom scope, spawn default, getAll merge, ctx.push frames, filter loops, include/layout blocks registers, and cycle groups. registers uses Object.create(null) and getRegister uses ??.

For-loop continue register defaults to 0 (not {}): Array.slice coerces plain {} but not null-prototype objects.

Export createScope from the package entry.

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
Yang Jun
2026-05-12 22:50:51 +08:00
co-authored by Cursor
parent 02dcd4e970
commit a69c3ea2a6
11 changed files with 46 additions and 28 deletions
+8
View File
@@ -216,4 +216,12 @@ describe('Context', function () {
expect(ctx.getSync(['foo'])).toEqual('zoo')
})
})
describe('scope storage', function () {
it('should use null prototype for bottom scope', function () {
expect(Object.getPrototypeOf(new Context().bottom())).toBeNull()
})
it('should use null prototype for getAll() merge result', function () {
expect(Object.getPrototypeOf(new Context({ a: 1 }).getAll())).toBeNull()
})
})
})