Skip to content

Commit 063ef68

Browse files
committed
Fix less#3591: refactor debugInfo from class to function
1 parent b37922c commit 063ef68

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed
+29-31
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,36 @@
1-
class debugInfo {
2-
constructor(context, ctx, lineSeparator) {
3-
let result = '';
4-
if (context.dumpLineNumbers && !context.compress) {
5-
switch (context.dumpLineNumbers) {
6-
case 'comments':
7-
result = debugInfo.asComment(ctx);
8-
break;
9-
case 'mediaquery':
10-
result = debugInfo.asMediaQuery(ctx);
11-
break;
12-
case 'all':
13-
result = debugInfo.asComment(ctx) + (lineSeparator || '') + debugInfo.asMediaQuery(ctx);
14-
break;
15-
}
16-
}
17-
return result;
18-
}
1+
function asComment(ctx) {
2+
return `/* line ${ctx.debugInfo.lineNumber}, ${ctx.debugInfo.fileName} */\n`;
3+
}
194

20-
static asComment(ctx) {
21-
return `/* line ${ctx.debugInfo.lineNumber}, ${ctx.debugInfo.fileName} */\n`;
5+
function asMediaQuery(ctx) {
6+
let filenameWithProtocol = ctx.debugInfo.fileName;
7+
if (!/^[a-z]+:\/\//i.test(filenameWithProtocol)) {
8+
filenameWithProtocol = `file://${filenameWithProtocol}`;
229
}
10+
return `@media -sass-debug-info{filename{font-family:${filenameWithProtocol.replace(/([.:\/\\])/g, function (a) {
11+
if (a == '\\') {
12+
a = '\/';
13+
}
14+
return `\\${a}`;
15+
})}}line{font-family:\\00003${ctx.debugInfo.lineNumber}}}\n`;
16+
}
2317

24-
static asMediaQuery(ctx) {
25-
let filenameWithProtocol = ctx.debugInfo.fileName;
26-
if (!/^[a-z]+:\/\//i.test(filenameWithProtocol)) {
27-
filenameWithProtocol = `file://${filenameWithProtocol}`;
18+
function debugInfo(context, ctx, lineSeparator) {
19+
let result = '';
20+
if (context.dumpLineNumbers && !context.compress) {
21+
switch (context.dumpLineNumbers) {
22+
case 'comments':
23+
result = asComment(ctx);
24+
break;
25+
case 'mediaquery':
26+
result = asMediaQuery(ctx);
27+
break;
28+
case 'all':
29+
result = asComment(ctx) + (lineSeparator || '') + asMediaQuery(ctx);
30+
break;
2831
}
29-
return `@media -sass-debug-info{filename{font-family:${filenameWithProtocol.replace(/([.:\/\\])/g, function (a) {
30-
if (a == '\\') {
31-
a = '\/';
32-
}
33-
return `\\${a}`;
34-
})}}line{font-family:\\00003${ctx.debugInfo.lineNumber}}}\n`;
3532
}
33+
return result;
3634
}
3735

38-
export default debugInfo;
36+
export default debugInfo;

0 commit comments

Comments
 (0)