Skip to content

Commit 48ff382

Browse files
Closure Teamcopybara-github
Closure Team
authored andcommitted
Add a few more test cases for messages on public class fields.
PiperOrigin-RevId: 734697347
1 parent dcfde7f commit 48ff382

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/com/google/javascript/jscomp/JsMessageVisitorTest.java

+30
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,36 @@ public void testJsMessageOnPublicField() {
364364
assertThat(msg.asJsMessageString()).isEqualTo("Greetings");
365365
}
366366

367+
@Test
368+
public void testJsMessageOnPublicField_directAlias() {
369+
extractMessagesSafely(
370+
lines(
371+
"/** @desc Something */",
372+
"const MSG_SOMETHING = goog.getMsg('Something');",
373+
"class Foo {",
374+
" MSG_SOMETHING = MSG_SOMETHING;",
375+
"}"));
376+
assertThat(assertOneMessage().getKey()).isEqualTo("MSG_SOMETHING");
377+
}
378+
379+
// Note: This may be undesirable but represents the current behavior.
380+
// Ideally the assignment to this MSG in the constructor should be sufficient to avoid the error.
381+
@Test
382+
public void testJsMessageOnPublicField_indirectAliasPresentlyErrors() {
383+
extractMessages(
384+
lines(
385+
"/** @desc Anything */",
386+
"const MSG_ANYTHING = goog.getMsg('Anything');",
387+
"class Baz {",
388+
" MSG_ANYTHING;",
389+
" constructor() {",
390+
" this.MSG_ANYTHING = MSG_ANYTHING;",
391+
" }",
392+
"}"));
393+
assertOneError(MESSAGE_HAS_NO_VALUE);
394+
assertThat(compiler.getWarnings()).isEmpty();
395+
}
396+
367397
@Test
368398
public void testErrorOnPublicFields() {
369399
extractMessages(

0 commit comments

Comments
 (0)