nesquick 0.0.23 → 0.0.25

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.
@@ -35,22 +35,32 @@ function hasIdentifier(node) {
35
35
  }
36
36
  const transformer = context => {
37
37
  return sourceFile => {
38
- let isComponent = false;
39
- const visitorGeneric = node => {
40
- if (TS.isJsxOpeningElement(node)) {
38
+ const visitGeneric = (node, options) => {
39
+ if (TS.isJsxOpeningLikeElement(node)) {
41
40
  const firstLetter = node.tagName.getText()[0];
42
- isComponent = firstLetter !== firstLetter.toLowerCase();
41
+ const userComponent = firstLetter !== firstLetter.toLowerCase();
42
+ return TS.visitEachChild(node, node => visitGeneric(node, { userComponent }), context);
43
43
  }
44
- if (TS.isJsxExpression(node)) {
45
- return TS.visitEachChild(node, visitorExpression, context);
44
+ if (TS.isJsxAttribute(node)) {
45
+ return TS.visitEachChild(node, node => visitGeneric(node, { ...options, isJsxAttribute: true }), context);
46
46
  }
47
- return TS.visitEachChild(node, visitorGeneric, context);
47
+ else if (TS.isJsxExpression(node)) {
48
+ return TS.visitEachChild(node, node => visitorExpression(node, { ...options, isJsxAttribute: false }), context);
49
+ }
50
+ else if (options.isJsxAttribute && TS.isStringLiteral(node)) {
51
+ const returnNode = TS.visitNode(node, node => visitorExpression(node, { ...options, isJsxAttribute: false }), TS.isExpression);
52
+ if (!TS.isStringLiteral(returnNode)) {
53
+ return TS.factory.createJsxExpression(undefined, returnNode);
54
+ }
55
+ return returnNode;
56
+ }
57
+ return TS.visitEachChild(node, node => visitGeneric(node, { ...options, isJsxAttribute: false }), context);
48
58
  };
49
- const visitorExpression = node => {
59
+ const visitorExpression = (node, options) => {
50
60
  if (TS.isParenthesizedExpression(node)) {
51
61
  const body = getSingleBody(node);
52
62
  if (body) {
53
- return TS.visitNode(body, visitorExpression, TS.isSourceFile);
63
+ return TS.visitNode(body, node => visitorExpression(node, options));
54
64
  }
55
65
  }
56
66
  else if (TS.isCallExpression(node)) {
@@ -59,15 +69,15 @@ const transformer = context => {
59
69
  return identifier;
60
70
  }
61
71
  else {
62
- return TS.factory.createArrowFunction(undefined, undefined, [], undefined, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), node);
72
+ return TS.factory.createArrowFunction(undefined, undefined, [], undefined, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), TS.visitNode(node, node => visitGeneric(node, {}), TS.isConciseBody));
63
73
  }
64
74
  }
65
- else if (!TS.isFunctionLike(node) && TS.isExpression(node) && (isComponent || hasIdentifier(node))) {
66
- return TS.factory.createArrowFunction(undefined, undefined, [], undefined, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), node);
75
+ else if (!TS.isFunctionLike(node) && TS.isExpression(node) && (options.userComponent || hasIdentifier(node))) {
76
+ return TS.factory.createArrowFunction(undefined, undefined, [], undefined, TS.factory.createToken(TS.SyntaxKind.EqualsGreaterThanToken), TS.visitNode(node, node => visitGeneric(node, {}), TS.isConciseBody));
67
77
  }
68
- return node;
78
+ return TS.visitNode(node, node => visitGeneric(node, {}));
69
79
  };
70
- return TS.visitNode(sourceFile, visitorGeneric, TS.isSourceFile);
80
+ return TS.visitNode(sourceFile, node => visitGeneric(node, {}), TS.isSourceFile);
71
81
  };
72
82
  };
73
83
  exports.transformer = transformer;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nesquick",
3
- "version": "0.0.23",
3
+ "version": "0.0.25",
4
4
  "description": "React-like library with focus on drawing performance",
5
5
  "types": "./lib/types",
6
6
  "main": "./lib",