@tsrx/prettier-plugin 0.3.79 → 0.3.81
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 +31 -3
- package/src/index.test.js +24 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsrx/prettier-plugin",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.81",
|
|
4
4
|
"description": "Ripple plugin for Prettier",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "src/index.js",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"prettier": "^3.8.3"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@tsrx/core": "0.1.
|
|
30
|
+
"@tsrx/core": "0.1.29"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"src/"
|
package/src/index.js
CHANGED
|
@@ -55,11 +55,11 @@ export const parsers = {
|
|
|
55
55
|
astFormat: 'ripple-ast',
|
|
56
56
|
/**
|
|
57
57
|
* @param {string} text
|
|
58
|
-
* @param {ParserOptions<AST.Node | AST.CSS.StyleSheet>}
|
|
58
|
+
* @param {ParserOptions<AST.Node | AST.CSS.StyleSheet>} options
|
|
59
59
|
* @returns {AST.Program}
|
|
60
60
|
*/
|
|
61
|
-
parse(text,
|
|
62
|
-
return parseModule(text);
|
|
61
|
+
parse(text, options) {
|
|
62
|
+
return parseModule(text, options.filepath || 'PrettierPlugin.tsrx');
|
|
63
63
|
},
|
|
64
64
|
|
|
65
65
|
/**
|
|
@@ -5912,6 +5912,7 @@ function printJSXElement(node, path, options, print) {
|
|
|
5912
5912
|
'{',
|
|
5913
5913
|
path.call(print, 'children', i, 'expression'),
|
|
5914
5914
|
'}',
|
|
5915
|
+
...printTemplateChildTrailingComments(child),
|
|
5915
5916
|
]);
|
|
5916
5917
|
childNodes.push(child);
|
|
5917
5918
|
} else {
|
|
@@ -6065,6 +6066,7 @@ function printJSXFragment(node, path, options, print) {
|
|
|
6065
6066
|
'{',
|
|
6066
6067
|
path.call(print, 'children', i, 'expression'),
|
|
6067
6068
|
'}',
|
|
6069
|
+
...printTemplateChildTrailingComments(child),
|
|
6068
6070
|
]);
|
|
6069
6071
|
childNodes.push(child);
|
|
6070
6072
|
} else {
|
|
@@ -6203,6 +6205,32 @@ function printTemplateChildLeadingComments(child) {
|
|
|
6203
6205
|
return parts;
|
|
6204
6206
|
}
|
|
6205
6207
|
|
|
6208
|
+
/**
|
|
6209
|
+
* Build doc parts for a template child's trailing comments (kept on the same
|
|
6210
|
+
* line as the child). Used for `{expr}` children, whose `{ … }` form is printed
|
|
6211
|
+
* inline by the JSX printers and so would otherwise skip the node's attached
|
|
6212
|
+
* trailing comments.
|
|
6213
|
+
* @param {AST.Node & AST.NodeWithMaybeComments} child
|
|
6214
|
+
* @returns {Doc[]}
|
|
6215
|
+
*/
|
|
6216
|
+
function printTemplateChildTrailingComments(child) {
|
|
6217
|
+
const comments = child.trailingComments;
|
|
6218
|
+
if (!comments || comments.length === 0) {
|
|
6219
|
+
return [];
|
|
6220
|
+
}
|
|
6221
|
+
/** @type {Doc[]} */
|
|
6222
|
+
const parts = [];
|
|
6223
|
+
for (const comment of comments) {
|
|
6224
|
+
if (comment.type === 'Line') {
|
|
6225
|
+
parts.push(lineSuffix([' ', '//' + comment.value]));
|
|
6226
|
+
parts.push(breakParent);
|
|
6227
|
+
} else if (comment.type === 'Block') {
|
|
6228
|
+
parts.push(' /*' + comment.value + '*/');
|
|
6229
|
+
}
|
|
6230
|
+
}
|
|
6231
|
+
return parts;
|
|
6232
|
+
}
|
|
6233
|
+
|
|
6206
6234
|
/**
|
|
6207
6235
|
* Collect and print the comments that belong to an element/fragment body:
|
|
6208
6236
|
* trailing comments after the last child (attached by the parser to the closing
|
package/src/index.test.js
CHANGED
|
@@ -2851,6 +2851,30 @@ function test() {
|
|
|
2851
2851
|
expect(result).toBeWithNewline(expected);
|
|
2852
2852
|
});
|
|
2853
2853
|
|
|
2854
|
+
it('should keep a trailing line comment after an expression container child', async () => {
|
|
2855
|
+
const expected = `function App() @{
|
|
2856
|
+
<>
|
|
2857
|
+
{q} // hey
|
|
2858
|
+
// hello
|
|
2859
|
+
</>
|
|
2860
|
+
}`;
|
|
2861
|
+
|
|
2862
|
+
const result = await format(expected, { singleQuote: true });
|
|
2863
|
+
expect(result).toBeWithNewline(expected);
|
|
2864
|
+
});
|
|
2865
|
+
|
|
2866
|
+
it('should keep a trailing block comment after an expression container child', async () => {
|
|
2867
|
+
const expected = `function App() {
|
|
2868
|
+
<div>
|
|
2869
|
+
{x} /* note */
|
|
2870
|
+
<span>{'tail'}</span>
|
|
2871
|
+
</div>
|
|
2872
|
+
}`;
|
|
2873
|
+
|
|
2874
|
+
const result = await format(expected, { singleQuote: true });
|
|
2875
|
+
expect(result).toBeWithNewline(expected);
|
|
2876
|
+
});
|
|
2877
|
+
|
|
2854
2878
|
it('should preserve trailing comments in function parameters', async () => {
|
|
2855
2879
|
const expected = `function test(
|
|
2856
2880
|
// comment in params
|