@codingame/monaco-vscode-npm-default-extension 1.82.6 → 1.83.1
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.
- package/index.js +1 -1
- package/npmBrowserMain.js +692 -466
- package/npmBrowserMain.js.map +1 -1
- package/package.json +2 -2
package/npmBrowserMain.js
CHANGED
|
@@ -163,6 +163,9 @@ exports.xhrDisabled = xhrDisabled;
|
|
|
163
163
|
"use strict";
|
|
164
164
|
__webpack_require__.r(__webpack_exports__);
|
|
165
165
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
166
|
+
/* harmony export */ "ParseErrorCode": () => (/* binding */ ParseErrorCode),
|
|
167
|
+
/* harmony export */ "ScanError": () => (/* binding */ ScanError),
|
|
168
|
+
/* harmony export */ "SyntaxKind": () => (/* binding */ SyntaxKind),
|
|
166
169
|
/* harmony export */ "applyEdits": () => (/* binding */ applyEdits),
|
|
167
170
|
/* harmony export */ "createScanner": () => (/* binding */ createScanner),
|
|
168
171
|
/* harmony export */ "findNodeAtLocation": () => (/* binding */ findNodeAtLocation),
|
|
@@ -195,84 +198,130 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
195
198
|
* Creates a JSON scanner on the given text.
|
|
196
199
|
* If ignoreTrivia is set, whitespaces or comments are ignored.
|
|
197
200
|
*/
|
|
198
|
-
|
|
201
|
+
const createScanner = _impl_scanner__WEBPACK_IMPORTED_MODULE_2__.createScanner;
|
|
202
|
+
var ScanError;
|
|
203
|
+
(function (ScanError) {
|
|
204
|
+
ScanError[ScanError["None"] = 0] = "None";
|
|
205
|
+
ScanError[ScanError["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
|
206
|
+
ScanError[ScanError["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
|
207
|
+
ScanError[ScanError["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
|
208
|
+
ScanError[ScanError["InvalidUnicode"] = 4] = "InvalidUnicode";
|
|
209
|
+
ScanError[ScanError["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
|
210
|
+
ScanError[ScanError["InvalidCharacter"] = 6] = "InvalidCharacter";
|
|
211
|
+
})(ScanError || (ScanError = {}));
|
|
212
|
+
var SyntaxKind;
|
|
213
|
+
(function (SyntaxKind) {
|
|
214
|
+
SyntaxKind[SyntaxKind["OpenBraceToken"] = 1] = "OpenBraceToken";
|
|
215
|
+
SyntaxKind[SyntaxKind["CloseBraceToken"] = 2] = "CloseBraceToken";
|
|
216
|
+
SyntaxKind[SyntaxKind["OpenBracketToken"] = 3] = "OpenBracketToken";
|
|
217
|
+
SyntaxKind[SyntaxKind["CloseBracketToken"] = 4] = "CloseBracketToken";
|
|
218
|
+
SyntaxKind[SyntaxKind["CommaToken"] = 5] = "CommaToken";
|
|
219
|
+
SyntaxKind[SyntaxKind["ColonToken"] = 6] = "ColonToken";
|
|
220
|
+
SyntaxKind[SyntaxKind["NullKeyword"] = 7] = "NullKeyword";
|
|
221
|
+
SyntaxKind[SyntaxKind["TrueKeyword"] = 8] = "TrueKeyword";
|
|
222
|
+
SyntaxKind[SyntaxKind["FalseKeyword"] = 9] = "FalseKeyword";
|
|
223
|
+
SyntaxKind[SyntaxKind["StringLiteral"] = 10] = "StringLiteral";
|
|
224
|
+
SyntaxKind[SyntaxKind["NumericLiteral"] = 11] = "NumericLiteral";
|
|
225
|
+
SyntaxKind[SyntaxKind["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
|
226
|
+
SyntaxKind[SyntaxKind["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
|
227
|
+
SyntaxKind[SyntaxKind["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
|
228
|
+
SyntaxKind[SyntaxKind["Trivia"] = 15] = "Trivia";
|
|
229
|
+
SyntaxKind[SyntaxKind["Unknown"] = 16] = "Unknown";
|
|
230
|
+
SyntaxKind[SyntaxKind["EOF"] = 17] = "EOF";
|
|
231
|
+
})(SyntaxKind || (SyntaxKind = {}));
|
|
199
232
|
/**
|
|
200
233
|
* For a given offset, evaluate the location in the JSON document. Each segment in the location path is either a property name or an array index.
|
|
201
234
|
*/
|
|
202
|
-
|
|
235
|
+
const getLocation = _impl_parser__WEBPACK_IMPORTED_MODULE_3__.getLocation;
|
|
203
236
|
/**
|
|
204
237
|
* Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
|
|
205
238
|
* Therefore, always check the errors list to find out if the input was valid.
|
|
206
239
|
*/
|
|
207
|
-
|
|
240
|
+
const parse = _impl_parser__WEBPACK_IMPORTED_MODULE_3__.parse;
|
|
208
241
|
/**
|
|
209
242
|
* Parses the given text and returns a tree representation the JSON content. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
|
|
210
243
|
*/
|
|
211
|
-
|
|
244
|
+
const parseTree = _impl_parser__WEBPACK_IMPORTED_MODULE_3__.parseTree;
|
|
212
245
|
/**
|
|
213
246
|
* Finds the node at the given path in a JSON DOM.
|
|
214
247
|
*/
|
|
215
|
-
|
|
248
|
+
const findNodeAtLocation = _impl_parser__WEBPACK_IMPORTED_MODULE_3__.findNodeAtLocation;
|
|
216
249
|
/**
|
|
217
250
|
* Finds the innermost node at the given offset. If includeRightBound is set, also finds nodes that end at the given offset.
|
|
218
251
|
*/
|
|
219
|
-
|
|
252
|
+
const findNodeAtOffset = _impl_parser__WEBPACK_IMPORTED_MODULE_3__.findNodeAtOffset;
|
|
220
253
|
/**
|
|
221
254
|
* Gets the JSON path of the given JSON DOM node
|
|
222
255
|
*/
|
|
223
|
-
|
|
256
|
+
const getNodePath = _impl_parser__WEBPACK_IMPORTED_MODULE_3__.getNodePath;
|
|
224
257
|
/**
|
|
225
258
|
* Evaluates the JavaScript object of the given JSON DOM node
|
|
226
259
|
*/
|
|
227
|
-
|
|
260
|
+
const getNodeValue = _impl_parser__WEBPACK_IMPORTED_MODULE_3__.getNodeValue;
|
|
228
261
|
/**
|
|
229
262
|
* Parses the given text and invokes the visitor functions for each object, array and literal reached.
|
|
230
263
|
*/
|
|
231
|
-
|
|
264
|
+
const visit = _impl_parser__WEBPACK_IMPORTED_MODULE_3__.visit;
|
|
232
265
|
/**
|
|
233
266
|
* Takes JSON with JavaScript-style comments and remove
|
|
234
267
|
* them. Optionally replaces every none-newline character
|
|
235
268
|
* of comments with a replaceCharacter
|
|
236
269
|
*/
|
|
237
|
-
|
|
270
|
+
const stripComments = _impl_parser__WEBPACK_IMPORTED_MODULE_3__.stripComments;
|
|
271
|
+
var ParseErrorCode;
|
|
272
|
+
(function (ParseErrorCode) {
|
|
273
|
+
ParseErrorCode[ParseErrorCode["InvalidSymbol"] = 1] = "InvalidSymbol";
|
|
274
|
+
ParseErrorCode[ParseErrorCode["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
|
275
|
+
ParseErrorCode[ParseErrorCode["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
|
276
|
+
ParseErrorCode[ParseErrorCode["ValueExpected"] = 4] = "ValueExpected";
|
|
277
|
+
ParseErrorCode[ParseErrorCode["ColonExpected"] = 5] = "ColonExpected";
|
|
278
|
+
ParseErrorCode[ParseErrorCode["CommaExpected"] = 6] = "CommaExpected";
|
|
279
|
+
ParseErrorCode[ParseErrorCode["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
|
280
|
+
ParseErrorCode[ParseErrorCode["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
|
281
|
+
ParseErrorCode[ParseErrorCode["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
|
282
|
+
ParseErrorCode[ParseErrorCode["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
|
283
|
+
ParseErrorCode[ParseErrorCode["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
|
284
|
+
ParseErrorCode[ParseErrorCode["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
|
285
|
+
ParseErrorCode[ParseErrorCode["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
|
286
|
+
ParseErrorCode[ParseErrorCode["InvalidUnicode"] = 14] = "InvalidUnicode";
|
|
287
|
+
ParseErrorCode[ParseErrorCode["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
|
288
|
+
ParseErrorCode[ParseErrorCode["InvalidCharacter"] = 16] = "InvalidCharacter";
|
|
289
|
+
})(ParseErrorCode || (ParseErrorCode = {}));
|
|
238
290
|
function printParseErrorCode(code) {
|
|
239
291
|
switch (code) {
|
|
240
|
-
case 1 /* InvalidSymbol */: return 'InvalidSymbol';
|
|
241
|
-
case 2 /* InvalidNumberFormat */: return 'InvalidNumberFormat';
|
|
242
|
-
case 3 /* PropertyNameExpected */: return 'PropertyNameExpected';
|
|
243
|
-
case 4 /* ValueExpected */: return 'ValueExpected';
|
|
244
|
-
case 5 /* ColonExpected */: return 'ColonExpected';
|
|
245
|
-
case 6 /* CommaExpected */: return 'CommaExpected';
|
|
246
|
-
case 7 /* CloseBraceExpected */: return 'CloseBraceExpected';
|
|
247
|
-
case 8 /* CloseBracketExpected */: return 'CloseBracketExpected';
|
|
248
|
-
case 9 /* EndOfFileExpected */: return 'EndOfFileExpected';
|
|
249
|
-
case 10 /* InvalidCommentToken */: return 'InvalidCommentToken';
|
|
250
|
-
case 11 /* UnexpectedEndOfComment */: return 'UnexpectedEndOfComment';
|
|
251
|
-
case 12 /* UnexpectedEndOfString */: return 'UnexpectedEndOfString';
|
|
252
|
-
case 13 /* UnexpectedEndOfNumber */: return 'UnexpectedEndOfNumber';
|
|
253
|
-
case 14 /* InvalidUnicode */: return 'InvalidUnicode';
|
|
254
|
-
case 15 /* InvalidEscapeCharacter */: return 'InvalidEscapeCharacter';
|
|
255
|
-
case 16 /* InvalidCharacter */: return 'InvalidCharacter';
|
|
292
|
+
case 1 /* ParseErrorCode.InvalidSymbol */: return 'InvalidSymbol';
|
|
293
|
+
case 2 /* ParseErrorCode.InvalidNumberFormat */: return 'InvalidNumberFormat';
|
|
294
|
+
case 3 /* ParseErrorCode.PropertyNameExpected */: return 'PropertyNameExpected';
|
|
295
|
+
case 4 /* ParseErrorCode.ValueExpected */: return 'ValueExpected';
|
|
296
|
+
case 5 /* ParseErrorCode.ColonExpected */: return 'ColonExpected';
|
|
297
|
+
case 6 /* ParseErrorCode.CommaExpected */: return 'CommaExpected';
|
|
298
|
+
case 7 /* ParseErrorCode.CloseBraceExpected */: return 'CloseBraceExpected';
|
|
299
|
+
case 8 /* ParseErrorCode.CloseBracketExpected */: return 'CloseBracketExpected';
|
|
300
|
+
case 9 /* ParseErrorCode.EndOfFileExpected */: return 'EndOfFileExpected';
|
|
301
|
+
case 10 /* ParseErrorCode.InvalidCommentToken */: return 'InvalidCommentToken';
|
|
302
|
+
case 11 /* ParseErrorCode.UnexpectedEndOfComment */: return 'UnexpectedEndOfComment';
|
|
303
|
+
case 12 /* ParseErrorCode.UnexpectedEndOfString */: return 'UnexpectedEndOfString';
|
|
304
|
+
case 13 /* ParseErrorCode.UnexpectedEndOfNumber */: return 'UnexpectedEndOfNumber';
|
|
305
|
+
case 14 /* ParseErrorCode.InvalidUnicode */: return 'InvalidUnicode';
|
|
306
|
+
case 15 /* ParseErrorCode.InvalidEscapeCharacter */: return 'InvalidEscapeCharacter';
|
|
307
|
+
case 16 /* ParseErrorCode.InvalidCharacter */: return 'InvalidCharacter';
|
|
256
308
|
}
|
|
257
309
|
return '<unknown ParseErrorCode>';
|
|
258
310
|
}
|
|
259
311
|
/**
|
|
260
|
-
* Computes the
|
|
312
|
+
* Computes the edit operations needed to format a JSON document.
|
|
261
313
|
*
|
|
262
314
|
* @param documentText The input text
|
|
263
315
|
* @param range The range to format or `undefined` to format the full content
|
|
264
316
|
* @param options The formatting options
|
|
265
|
-
* @returns
|
|
266
|
-
*
|
|
267
|
-
* text in the original document. However, multiple edits can have
|
|
268
|
-
* the same offset, for example multiple inserts, or an insert followed by a remove or replace. The order in the array defines which edit is applied first.
|
|
269
|
-
* To apply edits to an input, you can use `applyEdits`.
|
|
317
|
+
* @returns The edit operations describing the formatting changes to the original document following the format described in {@linkcode EditResult}.
|
|
318
|
+
* To apply the edit operations to the input, use {@linkcode applyEdits}.
|
|
270
319
|
*/
|
|
271
320
|
function format(documentText, range, options) {
|
|
272
321
|
return _impl_format__WEBPACK_IMPORTED_MODULE_0__.format(documentText, range, options);
|
|
273
322
|
}
|
|
274
323
|
/**
|
|
275
|
-
* Computes the
|
|
324
|
+
* Computes the edit operations needed to modify a value in the JSON document.
|
|
276
325
|
*
|
|
277
326
|
* @param documentText The input text
|
|
278
327
|
* @param path The path of the value to change. The path represents either to the document root, a property or an array item.
|
|
@@ -280,21 +329,37 @@ function format(documentText, range, options) {
|
|
|
280
329
|
* @param value The new value for the specified property or item. If the value is undefined,
|
|
281
330
|
* the property or item will be removed.
|
|
282
331
|
* @param options Options
|
|
283
|
-
* @returns
|
|
284
|
-
*
|
|
285
|
-
* text in the original document. However, multiple edits can have
|
|
286
|
-
* the same offset, for example multiple inserts, or an insert followed by a remove or replace. The order in the array defines which edit is applied first.
|
|
287
|
-
* To apply edits to an input, you can use `applyEdits`.
|
|
332
|
+
* @returns The edit operations describing the changes to the original document, following the format described in {@linkcode EditResult}.
|
|
333
|
+
* To apply the edit operations to the input, use {@linkcode applyEdits}.
|
|
288
334
|
*/
|
|
289
335
|
function modify(text, path, value, options) {
|
|
290
|
-
return _impl_edit__WEBPACK_IMPORTED_MODULE_1__.setProperty(text, path, value, options
|
|
336
|
+
return _impl_edit__WEBPACK_IMPORTED_MODULE_1__.setProperty(text, path, value, options);
|
|
291
337
|
}
|
|
292
338
|
/**
|
|
293
|
-
* Applies edits to
|
|
339
|
+
* Applies edits to an input string.
|
|
340
|
+
* @param text The input text
|
|
341
|
+
* @param edits Edit operations following the format described in {@linkcode EditResult}.
|
|
342
|
+
* @returns The text with the applied edits.
|
|
343
|
+
* @throws An error if the edit operations are not well-formed as described in {@linkcode EditResult}.
|
|
294
344
|
*/
|
|
295
345
|
function applyEdits(text, edits) {
|
|
296
|
-
|
|
297
|
-
|
|
346
|
+
let sortedEdits = edits.slice(0).sort((a, b) => {
|
|
347
|
+
const diff = a.offset - b.offset;
|
|
348
|
+
if (diff === 0) {
|
|
349
|
+
return a.length - b.length;
|
|
350
|
+
}
|
|
351
|
+
return diff;
|
|
352
|
+
});
|
|
353
|
+
let lastModifiedOffset = text.length;
|
|
354
|
+
for (let i = sortedEdits.length - 1; i >= 0; i--) {
|
|
355
|
+
let e = sortedEdits[i];
|
|
356
|
+
if (e.offset + e.length <= lastModifiedOffset) {
|
|
357
|
+
text = _impl_edit__WEBPACK_IMPORTED_MODULE_1__.applyEdit(text, e);
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
throw new Error('Overlapping edit');
|
|
361
|
+
}
|
|
362
|
+
lastModifiedOffset = e.offset;
|
|
298
363
|
}
|
|
299
364
|
return text;
|
|
300
365
|
}
|
|
@@ -318,11 +383,11 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
318
383
|
|
|
319
384
|
|
|
320
385
|
function format(documentText, range, options) {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
386
|
+
let initialIndentLevel;
|
|
387
|
+
let formatText;
|
|
388
|
+
let formatTextStart;
|
|
389
|
+
let rangeStart;
|
|
390
|
+
let rangeEnd;
|
|
326
391
|
if (range) {
|
|
327
392
|
rangeStart = range.offset;
|
|
328
393
|
rangeEnd = rangeStart + range.length;
|
|
@@ -330,7 +395,7 @@ function format(documentText, range, options) {
|
|
|
330
395
|
while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
|
|
331
396
|
formatTextStart--;
|
|
332
397
|
}
|
|
333
|
-
|
|
398
|
+
let endOffset = rangeEnd;
|
|
334
399
|
while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
|
|
335
400
|
endOffset++;
|
|
336
401
|
}
|
|
@@ -344,136 +409,193 @@ function format(documentText, range, options) {
|
|
|
344
409
|
rangeStart = 0;
|
|
345
410
|
rangeEnd = documentText.length;
|
|
346
411
|
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
412
|
+
const eol = getEOL(options, documentText);
|
|
413
|
+
let numberLineBreaks = 0;
|
|
414
|
+
let indentLevel = 0;
|
|
415
|
+
let indentValue;
|
|
351
416
|
if (options.insertSpaces) {
|
|
352
417
|
indentValue = repeat(' ', options.tabSize || 4);
|
|
353
418
|
}
|
|
354
419
|
else {
|
|
355
420
|
indentValue = '\t';
|
|
356
421
|
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
function
|
|
360
|
-
|
|
422
|
+
let scanner = (0,_scanner__WEBPACK_IMPORTED_MODULE_0__.createScanner)(formatText, false);
|
|
423
|
+
let hasError = false;
|
|
424
|
+
function newLinesAndIndent() {
|
|
425
|
+
if (numberLineBreaks > 1) {
|
|
426
|
+
return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
427
|
+
}
|
|
428
|
+
else {
|
|
429
|
+
return eol + repeat(indentValue, initialIndentLevel + indentLevel);
|
|
430
|
+
}
|
|
361
431
|
}
|
|
362
432
|
function scanNext() {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
while (token === 15 /* Trivia */ || token === 14 /* LineBreakTrivia */) {
|
|
366
|
-
|
|
433
|
+
let token = scanner.scan();
|
|
434
|
+
numberLineBreaks = 0;
|
|
435
|
+
while (token === 15 /* SyntaxKind.Trivia */ || token === 14 /* SyntaxKind.LineBreakTrivia */) {
|
|
436
|
+
if (token === 14 /* SyntaxKind.LineBreakTrivia */ && options.keepLines) {
|
|
437
|
+
numberLineBreaks += 1;
|
|
438
|
+
}
|
|
439
|
+
else if (token === 14 /* SyntaxKind.LineBreakTrivia */) {
|
|
440
|
+
numberLineBreaks = 1;
|
|
441
|
+
}
|
|
367
442
|
token = scanner.scan();
|
|
368
443
|
}
|
|
369
|
-
hasError = token === 16 /* Unknown */ || scanner.getTokenError() !== 0 /* None */;
|
|
444
|
+
hasError = token === 16 /* SyntaxKind.Unknown */ || scanner.getTokenError() !== 0 /* ScanError.None */;
|
|
370
445
|
return token;
|
|
371
446
|
}
|
|
372
|
-
|
|
447
|
+
const editOperations = [];
|
|
373
448
|
function addEdit(text, startOffset, endOffset) {
|
|
374
|
-
if (!hasError && startOffset < rangeEnd && endOffset > rangeStart && documentText.substring(startOffset, endOffset) !== text) {
|
|
449
|
+
if (!hasError && (!range || (startOffset < rangeEnd && endOffset > rangeStart)) && documentText.substring(startOffset, endOffset) !== text) {
|
|
375
450
|
editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text });
|
|
376
451
|
}
|
|
377
452
|
}
|
|
378
|
-
|
|
379
|
-
if (
|
|
380
|
-
|
|
381
|
-
|
|
453
|
+
let firstToken = scanNext();
|
|
454
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
455
|
+
addEdit(repeat(eol, numberLineBreaks), 0, 0);
|
|
456
|
+
}
|
|
457
|
+
if (firstToken !== 17 /* SyntaxKind.EOF */) {
|
|
458
|
+
let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
459
|
+
let initialIndent = repeat(indentValue, initialIndentLevel);
|
|
382
460
|
addEdit(initialIndent, formatTextStart, firstTokenStart);
|
|
383
461
|
}
|
|
384
|
-
while (firstToken !== 17 /* EOF */) {
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
462
|
+
while (firstToken !== 17 /* SyntaxKind.EOF */) {
|
|
463
|
+
let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
464
|
+
let secondToken = scanNext();
|
|
465
|
+
let replaceContent = '';
|
|
466
|
+
let needsLineBreak = false;
|
|
467
|
+
while (numberLineBreaks === 0 && (secondToken === 12 /* SyntaxKind.LineCommentTrivia */ || secondToken === 13 /* SyntaxKind.BlockCommentTrivia */)) {
|
|
468
|
+
let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
391
469
|
addEdit(' ', firstTokenEnd, commentTokenStart);
|
|
392
470
|
firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
|
|
393
|
-
|
|
471
|
+
needsLineBreak = secondToken === 12 /* SyntaxKind.LineCommentTrivia */;
|
|
472
|
+
replaceContent = needsLineBreak ? newLinesAndIndent() : '';
|
|
394
473
|
secondToken = scanNext();
|
|
395
474
|
}
|
|
396
|
-
if (secondToken === 2 /* CloseBraceToken */) {
|
|
397
|
-
if (firstToken !== 1 /* OpenBraceToken */) {
|
|
475
|
+
if (secondToken === 2 /* SyntaxKind.CloseBraceToken */) {
|
|
476
|
+
if (firstToken !== 1 /* SyntaxKind.OpenBraceToken */) {
|
|
398
477
|
indentLevel--;
|
|
399
|
-
|
|
478
|
+
}
|
|
479
|
+
;
|
|
480
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1 /* SyntaxKind.OpenBraceToken */) {
|
|
481
|
+
replaceContent = newLinesAndIndent();
|
|
482
|
+
}
|
|
483
|
+
else if (options.keepLines) {
|
|
484
|
+
replaceContent = ' ';
|
|
400
485
|
}
|
|
401
486
|
}
|
|
402
|
-
else if (secondToken === 4 /* CloseBracketToken */) {
|
|
403
|
-
if (firstToken !== 3 /* OpenBracketToken */) {
|
|
487
|
+
else if (secondToken === 4 /* SyntaxKind.CloseBracketToken */) {
|
|
488
|
+
if (firstToken !== 3 /* SyntaxKind.OpenBracketToken */) {
|
|
404
489
|
indentLevel--;
|
|
405
|
-
|
|
490
|
+
}
|
|
491
|
+
;
|
|
492
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3 /* SyntaxKind.OpenBracketToken */) {
|
|
493
|
+
replaceContent = newLinesAndIndent();
|
|
494
|
+
}
|
|
495
|
+
else if (options.keepLines) {
|
|
496
|
+
replaceContent = ' ';
|
|
406
497
|
}
|
|
407
498
|
}
|
|
408
499
|
else {
|
|
409
500
|
switch (firstToken) {
|
|
410
|
-
case 3 /* OpenBracketToken */:
|
|
411
|
-
case 1 /* OpenBraceToken */:
|
|
501
|
+
case 3 /* SyntaxKind.OpenBracketToken */:
|
|
502
|
+
case 1 /* SyntaxKind.OpenBraceToken */:
|
|
412
503
|
indentLevel++;
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
504
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
505
|
+
replaceContent = newLinesAndIndent();
|
|
506
|
+
}
|
|
507
|
+
else {
|
|
508
|
+
replaceContent = ' ';
|
|
509
|
+
}
|
|
418
510
|
break;
|
|
419
|
-
case
|
|
420
|
-
if (
|
|
421
|
-
replaceContent =
|
|
511
|
+
case 5 /* SyntaxKind.CommaToken */:
|
|
512
|
+
if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
|
|
513
|
+
replaceContent = newLinesAndIndent();
|
|
422
514
|
}
|
|
423
515
|
else {
|
|
424
|
-
// symbol following comment on the same line: keep on same line, separate with ' '
|
|
425
516
|
replaceContent = ' ';
|
|
426
517
|
}
|
|
427
518
|
break;
|
|
428
|
-
case
|
|
429
|
-
replaceContent =
|
|
519
|
+
case 12 /* SyntaxKind.LineCommentTrivia */:
|
|
520
|
+
replaceContent = newLinesAndIndent();
|
|
430
521
|
break;
|
|
431
|
-
case
|
|
432
|
-
if (
|
|
433
|
-
replaceContent =
|
|
434
|
-
|
|
522
|
+
case 13 /* SyntaxKind.BlockCommentTrivia */:
|
|
523
|
+
if (numberLineBreaks > 0) {
|
|
524
|
+
replaceContent = newLinesAndIndent();
|
|
525
|
+
}
|
|
526
|
+
else if (!needsLineBreak) {
|
|
527
|
+
replaceContent = ' ';
|
|
435
528
|
}
|
|
436
|
-
|
|
437
|
-
case
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
case 4 /* CloseBracketToken */:
|
|
443
|
-
if (secondToken === 12 /* LineCommentTrivia */ || secondToken === 13 /* BlockCommentTrivia */) {
|
|
529
|
+
break;
|
|
530
|
+
case 6 /* SyntaxKind.ColonToken */:
|
|
531
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
532
|
+
replaceContent = newLinesAndIndent();
|
|
533
|
+
}
|
|
534
|
+
else if (!needsLineBreak) {
|
|
444
535
|
replaceContent = ' ';
|
|
445
536
|
}
|
|
446
|
-
|
|
447
|
-
|
|
537
|
+
break;
|
|
538
|
+
case 10 /* SyntaxKind.StringLiteral */:
|
|
539
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
540
|
+
replaceContent = newLinesAndIndent();
|
|
541
|
+
}
|
|
542
|
+
else if (secondToken === 6 /* SyntaxKind.ColonToken */ && !needsLineBreak) {
|
|
543
|
+
replaceContent = '';
|
|
448
544
|
}
|
|
449
545
|
break;
|
|
450
|
-
case
|
|
546
|
+
case 7 /* SyntaxKind.NullKeyword */:
|
|
547
|
+
case 8 /* SyntaxKind.TrueKeyword */:
|
|
548
|
+
case 9 /* SyntaxKind.FalseKeyword */:
|
|
549
|
+
case 11 /* SyntaxKind.NumericLiteral */:
|
|
550
|
+
case 2 /* SyntaxKind.CloseBraceToken */:
|
|
551
|
+
case 4 /* SyntaxKind.CloseBracketToken */:
|
|
552
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
553
|
+
replaceContent = newLinesAndIndent();
|
|
554
|
+
}
|
|
555
|
+
else {
|
|
556
|
+
if ((secondToken === 12 /* SyntaxKind.LineCommentTrivia */ || secondToken === 13 /* SyntaxKind.BlockCommentTrivia */) && !needsLineBreak) {
|
|
557
|
+
replaceContent = ' ';
|
|
558
|
+
}
|
|
559
|
+
else if (secondToken !== 5 /* SyntaxKind.CommaToken */ && secondToken !== 17 /* SyntaxKind.EOF */) {
|
|
560
|
+
hasError = true;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
break;
|
|
564
|
+
case 16 /* SyntaxKind.Unknown */:
|
|
451
565
|
hasError = true;
|
|
452
566
|
break;
|
|
453
567
|
}
|
|
454
|
-
if (
|
|
455
|
-
replaceContent =
|
|
568
|
+
if (numberLineBreaks > 0 && (secondToken === 12 /* SyntaxKind.LineCommentTrivia */ || secondToken === 13 /* SyntaxKind.BlockCommentTrivia */)) {
|
|
569
|
+
replaceContent = newLinesAndIndent();
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
if (secondToken === 17 /* SyntaxKind.EOF */) {
|
|
573
|
+
if (options.keepLines && numberLineBreaks > 0) {
|
|
574
|
+
replaceContent = newLinesAndIndent();
|
|
575
|
+
}
|
|
576
|
+
else {
|
|
577
|
+
replaceContent = options.insertFinalNewline ? eol : '';
|
|
456
578
|
}
|
|
457
579
|
}
|
|
458
|
-
|
|
580
|
+
const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
|
|
459
581
|
addEdit(replaceContent, firstTokenEnd, secondTokenStart);
|
|
460
582
|
firstToken = secondToken;
|
|
461
583
|
}
|
|
462
584
|
return editOperations;
|
|
463
585
|
}
|
|
464
586
|
function repeat(s, count) {
|
|
465
|
-
|
|
466
|
-
for (
|
|
587
|
+
let result = '';
|
|
588
|
+
for (let i = 0; i < count; i++) {
|
|
467
589
|
result += s;
|
|
468
590
|
}
|
|
469
591
|
return result;
|
|
470
592
|
}
|
|
471
593
|
function computeIndentLevel(content, options) {
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
594
|
+
let i = 0;
|
|
595
|
+
let nChars = 0;
|
|
596
|
+
const tabSize = options.tabSize || 4;
|
|
475
597
|
while (i < content.length) {
|
|
476
|
-
|
|
598
|
+
let ch = content.charAt(i);
|
|
477
599
|
if (ch === ' ') {
|
|
478
600
|
nChars++;
|
|
479
601
|
}
|
|
@@ -488,8 +610,8 @@ function computeIndentLevel(content, options) {
|
|
|
488
610
|
return Math.floor(nChars / tabSize);
|
|
489
611
|
}
|
|
490
612
|
function getEOL(options, text) {
|
|
491
|
-
for (
|
|
492
|
-
|
|
613
|
+
for (let i = 0; i < text.length; i++) {
|
|
614
|
+
const ch = text.charAt(i);
|
|
493
615
|
if (ch === '\r') {
|
|
494
616
|
if (i + 1 < text.length && text.charAt(i + 1) === '\n') {
|
|
495
617
|
return '\r\n';
|
|
@@ -525,23 +647,22 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
525
647
|
* Creates a JSON scanner on the given text.
|
|
526
648
|
* If ignoreTrivia is set, whitespaces or comments are ignored.
|
|
527
649
|
*/
|
|
528
|
-
function createScanner(text, ignoreTrivia) {
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
var pos = 0, value = '', tokenOffset = 0, token = 16 /* Unknown */, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0 /* None */;
|
|
650
|
+
function createScanner(text, ignoreTrivia = false) {
|
|
651
|
+
const len = text.length;
|
|
652
|
+
let pos = 0, value = '', tokenOffset = 0, token = 16 /* SyntaxKind.Unknown */, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0 /* ScanError.None */;
|
|
532
653
|
function scanHexDigits(count, exact) {
|
|
533
|
-
|
|
534
|
-
|
|
654
|
+
let digits = 0;
|
|
655
|
+
let value = 0;
|
|
535
656
|
while (digits < count || !exact) {
|
|
536
|
-
|
|
537
|
-
if (ch >= 48 /* _0 */ && ch <= 57 /* _9 */) {
|
|
538
|
-
value = value * 16 + ch - 48 /* _0 */;
|
|
657
|
+
let ch = text.charCodeAt(pos);
|
|
658
|
+
if (ch >= 48 /* CharacterCodes._0 */ && ch <= 57 /* CharacterCodes._9 */) {
|
|
659
|
+
value = value * 16 + ch - 48 /* CharacterCodes._0 */;
|
|
539
660
|
}
|
|
540
|
-
else if (ch >= 65 /* A */ && ch <= 70 /* F */) {
|
|
541
|
-
value = value * 16 + ch - 65 /* A */ + 10;
|
|
661
|
+
else if (ch >= 65 /* CharacterCodes.A */ && ch <= 70 /* CharacterCodes.F */) {
|
|
662
|
+
value = value * 16 + ch - 65 /* CharacterCodes.A */ + 10;
|
|
542
663
|
}
|
|
543
|
-
else if (ch >= 97 /* a */ && ch <= 102 /* f */) {
|
|
544
|
-
value = value * 16 + ch - 97 /* a */ + 10;
|
|
664
|
+
else if (ch >= 97 /* CharacterCodes.a */ && ch <= 102 /* CharacterCodes.f */) {
|
|
665
|
+
value = value * 16 + ch - 97 /* CharacterCodes.a */ + 10;
|
|
545
666
|
}
|
|
546
667
|
else {
|
|
547
668
|
break;
|
|
@@ -558,12 +679,12 @@ function createScanner(text, ignoreTrivia) {
|
|
|
558
679
|
pos = newPosition;
|
|
559
680
|
value = '';
|
|
560
681
|
tokenOffset = 0;
|
|
561
|
-
token = 16 /* Unknown */;
|
|
562
|
-
scanError = 0 /* None */;
|
|
682
|
+
token = 16 /* SyntaxKind.Unknown */;
|
|
683
|
+
scanError = 0 /* ScanError.None */;
|
|
563
684
|
}
|
|
564
685
|
function scanNumber() {
|
|
565
|
-
|
|
566
|
-
if (text.charCodeAt(pos) === 48 /* _0 */) {
|
|
686
|
+
let start = pos;
|
|
687
|
+
if (text.charCodeAt(pos) === 48 /* CharacterCodes._0 */) {
|
|
567
688
|
pos++;
|
|
568
689
|
}
|
|
569
690
|
else {
|
|
@@ -572,7 +693,7 @@ function createScanner(text, ignoreTrivia) {
|
|
|
572
693
|
pos++;
|
|
573
694
|
}
|
|
574
695
|
}
|
|
575
|
-
if (pos < text.length && text.charCodeAt(pos) === 46 /* dot */) {
|
|
696
|
+
if (pos < text.length && text.charCodeAt(pos) === 46 /* CharacterCodes.dot */) {
|
|
576
697
|
pos++;
|
|
577
698
|
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
578
699
|
pos++;
|
|
@@ -581,14 +702,14 @@ function createScanner(text, ignoreTrivia) {
|
|
|
581
702
|
}
|
|
582
703
|
}
|
|
583
704
|
else {
|
|
584
|
-
scanError = 3 /* UnexpectedEndOfNumber */;
|
|
705
|
+
scanError = 3 /* ScanError.UnexpectedEndOfNumber */;
|
|
585
706
|
return text.substring(start, pos);
|
|
586
707
|
}
|
|
587
708
|
}
|
|
588
|
-
|
|
589
|
-
if (pos < text.length && (text.charCodeAt(pos) === 69 /* E */ || text.charCodeAt(pos) === 101 /* e */)) {
|
|
709
|
+
let end = pos;
|
|
710
|
+
if (pos < text.length && (text.charCodeAt(pos) === 69 /* CharacterCodes.E */ || text.charCodeAt(pos) === 101 /* CharacterCodes.e */)) {
|
|
590
711
|
pos++;
|
|
591
|
-
if (pos < text.length && text.charCodeAt(pos) === 43 /* plus */ || text.charCodeAt(pos) === 45 /* minus */) {
|
|
712
|
+
if (pos < text.length && text.charCodeAt(pos) === 43 /* CharacterCodes.plus */ || text.charCodeAt(pos) === 45 /* CharacterCodes.minus */) {
|
|
592
713
|
pos++;
|
|
593
714
|
}
|
|
594
715
|
if (pos < text.length && isDigit(text.charCodeAt(pos))) {
|
|
@@ -599,69 +720,69 @@ function createScanner(text, ignoreTrivia) {
|
|
|
599
720
|
end = pos;
|
|
600
721
|
}
|
|
601
722
|
else {
|
|
602
|
-
scanError = 3 /* UnexpectedEndOfNumber */;
|
|
723
|
+
scanError = 3 /* ScanError.UnexpectedEndOfNumber */;
|
|
603
724
|
}
|
|
604
725
|
}
|
|
605
726
|
return text.substring(start, end);
|
|
606
727
|
}
|
|
607
728
|
function scanString() {
|
|
608
|
-
|
|
729
|
+
let result = '', start = pos;
|
|
609
730
|
while (true) {
|
|
610
731
|
if (pos >= len) {
|
|
611
732
|
result += text.substring(start, pos);
|
|
612
|
-
scanError = 2 /* UnexpectedEndOfString */;
|
|
733
|
+
scanError = 2 /* ScanError.UnexpectedEndOfString */;
|
|
613
734
|
break;
|
|
614
735
|
}
|
|
615
|
-
|
|
616
|
-
if (ch === 34 /* doubleQuote */) {
|
|
736
|
+
const ch = text.charCodeAt(pos);
|
|
737
|
+
if (ch === 34 /* CharacterCodes.doubleQuote */) {
|
|
617
738
|
result += text.substring(start, pos);
|
|
618
739
|
pos++;
|
|
619
740
|
break;
|
|
620
741
|
}
|
|
621
|
-
if (ch === 92 /* backslash */) {
|
|
742
|
+
if (ch === 92 /* CharacterCodes.backslash */) {
|
|
622
743
|
result += text.substring(start, pos);
|
|
623
744
|
pos++;
|
|
624
745
|
if (pos >= len) {
|
|
625
|
-
scanError = 2 /* UnexpectedEndOfString */;
|
|
746
|
+
scanError = 2 /* ScanError.UnexpectedEndOfString */;
|
|
626
747
|
break;
|
|
627
748
|
}
|
|
628
|
-
|
|
749
|
+
const ch2 = text.charCodeAt(pos++);
|
|
629
750
|
switch (ch2) {
|
|
630
|
-
case 34 /* doubleQuote */:
|
|
751
|
+
case 34 /* CharacterCodes.doubleQuote */:
|
|
631
752
|
result += '\"';
|
|
632
753
|
break;
|
|
633
|
-
case 92 /* backslash */:
|
|
754
|
+
case 92 /* CharacterCodes.backslash */:
|
|
634
755
|
result += '\\';
|
|
635
756
|
break;
|
|
636
|
-
case 47 /* slash */:
|
|
757
|
+
case 47 /* CharacterCodes.slash */:
|
|
637
758
|
result += '/';
|
|
638
759
|
break;
|
|
639
|
-
case 98 /* b */:
|
|
760
|
+
case 98 /* CharacterCodes.b */:
|
|
640
761
|
result += '\b';
|
|
641
762
|
break;
|
|
642
|
-
case 102 /* f */:
|
|
763
|
+
case 102 /* CharacterCodes.f */:
|
|
643
764
|
result += '\f';
|
|
644
765
|
break;
|
|
645
|
-
case 110 /* n */:
|
|
766
|
+
case 110 /* CharacterCodes.n */:
|
|
646
767
|
result += '\n';
|
|
647
768
|
break;
|
|
648
|
-
case 114 /* r */:
|
|
769
|
+
case 114 /* CharacterCodes.r */:
|
|
649
770
|
result += '\r';
|
|
650
771
|
break;
|
|
651
|
-
case 116 /* t */:
|
|
772
|
+
case 116 /* CharacterCodes.t */:
|
|
652
773
|
result += '\t';
|
|
653
774
|
break;
|
|
654
|
-
case 117 /* u */:
|
|
655
|
-
|
|
775
|
+
case 117 /* CharacterCodes.u */:
|
|
776
|
+
const ch3 = scanHexDigits(4, true);
|
|
656
777
|
if (ch3 >= 0) {
|
|
657
778
|
result += String.fromCharCode(ch3);
|
|
658
779
|
}
|
|
659
780
|
else {
|
|
660
|
-
scanError = 4 /* InvalidUnicode */;
|
|
781
|
+
scanError = 4 /* ScanError.InvalidUnicode */;
|
|
661
782
|
}
|
|
662
783
|
break;
|
|
663
784
|
default:
|
|
664
|
-
scanError = 5 /* InvalidEscapeCharacter */;
|
|
785
|
+
scanError = 5 /* ScanError.InvalidEscapeCharacter */;
|
|
665
786
|
}
|
|
666
787
|
start = pos;
|
|
667
788
|
continue;
|
|
@@ -669,11 +790,11 @@ function createScanner(text, ignoreTrivia) {
|
|
|
669
790
|
if (ch >= 0 && ch <= 0x1f) {
|
|
670
791
|
if (isLineBreak(ch)) {
|
|
671
792
|
result += text.substring(start, pos);
|
|
672
|
-
scanError = 2 /* UnexpectedEndOfString */;
|
|
793
|
+
scanError = 2 /* ScanError.UnexpectedEndOfString */;
|
|
673
794
|
break;
|
|
674
795
|
}
|
|
675
796
|
else {
|
|
676
|
-
scanError = 6 /* InvalidCharacter */;
|
|
797
|
+
scanError = 6 /* ScanError.InvalidCharacter */;
|
|
677
798
|
// mark as error but continue with string
|
|
678
799
|
}
|
|
679
800
|
}
|
|
@@ -683,16 +804,16 @@ function createScanner(text, ignoreTrivia) {
|
|
|
683
804
|
}
|
|
684
805
|
function scanNext() {
|
|
685
806
|
value = '';
|
|
686
|
-
scanError = 0 /* None */;
|
|
807
|
+
scanError = 0 /* ScanError.None */;
|
|
687
808
|
tokenOffset = pos;
|
|
688
809
|
lineStartOffset = lineNumber;
|
|
689
810
|
prevTokenLineStartOffset = tokenLineStartOffset;
|
|
690
811
|
if (pos >= len) {
|
|
691
812
|
// at the end
|
|
692
813
|
tokenOffset = len;
|
|
693
|
-
return token = 17 /* EOF */;
|
|
814
|
+
return token = 17 /* SyntaxKind.EOF */;
|
|
694
815
|
}
|
|
695
|
-
|
|
816
|
+
let code = text.charCodeAt(pos);
|
|
696
817
|
// trivia: whitespace
|
|
697
818
|
if (isWhiteSpace(code)) {
|
|
698
819
|
do {
|
|
@@ -700,50 +821,50 @@ function createScanner(text, ignoreTrivia) {
|
|
|
700
821
|
value += String.fromCharCode(code);
|
|
701
822
|
code = text.charCodeAt(pos);
|
|
702
823
|
} while (isWhiteSpace(code));
|
|
703
|
-
return token = 15 /* Trivia */;
|
|
824
|
+
return token = 15 /* SyntaxKind.Trivia */;
|
|
704
825
|
}
|
|
705
826
|
// trivia: newlines
|
|
706
827
|
if (isLineBreak(code)) {
|
|
707
828
|
pos++;
|
|
708
829
|
value += String.fromCharCode(code);
|
|
709
|
-
if (code === 13 /* carriageReturn */ && text.charCodeAt(pos) === 10 /* lineFeed */) {
|
|
830
|
+
if (code === 13 /* CharacterCodes.carriageReturn */ && text.charCodeAt(pos) === 10 /* CharacterCodes.lineFeed */) {
|
|
710
831
|
pos++;
|
|
711
832
|
value += '\n';
|
|
712
833
|
}
|
|
713
834
|
lineNumber++;
|
|
714
835
|
tokenLineStartOffset = pos;
|
|
715
|
-
return token = 14 /* LineBreakTrivia */;
|
|
836
|
+
return token = 14 /* SyntaxKind.LineBreakTrivia */;
|
|
716
837
|
}
|
|
717
838
|
switch (code) {
|
|
718
839
|
// tokens: []{}:,
|
|
719
|
-
case 123 /* openBrace */:
|
|
840
|
+
case 123 /* CharacterCodes.openBrace */:
|
|
720
841
|
pos++;
|
|
721
|
-
return token = 1 /* OpenBraceToken */;
|
|
722
|
-
case 125 /* closeBrace */:
|
|
842
|
+
return token = 1 /* SyntaxKind.OpenBraceToken */;
|
|
843
|
+
case 125 /* CharacterCodes.closeBrace */:
|
|
723
844
|
pos++;
|
|
724
|
-
return token = 2 /* CloseBraceToken */;
|
|
725
|
-
case 91 /* openBracket */:
|
|
845
|
+
return token = 2 /* SyntaxKind.CloseBraceToken */;
|
|
846
|
+
case 91 /* CharacterCodes.openBracket */:
|
|
726
847
|
pos++;
|
|
727
|
-
return token = 3 /* OpenBracketToken */;
|
|
728
|
-
case 93 /* closeBracket */:
|
|
848
|
+
return token = 3 /* SyntaxKind.OpenBracketToken */;
|
|
849
|
+
case 93 /* CharacterCodes.closeBracket */:
|
|
729
850
|
pos++;
|
|
730
|
-
return token = 4 /* CloseBracketToken */;
|
|
731
|
-
case 58 /* colon */:
|
|
851
|
+
return token = 4 /* SyntaxKind.CloseBracketToken */;
|
|
852
|
+
case 58 /* CharacterCodes.colon */:
|
|
732
853
|
pos++;
|
|
733
|
-
return token = 6 /* ColonToken */;
|
|
734
|
-
case 44 /* comma */:
|
|
854
|
+
return token = 6 /* SyntaxKind.ColonToken */;
|
|
855
|
+
case 44 /* CharacterCodes.comma */:
|
|
735
856
|
pos++;
|
|
736
|
-
return token = 5 /* CommaToken */;
|
|
857
|
+
return token = 5 /* SyntaxKind.CommaToken */;
|
|
737
858
|
// strings
|
|
738
|
-
case 34 /* doubleQuote */:
|
|
859
|
+
case 34 /* CharacterCodes.doubleQuote */:
|
|
739
860
|
pos++;
|
|
740
861
|
value = scanString();
|
|
741
|
-
return token = 10 /* StringLiteral */;
|
|
862
|
+
return token = 10 /* SyntaxKind.StringLiteral */;
|
|
742
863
|
// comments
|
|
743
|
-
case 47 /* slash */:
|
|
744
|
-
|
|
864
|
+
case 47 /* CharacterCodes.slash */:
|
|
865
|
+
const start = pos - 1;
|
|
745
866
|
// Single-line comment
|
|
746
|
-
if (text.charCodeAt(pos + 1) === 47 /* slash */) {
|
|
867
|
+
if (text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */) {
|
|
747
868
|
pos += 2;
|
|
748
869
|
while (pos < len) {
|
|
749
870
|
if (isLineBreak(text.charCodeAt(pos))) {
|
|
@@ -752,23 +873,23 @@ function createScanner(text, ignoreTrivia) {
|
|
|
752
873
|
pos++;
|
|
753
874
|
}
|
|
754
875
|
value = text.substring(start, pos);
|
|
755
|
-
return token = 12 /* LineCommentTrivia */;
|
|
876
|
+
return token = 12 /* SyntaxKind.LineCommentTrivia */;
|
|
756
877
|
}
|
|
757
878
|
// Multi-line comment
|
|
758
|
-
if (text.charCodeAt(pos + 1) === 42 /* asterisk */) {
|
|
879
|
+
if (text.charCodeAt(pos + 1) === 42 /* CharacterCodes.asterisk */) {
|
|
759
880
|
pos += 2;
|
|
760
|
-
|
|
761
|
-
|
|
881
|
+
const safeLength = len - 1; // For lookahead.
|
|
882
|
+
let commentClosed = false;
|
|
762
883
|
while (pos < safeLength) {
|
|
763
|
-
|
|
764
|
-
if (ch === 42 /* asterisk */ && text.charCodeAt(pos + 1) === 47 /* slash */) {
|
|
884
|
+
const ch = text.charCodeAt(pos);
|
|
885
|
+
if (ch === 42 /* CharacterCodes.asterisk */ && text.charCodeAt(pos + 1) === 47 /* CharacterCodes.slash */) {
|
|
765
886
|
pos += 2;
|
|
766
887
|
commentClosed = true;
|
|
767
888
|
break;
|
|
768
889
|
}
|
|
769
890
|
pos++;
|
|
770
891
|
if (isLineBreak(ch)) {
|
|
771
|
-
if (ch === 13 /* carriageReturn */ && text.charCodeAt(pos) === 10 /* lineFeed */) {
|
|
892
|
+
if (ch === 13 /* CharacterCodes.carriageReturn */ && text.charCodeAt(pos) === 10 /* CharacterCodes.lineFeed */) {
|
|
772
893
|
pos++;
|
|
773
894
|
}
|
|
774
895
|
lineNumber++;
|
|
@@ -777,37 +898,37 @@ function createScanner(text, ignoreTrivia) {
|
|
|
777
898
|
}
|
|
778
899
|
if (!commentClosed) {
|
|
779
900
|
pos++;
|
|
780
|
-
scanError = 1 /* UnexpectedEndOfComment */;
|
|
901
|
+
scanError = 1 /* ScanError.UnexpectedEndOfComment */;
|
|
781
902
|
}
|
|
782
903
|
value = text.substring(start, pos);
|
|
783
|
-
return token = 13 /* BlockCommentTrivia */;
|
|
904
|
+
return token = 13 /* SyntaxKind.BlockCommentTrivia */;
|
|
784
905
|
}
|
|
785
906
|
// just a single slash
|
|
786
907
|
value += String.fromCharCode(code);
|
|
787
908
|
pos++;
|
|
788
|
-
return token = 16 /* Unknown */;
|
|
909
|
+
return token = 16 /* SyntaxKind.Unknown */;
|
|
789
910
|
// numbers
|
|
790
|
-
case 45 /* minus */:
|
|
911
|
+
case 45 /* CharacterCodes.minus */:
|
|
791
912
|
value += String.fromCharCode(code);
|
|
792
913
|
pos++;
|
|
793
914
|
if (pos === len || !isDigit(text.charCodeAt(pos))) {
|
|
794
|
-
return token = 16 /* Unknown */;
|
|
915
|
+
return token = 16 /* SyntaxKind.Unknown */;
|
|
795
916
|
}
|
|
796
917
|
// found a minus, followed by a number so
|
|
797
918
|
// we fall through to proceed with scanning
|
|
798
919
|
// numbers
|
|
799
|
-
case 48 /* _0 */:
|
|
800
|
-
case 49 /* _1 */:
|
|
801
|
-
case 50 /* _2 */:
|
|
802
|
-
case 51 /* _3 */:
|
|
803
|
-
case 52 /* _4 */:
|
|
804
|
-
case 53 /* _5 */:
|
|
805
|
-
case 54 /* _6 */:
|
|
806
|
-
case 55 /* _7 */:
|
|
807
|
-
case 56 /* _8 */:
|
|
808
|
-
case 57 /* _9 */:
|
|
920
|
+
case 48 /* CharacterCodes._0 */:
|
|
921
|
+
case 49 /* CharacterCodes._1 */:
|
|
922
|
+
case 50 /* CharacterCodes._2 */:
|
|
923
|
+
case 51 /* CharacterCodes._3 */:
|
|
924
|
+
case 52 /* CharacterCodes._4 */:
|
|
925
|
+
case 53 /* CharacterCodes._5 */:
|
|
926
|
+
case 54 /* CharacterCodes._6 */:
|
|
927
|
+
case 55 /* CharacterCodes._7 */:
|
|
928
|
+
case 56 /* CharacterCodes._8 */:
|
|
929
|
+
case 57 /* CharacterCodes._9 */:
|
|
809
930
|
value += scanNumber();
|
|
810
|
-
return token = 11 /* NumericLiteral */;
|
|
931
|
+
return token = 11 /* SyntaxKind.NumericLiteral */;
|
|
811
932
|
// literals and unknown symbols
|
|
812
933
|
default:
|
|
813
934
|
// is a literal? Read the full word.
|
|
@@ -819,16 +940,16 @@ function createScanner(text, ignoreTrivia) {
|
|
|
819
940
|
value = text.substring(tokenOffset, pos);
|
|
820
941
|
// keywords: true, false, null
|
|
821
942
|
switch (value) {
|
|
822
|
-
case 'true': return token = 8 /* TrueKeyword */;
|
|
823
|
-
case 'false': return token = 9 /* FalseKeyword */;
|
|
824
|
-
case 'null': return token = 7 /* NullKeyword */;
|
|
943
|
+
case 'true': return token = 8 /* SyntaxKind.TrueKeyword */;
|
|
944
|
+
case 'false': return token = 9 /* SyntaxKind.FalseKeyword */;
|
|
945
|
+
case 'null': return token = 7 /* SyntaxKind.NullKeyword */;
|
|
825
946
|
}
|
|
826
|
-
return token = 16 /* Unknown */;
|
|
947
|
+
return token = 16 /* SyntaxKind.Unknown */;
|
|
827
948
|
}
|
|
828
949
|
// some
|
|
829
950
|
value += String.fromCharCode(code);
|
|
830
951
|
pos++;
|
|
831
|
-
return token = 16 /* Unknown */;
|
|
952
|
+
return token = 16 /* SyntaxKind.Unknown */;
|
|
832
953
|
}
|
|
833
954
|
}
|
|
834
955
|
function isUnknownContentCharacter(code) {
|
|
@@ -836,49 +957,130 @@ function createScanner(text, ignoreTrivia) {
|
|
|
836
957
|
return false;
|
|
837
958
|
}
|
|
838
959
|
switch (code) {
|
|
839
|
-
case 125 /* closeBrace */:
|
|
840
|
-
case 93 /* closeBracket */:
|
|
841
|
-
case 123 /* openBrace */:
|
|
842
|
-
case 91 /* openBracket */:
|
|
843
|
-
case 34 /* doubleQuote */:
|
|
844
|
-
case 58 /* colon */:
|
|
845
|
-
case 44 /* comma */:
|
|
846
|
-
case 47 /* slash */:
|
|
960
|
+
case 125 /* CharacterCodes.closeBrace */:
|
|
961
|
+
case 93 /* CharacterCodes.closeBracket */:
|
|
962
|
+
case 123 /* CharacterCodes.openBrace */:
|
|
963
|
+
case 91 /* CharacterCodes.openBracket */:
|
|
964
|
+
case 34 /* CharacterCodes.doubleQuote */:
|
|
965
|
+
case 58 /* CharacterCodes.colon */:
|
|
966
|
+
case 44 /* CharacterCodes.comma */:
|
|
967
|
+
case 47 /* CharacterCodes.slash */:
|
|
847
968
|
return false;
|
|
848
969
|
}
|
|
849
970
|
return true;
|
|
850
971
|
}
|
|
851
972
|
function scanNextNonTrivia() {
|
|
852
|
-
|
|
973
|
+
let result;
|
|
853
974
|
do {
|
|
854
975
|
result = scanNext();
|
|
855
|
-
} while (result >= 12 /* LineCommentTrivia */ && result <= 15 /* Trivia */);
|
|
976
|
+
} while (result >= 12 /* SyntaxKind.LineCommentTrivia */ && result <= 15 /* SyntaxKind.Trivia */);
|
|
856
977
|
return result;
|
|
857
978
|
}
|
|
858
979
|
return {
|
|
859
980
|
setPosition: setPosition,
|
|
860
|
-
getPosition:
|
|
981
|
+
getPosition: () => pos,
|
|
861
982
|
scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
|
|
862
|
-
getToken:
|
|
863
|
-
getTokenValue:
|
|
864
|
-
getTokenOffset:
|
|
865
|
-
getTokenLength:
|
|
866
|
-
getTokenStartLine:
|
|
867
|
-
getTokenStartCharacter:
|
|
868
|
-
getTokenError:
|
|
983
|
+
getToken: () => token,
|
|
984
|
+
getTokenValue: () => value,
|
|
985
|
+
getTokenOffset: () => tokenOffset,
|
|
986
|
+
getTokenLength: () => pos - tokenOffset,
|
|
987
|
+
getTokenStartLine: () => lineStartOffset,
|
|
988
|
+
getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
|
|
989
|
+
getTokenError: () => scanError,
|
|
869
990
|
};
|
|
870
991
|
}
|
|
871
992
|
function isWhiteSpace(ch) {
|
|
872
|
-
return ch === 32 /* space */ || ch === 9 /* tab
|
|
873
|
-
ch === 160 /* nonBreakingSpace */ || ch === 5760 /* ogham */ || ch >= 8192 /* enQuad */ && ch <= 8203 /* zeroWidthSpace */ ||
|
|
874
|
-
ch === 8239 /* narrowNoBreakSpace */ || ch === 8287 /* mathematicalSpace */ || ch === 12288 /* ideographicSpace */ || ch === 65279 /* byteOrderMark */;
|
|
993
|
+
return ch === 32 /* CharacterCodes.space */ || ch === 9 /* CharacterCodes.tab */;
|
|
875
994
|
}
|
|
876
995
|
function isLineBreak(ch) {
|
|
877
|
-
return ch === 10 /* lineFeed */ || ch === 13 /* carriageReturn
|
|
996
|
+
return ch === 10 /* CharacterCodes.lineFeed */ || ch === 13 /* CharacterCodes.carriageReturn */;
|
|
878
997
|
}
|
|
879
998
|
function isDigit(ch) {
|
|
880
|
-
return ch >= 48 /* _0 */ && ch <= 57 /* _9 */;
|
|
999
|
+
return ch >= 48 /* CharacterCodes._0 */ && ch <= 57 /* CharacterCodes._9 */;
|
|
881
1000
|
}
|
|
1001
|
+
var CharacterCodes;
|
|
1002
|
+
(function (CharacterCodes) {
|
|
1003
|
+
CharacterCodes[CharacterCodes["lineFeed"] = 10] = "lineFeed";
|
|
1004
|
+
CharacterCodes[CharacterCodes["carriageReturn"] = 13] = "carriageReturn";
|
|
1005
|
+
CharacterCodes[CharacterCodes["space"] = 32] = "space";
|
|
1006
|
+
CharacterCodes[CharacterCodes["_0"] = 48] = "_0";
|
|
1007
|
+
CharacterCodes[CharacterCodes["_1"] = 49] = "_1";
|
|
1008
|
+
CharacterCodes[CharacterCodes["_2"] = 50] = "_2";
|
|
1009
|
+
CharacterCodes[CharacterCodes["_3"] = 51] = "_3";
|
|
1010
|
+
CharacterCodes[CharacterCodes["_4"] = 52] = "_4";
|
|
1011
|
+
CharacterCodes[CharacterCodes["_5"] = 53] = "_5";
|
|
1012
|
+
CharacterCodes[CharacterCodes["_6"] = 54] = "_6";
|
|
1013
|
+
CharacterCodes[CharacterCodes["_7"] = 55] = "_7";
|
|
1014
|
+
CharacterCodes[CharacterCodes["_8"] = 56] = "_8";
|
|
1015
|
+
CharacterCodes[CharacterCodes["_9"] = 57] = "_9";
|
|
1016
|
+
CharacterCodes[CharacterCodes["a"] = 97] = "a";
|
|
1017
|
+
CharacterCodes[CharacterCodes["b"] = 98] = "b";
|
|
1018
|
+
CharacterCodes[CharacterCodes["c"] = 99] = "c";
|
|
1019
|
+
CharacterCodes[CharacterCodes["d"] = 100] = "d";
|
|
1020
|
+
CharacterCodes[CharacterCodes["e"] = 101] = "e";
|
|
1021
|
+
CharacterCodes[CharacterCodes["f"] = 102] = "f";
|
|
1022
|
+
CharacterCodes[CharacterCodes["g"] = 103] = "g";
|
|
1023
|
+
CharacterCodes[CharacterCodes["h"] = 104] = "h";
|
|
1024
|
+
CharacterCodes[CharacterCodes["i"] = 105] = "i";
|
|
1025
|
+
CharacterCodes[CharacterCodes["j"] = 106] = "j";
|
|
1026
|
+
CharacterCodes[CharacterCodes["k"] = 107] = "k";
|
|
1027
|
+
CharacterCodes[CharacterCodes["l"] = 108] = "l";
|
|
1028
|
+
CharacterCodes[CharacterCodes["m"] = 109] = "m";
|
|
1029
|
+
CharacterCodes[CharacterCodes["n"] = 110] = "n";
|
|
1030
|
+
CharacterCodes[CharacterCodes["o"] = 111] = "o";
|
|
1031
|
+
CharacterCodes[CharacterCodes["p"] = 112] = "p";
|
|
1032
|
+
CharacterCodes[CharacterCodes["q"] = 113] = "q";
|
|
1033
|
+
CharacterCodes[CharacterCodes["r"] = 114] = "r";
|
|
1034
|
+
CharacterCodes[CharacterCodes["s"] = 115] = "s";
|
|
1035
|
+
CharacterCodes[CharacterCodes["t"] = 116] = "t";
|
|
1036
|
+
CharacterCodes[CharacterCodes["u"] = 117] = "u";
|
|
1037
|
+
CharacterCodes[CharacterCodes["v"] = 118] = "v";
|
|
1038
|
+
CharacterCodes[CharacterCodes["w"] = 119] = "w";
|
|
1039
|
+
CharacterCodes[CharacterCodes["x"] = 120] = "x";
|
|
1040
|
+
CharacterCodes[CharacterCodes["y"] = 121] = "y";
|
|
1041
|
+
CharacterCodes[CharacterCodes["z"] = 122] = "z";
|
|
1042
|
+
CharacterCodes[CharacterCodes["A"] = 65] = "A";
|
|
1043
|
+
CharacterCodes[CharacterCodes["B"] = 66] = "B";
|
|
1044
|
+
CharacterCodes[CharacterCodes["C"] = 67] = "C";
|
|
1045
|
+
CharacterCodes[CharacterCodes["D"] = 68] = "D";
|
|
1046
|
+
CharacterCodes[CharacterCodes["E"] = 69] = "E";
|
|
1047
|
+
CharacterCodes[CharacterCodes["F"] = 70] = "F";
|
|
1048
|
+
CharacterCodes[CharacterCodes["G"] = 71] = "G";
|
|
1049
|
+
CharacterCodes[CharacterCodes["H"] = 72] = "H";
|
|
1050
|
+
CharacterCodes[CharacterCodes["I"] = 73] = "I";
|
|
1051
|
+
CharacterCodes[CharacterCodes["J"] = 74] = "J";
|
|
1052
|
+
CharacterCodes[CharacterCodes["K"] = 75] = "K";
|
|
1053
|
+
CharacterCodes[CharacterCodes["L"] = 76] = "L";
|
|
1054
|
+
CharacterCodes[CharacterCodes["M"] = 77] = "M";
|
|
1055
|
+
CharacterCodes[CharacterCodes["N"] = 78] = "N";
|
|
1056
|
+
CharacterCodes[CharacterCodes["O"] = 79] = "O";
|
|
1057
|
+
CharacterCodes[CharacterCodes["P"] = 80] = "P";
|
|
1058
|
+
CharacterCodes[CharacterCodes["Q"] = 81] = "Q";
|
|
1059
|
+
CharacterCodes[CharacterCodes["R"] = 82] = "R";
|
|
1060
|
+
CharacterCodes[CharacterCodes["S"] = 83] = "S";
|
|
1061
|
+
CharacterCodes[CharacterCodes["T"] = 84] = "T";
|
|
1062
|
+
CharacterCodes[CharacterCodes["U"] = 85] = "U";
|
|
1063
|
+
CharacterCodes[CharacterCodes["V"] = 86] = "V";
|
|
1064
|
+
CharacterCodes[CharacterCodes["W"] = 87] = "W";
|
|
1065
|
+
CharacterCodes[CharacterCodes["X"] = 88] = "X";
|
|
1066
|
+
CharacterCodes[CharacterCodes["Y"] = 89] = "Y";
|
|
1067
|
+
CharacterCodes[CharacterCodes["Z"] = 90] = "Z";
|
|
1068
|
+
CharacterCodes[CharacterCodes["asterisk"] = 42] = "asterisk";
|
|
1069
|
+
CharacterCodes[CharacterCodes["backslash"] = 92] = "backslash";
|
|
1070
|
+
CharacterCodes[CharacterCodes["closeBrace"] = 125] = "closeBrace";
|
|
1071
|
+
CharacterCodes[CharacterCodes["closeBracket"] = 93] = "closeBracket";
|
|
1072
|
+
CharacterCodes[CharacterCodes["colon"] = 58] = "colon";
|
|
1073
|
+
CharacterCodes[CharacterCodes["comma"] = 44] = "comma";
|
|
1074
|
+
CharacterCodes[CharacterCodes["dot"] = 46] = "dot";
|
|
1075
|
+
CharacterCodes[CharacterCodes["doubleQuote"] = 34] = "doubleQuote";
|
|
1076
|
+
CharacterCodes[CharacterCodes["minus"] = 45] = "minus";
|
|
1077
|
+
CharacterCodes[CharacterCodes["openBrace"] = 123] = "openBrace";
|
|
1078
|
+
CharacterCodes[CharacterCodes["openBracket"] = 91] = "openBracket";
|
|
1079
|
+
CharacterCodes[CharacterCodes["plus"] = 43] = "plus";
|
|
1080
|
+
CharacterCodes[CharacterCodes["slash"] = 47] = "slash";
|
|
1081
|
+
CharacterCodes[CharacterCodes["formFeed"] = 12] = "formFeed";
|
|
1082
|
+
CharacterCodes[CharacterCodes["tab"] = 9] = "tab";
|
|
1083
|
+
})(CharacterCodes || (CharacterCodes = {}));
|
|
882
1084
|
|
|
883
1085
|
|
|
884
1086
|
/***/ }),
|
|
@@ -902,22 +1104,21 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
902
1104
|
|
|
903
1105
|
|
|
904
1106
|
|
|
905
|
-
function removeProperty(text, path,
|
|
906
|
-
return setProperty(text, path, void 0,
|
|
1107
|
+
function removeProperty(text, path, options) {
|
|
1108
|
+
return setProperty(text, path, void 0, options);
|
|
907
1109
|
}
|
|
908
|
-
function setProperty(text, originalPath, value,
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
var lastSegment = void 0;
|
|
1110
|
+
function setProperty(text, originalPath, value, options) {
|
|
1111
|
+
const path = originalPath.slice();
|
|
1112
|
+
const errors = [];
|
|
1113
|
+
const root = (0,_parser__WEBPACK_IMPORTED_MODULE_1__.parseTree)(text, errors);
|
|
1114
|
+
let parent = void 0;
|
|
1115
|
+
let lastSegment = void 0;
|
|
915
1116
|
while (path.length > 0) {
|
|
916
1117
|
lastSegment = path.pop();
|
|
917
1118
|
parent = (0,_parser__WEBPACK_IMPORTED_MODULE_1__.findNodeAtLocation)(root, path);
|
|
918
1119
|
if (parent === void 0 && value !== void 0) {
|
|
919
1120
|
if (typeof lastSegment === 'string') {
|
|
920
|
-
value =
|
|
1121
|
+
value = { [lastSegment]: value };
|
|
921
1122
|
}
|
|
922
1123
|
else {
|
|
923
1124
|
value = [value];
|
|
@@ -932,47 +1133,47 @@ function setProperty(text, originalPath, value, formattingOptions, getInsertionI
|
|
|
932
1133
|
if (value === void 0) { // delete
|
|
933
1134
|
throw new Error('Can not delete in empty document');
|
|
934
1135
|
}
|
|
935
|
-
return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) },
|
|
1136
|
+
return withFormatting(text, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
|
|
936
1137
|
}
|
|
937
1138
|
else if (parent.type === 'object' && typeof lastSegment === 'string' && Array.isArray(parent.children)) {
|
|
938
|
-
|
|
1139
|
+
const existing = (0,_parser__WEBPACK_IMPORTED_MODULE_1__.findNodeAtLocation)(parent, [lastSegment]);
|
|
939
1140
|
if (existing !== void 0) {
|
|
940
1141
|
if (value === void 0) { // delete
|
|
941
1142
|
if (!existing.parent) {
|
|
942
1143
|
throw new Error('Malformed AST');
|
|
943
1144
|
}
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
1145
|
+
const propertyIndex = parent.children.indexOf(existing.parent);
|
|
1146
|
+
let removeBegin;
|
|
1147
|
+
let removeEnd = existing.parent.offset + existing.parent.length;
|
|
947
1148
|
if (propertyIndex > 0) {
|
|
948
1149
|
// remove the comma of the previous node
|
|
949
|
-
|
|
1150
|
+
let previous = parent.children[propertyIndex - 1];
|
|
950
1151
|
removeBegin = previous.offset + previous.length;
|
|
951
1152
|
}
|
|
952
1153
|
else {
|
|
953
1154
|
removeBegin = parent.offset + 1;
|
|
954
1155
|
if (parent.children.length > 1) {
|
|
955
1156
|
// remove the comma of the next node
|
|
956
|
-
|
|
1157
|
+
let next = parent.children[1];
|
|
957
1158
|
removeEnd = next.offset;
|
|
958
1159
|
}
|
|
959
1160
|
}
|
|
960
|
-
return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: '' },
|
|
1161
|
+
return withFormatting(text, { offset: removeBegin, length: removeEnd - removeBegin, content: '' }, options);
|
|
961
1162
|
}
|
|
962
1163
|
else {
|
|
963
1164
|
// set value of existing property
|
|
964
|
-
return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) },
|
|
1165
|
+
return withFormatting(text, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
|
|
965
1166
|
}
|
|
966
1167
|
}
|
|
967
1168
|
else {
|
|
968
1169
|
if (value === void 0) { // delete
|
|
969
1170
|
return []; // property does not exist, nothing to do
|
|
970
1171
|
}
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
1172
|
+
const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
|
|
1173
|
+
const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map(p => p.children[0].value)) : parent.children.length;
|
|
1174
|
+
let edit;
|
|
974
1175
|
if (index > 0) {
|
|
975
|
-
|
|
1176
|
+
let previous = parent.children[index - 1];
|
|
976
1177
|
edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
|
|
977
1178
|
}
|
|
978
1179
|
else if (parent.children.length === 0) {
|
|
@@ -981,61 +1182,79 @@ function setProperty(text, originalPath, value, formattingOptions, getInsertionI
|
|
|
981
1182
|
else {
|
|
982
1183
|
edit = { offset: parent.offset + 1, length: 0, content: newProperty + ',' };
|
|
983
1184
|
}
|
|
984
|
-
return withFormatting(text, edit,
|
|
1185
|
+
return withFormatting(text, edit, options);
|
|
985
1186
|
}
|
|
986
1187
|
}
|
|
987
1188
|
else if (parent.type === 'array' && typeof lastSegment === 'number' && Array.isArray(parent.children)) {
|
|
988
|
-
|
|
1189
|
+
const insertIndex = lastSegment;
|
|
989
1190
|
if (insertIndex === -1) {
|
|
990
1191
|
// Insert
|
|
991
|
-
|
|
992
|
-
|
|
1192
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1193
|
+
let edit;
|
|
993
1194
|
if (parent.children.length === 0) {
|
|
994
1195
|
edit = { offset: parent.offset + 1, length: 0, content: newProperty };
|
|
995
1196
|
}
|
|
996
1197
|
else {
|
|
997
|
-
|
|
1198
|
+
const previous = parent.children[parent.children.length - 1];
|
|
998
1199
|
edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
|
|
999
1200
|
}
|
|
1000
|
-
return withFormatting(text, edit,
|
|
1201
|
+
return withFormatting(text, edit, options);
|
|
1001
1202
|
}
|
|
1002
|
-
else {
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
edit = { offset: offset, length: parentEndOffset - 2 - offset, content: '' };
|
|
1018
|
-
}
|
|
1019
|
-
else {
|
|
1020
|
-
edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: '' };
|
|
1021
|
-
}
|
|
1022
|
-
return withFormatting(text, edit, formattingOptions);
|
|
1203
|
+
else if (value === void 0 && parent.children.length >= 0) {
|
|
1204
|
+
// Removal
|
|
1205
|
+
const removalIndex = lastSegment;
|
|
1206
|
+
const toRemove = parent.children[removalIndex];
|
|
1207
|
+
let edit;
|
|
1208
|
+
if (parent.children.length === 1) {
|
|
1209
|
+
// only item
|
|
1210
|
+
edit = { offset: parent.offset + 1, length: parent.length - 2, content: '' };
|
|
1211
|
+
}
|
|
1212
|
+
else if (parent.children.length - 1 === removalIndex) {
|
|
1213
|
+
// last item
|
|
1214
|
+
let previous = parent.children[removalIndex - 1];
|
|
1215
|
+
let offset = previous.offset + previous.length;
|
|
1216
|
+
let parentEndOffset = parent.offset + parent.length;
|
|
1217
|
+
edit = { offset, length: parentEndOffset - 2 - offset, content: '' };
|
|
1023
1218
|
}
|
|
1024
1219
|
else {
|
|
1025
|
-
|
|
1220
|
+
edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: '' };
|
|
1026
1221
|
}
|
|
1222
|
+
return withFormatting(text, edit, options);
|
|
1223
|
+
}
|
|
1224
|
+
else if (value !== void 0) {
|
|
1225
|
+
let edit;
|
|
1226
|
+
const newProperty = `${JSON.stringify(value)}`;
|
|
1227
|
+
if (!options.isArrayInsertion && parent.children.length > lastSegment) {
|
|
1228
|
+
const toModify = parent.children[lastSegment];
|
|
1229
|
+
edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
|
|
1230
|
+
}
|
|
1231
|
+
else if (parent.children.length === 0 || lastSegment === 0) {
|
|
1232
|
+
edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + ',' };
|
|
1233
|
+
}
|
|
1234
|
+
else {
|
|
1235
|
+
const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
|
|
1236
|
+
const previous = parent.children[index - 1];
|
|
1237
|
+
edit = { offset: previous.offset + previous.length, length: 0, content: ',' + newProperty };
|
|
1238
|
+
}
|
|
1239
|
+
return withFormatting(text, edit, options);
|
|
1240
|
+
}
|
|
1241
|
+
else {
|
|
1242
|
+
throw new Error(`Can not ${value === void 0 ? 'remove' : (options.isArrayInsertion ? 'insert' : 'modify')} Array index ${insertIndex} as length is not sufficient`);
|
|
1027
1243
|
}
|
|
1028
1244
|
}
|
|
1029
1245
|
else {
|
|
1030
|
-
throw new Error(
|
|
1246
|
+
throw new Error(`Can not add ${typeof lastSegment !== 'number' ? 'index' : 'property'} to parent of type ${parent.type}`);
|
|
1031
1247
|
}
|
|
1032
1248
|
}
|
|
1033
|
-
function withFormatting(text, edit,
|
|
1249
|
+
function withFormatting(text, edit, options) {
|
|
1250
|
+
if (!options.formattingOptions) {
|
|
1251
|
+
return [edit];
|
|
1252
|
+
}
|
|
1034
1253
|
// apply the edit
|
|
1035
|
-
|
|
1254
|
+
let newText = applyEdit(text, edit);
|
|
1036
1255
|
// format the new text
|
|
1037
|
-
|
|
1038
|
-
|
|
1256
|
+
let begin = edit.offset;
|
|
1257
|
+
let end = edit.offset + edit.content.length;
|
|
1039
1258
|
if (edit.length === 0 || edit.content.length === 0) { // insert or remove
|
|
1040
1259
|
while (begin > 0 && !(0,_format__WEBPACK_IMPORTED_MODULE_0__.isEOL)(newText, begin - 1)) {
|
|
1041
1260
|
begin--;
|
|
@@ -1044,17 +1263,17 @@ function withFormatting(text, edit, formattingOptions) {
|
|
|
1044
1263
|
end++;
|
|
1045
1264
|
}
|
|
1046
1265
|
}
|
|
1047
|
-
|
|
1266
|
+
const edits = (0,_format__WEBPACK_IMPORTED_MODULE_0__.format)(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
|
|
1048
1267
|
// apply the formatting edits and track the begin and end offsets of the changes
|
|
1049
|
-
for (
|
|
1050
|
-
|
|
1051
|
-
newText = applyEdit(newText,
|
|
1052
|
-
begin = Math.min(begin,
|
|
1053
|
-
end = Math.max(end,
|
|
1054
|
-
end +=
|
|
1268
|
+
for (let i = edits.length - 1; i >= 0; i--) {
|
|
1269
|
+
const edit = edits[i];
|
|
1270
|
+
newText = applyEdit(newText, edit);
|
|
1271
|
+
begin = Math.min(begin, edit.offset);
|
|
1272
|
+
end = Math.max(end, edit.offset + edit.length);
|
|
1273
|
+
end += edit.content.length - edit.length;
|
|
1055
1274
|
}
|
|
1056
1275
|
// create a single edit with all changes
|
|
1057
|
-
|
|
1276
|
+
const editLength = text.length - (newText.length - end) - begin;
|
|
1058
1277
|
return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
|
|
1059
1278
|
}
|
|
1060
1279
|
function applyEdit(text, edit) {
|
|
@@ -1101,17 +1320,17 @@ var ParseOptions;
|
|
|
1101
1320
|
* For a given offset, evaluate the location in the JSON document. Each segment in the location path is either a property name or an array index.
|
|
1102
1321
|
*/
|
|
1103
1322
|
function getLocation(text, position) {
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1323
|
+
const segments = []; // strings or numbers
|
|
1324
|
+
const earlyReturnException = new Object();
|
|
1325
|
+
let previousNode = undefined;
|
|
1326
|
+
const previousNodeInst = {
|
|
1108
1327
|
value: {},
|
|
1109
1328
|
offset: 0,
|
|
1110
1329
|
length: 0,
|
|
1111
1330
|
type: 'object',
|
|
1112
1331
|
parent: undefined
|
|
1113
1332
|
};
|
|
1114
|
-
|
|
1333
|
+
let isAtPropertyKey = false;
|
|
1115
1334
|
function setPreviousNode(value, offset, length, type) {
|
|
1116
1335
|
previousNodeInst.value = value;
|
|
1117
1336
|
previousNodeInst.offset = offset;
|
|
@@ -1122,7 +1341,7 @@ function getLocation(text, position) {
|
|
|
1122
1341
|
}
|
|
1123
1342
|
try {
|
|
1124
1343
|
visit(text, {
|
|
1125
|
-
onObjectBegin:
|
|
1344
|
+
onObjectBegin: (offset, length) => {
|
|
1126
1345
|
if (position <= offset) {
|
|
1127
1346
|
throw earlyReturnException;
|
|
1128
1347
|
}
|
|
@@ -1130,7 +1349,7 @@ function getLocation(text, position) {
|
|
|
1130
1349
|
isAtPropertyKey = position > offset;
|
|
1131
1350
|
segments.push(''); // push a placeholder (will be replaced)
|
|
1132
1351
|
},
|
|
1133
|
-
onObjectProperty:
|
|
1352
|
+
onObjectProperty: (name, offset, length) => {
|
|
1134
1353
|
if (position < offset) {
|
|
1135
1354
|
throw earlyReturnException;
|
|
1136
1355
|
}
|
|
@@ -1140,28 +1359,28 @@ function getLocation(text, position) {
|
|
|
1140
1359
|
throw earlyReturnException;
|
|
1141
1360
|
}
|
|
1142
1361
|
},
|
|
1143
|
-
onObjectEnd:
|
|
1362
|
+
onObjectEnd: (offset, length) => {
|
|
1144
1363
|
if (position <= offset) {
|
|
1145
1364
|
throw earlyReturnException;
|
|
1146
1365
|
}
|
|
1147
1366
|
previousNode = undefined;
|
|
1148
1367
|
segments.pop();
|
|
1149
1368
|
},
|
|
1150
|
-
onArrayBegin:
|
|
1369
|
+
onArrayBegin: (offset, length) => {
|
|
1151
1370
|
if (position <= offset) {
|
|
1152
1371
|
throw earlyReturnException;
|
|
1153
1372
|
}
|
|
1154
1373
|
previousNode = undefined;
|
|
1155
1374
|
segments.push(0);
|
|
1156
1375
|
},
|
|
1157
|
-
onArrayEnd:
|
|
1376
|
+
onArrayEnd: (offset, length) => {
|
|
1158
1377
|
if (position <= offset) {
|
|
1159
1378
|
throw earlyReturnException;
|
|
1160
1379
|
}
|
|
1161
1380
|
previousNode = undefined;
|
|
1162
1381
|
segments.pop();
|
|
1163
1382
|
},
|
|
1164
|
-
onLiteralValue:
|
|
1383
|
+
onLiteralValue: (value, offset, length) => {
|
|
1165
1384
|
if (position < offset) {
|
|
1166
1385
|
throw earlyReturnException;
|
|
1167
1386
|
}
|
|
@@ -1170,7 +1389,7 @@ function getLocation(text, position) {
|
|
|
1170
1389
|
throw earlyReturnException;
|
|
1171
1390
|
}
|
|
1172
1391
|
},
|
|
1173
|
-
onSeparator:
|
|
1392
|
+
onSeparator: (sep, offset, length) => {
|
|
1174
1393
|
if (position <= offset) {
|
|
1175
1394
|
throw earlyReturnException;
|
|
1176
1395
|
}
|
|
@@ -1180,7 +1399,7 @@ function getLocation(text, position) {
|
|
|
1180
1399
|
previousNode = undefined;
|
|
1181
1400
|
}
|
|
1182
1401
|
else if (sep === ',') {
|
|
1183
|
-
|
|
1402
|
+
const last = segments[segments.length - 1];
|
|
1184
1403
|
if (typeof last === 'number') {
|
|
1185
1404
|
segments[segments.length - 1] = last + 1;
|
|
1186
1405
|
}
|
|
@@ -1200,11 +1419,11 @@ function getLocation(text, position) {
|
|
|
1200
1419
|
}
|
|
1201
1420
|
return {
|
|
1202
1421
|
path: segments,
|
|
1203
|
-
previousNode
|
|
1204
|
-
isAtPropertyKey
|
|
1205
|
-
matches:
|
|
1206
|
-
|
|
1207
|
-
for (
|
|
1422
|
+
previousNode,
|
|
1423
|
+
isAtPropertyKey,
|
|
1424
|
+
matches: (pattern) => {
|
|
1425
|
+
let k = 0;
|
|
1426
|
+
for (let i = 0; k < pattern.length && i < segments.length; i++) {
|
|
1208
1427
|
if (pattern[k] === segments[i] || pattern[k] === '*') {
|
|
1209
1428
|
k++;
|
|
1210
1429
|
}
|
|
@@ -1220,12 +1439,10 @@ function getLocation(text, position) {
|
|
|
1220
1439
|
* Parses the given text and returns the object the JSON content represents. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
|
|
1221
1440
|
* Therefore always check the errors list to find out if the input was valid.
|
|
1222
1441
|
*/
|
|
1223
|
-
function parse(text, errors, options) {
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
var currentParent = [];
|
|
1228
|
-
var previousParents = [];
|
|
1442
|
+
function parse(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
1443
|
+
let currentProperty = null;
|
|
1444
|
+
let currentParent = [];
|
|
1445
|
+
const previousParents = [];
|
|
1229
1446
|
function onValue(value) {
|
|
1230
1447
|
if (Array.isArray(currentParent)) {
|
|
1231
1448
|
currentParent.push(value);
|
|
@@ -1234,33 +1451,33 @@ function parse(text, errors, options) {
|
|
|
1234
1451
|
currentParent[currentProperty] = value;
|
|
1235
1452
|
}
|
|
1236
1453
|
}
|
|
1237
|
-
|
|
1238
|
-
onObjectBegin:
|
|
1239
|
-
|
|
1454
|
+
const visitor = {
|
|
1455
|
+
onObjectBegin: () => {
|
|
1456
|
+
const object = {};
|
|
1240
1457
|
onValue(object);
|
|
1241
1458
|
previousParents.push(currentParent);
|
|
1242
1459
|
currentParent = object;
|
|
1243
1460
|
currentProperty = null;
|
|
1244
1461
|
},
|
|
1245
|
-
onObjectProperty:
|
|
1462
|
+
onObjectProperty: (name) => {
|
|
1246
1463
|
currentProperty = name;
|
|
1247
1464
|
},
|
|
1248
|
-
onObjectEnd:
|
|
1465
|
+
onObjectEnd: () => {
|
|
1249
1466
|
currentParent = previousParents.pop();
|
|
1250
1467
|
},
|
|
1251
|
-
onArrayBegin:
|
|
1252
|
-
|
|
1468
|
+
onArrayBegin: () => {
|
|
1469
|
+
const array = [];
|
|
1253
1470
|
onValue(array);
|
|
1254
1471
|
previousParents.push(currentParent);
|
|
1255
1472
|
currentParent = array;
|
|
1256
1473
|
currentProperty = null;
|
|
1257
1474
|
},
|
|
1258
|
-
onArrayEnd:
|
|
1475
|
+
onArrayEnd: () => {
|
|
1259
1476
|
currentParent = previousParents.pop();
|
|
1260
1477
|
},
|
|
1261
1478
|
onLiteralValue: onValue,
|
|
1262
|
-
onError:
|
|
1263
|
-
errors.push({ error
|
|
1479
|
+
onError: (error, offset, length) => {
|
|
1480
|
+
errors.push({ error, offset, length });
|
|
1264
1481
|
}
|
|
1265
1482
|
};
|
|
1266
1483
|
visit(text, visitor, options);
|
|
@@ -1269,10 +1486,8 @@ function parse(text, errors, options) {
|
|
|
1269
1486
|
/**
|
|
1270
1487
|
* Parses the given text and returns a tree representation the JSON content. On invalid input, the parser tries to be as fault tolerant as possible, but still return a result.
|
|
1271
1488
|
*/
|
|
1272
|
-
function parseTree(text, errors, options) {
|
|
1273
|
-
|
|
1274
|
-
if (options === void 0) { options = ParseOptions.DEFAULT; }
|
|
1275
|
-
var currentParent = { type: 'array', offset: -1, length: -1, children: [], parent: undefined }; // artificial root
|
|
1489
|
+
function parseTree(text, errors = [], options = ParseOptions.DEFAULT) {
|
|
1490
|
+
let currentParent = { type: 'array', offset: -1, length: -1, children: [], parent: undefined }; // artificial root
|
|
1276
1491
|
function ensurePropertyComplete(endOffset) {
|
|
1277
1492
|
if (currentParent.type === 'property') {
|
|
1278
1493
|
currentParent.length = endOffset - currentParent.offset;
|
|
@@ -1283,33 +1498,33 @@ function parseTree(text, errors, options) {
|
|
|
1283
1498
|
currentParent.children.push(valueNode);
|
|
1284
1499
|
return valueNode;
|
|
1285
1500
|
}
|
|
1286
|
-
|
|
1287
|
-
onObjectBegin:
|
|
1288
|
-
currentParent = onValue({ type: 'object', offset
|
|
1501
|
+
const visitor = {
|
|
1502
|
+
onObjectBegin: (offset) => {
|
|
1503
|
+
currentParent = onValue({ type: 'object', offset, length: -1, parent: currentParent, children: [] });
|
|
1289
1504
|
},
|
|
1290
|
-
onObjectProperty:
|
|
1291
|
-
currentParent = onValue({ type: 'property', offset
|
|
1292
|
-
currentParent.children.push({ type: 'string', value: name, offset
|
|
1505
|
+
onObjectProperty: (name, offset, length) => {
|
|
1506
|
+
currentParent = onValue({ type: 'property', offset, length: -1, parent: currentParent, children: [] });
|
|
1507
|
+
currentParent.children.push({ type: 'string', value: name, offset, length, parent: currentParent });
|
|
1293
1508
|
},
|
|
1294
|
-
onObjectEnd:
|
|
1509
|
+
onObjectEnd: (offset, length) => {
|
|
1295
1510
|
ensurePropertyComplete(offset + length); // in case of a missing value for a property: make sure property is complete
|
|
1296
1511
|
currentParent.length = offset + length - currentParent.offset;
|
|
1297
1512
|
currentParent = currentParent.parent;
|
|
1298
1513
|
ensurePropertyComplete(offset + length);
|
|
1299
1514
|
},
|
|
1300
|
-
onArrayBegin:
|
|
1301
|
-
currentParent = onValue({ type: 'array', offset
|
|
1515
|
+
onArrayBegin: (offset, length) => {
|
|
1516
|
+
currentParent = onValue({ type: 'array', offset, length: -1, parent: currentParent, children: [] });
|
|
1302
1517
|
},
|
|
1303
|
-
onArrayEnd:
|
|
1518
|
+
onArrayEnd: (offset, length) => {
|
|
1304
1519
|
currentParent.length = offset + length - currentParent.offset;
|
|
1305
1520
|
currentParent = currentParent.parent;
|
|
1306
1521
|
ensurePropertyComplete(offset + length);
|
|
1307
1522
|
},
|
|
1308
|
-
onLiteralValue:
|
|
1309
|
-
onValue({ type: getNodeType(value), offset
|
|
1523
|
+
onLiteralValue: (value, offset, length) => {
|
|
1524
|
+
onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
|
|
1310
1525
|
ensurePropertyComplete(offset + length);
|
|
1311
1526
|
},
|
|
1312
|
-
onSeparator:
|
|
1527
|
+
onSeparator: (sep, offset, length) => {
|
|
1313
1528
|
if (currentParent.type === 'property') {
|
|
1314
1529
|
if (sep === ':') {
|
|
1315
1530
|
currentParent.colonOffset = offset;
|
|
@@ -1319,12 +1534,12 @@ function parseTree(text, errors, options) {
|
|
|
1319
1534
|
}
|
|
1320
1535
|
}
|
|
1321
1536
|
},
|
|
1322
|
-
onError:
|
|
1323
|
-
errors.push({ error
|
|
1537
|
+
onError: (error, offset, length) => {
|
|
1538
|
+
errors.push({ error, offset, length });
|
|
1324
1539
|
}
|
|
1325
1540
|
};
|
|
1326
1541
|
visit(text, visitor, options);
|
|
1327
|
-
|
|
1542
|
+
const result = currentParent.children[0];
|
|
1328
1543
|
if (result) {
|
|
1329
1544
|
delete result.parent;
|
|
1330
1545
|
}
|
|
@@ -1337,17 +1552,15 @@ function findNodeAtLocation(root, path) {
|
|
|
1337
1552
|
if (!root) {
|
|
1338
1553
|
return undefined;
|
|
1339
1554
|
}
|
|
1340
|
-
|
|
1341
|
-
for (
|
|
1342
|
-
var segment = path_1[_i];
|
|
1555
|
+
let node = root;
|
|
1556
|
+
for (let segment of path) {
|
|
1343
1557
|
if (typeof segment === 'string') {
|
|
1344
1558
|
if (node.type !== 'object' || !Array.isArray(node.children)) {
|
|
1345
1559
|
return undefined;
|
|
1346
1560
|
}
|
|
1347
|
-
|
|
1348
|
-
for (
|
|
1349
|
-
|
|
1350
|
-
if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment) {
|
|
1561
|
+
let found = false;
|
|
1562
|
+
for (const propertyNode of node.children) {
|
|
1563
|
+
if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
|
|
1351
1564
|
node = propertyNode.children[1];
|
|
1352
1565
|
found = true;
|
|
1353
1566
|
break;
|
|
@@ -1358,7 +1571,7 @@ function findNodeAtLocation(root, path) {
|
|
|
1358
1571
|
}
|
|
1359
1572
|
}
|
|
1360
1573
|
else {
|
|
1361
|
-
|
|
1574
|
+
const index = segment;
|
|
1362
1575
|
if (node.type !== 'array' || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
|
|
1363
1576
|
return undefined;
|
|
1364
1577
|
}
|
|
@@ -1374,13 +1587,13 @@ function getNodePath(node) {
|
|
|
1374
1587
|
if (!node.parent || !node.parent.children) {
|
|
1375
1588
|
return [];
|
|
1376
1589
|
}
|
|
1377
|
-
|
|
1590
|
+
const path = getNodePath(node.parent);
|
|
1378
1591
|
if (node.parent.type === 'property') {
|
|
1379
|
-
|
|
1592
|
+
const key = node.parent.children[0].value;
|
|
1380
1593
|
path.push(key);
|
|
1381
1594
|
}
|
|
1382
1595
|
else if (node.parent.type === 'array') {
|
|
1383
|
-
|
|
1596
|
+
const index = node.parent.children.indexOf(node);
|
|
1384
1597
|
if (index !== -1) {
|
|
1385
1598
|
path.push(index);
|
|
1386
1599
|
}
|
|
@@ -1395,10 +1608,9 @@ function getNodeValue(node) {
|
|
|
1395
1608
|
case 'array':
|
|
1396
1609
|
return node.children.map(getNodeValue);
|
|
1397
1610
|
case 'object':
|
|
1398
|
-
|
|
1399
|
-
for (
|
|
1400
|
-
|
|
1401
|
-
var valueNode = prop.children[1];
|
|
1611
|
+
const obj = Object.create(null);
|
|
1612
|
+
for (let prop of node.children) {
|
|
1613
|
+
const valueNode = prop.children[1];
|
|
1402
1614
|
if (valueNode) {
|
|
1403
1615
|
obj[prop.children[0].value] = getNodeValue(valueNode);
|
|
1404
1616
|
}
|
|
@@ -1413,20 +1625,18 @@ function getNodeValue(node) {
|
|
|
1413
1625
|
return undefined;
|
|
1414
1626
|
}
|
|
1415
1627
|
}
|
|
1416
|
-
function contains(node, offset, includeRightBound) {
|
|
1417
|
-
if (includeRightBound === void 0) { includeRightBound = false; }
|
|
1628
|
+
function contains(node, offset, includeRightBound = false) {
|
|
1418
1629
|
return (offset >= node.offset && offset < (node.offset + node.length)) || includeRightBound && (offset === (node.offset + node.length));
|
|
1419
1630
|
}
|
|
1420
1631
|
/**
|
|
1421
1632
|
* Finds the most inner node at the given offset. If includeRightBound is set, also finds nodes that end at the given offset.
|
|
1422
1633
|
*/
|
|
1423
|
-
function findNodeAtOffset(node, offset, includeRightBound) {
|
|
1424
|
-
if (includeRightBound === void 0) { includeRightBound = false; }
|
|
1634
|
+
function findNodeAtOffset(node, offset, includeRightBound = false) {
|
|
1425
1635
|
if (contains(node, offset, includeRightBound)) {
|
|
1426
|
-
|
|
1636
|
+
const children = node.children;
|
|
1427
1637
|
if (Array.isArray(children)) {
|
|
1428
|
-
for (
|
|
1429
|
-
|
|
1638
|
+
for (let i = 0; i < children.length && children[i].offset <= offset; i++) {
|
|
1639
|
+
const item = findNodeAtOffset(children[i], offset, includeRightBound);
|
|
1430
1640
|
if (item) {
|
|
1431
1641
|
return item;
|
|
1432
1642
|
}
|
|
@@ -1439,71 +1649,77 @@ function findNodeAtOffset(node, offset, includeRightBound) {
|
|
|
1439
1649
|
/**
|
|
1440
1650
|
* Parses the given text and invokes the visitor functions for each object, array and literal reached.
|
|
1441
1651
|
*/
|
|
1442
|
-
function visit(text, visitor, options) {
|
|
1443
|
-
|
|
1444
|
-
|
|
1652
|
+
function visit(text, visitor, options = ParseOptions.DEFAULT) {
|
|
1653
|
+
const _scanner = (0,_scanner__WEBPACK_IMPORTED_MODULE_0__.createScanner)(text, false);
|
|
1654
|
+
// Important: Only pass copies of this to visitor functions to prevent accidental modification, and
|
|
1655
|
+
// to not affect visitor functions which stored a reference to a previous JSONPath
|
|
1656
|
+
const _jsonPath = [];
|
|
1445
1657
|
function toNoArgVisit(visitFunction) {
|
|
1446
|
-
return visitFunction ?
|
|
1658
|
+
return visitFunction ? () => visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
1659
|
+
}
|
|
1660
|
+
function toNoArgVisitWithPath(visitFunction) {
|
|
1661
|
+
return visitFunction ? () => visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
1447
1662
|
}
|
|
1448
1663
|
function toOneArgVisit(visitFunction) {
|
|
1449
|
-
return visitFunction ?
|
|
1664
|
+
return visitFunction ? (arg) => visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
|
|
1450
1665
|
}
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1666
|
+
function toOneArgVisitWithPath(visitFunction) {
|
|
1667
|
+
return visitFunction ? (arg) => visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
|
|
1668
|
+
}
|
|
1669
|
+
const onObjectBegin = toNoArgVisitWithPath(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toNoArgVisit(visitor.onObjectEnd), onArrayBegin = toNoArgVisitWithPath(visitor.onArrayBegin), onArrayEnd = toNoArgVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
|
|
1670
|
+
const disallowComments = options && options.disallowComments;
|
|
1671
|
+
const allowTrailingComma = options && options.allowTrailingComma;
|
|
1454
1672
|
function scanNext() {
|
|
1455
1673
|
while (true) {
|
|
1456
|
-
|
|
1674
|
+
const token = _scanner.scan();
|
|
1457
1675
|
switch (_scanner.getTokenError()) {
|
|
1458
|
-
case 4 /* InvalidUnicode */:
|
|
1459
|
-
handleError(14 /* InvalidUnicode */);
|
|
1676
|
+
case 4 /* ScanError.InvalidUnicode */:
|
|
1677
|
+
handleError(14 /* ParseErrorCode.InvalidUnicode */);
|
|
1460
1678
|
break;
|
|
1461
|
-
case 5 /* InvalidEscapeCharacter */:
|
|
1462
|
-
handleError(15 /* InvalidEscapeCharacter */);
|
|
1679
|
+
case 5 /* ScanError.InvalidEscapeCharacter */:
|
|
1680
|
+
handleError(15 /* ParseErrorCode.InvalidEscapeCharacter */);
|
|
1463
1681
|
break;
|
|
1464
|
-
case 3 /* UnexpectedEndOfNumber */:
|
|
1465
|
-
handleError(13 /* UnexpectedEndOfNumber */);
|
|
1682
|
+
case 3 /* ScanError.UnexpectedEndOfNumber */:
|
|
1683
|
+
handleError(13 /* ParseErrorCode.UnexpectedEndOfNumber */);
|
|
1466
1684
|
break;
|
|
1467
|
-
case 1 /* UnexpectedEndOfComment */:
|
|
1685
|
+
case 1 /* ScanError.UnexpectedEndOfComment */:
|
|
1468
1686
|
if (!disallowComments) {
|
|
1469
|
-
handleError(11 /* UnexpectedEndOfComment */);
|
|
1687
|
+
handleError(11 /* ParseErrorCode.UnexpectedEndOfComment */);
|
|
1470
1688
|
}
|
|
1471
1689
|
break;
|
|
1472
|
-
case 2 /* UnexpectedEndOfString */:
|
|
1473
|
-
handleError(12 /* UnexpectedEndOfString */);
|
|
1690
|
+
case 2 /* ScanError.UnexpectedEndOfString */:
|
|
1691
|
+
handleError(12 /* ParseErrorCode.UnexpectedEndOfString */);
|
|
1474
1692
|
break;
|
|
1475
|
-
case 6 /* InvalidCharacter */:
|
|
1476
|
-
handleError(16 /* InvalidCharacter */);
|
|
1693
|
+
case 6 /* ScanError.InvalidCharacter */:
|
|
1694
|
+
handleError(16 /* ParseErrorCode.InvalidCharacter */);
|
|
1477
1695
|
break;
|
|
1478
1696
|
}
|
|
1479
1697
|
switch (token) {
|
|
1480
|
-
case 12 /* LineCommentTrivia */:
|
|
1481
|
-
case 13 /* BlockCommentTrivia */:
|
|
1698
|
+
case 12 /* SyntaxKind.LineCommentTrivia */:
|
|
1699
|
+
case 13 /* SyntaxKind.BlockCommentTrivia */:
|
|
1482
1700
|
if (disallowComments) {
|
|
1483
|
-
handleError(10 /* InvalidCommentToken */);
|
|
1701
|
+
handleError(10 /* ParseErrorCode.InvalidCommentToken */);
|
|
1484
1702
|
}
|
|
1485
1703
|
else {
|
|
1486
1704
|
onComment();
|
|
1487
1705
|
}
|
|
1488
1706
|
break;
|
|
1489
|
-
case 16 /* Unknown */:
|
|
1490
|
-
handleError(1 /* InvalidSymbol */);
|
|
1707
|
+
case 16 /* SyntaxKind.Unknown */:
|
|
1708
|
+
handleError(1 /* ParseErrorCode.InvalidSymbol */);
|
|
1491
1709
|
break;
|
|
1492
|
-
case 15 /* Trivia */:
|
|
1493
|
-
case 14 /* LineBreakTrivia */:
|
|
1710
|
+
case 15 /* SyntaxKind.Trivia */:
|
|
1711
|
+
case 14 /* SyntaxKind.LineBreakTrivia */:
|
|
1494
1712
|
break;
|
|
1495
1713
|
default:
|
|
1496
1714
|
return token;
|
|
1497
1715
|
}
|
|
1498
1716
|
}
|
|
1499
1717
|
}
|
|
1500
|
-
function handleError(error, skipUntilAfter, skipUntil) {
|
|
1501
|
-
if (skipUntilAfter === void 0) { skipUntilAfter = []; }
|
|
1502
|
-
if (skipUntil === void 0) { skipUntil = []; }
|
|
1718
|
+
function handleError(error, skipUntilAfter = [], skipUntil = []) {
|
|
1503
1719
|
onError(error);
|
|
1504
1720
|
if (skipUntilAfter.length + skipUntil.length > 0) {
|
|
1505
|
-
|
|
1506
|
-
while (token !== 17 /* EOF */) {
|
|
1721
|
+
let token = _scanner.getToken();
|
|
1722
|
+
while (token !== 17 /* SyntaxKind.EOF */) {
|
|
1507
1723
|
if (skipUntilAfter.indexOf(token) !== -1) {
|
|
1508
1724
|
scanNext();
|
|
1509
1725
|
break;
|
|
@@ -1516,39 +1732,36 @@ function visit(text, visitor, options) {
|
|
|
1516
1732
|
}
|
|
1517
1733
|
}
|
|
1518
1734
|
function parseString(isValue) {
|
|
1519
|
-
|
|
1735
|
+
const value = _scanner.getTokenValue();
|
|
1520
1736
|
if (isValue) {
|
|
1521
1737
|
onLiteralValue(value);
|
|
1522
1738
|
}
|
|
1523
1739
|
else {
|
|
1524
1740
|
onObjectProperty(value);
|
|
1741
|
+
// add property name afterwards
|
|
1742
|
+
_jsonPath.push(value);
|
|
1525
1743
|
}
|
|
1526
1744
|
scanNext();
|
|
1527
1745
|
return true;
|
|
1528
1746
|
}
|
|
1529
1747
|
function parseLiteral() {
|
|
1530
1748
|
switch (_scanner.getToken()) {
|
|
1531
|
-
case 11 /* NumericLiteral */:
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
value = 0;
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
catch (e) {
|
|
1541
|
-
handleError(2 /* InvalidNumberFormat */);
|
|
1749
|
+
case 11 /* SyntaxKind.NumericLiteral */:
|
|
1750
|
+
const tokenValue = _scanner.getTokenValue();
|
|
1751
|
+
let value = Number(tokenValue);
|
|
1752
|
+
if (isNaN(value)) {
|
|
1753
|
+
handleError(2 /* ParseErrorCode.InvalidNumberFormat */);
|
|
1754
|
+
value = 0;
|
|
1542
1755
|
}
|
|
1543
1756
|
onLiteralValue(value);
|
|
1544
1757
|
break;
|
|
1545
|
-
case 7 /* NullKeyword */:
|
|
1758
|
+
case 7 /* SyntaxKind.NullKeyword */:
|
|
1546
1759
|
onLiteralValue(null);
|
|
1547
1760
|
break;
|
|
1548
|
-
case 8 /* TrueKeyword */:
|
|
1761
|
+
case 8 /* SyntaxKind.TrueKeyword */:
|
|
1549
1762
|
onLiteralValue(true);
|
|
1550
1763
|
break;
|
|
1551
|
-
case 9 /* FalseKeyword */:
|
|
1764
|
+
case 9 /* SyntaxKind.FalseKeyword */:
|
|
1552
1765
|
onLiteralValue(false);
|
|
1553
1766
|
break;
|
|
1554
1767
|
default:
|
|
@@ -1558,49 +1771,50 @@ function visit(text, visitor, options) {
|
|
|
1558
1771
|
return true;
|
|
1559
1772
|
}
|
|
1560
1773
|
function parseProperty() {
|
|
1561
|
-
if (_scanner.getToken() !== 10 /* StringLiteral */) {
|
|
1562
|
-
handleError(3 /* PropertyNameExpected */, [], [2 /* CloseBraceToken */, 5 /* CommaToken */]);
|
|
1774
|
+
if (_scanner.getToken() !== 10 /* SyntaxKind.StringLiteral */) {
|
|
1775
|
+
handleError(3 /* ParseErrorCode.PropertyNameExpected */, [], [2 /* SyntaxKind.CloseBraceToken */, 5 /* SyntaxKind.CommaToken */]);
|
|
1563
1776
|
return false;
|
|
1564
1777
|
}
|
|
1565
1778
|
parseString(false);
|
|
1566
|
-
if (_scanner.getToken() === 6 /* ColonToken */) {
|
|
1779
|
+
if (_scanner.getToken() === 6 /* SyntaxKind.ColonToken */) {
|
|
1567
1780
|
onSeparator(':');
|
|
1568
1781
|
scanNext(); // consume colon
|
|
1569
1782
|
if (!parseValue()) {
|
|
1570
|
-
handleError(4 /* ValueExpected */, [], [2 /* CloseBraceToken */, 5 /* CommaToken */]);
|
|
1783
|
+
handleError(4 /* ParseErrorCode.ValueExpected */, [], [2 /* SyntaxKind.CloseBraceToken */, 5 /* SyntaxKind.CommaToken */]);
|
|
1571
1784
|
}
|
|
1572
1785
|
}
|
|
1573
1786
|
else {
|
|
1574
|
-
handleError(5 /* ColonExpected */, [], [2 /* CloseBraceToken */, 5 /* CommaToken */]);
|
|
1787
|
+
handleError(5 /* ParseErrorCode.ColonExpected */, [], [2 /* SyntaxKind.CloseBraceToken */, 5 /* SyntaxKind.CommaToken */]);
|
|
1575
1788
|
}
|
|
1789
|
+
_jsonPath.pop(); // remove processed property name
|
|
1576
1790
|
return true;
|
|
1577
1791
|
}
|
|
1578
1792
|
function parseObject() {
|
|
1579
1793
|
onObjectBegin();
|
|
1580
1794
|
scanNext(); // consume open brace
|
|
1581
|
-
|
|
1582
|
-
while (_scanner.getToken() !== 2 /* CloseBraceToken */ && _scanner.getToken() !== 17 /* EOF */) {
|
|
1583
|
-
if (_scanner.getToken() === 5 /* CommaToken */) {
|
|
1795
|
+
let needsComma = false;
|
|
1796
|
+
while (_scanner.getToken() !== 2 /* SyntaxKind.CloseBraceToken */ && _scanner.getToken() !== 17 /* SyntaxKind.EOF */) {
|
|
1797
|
+
if (_scanner.getToken() === 5 /* SyntaxKind.CommaToken */) {
|
|
1584
1798
|
if (!needsComma) {
|
|
1585
|
-
handleError(4 /* ValueExpected */, [], []);
|
|
1799
|
+
handleError(4 /* ParseErrorCode.ValueExpected */, [], []);
|
|
1586
1800
|
}
|
|
1587
1801
|
onSeparator(',');
|
|
1588
1802
|
scanNext(); // consume comma
|
|
1589
|
-
if (_scanner.getToken() === 2 /* CloseBraceToken */ && allowTrailingComma) {
|
|
1803
|
+
if (_scanner.getToken() === 2 /* SyntaxKind.CloseBraceToken */ && allowTrailingComma) {
|
|
1590
1804
|
break;
|
|
1591
1805
|
}
|
|
1592
1806
|
}
|
|
1593
1807
|
else if (needsComma) {
|
|
1594
|
-
handleError(6 /* CommaExpected */, [], []);
|
|
1808
|
+
handleError(6 /* ParseErrorCode.CommaExpected */, [], []);
|
|
1595
1809
|
}
|
|
1596
1810
|
if (!parseProperty()) {
|
|
1597
|
-
handleError(4 /* ValueExpected */, [], [2 /* CloseBraceToken */, 5 /* CommaToken */]);
|
|
1811
|
+
handleError(4 /* ParseErrorCode.ValueExpected */, [], [2 /* SyntaxKind.CloseBraceToken */, 5 /* SyntaxKind.CommaToken */]);
|
|
1598
1812
|
}
|
|
1599
1813
|
needsComma = true;
|
|
1600
1814
|
}
|
|
1601
1815
|
onObjectEnd();
|
|
1602
|
-
if (_scanner.getToken() !== 2 /* CloseBraceToken */) {
|
|
1603
|
-
handleError(7 /* CloseBraceExpected */, [2 /* CloseBraceToken */], []);
|
|
1816
|
+
if (_scanner.getToken() !== 2 /* SyntaxKind.CloseBraceToken */) {
|
|
1817
|
+
handleError(7 /* ParseErrorCode.CloseBraceExpected */, [2 /* SyntaxKind.CloseBraceToken */], []);
|
|
1604
1818
|
}
|
|
1605
1819
|
else {
|
|
1606
1820
|
scanNext(); // consume close brace
|
|
@@ -1610,29 +1824,40 @@ function visit(text, visitor, options) {
|
|
|
1610
1824
|
function parseArray() {
|
|
1611
1825
|
onArrayBegin();
|
|
1612
1826
|
scanNext(); // consume open bracket
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1827
|
+
let isFirstElement = true;
|
|
1828
|
+
let needsComma = false;
|
|
1829
|
+
while (_scanner.getToken() !== 4 /* SyntaxKind.CloseBracketToken */ && _scanner.getToken() !== 17 /* SyntaxKind.EOF */) {
|
|
1830
|
+
if (_scanner.getToken() === 5 /* SyntaxKind.CommaToken */) {
|
|
1616
1831
|
if (!needsComma) {
|
|
1617
|
-
handleError(4 /* ValueExpected */, [], []);
|
|
1832
|
+
handleError(4 /* ParseErrorCode.ValueExpected */, [], []);
|
|
1618
1833
|
}
|
|
1619
1834
|
onSeparator(',');
|
|
1620
1835
|
scanNext(); // consume comma
|
|
1621
|
-
if (_scanner.getToken() === 4 /* CloseBracketToken */ && allowTrailingComma) {
|
|
1836
|
+
if (_scanner.getToken() === 4 /* SyntaxKind.CloseBracketToken */ && allowTrailingComma) {
|
|
1622
1837
|
break;
|
|
1623
1838
|
}
|
|
1624
1839
|
}
|
|
1625
1840
|
else if (needsComma) {
|
|
1626
|
-
handleError(6 /* CommaExpected */, [], []);
|
|
1841
|
+
handleError(6 /* ParseErrorCode.CommaExpected */, [], []);
|
|
1842
|
+
}
|
|
1843
|
+
if (isFirstElement) {
|
|
1844
|
+
_jsonPath.push(0);
|
|
1845
|
+
isFirstElement = false;
|
|
1846
|
+
}
|
|
1847
|
+
else {
|
|
1848
|
+
_jsonPath[_jsonPath.length - 1]++;
|
|
1627
1849
|
}
|
|
1628
1850
|
if (!parseValue()) {
|
|
1629
|
-
handleError(4 /* ValueExpected */, [], [4 /* CloseBracketToken */, 5 /* CommaToken */]);
|
|
1851
|
+
handleError(4 /* ParseErrorCode.ValueExpected */, [], [4 /* SyntaxKind.CloseBracketToken */, 5 /* SyntaxKind.CommaToken */]);
|
|
1630
1852
|
}
|
|
1631
1853
|
needsComma = true;
|
|
1632
1854
|
}
|
|
1633
1855
|
onArrayEnd();
|
|
1634
|
-
if (
|
|
1635
|
-
|
|
1856
|
+
if (!isFirstElement) {
|
|
1857
|
+
_jsonPath.pop(); // remove array index
|
|
1858
|
+
}
|
|
1859
|
+
if (_scanner.getToken() !== 4 /* SyntaxKind.CloseBracketToken */) {
|
|
1860
|
+
handleError(8 /* ParseErrorCode.CloseBracketExpected */, [4 /* SyntaxKind.CloseBracketToken */], []);
|
|
1636
1861
|
}
|
|
1637
1862
|
else {
|
|
1638
1863
|
scanNext(); // consume close bracket
|
|
@@ -1641,30 +1866,30 @@ function visit(text, visitor, options) {
|
|
|
1641
1866
|
}
|
|
1642
1867
|
function parseValue() {
|
|
1643
1868
|
switch (_scanner.getToken()) {
|
|
1644
|
-
case 3 /* OpenBracketToken */:
|
|
1869
|
+
case 3 /* SyntaxKind.OpenBracketToken */:
|
|
1645
1870
|
return parseArray();
|
|
1646
|
-
case 1 /* OpenBraceToken */:
|
|
1871
|
+
case 1 /* SyntaxKind.OpenBraceToken */:
|
|
1647
1872
|
return parseObject();
|
|
1648
|
-
case 10 /* StringLiteral */:
|
|
1873
|
+
case 10 /* SyntaxKind.StringLiteral */:
|
|
1649
1874
|
return parseString(true);
|
|
1650
1875
|
default:
|
|
1651
1876
|
return parseLiteral();
|
|
1652
1877
|
}
|
|
1653
1878
|
}
|
|
1654
1879
|
scanNext();
|
|
1655
|
-
if (_scanner.getToken() === 17 /* EOF */) {
|
|
1880
|
+
if (_scanner.getToken() === 17 /* SyntaxKind.EOF */) {
|
|
1656
1881
|
if (options.allowEmptyContent) {
|
|
1657
1882
|
return true;
|
|
1658
1883
|
}
|
|
1659
|
-
handleError(4 /* ValueExpected */, [], []);
|
|
1884
|
+
handleError(4 /* ParseErrorCode.ValueExpected */, [], []);
|
|
1660
1885
|
return false;
|
|
1661
1886
|
}
|
|
1662
1887
|
if (!parseValue()) {
|
|
1663
|
-
handleError(4 /* ValueExpected */, [], []);
|
|
1888
|
+
handleError(4 /* ParseErrorCode.ValueExpected */, [], []);
|
|
1664
1889
|
return false;
|
|
1665
1890
|
}
|
|
1666
|
-
if (_scanner.getToken() !== 17 /* EOF */) {
|
|
1667
|
-
handleError(9 /* EndOfFileExpected */, [], []);
|
|
1891
|
+
if (_scanner.getToken() !== 17 /* SyntaxKind.EOF */) {
|
|
1892
|
+
handleError(9 /* ParseErrorCode.EndOfFileExpected */, [], []);
|
|
1668
1893
|
}
|
|
1669
1894
|
return true;
|
|
1670
1895
|
}
|
|
@@ -1674,14 +1899,14 @@ function visit(text, visitor, options) {
|
|
|
1674
1899
|
* of comments with a replaceCharacter
|
|
1675
1900
|
*/
|
|
1676
1901
|
function stripComments(text, replaceCh) {
|
|
1677
|
-
|
|
1902
|
+
let _scanner = (0,_scanner__WEBPACK_IMPORTED_MODULE_0__.createScanner)(text), parts = [], kind, offset = 0, pos;
|
|
1678
1903
|
do {
|
|
1679
1904
|
pos = _scanner.getPosition();
|
|
1680
1905
|
kind = _scanner.scan();
|
|
1681
1906
|
switch (kind) {
|
|
1682
|
-
case 12 /* LineCommentTrivia */:
|
|
1683
|
-
case 13 /* BlockCommentTrivia */:
|
|
1684
|
-
case 17 /* EOF */:
|
|
1907
|
+
case 12 /* SyntaxKind.LineCommentTrivia */:
|
|
1908
|
+
case 13 /* SyntaxKind.BlockCommentTrivia */:
|
|
1909
|
+
case 17 /* SyntaxKind.EOF */:
|
|
1685
1910
|
if (offset !== pos) {
|
|
1686
1911
|
parts.push(text.substring(offset, pos));
|
|
1687
1912
|
}
|
|
@@ -1691,7 +1916,7 @@ function stripComments(text, replaceCh) {
|
|
|
1691
1916
|
offset = _scanner.getPosition();
|
|
1692
1917
|
break;
|
|
1693
1918
|
}
|
|
1694
|
-
} while (kind !== 17 /* EOF */);
|
|
1919
|
+
} while (kind !== 17 /* SyntaxKind.EOF */);
|
|
1695
1920
|
return parts.join('');
|
|
1696
1921
|
}
|
|
1697
1922
|
function getNodeType(value) {
|
|
@@ -2151,11 +2376,12 @@ class PackageJSONContribution {
|
|
|
2151
2376
|
return null;
|
|
2152
2377
|
}
|
|
2153
2378
|
isValidNPMName(name) {
|
|
2154
|
-
// following rules from https://github.com/npm/validate-npm-package-name
|
|
2155
|
-
|
|
2379
|
+
// following rules from https://github.com/npm/validate-npm-package-name,
|
|
2380
|
+
// leading slash added as additional security measure
|
|
2381
|
+
if (!name || name.length > 214 || name.match(/^[-_.\s]/)) {
|
|
2156
2382
|
return false;
|
|
2157
2383
|
}
|
|
2158
|
-
const match = name.match(/^(?:@([
|
|
2384
|
+
const match = name.match(/^(?:@([^/~\s)('!*]+?)[/])?([^/~)('!*\s]+?)$/);
|
|
2159
2385
|
if (match) {
|
|
2160
2386
|
const scope = match[1];
|
|
2161
2387
|
if (scope && encodeURIComponent(scope) !== scope) {
|
|
@@ -2181,7 +2407,7 @@ class PackageJSONContribution {
|
|
|
2181
2407
|
}
|
|
2182
2408
|
npmView(npmCommandPath, pack, resource) {
|
|
2183
2409
|
return new Promise((resolve, _reject) => {
|
|
2184
|
-
const args = ['view', '--json', pack, 'description', 'dist-tags.latest', 'homepage', 'version', 'time'];
|
|
2410
|
+
const args = ['view', '--json', '--', pack, 'description', 'dist-tags.latest', 'homepage', 'version', 'time'];
|
|
2185
2411
|
const cwd = resource && resource.scheme === 'file' ? (0, path_1.dirname)(resource.fsPath) : undefined;
|
|
2186
2412
|
cp.execFile(npmCommandPath, args, { cwd }, (error, stdout) => {
|
|
2187
2413
|
if (!error) {
|