Actualizacion maquina principal
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / @babel / highlight / lib / index.js
1 "use strict";
2
3 Object.defineProperty(exports, "__esModule", {
4   value: true
5 });
6 exports.shouldHighlight = shouldHighlight;
7 exports.getChalk = getChalk;
8 exports.default = highlight;
9
10 var _jsTokens = _interopRequireWildcard(require("js-tokens"));
11
12 var _helperValidatorIdentifier = require("@babel/helper-validator-identifier");
13
14 var _chalk = _interopRequireDefault(require("chalk"));
15
16 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
18 function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
19
20 function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
22 function getDefs(chalk) {
23   return {
24     keyword: chalk.cyan,
25     capitalized: chalk.yellow,
26     jsx_tag: chalk.yellow,
27     punctuator: chalk.yellow,
28     number: chalk.magenta,
29     string: chalk.green,
30     regex: chalk.magenta,
31     comment: chalk.grey,
32     invalid: chalk.white.bgRed.bold
33   };
34 }
35
36 const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
37 const JSX_TAG = /^[a-z][\w-]*$/i;
38 const BRACKET = /^[()[\]{}]$/;
39
40 function getTokenType(match) {
41   const [offset, text] = match.slice(-2);
42   const token = (0, _jsTokens.matchToToken)(match);
43
44   if (token.type === "name") {
45     if ((0, _helperValidatorIdentifier.isKeyword)(token.value) || (0, _helperValidatorIdentifier.isReservedWord)(token.value)) {
46       return "keyword";
47     }
48
49     if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) {
50       return "jsx_tag";
51     }
52
53     if (token.value[0] !== token.value[0].toLowerCase()) {
54       return "capitalized";
55     }
56   }
57
58   if (token.type === "punctuator" && BRACKET.test(token.value)) {
59     return "bracket";
60   }
61
62   if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
63     return "punctuator";
64   }
65
66   return token.type;
67 }
68
69 function highlightTokens(defs, text) {
70   return text.replace(_jsTokens.default, function (...args) {
71     const type = getTokenType(args);
72     const colorize = defs[type];
73
74     if (colorize) {
75       return args[0].split(NEWLINE).map(str => colorize(str)).join("\n");
76     } else {
77       return args[0];
78     }
79   });
80 }
81
82 function shouldHighlight(options) {
83   return _chalk.default.supportsColor || options.forceColor;
84 }
85
86 function getChalk(options) {
87   let chalk = _chalk.default;
88
89   if (options.forceColor) {
90     chalk = new _chalk.default.constructor({
91       enabled: true,
92       level: 1
93     });
94   }
95
96   return chalk;
97 }
98
99 function highlight(code, options = {}) {
100   if (shouldHighlight(options)) {
101     const chalk = getChalk(options);
102     const defs = getDefs(chalk);
103     return highlightTokens(defs, code);
104   } else {
105     return code;
106   }
107 }