Skip to content

Commit 577cb61

Browse files
authored
fix: analyze splitting regardless even when sideEffects: false (#1179)
Currently we don't analyze splitting when `sideEffects: false`. This can result in duplication of symbols in shared files of entry-points. Even if there are no side effects, this duplication can cause issues with singletons or identify comparisons.
1 parent 5f13d97 commit 577cb61

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

server/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (ctx *BuildContext) Build() (meta *BuildMeta, err error) {
147147
}
148148

149149
// analyze splitting modules
150-
if !ctx.pkgJson.SideEffectsFalse && ctx.bundleMode == BundleDefault && ctx.pkgJson.Exports.Len() > 1 {
150+
if ctx.bundleMode == BundleDefault && ctx.pkgJson.Exports.Len() > 1 {
151151
ctx.status = "analyze"
152152
err = ctx.analyzeSplitting()
153153
if err != nil {

test/issue-1178/test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { assert, assertEquals } from "jsr:@std/assert";
2+
3+
// Needed as some Angular classes would need to be compiled.
4+
import "http://localhost:8080/@angular/[email protected]";
5+
6+
import {
7+
FactoryProvider,
8+
Provider,
9+
RendererFactory2,
10+
} from "http://localhost:8080/@angular/[email protected]";
11+
import { ɵDomRendererFactory2 } from "http://localhost:8080/@angular/[email protected]";
12+
import { provideAnimations } from "http://localhost:8080/@angular/[email protected]/animations";
13+
14+
// related issue: https://github.com/esm-dev/esm.sh/issues/1178
15+
Deno.test(
16+
"testing identity of classes matches between entry-points",
17+
() => {
18+
const renderFactoryProvider = provideAnimations()
19+
.find((r: Provider): r is FactoryProvider =>
20+
(r as Partial<FactoryProvider>).provide === RendererFactory2
21+
);
22+
assert(
23+
renderFactoryProvider !== undefined,
24+
"Expected renderer factory provider to be found.",
25+
);
26+
assertEquals(
27+
renderFactoryProvider.deps?.[0],
28+
ɵDomRendererFactory2,
29+
"Expected identity of DomRendererFactory to match between entry-points.",
30+
);
31+
},
32+
);

0 commit comments

Comments
 (0)