Skip to content

Fix exponent notation with a trailing decimal point - #5506

Open
sean0407 wants to merge 1 commit into
jashkenas:mainfrom
sean0407:codex/coffeescript-5469-scientific-notation
Open

sean0407 wants to merge 1 commit into
jashkenas:mainfrom
sean0407:codex/coffeescript-5469-scientific-notation

Conversation

@sean0407

Copy link
Copy Markdown

Fixes #5469

The lexer currently stops before the decimal point in 1.e1 and 1.e-1, producing 1..e1 and 1..e - 1. Recognize a trailing decimal point when it is followed by a valid exponent so these inputs compile as JavaScript numeric literals.

Changes:

  • Add the exponent form to the source and generated lexer.
  • Add regression coverage for positive and negative exponents.

Verification:

  • Generated lib/coffeescript/lexer.js from src/lexer.coffee in an isolated, network-disabled container.
  • Ran 5 isolated Node assertions: both expressions evaluate to the expected values, both emitted forms retain their numeric literal, and existing 4.toString() behavior remains intact.
  • git diff --check passed; patch policy accepted 3 text files and 8 changed lines.

@Inve1951

Copy link
Copy Markdown
Contributor

I suspect this was intentionally not supported.
See the decimal regex on the next line: it also doesn't support a trailing dot.

As you pointed out this also changes the meaning of 42.e3 from property access to number literal, which is a breaking change.

@sean0407

Copy link
Copy Markdown
Author

You're right: 42.e3 is currently parsed as access to the e3 property, so treating it as a number would change existing behavior. The same ambiguity applies to a signed exponent such as 1.e-1, which can currently be parsed as property access followed by subtraction.

I agree this should not be merged as a bug fix without a compatibility decision. Would you prefer to leave this syntax unsupported and close #5469, or consider the change only for a future breaking release? I'll hold off on further changes pending your preference.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Number with a dot before e in scientific notation returns two dots in JavaScript

2 participants