From 68b2e3a35ad5df3edc7ce9f6924e567a9042f105 Mon Sep 17 00:00:00 2001 From: lharker Date: Tue, 19 Nov 2024 08:44:06 -0800 Subject: [PATCH] Delete unused support for @hidden JSDoc tag & JSMessage.isHidden() PiperOrigin-RevId: 698031670 --- .../google/javascript/jscomp/CheckJSDoc.java | 3 +- .../google/javascript/jscomp/JsMessage.java | 15 -------- .../javascript/jscomp/parsing/Annotation.java | 2 -- .../jscomp/parsing/JsDocInfoParser.java | 6 ---- .../jscomp/serialization/JSDocSerializer.java | 7 ---- .../google/javascript/rhino/JSDocInfo.java | 17 --------- src/com/google/javascript/rhino/Msg.java | 1 - .../rhino/typed_ast/optimization_jsdoc.proto | 1 - .../jscomp/JsMessageVisitorTest.java | 1 - .../jscomp/parsing/JsDocInfoParserTest.java | 22 ++---------- .../jscomp/parsing/JsDocTokenStreamTest.java | 18 +++++----- .../javascript/rhino/JSDocInfoTest.java | 36 ++++--------------- 12 files changed, 19 insertions(+), 110 deletions(-) diff --git a/src/com/google/javascript/jscomp/CheckJSDoc.java b/src/com/google/javascript/jscomp/CheckJSDoc.java index c85bc553950..6dbbfabec95 100644 --- a/src/com/google/javascript/jscomp/CheckJSDoc.java +++ b/src/com/google/javascript/jscomp/CheckJSDoc.java @@ -533,8 +533,7 @@ private void validateMsgJsDoc(Node n, JSDocInfo info) { return; } - boolean hasNonDescMsgTag = - info.isHidden() || info.getMeaning() != null || info.getAlternateMessageId() != null; + boolean hasNonDescMsgTag = info.getMeaning() != null || info.getAlternateMessageId() != null; if (hasNonDescMsgTag // Don't error on TS gencode using @desc on a non-message. There's a lot of code that diff --git a/src/com/google/javascript/jscomp/JsMessage.java b/src/com/google/javascript/jscomp/JsMessage.java index 6f3ce64fc31..d73006c39d8 100644 --- a/src/com/google/javascript/jscomp/JsMessage.java +++ b/src/com/google/javascript/jscomp/JsMessage.java @@ -101,12 +101,6 @@ public PlaceholderFormatException(String msg) { /** Gets the meaning annotated to the message, intended to force different translations. */ public abstract @Nullable String getMeaning(); - /** - * Gets whether this message should be hidden from volunteer translators (to reduce the chances of - * a new feature leak). - */ - public abstract boolean isHidden(); - public abstract ImmutableMap getPlaceholderNameToExampleMap(); public abstract ImmutableMap getPlaceholderNameToOriginalCodeMap(); @@ -371,7 +365,6 @@ public static final class Builder { private String meaning; private String desc; - private boolean hidden; private boolean isAnonymous = false; private boolean isExternal = false; @@ -499,13 +492,6 @@ public Builder setAlternateId(@Nullable String alternateId) { return this; } - /** Sets whether the message should be hidden from volunteer translators. */ - @CanIgnoreReturnValue - public Builder setIsHidden(boolean hidden) { - this.hidden = hidden; - return this; - } - @CanIgnoreReturnValue public Builder setIsAnonymous(boolean isAnonymous) { this.isAnonymous = isAnonymous; @@ -554,7 +540,6 @@ public JsMessage build() { alternateId, desc, meaning, - hidden, placeholderNameToExampleMap, placeholderNameToOriginalCodeMap, ImmutableSet.copyOf(jsPlaceholderNames)); diff --git a/src/com/google/javascript/jscomp/parsing/Annotation.java b/src/com/google/javascript/jscomp/parsing/Annotation.java index f3e664913b0..ef7205a058f 100644 --- a/src/com/google/javascript/jscomp/parsing/Annotation.java +++ b/src/com/google/javascript/jscomp/parsing/Annotation.java @@ -41,7 +41,6 @@ enum Annotation { EXPORT, FILE_OVERVIEW, FINAL, - HIDDEN, IDGENERATOR, IMPLEMENTS, IMPLICIT_CAST, @@ -133,7 +132,6 @@ enum Annotation { .put("externs", Annotation.EXTERNS) .put("fileoverview", Annotation.FILE_OVERVIEW) .put("final", Annotation.FINAL) - .put("hidden", Annotation.HIDDEN) .put("idGenerator", Annotation.IDGENERATOR) .put("implements", Annotation.IMPLEMENTS) .put("implicitCast", Annotation.IMPLICIT_CAST) diff --git a/src/com/google/javascript/jscomp/parsing/JsDocInfoParser.java b/src/com/google/javascript/jscomp/parsing/JsDocInfoParser.java index a4268a75082..c232c271c38 100644 --- a/src/com/google/javascript/jscomp/parsing/JsDocInfoParser.java +++ b/src/com/google/javascript/jscomp/parsing/JsDocInfoParser.java @@ -674,12 +674,6 @@ private JsDocToken parseAnnotation(JsDocToken token, List exte token = eatUntilEOLIfNotAnnotation(token); return token; - case HIDDEN: - if (!jsdocBuilder.recordHiddenness()) { - addParserWarning(Msg.JSDOC_HIDDEN); - } - return eatUntilEOLIfNotAnnotation(); - case LENDS: skipEOLs(); diff --git a/src/com/google/javascript/jscomp/serialization/JSDocSerializer.java b/src/com/google/javascript/jscomp/serialization/JSDocSerializer.java index 38f930bbb24..fb48fabbe14 100644 --- a/src/com/google/javascript/jscomp/serialization/JSDocSerializer.java +++ b/src/com/google/javascript/jscomp/serialization/JSDocSerializer.java @@ -155,9 +155,6 @@ public static JSDocInfo convertJSDocInfoForOptimizations(JSDocInfo jsdoc) { } // Used by ReplaceMessages - if (jsdoc.isHidden()) { - builder.addKind(JsdocTag.JSDOC_HIDDEN); - } if (jsdoc.getDescription() != null) { builder.setDescriptionPointer(stringPool.put(jsdoc.getDescription())); } @@ -325,10 +322,6 @@ private static JSTypeExpression createPlaceholderType() { builder.recordAbstract(); continue; - case JSDOC_HIDDEN: - builder.recordHiddenness(); - continue; - // TODO(lharker): stage 2 passes ideally shouldn't report diagnostics, so this could be // moved to stage 1. case JSDOC_SUPPRESS_MESSAGE_CONVENTION: diff --git a/src/com/google/javascript/rhino/JSDocInfo.java b/src/com/google/javascript/rhino/JSDocInfo.java index 34ee9d069dd..df8130e1dd5 100644 --- a/src/com/google/javascript/rhino/JSDocInfo.java +++ b/src/com/google/javascript/rhino/JSDocInfo.java @@ -309,7 +309,6 @@ private static enum Bit { CONST, CONSTRUCTOR, DEFINE, - HIDDEN, TYPE_SUMMARY, FINAL, OVERRIDE, @@ -793,11 +792,6 @@ public boolean isDefine() { return checkBit(Bit.DEFINE); } - /** Returns whether the {@code @hidden} annotation is present on this {@link JSDocInfo}. */ - public boolean isHidden() { - return checkBit(Bit.HIDDEN); - } - /** Returns whether the {@code @override} annotation is present on this {@link JSDocInfo}. */ public boolean isOverride() { return checkBit(Bit.OVERRIDE); @@ -2296,17 +2290,6 @@ public boolean addLicense(String license) { return recordLicense(RhinoStringPool.addOrGet(nullToEmpty(txt) + license)); } - /** - * Records that the {@link JSDocInfo} being built should have its {@link JSDocInfo#isHidden()} - * flag set to {@code true}. - * - * @return {@code true} if the hiddenness was recorded and {@code false} if it was already - * defined - */ - public boolean recordHiddenness() { - return populateBit(Bit.HIDDEN, true); - } - /** * Records that the {@link JSDocInfo} being built should have its {@link * JSDocInfo#isNoCompile()} flag set to {@code true}. diff --git a/src/com/google/javascript/rhino/Msg.java b/src/com/google/javascript/rhino/Msg.java index 6716b1bc11a..77a0797981f 100644 --- a/src/com/google/javascript/rhino/Msg.java +++ b/src/com/google/javascript/rhino/Msg.java @@ -72,7 +72,6 @@ public enum Msg { JSDOC_FINAL("extra @final tag."), JSDOC_FUNCTION_NEWNOTOBJECT("constructed type must be an object type"), JSDOC_FUNCTION_VARARGS("variable length argument must be last."), - JSDOC_HIDDEN("extra @hidden tag"), JSDOC_IDGEN_BAD("malformed @idGenerator tag"), JSDOC_IDGEN_DUPLICATE("extra @idGenerator tag"), JSDOC_IDGEN_UNKNOWN("unknown @idGenerator parameter: {0}"), diff --git a/src/com/google/javascript/rhino/typed_ast/optimization_jsdoc.proto b/src/com/google/javascript/rhino/typed_ast/optimization_jsdoc.proto index 6b2fc540771..937fd6e1db2 100644 --- a/src/com/google/javascript/rhino/typed_ast/optimization_jsdoc.proto +++ b/src/com/google/javascript/rhino/typed_ast/optimization_jsdoc.proto @@ -48,7 +48,6 @@ enum JsdocTag { JSDOC_ABSTRACT = 19; // Used by ReplaceMessage i18n - JSDOC_HIDDEN = 21; JSDOC_SUPPRESS_MESSAGE_CONVENTION = 22; // Used by CollapseProperties diff --git a/test/com/google/javascript/jscomp/JsMessageVisitorTest.java b/test/com/google/javascript/jscomp/JsMessageVisitorTest.java index acdb503e68b..37ce838688b 100644 --- a/test/com/google/javascript/jscomp/JsMessageVisitorTest.java +++ b/test/com/google/javascript/jscomp/JsMessageVisitorTest.java @@ -903,7 +903,6 @@ public void testExtractPropertyMessageInFunction() { + "function f() {\n" + " /**\n" + " * @desc A message that demonstrates placeholders\n" - + " * @hidden\n" + " */\n" + " a.b.MSG_SILLY = goog.getMsg(\n" + " '{$adjective} ' + '{$someNoun}',\n" diff --git a/test/com/google/javascript/jscomp/parsing/JsDocInfoParserTest.java b/test/com/google/javascript/jscomp/parsing/JsDocInfoParserTest.java index afb40dd34ea..4d261154f66 100644 --- a/test/com/google/javascript/jscomp/parsing/JsDocInfoParserTest.java +++ b/test/com/google/javascript/jscomp/parsing/JsDocInfoParserTest.java @@ -2421,13 +2421,13 @@ public void testRegression3() { @Test public void testRegression4() { - String comment = " * @const\n" + " * @hidden\n" + " * @constructor\n" + " */"; + String comment = " * @const\n" + " * @private\n" + " * @constructor\n" + " */"; JSDocInfo info = parse(comment); assertThat(info.isConstant()).isTrue(); assertThat(info.isDefine()).isFalse(); assertThat(info.isConstructor()).isTrue(); - assertThat(info.isHidden()).isTrue(); + assertThat(info.getVisibility()).isEqualTo(Visibility.PRIVATE); } @Test @@ -2441,16 +2441,6 @@ public void testRegression5() { assertThat(info.getVisibility()).isEqualTo(Visibility.PUBLIC); } - @Test - public void testRegression6() { - String comment = "@hidden\n@enum\n@public*/"; - - JSDocInfo info = parse(comment); - assertThat(info.isHidden()).isTrue(); - assertTypeEquals(NUMBER_TYPE, info.getEnumParameterType()); - assertThat(info.getVisibility()).isEqualTo(Visibility.PUBLIC); - } - @Test public void testRegression7() { String comment = @@ -2490,7 +2480,6 @@ public void testRegression9() { assertThat(jsdoc.isConstant()).isFalse(); assertThat(jsdoc.getDescription()).isNull(); assertThat(jsdoc.getEnumParameterType()).isNull(); - assertThat(jsdoc.isHidden()).isFalse(); assertThat(jsdoc.getParameterCount()).isEqualTo(1); assertTypeEquals(STRING_TYPE, jsdoc.getParameterType("p0")); assertThat(jsdoc.getReturnType()).isNull(); @@ -2511,7 +2500,6 @@ public void testRegression10() { assertThat(jsdoc.isConstant()).isFalse(); assertThat(jsdoc.getDescription()).isNull(); assertThat(jsdoc.getEnumParameterType()).isNull(); - assertThat(jsdoc.isHidden()).isFalse(); assertThat(jsdoc.getParameterCount()).isEqualTo(2); assertTypeEquals(STRING_OBJECT_TYPE, jsdoc.getParameterType("p0")); assertTypeEquals(BOOLEAN_TYPE, jsdoc.getParameterType("p1")); @@ -2528,7 +2516,6 @@ public void testRegression11() { assertThat(jsdoc.isConstant()).isFalse(); assertThat(jsdoc.getDescription()).isNull(); assertThat(jsdoc.getEnumParameterType()).isNull(); - assertThat(jsdoc.isHidden()).isFalse(); assertThat(jsdoc.getParameterCount()).isEqualTo(0); assertThat(jsdoc.getReturnType()).isNull(); assertThat(jsdoc.getType()).isNull(); @@ -2543,7 +2530,6 @@ public void testRegression12() { assertThat(jsdoc.isConstant()).isFalse(); assertThat(jsdoc.getDescription()).isNull(); assertThat(jsdoc.getEnumParameterType()).isNull(); - assertThat(jsdoc.isHidden()).isFalse(); assertThat(jsdoc.getParameterCount()).isEqualTo(0); assertThat(jsdoc.getReturnType()).isNull(); assertThat(jsdoc.getType()).isNull(); @@ -2558,7 +2544,6 @@ public void testRegression13() { assertThat(jsdoc.isConstant()).isFalse(); assertThat(jsdoc.getDescription()).isNull(); assertThat(jsdoc.getEnumParameterType()).isNull(); - assertThat(jsdoc.isHidden()).isFalse(); assertThat(jsdoc.getParameterCount()).isEqualTo(0); assertThat(jsdoc.getReturnType()).isNull(); assertTypeEquals(REGEXP_TYPE, jsdoc.getType()); @@ -2573,7 +2558,6 @@ public void testRegression14() { assertThat(jsdoc.isConstant()).isTrue(); assertThat(jsdoc.getDescription()).isNull(); assertThat(jsdoc.getEnumParameterType()).isNull(); - assertThat(jsdoc.isHidden()).isFalse(); assertThat(jsdoc.getParameterCount()).isEqualTo(0); assertThat(jsdoc.getReturnType()).isNull(); assertThat(jsdoc.getType()).isNull(); @@ -2588,7 +2572,6 @@ public void testRegression15() { assertThat(jsdoc.isConstant()).isTrue(); assertThat(jsdoc.getDescription()).isEqualTo("Hello, World!"); assertThat(jsdoc.getEnumParameterType()).isNull(); - assertThat(jsdoc.isHidden()).isFalse(); assertThat(jsdoc.getParameterCount()).isEqualTo(0); assertThat(jsdoc.getReturnType()).isNull(); assertThat(jsdoc.getType()).isNull(); @@ -2603,7 +2586,6 @@ public void testRegression16() { assertThat(jsdoc.getBaseType()).isNull(); assertThat(jsdoc.isConstant()).isFalse(); assertTypeEquals(STRING_TYPE, jsdoc.getType()); - assertThat(jsdoc.isHidden()).isFalse(); assertThat(jsdoc.getParameterCount()).isEqualTo(0); assertThat(jsdoc.getReturnType()).isNull(); assertThat(jsdoc.getVisibility()).isEqualTo(Visibility.INHERITED); diff --git a/test/com/google/javascript/jscomp/parsing/JsDocTokenStreamTest.java b/test/com/google/javascript/jscomp/parsing/JsDocTokenStreamTest.java index 7717a9eed87..eacf499de90 100644 --- a/test/com/google/javascript/jscomp/parsing/JsDocTokenStreamTest.java +++ b/test/com/google/javascript/jscomp/parsing/JsDocTokenStreamTest.java @@ -127,15 +127,15 @@ public void testJsDocTokenization5() { public void testJsDocTokenization6() { ImmutableList tokens = ImmutableList.of(ANNOTATION, EOL, ANNOTATION, EOL, ANNOTATION, EOC); - ImmutableList strings = ImmutableList.of("hidden", "static", "desc"); - testJSDocTokenStream("@hidden\n@static\n@desc*/", tokens, strings); - testJSDocTokenStream("@hidden\n @static\n@desc*/", tokens, strings); - testJSDocTokenStream("@hidden\n@static\n @desc*/", tokens, strings); - testJSDocTokenStream("@hidden\n@static\n@desc */", tokens, strings); - testJSDocTokenStream(" @hidden \n@static\n @desc*/", tokens, strings); - testJSDocTokenStream("@hidden\n@static \n @desc */", tokens, strings); - testJSDocTokenStream("@hidden\n@static\n@desc*/", tokens, strings); - testJSDocTokenStream("@hidden \n@static \n @desc*/", tokens, strings); + ImmutableList strings = ImmutableList.of("private", "static", "desc"); + testJSDocTokenStream("@private\n@static\n@desc*/", tokens, strings); + testJSDocTokenStream("@private\n @static\n@desc*/", tokens, strings); + testJSDocTokenStream("@private\n@static\n @desc*/", tokens, strings); + testJSDocTokenStream("@private\n@static\n@desc */", tokens, strings); + testJSDocTokenStream(" @private \n@static\n @desc*/", tokens, strings); + testJSDocTokenStream("@private\n@static \n @desc */", tokens, strings); + testJSDocTokenStream("@private\n@static\n@desc*/", tokens, strings); + testJSDocTokenStream("@private \n@static \n @desc*/", tokens, strings); } @Test diff --git a/test/com/google/javascript/rhino/JSDocInfoTest.java b/test/com/google/javascript/rhino/JSDocInfoTest.java index e33c572d887..c8416ac9cd3 100644 --- a/test/com/google/javascript/rhino/JSDocInfoTest.java +++ b/test/com/google/javascript/rhino/JSDocInfoTest.java @@ -104,7 +104,6 @@ public void testSetType() { assertThat(info.hasType()).isTrue(); assertThat(info.isConstant()).isFalse(); assertThat(info.isConstructor()).isFalse(); - assertThat(info.isHidden()).isFalse(); } @Test @@ -124,7 +123,6 @@ public void testSetTypeAndVisibility() { assertThat(info.hasType()).isTrue(); assertThat(info.isConstant()).isFalse(); assertThat(info.isConstructor()).isFalse(); - assertThat(info.isHidden()).isFalse(); } @Test @@ -143,7 +141,6 @@ public void testSetReturnType() { assertThat(info.hasType()).isFalse(); assertThat(info.isConstant()).isFalse(); assertThat(info.isConstructor()).isFalse(); - assertThat(info.isHidden()).isFalse(); } /** Tests that all module local names get correctly removed from a JSTypeExpression */ @@ -181,7 +178,6 @@ public void testSetReturnTypeAndBaseType() { assertThat(info.hasType()).isFalse(); assertThat(info.isConstant()).isFalse(); assertThat(info.isConstructor()).isFalse(); - assertThat(info.isHidden()).isFalse(); } @Test @@ -201,7 +197,6 @@ public void testSetEnumParameterType() { assertThat(info.hasType()).isFalse(); assertThat(info.isConstant()).isFalse(); assertThat(info.isConstructor()).isFalse(); - assertThat(info.isHidden()).isFalse(); } @Test @@ -279,7 +274,6 @@ public void testSetConstant() { assertThat(info.isConstant()).isTrue(); assertThat(info.isConstructor()).isFalse(); assertThat(info.isDefine()).isFalse(); - assertThat(info.isHidden()).isFalse(); } @Test @@ -291,7 +285,6 @@ public void testSetConstructor() { assertThat(info.isConstant()).isFalse(); assertThat(info.isConstructor()).isTrue(); assertThat(info.isDefine()).isFalse(); - assertThat(info.isHidden()).isFalse(); } @Test @@ -303,20 +296,6 @@ public void testSetDefine() { assertThat(info.isConstant()).isTrue(); assertThat(info.isConstructor()).isFalse(); assertThat(info.isDefine()).isTrue(); - assertThat(info.isHidden()).isFalse(); - } - - @Test - public void testSetHidden() { - JSDocInfo.Builder builder = JSDocInfo.builder(); - builder.recordHiddenness(); - JSDocInfo info = builder.build(); - - assertThat(info.hasType()).isFalse(); - assertThat(info.isConstant()).isFalse(); - assertThat(info.isConstructor()).isFalse(); - assertThat(info.isDefine()).isFalse(); - assertThat(info.isHidden()).isTrue(); } @Test @@ -419,14 +398,14 @@ public void testMultipleSetFlags1() { JSDocInfo.Builder builder = JSDocInfo.builder(); builder.recordConstancy(); builder.recordConstructor(); - builder.recordHiddenness(); + builder.recordNoCollapse(); JSDocInfo info = builder.build(); assertThat(info.hasType()).isFalse(); assertThat(info.isConstant()).isTrue(); assertThat(info.isConstructor()).isTrue(); assertThat(info.isDefine()).isFalse(); - assertThat(info.isHidden()).isTrue(); + assertThat(info.isNoCollapse()).isTrue(); builder = info.toBuilder(); builder.recordMutable(); @@ -434,7 +413,7 @@ public void testMultipleSetFlags1() { assertThat(info.isConstant()).isFalse(); assertThat(info.isDefine()).isFalse(); - assertThat(info.isHidden()).isTrue(); + assertThat(info.isNoCollapse()).isTrue(); } @Test @@ -463,7 +442,7 @@ public void testClone() { builder.recordDescription("The source info"); builder.recordConstancy(); builder.recordConstructor(); - builder.recordHiddenness(); + builder.recordNoCollapse(); builder.recordBaseType( new JSTypeExpression(new Node(Token.BANG, Node.newString("Number")), "")); builder.recordReturnType(fromString("string")); @@ -477,7 +456,7 @@ public void testClone() { assertType(resolve(cloned.getReturnType())).isEqualTo(getNativeType(STRING_TYPE)); assertThat(cloned.isConstant()).isTrue(); assertThat(cloned.isConstructor()).isTrue(); - assertThat(cloned.isHidden()).isTrue(); + assertThat(cloned.isNoCollapse()).isTrue(); // TODO - cannot change these things! // cloned.recordDescription("The cloned info"); @@ -486,7 +465,7 @@ public void testClone() { // assertType(resolve(cloned.getBaseType())).isEqualTo(getNativeType(STRING_TYPE)); // assertThat(cloned.getDescription()).isEqualTo("The cloned info"); - // assertThat(cloned.isHidden()).isFalse(); + // assertThat(cloned.isNoCollapse()).isFalse(); // // Original info should be unchanged. // assertType(resolve(info.getBaseType())) @@ -495,7 +474,7 @@ public void testClone() { // assertType(resolve(info.getReturnType())).isEqualTo(getNativeType(STRING_TYPE)); // assertThat(info.isConstant()).isTrue(); // assertThat(info.isConstructor()).isTrue(); - // assertThat(info.isHidden()).isTrue(); + // assertThat(info.isNoCollapse()).isTrue(); } @Test @@ -504,7 +483,6 @@ public void testCloneTypeExpressions1() { builder.recordDescription("The source info"); builder.recordConstancy(); builder.recordConstructor(); - builder.recordHiddenness(); builder.recordBaseType( new JSTypeExpression(new Node(Token.BANG, Node.newString("Number")), "")); builder.recordReturnType(fromString("string"));