mirror of
https://github.com/jlengrand/open-wc.git
synced 2026-03-10 08:31:19 +00:00
fix(scoped-elements): refactor to remove optional chain in Cache
This commit is contained in:
committed by
Lars den Bakker
parent
1375963db8
commit
9fb1c1319d
5
.changeset/plenty-plants-hunt.md
Normal file
5
.changeset/plenty-plants-hunt.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@open-wc/scoped-elements': patch
|
||||
---
|
||||
|
||||
refactor to remove optional chaining syntax in Cache file for better tooling compatibility
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user