( parent, nodes, path, namespace = 'html', state, // TODO give these defaults (state.options.preserveWhitespace and state.options.preserveComments). // first, we need to make `Component(Client|Server)TransformState` inherit from a new `ComponentTransformState` // rather than from `ClientTransformState` and `ServerTransformState` preserve_whitespace, preserve_comments )
| 124 | * @param {boolean} preserve_comments |
| 125 | */ |
| 126 | export function clean_nodes( |
| 127 | parent, |
| 128 | nodes, |
| 129 | path, |
| 130 | namespace = 'html', |
| 131 | state, |
| 132 | // TODO give these defaults (state.options.preserveWhitespace and state.options.preserveComments). |
| 133 | // first, we need to make `Component(Client|Server)TransformState` inherit from a new `ComponentTransformState` |
| 134 | // rather than from `ClientTransformState` and `ServerTransformState` |
| 135 | preserve_whitespace, |
| 136 | preserve_comments |
| 137 | ) { |
| 138 | if (!state.analysis.runes) { |
| 139 | nodes = sort_const_tags(nodes, state); |
| 140 | } |
| 141 | |
| 142 | /** @type {AST.SvelteNode[]} */ |
| 143 | const hoisted = []; |
| 144 | |
| 145 | /** @type {AST.SvelteNode[]} */ |
| 146 | const regular = []; |
| 147 | |
| 148 | for (const node of nodes) { |
| 149 | if (node.type === 'Comment' && !preserve_comments) { |
| 150 | continue; |
| 151 | } |
| 152 | |
| 153 | if ( |
| 154 | node.type === 'ConstTag' || |
| 155 | node.type === 'DeclarationTag' || |
| 156 | node.type === 'DebugTag' || |
| 157 | node.type === 'SvelteBody' || |
| 158 | node.type === 'SvelteWindow' || |
| 159 | node.type === 'SvelteDocument' || |
| 160 | node.type === 'SvelteHead' || |
| 161 | node.type === 'TitleElement' || |
| 162 | node.type === 'SnippetBlock' |
| 163 | ) { |
| 164 | // TODO others? |
| 165 | hoisted.push(node); |
| 166 | } else { |
| 167 | regular.push(node); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | let trimmed = regular; |
| 172 | |
| 173 | if (!preserve_whitespace) { |
| 174 | trimmed = []; |
| 175 | |
| 176 | let first, last; |
| 177 | |
| 178 | while ( |
| 179 | (first = regular[0]) && |
| 180 | first.type === 'Text' && |
| 181 | !regex_not_whitespace.test(first.data) |
| 182 | ) { |
| 183 | regular.shift(); |
no test coverage detected
searching dependent graphs…