Skip to content

Commit 042945f

Browse files
rishipalcopybara-github
authored andcommitted
Skip constructing global namespace and converting super constructor calls when unnecessary during class rewriting
Currently, the global namespace construction and es6ConvertSuperConstructorCalls both get run even if the SCRIPT does not have Feature.SUPER specifically. This CL fixes it to only run if the SCRIPT has a Feature.SUPER. PiperOrigin-RevId: 621842089
1 parent 65d5fd8 commit 042945f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.google.javascript.jscomp.GlobalNamespace.Ref;
2626
import com.google.javascript.jscomp.colors.Color;
2727
import com.google.javascript.jscomp.colors.StandardColors;
28+
import com.google.javascript.jscomp.parsing.parser.FeatureSet.Feature;
2829
import com.google.javascript.rhino.IR;
2930
import com.google.javascript.rhino.Node;
3031
import com.google.javascript.rhino.QualifiedName;
@@ -71,6 +72,10 @@ public Es6ConvertSuperConstructorCalls(AbstractCompiler compiler) {
7172

7273
@Override
7374
public boolean shouldTraverse(NodeTraversal t, Node n, Node parent) {
75+
if (n.isScript() && !NodeUtil.getFeatureSetOfScript(n).contains(Feature.SUPER)) {
76+
// If a script contains Feature.SUPER, only then process super constructor calls for it
77+
return false;
78+
}
7479
if (n.isFunction()) {
7580
// TODO(bradfordcsmith): Avoid creating data for non-constructor functions.
7681
constructorDataStack.push(new ConstructorData(n));

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ public void process(Node externs, Node root) {
7171
// have an invalid AST state between passes.
7272
// TODO(bradfordcsmith): It would probably be more readable and efficient to merge the super
7373
// constructor rewriting logic into this class.
74+
// The code here only creates the GlobalNamespace object which is very cheap. The expensive
75+
// building of global namespace happens inside es6ConvertSuperConstructorCalls pass.
7476
convertSuperConstructorCalls.setGlobalNamespace(new GlobalNamespace(compiler, externs, root));
75-
TranspilationPasses.processTranspile(compiler, root, features, convertSuperConstructorCalls);
77+
NodeTraversal.traverse(compiler, root, convertSuperConstructorCalls);
7678
TranspilationPasses.maybeMarkFeaturesAsTranspiledAway(compiler, root, features);
7779
}
7880

@@ -256,7 +258,9 @@ private Node createObjectDotDefineProperty() {
256258
this.transpilationNamespace, "Object.defineProperty");
257259
}
258260

259-
/** @param member A getter or setter */
261+
/**
262+
* @param member A getter or setter
263+
*/
260264
private void addToDefinePropertiesObject(ClassDeclarationMetadata metadata, Node member) {
261265
Preconditions.checkArgument(!member.isComputedProp());
262266
Node obj =

0 commit comments

Comments
 (0)