Skip to content

Commit

Permalink
update tests #12
Browse files Browse the repository at this point in the history
  • Loading branch information
tbela99 committed Aug 19, 2023
1 parent 062d4a0 commit 6807478
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 114 deletions.
41 changes: 10 additions & 31 deletions dist/index-umd-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -2714,7 +2714,7 @@
const result = (intersect.length == 0 ? null : {
...node1,
// @ts-ignore
sel: [...new Set([...(n1?.raw?.reduce(reducer, []) /*|| splitRule(n1.sel) */).concat(n2?.raw?.reduce(reducer, []) /* || splitRule(n2.sel) */)])].join(','),
sel: [...new Set([...(n1?.raw?.reduce(reducer, []) || splitRule(n1.sel)).concat(n2?.raw?.reduce(reducer, []) || splitRule(n2.sel))])].join(','),
chi: intersect.reverse()
});
if (result == null || [n1, n2].reduce((acc, curr) => curr.chi.length == 0 ? acc : acc + render(curr, options).code.length, 0) <= [node1, node2, result].reduce((acc, curr) => curr.chi.length == 0 ? acc : acc + render(curr, options).code.length, 0)) {
Expand Down Expand Up @@ -3296,60 +3296,42 @@
ast.chi = [...properties].concat(ast.chi.slice(k));
return ast;
}
/*
function splitRule(buffer: string): string[][] {
const result: string[][] = [[]];
let str: string = '';
function splitRule(buffer) {
const result = [[]];
let str = '';
for (let i = 0; i < buffer.length; i++) {
let chr: string = buffer.charAt(i);
let chr = buffer.charAt(i);
if (isWhiteSpace(chr.charCodeAt(0))) {
let k = i;
while (k + 1 < buffer.length) {
if (isWhiteSpace(buffer[k + 1].charCodeAt(0))) {
k++;
continue;
}
break;
}
if (str !== '') {
// @ts-ignore
result.at(-1).push(str);
str = '';
}
// @ts-ignore
if (result.at(-1).length > 0) {
// @ts-ignore
result.at(-1).push(' ');
}
i = k;
continue;
}
if (chr == ',') {
if (str !== '') {
// @ts-ignore
result.at(-1).push(str);
str = '';
}
result.push([]);
continue;
}
str += chr;
if (chr == '\\') {
str += buffer.charAt(++i);
Expand Down Expand Up @@ -3385,7 +3367,8 @@
str += chr;
if (chr == open) {
inParens++;
} else if (chr == close) {
}
else if (chr == close) {
inParens--;
}
if (inParens == 0) {
Expand All @@ -3395,20 +3378,16 @@
i = k;
}
}
if (str !== '') {
// @ts-ignore
result.at(-1).push(str);
}
return result;
}
*/
function reduceRuleSelector(node) {
// if (node.raw == null) {
//
// Object.defineProperty(node, 'raw', {enumerable: false, writable: true, value: splitRule(node.sel)})
// }
if (node.raw == null) {
Object.defineProperty(node, 'raw', { enumerable: false, writable: true, value: splitRule(node.sel) });
}
// @ts-ignore
// if (node.raw != null) {
// @ts-ignore
Expand Down
41 changes: 10 additions & 31 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2712,7 +2712,7 @@ function minify(ast, options = {}, recursive = false, errors) {
const result = (intersect.length == 0 ? null : {
...node1,
// @ts-ignore
sel: [...new Set([...(n1?.raw?.reduce(reducer, []) /*|| splitRule(n1.sel) */).concat(n2?.raw?.reduce(reducer, []) /* || splitRule(n2.sel) */)])].join(','),
sel: [...new Set([...(n1?.raw?.reduce(reducer, []) || splitRule(n1.sel)).concat(n2?.raw?.reduce(reducer, []) || splitRule(n2.sel))])].join(','),
chi: intersect.reverse()
});
if (result == null || [n1, n2].reduce((acc, curr) => curr.chi.length == 0 ? acc : acc + render(curr, options).code.length, 0) <= [node1, node2, result].reduce((acc, curr) => curr.chi.length == 0 ? acc : acc + render(curr, options).code.length, 0)) {
Expand Down Expand Up @@ -3294,60 +3294,42 @@ function minifyRule(ast) {
ast.chi = [...properties].concat(ast.chi.slice(k));
return ast;
}
/*
function splitRule(buffer: string): string[][] {
const result: string[][] = [[]];
let str: string = '';
function splitRule(buffer) {
const result = [[]];
let str = '';
for (let i = 0; i < buffer.length; i++) {
let chr: string = buffer.charAt(i);
let chr = buffer.charAt(i);
if (isWhiteSpace(chr.charCodeAt(0))) {
let k = i;
while (k + 1 < buffer.length) {
if (isWhiteSpace(buffer[k + 1].charCodeAt(0))) {
k++;
continue;
}
break;
}
if (str !== '') {
// @ts-ignore
result.at(-1).push(str);
str = '';
}
// @ts-ignore
if (result.at(-1).length > 0) {
// @ts-ignore
result.at(-1).push(' ');
}
i = k;
continue;
}
if (chr == ',') {
if (str !== '') {
// @ts-ignore
result.at(-1).push(str);
str = '';
}
result.push([]);
continue;
}
str += chr;
if (chr == '\\') {
str += buffer.charAt(++i);
Expand Down Expand Up @@ -3383,7 +3365,8 @@ function splitRule(buffer: string): string[][] {
str += chr;
if (chr == open) {
inParens++;
} else if (chr == close) {
}
else if (chr == close) {
inParens--;
}
if (inParens == 0) {
Expand All @@ -3393,20 +3376,16 @@ function splitRule(buffer: string): string[][] {
i = k;
}
}
if (str !== '') {
// @ts-ignore
result.at(-1).push(str);
}
return result;
}
*/
function reduceRuleSelector(node) {
// if (node.raw == null) {
//
// Object.defineProperty(node, 'raw', {enumerable: false, writable: true, value: splitRule(node.sel)})
// }
if (node.raw == null) {
Object.defineProperty(node, 'raw', { enumerable: false, writable: true, value: splitRule(node.sel) });
}
// @ts-ignore
// if (node.raw != null) {
// @ts-ignore
Expand Down
43 changes: 11 additions & 32 deletions dist/lib/ast/minify.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isIdentStart, isIdent, isFunction } from '../parser/utils/syntax.js';
import { isIdentStart, isIdent, isFunction, isWhiteSpace } from '../parser/utils/syntax.js';
import { PropertyList } from '../parser/declaration/list.js';
import { eq } from '../parser/utils/eq.js';
import { render } from '../renderer/render.js';
Expand Down Expand Up @@ -128,7 +128,7 @@ function minify(ast, options = {}, recursive = false, errors) {
const result = (intersect.length == 0 ? null : {
...node1,
// @ts-ignore
sel: [...new Set([...(n1?.raw?.reduce(reducer, []) /*|| splitRule(n1.sel) */).concat(n2?.raw?.reduce(reducer, []) /* || splitRule(n2.sel) */)])].join(','),
sel: [...new Set([...(n1?.raw?.reduce(reducer, []) || splitRule(n1.sel)).concat(n2?.raw?.reduce(reducer, []) || splitRule(n2.sel))])].join(','),
chi: intersect.reverse()
});
if (result == null || [n1, n2].reduce((acc, curr) => curr.chi.length == 0 ? acc : acc + render(curr, options).code.length, 0) <= [node1, node2, result].reduce((acc, curr) => curr.chi.length == 0 ? acc : acc + render(curr, options).code.length, 0)) {
Expand Down Expand Up @@ -710,60 +710,42 @@ function minifyRule(ast) {
ast.chi = [...properties].concat(ast.chi.slice(k));
return ast;
}
/*
function splitRule(buffer: string): string[][] {
const result: string[][] = [[]];
let str: string = '';
function splitRule(buffer) {
const result = [[]];
let str = '';
for (let i = 0; i < buffer.length; i++) {
let chr: string = buffer.charAt(i);
let chr = buffer.charAt(i);
if (isWhiteSpace(chr.charCodeAt(0))) {
let k = i;
while (k + 1 < buffer.length) {
if (isWhiteSpace(buffer[k + 1].charCodeAt(0))) {
k++;
continue;
}
break;
}
if (str !== '') {
// @ts-ignore
result.at(-1).push(str);
str = '';
}
// @ts-ignore
if (result.at(-1).length > 0) {
// @ts-ignore
result.at(-1).push(' ');
}
i = k;
continue;
}
if (chr == ',') {
if (str !== '') {
// @ts-ignore
result.at(-1).push(str);
str = '';
}
result.push([]);
continue;
}
str += chr;
if (chr == '\\') {
str += buffer.charAt(++i);
Expand Down Expand Up @@ -799,7 +781,8 @@ function splitRule(buffer: string): string[][] {
str += chr;
if (chr == open) {
inParens++;
} else if (chr == close) {
}
else if (chr == close) {
inParens--;
}
if (inParens == 0) {
Expand All @@ -809,20 +792,16 @@ function splitRule(buffer: string): string[][] {
i = k;
}
}
if (str !== '') {
// @ts-ignore
result.at(-1).push(str);
}
return result;
}
*/
function reduceRuleSelector(node) {
// if (node.raw == null) {
//
// Object.defineProperty(node, 'raw', {enumerable: false, writable: true, value: splitRule(node.sel)})
// }
if (node.raw == null) {
Object.defineProperty(node, 'raw', { enumerable: false, writable: true, value: splitRule(node.sel) });
}
// @ts-ignore
// if (node.raw != null) {
// @ts-ignore
Expand Down
13 changes: 6 additions & 7 deletions src/lib/ast/minify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export function minify(ast: AstNode, options: ParserOptions = {}, recursive: boo
const result = (intersect.length == 0 ? null : {
...node1,
// @ts-ignore
sel: [...new Set([...(n1?.raw?.reduce(reducer, []) /*|| splitRule(n1.sel) */).concat(n2?.raw?.reduce(reducer, []) /* || splitRule(n2.sel) */)])].join(','),
sel: [...new Set([...(n1?.raw?.reduce(reducer, []) || splitRule(n1.sel) ).concat(n2?.raw?.reduce(reducer, []) || splitRule(n2.sel) )])].join(','),
chi: intersect.reverse()
});
if (result == null || [n1, n2].reduce((acc, curr) => curr.chi.length == 0 ? acc : acc + render(curr, options).code.length, 0) <= [node1, node2, result].reduce((acc, curr) => curr.chi.length == 0 ? acc : acc + render(curr, options).code.length, 0)) {
Expand Down Expand Up @@ -940,7 +940,6 @@ export function minifyRule(ast: AstRule | AstAtRule): AstRule | AstAtRule {
return ast;
}

/*
function splitRule(buffer: string): string[][] {

const result: string[][] = [[]];
Expand Down Expand Up @@ -1047,14 +1046,14 @@ function splitRule(buffer: string): string[][] {

return result;
}
*/


function reduceRuleSelector(node: AstRule) {

// if (node.raw == null) {
//
// Object.defineProperty(node, 'raw', {enumerable: false, writable: true, value: splitRule(node.sel)})
// }
if (node.raw == null) {

Object.defineProperty(node, 'raw', {enumerable: false, writable: true, value: splitRule(node.sel)})
}

// @ts-ignore
// if (node.raw != null) {
Expand Down
2 changes: 1 addition & 1 deletion test/files/css/animate.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/files/css/bootstrap-4.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/files/css/bootstrap-5.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/files/css/bootstrap-demo.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion test/files/css/bootstrap.css

Large diffs are not rendered by default.

Loading

0 comments on commit 6807478

Please sign in to comment.