@bikky/compiler 0.0.7 → 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/GlobalTypes.d.ts +25 -27
- 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/Transformers/CompilerInsertions.js +23 -22
- package/Transformers/MacroTransformer.d.ts +2 -2
- package/Transformers/MacroTransformer.d.ts.map +1 -1
- package/Transformers/MacroTransformer.js +282 -272
- package/Transformers/MixinTransformer.d.ts +2 -3
- package/Transformers/MixinTransformer.d.ts.map +1 -1
- package/Transformers/MixinTransformer.js +320 -123
- package/Transformers/{Macros.d.ts → SuperTransformer.d.ts} +3 -3
- package/Transformers/SuperTransformer.d.ts.map +1 -0
- package/Transformers/{SuperTransform.js → SuperTransformer.js} +139 -117
- package/bin/Microsoft.NodejsTools.WebRole.dll +0 -0
- package/obj/Debug/BiscuitCompiler.njsproj.AssemblyReference.cache +0 -0
- package/obj/Debug/BiscuitCompiler.njsproj.FileListAbsolute.txt +3 -3
- 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 -1
- package/ASTHelper.d.ts +0 -74
- package/ASTHelper.d.ts.map +0 -1
- package/Transformers/Macros.d.ts.map +0 -1
- package/Transformers/SuperTransform.d.ts +0 -3
- package/Transformers/SuperTransform.d.ts.map +0 -1
- package/tsconfig.build.tsbuildinfo +0 -1
package/Source/ASTHelper.js
CHANGED
|
@@ -1,344 +1,321 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Printer = exports.logError = exports.SourceFile = exports.ClassDeclaration = exports.AccessExpression = exports.
|
|
4
|
-
const ts = require("typescript");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
exports.
|
|
17
|
-
class NamedExpression {
|
|
18
|
-
constructor(name) {
|
|
19
|
-
this.name = name;
|
|
20
|
-
}
|
|
21
|
-
getName() {
|
|
22
|
-
return this.name;
|
|
23
|
-
}
|
|
24
|
-
rename(name) {
|
|
25
|
-
this.name = name;
|
|
26
|
-
return this;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.NamedExpression = NamedExpression;
|
|
30
|
-
class VariableDeclaration extends NamedExpression {
|
|
31
|
-
constructor() {
|
|
32
|
-
super(...arguments);
|
|
33
|
-
this.modifiers = [];
|
|
34
|
-
}
|
|
35
|
-
setValue(value) {
|
|
36
|
-
this.value = value;
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
addModifier(modifier) {
|
|
40
|
-
if (!this.modifiers) {
|
|
41
|
-
this.modifiers = [];
|
|
42
|
-
}
|
|
43
|
-
this.modifiers.push(modifier);
|
|
44
|
-
return this;
|
|
45
|
-
}
|
|
46
|
-
make(context) {
|
|
47
|
-
return context.factory.createVariableStatement(this.modifiers, context.factory.createVariableDeclarationList([context.factory.createVariableDeclaration(this.name, undefined, undefined, this.value)]));
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.VariableDeclaration = VariableDeclaration;
|
|
51
|
-
(function (VariableDeclaration) {
|
|
52
|
-
function from(variable) {
|
|
53
|
-
var result = new VariableDeclaration(variable.name);
|
|
54
|
-
result.value = variable.initializer;
|
|
55
|
-
result.modifiers = variable.modifiers ? Array.from(variable.modifiers) : undefined;
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
VariableDeclaration.from = from;
|
|
59
|
-
})(VariableDeclaration
|
|
60
|
-
class PropertyDeclaration extends VariableDeclaration {
|
|
61
|
-
//Property declarations can support a few more name types than normal variables.
|
|
62
|
-
constructor(name) {
|
|
63
|
-
super(name);
|
|
64
|
-
}
|
|
65
|
-
make(context) {
|
|
66
|
-
return context.factory.createPropertyDeclaration(
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
exports.PropertyDeclaration = PropertyDeclaration;
|
|
70
|
-
(function (PropertyDeclaration) {
|
|
71
|
-
function from(variable) {
|
|
72
|
-
var result = new PropertyDeclaration(variable.name);
|
|
73
|
-
result.value = variable.initializer;
|
|
74
|
-
result.modifiers = variable.modifiers ? Array.from(variable.modifiers) : undefined;
|
|
75
|
-
return result;
|
|
76
|
-
}
|
|
77
|
-
PropertyDeclaration.from = from;
|
|
78
|
-
})(PropertyDeclaration
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
this.
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
this.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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
|
-
this.
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
return
|
|
181
|
-
}
|
|
182
|
-
else if (ts.
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
return
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
return
|
|
224
|
-
|
|
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
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
return
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
return;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
console.error(`${source.fileName}(${pos.line},${pos.character}):`, error);
|
|
322
|
-
// This can cause the compiler to stop, but we're not using it because the above will allow
|
|
323
|
-
// us to go to the right location in the file. And we probably want to return what we can if
|
|
324
|
-
// there's an error since that's how the rest of typescript works.
|
|
325
|
-
//ts.createThrow(ts.createStringLiteral("Compiler Error."));
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
exports.logError = logError;
|
|
329
|
-
var Printer;
|
|
330
|
-
(function (Printer) {
|
|
331
|
-
var printer = ts.createPrinter();
|
|
332
|
-
function printNode(node, sourceFile) {
|
|
333
|
-
return printer.printNode(ts.EmitHint.Unspecified, node, sourceFile);
|
|
334
|
-
}
|
|
335
|
-
Printer.printNode = printNode;
|
|
336
|
-
function printNodeFirstLine(node, sourceFile) {
|
|
337
|
-
var code = printNode(node, node.getSourceFile());
|
|
338
|
-
//space matches tab.
|
|
339
|
-
code = code.replace(/^ *{? *\r\n?/, "");
|
|
340
|
-
return code.replace(/\r\n.*/gi, "");
|
|
341
|
-
}
|
|
342
|
-
Printer.printNodeFirstLine = printNodeFirstLine;
|
|
343
|
-
})(Printer = exports.Printer || (exports.Printer = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Printer = exports.logError = exports.SourceFile = exports.ClassDeclaration = exports.AccessExpression = exports.PropertyDeclaration = exports.VariableDeclaration = exports.NamedExpression = exports.getNodeText = exports.setContext = void 0;
|
|
4
|
+
const ts = require("typescript");
|
|
5
|
+
let context;
|
|
6
|
+
function setContext(newContext) {
|
|
7
|
+
context = newContext;
|
|
8
|
+
}
|
|
9
|
+
exports.setContext = setContext;
|
|
10
|
+
function getNodeText(node, source) {
|
|
11
|
+
if (node.pos > 0 && node.end < source.end) {
|
|
12
|
+
return node.getText(source);
|
|
13
|
+
}
|
|
14
|
+
return "[text not found]";
|
|
15
|
+
}
|
|
16
|
+
exports.getNodeText = getNodeText;
|
|
17
|
+
class NamedExpression {
|
|
18
|
+
constructor(name) {
|
|
19
|
+
this.name = name;
|
|
20
|
+
}
|
|
21
|
+
getName() {
|
|
22
|
+
return this.name;
|
|
23
|
+
}
|
|
24
|
+
rename(name) {
|
|
25
|
+
this.name = name;
|
|
26
|
+
return this;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.NamedExpression = NamedExpression;
|
|
30
|
+
class VariableDeclaration extends NamedExpression {
|
|
31
|
+
constructor() {
|
|
32
|
+
super(...arguments);
|
|
33
|
+
this.modifiers = [];
|
|
34
|
+
}
|
|
35
|
+
setValue(value) {
|
|
36
|
+
this.value = value;
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
addModifier(modifier) {
|
|
40
|
+
if (!this.modifiers) {
|
|
41
|
+
this.modifiers = [];
|
|
42
|
+
}
|
|
43
|
+
this.modifiers.push(modifier);
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
make(context) {
|
|
47
|
+
return context.factory.createVariableStatement(this.modifiers, context.factory.createVariableDeclarationList([context.factory.createVariableDeclaration(this.name, undefined, undefined, this.value)]));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.VariableDeclaration = VariableDeclaration;
|
|
51
|
+
(function (VariableDeclaration) {
|
|
52
|
+
function from(variable) {
|
|
53
|
+
var result = new VariableDeclaration(variable.name);
|
|
54
|
+
result.value = variable.initializer;
|
|
55
|
+
// result.modifiers = variable.modifiers ? Array.from(variable.modifiers) as ts.Modifier[] : undefined;
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
VariableDeclaration.from = from;
|
|
59
|
+
})(VariableDeclaration || (exports.VariableDeclaration = VariableDeclaration = {}));
|
|
60
|
+
class PropertyDeclaration extends VariableDeclaration {
|
|
61
|
+
//Property declarations can support a few more name types than normal variables.
|
|
62
|
+
constructor(name) {
|
|
63
|
+
super(name);
|
|
64
|
+
}
|
|
65
|
+
make(context) {
|
|
66
|
+
return context.factory.createPropertyDeclaration(this.modifiers, this.name, undefined, undefined, this.value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.PropertyDeclaration = PropertyDeclaration;
|
|
70
|
+
(function (PropertyDeclaration) {
|
|
71
|
+
function from(variable) {
|
|
72
|
+
var result = new PropertyDeclaration(variable.name);
|
|
73
|
+
result.value = variable.initializer;
|
|
74
|
+
// result.modifiers = variable.modifiers ? Array.from(variable.modifiers) as ts.Modifier[] : undefined;
|
|
75
|
+
return result;
|
|
76
|
+
}
|
|
77
|
+
PropertyDeclaration.from = from;
|
|
78
|
+
})(PropertyDeclaration || (exports.PropertyDeclaration = PropertyDeclaration = {}));
|
|
79
|
+
//this[super].function.call(this, arguments);
|
|
80
|
+
class AccessExpression {
|
|
81
|
+
constructor(start) {
|
|
82
|
+
this.start = start;
|
|
83
|
+
}
|
|
84
|
+
access(node) {
|
|
85
|
+
if (!this.chain) {
|
|
86
|
+
if (this.start.kind === ts.SyntaxKind.ThisKeyword) {
|
|
87
|
+
this.chain = context.factory.createElementAccessExpression(this.start, node);
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
this.chain = context.factory.createPropertyAccessExpression(this.start, node);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
this.chain = context.factory.createPropertyAccessExpression(this.chain, node);
|
|
95
|
+
}
|
|
96
|
+
return this;
|
|
97
|
+
}
|
|
98
|
+
make() {
|
|
99
|
+
return this.chain;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
exports.AccessExpression = AccessExpression;
|
|
103
|
+
class ClassDeclaration extends NamedExpression {
|
|
104
|
+
constructor() {
|
|
105
|
+
super(...arguments);
|
|
106
|
+
this.decorators = [];
|
|
107
|
+
this.members = [];
|
|
108
|
+
}
|
|
109
|
+
static from(oldClass) {
|
|
110
|
+
var Class = new ClassDeclaration(oldClass.name);
|
|
111
|
+
Class.original = oldClass;
|
|
112
|
+
if (oldClass.heritageClauses) {
|
|
113
|
+
for (var clause of oldClass.heritageClauses) {
|
|
114
|
+
if (clause.token == ts.SyntaxKind.ExtendsKeyword) {
|
|
115
|
+
Class.extends = clause.types[0].expression;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
Class.members = Array.from(oldClass.members);
|
|
120
|
+
Class.decorators = ClassDeclaration.getDecorators(oldClass);
|
|
121
|
+
return Class;
|
|
122
|
+
}
|
|
123
|
+
static getModifiers(node) {
|
|
124
|
+
var _a, _b;
|
|
125
|
+
return ([...((_b = (_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.filter((m) => m.kind != ts.SyntaxKind.Decorator)) !== null && _b !== void 0 ? _b : [])]);
|
|
126
|
+
}
|
|
127
|
+
static getDecorators(node) {
|
|
128
|
+
var _a, _b;
|
|
129
|
+
return ([...((_b = (_a = node.modifiers) === null || _a === void 0 ? void 0 : _a.filter((m) => m.kind == ts.SyntaxKind.Decorator)) !== null && _b !== void 0 ? _b : [])]);
|
|
130
|
+
}
|
|
131
|
+
addMemberAtStart(member) {
|
|
132
|
+
this.members.unshift(member);
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
addMember(member) {
|
|
136
|
+
this.members.push(member);
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
hasDecorator(identifier) {
|
|
140
|
+
var name = (typeof identifier === "string") ? identifier : identifier.text;
|
|
141
|
+
for (var i = 0; i < this.decorators.length; i++) {
|
|
142
|
+
var decorator = this.decorators[i];
|
|
143
|
+
if (ts.isIdentifier(decorator.expression) && decorator.expression.text == name) {
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
else if (ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() == name) {
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
removeDecorator(identifier) {
|
|
153
|
+
var name = (typeof identifier === "string") ? identifier : identifier.text;
|
|
154
|
+
for (var i = 0; i < this.decorators.length; i++) {
|
|
155
|
+
var decorator = this.decorators[i];
|
|
156
|
+
if (ts.isIdentifier(decorator.expression) && decorator.expression.text == name) {
|
|
157
|
+
this.decorators.splice(i, 1);
|
|
158
|
+
return this;
|
|
159
|
+
}
|
|
160
|
+
else if (ts.isCallExpression(decorator.expression) && decorator.expression.expression.getText() == name) {
|
|
161
|
+
this.decorators.splice(i, 1);
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return this;
|
|
166
|
+
}
|
|
167
|
+
hasExtends() {
|
|
168
|
+
return !!this.extends;
|
|
169
|
+
}
|
|
170
|
+
getExtends() {
|
|
171
|
+
return this.extends;
|
|
172
|
+
}
|
|
173
|
+
setExtends(Extends) {
|
|
174
|
+
this.extends = Extends;
|
|
175
|
+
return this;
|
|
176
|
+
}
|
|
177
|
+
static eachContextualNode(Class, foo, context) {
|
|
178
|
+
var statement = (node) => {
|
|
179
|
+
if (ts.isBlock(node)) {
|
|
180
|
+
return blocks(node);
|
|
181
|
+
}
|
|
182
|
+
else if (ts.isArrowFunction(node)) {
|
|
183
|
+
return members(node);
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
var result = foo(node);
|
|
187
|
+
if (!result) {
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
if (Array.isArray(result)) {
|
|
191
|
+
//TODO: Should probably do something smart here?
|
|
192
|
+
return result;
|
|
193
|
+
}
|
|
194
|
+
return ts.visitEachChild(result, statement, context);
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
var blocks = (node) => {
|
|
198
|
+
if (ts.isBlock(node)) {
|
|
199
|
+
return ts.visitEachChild(node, statement, context);
|
|
200
|
+
}
|
|
201
|
+
return node;
|
|
202
|
+
};
|
|
203
|
+
var members = (node) => {
|
|
204
|
+
if (ts.isMethodDeclaration(node)) {
|
|
205
|
+
return ts.visitEachChild(node, blocks, context);
|
|
206
|
+
}
|
|
207
|
+
else {
|
|
208
|
+
return node;
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
return ts.visitEachChild(Class, members, context);
|
|
212
|
+
}
|
|
213
|
+
update(context) {
|
|
214
|
+
if (!this.original) {
|
|
215
|
+
throw new Error("Cannot update class that doesn't exist!");
|
|
216
|
+
}
|
|
217
|
+
var replaceNodeArrays = (nodes, visitor, test, start, count) => {
|
|
218
|
+
if (nodes == this.original.members) {
|
|
219
|
+
return context.factory.createNodeArray([...this.decorators, ...ClassDeclaration.getModifiers(this.original)]);
|
|
220
|
+
// return context.factory.createNodeArray(this.decorators);
|
|
221
|
+
}
|
|
222
|
+
// if (nodes == this.original!.members) {
|
|
223
|
+
// return context.factory.createNodeArray(this.members);
|
|
224
|
+
// }
|
|
225
|
+
if (nodes) {
|
|
226
|
+
var changedArray = false;
|
|
227
|
+
var newArray = [];
|
|
228
|
+
for (var node of nodes) {
|
|
229
|
+
var newNode = ts.visitNode(node, visitor, test);
|
|
230
|
+
newArray.push(newNode);
|
|
231
|
+
if (node != newNode) {
|
|
232
|
+
changedArray = true;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
if (changedArray) {
|
|
236
|
+
return context.factory.createNodeArray(newArray);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
return nodes;
|
|
240
|
+
};
|
|
241
|
+
var replaceExports = (node) => {
|
|
242
|
+
if (node.kind == ts.SyntaxKind.HeritageClause && node.token == ts.SyntaxKind.ExtendsKeyword) {
|
|
243
|
+
//I hope this works...
|
|
244
|
+
var result = context.factory.createHeritageClause(ts.SyntaxKind.ExtendsKeyword, [ts.factory.createExpressionWithTypeArguments(this.extends, undefined)]);
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
247
|
+
return node;
|
|
248
|
+
};
|
|
249
|
+
//first parameter is the class, second is the thing to edit individual nodes, third is the context
|
|
250
|
+
// last parameter is the thing to edit entire node arrays.
|
|
251
|
+
return ts.visitEachChild(this.original, replaceExports, context, replaceNodeArrays);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
exports.ClassDeclaration = ClassDeclaration;
|
|
255
|
+
class SourceFile {
|
|
256
|
+
constructor() {
|
|
257
|
+
this.statements = [];
|
|
258
|
+
}
|
|
259
|
+
static from(oldfile) {
|
|
260
|
+
var file = new SourceFile;
|
|
261
|
+
file.statements = Array.from(oldfile.statements);
|
|
262
|
+
file.original = oldfile;
|
|
263
|
+
return file;
|
|
264
|
+
}
|
|
265
|
+
replaceNode(oldNode, newNode) {
|
|
266
|
+
var index = this.statements.indexOf(oldNode);
|
|
267
|
+
if (index < 0) {
|
|
268
|
+
throw new Error("Tried to replace a node that doesn't exist in file");
|
|
269
|
+
}
|
|
270
|
+
this.statements[index] = newNode;
|
|
271
|
+
return this;
|
|
272
|
+
}
|
|
273
|
+
insertUnderImports(node) {
|
|
274
|
+
for (var i = 0; i < this.statements.length; i++) {
|
|
275
|
+
if (this.statements[i].kind !== ts.SyntaxKind.ImportDeclaration) {
|
|
276
|
+
this.statements.splice(i, 0, node);
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return this;
|
|
281
|
+
}
|
|
282
|
+
update(context) {
|
|
283
|
+
if (!this.original) {
|
|
284
|
+
throw new Error("Cannot update file that doesn't exist!");
|
|
285
|
+
}
|
|
286
|
+
return ts.factory.updateSourceFile(this.original, this.statements);
|
|
287
|
+
;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
exports.SourceFile = SourceFile;
|
|
291
|
+
function logError(node, error) {
|
|
292
|
+
if (!node || !node.getSourceFile()) {
|
|
293
|
+
console.error("Why are we here?");
|
|
294
|
+
return;
|
|
295
|
+
}
|
|
296
|
+
var source = ts.isSourceFile(node) ? node : node.getSourceFile();
|
|
297
|
+
var pos = source.getLineAndCharacterOfPosition(node.pos);
|
|
298
|
+
console.error(`${source.fileName}(${pos.line},${pos.character}):`, error);
|
|
299
|
+
// This can cause the compiler to stop, but we're not using it because the above will allow
|
|
300
|
+
// us to go to the right location in the file. And we probably want to return what we can if
|
|
301
|
+
// there's an error since that's how the rest of typescript works.
|
|
302
|
+
//ts.createThrow(ts.createStringLiteral("Compiler Error."));
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
exports.logError = logError;
|
|
306
|
+
var Printer;
|
|
307
|
+
(function (Printer) {
|
|
308
|
+
var printer = ts.createPrinter();
|
|
309
|
+
function printNode(node, sourceFile) {
|
|
310
|
+
return printer.printNode(ts.EmitHint.Unspecified, node, sourceFile);
|
|
311
|
+
}
|
|
312
|
+
Printer.printNode = printNode;
|
|
313
|
+
function printNodeFirstLine(node, sourceFile) {
|
|
314
|
+
var code = printNode(node, node.getSourceFile());
|
|
315
|
+
//space matches tab.
|
|
316
|
+
code = code.replace(/^ *{? *\r\n?/, "");
|
|
317
|
+
return code.replace(/\r\n.*/gi, "");
|
|
318
|
+
}
|
|
319
|
+
Printer.printNodeFirstLine = printNodeFirstLine;
|
|
320
|
+
})(Printer || (exports.Printer = Printer = {}));
|
|
344
321
|
//# sourceMappingURL=ASTHelper.js.map
|