@babel/highlight
Advanced tools
Comparing version 7.0.0-beta.43 to 7.0.0-beta.44
@@ -11,5 +11,5 @@ "use strict"; | ||
function _jsTokens() { | ||
const data = _interopRequireWildcard(require("js-tokens")); | ||
var data = _interopRequireWildcard(require("js-tokens")); | ||
_jsTokens = function () { | ||
_jsTokens = function _jsTokens() { | ||
return data; | ||
@@ -22,5 +22,5 @@ }; | ||
function _esutils() { | ||
const data = _interopRequireDefault(require("esutils")); | ||
var data = _interopRequireDefault(require("esutils")); | ||
_esutils = function () { | ||
_esutils = function _esutils() { | ||
return data; | ||
@@ -33,5 +33,5 @@ }; | ||
function _chalk() { | ||
const data = _interopRequireDefault(require("chalk")); | ||
var data = _interopRequireDefault(require("chalk")); | ||
_chalk = function () { | ||
_chalk = function _chalk() { | ||
return data; | ||
@@ -61,10 +61,13 @@ }; | ||
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/; | ||
const JSX_TAG = /^[a-z][\w-]*$/i; | ||
const BRACKET = /^[()[\]{}]$/; | ||
var NEWLINE = /\r\n|[\n\r\u2028\u2029]/; | ||
var JSX_TAG = /^[a-z][\w-]*$/i; | ||
var BRACKET = /^[()[\]{}]$/; | ||
function getTokenType(match) { | ||
const [offset, text] = match.slice(-2); | ||
const token = (0, _jsTokens().matchToToken)(match); | ||
var _match$slice = match.slice(-2), | ||
offset = _match$slice[0], | ||
text = _match$slice[1]; | ||
var token = (0, _jsTokens().matchToToken)(match); | ||
if (token.type === "name") { | ||
@@ -96,8 +99,14 @@ if (_esutils().default.keyword.isReservedWordES6(token.value)) { | ||
function highlightTokens(defs, text) { | ||
return text.replace(_jsTokens().default, function (...args) { | ||
const type = getTokenType(args); | ||
const colorize = defs[type]; | ||
return text.replace(_jsTokens().default, function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var type = getTokenType(args); | ||
var colorize = defs[type]; | ||
if (colorize) { | ||
return args[0].split(NEWLINE).map(str => colorize(str)).join("\n"); | ||
return args[0].split(NEWLINE).map(function (str) { | ||
return colorize(str); | ||
}).join("\n"); | ||
} else { | ||
@@ -114,3 +123,3 @@ return args[0]; | ||
function getChalk(options) { | ||
let chalk = _chalk().default; | ||
var chalk = _chalk().default; | ||
@@ -127,6 +136,10 @@ if (options.forceColor) { | ||
function highlight(code, options = {}) { | ||
function highlight(code, options) { | ||
if (options === void 0) { | ||
options = {}; | ||
} | ||
if (shouldHighlight(options)) { | ||
const chalk = getChalk(options); | ||
const defs = getDefs(chalk); | ||
var chalk = getChalk(options); | ||
var defs = getDefs(chalk); | ||
return highlightTokens(defs, code); | ||
@@ -133,0 +146,0 @@ } else { |
{ | ||
"name": "@babel/highlight", | ||
"version": "7.0.0-beta.43", | ||
"version": "7.0.0-beta.44", | ||
"description": "Syntax highlight JavaScript strings for output in terminals.", | ||
@@ -5,0 +5,0 @@ "author": "suchipi <me@suchipi.com>", |
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
4636
111