File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,6 +17,10 @@ thiserror = "1.0.40"
1717serde = { version = " 1.0.159" , features = [" derive" ] }
1818serde_json = " 1.0.95"
1919
20+ [features ]
21+ default = [" source-span" ]
22+ source-span = []
23+
2024[dev-dependencies ]
2125indoc = " 2.0.1"
2226insta = { version = " 1.29.0" , features = [" json" ] }
Original file line number Diff line number Diff line change 11use super :: node:: Node ;
2+ #[ cfg( feature = "source-span" ) ]
23use super :: span:: SourceSpan ;
34use serde:: { Serialize , Serializer } ;
45use std:: collections:: { BTreeMap , HashMap } ;
@@ -45,6 +46,7 @@ pub struct Element {
4546 #[ serde( skip_serializing_if = "Vec::is_empty" ) ]
4647 pub children : Vec < Node > ,
4748
49+ #[ cfg( feature = "source-span" ) ]
4850 /// Span of the element in the parsed source
4951 #[ serde( skip) ]
5052 pub source_span : SourceSpan ,
@@ -59,6 +61,7 @@ impl Default for Element {
5961 classes : vec ! [ ] ,
6062 attributes : HashMap :: new ( ) ,
6163 children : vec ! [ ] ,
64+ #[ cfg( feature = "source-span" ) ]
6265 source_span : SourceSpan :: default ( ) ,
6366 }
6467 }
Original file line number Diff line number Diff line change @@ -10,8 +10,10 @@ use crate::grammar::Grammar;
1010pub mod element;
1111pub mod formatting;
1212pub mod node;
13+ #[ cfg( feature = "source-span" ) ]
1314pub mod span;
1415
16+ #[ cfg( feature = "source-span" ) ]
1517use crate :: dom:: span:: SourceSpan ;
1618use element:: { Element , ElementVariant } ;
1719use node:: Node ;
@@ -232,22 +234,21 @@ impl Dom {
232234 }
233235
234236 fn build_node_element ( pair : Pair < Rule > , dom : & mut Dom ) -> Result < Option < Node > > {
235- let source_span = {
236- let pair_span = pair. as_span ( ) ;
237- let ( start_line, start_column) = pair_span. start_pos ( ) . line_col ( ) ;
238- let ( end_line, end_column) = pair_span. end_pos ( ) . line_col ( ) ;
239-
240- SourceSpan :: new (
241- String :: from ( pair_span. as_str ( ) ) ,
242- start_line,
243- end_line,
244- start_column,
245- end_column,
246- )
247- } ;
248-
249237 let mut element = Element {
250- source_span,
238+ #[ cfg( feature = "source-span" ) ]
239+ source_span : {
240+ let pair_span = pair. as_span ( ) ;
241+ let ( start_line, start_column) = pair_span. start_pos ( ) . line_col ( ) ;
242+ let ( end_line, end_column) = pair_span. end_pos ( ) . line_col ( ) ;
243+
244+ SourceSpan :: new (
245+ String :: from ( pair_span. as_str ( ) ) ,
246+ start_line,
247+ end_line,
248+ start_column,
249+ end_column,
250+ )
251+ } ,
251252 ..Element :: default ( )
252253 } ;
253254
Original file line number Diff line number Diff line change @@ -106,6 +106,7 @@ pub use crate::dom::Dom;
106106pub use crate :: dom:: DomVariant ;
107107pub use crate :: dom:: element:: { Element , ElementVariant } ;
108108pub use crate :: dom:: node:: Node ;
109+ #[ cfg( feature = "source-span" ) ]
109110pub use crate :: dom:: span:: SourceSpan ;
110111pub use crate :: error:: Error ;
111112pub use crate :: error:: Result ;
You can’t perform that action at this time.
0 commit comments