Skip to content

Commit 3e85de5

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

13 files changed

+122
-93
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
mapDefined, MappedSymbol, MappedType, MappedTypeNode, MatchingKeys, maybeBind, MemberName, MemberOverrideStatus,
156156
memoize, MetaProperty, MethodDeclaration, MethodSignature, minAndMax, MinusToken, Modifier, ModifierFlags,
157157
modifiersToFlags, modifierToFlag, ModuleBlock, ModuleDeclaration, ModuleInstanceState, ModuleKind,
158-
ModuleResolutionKind, moduleSpecifiers, NamedDeclaration, NamedExports, NamedImportsOrExports, NamedTupleMember,
158+
ModuleResolutionKind, NamedDeclaration, NamedExports, NamedImportsOrExports, NamedTupleMember,
159159
NamespaceDeclaration, NamespaceExport, NamespaceExportDeclaration, NamespaceImport, needsScopeMarker, NewExpression,
160160
Node, NodeArray, NodeBuilderFlags, nodeCanBeDecorated, NodeCheckFlags, NodeFlags, nodeHasName, nodeIsDecorated,
161161
nodeIsMissing, nodeIsPresent, nodeIsSynthesized, NodeLinks, nodeStartsNewLexicalEnvironment, NodeWithTypeArguments,
@@ -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;
@@ -42559,10 +42561,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4255942561

4256042562
function checkSourceFile(node: SourceFile) {
4256142563
tracing?.push(tracing.Phase.Check, "checkSourceFile", { path: node.path }, /*separateBeginAndEnd*/ true);
42562-
ts.performance.mark("beforeCheck");
42564+
performance.mark("beforeCheck");
4256342565
checkSourceFileWorker(node);
42564-
ts.performance.mark("afterCheck");
42565-
ts.performance.measure("Check", "beforeCheck", "afterCheck");
42566+
performance.mark("afterCheck");
42567+
performance.measure("Check", "beforeCheck", "afterCheck");
4256642568
tracing?.pop();
4256742569
}
4256842570

Diff for: src/compiler/emitter.ts

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

8384
const brackets = createBracketsMap();
8485

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

