@ripple-ts/prettier-plugin 0.2.172 → 0.2.174
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 -12
- package/src/index.test.js +28 -2
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.174",
|
|
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.174"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {},
|
|
31
31
|
"files": [
|
package/src/index.js
CHANGED
|
@@ -1400,7 +1400,15 @@ function printRippleNode(node, path, options, print, args) {
|
|
|
1400
1400
|
|
|
1401
1401
|
case 'SpreadElement': {
|
|
1402
1402
|
const argumentDoc = path.call(print, 'argument');
|
|
1403
|
-
|
|
1403
|
+
// Wrap argument in parens if it's a low-precedence logical expression (e.g., nullish coalescing)
|
|
1404
|
+
// that needs them for correct parsing
|
|
1405
|
+
const needsParens =
|
|
1406
|
+
node.argument.type === 'LogicalExpression' && node.argument.operator === '??';
|
|
1407
|
+
if (needsParens) {
|
|
1408
|
+
nodeContent = concat(['...(', argumentDoc, ')']);
|
|
1409
|
+
} else {
|
|
1410
|
+
nodeContent = concat(['...', argumentDoc]);
|
|
1411
|
+
}
|
|
1404
1412
|
break;
|
|
1405
1413
|
}
|
|
1406
1414
|
case 'RestElement': {
|
|
@@ -3003,17 +3011,6 @@ function printObjectExpression(node, path, options, print, args) {
|
|
|
3003
3011
|
// 1-property objects: force inline with spaces
|
|
3004
3012
|
return concat([open_brace, ' ', properties[0], ' ', '}']);
|
|
3005
3013
|
}
|
|
3006
|
-
// 2-property objects: let normal formatting handle it (will be multiline)
|
|
3007
|
-
// Fall through to default multiline formatting below
|
|
3008
|
-
} else {
|
|
3009
|
-
// For attributes, force inline without spaces
|
|
3010
|
-
const parts = [open_brace];
|
|
3011
|
-
for (let i = 0; i < properties.length; i++) {
|
|
3012
|
-
if (i > 0) parts.push(', ');
|
|
3013
|
-
parts.push(properties[i]);
|
|
3014
|
-
}
|
|
3015
|
-
parts.push('}');
|
|
3016
|
-
return concat(parts);
|
|
3017
3014
|
}
|
|
3018
3015
|
}
|
|
3019
3016
|
|
package/src/index.test.js
CHANGED
|
@@ -878,6 +878,22 @@ export component Test({ a, b }: Props) {}`;
|
|
|
878
878
|
expect(result).toBeWithNewline(expected);
|
|
879
879
|
});
|
|
880
880
|
|
|
881
|
+
it('should format object in attribute with spaces at each side', async () => {
|
|
882
|
+
const input = `component App() {
|
|
883
|
+
<button
|
|
884
|
+
class="test another"
|
|
885
|
+
onClick={{handleEvent: handler}}>{'Click Me'}</button>
|
|
886
|
+
}`;
|
|
887
|
+
const expected = `component App() {
|
|
888
|
+
<button class="test another" onClick={{ handleEvent: handler }}>
|
|
889
|
+
{'Click Me'}
|
|
890
|
+
</button>
|
|
891
|
+
}`;
|
|
892
|
+
|
|
893
|
+
const result = await format(input, { singleQuote: true });
|
|
894
|
+
expect(result).toBeWithNewline(expected);
|
|
895
|
+
});
|
|
896
|
+
|
|
881
897
|
it('should not format function parameter spread', async () => {
|
|
882
898
|
const expected = `component Two({ arg1, ...rest }) {}`;
|
|
883
899
|
|
|
@@ -1691,6 +1707,16 @@ const program =
|
|
|
1691
1707
|
const result = await format(expected, { singleQuote: true, printWidth: 100 });
|
|
1692
1708
|
expect(result).toBeWithNewline(expected);
|
|
1693
1709
|
});
|
|
1710
|
+
|
|
1711
|
+
it('should have parents around low-precedence logical expression', async () => {
|
|
1712
|
+
const input = `files = [...files ?? [], ...dt.files];
|
|
1713
|
+
files = [...(files ?? []), ...dt.files];`;
|
|
1714
|
+
const expected = `files = [...(files ?? []), ...dt.files];
|
|
1715
|
+
files = [...(files ?? []), ...dt.files];`;
|
|
1716
|
+
|
|
1717
|
+
const result = await format(input, { singleQuote: true, printWidth: 100 });
|
|
1718
|
+
expect(result).toBeWithNewline(expected);
|
|
1719
|
+
});
|
|
1694
1720
|
});
|
|
1695
1721
|
|
|
1696
1722
|
describe('edge cases', () => {
|
|
@@ -2787,9 +2813,9 @@ component RowList({ rows, Row }) {
|
|
|
2787
2813
|
|
|
2788
2814
|
const expected = `export component App() {
|
|
2789
2815
|
<div>
|
|
2790
|
-
<RowList rows={#[{id: 'a'}, {id: 'b'}, {id: 'c'}]}>
|
|
2816
|
+
<RowList rows={#[{ id: 'a' }, { id: 'b' }, { id: 'c' }]}>
|
|
2791
2817
|
component Row({ id, index, isHighlighted = (index) => index % 2 === 0 }) {
|
|
2792
|
-
<div class={{highlighted: isHighlighted(index)}}>
|
|
2818
|
+
<div class={{ highlighted: isHighlighted(index) }}>
|
|
2793
2819
|
{index}
|
|
2794
2820
|
{' - '}
|
|
2795
2821
|
{id}
|