@bikky/compiler 0.1.0 → 0.1.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"ASTHelper.d.ts","sourceRoot":"","sources":["ASTHelper.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAEjC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,WAAW,QAAQ;IACrB,IAAI,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,CAAC;CAC7B;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,UAAU,UAK/D;AAED,qBAAa,eAAe;IACxB,IAAI,EAAE,EAAE,CAAC,UAAU,CAAC;gBAER,IAAI,EAAE,EAAE,CAAC,UAAU;IAI/B,OAAO;IAIP,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC,UAAU;CAI7B;AAED,qBAAa,mBAAoB,SAAQ,eAAe;IACpD,SAAS,CAAC,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAM;IAC/B,KAAK,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC;IAGtB,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,UAAU;IAK7B,WAAW,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ;IAQjC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,qBAAqB,GAAG,EAAE,CAAC,IAAI;CAKnD;AAED,yBAAc,mBAAmB,CAAC;IAC9B,SAAgB,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,mBAAmB,GAAG,mBAAmB,CAK1E;CACJ;AAED,qBAAa,mBAAoB,SAAQ,mBAAmB;gBAG5C,IAAI,EAAE,EAAE,CAAC,UAAU,GAAG,EAAE,CAAC,oBAAoB;IAIzD,IAAI,CAAC,OAAO,EAAE,EAAE,CA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,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,EAAE,CAAC,UAAU;IAelD,UAAU;IAIV,UAAU;IAIV,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,GAAG,SAAS;IAK7C,MAAM,CAAC,kBAAkB,CAAC,KAAK,EAAE,EAAE,CAAC,gBAAgB,EAAE,GAAG,EAAE,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE,CAAC,qBAAqB;IAmCxG,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,qBAAqB;CAgB3C;AAED,qBAAa,UAAU;IACnB,QAAQ,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC;IACzB,UAAU,EAAE,EAAE,CAAC,SAAS,EAAE,CAAM;IAEhC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU;IAOlC,WAAW,CAAC,OAAO,EAAE,EAAE,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE,CAAC,SAAS;IASxD,kBAAkB,CAAC,IAAI,EAAE,EAAE,CAAC,SAAS;IAUrC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC,qBAAqB;CAM3C;AAGD,wBAAgB,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS,CAiBhE;AAED,yBAAc,OAAO,CAAC;IAGlB,SAAgB,SAAS,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,EAAE,QAAQ,GAAE,EAAE,CAAC,QAAkC,UAElH;IAED,SAAgB,kBAAkB,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,UAAU,EAAE,EAAE,CAAC,UAAU,UAM1E;CACJ"}
@@ -10,6 +10,19 @@ function getNodeText(node, source) {
10
10
  return "[text not found]";
11
11
  }
12
12
  exports.getNodeText = getNodeText;
