nesquick 0.0.25 → 0.0.27
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/NesquickFragment.js +3 -1
- package/lib/cli/transformer.js +86 -25
- package/lib/jsx-runtime.js +5 -0
- package/lib/no-transformer/jsx-runtime.js +2 -1
- package/lib/types/NesquickFragment.d.ts +3 -3
- package/lib/types/State.d.ts +3 -1
- package/lib/types/jsx-runtime.d.ts +5 -2
- package/lib/types/no-transformer/jsx-runtime.d.ts +2 -1
- package/package.json +1 -1
package/lib/NesquickFragment.js
CHANGED
|
@@ -4,7 +4,9 @@ exports.NesquickFragment = void 0;
|
|
|
4
4
|
const NesquickComponent_1 = require("./NesquickComponent");
|
|
5
5
|
class NesquickFragment extends NesquickComponent_1.NesquickComponent {
|
|
6
6
|
constructor(children) {
|
|
7
|
-
super("", {
|
|
7
|
+
super("", {
|
|
8
|
+
children: children != null ? Array.isArray(children) ? children : [children] : []
|
|
9
|
+
});
|
|
8
10
|
this._lastNode = null;
|
|
9
11
|
this._fragment = null;
|
|
10
12
|
}
|
package/lib/cli/transformer.js
CHANGED
|
@@ -24,60 +24,121 @@ function getSingleBody(node) {
|
|
|
24
24
|
}
|
|
25
25
|
return null;
|
|
26
26
|
}
|
|
27
|
-
function hasIdentifier(node) {
|
|
28
|
-
let found = false;
|
|
29
|
-
node.forEachChild(node => {
|
|
30
|
-
if (!found && (TS.isIdentifier(node) || hasIdentifier(node))) {
|
|
31
|
-
found = true;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
return found;
|
|
35
|
-
}
|
|
36
27
|
const transformer = context => {
|
|
37
28
|
return sourceFile => {
|
|
38
29
|
const visitGeneric = (node, options) => {
|
|
30
|
+
let hasSpread = options.userComponent && TS.isJsxSpreadAttribute(node);
|
|
31
|
+
let hasChildIdentifier = false;
|
|
39
32
|
if (TS.isJsxOpeningLikeElement(node)) {
|
|
40
33
|
const firstLetter = node.tagName.getText()[0];
|
|
41
34
|
const userComponent = firstLetter !== firstLetter.toLowerCase();
|
|
42
|
-
|
|
35
|
+
node = TS.visitEachChild(node, node => {
|
|
36
|
+
const res = visitGeneric(node, { userComponent });
|
|
37
|
+
hasSpread = hasSpread || res.hasSpread;
|
|
38
|
+
hasChildIdentifier = hasChildIdentifier || res.hasChildIdentifier || TS.isIdentifier(node);
|
|
39
|
+
return res.node;
|
|
40
|
+
}, context);
|
|
41
|
+
if (userComponent && hasSpread) {
|
|
42
|
+
const symbol = TS.factory.createCallExpression(TS.factory.createPropertyAccessExpression(TS.factory.createIdentifier("Symbol"), "for"), void 0, [TS.factory.createStringLiteral("$nesquickSpreadProps")]);
|
|
43
|
+
if (TS.isJsxOpeningLikeElement(node)) {
|
|
44
|
+
const attributes = TS.factory.updateJsxAttributes(node.attributes, [
|
|
45
|
+
...node.attributes.properties,
|
|
46
|
+
TS.factory.createJsxSpreadAttribute(TS.factory.createObjectLiteralExpression([
|
|
47
|
+
TS.factory.createPropertyAssignment(TS.factory.createComputedPropertyName(symbol), TS.factory.createTrue())
|
|
48
|
+
]))
|
|
49
|
+
]);
|
|
50
|
+
if (TS.isJsxOpeningElement(node)) {
|
|
51
|
+
node = TS.factory.updateJsxOpeningElement(node, node.tagName, node.typeArguments, attributes);
|
|
52
|
+
}
|
|
53
|
+
else if (TS.isJsxSelfClosingElement(node)) {
|
|
54
|
+
node = TS.factory.updateJsxSelfClosingElement(node, node.tagName, node.typeArguments, attributes);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
43
58
|
}
|
|
44
|
-
if (TS.isJsxAttribute(node)) {
|
|
45
|
-
|
|
59
|
+
else if (TS.isJsxAttribute(node)) {
|
|
60
|
+
node = TS.visitEachChild(node, node => {
|
|
61
|
+
const res = visitGeneric(node, { ...options, isJsxAttribute: true });
|
|
62
|
+
hasSpread = hasSpread || res.hasSpread;
|
|
63
|
+
hasChildIdentifier = hasChildIdentifier || res.hasChildIdentifier || TS.isIdentifier(node);
|
|
64
|
+
return res.node;
|
|
65
|
+
}, context);
|
|
46
66
|
}
|
|
47
67
|
else if (TS.isJsxExpression(node)) {
|
|
48
|
-
|
|
68
|
+
node = TS.visitEachChild(node, node => {
|
|
69
|
+
const res = visitorExpression(node, { ...options, isJsxAttribute: false });
|
|
70
|
+
hasChildIdentifier = hasChildIdentifier || res.hasChildIdentifier || TS.isIdentifier(node);
|
|
71
|
+
return res.node;
|
|
72
|
+
}, context);
|
|
49
73
|
}
|
|
50
74
|
else if (options.isJsxAttribute && TS.isStringLiteral(node)) {
|
|
51
|
-
const returnNode = TS.visitNode(node, node =>
|
|
52
|
-
|
|
53
|
-
|
|
75
|
+
const returnNode = TS.visitNode(node, node => {
|
|
76
|
+
const res = visitorExpression(node, { ...options, isJsxAttribute: false });
|
|
77
|
+
hasChildIdentifier = hasChildIdentifier || res.hasChildIdentifier || TS.isIdentifier(node);
|
|
78
|
+
return res.node;
|
|
79
|
+
}, TS.isExpression);
|
|
80
|
+
if (TS.isStringLiteral(returnNode)) {
|
|
81
|
+
node = returnNode;
|
|
54
82
|
}
|
|
55
|
-
|
|
83
|
+
else {
|
|
84
|
+
node = TS.factory.createJsxExpression(undefined, returnNode);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
node = TS.visitEachChild(node, node => {
|
|
89
|
+
const res = visitGeneric(node, { ...options, isJsxAttribute: false });
|
|
90
|
+
hasSpread = hasSpread || res.hasSpread;
|
|
91
|
+
hasChildIdentifier = hasChildIdentifier || res.hasChildIdentifier || TS.isIdentifier(node);
|
|
92
|
+
return res.node;
|
|
93
|
+
}, context);
|
|
56
94
|
}
|
|
57
|
-
return
|
|
95
|
+
return { hasSpread, hasChildIdentifier, node };
|
|
58
96
|
};
|
|
59
97
|
const visitorExpression = (node, options) => {
|
|
98
|
+
let hasChildIdentifier = false;
|
|
60
99
|
if (TS.isParenthesizedExpression(node)) {
|
|
61
100
|
const body = getSingleBody(node);
|
|
62
101
|
if (body) {
|
|
63
|
-
|
|
102
|
+
node = TS.visitNode(body, node => {
|
|
103
|
+
const res = visitorExpression(node, options);
|
|
104
|
+
hasChildIdentifier = hasChildIdentifier || res.hasChildIdentifier || TS.isIdentifier(node);
|
|
105
|
+
return res.node;
|
|
106
|
+
});
|
|
64
107
|
}
|
|
65
108
|
}
|
|
66
109
|
else if (TS.isCallExpression(node)) {
|
|
67
110
|
const identifier = getSingleIdentifier(node);
|
|
68
111
|
if (identifier) {
|
|
69
|
-
|
|
112
|
+
node = identifier;
|
|
70
113
|
}
|
|
71
114
|
else {
|
|
72
|
-
|
|
115
|
+
node = TS.factory.createArrowFunction(undefined, undefined, [], undefined, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), TS.visitNode(node, node => {
|
|
116
|
+
const res = visitGeneric(node, {});
|
|
117
|
+
hasChildIdentifier = hasChildIdentifier || res.hasChildIdentifier || TS.isIdentifier(node);
|
|
118
|
+
return res.node;
|
|
119
|
+
}, TS.isConciseBody));
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
else if (!TS.isFunctionLike(node) && TS.isExpression(node)) {
|
|
123
|
+
node = TS.visitNode(node, node => {
|
|
124
|
+
const res = visitGeneric(node, {});
|
|
125
|
+
hasChildIdentifier = hasChildIdentifier || res.hasChildIdentifier;
|
|
126
|
+
return res.node;
|
|
127
|
+
});
|
|
128
|
+
if ((options.userComponent || hasChildIdentifier) && TS.isConciseBody(node)) {
|
|
129
|
+
node = TS.factory.createArrowFunction(undefined, undefined, [], undefined, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), node);
|
|
73
130
|
}
|
|
74
131
|
}
|
|
75
|
-
else
|
|
76
|
-
|
|
132
|
+
else {
|
|
133
|
+
node = TS.visitNode(node, node => {
|
|
134
|
+
const res = visitGeneric(node, {});
|
|
135
|
+
hasChildIdentifier = hasChildIdentifier || res.hasChildIdentifier || TS.isIdentifier(node);
|
|
136
|
+
return res.node;
|
|
137
|
+
});
|
|
77
138
|
}
|
|
78
|
-
return
|
|
139
|
+
return { hasChildIdentifier, node };
|
|
79
140
|
};
|
|
80
|
-
return TS.visitNode(sourceFile, node => visitGeneric(node, {}), TS.isSourceFile);
|
|
141
|
+
return TS.visitNode(sourceFile, node => visitGeneric(node, {}).node, TS.isSourceFile);
|
|
81
142
|
};
|
|
82
143
|
};
|
|
83
144
|
exports.transformer = transformer;
|
package/lib/jsx-runtime.js
CHANGED
|
@@ -4,11 +4,16 @@ exports.JSX = exports.jsx = exports.Fragment = void 0;
|
|
|
4
4
|
exports.jsxs = jsxs;
|
|
5
5
|
const NesquickComponent_1 = require("./NesquickComponent");
|
|
6
6
|
const NesquickFragment_1 = require("./NesquickFragment");
|
|
7
|
+
const jsx_runtime_1 = require("./no-transformer/jsx-runtime");
|
|
8
|
+
const propsSpreadSymbol = Symbol.for("$nesquickSpreadProps");
|
|
7
9
|
exports.Fragment = Symbol();
|
|
8
10
|
function jsxs(type, props, key) {
|
|
9
11
|
if (type === exports.Fragment) {
|
|
10
12
|
return new NesquickFragment_1.NesquickFragment(props.children);
|
|
11
13
|
}
|
|
14
|
+
if (props[propsSpreadSymbol]) {
|
|
15
|
+
(0, jsx_runtime_1.functionizeProps)(props);
|
|
16
|
+
}
|
|
12
17
|
if (key !== undefined) {
|
|
13
18
|
props.key = key;
|
|
14
19
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.JSX = exports.jsx = exports.Fragment = void 0;
|
|
4
|
+
exports.functionizeProps = functionizeProps;
|
|
4
5
|
exports.jsxs = jsxs;
|
|
5
6
|
const NesquickComponent_1 = require("../NesquickComponent");
|
|
6
7
|
const NesquickFragment_1 = require("../NesquickFragment");
|
|
7
8
|
exports.Fragment = Symbol();
|
|
8
9
|
function functionizeProps(props) {
|
|
9
10
|
for (const k in props) {
|
|
10
|
-
if (typeof props[k] !== "function") {
|
|
11
|
+
if (k !== "children" && typeof props[k] !== "function") {
|
|
11
12
|
const v = props[k];
|
|
12
13
|
props[k] = () => v;
|
|
13
14
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { JSX } from "./jsx-runtime";
|
|
2
|
-
import { NesquickComponent, NesquickParent, VeactDocument } from "./NesquickComponent";
|
|
2
|
+
import { Child, Children, NesquickComponent, NesquickParent, VeactDocument } from "./NesquickComponent";
|
|
3
3
|
export declare class NesquickFragment extends NesquickComponent<{
|
|
4
|
-
children:
|
|
4
|
+
children: Child[];
|
|
5
5
|
}> implements NesquickParent {
|
|
6
6
|
private _lastNode;
|
|
7
7
|
private _fragment;
|
|
8
|
-
constructor(children:
|
|
8
|
+
constructor(children: Children);
|
|
9
9
|
render(document: VeactDocument): Node;
|
|
10
10
|
getDocument(): Document | null;
|
|
11
11
|
getParent(): Node | null;
|
package/lib/types/State.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type Getter<T> = () => T;
|
|
2
|
+
export type Setter<T> = (value: T) => void;
|
|
3
|
+
export type State<T> = [get: Getter<T>, set: Setter<T>];
|
|
2
4
|
export type Subscription<T> = {
|
|
3
5
|
cb: () => T;
|
|
4
6
|
reaction: ((data: T, isState: boolean) => void) | null;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { FunctionComponent, ComponentProps, NesquickComponent } from "./NesquickComponent";
|
|
2
2
|
import { NesquickFragment } from "./NesquickFragment";
|
|
3
|
+
declare const propsSpreadSymbol: unique symbol;
|
|
3
4
|
export declare const Fragment: unique symbol;
|
|
4
|
-
export declare function jsxs<P extends ComponentProps
|
|
5
|
+
export declare function jsxs<P extends ComponentProps & {
|
|
6
|
+
[propsSpreadSymbol]?: true;
|
|
7
|
+
}>(type: string | FunctionComponent<P> | typeof Fragment, props: P, key?: string | number | null): NesquickFragment | NesquickComponent<P>;
|
|
5
8
|
export declare const jsx: typeof jsxs;
|
|
6
9
|
type HasUndefined<T, K extends keyof T> = {
|
|
7
10
|
[L in K]-?: T[K] | undefined;
|
|
@@ -14,7 +17,7 @@ type WrappedFunction<T> = (() => T) & {
|
|
|
14
17
|
};
|
|
15
18
|
type UserProp<T> = T extends (...args: any[]) => any ? T : WrappedFunction<T>;
|
|
16
19
|
type UserProps<T> = {
|
|
17
|
-
readonly [K in keyof T]: HasUndefined<T, K> extends true ? UserProp<T[K] | undefined> : UserProp<Exclude<T[K], undefined>>;
|
|
20
|
+
readonly [K in keyof T]: K extends keyof JSX.ElementChildrenAttribute ? T[K] : HasUndefined<T, K> extends true ? UserProp<T[K] | undefined> : UserProp<Exclude<T[K], undefined>>;
|
|
18
21
|
};
|
|
19
22
|
type JSXProp<T> = T extends {
|
|
20
23
|
readonly [WrappedFunctionType]?: infer R;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { FunctionComponent, ComponentProps, NesquickComponent } from "../NesquickComponent";
|
|
2
2
|
import { NesquickFragment } from "../NesquickFragment";
|
|
3
3
|
export declare const Fragment: unique symbol;
|
|
4
|
+
export declare function functionizeProps(props: ComponentProps): void;
|
|
4
5
|
export declare function jsxs<P extends ComponentProps>(type: string | FunctionComponent<P> | typeof Fragment, props: P, key?: string | number | null): NesquickFragment | NesquickComponent<P>;
|
|
5
6
|
export declare const jsx: typeof jsxs;
|
|
6
7
|
type HasUndefined<T, K extends keyof T> = {
|
|
@@ -14,7 +15,7 @@ type WrappedFunction<T> = (() => T) & {
|
|
|
14
15
|
};
|
|
15
16
|
type UserProp<T> = T extends (...args: infer A) => infer R ? (((...args: A) => R) | T) : WrappedFunction<T>;
|
|
16
17
|
type UserProps<T> = {
|
|
17
|
-
readonly [K in keyof T]: HasUndefined<T, K> extends true ? UserProp<T[K] | undefined> : UserProp<Exclude<T[K], undefined>>;
|
|
18
|
+
readonly [K in keyof T]: K extends keyof JSX.ElementChildrenAttribute ? T[K] : HasUndefined<T, K> extends true ? UserProp<T[K] | undefined> : UserProp<Exclude<T[K], undefined>>;
|
|
18
19
|
};
|
|
19
20
|
type JSXProp<T> = T extends {
|
|
20
21
|
readonly [WrappedFunctionType]?: infer R;
|