diff --git a/src/com/google/javascript/jscomp/JsMessageVisitor.java b/src/com/google/javascript/jscomp/JsMessageVisitor.java index df5c7f0d3ce..20495e1b65f 100644 --- a/src/com/google/javascript/jscomp/JsMessageVisitor.java +++ b/src/com/google/javascript/jscomp/JsMessageVisitor.java @@ -829,19 +829,24 @@ private void visitFallbackFunctionCall(NodeTraversal t, Node call) { } Node firstArg = call.getSecondChild(); - JsMessage firstMessage = getTrackedMessage(t, firstArg.getString()); + String name = firstArg.getOriginalName(); + if (name == null) { + name = firstArg.getString(); + } + JsMessage firstMessage = getTrackedMessage(t, name); if (firstMessage == null) { - compiler.report( - t.makeError(firstArg, FALLBACK_ARG_ERROR, firstArg.getString())); + compiler.report(t.makeError(firstArg, FALLBACK_ARG_ERROR, name)); return; } Node secondArg = firstArg.getNext(); - JsMessage secondMessage = getTrackedMessage( - t, call.getChildAtIndex(2).getString()); + name = secondArg.getOriginalName(); + if (name == null) { + name = secondArg.getString(); + } + JsMessage secondMessage = getTrackedMessage(t, name); if (secondMessage == null) { - compiler.report( - t.makeError(secondArg, FALLBACK_ARG_ERROR, secondArg.getString())); + compiler.report(t.makeError(secondArg, FALLBACK_ARG_ERROR, name)); return; } @@ -929,8 +934,7 @@ static String toLowerCamelCaseWithNumericSuffixes(String input) { return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, input); } else { return CaseFormat.UPPER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, - input.substring(0, suffixStart)) + - input.substring(suffixStart); + input.substring(0, suffixStart)) + input.substring(suffixStart); } } diff --git a/test/com/google/javascript/jscomp/JsMessageVisitorTest.java b/test/com/google/javascript/jscomp/JsMessageVisitorTest.java index 78f06e6a6c5..5ff48e296be 100644 --- a/test/com/google/javascript/jscomp/JsMessageVisitorTest.java +++ b/test/com/google/javascript/jscomp/JsMessageVisitorTest.java @@ -476,9 +476,9 @@ public void testIncorrectMessage() { assertThat(messages).isEmpty(); assertThat(compiler.getErrors()).hasLength(1); JSError error = compiler.getErrors()[0]; - assertEquals("Message parse tree malformed. "+ - "Message must be initialized using goog.getMsg function.", - error.description); + assertEquals( + "Message parse tree malformed. Message must be initialized using goog.getMsg function.", + error.description); } public void testUnrecognizedFunction() { @@ -488,10 +488,10 @@ public void testUnrecognizedFunction() { assertThat(messages).isEmpty(); assertThat(compiler.getErrors()).hasLength(1); JSError error = compiler.getErrors()[0]; - assertEquals("Message parse tree malformed. "+ - "Message initialized using unrecognized function. " + - "Please use goog.getMsg() instead.", - error.description); + assertEquals( + "Message parse tree malformed. Message initialized using unrecognized function. " + + "Please use goog.getMsg() instead.", + error.description); } public void testExtractPropertyMessage() { @@ -720,6 +720,18 @@ public void testUsingMsgPrefixWithFallback() { assertNoErrors(); } + public void testUsingMsgPrefixWithFallback_rename() { + renameMessages = true; + extractMessages( + LINE_JOINER.join( + "function f() {", + "/** @desc Hello */ var MSG_A = goog.getMsg('hello');", + "/** @desc Hello */ var MSG_B = goog.getMsg('hello!');", + "var x = goog.getMsgWithFallback(MSG_A, MSG_B);", + "}")); + assertNoErrors(); + } + public void testErrorWhenUsingMsgPrefixWithFallback() { extractMessages( "/** @desc Hello */ var MSG_HELLO_1 = goog.getMsg('hello');\n" +