aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJackson Ray Hamilton2019-02-09 15:42:42 -0800
committerJackson Ray Hamilton2019-04-08 22:48:20 -0700
commit58c77f1f3e041be320a05efb818a0e2bb1583e84 (patch)
treee020d7c3c4aa7f2f763646ac658a48742219e309
parente1872f80f24ab650f416ff8705898f12c7ad2800 (diff)
downloademacs-58c77f1f3e041be320a05efb818a0e2bb1583e84.tar.gz
emacs-58c77f1f3e041be320a05efb818a0e2bb1583e84.zip
Add failing tests for JSX indentation bugs
* test/manual/indent/js-jsx.js: Add failing tests for all the js-mode and js2-mode JSX indentation bugs reported over the years that I could find. Some may be duplicates, so I have grouped similar reports together, for now; we’ll see for certain which distinct cases we need once we start actually implementing fixes. * test/manual/indent/js-jsx-quote.js: New file with a nasty test.
-rw-r--r--test/manual/indent/js-jsx-quote.js18
-rw-r--r--test/manual/indent/js-jsx.js183
2 files changed, 201 insertions, 0 deletions
diff --git a/test/manual/indent/js-jsx-quote.js b/test/manual/indent/js-jsx-quote.js
new file mode 100644
index 00000000000..4b71a656744
--- /dev/null
+++ b/test/manual/indent/js-jsx-quote.js
@@ -0,0 +1,18 @@
1// -*- mode: js-jsx; -*-
2
3// JSX text node values should be strings, but only JS string syntax
4// is considered, so quote marks delimit strings like normal, with
5// disastrous results (https://github.com/mooz/js2-mode/issues/409).
6function Bug() {
7 return <div>C'est Montréal</div>;
8}
9function Test(foo = /'/,
10 bar = 123) {}
11
12// This test is in a separate file because it can break other tests
13// when indenting the whole buffer (not sure why).
14
15// Local Variables:
16// indent-tabs-mode: nil
17// js-indent-level: 2
18// End:
diff --git a/test/manual/indent/js-jsx.js b/test/manual/indent/js-jsx.js
index 7401939d282..35ca4b275a6 100644
--- a/test/manual/indent/js-jsx.js
+++ b/test/manual/indent/js-jsx.js
@@ -70,6 +70,189 @@ return (
70 </div> 70 </div>
71); 71);
72 72
73// Indent void expressions (no need for contextual parens / commas)
74// (https://github.com/mooz/js2-mode/issues/140#issuecomment-166250016).
75<div className="class-name">
76 <h2>Title</h2>
77 {array.map(() => {
78 return <Element />;
79 })}
80 {message}
81</div>
82// Another example of above issue
83// (https://github.com/mooz/js2-mode/issues/490).
84<App>
85 <div>
86 {variable1}
87 <Component/>
88 </div>
89</App>
90
91// Comments and arrows can break indentation (Bug#24896 /
92// https://github.com/mooz/js2-mode/issues/389).
93const Component = props => (
94 <FatArrow a={e => c}
95 b={123}>
96 </FatArrow>
97);
98const Component = props => (
99 <NoFatArrow a={123}
100 b={123}>
101 </NoFatArrow>
102);
103const Component = props => ( // Parse this comment, please.
104 <FatArrow a={e => c}
105 b={123}>
106 </FatArrow>
107);
108const Component = props => ( // Parse this comment, please.
109 <NoFatArrow a={123}
110 b={123}>
111 </NoFatArrow>
112);
113// Another example of above issue (Bug#30225).
114class {
115 render() {
116 return (
117 <select style={{paddingRight: "10px"}}
118 onChange={e => this.setState({value: e.target.value})}
119 value={this.state.value}>
120 <option>Hi</option>
121 </select>
122 );
123 }
124}
125
126// JSX attributes of an arrow function’s expression body’s JSX
127// expression should be indented with respect to the JSX opening
128// element (Bug#26001 /
129// https://github.com/mooz/js2-mode/issues/389#issuecomment-271869380).
130class {
131 render() {
132 const messages = this.state.messages.map(
133 message => <Message key={message.id}
134 text={message.text}
135 mine={message.mine} />
136 ); return messages;
137 }
138 render() {
139 const messages = this.state.messages.map(message =>
140 <Message key={message.timestamp}
141 text={message.text}
142 mine={message.mine} />
143 ); return messages;
144 }
145}
146
147// Users expect tag closers to align with the tag’s start; this is the
148// style used in the React docs, so it should be the default.
149// - https://github.com/mooz/js2-mode/issues/389#issuecomment-390766873
150// - https://github.com/mooz/js2-mode/issues/482
151// - Bug#32158
152const foo = (props) => (
153 <div>
154 <input
155 cat={i => i}
156 />
157 <button
158 className="square"
159 >
160 {this.state.value}
161 </button>
162 </div>
163);
164
165// Embedded JSX in parens breaks indentation
166// (https://github.com/mooz/js2-mode/issues/411).
167let a = (
168 <div>
169 {condition && <Component/>}
170 {condition && <Component/>}
171 <div/>
172 </div>
173)
174let b = (
175 <div>
176 {condition && (<Component/>)}
177 <div/>
178 </div>
179)
180let c = (
181 <div>
182 {condition && (<Component/>)}
183 {condition && "something"}
184 </div>
185)
186let d = (
187 <div>
188 {(<Component/>)}
189 {condition && "something"}
190 </div>
191)
192// Another example of the above issue (Bug#27000).
193function testA() {
194 return (
195 <div>
196 <div> { ( <div/> ) } </div>
197 </div>
198 );
199}
200function testB() {
201 return (
202 <div>
203 <div> { <div/> } </div>
204 </div>
205 );
206}
207// Another example of the above issue
208// (https://github.com/mooz/js2-mode/issues/451).
209class Classy extends React.Component {
210 render () {
211 return (
212 <div>
213 <ul className="tocListRoot">
214 { this.state.list.map((item) => {
215 return (<div />)
216 })}
217 </ul>
218 </div>
219 )
220 }
221}
222
223// Self-closing tags should be indented properly
224// (https://github.com/mooz/js2-mode/issues/459).
225export default ({ stars }) => (
226 <div className='overlay__container'>
227 <div className='overlay__header overlay--text'>
228 Congratulations!
229 </div>
230 <div className='overlay__reward'>
231 <Icon {...createIconProps(stars > 0)} size='large' />
232 <div className='overlay__reward__bottom'>
233 <Icon {...createIconProps(stars > 1)} size='small' />
234 <Icon {...createIconProps(stars > 2)} size='small' />
235 </div>
236 </div>
237 <div className='overlay__description overlay--text'>
238 You have created <large>1</large> reminder
239 </div>
240 </div>
241)
242
243// JS expressions should not break indentation
244// (https://github.com/mooz/js2-mode/issues/462).
245return (
246 <Router>
247 <Bar>
248 <Route exact path="/foo" render={() => (
249 <div>nothing</div>
250 )} />
251 <Route exact path="/bar" />
252 </Bar>
253 </Router>
254)
255
73// Local Variables: 256// Local Variables:
74// indent-tabs-mode: nil 257// indent-tabs-mode: nil
75// js-indent-level: 2 258// js-indent-level: 2