diff --git a/lib/coffeescript/lexer.js b/lib/coffeescript/lexer.js index b00e651c40..c200453457 100644 --- a/lib/coffeescript/lexer.js +++ b/lib/coffeescript/lexer.js @@ -1806,10 +1806,11 @@ // Is this an attribute with a value? }(?:\\s*:\\s*${JSX_IDENTIFIER_PART})?)([^\\S]*=(?!=))?`); - NUMBER = /^0b[01](?:_?[01])*n?|^0o[0-7](?:_?[0-7])*n?|^0x[\da-f](?:_?[\da-f])*n?|^\d+(?:_\d+)*n|^(?:\d+(?:_\d+)*)?\.?\d+(?:_\d+)*(?:e[+-]?\d+(?:_\d+)*)?/i; // binary + NUMBER = /^0b[01](?:_?[01])*n?|^0o[0-7](?:_?[0-7])*n?|^0x[\da-f](?:_?[\da-f])*n?|^\d+(?:_\d+)*n|^\d+(?:_\d+)*\.e[+-]?\d+(?:_\d+)*|^(?:\d+(?:_\d+)*)?\.?\d+(?:_\d+)*(?:e[+-]?\d+(?:_\d+)*)?/i; // binary // octal // hex // decimal bigint + // decimal with exponent and no fractional digits // decimal // decimal without support for numeric literal separators for reference: // \d*\.?\d+ (?:e[+-]?\d+)? diff --git a/src/lexer.coffee b/src/lexer.coffee index 80135b9db5..0b4087b0c7 100644 --- a/src/lexer.coffee +++ b/src/lexer.coffee @@ -1311,6 +1311,7 @@ NUMBER = /// ^ 0o[0-7](?:_?[0-7])*n? | # octal ^ 0x[\da-f](?:_?[\da-f])*n? | # hex ^ \d+(?:_\d+)*n | # decimal bigint + ^ \d+(?:_\d+)* \. e[+-]? \d+(?:_\d+)* | # decimal with exponent and no fractional digits ^ (?:\d+(?:_\d+)*)? \.? \d+(?:_\d+)* # decimal (?:e[+-]? \d+(?:_\d+)* )? # decimal without support for numeric literal separators for reference: diff --git a/test/numbers.coffee b/test/numbers.coffee index 04a83cb846..72b0ca39be 100644 --- a/test/numbers.coffee +++ b/test/numbers.coffee @@ -77,6 +77,10 @@ test "#5164: Allow lowercase and uppercase exponent notation", -> doesNotThrow -> CoffeeScript.compile "0e0", bare: yes doesNotThrow -> CoffeeScript.compile "0E0", bare: yes +test "#5469: Allow a trailing decimal point before an exponent", -> + eq 10, CoffeeScript.eval "1.e1" + eq 0.1, CoffeeScript.eval "1.e-1" + test "#2224: hex literals with 0b or B or E", -> eq 176, 0x0b0 eq 177, 0x0B1