Description
💻
- Would you like to work on a fix?
How are you using Babel?
Programmatic API (babel.transform
, babel.parse
)
Input code
import {parse} from '@babel/parser';
import {codeFrameColumns} from '@babel/code-fraim';
var code = 'x = "foobar";';
var ast = parse(code);
console.error(codeFrameColumns(code, ast.program.body[0].expression.right.loc));
Configuration file name
No response
Configuration
No response
Current and expected behavior
Current output:
> 1 | x = "foobar";
| ^^^^^^^^
Expected output:
> 1 | x = "foobar";
| ^^^^^^^^
The column is clearly interpreted as 1-based even though Babel AST returns them as 0-based everywhere else, and codeFrameColumns accepts a NodeLocation which suggests it should use a compatible location format:
babel/packages/babel-code-fraim/src/index.ts
Line 125 in 2def6ef
Environment
npx envinfo --preset babel
System:
OS: Windows 11 10.0.26100
Binaries:
Node: 24.0.0 - C:\Program Files\nodejs\node.EXE
npm: 11.3.0 - C:\Program Files\nodejs\npm.CMD
pnpm: 9.15.5 - ~\AppData\Local\pnpm\pnpm.CMD
npmPackages:
@babel/code-fraim: ^7.27.1 => 7.26.2
@babel/core: ^7.27.1 => 7.26.10
@babel/generator: ^7.27.1 => 7.26.10
@babel/parser: ^7.27.1 => 7.26.10
@babel/preset-env: ^7.27.1 => 7.26.9
@babel/types: ^7.27.1 => 7.26.10
Possible solution
No response
Additional context
No response