Add tests to show CollectFunctionNames is Es6 compatible
@@ -40,7 +40,8 @@ public final class CollectFunctionNamesTest extends CompilerTestCase {
public void testFunctionsNamesAndIds() {
setAcceptedLanguage(LanguageMode.ECMASCRIPT_2015);
- final String jsSource = LINE_JOINER.join(
+ final String jsSource =
+ LINE_JOINER.join(
"goog.widget = function(str) {",
" this.member_fn = function() {};",
" local_fn = function() {};",
@@ -62,7 +63,13 @@ public final class CollectFunctionNamesTest extends CompilerTestCase {
"class Klass{ constructor(){} method(){}}",
"KlassExpression = class{ constructor(){} method(){}}",
"var KlassExpressionToVar = class{ constructor(){} method(){}}",
- "class KlassWithStaticMethod{ static staticMethod(){}}");
+ "class KlassWithStaticMethod{ static staticMethod(){}}",
+ "() => {};",
+ "var arrowFn1 = () => {};",
+ "function foo1() {",
+ " var arrowFn2 = () => {};",
+ " () => {};",
+ "}");
testSame(jsSource);
@@ -75,7 +82,7 @@ public final class CollectFunctionNamesTest extends CompilerTestCase {
count++;
}
- assertEquals("Unexpected number of functions", 25, count);
+ assertEquals("Unexpected number of functions", 30, count);
final Map<Integer, String> expectedMap = new LinkedHashMap<>();
@@ -104,6 +111,11 @@ public final class CollectFunctionNamesTest extends CompilerTestCase {
expectedMap.put(22, "KlassExpressionToVar.constructor");
expectedMap.put(23, "KlassExpressionToVar.method");
expectedMap.put(24, "KlassWithStaticMethod.staticMethod");
+ expectedMap.put(25, "<anonymous>"); // arrow function in global scope
+ expectedMap.put(26, "arrowFn1"); // arrow function declared as variable
+ expectedMap.put(27, "foo1::arrowFn2"); // arrow function in inner scope
+ expectedMap.put(28, "foo1::<anonymous>"); // arrow function declared as variable in inner scope
+ expectedMap.put(29, "foo1");
assertEquals("Function id/name mismatch",
expectedMap, idNameMap);
}