13
+ //TODO: Add support for stuff inside classes.
14
+ // export function cloneNode<T extends ts.Node>(node: T): T {
15
+ // if (ts.isTypeNode(node)) {
16
+ // let sf = ts.createSourceFile("cloneNode.ts", `let a: ${node.getText(Crawler.GetFile())};`, ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS);
17
+ // let expr = sf.statements[0] as ts.VariableStatement;
18
+ // let varDecl = expr.declarationList.declarations[0];
19
+ // return varDecl.type! as any as T;
20
+ // }
21
+ // else {
22
+ // let sf = ts.createSourceFile("cloneNode.ts", `${node.getText(Crawler.GetFile())}`, ts.ScriptTarget.ESNext, true, ts.ScriptKind.TS);
23
+ // return sf.statements[0] as any as T;
24
+ // }
25
+ // }
13
26
  class NamedExpression {
14
27
  constructor(name) {
15
28
  this.name = name;
@@ -270,8 +283,13 @@ class SourceFile {
270
283
  }
271
284
  exports.SourceFile = SourceFile;
272
285
  function logError(node, error) {
273
- if (!node || !node.getSourceFile()) {
274
- console.error("Why are we here?");
286
+ var _a, _b;
287
+ if (!node) {
288
+ console.error(`Got an error but no node:`, error);
289
+ return;
290
+ }
291
+ if (!node.getSourceFile()) {
292
+ console.error(`Got an error for a generated node (${(_b = (_a = node.name) === null || _a === void 0 ? void 0 : _a.getText()) !== null && _b !== void 0 ? _b : node.kind}):`, error);
275
293
  return;
276
294
  }
277
295
  var source = ts.isSourceFile(node) ? node : node.getSourceFile();
@@ -287,8 +305,8 @@ exports.logError = logError;
287
305
  var Printer;
288
306
  (function (Printer) {
289
307
  var printer = ts.createPrinter();
290
- function printNode(node, sourceFile) {
291
- return printer.printNode(ts.EmitHint.Unspecified, node, sourceFile);
308
+ function printNode(node, sourceFile, emitHint = ts.EmitHint.Unspecified) {
309
+ return printer.printNode(emitHint, node, sourceFile);
292
310
  }
293
311
  Printer.printNode = printNode;
294
312
  function printNodeFirstLine(node, sourceFile) {
@@ -1,11 +1,17 @@
1
1
  import * as ts from "typescript";
2
2
  export declare namespace Crawler {
3
3
  function SetProgram(tsProgram: ts.Program): void;
4
- function SetFile(tsFile: ts.SourceFile): Promise<void>;
4
+ function SetFile(tsFile: ts.SourceFile): void;
5
+ function writeSupplementaryFile(path: string, data: string): void;
6
+ function getTestFiles(path: string): Map<string, string> | undefined;
5
7
  function OnFile(callback: (file: {
6
8
  ts: ts.SourceFile;
7
9
  data: any;
8
- }) => (Promise<void> | void)): Promise<void>;
10
+ }) => void): void;
11
+ function OnFileCompleted(callback: (file: {
12
+ ts: ts.SourceFile;
13
+ data: any;
14
+ }) => ts.SourceFile): void;
9
15
  function GetProgram(): {
10
16
  ts: ts.Program;
11
17
  data: any;
@@ -1 +1 @@
1
- {"version":3,"file":"Crawler.d.ts","sourceRoot":"","sources":["Crawler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAGjC,yBAAc,OAAO,CAAC;IAOlB,SAAgB,UAAU,CAAC,SAAS,EAAE,EAAE,CAAC,OAAO,QAE/C;IAED,SAAsB,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,UAAU,iBAKlD;IAED,SAAsB,MAAM,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE;QAAE,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAE,KAAG,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,iBAEtG;IAED,SAAgB,UAAU;;;MAEzB;IAED,SAAgB,OAAO;;;MAEtB;IAED,SAAgB,QAAQ,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAG,OAAO,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAG,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,QAE3G;IAED,SAAgB,UAAU,CAAC,UAAU,EAAE,EAAE,CAAC,qBAAqB,QAE9D;IAED,SAAgB,UAAU,6BAEzB;IAED,SAAgB,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC,IA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IAED,SAAgB,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAI,CAAC,EAAE,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,WAqCvF;CAEJ"}
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.Crawler = void 0;
13
4
  const ts = require("typescript");
@@ -18,25 +9,45 @@ var Crawler;
18
9
  let program;
19
10
  let file;
20
11
  let fileCallbacks = [];
12
+ let fileCompletedCallbacks = [];
13
+ let testFilesWritten = new Map();
21
14
  function SetProgram(tsProgram) {
22
15
  program = { ts: tsProgram, data: {} };
23
16
  }
24
17
  Crawler.SetProgram = SetProgram;
25
18
  function SetFile(tsFile) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- file = { ts: tsFile, data: {} };
28
- for (let callback of fileCallbacks) {
29
- yield callback(file);
30
- }
31
- });
19
+ file = { ts: tsFile, data: {} };
20
+ for (let callback of fileCallbacks) {
21
+ callback(file);
22
+ }
32
23
  }
33
24
  Crawler.SetFile = SetFile;
25
+ //TODO: Append supplementary file onto current file in the browser?
26
+ function writeSupplementaryFile(path, data) {
27
+ if (typeof __isTesting__ !== "undefined" && __isTesting__) {
28
+ testFilesWritten.set(path, data);
29
+ }
30
+ else {
31
+ const fs = require("fs");
32
+ fs.writeFileSync(path, data, { encoding: "utf8" });
33
+ }
34
+ }
35
+ Crawler.writeSupplementaryFile = writeSupplementaryFile;
36
+ function getTestFiles(path) {
37
+ if (typeof __isTesting__ !== "undefined" && __isTesting__) {
38
+ return testFilesWritten;
39
+ }
40
+ return undefined;
41
+ }
42
+ Crawler.getTestFiles = getTestFiles;
34
43
  function OnFile(callback) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- yield fileCallbacks.push(callback);
37
- });
44
+ fileCallbacks.push(callback);
38
45
  }
39
46
  Crawler.OnFile = OnFile;
47
+ function OnFileCompleted(callback) {
48
+ fileCompletedCallbacks.push(callback);
49
+ }
50
+ Crawler.OnFileCompleted = OnFileCompleted;
40
51
  function GetProgram() {
41
52
  return program;
42
53
  }
@@ -86,8 +97,13 @@ var Crawler;
86
97
  }
87
98
  return ts.visitEachChild(result, crawl, context);
88
99
  };
