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

Side by Side Diff: third_party/closure_compiler/runner/src/com/google/javascript/jscomp/ChromePass.java

Issue 1319263002: Fix Chrome-specific closure pass for cr.exportPath() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: nit Created 5 years, 3 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 | « third_party/closure_compiler/runner/runner.jar ('k') | no next file » | 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 28 matching lines...) Expand all
39 private static final String CR_DEFINE_PROPERTY = "cr.defineProperty"; 39 private static final String CR_DEFINE_PROPERTY = "cr.defineProperty";
40 private static final String CR_MAKE_PUBLIC = "cr.makePublic"; 40 private static final String CR_MAKE_PUBLIC = "cr.makePublic";
41 41
42 private static final String CR_DEFINE_COMMON_EXPLANATION = "It should be cal led like this:" 42 private static final String CR_DEFINE_COMMON_EXPLANATION = "It should be cal led like this:"
43 + " cr.define('name.space', function() '{ ... return {Export: Intern al}; }');"; 43 + " cr.define('name.space', function() '{ ... return {Export: Intern al}; }');";
44 44
45 static final DiagnosticType CR_DEFINE_WRONG_NUMBER_OF_ARGUMENTS = 45 static final DiagnosticType CR_DEFINE_WRONG_NUMBER_OF_ARGUMENTS =
46 DiagnosticType.error("JSC_CR_DEFINE_WRONG_NUMBER_OF_ARGUMENTS", 46 DiagnosticType.error("JSC_CR_DEFINE_WRONG_NUMBER_OF_ARGUMENTS",
47 "cr.define() should have exactly 2 arguments. " + CR_DEFINE_ COMMON_EXPLANATION); 47 "cr.define() should have exactly 2 arguments. " + CR_DEFINE_ COMMON_EXPLANATION);
48 48
49 static final DiagnosticType CR_EXPORT_PATH_WRONG_NUMBER_OF_ARGUMENTS = 49 static final DiagnosticType CR_EXPORT_PATH_TOO_FEW_ARGUMENTS =
50 DiagnosticType.error("JSC_CR_EXPORT_PATH_WRONG_NUMBER_OF_ARGUMENTS", 50 DiagnosticType.error("JSC_CR_EXPORT_PATH_TOO_FEW_ARGUMENTS",
51 "cr.exportPath() should have exactly 1 argument: namespace n ame."); 51 "cr.exportPath() should have at least 1 argument: path name. ");
52 52
53 static final DiagnosticType CR_DEFINE_INVALID_FIRST_ARGUMENT = 53 static final DiagnosticType CR_DEFINE_INVALID_FIRST_ARGUMENT =
54 DiagnosticType.error("JSC_CR_DEFINE_INVALID_FIRST_ARGUMENT", 54 DiagnosticType.error("JSC_CR_DEFINE_INVALID_FIRST_ARGUMENT",
55 "Invalid first argument for cr.define(). " + CR_DEFINE_COMMO N_EXPLANATION); 55 "Invalid first argument for cr.define(). " + CR_DEFINE_COMMO N_EXPLANATION);
56 56
57 static final DiagnosticType CR_DEFINE_INVALID_SECOND_ARGUMENT = 57 static final DiagnosticType CR_DEFINE_INVALID_SECOND_ARGUMENT =
58 DiagnosticType.error("JSC_CR_DEFINE_INVALID_SECOND_ARGUMENT", 58 DiagnosticType.error("JSC_CR_DEFINE_INVALID_SECOND_ARGUMENT",
59 "Invalid second argument for cr.define(). " + CR_DEFINE_COMM ON_EXPLANATION); 59 "Invalid second argument for cr.define(). " + CR_DEFINE_COMM ON_EXPLANATION);
60 60
61 static final DiagnosticType CR_DEFINE_INVALID_RETURN_IN_FUNCTION = 61 static final DiagnosticType CR_DEFINE_INVALID_RETURN_IN_FUNCTION =
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 } else { 243 } else {
244 compiler.report(JSError.make(jsDocSourceNode, CR_MAKE_PUBLIC _HAS_NO_JSDOC)); 244 compiler.report(JSError.make(jsDocSourceNode, CR_MAKE_PUBLIC _HAS_NO_JSDOC));
245 } 245 }
246 publicAPIStrings.remove(publicName); 246 publicAPIStrings.remove(publicName);
247 } 247 }
248 } 248 }
249 return changesMade; 249 return changesMade;
250 } 250 }
251 251
252 private void visitExportPath(Node crExportPathNode, Node parent) { 252 private void visitExportPath(Node crExportPathNode, Node parent) {
253 if (crExportPathNode.getChildCount() != 2) { 253 if (crExportPathNode.getChildCount() < 2) {
254 compiler.report(JSError.make(crExportPathNode, 254 compiler.report(JSError.make(crExportPathNode, CR_EXPORT_PATH_TOO_FE W_ARGUMENTS));
255 CR_EXPORT_PATH_WRONG_NUMBER_OF_ARGUMENTS));
256 return; 255 return;
257 } 256 }
258 257
259 createAndInsertObjectsForQualifiedName(parent, 258 Node pathArg = crExportPathNode.getChildAtIndex(1);
260 crExportPathNode.getChildAtIndex(1).getString()); 259 if (pathArg.isString()) {
260 createAndInsertObjectsForQualifiedName(parent, pathArg.getString());
261 }
261 } 262 }
262 263
263 private void createAndInsertObjectsForQualifiedName(Node scriptChild, String namespace) { 264 private void createAndInsertObjectsForQualifiedName(Node scriptChild, String namespace) {
264 List<Node> objectsForQualifiedName = createObjectsForQualifiedName(names pace); 265 List<Node> objectsForQualifiedName = createObjectsForQualifiedName(names pace);
265 for (Node n : objectsForQualifiedName) { 266 for (Node n : objectsForQualifiedName) {
266 scriptChild.getParent().addChildBefore(n, scriptChild); 267 scriptChild.getParent().addChildBefore(n, scriptChild);
267 } 268 }
268 } 269 }
269 270
270 private void visitNamespaceDefinition(Node crDefineCallNode, Node parent) { 271 private void visitNamespaceDefinition(Node crDefineCallNode, Node parent) {
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 } 446 }
446 } 447 }
447 448
448 private Node buildQualifiedName(Node internalName) { 449 private Node buildQualifiedName(Node internalName) {
449 String externalName = this.exports.get(internalName.getString()); 450 String externalName = this.exports.get(internalName.getString());
450 return NodeUtil.newQName(compiler, this.namespaceName + "." + extern alName).srcrefTree( 451 return NodeUtil.newQName(compiler, this.namespaceName + "." + extern alName).srcrefTree(
451 internalName); 452 internalName);
452 } 453 }
453 } 454 }
454 } 455 }
OLDNEW
« no previous file with comments | « third_party/closure_compiler/runner/runner.jar ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698