Legend:
- Unmodified
- Added
- Removed
-
imaps-frontend/node_modules/@babel/code-frame/lib/index.js
rd565449 r0c6b92a 1 "use strict";2 3 Object.defineProperty(exports, "__esModule", {4 value: true 5 });6 exports.codeFrameColumns = codeFrameColumns;7 exports.default = _default;8 var _highlight = require("@babel/highlight"); 9 var _picocolors = _interopRequireWildcard(require("picocolors"), true); 10 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); } 11 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; } 12 const colors = typeof process === "object" && (process.env.FORCE_COLOR === "0" || process.env.FORCE_COLOR === "false") ? (0, _picocolors.createColors)(false) : _picocolors.default; 1 'use strict'; 2 3 Object.defineProperty(exports, '__esModule', { value: true }); 4 5 var picocolors = require('picocolors'); 6 var jsTokens = require('js-tokens'); 7 var helperValidatorIdentifier = require('@babel/helper-validator-identifier'); 8 9 function isColorSupported() { 10 return (typeof process === "object" && (process.env.FORCE_COLOR === "0" || process.env.FORCE_COLOR === "false") ? false : picocolors.isColorSupported 11 ); 12 } 13 13 const compose = (f, g) => v => f(g(v)); 14 let pcWithForcedColor = undefined; 15 function getColors(forceColor) { 16 if (forceColor) { 17 var _pcWithForcedColor; 18 (_pcWithForcedColor = pcWithForcedColor) != null ? _pcWithForcedColor : pcWithForcedColor = (0, _picocolors.createColors)(true); 19 return pcWithForcedColor; 20 } 21 return colors; 22 } 23 let deprecationWarningShown = false; 24 function getDefs(colors) { 14 function buildDefs(colors) { 25 15 return { 16 keyword: colors.cyan, 17 capitalized: colors.yellow, 18 jsxIdentifier: colors.yellow, 19 punctuator: colors.yellow, 20 number: colors.magenta, 21 string: colors.green, 22 regex: colors.magenta, 23 comment: colors.gray, 24 invalid: compose(compose(colors.white, colors.bgRed), colors.bold), 26 25 gutter: colors.gray, 27 26 marker: compose(colors.red, colors.bold), 28 message: compose(colors.red, colors.bold) 29 }; 30 } 27 message: compose(colors.red, colors.bold), 28 reset: colors.reset 29 }; 30 } 31 const defsOn = buildDefs(picocolors.createColors(true)); 32 const defsOff = buildDefs(picocolors.createColors(false)); 33 function getDefs(enabled) { 34 return enabled ? defsOn : defsOff; 35 } 36 37 const sometimesKeywords = new Set(["as", "async", "from", "get", "of", "set"]); 38 const NEWLINE$1 = /\r\n|[\n\r\u2028\u2029]/; 39 const BRACKET = /^[()[\]{}]$/; 40 let tokenize; 41 { 42 const JSX_TAG = /^[a-z][\w-]*$/i; 43 const getTokenType = function (token, offset, text) { 44 if (token.type === "name") { 45 if (helperValidatorIdentifier.isKeyword(token.value) || helperValidatorIdentifier.isStrictReservedWord(token.value, true) || sometimesKeywords.has(token.value)) { 46 return "keyword"; 47 } 48 if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.slice(offset - 2, offset) === "</")) { 49 return "jsxIdentifier"; 50 } 51 if (token.value[0] !== token.value[0].toLowerCase()) { 52 return "capitalized"; 53 } 54 } 55 if (token.type === "punctuator" && BRACKET.test(token.value)) { 56 return "bracket"; 57 } 58 if (token.type === "invalid" && (token.value === "@" || token.value === "#")) { 59 return "punctuator"; 60 } 61 return token.type; 62 }; 63 tokenize = function* (text) { 64 let match; 65 while (match = jsTokens.default.exec(text)) { 66 const token = jsTokens.matchToToken(match); 67 yield { 68 type: getTokenType(token, match.index, text), 69 value: token.value 70 }; 71 } 72 }; 73 } 74 function highlight(text) { 75 if (text === "") return ""; 76 const defs = getDefs(true); 77 let highlighted = ""; 78 for (const { 79 type, 80 value 81 } of tokenize(text)) { 82 if (type in defs) { 83 highlighted += value.split(NEWLINE$1).map(str => defs[type](str)).join("\n"); 84 } else { 85 highlighted += value; 86 } 87 } 88 return highlighted; 89 } 90 91 let deprecationWarningShown = false; 31 92 const NEWLINE = /\r\n|[\n\r\u2028\u2029]/; 32 93 function getMarkerLines(loc, source, opts) { … … 87 148 } 88 149 function codeFrameColumns(rawLines, loc, opts = {}) { 89 const highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight.shouldHighlight)(opts); 90 const colors = getColors(opts.forceColor); 91 const defs = getDefs(colors); 92 const maybeHighlight = (fmt, string) => { 93 return highlighted ? fmt(string) : string; 94 }; 150 const shouldHighlight = opts.forceColor || isColorSupported() && opts.highlightCode; 151 const defs = getDefs(shouldHighlight); 95 152 const lines = rawLines.split(NEWLINE); 96 153 const { … … 101 158 const hasColumns = loc.start && typeof loc.start.column === "number"; 102 159 const numberMaxWidth = String(end).length; 103 const highlightedLines = highlighted ? (0, _highlight.default)(rawLines, opts) : rawLines;160 const highlightedLines = shouldHighlight ? highlight(rawLines) : rawLines; 104 161 let frame = highlightedLines.split(NEWLINE, end).slice(start, end).map((line, index) => { 105 162 const number = start + 1 + index; … … 113 170 const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " "); 114 171 const numberOfMarkers = hasMarker[1] || 1; 115 markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), " ", markerSpacing, maybeHighlight(defs.marker,"^").repeat(numberOfMarkers)].join("");172 markerLine = ["\n ", defs.gutter(gutter.replace(/\d/g, " ")), " ", markerSpacing, defs.marker("^").repeat(numberOfMarkers)].join(""); 116 173 if (lastMarkerLine && opts.message) { 117 markerLine += " " + maybeHighlight(defs.message,opts.message);174 markerLine += " " + defs.message(opts.message); 118 175 } 119 176 } 120 return [ maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter,gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");121 } else { 122 return ` ${ maybeHighlight(defs.gutter,gutter)}${line.length > 0 ? ` ${line}` : ""}`;177 return [defs.marker(">"), defs.gutter(gutter), line.length > 0 ? ` ${line}` : "", markerLine].join(""); 178 } else { 179 return ` ${defs.gutter(gutter)}${line.length > 0 ? ` ${line}` : ""}`; 123 180 } 124 181 }).join("\n"); … … 126 183 frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`; 127 184 } 128 if ( highlighted) {129 return colors.reset(frame);185 if (shouldHighlight) { 186 return defs.reset(frame); 130 187 } else { 131 188 return frame; 132 189 } 133 190 } 134 function _default(rawLines, lineNumber, colNumber, opts = {}) {191 function index (rawLines, lineNumber, colNumber, opts = {}) { 135 192 if (!deprecationWarningShown) { 136 193 deprecationWarningShown = true; … … 154 211 } 155 212 213 exports.codeFrameColumns = codeFrameColumns; 214 exports.default = index; 215 exports.highlight = highlight; 156 216 //# sourceMappingURL=index.js.map
Note:
See TracChangeset
for help on using the changeset viewer.