Skip to content

Add a helper function getOrUpdateProperty to prevent unprotected ac… #10136

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
1 commit merged into from
Aug 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>) {
Expand Down Expand Up @@ -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") {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions tests/baselines/reference/exportToString.js
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;
7 changes: 7 additions & 0 deletions tests/baselines/reference/exportToString.symbols
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))

8 changes: 8 additions & 0 deletions tests/baselines/reference/exportToString.types
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

2 changes: 2 additions & 0 deletions tests/cases/compiler/exportToString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const toString = 0;
export { toString };