Browse Source

Merge branch 'deshadow-bug' into rewrite-master

better-aggressive
Rich Harris 9 years ago
parent
commit
8e8895c3ab
  1. 4
      src/Module.js
  2. 1
      src/Statement.js
  3. 3
      test/function/deshadow-top-level-declaration/_config.js
  4. 1
      test/function/deshadow-top-level-declaration/a.js
  5. 5
      test/function/deshadow-top-level-declaration/b.js
  6. 3
      test/function/deshadow-top-level-declaration/foo.js
  7. 5
      test/function/deshadow-top-level-declaration/main.js
  8. 5
      test/function/deshadow-top-level-declaration/x.js

4
src/Module.js

@ -537,6 +537,8 @@ export default class Module {
// namespace optimisation – name of `foo.bar` could be `bar` // namespace optimisation – name of `foo.bar` could be `bar`
if ( reference.name === name && name.length === reference.end - reference.start ) return; if ( reference.name === name && name.length === reference.end - reference.start ) return;
reference.rewritten = true;
// prevent local variables from shadowing renamed references // prevent local variables from shadowing renamed references
const identifier = name.match( /[^\.]+/ )[0]; const identifier = name.match( /[^\.]+/ )[0];
if ( reference.scope.contains( identifier ) ) { if ( reference.scope.contains( identifier ) ) {
@ -553,7 +555,7 @@ export default class Module {
if ( keys( toDeshadow ).length ) { if ( keys( toDeshadow ).length ) {
statement.references.forEach( reference => { statement.references.forEach( reference => {
if ( reference.name in toDeshadow ) { if ( !reference.rewritten && reference.name in toDeshadow ) {
magicString.overwrite( reference.start, reference.end, toDeshadow[ reference.name ], true ); magicString.overwrite( reference.start, reference.end, toDeshadow[ reference.name ], true );
} }
}); });

1
src/Statement.js

@ -53,6 +53,7 @@ class Reference {
this.start = node.start; this.start = node.start;
this.end = node.start + this.name.length; // can be overridden in the case of namespace members this.end = node.start + this.name.length; // can be overridden in the case of namespace members
this.rewritten = false;
} }
} }

3
test/function/deshadow-top-level-declaration/_config.js

@ -0,0 +1,3 @@
module.exports = {
description: 'deshadows top-level declarations'
};

1
test/function/deshadow-top-level-declaration/a.js

@ -0,0 +1 @@
import './x';

5
test/function/deshadow-top-level-declaration/b.js

@ -0,0 +1,5 @@
import { foo as _foo } from './foo';
export default function foo () {
_foo();
}

3
test/function/deshadow-top-level-declaration/foo.js

@ -0,0 +1,3 @@
function foo () {}
export { foo };

5
test/function/deshadow-top-level-declaration/main.js

@ -0,0 +1,5 @@
import './foo';
import './a';
import b from './b';
assert.equal( typeof b, 'function' );

5
test/function/deshadow-top-level-declaration/x.js

@ -0,0 +1,5 @@
import { foo } from './foo';
function x () {
foo();
}
Loading…
Cancel
Save