@saykit/transform-jsx 0.0.0-beta-20260717162943 → 0.0.0-beta-20260717182009

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.
@@ -4,7 +4,11 @@ import * as t from "@babel/types";
4
4
  function generateSayJSXElement(message) {
5
5
  const id = message.descriptor.id ?? message.toHashString();
6
6
  const children = generateChildExpressions(message.children);
7
- const attributes = [t.jsxAttribute(t.jsxIdentifier("id"), t.stringLiteral(id)), ...children.map(([k, e]) => t.jsxAttribute(t.jsxIdentifier(Number.isNaN(+k) ? k : `_${k}`), t.jsxExpressionContainer(e)))];
7
+ const attributes = [
8
+ t.jsxAttribute(t.jsxIdentifier("id"), t.stringLiteral(id)),
9
+ ...message.whitespace === void 0 ? [] : [t.jsxAttribute(t.jsxIdentifier("whitespace"), t.jsxExpressionContainer(t.booleanLiteral(message.whitespace)))],
10
+ ...children.map(([k, e]) => t.jsxAttribute(t.jsxIdentifier(Number.isNaN(+k) ? k : `_${k}`), t.jsxExpressionContainer(e)))
11
+ ];
8
12
  return t.jsxElement(t.jsxOpeningElement(t.jsxIdentifier("Say"), attributes, true), null, []);
9
13
  }
10
14
  function generateChildExpressions(messages) {
package/dist/parser.mjs CHANGED
@@ -20,10 +20,13 @@ function parseJSXContainerElement(element) {
20
20
  }
21
21
  return p;
22
22
  }, []);
23
+ const descriptorId = findAttributeValueIfStringLiteralAsString(element.openingElement.attributes, "id");
24
+ const descriptorContext = findAttributeValueIfStringLiteralAsString(element.openingElement.attributes, "context");
25
+ const whitespace = findAttributeValueAsBoolean(element.openingElement.attributes, "whitespace");
23
26
  return new CompositeMessage({
24
- id: findAttributeValueIfStringLiteralAsString(element.openingElement.attributes, "id"),
25
- context: findAttributeValueIfStringLiteralAsString(element.openingElement.attributes, "context")
26
- }, [], [], children, accessor);
27
+ id: descriptorId,
28
+ context: descriptorContext
29
+ }, [], [], children, accessor, whitespace);
27
30
  }
28
31
  function parseJSXOpeningElement(element) {
29
32
  if (!element.selfClosing) return null;
@@ -105,6 +108,14 @@ function findAttributeValueIfExpressionOrStringLiteral(attributes, identifier) {
105
108
  }
106
109
  }
107
110
  }
111
+ function findAttributeValueAsBoolean(attributes, identifier) {
112
+ for (const attribute of attributes) {
113
+ if (!t.isJSXAttribute(attribute)) continue;
114
+ if (!t.isJSXIdentifier(attribute.name) || attribute.name.name !== identifier) continue;
115
+ if (attribute.value == null) return true;
116
+ if (t.isJSXExpressionContainer(attribute.value) && t.isBooleanLiteral(attribute.value.expression)) return attribute.value.expression.value;
117
+ }
118
+ }
108
119
  function getExpressionAsIdentifier(node) {
109
120
  if (t.isIdentifier(node)) return node.name;
110
121
  if (t.isJSXIdentifier(node)) return node.name;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saykit/transform-jsx",
3
- "version": "0.0.0-beta-20260717162943",
3
+ "version": "0.0.0-beta-20260717182009",
4
4
  "description": "JSX and TSX source transformer for SayKit",
5
5
  "keywords": [
6
6
  "i18n",
@@ -43,15 +43,15 @@
43
43
  "provenance": true
44
44
  },
45
45
  "dependencies": {
46
- "@babel/generator": "^7.29.1",
47
- "@babel/parser": "^7.29.3",
48
- "@babel/traverse": "^7.29.0",
49
- "@babel/types": "^7.29.0",
50
- "@saykit/config": "^0.0.0-beta-20260717162943",
51
- "@saykit/transform-js": "^0.0.0-beta-20260717162943"
46
+ "@babel/generator": "^7.29.7",
47
+ "@babel/parser": "^7.29.7",
48
+ "@babel/traverse": "^7.29.7",
49
+ "@babel/types": "^7.29.7",
50
+ "@saykit/config": "^0.0.0-beta-20260717182009",
51
+ "@saykit/transform-js": "^0.0.0-beta-20260717182009"
52
52
  },
53
53
  "devDependencies": {
54
- "@babel/core": "^7.29.0",
54
+ "@babel/core": "^7.29.7",
55
55
  "@types/babel__core": "^7.20.5",
56
56
  "@types/babel__generator": "^7.27.0",
57
57
  "@types/babel__traverse": "^7.28.0"