chore(TypeScript): refactor objects into classes

fix: `Nil`(null, undefined) now renders as empty string
change: `parser.parseValue()` renamed to `parser.parseOutput`
change: registered tags/filters become static and shared across different liquid instances
This commit is contained in:
harttle
2019-02-17 04:55:30 +08:00
parent b51b0dabca
commit 677e8511e6
134 changed files with 3327 additions and 3858 deletions
+5 -9
View File
@@ -1,4 +1,5 @@
import * as _ from './underscore'
import Token from 'src/parser/token'
function captureStack () {
if (Error.captureStackTrace) {
@@ -13,8 +14,8 @@ abstract class LiquidError {
message: string
name: string
stack: string
token: any
originalError: any
token: Token
originalError: Error
constructor(err, token) {
this.input = token.input
this.line = token.line
@@ -66,6 +67,7 @@ RenderError.prototype.constructor = RenderError
export class RenderBreakError {
message: string
resolvedHTML: string
constructor (message) {
captureStack.call(this)
this.message = message + ''
@@ -93,7 +95,7 @@ function mkContext (input, targetLine) {
.range(begin, end + 1)
.map(lineNumber => {
const indicator = (lineNumber === targetLine) ? '>> ' : ' '
const num = padStart(String(end).length, lineNumber)
const num = _.padStart(String(lineNumber), String(end).length)
const text = lines[lineNumber - 1]
return `${indicator}${num}| ${text}`
})
@@ -112,9 +114,3 @@ function mkMessage (msg, token) {
}
return msg
}
function padStart (length, str) {
str = String(str)
const blank = Array(length - str.length).join(' ')
return blank + str
}