nesquick 1.1.0 → 1.3.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/README.md +2 -2
- package/lib/Nesquick.js +4 -1
- package/lib/NesquickComponent.js +11 -3
- package/lib/index.js +0 -3
- package/lib/jsx-runtime.js +15 -11
- package/lib/types/For/For.d.ts +1 -1
- package/lib/types/For/getMap.d.ts +1 -1
- package/lib/types/Nesquick.d.ts +64 -0
- package/lib/types/NesquickFragment.d.ts +1 -1
- package/lib/types/State.d.ts +2 -2
- package/lib/types/index.d.ts +0 -3
- package/lib/types/jsx-runtime.d.ts +4 -69
- package/package.json +2 -8
- package/lib/cli/nesquick-tsc.js +0 -12
- package/lib/cli/processArgv.js +0 -19
- package/lib/cli/transformer.js +0 -144
- package/lib/cli/tsc.js +0 -56
- package/lib/no-transformer/jsx-dev-runtime.js +0 -22
- package/lib/no-transformer/jsx-runtime.js +0 -32
- package/lib/plugins/viteTransformerPlugin.js +0 -28
- package/lib/types/cli/nesquick-tsc.d.ts +0 -2
- package/lib/types/cli/processArgv.d.ts +0 -1
- package/lib/types/cli/transformer.d.ts +0 -2
- package/lib/types/cli/tsc.d.ts +0 -7
- package/lib/types/no-transformer/jsx-dev-runtime.d.ts +0 -9
- package/lib/types/no-transformer/jsx-runtime.d.ts +0 -72
- package/lib/types/plugins/viteTransformerPlugin.d.ts +0 -8
package/README.md
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
### Motivation
|
|
2
|
-
I like react, but it always bugged me how you need to create a full fake DOM that is going to be compared to a virtual DOM to finally render the updates in the browser. Yes, it will only update the real DOM with the new changes, but the process of creating a full fake DOM and comparing it each time something is updated is incredibly resource wasting. I always thought in a way to link states to HTML elementos directly, so no more virtual DOM is needed, and like so, **N**imble **E**
|
|
2
|
+
I like react, but it always bugged me how you need to create a full fake DOM that is going to be compared to a virtual DOM to finally render the updates in the browser. Yes, it will only update the real DOM with the new changes, but the process of creating a full fake DOM and comparing it each time something is updated is incredibly resource wasting. I always thought in a way to link states to HTML elementos directly, so no more virtual DOM is needed, and like so, **N**imble **E**elements **S**uper **Quick** (`nesquick`) was born. At first it required for you to define the *subscribers*, so if you forgot to create a subscriber, no state will be linked to an HTML property. Now, with the magic of Typescript, you can link states to HTML elements without taking care of the subscribers, which makes it easier. For example, this is `nesquick`:
|
|
3
3
|
```ts
|
|
4
4
|
import { useState } from "nesquick";
|
|
5
5
|
|
|
6
6
|
function MyComp() {
|
|
7
7
|
const [ getNumber, setNumber ] = useState(0);
|
|
8
8
|
return <div>
|
|
9
|
-
<button onClick={() => setNumber(
|
|
9
|
+
<button onClick={() => setNumber(Math.random())}>Update number</button>
|
|
10
10
|
<div>Number: {getNumber()}</div>
|
|
11
11
|
</div>;
|
|
12
12
|
}
|
package/lib/Nesquick.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Nesquick = void 0;
|
|
3
|
+
exports.JSX = exports.Nesquick = void 0;
|
|
4
4
|
var Nesquick;
|
|
5
5
|
(function (Nesquick) {
|
|
6
6
|
function render(component, parent) {
|
|
@@ -14,3 +14,6 @@ var Nesquick;
|
|
|
14
14
|
Nesquick.render = render;
|
|
15
15
|
})(Nesquick || (exports.Nesquick = Nesquick = {}));
|
|
16
16
|
exports.default = Nesquick;
|
|
17
|
+
var JSX;
|
|
18
|
+
(function (JSX) {
|
|
19
|
+
})(JSX || (exports.JSX = JSX = {}));
|
package/lib/NesquickComponent.js
CHANGED
|
@@ -215,9 +215,17 @@ class NesquickComponent {
|
|
|
215
215
|
this._renderChild(document, parent, this._pushChild(), child);
|
|
216
216
|
}
|
|
217
217
|
else if (typeof child === "function") {
|
|
218
|
-
|
|
219
|
-
(0, State_1.useRender)(child, children => {
|
|
220
|
-
|
|
218
|
+
let ch = null;
|
|
219
|
+
(0, State_1.useRender)(child, (children, lastReaction) => {
|
|
220
|
+
if (lastReaction && ch == null && Array.isArray(children)) {
|
|
221
|
+
this._renderChildren(document, parent, children);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
if (ch == null) {
|
|
225
|
+
ch = this._pushChild();
|
|
226
|
+
}
|
|
227
|
+
this._renderChild(document, parent, ch, children);
|
|
228
|
+
}
|
|
221
229
|
});
|
|
222
230
|
}
|
|
223
231
|
else {
|
package/lib/index.js
CHANGED
|
@@ -16,9 +16,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./Nesquick"), exports);
|
|
18
18
|
__exportStar(require("./For/For"), exports);
|
|
19
|
-
__exportStar(require("./cli/transformer"), exports);
|
|
20
19
|
__exportStar(require("./State"), exports);
|
|
21
20
|
__exportStar(require("./NesquickFragment"), exports);
|
|
22
21
|
__exportStar(require("./NesquickComponent"), exports);
|
|
23
|
-
__exportStar(require("./jsx-runtime"), exports);
|
|
24
|
-
__exportStar(require("./plugins/viteTransformerPlugin"), exports);
|
package/lib/jsx-runtime.js
CHANGED
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.jsx = 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
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const Fragment = Symbol();
|
|
9
|
+
function functionizeProps(props) {
|
|
10
|
+
for (const k in props) {
|
|
11
|
+
if (typeof props[k] !== "function") {
|
|
12
|
+
const v = props[k];
|
|
13
|
+
props[k] = () => v;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
10
17
|
function jsxs(type, props, key) {
|
|
11
|
-
if (type ===
|
|
18
|
+
if (type === Fragment) {
|
|
12
19
|
return new NesquickFragment_1.NesquickFragment(props.children);
|
|
13
20
|
}
|
|
14
|
-
if (
|
|
15
|
-
|
|
21
|
+
if (typeof type !== "string") {
|
|
22
|
+
functionizeProps(props);
|
|
16
23
|
}
|
|
17
|
-
if (key !== undefined) {
|
|
24
|
+
else if (key !== undefined) {
|
|
18
25
|
props.key = key;
|
|
19
26
|
}
|
|
20
27
|
return new NesquickComponent_1.NesquickComponent(type, props);
|
|
21
28
|
}
|
|
22
29
|
exports.jsx = jsxs;
|
|
23
|
-
var JSX;
|
|
24
|
-
(function (JSX) {
|
|
25
|
-
})(JSX || (exports.JSX = JSX = {}));
|
package/lib/types/For/For.d.ts
CHANGED
package/lib/types/Nesquick.d.ts
CHANGED
|
@@ -4,3 +4,67 @@ export declare namespace Nesquick {
|
|
|
4
4
|
}
|
|
5
5
|
export { Children, Child };
|
|
6
6
|
export default Nesquick;
|
|
7
|
+
type HasUndefined<T, K extends keyof T> = {
|
|
8
|
+
[L in K]-?: T[K] | undefined;
|
|
9
|
+
} extends {
|
|
10
|
+
[L in K]?: T[K];
|
|
11
|
+
} ? undefined extends T[K] ? true : false : false;
|
|
12
|
+
declare const WrappedFunctionType: unique symbol;
|
|
13
|
+
type WrappedFunction<T> = (() => T) & {
|
|
14
|
+
readonly [WrappedFunctionType]?: T;
|
|
15
|
+
};
|
|
16
|
+
type UserProp<T> = T extends (...args: any[]) => any ? T : WrappedFunction<T>;
|
|
17
|
+
type UserProps<T> = {
|
|
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>>;
|
|
19
|
+
};
|
|
20
|
+
type JSXProp<T> = T extends {
|
|
21
|
+
readonly [WrappedFunctionType]?: infer R;
|
|
22
|
+
} ? R : T;
|
|
23
|
+
type JSXProps<T> = keyof T extends never ? {} : {
|
|
24
|
+
[K in keyof T]: JSXProp<T[K]>;
|
|
25
|
+
};
|
|
26
|
+
export type Generic<T> = T extends (...args: any) => infer R ? R : T;
|
|
27
|
+
export { UserProps as Props };
|
|
28
|
+
export type Component<P = {}> = (props: UserProps<P>) => JSX.Element;
|
|
29
|
+
export declare namespace JSX {
|
|
30
|
+
export type JSXEvent<T extends Event, T2 extends EventTarget> = T & {
|
|
31
|
+
currentTarget: T2;
|
|
32
|
+
};
|
|
33
|
+
export type JSXHTMLEvent<T extends EventTarget> = {
|
|
34
|
+
[K in keyof HTMLElementEventMap as `on${Capitalize<K>}`]?: (e: JSXEvent<HTMLElementEventMap[K], T>) => void;
|
|
35
|
+
};
|
|
36
|
+
export type JSXSVGEvent<T extends EventTarget> = {
|
|
37
|
+
[K in keyof SVGElementEventMap as `on${Capitalize<K>}`]?: (e: JSXEvent<SVGElementEventMap[K], T>) => void;
|
|
38
|
+
};
|
|
39
|
+
export interface Props<T extends EventTarget = HTMLElement> extends JSXHTMLEvent<T>, JSXSVGEvent<T> {
|
|
40
|
+
[k: string]: any;
|
|
41
|
+
style?: Style;
|
|
42
|
+
xmlns?: string | null;
|
|
43
|
+
ref?: ((el: T) => void) | null;
|
|
44
|
+
}
|
|
45
|
+
export type Style = StyleProps | string;
|
|
46
|
+
export type StyleProps = {
|
|
47
|
+
[K in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[K] extends Function ? never : CSSStyleDeclaration[K] | (() => CSSStyleDeclaration[K]);
|
|
48
|
+
};
|
|
49
|
+
export type HTMLProps<T extends HTMLElement = HTMLElement> = Props<T>;
|
|
50
|
+
export type SVGProps<T extends SVGElement = SVGElement> = Props<T>;
|
|
51
|
+
export type IntrinsicElements = {
|
|
52
|
+
[K in keyof HTMLElementTagNameMap]: HTMLProps<HTMLElementTagNameMap[K]>;
|
|
53
|
+
} & {
|
|
54
|
+
[K in keyof SVGElementTagNameMap]: SVGProps<SVGElementTagNameMap[K]>;
|
|
55
|
+
};
|
|
56
|
+
export type Element = NesquickComponent<any>;
|
|
57
|
+
export type ElementType = keyof IntrinsicElements | Component<any> | typeof NesquickComponent<any>;
|
|
58
|
+
const NotEmptyObject: unique symbol;
|
|
59
|
+
export type IntrinsicAttributes = {
|
|
60
|
+
[NotEmptyObject]?: typeof NotEmptyObject;
|
|
61
|
+
};
|
|
62
|
+
export interface ElementAttributesProperty {
|
|
63
|
+
props: {};
|
|
64
|
+
}
|
|
65
|
+
export interface ElementChildrenAttribute {
|
|
66
|
+
children: {};
|
|
67
|
+
}
|
|
68
|
+
export type LibraryManagedAttributes<_, P> = JSXProps<P>;
|
|
69
|
+
export {};
|
|
70
|
+
}
|
package/lib/types/State.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export type Getter<T> = () => T;
|
|
2
2
|
export type Setter<T> = (value: T) => void;
|
|
3
|
-
export type
|
|
4
|
-
export type State<T> = [get: Getter<T>, set: Setter<T>,
|
|
3
|
+
export type Updater<T> = (cb: (value: T) => T) => void;
|
|
4
|
+
export type State<T> = [get: Getter<T>, set: Setter<T>, update: Updater<T>];
|
|
5
5
|
type Subscription<T> = {
|
|
6
6
|
cb: () => T;
|
|
7
7
|
iteration: number;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
export * from "./Nesquick";
|
|
2
2
|
export * from "./For/For";
|
|
3
|
-
export * from "./cli/transformer";
|
|
4
3
|
export * from "./State";
|
|
5
4
|
export * from "./NesquickFragment";
|
|
6
5
|
export * from "./NesquickComponent";
|
|
7
|
-
export * from "./jsx-runtime";
|
|
8
|
-
export * from "./plugins/viteTransformerPlugin";
|
|
@@ -1,72 +1,7 @@
|
|
|
1
1
|
import { FunctionComponent, ComponentProps, NesquickComponent } from "./NesquickComponent";
|
|
2
2
|
import { NesquickFragment } from "./NesquickFragment";
|
|
3
|
-
declare const
|
|
4
|
-
export declare
|
|
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>;
|
|
3
|
+
declare const Fragment: unique symbol;
|
|
4
|
+
export declare function functionizeProps(props: ComponentProps): void;
|
|
5
|
+
export declare function jsxs<P extends ComponentProps>(type: string | FunctionComponent<P> | typeof Fragment, props: P, key?: string | number | null): NesquickFragment | NesquickComponent<P>;
|
|
8
6
|
export declare const jsx: typeof jsxs;
|
|
9
|
-
type
|
|
10
|
-
[L in K]-?: T[K] | undefined;
|
|
11
|
-
} extends {
|
|
12
|
-
[L in K]?: T[K];
|
|
13
|
-
} ? undefined extends T[K] ? true : false : false;
|
|
14
|
-
declare const WrappedFunctionType: unique symbol;
|
|
15
|
-
type WrappedFunction<T> = (() => T) & {
|
|
16
|
-
readonly [WrappedFunctionType]?: T;
|
|
17
|
-
};
|
|
18
|
-
type UserProp<T> = T extends (...args: any[]) => any ? T : WrappedFunction<T>;
|
|
19
|
-
type UserProps<T> = {
|
|
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>>;
|
|
21
|
-
};
|
|
22
|
-
type JSXProp<T> = T extends {
|
|
23
|
-
readonly [WrappedFunctionType]?: infer R;
|
|
24
|
-
} ? R : T;
|
|
25
|
-
type JSXProps<T> = keyof T extends never ? {} : {
|
|
26
|
-
[K in keyof T]: JSXProp<T[K]>;
|
|
27
|
-
};
|
|
28
|
-
export type Generic<T> = T extends (...args: any) => infer R ? R : T;
|
|
29
|
-
export { UserProps as Props };
|
|
30
|
-
export type Component<P = {}> = (props: UserProps<P>) => JSX.Element;
|
|
31
|
-
export declare namespace JSX {
|
|
32
|
-
export type JSXEvent<T extends Event, T2 extends EventTarget> = T & {
|
|
33
|
-
currentTarget: T2;
|
|
34
|
-
};
|
|
35
|
-
export type JSXHTMLEvent<T extends EventTarget> = {
|
|
36
|
-
[K in keyof HTMLElementEventMap as `on${Capitalize<K>}`]?: (e: JSXEvent<HTMLElementEventMap[K], T>) => void;
|
|
37
|
-
};
|
|
38
|
-
export type JSXSVGEvent<T extends EventTarget> = {
|
|
39
|
-
[K in keyof SVGElementEventMap as `on${Capitalize<K>}`]?: (e: JSXEvent<SVGElementEventMap[K], T>) => void;
|
|
40
|
-
};
|
|
41
|
-
export interface Props<T extends EventTarget = HTMLElement> extends JSXHTMLEvent<T>, JSXSVGEvent<T> {
|
|
42
|
-
[k: string]: any;
|
|
43
|
-
style?: Style;
|
|
44
|
-
xmlns?: string | null;
|
|
45
|
-
ref?: ((el: T) => void) | null;
|
|
46
|
-
}
|
|
47
|
-
export type Style = StyleProps | string;
|
|
48
|
-
export type StyleProps = {
|
|
49
|
-
[K in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[K] extends Function ? never : CSSStyleDeclaration[K] | (() => CSSStyleDeclaration[K]);
|
|
50
|
-
};
|
|
51
|
-
export type HTMLProps<T extends HTMLElement = HTMLElement> = Props<T>;
|
|
52
|
-
export type SVGProps<T extends SVGElement = SVGElement> = Props<T>;
|
|
53
|
-
export type IntrinsicElements = {
|
|
54
|
-
[K in keyof HTMLElementTagNameMap]: HTMLProps<HTMLElementTagNameMap[K]>;
|
|
55
|
-
} & {
|
|
56
|
-
[K in keyof SVGElementTagNameMap]: SVGProps<SVGElementTagNameMap[K]>;
|
|
57
|
-
};
|
|
58
|
-
export type Element = NesquickComponent<any>;
|
|
59
|
-
export type ElementType = keyof IntrinsicElements | Component<any> | typeof NesquickComponent<any>;
|
|
60
|
-
const NotEmptyObject: unique symbol;
|
|
61
|
-
export type IntrinsicAttributes = {
|
|
62
|
-
[NotEmptyObject]?: typeof NotEmptyObject;
|
|
63
|
-
};
|
|
64
|
-
export interface ElementAttributesProperty {
|
|
65
|
-
props: {};
|
|
66
|
-
}
|
|
67
|
-
export interface ElementChildrenAttribute {
|
|
68
|
-
children: {};
|
|
69
|
-
}
|
|
70
|
-
export type LibraryManagedAttributes<_, P> = JSXProps<P>;
|
|
71
|
-
export {};
|
|
72
|
-
}
|
|
7
|
+
export type { Fragment };
|
package/package.json
CHANGED
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nesquick",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "React-like library with focus on drawing performance",
|
|
5
5
|
"types": "./lib/types",
|
|
6
6
|
"main": "./lib",
|
|
7
7
|
"typesVersions": {
|
|
8
8
|
"*": {
|
|
9
9
|
"jsx-runtime": ["./lib/types/jsx-runtime.d.ts"],
|
|
10
|
-
"jsx-dev-runtime": ["./lib/types/jsx-dev-runtime.d.ts"]
|
|
11
|
-
"no-transformer/jsx-runtime": ["./lib/types/no-transformer/jsx-runtime.d.ts"],
|
|
12
|
-
"no-transformer/jsx-dev-runtime": ["./lib/types/no-transformer/jsx-dev-runtime.d.ts"]
|
|
10
|
+
"jsx-dev-runtime": ["./lib/types/jsx-dev-runtime.d.ts"]
|
|
13
11
|
}
|
|
14
12
|
},
|
|
15
|
-
"bin": {
|
|
16
|
-
"nesquick-tsc": "lib/cli/nesquick-tsc.js",
|
|
17
|
-
"ntsc": "lib/cli/nesquick-tsc.js"
|
|
18
|
-
},
|
|
19
13
|
"sideEffects": false,
|
|
20
14
|
"files": [
|
|
21
15
|
"lib/",
|
package/lib/cli/nesquick-tsc.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const tsc_1 = require("./tsc");
|
|
5
|
-
const transformer_1 = require("./transformer");
|
|
6
|
-
(0, tsc_1.tsc)({
|
|
7
|
-
argv: process.argv,
|
|
8
|
-
cwd: process.cwd(),
|
|
9
|
-
transformers: {
|
|
10
|
-
before: [transformer_1.transformer]
|
|
11
|
-
}
|
|
12
|
-
});
|
package/lib/cli/processArgv.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getProject = getProject;
|
|
4
|
-
const Path = require("path");
|
|
5
|
-
function getProject(argv) {
|
|
6
|
-
let nextIsProject = false;
|
|
7
|
-
for (let i = 0; i < argv.length; i++) {
|
|
8
|
-
if (argv[i].startsWith("--")) {
|
|
9
|
-
nextIsProject = argv[i].substring(2) === "project";
|
|
10
|
-
}
|
|
11
|
-
else if (argv[i].startsWith("-")) {
|
|
12
|
-
nextIsProject = argv[i].substring(1) === "p";
|
|
13
|
-
}
|
|
14
|
-
else if (nextIsProject) {
|
|
15
|
-
return Path.resolve(process.cwd(), argv[i]);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return null;
|
|
19
|
-
}
|
package/lib/cli/transformer.js
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.transformer = void 0;
|
|
4
|
-
const TS = require("typescript");
|
|
5
|
-
function getSingleIdentifier(node) {
|
|
6
|
-
const identifiers = [];
|
|
7
|
-
node.forEachChild(node => {
|
|
8
|
-
if (TS.isIdentifier(node)) {
|
|
9
|
-
identifiers.push(node);
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
if (identifiers.length === 1) {
|
|
13
|
-
return identifiers[0];
|
|
14
|
-
}
|
|
15
|
-
return null;
|
|
16
|
-
}
|
|
17
|
-
function getSingleBody(node) {
|
|
18
|
-
const body = [];
|
|
19
|
-
node.forEachChild(node => {
|
|
20
|
-
body.push(node);
|
|
21
|
-
});
|
|
22
|
-
if (body.length === 1) {
|
|
23
|
-
return body[0];
|
|
24
|
-
}
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
const transformer = context => {
|
|
28
|
-
return sourceFile => {
|
|
29
|
-
const visitGeneric = (node, options) => {
|
|
30
|
-
let hasSpread = options.userComponent && TS.isJsxSpreadAttribute(node);
|
|
31
|
-
let hasChildIdentifier = false;
|
|
32
|
-
if (TS.isJsxOpeningLikeElement(node)) {
|
|
33
|
-
const firstLetter = node.tagName.getText()[0];
|
|
34
|
-
const userComponent = firstLetter !== firstLetter.toLowerCase();
|
|
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
|
-
}
|
|
58
|
-
}
|
|
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);
|
|
66
|
-
}
|
|
67
|
-
else if (TS.isJsxExpression(node)) {
|
|
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);
|
|
73
|
-
}
|
|
74
|
-
else if (options.isJsxAttribute && TS.isStringLiteral(node)) {
|
|
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;
|
|
82
|
-
}
|
|
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);
|
|
94
|
-
}
|
|
95
|
-
return { hasSpread, hasChildIdentifier, node };
|
|
96
|
-
};
|
|
97
|
-
const visitorExpression = (node, options) => {
|
|
98
|
-
let hasChildIdentifier = false;
|
|
99
|
-
if (TS.isParenthesizedExpression(node)) {
|
|
100
|
-
const body = getSingleBody(node);
|
|
101
|
-
if (body) {
|
|
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
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
else if (TS.isCallExpression(node)) {
|
|
110
|
-
const identifier = getSingleIdentifier(node);
|
|
111
|
-
if (identifier) {
|
|
112
|
-
node = identifier;
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
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);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
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
|
-
});
|
|
138
|
-
}
|
|
139
|
-
return { hasChildIdentifier, node };
|
|
140
|
-
};
|
|
141
|
-
return TS.visitNode(sourceFile, node => visitGeneric(node, {}).node, TS.isSourceFile);
|
|
142
|
-
};
|
|
143
|
-
};
|
|
144
|
-
exports.transformer = transformer;
|
package/lib/cli/tsc.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.tsc = tsc;
|
|
4
|
-
const TS = require("typescript");
|
|
5
|
-
const processArgv_1 = require("./processArgv");
|
|
6
|
-
function tsc(options) {
|
|
7
|
-
const oldDir = process.cwd();
|
|
8
|
-
try {
|
|
9
|
-
if (options.cwd !== oldDir) {
|
|
10
|
-
process.chdir(options.cwd);
|
|
11
|
-
}
|
|
12
|
-
let project = (0, processArgv_1.getProject)(options.argv);
|
|
13
|
-
if (project == null) {
|
|
14
|
-
const configPath = TS.findConfigFile(options.cwd, TS.sys.fileExists, "tsconfig.json");
|
|
15
|
-
if (configPath != null) {
|
|
16
|
-
project = configPath;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
if (!project) {
|
|
20
|
-
throw new Error("tsconfig.json not found");
|
|
21
|
-
}
|
|
22
|
-
const res = TS.readConfigFile(project, TS.sys.readFile);
|
|
23
|
-
const formatHost = {
|
|
24
|
-
getCanonicalFileName: f => f,
|
|
25
|
-
getCurrentDirectory: TS.sys.getCurrentDirectory,
|
|
26
|
-
getNewLine: () => TS.sys.newLine,
|
|
27
|
-
};
|
|
28
|
-
if (res.error) {
|
|
29
|
-
console.error(TS.formatDiagnosticsWithColorAndContext([res.error], formatHost));
|
|
30
|
-
throw new Error(`Error reading ${project}`);
|
|
31
|
-
}
|
|
32
|
-
else if (res.config == null) {
|
|
33
|
-
throw new Error(`Error reading ${project}`);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
const jsonConfig = TS.parseJsonConfigFileContent(res.config, TS.sys, options.cwd, {}, project);
|
|
37
|
-
const program = TS.createProgram({
|
|
38
|
-
options: jsonConfig.options,
|
|
39
|
-
rootNames: jsonConfig.fileNames,
|
|
40
|
-
configFileParsingDiagnostics: jsonConfig.errors
|
|
41
|
-
});
|
|
42
|
-
const preDiagnostics = TS.getPreEmitDiagnostics(program);
|
|
43
|
-
const programEmit = program.emit(void 0, void 0, void 0, void 0, options.transformers);
|
|
44
|
-
const allDiagnostics = [...preDiagnostics, ...programEmit.diagnostics, ...jsonConfig.errors];
|
|
45
|
-
if (allDiagnostics.length) {
|
|
46
|
-
console.error(TS.formatDiagnosticsWithColorAndContext(allDiagnostics, formatHost));
|
|
47
|
-
throw new Error(`Error compiling project`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
finally {
|
|
52
|
-
if (options.cwd !== oldDir) {
|
|
53
|
-
process.chdir(oldDir);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.jsxDEV = jsxDEV;
|
|
18
|
-
const jsx_runtime_1 = require("./jsx-runtime");
|
|
19
|
-
__exportStar(require("./jsx-runtime"), exports);
|
|
20
|
-
function jsxDEV(type, props, key, _isStaticChildren, _source, _self) {
|
|
21
|
-
return (0, jsx_runtime_1.jsx)(type, props, key);
|
|
22
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.JSX = exports.jsx = exports.Fragment = void 0;
|
|
4
|
-
exports.functionizeProps = functionizeProps;
|
|
5
|
-
exports.jsxs = jsxs;
|
|
6
|
-
const NesquickComponent_1 = require("../NesquickComponent");
|
|
7
|
-
const NesquickFragment_1 = require("../NesquickFragment");
|
|
8
|
-
exports.Fragment = Symbol();
|
|
9
|
-
function functionizeProps(props) {
|
|
10
|
-
for (const k in props) {
|
|
11
|
-
if (k !== "children" && typeof props[k] !== "function") {
|
|
12
|
-
const v = props[k];
|
|
13
|
-
props[k] = () => v;
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
function jsxs(type, props, key) {
|
|
18
|
-
if (type === exports.Fragment) {
|
|
19
|
-
return new NesquickFragment_1.NesquickFragment(props.children);
|
|
20
|
-
}
|
|
21
|
-
if (typeof type !== "string") {
|
|
22
|
-
functionizeProps(props);
|
|
23
|
-
}
|
|
24
|
-
else if (key !== undefined) {
|
|
25
|
-
props.key = key;
|
|
26
|
-
}
|
|
27
|
-
return new NesquickComponent_1.NesquickComponent(type, props);
|
|
28
|
-
}
|
|
29
|
-
exports.jsx = jsxs;
|
|
30
|
-
var JSX;
|
|
31
|
-
(function (JSX) {
|
|
32
|
-
})(JSX || (exports.JSX = JSX = {}));
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.viteTransformerPlugin = void 0;
|
|
4
|
-
const TS = require("typescript");
|
|
5
|
-
const transformer_1 = require("../cli/transformer");
|
|
6
|
-
exports.viteTransformerPlugin = {
|
|
7
|
-
name: "nesquick-transformer",
|
|
8
|
-
enforce: "pre",
|
|
9
|
-
transform(code, id) {
|
|
10
|
-
if (id.endsWith(".ts") || id.endsWith(".tsx")) {
|
|
11
|
-
const result = TS.transpileModule(code, {
|
|
12
|
-
compilerOptions: {
|
|
13
|
-
target: TS.ScriptTarget.ESNext,
|
|
14
|
-
module: TS.ModuleKind.ESNext,
|
|
15
|
-
jsx: TS.JsxEmit.Preserve,
|
|
16
|
-
},
|
|
17
|
-
transformers: {
|
|
18
|
-
before: [transformer_1.transformer],
|
|
19
|
-
},
|
|
20
|
-
fileName: id
|
|
21
|
-
});
|
|
22
|
-
return {
|
|
23
|
-
code: result.outputText,
|
|
24
|
-
map: result.sourceMapText ? JSON.parse(result.sourceMapText) : null
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function getProject(argv: string[]): string | null;
|
package/lib/types/cli/tsc.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Fragment } from "./jsx-runtime";
|
|
2
|
-
import { FunctionComponent, ComponentProps } from "../NesquickComponent";
|
|
3
|
-
export * from "./jsx-runtime";
|
|
4
|
-
type JsxSource = {
|
|
5
|
-
fileName: string;
|
|
6
|
-
lineNumber: number;
|
|
7
|
-
columnNumber?: number;
|
|
8
|
-
};
|
|
9
|
-
export declare function jsxDEV<P extends ComponentProps>(type: string | FunctionComponent<P> | typeof Fragment, props: P, key: string | number | null, _isStaticChildren: boolean, _source: JsxSource, _self: any): import("..").NesquickFragment | import("../NesquickComponent").NesquickComponent<P>;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { FunctionComponent, ComponentProps, NesquickComponent } from "../NesquickComponent";
|
|
2
|
-
import { NesquickFragment } from "../NesquickFragment";
|
|
3
|
-
export declare const Fragment: unique symbol;
|
|
4
|
-
export declare function functionizeProps(props: ComponentProps): void;
|
|
5
|
-
export declare function jsxs<P extends ComponentProps>(type: string | FunctionComponent<P> | typeof Fragment, props: P, key?: string | number | null): NesquickFragment | NesquickComponent<P>;
|
|
6
|
-
export declare const jsx: typeof jsxs;
|
|
7
|
-
type HasUndefined<T, K extends keyof T> = {
|
|
8
|
-
[L in K]-?: T[K] | undefined;
|
|
9
|
-
} extends {
|
|
10
|
-
[L in K]?: T[K];
|
|
11
|
-
} ? undefined extends T[K] ? true : false : false;
|
|
12
|
-
declare const WrappedFunctionType: unique symbol;
|
|
13
|
-
type WrappedFunction<T> = (() => T) & {
|
|
14
|
-
readonly [WrappedFunctionType]?: T;
|
|
15
|
-
};
|
|
16
|
-
type UserProp<T> = T extends (...args: infer A) => infer R ? (((...args: A) => R) | T) : WrappedFunction<T>;
|
|
17
|
-
type UserProps<T> = {
|
|
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>>;
|
|
19
|
-
};
|
|
20
|
-
type JSXProp<T> = T extends {
|
|
21
|
-
readonly [WrappedFunctionType]?: infer R;
|
|
22
|
-
} ? (T | R) : T extends (...args: any[]) => any ? T : (T | (() => T));
|
|
23
|
-
type JSXProps<T> = keyof T extends never ? {} : {
|
|
24
|
-
[K in keyof T]: JSXProp<T[K]>;
|
|
25
|
-
};
|
|
26
|
-
export type Generic<T> = T extends (...args: any) => infer R ? R : T;
|
|
27
|
-
export { UserProps as Props };
|
|
28
|
-
export type Component<P = {}> = (props: UserProps<P>) => JSX.Element;
|
|
29
|
-
export declare namespace JSX {
|
|
30
|
-
export type JSXEvent<T extends Event, T2 extends EventTarget> = T & {
|
|
31
|
-
currentTarget: T2;
|
|
32
|
-
};
|
|
33
|
-
export type JSXHTMLEvent<T extends EventTarget> = {
|
|
34
|
-
[K in keyof HTMLElementEventMap as `on${Capitalize<K>}`]?: (e: JSXEvent<HTMLElementEventMap[K], T>) => void;
|
|
35
|
-
};
|
|
36
|
-
export type JSXSVGEvent<T extends EventTarget> = {
|
|
37
|
-
[K in keyof SVGElementEventMap as `on${Capitalize<K>}`]?: (e: JSXEvent<SVGElementEventMap[K], T>) => void;
|
|
38
|
-
};
|
|
39
|
-
export interface Props<T extends EventTarget = HTMLElement> extends JSXHTMLEvent<T>, JSXSVGEvent<T> {
|
|
40
|
-
[k: string]: any;
|
|
41
|
-
style?: Style;
|
|
42
|
-
xmlns?: string | null;
|
|
43
|
-
ref?: ((el: T) => void) | null;
|
|
44
|
-
}
|
|
45
|
-
export type Style = StyleProps | string;
|
|
46
|
-
export type StyleProps = {
|
|
47
|
-
[K in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[K] extends Function ? never : CSSStyleDeclaration[K] | (() => CSSStyleDeclaration[K]);
|
|
48
|
-
};
|
|
49
|
-
export type HTMLProps<T extends HTMLElement = HTMLElement> = Props<T>;
|
|
50
|
-
export type SVGProps<T extends SVGElement = SVGElement> = Props<T>;
|
|
51
|
-
export type JSXElements = {
|
|
52
|
-
[K in keyof HTMLElementTagNameMap]: HTMLProps<HTMLElementTagNameMap[K]>;
|
|
53
|
-
} & {
|
|
54
|
-
[K in keyof SVGElementTagNameMap]: SVGProps<SVGElementTagNameMap[K]>;
|
|
55
|
-
};
|
|
56
|
-
export type Element = NesquickComponent<any>;
|
|
57
|
-
export interface IntrinsicElements extends JSXElements {
|
|
58
|
-
}
|
|
59
|
-
export type ElementType = keyof IntrinsicElements | Component<any> | typeof NesquickComponent<any>;
|
|
60
|
-
const NotEmptyObject: unique symbol;
|
|
61
|
-
export type IntrinsicAttributes = {
|
|
62
|
-
[NotEmptyObject]?: typeof NotEmptyObject;
|
|
63
|
-
};
|
|
64
|
-
export interface ElementAttributesProperty {
|
|
65
|
-
props: {};
|
|
66
|
-
}
|
|
67
|
-
export interface ElementChildrenAttribute {
|
|
68
|
-
children: {};
|
|
69
|
-
}
|
|
70
|
-
export type LibraryManagedAttributes<_, P> = JSXProps<P>;
|
|
71
|
-
export {};
|
|
72
|
-
}
|