Skip to content

Commit

Permalink
Fix insufficient cache invalidation in the incremental parser
Browse files Browse the repository at this point in the history
  • Loading branch information
TheUnlocked committed Apr 19, 2024
1 parent 3f84e99 commit 7a78bb9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@necode-org/mike",
"version": "0.3.6",
"version": "0.3.7",
"author": {
"name": "Trevor Paley",
"url": "https://github.com/TheUnlocked"
Expand Down
19 changes: 13 additions & 6 deletions src/parser/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,21 @@ export class Parser extends DiagnosticsMixin implements Rules {
for (const token of removedTokens) {
let node = this.memoTable.get(token)?.[0]?.node;
this.memoTable.delete(token);
while (node) {
const firstToken = node.tokens!.find(x => !isTrivia(x))!;

const memoEntry = this.memoTable.get(firstToken);
if (memoEntry) {
this.memoTable.set(firstToken, memoEntry.filter(x => x.node !== node));
if (node) {
for (const token of node.tokens!) {
this.memoTable.delete(token);
}

while (node) {
const firstToken = node.tokens!.find(x => !isTrivia(x))!;

const memoEntry = this.memoTable.get(firstToken);
if (memoEntry) {
this.memoTable.set(firstToken, memoEntry.filter(x => x.node !== node));
}
node = node.parent;
}
node = node.parent;
}
}

Expand Down
9 changes: 9 additions & 0 deletions tests/grammar/incremental.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ export default () => describe('incremental', () => {
}
`]}`;

testIncremental('modify condition in if statement')`
on foo() {
let x = 1;
if x ${['', '== 1']} {
}
}
`;

it('should be a no-op if a mutation is reversed', () => {
const p1 = new Parser();
// 0 5 10 15 20 25 30 35 40
Expand Down

0 comments on commit 7a78bb9

Please sign in to comment.