Skip to content

Commit b56483f

Browse files
authored
Remove shims project (#50049)
1 parent 7f1dc78 commit b56483f

File tree

13 files changed

+17
-954
lines changed

13 files changed

+17
-954
lines changed

Gulpfile.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,12 @@ const localize = async () => {
9292
}
9393
};
9494

95-
const buildShims = () => buildProject("src/shims");
96-
const cleanShims = () => cleanProject("src/shims");
97-
cleanTasks.push(cleanShims);
98-
9995
const buildDebugTools = () => buildProject("src/debug");
10096
const cleanDebugTools = () => cleanProject("src/debug");
10197
cleanTasks.push(cleanDebugTools);
10298

103-
const buildShimsAndTools = parallel(buildShims, buildDebugTools);
104-
10599
// Pre-build steps when targeting the LKG compiler
106-
const lkgPreBuild = parallel(generateLibs, series(buildScripts, generateDiagnostics, buildShimsAndTools));
100+
const lkgPreBuild = parallel(generateLibs, series(buildScripts, generateDiagnostics, buildDebugTools));
107101

108102
const buildTsc = () => buildProject("src/tsc");
109103
task("tsc", series(lkgPreBuild, buildTsc));
@@ -119,7 +113,7 @@ task("watch-tsc", series(lkgPreBuild, parallel(watchLib, watchDiagnostics, watch
119113
task("watch-tsc").description = "Watch for changes and rebuild the command-line compiler only.";
120114

121115
// Pre-build steps when targeting the built/local compiler.
122-
const localPreBuild = parallel(generateLibs, series(buildScripts, generateDiagnostics, buildShimsAndTools, buildTsc));
116+
const localPreBuild = parallel(generateLibs, series(buildScripts, generateDiagnostics, buildDebugTools, buildTsc));
123117

124118
// Pre-build steps to use based on supplied options.
125119
const preBuild = cmdLineOptions.lkg ? lkgPreBuild : localPreBuild;

src/compiler/corePublic.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -124,45 +124,34 @@ namespace ts {
124124
/**
125125
* Returns the native Map implementation if it is available and compatible (i.e. supports iteration).
126126
*/
127-
export function tryGetNativeMap(): MapConstructor | undefined {
127+
export function tryGetNativeMap(): MapConstructor {
128128
// Internet Explorer's Map doesn't support iteration, so don't use it.
129129
const gMap = globals?.Map;
130130
// eslint-disable-next-line no-in-operator
131-
return typeof gMap !== "undefined" && "entries" in gMap.prototype && new gMap([[0, 0]]).size === 1 ? gMap : undefined;
131+
const constructor = typeof gMap !== "undefined" && "entries" in gMap.prototype && new gMap([[0, 0]]).size === 1 ? gMap : undefined;
132+
if (!constructor) {
133+
throw new Error("No compatible Map implementation found.");
134+
}
135+
return constructor;
132136
}
133137

134138
/**
135139
* Returns the native Set implementation if it is available and compatible (i.e. supports iteration).
136140
*/
137-
export function tryGetNativeSet(): SetConstructor | undefined {
141+
export function tryGetNativeSet(): SetConstructor {
138142
// Internet Explorer's Set doesn't support iteration, so don't use it.
139143
const gSet = globals?.Set;
140144
// eslint-disable-next-line no-in-operator
141-
return typeof gSet !== "undefined" && "entries" in gSet.prototype && new gSet([0]).size === 1 ? gSet : undefined;
145+
const constructor = typeof gSet !== "undefined" && "entries" in gSet.prototype && new gSet([0]).size === 1 ? gSet : undefined;
146+
if (!constructor) {
147+
throw new Error("No compatible Set implementation found.");
148+
}
149+
return constructor;
142150
}
143151
}
144152

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

src/compiler/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
},
77

88
"references": [
9-
{ "path": "../shims" }
109
],
1110

1211
"files": [

src/compiler/tsconfig.release.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
"preserveConstEnums": false
77
},
88
"references": [
9-
{ "path": "../shims" }
109
]
1110
}

src/services/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"outFile": "../../built/local/services.js"
55
},
66
"references": [
7-
{ "path": "../shims" },
87
{ "path": "../compiler" },
98
{ "path": "../jsTyping" }
109
],

src/shims/collectionShims.ts

Lines changed: 0 additions & 267 deletions
This file was deleted.

src/shims/tsconfig.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)