Index: third_party/closure_compiler/runner/test/com/google/javascript/jscomp/ChromePassTest.java |
diff --git a/third_party/closure_compiler/runner/test/com/google/javascript/jscomp/ChromePassTest.java b/third_party/closure_compiler/runner/test/com/google/javascript/jscomp/ChromePassTest.java |
index b8db07d9b2f19f9d739cb76339ca3cd6f1c3c900..73675705e0a7ccf0d8791cc8df9efb9b429eeae5 100644 |
--- a/third_party/closure_compiler/runner/test/com/google/javascript/jscomp/ChromePassTest.java |
+++ b/third_party/closure_compiler/runner/test/com/google/javascript/jscomp/ChromePassTest.java |
@@ -76,7 +76,7 @@ public class ChromePassTest extends CompilerTestCase { |
"});"); |
} |
- public void testCrDefineReassignsExportedFunctionByQualifiedName() throws Exception { |
+ public void testCrDefineReassignsExportedVarByQualifiedName() throws Exception { |
test( |
"cr.define('namespace', function() {\n" + |
" var internalStaticMethod = function() {\n" + |
@@ -97,6 +97,42 @@ public class ChromePassTest extends CompilerTestCase { |
"});"); |
} |
+ public void testCrDefineExportsVarsWithoutAssignment() throws Exception { |
+ test( |
+ "cr.define('namespace', function() {\n" + |
+ " var a;\n" + |
+ " return {\n" + |
+ " a: a\n" + |
+ " };\n" + |
+ "});\n", |
+ "var namespace = namespace || {};\n" + |
+ "cr.define('namespace', function() {\n" + |
+ " namespace.a;\n" + |
+ " return {\n" + |
+ " a: namespace.a\n" + |
+ " };\n" + |
+ "});\n"); |
+ } |
+ |
+ public void testCrDefineExportsVarsWithoutAssignmentWithJSDoc() throws Exception { |
+ test( |
+ "cr.define('namespace', function() {\n" + |
+ " /** @type {number} */\n" + |
+ " var a;\n" + |
+ " return {\n" + |
+ " a: a\n" + |
+ " };\n" + |
+ "});\n", |
+ "var namespace = namespace || {};\n" + |
+ "cr.define('namespace', function() {\n" + |
+ " /** @type {number} */\n" + |
+ " namespace.a;\n" + |
+ " return {\n" + |
+ " a: namespace.a\n" + |
+ " };\n" + |
+ "});\n"); |
+ } |
+ |
public void testCrDefineCopiesJSDocForExportedVariable() throws Exception { |
test( |
"cr.define('namespace', function() {\n" + |
@@ -137,6 +173,25 @@ public class ChromePassTest extends CompilerTestCase { |
"});"); |
} |
+ public void testCrDefineDoesNothingWithNonExportedVar() throws Exception { |
+ test( |
+ "cr.define('namespace', function() {\n" + |
+ " var a;\n" + |
+ " var b;\n" + |
+ " return {\n" + |
+ " a: a\n" + |
+ " };\n" + |
+ "});\n", |
+ "var namespace = namespace || {};\n" + |
+ "cr.define('namespace', function() {\n" + |
+ " namespace.a;\n" + |
+ " var b;\n" + |
+ " return {\n" + |
+ " a: namespace.a\n" + |
+ " };\n" + |
+ "});\n"); |
+ } |
+ |
public void testCrDefineChangesReferenceToExportedFunction() throws Exception { |
test( |
"cr.define('namespace', function() {\n" + |
@@ -257,7 +312,7 @@ public class ChromePassTest extends CompilerTestCase { |
test( |
"cr.define('a.b.c.d', function() {\n" + |
" return {};\n" + |
- "});" + |
+ "});\n" + |
"cr.define('a.b.e.f', function() {\n" + |
" return {};\n" + |
"});", |
@@ -267,7 +322,7 @@ public class ChromePassTest extends CompilerTestCase { |
"a.b.c.d = a.b.c.d || {};\n" + |
"cr.define('a.b.c.d', function() {\n" + |
" return {};\n" + |
- "});" + |
+ "});\n" + |
"a.b.e = a.b.e || {};\n" + |
"a.b.e.f = a.b.e.f || {};\n" + |
"cr.define('a.b.e.f', function() {\n" + |