Title: Native API createSourceFile panics for numeric literals whose normalized text is longer than the source · Issue #65451 · microsoft/TypeScript · GitHub
Open Graph Title: Native API createSourceFile panics for numeric literals whose normalized text is longer than the source · Issue #65451 · microsoft/TypeScript
X Title: Native API createSourceFile panics for numeric literals whose normalized text is longer than the source · Issue #65451 · microsoft/TypeScript
Description: 🔎 Search Terms stringtable, createSourceFile panic, slice bounds, numeric literal encoder 🕗 Version & Regression Information Reproduces with typescript@7.1.0-beta and typescript@7.1.0-dev.20261111.1 on Linux x64, using Node.js 24.20.0. A...
Open Graph Description: 🔎 Search Terms stringtable, createSourceFile panic, slice bounds, numeric literal encoder 🕗 Version & Regression Information Reproduces with typescript@7.1.0-beta and typescript@7.1.0-dev.20261111....
X Description: 🔎 Search Terms stringtable, createSourceFile panic, slice bounds, numeric literal encoder 🕗 Version & Regression Information Reproduces with typescript@7.1.0-beta and typescript@7.1.0-dev.20261...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/65451
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Native API createSourceFile panics for numeric literals whose normalized text is longer than the source","articleBody":"### 🔎 Search Terms\n\n`stringtable`, `createSourceFile panic`, `slice bounds`, numeric literal encoder\n\n### 🕗 Version & Regression Information\n\nReproduces with `typescript@7.1.0-beta` and `typescript@7.1.0-dev.20261111.1` on Linux x64, using Node.js 24.20.0.\n\nAlso reproduces in an unmodified local build of current `main`, commit `ad24728023c52ef6a92a278046cdb69621048365` (`7.1.0-dev`), built with `node node_modules/hereby/bin/hereby.js build`.\n\nThe first affected version has not been identified. This concerns the native `typescript/sync` API. I reviewed the FAQ and found no entry covering this crash.\n\n### ⏯ Playground Link\n\nNot applicable: this reproduces through the native API's source-file serialization.\n\n### 💻 Code\n\nInstall an exact affected version:\n\n```sh\nnpm install typescript@7.1.0-dev.20261111.1\n```\n\nSave as `repro.cjs` and run `node repro.cjs`:\n\n```js\nconst { API } = require('typescript/sync');\nconst api = new API();\ntry {\n api.createSourceFile('a.ts', '.1');\n} finally {\n api.close();\n}\n```\n\n### 🙁 Actual behavior\n\nThe call throws an error containing the server panic:\n\n```text\npanic: runtime error: slice bounds out of range [-1:]\n.../internal/api/encoder.(*stringTable).add\n .../internal/api/encoder/stringtable.go:41\n.../internal/api/encoder.recordExtendedData_NumericLiteral\n .../internal/api/encoder/encoder.go:936\n```\n\nReplacing `.1` with `1e3` or `1e9` also panics. `1e2`, `1`, and `0` succeed. Each input was tested in a separate API instance/process.\n\n### 🙂 Expected behavior\n\nReturn a source-file syntax tree for these valid numeric expressions without a panic.\n\n### Additional information about the issue\n\nThe numeric literal's normalized text can be longer than its original spelling:\n\n| Source | Normalized text | Result |\n| --- | --- | --- |\n| `.1` | `0.1` | Panic, slice start -1 |\n| `1e3` | `1000` | Panic, slice start -1 |\n| `1e9` | `1000000000` | Panic, slice start -7 |\n| `1e2` | `100` | Success |\n| `1` | `1` | Success |\n| `0` | `0` | Success |\n\n`recordExtendedData_NumericLiteral` passes the normalized text and original positions to `stringTable.add`. The latter computes `start := end - len(text)` and slices `fileText[start:end]` before checking whether the slice matches the text. In these examples `start` is negative, so the existing fallback for text that cannot be reused from the source is never reached.\n\nSource inspected at commit `ad24728023c52ef6a92a278046cdb69621048365`:\nhttps://github.com/microsoft/TypeScript/blob/ad24728023c52ef6a92a278046cdb69621048365/tsc/internal/api/encoder/stringtable.go#L26-L52\n","author":{"url":"https://github.com/AkisArou","@type":"Person","name":"AkisArou"},"datePublished":"2026-11-12T08:10:01Z","url":"https://github.com/microsoft/TypeScript/issues/65451"}
| 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:a7831c6d-a6ee-da02-4f40-dd432c31fca3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E88C:229B2E:179E879:1F20BB1:6B0135DC |
| html-safe-nonce | 8df3675d55ffba69f03b5da816ed3cadf3c9d4d60d6e687828bfb0bca743986e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODhDOjIyOUIyRToxNzlFODc5OjFGMjBCQjE6NkIwMTM1REMiLCJ2aXNpdG9yX2lkIjoiMjk3NDQzMDkxMDU5NTgwNjY4NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 423b2f9580ceba6bee3140ffca4967b1245636c20b97cc3566fa6d61a296318e |
| hovercard-subject-tag | issue:6345646237 |
| 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/65451/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2b2b517731c7a97561b1bf882d404427835f4c08c454f5c56edf5cc488f0843a/microsoft/TypeScript/issues/65451 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2b2b517731c7a97561b1bf882d404427835f4c08c454f5c56edf5cc488f0843a/microsoft/TypeScript/issues/65451 |
| og:image:alt | 🔎 Search Terms stringtable, createSourceFile panic, slice bounds, numeric literal encoder 🕗 Version & Regression Information Reproduces with typescript@7.1.0-beta and typescript@7.1.0-dev.20261111.... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | AkisArou |
| 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