Skip to content

Commit d333378

Browse files
committed
Merge branch 'release-2.3' of https://github.com/Microsoft/TypeScript into release-2.3
2 parents fc4d109 + f80ca90 commit d333378

File tree

11 files changed

+494
-38
lines changed

11 files changed

+494
-38
lines changed

Jakefile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ var harnessSources = harnessCoreSources.concat([
129129
"initializeTSConfig.ts",
130130
"printer.ts",
131131
"textChanges.ts",
132+
"telemetry.ts",
132133
"transform.ts",
133134
"customTransforms.ts",
134135
].map(function (f) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
"travis-fold": "latest",
7777
"ts-node": "latest",
7878
"tslint": "next",
79-
"typescript": "next"
79+
"typescript": "^2.3.3"
8080
},
8181
"scripts": {
8282
"pretest": "jake tests",

src/compiler/commandLineParser.ts

Lines changed: 55 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -691,8 +691,7 @@ namespace ts {
691691
return typeAcquisition;
692692
}
693693

694-
/* @internal */
695-
export function getOptionNameMap(): OptionNameMap {
694+
function getOptionNameMap(): OptionNameMap {
696695
if (optionNameMapCache) {
697696
return optionNameMapCache;
698697
}
@@ -745,7 +744,6 @@ namespace ts {
745744
const options: CompilerOptions = {};
746745
const fileNames: string[] = [];
747746
const errors: Diagnostic[] = [];
748-
const { optionNameMap, shortOptionNames } = getOptionNameMap();
749747

750748
parseStrings(commandLine);
751749
return {
@@ -757,21 +755,13 @@ namespace ts {
757755
function parseStrings(args: string[]) {
758756
let i = 0;
759757
while (i < args.length) {
760-
let s = args[i];
758+
const s = args[i];
761759
i++;
762760
if (s.charCodeAt(0) === CharacterCodes.at) {
763761
parseResponseFile(s.slice(1));
764762
}
765763
else if (s.charCodeAt(0) === CharacterCodes.minus) {
766-
s = s.slice(s.charCodeAt(1) === CharacterCodes.minus ? 2 : 1).toLowerCase();
767-
768-
// Try to translate short option names to their full equivalents.
769-
const short = shortOptionNames.get(s);
770-
if (short !== undefined) {
771-
s = short;
772-
}
773-
774-
const opt = optionNameMap.get(s);
764+
const opt = getOptionFromName(s.slice(s.charCodeAt(1) === CharacterCodes.minus ? 2 : 1), /*allowShort*/ true);
775765
if (opt) {
776766
if (opt.isTSConfigOnly) {
777767
errors.push(createCompilerDiagnostic(Diagnostics.Option_0_can_only_be_specified_in_tsconfig_json_file, opt.name));
@@ -859,6 +849,19 @@ namespace ts {
859849
}
860850
}
861851

852+
function getOptionFromName(optionName: string, allowShort = false): CommandLineOption | undefined {
853+
optionName = optionName.toLowerCase();
854+
const { optionNameMap, shortOptionNames } = getOptionNameMap();
855+
// Try to translate short option names to their full equivalents.
856+
if (allowShort) {
857+
const short = shortOptionNames.get(optionName);
858+
if (short !== undefined) {
859+
optionName = short;
860+
}
861+
}
862+
return optionNameMap.get(optionName);
863+
}
864+
862865
/**
863866
* Read tsconfig.json file
864867
* @param fileName The path to the config file
@@ -1661,4 +1664,42 @@ namespace ts {
16611664
function caseInsensitiveKeyMapper(key: string) {
16621665
return key.toLowerCase();
16631666
}
1664-
}
1667+
1668+
/**
1669+
* Produces a cleaned version of compiler options with personally identifiying info (aka, paths) removed.
1670+
* Also converts enum values back to strings.
1671+
*/
1672+
/* @internal */
1673+
export function convertCompilerOptionsForTelemetry(opts: ts.CompilerOptions): ts.CompilerOptions {
1674+
const out: ts.CompilerOptions = {};
1675+
for (const key in opts) if (opts.hasOwnProperty(key)) {
1676+
const type = getOptionFromName(key);
1677+
if (type !== undefined) { // Ignore unknown options
1678+
out[key] = getOptionValueWithEmptyStrings(opts[key], type);
1679+
}
1680+
}
1681+
return out;
1682+
}
1683+
1684+
function getOptionValueWithEmptyStrings(value: any, option: CommandLineOption): {} {
1685+
switch (option.type) {
1686+
case "object": // "paths". Can't get any useful information from the value since we blank out strings, so just return "".
1687+
return "";
1688+
case "string": // Could be any arbitrary string -- use empty string instead.
1689+
return "";
1690+
case "number": // Allow numbers, but be sure to check it's actually a number.
1691+
return typeof value === "number" ? value : "";
1692+
case "boolean":
1693+
return typeof value === "boolean" ? value : "";
1694+
case "list":
1695+
const elementType = (option as CommandLineOptionOfListType).element;
1696+
return ts.isArray(value) ? value.map(v => getOptionValueWithEmptyStrings(v, elementType)) : "";
1697+
default:
1698+
return ts.forEachEntry(option.type, (optionEnumValue, optionStringValue) => {
1699+
if (optionEnumValue === value) {
1700+
return optionStringValue;
1701+
}
1702+
});
1703+
}
1704+
}
1705+
}

src/harness/tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
"./unittests/printer.ts",
128128
"./unittests/transform.ts",
129129
"./unittests/customTransforms.ts",
130-
"./unittests/textChanges.ts"
130+
"./unittests/textChanges.ts",
131+
"./unittests/telemetry.ts"
131132
]
132133
}

0 commit comments

Comments
 (0)