skittles 0.1.8 → 0.3.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/lib/abi/get-abi.d.ts +4 -0
- package/lib/abi/get-abi.js +67 -10
- package/lib/ast/get-ast.d.ts +3 -0
- package/lib/bytecode/get-bytecode.d.ts +2 -0
- package/lib/compiler/skittles-compiler.d.ts +2 -0
- package/lib/compiler/skittles-compiler.js +35 -0
- package/lib/data/constants.d.ts +1 -0
- package/lib/data/constants.js +4 -0
- package/lib/data/yul-template.d.ts +12 -0
- package/lib/data/yul-template.js +7 -0
- package/lib/dependencies/add-dependencies.d.ts +3 -0
- package/lib/dependencies/add-dependencies.js +29 -0
- package/lib/helpers/ast-helper.d.ts +13 -0
- package/lib/helpers/ast-helper.js +2 -1
- package/lib/helpers/console-helper.d.ts +1 -0
- package/lib/helpers/console-helper.js +33 -0
- package/lib/helpers/file-helper.d.ts +5 -0
- package/lib/helpers/file-helper.js +43 -8
- package/lib/helpers/selector-helper.d.ts +2 -0
- package/lib/helpers/string-helper.d.ts +2 -0
- package/lib/helpers/yul-helper.d.ts +3 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +17 -46
- package/lib/skittles-class/get-skittles-class.d.ts +3 -0
- package/lib/skittles-class/get-skittles-class.js +17 -4
- package/lib/skittles-class/get-skittles-constructor.d.ts +4 -0
- package/lib/skittles-class/get-skittles-constructor.js +3 -3
- package/lib/skittles-class/get-skittles-expression.d.ts +4 -0
- package/lib/skittles-class/get-skittles-expression.js +117 -56
- package/lib/skittles-class/get-skittles-interfaces.d.ts +4 -0
- package/lib/skittles-class/get-skittles-interfaces.js +47 -0
- package/lib/skittles-class/get-skittles-method.d.ts +4 -0
- package/lib/skittles-class/get-skittles-method.js +9 -9
- package/lib/skittles-class/get-skittles-operator.d.ts +4 -0
- package/lib/skittles-class/get-skittles-operator.js +2 -0
- package/lib/skittles-class/get-skittles-property.d.ts +4 -0
- package/lib/skittles-class/get-skittles-property.js +5 -3
- package/lib/skittles-class/get-skittles-state-mutability.d.ts +3 -0
- package/lib/skittles-class/get-skittles-state-mutability.js +1 -1
- package/lib/skittles-class/get-skittles-statements.d.ts +4 -0
- package/lib/skittles-class/get-skittles-statements.js +139 -34
- package/lib/skittles-class/get-skittles-type.d.ts +4 -0
- package/lib/skittles-class/get-skittles-type.js +54 -18
- package/lib/testing/get-skittles-factory.d.ts +4 -0
- package/lib/testing/get-skittles-factory.js +25 -0
- package/lib/types/abi-types.d.ts +12 -0
- package/lib/types/core-types.d.ts +21 -0
- package/lib/types/skittles-class.d.ts +211 -0
- package/lib/types/skittles-class.js +30 -11
- package/lib/yul/add-yul-constructor.d.ts +3 -0
- package/lib/yul/add-yul-method-dispatcher.d.ts +3 -0
- package/lib/yul/add-yul-method-dispatcher.js +30 -9
- package/lib/yul/add-yul-method-function.d.ts +3 -0
- package/lib/yul/add-yul-method-function.js +15 -4
- package/lib/yul/add-yul-property-dispatcher.d.ts +3 -0
- package/lib/yul/add-yul-property-dispatcher.js +21 -1
- package/lib/yul/add-yul-storage-access.d.ts +3 -0
- package/lib/yul/add-yul-storage-access.js +32 -4
- package/lib/yul/add-yul-storage-layout.d.ts +7 -0
- package/lib/yul/add-yul-storage-layout.js +41 -16
- package/lib/yul/add-yul-value-initialzations.d.ts +3 -0
- package/lib/yul/add-yul-value-initialzations.js +3 -2
- package/lib/yul/format-yul.d.ts +2 -0
- package/lib/yul/get-block-yul.d.ts +3 -0
- package/lib/yul/get-expression-yul.d.ts +3 -0
- package/lib/yul/get-expression-yul.js +16 -1
- package/lib/yul/get-statement-yul.d.ts +3 -0
- package/lib/yul/get-statement-yul.js +55 -3
- package/lib/yul/get-yul.d.ts +4 -0
- package/lib/yul/get-yul.js +7 -5
- package/lib/yul/yul-constants.d.ts +3 -0
- package/lib/yul/yul-constants.js +1 -0
- package/package.json +16 -17
package/lib/abi/get-abi.js
CHANGED
|
@@ -1,37 +1,94 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const skittles_class_1 = require("../types/skittles-class");
|
|
4
|
+
const getTypeString = (type) => {
|
|
5
|
+
return type.kind;
|
|
6
|
+
};
|
|
3
7
|
const getConstructorAbi = (constructor) => {
|
|
4
8
|
if (!constructor)
|
|
5
9
|
return [];
|
|
6
10
|
return [
|
|
7
11
|
{
|
|
8
12
|
type: "constructor",
|
|
9
|
-
inputs: constructor.parameters.map((i) =>
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
inputs: constructor.parameters.map((i) => {
|
|
14
|
+
return {
|
|
15
|
+
name: i.name,
|
|
16
|
+
type: getTypeString(i.type),
|
|
17
|
+
};
|
|
18
|
+
}),
|
|
13
19
|
stateMutability: "nonpayable",
|
|
14
20
|
},
|
|
15
21
|
];
|
|
16
22
|
};
|
|
17
23
|
const getPropertyAbi = (property) => {
|
|
24
|
+
if (property.type.kind === skittles_class_1.SkittlesTypeKind.Mapping) {
|
|
25
|
+
return {
|
|
26
|
+
type: "function",
|
|
27
|
+
name: property.name,
|
|
28
|
+
inputs: property.type.inputs.map((i) => {
|
|
29
|
+
return {
|
|
30
|
+
name: "",
|
|
31
|
+
type: getTypeString(i),
|
|
32
|
+
};
|
|
33
|
+
}),
|
|
34
|
+
outputs: [{ name: "", type: getTypeString(property.type.output) }],
|
|
35
|
+
stateMutability: "view",
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (property.type.kind === skittles_class_1.SkittlesTypeKind.Array) {
|
|
39
|
+
return {
|
|
40
|
+
type: "function",
|
|
41
|
+
name: property.name,
|
|
42
|
+
inputs: [
|
|
43
|
+
{
|
|
44
|
+
name: "index",
|
|
45
|
+
type: "uint256",
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
outputs: [{ name: "", type: getTypeString(property.type.itemType) }],
|
|
49
|
+
stateMutability: "view",
|
|
50
|
+
};
|
|
51
|
+
}
|
|
18
52
|
return {
|
|
19
53
|
type: "function",
|
|
20
54
|
name: property.name,
|
|
21
55
|
inputs: [],
|
|
22
|
-
outputs: [{ name: "", type: property.type }],
|
|
56
|
+
outputs: [{ name: "", type: getTypeString(property.type) }],
|
|
23
57
|
stateMutability: "view",
|
|
24
58
|
};
|
|
25
59
|
};
|
|
26
60
|
const getMethodAbi = (method) => {
|
|
61
|
+
const outputs = () => {
|
|
62
|
+
const { returns } = method;
|
|
63
|
+
if (returns.kind === skittles_class_1.SkittlesTypeKind.Void)
|
|
64
|
+
return [];
|
|
65
|
+
if (returns.kind === skittles_class_1.SkittlesTypeKind.Interface) {
|
|
66
|
+
return [
|
|
67
|
+
...returns.interface.elements.map((e) => {
|
|
68
|
+
return {
|
|
69
|
+
name: e.name,
|
|
70
|
+
type: getTypeString(e.type),
|
|
71
|
+
};
|
|
72
|
+
}),
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
return [
|
|
76
|
+
{
|
|
77
|
+
name: "",
|
|
78
|
+
type: getTypeString(returns),
|
|
79
|
+
},
|
|
80
|
+
];
|
|
81
|
+
};
|
|
27
82
|
return {
|
|
28
83
|
type: "function",
|
|
29
84
|
name: method.name,
|
|
30
|
-
inputs: method.parameters.map((i) =>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
85
|
+
inputs: method.parameters.map((i) => {
|
|
86
|
+
return {
|
|
87
|
+
name: i.name,
|
|
88
|
+
type: getTypeString(i.type),
|
|
89
|
+
};
|
|
90
|
+
}),
|
|
91
|
+
outputs: outputs(),
|
|
35
92
|
stateMutability: method.view ? "view" : "payable",
|
|
36
93
|
};
|
|
37
94
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
const ora_1 = __importDefault(require("ora"));
|
|
7
|
+
const get_abi_1 = __importDefault(require("../abi/get-abi"));
|
|
8
|
+
const get_bytecode_1 = __importDefault(require("../bytecode/get-bytecode"));
|
|
9
|
+
const add_dependencies_1 = __importDefault(require("../dependencies/add-dependencies"));
|
|
10
|
+
const file_helper_1 = require("../helpers/file-helper");
|
|
11
|
+
const get_skittles_class_1 = __importDefault(require("../skittles-class/get-skittles-class"));
|
|
12
|
+
const get_yul_1 = __importDefault(require("../yul/get-yul"));
|
|
13
|
+
const doTask = (task, fn) => {
|
|
14
|
+
const spinner = (0, ora_1.default)(task).start();
|
|
15
|
+
const response = fn();
|
|
16
|
+
spinner.succeed();
|
|
17
|
+
return response;
|
|
18
|
+
};
|
|
19
|
+
const skittlesCompile = () => {
|
|
20
|
+
const files = doTask("Loading Contracts", () => (0, file_helper_1.getAllContractFiles)());
|
|
21
|
+
const classes = doTask("Processing", () => files.map(get_skittles_class_1.default));
|
|
22
|
+
classes.forEach((skittlesClass) => {
|
|
23
|
+
const { name } = skittlesClass;
|
|
24
|
+
doTask(`Compiling ${name}`, () => {
|
|
25
|
+
const newClass = (0, add_dependencies_1.default)(skittlesClass, classes);
|
|
26
|
+
const abi = (0, get_abi_1.default)(newClass);
|
|
27
|
+
(0, file_helper_1.writeFile)("abi", name, JSON.stringify(abi, null, 2));
|
|
28
|
+
const yul = (0, get_yul_1.default)(newClass, abi);
|
|
29
|
+
(0, file_helper_1.writeFile)("yul", name, yul);
|
|
30
|
+
const bytecode = (0, get_bytecode_1.default)(name, yul);
|
|
31
|
+
(0, file_helper_1.writeFile)("bytecode", name, bytecode);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
exports.default = skittlesCompile;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare enum YulSection {
|
|
2
|
+
Constructor = "constructor",
|
|
3
|
+
Dispatchers = "dispatchers",
|
|
4
|
+
Functions = "functions",
|
|
5
|
+
ConstructorFunctions = "constructor functions",
|
|
6
|
+
StorageLayout = "storage layout",
|
|
7
|
+
ConstructorStorageLayout = "constructor storage layout",
|
|
8
|
+
StorageAccess = "storage access",
|
|
9
|
+
ConstructorStorageAccess = "constructor storage access"
|
|
10
|
+
}
|
|
11
|
+
declare const yulTemplate: string[];
|
|
12
|
+
export default yulTemplate;
|
package/lib/data/yul-template.js
CHANGED
|
@@ -6,6 +6,7 @@ var YulSection;
|
|
|
6
6
|
YulSection["Constructor"] = "constructor";
|
|
7
7
|
YulSection["Dispatchers"] = "dispatchers";
|
|
8
8
|
YulSection["Functions"] = "functions";
|
|
9
|
+
YulSection["ConstructorFunctions"] = "constructor functions";
|
|
9
10
|
YulSection["StorageLayout"] = "storage layout";
|
|
10
11
|
YulSection["ConstructorStorageLayout"] = "constructor storage layout";
|
|
11
12
|
YulSection["StorageAccess"] = "storage access";
|
|
@@ -54,6 +55,9 @@ const yulTemplate = [
|
|
|
54
55
|
`/* ---------- constructor ----------- */`,
|
|
55
56
|
``,
|
|
56
57
|
``,
|
|
58
|
+
`/* ---------- constructor functions ----------- */`,
|
|
59
|
+
``,
|
|
60
|
+
``,
|
|
57
61
|
`/* -------- constructor storage layout ---------- */`,
|
|
58
62
|
``,
|
|
59
63
|
``,
|
|
@@ -108,6 +112,9 @@ const yulTemplate = [
|
|
|
108
112
|
`mstore(64, v)`,
|
|
109
113
|
`return(0x00, 0x60)`,
|
|
110
114
|
`}`,
|
|
115
|
+
`function returnArray(v) {`,
|
|
116
|
+
`return(0, v)`,
|
|
117
|
+
`}`,
|
|
111
118
|
`function returnBoolean(v) {`,
|
|
112
119
|
`switch v`,
|
|
113
120
|
`case true {`,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const addDependencies = (skittlesClass, classes) => {
|
|
4
|
+
const dependencyClasses = classes.filter((c) => {
|
|
5
|
+
return skittlesClass.classExtensions.includes(c.name);
|
|
6
|
+
});
|
|
7
|
+
if (dependencyClasses.length === 0)
|
|
8
|
+
return skittlesClass;
|
|
9
|
+
const { name, constructor, methods, interfaces, variables, classExtensions } = skittlesClass;
|
|
10
|
+
dependencyClasses.forEach((dependencyClass) => {
|
|
11
|
+
const { methods: dependencyMethods, interfaces: dependencyInterfaces, variables: dependencyVariables, classExtensions: dependencyClassExtensions, } = dependencyClass;
|
|
12
|
+
Object.entries(dependencyInterfaces).forEach(([key, value]) => {
|
|
13
|
+
if (!interfaces[key])
|
|
14
|
+
interfaces[key] = value;
|
|
15
|
+
});
|
|
16
|
+
methods.push(...dependencyMethods);
|
|
17
|
+
variables.push(...dependencyVariables);
|
|
18
|
+
classExtensions.push(...dependencyClassExtensions);
|
|
19
|
+
});
|
|
20
|
+
return {
|
|
21
|
+
classExtensions,
|
|
22
|
+
name,
|
|
23
|
+
constructor,
|
|
24
|
+
methods,
|
|
25
|
+
interfaces,
|
|
26
|
+
variables,
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
exports.default = addDependencies;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BinaryExpression, ClassDeclaration, Node, PropertyDeclaration } from "typescript";
|
|
2
|
+
export declare const getClassNode: (node: Node) => ClassDeclaration;
|
|
3
|
+
export declare const getNodeName: (node: Node) => string;
|
|
4
|
+
export declare const isPlusEquals: (expression: BinaryExpression) => boolean;
|
|
5
|
+
export declare const isEquals: (expression: BinaryExpression) => boolean;
|
|
6
|
+
export declare const isMinusEquals: (expression: BinaryExpression) => boolean;
|
|
7
|
+
export declare const isTrueKeyword: (node: Node) => boolean;
|
|
8
|
+
export declare const isFalseKeyword: (node: Node) => boolean;
|
|
9
|
+
export declare const isNodePrivate: (node: Node) => boolean;
|
|
10
|
+
export declare const isNodeImmutable: (node: Node) => boolean;
|
|
11
|
+
export declare const isPropertyArrowFunction: (node: PropertyDeclaration) => boolean;
|
|
12
|
+
export declare const isVariable: (property: PropertyDeclaration) => boolean;
|
|
13
|
+
export declare const isExpression: (node: Node) => boolean;
|
|
@@ -48,7 +48,8 @@ exports.isFalseKeyword = isFalseKeyword;
|
|
|
48
48
|
const isNodePrivate = (node) => {
|
|
49
49
|
let isPrivate = false;
|
|
50
50
|
(0, typescript_1.forEachChild)(node, (node) => {
|
|
51
|
-
if (node.kind === typescript_1.SyntaxKind.PrivateKeyword
|
|
51
|
+
if (node.kind === typescript_1.SyntaxKind.PrivateKeyword ||
|
|
52
|
+
node.kind === typescript_1.SyntaxKind.ProtectedKeyword) {
|
|
52
53
|
isPrivate = true;
|
|
53
54
|
}
|
|
54
55
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const logSkittles: () => void;
|
|
@@ -0,0 +1,33 @@
|
|
|
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.logSkittles = void 0;
|
|
7
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
8
|
+
const lines = [
|
|
9
|
+
` 888 d8b 888 888 888 `,
|
|
10
|
+
` 888 Y8P 888 888 888 `,
|
|
11
|
+
` 888 888 888 888 `,
|
|
12
|
+
`.d8888b 888 888 888 888888 888888 888 .d88b. .d8888b `,
|
|
13
|
+
`88K 888 .88P 888 888 888 888 d8P Y8b 88K `,
|
|
14
|
+
`"Y8888b. 888888K 888 888 888 888 88888888 "Y8888b. `,
|
|
15
|
+
` X88 888 "88b 888 Y88b. Y88b. 888 Y8b. X88 `,
|
|
16
|
+
` 88888P' 888 888 888 "Y888 "Y888 888 "Y8888 88888P' `,
|
|
17
|
+
];
|
|
18
|
+
const letterBreakpoints = [9, 17, 21, 28, 35, 39, 48];
|
|
19
|
+
const logSkittles = () => {
|
|
20
|
+
console.log("");
|
|
21
|
+
lines.forEach((line) => {
|
|
22
|
+
console.log(chalk_1.default.hex("#de3c3c")(line.substring(0, letterBreakpoints[0])) +
|
|
23
|
+
chalk_1.default.hex("#deb53c")(line.substring(letterBreakpoints[0], letterBreakpoints[1])) +
|
|
24
|
+
chalk_1.default.hex("#8dde3c")(line.substring(letterBreakpoints[1], letterBreakpoints[2])) +
|
|
25
|
+
chalk_1.default.hex("#3cde64")(line.substring(letterBreakpoints[2], letterBreakpoints[3])) +
|
|
26
|
+
chalk_1.default.hex("#3cdede")(line.substring(letterBreakpoints[3], letterBreakpoints[4])) +
|
|
27
|
+
chalk_1.default.hex("#3c64de")(line.substring(letterBreakpoints[4], letterBreakpoints[5])) +
|
|
28
|
+
chalk_1.default.hex("#8d3cde")(line.substring(letterBreakpoints[5], letterBreakpoints[6])) +
|
|
29
|
+
chalk_1.default.hex("#de3cb5")(line.substring(letterBreakpoints[6])));
|
|
30
|
+
});
|
|
31
|
+
console.log("");
|
|
32
|
+
};
|
|
33
|
+
exports.logSkittles = logSkittles;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const getAllFilesInDirectory: (dir: string) => string[];
|
|
2
|
+
export declare const getAllContractFiles: () => string[];
|
|
3
|
+
export declare const writeFile: (type: string, fileName: string, content: string) => void;
|
|
4
|
+
export declare const clearDirectory: (directory: string) => void;
|
|
5
|
+
export declare const getContractName: (fileName: string) => string;
|
|
@@ -3,21 +3,33 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.writeFile = exports.getAllContractFiles = void 0;
|
|
6
|
+
exports.getContractName = exports.clearDirectory = exports.writeFile = exports.getAllContractFiles = exports.getAllFilesInDirectory = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const CONTRCT_PATH = "./contracts";
|
|
10
|
+
const getAllFilesInDirectory = (dir) => {
|
|
11
|
+
const files = [];
|
|
12
|
+
fs_1.default.readdirSync(dir).forEach((file) => {
|
|
13
|
+
const filePath = path_1.default.join(dir, file);
|
|
14
|
+
if (fs_1.default.statSync(filePath).isDirectory()) {
|
|
15
|
+
files.push(...(0, exports.getAllFilesInDirectory)(filePath));
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
files.push(filePath);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
return files;
|
|
22
|
+
};
|
|
23
|
+
exports.getAllFilesInDirectory = getAllFilesInDirectory;
|
|
10
24
|
const getAllContractFiles = () => {
|
|
11
|
-
return
|
|
12
|
-
.readdirSync(CONTRCT_PATH)
|
|
25
|
+
return (0, exports.getAllFilesInDirectory)(CONTRCT_PATH)
|
|
13
26
|
.filter((file) => {
|
|
14
|
-
return fs_1.default.statSync(
|
|
15
|
-
})
|
|
16
|
-
.map((file) => {
|
|
17
|
-
return path_1.default.join(CONTRCT_PATH, file);
|
|
27
|
+
return fs_1.default.statSync(file).isFile();
|
|
18
28
|
})
|
|
19
29
|
.filter((file) => {
|
|
20
|
-
return file.endsWith(".ts")
|
|
30
|
+
return (file.endsWith(".ts") &&
|
|
31
|
+
!file.endsWith(".d.ts") &&
|
|
32
|
+
!file.endsWith(".spec.ts"));
|
|
21
33
|
});
|
|
22
34
|
};
|
|
23
35
|
exports.getAllContractFiles = getAllContractFiles;
|
|
@@ -28,3 +40,26 @@ const writeFile = (type, fileName, content) => {
|
|
|
28
40
|
fs_1.default.writeFileSync(`${directory}/${fileName}.${type}`, content);
|
|
29
41
|
};
|
|
30
42
|
exports.writeFile = writeFile;
|
|
43
|
+
// Delete all files and directories in the given directory
|
|
44
|
+
const clearDirectory = (directory) => {
|
|
45
|
+
const files = fs_1.default.readdirSync(directory);
|
|
46
|
+
for (const file of files) {
|
|
47
|
+
const filePath = path_1.default.join(directory, file);
|
|
48
|
+
if (fs_1.default.statSync(filePath).isFile()) {
|
|
49
|
+
fs_1.default.unlinkSync(filePath);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
(0, exports.clearDirectory)(filePath);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
fs_1.default.rmdirSync(directory);
|
|
56
|
+
};
|
|
57
|
+
exports.clearDirectory = clearDirectory;
|
|
58
|
+
const getContractName = (fileName) => {
|
|
59
|
+
const file = fs_1.default.readFileSync(fileName, { encoding: "utf8" });
|
|
60
|
+
const contractIndex = file.indexOf("class");
|
|
61
|
+
if (contractIndex === -1)
|
|
62
|
+
throw new Error(`No contract in file ${file}`);
|
|
63
|
+
return file.substring(contractIndex + 6, file.indexOf(" ", contractIndex + 6));
|
|
64
|
+
};
|
|
65
|
+
exports.getContractName = getContractName;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { address, self, block, chain, msg, tx } from "./types/core-types";
|
|
3
|
+
import getSkittlesFactory from "./testing/get-skittles-factory";
|
|
4
|
+
import { ZERO_ADDRESS } from "./data/constants";
|
|
5
|
+
export { address, self, block, chain, msg, tx, getSkittlesFactory, ZERO_ADDRESS, };
|
package/lib/index.js
CHANGED
|
@@ -13,56 +13,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
13
13
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
14
14
|
};
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
-
exports.tx = exports.msg = exports.chain = exports.block = exports.self = void 0;
|
|
17
|
-
|
|
18
|
-
// import clear from "clear";
|
|
19
|
-
// import figlet from "figlet";
|
|
20
|
-
// import path from "path";
|
|
21
|
-
const commander_1 = require("commander");
|
|
22
|
-
const get_abi_1 = __importDefault(require("./abi/get-abi"));
|
|
23
|
-
const get_bytecode_1 = __importDefault(require("./bytecode/get-bytecode"));
|
|
16
|
+
exports.ZERO_ADDRESS = exports.getSkittlesFactory = exports.tx = exports.msg = exports.chain = exports.block = exports.self = void 0;
|
|
17
|
+
const yargs_1 = __importDefault(require("yargs"));
|
|
24
18
|
const file_helper_1 = require("./helpers/file-helper");
|
|
25
|
-
const get_skittles_class_1 = __importDefault(require("./skittles-class/get-skittles-class"));
|
|
26
|
-
const get_yul_1 = __importDefault(require("./yul/get-yul"));
|
|
27
19
|
const core_types_1 = require("./types/core-types");
|
|
28
20
|
Object.defineProperty(exports, "self", { enumerable: true, get: function () { return core_types_1.self; } });
|
|
29
21
|
Object.defineProperty(exports, "block", { enumerable: true, get: function () { return core_types_1.block; } });
|
|
30
22
|
Object.defineProperty(exports, "chain", { enumerable: true, get: function () { return core_types_1.chain; } });
|
|
31
23
|
Object.defineProperty(exports, "msg", { enumerable: true, get: function () { return core_types_1.msg; } });
|
|
32
24
|
Object.defineProperty(exports, "tx", { enumerable: true, get: function () { return core_types_1.tx; } });
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
// console.log(
|
|
49
|
-
// chalk.red(figlet.textSync("skittles-cli", { horizontalLayout: "full" }))
|
|
50
|
-
// );
|
|
51
|
-
commander_1.program
|
|
52
|
-
.name("skittles")
|
|
53
|
-
.description("CLI for the Skittles compiler")
|
|
54
|
-
.version("0.1.0");
|
|
55
|
-
// program
|
|
56
|
-
// .command("compile")
|
|
57
|
-
// .description("Compile TypeScript file")
|
|
58
|
-
// .argument("<string>", "file name")
|
|
59
|
-
// .action(async (str, options) => {
|
|
60
|
-
// console.log(await compileTypeScriptToBytecode(str));
|
|
61
|
-
// });
|
|
62
|
-
commander_1.program
|
|
63
|
-
.command("compile")
|
|
64
|
-
.description("Compile all TypeScript file")
|
|
65
|
-
.action(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
66
|
-
yield skittlesCompile();
|
|
67
|
-
}));
|
|
68
|
-
commander_1.program.parse();
|
|
25
|
+
const get_skittles_factory_1 = __importDefault(require("./testing/get-skittles-factory"));
|
|
26
|
+
exports.getSkittlesFactory = get_skittles_factory_1.default;
|
|
27
|
+
const console_helper_1 = require("./helpers/console-helper");
|
|
28
|
+
const skittles_compiler_1 = __importDefault(require("./compiler/skittles-compiler"));
|
|
29
|
+
const constants_1 = require("./data/constants");
|
|
30
|
+
Object.defineProperty(exports, "ZERO_ADDRESS", { enumerable: true, get: function () { return constants_1.ZERO_ADDRESS; } });
|
|
31
|
+
yargs_1.default
|
|
32
|
+
.command("compile", "Compile all TypeScript files", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
+
(0, console_helper_1.logSkittles)();
|
|
34
|
+
(0, skittles_compiler_1.default)();
|
|
35
|
+
}))
|
|
36
|
+
.command("clean", "Clears the cache and deletes all builds", () => {
|
|
37
|
+
(0, file_helper_1.clearDirectory)("./build");
|
|
38
|
+
})
|
|
39
|
+
.parse();
|
|
@@ -7,12 +7,14 @@ const typescript_1 = require("typescript");
|
|
|
7
7
|
const get_ast_1 = __importDefault(require("../ast/get-ast"));
|
|
8
8
|
const ast_helper_1 = require("../helpers/ast-helper");
|
|
9
9
|
const get_skittles_constructor_1 = __importDefault(require("./get-skittles-constructor"));
|
|
10
|
+
const get_skittles_interfaces_1 = __importDefault(require("./get-skittles-interfaces"));
|
|
10
11
|
const get_skittles_method_1 = __importDefault(require("./get-skittles-method"));
|
|
11
12
|
const get_skittles_property_1 = __importDefault(require("./get-skittles-property"));
|
|
12
13
|
const get_skittles_state_mutability_1 = __importDefault(require("./get-skittles-state-mutability"));
|
|
13
14
|
const getSkittlesClass = (file) => {
|
|
14
15
|
const ast = (0, get_ast_1.default)(file);
|
|
15
16
|
const classNode = (0, ast_helper_1.getClassNode)(ast);
|
|
17
|
+
const interfaces = (0, get_skittles_interfaces_1.default)(ast);
|
|
16
18
|
const astVariables = classNode.members
|
|
17
19
|
.filter(typescript_1.isPropertyDeclaration)
|
|
18
20
|
.filter(ast_helper_1.isVariable);
|
|
@@ -21,15 +23,26 @@ const getSkittlesClass = (file) => {
|
|
|
21
23
|
.filter(typescript_1.isPropertyDeclaration)
|
|
22
24
|
.filter(ast_helper_1.isPropertyArrowFunction);
|
|
23
25
|
const astConstructor = classNode.members.find(typescript_1.isConstructorDeclaration);
|
|
26
|
+
const classExtensions = [];
|
|
27
|
+
const { heritageClauses } = classNode;
|
|
28
|
+
if (heritageClauses) {
|
|
29
|
+
heritageClauses.forEach((heritageClause) => {
|
|
30
|
+
heritageClause.types.forEach((type) => {
|
|
31
|
+
classExtensions.push((0, ast_helper_1.getNodeName)(type.expression));
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
24
35
|
const skittlesClass = {
|
|
36
|
+
classExtensions,
|
|
37
|
+
interfaces,
|
|
25
38
|
name: (0, ast_helper_1.getNodeName)(classNode),
|
|
26
39
|
constructor: astConstructor
|
|
27
|
-
? (0, get_skittles_constructor_1.default)(astConstructor)
|
|
40
|
+
? (0, get_skittles_constructor_1.default)(astConstructor, interfaces)
|
|
28
41
|
: undefined,
|
|
29
|
-
variables: astVariables.map(get_skittles_property_1.default),
|
|
42
|
+
variables: astVariables.map((v) => (0, get_skittles_property_1.default)(v, interfaces)),
|
|
30
43
|
methods: [
|
|
31
|
-
...astMethods.map(get_skittles_method_1.default),
|
|
32
|
-
...astArrowFunctions.map(get_skittles_method_1.default),
|
|
44
|
+
...astMethods.map((m) => (0, get_skittles_method_1.default)(m, interfaces)),
|
|
45
|
+
...astArrowFunctions.map((f) => (0, get_skittles_method_1.default)(f, interfaces)),
|
|
33
46
|
],
|
|
34
47
|
};
|
|
35
48
|
return (0, get_skittles_state_mutability_1.default)(skittlesClass);
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ConstructorDeclaration } from "typescript";
|
|
2
|
+
import { SkittlesConstructor, SkittlesInterfaces } from "../types/skittles-class";
|
|
3
|
+
declare const getSkittlesConstructor: (astConstructor: ConstructorDeclaration, interfaces: SkittlesInterfaces) => SkittlesConstructor;
|
|
4
|
+
export default getSkittlesConstructor;
|
|
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
const ast_helper_1 = require("../helpers/ast-helper");
|
|
7
7
|
const get_skittles_statements_1 = __importDefault(require("./get-skittles-statements"));
|
|
8
8
|
const get_skittles_type_1 = __importDefault(require("./get-skittles-type"));
|
|
9
|
-
const getSkittlesConstructor = (astConstructor) => {
|
|
9
|
+
const getSkittlesConstructor = (astConstructor, interfaces) => {
|
|
10
10
|
return {
|
|
11
11
|
parameters: astConstructor.parameters.map((parameter) => {
|
|
12
12
|
return {
|
|
13
13
|
name: (0, ast_helper_1.getNodeName)(parameter),
|
|
14
|
-
type: (0, get_skittles_type_1.default)(parameter.type),
|
|
14
|
+
type: (0, get_skittles_type_1.default)(parameter.type, interfaces),
|
|
15
15
|
};
|
|
16
16
|
}),
|
|
17
|
-
statements: (0, get_skittles_statements_1.default)(astConstructor.body, (0, get_skittles_type_1.default)(astConstructor.type)),
|
|
17
|
+
statements: (0, get_skittles_statements_1.default)(astConstructor.body, (0, get_skittles_type_1.default)(astConstructor.type, interfaces), interfaces),
|
|
18
18
|
};
|
|
19
19
|
};
|
|
20
20
|
exports.default = getSkittlesConstructor;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Expression } from "typescript";
|
|
2
|
+
import { SkittlesExpression, SkittlesInterfaces } from "../types/skittles-class";
|
|
3
|
+
declare const getSkittlesExpression: (expression: Expression, interfaces: SkittlesInterfaces) => SkittlesExpression;
|
|
4
|
+
export default getSkittlesExpression;
|