diff --git a/src/Declaration.js b/src/Declaration.js index 7755cdd..0c8fd1e 100644 --- a/src/Declaration.js +++ b/src/Declaration.js @@ -195,8 +195,9 @@ export class SyntheticNamespaceDeclaration { // if we have e.g. `foo.bar`, we can optimise // the reference by pointing directly to `bar` if ( reference.parts.length ) { - reference.name = reference.parts.shift(); - reference.end = reference.node.end; + const ref = reference.parts.shift(); + reference.name = ref.name; + reference.end = ref.end; const original = this.originals[ reference.name ]; diff --git a/src/Reference.js b/src/Reference.js index e86ad9b..5c5c3e9 100644 --- a/src/Reference.js +++ b/src/Reference.js @@ -10,7 +10,7 @@ export class Reference { let root = node; while ( root.type === 'MemberExpression' ) { - this.parts.unshift( root.property.name ); + this.parts.unshift( root.property ); root = root.object; } diff --git a/test/form/erroneous-nested-member-expression/_config.js b/test/form/erroneous-nested-member-expression/_config.js new file mode 100644 index 0000000..684fe7c --- /dev/null +++ b/test/form/erroneous-nested-member-expression/_config.js @@ -0,0 +1,3 @@ +module.exports = { + description: 'erroneous nested member expression does not mess up naming' +}; diff --git a/test/form/erroneous-nested-member-expression/_expected/amd.js b/test/form/erroneous-nested-member-expression/_expected/amd.js new file mode 100644 index 0000000..6499b90 --- /dev/null +++ b/test/form/erroneous-nested-member-expression/_expected/amd.js @@ -0,0 +1,13 @@ +define(function () { 'use strict'; + + function yar() { + return { + har() { + console.log('har?'); + } + }; + }; + + yar.har(); + +}); \ No newline at end of file diff --git a/test/form/erroneous-nested-member-expression/_expected/cjs.js b/test/form/erroneous-nested-member-expression/_expected/cjs.js new file mode 100644 index 0000000..aa4b949 --- /dev/null +++ b/test/form/erroneous-nested-member-expression/_expected/cjs.js @@ -0,0 +1,11 @@ +'use strict'; + +function yar() { + return { + har() { + console.log('har?'); + } + }; +}; + +yar.har(); \ No newline at end of file diff --git a/test/form/erroneous-nested-member-expression/_expected/es6.js b/test/form/erroneous-nested-member-expression/_expected/es6.js new file mode 100644 index 0000000..34c4e2e --- /dev/null +++ b/test/form/erroneous-nested-member-expression/_expected/es6.js @@ -0,0 +1,9 @@ +function yar() { + return { + har() { + console.log('har?'); + } + }; +}; + +yar.har(); \ No newline at end of file diff --git a/test/form/erroneous-nested-member-expression/_expected/iife.js b/test/form/erroneous-nested-member-expression/_expected/iife.js new file mode 100644 index 0000000..4233cfe --- /dev/null +++ b/test/form/erroneous-nested-member-expression/_expected/iife.js @@ -0,0 +1,14 @@ +(function () { + 'use strict'; + + function yar() { + return { + har() { + console.log('har?'); + } + }; + }; + + yar.har(); + +}()); \ No newline at end of file diff --git a/test/form/erroneous-nested-member-expression/_expected/umd.js b/test/form/erroneous-nested-member-expression/_expected/umd.js new file mode 100644 index 0000000..d11bd9f --- /dev/null +++ b/test/form/erroneous-nested-member-expression/_expected/umd.js @@ -0,0 +1,17 @@ +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory() : + typeof define === 'function' && define.amd ? define(factory) : + (factory()); +}(this, function () { 'use strict'; + + function yar() { + return { + har() { + console.log('har?'); + } + }; + }; + + yar.har(); + +})); \ No newline at end of file diff --git a/test/form/erroneous-nested-member-expression/foo.js b/test/form/erroneous-nested-member-expression/foo.js new file mode 100644 index 0000000..44f5e23 --- /dev/null +++ b/test/form/erroneous-nested-member-expression/foo.js @@ -0,0 +1,7 @@ +export function yar() { + return { + har() { + console.log('har?'); + } + }; +}; diff --git a/test/form/erroneous-nested-member-expression/main.js b/test/form/erroneous-nested-member-expression/main.js new file mode 100644 index 0000000..37c4b16 --- /dev/null +++ b/test/form/erroneous-nested-member-expression/main.js @@ -0,0 +1,2 @@ +import * as foo from './foo.js'; +foo.yar.har();