1- 'use strict'
2-
3- module . exports = buildJsx
4-
5- var walk = require ( 'estree-walker' ) . walk
6- var isIdentifierName = require ( 'estree-util-is-identifier-name' ) . name
1+ import { walk } from 'estree-walker'
2+ import { name as isIdentifierName } from 'estree-util-is-identifier-name'
73
84var regex = / @ ( j s x | j s x F r a g | j s x I m p o r t S o u r c e | j s x R u n t i m e ) \s + ( \S + ) / g
95
10- function buildJsx ( tree , options ) {
6+ export function buildJsx ( tree , options ) {
117 var settings = options || { }
128 var automatic = settings . runtime === 'automatic'
139 var annotations = { }
1410 var imports = { }
1511
16- walk ( tree , { enter : enter , leave : leave } )
12+ walk ( tree , { enter, leave} )
1713
1814 return tree
1915
@@ -109,10 +105,10 @@ function buildJsx(tree, options) {
109105 } )
110106 }
111107
112- if ( specifiers . length ) {
108+ if ( specifiers . length > 0 ) {
113109 node . body . unshift ( {
114110 type : 'ImportDeclaration' ,
115- specifiers : specifiers ,
111+ specifiers,
116112 source : {
117113 type : 'Literal' ,
118114 value :
@@ -184,7 +180,7 @@ function buildJsx(tree, options) {
184180 // in them and what’s spread in.
185181 while ( ++ index < attributes . length ) {
186182 if ( attributes [ index ] . type === 'JSXSpreadAttribute' ) {
187- if ( fields . length ) {
183+ if ( fields . length > 0 ) {
188184 objects . push ( { type : 'ObjectExpression' , properties : fields } )
189185 fields = [ ]
190186 }
@@ -218,7 +214,7 @@ function buildJsx(tree, options) {
218214 )
219215 }
220216
221- if ( automatic && children . length ) {
217+ if ( automatic && children . length > 0 ) {
222218 fields . push ( {
223219 type : 'Property' ,
224220 key : { type : 'Identifier' , name : 'children' } ,
@@ -232,7 +228,7 @@ function buildJsx(tree, options) {
232228 parameters = children
233229 }
234230
235- if ( fields . length ) {
231+ if ( fields . length > 0 ) {
236232 objects . push ( { type : 'ObjectExpression' , properties : fields } )
237233 }
238234
@@ -247,7 +243,7 @@ function buildJsx(tree, options) {
247243 callee : toMemberExpression ( 'Object.assign' ) ,
248244 arguments : objects
249245 }
250- } else if ( objects . length ) {
246+ } else if ( objects . length > 0 ) {
251247 props = objects [ 0 ]
252248 }
253249
@@ -269,7 +265,7 @@ function buildJsx(tree, options) {
269265 // Classic.
270266 else {
271267 // There are props or children.
272- if ( props || parameters . length ) {
268+ if ( props || parameters . length > 0 ) {
273269 parameters . unshift ( props || { type : 'Literal' , value : null } )
274270 }
275271
@@ -281,11 +277,7 @@ function buildJsx(tree, options) {
281277 parameters . unshift ( name )
282278
283279 this . replace (
284- create ( node , {
285- type : 'CallExpression' ,
286- callee : callee ,
287- arguments : parameters
288- } )
280+ create ( node , { type : 'CallExpression' , callee, arguments : parameters } )
289281 )
290282 }
291283}
@@ -312,7 +304,7 @@ function toProperty(node) {
312304 return create ( node , {
313305 type : 'Property' ,
314306 key : toIdentifier ( node . name ) ,
315- value : value ,
307+ value,
316308 kind : 'init'
317309 } )
318310}
0 commit comments