Skip to content

Commit c9d5bf0

Browse files
committed
CONVERSION STEP - stripNamespaces
This step converts each file into an exported module by hoisting the namespace bodies into the global scope and transferring internal markers down onto declarations as needed. The namespaces are reconstructed as "barrel"-style modules, which are identical to the old namespace objects in structure. These reconstructed namespaces are then imported in the newly module-ified files, making existing expressions like "ts." valid.
1 parent 0eb75ad commit c9d5bf0

File tree

562 files changed

+4362
-1214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

562 files changed

+4362
-1214
lines changed

Diff for: src/compiler/_namespaces/ts.moduleSpecifiers.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* Generated file to emulate the ts.moduleSpecifiers namespace. */
2+
export * from "../moduleSpecifiers";

Diff for: src/compiler/_namespaces/ts.performance.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/* Generated file to emulate the ts.performance namespace. */
2+
export * from "../performance";

Diff for: src/compiler/_namespaces/ts.ts

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/* Generated file to emulate the ts namespace. */
2+
export * from "../../shims/_namespaces/ts";
3+
export * from "../binder";
4+
export * from "../builder";
5+
export * from "../builderPublic";
6+
export * from "../builderState";
7+
export * from "../builderStatePublic";
8+
export * from "../checker";
9+
export * from "../commandLineParser";
10+
export * from "../core";
11+
export * from "../corePublic";
12+
export * from "../debug";
13+
export * from "../diagnosticInformationMap.generated";
14+
export * from "../emitter";
15+
export * from "../moduleNameResolver";
16+
export * from "../parser";
17+
export * from "../path";
18+
export * from "../perfLogger";
19+
export * from "../performanceCore";
20+
export * from "../program";
21+
export * from "../resolutionCache";
22+
export * from "../scanner";
23+
export * from "../semver";
24+
export * from "../sourcemap";
25+
export * from "../symbolWalker";
26+
export * from "../sys";
27+
export * from "../tracing";
28+
export * from "../transformer";
29+
export * from "../tsbuild";
30+
export * from "../tsbuildPublic";
31+
export * from "../types";
32+
export * from "../utilities";
33+
export * from "../utilitiesPublic";
34+
export * from "../visitorPublic";
35+
export * from "../watch";
36+
export * from "../watchPublic";
37+
export * from "../watchUtilities";
38+
export * from "../factory/baseNodeFactory";
39+
export * from "../factory/emitHelpers";
40+
export * from "../factory/emitNode";
41+
export * from "../factory/nodeConverters";
42+
export * from "../factory/nodeFactory";
43+
export * from "../factory/nodeTests";
44+
export * from "../factory/parenthesizerRules";
45+
export * from "../factory/utilities";
46+
export * from "../factory/utilitiesPublic";
47+
export * from "../transformers/classFields";
48+
export * from "../transformers/declarations";
49+
export * from "../transformers/destructuring";
50+
export * from "../transformers/es2015";
51+
export * from "../transformers/es2016";
52+
export * from "../transformers/es2017";
53+
export * from "../transformers/es2018";
54+
export * from "../transformers/es2019";
55+
export * from "../transformers/es2020";
56+
export * from "../transformers/es2021";
57+
export * from "../transformers/es5";
58+
export * from "../transformers/esnext";
59+
export * from "../transformers/generators";
60+
export * from "../transformers/jsx";
61+
export * from "../transformers/taggedTemplate";
62+
export * from "../transformers/ts";
63+
export * from "../transformers/utilities";
64+
export * from "../transformers/declarations/diagnostics";
65+
export * from "../transformers/module/esnextAnd2015";
66+
export * from "../transformers/module/module";
67+
export * from "../transformers/module/node";
68+
export * from "../transformers/module/system";
69+
import * as moduleSpecifiers from "./ts.moduleSpecifiers";
70+
export { moduleSpecifiers };
71+
import * as performance from "./ts.performance";
72+
export { performance };

Diff for: src/compiler/binder.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import * as ts from "./_namespaces/ts";
12

