Skip to content

Fix namespace tracing - #2408

Merged
guybedford merged 4 commits into
masterfrom
namespace-trace-fix
Aug 24, 2018
Merged

Fix namespace tracing#2408
guybedford merged 4 commits into
masterfrom
namespace-trace-fix

Conversation

@guybedford

Copy link
Copy Markdown
Contributor

This PR contains:

  • bugfix
  • feature
  • refactor
  • tests
  • documentation
  • metadata

Breaking Changes?

  • yes
  • no

Please Describe Your Changes

This resolves #2391 by ensuring that namespace exports are in turn traced in chunking to ensure they are properly resolved.

@guybedford
guybedford force-pushed the namespace-trace-fix branch from 7694c44 to 285ab76 Compare August 14, 2018 14:28

@lukastaegert lukastaegert left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very nice getting to the bottom of this! Just one comment regarding encapsulation.

private references: Identifier[] = [];

constructor(context: AstContext) {
constructor(context: AstContext, module: Module) {

@lukastaegert lukastaegert Aug 15, 2018

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do not like adding the module as a parameter here as this breaks the encapsulation created by the AstContext. As the AstContext already has a traceExport function, maybe this can be avoided by adding a new method to the NamespaceVariable that does a trace inside this variable's module using its AstContext's traceExport function? This should cover the only usage of .module in Chunk while keeping encapsulation of the AST from the module.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I disagree about the encapsulation point, as I think it should be possible to trace up the parent hierarchy for any object. Plain data structures will always be a better abstraction than function closures. Yes we're exposing a class, but we're really after the "data representing the module semantically".

The additional point here is that there are two traceExport functions - one for Module which does direct tracing, and one for Chunk which does chunk to chunk tracing. I did initially spend many hours trying to make these share the same routine but in the end it was much easier this way around.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see. Yes, switching to plain data structures would definitely be a great improvement as it would also allow nice serializations etc. As you have guessed, my issue is with having the "rich" data structure of the module attached to the namespace variable while we go to great lengths to encapsulate the Module methods from the AST in the context.
Then at least we should add a comment to the module field that it is only meant to be used for tracing exports in the Chunk to avoid people in the future actually accessing properties on it to make other things "work" instead of thinking about the architecture.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just added a clarifying comment

@guybedford
guybedford merged commit 75de26d into master Aug 24, 2018
@guybedford
guybedford deleted the namespace-trace-fix branch August 24, 2018 19:51
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.

Malformed exports in chunks when code splitting

2 participants