Add support for this type to Babel 6.x
This commit is contained in:
parent
ae8b7ea352
commit
32c03222bf
@ -140,6 +140,10 @@ export function StringTypeAnnotation() {
|
||||
this.push("string");
|
||||
}
|
||||
|
||||
export function ThisTypeAnnotation() {
|
||||
this.push("this");
|
||||
}
|
||||
|
||||
export function TupleTypeAnnotation(node: Object) {
|
||||
this.push("[");
|
||||
this.printJoin(node.types, node, { separator: ", " });
|
||||
|
||||
5
packages/babel-generator/test/fixtures/flow/this-types/actual.js
vendored
Normal file
5
packages/babel-generator/test/fixtures/flow/this-types/actual.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
bar(): this {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
5
packages/babel-generator/test/fixtures/flow/this-types/expected.js
vendored
Normal file
5
packages/babel-generator/test/fixtures/flow/this-types/expected.js
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
class Foo {
|
||||
bar(): this {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@ -174,6 +174,11 @@ defineType("StringTypeAnnotation", {
|
||||
}
|
||||
});
|
||||
|
||||
defineType("ThisTypeAnnotation", {
|
||||
aliases: ["Flow", "FlowBaseAnnotation"],
|
||||
fields: {}
|
||||
});
|
||||
|
||||
defineType("TupleTypeAnnotation", {
|
||||
visitor: ["types"],
|
||||
aliases: ["Flow"],
|
||||
|
||||
@ -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();
|
||||
|
||||
1
packages/babylon/test/fixtures/flow/type-annotations/100/actual.js
vendored
Normal file
1
packages/babylon/test/fixtures/flow/type-annotations/100/actual.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
class Foo { bar():this { return this; }}
|
||||
200
packages/babylon/test/fixtures/flow/type-annotations/100/expected.json
vendored
Normal file
200
packages/babylon/test/fixtures/flow/type-annotations/100/expected.json
vendored
Normal file
@ -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": []
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user