1- 'use strict' ;
1+ 'use strict'
22
3- var information = require ( 'property-information' ) ;
4- var camelcase = require ( 'camelcase' ) ;
5- var h = require ( 'hastscript' ) ;
6- var xtend = require ( 'xtend' ) ;
7- var count = require ( 'ccount' ) ;
3+ var information = require ( 'property-information' )
4+ var camelcase = require ( 'camelcase' )
5+ var h = require ( 'hastscript' )
6+ var xtend = require ( 'xtend' )
7+ var count = require ( 'ccount' )
88
9- module . exports = wrapper ;
9+ module . exports = wrapper
1010
11- var own = { } . hasOwnProperty ;
11+ var own = { } . hasOwnProperty
1212
1313/* Handlers. */
1414var map = {
@@ -17,83 +17,87 @@ var map = {
1717 '#text' : text ,
1818 '#comment' : comment ,
1919 '#documentType' : doctype
20- } ;
20+ }
2121
2222/* Wrapper to normalise options. */
2323function wrapper ( ast , options ) {
24- var settings = options || { } ;
25- var file ;
24+ var settings = options || { }
25+ var file
2626
2727 if ( settings . messages ) {
28- file = settings ;
29- settings = { } ;
28+ file = settings
29+ settings = { }
3030 } else {
31- file = settings . file ;
31+ file = settings . file
3232 }
3333
3434 return transform ( ast , {
3535 file : file ,
3636 verbose : settings . verbose ,
3737 location : false
38- } ) ;
38+ } )
3939}
4040
4141/* Transform a node. */
4242function transform ( ast , config ) {
43- var fn = own . call ( map , ast . nodeName ) ? map [ ast . nodeName ] : element ;
44- var children ;
45- var node ;
46- var pos ;
43+ var fn = own . call ( map , ast . nodeName ) ? map [ ast . nodeName ] : element
44+ var children
45+ var node
46+ var pos
4747
4848 if ( ast . childNodes ) {
49- children = nodes ( ast . childNodes , config ) ;
49+ children = nodes ( ast . childNodes , config )
5050 }
5151
52- node = fn ( ast , children , config ) ;
52+ node = fn ( ast , children , config )
5353
5454 if ( ast . sourceCodeLocation && config . file ) {
55- pos = location ( node , ast . sourceCodeLocation , config . verbose ) ;
55+ pos = location ( node , ast . sourceCodeLocation , config . verbose )
5656
5757 if ( pos ) {
58- config . location = true ;
59- node . position = pos ;
58+ config . location = true
59+ node . position = pos
6060 }
6161 }
6262
63- return node ;
63+ return node
6464}
6565
6666/* Transform children. */
6767function nodes ( children , config ) {
68- var length = children . length ;
69- var index = - 1 ;
70- var result = [ ] ;
68+ var length = children . length
69+ var index = - 1
70+ var result = [ ]
7171
7272 while ( ++ index < length ) {
73- result [ index ] = transform ( children [ index ] , config ) ;
73+ result [ index ] = transform ( children [ index ] , config )
7474 }
7575
76- return result ;
76+ return result
7777}
7878
7979/* Transform a document.
8080 * Stores `ast.quirksMode` in `node.data.quirksMode`. */
8181function root ( ast , children , config ) {
82- var node = { type : 'root' , children : children , data : { } } ;
83- var doc ;
82+ var node = { type : 'root' , children : children , data : { } }
83+ var doc
8484
85- node . data . quirksMode = ast . mode === 'quirks' || ast . mode === 'limited-quirks' ;
85+ node . data . quirksMode = ast . mode === 'quirks' || ast . mode === 'limited-quirks'
8686
8787 if ( config . file && config . location ) {
88- doc = String ( config . file ) ;
88+ doc = String ( config . file )
8989
9090 node . position = {
9191 start : { line : 1 , column : 1 , offset : 0 } ,
92- end : { line : count ( doc , '\n' ) + 1 , column : doc . length - doc . lastIndexOf ( '\n' ) , offset : doc . length }
93- } ;
92+ end : {
93+ line : count ( doc , '\n' ) + 1 ,
94+ column : doc . length - doc . lastIndexOf ( '\n' ) ,
95+ offset : doc . length
96+ }
97+ }
9498 }
9599
96- return node ;
100+ return node
97101}
98102
99103/* Transform a doctype. */
@@ -103,77 +107,82 @@ function doctype(ast) {
103107 name : ast . name || '' ,
104108 public : ast . publicId || null ,
105109 system : ast . systemId || null
106- } ;
110+ }
107111}
108112
109113/* Transform a text. */
110114function text ( ast ) {
111- return { type : 'text' , value : ast . value } ;
115+ return { type : 'text' , value : ast . value }
112116}
113117
114118/* Transform a comment. */
115119function comment ( ast ) {
116- return { type : 'comment' , value : ast . data } ;
120+ return { type : 'comment' , value : ast . data }
117121}
118122
119123/* Transform an element. */
120124function element ( ast , children , config ) {
121- var props = { } ;
122- var values = ast . attrs ;
123- var length = values . length ;
124- var index = - 1 ;
125- var attr ;
126- var node ;
127- var pos ;
128- var start ;
129- var end ;
125+ var props = { }
126+ var values = ast . attrs
127+ var length = values . length
128+ var index = - 1
129+ var attr
130+ var node
131+ var pos
132+ var start
133+ var end
130134
131135 while ( ++ index < length ) {
132- attr = values [ index ] ;
133- props [ ( attr . prefix ? attr . prefix + ':' : '' ) + attr . name ] = attr . value ;
136+ attr = values [ index ]
137+ props [ ( attr . prefix ? attr . prefix + ':' : '' ) + attr . name ] = attr . value
134138 }
135139
136- node = h ( ast . tagName , props , children ) ;
140+ node = h ( ast . tagName , props , children )
137141
138142 if ( ast . nodeName === 'template' && 'content' in ast ) {
139- pos = ast . sourceCodeLocation ;
140- start = pos && pos . startTag && position ( pos . startTag ) . end ;
141- end = pos && pos . endTag && position ( pos . endTag ) . start ;
143+ pos = ast . sourceCodeLocation
144+ start = pos && pos . startTag && position ( pos . startTag ) . end
145+ end = pos && pos . endTag && position ( pos . endTag ) . start
142146
143- node . content = transform ( ast . content , config ) ;
147+ node . content = transform ( ast . content , config )
144148
145149 if ( ( start || end ) && config . file ) {
146- node . content . position = { start : start , end : end } ;
150+ node . content . position = { start : start , end : end }
147151 }
148152 }
149153
150- return node ;
154+ return node
151155}
152156
153157/* Create clean positional information. */
154158function location ( node , location , verbose ) {
155- var pos = position ( location ) ;
156- var reference ;
157- var values ;
158- var props ;
159- var prop ;
160- var name ;
159+ var pos = position ( location )
160+ var reference
161+ var values
162+ var props
163+ var prop
164+ var name
161165
162166 if ( node . type === 'element' ) {
163- reference = node . children [ node . children . length - 1 ] ;
167+ reference = node . children [ node . children . length - 1 ]
164168
165169 /* Unclosed with children (upstream: https://github.com/inikulin/parse5/issues/109) */
166- if ( ! location . endTag && reference && reference . position && reference . position . end ) {
167- pos . end = xtend ( reference . position . end ) ;
170+ if (
171+ ! location . endTag &&
172+ reference &&
173+ reference . position &&
174+ reference . position . end
175+ ) {
176+ pos . end = xtend ( reference . position . end )
168177 }
169178
170179 if ( verbose ) {
171- values = location . attrs ;
172- props = { } ;
180+ values = location . attrs
181+ props = { }
173182
174183 for ( prop in values ) {
175- name = ( information ( prop ) || { } ) . propertyName || camelcase ( prop ) ;
176- props [ name ] = position ( values [ prop ] ) ;
184+ name = ( information ( prop ) || { } ) . propertyName || camelcase ( prop )
185+ props [ name ] = position ( values [ prop ] )
177186 }
178187
179188 node . data = {
@@ -182,19 +191,27 @@ function location(node, location, verbose) {
182191 closing : location . endTag ? position ( location . endTag ) : null ,
183192 properties : props
184193 }
185- } ;
194+ }
186195 }
187196 }
188197
189- return pos ;
198+ return pos
190199}
191200
192201function position ( loc ) {
193- var start = point ( { line : loc . startLine , column : loc . startCol , offset : loc . startOffset } ) ;
194- var end = point ( { line : loc . endLine , column : loc . endCol , offset : loc . endOffset } ) ;
195- return start || end ? { start : start , end : end } : null ;
202+ var start = point ( {
203+ line : loc . startLine ,
204+ column : loc . startCol ,
205+ offset : loc . startOffset
206+ } )
207+ var end = point ( {
208+ line : loc . endLine ,
209+ column : loc . endCol ,
210+ offset : loc . endOffset
211+ } )
212+ return start || end ? { start : start , end : end } : null
196213}
197214
198215function point ( point ) {
199- return point . line && point . column ? point : null ;
216+ return point . line && point . column ? point : null
200217}
0 commit comments