From 3a8b1c146069c2c489f3dd8efa883ef128505a9f Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Fri, 13 Jan 2017 19:49:32 -0500 Subject: [PATCH] dont treat this.foo as possible namespace - fixes #1258 --- src/ast/nodes/MemberExpression.js | 2 +- test/function/this-not-namespace/_config.js | 8 ++++++++ test/function/this-not-namespace/main.js | 5 +++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 test/function/this-not-namespace/_config.js create mode 100644 test/function/this-not-namespace/main.js diff --git a/src/ast/nodes/MemberExpression.js b/src/ast/nodes/MemberExpression.js index 9b2313d..5f499ac 100644 --- a/src/ast/nodes/MemberExpression.js +++ b/src/ast/nodes/MemberExpression.js @@ -33,7 +33,7 @@ export default class MemberExpression extends Node { // TODO this code is a bit inefficient const keypath = new Keypath( this ); - if ( !keypath.computed ) { + if ( !keypath.computed && keypath.root.type === 'Identifier' ) { let declaration = scope.findDeclaration( keypath.root.name ); while ( declaration.isNamespace && keypath.parts.length ) { diff --git a/test/function/this-not-namespace/_config.js b/test/function/this-not-namespace/_config.js new file mode 100644 index 0000000..ee9b9f7 --- /dev/null +++ b/test/function/this-not-namespace/_config.js @@ -0,0 +1,8 @@ +const assert = require( 'assert' ); + +module.exports = { + description: 'does not treat this.foo as a possible namespace (#1258)', + exports: exports => { + assert.equal( typeof exports.Foo, 'function' ); + } +}; diff --git a/test/function/this-not-namespace/main.js b/test/function/this-not-namespace/main.js new file mode 100644 index 0000000..f2fdc1f --- /dev/null +++ b/test/function/this-not-namespace/main.js @@ -0,0 +1,5 @@ +export class Foo { + constructor ( name ) { + this.name = undefined; + } +}