"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = highlight; exports.shouldHighlight = shouldHighlight; var _jsTokens = require("js-tokens"); var _helperValidatorIdentifier = require("@babel/helper-validator-identifier"); var _chalk = _interopRequireWildcard(require("chalk"), 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 sometimesKeywords = new Set(["as", "async", "from", "get", "of", "set"]); function getDefs(chalk) { 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 }; } const NEWLINE = /\r\n|[\n\r\u2028\u2029]/; const BRACKET = /^[()[\]{}]$/; let tokenize; { const JSX_TAG = /^[a-z][\w-]*$/i; const getTokenType = function (token, offset, text) { if (token.type === "name") { 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) == " colorize(str)).join("\n"); } else { highlighted += value; } } return highlighted; } function shouldHighlight(options) { return _chalk.default.level > 0 || options.forceColor; } let chalkWithForcedColor = undefined; function getChalk(forceColor) { if (forceColor) { var _chalkWithForcedColor; (_chalkWithForcedColor = chalkWithForcedColor) != null ? _chalkWithForcedColor : chalkWithForcedColor = new _chalk.default.constructor({ enabled: true, level: 1 }); return chalkWithForcedColor; } return _chalk.default; } { exports.getChalk = options => getChalk(options.forceColor); } function highlight(code, options = {}) { if (code !== "" && shouldHighlight(options)) { const defs = getDefs(getChalk(options.forceColor)); return highlightTokens(defs, code); } else { return code; } } //# sourceMappingURL=index.js.map