3
3
* @typedef {import('estree-jsx').JSXClosingElement } JSXClosingElement
4
4
* @typedef {import('estree-jsx').JSXClosingFragment } JSXClosingFragment
5
5
* @typedef {import('estree-jsx').JSXElement } JSXElement
6
- * @typedef {import('estree-jsx').JSXEmptyExpression } JSXEmptyExpression
7
6
* @typedef {import('estree-jsx').JSXExpressionContainer } JSXExpressionContainer
8
7
* @typedef {import('estree-jsx').JSXFragment } JSXFragment
9
8
* @typedef {import('estree-jsx').JSXIdentifier } JSXIdentifier
13
12
* @typedef {import('estree-jsx').JSXOpeningFragment } JSXOpeningFragment
14
13
* @typedef {import('estree-jsx').JSXSpreadAttribute } JSXSpreadAttribute
15
14
* @typedef {import('estree-jsx').JSXText } JSXText
16
- * @typedef {import('./types.js').Handler } Handler
17
15
* @typedef {import('./types.js').Generator } Generator
18
16
* @typedef {import('./types.js').State } State
19
17
*/
@@ -41,9 +39,13 @@ export const jsx = {
41
39
* `attr={1}`
42
40
*
43
41
* @this {Generator}
42
+ * `astring` generator.
44
43
* @param {JSXAttribute } node
44
+ * Node to serialize.
45
45
* @param {State } state
46
+ * Info passed around.
46
47
* @returns {void }
48
+ * Nothing.
47
49
*/
48
50
function JSXAttribute ( node , state ) {
49
51
this [ node . name . type ] ( node . name , state )
@@ -67,9 +69,13 @@ function JSXAttribute(node, state) {
67
69
* `</div>`
68
70
*
69
71
* @this {Generator}
72
+ * `astring` generator.
70
73
* @param {JSXClosingElement } node
74
+ * Node to serialize.
71
75
* @param {State } state
76
+ * Info passed around.
72
77
* @returns {void }
78
+ * Nothing.
73
79
*/
74
80
function JSXClosingElement ( node , state ) {
75
81
state . write ( '</' )
@@ -81,9 +87,13 @@ function JSXClosingElement(node, state) {
81
87
* `</>`
82
88
*
83
89
* @this {Generator}
90
+ * `astring` generator.
84
91
* @param {JSXClosingFragment } node
92
+ * Node to serialize.
85
93
* @param {State } state
94
+ * Info passed around.
86
95
* @returns {void }
96
+ * Nothing.
87
97
*/
88
98
function JSXClosingFragment ( node , state ) {
89
99
state . write ( '</>' , node )
@@ -94,9 +104,13 @@ function JSXClosingFragment(node, state) {
94
104
* `<div></div>`
95
105
*
96
106
* @this {Generator}
107
+ * `astring` generator.
97
108
* @param {JSXElement } node
109
+ * Node to serialize.
98
110
* @param {State } state
111
+ * Info passed around.
99
112
* @returns {void }
113
+ * Nothing.
100
114
*/
101
115
function JSXElement ( node , state ) {
102
116
let index = - 1
@@ -126,17 +140,23 @@ function JSXElement(node, state) {
126
140
* `{}` (always in a `JSXExpressionContainer`, which does the curlies)
127
141
*
128
142
* @this {Generator}
143
+ * `astring` generator.
129
144
* @returns {void }
145
+ * Nothing.
130
146
*/
131
147
function JSXEmptyExpression ( ) { }
132
148
133
149
/**
134
150
* `{expression}`
135
151
*
136
152
* @this {Generator}
153
+ * `astring` generator.
137
154
* @param {JSXExpressionContainer } node
155
+ * Node to serialize.
138
156
* @param {State } state
157
+ * Info passed around.
139
158
* @returns {void }
159
+ * Nothing.
140
160
*/
141
161
function JSXExpressionContainer ( node , state ) {
142
162
state . write ( '{' )
@@ -148,9 +168,13 @@ function JSXExpressionContainer(node, state) {
148
168
* `<></>`
149
169
*
150
170
* @this {Generator}
171
+ * `astring` generator.
151
172
* @param {JSXFragment } node
173
+ * Node to serialize.
152
174
* @param {State } state
175
+ * Info passed around.
153
176
* @returns {void }
177
+ * Nothing.
154
178
*/
155
179
function JSXFragment ( node , state ) {
156
180
let index = - 1
@@ -178,9 +202,13 @@ function JSXFragment(node, state) {
178
202
* `div`
179
203
*
180
204
* @this {Generator}
205
+ * `astring` generator.
181
206
* @param {JSXIdentifier } node
207
+ * Node to serialize.
182
208
* @param {State } state
209
+ * Info passed around.
183
210
* @returns {void }
211
+ * Nothing.
184
212
*/
185
213
function JSXIdentifier ( node , state ) {
186
214
state . write ( node . name , node )
@@ -190,9 +218,13 @@ function JSXIdentifier(node, state) {
190
218
* `member.expression`
191
219
*
192
220
* @this {Generator}
221
+ * `astring` generator.
193
222
* @param {JSXMemberExpression } node
223
+ * Node to serialize.
194
224
* @param {State } state
225
+ * Info passed around.
195
226
* @returns {void }
227
+ * Nothing.
196
228
*/
197
229
function JSXMemberExpression ( node , state ) {
198
230
this [ node . object . type ] ( node . object , state )
@@ -204,9 +236,13 @@ function JSXMemberExpression(node, state) {
204
236
* `ns:name`
205
237
*
206
238
* @this {Generator}
239
+ * `astring` generator.
207
240
* @param {JSXNamespacedName } node
241
+ * Node to serialize.
208
242
* @param {State } state
243
+ * Info passed around.
209
244
* @returns {void }
245
+ * Nothing.
210
246
*/
211
247
function JSXNamespacedName ( node , state ) {
212
248
this [ node . namespace . type ] ( node . namespace , state )
@@ -218,9 +254,13 @@ function JSXNamespacedName(node, state) {
218
254
* `<div>`
219
255
*
220
256
* @this {Generator}
257
+ * `astring` generator.
221
258
* @param {JSXOpeningElement } node
259
+ * Node to serialize.
222
260
* @param {State } state
261
+ * Info passed around.
223
262
* @returns {void }
263
+ * Nothing.
224
264
*/
225
265
function JSXOpeningElement ( node , state ) {
226
266
let index = - 1
@@ -242,9 +282,13 @@ function JSXOpeningElement(node, state) {
242
282
* `<>`
243
283
*
244
284
* @this {Generator}
285
+ * `astring` generator.
245
286
* @param {JSXOpeningFragment } node
287
+ * Node to serialize.
246
288
* @param {State } state
289
+ * Info passed around.
247
290
* @returns {void }
291
+ * Nothing.
248
292
*/
249
293
function JSXOpeningFragment ( node , state ) {
250
294
state . write ( '<>' , node )
@@ -254,9 +298,13 @@ function JSXOpeningFragment(node, state) {
254
298
* `{...argument}`
255
299
*
256
300
* @this {Generator}
301
+ * `astring` generator.
257
302
* @param {JSXSpreadAttribute } node
303
+ * Node to serialize.
258
304
* @param {State } state
305
+ * Info passed around.
259
306
* @returns {void }
307
+ * Nothing.
260
308
*/
261
309
function JSXSpreadAttribute ( node , state ) {
262
310
state . write ( '{' )
@@ -269,9 +317,13 @@ function JSXSpreadAttribute(node, state) {
269
317
* `!`
270
318
*
271
319
* @this {Generator}
320
+ * `astring` generator.
272
321
* @param {JSXText } node
322
+ * Node to serialize.
273
323
* @param {State } state
324
+ * Info passed around.
274
325
* @returns {void }
326
+ * Nothing.
275
327
*/
276
328
function JSXText ( node , state ) {
277
329
state . write (
@@ -290,6 +342,7 @@ function JSXText(node, state) {
290
342
291
343
/**
292
344
* Make sure that character references don’t pop up.
345
+ *
293
346
* For example, the text `©` should stay that way, and not turn into `©`.
294
347
* We could encode all `&` (easy but verbose) or look for actual valid
295
348
* references (complex but cleanest output).
@@ -298,7 +351,9 @@ function JSXText(node, state) {
298
351
* are for the named references.
299
352
*
300
353
* @param {string } value
354
+ * Value to encode.
301
355
* @returns {string }
356
+ * Encoded value.
302
357
*/
303
358
function encodeJsx ( value ) {
304
359
return value . replace ( / & (? = [ # a - z ] ) / gi, '&' )
0 commit comments