Fix negative number literal typeannotations (#366)

* Fix negative number literal typeannotations

Also use parseLiteral() to parser string and number literal typeannotations
so that future changes (estree) to literals are also reflected to flow.

* Instead of invalid fallthrough throw immediately

* Increase coverage and better error mesage
This commit is contained in:
Daniel Tschinder
2017-02-20 22:43:59 +01:00
committed by GitHub
parent 57aaceaae7
commit 2ef00a6631
13 changed files with 47 additions and 47 deletions

View File

@@ -0,0 +1 @@
var a: -z

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token, expected number (1:8)"
}

View File

@@ -0,0 +1 @@
var a: +1

View File

@@ -0,0 +1,3 @@
{
"throws": "Unexpected token (1:7)"
}

View File

@@ -1 +1 @@
var a: 0b1111011
var a: -0b1111011

View File

@@ -1,7 +1,7 @@
{
"type": "File",
"start": 0,
"end": 16,
"end": 17,
"loc": {
"start": {
"line": 1,
@@ -9,13 +9,13 @@
},
"end": {
"line": 1,
"column": 16
"column": 17
}
},
"program": {
"type": "Program",
"start": 0,
"end": 16,
"end": 17,
"loc": {
"start": {
"line": 1,
@@ -23,7 +23,7 @@
},
"end": {
"line": 1,
"column": 16
"column": 17
}
},
"sourceType": "module",
@@ -31,7 +31,7 @@
{
"type": "VariableDeclaration",
"start": 0,
"end": 16,
"end": 17,
"loc": {
"start": {
"line": 1,
@@ -39,14 +39,14 @@
},
"end": {
"line": 1,
"column": 16
"column": 17
}
},
"declarations": [
{
"type": "VariableDeclarator",
"start": 4,
"end": 16,
"end": 17,
"loc": {
"start": {
"line": 1,
@@ -54,13 +54,13 @@
},
"end": {
"line": 1,
"column": 16
"column": 17
}
},
"id": {
"type": "Identifier",
"start": 4,
"end": 16,
"end": 17,
"loc": {
"start": {
"line": 1,
@@ -68,14 +68,14 @@
},
"end": {
"line": 1,
"column": 16
"column": 17
}
},
"name": "a",
"typeAnnotation": {
"type": "TypeAnnotation",
"start": 5,
"end": 16,
"end": 17,
"loc": {
"start": {
"line": 1,
@@ -83,13 +83,13 @@
},
"end": {
"line": 1,
"column": 16
"column": 17
}
},
"typeAnnotation": {
"type": "NumericLiteralTypeAnnotation",
"start": 7,
"end": 16,
"end": 17,
"loc": {
"start": {
"line": 1,
@@ -97,13 +97,13 @@
},
"end": {
"line": 1,
"column": 16
"column": 17
}
},
"value": 123,
"value": -123,
"extra": {
"rawValue": 123,
"raw": "0b1111011"
"rawValue": -123,
"raw": "-0b1111011"
}
}
}
@@ -116,4 +116,4 @@
],
"directives": []
}
}
}

View File

@@ -103,7 +103,7 @@
"value": -123,
"extra": {
"rawValue": -123,
"raw": "123.0"
"raw": "-123.0"
}
}
}
@@ -116,4 +116,4 @@
],
"directives": []
}
}
}

View File

@@ -103,7 +103,7 @@
"value": -123,
"extra": {
"rawValue": -123,
"raw": "0o173"
"raw": "-0o173"
}
}
}
@@ -116,4 +116,4 @@
],
"directives": []
}
}
}

View File

@@ -103,7 +103,7 @@
"value": -123,
"extra": {
"rawValue": -123,
"raw": "0x7B"
"raw": "-0x7B"
}
}
}
@@ -116,4 +116,4 @@
],
"directives": []
}
}
}

View File

@@ -92,7 +92,7 @@
"value": -1,
"extra": {
"rawValue": -1,
"raw": "1"
"raw": "-1"
}
},
{
@@ -417,4 +417,4 @@
}
}
]
}
}