(ast, options)
| 121 | } |
| 122 | |
| 123 | export default function compress(ast, options) { |
| 124 | ast = ast || { type: 'StyleSheet', loc: null, children: new List() }; |
| 125 | options = options || {}; |
| 126 | |
| 127 | const compressOptions = { |
| 128 | logger: typeof options.logger === 'function' ? options.logger : function() {}, |
| 129 | restructuring: getRestructureOption(options), |
| 130 | forceMediaMerge: Boolean(options.forceMediaMerge), |
| 131 | usage: options.usage ? buildIndex(options.usage) : false |
| 132 | }; |
| 133 | const output = new List(); |
| 134 | let specialComments = getCommentsOption(options); |
| 135 | let firstAtrulesAllowed = true; |
| 136 | let input; |
| 137 | let chunk; |
| 138 | let chunkNum = 1; |
| 139 | let chunkChildren; |
| 140 | |
| 141 | if (options.clone) { |
| 142 | ast = clone(ast); |
| 143 | } |
| 144 | |
| 145 | if (ast.type === 'StyleSheet') { |
| 146 | input = ast.children; |
| 147 | ast.children = output; |
| 148 | } else { |
| 149 | input = wrapBlock(ast); |
| 150 | } |
| 151 | |
| 152 | do { |
| 153 | chunk = readChunk(input, Boolean(specialComments)); |
| 154 | compressChunk(chunk.stylesheet, firstAtrulesAllowed, chunkNum++, compressOptions); |
| 155 | chunkChildren = chunk.stylesheet.children; |
| 156 | |
| 157 | if (chunk.comment) { |
| 158 | // add \n before comment if there is another content in output |
| 159 | if (!output.isEmpty) { |
| 160 | output.insert(List.createItem({ |
| 161 | type: 'Raw', |
| 162 | value: '\n' |
| 163 | })); |
| 164 | } |
| 165 | |
| 166 | output.insert(List.createItem(chunk.comment)); |
| 167 | |
| 168 | // add \n after comment if chunk is not empty |
| 169 | if (!chunkChildren.isEmpty) { |
| 170 | output.insert(List.createItem({ |
| 171 | type: 'Raw', |
| 172 | value: '\n' |
| 173 | })); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | if (firstAtrulesAllowed && !chunkChildren.isEmpty) { |
| 178 | const lastRule = chunkChildren.last; |
| 179 | |
| 180 | if (lastRule.type !== 'Atrule' || |
no test coverage detected
searching dependent graphs…