microsoft / microsoft/TypeScript
Improve call expression source maps
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
🔎 Search Terms
- source map call expression
- emitCallExpression source map
- source map function call
🕗 Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about "Source Maps"
⏯ Playground Link
💻 Code
import mockExternal from "./mock.js";
function mock<T>(arg?: T){}
const a = mock();
const b = mock ( );
const c = mock<string> ("aaaa");
const d = mock /* meow */ ( "arg1" );
// Note: force tsc to generate an indirect call
const e = mockExternal ( "" );
Compiled:
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const mock_js_1 = __importDefault(require("./mock.js"));
function mock(arg) { }
const a = mock();
const b = mock();
const c = mock("aaaa");
const d = mock /* meow */("arg1");
// Note: force tsc to generate an indirect call
const e = (0, mock_js_1.default)("");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5wdXQuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbnB1dC50c3giXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSx3REFBcUM7QUFFckMsU0FBUyxJQUFJLENBQUksR0FBTyxJQUFFLENBQUM7QUFFM0IsTUFBTSxDQUFDLEdBQUcsSUFBSSxFQUFFLENBQUM7QUFDakIsTUFBTSxDQUFDLEdBQUcsSUFBSSxFQUFLLENBQUM7QUFDcEIsTUFBTSxDQUFDLEdBQUcsSUFBSSxDQUFXLE1BQU0sQ0FBQyxDQUFDO0FBQ2pDLE1BQU0sQ0FBQyxHQUFHLElBQUksQ0FBQyxVQUFVLENBQUssTUFBTSxDQUFJLENBQUM7QUFFekMsK0NBQStDO0FBQy9DLE1BQU0sQ0FBQyxHQUFHLElBQUEsaUJBQVksRUFBTyxFQUFFLENBQUcsQ0FBQyJ9
🙁 Actual behavior
The JS is compiled perfectly and works fine, however due to the way NodeJS reports call sites the call site of each mock function invocation is as follows:
| position in JS (line, col) | substring in JS at position | position after source mapping | substring in TS at position |
|---|---|---|---|
| (8, 11) | mock |
(5, 11) | mock |
| (9, 11) | mock |
(6, 11) | mock |
| (10, 11) | mock |
(7, 11) | mock |
| (11, 11) | mock |
(8, 11) | mock |
| (13, 31) | (""); |
(11, 29) | "" ); |
When looking at a call expressions reported call site I personally think that indirect call expressions positions are misleading after being source mapped as it seems to imply the first argument is the section of the code affected when there are spaces between the first argument and the open parenthesis token.
🙂 Expected behavior
I would expect the (13,31) call site to map directly to (12, 27) in the source map, so that users can easily see the invocation position of the function call, in a consistent and predictable way.
Additional information about the issue
I debated on whether this would be considered a bug or a feature request, but decided on bug due to the current call site position being inconsistent for users trying to map their codes call location. If you think this should be a feature request, I am more than happy to change this issue to be a feature request.
If this feature is deemed to be an acceptable change to typescripts source map emissions, I have created a simple implementation that in my own testing seems to work, I am happy to add automated tests and raise a PR (https://github.com/mini-ninja-64/TypeScript/tree/improve-source-map). My current implementation works by emitting a source map position in the emitNodeList function based on the start position of the provided NodeArray<T>, this means it could also improve the source map production for other node lists; however this could increase the size of source maps generated by tsc.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit der im Issue erwähnten Funktion emitNodeList und reproduziere die Zuordnung für indirekte Aufrufe anhand des verlinkten TypeScript Playground-Beispiels. Vergleiche die Position im erzeugten Source-Map mit der erwarteten Aufrufposition und füge anschließend eine automatisierte Abdeckung hinzu, die zeigt, dass Ausdrücke mit Leerzeichen und indirekte Aufrufausdrücke konsistent zugeordnet werden.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 45/100