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

Fix accessing nested properties of namespaces #3643

Merged
merged 2 commits into from Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;