mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-16 21:00:40 -07:00
fix dupe name bug
This commit is contained in:
+3
-1
@@ -36,7 +36,9 @@ module.exports = function (options) {
|
||||
while ((match = valueRE.exec(argList.trim()))) {
|
||||
var v = match[0]
|
||||
var re = new RegExp(`${v}\\s*:`, 'g')
|
||||
re.test(match.input) ? args.push(`'${v}'`) : args.push(v)
|
||||
var keyMatch = re.exec(match.input)
|
||||
var currentMatchIsKey = keyMatch && keyMatch.index === match.index
|
||||
currentMatchIsKey ? args.push(`'${v}'`) : args.push(v)
|
||||
}
|
||||
|
||||
this.name = name
|
||||
|
||||
@@ -54,4 +54,40 @@ describe('filter', function () {
|
||||
filter.construct('foo: 33').render('foo', scope)
|
||||
expect(spy).to.have.been.calledWith('foo', 33)
|
||||
})
|
||||
|
||||
it('should support arguments as named key/values', function () {
|
||||
filter.register('foo', x => x)
|
||||
var f = filter.construct('foo: key1: "literal1", key2: value2');
|
||||
expect(f.name).to.equal('foo')
|
||||
expect(f.args).to.deep.equal([ '\'key1\'', '"literal1"', '\'key2\'', 'value2' ]);
|
||||
})
|
||||
|
||||
it('should support arguments as named key/values with inline literals', function () {
|
||||
filter.register('foo', x => x)
|
||||
var f = filter.construct('foo: "test0", key1: "literal1", key2: value2');
|
||||
expect(f.name).to.equal('foo')
|
||||
expect(f.args).to.deep.equal([ '"test0"', '\'key1\'', '"literal1"', '\'key2\'', 'value2' ]);
|
||||
})
|
||||
|
||||
it('should support arguments as named key/values with inline values', function () {
|
||||
filter.register('foo', x => x)
|
||||
var f = filter.construct('foo: test0, key1: "literal1", key2: value2');
|
||||
expect(f.name).to.equal('foo')
|
||||
expect(f.args).to.deep.equal([ 'test0', '\'key1\'', '"literal1"', '\'key2\'', 'value2' ]);
|
||||
})
|
||||
|
||||
|
||||
it('should support argument values named same as keys', function () {
|
||||
filter.register('foo', x => x)
|
||||
var f = filter.construct('foo: a: a');
|
||||
expect(f.name).to.equal('foo')
|
||||
expect(f.args).to.deep.equal(['\'a\'', 'a'])
|
||||
})
|
||||
|
||||
it('should support argument literals named same as keys', function () {
|
||||
filter.register('foo', x => x)
|
||||
var f = filter.construct('foo: a: "a"');
|
||||
expect(f.name).to.equal('foo')
|
||||
expect(f.args).to.deep.equal(['\'a\'', '"a"'])
|
||||
})
|
||||
})
|
||||
|
||||
+2
-1
@@ -394,6 +394,7 @@ describe('filters', function () {
|
||||
liquid.registerFilter('obj_test', function () {
|
||||
return Array.prototype.slice.call(arguments).join(',')
|
||||
})
|
||||
it('should support object', () => test('{{ "a" | obj_test: k1: "v1", k2: "v2" }}', 'a,k1,v1,k2,v2'))
|
||||
it('should support object', () => test(`{{ "a" | obj_test: k1: "v1", k2: foo }}`, 'a,k1,v1,k2,bar'))
|
||||
it('should support mixed object', () => test(`{{ "a" | obj_test: "something", k1: "v1", k2: foo }}`, 'a,something,k1,v1,k2,bar'))
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user