mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge pull request #10115 from Microsoft/export_specifiers_map
Add a helper function `getOrUpdateProperty` to prevent unprotected access to Maps.
This commit is contained in:
@@ -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$))?)*";
|
||||
const singleAsteriskRegexFragmentOther = "[^/]*";
|
||||
|
||||
export function getRegularExpressionForWildcard(specs: string[], basePath: string, usage: "files" | "directories" | "exclude") {
|
||||
|
||||
@@ -6842,7 +6842,7 @@ const _super = (function (geti, seti) {
|
||||
// export { x, y }
|
||||
for (const specifier of (<ExportDeclaration>node).exportClause.elements) {
|
||||
const name = (specifier.propertyName || specifier.name).text;
|
||||
(exportSpecifiers[name] || (exportSpecifiers[name] = [])).push(specifier);
|
||||
getOrUpdateProperty(exportSpecifiers, name, () => []).push(specifier);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
//// [exportToString.ts]
|
||||
const toString = 0;
|
||||
export { toString };
|
||||
|
||||
|
||||
//// [exportToString.js]
|
||||
"use strict";
|
||||
var toString = 0;
|
||||
exports.toString = toString;
|
||||
@@ -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))
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
=== tests/cases/compiler/exportToString.ts ===
|
||||
const toString = 0;
|
||||
>toString : number
|
||||
>0 : number
|
||||
|
||||
export { toString };
|
||||
>toString : number
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
const toString = 0;
|
||||
export { toString };
|
||||
Reference in New Issue
Block a user