'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var _commonjsHelpers = require('../../../../../../../../_virtual/_commonjsHelpers.js');
require('../../../../../../../../_virtual/mixin-base.js');
require('../../../../../../../../_virtual/tokenizer-mixin2.js');
require('../../../../../../../../_virtual/tokenizer-mixin.js');
require('../../../../../../../../_virtual/mixin.js');
var mixinBase = require('./mixin-base.js');
var tokenizerMixin = require('./tokenizer-mixin.js');
var tokenizerMixin$1 = require('../location-info/tokenizer-mixin.js');
var mixin = require('../../utils/mixin.js');

'use strict';

const ErrorReportingMixinBase = mixinBase.mixinBase;
const ErrorReportingTokenizerMixin = tokenizerMixin.tokenizerMixin;
const LocationInfoTokenizerMixin = tokenizerMixin$1.tokenizerMixin;
const Mixin = mixin.mixin;

class ErrorReportingParserMixin extends ErrorReportingMixinBase {
    constructor(parser, opts) {
        super(parser, opts);

        this.opts = opts;
        this.ctLoc = null;
        this.locBeforeToken = false;
    }

    _setErrorLocation(err) {
        if (this.ctLoc) {
            err.startLine = this.ctLoc.startLine;
            err.startCol = this.ctLoc.startCol;
            err.startOffset = this.ctLoc.startOffset;

            err.endLine = this.locBeforeToken ? this.ctLoc.startLine : this.ctLoc.endLine;
            err.endCol = this.locBeforeToken ? this.ctLoc.startCol : this.ctLoc.endCol;
            err.endOffset = this.locBeforeToken ? this.ctLoc.startOffset : this.ctLoc.endOffset;
        }
    }

    _getOverriddenMethods(mxn, orig) {
        return {
            _bootstrap(document, fragmentContext) {
                orig._bootstrap.call(this, document, fragmentContext);

                Mixin.install(this.tokenizer, ErrorReportingTokenizerMixin, mxn.opts);
                Mixin.install(this.tokenizer, LocationInfoTokenizerMixin);
            },

            _processInputToken(token) {
                mxn.ctLoc = token.location;

                orig._processInputToken.call(this, token);
            },

            _err(code, options) {
                mxn.locBeforeToken = options && options.beforeToken;
                mxn._reportError(code);
            }
        };
    }
}

var parserMixin = ErrorReportingParserMixin;

var parserMixin_default = /*@__PURE__*/_commonjsHelpers.getDefaultExportFromCjs(parserMixin);

exports.default = parserMixin_default;
exports.parserMixin = parserMixin;
//# sourceMappingURL=parser-mixin.js.map
