Add a helper function getOrUpdateProperty to prevent unprotected access to Maps.

This commit is contained in:
Andy Hanson
2016-08-04 06:04:41 -07:00
parent 126c1eeb59
commit 0aaec56b8f
7 changed files with 34 additions and 3 deletions

View File

@@ -20,6 +20,7 @@ declare module "gulp-typescript" {
}
import * as insert from "gulp-insert";
import * as sourcemaps from "gulp-sourcemaps";
import Q = require("q");
declare global {
// This is silly. We include Q because orchestrator (a part of gulp) depends on it, but its not included.
// `del` further depends on `Promise` (and is also not included), so we just, patch the global scope's Promise to Q's

View File

@@ -319,7 +319,11 @@ namespace ts {
}
export function getProperty<T>(map: Map<T>, key: string): T {
return hasOwnProperty.call(map, key) ? map[key] : 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>) {
@@ -928,7 +932,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") {

View File

@@ -6841,7 +6841,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;

View File

@@ -0,0 +1,9 @@
//// [exportToString.ts]
const toString = 0;
export { toString };
//// [exportToString.js]
"use strict";
var toString = 0;
exports.toString = toString;

View File

@@ -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))

View File

@@ -0,0 +1,8 @@
=== tests/cases/compiler/exportToString.ts ===
const toString = 0;
>toString : number
>0 : number
export { toString };
>toString : number

View File

@@ -0,0 +1,2 @@
const toString = 0;
export { toString };