mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 09:57:11 -05:00
fix(unstable): lint plugin :exit
called at wrong time (#28229)
The `:exit` selectors were called at the wrong time during visiting. They need to be called when going upwards and a node and all its children have been fully visited. Instead we called it when the node + all its sibling were visited which is wrong. Fixes https://github.com/denoland/deno/issues/28227
This commit is contained in:
parent
d3f6d66084
commit
cca55d3140
2 changed files with 30 additions and 5 deletions
|
@ -1186,11 +1186,6 @@ function traverse(ctx, visitors, idx, cancellationToken) {
|
|||
if (childIdx > AST_IDX_INVALID) {
|
||||
traverse(ctx, visitors, childIdx, cancellationToken);
|
||||
}
|
||||
|
||||
const nextIdx = readNext(buf, idx);
|
||||
if (nextIdx > AST_IDX_INVALID) {
|
||||
traverse(ctx, visitors, nextIdx, cancellationToken);
|
||||
}
|
||||
} finally {
|
||||
if (exits !== null) {
|
||||
for (let i = 0; i < exits.length; i++) {
|
||||
|
@ -1199,6 +1194,11 @@ function traverse(ctx, visitors, idx, cancellationToken) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
const nextIdx = readNext(buf, idx);
|
||||
if (nextIdx > AST_IDX_INVALID) {
|
||||
traverse(ctx, visitors, nextIdx, cancellationToken);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -101,6 +101,31 @@ Deno.test("Plugin - visitor enter/exit", () => {
|
|||
assertEquals(both.map((t) => t.selector), ["Identifier", "Identifier:exit"]);
|
||||
});
|
||||
|
||||
// https://github.com/denoland/deno/issues/28227
|
||||
Deno.test("Plugin - visitor enter/exit #2", () => {
|
||||
const log: string[] = [];
|
||||
|
||||
testPlugin("{}\nfoo;", {
|
||||
create() {
|
||||
return {
|
||||
"*": (node: Deno.lint.Node) => log.push(`-> ${node.type}`),
|
||||
"*:exit": (node: Deno.lint.Node) => log.push(`<- ${node.type}`),
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
assertEquals(log, [
|
||||
"-> Program",
|
||||
"-> BlockStatement",
|
||||
"<- BlockStatement",
|
||||
"-> ExpressionStatement",
|
||||
"-> Identifier",
|
||||
"<- Identifier",
|
||||
"<- ExpressionStatement",
|
||||
"<- Program",
|
||||
]);
|
||||
});
|
||||
|
||||
Deno.test("Plugin - visitor descendant", () => {
|
||||
let result = testVisit(
|
||||
"if (false) foo; if (false) bar()",
|
||||
|
|
Loading…
Add table
Reference in a new issue