@@ -29,13 +29,13 @@ module FourSlash {
2929 fileName : string ;
3030 version : number ;
3131 // File-specific options (name/value pairs)
32- fileOptions : { [ index : string ] : string ; } ;
32+ fileOptions : Harness . TestCaseParser . CompilerSettings ;
3333 }
3434
3535 // Represents a set of parsed source files and options
3636 export interface FourSlashData {
3737 // Global options (name/value pairs)
38- globalOptions : { [ index : string ] : string ; } ;
38+ globalOptions : Harness . TestCaseParser . CompilerSettings ;
3939
4040 files : FourSlashFile [ ] ;
4141
@@ -117,89 +117,17 @@ module FourSlash {
117117 // Add cases into convertGlobalOptionsToCompilationsSettings function for the compiler to acknowledge such option from meta data
118118 let metadataOptionNames = {
119119 baselineFile : "BaselineFile" ,
120- declaration : "declaration" ,
121120 emitThisFile : "emitThisFile" , // This flag is used for testing getEmitOutput feature. It allows test-cases to indicate what file to be output in multiple files project
122121 fileName : "Filename" ,
123- mapRoot : "mapRoot" ,
124- module : "module" ,
125- out : "out" ,
126- outFile : "outFile" ,
127- outDir : "outDir" ,
128- sourceMap : "sourceMap" ,
129- sourceRoot : "sourceRoot" ,
130- allowNonTsExtensions : "allowNonTsExtensions" ,
131122 resolveReference : "ResolveReference" , // This flag is used to specify entry file for resolve file references. The flag is only allow once per test file
132- jsx : "jsx" ,
133123 } ;
134124
135125 // List of allowed metadata names
136126 let fileMetadataNames = [ metadataOptionNames . fileName , metadataOptionNames . emitThisFile , metadataOptionNames . resolveReference ] ;
137- let globalMetadataNames = [ metadataOptionNames . allowNonTsExtensions , metadataOptionNames . baselineFile , metadataOptionNames . declaration ,
138- metadataOptionNames . mapRoot , metadataOptionNames . module , metadataOptionNames . out , metadataOptionNames . outFile ,
139- metadataOptionNames . outDir , metadataOptionNames . sourceMap , metadataOptionNames . sourceRoot , metadataOptionNames . jsx ] ;
140127
141- function convertGlobalOptionsToCompilerOptions ( globalOptions : { [ idx : string ] : string } ) : ts . CompilerOptions {
128+ function convertGlobalOptionsToCompilerOptions ( globalOptions : Harness . TestCaseParser . CompilerSettings ) : ts . CompilerOptions {
142129 let settings : ts . CompilerOptions = { target : ts . ScriptTarget . ES5 } ;
143- // Convert all property in globalOptions into ts.CompilationSettings
144- for ( let prop in globalOptions ) {
145- if ( globalOptions . hasOwnProperty ( prop ) ) {
146- switch ( prop ) {
147- case metadataOptionNames . allowNonTsExtensions :
148- settings . allowNonTsExtensions = globalOptions [ prop ] === "true" ;
149- break ;
150- case metadataOptionNames . declaration :
151- settings . declaration = globalOptions [ prop ] === "true" ;
152- break ;
153- case metadataOptionNames . mapRoot :
154- settings . mapRoot = globalOptions [ prop ] ;
155- break ;
156- case metadataOptionNames . module :
157- // create appropriate external module target for CompilationSettings
158- switch ( globalOptions [ prop ] ) {
159- case "AMD" :
160- settings . module = ts . ModuleKind . AMD ;
161- break ;
162- case "CommonJS" :
163- settings . module = ts . ModuleKind . CommonJS ;
164- break ;
165- default :
166- ts . Debug . assert ( globalOptions [ prop ] === undefined || globalOptions [ prop ] === "None" ) ;
167- settings . module = ts . ModuleKind . None ;
168- break ;
169- }
170- break ;
171- case metadataOptionNames . out :
172- settings . out = globalOptions [ prop ] ;
173- break ;
174- case metadataOptionNames . outFile :
175- settings . outFile = globalOptions [ prop ] ;
176- break ;
177- case metadataOptionNames . outDir :
178- settings . outDir = globalOptions [ prop ] ;
179- break ;
180- case metadataOptionNames . sourceMap :
181- settings . sourceMap = globalOptions [ prop ] === "true" ;
182- break ;
183- case metadataOptionNames . sourceRoot :
184- settings . sourceRoot = globalOptions [ prop ] ;
185- break ;
186- case metadataOptionNames . jsx :
187- switch ( globalOptions [ prop ] . toLowerCase ( ) ) {
188- case "react" :
189- settings . jsx = ts . JsxEmit . React ;
190- break ;
191- case "preserve" :
192- settings . jsx = ts . JsxEmit . Preserve ;
193- break ;
194- default :
195- ts . Debug . assert ( globalOptions [ prop ] === undefined || globalOptions [ prop ] === "None" ) ;
196- settings . jsx = ts . JsxEmit . None ;
197- break ;
198- }
199- break ;
200- }
201- }
202- }
130+ Harness . Compiler . setCompilerOptionsFromHarnessSetting ( globalOptions , settings ) ;
203131 return settings ;
204132 }
205133
@@ -2514,12 +2442,16 @@ module FourSlash {
25142442 // Comment line, check for global/file @options and record them
25152443 let match = optionRegex . exec ( line . substr ( 2 ) ) ;
25162444 if ( match ) {
2517- let globalMetadataNamesIndex = globalMetadataNames . indexOf ( match [ 1 ] ) ;
25182445 let fileMetadataNamesIndex = fileMetadataNames . indexOf ( match [ 1 ] ) ;
2519- if ( globalMetadataNamesIndex === - 1 ) {
2520- if ( fileMetadataNamesIndex === - 1 ) {
2521- throw new Error ( `Unrecognized metadata name "${ match [ 1 ] } ". Available global metadata names are: ${ globalMetadataNames . join ( ", " ) } ; file metadata names are: ${ fileMetadataNames . join ( ", " ) } ` ) ;
2522- } else if ( fileMetadataNamesIndex === fileMetadataNames . indexOf ( metadataOptionNames . fileName ) ) {
2446+ if ( fileMetadataNamesIndex === - 1 ) {
2447+ // Check if the match is already existed in the global options
2448+ if ( globalOptions [ match [ 1 ] ] !== undefined ) {
2449+ throw new Error ( "Global Option : '" + match [ 1 ] + "' is already existed" ) ;
2450+ }
2451+ globalOptions [ match [ 1 ] ] = match [ 2 ] ;
2452+ }
2453+ else {
2454+ if ( fileMetadataNamesIndex === fileMetadataNames . indexOf ( metadataOptionNames . fileName ) ) {
25232455 // Found an @FileName directive, if this is not the first then create a new subfile
25242456 if ( currentFileContent ) {
25252457 let file = parseFileContent ( currentFileContent , currentFileName , markerPositions , markers , ranges ) ;
@@ -2540,12 +2472,6 @@ module FourSlash {
25402472 // Add other fileMetadata flag
25412473 currentFileOptions [ match [ 1 ] ] = match [ 2 ] ;
25422474 }
2543- } else {
2544- // Check if the match is already existed in the global options
2545- if ( globalOptions [ match [ 1 ] ] !== undefined ) {
2546- throw new Error ( "Global Option : '" + match [ 1 ] + "' is already existed" ) ;
2547- }
2548- globalOptions [ match [ 1 ] ] = match [ 2 ] ;
25492475 }
25502476 }
25512477 // TODO: should be '==='?
0 commit comments