@bikky/compiler 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/ASTHelper.d.ts +74 -0
  2. package/ASTHelper.d.ts.map +1 -0
  3. package/BiscuitCompiler.njsproj +89 -0
  4. package/BiscuitCompiler.njsproj.user +7 -0
  5. package/Libraries/BiscuitLibraries.d.ts +3 -0
  6. package/Libraries/BiscuitLibraries.d.ts.map +1 -0
  7. package/Libraries/BiscuitLibraries.js +3 -0
  8. package/Libraries/BiscuitLibraries.js.map +1 -0
  9. package/Libraries/BiscuitLibraries.ts +2 -0
  10. package/Libraries/GlobalTypes.d.ts +57 -0
  11. package/Libraries/MixinCode.d.ts +14 -0
  12. package/Libraries/MixinCode.d.ts.map +1 -0
  13. package/Libraries/MixinCode.js +109 -0
  14. package/Libraries/MixinCode.js.map +1 -0
  15. package/Libraries/MixinCode.ts +125 -0
  16. package/Libraries/package-lock.json +5 -0
  17. package/Source/ASTHelper.js +344 -0
  18. package/Source/ASTHelper.js.map +1 -0
  19. package/Source/ASTHelper.ts +373 -0
  20. package/Source/TSPatchTypes.d.ts +17 -0
  21. package/Transformers/CompilerInsertions.ts +21 -0
  22. package/Transformers/MacroTransformer.js +273 -0
  23. package/Transformers/MacroTransformer.js.map +1 -0
  24. package/Transformers/MacroTransformer.ts +304 -0
  25. package/Transformers/Macros.d.ts +3 -0
  26. package/Transformers/Macros.d.ts.map +1 -0
  27. package/Transformers/MixinTransformer.js +124 -0
  28. package/Transformers/MixinTransformer.js.map +1 -0
  29. package/Transformers/MixinTransformer.ts +151 -0
  30. package/Transformers/SuperTransform.d.ts +3 -0
  31. package/Transformers/SuperTransform.d.ts.map +1 -0
  32. package/Transformers/SuperTransform.js +117 -0
  33. package/Transformers/SuperTransform.js.map +1 -0
  34. package/Transformers/SuperTransform.ts +129 -0
  35. package/bin/Microsoft.NodejsTools.WebRole.dll +0 -0
  36. package/obj/Debug/BiscuitCompiler.njsproj.AssemblyReference.cache +0 -0
  37. package/obj/Debug/BiscuitCompiler.njsproj.CoreCompileInputs.cache +1 -0
  38. package/obj/Debug/BiscuitCompiler.njsproj.FileListAbsolute.txt +3 -0
  39. package/package.json +23 -0
  40. package/tsconfig.build.json +20 -0
  41. package/tsconfig.json +26 -0
  42. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Macros.js","sourceRoot":"","sources":["Macros.ts"],"names":[],"mappings":";;AACA,sBAAsB;AACtB,iCAAiC;AAEjC,+CAA+C;AAC/C,kCAAkC;AAClC,iBAAiB;AACjB,qEAAqE;AACrE,+DAA+D;AAC/D,8DAA8D;AAC9D,MAAM,gBAAgB;IAIrB;QAHA,qBAAgB,GAAG,IAAI,GAAG,EAAoD,CAAC;QAC/E,oBAAe,GAAW,OAAO,CAAC;QAoBlC,YAAO,GAAG,EAAE,CAAC,aAAa,EAAE,CAAC;IAjB7B,CAAC;IAED,QAAQ,CAAC,IAAa,EAAE,KAAa;QACpC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,EAAE;YACnC,OAAO,CAAC,KAAK,CAAC,kBAAkB,CAAC,CAAC;YAClC,OAAO;SACP;QACD,IAAI,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;QACjE,IAAI,GAAG,GAAG,MAAM,CAAC,6BAA6B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzD,OAAO,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,QAAQ,IAAI,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,SAAS,IAAI,EAAE,KAAK,CAAC,CAAC;QAC1E,2FAA2F;QAC3F,4FAA4F;QAC5F,kEAAkE;QAClE,4DAA4D;QAC5D,OAAO;IACR,CAAC;IAID,SAAS,CAAC,IAAa,EAAE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C,WAAW,CAAC,OAAO,GAAG,OAAO,CAAC;QAC9B,OAAO,CAAC,UAAyB,EAAE,EAAE;YACpC,OAAO,WAAW,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;QACpD,CAAC,CAAA;IACF,CAAC,CAAA;AACF,CAAC;AAPD,4BAOC"}
