Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a few changes to allow all code to be loaded as one project #1

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/compiler/factory/nodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -534,7 +541,9 @@ namespace ts {
liftToBlock,
mergeLexicalEnvironment,
updateModifiers,
};
} as any;

forEach(nodeFactoryPatchers, fn => fn(factory));

return factory;

Expand Down
12 changes: 2 additions & 10 deletions src/deprecatedCompat/4.2/abstractConstructorTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 2 additions & 10 deletions src/deprecatedCompat/4.6/importTypeAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
12 changes: 2 additions & 10 deletions src/deprecatedCompat/4.7/typeParameterModifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
10 changes: 1 addition & 9 deletions src/deprecatedCompat/4.8/mergeDecoratorsAndModifiers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 7 additions & 3 deletions src/tsserver/webServer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/*@internal*/

/// <reference lib="webworker" />

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,
Expand Down
12 changes: 6 additions & 6 deletions src/webServer/webServer.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*@internal*/
/// <reference lib="dom" />
/// <reference lib="webworker.importscripts" />

namespace ts.server {
declare const fetch: any;
declare const importScripts: any;

export interface HostWithWriteMessage {
writeMessage(s: any): void;
}
Expand Down Expand Up @@ -112,8 +113,6 @@ namespace ts.server {
}
}

export declare const dynamicImport: ((id: string) => Promise<any>) | undefined;

// Attempt to load `dynamicImport`
if (typeof importScripts === "function") {
try {
Expand All @@ -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<any> => {
const serverDynamicImport: ((id: string) => Promise<any>) | 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");
Expand Down