mirror of
https://github.com/harttle/liquidjs.git
synced 2026-10-03 09:05:14 -07:00
fixes #88
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@ export const integer = /-?\d+/
|
|||||||
export const number = /-?\d+\.?\d*|\.?\d+/
|
export const number = /-?\d+\.?\d*|\.?\d+/
|
||||||
export const bool = /true|false/
|
export const bool = /true|false/
|
||||||
|
|
||||||
// peoperty access
|
// property access
|
||||||
export const identifier = /[\w-]+[?]?/
|
export const identifier = /[\w-]+[?]?/
|
||||||
export const subscript = new RegExp(`\\[(?:${quoted.source}|[\\w-\\.]+)\\]`)
|
export const subscript = new RegExp(`\\[(?:${quoted.source}|[\\w-\\.]+)\\]`)
|
||||||
export const literal = new RegExp(`(?:${quoted.source}|${bool.source}|${number.source})`)
|
export const literal = new RegExp(`(?:${quoted.source}|${bool.source}|${number.source})`)
|
||||||
|
|||||||
+1
-1
@@ -109,7 +109,7 @@ const Scope = {
|
|||||||
assert(j !== -1, `unbalanced []: ${str}`)
|
assert(j !== -1, `unbalanced []: ${str}`)
|
||||||
name = str.slice(i + 1, j)
|
name = str.slice(i + 1, j)
|
||||||
if (!lexical.isInteger(name)) { // foo[bar] vs. foo[1]
|
if (!lexical.isInteger(name)) { // foo[bar] vs. foo[1]
|
||||||
name = this.get(name)
|
name = String(this.get(name))
|
||||||
}
|
}
|
||||||
push()
|
push()
|
||||||
i = j + 1
|
i = j + 1
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ describe('scope', function () {
|
|||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
ctx = {
|
ctx = {
|
||||||
foo: 'zoo',
|
foo: 'zoo',
|
||||||
|
one: 1,
|
||||||
bar: {
|
bar: {
|
||||||
zoo: 'coo',
|
zoo: 'coo',
|
||||||
'Mr.Smith': 'John',
|
'Mr.Smith': 'John',
|
||||||
@@ -46,6 +47,14 @@ describe('scope', function () {
|
|||||||
expect(scope.propertyAccessSeq('foo[0].bar'))
|
expect(scope.propertyAccessSeq('foo[0].bar'))
|
||||||
.to.deep.equal(['foo', '0', 'bar'])
|
.to.deep.equal(['foo', '0', 'bar'])
|
||||||
})
|
})
|
||||||
|
it('should handle nested access 5', function () {
|
||||||
|
expect(scope.propertyAccessSeq('foo[one].bar'))
|
||||||
|
.to.deep.equal(['foo', '1', 'bar'])
|
||||||
|
})
|
||||||
|
it('should handle nested access 6', function () {
|
||||||
|
expect(scope.propertyAccessSeq('foo[two].bar'))
|
||||||
|
.to.deep.equal(['foo', 'undefined', 'bar'])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('#get()', function () {
|
describe('#get()', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user