Merge pull request #3130 from amasad/flow-null-type
Add support for null literal type
This commit is contained in:
commit
d2ff843dae
@ -20,6 +20,10 @@ export function BooleanLiteralTypeAnnotation(node: Object) {
|
|||||||
this.push(node.value ? "true" : "false");
|
this.push(node.value ? "true" : "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function NullLiteralTypeAnnotation() {
|
||||||
|
this.push("null");
|
||||||
|
}
|
||||||
|
|
||||||
export function DeclareClass(node: Object) {
|
export function DeclareClass(node: Object) {
|
||||||
this.push("declare class ");
|
this.push("declare class ");
|
||||||
this._interfaceish(node);
|
this._interfaceish(node);
|
||||||
|
|||||||
1
packages/babel-generator/test/fixtures/flow/null-literal-types/actual.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/flow/null-literal-types/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var foo: null;
|
||||||
1
packages/babel-generator/test/fixtures/flow/null-literal-types/expected.js
vendored
Normal file
1
packages/babel-generator/test/fixtures/flow/null-literal-types/expected.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var foo: null;
|
||||||
@ -26,9 +26,12 @@ defineType("BooleanTypeAnnotation", {
|
|||||||
|
|
||||||
defineType("BooleanLiteralTypeAnnotation", {
|
defineType("BooleanLiteralTypeAnnotation", {
|
||||||
aliases: ["Flow"],
|
aliases: ["Flow"],
|
||||||
fields: {
|
fields: {}
|
||||||
// todo
|
});
|
||||||
}
|
|
||||||
|
defineType("NullLiteralTypeAnnotation", {
|
||||||
|
aliases: ["Flow"],
|
||||||
|
fields: {}
|
||||||
});
|
});
|
||||||
|
|
||||||
defineType("ClassImplements", {
|
defineType("ClassImplements", {
|
||||||
|
|||||||
@ -514,6 +514,11 @@ pp.flowParsePrimaryType = function () {
|
|||||||
this.next();
|
this.next();
|
||||||
return this.finishNode(node, "NumericLiteralTypeAnnotation");
|
return this.finishNode(node, "NumericLiteralTypeAnnotation");
|
||||||
|
|
||||||
|
case tt._null:
|
||||||
|
node.value = this.match(tt._null);
|
||||||
|
this.next();
|
||||||
|
return this.finishNode(node, "NullLiteralTypeAnnotation");
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (this.state.type.keyword === "typeof") {
|
if (this.state.type.keyword === "typeof") {
|
||||||
return this.flowParseTypeofType();
|
return this.flowParseTypeofType();
|
||||||
|
|||||||
1
packages/babylon/test/fixtures/flow/literal-types/null/actual.js
vendored
Normal file
1
packages/babylon/test/fixtures/flow/literal-types/null/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var foo: null
|
||||||
114
packages/babylon/test/fixtures/flow/literal-types/null/expected.json
vendored
Normal file
114
packages/babylon/test/fixtures/flow/literal-types/null/expected.json
vendored
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
{
|
||||||
|
"type": "File",
|
||||||
|
"start": 0,
|
||||||
|
"end": 13,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 13
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"program": {
|
||||||
|
"type": "Program",
|
||||||
|
"start": 0,
|
||||||
|
"end": 13,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 13
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sourceType": "module",
|
||||||
|
"body": [
|
||||||
|
{
|
||||||
|
"type": "VariableDeclaration",
|
||||||
|
"start": 0,
|
||||||
|
"end": 13,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 0
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 13
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"declarations": [
|
||||||
|
{
|
||||||
|
"type": "VariableDeclarator",
|
||||||
|
"start": 4,
|
||||||
|
"end": 13,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 4
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 13
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"id": {
|
||||||
|
"type": "Identifier",
|
||||||
|
"start": 4,
|
||||||
|
"end": 13,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 4
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 13
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"name": "foo",
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "TypeAnnotation",
|
||||||
|
"start": 7,
|
||||||
|
"end": 13,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 7
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 13
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"typeAnnotation": {
|
||||||
|
"type": "NullLiteralTypeAnnotation",
|
||||||
|
"start": 9,
|
||||||
|
"end": 13,
|
||||||
|
"loc": {
|
||||||
|
"start": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 9
|
||||||
|
},
|
||||||
|
"end": {
|
||||||
|
"line": 1,
|
||||||
|
"column": 13
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"value": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"init": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"kind": "var"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user