-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Loose mode for import * as #144
Comments
@Rich-Harris has considered avoiding getters, at least for However, it would be possible to optimise export const foo = {}; when imported as var a = { foo: foo };
Object.defineProperty(a, 'foo', {
enumerable: true,
value: foo
}); since we know that |
Could you expand on that? I understand it would no longer follow the spec, thats why I am suggesting an option along the lines of babel's loose mode (and its strict mode = false) which make the code shorter/faster but don't follow the spec perfectly. It would be more work for rollup, but I would imagine the code that generates this is in one or two specific places. I'd be interested in any downsides to that for the consumer or anything you think might break. |
With the loose more you're suggesting, Rollup could generate a bundle like the one below. The semantics state that the access of the //--- foo.js
export function nextFoo () { foo++; }
export var foo = 1;
//--- main.js
import * as a from './foo.js';
import { foo, nextFoo } from './foo.js';
nextFoo();
assert.equal( a.foo, foo );
//--- proposed.js
function nextFoo () { foo++; }
var foo = 1;
var a = { foo: foo };
nextFoo();
assert.equal( a.foo, foo ); Current Rollup will generate the below bundle, and completely optimise the namespace away. //--- current.js
function nextFoo () { foo++; }
var foo = 1;
nextFoo();
assert.equal( foo, foo ); |
Is that because you optimize in stages and a later stage wouldn't be able to tell that Ideally from your example, rollup would generate the same thing as now, but I wouldn't end up with hundreds of
in my output from every
or
(proposal from es2016) as
|
I see. So, what you really want is to be able to use the ES2016 export extensions? We're tracking it in #82. Rollup could easily handle your example, and I'd be more than happy to add support for it, but unfortunately Acorn doesn't have a plugin (I know of) that can parse the export extensions. If one existed, it'd be another issue entirely. 😄 |
Good thinking. In fact, we could determine whether an export is in fact possible to change, rather than relying on It would be good to have a loose mode anyway, for people who still have to support IE8 as well as for people who really don't want to mess around with accessors even if the exports could change. In Esperanto the option was called |
no, I was just adding the 2016 export extension example to make my usecase clearer.. sorry this probably confused things. I show 2 equivalent pieces of code for es2015 and es2016 and then what I have to write in es2015 to get rollup to output what I would like it to..
+1 and I don't mind a name like that, though I'd rather it was es3 specific since I want it to get nicer output |
As of 0.18, namespace blocks will only use getters for exports that could be reassigned or updated. Unfortunately less.js still doesn't build correctly (for unrelated reasons – investigating) but hopefully that does a good enough job of resolving this issue |
Perfect, have tried it out and this looks good to me.
It builds and tests okay to me. It may be just because I haven't finished switching everything to rollup, so You may be interested in filesize specs (not so important for less but I was interested regardless):
|
Yep, I fixed the other issue (9a8f331). Thanks for sharing the filesizes – good to know it ends up smaller with Rolllup |
Hi,
When using
import * as
we get the following outputwhich is "correct", however a shorter form would be
Would you consider a option that didn't bother with writing getters.. since I very much doubt any code will depend on not being able to set things on that object?
The text was updated successfully, but these errors were encountered: