perf: remove instanceof DelimitedToken

This commit is contained in:
harttle
2020-03-15 02:51:25 +08:00
committed by Jun Yang
parent d2d6a38235
commit 1673e84e27
3 changed files with 20 additions and 15 deletions
+13 -12
View File
@@ -1,14 +1,15 @@
export enum TokenKind { export enum TokenKind {
Number, Number = 1,
Literal, Literal = 2,
Tag, Tag = 4,
Output, Output = 8,
HTML, HTML = 16,
Filter, Filter = 32,
Hash, Hash = 64,
PropertyAccess, PropertyAccess = 128,
Word, Word = 256,
Range, Range = 512,
Quoted, Quoted = 1024,
Operator Operator = 2048,
Delimited = Tag | Output
} }
+2 -3
View File
@@ -1,6 +1,5 @@
import { Token } from '../tokens/token' import { Token } from '../tokens/token'
import { DelimitedToken } from '../tokens/delimited-token' import { isTagToken, isHTMLToken, isDelimitedToken } from '../util/type-guards'
import { isTagToken, isHTMLToken } from '../util/type-guards'
import { NormalizedFullOptions } from '../liquid-options' import { NormalizedFullOptions } from '../liquid-options'
import { TYPES, INLINE_BLANK, BLANK } from '../util/character' import { TYPES, INLINE_BLANK, BLANK } from '../util/character'
@@ -10,7 +9,7 @@ export function whiteSpaceCtrl (tokens: Token[], options: NormalizedFullOptions)
for (let i = 0; i < tokens.length; i++) { for (let i = 0; i < tokens.length; i++) {
const token = tokens[i] const token = tokens[i]
if (!(token instanceof DelimitedToken)) continue if (!isDelimitedToken(token)) continue
if (!inRaw && token.trimLeft) { if (!inRaw && token.trimLeft) {
trimLeft(tokens[i - 1], options.greedy) trimLeft(tokens[i - 1], options.greedy)
} }
+5
View File
@@ -1,4 +1,5 @@
import { OperatorToken } from '../tokens/operator-token' import { OperatorToken } from '../tokens/operator-token'
import { DelimitedToken } from '../tokens/delimited-token'
import { WordToken } from '../tokens/word-token' import { WordToken } from '../tokens/word-token'
import { TagToken } from '../tokens/tag-token' import { TagToken } from '../tokens/tag-token'
import { HTMLToken } from '../tokens/html-token' import { HTMLToken } from '../tokens/html-token'
@@ -10,6 +11,10 @@ import { NumberToken } from '../tokens/number-token'
import { RangeToken } from '../tokens/range-token' import { RangeToken } from '../tokens/range-token'
import { TokenKind } from '../parser/token-kind' import { TokenKind } from '../parser/token-kind'
export function isDelimitedToken (val: any): val is DelimitedToken {
return !!(getKind(val) & TokenKind.Delimited)
}
export function isOperatorToken (val: any): val is OperatorToken { export function isOperatorToken (val: any): val is OperatorToken {
return getKind(val) === TokenKind.Operator return getKind(val) === TokenKind.Operator
} }