Skip to content

Directly import namespaces for improved esbuild output #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
**/node_modules/**
/built/local/**
/built/**
/tests/**
/lib/**
/src/lib/*.generated.d.ts
Expand Down
25 changes: 23 additions & 2 deletions src/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@
},
"rules": {
"@typescript-eslint/no-unnecessary-qualifier": "error",
"@typescript-eslint/no-unnecessary-type-assertion": "error"
"@typescript-eslint/no-unnecessary-type-assertion": "error",
"no-restricted-globals": ["error",
{ "name": "setTimeout" },
{ "name": "clearTimeout" },
{ "name": "setInterval" },
{ "name": "clearInterval" },
{ "name": "setImmediate" },
{ "name": "clearImmediate" },
{ "name": "performance" },
{ "name": "Iterator" },
{ "name": "Map" },
{ "name": "ReadonlyMap" },
{ "name": "Set" },
{ "name": "ReadonlySet" }
]
},
"overrides": [
{
Expand All @@ -20,14 +34,21 @@
"local/no-keywords": "off",

// eslint
"no-var": "off"
"no-var": "off",
"no-restricted-globals": "off"
}
},
{
"files": ["lib/es2019.array.d.ts"],
"rules": {
"@typescript-eslint/array-type": "off"
}
},
{
"files": ["debug/**", "harness/**", "testRunner/**"],
"rules": {
"no-restricted-globals": "off"
}
}
]
}
8 changes: 4 additions & 4 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as ts from "./_namespaces/ts";
import {
__String, AccessExpression, addRelatedInfo, append, appendIfUnique, ArrayBindingElement, ArrayLiteralExpression,
ArrowFunction, AssignmentDeclarationKind, BinaryExpression, BinaryOperatorToken, BindableAccessExpression,
Expand Down Expand Up @@ -59,6 +58,7 @@ import {
TypeLiteralNode, TypeOfExpression, TypeParameterDeclaration, unescapeLeadingUnderscores, unreachableCodeIsError,
unusedLabelIsError, VariableDeclaration, WhileStatement, WithStatement,
} from "./_namespaces/ts";
import * as performance from "./_namespaces/ts.performance";

/** @internal */
export const enum ModuleInstanceState {
Expand Down Expand Up @@ -236,12 +236,12 @@ const binder = createBinder();

/** @internal */
export function bindSourceFile(file: SourceFile, options: CompilerOptions) {
ts.performance.mark("beforeBind");
performance.mark("beforeBind");
perfLogger.logStartBindFile("" + file.fileName);
binder(file, options);
perfLogger.logStopBindFile();
ts.performance.mark("afterBind");
ts.performance.measure("Bind", "beforeBind", "afterBind");
performance.mark("afterBind");
performance.measure("Bind", "beforeBind", "afterBind");
}

function createBinder(): (file: SourceFile, options: CompilerOptions) => void {
Expand Down
10 changes: 6 additions & 4 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ import {
mapDefined, MappedSymbol, MappedType, MappedTypeNode, MatchingKeys, maybeBind, MemberName, MemberOverrideStatus,
memoize, MetaProperty, MethodDeclaration, MethodSignature, minAndMax, MinusToken, Modifier, ModifierFlags,
modifiersToFlags, modifierToFlag, ModuleBlock, ModuleDeclaration, ModuleInstanceState, ModuleKind,
ModuleResolutionKind, moduleSpecifiers, NamedDeclaration, NamedExports, NamedImportsOrExports, NamedTupleMember,
ModuleResolutionKind, NamedDeclaration, NamedExports, NamedImportsOrExports, NamedTupleMember,
NamespaceDeclaration, NamespaceExport, NamespaceExportDeclaration, NamespaceImport, needsScopeMarker, NewExpression,
Node, NodeArray, NodeBuilderFlags, nodeCanBeDecorated, NodeCheckFlags, NodeFlags, nodeHasName, nodeIsDecorated,
nodeIsMissing, nodeIsPresent, nodeIsSynthesized, NodeLinks, nodeStartsNewLexicalEnvironment, NodeWithTypeArguments,
Expand Down Expand Up @@ -197,6 +197,8 @@ import {
walkUpBindingElementsAndPatterns, walkUpParenthesizedExpressions, walkUpParenthesizedTypes,
walkUpParenthesizedTypesAndGetParentAndChild, WhileStatement, WideningContext, WithStatement, YieldExpression,
} from "./_namespaces/ts";
import * as performance from "./_namespaces/ts.performance";
import * as moduleSpecifiers from "./_namespaces/ts.moduleSpecifiers";

const ambientModuleSymbolRegex = /^".+"$/;
const anon = "(anonymous)" as __String & string;
Expand Down Expand Up @@ -42552,10 +42554,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {

function checkSourceFile(node: SourceFile) {
tracing?.push(tracing.Phase.Check, "checkSourceFile", { path: node.path }, /*separateBeginAndEnd*/ true);
ts.performance.mark("beforeCheck");
performance.mark("beforeCheck");
checkSourceFileWorker(node);
ts.performance.mark("afterCheck");
ts.performance.measure("Check", "beforeCheck", "afterCheck");
performance.mark("afterCheck");
performance.measure("Check", "beforeCheck", "afterCheck");
tracing?.pop();
}

Expand Down
5 changes: 3 additions & 2 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import {
VariableDeclaration, VariableDeclarationList, VariableStatement, VoidExpression, WhileStatement, WithStatement,
writeCommentRange, writeFile, WriteFileCallbackData, YieldExpression,
} from "./_namespaces/ts";
import * as performance from "./_namespaces/ts.performance";

const brackets = createBracketsMap();

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

Expand Down Expand Up @@ -1030,7 +1031,7 @@ export function createPrinter(printerOptions: PrinterOptions = {}, handlers: Pri
let commentsDisabled = !!printerOptions.removeComments;
let lastSubstitution: Node | undefined;
let currentParenthesizerRule: ((node: Node) => Node) | undefined;
const { enter: enterComment, exit: exitComment } = ts.performance.createTimerIf(extendedDiagnostics, "commentTime", "beforeComment", "afterComment");
const { enter: enterComment, exit: exitComment } = performance.createTimerIf(extendedDiagnostics, "commentTime", "beforeComment", "afterComment");
const parenthesizer = factory.parenthesizer;
const typeArgumentParenthesizerRuleSelector: OrdinalParentheizerRuleSelector<Node> = {
select: index => index === 0 ? parenthesizer.parenthesizeLeadingTypeArgument : undefined
Expand Down
7 changes: 4 additions & 3 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
UnionOrIntersectionTypeNode, UnionTypeNode, UpdateExpression, VariableDeclaration, VariableDeclarationList,
VariableStatement, VoidExpression, WhileStatement, WithStatement, YieldExpression,
} from "./_namespaces/ts";
import * as performance from "./_namespaces/ts.performance";

const enum SignatureFlags {
None = 0,
Expand Down Expand Up @@ -1005,7 +1006,7 @@ function setExternalModuleIndicator(sourceFile: SourceFile) {

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

perfLogger.logStartParseSourceFile(fileName);
Expand All @@ -1026,8 +1027,8 @@ export function createSourceFile(fileName: string, sourceText: string, languageV
}
perfLogger.logStopParseSourceFile();

ts.performance.mark("afterParse");
ts.performance.measure("Parse", "beforeParse", "afterParse");
performance.mark("afterParse");
performance.measure("Parse", "beforeParse", "afterParse");
tracing?.pop();
return result;
}
Expand Down
43 changes: 22 additions & 21 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ import {
VariableStatement, walkUpParenthesizedExpressions, WriteFileCallback, WriteFileCallbackData,
writeFileEnsuringDirectories, zipToModeAwareCache,
} from "./_namespaces/ts";
import * as performance from "./_namespaces/ts.performance";

export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName = "tsconfig.json"): string | undefined {
return forEachAncestorDirectory(searchPath, ancestor => {
Expand Down Expand Up @@ -133,10 +134,10 @@ export function createGetSourceFile(
return (fileName, languageVersionOrOptions, onError) => {
let text: string | undefined;
try {
ts.performance.mark("beforeIORead");
performance.mark("beforeIORead");
text = readFile(fileName, getCompilerOptions().charset);
ts.performance.mark("afterIORead");
ts.performance.measure("I/O Read", "beforeIORead", "afterIORead");
performance.mark("afterIORead");
performance.measure("I/O Read", "beforeIORead", "afterIORead");
}
catch (e) {
if (onError) {
Expand All @@ -156,7 +157,7 @@ export function createWriteFileMeasuringIO(
): CompilerHost["writeFile"] {
return (fileName, data, writeByteOrderMark, onError) => {
try {
ts.performance.mark("beforeIOWrite");
performance.mark("beforeIOWrite");

// NOTE: If patchWriteFileEnsuringDirectory has been called,
// the system.writeFile will do its own directory creation and
Expand All @@ -170,8 +171,8 @@ export function createWriteFileMeasuringIO(
directoryExists
);

ts.performance.mark("afterIOWrite");
ts.performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite");
performance.mark("afterIOWrite");
performance.measure("I/O Write", "beforeIOWrite", "afterIOWrite");
}
catch (e) {
if (onError) {
Expand Down Expand Up @@ -1145,7 +1146,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
const sourceFilesFoundSearchingNodeModules = new Map<string, boolean>();

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

const host = createProgramOptions.host || createCompilerHost(options);
const configParsingHost = parseConfigHostFromCompilerHostLike(host);
Expand Down Expand Up @@ -1468,8 +1469,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
});

verifyCompilerOptions();
ts.performance.mark("afterProgram");
ts.performance.measure("Program", "beforeProgram", "afterProgram");
performance.mark("afterProgram");
performance.measure("Program", "beforeProgram", "afterProgram");
tracing?.pop();

return program;
Expand Down Expand Up @@ -1506,10 +1507,10 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
const containingFileName = getNormalizedAbsolutePath(containingFile.originalFileName, currentDirectory);
const redirectedReference = getRedirectReferenceForResolution(containingFile);
tracing?.push(tracing.Phase.Program, "resolveModuleNamesWorker", { containingFileName });
ts.performance.mark("beforeResolveModule");
performance.mark("beforeResolveModule");
const result = actualResolveModuleNamesWorker(moduleNames, containingFile, containingFileName, redirectedReference, resolutionInfo);
ts.performance.mark("afterResolveModule");
ts.performance.measure("ResolveModule", "beforeResolveModule", "afterResolveModule");
performance.mark("afterResolveModule");
performance.measure("ResolveModule", "beforeResolveModule", "afterResolveModule");
tracing?.pop();
pullDiagnosticsFromCache(moduleNames, containingFile);
return result;
Expand All @@ -1521,10 +1522,10 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
const redirectedReference = !isString(containingFile) ? getRedirectReferenceForResolution(containingFile) : undefined;
const containingFileMode = !isString(containingFile) ? containingFile.impliedNodeFormat : undefined;
tracing?.push(tracing.Phase.Program, "resolveTypeReferenceDirectiveNamesWorker", { containingFileName });
ts.performance.mark("beforeResolveTypeReference");
performance.mark("beforeResolveTypeReference");
const result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference, containingFileMode);
ts.performance.mark("afterResolveTypeReference");
ts.performance.measure("ResolveTypeReference", "beforeResolveTypeReference", "afterResolveTypeReference");
performance.mark("afterResolveTypeReference");
performance.measure("ResolveTypeReference", "beforeResolveTypeReference", "afterResolveTypeReference");
tracing?.pop();
return result;
}
Expand Down Expand Up @@ -2067,7 +2068,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
function emitBuildInfo(writeFileCallback?: WriteFileCallback): EmitResult {
Debug.assert(!outFile(options));
tracing?.push(tracing.Phase.Emit, "emitBuildInfo", {}, /*separateBeginAndEnd*/ true);
ts.performance.mark("beforeEmit");
performance.mark("beforeEmit");
const emitResult = emitFiles(
notImplementedResolver,
getEmitHost(writeFileCallback),
Expand All @@ -2077,8 +2078,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
/*onlyBuildInfo*/ true
);

ts.performance.mark("afterEmit");
ts.performance.measure("Emit", "beforeEmit", "afterEmit");
performance.mark("afterEmit");
performance.measure("Emit", "beforeEmit", "afterEmit");
tracing?.pop();
return emitResult;
}
Expand Down Expand Up @@ -2163,7 +2164,7 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
// checked is to not pass the file to getEmitResolver.
const emitResolver = getTypeChecker().getEmitResolver(outFile(options) ? undefined : sourceFile, cancellationToken);

ts.performance.mark("beforeEmit");
performance.mark("beforeEmit");

const emitResult = emitFiles(
emitResolver,
Expand All @@ -2175,8 +2176,8 @@ export function createProgram(rootNamesOrOptions: readonly string[] | CreateProg
forceDtsEmit
);

ts.performance.mark("afterEmit");
ts.performance.measure("Emit", "beforeEmit", "afterEmit");
performance.mark("afterEmit");
performance.measure("Emit", "beforeEmit", "afterEmit");
return emitResult;
}

Expand Down
6 changes: 3 additions & 3 deletions src/compiler/sourcemap.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as ts from "./_namespaces/ts";
import {
arrayFrom, binarySearchKey, CharacterCodes, combinePaths, compareValues, Debug, DocumentPosition,
DocumentPositionMapper, DocumentPositionMapperHost, EmitHost, emptyArray, ESMap, every, getDirectoryPath,
getNormalizedAbsolutePath, getPositionOfLineAndCharacter, getRelativePathToDirectoryOrUrl, identity, isArray,
isString, Iterator, LineAndCharacter, Map, RawSourceMap, some, sortAndDeduplicate, SortedReadonlyArray,
SourceMapGenerator, trimStringEnd,
} from "./_namespaces/ts";
import * as performance from "./_namespaces/ts.performance";

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

// Current source map file and its index in the sources list
const rawSources: string[] = [];
Expand Down
14 changes: 7 additions & 7 deletions src/compiler/tracing.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as ts from "./_namespaces/ts";
import {
combinePaths, ConditionalType, Debug, EvolvingArrayType, getLineAndCharacterOfPosition, getSourceFileOfNode,
IndexedAccessType, IndexType, IntersectionType, LineAndCharacter, Map, Node, ObjectFlags, Path, ReverseMappedType,
SubstitutionType, timestamp, Type, TypeFlags, TypeReference, unescapeLeadingUnderscores, UnionType,
} from "./_namespaces/ts";
import * as performance from "./_namespaces/ts.performance";

/* Tracing events for the compiler. */

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

ts.performance.mark("beginTracing");
performance.mark("beginTracing");
fs.writeSync(traceFd, `,\n{"pid":1,"tid":1,"ph":"${eventType}","cat":"${phase}","ts":${time},"name":"${name}"`);
if (extras) fs.writeSync(traceFd, `,${extras}`);
if (args) fs.writeSync(traceFd, `,"args":${JSON.stringify(args)}`);
fs.writeSync(traceFd, `}`);
ts.performance.mark("endTracing");
ts.performance.measure("Tracing", "beginTracing", "endTracing");
performance.mark("endTracing");
performance.measure("Tracing", "beginTracing", "endTracing");
}

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

function dumpTypes(types: readonly Type[]) {
ts.performance.mark("beginDumpTypes");
performance.mark("beginDumpTypes");

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

fs.closeSync(typesFd);

ts.performance.mark("endDumpTypes");
ts.performance.measure("Dump types", "beginDumpTypes", "endDumpTypes");
performance.mark("endDumpTypes");
performance.measure("Dump types", "beginDumpTypes", "endDumpTypes");
}

export function dumpLegend() {
Expand Down
Loading