nesquick 2.1.0 → 2.2.0
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/lib/NesquickComponent.js +52 -8
- package/lib/NesquickFragment.js +2 -2
- package/lib/cli/transformer.js +18 -14
- package/lib/jsx-runtime.js +4 -10
- package/lib/types/NesquickComponent.d.ts +7 -6
- package/lib/types/NesquickFragment.d.ts +3 -3
- package/lib/types/jsx-runtime.d.ts +1 -1
- package/package.json +1 -1
package/lib/NesquickComponent.js
CHANGED
|
@@ -21,21 +21,65 @@ function getAttributeNs(attributes, k) {
|
|
|
21
21
|
}
|
|
22
22
|
return null;
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
const res =
|
|
24
|
+
function getterFromFunctionsSingleChildren(props) {
|
|
25
|
+
const res = {};
|
|
26
26
|
for (const k in props) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
if (k === "children") {
|
|
28
|
+
const v = props.children;
|
|
29
|
+
if (typeof v === "function" && !(v instanceof NesquickComponent)) {
|
|
30
|
+
Object.defineProperty(res, "children", {
|
|
31
|
+
get() {
|
|
32
|
+
return v();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
res.children = v;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const v = props[k];
|
|
42
|
+
Object.defineProperty(res, k, {
|
|
43
|
+
get() {
|
|
44
|
+
return v();
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return res;
|
|
50
|
+
}
|
|
51
|
+
function getterFromFunctionsArrayChildren(props) {
|
|
52
|
+
const res = {};
|
|
53
|
+
for (const k in props) {
|
|
54
|
+
if (k === "children") {
|
|
55
|
+
res.children = props.children;
|
|
56
|
+
for (let i = 0; i < props.children.length; i++) {
|
|
57
|
+
const v = props.children[i];
|
|
58
|
+
if (typeof v === "function" && !(v instanceof NesquickComponent)) {
|
|
59
|
+
Object.defineProperty(res.children, i, {
|
|
60
|
+
get() {
|
|
61
|
+
return v();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
30
65
|
}
|
|
31
|
-
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const v = props[k];
|
|
69
|
+
Object.defineProperty(res, k, {
|
|
70
|
+
get() {
|
|
71
|
+
return v();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
32
75
|
}
|
|
33
76
|
return res;
|
|
34
77
|
}
|
|
35
78
|
class NesquickComponent {
|
|
36
|
-
constructor(_render, props) {
|
|
79
|
+
constructor(_render, props, jsxs = false) {
|
|
37
80
|
this._render = _render;
|
|
38
81
|
this.props = props;
|
|
82
|
+
this.jsxs = jsxs;
|
|
39
83
|
this._subscriptions = new State_1.Subscriptions();
|
|
40
84
|
this._styleSubscriptions = null;
|
|
41
85
|
this._xmlns = null;
|
|
@@ -45,7 +89,7 @@ class NesquickComponent {
|
|
|
45
89
|
render(document) {
|
|
46
90
|
State_1.subscriptions.set(this._subscriptions);
|
|
47
91
|
if (typeof this._render === "function") {
|
|
48
|
-
this.props =
|
|
92
|
+
this.props = this.jsxs ? getterFromFunctionsArrayChildren(this.props) : getterFromFunctionsSingleChildren(this.props);
|
|
49
93
|
const element = this._render(this.props);
|
|
50
94
|
if (this._xmlns) {
|
|
51
95
|
element.setXmlns(this._xmlns);
|
package/lib/NesquickFragment.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.NesquickFragment = void 0;
|
|
4
4
|
const NesquickComponent_1 = require("./NesquickComponent");
|
|
5
5
|
class NesquickFragment extends NesquickComponent_1.NesquickComponent {
|
|
6
|
-
constructor(children) {
|
|
7
|
-
super("", { children });
|
|
6
|
+
constructor(children, jsxs = false) {
|
|
7
|
+
super("", { children }, jsxs);
|
|
8
8
|
this._lastNode = null;
|
|
9
9
|
this._fragment = null;
|
|
10
10
|
}
|
package/lib/cli/transformer.js
CHANGED
|
@@ -7,6 +7,7 @@ function getSingleIdentifier(node) {
|
|
|
7
7
|
node.forEachChild(node => {
|
|
8
8
|
if (TS.isIdentifier(node)) {
|
|
9
9
|
if (identifier != null) {
|
|
10
|
+
identifier = null;
|
|
10
11
|
return node;
|
|
11
12
|
}
|
|
12
13
|
identifier = node;
|
|
@@ -53,6 +54,9 @@ function createSpreadCheckFunction(fName) {
|
|
|
53
54
|
TS.factory.createReturnStatement(res)
|
|
54
55
|
], true));
|
|
55
56
|
}
|
|
57
|
+
function arrowify(node) {
|
|
58
|
+
return TS.factory.createArrowFunction(void 0, void 0, [], void 0, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), node);
|
|
59
|
+
}
|
|
56
60
|
const transformer = context => {
|
|
57
61
|
return sourceFile => {
|
|
58
62
|
let hasSpreadChecker = false;
|
|
@@ -67,7 +71,7 @@ const transformer = context => {
|
|
|
67
71
|
return { node, hasCallExpression };
|
|
68
72
|
};
|
|
69
73
|
const visitGeneric = (node, options) => {
|
|
70
|
-
let hasCallExpression = TS.isCallExpression(node);
|
|
74
|
+
let hasCallExpression = TS.isCallExpression(node) || TS.isElementAccessExpression(node) || TS.isPropertyAccessExpression(node);
|
|
71
75
|
if (TS.isJsxSpreadAttribute(node)) {
|
|
72
76
|
hasSpreadChecker = true;
|
|
73
77
|
const expression = visitGeneric(node.expression, {}).node;
|
|
@@ -76,19 +80,12 @@ const transformer = context => {
|
|
|
76
80
|
node = TS.factory.updateJsxSpreadAttribute(node, callExpression);
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
|
-
else if (TS.isJsxElement(node)) {
|
|
80
|
-
const firstLetter = node.openingElement.tagName.getText()[0];
|
|
83
|
+
else if (TS.isJsxElement(node) || TS.isJsxSelfClosingElement(node)) {
|
|
84
|
+
const firstLetter = TS.isJsxSelfClosingElement(node) ? node.tagName.getText()[0] : node.openingElement.tagName.getText()[0];
|
|
81
85
|
const userComponent = firstLetter !== firstLetter.toLowerCase();
|
|
82
86
|
const res = processNode(node, { userComponent });
|
|
83
87
|
node = res.node;
|
|
84
88
|
}
|
|
85
|
-
else if (TS.isJsxOpeningLikeElement(node)) {
|
|
86
|
-
const firstLetter = node.tagName.getText()[0];
|
|
87
|
-
const userComponent = firstLetter !== firstLetter.toLowerCase();
|
|
88
|
-
const res = processNode(node, { userComponent });
|
|
89
|
-
node = res.node;
|
|
90
|
-
hasCallExpression = hasCallExpression || res.hasCallExpression;
|
|
91
|
-
}
|
|
92
89
|
else if (TS.isJsxAttribute(node)) {
|
|
93
90
|
node = TS.visitEachChild(node, node => {
|
|
94
91
|
const res = visitGeneric(node, { ...options, isJsxAttribute: true });
|
|
@@ -108,6 +105,12 @@ const transformer = context => {
|
|
|
108
105
|
node = TS.factory.createJsxExpression(void 0, returnNode);
|
|
109
106
|
}
|
|
110
107
|
}
|
|
108
|
+
else if (TS.isFunctionLike(node)) {
|
|
109
|
+
node = TS.visitEachChild(node, node => {
|
|
110
|
+
const res = visitGeneric(node, { ...options, isJsxAttribute: false });
|
|
111
|
+
return res.node;
|
|
112
|
+
}, context);
|
|
113
|
+
}
|
|
111
114
|
else {
|
|
112
115
|
node = TS.visitEachChild(node, node => {
|
|
113
116
|
const res = visitGeneric(node, { ...options, isJsxAttribute: false });
|
|
@@ -115,6 +118,9 @@ const transformer = context => {
|
|
|
115
118
|
return res.node;
|
|
116
119
|
}, context);
|
|
117
120
|
}
|
|
121
|
+
if (TS.isJsxChild(node) && !TS.isJsxText(node) && !TS.isJsxExpression(node) && options.userComponent) {
|
|
122
|
+
node = TS.factory.createJsxExpression(void 0, arrowify(node));
|
|
123
|
+
}
|
|
118
124
|
return { node, hasCallExpression };
|
|
119
125
|
};
|
|
120
126
|
const visitorExpression = (node, options) => {
|
|
@@ -132,10 +138,8 @@ const transformer = context => {
|
|
|
132
138
|
}
|
|
133
139
|
const res = visitGeneric(node, {});
|
|
134
140
|
node = res.node;
|
|
135
|
-
if (TS.
|
|
136
|
-
|
|
137
|
-
node = TS.factory.createArrowFunction(void 0, void 0, [], void 0, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), node);
|
|
138
|
-
}
|
|
141
|
+
if (TS.isConciseBody(node) && (options.userComponent || res.hasCallExpression)) {
|
|
142
|
+
node = arrowify(node);
|
|
139
143
|
}
|
|
140
144
|
return node;
|
|
141
145
|
};
|
package/lib/jsx-runtime.js
CHANGED
|
@@ -7,22 +7,16 @@ const NesquickComponent_1 = require("./NesquickComponent");
|
|
|
7
7
|
const NesquickFragment_1 = require("./NesquickFragment");
|
|
8
8
|
exports.Fragment = Symbol();
|
|
9
9
|
function jsxs(type, props, key) {
|
|
10
|
-
|
|
11
|
-
return new NesquickFragment_1.NesquickFragment(props.children);
|
|
12
|
-
}
|
|
13
|
-
if (key !== undefined) {
|
|
14
|
-
props.key = key;
|
|
15
|
-
}
|
|
16
|
-
return new NesquickComponent_1.NesquickComponent(type, props);
|
|
10
|
+
return jsx(type, props, key, true);
|
|
17
11
|
}
|
|
18
|
-
function jsx(type, props, key) {
|
|
12
|
+
function jsx(type, props, key, jsxs = false) {
|
|
19
13
|
if (type === exports.Fragment) {
|
|
20
|
-
return new NesquickFragment_1.NesquickFragment([props.children]);
|
|
14
|
+
return new NesquickFragment_1.NesquickFragment([props.children], jsxs);
|
|
21
15
|
}
|
|
22
16
|
if (key !== undefined) {
|
|
23
17
|
props.key = key;
|
|
24
18
|
}
|
|
25
|
-
return new NesquickComponent_1.NesquickComponent(type, props);
|
|
19
|
+
return new NesquickComponent_1.NesquickComponent(type, props, jsxs);
|
|
26
20
|
}
|
|
27
21
|
var JSX;
|
|
28
22
|
(function (JSX) {
|
|
@@ -2,8 +2,8 @@ export type Child = NesquickComponent<any> | NesquickFragment | string | boolean
|
|
|
2
2
|
export type Children = Child | Child[];
|
|
3
3
|
export type ChildFunc = () => Exclude<Child, ChildFunc> | Exclude<Child, ChildFunc>[];
|
|
4
4
|
export type ComponentProps = Record<string, any>;
|
|
5
|
-
export type FunctionComponent<P extends ComponentProps = {}> = (props: P) => NesquickComponent<
|
|
6
|
-
export type
|
|
5
|
+
export type FunctionComponent<P extends ComponentProps = {}> = (props: P) => NesquickComponent<any>;
|
|
6
|
+
export type NesquickDocument = Pick<Document, "createElement" | "createElementNS" | "createTextNode" | "createDocumentFragment" | "createComment">;
|
|
7
7
|
type NesquickChild = {
|
|
8
8
|
node: Node | null;
|
|
9
9
|
} & ({
|
|
@@ -25,25 +25,26 @@ type XmlNs = {
|
|
|
25
25
|
export declare class NesquickComponent<P extends ComponentProps = {}> {
|
|
26
26
|
private _render;
|
|
27
27
|
protected props: P;
|
|
28
|
+
protected jsxs: boolean;
|
|
28
29
|
private _subscriptions;
|
|
29
30
|
private _styleSubscriptions;
|
|
30
31
|
private _xmlns;
|
|
31
32
|
private _onUpdate;
|
|
32
33
|
protected _children: NesquickChild[];
|
|
33
|
-
constructor(_render: string | FunctionComponent<P>, props: P);
|
|
34
|
-
render(document:
|
|
34
|
+
constructor(_render: string | FunctionComponent<P>, props: P, jsxs?: boolean);
|
|
35
|
+
render(document: NesquickDocument): Node;
|
|
35
36
|
setXmlns(xmlns: XmlNs | null): void;
|
|
36
37
|
private _onUpdated;
|
|
37
38
|
private _renderPropsNs;
|
|
38
39
|
private _renderProps;
|
|
39
40
|
private _renderStyles;
|
|
40
41
|
private _renderStyle;
|
|
41
|
-
protected _renderChildren(document:
|
|
42
|
+
protected _renderChildren(document: NesquickDocument, parent: NesquickParent, children?: Children): void;
|
|
42
43
|
protected _pushChild(): NesquickChild;
|
|
43
44
|
protected _spliceChild(i: number): NesquickChild;
|
|
44
45
|
protected _swapChilds(parent: NesquickParent, i1: number, i2: number): void;
|
|
45
46
|
protected _removeChild(i: number): void;
|
|
46
|
-
protected _renderChild(document:
|
|
47
|
+
protected _renderChild(document: NesquickDocument, parent: NesquickParent, nesquickChild: NesquickChild, child: Exclude<Child, ChildFunc> | Exclude<Child, ChildFunc>[]): void;
|
|
47
48
|
dispose(): void;
|
|
48
49
|
}
|
|
49
50
|
import { NesquickFragment } from "./NesquickFragment";
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { JSX } from "./Nesquick";
|
|
2
|
-
import { Child, NesquickComponent, NesquickParent,
|
|
2
|
+
import { Child, NesquickComponent, NesquickParent, NesquickDocument } from "./NesquickComponent";
|
|
3
3
|
export declare class NesquickFragment extends NesquickComponent<{
|
|
4
4
|
children: Child[];
|
|
5
5
|
}> implements NesquickParent {
|
|
6
6
|
private _lastNode;
|
|
7
7
|
private _fragment;
|
|
8
|
-
constructor(children: Child[]);
|
|
9
|
-
render(document:
|
|
8
|
+
constructor(children: Child[], jsxs?: boolean);
|
|
9
|
+
render(document: NesquickDocument): Node;
|
|
10
10
|
getDocument(): Document | null;
|
|
11
11
|
getParent(): Node | null;
|
|
12
12
|
appendChild(child: Node): void;
|
|
@@ -2,7 +2,7 @@ import { FunctionComponent, ComponentProps, NesquickComponent } from "./Nesquick
|
|
|
2
2
|
import { NesquickFragment } from "./NesquickFragment";
|
|
3
3
|
export declare const Fragment: unique symbol;
|
|
4
4
|
export declare function jsxs<P extends ComponentProps>(type: string | FunctionComponent<P> | typeof Fragment, props: P, key?: string | number | null): NesquickFragment | NesquickComponent<P>;
|
|
5
|
-
export declare function jsx<P extends ComponentProps>(type: string | FunctionComponent<P> | typeof Fragment, props: P, key?: string | number | null): NesquickFragment | NesquickComponent<P>;
|
|
5
|
+
export declare function jsx<P extends ComponentProps>(type: string | FunctionComponent<P> | typeof Fragment, props: P, key?: string | number | null, jsxs?: boolean): NesquickFragment | NesquickComponent<P>;
|
|
6
6
|
export type Component<P extends Record<any, any> = {}> = (props: P) => JSX.Element;
|
|
7
7
|
export declare namespace JSX {
|
|
8
8
|
export type JSXEvent<T extends Event, T2 extends EventTarget> = T & {
|