-
Notifications
You must be signed in to change notification settings - Fork 12.9k
fix(54760): Report error for 'declare type' followed by newline #54761
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2645eb0
fix(54760): Report error for 'declare type' followed by newline
strager 831fad4
Enable type checking in test and add more documentation and assertions
strager 894120d
Update test baselines
strager 72502bc
Remove unnecessary code block
strager 63af658
Add missing test baseline files
strager f2190c4
Use different, specific types for helper variables
strager File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
26 changes: 26 additions & 0 deletions
26
tests/baselines/reference/typeAliasDeclareKeywordNewlines.errors.txt
This file contains hidden or 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,26 @@ | ||
typeAliasDeclareKeywordNewlines.ts(5,1): error TS1142: Line break not permitted here. | ||
|
||
|
||
==== typeAliasDeclareKeywordNewlines.ts (1 errors) ==== | ||
var declare: string, type: number; | ||
|
||
// The following is invalid but should declare a type alias named 'T1': | ||
declare type /*unexpected newline*/ | ||
T1 = null; | ||
~~ | ||
!!! error TS1142: Line break not permitted here. | ||
const t1: T1 = null; // Assert that T1 is the null type. | ||
|
||
let T: null; | ||
// The following should use a variable named 'declare', use a variable named | ||
// 'type', and assign to a variable named 'T'. | ||
declare /*ASI*/ | ||
type /*ASI*/ | ||
T = null; | ||
|
||
// The following should use a variable named 'declare' and declare a type alias | ||
// named 'T2': | ||
declare /*ASI*/ | ||
type T2 = null; | ||
const t2: T2 = null; // Assert that T2 is the null type. | ||
|
37 changes: 37 additions & 0 deletions
37
tests/baselines/reference/typeAliasDeclareKeywordNewlines.js
This file contains hidden or 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/compiler/typeAliasDeclareKeywordNewlines.ts] //// | ||
|
||
//// [typeAliasDeclareKeywordNewlines.ts] | ||
var declare: string, type: number; | ||
|
||
// The following is invalid but should declare a type alias named 'T1': | ||
declare type /*unexpected newline*/ | ||
T1 = null; | ||
const t1: T1 = null; // Assert that T1 is the null type. | ||
|
||
let T: null; | ||
// The following should use a variable named 'declare', use a variable named | ||
// 'type', and assign to a variable named 'T'. | ||
declare /*ASI*/ | ||
type /*ASI*/ | ||
T = null; | ||
|
||
// The following should use a variable named 'declare' and declare a type alias | ||
// named 'T2': | ||
declare /*ASI*/ | ||
type T2 = null; | ||
const t2: T2 = null; // Assert that T2 is the null type. | ||
|
||
|
||
//// [typeAliasDeclareKeywordNewlines.js] | ||
var declare, type; | ||
var t1 = null; // Assert that T1 is the null type. | ||
var T; | ||
// The following should use a variable named 'declare', use a variable named | ||
// 'type', and assign to a variable named 'T'. | ||
declare; /*ASI*/ | ||
type; /*ASI*/ | ||
T = null; | ||
// The following should use a variable named 'declare' and declare a type alias | ||
// named 'T2': | ||
declare; /*ASI*/ | ||
var t2 = null; // Assert that T2 is the null type. |
42 changes: 42 additions & 0 deletions
42
tests/baselines/reference/typeAliasDeclareKeywordNewlines.symbols
This file contains hidden or 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,42 @@ | ||
//// [tests/cases/compiler/typeAliasDeclareKeywordNewlines.ts] //// | ||
|
||
=== typeAliasDeclareKeywordNewlines.ts === | ||
var declare: string, type: number; | ||
>declare : Symbol(declare, Decl(typeAliasDeclareKeywordNewlines.ts, 0, 3)) | ||
>type : Symbol(type, Decl(typeAliasDeclareKeywordNewlines.ts, 0, 20)) | ||
|
||
// The following is invalid but should declare a type alias named 'T1': | ||
declare type /*unexpected newline*/ | ||
T1 = null; | ||
>T1 : Symbol(T1, Decl(typeAliasDeclareKeywordNewlines.ts, 0, 34)) | ||
|
||
const t1: T1 = null; // Assert that T1 is the null type. | ||
>t1 : Symbol(t1, Decl(typeAliasDeclareKeywordNewlines.ts, 5, 5)) | ||
>T1 : Symbol(T1, Decl(typeAliasDeclareKeywordNewlines.ts, 0, 34)) | ||
|
||
let T: null; | ||
>T : Symbol(T, Decl(typeAliasDeclareKeywordNewlines.ts, 7, 3)) | ||
|
||
// The following should use a variable named 'declare', use a variable named | ||
// 'type', and assign to a variable named 'T'. | ||
declare /*ASI*/ | ||
>declare : Symbol(declare, Decl(typeAliasDeclareKeywordNewlines.ts, 0, 3)) | ||
|
||
type /*ASI*/ | ||
>type : Symbol(type, Decl(typeAliasDeclareKeywordNewlines.ts, 0, 20)) | ||
|
||
T = null; | ||
>T : Symbol(T, Decl(typeAliasDeclareKeywordNewlines.ts, 7, 3)) | ||
|
||
// The following should use a variable named 'declare' and declare a type alias | ||
// named 'T2': | ||
declare /*ASI*/ | ||
>declare : Symbol(declare, Decl(typeAliasDeclareKeywordNewlines.ts, 0, 3)) | ||
|
||
type T2 = null; | ||
>T2 : Symbol(T2, Decl(typeAliasDeclareKeywordNewlines.ts, 16, 7)) | ||
|
||
const t2: T2 = null; // Assert that T2 is the null type. | ||
>t2 : Symbol(t2, Decl(typeAliasDeclareKeywordNewlines.ts, 18, 5)) | ||
>T2 : Symbol(T2, Decl(typeAliasDeclareKeywordNewlines.ts, 16, 7)) | ||
|
41 changes: 41 additions & 0 deletions
41
tests/baselines/reference/typeAliasDeclareKeywordNewlines.types
This file contains hidden or 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,41 @@ | ||
//// [tests/cases/compiler/typeAliasDeclareKeywordNewlines.ts] //// | ||
|
||
=== typeAliasDeclareKeywordNewlines.ts === | ||
var declare: string, type: number; | ||
>declare : string | ||
>type : number | ||
|
||
// The following is invalid but should declare a type alias named 'T1': | ||
declare type /*unexpected newline*/ | ||
T1 = null; | ||
>T1 : null | ||
|
||
const t1: T1 = null; // Assert that T1 is the null type. | ||
>t1 : null | ||
|
||
let T: null; | ||
>T : null | ||
|
||
// The following should use a variable named 'declare', use a variable named | ||
// 'type', and assign to a variable named 'T'. | ||
declare /*ASI*/ | ||
>declare : string | ||
|
||
type /*ASI*/ | ||
>type : number | ||
|
||
T = null; | ||
>T = null : null | ||
>T : null | ||
|
||
// The following should use a variable named 'declare' and declare a type alias | ||
// named 'T2': | ||
declare /*ASI*/ | ||
>declare : string | ||
|
||
type T2 = null; | ||
>T2 : null | ||
|
||
const t2: T2 = null; // Assert that T2 is the null type. | ||
>t2 : null | ||
|
This file contains hidden or 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,19 @@ | ||
var declare: string, type: number; | ||
|
||
// The following is invalid but should declare a type alias named 'T1': | ||
declare type /*unexpected newline*/ | ||
T1 = null; | ||
const t1: T1 = null; // Assert that T1 is the null type. | ||
|
||
let T: null; | ||
// The following should use a variable named 'declare', use a variable named | ||
// 'type', and assign to a variable named 'T'. | ||
declare /*ASI*/ | ||
type /*ASI*/ | ||
T = null; | ||
|
||
// The following should use a variable named 'declare' and declare a type alias | ||
// named 'T2': | ||
declare /*ASI*/ | ||
type T2 = null; | ||
const t2: T2 = null; // Assert that T2 is the null type. |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Question for reviewers: I don't like the placement of the diagnostic, but I don't know TypeScript diagnostic conventions. Is here fine or should it point to the
type
keyword on the previous line?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.
You can give a specialized diagnostic, but I think this is actually fine as-is.