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
+5 -5
View File
@@ -13,21 +13,21 @@ export default class Filter {
args: string[]
private static impls: {[key: string]: impl} = {}
constructor (str: string, strict_filters: boolean = false) {
let match = lexical.filterLine.exec(str)
constructor (str: string, strictFilters: boolean = false) {
const match = lexical.filterLine.exec(str)
assert(match, 'illegal filter: ' + str)
const name = match[1]
const argList = match[2] || ''
const impl = Filter.impls[name]
if (!impl && strict_filters) throw new TypeError(`undefined filter: ${name}`)
if (!impl && strictFilters) throw new TypeError(`undefined filter: ${name}`)
this.name = name
this.impl = impl || (x => x)
this.args = this.parseArgs(argList)
}
parseArgs (argList: string): string[] {
let match, args = []
let match; const args = []
while ((match = valueRE.exec(argList.trim()))) {
const v = match[0]
const re = new RegExp(`${v}\\s*:`, 'g')
@@ -42,7 +42,7 @@ export default class Filter {
args.unshift(value)
return this.impl.apply(null, args)
}
static register(name, filter) {
static register (name, filter) {
Filter.impls[name] = filter
}
static clear () {
+2 -3
View File
@@ -1,15 +1,14 @@
import Template from 'src/template/template'
import Scope from 'src/scope/scope'
import ITemplate from 'src/template/itemplate'
import Token from 'src/parser/token'
export default class extends Template implements ITemplate {
str: string
constructor(token: Token) {
constructor (token: Token) {
super(token)
this.str = token.value
}
async render(scope: Scope): Promise<string> {
async render (): Promise<string> {
return this.str
}
}
+4 -3
View File
@@ -3,14 +3,15 @@ import { stringify } from 'src/util/underscore'
import Template from 'src/template/template'
import ITemplate from 'src/template/itemplate'
import Scope from 'src/scope/scope'
import OutputToken from 'src/parser/output-token'
export default class Output extends Template implements ITemplate {
value: Value
constructor(token, strict_filters?) {
constructor (token: OutputToken, strictFilters?: boolean) {
super(token)
this.value = new Value(token.value, strict_filters)
this.value = new Value(token.value, strictFilters)
}
async render(scope: Scope) {
async render (scope: Scope): Promise<string> {
const html = await this.value.value(scope)
return stringify(html)
}
+1 -1
View File
@@ -9,7 +9,7 @@ import { evalValue } from 'src/render/syntax'
*/
export default class Hash {
[key: string]: any
constructor(markup, scope) {
constructor (markup, scope) {
let match
hashCapture.lastIndex = 0
while ((match = hashCapture.exec(markup))) {
+1 -1
View File
@@ -6,5 +6,5 @@ import ITagImpl from './itag-impl'
export default interface ITagImplOptions {
parse?: (this: ITagImpl, token: TagToken, remainingTokens: Array<Token>) => void
render?: (this: ITagImpl, scope: Scope, hash: Hash) => string | Promise<string>
render?: (this: ITagImpl, scope: Scope, hash: Hash) => any | Promise<any>
}
+7 -6
View File
@@ -1,6 +1,6 @@
import { create } from 'src/util/underscore'
import { stringify } from 'src/util/underscore'
import { create, stringify } from 'src/util/underscore'
import assert from 'src/util/assert'
import Scope from 'src/scope/scope'
import ITagImpl from './itag-impl'
import ITagImplOptions from './itag-impl-options'
import Liquid from 'src/liquid'
@@ -8,26 +8,27 @@ import Hash from './hash'
import Template from 'src/template/template'
import ITemplate from 'src/template/itemplate'
import TagToken from 'src/parser/tag-token'
import Token from 'src/parser/token'
export default class Tag extends Template implements ITemplate {
name: string
token: TagToken
private impl: ITagImpl
static impls: object = {}
static impls: { [key: string]: ITagImplOptions } = {}
constructor (token, tokens, liquid: Liquid) {
constructor (token: TagToken, tokens: Token[], liquid: Liquid) {
super(token)
this.name = token.name
const impl = Tag.impls[token.name]
assert(impl, `tag ${token.name} not found`)
this.impl = create(impl)
this.impl = create<ITagImplOptions, ITagImpl>(impl)
this.impl.liquid = liquid
if (this.impl.parse) {
this.impl.parse(token, tokens)
}
}
async render (scope) {
async render (scope: Scope) {
const hash = new Hash(this.token.args, scope)
const impl = this.impl
if (typeof impl.render !== 'function') {
+2 -2
View File
@@ -2,7 +2,7 @@ import Token from 'src/parser/token'
export default class Template {
token: Token;
constructor(token) {
this.token = token;
constructor (token) {
this.token = token
}
}
+3 -3
View File
@@ -7,7 +7,7 @@ import Scope from 'src/scope/scope'
export default class {
initial: any
filters: Array<any>
constructor(str: string, strict_filters?: boolean) {
constructor (str: string, strictFilters?: boolean) {
let match = lexical.matchValue(str)
assert(match, `illegal value string: ${str}`)
@@ -20,9 +20,9 @@ export default class {
}
this.initial = initial
this.filters = filters.map(str => new Filter(str, strict_filters))
this.filters = filters.map(str => new Filter(str, strictFilters))
}
value(scope: Scope) {
value (scope: Scope) {
return this.filters.reduce(
(prev, filter) => filter.render(prev, scope),
evalExp(this.initial, scope))