babel-plugin-wallace 0.0.1 → 0.0.5

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 (78) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/ast-helpers.d.ts +10 -0
  3. package/dist/ast-helpers.js +52 -0
  4. package/dist/ast-helpers.js.map +1 -0
  5. package/dist/babel-types.d.ts +4 -0
  6. package/dist/babel-types.js +3 -0
  7. package/dist/babel-types.js.map +1 -0
  8. package/dist/builders/consolidation.d.ts +30 -0
  9. package/dist/builders/consolidation.js +321 -0
  10. package/dist/builders/consolidation.js.map +1 -0
  11. package/dist/builders/define-component.d.ts +7 -0
  12. package/dist/builders/define-component.js +101 -0
  13. package/dist/builders/define-component.js.map +1 -0
  14. package/dist/builders/index.d.ts +2 -0
  15. package/dist/builders/index.js +7 -0
  16. package/dist/builders/index.js.map +1 -0
  17. package/dist/builders/types.d.ts +15 -0
  18. package/dist/builders/types.js +3 -0
  19. package/dist/builders/types.js.map +1 -0
  20. package/dist/builders/visibility.d.ts +5 -0
  21. package/dist/builders/visibility.js +43 -0
  22. package/dist/builders/visibility.js.map +1 -0
  23. package/dist/config.d.ts +14 -0
  24. package/dist/config.js +47 -0
  25. package/dist/config.js.map +1 -0
  26. package/dist/constants.d.ts +31 -0
  27. package/dist/constants.js +40 -0
  28. package/dist/constants.js.map +1 -0
  29. package/dist/contexts/handlers.d.ts +18 -0
  30. package/dist/contexts/handlers.js +152 -0
  31. package/dist/contexts/handlers.js.map +1 -0
  32. package/dist/contexts/index.d.ts +2 -0
  33. package/dist/contexts/index.js +6 -0
  34. package/dist/contexts/index.js.map +1 -0
  35. package/dist/contexts/parameters.d.ts +8 -0
  36. package/dist/contexts/parameters.js +114 -0
  37. package/dist/contexts/parameters.js.map +1 -0
  38. package/dist/directives.d.ts +8 -0
  39. package/dist/directives.js +94 -0
  40. package/dist/directives.js.map +1 -0
  41. package/dist/errors.d.ts +32 -0
  42. package/dist/errors.js +45 -0
  43. package/dist/errors.js.map +1 -0
  44. package/dist/helpers.d.ts +4 -0
  45. package/dist/helpers.js +35 -0
  46. package/dist/helpers.js.map +1 -0
  47. package/dist/index.d.ts +10 -0
  48. package/dist/index.js +34 -0
  49. package/dist/index.js.map +1 -0
  50. package/dist/models/component.d.ts +25 -0
  51. package/dist/models/component.js +114 -0
  52. package/dist/models/component.js.map +1 -0
  53. package/dist/models/directive.d.ts +13 -0
  54. package/dist/models/directive.js +8 -0
  55. package/dist/models/directive.js.map +1 -0
  56. package/dist/models/index.d.ts +5 -0
  57. package/dist/models/index.js +15 -0
  58. package/dist/models/index.js.map +1 -0
  59. package/dist/models/module.d.ts +12 -0
  60. package/dist/models/module.js +40 -0
  61. package/dist/models/module.js.map +1 -0
  62. package/dist/models/node.d.ts +82 -0
  63. package/dist/models/node.js +306 -0
  64. package/dist/models/node.js.map +1 -0
  65. package/dist/utils.d.ts +12 -0
  66. package/dist/utils.js +59 -0
  67. package/dist/utils.js.map +1 -0
  68. package/dist/visitors/attribute.d.ts +10 -0
  69. package/dist/visitors/attribute.js +82 -0
  70. package/dist/visitors/attribute.js.map +1 -0
  71. package/dist/visitors/jsx.d.ts +13 -0
  72. package/dist/visitors/jsx.js +61 -0
  73. package/dist/visitors/jsx.js.map +1 -0
  74. package/dist/visitors/program.d.ts +12 -0
  75. package/dist/visitors/program.js +26 -0
  76. package/dist/visitors/program.js.map +1 -0
  77. package/package.json +19 -10
  78. package/lib/index.js +0 -13
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processShields = processShields;
4
+ const utils_1 = require("../utils");
5
+ /*
6
+ * Given an array of addresses such as
7
+ *
8
+ * [
9
+ * [0],
10
+ * [0, 1],
11
+ * [0, 2],
12
+ * [1],
13
+ * ]
14
+ *
15
+ * It returns an array with the count of nested items, like so:
16
+ *
17
+ * [2, 0, 0, 0]
18
+ */
19
+ function calculateShieldCounts(addresses) {
20
+ const processedAddresses = [];
21
+ addresses.forEach((path) => {
22
+ processedAddresses.forEach((processed) => {
23
+ if ((0, utils_1.arrayStartsWith)(processed.path, path)) {
24
+ processed.count++;
25
+ }
26
+ });
27
+ processedAddresses.push({ path: path, count: 0 });
28
+ });
29
+ return processedAddresses.map((i) => i.count);
30
+ }
31
+ /**
32
+ * Must be done after processing watches as we need to know how many watches to skip.
33
+ */
34
+ function processShields(watches) {
35
+ const addresses = watches.map((watch) => watch.address.slice(1));
36
+ const shieldCounts = calculateShieldCounts(addresses);
37
+ watches.forEach((watch, index) => {
38
+ if (watch.shieldInfo) {
39
+ watch.shieldInfo.count = shieldCounts[index];
40
+ }
41
+ });
42
+ }
43
+ //# sourceMappingURL=visibility.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visibility.js","sourceRoot":"","sources":["../../src/builders/visibility.ts"],"names":[],"mappings":";;AAiCA,wCAQC;AAzCD,oCAA2C;AAG3C;;;;;;;;;;;;;GAaG;AACH,SAAS,qBAAqB,CAAC,SAA6B;IAC1D,MAAM,kBAAkB,GAAG,EAAE,CAAC;IAC9B,SAAS,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACzB,kBAAkB,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;YACvC,IAAI,IAAA,uBAAe,EAAC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;gBAC1C,SAAS,CAAC,KAAK,EAAE,CAAC;YACpB,CAAC;QACH,CAAC,CAAC,CAAC;QACH,kBAAkB,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC,CAAC;IACH,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,OAA8B;IAC3D,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACjE,MAAM,YAAY,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;IACtD,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAC/B,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;YACrB,KAAK,CAAC,UAAU,CAAC,KAAK,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { Directive } from "./models";
2
+ interface GleekitOptions {
3
+ directives?: Array<typeof Directive>;
4
+ }
5
+ declare class GleekitConfig {
6
+ #private;
7
+ directives: {
8
+ [key: string]: typeof Directive;
9
+ };
10
+ applyOptions(options: GleekitOptions): void;
11
+ addDirectives(directives: Array<typeof Directive>): void;
12
+ }
13
+ export declare const gleekitConfig: GleekitConfig;
14
+ export {};
package/dist/config.js ADDED
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
6
+ };
7
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
8
+ if (kind === "m") throw new TypeError("Private method is not writable");
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
+ };
13
+ var _GleekitConfig_loaded;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.gleekitConfig = void 0;
16
+ const directives_1 = require("./directives");
17
+ class GleekitConfig {
18
+ constructor() {
19
+ this.directives = {};
20
+ _GleekitConfig_loaded.set(this, false);
21
+ }
22
+ applyOptions(options) {
23
+ if (__classPrivateFieldGet(this, _GleekitConfig_loaded, "f")) {
24
+ return;
25
+ }
26
+ if (options.directives) {
27
+ this.addDirectives(options.directives);
28
+ }
29
+ __classPrivateFieldSet(this, _GleekitConfig_loaded, true, "f");
30
+ }
31
+ addDirectives(directives) {
32
+ for (const directiveClass of directives) {
33
+ const attributeName = directiveClass.attributeName;
34
+ if (attributeName === undefined) {
35
+ throw new Error(`"Directive class "${directiveClass.name}" must have an attributName.`);
36
+ }
37
+ if (this.directives.hasOwnProperty(attributeName)) {
38
+ console.debug(`Overriding directive ${attributeName} with ${directiveClass}.`);
39
+ }
40
+ this.directives[attributeName] = directiveClass;
41
+ }
42
+ }
43
+ }
44
+ _GleekitConfig_loaded = new WeakMap();
45
+ exports.gleekitConfig = new GleekitConfig();
46
+ exports.gleekitConfig.addDirectives(directives_1.builtinDirectives);
47
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,6CAAiD;AAMjD,MAAM,aAAa;IAAnB;QACE,eAAU,GAAwC,EAAE,CAAC;QACrD,gCAAmB,KAAK,EAAC;IA0B3B,CAAC;IAzBC,YAAY,CAAC,OAAuB;QAClC,IAAI,uBAAA,IAAI,6BAAQ,EAAE,CAAC;YACjB,OAAO;QACT,CAAC;QACD,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QACzC,CAAC;QACD,uBAAA,IAAI,yBAAW,IAAI,MAAA,CAAC;IACtB,CAAC;IACD,aAAa,CAAC,UAAmC;QAC/C,KAAK,MAAM,cAAc,IAAI,UAAU,EAAE,CAAC;YACxC,MAAM,aAAa,GAAG,cAAc,CAAC,aAAa,CAAC;YACnD,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;gBAChC,MAAM,IAAI,KAAK,CACb,qBAAqB,cAAc,CAAC,IAAI,8BAA8B,CACvE,CAAC;YACJ,CAAC;YACD,IAAI,IAAI,CAAC,UAAU,CAAC,cAAc,CAAC,aAAa,CAAC,EAAE,CAAC;gBAClD,OAAO,CAAC,KAAK,CACX,wBAAwB,aAAa,SAAS,cAAc,GAAG,CAChE,CAAC;YACJ,CAAC;YACD,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,GAAG,cAAc,CAAC;QAClD,CAAC;IACH,CAAC;CACF;;AAEY,QAAA,aAAa,GAAG,IAAI,aAAa,EAAE,CAAC;AAEjD,qBAAa,CAAC,aAAa,CAAC,8BAAiB,CAAC,CAAC"}
@@ -0,0 +1,31 @@
1
+ export declare enum WATCH_CALLBACK_PARAMS {
2
+ newValue = "n",
3
+ oldValue = "o",
4
+ element = "e",
5
+ props = "p",
6
+ component = "c"
7
+ }
8
+ export declare enum COMPONENT_BUILD_PARAMS {
9
+ component = "component",
10
+ rootElement = "root"
11
+ }
12
+ export declare enum IMPORTABLES {
13
+ defineComponent = "defineComponent",
14
+ extendComponent = "extendComponent",
15
+ findElement = "findElement",
16
+ nestComponent = "nestComponent",
17
+ saveRef = "saveRef",
18
+ saveMiscObject = "saveMiscObject",
19
+ onEvent = "onEvent",
20
+ getSequentialPool = "getSequentialPool"
21
+ }
22
+ export declare enum EVENT_CALLBACK_VARIABLES {
23
+ component = "_component",
24
+ element = "_element",
25
+ event = "_event"
26
+ }
27
+ export declare enum SPECIAL_SYMBOLS {
28
+ objectStash = "_o",
29
+ alwaysUpdate = "*",
30
+ patch = "patch"
31
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SPECIAL_SYMBOLS = exports.EVENT_CALLBACK_VARIABLES = exports.IMPORTABLES = exports.COMPONENT_BUILD_PARAMS = exports.WATCH_CALLBACK_PARAMS = void 0;
4
+ var WATCH_CALLBACK_PARAMS;
5
+ (function (WATCH_CALLBACK_PARAMS) {
6
+ WATCH_CALLBACK_PARAMS["newValue"] = "n";
7
+ WATCH_CALLBACK_PARAMS["oldValue"] = "o";
8
+ WATCH_CALLBACK_PARAMS["element"] = "e";
9
+ WATCH_CALLBACK_PARAMS["props"] = "p";
10
+ WATCH_CALLBACK_PARAMS["component"] = "c";
11
+ })(WATCH_CALLBACK_PARAMS || (exports.WATCH_CALLBACK_PARAMS = WATCH_CALLBACK_PARAMS = {}));
12
+ var COMPONENT_BUILD_PARAMS;
13
+ (function (COMPONENT_BUILD_PARAMS) {
14
+ COMPONENT_BUILD_PARAMS["component"] = "component";
15
+ COMPONENT_BUILD_PARAMS["rootElement"] = "root";
16
+ })(COMPONENT_BUILD_PARAMS || (exports.COMPONENT_BUILD_PARAMS = COMPONENT_BUILD_PARAMS = {}));
17
+ var IMPORTABLES;
18
+ (function (IMPORTABLES) {
19
+ IMPORTABLES["defineComponent"] = "defineComponent";
20
+ IMPORTABLES["extendComponent"] = "extendComponent";
21
+ IMPORTABLES["findElement"] = "findElement";
22
+ IMPORTABLES["nestComponent"] = "nestComponent";
23
+ IMPORTABLES["saveRef"] = "saveRef";
24
+ IMPORTABLES["saveMiscObject"] = "saveMiscObject";
25
+ IMPORTABLES["onEvent"] = "onEvent";
26
+ IMPORTABLES["getSequentialPool"] = "getSequentialPool";
27
+ })(IMPORTABLES || (exports.IMPORTABLES = IMPORTABLES = {}));
28
+ var EVENT_CALLBACK_VARIABLES;
29
+ (function (EVENT_CALLBACK_VARIABLES) {
30
+ EVENT_CALLBACK_VARIABLES["component"] = "_component";
31
+ EVENT_CALLBACK_VARIABLES["element"] = "_element";
32
+ EVENT_CALLBACK_VARIABLES["event"] = "_event";
33
+ })(EVENT_CALLBACK_VARIABLES || (exports.EVENT_CALLBACK_VARIABLES = EVENT_CALLBACK_VARIABLES = {}));
34
+ var SPECIAL_SYMBOLS;
35
+ (function (SPECIAL_SYMBOLS) {
36
+ SPECIAL_SYMBOLS["objectStash"] = "_o";
37
+ SPECIAL_SYMBOLS["alwaysUpdate"] = "*";
38
+ SPECIAL_SYMBOLS["patch"] = "patch";
39
+ })(SPECIAL_SYMBOLS || (exports.SPECIAL_SYMBOLS = SPECIAL_SYMBOLS = {}));
40
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA,IAAY,qBAMX;AAND,WAAY,qBAAqB;IAC/B,uCAAc,CAAA;IACd,uCAAc,CAAA;IACd,sCAAa,CAAA;IACb,oCAAW,CAAA;IACX,wCAAe,CAAA;AACjB,CAAC,EANW,qBAAqB,qCAArB,qBAAqB,QAMhC;AAED,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,iDAAuB,CAAA;IACvB,8CAAoB,CAAA;AACtB,CAAC,EAHW,sBAAsB,sCAAtB,sBAAsB,QAGjC;AAED,IAAY,WASX;AATD,WAAY,WAAW;IACrB,kDAAmC,CAAA;IACnC,kDAAmC,CAAA;IACnC,0CAA2B,CAAA;IAC3B,8CAA+B,CAAA;IAC/B,kCAAmB,CAAA;IACnB,gDAAiC,CAAA;IACjC,kCAAmB,CAAA;IACnB,sDAAuC,CAAA;AACzC,CAAC,EATW,WAAW,2BAAX,WAAW,QAStB;AAED,IAAY,wBAIX;AAJD,WAAY,wBAAwB;IAClC,oDAAwB,CAAA;IACxB,gDAAoB,CAAA;IACpB,4CAAgB,CAAA;AAClB,CAAC,EAJW,wBAAwB,wCAAxB,wBAAwB,QAInC;AAED,IAAY,eAIX;AAJD,WAAY,eAAe;IACzB,qCAAkB,CAAA;IAClB,qCAAkB,CAAA;IAClB,kCAAe,CAAA;AACjB,CAAC,EAJW,eAAe,+BAAf,eAAe,QAI1B"}
@@ -0,0 +1,18 @@
1
+ import type { NodePath } from "@babel/core";
2
+ import type { Function } from "@babel/types";
3
+ import { Component, Module } from "../models";
4
+ /**
5
+ * Base class for contexts where an arrow function of interest may be found.
6
+ */
7
+ declare class AbstractContextHandler {
8
+ componentName: string;
9
+ component: Component;
10
+ isMatch: boolean;
11
+ module: Module;
12
+ path: NodePath<Function>;
13
+ constructor(path: NodePath<Function>, module: Module);
14
+ applyTransformations(): void;
15
+ initialiseComponent(componentName: string): void;
16
+ }
17
+ export declare function identifyContextToBeHandled(path: NodePath<Function>, module: Module): AbstractContextHandler | undefined;
18
+ export {};
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.identifyContextToBeHandled = identifyContextToBeHandled;
4
+ const t = require("@babel/types");
5
+ const constants_1 = require("../constants");
6
+ const jsx_1 = require("../visitors/jsx");
7
+ const builders_1 = require("../builders");
8
+ const errors_1 = require("../errors");
9
+ const models_1 = require("../models");
10
+ const helpers_1 = require("../helpers");
11
+ const utils_1 = require("../utils");
12
+ const parameters_1 = require("./parameters");
13
+ /**
14
+ * Base class for contexts where an arrow function of interest may be found.
15
+ */
16
+ class AbstractContextHandler {
17
+ constructor(path, module) {
18
+ this.isMatch = false;
19
+ this.path = path;
20
+ this.module = module;
21
+ }
22
+ applyTransformations() {
23
+ throw new Error("not implemented");
24
+ }
25
+ initialiseComponent(componentName) {
26
+ if (!(0, utils_1.isCapitalized)(componentName)) {
27
+ (0, errors_1.error)(this.path.parentPath, errors_1.ERROR_MESSAGES.CAPITALISED_COMPONENT_NAME);
28
+ }
29
+ const scope = this.path.scope;
30
+ this.component = new models_1.Component(componentName, this.module, scope.generateUidIdentifier("p"), scope.generateUidIdentifier("c"));
31
+ this.isMatch = true;
32
+ }
33
+ }
34
+ function getAssignedName(path) {
35
+ const parentNode = path.parentPath.node;
36
+ if (t.isVariableDeclarator(parentNode) && t.isIdentifier(parentNode.id)) {
37
+ return parentNode.id.name;
38
+ }
39
+ return "Anonymous";
40
+ }
41
+ /**
42
+ * const A = () => <div></div>
43
+ * A.prototype.foo = () => <div></div>
44
+ */
45
+ class AssignedJsxFunction extends AbstractContextHandler {
46
+ constructor(path, module) {
47
+ super(path, module);
48
+ if ((0, helpers_1.functionReturnsOnlyJSX)(path)) {
49
+ this.initialiseComponent(getAssignedName(path));
50
+ module.requireImport(constants_1.IMPORTABLES.defineComponent);
51
+ this.pathToReplace = path;
52
+ }
53
+ }
54
+ applyTransformations() {
55
+ (0, parameters_1.processFunctionParameters)(this.path, this.component);
56
+ this.path.traverse(jsx_1.jsxVisitors, { component: this.component });
57
+ this.pathToReplace.replaceWith((0, builders_1.buildDefineComponentCall)(this.component));
58
+ }
59
+ }
60
+ class JsxClassMethod extends AbstractContextHandler {
61
+ constructor(path, module) {
62
+ super(path, module);
63
+ if ((0, helpers_1.functionReturnsOnlyJSX)(path)) {
64
+ // @ts-ignore
65
+ this.classDeclarationPath = path.parentPath.parentPath;
66
+ if (t.isClassDeclaration(this.classDeclarationPath.node)) {
67
+ const className = this.classDeclarationPath.node.id.name;
68
+ this.initialiseComponent(className);
69
+ module.requireImport(constants_1.IMPORTABLES.extendComponent);
70
+ }
71
+ }
72
+ }
73
+ applyTransformations() {
74
+ (0, parameters_1.processFunctionParameters)(this.path, this.component);
75
+ this.path.traverse(jsx_1.jsxVisitors, { component: this.component });
76
+ this.classDeclarationPath.insertAfter((0, builders_1.buildExtendComponentCall)(this.component));
77
+ }
78
+ }
79
+ // NOT SUPPORTED UNTIL WE FIND A WAY TO MAKE IT WORK WITH .nest AND .repeat
80
+ // class AbstractClassPropertyContext extends AbstractContextHandler {
81
+ // classDeclarationPath: NodePath<ClassDeclaration>;
82
+ // constructor(path: NodePath<Function>, module: Module) {
83
+ // super(path, module);
84
+ // if (this.isRightShape(path)) {
85
+ // const parentNode = path.parentPath.node;
86
+ // if (t.isClassProperty(parentNode)) {
87
+ // // @ts-ignore
88
+ // const propName = parentNode.key.name;
89
+ // // @ts-ignore
90
+ // this.classDeclarationPath = path.parentPath.parentPath.parentPath;
91
+ // // @ts-ignore
92
+ // const className = this.classDeclarationPath.node.id.name;
93
+ // this.tryMatch(path, propName, className, module);
94
+ // }
95
+ // }
96
+ // }
97
+ // isRightShape(path: NodePath<Function>): boolean {
98
+ // throw new Error("not implemented");
99
+ // }
100
+ // tryMatch(
101
+ // path: NodePath<Function>,
102
+ // propName: string,
103
+ // className: string,
104
+ // module: Module,
105
+ // ) {
106
+ // throw new Error("not implemented");
107
+ // }
108
+ // }
109
+ // class JsxFunctionAssignedToJsxClassProperty extends AbstractClassPropertyContext {
110
+ // isRightShape(path: NodePath<Function>): boolean {
111
+ // return !!functionReturnsOnlyJSX(path);
112
+ // }
113
+ // tryMatch(
114
+ // path: NodePath<Function>,
115
+ // propName: string,
116
+ // className: string,
117
+ // module: Module,
118
+ // ) {
119
+ // if (propName === "jsx") {
120
+ // this.initialiseComponent(className);
121
+ // module.requireImport(IMPORTABLES.extendComponent);
122
+ // } else {
123
+ // error(path.parentPath, ERROR_MESSAGES.CLASS_METHOD_MUST_BE_PROPERTY_JSX);
124
+ // }
125
+ // }
126
+ // applyTransformations(): void {
127
+ // processFunctionParameters(this.path, this.component);
128
+ // this.path.traverse(jsxVisitors, { component: this.component });
129
+ // this.classDeclarationPath.insertAfter(
130
+ // buildExtendComponentCall(this.component),
131
+ // );
132
+ // }
133
+ // }
134
+ const contextClasses = [
135
+ AssignedJsxFunction,
136
+ // JsxClassMethod,
137
+ // JsxFunctionAssignedToJsxClassProperty,
138
+ ];
139
+ function identifyContextToBeHandled(path, module) {
140
+ const contexts = [];
141
+ contextClasses.forEach((contextClass) => {
142
+ contexts.push(new contextClass(path, module));
143
+ });
144
+ const matches = contexts.filter((context) => context.isMatch);
145
+ if (matches.length > 1) {
146
+ throw new Error("Function matches more than one context. This is an error with the plugin.");
147
+ }
148
+ else if (matches.length === 1) {
149
+ return matches[0];
150
+ }
151
+ }
152
+ //# sourceMappingURL=handlers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/contexts/handlers.ts"],"names":[],"mappings":";;AAiKA,gEAgBC;AAjLD,kCAAkC;AAGlC,4CAA2C;AAC3C,yCAA8C;AAC9C,0CAGqB;AACrB,sCAAkD;AAClD,sCAA8C;AAC9C,wCAAoD;AACpD,oCAAyC;AACzC,6CAAyD;AAEzD;;GAEG;AACH,MAAM,sBAAsB;IAM1B,YAAY,IAAwB,EAAE,MAAc;QAHpD,YAAO,GAAY,KAAK,CAAC;QAIvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IACD,oBAAoB;QAClB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACrC,CAAC;IACD,mBAAmB,CAAC,aAAqB;QACvC,IAAI,CAAC,IAAA,qBAAa,EAAC,aAAa,CAAC,EAAE,CAAC;YAClC,IAAA,cAAK,EAAC,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,uBAAc,CAAC,0BAA0B,CAAC,CAAC;QACzE,CAAC;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,IAAI,kBAAS,CAC5B,aAAa,EACb,IAAI,CAAC,MAAM,EACX,KAAK,CAAC,qBAAqB,CAAC,GAAG,CAAC,EAChC,KAAK,CAAC,qBAAqB,CAAC,GAAG,CAAC,CACjC,CAAC;QACF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;IACtB,CAAC;CACF;AAED,SAAS,eAAe,CAAC,IAAwB;IAC/C,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;IACxC,IAAI,CAAC,CAAC,oBAAoB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC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AAS;AACT,MAAM;AACN,IAAI;AAEJ,MAAM,cAAc,GAAG;IACrB,mBAAmB;IACnB,kBAAkB;IAClB,yCAAyC;CAC1C,CAAC;AAEF,SAAgB,0BAA0B,CACxC,IAAwB,EACxB,MAAc;IAEd,MAAM,QAAQ,GAAG,EAAE,CAAC;IACpB,cAAc,CAAC,OAAO,CAAC,CAAC,YAAY,EAAE,EAAE;QACtC,QAAQ,CAAC,IAAI,CAAC,IAAI,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;IAChD,CAAC,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC9D,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,2EAA2E,CAC5E,CAAC;IACJ,CAAC;SAAM,IAAI,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;AACH,CAAC"}
@@ -0,0 +1,2 @@
1
+ import { identifyContextToBeHandled } from "./handlers";
2
+ export { identifyContextToBeHandled as getJsxFunctionHandler };
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getJsxFunctionHandler = void 0;
4
+ const handlers_1 = require("./handlers");
5
+ Object.defineProperty(exports, "getJsxFunctionHandler", { enumerable: true, get: function () { return handlers_1.identifyContextToBeHandled; } });
6
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/contexts/index.ts"],"names":[],"mappings":";;;AAAA,yCAAwD;AACjB,sGAD9B,qCAA0B,OACyB"}
@@ -0,0 +1,8 @@
1
+ import type { NodePath } from "@babel/core";
2
+ import type { Function } from "@babel/types";
3
+ import { Component } from "../models";
4
+ /**
5
+ * Process JSX function parameters which included destructuring, renaming and checking
6
+ * for illegal names.
7
+ */
8
+ export declare function processFunctionParameters(path: NodePath<Function>, component: Component): void;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processFunctionParameters = processFunctionParameters;
4
+ const t = require("@babel/types");
5
+ const constants_1 = require("../constants");
6
+ const errors_1 = require("../errors");
7
+ function splitLast(s, on) {
8
+ const chunks = s.split(on);
9
+ const len = chunks.length;
10
+ return [chunks[len - 1], len > 1 ? chunks.splice(0, len - 1).join(on) : null];
11
+ }
12
+ /**
13
+ * Expands a name to a member expression if it has dots. Works recursively.
14
+ *
15
+ * "a" > t.Identifier('a')
16
+ * "a.b" > t.MemberExpression(...)
17
+ */
18
+ function expandNameToMemberExpression(name) {
19
+ const [end, rest] = splitLast(name, ".");
20
+ if (rest === null) {
21
+ return t.identifier(end);
22
+ }
23
+ return t.memberExpression(expandNameToMemberExpression(rest), t.identifier(end));
24
+ }
25
+ function checkForIllegalNamesInProps(path, propVariableMap) {
26
+ const illegalNamesFound = [];
27
+ for (let name in constants_1.EVENT_CALLBACK_VARIABLES) {
28
+ const variable = constants_1.EVENT_CALLBACK_VARIABLES[name];
29
+ if (propVariableMap.hasOwnProperty(variable)) {
30
+ illegalNamesFound.push(variable);
31
+ }
32
+ }
33
+ if (illegalNamesFound.length > 0) {
34
+ (0, errors_1.error)(path, errors_1.ERROR_MESSAGES.ILLEGAL_NAMES_IN_PROPS(illegalNamesFound));
35
+ }
36
+ }
37
+ function checkForIllegalNamesInRemainingParameters(path) {
38
+ const extraParameters = path.node.params.slice(1);
39
+ for (const param of extraParameters) {
40
+ if (t.isIdentifier(param)) {
41
+ const name = param["name"];
42
+ if (!Object.values(constants_1.EVENT_CALLBACK_VARIABLES).includes(name)) {
43
+ (0, errors_1.error)(path, errors_1.ERROR_MESSAGES.ILLEGAL_PARAMETERS(name));
44
+ }
45
+ }
46
+ else {
47
+ (0, errors_1.error)(path, errors_1.ERROR_MESSAGES.ILLEGAL_PARAMETERS(param.type));
48
+ }
49
+ }
50
+ }
51
+ function renamePropKeysInsideFunction(path, propVariableMap, propsVar) {
52
+ // Babel lets us set identifier names that look like member expressions, however...
53
+ for (const [key, value] of Object.entries(propVariableMap)) {
54
+ path.scope.rename(key, value === null ? propsVar : `${propsVar}.${value}`);
55
+ }
56
+ // We are now left with identifiers like `_p2.name` which messes up further renaming
57
+ // as that is seen as a single identifier rather than a memberExpression, so
58
+ // we need to replace those.
59
+ path.traverse({
60
+ Identifier(path) {
61
+ const name = path.node.name;
62
+ if (name.includes(".")) {
63
+ path.replaceWith(expandNameToMemberExpression(name));
64
+ }
65
+ },
66
+ });
67
+ }
68
+ function extractFinalPropsName(path) {
69
+ const propVariableMap = {};
70
+ const propsParam = path.node.params[0];
71
+ if (t.isObjectPattern(propsParam)) {
72
+ // key: prop on original object, may be an ObjectPattern
73
+ // value: as used in function
74
+ for (const prop of propsParam.properties) {
75
+ if (t.isObjectProperty(prop)) {
76
+ if (t.isIdentifier(prop.value) && t.isIdentifier(prop.key)) {
77
+ propVariableMap[prop.value.name] = prop.key.name;
78
+ }
79
+ else {
80
+ // ObjectPattern - TODO: allow further deconstruction.
81
+ throw new Error(`Unexpected prop value type: ${prop.type}`);
82
+ }
83
+ }
84
+ else {
85
+ throw new Error(`Unexpected prop key type: ${prop.type}`);
86
+ }
87
+ }
88
+ }
89
+ else if (t.isIdentifier(propsParam)) {
90
+ propVariableMap[propsParam.name] = null;
91
+ }
92
+ else {
93
+ throw new Error(`Unexpected props param type: ${propsParam.type}`);
94
+ }
95
+ return propVariableMap;
96
+ }
97
+ function renameComponentInsideFunction(path, componentVar) {
98
+ path.scope.rename(constants_1.EVENT_CALLBACK_VARIABLES.component, componentVar);
99
+ }
100
+ /**
101
+ * Process JSX function parameters which included destructuring, renaming and checking
102
+ * for illegal names.
103
+ */
104
+ function processFunctionParameters(path, component) {
105
+ if (path.node.params.length < 1) {
106
+ return;
107
+ }
108
+ const propVariableMap = extractFinalPropsName(path);
109
+ checkForIllegalNamesInProps(path, propVariableMap);
110
+ checkForIllegalNamesInRemainingParameters(path);
111
+ renamePropKeysInsideFunction(path, propVariableMap, component.propsIdentifier.name);
112
+ renameComponentInsideFunction(path, component.componentIdentifier.name);
113
+ }
114
+ //# sourceMappingURL=parameters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parameters.js","sourceRoot":"","sources":["../../src/contexts/parameters.ts"],"names":[],"mappings":";;AAiIA,8DAgBC;AAjJD,kCAAkC;AAIlC,4CAAwD;AACxD,sCAAkD;AAMlD,SAAS,SAAS,CAAC,CAAS,EAAE,EAAU;IACtC,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IAC3B,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1B,OAAO,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;AAChF,CAAC;AAED;;;;;GAKG;AACH,SAAS,4BAA4B,CACnC,IAAY;IAEZ,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,SAAS,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;IACzC,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,CAAC,CAAC,gBAAgB,CACvB,4BAA4B,CAAC,IAAI,CAAC,EAClC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAClB,CAAC;AACJ,CAAC;AAED,SAAS,2BAA2B,CAClC,IAAwB,EACxB,eAA0C;IAE1C,MAAM,iBAAiB,GAAG,EAAE,CA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AC9D,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,MAAM,IAAI,KAAK,CAAC,6BAA6B,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YAC5D,CAAC;QACH,CAAC;IACH,CAAC;SAAM,IAAI,CAAC,CAAC,YAAY,CAAC,UAAU,CAAC,EAAE,CAAC;QACtC,eAAe,CAAC,UAAU,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC1C,CAAC;SAAM,CAAC;QACN,MAAM,IAAI,KAAK,CAAC,gCAAgC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC;IACrE,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,SAAS,6BAA6B,CACpC,IAAwB,EACxB,YAAoB;IAEpB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,oCAAwB,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;AACtE,CAAC;AAED;;;GAGG;AACH,SAAgB,yBAAyB,CACvC,IAAwB,EACxB,SAAoB;IAEpB,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,OAAO;IACT,CAAC;IACD,MAAM,eAAe,GAAG,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACpD,2BAA2B,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IACnD,yCAAyC,CAAC,IAAI,CAAC,CAAC;IAChD,4BAA4B,CAC1B,IAAI,EACJ,eAAe,EACf,SAAS,CAAC,eAAe,CAAC,IAAI,CAC/B,CAAC;IACF,6BAA6B,CAAC,IAAI,EAAE,SAAS,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;AAC1E,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Directive, TagNode, NodeValue, Qualifier } from "./models";
2
+ declare class BaseDirective extends Directive {
3
+ static attributeName: string;
4
+ static help: string;
5
+ apply(node: TagNode, value: NodeValue, qualifier: Qualifier, base: string): void;
6
+ }
7
+ export declare const builtinDirectives: (typeof BaseDirective)[];
8
+ export {};
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.builtinDirectives = void 0;
4
+ const models_1 = require("./models");
5
+ class BaseDirective extends models_1.Directive {
6
+ apply(node, value, qualifier, base) {
7
+ node.setBaseComponent(value.expression);
8
+ }
9
+ }
10
+ BaseDirective.attributeName = "base";
11
+ BaseDirective.help = `
12
+ Causes this componento to extend (inherit from) a base component:
13
+
14
+ /h <div base={OtherComponent}></div>
15
+ `;
16
+ class HelpDirective extends models_1.Directive {
17
+ apply(node, value, qualifier, base) {
18
+ console.log(`Help launched`);
19
+ }
20
+ }
21
+ HelpDirective.attributeName = "help";
22
+ HelpDirective.help = `
23
+ Displays the help system:
24
+
25
+ /h <div help></div>
26
+ `;
27
+ class HideDirective extends models_1.Directive {
28
+ apply(node, value, qualifier, base) {
29
+ // this.ensureValueType();
30
+ node.setConditionalDisplay(value.expression, false);
31
+ }
32
+ }
33
+ HideDirective.attributeName = "hide";
34
+ HideDirective.help = `
35
+ Conditionally hides an element and all nested elements.
36
+
37
+ /h <div hide={}></div>
38
+ `;
39
+ class OnEventDirective extends models_1.Directive {
40
+ apply(node, value, qualifier, base) {
41
+ // TODO: change behaviour if value vs expression
42
+ if (value.type === "string") {
43
+ node.addFixedAttribute(base, value.value);
44
+ }
45
+ else {
46
+ node.addEventListener(base.substring(2).toLowerCase(), value.expression);
47
+ }
48
+ }
49
+ }
50
+ OnEventDirective.attributeName = "on*";
51
+ OnEventDirective.help = `
52
+ Creates an event handler:
53
+
54
+ /h <div onclick={alert('hello')}></div>
55
+ `;
56
+ class PropsDirective extends models_1.Directive {
57
+ apply(node, value, _qualifier, _base) {
58
+ node.setProps(value.expression);
59
+ }
60
+ }
61
+ PropsDirective.attributeName = "props";
62
+ class RefDirective extends models_1.Directive {
63
+ apply(node, _value, qualifier, _base) {
64
+ node.setRef(qualifier);
65
+ }
66
+ }
67
+ RefDirective.attributeName = "ref";
68
+ RefDirective.help = `
69
+ Saves a reference to an element:
70
+
71
+ /h <div ref:title></div>
72
+ `;
73
+ class ShowDirective extends models_1.Directive {
74
+ apply(node, value, _qualifier, _base) {
75
+ // this.ensureValueType();
76
+ node.setConditionalDisplay(value.expression, true);
77
+ }
78
+ }
79
+ ShowDirective.attributeName = "show";
80
+ ShowDirective.help = `
81
+ Conditionally shows an element and all nested elements.
82
+
83
+ /h <div show={}></div>
84
+ `;
85
+ exports.builtinDirectives = [
86
+ BaseDirective,
87
+ HelpDirective,
88
+ HideDirective,
89
+ OnEventDirective,
90
+ PropsDirective,
91
+ RefDirective,
92
+ ShowDirective,
93
+ ];
94
+ //# sourceMappingURL=directives.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"directives.js","sourceRoot":"","sources":["../src/directives.ts"],"names":[],"mappings":";;;AAAA,qCAAoE;AAEpE,MAAM,aAAc,SAAQ,kBAAS;IAOnC,KAAK,CAAC,IAAa,EAAE,KAAgB,EAAE,SAAoB,EAAE,IAAY;QACvE,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;;AARM,2BAAa,GAAG,MAAM,CAAC;AACvB,kBAAI,GAAG;;;;KAIX,CAAC;AAMN,MAAM,aAAc,SAAQ,kBAAS;IAOnC,KAAK,CAAC,IAAa,EAAE,KAAgB,EAAE,SAAoB,EAAE,IAAY;QACvE,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC/B,CAAC;;AARM,2BAAa,GAAG,MAAM,CAAC;AACvB,kBAAI,GAAG;;;;KAIX,CAAC;AAMN,MAAM,aAAc,SAAQ,kBAAS;IAOnC,KAAK,CAAC,IAAa,EAAE,KAAgB,EAAE,SAAoB,EAAE,IAAY;QACvE,0BAA0B;QAC1B,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;;AATM,2BAAa,GAAG,MAAM,CAAC;AACvB,kB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