Skip to content

Commit 1bfb437

Browse files
eps1lonmischnic
andcommitted
[sourcemaps] Consistent cursor columns
Co-authored-by: Niklas Mischkulnig <[email protected]>
1 parent f74a169 commit 1bfb437

File tree

93 files changed

+822
-941
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+822
-941
lines changed

packages/next/src/build/webpack/plugins/wellknown-errors-plugin/parseNotFoundError.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async function getSourceFrame(
5757
input: any,
5858
fileName: any,
5959
compilation: any
60-
): Promise<{ frame: string; lineNumber: string; column: string }> {
60+
): Promise<{ frame: string; line1: string; column1: string }> {
6161
try {
6262
const loc =
6363
input.loc || input.dependencies.map((d: any) => d.loc).filter(Boolean)[0]
@@ -83,21 +83,21 @@ async function getSourceFrame(
8383
arguments: [],
8484
file: fileName,
8585
methodName: '',
86-
lineNumber: loc.start.line,
86+
line1: loc.start.line,
8787
// loc is 0-based but columns in stack frames are 1-based.
88-
column: (loc.start.column ?? 0) + 1,
88+
column1: (loc.start.column ?? 0) + 1,
8989
},
9090
})
9191

9292
return {
9393
frame: result?.originalCodeFrame ?? '',
94-
lineNumber: result?.originalStackFrame?.lineNumber?.toString() ?? '',
95-
column: result?.originalStackFrame?.column?.toString() ?? '',
94+
line1: result?.originalStackFrame?.line1?.toString() ?? '',
95+
column1: result?.originalStackFrame?.column1?.toString() ?? '',
9696
}
9797
}
9898
} catch {}
9999

100-
return { frame: '', lineNumber: '', column: '' }
100+
return { frame: '', line1: '', column1: '' }
101101
}
102102

