@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,156 @@
1
+ "use strict";
2
+ var __read = (this && this.__read) || function (o, n) {
3
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
4
+ if (!m) return o;
5
+ var i = m.call(o), r, ar = [], e;
6
+ try {
7
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
+ }
9
+ catch (error) { e = { error: error }; }
10
+ finally {
11
+ try {
12
+ if (r && !r.done && (m = i["return"])) m.call(i);
13
+ }
14
+ finally { if (e) throw e.error; }
15
+ }
16
+ return ar;
17
+ };
18
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
+ if (ar || !(i in from)) {
21
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
+ ar[i] = from[i];
23
+ }
24
+ }
25
+ return to.concat(ar || Array.prototype.slice.call(from));
26
+ };
27
+ var __values = (this && this.__values) || function(o) {
28
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
29
+ if (m) return m.call(o);
30
+ if (o && typeof o.length === "number") return {
31
+ next: function () {
32
+ if (o && i >= o.length) o = void 0;
33
+ return { value: o && o[i++], done: !o };
34
+ }
35
+ };
36
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.buildInstanceShape = buildInstanceShape;
40
+ var factory_1 = require("../factory");
41
+ var buildGuardFromType_1 = require("./buildGuardFromType");
42
+ var getInstanceTypeFromType_1 = require("./getInstanceTypeFromType");
43
+ /**
44
+ * The instance tree a type describes, as the data `@flamework-experimental/components` checks and
45
+ * watches: `{ isA = { "Model" }, children = { Root = { isA = { "BasePart" } } } }` for
46
+ * `Model & { Root: BasePart }`.
47
+ *
48
+ * `componentChildren` names the direct children that are typed as a component. Their own trees
49
+ * belong to that component -- its tracker checks and watches them -- so the shape stops at their
50
+ * class.
51
+ *
52
+ * Nothing when the type says more than classes and children -- a union whose members declare
53
+ * children of their own, a member that is not an instance -- and the caller falls back to a `t`
54
+ * guard, which can say anything but has to read the whole tree to say it.
55
+ */
56
+ function buildInstanceShape(state, node, type, componentChildren) {
57
+ var shape = readShape(state, node, type, false, true, componentChildren);
58
+ return shape === undefined ? undefined : emitShape(shape);
59
+ }
60
+ function readShape(state, node, type, allowOptional, descend, componentChildren) {
61
+ var e_1, _a, e_2, _b;
62
+ var _c;
63
+ var checker = state.typeChecker;
64
+ var members = [type];
65
+ var optional = false;
66
+ if (type.isUnion()) {
67
+ var _d = __read((0, buildGuardFromType_1.extractTypes)(checker, __spreadArray([], __read(type.types), false)), 2), isOptional = _d[0], types = _d[1];
68
+ if (isOptional && !allowOptional)
69
+ return undefined;
70
+ optional = isOptional;
71
+ members = types;
72
+ }
73
+ if (members.length === 0)
74
+ return undefined;
75
+ var file = state.getSourceFile(node);
76
+ var isA = new Array();
77
+ var children;
78
+ try {
79
+ for (var members_1 = __values(members), members_1_1 = members_1.next(); !members_1_1.done; members_1_1 = members_1.next()) {
80
+ var member = members_1_1.value;
81
+ if (!(0, buildGuardFromType_1.isInstanceType)(member))
82
+ return undefined;
83
+ var instanceType = (0, getInstanceTypeFromType_1.getInstanceTypeFromType)(file, member);
84
+ var className = (_c = instanceType.symbol) === null || _c === void 0 ? void 0 : _c.name;
85
+ if (className === undefined)
86
+ return undefined;
87
+ if (!isA.includes(className))
88
+ isA.push(className);
89
+ if (!descend)
90
+ continue;
91
+ var declared = new Map();
92
+ try {
93
+ for (var _e = (e_2 = void 0, __values(member.getProperties())), _f = _e.next(); !_f.done; _f = _e.next()) {
94
+ var property = _f.value;
95
+ if (instanceType.getProperty(property.name))
96
+ continue;
97
+ var propertyType = checker.getTypeOfPropertyOfType(member, property.name);
98
+ if (!propertyType)
99
+ return undefined;
100
+ var child = readShape(state, node, propertyType, true, !(componentChildren === null || componentChildren === void 0 ? void 0 : componentChildren.has(property.name)));
101
+ if (child === undefined)
102
+ return undefined;
103
+ declared.set(property.name, child);
104
+ }
105
+ }
106
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
107
+ finally {
108
+ try {
109
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
110
+ }
111
+ finally { if (e_2) throw e_2.error; }
112
+ }
113
+ if (declared.size > 0) {
114
+ // Which children go with which class is more than a shape says.
115
+ if (members.length > 1)
116
+ return undefined;
117
+ children = declared;
118
+ }
119
+ }
120
+ }
121
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
122
+ finally {
123
+ try {
124
+ if (members_1_1 && !members_1_1.done && (_a = members_1.return)) _a.call(members_1);
125
+ }
126
+ finally { if (e_1) throw e_1.error; }
127
+ }
128
+ return { isA: isA, children: children, optional: optional };
129
+ }
130
+ function emitShape(shape) {
131
+ var e_3, _a;
132
+ var properties = [
133
+ factory_1.f.propertyAssignmentDeclaration("isA", factory_1.f.array(shape.isA.map(function (name) { return factory_1.f.string(name); }), false)),
134
+ ];
135
+ if (shape.children !== undefined) {
136
+ var children = new Array();
137
+ try {
138
+ for (var _b = __values(shape.children), _c = _b.next(); !_c.done; _c = _b.next()) {
139
+ var _d = __read(_c.value, 2), name_1 = _d[0], child = _d[1];
140
+ children.push(factory_1.f.propertyAssignmentDeclaration(name_1, emitShape(child)));
141
+ }
142
+ }
143
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
144
+ finally {
145
+ try {
146
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
147
+ }
148
+ finally { if (e_3) throw e_3.error; }
149
+ }
150
+ properties.push(factory_1.f.propertyAssignmentDeclaration("children", factory_1.f.object(children, false)));
151
+ }
152
+ if (shape.optional) {
153
+ properties.push(factory_1.f.propertyAssignmentDeclaration("optional", true));
154
+ }
155
+ return factory_1.f.object(properties, false);
156
+ }