Skip to content

Commit 2061afd

Browse files
committed
fix(octane): exclude arrows named async from receiver tracking
The ARROW_HEAD regex used \s* after the async prefix, allowing it to match method-named-async source text 'async(' (no whitespace). A separate method.name !== 'async' guard excluded that false positive, but also incorrectly excluded parenthesized arrows whose inferred name happened to be 'async' (e.g. const async = () => {} or { async: () => {} }). Fix: require \s+ (at least one whitespace character) after the async prefix. This rejects 'async(' (method) at the regex level and removes the need for the name guard, so arrows with an inferred name of 'async' are correctly classified.
1 parent 56685f9 commit 2061afd

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

‎packages/octane/src/method-dep.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@ export function __methodDep(
8080
}
8181

8282
// An arrow's source text starts with its parameters, after an optional
83-
// `async`: a parenthesized list, or one identifier followed by `=>`. Every
84-
// other function starts with `function`, `class`, or a method's property key,
85-
// and a bound, native, or proxied function reads as `function … [native code]`.
86-
// Anything this does not recognize counts as a method, which only costs a
87-
// spurious recompute. A method named `async` also reads as `async(`, so the
88-
// name check runs only after the pattern matched.
89-
const ARROW_HEAD = /^(?:async\s*)?(?:\(|[\w$]+\s*=>)/;
83+
// `async ` (with whitespace): a parenthesized list, or one identifier followed
84+
// by `=>`. Every other function starts with `function`, `class`, or a method's
85+
// property key, and a bound, native, or proxied function reads as
86+
// `function … [native code]`. A method named `async` stringifies as `async(`
87+
// with no whitespace, so requiring `\s+` after `async` excludes it without a
88+
// name check. Anything this does not recognize counts as a method, which only
89+
// costs a spurious recompute.
90+
const ARROW_HEAD = /^(?:async\s+)?(?:\(|[\w$]+\s*=>)/;
9091

9192
function ownMethodDep(receiver: object, method: unknown): unknown {
92-
return typeof method === 'function' &&
93-
!(ARROW_HEAD.test(Function.prototype.toString.call(method)) && method.name !== 'async')
93+
return typeof method === 'function' && !ARROW_HEAD.test(Function.prototype.toString.call(method))
9494
? receiver
9595
: method;
9696
}

0 commit comments

Comments
 (0)