fix: correctly understand variables with question marks

Fixes #77
This commit is contained in:
Ryan Kennedy
2018-07-18 10:15:43 +08:00
committed by Jun Yang
parent 6755462056
commit c79700ef1a
2 changed files with 4 additions and 2 deletions
+1 -1
View File
@@ -10,7 +10,7 @@ var number = /-?\d+\.?\d*|\.?\d+/
var bool = /true|false/
// peoperty access
var identifier = /[\w-]+/
var identifier = /[\w-]+[?]?/
var subscript = new RegExp(`\\[(?:${quoted.source}|[\\w-\\.]+)\\]`)
var literal = new RegExp(`(?:${quoted.source}|${bool.source}|${number.source})`)
var variable = new RegExp(`${identifier.source}(?:\\.${identifier.source}|${subscript.source})*`)
+3 -1
View File
@@ -17,7 +17,8 @@ describe('expression', function () {
empty: '',
x: 'XXX',
y: undefined,
z: null
z: null,
'has_value?': true
})
})
@@ -30,6 +31,7 @@ describe('expression', function () {
it('should eval variables', function () {
expect(evalValue('23', scope)).to.equal(23)
expect(evalValue('one', scope)).to.equal(1)
expect(evalValue('has_value?', scope)).to.equal(true)
expect(evalValue('x', scope)).to.equal('XXX')
})