@ripple-ts/prettier-plugin 0.2.176 → 0.2.178
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/package.json +2 -2
- package/src/index.js +9 -19
- package/src/index.test.js +21 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ripple-ts/prettier-plugin",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.178",
|
|
4
4
|
"description": "Ripple plugin for Prettier",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"prettier": "^3.6.2",
|
|
28
|
-
"ripple": "0.2.
|
|
28
|
+
"ripple": "0.2.178"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {},
|
|
31
31
|
"files": [
|
package/src/index.js
CHANGED
|
@@ -4492,7 +4492,12 @@ function printJSXElement(node, path, options, print) {
|
|
|
4492
4492
|
if (hasAttributes) {
|
|
4493
4493
|
const attrs = openingElement.attributes.map((attr, i) => {
|
|
4494
4494
|
if (attr.type === 'JSXAttribute') {
|
|
4495
|
-
return
|
|
4495
|
+
return path.call(
|
|
4496
|
+
(attrPath) => printJSXAttribute(attrPath.getValue(), attrPath, options, print),
|
|
4497
|
+
'openingElement',
|
|
4498
|
+
'attributes',
|
|
4499
|
+
i,
|
|
4500
|
+
);
|
|
4496
4501
|
} else if (attr.type === 'JSXSpreadAttribute') {
|
|
4497
4502
|
return concat([
|
|
4498
4503
|
'{...',
|
|
@@ -4625,7 +4630,7 @@ function printJSXFragment(node, path, options, print) {
|
|
|
4625
4630
|
return group(['<>', indent(concat([hardline, ...formattedChildren])), hardline, '</>']);
|
|
4626
4631
|
}
|
|
4627
4632
|
|
|
4628
|
-
function printJSXAttribute(attr, path, options, print
|
|
4633
|
+
function printJSXAttribute(attr, path, options, print) {
|
|
4629
4634
|
const name = attr.name.name;
|
|
4630
4635
|
|
|
4631
4636
|
if (!attr.value) {
|
|
@@ -4638,23 +4643,8 @@ function printJSXAttribute(attr, path, options, print, index) {
|
|
|
4638
4643
|
}
|
|
4639
4644
|
|
|
4640
4645
|
if (attr.value.type === 'JSXExpressionContainer') {
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
const exprValue = attr.value.expression;
|
|
4644
|
-
let exprStr;
|
|
4645
|
-
|
|
4646
|
-
if (exprValue.type === 'Literal' || exprValue.type === 'StringLiteral') {
|
|
4647
|
-
exprStr = JSON.stringify(exprValue.value);
|
|
4648
|
-
} else if (exprValue.type === 'Identifier') {
|
|
4649
|
-
exprStr = (exprValue.tracked ? '@' : '') + exprValue.name;
|
|
4650
|
-
} else if (exprValue.type === 'MemberExpression') {
|
|
4651
|
-
exprStr = printMemberExpressionSimple(exprValue, options);
|
|
4652
|
-
} else {
|
|
4653
|
-
// For complex expressions, try to stringify
|
|
4654
|
-
exprStr = '...';
|
|
4655
|
-
}
|
|
4656
|
-
|
|
4657
|
-
return concat([name, '={', exprStr, '}']);
|
|
4646
|
+
const exprDoc = path.call(print, 'value', 'expression');
|
|
4647
|
+
return concat([name, '={', exprDoc, '}']);
|
|
4658
4648
|
}
|
|
4659
4649
|
|
|
4660
4650
|
return name;
|
package/src/index.test.js
CHANGED
|
@@ -4019,6 +4019,27 @@ component Polygon() {
|
|
|
4019
4019
|
expect(result).toBeWithNewline(expected);
|
|
4020
4020
|
});
|
|
4021
4021
|
|
|
4022
|
+
it('should format JSX attributes with JSX elements correctly', async () => {
|
|
4023
|
+
const input = `export component App() {
|
|
4024
|
+
<tsx:react>
|
|
4025
|
+
<Suspense fallback={<div>Loading...</div>}>
|
|
4026
|
+
<Child />
|
|
4027
|
+
</Suspense>
|
|
4028
|
+
</tsx:react>
|
|
4029
|
+
}`;
|
|
4030
|
+
|
|
4031
|
+
const expected = `export component App() {
|
|
4032
|
+
<tsx:react>
|
|
4033
|
+
<Suspense fallback={<div>Loading...</div>}>
|
|
4034
|
+
<Child />
|
|
4035
|
+
</Suspense>
|
|
4036
|
+
</tsx:react>
|
|
4037
|
+
}`;
|
|
4038
|
+
|
|
4039
|
+
const result = await format(input);
|
|
4040
|
+
expect(result).toBeWithNewline(expected);
|
|
4041
|
+
});
|
|
4042
|
+
|
|
4022
4043
|
it('should format JSXFragment with text and elements mixed', async () => {
|
|
4023
4044
|
const input = `component App() {
|
|
4024
4045
|
<tsx:react>
|