Title: createProgarm with @typescript/vfs fails for target ES2021 · Issue #47273 · microsoft/TypeScript · GitHub
Open Graph Title: createProgarm with @typescript/vfs fails for target ES2021 · Issue #47273 · microsoft/TypeScript
X Title: createProgarm with @typescript/vfs fails for target ES2021 · Issue #47273 · microsoft/TypeScript
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, @typescrip...
Open Graph 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...
X 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...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/47273
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"createProgarm with @typescript/vfs fails for target ES2021","articleBody":"# Bug Report\r\n\r\n`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.\r\n\r\n### 🔎 Search Terms\r\n\r\n\u003c!--\r\n What search terms did you use when trying to find an existing bug report?\r\n List them here so people in the future can find this one more easily.\r\n-->\r\nES2021, createProgram, @typescript/vfs, vfs\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n\u003c!-- When did you start seeing this bug occur?\r\n\r\n\"Bugs\" that have existed in TS for a long time are very likely to be FAQs; refer to\r\n https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs\r\n\r\nIf possible, please try testing the nightly version of TS to see if it's already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n\r\nNote: The TypeScript Playground can be used to try older versions of TypeScript.\r\n\r\nPlease keep and fill in the line that best applies:\r\n-->\r\n- This changed between versions 4.4.x and 4.5.x\r\n\r\nFull version information:\r\n- typescript@4.6.0-dev.20211230\r\n- @typescript/vfs@1.3.5\r\n\r\n### ⏯ Playground Link\r\n\r\nReproduction requires import of `typescript` and `@typescript/vfs`. Playground doesn't appear to support this.\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n\r\n```ts\r\nimport ts, { createProgram, ScriptTarget } from 'typescript';\r\nimport { createDefaultMapFromNodeModules, createSystem, createVirtualCompilerHost } from '@typescript/vfs';\r\n\r\nconst compilerOptions = { target: ScriptTarget.ES2021 };\r\nconst code = 'export default \"foo\"';\r\n\r\nconst fsMap = createDefaultMapFromNodeModules(compilerOptions, ts);\r\nfsMap.set('index.tsx', code);\r\nconst host = createVirtualCompilerHost(createSystem(fsMap), compilerOptions, ts);\r\n\r\nconst program = createProgram({\r\n rootNames: [...fsMap.keys()],\r\n options: compilerOptions,\r\n host: host.compilerHost,\r\n});\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nAbove snippet fails with following error:\r\n\r\n```\r\n/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:10460\r\n scan: while (pos >= 0 && pos \u003c text.length) {\r\n ^\r\nTypeError: Cannot read property 'length' of undefined\r\n at iterateCommentRanges (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:10460:45)\r\n at reduceEachLeadingCommentRange (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:10551:16)\r\n at Object.getLeadingCommentRanges (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:10566:16)\r\n at Object.getJSDocCommentRanges (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:15263:16)\r\n at addJSDocComment (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:30878:42)\r\n at parseSourceFileWorker (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:30851:34)\r\n at Object.parseSourceFile (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:30683:26)\r\n at Object.createSourceFile (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:30481:29)\r\n at Object.getSourceFile (/local/home/dppilche/typescript-vfs-bug/node_modules/@typescript/vfs/src/index.ts:504:16)\r\n at findSourceFileWorker (/local/home/dppilche/typescript-vfs-bug/node_modules/typescript/lib/typescript.js:115369:29)\r\n```\r\n\r\n### 🙂 Expected behavior\r\n\r\n\u003c!-- What you expected to happen instead, and why -->\r\n\r\n`createProgram` does not crash.","author":{"url":"https://github.com/dpilch","@type":"Person","name":"dpilch"},"datePublished":"2021-12-30T16:44:08Z","url":"https://github.com/microsoft/TypeScript/issues/47273"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b310c60c-6df1-5481-e5cd-c5174e2af50a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DD98:3D97C8:2388E3C:2F44F92:6B01935C |
| html-safe-nonce | ea97e28e245a1993d102acb8433bcd5493aecd0e17e9c017cac21c8d95bc9283 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDk4OjNEOTdDODoyMzg4RTNDOjJGNDRGOTI6NkIwMTkzNUMiLCJ2aXNpdG9yX2lkIjoiMzM0MTY4NzkzMzM3NDY2NTU2NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 9f12e40b55e397f2d04cb1e2b7501f9fd78d41114b98d07018c963bd3905c9a0 |
| hovercard-subject-tag | issue:1091205780 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/47273/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5fd3339f0a4cfcc9b7f0a75e75402a909aebd3c88adb569b1bba8d8e6f6a96ae/microsoft/TypeScript/issues/47273 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5fd3339f0a4cfcc9b7f0a75e75402a909aebd3c88adb569b1bba8d8e6f6a96ae/microsoft/TypeScript/issues/47273 |
| og:image:alt | 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... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dpilch |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width