@babel/highlight
Advanced tools
Comparing version 8.0.0-alpha.7 to 8.0.0-alpha.8
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
19355
2
+ Addedpicocolors@^1.0.0
+ Addedpicocolors@1.0.1(transitive)
- Removedchalk@^5.3.0
- Removedchalk@5.3.0(transitive)