Skip to content

Commit cbe037f

Browse files
committed
Revert "fix: use custom set in transpiled module to bypass polyfill of Array,from (#6604)"
This reverts commit 206da7c.
1 parent 206da7c commit cbe037f

File tree

3 files changed

+37
-79
lines changed

3 files changed

+37
-79
lines changed

packages/sandpack-core/src/manager.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -626,13 +626,11 @@ export default class Manager implements IEvaluator {
626626
}
627627

628628
verifyTreeTranspiled() {
629-
const promises = [];
630-
for (const tModule of this.getTranspiledModules()) {
631-
if (tModule.shouldTranspile()) {
632-
promises.push(tModule.transpile(this));
633-
}
634-
}
635-
return Promise.all(promises);
629+
return Promise.all(
630+
this.getTranspiledModules()
631+
.filter(tModule => tModule.shouldTranspile())
632+
.map(tModule => tModule.transpile(this))
633+
);
636634
}
637635

638636
clearCompiledCache() {

packages/sandpack-core/src/transpiled-module/CustomSet.ts

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

packages/sandpack-core/src/transpiled-module/transpiled-module.ts

Lines changed: 32 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import HMR from './hmr';
2323
import { splitQueryFromPath } from './utils/query-path';
2424
import { getModuleUrl } from './module-url';
2525
import delay from '../utils/delay';
26-
import { CustomSet } from './CustomSet';
2726

2827
declare const BrowserFS: any;
2928

@@ -164,11 +163,11 @@ export class TranspiledModule {
164163
errors: Array<ModuleError>;
165164
warnings: Array<ModuleWarning>;
166165
compilation: Compilation | null = null;
167-
initiators: CustomSet<TranspiledModule>; // eslint-disable-line no-use-before-define
168-
dependencies: CustomSet<TranspiledModule>; // eslint-disable-line no-use-before-define
166+
initiators: Set<TranspiledModule>; // eslint-disable-line no-use-before-define
167+
dependencies: Set<TranspiledModule>; // eslint-disable-line no-use-before-define
169168
asyncDependencies: Array<Promise<TranspiledModule>>; // eslint-disable-line no-use-before-define
170-
transpilationDependencies: CustomSet<TranspiledModule>;
171-
transpilationInitiators: CustomSet<TranspiledModule>;
169+
transpilationDependencies: Set<TranspiledModule>;
170+
transpilationInitiators: Set<TranspiledModule>;
172171

173172
// Unique identifier
174173
hash: string;
@@ -197,11 +196,11 @@ export class TranspiledModule {
197196
this.errors = [];
198197
this.warnings = [];
199198
this.childModules = [];
200-
this.transpilationDependencies = new CustomSet();
201-
this.dependencies = new CustomSet();
199+
this.transpilationDependencies = new Set();
200+
this.dependencies = new Set();
202201
this.asyncDependencies = [];
203-
this.transpilationInitiators = new CustomSet();
204-
this.initiators = new CustomSet();
202+
this.transpilationInitiators = new Set();
203+
this.initiators = new Set();
205204
this.isEntry = false;
206205
this.isTestFile = false;
207206

@@ -221,7 +220,7 @@ export class TranspiledModule {
221220
this.reset();
222221

223222
// Reset parents
224-
this.initiators.values().forEach(tModule => {
223+
this.initiators.forEach(tModule => {
225224
tModule.resetTranspilation();
226225
});
227226

@@ -252,8 +251,7 @@ export class TranspiledModule {
252251
}
253252

254253
resetTranspilation() {
255-
this.transpilationInitiators
256-
.values()
254+
Array.from(this.transpilationInitiators)
257255
.filter(t => t.source)
258256
.forEach(dep => {
259257
dep.resetTranspilation();
@@ -265,7 +263,7 @@ export class TranspiledModule {
265263
this.errors = [];
266264
this.warnings = [];
267265

268-
this.dependencies.values().forEach(t => {
266+
Array.from(this.dependencies).forEach(t => {
269267
t.initiators.delete(this);
270268
});
271269
// Don't do it for transpilation dependencies, since those cannot be traced back since we also reset transpilation of them.
@@ -283,15 +281,13 @@ export class TranspiledModule {
283281
if (this.hmrConfig && this.hmrConfig.isHot()) {
284282
this.hmrConfig.setDirty(true);
285283
} else {
286-
this.initiators
287-
.values()
284+
Array.from(this.initiators)
288285
.filter(t => t.compilation)
289286
.forEach(initiator => {
290287
initiator.resetCompilation();
291288
});
292289

293-
this.transpilationInitiators
294-
.values()
290+
Array.from(this.transpilationInitiators)
295291
.filter(t => t.compilation)
296292
.forEach(dep => {
297293
dep.resetCompilation();
@@ -300,8 +296,7 @@ export class TranspiledModule {
300296
// If this is an entry we want all direct entries to be reset as well.
301297
// Entries generally have side effects
302298
if (this.isEntry) {
303-
this.dependencies
304-
.values()
299+
Array.from(this.dependencies)
305300
.filter(t => t.compilation && t.isEntry)
306301
.forEach(dep => {
307302
dep.resetCompilation();
@@ -318,7 +313,7 @@ export class TranspiledModule {
318313
return (
319314
!this.source &&
320315
!this.isTestFile &&
321-
!(this.initiators.size() === 0 && this.transpilationInitiators.size() > 0)
316+
!(this.initiators.size === 0 && this.transpilationInitiators.size > 0)
322317
);
323318
}
324319

@@ -566,16 +561,15 @@ export class TranspiledModule {
566561

567562
// Remove this module from the initiators of old deps, so we can populate a
568563
// fresh cache
569-
this.dependencies.values().forEach(tModule => {
564+
this.dependencies.forEach(tModule => {
570565
tModule.initiators.delete(this);
571566
});
572-
this.transpilationDependencies.values().forEach(tModule => {
567+
this.transpilationDependencies.forEach(tModule => {
573568
tModule.transpilationInitiators.delete(this);
574569
});
575570
this.childModules.forEach(tModule => {
576571
tModule.dispose(manager);
577572
});
578-
579573
this.dependencies.clear();
580574
this.transpilationDependencies.clear();
581575
this.childModules.length = 0;
@@ -697,8 +691,10 @@ export class TranspiledModule {
697691
this.asyncDependencies = [];
698692

699693
await Promise.all([
700-
...this.transpilationInitiators.values().map(t => t.transpile(manager)),
701-
...this.dependencies.values().map(t => t.transpile(manager)),
694+
...Array.from(this.transpilationInitiators).map(t =>
695+
t.transpile(manager)
696+
),
697+
...Array.from(this.dependencies).map(t => t.transpile(manager)),
702698
]);
703699

704700
return this;
@@ -951,8 +947,7 @@ export class TranspiledModule {
951947
this.hmrConfig = this.hmrConfig || new HMR();
952948

953949
// We have to bubble up, so reset compilation of parents
954-
this.initiators
955-
.values()
950+
Array.from(this.initiators)
956951
.filter(t => t.compilation)
957952
.forEach(dep => {
958953
dep.resetCompilation();
@@ -1098,8 +1093,8 @@ export class TranspiledModule {
10981093

10991094
postTranspile(manager: Manager) {
11001095
if (
1101-
this.initiators.size() === 0 &&
1102-
this.transpilationInitiators.size() === 0 &&
1096+
this.initiators.size === 0 &&
1097+
this.transpilationInitiators.size === 0 &&
11031098
!this.isEntry &&
11041099
!manager.isFirstLoad &&
11051100
// Don't delete stubbed modules, they are here for a reason, most probably
@@ -1133,7 +1128,6 @@ export class TranspiledModule {
11331128
const sourceEqualsCompiled = Boolean(
11341129
this.source && this.source.sourceEqualsCompiled
11351130
);
1136-
11371131
const serializableObject: SerializedTranspiledModule = {
11381132
query: this.query,
11391133
module: this.module,
@@ -1142,16 +1136,14 @@ export class TranspiledModule {
11421136

11431137
sourceEqualsCompiled,
11441138
childModules: this.childModules.map(m => m.getId()),
1145-
dependencies: this.dependencies.values().map(m => {
1146-
return m.getId();
1147-
}),
1148-
initiators: this.initiators.values().map(m => m.getId()),
1149-
transpilationDependencies: this.transpilationDependencies
1150-
.values()
1151-
.map(m => m.getId()),
1152-
transpilationInitiators: this.transpilationInitiators
1153-
.values()
1154-
.map(m => m.getId()),
1139+
dependencies: Array.from(this.dependencies).map(m => m.getId()),
1140+
initiators: Array.from(this.initiators).map(m => m.getId()),
1141+
transpilationDependencies: Array.from(
1142+
this.transpilationDependencies
1143+
).map(m => m.getId()),
1144+
transpilationInitiators: Array.from(this.transpilationInitiators).map(m =>
1145+
m.getId()
1146+
),
11551147
asyncDependencies: await Promise.all(
11561148
Array.from(this.asyncDependencies).map(m => m.then(x => x.getId()))
11571149
),

0 commit comments

Comments
 (0)