11'use strict'
22
3- var information = require ( 'property-information' )
4- var camelcase = require ( 'camelcase' )
3+ var html = require ( 'property-information/html' )
4+ var svg = require ( 'property-information/svg' )
5+ var find = require ( 'property-information/find' )
56var h = require ( 'hastscript' )
67var xtend = require ( 'xtend' )
78var count = require ( 'ccount' )
@@ -32,6 +33,7 @@ function wrapper(ast, options) {
3233 }
3334
3435 return transform ( ast , {
36+ schema : settings . space === 'svg' ? svg : html ,
3537 file : file ,
3638 verbose : settings . verbose ,
3739 location : false
@@ -40,26 +42,33 @@ function wrapper(ast, options) {
4042
4143/* Transform a node. */
4244function transform ( ast , config ) {
45+ var schema = config . schema
4346 var fn = own . call ( map , ast . nodeName ) ? map [ ast . nodeName ] : element
4447 var children
4548 var node
4649 var pos
4750
51+ if ( fn === element && schema . space === 'html' && ast . nodeName === 'svg' ) {
52+ config . schema = svg
53+ }
54+
4855 if ( ast . childNodes ) {
4956 children = nodes ( ast . childNodes , config )
5057 }
5158
5259 node = fn ( ast , children , config )
5360
5461 if ( ast . sourceCodeLocation && config . file ) {
55- pos = location ( node , ast . sourceCodeLocation , config . verbose )
62+ pos = location ( node , ast . sourceCodeLocation , config )
5663
5764 if ( pos ) {
5865 config . location = true
5966 node . position = pos
6067 }
6168 }
6269
70+ config . schema = schema
71+
6372 return node
6473}
6574
@@ -122,24 +131,27 @@ function comment(ast) {
122131
123132/* Transform an element. */
124133function element ( ast , children , config ) {
134+ var name = ast . tagName
135+ var attributes = ast . attrs
136+ var length = attributes . length
125137 var props = { }
126- var values = ast . attrs
127- var length = values . length
128138 var index = - 1
129- var attr
139+ var attribute
140+ var prop
130141 var node
131142 var pos
132143 var start
133144 var end
134145
135146 while ( ++ index < length ) {
136- attr = values [ index ]
137- props [ ( attr . prefix ? attr . prefix + ':' : '' ) + attr . name ] = attr . value
147+ attribute = attributes [ index ]
148+ prop = ( attribute . prefix ? attribute . prefix + ':' : '' ) + attribute . name
149+ props [ prop ] = attribute . value
138150 }
139151
140- node = h ( ast . tagName , props , children )
152+ node = h ( name , props , children )
141153
142- if ( ast . nodeName === 'template' && 'content' in ast ) {
154+ if ( name === 'template' && 'content' in ast ) {
143155 pos = ast . sourceCodeLocation
144156 start = pos && pos . startTag && position ( pos . startTag ) . end
145157 end = pos && pos . endTag && position ( pos . endTag ) . start
@@ -155,13 +167,15 @@ function element(ast, children, config) {
155167}
156168
157169/* Create clean positional information. */
158- function location ( node , location , verbose ) {
170+ function location ( node , location , config ) {
171+ var schema = config . schema
172+ var verbose = config . verbose
159173 var pos = position ( location )
160174 var reference
161- var values
175+ var attributes
176+ var attribute
162177 var props
163178 var prop
164- var name
165179
166180 if ( node . type === 'element' ) {
167181 reference = node . children [ node . children . length - 1 ]
@@ -177,12 +191,12 @@ function location(node, location, verbose) {
177191 }
178192
179193 if ( verbose ) {
180- values = location . attrs
194+ attributes = location . attrs
181195 props = { }
182196
183- for ( prop in values ) {
184- name = ( information ( prop ) || { } ) . propertyName || camelcase ( prop )
185- props [ name ] = position ( values [ prop ] )
197+ for ( attribute in attributes ) {
198+ prop = find ( schema , attribute ) . property
199+ props [ prop ] = position ( attributes [ attribute ] )
186200 }
187201
188202 node . data = {
0 commit comments