-
Notifications
You must be signed in to change notification settings - Fork 1.8k
TS: fix a case of infinite type expansion #1059
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
semmle-qlci
merged 3 commits into
github:rc/1.20
from
asger-semmle:ts-infinite-expansion
Mar 11, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
2 changes: 0 additions & 2 deletions
2
javascript/ql/test/library-tests/TypeScript/ArrayTypes/ArrayTypes.expected
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
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
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
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
2 changes: 0 additions & 2 deletions
2
javascript/ql/test/library-tests/TypeScript/ExternalTypes/GlobalQualifiedNames.expected
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 |
---|---|---|
@@ -1,10 +1,8 @@ | ||
| Function | Function | | ||
| Intl.CollatorOptions | CollatorOptions | | ||
| Intl.NumberFormatOptions | NumberFormatOptions | | ||
| LegacyGlobals.LegacySubclass | LegacySubclass | | ||
| Modern.ModernClass | ModernClass | | ||
| ModernGlobals.ModernSubclass | ModernSubclass | | ||
| Object | Object | | ||
| RegExp | RegExp | | ||
| RegExpMatchArray | RegExpMatchArray | | ||
| __Legacy.LegacyClass | LegacyClass | |
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
8 changes: 8 additions & 0 deletions
8
javascript/ql/test/library-tests/TypeScript/InfiniteTypes/recursiveMappedType.ts
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,8 @@ | ||
interface X { | ||
a: RecursiveMappedType<this> & X; | ||
b: boolean; | ||
} | ||
|
||
type RecursiveMappedType<V> = { | ||
[P in keyof V]?: X & RecursiveMappedType<V[P]> | ||
} |
2 changes: 2 additions & 0 deletions
2
javascript/ql/test/library-tests/TypeScript/InfiniteTypes/test.expected
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,2 @@ | ||
| recursiveMappedType.ts:2:5:2:5 | a | RecursiveMappedType<this> & X | | ||
| recursiveMappedType.ts:3:5:3:5 | b | boolean | |
4 changes: 4 additions & 0 deletions
4
javascript/ql/test/library-tests/TypeScript/InfiniteTypes/test.ql
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,4 @@ | ||
import javascript | ||
|
||
from Expr e | ||
select e, e.getType() |
3 changes: 3 additions & 0 deletions
3
javascript/ql/test/library-tests/TypeScript/InfiniteTypes/tsconfig.json
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,3 @@ | ||
{ | ||
"include": ["."] | ||
} |
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.
Very approximate indeed.
Maybe we should look into special casing on some common cases 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.
It shouldn't be that bad. The structure of a type is still extracted, this just determines whether its properties are. So for a type like
Buffer | string
, we can still tell it's aBuffer | string
, but we won't necessarily compute the members of the union itself (i.e. the intersection of members onBuffer
andstring
).Also, members are always computed for types directly referenced from the AST, for example, if some expression is inferred to have the type
A & B
, that type is fully extracted, members and all, butA
andB
themselves might be shallow.(edited for a better example)