@bikky/compiler 0.0.8 → 0.0.9
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/Libraries/BiscuitLibraries.d.ts +2 -2
- package/Libraries/BiscuitLibraries.js +2 -2
- package/Libraries/MixinCode.d.ts +13 -13
- package/Libraries/MixinCode.js +92 -92
- package/Source/ASTBuilder.d.ts +36 -0
- package/Source/ASTBuilder.d.ts.map +1 -0
- package/Source/ASTBuilder.js +180 -0
- package/Source/ASTHelper.d.ts +67 -73
- package/Source/ASTHelper.d.ts.map +1 -1
- package/Source/ASTHelper.js +320 -343
- package/Source/ASTInterface/Class.d.ts +38 -0
- package/Source/ASTInterface/Class.d.ts.map +1 -0
- package/Source/ASTInterface/Class.js +256 -0
- package/Source/ASTInterface/Crawler.d.ts +8 -0
- package/Source/ASTInterface/Crawler.d.ts.map +1 -0
- package/Source/ASTInterface/Crawler.js +55 -0
- package/Source/ASTInterface/Tokens.d.ts +78 -0
- package/Source/ASTInterface/Tokens.d.ts.map +1 -0
- package/Source/ASTInterface/Tokens.js +49 -0
- package/Source/ASTSearcher.d.ts +20 -0
- package/Source/ASTSearcher.d.ts.map +1 -0
- package/Source/ASTSearcher.js +116 -0
- package/Source/ASTTraverser.d.ts +10 -0
- package/Source/ASTTraverser.d.ts.map +1 -0
- package/Source/ASTTraverser.js +74 -0
- package/Source/TSPatchTypes.d.ts +17 -0
- package/Transformers/CompilerInsertions.js +23 -23
- package/Transformers/MacroTransformer.d.ts +2 -2
- package/Transformers/MacroTransformer.d.ts.map +1 -1
- package/Transformers/MacroTransformer.js +282 -281
- package/Transformers/MixinTransformer.d.ts +2 -3
- package/Transformers/MixinTransformer.d.ts.map +1 -1
- package/Transformers/MixinTransformer.js +320 -124
- package/Transformers/SuperTransformer.d.ts +2 -2
- package/Transformers/SuperTransformer.d.ts.map +1 -1
- package/Transformers/SuperTransformer.js +138 -117
- package/obj/Debug/BiscuitCompiler.njsproj.AssemblyReference.cache +0 -0
- package/package.json +6 -5
- package/tsconfig.build.libs.json +1 -1
- package/tsconfig.build.libs.tsbuildinfo +1 -1
- package/tsconfig.build.src.json +1 -1
- package/tsconfig.build.src.tsbuildinfo +1 -1
- package/tsconfig.json +10 -11
- package/tsconfig.tsbuildinfo +1 -0
|
@@ -1,282 +1,283 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
// transformer1-module
|
|
4
|
-
const ts = require("typescript");
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
10
|
-
//
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
//
|
|
27
|
-
//
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
//
|
|
49
|
-
for
|
|
50
|
-
|
|
51
|
-
//
|
|
52
|
-
if (
|
|
53
|
-
|
|
54
|
-
&& ts.
|
|
55
|
-
&& declaration.initializer.expression
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
//
|
|
93
|
-
//
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
var
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
var
|
|
121
|
-
var
|
|
122
|
-
|
|
123
|
-
//
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
&&
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
//"context" is
|
|
155
|
-
//
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
var
|
|
159
|
-
var
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
//
|
|
175
|
-
//
|
|
176
|
-
|
|
177
|
-
var
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
//
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
//
|
|
212
|
-
//
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
&& node.expression
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
&& node.expression
|
|
223
|
-
|
|
224
|
-
return
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
//
|
|
262
|
-
//
|
|
263
|
-
//
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
//
|
|
272
|
-
// //
|
|
273
|
-
// //
|
|
274
|
-
//
|
|
275
|
-
//
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
}
|
|
281
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// transformer1-module
|
|
4
|
+
const ts = require("typescript");
|
|
5
|
+
const ASTBuilder_1 = require("../Source/ASTBuilder");
|
|
6
|
+
//This class should be able to do a few things:
|
|
7
|
+
// Import macros from other files.
|
|
8
|
+
// Copy macro AST
|
|
9
|
+
// Insert macro AST to the destination location (inlining the macro).
|
|
10
|
+
// Resolve variable names to the name of the provided variable.
|
|
11
|
+
// Not require special (complex) syntax in the macro creation.
|
|
12
|
+
class MacroTransformer {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.RegisteredMacros = new Map();
|
|
15
|
+
this.DeclarationName = "MACRO";
|
|
16
|
+
this.printer = ts.createPrinter();
|
|
17
|
+
}
|
|
18
|
+
logError(node, error) {
|
|
19
|
+
if (!node || !node.getSourceFile()) {
|
|
20
|
+
console.error("Why are we here?");
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
var source = ts.isSourceFile(node) ? node : node.getSourceFile();
|
|
24
|
+
var pos = source.getLineAndCharacterOfPosition(node.pos);
|
|
25
|
+
console.error(`${source.fileName}(${pos.line},${pos.character}):`, error);
|
|
26
|
+
// This can cause the compiler to stop, but we're not using it because the above will allow
|
|
27
|
+
// us to go to the right location in the file. And we probably want to return what we can if
|
|
28
|
+
// there's an error since that's how the rest of typescript works.
|
|
29
|
+
//ts.createThrow(ts.createStringLiteral("Compiler Error."));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
printNode(node, sourceFile) {
|
|
33
|
+
return this.printer.printNode(ts.EmitHint.Unspecified, node, sourceFile);
|
|
34
|
+
}
|
|
35
|
+
printNodeFirstLine(node, sourceFile) {
|
|
36
|
+
var code = this.printNode(node, node.getSourceFile());
|
|
37
|
+
//space matches tab.
|
|
38
|
+
code = code.replace(/^ *{? *\r\n?/, "");
|
|
39
|
+
return code.replace(/\r\n.*/gi, "");
|
|
40
|
+
}
|
|
41
|
+
CrawlExpressionTree(node) {
|
|
42
|
+
//Run twice, we hoist macro declarations.
|
|
43
|
+
node = ts.visitNode(node, this.FindMacroDeclaration.bind(this));
|
|
44
|
+
return ts.visitNode(node, this.SearchForMacroUseStatement.bind(this));
|
|
45
|
+
}
|
|
46
|
+
FindMacroDeclaration(node) {
|
|
47
|
+
if (ts.isVariableStatement(node)) {
|
|
48
|
+
//This statement has potential to contain a MACRO declaration.
|
|
49
|
+
//Support for comma separated declarations.
|
|
50
|
+
for (var declaration of node.declarationList.declarations) {
|
|
51
|
+
//If this variable is initialised, and it's initialised with a function call check to see
|
|
52
|
+
// if the function's name is MACRO (which is our custom buzzword).
|
|
53
|
+
if (declaration.initializer
|
|
54
|
+
&& ts.isCallExpression(declaration.initializer)
|
|
55
|
+
&& ts.isIdentifier(declaration.initializer.expression)
|
|
56
|
+
&& declaration.initializer.expression.text === this.DeclarationName) {
|
|
57
|
+
//This is the name of the variable that the macro's being assigned to.
|
|
58
|
+
var name = declaration.name;
|
|
59
|
+
//Macros must be identifiers (normal variables, not symbols and not array unwraps).
|
|
60
|
+
if (!ts.isIdentifier(name)) {
|
|
61
|
+
this.logError(declaration, "Macros must be declared as using normal identifiers, symbols and array unwraps are unsupported.");
|
|
62
|
+
return node;
|
|
63
|
+
}
|
|
64
|
+
if (declaration.initializer.arguments.length == 0) {
|
|
65
|
+
this.logError(declaration, "When declaring a macro a function must be supplied as the first parameter.");
|
|
66
|
+
return node;
|
|
67
|
+
}
|
|
68
|
+
if (declaration.initializer.arguments.length > 1) {
|
|
69
|
+
this.logError(declaration, "Macro declaration only takes one parameter.");
|
|
70
|
+
return node;
|
|
71
|
+
}
|
|
72
|
+
var value = declaration.initializer.arguments[0];
|
|
73
|
+
this.RegisteredMacros.set(name.text, value);
|
|
74
|
+
console.log("Registering macro", name.text);
|
|
75
|
+
//Now that we've stored the macro code for later use, we need to delete it from the file.
|
|
76
|
+
//Todo: this creates an unnecessary semicolon.
|
|
77
|
+
return ts.factory.createEmptyStatement();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
node = ts.visitEachChild(node, this.FindMacroDeclaration.bind(this), this.context) || node;
|
|
82
|
+
return node;
|
|
83
|
+
}
|
|
84
|
+
SearchForMacroUseStatement(node) {
|
|
85
|
+
if (ts.isBlock(node) || ts.isSourceFile(node) || ts.isCaseBlock(node)) {
|
|
86
|
+
//console.log("Block:", this.printNodeFirstLine(node, node.getSourceFile()));
|
|
87
|
+
return ts.visitEachChild(node, this.FindMacroUsage.bind(this), this.context);
|
|
88
|
+
}
|
|
89
|
+
else if (ts.isFunctionDeclaration(node)) {
|
|
90
|
+
var body = ts.visitEachChild(node.body, this.FindMacroUsage.bind(this), this.context);
|
|
91
|
+
let foo = ts.factory.updateFunctionDeclaration(node, node.modifiers, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, body);
|
|
92
|
+
//if (foo.name) {
|
|
93
|
+
// console.log("Function:", this.printNode(foo.name, node.getSourceFile()));
|
|
94
|
+
//}
|
|
95
|
+
return foo;
|
|
96
|
+
}
|
|
97
|
+
else if (ts.isMethodDeclaration(node)) {
|
|
98
|
+
var body = ts.visitEachChild(node.body, this.FindMacroUsage.bind(this), this.context);
|
|
99
|
+
let foo = ts.factory.updateMethodDeclaration(node, node.modifiers, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, body);
|
|
100
|
+
//console.log("Method:", this.printNode(foo.name, node.getSourceFile()));
|
|
101
|
+
return foo;
|
|
102
|
+
}
|
|
103
|
+
else if (ts.isIfStatement(node)) {
|
|
104
|
+
//console.log("IF:", this.printNode(node, node.getSourceFile()));
|
|
105
|
+
var thenS = ts.visitNode(node.thenStatement, this.SearchForMacroUseStatement.bind(this));
|
|
106
|
+
var elseS = node.elseStatement ? ts.visitNode(node.elseStatement, this.SearchForMacroUseStatement.bind(this)) : undefined;
|
|
107
|
+
return ts.factory.updateIfStatement(node, node.expression, thenS, elseS);
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
return ts.visitEachChild(node, this.SearchForMacroUseStatement.bind(this), this.context);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
isBlocky(node) {
|
|
114
|
+
return ts.isMethodDeclaration(node) || ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node) || ts.isInterfaceDeclaration(node) || ts.isIfStatement(node);
|
|
115
|
+
}
|
|
116
|
+
FindMacroUsage(node) {
|
|
117
|
+
if (this.isBlocky(node)) {
|
|
118
|
+
return ts.visitNode(node, this.SearchForMacroUseStatement.bind(this));
|
|
119
|
+
}
|
|
120
|
+
var MACARONY = false;
|
|
121
|
+
var context = undefined;
|
|
122
|
+
var call = undefined;
|
|
123
|
+
//How to do this:
|
|
124
|
+
//Recurse through statement to see if it has a macro expression.
|
|
125
|
+
function SpyMacro(node) {
|
|
126
|
+
//If there's a new block in here we bail, otherwise we'd put the macro scoping in the wrong scoping level.
|
|
127
|
+
if (ts.isBlock(node) || ts.isCaseBlock(node) || this.isBlocky(node)) {
|
|
128
|
+
return ts.visitNode(node, this.SearchForMacroUseStatement.bind(this));
|
|
129
|
+
}
|
|
130
|
+
if (ts.isCallExpression(node)
|
|
131
|
+
&& ts.isPropertyAccessExpression(node.expression)
|
|
132
|
+
&& this.RegisteredMacros.has(node.expression.name.text)) {
|
|
133
|
+
MACARONY = true;
|
|
134
|
+
context = node.expression.expression;
|
|
135
|
+
call = node;
|
|
136
|
+
//console.log("FOUND MACRO USAGE!", node.expression.name.text);
|
|
137
|
+
}
|
|
138
|
+
if (ts.isCallExpression(node) &&
|
|
139
|
+
ts.isIdentifier(node.expression) &&
|
|
140
|
+
this.RegisteredMacros.has(node.expression.text)) {
|
|
141
|
+
MACARONY = true;
|
|
142
|
+
call = node;
|
|
143
|
+
}
|
|
144
|
+
return ts.visitEachChild(node, SpyMacro.bind(this), this.context);
|
|
145
|
+
}
|
|
146
|
+
ts.visitEachChild(node, SpyMacro.bind(this), this.context);
|
|
147
|
+
if (MACARONY) {
|
|
148
|
+
return this.InsertMacro(node, context, call);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
return node;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
//"context" is the thing before the dot when the macro is called, might be undefined.
|
|
155
|
+
//"context" is present if you call the macro like so: context.MACRO().
|
|
156
|
+
//Call expression is the node that represents the MACRO() part of the statement.
|
|
157
|
+
InsertMacro(statement, context, macroCall) {
|
|
158
|
+
var block = [];
|
|
159
|
+
var macro;
|
|
160
|
+
var macroName;
|
|
161
|
+
if (ts.isIdentifier(macroCall.expression)) {
|
|
162
|
+
macroName = macroCall.expression.text;
|
|
163
|
+
}
|
|
164
|
+
else if (ts.isPropertyAccessExpression(macroCall.expression)) {
|
|
165
|
+
macroName = macroCall.expression.name.text;
|
|
166
|
+
}
|
|
167
|
+
if (macroName) {
|
|
168
|
+
macro = this.RegisteredMacros.get(macroName);
|
|
169
|
+
}
|
|
170
|
+
if (!macroName || !macro) {
|
|
171
|
+
this.logError(statement, "Unspecified error in macro expansion.");
|
|
172
|
+
return statement;
|
|
173
|
+
}
|
|
174
|
+
//console.log("Putting", macroName, "in to place:", statement.getText());
|
|
175
|
+
//Map macro parameters to the arguments (replace all instances of the parameter with the argument's expression).
|
|
176
|
+
//Replacing identifiers with nodes because it can be an unnamed expression (lambda or 3 + 5).
|
|
177
|
+
var parameters = new Map();
|
|
178
|
+
var parameterOffset = 0;
|
|
179
|
+
for (var i = 0; i + parameterOffset < macro.parameters.length; i++) {
|
|
180
|
+
var parameter = macro.parameters[i + parameterOffset];
|
|
181
|
+
//Detect and skip "this" parameter
|
|
182
|
+
if (ts.isParameter(parameter) && parameter.name.getText() == "this") {
|
|
183
|
+
parameterOffset = 1;
|
|
184
|
+
//If "this" is the only parameter then don't do the rest of the loop.
|
|
185
|
+
if (!(i + parameterOffset < macro.parameters.length)) {
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
parameter = macro.parameters[i + parameterOffset];
|
|
189
|
+
}
|
|
190
|
+
var argument = macroCall.arguments[i];
|
|
191
|
+
if (typeof argument === "undefined") {
|
|
192
|
+
if (typeof parameter.questionToken === "undefined") {
|
|
193
|
+
this.logError(parameter, `Failure to specify non-optional argument to macro ${macroName}.`);
|
|
194
|
+
return statement;
|
|
195
|
+
//throw new Error("Failure to specify non-optional argument to macro.");
|
|
196
|
+
}
|
|
197
|
+
else {
|
|
198
|
+
//Probably use this instead, because it's guaranteed to be unique.
|
|
199
|
+
//ts.getGeneratedNameForNode
|
|
200
|
+
var name = parameter.name.getText();
|
|
201
|
+
//This is "let param;" for optional variables that weren't done.
|
|
202
|
+
let ver = (0, ASTBuilder_1.LET)(name);
|
|
203
|
+
block.push(ver.toAST());
|
|
204
|
+
parameters.set(name, (0, ASTBuilder_1.ID)(name).toAST());
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
parameters.set(parameter.name.getText(), argument);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
//Macros can be multiline!
|
|
212
|
+
//So we need to insert the macro into the appropriate place in the block, and then duplicate expression
|
|
213
|
+
// wherever return shows up in the macro (or on the next line if it doesn't? or maybe error...).
|
|
214
|
+
var body = (macro.body);
|
|
215
|
+
//Put the macro's result in the calling expression in place of the macro call.
|
|
216
|
+
var PutResultInExpression = (result) => {
|
|
217
|
+
return function IterateResult(node) {
|
|
218
|
+
if (ts.isCallExpression(node)
|
|
219
|
+
&& ts.isPropertyAccessExpression(node.expression)
|
|
220
|
+
&& node.expression.name.text == macroName
|
|
221
|
+
|| ts.isCallExpression(node)
|
|
222
|
+
&& ts.isIdentifier(node.expression)
|
|
223
|
+
&& node.expression.text == macroName) {
|
|
224
|
+
//replace with stuff after return statement.
|
|
225
|
+
return ts.visitNode(result.expression, ReplaceStuffInMacro.bind(this));
|
|
226
|
+
}
|
|
227
|
+
return ts.visitEachChild(node, IterateResult.bind(this), this.context);
|
|
228
|
+
}.bind(this);
|
|
229
|
+
};
|
|
230
|
+
function CopyAsIs(node) {
|
|
231
|
+
return ts.visitEachChild(node, CopyAsIs.bind(this), this.context);
|
|
232
|
+
}
|
|
233
|
+
function ReplaceStuffInMacro(node) {
|
|
234
|
+
if (ts.isReturnStatement(node)) {
|
|
235
|
+
return ts.visitEachChild(statement, PutResultInExpression(node), this.context);
|
|
236
|
+
}
|
|
237
|
+
if (ts.isPropertyAccessExpression(node) && (node.expression.kind == ts.SyntaxKind.ThisType || node.expression.kind == ts.SyntaxKind.ThisKeyword)) {
|
|
238
|
+
if (!context) {
|
|
239
|
+
this.logError(node, "Macro can only be executed as a property accessor (value.MACRO) but here is not, this causes an error. MACRO.bind is not supported use value.MACRO instead.");
|
|
240
|
+
return node;
|
|
241
|
+
}
|
|
242
|
+
//If this is referenced then replace it with the stuff before the . when the macro is called.
|
|
243
|
+
return ts.factory.createPropertyAccessExpression(context, node.name.text);
|
|
244
|
+
//return ts.visitEachChild(context, Inplace.bind(this), this.context);
|
|
245
|
+
}
|
|
246
|
+
if (ts.isIdentifier(node) && parameters.has(node.text)) {
|
|
247
|
+
//If a parameter is referenced replace it with the argument provided in macro use.
|
|
248
|
+
return ts.visitNode(parameters.get(node.text), CopyAsIs.bind(this));
|
|
249
|
+
}
|
|
250
|
+
return ts.visitEachChild(node, ReplaceStuffInMacro.bind(this), this.context);
|
|
251
|
+
}
|
|
252
|
+
//unroll macro and then replace all return statements with expression.
|
|
253
|
+
for (var expression of body.statements) {
|
|
254
|
+
block.push(ts.visitNode(expression, ReplaceStuffInMacro.bind(this)));
|
|
255
|
+
}
|
|
256
|
+
var result = ts.factory.createBlock(block);
|
|
257
|
+
return result;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
console.log("MACROS ENABLED");
|
|
261
|
+
//Initiating the transformer here is a hodge-podge solution to resolving transforms supplied in other files.
|
|
262
|
+
// We probably need to do a proper solution that involves aliasing the macro's name to whatever the import is called, and removing
|
|
263
|
+
// the import statement if the only thing that's imported is macros. On second thought that last part is really hard so let's not
|
|
264
|
+
// do that.
|
|
265
|
+
var transformer = new MacroTransformer();
|
|
266
|
+
function default_1(program, pluginOptions) {
|
|
267
|
+
return (context) => {
|
|
268
|
+
transformer.context = context;
|
|
269
|
+
return (sourceFile) => {
|
|
270
|
+
console.log("HERE!");
|
|
271
|
+
// function visitor(node: ts.Node): ts.Node {
|
|
272
|
+
// // if (ts.isCallExpression(node)) {
|
|
273
|
+
// // return ts.createLiteral('call');
|
|
274
|
+
// // }
|
|
275
|
+
// return ts.visitEachChild(node, visitor, context);
|
|
276
|
+
// }
|
|
277
|
+
return transformer.CrawlExpressionTree(sourceFile);
|
|
278
|
+
// return ts.visitEachChild(sourceFile, visitor, context);
|
|
279
|
+
};
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
exports.default = default_1;
|
|
282
283
|
//# sourceMappingURL=MacroTransformer.js.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as ts from "typescript";
|
|
2
|
-
|
|
3
|
-
export default function (program: ts.Program, pluginOptions: {}): (context: ts.TransformationContext) => (sourceFile: ts.SourceFile) => ts.SourceFile;
|
|
1
|
+
import * as ts from "typescript";
|
|
2
|
+
export default function (program: ts.Program, pluginOptions: {}): (context: ts.TransformationContext) => (sourceFile: ts.SourceFile) => ts.Node;
|
|
4
3
|
//# sourceMappingURL=MixinTransformer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MixinTransformer.d.ts","sourceRoot":"","sources":["MixinTransformer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"MixinTransformer.d.ts","sourceRoot":"","sources":["MixinTransformer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAiVjC,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,aAC7C,GAAG,qBAAqB,kBAEpB,GAAG,UAAU,aAQlC"}
|