@loaders.gl/json 3.1.0-beta.7 → 3.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/dist/bundle.js +5 -1845
  2. package/dist/dist.min.js +2543 -0
  3. package/dist/es5/bundle.js +1 -1
  4. package/dist/es5/bundle.js.map +1 -1
  5. package/dist/es5/geojson-loader.js +143 -29
  6. package/dist/es5/geojson-loader.js.map +1 -1
  7. package/dist/es5/index.js +14 -6
  8. package/dist/es5/index.js.map +1 -1
  9. package/dist/es5/json-loader.js +44 -18
  10. package/dist/es5/json-loader.js.map +1 -1
  11. package/dist/es5/lib/clarinet/clarinet.js +359 -335
  12. package/dist/es5/lib/clarinet/clarinet.js.map +1 -1
  13. package/dist/es5/lib/jsonpath/jsonpath.js +101 -54
  14. package/dist/es5/lib/jsonpath/jsonpath.js.map +1 -1
  15. package/dist/es5/lib/parse-json-in-batches.js +251 -72
  16. package/dist/es5/lib/parse-json-in-batches.js.map +1 -1
  17. package/dist/es5/lib/parse-json.js +9 -4
  18. package/dist/es5/lib/parse-json.js.map +1 -1
  19. package/dist/es5/lib/parse-ndjson-in-batches.js +143 -31
  20. package/dist/es5/lib/parse-ndjson-in-batches.js.map +1 -1
  21. package/dist/es5/lib/parse-ndjson.js +2 -2
  22. package/dist/es5/lib/parse-ndjson.js.map +1 -1
  23. package/dist/es5/lib/parser/json-parser.js +117 -95
  24. package/dist/es5/lib/parser/json-parser.js.map +1 -1
  25. package/dist/es5/lib/parser/streaming-json-parser.js +115 -59
  26. package/dist/es5/lib/parser/streaming-json-parser.js.map +1 -1
  27. package/dist/es5/ndjson-loader.js +30 -8
  28. package/dist/es5/ndjson-loader.js.map +1 -1
  29. package/dist/esm/geojson-loader.js +1 -1
  30. package/dist/esm/geojson-loader.js.map +1 -1
  31. package/dist/esm/index.js +1 -0
  32. package/dist/esm/index.js.map +1 -1
  33. package/dist/esm/json-loader.js +1 -1
  34. package/dist/esm/json-loader.js.map +1 -1
  35. package/dist/esm/lib/parse-json-in-batches.js +18 -1
  36. package/dist/esm/lib/parse-json-in-batches.js.map +1 -1
  37. package/dist/esm/ndjson-loader.js +1 -1
  38. package/dist/esm/ndjson-loader.js.map +1 -1
  39. package/dist/geojson-worker.js +777 -182
  40. package/dist/index.d.ts +1 -0
  41. package/dist/index.d.ts.map +1 -1
  42. package/dist/index.js +3 -1
  43. package/dist/lib/parse-json-in-batches.d.ts +1 -0
  44. package/dist/lib/parse-json-in-batches.d.ts.map +1 -1
  45. package/dist/lib/parse-json-in-batches.js +20 -0
  46. package/package.json +6 -6
  47. package/src/index.ts +2 -0
  48. package/src/lib/parse-json-in-batches.ts +23 -1
@@ -7,9 +7,17 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = void 0;
9
9
 
10
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
+
12
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
13
+
10
14
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
15
 
12
- const MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
17
+
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
19
+
20
+ var MAX_BUFFER_LENGTH = Number.MAX_SAFE_INTEGER;
13
21
  var STATE;
14
22
 
15
23
  (function (STATE) {
@@ -39,7 +47,7 @@ var STATE;
39
47
  STATE[STATE["NUMBER_DIGIT"] = 23] = "NUMBER_DIGIT";
40
48
  })(STATE || (STATE = {}));
41
49
 
