Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: replace @babel/code-frame with own implementation (#43337)
Pavel Feldmane6f60ac6fc92
diff --git a/.claude/skills/playwright-dev/vendor.md b/.claude/skills/playwright-dev/vendor.mdindex 2ba612a649..52d649b50c 100644--- a/.claude/skills/playwright-dev/vendor.md+++ b/.claude/skills/playwright-dev/vendor.md@@ -38,7 +38,7 @@ export key lives in `utils/build/utilsBundleMapping.js`.| Output | Entry | Purpose ||---|---|---|-| `lib/transform/babelBundle.js` | `src/transform/babelBundle.ts` | Wraps `@babel/core`, `@babel/traverse`, `@babel/code-frame`, plugins. Shared by every consumer that needs babel. |+| `lib/transform/babelBundle.js` | `src/transform/babelBundle.ts` | Wraps `@babel/core`, `@babel/traverse`, plugins. Shared by every consumer that needs babel. || `lib/transform/esmLoader.js` | `src/transform/esmLoader.ts` | Node ESM loader registered via `node:module.register()`. Output sits next to `babelBundle.js` so its `./babelBundle` sibling require resolves correctly. || `lib/common/index.js` | `src/common/index.ts` | Barrel of `common/*` + `transform/*` (compilationCache, test, configLoader, fixtures, globals, …). State-holding singletons (currentTestInfo, memoryCache, …) live here. || `lib/runner/index.js` | `src/runner/index.ts` | Barrel of `runner/*` + `reporters/*` + `plugins/*`. |diff --git a/package-lock.json b/package-lock.jsonindex 5465dbfc04..9f0f82d48d 100644--- a/package-lock.json+++ b/package-lock.json@@ -14,7 +14,6 @@"devDependencies": {"@actions/core": "3.0.1","@actions/github": "9.1.1",- "@babel/code-frame": "7.29.7","@babel/core": "7.29.7","@babel/helper-plugin-utils": "7.29.7","@babel/parser": "7.29.7",@@ -44,7 +43,6 @@"@jest/expect-utils": "30.4.1","@modelcontextprotocol/sdk": "1.31.0","@stylistic/eslint-plugin": "5.10.0",- "@types/babel__code-frame": "7.27.0","@types/babel__core": "7.20.5","@types/babel__helper-plugin-utils": "7.10.3","@types/babel__traverse": "7.28.0",@@ -2722,13 +2720,6 @@"tslib": "^2.4.0"}},- "node_modules/@types/babel__code-frame": {- "version": "7.27.0",- "resolved": "https://registry.npmjs.org/@types/babel__code-frame/-/babel__code-frame-7.27.0.tgz",- "integrity": "sha512-Dwlo+LrxDx/0SpfmJ/BKveHf7QXWvLBLc+x03l5sbzykj3oB9nHygCpSECF1a+s+QIxbghe+KHqC90vGtxLRAA==",- "dev": true,- "license": "MIT"- },"node_modules/@types/babel__core": {"version": "7.20.5","resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",diff --git a/package.json b/package.jsonindex 6abe40d0f3..e76b510377 100644--- a/package.json+++ b/package.json@@ -57,7 +57,6 @@"devDependencies": {"@actions/core": "3.0.1","@actions/github": "9.1.1",- "@babel/code-frame": "7.29.7","@babel/core": "7.29.7","@babel/helper-plugin-utils": "7.29.7","@babel/parser": "7.29.7",@@ -87,7 +86,6 @@"@jest/expect-utils": "30.4.1","@modelcontextprotocol/sdk": "1.31.0","@stylistic/eslint-plugin": "5.10.0",- "@types/babel__code-frame": "7.27.0","@types/babel__core": "7.20.5","@types/babel__helper-plugin-utils": "7.10.3","@types/babel__traverse": "7.28.0",diff --git a/packages/isomorphic/codeFrame.ts b/packages/isomorphic/codeFrame.tsnew file mode 100644index 0000000000..b3c705b9cc--- /dev/null+++ b/packages/isomorphic/codeFrame.ts@@ -0,0 +1,188 @@+/**+ * Copyright (c) Microsoft Corporation.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { noColors } from './colors';++import type { Colors } from './colors';++export type CodeFrameLocation = {+ line: number;+ column?: number;+};++export type CodeFrameOptions = {+ colors?: Colors;+ linesAbove?: number;+ linesBelow?: number;+ message?: string;+};++const kLineBreak = /\r\n|[\n\r\u2028\u2029]/;++export function codeFrame(source: string, location: CodeFrameLocation, options: CodeFrameOptions = {}): string {+ const colors = options.colors ?? noColors;+ const rawLines = source.split(kLineBreak);+ const lines = colors.enabled ? highlight(source, colors).split(kLineBreak) : rawLines;+ const first = Math.max(location.line - (options.linesAbove ?? 2), 1);+ const last = Math.min(location.line + (options.linesBelow ?? 3), rawLines.length);+ const width = String(last).length;+ const column = location.column || 0;++ const frame: string[] = [];+ for (let lineNumber = first; lineNumber <= last; lineNumber++) {+ const rawLine = rawLines[lineNumber - 1];+ const isMarked = lineNumber === location.line;+ const gutter = colors.gray(` ${String(lineNumber).padStart(width)} |`);+ frame.push((isMarked ? colors.red(colors.bold('>')) : ' ') + gutter + (rawLine ? ' ' + lines[lineNumber - 1] : ''));+ if (!isMarked || !column)+ continue;+ const spacing = rawLine.slice(0, column - 1).replace(/[^\t]/g, ' ');+ const message = options.message ? ' ' + colors.red(colors.bold(options.message)) : '';+ frame.push(' ' + colors.gray(` ${' '.repeat(width)} |`) + ' ' + spacing + colors.red(colors.bold('^')) + message);+ }+ if (options.message && location.column === undefined)+ return ' '.repeat(width + 1) + options.message + '\n' + frame.join('\n');+ return frame.join('\n');+}++const kKeywords = new Set([+ 'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete', 'do',+ 'else', 'enum', 'export', 'extends', 'false', 'finally', 'for', 'function', 'if', 'import', 'in',+ 'instanceof', 'new', 'null', 'return', 'super', 'switch', 'this', 'throw', 'true', 'try', 'typeof',+ 'var', 'void', 'while', 'with', 'yield',+ 'implements', 'interface', 'let', 'package', 'private', 'protected', 'public', 'static',+ 'as', 'async', 'from', 'get', 'of', 'set',+]);++const kValueKeywords = new Set(['this', 'super', 'null', 'true', 'false']);++type TokenType = 'whitespace' | 'comment' | 'string' | 'regex' | 'number' | 'name' | 'punctuator' | 'bracket' | 'other';++// Returns the end of the token starting at `index`, or `index` when there is no match.+type Matcher = (source: string, index: number) => number;++function regexMatcher(regex: RegExp): Matcher {+ return (source, index) => {+ regex.lastIndex = index;+ return regex.exec(source) ? regex.lastIndex : index;+ };+}++const quotedString = regexMatcher(/'(?:[^'\\\n\r]|\\[\s\S])*'?|"(?:[^"\\\n\r]|\\[\s\S])*"?/y);++function templateEnd(source: string, index: number): number {+ if (source[index] !== '`')+ return index;+ for (let i = index + 1; i < source.length; i++) {+ if (source[i] === '\\')+ i++;+ else if (source[i] === '`')+ return i + 1;+ else if (source[i] === '$' && source[i + 1] === '{')+ i = substitutionEnd(source, i + 2) - 1;+ }+ return source.length;+}++function substitutionEnd(source: string, index: number): number {+ let depth = 1;+ for (let i = index; i < source.length;) {+ const end = Math.max(templateEnd(source, i), quotedString(source, i));+ if (end > i) {+ i = end;+ continue;+ }+ if (source[i] === '{')+ depth++;+ else if (source[i] === '}' && --depth === 0)+ return i + 1;+ i++;+ }+ return source.length;+}++const kTokens: [TokenType, Matcher][] = [+ ['whitespace', regexMatcher(/\s+/y)],+ ['comment', regexMatcher(/\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/y)],+ ['string', (source, index) => Math.max(quotedString(source, index), templateEnd(source, index))],+ ['regex', regexMatcher(/\/(?:[^/\\[\n\r]|\\.|\[(?:[^\]\\\n\r]|\\.)*\])+\/[a-z]*/y)],+ ['number', regexMatcher(/(?:0[xX][\da-fA-F_]+|0[oO][0-7_]+|0[bB][01_]+|(?:\d[\d_]*(?:\.[\d_]*)?|\.\d[\d_]*)(?:[eE][+-]?\d[\d_]*)?)n?/y)],+ ['name', regexMatcher(/#?[\p{ID_Start}$_][\p{ID_Continue}$\u200C\u200D]*/uy)],+ ['bracket', regexMatcher(/[()[\]{}]/y)],+ ['punctuator', regexMatcher(/<\/(?=[\p{ID_Start}>])|\.\.\.|>>>=?|\*\*=?|&&=?|\|\|=?|\?\?=?|\?\.(?!\d)|=>|\+\+|--|<<=?|>>=?|[=!]=?=?|[<>+\-*/%&|^]=?|[~?:;,.@]/uy)],+ ['other', (source, index) => index + 1],+];++function highlight(source: string, colors: Colors): string {+ const result: string[] = [];+ let previous: { type: TokenType, text: string, end: number } | undefined;+ for (let index = 0; index < source.length;) {+ for (const [type, matcher] of kTokens) {+ if (type === 'regex' && !regexAllowed(previous))+ continue;+ const end = matcher(source, index);+ if (end === index)+ continue;+ const text = source.slice(index, end);+ result.push(colorize(text, tokenColor(type, text, previous, index), colors));+ if (type !== 'whitespace' && type !== 'comment')+ previous = { type, text, end };+ index = end;+ break;+ }+ }+ return result.join('');+}++function regexAllowed(previous: { type: TokenType, text: string } | undefined): boolean {+ if (!previous)+ return true;+ if (previous.type === 'punctuator')+ return true;+ if (previous.type === 'bracket')+ return '([{'.includes(previous.text);+ if (previous.type === 'name')+ return kKeywords.has(previous.text) && !kValueKeywords.has(previous.text);+ return false;+}++type Color = 'cyan' | 'yellow' | 'green' | 'magenta' | 'gray' | undefined;++function tokenColor(type: TokenType, text: string, previous: { type: TokenType, text: string, end: number } | undefined, start: number): Color {+ switch (type) {+ case 'comment': return 'gray';+ case 'string': return 'green';+ case 'regex': return 'magenta';+ case 'number': return 'magenta';+ case 'punctuator': return 'yellow';+ case 'name': {+ const isProperty = previous?.type === 'punctuator' && (previous.text === '.' || previous.text === '?.');+ const isTagName = previous?.type === 'punctuator' && (previous.text === '<' || previous.text === '</') && previous.end === start;+ if (kKeywords.has(text) && !isProperty)+ return 'cyan';+ if (isTagName || /^\p{Lu}/u.test(text))+ return 'yellow';+ return undefined;+ }+ }+ return undefined;+}++function colorize(text: string, color: Color, colors: Colors): string {+ if (!color)+ return text;+ return text.split(/(\r\n|[\n\r\u2028\u2029])/).map((part, i) => i % 2 || !part ? part : colors[color](part)).join('');+}diff --git a/packages/isomorphic/index.ts b/packages/isomorphic/index.tsindex 146759e178..6b073e7f9b 100644--- a/packages/isomorphic/index.ts+++ b/packages/isomorphic/index.ts@@ -18,6 +18,7 @@ export * from './ariaSnapshot';export * from './ariaSnapshotRenderer';export * from './assert';export * from './base64';+export * from './codeFrame';export * from './colors';export * from './headers';export * from './imageUtils';diff --git a/packages/playwright/src/reporters/DEPS.list b/packages/playwright/src/reporters/DEPS.listindex d832203a0a..ad7ebae6f8 100644--- a/packages/playwright/src/reporters/DEPS.list+++ b/packages/playwright/src/reporters/DEPS.list@@ -12,9 +12,3 @@ node_modules/yazl[merge.ts]../runner/reporters.ts--[internalReporter.ts]-../transform/babelBundle.ts--[html.ts]-../transform/babelBundle.tsdiff --git a/packages/playwright/src/reporters/html.ts b/packages/playwright/src/reporters/html.tsindex 647107d6e8..f37aea3d2e 100644--- a/packages/playwright/src/reporters/html.ts+++ b/packages/playwright/src/reporters/html.ts@@ -23,6 +23,7 @@ import colors from 'colors/safe';import mime from 'mime';import open from 'open';import * as yazl from 'yazl';+import { codeFrame } from '@isomorphic/codeFrame';import { MultiMap } from '@isomorphic/multimap';import { calculateSha1 } from '@utils/crypto';import { copyFileAndMakeWritable, removeFolders, sanitizeForFilePath, toPosixPath } from '@utils/fileUtils';@@ -37,7 +38,6 @@ import { extractZip } from '@utils/third_party/extractZip';declare const __PW_HMR__: boolean;import { createTestFilter, filterTests, formatError, formatResultFailure, internalScreen } from './base';-import * as babel from '../transform/babelBundle';import { resolveReporterOutputPath, stripAnsiEscapes } from '../util';import type { ReportConfigureParams, ReportEndParams, ReporterV2 } from './reporterV2';@@ -803,7 +803,7 @@ function createSnippets(stepsInFile: MultiMap<string, TestStep>) {continue;}const lines = source.split('\n').length;- const highlighted = babel.codeFrameColumns(source, { start: { line: lines, column: 1 } }, { highlightCode: true, linesAbove: lines, linesBelow: 0 });+ const highlighted = codeFrame(source, { line: lines, column: 1 }, { colors: internalScreen.colors, linesAbove: lines, linesBelow: 0 });const highlightedLines = highlighted.split('\n');const lineWithArrow = highlightedLines[highlightedLines.length - 1];for (const step of stepsInFile.get(file)) {@@ -830,16 +830,13 @@ function createErrorCodeframe(message: string, location: Location) {return;}- return babel.codeFrameColumns(+ return codeFrame(source,{- start: {- line: location.line,- column: location.column,- },+ line: location.line,+ column: location.column,},{- highlightCode: false,linesAbove: 100,linesBelow: 100,message: stripAnsiEscapes(message).split('\n')[0] || undefined,diff --git a/packages/playwright/src/reporters/internalReporter.ts b/packages/playwright/src/reporters/internalReporter.tsindex 26e9ba42dc..68384d8f49 100644--- a/packages/playwright/src/reporters/internalReporter.ts+++ b/packages/playwright/src/reporters/internalReporter.ts@@ -16,12 +16,12 @@import fs from 'fs';+import { codeFrame } from '@isomorphic/codeFrame';import { monotonicTime } from '@isomorphic/time';import { internalScreen, prepareErrorStack, relativeFilePath } from './base';import { Multiplexer } from './multiplexer';import { test as testNs } from '../common';-import * as babel from '../transform/babelBundle';import { wrapReporterAsV2 } from './reporterV2';import type { AnyReporter, ReporterPreprocessParams, ReporterV2 } from './reporterV2';@@ -142,13 +142,13 @@ export function addLocationAndSnippetToError(config: FullConfig, error: TestErrotry {const tokens = [];const source = fs.readFileSync(location.file, 'utf8');- const codeFrame = babel.codeFrameColumns(source, { start: location }, { highlightCode: true });+ const frame = codeFrame(source, location, { colors: internalScreen.colors });// Convert /var/folders to /private/var/folders on Mac.if (!file || fs.realpathSync(file) !== location.file) {tokens.push(internalScreen.colors.gray(` at `) + `${relativeFilePath(internalScreen, config, location.file)}:${location.line}`);tokens.push('');}- tokens.push(codeFrame);+ tokens.push(frame);error.snippet = tokens.join('\n');} catch (e) {// Failed to read the source file - that's ok.diff --git a/packages/playwright/src/transform/babelBundle.ts b/packages/playwright/src/transform/babelBundle.tsindex 1fdbf91481..85ee4f1ffc 100644--- a/packages/playwright/src/transform/babelBundle.ts+++ b/packages/playwright/src/transform/babelBundle.ts@@ -21,7 +21,6 @@ import type { BabelFileResult, NodePath, PluginObj, TransformOptions } from '@baimport type { TemplateBuilder } from '@babel/template';import type { TSExportAssignment } from '@babel/types';-export { codeFrameColumns } from '@babel/code-frame';export { declare } from '@babel/helper-plugin-utils';export { types } from '@babel/core';export const traverse = traverseFunction;diff --git a/tests/library/unit/code-frame.spec.ts b/tests/library/unit/code-frame.spec.tsnew file mode 100644index 0000000000..f34545107f--- /dev/null+++ b/tests/library/unit/code-frame.spec.ts@@ -0,0 +1,146 @@+/**+ * Copyright (c) Microsoft Corporation.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import { test, expect } from '@playwright/test';+import { codeFrame } from '../../../packages/isomorphic/codeFrame';+import { noColors } from '../../../packages/isomorphic/colors';++import type { Colors } from '../../../packages/isomorphic/colors';++const tagColors = Object.fromEntries(Object.keys(noColors).map(name => [name, name === 'enabled' ? true : (text: string) => `<${name}>${text}</${name}>`])) as Colors;++const source = Array.from({ length: 12 }, (_, i) => `line${i + 1} = foo(${i + 1});`).join('\n');++test('should mark the column', () => {+ expect(codeFrame(source, { line: 5, column: 3 })).toBe([+ ' 3 | line3 = foo(3);',+ ' 4 | line4 = foo(4);',+ '> 5 | line5 = foo(5);',+ ' | ^',+ ' 6 | line6 = foo(6);',+ ' 7 | line7 = foo(7);',+ ' 8 | line8 = foo(8);',+ ].join('\n'));+});++test('should mark the line without a column', () => {+ expect(codeFrame(source, { line: 5 })).toBe([+ ' 3 | line3 = foo(3);',+ ' 4 | line4 = foo(4);',+ '> 5 | line5 = foo(5);',+ ' 6 | line6 = foo(6);',+ ' 7 | line7 = foo(7);',+ ' 8 | line8 = foo(8);',+ ].join('\n'));+});++test('should respect linesAbove and linesBelow', () => {+ expect(codeFrame(source, { line: 6, column: 2 }, { linesAbove: 0, linesBelow: 1 })).toBe([+ '> 6 | line6 = foo(6);',+ ' | ^',+ ' 7 | line7 = foo(7);',+ ].join('\n'));+});++test('should clip to the source lines', () => {+ expect(codeFrame(source, { line: 12, column: 2 })).toBe([+ ' 10 | line10 = foo(10);',+ ' 11 | line11 = foo(11);',+ '> 12 | line12 = foo(12);',+ ' | ^',+ ].join('\n'));+});++test('should pad line numbers to the widest one', () => {+ expect(codeFrame(source, { line: 9, column: 1 })).toBe([+ ' 7 | line7 = foo(7);',+ ' 8 | line8 = foo(8);',+ '> 9 | line9 = foo(9);',+ ' | ^',+ ' 10 | line10 = foo(10);',+ ' 11 | line11 = foo(11);',+ ' 12 | line12 = foo(12);',+ ].join('\n'));+});++test('should print the message after the marker', () => {+ expect(codeFrame(source, { line: 5, column: 3 }, { linesAbove: 0, linesBelow: 0, message: 'Boom' })).toBe([+ '> 5 | line5 = foo(5);',+ ' | ^ Boom',+ ].join('\n'));+});++test('should print the message above the frame without a column', () => {+ expect(codeFrame(source, { line: 5 }, { linesAbove: 0, linesBelow: 0, message: 'Boom' })).toBe([+ ' Boom',+ '> 5 | line5 = foo(5);',+ ].join('\n'));+});++test('should keep tabs before the marker', () => {+ expect(codeFrame('a\n\t\tfoo(\tbar)\nb', { line: 2, column: 6 })).toBe([+ ' 1 | a',+ '> 2 | \t\tfoo(\tbar)',+ ' | \t\t ^',+ ' 3 | b',+ ].join('\n'));+});++test('should not add a space after the gutter for empty lines', () => {+ expect(codeFrame('a\n\nfoo\n \nb', { line: 3, column: 1 })).toBe([+ ' 1 | a',+ ' 2 |',+ '> 3 | foo',+ ' | ^',+ ' 4 | ',+ ' 5 | b',+ ].join('\n'));+});++test('should split lines on all line terminators', () => {+ expect(codeFrame('a\r\nb\rc\u2028d\ne', { line: 3, column: 1 }, { linesAbove: 5, linesBelow: 5 })).toBe([+ ' 1 | a',+ ' 2 | b',+ '> 3 | c',+ ' | ^',+ ' 4 | d',+ ' 5 | e',+ ].join('\n'));+});++test('should highlight code', () => {+ const code = `const page = new Page(/re/g, 'a', 42) + x; // comment`;+ expect(codeFrame(code, { line: 1, column: 7 }, { colors: tagColors, message: 'Boom' })).toBe([+ '<red><bold>></bold></red><gray> 1 |</gray> ' ++ '<cyan>const</cyan> page <yellow>=</yellow> <cyan>new</cyan> <yellow>Page</yellow>(<magenta>/re/g</magenta><yellow>,</yellow> ' ++ `<green>'a'</green><yellow>,</yellow> <magenta>42</magenta>) <yellow>+</yellow> x<yellow>;</yellow> <gray>// comment</gray>`,+ ' <gray> |</gray> <red><bold>^</bold></red> <red><bold>Boom</bold></red>',+ ].join('\n'));+});++test('should highlight multi-line tokens on each line', () => {+ expect(codeFrame('a = `x ${`y`}\nz`; /* b\nc */', { line: 1 }, { colors: tagColors })).toBe([+ '<red><bold>></bold></red><gray> 1 |</gray> a <yellow>=</yellow> <green>`x ${`y`}</green>',+ ' <gray> 2 |</gray> <green>z`</green><yellow>;</yellow> <gray>/* b</gray>',+ ' <gray> 3 |</gray> <gray>c */</gray>',+ ].join('\n'));+});++test('should highlight keywords used as property names as identifiers', () => {+ expect(codeFrame('promise.catch(e => e).finally(done);', { line: 1 }, { colors: tagColors })).toBe(+ '<red><bold>></bold></red><gray> 1 |</gray> promise<yellow>.</yellow>catch(e <yellow>=></yellow> e)<yellow>.</yellow>finally(done)<yellow>;</yellow>'+ );+});diff --git a/utils/doclint/linting-code-snippets/cli.js b/utils/doclint/linting-code-snippets/cli.jsindex 38b11fa761..fa56ce1eaf 100644--- a/utils/doclint/linting-code-snippets/cli.js+++ b/utils/doclint/linting-code-snippets/cli.js@@ -26,7 +26,7 @@ const { ESLint } = require('eslint')const child_process = require('child_process');const os = require('os');-const { codeFrameColumns } = require('@babel/code-frame');+const { codeFrame, webColors } = require('../../../packages/playwright-core/lib/coreBundle').iso;/** @typedef {import('../documentation').Type} Type *//** @typedef {import('../../markdown').MarkdownNode} MarkdownNode */@@ -201,7 +201,7 @@ class JSLintingService extends LintingService {if (!results || !results.length || !results[0].messages.length)return { status: 'ok' };const result = results[0];- const error = result.source ? results[0].messages[0].message + '\n\n' + codeFrameColumns(result.source, { start: result.messages[0] }, { highlightCode: true }) : results[0].messages[0].message;+ const error = result.source ? results[0].messages[0].message + '\n\n' + codeFrame(result.source, result.messages[0], { colors: webColors }) : results[0].messages[0].message;return { status: 'error', error };}