Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
if (stylesheetAsts[href]) {
allUsedHrefs.push(href);
}
});
const allCombinedAst = {
type: 'StyleSheet',
loc: null,
children: allUsedHrefs.reduce(
(children, href) => children.appendList(stylesheetAsts[href].children),
new csstree.List()
)
};
// Lift important comments (i.e. /*! comment */) up to the beginning
const comments = new csstree.List();
csstree.walk(allCombinedAst, {
visit: 'Comment',
enter: (_node, item, list) => {
comments.append(list.remove(item));
}
});
allCombinedAst.children.prependList(comments);
// Why not just allow the return of the "unminified" CSS (in case
// some odd ball wants it)?
// 'allCombinedAst' concatenates multiple payloads of CSS.
// It only contains the selectors that are supposedly
// in the DOM. However it does contain *duplicate* selectors.
// E.g. `p { color: blue; } p { font-weight: bold; }`
// When ultimately, what was need is `p { color: blue; font-weight: bold}`.
// The csso.minify() function will solve this, *and* whitespace minify
// each item existing in stylesheetAsts.
const allUsedHrefs = [];
allHrefs.forEach(href => {
while (redirectResponses[href]) {
href = redirectResponses[href];
}
if (stylesheetAsts[href]) {
allUsedHrefs.push(href);
}
});
const allCombinedAst = {
type: 'StyleSheet',
loc: null,
children: allUsedHrefs.reduce(
(children, href) => children.appendList(stylesheetAsts[href].children),
new csstree.List()
)
};
// Lift important comments (i.e. /*! comment */) up to the beginning
const comments = new csstree.List();
csstree.walk(allCombinedAst, {
visit: 'Comment',
enter: (_node, item, list) => {
comments.append(list.remove(item));
}
});
allCombinedAst.children.prependList(comments);
// Why not just allow the return of the "unminified" CSS (in case
// some odd ball wants it)?
// 'allCombinedAst' concatenates multiple payloads of CSS.
// create new ruleset if declarations length greater than
// ruleset description overhead
if (allowMergeDown && blockLength >= newBlockLength) {
var newRule = {
type: 'Rule',
loc: null,
prelude: newSelector,
block: {
type: 'Block',
loc: null,
children: new List().fromArray(diff.eq)
},
pseudoSignature: node.pseudoSignature
};
block.children = new List().fromArray(diff.ne1);
prevBlock.children = new List().fromArray(diff.ne2overrided);
list.insert(list.createItem(newRule), prevItem);
return true;
}
}
}
}
if (allowMergeUp) {
// TODO: disallow up merge only if any property interception only (i.e. diff.ne2overrided.length > 0);
// await property families to find property interception correctly
allowMergeUp = !prevSelectors.some(function(prevSelector) {
return selectors.some(function(selector) {
return selector.compareMarker === prevSelector.compareMarker;
});
});
(fontFormatNames.indexOf(a.formatName) + 1 || 9) -
(fontFormatNames.indexOf(b.formatName) + 1 || 9)
)
})[0] as RemoteFont | undefined
const optimalRemoteNodes: csstree.CssNode[] = optimalRemote
? [
{
type: 'Url',
value: { type: 'Raw', value: optimalRemote.path },
},
{ type: 'WhiteSpace', value: ' ' },
{
type: 'Function',
name: 'format',
children: new csstree.List().fromArray([
{ type: 'String', value: `'${optimalRemote.formatName}'` },
]),
},
]
: []
const chunks = [...local.map(l => [l]), optimalRemoteNodes]
const children = chunks.reduce((list, chunk) => {
if (list.getSize()) {
list.appendData({ type: 'Operator', value: ',' })
}
chunk.forEach(node => list.appendData(node))
return list
}, new csstree.List())
parse: function SassInterpolation(recognizer, readSequence) {
var start = this.scanner.tokenStart;
var children = new List();
if (!this.scanner.isDelim(NUMBERSIGN)) {
this.error();
}
this.scanner.next();
this.eat(LEFTCURLYBRACKET);
children = readSequence.call(this, recognizer);
this.eat(RIGHTCURLYBRACKET);
return {
type: 'SassInterpolation',
loc: this.getLocation(start, this.scanner.tokenStart),
children: children
};
}
TRBL.prototype.getValue = function() {
var result = new List();
var sides = this.sides;
var values = [
sides.top,
sides.right,
sides.bottom,
sides.left
];
var stringValues = [
generate(sides.top.node),
generate(sides.right.node),
generate(sides.bottom.node),
generate(sides.left.node)
];
if (stringValues[LEFT] === stringValues[RIGHT]) {
values.pop();
function addRuleToMap(map, item, list, single) {
var node = item.data;
var name = resolveKeyword(node.name).basename;
var id = node.name.toLowerCase() + '/' + (node.prelude ? node.prelude.id : null);
if (!hasOwnProperty.call(map, name)) {
map[name] = Object.create(null);
}
if (single) {
delete map[name][id];
}
if (!hasOwnProperty.call(map[name], id)) {
map[name][id] = new List();
}
map[name][id].append(list.remove(item));
}
function readChunk(children, specialComments) {
var buffer = new List();
var nonSpaceTokenInBuffer = false;
var protectedComment;
children.nextUntil(children.head, function(node, item, list) {
if (node.type === 'Comment') {
if (!specialComments || node.value.charAt(0) !== '!') {
list.remove(item);
return;
}
if (nonSpaceTokenInBuffer || protectedComment) {
return true;
}
list.remove(item);
protectedComment = node;
module.exports = function compress(ast, options) {
ast = ast || { type: 'StyleSheet', loc: null, children: new List() };
options = options || {};
var compressOptions = {
logger: typeof options.logger === 'function' ? options.logger : function() {},
restructuring: getRestructureOption(options),
forceMediaMerge: Boolean(options.forceMediaMerge),
usage: options.usage ? usageUtils.buildIndex(options.usage) : false
};
var specialComments = getCommentsOption(options);
var firstAtrulesAllowed = true;
var input;
var output = new List();
var chunk;
var chunkNum = 1;
var chunkChildren;
if (options.clone) {
ast = clone(ast);
}
if (ast.type === 'StyleSheet') {
input = ast.children;
ast.children = output;
} else {
input = wrapBlock(ast);
}
do {