103103
function getFormattedFileName(
@@ -141,7 +141,7 @@ export async function getNotFoundError(
141141
}
142142

143143
try {
144-
const { frame, lineNumber, column } = await getSourceFrame(
144+
const { frame, line1, column1 } = await getSourceFrame(
145145
input,
146146
fileName,
147147
compilation
@@ -181,8 +181,8 @@ export async function getNotFoundError(
181181
const formattedFileName = getFormattedFileName(
182182
fileName,
183183
module,
184-
lineNumber,
185-
column
184+
line1,
185+
column1
186186
)
187187

188188
return new SimpleWebpackError(formattedFileName, message)

packages/next/src/next-devtools/dev-overlay/components/call-stack-frame/call-stack-frame.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ const frame = {
3434
file: './app/page.tsx',
3535
methodName: 'MyComponent',
3636
arguments: [],
37-
lineNumber: 10,
38-
column: 5,
37+
line1: 10,
38+
column1: 5,
3939
ignored: false,
4040
},
4141
sourceStackFrame: {
4242
file: './app/page.tsx',
4343
methodName: 'MyComponent',
4444
arguments: [],
45-
lineNumber: 10,
46-
column: 5,
45+
line1: 10,
46+
column1: 5,
4747
},
4848
error: false as const,
4949
reason: null,

packages/next/src/next-devtools/dev-overlay/components/call-stack-frame/call-stack-frame.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { StackFrame } from 'next/dist/compiled/stacktrace-parser'
21
import type { OriginalStackFrame } from '../../../shared/stack-frame'
32

43
import { HotlinkedText } from '../hot-linked-text'
@@ -11,14 +10,14 @@ export const CallStackFrame: React.FC<{
1110
}> = function CallStackFrame({ frame }) {
1211
// TODO: ability to expand resolved frames
1312

14-
const f: StackFrame = frame.originalStackFrame ?? frame.sourceStackFrame
13+
const f = frame.originalStackFrame ?? frame.sourceStackFrame
1514
const hasSource = Boolean(frame.originalCodeFrame)
1615
const open = useOpenInEditor(
1716
hasSource
1817
? {
1918
file: f.file,
20-
lineNumber: f.lineNumber,
21-
column: f.column,
19+
line1: f.line1 ?? 1,
20+
column1: f.column1 ?? 1,
2221
}
2322
: undefined
2423
)

packages/next/src/next-devtools/dev-overlay/components/call-stack/call-stack.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ const frame = {
3333
file: './app/page.tsx',
3434
methodName: 'MyComponent',
3535
arguments: [],
36-
lineNumber: 10,
37-
column: 5,
36+
line1: 10,
37+
column1: 5,
3838
ignored: false,
3939
},
4040
sourceStackFrame: {
4141
file: './app/page.tsx',
4242
methodName: 'MyComponent',
4343
arguments: [],
44-
lineNumber: 10,
45-
column: 5,
44+
line1: 10,
45+
column1: 5,
4646
},
4747
originalCodeFrame: 'export default function MyComponent() {',
4848
error: false as const,

packages/next/src/next-devtools/dev-overlay/components/code-frame/code-frame.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const baseStackFrame = {
1717
file: './app/page.tsx',
1818
methodName: 'Home',
1919
arguments: [],
20-
lineNumber: 10,
21-
column: 5,
20+
line1: 10,
21+
column1: 5,
2222
}
2323

2424
export const SimpleCodeFrame: Story = {

packages/next/src/next-devtools/dev-overlay/components/code-frame/code-frame.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
import type { StackFrame } from 'next/dist/compiled/stacktrace-parser'
21
import { useMemo } from 'react'
32
import { HotlinkedText } from '../hot-linked-text'
4-
import { getFrameSource } from '../../../shared/stack-frame'
3+
import { getFrameSource, type StackFrame } from '../../../shared/stack-frame'
54
import { useOpenInEditor } from '../../utils/use-open-in-editor'
65
import { ExternalIcon } from '../../icons/external'
76
import { FileIcon } from '../../icons/file'
@@ -11,7 +10,10 @@ import {
1110
parseLineNumberFromCodeFrameLine,
1211
} from './parse-code-frame'
1312

14-
export type CodeFrameProps = { stackFrame: StackFrame; codeFrame: string }
13+
export type CodeFrameProps = {
14+
stackFrame: StackFrame
15+
codeFrame: string
16+
}
1517

1618
export function CodeFrame({ stackFrame, codeFrame }: CodeFrameProps) {
1719
const parsedLineStates = useMemo(() => {
@@ -27,8 +29,8 @@ export function CodeFrame({ stackFrame, codeFrame }: CodeFrameProps) {
2729

2830
const open = useOpenInEditor({
2931
file: stackFrame.file,
30-
lineNumber: stackFrame.lineNumber,
31-
column: stackFrame.column,
32+
line1: stackFrame.line1 ?? 1,
33+
column1: stackFrame.column1 ?? 1,
3234
})
3335

3436
const fileExtension = stackFrame?.file?.split('.').pop()

packages/next/src/next-devtools/dev-overlay/components/code-frame/parse-code-frame.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ describe('parse line numbers', () => {
99
const input = {
1010
stackFrame: {
1111
file: 'app/page.tsx',
12-
lineNumber: 2,
13-
column: 9,
12+
line1: 2,
13+
column1: 9,
1414
methodName: 'Page',
1515
arguments: [],
1616
ignored: false,
@@ -61,8 +61,8 @@ describe('parse line numbers', () => {
6161
const input = {
6262
stackFrame: {
6363
file: 'app/page.tsx',
64-
lineNumber: 6,
65-
column: 7,
64+
line1: 6,
65+
column1: 7,
6666
methodName: 'Page',
6767
arguments: [],
6868
},

packages/next/src/next-devtools/dev-overlay/components/code-frame/parse-code-frame.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { StackFrame } from 'next/dist/compiled/stacktrace-parser'
21
import Anser, { type AnserJsonEntry } from 'next/dist/compiled/anser'
32
import stripAnsi from 'next/dist/compiled/strip-ansi'
3+
import type { StackFrame } from '../../../shared/stack-frame'
44

55
// Strip leading spaces out of the code frame
66
export function formatCodeFrame(codeFrame: string) {
@@ -77,19 +77,19 @@ export function parseLineNumberFromCodeFrameLine(
7777
stackFrame: StackFrame
7878
) {
7979
let lineNumberToken: AnserJsonEntry | undefined
80-
let lineNumber: string | undefined
80+
let line1: string | undefined
8181
// parse line number from line first 2 tokens
8282
// e.g. ` > 1 | const foo = 'bar'` => `1`, first token is `1 |`
8383
// e.g. ` 2 | const foo = 'bar'` => `2`. first 2 tokens are ' ' and ' 2 |'
8484
if (line[0]?.content === '>' || line[0]?.content === ' ') {
8585
lineNumberToken = line[1]
86-
lineNumber = lineNumberToken?.content?.replace('|', '')?.trim()
86+
line1 = lineNumberToken?.content?.replace('|', '')?.trim()
8787
}
8888

8989
// When the line number is possibly undefined, it can be just the non-source code line
9090
// e.g. the ^ sign can also take a line, we skip rendering line number for it
9191
return {
92-
lineNumber,
93-
isErroredLine: lineNumber === stackFrame.lineNumber?.toString(),
92+
lineNumber: line1,
93+
isErroredLine: line1 === stackFrame.line1?.toString(),
9494
}
9595
}

packages/next/src/next-devtools/dev-overlay/components/errors/error-overlay-call-stack/error-overlay-call-stack.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ const frame = {
3333
file: './app/page.tsx',
3434
methodName: 'MyComponent',
3535
arguments: [],
36-
lineNumber: 10,
37-
column: 5,
36+
line1: 10,
37+
column1: 5,
3838
ignored: false,
3939
},
4040
sourceStackFrame: {
4141
file: './app/page.tsx',
4242
methodName: 'MyComponent',
4343
arguments: [],
44-
lineNumber: 10,
45-
column: 5,
44+
line1: 10,
45+
column1: 5,
4646
},
4747
originalCodeFrame: 'export default function MyComponent() {',
4848
error: false as const,

packages/next/src/next-devtools/dev-overlay/components/terminal/editor-link.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ type EditorLinkProps = {
1111
export function EditorLink({ file, location }: EditorLinkProps) {
1212
const open = useOpenInEditor({
1313
file,
14-
lineNumber: location?.line ?? 1,
15-
column: location?.column ?? 0,
14+
line1: location?.line ?? 1,
15+
column1: location?.column ?? 1,
1616
})
1717

1818
return (

0 commit comments

Comments
 (0)