New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Emit grammar error on quoted constructors and class fields named “constructor” #31119
Merged
Merged
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
72f30a8
Add test for quoted constructors
andrewbranch c5e6913
Add grammar error on quoted constructors for TS 3.5
andrewbranch b1b0a82
Add baselines
andrewbranch 9f601ff
Change error code
andrewbranch e81fa21
Emit error on class fields named "constructor"
andrewbranch 0eb2862
Update error code in baseline
andrewbranch 67a9029
Update existing baseline
andrewbranch File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
tests/cases/conformance/classes/constructorDeclarations/quotedConstructors.ts(2,5): error TS96000: 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 TS96000: 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 TS96000: 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 TS96000: 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 TS96000: 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 TS96000: 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"() {} }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use a normal code here; it's fine to introduce a gap in the sequence later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was confused about why
18004
was way down here. Now I see that's the latest of an earlier sequence.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to 18005