Skip to content

Commit

Permalink
feat: do not check injection on $ or _ prefixed props
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Feb 2, 2024
1 parent 205ff60 commit 0edd83e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cordis",
"description": "AOP Framework for Modern JavaScript Applications",
"version": "3.7.0",
"version": "3.7.1",
"sideEffects": false,
"type": "module",
"main": "lib/index.cjs",
Expand Down Expand Up @@ -47,7 +47,6 @@
"chai-as-promised": "^7.1.1",
"dtsc": "^3.0.1",
"esbuild": "^0.18.20",
"esbuild-register": "^3.5.0",
"shx": "^0.3.4",
"tsx": "^4.7.0",
"typescript": "^5.3.2"
Expand Down
6 changes: 4 additions & 2 deletions src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,11 @@ export class Context {
// - prototype: prototype detection
// - then: async function return
if (['prototype', 'then', 'registry', 'lifecycle'].includes(name)) return
// Case 3: access directly from root
// Case 3: `$` or `_` prefix
if (name[0] === '$' || name[0] === '_') return
// Case 4: access directly from root
if (!ctx.runtime.plugin) return
// Case 4: inject in ancestor contexts
// Case 5: inject in ancestor contexts
let parent = ctx
while (parent.runtime.plugin) {
for (const key of parent.runtime.inject) {
Expand Down
4 changes: 4 additions & 0 deletions tests/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ describe('Service', () => {
root.on('internal/warning', warn)

root.plugin((ctx) => {
// `$bar` is `$`-prefixed
ctx['$bar']
expect(warn.mock.calls).to.have.length(0)

// `bar` is neither defined on context nor declared as injection
ctx.bar
expect(warn.mock.calls).to.have.length(1)
Expand Down

0 comments on commit 0edd83e

Please sign in to comment.