nesquick 1.2.0 → 1.4.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/Nesquick.js CHANGED
@@ -1,4 +1,18 @@
1
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
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
17
  exports.Nesquick = void 0;
4
18
  var Nesquick;
@@ -14,3 +28,4 @@ var Nesquick;
14
28
  Nesquick.render = render;
15
29
  })(Nesquick || (exports.Nesquick = Nesquick = {}));
16
30
  exports.default = Nesquick;
31
+ __exportStar(require("./jsx-runtime"), exports);
@@ -6,6 +6,21 @@ const SVGNamespaces = new Map([
6
6
  ["xlink", "http://www.w3.org/1999/xlink"],
7
7
  ["xml", "http://www.w3.org/XML/1998/namespace"]
8
8
  ]);
9
+ function getAttributeNs(attributes, k) {
10
+ const index = k.indexOf(":");
11
+ if (index > -1) {
12
+ const ns = k.substring(0, index);
13
+ const name = k.substring(index + 1);
14
+ const namespace = attributes.get(ns);
15
+ if (namespace != null) {
16
+ return {
17
+ namespace: namespace,
18
+ name: name
19
+ };
20
+ }
21
+ }
22
+ return null;
23
+ }
9
24
  class NesquickComponent {
10
25
  constructor(_render, props) {
11
26
  this._render = _render;
@@ -72,21 +87,6 @@ class NesquickComponent {
72
87
  setXmlns(xmlns) {
73
88
  this._xmlns = xmlns;
74
89
  }
75
- _getAttributeNs(attributes, k) {
76
- const index = k.indexOf(":");
77
- if (index > -1) {
78
- const ns = k.substring(0, index);
79
- const name = k.substring(index + 1);
80
- const namespace = attributes.get(ns);
81
- if (namespace != null) {
82
- return {
83
- namespace: namespace,
84
- name: name
85
- };
86
- }
87
- }
88
- return null;
89
- }
90
90
  _renderPropsNs(attributes, element, props) {
91
91
  for (const k in props) {
92
92
  if (k !== "children" && k !== "xmlns" && k !== "ref") {
@@ -98,7 +98,7 @@ class NesquickComponent {
98
98
  element[k.toLowerCase()] = props[k];
99
99
  }
100
100
  else {
101
- const attribute = this._getAttributeNs(attributes, k);
101
+ const attribute = getAttributeNs(attributes, k);
102
102
  if (attribute) {
103
103
  (0, State_1.useRender)(props[k], v => {
104
104
  element.setAttributeNS(attribute.namespace, attribute.name, String(v));
@@ -112,7 +112,7 @@ class NesquickComponent {
112
112
  }
113
113
  }
114
114
  else {
115
- const attribute = this._getAttributeNs(attributes, k);
115
+ const attribute = getAttributeNs(attributes, k);
116
116
  if (attribute) {
117
117
  element.setAttributeNS(attribute.namespace, attribute.name, String(props[k]));
118
118
  }
@@ -1,41 +1,49 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transformer = void 0;
4
+ exports.createCheckFunction = createCheckFunction;
4
5
  const TS = require("typescript");
5
6
  function getSingleIdentifier(node) {
6
- const identifiers = [];
7
+ let identifier = null;
7
8
  node.forEachChild(node => {
8
9
  if (TS.isIdentifier(node)) {
9
- identifiers.push(node);
10
+ if (identifier != null) {
11
+ return node;
12
+ }
13
+ identifier = node;
10
14
  }
11
15
  });
12
- if (identifiers.length === 1) {
13
- return identifiers[0];
14
- }
15
- return null;
16
+ return identifier;
16
17
  }
17
18
  function getSingleBody(node) {
18
- const body = [];
19
+ let body = null;
19
20
  node.forEachChild(node => {
20
- body.push(node);
21
+ if (body != null) {
22
+ return node;
23
+ }
24
+ body = node;
21
25
  });
22
- if (body.length === 1) {
23
- return body[0];
24
- }
25
- return null;
26
+ return body;
27
+ }
28
+ function createCheckFunction(fName) {
29
+ return TS.factory.createFunctionDeclaration(void 0, void 0, fName, void 0, [TS.factory.createParameterDeclaration(void 0, void 0, TS.factory.createIdentifier("v"))], void 0, TS.factory.createBlock([
30
+ TS.factory.createReturnStatement(TS.factory.createConditionalExpression(TS.factory.createBinaryExpression(TS.factory.createTypeOfExpression(TS.factory.createIdentifier("v")), TS.factory.createToken(TS.SyntaxKind.EqualsEqualsEqualsToken), TS.factory.createStringLiteral("function")), TS.factory.createToken(TS.SyntaxKind.QuestionToken), TS.factory.createIdentifier("v"), TS.factory.createToken(TS.SyntaxKind.ColonToken), TS.factory.createArrowFunction(void 0, void 0, [], void 0, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), TS.factory.createIdentifier("v"))))
31
+ ]));
26
32
  }
27
33
  const transformer = context => {
28
34
  return sourceFile => {
35
+ let hasChecker = false;
36
+ const checkerName = TS.factory.createUniqueName("_check");
29
37
  const visitGeneric = (node, options) => {
30
38
  let hasSpread = options.userComponent && TS.isJsxSpreadAttribute(node);
31
- let hasChildIdentifier = false;
39
+ let hasCallExpression = TS.isCallExpression(node);
32
40
  if (TS.isJsxOpeningLikeElement(node)) {
33
41
  const firstLetter = node.tagName.getText()[0];
34
42
  const userComponent = firstLetter !== firstLetter.toLowerCase();
35
43
  node = TS.visitEachChild(node, node => {
36
44
  const res = visitGeneric(node, { userComponent });
37
45
  hasSpread = hasSpread || res.hasSpread;
38
- hasChildIdentifier = hasChildIdentifier || res.hasChildIdentifier || TS.isIdentifier(node);
46
+ hasCallExpression = hasCallExpression || res.hasCallExpression;
39
47
  return res.node;
40
48
  }, context);
41
49
  if (userComponent && hasSpread) {
@@ -60,85 +68,71 @@ const transformer = context => {
60
68
  node = TS.visitEachChild(node, node => {
61
69
  const res = visitGeneric(node, { ...options, isJsxAttribute: true });
62
70
  hasSpread = hasSpread || res.hasSpread;
63
- hasChildIdentifier = hasChildIdentifier || res.hasChildIdentifier || TS.isIdentifier(node);
71
+ hasCallExpression = hasCallExpression || res.hasCallExpression;
64
72
  return res.node;
65
73
  }, context);
66
74
  }
67
75
  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);
76
+ node = TS.visitEachChild(node, node => visitorExpression(node, { ...options, isJsxAttribute: false }), context);
73
77
  }
74
78
  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);
79
+ const returnNode = TS.visitNode(node, node => visitorExpression(node, { ...options, isJsxAttribute: false }), TS.isExpression);
80
80
  if (TS.isStringLiteral(returnNode)) {
81
81
  node = returnNode;
82
82
  }
83
83
  else {
84
- node = TS.factory.createJsxExpression(undefined, returnNode);
84
+ node = TS.factory.createJsxExpression(void 0, returnNode);
85
85
  }
86
86
  }
87
87
  else {
88
88
  node = TS.visitEachChild(node, node => {
89
89
  const res = visitGeneric(node, { ...options, isJsxAttribute: false });
90
90
  hasSpread = hasSpread || res.hasSpread;
91
- hasChildIdentifier = hasChildIdentifier || res.hasChildIdentifier || TS.isIdentifier(node);
91
+ hasCallExpression = hasCallExpression || res.hasCallExpression;
92
92
  return res.node;
93
93
  }, context);
94
94
  }
95
- return { hasSpread, hasChildIdentifier, node };
95
+ return { hasSpread, hasCallExpression, node };
96
96
  };
97
97
  const visitorExpression = (node, options) => {
98
- let hasChildIdentifier = false;
99
98
  if (TS.isParenthesizedExpression(node)) {
100
99
  const body = getSingleBody(node);
101
100
  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
- });
101
+ node = body;
107
102
  }
108
103
  }
109
- else if (TS.isCallExpression(node)) {
110
- const identifier = getSingleIdentifier(node);
111
- if (identifier) {
104
+ if (TS.isCallExpression(node)) {
105
+ let identifier = null;
106
+ if (node.arguments.length === 0 && (identifier = getSingleIdentifier(node)) != null) {
112
107
  node = identifier;
113
108
  }
114
109
  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);
110
+ node = TS.factory.createArrowFunction(void 0, void 0, [], void 0, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), TS.visitNode(node, node => visitGeneric(node, {}).node, TS.isConciseBody));
130
111
  }
131
112
  }
132
113
  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
- });
114
+ const res = visitGeneric(node, {});
115
+ node = res.node;
116
+ if (TS.isExpression(node) && !TS.isFunctionLike(node) && !TS.isJsxElement(node) && !TS.isJsxOpeningLikeElement(node)) {
117
+ if (res.hasCallExpression) {
118
+ node = TS.factory.createArrowFunction(void 0, void 0, [], void 0, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), TS.visitNode(node, node => visitGeneric(node, {}).node, TS.isConciseBody));
119
+ }
120
+ else if (options.userComponent) {
121
+ hasChecker = true;
122
+ node = TS.factory.createCallExpression(checkerName, void 0, [node]);
123
+ }
124
+ }
138
125
  }
139
- return { hasChildIdentifier, node };
126
+ return node;
140
127
  };
141
- return TS.visitNode(sourceFile, node => visitGeneric(node, {}).node, TS.isSourceFile);
128
+ sourceFile = TS.visitNode(sourceFile, node => visitGeneric(node, {}).node, TS.isSourceFile);
129
+ if (hasChecker) {
130
+ sourceFile = TS.factory.updateSourceFile(sourceFile, [
131
+ ...sourceFile.statements,
132
+ createCheckFunction(checkerName)
133
+ ]);
134
+ }
135
+ return sourceFile;
142
136
  };
