Skip to content

Commit f0ec1b7

Browse files
committed
Avoid using source-map-support/register
This was highly unperformant.
1 parent 06b3f6e commit f0ec1b7

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-4
lines changed

lib/assertions.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function fail(message: string) {
99
}
1010

1111
export function assert(value: unknown, message: string): asserts value {
12-
if (value) {
12+
if (value != null) {
1313
return;
1414
}
1515

lib/diagnostics/diagnose.ts

+29-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import "source-map-support/register";
21
import fs from "fs/promises";
32
import path from "path";
43
import util from "util";
@@ -14,6 +13,7 @@ import {
1413
import { generateMessages } from "@cucumber/gherkin";
1514
import { IdGenerator, SourceMediaType } from "@cucumber/messages";
1615
import * as esbuild from "esbuild";
16+
import sourceMap from "source-map";
1717
import { assert, assertAndReturn } from "../assertions";
1818
import { createAstIdMap } from "../ast-helpers";
1919
import { ensureIsRelative } from "../helpers/paths";
@@ -138,7 +138,7 @@ export async function diagnose(configuration: {
138138
const esbuildResult = await esbuild.build({
139139
entryPoints: [inputFileName],
140140
bundle: true,
141-
sourcemap: true,
141+
sourcemap: "external",
142142
outfile: outputFileName,
143143
});
144144

@@ -175,6 +175,33 @@ export async function diagnose(configuration: {
175175
await fs.rm(outputFileName).catch(() => true);
176176
}
177177

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+
178205
const options = {
179206
includeSource: false,
180207
includeGherkinDocument: true,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"module-alias": "^2.2.2",
6767
"node-hook": "^1.0.0",
6868
"resolve-pkg": "^2.0.0",
69-
"source-map-support": "^0.5.21",
69+
"source-map": "^0.7.4",
7070
"uuid": "^8.3.2"
7171
},
7272
"devDependencies": {

0 commit comments

Comments
 (0)