mirror of
https://github.com/harttle/liquidjs.git
synced 2026-09-17 05:10:40 -07:00
style: introduce @typescript-eslint/recommended
This commit is contained in:
@@ -2,7 +2,7 @@ import Token from './token'
|
||||
import { last } from '../util/underscore'
|
||||
|
||||
export default class DelimitedToken extends Token {
|
||||
constructor (
|
||||
public constructor (
|
||||
raw: string,
|
||||
value: string,
|
||||
input: string,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import Token from './token'
|
||||
|
||||
export default class HTMLToken extends Token {
|
||||
constructor (str: string, input: string, line: number, col: number, file?: string) {
|
||||
public constructor (str: string, input: string, line: number, col: number, file?: string) {
|
||||
super(str, input, line, col, file)
|
||||
this.type = 'html'
|
||||
this.value = str
|
||||
}
|
||||
static is (token: Token): token is HTMLToken {
|
||||
public static is (token: Token): token is HTMLToken {
|
||||
return token.type === 'html'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import Token from './token'
|
||||
import { NormalizedFullOptions } from '../liquid-options'
|
||||
|
||||
export default class OutputToken extends DelimitedToken {
|
||||
constructor (
|
||||
public constructor (
|
||||
raw: string,
|
||||
value: string,
|
||||
input: string,
|
||||
@@ -15,7 +15,7 @@ export default class OutputToken extends DelimitedToken {
|
||||
super(raw, value, input, line, pos, options.trimOutputLeft, options.trimOutputRight, file)
|
||||
this.type = 'output'
|
||||
}
|
||||
static is (token: Token): token is OutputToken {
|
||||
public static is (token: Token): token is OutputToken {
|
||||
return token.type === 'output'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,19 +2,19 @@ import Token from '../parser/token'
|
||||
import ITemplate from '../template/itemplate'
|
||||
import TagToken from './tag-token'
|
||||
|
||||
type ParseToken = ((token: Token, remainTokens: Array<Token>) => ITemplate)
|
||||
type ParseToken = ((token: Token, remainTokens: Token[]) => ITemplate)
|
||||
|
||||
export default class ParseStream {
|
||||
private tokens: Array<Token>
|
||||
private tokens: Token[]
|
||||
private handlers: {[key: string]: (arg: any) => void} = {}
|
||||
private stopRequested: boolean = false
|
||||
private parseToken: ParseToken
|
||||
|
||||
constructor (tokens: Array<Token>, parseToken: ParseToken) {
|
||||
public constructor (tokens: Token[], parseToken: ParseToken) {
|
||||
this.tokens = tokens
|
||||
this.parseToken = parseToken
|
||||
}
|
||||
on<T extends ITemplate | Token | undefined> (name: string, cb: (arg: T) => void): ParseStream {
|
||||
public on<T extends ITemplate | Token | undefined> (name: string, cb: (arg: T) => void): ParseStream {
|
||||
this.handlers[name] = cb
|
||||
return this
|
||||
}
|
||||
@@ -22,7 +22,7 @@ export default class ParseStream {
|
||||
const h = this.handlers[event]
|
||||
return h ? (h(arg), true) : false
|
||||
}
|
||||
start () {
|
||||
public start () {
|
||||
this.trigger('start')
|
||||
let token: Token | undefined
|
||||
while (!this.stopRequested && (token = this.tokens.shift())) {
|
||||
@@ -36,7 +36,7 @@ export default class ParseStream {
|
||||
if (!this.stopRequested) this.trigger('end')
|
||||
return this
|
||||
}
|
||||
stop () {
|
||||
public stop () {
|
||||
this.stopRequested = true
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -10,12 +10,12 @@ import HTML from '../template/html'
|
||||
import ITemplate from '../template/itemplate'
|
||||
|
||||
export default class Parser {
|
||||
liquid: Liquid
|
||||
private liquid: Liquid
|
||||
|
||||
constructor (liquid: Liquid) {
|
||||
public constructor (liquid: Liquid) {
|
||||
this.liquid = liquid
|
||||
}
|
||||
parse (tokens: Array<Token>) {
|
||||
public parse (tokens: Token[]) {
|
||||
let token
|
||||
const templates: ITemplate[] = []
|
||||
while ((token = tokens.shift())) {
|
||||
@@ -23,7 +23,7 @@ export default class Parser {
|
||||
}
|
||||
return templates
|
||||
}
|
||||
parseToken (token: Token, remainTokens: Array<Token>) {
|
||||
public parseToken (token: Token, remainTokens: Token[]) {
|
||||
try {
|
||||
if (TagToken.is(token)) {
|
||||
return new Tag(token, remainTokens, this.liquid)
|
||||
@@ -36,7 +36,7 @@ export default class Parser {
|
||||
throw new ParseError(e, token)
|
||||
}
|
||||
}
|
||||
parseStream (tokens: Array<Token>) {
|
||||
public parseStream (tokens: Token[]) {
|
||||
return new ParseStream(tokens, (token, tokens) => this.parseToken(token, tokens))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,9 @@ import * as lexical from './lexical'
|
||||
import { NormalizedFullOptions } from '../liquid-options'
|
||||
|
||||
export default class TagToken extends DelimitedToken {
|
||||
name: string
|
||||
args: string
|
||||
constructor (
|
||||
public name: string
|
||||
public args: string
|
||||
public constructor (
|
||||
raw: string,
|
||||
value: string,
|
||||
input: string,
|
||||
@@ -25,7 +25,7 @@ export default class TagToken extends DelimitedToken {
|
||||
this.name = match[1]
|
||||
this.args = match[2]
|
||||
}
|
||||
static is (token: Token): token is TagToken {
|
||||
public static is (token: Token): token is TagToken {
|
||||
return token.type === 'tag'
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,14 +1,14 @@
|
||||
export default class Token {
|
||||
trimLeft: boolean = false
|
||||
trimRight: boolean = false
|
||||
type: string = 'notset'
|
||||
line: number
|
||||
col: number
|
||||
raw: string
|
||||
input: string
|
||||
file?: string
|
||||
value: string
|
||||
constructor (raw: string, input: string, line: number, col: number, file?: string) {
|
||||
public trimLeft: boolean = false
|
||||
public trimRight: boolean = false
|
||||
public type: string = 'notset'
|
||||
public line: number
|
||||
public col: number
|
||||
public raw: string
|
||||
public input: string
|
||||
public file?: string
|
||||
public value: string
|
||||
public constructor (raw: string, input: string, line: number, col: number, file?: string) {
|
||||
this.col = col
|
||||
this.line = line
|
||||
this.raw = raw
|
||||
|
||||
@@ -10,10 +10,10 @@ enum ParseState { HTML, OUTPUT, TAG }
|
||||
|
||||
export default class Tokenizer {
|
||||
private options: NormalizedFullOptions
|
||||
constructor (options?: NormalizedFullOptions) {
|
||||
public constructor (options?: NormalizedFullOptions) {
|
||||
this.options = applyDefault(options)
|
||||
}
|
||||
tokenize (input: string, file?: string) {
|
||||
public tokenize (input: string, file?: string) {
|
||||
const tokens: Token[] = []
|
||||
const {
|
||||
tagDelimiterLeft,
|
||||
|
||||
Reference in New Issue
Block a user