Skip to content

Commit be1c2fe

Browse files
committed
Review feedback
1 parent cd5af88 commit be1c2fe

File tree

7 files changed

+18
-40
lines changed

7 files changed

+18
-40
lines changed

src/com/google/javascript/jscomp/CompilerInput.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
* and maintain state such as module for the input and whether the input is an extern. Also
4949
* calculates provided and required types.
5050
*/
51-
public class CompilerInput extends DependencyInfo.Base {
51+
public class CompilerInput implements DependencyInfo {
5252

5353
private static final long serialVersionUID = 2L;
5454

@@ -573,11 +573,13 @@ public String toString() {
573573

574574
@Override
575575
public boolean isEs6Module() {
576+
// Instead of doing a full parse to read all load flags, just ask the delegate, which at least has this much info
576577
return getDependencyInfo().isEs6Module();
577578
}
578579

579580
@Override
580581
public boolean isGoogModule() {
582+
// Instead of doing a full parse to read all load flags, just ask the delegate, which at least has this much info
581583
return getDependencyInfo().isGoogModule();
582584
}
583585

src/com/google/javascript/jscomp/JSChunk.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
* A JavaScript chunk has a unique name, consists of a list of compiler inputs, and can depend on
4242
* other chunks.
4343
*/
44-
public final class JSChunk extends DependencyInfo.Base implements Serializable {
44+
public final class JSChunk implements Serializable, DependencyInfo {
4545
// The name of the artificial chunk containing all strong sources when there is no chunk spec.
4646
// If there is a chunk spec, strong sources go in their respective chunks, and this chunk does
4747
// not exist.
@@ -59,7 +59,7 @@ public final class JSChunk extends DependencyInfo.Base implements Serializable {
5959
private final String name;
6060

6161
/** Source code inputs */
62-
// non-final for deserilaization
62+
// non-final for deserialization
6363
// CompilerInputs must be explicitly added to the JSChunk again after deserialization
6464
// A map keyed by the {@code CompilerInput.getName()} to speed up getByName and removeByName.
6565
private transient Map<String, CompilerInput> inputs = new LinkedHashMap<>();
@@ -131,15 +131,6 @@ public ImmutableMap<String, String> getLoadFlags() {
131131
throw new UnsupportedOperationException();
132132
}
133133

134-
@Override
135-
public boolean isModule() {
136-
// NOTE: The meaning of "module" has changed over time. A "JsChunk" is
137-
// a collection of inputs that are loaded together. A "module" file,
138-
// is a CommonJs module, ES6 module, goog.module or other file whose
139-
// top level symbols are not in global scope.
140-
throw new UnsupportedOperationException();
141-
}
142-
143134
/** Adds a source file input to this chunk. */
144135
public void add(SourceFile file) {
145136
add(new CompilerInput(file));

src/com/google/javascript/jscomp/LazyParsedDependencyInfo.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import org.jspecify.nullness.Nullable;
3030

3131
/** A DependencyInfo class that determines load flags by parsing the AST just-in-time. */
32-
public class LazyParsedDependencyInfo extends DependencyInfo.Base {
32+
public class LazyParsedDependencyInfo implements DependencyInfo {
3333

3434
private final DependencyInfo delegate;
3535
private @Nullable JsAst ast;
@@ -45,13 +45,13 @@ public LazyParsedDependencyInfo(DependencyInfo delegate, JsAst ast, AbstractComp
4545

4646
@Override
4747
public boolean isEs6Module() {
48-
// Instead of doing a full parse to look this up, just ask the delegate, which at least has this much info
48+
// Instead of doing a full parse to read all load flags, just ask the delegate, which at least has this much info
4949
return delegate.isEs6Module();
5050
}
5151

5252
@Override
5353
public boolean isGoogModule() {
54-
// Instead of doing a full parse to look this up, just ask the delegate, which at least has this much info
54+
// Instead of doing a full parse to read all load flags, just ask the delegate, which at least has this much info
5555
return delegate.isGoogModule();
5656
}
5757

src/com/google/javascript/jscomp/deps/DependencyInfo.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,21 @@ abstract static class Builder {
129129
/** Gets the symbols required by this file. */
130130
ImmutableList<Require> getRequires();
131131

132-
ImmutableList<String> getRequiredSymbols();
132+
default ImmutableList<String> getRequiredSymbols() {
133+
return Require.asSymbolList(getRequires());
134+
}
133135

134136
/** Gets the symbols type-required by this file (i.e. for typechecking only). */
135137
ImmutableList<String> getTypeRequires();
136138

137139
/** Gets the loading information for this file. */
138140
ImmutableMap<String, String> getLoadFlags();
139141

140-
/** Whether the symbol is provided by a module */
141-
boolean isModule();
142-
142+
/** Whether the symbol is provided by an ES6 module */
143143
default boolean isEs6Module() {
144144
return "es6".equals(getLoadFlags().get("module"));
145145
}
146+
/** Whether the symbol is provided by a goog module */
146147
default boolean isGoogModule() {
147148
return "goog".equals(getLoadFlags().get("module"));
148149
}
@@ -153,21 +154,6 @@ default boolean isGoogModule() {
153154
/** Whether the file has the '@nocompile' annotation. */
154155
boolean getHasNoCompileAnnotation();
155156

156-
/**
157-
* Abstract base implementation that defines derived accessors such
158-
* as {@link #isModule}.
159-
*/
160-
abstract class Base implements DependencyInfo {
161-
@Override public boolean isModule() {
162-
return isGoogModule();
163-
}
164-
165-
@Override
166-
public ImmutableList<String> getRequiredSymbols() {
167-
return Require.asSymbolList(getRequires());
168-
}
169-
}
170-
171157
/** Utility methods. */
172158
class Util {
173159
private Util() {}

src/com/google/javascript/jscomp/deps/DepsGenerator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ private void validateDependencies(Iterable<DependencyInfo> preparsedFileDependen
277277
} else if (provider == depInfo) {
278278
reportSameFile(namespace, depInfo);
279279
} else {
280-
depInfo.isModule();
281280
boolean providerIsEs6Module = provider.isEs6Module();
282281

283282
switch (require.getType()) {

src/com/google/javascript/jscomp/deps/SimpleDependencyInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* A class to hold JS dependency information for a single .js file.
2828
*/
2929
@Immutable @AutoValue @AutoValue.CopyAnnotations
30-
public abstract class SimpleDependencyInfo extends DependencyInfo.Base {
30+
public abstract class SimpleDependencyInfo implements DependencyInfo {
3131

3232
public static Builder builder(String srcPathRelativeToClosure, String pathOfDefiningFile) {
3333
return new AutoValue_SimpleDependencyInfo.Builder()

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void testLoadFlagsParsesEs3() {
6767
// is lifted and we can depend on a newer Truth, these assertions should be
6868
// changed to assertThat(info.getLoadFlags()).containsExactly(...)
6969
assertThat(info.getLoadFlags()).containsExactly("foo", "bar");
70-
assertThat(info.isModule()).isFalse();
70+
assertThat(info.isGoogModule()).isFalse();
7171
}
7272

7373
@Test
@@ -82,7 +82,7 @@ public void testLoadFlagsParsesEs5() {
8282
DependencyInfo info = new LazyParsedDependencyInfo(delegate, ast, compiler);
8383

8484
assertThat(info.getLoadFlags()).containsExactly("module", "goog", "lang", "es5");
85-
assertThat(info.isModule()).isTrue();
85+
assertThat(info.isGoogModule()).isTrue();
8686
}
8787

8888
@Test
@@ -97,7 +97,7 @@ public void testLoadFlagsParsesEs6Impl() {
9797
DependencyInfo info = new LazyParsedDependencyInfo(delegate, ast, compiler);
9898

9999
assertThat(info.getLoadFlags()).containsExactly("foo", "bar", "lang", "es6");
100-
assertThat(info.isModule()).isFalse();
100+
assertThat(info.isGoogModule()).isFalse();
101101
}
102102

103103
@Test
@@ -112,7 +112,7 @@ public void testLoadFlagsParsesEs6() {
112112
DependencyInfo info = new LazyParsedDependencyInfo(delegate, ast, compiler);
113113

114114
assertThat(info.getLoadFlags()).containsExactly("foo", "bar", "lang", "es6");
115-
assertThat(info.isModule()).isFalse();
115+
assertThat(info.isGoogModule()).isFalse();
116116
}
117117

118118
@Test

0 commit comments

Comments
 (0)