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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package com.google.javascript.jscomp; 5 package com.google.javascript.jscomp;
6 6
7 import com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback; 7 import com.google.javascript.jscomp.NodeTraversal.AbstractPostOrderCallback;
8 import com.google.javascript.rhino.IR; 8 import com.google.javascript.rhino.IR;
9 import com.google.javascript.rhino.JSDocInfoBuilder; 9 import com.google.javascript.rhino.JSDocInfoBuilder;
10 import com.google.javascript.rhino.JSTypeExpression; 10 import com.google.javascript.rhino.JSTypeExpression;
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 288
289 if (n.getJSDocInfo() != null) { 289 if (n.getJSDocInfo() != null) {
290 exprResult.getFirstChild().setJSDocInfo(n.getJSDocInfo()); 290 exprResult.getFirstChild().setJSDocInfo(n.getJSDocInfo());
291 functionTree.removeProp(Node.JSDOC_INFO_PROP); 291 functionTree.removeProp(Node.JSDOC_INFO_PROP);
292 } 292 }
293 this.namespaceBlock.replaceChild(n, exprResult); 293 this.namespaceBlock.replaceChild(n, exprResult);
294 } else if (n.isName() && this.exports.containsKey(n.getString()) && 294 } else if (n.isName() && this.exports.containsKey(n.getString()) &&
295 !parent.isFunction()) { 295 !parent.isFunction()) {
296 if (parent.isVar()) { 296 if (parent.isVar()) {
297 if (parent.getParent() == this.namespaceBlock) { 297 if (parent.getParent() == this.namespaceBlock) {
298 // It's a top-level exported variable definition. 298 // It's a top-level exported variable definition (maybe without an
299 // assignment).
299 // Change 300 // Change
300 // 301 //
301 // var enum = { 'one': 1, 'two': 2 }; 302 // var enum = { 'one': 1, 'two': 2 };
302 // 303 //
303 // to 304 // to
304 // 305 //
305 // my.namespace.name.enum = { 'one': 1, 'two': 2 }; 306 // my.namespace.name.enum = { 'one': 1, 'two': 2 };
306 Node varContent = n.removeFirstChild(); 307 Node varContent = n.removeFirstChild();
307 Node exprResult = IR.exprResult( 308 Node exprResult;
308 IR.assign(buildQualifiedName(n), varContent) .srcref(parent) 309 if (varContent == null) {
309 ).srcref(parent); 310 exprResult = IR.exprResult(buildQualifiedName(n)).sr cref(parent);
310 311 } else {
312 exprResult = IR.exprResult(
313 IR.assign(buildQualifiedName(n), varCont ent).srcref(parent)
314 ).srcref(parent);
315 }
311 if (parent.getJSDocInfo() != null) { 316 if (parent.getJSDocInfo() != null) {
312 exprResult.getFirstChild().setJSDocInfo(parent.getJS DocInfo().clone()); 317 exprResult.getFirstChild().setJSDocInfo(parent.getJS DocInfo().clone());
313 } 318 }
314 this.namespaceBlock.replaceChild(parent, exprResult); 319 this.namespaceBlock.replaceChild(parent, exprResult);
315 } 320 }
316 } else { 321 } else {
317 // It's a local name referencing exported entity. Change to its global name. 322 // It's a local name referencing exported entity. Change to its global name.
318 Node newNode = buildQualifiedName(n); 323 Node newNode = buildQualifiedName(n);
319 if (n.getJSDocInfo() != null) { 324 if (n.getJSDocInfo() != null) {
320 newNode.setJSDocInfo(n.getJSDocInfo().clone()); 325 newNode.setJSDocInfo(n.getJSDocInfo().clone());
(...skipping 11 matching lines...) Expand all
332 } 337 }
333 338
334 private Node buildQualifiedName(Node internalName) { 339 private Node buildQualifiedName(Node internalName) {
335 String externalName = this.exports.get(internalName.getString()); 340 String externalName = this.exports.get(internalName.getString());
336 return NodeUtil.newQualifiedNameNode(compiler.getCodingConvention(), 341 return NodeUtil.newQualifiedNameNode(compiler.getCodingConvention(),
337 this.namespaceName + "." + externalName).srcrefTree(internal Name); 342 this.namespaceName + "." + externalName).srcrefTree(internal Name);
338 } 343 }
339 } 344 }
340 345
341 } 346 }
OLDNEW
« 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