forked from less/less.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Fix less#3591: refactor debugInfo from class to function * chore: add newline * chore: trigger ci Co-authored-by: drdevlin <[email protected]> Co-authored-by: Lei Chen <[email protected]>
- Loading branch information
1 parent
7fc6a1d
commit ce973cd
Showing
1 changed file
with
29 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|