Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NumericLiteral nodes with value 9007199254740993 claim to have .text = 9007199254740992 #33298

Closed
JoshuaKGoldberg opened this issue Sep 7, 2019 · 3 comments
Labels
Bug A bug in TypeScript
Milestone

Comments

@JoshuaKGoldberg
Copy link
Contributor

TypeScript Version: 3.7.0-dev.20190907

Search Terms: numeric literal max value 9007199254740992 9007199254740993

Code

const ts = require("typescript");
const sourceFile = ts.createSourceFile("temp.ts", "9007199254740993", 99);
const literal = sourceFile.statements[0].expression;

// '9007199254740992'
console.log("Actual .text:", literal.text);

// '9007199254740993'
console.log("Expected .text:", literal.getText(sourceFile));

Expected behavior:

.text should be the direct textual representation of the literal's value, right?

Actual behavior:

...some kind of rounding behavior related to being above Number.MAX_SAFE_INTEGER?

Playground Link: https://astexplorer.net/#/gist/8ee21b9bb7973f0d0118658496cec5ec/9dcea811268d39e678732414b53d608e37747a63 - since this is an AST parser issue

Related Issues: Discovered while writing a codefix for #29863. 😆

@JoshuaKGoldberg
Copy link
Contributor Author

Did a little bit of digging. This happens in checkBigIntSuffix (in scanner.ts):

: +tokenValue;

Removing that + fixes the issue. Happy to send a PR if this is desirable!

@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Sep 12, 2019
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Sep 12, 2019
@lowr
Copy link
Contributor

lowr commented Dec 3, 2021

I found this issue while fixing #46195. Looking at the explanation for the text property of LiteralLikeNode (link), it seems like it is actually working as intended. I'm not sure it’s always been like so since when this issue was opened, though.

I could argue that the property name text is confusing as one would expect it to be the node's textual representation in the source code.

@RyanCavanaugh
Copy link
Member

Agreed this is operating as documented.

@RyanCavanaugh RyanCavanaugh closed this as not planned Won't fix, can't repro, duplicate, stale Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript
Projects
None yet
Development

No branches or pull requests

3 participants