MCPcopy Index your code
hub / github.com/BloombergGraphics/whatiscode / unexpectedTokenError

Function unexpectedTokenError

scripts/libs/esprima.js:2087–2111  ·  view source on GitHub ↗
(token, message)

Source from the content-addressed store, hash-verified

2085 // Throw an exception because of the token.
2086
2087 function unexpectedTokenError(token, message) {
2088 var msg = message || Messages.UnexpectedToken;
2089
2090 if (token && !message) {
2091 msg = (token.type === Token.EOF) ? Messages.UnexpectedEOS :
2092 (token.type === Token.Identifier) ? Messages.UnexpectedIdentifier :
2093 (token.type === Token.NumericLiteral) ? Messages.UnexpectedNumber :
2094 (token.type === Token.StringLiteral) ? Messages.UnexpectedString :
2095 Messages.UnexpectedToken;
2096
2097 if (token.type === Token.Keyword) {
2098 if (isFutureReservedWord(token.value)) {
2099 msg = Messages.UnexpectedReserved;
2100 } else if (strict && isStrictModeReservedWord(token.value)) {
2101 msg = Messages.StrictReservedWord;
2102 }
2103 }
2104 }
2105
2106 msg = msg.replace('%0', token ? token.value : 'ILLEGAL');
2107
2108 return (token && typeof token.lineNumber === 'number') ?
2109 createError(token.lineNumber, token.start, msg) :
2110 createError(scanning ? lineNumber : lastLineNumber, scanning ? index : lastIndex, msg);
2111 }
2112
2113 function throwUnexpectedToken(token, message) {
2114 throw unexpectedTokenError(token, message);

Callers 2

throwUnexpectedTokenFunction · 0.85
tolerateUnexpectedTokenFunction · 0.85

Calls 3

isFutureReservedWordFunction · 0.85
isStrictModeReservedWordFunction · 0.85
createErrorFunction · 0.85

Tested by

no test coverage detected