feat: move filters/tags to instances, fixes #188

This commit is contained in:
harttle
2020-03-03 00:02:29 +08:00
parent f6762078e0
commit df8a919f71
47 changed files with 240 additions and 221 deletions
+7 -6
View File
@@ -3,14 +3,15 @@ import { toThenable } from '../../../src/util/async'
import { Context } from '../../../src/context/context'
import { Output } from '../../../src/template/output'
import { OutputToken } from '../../../src/parser/output-token'
import { Filter } from '../../../src/template/filter/filter'
import { FilterMap } from '../../../src/template/filter/filter-map'
const expect = chai.expect
describe('Output', function () {
const emitter: any = { write: (html: string) => (emitter.html += html), html: '' }
let filters: FilterMap
beforeEach(function () {
Filter.clear()
filters = new FilterMap(false)
emitter.html = ''
})
@@ -18,25 +19,25 @@ describe('Output', function () {
const scope = new Context({
foo: { obj: { arr: ['a', 2] } }
})
const output = new Output({ value: 'foo' } as OutputToken, false)
const output = new Output({ value: 'foo' } as OutputToken, filters)
await toThenable(output.render(scope, emitter))
return expect(emitter.html).to.equal('[object Object]')
})
it('should skip function property', async function () {
const scope = new Context({ obj: { foo: 'foo', bar: (x: any) => x } })
const output = new Output({ value: 'obj' } as OutputToken, false)
const output = new Output({ value: 'obj' } as OutputToken, filters)
await toThenable(output.render(scope, emitter))
return expect(emitter.html).to.equal('[object Object]')
})
it('should respect to .toString()', async () => {
const scope = new Context({ obj: { toString: () => 'FOO' } })
const output = new Output({ value: 'obj' } as OutputToken, false)
const output = new Output({ value: 'obj' } as OutputToken, filters)
await toThenable(output.render(scope, emitter))
return expect(emitter.html).to.equal('FOO')
})
it('should respect to .toString()', async () => {
const scope = new Context({ obj: { toString: () => 'FOO' } })
const output = new Output({ value: 'obj' } as OutputToken, false)
const output = new Output({ value: 'obj' } as OutputToken, filters)
await toThenable(output.render(scope, emitter))
return expect(emitter.html).to.equal('FOO')
})