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
+18 -17
View File
@@ -1,46 +1,47 @@
import { assign } from 'src/util/underscore'
import TagToken from './tag-token'
import OutputToken from './output-token'
import HTMLToken from './html-token'
import DelimitedToken from 'src/parser/delimited-token'
import Token from 'src/parser/token'
import TagToken from 'src/parser/tag-token'
import { LiquidOptions } from 'src/liquid-options'
export default function whiteSpaceCtrl (tokens, options) {
export default function whiteSpaceCtrl (tokens: Token[], options: LiquidOptions) {
options = assign({ greedy: true }, options)
let inRaw = false
tokens.forEach((token, i) => {
if (shouldTrimLeft(token, inRaw, options)) {
tokens.forEach((token: Token, i: number) => {
if (shouldTrimLeft(token as DelimitedToken, inRaw, options)) {
trimLeft(tokens[i - 1], options.greedy)
}
if (token.type === 'tag' && token.name === 'raw') inRaw = true
if (token.type === 'tag' && token.name === 'endraw') inRaw = false
if (token.type === 'tag' && (token as TagToken).name === 'raw') inRaw = true
if (token.type === 'tag' && (token as TagToken).name === 'endraw') inRaw = false
if (shouldTrimRight(token, inRaw, options)) {
if (shouldTrimRight(token as DelimitedToken, inRaw, options)) {
trimRight(tokens[i + 1], options.greedy)
}
})
}
function shouldTrimLeft (token, inRaw, options) {
function shouldTrimLeft (token: DelimitedToken, inRaw: boolean, options) {
if (inRaw) return false
if (token.type === 'tag') return token.trim_left || options.trim_tag_left
if (token.type === 'output') return token.trim_left || options.trim_value_left
if (token.type === 'tag') return token.trimLeft || options.trim_tag_left
if (token.type === 'output') return token.trimLeft || options.trim_value_left
}
function shouldTrimRight (token, inRaw, options) {
function shouldTrimRight (token: DelimitedToken, inRaw: boolean, options) {
if (inRaw) return false
if (token.type === 'tag') return token.trim_right || options.trim_tag_right
if (token.type === 'output') return token.trim_right || options.trim_value_right
if (token.type === 'tag') return token.trimRight || options.trim_tag_right
if (token.type === 'output') return token.trimRight || options.trim_value_right
}
function trimLeft (token, greedy) {
function trimLeft (token: Token, greedy: boolean) {
if (!token || token.type !== 'html') return
const rLeft = greedy ? /\s+$/g : /[\t\r ]*$/g
token.value = token.value.replace(rLeft, '')
}
function trimRight (token, greedy) {
function trimRight (token: Token, greedy: boolean) {
if (!token || token.type !== 'html') return
const rRight = greedy ? /^\s+/g : /^[\t\r ]*\n?/g