@forge-kit/plugin-source-map-prase 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app.js +17 -19
- package/dist/node.js +2552 -0
- package/package.json +5 -3
- package/src/App.less +35 -26
- package/src/App.tsx +70 -23
- package/src/components/map-input-panel/index.less +71 -78
- package/src/components/map-input-panel/index.tsx +19 -20
- package/src/components/panel-card/index.less +16 -13
- package/src/components/panel-card/index.tsx +2 -2
- package/src/components/trace-chain/index.less +119 -120
- package/src/components/trace-chain/index.tsx +9 -7
- package/src/main.tsx +1 -1
- package/src/node/index.ts +6 -0
- package/src/{utils/source-map → node/trace/core}/base/registry.ts +14 -11
- package/src/{utils/source-map → node/trace/core}/base/types.ts +1 -0
- package/src/node/trace/core/domain/chain-slots.ts +33 -0
- package/src/{utils/source-map → node/trace/core}/domain/source-content.ts +15 -2
- package/src/node/trace/core/domain/trace-resolver.ts +179 -0
- package/src/node/trace/core/domain/view-model.ts +57 -0
- package/src/node/trace/resolve/context.ts +59 -0
- package/src/node/trace/resolve/index.ts +97 -0
- package/src/node/trace/resolve/input.ts +35 -0
- package/src/node/trace/resolve/snippet-limit.ts +35 -0
- package/src/node/trace/resolve/types.ts +37 -0
- package/src/node/trace/runner.ts +149 -0
- package/src/shared/trace-common.ts +104 -0
- package/src/shared/trace-contract.ts +29 -0
- package/src/types.ts +11 -0
- package/src/utils/trace-ui/index.ts +12 -0
- package/src/utils/trace-ui/state.ts +81 -0
- package/src/utils/source-map/domain/chain-slots.ts +0 -59
- package/src/utils/source-map/domain/trace-resolver.ts +0 -165
- package/src/utils/source-map/domain/view-model.ts +0 -20
- package/src/utils/source-map/facade/source-map-utils.ts +0 -212
- package/src/utils/source-map/index.ts +0 -18
- /package/src/{utils/source-map → node/trace/core}/base/constants.ts +0 -0
- /package/src/{utils/source-map → node/trace/core}/base/path.ts +0 -0
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import {normalizePath, stripMapExt} from "../base/path";
|
|
2
|
-
import {registerSourceMap} from "../base/registry";
|
|
3
|
-
import type {ChainMapSlot, SourceMapRegistry} from "../base/types";
|
|
4
|
-
|
|
5
|
-
export const createChainSlotFromFile = async (file: File): Promise<ChainMapSlot> => {
|
|
6
|
-
const slotId = `${file.name}-${Math.random().toString(36).slice(2, 8)}`
|
|
7
|
-
|
|
8
|
-
try {
|
|
9
|
-
const fileText = await file.text()
|
|
10
|
-
const rawSourceMap = JSON.parse(fileText)
|
|
11
|
-
|
|
12
|
-
if (!rawSourceMap || typeof rawSourceMap !== "object" || typeof rawSourceMap.mappings !== "string") {
|
|
13
|
-
throw new Error("invalid source-map json")
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
id: slotId,
|
|
18
|
-
mapFileName: file.name,
|
|
19
|
-
sourceMapRecord: {rawSourceMap, mapFileName: file.name},
|
|
20
|
-
}
|
|
21
|
-
} catch (error) {
|
|
22
|
-
const message = error instanceof Error ? error.message : "unknown error"
|
|
23
|
-
return {
|
|
24
|
-
id: slotId,
|
|
25
|
-
mapFileName: file.name,
|
|
26
|
-
error: `${file.name}: ${message}`,
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export const buildRegistryFromChainSlots = (slots: ChainMapSlot[]) => {
|
|
32
|
-
let registry: SourceMapRegistry = {}
|
|
33
|
-
const orderedMapFileNames: string[] = []
|
|
34
|
-
|
|
35
|
-
slots.forEach((slot) => {
|
|
36
|
-
const {sourceMapRecord: record} = slot
|
|
37
|
-
if (!record) return
|
|
38
|
-
|
|
39
|
-
orderedMapFileNames.push(record.mapFileName)
|
|
40
|
-
registry = registerSourceMap(registry, record.mapFileName, record)
|
|
41
|
-
registry = registerSourceMap(registry, stripMapExt(record.mapFileName), record)
|
|
42
|
-
|
|
43
|
-
if (record.rawSourceMap.file) {
|
|
44
|
-
registry = registerSourceMap(registry, record.rawSourceMap.file, record)
|
|
45
|
-
}
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
return {registry, orderedMapFileNames}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export const getAutoEntryFileNameFromSlots = (slots: ChainMapSlot[]) => {
|
|
52
|
-
const firstValidSlot = slots.find((slot) => slot.sourceMapRecord)
|
|
53
|
-
if (!firstValidSlot?.sourceMapRecord) return ""
|
|
54
|
-
|
|
55
|
-
const mappedFile = firstValidSlot.sourceMapRecord.rawSourceMap.file
|
|
56
|
-
if (mappedFile) return normalizePath(mappedFile)
|
|
57
|
-
|
|
58
|
-
return stripMapExt(firstValidSlot.sourceMapRecord.mapFileName)
|
|
59
|
-
}
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
import {SourceMapConsumer, type RawSourceMap} from "source-map-js";
|
|
2
|
-
import {MAX_TRACE_DEPTH} from "../base/constants";
|
|
3
|
-
import {getSourceMapByFileName, getSourceMapByMapFileName} from "../base/registry";
|
|
4
|
-
import type {ResolveTraceOptions, SourceMapRecord, SourceMapRegistry, TraceHop, TraceLocation} from "../base/types";
|
|
5
|
-
|
|
6
|
-
interface ResolvedTraceHop extends TraceHop {
|
|
7
|
-
output: TraceLocation
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
const toLocationCursor = (location: TraceLocation) => {
|
|
11
|
-
return `${location.fileName}:${location.lineNumber}:${location.columnNumber}`
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const isSameLocation = (left: TraceLocation, right: TraceLocation) => {
|
|
15
|
-
return (
|
|
16
|
-
left.fileName === right.fileName
|
|
17
|
-
&& left.lineNumber === right.lineNumber
|
|
18
|
-
&& left.columnNumber === right.columnNumber
|
|
19
|
-
)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const resolveOriginalLocation = (
|
|
23
|
-
rawSourceMap: RawSourceMap,
|
|
24
|
-
position: { line: number; column: number },
|
|
25
|
-
): TraceLocation | null => {
|
|
26
|
-
const consumer = new SourceMapConsumer(rawSourceMap)
|
|
27
|
-
|
|
28
|
-
const attempts = [
|
|
29
|
-
{line: position.line, column: position.column, bias: SourceMapConsumer.GREATEST_LOWER_BOUND},
|
|
30
|
-
{line: position.line, column: 0, bias: SourceMapConsumer.GREATEST_LOWER_BOUND},
|
|
31
|
-
{line: position.line, column: position.column, bias: SourceMapConsumer.LEAST_UPPER_BOUND},
|
|
32
|
-
{line: position.line, column: 0, bias: SourceMapConsumer.LEAST_UPPER_BOUND},
|
|
33
|
-
]
|
|
34
|
-
|
|
35
|
-
for (const attempt of attempts) {
|
|
36
|
-
const found = consumer.originalPositionFor(attempt)
|
|
37
|
-
if (found.source && found.line != null && found.column != null) {
|
|
38
|
-
return {
|
|
39
|
-
fileName: found.source,
|
|
40
|
-
lineNumber: found.line,
|
|
41
|
-
columnNumber: found.column,
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return null
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const resolveHopFromRecord = (sourceMapRecord: SourceMapRecord, input: TraceLocation): ResolvedTraceHop | null => {
|
|
50
|
-
try {
|
|
51
|
-
const output = resolveOriginalLocation(sourceMapRecord.rawSourceMap, {
|
|
52
|
-
line: input.lineNumber,
|
|
53
|
-
column: input.columnNumber,
|
|
54
|
-
})
|
|
55
|
-
if (!output) return null
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
input,
|
|
59
|
-
output,
|
|
60
|
-
mapFileName: sourceMapRecord.mapFileName,
|
|
61
|
-
}
|
|
62
|
-
} catch {
|
|
63
|
-
return null
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const appendUnresolvedHop = (traceHops: TraceHop[], input: TraceLocation, mapFileName?: string) => {
|
|
68
|
-
traceHops.push({input, mapFileName})
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const resolveTraceWithOrderedMaps = (
|
|
72
|
-
entry: TraceLocation,
|
|
73
|
-
sourceMaps: SourceMapRegistry,
|
|
74
|
-
orderedMapFileNames: string[],
|
|
75
|
-
maxDepth: number,
|
|
76
|
-
) => {
|
|
77
|
-
const traceHops: TraceHop[] = []
|
|
78
|
-
const visited = new Set<string>()
|
|
79
|
-
let current = entry
|
|
80
|
-
|
|
81
|
-
for (let depth = 0; depth < orderedMapFileNames.length && depth < maxDepth; depth++) {
|
|
82
|
-
const mapFileName = orderedMapFileNames[depth]
|
|
83
|
-
const cursor = toLocationCursor(current)
|
|
84
|
-
|
|
85
|
-
if (visited.has(cursor)) {
|
|
86
|
-
appendUnresolvedHop(traceHops, current, mapFileName)
|
|
87
|
-
continue
|
|
88
|
-
}
|
|
89
|
-
visited.add(cursor)
|
|
90
|
-
|
|
91
|
-
const sourceMapRecord = getSourceMapByMapFileName(sourceMaps, mapFileName)
|
|
92
|
-
if (!sourceMapRecord) {
|
|
93
|
-
appendUnresolvedHop(traceHops, current, mapFileName)
|
|
94
|
-
continue
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const hop = resolveHopFromRecord(sourceMapRecord, current)
|
|
98
|
-
if (!hop) {
|
|
99
|
-
appendUnresolvedHop(traceHops, current, sourceMapRecord.mapFileName)
|
|
100
|
-
continue
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
traceHops.push(hop)
|
|
104
|
-
current = hop.output
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
return traceHops
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const resolveTraceByFileLookup = (
|
|
111
|
-
entry: TraceLocation,
|
|
112
|
-
sourceMaps: SourceMapRegistry,
|
|
113
|
-
maxDepth: number,
|
|
114
|
-
) => {
|
|
115
|
-
const traceHops: TraceHop[] = []
|
|
116
|
-
const visited = new Set<string>()
|
|
117
|
-
let current = entry
|
|
118
|
-
|
|
119
|
-
for (let depth = 0; depth < maxDepth; depth++) {
|
|
120
|
-
const cursor = toLocationCursor(current)
|
|
121
|
-
|
|
122
|
-
if (visited.has(cursor)) {
|
|
123
|
-
appendUnresolvedHop(traceHops, current)
|
|
124
|
-
break
|
|
125
|
-
}
|
|
126
|
-
visited.add(cursor)
|
|
127
|
-
|
|
128
|
-
const sourceMapRecord = getSourceMapByFileName(sourceMaps, current.fileName)
|
|
129
|
-
if (!sourceMapRecord) {
|
|
130
|
-
if (traceHops.length === 0) {
|
|
131
|
-
appendUnresolvedHop(traceHops, current)
|
|
132
|
-
}
|
|
133
|
-
break
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const hop = resolveHopFromRecord(sourceMapRecord, current)
|
|
137
|
-
if (!hop) {
|
|
138
|
-
appendUnresolvedHop(traceHops, current, sourceMapRecord.mapFileName)
|
|
139
|
-
break
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
traceHops.push(hop)
|
|
143
|
-
if (isSameLocation(hop.output, current)) {
|
|
144
|
-
break
|
|
145
|
-
}
|
|
146
|
-
current = hop.output
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return traceHops
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export const resolveTraceBySourceMaps = async (
|
|
153
|
-
entry: TraceLocation,
|
|
154
|
-
sourceMaps: SourceMapRegistry,
|
|
155
|
-
orderedMapFileNames: string[] = [],
|
|
156
|
-
options: ResolveTraceOptions = {},
|
|
157
|
-
): Promise<TraceHop[]> => {
|
|
158
|
-
const maxDepth = options.maxDepth ?? MAX_TRACE_DEPTH
|
|
159
|
-
|
|
160
|
-
if (orderedMapFileNames.length > 0) {
|
|
161
|
-
return resolveTraceWithOrderedMaps(entry, sourceMaps, orderedMapFileNames, maxDepth)
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return resolveTraceByFileLookup(entry, sourceMaps, maxDepth)
|
|
165
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import {DEFAULT_CONTEXT_LINE_RADIUS} from "../base/constants";
|
|
2
|
-
import type {TraceLocation} from "../base/types";
|
|
3
|
-
|
|
4
|
-
export const toDisplayLocation = (location: TraceLocation): TraceLocation => ({...location})
|
|
5
|
-
|
|
6
|
-
export const createCodeExcerpt = (fullCode: string, targetLine: number, radius = DEFAULT_CONTEXT_LINE_RADIUS) => {
|
|
7
|
-
const lines = fullCode.split(/\r?\n/)
|
|
8
|
-
if (lines.length === 0) {
|
|
9
|
-
return {code: fullCode, highlightLine: targetLine}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const safeTarget = Math.min(Math.max(targetLine, 1), lines.length)
|
|
13
|
-
const start = Math.max(1, safeTarget - radius)
|
|
14
|
-
const end = Math.min(lines.length, safeTarget + radius)
|
|
15
|
-
|
|
16
|
-
return {
|
|
17
|
-
code: lines.slice(start - 1, end).join("\n"),
|
|
18
|
-
highlightLine: safeTarget - start + 1,
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,212 +0,0 @@
|
|
|
1
|
-
import {DEFAULT_CONTEXT_LINE_RADIUS, MAX_TRACE_DEPTH} from "../base/constants";
|
|
2
|
-
import {createChainSlotFromFile, buildRegistryFromChainSlots, getAutoEntryFileNameFromSlots} from "../domain/chain-slots";
|
|
3
|
-
import {resolveSourceCodeFromTrace, getLastResolvedOutput} from "../domain/source-content";
|
|
4
|
-
import {resolveTraceBySourceMaps} from "../domain/trace-resolver";
|
|
5
|
-
import {toDisplayLocation, createCodeExcerpt} from "../domain/view-model";
|
|
6
|
-
import type {
|
|
7
|
-
ChainMapSlot,
|
|
8
|
-
ResolvedSourceMeta,
|
|
9
|
-
SourceMapRegistry,
|
|
10
|
-
TraceHop,
|
|
11
|
-
TraceLocation,
|
|
12
|
-
} from "../base/types";
|
|
13
|
-
|
|
14
|
-
export interface TraceOutputState {
|
|
15
|
-
traceData: TraceHop[]
|
|
16
|
-
traceCode: string
|
|
17
|
-
resolvedSourceMeta: ResolvedSourceMeta | null
|
|
18
|
-
traceHighlightLines: number[]
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface SourceMapChainState {
|
|
22
|
-
sourceMaps: SourceMapRegistry
|
|
23
|
-
sourceMapFileNames: string[]
|
|
24
|
-
chainMapSlots: ChainMapSlot[]
|
|
25
|
-
entryFileName: string
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface TraceDisplayHop {
|
|
29
|
-
input: TraceLocation
|
|
30
|
-
output?: TraceLocation
|
|
31
|
-
mapFileName?: string
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export interface ResolveInputConfig {
|
|
35
|
-
entryFileName: string
|
|
36
|
-
entryLine: string
|
|
37
|
-
entryColumn: string
|
|
38
|
-
contextLineRadius: string
|
|
39
|
-
mapCount: number
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
interface ResolveTaskContext {
|
|
43
|
-
entry: TraceLocation
|
|
44
|
-
contextLineRadius: number
|
|
45
|
-
sourceMaps: SourceMapRegistry
|
|
46
|
-
sourceMapFileNames: string[]
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
type ResolveInputValidation =
|
|
50
|
-
| { ok: true; entry: TraceLocation; contextLineRadius: number }
|
|
51
|
-
| { ok: false; message: string }
|
|
52
|
-
|
|
53
|
-
export class SourceMapUtils {
|
|
54
|
-
static readonly MAX_TRACE_DEPTH = MAX_TRACE_DEPTH
|
|
55
|
-
static readonly DEFAULT_CONTEXT_LINE_RADIUS = DEFAULT_CONTEXT_LINE_RADIUS
|
|
56
|
-
|
|
57
|
-
static createInitialOutputState(): TraceOutputState {
|
|
58
|
-
return {
|
|
59
|
-
traceData: [],
|
|
60
|
-
traceCode: "请先上传一个或多个 .map 文件。",
|
|
61
|
-
resolvedSourceMeta: null,
|
|
62
|
-
traceHighlightLines: [],
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
static patchOutputMessage(prev: TraceOutputState, message: string): TraceOutputState {
|
|
67
|
-
return {
|
|
68
|
-
...prev,
|
|
69
|
-
traceCode: message,
|
|
70
|
-
traceHighlightLines: [],
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
static createChainSlotFromFile(file: File): Promise<ChainMapSlot> {
|
|
75
|
-
return createChainSlotFromFile(file)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
static buildChainStateFromSlots(slots: ChainMapSlot[]): SourceMapChainState {
|
|
79
|
-
const {registry, orderedMapFileNames} = buildRegistryFromChainSlots(slots)
|
|
80
|
-
return {
|
|
81
|
-
sourceMaps: registry,
|
|
82
|
-
sourceMapFileNames: orderedMapFileNames,
|
|
83
|
-
chainMapSlots: slots,
|
|
84
|
-
entryFileName: getAutoEntryFileNameFromSlots(slots),
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
static removeChainSlot(slots: ChainMapSlot[], slotId: string): ChainMapSlot[] {
|
|
89
|
-
return slots.filter((item) => item.id !== slotId)
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
static reorderChainSlots(slots: ChainMapSlot[], nextIds: string[]): ChainMapSlot[] {
|
|
93
|
-
const idOrder = new Map(nextIds.map((id, index) => [id, index]))
|
|
94
|
-
return [...slots].sort((a, b) => {
|
|
95
|
-
const aIndex = idOrder.get(a.id) ?? Number.MAX_SAFE_INTEGER
|
|
96
|
-
const bIndex = idOrder.get(b.id) ?? Number.MAX_SAFE_INTEGER
|
|
97
|
-
return aIndex - bIndex
|
|
98
|
-
})
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
static mapTraceForDisplay(traceData: TraceHop[]): TraceDisplayHop[] {
|
|
102
|
-
return traceData.map((item) => {
|
|
103
|
-
let output: TraceLocation | undefined
|
|
104
|
-
if (item.output) {
|
|
105
|
-
output = toDisplayLocation(item.output)
|
|
106
|
-
}
|
|
107
|
-
return {
|
|
108
|
-
input: toDisplayLocation(item.input),
|
|
109
|
-
output,
|
|
110
|
-
mapFileName: item.mapFileName,
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
static validateResolveInput(config: ResolveInputConfig): ResolveInputValidation {
|
|
116
|
-
const parsedLine = Number(config.entryLine)
|
|
117
|
-
const parsedColumn = Number(config.entryColumn)
|
|
118
|
-
const parsedContextLineRadius = Number(config.contextLineRadius)
|
|
119
|
-
const normalizedFileName = config.entryFileName.replace(/\\/g, "/").trim()
|
|
120
|
-
|
|
121
|
-
if (!normalizedFileName) {
|
|
122
|
-
return {ok: false, message: "请输入入口文件名,例如 index.js"}
|
|
123
|
-
}
|
|
124
|
-
if (!config.entryLine.trim()) {
|
|
125
|
-
return {ok: false, message: "请输入入口行号(1-based)。"}
|
|
126
|
-
}
|
|
127
|
-
if (!config.entryColumn.trim()) {
|
|
128
|
-
return {ok: false, message: "请输入入口列号(0-based)。"}
|
|
129
|
-
}
|
|
130
|
-
if (!Number.isInteger(parsedLine) || parsedLine < 1) {
|
|
131
|
-
return {ok: false, message: "行号必须是大于等于 1 的整数。"}
|
|
132
|
-
}
|
|
133
|
-
if (!Number.isInteger(parsedColumn) || parsedColumn < 0) {
|
|
134
|
-
return {ok: false, message: "列号必须是大于等于 0 的整数。"}
|
|
135
|
-
}
|
|
136
|
-
if (!Number.isInteger(parsedContextLineRadius) || parsedContextLineRadius < 0) {
|
|
137
|
-
return {ok: false, message: "上下文行数必须是大于等于 0 的整数。"}
|
|
138
|
-
}
|
|
139
|
-
if (config.mapCount === 0) {
|
|
140
|
-
return {ok: false, message: "未加载可用 map 文件,请先上传。"}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return {
|
|
144
|
-
ok: true,
|
|
145
|
-
entry: {
|
|
146
|
-
fileName: normalizedFileName,
|
|
147
|
-
lineNumber: parsedLine,
|
|
148
|
-
columnNumber: parsedColumn,
|
|
149
|
-
},
|
|
150
|
-
contextLineRadius: parsedContextLineRadius,
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
static async resolveTraceOutput(context: ResolveTaskContext): Promise<TraceOutputState> {
|
|
155
|
-
try {
|
|
156
|
-
const traceChain = await resolveTraceBySourceMaps(
|
|
157
|
-
context.entry,
|
|
158
|
-
context.sourceMaps,
|
|
159
|
-
context.sourceMapFileNames,
|
|
160
|
-
{maxDepth: this.MAX_TRACE_DEPTH},
|
|
161
|
-
)
|
|
162
|
-
|
|
163
|
-
const sourceCode = resolveSourceCodeFromTrace(traceChain, context.sourceMaps)
|
|
164
|
-
if (sourceCode) {
|
|
165
|
-
const excerpt = createCodeExcerpt(sourceCode.code, sourceCode.lineNumber, context.contextLineRadius)
|
|
166
|
-
return {
|
|
167
|
-
traceData: traceChain,
|
|
168
|
-
traceCode: excerpt.code,
|
|
169
|
-
resolvedSourceMeta: {
|
|
170
|
-
sourceFile: sourceCode.sourceFile,
|
|
171
|
-
lineNumber: sourceCode.lineNumber,
|
|
172
|
-
columnNumber: sourceCode.columnNumber,
|
|
173
|
-
},
|
|
174
|
-
traceHighlightLines: [excerpt.highlightLine],
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
const lastResolved = getLastResolvedOutput(traceChain)
|
|
179
|
-
if (lastResolved) {
|
|
180
|
-
const display = toDisplayLocation(lastResolved)
|
|
181
|
-
return {
|
|
182
|
-
traceData: traceChain,
|
|
183
|
-
traceCode: [
|
|
184
|
-
`已定位到源码位置:${display.fileName}:${display.lineNumber}:${display.columnNumber}`,
|
|
185
|
-
"当前 map 不包含 sourcesContent,无法直接渲染源码内容。",
|
|
186
|
-
].join("\n"),
|
|
187
|
-
resolvedSourceMeta: {
|
|
188
|
-
sourceFile: display.fileName,
|
|
189
|
-
lineNumber: display.lineNumber,
|
|
190
|
-
columnNumber: display.columnNumber,
|
|
191
|
-
},
|
|
192
|
-
traceHighlightLines: [],
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return {
|
|
197
|
-
traceData: traceChain,
|
|
198
|
-
traceCode: "未命中映射,未定位到源码位置。",
|
|
199
|
-
resolvedSourceMeta: null,
|
|
200
|
-
traceHighlightLines: [],
|
|
201
|
-
}
|
|
202
|
-
} catch (error) {
|
|
203
|
-
const message = error instanceof Error ? error.message : "unknown error"
|
|
204
|
-
return {
|
|
205
|
-
traceData: [{input: context.entry}],
|
|
206
|
-
traceCode: `source-map trace failed: ${message}`,
|
|
207
|
-
resolvedSourceMeta: null,
|
|
208
|
-
traceHighlightLines: [],
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export {SourceMapUtils} from "./facade/source-map-utils"
|
|
2
|
-
|
|
3
|
-
export type {
|
|
4
|
-
TraceOutputState,
|
|
5
|
-
SourceMapChainState,
|
|
6
|
-
TraceDisplayHop,
|
|
7
|
-
ResolveInputConfig,
|
|
8
|
-
} from "./facade/source-map-utils"
|
|
9
|
-
|
|
10
|
-
export type {
|
|
11
|
-
ChainMapSlot,
|
|
12
|
-
SourceMapRegistry,
|
|
13
|
-
TraceLocation,
|
|
14
|
-
TraceHop,
|
|
15
|
-
ResolvedSourceMeta,
|
|
16
|
-
ResolveTraceOptions,
|
|
17
|
-
SourceMapRecord,
|
|
18
|
-
} from "./base/types"
|
|
File without changes
|
|
File without changes
|