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

Fix #74 and refactor name tracing mechanism #78

Merged
merged 31 commits into from
Aug 16, 2015
Merged

Fix #74 and refactor name tracing mechanism #78

merged 31 commits into from
Aug 16, 2015

Conversation

Rich-Harris
Copy link
Contributor

superceded by #79

This started out as a straightforward attempt at fixing #74 and turned into a far more comprehensive chunk of work.

@Victorystick as I hadn't quite got my head round #71, I started from the existing codebase, but there's now a fair bit of overlap between this and #71, insofar as renaming things is now a bundle-level concern – handled by bundle.trace() rather than module.getCanonicalName(), which was a source of pain and no longer exists. Would be keen to get your thoughts. This is a bit simpler than #71 (only adds ~5 LOC excluding tests, net, and doesn't introduce any new classes), but I want to make sure that I'm not missing a load of necessary stuff from #71 or otherwise stomping on your work!

There's probably a bit of dust that still needs clearing up, as after any largish refactor

this.assumedGlobals[ name ] = true;
// TODO is this necessary in the ES6 case?
let name = makeLegalIdentifier( module.suggestedNames['*'] || module.suggestedNames.default || module.id );
module.name = getSafeName( name );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't necessary in the ES6 case, but if we always do it, taking the needs of all module formats into account, we only have to deconflict once. Might as well do it in Bundle.build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 that makes sense

@Victorystick
Copy link
Contributor

I'll try to integrate some key points from BundleScopes (which in truth got more complicated than I'd hoped) into the current master. There are some issues I think could be solved by doing so.

@@ -453,4 +464,55 @@ export default class Bundle {

return ordered;
}

trace ( module, localName, es6 ) {
const importDeclaration = module.imports[ localName ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has bothered me a bit. module.imports is used for both imports and re-exports. The linking (dare I say, binding?) I'm proposing in #71, avoids this issue. Consider:

export { foo as bar } from './foo1';
import foo from './foo2';

export function baz () {
  return foo(4, []);
}; 

Two identifiers foo are imported. Which one is in module.imports? Can't this cause a lot of issues down the road?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm... that's true, re-exports aren't supposed to create a binding in the local scope. I think it could be solved fairly easily by having a module.reexports alongside module.imports and module.exports, and using that in bundle.trace() and module.mark(), but that's just speculation at this point

@eventualbuddha eventualbuddha deleted the gh-74 branch August 20, 2015 02:50
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