@@ -128,6 +128,9 @@ export default class Tokenizer {
128
128
if ( input . length ) {
129
129
// Get the next token and the token type
130
130
token = this . getNextToken ( input , token ) ;
131
+ if ( ! token ) {
132
+ throw new Error ( `Parse error: Unexpected "${ input . slice ( 0 , 100 ) } "` ) ;
133
+ }
131
134
// Advance the string
132
135
input = input . substring ( token . value . length ) ;
133
136
@@ -154,8 +157,9 @@ export default class Tokenizer {
154
157
} ) ;
155
158
156
159
/** Attempts to match next token from input string, tests RegExp patterns in decreasing priority */
157
- getNextToken ( input : string , previousToken ?: Token ) {
158
- return ( this . matchToken ( TokenType . LINE_COMMENT ) ( input ) ||
160
+ getNextToken ( input : string , previousToken ?: Token ) : Token | undefined {
161
+ return (
162
+ this . matchToken ( TokenType . LINE_COMMENT ) ( input ) ||
159
163
this . matchToken ( TokenType . BLOCK_COMMENT ) ( input ) ||
160
164
this . matchToken ( TokenType . STRING ) ( input ) ||
161
165
this . matchToken ( TokenType . BLOCK_START ) ( input ) ||
@@ -164,7 +168,8 @@ export default class Tokenizer {
164
168
this . matchToken ( TokenType . NUMBER ) ( input ) ||
165
169
this . getReservedWordToken ( input , previousToken ) ||
166
170
this . matchToken ( TokenType . WORD ) ( input ) ||
167
- this . matchToken ( TokenType . OPERATOR ) ( input ) ) as Token ;
171
+ this . matchToken ( TokenType . OPERATOR ) ( input )
172
+ ) ;
168
173
}
169
174
170
175
/**
0 commit comments