-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): correct caching of touched declarations #4344
- Loading branch information
Showing
17 changed files
with
331 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import CoreDefStack from './core.def-stack'; | ||
|
||
describe('CoreDefStack', () => { | ||
it('returns empty map on empty pop', () => { | ||
const stack = new CoreDefStack(); | ||
|
||
const result1 = stack.pop(); | ||
const result2 = stack.pop(); | ||
|
||
expect(result1).toBeDefined(); | ||
expect(result2).toBeDefined(); | ||
expect(result1).not.toBe(result2); | ||
}); | ||
|
||
it('returns undefined on empty get', () => { | ||
const stack = new CoreDefStack(); | ||
expect(stack.get(CoreDefStack)).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { mapEntries } from './core.helpers'; | ||
|
||
export default class<K, V> { | ||
protected stack: Array<Map<K, V>> = []; | ||
|
||
public constructor() { | ||
this.push(); | ||
} | ||
|
||
public push() { | ||
this.stack.push(new Map()); | ||
} | ||
|
||
public pop(): Map<V, V> { | ||
return this.stack.pop() ?? new Map(); | ||
} | ||
|
||
public has(key: K): ReturnType<Map<K, V>['has']> { | ||
for (let i = this.stack.length - 1; i >= 0; i -= 1) { | ||
if (this.stack[i].has(key)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public get(key: K): ReturnType<Map<K, V>['get']> { | ||
for (let i = this.stack.length - 1; i >= 0; i -= 1) { | ||
if (this.stack[i].has(key)) { | ||
return this.stack[i].get(key); | ||
} | ||
} | ||
|
||
return undefined; | ||
} | ||
|
||
public set(key: K, value: V): this { | ||
for (let i = this.stack.length - 1; i >= 0; i -= 1) { | ||
this.stack[i].set(key, value); | ||
} | ||
|
||
return this; | ||
} | ||
|
||
public merge(resolutions: Map<K, V>): this { | ||
for (const [key, value] of mapEntries(resolutions)) { | ||
this.set(key, value); | ||
} | ||
|
||
return this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.