Skip to content

Commit

Permalink
minify 0% #14
Browse files Browse the repository at this point in the history
  • Loading branch information
tbela99 committed Aug 22, 2023
1 parent 213b1f8 commit 5f267fe
Show file tree
Hide file tree
Showing 8 changed files with 13,488 additions and 14 deletions.
7 changes: 4 additions & 3 deletions dist/index-umd-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,8 @@
}
return val + unit;
case 'Perc':
return token.val + '%';
const perc = reduceNumber(token.val);
return options.minify && perc == '0' ? '0' : perc + '%';
case 'Number':
return reduceNumber(token.val);
case 'Comment':
Expand Down Expand Up @@ -2820,7 +2821,7 @@
if (delim.typ == 'Block-start') {
const position = map.get(tokens[0]);
const uniq = new Map;
parseTokens(tokens, { minify: options.minify }).reduce((acc, curr, index, array) => {
parseTokens(tokens, { minify: true }).reduce((acc, curr, index, array) => {
if (curr.typ == 'Whitespace') {
if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
trimWhiteSpace.includes(array[index + 1]?.typ) ||
Expand All @@ -2829,7 +2830,7 @@
return acc;
}
}
let t = renderToken(curr, { minify: true });
let t = renderToken(curr, { minify: false });
if (t == ',') {
acc.push([]);
}
Expand Down
7 changes: 4 additions & 3 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,8 @@ function renderToken(token, options = {}, reducer, errors) {
}
return val + unit;
case 'Perc':
return token.val + '%';
const perc = reduceNumber(token.val);
return options.minify && perc == '0' ? '0' : perc + '%';
case 'Number':
return reduceNumber(token.val);
case 'Comment':
Expand Down Expand Up @@ -2818,7 +2819,7 @@ async function parse$1(iterator, opt = {}) {
if (delim.typ == 'Block-start') {
const position = map.get(tokens[0]);
const uniq = new Map;
parseTokens(tokens, { minify: options.minify }).reduce((acc, curr, index, array) => {
parseTokens(tokens, { minify: true }).reduce((acc, curr, index, array) => {
if (curr.typ == 'Whitespace') {
if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
trimWhiteSpace.includes(array[index + 1]?.typ) ||
Expand All @@ -2827,7 +2828,7 @@ async function parse$1(iterator, opt = {}) {
return acc;
}
}
let t = renderToken(curr, { minify: true });
let t = renderToken(curr, { minify: false });
if (t == ',') {
acc.push([]);
}
Expand Down
4 changes: 2 additions & 2 deletions dist/lib/parser/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ async function parse(iterator, opt = {}) {
if (delim.typ == 'Block-start') {
const position = map.get(tokens[0]);
const uniq = new Map;
parseTokens(tokens, { minify: options.minify }).reduce((acc, curr, index, array) => {
parseTokens(tokens, { minify: true }).reduce((acc, curr, index, array) => {
if (curr.typ == 'Whitespace') {
if (trimWhiteSpace.includes(array[index - 1]?.typ) ||
trimWhiteSpace.includes(array[index + 1]?.typ) ||
Expand All @@ -213,7 +213,7 @@ async function parse(iterator, opt = {}) {
return acc;
}
}
let t = renderToken(curr, { minify: true });
let t = renderToken(curr, { minify: false });
if (t == ',') {
acc.push([]);
}
Expand Down
3 changes: 2 additions & 1 deletion dist/lib/renderer/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ function renderToken(token, options = {}, reducer, errors) {
}
return val + unit;
case 'Perc':
return token.val + '%';
const perc = reduceNumber(token.val);
return options.minify && perc == '0' ? '0' : perc + '%';
case 'Number':
return reduceNumber(token.val);
case 'Comment':
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ast/walk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function* walk(node: AstNode, parent?: AstRuleList, root?: AstRuleList):

for (const child of <Array<AstNode>>node.chi) {

yield* walk(<AstNode>child, <AstRuleList>node, <AstRuleList>(root ?? node))
yield* walk(<AstNode>child, <AstRuleList>node, <AstRuleList>(root ?? node));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib/parser/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export async function parse(iterator: string, opt: ParserOptions = {}): Promise<
const position: Position = <Position>map.get(tokens[0]);

const uniq = new Map<string, string[]>;
parseTokens(tokens, {minify: options.minify}).reduce((acc: string[][], curr: Token, index: number, array: Token[]) => {
parseTokens(tokens, {minify: true}).reduce((acc: string[][], curr: Token, index: number, array: Token[]) => {

if (curr.typ == 'Whitespace') {

Expand All @@ -298,7 +298,7 @@ export async function parse(iterator: string, opt: ParserOptions = {}): Promise<
}
}

let t = renderToken(curr, {minify: true});
let t = renderToken(curr, {minify: false});
if (t == ',') {
acc.push([]);
} else {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/renderer/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,8 @@ export function renderToken(token: Token, options: RenderOptions = {}, reducer?:

case 'Perc':

return token.val + '%';
const perc = reduceNumber(token.val);
return options.minify && perc == '0' ? '0' : perc + '%';

case 'Number':

Expand Down
13,472 changes: 13,471 additions & 1 deletion test/files/css/bootstrap.css

Large diffs are not rendered by default.

0 comments on commit 5f267fe

Please sign in to comment.