@@ -6,7 +6,7 @@ var find = require('property-information/find')
6
6
var ns = require ( 'web-namespaces' )
7
7
var s = require ( 'hastscript/svg' )
8
8
var h = require ( 'hastscript' )
9
- var count = require ( 'ccount ' )
9
+ var vfileLocation = require ( 'vfile-location ' )
10
10
11
11
module . exports = wrapper
12
12
@@ -36,8 +36,7 @@ function wrapper(ast, options) {
36
36
return transform ( ast , {
37
37
schema : settings . space === 'svg' ? svg : html ,
38
38
file : file ,
39
- verbose : settings . verbose ,
40
- location : false
39
+ verbose : settings . verbose
41
40
} )
42
41
}
43
42
@@ -47,7 +46,7 @@ function transform(ast, config) {
47
46
var fn = own . call ( map , ast . nodeName ) ? map [ ast . nodeName ] : element
48
47
var children
49
48
var node
50
- var pos
49
+ var position
51
50
52
51
if ( fn === element ) {
53
52
config . schema = ast . namespaceURI === ns . svg ? svg : html
@@ -60,11 +59,11 @@ function transform(ast, config) {
60
59
node = fn ( ast , children , config )
61
60
62
61
if ( ast . sourceCodeLocation && config . file ) {
63
- pos = location ( node , ast . sourceCodeLocation , config )
62
+ position = location ( node , ast . sourceCodeLocation , config )
64
63
65
- if ( pos ) {
64
+ if ( position ) {
66
65
config . location = true
67
- node . position = pos
66
+ node . position = position
68
67
}
69
68
}
70
69
@@ -75,11 +74,10 @@ function transform(ast, config) {
75
74
76
75
// Transform children.
77
76
function nodes ( children , config ) {
78
- var length = children . length
79
77
var index = - 1
80
78
var result = [ ]
81
79
82
- while ( ++ index < length ) {
80
+ while ( ++ index < children . length ) {
83
81
result [ index ] = transform ( children [ index ] , config )
84
82
}
85
83
@@ -89,21 +87,20 @@ function nodes(children, config) {
89
87
// Transform a document.
90
88
// Stores `ast.quirksMode` in `node.data.quirksMode`.
91
89
function 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
+ }
93
95
var doc
94
-
95
- node . data . quirksMode = ast . mode === 'quirks' || ast . mode === 'limited-quirks'
96
+ var location
96
97
97
98
if ( config . file && config . location ) {
98
99
doc = String ( config . file )
99
-
100
+ location = vfileLocation ( doc )
100
101
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 )
107
104
}
108
105
}
109
106
0 commit comments