Skip to content

Commit 81d5544

Browse files
committed
fix bug when nesting is disabled #89
1 parent a770c97 commit 81d5544

7 files changed

Lines changed: 66 additions & 10 deletions

File tree

dist/index-umd-web.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,17 @@
1515
*/
1616
exports.ValidationLevel = void 0;
1717
(function (ValidationLevel) {
18+
/**
19+
* disable validation
20+
*/
1821
ValidationLevel[ValidationLevel["None"] = 0] = "None";
22+
/**
23+
* validate selectors and at-rules
24+
*/
1925
ValidationLevel[ValidationLevel["Default"] = 1] = "Default";
26+
/**
27+
* validate selectors, at-rules and declarations
28+
*/
2029
ValidationLevel[ValidationLevel["All"] = 2] = "All"; // selectors + at-rules + declarations
2130
})(exports.ValidationLevel || (exports.ValidationLevel = {}));
2231
/**
@@ -20923,8 +20932,7 @@
2092320932
}
2092420933
let rule = selector.map(s => {
2092520934
if (s[0] == '&') {
20926-
// @ts-ignore
20927-
s[0] = node.optimized.optimized[0];
20935+
s.splice(0, 1, ...node.optimized.optimized);
2092820936
}
2092920937
return s.join('');
2093020938
}).join(',');

dist/index.cjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,17 @@ var SyntaxValidationResult;
1414
*/
1515
exports.ValidationLevel = void 0;
1616
(function (ValidationLevel) {
17+
/**
18+
* disable validation
19+
*/
1720
ValidationLevel[ValidationLevel["None"] = 0] = "None";
21+
/**
22+
* validate selectors and at-rules
23+
*/
1824
ValidationLevel[ValidationLevel["Default"] = 1] = "Default";
25+
/**
26+
* validate selectors, at-rules and declarations
27+
*/
1928
ValidationLevel[ValidationLevel["All"] = 2] = "All"; // selectors + at-rules + declarations
2029
})(exports.ValidationLevel || (exports.ValidationLevel = {}));
2130
/**
@@ -21032,8 +21041,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
2103221041
}
2103321042
let rule = selector.map(s => {
2103421043
if (s[0] == '&') {
21035-
// @ts-ignore
21036-
s[0] = node.optimized.optimized[0];
21044+
s.splice(0, 1, ...node.optimized.optimized);
2103721045
}
2103821046
return s.join('');
2103921047
}).join(',');

dist/index.d.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,17 @@
22
* validation level enum
33
*/
44
declare enum ValidationLevel {
5+
/**
6+
* disable validation
7+
*/
58
None = 0,
9+
/**
10+
* validate selectors and at-rules
11+
*/
612
Default = 1,// selectors + at-rules
13+
/**
14+
* validate selectors, at-rules and declarations
15+
*/
716
All = 2
817
}
918
/**
@@ -1160,6 +1169,8 @@ interface ValidationOptions {
11601169
interface MinifyOptions {
11611170

11621171
minify?: boolean;
1172+
parseColor?: boolean;
1173+
convertColor?: boolean;
11631174
nestingRules?: boolean;
11641175
expandNestingRules?: boolean;
11651176
removeDuplicateDeclarations?: boolean;
@@ -1179,7 +1190,6 @@ export declare interface ParserOptions extends MinifyOptions, MinifyFeatureOptio
11791190
resolveUrls?: boolean;
11801191
resolveImport?: boolean;
11811192
cwd?: string;
1182-
parseColor?: boolean;
11831193
removePrefix?: boolean;
11841194
load?: (url: string, currentUrl: string) => Promise<string>;
11851195
dirname?: (path: string) => string;

dist/lib/ast/minify.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,7 @@ function doMinify(ast, options = {}, recursive = false, errors, nestingContent,
347347
}
348348
let rule = selector.map(s => {
349349
if (s[0] == '&') {
350-
// @ts-ignore
351-
s[0] = node.optimized.optimized[0];
350+
s.splice(0, 1, ...node.optimized.optimized);
352351
}
353352
return s.join('');
354353
}).join(',');

dist/lib/ast/types.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,17 @@ var SyntaxValidationResult;
99
*/
1010
var ValidationLevel;
1111
(function (ValidationLevel) {
12+
/**
13+
* disable validation
14+
*/
1215
ValidationLevel[ValidationLevel["None"] = 0] = "None";
16+
/**
17+
* validate selectors and at-rules
18+
*/
1319
ValidationLevel[ValidationLevel["Default"] = 1] = "Default";
20+
/**
21+
* validate selectors, at-rules and declarations
22+
*/
1423
ValidationLevel[ValidationLevel["All"] = 2] = "All"; // selectors + at-rules + declarations
1524
})(ValidationLevel || (ValidationLevel = {}));
1625
/**

src/lib/ast/minify.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ function doMinify(ast: AstNode, options: ParserOptions = {}, recursive: boolean
487487
return acc;
488488

489489
}, []);
490-
490+
``
491491
if (!wrap) {
492492

493493
wrap = selector.some((s: string[]) => s[0] != '&');
@@ -497,8 +497,7 @@ function doMinify(ast: AstNode, options: ParserOptions = {}, recursive: boolean
497497

498498
if (s[0] == '&') {
499499

500-
// @ts-ignore
501-
s[0] = node.optimized.optimized[0];
500+
s.splice(0, 1, ...(node as AstRule)!.optimized!.optimized);
502501
}
503502

504503
return s.join('');

test/specs/code/nesting.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,29 @@ article {
586586
expandNestingRules: false
587587
}).then(result => expect(result.code).equals(`article{color:red;&{color:blue}&{color:green}}`));
588588
});
589+
590+
it('no nested rules #25', function () {
591+
592+
const css = `
593+
594+
table.colortable td.c {
595+
text-transform:uppercase;
596+
}
597+
table.colortable td:first-child, table.colortable td:first-child+td {
598+
border:1px solid black;
599+
}
600+
`;
601+
602+
return transform(css, {
603+
beautify: true,
604+
nestingRules: false
605+
}).then(result => expect(result.code).equals(`table.colortable td.c {
606+
text-transform: uppercase
607+
}
608+
table.colortable td:first-child,table.colortable td:first-child+td {
609+
border: 1px solid #000
610+
}`));
611+
});
589612
});
590613

591614
}

0 commit comments

Comments
 (0)