1
- import "source-map-support/register" ;
2
1
import fs from "fs/promises" ;
3
2
import path from "path" ;
4
3
import util from "util" ;
@@ -14,6 +13,7 @@ import {
14
13
import { generateMessages } from "@cucumber/gherkin" ;
15
14
import { IdGenerator , SourceMediaType } from "@cucumber/messages" ;
16
15
import * as esbuild from "esbuild" ;
16
+ import sourceMap from "source-map" ;
17
17
import { assert , assertAndReturn } from "../assertions" ;
18
18
import { createAstIdMap } from "../ast-helpers" ;
19
19
import { ensureIsRelative } from "../helpers/paths" ;
@@ -138,7 +138,7 @@ export async function diagnose(configuration: {
138
138
const esbuildResult = await esbuild . build ( {
139
139
entryPoints : [ inputFileName ] ,
140
140
bundle : true ,
141
- sourcemap : true ,
141
+ sourcemap : "external" ,
142
142
outfile : outputFileName ,
143
143
} ) ;
144
144
@@ -175,6 +175,33 @@ export async function diagnose(configuration: {
175
175
await fs . rm ( outputFileName ) . catch ( ( ) => true ) ;
176
176
}
177
177
178
+ const consumer = await new sourceMap . SourceMapConsumer (
179
+ ( await fs . readFile ( outputFileName + ".map" ) ) . toString ( )
180
+ ) ;
181
+
182
+ for ( const stepDefinition of registry . stepDefinitions ) {
183
+ const originalPosition = position ( stepDefinition ) ;
184
+
185
+ const newPosition = consumer . originalPositionFor ( originalPosition ) ;
186
+
187
+ stepDefinition . position = {
188
+ line : assertAndReturn (
189
+ newPosition . line ,
190
+ "Expected to find a line number"
191
+ ) ,
192
+ column : assertAndReturn (
193
+ newPosition . column ,
194
+ "Expected to find a column number"
195
+ ) ,
196
+ source : assertAndReturn (
197
+ newPosition . source ,
198
+ "Expected to find a source"
199
+ ) ,
200
+ } ;
201
+ }
202
+
203
+ consumer . destroy ( ) ;
204
+
178
205
const options = {
179
206
includeSource : false ,
180
207
includeGherkinDocument : true ,
0 commit comments