🔒 fix: resolve the metadata symbol into a binding, not a per-use lookup
Review on #4 flagged that the Symbol.metadata polyfill is a module-level side effect while package.json declares "sideEffects": false, so a bundler is permitted to drop the module. Checking it narrowed the concern and corrected half of it. The decorator transforms are not exposed: esbuild's helper is __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name) which already falls back. The exposure was in this library's own read path, which used `Symbol.metadata` directly. Had the symbol been absent, `clazz[undefined]` would read a property literally named "undefined", modelOf() would return an empty model, and every object would validate clean — silent success, the worst failure mode a validation library can have. The key is now resolved once into METADATA_KEY, with the same Symbol.for fallback the transforms use, and all reads and writes go through it. The global assignment stays for consumer emit that reads Symbol.metadata directly, and package.json now lists metadata.js under sideEffects so bundlers keep it. 193 tests pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SAcqrz3FcadkYr3xG32CjK
This commit is contained in:
+5
-2
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "cereale",
|
||||
"version": "2.0.0",
|
||||
"description": "Strongly typed JSON mapping and validation for TypeScript classes — validated domain objects, not validated data",
|
||||
"description": "Strongly typed JSON mapping and validation for TypeScript classes \u2014 validated domain objects, not validated data",
|
||||
"type": "module",
|
||||
"main": "./dist/cjs/index.js",
|
||||
"module": "./dist/esm/index.js",
|
||||
@@ -13,7 +13,10 @@
|
||||
"require": "./dist/cjs/index.js"
|
||||
}
|
||||
},
|
||||
"sideEffects": false,
|
||||
"sideEffects": [
|
||||
"./dist/esm/metadata.js",
|
||||
"./dist/cjs/metadata.js"
|
||||
],
|
||||
"files": [
|
||||
"dist"
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user