@flamework-experimental/transformer 2.0.0-alpha.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.
Files changed (72) hide show
  1. package/README.md +66 -0
  2. package/flamework-schema.json +76 -0
  3. package/flamework.config.schema.json +197 -0
  4. package/out/classes/buildInfo.js +467 -0
  5. package/out/classes/diagnostics.js +110 -0
  6. package/out/classes/logger.js +201 -0
  7. package/out/classes/nodeMetadata.js +232 -0
  8. package/out/classes/transformState.js +623 -0
  9. package/out/index.js +75 -0
  10. package/out/transformations/expressions/transformAccessExpression.js +35 -0
  11. package/out/transformations/expressions/transformBinaryExpression.js +57 -0
  12. package/out/transformations/expressions/transformCallExpression.js +33 -0
  13. package/out/transformations/expressions/transformDeleteExpression.js +22 -0
  14. package/out/transformations/expressions/transformNewExpression.js +17 -0
  15. package/out/transformations/expressions/transformUnaryExpression.js +63 -0
  16. package/out/transformations/macros/intrinsics/components.js +64 -0
  17. package/out/transformations/macros/intrinsics/env.js +31 -0
  18. package/out/transformations/macros/intrinsics/guards.js +43 -0
  19. package/out/transformations/macros/intrinsics/inlining.js +22 -0
  20. package/out/transformations/macros/intrinsics/networking.js +131 -0
  21. package/out/transformations/macros/intrinsics/parameters.js +81 -0
  22. package/out/transformations/macros/intrinsics/paths.js +42 -0
  23. package/out/transformations/macros/updateComponentConfig.js +409 -0
  24. package/out/transformations/plugins/nodeFactory.js +159 -0
  25. package/out/transformations/plugins/pluginHost.js +235 -0
  26. package/out/transformations/plugins/typeFacade.js +242 -0
  27. package/out/transformations/statements/transformClassDeclaration.js +282 -0
  28. package/out/transformations/transformExpression.js +34 -0
  29. package/out/transformations/transformFile.js +78 -0
  30. package/out/transformations/transformNetworkingCall.js +566 -0
  31. package/out/transformations/transformNode.js +27 -0
  32. package/out/transformations/transformStatement.js +57 -0
  33. package/out/transformations/transformStatementList.js +64 -0
  34. package/out/transformations/transformUserMacro.js +698 -0
  35. package/out/transformer.js +52 -0
  36. package/out/util/cache.js +10 -0
  37. package/out/util/constants.js +5 -0
  38. package/out/util/diagnosticsUtils.js +112 -0
  39. package/out/util/env.js +267 -0
  40. package/out/util/factory.js +583 -0
  41. package/out/util/functions/addLeadingComment.js +13 -0
  42. package/out/util/functions/arePathsEqual.js +14 -0
  43. package/out/util/functions/assert.js +17 -0
  44. package/out/util/functions/buildGuardFromType.js +713 -0
  45. package/out/util/functions/buildInstanceShape.js +156 -0
  46. package/out/util/functions/buildSerializerFromType.js +2309 -0
  47. package/out/util/functions/createPathTranslator.js +54 -0
  48. package/out/util/functions/emitTypescriptMismatch.js +80 -0
  49. package/out/util/functions/getDeclarationName.js +23 -0
  50. package/out/util/functions/getDeclarationOfType.js +7 -0
  51. package/out/util/functions/getIndexExpression.js +16 -0
  52. package/out/util/functions/getInstanceTypeFromType.js +75 -0
  53. package/out/util/functions/getNodeList.js +6 -0
  54. package/out/util/functions/getPackageJson.js +44 -0
  55. package/out/util/functions/getSuperClasses.js +51 -0
  56. package/out/util/functions/isAttributesAccess.js +23 -0
  57. package/out/util/functions/isCleanBuildDirectory.js +13 -0
  58. package/out/util/functions/isDefinedType.js +16 -0
  59. package/out/util/functions/isPathDescendantOf.js +25 -0
  60. package/out/util/functions/isTupleType.js +10 -0
  61. package/out/util/functions/parseCommandLine.js +31 -0
  62. package/out/util/functions/shuffle.js +39 -0
  63. package/out/util/functions/tryResolve.js +15 -0
  64. package/out/util/functions/validateConstraintMetadata.js +60 -0
  65. package/out/util/packages.js +12 -0
  66. package/out/util/projectConfig.js +221 -0
  67. package/out/util/schema.js +80 -0
  68. package/out/util/tsInternals.js +16 -0
  69. package/out/util/uid.js +227 -0
  70. package/package.json +45 -0
  71. package/rojo-schema.json +34 -0
  72. package/types.d.ts +4 -0
