@ripple-ts/prettier-plugin 0.2.158 → 0.2.159
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 +39 -0
- package/src/index.test.js +26 -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.159",
|
|
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.159"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {},
|
|
31
31
|
"files": [
|
package/src/index.js
CHANGED
|
@@ -3646,6 +3646,45 @@ function printProperty(node, path, options, print) {
|
|
|
3646
3646
|
|
|
3647
3647
|
const parts = [];
|
|
3648
3648
|
|
|
3649
|
+
// Handle getter/setter methods
|
|
3650
|
+
if (node.kind === 'get' || node.kind === 'set') {
|
|
3651
|
+
const methodParts = [];
|
|
3652
|
+
const funcValue = node.value;
|
|
3653
|
+
|
|
3654
|
+
// Add get/set keyword
|
|
3655
|
+
methodParts.push(node.kind, ' ');
|
|
3656
|
+
|
|
3657
|
+
// Print key (with computed property brackets if needed)
|
|
3658
|
+
if (node.computed) {
|
|
3659
|
+
methodParts.push('[', path.call(print, 'key'), ']');
|
|
3660
|
+
} else if (node.key.type === 'Literal' && typeof node.key.value === 'string') {
|
|
3661
|
+
const key = node.key.value;
|
|
3662
|
+
const isValidIdentifier = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key);
|
|
3663
|
+
if (isValidIdentifier) {
|
|
3664
|
+
methodParts.push(key);
|
|
3665
|
+
} else {
|
|
3666
|
+
methodParts.push(formatStringLiteral(key, options));
|
|
3667
|
+
}
|
|
3668
|
+
} else {
|
|
3669
|
+
methodParts.push(path.call(print, 'key'));
|
|
3670
|
+
}
|
|
3671
|
+
|
|
3672
|
+
// Print parameters by calling into the value path
|
|
3673
|
+
const paramsPart = path.call(
|
|
3674
|
+
(valuePath) => printFunctionParameters(valuePath, options, print),
|
|
3675
|
+
'value',
|
|
3676
|
+
);
|
|
3677
|
+
methodParts.push(group(paramsPart));
|
|
3678
|
+
|
|
3679
|
+
// Handle return type annotation
|
|
3680
|
+
if (funcValue.returnType) {
|
|
3681
|
+
methodParts.push(': ', path.call(print, 'value', 'returnType'));
|
|
3682
|
+
}
|
|
3683
|
+
|
|
3684
|
+
methodParts.push(' ', path.call(print, 'value', 'body'));
|
|
3685
|
+
return concat(methodParts);
|
|
3686
|
+
}
|
|
3687
|
+
|
|
3649
3688
|
// Handle method shorthand: increment() {} instead of increment: function() {}
|
|
3650
3689
|
if (node.method && node.value.type === 'FunctionExpression') {
|
|
3651
3690
|
const methodParts = [];
|
package/src/index.test.js
CHANGED
|
@@ -3889,5 +3889,31 @@ component App() {
|
|
|
3889
3889
|
expect(result).toBeWithNewline(expected);
|
|
3890
3890
|
});
|
|
3891
3891
|
});
|
|
3892
|
+
|
|
3893
|
+
describe('object getters and setters', () => {
|
|
3894
|
+
it('should preserve get and set keywords in object methods', async () => {
|
|
3895
|
+
const input = `const foo = {
|
|
3896
|
+
get bar() {
|
|
3897
|
+
return 0
|
|
3898
|
+
},
|
|
3899
|
+
|
|
3900
|
+
set baz(arg: 0) {
|
|
3901
|
+
//
|
|
3902
|
+
}
|
|
3903
|
+
}`;
|
|
3904
|
+
const expected = `const foo = {
|
|
3905
|
+
get bar() {
|
|
3906
|
+
return 0;
|
|
3907
|
+
},
|
|
3908
|
+
|
|
3909
|
+
set baz(arg: 0) {
|
|
3910
|
+
//
|
|
3911
|
+
},
|
|
3912
|
+
};`;
|
|
3913
|
+
|
|
3914
|
+
const result = await format(input);
|
|
3915
|
+
expect(result).toBeWithNewline(expected);
|
|
3916
|
+
});
|
|
3917
|
+
});
|
|
3892
3918
|
});
|
|
3893
3919
|
});
|