Socket
Socket
Sign inDemoInstall

@babel/code-frame

Package Overview
Dependencies
10
Maintainers
5
Versions
69
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 7.0.0-beta.46 to 7.0.0-beta.47

114

lib/index.js

@@ -10,3 +10,3 @@ "use strict";

function _highlight() {
var data = _interopRequireWildcard(require("@babel/highlight"));
const data = _interopRequireWildcard(require("@babel/highlight"));

@@ -22,3 +22,3 @@ _highlight = function _highlight() {

var deprecationWarningShown = false;
let deprecationWarningShown = false;

@@ -33,23 +33,23 @@ function getDefs(chalk) {

var NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
function getMarkerLines(loc, source, opts) {
var startLoc = Object.assign({}, {
const startLoc = Object.assign({
column: 0,
line: -1
}, loc.start);
var endLoc = Object.assign({}, startLoc, loc.end);
const endLoc = Object.assign({}, startLoc, loc.end);
var _ref = opts || {},
_ref$linesAbove = _ref.linesAbove,
linesAbove = _ref$linesAbove === void 0 ? 2 : _ref$linesAbove,
_ref$linesBelow = _ref.linesBelow,
linesBelow = _ref$linesBelow === void 0 ? 3 : _ref$linesBelow;
const _ref = opts || {},
_ref$linesAbove = _ref.linesAbove,
linesAbove = _ref$linesAbove === void 0 ? 2 : _ref$linesAbove,
_ref$linesBelow = _ref.linesBelow,
linesBelow = _ref$linesBelow === void 0 ? 3 : _ref$linesBelow;
var startLine = startLoc.line;
var startColumn = startLoc.column;
var endLine = endLoc.line;
var endColumn = endLoc.column;
var start = Math.max(startLine - (linesAbove + 1), 0);
var end = Math.min(source.length, endLine + linesBelow);
const startLine = startLoc.line;
const startColumn = startLoc.column;
const endLine = endLoc.line;
const endColumn = endLoc.column;
let start = Math.max(startLine - (linesAbove + 1), 0);
let end = Math.min(source.length, endLine + linesBelow);

@@ -64,8 +64,8 @@ if (startLine === -1) {

var lineDiff = endLine - startLine;
var markerLines = {};
const lineDiff = endLine - startLine;
const markerLines = {};
if (lineDiff) {
for (var i = 0; i <= lineDiff; i++) {
var lineNumber = i + startLine;
for (let i = 0; i <= lineDiff; i++) {
const lineNumber = i + startLine;

@@ -75,3 +75,3 @@ if (!startColumn) {

} else if (i === 0) {
var sourceLength = source[lineNumber - 1].length;
const sourceLength = source[lineNumber - 1].length;
markerLines[lineNumber] = [startColumn, sourceLength - startColumn];

@@ -81,4 +81,4 @@ } else if (i === lineDiff) {

} else {
var _sourceLength = source[lineNumber - i].length;
markerLines[lineNumber] = [0, _sourceLength];
const sourceLength = source[lineNumber - i].length;
markerLines[lineNumber] = [0, sourceLength];
}

@@ -99,18 +99,14 @@ }

return {
start: start,
end: end,
markerLines: markerLines
start,
end,
markerLines
};
}
function codeFrameColumns(rawLines, loc, opts) {
if (opts === void 0) {
opts = {};
}
function codeFrameColumns(rawLines, loc, opts = {}) {
const highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight().shouldHighlight)(opts);
const chalk = (0, _highlight().getChalk)(opts);
const defs = getDefs(chalk);
var highlighted = (opts.highlightCode || opts.forceColor) && (0, _highlight().shouldHighlight)(opts);
var chalk = (0, _highlight().getChalk)(opts);
var defs = getDefs(chalk);
var maybeHighlight = function maybeHighlight(chalkFn, string) {
const maybeHighlight = (chalkFn, string) => {
return highlighted ? chalkFn(string) : string;

@@ -120,24 +116,24 @@ };

if (highlighted) rawLines = (0, _highlight().default)(rawLines, opts);
var lines = rawLines.split(NEWLINE);
const lines = rawLines.split(NEWLINE);
var _getMarkerLines = getMarkerLines(loc, lines, opts),
start = _getMarkerLines.start,
end = _getMarkerLines.end,
markerLines = _getMarkerLines.markerLines;
const _getMarkerLines = getMarkerLines(loc, lines, opts),
start = _getMarkerLines.start,
end = _getMarkerLines.end,
markerLines = _getMarkerLines.markerLines;
var hasColumns = loc.start && typeof loc.start.column === "number";
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 + " | ";
var hasMarker = markerLines[number];
var lastMarkerLine = !markerLines[number + 1];
const hasColumns = loc.start && typeof loc.start.column === "number";
const numberMaxWidth = String(end).length;
let frame = lines.slice(start, end).map((line, index) => {
const number = start + 1 + index;
const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
const gutter = ` ${paddedNumber} | `;
const hasMarker = markerLines[number];
const lastMarkerLine = !markerLines[number + 1];
if (hasMarker) {
var markerLine = "";
let markerLine = "";
if (Array.isArray(hasMarker)) {
var markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
var numberOfMarkers = hasMarker[1] || 1;
const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
const numberOfMarkers = hasMarker[1] || 1;
markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");

@@ -152,3 +148,3 @@

} else {
return " " + maybeHighlight(defs.gutter, gutter) + line;
return ` ${maybeHighlight(defs.gutter, gutter)}${line}`;
}

@@ -158,3 +154,3 @@ }).join("\n");

if (opts.message && !hasColumns) {
frame = "" + " ".repeat(numberMaxWidth + 1) + opts.message + "\n" + frame;
frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
}

@@ -169,10 +165,6 @@

function _default(rawLines, lineNumber, colNumber, opts) {
if (opts === void 0) {
opts = {};
}
function _default(rawLines, lineNumber, colNumber, opts = {}) {
if (!deprecationWarningShown) {
deprecationWarningShown = true;
var message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
const message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";

@@ -182,3 +174,3 @@ if (process.emitWarning) {

} else {
var deprecationError = new Error(message);
const deprecationError = new Error(message);
deprecationError.name = "DeprecationWarning";

@@ -190,3 +182,3 @@ console.warn(new Error(message));

colNumber = Math.max(colNumber, 0);
var location = {
const location = {
start: {

@@ -193,0 +185,0 @@ column: colNumber,

{
"name": "@babel/code-frame",
"version": "7.0.0-beta.46",
"version": "7.0.0-beta.47",
"description": "Generate errors that contain a code frame that point to source locations.",

@@ -11,3 +11,3 @@ "author": "Sebastian McKenzie <sebmck@gmail.com>",

"dependencies": {
"@babel/highlight": "7.0.0-beta.46"
"@babel/highlight": "7.0.0-beta.47"
},

@@ -14,0 +14,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc