Skip to content

Generated module conversion step - stripNamespaces #5

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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions src/compiler/_namespaces/ts.moduleSpecifiers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Generated file to emulate the ts.moduleSpecifiers namespace. */

export * from "../moduleSpecifiers";
3 changes: 3 additions & 0 deletions src/compiler/_namespaces/ts.performance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* Generated file to emulate the ts.performance namespace. */

export * from "../performance";
74 changes: 74 additions & 0 deletions src/compiler/_namespaces/ts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/* Generated file to emulate the ts namespace. */

export * from "../corePublic";
export * from "../core";
export * from "../debug";
export * from "../semver";
export * from "../performanceCore";
export * from "../perfLogger";
export * from "../tracing";
export * from "../types";
export * from "../sys";
export * from "../path";
export * from "../diagnosticInformationMap.generated";
export * from "../scanner";
export * from "../utilitiesPublic";
export * from "../utilities";
export * from "../factory/baseNodeFactory";
export * from "../factory/parenthesizerRules";
export * from "../factory/nodeConverters";
export * from "../factory/nodeFactory";
export * from "../factory/emitNode";
export * from "../factory/emitHelpers";
export * from "../factory/nodeTests";
export * from "../factory/utilities";
export * from "../factory/utilitiesPublic";
export * from "../parser";
export * from "../commandLineParser";
export * from "../moduleNameResolver";
export * from "../binder";
export * from "../symbolWalker";
export * from "../checker";
export * from "../visitorPublic";
export * from "../sourcemap";
export * from "../transformers/utilities";
export * from "../transformers/destructuring";
export * from "../transformers/taggedTemplate";
export * from "../transformers/ts";
export * from "../transformers/classFields";
export * from "../transformers/typeSerializer";
export * from "../transformers/legacyDecorators";
export * from "../transformers/es2017";
export * from "../transformers/es2018";
export * from "../transformers/es2019";
export * from "../transformers/es2020";
export * from "../transformers/es2021";
export * from "../transformers/esnext";
export * from "../transformers/jsx";
export * from "../transformers/es2016";
export * from "../transformers/es2015";
export * from "../transformers/es5";
export * from "../transformers/generators";
export * from "../transformers/module/module";
export * from "../transformers/module/system";
export * from "../transformers/module/esnextAnd2015";
export * from "../transformers/module/node";
export * from "../transformers/declarations/diagnostics";
export * from "../transformers/declarations";
export * from "../transformer";
export * from "../emitter";
export * from "../watchUtilities";
export * from "../program";
export * from "../builderStatePublic";
export * from "../builderState";
export * from "../builder";
export * from "../builderPublic";
export * from "../resolutionCache";
export * from "../watch";
export * from "../watchPublic";
export * from "../tsbuild";
export * from "../tsbuildPublic";
import * as moduleSpecifiers from "./ts.moduleSpecifiers";
export { moduleSpecifiers };
import * as performance from "./ts.performance";
export { performance };
8 changes: 5 additions & 3 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as ts from "./_namespaces/ts";