143
137
  };
144
138
  exports.transformer = transformer;
@@ -4,16 +4,12 @@ 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
7
  const propsSpreadSymbol = Symbol.for("$nesquickSpreadProps");
9
8
  exports.Fragment = Symbol();
10
9
  function jsxs(type, props, key) {
11
10
  if (type === exports.Fragment) {
12
11
  return new NesquickFragment_1.NesquickFragment(props.children);
13
12
  }
14
- if (props[propsSpreadSymbol]) {
15
- (0, jsx_runtime_1.functionizeProps)(props);
16
- }
17
13
  if (key !== undefined) {
18
14
  props.key = key;
19
15
  }
@@ -1,4 +1,4 @@
1
- import { Props, JSX } from "../jsx-runtime";
1
+ import { Props, JSX } from "../Nesquick";
2
2
  import { NesquickFragment } from "../NesquickFragment";
3
3
  type ChildRender<T> = (item: T, i: () => number) => JSX.Element;
4
4
  export type ForProps<T> = {
@@ -1,4 +1,4 @@
1
- import { Props } from "../jsx-runtime";
1
+ import { Props } from "../Nesquick";
2
2
  import { ForProps } from "./For";
3
3
  export type IdMap<T, ID, CHILD> = {
4
4
  getId(item: T, i: number): ID;
@@ -4,3 +4,4 @@ export declare namespace Nesquick {
4
4
  }
5
5
  export { Children, Child };
6
6
  export default Nesquick;
7
+ export * from "./jsx-runtime";
@@ -32,7 +32,6 @@ export declare class NesquickComponent<P extends ComponentProps = {}> {
32
32
  constructor(_render: string | FunctionComponent<P>, props: P);
33
33
  render(document: VeactDocument): Node;
34
34
  setXmlns(xmlns: XmlNs | null): void;
35
- private _getAttributeNs;
36
35
  private _renderPropsNs;
37
36
  private _renderProps;
38
37
  private _renderStyles;
@@ -1,4 +1,4 @@
1
- import { JSX } from "./jsx-runtime";
1
+ import { JSX } from "./Nesquick";
2
2
  import { Child, Children, NesquickComponent, NesquickParent, VeactDocument } from "./NesquickComponent";
3
3
  export declare class NesquickFragment extends NesquickComponent<{
4
4
  children: Child[];
@@ -1,2 +1,3 @@
1
1
  import * as TS from "typescript";
2
+ export declare function createCheckFunction(fName: TS.Identifier): TS.FunctionDeclaration;
2
3
  export declare const transformer: TS.TransformerFactory<TS.SourceFile>;
package/package.json CHANGED
@@ -1,15 +1,38 @@
1
1
  {
2
2
  "name": "nesquick",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "React-like library with focus on drawing performance",
5
- "types": "./lib/types",
6
- "main": "./lib",
5
+ "types": "./lib/types/index.d.ts",
6
+ "main": "./lib/index.js",
7
7
  "typesVersions": {
8
8
  "*": {
9
+ ".": ["./lib/types/index.d.ts"],
9
10
  "jsx-runtime": ["./lib/types/jsx-runtime.d.ts"],
10
11
  "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"]
12
+ "no-transformer/jsx-runtime": ["./lib/types/jsx-runtime.d.ts"],
13
+ "no-transformer/jsx-dev-runtime": ["./lib/types/jsx-dev-runtime.d.ts"]
14
+ }
15
+ },
16
+ "exports": {
17
+ ".": {
18
+ "types": "./lib/types/index.d.ts",
19
+ "default": "./lib/index.js"
20
+ },
21
+ "./jsx-runtime": {
22
+ "types": "./lib/types/jsx-runtime.d.ts",
23
+ "default": "./lib/jsx-runtime.js"
24
+ },
25
+ "./jsx-dev-runtime": {
26
+ "types": "./lib/types/jsx-dev-runtime.d.ts",
27
+ "default": "./lib/jsx-dev-runtime.js"
28
+ },
29
+ "./no-transformer/jsx-runtime": {
30
+ "types": "./lib/types/no-transformer/jsx-runtime.d.ts",
31
+ "default": "./lib/no-transformer/jsx-runtime.js"
32
+ },
33
+ "./no-transformer/jsx-dev-runtime": {
34
+ "types": "./lib/types/no-transformer/jsx-dev-runtime.d.ts",
35
+ "default": "./lib/no-transformer/jsx-dev-runtime.js"
13
36
  }
14
37
  },
15
38
  "bin": {