Skip to content

Commit fd7a197

Browse files
committed
Do not emit code for @extends tags in JS.
When transpiling JavaScript, TS3.1+ emits `@extends` tags as code. E.g. /** @extends {SuperClass} */ class SubClass {} Causes an ES5 emit that references SuperClass: /** * @extends {SomeBase} */ var SubClass = /** @Class */ (function (_super) { __extends(SubClass, _super); function SubClass() { return _super !== null && _super.apply(this, arguments) || this; } return SubClass; }(SomeBase)); Note the literal references to `SomeBase`. This appears to be an accidental effect of 0f55566. It refactored `getEffectiveBaseTypeNode` for type checking, but missed an instance where it is also used for emit logic. This change fixes the problem by specifically getting the heritage clauses directly off the AST. Change-Id: I97bf5728a10598c3076fa7125a49dc0c07d4301c
1 parent b2f76e9 commit fd7a197

File tree

11 files changed

+103
-1
lines changed

11 files changed

+103
-1
lines changed

src/compiler/transformers/es2015.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ namespace ts {
780780
enableSubstitutionsForBlockScopedBindings();
781781
}
782782

783-
const extendsClauseElement = getEffectiveBaseTypeNode(node);
783+
const extendsClauseElement = getClassExtendsHeritageElement(node);
784784
const classFunction = createFunctionExpression(
785785
/*modifiers*/ undefined,
786786
/*asteriskToken*/ undefined,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ExtendsTag/tsconfig.json(4,5): error TS5053: Option 'allowJs' cannot be specified with option 'declaration'.
2+
3+
4+
==== ExtendsTag/tsconfig.json (1 errors) ====
5+
{
6+
"compilerOptions": {
7+
"out": "test.js",
8+
"allowJs": true
9+
~~~~~~~~~
10+
!!! error TS5053: Option 'allowJs' cannot be specified with option 'declaration'.
11+
},
12+
"files": [ "extends.js" ]
13+
}
14+
15+
==== ExtendsTag/extends.js (0 errors) ====
16+
/**
17+
* @extends {SomeBase}
18+
*/
19+
class MyClass {
20+
21+
}
22+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"scenario": "Check that @extends clauses do not cause code emit in JavaScript compilation",
3+
"projectRoot": "tests/cases/projects/jsFileCompilation",
4+
"baselineCheck": true,
5+
"declaration": false,
6+
"project": "ExtendsTag",
7+
"resolvedInputFiles": [
8+
"lib.es5.d.ts",
9+
"ExtendsTag/extends.js"
10+
],
11+
"emittedFiles": [
12+
"test.js"
13+
]
14+
}

tests/baselines/reference/project/jsFileCompilationExtendsTag/amd/test.d.ts

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @extends {SomeBase}
3+
*/
4+
var MyClass = /** @class */ (function () {
5+
function MyClass() {
6+
}
7+
return MyClass;
8+
}());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ExtendsTag/tsconfig.json(3,5): error TS6082: Only 'amd' and 'system' modules are supported alongside --out.
2+
3+
4+
==== ExtendsTag/tsconfig.json (1 errors) ====
5+
{
6+
"compilerOptions": {
7+
"out": "test.js",
8+
~~~~~
9+
!!! error TS6082: Only 'amd' and 'system' modules are supported alongside --out.
10+
"allowJs": true
11+
},
12+
"files": [ "extends.js" ]
13+
}
14+
15+
==== ExtendsTag/extends.js (0 errors) ====
16+
/**
17+
* @extends {SomeBase}
18+
*/
19+
class MyClass {
20+
21+
}
22+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"scenario": "Check that @extends clauses do not cause code emit in JavaScript compilation",
3+
"projectRoot": "tests/cases/projects/jsFileCompilation",
4+
"baselineCheck": true,
5+
"declaration": false,
6+
"project": "ExtendsTag",
7+
"resolvedInputFiles": [
8+
"lib.es5.d.ts",
9+
"ExtendsTag/extends.js"
10+
],
11+
"emittedFiles": [
12+
"test.js"
13+
]
14+
}

tests/baselines/reference/project/jsFileCompilationExtendsTag/node/test.d.ts

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @extends {SomeBase}
3+
*/
4+
var MyClass = /** @class */ (function () {
5+
function MyClass() {
6+
}
7+
return MyClass;
8+
}());
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"scenario": "Check that @extends clauses do not cause code emit in JavaScript compilation",
3+
"projectRoot": "tests/cases/projects/jsFileCompilation",
4+
"baselineCheck": true,
5+
"declaration": false,
6+
"project": "ExtendsTag"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"out": "test.js",
4+
"allowJs": true
5+
},
6+
"files": [ "extends.js" ]
7+
}

0 commit comments

Comments
 (0)