Skip to content

Commit

Permalink
Make types and signatures monomorphic too.
Browse files Browse the repository at this point in the history
  • Loading branch information
dragomirtitian committed Jun 19, 2024
1 parent 5dcba5f commit 49b3d87
Show file tree
Hide file tree
Showing 7 changed files with 1,243 additions and 568 deletions.
7 changes: 4 additions & 3 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1416,9 +1416,10 @@ const SymbolLinks = class implements SymbolLinks {
declare _symbolLinksBrand: any;
};

function NodeLinks(this: NodeLinks) {
this.flags = NodeCheckFlags.None;
}
const NodeLinks = class {
flags = NodeCheckFlags.None;
calculatedFlags = NodeCheckFlags.None;
};

/** @internal */
export function getNodeId(node: Node): number {
Expand Down
1 change: 1 addition & 0 deletions src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ import {
ParsedCommandLine,
parseJsonText,
Path,
PluginImport,

Check warning on line 100 in src/compiler/commandLineParser.ts

View workflow job for this annotation

GitHub Actions / lint

'PluginImport' is defined but never used. Allowed unused vars must match /^(_+$|_[^_])/u
PollingWatchKind,
PrefixUnaryExpression,
ProjectReference,
Expand Down
32 changes: 12 additions & 20 deletions src/compiler/factory/nodeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ import {
NodeArray,
NodeFactory,
NodeFlags,
NodeImpl,
nodeIsSynthesized,
NonNullChain,
NonNullExpression,
Expand Down Expand Up @@ -6077,8 +6078,8 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
}

function createRedirectedSourceFile(redirectInfo: RedirectInfo) {
const node: SourceFile = Object.create(redirectInfo.redirectTarget);
Object.defineProperties(node, {
const nodeData: any = Object.create((redirectInfo.redirectTarget as any as NodeImpl).data);
Object.defineProperties(nodeData, {
id: {
get(this: SourceFile) {
return this.redirectInfo!.redirectTarget.id;
Expand All @@ -6095,9 +6096,13 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
this.redirectInfo!.redirectTarget.symbol = value;
},
},
redirectInfo: {
value: redirectInfo,
},
});
node.redirectInfo = redirectInfo;
return node;
const sourceFile = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile);
(sourceFile as NodeImpl).data = nodeData;
return sourceFile as SourceFile;
}

function cloneRedirectedSourceFile(source: SourceFile) {
Expand All @@ -6118,18 +6123,17 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
// work, we should consider switching explicit property assignments instead of using `for..in`.
const node = baseFactory.createBaseSourceFileNode(SyntaxKind.SourceFile) as Mutable<SourceFile>;
node.flags |= source.flags & ~NodeFlags.Synthesized;
copyBaseNodeProperties(source, node);
const sourceData = (source as any).data ?? source;
const nodeData = (node as any).data ?? node;
for (const p in sourceData) {
if (hasProperty(nodeData, p) || !hasProperty(sourceData, p)) {
continue;
}
if (p === "emitNode") {
nodeData.emitNode = undefined;
node.emitNode = undefined;
continue;
}
nodeData[p] = sourceData[p];
(node as any)[p] = sourceData[p];
}
return node;
}
Expand Down Expand Up @@ -6379,28 +6383,16 @@ export function createNodeFactory(flags: NodeFactoryFlags, baseFactory: BaseNode
(clone as Mutable<T>).flags |= node.flags & ~NodeFlags.Synthesized;
(clone as Mutable<T>).transformFlags = node.transformFlags;
setOriginal(clone, node);
copyBaseNodeProperties(node, clone);
const nodeData = (node as any).data ?? node;
const cloneData = (clone as any).data ?? clone;
for (const key in nodeData) {
if (hasProperty(cloneData, key) || !hasProperty(nodeData, key)) {
continue;
}
cloneData[key] = nodeData[key];
(clone as any)[key] = nodeData[key];
}
return clone;
}
function copyBaseNodeProperties(node: Node, clone: Mutable<Node>) {
clone.pos = node.pos;
clone.end = node.end;
clone.kind = node.kind;
clone.id = node.id;
clone.modifierFlagsCache = node.modifierFlagsCache;
clone.transformFlags = node.transformFlags;
clone.parent = node.parent;
clone.original = node.original;
clone.emitNode = node.emitNode;
}
// compound nodes
function createImmediatelyInvokedFunctionExpression(statements: readonly Statement[]): ImmediatelyInvokedFunctionExpression;
function createImmediatelyInvokedFunctionExpression(statements: readonly Statement[], param: ParameterDeclaration, paramValue: Expression): ImmediatelyInvokedFunctionExpression;
Expand Down
Loading

0 comments on commit 49b3d87

Please sign in to comment.