Skip to content

Commit 364a485

Browse files
committed
Merge branch 'transforms-fixPerformance' into transforms-visitEachChildPerf
2 parents 3d3b3a4 + 82e2531 commit 364a485

5 files changed

Lines changed: 131 additions & 129 deletions

File tree

src/compiler/core.ts

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,18 @@ namespace ts {
11201120
}
11211121
}
11221122

1123+
export function getEnvironmentVariable(name: string, host?: CompilerHost) {
1124+
if (host && host.getEnvironmentVariable) {
1125+
return host.getEnvironmentVariable(name);
1126+
}
1127+
1128+
if (sys && sys.getEnvironmentVariable) {
1129+
return sys.getEnvironmentVariable(name);
1130+
}
1131+
1132+
return "";
1133+
}
1134+
11231135
export function copyListRemovingItem<T>(item: T, list: T[]) {
11241136
const copiedList: T[] = [];
11251137
for (const e of list) {
@@ -1139,17 +1151,16 @@ namespace ts {
11391151
/** Performance measurements for the compiler. */
11401152
/*@internal*/
11411153
export namespace performance {
1142-
let counters: Map<number> = {};
1143-
let measures: Map<number> = {};
1144-
let enabled = false;
1154+
let counters: Map<number>;
1155+
let measures: Map<number>;
11451156

11461157
/**
11471158
* Increments a counter with the specified name.
11481159
*
11491160
* @param counterName The name of the counter.
11501161
*/
11511162
export function increment(counterName: string) {
1152-
if (enabled) {
1163+
if (counters) {
11531164
counters[counterName] = (getProperty(counters, counterName) || 0) + 1;
11541165
}
11551166
}
@@ -1160,14 +1171,14 @@ namespace ts {
11601171
* @param counterName The name of the counter.
11611172
*/
11621173
export function getCount(counterName: string) {
1163-
return enabled && getProperty(counters, counterName) || 0;
1174+
return counters && getProperty(counters, counterName) || 0;
11641175
}
11651176

11661177
/**
11671178
* Marks the start of a performance measurement.
11681179
*/
11691180
export function mark() {
1170-
return enabled ? Date.now() : 0;
1181+
return measures ? Date.now() : 0;
11711182
}
11721183

11731184
/**
@@ -1177,7 +1188,7 @@ namespace ts {
11771188
* @param marker The timestamp of the starting mark.
11781189
*/
11791190
export function measure(measureName: string, marker: number) {
1180-
if (enabled) {
1191+
if (measures) {
11811192
measures[measureName] = (getProperty(measures, measureName) || 0) + (mark() - marker);
11821193
}
11831194
}
@@ -1188,25 +1199,29 @@ namespace ts {
11881199
* @param measureName The name of the measure whose durations should be accumulated.
11891200
*/
11901201
export function getDuration(measureName: string) {
1191-
return enabled && getProperty(measures, measureName) || 0;
1202+
return measures && getProperty(measures, measureName) || 0;
11921203
}
11931204

1194-
/**
1195-
* Resets all marks and measurements in the performance service.
1196-
*/
1197-
export function reset() {
1198-
counters = {};
1199-
measures = {};
1200-
}
1201-
1202-
/** Enables performance measurements for the compiler. */
1205+
/** Enables (and resets) performance measurements for the compiler. */
12031206
export function enable() {
1204-
enabled = true;
1205-
}
1206-
1207-
/** Disables performance measurements for the compiler. */
1207+
counters = { };
1208+
measures = {
1209+
programTime: 0,
1210+
parseTime: 0,
1211+
bindTime: 0,
1212+
emitTime: 0,
1213+
ioReadTime: 0,
1214+
ioWriteTime: 0,
1215+
printTime: 0,
1216+
commentTime: 0,
1217+
sourceMapTime: 0
1218+
};
1219+
}
1220+
1221+
/** Disables (and clears) performance measurements for the compiler. */
12081222
export function disable() {
1209-
enabled = false;
1223+
counters = undefined;
1224+
measures = undefined;
12101225
}
12111226
}
12121227
}

src/compiler/transformer.ts

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,100 @@ namespace ts {
2323
EmitNotifications = 1 << 1,
2424
}
2525

26+
/* @internal */
27+
export interface TransformationContext extends LexicalEnvironment {
28+
getCompilerOptions(): CompilerOptions;
29+
getEmitResolver(): EmitResolver;
30+
getEmitHost(): EmitHost;
31+
32+
/**
33+
* Gets flags used to customize later transformations or emit.
34+
*/
35+
getNodeEmitFlags(node: Node): NodeEmitFlags;
36+
37+
/**
38+
* Sets flags used to customize later transformations or emit.
39+
*/
40+
setNodeEmitFlags<T extends Node>(node: T, flags: NodeEmitFlags): T;
41+
42+
/**
43+
* Gets the TextRange to use for source maps for the node.
44+
*/
45+
getSourceMapRange(node: Node): TextRange;
46+
47+
/**
48+
* Sets the TextRange to use for source maps for the node.
49+
*/
50+
setSourceMapRange<T extends Node>(node: T, range: TextRange): T;
51+
52+
/**
53+
* Gets the TextRange to use for source maps for a token of a node.
54+
*/
55+
getTokenSourceMapRange(node: Node, token: SyntaxKind): TextRange;
56+
57+
/**
58+
* Sets the TextRange to use for source maps for a token of a node.
59+
*/
60+
setTokenSourceMapRange<T extends Node>(node: T, token: SyntaxKind, range: TextRange): T;
61+
62+
/**
63+
* Gets the TextRange to use for comments for the node.
64+
*/
65+
getCommentRange(node: Node): TextRange;
66+
67+
/**
68+
* Sets the TextRange to use for comments for the node.
69+
*/
70+
setCommentRange<T extends Node>(node: T, range: TextRange): T;
71+
72+
/**
73+
* Hoists a function declaration to the containing scope.
74+
*/
75+
hoistFunctionDeclaration(node: FunctionDeclaration): void;
76+
77+
/**
78+
* Hoists a variable declaration to the containing scope.
79+
*/
80+
hoistVariableDeclaration(node: Identifier): void;
81+
82+
/**
83+
* Enables expression substitutions in the pretty printer for the provided SyntaxKind.
84+
*/
85+
enableSubstitution(kind: SyntaxKind): void;
86+
87+
/**
88+
* Determines whether expression substitutions are enabled for the provided node.
89+
*/
90+
isSubstitutionEnabled(node: Node): boolean;
91+
92+
/**
93+
* Hook used by transformers to substitute expressions just before they
94+
* are emitted by the pretty printer.
95+
*/
96+
onSubstituteNode?: (node: Node, isExpression: boolean) => Node;
97+
98+
/**
99+
* Enables before/after emit notifications in the pretty printer for the provided
100+
* SyntaxKind.
101+
*/
102+
enableEmitNotification(kind: SyntaxKind): void;
103+
104+
/**
105+
* Determines whether before/after emit notifications should be raised in the pretty
106+
* printer when it emits a node.
107+
*/
108+
isEmitNotificationEnabled(node: Node): boolean;
109+
110+
/**
111+
* Hook used to allow transformers to capture state before or after
112+
* the printer emits a node.
113+
*/
114+
onEmitNode?: (node: Node, emit: (node: Node) => void) => void;
115+
}
116+
117+
/* @internal */
118+
export type Transformer = (context: TransformationContext) => (node: SourceFile) => SourceFile;
119+
26120
export function getTransformers(compilerOptions: CompilerOptions) {
27121
const jsx = compilerOptions.jsx;
28122
const languageVersion = getEmitScriptTarget(compilerOptions);

src/compiler/tsc.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,6 @@ namespace ts {
560560
let statistics: Statistic[];
561561
if (compilerOptions.diagnostics || compilerOptions.extendedDiagnostics) {
562562
performance.enable();
563-
performance.reset();
564563
statistics = [];
565564
}
566565

@@ -610,7 +609,6 @@ namespace ts {
610609
reportStatistics();
611610

612611
performance.disable();
613-
performance.reset();
614612
}
615613

616614
return { program, exitStatus };

src/compiler/types.ts

Lines changed: 0 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,99 +3019,6 @@ namespace ts {
30193019
endLexicalEnvironment(): Statement[];
30203020
}
30213021

3022-
/* @internal */
3023-
export interface TransformationContext extends LexicalEnvironment {
3024-
getCompilerOptions(): CompilerOptions;
3025-
getEmitResolver(): EmitResolver;
3026-
getEmitHost(): EmitHost;
3027-
3028-
/**
3029-
* Gets flags used to customize later transformations or emit.
3030-
*/
3031-
getNodeEmitFlags(node: Node): NodeEmitFlags;
3032-
3033-
/**
3034-
* Sets flags used to customize later transformations or emit.
3035-
*/
3036-
setNodeEmitFlags<T extends Node>(node: T, flags: NodeEmitFlags): T;
3037-
3038-
/**
3039-
* Gets the TextRange to use for source maps for the node.
3040-
*/
3041-
getSourceMapRange(node: Node): TextRange;
3042-
3043-
/**
3044-
* Sets the TextRange to use for source maps for the node.
3045-
*/
3046-
setSourceMapRange<T extends Node>(node: T, range: TextRange): T;
3047-
3048-
/**
3049-
* Gets the TextRange to use for source maps for a token of a node.
3050-
*/
3051-
getTokenSourceMapRange(node: Node, token: SyntaxKind): TextRange;
3052-
3053-
/**
3054-
* Sets the TextRange to use for source maps for a token of a node.
3055-
*/
3056-
setTokenSourceMapRange<T extends Node>(node: T, token: SyntaxKind, range: TextRange): T;
3057-
3058-
/**
3059-
* Gets the TextRange to use for comments for the node.
3060-
*/
3061-
getCommentRange(node: Node): TextRange;
3062-
3063-
/**
3064-
* Sets the TextRange to use for comments for the node.
3065-
*/
3066-
setCommentRange<T extends Node>(node: T, range: TextRange): T;
3067-
3068-
/**
3069-
* Hoists a function declaration to the containing scope.
3070-
*/
3071-
hoistFunctionDeclaration(node: FunctionDeclaration): void;
3072-
3073-
/**
3074-
* Hoists a variable declaration to the containing scope.
3075-
*/
3076-
hoistVariableDeclaration(node: Identifier): void;
3077-
3078-
/**
3079-
* Enables expression substitutions in the pretty printer for the provided SyntaxKind.
3080-
*/
3081-
enableSubstitution(kind: SyntaxKind): void;
3082-
3083-
/**
3084-
* Determines whether expression substitutions are enabled for the provided node.
3085-
*/
3086-
isSubstitutionEnabled(node: Node): boolean;
3087-
3088-
/**
3089-
* Hook used by transformers to substitute expressions just before they
3090-
* are emitted by the pretty printer.
3091-
*/
3092-
onSubstituteNode?: (node: Node, isExpression: boolean) => Node;
3093-
3094-
/**
3095-
* Enables before/after emit notifications in the pretty printer for the provided
3096-
* SyntaxKind.
3097-
*/
3098-
enableEmitNotification(kind: SyntaxKind): void;
3099-
3100-
/**
3101-
* Determines whether before/after emit notifications should be raised in the pretty
3102-
* printer when it emits a node.
3103-
*/
3104-
isEmitNotificationEnabled(node: Node): boolean;
3105-
3106-
/**
3107-
* Hook used to allow transformers to capture state before or after
3108-
* the printer emits a node.
3109-
*/
3110-
onEmitNode?: (node: Node, emit: (node: Node) => void) => void;
3111-
}
3112-
3113-
/* @internal */
3114-
export type Transformer = (context: TransformationContext) => (node: SourceFile) => SourceFile;
31153022

31163023
export interface TextSpan {
31173024
start: number;

src/compiler/utilities.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,18 +226,6 @@ namespace ts {
226226
return `${ file.fileName }(${ loc.line + 1 },${ loc.character + 1 })`;
227227
}
228228

229-
export function getEnvironmentVariable(name: string, host?: CompilerHost) {
230-
if (host && host.getEnvironmentVariable) {
231-
return host.getEnvironmentVariable(name);
232-
}
233-
234-
if (sys && sys.getEnvironmentVariable) {
235-
return sys.getEnvironmentVariable(name);
236-
}
237-
238-
return "";
239-
}
240-
241229
export function getStartPosOfNode(node: Node): number {
242230
return node.pos;
243231
}

0 commit comments

Comments
 (0)