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