@tsrx/prettier-plugin 0.3.77 → 0.3.78
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 +6 -1
- package/src/index.test.js +28 -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.78",
|
|
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.26"
|
|
31
31
|
},
|
|
32
32
|
"files": [
|
|
33
33
|
"src/"
|
package/src/index.js
CHANGED
|
@@ -5870,7 +5870,12 @@ function printJSXElement(node, path, options, print) {
|
|
|
5870
5870
|
const openingElement = node.openingElement;
|
|
5871
5871
|
const closingElement = node.closingElement;
|
|
5872
5872
|
|
|
5873
|
-
|
|
5873
|
+
// Dynamic tags (`<{expr}>`) print the opening expression for both tags so
|
|
5874
|
+
// they stay textually identical; static names print as plain strings.
|
|
5875
|
+
const tagName =
|
|
5876
|
+
/** @type {any} */ (openingElement.name).type === 'JSXExpressionContainer'
|
|
5877
|
+
? ['{', path.call(print, 'openingElement', 'name', 'expression'), '}']
|
|
5878
|
+
: printJSXElementName(openingElement.name);
|
|
5874
5879
|
|
|
5875
5880
|
const isSelfClosing = openingElement.selfClosing;
|
|
5876
5881
|
const hasAttributes = openingElement.attributes && openingElement.attributes.length > 0;
|
package/src/index.test.js
CHANGED
|
@@ -74,6 +74,34 @@ describe('prettier-plugin', () => {
|
|
|
74
74
|
expect(result).toBeWithNewline(expected);
|
|
75
75
|
});
|
|
76
76
|
|
|
77
|
+
it('formats dynamic element tags', async () => {
|
|
78
|
+
const input = `function App(props){const Child='div';return <{Child} {...props} class="card"><span>Hello</span></{Child}>}`;
|
|
79
|
+
const expected = `function App(props) {
|
|
80
|
+
const Child = "div";
|
|
81
|
+
return <{Child} {...props} class="card">
|
|
82
|
+
<span>Hello</span>
|
|
83
|
+
</{Child}>;
|
|
84
|
+
}`;
|
|
85
|
+
|
|
86
|
+
const result = await format(input);
|
|
87
|
+
expect(result).toBeWithNewline(expected);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('formats dynamic element tag expressions', async () => {
|
|
91
|
+
const input = `function App(){return <><{registry.item}/><{items[0]}/><{'section'}/><{\`article\`}/></>;}`;
|
|
92
|
+
const expected = `function App() {
|
|
93
|
+
return <>
|
|
94
|
+
<{registry.item} />
|
|
95
|
+
<{items[0]} />
|
|
96
|
+
<{"section"} />
|
|
97
|
+
<{\`article\`} />
|
|
98
|
+
</>;
|
|
99
|
+
}`;
|
|
100
|
+
|
|
101
|
+
const result = await format(input);
|
|
102
|
+
expect(result).toBeWithNewline(expected);
|
|
103
|
+
});
|
|
104
|
+
|
|
77
105
|
it('formats a fragment code block with setup and template control flow', async () => {
|
|
78
106
|
const input = `function App(){return <>@{
|
|
79
107
|
const items=[1,2,3];
|