/* @internal */
namespace ts {
/** @internal */
export const enum ModuleInstanceState {
NonInstantiated = 0,
Instantiated = 1,
Expand All @@ -15,6 +15,7 @@ interface ActiveLabel {
referenced: boolean;
}

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

const binder = createBinder();

/** @internal */
export function bindSourceFile(file: ts.SourceFile, options: ts.CompilerOptions) {
ts.performance.mark("beforeBind");
ts.perfLogger.logStartBindFile("" + file.fileName);
Expand Down Expand Up @@ -3498,6 +3500,7 @@ function isPurelyTypeDeclaration(s: ts.Statement): boolean {
}
}

/** @internal */
export function isExportsOrModuleExportsOrAlias(sourceFile: ts.SourceFile, node: ts.Expression): boolean {
let i = 0;
const q = ts.createQueue<ts.Expression>();
Expand Down Expand Up @@ -3533,4 +3536,3 @@ function lookupSymbolForName(container: ts.Node, name: ts.__String): ts.Symbol |
}
return container.symbol && container.symbol.exports && container.symbol.exports.get(name);
}
}
43 changes: 40 additions & 3 deletions src/compiler/builder.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*@internal*/
namespace ts {
import * as ts from "./_namespaces/ts";

/** @internal */
export interface ReusableDiagnostic extends ReusableDiagnosticRelatedInformation {
/** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
reportsUnnecessary?: {};
Expand All @@ -9,6 +10,7 @@ export interface ReusableDiagnostic extends ReusableDiagnosticRelatedInformation
skippedOn?: keyof ts.CompilerOptions;
}

/** @internal */
export interface ReusableDiagnosticRelatedInformation {
category: ts.DiagnosticCategory;
code: number;
Expand All @@ -18,11 +20,14 @@ export interface ReusableDiagnosticRelatedInformation {
messageText: string | ReusableDiagnosticMessageChain;
}

/** @internal */
export type ReusableDiagnosticMessageChain = ts.DiagnosticMessageChain;

/** @internal */
/** 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 */
export type EmitSignature = string | [signature: string];

/** @internal */
export interface ReusableBuilderProgramState extends ts.BuilderState {
/**
* Cache of bind and check diagnostics for files with their Path being the key
Expand Down Expand Up @@ -70,6 +75,7 @@ export interface ReusableBuilderProgramState extends ts.BuilderState {
bundle?: ts.BundleBuildInfo;
}

/** @internal */
export const enum BuilderFileEmit {
None = 0,
Js = 1 << 0, // emit js file
Expand All @@ -83,6 +89,7 @@ export const enum BuilderFileEmit {
All = AllJs | AllDts,
}

/** @internal */
/**
* State to store the changed files, affected files and cache semantic diagnostics
*/
Expand Down Expand Up @@ -140,6 +147,7 @@ export interface BuilderProgramState extends ts.BuilderState, ReusableBuilderPro
filesChangingSignature?: ts.Set<ts.Path>;
}

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

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

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

/** @internal */
export type ProgramBuildInfoFileId = number & { __programBuildInfoFileIdBrand: any };
/** @internal */
export type ProgramBuildInfoFileIdListId = number & { __programBuildInfoFileIdListIdBrand: any };
/** @internal */
export type ProgramBuildInfoDiagnostic = ProgramBuildInfoFileId | [fileId: ProgramBuildInfoFileId, diagnostics: readonly ReusableDiagnostic[]];
/** @internal */
/**
* fileId if pending emit is same as what compilerOptions suggest
* [fileId] if pending emit is only dts file emit
* [fileId, emitKind] if any other type emit is pending
*/
export type ProgramBuilderInfoFilePendingEmit = ProgramBuildInfoFileId | [fileId: ProgramBuildInfoFileId] | [fileId: ProgramBuildInfoFileId, emitKind: BuilderFileEmit];
/** @internal */
export type ProgramBuildInfoReferencedMap = [fileId: ProgramBuildInfoFileId, fileIdListId: ProgramBuildInfoFileIdListId][];
/** @internal */
export type ProgramMultiFileEmitBuildInfoBuilderStateFileInfo = Omit<ts.BuilderState.FileInfo, "signature"> & {
/**
* Signature is
Expand All @@ -808,15 +824,18 @@ export type ProgramMultiFileEmitBuildInfoBuilderStateFileInfo = Omit<ts.BuilderS
*/
signature: string | false | undefined;
};
/** @internal */
/**
* [fileId, signature] if different from file's signature
* fileId if file wasnt emitted
*/
export type ProgramBuildInfoEmitSignature = ProgramBuildInfoFileId | [fileId: ProgramBuildInfoFileId, signature: EmitSignature | []];
/** @internal */
/**
* ProgramMultiFileEmitBuildInfoFileInfo is string if FileInfo.version === FileInfo.signature && !FileInfo.affectsGlobalScope otherwise encoded FileInfo
*/
export type ProgramMultiFileEmitBuildInfoFileInfo = string | ProgramMultiFileEmitBuildInfoBuilderStateFileInfo;
/** @internal */
export interface ProgramMultiFileEmitBuildInfo {
fileNames: readonly string[];
fileInfos: readonly ProgramMultiFileEmitBuildInfoFileInfo[];
Expand All @@ -831,15 +850,18 @@ export interface ProgramMultiFileEmitBuildInfo {
// Because this is only output file in the program, we dont need fileId to deduplicate name
latestChangedDtsFile?: string | undefined;
}
/** @internal */
/**
* ProgramBundleEmitBuildInfoFileInfo is string if !FileInfo.impliedFormat otherwise encoded FileInfo
*/
export type ProgramBundleEmitBuildInfoFileInfo = string | ts.BuilderState.FileInfo;
/** @internal */
/**
* false if it is the emit corresponding to compilerOptions
* value otherwise
*/
export type ProgramBuildInfoBundlePendingEmit = BuilderFileEmit | false;
/** @internal */
export interface ProgramBundleEmitBuildInfo {
fileNames: readonly string[];
fileInfos: readonly ProgramBundleEmitBuildInfoFileInfo[];
Expand All @@ -849,8 +871,10 @@ export interface ProgramBundleEmitBuildInfo {
pendingEmit: ProgramBuildInfoBundlePendingEmit | undefined;
}

/** @internal */
export type ProgramBuildInfo = ProgramMultiFileEmitBuildInfo | ProgramBundleEmitBuildInfo;

/** @internal */
export function isProgramBundleEmitBuildInfo(info: ProgramBuildInfo): info is ProgramBundleEmitBuildInfo {
return !!ts.outFile(info.options || {});
}
Expand Down Expand Up @@ -1100,18 +1124,21 @@ function convertToReusableDiagnosticRelatedInformation(diagnostic: ts.Diagnostic
};
}

/** @internal */
export enum BuilderProgramKind {
SemanticDiagnosticsBuilderProgram,
EmitAndSemanticDiagnosticsBuilderProgram
}

/** @internal */
export interface BuilderCreationParameters {
newProgram: ts.Program;
host: ts.BuilderProgramHost;
oldProgram: ts.BuilderProgram | undefined;
configFileParsingDiagnostics: readonly ts.Diagnostic[];
}

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

/** @internal */
export function computeSignatureWithDiagnostics(
sourceFile: ts.SourceFile,
text: string,
Expand Down Expand Up @@ -1181,12 +1209,16 @@ export function computeSignatureWithDiagnostics(
}
}

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

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

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

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

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

/** @internal */
export function createBuilderProgramUsingProgramBuildInfo(buildInfo: ts.BuildInfo, buildInfoPath: string, host: ts.ReadBuildProgramHost): ts.EmitAndSemanticDiagnosticsBuilderProgram {
const program = buildInfo.program!;
const buildInfoDirectory = ts.getDirectoryPath(ts.getNormalizedAbsolutePath(buildInfoPath, host.getCurrentDirectory()));
Expand Down Expand Up @@ -1661,6 +1697,7 @@ export function createBuilderProgramUsingProgramBuildInfo(buildInfo: ts.BuildInf
}
}

/** @internal */
export function getBuildInfoFileVersionMap(
program: ProgramBuildInfo,
buildInfoPath: string,
Expand All @@ -1677,6 +1714,7 @@ export function getBuildInfoFileVersionMap(
return fileInfos;
}

/** @internal */
export function createRedirectedBuilderProgram(getState: () => { program?: ts.Program | undefined; compilerOptions: ts.CompilerOptions; }, configFileParsingDiagnostics: readonly ts.Diagnostic[]): ts.BuilderProgram {
return {
getState: ts.notImplemented,
Expand Down Expand Up @@ -1705,4 +1743,3 @@ export function createRedirectedBuilderProgram(getState: () => { program?: ts.Pr
return ts.Debug.checkDefined(getState().program);
}
}
}
4 changes: 2 additions & 2 deletions src/compiler/builderPublic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace ts {
import * as ts from "./_namespaces/ts";

export type AffectedFileResult<T> = { result: T; affected: ts.SourceFile | ts.Program; } | undefined;

export interface BuilderProgramHost {
Expand Down Expand Up @@ -178,4 +179,3 @@ export function createAbstractBuilder(newProgramOrRootNames: ts.Program | readon
const { newProgram, configFileParsingDiagnostics: newConfigFileParsingDiagnostics } = ts.getBuilderCreationParameters(newProgramOrRootNames, hostOrOptions, oldProgramOrHost, configFileParsingDiagnosticsOrOldProgram, configFileParsingDiagnostics, projectReferences);
return ts.createRedirectedBuilderProgram(() => ({ program: newProgram, compilerOptions: newProgram.getCompilerOptions() }), newConfigFileParsingDiagnostics);
}
}
Loading