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

Make sure default exports snapshot synthetic named exports #3946

Merged
merged 1 commit into from Feb 1, 2021

Conversation

lukastaegert
Copy link
Member

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:
rollup/plugins#658

Description

This is an inconsistency that turned up when looking into rollup/plugins#658 (comment). Basically the following situation:

// main.js
import foo from './dep';
import { update } from './synthetic';

assert.strictEqual(foo, 'original');
update();
// This would fail
assert.strictEqual(foo, 'original');

// dep.js
import { foo } from './synthetic';
// This default export should produce a snapshot of the current value of foo
export default foo;

// synthetic.js
// This should be the synthetic namespace
export const __synthetic = { foo: 'original' };
export const update = () => (__synthetic.foo = 'reassigned');

So in short we have a synthetic named export foo that is "reexported" via an export default declaration which is evaluated before and after the synthetic namespace is updated. This should not change the result as the default export declaration should snapshot. Previously, though, the following output was generated:

const __synthetic = { foo: 'original' };
const update = () => (__synthetic.foo = 'reassigned');
    
assert.strictEqual(__synthetic.foo, 'original');
update();
assert.strictEqual(__synthetic.foo, 'original');

which did in fact live-bind where it should not. This is fixed now:

const __synthetic = { foo: 'original' };
const update = () => (__synthetic.foo = 'reassigned');

// This is the new snapshot
var foo = __synthetic.foo;
    
assert.strictEqual(foo, 'original');
update();
assert.strictEqual(foo, 'original');

@lukastaegert lukastaegert force-pushed the default-export-synthetic-named-export branch 2 times, most recently from 84cf854 to 8aab31b Compare February 1, 2021 05:20
@rollup-bot
Copy link
Collaborator

rollup-bot commented Feb 1, 2021

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#default-export-synthetic-named-export

or load it into the REPL:
https://rollupjs.org/repl/?circleci=14160

@codecov
Copy link

codecov bot commented Feb 1, 2021

Codecov Report

Merging #3946 (bce9d86) into master (683cc6a) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3946      +/-   ##
==========================================
- Coverage   97.18%   97.18%   -0.01%     
==========================================
  Files         188      188              
  Lines        6685     6681       -4     
  Branches     1947     1946       -1     
==========================================
- Hits         6497     6493       -4     
  Misses         99       99              
  Partials       89       89              
Impacted Files Coverage Δ
src/ast/variables/ExportDefaultVariable.ts 100.00% <ø> (ø)
src/ast/variables/SyntheticNamedExportVariable.ts 96.15% <ø> (-0.52%) ⬇️
src/Module.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 683cc6a...bce9d86. Read the comment docs.

@lukastaegert lukastaegert force-pushed the default-export-synthetic-named-export branch from 8aab31b to bce9d86 Compare February 1, 2021 06:03
@lukastaegert lukastaegert merged commit bab3d3d into master Feb 1, 2021
@lukastaegert lukastaegert deleted the default-export-synthetic-named-export branch February 1, 2021 06:11
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