@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.
- package/README.md +66 -0
- package/flamework-schema.json +76 -0
- package/flamework.config.schema.json +197 -0
- package/out/classes/buildInfo.js +467 -0
- package/out/classes/diagnostics.js +110 -0
- package/out/classes/logger.js +201 -0
- package/out/classes/nodeMetadata.js +232 -0
- package/out/classes/transformState.js +623 -0
- package/out/index.js +75 -0
- package/out/transformations/expressions/transformAccessExpression.js +35 -0
- package/out/transformations/expressions/transformBinaryExpression.js +57 -0
- package/out/transformations/expressions/transformCallExpression.js +33 -0
- package/out/transformations/expressions/transformDeleteExpression.js +22 -0
- package/out/transformations/expressions/transformNewExpression.js +17 -0
- package/out/transformations/expressions/transformUnaryExpression.js +63 -0
- package/out/transformations/macros/intrinsics/components.js +64 -0
- package/out/transformations/macros/intrinsics/env.js +31 -0
- package/out/transformations/macros/intrinsics/guards.js +43 -0
- package/out/transformations/macros/intrinsics/inlining.js +22 -0
- package/out/transformations/macros/intrinsics/networking.js +131 -0
- package/out/transformations/macros/intrinsics/parameters.js +81 -0
- package/out/transformations/macros/intrinsics/paths.js +42 -0
- package/out/transformations/macros/updateComponentConfig.js +409 -0
- package/out/transformations/plugins/nodeFactory.js +159 -0
- package/out/transformations/plugins/pluginHost.js +235 -0
- package/out/transformations/plugins/typeFacade.js +242 -0
- package/out/transformations/statements/transformClassDeclaration.js +282 -0
- package/out/transformations/transformExpression.js +34 -0
- package/out/transformations/transformFile.js +78 -0
- package/out/transformations/transformNetworkingCall.js +566 -0
- package/out/transformations/transformNode.js +27 -0
- package/out/transformations/transformStatement.js +57 -0
- package/out/transformations/transformStatementList.js +64 -0
- package/out/transformations/transformUserMacro.js +698 -0
- package/out/transformer.js +52 -0
- package/out/util/cache.js +10 -0
- package/out/util/constants.js +5 -0
- package/out/util/diagnosticsUtils.js +112 -0
- package/out/util/env.js +267 -0
- package/out/util/factory.js +583 -0
- package/out/util/functions/addLeadingComment.js +13 -0
- package/out/util/functions/arePathsEqual.js +14 -0
- package/out/util/functions/assert.js +17 -0
- package/out/util/functions/buildGuardFromType.js +713 -0
- package/out/util/functions/buildInstanceShape.js +156 -0
- package/out/util/functions/buildSerializerFromType.js +2309 -0
- package/out/util/functions/createPathTranslator.js +54 -0
- package/out/util/functions/emitTypescriptMismatch.js +80 -0
- package/out/util/functions/getDeclarationName.js +23 -0
- package/out/util/functions/getDeclarationOfType.js +7 -0
- package/out/util/functions/getIndexExpression.js +16 -0
- package/out/util/functions/getInstanceTypeFromType.js +75 -0
- package/out/util/functions/getNodeList.js +6 -0
- package/out/util/functions/getPackageJson.js +44 -0
- package/out/util/functions/getSuperClasses.js +51 -0
- package/out/util/functions/isAttributesAccess.js +23 -0
- package/out/util/functions/isCleanBuildDirectory.js +13 -0
- package/out/util/functions/isDefinedType.js +16 -0
- package/out/util/functions/isPathDescendantOf.js +25 -0
- package/out/util/functions/isTupleType.js +10 -0
- package/out/util/functions/parseCommandLine.js +31 -0
- package/out/util/functions/shuffle.js +39 -0
- package/out/util/functions/tryResolve.js +15 -0
- package/out/util/functions/validateConstraintMetadata.js +60 -0
- package/out/util/packages.js +12 -0
- package/out/util/projectConfig.js +221 -0
- package/out/util/schema.js +80 -0
- package/out/util/tsInternals.js +16 -0
- package/out/util/uid.js +227 -0
- package/package.json +45 -0
- package/rojo-schema.json +34 -0
- package/types.d.ts +4 -0
|
@@ -0,0 +1,54 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.createPathTranslator = createPathTranslator;
|
|
32
|
+
var path_1 = __importDefault(require("path"));
|
|
33
|
+
var assert_1 = require("./assert");
|
|
34
|
+
var path_translator_1 = require("@roblox-ts/path-translator");
|
|
35
|
+
function findAncestorDir(dirs) {
|
|
36
|
+
dirs = dirs.map(path_1.default.normalize).map(function (v) { return (v.endsWith(path_1.default.sep) ? v : v + path_1.default.sep); });
|
|
37
|
+
var currentDir = dirs[0];
|
|
38
|
+
while (!dirs.every(function (v) { return v.startsWith(currentDir); })) {
|
|
39
|
+
currentDir = path_1.default.join(currentDir, "..");
|
|
40
|
+
}
|
|
41
|
+
return currentDir;
|
|
42
|
+
}
|
|
43
|
+
function getRootDirs(compilerOptions) {
|
|
44
|
+
var rootDirs = compilerOptions.rootDir ? [compilerOptions.rootDir] : compilerOptions.rootDirs;
|
|
45
|
+
if (!rootDirs)
|
|
46
|
+
(0, assert_1.assert)(false, "rootDir or rootDirs must be specified");
|
|
47
|
+
return rootDirs;
|
|
48
|
+
}
|
|
49
|
+
function createPathTranslator(program) {
|
|
50
|
+
var compilerOptions = program.getCompilerOptions();
|
|
51
|
+
var rootDir = findAncestorDir(__spreadArray([program.getCommonSourceDirectory()], __read(getRootDirs(compilerOptions)), false));
|
|
52
|
+
var outDir = compilerOptions.outDir;
|
|
53
|
+
return new path_translator_1.PathTranslator(rootDir, outDir, undefined, compilerOptions.declaration || false);
|
|
54
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.emitTypescriptMismatch = emitTypescriptMismatch;
|
|
32
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
33
|
+
var path_1 = __importDefault(require("path"));
|
|
34
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
35
|
+
var logger_1 = require("../../classes/logger");
|
|
36
|
+
var getPackageJson_1 = require("./getPackageJson");
|
|
37
|
+
var isPathDescendantOf_1 = require("./isPathDescendantOf");
|
|
38
|
+
function tryResolve(name, path) {
|
|
39
|
+
try {
|
|
40
|
+
return require.resolve(name, { paths: [path] });
|
|
41
|
+
}
|
|
42
|
+
catch (e) { }
|
|
43
|
+
}
|
|
44
|
+
function emitMessages(messages) {
|
|
45
|
+
logger_1.Logger.writeLine.apply(logger_1.Logger, __spreadArray([], __read(messages), false));
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Spits out information about the mismatch.
|
|
50
|
+
* This should only be called after a mismatch is detected.
|
|
51
|
+
*/
|
|
52
|
+
function emitTypescriptMismatch(state, baseMessage) {
|
|
53
|
+
var messages = [baseMessage];
|
|
54
|
+
// Check if they have a local install.
|
|
55
|
+
var robloxTsPath = tryResolve("roblox-ts", state.rootDirectory);
|
|
56
|
+
if (!robloxTsPath) {
|
|
57
|
+
messages.push("It is recommended that you use a local install of roblox-ts.", "You can install a local version using ".concat(chalk_1.default.green("npm install -D roblox-ts")));
|
|
58
|
+
emitMessages(messages);
|
|
59
|
+
}
|
|
60
|
+
// Check if they've used a global install.
|
|
61
|
+
if (require.main) {
|
|
62
|
+
if (!(0, isPathDescendantOf_1.isPathDescendantOf)(require.main.filename, path_1.default.join(state.rootDirectory, "node_modules"))) {
|
|
63
|
+
messages.push("It appears you've run the transformer using a global install.", "You can run using the locally installed version using ".concat(chalk_1.default.green("npx rbxtsc")));
|
|
64
|
+
emitMessages(messages);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// They're using a local install
|
|
68
|
+
// but they're using the wrong TypeScript version.
|
|
69
|
+
var robloxTsTypeScript = tryResolve("typescript", robloxTsPath);
|
|
70
|
+
if (robloxTsTypeScript) {
|
|
71
|
+
var typescriptPackage = (0, getPackageJson_1.getPackageJson)(robloxTsTypeScript);
|
|
72
|
+
if (typescriptPackage) {
|
|
73
|
+
var requiredVersion = typescriptPackage.result.version;
|
|
74
|
+
if (typescript_1.default.version !== requiredVersion) {
|
|
75
|
+
messages.push("Flamework is using TypeScript version ".concat(typescript_1.default.version), "roblox-ts requires TypeScript version ".concat(requiredVersion), "You can fix this by setting your TypeScript version: ".concat(chalk_1.default.green("npm install -D typescript@=".concat(requiredVersion))));
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
emitMessages(messages);
|
|
80
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getDeclarationName = getDeclarationName;
|
|
7
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
var factory_1 = require("../factory");
|
|
9
|
+
/**
|
|
10
|
+
* Calculates a name, including all named ancestors, such as Enum.Material.Air
|
|
11
|
+
* @param node The node to retrieve the name of
|
|
12
|
+
*/
|
|
13
|
+
function getDeclarationName(node) {
|
|
14
|
+
if (!factory_1.f.is.identifier(node.name))
|
|
15
|
+
return "$p:error";
|
|
16
|
+
var name = node.name.text;
|
|
17
|
+
for (var parent_1 = node.parent; parent_1 !== undefined; parent_1 = parent_1.parent) {
|
|
18
|
+
if (typescript_1.default.isNamedDeclaration(parent_1)) {
|
|
19
|
+
name = parent_1.name.getText() + "." + name;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return name;
|
|
23
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDeclarationOfType = getDeclarationOfType;
|
|
4
|
+
function getDeclarationOfType(type) {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
return (_b = (_a = type.symbol) === null || _a === void 0 ? void 0 : _a.declarations) === null || _b === void 0 ? void 0 : _b[0];
|
|
7
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getIndexExpression = getIndexExpression;
|
|
4
|
+
var factory_1 = require("../factory");
|
|
5
|
+
/**
|
|
6
|
+
* Gets the expression used to index the AccessExpression.
|
|
7
|
+
* Converts properties to strings.
|
|
8
|
+
*/
|
|
9
|
+
function getIndexExpression(expression) {
|
|
10
|
+
if (factory_1.f.is.propertyAccessExpression(expression)) {
|
|
11
|
+
return factory_1.f.string(expression.name.text);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
return expression.argumentExpression;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.getInstanceTypeFromType = getInstanceTypeFromType;
|
|
18
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
19
|
+
var diagnostics_1 = require("../../classes/diagnostics");
|
|
20
|
+
var assert_1 = require("./assert");
|
|
21
|
+
var getDeclarationOfType_1 = require("./getDeclarationOfType");
|
|
22
|
+
function getInstanceTypeFromType(file, type) {
|
|
23
|
+
var e_1, _a, e_2, _b;
|
|
24
|
+
var _c, _d, _e;
|
|
25
|
+
(0, assert_1.assert)(type.getProperty("_nominal_Instance"), "non instance type was passed into getInstanceTypeFromType");
|
|
26
|
+
var diagnosticsLocation = (_c = (0, getDeclarationOfType_1.getDeclarationOfType)(type)) !== null && _c !== void 0 ? _c : file;
|
|
27
|
+
var nominalProperties = getNominalProperties(type);
|
|
28
|
+
var specificType = type, specificTypeCount = 0;
|
|
29
|
+
try {
|
|
30
|
+
for (var nominalProperties_1 = __values(nominalProperties), nominalProperties_1_1 = nominalProperties_1.next(); !nominalProperties_1_1.done; nominalProperties_1_1 = nominalProperties_1.next()) {
|
|
31
|
+
var property = nominalProperties_1_1.value;
|
|
32
|
+
var noNominalName = (_d = /_nominal_(.*)/.exec(property.name)) === null || _d === void 0 ? void 0 : _d[1];
|
|
33
|
+
(0, assert_1.assert)(noNominalName);
|
|
34
|
+
var instanceSymbol = type.checker.resolveName(noNominalName, undefined, typescript_1.default.SymbolFlags.Type, false);
|
|
35
|
+
if (!instanceSymbol)
|
|
36
|
+
continue;
|
|
37
|
+
var instanceDeclaration = (_e = instanceSymbol.declarations) === null || _e === void 0 ? void 0 : _e[0];
|
|
38
|
+
if (!instanceDeclaration)
|
|
39
|
+
continue;
|
|
40
|
+
var instanceType = type.checker.getTypeAtLocation(instanceDeclaration);
|
|
41
|
+
var subNominalProperties = getNominalProperties(instanceType);
|
|
42
|
+
if (subNominalProperties.length > specificTypeCount) {
|
|
43
|
+
specificType = instanceType;
|
|
44
|
+
specificTypeCount = subNominalProperties.length;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
49
|
+
finally {
|
|
50
|
+
try {
|
|
51
|
+
if (nominalProperties_1_1 && !nominalProperties_1_1.done && (_a = nominalProperties_1.return)) _a.call(nominalProperties_1);
|
|
52
|
+
}
|
|
53
|
+
finally { if (e_1) throw e_1.error; }
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
// intersection between two nominal types?
|
|
57
|
+
for (var nominalProperties_2 = __values(nominalProperties), nominalProperties_2_1 = nominalProperties_2.next(); !nominalProperties_2_1.done; nominalProperties_2_1 = nominalProperties_2.next()) {
|
|
58
|
+
var property = nominalProperties_2_1.value;
|
|
59
|
+
if (!specificType.getProperty(property.name)) {
|
|
60
|
+
diagnostics_1.Diagnostics.error(diagnosticsLocation, "Intersection between nominal types is forbidden.");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
65
|
+
finally {
|
|
66
|
+
try {
|
|
67
|
+
if (nominalProperties_2_1 && !nominalProperties_2_1.done && (_b = nominalProperties_2.return)) _b.call(nominalProperties_2);
|
|
68
|
+
}
|
|
69
|
+
finally { if (e_2) throw e_2.error; }
|
|
70
|
+
}
|
|
71
|
+
return specificType;
|
|
72
|
+
}
|
|
73
|
+
function getNominalProperties(type) {
|
|
74
|
+
return type.getProperties().filter(function (x) { return x.name.startsWith("_nominal_"); });
|
|
75
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getPackageJson = getPackageJson;
|
|
7
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
var path_1 = __importDefault(require("path"));
|
|
9
|
+
var normalize_package_data_1 = __importDefault(require("normalize-package-data"));
|
|
10
|
+
var isPathDescendantOf_1 = require("./isPathDescendantOf");
|
|
11
|
+
var cache_1 = require("../cache");
|
|
12
|
+
/**
|
|
13
|
+
* Looks recursively at ancestors until a package.json is found
|
|
14
|
+
* @param directory The directory to start under.
|
|
15
|
+
*/
|
|
16
|
+
function getPackageJson(directory) {
|
|
17
|
+
var existing = cache_1.Cache.pkgJsonCache.get(path_1.default.normalize(directory));
|
|
18
|
+
if (existing)
|
|
19
|
+
return existing;
|
|
20
|
+
var result = getPackageJsonInner(directory);
|
|
21
|
+
cache_1.Cache.pkgJsonCache.set(path_1.default.normalize(directory), result);
|
|
22
|
+
typescript_1.default.forEachAncestorDirectory(directory, function (dir) {
|
|
23
|
+
if ((0, isPathDescendantOf_1.isPathDescendantOf)(dir, result.directory)) {
|
|
24
|
+
cache_1.Cache.pkgJsonCache.set(path_1.default.normalize(dir), result);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
function getPackageJsonInner(directory) {
|
|
33
|
+
var packageJsonPath = typescript_1.default.findPackageJson(directory, typescript_1.default.sys);
|
|
34
|
+
if (!packageJsonPath)
|
|
35
|
+
throw new Error("package.json not found in ".concat(directory));
|
|
36
|
+
var text = packageJsonPath ? typescript_1.default.sys.readFile(packageJsonPath) : undefined;
|
|
37
|
+
var packageJson = text ? JSON.parse(text) : {};
|
|
38
|
+
(0, normalize_package_data_1.default)(packageJson);
|
|
39
|
+
return {
|
|
40
|
+
directory: path_1.default.dirname(packageJsonPath),
|
|
41
|
+
path: packageJsonPath,
|
|
42
|
+
result: packageJson,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
28
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.getSuperClasses = getSuperClasses;
|
|
32
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
33
|
+
function getSuperClasses(typeChecker, node) {
|
|
34
|
+
var _a, _b, _c, _d;
|
|
35
|
+
var superClasses = new Array();
|
|
36
|
+
var superClass = (_c = (_b = (_a = node.heritageClauses) === null || _a === void 0 ? void 0 : _a.find(function (x) { return x.token === typescript_1.default.SyntaxKind.ExtendsKeyword; })) === null || _b === void 0 ? void 0 : _b.types) === null || _c === void 0 ? void 0 : _c[0];
|
|
37
|
+
if (superClass) {
|
|
38
|
+
var aliasSymbol = typeChecker.getSymbolAtLocation(superClass.expression);
|
|
39
|
+
if (aliasSymbol) {
|
|
40
|
+
var symbol = typescript_1.default.skipAlias(aliasSymbol, typeChecker);
|
|
41
|
+
var classDeclaration = (_d = symbol === null || symbol === void 0 ? void 0 : symbol.declarations) === null || _d === void 0 ? void 0 : _d.find(function (x) {
|
|
42
|
+
return typescript_1.default.isClassDeclaration(x);
|
|
43
|
+
});
|
|
44
|
+
if (classDeclaration) {
|
|
45
|
+
superClasses.push(classDeclaration);
|
|
46
|
+
superClasses.push.apply(superClasses, __spreadArray([], __read(getSuperClasses(typeChecker, classDeclaration)), false));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return superClasses;
|
|
51
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isAttributesAccess = isAttributesAccess;
|
|
4
|
+
var factory_1 = require("../factory");
|
|
5
|
+
var nodeMetadata_1 = require("../../classes/nodeMetadata");
|
|
6
|
+
/**
|
|
7
|
+
* Checks if an expression is attempting to access component attributes.
|
|
8
|
+
* E.g `this.attributes.myProp`
|
|
9
|
+
*/
|
|
10
|
+
function isAttributesAccess(state, expression) {
|
|
11
|
+
if (!factory_1.f.is.accessExpression(expression)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
var lhs = state.getSymbol(expression.expression);
|
|
15
|
+
if (!lhs) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
var metadata = nodeMetadata_1.NodeMetadata.fromSymbol(state, lhs);
|
|
19
|
+
if (!metadata) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
return metadata.isRequested("intrinsic-component-attributes");
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isCleanBuildDirectory = isCleanBuildDirectory;
|
|
7
|
+
var fs_1 = __importDefault(require("fs"));
|
|
8
|
+
function isCleanBuildDirectory(compilerOptions) {
|
|
9
|
+
if (compilerOptions.incremental && compilerOptions.tsBuildInfoFile) {
|
|
10
|
+
return !fs_1.default.existsSync(compilerOptions.tsBuildInfoFile);
|
|
11
|
+
}
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isDefinedType = isDefinedType;
|
|
7
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
// https://github.com/roblox-ts/roblox-ts/blob/dc74f34fdab3caf20d65db080cf2dbf5c4f38fdc/src/TSTransformer/util/types.ts#L70
|
|
9
|
+
function isDefinedType(type) {
|
|
10
|
+
return (type.flags === typescript_1.default.TypeFlags.Object &&
|
|
11
|
+
type.getProperties().length === 0 &&
|
|
12
|
+
type.getCallSignatures().length === 0 &&
|
|
13
|
+
type.getConstructSignatures().length === 0 &&
|
|
14
|
+
type.getNumberIndexType() === undefined &&
|
|
15
|
+
type.getStringIndexType() === undefined);
|
|
16
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isPathDescendantOf = isPathDescendantOf;
|
|
7
|
+
exports.isPathDescendantOfAny = isPathDescendantOfAny;
|
|
8
|
+
var path_1 = __importDefault(require("path"));
|
|
9
|
+
/**
|
|
10
|
+
* Checks if the `filePath` path is a descendant of the `dirPath` path.
|
|
11
|
+
* @param filePath A path to a file.
|
|
12
|
+
* @param dirPath A path to a directory.
|
|
13
|
+
*/
|
|
14
|
+
function isPathDescendantOf(filePath, dirPath) {
|
|
15
|
+
var relative = path_1.default.relative(dirPath, filePath);
|
|
16
|
+
return dirPath === filePath || (!relative.startsWith("..") && !path_1.default.isAbsolute(relative));
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Checks if the `filePath` is a descendant of any of the specified `dirPaths` paths.
|
|
20
|
+
* @param filePath A path to a file.
|
|
21
|
+
* @param dirPaths The directories to check.
|
|
22
|
+
*/
|
|
23
|
+
function isPathDescendantOfAny(filePath, dirPaths) {
|
|
24
|
+
return dirPaths.some(function (dirPath) { return isPathDescendantOf(filePath, dirPath); });
|
|
25
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isTupleType = isTupleType;
|
|
4
|
+
exports.isArrayType = isArrayType;
|
|
5
|
+
function isTupleType(state, type) {
|
|
6
|
+
return state.typeChecker.isTupleType(type);
|
|
7
|
+
}
|
|
8
|
+
function isArrayType(state, type) {
|
|
9
|
+
return state.typeChecker.isArrayType(type);
|
|
10
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.parseCommandLine = parseCommandLine;
|
|
7
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
var path_1 = __importDefault(require("path"));
|
|
9
|
+
var fs_1 = __importDefault(require("fs"));
|
|
10
|
+
function findTsConfigPath(projectPath) {
|
|
11
|
+
var tsConfigPath = path_1.default.resolve(projectPath);
|
|
12
|
+
if (!fs_1.default.existsSync(tsConfigPath) || !fs_1.default.statSync(tsConfigPath).isFile()) {
|
|
13
|
+
tsConfigPath = typescript_1.default.findConfigFile(tsConfigPath, typescript_1.default.sys.fileExists);
|
|
14
|
+
if (tsConfigPath === undefined) {
|
|
15
|
+
throw new Error("Unable to find tsconfig.json!");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return path_1.default.resolve(process.cwd(), tsConfigPath);
|
|
19
|
+
}
|
|
20
|
+
function parseCommandLine() {
|
|
21
|
+
var options = {};
|
|
22
|
+
var projectIndex = process.argv.findIndex(function (x) { return x === "-p" || x === "--project"; });
|
|
23
|
+
if (projectIndex !== -1) {
|
|
24
|
+
options.tsconfigPath = findTsConfigPath(process.argv[projectIndex + 1]);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
options.tsconfigPath = findTsConfigPath(".");
|
|
28
|
+
}
|
|
29
|
+
options.project = path_1.default.dirname(options.tsconfigPath);
|
|
30
|
+
return options;
|
|
31
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.shuffle = shuffle;
|
|
29
|
+
function shuffle(array) {
|
|
30
|
+
return shuffleInPlace(__spreadArray([], __read(array), false));
|
|
31
|
+
}
|
|
32
|
+
function shuffleInPlace(array) {
|
|
33
|
+
var _a;
|
|
34
|
+
for (var i = array.length - 1; i >= 0; i--) {
|
|
35
|
+
var randomIndex = Math.floor(Math.random() * (i + 1));
|
|
36
|
+
_a = __read([array[randomIndex], array[i]], 2), array[i] = _a[0], array[randomIndex] = _a[1];
|
|
37
|
+
}
|
|
38
|
+
return array;
|
|
39
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.tryResolveTS = tryResolveTS;
|
|
7
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
8
|
+
/**
|
|
9
|
+
* Resolves a module the way the compiler would from `containingFile`, returning the file it lands on.
|
|
10
|
+
*/
|
|
11
|
+
function tryResolveTS(state, moduleName, containingFile) {
|
|
12
|
+
var _a;
|
|
13
|
+
var module = typescript_1.default.resolveModuleName(moduleName, containingFile, state.options, typescript_1.default.sys);
|
|
14
|
+
return (_a = module.resolvedModule) === null || _a === void 0 ? void 0 : _a.resolvedFileName;
|
|
15
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.validateConstraintMetadata = validateConstraintMetadata;
|
|
18
|
+
var typescript_1 = __importDefault(require("typescript"));
|
|
19
|
+
var nodeMetadata_1 = require("../../classes/nodeMetadata");
|
|
20
|
+
var assert_1 = require("./assert");
|
|
21
|
+
var diagnostics_1 = require("../../classes/diagnostics");
|
|
22
|
+
function validateConstraintMetadata(state, node, metadata) {
|
|
23
|
+
var e_1, _a;
|
|
24
|
+
var _b;
|
|
25
|
+
if (metadata === void 0) { metadata = nodeMetadata_1.NodeMetadata.fromCache(state, node); }
|
|
26
|
+
if (!node.name) {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
var symbol = state.getSymbol(node.name);
|
|
30
|
+
(0, assert_1.assert)(symbol);
|
|
31
|
+
var constraintTypes = metadata.getType("constraint");
|
|
32
|
+
var nodeType = state.typeChecker.getTypeOfSymbolAtLocation(symbol, node);
|
|
33
|
+
try {
|
|
34
|
+
for (var _c = __values(constraintTypes !== null && constraintTypes !== void 0 ? constraintTypes : []), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
35
|
+
var constraintType = _d.value;
|
|
36
|
+
if (!state.typeChecker.isTypeAssignableTo(nodeType, constraintType)) {
|
|
37
|
+
diagnostics_1.Diagnostics.addDiagnostic(getAssignabilityDiagnostics((_b = node.name) !== null && _b !== void 0 ? _b : node, nodeType, constraintType, metadata.getTrace(constraintType)));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
42
|
+
finally {
|
|
43
|
+
try {
|
|
44
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
45
|
+
}
|
|
46
|
+
finally { if (e_1) throw e_1.error; }
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function getAssignabilityDiagnostics(node, sourceType, constraintType, trace) {
|
|
50
|
+
var diagnostic = diagnostics_1.Diagnostics.createDiagnostic(node, typescript_1.default.DiagnosticCategory.Error, "Type '".concat(formatType(sourceType), "' does not satify constraint '").concat(formatType(constraintType), "'"));
|
|
51
|
+
if (trace) {
|
|
52
|
+
typescript_1.default.addRelatedInfo(diagnostic, diagnostics_1.Diagnostics.createDiagnostic(trace, typescript_1.default.DiagnosticCategory.Message, "The constraint is defined here."));
|
|
53
|
+
}
|
|
54
|
+
return diagnostic;
|
|
55
|
+
}
|
|
56
|
+
function formatType(type) {
|
|
57
|
+
var typeNode = type.checker.typeToTypeNode(type, undefined, typescript_1.default.NodeBuilderFlags.InTypeAlias | typescript_1.default.NodeBuilderFlags.IgnoreErrors);
|
|
58
|
+
var printer = typescript_1.default.createPrinter();
|
|
59
|
+
return printer.printNode(typescript_1.default.EmitHint.Unspecified, typeNode, undefined);
|
|
60
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PLUGIN_PACKAGE = exports.NETWORKING_PACKAGE = exports.COMPONENTS_PACKAGE = exports.CORE_PACKAGE = exports.FLAMEWORK_SCOPE = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* The npm scope every Flamework package is published under, and the package names the transformer
|
|
6
|
+
* emits imports for or resolves. Nothing else in the transformer spells the scope out.
|
|
7
|
+
*/
|
|
8
|
+
exports.FLAMEWORK_SCOPE = "@flamework-experimental";
|
|
9
|
+
exports.CORE_PACKAGE = "".concat(exports.FLAMEWORK_SCOPE, "/core");
|
|
10
|
+
exports.COMPONENTS_PACKAGE = "".concat(exports.FLAMEWORK_SCOPE, "/components");
|
|
11
|
+
exports.NETWORKING_PACKAGE = "".concat(exports.FLAMEWORK_SCOPE, "/networking");
|
|
12
|
+
exports.PLUGIN_PACKAGE = "".concat(exports.FLAMEWORK_SCOPE, "/transformer-plugin");
|