1 | (function (factory) {
|
2 | if (typeof module === "object" && typeof module.exports === "object") {
|
3 | var v = factory(require, exports);
|
4 | if (v !== undefined) module.exports = v;
|
5 | }
|
6 | else if (typeof define === "function" && define.amd) {
|
7 | define(["require", "exports", "./impl/format", "./impl/edit", "./impl/scanner", "./impl/parser"], factory);
|
8 | }
|
9 | })(function (require, exports) {
|
10 | |
11 |
|
12 |
|
13 |
|
14 | 'use strict';
|
15 | Object.defineProperty(exports, "__esModule", { value: true });
|
16 | exports.applyEdits = exports.modify = exports.format = exports.printParseErrorCode = exports.ParseErrorCode = exports.stripComments = exports.visit = exports.getNodeValue = exports.getNodePath = exports.findNodeAtOffset = exports.findNodeAtLocation = exports.parseTree = exports.parse = exports.getLocation = exports.SyntaxKind = exports.ScanError = exports.createScanner = void 0;
|
17 | const formatter = require("./impl/format");
|
18 | const edit = require("./impl/edit");
|
19 | const scanner = require("./impl/scanner");
|
20 | const parser = require("./impl/parser");
|
21 | |
22 |
|
23 |
|
24 |
|
25 | exports.createScanner = scanner.createScanner;
|
26 | var ScanError;
|
27 | (function (ScanError) {
|
28 | ScanError[ScanError["None"] = 0] = "None";
|
29 | ScanError[ScanError["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
|
30 | ScanError[ScanError["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
|
31 | ScanError[ScanError["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
|
32 | ScanError[ScanError["InvalidUnicode"] = 4] = "InvalidUnicode";
|
33 | ScanError[ScanError["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
|
34 | ScanError[ScanError["InvalidCharacter"] = 6] = "InvalidCharacter";
|
35 | })(ScanError || (exports.ScanError = ScanError = {}));
|
36 | var SyntaxKind;
|
37 | (function (SyntaxKind) {
|
38 | SyntaxKind[SyntaxKind["OpenBraceToken"] = 1] = "OpenBraceToken";
|
39 | SyntaxKind[SyntaxKind["CloseBraceToken"] = 2] = "CloseBraceToken";
|
40 | SyntaxKind[SyntaxKind["OpenBracketToken"] = 3] = "OpenBracketToken";
|
41 | SyntaxKind[SyntaxKind["CloseBracketToken"] = 4] = "CloseBracketToken";
|
42 | SyntaxKind[SyntaxKind["CommaToken"] = 5] = "CommaToken";
|
43 | SyntaxKind[SyntaxKind["ColonToken"] = 6] = "ColonToken";
|
44 | SyntaxKind[SyntaxKind["NullKeyword"] = 7] = "NullKeyword";
|
45 | SyntaxKind[SyntaxKind["TrueKeyword"] = 8] = "TrueKeyword";
|
46 | SyntaxKind[SyntaxKind["FalseKeyword"] = 9] = "FalseKeyword";
|
47 | SyntaxKind[SyntaxKind["StringLiteral"] = 10] = "StringLiteral";
|
48 | SyntaxKind[SyntaxKind["NumericLiteral"] = 11] = "NumericLiteral";
|
49 | SyntaxKind[SyntaxKind["LineCommentTrivia"] = 12] = "LineCommentTrivia";
|
50 | SyntaxKind[SyntaxKind["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
|
51 | SyntaxKind[SyntaxKind["LineBreakTrivia"] = 14] = "LineBreakTrivia";
|
52 | SyntaxKind[SyntaxKind["Trivia"] = 15] = "Trivia";
|
53 | SyntaxKind[SyntaxKind["Unknown"] = 16] = "Unknown";
|
54 | SyntaxKind[SyntaxKind["EOF"] = 17] = "EOF";
|
55 | })(SyntaxKind || (exports.SyntaxKind = SyntaxKind = {}));
|
56 | |
57 |
|
58 |
|
59 | exports.getLocation = parser.getLocation;
|
60 | |
61 |
|
62 |
|
63 |
|
64 | exports.parse = parser.parse;
|
65 | |
66 |
|
67 |
|
68 | exports.parseTree = parser.parseTree;
|
69 | |
70 |
|
71 |
|
72 | exports.findNodeAtLocation = parser.findNodeAtLocation;
|
73 | |
74 |
|
75 |
|
76 | exports.findNodeAtOffset = parser.findNodeAtOffset;
|
77 | |
78 |
|
79 |
|
80 | exports.getNodePath = parser.getNodePath;
|
81 | |
82 |
|
83 |
|
84 | exports.getNodeValue = parser.getNodeValue;
|
85 | |
86 |
|
87 |
|
88 | exports.visit = parser.visit;
|
89 | |
90 |
|
91 |
|
92 |
|
93 |
|
94 | exports.stripComments = parser.stripComments;
|
95 | var ParseErrorCode;
|
96 | (function (ParseErrorCode) {
|
97 | ParseErrorCode[ParseErrorCode["InvalidSymbol"] = 1] = "InvalidSymbol";
|
98 | ParseErrorCode[ParseErrorCode["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
|
99 | ParseErrorCode[ParseErrorCode["PropertyNameExpected"] = 3] = "PropertyNameExpected";
|
100 | ParseErrorCode[ParseErrorCode["ValueExpected"] = 4] = "ValueExpected";
|
101 | ParseErrorCode[ParseErrorCode["ColonExpected"] = 5] = "ColonExpected";
|
102 | ParseErrorCode[ParseErrorCode["CommaExpected"] = 6] = "CommaExpected";
|
103 | ParseErrorCode[ParseErrorCode["CloseBraceExpected"] = 7] = "CloseBraceExpected";
|
104 | ParseErrorCode[ParseErrorCode["CloseBracketExpected"] = 8] = "CloseBracketExpected";
|
105 | ParseErrorCode[ParseErrorCode["EndOfFileExpected"] = 9] = "EndOfFileExpected";
|
106 | ParseErrorCode[ParseErrorCode["InvalidCommentToken"] = 10] = "InvalidCommentToken";
|
107 | ParseErrorCode[ParseErrorCode["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
|
108 | ParseErrorCode[ParseErrorCode["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
|
109 | ParseErrorCode[ParseErrorCode["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
|
110 | ParseErrorCode[ParseErrorCode["InvalidUnicode"] = 14] = "InvalidUnicode";
|
111 | ParseErrorCode[ParseErrorCode["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
|
112 | ParseErrorCode[ParseErrorCode["InvalidCharacter"] = 16] = "InvalidCharacter";
|
113 | })(ParseErrorCode || (exports.ParseErrorCode = ParseErrorCode = {}));
|
114 | function printParseErrorCode(code) {
|
115 | switch (code) {
|
116 | case 1 : return 'InvalidSymbol';
|
117 | case 2 : return 'InvalidNumberFormat';
|
118 | case 3 : return 'PropertyNameExpected';
|
119 | case 4 : return 'ValueExpected';
|
120 | case 5 : return 'ColonExpected';
|
121 | case 6 : return 'CommaExpected';
|
122 | case 7 : return 'CloseBraceExpected';
|
123 | case 8 : return 'CloseBracketExpected';
|
124 | case 9 : return 'EndOfFileExpected';
|
125 | case 10 : return 'InvalidCommentToken';
|
126 | case 11 : return 'UnexpectedEndOfComment';
|
127 | case 12 : return 'UnexpectedEndOfString';
|
128 | case 13 : return 'UnexpectedEndOfNumber';
|
129 | case 14 : return 'InvalidUnicode';
|
130 | case 15 : return 'InvalidEscapeCharacter';
|
131 | case 16 : return 'InvalidCharacter';
|
132 | }
|
133 | return '<unknown ParseErrorCode>';
|
134 | }
|
135 | exports.printParseErrorCode = printParseErrorCode;
|
136 | |
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 | function format(documentText, range, options) {
|
146 | return formatter.format(documentText, range, options);
|
147 | }
|
148 | exports.format = format;
|
149 | |
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 | function modify(text, path, value, options) {
|
162 | return edit.setProperty(text, path, value, options);
|
163 | }
|
164 | exports.modify = modify;
|
165 | |
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 | function applyEdits(text, edits) {
|
173 | let sortedEdits = edits.slice(0).sort((a, b) => {
|
174 | const diff = a.offset - b.offset;
|
175 | if (diff === 0) {
|
176 | return a.length - b.length;
|
177 | }
|
178 | return diff;
|
179 | });
|
180 | let lastModifiedOffset = text.length;
|
181 | for (let i = sortedEdits.length - 1; i >= 0; i--) {
|
182 | let e = sortedEdits[i];
|
183 | if (e.offset + e.length <= lastModifiedOffset) {
|
184 | text = edit.applyEdit(text, e);
|
185 | }
|
186 | else {
|
187 | throw new Error('Overlapping edit');
|
188 | }
|
189 | lastModifiedOffset = e.offset;
|
190 | }
|
191 | return text;
|
192 | }
|
193 | exports.applyEdits = applyEdits;
|
194 | });
|