@@ -29,13 +29,13 @@ module FourSlash {
29
29
fileName : string ;
30
30
version : number ;
31
31
// File-specific options (name/value pairs)
32
- fileOptions : { [ index : string ] : string ; } ;
32
+ fileOptions : Harness . TestCaseParser . CompilerSettings ;
33
33
}
34
34
35
35
// Represents a set of parsed source files and options
36
36
export interface FourSlashData {
37
37
// Global options (name/value pairs)
38
- globalOptions : { [ index : string ] : string ; } ;
38
+ globalOptions : Harness . TestCaseParser . CompilerSettings ;
39
39
40
40
files : FourSlashFile [ ] ;
41
41
@@ -117,89 +117,17 @@ module FourSlash {
117
117
// Add cases into convertGlobalOptionsToCompilationsSettings function for the compiler to acknowledge such option from meta data
118
118
let metadataOptionNames = {
119
119
baselineFile : "BaselineFile" ,
120
- declaration : "declaration" ,
121
120
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
122
121
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" ,
131
122
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" ,
133
123
} ;
134
124
135
125
// List of allowed metadata names
136
126
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 ] ;
140
127
141
- function convertGlobalOptionsToCompilerOptions ( globalOptions : { [ idx : string ] : string } ) : ts . CompilerOptions {
128
+ function convertGlobalOptionsToCompilerOptions ( globalOptions : Harness . TestCaseParser . CompilerSettings ) : ts . CompilerOptions {
142
129
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 ) ;
203
131
return settings ;
204
132
}
205
133
@@ -2514,12 +2442,16 @@ module FourSlash {
2514
2442
// Comment line, check for global/file @options and record them
2515
2443
let match = optionRegex . exec ( line . substr ( 2 ) ) ;
2516
2444
if ( match ) {
2517
- let globalMetadataNamesIndex = globalMetadataNames . indexOf ( match [ 1 ] ) ;
2518
2445
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 ) ) {
2523
2455
// Found an @FileName directive, if this is not the first then create a new subfile
2524
2456
if ( currentFileContent ) {
2525
2457
let file = parseFileContent ( currentFileContent , currentFileName , markerPositions , markers , ranges ) ;
@@ -2540,12 +2472,6 @@ module FourSlash {
2540
2472
// Add other fileMetadata flag
2541
2473
currentFileOptions [ match [ 1 ] ] = match [ 2 ] ;
2542
2474
}
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 ] ;
2549
2475
}
2550
2476
}
2551
2477
// TODO: should be '==='?
0 commit comments