@@ -108,23 +108,16 @@ namespace ts {
108
108
it ( `${ caption } [${ extension } ]` , ( ) => runBaseline ( extension ) ) ) ;
109
109
110
110
function runBaseline ( extension : Extension ) {
111
- const f = {
112
- path : "/a" + extension ,
113
- content : t . source
114
- } ;
115
- const host = projectSystem . createServerHost ( [ f , projectSystem . libFile ] ) ;
116
- const projectService = projectSystem . createProjectService ( host ) ;
117
- projectService . openClientFile ( f . path ) ;
118
- const program = projectService . inferredProjects [ 0 ] . getLanguageService ( ) . getProgram ( ) ;
111
+ const path = "/a" + extension ;
112
+ const program = makeProgram ( { path, content : t . source } ) ;
119
113
120
- // Don't bother generating JS baselines for inputs that aren't valid JS.
121
- const diags = program . getSyntacticDiagnostics ( ) ;
122
- if ( diags && diags . length ) {
114
+ if ( hasSyntacticDiagnostics ( program ) ) {
115
+ // Don't bother generating JS baselines for inputs that aren't valid JS.
123
116
assert . equal ( Extension . Js , extension ) ;
124
117
return ;
125
118
}
126
119
127
- const sourceFile = program . getSourceFile ( f . path ) ;
120
+ const sourceFile = program . getSourceFile ( path ) ;
128
121
const context : RefactorContext = {
129
122
cancellationToken : { throwIfCancellationRequested ( ) { } , isCancellationRequested ( ) { return false ; } } ,
130
123
newLineCharacter,
@@ -150,10 +143,26 @@ namespace ts {
150
143
const newText = textChanges . applyChanges ( sourceFile . text , edits [ 0 ] . textChanges ) ;
151
144
const newTextWithRename = newText . slice ( 0 , renameLocation ) + "/*RENAME*/" + newText . slice ( renameLocation ) ;
152
145
data . push ( newTextWithRename ) ;
146
+
147
+ const diagProgram = makeProgram ( { path, content : newText } ) ;
148
+ assert . isFalse ( hasSyntacticDiagnostics ( diagProgram ) ) ;
153
149
}
154
150
return data . join ( newLineCharacter ) ;
155
151
} ) ;
156
152
}
153
+
154
+ function makeProgram ( f : { path : string , content : string } ) {
155
+ const host = projectSystem . createServerHost ( [ f , projectSystem . libFile ] ) ;
156
+ const projectService = projectSystem . createProjectService ( host ) ;
157
+ projectService . openClientFile ( f . path ) ;
158
+ const program = projectService . inferredProjects [ 0 ] . getLanguageService ( ) . getProgram ( ) ;
159
+ return program ;
160
+ }
161
+
162
+ function hasSyntacticDiagnostics ( program : Program ) {
163
+ const diags = program . getSyntacticDiagnostics ( ) ;
164
+ return length ( diags ) > 0 ;
165
+ }
157
166
}
158
167
159
168
export function testExtractSymbolFailed ( caption : string , text : string , description : DiagnosticMessage ) {
0 commit comments