From e3da84bcc30ad67d2a411ef33634a8926e505280 Mon Sep 17 00:00:00 2001 From: Amjad Masad Date: Thu, 3 Dec 2015 23:58:25 -0800 Subject: [PATCH] Add support for null literal type --- src/plugins/flow.js | 5 + .../flow/literal-types/null/actual.js | 1 + .../flow/literal-types/null/expected.js | 114 ++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 test/fixtures/flow/literal-types/null/actual.js create mode 100644 test/fixtures/flow/literal-types/null/expected.js diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 060f623649..7e561ac56d 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -514,6 +514,11 @@ pp.flowParsePrimaryType = function () { this.next(); return this.finishNode(node, "NumericLiteralTypeAnnotation"); + case tt._null: + node.value = this.match(tt._null); + this.next(); + return this.finishNode(node, "NullLiteralTypeAnnotation"); + default: if (this.state.type.keyword === "typeof") { return this.flowParseTypeofType(); diff --git a/test/fixtures/flow/literal-types/null/actual.js b/test/fixtures/flow/literal-types/null/actual.js new file mode 100644 index 0000000000..8595ff5eeb --- /dev/null +++ b/test/fixtures/flow/literal-types/null/actual.js @@ -0,0 +1 @@ +var foo: null diff --git a/test/fixtures/flow/literal-types/null/expected.js b/test/fixtures/flow/literal-types/null/expected.js new file mode 100644 index 0000000000..78ebec7ba0 --- /dev/null +++ b/test/fixtures/flow/literal-types/null/expected.js @@ -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" + } + ] + } +}