@@ -1024,7 +1025,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
10241025
let commentsDisabled = !!printerOptions.removeComments;
10251026
let lastSubstitution: Node | undefined;
10261027
let currentParenthesizerRule: ((node: Node) => Node) | undefined;
1027-
const { enter: enterComment, exit: exitComment } = ts.performance.createTimerIf(extendedDiagnostics, "commentTime", "beforeComment", "afterComment");
1028+
const { enter: enterComment, exit: exitComment } = performance.createTimerIf(extendedDiagnostics, "commentTime", "beforeComment", "afterComment");
10281029
const parenthesizer = factory.parenthesizer;
10291030
const typeArgumentParenthesizerRuleSelector: OrdinalParentheizerRuleSelector<Node> = {
10301031
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
@@ -60,6 +60,7 @@ import {
6060
VariableStatement, walkUpParenthesizedExpressions, WriteFileCallback, WriteFileCallbackData,
6161
writeFileEnsuringDirectories, zipToModeAwareCache,
6262
} from "./_namespaces/ts";
63+
import * as performance from "./_namespaces/ts.performance";
6364

6465
export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName = "tsconfig.json"): string | undefined {
6566
return forEachAncestorDirectory(searchPath, ancestor => {
@@ -133,10 +134,10 @@ export function createGetSourceFile(
133134
return (fileName, languageVersionOrOptions, onError) => {
134135
let text: string | undefined;
135136
try {
136-
ts.performance.mark("beforeIORead");
137+
performance.mark("beforeIORead");
137138
text = readFile(fileName, getCompilerOptions().charset);
138-
ts.performance.mark("afterIORead");
139-
ts.performance.measure("I/O Read", "beforeIORead", "afterIORead");
139+
performance.mark("afterIORead");
140+
performance.measure("I/O Read", "beforeIORead", "afterIORead");
140141
}
141142
catch (e) {
142143
if (onError) {
@@ -156,7 +157,7 @@ export function createWriteFileMeasuringIO(
156157
): CompilerHost["writeFile"] {
157158
return (fileName, data, writeByteOrderMark, onError) => {
158159
try {
159-
ts.performance.mark("beforeIOWrite");
160+
performance.mark("beforeIOWrite");
160161

161162
// NOTE: If patchWriteFileEnsuringDirectory has been called,
162163
// the system.writeFile will do its own directory creation and
@@ -170,8 +171,8 @@ export function createWriteFileMeasuringIO(
170171
directoryExists
171172
);
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) {
@@ -1142,7 +1143,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
11421143
const sourceFilesFoundSearchingNodeModules = new Map<string, boolean>();
11431144

11441145
tracing?.push(tracing.Phase.Program, "createProgram", { configFilePath: options.configFilePath, rootDir: options.rootDir }, /*separateBeginAndEnd*/ true);
1145-
ts.performance.mark("beforeProgram");
1146+
performance.mark("beforeProgram");
11461147

11471148
const host = createProgramOptions.host || createCompilerHost(options);
11481149
const configParsingHost = parseConfigHostFromCompilerHostLike(host);
@@ -1448,8 +1449,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
14481449
});
14491450

14501451
verifyCompilerOptions();
1451-
ts.performance.mark("afterProgram");
1452-
ts.performance.measure("Program", "beforeProgram", "afterProgram");
1452+
performance.mark("afterProgram");
1453+
performance.measure("Program", "beforeProgram", "afterProgram");
14531454
tracing?.pop();
14541455

14551456
return program;
@@ -1489,10 +1490,10 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
14891490
const containingFileName = getNormalizedAbsolutePath(containingFile.originalFileName, currentDirectory);
14901491
const redirectedReference = getRedirectReferenceForResolution(containingFile);
14911492
tracing?.push(tracing.Phase.Program, "resolveModuleNamesWorker", { containingFileName });
1492-
ts.performance.mark("beforeResolveModule");
1493+
performance.mark("beforeResolveModule");
14931494
const result = actualResolveModuleNamesWorker(moduleNames, containingFile, containingFileName, reusedNames, redirectedReference);
1494-
ts.performance.mark("afterResolveModule");
1495-
ts.performance.measure("ResolveModule", "beforeResolveModule", "afterResolveModule");
1495+
performance.mark("afterResolveModule");
1496+
performance.measure("ResolveModule", "beforeResolveModule", "afterResolveModule");
14961497
tracing?.pop();
14971498
pullDiagnosticsFromCache(moduleNames, containingFile);
14981499
return result;
@@ -1504,10 +1505,10 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
15041505
const redirectedReference = !isString(containingFile) ? getRedirectReferenceForResolution(containingFile) : undefined;
15051506
const containingFileMode = !isString(containingFile) ? containingFile.impliedNodeFormat : undefined;
15061507
tracing?.push(tracing.Phase.Program, "resolveTypeReferenceDirectiveNamesWorker", { containingFileName });
1507-
ts.performance.mark("beforeResolveTypeReference");
1508+
performance.mark("beforeResolveTypeReference");
15081509
const result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference, containingFileMode);
1509-
ts.performance.mark("afterResolveTypeReference");
1510-
ts.performance.measure("ResolveTypeReference", "beforeResolveTypeReference", "afterResolveTypeReference");
1510+
performance.mark("afterResolveTypeReference");
1511+
performance.measure("ResolveTypeReference", "beforeResolveTypeReference", "afterResolveTypeReference");
15111512
tracing?.pop();
15121513
return result;
15131514
}
@@ -2052,7 +2053,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
20522053
function emitBuildInfo(writeFileCallback?: WriteFileCallback): EmitResult {
20532054
Debug.assert(!outFile(options));
20542055
tracing?.push(tracing.Phase.Emit, "emitBuildInfo", {}, /*separateBeginAndEnd*/ true);
2055-
ts.performance.mark("beforeEmit");
2056+
performance.mark("beforeEmit");
20562057
const emitResult = emitFiles(
20572058
notImplementedResolver,
20582059
getEmitHost(writeFileCallback),
@@ -2062,8 +2063,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
20622063
/*onlyBuildInfo*/ true
20632064
);
20642065

2065-
ts.performance.mark("afterEmit");
2066-
ts.performance.measure("Emit", "beforeEmit", "afterEmit");
2066+
performance.mark("afterEmit");
2067+
performance.measure("Emit", "beforeEmit", "afterEmit");
20672068
tracing?.pop();
20682069
return emitResult;
20692070
}
@@ -2148,7 +2149,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
21482149
// checked is to not pass the file to getEmitResolver.
21492150
const emitResolver = getTypeChecker().getEmitResolver(outFile(options) ? undefined : sourceFile, cancellationToken);
21502151

2151-
ts.performance.mark("beforeEmit");
2152+
performance.mark("beforeEmit");
21522153

21532154
const emitResult = emitFiles(
21542155
emitResolver,
@@ -2160,8 +2161,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
21602161
forceDtsEmit
21612162
);
21622163

2163-
ts.performance.mark("afterEmit");
2164-
ts.performance.measure("Emit", "beforeEmit", "afterEmit");
2164+
performance.mark("afterEmit");
2165+
performance.measure("Emit", "beforeEmit", "afterEmit");
21652166
return emitResult;
21662167
}
21672168

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)