@@ -692,8 +692,7 @@ namespace ts {
692
692
return typeAcquisition ;
693
693
}
694
694
695
- /* @internal */
696
- export function getOptionNameMap ( ) : OptionNameMap {
695
+ function getOptionNameMap ( ) : OptionNameMap {
697
696
if ( optionNameMapCache ) {
698
697
return optionNameMapCache ;
699
698
}
@@ -746,7 +745,6 @@ namespace ts {
746
745
const options : CompilerOptions = { } ;
747
746
const fileNames : string [ ] = [ ] ;
748
747
const errors : Diagnostic [ ] = [ ] ;
749
- const { optionNameMap, shortOptionNames } = getOptionNameMap ( ) ;
750
748
751
749
parseStrings ( commandLine ) ;
752
750
return {
@@ -758,21 +756,13 @@ namespace ts {
758
756
function parseStrings ( args : string [ ] ) {
759
757
let i = 0 ;
760
758
while ( i < args . length ) {
761
- let s = args [ i ] ;
759
+ const s = args [ i ] ;
762
760
i ++ ;
763
761
if ( s . charCodeAt ( 0 ) === CharacterCodes . at ) {
764
762
parseResponseFile ( s . slice ( 1 ) ) ;
765
763
}
766
764
else if ( s . charCodeAt ( 0 ) === CharacterCodes . minus ) {
767
- s = s . slice ( s . charCodeAt ( 1 ) === CharacterCodes . minus ? 2 : 1 ) . toLowerCase ( ) ;
768
-
769
- // Try to translate short option names to their full equivalents.
770
- const short = shortOptionNames . get ( s ) ;
771
- if ( short !== undefined ) {
772
- s = short ;
773
- }
774
-
775
- const opt = optionNameMap . get ( s ) ;
765
+ const opt = getOptionFromName ( s . slice ( s . charCodeAt ( 1 ) === CharacterCodes . minus ? 2 : 1 ) , /*allowShort*/ true ) ;
776
766
if ( opt ) {
777
767
if ( opt . isTSConfigOnly ) {
778
768
errors . push ( createCompilerDiagnostic ( Diagnostics . Option_0_can_only_be_specified_in_tsconfig_json_file , opt . name ) ) ;
@@ -860,6 +850,19 @@ namespace ts {
860
850
}
861
851
}
862
852
853
+ function getOptionFromName ( optionName : string , allowShort = false ) : CommandLineOption | undefined {
854
+ optionName = optionName . toLowerCase ( ) ;
855
+ const { optionNameMap, shortOptionNames } = getOptionNameMap ( ) ;
856
+ // Try to translate short option names to their full equivalents.
857
+ if ( allowShort ) {
858
+ const short = shortOptionNames . get ( optionName ) ;
859
+ if ( short !== undefined ) {
860
+ optionName = short ;
861
+ }
862
+ }
863
+ return optionNameMap . get ( optionName ) ;
864
+ }
865
+
863
866
/**
864
867
* Read tsconfig.json file
865
868
* @param fileName The path to the config file
@@ -1705,4 +1708,42 @@ namespace ts {
1705
1708
function caseInsensitiveKeyMapper ( key : string ) {
1706
1709
return key . toLowerCase ( ) ;
1707
1710
}
1711
+
1712
+ /**
1713
+ * Produces a cleaned version of compiler options with personally identifiying info (aka, paths) removed.
1714
+ * Also converts enum values back to strings.
1715
+ */
1716
+ /* @internal */
1717
+ export function convertCompilerOptionsForTelemetry ( opts : ts . CompilerOptions ) : ts . CompilerOptions {
1718
+ const out : ts . CompilerOptions = { } ;
1719
+ for ( const key in opts ) if ( opts . hasOwnProperty ( key ) ) {
1720
+ const type = getOptionFromName ( key ) ;
1721
+ if ( type !== undefined ) { // Ignore unknown options
1722
+ out [ key ] = getOptionValueWithEmptyStrings ( opts [ key ] , type ) ;
1723
+ }
1724
+ }
1725
+ return out ;
1726
+ }
1727
+
1728
+ function getOptionValueWithEmptyStrings ( value : any , option : CommandLineOption ) : { } {
1729
+ switch ( option . type ) {
1730
+ case "object" : // "paths". Can't get any useful information from the value since we blank out strings, so just return "".
1731
+ return "" ;
1732
+ case "string" : // Could be any arbitrary string -- use empty string instead.
1733
+ return "" ;
1734
+ case "number" : // Allow numbers, but be sure to check it's actually a number.
1735
+ return typeof value === "number" ? value : "" ;
1736
+ case "boolean" :
1737
+ return typeof value === "boolean" ? value : "" ;
1738
+ case "list" :
1739
+ const elementType = ( option as CommandLineOptionOfListType ) . element ;
1740
+ return ts . isArray ( value ) ? value . map ( v => getOptionValueWithEmptyStrings ( v , elementType ) ) : "" ;
1741
+ default :
1742
+ return ts . forEachEntry ( option . type , ( optionEnumValue , optionStringValue ) => {
1743
+ if ( optionEnumValue === value ) {
1744
+ return optionStringValue ;
1745
+ }
1746
+ } ) ;
1747
+ }
1748
+ }
1708
1749
}
0 commit comments