fix scope when falling back to original load function

This commit is contained in:
Johannes Rieken
2019-08-19 14:11:46 +02:00
parent 57379e0f97
commit c8d44e24dd
3 changed files with 10 additions and 6 deletions

View File

@@ -21,12 +21,12 @@ import { platform } from 'vs/base/common/process';
interface LoadFunction {
(request: string, parent: { filename: string; }, isMain: any): any;
(request: string): any;
}
interface INodeModuleFactory {
readonly nodeModuleName: string | string[];
load(request: string, parent: URI, isMain: any, original: LoadFunction): any;
load(request: string, parent: URI, original: LoadFunction): any;
alternativeModuleName?(name: string): string | undefined;
}
@@ -245,7 +245,7 @@ class OpenNodeModuleFactory implements INodeModuleFactory {
};
}
public load(request: string, parent: URI, isMain: any, original: LoadFunction): any {
public load(request: string, parent: URI, original: LoadFunction): any {
// get extension id from filename and api for extension
const extension = this._extensionPaths.findSubstr(parent.fsPath);
if (extension) {
@@ -253,7 +253,7 @@ class OpenNodeModuleFactory implements INodeModuleFactory {
this.sendShimmingTelemetry();
}
this._original = original(request, { filename: parent.fsPath }, isMain);
this._original = original(request);
return this._impl;
}

View File

@@ -31,7 +31,11 @@ class NodeModuleRequireInterceptor extends RequireInterceptor {
if (!that._factories.has(request)) {
return original.apply(this, arguments);
}
return that._factories.get(request)!.load(request, URI.file(parent.filename), isMain, original);
return that._factories.get(request)!.load(
request,
URI.file(parent.filename),
request => original.apply(this, [request, parent, isMain])
);
};
}
}

View File

@@ -89,7 +89,7 @@ class WorkerRequireInterceptor extends RequireInterceptor {
}
if (this._factories.has(request)) {
return this._factories.get(request)!.load(request, parent, false, () => { throw new Error(); });
return this._factories.get(request)!.load(request, parent, () => { throw new Error('CANNOT LOAD MODULE from here.'); });
}
return undefined;
}