Skip to content

Commit 2a26179

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 3210ec1 commit 2a26179

File tree

583 files changed

+4370
-1498
lines changed

Some content is hidden

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

583 files changed

+4370
-1498
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* Generated file to emulate the ts.moduleSpecifiers namespace. */
2+
3+
export * from "../moduleSpecifiers";
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* Generated file to emulate the ts.performance namespace. */
2+
3+
export * from "../performance";

src/compiler/_namespaces/ts.ts

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

src/compiler/binder.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import * as ts from "./_namespaces/ts";
12

2-
/* @internal */
3-
namespace ts {
3+
/** @internal */
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);
@@ -3498,6 +3500,7 @@ function isPurelyTypeDeclaration(s: ts.Statement): boolean {
34983500
}
34993501
}
35003502

3503+
/** @internal */
35013504
export function isExportsOrModuleExportsOrAlias(sourceFile: ts.SourceFile, node: ts.Expression): boolean {
35023505
let i = 0;
35033506
const q = ts.createQueue<ts.Expression>();
@@ -3533,4 +3536,3 @@ function lookupSymbolForName(container: ts.Node, name: ts.__String): ts.Symbol |
35333536
}
35343537
return container.symbol && container.symbol.exports && container.symbol.exports.get(name);
35353538
}
3536-
}

src/compiler/builder.ts

Lines changed: 33 additions & 3 deletions
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.BuilderState {
2428
/**
2529
* Cache of bind and check diagnostics for files with their Path being the key
@@ -67,11 +71,13 @@ export interface ReusableBuilderProgramState extends ts.BuilderState {
6771
latestChangedDtsFile: string | undefined;
6872
}
6973

74+
/** @internal */
7075
export const enum BuilderFileEmit {
7176
DtsOnly,
7277
Full
7378
}
7479

80+
/** @internal */
7581
/**
7682
* State to store the changed files, affected files and cache semantic diagnostics
7783
*/
@@ -133,6 +139,7 @@ export interface BuilderProgramState extends ts.BuilderState, ReusableBuilderPro
133139
filesChangingSignature?: ts.Set<ts.Path>;
134140
}
135141

142+
/** @internal */
136143
export type SavedBuildProgramEmitState = Pick<BuilderProgramState,
137144
"affectedFilesPendingEmit" |
138145
"affectedFilesPendingEmitIndex" |
@@ -761,11 +768,17 @@ function getBinderAndCheckerDiagnosticsOfFile(state: BuilderProgramState, source
761768
return ts.filterSemanticDiagnostics(diagnostics, state.compilerOptions);
762769
}
763770

