UNPKG

sucrase

Version:

Super-fast alternative to Babel for when you can target modern JS runtimes

31 lines (30 loc) 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const lines_and_columns_1 = require("lines-and-columns"); class BaseParser { hasPlugin(name) { return Boolean(this.plugins[name]); } // This function is used to raise exceptions on parse errors. It // takes an offset integer (into the current `input`) to indicate // the location of the error, attaches the position to the end // of the error message, and then raises a `SyntaxError` with that // message. raise(pos, message, missingPluginNames) { let loc = new lines_and_columns_1.default(this.input).locationForIndex(pos); if (!loc) { loc = { line: 0, column: 0 }; } message += ` (${loc.line}:${loc.column})`; // tslint:disable-next-line no-any const err = new SyntaxError(message); err.pos = pos; err.loc = loc; if (missingPluginNames) { // @ts-ignore err.missingPlugin = missingPluginNames; } throw err; } } exports.default = BaseParser;