@@ -0,0 +1,304 @@
1
+ 
2
+ // transformer1-module
3
+ import * as ts from "typescript";
4
+
5
+ //This class should be able to do a few things:
6
+ // Import macros from other files.
7
+ // Copy macro AST
8
+ // Insert macro AST to the destination location (inlining the macro).
9
+ // Resolve variable names to the name of the provided variable.
10
+ // Not require special (complex) syntax in the macro creation.
11
+ class MacroTransformer {
12
+ RegisteredMacros = new Map<string, ts.FunctionExpression | ts.ArrowFunction>();
13
+ DeclarationName: string = "MACRO";
14
+ context!: ts.TransformationContext;
15
+ constructor() {
16
+ }
17
+
18
+ logError(node: ts.Node, error: string): undefined {
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
+
33
+ printer = ts.createPrinter();
34
+
35
+ printNode(node: ts.Node, sourceFile: ts.SourceFile) {
36
+ return this.printer.printNode(ts.EmitHint.Unspecified, node, sourceFile);
37
+ }
38
+
39
+ printNodeFirstLine(node: ts.Node, sourceFile: ts.SourceFile) {
40
+ var code = this.printNode(node, node.getSourceFile());
41
+ //space matches tab.
42
+ code = code.replace(/^ *{? *\r\n?/, "");
43
+ return code.replace(/\r\n.*/gi, "");
44
+
45
+ }
46
+
47
+ CrawlExpressionTree(node: ts.SourceFile) {
48
+ //Run twice, we hoist macro declarations.
49
+ node = ts.visitNode(node, this.FindMacroDeclaration.bind(this));
50
+ return ts.visitNode(node, this.SearchForMacroUseStatement.bind(this));
51
+ }
52
+
53
+ FindMacroDeclaration(node: ts.Node): ts.Node {
54
+ if (ts.isVariableStatement(node)) {
55
+ //This statement has potential to contain a MACRO declaration.
56
+ //Support for comma separated declarations.
57
+ for (var declaration of node.declarationList.declarations) {
58
+ //If this variable is initialised, and it's initialised with a function call check to see
59
+ // if the function's name is MACRO (which is our custom buzzword).
60
+ if (
61
+ declaration.initializer
62
+ && ts.isCallExpression(declaration.initializer)
63
+ && ts.isIdentifier(declaration.initializer.expression)
64
+ && declaration.initializer.expression.text === this.DeclarationName
65
+ ) {
66
+ //This is the name of the variable that the macro's being assigned to.
67
+ var name = declaration.name;
68
+ //Macros must be identifiers (normal variables, not symbols and not array unwraps).
69
+ if (!ts.isIdentifier(name)) {
70
+ this.logError(declaration, "Macros must be declared as using normal identifiers, symbols and array unwraps are unsupported.");
71
+ return node;
72
+ }
73
+ if (declaration.initializer.arguments.length == 0) {
74
+ this.logError(declaration, "When declaring a macro a function must be supplied as the first parameter.");
75
+ return node;
76
+ }
77
+ if (declaration.initializer.arguments.length > 1) {
78
+ this.logError(declaration, "Macro declaration only takes one parameter.");
79
+ return node;
80
+ }
81
+ var value = declaration.initializer.arguments[0];
82
+ this.RegisteredMacros.set(name.text, <ts.FunctionExpression>value);
83
+ console.log("Registering macro", name.text);
84
+ //Now that we've stored the macro code for later use, we need to delete it from the file.
85
+ //Todo: this creates an unnecessary semicolon.
86
+ return ts.createEmptyStatement();
87
+ }
88
+ }
89
+ }
90
+ node = ts.visitEachChild(node, this.FindMacroDeclaration.bind(this), this.context) || node;
91
+ return node;
92
+ }
93
+
94
+ SearchForMacroUseStatement(node: ts.Node): ts.Node {
95
+ if (ts.isBlock(node) || ts.isSourceFile(node) || ts.isCaseBlock(node)) {
96
+ //console.log("Block:", this.printNodeFirstLine(node, node.getSourceFile()));
97
+ return ts.visitEachChild(node, <any>this.FindMacroUsage.bind(this), this.context);
98
+ }
99
+ else if (ts.isFunctionDeclaration(node)) {
100
+ var body = ts.visitEachChild(node.body, <any>this.FindMacroUsage.bind(this), this.context)!;
101
+ let foo = ts.updateFunctionDeclaration(node, node.decorators, node.modifiers, node.asteriskToken, node.name, node.typeParameters, node.parameters, node.type, body);
102
+ //if (foo.name) {
103
+ // console.log("Function:", this.printNode(foo.name, node.getSourceFile()));
104
+ //}
105
+ return foo;
106
+ }
107
+ else if (ts.isMethodDeclaration(node)) {
108
+ var body = ts.visitEachChild(node.body, <any>this.FindMacroUsage.bind(this), this.context)!;
109
+ let foo = ts.updateMethod(node, node.decorators, node.modifiers, node.asteriskToken, node.name, node.questionToken, node.typeParameters, node.parameters, node.type, body);
110
+ //console.log("Method:", this.printNode(foo.name, node.getSourceFile()));
111
+ return foo;
112
+ }
113
+ else if (ts.isIfStatement(node)) {
114
+ //console.log("IF:", this.printNode(node, node.getSourceFile()));
115
+ var thenS = ts.visitNode(node.thenStatement, this.SearchForMacroUseStatement.bind(this));
116
+ var elseS = node.elseStatement ? ts.visitNode(node.elseStatement, this.SearchForMacroUseStatement.bind(this)) : undefined;
117
+ return ts.updateIf(node, node.expression, thenS, elseS);
118
+ }
119
+ else {
120
+ return ts.visitEachChild(node, this.SearchForMacroUseStatement.bind(this), this.context);
121
+ }
122
+ }
123
+
124
+ isBlocky(node: ts.Node) {
125
+ return ts.isMethodDeclaration(node) || ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node) || ts.isInterfaceDeclaration(node) || ts.isIfStatement(node);
126
+ }
127
+
128
+ FindMacroUsage(node: ts.Statement): ts.Node {
129
+ if (this.isBlocky(node)) {
130
+ return ts.visitNode(node, this.SearchForMacroUseStatement.bind(this));
131
+ }
132
+ var MACARONY = false;
133
+ var context: ts.Expression | undefined = undefined;
134
+ var call: ts.CallExpression | undefined = undefined;
135
+ //How to do this:
136
+ //Recurse through statement to see if it has a macro expression.
137
+ function SpyMacro(this: MacroTransformer, node: ts.Node): ts.Node {
138
+ //If there's a new block in here we bail, otherwise we'd put the macro scoping in the wrong scoping level.
139
+ if (ts.isBlock(node) || ts.isCaseBlock(node) || this.isBlocky(node)) {
140
+ return ts.visitNode(node, this.SearchForMacroUseStatement.bind(this));
141
+ }
142
+
143
+ if (
144
+ ts.isCallExpression(node)
145
+ && ts.isPropertyAccessExpression(node.expression)
146
+ && this.RegisteredMacros.has(node.expression.name.text)
147
+ ) {
148
+ MACARONY = true;
149
+ context = node.expression.expression;
150
+ call = node;
151
+ //console.log("FOUND MACRO USAGE!", node.expression.name.text);
152
+ }
153
+ if (
154
+ ts.isCallExpression(node) &&
155
+ ts.isIdentifier(node.expression) &&
156
+ this.RegisteredMacros.has(node.expression.text)
157
+ ) {
158
+ MACARONY = true;
159
+ call = node;
160
+ }
161
+ return ts.visitEachChild(node, SpyMacro.bind(this), this.context);
162
+ }
163
+
164
+ ts.visitEachChild(node, SpyMacro.bind(this), this.context);
165
+
166
+ if (MACARONY) {
167
+ return this.InsertMacro(node, context, call!);
168
+ }
169
+ else {
170
+ return node;
171
+ }
172
+ }
173
+
174
+ //"context" is the thing before the dot when the macro is called, might be undefined.
175
+ //"context" is present if you call the macro like so: context.MACRO().
176
+ //Call expression is the node that represents the MACRO() part of the statement.
177
+ InsertMacro(statement: ts.Node, context: ts.Expression | undefined, macroCall: ts.CallExpression): ts.Block | ts.Statement {
178
+ var block = <ts.Statement[]>[];
179
+ var macro: ts.FunctionExpression | ts.ArrowFunction | undefined;
180
+ var macroName: string | undefined;
181
+ if (ts.isIdentifier(macroCall.expression)) {
182
+ macroName = macroCall.expression.text;
183
+ }
184
+ else if (ts.isPropertyAccessExpression(macroCall.expression)) {
185
+ macroName = macroCall.expression.name.text;
186
+ }
187
+ if (macroName) {
188
+ macro = this.RegisteredMacros.get(macroName);
189
+ }
190
+ if (!macroName || !macro) {
191
+ this.logError(statement, "Unspecified error in macro expansion.");
192
+ return <any>statement;
193
+ }
194
+
195
+ //console.log("Putting", macroName, "in to place:", statement.getText());
196
+
197
+ //Map macro parameters to the arguments (replace all instances of the parameter with the argument's expression).
198
+ //Replacing identifiers with nodes because it can be an unnamed expression (lambda or 3 + 5).
199
+ var parameters = new Map<string, ts.Node>();
200
+ var parameterOffset = 0;
201
+
202
+ for (var i = 0; i + parameterOffset < macro.parameters.length; i++) {
203
+ var parameter = macro.parameters[i + parameterOffset];
204
+ //Detect and skip "this" parameter
205
+ if (ts.isParameter(parameter) && parameter.name.getText() == "this") {
206
+ parameterOffset = 1;
207
+ //If "this" is the only parameter then don't do the rest of the loop.
208
+ if (!(i + parameterOffset < macro.parameters.length)) {
209
+ break;
210
+ }
211
+ parameter = macro.parameters[i + parameterOffset];
212
+ }
213
+ var argument = macroCall.arguments[i];
214
+ if (typeof argument === "undefined") {
215
+ if (typeof parameter.questionToken === "undefined") {
216
+ this.logError(parameter, `Failure to specify non-optional argument to macro ${macroName}.`);
217
+ return <any>statement;
218
+ //throw new Error("Failure to specify non-optional argument to macro.");
219
+ }
220
+ else {
221
+ //Probably use this instead, because it's garenteed to be unique.
222
+ //ts.getGeneratedNameForNode
223
+ var name = parameter.name.getText();
224
+ //This is "let param;" for optional variables that weren't done.
225
+ var ver = ts.createVariableStatement([], ts.createVariableDeclarationList([ts.createVariableDeclaration(name)], ts.NodeFlags.Let));
226
+ block.push(ver);
227
+ parameters.set(name, ts.createIdentifier(name));
228
+ }
229
+ }
230
+ else {
231
+ parameters.set(parameter.name.getText(), argument);
232
+ }
233
+ }
234
+ //Macros can be multiline!
235
+ //So we need to insert the macro into the appropriate place in the block, and then duplicate expression
236
+ // wherever return shows up in the macro (or on the next line if it doesn't? or maybe error...).
237
+
238
+ var body = <ts.Block>(macro.body);
239
+
240
+ //Put the macro's result in the calling expression in place of the macro call.
241
+ var PutResultInExpression = (result: ts.ReturnStatement) => {
242
+ return function IterateResult(this: MacroTransformer, node: ts.Node): ts.Node {
243
+
244
+ if (
245
+ ts.isCallExpression(node)
246
+ && ts.isPropertyAccessExpression(node.expression)
247
+ && node.expression.name.text == macroName
248
+ || ts.isCallExpression(node)
249
+ && ts.isIdentifier(node.expression)
250
+ && node.expression.text == macroName
251
+ ) {
252
+ //replace with stuff after return statement.
253
+ return ts.visitNode(result.expression, ReplaceStuffInMacro.bind(this))!;
254
+ }
255
+ return ts.visitEachChild(node, IterateResult.bind(this), this.context);
256
+ }.bind(this);
257
+ }
258
+ function CopyAsIs(this: MacroTransformer, node: ts.Node): ts.Node {
259
+ return ts.visitEachChild(node, CopyAsIs.bind(this), this.context);
260
+ }
261
+
262
+ function ReplaceStuffInMacro(this: MacroTransformer, node: ts.Node): ts.Node {
263
+ if (ts.isReturnStatement(node)) {
264
+ return ts.visitEachChild(statement, PutResultInExpression(node), this.context);
265
+ }
266
+ if (ts.isPropertyAccessExpression(node) && (node.expression.kind == ts.SyntaxKind.ThisType || node.expression.kind == ts.SyntaxKind.ThisKeyword)) {
267
+ if (!context) {
268
+ 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.");
269
+ return node;
270
+ }
271
+ //If this is referenced then replace it with the stuff before the . when the macro is called.
272
+ return ts.createPropertyAccess(context, node.name.text);
273
+ //return ts.visitEachChild(context, Inplace.bind(this), this.context);
274
+ }
275
+ if (ts.isIdentifier(node) && parameters.has(node.text)) {
276
+ //If a parameter is referenced replace it with the argument provided in macro use.
277
+ return ts.visitNode(parameters.get(node.text)!, CopyAsIs.bind(this));
278
+ }
279
+ return ts.visitEachChild(node, ReplaceStuffInMacro.bind(this), this.context);
280
+ }
281
+ //unroll macro and then replace all return statements with expression.
282
+ for (var expression of body.statements) {
283
+ block.push(
284
+ ts.visitNode(expression, ReplaceStuffInMacro.bind(this))
285
+ );
286
+ }
287
+ var result = ts.createBlock(block);
288
+ return result;
289
+ }
290
+ }
291
+
292
+ //Initiating the transformer here is a hodge-podge solution to resolving transforms supplied in other files.
293
+ // We probably need to do a proper solution that involves aliasing the macro's name to whatever the import is called, and removing
294
+ // 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
295
+ // do that.
296
+ var transformer = new MacroTransformer();
297
+ export default function (program: ts.Program, pluginOptions: {}) {
298
+ return (context: ts.TransformationContext) => {
299
+ transformer.context = context;
300
+ return (sourceFile: ts.SourceFile) => {
301
+ return transformer.CrawlExpressionTree(sourceFile);
302
+ }
303
+ }
304
+ }
@@ -0,0 +1,3 @@
1
+ import * as ts from "typescript";
2
+ export default function (program: ts.Program, pluginOptions: {}): (context: ts.TransformationContext) => (sourceFile: ts.SourceFile) => ts.SourceFile;
3
+ //# sourceMappingURL=Macros.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Macros.d.ts","sourceRoot":"","sources":["Macros.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAsSjC,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,aAC7C,GAAG,qBAAqB,kBAEpB,GAAG,UAAU,mBAIlC"}
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const ts = require("typescript");
4
+ const ASTHelper_js_1 = require("../../ASTHelper.js");
5
+ //This transform replaces super. usage with this.parent.
6
+ // - this is to make sure macros work properly.
7
+ var mixMakerName = "Mixable";
8
+ var MixinMagicNumbers = {
9
+ decoratorEditExport: ts.SyntaxKind.ExtendsKeyword,
10
+ identifier: ts.SyntaxKind.Identifier,
11
+ mixinDescriptionKind: ts.SyntaxKind.PropertySignature,
12
+ };
13
+ /**
14
+ * This is a multi-process thing:
15
+ * 2) Remove the @mixin decorator.
16
+ * 3) Add var Super = Symbol("super") at the top of the file.
17
+ * 4) Add this[super] = prototype and static Super = Super to class.
18
+ * 5) Change all super.function references to this[super].function.
19
+ */
20
+ function MixClass(context, RawClass, symbolName) {
21
+ //Add symbol definition to the top of the file.
22
+ var computedSymbolName = context.factory.createComputedPropertyName(symbolName);
23
+ var Class = ASTHelper_js_1.ClassDeclaration.from(RawClass);
24
+ if (!Class.hasExtends()) {
25
+ ASTHelper_js_1.logError(RawClass, "Mixins need to extend from something");
26
+ return RawClass;
27
+ }
28
+ //Remove Decorator.
29
+ Class.removeDecorator("mixin");
30
+ //Store the symbol statically on the class so we can access it in the mixin maker.
31
+ var declareStaticSymbol = (new ASTHelper_js_1.PropertyDeclaration(ASTHelper_js_1.Identifier(context, "Super"))
32
+ .addModifier(ASTHelper_js_1.StaticModifier(context))
33
+ .setValue(symbolName));
34
+ Class.addMemberAtStart(declareStaticSymbol.make(context));
35
+ //Can't add prototype manually because it will override the prototype provided by MixinCode.ts (because the constructor
36
+ // runs after the mixin code, and class variables are assigned in the constructor).
37
+ //var declareSuperPrototype = (new PropertyDeclaration(computedSymbolName))
38
+ // .setValue(Class.getExtends()!);
39
+ //Class.addMemberAtStart(declareSuperPrototype.make(context));
40
+ Class.setExtends((new ASTHelper_js_1.CallExpression(ASTHelper_js_1.Identifier(context, mixMakerName))
41
+ .addArgument(Class.getExtends())).make(context));
42
+ var newRawClass = Class.update(context);
43
+ newRawClass = ts.visitNode(newRawClass, ReplaceSuper(Class.getName(), symbolName, context));
44
+ return newRawClass;
45
+ }
46
+ //Change all references in member functions of super. to this[Super].
47
+ function ReplaceSuper(classID, computedSuperID, context) {
48
+ var className = classID.text;
49
+ return (node) => {
50
+ return ASTHelper_js_1.ClassDeclaration.eachContextualNode(node, (node) => {
51
+ //check to see if node chain represents this.method().
52
+ if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.expression.kind === ts.SyntaxKind.SuperKeyword) {
53
+ var f = context.factory;
54
+ var access = (new ASTHelper_js_1.AccessExpression(context)).this().access(computedSuperID)
55
+ /*.access(f.createIdentifier("prototype"))*/ .access(f.createIdentifier(node.expression.name.text)).access((new ASTHelper_js_1.CallExpression(f.createIdentifier("call")))
56
+ .addArgument(f.createThis())
57
+ .addArgument(...Array.from(node.arguments)).make(context));
58
+ //this[super].prototype.method.call(this, arguments);
59
+ return access.make();
60
+ }
61
+ else {
62
+ return node;
63
+ }
64
+ }, context);
65
+ };
66
+ }
67
+ /**
68
+ *
69
+ * Searching stuff!
70
+ * 1) Find classes defined with the @mixin decorator.
71
+ *
72
+ */
73
+ class MixinSource {
74
+ constructor(sourceFile) {
75
+ this.sourceFile = sourceFile;
76
+ }
77
+ //Look for a class with the @mixin decorator!
78
+ update(context) {
79
+ var _a;
80
+ this.context = context;
81
+ var declarations = [];
82
+ var crawl = (node) => {
83
+ if (node.kind === ts.SyntaxKind.ClassDeclaration) {
84
+ var Class = ASTHelper_js_1.ClassDeclaration.from(node);
85
+ if (Class.hasDecorator("mixin")) {
86
+ var name = Class.getName().text;
87
+ var symbolName = ASTHelper_js_1.Identifier(context, "Super_" + declarations.length);
88
+ var declareSuperSymbol = (new ASTHelper_js_1.VariableDeclaration(symbolName))
89
+ .setValue((new ASTHelper_js_1.CallExpression(ASTHelper_js_1.Identifier(context, "Symbol")))
90
+ .addArgument(ASTHelper_js_1.StringLiteral(context, "super_" + name))
91
+ .make(context)).make(context);
92
+ declarations.push(declareSuperSymbol);
93
+ var test = MixClass(this.context, node, symbolName);
94
+ return test;
95
+ }
96
+ }
97
+ return ts.visitEachChild(node, crawl, this.context);
98
+ };
99
+ var source = ts.visitNode(this.sourceFile, crawl);
100
+ var file = ASTHelper_js_1.SourceFile.from(source);
101
+ for (var declaration of declarations) {
102
+ file.insertUnderImports(declaration);
103
+ }
104
+ var result = file.update(context);
105
+ this.sourceFile = result;
106
+ if (declarations.length > 0) {
107
+ console.log("Updated file", (_a = file.original) === null || _a === void 0 ? void 0 : _a.fileName, "with mixin data");
108
+ // console.log("~~~~~~~~~~~");
109
+ // console.log(Printer.printNode(result, this.sourceFile));
110
+ // console.log("~~~~~~~~~~~");
111
+ }
112
+ return result;
113
+ }
114
+ }
115
+ function default_1(program, pluginOptions) {
116
+ return (context) => {
117
+ return (sourceFile) => {
118
+ return (new MixinSource(sourceFile)).update(context);
119
+ //return sourceFile;
120
+ };
121
+ };
122
+ }
123
+ exports.default = default_1;
124
+ //# sourceMappingURL=MixinTransformer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MixinTransformer.js","sourceRoot":"","sources":["MixinTransformer.ts"],"names":[],"mappings":";;AACA,iCAAiC;AACjC,qDAA4M;AAE5M,yDAAyD;AACzD,+CAA+C;AAE/C,IAAI,YAAY,GAAG,SAAS,CAAC;AAG7B,IAAI,iBAAiB,GAAG;IACvB,mBAAmB,EAAE,EAAE,CAAC,UAAU,CAAC,cAAc;IACjD,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,UAAU;IACpC,oBAAoB,EAAE,EAAE,CAAC,UAAU,CAAC,iBAAiB;CACrD,CAAA;AAED;;;;;;GAMG;AACH,SAAS,QAAQ,CAAC,OAAiC,EAAE,QAA6B,EAAE,UAAyB;IAC5G,+CAA+C;IAC/C,IAAI,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC,0BAA0B,CAAC,UAAU,CAAC,CAAC;IAEhF,IAAI,KAAK,GAAG,+BAAgB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE;QACxB,uBAAQ,CAAC,QAAQ,EAAE,sCAAsC,CAAC,CAAC;QAC3D,OAAO,QAAQ,CAAC;KAChB;IACD,mBAAmB;IACnB,KAAK,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;IAE/B,kFAAkF;IAClF,IAAI,mBAAmB,GAAG,CAAC,IAAI,kCAAmB,CAAC,yBAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;SAC9E,WAAW,CAAC,6BAAc,CAAC,OAAO,CAAC,CAAC;SACpC,QAAQ,CAAC,UAAU,CAAC,CACrB,CAAC;IACF,KAAK,CAAC,gBAAgB,CAAC,mBAAmB,CAAC,IAAI,CAAC,OAAO,CAAC,CA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CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YACrD,oBAAoB;QACrB,CAAC,CAAA;IACF,CAAC,CAAA;AACF,CAAC;AAPD,4BAOC"}
@@ -0,0 +1,151 @@
1
+ 
2
+ import * as ts from "typescript";
3
+ import { VariableDeclaration, CallExpression, PropertyDeclaration, StaticModifier, Identifier, ClassDeclaration, SourceFile, logError, StringLiteral, Printer, AccessExpression } from "../Source/ASTHelper.js";
4
+
5
+ //This transform replaces super. usage with this.parent.
6
+ // - this is to make sure macros work properly.
7
+
8
+ var mixMakerName = "Mixable";
9
+
10
+
11
+ var MixinMagicNumbers = {
12
+ decoratorEditExport: ts.SyntaxKind.ExtendsKeyword,
13
+ identifier: ts.SyntaxKind.Identifier,
14
+ mixinDescriptionKind: ts.SyntaxKind.PropertySignature,
15
+ }
16
+
17
+ /**
18
+ * This is a multi-process thing:
19
+ * 2) Remove the @mixin decorator.
20
+ * 3) Add var Super = Symbol("super") at the top of the file.
21
+ * 4) Add this[super] = prototype and static Super = Super to class.
22
+ * 5) Change all super.function references to this[super].function.
23
+ */
24
+ function MixClass(context: ts.TransformationContext, RawClass: ts.ClassDeclaration, symbolName: ts.Identifier): ts.ClassDeclaration {
25
+ //Add symbol definition to the top of the file.
26
+ var computedSymbolName = context.factory.createComputedPropertyName(symbolName);
27
+
28
+ var Class = ClassDeclaration.from(RawClass);
29
+ if (!Class.hasExtends()) {
30
+ logError(RawClass, "Mixins need to extend from something");
31
+ return RawClass;
32
+ }
33
+ //Remove Decorator.
34
+ Class.removeDecorator("mixin");
35
+
36
+ //Store the symbol statically on the class so we can access it in the mixin maker.
37
+ var declareStaticSymbol = (new PropertyDeclaration(Identifier(context, "Super"))
38
+ .addModifier(StaticModifier(context))
39
+ .setValue(symbolName)
40
+ );
41
+ Class.addMemberAtStart(declareStaticSymbol.make(context));
42
+
43
+ //Can't add prototype manually because it will override the prototype provided by MixinCode.ts (because the constructor
44
+ // runs after the mixin code, and class variables are assigned in the constructor).
45
+ //var declareSuperPrototype = (new PropertyDeclaration(computedSymbolName))
46
+ // .setValue(Class.getExtends()!);
47
+ //Class.addMemberAtStart(declareSuperPrototype.make(context));
48
+
49
+ Class.setExtends((
50
+ new CallExpression(Identifier(context, mixMakerName))
51
+ .addArgument(Class.getExtends()!)
52
+ ).make(context));
53
+
54
+ var newRawClass = Class.update(context)!;
55
+
56
+ newRawClass = ts.visitNode(newRawClass, ReplaceSuper(Class.getName(), symbolName, context));
57
+
58
+ return newRawClass;
59
+ }
60
+
61
+ //Change all references in member functions of super. to this[Super].
62
+ function ReplaceSuper(classID: ts.Identifier, computedSuperID: ts.Identifier, context: ts.TransformationContext) {
63
+ var className = classID.text;
64
+ return (node: ts.Node) => {
65
+ return ClassDeclaration.eachContextualNode(<ts.ClassDeclaration>node, (node: ts.Node) => {
66
+ //check to see if node chain represents this.method().
67
+ if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && node.expression.expression.kind === ts.SyntaxKind.SuperKeyword) {
68
+ var f = context.factory;
69
+ var access = (new AccessExpression(context)).this().access(computedSuperID)
70
+ /*.access(f.createIdentifier("prototype"))*/.access(f.createIdentifier(node.expression.name.text)).access(
71
+ (new CallExpression(f.createIdentifier("call")))
72
+ .addArgument(f.createThis())
73
+ .addArgument(...Array.from(node.arguments)
74
+ ).make(context)
75
+ );
76
+ //this[super].prototype.method.call(this, arguments);
77
+ return access.make();
78
+ }
79
+ else {
80
+ return node;
81
+ }
82
+ }, context);
83
+ }
84
+ }
85
+
86
+ /**
87
+ *
88
+ * Searching stuff!
89
+ * 1) Find classes defined with the @mixin decorator.
90
+ *
91
+ */
92
+
93
+ class MixinSource {
94
+ sourceFile: ts.SourceFile;
95
+ context!: ts.TransformationContext;
96
+ constructor(sourceFile: ts.SourceFile) {
97
+ this.sourceFile = sourceFile;
98
+ }
99
+
100
+ //Look for a class with the @mixin decorator!
101
+ update(context: ts.TransformationContext) {
102
+ this.context = context;
103
+ var declarations = <ts.Statement[]>[];
104
+
105
+ var crawl = (node: ts.Node): ts.Node => {
106
+ if (node.kind === ts.SyntaxKind.ClassDeclaration) {
107
+ var Class = ClassDeclaration.from(<ts.ClassDeclaration>node);
108
+ if (Class.hasDecorator("mixin")) {
109
+ var name = Class.getName().text;
110
+ var symbolName = Identifier(context, "Super_" + declarations.length);
111
+ var declareSuperSymbol = (new VariableDeclaration(symbolName))
112
+ .setValue(
113
+ (new CallExpression(Identifier(context, "Symbol")))
114
+ .addArgument(StringLiteral(context, "super_"+name))
115
+ .make(context)
116
+ ).make(context);
117
+ declarations.push(<ts.Statement>declareSuperSymbol);
118
+ var test = MixClass(this.context, <ts.ClassDeclaration>node, symbolName);
119
+ return test;
120
+ }
121
+ }
122
+ return ts.visitEachChild(node, crawl, this.context);
123
+ }
124
+
125
+ var source = ts.visitNode(this.sourceFile, crawl);
126
+
127
+ var file = SourceFile.from(source);
128
+ for (var declaration of declarations) {
129
+ file.insertUnderImports(declaration);
130
+ }
131
+ var result = file.update(context);
132
+ this.sourceFile = result;
133
+ if (declarations.length > 0) {
134
+ console.log("Updated file", file.original?.fileName, "with mixin data");
135
+ // console.log("~~~~~~~~~~~");
136
+ // console.log(Printer.printNode(result, this.sourceFile));
137
+ // console.log("~~~~~~~~~~~");
138
+ }
139
+ return result;
140
+ }
141
+ }
142
+
143
+
144
+ export default function (program: ts.Program, pluginOptions: {}) {
145
+ return (context: ts.TransformationContext) => {
146
+ return (sourceFile: ts.SourceFile) => {
147
+ return (new MixinSource(sourceFile)).update(context);
148
+ //return sourceFile;
149
+ }
150
+ }
151
+ }
@@ -0,0 +1,3 @@
1
+ import * as ts from "typescript";
2
+ export default function (program: ts.Program, pluginOptions: {}): (context: ts.TransformationContext) => (sourceFile: ts.SourceFile) => ts.SourceFile;
3
+ //# sourceMappingURL=SuperTransform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SuperTransform.d.ts","sourceRoot":"","sources":["SuperTransform.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AA8DjC,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,aAC7C,GAAG,qBAAqB,kBACpB,GAAG,UAAU,mBA2DlC"}