Fix throw exception on emit file

Fix issue #852
Though targetSourceFile is not declaration file, it may be possible that compilerOptions.out may not be defined as well which will be a problem as well.