Parses the text into a CST. WARNING: You MUST not drop the root node for the duration of using the CST or a panic could occur in certain scenarios. This is because the CST uses weak references for ancestors and if the root node is dropped then the weak reference will be lost and the CST will panic to prevent bugs when a descendant node attempts to access an ancestor that was dropped. ``` use jso
(text: &str, parse_options: &ParseOptions)
| 1105 | /// }"#); |
| 1106 | /// ``` |
| 1107 | pub fn parse(text: &str, parse_options: &ParseOptions) -> Result<Self, ParseError> { |
| 1108 | let parse_result = parse_to_ast( |
| 1109 | text, |
| 1110 | &crate::CollectOptions { |
| 1111 | comments: crate::CommentCollectionStrategy::AsTokens, |
| 1112 | tokens: true, |
| 1113 | }, |
| 1114 | parse_options, |
| 1115 | )?; |
| 1116 | |
| 1117 | Ok( |
| 1118 | CstBuilder { |
| 1119 | text, |
| 1120 | tokens: parse_result.tokens.unwrap().into_iter().collect(), |
| 1121 | } |
| 1122 | .build(parse_result.value), |
| 1123 | ) |
| 1124 | } |
| 1125 | |
| 1126 | /// Computes the single indentation text of the file. |
| 1127 | pub fn single_indent_text(&self) -> Option<String> { |
nothing calls this directly
no test coverage detected