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

Revert "simplify trim methods" #53

Closed
wants to merge 1 commit into from
Closed

Revert "simplify trim methods" #53

wants to merge 1 commit into from

Conversation

eventualbuddha
Copy link
Contributor

This reverts commit 7532328.

I discovered that this was causing problems after attempting to update rollup-plugin-commonjs to use the latest of all its dependencies, including magic-string. Updating from v0.10.0 to v0.11.1 produced the following error:

  1) rollup-plugin-commonjs generates a sourcemap:
     AssertionError: null == 'samples/sourcemap/main.js'
      at test.js:72:11
      at tryCatch (node_modules/rollup/dist/rollup.js:400:12)
      at invokeCallback (node_modules/rollup/dist/rollup.js:412:13)
      at publish (node_modules/rollup/dist/rollup.js:383:7)
      at flush (node_modules/rollup/dist/rollup.js:127:5)

I noticed that the source map differed between the different versions of magic-string:

# magic-string 0.10.0

'use strict';

function __commonjs(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; }

var require$$0 = 42;

var main = __commonjs(function (module) {
var foo = require$$0;
console.log( foo );
});

var main$1 = (main && typeof main === 'object' && 'default' in main ? main['default'] : main);

module.exports = main$1;
{ version: 3,
  file: 'bundle.js',
  sources: [ 'samples/sourcemap/foo.js', 'samples/sourcemap/main.js' ],
  sourcesContent: 
   [ 'export default 42;\n',
     'var foo = require( \'./foo\' );\nconsole.log( foo );\n' ],
  names: [],
  mappings: ';;;;iBAAe,EAAE,CAAC;;;ACAlB,IAAI,GAAG,GAAG,UAAkB,CAAC;AAC7B,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,CAAC;;;;;' }


# magic-string 0.11.1

'use strict';

function __commonjs(fn, module) { return module = { exports: {} }, fn(module, module.exports), module.exports; }

var require$$0 = 42;

var main = __commonjs(function (module) {
var foo = require$$0;
console.log( foo );
});

var main$1 = (main && typeof main === 'object' && 'default' in main ? main['default'] : main);

module.exports = main$1;
{ version: 3,
  file: 'bundle.js',
  sources: [ 'samples/sourcemap/foo.js', 'samples/sourcemap/main.js' ],
  sourcesContent: 
   [ 'export default 42;\n',
     'var foo = require( \'./foo\' );\nconsole.log( foo );\n' ],
  names: [],
  mappings: ';;;;iBAAe,EAAE,CAAC;;;ACAlB,IAAI,GAAG,GAAG,UAAkB;;;;;;' }

It appears the source map in v0.11.1 is a truncated version of the other one. I determined that this commit was the bad one by using git bisect and npm link to run the rollup-plugin-commonjs tests with each revision, using git bisect skip on a few commits in magic-string that failed to pass its own tests. After reverting the bad commit on top of the current master the tests for rollup-plugin-commonjs began to work again. I don't have enough context on magic-string to fix the underlying cause, but you probably do, @Rich-Harris. Let me know if you need more information!

@Rich-Harris
Copy link
Owner

Thanks for digging into this and figuring out what was happening with the sourcemaps. I've released an alternative fix (52f4740) as 0.11.3. I rewrote most of the library to support #14 (a new move() method), and didn't have sufficient tests for this – as of 0.11 the content is stored as a series of consecutive chunks rather than as the original string plus a few patches.

The context for this, incidentally, is that I spent the last few days working on a new ES2015 compiler, Bublé, which needs the ability to move chunks of code around within a file. There's also rollup-plugin-buble which I'll move over to the rollup organisation once everything's a bit more tested. This package is now built with it.

@eventualbuddha eventualbuddha deleted the fix-trim-regression branch December 18, 2016 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants