Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1040)

Unified Diff: third_party/closure_compiler/runner/test/com/google/javascript/jscomp/ChromePassTest.java

Issue 469213009: Fix in compiler pass: cr.define() can export variable without assigned value (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@true_master
Patch Set: add test to show behavior on unexported variables Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/closure_compiler/runner/src/com/google/javascript/jscomp/ChromePass.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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" +
« no previous file with comments | « third_party/closure_compiler/runner/src/com/google/javascript/jscomp/ChromePass.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698