Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Source maps mapping looks wrong when using Webpack

オープン
#498 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
javascript, typescript, webpack
領域
devtools

調査の方向性

外部の test-source-maps プロジェクトから始め、issue に示されている generatedPositionFor() と originalPositionFor() の呼び出しと併せて dist/bundle.js.map を調査します。返されたマッピングを source-map API の想定および Webpack の設定と比較します。ラウンドトリップが有効かどうかを判断するか、再現可能なマッピング/設定の不具合を特定できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Hello,
I've been experimenting with this repository. I tried to generate a simple project to use source maps using Webpack: https://github.com/eloparco/test-source-maps, where I produce a js bundle starting from Typescript and I want to use source maps for the mapping between the two.

I tried to play around with the generated source maps:

const SourceMapConsumer = require("source-map").SourceMapConsumer;
const fs = require("fs");

const SOURCEMAP_ABSOUTE_PATH = "/path/to/test-source-maps/dist/bundle.js.map";
const ORIGINAL_ABSOLUTE_PATH = "/path/to/test-source-maps/src/index.ts";
const GENERATED_ABSOLUTE_PATH = "/path/to/test-source-maps/dist/bundle.js";
const ORIGINAL_LINE = 11;

let json = JSON.parse(fs.readFileSync(SOURCEMAP_ABSOUTE_PATH).toString());

SourceMapConsumer.with(json, null, (consumer) => {
  console.log(consumer.sources);

  const generated = consumer.generatedPositionFor({
    source: ORIGINAL_ABSOLUTE_PATH,
    line: ORIGINAL_LINE,
    column: 0,
  });
  console.log(generated);

  const original = consumer.originalPositionFor({
    line: generated.line,
    column: generated.column,
  });
  console.log(original);

  assert(original.line === ORIGINAL_LINE); // <------------ This assertion fails!!!
});

Here I use generatedPositionFor() to get the mapping from the original .ts file to the corresponding .js file. Then, I try to do the opposite and feed the line and column previously retrieved to originalPositionFor(), expecting it to return the original line/column that I passed to generatedPositionFor(). But that doesn't happen.

Is my understanding of source maps wrong? Or am I doing something wrong in the Webpack configuration?
Thanks

主要言語
JavaScript
スター
3.7k
フォーク
370
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

mozilla/source-map のほかの issue

mozilla/source-map の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。