Skip to content

Commit

Permalink
[MERGE #1356 @pleath] Let named function expression be eligible for I…
Browse files Browse the repository at this point in the history
…IFE heuristic

Merge pull request #1356 from pleath:iife

Trivial change to our deferred-parsing heuristic for detecting IIFE's: also treat a function expression as an IIFE if it has a name, provided it is preceded by a unary operator or parenthesis. The name consideration dates from legacy mode, in which a function expression's name could be referred to outside the function.
  • Loading branch information
pleath committed Jul 29, 2016
2 parents a37eed2 + 5204f8d commit 47bded7
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/Parser/Parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4795,8 +4795,7 @@ bool Parser::ParseFncDeclHelper(ParseNodePtr pnodeFnc, LPCOLESTR pNameHint, usho
bool parallelJobStarted = false;
if (buildAST)
{
bool isLikelyModulePattern =
!fDeclaration && pnodeFnc && pnodeFnc->sxFnc.pnodeName == nullptr && fUnaryOrParen;
bool isLikelyIIFE = !fDeclaration && pnodeFnc && fUnaryOrParen;

BOOL isDeferredFnc = IsDeferredFnc();
AnalysisAssert(isDeferredFnc || pnodeFnc);
Expand All @@ -4806,15 +4805,15 @@ bool Parser::ParseFncDeclHelper(ParseNodePtr pnodeFnc, LPCOLESTR pNameHint, usho
&& (!pnodeFnc->sxFnc.IsNested() || CONFIG_FLAG(DeferNested))
// Don't defer if this is a function expression not contained in a statement or other expression.
// Assume it will be called as part of this expression.
&& (!isLikelyModulePattern || !topLevelStmt || PHASE_FORCE_RAW(Js::DeferParsePhase, m_sourceContextInfo->sourceContextId, pnodeFnc->sxFnc.functionId))
&& (!isLikelyIIFE || !topLevelStmt || PHASE_FORCE_RAW(Js::DeferParsePhase, m_sourceContextInfo->sourceContextId, pnodeFnc->sxFnc.functionId))
&& !m_InAsmMode
// Don't defer a module function wrapper because we need to do export resolution at parse time
&& !fModule
);

if (!fLambda &&
!isDeferredFnc &&
!isLikelyModulePattern &&
!isLikelyIIFE &&
!this->IsBackgroundParser() &&
!this->m_doingFastScan &&
!(pnodeFncSave && m_currDeferredStub) &&
Expand Down

0 comments on commit 47bded7

Please sign in to comment.