Skip to content

Commit

Permalink
Merge pull request #59 from HubSpot/fix/float-missing-leading-zero
Browse files Browse the repository at this point in the history
Fix float missing leading zero parsing error
  • Loading branch information
anthmatic authored Jan 27, 2023
2 parents bc0e58b + 130baf1 commit 19272d5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions parser/src/parser/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1230,6 +1230,11 @@ class Parser extends Obj {
val = null;
} else if (tok.type === lexer.TOKEN_REGEX) {
val = new RegExp(tok.value.body, tok.value.flags);
} else if (tok.type === lexer.TOKEN_OPERATOR && tok.value === ".") {
const maybeIntTok = this.nextToken();
if (maybeIntTok.type === lexer.TOKEN_INT) {
val = parseFloat("." + maybeIntTok.value);
}
}

if (val !== undefined) {
Expand Down
14 changes: 14 additions & 0 deletions prettier/tests/__snapshots__/run_tests.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,13 @@ What is this element?
{{ variable1.variable2['one'] }}
{{ variable['two-words'] }}
{{ variable1.variable2['two-words'] }}
{{ 1.0 }}
{{ 1.0002 }}
{{ .1 }}
{{ .1000001 }}
{{ .1002 }}
{{ 0.100004 }}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{% if sky != "blue" %}
Clouds
Expand Down Expand Up @@ -1769,6 +1776,13 @@ What is this element?
{{ variable["two-words"] }}
{{ variable1.variable2["two-words"] }}
{{ 1 }}
{{ 1.0002 }}
{{ 0.1 }}
{{ 0.1000001 }}
{{ 0.1002 }}
{{ 0.100004 }}
`;
exports[`nestedHtmlTags.html 1`] = `
Expand Down
7 changes: 7 additions & 0 deletions prettier/tests/misc.html
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,10 @@
{{ variable1.variable2['one'] }}
{{ variable['two-words'] }}
{{ variable1.variable2['two-words'] }}

{{ 1.0 }}
{{ 1.0002 }}
{{ .1 }}
{{ .1000001 }}
{{ .1002 }}
{{ 0.100004 }}

0 comments on commit 19272d5

Please sign in to comment.