perf: remove transient strings to reduce memory

This commit is contained in:
harttle
2020-03-14 19:04:18 +08:00
committed by Jun Yang
parent 0f25017d5d
commit 3dfdf982c9
16 changed files with 124 additions and 125 deletions
+8 -8
View File
@@ -6,21 +6,21 @@ import { HTMLToken } from '../../../src/parser/html-token'
describe('Tokenize', function () {
it('should read quoted', () => {
expect(new Tokenizer('"foo" ff').readQuoted()).to.equal('"foo"')
expect(new Tokenizer(' "foo"ff').readQuoted()).to.equal('"foo"')
expect(new Tokenizer('"foo" ff').readQuoted().toString()).to.equal('"foo"')
expect(new Tokenizer(' "foo"ff').readQuoted().toString()).to.equal('"foo"')
})
it('should read property access', () => {
expect(new Tokenizer('a[ b][ "c d" ]').readPropertyAccess()).to.equal('a[b]["c d"]')
expect(new Tokenizer('a.b[c[d.e]]').readPropertyAccess()).to.equal('a.b[c[d.e]]')
expect(new Tokenizer('a[ b][ "c d" ]').readPropertyAccess().toString()).to.equal('a[ b][ "c d" ]')
expect(new Tokenizer('a.b[c[d.e]]').readPropertyAccess().toString()).to.equal('a.b[c[d.e]]')
})
it('should read value', () => {
expect(new Tokenizer('2.33.2').readValue()).to.equal('2.33.2')
expect(new Tokenizer('"foo"a').readValue()).to.equal('"foo"')
expect(new Tokenizer('a[b]["c d"]').readValue()).to.equal('a[b]["c d"]')
expect(new Tokenizer('2.33.2').readValue().toString()).to.equal('2.33.2')
expect(new Tokenizer('"foo"a').readValue().toString()).to.equal('"foo"')
expect(new Tokenizer('a[b]["c d"]').readValue().toString()).to.equal('a[b]["c d"]')
})
it('should read hash', () => {
expect(new Tokenizer('foo: 3').readHash()).to.deep.equal(['foo', '3'])
expect(new Tokenizer(', foo: a[ "bar"]').readHash()).to.deep.equal(['foo', 'a["bar"]'])
expect(new Tokenizer(', foo: a[ "bar"]').readHash()).to.deep.equal(['foo', 'a[ "bar"]'])
})
it('should read hashs', () => {
expect(new Tokenizer(', limit: 3 reverse offset:off').readHashes())
+1 -1
View File
@@ -14,7 +14,7 @@ describe('render', function () {
describe('.renderTemplates()', function () {
it('should render html', async function () {
const scope = new Context()
const token = { type: 'html', content: '<p>' } as Token
const token = { content: '<p>' } as Token
const html = await toThenable(render.renderTemplates([new HTML(token)], scope))
return expect(html).to.equal('<p>')
})
-1
View File
@@ -16,7 +16,6 @@ describe('Tag', function () {
it('should call tag.render', async function () {
const spy = sinon.spy()
const token = {
type: 'tag',
content: 'foo',
args: '',
name: 'foo'