|
|
@@ -79,8 +79,7 @@ this.uglifycss = (() => {
|
|
|
const maxIndex = css.length - 1;
|
|
|
const sb = [];
|
|
|
|
|
|
- let appendIndex = 0;
|
|
|
- let match;
|
|
|
+ let appendIndex = 0, match;
|
|
|
|
|
|
// Since we need to account for non-base64 data urls, we need to handle
|
|
|
// ' and ) being part of the data string. Hence switching to indexOf,
|
|
|
@@ -89,16 +88,14 @@ this.uglifycss = (() => {
|
|
|
|
|
|
while ((match = pattern.exec(css)) !== null) {
|
|
|
|
|
|
- let startIndex = match.index + match[1].length; // 'url('.length()
|
|
|
+ const startIndex = match.index + match[1].length; // 'url('.length()
|
|
|
let terminator = match[2]; // ', " or empty (not quoted)
|
|
|
|
|
|
if (terminator.length === 0) {
|
|
|
terminator = ")";
|
|
|
}
|
|
|
|
|
|
- let foundTerminator = false;
|
|
|
-
|
|
|
- let endIndex = pattern.lastIndex - 1;
|
|
|
+ let foundTerminator = false, endIndex = pattern.lastIndex - 1;
|
|
|
|
|
|
while (foundTerminator === false && endIndex + 1 <= maxIndex) {
|
|
|
endIndex = css.indexOf(terminator, endIndex + 1);
|
|
|
@@ -126,13 +123,11 @@ this.uglifycss = (() => {
|
|
|
terminator = "";
|
|
|
}
|
|
|
|
|
|
- let url;
|
|
|
-
|
|
|
- url = terminator + token + terminator;
|
|
|
+ const url = terminator + token + terminator;
|
|
|
|
|
|
preservedTokens.push(url);
|
|
|
|
|
|
- let preserver = "url(" + ___PRESERVED_TOKEN_ + (preservedTokens.length - 1) + "___)";
|
|
|
+ const preserver = "url(" + ___PRESERVED_TOKEN_ + (preservedTokens.length - 1) + "___)";
|
|
|
sb.push(preserver);
|
|
|
|
|
|
} else {
|
|
|
@@ -171,8 +166,7 @@ this.uglifycss = (() => {
|
|
|
const maxIndex = css.length - 1;
|
|
|
const sb = [];
|
|
|
|
|
|
- let appendIndex = 0;
|
|
|
- let match;
|
|
|
+ let appendIndex = 0, match;
|
|
|
|
|
|
// Since we need to account for non-base64 data urls, we need to handle
|
|
|
// ' and ) being part of the data string. Hence switching to indexOf,
|
|
|
@@ -181,15 +175,14 @@ this.uglifycss = (() => {
|
|
|
|
|
|
while ((match = pattern.exec(css)) !== null) {
|
|
|
|
|
|
- let startIndex = match.index + 4; // 'url('.length()
|
|
|
+ const startIndex = match.index + 4; // 'url('.length()
|
|
|
let terminator = match[1]; // ', " or empty (not quoted)
|
|
|
|
|
|
if (terminator.length === 0) {
|
|
|
terminator = ")";
|
|
|
}
|
|
|
|
|
|
- let foundTerminator = false;
|
|
|
- let endIndex = pattern.lastIndex - 1;
|
|
|
+ let foundTerminator = false, endIndex = pattern.lastIndex - 1;
|
|
|
|
|
|
while (foundTerminator === false && endIndex + 1 <= maxIndex) {
|
|
|
endIndex = css.indexOf(terminator, endIndex + 1);
|
|
|
@@ -209,7 +202,7 @@ this.uglifycss = (() => {
|
|
|
if (foundTerminator) {
|
|
|
|
|
|
let token = css.substring(startIndex, endIndex);
|
|
|
- let parts = token.split(",");
|
|
|
+ const parts = token.split(",");
|
|
|
if (parts.length > 1 && parts[0].slice(-7) == ";base64") {
|
|
|
token = token.replace(/\s+/g, "");
|
|
|
} else {
|
|
|
@@ -220,7 +213,7 @@ this.uglifycss = (() => {
|
|
|
|
|
|
preservedTokens.push(token);
|
|
|
|
|
|
- let preserver = "url(" + ___PRESERVED_TOKEN_ + (preservedTokens.length - 1) + "___)";
|
|
|
+ const preserver = "url(" + ___PRESERVED_TOKEN_ + (preservedTokens.length - 1) + "___)";
|
|
|
sb.push(preserver);
|
|
|
|
|
|
appendIndex = endIndex + 1;
|
|
|
@@ -259,14 +252,13 @@ this.uglifycss = (() => {
|
|
|
const pattern = /(=\s*?["']?)?#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])(\}|[^0-9a-f{][^{]*?\})/gi;
|
|
|
const sb = [];
|
|
|
|
|
|
- let index = 0;
|
|
|
- let match;
|
|
|
+ let index = 0, match;
|
|
|
|
|
|
while ((match = pattern.exec(css)) !== null) {
|
|
|
|
|
|
sb.push(css.substring(index, match.index));
|
|
|
|
|
|
- let isFilter = match[1];
|
|
|
+ const isFilter = match[1];
|
|
|
|
|
|
if (isFilter) {
|
|
|
// Restore, maintain case, otherwise filter will break
|
|
|
@@ -304,8 +296,7 @@ this.uglifycss = (() => {
|
|
|
|
|
|
const pattern = /@[a-z0-9-_]*keyframes\s+[a-z0-9-_]+\s*{/gi;
|
|
|
|
|
|
- let index = 0;
|
|
|
- let buffer;
|
|
|
+ let index = 0, buffer;
|
|
|
|
|
|
const preserve = (part, i) => {
|
|
|
part = part.replace(/(^\s|\s$)/g, "");
|
|
|
@@ -328,12 +319,12 @@ this.uglifycss = (() => {
|
|
|
index += startIndex;
|
|
|
startIndex = index;
|
|
|
|
|
|
- let len = content.length;
|
|
|
- let buffers = [];
|
|
|
+ const len = content.length;
|
|
|
+ const buffers = [];
|
|
|
|
|
|
for (; index < len; ++index) {
|
|
|
|
|
|
- let ch = content.charAt(index);
|
|
|
+ const ch = content.charAt(index);
|
|
|
|
|
|
if (ch === "{") {
|
|
|
|
|
|
@@ -394,12 +385,11 @@ this.uglifycss = (() => {
|
|
|
|
|
|
const table = [];
|
|
|
|
|
|
- let from = 0;
|
|
|
- let end;
|
|
|
+ let from = 0, end;
|
|
|
|
|
|
while (true) { // eslint-disable-line no-constant-condition
|
|
|
|
|
|
- let start = content.indexOf("/*", from);
|
|
|
+ const start = content.indexOf("/*", from);
|
|
|
|
|
|
if (start > -1) {
|
|
|
|
|
|
@@ -467,8 +457,8 @@ this.uglifycss = (() => {
|
|
|
// strings are safe, now wrestle the comments
|
|
|
for (let i = 0, len = comments.length; i < len; i += 1) {
|
|
|
|
|
|
- let token = comments[i];
|
|
|
- let placeholder = "___PRESERVE_CANDIDATE_COMMENT_" + i + "___";
|
|
|
+ const token = comments[i];
|
|
|
+ const placeholder = "___PRESERVE_CANDIDATE_COMMENT_" + i + "___";
|
|
|
|
|
|
// ! in the first position of the comment means preserve
|
|
|
// so push to the preserved tokens keeping the !
|
|
|
@@ -501,7 +491,7 @@ this.uglifycss = (() => {
|
|
|
// keep empty comments after child selectors (IE7 hack)
|
|
|
// e.g. html >/**/ body
|
|
|
if (token.length === 0) {
|
|
|
- let startIndex = content.indexOf(placeholder);
|
|
|
+ const startIndex = content.indexOf(placeholder);
|
|
|
if (startIndex > 2) {
|
|
|
if (content.charAt(startIndex - 3) === ">") {
|
|
|
preservedTokens.push("");
|
|
|
@@ -598,7 +588,7 @@ this.uglifycss = (() => {
|
|
|
|
|
|
// preserve 0% in hsl and hsla color definitions
|
|
|
content = content.replace(/(hsla?)\(([^)]+)\)/g, (_, f1, f2) => {
|
|
|
- var f0 = [];
|
|
|
+ const f0 = [];
|
|
|
f2.split(",").forEach(part => {
|
|
|
part = part.replace(/(^\s+|\s+$)/g, "");
|
|
|
if (part === "0%") {
|
|
|
@@ -688,8 +678,7 @@ this.uglifycss = (() => {
|
|
|
// this makes it more likely that it'll get further compressed in the next step.
|
|
|
pattern = /rgb\s*\(\s*([0-9,\s]+)\s*\)/gi;
|
|
|
content = content.replace(pattern, (_, f1) => {
|
|
|
- const rgbcolors = f1.split(",");
|
|
|
- let hexcolor = "#";
|
|
|
+ let rgbcolors = f1.split(","), hexcolor = "#";
|
|
|
for (let i = 0; i < rgbcolors.length; i += 1) {
|
|
|
let val = parseInt(rgbcolors[i], 10);
|
|
|
if (val < 16) {
|
|
|
@@ -743,7 +732,7 @@ this.uglifycss = (() => {
|
|
|
const lines = [];
|
|
|
let line = [];
|
|
|
for (let i = 0, len = content.length; i < len; i += 1) {
|
|
|
- let ch = content.charAt(i);
|
|
|
+ const ch = content.charAt(i);
|
|
|
line.push(ch);
|
|
|
if (ch === "}" && line.length > options.maxLineLen) {
|
|
|
lines.push(line.join(""));
|