1 | "use strict"; function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }Object.defineProperty(exports, "__esModule", {value: true});var _state = require('../tokenizer/state'); var _state2 = _interopRequireDefault(_state);
|
2 | var _charcodes = require('../util/charcodes');
|
3 |
|
4 | exports.isJSXEnabled;
|
5 | exports.isTypeScriptEnabled;
|
6 | exports.isFlowEnabled;
|
7 | exports.state;
|
8 | exports.input;
|
9 | exports.nextContextId;
|
10 |
|
11 | function getNextContextId() {
|
12 | return exports.nextContextId++;
|
13 | } exports.getNextContextId = getNextContextId;
|
14 |
|
15 |
|
16 | function augmentError(error) {
|
17 | if ("pos" in error) {
|
18 | const loc = locationForIndex(error.pos);
|
19 | error.message += ` (${loc.line}:${loc.column})`;
|
20 | error.loc = loc;
|
21 | }
|
22 | return error;
|
23 | } exports.augmentError = augmentError;
|
24 |
|
25 | class Loc {
|
26 |
|
27 |
|
28 | constructor(line, column) {
|
29 | this.line = line;
|
30 | this.column = column;
|
31 | }
|
32 | } exports.Loc = Loc;
|
33 |
|
34 | function locationForIndex(pos) {
|
35 | let line = 1;
|
36 | let column = 1;
|
37 | for (let i = 0; i < pos; i++) {
|
38 | if (exports.input.charCodeAt(i) === _charcodes.charCodes.lineFeed) {
|
39 | line++;
|
40 | column = 1;
|
41 | } else {
|
42 | column++;
|
43 | }
|
44 | }
|
45 | return new Loc(line, column);
|
46 | } exports.locationForIndex = locationForIndex;
|
47 |
|
48 | function initParser(
|
49 | inputCode,
|
50 | isJSXEnabledArg,
|
51 | isTypeScriptEnabledArg,
|
52 | isFlowEnabledArg,
|
53 | ) {
|
54 | exports.input = inputCode;
|
55 | exports.state = new (0, _state2.default)();
|
56 | exports.nextContextId = 1;
|
57 | exports.isJSXEnabled = isJSXEnabledArg;
|
58 | exports.isTypeScriptEnabled = isTypeScriptEnabledArg;
|
59 | exports.isFlowEnabled = isFlowEnabledArg;
|
60 | } exports.initParser = initParser;
|