Skip to content

Commit

Permalink
Fix off by one error with line numbers (#6007)
Browse files Browse the repository at this point in the history
**Problem:**
Babel starts line numbers from 1, vscode starts them from 0.

**Fix:**
Subtract 1 from the Babel line numbers before storing it in the Bounds
object

**Manual Tests:**
I hereby swear that:

- [x] I opened a hydrogen project and it loaded
- [x] I could navigate to various routes in Preview mode
  • Loading branch information
gbalint authored Jun 20, 2024
1 parent 9359aef commit edc6e47
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ export function generateComponentBounds(
const { loc } = component
if (loc != null) {
componentBoundsByModule[moduleName][componentName] = {
startLine: loc.start.line,
startCol: loc.start.column,
endLine: loc.end.line,
endCol: loc.end.column,
startLine: loc.start.line - 1,
startCol: loc.start.column - 1,
endLine: loc.end.line - 1,
endCol: loc.end.column - 1,
}
}
})
Expand Down
64 changes: 32 additions & 32 deletions editor/src/core/property-controls/property-controls-local.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ describe('registered property controls', () => {
},
"source": Object {
"bounds": Object {
"endCol": 5,
"endLine": 42,
"startCol": 4,
"startLine": 5,
"endCol": 4,
"endLine": 41,
"startCol": 3,
"startLine": 4,
},
"sourceDescriptorFile": "/utopia/components.utopia.js",
"type": "DESCRIPTOR_FILE",
Expand Down Expand Up @@ -378,10 +378,10 @@ describe('registered property controls', () => {
},
"source": Object {
"bounds": Object {
"endCol": 5,
"endLine": 16,
"startCol": 4,
"startLine": 6,
"endCol": 4,
"endLine": 15,
"startCol": 3,
"startLine": 5,
},
"sourceDescriptorFile": "/utopia/components.utopia.js",
"type": "DESCRIPTOR_FILE",
Expand Down Expand Up @@ -1011,10 +1011,10 @@ describe('registered property controls', () => {
},
"source": Object {
"bounds": Object {
"endCol": 5,
"endLine": 32,
"startCol": 4,
"startLine": 5,
"endCol": 4,
"endLine": 31,
"startCol": 3,
"startLine": 4,
},
"sourceDescriptorFile": "/utopia/components.utopia.js",
"type": "DESCRIPTOR_FILE",
Expand Down Expand Up @@ -1931,10 +1931,10 @@ describe('registered property controls', () => {
},
"source": Object {
"bounds": Object {
"endCol": 5,
"endLine": 34,
"startCol": 4,
"startLine": 6,
"endCol": 4,
"endLine": 33,
"startCol": 3,
"startLine": 5,
},
"sourceDescriptorFile": "/utopia/components.utopia.js",
"type": "DESCRIPTOR_FILE",
Expand Down Expand Up @@ -2688,10 +2688,10 @@ describe('Lifecycle management of registering components', () => {
.toMatchInlineSnapshot(`
Object {
"bounds": Object {
"endCol": 5,
"endLine": 12,
"startCol": 4,
"startLine": 5,
"endCol": 4,
"endLine": 11,
"startCol": 3,
"startLine": 4,
},
"sourceDescriptorFile": "/utopia/components1.utopia.js",
"type": "DESCRIPTOR_FILE",
Expand All @@ -2705,10 +2705,10 @@ describe('Lifecycle management of registering components', () => {
.toMatchInlineSnapshot(`
Object {
"bounds": Object {
"endCol": 5,
"endLine": 12,
"startCol": 4,
"startLine": 5,
"endCol": 4,
"endLine": 11,
"startCol": 3,
"startLine": 4,
},
"sourceDescriptorFile": "/utopia/components2.utopia.js",
"type": "DESCRIPTOR_FILE",
Expand Down Expand Up @@ -2746,10 +2746,10 @@ describe('Lifecycle management of registering components', () => {
.toMatchInlineSnapshot(`
Object {
"bounds": Object {
"endCol": 5,
"endLine": 12,
"startCol": 4,
"startLine": 5,
"endCol": 4,
"endLine": 11,
"startCol": 3,
"startLine": 4,
},
"sourceDescriptorFile": "/utopia/components1.utopia.js",
"type": "DESCRIPTOR_FILE",
Expand Down Expand Up @@ -2797,10 +2797,10 @@ describe('Lifecycle management of registering components', () => {
.toMatchInlineSnapshot(`
Object {
"bounds": Object {
"endCol": 5,
"endLine": 12,
"startCol": 4,
"startLine": 5,
"endCol": 4,
"endLine": 11,
"startCol": 3,
"startLine": 4,
},
"sourceDescriptorFile": "/utopia/components1.utopia.js",
"type": "DESCRIPTOR_FILE",
Expand Down

0 comments on commit edc6e47

Please sign in to comment.