Skip to content
This repository was archived by the owner on Mar 29, 2018. It is now read-only.
This repository was archived by the owner on Mar 29, 2018. It is now read-only.

Import chains do not preserve bindings across multiple files in CommonJS #178

@eventualbuddha

Description

@eventualbuddha

See this example:

// a.js

export var count = 0;
export function incr() {
  count++;
}

// b.js

export { count, incr } from './a';

// c.js

import { count, incr } from './b';

console.log(count);
incr();
console.log(count);

Which currently outputs this:

// a.js

"use strict";
exports.incr = incr;
var count = 0;
function incr() {
  count++, exports.count = count;
}
exports.count = count;

// b.js

"use strict";
var a$$ = require("./a");
exports.count = a$$.count, exports.incr = a$$.incr;

// c.js

"use strict";
var b$$ = require("./b");

console.log(b$$.count);
b$$.incr();
console.log(b$$.count);

Since inside b.js exports.count is only ever set once, it never receives updates to count when incr is called, which means 0 0 will be output instead of 0 1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions