From f9e1f651332e72dde74795e949932166c0ef0848 Mon Sep 17 00:00:00 2001 From: dcode Date: Sat, 25 May 2019 19:22:19 +0200 Subject: [PATCH] fix 'no-unbound-method' --- src/flow.ts | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/flow.ts b/src/flow.ts index 31d71179..87cccfe2 100644 --- a/src/flow.ts +++ b/src/flow.ts @@ -295,20 +295,6 @@ export class Flow { return branch; } - private static findUsedLocals(expr: ExpressionRef, blocked: Set): void { - switch (getExpressionId(expr)) { - case ExpressionId.LocalGet: { - blocked.add(getGetLocalIndex(expr)); - break; - } - case ExpressionId.LocalSet: { - blocked.add(getSetLocalIndex(expr)); - break; - } - default: traverse(expr, blocked, Flow.findUsedLocals); - } - } - /** Gets a free temporary local of the specified type. */ getTempLocal(type: Type, except: ExpressionRef = 0): Local { var parentFunction = this.parentFunction; @@ -324,7 +310,7 @@ export class Flow { var local: Local; if (except) { let usedLocals = new Set(); - traverse(except, usedLocals, Flow.findUsedLocals); + traverse(except, usedLocals, findUsedLocals); if (temps) { for (let i = 0, k = temps.length; i < k; ++i) { if (!usedLocals.has(temps[i].index)) { @@ -1089,3 +1075,18 @@ function canConversionOverflow(fromType: Type, toType: Type): bool { || fromType.size > toType.size || fromType.is(TypeFlags.SIGNED) != toType.is(TypeFlags.SIGNED); } + +/** A visitor function for use with `traverse` that finds all indexes of used locals. */ +function findUsedLocals(expr: ExpressionRef, used: Set): void { + switch (getExpressionId(expr)) { + case ExpressionId.LocalGet: { + used.add(getGetLocalIndex(expr)); + break; + } + case ExpressionId.LocalSet: { + used.add(getSetLocalIndex(expr)); + break; + } + default: traverse(expr, used, findUsedLocals); + } +}