diff --git a/src/plugins/flow.js b/src/plugins/flow.js index a0f32f550c..d5db18957e 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -519,6 +519,11 @@ pp.flowParsePrimaryType = function () { this.next(); return this.finishNode(node, "NullLiteralTypeAnnotation"); + case tt._this: + node.value = this.match(tt._this); + this.next(); + return this.finishNode(node, "ThisTypeAnnotation"); + default: if (this.state.type.keyword === "typeof") { return this.flowParseTypeofType(); diff --git a/test/fixtures/flow/type-annotations/100/actual.js b/test/fixtures/flow/type-annotations/100/actual.js new file mode 100644 index 0000000000..9807075501 --- /dev/null +++ b/test/fixtures/flow/type-annotations/100/actual.js @@ -0,0 +1 @@ +class Foo { bar():this { return this; }} diff --git a/test/fixtures/flow/type-annotations/100/expected.json b/test/fixtures/flow/type-annotations/100/expected.json new file mode 100644 index 0000000000..5efdb76d0e --- /dev/null +++ b/test/fixtures/flow/type-annotations/100/expected.json @@ -0,0 +1,200 @@ + +{ + "type": "File", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "sourceType": "module", + "body": [ + { + "type": "ClassDeclaration", + "start": 0, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "id": { + "type": "Identifier", + "start": 6, + "end": 9, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start": 10, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 1, + "column": 40 + } + }, + "body": [ + { + "type": "ClassMethod", + "start": 12, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "computed": false, + "key": { + "type": "Identifier", + "start": 12, + "end": 15, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 15 + } + }, + "name": "bar" + }, + "static": false, + "kind": "method", + "id": null, + "generator": false, + "expression": false, + "async": false, + "params": [], + "returnType": { + "type": "TypeAnnotation", + "start": 17, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 17 + }, + "end": { + "line": 1, + "column": 22 + } + }, + "typeAnnotation": { + "type": "ThisTypeAnnotation", + "start": 18, + "end": 22, + "loc": { + "start": { + "line": 1, + "column": 18 + }, + "end": { + "line": 1, + "column": 22 + } + } + } + }, + "body": { + "type": "BlockStatement", + "start": 23, + "end": 39, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 39 + } + }, + "body": [ + { + "type": "ReturnStatement", + "start": 25, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "argument": { + "type": "ThisExpression", + "start": 32, + "end": 36, + "loc": { + "start": { + "line": 1, + "column": 32 + }, + "end": { + "line": 1, + "column": 36 + } + } + } + } + ] + } + } + ] + } + } + ] + }, + "comments": [] +}