@babel/highlight
Advanced tools
Comparing version 7.23.4 to 7.24.1
@@ -10,17 +10,18 @@ "use strict"; | ||
var _helperValidatorIdentifier = require("@babel/helper-validator-identifier"); | ||
var _chalk = _interopRequireWildcard(require("chalk"), true); | ||
var _picocolors = _interopRequireWildcard(require("picocolors"), true); | ||
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); } | ||
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } | ||
const compose = (f, g) => v => f(g(v)); | ||
const sometimesKeywords = new Set(["as", "async", "from", "get", "of", "set"]); | ||
function getDefs(chalk) { | ||
function getDefs(colors) { | ||
return { | ||
keyword: chalk.cyan, | ||
capitalized: chalk.yellow, | ||
jsxIdentifier: chalk.yellow, | ||
punctuator: chalk.yellow, | ||
number: chalk.magenta, | ||
string: chalk.green, | ||
regex: chalk.magenta, | ||
comment: chalk.grey, | ||
invalid: chalk.white.bgRed.bold | ||
keyword: colors.cyan, | ||
capitalized: colors.yellow, | ||
jsxIdentifier: colors.yellow, | ||
punctuator: colors.yellow, | ||
number: colors.magenta, | ||
string: colors.green, | ||
regex: colors.magenta, | ||
comment: colors.gray, | ||
invalid: compose(compose(colors.white, colors.bgRed), colors.bold) | ||
}; | ||
@@ -80,22 +81,16 @@ } | ||
function shouldHighlight(options) { | ||
return _chalk.default.level > 0 || options.forceColor; | ||
return _picocolors.default.isColorSupported || options.forceColor; | ||
} | ||
let chalkWithForcedColor = undefined; | ||
function getChalk(forceColor) { | ||
let pcWithForcedColor = undefined; | ||
function getColors(forceColor) { | ||
if (forceColor) { | ||
var _chalkWithForcedColor; | ||
(_chalkWithForcedColor = chalkWithForcedColor) != null ? _chalkWithForcedColor : chalkWithForcedColor = new _chalk.default.constructor({ | ||
enabled: true, | ||
level: 1 | ||
}); | ||
return chalkWithForcedColor; | ||
var _pcWithForcedColor; | ||
(_pcWithForcedColor = pcWithForcedColor) != null ? _pcWithForcedColor : pcWithForcedColor = (0, _picocolors.createColors)(true); | ||
return pcWithForcedColor; | ||
} | ||
return _chalk.default; | ||
return _picocolors.default; | ||
} | ||
{ | ||
exports.getChalk = options => getChalk(options.forceColor); | ||
} | ||
function highlight(code, options = {}) { | ||
if (code !== "" && shouldHighlight(options)) { | ||
const defs = getDefs(getChalk(options.forceColor)); | ||
const defs = getDefs(getColors(options.forceColor)); | ||
return highlightTokens(defs, code); | ||
@@ -106,3 +101,21 @@ } else { | ||
} | ||
{ | ||
let chalk, chalkWithForcedColor; | ||
exports.getChalk = ({ | ||
forceColor | ||
}) => { | ||
var _chalk; | ||
(_chalk = chalk) != null ? _chalk : chalk = require("chalk"); | ||
if (forceColor) { | ||
var _chalkWithForcedColor; | ||
(_chalkWithForcedColor = chalkWithForcedColor) != null ? _chalkWithForcedColor : chalkWithForcedColor = new chalk.constructor({ | ||
enabled: true, | ||
level: 1 | ||
}); | ||
return chalkWithForcedColor; | ||
} | ||
return chalk; | ||
}; | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@babel/highlight", | ||
"version": "7.23.4", | ||
"version": "7.24.1", | ||
"description": "Syntax highlight JavaScript strings for output in terminals.", | ||
@@ -20,3 +20,4 @@ "author": "The Babel Team (https://babel.dev/team)", | ||
"chalk": "^2.4.2", | ||
"js-tokens": "^4.0.0" | ||
"js-tokens": "^4.0.0", | ||
"picocolors": "^1.0.0" | ||
}, | ||
@@ -23,0 +24,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
19777
117
4
+ Addedpicocolors@^1.0.0
+ Addedpicocolors@1.0.1(transitive)