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:
1
test/fixtures/flow/literal-types/invalid-number-negative/actual.js
vendored
Normal file
1
test/fixtures/flow/literal-types/invalid-number-negative/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
var a: -z
|
||||
3
test/fixtures/flow/literal-types/invalid-number-negative/options.json
vendored
Normal file
3
test/fixtures/flow/literal-types/invalid-number-negative/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Unexpected token, expected number (1:8)"
|
||||
}
|
||||
1
test/fixtures/flow/literal-types/invalid-number-positive/actual.js
vendored
Normal file
1
test/fixtures/flow/literal-types/invalid-number-positive/actual.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
var a: +1
|
||||
3
test/fixtures/flow/literal-types/invalid-number-positive/options.json
vendored
Normal file
3
test/fixtures/flow/literal-types/invalid-number-positive/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Unexpected token (1:7)"
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
var a: 0b1111011
|
||||
var a: -0b1111011
|
||||
|
||||
@@ -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": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@
|
||||
"value": -123,
|
||||
"extra": {
|
||||
"rawValue": -123,
|
||||
"raw": "123.0"
|
||||
"raw": "-123.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,4 +116,4 @@
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@
|
||||
"value": -123,
|
||||
"extra": {
|
||||
"rawValue": -123,
|
||||
"raw": "0o173"
|
||||
"raw": "-0o173"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,4 +116,4 @@
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@
|
||||
"value": -123,
|
||||
"extra": {
|
||||
"rawValue": -123,
|
||||
"raw": "0x7B"
|
||||
"raw": "-0x7B"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,4 +116,4 @@
|
||||
],
|
||||
"directives": []
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@
|
||||
"value": -1,
|
||||
"extra": {
|
||||
"rawValue": -1,
|
||||
"raw": "1"
|
||||
"raw": "-1"
|
||||
}
|
||||
},
|
||||
{
|
||||
@@ -417,4 +417,4 @@
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user