@vitest/utils
Advanced tools
+4
-1
@@ -697,2 +697,5 @@ import { plugins, createDOMElementFilter, format as format$1 } from '@vitest/pretty-format'; | ||
| } | ||
| if (typeof value === "symbol") { | ||
| return "NaN"; | ||
| } | ||
| return Number(value).toString(); | ||
@@ -731,3 +734,3 @@ } | ||
| if (x === null || typeof x !== "object") { | ||
| str += ` ${x}`; | ||
| str += ` ${typeof x === "symbol" ? x.toString() : x}`; | ||
| } else { | ||
@@ -734,0 +737,0 @@ str += ` ${formatArg(x)}`; |
+2
-1
| import { D as DiffOptions } from './types.d-BCElaP-c.js'; | ||
| import { TestError } from './types.js'; | ||
| export { serializeValue as serializeError } from './serialize.js'; | ||
| import '@vitest/pretty-format'; | ||
| declare function processError(_err: any, diffOptions?: DiffOptions, seen?: WeakSet<WeakKey>): any; | ||
| declare function processError(_err: any, diffOptions?: DiffOptions, seen?: WeakSet<WeakKey>): TestError; | ||
| export { processError }; |
+1
-2
@@ -8,3 +8,2 @@ import { printDiffOrStringify } from './diff.js'; | ||
| import './constants.js'; | ||
| import './chunk-_commonjsHelpers.js'; | ||
@@ -39,3 +38,3 @@ function processError(_err, diffOptions, seen = new WeakSet()) { | ||
| } catch (e) { | ||
| return serializeValue(new Error(`Failed to fully serialize error: ${e === null || e === void 0 ? void 0 : e.message}\nInner error message: ${err === null || err === void 0 ? void 0 : err.message}`)); | ||
| return serializeValue(new Error(`Failed to fully serialize error: ${e?.message}\nInner error message: ${err?.message}`)); | ||
| } | ||
@@ -42,0 +41,0 @@ } |
+1
-2
@@ -8,3 +8,2 @@ import fs from 'node:fs'; | ||
| while (basedir) { | ||
| var _tryStatSync; | ||
| const cached = getCachedData(packageCache, basedir, originalBasedir); | ||
@@ -15,3 +14,3 @@ if (cached) { | ||
| const pkgPath = join(basedir, "package.json"); | ||
| if ((_tryStatSync = tryStatSync(pkgPath)) === null || _tryStatSync === void 0 ? void 0 : _tryStatSync.isFile()) { | ||
| if (tryStatSync(pkgPath)?.isFile()) { | ||
| const pkgData = JSON.parse(stripBomTag(fs.readFileSync(pkgPath, "utf8"))); | ||
@@ -18,0 +17,0 @@ if (packageCache) { |
@@ -25,12 +25,12 @@ const IS_RECORD_SYMBOL = "@@__IMMUTABLE_RECORD__@@"; | ||
| if (typeof val.message === "string") { | ||
| safe(() => jsonValue.message ?? (jsonValue.message = normalizeErrorMessage(val.message))); | ||
| safe(() => jsonValue.message ??= normalizeErrorMessage(val.message)); | ||
| } | ||
| if (typeof val.stack === "string") { | ||
| safe(() => jsonValue.stack ?? (jsonValue.stack = val.stack)); | ||
| safe(() => jsonValue.stack ??= val.stack); | ||
| } | ||
| if (typeof val.name === "string") { | ||
| safe(() => jsonValue.name ?? (jsonValue.name = val.name)); | ||
| safe(() => jsonValue.name ??= val.name); | ||
| } | ||
| if (val.cause != null) { | ||
| safe(() => jsonValue.cause ?? (jsonValue.cause = serializeValue(val.cause, seen))); | ||
| safe(() => jsonValue.cause ??= serializeValue(val.cause, seen)); | ||
| } | ||
@@ -37,0 +37,0 @@ } |
@@ -381,9 +381,13 @@ import { isPrimitive, notNullish } from './helpers.js'; | ||
| const { ignoreStackEntries = stackIgnorePatterns } = options; | ||
| const stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack); | ||
| let stacks = !CHROME_IE_STACK_REGEXP.test(stack) ? parseFFOrSafariStackTrace(stack) : parseV8Stacktrace(stack); | ||
| // remove assertion helper's internal stacks | ||
| const helperIndex = stacks.findLastIndex((s) => s.method === "__VITEST_HELPER__" || s.method === "async*__VITEST_HELPER__"); | ||
| if (helperIndex >= 0) { | ||
| stacks = stacks.slice(helperIndex + 1); | ||
| } | ||
| return stacks.map((stack) => { | ||
| var _options$getSourceMap; | ||
| if (options.getUrlId) { | ||
| stack.file = options.getUrlId(stack.file); | ||
| } | ||
| const map = (_options$getSourceMap = options.getSourceMap) === null || _options$getSourceMap === void 0 ? void 0 : _options$getSourceMap.call(options, stack.file); | ||
| const map = options.getSourceMap?.(stack.file); | ||
| if (!map || typeof map !== "object" || !map.version) { | ||
@@ -467,3 +471,3 @@ return shouldFilter(ignoreStackEntries, stack.file) ? null : stack; | ||
| this.url = from; | ||
| this.resolvedSources = (sources || []).map((s) => resolve(s || "", from)); | ||
| this.resolvedSources = (sources || []).map((s) => resolve(from, "..", s || "")); | ||
| } | ||
@@ -470,0 +474,0 @@ } |
+3
-8
| { | ||
| "name": "@vitest/utils", | ||
| "type": "module", | ||
| "version": "4.1.0-beta.3", | ||
| "version": "4.1.0-beta.4", | ||
| "description": "Shared Vitest utility functions", | ||
@@ -55,6 +55,2 @@ "license": "MIT", | ||
| }, | ||
| "./highlight": { | ||
| "types": "./dist/highlight.d.ts", | ||
| "default": "./dist/highlight.js" | ||
| }, | ||
| "./source-map": { | ||
@@ -86,3 +82,3 @@ "types": "./dist/source-map.d.ts", | ||
| "tinyrainbow": "^3.0.3", | ||
| "@vitest/pretty-format": "4.1.0-beta.3" | ||
| "@vitest/pretty-format": "4.1.0-beta.4" | ||
| }, | ||
@@ -93,4 +89,3 @@ "devDependencies": { | ||
| "diff-sequences": "^29.6.3", | ||
| "loupe": "^3.2.1", | ||
| "tinyhighlight": "^0.3.2" | ||
| "loupe": "^3.2.1" | ||
| }, | ||
@@ -97,0 +92,0 @@ "scripts": { |
| function getDefaultExportFromCjs(x) { | ||
| return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x; | ||
| } | ||
| export { getDefaultExportFromCjs as g }; |
| import { Colors } from 'tinyrainbow'; | ||
| interface HighlightOptions { | ||
| jsx?: boolean; | ||
| colors?: Colors; | ||
| } | ||
| declare function highlight(code: string, options?: HighlightOptions): string; | ||
| export { highlight }; |
| import { g as getDefaultExportFromCjs } from './chunk-_commonjsHelpers.js'; | ||
| import c from 'tinyrainbow'; | ||
| var jsTokens_1; | ||
| var hasRequiredJsTokens; | ||
| function requireJsTokens () { | ||
| if (hasRequiredJsTokens) return jsTokens_1; | ||
| hasRequiredJsTokens = 1; | ||
| // Copyright 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023 Simon Lydell | ||
| // License: MIT. | ||
| var Identifier, JSXIdentifier, JSXPunctuator, JSXString, JSXText, KeywordsWithExpressionAfter, KeywordsWithNoLineTerminatorAfter, LineTerminatorSequence, MultiLineComment, Newline, NumericLiteral, Punctuator, RegularExpressionLiteral, SingleLineComment, StringLiteral, Template, TokensNotPrecedingObjectLiteral, TokensPrecedingExpression, WhiteSpace; | ||
| RegularExpressionLiteral = /\/(?![*\/])(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\\]).|\\.)*(\/[$_\u200C\u200D\p{ID_Continue}]*|\\)?/yu; | ||
| Punctuator = /--|\+\+|=>|\.{3}|\??\.(?!\d)|(?:&&|\|\||\?\?|[+\-%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2}|\/(?![\/*]))=?|[?~,:;[\](){}]/y; | ||
| Identifier = /(\x23?)(?=[$_\p{ID_Start}\\])(?:[$_\u200C\u200D\p{ID_Continue}]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+/yu; | ||
| StringLiteral = /(['"])(?:(?!\1)[^\\\n\r]|\\(?:\r\n|[^]))*(\1)?/y; | ||
| NumericLiteral = /(?:0[xX][\da-fA-F](?:_?[\da-fA-F])*|0[oO][0-7](?:_?[0-7])*|0[bB][01](?:_?[01])*)n?|0n|[1-9](?:_?\d)*n|(?:(?:0(?!\d)|0\d*[89]\d*|[1-9](?:_?\d)*)(?:\.(?:\d(?:_?\d)*)?)?|\.\d(?:_?\d)*)(?:[eE][+-]?\d(?:_?\d)*)?|0[0-7]+/y; | ||
| Template = /[`}](?:[^`\\$]|\\[^]|\$(?!\{))*(`|\$\{)?/y; | ||
| WhiteSpace = /[\t\v\f\ufeff\p{Zs}]+/yu; | ||
| LineTerminatorSequence = /\r?\n|[\r\u2028\u2029]/y; | ||
| MultiLineComment = /\/\*(?:[^*]|\*(?!\/))*(\*\/)?/y; | ||
| SingleLineComment = /\/\/.*/y; | ||
| JSXPunctuator = /[<>.:={}]|\/(?![\/*])/y; | ||
| JSXIdentifier = /[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}-]*/yu; | ||
| JSXString = /(['"])(?:(?!\1)[^])*(\1)?/y; | ||
| JSXText = /[^<>{}]+/y; | ||
| TokensPrecedingExpression = /^(?:[\/+-]|\.{3}|\?(?:InterpolationIn(?:JSX|Template)|NoLineTerminatorHere|NonExpressionParenEnd|UnaryIncDec))?$|[{}([,;<>=*%&|^!~?:]$/; | ||
| TokensNotPrecedingObjectLiteral = /^(?:=>|[;\]){}]|else|\?(?:NoLineTerminatorHere|NonExpressionParenEnd))?$/; | ||
| KeywordsWithExpressionAfter = /^(?:await|case|default|delete|do|else|instanceof|new|return|throw|typeof|void|yield)$/; | ||
| KeywordsWithNoLineTerminatorAfter = /^(?:return|throw|yield)$/; | ||
| Newline = RegExp(LineTerminatorSequence.source); | ||
| jsTokens_1 = function*(input, {jsx = false} = {}) { | ||
| var braces, firstCodePoint, isExpression, lastIndex, lastSignificantToken, length, match, mode, nextLastIndex, nextLastSignificantToken, parenNesting, postfixIncDec, punctuator, stack; | ||
| ({length} = input); | ||
| lastIndex = 0; | ||
| lastSignificantToken = ""; | ||
| stack = [ | ||
| {tag: "JS"} | ||
| ]; | ||
| braces = []; | ||
| parenNesting = 0; | ||
| postfixIncDec = false; | ||
| while (lastIndex < length) { | ||
| mode = stack[stack.length - 1]; | ||
| switch (mode.tag) { | ||
| case "JS": | ||
| case "JSNonExpressionParen": | ||
| case "InterpolationInTemplate": | ||
| case "InterpolationInJSX": | ||
| if (input[lastIndex] === "/" && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) { | ||
| RegularExpressionLiteral.lastIndex = lastIndex; | ||
| if (match = RegularExpressionLiteral.exec(input)) { | ||
| lastIndex = RegularExpressionLiteral.lastIndex; | ||
| lastSignificantToken = match[0]; | ||
| postfixIncDec = true; | ||
| yield ({ | ||
| type: "RegularExpressionLiteral", | ||
| value: match[0], | ||
| closed: match[1] !== void 0 && match[1] !== "\\" | ||
| }); | ||
| continue; | ||
| } | ||
| } | ||
| Punctuator.lastIndex = lastIndex; | ||
| if (match = Punctuator.exec(input)) { | ||
| punctuator = match[0]; | ||
| nextLastIndex = Punctuator.lastIndex; | ||
| nextLastSignificantToken = punctuator; | ||
| switch (punctuator) { | ||
| case "(": | ||
| if (lastSignificantToken === "?NonExpressionParenKeyword") { | ||
| stack.push({ | ||
| tag: "JSNonExpressionParen", | ||
| nesting: parenNesting | ||
| }); | ||
| } | ||
| parenNesting++; | ||
| postfixIncDec = false; | ||
| break; | ||
| case ")": | ||
| parenNesting--; | ||
| postfixIncDec = true; | ||
| if (mode.tag === "JSNonExpressionParen" && parenNesting === mode.nesting) { | ||
| stack.pop(); | ||
| nextLastSignificantToken = "?NonExpressionParenEnd"; | ||
| postfixIncDec = false; | ||
| } | ||
| break; | ||
| case "{": | ||
| Punctuator.lastIndex = 0; | ||
| isExpression = !TokensNotPrecedingObjectLiteral.test(lastSignificantToken) && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken)); | ||
| braces.push(isExpression); | ||
| postfixIncDec = false; | ||
| break; | ||
| case "}": | ||
| switch (mode.tag) { | ||
| case "InterpolationInTemplate": | ||
| if (braces.length === mode.nesting) { | ||
| Template.lastIndex = lastIndex; | ||
| match = Template.exec(input); | ||
| lastIndex = Template.lastIndex; | ||
| lastSignificantToken = match[0]; | ||
| if (match[1] === "${") { | ||
| lastSignificantToken = "?InterpolationInTemplate"; | ||
| postfixIncDec = false; | ||
| yield ({ | ||
| type: "TemplateMiddle", | ||
| value: match[0] | ||
| }); | ||
| } else { | ||
| stack.pop(); | ||
| postfixIncDec = true; | ||
| yield ({ | ||
| type: "TemplateTail", | ||
| value: match[0], | ||
| closed: match[1] === "`" | ||
| }); | ||
| } | ||
| continue; | ||
| } | ||
| break; | ||
| case "InterpolationInJSX": | ||
| if (braces.length === mode.nesting) { | ||
| stack.pop(); | ||
| lastIndex += 1; | ||
| lastSignificantToken = "}"; | ||
| yield ({ | ||
| type: "JSXPunctuator", | ||
| value: "}" | ||
| }); | ||
| continue; | ||
| } | ||
| } | ||
| postfixIncDec = braces.pop(); | ||
| nextLastSignificantToken = postfixIncDec ? "?ExpressionBraceEnd" : "}"; | ||
| break; | ||
| case "]": | ||
| postfixIncDec = true; | ||
| break; | ||
| case "++": | ||
| case "--": | ||
| nextLastSignificantToken = postfixIncDec ? "?PostfixIncDec" : "?UnaryIncDec"; | ||
| break; | ||
| case "<": | ||
| if (jsx && (TokensPrecedingExpression.test(lastSignificantToken) || KeywordsWithExpressionAfter.test(lastSignificantToken))) { | ||
| stack.push({tag: "JSXTag"}); | ||
| lastIndex += 1; | ||
| lastSignificantToken = "<"; | ||
| yield ({ | ||
| type: "JSXPunctuator", | ||
| value: punctuator | ||
| }); | ||
| continue; | ||
| } | ||
| postfixIncDec = false; | ||
| break; | ||
| default: | ||
| postfixIncDec = false; | ||
| } | ||
| lastIndex = nextLastIndex; | ||
| lastSignificantToken = nextLastSignificantToken; | ||
| yield ({ | ||
| type: "Punctuator", | ||
| value: punctuator | ||
| }); | ||
| continue; | ||
| } | ||
| Identifier.lastIndex = lastIndex; | ||
| if (match = Identifier.exec(input)) { | ||
| lastIndex = Identifier.lastIndex; | ||
| nextLastSignificantToken = match[0]; | ||
| switch (match[0]) { | ||
| case "for": | ||
| case "if": | ||
| case "while": | ||
| case "with": | ||
| if (lastSignificantToken !== "." && lastSignificantToken !== "?.") { | ||
| nextLastSignificantToken = "?NonExpressionParenKeyword"; | ||
| } | ||
| } | ||
| lastSignificantToken = nextLastSignificantToken; | ||
| postfixIncDec = !KeywordsWithExpressionAfter.test(match[0]); | ||
| yield ({ | ||
| type: match[1] === "#" ? "PrivateIdentifier" : "IdentifierName", | ||
| value: match[0] | ||
| }); | ||
| continue; | ||
| } | ||
| StringLiteral.lastIndex = lastIndex; | ||
| if (match = StringLiteral.exec(input)) { | ||
| lastIndex = StringLiteral.lastIndex; | ||
| lastSignificantToken = match[0]; | ||
| postfixIncDec = true; | ||
| yield ({ | ||
| type: "StringLiteral", | ||
| value: match[0], | ||
| closed: match[2] !== void 0 | ||
| }); | ||
| continue; | ||
| } | ||
| NumericLiteral.lastIndex = lastIndex; | ||
| if (match = NumericLiteral.exec(input)) { | ||
| lastIndex = NumericLiteral.lastIndex; | ||
| lastSignificantToken = match[0]; | ||
| postfixIncDec = true; | ||
| yield ({ | ||
| type: "NumericLiteral", | ||
| value: match[0] | ||
| }); | ||
| continue; | ||
| } | ||
| Template.lastIndex = lastIndex; | ||
| if (match = Template.exec(input)) { | ||
| lastIndex = Template.lastIndex; | ||
| lastSignificantToken = match[0]; | ||
| if (match[1] === "${") { | ||
| lastSignificantToken = "?InterpolationInTemplate"; | ||
| stack.push({ | ||
| tag: "InterpolationInTemplate", | ||
| nesting: braces.length | ||
| }); | ||
| postfixIncDec = false; | ||
| yield ({ | ||
| type: "TemplateHead", | ||
| value: match[0] | ||
| }); | ||
| } else { | ||
| postfixIncDec = true; | ||
| yield ({ | ||
| type: "NoSubstitutionTemplate", | ||
| value: match[0], | ||
| closed: match[1] === "`" | ||
| }); | ||
| } | ||
| continue; | ||
| } | ||
| break; | ||
| case "JSXTag": | ||
| case "JSXTagEnd": | ||
| JSXPunctuator.lastIndex = lastIndex; | ||
| if (match = JSXPunctuator.exec(input)) { | ||
| lastIndex = JSXPunctuator.lastIndex; | ||
| nextLastSignificantToken = match[0]; | ||
| switch (match[0]) { | ||
| case "<": | ||
| stack.push({tag: "JSXTag"}); | ||
| break; | ||
| case ">": | ||
| stack.pop(); | ||
| if (lastSignificantToken === "/" || mode.tag === "JSXTagEnd") { | ||
| nextLastSignificantToken = "?JSX"; | ||
| postfixIncDec = true; | ||
| } else { | ||
| stack.push({tag: "JSXChildren"}); | ||
| } | ||
| break; | ||
| case "{": | ||
| stack.push({ | ||
| tag: "InterpolationInJSX", | ||
| nesting: braces.length | ||
| }); | ||
| nextLastSignificantToken = "?InterpolationInJSX"; | ||
| postfixIncDec = false; | ||
| break; | ||
| case "/": | ||
| if (lastSignificantToken === "<") { | ||
| stack.pop(); | ||
| if (stack[stack.length - 1].tag === "JSXChildren") { | ||
| stack.pop(); | ||
| } | ||
| stack.push({tag: "JSXTagEnd"}); | ||
| } | ||
| } | ||
| lastSignificantToken = nextLastSignificantToken; | ||
| yield ({ | ||
| type: "JSXPunctuator", | ||
| value: match[0] | ||
| }); | ||
| continue; | ||
| } | ||
| JSXIdentifier.lastIndex = lastIndex; | ||
| if (match = JSXIdentifier.exec(input)) { | ||
| lastIndex = JSXIdentifier.lastIndex; | ||
| lastSignificantToken = match[0]; | ||
| yield ({ | ||
| type: "JSXIdentifier", | ||
| value: match[0] | ||
| }); | ||
| continue; | ||
| } | ||
| JSXString.lastIndex = lastIndex; | ||
| if (match = JSXString.exec(input)) { | ||
| lastIndex = JSXString.lastIndex; | ||
| lastSignificantToken = match[0]; | ||
| yield ({ | ||
| type: "JSXString", | ||
| value: match[0], | ||
| closed: match[2] !== void 0 | ||
| }); | ||
| continue; | ||
| } | ||
| break; | ||
| case "JSXChildren": | ||
| JSXText.lastIndex = lastIndex; | ||
| if (match = JSXText.exec(input)) { | ||
| lastIndex = JSXText.lastIndex; | ||
| lastSignificantToken = match[0]; | ||
| yield ({ | ||
| type: "JSXText", | ||
| value: match[0] | ||
| }); | ||
| continue; | ||
| } | ||
| switch (input[lastIndex]) { | ||
| case "<": | ||
| stack.push({tag: "JSXTag"}); | ||
| lastIndex++; | ||
| lastSignificantToken = "<"; | ||
| yield ({ | ||
| type: "JSXPunctuator", | ||
| value: "<" | ||
| }); | ||
| continue; | ||
| case "{": | ||
| stack.push({ | ||
| tag: "InterpolationInJSX", | ||
| nesting: braces.length | ||
| }); | ||
| lastIndex++; | ||
| lastSignificantToken = "?InterpolationInJSX"; | ||
| postfixIncDec = false; | ||
| yield ({ | ||
| type: "JSXPunctuator", | ||
| value: "{" | ||
| }); | ||
| continue; | ||
| } | ||
| } | ||
| WhiteSpace.lastIndex = lastIndex; | ||
| if (match = WhiteSpace.exec(input)) { | ||
| lastIndex = WhiteSpace.lastIndex; | ||
| yield ({ | ||
| type: "WhiteSpace", | ||
| value: match[0] | ||
| }); | ||
| continue; | ||
| } | ||
| LineTerminatorSequence.lastIndex = lastIndex; | ||
| if (match = LineTerminatorSequence.exec(input)) { | ||
| lastIndex = LineTerminatorSequence.lastIndex; | ||
| postfixIncDec = false; | ||
| if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) { | ||
| lastSignificantToken = "?NoLineTerminatorHere"; | ||
| } | ||
| yield ({ | ||
| type: "LineTerminatorSequence", | ||
| value: match[0] | ||
| }); | ||
| continue; | ||
| } | ||
| MultiLineComment.lastIndex = lastIndex; | ||
| if (match = MultiLineComment.exec(input)) { | ||
| lastIndex = MultiLineComment.lastIndex; | ||
| if (Newline.test(match[0])) { | ||
| postfixIncDec = false; | ||
| if (KeywordsWithNoLineTerminatorAfter.test(lastSignificantToken)) { | ||
| lastSignificantToken = "?NoLineTerminatorHere"; | ||
| } | ||
| } | ||
| yield ({ | ||
| type: "MultiLineComment", | ||
| value: match[0], | ||
| closed: match[1] !== void 0 | ||
| }); | ||
| continue; | ||
| } | ||
| SingleLineComment.lastIndex = lastIndex; | ||
| if (match = SingleLineComment.exec(input)) { | ||
| lastIndex = SingleLineComment.lastIndex; | ||
| postfixIncDec = false; | ||
| yield ({ | ||
| type: "SingleLineComment", | ||
| value: match[0] | ||
| }); | ||
| continue; | ||
| } | ||
| firstCodePoint = String.fromCodePoint(input.codePointAt(lastIndex)); | ||
| lastIndex += firstCodePoint.length; | ||
| lastSignificantToken = firstCodePoint; | ||
| postfixIncDec = false; | ||
| yield ({ | ||
| type: mode.tag.startsWith("JSX") ? "JSXInvalid" : "Invalid", | ||
| value: firstCodePoint | ||
| }); | ||
| } | ||
| return void 0; | ||
| }; | ||
| return jsTokens_1; | ||
| } | ||
| var jsTokensExports = /*@__PURE__*/ requireJsTokens(); | ||
| var jsTokens = /*@__PURE__*/getDefaultExportFromCjs(jsTokensExports); | ||
| // src/index.ts | ||
| var reservedWords = { | ||
| keyword: [ | ||
| "break", | ||
| "case", | ||
| "catch", | ||
| "continue", | ||
| "debugger", | ||
| "default", | ||
| "do", | ||
| "else", | ||
| "finally", | ||
| "for", | ||
| "function", | ||
| "if", | ||
| "return", | ||
| "switch", | ||
| "throw", | ||
| "try", | ||
| "var", | ||
| "const", | ||
| "while", | ||
| "with", | ||
| "new", | ||
| "this", | ||
| "super", | ||
| "class", | ||
| "extends", | ||
| "export", | ||
| "import", | ||
| "null", | ||
| "true", | ||
| "false", | ||
| "in", | ||
| "instanceof", | ||
| "typeof", | ||
| "void", | ||
| "delete" | ||
| ], | ||
| strict: [ | ||
| "implements", | ||
| "interface", | ||
| "let", | ||
| "package", | ||
| "private", | ||
| "protected", | ||
| "public", | ||
| "static", | ||
| "yield" | ||
| ] | ||
| }, keywords = new Set(reservedWords.keyword), reservedWordsStrictSet = new Set(reservedWords.strict), sometimesKeywords = /* @__PURE__ */ new Set(["as", "async", "from", "get", "of", "set"]); | ||
| function isReservedWord(word) { | ||
| return word === "await" || word === "enum"; | ||
| } | ||
| function isStrictReservedWord(word) { | ||
| return isReservedWord(word) || reservedWordsStrictSet.has(word); | ||
| } | ||
| function isKeyword(word) { | ||
| return keywords.has(word); | ||
| } | ||
| var BRACKET = /^[()[\]{}]$/, getTokenType = function(token) { | ||
| if (token.type === "IdentifierName") { | ||
| if (isKeyword(token.value) || isStrictReservedWord(token.value) || sometimesKeywords.has(token.value)) | ||
| return "Keyword"; | ||
| if (token.value[0] && token.value[0] !== token.value[0].toLowerCase()) | ||
| return "IdentifierCapitalized"; | ||
| } | ||
| return token.type === "Punctuator" && BRACKET.test(token.value) ? "Bracket" : token.type === "Invalid" && (token.value === "@" || token.value === "#") ? "Punctuator" : token.type; | ||
| }; | ||
| function getCallableType(token) { | ||
| if (token.type === "IdentifierName") | ||
| return "IdentifierCallable"; | ||
| if (token.type === "PrivateIdentifier") | ||
| return "PrivateIdentifierCallable"; | ||
| throw new Error("Not a callable token"); | ||
| } | ||
| var colorize = (defs, type, value) => { | ||
| let colorize2 = defs[type]; | ||
| return colorize2 ? colorize2(value) : value; | ||
| }, highlightTokens = (defs, text, jsx) => { | ||
| let highlighted = "", lastPotentialCallable = null, stackedHighlight = ""; | ||
| for (let token of jsTokens(text, { jsx })) { | ||
| let type = getTokenType(token); | ||
| if (type === "IdentifierName" || type === "PrivateIdentifier") { | ||
| lastPotentialCallable && (highlighted += colorize(defs, getTokenType(lastPotentialCallable), lastPotentialCallable.value) + stackedHighlight, stackedHighlight = ""), lastPotentialCallable = token; | ||
| continue; | ||
| } | ||
| if (lastPotentialCallable && (token.type === "WhiteSpace" || token.type === "LineTerminatorSequence" || token.type === "Punctuator" && (token.value === "?." || token.value === "!"))) { | ||
| stackedHighlight += colorize(defs, type, token.value); | ||
| continue; | ||
| } | ||
| if (stackedHighlight && !lastPotentialCallable && (highlighted += stackedHighlight, stackedHighlight = ""), lastPotentialCallable) { | ||
| let type2 = token.type === "Punctuator" && token.value === "(" ? getCallableType(lastPotentialCallable) : getTokenType(lastPotentialCallable); | ||
| highlighted += colorize(defs, type2, lastPotentialCallable.value) + stackedHighlight, stackedHighlight = "", lastPotentialCallable = null; | ||
| } | ||
| highlighted += colorize(defs, type, token.value); | ||
| } | ||
| return highlighted; | ||
| }; | ||
| function highlight$1(code, options = { jsx: false, colors: {} }) { | ||
| return code && highlightTokens(options.colors || {}, code, options.jsx); | ||
| } | ||
| function getDefs(c) { | ||
| const Invalid = (text) => c.white(c.bgRed(c.bold(text))); | ||
| return { | ||
| Keyword: c.magenta, | ||
| IdentifierCapitalized: c.yellow, | ||
| Punctuator: c.yellow, | ||
| StringLiteral: c.green, | ||
| NoSubstitutionTemplate: c.green, | ||
| MultiLineComment: c.gray, | ||
| SingleLineComment: c.gray, | ||
| RegularExpressionLiteral: c.cyan, | ||
| NumericLiteral: c.blue, | ||
| TemplateHead: (text) => c.green(text.slice(0, text.length - 2)) + c.cyan(text.slice(-2)), | ||
| TemplateTail: (text) => c.cyan(text.slice(0, 1)) + c.green(text.slice(1)), | ||
| TemplateMiddle: (text) => c.cyan(text.slice(0, 1)) + c.green(text.slice(1, text.length - 2)) + c.cyan(text.slice(-2)), | ||
| IdentifierCallable: c.blue, | ||
| PrivateIdentifierCallable: (text) => `#${c.blue(text.slice(1))}`, | ||
| Invalid, | ||
| JSXString: c.green, | ||
| JSXIdentifier: c.yellow, | ||
| JSXInvalid: Invalid, | ||
| JSXPunctuator: c.yellow | ||
| }; | ||
| } | ||
| function highlight(code, options = { jsx: false }) { | ||
| return highlight$1(code, { | ||
| jsx: options.jsx, | ||
| colors: getDefs(options.colors || c) | ||
| }); | ||
| } | ||
| export { highlight }; |
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
4
-20%9
-10%164682
-10.04%31
-8.82%4585
-10.48%+ Added
- Removed