Microsoft/TypeScript

createProgarm with @typescript/vfs fails for target ES2021

Open

#47 273 ouverte le 30 déc. 2021

Voir sur GitHub
 (3 commentaires) (1 réaction) (0 assignés)TypeScript (6 726 forks)batch import
BugDomain: ParserHelp Wanted

Métriques du dépôt

Stars
 (48 455 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (9 PRs mergées en 30 j)

Description

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

ES2021, createProgram, @typescript/vfs, vfs

🕗 Version & Regression Information

  • 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

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

createProgram does not crash.

Guide contributeur