mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 12:50:38 -07:00
fix: incorrect scope when using assign with for, fixes #115
* remove AssignScope, CaptureScope, IncrementScope, DecrementScope concepts * introduce Scope.environments for decrement/increment * assign to scopes[0] for assign/capture
This commit is contained in:
@@ -21,13 +21,6 @@ describe('tags/assign', function () {
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('10086')
|
||||
})
|
||||
it('should shading rather than overwriting', async function () {
|
||||
const ctx = { foo: 'foo' }
|
||||
const src = '{% assign foo="FOO" %}{{foo}}'
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
expect(html).to.equal('FOO')
|
||||
expect(ctx.foo).to.equal('foo')
|
||||
})
|
||||
it('should assign as array', async function () {
|
||||
const src = '{% assign foo=(1..3) %}{{foo}}'
|
||||
const html = await liquid.parseAndRender(src)
|
||||
@@ -76,4 +69,16 @@ describe('tags/assign', function () {
|
||||
const html = await liquid.parseAndRender(src)
|
||||
return expect(html).to.equal('-6')
|
||||
})
|
||||
describe('scope', function () {
|
||||
it('should read from parent scope', async function () {
|
||||
const src = '{%for a in (1..2)%}{{num}}{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, { num: 1 })
|
||||
return expect(html).to.equal('11')
|
||||
})
|
||||
it('should write to the belonging scope', async function () {
|
||||
const src = '{%for a in (1..2)%}{%assign num = a%}{{a}}{%endfor%} {{num}}'
|
||||
const html = await liquid.parseAndRender(src, { num: 1 })
|
||||
return expect(html).to.equal('12 2')
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -39,19 +39,6 @@ describe('tags/for', function () {
|
||||
const html = await liquid.parseAndRender(src, ctx)
|
||||
return expect(html).to.equal('{"i":0,"length":1}')
|
||||
})
|
||||
describe('scope', function () {
|
||||
it('should read super scope', async function () {
|
||||
const src = '{%for a in (1..2)%}{{num}}{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, { num: 1 })
|
||||
return expect(html).to.equal('11')
|
||||
})
|
||||
it('should write super scope', async function () {
|
||||
const src = '{%for a in (1..2)%}{{num}}{%assign num = 2%}{%endfor%}'
|
||||
const html = await liquid.parseAndRender(src, { num: 1 })
|
||||
return expect(html).to.equal('12')
|
||||
})
|
||||
})
|
||||
|
||||
describe('illegal', function () {
|
||||
it('should reject when for not closed', function () {
|
||||
const src = '{%for c in alpha%}{{c}}'
|
||||
|
||||
Reference in New Issue
Block a user