89
- if (ts.isSourceFile(start))
90
- return ts.visitNode(start, crawl);
100
+ if (ts.isSourceFile(start)) {
101
+ let result = ts.visitNode(start, crawl);
102
+ for (let callback of fileCompletedCallbacks) {
103
+ result = callback({ ts: result, data: {} });
104
+ }
105
+ return result;
106
+ }
91
107
  return ts.visitEachChild(start, crawl, context);
92
108
  }
93
109
  Crawler.Crawl = Crawl;
@@ -0,0 +1,21 @@
1
+ import * as ts from "typescript";
2
+ /**
3
+ * This is to get all mixin classes.
4
+ */
5
+ export declare function getAllInheritedMixinClassNames(node: ts.HeritageClause): string[];
6
+ /**
7
+ * Copied from @bikky/path.
8
+ * Normalises a path to the imports standard (using / as separators).
9
+ * Pedantic will force / on the start and end of paths.
10
+ */
11
+ export declare function normalisePath(path: string, pedantic?: boolean): string;
12
+ /**
13
+ * Copied from @bikky/path.
14
+ * @param strArray the paths to join.
15
+ */
16
+ export declare function joinPaths(...strArray: string[]): string;
17
+ /**
18
+ * Copied from @bikky/path. Get the directory portion of the path (without the filename or extension).
19
+ */
20
+ export declare function getPathDir(path: string): string;
21
+ //# sourceMappingURL=MiscHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MiscHelpers.d.ts","sourceRoot":"","sources":["MiscHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAGjC;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,GAAG,MAAM,EAAE,CA4ChF;AAMD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,UAAQ,UAe3D;AAGD;;;GAGG;AAEH,wBAAgB,SAAS,CAAC,GAAG,QAAQ,EAAE,MAAM,EAAE,UAkE9C;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,UAEtC"}
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPathDir = exports.joinPaths = exports.normalisePath = exports.getAllInheritedMixinClassNames = void 0;
4
+ const ts = require("typescript");
5
+ const ASTHelper_js_1 = require("./ASTHelper.js");
6
+ /**
7
+ * This is to get all mixin classes.
8
+ */
9
+ function getAllInheritedMixinClassNames(node) {
10
+ if (node.token !== ts.SyntaxKind.ExtendsKeyword) {
11
+ return [];
12
+ }
13
+ let classes = [];
14
+ let subcrawler = (node) => {
15
+ if (ts.isPropertyAccessExpression(node.expression)) {
16
+ if (!ts.isIdentifier(node.expression.expression)) {
17
+ throw new Error((0, ASTHelper_js_1.logError)(node.expression.expression, `Cannot gather class data from a complex expression.`));
18
+ }
19
+ else {
20
+ classes.push(node.expression.expression.getText());
21
+ }
22
+ if (!ts.isIdentifier(node.expression.name)) {
23
+ throw new Error((0, ASTHelper_js_1.logError)(node.expression.name, `Cannot gather class data from a complex expression.`));
24
+ }
25
+ if (node.expression.name.text !== "mix") {
26
+ throw new Error((0, ASTHelper_js_1.logError)(node.expression.name, `Cannot gather class data from a function result that's not a mixin function.`));
27
+ }
28
+ if (node.arguments.length !== 1) {
29
+ throw new Error((0, ASTHelper_js_1.logError)(node, `Mixin function must be called with exactly one argument.`));
30
+ }
31
+ let subExpr = node.arguments[0];
32
+ if (ts.isCallExpression(subExpr)) {
33
+ subcrawler(subExpr);
34
+ }
35
+ else if (ts.isIdentifier(subExpr)) {
36
+ classes.push(subExpr.getText());
37
+ }
38
+ else {
39
+ throw new Error((0, ASTHelper_js_1.logError)(subExpr, `Cannot gather class data from a complex expression.`));
40
+ }
41
+ }
42
+ };
43
+ if (node.types.length > 0) {
44
+ let expr = node.types[0].expression;
45
+ if (ts.isCallExpression(expr)) {
46
+ subcrawler(expr);
47
+ }
48
+ if (ts.isIdentifier(expr)) {
49
+ classes.push(expr.getText());
50
+ }
51
+ }
52
+ return classes;
53
+ }
54
+ exports.getAllInheritedMixinClassNames = getAllInheritedMixinClassNames;
55
+ const fileExtension = /\.[a-zA-Z0-9_]*?$/;
56
+ const fileNameIncludingExt = /[^\/\\]+$/;
57
+ /**
58
+ * Copied from @bikky/path.
59
+ * Normalises a path to the imports standard (using / as separators).
60
+ * Pedantic will force / on the start and end of paths.
61
+ */
62
+ function normalisePath(path, pedantic = false) {
63
+ if (path === '') {
64
+ return "";
65
+ }
66
+ //Replace backslashes with forwards slashes.
67
+ path = path.replace(/\\/g, "/");
68
+ //Replace multiple forwards slashes with only one forwards slash.
69
+ path = path.replace(/(?!(?:file:|[\\\/]))\/{2,}/g, "/");
70
+ //Make sure the path ends with a /.
71
+ if (!fileExtension.test(path)) {
72
+ if (pedantic && !path.endsWith("/")) {
73
+ path += "/";
74
+ }
75
+ }
76
+ return path;
77
+ }
78
+ exports.normalisePath = normalisePath;
79
+ /**
80
+ * Copied from @bikky/path.
81
+ * @param strArray the paths to join.
82
+ */
83
+ function joinPaths(...strArray) {
84
+ var resultArray = [];
85
+ if (strArray.length === 0) {
86
+ return '';
87
+ }
88
+ if (typeof strArray[0] !== 'string') {
89
+ throw new TypeError(`Path must be a string. Received ` + strArray[0]);
90
+ }
91
+ // If the first part is a plain protocol, we combine it with the next part.
92
+ if (strArray.length > 1 && strArray[0].match(/^[^/:]+:[\/\\]{2,3}$/)) {
93
+ var first = strArray.shift();
94
+ strArray[0] = first + strArray[0];
95
+ }
96
+ for (var i = 0; i < strArray.length; i++) {
97
+ strArray[i] = normalisePath(strArray[i], true);
98
+ var component = strArray[i];
99
+ if (typeof component !== 'string') {
100
+ throw new TypeError(`Path must be a string. ${i}th argument is ` + component);
101
+ }
102
+ if (component === '') {
103
+ continue;
104
+ }
105
+ //Remove the ending slash of each component.
106
+ if (component.endsWith("/") && !(component.endsWith("../") || component.endsWith("./"))) {
107
+ component = component.slice(0, -1);
108
+ }
109
+ //For each component but the first:
110
+ if (i > 0) {
111
+ // Removing the starting slashes.
112
+ if (component.startsWith("/"))
113
+ component = component.slice(1);
114
+ // Remove any starting ./
115
+ if (component.startsWith("./"))
116
+ component = component.slice(2);
117
+ //While there are starting ../
118
+ while (component.startsWith("../")) {
119
+ //Remove the trailing /**** from the previous string section
120
+ resultArray[i - 1] = resultArray[i - 1].replace(/\/[^\/]*$/, "");
121
+ //Remove the starting ../
122
+ component = component.slice(3);
123
+ }
124
+ }
125
+ if (i < strArray.length - 1) {
126
+ // Removing the ending slashes for each component but the last.
127
+ component = component.replace(/[\/]+$/, '');
128
+ }
129
+ else {
130
+ // For the last component we will combine multiple slashes to a single one.
131
+ component = component.replace(/[\/]+$/, '/');
132
+ }
133
+ resultArray.push(component);
134
+ }
135
+ var str = resultArray.join('/');
136
+ // Each input component is now separated by a single slash except the possible first plain protocol part.
137
+ // remove trailing slash before parameters or hash
138
+ str = str.replace(/\/(\?|&|#[^!])/g, '$1');
139
+ // replace ? in parameters with &
140
+ var parts = str.split('?');
141
+ str = parts.shift() + (parts.length > 0 ? '?' : '') + parts.join('&');
142
+ return str;
143
+ }
144
+ exports.joinPaths = joinPaths;
145
+ /**
146
+ * Copied from @bikky/path. Get the directory portion of the path (without the filename or extension).
147
+ */
148
+ function getPathDir(path) {
149
+ return path.replace(fileNameIncludingExt, "");
150
+ }
151
+ exports.getPathDir = getPathDir;
152
+ //# sourceMappingURL=MiscHelpers.js.map
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const ts = require("typescript");
4
+ const Crawler_js_1 = require("../Source/ASTInterface/Crawler.js");
4
5
  const Class_js_1 = require("../Source/ASTInterface/Class.js");
5
6
  const ASTBuilder_js_1 = require("../Source/ASTBuilder.js");
6
7
  const DelayFunctionName = "__BikCompileDelayCreate";
8
+ const HotReloadFunctionName = "__BikRegisterHotReload";
7
9
  Class_js_1.Class.onClass((delayClass) => {
8
10
  let chosenPromise = null;
9
11
  //Find out if the class has the @DelayUntil decorator. If it does, remove it (by returning null).
@@ -42,4 +44,54 @@ Class_js_1.Class.onClass((delayClass) => {
42
44
  let wrapper = (0, ASTBuilder_js_1.STATEMENT)().LINE((0, ASTBuilder_js_1.ID)(DelayFunctionName).CALL(chosenPromise, delayClass.name, lambdaWithClass, lambdaClassAssignment));
43
45
  return [placeholder.update(), ...wrapper.toAST()];
44
46
  });
47
+ let currentFileExports = new Array;
48
+ //HOT RELOAD SUPPORT - Record all exported file members.
49
+ Crawler_js_1.Crawler.Register((node) => {
50
+ //Can't find a good ts.isExport check for this so we do it manually.
51
+ if (ts.isModifier(node) && node.kind === ts.SyntaxKind.ExportKeyword && ts.isSourceFile(node.parent.parent)) {
52
+ let parent = node.parent;
53
+ // Don't export anything that is declared only as it doesn't have a runtime representation.
54
+ if (parent.modifiers.some((e) => e.kind == ts.SyntaxKind.DeclareKeyword))
55
+ return false;
56
+ // Don't export anything that is an interface as it doesn't have a runtime representation.
57
+ if (ts.isInterfaceDeclaration(parent))
58
+ return false;
59
+ // Don't export const enums as they are inlined at compile time.
60
+ if (ts.isEnumDeclaration(parent) && parent.modifiers.some((e) => e.kind == ts.SyntaxKind.ConstKeyword))
61
+ return false;
62
+ return true;
63
+ }
64
+ return false;
65
+ }, (node) => {
66
+ if (ts.isVariableStatement(node)) {
67
+ for (let decl of node.declarationList.declarations) {
68
+ if (ts.isIdentifier(decl.name)) {
69
+ currentFileExports.push(decl.name.text);
70
+ }
71
+ }
72
+ }
73
+ else if (ts.isFunctionDeclaration(node) && node.name) {
74
+ currentFileExports.push(node.name.text);
75
+ }
76
+ else if (ts.isClassDeclaration(node) && node.name) {
77
+ currentFileExports.push(node.name.text);
78
+ }
79
+ else if (ts.isEnumDeclaration(node)) {
80
+ currentFileExports.push(node.name.text);
81
+ }
82
+ else if (ts.isModuleDeclaration(node) && node.name) {
83
+ currentFileExports.push(node.name.text);
84
+ }
85
+ return node;
86
+ });
87
+ // HOT RELOAD SUPPORT - At the end of the file, register all exported members for hot reloading.
88
+ Crawler_js_1.Crawler.OnFileCompleted((file) => {
89
+ let newStatements = [];
90
+ for (let exportedMember of currentFileExports) {
91
+ let lambdaExportAssignment = (0, ASTBuilder_js_1.LAMBDA_DECL)([(0, ASTBuilder_js_1.PARAM_DECL)("r")], (0, ASTBuilder_js_1.STATEMENT)().LINE((0, ASTBuilder_js_1.ID)(exportedMember).ASGN("=", (0, ASTBuilder_js_1.ID)("r"))), true);
92
+ let callReloadFunction = (0, ASTBuilder_js_1.STATEMENT)().LINE((0, ASTBuilder_js_1.ID)(HotReloadFunctionName).CALL((0, ASTBuilder_js_1.LITERAL)(exportedMember), (0, ASTBuilder_js_1.ID)(exportedMember), lambdaExportAssignment));
93
+ newStatements.push(...callReloadFunction.toAST());
94
+ }
95
+ return ts.factory.updateSourceFile(file.ts, [...file.ts.statements, ...newStatements]);
96
+ });
45
97
  //# sourceMappingURL=DelayTransformer.js.map
@@ -1,5 +1,6 @@
1
1
  import "./DelayTransformer.js";
2
2
  import "./MixinTransformer.js";
3
+ import "./ReplicableTransformer.js";
3
4
  import * as ts from "typescript";
4
- export default function (program: ts.Program, pluginOptions: {}): (context: ts.TransformationContext) => (sourceFile: ts.SourceFile) => Promise<ts.Node>;
5
+ export default function (program: ts.Program, pluginOptions: {}): (context: ts.TransformationContext) => (sourceFile: ts.SourceFile) => ts.Node;
5
6
  //# sourceMappingURL=Main.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Main.d.ts","sourceRoot":"","sources":["Main.ts"],"names":[],"mappings":"AACA,OAAO,uBAAuB,CAAC;AAC/B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAGjC,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,aAE1C,GAAG,qBAAqB,kBAEX,GAAG,UAAU,sBAK9C"}
1
+ {"version":3,"file":"Main.d.ts","sourceRoot":"","sources":["Main.ts"],"names":[],"mappings":"AACA,OAAO,uBAAuB,CAAC;AAC/B,OAAO,uBAAuB,CAAC;AAC/B,OAAO,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAIjC,MAAM,CAAC,OAAO,WAAW,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,EAAE,aAE1C,GAAG,qBAAqB,kBAEjB,GAAG,UAAU,aAKxC"}
@@ -1,25 +1,17 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  require("./DelayTransformer.js");
13
4
  require("./MixinTransformer.js");
5
+ require("./ReplicableTransformer.js");
14
6
  const Crawler_js_1 = require("../Source/ASTInterface/Crawler.js");
15
7
  function default_1(program, pluginOptions) {
16
8
  Crawler_js_1.Crawler.SetProgram(program);
17
9
  return (context) => {
18
10
  Crawler_js_1.Crawler.setContext(context);
19
- return (sourceFile) => __awaiter(this, void 0, void 0, function* () {
20
- yield Crawler_js_1.Crawler.SetFile(sourceFile);
11
+ return (sourceFile) => {
12
+ Crawler_js_1.Crawler.SetFile(sourceFile);
21
13
  return Crawler_js_1.Crawler.Crawl(sourceFile);
22
- });
14
+ };
23
15
  };
24
16
  }
25
17
  exports.default = default_1;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ReplicableTransformer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReplicableTransformer.d.ts","sourceRoot":"","sources":["ReplicableTransformer.ts"],"names":[],"mappings":""}