Skip to content

Commit d173bca

Browse files
author
Andy
authored
Merge pull request #10136 from Microsoft/release-2.0_export_specifiers_map
Add a helper function `getOrUpdateProperty` to prevent unprotected ac…
2 parents 126c1ee + 0aaec56 commit d173bca

File tree

7 files changed

+34
-3
lines changed

7 files changed

+34
-3
lines changed

Gulpfile.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ declare module "gulp-typescript" {
2020
}
2121
import * as insert from "gulp-insert";
2222
import * as sourcemaps from "gulp-sourcemaps";
23+
import Q = require("q");
2324
declare global {
2425
// This is silly. We include Q because orchestrator (a part of gulp) depends on it, but its not included.
2526
// `del` further depends on `Promise` (and is also not included), so we just, patch the global scope's Promise to Q's

src/compiler/core.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,11 @@ namespace ts {
319319
}
320320

321321
export function getProperty<T>(map: Map<T>, key: string): T {
322-
return hasOwnProperty.call(map, key) ? map[key] : undefined;
322+
return hasProperty(map, key) ? map[key] : undefined;
323+
}
324+
325+
export function getOrUpdateProperty<T>(map: Map<T>, key: string, makeValue: () => T): T {
326+
return hasProperty(map, key) ? map[key] : map[key] = makeValue();
323327
}
324328

325329
export function isEmpty<T>(map: Map<T>) {
@@ -928,7 +932,7 @@ namespace ts {
928932
* [^./] # matches everything up to the first . character (excluding directory seperators)
929933
* (\\.(?!min\\.js$))? # matches . characters but not if they are part of the .min.js file extension
930934
*/
931-
const singleAsteriskRegexFragmentFiles = "([^./]|(\\.(?!min\\.js$))?)*";
935+
const singleAsteriskRegexFragmentFiles = "([^./]|(\\.(?!min\\.js$))?)*";
932936
const singleAsteriskRegexFragmentOther = "[^/]*";
933937

934938
export function getRegularExpressionForWildcard(specs: string[], basePath: string, usage: "files" | "directories" | "exclude") {

src/compiler/emitter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6841,7 +6841,7 @@ const _super = (function (geti, seti) {
68416841
// export { x, y }
68426842
for (const specifier of (<ExportDeclaration>node).exportClause.elements) {
68436843
const name = (specifier.propertyName || specifier.name).text;
6844-
(exportSpecifiers[name] || (exportSpecifiers[name] = [])).push(specifier);
6844+
getOrUpdateProperty(exportSpecifiers, name, () => []).push(specifier);
68456845
}
68466846
}
68476847
break;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//// [exportToString.ts]
2+
const toString = 0;
3+
export { toString };
4+
5+
6+
//// [exportToString.js]
7+
"use strict";
8+
var toString = 0;
9+
exports.toString = toString;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/exportToString.ts ===
2+
const toString = 0;
3+
>toString : Symbol(toString, Decl(exportToString.ts, 0, 5))
4+
5+
export { toString };
6+
>toString : Symbol(toString, Decl(exportToString.ts, 1, 8))
7+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/compiler/exportToString.ts ===
2+
const toString = 0;
3+
>toString : number
4+
>0 : number
5+
6+
export { toString };
7+
>toString : number
8+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const toString = 0;
2+
export { toString };

0 commit comments

Comments
 (0)