Skip to content

Commit

Permalink
Remove code for avoiding marking module exports as @const.
Browse files Browse the repository at this point in the history
This is not needed now that we make a distinction between @Final (meaning not
subclassable or overwritable) and @const (just not overwritable).

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=138241813
  • Loading branch information
blickly committed Nov 7, 2016
1 parent 3971bdb commit 4c21156
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 25 deletions.
12 changes: 1 addition & 11 deletions src/com/google/javascript/jscomp/ClosureRewriteModule.java
Expand Up @@ -1408,20 +1408,10 @@ private void maybeSplitMultiVar(Node rhsNode) {
statementNode.getParent().addChildBefore(IR.var(nameNode, rhsNode), statementNode);
}

/**
* Will skip const if the target is a class definition as that has a different meaning.
*/
private void markConstAndCopyJsDoc(Node from, Node target, Node value) {
JSDocInfo info = from.getJSDocInfo();
JSDocInfoBuilder builder = JSDocInfoBuilder.maybeCopyFrom(info);

// Don't add @const on class declarations because in that context it means "not subclassable".
if (!NodeUtil.isCallTo(value, "goog.defineClass")
&& !(info != null && info.isConstructorOrInterface())) {
builder.recordConstancy();
compiler.reportCodeChange();
}

builder.recordConstancy();
target.setJSDocInfo(builder.build());
}

Expand Down
28 changes: 14 additions & 14 deletions test/com/google/javascript/jscomp/ClosureRewriteModuleTest.java
Expand Up @@ -173,7 +173,7 @@ public void testDestructuringImports() {
new String[] {
LINE_JOINER.join(
"/** @const */ var module$exports$ns$b = {};",
"/** @constructor */ module$exports$ns$b.Foo = function() {};"),
"/** @constructor @const */ module$exports$ns$b.Foo = function() {};"),
LINE_JOINER.join(
"/** @const */ var module$exports$ns$a = {}",
"/** @type {module$exports$ns$b.Foo} */",
Expand Down Expand Up @@ -236,7 +236,7 @@ public void testDestructuringImports() {
new String[] {
LINE_JOINER.join(
"goog.provide('ns.b');",
"/** @constructor */ ns.b.Foo = function() {};"),
"/** @constructor @const */ ns.b.Foo = function() {};"),
LINE_JOINER.join(
"/** @const */ var module$exports$ns$a = {}",
"/** @type {ns.b.Foo} */",
Expand All @@ -256,7 +256,7 @@ public void testDestructuringImports() {
new String[] {
LINE_JOINER.join(
"/** @const */ var module$exports$ns$b = {};",
"/** @constructor */ module$exports$ns$b.Foo = function() {};"),
"/** @constructor @const */ module$exports$ns$b.Foo = function() {};"),
LINE_JOINER.join(
"/** @const */ var module$exports$ns$a = {}",
"/** @type {module$exports$ns$b.Foo} */",
Expand Down Expand Up @@ -424,7 +424,7 @@ public void testTypeOnlyModuleImport() {
"/** @type {ns.B} */ var c;")},

new String[] {
"/** @constructor */ var module$exports$ns$B = function() {};",
"/** @constructor @const */ var module$exports$ns$B = function() {};",
LINE_JOINER.join(
"/** @const */ var module$exports$ns$a = {};",
"/** @type {module$exports$ns$B} */ var module$contents$ns$a_c;")});
Expand Down Expand Up @@ -477,7 +477,7 @@ public void testTypeOnlyModuleImportFromLegacyFile() {
"/** @type {ns.B} */ var c;")},

new String[] {
"/** @constructor */ var module$exports$ns$B = function() {};",
"/** @constructor @const */ var module$exports$ns$B = function() {};",
LINE_JOINER.join(
"goog.provide('ns.a');",
"",
Expand Down Expand Up @@ -1122,23 +1122,23 @@ public void testExport6() {
"};"));
}

public void testExport7_classNoConst() {
public void testExport7() {
test(
LINE_JOINER.join(
"goog.module('ns.a');",
"/** @constructor */",
"exports = function() {};"),

"/** @constructor */ var module$exports$ns$a = function() {};");
"/** @constructor @const */ var module$exports$ns$a = function() {};");
}

public void testExport8_classNoConst() {
public void testExport8() {
test(
LINE_JOINER.join(
"goog.module('ns.a');",
"exports = goog.defineClass({});"),

"var module$exports$ns$a = goog.defineClass({});");
"/** @const */ var module$exports$ns$a = goog.defineClass({});");
}

public void testExport9() {
Expand Down Expand Up @@ -1175,15 +1175,15 @@ public void testExport11() {
"/** @const @typedef {string} */ module$exports$a$B.C;"));
}

public void testExport12_classNoConst() {
public void testExport12() {
test(
LINE_JOINER.join(
"goog.module('ns.a');",
"exports.foo = goog.defineClass({});"),

LINE_JOINER.join(
"/** @const */ var module$exports$ns$a = {};",
"module$exports$ns$a.foo = goog.defineClass({});"));
"/** @const */ module$exports$ns$a.foo = goog.defineClass({});"));
}

public void testExport13() {
Expand Down Expand Up @@ -1605,7 +1605,7 @@ public void testLegacyGoogModuleValidReferences() {
"/** @param {a.b.Foo} x */ function f(x) {}"
},
new String[] {
"goog.provide('a.b.Foo'); /** @constructor */ a.b.Foo = function() {};",
"goog.provide('a.b.Foo'); /** @constructor @const */ a.b.Foo = function() {};",
"/** @param {a.b.Foo} x */ function f(x) {}"
});

Expand Down Expand Up @@ -1797,7 +1797,7 @@ public void testRewriteGoogModuleAliases6() {
new String[] {
LINE_JOINER.join(
"/** @const */ var module$exports$base = {};",
"/** @constructor */ module$exports$base.Foo = function() {};"),
"/** @constructor @const */ module$exports$base.Foo = function() {};"),
"/** @const */ var module$exports$FooWrapper = module$exports$base.Foo;",
});
}
Expand All @@ -1818,7 +1818,7 @@ public void testRewriteGoogModuleAliases7() {
new String[] {
LINE_JOINER.join(
"/** @const */ var module$exports$base = {};",
"/** @constructor */ module$exports$base.Foo = function() {};"),
"/** @constructor @const */ module$exports$base.Foo = function() {};"),
"/** @const */ var module$exports$FooWrapper = module$exports$base.Foo;",
});
}
Expand Down

0 comments on commit 4c21156

Please sign in to comment.