babel-plugin-wallace 0.0.2 → 0.0.6

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 (120) 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/config.d.ts +14 -0
  9. package/dist/config.js +47 -0
  10. package/dist/config.js.map +1 -0
  11. package/dist/consolidation/ComponentDefinitionData.d.ts +29 -0
  12. package/dist/consolidation/ComponentDefinitionData.js +82 -0
  13. package/dist/consolidation/ComponentDefinitionData.js.map +1 -0
  14. package/dist/consolidation/consolidateComponent.d.ts +6 -0
  15. package/dist/consolidation/consolidateComponent.js +41 -0
  16. package/dist/consolidation/consolidateComponent.js.map +1 -0
  17. package/dist/consolidation/index.d.ts +2 -0
  18. package/dist/consolidation/index.js +8 -0
  19. package/dist/consolidation/index.js.map +1 -0
  20. package/dist/consolidation/processNodes.d.ts +3 -0
  21. package/dist/consolidation/processNodes.js +202 -0
  22. package/dist/consolidation/processNodes.js.map +1 -0
  23. package/dist/consolidation/types.d.ts +15 -0
  24. package/dist/consolidation/types.js +3 -0
  25. package/dist/consolidation/types.js.map +1 -0
  26. package/dist/consolidation/utils.d.ts +21 -0
  27. package/dist/consolidation/utils.js +91 -0
  28. package/dist/consolidation/utils.js.map +1 -0
  29. package/dist/consolidation/visibility.d.ts +5 -0
  30. package/dist/consolidation/visibility.js +43 -0
  31. package/dist/consolidation/visibility.js.map +1 -0
  32. package/dist/constants.d.ts +31 -0
  33. package/dist/constants.js +40 -0
  34. package/dist/constants.js.map +1 -0
  35. package/dist/contexts/handlers.d.ts +18 -0
  36. package/dist/contexts/handlers.js +152 -0
  37. package/dist/contexts/handlers.js.map +1 -0
  38. package/dist/contexts/index.d.ts +2 -0
  39. package/dist/contexts/index.js +6 -0
  40. package/dist/contexts/index.js.map +1 -0
  41. package/dist/contexts/parameters.d.ts +8 -0
  42. package/dist/contexts/parameters.js +114 -0
  43. package/dist/contexts/parameters.js.map +1 -0
  44. package/dist/directives.d.ts +8 -0
  45. package/dist/directives.js +193 -0
  46. package/dist/directives.js.map +1 -0
  47. package/dist/errors.d.ts +34 -0
  48. package/dist/errors.js +47 -0
  49. package/dist/errors.js.map +1 -0
  50. package/dist/helpers.d.ts +4 -0
  51. package/dist/helpers.js +35 -0
  52. package/dist/helpers.js.map +1 -0
  53. package/dist/index.d.ts +10 -0
  54. package/dist/index.js +34 -0
  55. package/dist/index.js.map +1 -0
  56. package/dist/models/component.d.ts +25 -0
  57. package/dist/models/component.js +114 -0
  58. package/dist/models/component.js.map +1 -0
  59. package/dist/models/directive.d.ts +13 -0
  60. package/dist/models/directive.js +8 -0
  61. package/dist/models/directive.js.map +1 -0
  62. package/dist/models/index.d.ts +5 -0
  63. package/dist/models/index.js +15 -0
  64. package/dist/models/index.js.map +1 -0
  65. package/dist/models/module.d.ts +12 -0
  66. package/dist/models/module.js +40 -0
  67. package/dist/models/module.js.map +1 -0
  68. package/dist/models/node.d.ts +107 -0
  69. package/dist/models/node.js +327 -0
  70. package/dist/models/node.js.map +1 -0
  71. package/dist/utils.d.ts +13 -0
  72. package/dist/utils.js +66 -0
  73. package/dist/utils.js.map +1 -0
  74. package/dist/visitors/attribute.d.ts +10 -0
  75. package/dist/visitors/attribute.js +82 -0
  76. package/dist/visitors/attribute.js.map +1 -0
  77. package/dist/visitors/jsx.d.ts +13 -0
  78. package/dist/visitors/jsx.js +61 -0
  79. package/dist/visitors/jsx.js.map +1 -0
  80. package/dist/visitors/program.d.ts +12 -0
  81. package/dist/visitors/program.js +26 -0
  82. package/dist/visitors/program.js.map +1 -0
  83. package/dist/writers/define-component.d.ts +7 -0
  84. package/dist/writers/define-component.js +101 -0
  85. package/dist/writers/define-component.js.map +1 -0
  86. package/dist/writers/index.d.ts +1 -0
  87. package/dist/writers/index.js +7 -0
  88. package/dist/writers/index.js.map +1 -0
  89. package/package.json +20 -10
  90. package/README.md +0 -3
  91. package/lib/_config/directives.js +0 -356
  92. package/lib/_config/index.js +0 -2
  93. package/lib/_config/loader.js +0 -43
  94. package/lib/_config/parse_directives.js +0 -63
  95. package/lib/config.js +0 -263
  96. package/lib/convert.js +0 -27
  97. package/lib/definitions/constants.js +0 -73
  98. package/lib/definitions/node_data.js +0 -183
  99. package/lib/definitions/watcher.js +0 -26
  100. package/lib/generate/code_generator.js +0 -333
  101. package/lib/generate/statement_builders.js +0 -130
  102. package/lib/help-system/browser-code.js +0 -50
  103. package/lib/help-system/entry.js +0 -92
  104. package/lib/help-system/error-display.js +0 -20
  105. package/lib/help-system/styles.css +0 -25
  106. package/lib/import-checker.js +0 -35
  107. package/lib/index.js +0 -47
  108. package/lib/jsx/component_dom.js +0 -40
  109. package/lib/jsx/contexts.js +0 -121
  110. package/lib/jsx/extract.js +0 -214
  111. package/lib/jsx/parse.js +0 -98
  112. package/lib/parse/component_templates.js +0 -44
  113. package/lib/parse/inline_directives.js +0 -318
  114. package/lib/parse/parse_node.js +0 -73
  115. package/lib/polyfills.js +0 -10
  116. package/lib/utils/babel.js +0 -100
  117. package/lib/utils/dom.js +0 -174
  118. package/lib/utils/misc.js +0 -152
  119. package/lib_old/handlers.js +0 -52
  120. package/lib_old/index.js +0 -145
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2023 Andrew Buchan
3
+ Copyright (c) 2025 Andrew Buchan
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,10 @@
1
+ import type { NodePath } from "@babel/core";
2
+ import type { Expression, JSXElement, JSXEmptyExpression } from "@babel/types";
3
+ export declare function getJSXElementName(path: NodePath<JSXElement>): string | {
4
+ name: string;
5
+ namespace: string;
6
+ };
7
+ /**
8
+ * An Expression can be one of dozens of types, most of which are not usable.
9
+ */
10
+ export declare function getPlaceholderExpression(path: NodePath, expression: Expression | JSXEmptyExpression): Expression;
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getJSXElementName = getJSXElementName;
4
+ exports.getPlaceholderExpression = getPlaceholderExpression;
5
+ const t = require("@babel/types");
6
+ const errors_1 = require("./errors");
7
+ function getJSXElementName(path) {
8
+ const openingElementName = path.node.openingElement.name;
9
+ if (t.isJSXIdentifier(openingElementName)) {
10
+ return openingElementName.name;
11
+ }
12
+ else if (t.isJSXNamespacedName(openingElementName)) {
13
+ const { namespace, name } = openingElementName;
14
+ return { namespace: namespace.name, name: name.name };
15
+ }
16
+ else if (t.isJSXMemberExpression(openingElementName)) {
17
+ const { object, property } = openingElementName;
18
+ if (t.isJSXIdentifier(object)) {
19
+ return { namespace: object.name, name: property.name };
20
+ }
21
+ else {
22
+ (0, errors_1.error)(path, errors_1.ERROR_MESSAGES.ARROW_FUNCTION_NOT_ASSIGNED);
23
+ }
24
+ }
25
+ else {
26
+ console.debug(path.node);
27
+ throw Error(`Can't read name from ${openingElementName}`);
28
+ }
29
+ }
30
+ /**
31
+ * An Expression can be one of dozens of types, most of which are not usable.
32
+ */
33
+ function getPlaceholderExpression(path, expression) {
34
+ // if (
35
+ // // TODO: I probably need to expand this...
36
+ // t.isIdentifier(expression) ||
37
+ // t.isMemberExpression(expression) ||
38
+ // t.isCallExpression(expression)
39
+ // ) {
40
+ // return expression;
41
+ // } else
42
+ if (t.isJSXEmptyExpression(expression)) {
43
+ (0, errors_1.error)(path, errors_1.ERROR_MESSAGES.PLACEHOLDER_MAY_NOT_BE_EMPTY);
44
+ }
45
+ else if (t.isObjectExpression(expression)) {
46
+ // The code is copied, so the object would be created afresh each time.
47
+ (0, errors_1.error)(path, errors_1.ERROR_MESSAGES.PLACEHOLDER_MAY_NOT_BE_LITERAL_OBJECT);
48
+ }
49
+ //error(path, ERROR_MESSAGES.INVALID_PLACEHOLDER_EXPRESSION);
50
+ return expression;
51
+ }
52
+ //# sourceMappingURL=ast-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast-helpers.js","sourceRoot":"","sources":["../src/ast-helpers.ts"],"names":[],"mappings":";;AAKA,8CAoBC;AAKD,4DAoBC;AAlDD,kCAAkC;AAGlC,qCAAiD;AAEjD,SAAgB,iBAAiB,CAC/B,IAA0B;IAE1B,MAAM,kBAAkB,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;IACzD,IAAI,CAAC,CAAC,eAAe,CAAC,kBAAkB,CAAC,EAAE,CAAC;QAC1C,OAAO,kBAAkB,CAAC,IAAI,CAAC;IACjC,CAAC;SAAM,IAAI,CAAC,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACrD,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,kBAAkB,CAAC;QAC/C,OAAO,EAAE,SAAS,EAAE,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;IACxD,CAAC;SAAM,IAAI,CAAC,CAAC,qBAAqB,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACvD,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,kBAAkB,CAAC;QAChD,IAAI,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,CAAC;YAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;QACzD,CAAC;aAAM,CAAC;YACN,IAAA,cAAK,EAAC,IAAI,EAAE,uBAAc,CAAC,2BAA2B,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzB,MAAM,KAAK,CAAC,wBAAwB,kBAAkB,EAAE,CAAC,CAAC;IAC5D,CAAC;AACH,CAAC;AAED;;GAEG;AACH,SAAgB,wBAAwB,CACtC,IAAc,EACd,UAA2C;IAE3C,OAAO;IACP,+CAA+C;IAC/C,kCAAkC;IAClC,wCAAwC;IACxC,mCAAmC;IACnC,MAAM;IACN,uBAAuB;IACvB,SAAS;IACT,IAAI,CAAC,CAAC,oBAAoB,CAAC,UAAU,CAAC,EAAE,CAAC;QACvC,IAAA,cAAK,EAAC,IAAI,EAAE,uBAAc,CAAC,4BAA4B,CAAC,CAAC;IAC3D,CAAC;SAAM,IAAI,CAAC,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,CAAC;QAC5C,uEAAuE;QACvE,IAAA,cAAK,EAAC,IAAI,EAAE,uBAAc,CAAC,qCAAqC,CAAC,CAAC;IACpE,CAAC;IACD,6DAA6D;IAC7D,OAAO,UAAwB,CAAC;AAClC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type * as BabelCoreNamespace from "@babel/core";
2
+ import type * as BabelTypesNamespace from "@babel/types";
3
+ export type Babel = typeof BabelCoreNamespace;
4
+ export type BabelTypes = typeof BabelTypesNamespace;
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=babel-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"babel-types.js","sourceRoot":"","sources":["../src/babel-types.ts"],"names":[],"mappings":""}
@@ -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,29 @@
1
+ import type { Expression, CallExpression, FunctionExpression, Identifier } from "@babel/types";
2
+ import { Component } from "../models";
3
+ import { IMPORTABLES } from "../constants";
4
+ import { ComponentWatch, NodeAddress } from "./types";
5
+ /**
6
+ * An object with all the consolidated data for writing.
7
+ */
8
+ export declare class ComponentDefinitionData {
9
+ #private;
10
+ component: Component;
11
+ html: string;
12
+ watches: Array<ComponentWatch>;
13
+ stash: {
14
+ [key: string]: CallExpression;
15
+ };
16
+ baseComponent: Expression | undefined;
17
+ lookups: {
18
+ [key: string]: FunctionExpression;
19
+ };
20
+ collectedRefs: Array<string>;
21
+ constructor(component: Component);
22
+ saveElementToStash(address: NodeAddress): string;
23
+ saveNestedClassToStash(address: NodeAddress, componentCls: Expression): string;
24
+ addLookup(expression: Expression): string;
25
+ getFunctionIdentifier(name: IMPORTABLES): Identifier;
26
+ getLookupCallBackParams(): Array<Identifier>;
27
+ wrapStashCall(key: string, functionName: IMPORTABLES, remainingArgs: Expression[]): void;
28
+ getNextMiscObjectKey(): number;
29
+ }
@@ -0,0 +1,82 @@
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 _ComponentDefinitionData_stashKey, _ComponentDefinitionData_miscObjectKey, _ComponentDefinitionData_lookupKeys;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.ComponentDefinitionData = void 0;
16
+ const types_1 = require("@babel/types");
17
+ const utils_1 = require("./utils");
18
+ /**
19
+ * An object with all the consolidated data for writing.
20
+ */
21
+ class ComponentDefinitionData {
22
+ constructor(component) {
23
+ this.watches = [];
24
+ this.stash = {};
25
+ this.lookups = {};
26
+ this.collectedRefs = [];
27
+ _ComponentDefinitionData_stashKey.set(this, 0);
28
+ _ComponentDefinitionData_miscObjectKey.set(this, 0);
29
+ _ComponentDefinitionData_lookupKeys.set(this, []);
30
+ this.component = component;
31
+ this.baseComponent = component.baseComponent;
32
+ }
33
+ saveElementToStash(address) {
34
+ var _a;
35
+ __classPrivateFieldSet(this, _ComponentDefinitionData_stashKey, (_a = __classPrivateFieldGet(this, _ComponentDefinitionData_stashKey, "f"), _a++, _a), "f");
36
+ const key = String(__classPrivateFieldGet(this, _ComponentDefinitionData_stashKey, "f"));
37
+ this.stash[key] = (0, utils_1.buildFindElementCall)(this.component.module, address);
38
+ return key;
39
+ }
40
+ saveNestedClassToStash(address, componentCls) {
41
+ var _a;
42
+ __classPrivateFieldSet(this, _ComponentDefinitionData_stashKey, (_a = __classPrivateFieldGet(this, _ComponentDefinitionData_stashKey, "f"), _a++, _a), "f");
43
+ const key = String(__classPrivateFieldGet(this, _ComponentDefinitionData_stashKey, "f"));
44
+ this.stash[key] = (0, utils_1.buildNestedClassCall)(this.component.module, address, componentCls);
45
+ return key;
46
+ }
47
+ addLookup(expression) {
48
+ const hashExpression = (expr) => {
49
+ const copy = JSON.parse(JSON.stringify(expr));
50
+ (0, utils_1.removeKeys)(copy, ["start", "end", "loc"]);
51
+ return JSON.stringify(copy);
52
+ };
53
+ const hash = hashExpression(expression);
54
+ if (__classPrivateFieldGet(this, _ComponentDefinitionData_lookupKeys, "f").indexOf(hash) === -1) {
55
+ __classPrivateFieldGet(this, _ComponentDefinitionData_lookupKeys, "f").push(hash);
56
+ }
57
+ const key = String(__classPrivateFieldGet(this, _ComponentDefinitionData_lookupKeys, "f").indexOf(hash));
58
+ this.lookups[key] = (0, types_1.functionExpression)(null, this.getLookupCallBackParams(), (0, types_1.blockStatement)([(0, types_1.returnStatement)(expression)]));
59
+ return key;
60
+ }
61
+ getFunctionIdentifier(name) {
62
+ this.component.module.requireImport(name);
63
+ return (0, types_1.identifier)(name);
64
+ }
65
+ getLookupCallBackParams() {
66
+ return [this.component.propsIdentifier, this.component.componentIdentifier];
67
+ }
68
+ wrapStashCall(key, functionName, remainingArgs) {
69
+ this.stash[key] = (0, types_1.callExpression)(this.getFunctionIdentifier(functionName), [
70
+ this.stash[key],
71
+ ...remainingArgs,
72
+ ]);
73
+ }
74
+ getNextMiscObjectKey() {
75
+ var _a;
76
+ __classPrivateFieldSet(this, _ComponentDefinitionData_miscObjectKey, (_a = __classPrivateFieldGet(this, _ComponentDefinitionData_miscObjectKey, "f"), _a++, _a), "f");
77
+ return __classPrivateFieldGet(this, _ComponentDefinitionData_miscObjectKey, "f") - 1;
78
+ }
79
+ }
80
+ exports.ComponentDefinitionData = ComponentDefinitionData;
81
+ _ComponentDefinitionData_stashKey = new WeakMap(), _ComponentDefinitionData_miscObjectKey = new WeakMap(), _ComponentDefinitionData_lookupKeys = new WeakMap();
82
+ //# sourceMappingURL=ComponentDefinitionData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ComponentDefinitionData.js","sourceRoot":"","sources":["../../src/consolidation/ComponentDefinitionData.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAMA,wCAMsB;AAItB,mCAIiB;AAEjB;;GAEG;AACH,MAAa,uBAAuB;IAWlC,YAAY,SAAoB;QARhC,YAAO,GAA0B,EAAE,CAAC;QACpC,UAAK,GAAsC,EAAE,CAAC;QAE9C,YAAO,GAA0C,EAAE,CAAC;QACpD,kBAAa,GAAkB,EAAE,CAAC;QAClC,4CAAoB,CAAC,EAAC;QACtB,iDAAyB,CAAC,EAAC;QAC3B,8CAA6B,EAAE,EAAC;QAE9B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC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AAC,IAAI,CAAC,CAAC;QAC9B,CAAC;QACD,MAAM,GAAG,GAAG,MAAM,CAAC,uBAAA,IAAI,2CAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;QACnD,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,IAAA,0BAAkB,EACpC,IAAI,EACJ,IAAI,CAAC,uBAAuB,EAAE,EAC9B,IAAA,sBAAc,EAAC,CAAC,IAAA,uBAAe,EAAC,UAAU,CAAC,CAAC,CAAC,CAC9C,CAAC;QACF,OAAO,GAAG,CAAC;IACb,CAAC;IACD,qBAAqB,CAAC,IAAiB;QACrC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;QAC1C,OAAO,IAAA,kBAAU,EAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IACD,uBAAuB;QACrB,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CAAC;IAC9E,CAAC;IACD,aAAa,CACX,GAAW,EACX,YAAyB,EACzB,aAA2B;QAE3B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAA,sBAAc,EAAC,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,EAAE;YACzE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;YACf,GAAG,aAAa;SACjB,CAAC,CAAC;IACL,CAAC;IACD,oBAAoB;;QAClB,qEAAA,CAAA,8EAAmB,EAAnB,IAAqB,IAAA,CAAA,MAAA,CAAC;QACtB,OAAO,uBAAA,IAAI,8CAAe,GAAG,CAAC,CAAC;IACjC,CAAC;CACF;AAtED,0DAsEC"}
@@ -0,0 +1,6 @@
1
+ import { Component } from "../models";
2
+ import { ComponentDefinitionData } from "./ComponentDefinitionData";
3
+ /**
4
+ * Deals with shielding, setting ref keys and such.
5
+ */
6
+ export declare function consolidateComponent(component: Component): ComponentDefinitionData;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.consolidateComponent = consolidateComponent;
4
+ const models_1 = require("../models");
5
+ const visibility_1 = require("./visibility");
6
+ const ComponentDefinitionData_1 = require("./ComponentDefinitionData");
7
+ const processNodes_1 = require("./processNodes");
8
+ const utils_1 = require("./utils");
9
+ /**
10
+ * If a node contains only a JSXExpression, then rather than make a span, we set
11
+ * textContent on that node.
12
+ */
13
+ function hoistTextNodes(component) {
14
+ const nodesToDelete = [];
15
+ component.extractedNodes.forEach((node) => {
16
+ if (node instanceof models_1.DynamicTextNode) {
17
+ if ((0, utils_1.getSiblings)(node, component.extractedNodes).length === 0) {
18
+ const parent = node.parent;
19
+ parent.watches.push(...node.watches);
20
+ nodesToDelete.push(node);
21
+ node.element.remove();
22
+ }
23
+ }
24
+ });
25
+ nodesToDelete.forEach((node) => {
26
+ component.extractedNodes.splice(component.extractedNodes.indexOf(node), 1);
27
+ });
28
+ }
29
+ /**
30
+ * Deals with shielding, setting ref keys and such.
31
+ */
32
+ function consolidateComponent(component) {
33
+ const componentDefinition = new ComponentDefinitionData_1.ComponentDefinitionData(component);
34
+ hoistTextNodes(component);
35
+ (0, processNodes_1.processNodes)(component, componentDefinition);
36
+ (0, visibility_1.processShields)(componentDefinition.watches);
37
+ // This must be done after all the processing, as DOM may have changed.
38
+ componentDefinition.html = component.rootElement.outerHTML;
39
+ return componentDefinition;
40
+ }
41
+ //# sourceMappingURL=consolidateComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consolidateComponent.js","sourceRoot":"","sources":["../../src/consolidation/consolidateComponent.ts"],"names":[],"mappings":";;AA8BA,oDAUC;AAxCD,sCAAuD;AACvD,6CAA8C;AAC9C,uEAAoE;AACpE,iDAA8C;AAC9C,mCAAsC;AAEtC;;;GAGG;AACH,SAAS,cAAc,CAAC,SAAoB;IAC1C,MAAM,aAAa,GAAG,EAAE,CAAC;IACzB,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QACxC,IAAI,IAAI,YAAY,wBAAe,EAAE,CAAC;YACpC,IAAI,IAAA,mBAAW,EAAC,IAAI,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC7D,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;gBAC3B,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;gBACrC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACzB,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACxB,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;IACH,aAAa,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC7B,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAClC,SAAoB;IAEpB,MAAM,mBAAmB,GAAG,IAAI,iDAAuB,CAAC,SAAS,CAAC,CAAC;IACnE,cAAc,CAAC,SAAS,CAAC,CAAC;IAC1B,IAAA,2BAAY,EAAC,SAAS,EAAE,mBAAmB,CAAC,CAAC;IAC7C,IAAA,2BAAc,EAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAC5C,uEAAuE;IACvE,mBAAmB,CAAC,IAAI,GAAG,SAAS,CAAC,WAAW,CAAC,SAAS,CAAC;IAC3D,OAAO,mBAAmB,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { ComponentDefinitionData } from "./ComponentDefinitionData";
2
+ export { consolidateComponent } from "./consolidateComponent";
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.consolidateComponent = exports.ComponentDefinitionData = void 0;
4
+ var ComponentDefinitionData_1 = require("./ComponentDefinitionData");
5
+ Object.defineProperty(exports, "ComponentDefinitionData", { enumerable: true, get: function () { return ComponentDefinitionData_1.ComponentDefinitionData; } });
6
+ var consolidateComponent_1 = require("./consolidateComponent");
7
+ Object.defineProperty(exports, "consolidateComponent", { enumerable: true, get: function () { return consolidateComponent_1.consolidateComponent; } });
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/consolidation/index.ts"],"names":[],"mappings":";;;AAAA,qEAAoE;AAA3D,kIAAA,uBAAuB,OAAA;AAChC,+DAA8D;AAArD,4HAAA,oBAAoB,OAAA"}
@@ -0,0 +1,3 @@
1
+ import { Component } from "../models";
2
+ import { ComponentDefinitionData } from "./ComponentDefinitionData";
3
+ export declare function processNodes(component: Component, componentDefinition: ComponentDefinitionData): void;
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processNodes = processNodes;
4
+ const types_1 = require("@babel/types");
5
+ const t = require("@babel/types");
6
+ const utils_1 = require("../utils");
7
+ const errors_1 = require("../errors");
8
+ const constants_1 = require("../constants");
9
+ const utils_2 = require("./utils");
10
+ function addBindInstruction(node) {
11
+ if (node.tagName.toLowerCase() == "input") {
12
+ // @ts-ignore
13
+ const inputType = node.element.type.toLowerCase();
14
+ const attribute = inputType === "checkbox" ? "checked" : "value";
15
+ node.bindInstructions.forEach(({ eventName, expression }) => {
16
+ node.watchAttribute(attribute, expression);
17
+ const callback = t.assignmentExpression("=", expression, t.memberExpression(t.identifier(constants_1.EVENT_CALLBACK_VARIABLES.element), t.identifier(attribute)));
18
+ node.addEventListener(eventName, callback);
19
+ });
20
+ }
21
+ else {
22
+ (0, errors_1.error)(node.path, errors_1.ERROR_MESSAGES.BIND_ONLY_ALLOWED_ON_INPUT);
23
+ }
24
+ }
25
+ function addShieldInfo(componentDefinition, componentWatch, shieldInfo) {
26
+ const shieldLookupKey = componentDefinition.addLookup(shieldInfo.expression);
27
+ componentWatch.shieldInfo = {
28
+ count: 0,
29
+ key: shieldLookupKey,
30
+ reverse: shieldInfo.reverse,
31
+ };
32
+ }
33
+ function ensureToggleTargetsHaveTriggers(node) {
34
+ node.toggleTargets.forEach((target) => {
35
+ const match = node.toggleTriggers.find((trigger) => trigger.name == target.name);
36
+ if (!match) {
37
+ (0, errors_1.error)(node.path, errors_1.ERROR_MESSAGES.TOGGLE_TARGETS_WITHOUT_TOGGLE_TRIGGERS);
38
+ }
39
+ });
40
+ }
41
+ function extractCssClasses(value) {
42
+ if (typeof value == "string") {
43
+ return value
44
+ .trim()
45
+ .split(" ")
46
+ .map((v) => t.stringLiteral(v));
47
+ }
48
+ else {
49
+ return [t.spreadElement(value)];
50
+ }
51
+ }
52
+ // Notes: toggles are implemented as add/remove because:
53
+ // a) they allow multiple classes
54
+ // b) it's less brittle around truthiness
55
+ function addToggleCallbackStatement(componentDefinition, node, addCallbackStatement) {
56
+ node.toggleTriggers.forEach((trigger) => {
57
+ const target = node.toggleTargets.find((target) => target.name == trigger.name);
58
+ const classesToToggle = target
59
+ ? extractCssClasses(target.value)
60
+ : [t.stringLiteral(trigger.name)];
61
+ const toBoolExpression = trigger.expression;
62
+ const lookupKey = componentDefinition.addLookup(toBoolExpression);
63
+ const getCallback = (method) => (0, types_1.callExpression)((0, types_1.memberExpression)((0, types_1.memberExpression)((0, types_1.identifier)(constants_1.WATCH_CALLBACK_PARAMS.element), (0, types_1.identifier)("classList")), (0, types_1.identifier)(method)), classesToToggle);
64
+ addCallbackStatement(lookupKey, [
65
+ t.ifStatement(t.identifier(constants_1.WATCH_CALLBACK_PARAMS.newValue), (0, types_1.blockStatement)([(0, types_1.expressionStatement)(getCallback("add"))]), (0, types_1.blockStatement)([(0, types_1.expressionStatement)(getCallback("remove"))])),
66
+ ]);
67
+ });
68
+ }
69
+ // TODO: break this up.
70
+ function processNodes(component, componentDefinition) {
71
+ component.extractedNodes.forEach((node) => {
72
+ if (node.isRepeatedNode) {
73
+ // The watch should already have been added to the parent node, which is already
74
+ // processed. All we do here is run some extra checks.
75
+ const siblings = (0, utils_2.getSiblings)(node, component.extractedNodes);
76
+ if (siblings.length > 0) {
77
+ (0, errors_1.error)(node.path, errors_1.ERROR_MESSAGES.REPEAT_DIRECTIVE_WITH_SIBLINGS);
78
+ }
79
+ const children = (0, utils_2.getChildren)(node, component.extractedNodes);
80
+ if (children.length > 0) {
81
+ (0, errors_1.error)(node.path, errors_1.ERROR_MESSAGES.REPEAT_DIRECTIVE_WITH_CHILDREN);
82
+ }
83
+ return;
84
+ }
85
+ const stubName = node.getStub();
86
+ const stubComponentName = stubName
87
+ ? t.memberExpression(t.identifier(constants_1.COMPONENT_BUILD_PARAMS.component), t.identifier(stubName))
88
+ : undefined;
89
+ const shieldInfo = node.getShieldInfo();
90
+ const ref = node.getRef();
91
+ const repeatInstruction = node.getRepeatInstruction();
92
+ const createWatch = node.watches.length > 0 ||
93
+ node.bindInstructions.length > 0 ||
94
+ node.toggleTriggers.length > 0 ||
95
+ shieldInfo ||
96
+ node.isNestedClass ||
97
+ stubName ||
98
+ repeatInstruction;
99
+ const shouldStash = createWatch || ref || node.eventListeners.length > 0;
100
+ ensureToggleTargetsHaveTriggers(node);
101
+ if (shouldStash) {
102
+ const nestedComponentCls = node.isNestedClass
103
+ ? t.identifier(node.tagName)
104
+ : stubComponentName;
105
+ const stashRef = nestedComponentCls
106
+ ? componentDefinition.saveNestedClassToStash(node.address, nestedComponentCls)
107
+ : componentDefinition.saveElementToStash(node.address);
108
+ if (node.bindInstructions.length) {
109
+ addBindInstruction(node);
110
+ }
111
+ if (createWatch) {
112
+ const _callbacks = {};
113
+ const addCallbackStatement = (key, statements) => {
114
+ if (!_callbacks.hasOwnProperty(key)) {
115
+ _callbacks[key] = [];
116
+ }
117
+ _callbacks[key].push(...statements);
118
+ };
119
+ const componentWatch = {
120
+ stashRef,
121
+ callbacks: {},
122
+ address: node.address,
123
+ };
124
+ componentDefinition.watches.push(componentWatch);
125
+ node.watches.forEach((watch) => {
126
+ const lookupKey = componentDefinition.addLookup(watch.expression);
127
+ addCallbackStatement(lookupKey, (0, utils_1.codeToNode)(watch.callback));
128
+ });
129
+ if (node.isNestedClass) {
130
+ const props = node.getProps();
131
+ const args = props ? [props] : [];
132
+ addCallbackStatement(constants_1.SPECIAL_SYMBOLS.alwaysUpdate, [
133
+ (0, types_1.expressionStatement)((0, types_1.callExpression)((0, types_1.memberExpression)((0, types_1.identifier)(constants_1.WATCH_CALLBACK_PARAMS.element), (0, types_1.identifier)("render")), args)),
134
+ ]);
135
+ }
136
+ if (node.toggleTriggers.length) {
137
+ addToggleCallbackStatement(componentDefinition, node, addCallbackStatement);
138
+ }
139
+ // Need to be careful with WATCH_CALLBACK_PARAMS
140
+ if (stubName) {
141
+ addCallbackStatement(constants_1.SPECIAL_SYMBOLS.alwaysUpdate, [
142
+ (0, types_1.expressionStatement)((0, types_1.callExpression)((0, types_1.memberExpression)((0, types_1.identifier)(constants_1.WATCH_CALLBACK_PARAMS.element), (0, types_1.identifier)("render")), [component.propsIdentifier])),
143
+ ]);
144
+ }
145
+ if (shieldInfo) {
146
+ addShieldInfo(componentDefinition, componentWatch, shieldInfo);
147
+ }
148
+ if (repeatInstruction) {
149
+ const miscObjectKey = componentDefinition.getNextMiscObjectKey();
150
+ componentDefinition.component.module.requireImport(constants_1.IMPORTABLES.getSequentialPool);
151
+ const poolInstance = repeatInstruction.poolExpression ||
152
+ (0, types_1.callExpression)((0, types_1.identifier)(constants_1.IMPORTABLES.getSequentialPool), [
153
+ (0, types_1.identifier)(repeatInstruction.componentCls),
154
+ ]);
155
+ componentDefinition.wrapStashCall(stashRef, constants_1.IMPORTABLES.saveMiscObject, [(0, types_1.identifier)(constants_1.COMPONENT_BUILD_PARAMS.component), poolInstance]);
156
+ addCallbackStatement(constants_1.SPECIAL_SYMBOLS.alwaysUpdate, [
157
+ (0, types_1.expressionStatement)((0, types_1.callExpression)((0, types_1.memberExpression)((0, types_1.memberExpression)((0, types_1.memberExpression)(component.componentIdentifier, (0, types_1.identifier)(constants_1.SPECIAL_SYMBOLS.objectStash)), (0, types_1.numericLiteral)(miscObjectKey), true), (0, types_1.identifier)(constants_1.SPECIAL_SYMBOLS.patch)), [
158
+ (0, types_1.identifier)(constants_1.WATCH_CALLBACK_PARAMS.element),
159
+ repeatInstruction.expression,
160
+ component.componentIdentifier,
161
+ ])),
162
+ ]);
163
+ }
164
+ for (const key in _callbacks) {
165
+ const args = key === constants_1.SPECIAL_SYMBOLS.alwaysUpdate
166
+ ? [
167
+ (0, types_1.identifier)(constants_1.WATCH_CALLBACK_PARAMS.element),
168
+ component.propsIdentifier,
169
+ component.componentIdentifier,
170
+ ]
171
+ : (0, utils_2.buildWatchCallbackParams)();
172
+ componentWatch.callbacks[key] = (0, types_1.functionExpression)(null, args, (0, types_1.blockStatement)(_callbacks[key]));
173
+ }
174
+ }
175
+ if (ref) {
176
+ if (componentDefinition.collectedRefs.includes(ref)) {
177
+ (0, errors_1.error)(node.path, errors_1.ERROR_MESSAGES.REFS_MUST_BE_UNIQUE_WITHIN_EACH_COMPONENT);
178
+ }
179
+ componentDefinition.collectedRefs.push(ref);
180
+ componentDefinition.wrapStashCall(stashRef, constants_1.IMPORTABLES.saveRef, [
181
+ (0, types_1.identifier)(constants_1.COMPONENT_BUILD_PARAMS.component),
182
+ (0, types_1.stringLiteral)(ref),
183
+ ]);
184
+ }
185
+ // Note that some things will already have been renamed, but here we are renaming
186
+ // specifically inside the buildComponent scope.
187
+ const eventVariableMapping = {
188
+ [component.componentIdentifier.name]: constants_1.COMPONENT_BUILD_PARAMS.component,
189
+ [component.propsIdentifier.name]: `${constants_1.COMPONENT_BUILD_PARAMS.component}.props`,
190
+ [constants_1.EVENT_CALLBACK_VARIABLES.element]: `${constants_1.EVENT_CALLBACK_VARIABLES.event}.target`,
191
+ };
192
+ node.eventListeners.forEach((listener) => {
193
+ const updatedExpression = (0, utils_2.renameVariablesInExpression)(listener.callback, eventVariableMapping);
194
+ componentDefinition.wrapStashCall(stashRef, constants_1.IMPORTABLES.onEvent, [
195
+ (0, types_1.stringLiteral)(listener.eventName),
196
+ (0, types_1.functionExpression)(null, [(0, types_1.identifier)(constants_1.EVENT_CALLBACK_VARIABLES.event)], (0, types_1.blockStatement)([(0, types_1.expressionStatement)(updatedExpression)])),
197
+ ]);
198
+ });
199
+ }
200
+ });
201
+ }
202
+ //# sourceMappingURL=processNodes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processNodes.js","sourceRoot":"","sources":["../../src/consolidation/processNodes.ts"],"names":[],"mappings":";;AAiIA,oCAuNC;AAvVD,wCASsB;AACtB,kCAAkC;AAClC,oCAAsC;AAEtC,sCAAkD;AAClD,4CAMsB;AAGtB,mCAKiB;AAEjB,SAAS,kBAAkB,CAAC,IAAmB;IAC7C,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,OAAO,EAAE,CAAC;QAC1C,aAAa;QACb,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;QAClD,MAAM,SAAS,GAAG,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;QACjE,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,EAAE,SAAS,EAAE,UAAU,EAAE,EAAE,EAAE;YAC1D,IAAI,CAAC,cAAc,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;YAC3C,MAAM,QAAQ,GAAG,CAAC,CAAC,oBAAoB,CACrC,GAAG,EACH,UAAwB,EACxB,CAAC,CAAC,gBAAgB,CAChB,CAAC,CAAC,UAAU,CAAC,oCAAwB,CAAC,OAAO,CAAC,EAC9C,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,CACxB,CACF,CAAC;YACF,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE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GAAG,IAAA,mCAA2B,EACnD,QAAQ,CAAC,QAAQ,EACjB,oBAAoB,CACrB,CAAC;gBAEF,mBAAmB,CAAC,aAAa,CAAC,QAAQ,EAAE,uBAAW,CAAC,OAAO,EAAE;oBAC/D,IAAA,qBAAa,EAAC,QAAQ,CAAC,SAAS,CAAC;oBACjC,IAAA,0BAAkB,EAChB,IAAI,EACJ,CAAC,IAAA,kBAAU,EAAC,oCAAwB,CAAC,KAAK,CAAC,CAAC,EAC5C,IAAA,sBAAc,EAAC,CAAC,IAAA,2BAAmB,EAAC,iBAAiB,CAAC,CAAC,CAAC,CACzD;iBACF,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { FunctionExpression } from "@babel/types";
2
+ export type NodeAddress = Array<number>;
3
+ export interface ShieldInfo {
4
+ key: string;
5
+ reverse: boolean;
6
+ count: number;
7
+ }
8
+ export interface ComponentWatch {
9
+ stashRef: string;
10
+ shieldInfo?: ShieldInfo | undefined;
11
+ callbacks: {
12
+ [key: string]: FunctionExpression;
13
+ };
14
+ address: NodeAddress;
15
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/consolidation/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ import type { ArrayExpression, Expression, CallExpression } from "@babel/types";
2
+ import { ExtractedNode, Module } from "../models";
3
+ import { NodeAddress } from "./types";
4
+ export declare function getSiblings(node: ExtractedNode, allNodes: Array<ExtractedNode>): ExtractedNode[];
5
+ export declare function getChildren(node: ExtractedNode, allNodes: Array<ExtractedNode>): ExtractedNode[];
6
+ export declare function buildAddressArray(address: NodeAddress): ArrayExpression;
7
+ export declare function buildFindElementCall(module: Module, address: NodeAddress): CallExpression;
8
+ export declare function buildNestedClassCall(module: Module, address: NodeAddress, componentCls: Expression): CallExpression;
9
+ export declare function removeKeys(obj: Object, keys: Array<string>): void;
10
+ /**
11
+ * Use this to rename variables when there is no scope.
12
+ * It came from chatGTP.
13
+ */
14
+ export declare function renameVariablesInExpression(originalExpression: Expression, variableMapping: {
15
+ [key: string]: string;
16
+ }): Expression;
17
+ /**
18
+ * No user code gets copied into the watch callback functions, so we can hardcode params
19
+ * as they won't clash with anything.
20
+ */
21
+ export declare function buildWatchCallbackParams(): import("@babel/types").Identifier[];