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
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jsxVisitors = void 0;
4
+ const ast_helpers_1 = require("../ast-helpers");
5
+ const errors_1 = require("../errors");
6
+ const utils_1 = require("../utils");
7
+ // Calls itself recursively, using trackers to identify where we are.
8
+ // Must delete visited nodes to avoid reprocessing them with recursion.
9
+ exports.jsxVisitors = {
10
+ JSXElement(path, { component, tracker = { childIndex: 0, parent: undefined } }) {
11
+ const tagName = (0, ast_helpers_1.getJSXElementName)(path);
12
+ if (typeof tagName === "string") {
13
+ if ((0, utils_1.isCapitalized)(tagName)) {
14
+ (0, errors_1.error)(path, errors_1.ERROR_MESSAGES.INCORRECTLY_NESTED_COMPONENT);
15
+ }
16
+ component.processJSXElement(path, tracker, tagName, exports.jsxVisitors);
17
+ }
18
+ else {
19
+ const { namespace, name } = tagName;
20
+ if (name === "nest" || name === "repeat") {
21
+ const componentCls = namespace;
22
+ if (!(0, utils_1.isCapitalized)(componentCls)) {
23
+ (0, errors_1.error)(path, errors_1.ERROR_MESSAGES.NESTED_COMPONENT_MUST_BE_CAPTIALIZED);
24
+ }
25
+ component.processNestedElement(path, tracker, componentCls, name === "repeat");
26
+ path.traverse(errorIfJSXelementsFoundUnderNested);
27
+ }
28
+ else if (namespace === "stub") {
29
+ // TODO: ensure there is nothing inside and no other attributes.
30
+ component.processStub(path, name, tracker);
31
+ }
32
+ else {
33
+ (0, errors_1.error)(path, errors_1.ERROR_MESSAGES.UNSUPPORTED_NAMESPACE);
34
+ }
35
+ }
36
+ path.remove();
37
+ },
38
+ JSXText(path, { component, tracker }) {
39
+ if (path.node.value.trim() !== "") {
40
+ component.processJSXText(path, tracker);
41
+ }
42
+ path.remove();
43
+ },
44
+ JSXExpressionContainer(path, { component, tracker }) {
45
+ path.traverse(errorIfJSXelementsFoundInExpression);
46
+ // We remove attributes while processing JSXElements, so the only expressions left
47
+ // must be text nodes.
48
+ component.processJSXExpressionInText(path, tracker);
49
+ path.remove();
50
+ },
51
+ };
52
+ function getVisitorThatErrorsIfJSXElementFound(errorMessage) {
53
+ return {
54
+ JSXElement(path) {
55
+ (0, errors_1.error)(path, errorMessage);
56
+ },
57
+ };
58
+ }
59
+ const errorIfJSXelementsFoundInExpression = getVisitorThatErrorsIfJSXElementFound(errors_1.ERROR_MESSAGES.JSX_ELEMENTS_NOT_ALLOWED_IN_EXPRESSIONS);
60
+ const errorIfJSXelementsFoundUnderNested = getVisitorThatErrorsIfJSXElementFound(errors_1.ERROR_MESSAGES.NESTED_COMP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AAE,CAAC;gBAChC,gEAAgE;gBAChE,SAAS,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;YAC7C,CAAC;iBAAM,CAAC;gBACN,IAAA,cAAK,EAAC,IAAI,EAAE,uBAAc,CAAC,qBAAqB,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QACD,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;IACD,OAAO,CAAC,IAAuB,EAAE,EAAE,SAAS,EAAE,OAAO,EAAS;QAC5D,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAClC,SAAS,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC1C,CAAC;QACD,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;IACD,sBAAsB,CACpB,IAAsC,EACtC,EAAE,SAAS,EAAE,OAAO,EAAS;QAE7B,IAAI,CAAC,QAAQ,CAAC,mCAAmC,CAAC,CAAC;QACnD,kFAAkF;QAClF,sBAAsB;QACtB,SAAS,CAAC,0BAA0B,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACpD,IAAI,CAAC,MAAM,EAAE,CAAC;IAChB,CAAC;CACF,CAAC;AAEF,SAAS,qCAAqC,CAAC,YAAoB;IACjE,OAAO;QACL,UAAU,CAAC,IAA0B;YACnC,IAAA,cAAK,EAAC,IAAI,EAAE,YAAY,CAAC,CAAC;QAC5B,CAAC;KACF,CAAC;AACJ,CAAC;AAED,MAAM,mCAAmC,GACvC,qCAAqC,CACnC,uBAAc,CAAC,uCAAuC,CACvD,CAAC;AAEJ,MAAM,kCAAkC,GACtC,qCAAqC,CACnC,uBAAc,CAAC,8BAA8B,CAC9C,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { NodePath } from "@babel/core";
2
+ import type { Function, JSXElement, ImportSpecifier } from "@babel/types";
3
+ import { Module } from "../models";
4
+ interface State {
5
+ module: Module;
6
+ }
7
+ export declare const programVisitors: {
8
+ ImportSpecifier(path: NodePath<ImportSpecifier>, { module }: State): void;
9
+ Function(path: NodePath<Function>, { module }: State): void;
10
+ JSXElement(path: NodePath<JSXElement>): void;
11
+ };
12
+ export {};
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.programVisitors = void 0;
4
+ const errors_1 = require("../errors");
5
+ const handlers_1 = require("../contexts/handlers");
6
+ // Although we're mainly interested in JSXElements, we visit nodes above where
7
+ // we expect to find those, so that we can get in before other plugins apply
8
+ // their transformations (like ES6 ArrowFunction conversion).
9
+ // Note that those plugins may not be loaded, so we can't depend on their
10
+ // transformations happening.
11
+ exports.programVisitors = {
12
+ ImportSpecifier(path, { module }) {
13
+ module.foundImport(path);
14
+ },
15
+ Function(path, { module }) {
16
+ const contextHandler = (0, handlers_1.identifyContextToBeHandled)(path, module);
17
+ if (contextHandler) {
18
+ contextHandler.applyTransformations();
19
+ }
20
+ },
21
+ // This captures JSX not caught by valid contexts, and therefore not allowed.
22
+ JSXElement(path) {
23
+ (0, errors_1.error)(path, errors_1.ERROR_MESSAGES.FOUND_JSX_IN_INVALID_LOCATION);
24
+ },
25
+ };
26
+ //# sourceMappingURL=program.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"program.js","sourceRoot":"","sources":["../../src/visitors/program.ts"],"names":[],"mappings":";;;AAEA,sCAAkD;AAElD,mDAAkE;AAMlE,8EAA8E;AAC9E,4EAA4E;AAC5E,6DAA6D;AAC7D,yEAAyE;AACzE,6BAA6B;AAEhB,QAAA,eAAe,GAAG;IAC7B,eAAe,CAAC,IAA+B,EAAE,EAAE,MAAM,EAAS;QAChE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;IACD,QAAQ,CAAC,IAAwB,EAAE,EAAE,MAAM,EAAS;QAClD,MAAM,cAAc,GAAG,IAAA,qCAA0B,EAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAChE,IAAI,cAAc,EAAE,CAAC;YACnB,cAAc,CAAC,oBAAoB,EAAE,CAAC;QACxC,CAAC;IACH,CAAC;IACD,6EAA6E;IAC7E,UAAU,CAAC,IAA0B;QACnC,IAAA,cAAK,EAAC,IAAI,EAAE,uBAAc,CAAC,6BAA6B,CAAC,CAAC;IAC5D,CAAC;CACF,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { CallExpression } from "@babel/types";
2
+ import { Component } from "../models";
3
+ export declare function buildDefineComponentCall(component: Component): CallExpression;
4
+ /**
5
+ * Unused. Was for classes.
6
+ */
7
+ export declare function buildExtendComponentCall(component: Component): CallExpression;
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildDefineComponentCall = buildDefineComponentCall;
4
+ exports.buildExtendComponentCall = buildExtendComponentCall;
5
+ const t = require("@babel/types");
6
+ const types_1 = require("@babel/types");
7
+ const utils_1 = require("../utils");
8
+ const consolidation_1 = require("../consolidation");
9
+ const constants_1 = require("../constants");
10
+ // component base to inherit from. Using 0 as false.
11
+ function buildComponentBaseArg(componentDefinition) {
12
+ return componentDefinition.baseComponent || t.numericLiteral(0);
13
+ }
14
+ function buildTemplateArg(componentDefinition) {
15
+ return t.stringLiteral((0, utils_1.escapeSingleQuotes)((0, utils_1.stripHtml)(componentDefinition.html)));
16
+ }
17
+ function buildObjectExpression(object, fn) {
18
+ const properties = [];
19
+ for (const [key, value] of Object.entries(object)) {
20
+ properties.push({
21
+ type: "ObjectProperty",
22
+ key: (0, types_1.identifier)(key),
23
+ value: fn(value),
24
+ computed: false,
25
+ shorthand: false,
26
+ });
27
+ }
28
+ return (0, types_1.objectExpression)(properties);
29
+ }
30
+ function buildWatchesArg(componentDefinition) {
31
+ const watchDeclarations = componentDefinition.watches.map((watch) => {
32
+ var _a, _b;
33
+ const callbacks = [];
34
+ for (const [key, fnExpr] of Object.entries(watch.callbacks)) {
35
+ callbacks.push({
36
+ type: "ObjectProperty",
37
+ key: t.identifier(key),
38
+ value: fnExpr,
39
+ computed: false,
40
+ shorthand: false,
41
+ });
42
+ }
43
+ return t.arrayExpression([
44
+ t.stringLiteral(watch.stashRef),
45
+ watch.shieldInfo
46
+ ? t.stringLiteral(watch.shieldInfo.key)
47
+ : t.numericLiteral(0),
48
+ t.numericLiteral(((_a = watch.shieldInfo) === null || _a === void 0 ? void 0 : _a.reverse) ? 1 : 0),
49
+ t.numericLiteral(((_b = watch.shieldInfo) === null || _b === void 0 ? void 0 : _b.count) || 0),
50
+ t.objectExpression(callbacks),
51
+ ]);
52
+ });
53
+ return t.arrayExpression([...watchDeclarations]);
54
+ }
55
+ function buildLookupsArg(componentDefinition) {
56
+ return buildObjectExpression(componentDefinition.lookups, (fnExpx) => fnExpx);
57
+ }
58
+ /**
59
+ *
60
+ component._e = {
61
+ 1: findElement(rootElement, [0]),
62
+ 2: findElement(rootElement, [1, 1]),
63
+ };
64
+ */
65
+ function buildComponentBuildFunction(componentDefinition) {
66
+ const stashValueObject = buildObjectExpression(componentDefinition.stash, (stashEntry) => stashEntry);
67
+ const stashAssignment = t.assignmentExpression("=", t.memberExpression(t.identifier("component"), t.identifier("_e")), stashValueObject);
68
+ const statements = [t.expressionStatement(stashAssignment)];
69
+ return t.functionExpression(null, [
70
+ t.identifier(constants_1.COMPONENT_BUILD_PARAMS.component),
71
+ t.identifier(constants_1.COMPONENT_BUILD_PARAMS.rootElement),
72
+ ], t.blockStatement(statements));
73
+ }
74
+ function buildProtoExtrasCall(component) {
75
+ return t.objectExpression([]);
76
+ }
77
+ function buildDefineComponentCall(component) {
78
+ const componentDefinition = (0, consolidation_1.consolidateComponent)(component);
79
+ return t.callExpression(t.identifier("defineComponent"), [
80
+ buildTemplateArg(componentDefinition),
81
+ buildWatchesArg(componentDefinition),
82
+ buildLookupsArg(componentDefinition),
83
+ buildComponentBuildFunction(componentDefinition),
84
+ buildComponentBaseArg(componentDefinition),
85
+ buildProtoExtrasCall(componentDefinition),
86
+ ]);
87
+ }
88
+ /**
89
+ * Unused. Was for classes.
90
+ */
91
+ function buildExtendComponentCall(component) {
92
+ const componentDefinition = (0, consolidation_1.consolidateComponent)(component);
93
+ return t.callExpression(t.identifier("extendComponent"), [
94
+ t.memberExpression(t.identifier(component.name), t.identifier("prototype")),
95
+ buildTemplateArg(componentDefinition),
96
+ buildWatchesArg(componentDefinition),
97
+ buildLookupsArg(componentDefinition),
98
+ buildComponentBuildFunction(componentDefinition),
99
+ ]);
100
+ }
101
+ //# sourceMappingURL=define-component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"define-component.js","sourceRoot":"","sources":["../../src/writers/define-component.ts"],"names":[],"mappings":";;AA0HA,4DAUC;AAKD,4DASC;AAlJD,kCAAkC;AAWlC,wCAA4D;AAC5D,oCAAyD;AACzD,oDAG0B;AAC1B,4CAAsD;AAEtD,oDAAoD;AACpD,SAAS,qBAAqB,CAC5B,mBAA4C;IAE5C,OAAO,mBAAmB,CAAC,aAAa,IAAI,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,SAAS,gBAAgB,CACvB,mBAA4C;IAE5C,OAAO,CAAC,CAAC,aAAa,CACpB,IAAA,0BAAkB,EAAC,IAAA,iBAAS,EAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CACxD,CAAC;AACJ,CAAC;AAED,SAAS,qBAAqB,CAC5B,MAA8B,EAC9B,EAAmB;IAEnB,MAAM,UAAU,GAA0B,EAAE,CAAC;IAE7C,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,UAAU,CAAC,IAAI,CAAC;YACd,IAAI,EAAE,gBAAgB;YACtB,GAAG,EAAE,IAAA,kBAAU,EAAC,GAAG,CAAC;YACpB,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC;YAChB,QAAQ,EAAE,KAAK;YACf,SAAS,EA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AAC,mBAAmB,CAAC;QAChD,qBAAqB,CAAC,mBAAmB,CAAC;QAC1C,oBAAoB,CAAC,mBAAmB,CAAC;KAC1C,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAgB,wBAAwB,CAAC,SAAoB;IAC3D,MAAM,mBAAmB,GAAG,IAAA,oCAAoB,EAAC,SAAS,CAAC,CAAC;IAC5D,OAAO,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC,iBAAiB,CAAC,EAAE;QACvD,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC;QAC3E,gBAAgB,CAAC,mBAAmB,CAAC;QACrC,eAAe,CAAC,mBAAmB,CAAC;QACpC,eAAe,CAAC,mBAAmB,CAAC;QACpC,2BAA2B,CAAC,mBAAmB,CAAC;KACjD,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1 @@
1
+ export { buildDefineComponentCall, buildExtendComponentCall, } from "./define-component";
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.buildExtendComponentCall = exports.buildDefineComponentCall = void 0;
4
+ var define_component_1 = require("./define-component");
5
+ Object.defineProperty(exports, "buildDefineComponentCall", { enumerable: true, get: function () { return define_component_1.buildDefineComponentCall; } });
6
+ Object.defineProperty(exports, "buildExtendComponentCall", { enumerable: true, get: function () { return define_component_1.buildExtendComponentCall; } });
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/writers/index.ts"],"names":[],"mappings":";;;AAAA,uDAG4B;AAF1B,4HAAA,wBAAwB,OAAA;AACxB,4HAAA,wBAAwB,OAAA"}
package/package.json CHANGED
@@ -1,17 +1,27 @@
1
1
  {
2
2
  "name": "babel-plugin-wallace",
3
- "version": "0.0.2",
4
- "description": "Babel plugin for wallace",
5
- "main": "lib/index.js",
3
+ "version": "0.0.6",
4
+ "author": "Andrew Buchan",
5
+ "description": "The babel plugin for wallace",
6
+ "license": "ISC",
7
+ "main": "dist/index.js",
8
+ "files": [
9
+ "/dist"
10
+ ],
6
11
  "scripts": {
7
- "test": "echo \"No test here, they are all in 'wallace' package.\""
12
+ "test": "echo \"All tests are in packages/wallace.\"",
13
+ "build": "shx rm -rf dist/* && tsc",
14
+ "prepack": "npm run build"
8
15
  },
9
16
  "dependencies": {
10
- "@babel/plugin-proposal-class-properties": "^7.18.6",
11
- "@babel/preset-env": "^7.22.9",
12
- "jsdom": "^22.1.0"
17
+ "@babel/plugin-syntax-jsx": "^7.22.5",
18
+ "jsdom": "^26.0.0"
13
19
  },
14
- "author": "Andrew Buchan",
15
- "license": "MIT",
16
- "gitHead": "922a989fa10d19dbcd2aaffe725d075a85214a73"
20
+ "devDependencies": {
21
+ "@types/node": "^22.8.1",
22
+ "babylon": "^6.18.0",
23
+ "source-map-support": "^0.5.21",
24
+ "typescript": "^5.6.3"
25
+ },
26
+ "gitHead": "3742fbcfdc21146c90252c2436fde91634fafa9e"
17
27
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Babel-plugin-wallace
2
-
3
- See https://github.com/andyhasit/wallace
@@ -1,356 +0,0 @@
1
- /**
2
- * The object which holds the directive definitions.
3
- *
4
- * A directive definition's handler's "this" is a NodeData instance.
5
- */
6
- const {RequestsHelp, alwaysUpdate, neverUpdate} = require('../definitions/constants')
7
- const componentRefVariable = 'c'; // The variable name by which the component will be known.
8
-
9
-
10
- const old = {
11
- // What is this for?
12
- "bind": {
13
- params: 'watch, event?',
14
- handle: function(watch, event='change') {
15
- this.addWatch(watch, undefined, 'value')
16
- this.addEventListener(event, `${watch} = w.getValue()`)
17
- }
18
- },
19
- "checked": {
20
- params: 'watch, converter?',
21
- handle: function(watch, converter) {
22
- this.addWatch(watch, converter, 'checked')
23
- }
24
- },
25
- "css": {
26
- params: 'watch, converter?',
27
- handle: function(watch, converter) {
28
- this.addWatch(watch, converter, 'css')
29
- }
30
- },
31
- "css-f": {
32
- params: 'value',
33
- handle: function(value) {
34
- this.addWatch(neverUpdate, value, 'css')
35
- }
36
- },
37
- // "el": {
38
- // handle: function(arg) {
39
- // this.saveAs = arg
40
- // }
41
- // },
42
- // "hide": {
43
- // params: 'watch',
44
- // handle: function(watch) {
45
- // this.shieldQuery = watch
46
- // }
47
- // },
48
- "helper": {
49
- handle: function(watch, converter) {
50
- throw new RequestsHelp(helpTopic)
51
- }
52
- },
53
- "inner": {
54
- params: 'watch, converter',
55
- handle: function(watch, converter) {
56
- this.addWatch(watch, converter, 'inner')
57
- }
58
- },
59
- "items": {
60
- params: 'watch, converter?',
61
- handle: function(watch, converter) {
62
- this.addWatch(watch, converter, 'items', componentRefVariable)
63
- }
64
- },
65
- // "on": {
66
- // params: 'event, callbackStr',
67
- // handle: function(event, callbackStr) {
68
- // this.addEventListener(event, callbackStr)
69
- // }
70
- // },
71
- // "pool": {
72
- // params: 'poolInstance',
73
- // handle: function(poolInstance) {
74
- // this.chainedCalls.push(`pool(${poolInstance})`)
75
- // }
76
- // },
77
- // "props": {
78
- // params: 'args',
79
- // handle: function(args) {
80
- // this.props = this.expandProps(args)
81
- // }
82
- // },
83
- "replace": {
84
- params: 'componentCls, props?',
85
- handle: function(componentCls, props) {
86
- this.replaceWith = componentCls
87
- if (props) {
88
- this.props = this.expandProps(props)
89
- }
90
- }
91
- },
92
- // "show": {
93
- // params: 'watch',
94
- // handle: function(watch) {
95
- // this.shieldQuery = watch
96
- // this.reverseShield = 1
97
- // }
98
- // },
99
- "stub": {
100
- params: 'stubName',
101
- handle: function(stubName) {
102
- this.stubName = stubName
103
- }
104
- },
105
- "swap": {
106
- params: 'watch, mappings, fallback?',
107
- handle: function(watch, mappings, fallback) {
108
- let args = this.expandDots(mappings)
109
- if (fallback) {
110
- args += ', ' + this.expandDots(fallback)
111
- }
112
- this.chainedCalls.push(`pool(component.__ic(${args}))`)
113
- this.addWatch(watch, undefined, 'swap', componentRefVariable)
114
- }
115
- },
116
- // Only for repeat items
117
- "use": {
118
- params: 'componentDef, key?',
119
- handle: function(componentDef, key) {
120
- this.chainedCalls.push(`pool(${this.buildPoolInit(componentDef, key)})`)
121
- }
122
- },
123
- "value": {
124
- params: 'watch, converter?',
125
- handle: function(watch, converter) {
126
- this.addWatch(watch, converter, 'value')
127
- }
128
- },
129
- "watch": {
130
- params: 'watch, converter, wrapperMethod?',
131
- handle: function(watch, converter, wrapperMethod) {
132
- this.addWatch(watch, converter, wrapperMethod)
133
- }
134
- },
135
- // "wrapper": {
136
- // params: 'cls, args?',
137
- // handle: function(cls, args) {
138
- // this.customWrapperClass = cls
139
- // this.customWrapperArgs = args
140
- // }
141
- // }
142
- }
143
-
144
-
145
- const callData = {
146
- value: "str", // if type str
147
- args: "str", // if type expr
148
- qualifier: "str|undefined", // foo:qualifier
149
- }
150
-
151
-
152
- const schema = {
153
- help: "...",
154
- allowNull: false,
155
- allowQualifier: false,
156
- requireQualifier: false,
157
- requireNull: false,
158
- handle: "function(nodeData, callData)",
159
- args: "array", // only if type "expr"
160
- argSets: "array", // in case it allows multiple args
161
- }
162
-
163
- /**
164
- * Do not create directive which allows or requires null which has the same name as a
165
- * normal attribute.
166
- */
167
- const directives = {
168
- att: {
169
- help: `
170
- Sets an HTML attribute on the element:
171
-
172
- /h <div _att:hidden="x > 3"></div>
173
- `,
174
- requireQualifier: true,
175
- handle: function(nodeData, attInfo) {
176
- nodeData.addWatch(attInfo.args[0], undefined, `@${attInfo.qualifier}`)
177
- }
178
-
179
- },
180
- call: {
181
- help: `
182
- Watch a value and call a wrapper method if it changes.
183
-
184
- /h <div _call:method={watch, tranform}></div>
185
-
186
- Variables for watch: c, p
187
- Variables for callback: c, p, n, o, w
188
- `,
189
- requireQualifier: true,
190
- handle: function(nodeData, attInfo) {
191
- nodeData.addWatch(attInfo.args[0], attInfo.args[1], attInfo.qualifier)
192
- }
193
- },
194
- checked: {
195
- help: `
196
- Sets the "checked" status of the element:
197
-
198
- /h <input _checked={c.active} type="checkbox"/>
199
- `,
200
- handle: function(nodeData, attInfo) {
201
- nodeData.addWatch(attInfo.args[0], undefined, 'checked')
202
- }
203
- },
204
- // disabled: {
205
- // help: `
206
- // Sets the "disabled" status of the element:
207
-
208
- // /h <button _disabled={!c.active}>...</button>
209
- // `,
210
- // allowedTypes: "expr",
211
- // handle: function(nodeData, attInfo) {
212
- // nodeData.addWatch(attInfo.args[0], undefined, 'disabled')
213
- // }
214
- // },
215
- el: {
216
- help: `
217
- Gives the wrapper for this element a name so it can be accessed later:
218
-
219
- /h <div _el:user></div>
220
-
221
- /j c.el.user.text("Wallace")
222
- `,
223
- allowNull: true,
224
- requireQualifier: true,
225
- handle: function(nodeData, attInfo) {
226
- nodeData.saveAs = attInfo.qualifier
227
- }
228
- },
229
- foreach: {
230
- help: `
231
- Repeats a nested component:
232
-
233
- /h <div>
234
- /h <Child _for={c.items|id} />
235
- /h </div>
236
-
237
- `,
238
- handle: function(nodeData, attInfo) {
239
- const parent = nodeData.parentNodeData
240
- if (parent === undefined) {
241
- // TODO: throw better error, and assert parent has no other chldren.
242
- throw Error("For must be used under a parent.")
243
- }
244
- const componentDef = nodeData.nestedClass
245
- const data = attInfo.args[0]
246
- const key = attInfo.args[1]
247
- parent.chainedCalls.push(`pool(${parent.buildPoolInit(componentDef, key)})`)
248
- parent.addWatch(alwaysUpdate, data, 'items', componentRefVariable)
249
- nodeData.isRepeat = true
250
- }
251
- },
252
- hidden: {
253
- help: `
254
- Hides an element:
255
-
256
- /h <div hidden={x > 10}></div>
257
-
258
- Available args are: c, p
259
- `,
260
- handle: function(nodeData, attInfo) {
261
- nodeData.shieldQuery = attInfo.args[0]
262
- }
263
- },
264
- on: {
265
- help: `
266
- Creates an event handler:
267
-
268
- /h <div on:click={alert('hello')}></div>
269
-
270
- Available args are: w, e
271
- `,
272
- requireQualifier: true,
273
- handle: function(nodeData, attInfo) {
274
- nodeData.addEventListener(attInfo.qualifier, attInfo.args[0])
275
- }
276
- },
277
-
278
- // TODO: change this because we may use a special wrapper?
279
- pool: {
280
- help: `
281
- Specify a pool object for repeat items:
282
-
283
- /h <div pool={poolObject}></div>
284
-
285
- `,
286
- handle: function(nodeData, attInfo) {
287
- nodeData.chainedCalls.push(`pool(${attInfo.args[0]})`)
288
- }
289
- },
290
- props: {
291
- help: `
292
- Specify props for a nested component:
293
-
294
- /h <NestedComponent props={{foo: 'bar'}} />
295
-
296
- `,
297
- handle: function(nodeData, attInfo) {
298
- nodeData.props = nodeData.expandProps(attInfo.args[0])
299
- }
300
- },
301
- show: {
302
- help: `
303
- Shows an element:
304
-
305
- /h <div show={x > 10}></div>
306
-
307
- Variables are: c, p
308
- `,
309
- handle: function(nodeData, attInfo) {
310
- nodeData.shieldQuery = attInfo.args[0]
311
- nodeData.reverseShield = 1
312
- }
313
- },
314
- style: {
315
- help: `
316
- Sets the style directive:
317
-
318
- /h <div style:color={p.color}></div>
319
-
320
- Variables are: c, p
321
- `,
322
- requireQualifier: true,
323
- handle: function(nodeData, attInfo) {
324
- nodeData.addWatch(attInfo.args[0], undefined, 'style', `'${attInfo.qualifier}'`)
325
- }
326
- },
327
- watch: {
328
- help: `
329
- Watch a value and call
330
-
331
- /h <div watch={watch, callback}></div>
332
-
333
- Variables for watch: c, p
334
- Variables for callback: c, p, n, o, w
335
- `,
336
- handle: function(nodeData, attInfo) {
337
- nodeData.addWatch(...attInfo.args)
338
- }
339
- },
340
- wrapper: {
341
- help: `
342
- Specify an alternative wrapper class:
343
-
344
- /h <div wrapper={MyCustomWrapper}></div>
345
-
346
- Available args are: c, p
347
- `,
348
- handle: function(nodeData, attInfo) {
349
- nodeData.customWrapperClass = attInfo.args[0]
350
- }
351
- },
352
- }
353
-
354
- // Do not import directly, only through index so we get custom directives too.
355
- module.exports = {directives}
356
-
@@ -1,2 +0,0 @@
1
- const {config} = require('./loader');
2
- module.exports = {config}