42
- const Char = {
50
+ var Char = {
43
51
  tab: 0x09,
44
52
  lineFeed: 0x0a,
45
53
  carriageReturn: 0x0d,
@@ -69,22 +77,24 @@ const Char = {
69
77
  openBrace: 0x7b,
70
78
  closeBrace: 0x7d
71
79
  };
72
- const stringTokenPattern = /[\\"\n]/g;
73
- const DEFAULT_OPTIONS = {
74
- onready: () => {},
75
- onopenobject: () => {},
76
- onkey: () => {},
77
- oncloseobject: () => {},
78
- onopenarray: () => {},
79
- onclosearray: () => {},
80
- onvalue: () => {},
81
- onerror: () => {},
82
- onend: () => {},
83
- onchunkparsed: () => {}
80
+ var stringTokenPattern = /[\\"\n]/g;
81
+ var DEFAULT_OPTIONS = {
82
+ onready: function onready() {},
83
+ onopenobject: function onopenobject() {},
84
+ onkey: function onkey() {},
85
+ oncloseobject: function oncloseobject() {},
86
+ onopenarray: function onopenarray() {},
87
+ onclosearray: function onclosearray() {},
88
+ onvalue: function onvalue() {},
89
+ onerror: function onerror() {},
90
+ onend: function onend() {},
91
+ onchunkparsed: function onchunkparsed() {}
84
92
  };
85
93
 
86
- class ClarinetParser {
87
- constructor(options = {}) {
94
+ var ClarinetParser = function () {
95
+ function ClarinetParser() {
96
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
97
+ (0, _classCallCheck2.default)(this, ClarinetParser);
88
98
  (0, _defineProperty2.default)(this, "options", DEFAULT_OPTIONS);
89
99
  (0, _defineProperty2.default)(this, "bufferCheckPosition", MAX_BUFFER_LENGTH);
90
100
  (0, _defineProperty2.default)(this, "q", '');
@@ -105,379 +115,392 @@ class ClarinetParser {
105
115
  (0, _defineProperty2.default)(this, "depth", 0);
106
116
  (0, _defineProperty2.default)(this, "textNode", void 0);
107
117
  (0, _defineProperty2.default)(this, "numberNode", void 0);
108
- this.options = { ...DEFAULT_OPTIONS,
109
- ...options
110
- };
118
+ this.options = _objectSpread(_objectSpread({}, DEFAULT_OPTIONS), options);
111
119
  this.textNode = undefined;
112
120
  this.numberNode = '';
113
121
  this.emit('onready');
114
122
  }
115
123
 
116
- end() {
117
- if (this.state !== STATE.VALUE || this.depth !== 0) this._error('Unexpected end');
124
+ (0, _createClass2.default)(ClarinetParser, [{
125
+ key: "end",
126
+ value: function end() {
127
+ if (this.state !== STATE.VALUE || this.depth !== 0) this._error('Unexpected end');
118
128
 
119
- this._closeValue();
129
+ this._closeValue();
120
130
 
121
- this.c = '';
122
- this.closed = true;
123
- this.emit('onend');
124
- return this;
125
- }
131
+ this.c = '';
132
+ this.closed = true;
133
+ this.emit('onend');
134
+ return this;
135
+ }
136
+ }, {
137
+ key: "resume",
138
+ value: function resume() {
139
+ this.error = null;
140
+ return this;
141
+ }
142
+ }, {
143
+ key: "close",
144
+ value: function close() {
145
+ return this.write(null);
146
+ }
147
+ }, {
148
+ key: "emit",
149
+ value: function emit(event, data) {
150
+ var _this$options$event, _this$options;
126
151
 
127
- resume() {
128
- this.error = null;
129
- return this;
130
- }
152
+ (_this$options$event = (_this$options = this.options)[event]) === null || _this$options$event === void 0 ? void 0 : _this$options$event.call(_this$options, data, this);
153
+ }
154
+ }, {
155
+ key: "emitNode",
156
+ value: function emitNode(event, data) {
157
+ this._closeValue();
131
158
 
132
- close() {
133
- return this.write(null);
134
- }
159
+ this.emit(event, data);
160
+ }
161
+ }, {
162
+ key: "write",
163
+ value: function write(chunk) {
164
+ if (this.error) {
165
+ throw this.error;
166
+ }
135
167
 
136
- emit(event, data) {
137
- var _this$options$event, _this$options;
168
+ if (this.closed) {
169
+ return this._error('Cannot write after close. Assign an onready handler.');
170
+ }
138
171
 
139
- (_this$options$event = (_this$options = this.options)[event]) === null || _this$options$event === void 0 ? void 0 : _this$options$event.call(_this$options, data, this);
140
- }
172
+ if (chunk === null) {
173
+ return this.end();
174
+ }
141
175
 
142
- emitNode(event, data) {
143
- this._closeValue();
176
+ var i = 0;
177
+ var c = chunk.charCodeAt(0);
178
+ var p = this.p;
144
179
 
145
- this.emit(event, data);
146
- }
180
+ while (c) {
181
+ p = c;
182
+ this.c = c = chunk.charCodeAt(i++);
147
183
 
148
- write(chunk) {
149
- if (this.error) {
150
- throw this.error;
151
- }
184
+ if (p !== c) {
185
+ this.p = p;
186
+ } else {
187
+ p = this.p;
188
+ }
152
189
 
153
- if (this.closed) {
154
- return this._error('Cannot write after close. Assign an onready handler.');
155
- }
190
+ if (!c) break;
191
+ this.position++;
156
192
 
157
- if (chunk === null) {
158
- return this.end();
159
- }
193
+ if (c === Char.lineFeed) {
194
+ this.line++;
195
+ this.column = 0;
196
+ } else this.column++;
160
197
 
161
- let i = 0;
162
- let c = chunk.charCodeAt(0);
163
- let p = this.p;
198
+ switch (this.state) {
199
+ case STATE.BEGIN:
200
+ if (c === Char.openBrace) this.state = STATE.OPEN_OBJECT;else if (c === Char.openBracket) this.state = STATE.OPEN_ARRAY;else if (!isWhitespace(c)) {
201
+ this._error('Non-whitespace before {[.');
202
+ }
203
+ continue;
164
204
 
165
- while (c) {
166
- p = c;
167
- this.c = c = chunk.charCodeAt(i++);
205
+ case STATE.OPEN_KEY:
206
+ case STATE.OPEN_OBJECT:
207
+ if (isWhitespace(c)) continue;
208
+ if (this.state === STATE.OPEN_KEY) this.stack.push(STATE.CLOSE_KEY);else if (c === Char.closeBrace) {
209
+ this.emit('onopenobject');
210
+ this.depth++;
211
+ this.emit('oncloseobject');
212
+ this.depth--;
213
+ this.state = this.stack.pop() || STATE.VALUE;
214
+ continue;
215
+ } else this.stack.push(STATE.CLOSE_OBJECT);
216
+ if (c === Char.doubleQuote) this.state = STATE.STRING;else this._error('Malformed object key should start with "');
217
+ continue;
168
218
 
169
- if (p !== c) {
170
- this.p = p;
171
- } else {
172
- p = this.p;
173
- }
219
+ case STATE.CLOSE_KEY:
220
+ case STATE.CLOSE_OBJECT:
221
+ if (isWhitespace(c)) continue;
174
222
 
175
- if (!c) break;
176
- this.position++;
177
-
178
- if (c === Char.lineFeed) {
179
- this.line++;
180
- this.column = 0;
181
- } else this.column++;
182
-
183
- switch (this.state) {
184
- case STATE.BEGIN:
185
- if (c === Char.openBrace) this.state = STATE.OPEN_OBJECT;else if (c === Char.openBracket) this.state = STATE.OPEN_ARRAY;else if (!isWhitespace(c)) {
186
- this._error('Non-whitespace before {[.');
187
- }
188
- continue;
189
-
190
- case STATE.OPEN_KEY:
191
- case STATE.OPEN_OBJECT:
192
- if (isWhitespace(c)) continue;
193
- if (this.state === STATE.OPEN_KEY) this.stack.push(STATE.CLOSE_KEY);else if (c === Char.closeBrace) {
194
- this.emit('onopenobject');
195
- this.depth++;
196
- this.emit('oncloseobject');
197
- this.depth--;
198
- this.state = this.stack.pop() || STATE.VALUE;
199
- continue;
200
- } else this.stack.push(STATE.CLOSE_OBJECT);
201
- if (c === Char.doubleQuote) this.state = STATE.STRING;else this._error('Malformed object key should start with "');
202
- continue;
223
+ if (c === Char.colon) {
224
+ if (this.state === STATE.CLOSE_OBJECT) {
225
+ this.stack.push(STATE.CLOSE_OBJECT);
203
226
 
204
- case STATE.CLOSE_KEY:
205
- case STATE.CLOSE_OBJECT:
206
- if (isWhitespace(c)) continue;
227
+ this._closeValue('onopenobject');
207
228
 
208
- if (c === Char.colon) {
209
- if (this.state === STATE.CLOSE_OBJECT) {
210
- this.stack.push(STATE.CLOSE_OBJECT);
229
+ this.depth++;
230
+ } else this._closeValue('onkey');
211
231
 
212
- this._closeValue('onopenobject');
232
+ this.state = STATE.VALUE;
233
+ } else if (c === Char.closeBrace) {
234
+ this.emitNode('oncloseobject');
235
+ this.depth--;
236
+ this.state = this.stack.pop() || STATE.VALUE;
237
+ } else if (c === Char.comma) {
238
+ if (this.state === STATE.CLOSE_OBJECT) this.stack.push(STATE.CLOSE_OBJECT);
213
239
 
214
- this.depth++;
215
- } else this._closeValue('onkey');
240
+ this._closeValue();
241
+
242
+ this.state = STATE.OPEN_KEY;
243
+ } else this._error('Bad object');
244
+
245
+ continue;
216
246
 
217
- this.state = STATE.VALUE;
218
- } else if (c === Char.closeBrace) {
219
- this.emitNode('oncloseobject');
220
- this.depth--;
221
- this.state = this.stack.pop() || STATE.VALUE;
222
- } else if (c === Char.comma) {
223
- if (this.state === STATE.CLOSE_OBJECT) this.stack.push(STATE.CLOSE_OBJECT);
247
+ case STATE.OPEN_ARRAY:
248
+ case STATE.VALUE:
249
+ if (isWhitespace(c)) continue;
224
250
 
225
- this._closeValue();
251
+ if (this.state === STATE.OPEN_ARRAY) {
252
+ this.emit('onopenarray');
253
+ this.depth++;
254
+ this.state = STATE.VALUE;
226
255
 
227
- this.state = STATE.OPEN_KEY;
228
- } else this._error('Bad object');
256
+ if (c === Char.closeBracket) {
257
+ this.emit('onclosearray');
258
+ this.depth--;
259
+ this.state = this.stack.pop() || STATE.VALUE;
260
+ continue;
261
+ } else {
262
+ this.stack.push(STATE.CLOSE_ARRAY);
263
+ }
264
+ }
229
265
 
230
- continue;
266
+ if (c === Char.doubleQuote) this.state = STATE.STRING;else if (c === Char.openBrace) this.state = STATE.OPEN_OBJECT;else if (c === Char.openBracket) this.state = STATE.OPEN_ARRAY;else if (c === Char.t) this.state = STATE.TRUE;else if (c === Char.f) this.state = STATE.FALSE;else if (c === Char.n) this.state = STATE.NULL;else if (c === Char.minus) {
267
+ this.numberNode += '-';
268
+ } else if (Char._0 <= c && c <= Char._9) {
269
+ this.numberNode += String.fromCharCode(c);
270
+ this.state = STATE.NUMBER_DIGIT;
271
+ } else this._error('Bad value');
272
+ continue;
231
273
 
232
- case STATE.OPEN_ARRAY:
233
- case STATE.VALUE:
234
- if (isWhitespace(c)) continue;
274
+ case STATE.CLOSE_ARRAY:
275
+ if (c === Char.comma) {
276
+ this.stack.push(STATE.CLOSE_ARRAY);
235
277
 
236
- if (this.state === STATE.OPEN_ARRAY) {
237
- this.emit('onopenarray');
238
- this.depth++;
239
- this.state = STATE.VALUE;
278
+ this._closeValue('onvalue');
240
279
 
241
- if (c === Char.closeBracket) {
242
- this.emit('onclosearray');
280
+ this.state = STATE.VALUE;
281
+ } else if (c === Char.closeBracket) {
282
+ this.emitNode('onclosearray');
243
283
  this.depth--;
244
284
  this.state = this.stack.pop() || STATE.VALUE;
245
- continue;
246
- } else {
247
- this.stack.push(STATE.CLOSE_ARRAY);
285
+ } else if (isWhitespace(c)) continue;else this._error('Bad array');
286
+
287
+ continue;
288
+
289
+ case STATE.STRING:
290
+ if (this.textNode === undefined) {
291
+ this.textNode = '';
248
292
  }
249
- }
250
-
251
- if (c === Char.doubleQuote) this.state = STATE.STRING;else if (c === Char.openBrace) this.state = STATE.OPEN_OBJECT;else if (c === Char.openBracket) this.state = STATE.OPEN_ARRAY;else if (c === Char.t) this.state = STATE.TRUE;else if (c === Char.f) this.state = STATE.FALSE;else if (c === Char.n) this.state = STATE.NULL;else if (c === Char.minus) {
252
- this.numberNode += '-';
253
- } else if (Char._0 <= c && c <= Char._9) {
254
- this.numberNode += String.fromCharCode(c);
255
- this.state = STATE.NUMBER_DIGIT;
256
- } else this._error('Bad value');
257
- continue;
258
-
259
- case STATE.CLOSE_ARRAY:
260
- if (c === Char.comma) {
261
- this.stack.push(STATE.CLOSE_ARRAY);
262
-
263
- this._closeValue('onvalue');
264
-
265
- this.state = STATE.VALUE;
266
- } else if (c === Char.closeBracket) {
267
- this.emitNode('onclosearray');
268
- this.depth--;
269
- this.state = this.stack.pop() || STATE.VALUE;
270
- } else if (isWhitespace(c)) continue;else this._error('Bad array');
271
-
272
- continue;
273
-
274
- case STATE.STRING:
275
- if (this.textNode === undefined) {
276
- this.textNode = '';
277
- }
278
-
279
- let starti = i - 1;
280
- let slashed = this.slashed;
281
- let unicodeI = this.unicodeI;
282
-
283
- STRING_BIGLOOP: while (true) {
284
- while (unicodeI > 0) {
285
- this.unicodeS += String.fromCharCode(c);
286
- c = chunk.charCodeAt(i++);
287
- this.position++;
288
-
289
- if (unicodeI === 4) {
290
- this.textNode += String.fromCharCode(parseInt(this.unicodeS, 16));
291
- unicodeI = 0;
293
+
294
+ var starti = i - 1;
295
+ var slashed = this.slashed;
296
+ var unicodeI = this.unicodeI;
297
+
298
+ STRING_BIGLOOP: while (true) {
299
+ while (unicodeI > 0) {
300
+ this.unicodeS += String.fromCharCode(c);
301
+ c = chunk.charCodeAt(i++);
302
+ this.position++;
303
+
304
+ if (unicodeI === 4) {
305
+ this.textNode += String.fromCharCode(parseInt(this.unicodeS, 16));
306
+ unicodeI = 0;
307
+ starti = i - 1;
308
+ } else {
309
+ unicodeI++;
310
+ }
311
+
312
+ if (!c) break STRING_BIGLOOP;
313
+ }
314
+
315
+ if (c === Char.doubleQuote && !slashed) {
316
+ this.state = this.stack.pop() || STATE.VALUE;
317
+ this.textNode += chunk.substring(starti, i - 1);
318
+ this.position += i - 1 - starti;
319
+ break;
320
+ }
321
+
322
+ if (c === Char.backslash && !slashed) {
323
+ slashed = true;
324
+ this.textNode += chunk.substring(starti, i - 1);
325
+ this.position += i - 1 - starti;
326
+ c = chunk.charCodeAt(i++);
327
+ this.position++;
328
+ if (!c) break;
329
+ }
330
+
331
+ if (slashed) {
332
+ slashed = false;
333
+
334
+ if (c === Char.n) {
335
+ this.textNode += '\n';
336
+ } else if (c === Char.r) {
337
+ this.textNode += '\r';
338
+ } else if (c === Char.t) {
339
+ this.textNode += '\t';
340
+ } else if (c === Char.f) {
341
+ this.textNode += '\f';
342
+ } else if (c === Char.b) {
343
+ this.textNode += '\b';
344
+ } else if (c === Char.u) {
345
+ unicodeI = 1;
346
+ this.unicodeS = '';
347
+ } else {
348
+ this.textNode += String.fromCharCode(c);
349
+ }
350
+
351
+ c = chunk.charCodeAt(i++);
352
+ this.position++;
292
353
  starti = i - 1;
293
- } else {
294
- unicodeI++;
354
+ if (!c) break;else continue;
295
355
  }
296
356
 
297
- if (!c) break STRING_BIGLOOP;
357
+ stringTokenPattern.lastIndex = i;
358
+ var reResult = stringTokenPattern.exec(chunk);
359
+
360
+ if (reResult === null) {
361
+ i = chunk.length + 1;
362
+ this.textNode += chunk.substring(starti, i - 1);
363
+ this.position += i - 1 - starti;
364
+ break;
365
+ }
366
+
367
+ i = reResult.index + 1;
368
+ c = chunk.charCodeAt(reResult.index);
369
+
370
+ if (!c) {
371
+ this.textNode += chunk.substring(starti, i - 1);
372
+ this.position += i - 1 - starti;
373
+ break;
374
+ }
298
375
  }
299
376
 
300
- if (c === Char.doubleQuote && !slashed) {
377
+ this.slashed = slashed;
378
+ this.unicodeI = unicodeI;
379
+ continue;
380
+
381
+ case STATE.TRUE:
382
+ if (c === Char.r) this.state = STATE.TRUE2;else this._error("Invalid true started with t".concat(c));
383
+ continue;
384
+
385
+ case STATE.TRUE2:
386
+ if (c === Char.u) this.state = STATE.TRUE3;else this._error("Invalid true started with tr".concat(c));
387
+ continue;
388
+
389
+ case STATE.TRUE3:
390
+ if (c === Char.e) {
391
+ this.emit('onvalue', true);
301
392
  this.state = this.stack.pop() || STATE.VALUE;
302
- this.textNode += chunk.substring(starti, i - 1);
303
- this.position += i - 1 - starti;
304
- break;
305
- }
393
+ } else this._error("Invalid true started with tru".concat(c));
306
394
 
307
- if (c === Char.backslash && !slashed) {
308
- slashed = true;
309
- this.textNode += chunk.substring(starti, i - 1);
310
- this.position += i - 1 - starti;
311
- c = chunk.charCodeAt(i++);
312
- this.position++;
313
- if (!c) break;
314
- }
395
+ continue;
315
396
 
316
- if (slashed) {
317
- slashed = false;
318
-
319
- if (c === Char.n) {
320
- this.textNode += '\n';
321
- } else if (c === Char.r) {
322
- this.textNode += '\r';
323
- } else if (c === Char.t) {
324
- this.textNode += '\t';
325
- } else if (c === Char.f) {
326
- this.textNode += '\f';
327
- } else if (c === Char.b) {
328
- this.textNode += '\b';
329
- } else if (c === Char.u) {
330
- unicodeI = 1;
331
- this.unicodeS = '';
332
- } else {
333
- this.textNode += String.fromCharCode(c);
334
- }
397
+ case STATE.FALSE:
398
+ if (c === Char.a) this.state = STATE.FALSE2;else this._error("Invalid false started with f".concat(c));
399
+ continue;
335
400
 
336
- c = chunk.charCodeAt(i++);
337
- this.position++;
338
- starti = i - 1;
339
- if (!c) break;else continue;
340
- }
401
+ case STATE.FALSE2:
402
+ if (c === Char.l) this.state = STATE.FALSE3;else this._error("Invalid false started with fa".concat(c));
403
+ continue;
341
404
 
342
- stringTokenPattern.lastIndex = i;
343
- const reResult = stringTokenPattern.exec(chunk);
405
+ case STATE.FALSE3:
406
+ if (c === Char.s) this.state = STATE.FALSE4;else this._error("Invalid false started with fal".concat(c));
407
+ continue;
344
408
 
345
- if (reResult === null) {
346
- i = chunk.length + 1;
347
- this.textNode += chunk.substring(starti, i - 1);
348
- this.position += i - 1 - starti;
349
- break;
350
- }
409
+ case STATE.FALSE4:
410
+ if (c === Char.e) {
411
+ this.emit('onvalue', false);
412
+ this.state = this.stack.pop() || STATE.VALUE;
413
+ } else this._error("Invalid false started with fals".concat(c));
414
+
415
+ continue;
351
416
 
352
- i = reResult.index + 1;
353
- c = chunk.charCodeAt(reResult.index);
417
+ case STATE.NULL:
418
+ if (c === Char.u) this.state = STATE.NULL2;else this._error("Invalid null started with n".concat(c));
419
+ continue;
354
420
 
355
- if (!c) {
356
- this.textNode += chunk.substring(starti, i - 1);
357
- this.position += i - 1 - starti;
358
- break;
421
+ case STATE.NULL2:
422
+ if (c === Char.l) this.state = STATE.NULL3;else this._error("Invalid null started with nu".concat(c));
423
+ continue;
424
+
425
+ case STATE.NULL3:
426
+ if (c === Char.l) {
427
+ this.emit('onvalue', null);
428
+ this.state = this.stack.pop() || STATE.VALUE;
429
+ } else this._error("Invalid null started with nul".concat(c));
430
+
431
+ continue;
432
+
433
+ case STATE.NUMBER_DECIMAL_POINT:
434
+ if (c === Char.period) {
435
+ this.numberNode += '.';
436
+ this.state = STATE.NUMBER_DIGIT;
437
+ } else this._error('Leading zero not followed by .');
438
+
439
+ continue;
440
+
441
+ case STATE.NUMBER_DIGIT:
442
+ if (Char._0 <= c && c <= Char._9) this.numberNode += String.fromCharCode(c);else if (c === Char.period) {
443
+ if (this.numberNode.indexOf('.') !== -1) this._error('Invalid number has two dots');
444
+ this.numberNode += '.';
445
+ } else if (c === Char.e || c === Char.E) {
446
+ if (this.numberNode.indexOf('e') !== -1 || this.numberNode.indexOf('E') !== -1) this._error('Invalid number has two exponential');
447
+ this.numberNode += 'e';
448
+ } else if (c === Char.plus || c === Char.minus) {
449
+ if (!(p === Char.e || p === Char.E)) this._error('Invalid symbol in number');
450
+ this.numberNode += String.fromCharCode(c);
451
+ } else {
452
+ this._closeNumber();
453
+
454
+ i--;
455
+ this.state = this.stack.pop() || STATE.VALUE;
359
456
  }
360
- }
361
-
362
- this.slashed = slashed;
363
- this.unicodeI = unicodeI;
364
- continue;
365
-
366
- case STATE.TRUE:
367
- if (c === Char.r) this.state = STATE.TRUE2;else this._error("Invalid true started with t".concat(c));
368
- continue;
369
-
370
- case STATE.TRUE2:
371
- if (c === Char.u) this.state = STATE.TRUE3;else this._error("Invalid true started with tr".concat(c));
372
- continue;
373
-
374
- case STATE.TRUE3:
375
- if (c === Char.e) {
376
- this.emit('onvalue', true);
377
- this.state = this.stack.pop() || STATE.VALUE;
378
- } else this._error("Invalid true started with tru".concat(c));
379
-
380
- continue;
381
-
382
- case STATE.FALSE:
383
- if (c === Char.a) this.state = STATE.FALSE2;else this._error("Invalid false started with f".concat(c));
384
- continue;
385
-
386
- case STATE.FALSE2:
387
- if (c === Char.l) this.state = STATE.FALSE3;else this._error("Invalid false started with fa".concat(c));
388
- continue;
389
-
390
- case STATE.FALSE3:
391
- if (c === Char.s) this.state = STATE.FALSE4;else this._error("Invalid false started with fal".concat(c));
392
- continue;
393
-
394
- case STATE.FALSE4:
395
- if (c === Char.e) {
396
- this.emit('onvalue', false);
397
- this.state = this.stack.pop() || STATE.VALUE;
398
- } else this._error("Invalid false started with fals".concat(c));
399
-
400
- continue;
401
-
402
- case STATE.NULL:
403
- if (c === Char.u) this.state = STATE.NULL2;else this._error("Invalid null started with n".concat(c));
404
- continue;
405
-
406
- case STATE.NULL2:
407
- if (c === Char.l) this.state = STATE.NULL3;else this._error("Invalid null started with nu".concat(c));
408
- continue;
409
-
410
- case STATE.NULL3:
411
- if (c === Char.l) {
412
- this.emit('onvalue', null);
413
- this.state = this.stack.pop() || STATE.VALUE;
414
- } else this._error("Invalid null started with nul".concat(c));
415
-
416
- continue;
417
-
418
- case STATE.NUMBER_DECIMAL_POINT:
419
- if (c === Char.period) {
420
- this.numberNode += '.';
421
- this.state = STATE.NUMBER_DIGIT;
422
- } else this._error('Leading zero not followed by .');
423
-
424
- continue;
425
-
426
- case STATE.NUMBER_DIGIT:
427
- if (Char._0 <= c && c <= Char._9) this.numberNode += String.fromCharCode(c);else if (c === Char.period) {
428
- if (this.numberNode.indexOf('.') !== -1) this._error('Invalid number has two dots');
429
- this.numberNode += '.';
430
- } else if (c === Char.e || c === Char.E) {
431
- if (this.numberNode.indexOf('e') !== -1 || this.numberNode.indexOf('E') !== -1) this._error('Invalid number has two exponential');
432
- this.numberNode += 'e';
433
- } else if (c === Char.plus || c === Char.minus) {
434
- if (!(p === Char.e || p === Char.E)) this._error('Invalid symbol in number');
435
- this.numberNode += String.fromCharCode(c);
436
- } else {
437
- this._closeNumber();
438
-
439
- i--;
440
- this.state = this.stack.pop() || STATE.VALUE;
441
- }
442
- continue;
457
+ continue;
443
458
 
444
- default:
445
- this._error("Unknown state: ".concat(this.state));
459
+ default:
460
+ this._error("Unknown state: ".concat(this.state));
446
461
 
462
+ }
447
463
  }
448
- }
449
-
450
- if (this.position >= this.bufferCheckPosition) {
451
- checkBufferLength(this);
452
- }
453
464
 
454
- this.emit('onchunkparsed');
455
- return this;
456
- }
465
+ if (this.position >= this.bufferCheckPosition) {
466
+ checkBufferLength(this);
467
+ }
457
468
 
458
- _closeValue(event = 'onvalue') {
459
- if (this.textNode !== undefined) {
460
- this.emit(event, this.textNode);
469
+ this.emit('onchunkparsed');
470
+ return this;
461
471
  }
472
+ }, {
473
+ key: "_closeValue",
474
+ value: function _closeValue() {
475
+ var event = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'onvalue';
462
476
 
463
- this.textNode = undefined;
464
- }
465
-
466
- _closeNumber() {
467
- if (this.numberNode) this.emit('onvalue', parseFloat(this.numberNode));
468
- this.numberNode = '';
469
- }
477
+ if (this.textNode !== undefined) {
478
+ this.emit(event, this.textNode);
479
+ }
470
480
 
471
- _error(message = '') {
472
- this._closeValue();
481
+ this.textNode = undefined;
482
+ }
483
+ }, {
484
+ key: "_closeNumber",
485
+ value: function _closeNumber() {
486
+ if (this.numberNode) this.emit('onvalue', parseFloat(this.numberNode));
487
+ this.numberNode = '';
488
+ }
489
+ }, {
490
+ key: "_error",
491
+ value: function _error() {
492
+ var message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
473
493
 
474
- message += "\nLine: ".concat(this.line, "\nColumn: ").concat(this.column, "\nChar: ").concat(this.c);
475
- const error = new Error(message);
476
- this.error = error;
477
- this.emit('onerror', error);
478
- }
494
+ this._closeValue();
479
495
 
480
- }
496
+ message += "\nLine: ".concat(this.line, "\nColumn: ").concat(this.column, "\nChar: ").concat(this.c);
497
+ var error = new Error(message);
498
+ this.error = error;
499
+ this.emit('onerror', error);
500
+ }
501
+ }]);
502
+ return ClarinetParser;
503
+ }();
481
504
 
482
505
  exports.default = ClarinetParser;
483
506
 
@@ -486,11 +509,12 @@ function isWhitespace(c) {
486
509
  }
487
510
 
488
511
  function checkBufferLength(parser) {
489
- const maxAllowed = Math.max(MAX_BUFFER_LENGTH, 10);
490
- let maxActual = 0;
512
+ var maxAllowed = Math.max(MAX_BUFFER_LENGTH, 10);
513
+ var maxActual = 0;
491
514
 
492
- for (const buffer of ['textNode', 'numberNode']) {
493
- const len = parser[buffer] === undefined ? 0 : parser[buffer].length;
515
+ for (var _i = 0, _arr = ['textNode', 'numberNode']; _i < _arr.length; _i++) {
516
+ var buffer = _arr[_i];
517
+ var len = parser[buffer] === undefined ? 0 : parser[buffer].length;
494
518
 
495
519
  if (len > maxAllowed) {
496
520
  switch (buffer) {