1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | Object.defineProperty(exports, "__esModule", { value: true });
|
19 | var fs = require("fs");
|
20 | var resolve = require("resolve");
|
21 | var ts = require("typescript");
|
22 |
|
23 |
|
24 |
|
25 | function arrayify(arg) {
|
26 | if (Array.isArray(arg)) {
|
27 | return arg;
|
28 | }
|
29 | else if (arg != undefined) {
|
30 | return [arg];
|
31 | }
|
32 | else {
|
33 | return [];
|
34 | }
|
35 | }
|
36 | exports.arrayify = arrayify;
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | function objectify(arg) {
|
42 | if (typeof arg === "object" && arg != undefined) {
|
43 | return arg;
|
44 | }
|
45 | else {
|
46 | return {};
|
47 | }
|
48 | }
|
49 | exports.objectify = objectify;
|
50 | function hasOwnProperty(arg, key) {
|
51 | return Object.prototype.hasOwnProperty.call(arg, key);
|
52 | }
|
53 | exports.hasOwnProperty = hasOwnProperty;
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | function camelize(stringWithHyphens) {
|
59 | return stringWithHyphens.replace(/-(.)/g, function (_, nextLetter) {
|
60 | return nextLetter.toUpperCase();
|
61 | });
|
62 | }
|
63 | exports.camelize = camelize;
|
64 | function isUpperCase(str) {
|
65 | return str === str.toUpperCase();
|
66 | }
|
67 | exports.isUpperCase = isUpperCase;
|
68 | function isLowerCase(str) {
|
69 | return str === str.toLowerCase();
|
70 | }
|
71 | exports.isLowerCase = isLowerCase;
|
72 |
|
73 |
|
74 |
|
75 | function dedent(strings) {
|
76 | var values = [];
|
77 | for (var _i = 1; _i < arguments.length; _i++) {
|
78 | values[_i - 1] = arguments[_i];
|
79 | }
|
80 | var fullString = strings.reduce(function (accumulator, str, i) { return "" + accumulator + values[i - 1] + str; });
|
81 |
|
82 | var match = fullString.match(/^[ \t]*(?=\S)/gm);
|
83 | if (match === null) {
|
84 |
|
85 | return fullString;
|
86 | }
|
87 |
|
88 | var indent = Math.min.apply(Math, match.map(function (el) { return el.length; }));
|
89 | var regexp = new RegExp("^[ \\t]{" + indent + "}", "gm");
|
90 | fullString = indent > 0 ? fullString.replace(regexp, "") : fullString;
|
91 | return fullString;
|
92 | }
|
93 | exports.dedent = dedent;
|
94 |
|
95 |
|
96 |
|
97 | function stripComments(content) {
|
98 | |
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 | var regexp = /("(?:[^\\\"]*(?:\\.)?)*")|('(?:[^\\\']*(?:\\.)?)*')|(\/\*(?:\r?\n|.)*?\*\/)|(\/{2,}.*?(?:(?:\r?\n)|$))/g;
|
105 | var result = content.replace(regexp, function (match, _m1, _m2, m3, m4) {
|
106 |
|
107 | if (m3 !== undefined) {
|
108 |
|
109 | return "";
|
110 | }
|
111 | else if (m4 !== undefined) {
|
112 |
|
113 | var length = m4.length;
|
114 | if (length > 2 && m4[length - 1] === "\n") {
|
115 | return m4[length - 2] === "\r" ? "\r\n" : "\n";
|
116 | }
|
117 | else {
|
118 | return "";
|
119 | }
|
120 | }
|
121 | else {
|
122 |
|
123 | return match;
|
124 | }
|
125 | });
|
126 | return result;
|
127 | }
|
128 | exports.stripComments = stripComments;
|
129 |
|
130 |
|
131 |
|
132 | function escapeRegExp(re) {
|
133 | return re.replace(/[.+*?|^$[\]{}()\\]/g, "\\$&");
|
134 | }
|
135 | exports.escapeRegExp = escapeRegExp;
|
136 | function arraysAreEqual(a, b, eq) {
|
137 | return (a === b ||
|
138 | (a !== undefined &&
|
139 | b !== undefined &&
|
140 | a.length === b.length &&
|
141 | a.every(function (x, idx) { return eq(x, b[idx]); })));
|
142 | }
|
143 | exports.arraysAreEqual = arraysAreEqual;
|
144 |
|
145 | function find(inputs, getResult) {
|
146 | for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) {
|
147 | var element = inputs_1[_i];
|
148 | var result = getResult(element);
|
149 | if (result !== undefined) {
|
150 | return result;
|
151 | }
|
152 | }
|
153 | return undefined;
|
154 | }
|
155 | exports.find = find;
|
156 |
|
157 | function flatMap(inputs, getOutputs) {
|
158 | var out = [];
|
159 | for (var i = 0; i < inputs.length; i++) {
|
160 | out.push.apply(out, getOutputs(inputs[i], i));
|
161 | }
|
162 | return out;
|
163 | }
|
164 | exports.flatMap = flatMap;
|
165 |
|
166 | function mapDefined(inputs, getOutput) {
|
167 | var out = [];
|
168 | for (var _i = 0, inputs_2 = inputs; _i < inputs_2.length; _i++) {
|
169 | var input = inputs_2[_i];
|
170 | var output = getOutput(input);
|
171 | if (output !== undefined) {
|
172 | out.push(output);
|
173 | }
|
174 | }
|
175 | return out;
|
176 | }
|
177 | exports.mapDefined = mapDefined;
|
178 | function readBufferWithDetectedEncoding(buffer) {
|
179 | switch (detectBufferEncoding(buffer)) {
|
180 | case "utf8":
|
181 | return buffer.toString();
|
182 | case "utf8-bom":
|
183 | return buffer.toString("utf-8", 2);
|
184 | case "utf16le":
|
185 | return buffer.toString("utf16le", 2);
|
186 | case "utf16be":
|
187 |
|
188 | var len = buffer.length & ~1;
|
189 |
|
190 | for (var i = 0; i < len; i += 2) {
|
191 | var temp = buffer[i];
|
192 | buffer[i] = buffer[i + 1];
|
193 | buffer[i + 1] = temp;
|
194 | }
|
195 | return buffer.toString("utf16le", 2);
|
196 | }
|
197 | }
|
198 | exports.readBufferWithDetectedEncoding = readBufferWithDetectedEncoding;
|
199 | function detectBufferEncoding(buffer, length) {
|
200 | if (length === void 0) { length = buffer.length; }
|
201 | if (length < 2) {
|
202 | return "utf8";
|
203 | }
|
204 | switch (buffer[0]) {
|
205 | case 0xef:
|
206 | if (buffer[1] === 0xbb && length >= 3 && buffer[2] === 0xbf) {
|
207 | return "utf8-bom";
|
208 | }
|
209 | break;
|
210 | case 0xfe:
|
211 | if (buffer[1] === 0xff) {
|
212 | return "utf16be";
|
213 | }
|
214 | break;
|
215 | case 0xff:
|
216 | if (buffer[1] === 0xfe) {
|
217 | return "utf16le";
|
218 | }
|
219 | }
|
220 | return "utf8";
|
221 | }
|
222 | exports.detectBufferEncoding = detectBufferEncoding;
|
223 |
|
224 | function denormalizeWinPath(path) {
|
225 | return path.replace(/\\/g, "/");
|
226 | }
|
227 | exports.denormalizeWinPath = denormalizeWinPath;
|
228 | function isPascalCased(name) {
|
229 | return isUpperCase(name[0]) && !name.includes("_") && !name.includes("-");
|
230 | }
|
231 | exports.isPascalCased = isPascalCased;
|
232 | function isCamelCased(name) {
|
233 | return isLowerCase(name[0]) && !name.includes("_") && !name.includes("-");
|
234 | }
|
235 | exports.isCamelCased = isCamelCased;
|
236 | function isSeparatorCased(name, disallowedSeparator) {
|
237 | for (var i = 0; i < name.length; i++) {
|
238 | var c = name.charAt(i);
|
239 | if (c === disallowedSeparator || !isLowerCase(c)) {
|
240 | return false;
|
241 | }
|
242 | }
|
243 | return true;
|
244 | }
|
245 | function isKebabCased(name) {
|
246 | return isSeparatorCased(name, "_");
|
247 | }
|
248 | exports.isKebabCased = isKebabCased;
|
249 | function isSnakeCased(name) {
|
250 | return isSeparatorCased(name, "-");
|
251 | }
|
252 | exports.isSnakeCased = isSnakeCased;
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 | function tryResolvePackage(packageName, relativeTo) {
|
259 | var realRelativeToPath = relativeTo !== undefined ? fs.realpathSync(relativeTo) : undefined;
|
260 | var resolvedPath = tryResolveSync(packageName, realRelativeToPath);
|
261 | if (resolvedPath === undefined) {
|
262 | resolvedPath = tryResolveSync(packageName, relativeTo);
|
263 | }
|
264 | return resolvedPath;
|
265 | }
|
266 | exports.tryResolvePackage = tryResolvePackage;
|
267 |
|
268 |
|
269 |
|
270 | function tryResolveSync(packageName, relativeTo) {
|
271 | try {
|
272 | return resolve.sync(packageName, { basedir: relativeTo });
|
273 | }
|
274 | catch (_a) {
|
275 | return undefined;
|
276 | }
|
277 | }
|
278 |
|
279 |
|
280 |
|
281 | function isFunctionScopeBoundary(node) {
|
282 | switch (node.kind) {
|
283 | case ts.SyntaxKind.FunctionExpression:
|
284 | case ts.SyntaxKind.ArrowFunction:
|
285 | case ts.SyntaxKind.Constructor:
|
286 | case ts.SyntaxKind.ModuleDeclaration:
|
287 | case ts.SyntaxKind.ClassDeclaration:
|
288 | case ts.SyntaxKind.ClassExpression:
|
289 | case ts.SyntaxKind.EnumDeclaration:
|
290 | case ts.SyntaxKind.MethodDeclaration:
|
291 | case ts.SyntaxKind.FunctionDeclaration:
|
292 | case ts.SyntaxKind.GetAccessor:
|
293 | case ts.SyntaxKind.SetAccessor:
|
294 | case ts.SyntaxKind.InterfaceDeclaration:
|
295 | case ts.SyntaxKind.TypeAliasDeclaration:
|
296 | case ts.SyntaxKind.MethodSignature:
|
297 | case ts.SyntaxKind.CallSignature:
|
298 | case ts.SyntaxKind.ConstructSignature:
|
299 | case ts.SyntaxKind.ConstructorType:
|
300 | case ts.SyntaxKind.FunctionType:
|
301 | case ts.SyntaxKind.MappedType:
|
302 | case ts.SyntaxKind.ConditionalType:
|
303 | return true;
|
304 | case ts.SyntaxKind.SourceFile:
|
305 |
|
306 |
|
307 | return ts.isExternalModule(node);
|
308 |
|
309 | default:
|
310 | return false;
|
311 | }
|
312 | }
|
313 | exports.isFunctionScopeBoundary = isFunctionScopeBoundary;
|