23
/* @internal */
3-
namespace ts {
44
export const enum ModuleInstanceState {
55
NonInstantiated = 0,
66
Instantiated = 1,
@@ -15,6 +15,7 @@ interface ActiveLabel {
1515
referenced: boolean;
1616
}
1717

18+
/* @internal */
1819
export function getModuleInstanceState(node: ts.ModuleDeclaration, visited?: ts.ESMap<number, ModuleInstanceState | undefined>): ModuleInstanceState {
1920
if (node.body && !node.body.parent) {
2021
// getModuleInstanceStateForAliasTarget needs to walk up the parent chain, so parent pointers must be set on this tree already
@@ -173,6 +174,7 @@ function initFlowNode<T extends ts.FlowNode>(node: T) {
173174

174175
const binder = createBinder();
175176

177+
/* @internal */
176178
export function bindSourceFile(file: ts.SourceFile, options: ts.CompilerOptions) {
177179
ts.performance.mark("beforeBind");
178180
ts.perfLogger.logStartBindFile("" + file.fileName);
@@ -3502,6 +3504,7 @@ function isPurelyTypeDeclaration(s: ts.Statement): boolean {
35023504
}
35033505
}
35043506

3507+
/* @internal */
35053508
export function isExportsOrModuleExportsOrAlias(sourceFile: ts.SourceFile, node: ts.Expression): boolean {
35063509
let i = 0;
35073510
const q = [node];
@@ -3536,4 +3539,3 @@ function lookupSymbolForName(container: ts.Node, name: ts.__String): ts.Symbol |
35363539
}
35373540
return container.symbol && container.symbol.exports && container.symbol.exports.get(name);
35383541
}
3539-
}

Diff for: src/compiler/builder.ts

+25-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
/*@internal*/
2-
namespace ts {
1+
import * as ts from "./_namespaces/ts";
2+
3+
/* @internal */
34
export interface ReusableDiagnostic extends ReusableDiagnosticRelatedInformation {
45
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
56
reportsUnnecessary?: {};
@@ -9,6 +10,7 @@ export interface ReusableDiagnostic extends ReusableDiagnosticRelatedInformation
910
skippedOn?: keyof ts.CompilerOptions;
1011
}
1112

13+
/* @internal */
1214
export interface ReusableDiagnosticRelatedInformation {
1315
category: ts.DiagnosticCategory;
1416
code: number;
@@ -18,8 +20,10 @@ export interface ReusableDiagnosticRelatedInformation {
1820
messageText: string | ReusableDiagnosticMessageChain;
1921
}
2022

23+
/* @internal */
2124
export type ReusableDiagnosticMessageChain = ts.DiagnosticMessageChain;
2225

26+
/* @internal */
2327
export interface ReusableBuilderProgramState extends ts.ReusableBuilderState {
2428
/**
2529
* Cache of bind and check diagnostics for files with their Path being the key
@@ -76,11 +80,13 @@ export interface ReusableBuilderProgramState extends ts.ReusableBuilderState {
7680
hasReusableDiagnostic?: true;
7781
}
7882

83+
/* @internal */
7984
export const enum BuilderFileEmit {
8085
DtsOnly,
8186
Full
8287
}
8388

89+
/* @internal */
8490
/**
8591
* State to store the changed files, affected files and cache semantic diagnostics
8692
*/
@@ -773,11 +779,17 @@ function getBinderAndCheckerDiagnosticsOfFile(state: BuilderProgramState, source
773779
return ts.filterSemanticDiagnostics(diagnostics, state.compilerOptions);
774780
}
775781

782+
/* @internal */
776783
export type ProgramBuildInfoFileId = number & { __programBuildInfoFileIdBrand: any };
784+
/* @internal */
777785
export type ProgramBuildInfoFileIdListId = number & { __programBuildInfoFileIdListIdBrand: any };
786+
/* @internal */
778787
export type ProgramBuildInfoDiagnostic = ProgramBuildInfoFileId | [fileId: ProgramBuildInfoFileId, diagnostics: readonly ReusableDiagnostic[]];
788+
/* @internal */
779789
export type ProgramBuilderInfoFilePendingEmit = [fileId: ProgramBuildInfoFileId, emitKind: BuilderFileEmit];
790+
/* @internal */
780791
export type ProgramBuildInfoReferencedMap = [fileId: ProgramBuildInfoFileId, fileIdListId: ProgramBuildInfoFileIdListId][];
792+
/* @internal */
781793
export type ProgramBuildInfoBuilderStateFileInfo = Omit<ts.BuilderState.FileInfo, "signature"> & {
782794
/**
783795
* Signature is
@@ -787,10 +799,12 @@ export type ProgramBuildInfoBuilderStateFileInfo = Omit<ts.BuilderState.FileInfo
787799
*/
788800
signature: string | false | undefined;
789801
};
802+
/* @internal */
790803
/**
791804
* ProgramBuildInfoFileInfo is string if FileInfo.version === FileInfo.signature && !FileInfo.affectsGlobalScope otherwise encoded FileInfo
792805
*/
793806
export type ProgramBuildInfoFileInfo = string | ProgramBuildInfoBuilderStateFileInfo;
807+
/* @internal */
794808
export interface ProgramBuildInfo {
795809
fileNames: readonly string[];
796810
fileInfos: readonly ProgramBuildInfoFileInfo[];
@@ -993,18 +1007,21 @@ function convertToReusableDiagnosticRelatedInformation(diagnostic: ts.Diagnostic
9931007
};
9941008
}
9951009

1010+
/* @internal */
9961011
export enum BuilderProgramKind {
9971012
SemanticDiagnosticsBuilderProgram,
9981013
EmitAndSemanticDiagnosticsBuilderProgram
9991014
}
10001015

1016+
/* @internal */
10011017
export interface BuilderCreationParameters {
10021018
newProgram: ts.Program;
10031019
host: ts.BuilderProgramHost;
10041020
oldProgram: ts.BuilderProgram | undefined;
10051021
configFileParsingDiagnostics: readonly ts.Diagnostic[];
10061022
}
10071023

1024+
/* @internal */
10081025
export function getBuilderCreationParameters(newProgramOrRootNames: ts.Program | readonly string[] | undefined, hostOrOptions: ts.BuilderProgramHost | ts.CompilerOptions | undefined, oldProgramOrHost?: ts.BuilderProgram | ts.CompilerHost, configFileParsingDiagnosticsOrOldProgram?: readonly ts.Diagnostic[] | ts.BuilderProgram, configFileParsingDiagnostics?: readonly ts.Diagnostic[], projectReferences?: readonly ts.ProjectReference[]): BuilderCreationParameters {
10091026
let host: ts.BuilderProgramHost;
10101027
let newProgram: ts.Program;
@@ -1037,8 +1054,11 @@ export function getBuilderCreationParameters(newProgramOrRootNames: ts.Program |
10371054
return { host, newProgram, oldProgram, configFileParsingDiagnostics: configFileParsingDiagnostics || ts.emptyArray };
10381055
}
10391056

1057+
/* @internal */
10401058
export function createBuilderProgram(kind: BuilderProgramKind.SemanticDiagnosticsBuilderProgram, builderCreationParameters: BuilderCreationParameters): ts.SemanticDiagnosticsBuilderProgram;
1059+
/* @internal */
10411060
export function createBuilderProgram(kind: BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram, builderCreationParameters: BuilderCreationParameters): ts.EmitAndSemanticDiagnosticsBuilderProgram;
1061+
/* @internal */
10421062
export function createBuilderProgram(kind: BuilderProgramKind, { newProgram, host, oldProgram, configFileParsingDiagnostics }: BuilderCreationParameters) {
10431063
// Return same program if underlying program doesnt change
10441064
let oldState = oldProgram && oldProgram.getState();
@@ -1351,6 +1371,7 @@ function addToAffectedFilesPendingEmit(state: BuilderProgramState, affectedFileP
13511371
}
13521372
}
13531373

1374+
/* @internal */
13541375
export function toBuilderStateFileInfo(fileInfo: ProgramBuildInfoFileInfo): ts.BuilderState.FileInfo {
13551376
return ts.isString(fileInfo) ?
13561377
{ version: fileInfo, signature: fileInfo, affectsGlobalScope: undefined, impliedFormat: undefined } :
@@ -1359,6 +1380,7 @@ export function toBuilderStateFileInfo(fileInfo: ProgramBuildInfoFileInfo): ts.B
13591380
{ version: fileInfo.version, signature: fileInfo.signature === false ? undefined : fileInfo.version, affectsGlobalScope: fileInfo.affectsGlobalScope, impliedFormat: fileInfo.impliedFormat };
13601381
}
13611382

1383+
/* @internal */
13621384
export function createBuildProgramUsingProgramBuildInfo(program: ProgramBuildInfo, buildInfoPath: string, host: ts.ReadBuildProgramHost): ts.EmitAndSemanticDiagnosticsBuilderProgram {
13631385
const buildInfoDirectory = ts.getDirectoryPath(ts.getNormalizedAbsolutePath(buildInfoPath, host.getCurrentDirectory()));
13641386
const getCanonicalFileName = ts.createGetCanonicalFileName(host.useCaseSensitiveFileNames());
@@ -1432,6 +1454,7 @@ export function createBuildProgramUsingProgramBuildInfo(program: ProgramBuildInf
14321454
}
14331455
}
14341456

1457+
/* @internal */
14351458
export function createRedirectedBuilderProgram(getState: () => { program: ts.Program | undefined; compilerOptions: ts.CompilerOptions; }, configFileParsingDiagnostics: readonly ts.Diagnostic[]): ts.BuilderProgram {
14361459
return {
14371460
getState: ts.notImplemented,
@@ -1460,4 +1483,3 @@ export function createRedirectedBuilderProgram(getState: () => { program: ts.Pro
14601483
return ts.Debug.checkDefined(getState().program);
14611484
}
14621485
}
1463-
}

Diff for: src/compiler/builderPublic.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
namespace ts {
1+
import * as ts from "./_namespaces/ts";
2+
23
export type AffectedFileResult<T> = { result: T; affected: ts.SourceFile | ts.Program; } | undefined;
34

45
export interface BuilderProgramHost {
@@ -171,4 +172,3 @@ export function createAbstractBuilder(newProgramOrRootNames: ts.Program | readon
171172
const { newProgram, configFileParsingDiagnostics: newConfigFileParsingDiagnostics } = ts.getBuilderCreationParameters(newProgramOrRootNames, hostOrOptions, oldProgramOrHost, configFileParsingDiagnosticsOrOldProgram, configFileParsingDiagnostics, projectReferences);
172173
return ts.createRedirectedBuilderProgram(() => ({ program: newProgram, compilerOptions: newProgram.getCompilerOptions() }), newConfigFileParsingDiagnostics);
173174
}
174-
}

Diff for: src/compiler/builderState.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
/*@internal*/
2-
namespace ts {
1+
import * as ts from "./_namespaces/ts";
2+
3+
/* @internal */
34
export function getFileEmitOutput(program: ts.Program, sourceFile: ts.SourceFile, emitOnlyDtsFiles: boolean,
45
cancellationToken?: ts.CancellationToken, customTransformers?: ts.CustomTransformers, forceDtsEmit?: boolean): ts.EmitOutput {
56
const outputFiles: ts.OutputFile[] = [];
@@ -11,6 +12,7 @@ export function getFileEmitOutput(program: ts.Program, sourceFile: ts.SourceFile
1112
}
1213
}
1314

15+
/* @internal */
1416
export interface ReusableBuilderState {
1517
/**
1618
* Information of the file eg. its version, signature etc
@@ -29,6 +31,7 @@ export interface ReusableBuilderState {
2931
readonly exportedModulesMap?: BuilderState.ReadonlyManyToManyPathMap | undefined;
3032
}
3133

34+
/* @internal */
3235
export interface BuilderState {
3336
/**
3437
* Information of the file eg. its version, signature etc
@@ -69,6 +72,7 @@ export interface BuilderState {
6972
allFileNames?: readonly string[];
7073
}
7174

75+
/* @internal */
7276
export namespace BuilderState {
7377
/**
7478
* Information about the source file: Its version and optional signature from last emit
@@ -647,4 +651,3 @@ export namespace BuilderState {
647651
return ts.arrayFrom(ts.mapDefinedIterator(seenFileNamesMap.values(), value => value));
648652
}
649653
}
650-
}

Diff for: src/compiler/builderStatePublic.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
namespace ts {
1+
import * as ts from "./_namespaces/ts";
2+
23
export interface EmitOutput {
34
outputFiles: OutputFile[];
45
emitSkipped: boolean;
@@ -11,4 +12,3 @@ export interface OutputFile {
1112
writeByteOrderMark: boolean;
1213
text: string;
1314
}
14-
}

Diff for: src/compiler/checker.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
/* @internal */
2-
namespace ts {
1+
import * as ts from "./_namespaces/ts";
2+
33
const ambientModuleSymbolRegex = /^".+"$/;
44
const anon = "(anonymous)" as ts.__String & string;
55

@@ -284,6 +284,7 @@ function NodeLinks(this: ts.NodeLinks) {
284284
this.flags = 0;
285285
}
286286

287+
/* @internal */
287288
export function getNodeId(node: ts.Node): number {
288289
if (!node.id) {
289290
node.id = nextNodeId;
@@ -292,6 +293,7 @@ export function getNodeId(node: ts.Node): number {
292293
return node.id;
293294
}
294295

296+
/* @internal */
295297
export function getSymbolId(symbol: ts.Symbol): ts.SymbolId {
296298
if (!symbol.id) {
297299
symbol.id = nextSymbolId;
@@ -301,12 +303,14 @@ export function getSymbolId(symbol: ts.Symbol): ts.SymbolId {
301303
return symbol.id;
302304
}
303305

306+
/* @internal */
304307
export function isInstantiatedModule(node: ts.ModuleDeclaration, preserveConstEnums: boolean) {
305308
const moduleState = ts.getModuleInstanceState(node);
306309
return moduleState === ts.ModuleInstanceState.Instantiated ||
307310
(preserveConstEnums && moduleState === ts.ModuleInstanceState.ConstEnumOnly);
308311
}
309312

313+
/* @internal */
310314
export function createTypeChecker(host: ts.TypeCheckerHost): ts.TypeChecker {
311315
const getPackagesMap = ts.memoize(() => {
312316
// A package name maps to true when we detect it has .d.ts files.
@@ -45226,11 +45230,12 @@ function getIterationTypesKeyFromIterationTypeKind(typeKind: IterationTypeKind)
4522645230
}
4522745231
}
4522845232

45233+
/* @internal */
4522945234
export function signatureHasRestParameter(s: ts.Signature) {
4523045235
return !!(s.flags & ts.SignatureFlags.HasRestParameter);
4523145236
}
4523245237

45238+
/* @internal */
4523345239
export function signatureHasLiteralTypes(s: ts.Signature) {
4523445240
return !!(s.flags & ts.SignatureFlags.HasLiteralTypes);
4523545241
}
45236-
}

Diff for: src/compiler/commandLineParser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
namespace ts {
1+
import * as ts from "./_namespaces/ts";
2+
23
/* @internal */
34
export const compileOnSaveCommandLineOption: ts.CommandLineOption = {
45
name: "compileOnSave",
@@ -3666,4 +3667,3 @@ function getDefaultValueForOption(option: ts.CommandLineOption) {
36663667
return ts.Debug.fail("Expected 'option.type' to have entries.");
36673668
}
36683669
}
3669-
}

0 commit comments

Comments
 (0)