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
RFC: Add a move
method, or tweak insert
#14
Comments
The fundamental operation I'm looking for is a way to turn this: function add( x, y ) {
return x + y;
}
function sub( x, y ) {
return x - y;
} into this: function sub( x, y ) {
return x - y;
}
function add( x, y ) {
return x + y;
} while preserving source maps. |
This seems doable, though it'd require a bit of a rethink about how mappings are stored. Hmm... I don't quite understand the use case – why would you need to move functions around? |
Ok, the example doesn't really make it clear. If you take a look at SystemJS, what I propose should make more sense. In SystemJS, declarations are hoisted to the top of the wrapper, while all other statements are kept at the "bottom", inside another function. For example: import { a } from 'foo';
export var x = a( data, 17 );
export function data(...) { ... } becomes something like: System.register(['foo'], function($__export) {
var a, x;
function data(...) { ... }
$__export('data', data);
return {
setters: [
// every time a dependency updates an export,
// this function is called to update the local binding
// the setter array matches up with the dependency array above
function(foo) {
a = foo.a;
}
],
execute: function() {
// use the export function to update the exports of this module
x = a( data, 17 );
$__export( 'x', x );
}
};
}); So you see, I don't want to change the order of function declarations by moving them around, no. Depending on what you consider being moved where, I want to move Statements down below all declarations. |
This is implemented in 0.11! Bit experimental – no sourcemap tests yet, for example – but it seems to work. Tests have examples of usage – basically goes like this: var s = new MagicString( 'abcdefghijkl' );
s.move( 0, 3, 6 ); // start, end, newIndex
assert.equal( s.toString(), 'defabcghijkl' ); |
Now that there exists a Rollup issue for SystemJS, we'll need to be able to hoist function declarations, while retaining SourceMaps.
I haven't been able to find any
move
method, and the method combination that could have replicated the behavior (snip
,remove
andinsert
) requiresinsert
to work on MagicStrings in addition to strings.I suggest extending MagicStrings API with either a
move
method, or aninsert
that supports MagicStrings.The text was updated successfully, but these errors were encountered: