Browse Source

external module deshadowing

contingency-plan
Rich Harris 10 years ago
parent
commit
259e00cf40
  1. 15
      src/Statement.js
  2. 2
      src/finalisers/iife.js
  3. 3
      test/function/shadowed-external-export/_config.js

15
src/Statement.js

@ -239,6 +239,12 @@ export default class Statement {
const replacementStack = [ names ]; const replacementStack = [ names ];
const nameList = keys( names ); const nameList = keys( names );
let deshadowList = [];
nameList.forEach( name => {
const replacement = names[ name ];
deshadowList.push( replacement.split( '.' )[0] );
});
if ( nameList.length > 0 ) { if ( nameList.length > 0 ) {
walk( this.node, { walk( this.node, {
enter ( node, parent ) { enter ( node, parent ) {
@ -248,13 +254,20 @@ export default class Statement {
let newNames = {}; let newNames = {};
let hasReplacements; let hasReplacements;
nameList.forEach( key => { keys( names ).forEach( key => {
if ( !~scope.names.indexOf( key ) ) { if ( !~scope.names.indexOf( key ) ) {
newNames[ key ] = names[ key ]; newNames[ key ] = names[ key ];
hasReplacements = true; hasReplacements = true;
} }
}); });
deshadowList.forEach( name => {
if ( ~scope.names.indexOf( name ) ) {
newNames[ name ] = name + '$$'; // TODO better mechanism
hasReplacements = true;
}
});
if ( !hasReplacements ) { if ( !hasReplacements ) {
return this.skip(); return this.skip();
} }

2
src/finalisers/iife.js

@ -1,4 +1,4 @@
export default function es6 ( bundle, magicString, exportMode, options ) { export default function iife ( bundle, magicString, exportMode, options ) {
const intro = `(function () { 'use strict';\n\n`; const intro = `(function () { 'use strict';\n\n`;
const outro = `\n\n})();`; const outro = `\n\n})();`;

3
test/function/shadowed-external-export/_config.js

@ -1,4 +1,3 @@
module.exports = { module.exports = {
description: 'external modules are not shadowed', description: 'external modules are not shadowed'
skip: true
}; };

Loading…
Cancel
Save