@@ -6,7 +6,7 @@ var find = require('property-information/find')
66var ns = require ( 'web-namespaces' )
77var s = require ( 'hastscript/svg' )
88var h = require ( 'hastscript' )
9- var count = require ( 'ccount ' )
9+ var vfileLocation = require ( 'vfile-location ' )
1010
1111module . exports = wrapper
1212
@@ -36,8 +36,7 @@ function wrapper(ast, options) {
3636 return transform ( ast , {
3737 schema : settings . space === 'svg' ? svg : html ,
3838 file : file ,
39- verbose : settings . verbose ,
40- location : false
39+ verbose : settings . verbose
4140 } )
4241}
4342
@@ -47,7 +46,7 @@ function transform(ast, config) {
4746 var fn = own . call ( map , ast . nodeName ) ? map [ ast . nodeName ] : element
4847 var children
4948 var node
50- var pos
49+ var position
5150
5251 if ( fn === element ) {
5352 config . schema = ast . namespaceURI === ns . svg ? svg : html
@@ -60,11 +59,11 @@ function transform(ast, config) {
6059 node = fn ( ast , children , config )
6160
6261 if ( ast . sourceCodeLocation && config . file ) {
63- pos = location ( node , ast . sourceCodeLocation , config )
62+ position = location ( node , ast . sourceCodeLocation , config )
6463
65- if ( pos ) {
64+ if ( position ) {
6665 config . location = true
67- node . position = pos
66+ node . position = position
6867 }
6968 }
7069
@@ -75,11 +74,10 @@ function transform(ast, config) {
7574
7675// Transform children.
7776function nodes ( children , config ) {
78- var length = children . length
7977 var index = - 1
8078 var result = [ ]
8179
82- while ( ++ index < length ) {
80+ while ( ++ index < children . length ) {
8381 result [ index ] = transform ( children [ index ] , config )
8482 }
8583
@@ -89,21 +87,20 @@ function nodes(children, config) {
8987// Transform a document.
9088// Stores `ast.quirksMode` in `node.data.quirksMode`.
9189function root ( ast , children , config ) {
92- var node = { type : 'root' , children : children , data : { } }
90+ var node = {
91+ type : 'root' ,
92+ children : children ,
93+ data : { quirksMode : ast . mode === 'quirks' || ast . mode === 'limited-quirks' }
94+ }
9395 var doc
94-
95- node . data . quirksMode = ast . mode === 'quirks' || ast . mode === 'limited-quirks'
96+ var location
9697
9798 if ( config . file && config . location ) {
9899 doc = String ( config . file )
99-
100+ location = vfileLocation ( doc )
100101 node . position = {
101- start : { line : 1 , column : 1 , offset : 0 } ,
102- end : {
103- line : count ( doc , '\n' ) + 1 ,
104- column : doc . length - doc . lastIndexOf ( '\n' ) ,
105- offset : doc . length
106- }
102+ start : location . toPoint ( 0 ) ,
103+ end : location . toPoint ( doc . length )
107104 }
108105 }
109106
0 commit comments