@babel/highlight
Advanced tools
Comparing version 8.0.0-alpha.0 to 8.0.0-alpha.1
import jsTokens from 'js-tokens'; | ||
import { isKeyword, isStrictReservedWord } from '@babel/helper-validator-identifier'; | ||
import Chalk from 'chalk'; | ||
import chalk from 'chalk'; | ||
@@ -126,14 +126,18 @@ const sometimesKeywords = new Set(["as", "async", "from", "get", "of", "set"]); | ||
function shouldHighlight(options) { | ||
return !!Chalk.supportsColor || options.forceColor; | ||
return !!chalk.supportsColor || options.forceColor; | ||
} | ||
function getChalk(options) { | ||
return options.forceColor ? new Chalk.constructor({ | ||
enabled: true, | ||
level: 1 | ||
}) : Chalk; | ||
let chalkWithForcedColor = undefined; | ||
function getChalk(forceColor) { | ||
if (forceColor) { | ||
chalkWithForcedColor ??= new chalk.constructor({ | ||
enabled: true, | ||
level: 1 | ||
}); | ||
return chalkWithForcedColor; | ||
} | ||
return chalk; | ||
} | ||
function highlight(code, options = {}) { | ||
if (code !== "" && shouldHighlight(options)) { | ||
const chalk = getChalk(options); | ||
const defs = getDefs(chalk); | ||
const defs = getDefs(getChalk(options.forceColor)); | ||
return highlightTokens(defs, code); | ||
@@ -145,3 +149,3 @@ } else { | ||
export { highlight as default, getChalk, shouldHighlight }; | ||
export { highlight as default, shouldHighlight }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@babel/highlight", | ||
"version": "8.0.0-alpha.0", | ||
"version": "8.0.0-alpha.1", | ||
"description": "Syntax highlight JavaScript strings for output in terminals.", | ||
@@ -18,8 +18,7 @@ "author": "The Babel Team (https://babel.dev/team)", | ||
"dependencies": { | ||
"@babel/helper-validator-identifier": "^8.0.0-alpha.0", | ||
"chalk": "^2.0.0", | ||
"@babel/helper-validator-identifier": "^8.0.0-alpha.1", | ||
"chalk": "^2.4.2", | ||
"js-tokens": "^8.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/chalk": "^2.0.0", | ||
"strip-ansi": "^4.0.0" | ||
@@ -26,0 +25,0 @@ }, |
Sorry, the diff of this file is not supported yet
18066
1
147