@ripple-ts/prettier-plugin 0.2.175 → 0.2.177
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 +17 -21
- package/src/index.test.js +36 -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.177",
|
|
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.177"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {},
|
|
31
31
|
"files": [
|
package/src/index.js
CHANGED
|
@@ -696,6 +696,7 @@ function printRippleNode(node, path, options, print, args) {
|
|
|
696
696
|
break;
|
|
697
697
|
|
|
698
698
|
case 'ClassDeclaration':
|
|
699
|
+
case 'ClassExpression':
|
|
699
700
|
nodeContent = printClassDeclaration(node, path, options, print);
|
|
700
701
|
break;
|
|
701
702
|
|
|
@@ -3073,8 +3074,13 @@ function printObjectExpression(node, path, options, print, args) {
|
|
|
3073
3074
|
|
|
3074
3075
|
function printClassDeclaration(node, path, options, print) {
|
|
3075
3076
|
const parts = [];
|
|
3076
|
-
parts.push('class
|
|
3077
|
-
|
|
3077
|
+
parts.push('class');
|
|
3078
|
+
|
|
3079
|
+
// Class name (optional for ClassExpression)
|
|
3080
|
+
if (node.id) {
|
|
3081
|
+
parts.push(' ');
|
|
3082
|
+
parts.push(node.id.name);
|
|
3083
|
+
}
|
|
3078
3084
|
|
|
3079
3085
|
// Add TypeScript generics if present
|
|
3080
3086
|
if (node.typeParameters) {
|
|
@@ -4486,7 +4492,12 @@ function printJSXElement(node, path, options, print) {
|
|
|
4486
4492
|
if (hasAttributes) {
|
|
4487
4493
|
const attrs = openingElement.attributes.map((attr, i) => {
|
|
4488
4494
|
if (attr.type === 'JSXAttribute') {
|
|
4489
|
-
return
|
|
4495
|
+
return path.call(
|
|
4496
|
+
(attrPath) => printJSXAttribute(attrPath.getValue(), attrPath, options, print),
|
|
4497
|
+
'openingElement',
|
|
4498
|
+
'attributes',
|
|
4499
|
+
i,
|
|
4500
|
+
);
|
|
4490
4501
|
} else if (attr.type === 'JSXSpreadAttribute') {
|
|
4491
4502
|
return concat([
|
|
4492
4503
|
'{...',
|
|
@@ -4619,7 +4630,7 @@ function printJSXFragment(node, path, options, print) {
|
|
|
4619
4630
|
return group(['<>', indent(concat([hardline, ...formattedChildren])), hardline, '</>']);
|
|
4620
4631
|
}
|
|
4621
4632
|
|
|
4622
|
-
function printJSXAttribute(attr, path, options, print
|
|
4633
|
+
function printJSXAttribute(attr, path, options, print) {
|
|
4623
4634
|
const name = attr.name.name;
|
|
4624
4635
|
|
|
4625
4636
|
if (!attr.value) {
|
|
@@ -4632,23 +4643,8 @@ function printJSXAttribute(attr, path, options, print, index) {
|
|
|
4632
4643
|
}
|
|
4633
4644
|
|
|
4634
4645
|
if (attr.value.type === 'JSXExpressionContainer') {
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
const exprValue = attr.value.expression;
|
|
4638
|
-
let exprStr;
|
|
4639
|
-
|
|
4640
|
-
if (exprValue.type === 'Literal' || exprValue.type === 'StringLiteral') {
|
|
4641
|
-
exprStr = JSON.stringify(exprValue.value);
|
|
4642
|
-
} else if (exprValue.type === 'Identifier') {
|
|
4643
|
-
exprStr = (exprValue.tracked ? '@' : '') + exprValue.name;
|
|
4644
|
-
} else if (exprValue.type === 'MemberExpression') {
|
|
4645
|
-
exprStr = printMemberExpressionSimple(exprValue, options);
|
|
4646
|
-
} else {
|
|
4647
|
-
// For complex expressions, try to stringify
|
|
4648
|
-
exprStr = '...';
|
|
4649
|
-
}
|
|
4650
|
-
|
|
4651
|
-
return concat([name, '={', exprStr, '}']);
|
|
4646
|
+
const exprDoc = path.call(print, 'value', 'expression');
|
|
4647
|
+
return concat([name, '={', exprDoc, '}']);
|
|
4652
4648
|
}
|
|
4653
4649
|
|
|
4654
4650
|
return name;
|
package/src/index.test.js
CHANGED
|
@@ -1717,6 +1717,13 @@ files = [...(files ?? []), ...dt.files];`;
|
|
|
1717
1717
|
const result = await format(input, { singleQuote: true, printWidth: 100 });
|
|
1718
1718
|
expect(result).toBeWithNewline(expected);
|
|
1719
1719
|
});
|
|
1720
|
+
|
|
1721
|
+
it('should recognize and preserve class assignments to variables', async () => {
|
|
1722
|
+
const expected = `let test = class MediaQueryList {};`;
|
|
1723
|
+
|
|
1724
|
+
const result = await format(expected, { singleQuote: true, printWidth: 100 });
|
|
1725
|
+
expect(result).toBeWithNewline(expected);
|
|
1726
|
+
});
|
|
1720
1727
|
});
|
|
1721
1728
|
|
|
1722
1729
|
describe('edge cases', () => {
|
|
@@ -2736,6 +2743,14 @@ try {
|
|
|
2736
2743
|
expect(result).toBeWithNewline(expected);
|
|
2737
2744
|
});
|
|
2738
2745
|
|
|
2746
|
+
it('should preserve inline comments inside jsx expressions', async () => {
|
|
2747
|
+
const expected = `<div>{/* 'This is visible text' */}</div>
|
|
2748
|
+
<div>{/* <div>{'Card Component'}</div> */}</div>`;
|
|
2749
|
+
|
|
2750
|
+
const result = await format(expected, { singleQuote: true });
|
|
2751
|
+
expect(result).toBeWithNewline(expected);
|
|
2752
|
+
});
|
|
2753
|
+
|
|
2739
2754
|
it('correctly formats array of objects and keys as either literals or identifiers', async () => {
|
|
2740
2755
|
const input = `const tt = [
|
|
2741
2756
|
{
|
|
@@ -4004,6 +4019,27 @@ component Polygon() {
|
|
|
4004
4019
|
expect(result).toBeWithNewline(expected);
|
|
4005
4020
|
});
|
|
4006
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
|
+
|
|
4007
4043
|
it('should format JSXFragment with text and elements mixed', async () => {
|
|
4008
4044
|
const input = `component App() {
|
|
4009
4045
|
<tsx:react>
|