771+
/** @internal */
764772
export type ProgramBuildInfoFileId = number & { __programBuildInfoFileIdBrand: any };
773+
/** @internal */
765774
export type ProgramBuildInfoFileIdListId = number & { __programBuildInfoFileIdListIdBrand: any };
775+
/** @internal */
766776
export type ProgramBuildInfoDiagnostic = ProgramBuildInfoFileId | [fileId: ProgramBuildInfoFileId, diagnostics: readonly ReusableDiagnostic[]];
777+
/** @internal */
767778
export type ProgramBuilderInfoFilePendingEmit = [fileId: ProgramBuildInfoFileId, emitKind: BuilderFileEmit];
779+
/** @internal */
768780
export type ProgramBuildInfoReferencedMap = [fileId: ProgramBuildInfoFileId, fileIdListId: ProgramBuildInfoFileIdListId][];
781+
/** @internal */
769782
export type ProgramBuildInfoBuilderStateFileInfo = Omit<ts.BuilderState.FileInfo, "signature"> & {
770783
/**
771784
* Signature is
@@ -775,15 +788,18 @@ export type ProgramBuildInfoBuilderStateFileInfo = Omit<ts.BuilderState.FileInfo
775788
*/
776789
signature: string | false | undefined;
777790
};
791+
/** @internal */
778792
/**
779793
* [fileId, signature] if different from file's signature
780794
* fileId if file wasnt emitted
781795
*/
782796
export type ProgramBuildInfoEmitSignature = ProgramBuildInfoFileId | [fileId: ProgramBuildInfoFileId, signature: string];
797+
/** @internal */
783798
/**
784799
* ProgramBuildInfoFileInfo is string if FileInfo.version === FileInfo.signature && !FileInfo.affectsGlobalScope otherwise encoded FileInfo
785800
*/
786801
export type ProgramBuildInfoFileInfo = string | ProgramBuildInfoBuilderStateFileInfo;
802+
/** @internal */
787803
export interface ProgramMultiFileEmitBuildInfo {
788804
fileNames: readonly string[];
789805
fileInfos: readonly ProgramBuildInfoFileInfo[];
@@ -799,6 +815,7 @@ export interface ProgramMultiFileEmitBuildInfo {
799815
latestChangedDtsFile?: string;
800816
}
801817

818+
/** @internal */
802819
export interface ProgramBundleEmitBuildInfo {
803820
fileNames: readonly string[];
804821
fileInfos: readonly string[];
@@ -807,8 +824,10 @@ export interface ProgramBundleEmitBuildInfo {
807824
latestChangedDtsFile?: string;
808825
}
809826

827+
/** @internal */
810828
export type ProgramBuildInfo = ProgramMultiFileEmitBuildInfo | ProgramBundleEmitBuildInfo;
811829

830+
/** @internal */
812831
export function isProgramBundleEmitBuildInfo(info: ProgramBuildInfo): info is ProgramBundleEmitBuildInfo {
813832
return !!ts.outFile(info.options || {});
814833
}
@@ -1033,18 +1052,21 @@ function convertToReusableDiagnosticRelatedInformation(diagnostic: ts.Diagnostic
10331052
};
10341053
}
10351054

1055+
/** @internal */
10361056
export enum BuilderProgramKind {
10371057
SemanticDiagnosticsBuilderProgram,
10381058
EmitAndSemanticDiagnosticsBuilderProgram
10391059
}
10401060

1061+
/** @internal */
10411062
export interface BuilderCreationParameters {
10421063
newProgram: ts.Program;
10431064
host: ts.BuilderProgramHost;
10441065
oldProgram: ts.BuilderProgram | undefined;
10451066
configFileParsingDiagnostics: readonly ts.Diagnostic[];
10461067
}
10471068

1069+
/** @internal */
10481070
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 {
10491071
let host: ts.BuilderProgramHost;
10501072
let newProgram: ts.Program;
@@ -1081,6 +1103,7 @@ function getTextHandlingSourceMapForSignature(text: string, data: ts.WriteFileCa
10811103
return data?.sourceMapUrlPos !== undefined ? text.substring(0, data.sourceMapUrlPos) : text;
10821104
}
10831105

1106+
/** @internal */
10841107
export function computeSignatureWithDiagnostics(
10851108
sourceFile: ts.SourceFile,
10861109
text: string,
@@ -1114,12 +1137,16 @@ export function computeSignatureWithDiagnostics(
11141137
}
11151138
}
11161139

1140+
/** @internal */
11171141
export function computeSignature(text: string, computeHash: ts.BuilderState.ComputeHash | undefined, data?: ts.WriteFileCallbackData) {
11181142
return (computeHash ?? ts.generateDjb2Hash)(getTextHandlingSourceMapForSignature(text, data));
11191143
}
11201144

1145+
/** @internal */
11211146
export function createBuilderProgram(kind: BuilderProgramKind.SemanticDiagnosticsBuilderProgram, builderCreationParameters: BuilderCreationParameters): ts.SemanticDiagnosticsBuilderProgram;
1147+
/** @internal */
11221148
export function createBuilderProgram(kind: BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram, builderCreationParameters: BuilderCreationParameters): ts.EmitAndSemanticDiagnosticsBuilderProgram;
1149+
/** @internal */
11231150
export function createBuilderProgram(kind: BuilderProgramKind, { newProgram, host, oldProgram, configFileParsingDiagnostics }: BuilderCreationParameters) {
11241151
// Return same program if underlying program doesnt change
11251152
let oldState = oldProgram && oldProgram.getState();
@@ -1461,6 +1488,7 @@ function addToAffectedFilesPendingEmit(state: BuilderProgramState, affectedFileP
14611488
}
14621489
}
14631490

1491+
/** @internal */
14641492
export function toBuilderStateFileInfo(fileInfo: ProgramBuildInfoFileInfo): ts.BuilderState.FileInfo {
14651493
return ts.isString(fileInfo) ?
14661494
{ version: fileInfo, signature: fileInfo, affectsGlobalScope: undefined, impliedFormat: undefined } :
@@ -1469,6 +1497,7 @@ export function toBuilderStateFileInfo(fileInfo: ProgramBuildInfoFileInfo): ts.B
14691497
{ version: fileInfo.version, signature: fileInfo.signature === false ? undefined : fileInfo.version, affectsGlobalScope: fileInfo.affectsGlobalScope, impliedFormat: fileInfo.impliedFormat };
14701498
}
14711499

1500+
/** @internal */
14721501
export function createBuilderProgramUsingProgramBuildInfo(program: ProgramBuildInfo, buildInfoPath: string, host: ts.ReadBuildProgramHost): ts.EmitAndSemanticDiagnosticsBuilderProgram {
14731502
const buildInfoDirectory = ts.getDirectoryPath(ts.getNormalizedAbsolutePath(buildInfoPath, host.getCurrentDirectory()));
14741503
const getCanonicalFileName = ts.createGetCanonicalFileName(host.useCaseSensitiveFileNames());
@@ -1571,6 +1600,7 @@ export function createBuilderProgramUsingProgramBuildInfo(program: ProgramBuildI
15711600
}
15721601
}
15731602

1603+
/** @internal */
15741604
export function getBuildInfoFileVersionMap(
15751605
program: ProgramBuildInfo,
15761606
buildInfoPath: string,
@@ -1587,6 +1617,7 @@ export function getBuildInfoFileVersionMap(
15871617
return fileInfos;
15881618
}
15891619

1620+
/** @internal */
15901621
export function createRedirectedBuilderProgram(getState: () => { program?: ts.Program | undefined; compilerOptions: ts.CompilerOptions; }, configFileParsingDiagnostics: readonly ts.Diagnostic[]): ts.BuilderProgram {
15911622
return {
15921623
getState: ts.notImplemented,
@@ -1615,4 +1646,3 @@ export function createRedirectedBuilderProgram(getState: () => { program?: ts.Pr
16151646
return ts.Debug.checkDefined(getState().program);
16161647
}
16171648
}
1618-
}

src/compiler/builderPublic.ts

Lines changed: 2 additions & 2 deletions
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 {
@@ -178,4 +179,3 @@ export function createAbstractBuilder(newProgramOrRootNames: ts.Program | readon
178179
const { newProgram, configFileParsingDiagnostics: newConfigFileParsingDiagnostics } = ts.getBuilderCreationParameters(newProgramOrRootNames, hostOrOptions, oldProgramOrHost, configFileParsingDiagnosticsOrOldProgram, configFileParsingDiagnostics, projectReferences);
179180
return ts.createRedirectedBuilderProgram(() => ({ program: newProgram, compilerOptions: newProgram.getCompilerOptions() }), newConfigFileParsingDiagnostics);
180181
}
181-
}

src/compiler/builderState.ts

Lines changed: 5 additions & 3 deletions
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[] = [];
@@ -10,6 +11,7 @@ export function getFileEmitOutput(program: ts.Program, sourceFile: ts.SourceFile
1011
outputFiles.push({ name: fileName, writeByteOrderMark, text });
1112
}
1213
}
14+
/** @internal */
1315
export interface BuilderState {
1416
/**
1517
* Information of the file eg. its version, signature etc
@@ -57,6 +59,7 @@ export interface BuilderState {
5759
*/
5860
allFileNames?: readonly string[];
5961
}
62+
/** @internal */
6063
export namespace BuilderState {
6164
/**
6265
* Information about the source file: Its version and optional signature from last emit
@@ -625,4 +628,3 @@ export namespace BuilderState {
625628
return ts.arrayFrom(ts.mapDefinedIterator(seenFileNamesMap.values(), value => value));
626629
}
627630
}
628-
}

src/compiler/builderStatePublic.ts

Lines changed: 2 additions & 2 deletions
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
text: string;
1213
/* @internal */ buildInfo?: ts.BuildInfo
1314
}
14-
}

0 commit comments

Comments
 (0)