diff --git a/src/com/google/javascript/jscomp/InlineFunctions.java b/src/com/google/javascript/jscomp/InlineFunctions.java index fef1284aaa6..7d73c70d3e9 100644 --- a/src/com/google/javascript/jscomp/InlineFunctions.java +++ b/src/com/google/javascript/jscomp/InlineFunctions.java @@ -28,6 +28,7 @@ import com.google.javascript.jscomp.FunctionInjector.CanInlineResult; import com.google.javascript.jscomp.FunctionInjector.InliningMode; import com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback; +import com.google.javascript.rhino.JSDocInfo; import com.google.javascript.rhino.Node; import java.util.Collection; import java.util.Collections; @@ -262,6 +263,12 @@ void maybeAddFunction(Function fn, JSModule module) { return; } Node fnNode = fn.getFunctionNode(); + + if (hasNoInlineAnnotation(fnNode)) { + functionState.setInline(false); + return; + } + if (enforceMaxSizeAfterInlining && !isAlwaysInlinable(fnNode) && maxSizeAfterInlining <= NodeUtil.countAstSizeUpToLimit(fnNode, maxSizeAfterInlining)) { @@ -328,6 +335,11 @@ void maybeAddFunction(Function fn, JSModule module) { } } + private boolean hasNoInlineAnnotation(Node fnNode) { + JSDocInfo jsDocInfo = NodeUtil.getBestJSDocInfo(fnNode); + return jsDocInfo != null && jsDocInfo.isNoInline(); + } + /** * @param fnNode The function to inspect. * @return Whether the function has parameters, var/const/let, class, or function declarations. diff --git a/test/com/google/javascript/jscomp/InlineFunctionsTest.java b/test/com/google/javascript/jscomp/InlineFunctionsTest.java index 6a213b02505..50b4b83c278 100644 --- a/test/com/google/javascript/jscomp/InlineFunctionsTest.java +++ b/test/com/google/javascript/jscomp/InlineFunctionsTest.java @@ -77,6 +77,11 @@ protected int getNumRepetitions() { return 3; } + public void testNoInline() { + testSame("/** @noinline */ function foo(){} foo();foo();foo();"); + testSame("/** @noinline */ var foo = function(){}; foo();foo();foo();"); + } + public void testInlineEmptyFunction1() { // Empty function, no params. test("function foo(){}" +