fix(scoped-elements): refactor to remove optional chain in Cache

This commit is contained in:
Matthew Ailes
2020-11-11 16:18:32 -05:00
committed by Lars den Bakker
parent 1375963db8
commit 9fb1c1319d
3 changed files with 19 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
'@open-wc/scoped-elements': patch
---
refactor to remove optional chaining syntax in Cache file for better tooling compatibility

View File

@@ -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));
}
}

View File

@@ -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);