@babel/highlight
Advanced tools
Comparing version 7.21.4-esm.2 to 7.21.4-esm.3
@@ -1,4 +0,12 @@ | ||
import jsTokens from "js-tokens"; | ||
import { isStrictReservedWord, isKeyword } from "@babel/helper-validator-identifier"; | ||
import Chalk from "chalk"; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = highlight; | ||
exports.getChalk = getChalk; | ||
exports.shouldHighlight = shouldHighlight; | ||
var _jsTokens = require("js-tokens"); | ||
var _helperValidatorIdentifier = require("@babel/helper-validator-identifier"); | ||
var _chalk = require("chalk"); | ||
const sometimesKeywords = new Set(["as", "async", "from", "get", "of", "set"]); | ||
@@ -25,3 +33,3 @@ function getDefs(chalk) { | ||
if (token.type === "name") { | ||
if (isKeyword(token.value) || isStrictReservedWord(token.value, true) || sometimesKeywords.has(token.value)) { | ||
if ((0, _helperValidatorIdentifier.isKeyword)(token.value) || (0, _helperValidatorIdentifier.isStrictReservedWord)(token.value, true) || sometimesKeywords.has(token.value)) { | ||
return "keyword"; | ||
@@ -46,4 +54,4 @@ } | ||
let match; | ||
while (match = jsTokens.default.exec(text)) { | ||
const token = jsTokens.matchToToken(match); | ||
while (match = _jsTokens.default.exec(text)) { | ||
const token = _jsTokens.matchToToken(match); | ||
yield { | ||
@@ -71,12 +79,12 @@ type: getTokenType(token, match.index, text), | ||
} | ||
export function shouldHighlight(options) { | ||
return !!Chalk.supportsColor || options.forceColor; | ||
function shouldHighlight(options) { | ||
return !!_chalk.supportsColor || options.forceColor; | ||
} | ||
export function getChalk(options) { | ||
return options.forceColor ? new Chalk.constructor({ | ||
function getChalk(options) { | ||
return options.forceColor ? new _chalk.constructor({ | ||
enabled: true, | ||
level: 1 | ||
}) : Chalk; | ||
}) : _chalk; | ||
} | ||
export default function highlight(code, options = {}) { | ||
function highlight(code, options = {}) { | ||
if (code !== "" && shouldHighlight(options)) { | ||
@@ -83,0 +91,0 @@ const chalk = getChalk(options); |
{ | ||
"name": "@babel/highlight", | ||
"version": "7.21.4-esm.2", | ||
"version": "7.21.4-esm.3", | ||
"description": "Syntax highlight JavaScript strings for output in terminals.", | ||
@@ -18,3 +18,3 @@ "author": "The Babel Team (https://babel.dev/team)", | ||
"dependencies": { | ||
"@babel/helper-validator-identifier": "7.21.4-esm.2", | ||
"@babel/helper-validator-identifier": "7.21.4-esm.3", | ||
"chalk": "^2.0.0", | ||
@@ -21,0 +21,0 @@ "js-tokens": "^4.0.0" |
Sorry, the diff of this file is not supported yet
15606
94
+ Added@babel/helper-validator-identifier@7.21.4-esm.3(transitive)
- Removed@babel/helper-validator-identifier@7.21.4-esm.2(transitive)