Skip to content

Commit 7917932

Browse files
committed
More test coverage
1 parent de15231 commit 7917932

File tree

12 files changed

+192
-157
lines changed

12 files changed

+192
-157
lines changed

packages/less/scripts/coverage-lines.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,5 +203,5 @@ const jsonOutput = {
203203
};
204204

205205
fs.writeFileSync(jsonOutputPath, JSON.stringify(jsonOutput, null, 2), 'utf8');
206-
console.log(`\n📄 Uncovered lines data written to: coverage/uncovered-lines.json\n`);
206+
console.log('\n📄 Uncovered lines data written to: coverage/uncovered-lines.json\n');
207207

packages/less/src/less/contexts.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const parseCopyProperties = [
2525
'dumpLineNumbers', // option - @deprecated The dumpLineNumbers option is deprecated. Use sourcemaps instead. All modes ('comments', 'mediaquery', 'all') will be removed in a future version.
2626
'compress', // option - whether to compress
2727
'syncImport', // option - whether to import synchronously
28-
'chunkInput', // option - whether to chunk input. more performant but causes parse issues.
2928
'mime', // browser only - mime type for sheet import
3029
'useFileCache', // browser only - whether to use the per file session cache
3130
// context

packages/less/src/less/parser/chunker.js

Lines changed: 0 additions & 122 deletions
This file was deleted.

packages/less/src/less/parser/parser-input.js

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import chunker from './chunker';
2-
31
export default () => {
42
let // Less input string
53
input;
@@ -351,26 +349,11 @@ export default () => {
351349
return (c > CHARCODE_9 || c < CHARCODE_PLUS) || c === CHARCODE_FORWARD_SLASH || c === CHARCODE_COMMA;
352350
};
353351

354-
parserInput.start = (str, chunkInput, failFunction) => {
352+
parserInput.start = (str) => {
355353
input = str;
356354
parserInput.i = j = currentPos = furthest = 0;
357355

358-
// chunking apparently makes things quicker (but my tests indicate
359-
// it might actually make things slower in node at least)
360-
// and it is a non-perfect parse - it can't recognise
361-
// unquoted urls, meaning it can't distinguish comments
362-
// meaning comments with quotes or {}() in them get 'counted'
363-
// and then lead to parse errors.
364-
// In addition if the chunking chunks in the wrong place we might
365-
// not be able to parse a parser statement in one go
366-
// this is officially deprecated but can be switched on via an option
367-
// in the case it causes too much performance issues.
368-
if (chunkInput) {
369-
chunks = chunker(str, failFunction);
370-
} else {
371-
chunks = [str];
372-
}
373-
356+
chunks = [str];
374357
current = chunks[0];
375358

376359
skipWhitespace(0);

packages/less/src/less/parser/parser.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,7 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
124124
const parser = parserInput;
125125

126126
try {
127-
parser.start(str, false, function fail(msg, index) {
128-
callback({
129-
message: msg,
130-
index: index + currentIndex
131-
});
132-
});
127+
parser.start(str);
133128
for (let x = 0, p; (p = parseList[x]); x++) {
134129
result = parsers[p]();
135130
returnNodes.push(result || null);
@@ -209,14 +204,7 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
209204
// with the `root` property set to true, so no `{}` are
210205
// output. The callback is called when the input is parsed.
211206
try {
212-
parserInput.start(str, context.chunkInput, function fail(msg, index) {
213-
throw new LessError({
214-
index,
215-
type: 'Parse',
216-
message: msg,
217-
filename: fileInfo.filename
218-
}, imports);
219-
});
207+
parserInput.start(str);
220208

221209
tree.Node.prototype.parse = this;
222210
root = new tree.Ruleset(null, this.parsers.primary());

packages/test-data/tests-config/at-rules-compressed-evaluation/at-rules-compressed-evaluation.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Test at-rule evaluation paths (eval, evalRoot, genCSS, accept, etc.)
2+
3+
// Test keywordList - @media with keyword list
4+
@media screen, print, handheld {
5+
body {
6+
font-size: 12pt;
7+
}
8+
}
9+
10+
// Test declarationsBlock with mergeable=true (nested ruleset with declarations)
11+
@media screen {
12+
.container {
13+
color: red;
14+
background: blue;
15+
}
16+
}
17+
18+
// Test simpleBlock optimization with allRulesetDeclarations (single ruleset)
19+
@media screen {
20+
.test {
21+
color: red;
22+
background: blue;
23+
}
24+
}
25+
26+
// Test eval with value evaluation and keywordList conversion
27+
@breakpoint: screen;
28+
@media @breakpoint, print {
29+
body {
30+
margin: 0;
31+
}
32+
}
33+
34+
// Test evalRoot with ampersand handling
35+
.container {
36+
@media screen {
37+
& {
38+
color: red;
39+
}
40+
.child {
41+
color: blue;
42+
}
43+
}
44+
}
45+
46+
// Test evalRoot with mixed ampersands
47+
.wrapper {
48+
.inner {
49+
@media screen {
50+
& {
51+
color: green;
52+
}
53+
}
54+
}
55+
}
56+
57+
// Test genCSS with value
58+
@charset "UTF-8";
59+
60+
// Test genCSS with simpleBlock
61+
@page {
62+
margin: 2cm;
63+
size: A4;
64+
}
65+
66+
// Test genCSS with rules (non-simpleBlock)
67+
@supports (display: grid) {
68+
.grid {
69+
display: grid;
70+
}
71+
.flex {
72+
display: flex;
73+
}
74+
}
75+
76+
// Test isCharset
77+
@charset "UTF-8";
78+
79+
// Test isRulesetLike (non-charset)
80+
@media screen {
81+
body {
82+
color: black;
83+
}
84+
}
85+
86+
// Test compressed output (outputRuleset compressed path)
87+
@layer base {
88+
body {
89+
margin: 0;
90+
}
91+
p {
92+
padding: 0;
93+
}
94+
}
95+
96+
// Test variable/find/rulesets delegation
97+
@media screen {
98+
@var: value;
99+
.test {
100+
color: @var;
101+
}
102+
}
103+
104+
// Test eval with media bubbling
105+
@media screen {
106+
@media print {
107+
body {
108+
color: black;
109+
}
110+
}
111+
}
112+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
language: {
3+
less: {
4+
compress: true
5+
}
6+
}
7+
};
8+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.test {
2+
prop-name: color;
3+
my: background;
4+
value: width;
5+
color: red;
6+
border-color-width: 2px;
7+
*-z-color: 1px dashed blue;
8+
background-color-width: green;
9+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Test for ruleProperty parser with ${prop} interpolation (line 2640)
2+
// This tests complex property names using ${property} interpolation in property NAMES
3+
// ${prop} uses the VALUE of a plain property (not a variable) as the property name
4+
// Note: This is different from @{var} which uses variables
5+
6+
.test {
7+
// Define properties - their VALUES will be used as property names
8+
prop-name: color;
9+
my: background;
10+
value: width;
11+
12+
// Simple ${prop} interpolation in property name (ruleProperty parser line 2640)
13+
// ${prop-name} uses the value of prop-name ("color") as the property name
14+
// This triggers the branch at line 2640: new(tree.Property)(`$${s.slice(2, -1)}`, ...)
15+
${prop-name}: red;
16+
17+
// Multiple interpolations with literal parts
18+
// border-${prop-name} becomes "border-color" (since prop-name's value is "color")
19+
border-${prop-name}-width: 2px;
20+
21+
// Complex property name with ${prop}
22+
*-z-${prop-name}: 1px dashed blue;
23+
24+
// Multiple ${prop} in same property name
25+
// ${my}-${prop-name}-${value} becomes "background-color-width"
26+
${my}-${prop-name}-${value}: green;
27+
}
28+

0 commit comments

Comments
 (0)