Skip to content

Commit ec16755

Browse files
committed
Generated module 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 dc25bdf commit ec16755

File tree

588 files changed

+4411
-1504
lines changed

Some content is hidden

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

588 files changed

+4411
-1504
lines changed
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";
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

+74
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

+5-3
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

+40-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,11 +20,14 @@ export interface ReusableDiagnosticRelatedInformation {
1820
messageText: string | ReusableDiagnosticMessageChain;
1921
}
2022

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

26+
/** @internal */
2327
/** Signature (Hash of d.ts emitted), is string if it was emitted using same d.ts.map option as what compilerOptions indicate, otherwise tuple of string */
2428
export type EmitSignature = string | [signature: string];
2529

30+
/** @internal */
2631
export interface ReusableBuilderProgramState extends ts.BuilderState {
2732
/**
2833
* Cache of bind and check diagnostics for files with their Path being the key
@@ -70,6 +75,7 @@ export interface ReusableBuilderProgramState extends ts.BuilderState {
7075
bundle?: ts.BundleBuildInfo;
7176
}
7277

78+
/** @internal */
7379
export const enum BuilderFileEmit {
7480
None = 0,
7581
Js = 1 << 0, // emit js file
@@ -83,6 +89,7 @@ export const enum BuilderFileEmit {
8389
All = AllJs | AllDts,
8490
}
8591

92+
/** @internal */
8693
/**
8794
* State to store the changed files, affected files and cache semantic diagnostics
8895
*/
@@ -140,6 +147,7 @@ export interface BuilderProgramState extends ts.BuilderState, ReusableBuilderPro
140147
filesChangingSignature?: ts.Set<ts.Path>;
141148
}
142149

150+
/** @internal */
143151
export type SavedBuildProgramEmitState = Pick<BuilderProgramState,
144152
"affectedFilesPendingEmit" |
145153
"seenEmittedFiles" |
@@ -150,6 +158,7 @@ export type SavedBuildProgramEmitState = Pick<BuilderProgramState,
150158
"hasChangedEmitSignature"
151159
> & { changedFilesSet: BuilderProgramState["changedFilesSet"] | undefined };
152160

161+
/** @internal */
153162
/** Get flags determining what all needs to be emitted */
154163
export function getBuilderFileEmit(options: ts.CompilerOptions) {
155164
let result = BuilderFileEmit.Js;
@@ -161,6 +170,7 @@ export function getBuilderFileEmit(options: ts.CompilerOptions) {
161170
return result;
162171
}
163172

173+
/** @internal */
164174
/** Determing what all is pending to be emitted based on previous options or previous file emit flags */
165175
export function getPendingEmitKind(optionsOrEmitKind: ts.CompilerOptions | BuilderFileEmit, oldOptionsOrEmitKind: ts.CompilerOptions | BuilderFileEmit | undefined): BuilderFileEmit {
166176
const oldEmitKind = oldOptionsOrEmitKind && (ts.isNumber(oldOptionsOrEmitKind) ? oldOptionsOrEmitKind : getBuilderFileEmit(oldOptionsOrEmitKind));
@@ -789,16 +799,22 @@ function getBinderAndCheckerDiagnosticsOfFile(state: BuilderProgramState, source
789799
return ts.filterSemanticDiagnostics(diagnostics, state.compilerOptions);
790800
}
791801

802+
/** @internal */
792803
export type ProgramBuildInfoFileId = number & { __programBuildInfoFileIdBrand: any };
804+
/** @internal */
793805
export type ProgramBuildInfoFileIdListId = number & { __programBuildInfoFileIdListIdBrand: any };
806+
/** @internal */
794807
export type ProgramBuildInfoDiagnostic = ProgramBuildInfoFileId | [fileId: ProgramBuildInfoFileId, diagnostics: readonly ReusableDiagnostic[]];
808+
/** @internal */
795809
/**
796810
* fileId if pending emit is same as what compilerOptions suggest
797811
* [fileId] if pending emit is only dts file emit
798812
* [fileId, emitKind] if any other type emit is pending
799813
*/
800814
export type ProgramBuilderInfoFilePendingEmit = ProgramBuildInfoFileId | [fileId: ProgramBuildInfoFileId] | [fileId: ProgramBuildInfoFileId, emitKind: BuilderFileEmit];
815+
/** @internal */
801816
export type ProgramBuildInfoReferencedMap = [fileId: ProgramBuildInfoFileId, fileIdListId: ProgramBuildInfoFileIdListId][];
817+
/** @internal */
802818
export type ProgramMultiFileEmitBuildInfoBuilderStateFileInfo = Omit<ts.BuilderState.FileInfo, "signature"> & {
803819
/**
804820
* Signature is
@@ -808,15 +824,18 @@ export type ProgramMultiFileEmitBuildInfoBuilderStateFileInfo = Omit<ts.BuilderS
808824
*/
809825
signature: string | false | undefined;
810826
};
827+
/** @internal */
811828
/**
812829
* [fileId, signature] if different from file's signature
813830
* fileId if file wasnt emitted
814831
*/
815832
export type ProgramBuildInfoEmitSignature = ProgramBuildInfoFileId | [fileId: ProgramBuildInfoFileId, signature: EmitSignature | []];
833+
/** @internal */
816834
/**
817835
* ProgramMultiFileEmitBuildInfoFileInfo is string if FileInfo.version === FileInfo.signature && !FileInfo.affectsGlobalScope otherwise encoded FileInfo
818836
*/
819837
export type ProgramMultiFileEmitBuildInfoFileInfo = string | ProgramMultiFileEmitBuildInfoBuilderStateFileInfo;
838+
/** @internal */
820839
export interface ProgramMultiFileEmitBuildInfo {
821840
fileNames: readonly string[];
822841
fileInfos: readonly ProgramMultiFileEmitBuildInfoFileInfo[];
@@ -831,15 +850,18 @@ export interface ProgramMultiFileEmitBuildInfo {
831850
// Because this is only output file in the program, we dont need fileId to deduplicate name
832851
latestChangedDtsFile?: string | undefined;
833852
}
853+
/** @internal */
834854
/**
835855
* ProgramBundleEmitBuildInfoFileInfo is string if !FileInfo.impliedFormat otherwise encoded FileInfo
836856
*/
837857
export type ProgramBundleEmitBuildInfoFileInfo = string | ts.BuilderState.FileInfo;
858+
/** @internal */
838859
/**
839860
* false if it is the emit corresponding to compilerOptions
840861
* value otherwise
841862
*/
842863
export type ProgramBuildInfoBundlePendingEmit = BuilderFileEmit | false;
864+
/** @internal */
843865
export interface ProgramBundleEmitBuildInfo {
844866
fileNames: readonly string[];
845867
fileInfos: readonly ProgramBundleEmitBuildInfoFileInfo[];
@@ -849,8 +871,10 @@ export interface ProgramBundleEmitBuildInfo {
849871
pendingEmit: ProgramBuildInfoBundlePendingEmit | undefined;
850872
}
851873

874+
/** @internal */
852875
export type ProgramBuildInfo = ProgramMultiFileEmitBuildInfo | ProgramBundleEmitBuildInfo;
853876

877+
/** @internal */
854878
export function isProgramBundleEmitBuildInfo(info: ProgramBuildInfo): info is ProgramBundleEmitBuildInfo {
855879
return !!ts.outFile(info.options || {});
856880
}
@@ -1100,18 +1124,21 @@ function convertToReusableDiagnosticRelatedInformation(diagnostic: ts.Diagnostic
11001124
};
11011125
}
11021126

1127+
/** @internal */
11031128
export enum BuilderProgramKind {
11041129
SemanticDiagnosticsBuilderProgram,
11051130
EmitAndSemanticDiagnosticsBuilderProgram
11061131
}
11071132

1133+
/** @internal */
11081134
export interface BuilderCreationParameters {
11091135
newProgram: ts.Program;
11101136
host: ts.BuilderProgramHost;
11111137
oldProgram: ts.BuilderProgram | undefined;
11121138
configFileParsingDiagnostics: readonly ts.Diagnostic[];
11131139
}
11141140

1141+
/** @internal */
11151142
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 {
11161143
let host: ts.BuilderProgramHost;
11171144
let newProgram: ts.Program;
@@ -1148,6 +1175,7 @@ function getTextHandlingSourceMapForSignature(text: string, data: ts.WriteFileCa
11481175
return data?.sourceMapUrlPos !== undefined ? text.substring(0, data.sourceMapUrlPos) : text;
11491176
}
11501177

1178+
/** @internal */
11511179
export function computeSignatureWithDiagnostics(
11521180
sourceFile: ts.SourceFile,
11531181
text: string,
@@ -1181,12 +1209,16 @@ export function computeSignatureWithDiagnostics(
11811209
}
11821210
}
11831211

1212+
/** @internal */
11841213
export function computeSignature(text: string, computeHash: ts.BuilderState.ComputeHash | undefined, data?: ts.WriteFileCallbackData) {
11851214
return (computeHash ?? ts.generateDjb2Hash)(getTextHandlingSourceMapForSignature(text, data));
11861215
}
11871216

1217+
/** @internal */
11881218
export function createBuilderProgram(kind: BuilderProgramKind.SemanticDiagnosticsBuilderProgram, builderCreationParameters: BuilderCreationParameters): ts.SemanticDiagnosticsBuilderProgram;
1219+
/** @internal */
11891220
export function createBuilderProgram(kind: BuilderProgramKind.EmitAndSemanticDiagnosticsBuilderProgram, builderCreationParameters: BuilderCreationParameters): ts.EmitAndSemanticDiagnosticsBuilderProgram;
1221+
/** @internal */
11901222
export function createBuilderProgram(kind: BuilderProgramKind, { newProgram, host, oldProgram, configFileParsingDiagnostics }: BuilderCreationParameters) {
11911223
// Return same program if underlying program doesnt change
11921224
let oldState = oldProgram && oldProgram.getState();
@@ -1530,6 +1562,7 @@ function addToAffectedFilesPendingEmit(state: BuilderProgramState, affectedFileP
15301562
(state.affectedFilesPendingEmit ??= new ts.Map()).set(affectedFilePendingEmit, existingKind | kind);
15311563
}
15321564

1565+
/** @internal */
15331566
export function toBuilderStateFileInfoForMultiEmit(fileInfo: ProgramMultiFileEmitBuildInfoFileInfo): ts.BuilderState.FileInfo {
15341567
return ts.isString(fileInfo) ?
15351568
{ version: fileInfo, signature: fileInfo, affectsGlobalScope: undefined, impliedFormat: undefined } :
@@ -1538,14 +1571,17 @@ export function toBuilderStateFileInfoForMultiEmit(fileInfo: ProgramMultiFileEmi
15381571
{ version: fileInfo.version, signature: fileInfo.signature === false ? undefined : fileInfo.version, affectsGlobalScope: fileInfo.affectsGlobalScope, impliedFormat: fileInfo.impliedFormat };
15391572
}
15401573

1574+
/** @internal */
15411575
export function toBuilderFileEmit(value: ProgramBuilderInfoFilePendingEmit, fullEmitForOptions: BuilderFileEmit): BuilderFileEmit{
15421576
return ts.isNumber(value) ? fullEmitForOptions : value[1] || BuilderFileEmit.Dts;
15431577
}
15441578

1579+
/** @internal */
15451580
export function toProgramEmitPending(value: ProgramBuildInfoBundlePendingEmit, options: ts.CompilerOptions | undefined): BuilderFileEmit | undefined {
15461581
return !value ? getBuilderFileEmit(options || {}) : value;
15471582
}
15481583

1584+
/** @internal */
15491585
export function createBuilderProgramUsingProgramBuildInfo(buildInfo: ts.BuildInfo, buildInfoPath: string, host: ts.ReadBuildProgramHost): ts.EmitAndSemanticDiagnosticsBuilderProgram {
15501586
const program = buildInfo.program!;
15511587
const buildInfoDirectory = ts.getDirectoryPath(ts.getNormalizedAbsolutePath(buildInfoPath, host.getCurrentDirectory()));
@@ -1661,6 +1697,7 @@ export function createBuilderProgramUsingProgramBuildInfo(buildInfo: ts.BuildInf
16611697
}
16621698
}
16631699

1700+
/** @internal */
16641701
export function getBuildInfoFileVersionMap(
16651702
program: ProgramBuildInfo,
16661703
buildInfoPath: string,
@@ -1677,6 +1714,7 @@ export function getBuildInfoFileVersionMap(
16771714
return fileInfos;
16781715
}
16791716

1717+
/** @internal */
16801718
export function createRedirectedBuilderProgram(getState: () => { program?: ts.Program | undefined; compilerOptions: ts.CompilerOptions; }, configFileParsingDiagnostics: readonly ts.Diagnostic[]): ts.BuilderProgram {
16811719
return {
16821720
getState: ts.notImplemented,
@@ -1705,4 +1743,3 @@ export function createRedirectedBuilderProgram(getState: () => { program?: ts.Pr
17051743
return ts.Debug.checkDefined(getState().program);
17061744
}
17071745
}
1708-
}

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 {
@@ -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-
}

0 commit comments

Comments
 (0)