diff --git a/.changeset/plenty-plants-hunt.md b/.changeset/plenty-plants-hunt.md new file mode 100644 index 00000000..5fec8bab --- /dev/null +++ b/.changeset/plenty-plants-hunt.md @@ -0,0 +1,5 @@ +--- +'@open-wc/scoped-elements': patch +--- + +refactor to remove optional chaining syntax in Cache file for better tooling compatibility diff --git a/packages/scoped-elements/src/Cache.js b/packages/scoped-elements/src/Cache.js index da1781ff..036396dd 100644 --- a/packages/scoped-elements/src/Cache.js +++ b/packages/scoped-elements/src/Cache.js @@ -19,7 +19,7 @@ export class Cache { * @return {boolean} */ has(key) { - return !!(this._cache.has(key) || this._parent?._cache.has(key)); + return !!(this._cache.has(key) || (this._parent && this._parent._cache.has(key))); } /** @@ -44,6 +44,6 @@ export class Cache { * @return {Q} */ get(key) { - return this._cache.get(key) || this._parent?._cache.get(key); + return this._cache.get(key) || (this._parent && this._parent._cache.get(key)); } } diff --git a/packages/scoped-elements/test-web/Cache.test.js b/packages/scoped-elements/test-web/Cache.test.js index b7ced4dc..53e8f94a 100644 --- a/packages/scoped-elements/test-web/Cache.test.js +++ b/packages/scoped-elements/test-web/Cache.test.js @@ -24,6 +24,12 @@ describe('Cache', () => { expect(cache.has('key')).to.be.false; }); + it(`should return false if the key does not exist and no parent exists`, () => { + const cache = new Cache(); + + expect(cache.has('key')).to.be.false; + }); + it(`should return true if the key exist`, () => { const cache = new Cache(); cache._cache.set('key', 'value'); @@ -93,6 +99,12 @@ describe('Cache', () => { expect(cache.get('key')).to.be.undefined; }); + it('should return undefined in case key does not exist and parent does not exist', () => { + const cache = new Cache(); + + expect(cache.get('key')).to.be.undefined; + }); + it('should return undefined in case the key is not provided', () => { const parent = new Cache(); const cache = new Cache(parent);