Skip to content

Commit dd3a6e6

Browse files
committed
fix(objects): remove incorrect NO_SIDE_EFFECTS annotations from property definers
The defineGetter, defineLazyGetter, and defineLazyGetters functions mutate objects by defining properties on them, so they have side effects. The /*@__NO_SIDE_EFFECTS__*/ annotations caused esbuild to incorrectly tree-shake these function calls when their return values weren't used, resulting in lazy getters returning undefined instead of computed values. Also removed double wrapping in defineLazyGetters where createLazyGetter was being called unnecessarily before passing to defineLazyGetter (which already calls createLazyGetter internally). Fixes three failing tests: - createConstantsObject > should create object with lazy getters - defineLazyGetters > should define multiple lazy getters - defineLazyGetters > should handle symbol keys in getters
1 parent 576adaa commit dd3a6e6

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

.config/esbuild.config.mjs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,17 @@ function createAliasPlugin() {
4040
// Intercept imports for aliased packages
4141
for (const [packageName, aliasPath] of Object.entries(aliases)) {
4242
// Match both exact package name and subpath imports
43-
build.onResolve({ filter: new RegExp(`^${packageName}(/|$)`) }, args => {
44-
// Handle subpath imports like '@socketsecurity/lib/spinner'
45-
const subpath = args.path.slice(packageName.length + 1)
46-
const resolvedPath = subpath ? path.join(aliasPath, subpath) : aliasPath
47-
return { path: resolvedPath, external: true }
48-
})
43+
build.onResolve(
44+
{ filter: new RegExp(`^${packageName}(/|$)`) },
45+
args => {
46+
// Handle subpath imports like '@socketsecurity/lib/spinner'
47+
const subpath = args.path.slice(packageName.length + 1)
48+
const resolvedPath = subpath
49+
? path.join(aliasPath, subpath)
50+
: aliasPath
51+
return { path: resolvedPath, external: true }
52+
},
53+
)
4954
}
5055
},
5156
}

src/objects.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ export function createConstantsObject(
272272
* console.log(Object.keys(obj)) // [] (non-enumerable)
273273
* ```
274274
*/
275-
/*@__NO_SIDE_EFFECTS__*/
276275
export function defineGetter<T>(
277276
object: object,
278277
propKey: PropertyKey,
@@ -309,7 +308,6 @@ export function defineGetter<T>(
309308
* console.log(obj.data) // Returns same data without logging
310309
* ```
311310
*/
312-
/*@__NO_SIDE_EFFECTS__*/
313311
export function defineLazyGetter<T>(
314312
object: object,
315313
propKey: PropertyKey,
@@ -346,7 +344,6 @@ export function defineLazyGetter<T>(
346344
* console.log(stats.initialized) // Set(['user', 'config'])
347345
* ```
348346
*/
349-
/*@__NO_SIDE_EFFECTS__*/
350347
export function defineLazyGetters(
351348
object: object,
352349
getterDefObj: GetterDefObj | undefined,
@@ -356,11 +353,7 @@ export function defineLazyGetters(
356353
const keys = ReflectOwnKeys(getterDefObj)
357354
for (let i = 0, { length } = keys; i < length; i += 1) {
358355
const key = keys[i] as PropertyKey
359-
defineLazyGetter(
360-
object,
361-
key,
362-
createLazyGetter(key, getterDefObj[key] as () => unknown, stats),
363-
)
356+
defineLazyGetter(object, key, getterDefObj[key] as () => unknown, stats)
364357
}
365358
}
366359
return object

0 commit comments

Comments
 (0)