Every line of 'jest encountered an unexpected token' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
313 function unexpected(c) { 314 throw new UnexpectedChar(c, locate()); 315 }
Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code
131 export function unexpected(parser, atToken?: ?Token): Error { 132 var token = atToken || parser.token; 133 return syntaxError( 134 parser.source, 135 token.start, 136 `Unexpected ${getTokenDesc(token)}` 137 ); 138 }
11 function expectToken(expectedStart, parseContext) { 12 var tokens = parseContext.tokens; 13 if (tokens[0] !== expectedStart) { 14 throw new Error( 15 `Invalid parse state! Expected: '${expectedStart}' but got: '${ 16 tokens[0] 17 }' from chain: [${tokens}]. ${parseInfo(parseContext)}` 18 ); 19 } 20 }
105 unexpected(pos) { 106 let message = "Unexpected Token"; 107 if (pos == null) { 108 pos = this.state.cur.start; 109 } 110 let token = pos === this.state.cur.start ? this.state.cur : pos === this.state.prev.start ? this.state.prev : null; 111 if (token == null) for (let i = this.state.index - 2; i >= 0; i--) { 112 if (this.state.tokens[i].start === pos) token = this.state.tokens[i]; 113 } 114 if (token) { 115 message += ": " + token.type.key + " (" + JSON.stringify(token.value) + ")"; 116 } 117 this.raise(pos, message); 118 }
323 function expectKeyword(keyword) { 324 const token = nextToken(); 325 if (token.type !== Token.Keyword || token.value !== keyword) { 326 throwUnexpectedToken(token); 327 } 328 }
76 expect(text: string, consume?: boolean = true) { 77 if (this.fetch().text !== text) { 78 throw new ParseError( 79 `Expected '${text}', got '${this.fetch().text}'`, this.fetch() 80 ); 81 } 82 if (consume) { 83 this.consume(); 84 } 85 }
29 expect (...tokenTypes) { 30 if (!(new Set(tokenTypes).has(this.current.type))) { 31 throw new UnexpectedTokenError( 32 tokenTypes, this.current 33 ) 34 } 35 return true 36 }
981 function expectKeyword(lexer, value) { 982 var token = lexer.token; 983 if (token.kind === _lexer.TokenKind.NAME && token.value === value) { 984 lexer.advance(); 985 return token; 986 } 987 throw (0, _error.syntaxError)(lexer.source, token.start, 'Expected "' + value + '", found ' + (0, _lexer.getTokenDesc)(token)); 988 }
53 expect(kind: TokenKind): boolean { 54 if (!this.peek(kind)) { 55 this.log.error( 56 this.current.range, 57 `Expected ${tokenToString(kind)} but found ${tokenToString(this.current.kind)}` 58 ); 59 return false; 60 } 61 62 this.advance(); 63 return true; 64 }
291 function expect(value) { 292 const token = nextToken(); 293 if (token.type !== Token.Punctuator || token.value !== value) { 294 throwUnexpectedToken(token); 295 } 296 }