babel-code-frame
Advanced tools
Comparing version 6.16.0 to 6.20.0
@@ -6,11 +6,16 @@ "use strict"; | ||
exports.default = function (rawLines, lineNumber, colNumber) { | ||
var opts = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; | ||
var opts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
colNumber = Math.max(colNumber, 0); | ||
var highlighted = opts.highlightCode && _chalk2.default.supportsColor; | ||
var highlighted = opts.highlightCode && _chalk2.default.supportsColor || opts.forceColor; | ||
var chalk = _chalk2.default; | ||
if (opts.forceColor) { | ||
chalk = new _chalk2.default.constructor({ enabled: true }); | ||
} | ||
var maybeHighlight = function maybeHighlight(chalkFn, string) { | ||
return highlighted ? chalkFn(string) : string; | ||
}; | ||
if (highlighted) rawLines = highlight(rawLines); | ||
var defs = getDefs(chalk); | ||
if (highlighted) rawLines = highlight(defs, rawLines); | ||
@@ -48,3 +53,3 @@ var linesAbove = opts.linesAbove || 2; | ||
if (highlighted) { | ||
return _chalk2.default.reset(frame); | ||
return chalk.reset(frame); | ||
} else { | ||
@@ -69,16 +74,18 @@ return frame; | ||
var defs = { | ||
keyword: _chalk2.default.cyan, | ||
capitalized: _chalk2.default.yellow, | ||
jsx_tag: _chalk2.default.yellow, | ||
punctuator: _chalk2.default.yellow, | ||
function getDefs(chalk) { | ||
return { | ||
keyword: chalk.cyan, | ||
capitalized: chalk.yellow, | ||
jsx_tag: chalk.yellow, | ||
punctuator: chalk.yellow, | ||
number: _chalk2.default.magenta, | ||
string: _chalk2.default.green, | ||
regex: _chalk2.default.magenta, | ||
comment: _chalk2.default.grey, | ||
invalid: _chalk2.default.white.bgRed.bold, | ||
gutter: _chalk2.default.grey, | ||
marker: _chalk2.default.red.bold | ||
}; | ||
number: chalk.magenta, | ||
string: chalk.green, | ||
regex: chalk.magenta, | ||
comment: chalk.grey, | ||
invalid: chalk.white.bgRed.bold, | ||
gutter: chalk.grey, | ||
marker: chalk.red.bold | ||
}; | ||
} | ||
@@ -92,7 +99,6 @@ var NEWLINE = /\r\n|[\n\r\u2028\u2029]/; | ||
function getTokenType(match) { | ||
var _match$slice = match.slice(-2); | ||
var _match$slice = match.slice(-2), | ||
offset = _match$slice[0], | ||
text = _match$slice[1]; | ||
var offset = _match$slice[0]; | ||
var text = _match$slice[1]; | ||
var token = _jsTokens2.default.matchToToken(match); | ||
@@ -121,3 +127,3 @@ | ||
function highlight(text) { | ||
function highlight(defs, text) { | ||
return text.replace(_jsTokens2.default, function () { | ||
@@ -124,0 +130,0 @@ for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { |
{ | ||
"name": "babel-code-frame", | ||
"version": "6.16.0", | ||
"version": "6.20.0", | ||
"description": "Generate errors that contain a code frame that point to source locations.", | ||
@@ -5,0 +5,0 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>", |
@@ -8,3 +8,3 @@ # babel-code-frame | ||
```sh | ||
$ npm install babel-code-frame | ||
npm install --save-dev babel-code-frame | ||
``` | ||
@@ -44,1 +44,2 @@ | ||
linesBelow | number | 3 | The number of lines to show below the error | ||
forceColor | boolean | `false` | Forcibly syntax highlight the code as JavaScript (for non-terminals); overrides highlightCode |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5531
108
44