mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
fix(electron): honor ordered switch-case completion in call paths (#10057)
fix(electron): honor switch-case completion in wrapper paths
This commit is contained in:
1 parent
827b808248
commit
4073cfc932
3 files changed
+116
-10
No files matched your search
@@ -45,6 +45,9 @@ interface PrefixEntry {
|
||||
readonly fact: ElectronStatementFallthrough;
|
||||
}
|
||||
|
||||
/** Both braced blocks and switch cases own ordered statement sequences. */
|
||||
type StatementList = t.BlockStatement | t.SwitchCase;
|
||||
|
||||
interface BlockIndex {
|
||||
readonly positions: WeakMap<t.Node, number>;
|
||||
readonly entries: readonly PrefixEntry[];
|
||||
@@ -57,7 +60,7 @@ interface BlockIndex {
|
||||
* to the invocation's symbolic environment and can establish unknown coverage.
|
||||
*/
|
||||
export class ElectronCallPathBlockPrefixes {
|
||||
readonly #blocks = new WeakMap<t.BlockStatement, BlockIndex>();
|
||||
readonly #blocks = new WeakMap<StatementList, BlockIndex>();
|
||||
readonly #facts = new WeakMap<
|
||||
t.Statement,
|
||||
ElectronStatementFallthrough | null
|
||||
@@ -120,7 +123,7 @@ export class ElectronCallPathBlockPrefixes {
|
||||
if (depth >= 128) return UNKNOWN;
|
||||
if (!this.admitVisit()) return undefined;
|
||||
if (t.isReturnStatement(node) || t.isThrowStatement(node)) return EXIT;
|
||||
if (t.isBreakStatement(node))
|
||||
if (t.isBreakStatement(node) || t.isContinueStatement(node))
|
||||
return {
|
||||
fallthrough: false,
|
||||
exits: false,
|
||||
@@ -162,13 +165,15 @@ export class ElectronCallPathBlockPrefixes {
|
||||
|
||||
private exits(
|
||||
node: t.Node | null | undefined,
|
||||
block: t.BlockStatement,
|
||||
block: StatementList,
|
||||
): boolean | undefined {
|
||||
const result = this.completion(node);
|
||||
if (result === undefined || result.fallthrough || result.uncertain)
|
||||
return result === undefined ? undefined : false;
|
||||
for (const label of result.breaks) {
|
||||
if (!label || !this.parents) return false;
|
||||
// A switch-local break or enclosing-loop continue ends this case.
|
||||
if (!label && t.isSwitchCase(block)) continue;
|
||||
if (!this.parents) return false;
|
||||
let matched = false;
|
||||
for (
|
||||
let parent = this.parents.get(block), n = 0;
|
||||
@@ -177,7 +182,11 @@ export class ElectronCallPathBlockPrefixes {
|
||||
) {
|
||||
if (!this.admitVisit()) return undefined;
|
||||
if (t.isFunction(parent)) break;
|
||||
if (t.isLabeledStatement(parent) && parent.label.name === label) {
|
||||
if (
|
||||
label
|
||||
? t.isLabeledStatement(parent) && parent.label.name === label
|
||||
: t.isLoop(parent) || t.isSwitchStatement(parent)
|
||||
) {
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
@@ -189,7 +198,7 @@ export class ElectronCallPathBlockPrefixes {
|
||||
|
||||
statement(
|
||||
statement: t.Statement,
|
||||
block: t.BlockStatement,
|
||||
block: StatementList,
|
||||
): ElectronStatementFallthrough | null | undefined {
|
||||
const cached = this.#facts.get(statement);
|
||||
if (cached !== undefined) return cached;
|
||||
@@ -218,7 +227,7 @@ export class ElectronCallPathBlockPrefixes {
|
||||
}
|
||||
|
||||
*before(
|
||||
block: t.BlockStatement,
|
||||
block: StatementList,
|
||||
child: t.Node,
|
||||
): Generator<
|
||||
void,
|
||||
@@ -229,7 +238,8 @@ export class ElectronCallPathBlockPrefixes {
|
||||
if (index === undefined) {
|
||||
const positions = new WeakMap<t.Node, number>();
|
||||
const entries: PrefixEntry[] = [];
|
||||
for (const [position, statement] of block.body.entries()) {
|
||||
const statements = t.isSwitchCase(block) ? block.consequent : block.body;
|
||||
for (const [position, statement] of statements.entries()) {
|
||||
if (!this.admitVisit()) return undefined;
|
||||
positions.set(statement, position);
|
||||
const fact = this.statement(statement, block);
|
||||
|
||||
Reference in new issue
Block a user