| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/61475 |
Sorry, something went wrong.
|
commit: 455553e |
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks!
Sorry, something went wrong.
There was a problem hiding this comment.
This PR aligns @babel/code-frame column handling with Babel AST locations by treating columns as 0-based, and updates internal Babel callers/tests to remove prior + 1 compensations.
Changes:
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file| File | Description |
|---|---|
| packages/babel-traverse/src/path/replacement.ts | Removes + 1 adjustment when passing parser error locations into codeFrameColumns. |
| packages/babel-core/src/transformation/file/file.ts | Removes + 1 adjustments for node locs passed into codeFrameColumns. |
| packages/babel-core/src/parser/index.ts | Removes + 1 adjustment for parser error locations used in code frames. |
| packages/babel-code-frame/test/index.js | Updates existing tests to 0-based columns and adds new tests for AST-style locations including column 0. |
| packages/babel-code-frame/test/color-detection.js | Updates highlight tests to use 0-based columns and column 0. |
| packages/babel-code-frame/src/common.ts | Switches missing-column sentinel to null and updates spacing/length calculations for 0-based columns. |
packages/babel-code-frame/src/common.ts:65
const startLoc: Location = {
// @ts-expect-error default value
column: null,
// @ts-expect-error default value
line: -1,
...loc.start,
};
packages/babel-code-frame/src/common.ts:106
} else {
const sourceLength = source[lineNumber - i].length;
markerLines[lineNumber] = [0, sourceLength];
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was a problem hiding this comment.
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was a problem hiding this comment.
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)packages/babel-code-frame/src/common.ts:65
const startLoc: Location = {
// @ts-expect-error default value
column: null,
// @ts-expect-error default value
line: -1,
...loc.start,
};
packages/babel-code-frame/src/common.ts:117
if (startColumn === endColumn) {
if (startColumn != null) {
markerLines[startLine] = [startColumn, 0];
} else {
markerLines[startLine] = true;
}
} else {
markerLines[startLine] = [startColumn, endColumn - startColumn];
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
…bel#17316) `codeFrameColumns` treated the `column` property as 1-based, but Babel AST locations use 0-based columns. This caused the caret/underline to be off by one character when passing AST `.loc` objects directly. - Removed the `- 1` offset in marker spacing calculation - Removed the `+ 1` in multiline start marker count - Changed default column sentinel from `0` to `null` so that `column: 0` is treated as a valid position - Updated falsiness checks (`!startColumn`) to null checks - Removed `+ 1` workarounds in babel-core and babel-traverse callers This is a breaking change for external consumers of `@babel/code-frame` who passed 1-based columns manually.
There was a problem hiding this comment.
Copilot reviewed 7 out of 7 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)packages/babel-code-frame/src/common.ts:66
const startLoc: Location = {
// @ts-expect-error default value
column: null,
// @ts-expect-error default value
line: -1,
...loc.start,
};
const endLoc: Location = {
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
There was a problem hiding this comment.
Thank you. The changes now look good to me. Could you open a docs PR to babel/website?
Sorry, something went wrong.
|
Thanks for the review. Docs PR opened: babel/website#3200 |
Sorry, something went wrong.
Updates the codeFrameColumns examples to use 0-based column values matching the API change in babel/babel#17849, and adds a Babel 7 to Babel 8 migration note.
Add @babel/code-frame entry under v8-migration-api.md for the 0-based column change in babel/babel#17849.
Add @babel/code-frame entry under v8-migration-api.md for the 0-based column change in babel/babel#17849.
Add @babel/code-frame entry under v8-migration-api.md for the 0-based column change in babel/babel#17849.
|
@SimenB This should be the last breaking change that can affect Jest |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary
Fixes #17316
codeFrameColumns currently treats columns as 1-based, while Babel AST locations are 0-based. This mismatch causes caret/underline markers to be off by one character when codeFrameColumns is called with AST locations directly.
This PR updates @babel/code-frame to treat columns as 0-based, and removes the corresponding + 1 compensations in internal callers (@babel/core, @babel/traverse) that were working around the previous behavior.
Changes
@babel/code-frame (common.ts)
@babel/core and @babel/traverse
Tests
Breaking change note
This may be a breaking change for external consumers who manually pass 1-based column values to codeFrameColumns.
Consumers passing Babel AST .loc objects (the primary use case) will now receive correct results without manual adjustment.
If preferred, this change can be targeted for Babel 8.
Test plan