nesquick 0.0.21 → 0.0.23

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.
@@ -2,14 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NesquickComponent = void 0;
4
4
  const State_1 = require("./State");
5
- function functionizeProps(props) {
6
- for (const k in props) {
7
- if (typeof props[k] !== "function") {
8
- const v = props[k];
9
- props[k] = () => v;
10
- }
11
- }
12
- }
13
5
  const SVGNamespaces = new Map([
14
6
  ["xlink", "http://www.w3.org/1999/xlink"],
15
7
  ["xml", "http://www.w3.org/XML/1998/namespace"]
@@ -27,7 +19,6 @@ class NesquickComponent {
27
19
  render(document) {
28
20
  State_1.subscriptions.set(this._subscriptions);
29
21
  if (typeof this._render === "function") {
30
- functionizeProps(this.props);
31
22
  const element = this._render(this.props);
32
23
  if (this._xmlns) {
33
24
  element.setXmlns(this._xmlns);
@@ -0,0 +1,12 @@
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
+ });
@@ -0,0 +1,19 @@
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
+ }
@@ -35,7 +35,12 @@ function hasIdentifier(node) {
35
35
  }
36
36
  const transformer = context => {
37
37
  return sourceFile => {
38
+ let isComponent = false;
38
39
  const visitorGeneric = node => {
40
+ if (TS.isJsxOpeningElement(node)) {
41
+ const firstLetter = node.tagName.getText()[0];
42
+ isComponent = firstLetter !== firstLetter.toLowerCase();
43
+ }
39
44
  if (TS.isJsxExpression(node)) {
40
45
  return TS.visitEachChild(node, visitorExpression, context);
41
46
  }
@@ -57,7 +62,7 @@ const transformer = context => {
57
62
  return TS.factory.createArrowFunction(undefined, undefined, [], undefined, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), node);
58
63
  }
59
64
  }
60
- else if (!TS.isFunctionLike(node) && TS.isExpression(node) && hasIdentifier(node)) {
65
+ else if (!TS.isFunctionLike(node) && TS.isExpression(node) && (isComponent || hasIdentifier(node))) {
61
66
  return TS.factory.createArrowFunction(undefined, undefined, [], undefined, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), node);
62
67
  }
63
68
  return node;
package/lib/cli/tsc.js ADDED
@@ -0,0 +1,56 @@
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
+ }
@@ -0,0 +1,22 @@
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
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JSX = exports.jsx = exports.Fragment = void 0;
4
+ exports.jsxs = jsxs;
5
+ const NesquickComponent_1 = require("../NesquickComponent");
6
+ const NesquickFragment_1 = require("../NesquickFragment");
7
+ exports.Fragment = Symbol();
8
+ function functionizeProps(props) {
9
+ for (const k in props) {
10
+ if (typeof props[k] !== "function") {
11
+ const v = props[k];
12
+ props[k] = () => v;
13
+ }
14
+ }
15
+ }
16
+ function jsxs(type, props, key) {
17
+ if (type === exports.Fragment) {
18
+ return new NesquickFragment_1.NesquickFragment(props.children);
19
+ }
20
+ if (typeof type !== "string") {
21
+ functionizeProps(props);
22
+ }
23
+ else if (key !== undefined) {
24
+ props.key = key;
25
+ }
26
+ return new NesquickComponent_1.NesquickComponent(type, props);
27
+ }
28
+ exports.jsx = jsxs;
29
+ var JSX;
30
+ (function (JSX) {
31
+ })(JSX || (exports.JSX = JSX = {}));
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1 @@
1
+ export declare function getProject(argv: string[]): string | null;
@@ -0,0 +1,7 @@
1
+ import * as TS from "typescript";
2
+ export type CompileOptions = {
3
+ argv: string[];
4
+ cwd: string;
5
+ transformers?: TS.CustomTransformers;
6
+ };
7
+ export declare function tsc(options: CompileOptions): void;
@@ -3,19 +3,24 @@ 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
5
  export declare const jsx: typeof jsxs;
6
+ type HasUndefined<T, K extends keyof T> = {
7
+ [L in K]-?: T[K] | undefined;
8
+ } extends {
9
+ [L in K]?: T[K];
10
+ } ? undefined extends T[K] ? true : false : false;
6
11
  declare const WrappedFunctionType: unique symbol;
7
12
  type WrappedFunction<T> = (() => T) & {
8
13
  readonly [WrappedFunctionType]?: T;
9
14
  };
10
- type UserProp<T> = T extends (...args: infer A) => infer R ? (((...args: A) => R) | T) : WrappedFunction<T>;
11
- type ComponentProp<T> = T extends {
12
- readonly [WrappedFunctionType]?: infer R;
13
- } ? (T | R) : T extends (...args: any[]) => any ? T : (T | (() => T));
15
+ type UserProp<T> = T extends (...args: any[]) => any ? T : WrappedFunction<T>;
14
16
  type UserProps<T> = {
15
- [K in keyof T]: UserProp<T[K]>;
17
+ readonly [K in keyof T]: HasUndefined<T, K> extends true ? UserProp<T[K] | undefined> : UserProp<Exclude<T[K], undefined>>;
16
18
  };
19
+ type JSXProp<T> = T extends {
20
+ readonly [WrappedFunctionType]?: infer R;
21
+ } ? R : T;
17
22
  type JSXProps<T> = keyof T extends never ? {} : {
18
- [K in keyof T]: ComponentProp<T[K]>;
23
+ [K in keyof T]: JSXProp<T[K]>;
19
24
  };
20
25
  export type Generic<T> = T extends (...args: any) => infer R ? R : T;
21
26
  export { UserProps as Props };
@@ -32,23 +37,22 @@ export declare namespace JSX {
32
37
  };
33
38
  export interface Props<T extends EventTarget = HTMLElement> extends JSXHTMLEvent<T>, JSXSVGEvent<T> {
34
39
  [k: string]: any;
35
- style?: StyleProps | string;
40
+ style?: Style;
36
41
  xmlns?: string | null;
37
42
  ref?: ((el: T) => void) | null;
38
43
  }
44
+ export type Style = StyleProps | string;
39
45
  export type StyleProps = {
40
46
  [K in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[K] extends Function ? never : CSSStyleDeclaration[K] | (() => CSSStyleDeclaration[K]);
41
47
  };
42
48
  export type HTMLProps<T extends HTMLElement = HTMLElement> = Props<T>;
43
49
  export type SVGProps<T extends SVGElement = SVGElement> = Props<T>;
44
- export type JSXElements = {
50
+ export type IntrinsicElements = {
45
51
  [K in keyof HTMLElementTagNameMap]: HTMLProps<HTMLElementTagNameMap[K]>;
46
52
  } & {
47
53
  [K in keyof SVGElementTagNameMap]: SVGProps<SVGElementTagNameMap[K]>;
48
54
  };
49
55
  export type Element = NesquickComponent<any>;
50
- export interface IntrinsicElements extends JSXElements {
51
- }
52
56
  export type ElementType = keyof IntrinsicElements | Component<any> | typeof NesquickComponent<any>;
53
57
  const NotEmptyObject: unique symbol;
54
58
  export type IntrinsicAttributes = {
@@ -0,0 +1,9 @@
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>;
@@ -0,0 +1,71 @@
1
+ import { FunctionComponent, ComponentProps, NesquickComponent } from "../NesquickComponent";
2
+ import { NesquickFragment } from "../NesquickFragment";
3
+ export declare const Fragment: unique symbol;
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 const jsx: typeof jsxs;
6
+ type HasUndefined<T, K extends keyof T> = {
7
+ [L in K]-?: T[K] | undefined;
8
+ } extends {
9
+ [L in K]?: T[K];
10
+ } ? undefined extends T[K] ? true : false : false;
11
+ declare const WrappedFunctionType: unique symbol;
12
+ type WrappedFunction<T> = (() => T) & {
13
+ readonly [WrappedFunctionType]?: T;
14
+ };
15
+ type UserProp<T> = T extends (...args: infer A) => infer R ? (((...args: A) => R) | T) : WrappedFunction<T>;
16
+ type UserProps<T> = {
17
+ readonly [K in keyof T]: HasUndefined<T, K> extends true ? UserProp<T[K] | undefined> : UserProp<Exclude<T[K], undefined>>;
18
+ };
19
+ type JSXProp<T> = T extends {
20
+ readonly [WrappedFunctionType]?: infer R;
21
+ } ? (T | R) : T extends (...args: any[]) => any ? T : (T | (() => T));
22
+ type JSXProps<T> = keyof T extends never ? {} : {
23
+ [K in keyof T]: JSXProp<T[K]>;
24
+ };
25
+ export type Generic<T> = T extends (...args: any) => infer R ? R : T;
26
+ export { UserProps as Props };
27
+ export type Component<P = {}> = (props: UserProps<P>) => JSX.Element;
28
+ export declare namespace JSX {
29
+ export type JSXEvent<T extends Event, T2 extends EventTarget> = T & {
30
+ currentTarget: T2;
31
+ };
32
+ export type JSXHTMLEvent<T extends EventTarget> = {
33
+ [K in keyof HTMLElementEventMap as `on${Capitalize<K>}`]?: (e: JSXEvent<HTMLElementEventMap[K], T>) => void;
34
+ };
35
+ export type JSXSVGEvent<T extends EventTarget> = {
36
+ [K in keyof SVGElementEventMap as `on${Capitalize<K>}`]?: (e: JSXEvent<SVGElementEventMap[K], T>) => void;
37
+ };
38
+ export interface Props<T extends EventTarget = HTMLElement> extends JSXHTMLEvent<T>, JSXSVGEvent<T> {
39
+ [k: string]: any;
40
+ style?: Style;
41
+ xmlns?: string | null;
42
+ ref?: ((el: T) => void) | null;
43
+ }
44
+ export type Style = StyleProps | string;
45
+ export type StyleProps = {
46
+ [K in keyof CSSStyleDeclaration]?: CSSStyleDeclaration[K] extends Function ? never : CSSStyleDeclaration[K] | (() => CSSStyleDeclaration[K]);
47
+ };
48
+ export type HTMLProps<T extends HTMLElement = HTMLElement> = Props<T>;
49
+ export type SVGProps<T extends SVGElement = SVGElement> = Props<T>;
50
+ export type JSXElements = {
51
+ [K in keyof HTMLElementTagNameMap]: HTMLProps<HTMLElementTagNameMap[K]>;
52
+ } & {
53
+ [K in keyof SVGElementTagNameMap]: SVGProps<SVGElementTagNameMap[K]>;
54
+ };
55
+ export type Element = NesquickComponent<any>;
56
+ export interface IntrinsicElements extends JSXElements {
57
+ }
58
+ export type ElementType = keyof IntrinsicElements | Component<any> | typeof NesquickComponent<any>;
59
+ const NotEmptyObject: unique symbol;
60
+ export type IntrinsicAttributes = {
61
+ [NotEmptyObject]?: typeof NotEmptyObject;
62
+ };
63
+ export interface ElementAttributesProperty {
64
+ props: {};
65
+ }
66
+ export interface ElementChildrenAttribute {
67
+ children: {};
68
+ }
69
+ export type LibraryManagedAttributes<_, P> = JSXProps<P>;
70
+ export {};
71
+ }
package/package.json CHANGED
@@ -1,13 +1,15 @@
1
1
  {
2
2
  "name": "nesquick",
3
- "version": "0.0.21",
3
+ "version": "0.0.23",
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"]
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"]
11
13
  }
12
14
  },
13
15
  "bin": {
@@ -17,6 +19,7 @@
17
19
  "sideEffects": false,
18
20
  "files": [
19
21
  "lib/",
22
+ "no-transformer/",
20
23
  "jsx-runtime.js",
21
24
  "jsx-dev-runtime.js"
22
25
  ],