Skip to content

Commit af228b5

Browse files
committed
Don't emit __extends if one is already in scope
1 parent c075fe1 commit af228b5

13 files changed

+170
-1
lines changed

src/compiler/checker.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7886,7 +7886,7 @@ module ts {
78867886
var staticType = <ObjectType>getTypeOfSymbol(symbol);
78877887
var baseTypeNode = getClassBaseTypeNode(node);
78887888
if (baseTypeNode) {
7889-
emitExtends = emitExtends || !isInAmbientContext(node);
7889+
emitExtends = emitExtends || !(isInAmbientContext(node) || resolveName(node.parent, escapeIdentifier('__extends'), SymbolFlags.Value, undefined, undefined));
78907890
checkTypeReference(baseTypeNode);
78917891
}
78927892
if (type.baseTypes.length) {
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [__extends.ts]
2+
var __extends;
3+
4+
class A { }
5+
class B extends A { }
6+
7+
//// [__extends.js]
8+
var __extends;
9+
var A = (function () {
10+
function A() {
11+
}
12+
return A;
13+
})();
14+
var B = (function (_super) {
15+
__extends(B, _super);
16+
function B() {
17+
_super.apply(this, arguments);
18+
}
19+
return B;
20+
})(A);
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/compiler/__extends.ts ===
2+
var __extends;
3+
>__extends : any
4+
5+
class A { }
6+
>A : A
7+
8+
class B extends A { }
9+
>B : B
10+
>A : A
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//// [__extendsAmbient.ts]
2+
declare var __extends;
3+
4+
class A { }
5+
class B extends A { }
6+
7+
//// [__extendsAmbient.js]
8+
var A = (function () {
9+
function A() {
10+
}
11+
return A;
12+
})();
13+
var B = (function (_super) {
14+
__extends(B, _super);
15+
function B() {
16+
_super.apply(this, arguments);
17+
}
18+
return B;
19+
})(A);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/compiler/__extendsAmbient.ts ===
2+
declare var __extends;
3+
>__extends : any
4+
5+
class A { }
6+
>A : A
7+
8+
class B extends A { }
9+
>B : B
10+
>A : A
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//// [__extendsModule.ts]
2+
3+
module M {
4+
export var __extends;
5+
}
6+
7+
class A { }
8+
class B extends A { }
9+
10+
//// [__extendsModule.js]
11+
var __extends = this.__extends || function (d, b) {
12+
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
13+
function __() { this.constructor = d; }
14+
__.prototype = b.prototype;
15+
d.prototype = new __();
16+
};
17+
var M;
18+
(function (M) {
19+
M.__extends;
20+
})(M || (M = {}));
21+
var A = (function () {
22+
function A() {
23+
}
24+
return A;
25+
})();
26+
var B = (function (_super) {
27+
__extends(B, _super);
28+
function B() {
29+
_super.apply(this, arguments);
30+
}
31+
return B;
32+
})(A);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/compiler/__extendsModule.ts ===
2+
3+
module M {
4+
>M : typeof M
5+
6+
export var __extends;
7+
>__extends : any
8+
}
9+
10+
class A { }
11+
>A : A
12+
13+
class B extends A { }
14+
>B : B
15+
>A : A
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//// [tests/cases/compiler/__extendsMultifile.ts] ////
2+
3+
//// [foo.ts]
4+
5+
declare var __extends;
6+
7+
//// [bar.ts]
8+
class A { }
9+
class B extends A { }
10+
11+
12+
//// [foo.js]
13+
//// [bar.js]
14+
var A = (function () {
15+
function A() {
16+
}
17+
return A;
18+
})();
19+
var B = (function (_super) {
20+
__extends(B, _super);
21+
function B() {
22+
_super.apply(this, arguments);
23+
}
24+
return B;
25+
})(A);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/foo.ts ===
2+
3+
declare var __extends;
4+
>__extends : any
5+
6+
=== tests/cases/compiler/bar.ts ===
7+
class A { }
8+
>A : A
9+
10+
class B extends A { }
11+
>B : B
12+
>A : A
13+

tests/cases/compiler/__extends.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
var __extends;
2+
3+
class A { }
4+
class B extends A { }
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare var __extends;
2+
3+
class A { }
4+
class B extends A { }
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
module M {
3+
export var __extends;
4+
}
5+
6+
class A { }
7+
class B extends A { }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
// @Filename: foo.ts
3+
declare var __extends;
4+
5+
// @Filename: bar.ts
6+
class A { }
7+
class B extends A { }

0 commit comments

Comments
 (0)