diff options
author | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2016-10-10 03:43:44 +0200 |
commit | abd94a7f5a50f43c797a11b53549ae48fff667c3 (patch) | |
tree | ab8ed457f65cdd72e13e0571d2975729428f1551 /node_modules/babel-code-frame | |
parent | a0247c6a3fd6a09a41a7e35a3441324c4dcb58be (diff) | |
download | wallet-core-abd94a7f5a50f43c797a11b53549ae48fff667c3.tar.xz |
add node_modules to address #4364
Diffstat (limited to 'node_modules/babel-code-frame')
-rw-r--r-- | node_modules/babel-code-frame/.npmignore | 3 | ||||
-rw-r--r-- | node_modules/babel-code-frame/README.md | 42 | ||||
-rw-r--r-- | node_modules/babel-code-frame/lib/index.js | 135 | ||||
-rw-r--r-- | node_modules/babel-code-frame/package.json | 102 |
4 files changed, 282 insertions, 0 deletions
diff --git a/node_modules/babel-code-frame/.npmignore b/node_modules/babel-code-frame/.npmignore new file mode 100644 index 000000000..47cdd2c65 --- /dev/null +++ b/node_modules/babel-code-frame/.npmignore @@ -0,0 +1,3 @@ +src +test +node_modules diff --git a/node_modules/babel-code-frame/README.md b/node_modules/babel-code-frame/README.md new file mode 100644 index 000000000..7e61e3ea5 --- /dev/null +++ b/node_modules/babel-code-frame/README.md @@ -0,0 +1,42 @@ +# babel-code-frame + +> Generate errors that contain a code frame that point to source locations. + +## Install + +```sh +$ npm install babel-code-frame +``` + +## Usage + +```js +import codeFrame from 'babel-code-frame'; + +const rawLines = `class Foo { + constructor() +}`; +const lineNumber = 2; +const colNumber = 16; + +const result = codeFrame(rawLines, lineNumber, colNumber, { /* options */ }); + +console.log(result); +``` + +```sh + 1 | class Foo { +> 2 | constructor() + | ^ + 3 | } +``` + +If the column number is not known, you may pass `null` instead. + +## Options + +name | type | default | description +-----------------------|----------|-----------------|------------------------------------------------------ +highlightCode | boolean | `false` | Syntax highlight the code as JavaScript for terminals +linesAbove | number | 2 | The number of lines to show above the error +linesBelow | number | 3 | The number of lines to show below the error diff --git a/node_modules/babel-code-frame/lib/index.js b/node_modules/babel-code-frame/lib/index.js new file mode 100644 index 000000000..54c838c3b --- /dev/null +++ b/node_modules/babel-code-frame/lib/index.js @@ -0,0 +1,135 @@ +"use strict"; + +exports.__esModule = true; + +exports.default = function (rawLines, lineNumber, colNumber) { + var opts = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3]; + + colNumber = Math.max(colNumber, 0); + + var highlighted = opts.highlightCode && _chalk2.default.supportsColor; + var maybeHighlight = function maybeHighlight(chalkFn, string) { + return highlighted ? chalkFn(string) : string; + }; + if (highlighted) rawLines = highlight(rawLines); + + var linesAbove = opts.linesAbove || 2; + var linesBelow = opts.linesBelow || 3; + + var lines = rawLines.split(NEWLINE); + var start = Math.max(lineNumber - (linesAbove + 1), 0); + var end = Math.min(lines.length, lineNumber + linesBelow); + + if (!lineNumber && !colNumber) { + start = 0; + end = lines.length; + } + + var numberMaxWidth = String(end).length; + + var frame = lines.slice(start, end).map(function (line, index) { + var number = start + 1 + index; + var paddedNumber = (" " + number).slice(-numberMaxWidth); + var gutter = " " + paddedNumber + " | "; + if (number === lineNumber) { + var markerLine = ""; + if (colNumber) { + var markerSpacing = line.slice(0, colNumber - 1).replace(/[^\t]/g, " "); + markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^")].join(""); + } + return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line, markerLine].join(""); + } else { + return " " + maybeHighlight(defs.gutter, gutter) + line; + } + }).join("\n"); + + if (highlighted) { + return _chalk2.default.reset(frame); + } else { + return frame; + } +}; + +var _jsTokens = require("js-tokens"); + +var _jsTokens2 = _interopRequireDefault(_jsTokens); + +var _esutils = require("esutils"); + +var _esutils2 = _interopRequireDefault(_esutils); + +var _chalk = require("chalk"); + +var _chalk2 = _interopRequireDefault(_chalk); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +var defs = { + keyword: _chalk2.default.cyan, + capitalized: _chalk2.default.yellow, + jsx_tag: _chalk2.default.yellow, + punctuator: _chalk2.default.yellow, + + number: _chalk2.default.magenta, + string: _chalk2.default.green, + regex: _chalk2.default.magenta, + comment: _chalk2.default.grey, + invalid: _chalk2.default.white.bgRed.bold, + gutter: _chalk2.default.grey, + marker: _chalk2.default.red.bold +}; + +var NEWLINE = /\r\n|[\n\r\u2028\u2029]/; + +var JSX_TAG = /^[a-z][\w-]*$/i; + +var BRACKET = /^[()\[\]{}]$/; + +function getTokenType(match) { + var _match$slice = match.slice(-2); + + var offset = _match$slice[0]; + var text = _match$slice[1]; + + var token = _jsTokens2.default.matchToToken(match); + + if (token.type === "name") { + if (_esutils2.default.keyword.isReservedWordES6(token.value)) { + return "keyword"; + } + + if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) { + return "jsx_tag"; + } + + if (token.value[0] !== token.value[0].toLowerCase()) { + return "capitalized"; + } + } + + if (token.type === "punctuator" && BRACKET.test(token.value)) { + return "bracket"; + } + + return token.type; +} + +function highlight(text) { + return text.replace(_jsTokens2.default, function () { + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + var type = getTokenType(args); + var colorize = defs[type]; + if (colorize) { + return args[0].split(NEWLINE).map(function (str) { + return colorize(str); + }).join("\n"); + } else { + return args[0]; + } + }); +} + +module.exports = exports["default"];
\ No newline at end of file diff --git a/node_modules/babel-code-frame/package.json b/node_modules/babel-code-frame/package.json new file mode 100644 index 000000000..386f59f2f --- /dev/null +++ b/node_modules/babel-code-frame/package.json @@ -0,0 +1,102 @@ +{ + "_args": [ + [ + { + "raw": "babel-code-frame@^6.16.0", + "scope": null, + "escapedName": "babel-code-frame", + "name": "babel-code-frame", + "rawSpec": "^6.16.0", + "spec": ">=6.16.0 <7.0.0", + "type": "range" + }, + "/home/dold/repos/taler/wallet-webex/node_modules/babel-traverse" + ] + ], + "_from": "babel-code-frame@>=6.16.0 <7.0.0", + "_id": "babel-code-frame@6.16.0", + "_inCache": true, + "_location": "/babel-code-frame", + "_nodeVersion": "5.11.1", + "_npmOperationalInternal": { + "host": "packages-16-east.internal.npmjs.com", + "tmp": "tmp/babel-code-frame-6.16.0.tgz_1475091527344_0.9727453696541488" + }, + "_npmUser": { + "name": "hzoo", + "email": "hi@henryzoo.com" + }, + "_npmVersion": "3.10.8", + "_phantomChildren": {}, + "_requested": { + "raw": "babel-code-frame@^6.16.0", + "scope": null, + "escapedName": "babel-code-frame", + "name": "babel-code-frame", + "rawSpec": "^6.16.0", + "spec": ">=6.16.0 <7.0.0", + "type": "range" + }, + "_requiredBy": [ + "/babel-traverse" + ], + "_resolved": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.16.0.tgz", + "_shasum": "f90e60da0862909d3ce098733b5d3987c97cb8de", + "_shrinkwrap": null, + "_spec": "babel-code-frame@^6.16.0", + "_where": "/home/dold/repos/taler/wallet-webex/node_modules/babel-traverse", + "author": { + "name": "Sebastian McKenzie", + "email": "sebmck@gmail.com" + }, + "dependencies": { + "chalk": "^1.1.0", + "esutils": "^2.0.2", + "js-tokens": "^2.0.0" + }, + "description": "Generate errors that contain a code frame that point to source locations.", + "devDependencies": {}, + "directories": {}, + "dist": { + "shasum": "f90e60da0862909d3ce098733b5d3987c97cb8de", + "tarball": "https://registry.npmjs.org/babel-code-frame/-/babel-code-frame-6.16.0.tgz" + }, + "homepage": "https://babeljs.io/", + "license": "MIT", + "main": "lib/index.js", + "maintainers": [ + { + "name": "amasad", + "email": "amjad.masad@gmail.com" + }, + { + "name": "hzoo", + "email": "hi@henryzoo.com" + }, + { + "name": "jmm", + "email": "npm-public@jessemccarthy.net" + }, + { + "name": "loganfsmyth", + "email": "loganfsmyth@gmail.com" + }, + { + "name": "sebmck", + "email": "sebmck@gmail.com" + }, + { + "name": "thejameskyle", + "email": "me@thejameskyle.com" + } + ], + "name": "babel-code-frame", + "optionalDependencies": {}, + "readme": "ERROR: No README data found!", + "repository": { + "type": "git", + "url": "https://github.com/babel/babel/tree/master/packages/babel-code-frame" + }, + "scripts": {}, + "version": "6.16.0" +} |