1
1
import { evalExp } from 'src/render/syntax'
2
- import * as lexical from 'src/parser/lexical'
3
2
import Filter from './filter/filter'
4
3
import Scope from 'src/scope/scope'
5
4
6
-
7
5
enum ParseState {
8
6
INIT = 0 ,
9
7
FILTER_NAME = 1 ,
@@ -18,7 +16,6 @@ export default class {
18
16
* @param str value string, like: "i have a dream | truncate: 3
19
17
*/
20
18
constructor ( str : string , strictFilters : boolean ) {
21
- const N = str . length
22
19
let buffer = ''
23
20
let quoted = ''
24
21
let state = ParseState . INIT
@@ -27,23 +24,20 @@ export default class {
27
24
let filterName = ''
28
25
let filterArgs : string [ ] = [ ]
29
26
30
- for ( let i = 0 ; i < str . length ; i ++ ) {
27
+ for ( let i = 0 ; i < str . length ; i ++ ) {
31
28
if ( quoted ) {
32
- if ( str [ i ] == quoted ) {
29
+ if ( str [ i ] === quoted ) {
33
30
quoted = ''
34
31
sealed = true
35
32
}
36
33
buffer += str [ i ]
37
- }
38
- else if ( / \s / . test ( str [ i ] ) ) {
34
+ } else if ( / \s / . test ( str [ i ] ) ) {
39
35
if ( ! buffer ) continue
40
36
else sealed = true
41
- }
42
- else if ( str [ i ] === '|' ) {
37
+ } else if ( str [ i ] === '|' ) {
43
38
if ( state === ParseState . INIT ) {
44
39
this . initial = buffer
45
- }
46
- else {
40
+ } else {
47
41
if ( state === ParseState . FILTER_NAME ) filterName = buffer
48
42
else filterArgs . push ( buffer )
49
43
this . filters . push ( new Filter ( filterName , filterArgs , strictFilters ) )
@@ -53,19 +47,16 @@ export default class {
53
47
state = ParseState . FILTER_NAME
54
48
buffer = ''
55
49
sealed = false
56
- }
57
- else if ( state === ParseState . FILTER_NAME && str [ i ] === ':' ) {
50
+ } else if ( state === ParseState . FILTER_NAME && str [ i ] === ':' ) {
58
51
filterName = buffer
59
52
state = ParseState . FILTER_ARG
60
53
buffer = ''
61
54
sealed = false
62
- }
63
- else if ( state === ParseState . FILTER_ARG && str [ i ] === ',' ) {
55
+ } else if ( state === ParseState . FILTER_ARG && str [ i ] === ',' ) {
64
56
filterArgs . push ( buffer )
65
57
buffer = ''
66
58
sealed = false
67
- }
68
- else if ( sealed ) continue
59
+ } else if ( sealed ) continue
69
60
else {
70
61
if ( ( str [ i ] === '"' || str [ i ] === "'" ) && ! quoted ) quoted = str [ i ]
71
62
buffer += str [ i ]
0 commit comments