Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Merge pull request #31119 from andrewbranch/bug/31020
Emit grammar error on quoted constructors and class fields named “constructor”
- Loading branch information
Showing
13 changed files
with
259 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
tests/baselines/reference/propertyNamedConstructor.errors.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
tests/cases/conformance/classes/propertyMemberDeclarations/propertyNamedConstructor.ts(2,3): error TS18006: Classes may not have a field named 'constructor'. | ||
|
||
|
||
==== tests/cases/conformance/classes/propertyMemberDeclarations/propertyNamedConstructor.ts (1 errors) ==== | ||
class X1 { | ||
"constructor" = 3; // Error | ||
~~~~~~~~~~~~~ | ||
!!! error TS18006: Classes may not have a field named 'constructor'. | ||
} | ||
|
||
class X2 { | ||
["constructor"] = 3; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//// [propertyNamedConstructor.ts] | ||
class X1 { | ||
"constructor" = 3; // Error | ||
} | ||
|
||
class X2 { | ||
["constructor"] = 3; | ||
} | ||
|
||
|
||
//// [propertyNamedConstructor.js] | ||
var X1 = /** @class */ (function () { | ||
function X1() { | ||
this["constructor"] = 3; // Error | ||
} | ||
return X1; | ||
}()); | ||
var X2 = /** @class */ (function () { | ||
function X2() { | ||
this["constructor"] = 3; | ||
} | ||
return X2; | ||
}()); |
16 changes: 16 additions & 0 deletions
16
tests/baselines/reference/propertyNamedConstructor.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyNamedConstructor.ts === | ||
class X1 { | ||
>X1 : Symbol(X1, Decl(propertyNamedConstructor.ts, 0, 0)) | ||
|
||
"constructor" = 3; // Error | ||
>"constructor" : Symbol(X1["constructor"], Decl(propertyNamedConstructor.ts, 0, 10)) | ||
} | ||
|
||
class X2 { | ||
>X2 : Symbol(X2, Decl(propertyNamedConstructor.ts, 2, 1)) | ||
|
||
["constructor"] = 3; | ||
>["constructor"] : Symbol(X2["constructor"], Decl(propertyNamedConstructor.ts, 4, 10)) | ||
>"constructor" : Symbol(X2["constructor"], Decl(propertyNamedConstructor.ts, 4, 10)) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
=== tests/cases/conformance/classes/propertyMemberDeclarations/propertyNamedConstructor.ts === | ||
class X1 { | ||
>X1 : X1 | ||
|
||
"constructor" = 3; // Error | ||
>"constructor" : number | ||
>3 : 3 | ||
} | ||
|
||
class X2 { | ||
>X2 : X2 | ||
|
||
["constructor"] = 3; | ||
>["constructor"] : number | ||
>"constructor" : "constructor" | ||
>3 : 3 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts(2,5): error TS18005: Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '["constructor"]()' to write a method. | ||
tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts(6,5): error TS18005: Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '["constructor"]()' to write a method. | ||
tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts(14,5): error TS18005: Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '["constructor"]()' to write a method. | ||
|
||
|
||
==== tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts (3 errors) ==== | ||
class C { | ||
"constructor"() {} // Error in 3.5 | ||
~~~~~~~~~~~~~ | ||
!!! error TS18005: Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '["constructor"]()' to write a method. | ||
} | ||
|
||
class D { | ||
'constructor'() {} // Error in 3.5 | ||
~~~~~~~~~~~~~ | ||
!!! error TS18005: Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '["constructor"]()' to write a method. | ||
} | ||
|
||
class E { | ||
['constructor']() {} | ||
} | ||
|
||
new class { | ||
"constructor"() {} // Error in 3.5 | ||
~~~~~~~~~~~~~ | ||
!!! error TS18005: Quoted constructors have previously been interpreted as methods, which is incorrect. In TypeScript 3.6, they will be correctly parsed as constructors. In the meantime, consider using 'constructor()' to write a constructor, or '["constructor"]()' to write a method. | ||
}; | ||
|
||
var o = { "constructor"() {} }; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//// [quotedConstructors.ts] | ||
class C { | ||
"constructor"() {} // Error in 3.5 | ||
} | ||
|
||
class D { | ||
'constructor'() {} // Error in 3.5 | ||
} | ||
|
||
class E { | ||
['constructor']() {} | ||
} | ||
|
||
new class { | ||
"constructor"() {} // Error in 3.5 | ||
}; | ||
|
||
var o = { "constructor"() {} }; | ||
|
||
|
||
//// [quotedConstructors.js] | ||
var C = /** @class */ (function () { | ||
function C() { | ||
} | ||
C.prototype["constructor"] = function () { }; // Error in 3.5 | ||
return C; | ||
}()); | ||
var D = /** @class */ (function () { | ||
function D() { | ||
} | ||
D.prototype['constructor'] = function () { }; // Error in 3.5 | ||
return D; | ||
}()); | ||
var E = /** @class */ (function () { | ||
function E() { | ||
} | ||
E.prototype['constructor'] = function () { }; | ||
return E; | ||
}()); | ||
new /** @class */ (function () { | ||
function class_1() { | ||
} | ||
class_1.prototype["constructor"] = function () { }; // Error in 3.5 | ||
return class_1; | ||
}()); | ||
var o = { "constructor": function () { } }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
=== tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts === | ||
class C { | ||
>C : Symbol(C, Decl(quotedConstructors.ts, 0, 0)) | ||
|
||
"constructor"() {} // Error in 3.5 | ||
>"constructor" : Symbol(C["constructor"], Decl(quotedConstructors.ts, 0, 9)) | ||
} | ||
|
||
class D { | ||
>D : Symbol(D, Decl(quotedConstructors.ts, 2, 1)) | ||
|
||
'constructor'() {} // Error in 3.5 | ||
>'constructor' : Symbol(D['constructor'], Decl(quotedConstructors.ts, 4, 9)) | ||
} | ||
|
||
class E { | ||
>E : Symbol(E, Decl(quotedConstructors.ts, 6, 1)) | ||
|
||
['constructor']() {} | ||
>['constructor'] : Symbol(E['constructor'], Decl(quotedConstructors.ts, 8, 9)) | ||
>'constructor' : Symbol(E['constructor'], Decl(quotedConstructors.ts, 8, 9)) | ||
} | ||
|
||
new class { | ||
"constructor"() {} // Error in 3.5 | ||
>"constructor" : Symbol((Anonymous class)["constructor"], Decl(quotedConstructors.ts, 12, 11)) | ||
|
||
}; | ||
|
||
var o = { "constructor"() {} }; | ||
>o : Symbol(o, Decl(quotedConstructors.ts, 16, 3)) | ||
>"constructor" : Symbol("constructor", Decl(quotedConstructors.ts, 16, 9)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
=== tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts === | ||
class C { | ||
>C : C | ||
|
||
"constructor"() {} // Error in 3.5 | ||
>"constructor" : () => void | ||
} | ||
|
||
class D { | ||
>D : D | ||
|
||
'constructor'() {} // Error in 3.5 | ||
>'constructor' : () => void | ||
} | ||
|
||
class E { | ||
>E : E | ||
|
||
['constructor']() {} | ||
>['constructor'] : () => void | ||
>'constructor' : "constructor" | ||
} | ||
|
||
new class { | ||
>new class { "constructor"() {} // Error in 3.5} : (Anonymous class) | ||
>class { "constructor"() {} // Error in 3.5} : typeof (Anonymous class) | ||
|
||
"constructor"() {} // Error in 3.5 | ||
>"constructor" : () => void | ||
|
||
}; | ||
|
||
var o = { "constructor"() {} }; | ||
>o : { "constructor"(): void; } | ||
>{ "constructor"() {} } : { "constructor"(): void; } | ||
>"constructor" : () => void | ||
|
17 changes: 17 additions & 0 deletions
17
tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class C { | ||
"constructor"() {} // Error in 3.5 | ||
} | ||
|
||
class D { | ||
'constructor'() {} // Error in 3.5 | ||
} | ||
|
||
class E { | ||
['constructor']() {} | ||
} | ||
|
||
new class { | ||
"constructor"() {} // Error in 3.5 | ||
}; | ||
|
||
var o = { "constructor"() {} }; |
7 changes: 7 additions & 0 deletions
7
tests/cases/conformance/classes/propertyMemberDeclarations/propertyNamedConstructor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class X1 { | ||
"constructor" = 3; // Error | ||
} | ||
|
||
class X2 { | ||
["constructor"] = 3; | ||
} |