Skip to content

Commit

Permalink
fix: ensure floats with leading periods work as expected (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
eventualbuddha authored Dec 30, 2016
1 parent 3945864 commit 6a0a142
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/mappers/mapLiteral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function mapLiteral(context: ParseContext, node: Literal): Node {
return new JavaScript(line, column, start, end, raw, virtual, node.value);
}

if (startToken.type === SourceType.NUMBER) {
if (startToken.type === SourceType.NUMBER || startToken.type === SourceType.DOT) {
if (raw.includes('.')) {
return new Float(line, column, start, end, raw, virtual, parseNumber(node.value));
} else {
Expand Down
1 change: 1 addition & 0 deletions test/examples/float-leading-period/input.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.25
33 changes: 33 additions & 0 deletions test/examples/float-leading-period/output.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"type": "Program",
"line": 1,
"column": 1,
"range": [
0,
4
],
"raw": ".25\n",
"body": {
"type": "Block",
"line": 1,
"column": 1,
"range": [
0,
3
],
"statements": [
{
"type": "Float",
"line": 1,
"column": 1,
"range": [
0,
3
],
"raw": ".25",
"data": 0.25
}
],
"raw": ".25"
}
}

0 comments on commit 6a0a142

Please sign in to comment.