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.
- package/LICENSE.md +1 -1
- package/dist/ast-helpers.d.ts +10 -0
- package/dist/ast-helpers.js +52 -0
- package/dist/ast-helpers.js.map +1 -0
- package/dist/babel-types.d.ts +4 -0
- package/dist/babel-types.js +3 -0
- package/dist/babel-types.js.map +1 -0
- package/dist/builders/consolidation.d.ts +30 -0
- package/dist/builders/consolidation.js +321 -0
- package/dist/builders/consolidation.js.map +1 -0
- package/dist/builders/define-component.d.ts +7 -0
- package/dist/builders/define-component.js +101 -0
- package/dist/builders/define-component.js.map +1 -0
- package/dist/builders/index.d.ts +2 -0
- package/dist/builders/index.js +7 -0
- package/dist/builders/index.js.map +1 -0
- package/dist/builders/types.d.ts +15 -0
- package/dist/builders/types.js +3 -0
- package/dist/builders/types.js.map +1 -0
- package/dist/builders/visibility.d.ts +5 -0
- package/dist/builders/visibility.js +43 -0
- package/dist/builders/visibility.js.map +1 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.js +47 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.d.ts +31 -0
- package/dist/constants.js +40 -0
- package/dist/constants.js.map +1 -0
- package/dist/contexts/handlers.d.ts +18 -0
- package/dist/contexts/handlers.js +152 -0
- package/dist/contexts/handlers.js.map +1 -0
- package/dist/contexts/index.d.ts +2 -0
- package/dist/contexts/index.js +6 -0
- package/dist/contexts/index.js.map +1 -0
- package/dist/contexts/parameters.d.ts +8 -0
- package/dist/contexts/parameters.js +114 -0
- package/dist/contexts/parameters.js.map +1 -0
- package/dist/directives.d.ts +8 -0
- package/dist/directives.js +94 -0
- package/dist/directives.js.map +1 -0
- package/dist/errors.d.ts +32 -0
- package/dist/errors.js +45 -0
- package/dist/errors.js.map +1 -0
- package/dist/helpers.d.ts +4 -0
- package/dist/helpers.js +35 -0
- package/dist/helpers.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +34 -0
- package/dist/index.js.map +1 -0
- package/dist/models/component.d.ts +25 -0
- package/dist/models/component.js +114 -0
- package/dist/models/component.js.map +1 -0
- package/dist/models/directive.d.ts +13 -0
- package/dist/models/directive.js +8 -0
- package/dist/models/directive.js.map +1 -0
- package/dist/models/index.d.ts +5 -0
- package/dist/models/index.js +15 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models/module.d.ts +12 -0
- package/dist/models/module.js +40 -0
- package/dist/models/module.js.map +1 -0
- package/dist/models/node.d.ts +82 -0
- package/dist/models/node.js +306 -0
- package/dist/models/node.js.map +1 -0
- package/dist/utils.d.ts +12 -0
- package/dist/utils.js +59 -0
- package/dist/utils.js.map +1 -0
- package/dist/visitors/attribute.d.ts +10 -0
- package/dist/visitors/attribute.js +82 -0
- package/dist/visitors/attribute.js.map +1 -0
- package/dist/visitors/jsx.d.ts +13 -0
- package/dist/visitors/jsx.js +61 -0
- package/dist/visitors/jsx.js.map +1 -0
- package/dist/visitors/program.d.ts +12 -0
- package/dist/visitors/program.js +26 -0
- package/dist/visitors/program.js.map +1 -0
- package/package.json +19 -10
- package/lib/index.js +0 -13
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { NodePath } from "@babel/core";
|
|
2
|
+
export declare const ERROR_MESSAGES: {
|
|
3
|
+
BASE_COMPONENT_ALREADY_DEFINED: string;
|
|
4
|
+
FOUND_JSX_IN_INVALID_LOCATION: string;
|
|
5
|
+
CLASS_METHOD_MUST_BE_PROPERTY_JSX: string;
|
|
6
|
+
CAPITALISED_COMPONENT_NAME: string;
|
|
7
|
+
NESTED_COMPONENT_MUST_BE_CAPTIALIZED: string;
|
|
8
|
+
INCORRECTLY_NESTED_COMPONENT: string;
|
|
9
|
+
ARROW_FUNCTION_NOT_ASSIGNED: string;
|
|
10
|
+
PLACEHOLDER_MAY_NOT_BE_EMPTY: string;
|
|
11
|
+
PLACEHOLDER_MAY_NOT_BE_LITERAL_OBJECT: string;
|
|
12
|
+
INVALID_PLACEHOLDER_EXPRESSION: string;
|
|
13
|
+
JSX_ELEMENTS_NOT_ALLOWED_IN_EXPRESSIONS: string;
|
|
14
|
+
UNSUPPORTED_ATTRIBUTE_VALUE: string;
|
|
15
|
+
CONDITIONAL_DISPLAY_ALREADY_DEFINED: string;
|
|
16
|
+
REF_ALREADY_DEFINED: string;
|
|
17
|
+
STUB_ALREADY_DEFINED: string;
|
|
18
|
+
PROPS_ALREADY_DEFINED: string;
|
|
19
|
+
NESTED_COMPONENT_WITH_CHILDREN: string;
|
|
20
|
+
NO_ATTRIBUTES_ON_NESTED_CLASS: string;
|
|
21
|
+
REFS_MUST_BE_UNIQUE_WITHIN_EACH_COMPONENT: string;
|
|
22
|
+
REPEAT_ALREADY_DEFINED: string;
|
|
23
|
+
REPEAT_ONLY_ON_NESTED_CLASS: string;
|
|
24
|
+
REPEAT_WITHOUT_PARENT: string;
|
|
25
|
+
REPEAT_DIRECTIVE_WITH_SIBLINGS: string;
|
|
26
|
+
REPEAT_DIRECTIVE_WITH_CHILDREN: string;
|
|
27
|
+
UNSUPPORTED_NAMESPACE: string;
|
|
28
|
+
ILLEGAL_NAMES_IN_PROPS: (names: string[]) => string;
|
|
29
|
+
ILLEGAL_PARAMETERS: (name: string) => string;
|
|
30
|
+
};
|
|
31
|
+
export declare function error(path: NodePath<any>, errorMessage: string): void;
|
|
32
|
+
export declare function ensure(condition: boolean, path: NodePath<any>, errorMessage: string): void;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERROR_MESSAGES = void 0;
|
|
4
|
+
exports.error = error;
|
|
5
|
+
exports.ensure = ensure;
|
|
6
|
+
exports.ERROR_MESSAGES = {
|
|
7
|
+
BASE_COMPONENT_ALREADY_DEFINED: "Base component already defined.",
|
|
8
|
+
FOUND_JSX_IN_INVALID_LOCATION: "Found JSX in invalid location.",
|
|
9
|
+
CLASS_METHOD_MUST_BE_PROPERTY_JSX: "Function returning JSX in a class must be assigned to property 'jsx'",
|
|
10
|
+
CAPITALISED_COMPONENT_NAME: "Component name must be capitalized.",
|
|
11
|
+
NESTED_COMPONENT_MUST_BE_CAPTIALIZED: "Nested component must be capitalized.",
|
|
12
|
+
INCORRECTLY_NESTED_COMPONENT: "Nest components using <Name.nest /> or <Name.repeat />.",
|
|
13
|
+
ARROW_FUNCTION_NOT_ASSIGNED: "Component function must be assigned to a variable.",
|
|
14
|
+
PLACEHOLDER_MAY_NOT_BE_EMPTY: "Placeholder expressions may not be empty.",
|
|
15
|
+
PLACEHOLDER_MAY_NOT_BE_LITERAL_OBJECT: "Literal objects in placeholders not allowed as they will become constants.",
|
|
16
|
+
INVALID_PLACEHOLDER_EXPRESSION: "Invalid expressions for a placeholder",
|
|
17
|
+
JSX_ELEMENTS_NOT_ALLOWED_IN_EXPRESSIONS: "JSX elements are not allowed in expressions.",
|
|
18
|
+
UNSUPPORTED_ATTRIBUTE_VALUE: "Attribute value must be a string or expression.",
|
|
19
|
+
CONDITIONAL_DISPLAY_ALREADY_DEFINED: "Conditional display already defined on element.",
|
|
20
|
+
REF_ALREADY_DEFINED: "Ref already defined on element.",
|
|
21
|
+
STUB_ALREADY_DEFINED: "Stub already defined on element.",
|
|
22
|
+
PROPS_ALREADY_DEFINED: "Props already defined on element.",
|
|
23
|
+
NESTED_COMPONENT_WITH_CHILDREN: "Nested component may not have child nodes.",
|
|
24
|
+
NO_ATTRIBUTES_ON_NESTED_CLASS: "Attributes not allowed on nested class elements.",
|
|
25
|
+
REFS_MUST_BE_UNIQUE_WITHIN_EACH_COMPONENT: "Refs must be unique within each component.",
|
|
26
|
+
REPEAT_ALREADY_DEFINED: "Repeat already defined on element.",
|
|
27
|
+
REPEAT_ONLY_ON_NESTED_CLASS: "Repeat only allowed on nested component elements.",
|
|
28
|
+
REPEAT_WITHOUT_PARENT: "Repeat may only be used under a parent node.",
|
|
29
|
+
REPEAT_DIRECTIVE_WITH_SIBLINGS: "Repeat may only be used when the parent node has no other children.",
|
|
30
|
+
REPEAT_DIRECTIVE_WITH_CHILDREN: "Repeat may not have child nodes.",
|
|
31
|
+
UNSUPPORTED_NAMESPACE: "Unsupported namespace, may only use 'stub'.",
|
|
32
|
+
ILLEGAL_NAMES_IN_PROPS: (names) => `Illegal names in props: ${names
|
|
33
|
+
.map((name) => `"${name}"`)
|
|
34
|
+
.join(", ")} - these are reserved for event callbacks.`,
|
|
35
|
+
ILLEGAL_PARAMETERS: (name) => `Illegal parameters: "${name}". You are only allowed "_element", "_event" and "_component".`,
|
|
36
|
+
};
|
|
37
|
+
function error(path, errorMessage) {
|
|
38
|
+
throw path.buildCodeFrameError(errorMessage);
|
|
39
|
+
}
|
|
40
|
+
function ensure(condition, path, errorMessage) {
|
|
41
|
+
if (!condition) {
|
|
42
|
+
error(path, errorMessage);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;;AA+CA,sBAEC;AAED,wBAQC;AAzDY,QAAA,cAAc,GAAG;IAC5B,8BAA8B,EAAE,iCAAiC;IACjE,6BAA6B,EAAE,gCAAgC;IAC/D,iCAAiC,EAC/B,sEAAsE;IACxE,0BAA0B,EAAE,qCAAqC;IACjE,oCAAoC,EAAE,uCAAuC;IAC7E,4BAA4B,EAC1B,yDAAyD;IAC3D,2BAA2B,EACzB,oDAAoD;IACtD,4BAA4B,EAAE,2CAA2C;IACzE,qCAAqC,EACnC,4EAA4E;IAC9E,8BAA8B,EAAE,uCAAuC;IACvE,uCAAuC,EACrC,8CAA8C;IAChD,2BAA2B,EACzB,iDAAiD;IACnD,mCAAmC,EACjC,iDAAiD;IACnD,mBAAmB,EAAE,iCAAiC;IACtD,oBAAoB,EAAE,kCAAkC;IACxD,qBAAqB,EAAE,mCAAmC;IAC1D,8BAA8B,EAAE,4CAA4C;IAC5E,6BAA6B,EAC3B,kDAAkD;IACpD,yCAAyC,EACvC,4CAA4C;IAC9C,sBAAsB,EAAE,oCAAoC;IAC5D,2BAA2B,EACzB,mDAAmD;IACrD,qBAAqB,EAAE,8CAA8C;IACrE,8BAA8B,EAC5B,qEAAqE;IACvE,8BAA8B,EAAE,kCAAkC;IAClE,qBAAqB,EAAE,6CAA6C;IACpE,sBAAsB,EAAE,CAAC,KAAe,EAAE,EAAE,CAC1C,2BAA2B,KAAK;SAC7B,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,GAAG,CAAC;SAC1B,IAAI,CAAC,IAAI,CAAC,4CAA4C;IAC3D,kBAAkB,EAAE,CAAC,IAAY,EAAE,EAAE,CACnC,wBAAwB,IAAI,gEAAgE;CAC/F,CAAC;AAEF,SAAgB,KAAK,CAAC,IAAmB,EAAE,YAAoB;IAC7D,MAAM,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAAC,CAAC;AAC/C,CAAC;AAED,SAAgB,MAAM,CACpB,SAAkB,EAClB,IAAmB,EACnB,YAAoB;IAEpB,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,KAAK,CAAC,IAAI,EAAE,YAAY,CAAC,CAAC;IAC5B,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NodePath } from "@babel/core";
|
|
2
|
+
import type { Function, BlockStatement, Expression } from "@babel/types";
|
|
3
|
+
export declare function functionReturnsOnlyJSX(path: NodePath<Function>): Expression | BlockStatement | undefined;
|
|
4
|
+
export declare function functionReturnsObjectWithJSX(path: NodePath<Function>): Expression | BlockStatement | undefined;
|
package/dist/helpers.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.functionReturnsOnlyJSX = functionReturnsOnlyJSX;
|
|
4
|
+
exports.functionReturnsObjectWithJSX = functionReturnsObjectWithJSX;
|
|
5
|
+
const t = require("@babel/types");
|
|
6
|
+
/**
|
|
7
|
+
* Determines wether a function only returns the expected expression, either because its
|
|
8
|
+
* explicitly returned, or because its an arrow function's only statement.
|
|
9
|
+
*/
|
|
10
|
+
function functionOnlyReturns(path, test) {
|
|
11
|
+
const body = path.node.body;
|
|
12
|
+
if (test(body)) {
|
|
13
|
+
return body;
|
|
14
|
+
}
|
|
15
|
+
if (t.isBlockStatement(body) &&
|
|
16
|
+
body.body.length === 1 &&
|
|
17
|
+
t.isReturnStatement(body.body[0]) &&
|
|
18
|
+
test(body.body[0].argument)) {
|
|
19
|
+
return body.body[0].argument;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function functionReturnsOnlyJSX(path) {
|
|
23
|
+
return functionOnlyReturns(path, t.isJSXElement);
|
|
24
|
+
}
|
|
25
|
+
function functionReturnsObjectWithJSX(path) {
|
|
26
|
+
return functionOnlyReturns(path, (expr) => {
|
|
27
|
+
if (t.isObjectExpression(expr)) {
|
|
28
|
+
expr;
|
|
29
|
+
return (expr.properties.length > 0 &&
|
|
30
|
+
expr.properties.every((prop) => t.isIdentifier(prop.key) && t.isJSXElement(prop.value)));
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;AA0BA,wDAIC;AAED,oEAgBC;AA9CD,kCAAkC;AAElC;;;GAGG;AACH,SAAS,mBAAmB,CAC1B,IAAwB,EACxB,IAAoD;IAEpD,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;IAC5B,IAAI,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IACE,CAAC,CAAC,gBAAgB,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC;QACtB,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAC3B,CAAC;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAC/B,CAAC;AACH,CAAC;AAED,SAAgB,sBAAsB,CACpC,IAAwB;IAExB,OAAO,mBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC,YAAY,CAAC,CAAC;AACnD,CAAC;AAED,SAAgB,4BAA4B,CAC1C,IAAwB;IAExB,OAAO,mBAAmB,CAAC,IAAI,EAAE,CAAC,IAAiC,EAAE,EAAE;QACrE,IAAI,CAAC,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC/B,IAA0B,CAAC;YAC3B,OAAO,CACL,IAAI,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC;gBAC1B,IAAI,CAAC,UAAU,CAAC,KAAK,CACnB,CAAC,IAAsB,EAAE,EAAE,CACzB,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CACzD,CACF,CAAC;QACJ,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import "source-map-support/register";
|
|
2
|
+
import type { PluginObj } from "@babel/core";
|
|
3
|
+
import type { Babel } from "./babel-types";
|
|
4
|
+
import { gleekitConfig } from "./config";
|
|
5
|
+
import { Directive, NodeValue } from "./models";
|
|
6
|
+
export default function gleekitPlugin({ types: t }: Babel): PluginObj;
|
|
7
|
+
/**
|
|
8
|
+
* These exports are for custom plugin development.
|
|
9
|
+
*/
|
|
10
|
+
export { gleekitConfig, Directive, NodeValue };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Directive = exports.gleekitConfig = void 0;
|
|
4
|
+
exports.default = gleekitPlugin;
|
|
5
|
+
require("source-map-support/register"); // ensures correct line numbers in stack traces.
|
|
6
|
+
const config_1 = require("./config");
|
|
7
|
+
Object.defineProperty(exports, "gleekitConfig", { enumerable: true, get: function () { return config_1.gleekitConfig; } });
|
|
8
|
+
const models_1 = require("./models");
|
|
9
|
+
Object.defineProperty(exports, "Directive", { enumerable: true, get: function () { return models_1.Directive; } });
|
|
10
|
+
const module_1 = require("./models/module");
|
|
11
|
+
const program_1 = require("./visitors/program");
|
|
12
|
+
// The general pattern involves visting high-level nodes where we instantiate models
|
|
13
|
+
// which are passed to traverse calls with sets of visitors for low-level nodes,
|
|
14
|
+
// which do some of their own transformations and call helper methods to add state.
|
|
15
|
+
// The higher level nodes may then use the helpers with their collected state after
|
|
16
|
+
// the nested traversal.
|
|
17
|
+
//
|
|
18
|
+
// This avoids the use of global state which would be necessary if visitors were
|
|
19
|
+
// all in the same set.
|
|
20
|
+
function gleekitPlugin({ types: t }) {
|
|
21
|
+
return {
|
|
22
|
+
visitor: {
|
|
23
|
+
Program: {
|
|
24
|
+
enter(path, pluginPass) {
|
|
25
|
+
config_1.gleekitConfig.applyOptions(pluginPass.opts);
|
|
26
|
+
const module = new module_1.Module(path);
|
|
27
|
+
path.traverse(program_1.programVisitors, { module });
|
|
28
|
+
module.addMissingImports();
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAoBA,gCAaC;AAjCD,uCAAqC,CAAC,gDAAgD;AAMtF,qCAAyC;AAgChC,8FAhCA,sBAAa,OAgCA;AA/BtB,qCAAgD;AA+BxB,0FA/Bf,kBAAS,OA+Be;AA9BjC,4CAAyC;AACzC,gDAAqD;AAErD,oFAAoF;AACpF,gFAAgF;AAChF,mFAAmF;AACnF,mFAAmF;AACnF,wBAAwB;AACxB,EAAE;AACF,gFAAgF;AAChF,uBAAuB;AAEvB,SAAwB,aAAa,CAAC,EAAE,KAAK,EAAE,CAAC,EAAS;IACvD,OAAO;QACL,OAAO,EAAE;YACP,OAAO,EAAE;gBACP,KAAK,CAAC,IAAuB,EAAE,UAAsB;oBACnD,sBAAa,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;oBAC5C,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,IAAI,CAAC,CAAC;oBAChC,IAAI,CAAC,QAAQ,CAAC,yBAAe,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;oBAC3C,MAAM,CAAC,iBAAiB,EAAE,CAAC;gBAC7B,CAAC;aACF;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { NodePath } from "@babel/core";
|
|
2
|
+
import type { Identifier, JSXElement, JSXExpressionContainer, JSXText, Expression } from "@babel/types";
|
|
3
|
+
import { ExtractedNode, TagNode } from "./node";
|
|
4
|
+
import { Module } from "./module";
|
|
5
|
+
export interface WalkTracker {
|
|
6
|
+
parent: TagNode;
|
|
7
|
+
childIndex: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class Component {
|
|
10
|
+
#private;
|
|
11
|
+
_currentNodeAddress: Array<number>;
|
|
12
|
+
name: string;
|
|
13
|
+
module: Module;
|
|
14
|
+
baseComponent: Expression | undefined;
|
|
15
|
+
rootElement: HTMLElement;
|
|
16
|
+
extractedNodes: ExtractedNode[];
|
|
17
|
+
propsIdentifier: Identifier;
|
|
18
|
+
componentIdentifier: Identifier;
|
|
19
|
+
constructor(name: string, module: Module, propsIdentifier: Identifier, componentIdentifier: Identifier);
|
|
20
|
+
processJSXElement(path: NodePath<JSXElement>, tracker: WalkTracker, tagName: string, jsxVisitors: any): void;
|
|
21
|
+
processNestedElement(path: NodePath<JSXElement>, tracker: WalkTracker, tagName: string, isRepeat: boolean): void;
|
|
22
|
+
processStub(path: NodePath<JSXElement>, name: string, tracker: WalkTracker): void;
|
|
23
|
+
processJSXText(path: NodePath<JSXText>, tracker: WalkTracker): void;
|
|
24
|
+
processJSXExpressionInText(path: NodePath<JSXExpressionContainer>, tracker: WalkTracker): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
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 _Component_instances, _Component_enterLevel, _Component_exitLevel, _Component_getCurrentAddress, _Component_addElement, _Component_addNode;
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.Component = void 0;
|
|
10
|
+
const errors_1 = require("../errors");
|
|
11
|
+
const ast_helpers_1 = require("../ast-helpers");
|
|
12
|
+
const attribute_1 = require("../visitors/attribute");
|
|
13
|
+
const node_1 = require("./node");
|
|
14
|
+
/*
|
|
15
|
+
Captures all the information extracted for a component.
|
|
16
|
+
|
|
17
|
+
`currentNodeAddress` is an array of integers representing the position of an element
|
|
18
|
+
relative to root, resolvable using `reduce`, which is how wallace creates references
|
|
19
|
+
at runtime.
|
|
20
|
+
|
|
21
|
+
<div> []
|
|
22
|
+
<div> [0]
|
|
23
|
+
<span>A<span> [0, 0]
|
|
24
|
+
<img /> [0, 1]
|
|
25
|
+
</div>
|
|
26
|
+
<a href>go</a> [1]
|
|
27
|
+
</div>
|
|
28
|
+
*/
|
|
29
|
+
class Component {
|
|
30
|
+
constructor(name, module, propsIdentifier, componentIdentifier) {
|
|
31
|
+
_Component_instances.add(this);
|
|
32
|
+
this._currentNodeAddress = [];
|
|
33
|
+
this.extractedNodes = [];
|
|
34
|
+
this.name = name;
|
|
35
|
+
this.module = module;
|
|
36
|
+
this.propsIdentifier = propsIdentifier;
|
|
37
|
+
this.componentIdentifier = componentIdentifier;
|
|
38
|
+
}
|
|
39
|
+
processJSXElement(path, tracker, tagName, jsxVisitors) {
|
|
40
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_enterLevel).call(this, tracker.childIndex);
|
|
41
|
+
const extractedNode = new node_1.TagNode(path, __classPrivateFieldGet(this, _Component_instances, "m", _Component_getCurrentAddress).call(this), tracker.parent, this, tagName, false);
|
|
42
|
+
path.traverse(attribute_1.attributeVisitors, { extractedNode });
|
|
43
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_addNode).call(this, extractedNode, path, tracker);
|
|
44
|
+
path.traverse(jsxVisitors, {
|
|
45
|
+
component: this,
|
|
46
|
+
tracker: { childIndex: 0, parent: extractedNode },
|
|
47
|
+
});
|
|
48
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_exitLevel).call(this);
|
|
49
|
+
}
|
|
50
|
+
processNestedElement(path, tracker, tagName, isRepeat) {
|
|
51
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_enterLevel).call(this, tracker.childIndex);
|
|
52
|
+
const extractedNode = new node_1.TagNode(path, __classPrivateFieldGet(this, _Component_instances, "m", _Component_getCurrentAddress).call(this), tracker.parent, this, tagName, true);
|
|
53
|
+
extractedNode.isRepeatedNode = isRepeat;
|
|
54
|
+
path.traverse(attribute_1.attributeVisitors, { extractedNode });
|
|
55
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_addNode).call(this, extractedNode, path, tracker);
|
|
56
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_exitLevel).call(this);
|
|
57
|
+
}
|
|
58
|
+
processStub(path, name, tracker) {
|
|
59
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_enterLevel).call(this, tracker.childIndex);
|
|
60
|
+
const extractedNode = new node_1.StubNode(path, __classPrivateFieldGet(this, _Component_instances, "m", _Component_getCurrentAddress).call(this), tracker.parent, name);
|
|
61
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_addNode).call(this, extractedNode, path, tracker);
|
|
62
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_exitLevel).call(this);
|
|
63
|
+
}
|
|
64
|
+
processJSXText(path, tracker) {
|
|
65
|
+
// This will always be a leaf node.
|
|
66
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_enterLevel).call(this, tracker.childIndex);
|
|
67
|
+
const extractedNode = new node_1.PlainTextNode(path, __classPrivateFieldGet(this, _Component_instances, "m", _Component_getCurrentAddress).call(this), tracker.parent);
|
|
68
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_addNode).call(this, extractedNode, path, tracker);
|
|
69
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_exitLevel).call(this);
|
|
70
|
+
}
|
|
71
|
+
processJSXExpressionInText(path, tracker) {
|
|
72
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_enterLevel).call(this, tracker.childIndex);
|
|
73
|
+
const expression = (0, ast_helpers_1.getPlaceholderExpression)(path, path.node.expression);
|
|
74
|
+
const extractedNode = new node_1.DynamicTextNode(path, __classPrivateFieldGet(this, _Component_instances, "m", _Component_getCurrentAddress).call(this), tracker.parent, expression);
|
|
75
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_addNode).call(this, extractedNode, path, tracker);
|
|
76
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_exitLevel).call(this);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.Component = Component;
|
|
80
|
+
_Component_instances = new WeakSet(), _Component_enterLevel = function _Component_enterLevel(index) {
|
|
81
|
+
// This skips this step for root, whose address is []
|
|
82
|
+
if (this.rootElement) {
|
|
83
|
+
this._currentNodeAddress.push(index);
|
|
84
|
+
}
|
|
85
|
+
}, _Component_exitLevel = function _Component_exitLevel() {
|
|
86
|
+
this._currentNodeAddress.pop();
|
|
87
|
+
}, _Component_getCurrentAddress = function _Component_getCurrentAddress() {
|
|
88
|
+
return this._currentNodeAddress.slice();
|
|
89
|
+
}, _Component_addElement = function _Component_addElement(element, path, tracker) {
|
|
90
|
+
var _a, _b;
|
|
91
|
+
if ((_a = tracker.parent) === null || _a === void 0 ? void 0 : _a.isNestedClass) {
|
|
92
|
+
(0, errors_1.error)(path, errors_1.ERROR_MESSAGES.NESTED_COMPONENT_WITH_CHILDREN);
|
|
93
|
+
}
|
|
94
|
+
if ((_b = tracker.parent) === null || _b === void 0 ? void 0 : _b.isRepeatedNode) {
|
|
95
|
+
(0, errors_1.error)(path, errors_1.ERROR_MESSAGES.REPEAT_DIRECTIVE_WITH_CHILDREN);
|
|
96
|
+
}
|
|
97
|
+
if (!element) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
if (this.rootElement) {
|
|
101
|
+
const relativePath = this._currentNodeAddress.slice(0, -1);
|
|
102
|
+
const parentNode = relativePath.reduce((acc, index) => acc.childNodes[index], this.rootElement);
|
|
103
|
+
parentNode.appendChild(element);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
// @ts-ignore (TS complains this could be Text, but we know it's not.)
|
|
107
|
+
this.rootElement = element;
|
|
108
|
+
}
|
|
109
|
+
tracker.childIndex += 1;
|
|
110
|
+
}, _Component_addNode = function _Component_addNode(node, path, tracker) {
|
|
111
|
+
__classPrivateFieldGet(this, _Component_instances, "m", _Component_addElement).call(this, node.getElement(), path, tracker);
|
|
112
|
+
this.extractedNodes.push(node);
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component.js","sourceRoot":"","sources":["../../src/models/component.ts"],"names":[],"mappings":";;;;;;;;;AASA,sCAAkD;AAClD,gDAA0D;AAC1D,qDAA0D;AAC1D,iCAMgB;AAQhB;;;;;;;;;;;;;;EAcE;AACF,MAAa,SAAS;IASpB,YACE,IAAY,EACZ,MAAc,EACd,eAA2B,EAC3B,mBAA+B;;QAZjC,wBAAmB,GAAkB,EAAE,CAAC;QAKxC,mBAAc,GAAoB,EAAE,CAAC;QASnC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;QACvC,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;IACjD,CAAC;IA4CD,iBAAiB,CACf,IAA0B,EAC1B,OAAoB,EACpB,OAAe,EACf,WAAgB;QAEhB,uBAAA,IAAI,mDAAY,MAAhB,IAAI,EAAa,OAAO,CAAC,UAAU,CAAC,CAAC;QACrC,MAAM,aAAa,GAAG,IAAI,cAAO,CAC/B,IAAI,EACJ,uBAAA,IAAI,0DAAmB,MAAvB,IAAI,CAAqB,EACzB,OAAO,CAAC,MAAM,EACd,IAAI,EACJ,OAAO,EACP,KAAK,CACN,CAAC;QACF,IAAI,CAAC,QAAQ,CAAC,6BAAiB,EAAE,EAAE,aAAa,EAAE,CAAC,CAAC;QACpD,uBAAA,IAAI,gDAAS,MAAb,IAAI,EAAU,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QAC5C,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE;YACzB,SAAS,EAAE,IAAI;YACf,OAAO,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,aAAa,EAAE;SAClD,CAAC,CAAC;QACH,uBAAA,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AI,MAAA,OAAO,CAAC,MAAM,0CAAE,cAAc,EAAE,CAAC;QACnC,IAAA,cAAK,EAAC,IAAI,EAAE,uBAAc,CAAC,8BAA8B,CAAC,CAAC;IAC7D,CAAC;IACD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO;IACT,CAAC;IACD,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;QACrB,MAAM,YAAY,GAAG,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC3D,MAAM,UAAU,GAAG,YAAY,CAAC,MAAM,CACpC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,CAAC,EACrC,IAAI,CAAC,WAAW,CACjB,CAAC;QACF,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;SAAM,CAAC;QACN,sEAAsE;QACtE,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC;IAC7B,CAAC;IACD,OAAO,CAAC,UAAU,IAAI,CAAC,CAAC;AAC1B,CAAC,mDACQ,IAAmB,EAAE,IAAc,EAAE,OAAoB;IAChE,uBAAA,IAAI,mDAAY,MAAhB,IAAI,EAAa,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;IACnD,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Expression } from "@babel/types";
|
|
2
|
+
import { TagNode } from "./node";
|
|
3
|
+
export interface NodeValue {
|
|
4
|
+
type: "string" | "expression" | "null";
|
|
5
|
+
value?: string | undefined;
|
|
6
|
+
expression?: Expression | undefined;
|
|
7
|
+
}
|
|
8
|
+
export type Qualifier = string | undefined;
|
|
9
|
+
export declare class Directive {
|
|
10
|
+
static attributeName: string;
|
|
11
|
+
static help: string;
|
|
12
|
+
apply(node: TagNode, value: NodeValue, qualifier: Qualifier, base: string): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directive.js","sourceRoot":"","sources":["../../src/models/directive.ts"],"names":[],"mappings":";;;AAWA,MAAa,SAAS;IAGpB,KAAK,CAAC,IAAa,EAAE,KAAgB,EAAE,SAAoB,EAAE,IAAY,IAAG,CAAC;CAC9E;AAJD,8BAIC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Module } from "./module";
|
|
2
|
+
import { Directive, NodeValue, Qualifier } from "./directive";
|
|
3
|
+
import { Component, WalkTracker } from "./component";
|
|
4
|
+
import { ExtractedNode, TagNode, DynamicTextNode, PlainTextNode } from "./node";
|
|
5
|
+
export { Component, Directive, NodeValue, ExtractedNode, TagNode, DynamicTextNode, PlainTextNode, Module, Qualifier, WalkTracker, };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Module = exports.PlainTextNode = exports.DynamicTextNode = exports.TagNode = exports.ExtractedNode = exports.Directive = exports.Component = void 0;
|
|
4
|
+
const module_1 = require("./module");
|
|
5
|
+
Object.defineProperty(exports, "Module", { enumerable: true, get: function () { return module_1.Module; } });
|
|
6
|
+
const directive_1 = require("./directive");
|
|
7
|
+
Object.defineProperty(exports, "Directive", { enumerable: true, get: function () { return directive_1.Directive; } });
|
|
8
|
+
const component_1 = require("./component");
|
|
9
|
+
Object.defineProperty(exports, "Component", { enumerable: true, get: function () { return component_1.Component; } });
|
|
10
|
+
const node_1 = require("./node");
|
|
11
|
+
Object.defineProperty(exports, "ExtractedNode", { enumerable: true, get: function () { return node_1.ExtractedNode; } });
|
|
12
|
+
Object.defineProperty(exports, "TagNode", { enumerable: true, get: function () { return node_1.TagNode; } });
|
|
13
|
+
Object.defineProperty(exports, "DynamicTextNode", { enumerable: true, get: function () { return node_1.DynamicTextNode; } });
|
|
14
|
+
Object.defineProperty(exports, "PlainTextNode", { enumerable: true, get: function () { return node_1.PlainTextNode; } });
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":";;;AAAA,qCAAkC;AAahC,uFAbO,eAAM,OAaP;AAZR,2CAA8D;AAM5D,0FANO,qBAAS,OAMP;AALX,2CAAqD;AAInD,0FAJO,qBAAS,OAIP;AAHX,iCAAgF;AAM9E,8FANO,oBAAa,OAMP;AACb,wFAPsB,cAAO,OAOtB;AACP,gGAR+B,sBAAe,OAQ/B;AACf,8FATgD,oBAAa,OAShD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { NodePath } from "@babel/core";
|
|
2
|
+
import type { ImportSpecifier, Program } from "@babel/types";
|
|
3
|
+
import { IMPORTABLES } from "../constants";
|
|
4
|
+
export declare class Module {
|
|
5
|
+
path: NodePath<Program>;
|
|
6
|
+
existingImports: Set<string>;
|
|
7
|
+
requestedImports: Set<string>;
|
|
8
|
+
constructor(path: NodePath<Program>);
|
|
9
|
+
foundImport(path: NodePath<ImportSpecifier>): void;
|
|
10
|
+
requireImport(name: IMPORTABLES): void;
|
|
11
|
+
addMissingImports(): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Module = void 0;
|
|
4
|
+
const t = require("@babel/types");
|
|
5
|
+
function addImportStatement(path, name, source) {
|
|
6
|
+
const specifier = t.importSpecifier(t.identifier(name), t.identifier(name));
|
|
7
|
+
const importStatement = t.importDeclaration([specifier], t.stringLiteral(source));
|
|
8
|
+
path.unshiftContainer("body", importStatement);
|
|
9
|
+
}
|
|
10
|
+
class Module {
|
|
11
|
+
constructor(path) {
|
|
12
|
+
this.path = path;
|
|
13
|
+
this.existingImports = new Set();
|
|
14
|
+
this.requestedImports = new Set();
|
|
15
|
+
}
|
|
16
|
+
foundImport(path) {
|
|
17
|
+
const imported = path.node.imported;
|
|
18
|
+
const parent = path.parent;
|
|
19
|
+
const name = t.isIdentifier(imported) ? imported.name : imported.value;
|
|
20
|
+
const source = t.isImportDeclaration(parent)
|
|
21
|
+
? parent.source.value
|
|
22
|
+
: undefined;
|
|
23
|
+
if (source === "wallace") {
|
|
24
|
+
this.existingImports.add(name);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
requireImport(name) {
|
|
28
|
+
this.requestedImports.add(name);
|
|
29
|
+
}
|
|
30
|
+
addMissingImports() {
|
|
31
|
+
this.requestedImports.forEach((entry) => {
|
|
32
|
+
if (!this.existingImports.has(entry)) {
|
|
33
|
+
addImportStatement(this.path, entry, "wallace");
|
|
34
|
+
this.existingImports.add(entry);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.Module = Module;
|
|
40
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/models/module.ts"],"names":[],"mappings":";;;AAAA,kCAAkC;AAKlC,SAAS,kBAAkB,CACzB,IAAuB,EACvB,IAAY,EACZ,MAAc;IAEd,MAAM,SAAS,GAAG,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;IAC5E,MAAM,eAAe,GAAG,CAAC,CAAC,iBAAiB,CACzC,CAAC,SAAS,CAAC,EACX,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CACxB,CAAC;IACF,IAAI,CAAC,gBAAgB,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;AACjD,CAAC;AAED,MAAa,MAAM;IAIjB,YAAY,IAAuB;QACjC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB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from "@babel/types";
|
|
3
|
+
interface Attribute {
|
|
4
|
+
name: string;
|
|
5
|
+
value?: string;
|
|
6
|
+
}
|
|
7
|
+
interface Watch {
|
|
8
|
+
expression: Expression;
|
|
9
|
+
callback: string;
|
|
10
|
+
}
|
|
11
|
+
interface RepeatInstruction {
|
|
12
|
+
expression: Expression;
|
|
13
|
+
componentCls: string;
|
|
14
|
+
poolExpression: Expression | undefined;
|
|
15
|
+
}
|
|
16
|
+
interface EventListener {
|
|
17
|
+
eventName: string;
|
|
18
|
+
callback: Expression;
|
|
19
|
+
}
|
|
20
|
+
interface ConditionalDisplay {
|
|
21
|
+
expression: Expression;
|
|
22
|
+
reverse: boolean;
|
|
23
|
+
}
|
|
24
|
+
type ValidElementType = JSXElement | JSXExpressionContainer | JSXText;
|
|
25
|
+
export declare class ExtractedNode {
|
|
26
|
+
#private;
|
|
27
|
+
component: any;
|
|
28
|
+
tagName: string;
|
|
29
|
+
element: HTMLElement | Text | undefined;
|
|
30
|
+
isRepeatedNode: boolean;
|
|
31
|
+
repeatNode: ExtractedNode | undefined;
|
|
32
|
+
address: Array<number>;
|
|
33
|
+
path: NodePath<ValidElementType>;
|
|
34
|
+
parent: TagNode;
|
|
35
|
+
watches: Watch[];
|
|
36
|
+
eventListeners: EventListener[];
|
|
37
|
+
isNestedClass: boolean;
|
|
38
|
+
repeatExpression: Expression | undefined;
|
|
39
|
+
poolExpression: Expression | undefined;
|
|
40
|
+
constructor(address: Array<number>, path: NodePath<ValidElementType>, parent: TagNode);
|
|
41
|
+
getElement(): HTMLElement | Text;
|
|
42
|
+
addEventListener(eventName: string, callback: Expression): void;
|
|
43
|
+
watchAttribute(attName: string, expression: Expression): void;
|
|
44
|
+
watchText(expression: Expression): void;
|
|
45
|
+
setProps(expression: Expression): void;
|
|
46
|
+
getProps(): Expression | undefined;
|
|
47
|
+
setConditionalDisplay(expression: Expression, reverse: boolean): void;
|
|
48
|
+
getShieldInfo(): ConditionalDisplay | undefined;
|
|
49
|
+
setRef(name: string): void;
|
|
50
|
+
getRef(): string | undefined;
|
|
51
|
+
setRepeatExpression(expression: Expression): void;
|
|
52
|
+
/**
|
|
53
|
+
* Called on the parent of a repeat.
|
|
54
|
+
*/
|
|
55
|
+
getRepeatInstruction(): RepeatInstruction | undefined;
|
|
56
|
+
setStub(name: string): void;
|
|
57
|
+
getStub(): string | undefined;
|
|
58
|
+
setBaseComponent(expression: Expression): void;
|
|
59
|
+
}
|
|
60
|
+
export declare class TagNode extends ExtractedNode {
|
|
61
|
+
parent: TagNode;
|
|
62
|
+
address: Array<number>;
|
|
63
|
+
path: NodePath<JSXElement>;
|
|
64
|
+
attributes: Attribute[];
|
|
65
|
+
constructor(path: NodePath<JSXElement>, address: Array<number>, parent: TagNode, component: any, // TODO: fix type circular import.
|
|
66
|
+
tagName: string, isNestedClass: boolean);
|
|
67
|
+
addFixedAttribute(name: string, value?: string): void;
|
|
68
|
+
getElement(): HTMLElement | undefined;
|
|
69
|
+
}
|
|
70
|
+
export declare class StubNode extends ExtractedNode {
|
|
71
|
+
constructor(path: NodePath<JSXElement>, address: Array<number>, parent: TagNode, name: string);
|
|
72
|
+
getElement(): HTMLElement | Text;
|
|
73
|
+
}
|
|
74
|
+
export declare class DynamicTextNode extends ExtractedNode {
|
|
75
|
+
constructor(path: NodePath<JSXExpressionContainer>, address: Array<number>, parent: TagNode, expression: Expression);
|
|
76
|
+
getElement(): HTMLElement | Text;
|
|
77
|
+
}
|
|
78
|
+
export declare class PlainTextNode extends ExtractedNode {
|
|
79
|
+
constructor(path: NodePath<JSXText>, address: Array<number>, parent: TagNode);
|
|
80
|
+
getElement(): HTMLElement | Text;
|
|
81
|
+
}
|
|
82
|
+
export {};
|