Skip to content

Commit 4172f02

Browse files
authored
refactor(runtime): seal ES module namespace object instead of feezing (#15914)
1 parent 63a39c2 commit 4172f02

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts

+11
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,22 @@ describe('vite-runtime initialization', async () => {
8787

8888
it('exports is not modifiable', async ({ runtime }) => {
8989
const mod = await runtime.executeUrl('/fixtures/simple.js')
90+
expect(Object.isSealed(mod)).toBe(true)
9091
expect(() => {
9192
mod.test = 'I am modified'
9293
}).toThrowErrorMatchingInlineSnapshot(
9394
`[TypeError: Cannot set property test of [object Module] which has only a getter]`,
9495
)
96+
expect(() => {
97+
delete mod.test
98+
}).toThrowErrorMatchingInlineSnapshot(
99+
`[TypeError: Cannot delete property 'test' of [object Module]]`,
100+
)
101+
expect(() => {
102+
Object.defineProperty(mod, 'test', { value: 'I am modified' })
103+
}).toThrowErrorMatchingInlineSnapshot(
104+
`[TypeError: Cannot redefine property: test]`,
105+
)
95106
expect(() => {
96107
mod.other = 'I am added'
97108
}).toThrowErrorMatchingInlineSnapshot(

packages/vite/src/node/ssr/runtime/esmRunner.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class ESModulesRunner implements ViteModuleRunner {
3434
context[ssrExportAllKey],
3535
)
3636

37-
Object.freeze(context[ssrModuleExportsKey])
37+
Object.seal(context[ssrModuleExportsKey])
3838
}
3939

4040
runExternalModule(filepath: string): Promise<any> {

0 commit comments

Comments
 (0)