diff --git a/src/compiler/factory/nodeFactory.ts b/src/compiler/factory/nodeFactory.ts
index 713df9c86780a..2ac0fb4840ad0 100644
--- a/src/compiler/factory/nodeFactory.ts
+++ b/src/compiler/factory/nodeFactory.ts
@@ -14,6 +14,13 @@ namespace ts {
NoOriginalNode = 1 << 3,
}
+ const nodeFactoryPatchers: ((factory: NodeFactory) => void)[] = [];
+
+ /* @internal */
+ export function addNodeFactoryPatcher(fn: (factory: NodeFactory) => void) {
+ nodeFactoryPatchers.push(fn);
+ }
+
/**
* Creates a `NodeFactory` that can be used to create and update a syntax tree.
* @param flags Flags that control factory behavior.
@@ -161,11 +168,11 @@ namespace ts {
createObjectLiteralExpression,
updateObjectLiteralExpression,
createPropertyAccessExpression: flags & NodeFactoryFlags.NoIndentationOnFreshPropertyAccess ?
- (expression, name) => setEmitFlags(createPropertyAccessExpression(expression, name), EmitFlags.NoIndentation) :
+ (expression: Expression, name: string | MemberName) => setEmitFlags(createPropertyAccessExpression(expression, name), EmitFlags.NoIndentation) :
createPropertyAccessExpression,
updatePropertyAccessExpression,
createPropertyAccessChain: flags & NodeFactoryFlags.NoIndentationOnFreshPropertyAccess ?
- (expression, questionDotToken, name) => setEmitFlags(createPropertyAccessChain(expression, questionDotToken, name), EmitFlags.NoIndentation) :
+ (expression: Expression, questionDotToken: QuestionDotToken | undefined, name: string | MemberName) => setEmitFlags(createPropertyAccessChain(expression, questionDotToken, name), EmitFlags.NoIndentation) :
createPropertyAccessChain,
updatePropertyAccessChain,
createElementAccessExpression,
@@ -534,7 +541,9 @@ namespace ts {
liftToBlock,
mergeLexicalEnvironment,
updateModifiers,
- };
+ } as any;
+
+ forEach(nodeFactoryPatchers, fn => fn(factory));
return factory;
diff --git a/src/deprecatedCompat/4.2/abstractConstructorTypes.ts b/src/deprecatedCompat/4.2/abstractConstructorTypes.ts
index b2645d9ffea8b..89a2c1084f6ef 100644
--- a/src/deprecatedCompat/4.2/abstractConstructorTypes.ts
+++ b/src/deprecatedCompat/4.2/abstractConstructorTypes.ts
@@ -59,16 +59,8 @@ namespace ts {
// Patch `createNodeFactory` because it creates the factories that are provided to transformers
// in the public API.
-
- const prevCreateNodeFactory = createNodeFactory;
-
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-qualifier
- ts.createNodeFactory = (flags, baseFactory) => {
- const factory = prevCreateNodeFactory(flags, baseFactory);
- patchNodeFactory(factory);
- return factory;
- };
+ addNodeFactoryPatcher(patchNodeFactory);
// Patch `ts.factory` because its public
patchNodeFactory(factory);
-}
\ No newline at end of file
+}
diff --git a/src/deprecatedCompat/4.6/importTypeAssertions.ts b/src/deprecatedCompat/4.6/importTypeAssertions.ts
index 1bfe3ef920ed5..4fd063801221d 100644
--- a/src/deprecatedCompat/4.6/importTypeAssertions.ts
+++ b/src/deprecatedCompat/4.6/importTypeAssertions.ts
@@ -80,16 +80,8 @@ namespace ts {
// Patch `createNodeFactory` because it creates the factories that are provided to transformers
// in the public API.
-
- const prevCreateNodeFactory = createNodeFactory;
-
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-qualifier
- ts.createNodeFactory = (flags, baseFactory) => {
- const factory = prevCreateNodeFactory(flags, baseFactory);
- patchNodeFactory(factory);
- return factory;
- };
+ addNodeFactoryPatcher(patchNodeFactory);
// Patch `ts.factory` because its public
patchNodeFactory(factory);
-}
\ No newline at end of file
+}
diff --git a/src/deprecatedCompat/4.7/typeParameterModifiers.ts b/src/deprecatedCompat/4.7/typeParameterModifiers.ts
index b7e531a4a9238..ecd5ea448d539 100644
--- a/src/deprecatedCompat/4.7/typeParameterModifiers.ts
+++ b/src/deprecatedCompat/4.7/typeParameterModifiers.ts
@@ -65,16 +65,8 @@ namespace ts {
// Patch `createNodeFactory` because it creates the factories that are provided to transformers
// in the public API.
-
- const prevCreateNodeFactory = createNodeFactory;
-
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-qualifier
- ts.createNodeFactory = (flags, baseFactory) => {
- const factory = prevCreateNodeFactory(flags, baseFactory);
- patchNodeFactory(factory);
- return factory;
- };
+ addNodeFactoryPatcher(patchNodeFactory);
// Patch `ts.factory` because its public
patchNodeFactory(factory);
-}
\ No newline at end of file
+}
diff --git a/src/deprecatedCompat/4.8/mergeDecoratorsAndModifiers.ts b/src/deprecatedCompat/4.8/mergeDecoratorsAndModifiers.ts
index d6cdbf2969e1c..5817bb0c0be85 100644
--- a/src/deprecatedCompat/4.8/mergeDecoratorsAndModifiers.ts
+++ b/src/deprecatedCompat/4.8/mergeDecoratorsAndModifiers.ts
@@ -1397,15 +1397,7 @@ namespace ts {
// Patch `createNodeFactory` because it creates the factories that are provided to transformers
// in the public API.
-
- const prevCreateNodeFactory = createNodeFactory;
-
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-qualifier
- ts.createNodeFactory = (flags, baseFactory) => {
- const factory = prevCreateNodeFactory(flags, baseFactory);
- patchNodeFactory(factory);
- return factory;
- };
+ addNodeFactoryPatcher(patchNodeFactory);
// Patch `ts.factory` because its public
patchNodeFactory(factory);
diff --git a/src/tsserver/webServer.ts b/src/tsserver/webServer.ts
index 71beb5a8db92b..78702954328ca 100644
--- a/src/tsserver/webServer.ts
+++ b/src/tsserver/webServer.ts
@@ -1,8 +1,12 @@
/*@internal*/
-
-///
-
namespace ts.server {
+ declare const addEventListener: any;
+ declare const postMessage: any;
+ declare const close: any;
+ declare const location: any;
+ declare const XMLHttpRequest: any;
+ declare const self: any;
+
const nullLogger: Logger = {
close: noop,
hasLevel: returnFalse,
diff --git a/src/webServer/webServer.ts b/src/webServer/webServer.ts
index c989c00557ba4..db12074aee5ce 100644
--- a/src/webServer/webServer.ts
+++ b/src/webServer/webServer.ts
@@ -1,8 +1,9 @@
/*@internal*/
-///
-///
namespace ts.server {
+ declare const fetch: any;
+ declare const importScripts: any;
+
export interface HostWithWriteMessage {
writeMessage(s: any): void;
}
@@ -112,8 +113,6 @@ namespace ts.server {
}
}
- export declare const dynamicImport: ((id: string) => Promise) | undefined;
-
// Attempt to load `dynamicImport`
if (typeof importScripts === "function") {
try {
@@ -132,9 +131,10 @@ namespace ts.server {
const getWebPath = (path: string) => startsWith(path, directorySeparator) ? path.replace(directorySeparator, getExecutingDirectoryPath()) : undefined;
const dynamicImport = async (id: string): Promise => {
+ const serverDynamicImport: ((id: string) => Promise) | undefined = (server as any).dynamicImport;
// Use syntactic dynamic import first, if available
- if (server.dynamicImport) {
- return server.dynamicImport(id);
+ if (serverDynamicImport) {
+ return serverDynamicImport(id);
}
throw new Error("Dynamic import not implemented");