Skip to content

Commit 4afa5e8

Browse files
brad4dcopybara-github
authored andcommitted
Use LinkedHash(Map|Set) to guarantee deterministic iteration order
parsing PiperOrigin-RevId: 614828574
1 parent 459994d commit 4afa5e8

File tree

3 files changed

+13
-22
lines changed

3 files changed

+13
-22
lines changed

src/com/google/javascript/jscomp/parsing/IRFactory.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@
136136
import java.math.BigInteger;
137137
import java.util.ArrayDeque;
138138
import java.util.Deque;
139-
import java.util.HashSet;
140139
import java.util.LinkedHashSet;
141140
import java.util.List;
142141
import java.util.Set;
@@ -193,6 +192,7 @@ class IRFactory {
193192

194193
private final StaticSourceFile sourceFile;
195194
private final @Nullable String sourceName;
195+
196196
/** Source file reference that also contains the file content. */
197197
private final SourceFile fileWithContent;
198198

@@ -227,7 +227,7 @@ class IRFactory {
227227
/** If non-null, use this set of keywords instead of TokenStream.isKeyword(). */
228228
private final @Nullable ImmutableSet<String> reservedKeywords;
229229

230-
private final Set<Comment> parsedComments = new HashSet<>();
230+
private final Set<Comment> parsedComments = new LinkedHashSet<>();
231231

232232
private final LinkedHashSet<String> licenseBuilder = new LinkedHashSet<>();
233233
private @Nullable JSDocInfo firstFileoverview = null;
@@ -288,8 +288,7 @@ private static final class CommentTracker {
288288
this.advance();
289289
}
290290

291-
@Nullable
292-
Comment current() {
291+
@Nullable Comment current() {
293292
return (this.index >= this.source.size()) ? null : this.source.get(this.index);
294293
}
295294

src/com/google/javascript/jscomp/parsing/JsDocInfoParser.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import com.google.javascript.rhino.TokenStream;
3939
import com.google.javascript.rhino.TokenUtil;
4040
import java.util.ArrayList;
41-
import java.util.HashSet;
41+
import java.util.LinkedHashSet;
4242
import java.util.List;
4343
import java.util.Set;
4444
import org.jspecify.nullness.Nullable;
@@ -1362,7 +1362,7 @@ private JsDocToken parseSuppressTag(JsDocToken token) {
13621362
addParserWarning(Msg.JSDOC_SUPPRESS);
13631363
return token;
13641364
} else {
1365-
Set<String> suppressions = new HashSet<>();
1365+
Set<String> suppressions = new LinkedHashSet<>();
13661366
while (true) {
13671367
if (match(JsDocToken.STRING)) {
13681368
String name = stream.getString();
@@ -1465,7 +1465,7 @@ private JsDocToken parseClosurePrimitiveTag(JsDocToken token) {
14651465
*/
14661466
private JsDocToken parseModifiesTag(JsDocToken token) {
14671467
if (token == JsDocToken.LEFT_CURLY) {
1468-
Set<String> modifies = new HashSet<>();
1468+
Set<String> modifies = new LinkedHashSet<>();
14691469
while (true) {
14701470
if (match(JsDocToken.STRING)) {
14711471
String name = stream.getString();
@@ -2577,7 +2577,7 @@ private Node parseRecordType(JsDocToken token) {
25772577
private @Nullable Node parseFieldTypeList(JsDocToken token) {
25782578
Node fieldTypeList = newNode(Token.LB);
25792579

2580-
Set<String> names = new HashSet<>();
2580+
Set<String> names = new LinkedHashSet<>();
25812581

25822582
do {
25832583
Node fieldType = parseFieldType(token);

src/com/google/javascript/jscomp/parsing/ParserRunner.java

+6-14
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import com.google.javascript.rhino.ErrorReporter;
3636
import com.google.javascript.rhino.Node;
3737
import com.google.javascript.rhino.StaticSourceFile;
38-
import java.util.HashSet;
38+
import java.util.LinkedHashSet;
3939
import java.util.List;
4040
import java.util.Set;
4141
import org.jspecify.nullness.Nullable;
@@ -75,7 +75,7 @@ public static Config createConfig(
7575
if (extraAnnotationNames == null) {
7676
effectiveAnnotationNames = annotationNames;
7777
} else {
78-
effectiveAnnotationNames = new HashSet<>(annotationNames);
78+
effectiveAnnotationNames = new LinkedHashSet<>(annotationNames);
7979
effectiveAnnotationNames.addAll(extraAnnotationNames);
8080
}
8181
return Config.builder()
@@ -188,9 +188,7 @@ private static class Es6ErrorReporter
188188
private boolean errorSeen = false;
189189
private final boolean reportAllErrors;
190190

191-
Es6ErrorReporter(
192-
ErrorReporter reporter,
193-
boolean reportAllErrors) {
191+
Es6ErrorReporter(ErrorReporter reporter, boolean reportAllErrors) {
194192
this.reporter = reporter;
195193
this.reportAllErrors = reportAllErrors;
196194
}
@@ -201,23 +199,17 @@ protected void reportError(SourcePosition location, String message) {
201199
// sometimes it is useful to keep going.
202200
if (reportAllErrors || !errorSeen) {
203201
errorSeen = true;
204-
this.reporter.error(
205-
message, location.source.name,
206-
location.line + 1, location.column);
202+
this.reporter.error(message, location.source.name, location.line + 1, location.column);
207203
}
208204
}
209205

210206
@Override
211207
protected void reportWarning(SourcePosition location, String message) {
212-
this.reporter.warning(
213-
message, location.source.name,
214-
location.line + 1, location.column);
208+
this.reporter.warning(message, location.source.name, location.line + 1, location.column);
215209
}
216210
}
217211

218-
/**
219-
* Holds results of parsing.
220-
*/
212+
/** Holds results of parsing. */
221213
public static class ParseResult {
222214
public final Node ast;
223215
public final List<Comment> comments;

0 commit comments

Comments
 (0)