Skip to content

Commit f2b4185

Browse files
committed
Directly import namespaces for improved esbuild output
I should report this upstream, if I can manage to minimize this.
1 parent cd922a6 commit f2b4185

14 files changed

+134
-105
lines changed

Diff for: .eslintignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
**/node_modules/**
2-
/built/local/**
2+
/built/**
33
/tests/**
44
/lib/**
55
/src/lib/*.generated.d.ts

Diff for: src/.eslintrc.json

+23-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,21 @@
66
},
77
"rules": {
88
"@typescript-eslint/no-unnecessary-qualifier": "error",
9-
"@typescript-eslint/no-unnecessary-type-assertion": "error"
9+
"@typescript-eslint/no-unnecessary-type-assertion": "error",
10+
"no-restricted-globals": ["error",
11+
{ "name": "setTimeout" },
12+
{ "name": "clearTimeout" },
13+
{ "name": "setInterval" },
14+
{ "name": "clearInterval" },
15+
{ "name": "setImmediate" },
16+
{ "name": "clearImmediate" },
17+
{ "name": "performance" },
18+
{ "name": "Iterator" },
19+
{ "name": "Map" },
20+
{ "name": "ReadonlyMap" },
21+
{ "name": "Set" },
22+
{ "name": "ReadonlySet" }
23+
]
1024
},
1125
"overrides": [
1226
{
@@ -20,14 +34,21 @@
2034
"local/no-keywords": "off",
2135

2236
// eslint
23-
"no-var": "off"
37+
"no-var": "off",
38+
"no-restricted-globals": "off"
2439
}
2540
},
2641
{
2742
"files": ["lib/es2019.array.d.ts"],
2843
"rules": {
2944
"@typescript-eslint/array-type": "off"
3045
}
46+
},
47+
{
48+
"files": ["debug/**", "harness/**", "testRunner/**"],
49+
"rules": {
50+
"no-restricted-globals": "off"
51+
}
3152
}
3253
]
3354
}

Diff for: src/compiler/binder.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import * as ts from "./_namespaces/ts";
21
import {
32
__String, AccessExpression, addRelatedInfo, append, appendIfUnique, ArrayBindingElement, ArrayLiteralExpression,
43
ArrowFunction, AssignmentDeclarationKind, BinaryExpression, BinaryOperatorToken, BindableAccessExpression,
@@ -59,6 +58,7 @@ import {
5958
TypeLiteralNode, TypeOfExpression, TypeParameterDeclaration, unescapeLeadingUnderscores, unreachableCodeIsError,
6059
unusedLabelIsError, VariableDeclaration, WhileStatement, WithStatement,
6160
} from "./_namespaces/ts";
61+
import * as performance from "./_namespaces/ts.performance";
6262

6363
/** @internal */
6464
export const enum ModuleInstanceState {
@@ -236,12 +236,12 @@ const binder = createBinder();
236236

237237
/** @internal */
238238
export function bindSourceFile(file: SourceFile, options: CompilerOptions) {
239-
ts.performance.mark("beforeBind");
239+
performance.mark("beforeBind");
240240
perfLogger.logStartBindFile("" + file.fileName);
241241
binder(file, options);
242242
perfLogger.logStopBindFile();
243-
ts.performance.mark("afterBind");
244-
ts.performance.measure("Bind", "beforeBind", "afterBind");
243+
performance.mark("afterBind");
244+
performance.measure("Bind", "beforeBind", "afterBind");
245245
}
246246

247247
function createBinder(): (file: SourceFile, options: CompilerOptions) => void {

Diff for: src/compiler/checker.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ import {
155155
mangleScopedPackageName, map, Map, mapDefined, MappedSymbol, MappedType, MappedTypeNode, MatchingKeys, maybeBind,
156156
MemberName, MemberOverrideStatus, memoize, MetaProperty, MethodDeclaration, MethodSignature, minAndMax, MinusToken,
157157
Modifier, ModifierFlags, modifiersToFlags, modifierToFlag, ModuleBlock, ModuleDeclaration, ModuleInstanceState,
158-
ModuleKind, ModuleResolutionKind, moduleSpecifiers, NamedDeclaration, NamedExports, NamedImportsOrExports,
158+
ModuleKind, ModuleResolutionKind, NamedDeclaration, NamedExports, NamedImportsOrExports,
159159
NamedTupleMember, NamespaceDeclaration, NamespaceExport, NamespaceExportDeclaration, NamespaceImport,
160160
needsScopeMarker, NewExpression, Node, NodeArray, NodeBuilderFlags, nodeCanBeDecorated, NodeCheckFlags, NodeFlags,
161161
nodeHasName, nodeIsDecorated, nodeIsMissing, nodeIsPresent, nodeIsSynthesized, NodeLinks,
@@ -197,6 +197,8 @@ import {
197197
walkUpBindingElementsAndPatterns, walkUpParenthesizedExpressions, walkUpParenthesizedTypes,
198198
walkUpParenthesizedTypesAndGetParentAndChild, WhileStatement, WideningContext, WithStatement, YieldExpression,
199199
} from "./_namespaces/ts";
200+
import * as performance from "./_namespaces/ts.performance";
201+
import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers";
200202

201203
const ambientModuleSymbolRegex = /^".+"$/;
202204
const anon = "(anonymous)" as __String & string;
@@ -42595,10 +42597,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4259542597

4259642598
function checkSourceFile(node: SourceFile) {
4259742599
tracing?.push(tracing.Phase.Check, "checkSourceFile", { path: node.path }, /*separateBeginAndEnd*/ true);
42598-
ts.performance.mark("beforeCheck");
42600+
performance.mark("beforeCheck");
4259942601
checkSourceFileWorker(node);
42600-
ts.performance.mark("afterCheck");
42601-
ts.performance.measure("Check", "beforeCheck", "afterCheck");
42602+
performance.mark("afterCheck");
42603+
performance.measure("Check", "beforeCheck", "afterCheck");
4260242604
tracing?.pop();
4260342605
}
4260442606

Diff for: src/compiler/emitter.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ import {
7878
VariableDeclaration, VariableDeclarationList, VariableStatement, VoidExpression, WhileStatement, WithStatement,
7979
writeCommentRange, writeFile, WriteFileCallbackData, YieldExpression,
8080
} from "./_namespaces/ts";
81+
import * as performance from "./_namespaces/ts.performance";
8182

8283
const brackets = createBracketsMap();
8384

@@ -366,7 +367,7 @@ export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFi
366367
const emitterDiagnostics = createDiagnosticCollection();
367368
const newLine = getNewLineCharacter(compilerOptions, () => host.getNewLine());
368369
const writer = createTextWriter(newLine);
369-
const { enter, exit } = ts.performance.createTimer("printTime", "beforePrint", "afterPrint");
370+
const { enter, exit } = performance.createTimer("printTime", "beforePrint", "afterPrint");
370371
let bundleBuildInfo: BundleBuildInfo | undefined;
371372
let emitSkipped = false;
372373

@@ -1026,7 +1027,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
10261027
let commentsDisabled = !!printerOptions.removeComments;
10271028
let lastSubstitution: Node | undefined;
10281029
let currentParenthesizerRule: ((node: Node) => Node) | undefined;
1029-
const { enter: enterComment, exit: exitComment } = ts.performance.createTimerIf(extendedDiagnostics, "commentTime", "beforeComment", "afterComment");
1030+
const { enter: enterComment, exit: exitComment } = performance.createTimerIf(extendedDiagnostics, "commentTime", "beforeComment", "afterComment");
10301031
const parenthesizer = factory.parenthesizer;
10311032
const typeArgumentParenthesizerRuleSelector: OrdinalParentheizerRuleSelector<Node> = {
10321033
select: index => index === 0 ? parenthesizer.parenthesizeLeadingTypeArgument : undefined

Diff for: src/compiler/parser.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import {
6565
UnionOrIntersectionTypeNode, UnionTypeNode, UpdateExpression, VariableDeclaration, VariableDeclarationList,
6666
VariableStatement, VoidExpression, WhileStatement, WithStatement, YieldExpression,
6767
} from "./_namespaces/ts";
68+
import * as performance from "./_namespaces/ts.performance";
6869

6970
const enum SignatureFlags {
7071
None = 0,
@@ -1005,7 +1006,7 @@ function setExternalModuleIndicator(sourceFile: SourceFile) {
10051006

10061007
export function createSourceFile(fileName: string, sourceText: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, setParentNodes = false, scriptKind?: ScriptKind): SourceFile {
10071008
tracing?.push(tracing.Phase.Parse, "createSourceFile", { path: fileName }, /*separateBeginAndEnd*/ true);
1008-
ts.performance.mark("beforeParse");
1009+
performance.mark("beforeParse");
10091010
let result: SourceFile;
10101011

10111012
perfLogger.logStartParseSourceFile(fileName);
@@ -1026,8 +1027,8 @@ export function createSourceFile(fileName: string, sourceText: string, languageV
10261027
}
10271028
perfLogger.logStopParseSourceFile();
10281029

1029-
ts.performance.mark("afterParse");
1030-
ts.performance.measure("Parse", "beforeParse", "afterParse");
1030+
performance.mark("afterParse");
1031+
performance.measure("Parse", "beforeParse", "afterParse");
10311032
tracing?.pop();
10321033
return result;
10331034
}

Diff for: src/compiler/program.ts

+22-21
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
VariableStatement, walkUpParenthesizedExpressions, WriteFileCallback, WriteFileCallbackData,
6060
writeFileEnsuringDirectories, zipToModeAwareCache,
6161
} from "./_namespaces/ts";
62+
import * as performance from "./_namespaces/ts.performance";
6263

6364
export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName = "tsconfig.json"): string | undefined {
6465
return forEachAncestorDirectory(searchPath, ancestor => {
@@ -130,10 +131,10 @@ export function createCompilerHostWorker(options: CompilerOptions, setParentNode
130131
function getSourceFile(fileName: string, languageVersionOrOptions: ScriptTarget | CreateSourceFileOptions, onError?: (message: string) => void): SourceFile | undefined {
131132
let text: string | undefined;
132133
try {
133-
ts.performance.mark("beforeIORead");
134+
performance.mark("beforeIORead");
134135
text = compilerHost.readFile(fileName);
135-
ts.performance.mark("afterIORead");
136-
ts.performance.measure("I/O Read", "beforeIORead", "afterIORead");
136+
performance.mark("afterIORead");
137+
performance.measure("I/O Read", "beforeIORead", "afterIORead");
137138
}
138139
catch (e) {
139140
if (onError) {
@@ -157,7 +158,7 @@ export function createCompilerHostWorker(options: CompilerOptions, setParentNode
157158

158159
function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) {
159160
try {
160-
ts.performance.mark("beforeIOWrite");
161+
performance.mark("beforeIOWrite");
161162

162163
// NOTE: If patchWriteFileEnsuringDirectory has been called,
163164
// the system.writeFile will do its own directory creation and
@@ -170,8 +171,8 @@ export function createCompilerHostWorker(options: CompilerOptions, setParentNode
170171
path => (compilerHost.createDirectory || system.createDirectory)(path),
171172
path => directoryExists(path));
172173

173-
ts.performance.mark("afterIOWrite");
174-
ts.performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite");
174+
performance.mark("afterIOWrite");
175+
performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite");
175176
}
176177
catch (e) {
177178
if (onError) {
@@ -1118,7 +1119,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
11181119
const sourceFilesFoundSearchingNodeModules = new Map<string, boolean>();
11191120

11201121
tracing?.push(tracing.Phase.Program, "createProgram", { configFilePath: options.configFilePath, rootDir: options.rootDir }, /*separateBeginAndEnd*/ true);
1121-
ts.performance.mark("beforeProgram");
1122+
performance.mark("beforeProgram");
11221123

11231124
const host = createProgramOptions.host || createCompilerHost(options);
11241125
const configParsingHost = parseConfigHostFromCompilerHostLike(host);
@@ -1424,8 +1425,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
14241425
});
14251426

14261427
verifyCompilerOptions();
1427-
ts.performance.mark("afterProgram");
1428-
ts.performance.measure("Program", "beforeProgram", "afterProgram");
1428+
performance.mark("afterProgram");
1429+
performance.measure("Program", "beforeProgram", "afterProgram");
14291430
tracing?.pop();
14301431

14311432
return program;
@@ -1465,10 +1466,10 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
14651466
const containingFileName = getNormalizedAbsolutePath(containingFile.originalFileName, currentDirectory);
14661467
const redirectedReference = getRedirectReferenceForResolution(containingFile);
14671468
tracing?.push(tracing.Phase.Program, "resolveModuleNamesWorker", { containingFileName });
1468-
ts.performance.mark("beforeResolveModule");
1469+
performance.mark("beforeResolveModule");
14691470
const result = actualResolveModuleNamesWorker(moduleNames, containingFile, containingFileName, reusedNames, redirectedReference);
1470-
ts.performance.mark("afterResolveModule");
1471-
ts.performance.measure("ResolveModule", "beforeResolveModule", "afterResolveModule");
1471+
performance.mark("afterResolveModule");
1472+
performance.measure("ResolveModule", "beforeResolveModule", "afterResolveModule");
14721473
tracing?.pop();
14731474
pullDiagnosticsFromCache(moduleNames, containingFile);
14741475
return result;
@@ -1480,10 +1481,10 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
14801481
const redirectedReference = !isString(containingFile) ? getRedirectReferenceForResolution(containingFile) : undefined;
14811482
const containingFileMode = !isString(containingFile) ? containingFile.impliedNodeFormat : undefined;
14821483
tracing?.push(tracing.Phase.Program, "resolveTypeReferenceDirectiveNamesWorker", { containingFileName });
1483-
ts.performance.mark("beforeResolveTypeReference");
1484+
performance.mark("beforeResolveTypeReference");
14841485
const result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference, containingFileMode);
1485-
ts.performance.mark("afterResolveTypeReference");
1486-
ts.performance.measure("ResolveTypeReference", "beforeResolveTypeReference", "afterResolveTypeReference");
1486+
performance.mark("afterResolveTypeReference");
1487+
performance.measure("ResolveTypeReference", "beforeResolveTypeReference", "afterResolveTypeReference");
14871488
tracing?.pop();
14881489
return result;
14891490
}
@@ -2028,7 +2029,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
20282029
function emitBuildInfo(writeFileCallback?: WriteFileCallback): EmitResult {
20292030
Debug.assert(!outFile(options));
20302031
tracing?.push(tracing.Phase.Emit, "emitBuildInfo", {}, /*separateBeginAndEnd*/ true);
2031-
ts.performance.mark("beforeEmit");
2032+
performance.mark("beforeEmit");
20322033
const emitResult = emitFiles(
20332034
notImplementedResolver,
20342035
getEmitHost(writeFileCallback),
@@ -2038,8 +2039,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
20382039
/*onlyBuildInfo*/ true
20392040
);
20402041

2041-
ts.performance.mark("afterEmit");
2042-
ts.performance.measure("Emit", "beforeEmit", "afterEmit");
2042+
performance.mark("afterEmit");
2043+
performance.measure("Emit", "beforeEmit", "afterEmit");
20432044
tracing?.pop();
20442045
return emitResult;
20452046
}
@@ -2123,7 +2124,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
21232124
// checked is to not pass the file to getEmitResolver.
21242125
const emitResolver = getTypeChecker().getEmitResolver(outFile(options) ? undefined : sourceFile, cancellationToken);
21252126

2126-
ts.performance.mark("beforeEmit");
2127+
performance.mark("beforeEmit");
21272128

21282129
const emitResult = emitFiles(
21292130
emitResolver,
@@ -2135,8 +2136,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
21352136
forceDtsEmit
21362137
);
21372138

2138-
ts.performance.mark("afterEmit");
2139-
ts.performance.measure("Emit", "beforeEmit", "afterEmit");
2139+
performance.mark("afterEmit");
2140+
performance.measure("Emit", "beforeEmit", "afterEmit");
21402141
return emitResult;
21412142
}
21422143

Diff for: src/compiler/sourcemap.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import * as ts from "./_namespaces/ts";
21
import {
32
arrayFrom, binarySearchKey, CharacterCodes, combinePaths, compareValues, Debug, DocumentPosition,
43
DocumentPositionMapper, DocumentPositionMapperHost, EmitHost, emptyArray, ESMap, every, getDirectoryPath,
54
getNormalizedAbsolutePath, getPositionOfLineAndCharacter, getRelativePathToDirectoryOrUrl, identity, isArray,
65
isString, Iterator, LineAndCharacter, Map, RawSourceMap, some, sortAndDeduplicate, SortedReadonlyArray,
76
SourceMapGenerator, trimStringEnd,
87
} from "./_namespaces/ts";
8+
import * as performance from "./_namespaces/ts.performance";
99

1010
/** @internal */
1111
export interface SourceMapGeneratorOptions {
@@ -15,8 +15,8 @@ export interface SourceMapGeneratorOptions {
1515
/** @internal */
1616
export function createSourceMapGenerator(host: EmitHost, file: string, sourceRoot: string, sourcesDirectoryPath: string, generatorOptions: SourceMapGeneratorOptions): SourceMapGenerator {
1717
const { enter, exit } = generatorOptions.extendedDiagnostics
18-
? ts.performance.createTimer("Source Map", "beforeSourcemap", "afterSourcemap")
19-
: ts.performance.nullTimer;
18+
? performance.createTimer("Source Map", "beforeSourcemap", "afterSourcemap")
19+
: performance.nullTimer;
2020

2121
// Current source map file and its index in the sources list
2222
const rawSources: string[] = [];

Diff for: src/compiler/tracing.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import * as ts from "./_namespaces/ts";
21
import {
32
combinePaths, ConditionalType, Debug, EvolvingArrayType, getLineAndCharacterOfPosition, getSourceFileOfNode,
43
IndexedAccessType, IndexType, IntersectionType, LineAndCharacter, Map, Node, ObjectFlags, Path, ReverseMappedType,
54
SubstitutionType, timestamp, Type, TypeFlags, TypeReference, unescapeLeadingUnderscores, UnionType,
65
} from "./_namespaces/ts";
6+
import * as performance from "./_namespaces/ts.performance";
77

88
/* Tracing events for the compiler. */
99

@@ -172,13 +172,13 @@ export namespace tracingEnabled {
172172
// In server mode, there's no easy way to dump type information, so we drop events that would require it.
173173
if (mode === "server" && phase === Phase.CheckTypes) return;
174174

175-
ts.performance.mark("beginTracing");
175+
performance.mark("beginTracing");
176176
fs.writeSync(traceFd, `,\n{"pid":1,"tid":1,"ph":"${eventType}","cat":"${phase}","ts":${time},"name":"${name}"`);
177177
if (extras) fs.writeSync(traceFd, `,${extras}`);
178178
if (args) fs.writeSync(traceFd, `,"args":${JSON.stringify(args)}`);
179179
fs.writeSync(traceFd, `}`);
180-
ts.performance.mark("endTracing");
181-
ts.performance.measure("Tracing", "beginTracing", "endTracing");
180+
performance.mark("endTracing");
181+
performance.measure("Tracing", "beginTracing", "endTracing");
182182
}
183183

184184
function getLocation(node: Node | undefined) {
@@ -200,7 +200,7 @@ export namespace tracingEnabled {
200200
}
201201

202202
function dumpTypes(types: readonly Type[]) {
203-
ts.performance.mark("beginDumpTypes");
203+
performance.mark("beginDumpTypes");
204204

205205
const typesPath = legend[legend.length - 1].typesPath!;
206206
const typesFd = fs.openSync(typesPath, "w");
@@ -329,8 +329,8 @@ export namespace tracingEnabled {
329329

330330
fs.closeSync(typesFd);
331331

332-
ts.performance.mark("endDumpTypes");
333-
ts.performance.measure("Dump types", "beginDumpTypes", "endDumpTypes");
332+
performance.mark("endDumpTypes");
333+
performance.measure("Dump types", "beginDumpTypes", "endDumpTypes");
334334
}
335335

336336
export function dumpLegend() {

0 commit comments

Comments
 (0)