@zessjs/compiler 1.1.6 → 1.1.7

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/dist/compiler.cjs CHANGED
@@ -591,53 +591,59 @@ function transformElement(node) {
591
591
  return stmts;
592
592
  }
593
593
  function transformFragment(children, position, isInComponent) {
594
- const elements = [];
595
594
  let hasDynamicChildren = false;
596
595
  let shouldImportUseMemo = false;
597
596
  let textContent;
598
597
  let textPosition;
599
598
  let elementsPosition;
600
599
  let childExpression;
601
- for (let i = 0; i < children.length; ++i) {
602
- const childNode = children[i];
603
- if (childNode.type === "JSXText") {
604
- const text = childNode.value;
605
- if (isBlankLine(text)) continue;
606
- if (textContent) textContent = `${textContent}${text}`;
607
- else {
608
- textContent = text;
609
- textPosition = copyPosition(childNode);
610
- elementsPosition ??= textPosition;
611
- }
612
- } else if (isJSXEmptyExpression(childNode)) continue;
613
- else if (childNode.type === "JSXFragment") children.splice(i--, 1, ...childNode.children);
614
- else {
615
- const childPosition = copyPosition(childNode);
616
- let childElement;
617
- if (textContent) {
618
- elements.push(createLiteral(decodeText(textContent), textPosition));
619
- textContent = textPosition = void 0;
620
- }
621
- if (childNode.type === "JSXElement") {
622
- const stmts = transformElement(childNode);
623
- if (isInComponent) hasDynamicChildren = true;
624
- if (stmts.length > 1) {
625
- const id = stmts[0].declarations[0].id;
626
- childElement = createCallExpression(createArrowFunctionExpression(createBlockStatement([...stmts, createReturnStatement(id, childPosition)], childPosition), childPosition), [], childPosition);
627
- } else if (stmts[0].type === "VariableDeclaration") childElement = stmts[0].declarations[0].init;
628
- else childElement = stmts[0].expression;
629
- } else {
630
- const expression = childNode.expression;
631
- if (isInComponent) childExpression ??= expression;
632
- if (isDynamicExpression(expression, isInComponent)) {
633
- shouldImportUseMemo = hasDynamicChildren = true;
634
- childElement = createCallExpression(createIdentifier("_$memo", childPosition), [!isInComponent && isBareIdentifierCall(expression) ? expression.callee : createArrowFunctionExpression(expression, copyPosition(expression))], childPosition);
635
- } else childElement = expression;
600
+ const stack = [[children, 0]];
601
+ const elements = [];
602
+ outer: do {
603
+ const top = stack.at(-1);
604
+ while (top[1] < top[0].length) {
605
+ const childNode = top[0][top[1]++];
606
+ if (childNode.type === "JSXText") {
607
+ const text = childNode.value;
608
+ if (isBlankLine(text)) continue;
609
+ if (textContent) textContent = `${textContent}${text}`;
610
+ else {
611
+ textContent = text;
612
+ textPosition = copyPosition(childNode);
613
+ elementsPosition ??= textPosition;
614
+ }
615
+ } else if (childNode.type === "JSXFragment") {
616
+ stack.push([childNode.children, 0]);
617
+ continue outer;
618
+ } else if (!isJSXEmptyExpression(childNode)) {
619
+ const childPosition = copyPosition(childNode);
620
+ let childElement;
621
+ if (textContent) {
622
+ elements.push(createLiteral(decodeText(textContent), textPosition));
623
+ textContent = textPosition = void 0;
624
+ }
625
+ if (childNode.type === "JSXElement") {
626
+ const stmts = transformElement(childNode);
627
+ if (isInComponent) hasDynamicChildren = true;
628
+ if (stmts.length > 1) {
629
+ const id = stmts[0].declarations[0].id;
630
+ childElement = createCallExpression(createArrowFunctionExpression(createBlockStatement([...stmts, createReturnStatement(id, childPosition)], childPosition), childPosition), [], childPosition);
631
+ } else if (stmts[0].type === "VariableDeclaration") childElement = stmts[0].declarations[0].init;
632
+ else childElement = stmts[0].expression;
633
+ } else {
634
+ const expression = childNode.expression;
635
+ if (isInComponent) childExpression ??= expression;
636
+ if (isDynamicExpression(expression, isInComponent)) {
637
+ shouldImportUseMemo = hasDynamicChildren = true;
638
+ childElement = createCallExpression(createIdentifier("_$memo", childPosition), [!isInComponent && isBareIdentifierCall(expression) ? expression.callee : createArrowFunctionExpression(expression, copyPosition(expression))], childPosition);
639
+ } else childElement = expression;
640
+ }
641
+ elements.push(childElement);
642
+ elementsPosition ??= childPosition;
636
643
  }
637
- elements.push(childElement);
638
- elementsPosition ??= childPosition;
639
644
  }
640
- }
645
+ stack.pop();
646
+ } while (stack.length);
641
647
  if (textContent) elements.push(createLiteral(decodeText(textContent), textPosition));
642
648
  if (isInComponent) {
643
649
  currentContext.prevHasDynamicChildrenInComponent = currentContext.hasDynamicChildrenInComponent;
@@ -989,58 +995,64 @@ function transformAttributes(attrs, id) {
989
995
  return stmts;
990
996
  }
991
997
  function transformChildren(children, id) {
992
- const stmts = [];
993
998
  let elements = [];
994
999
  let textContent;
995
1000
  let textPosition;
996
1001
  let elementsPosition;
997
- for (let i = 0; i < children.length; ++i) {
998
- const childNode = children[i];
999
- if (childNode.type === "JSXText") {
1000
- const text = childNode.value;
1001
- if (isBlankLine(text)) continue;
1002
- if (textContent) textContent = `${textContent}${text}`;
1003
- else {
1004
- textContent = text;
1005
- textPosition = copyPosition(childNode);
1006
- elementsPosition ??= textPosition;
1007
- }
1008
- } else if (isJSXEmptyExpression(childNode)) continue;
1009
- else if (childNode.type === "JSXFragment") children.splice(i--, 1, ...childNode.children);
1010
- else {
1011
- const childPosition = copyPosition(childNode);
1012
- let expression;
1013
- if (textContent) {
1014
- elements.push(createLiteral(decodeText(textContent), textPosition));
1015
- textContent = textPosition = void 0;
1016
- }
1017
- if (childNode.type === "JSXElement") {
1018
- const childStmts = transformElement(childNode);
1019
- if (childStmts.length > 1) {
1020
- const stmt = childStmts[0];
1021
- elements.push(stmt.declarations[0].id);
1022
- elementsPosition ??= childPosition;
1023
- stmts.push(...childStmts);
1024
- continue;
1025
- } else if (childStmts[0].type === "VariableDeclaration") {
1026
- elements.push(childStmts[0].declarations[0].init);
1027
- elementsPosition ??= childPosition;
1028
- continue;
1029
- } else expression = childStmts[0].expression;
1030
- } else {
1031
- expression = childNode.expression;
1032
- if (isBareIdentifierCall(expression)) expression = expression.callee;
1033
- else if (isDynamicExpression(expression)) expression = createArrowFunctionExpression(expression, copyPosition(expression));
1034
- }
1035
- if (elements.length) {
1036
- stmts.push(createExpressionStatement(createCallExpression(createMemberExpression(id, createIdentifier("append", elementsPosition), false, elementsPosition), elements, elementsPosition), elementsPosition));
1037
- elements = [];
1038
- elementsPosition = void 0;
1002
+ const stack = [[children, 0]];
1003
+ const stmts = [];
1004
+ outer: do {
1005
+ const top = stack.at(-1);
1006
+ while (top[1] < top[0].length) {
1007
+ const childNode = top[0][top[1]++];
1008
+ if (childNode.type === "JSXText") {
1009
+ const text = childNode.value;
1010
+ if (isBlankLine(text)) continue;
1011
+ if (textContent) textContent = `${textContent}${text}`;
1012
+ else {
1013
+ textContent = text;
1014
+ textPosition = copyPosition(childNode);
1015
+ elementsPosition ??= textPosition;
1016
+ }
1017
+ } else if (childNode.type === "JSXFragment") {
1018
+ stack.push([childNode.children, 0]);
1019
+ continue outer;
1020
+ } else if (!isJSXEmptyExpression(childNode)) {
1021
+ const childPosition = copyPosition(childNode);
1022
+ let expression;
1023
+ if (textContent) {
1024
+ elements.push(createLiteral(decodeText(textContent), textPosition));
1025
+ textContent = textPosition = void 0;
1026
+ }
1027
+ if (childNode.type === "JSXElement") {
1028
+ const childStmts = transformElement(childNode);
1029
+ if (childStmts.length > 1) {
1030
+ const stmt = childStmts[0];
1031
+ elements.push(stmt.declarations[0].id);
1032
+ elementsPosition ??= childPosition;
1033
+ stmts.push(...childStmts);
1034
+ continue;
1035
+ } else if (childStmts[0].type === "VariableDeclaration") {
1036
+ elements.push(childStmts[0].declarations[0].init);
1037
+ elementsPosition ??= childPosition;
1038
+ continue;
1039
+ } else expression = childStmts[0].expression;
1040
+ } else {
1041
+ expression = childNode.expression;
1042
+ if (isBareIdentifierCall(expression)) expression = expression.callee;
1043
+ else if (isDynamicExpression(expression)) expression = createArrowFunctionExpression(expression, copyPosition(expression));
1044
+ }
1045
+ if (elements.length) {
1046
+ stmts.push(createExpressionStatement(createCallExpression(createMemberExpression(id, createIdentifier("append", elementsPosition), false, elementsPosition), elements, elementsPosition), elementsPosition));
1047
+ elements = [];
1048
+ elementsPosition = void 0;
1049
+ }
1050
+ currentContext.shouldImportInsert = true;
1051
+ stmts.push(createExpressionStatement(createCallExpression(createIdentifier("_$insert", childPosition), [id, expression], childPosition), childPosition));
1039
1052
  }
1040
- currentContext.shouldImportInsert = true;
1041
- stmts.push(createExpressionStatement(createCallExpression(createIdentifier("_$insert", childPosition), [id, expression], childPosition), childPosition));
1042
1053
  }
1043
- }
1054
+ stack.pop();
1055
+ } while (stack.length);
1044
1056
  if (textContent) elements.push(createLiteral(decodeText(textContent), textPosition));
1045
1057
  if (elements.length) stmts.push(createExpressionStatement(!stmts.length && elements.length === 1 && textContent ? createAssignmentExpression(createMemberExpression(id, createIdentifier("textContent", elementsPosition), false, elementsPosition), elements[0], elementsPosition) : createCallExpression(createMemberExpression(id, createIdentifier("append", elementsPosition), false, elementsPosition), elements, elementsPosition), elementsPosition));
1046
1058
  return stmts;
package/dist/compiler.js CHANGED
@@ -563,53 +563,59 @@ function transformElement(node) {
563
563
  return stmts;
564
564
  }
565
565
  function transformFragment(children, position, isInComponent) {
566
- const elements = [];
567
566
  let hasDynamicChildren = false;
568
567
  let shouldImportUseMemo = false;
569
568
  let textContent;
570
569
  let textPosition;
571
570
  let elementsPosition;
572
571
  let childExpression;
573
- for (let i = 0; i < children.length; ++i) {
574
- const childNode = children[i];
575
- if (childNode.type === "JSXText") {
576
- const text = childNode.value;
577
- if (isBlankLine(text)) continue;
578
- if (textContent) textContent = `${textContent}${text}`;
579
- else {
580
- textContent = text;
581
- textPosition = copyPosition(childNode);
582
- elementsPosition ??= textPosition;
583
- }
584
- } else if (isJSXEmptyExpression(childNode)) continue;
585
- else if (childNode.type === "JSXFragment") children.splice(i--, 1, ...childNode.children);
586
- else {
587
- const childPosition = copyPosition(childNode);
588
- let childElement;
589
- if (textContent) {
590
- elements.push(createLiteral(decodeText(textContent), textPosition));
591
- textContent = textPosition = void 0;
592
- }
593
- if (childNode.type === "JSXElement") {
594
- const stmts = transformElement(childNode);
595
- if (isInComponent) hasDynamicChildren = true;
596
- if (stmts.length > 1) {
597
- const id = stmts[0].declarations[0].id;
598
- childElement = createCallExpression(createArrowFunctionExpression(createBlockStatement([...stmts, createReturnStatement(id, childPosition)], childPosition), childPosition), [], childPosition);
599
- } else if (stmts[0].type === "VariableDeclaration") childElement = stmts[0].declarations[0].init;
600
- else childElement = stmts[0].expression;
601
- } else {
602
- const expression = childNode.expression;
603
- if (isInComponent) childExpression ??= expression;
604
- if (isDynamicExpression(expression, isInComponent)) {
605
- shouldImportUseMemo = hasDynamicChildren = true;
606
- childElement = createCallExpression(createIdentifier("_$memo", childPosition), [!isInComponent && isBareIdentifierCall(expression) ? expression.callee : createArrowFunctionExpression(expression, copyPosition(expression))], childPosition);
607
- } else childElement = expression;
572
+ const stack = [[children, 0]];
573
+ const elements = [];
574
+ outer: do {
575
+ const top = stack.at(-1);
576
+ while (top[1] < top[0].length) {
577
+ const childNode = top[0][top[1]++];
578
+ if (childNode.type === "JSXText") {
579
+ const text = childNode.value;
580
+ if (isBlankLine(text)) continue;
581
+ if (textContent) textContent = `${textContent}${text}`;
582
+ else {
583
+ textContent = text;
584
+ textPosition = copyPosition(childNode);
585
+ elementsPosition ??= textPosition;
586
+ }
587
+ } else if (childNode.type === "JSXFragment") {
588
+ stack.push([childNode.children, 0]);
589
+ continue outer;
590
+ } else if (!isJSXEmptyExpression(childNode)) {
591
+ const childPosition = copyPosition(childNode);
592
+ let childElement;
593
+ if (textContent) {
594
+ elements.push(createLiteral(decodeText(textContent), textPosition));
595
+ textContent = textPosition = void 0;
596
+ }
597
+ if (childNode.type === "JSXElement") {
598
+ const stmts = transformElement(childNode);
599
+ if (isInComponent) hasDynamicChildren = true;
600
+ if (stmts.length > 1) {
601
+ const id = stmts[0].declarations[0].id;
602
+ childElement = createCallExpression(createArrowFunctionExpression(createBlockStatement([...stmts, createReturnStatement(id, childPosition)], childPosition), childPosition), [], childPosition);
603
+ } else if (stmts[0].type === "VariableDeclaration") childElement = stmts[0].declarations[0].init;
604
+ else childElement = stmts[0].expression;
605
+ } else {
606
+ const expression = childNode.expression;
607
+ if (isInComponent) childExpression ??= expression;
608
+ if (isDynamicExpression(expression, isInComponent)) {
609
+ shouldImportUseMemo = hasDynamicChildren = true;
610
+ childElement = createCallExpression(createIdentifier("_$memo", childPosition), [!isInComponent && isBareIdentifierCall(expression) ? expression.callee : createArrowFunctionExpression(expression, copyPosition(expression))], childPosition);
611
+ } else childElement = expression;
612
+ }
613
+ elements.push(childElement);
614
+ elementsPosition ??= childPosition;
608
615
  }
609
- elements.push(childElement);
610
- elementsPosition ??= childPosition;
611
616
  }
612
- }
617
+ stack.pop();
618
+ } while (stack.length);
613
619
  if (textContent) elements.push(createLiteral(decodeText(textContent), textPosition));
614
620
  if (isInComponent) {
615
621
  currentContext.prevHasDynamicChildrenInComponent = currentContext.hasDynamicChildrenInComponent;
@@ -961,58 +967,64 @@ function transformAttributes(attrs, id) {
961
967
  return stmts;
962
968
  }
963
969
  function transformChildren(children, id) {
964
- const stmts = [];
965
970
  let elements = [];
966
971
  let textContent;
967
972
  let textPosition;
968
973
  let elementsPosition;
969
- for (let i = 0; i < children.length; ++i) {
970
- const childNode = children[i];
971
- if (childNode.type === "JSXText") {
972
- const text = childNode.value;
973
- if (isBlankLine(text)) continue;
974
- if (textContent) textContent = `${textContent}${text}`;
975
- else {
976
- textContent = text;
977
- textPosition = copyPosition(childNode);
978
- elementsPosition ??= textPosition;
979
- }
980
- } else if (isJSXEmptyExpression(childNode)) continue;
981
- else if (childNode.type === "JSXFragment") children.splice(i--, 1, ...childNode.children);
982
- else {
983
- const childPosition = copyPosition(childNode);
984
- let expression;
985
- if (textContent) {
986
- elements.push(createLiteral(decodeText(textContent), textPosition));
987
- textContent = textPosition = void 0;
988
- }
989
- if (childNode.type === "JSXElement") {
990
- const childStmts = transformElement(childNode);
991
- if (childStmts.length > 1) {
992
- const stmt = childStmts[0];
993
- elements.push(stmt.declarations[0].id);
994
- elementsPosition ??= childPosition;
995
- stmts.push(...childStmts);
996
- continue;
997
- } else if (childStmts[0].type === "VariableDeclaration") {
998
- elements.push(childStmts[0].declarations[0].init);
999
- elementsPosition ??= childPosition;
1000
- continue;
1001
- } else expression = childStmts[0].expression;
1002
- } else {
1003
- expression = childNode.expression;
1004
- if (isBareIdentifierCall(expression)) expression = expression.callee;
1005
- else if (isDynamicExpression(expression)) expression = createArrowFunctionExpression(expression, copyPosition(expression));
1006
- }
1007
- if (elements.length) {
1008
- stmts.push(createExpressionStatement(createCallExpression(createMemberExpression(id, createIdentifier("append", elementsPosition), false, elementsPosition), elements, elementsPosition), elementsPosition));
1009
- elements = [];
1010
- elementsPosition = void 0;
974
+ const stack = [[children, 0]];
975
+ const stmts = [];
976
+ outer: do {
977
+ const top = stack.at(-1);
978
+ while (top[1] < top[0].length) {
979
+ const childNode = top[0][top[1]++];
980
+ if (childNode.type === "JSXText") {
981
+ const text = childNode.value;
982
+ if (isBlankLine(text)) continue;
983
+ if (textContent) textContent = `${textContent}${text}`;
984
+ else {
985
+ textContent = text;
986
+ textPosition = copyPosition(childNode);
987
+ elementsPosition ??= textPosition;
988
+ }
989
+ } else if (childNode.type === "JSXFragment") {
990
+ stack.push([childNode.children, 0]);
991
+ continue outer;
992
+ } else if (!isJSXEmptyExpression(childNode)) {
993
+ const childPosition = copyPosition(childNode);
994
+ let expression;
995
+ if (textContent) {
996
+ elements.push(createLiteral(decodeText(textContent), textPosition));
997
+ textContent = textPosition = void 0;
998
+ }
999
+ if (childNode.type === "JSXElement") {
1000
+ const childStmts = transformElement(childNode);
1001
+ if (childStmts.length > 1) {
1002
+ const stmt = childStmts[0];
1003
+ elements.push(stmt.declarations[0].id);
1004
+ elementsPosition ??= childPosition;
1005
+ stmts.push(...childStmts);
1006
+ continue;
1007
+ } else if (childStmts[0].type === "VariableDeclaration") {
1008
+ elements.push(childStmts[0].declarations[0].init);
1009
+ elementsPosition ??= childPosition;
1010
+ continue;
1011
+ } else expression = childStmts[0].expression;
1012
+ } else {
1013
+ expression = childNode.expression;
1014
+ if (isBareIdentifierCall(expression)) expression = expression.callee;
1015
+ else if (isDynamicExpression(expression)) expression = createArrowFunctionExpression(expression, copyPosition(expression));
1016
+ }
1017
+ if (elements.length) {
1018
+ stmts.push(createExpressionStatement(createCallExpression(createMemberExpression(id, createIdentifier("append", elementsPosition), false, elementsPosition), elements, elementsPosition), elementsPosition));
1019
+ elements = [];
1020
+ elementsPosition = void 0;
1021
+ }
1022
+ currentContext.shouldImportInsert = true;
1023
+ stmts.push(createExpressionStatement(createCallExpression(createIdentifier("_$insert", childPosition), [id, expression], childPosition), childPosition));
1011
1024
  }
1012
- currentContext.shouldImportInsert = true;
1013
- stmts.push(createExpressionStatement(createCallExpression(createIdentifier("_$insert", childPosition), [id, expression], childPosition), childPosition));
1014
1025
  }
1015
- }
1026
+ stack.pop();
1027
+ } while (stack.length);
1016
1028
  if (textContent) elements.push(createLiteral(decodeText(textContent), textPosition));
1017
1029
  if (elements.length) stmts.push(createExpressionStatement(!stmts.length && elements.length === 1 && textContent ? createAssignmentExpression(createMemberExpression(id, createIdentifier("textContent", elementsPosition), false, elementsPosition), elements[0], elementsPosition) : createCallExpression(createMemberExpression(id, createIdentifier("append", elementsPosition), false, elementsPosition), elements, elementsPosition), elementsPosition));
1018
1030
  return stmts;
package/package.json CHANGED
@@ -1,49 +1,49 @@
1
1
  {
2
2
  "name": "@zessjs/compiler",
3
- "version": "1.1.6",
4
- "description": "Zess JSX compiler 💥 Delivers efficient code conversion for super - responsive web experiences.",
5
3
  "type": "module",
6
- "keywords": [
7
- "zess",
8
- "zessjs",
9
- "compiler",
10
- "JSX"
11
- ],
4
+ "version": "1.1.7",
5
+ "description": "Zess JSX compiler 💥 Delivers efficient code conversion for super - responsive web experiences.",
6
+ "author": "Columsys",
12
7
  "license": "MIT",
13
8
  "homepage": "https://github.com/rpsffx/zess/tree/main/packages/compiler#readme",
14
- "bugs": {
15
- "url": "https://github.com/rpsffx/zess/issues"
16
- },
17
9
  "repository": {
18
10
  "type": "git",
19
11
  "url": "git+https://github.com/rpsffx/zess.git",
20
12
  "directory": "packages/compiler"
21
13
  },
22
- "author": "Columsys",
23
- "files": [
24
- "dist"
14
+ "bugs": {
15
+ "url": "https://github.com/rpsffx/zess/issues"
16
+ },
17
+ "keywords": [
18
+ "zess",
19
+ "zessjs",
20
+ "compiler",
21
+ "JSX"
25
22
  ],
26
- "main": "./dist/compiler.js",
27
- "module": "./dist/compiler.js",
28
- "types": "./dist/compiler.d.ts",
29
23
  "exports": {
30
24
  "types": "./dist/compiler.d.ts",
31
- "require": "./dist/compiler.cjs",
32
- "import": "./dist/compiler.js"
25
+ "import": "./dist/compiler.js",
26
+ "require": "./dist/compiler.cjs"
33
27
  },
28
+ "main": "./dist/compiler.js",
29
+ "module": "./dist/compiler.js",
30
+ "types": "./dist/compiler.d.ts",
31
+ "files": [
32
+ "dist"
33
+ ],
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
+ "engines": {
38
+ "node": ">=18.12.0"
39
+ },
37
40
  "dependencies": {
38
41
  "astring": "^1.9.0",
39
- "entities": "^7.0.0",
42
+ "entities": "^7.0.1",
40
43
  "merge-source-map": "^1.1.0",
41
- "meriyah": "^6.1.4",
44
+ "meriyah": "^7.1.0",
42
45
  "source-map": "^0.7.6"
43
46
  },
44
- "engines": {
45
- "node": ">=18.12.0"
46
- },
47
47
  "scripts": {
48
48
  "build": "tsdown",
49
49
  "dev": "tsdown --watch"