chore(TypeScript): fix linting and generate .d.ts

This commit is contained in:
harttle
2019-02-17 18:20:04 +08:00
parent 7ee87008c7
commit fc9ebdb90f
79 changed files with 809 additions and 820 deletions
+1 -1
View File
@@ -25,5 +25,5 @@ export default {
'escape': escape,
'escape_once': str => escape(unescape(str)),
'newline_to_br': v => v.replace(/\n/g, '<br />'),
'strip_html': v => String(v).replace(/<script.*?<\/script>|<!--.*?-->|<style.*?<\/style>|<.*?>/g, ''),
'strip_html': v => String(v).replace(/<script.*?<\/script>|<!--.*?-->|<style.*?<\/style>|<.*?>/g, '')
}
+1 -1
View File
@@ -10,7 +10,7 @@ export default {
return Math.round(v * amp) / amp
},
'plus': bindFixed((v, arg) => Number(v) + Number(arg)),
'times': (v, arg) => v * arg,
'times': (v, arg) => v * arg
}
function getFixed (v) {
+1 -1
View File
@@ -28,5 +28,5 @@ export default {
let ret = arr.slice(0, l).join(' ')
if (arr.length > l) ret += o
return ret
},
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
import { RenderBreakError } from 'src/util/error'
export default {
render: async function (scope) {
render: async function () {
throw new RenderBreakError('break')
}
}
+7 -4
View File
@@ -1,11 +1,14 @@
import assert from 'src/util/assert'
import { identifier } from 'src/parser/lexical'
import { CaptureScope } from 'src/scope/scopes'
import TagToken from 'src/parser/tag-token'
import Token from 'src/parser/token'
import Scope from 'src/scope/scope'
const re = new RegExp(`(${identifier.source})`)
export default {
parse: function (tagToken, remainTokens) {
parse: function (tagToken: TagToken, remainTokens: Token[]) {
const match = tagToken.args.match(re)
assert(match, `${tagToken.args} not valid identifier`)
@@ -13,14 +16,14 @@ export default {
this.templates = []
const stream = this.liquid.parser.parseStream(remainTokens)
stream.on('tag:endcapture', token => stream.stop())
stream.on('tag:endcapture', () => stream.stop())
.on('template', tpl => this.templates.push(tpl))
.on('end', x => {
.on('end', () => {
throw new Error(`tag ${tagToken.raw} not closed`)
})
stream.start()
},
render: async function (scope, hash) {
render: async function (scope: Scope) {
const html = await this.liquid.renderer.renderTemplates(this.templates, scope)
const ctx = new CaptureScope()
ctx[this.variable] = html
+3 -3
View File
@@ -15,16 +15,16 @@ export default {
})
})
.on('tag:else', () => (p = this.elseTemplates))
.on('tag:endcase', token => stream.stop())
.on('tag:endcase', () => stream.stop())
.on('template', tpl => p.push(tpl))
.on('end', x => {
.on('end', () => {
throw new Error(`tag ${tagToken.raw} not closed`)
})
stream.start()
},
render: function (scope, hash) {
render: function (scope) {
for (let i = 0; i < this.cases.length; i++) {
const branch = this.cases[i]
const val = evalExp(branch.val, scope)
+1 -1
View File
@@ -5,7 +5,7 @@ export default {
.on('token', token => {
if (token.name === 'endcomment') stream.stop()
})
.on('end', x => {
.on('end', () => {
throw new Error(`tag ${tagToken.raw} not closed`)
})
stream.start()
+1 -1
View File
@@ -1,7 +1,7 @@
import { RenderBreakError } from 'src/util/error'
export default {
render: async function (scope) {
render: async function () {
throw new RenderBreakError('continue')
}
}
+2 -2
View File
@@ -6,7 +6,7 @@ const groupRE = new RegExp(`^(?:(${rValue.source})\\s*:\\s*)?(.*)$`)
const candidatesRE = new RegExp(rValue.source, 'g')
export default {
parse: function (tagToken, remainTokens) {
parse: function (tagToken) {
let match = groupRE.exec(tagToken.args)
assert(match, `illegal tag: ${tagToken.raw}`)
@@ -21,7 +21,7 @@ export default {
assert(this.candidates.length, `empty candidates: ${tagToken.raw}`)
},
render: function (scope, hash) {
render: function (scope) {
const group = evalValue(this.group, scope)
const fingerprint = `cycle:${group}:` + this.candidates.join(',')
+4 -2
View File
@@ -1,14 +1,16 @@
import assert from 'src/util/assert'
import { identifier } from 'src/parser/lexical'
import { CaptureScope, AssignScope, DecrementScope } from 'src/scope/scopes'
import TagToken from 'src/parser/tag-token'
import Scope from 'src/scope/scope'
export default {
parse: function (token) {
parse: function (token: TagToken) {
const match = token.args.match(identifier)
assert(match, `illegal identifier ${token.args}`)
this.variable = match[0]
},
render: function (scope, hash) {
render: function (scope: Scope) {
let context = scope.findContextFor(
this.variable,
ctx => {
+3 -3
View File
@@ -18,16 +18,16 @@ export default {
})
})
.on('tag:else', () => (p = this.elseTemplates))
.on('tag:endif', token => stream.stop())
.on('tag:endif', () => stream.stop())
.on('template', tpl => p.push(tpl))
.on('end', x => {
.on('end', () => {
throw new Error(`tag ${tagToken.raw} not closed`)
})
stream.start()
},
render: function (scope, hash) {
render: function (scope) {
for (const branch of this.branches) {
const cond = evalExp(branch.cond, scope)
if (isTruthy(cond)) {
+1 -1
View File
@@ -8,7 +8,7 @@ export default {
assert(match, `illegal identifier ${token.args}`)
this.variable = match[0]
},
render: function (scope, hash) {
render: function (scope) {
let context = scope.findContextFor(
this.variable,
ctx => {
+4 -1
View File
@@ -15,7 +15,10 @@ import tablerow from './tablerow'
import unless from './unless'
import Break from './break'
import Continue from './continue'
import ITagImplOptions from 'src/template/tag/itag-impl-options'
export default {
const tags: { [key: string]: ITagImplOptions } = {
assign, 'for': For, capture, 'case': Case, comment, include, decrement, increment, cycle, 'if': If, layout, block, raw, tablerow, unless, 'break': Break, 'continue': Continue
}
export default tags
+1 -1
View File
@@ -13,7 +13,7 @@ export default {
})
stream.start()
},
render: function (scope, hash) {
render: function () {
return this.tokens.map(token => token.raw).join('')
}
}
+2 -2
View File
@@ -19,7 +19,7 @@ export default {
let p
const stream = this.liquid.parser.parseStream(remainTokens)
.on('start', () => (p = this.templates))
.on('tag:endtablerow', token => stream.stop())
.on('tag:endtablerow', () => stream.stop())
.on('template', tpl => p.push(tpl))
.on('end', () => {
throw new Error(`tag ${tagToken.raw} not closed`)
@@ -35,7 +35,7 @@ export default {
collection = collection.slice(offset, offset + limit)
const cols = hash.cols || collection.length
const contexts = collection.map((item, i) => {
const contexts = collection.map(item => {
const ctx = {}
ctx[this.variable] = item
return ctx
+4 -4
View File
@@ -6,21 +6,21 @@ export default {
this.elseTemplates = []
let p
const stream = this.liquid.parser.parseStream(remainTokens)
.on('start', x => {
.on('start', () => {
p = this.templates
this.cond = tagToken.args
})
.on('tag:else', () => (p = this.elseTemplates))
.on('tag:endunless', token => stream.stop())
.on('tag:endunless', () => stream.stop())
.on('template', tpl => p.push(tpl))
.on('end', x => {
.on('end', () => {
throw new Error(`tag ${tagToken.raw} not closed`)
})
stream.start()
},
render: function (scope, hash) {
render: function (scope) {
const cond = evalExp(this.cond, scope)
return isFalsy(cond)
? this.liquid.renderer.renderTemplates(this.templates, scope)