Skip to content

Commit e331522

Browse files
committed
consistency: use arrow functions to pass 'this' context
1 parent fe7e0c4 commit e331522

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

src/Module.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -735,32 +735,36 @@ export default class Module {
735735
timeStart('analyse ast', 3);
736736

737737
this.astContext = {
738-
addDynamicImport: this.addDynamicImport.bind(this),
739-
addExport: this.addExport.bind(this),
740-
addImport: this.addImport.bind(this),
741-
addImportMeta: this.addImportMeta.bind(this),
738+
addDynamicImport: (node: ImportExpression): void => this.addDynamicImport(node),
739+
addExport: (
740+
node: ExportAllDeclaration | ExportNamedDeclaration | ExportDefaultDeclaration
741+
): void => this.addExport(node),
742+
addImport: (node: ImportDeclaration): void => this.addImport(node),
743+
addImportMeta: (node: MetaProperty): void => this.addImportMeta(node),
742744
code, // Only needed for debugging
743745
deoptimizationTracker: this.graph.deoptimizationTracker,
744-
error: this.error.bind(this),
746+
error: (props: RollupError, pos: number) => this.error(props, pos),
745747
fileName, // Needed for warnings
746-
getExports: this.getExports.bind(this),
748+
getExports: () => this.getExports(),
747749
getModuleExecIndex: () => this.execIndex,
748-
getModuleName: this.basename.bind(this),
750+
getModuleName: () => this.basename(),
749751
getNodeConstructor: (name: string) => nodeConstructors[name] || nodeConstructors.UnknownNode,
750-
getReexports: this.getReexports.bind(this),
752+
getReexports: () => this.getReexports(),
751753
importDescriptions: this.importDescriptions,
752754
includeAllExports: () => this.includeAllExports(true),
753-
includeDynamicImport: this.includeDynamicImport.bind(this),
754-
includeVariableInModule: this.includeVariableInModule.bind(this),
755+
includeDynamicImport: (node: ImportExpression) => this.includeDynamicImport(node),
756+
includeVariableInModule: (variable: Variable) => this.includeVariableInModule(variable),
755757
magicString: this.magicString,
756758
module: this,
757759
moduleContext: this.context,
758760
options: this.options,
759-
requestTreeshakingPass: () => (this.graph.needsTreeshakingPass = true),
760-
traceExport: this.getVariableForExportName.bind(this),
761-
traceVariable: this.traceVariable.bind(this),
761+
requestTreeshakingPass: () => {
762+
this.graph.needsTreeshakingPass = true;
763+
},
764+
traceExport: (name: string) => this.getVariableForExportName(name),
765+
traceVariable: (name: string) => this.traceVariable(name),
762766
usesTopLevelAwait: false,
763-
warn: this.warn.bind(this)
767+
warn: (warning: RollupWarning, pos: number) => this.warn(warning, pos)
764768
};
765769

766770
this.scope = new ModuleScope(this.graph.scope, this.astContext);

0 commit comments

Comments
 (0)