Browse Source

more fixes

declarations-and-references
Rich-Harris 9 years ago
parent
commit
0334cc86fe
  1. 23
      src/Bundle.js
  2. 10
      src/Module.js

23
src/Bundle.js

@ -68,19 +68,32 @@ export default class Bundle {
this.markAllModifierStatements();
this.orderedModules = this.sort();
this.deconflict();
});
}
// TODO would be better to deconflict once, rather than per-render
deconflict () {
let nameCount = blank();
let used = blank();
// ensure no conflicts with globals
keys( this.assumedGlobals ).forEach( name => nameCount[ name ] = 0 );
keys( this.assumedGlobals ).forEach( name => used[ name ] = 1 );
let allReplacements = blank();
this.externalModules.forEach( module => {
// TODO treat external module names/imports as globals
});
return allReplacements;
this.modules.forEach( module => {
keys( module.declarations ).forEach( originalName => {
const declaration = module.declarations[ originalName ];
const name = declaration.name;
if ( used[ name ] ) {
declaration.name = `${name}$${used[name]++}`;
} else {
used[ name ] = 1;
}
});
});
}
fetchModule ( id ) {

10
src/Module.js

@ -13,13 +13,15 @@ class SyntheticDefaultDeclaration {
this.node = node;
this.statement = statement;
this.name = name;
this.references = [];
}
addReference ( reference ) {
reference.declaration = this;
this.name = reference.name;
console.log( 'this.name', this.name )
}
}
@ -511,11 +513,13 @@ export default class Module {
}
else if ( statement.node.type === 'ExportDefaultDeclaration' ) {
const defaultName = this.declarations.default.name;
// anonymous functions should be converted into declarations
if ( statement.node.declaration.type === 'FunctionExpression' ) {
magicString.overwrite( statement.node.start, statement.node.declaration.start + 8, `function ${this.defaultName()}` );
magicString.overwrite( statement.node.start, statement.node.declaration.start + 8, `function ${defaultName}` );
} else {
magicString.overwrite( statement.node.start, statement.node.declaration.start, `var ${this.defaultName()} = ` );
magicString.overwrite( statement.node.start, statement.node.declaration.start, `var ${defaultName} = ` );
}
}

Loading…
Cancel
Save