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

Unified Diff: third_party/closure_compiler/runner/src/com/google/javascript/jscomp/ChromePass.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 | « no previous file | third_party/closure_compiler/runner/test/com/google/javascript/jscomp/ChromePassTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/closure_compiler/runner/src/com/google/javascript/jscomp/ChromePass.java
diff --git a/third_party/closure_compiler/runner/src/com/google/javascript/jscomp/ChromePass.java b/third_party/closure_compiler/runner/src/com/google/javascript/jscomp/ChromePass.java
index 8ff3fb0a1405133424da35b7d6b6e67e5e8fc1de..c7f3c12daccb071f705a6a6a9c896653b3045a37 100644
--- a/third_party/closure_compiler/runner/src/com/google/javascript/jscomp/ChromePass.java
+++ b/third_party/closure_compiler/runner/src/com/google/javascript/jscomp/ChromePass.java
@@ -295,7 +295,8 @@ public class ChromePass extends AbstractPostOrderCallback implements CompilerPas
!parent.isFunction()) {
if (parent.isVar()) {
if (parent.getParent() == this.namespaceBlock) {
- // It's a top-level exported variable definition.
+ // It's a top-level exported variable definition (maybe without an
+ // assignment).
// Change
//
// var enum = { 'one': 1, 'two': 2 };
@@ -304,10 +305,14 @@ public class ChromePass extends AbstractPostOrderCallback implements CompilerPas
//
// my.namespace.name.enum = { 'one': 1, 'two': 2 };
Node varContent = n.removeFirstChild();
- Node exprResult = IR.exprResult(
- IR.assign(buildQualifiedName(n), varContent).srcref(parent)
- ).srcref(parent);
-
+ Node exprResult;
+ if (varContent == null) {
+ exprResult = IR.exprResult(buildQualifiedName(n)).srcref(parent);
+ } else {
+ exprResult = IR.exprResult(
+ IR.assign(buildQualifiedName(n), varContent).srcref(parent)
+ ).srcref(parent);
+ }
if (parent.getJSDocInfo() != null) {
exprResult.getFirstChild().setJSDocInfo(parent.getJSDocInfo().clone());
}
« no previous file with comments | « no previous file | third_party/closure_compiler/runner/test/com/google/javascript/jscomp/ChromePassTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698