Skip to content

Commit 21d2bb9

Browse files
committed
Bad attempt to solve some cycles (not complete)
inlineImports does not preserve evaluation order, instead preferring to format the imports how a user would. This causes the evaluation order to change and some cycles to cause problems.
1 parent b303800 commit 21d2bb9

File tree

4 files changed

+95
-82
lines changed

4 files changed

+95
-82
lines changed

Gulpfile.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ const localPreBuild = parallel(generateLibs, series(buildScripts, generateDiagno
127127
const preBuild = cmdLineOptions.lkg ? lkgPreBuild : localPreBuild;
128128

129129
const buildServices = (() => {
130+
// TODO(jakebailey): fix this for modules
130131
return cb => { console.log("!!!TODO!!! buildServices"); cb(); };
131132

132133
// build typescriptServices.out.js
@@ -253,6 +254,7 @@ task("watch-min").flags = {
253254
};
254255

255256
const buildLssl = (() => {
257+
// TODO(jakebailey): fix this for modules
256258
return cb => { console.log("!!!TODO!!! buildLssl"); cb(); };
257259

258260
// build tsserverlibrary.out.js
@@ -449,7 +451,7 @@ preTest.displayName = "preTest";
449451
const postTest = (done) => cmdLineOptions.lint ? lint(done) : done();
450452

451453
const runTests = () => runConsoleTests(testRunner, "mocha-fivemat-progress-reporter", /*runInParallel*/ false, /*watchMode*/ false);
452-
task("runtests", series(/*preBuild, preTest,*/ runTests /*, postTest*/)); // !!!TODO!!!
454+
task("runtests", series(/*preBuild, preTest,*/ runTests /*, postTest*/)); // TODO(jakebailey): fix this for modules
453455
task("runtests").description = "Runs the tests using the built run.js file.";
454456
task("runtests").flags = {
455457
"-t --tests=<regex>": "Pattern for tests to run.",
@@ -469,7 +471,7 @@ task("runtests").flags = {
469471
};
470472

471473
const runTestsParallel = () => runConsoleTests(testRunner, "min", /*runInParallel*/ cmdLineOptions.workers > 1, /*watchMode*/ false);
472-
task("runtests-parallel", series(/*preBuild, preTest,*/ runTestsParallel /*, postTest*/)); // !!!TODO!!!
474+
task("runtests-parallel", series(/*preBuild, preTest,*/ runTestsParallel /*, postTest*/)); // TODO(jakebailey): fix this for modules
473475
task("runtests-parallel").description = "Runs all the tests in parallel using the built run.js file.";
474476
task("runtests-parallel").flags = {
475477
" --no-lint": "disables lint.",

src/compiler/corePublic.ts

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { ShimCollections } from "../shims/collectionShims";
2-
import { getIterator } from "./core";
3-
import { MatchingKeys } from "./types";
1+
// import { ShimCollections } from "../shims/collectionShims";
2+
// import { getIterator } from "./core";
3+
// import { MatchingKeys } from "./types";
44

55
// WARNING: The script `configurePrerelease.ts` uses a regexp to parse out these values.
66
// If changing the text in this section, be sure to test `configurePrerelease` too.
@@ -115,56 +115,56 @@ export const enum Comparison {
115115
GreaterThan = 1
116116
}
117117

118-
/* @internal */
119-
namespace NativeCollections {
120-
declare const self: any;
121-
122-
const globals = typeof globalThis !== "undefined" ? globalThis :
123-
typeof global !== "undefined" ? global :
124-
typeof self !== "undefined" ? self :
125-
undefined;
126-
127-
/**
128-
* Returns the native Map implementation if it is available and compatible (i.e. supports iteration).
129-
*/
130-
export function tryGetNativeMap(): MapConstructor | undefined {
131-
// Internet Explorer's Map doesn't support iteration, so don't use it.
132-
const gMap = globals?.Map;
133-
// eslint-disable-next-line no-in-operator
134-
return typeof gMap !== "undefined" && "entries" in gMap.prototype && new gMap([[0, 0]]).size === 1 ? gMap : undefined;
135-
}
136-
137-
/**
138-
* Returns the native Set implementation if it is available and compatible (i.e. supports iteration).
139-
*/
140-
export function tryGetNativeSet(): SetConstructor | undefined {
141-
// Internet Explorer's Set doesn't support iteration, so don't use it.
142-
const gSet = globals?.Set;
143-
// eslint-disable-next-line no-in-operator
144-
return typeof gSet !== "undefined" && "entries" in gSet.prototype && new gSet([0]).size === 1 ? gSet : undefined;
145-
}
146-
}
118+
// /* @internal */
119+
// namespace NativeCollections {
120+
// declare const self: any;
121+
122+
// const globals = typeof globalThis !== "undefined" ? globalThis :
123+
// typeof global !== "undefined" ? global :
124+
// typeof self !== "undefined" ? self :
125+
// undefined;
126+
127+
// /**
128+
// * Returns the native Map implementation if it is available and compatible (i.e. supports iteration).
129+
// */
130+
// export function tryGetNativeMap(): MapConstructor | undefined {
131+
// // Internet Explorer's Map doesn't support iteration, so don't use it.
132+
// const gMap = globals?.Map;
133+
// // eslint-disable-next-line no-in-operator
134+
// return typeof gMap !== "undefined" && "entries" in gMap.prototype && new gMap([[0, 0]]).size === 1 ? gMap : undefined;
135+
// }
136+
137+
// /**
138+
// * Returns the native Set implementation if it is available and compatible (i.e. supports iteration).
139+
// */
140+
// export function tryGetNativeSet(): SetConstructor | undefined {
141+
// // Internet Explorer's Set doesn't support iteration, so don't use it.
142+
// const gSet = globals?.Set;
143+
// // eslint-disable-next-line no-in-operator
144+
// return typeof gSet !== "undefined" && "entries" in gSet.prototype && new gSet([0]).size === 1 ? gSet : undefined;
145+
// }
146+
// }
147147

148148
/* @internal */
149-
export const Map = getCollectionImplementation("Map", "tryGetNativeMap", "createMapShim");
150-
/* @internal */
151-
export const Set = getCollectionImplementation("Set", "tryGetNativeSet", "createSetShim");
152-
149+
export const Map: MapConstructor = globalThis.Map; // TODO(jakebailey): fix this for modules
153150
/* @internal */
154-
type GetIteratorCallback = <I extends readonly any[] | ReadonlySet<any> | ReadonlyESMap<any, any> | undefined>(iterable: I) => Iterator<
155-
I extends ReadonlyESMap<infer K, infer V> ? [K, V] :
156-
I extends ReadonlySet<infer T> ? T :
157-
I extends readonly (infer T)[] ? T :
158-
I extends undefined ? undefined :
159-
never>;
160-
161-
/* @internal */
162-
function getCollectionImplementation<
163-
K1 extends MatchingKeys<typeof NativeCollections, () => any>,
164-
K2 extends MatchingKeys<typeof ShimCollections, (getIterator?: GetIteratorCallback) => ReturnType<(typeof NativeCollections)[K1]>>
165-
>(name: string, nativeFactory: K1, shimFactory: K2): NonNullable<ReturnType<(typeof NativeCollections)[K1]>> {
166-
// NOTE: ts.ShimCollections will be defined for typescriptServices.js but not for tsc.js, so we must test for it.
167-
const constructor = NativeCollections[nativeFactory]() ?? ShimCollections?.[shimFactory](getIterator);
168-
if (constructor) return constructor as NonNullable<ReturnType<(typeof NativeCollections)[K1]>>;
169-
throw new Error(`TypeScript requires an environment that provides a compatible native ${name} implementation.`);
170-
}
151+
export const Set: SetConstructor = globalThis.Set as any; // TODO(jakebailey): fix this for modules
152+
153+
// /* @internal */
154+
// type GetIteratorCallback = <I extends readonly any[] | ReadonlySet<any> | ReadonlyESMap<any, any> | undefined>(iterable: I) => Iterator<
155+
// I extends ReadonlyESMap<infer K, infer V> ? [K, V] :
156+
// I extends ReadonlySet<infer T> ? T :
157+
// I extends readonly (infer T)[] ? T :
158+
// I extends undefined ? undefined :
159+
// never>;
160+
161+
// /* @internal */
162+
// function getCollectionImplementation<
163+
// K1 extends MatchingKeys<typeof NativeCollections, () => any>,
164+
// K2 extends MatchingKeys<typeof ShimCollections, (getIterator?: GetIteratorCallback) => ReturnType<(typeof NativeCollections)[K1]>>
165+
// >(name: string, nativeFactory: K1, shimFactory: K2): NonNullable<ReturnType<(typeof NativeCollections)[K1]>> {
166+
// // NOTE: ts.ShimCollections will be defined for typescriptServices.js but not for tsc.js, so we must test for it.
167+
// const constructor = NativeCollections[nativeFactory]() ?? ShimCollections?.[shimFactory](getIterator);
168+
// if (constructor) return constructor as NonNullable<ReturnType<(typeof NativeCollections)[K1]>>;
169+
// throw new Error(`TypeScript requires an environment that provides a compatible native ${name} implementation.`);
170+
// }

src/compiler/debug.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as ts from "./_namespaces/ts";
1+
// import * as ts from "./_namespaces/ts";
22
import {
33
AnyFunction, AssertionLevel, compareValues, every, getOwnKeys, hasProperty, map, noop, stableSort,
44
} from "./core";
@@ -12,14 +12,15 @@ import {
1212
isThisTypeNode, isTupleTypeNode, isTypeLiteralNode, isTypeOperatorNode, isTypeParameterDeclaration,
1313
isTypePredicateNode, isTypeQueryNode, isTypeReferenceNode, isUnionTypeNode,
1414
} from "./factory/nodeTests";
15-
import { getDirectoryPath, resolvePath } from "./path";
15+
// import { getDirectoryPath, resolvePath } from "./path";
1616
import { Version } from "./semver";
17-
import { sys } from "./sys";
17+
// import { sys } from "./sys";
1818
import {
1919
BigIntLiteralType, EmitFlags, FlowFlags, FlowNode, FlowNodeBase, IntrinsicType, LiteralType, MatchingKeys,
20-
ModifierFlags, Node, NodeArray, NodeFlags, ObjectFlags, ObjectType, RequireResult, Signature, SignatureFlags,
20+
ModifierFlags, Node, NodeArray, NodeFlags, ObjectFlags, ObjectType, Signature, SignatureFlags,
2121
SnippetKind, Symbol, SymbolFlags, SyntaxKind, TransformFlags, Type, TypeFlags,
2222
} from "./types";
23+
import * as types from "./types";
2324
import {
2425
formatStringFromArgs, getEffectiveModifierFlagsNoCache, getEmitFlags, getSourceFileOfNode,
2526
getSourceTextOfNodeFromSourceFile, nodeIsSynthesized, objectAllocator,
@@ -368,53 +369,53 @@ export namespace Debug {
368369
}
369370

370371
export function formatSyntaxKind(kind: SyntaxKind | undefined): string {
371-
return formatEnum(kind, (ts as any).SyntaxKind, /*isFlags*/ false);
372+
return formatEnum(kind, (types as any).SyntaxKind, /*isFlags*/ false);
372373
}
373374

374375
export function formatSnippetKind(kind: SnippetKind | undefined): string {
375-
return formatEnum(kind, (ts as any).SnippetKind, /*isFlags*/ false);
376+
return formatEnum(kind, (types as any).SnippetKind, /*isFlags*/ false);
376377
}
377378

378379
export function formatNodeFlags(flags: NodeFlags | undefined): string {
379-
return formatEnum(flags, (ts as any).NodeFlags, /*isFlags*/ true);
380+
return formatEnum(flags, (types as any).NodeFlags, /*isFlags*/ true);
380381
}
381382

382383
export function formatModifierFlags(flags: ModifierFlags | undefined): string {
383-
return formatEnum(flags, (ts as any).ModifierFlags, /*isFlags*/ true);
384+
return formatEnum(flags, (types as any).ModifierFlags, /*isFlags*/ true);
384385
}
385386

386387
export function formatTransformFlags(flags: TransformFlags | undefined): string {
387-
return formatEnum(flags, (ts as any).TransformFlags, /*isFlags*/ true);
388+
return formatEnum(flags, (types as any).TransformFlags, /*isFlags*/ true);
388389
}
389390

390391
export function formatEmitFlags(flags: EmitFlags | undefined): string {
391-
return formatEnum(flags, (ts as any).EmitFlags, /*isFlags*/ true);
392+
return formatEnum(flags, (types as any).EmitFlags, /*isFlags*/ true);
392393
}
393394

394395
export function formatSymbolFlags(flags: SymbolFlags | undefined): string {
395-
return formatEnum(flags, (ts as any).SymbolFlags, /*isFlags*/ true);
396+
return formatEnum(flags, (types as any).SymbolFlags, /*isFlags*/ true);
396397
}
397398

398399
export function formatTypeFlags(flags: TypeFlags | undefined): string {
399-
return formatEnum(flags, (ts as any).TypeFlags, /*isFlags*/ true);
400+
return formatEnum(flags, (types as any).TypeFlags, /*isFlags*/ true);
400401
}
401402

402403
export function formatSignatureFlags(flags: SignatureFlags | undefined): string {
403-
return formatEnum(flags, (ts as any).SignatureFlags, /*isFlags*/ true);
404+
return formatEnum(flags, (types as any).SignatureFlags, /*isFlags*/ true);
404405
}
405406

406407
export function formatObjectFlags(flags: ObjectFlags | undefined): string {
407-
return formatEnum(flags, (ts as any).ObjectFlags, /*isFlags*/ true);
408+
return formatEnum(flags, (types as any).ObjectFlags, /*isFlags*/ true);
408409
}
409410

410411
export function formatFlowFlags(flags: FlowFlags | undefined): string {
411-
return formatEnum(flags, (ts as any).FlowFlags, /*isFlags*/ true);
412+
return formatEnum(flags, (types as any).FlowFlags, /*isFlags*/ true);
412413
}
413414

414415
let isDebugInfoEnabled = false;
415416

416417
interface ExtendedDebugModule {
417-
init(_ts: typeof ts): void;
418+
init(_ts: any/* typeof ts */): void; // TODO(jakebailey): fix this for modules
418419
formatControlFlowGraph(flowNode: FlowNode): string;
419420
}
420421

@@ -461,7 +462,7 @@ export namespace Debug {
461462
return `${flowHeader}${remainingFlags ? ` (${formatFlowFlags(remainingFlags)})`: ""}`;
462463
}
463464
},
464-
__debugFlowFlags: { get(this: FlowNodeBase) { return formatEnum(this.flags, (ts as any).FlowFlags, /*isFlags*/ true); } },
465+
__debugFlowFlags: { get(this: FlowNodeBase) { return formatEnum(this.flags, (types as any).FlowFlags, /*isFlags*/ true); } },
465466
__debugToString: { value(this: FlowNodeBase) { return formatControlFlowGraph(this); } }
466467
});
467468
}
@@ -698,14 +699,15 @@ export namespace Debug {
698699

699700
// attempt to load extended debugging information
700701
try {
701-
if (sys && sys.require) {
702-
const basePath = getDirectoryPath(resolvePath(sys.getExecutingFilePath()));
703-
const result = sys.require(basePath, "./compiler-debug") as RequireResult<ExtendedDebugModule>;
704-
if (!result.error) {
705-
result.module.init(ts);
706-
extendedDebugModule = result.module;
707-
}
708-
}
702+
// TODO(jakebailey): fix this for modules
703+
// if (sys && sys.require) {
704+
// const basePath = getDirectoryPath(resolvePath(sys.getExecutingFilePath()));
705+
// const result = sys.require(basePath, "./compiler-debug") as RequireResult<ExtendedDebugModule>;
706+
// if (!result.error) {
707+
// result.module.init(ts);
708+
// extendedDebugModule = result.module;
709+
// }
710+
// }
709711
}
710712
catch {
711713
// do nothing

src/compiler/semver.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,26 @@ const numericIdentifierRegExp = /^(0|[1-9]\d*)$/;
3333
* Describes a precise semantic version number, https://semver.org
3434
*/
3535
export class Version {
36-
static readonly zero = new Version(0, 0, 0);
36+
static readonly zero = new Version();
3737

3838
readonly major: number;
3939
readonly minor: number;
4040
readonly patch: number;
4141
readonly prerelease: readonly string[];
4242
readonly build: readonly string[];
4343

44+
constructor();
4445
constructor(text: string);
4546
constructor(major: number, minor?: number, patch?: number, prerelease?: string, build?: string);
46-
constructor(major: number | string, minor = 0, patch = 0, prerelease = "", build = "") {
47+
constructor(major?: number | string, minor = 0, patch = 0, prerelease = "", build = "") {
48+
if (major === undefined) {
49+
// HACK: constructor for Version.zero which does not use Debug.
50+
// TODO(jakebailey): fix this for modules
51+
this.major = this.minor = this.patch = 0;
52+
this.prerelease = this.build = emptyArray;
53+
return;
54+
}
55+
4756
if (typeof major === "string") {
4857
const result = Debug.checkDefined(tryParseComponents(major), "Invalid version");
4958
({ major, minor, patch, prerelease, build } = result);

0 commit comments

Comments
 (0)