Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 30 matching lines...) Expand all Loading... | |
| 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_WRONG_NUMBER_OF_ARGUMENTS = |
| 50 DiagnosticType.error("JSC_CR_EXPORT_PATH_WRONG_NUMBER_OF_ARGUMENTS", | 50 DiagnosticType.error("JSC_CR_EXPORT_PATH_WRONG_NUMBER_OF_ARGUMENTS", |
| 51 "cr.exportPath() should have exactly 1 argument: namespace n ame."); | 51 "cr.exportPath() should have between 1 and 3 arguments: " |
| 52 + "namespace name[, object to expose[, object to export to]] ."); | |
| 52 | 53 |
| 53 static final DiagnosticType CR_DEFINE_INVALID_FIRST_ARGUMENT = | 54 static final DiagnosticType CR_DEFINE_INVALID_FIRST_ARGUMENT = |
| 54 DiagnosticType.error("JSC_CR_DEFINE_INVALID_FIRST_ARGUMENT", | 55 DiagnosticType.error("JSC_CR_DEFINE_INVALID_FIRST_ARGUMENT", |
| 55 "Invalid first argument for cr.define(). " + CR_DEFINE_COMMO N_EXPLANATION); | 56 "Invalid first argument for cr.define(). " + CR_DEFINE_COMMO N_EXPLANATION); |
| 56 | 57 |
| 57 static final DiagnosticType CR_DEFINE_INVALID_SECOND_ARGUMENT = | 58 static final DiagnosticType CR_DEFINE_INVALID_SECOND_ARGUMENT = |
| 58 DiagnosticType.error("JSC_CR_DEFINE_INVALID_SECOND_ARGUMENT", | 59 DiagnosticType.error("JSC_CR_DEFINE_INVALID_SECOND_ARGUMENT", |
| 59 "Invalid second argument for cr.define(). " + CR_DEFINE_COMM ON_EXPLANATION); | 60 "Invalid second argument for cr.define(). " + CR_DEFINE_COMM ON_EXPLANATION); |
| 60 | 61 |
| 61 static final DiagnosticType CR_DEFINE_INVALID_RETURN_IN_FUNCTION = | 62 static final DiagnosticType CR_DEFINE_INVALID_RETURN_IN_FUNCTION = |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 } else { | 244 } else { |
| 244 compiler.report(JSError.make(jsDocSourceNode, CR_MAKE_PUBLIC _HAS_NO_JSDOC)); | 245 compiler.report(JSError.make(jsDocSourceNode, CR_MAKE_PUBLIC _HAS_NO_JSDOC)); |
| 245 } | 246 } |
| 246 publicAPIStrings.remove(publicName); | 247 publicAPIStrings.remove(publicName); |
| 247 } | 248 } |
| 248 } | 249 } |
| 249 return changesMade; | 250 return changesMade; |
| 250 } | 251 } |
| 251 | 252 |
| 252 private void visitExportPath(Node crExportPathNode, Node parent) { | 253 private void visitExportPath(Node crExportPathNode, Node parent) { |
| 253 if (crExportPathNode.getChildCount() != 2) { | 254 int childCount = crExportPathNode.getChildCount(); |
| 255 if (childCount < 2 || childCount > 4) { | |
| 254 compiler.report(JSError.make(crExportPathNode, | 256 compiler.report(JSError.make(crExportPathNode, |
| 255 CR_EXPORT_PATH_WRONG_NUMBER_OF_ARGUMENTS)); | 257 CR_EXPORT_PATH_WRONG_NUMBER_OF_ARGUMENTS)); |
| 258 } | |
| 259 if (childCount != 2) | |
| 256 return; | 260 return; |
| 257 } | |
| 258 | 261 |
| 259 createAndInsertObjectsForQualifiedName(parent, | 262 createAndInsertObjectsForQualifiedName(parent, |
| 260 crExportPathNode.getChildAtIndex(1).getString()); | 263 crExportPathNode.getChildAtIndex(1).getString()); |
|
Dan Beam
2015/08/29 01:49:30
cr.exportPath(pathName); // throws without a 'lit
michaelpg
2015/08/29 01:53:23
Acknowledged.
| |
| 261 } | 264 } |
| 262 | 265 |
| 263 private void createAndInsertObjectsForQualifiedName(Node scriptChild, String namespace) { | 266 private void createAndInsertObjectsForQualifiedName(Node scriptChild, String namespace) { |
| 264 List<Node> objectsForQualifiedName = createObjectsForQualifiedName(names pace); | 267 List<Node> objectsForQualifiedName = createObjectsForQualifiedName(names pace); |
| 265 for (Node n : objectsForQualifiedName) { | 268 for (Node n : objectsForQualifiedName) { |
| 266 scriptChild.getParent().addChildBefore(n, scriptChild); | 269 scriptChild.getParent().addChildBefore(n, scriptChild); |
| 267 } | 270 } |
| 268 } | 271 } |
| 269 | 272 |
| 270 private void visitNamespaceDefinition(Node crDefineCallNode, Node parent) { | 273 private void visitNamespaceDefinition(Node crDefineCallNode, Node parent) { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 445 } | 448 } |
| 446 } | 449 } |
| 447 | 450 |
| 448 private Node buildQualifiedName(Node internalName) { | 451 private Node buildQualifiedName(Node internalName) { |
| 449 String externalName = this.exports.get(internalName.getString()); | 452 String externalName = this.exports.get(internalName.getString()); |
| 450 return NodeUtil.newQName(compiler, this.namespaceName + "." + extern alName).srcrefTree( | 453 return NodeUtil.newQName(compiler, this.namespaceName + "." + extern alName).srcrefTree( |
| 451 internalName); | 454 internalName); |
| 452 } | 455 } |
| 453 } | 456 } |
| 454 } | 457 } |
| OLD | NEW |