@tslite/parser 1.9.0 → 1.12.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/LICENSE +55 -0
- package/NOTICE +14 -0
- package/dist/_namespaces/ts.d.ts +18 -0
- package/dist/_namespaces/ts.js +21 -0
- package/dist/_namespaces/ts.performance.d.ts +1 -0
- package/dist/_namespaces/ts.performance.js +2 -0
- package/dist/core.d.ts +450 -0
- package/dist/core.js +1394 -0
- package/dist/corePublic.d.ts +62 -0
- package/dist/corePublic.js +31 -0
- package/dist/debug.d.ts +74 -0
- package/dist/debug.js +326 -0
- package/dist/diagnosticInformationMap.generated.d.ts +1435 -0
- package/dist/diagnosticInformationMap.generated.js +1441 -0
- package/dist/factory.d.ts +78 -0
- package/dist/factory.js +622 -0
- package/dist/factoryPublic.d.ts +314 -0
- package/dist/factoryPublic.js +1796 -0
- package/dist/index.d.ts +1 -249
- package/dist/index.js +4 -6
- package/dist/parser.d.ts +59 -0
- package/dist/parser.js +5075 -0
- package/dist/path.d.ts +312 -0
- package/dist/path.js +475 -0
- package/dist/perfLogger.d.ts +4 -0
- package/dist/perfLogger.js +38 -0
- package/dist/performance.d.ts +20 -0
- package/dist/performance.js +49 -0
- package/dist/performanceTimestamp.d.ts +2 -0
- package/dist/performanceTimestamp.js +2 -0
- package/dist/scanner.d.ts +80 -0
- package/dist/scanner.js +1984 -0
- package/dist/shims/mapShim.d.ts +23 -0
- package/dist/shims/mapShim.js +156 -0
- package/dist/types.d.ts +2626 -0
- package/dist/types.js +1074 -0
- package/dist/utilities.d.ts +473 -0
- package/dist/utilities.js +2632 -0
- package/dist/utilitiesPublic.d.ts +274 -0
- package/dist/utilitiesPublic.js +1049 -0
- package/dist/visitor.d.ts +15 -0
- package/dist/visitor.js +64 -0
- package/dist/visitorPublic.d.ts +82 -0
- package/dist/visitorPublic.js +352 -0
- package/package.json +14 -42
- package/dist/index.cjs +0 -6
- package/dist/index.d.cts +0 -249
package/dist/path.js
ADDED
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/compiler/path.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { Debug, compareStringsCaseInsensitive, compareValues, endsWith, equateStringsCaseInsensitive, equateStringsCaseSensitive, getStringComparer, identity, lastOrUndefined, some, startsWith, } from "./_namespaces/ts.js";
|
|
3
|
+
/**
|
|
4
|
+
* Internally, we represent paths as strings with '/' as the directory separator.
|
|
5
|
+
* When we make system calls (eg: LanguageServiceHost.getDirectory()),
|
|
6
|
+
* we expect the host to correctly handle paths in our specified format.
|
|
7
|
+
*/
|
|
8
|
+
export const directorySeparator = "/";
|
|
9
|
+
const altDirectorySeparator = "\\";
|
|
10
|
+
const urlSchemeSeparator = "://";
|
|
11
|
+
const backslashRegExp = /\\/g;
|
|
12
|
+
//// Path Tests
|
|
13
|
+
/**
|
|
14
|
+
* Determines whether a charCode corresponds to `/` or `\`.
|
|
15
|
+
*/
|
|
16
|
+
export function isAnyDirectorySeparator(charCode) {
|
|
17
|
+
return charCode === 47 /* CharacterCodes.slash */ || charCode === 92 /* CharacterCodes.backslash */;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Determines whether a path is an absolute disk path (e.g. starts with `/`, or a dos path
|
|
21
|
+
* like `c:`, `c:\` or `c:/`).
|
|
22
|
+
*/
|
|
23
|
+
export function isRootedDiskPath(path) {
|
|
24
|
+
return getEncodedRootLength(path) > 0;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Determines whether a path starts with an absolute path component (i.e. `/`, `c:/`, `file://`, etc.).
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* // POSIX
|
|
31
|
+
* pathIsAbsolute("/path/to/file.ext") === true
|
|
32
|
+
* // DOS
|
|
33
|
+
* pathIsAbsolute("c:/path/to/file.ext") === true
|
|
34
|
+
* // URL
|
|
35
|
+
* pathIsAbsolute("file:///path/to/file.ext") === true
|
|
36
|
+
* // Non-absolute
|
|
37
|
+
* pathIsAbsolute("path/to/file.ext") === false
|
|
38
|
+
* pathIsAbsolute("./path/to/file.ext") === false
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function pathIsAbsolute(path) {
|
|
42
|
+
return getEncodedRootLength(path) !== 0;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Determines whether a path starts with a relative path component (i.e. `.` or `..`).
|
|
46
|
+
*/
|
|
47
|
+
export function pathIsRelative(path) {
|
|
48
|
+
return /^\.\.?($|[\\/])/.test(path);
|
|
49
|
+
}
|
|
50
|
+
export function fileExtensionIs(path, extension) {
|
|
51
|
+
return path.length > extension.length && endsWith(path, extension);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Determines whether a path has a trailing separator (`/` or `\\`).
|
|
55
|
+
*/
|
|
56
|
+
export function hasTrailingDirectorySeparator(path) {
|
|
57
|
+
return path.length > 0 && isAnyDirectorySeparator(path.charCodeAt(path.length - 1));
|
|
58
|
+
}
|
|
59
|
+
//// Path Parsing
|
|
60
|
+
function isVolumeCharacter(charCode) {
|
|
61
|
+
return (charCode >= 97 /* CharacterCodes.a */ && charCode <= 122 /* CharacterCodes.z */) ||
|
|
62
|
+
(charCode >= 65 /* CharacterCodes.A */ && charCode <= 90 /* CharacterCodes.Z */);
|
|
63
|
+
}
|
|
64
|
+
function getFileUrlVolumeSeparatorEnd(url, start) {
|
|
65
|
+
const ch0 = url.charCodeAt(start);
|
|
66
|
+
if (ch0 === 58 /* CharacterCodes.colon */)
|
|
67
|
+
return start + 1;
|
|
68
|
+
if (ch0 === 37 /* CharacterCodes.percent */ && url.charCodeAt(start + 1) === 51 /* CharacterCodes._3 */) {
|
|
69
|
+
const ch2 = url.charCodeAt(start + 2);
|
|
70
|
+
if (ch2 === 97 /* CharacterCodes.a */ || ch2 === 65 /* CharacterCodes.A */)
|
|
71
|
+
return start + 3;
|
|
72
|
+
}
|
|
73
|
+
return -1;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Returns length of the root part of a path or URL (i.e. length of "/", "x:/", "//server/share/, file:///user/files").
|
|
77
|
+
* If the root is part of a URL, the twos-complement of the root length is returned.
|
|
78
|
+
*/
|
|
79
|
+
function getEncodedRootLength(path) {
|
|
80
|
+
if (!path)
|
|
81
|
+
return 0;
|
|
82
|
+
const ch0 = path.charCodeAt(0);
|
|
83
|
+
// POSIX or UNC
|
|
84
|
+
if (ch0 === 47 /* CharacterCodes.slash */ || ch0 === 92 /* CharacterCodes.backslash */) {
|
|
85
|
+
if (path.charCodeAt(1) !== ch0)
|
|
86
|
+
return 1; // POSIX: "/" (or non-normalized "\")
|
|
87
|
+
const p1 = path.indexOf(ch0 === 47 /* CharacterCodes.slash */ ? directorySeparator : altDirectorySeparator, 2);
|
|
88
|
+
if (p1 < 0)
|
|
89
|
+
return path.length; // UNC: "//server" or "\\server"
|
|
90
|
+
return p1 + 1; // UNC: "//server/" or "\\server\"
|
|
91
|
+
}
|
|
92
|
+
// DOS
|
|
93
|
+
if (isVolumeCharacter(ch0) && path.charCodeAt(1) === 58 /* CharacterCodes.colon */) {
|
|
94
|
+
const ch2 = path.charCodeAt(2);
|
|
95
|
+
if (ch2 === 47 /* CharacterCodes.slash */ || ch2 === 92 /* CharacterCodes.backslash */)
|
|
96
|
+
return 3; // DOS: "c:/" or "c:\"
|
|
97
|
+
if (path.length === 2)
|
|
98
|
+
return 2; // DOS: "c:" (but not "c:d")
|
|
99
|
+
}
|
|
100
|
+
// URL
|
|
101
|
+
const schemeEnd = path.indexOf(urlSchemeSeparator);
|
|
102
|
+
if (schemeEnd !== -1) {
|
|
103
|
+
const authorityStart = schemeEnd + urlSchemeSeparator.length;
|
|
104
|
+
const authorityEnd = path.indexOf(directorySeparator, authorityStart);
|
|
105
|
+
if (authorityEnd !== -1) { // URL: "file:///", "file://server/", "file://server/path"
|
|
106
|
+
// For local "file" URLs, include the leading DOS volume (if present).
|
|
107
|
+
// Per https://www.ietf.org/rfc/rfc1738.txt, a host of "" or "localhost" is a
|
|
108
|
+
// special case interpreted as "the machine from which the URL is being interpreted".
|
|
109
|
+
const scheme = path.slice(0, schemeEnd);
|
|
110
|
+
const authority = path.slice(authorityStart, authorityEnd);
|
|
111
|
+
if (scheme === "file" && (authority === "" || authority === "localhost") &&
|
|
112
|
+
isVolumeCharacter(path.charCodeAt(authorityEnd + 1))) {
|
|
113
|
+
const volumeSeparatorEnd = getFileUrlVolumeSeparatorEnd(path, authorityEnd + 2);
|
|
114
|
+
if (volumeSeparatorEnd !== -1) {
|
|
115
|
+
if (path.charCodeAt(volumeSeparatorEnd) === 47 /* CharacterCodes.slash */) {
|
|
116
|
+
// URL: "file:///c:/", "file://localhost/c:/", "file:///c%3a/", "file://localhost/c%3a/"
|
|
117
|
+
return ~(volumeSeparatorEnd + 1);
|
|
118
|
+
}
|
|
119
|
+
if (volumeSeparatorEnd === path.length) {
|
|
120
|
+
// URL: "file:///c:", "file://localhost/c:", "file:///c$3a", "file://localhost/c%3a"
|
|
121
|
+
// but not "file:///c:d" or "file:///c%3ad"
|
|
122
|
+
return ~volumeSeparatorEnd;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return ~(authorityEnd + 1); // URL: "file://server/", "http://server/"
|
|
127
|
+
}
|
|
128
|
+
return ~path.length; // URL: "file://server", "http://server"
|
|
129
|
+
}
|
|
130
|
+
// relative
|
|
131
|
+
return 0;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Returns length of the root part of a path or URL (i.e. length of "/", "x:/", "//server/share/, file:///user/files").
|
|
135
|
+
*
|
|
136
|
+
* For example:
|
|
137
|
+
* ```ts
|
|
138
|
+
* getRootLength("a") === 0 // ""
|
|
139
|
+
* getRootLength("/") === 1 // "/"
|
|
140
|
+
* getRootLength("c:") === 2 // "c:"
|
|
141
|
+
* getRootLength("c:d") === 0 // ""
|
|
142
|
+
* getRootLength("c:/") === 3 // "c:/"
|
|
143
|
+
* getRootLength("c:\\") === 3 // "c:\\"
|
|
144
|
+
* getRootLength("//server") === 7 // "//server"
|
|
145
|
+
* getRootLength("//server/share") === 8 // "//server/"
|
|
146
|
+
* getRootLength("\\\\server") === 7 // "\\\\server"
|
|
147
|
+
* getRootLength("\\\\server\\share") === 8 // "\\\\server\\"
|
|
148
|
+
* getRootLength("file:///path") === 8 // "file:///"
|
|
149
|
+
* getRootLength("file:///c:") === 10 // "file:///c:"
|
|
150
|
+
* getRootLength("file:///c:d") === 8 // "file:///"
|
|
151
|
+
* getRootLength("file:///c:/path") === 11 // "file:///c:/"
|
|
152
|
+
* getRootLength("file://server") === 13 // "file://server"
|
|
153
|
+
* getRootLength("file://server/path") === 14 // "file://server/"
|
|
154
|
+
* getRootLength("http://server") === 13 // "http://server"
|
|
155
|
+
* getRootLength("http://server/path") === 14 // "http://server/"
|
|
156
|
+
* ```
|
|
157
|
+
*/
|
|
158
|
+
export function getRootLength(path) {
|
|
159
|
+
const rootLength = getEncodedRootLength(path);
|
|
160
|
+
return rootLength < 0 ? ~rootLength : rootLength;
|
|
161
|
+
}
|
|
162
|
+
export function getDirectoryPath(path) {
|
|
163
|
+
path = normalizeSlashes(path);
|
|
164
|
+
// If the path provided is itself the root, then return it.
|
|
165
|
+
const rootLength = getRootLength(path);
|
|
166
|
+
if (rootLength === path.length)
|
|
167
|
+
return path;
|
|
168
|
+
// return the leading portion of the path up to the last (non-terminal) directory separator
|
|
169
|
+
// but not including any trailing directory separator.
|
|
170
|
+
path = removeTrailingDirectorySeparator(path);
|
|
171
|
+
return path.slice(0, Math.max(rootLength, path.lastIndexOf(directorySeparator)));
|
|
172
|
+
}
|
|
173
|
+
export function getBaseFileName(path, extensions, ignoreCase) {
|
|
174
|
+
path = normalizeSlashes(path);
|
|
175
|
+
// if the path provided is itself the root, then it has not file name.
|
|
176
|
+
const rootLength = getRootLength(path);
|
|
177
|
+
if (rootLength === path.length)
|
|
178
|
+
return "";
|
|
179
|
+
// return the trailing portion of the path starting after the last (non-terminal) directory
|
|
180
|
+
// separator but not including any trailing directory separator.
|
|
181
|
+
path = removeTrailingDirectorySeparator(path);
|
|
182
|
+
const name = path.slice(Math.max(getRootLength(path), path.lastIndexOf(directorySeparator) + 1));
|
|
183
|
+
const extension = extensions !== undefined && ignoreCase !== undefined ? getAnyExtensionFromPath(name, extensions, ignoreCase) : undefined;
|
|
184
|
+
return extension ? name.slice(0, name.length - extension.length) : name;
|
|
185
|
+
}
|
|
186
|
+
function tryGetExtensionFromPath(path, extension, stringEqualityComparer) {
|
|
187
|
+
if (!startsWith(extension, "."))
|
|
188
|
+
extension = "." + extension;
|
|
189
|
+
if (path.length >= extension.length && path.charCodeAt(path.length - extension.length) === 46 /* CharacterCodes.dot */) {
|
|
190
|
+
const pathExtension = path.slice(path.length - extension.length);
|
|
191
|
+
if (stringEqualityComparer(pathExtension, extension)) {
|
|
192
|
+
return pathExtension;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
function getAnyExtensionFromPathWorker(path, extensions, stringEqualityComparer) {
|
|
197
|
+
if (typeof extensions === "string") {
|
|
198
|
+
return tryGetExtensionFromPath(path, extensions, stringEqualityComparer) || "";
|
|
199
|
+
}
|
|
200
|
+
for (const extension of extensions) {
|
|
201
|
+
const result = tryGetExtensionFromPath(path, extension, stringEqualityComparer);
|
|
202
|
+
if (result)
|
|
203
|
+
return result;
|
|
204
|
+
}
|
|
205
|
+
return "";
|
|
206
|
+
}
|
|
207
|
+
export function getAnyExtensionFromPath(path, extensions, ignoreCase) {
|
|
208
|
+
// Retrieves any string from the final "." onwards from a base file name.
|
|
209
|
+
// Unlike extensionFromPath, which throws an exception on unrecognized extensions.
|
|
210
|
+
if (extensions) {
|
|
211
|
+
return getAnyExtensionFromPathWorker(removeTrailingDirectorySeparator(path), extensions, ignoreCase ? equateStringsCaseInsensitive : equateStringsCaseSensitive);
|
|
212
|
+
}
|
|
213
|
+
const baseFileName = getBaseFileName(path);
|
|
214
|
+
const extensionIndex = baseFileName.lastIndexOf(".");
|
|
215
|
+
if (extensionIndex >= 0) {
|
|
216
|
+
return baseFileName.substring(extensionIndex);
|
|
217
|
+
}
|
|
218
|
+
return "";
|
|
219
|
+
}
|
|
220
|
+
function pathComponents(path, rootLength) {
|
|
221
|
+
const root = path.substring(0, rootLength);
|
|
222
|
+
const rest = path.substring(rootLength).split(directorySeparator);
|
|
223
|
+
if (rest.length && !lastOrUndefined(rest))
|
|
224
|
+
rest.pop();
|
|
225
|
+
return [root, ...rest];
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Parse a path into an array containing a root component (at index 0) and zero or more path
|
|
229
|
+
* components (at indices > 0). The result is not normalized.
|
|
230
|
+
* If the path is relative, the root component is `""`.
|
|
231
|
+
* If the path is absolute, the root component includes the first path separator (`/`).
|
|
232
|
+
*
|
|
233
|
+
* ```ts
|
|
234
|
+
* // POSIX
|
|
235
|
+
* getPathComponents("/path/to/file.ext") === ["/", "path", "to", "file.ext"]
|
|
236
|
+
* getPathComponents("/path/to/") === ["/", "path", "to"]
|
|
237
|
+
* getPathComponents("/") === ["/"]
|
|
238
|
+
* // DOS
|
|
239
|
+
* getPathComponents("c:/path/to/file.ext") === ["c:/", "path", "to", "file.ext"]
|
|
240
|
+
* getPathComponents("c:/path/to/") === ["c:/", "path", "to"]
|
|
241
|
+
* getPathComponents("c:/") === ["c:/"]
|
|
242
|
+
* getPathComponents("c:") === ["c:"]
|
|
243
|
+
* // URL
|
|
244
|
+
* getPathComponents("http://typescriptlang.org/path/to/file.ext") === ["http://typescriptlang.org/", "path", "to", "file.ext"]
|
|
245
|
+
* getPathComponents("http://typescriptlang.org/path/to/") === ["http://typescriptlang.org/", "path", "to"]
|
|
246
|
+
* getPathComponents("http://typescriptlang.org/") === ["http://typescriptlang.org/"]
|
|
247
|
+
* getPathComponents("http://typescriptlang.org") === ["http://typescriptlang.org"]
|
|
248
|
+
* getPathComponents("file://server/path/to/file.ext") === ["file://server/", "path", "to", "file.ext"]
|
|
249
|
+
* getPathComponents("file://server/path/to/") === ["file://server/", "path", "to"]
|
|
250
|
+
* getPathComponents("file://server/") === ["file://server/"]
|
|
251
|
+
* getPathComponents("file://server") === ["file://server"]
|
|
252
|
+
* getPathComponents("file:///path/to/file.ext") === ["file:///", "path", "to", "file.ext"]
|
|
253
|
+
* getPathComponents("file:///path/to/") === ["file:///", "path", "to"]
|
|
254
|
+
* getPathComponents("file:///") === ["file:///"]
|
|
255
|
+
* getPathComponents("file://") === ["file://"]
|
|
256
|
+
*/
|
|
257
|
+
export function getPathComponents(path, currentDirectory = "") {
|
|
258
|
+
path = combinePaths(currentDirectory, path);
|
|
259
|
+
return pathComponents(path, getRootLength(path));
|
|
260
|
+
}
|
|
261
|
+
//// Path Formatting
|
|
262
|
+
/**
|
|
263
|
+
* Formats a parsed path consisting of a root component (at index 0) and zero or more path
|
|
264
|
+
* segments (at indices > 0).
|
|
265
|
+
*
|
|
266
|
+
* ```ts
|
|
267
|
+
* getPathFromPathComponents(["/", "path", "to", "file.ext"]) === "/path/to/file.ext"
|
|
268
|
+
* ```
|
|
269
|
+
*/
|
|
270
|
+
export function getPathFromPathComponents(pathComponents) {
|
|
271
|
+
if (pathComponents.length === 0)
|
|
272
|
+
return "";
|
|
273
|
+
const root = pathComponents[0] && ensureTrailingDirectorySeparator(pathComponents[0]);
|
|
274
|
+
return root + pathComponents.slice(1).join(directorySeparator);
|
|
275
|
+
}
|
|
276
|
+
//// Path Normalization
|
|
277
|
+
/**
|
|
278
|
+
* Normalize path separators, converting `\` into `/`.
|
|
279
|
+
*/
|
|
280
|
+
export function normalizeSlashes(path) {
|
|
281
|
+
return path.replace(backslashRegExp, directorySeparator);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Reduce an array of path components to a more simplified path by navigating any
|
|
285
|
+
* `"."` or `".."` entries in the path.
|
|
286
|
+
*/
|
|
287
|
+
export function reducePathComponents(components) {
|
|
288
|
+
if (!some(components))
|
|
289
|
+
return [];
|
|
290
|
+
const reduced = [components[0]];
|
|
291
|
+
for (let i = 1; i < components.length; i++) {
|
|
292
|
+
const component = components[i];
|
|
293
|
+
if (!component)
|
|
294
|
+
continue;
|
|
295
|
+
if (component === ".")
|
|
296
|
+
continue;
|
|
297
|
+
if (component === "..") {
|
|
298
|
+
if (reduced.length > 1) {
|
|
299
|
+
if (reduced[reduced.length - 1] !== "..") {
|
|
300
|
+
reduced.pop();
|
|
301
|
+
continue;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
else if (reduced[0])
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
reduced.push(component);
|
|
308
|
+
}
|
|
309
|
+
return reduced;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Combines paths. If a path is absolute, it replaces any previous path. Relative paths are not simplified.
|
|
313
|
+
*
|
|
314
|
+
* ```ts
|
|
315
|
+
* // Non-rooted
|
|
316
|
+
* combinePaths("path", "to", "file.ext") === "path/to/file.ext"
|
|
317
|
+
* combinePaths("path", "dir", "..", "to", "file.ext") === "path/dir/../to/file.ext"
|
|
318
|
+
* // POSIX
|
|
319
|
+
* combinePaths("/path", "to", "file.ext") === "/path/to/file.ext"
|
|
320
|
+
* combinePaths("/path", "/to", "file.ext") === "/to/file.ext"
|
|
321
|
+
* // DOS
|
|
322
|
+
* combinePaths("c:/path", "to", "file.ext") === "c:/path/to/file.ext"
|
|
323
|
+
* combinePaths("c:/path", "c:/to", "file.ext") === "c:/to/file.ext"
|
|
324
|
+
* // URL
|
|
325
|
+
* combinePaths("file:///path", "to", "file.ext") === "file:///path/to/file.ext"
|
|
326
|
+
* combinePaths("file:///path", "file:///to", "file.ext") === "file:///to/file.ext"
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
329
|
+
export function combinePaths(path, ...paths) {
|
|
330
|
+
if (path)
|
|
331
|
+
path = normalizeSlashes(path);
|
|
332
|
+
for (let relativePath of paths) {
|
|
333
|
+
if (!relativePath)
|
|
334
|
+
continue;
|
|
335
|
+
relativePath = normalizeSlashes(relativePath);
|
|
336
|
+
if (!path || getRootLength(relativePath) !== 0) {
|
|
337
|
+
path = relativePath;
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
path = ensureTrailingDirectorySeparator(path) + relativePath;
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
return path;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Parse a path into an array containing a root component (at index 0) and zero or more path
|
|
347
|
+
* components (at indices > 0). The result is normalized.
|
|
348
|
+
* If the path is relative, the root component is `""`.
|
|
349
|
+
* If the path is absolute, the root component includes the first path separator (`/`).
|
|
350
|
+
*
|
|
351
|
+
* ```ts
|
|
352
|
+
* getNormalizedPathComponents("to/dir/../file.ext", "/path/") === ["/", "path", "to", "file.ext"]
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
355
|
+
export function getNormalizedPathComponents(path, currentDirectory) {
|
|
356
|
+
return reducePathComponents(getPathComponents(path, currentDirectory));
|
|
357
|
+
}
|
|
358
|
+
export function getNormalizedAbsolutePath(fileName, currentDirectory) {
|
|
359
|
+
return getPathFromPathComponents(getNormalizedPathComponents(fileName, currentDirectory));
|
|
360
|
+
}
|
|
361
|
+
export function normalizePath(path) {
|
|
362
|
+
path = normalizeSlashes(path);
|
|
363
|
+
const normalized = getPathFromPathComponents(reducePathComponents(getPathComponents(path)));
|
|
364
|
+
return normalized && hasTrailingDirectorySeparator(path) ? ensureTrailingDirectorySeparator(normalized) : normalized;
|
|
365
|
+
}
|
|
366
|
+
export function toPath(fileName, basePath, getCanonicalFileName) {
|
|
367
|
+
const nonCanonicalizedPath = isRootedDiskPath(fileName)
|
|
368
|
+
? normalizePath(fileName)
|
|
369
|
+
: getNormalizedAbsolutePath(fileName, basePath);
|
|
370
|
+
return getCanonicalFileName(nonCanonicalizedPath);
|
|
371
|
+
}
|
|
372
|
+
export function removeTrailingDirectorySeparator(path) {
|
|
373
|
+
if (hasTrailingDirectorySeparator(path)) {
|
|
374
|
+
return path.substr(0, path.length - 1);
|
|
375
|
+
}
|
|
376
|
+
return path;
|
|
377
|
+
}
|
|
378
|
+
export function ensureTrailingDirectorySeparator(path) {
|
|
379
|
+
if (!hasTrailingDirectorySeparator(path)) {
|
|
380
|
+
return path + directorySeparator;
|
|
381
|
+
}
|
|
382
|
+
return path;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Ensures a path is either absolute (prefixed with `/` or `c:`) or dot-relative (prefixed
|
|
386
|
+
* with `./` or `../`) so as not to be confused with an unprefixed module name.
|
|
387
|
+
*
|
|
388
|
+
* ```ts
|
|
389
|
+
* ensurePathIsNonModuleName("/path/to/file.ext") === "/path/to/file.ext"
|
|
390
|
+
* ensurePathIsNonModuleName("./path/to/file.ext") === "./path/to/file.ext"
|
|
391
|
+
* ensurePathIsNonModuleName("../path/to/file.ext") === "../path/to/file.ext"
|
|
392
|
+
* ensurePathIsNonModuleName("path/to/file.ext") === "./path/to/file.ext"
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
export function ensurePathIsNonModuleName(path) {
|
|
396
|
+
return !pathIsAbsolute(path) && !pathIsRelative(path) ? "./" + path : path;
|
|
397
|
+
}
|
|
398
|
+
//// Path Comparisons
|
|
399
|
+
// check path for these segments: '', '.'. '..'
|
|
400
|
+
const relativePathSegmentRegExp = /(^|\/)\.{0,2}($|\/)/;
|
|
401
|
+
function comparePathsWorker(a, b, componentComparer) {
|
|
402
|
+
if (a === b)
|
|
403
|
+
return 0 /* Comparison.EqualTo */;
|
|
404
|
+
if (a === undefined)
|
|
405
|
+
return -1 /* Comparison.LessThan */;
|
|
406
|
+
if (b === undefined)
|
|
407
|
+
return 1 /* Comparison.GreaterThan */;
|
|
408
|
+
// NOTE: Performance optimization - shortcut if the root segments differ as there would be no
|
|
409
|
+
// need to perform path reduction.
|
|
410
|
+
const aRoot = a.substring(0, getRootLength(a));
|
|
411
|
+
const bRoot = b.substring(0, getRootLength(b));
|
|
412
|
+
const result = compareStringsCaseInsensitive(aRoot, bRoot);
|
|
413
|
+
if (result !== 0 /* Comparison.EqualTo */) {
|
|
414
|
+
return result;
|
|
415
|
+
}
|
|
416
|
+
// NOTE: Performance optimization - shortcut if there are no relative path segments in
|
|
417
|
+
// the non-root portion of the path
|
|
418
|
+
const aRest = a.substring(aRoot.length);
|
|
419
|
+
const bRest = b.substring(bRoot.length);
|
|
420
|
+
if (!relativePathSegmentRegExp.test(aRest) && !relativePathSegmentRegExp.test(bRest)) {
|
|
421
|
+
return componentComparer(aRest, bRest);
|
|
422
|
+
}
|
|
423
|
+
// The path contains a relative path segment. Normalize the paths and perform a slower component
|
|
424
|
+
// by component comparison.
|
|
425
|
+
const aComponents = reducePathComponents(getPathComponents(a));
|
|
426
|
+
const bComponents = reducePathComponents(getPathComponents(b));
|
|
427
|
+
const sharedLength = Math.min(aComponents.length, bComponents.length);
|
|
428
|
+
for (let i = 1; i < sharedLength; i++) {
|
|
429
|
+
const result = componentComparer(aComponents[i], bComponents[i]);
|
|
430
|
+
if (result !== 0 /* Comparison.EqualTo */) {
|
|
431
|
+
return result;
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
return compareValues(aComponents.length, bComponents.length);
|
|
435
|
+
}
|
|
436
|
+
export function comparePaths(a, b, currentDirectory, ignoreCase) {
|
|
437
|
+
if (typeof currentDirectory === "string") {
|
|
438
|
+
a = combinePaths(currentDirectory, a);
|
|
439
|
+
b = combinePaths(currentDirectory, b);
|
|
440
|
+
}
|
|
441
|
+
else if (typeof currentDirectory === "boolean") {
|
|
442
|
+
ignoreCase = currentDirectory;
|
|
443
|
+
}
|
|
444
|
+
return comparePathsWorker(a, b, getStringComparer(ignoreCase));
|
|
445
|
+
}
|
|
446
|
+
//// Relative Paths
|
|
447
|
+
export function getPathComponentsRelativeTo(from, to, stringEqualityComparer, getCanonicalFileName) {
|
|
448
|
+
const fromComponents = reducePathComponents(getPathComponents(from));
|
|
449
|
+
const toComponents = reducePathComponents(getPathComponents(to));
|
|
450
|
+
let start;
|
|
451
|
+
for (start = 0; start < fromComponents.length && start < toComponents.length; start++) {
|
|
452
|
+
const fromComponent = getCanonicalFileName(fromComponents[start]);
|
|
453
|
+
const toComponent = getCanonicalFileName(toComponents[start]);
|
|
454
|
+
const comparer = start === 0 ? equateStringsCaseInsensitive : stringEqualityComparer;
|
|
455
|
+
if (!comparer(fromComponent, toComponent))
|
|
456
|
+
break;
|
|
457
|
+
}
|
|
458
|
+
if (start === 0) {
|
|
459
|
+
return toComponents;
|
|
460
|
+
}
|
|
461
|
+
const components = toComponents.slice(start);
|
|
462
|
+
const relative = [];
|
|
463
|
+
for (; start < fromComponents.length; start++) {
|
|
464
|
+
relative.push("..");
|
|
465
|
+
}
|
|
466
|
+
return ["", ...relative, ...components];
|
|
467
|
+
}
|
|
468
|
+
export function getRelativePathFromDirectory(fromDirectory, to, getCanonicalFileNameOrIgnoreCase) {
|
|
469
|
+
Debug.assert((getRootLength(fromDirectory) > 0) === (getRootLength(to) > 0), "Paths must either both be absolute or both be relative");
|
|
470
|
+
const getCanonicalFileName = typeof getCanonicalFileNameOrIgnoreCase === "function" ? getCanonicalFileNameOrIgnoreCase : identity;
|
|
471
|
+
const ignoreCase = typeof getCanonicalFileNameOrIgnoreCase === "boolean" ? getCanonicalFileNameOrIgnoreCase : false;
|
|
472
|
+
const pathComponents = getPathComponentsRelativeTo(fromDirectory, to, ignoreCase ? equateStringsCaseInsensitive : equateStringsCaseSensitive, getCanonicalFileName);
|
|
473
|
+
return getPathFromPathComponents(pathComponents);
|
|
474
|
+
}
|
|
475
|
+
//// Path Traversal
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/compiler/perfLogger.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { noop, } from "./_namespaces/ts.js";
|
|
3
|
+
const nullLogger = {
|
|
4
|
+
logEvent: noop,
|
|
5
|
+
logErrEvent: noop,
|
|
6
|
+
logPerfEvent: noop,
|
|
7
|
+
logInfoEvent: noop,
|
|
8
|
+
logStartCommand: noop,
|
|
9
|
+
logStopCommand: noop,
|
|
10
|
+
logStartUpdateProgram: noop,
|
|
11
|
+
logStopUpdateProgram: noop,
|
|
12
|
+
logStartUpdateGraph: noop,
|
|
13
|
+
logStopUpdateGraph: noop,
|
|
14
|
+
logStartResolveModule: noop,
|
|
15
|
+
logStopResolveModule: noop,
|
|
16
|
+
logStartParseSourceFile: noop,
|
|
17
|
+
logStopParseSourceFile: noop,
|
|
18
|
+
logStartReadFile: noop,
|
|
19
|
+
logStopReadFile: noop,
|
|
20
|
+
logStartBindFile: noop,
|
|
21
|
+
logStopBindFile: noop,
|
|
22
|
+
logStartScheduledOperation: noop,
|
|
23
|
+
logStopScheduledOperation: noop,
|
|
24
|
+
};
|
|
25
|
+
// Load optional module to enable Event Tracing for Windows
|
|
26
|
+
// See https://github.com/microsoft/typescript-etw for more information
|
|
27
|
+
let etwModule;
|
|
28
|
+
try {
|
|
29
|
+
const etwModulePath = process.env.TS_ETW_MODULE_PATH ?? "./node_modules/@microsoft/typescript-etw";
|
|
30
|
+
// require() will throw an exception if the module is not found
|
|
31
|
+
// It may also return undefined if not installed properly
|
|
32
|
+
etwModule = require(etwModulePath);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
etwModule = undefined;
|
|
36
|
+
}
|
|
37
|
+
/** Performance logger that will generate ETW events if possible - check for `logEvent` member, as `etwModule` will be `{}` when browserified */
|
|
38
|
+
export const perfLogger = etwModule && etwModule.logEvent ? etwModule : nullLogger;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks a performance event.
|
|
3
|
+
*
|
|
4
|
+
* @param markName The name of the mark.
|
|
5
|
+
*/
|
|
6
|
+
export declare function mark(markName: string): void;
|
|
7
|
+
/**
|
|
8
|
+
* Adds a performance measurement with the specified name.
|
|
9
|
+
*
|
|
10
|
+
* @param measureName The name of the performance measurement.
|
|
11
|
+
* @param startMarkName The name of the starting mark. If not supplied, the point at which the
|
|
12
|
+
* profiler was enabled is used.
|
|
13
|
+
* @param endMarkName The name of the ending mark. If not supplied, the current timestamp is
|
|
14
|
+
* used.
|
|
15
|
+
*/
|
|
16
|
+
export declare function measure(measureName: string, startMarkName?: string, endMarkName?: string): void;
|
|
17
|
+
/** Enables (and resets) performance measurements for the compiler. */
|
|
18
|
+
export declare function enable(): void;
|
|
19
|
+
/** Disables performance measurements for the compiler. */
|
|
20
|
+
export declare function disable(): void;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/compiler/performance.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { createMap, timestamp, } from "./_namespaces/ts.js";
|
|
3
|
+
// NOTE: cannot use ts.noop as core.ts loads after this
|
|
4
|
+
const profilerEvent = typeof onProfilerEvent === "function" && onProfilerEvent.profiler === true ? onProfilerEvent : () => { };
|
|
5
|
+
let enabled = false;
|
|
6
|
+
let profilerStart = 0;
|
|
7
|
+
let counts;
|
|
8
|
+
let marks;
|
|
9
|
+
let measures;
|
|
10
|
+
/**
|
|
11
|
+
* Marks a performance event.
|
|
12
|
+
*
|
|
13
|
+
* @param markName The name of the mark.
|
|
14
|
+
*/
|
|
15
|
+
export function mark(markName) {
|
|
16
|
+
if (enabled) {
|
|
17
|
+
marks.set(markName, timestamp());
|
|
18
|
+
counts.set(markName, (counts.get(markName) || 0) + 1);
|
|
19
|
+
profilerEvent(markName);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Adds a performance measurement with the specified name.
|
|
24
|
+
*
|
|
25
|
+
* @param measureName The name of the performance measurement.
|
|
26
|
+
* @param startMarkName The name of the starting mark. If not supplied, the point at which the
|
|
27
|
+
* profiler was enabled is used.
|
|
28
|
+
* @param endMarkName The name of the ending mark. If not supplied, the current timestamp is
|
|
29
|
+
* used.
|
|
30
|
+
*/
|
|
31
|
+
export function measure(measureName, startMarkName, endMarkName) {
|
|
32
|
+
if (enabled) {
|
|
33
|
+
const end = endMarkName && marks.get(endMarkName) || timestamp();
|
|
34
|
+
const start = startMarkName && marks.get(startMarkName) || profilerStart;
|
|
35
|
+
measures.set(measureName, (measures.get(measureName) || 0) + (end - start));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Enables (and resets) performance measurements for the compiler. */
|
|
39
|
+
export function enable() {
|
|
40
|
+
counts = createMap();
|
|
41
|
+
marks = createMap();
|
|
42
|
+
measures = createMap();
|
|
43
|
+
enabled = true;
|
|
44
|
+
profilerStart = timestamp();
|
|
45
|
+
}
|
|
46
|
+
/** Disables performance measurements for the compiler. */
|
|
47
|
+
export function disable() {
|
|
48
|
+
enabled = false;
|
|
49
|
+
}
|