diff options
Diffstat (limited to 'node_modules/@babel/highlight/lib/index.js')
| -rw-r--r-- | node_modules/@babel/highlight/lib/index.js | 68 |
1 files changed, 41 insertions, 27 deletions
diff --git a/node_modules/@babel/highlight/lib/index.js b/node_modules/@babel/highlight/lib/index.js index a45bc5a8..944a0433 100644 --- a/node_modules/@babel/highlight/lib/index.js +++ b/node_modules/@babel/highlight/lib/index.js @@ -7,21 +7,23 @@ exports.default = highlight; exports.shouldHighlight = shouldHighlight; var _jsTokens = require("js-tokens"); 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; } +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 && {}.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 colors = typeof process === "object" && (process.env.FORCE_COLOR === "0" || process.env.FORCE_COLOR === "false") ? (0, _picocolors.createColors)(false) : _picocolors.default; +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) }; } const NEWLINE = /\r\n|[\n\r\u2028\u2029]/; @@ -34,7 +36,7 @@ let tokenize; if ((0, _helperValidatorIdentifier.isKeyword)(token.value) || (0, _helperValidatorIdentifier.isStrictReservedWord)(token.value, true) || sometimesKeywords.has(token.value)) { return "keyword"; } - if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.slice(offset - 2, offset) == "</")) { + if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.slice(offset - 2, offset) === "</")) { return "jsxIdentifier"; } if (token.value[0] !== token.value[0].toLowerCase()) { @@ -76,30 +78,42 @@ function highlightTokens(defs, text) { return highlighted; } function shouldHighlight(options) { - return _chalk.default.level > 0 || options.forceColor; + return colors.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; -} -{ - exports.getChalk = options => getChalk(options.forceColor); + return colors; } function highlight(code, options = {}) { if (code !== "" && shouldHighlight(options)) { - const defs = getDefs(getChalk(options.forceColor)); + const defs = getDefs(getColors(options.forceColor)); return highlightTokens(defs, code); } else { return code; } } +{ + 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 |
