Skip to content

System format tests - #2022

Merged
lukastaegert merged 2 commits into
masterfrom
system-form
Mar 5, 2018
Merged

System format tests#2022
lukastaegert merged 2 commits into
masterfrom
system-form

Conversation

@guybedford

Copy link
Copy Markdown
Contributor

This fleshes out the System module format tests for the whole "form" folder, and caught a few bugs in the process which have been corrected here too, specifically:

  • Reexporting namespaces wasn't supported properly
  • default exports were being incorrectly output in certain scenarios
  • class declaration export bindings were missing in some cases

@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.

Nice to finally have this! Just some minor nits about the magic-string usage, otherwise this is ok from my side.

Comment thread src/Chunk.ts
const used = blank();
const es = options.format === 'es';
const system = options.format === 'system';
const es = options.format === 'es' || options.format === 'system';

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.

👍

Comment thread src/ast/nodes/ClassDeclaration.ts Outdated
if (options.systemBindings && this.id.variable.exportName) {
code.appendRight(this.end, ` exports('${this.id.variable.exportName}', ${this.id.variable.getName()});`);
if (options.systemBindings && this.id && this.id.variable.exportName) {
code.overwrite(this.end - 1, this.end, `} exports('${this.id.variable.exportName}', ${this.id.variable.getName()});`);

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 understand this fix and it works because class declarations always end with a "}" but conceptually, I would stay with the original approach and use appendLeft instead of appendRight. appendRight code is removed if the code following the insertion is removed while appendLeft is removed if the preceding code is removed. Since this code only ever makes sense if the last character of the preceding class declaration is retained, appendLeft (or maybe prependLeft, not sure if there is ever a situation where this would make a difference here) seems to me to be the better and maybe even safer choice.

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.

Nice, that works much better!

if (options.systemBindings && isClassDeclaration(this.declaration)) {
code.appendRight(this.end, ` exports('default', ${name});`);
if (options.systemBindings && isClassDeclaration(this.declaration) && this.variable.exportName) {
code.appendRight(this.end, ` exports('${this.variable.exportName}', ${name});`);

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.

As in ClassDeclaration, I guess this should be appendLeft.

@lukastaegert lukastaegert added this to the 0.56.4 milestone Mar 2, 2018
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.

2 participants