|
@ -144,10 +144,14 @@ export default class Module { |
|
|
|
|
|
|
|
|
// Always define a new `Identifier` for the default export.
|
|
|
// Always define a new `Identifier` for the default export.
|
|
|
this.exports.define( 'default', { |
|
|
this.exports.define( 'default', { |
|
|
originalName: name, |
|
|
originalName: 'default', |
|
|
name, |
|
|
name, |
|
|
|
|
|
|
|
|
module: this, |
|
|
module: this, |
|
|
|
|
|
mark () { |
|
|
|
|
|
this.isUsed = true; |
|
|
|
|
|
this.statement.mark(); |
|
|
|
|
|
}, |
|
|
statement, |
|
|
statement, |
|
|
|
|
|
|
|
|
// Keep the identifier name, if one exists.
|
|
|
// Keep the identifier name, if one exists.
|
|
@ -194,6 +198,10 @@ export default class Module { |
|
|
name, |
|
|
name, |
|
|
|
|
|
|
|
|
module: this, |
|
|
module: this, |
|
|
|
|
|
mark () { |
|
|
|
|
|
this.isUsed = true; |
|
|
|
|
|
this.statement.mark(); |
|
|
|
|
|
}, |
|
|
statement, |
|
|
statement, |
|
|
localName: name, |
|
|
localName: name, |
|
|
expression: declaration |
|
|
expression: declaration |
|
@ -259,7 +267,11 @@ export default class Module { |
|
|
name, |
|
|
name, |
|
|
|
|
|
|
|
|
statement, |
|
|
statement, |
|
|
module: this |
|
|
module: this, |
|
|
|
|
|
mark () { |
|
|
|
|
|
this.isUsed = true; |
|
|
|
|
|
this.statement.mark(); |
|
|
|
|
|
} |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -296,7 +308,11 @@ export default class Module { |
|
|
// For each name we depend on that isn't in scope,
|
|
|
// For each name we depend on that isn't in scope,
|
|
|
// add a new global and bind the local name to it.
|
|
|
// add a new global and bind the local name to it.
|
|
|
if ( !this.locals.inScope( name ) ) { |
|
|
if ( !this.locals.inScope( name ) ) { |
|
|
this.bundle.globals.define( name ); |
|
|
this.bundle.globals.define( name, { |
|
|
|
|
|
originalName: name, |
|
|
|
|
|
name, |
|
|
|
|
|
mark () {} |
|
|
|
|
|
}); |
|
|
this.locals.bind( name, this.bundle.globals.reference( name ) ); |
|
|
this.locals.bind( name, this.bundle.globals.reference( name ) ); |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
@ -383,6 +399,8 @@ export default class Module { |
|
|
|
|
|
|
|
|
// Enforce dynamic access of the module's properties.
|
|
|
// Enforce dynamic access of the module's properties.
|
|
|
dynamicAccess () { |
|
|
dynamicAccess () { |
|
|
|
|
|
if ( this.needsDynamicAccess ) return; |
|
|
|
|
|
|
|
|
this.needsDynamicAccess = true; |
|
|
this.needsDynamicAccess = true; |
|
|
this.markAllExportStatements(); |
|
|
this.markAllExportStatements(); |
|
|
|
|
|
|
|
@ -395,20 +413,8 @@ export default class Module { |
|
|
return this.bundle.moduleById[ this.resolvedIds[ source ] ]; |
|
|
return this.bundle.moduleById[ this.resolvedIds[ source ] ]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
mark ( name ) { |
|
|
mark () { |
|
|
const id = this.locals.lookup( name ); |
|
|
this.dynamicAccess(); |
|
|
|
|
|
|
|
|
if ( id && id.module ) { |
|
|
|
|
|
if ( id.module.isExternal ) { |
|
|
|
|
|
id.module.importedByBundle[ id.originalName ] = true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( id.statement ) { |
|
|
|
|
|
// Assert that statement is defined. It isn't for external modules.
|
|
|
|
|
|
id.isUsed = true; |
|
|
|
|
|
id.statement.mark(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
markAllStatements ( isEntryModule ) { |
|
|
markAllStatements ( isEntryModule ) { |
|
@ -436,7 +442,7 @@ export default class Module { |
|
|
else { |
|
|
else { |
|
|
// Be sure to mark the default export for the entry module.
|
|
|
// Be sure to mark the default export for the entry module.
|
|
|
if ( isEntryModule && statement.node.type === 'ExportDefaultDeclaration' ) { |
|
|
if ( isEntryModule && statement.node.type === 'ExportDefaultDeclaration' ) { |
|
|
this.markExport( 'default', this ); |
|
|
this.exports.lookup( 'default' ).mark(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
statement.mark(); |
|
|
statement.mark(); |
|
@ -450,34 +456,6 @@ export default class Module { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
markExport ( name, importer ) { |
|
|
|
|
|
const id = this.exports.lookup( name ); |
|
|
|
|
|
|
|
|
|
|
|
if ( id ) { |
|
|
|
|
|
id.isUsed = true; |
|
|
|
|
|
|
|
|
|
|
|
// Assert that statement is defined. It isn't for external modules.
|
|
|
|
|
|
if ( id.statement ) id.statement.mark(); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for ( const module of this.exportAlls ) { |
|
|
|
|
|
const id = module.exports.lookup( name ); |
|
|
|
|
|
|
|
|
|
|
|
if ( id ) { |
|
|
|
|
|
id.isUsed = true; |
|
|
|
|
|
|
|
|
|
|
|
// Assert that statement is defined. It isn't for external modules.
|
|
|
|
|
|
if ( id.statement ) id.statement.mark(); |
|
|
|
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
throw new Error( `Module ${this.id} does not export ${name} (imported by ${importer.id})` ); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
parse ( ast ) { |
|
|
parse ( ast ) { |
|
|
// The ast can be supplied programmatically (but usually won't be)
|
|
|
// The ast can be supplied programmatically (but usually won't be)
|
|
|
if ( !ast ) { |
|
|
if ( !ast ) { |
|
|