Skip to content

Commit

Permalink
Fix accessing nested properties of namespaces (#3643)
Browse files Browse the repository at this point in the history
* Fix accessing nested properties of namespaces

* Update changelog
  • Loading branch information
lukastaegert committed Jun 19, 2020
1 parent 3fabc1b commit 404a108
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 11 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,14 @@
# rollup changelog

## 2.17.1
*2020-06-19*

### Bug Fixes
* Properly resolve accessing properties of namespace members again (#3643)

### Pull Requests
* [#3643](https://github.com/rollup/rollup/pull/3643): Fix accessing nested properties of namespaces (@lukastaegert)

## 2.17.0
*2020-06-17*

Expand Down
18 changes: 9 additions & 9 deletions src/ast/nodes/MemberExpression.ts
Expand Up @@ -93,16 +93,16 @@ export default class MemberExpression extends NodeBase implements DeoptimizableE
const baseVariable = path && this.scope.findVariable(path[0].key);
if (baseVariable && baseVariable.isNamespace) {
const resolvedVariable = this.resolveNamespaceVariables(baseVariable, path!.slice(1));
if (resolvedVariable) {
if (typeof resolvedVariable === 'string') {
this.replacement = resolvedVariable;
} else {
if (resolvedVariable instanceof ExternalVariable && resolvedVariable.module) {
resolvedVariable.module.suggestName(path![0].key);
}
this.variable = resolvedVariable;
this.scope.addNamespaceMemberAccess(getStringFromPath(path!), resolvedVariable);
if (!resolvedVariable) {
super.bind();
} else if (typeof resolvedVariable === 'string') {
this.replacement = resolvedVariable;
} else {
if (resolvedVariable instanceof ExternalVariable && resolvedVariable.module) {
resolvedVariable.module.suggestName(path![0].key);
}
this.variable = resolvedVariable;
this.scope.addNamespaceMemberAccess(getStringFromPath(path!), resolvedVariable);
}
} else {
super.bind();
Expand Down
4 changes: 2 additions & 2 deletions test/cli/samples/watch/bundle-error/_config.js
Expand Up @@ -11,11 +11,11 @@ module.exports = {
fs.writeFileSync(mainFile, '<=>');
},
after() {
setTimeout(() => fs.unlinkSync(mainFile), 300);
setTimeout(() => fs.unlinkSync(mainFile), 100);
},
abortOnStderr(data) {
if (data.includes('Error: Unexpected token')) {
setTimeout(() => fs.writeFileSync(mainFile, 'export default 42;'), 300);
setTimeout(() => fs.writeFileSync(mainFile, 'export default 42;'), 500);
return false;
}
if (data.includes('created _actual')) {
Expand Down
@@ -0,0 +1,8 @@
const assert = require('assert');

module.exports = {
description: 'handles accessing members of namespaces correctly',
exports(exports) {
assert.strictEqual(exports, false);
}
};
@@ -0,0 +1 @@
export var global = {Object: {}};
@@ -0,0 +1,2 @@
import * as helpers from './helpers.js';
export default helpers.global.Object === Object;

0 comments on commit 404a108

Please sign in to comment.