Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source map is changed when re-running babel with no transforms. #10518

Open
coreyfarrell opened this issue Oct 2, 2019 · 1 comment

Comments

@coreyfarrell
Copy link
Contributor

commented Oct 2, 2019

Bug Report

Current Behavior
Running no transform on babel output changes the source-map.

Input Code

'use strict';

const {transformSync} = require('@babel/core');

const source = `console.log('minimum test');`;
const baseConfig = {
  babelrc: false,
  configFile: false,
  filename: 'test.js',
  sourceMaps: true
};

const result1 = transformSync(source, baseConfig);
const result2 = transformSync(result1.code, Object.assign({inputSourceMap: result1.map}, baseConfig));

console.log(source === result1.code && source === result2.code ? 'Code is identical' : 'Code is changed');
console.log('\nresult1.map:', result1.map);
console.log('\nresult2.map:', result2.map);

Expected behavior/code
result1.map should deeply equal result2.map.

Environment

  • Babel version(s): 7.6.2
  • Node/npm version: node 12.11.0, npm 6.11.3
  • OS: Fedora 30
  • Monorepo: no
  • How you are using Babel: API

Additional context/Screenshots

result1.map:

{
  version: 3,
  sources: [ 'test.js' ],
  names: [ 'console', 'log' ],
  mappings: 'AAAAA,OAAO,CAACC,GAAR,CAAY,cAAZ',
  sourcesContent: [ "console.log('minimum test');" ]
}

result2.map:

{
  version: 3,
  sources: [ 'test.js' ],
  names: [ 'console' ],
  mappings: 'AAAAA,OAAO,CAAPA,GAAAA,CAAAA,cAAAA',
  sourcesContent: [ "console.log('minimum test');" ]
}

This does seem to result in a loss of resolution in the source-map. See visualization of result1 compared to result2 - hovering over parts of the generated/original source will highlight what is associated from the other source.

@babel-bot

This comment has been minimized.

Copy link
Collaborator

commented Oct 2, 2019

Hey @coreyfarrell! We really appreciate you taking the time to report an issue. The collaborators on this project attempt to help as many people as possible, but we're a limited number of volunteers, so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack community that typically always has someone willing to help. You can sign-up here for an invite."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.