MCPcopy Index your code
hub / github.com/GitbookIO/gitbook / createExpressionErrorFromSyntaxError

Function createExpressionErrorFromSyntaxError

packages/expr/src/runtime.ts:227–245  ·  view source on GitHub ↗
(
    code: string,
    error: SyntaxError & { loc?: Position }
)

Source from the content-addressed store, hash-verified

225}
226
227function createExpressionErrorFromSyntaxError(
228 code: string,
229 error: SyntaxError & { loc?: Position }
230): ExpressionError {
231 const loc = error.loc;
232
233 if (!loc) {
234 return new ExpressionError(error.message);
235 }
236
237 const errorMessage = `${error.message.replace(/\s*\(\d+:\d+\)$/, '')} at ${code.split('\n').length > 1 ? `line ${loc.line}, ` : ''}char ${loc.column}`;
238 const token = getTokenAtLoc(code, loc);
239
240 if (!token) {
241 return new ExpressionError(errorMessage, loc);
242 }
243
244 return new ExpressionError(errorMessage, loc, token);
245}
246function getTokenAtLoc(code: string, errorLoc: Position): Token | undefined {
247 const tokens = tokenizer(code, {
248 ecmaVersion: 'latest',

Callers 1

parseMethod · 0.85

Calls 1

getTokenAtLocFunction · 0.85

Tested by

no test coverage detected