-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add a helper function getOrUpdateProperty
to prevent unprotected access to Maps.
#10115
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,8 +323,12 @@ namespace ts { | |
return keys; | ||
} | ||
|
||
export function getProperty<T>(map: Map<T>, key: string): T { | ||
return hasOwnProperty.call(map, key) ? map[key] : undefined; | ||
export function getProperty<T>(map: Map<T>, key: string): T | undefined { | ||
return hasProperty(map, key) ? map[key] : undefined; | ||
} | ||
|
||
export function getOrUpdateProperty<T>(map: Map<T>, key: string, makeValue: () => T): T { | ||
return hasProperty(map, key) ? map[key] : map[key] = makeValue(); | ||
} | ||
|
||
export function isEmpty<T>(map: Map<T>) { | ||
|
@@ -941,7 +945,7 @@ namespace ts { | |
* [^./] # matches everything up to the first . character (excluding directory seperators) | ||
* (\\.(?!min\\.js$))? # matches . characters but not if they are part of the .min.js file extension | ||
*/ | ||
const singleAsteriskRegexFragmentFiles = "([^./]|(\\.(?!min\\.js$))?)*"; | ||
const singleAsteriskRegexFragmentFiles = "([^./]|(\\.(?!min\\.js$))?)*"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what changes on this line? Is it the line ending? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's line ending. This line ends with just an Which is strange, because we have a lint rule covering this which is not triggering. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it only detect extra line endings? It just fired for me when I had an extra. |
||
const singleAsteriskRegexFragmentOther = "[^/]*"; | ||
|
||
export function getRegularExpressionForWildcard(specs: string[], basePath: string, usage: "files" | "directories" | "exclude") { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//// [exportToString.ts] | ||
const toString = 0; | ||
export { toString }; | ||
|
||
|
||
//// [exportToString.js] | ||
"use strict"; | ||
var toString = 0; | ||
exports.toString = toString; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
=== tests/cases/compiler/exportToString.ts === | ||
const toString = 0; | ||
>toString : Symbol(toString, Decl(exportToString.ts, 0, 5)) | ||
|
||
export { toString }; | ||
>toString : Symbol(toString, Decl(exportToString.ts, 1, 8)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
=== tests/cases/compiler/exportToString.ts === | ||
const toString = 0; | ||
>toString : number | ||
>0 : number | ||
|
||
export { toString }; | ||
>toString : number | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
const toString = 0; | ||
export { toString }; |
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.
are there any other places that should use this function? I think we use objects as maps quite a lot.
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.
There are a lot of places that use code like this -- just search for
] ||
-- but they seem to be using numeric IDs (so are safe from default properties) or are safe for other reasons.I'm also currently looking into using Maps as maps.