Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.client.Debugger.getScriptSource({ scriptId: frame.location.scriptId }, function(err, resp) {
self.writeLn('break in ' + [lineNumber, columnNumber].join(':'))
var startLine = lineNumber - NUM_LINES;
var lastLine = lineNumber + NUM_LINES;
var out = [];
var src = cardinal.highlight(resp.scriptSource, {
theme: resolveCardinalTheme()
}).split('\n');
for (var i=startLine; i < lastLine; ++i) {
var prefix = pad(lastLine, lineNumber, i);
var bpsForLine = self.breakpointsForLocation({
scriptId: frame.location.scriptId,
lineNumber: i
});
if (bpsForLine) {
prefix = prefix.red;
}
if (src[i])
out.push(prefix + src[i]);
}
self.writeLn(out.join('\n'));
// TODO mark current column with underline?
codes.forEach(function (cur) {
try {
var tmp = cur.replace(/\<(\/)?(code|pre)\>/g, '').replace(/\&\;/g, '&').replace(/(^|\n)( +)?\#/g, '$1$2\/\/'); // lines starting with #
replacement = cardinal.highlight(tmp, {
linenos: true
});
} catch (e) {
replacement = require('./highlighter.js').highlight(cur.replace(/\<(\/)?(code|pre)\>/g, ''));
// not able to highlight it...ok, let's go on!
replacement = replacement.replace(/\<(\/)?(code|pre)\>/g, '');
}
finalStr = finalStr.replace(cur, CODE_START + CODE_LINE + replacement.replace(/\n/g, CODE_LINE) + CODE_END);
});
})();
function emitHighlightedCode(src, format) {
if (config.highlight) {
// force 'compact' since there is no point in sourcing entire code if we printed it highlighted already
format.compact = true;
try {
stdout.write(cardinal.highlight(src, { linenos: true }) + '\n');
} catch(e) { }
}
}
function printDetails(src, tgt, upgraded) {
console.log(
cardinal.highlight(src) + '\n' +
'==========\nexpected:\n' +
cardinal.highlight(tgt) + '\n' +
'==========\nactual:\n' +
cardinal.highlight(upgraded)
);
}
function run(t, fixture, opts) {
var file = path.join(fixtures, fixture)
, src = fs.readFileSync(file + '.js', 'utf-8')
, tgt = fs.readFileSync(file + '.upgraded.js', 'utf-8').trim('\n')
, upgraded = upgrade(src, opts || defOpts, resolvePath).trim('\n');
t.equals(cardinal.highlight(upgraded), cardinal.highlight(tgt), 'upgrades ' + fixture + '\n')
t.end()
}
let render = (lesson) => {
clear();
console.log(chalk.green(lesson.title));
for (let step of lesson.gyan) {
if (step.type === 'text') console.log(step.value);
else if (step.type === 'code') console.log(cardinal.highlight(step.value));
else if (step.type === 'break') pause();
else if (step.type === 'clear') clear();
}
};
module.exports = (diag) => {
if (!diag || typeof diag.source !== 'string')
return null
if (!diag.source || !diag.at || !diag.at.line || !diag.at.file)
return diag.source
const source = diag.source
const at = diag.at
try {
const lines = highlightFileSync(at.file, {
jsx: true,
theme,
}).split('\n')
const ctx = 3
const startLine = Math.max(at.line - ctx, 0)
const endLine = Math.min(at.line + ctx, lines.length)
const numLen = endLine.toString().length + 1
const caret = at.column
? [
` ${new Array(numLen).join(' ')
} ` + hex('#777')('| ') +
red(`${new Array(at.column).join('-')}${bold('^')}`)
] : []
function tryHighlight(s) {
try {
return cardinal.highlight(s, { linenos: false });
} catch (e) {
return null;
}
}
function highlightSource(s) {
try {
return cardinal.highlight(s, { lineno: true });
} catch (e) {
return s;
}
}