Socket
Socket
Sign inDemoInstall

@babel/highlight

Package Overview
Dependencies
3
Maintainers
4
Versions
68
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 8.0.0-alpha.7 to 8.0.0-alpha.8

40

lib/index.js
import jsTokens from 'js-tokens';
import { isKeyword, isStrictReservedWord } from '@babel/helper-validator-identifier';
import chalk, { Chalk } from 'chalk';
import _colors, { createColors } from 'picocolors';
const colors = typeof process === "object" && (process.env.FORCE_COLOR === "0" || process.env.FORCE_COLOR === "false") ? createColors(false) : _colors;
const compose = (f, g) => v => f(g(v));
const sometimesKeywords = new Set(["as", "async", "from", "get", "of", "set"]);
function getDefs(chalk) {
function getDefs(colors) {
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
keyword: colors.cyan,
capitalized: colors.yellow,
jsxIdentifier: colors.yellow,
punctuator: colors.yellow,
number: colors.magenta,
string: colors.green,
regex: colors.magenta,
comment: colors.gray,
invalid: compose(compose(colors.white, colors.bgRed), colors.bold)
};

@@ -126,17 +128,15 @@ }

function shouldHighlight(options) {
return chalk.level > 0 || options.forceColor;
return colors.isColorSupported || options.forceColor;
}
let chalkWithForcedColor = undefined;
function getChalk(forceColor) {
let pcWithForcedColor = undefined;
function getColors(forceColor) {
if (forceColor) {
chalkWithForcedColor ??= new Chalk({
level: 1
});
return chalkWithForcedColor;
pcWithForcedColor ??= createColors(true);
return pcWithForcedColor;
}
return chalk;
return colors;
}
function highlight(code, options = {}) {
if (code !== "" && shouldHighlight(options)) {
const defs = getDefs(getChalk(options.forceColor));
const defs = getDefs(getColors(options.forceColor));
return highlightTokens(defs, code);

@@ -143,0 +143,0 @@ } else {

{
"name": "@babel/highlight",
"version": "8.0.0-alpha.7",
"version": "8.0.0-alpha.8",
"description": "Syntax highlight JavaScript strings for output in terminals.",

@@ -18,5 +18,5 @@ "author": "The Babel Team (https://babel.dev/team)",

"dependencies": {
"@babel/helper-validator-identifier": "^8.0.0-alpha.7",
"chalk": "^5.3.0",
"js-tokens": "^8.0.0"
"@babel/helper-validator-identifier": "^8.0.0-alpha.8",
"js-tokens": "^8.0.0",
"picocolors": "^1.0.0"
},

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

Sorry, the diff of this file is not supported yet

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