Skip to content

Commit

Permalink
Fix #3591: refactor debugInfo from class to function (#3613)
Browse files Browse the repository at this point in the history
* Fix #3591: refactor debugInfo from class to function

* chore: add newline

* chore: trigger ci

Co-authored-by: drdevlin <drdevlin@fastmail.com>
Co-authored-by: Lei Chen <chenleicoder@foxmail.com>
  • Loading branch information
3 people committed Dec 30, 2021
1 parent 7fc6a1d commit ce973cd
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions packages/less/src/less/tree/debug-info.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
class debugInfo {
constructor(context, ctx, lineSeparator) {
let result = '';
if (context.dumpLineNumbers && !context.compress) {
switch (context.dumpLineNumbers) {
case 'comments':
result = debugInfo.asComment(ctx);
break;
case 'mediaquery':
result = debugInfo.asMediaQuery(ctx);
break;
case 'all':
result = debugInfo.asComment(ctx) + (lineSeparator || '') + debugInfo.asMediaQuery(ctx);
break;
}
}
return result;
}
function asComment(ctx) {
return `/* line ${ctx.debugInfo.lineNumber}, ${ctx.debugInfo.fileName} */\n`;
}

static asComment(ctx) {
return `/* line ${ctx.debugInfo.lineNumber}, ${ctx.debugInfo.fileName} */\n`;
function asMediaQuery(ctx) {
let filenameWithProtocol = ctx.debugInfo.fileName;
if (!/^[a-z]+:\/\//i.test(filenameWithProtocol)) {
filenameWithProtocol = `file://${filenameWithProtocol}`;
}
return `@media -sass-debug-info{filename{font-family:${filenameWithProtocol.replace(/([.:\/\\])/g, function (a) {
if (a == '\\') {
a = '\/';
}
return `\\${a}`;
})}}line{font-family:\\00003${ctx.debugInfo.lineNumber}}}\n`;
}

static asMediaQuery(ctx) {
let filenameWithProtocol = ctx.debugInfo.fileName;
if (!/^[a-z]+:\/\//i.test(filenameWithProtocol)) {
filenameWithProtocol = `file://${filenameWithProtocol}`;
function debugInfo(context, ctx, lineSeparator) {
let result = '';
if (context.dumpLineNumbers && !context.compress) {
switch (context.dumpLineNumbers) {
case 'comments':
result = asComment(ctx);
break;
case 'mediaquery':
result = asMediaQuery(ctx);
break;
case 'all':
result = asComment(ctx) + (lineSeparator || '') + asMediaQuery(ctx);
break;
}
return `@media -sass-debug-info{filename{font-family:${filenameWithProtocol.replace(/([.:\/\\])/g, function (a) {
if (a == '\\') {
a = '\/';
}
return `\\${a}`;
})}}line{font-family:\\00003${ctx.debugInfo.lineNumber}}}\n`;
}
return result;
}

export default debugInfo;

0 comments on commit ce973cd

Please sign in to comment.