Repository: TypeScript
Issue: createProgarm with @typescript/vfs fails for target ES2021
Labels: Bug,Help Wanted

# Bug Report

`createProgram` fails with internal error when using @typescript/vfs and setting compiler option target to ES2021. This issue only happens for `ES2021`, all other targets work fine.

### 🔎 Search Terms

<!--
  What search terms did you use when trying to find an existing bug report?
  List them here so people in the future can find this one more easily.
-->
ES2021, createProgram, @typescript/vfs, vfs

### 🕗 Version & Regression Information

<!-- When did you start seeing this bug occur?

"Bugs" that have existed in TS for a long time are very likely to be FAQs; refer to
  https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs

If possible, please try testing the nightly version of TS to see if it's already been fixed.
For npm: `typescript@next`
This is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly

Note: The TypeScript Playground can be used to try older versions of TypeScript.

Please keep and fill in the line that best applies:
-->
- This changed between versions 4.4.x and 4.5.x

Full version information:
- typescript@4.6.0-dev.20211230
- @typescript/vfs@1.3.5

### ⏯ Playground Link

Reproduction requires import of `typescript` and `@typescript/vfs`. Playground doesn't appear to support this.

### 💻 Code

<!-- Please post the relevant code sample here as well-->

```ts
import ts, { createProgram, ScriptTarget } from 'typescript';
import { createDefaultMapFromNodeModules, createSystem, createVirtualCompilerHost } from '@typescript/vfs';

const compilerOptions = { target: ScriptTarget.ES2021 };
const code = 'export default "foo"';

const fsMap = createDefaultMapFromNodeModules(compilerOptions, ts);
fsMap.set('index.tsx', code);
const host = createVirtualCompilerHost(createSystem(fsMap), compilerOptions, ts);

const program = createProgram({
  rootNames: [...fsMap.keys()],
  options: compilerOptions,
  host: host.compilerHost,
});
```

### 🙁 Actual behavior

Above snippet fails with following error:

```
/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:10460
        scan: while (pos >= 0 && pos < text.length) {
                                            ^
TypeError: Cannot read property 'length' of undefined
    at iterateCommentRanges (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:10460:45)
    at reduceEachLeadingCommentRange (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:10551:16)
    at Object.getLeadingCommentRanges (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:10566:16)
    at Object.getJSDocCommentRanges (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:15263:16)
    at addJSDocComment (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:30878:42)
    at parseSourceFileWorker (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:30851:34)
    at Object.parseSourceFile (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:30683:26)
    at Object.createSourceFile (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:30481:29)
    at Object.getSourceFile (/local/home/dppilche/typescript-vfs-bug/node_modules/@typescript/vfs/src/index.ts:504:16)
    at findSourceFileWorker (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:115369:29)
```

### 🙂 Expected behavior

<!-- What you expected to happen instead, and why -->

`createProgram` does not crash.