Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3591: refactor debugInfo from class to function #3613

Merged
merged 3 commits into from Dec 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 29 additions & 30 deletions packages/less/src/less/tree/debug-info.js
@@ -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;