Skip to content

[babel-generator] should normalize sourceFileName when generating source maps #10254

@JLHwung

Description

@JLHwung

Bug Report

Background
Babel generator pass sourceFileName as sources when generating source maps. However, the sources must be a valid URI, and source-map would not normalize the passing sourceFileName option. According to discussions on mozilla/source-map#91 (comment), we should normalize the sourcePathName to ensure it is a valid URI before passing.

Input Code
Run the following test on a Windows platform:

yarn jest babel-generator -t sourcemaps

Expected behavior/code
It should pass on Windows Machine.

Current Behavior

FAIL packages/babel-generator/test/index.js
  ● generation/sourcemaps › call identifiers

    expect(received).toEqual(expected) // deep equality

    - Expected
    + Received

    @@ -4,11 +4,11 @@
          "foo",
          "bar",
          "obj",
        ],
        "sources": Array [
    -     "fixtures/sourcemaps/call-identifiers/input.js",
    +     "fixtures\\sourcemaps\\call-identifiers\\input.js",
        ],
        "sourcesContent": Array [
          "foo;
      foo();
      foo().bar;

      504 | 
      505 |             if (options.sourceMaps) {
    > 506 |               expect(result.map).toEqual(task.sourceMap);
          |                                  ^
      507 |             }
      508 | 
      509 |             if (

      at Object.toEqual (packages/babel-generator/test/index.js:506:34)

Babel Configuration (.babelrc, package.json, cli command)

{
  "your": { "config": "here" }
}

Environment

  • Babel version(s): master
  • Node/npm version: Node 12
  • OS: Windows 7
  • How you are using Babel: Running unit test

Possible Solution
Apply necessary normalization on packages/babel-generator/src/source-map.js

Additional context/Screenshots
This issue is originally reported in #10209. I submit this issue to track the invalid source map generation on Windows.

Metadata

Metadata

Assignees

Labels

Has PRarea: sourcemapsoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions