Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "eslint:recommended",
"env": {
"browser": false,
"node": true,
"es2020": true,
"mocha": true
},
"parserOptions": {
"ecmaVersion": 2022,
"sourceType": "module"
},
"rules": {
"no-unused-vars": ["warn", { "argsIgnorePattern": "^_" }],
"no-prototype-builtins": "off",
"no-undef": "warn",
"no-constant-condition": ["error", { "checkLoops": false }]
}
}
40 changes: 40 additions & 0 deletions src/expression/error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Shortcut for getting the current col value (one based)
* Returns the column (position) where the last state.token starts
* @param {Object} state
* @return {number}
* @private
*/
export function col (state) {
return state.index - state.token.length + 1
}

/**
* Create a syntax error with the message:
* 'Syntax error in part "<part>" (char <char>)'
* @param {Object} state
* @param {string} message
* @return {SyntaxError} instantiated error
* @private
*/
export function createSyntaxError (state, message) {
const c = col(state)
const error = new SyntaxError(message + ' (char ' + c + ')')
error.char = c
return error
}

/**
* Create an error with the message:
* '<message> (char <char>)'
* @param {Object} state
* @param {string} message
* @return {Error} instantiated error
* @private
*/
export function createError (state, message) {
const c = col(state)
const error = new Error(message + ' (char ' + c + ')') // Changed to regular Error as per original type, can be SyntaxError if preferred
error.char = c
return error
}
Loading