Skip to content

Commit 877e3c4

Browse files
committed
Merge pull request microsoft#8929 from Microsoft/transforms-extractFromPrinter
[Transforms] Extract transformFiles call from printFile
2 parents f619282 + ef436a1 commit 877e3c4

File tree

6 files changed

+2510
-2326
lines changed

6 files changed

+2510
-2326
lines changed

src/compiler/checker.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17162,7 +17162,7 @@ namespace ts {
1716217162

1716317163
function isArgumentsLocalBinding(node: Identifier): boolean {
1716417164
if (!isGeneratedIdentifier(node)) {
17165-
node = getSourceTreeNodeOfType(node, isIdentifier);
17165+
node = getParseTreeNode(node, isIdentifier);
1716617166
if (node) {
1716717167
return getReferencedValueSymbol(node) === argumentsSymbol;
1716817168
}
@@ -17208,7 +17208,7 @@ namespace ts {
1720817208
// When resolved as an expression identifier, if the given node references an exported entity, return the declaration
1720917209
// node of the exported entity's container. Otherwise, return undefined.
1721017210
function getReferencedExportContainer(node: Identifier, prefixLocals?: boolean): SourceFile | ModuleDeclaration | EnumDeclaration {
17211-
node = getSourceTreeNodeOfType(node, isIdentifier);
17211+
node = getParseTreeNode(node, isIdentifier);
1721217212
if (node) {
1721317213
// When resolving the export container for the name of a module or enum
1721417214
// declaration, we need to start resolution at the declaration's container.
@@ -17246,7 +17246,7 @@ namespace ts {
1724617246
// When resolved as an expression identifier, if the given node references an import, return the declaration of
1724717247
// that import. Otherwise, return undefined.
1724817248
function getReferencedImportDeclaration(node: Identifier): Declaration {
17249-
node = getSourceTreeNodeOfType(node, isIdentifier);
17249+
node = getParseTreeNode(node, isIdentifier);
1725017250
if (node) {
1725117251
const symbol = getReferencedValueSymbol(node);
1725217252
if (symbol && symbol.flags & SymbolFlags.Alias) {
@@ -17305,7 +17305,7 @@ namespace ts {
1730517305
// return the declaration of that entity. Otherwise, return undefined.
1730617306
function getReferencedDeclarationWithCollidingName(node: Identifier): Declaration {
1730717307
if (!isGeneratedIdentifier(node)) {
17308-
node = getSourceTreeNodeOfType(node, isIdentifier);
17308+
node = getParseTreeNode(node, isIdentifier);
1730917309
if (node) {
1731017310
const symbol = getReferencedValueSymbol(node);
1731117311
if (symbol && isSymbolOfDeclarationWithCollidingName(symbol)) {
@@ -17320,7 +17320,7 @@ namespace ts {
1732017320
// Return true if the given node is a declaration of a nested block scoped entity with a name that either hides an
1732117321
// existing name or might hide a name when compiled downlevel
1732217322
function isDeclarationWithCollidingName(node: Declaration): boolean {
17323-
node = getSourceTreeNodeOfType(node, isDeclaration);
17323+
node = getParseTreeNode(node, isDeclaration);
1732417324
if (node) {
1732517325
const symbol = getSymbolOfNode(node);
1732617326
if (symbol) {
@@ -17332,7 +17332,7 @@ namespace ts {
1733217332
}
1733317333

1733417334
function isValueAliasDeclaration(node: Node): boolean {
17335-
node = getSourceTreeNode(node);
17335+
node = getParseTreeNode(node);
1733617336
if (node === undefined) {
1733717337
// A synthesized node comes from an emit transformation and is always a value.
1733817338
return true;
@@ -17358,7 +17358,7 @@ namespace ts {
1735817358
}
1735917359

1736017360
function isTopLevelValueImportEqualsWithEntityName(node: ImportEqualsDeclaration): boolean {
17361-
node = getSourceTreeNodeOfType(node, isImportEqualsDeclaration);
17361+
node = getParseTreeNode(node, isImportEqualsDeclaration);
1736217362
if (node === undefined || node.parent.kind !== SyntaxKind.SourceFile || !isInternalModuleImportEqualsDeclaration(node)) {
1736317363
// parent is not source file or it is not reference to internal module
1736417364
return false;
@@ -17384,7 +17384,7 @@ namespace ts {
1738417384
}
1738517385

1738617386
function isReferencedAliasDeclaration(node: Node, checkChildren?: boolean): boolean {
17387-
node = getSourceTreeNode(node);
17387+
node = getParseTreeNode(node);
1738817388
if (isAliasSymbolDeclaration(node)) {
1738917389
const symbol = getSymbolOfNode(node);
1739017390
if (symbol && getSymbolLinks(symbol).referenced) {
@@ -17420,7 +17420,7 @@ namespace ts {
1742017420
}
1742117421

1742217422
function getNodeCheckFlags(node: Node): NodeCheckFlags {
17423-
node = getSourceTreeNode(node);
17423+
node = getParseTreeNode(node);
1742417424
return node ? getNodeLinks(node).flags : undefined;
1742517425
}
1742617426

@@ -17551,7 +17551,7 @@ namespace ts {
1755117551

1755217552
function getReferencedValueDeclaration(reference: Identifier): Declaration {
1755317553
if (!isGeneratedIdentifier(reference)) {
17554-
reference = getSourceTreeNodeOfType(reference, isIdentifier);
17554+
reference = getParseTreeNode(reference, isIdentifier);
1755517555
if (reference) {
1755617556
const symbol = getReferencedValueSymbol(reference);
1755717557
if (symbol) {

src/compiler/core.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1150,9 +1150,23 @@ namespace ts {
11501150
/** Performance measurements for the compiler. */
11511151
/*@internal*/
11521152
export namespace performance {
1153+
declare const onProfilerEvent: { (markName: string): void; profiler: boolean; };
1154+
let profilerEvent: (markName: string) => void;
11531155
let counters: Map<number>;
11541156
let measures: Map<number>;
11551157

1158+
/**
1159+
* Emit a performance event if ts-profiler is connected. This is primarily used
1160+
* to generate heap snapshots.
1161+
*
1162+
* @param eventName A name for the event.
1163+
*/
1164+
export function emit(eventName: string) {
1165+
if (profilerEvent) {
1166+
onProfilerEvent(eventName);
1167+
}
1168+
}
1169+
11561170
/**
11571171
* Increments a counter with the specified name.
11581172
*
@@ -1188,7 +1202,7 @@ namespace ts {
11881202
*/
11891203
export function measure(measureName: string, marker: number) {
11901204
if (measures) {
1191-
measures[measureName] = (getProperty(measures, measureName) || 0) + (mark() - marker);
1205+
measures[measureName] = (getProperty(measures, measureName) || 0) + (Date.now() - marker);
11921206
}
11931207
}
11941208

@@ -1215,12 +1229,17 @@ namespace ts {
12151229
commentTime: 0,
12161230
sourceMapTime: 0
12171231
};
1232+
1233+
profilerEvent = typeof onProfilerEvent === "function" && onProfilerEvent.profiler === true
1234+
? onProfilerEvent
1235+
: undefined;
12181236
}
12191237

12201238
/** Disables (and clears) performance measurements for the compiler. */
12211239
export function disable() {
12221240
counters = undefined;
12231241
measures = undefined;
1242+
profilerEvent = undefined;
12241243
}
12251244
}
12261245
}

0 commit comments

Comments
 (0)