@@ -0,0 +1,467 @@
1
+ "use strict";
2
+ var __values = (this && this.__values) || function(o) {
3
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
+ if (m) return m.call(o);
5
+ if (o && typeof o.length === "number") return {
6
+ next: function () {
7
+ if (o && i >= o.length) o = void 0;
8
+ return { value: o && o[i++], done: !o };
9
+ }
10
+ };
11
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
29
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
30
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
31
+ if (ar || !(i in from)) {
32
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
33
+ ar[i] = from[i];
34
+ }
35
+ }
36
+ return to.concat(ar || Array.prototype.slice.call(from));
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.BuildInfo = void 0;
43
+ var typescript_1 = __importDefault(require("typescript"));
44
+ var path_1 = __importDefault(require("path"));
45
+ var fs_1 = __importDefault(require("fs"));
46
+ var crypto_1 = __importDefault(require("crypto"));
47
+ var uuid_1 = require("uuid");
48
+ var isPathDescendantOf_1 = require("../util/functions/isPathDescendantOf");
49
+ var schema_1 = require("../util/schema");
50
+ var constants_1 = require("../util/constants");
51
+ var BuildInfo = /** @class */ (function () {
52
+ function BuildInfo(buildInfoPath, buildInfo) {
53
+ var e_1, _a;
54
+ this.buildInfoPath = buildInfoPath;
55
+ this.buildInfos = [];
56
+ this.identifiersLookup = new Map();
57
+ this.buildInfo = buildInfo !== null && buildInfo !== void 0 ? buildInfo : {
58
+ version: 1,
59
+ flameworkVersion: constants_1.PKG_VERSION,
60
+ identifiers: {},
61
+ };
62
+ if (buildInfo) {
63
+ try {
64
+ for (var _b = __values(Object.entries(buildInfo.identifiers)), _c = _b.next(); !_c.done; _c = _b.next()) {
65
+ var _d = __read(_c.value, 2), internalId = _d[0], id = _d[1];
66
+ this.identifiersLookup.set(id, internalId);
67
+ }
68
+ }
69
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
70
+ finally {
71
+ try {
72
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
73
+ }
74
+ finally { if (e_1) throw e_1.error; }
75
+ }
76
+ }
77
+ }
78
+ BuildInfo.fromPath = function (fileName) {
79
+ if (!typescript_1.default.sys.fileExists(fileName))
80
+ return new BuildInfo(fileName);
81
+ var fileContents = typescript_1.default.sys.readFile(fileName);
82
+ if (!fileContents)
83
+ throw new Error("Could not read file ".concat(fileName));
84
+ var buildInfo = JSON.parse(fileContents);
85
+ if ((0, schema_1.validateSchema)("buildInfo", buildInfo)) {
86
+ return new BuildInfo(fileName, buildInfo);
87
+ }
88
+ throw new Error("Found invalid build info at ".concat(fileName));
89
+ };
90
+ BuildInfo.fromDirectory = function (directory) {
91
+ var buildInfoPath = path_1.default.join(directory, "flamework.build");
92
+ if (typescript_1.default.sys.fileExists(buildInfoPath)) {
93
+ return this.fromPath(buildInfoPath);
94
+ }
95
+ var packageJsonPath = typescript_1.default.findPackageJson(directory, typescript_1.default.sys);
96
+ if (packageJsonPath) {
97
+ var buildInfoPath_1 = path_1.default.join(path_1.default.dirname(packageJsonPath), "flamework.build");
98
+ if (buildInfoPath_1 && typescript_1.default.sys.fileExists(buildInfoPath_1)) {
99
+ return this.fromPath(buildInfoPath_1);
100
+ }
101
+ }
102
+ };
103
+ BuildInfo.findCandidateUpper = function (startDirectory, depth) {
104
+ if (depth === void 0) { depth = 4; }
105
+ var cache = this.candidateCache.get(startDirectory);
106
+ if (cache && cache.result) {
107
+ return cache.result;
108
+ }
109
+ var buildPath = path_1.default.join(startDirectory, "flamework.build");
110
+ if (!cache && fs_1.default.existsSync(buildPath)) {
111
+ this.candidateCache.set(startDirectory, { result: buildPath });
112
+ return buildPath;
113
+ }
114
+ else {
115
+ this.candidateCache.set(startDirectory, {});
116
+ }
117
+ if (depth > 0) {
118
+ return this.findCandidateUpper(path_1.default.dirname(startDirectory), depth - 1);
119
+ }
120
+ };
121
+ BuildInfo.findCandidates = function (searchPath, depth, isNodeModules) {
122
+ var e_2, _a;
123
+ if (depth === void 0) { depth = 2; }
124
+ if (isNodeModules === void 0) { isNodeModules = true; }
125
+ var candidates = [];
126
+ try {
127
+ for (var _b = __values(fs_1.default.readdirSync(searchPath)), _c = _b.next(); !_c.done; _c = _b.next()) {
128
+ var childPath = _c.value;
129
+ // only search @* (@rbxts, @flamework-experimental, @custom, etc)
130
+ if (!isNodeModules || childPath.startsWith("@")) {
131
+ var fullPath = path_1.default.join(searchPath, childPath);
132
+ var realPath = fs_1.default.realpathSync(fullPath);
133
+ if (fs_1.default.lstatSync(realPath).isDirectory() && depth !== 0) {
134
+ candidates.push.apply(candidates, __spreadArray([], __read(BuildInfo.findCandidates(fullPath, depth - 1, childPath === "node_modules")), false));
135
+ }
136
+ else {
137
+ if (childPath === "flamework.build") {
138
+ candidates.push(fullPath);
139
+ }
140
+ }
141
+ }
142
+ }
143
+ }
144
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
145
+ finally {
146
+ try {
147
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
148
+ }
149
+ finally { if (e_2) throw e_2.error; }
150
+ }
151
+ return candidates;
152
+ };
153
+ /**
154
+ * Saves the build info to a file.
155
+ */
156
+ BuildInfo.prototype.save = function () {
157
+ fs_1.default.writeFileSync(this.buildInfoPath, JSON.stringify(this.buildInfo, undefined, "\t"));
158
+ };
159
+ /**
160
+ * Retrieves the salt previously used to generate identifiers, or creates one.
161
+ */
162
+ BuildInfo.prototype.getSalt = function () {
163
+ if (this.buildInfo.salt)
164
+ return this.buildInfo.salt;
165
+ var salt = crypto_1.default.randomBytes(64).toString("hex");
166
+ this.buildInfo.salt = salt;
167
+ return salt;
168
+ };
169
+ /**
170
+ * A random seed that lives as long as this build info does: made when the build info is
171
+ * created, kept while it is reused. A plain build recreates the build info and so gets a new
172
+ * seed; a watcher reuses it across rebuilds and keeps the same one. Under obfuscation the
173
+ * callsite uuids -- the names of every remote -- are derived from it, so that they change with
174
+ * every build and cannot be mapped once and reused against the next release.
175
+ */
176
+ BuildInfo.prototype.getBuildSeed = function () {
177
+ if (this.buildInfo.buildSeed)
178
+ return this.buildInfo.buildSeed;
179
+ var seed = (0, uuid_1.v4)();
180
+ this.buildInfo.buildSeed = seed;
181
+ return seed;
182
+ };
183
+ /**
184
+ * Retrieves the version of flamework that this project was originally compiled on.
185
+ */
186
+ BuildInfo.prototype.getFlameworkVersion = function () {
187
+ return this.buildInfo.flameworkVersion;
188
+ };
189
+ /**
190
+ * Register a build info from an external source, normally packages.
191
+ * @param buildInfo The BuildInfo to add
192
+ */
193
+ BuildInfo.prototype.addBuildInfo = function (buildInfo) {
194
+ this.buildInfos.push(buildInfo);
195
+ };
196
+ /**
197
+ * Register a new identifier to be saved with the build info.
198
+ * @param internalId The internal, reproducible ID
199
+ * @param id The random or incremental ID
200
+ */
201
+ BuildInfo.prototype.addIdentifier = function (internalId, id) {
202
+ var identifier = this.getIdentifierFromInternal(internalId);
203
+ if (identifier)
204
+ throw new Error("Attempt to rewrite identifier ".concat(internalId, " -> ").concat(id, " (from ").concat(identifier, ")"));
205
+ this.buildInfo.identifiers[internalId] = id;
206
+ this.identifiersLookup.set(id, internalId);
207
+ };
208
+ BuildInfo.prototype.getBuildInfoFromFile = function (fileName) {
209
+ var e_3, _a;
210
+ try {
211
+ for (var _b = __values(this.buildInfos), _c = _b.next(); !_c.done; _c = _b.next()) {
212
+ var build = _c.value;
213
+ if ((0, isPathDescendantOf_1.isPathDescendantOf)(fileName, path_1.default.dirname(build.buildInfoPath))) {
214
+ return build;
215
+ }
216
+ }
217
+ }
218
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
219
+ finally {
220
+ try {
221
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
222
+ }
223
+ finally { if (e_3) throw e_3.error; }
224
+ }
225
+ };
226
+ /**
227
+ * Sets metadata which will be exposed at runtime.
228
+ */
229
+ BuildInfo.prototype.setMetadata = function (key, value) {
230
+ var _a;
231
+ var _b;
232
+ (_a = (_b = this.buildInfo).metadata) !== null && _a !== void 0 ? _a : (_b.metadata = {});
233
+ this.buildInfo.metadata[key] = value;
234
+ };
235
+ /**
236
+ * Gets metadata exposed at runtime.
237
+ */
238
+ BuildInfo.prototype.getMetadata = function (key) {
239
+ var _a;
240
+ return (_a = this.buildInfo.metadata) === null || _a === void 0 ? void 0 : _a[key];
241
+ };
242
+ /**
243
+ * Retrieves all metadata of this build info and its children.
244
+ */
245
+ BuildInfo.prototype.getChildrenMetadata = function (name) {
246
+ var e_4, _a, e_5, _b;
247
+ var childrenMetadata = new Map();
248
+ try {
249
+ for (var _c = __values(this.buildInfos), _d = _c.next(); !_d.done; _d = _c.next()) {
250
+ var build = _d.value;
251
+ var key = build.getIdentifierPrefix();
252
+ var metadata = build.getMetadata(name);
253
+ if (!key)
254
+ continue;
255
+ if (!metadata)
256
+ continue;
257
+ childrenMetadata.set(key, metadata);
258
+ try {
259
+ for (var _e = (e_5 = void 0, __values(build.getChildrenMetadata(name))), _f = _e.next(); !_f.done; _f = _e.next()) {
260
+ var _g = __read(_f.value, 2), key_1 = _g[0], metadata_1 = _g[1];
261
+ childrenMetadata.set(key_1, metadata_1);
262
+ }
263
+ }
264
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
265
+ finally {
266
+ try {
267
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
268
+ }
269
+ finally { if (e_5) throw e_5.error; }
270
+ }
271
+ }
272
+ }
273
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
274
+ finally {
275
+ try {
276
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
277
+ }
278
+ finally { if (e_4) throw e_4.error; }
279
+ }
280
+ return childrenMetadata;
281
+ };
282
+ BuildInfo.prototype.getBuildInfoFromPrefix = function (prefix) {
283
+ var e_6, _a;
284
+ try {
285
+ for (var _b = __values(this.buildInfos), _c = _b.next(); !_c.done; _c = _b.next()) {
286
+ var build = _c.value;
287
+ if (build.getIdentifierPrefix() === prefix) {
288
+ return build;
289
+ }
290
+ var child = build.getBuildInfoFromPrefix(prefix);
291
+ if (child) {
292
+ return child;
293
+ }
294
+ }
295
+ }
296
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
297
+ finally {
298
+ try {
299
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
300
+ }
301
+ finally { if (e_6) throw e_6.error; }
302
+ }
303
+ };
304
+ /**
305
+ * Adds a glob that will automatically be tracked between compiles.
306
+ */
307
+ BuildInfo.prototype.addGlob = function (glob, origin) {
308
+ var _a, _b, _c, _d, _e;
309
+ var _f, _g, _h, _j, _k;
310
+ (_a = (_f = this.buildInfo).metadata) !== null && _a !== void 0 ? _a : (_f.metadata = {});
311
+ (_b = (_g = this.buildInfo.metadata).globs) !== null && _b !== void 0 ? _b : (_g.globs = {});
312
+ (_c = (_h = this.buildInfo.metadata.globs).paths) !== null && _c !== void 0 ? _c : (_h.paths = {});
313
+ (_d = (_j = this.buildInfo.metadata.globs).origins) !== null && _d !== void 0 ? _d : (_j.origins = {});
314
+ this.buildInfo.metadata.globs.paths[glob] = [];
315
+ (_e = (_k = this.buildInfo.metadata.globs.origins)[origin]) !== null && _e !== void 0 ? _e : (_k[origin] = []);
316
+ this.buildInfo.metadata.globs.origins[origin].push(glob);
317
+ };
318
+ /**
319
+ * Removes all globs related to this file.
320
+ */
321
+ BuildInfo.prototype.invalidateGlobs = function (origin) {
322
+ var e_7, _a, e_8, _b;
323
+ var _c;
324
+ var globs = (_c = this.buildInfo.metadata) === null || _c === void 0 ? void 0 : _c.globs;
325
+ if (globs && globs.paths && globs.origins) {
326
+ delete globs.origins[origin];
327
+ try {
328
+ outer: for (var _d = __values(Object.keys(globs.paths)), _e = _d.next(); !_e.done; _e = _d.next()) {
329
+ var path_2 = _e.value;
330
+ try {
331
+ for (var _f = (e_8 = void 0, __values(Object.values(globs.origins))), _g = _f.next(); !_g.done; _g = _f.next()) {
332
+ var origin_1 = _g.value;
333
+ if (origin_1.includes(path_2)) {
334
+ continue outer;
335
+ }
336
+ }
337
+ }
338
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
339
+ finally {
340
+ try {
341
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
342
+ }
343
+ finally { if (e_8) throw e_8.error; }
344
+ }
345
+ delete globs.paths[path_2];
346
+ }
347
+ }
348
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
349
+ finally {
350
+ try {
351
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
352
+ }
353
+ finally { if (e_7) throw e_7.error; }
354
+ }
355
+ }
356
+ };
357
+ /**
358
+ * Get the random or incremental Id from the internalId.
359
+ * @param internalId The internal, reproducible ID
360
+ */
361
+ BuildInfo.prototype.getIdentifierFromInternal = function (internalId) {
362
+ var e_9, _a;
363
+ var id = this.buildInfo.identifiers[internalId];
364
+ if (id)
365
+ return id;
366
+ try {
367
+ for (var _b = __values(this.buildInfos), _c = _b.next(); !_c.done; _c = _b.next()) {
368
+ var build = _c.value;
369
+ var subId = build.getIdentifierFromInternal(internalId);
370
+ if (subId)
371
+ return subId;
372
+ }
373
+ }
374
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
375
+ finally {
376
+ try {
377
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
378
+ }
379
+ finally { if (e_9) throw e_9.error; }
380
+ }
381
+ };
382
+ /**
383
+ * Get the internal, reproducible Id from a random Id.
384
+ * @param id The random or incremental Id
385
+ */
386
+ BuildInfo.prototype.getInternalFromIdentifier = function (id) {
387
+ var e_10, _a;
388
+ var internalId = this.identifiersLookup.get(id);
389
+ if (internalId)
390
+ return internalId;
391
+ try {
392
+ for (var _b = __values(this.buildInfos), _c = _b.next(); !_c.done; _c = _b.next()) {
393
+ var build = _c.value;
394
+ var subId = build.getIdentifierFromInternal(id);
395
+ if (subId)
396
+ return subId;
397
+ }
398
+ }
399
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
400
+ finally {
401
+ try {
402
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
403
+ }
404
+ finally { if (e_10) throw e_10.error; }
405
+ }
406
+ };
407
+ /**
408
+ * Returns the next Id for incremental generation.
409
+ */
410
+ BuildInfo.prototype.getLatestId = function () {
411
+ return Object.keys(this.buildInfo.identifiers).length + 1;
412
+ };
413
+ /**
414
+ * Create a UUID, subsequent calls with the same string will have the same UUID.
415
+ * @param str The string to hash
416
+ */
417
+ BuildInfo.prototype.hashString = function (str, context) {
418
+ if (context === void 0) { context = "@"; }
419
+ str = "".concat(context, ":").concat(str);
420
+ var stringHashes = this.buildInfo.stringHashes;
421
+ if (!stringHashes)
422
+ this.buildInfo.stringHashes = stringHashes = {};
423
+ if (stringHashes[str])
424
+ return stringHashes[str];
425
+ var strUuid = (0, uuid_1.v4)();
426
+ stringHashes[str] = strUuid;
427
+ return strUuid;
428
+ };
429
+ /**
430
+ * Sets the prefix used for identifiers.
431
+ * Used to generate IDs for packages.
432
+ */
433
+ BuildInfo.prototype.setIdentifierPrefix = function (prefix) {
434
+ this.buildInfo.identifierPrefix = prefix;
435
+ };
436
+ /**
437
+ * Gets the prefixed used for identifiers.
438
+ */
439
+ BuildInfo.prototype.getIdentifierPrefix = function () {
440
+ return this.buildInfo.identifierPrefix;
441
+ };
442
+ /**
443
+ * Records the mode identifiers are generated in. An identifier, once generated, is answered from
444
+ * the table without looking at the mode again, so a build info written in another mode would
445
+ * hand out a mix. When the mode differs from the recorded one the table is dropped and every id
446
+ * is generated afresh; the previous mode is returned so that the caller can say so.
447
+ *
448
+ * A build info from before the mode was recorded keeps its table: there is no telling what
449
+ * mode it was made in, and dropping ids without cause is worse than keeping them.
450
+ */
451
+ BuildInfo.prototype.setIdGenerationMode = function (mode) {
452
+ var previous = this.buildInfo.idGenerationMode;
453
+ this.buildInfo.idGenerationMode = mode;
454
+ if (previous !== undefined && previous !== mode) {
455
+ this.buildInfo.identifiers = {};
456
+ this.identifiersLookup.clear();
457
+ return previous;
458
+ }
459
+ };
460
+ /** The mode the identifiers in the table were generated in, if it was recorded. */
461
+ BuildInfo.prototype.getIdGenerationMode = function () {
462
+ return this.buildInfo.idGenerationMode;
463
+ };
464
+ BuildInfo.candidateCache = new Map();
465
+ return BuildInfo;
466
+ }());
467
+ exports.BuildInfo = BuildInfo;
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __read = (this && this.__read) || function (o, n) {
18
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
19
+ if (!m) return o;
20
+ var i = m.call(o), r, ar = [], e;
21
+ try {
22
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
23
+ }
24
+ catch (error) { e = { error: error }; }
25
+ finally {
26
+ try {
27
+ if (r && !r.done && (m = i["return"])) m.call(i);
28
+ }
29
+ finally { if (e) throw e.error; }
30
+ }
31
+ return ar;
32
+ };
33
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
34
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
35
+ if (ar || !(i in from)) {
36
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
37
+ ar[i] = from[i];
38
+ }
39
+ }
40
+ return to.concat(ar || Array.prototype.slice.call(from));
41
+ };
42
+ var __importDefault = (this && this.__importDefault) || function (mod) {
43
+ return (mod && mod.__esModule) ? mod : { "default": mod };
44
+ };
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.Diagnostics = exports.DiagnosticError = void 0;
47
+ var typescript_1 = __importDefault(require("typescript"));
48
+ function createDiagnosticAtLocation(node, messageText, category, file) {
49
+ if (file === void 0) { file = typescript_1.default.getSourceFileOfNode(node); }
50
+ return {
51
+ category: category,
52
+ file: file,
53
+ messageText: messageText,
54
+ start: node.getStart(),
55
+ length: node.getWidth(),
56
+ code: " @flamework-experimental/core",
57
+ };
58
+ }
59
+ var DiagnosticError = /** @class */ (function (_super) {
60
+ __extends(DiagnosticError, _super);
61
+ function DiagnosticError(diagnostic) {
62
+ var _this = _super.call(this, diagnostic.messageText) || this;
63
+ _this.diagnostic = diagnostic;
64
+ return _this;
65
+ }
66
+ return DiagnosticError;
67
+ }(Error));
68
+ exports.DiagnosticError = DiagnosticError;
69
+ var Diagnostics = /** @class */ (function () {
70
+ function Diagnostics() {
71
+ }
72
+ Diagnostics.addDiagnostic = function (diag) {
73
+ this.diagnostics.push(diag);
74
+ };
75
+ Diagnostics.createDiagnostic = function (node, category) {
76
+ var messages = [];
77
+ for (var _i = 2; _i < arguments.length; _i++) {
78
+ messages[_i - 2] = arguments[_i];
79
+ }
80
+ return createDiagnosticAtLocation(node, messages.join("\n"), category);
81
+ };
82
+ Diagnostics.relocate = function (diagnostic, node) {
83
+ diagnostic.file = typescript_1.default.getSourceFileOfNode(node);
84
+ diagnostic.start = node.getStart();
85
+ diagnostic.length = node.getWidth();
86
+ throw new DiagnosticError(diagnostic);
87
+ };
88
+ Diagnostics.error = function (node) {
89
+ var messages = [];
90
+ for (var _i = 1; _i < arguments.length; _i++) {
91
+ messages[_i - 1] = arguments[_i];
92
+ }
93
+ throw new DiagnosticError(this.createDiagnostic.apply(this, __spreadArray([node, typescript_1.default.DiagnosticCategory.Error], __read(messages), false)));
94
+ };
95
+ Diagnostics.warning = function (node) {
96
+ var messages = [];
97
+ for (var _i = 1; _i < arguments.length; _i++) {
98
+ messages[_i - 1] = arguments[_i];
99
+ }
100
+ this.addDiagnostic(this.createDiagnostic.apply(this, __spreadArray([node, typescript_1.default.DiagnosticCategory.Warning], __read(messages), false)));
101
+ };
102
+ Diagnostics.flush = function () {
103
+ var diagnostics = this.diagnostics;
104
+ this.diagnostics = [];
105
+ return diagnostics;
106
+ };
107
+ Diagnostics.diagnostics = new Array();
108
+ return Diagnostics;
109
+ }());
110
+ exports.Diagnostics = Diagnostics;