diff --git a/packages/babel-generator/src/generators/flow.ts b/packages/babel-generator/src/generators/flow.ts index 587d3fcb85dd..25a5c33184fb 100644 --- a/packages/babel-generator/src/generators/flow.ts +++ b/packages/babel-generator/src/generators/flow.ts @@ -289,6 +289,18 @@ export function FunctionTypeAnnotation( ) { this.print(node.typeParameters, node); this.token("("); + + if (node.this) { + this.word("this"); + this.token(":"); + this.space(); + this.print(node.this.typeAnnotation, node); + if (node.params.length || node.rest) { + this.token(","); + this.space(); + } + } + this.printList(node.params, node); if (node.rest) { diff --git a/packages/babel-generator/test/fixtures/flow/this-param/input.js b/packages/babel-generator/test/fixtures/flow/this-param/input.js new file mode 100644 index 000000000000..deac524b714b --- /dev/null +++ b/packages/babel-generator/test/fixtures/flow/this-param/input.js @@ -0,0 +1,45 @@ +function one (this : number) {} +function two (this : number, a) {} +function three (this : number, ...a) {} +function four (this : number, a, b, ...c) {} +function five (this : T) {} + +type six = (this : number) => void +type seven = (this : number, a : number) => void +type eight = (this : number, ...a : any) => void +type nine = (this : T) => void + +type ten = { + m1(this : string) : void, + m2(this : string, a : number) : void, + m3(this : string, ...a : any) : void, + m4(this : T) : void +} + +declare function eleven (this : number) : void +declare function twelve (this : string, a : number) : void +declare function thirteen (this : string, ...a : any) : void +declare function fourteen(this : T) : void + +declare class Fifteen { + m1(this : string) : void, + m2(this : string, a : number) : void, + m3(this : string, ...a : any) : void, + m4(this : T) : void +} + +class Sixteen { + m1 (this : number) {} + m2 (this : number, a) {} + m3 (this : number, ...a) {} + m4 (this : number, a, b, ...c) {} + m5 (this : T) {} +} + +let seventeen = { + m1 (this : number) {}, + m2 (this : number, a) {}, + m3 (this : number, ...a) {}, + m4 (this : number, a, b, ...c) {}, + m5 (this : T) {} +} diff --git a/packages/babel-generator/test/fixtures/flow/this-param/output.js b/packages/babel-generator/test/fixtures/flow/this-param/output.js new file mode 100644 index 000000000000..6f10af88264b --- /dev/null +++ b/packages/babel-generator/test/fixtures/flow/this-param/output.js @@ -0,0 +1,56 @@ +function one(this: number) {} + +function two(this: number, a) {} + +function three(this: number, ...a) {} + +function four(this: number, a, b, ...c) {} + +function five(this: T) {} + +type six = (this: number) => void; +type seven = (this: number, a: number) => void; +type eight = (this: number, ...a: any) => void; +type nine = (this: T) => void; +type ten = { + m1(this: string): void, + m2(this: string, a: number): void, + m3(this: string, ...a: any): void, + m4(this: T): void, +}; +declare function eleven(this: number): void; +declare function twelve(this: string, a: number): void; +declare function thirteen(this: string, ...a: any): void; +declare function fourteen(this: T): void; +declare class Fifteen { + m1(this: string): void, + m2(this: string, a: number): void, + m3(this: string, ...a: any): void, + m4(this: T): void, +} + +class Sixteen { + m1(this: number) {} + + m2(this: number, a) {} + + m3(this: number, ...a) {} + + m4(this: number, a, b, ...c) {} + + m5(this: T) {} + +} + +let seventeen = { + m1(this: number) {}, + + m2(this: number, a) {}, + + m3(this: number, ...a) {}, + + m4(this: number, a, b, ...c) {}, + + m5(this: T) {} + +}; \ No newline at end of file diff --git a/packages/babel-parser/src/plugins/flow/index.js b/packages/babel-parser/src/plugins/flow/index.js index 0f606cfd35fa..2df5a06a9ad1 100644 --- a/packages/babel-parser/src/plugins/flow/index.js +++ b/packages/babel-parser/src/plugins/flow/index.js @@ -81,6 +81,7 @@ const FlowErrors = Object.freeze({ "Number enum members need to be initialized, e.g. `%1 = 1` in enum `%0`.", EnumStringMemberInconsistentlyInitailized: "String enum members need to consistently either all use initializers, or use no initializers, in enum `%0`.", + GetterMayNotHaveThisParam: "A getter cannot have a `this` parameter.", ImportTypeShorthandOnlyInPureImport: "The `type` and `typeof` keywords on named imports can only be used on regular `import` statements. It cannot be used with `import type` or `import typeof` statements", InexactInsideExact: @@ -97,7 +98,16 @@ const FlowErrors = Object.freeze({ NestedFlowComment: "Cannot have a flow comment inside another flow comment", OptionalBindingPattern: "A binding pattern parameter cannot be optional in an implementation signature.", + SetterMayNotHaveThisParam: "A setter cannot have a `this` parameter.", SpreadVariance: "Spread properties cannot have variance", + ThisParamAnnotationRequired: + "A type annotation is required for the `this` parameter.", + ThisParamBannedInConstructor: + "Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions.", + ThisParamMayNotBeOptional: "The `this` parameter cannot be optional.", + ThisParamMustBeFirst: + "The `this` parameter must be the first function parameter.", + ThisParamNoDefault: "The `this` parameter may not have a default value.", TypeBeforeInitializer: "Type annotations must come before default assignments, e.g. instead of `age = 25: number` use `age: number = 25`", TypeCastInPattern: @@ -308,6 +318,7 @@ export default (superClass: Class): Class => const tmp = this.flowParseFunctionTypeParams(); typeNode.params = tmp.params; typeNode.rest = tmp.rest; + typeNode.this = tmp._this; this.expect(tt.parenR); [ @@ -905,21 +916,30 @@ export default (superClass: Class): Class => node.params = []; node.rest = null; node.typeParameters = null; + node.this = null; if (this.isRelational("<")) { node.typeParameters = this.flowParseTypeParameterDeclaration(); } this.expect(tt.parenL); + if (this.match(tt._this)) { + node.this = this.flowParseFunctionTypeParam(/* first */ true); + // match Flow parser behavior + node.this.name = null; + if (!this.match(tt.parenR)) { + this.expect(tt.comma); + } + } while (!this.match(tt.parenR) && !this.match(tt.ellipsis)) { - node.params.push(this.flowParseFunctionTypeParam()); + node.params.push(this.flowParseFunctionTypeParam(false)); if (!this.match(tt.parenR)) { this.expect(tt.comma); } } if (this.eat(tt.ellipsis)) { - node.rest = this.flowParseFunctionTypeParam(); + node.rest = this.flowParseFunctionTypeParam(false); } this.expect(tt.parenR); node.returnType = this.flowParseTypeInitialiser(); @@ -1162,6 +1182,17 @@ export default (superClass: Class): Class => if (kind === "get" || kind === "set") { this.flowCheckGetterSetterParams(node); } + /** Declared classes/interfaces do not allow spread */ + if ( + !allowSpread && + node.key.name === "constructor" && + node.value.this + ) { + this.raise( + node.value.this.start, + FlowErrors.ThisParamBannedInConstructor, + ); + } } else { if (kind !== "init") this.unexpected(); @@ -1189,6 +1220,16 @@ export default (superClass: Class): Class => const start = property.start; const length = property.value.params.length + (property.value.rest ? 1 : 0); + + if (property.value.this) { + this.raise( + property.value.this.start, + property.kind === "get" + ? FlowErrors.GetterMayNotHaveThisParam + : FlowErrors.SetterMayNotHaveThisParam, + ); + } + if (length !== paramCount) { if (property.kind === "get") { this.raise(start, Errors.BadGetterArity); @@ -1270,16 +1311,24 @@ export default (superClass: Class): Class => return this.finishNode(node, "TupleTypeAnnotation"); } - flowParseFunctionTypeParam(): N.FlowFunctionTypeParam { + flowParseFunctionTypeParam(first: boolean): N.FlowFunctionTypeParam { let name = null; let optional = false; let typeAnnotation = null; const node = this.startNode(); const lh = this.lookahead(); + const isThis = this.state.type === tt._this; + if (lh.type === tt.colon || lh.type === tt.question) { - name = this.parseIdentifier(); + if (isThis && !first) { + this.raise(node.start, FlowErrors.ThisParamMustBeFirst); + } + name = this.parseIdentifier(isThis); if (this.eat(tt.question)) { optional = true; + if (isThis) { + this.raise(node.start, FlowErrors.ThisParamMayNotBeOptional); + } } typeAnnotation = this.flowParseTypeInitialiser(); } else { @@ -1303,18 +1352,31 @@ export default (superClass: Class): Class => flowParseFunctionTypeParams( params: N.FlowFunctionTypeParam[] = [], - ): { params: N.FlowFunctionTypeParam[], rest: ?N.FlowFunctionTypeParam } { + ): { + params: N.FlowFunctionTypeParam[], + rest: ?N.FlowFunctionTypeParam, + _this: ?N.FlowFunctionTypeParam, + } { let rest: ?N.FlowFunctionTypeParam = null; + let _this: ?N.FlowFunctionTypeParam = null; + if (this.match(tt._this)) { + _this = this.flowParseFunctionTypeParam(/* first */ true); + // match Flow parser behavior + _this.name = null; + if (!this.match(tt.parenR)) { + this.expect(tt.comma); + } + } while (!this.match(tt.parenR) && !this.match(tt.ellipsis)) { - params.push(this.flowParseFunctionTypeParam()); + params.push(this.flowParseFunctionTypeParam(false)); if (!this.match(tt.parenR)) { this.expect(tt.comma); } } if (this.eat(tt.ellipsis)) { - rest = this.flowParseFunctionTypeParam(); + rest = this.flowParseFunctionTypeParam(false); } - return { params, rest }; + return { params, rest, _this }; } flowIdentToTypeAnnotation( @@ -1408,6 +1470,7 @@ export default (superClass: Class): Class => tmp = this.flowParseFunctionTypeParams(); node.params = tmp.params; node.rest = tmp.rest; + node.this = tmp._this; this.expect(tt.parenR); this.expect(tt.arrow); @@ -1423,7 +1486,7 @@ export default (superClass: Class): Class => // Check to see if this is actually a grouped type if (!this.match(tt.parenR) && !this.match(tt.ellipsis)) { - if (this.match(tt.name)) { + if (this.match(tt.name) || this.match(tt._this)) { const token = this.lookahead().type; isGroupedType = token !== tt.question && token !== tt.colon; } else { @@ -1462,6 +1525,7 @@ export default (superClass: Class): Class => node.params = tmp.params; node.rest = tmp.rest; + node.this = tmp._this; this.expect(tt.parenR); @@ -2311,6 +2375,11 @@ export default (superClass: Class): Class => return !this.match(tt.colon) && super.isNonstaticConstructor(method); } + // determine whether a parameter is a this param + isThisParam(param) { + return param.type === "Identifier" && param.name === "this"; + } + // parse type parameters for class methods pushClassMethod( classBody: N.ClassBody, @@ -2336,6 +2405,24 @@ export default (superClass: Class): Class => isConstructor, allowsDirectSuper, ); + + if (method.params && isConstructor) { + const params = method.params; + if (params.length > 0 && this.isThisParam(params[0])) { + this.raise(method.start, FlowErrors.ThisParamBannedInConstructor); + } + // estree support + } else if ( + // $FlowFixMe flow does not know about the face that estree can replace ClassMethod with MethodDefinition + method.type === "MethodDefinition" && + isConstructor && + method.value.params + ) { + const params = method.value.params; + if (params.length > 0 && this.isThisParam(params[0])) { + this.raise(method.start, FlowErrors.ThisParamBannedInConstructor); + } + } } pushClassPrivateMethod( @@ -2377,6 +2464,19 @@ export default (superClass: Class): Class => } } + checkGetterSetterParams(method: N.ObjectMethod | N.ClassMethod): void { + super.checkGetterSetterParams(method); + const params = this.getObjectOrClassMethodParams(method); + if (params.length > 0) { + const param = params[0]; + if (this.isThisParam(param) && method.kind === "get") { + this.raise(param.start, FlowErrors.GetterMayNotHaveThisParam); + } else if (this.isThisParam(param)) { + this.raise(param.start, FlowErrors.SetterMayNotHaveThisParam); + } + } + } + parsePropertyName( node: N.ObjectOrClassMember | N.ClassMember | N.TsNamedTypeElementBase, isPrivateNameAllowed: boolean, @@ -2434,12 +2534,22 @@ export default (superClass: Class): Class => if (param.type !== "Identifier") { this.raise(param.start, FlowErrors.OptionalBindingPattern); } + if (this.isThisParam(param)) { + this.raise(param.start, FlowErrors.ThisParamMayNotBeOptional); + } ((param: any): N.Identifier).optional = true; } if (this.match(tt.colon)) { param.typeAnnotation = this.flowParseTypeAnnotation(); + } else if (this.isThisParam(param)) { + this.raise(param.start, FlowErrors.ThisParamAnnotationRequired); } + + if (this.match(tt.eq) && this.isThisParam(param)) { + this.raise(param.start, FlowErrors.ThisParamNoDefault); + } + this.resetEndLocation(param); return param; } @@ -2609,6 +2719,16 @@ export default (superClass: Class): Class => node.specifiers.push(this.finishNode(specifier, "ImportSpecifier")); } + parseBindingAtom(): N.Pattern { + switch (this.state.type) { + case tt._this: + // "this" may be the name of a parameter, so allow it. + return this.parseIdentifier(/* liberal */ true); + default: + return super.parseBindingAtom(); + } + } + // parse function type parameters - function foo() {} parseFunctionParams(node: N.Function, allowModifiers?: boolean): void { // $FlowFixMe @@ -2866,6 +2986,13 @@ export default (superClass: Class): Class => return; } + // ensure the `this` param is first, if it exists + for (let i = 0; i < node.params.length; i++) { + if (this.isThisParam(node.params[i]) && i > 0) { + this.raise(node.params[i].start, FlowErrors.ThisParamMustBeFirst); + } + } + return super.checkParams(...arguments); } diff --git a/packages/babel-parser/test/fixtures/estree/object-method/invalid-setter/output.json b/packages/babel-parser/test/fixtures/estree/object-method/invalid-setter/output.json index bba388a4344b..98c7c647bf60 100644 --- a/packages/babel-parser/test/fixtures/estree/object-method/invalid-setter/output.json +++ b/packages/babel-parser/test/fixtures/estree/object-method/invalid-setter/output.json @@ -16,6 +16,10 @@ "expression": { "type": "ObjectExpression", "start":1,"end":14,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":14}}, + "extra": { + "parenthesized": true, + "parenStart": 0 + }, "properties": [ { "type": "Property", @@ -44,11 +48,7 @@ }, "shorthand": false } - ], - "extra": { - "parenthesized": true, - "parenStart": 0 - } + ] } } ] diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_10/output.json b/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_10/output.json index 33e95403e790..5e4a04fcf81c 100644 --- a/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_10/output.json +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_10/output.json @@ -50,6 +50,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":32,"end":38,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":38}} diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_14/output.json b/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_14/output.json index eadc2d985387..67e57a7f761b 100644 --- a/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_14/output.json +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_14/output.json @@ -39,6 +39,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":27,"end":33,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":33}} diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_15/output.json b/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_15/output.json index 64a149197c0c..cb3951a318b8 100644 --- a/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_15/output.json +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-no-parens-types/good_15/output.json @@ -49,6 +49,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":30,"end":36,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":36}} diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_01/output.json b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_01/output.json index 00814ac01665..7e1547e59980 100644 --- a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_01/output.json +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_01/output.json @@ -48,6 +48,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":41,"end":45,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":45}} diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_03/output.json b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_03/output.json index 8dcd1b0be60d..908fb3b42679 100644 --- a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_03/output.json +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_03/output.json @@ -32,6 +32,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":21,"end":25,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":25}} diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_04/output.json b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_04/output.json index 5dc10956fa1f..ed6189670eb8 100644 --- a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_04/output.json +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_04/output.json @@ -32,6 +32,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":22,"end":26,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":26}} diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_05/output.json b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_05/output.json index 0125e6307fa9..3ec32b39779b 100644 --- a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_05/output.json +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_05/output.json @@ -47,6 +47,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":28,"end":32,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":32}} diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_06/output.json b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_06/output.json index c8e969c81806..76bacf075852 100644 --- a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_06/output.json +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_06/output.json @@ -47,6 +47,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":29,"end":33,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":33}} diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_07/output.json b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_07/output.json index 9441e11a5d82..951c19736c73 100644 --- a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_07/output.json +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_07/output.json @@ -46,6 +46,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":32,"end":36,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":36}} diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_08/output.json b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_08/output.json index c39333b8861f..68b0835fdf42 100644 --- a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_08/output.json +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_08/output.json @@ -45,6 +45,7 @@ } } }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":31,"end":35,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":35}} diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_09/output.json b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_09/output.json index 7e3230844ebd..2c15f4a41e65 100644 --- a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_09/output.json +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_09/output.json @@ -71,6 +71,7 @@ } } }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":46,"end":50,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":50}} diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_10/output.json b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_10/output.json index 316359169e24..5f7e4b48271b 100644 --- a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_10/output.json +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_10/output.json @@ -46,6 +46,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "NumberLiteralTypeAnnotation", "start":28,"end":31,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":31}}, diff --git a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_13/output.json b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_13/output.json index 0aba1cc06f66..536676cd3770 100644 --- a/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_13/output.json +++ b/packages/babel-parser/test/fixtures/flow/anonymous-function-types/good_13/output.json @@ -42,6 +42,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "NumberLiteralTypeAnnotation", "start":26,"end":29,"loc":{"start":{"line":1,"column":26},"end":{"line":1,"column":29}}, diff --git a/packages/babel-parser/test/fixtures/flow/array-types/4/output.json b/packages/babel-parser/test/fixtures/flow/array-types/4/output.json index 7d395e92050c..909ca9cce01e 100644 --- a/packages/babel-parser/test/fixtures/flow/array-types/4/output.json +++ b/packages/babel-parser/test/fixtures/flow/array-types/4/output.json @@ -26,6 +26,7 @@ "start":7,"end":21,"loc":{"start":{"line":1,"column":7},"end":{"line":1,"column":21}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "ArrayTypeAnnotation", "start":13,"end":21,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":21}}, diff --git a/packages/babel-parser/test/fixtures/flow/array-types/5/output.json b/packages/babel-parser/test/fixtures/flow/array-types/5/output.json index f6fbb173576b..b38fb7bf0525 100644 --- a/packages/babel-parser/test/fixtures/flow/array-types/5/output.json +++ b/packages/babel-parser/test/fixtures/flow/array-types/5/output.json @@ -29,6 +29,7 @@ "start":8,"end":20,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":20}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":14,"end":20,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":20}} diff --git a/packages/babel-parser/test/fixtures/flow/call-properties/1/output.json b/packages/babel-parser/test/fixtures/flow/call-properties/1/output.json index 225c82bca9dc..812bbf31ad88 100644 --- a/packages/babel-parser/test/fixtures/flow/call-properties/1/output.json +++ b/packages/babel-parser/test/fixtures/flow/call-properties/1/output.json @@ -35,6 +35,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":14,"end":20,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":20}} diff --git a/packages/babel-parser/test/fixtures/flow/call-properties/2/output.json b/packages/babel-parser/test/fixtures/flow/call-properties/2/output.json index 7c3d10f344ce..9fc09769bee6 100644 --- a/packages/babel-parser/test/fixtures/flow/call-properties/2/output.json +++ b/packages/babel-parser/test/fixtures/flow/call-properties/2/output.json @@ -35,6 +35,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":14,"end":20,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":20}} diff --git a/packages/babel-parser/test/fixtures/flow/call-properties/3/output.json b/packages/babel-parser/test/fixtures/flow/call-properties/3/output.json index 84334ba4a90d..4b1644494a45 100644 --- a/packages/babel-parser/test/fixtures/flow/call-properties/3/output.json +++ b/packages/babel-parser/test/fixtures/flow/call-properties/3/output.json @@ -35,6 +35,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":14,"end":20,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":20}} @@ -66,6 +67,7 @@ ], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "StringTypeAnnotation", "start":46,"end":52,"loc":{"start":{"line":1,"column":46},"end":{"line":1,"column":52}} diff --git a/packages/babel-parser/test/fixtures/flow/call-properties/4/output.json b/packages/babel-parser/test/fixtures/flow/call-properties/4/output.json index 3f664920aa97..086f5b45d748 100644 --- a/packages/babel-parser/test/fixtures/flow/call-properties/4/output.json +++ b/packages/babel-parser/test/fixtures/flow/call-properties/4/output.json @@ -67,6 +67,7 @@ } ] }, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":21,"end":27,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":27}} diff --git a/packages/babel-parser/test/fixtures/flow/call-properties/5/output.json b/packages/babel-parser/test/fixtures/flow/call-properties/5/output.json index 891892e2f708..118b6d1a088e 100644 --- a/packages/babel-parser/test/fixtures/flow/call-properties/5/output.json +++ b/packages/babel-parser/test/fixtures/flow/call-properties/5/output.json @@ -33,6 +33,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":18,"end":24,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":24}} diff --git a/packages/babel-parser/test/fixtures/flow/class-properties/getter-setter/output.json b/packages/babel-parser/test/fixtures/flow/class-properties/getter-setter/output.json index f35d695d38ca..46c34ef53135 100644 --- a/packages/babel-parser/test/fixtures/flow/class-properties/getter-setter/output.json +++ b/packages/babel-parser/test/fixtures/flow/class-properties/getter-setter/output.json @@ -42,6 +42,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":29,"end":35,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":17}} @@ -82,6 +83,7 @@ ], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":57,"end":61,"loc":{"start":{"line":3,"column":20},"end":{"line":3,"column":24}} @@ -111,6 +113,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":76,"end":82,"loc":{"start":{"line":4,"column":13},"end":{"line":4,"column":19}} @@ -155,6 +158,7 @@ ], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":106,"end":110,"loc":{"start":{"line":5,"column":22},"end":{"line":5,"column":26}} @@ -184,6 +188,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":123,"end":129,"loc":{"start":{"line":6,"column":11},"end":{"line":6,"column":17}} @@ -228,6 +233,7 @@ ], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":151,"end":155,"loc":{"start":{"line":7,"column":20},"end":{"line":7,"column":24}} diff --git a/packages/babel-parser/test/fixtures/flow/classes/constructor-override-with-class-prop-plugin/output.json b/packages/babel-parser/test/fixtures/flow/classes/constructor-override-with-class-prop-plugin/output.json index e7dba971db17..078602d8aced 100644 --- a/packages/babel-parser/test/fixtures/flow/classes/constructor-override-with-class-prop-plugin/output.json +++ b/packages/babel-parser/test/fixtures/flow/classes/constructor-override-with-class-prop-plugin/output.json @@ -42,6 +42,7 @@ "start":27,"end":37,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":25}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "ThisTypeAnnotation", "start":33,"end":37,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":25}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-export/export-class/output.json b/packages/babel-parser/test/fixtures/flow/declare-export/export-class/output.json index 7e96f7035a5f..b2ef70379a47 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-export/export-class/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-export/export-class/output.json @@ -76,6 +76,7 @@ ], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":68,"end":72,"loc":{"start":{"line":1,"column":68},"end":{"line":1,"column":72}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-export/export-default-arrow/output.json b/packages/babel-parser/test/fixtures/flow/declare-export/export-default-arrow/output.json index f479dcf7f189..1b6d2b652995 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-export/export-default-arrow/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-export/export-default-arrow/output.json @@ -30,6 +30,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":37,"end":43,"loc":{"start":{"line":1,"column":37},"end":{"line":1,"column":43}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-export/export-default-function/output.json b/packages/babel-parser/test/fixtures/flow/declare-export/export-default-function/output.json index 670fd3f48b4f..9f6fe31dd5f7 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-export/export-default-function/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-export/export-default-function/output.json @@ -41,6 +41,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "StringTypeAnnotation", "start":49,"end":55,"loc":{"start":{"line":1,"column":49},"end":{"line":1,"column":55}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-export/export-function/output.json b/packages/babel-parser/test/fixtures/flow/declare-export/export-function/output.json index db29c7c10d2b..b9bdc4a556d1 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-export/export-function/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-export/export-function/output.json @@ -57,6 +57,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "StringTypeAnnotation", "start":64,"end":70,"loc":{"start":{"line":1,"column":64},"end":{"line":1,"column":70}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-module/10/output.json b/packages/babel-parser/test/fixtures/flow/declare-module/10/output.json index ffea09887f0f..e360b80f3b80 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-module/10/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-module/10/output.json @@ -36,6 +36,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":33,"end":39,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":39}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-module/4/output.json b/packages/babel-parser/test/fixtures/flow/declare-module/4/output.json index 4815b5f5dc06..31d82465a5dc 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-module/4/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-module/4/output.json @@ -35,6 +35,7 @@ "typeParameters": null, "params": [], "rest": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":43,"end":49,"loc":{"start":{"line":1,"column":43},"end":{"line":1,"column":49}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-module/5/output.json b/packages/babel-parser/test/fixtures/flow/declare-module/5/output.json index 20e04284533f..b4a8c7abe620 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-module/5/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-module/5/output.json @@ -54,6 +54,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":44,"end":50,"loc":{"start":{"line":1,"column":44},"end":{"line":1,"column":50}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-module/6/output.json b/packages/babel-parser/test/fixtures/flow/declare-module/6/output.json index dcc3dbe0267f..b1e3e5d06ab9 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-module/6/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-module/6/output.json @@ -48,6 +48,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":52,"end":58,"loc":{"start":{"line":1,"column":52},"end":{"line":1,"column":58}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-statements/10/output.json b/packages/babel-parser/test/fixtures/flow/declare-statements/10/output.json index 06a5d571ff09..921856f92729 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-statements/10/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-statements/10/output.json @@ -42,6 +42,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":32,"end":38,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":38}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-statements/12/output.json b/packages/babel-parser/test/fixtures/flow/declare-statements/12/output.json index 63f60d28b1b1..beff50dce45d 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-statements/12/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-statements/12/output.json @@ -33,6 +33,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":30,"end":36,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":36}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-statements/18/output.json b/packages/babel-parser/test/fixtures/flow/declare-statements/18/output.json index faab69fb629c..bae862069da6 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-statements/18/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-statements/18/output.json @@ -33,6 +33,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":30,"end":36,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":36}} @@ -72,6 +73,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":62,"end":68,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":29}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-statements/3/output.json b/packages/babel-parser/test/fixtures/flow/declare-statements/3/output.json index 64089206d0c7..bd3076f29bd3 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-statements/3/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-statements/3/output.json @@ -23,6 +23,7 @@ "typeParameters": null, "params": [], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":24,"end":28,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":28}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-statements/4/output.json b/packages/babel-parser/test/fixtures/flow/declare-statements/4/output.json index f377b44c81af..d3af8971977e 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-statements/4/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-statements/4/output.json @@ -23,6 +23,7 @@ "typeParameters": null, "params": [], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":24,"end":28,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":28}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-statements/5/output.json b/packages/babel-parser/test/fixtures/flow/declare-statements/5/output.json index 033bfd0bfc02..8fb724f7edac 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-statements/5/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-statements/5/output.json @@ -34,6 +34,7 @@ }, "params": [], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":27,"end":31,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":31}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-statements/6/output.json b/packages/babel-parser/test/fixtures/flow/declare-statements/6/output.json index 7a8d40112005..e7a071e81948 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-statements/6/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-statements/6/output.json @@ -52,6 +52,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":44,"end":48,"loc":{"start":{"line":1,"column":44},"end":{"line":1,"column":48}} diff --git a/packages/babel-parser/test/fixtures/flow/declare-statements/7/output.json b/packages/babel-parser/test/fixtures/flow/declare-statements/7/output.json index e5ae7dd2d318..8f4a842da29a 100644 --- a/packages/babel-parser/test/fixtures/flow/declare-statements/7/output.json +++ b/packages/babel-parser/test/fixtures/flow/declare-statements/7/output.json @@ -77,6 +77,7 @@ ], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":67,"end":71,"loc":{"start":{"line":1,"column":67},"end":{"line":1,"column":71}} diff --git a/packages/babel-parser/test/fixtures/flow/interface-types/identifier-named-static-method/output.json b/packages/babel-parser/test/fixtures/flow/interface-types/identifier-named-static-method/output.json index db1accdec445..e6b9035c5bc4 100644 --- a/packages/babel-parser/test/fixtures/flow/interface-types/identifier-named-static-method/output.json +++ b/packages/babel-parser/test/fixtures/flow/interface-types/identifier-named-static-method/output.json @@ -43,6 +43,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":31,"end":37,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":37}} diff --git a/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/10/output.json b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/10/output.json index 08a97862a7d3..85dc1ab0ac20 100644 --- a/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/10/output.json +++ b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/10/output.json @@ -61,6 +61,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":44,"end":48,"loc":{"start":{"line":3,"column":13},"end":{"line":3,"column":17}} diff --git a/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/4/output.json b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/4/output.json index a4261a11c12a..c779878f81e7 100644 --- a/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/4/output.json +++ b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/4/output.json @@ -41,6 +41,7 @@ "start":19,"end":31,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":31}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":25,"end":31,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":31}} diff --git a/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/identifier-named-static-method/output.json b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/identifier-named-static-method/output.json index b0834548218e..eac134286c30 100644 --- a/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/identifier-named-static-method/output.json +++ b/packages/babel-parser/test/fixtures/flow/interfaces-module-and-script/identifier-named-static-method/output.json @@ -42,6 +42,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":24,"end":30,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":30}} diff --git a/packages/babel-parser/test/fixtures/flow/internal-slot/interface-method/output.json b/packages/babel-parser/test/fixtures/flow/internal-slot/interface-method/output.json index 285585f5d6ac..e61dc7bd653e 100644 --- a/packages/babel-parser/test/fixtures/flow/internal-slot/interface-method/output.json +++ b/packages/babel-parser/test/fixtures/flow/internal-slot/interface-method/output.json @@ -43,6 +43,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "GenericTypeAnnotation", "start":25,"end":26,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":26}}, diff --git a/packages/babel-parser/test/fixtures/flow/internal-slot/object-method/output.json b/packages/babel-parser/test/fixtures/flow/internal-slot/object-method/output.json index 16491604be46..51061a05eb63 100644 --- a/packages/babel-parser/test/fixtures/flow/internal-slot/object-method/output.json +++ b/packages/babel-parser/test/fixtures/flow/internal-slot/object-method/output.json @@ -40,6 +40,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "GenericTypeAnnotation", "start":22,"end":23,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":23}}, diff --git a/packages/babel-parser/test/fixtures/flow/iterator/01/output.json b/packages/babel-parser/test/fixtures/flow/iterator/01/output.json index 9cf79269df16..f606edd83516 100644 --- a/packages/babel-parser/test/fixtures/flow/iterator/01/output.json +++ b/packages/babel-parser/test/fixtures/flow/iterator/01/output.json @@ -42,6 +42,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "GenericTypeAnnotation", "start":34,"end":48,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":30}}, diff --git a/packages/babel-parser/test/fixtures/flow/iterator/02/output.json b/packages/babel-parser/test/fixtures/flow/iterator/02/output.json index 91a02b2c7369..764bc1651365 100644 --- a/packages/babel-parser/test/fixtures/flow/iterator/02/output.json +++ b/packages/babel-parser/test/fixtures/flow/iterator/02/output.json @@ -42,6 +42,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "GenericTypeAnnotation", "start":39,"end":53,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":35}}, diff --git a/packages/babel-parser/test/fixtures/flow/iterator/12/output.json b/packages/babel-parser/test/fixtures/flow/iterator/12/output.json index c8866d697474..75fcbeb9c06d 100644 --- a/packages/babel-parser/test/fixtures/flow/iterator/12/output.json +++ b/packages/babel-parser/test/fixtures/flow/iterator/12/output.json @@ -44,6 +44,7 @@ "start":30,"end":42,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":42}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "StringTypeAnnotation", "start":36,"end":42,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":42}} @@ -70,6 +71,10 @@ "argument": { "type": "TypeCastExpression", "start":57,"end":63,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":16}}, + "extra": { + "parenthesized": true, + "parenStart": 56 + }, "expression": { "type": "NumericLiteral", "start":57,"end":58,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11}}, @@ -86,10 +91,6 @@ "type": "AnyTypeAnnotation", "start":60,"end":63,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":16}} } - }, - "extra": { - "parenthesized": true, - "parenStart": 56 } } } diff --git a/packages/babel-parser/test/fixtures/flow/iterator/13/output.json b/packages/babel-parser/test/fixtures/flow/iterator/13/output.json index 3d995d3398b7..a7d70847b527 100644 --- a/packages/babel-parser/test/fixtures/flow/iterator/13/output.json +++ b/packages/babel-parser/test/fixtures/flow/iterator/13/output.json @@ -44,6 +44,7 @@ "start":35,"end":47,"loc":{"start":{"line":1,"column":35},"end":{"line":1,"column":47}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "StringTypeAnnotation", "start":41,"end":47,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":47}} @@ -70,6 +71,10 @@ "argument": { "type": "TypeCastExpression", "start":62,"end":68,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":16}}, + "extra": { + "parenthesized": true, + "parenStart": 61 + }, "expression": { "type": "NumericLiteral", "start":62,"end":63,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":11}}, @@ -86,10 +91,6 @@ "type": "AnyTypeAnnotation", "start":65,"end":68,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":16}} } - }, - "extra": { - "parenthesized": true, - "parenStart": 61 } } } diff --git a/packages/babel-parser/test/fixtures/flow/iterator/14/output.json b/packages/babel-parser/test/fixtures/flow/iterator/14/output.json index 3e8644cc75b6..a511d794d29b 100644 --- a/packages/babel-parser/test/fixtures/flow/iterator/14/output.json +++ b/packages/babel-parser/test/fixtures/flow/iterator/14/output.json @@ -42,6 +42,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "GenericTypeAnnotation", "start":30,"end":44,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":30}}, diff --git a/packages/babel-parser/test/fixtures/flow/iterator/15/output.json b/packages/babel-parser/test/fixtures/flow/iterator/15/output.json index d88ede13e992..d9ce5b890371 100644 --- a/packages/babel-parser/test/fixtures/flow/iterator/15/output.json +++ b/packages/babel-parser/test/fixtures/flow/iterator/15/output.json @@ -42,6 +42,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "GenericTypeAnnotation", "start":35,"end":49,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":35}}, diff --git a/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-function/output.json b/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-function/output.json index f9915cba13fe..b1265cceb647 100644 --- a/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-function/output.json +++ b/packages/babel-parser/test/fixtures/flow/multiple-declarations/declare-function/output.json @@ -23,6 +23,7 @@ "typeParameters": null, "params": [], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":23,"end":27,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":27}} @@ -48,6 +49,7 @@ "typeParameters": null, "params": [], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":51,"end":55,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":27}} diff --git a/packages/babel-parser/test/fixtures/flow/object-types/complex-param-types/output.json b/packages/babel-parser/test/fixtures/flow/object-types/complex-param-types/output.json index 948d1edb1a7a..7d0f9faf2d11 100644 --- a/packages/babel-parser/test/fixtures/flow/object-types/complex-param-types/output.json +++ b/packages/babel-parser/test/fixtures/flow/object-types/complex-param-types/output.json @@ -66,6 +66,7 @@ ], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":25,"end":29,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":29}} diff --git a/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count-rest/output.json b/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count-rest/output.json index e100d1aafcfe..200019bb51bd 100644 --- a/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count-rest/output.json +++ b/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count-rest/output.json @@ -57,6 +57,7 @@ } }, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":28,"end":34,"loc":{"start":{"line":2,"column":17},"end":{"line":2,"column":23}} diff --git a/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count/output.json b/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count/output.json index 0c62673bf17e..d98c7d2c4130 100644 --- a/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count/output.json +++ b/packages/babel-parser/test/fixtures/flow/object-types/invalid-getter-param-count/output.json @@ -57,6 +57,7 @@ ], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":32,"end":38,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":27}} diff --git a/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-count/output.json b/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-count/output.json index 345f3c0c34f3..fa18c3c235cd 100644 --- a/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-count/output.json +++ b/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-count/output.json @@ -42,6 +42,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":22,"end":26,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":15}} diff --git a/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-type/output.json b/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-type/output.json index 07259bb3363e..b2207b3a6f28 100644 --- a/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-type/output.json +++ b/packages/babel-parser/test/fixtures/flow/object-types/invalid-setter-param-type/output.json @@ -57,6 +57,7 @@ } }, "typeParameters": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":26,"end":30,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":19}} diff --git a/packages/babel-parser/test/fixtures/flow/predicates/1/output.json b/packages/babel-parser/test/fixtures/flow/predicates/1/output.json index bd9ce6276726..6ff5da59cb69 100644 --- a/packages/babel-parser/test/fixtures/flow/predicates/1/output.json +++ b/packages/babel-parser/test/fixtures/flow/predicates/1/output.json @@ -38,6 +38,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "BooleanTypeAnnotation", "start":32,"end":39,"loc":{"start":{"line":1,"column":32},"end":{"line":1,"column":39}} diff --git a/packages/babel-parser/test/fixtures/flow/predicates/6/output.json b/packages/babel-parser/test/fixtures/flow/predicates/6/output.json index e3602f7e23c7..2300a1b2991e 100644 --- a/packages/babel-parser/test/fixtures/flow/predicates/6/output.json +++ b/packages/babel-parser/test/fixtures/flow/predicates/6/output.json @@ -124,6 +124,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "GenericTypeAnnotation", "start":64,"end":85,"loc":{"start":{"line":1,"column":64},"end":{"line":1,"column":85}}, diff --git a/packages/babel-parser/test/fixtures/flow/regression/issue-321/output.json b/packages/babel-parser/test/fixtures/flow/regression/issue-321/output.json index 0c22b938a43e..f2be47a37da1 100644 --- a/packages/babel-parser/test/fixtures/flow/regression/issue-321/output.json +++ b/packages/babel-parser/test/fixtures/flow/regression/issue-321/output.json @@ -63,6 +63,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":33,"end":37,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":37}} @@ -155,6 +156,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":93,"end":97,"loc":{"start":{"line":2,"column":35},"end":{"line":2,"column":39}} diff --git a/packages/babel-parser/test/fixtures/flow/scope/declare-function-export/output.json b/packages/babel-parser/test/fixtures/flow/scope/declare-function-export/output.json index 2e2941394998..905af01b1765 100644 --- a/packages/babel-parser/test/fixtures/flow/scope/declare-function-export/output.json +++ b/packages/babel-parser/test/fixtures/flow/scope/declare-function-export/output.json @@ -23,6 +23,7 @@ "typeParameters": null, "params": [], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":24,"end":28,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":28}} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-declare-func-declare-func/output.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-declare-func-declare-func/output.json index de9cd47bb358..6656daffab8f 100644 --- a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-declare-func-declare-func/output.json +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-declare-func-declare-func/output.json @@ -23,6 +23,7 @@ "typeParameters": null, "params": [], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":22,"end":26,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":26}} @@ -48,6 +49,7 @@ "typeParameters": null, "params": [], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":50,"end":54,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":26}} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-declare-func-declare-var/output.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-declare-func-declare-var/output.json index 27ab9b95ad66..3d0bf7fb3866 100644 --- a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-declare-func-declare-var/output.json +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-declare-func-declare-var/output.json @@ -23,6 +23,7 @@ "typeParameters": null, "params": [], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":22,"end":26,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":26}} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-declare-func-func/output.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-declare-func-func/output.json index 6895d0b4ef67..583414100a2f 100644 --- a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-declare-func-func/output.json +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-declare-func-func/output.json @@ -23,6 +23,7 @@ "typeParameters": null, "params": [], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":22,"end":26,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":26}} diff --git a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-func-declare-func/output.json b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-func-declare-func/output.json index e088b316d6c6..ac0fe1790e79 100644 --- a/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-func-declare-func/output.json +++ b/packages/babel-parser/test/fixtures/flow/scope/dupl-decl-func-declare-func/output.json @@ -44,6 +44,7 @@ "typeParameters": null, "params": [], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":38,"end":42,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":26}} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/declare-function/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/declare-function/input.js new file mode 100644 index 000000000000..a11916d5e736 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/declare-function/input.js @@ -0,0 +1,7 @@ +declare function foo (this : number, a : string, b : number) : void + +declare function bar (this : number): void + +declare function baz (this : number, ...a : any): void + +declare function qux (this : T) : void diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/declare-function/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/declare-function/output.json new file mode 100644 index 000000000000..925b7febf329 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/declare-function/output.json @@ -0,0 +1,212 @@ +{ + "type": "File", + "start":0,"end":210,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":41}}, + "program": { + "type": "Program", + "start":0,"end":210,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":41}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "DeclareFunction", + "start":0,"end":67,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":67}}, + "id": { + "type": "Identifier", + "start":17,"end":67,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":67},"identifierName":"foo"}, + "name": "foo", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":21,"end":67,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":67}}, + "typeAnnotation": { + "type": "FunctionTypeAnnotation", + "start":21,"end":67,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":67}}, + "typeParameters": null, + "params": [ + { + "type": "FunctionTypeParam", + "start":37,"end":47,"loc":{"start":{"line":1,"column":37},"end":{"line":1,"column":47}}, + "name": { + "type": "Identifier", + "start":37,"end":38,"loc":{"start":{"line":1,"column":37},"end":{"line":1,"column":38},"identifierName":"a"}, + "name": "a" + }, + "optional": false, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start":41,"end":47,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":47}} + } + }, + { + "type": "FunctionTypeParam", + "start":49,"end":59,"loc":{"start":{"line":1,"column":49},"end":{"line":1,"column":59}}, + "name": { + "type": "Identifier", + "start":49,"end":50,"loc":{"start":{"line":1,"column":49},"end":{"line":1,"column":50},"identifierName":"b"}, + "name": "b" + }, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":53,"end":59,"loc":{"start":{"line":1,"column":53},"end":{"line":1,"column":59}} + } + } + ], + "rest": null, + "this": { + "type": "FunctionTypeParam", + "start":22,"end":35,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":35}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":29,"end":35,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":35}} + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":63,"end":67,"loc":{"start":{"line":1,"column":63},"end":{"line":1,"column":67}} + } + } + } + }, + "predicate": null + }, + { + "type": "DeclareFunction", + "start":69,"end":111,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":42}}, + "id": { + "type": "Identifier", + "start":86,"end":111,"loc":{"start":{"line":3,"column":17},"end":{"line":3,"column":42},"identifierName":"bar"}, + "name": "bar", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":90,"end":111,"loc":{"start":{"line":3,"column":21},"end":{"line":3,"column":42}}, + "typeAnnotation": { + "type": "FunctionTypeAnnotation", + "start":90,"end":111,"loc":{"start":{"line":3,"column":21},"end":{"line":3,"column":42}}, + "typeParameters": null, + "params": [], + "rest": null, + "this": { + "type": "FunctionTypeParam", + "start":91,"end":104,"loc":{"start":{"line":3,"column":22},"end":{"line":3,"column":35}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":98,"end":104,"loc":{"start":{"line":3,"column":29},"end":{"line":3,"column":35}} + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":107,"end":111,"loc":{"start":{"line":3,"column":38},"end":{"line":3,"column":42}} + } + } + } + }, + "predicate": null + }, + { + "type": "DeclareFunction", + "start":113,"end":167,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":54}}, + "id": { + "type": "Identifier", + "start":130,"end":167,"loc":{"start":{"line":5,"column":17},"end":{"line":5,"column":54},"identifierName":"baz"}, + "name": "baz", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":134,"end":167,"loc":{"start":{"line":5,"column":21},"end":{"line":5,"column":54}}, + "typeAnnotation": { + "type": "FunctionTypeAnnotation", + "start":134,"end":167,"loc":{"start":{"line":5,"column":21},"end":{"line":5,"column":54}}, + "typeParameters": null, + "params": [], + "rest": { + "type": "FunctionTypeParam", + "start":153,"end":160,"loc":{"start":{"line":5,"column":40},"end":{"line":5,"column":47}}, + "name": { + "type": "Identifier", + "start":153,"end":154,"loc":{"start":{"line":5,"column":40},"end":{"line":5,"column":41},"identifierName":"a"}, + "name": "a" + }, + "optional": false, + "typeAnnotation": { + "type": "AnyTypeAnnotation", + "start":157,"end":160,"loc":{"start":{"line":5,"column":44},"end":{"line":5,"column":47}} + } + }, + "this": { + "type": "FunctionTypeParam", + "start":135,"end":148,"loc":{"start":{"line":5,"column":22},"end":{"line":5,"column":35}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":142,"end":148,"loc":{"start":{"line":5,"column":29},"end":{"line":5,"column":35}} + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":163,"end":167,"loc":{"start":{"line":5,"column":50},"end":{"line":5,"column":54}} + } + } + } + }, + "predicate": null + }, + { + "type": "DeclareFunction", + "start":169,"end":210,"loc":{"start":{"line":7,"column":0},"end":{"line":7,"column":41}}, + "id": { + "type": "Identifier", + "start":186,"end":210,"loc":{"start":{"line":7,"column":17},"end":{"line":7,"column":41},"identifierName":"qux"}, + "name": "qux", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":189,"end":210,"loc":{"start":{"line":7,"column":20},"end":{"line":7,"column":41}}, + "typeAnnotation": { + "type": "FunctionTypeAnnotation", + "start":189,"end":210,"loc":{"start":{"line":7,"column":20},"end":{"line":7,"column":41}}, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start":189,"end":192,"loc":{"start":{"line":7,"column":20},"end":{"line":7,"column":23}}, + "params": [ + { + "type": "TypeParameter", + "start":190,"end":191,"loc":{"start":{"line":7,"column":21},"end":{"line":7,"column":22}}, + "name": "T", + "variance": null + } + ] + }, + "params": [], + "rest": null, + "this": { + "type": "FunctionTypeParam", + "start":194,"end":202,"loc":{"start":{"line":7,"column":25},"end":{"line":7,"column":33}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start":201,"end":202,"loc":{"start":{"line":7,"column":32},"end":{"line":7,"column":33}}, + "typeParameters": null, + "id": { + "type": "Identifier", + "start":201,"end":202,"loc":{"start":{"line":7,"column":32},"end":{"line":7,"column":33},"identifierName":"T"}, + "name": "T" + } + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":206,"end":210,"loc":{"start":{"line":7,"column":37},"end":{"line":7,"column":41}} + } + } + } + }, + "predicate": null + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/declare-method/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/declare-method/input.js new file mode 100644 index 000000000000..69755c4c5fab --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/declare-method/input.js @@ -0,0 +1,6 @@ +declare class A { + m(this : number, a : number, b : string) : void, + n(this : number, ...c : any) : void, + o(this : number) : void, + p(this : T) : void +} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/declare-method/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/declare-method/output.json new file mode 100644 index 000000000000..b089a3cf4d97 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/declare-method/output.json @@ -0,0 +1,235 @@ +{ + "type": "File", + "start":0,"end":168,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":168,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "DeclareClass", + "start":0,"end":168,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}}, + "id": { + "type": "Identifier", + "start":14,"end":15,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":15},"identifierName":"A"}, + "name": "A" + }, + "typeParameters": null, + "extends": [], + "implements": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start":16,"end":168,"loc":{"start":{"line":1,"column":16},"end":{"line":6,"column":1}}, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start":22,"end":69,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":51}}, + "key": { + "type": "Identifier", + "start":22,"end":23,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":5},"identifierName":"m"}, + "name": "m" + }, + "static": false, + "proto": false, + "kind": "init", + "method": true, + "value": { + "type": "FunctionTypeAnnotation", + "start":22,"end":69,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":51}}, + "params": [ + { + "type": "FunctionTypeParam", + "start":39,"end":49,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":31}}, + "name": { + "type": "Identifier", + "start":39,"end":40,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":22},"identifierName":"a"}, + "name": "a" + }, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":43,"end":49,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":31}} + } + }, + { + "type": "FunctionTypeParam", + "start":51,"end":61,"loc":{"start":{"line":2,"column":33},"end":{"line":2,"column":43}}, + "name": { + "type": "Identifier", + "start":51,"end":52,"loc":{"start":{"line":2,"column":33},"end":{"line":2,"column":34},"identifierName":"b"}, + "name": "b" + }, + "optional": false, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start":55,"end":61,"loc":{"start":{"line":2,"column":37},"end":{"line":2,"column":43}} + } + } + ], + "rest": null, + "typeParameters": null, + "this": { + "type": "FunctionTypeParam", + "start":24,"end":37,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":19}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":31,"end":37,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":19}} + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":65,"end":69,"loc":{"start":{"line":2,"column":47},"end":{"line":2,"column":51}} + } + }, + "optional": false + }, + { + "type": "ObjectTypeProperty", + "start":75,"end":110,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":39}}, + "key": { + "type": "Identifier", + "start":75,"end":76,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":5},"identifierName":"n"}, + "name": "n" + }, + "static": false, + "proto": false, + "kind": "init", + "method": true, + "value": { + "type": "FunctionTypeAnnotation", + "start":75,"end":110,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":39}}, + "params": [], + "rest": { + "type": "FunctionTypeParam", + "start":95,"end":102,"loc":{"start":{"line":3,"column":24},"end":{"line":3,"column":31}}, + "name": { + "type": "Identifier", + "start":95,"end":96,"loc":{"start":{"line":3,"column":24},"end":{"line":3,"column":25},"identifierName":"c"}, + "name": "c" + }, + "optional": false, + "typeAnnotation": { + "type": "AnyTypeAnnotation", + "start":99,"end":102,"loc":{"start":{"line":3,"column":28},"end":{"line":3,"column":31}} + } + }, + "typeParameters": null, + "this": { + "type": "FunctionTypeParam", + "start":77,"end":90,"loc":{"start":{"line":3,"column":6},"end":{"line":3,"column":19}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":84,"end":90,"loc":{"start":{"line":3,"column":13},"end":{"line":3,"column":19}} + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":106,"end":110,"loc":{"start":{"line":3,"column":35},"end":{"line":3,"column":39}} + } + }, + "optional": false + }, + { + "type": "ObjectTypeProperty", + "start":116,"end":139,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":27}}, + "key": { + "type": "Identifier", + "start":116,"end":117,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":5},"identifierName":"o"}, + "name": "o" + }, + "static": false, + "proto": false, + "kind": "init", + "method": true, + "value": { + "type": "FunctionTypeAnnotation", + "start":116,"end":139,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":27}}, + "params": [], + "rest": null, + "typeParameters": null, + "this": { + "type": "FunctionTypeParam", + "start":118,"end":131,"loc":{"start":{"line":4,"column":6},"end":{"line":4,"column":19}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":125,"end":131,"loc":{"start":{"line":4,"column":13},"end":{"line":4,"column":19}} + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":135,"end":139,"loc":{"start":{"line":4,"column":23},"end":{"line":4,"column":27}} + } + }, + "optional": false + }, + { + "type": "ObjectTypeProperty", + "start":145,"end":166,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":25}}, + "key": { + "type": "Identifier", + "start":145,"end":146,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":5},"identifierName":"p"}, + "name": "p" + }, + "static": false, + "proto": false, + "kind": "init", + "method": true, + "value": { + "type": "FunctionTypeAnnotation", + "start":145,"end":166,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":25}}, + "params": [], + "rest": null, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start":146,"end":149,"loc":{"start":{"line":5,"column":5},"end":{"line":5,"column":8}}, + "params": [ + { + "type": "TypeParameter", + "start":147,"end":148,"loc":{"start":{"line":5,"column":6},"end":{"line":5,"column":7}}, + "name": "T", + "variance": null + } + ] + }, + "this": { + "type": "FunctionTypeParam", + "start":150,"end":158,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":17}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start":157,"end":158,"loc":{"start":{"line":5,"column":16},"end":{"line":5,"column":17}}, + "typeParameters": null, + "id": { + "type": "Identifier", + "start":157,"end":158,"loc":{"start":{"line":5,"column":16},"end":{"line":5,"column":17},"identifierName":"T"}, + "name": "T" + } + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":162,"end":166,"loc":{"start":{"line":5,"column":21},"end":{"line":5,"column":25}} + } + }, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/default/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/default/input.js new file mode 100644 index 000000000000..5c62115ccd84 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/default/input.js @@ -0,0 +1 @@ +function foo (this : number = 2) {} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/default/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/default/output.json new file mode 100644 index 000000000000..594580b04d84 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/default/output.json @@ -0,0 +1,73 @@ +{ + "type": "File", + "start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":38}}, + "errors": [ + "SyntaxError: The `this` parameter may not have a default value. (1:17)" + ], + "program": { + "type": "Program", + "start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":38}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":38,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":38}}, + "id": { + "type": "Identifier", + "start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12},"identifierName":"foo"}, + "name": "foo" + }, + "generator": false, + "async": false, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start":12,"end":15,"loc":{"start":{"line":1,"column":12},"end":{"line":1,"column":15}}, + "params": [ + { + "type": "TypeParameter", + "start":13,"end":14,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":14}}, + "name": "T", + "variance": null + } + ] + }, + "params": [ + { + "type": "AssignmentPattern", + "start":17,"end":34,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":34}}, + "left": { + "type": "Identifier", + "start":17,"end":30,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":30},"identifierName":"this"}, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":22,"end":30,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":30}}, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":24,"end":30,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":30}} + } + } + }, + "right": { + "type": "NumericLiteral", + "start":33,"end":34,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":34}}, + "extra": { + "rawValue": 2, + "raw": "2" + }, + "value": 2 + } + } + ], + "body": { + "type": "BlockStatement", + "start":36,"end":38,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":38}}, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/function-declaration/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/function-declaration/input.js new file mode 100644 index 000000000000..f2d69ae4f83e --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/function-declaration/input.js @@ -0,0 +1,7 @@ +function foo (this : number, a : string, b) {} + +function bar (this : number) {} + +function baz (this : number, ...a) {} + +function qux (this : T) {} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/function-declaration/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/function-declaration/output.json new file mode 100644 index 000000000000..2c042f9f63fd --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/function-declaration/output.json @@ -0,0 +1,186 @@ +{ + "type": "File", + "start":0,"end":149,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":29}}, + "program": { + "type": "Program", + "start":0,"end":149,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":29}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":46,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":46}}, + "id": { + "type": "Identifier", + "start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12},"identifierName":"foo"}, + "name": "foo" + }, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":14,"end":27,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":27},"identifierName":"this"}, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":19,"end":27,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":27}}, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":21,"end":27,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":27}} + } + } + }, + { + "type": "Identifier", + "start":29,"end":39,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":39},"identifierName":"a"}, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":31,"end":39,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":39}}, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start":33,"end":39,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":39}} + } + } + }, + { + "type": "Identifier", + "start":41,"end":42,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":42},"identifierName":"b"}, + "name": "b" + } + ], + "body": { + "type": "BlockStatement", + "start":44,"end":46,"loc":{"start":{"line":1,"column":44},"end":{"line":1,"column":46}}, + "body": [], + "directives": [] + } + }, + { + "type": "FunctionDeclaration", + "start":48,"end":79,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":31}}, + "id": { + "type": "Identifier", + "start":57,"end":60,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":12},"identifierName":"bar"}, + "name": "bar" + }, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":62,"end":75,"loc":{"start":{"line":3,"column":14},"end":{"line":3,"column":27},"identifierName":"this"}, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":67,"end":75,"loc":{"start":{"line":3,"column":19},"end":{"line":3,"column":27}}, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":69,"end":75,"loc":{"start":{"line":3,"column":21},"end":{"line":3,"column":27}} + } + } + } + ], + "body": { + "type": "BlockStatement", + "start":77,"end":79,"loc":{"start":{"line":3,"column":29},"end":{"line":3,"column":31}}, + "body": [], + "directives": [] + } + }, + { + "type": "FunctionDeclaration", + "start":81,"end":118,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":37}}, + "id": { + "type": "Identifier", + "start":90,"end":93,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":12},"identifierName":"baz"}, + "name": "baz" + }, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":95,"end":108,"loc":{"start":{"line":5,"column":14},"end":{"line":5,"column":27},"identifierName":"this"}, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":100,"end":108,"loc":{"start":{"line":5,"column":19},"end":{"line":5,"column":27}}, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":102,"end":108,"loc":{"start":{"line":5,"column":21},"end":{"line":5,"column":27}} + } + } + }, + { + "type": "RestElement", + "start":110,"end":114,"loc":{"start":{"line":5,"column":29},"end":{"line":5,"column":33}}, + "argument": { + "type": "Identifier", + "start":113,"end":114,"loc":{"start":{"line":5,"column":32},"end":{"line":5,"column":33},"identifierName":"a"}, + "name": "a" + } + } + ], + "body": { + "type": "BlockStatement", + "start":116,"end":118,"loc":{"start":{"line":5,"column":35},"end":{"line":5,"column":37}}, + "body": [], + "directives": [] + } + }, + { + "type": "FunctionDeclaration", + "start":120,"end":149,"loc":{"start":{"line":7,"column":0},"end":{"line":7,"column":29}}, + "id": { + "type": "Identifier", + "start":129,"end":132,"loc":{"start":{"line":7,"column":9},"end":{"line":7,"column":12},"identifierName":"qux"}, + "name": "qux" + }, + "generator": false, + "async": false, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start":132,"end":135,"loc":{"start":{"line":7,"column":12},"end":{"line":7,"column":15}}, + "params": [ + { + "type": "TypeParameter", + "start":133,"end":134,"loc":{"start":{"line":7,"column":13},"end":{"line":7,"column":14}}, + "name": "T", + "variance": null + } + ] + }, + "params": [ + { + "type": "Identifier", + "start":137,"end":145,"loc":{"start":{"line":7,"column":17},"end":{"line":7,"column":25},"identifierName":"this"}, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":142,"end":145,"loc":{"start":{"line":7,"column":22},"end":{"line":7,"column":25}}, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start":144,"end":145,"loc":{"start":{"line":7,"column":24},"end":{"line":7,"column":25}}, + "typeParameters": null, + "id": { + "type": "Identifier", + "start":144,"end":145,"loc":{"start":{"line":7,"column":24},"end":{"line":7,"column":25},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "body": { + "type": "BlockStatement", + "start":147,"end":149,"loc":{"start":{"line":7,"column":27},"end":{"line":7,"column":29}}, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/function-type/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/function-type/input.js new file mode 100644 index 000000000000..0ae4768556fc --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/function-type/input.js @@ -0,0 +1,7 @@ +type T = (this : number, a : string, b : number) => void + +type U = (this : number, ...c : any) => void + +type V = (this : number) => void + +type Q = (this : T) => void diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/function-type/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/function-type/output.json new file mode 100644 index 000000000000..b3a6efdfd014 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/function-type/output.json @@ -0,0 +1,196 @@ +{ + "type": "File", + "start":0,"end":168,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":30}}, + "program": { + "type": "Program", + "start":0,"end":168,"loc":{"start":{"line":1,"column":0},"end":{"line":7,"column":30}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TypeAlias", + "start":0,"end":56,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":56}}, + "id": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"T"}, + "name": "T" + }, + "typeParameters": null, + "right": { + "type": "FunctionTypeAnnotation", + "start":9,"end":56,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":56}}, + "params": [ + { + "type": "FunctionTypeParam", + "start":25,"end":35,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":35}}, + "name": { + "type": "Identifier", + "start":25,"end":26,"loc":{"start":{"line":1,"column":25},"end":{"line":1,"column":26},"identifierName":"a"}, + "name": "a" + }, + "optional": false, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start":29,"end":35,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":35}} + } + }, + { + "type": "FunctionTypeParam", + "start":37,"end":47,"loc":{"start":{"line":1,"column":37},"end":{"line":1,"column":47}}, + "name": { + "type": "Identifier", + "start":37,"end":38,"loc":{"start":{"line":1,"column":37},"end":{"line":1,"column":38},"identifierName":"b"}, + "name": "b" + }, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":41,"end":47,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":47}} + } + } + ], + "rest": null, + "this": { + "type": "FunctionTypeParam", + "start":10,"end":23,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":23}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":17,"end":23,"loc":{"start":{"line":1,"column":17},"end":{"line":1,"column":23}} + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":52,"end":56,"loc":{"start":{"line":1,"column":52},"end":{"line":1,"column":56}} + }, + "typeParameters": null + } + }, + { + "type": "TypeAlias", + "start":58,"end":102,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":44}}, + "id": { + "type": "Identifier", + "start":63,"end":64,"loc":{"start":{"line":3,"column":5},"end":{"line":3,"column":6},"identifierName":"U"}, + "name": "U" + }, + "typeParameters": null, + "right": { + "type": "FunctionTypeAnnotation", + "start":67,"end":102,"loc":{"start":{"line":3,"column":9},"end":{"line":3,"column":44}}, + "params": [], + "rest": { + "type": "FunctionTypeParam", + "start":86,"end":93,"loc":{"start":{"line":3,"column":28},"end":{"line":3,"column":35}}, + "name": { + "type": "Identifier", + "start":86,"end":87,"loc":{"start":{"line":3,"column":28},"end":{"line":3,"column":29},"identifierName":"c"}, + "name": "c" + }, + "optional": false, + "typeAnnotation": { + "type": "AnyTypeAnnotation", + "start":90,"end":93,"loc":{"start":{"line":3,"column":32},"end":{"line":3,"column":35}} + } + }, + "this": { + "type": "FunctionTypeParam", + "start":68,"end":81,"loc":{"start":{"line":3,"column":10},"end":{"line":3,"column":23}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":75,"end":81,"loc":{"start":{"line":3,"column":17},"end":{"line":3,"column":23}} + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":98,"end":102,"loc":{"start":{"line":3,"column":40},"end":{"line":3,"column":44}} + }, + "typeParameters": null + } + }, + { + "type": "TypeAlias", + "start":104,"end":136,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":32}}, + "id": { + "type": "Identifier", + "start":109,"end":110,"loc":{"start":{"line":5,"column":5},"end":{"line":5,"column":6},"identifierName":"V"}, + "name": "V" + }, + "typeParameters": null, + "right": { + "type": "FunctionTypeAnnotation", + "start":113,"end":136,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":32}}, + "params": [], + "rest": null, + "this": { + "type": "FunctionTypeParam", + "start":114,"end":127,"loc":{"start":{"line":5,"column":10},"end":{"line":5,"column":23}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":121,"end":127,"loc":{"start":{"line":5,"column":17},"end":{"line":5,"column":23}} + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":132,"end":136,"loc":{"start":{"line":5,"column":28},"end":{"line":5,"column":32}} + }, + "typeParameters": null + } + }, + { + "type": "TypeAlias", + "start":138,"end":168,"loc":{"start":{"line":7,"column":0},"end":{"line":7,"column":30}}, + "id": { + "type": "Identifier", + "start":143,"end":144,"loc":{"start":{"line":7,"column":5},"end":{"line":7,"column":6},"identifierName":"Q"}, + "name": "Q" + }, + "typeParameters": null, + "right": { + "type": "FunctionTypeAnnotation", + "start":147,"end":168,"loc":{"start":{"line":7,"column":9},"end":{"line":7,"column":30}}, + "typeParameters": { + "type": "TypeParameterDeclaration", + "start":147,"end":150,"loc":{"start":{"line":7,"column":9},"end":{"line":7,"column":12}}, + "params": [ + { + "type": "TypeParameter", + "start":148,"end":149,"loc":{"start":{"line":7,"column":10},"end":{"line":7,"column":11}}, + "name": "T", + "variance": null + } + ] + }, + "params": [], + "rest": null, + "this": { + "type": "FunctionTypeParam", + "start":151,"end":159,"loc":{"start":{"line":7,"column":13},"end":{"line":7,"column":21}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start":158,"end":159,"loc":{"start":{"line":7,"column":20},"end":{"line":7,"column":21}}, + "typeParameters": null, + "id": { + "type": "Identifier", + "start":158,"end":159,"loc":{"start":{"line":7,"column":20},"end":{"line":7,"column":21},"identifierName":"T"}, + "name": "T" + } + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":164,"end":168,"loc":{"start":{"line":7,"column":26},"end":{"line":7,"column":30}} + } + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/method/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/method/input.js new file mode 100644 index 000000000000..9b145069abcb --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/method/input.js @@ -0,0 +1,6 @@ +class A { + m(this : number, a : number, b : string) {} + n(this : number, ...c) {} + o(this : number) {} + p(this : T) {} +} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/method/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/method/output.json new file mode 100644 index 000000000000..b972757dedd7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/method/output.json @@ -0,0 +1,226 @@ +{ + "type": "File", + "start":0,"end":135,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":135,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":135,"loc":{"start":{"line":1,"column":0},"end":{"line":6,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"A"}, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":8,"end":135,"loc":{"start":{"line":1,"column":8},"end":{"line":6,"column":1}}, + "body": [ + { + "type": "ClassMethod", + "start":14,"end":57,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":47}}, + "static": false, + "key": { + "type": "Identifier", + "start":14,"end":15,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":5},"identifierName":"m"}, + "name": "m" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":16,"end":29,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":19},"identifierName":"this"}, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":21,"end":29,"loc":{"start":{"line":2,"column":11},"end":{"line":2,"column":19}}, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":23,"end":29,"loc":{"start":{"line":2,"column":13},"end":{"line":2,"column":19}} + } + } + }, + { + "type": "Identifier", + "start":31,"end":41,"loc":{"start":{"line":2,"column":21},"end":{"line":2,"column":31},"identifierName":"a"}, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":33,"end":41,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":31}}, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":35,"end":41,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":31}} + } + } + }, + { + "type": "Identifier", + "start":43,"end":53,"loc":{"start":{"line":2,"column":33},"end":{"line":2,"column":43},"identifierName":"b"}, + "name": "b", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":45,"end":53,"loc":{"start":{"line":2,"column":35},"end":{"line":2,"column":43}}, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start":47,"end":53,"loc":{"start":{"line":2,"column":37},"end":{"line":2,"column":43}} + } + } + } + ], + "body": { + "type": "BlockStatement", + "start":55,"end":57,"loc":{"start":{"line":2,"column":45},"end":{"line":2,"column":47}}, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start":62,"end":87,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":29}}, + "static": false, + "key": { + "type": "Identifier", + "start":62,"end":63,"loc":{"start":{"line":3,"column":4},"end":{"line":3,"column":5},"identifierName":"n"}, + "name": "n" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":64,"end":77,"loc":{"start":{"line":3,"column":6},"end":{"line":3,"column":19},"identifierName":"this"}, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":69,"end":77,"loc":{"start":{"line":3,"column":11},"end":{"line":3,"column":19}}, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":71,"end":77,"loc":{"start":{"line":3,"column":13},"end":{"line":3,"column":19}} + } + } + }, + { + "type": "RestElement", + "start":79,"end":83,"loc":{"start":{"line":3,"column":21},"end":{"line":3,"column":25}}, + "argument": { + "type": "Identifier", + "start":82,"end":83,"loc":{"start":{"line":3,"column":24},"end":{"line":3,"column":25},"identifierName":"c"}, + "name": "c" + } + } + ], + "body": { + "type": "BlockStatement", + "start":85,"end":87,"loc":{"start":{"line":3,"column":27},"end":{"line":3,"column":29}}, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start":92,"end":111,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":23}}, + "static": false, + "key": { + "type": "Identifier", + "start":92,"end":93,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":5},"identifierName":"o"}, + "name": "o" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":94,"end":107,"loc":{"start":{"line":4,"column":6},"end":{"line":4,"column":19},"identifierName":"this"}, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":99,"end":107,"loc":{"start":{"line":4,"column":11},"end":{"line":4,"column":19}}, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":101,"end":107,"loc":{"start":{"line":4,"column":13},"end":{"line":4,"column":19}} + } + } + } + ], + "body": { + "type": "BlockStatement", + "start":109,"end":111,"loc":{"start":{"line":4,"column":21},"end":{"line":4,"column":23}}, + "body": [], + "directives": [] + } + }, + { + "type": "ClassMethod", + "start":116,"end":133,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":21}}, + "static": false, + "key": { + "type": "Identifier", + "start":116,"end":117,"loc":{"start":{"line":5,"column":4},"end":{"line":5,"column":5},"identifierName":"p"}, + "name": "p" + }, + "computed": false, + "kind": "method", + "typeParameters": { + "type": "TypeParameterDeclaration", + "start":117,"end":120,"loc":{"start":{"line":5,"column":5},"end":{"line":5,"column":8}}, + "params": [ + { + "type": "TypeParameter", + "start":118,"end":119,"loc":{"start":{"line":5,"column":6},"end":{"line":5,"column":7}}, + "name": "T", + "variance": null + } + ] + }, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":121,"end":129,"loc":{"start":{"line":5,"column":9},"end":{"line":5,"column":17},"identifierName":"this"}, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":126,"end":129,"loc":{"start":{"line":5,"column":14},"end":{"line":5,"column":17}}, + "typeAnnotation": { + "type": "GenericTypeAnnotation", + "start":128,"end":129,"loc":{"start":{"line":5,"column":16},"end":{"line":5,"column":17}}, + "typeParameters": null, + "id": { + "type": "Identifier", + "start":128,"end":129,"loc":{"start":{"line":5,"column":16},"end":{"line":5,"column":17},"identifierName":"T"}, + "name": "T" + } + } + } + } + ], + "body": { + "type": "BlockStatement", + "start":131,"end":133,"loc":{"start":{"line":5,"column":19},"end":{"line":5,"column":21}}, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/object-constructor/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/object-constructor/input.js new file mode 100644 index 000000000000..903a43ad1cca --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/object-constructor/input.js @@ -0,0 +1,5 @@ +// @flow + +({ + constructor(this: number){} +}) diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/object-constructor/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/object-constructor/output.json new file mode 100644 index 000000000000..7736cab5a72c --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/object-constructor/output.json @@ -0,0 +1,77 @@ +{ + "type": "File", + "start":0,"end":47,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}}, + "program": { + "type": "Program", + "start":0,"end":47,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":2}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ExpressionStatement", + "start":10,"end":47,"loc":{"start":{"line":3,"column":0},"end":{"line":5,"column":2}}, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}} + } + ], + "expression": { + "type": "ObjectExpression", + "start":11,"end":46,"loc":{"start":{"line":3,"column":1},"end":{"line":5,"column":1}}, + "extra": { + "parenthesized": true, + "parenStart": 10 + }, + "properties": [ + { + "type": "ObjectMethod", + "start":17,"end":44,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":31}}, + "method": true, + "key": { + "type": "Identifier", + "start":17,"end":28,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":15},"identifierName":"constructor"}, + "name": "constructor" + }, + "computed": false, + "kind": "method", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":29,"end":41,"loc":{"start":{"line":4,"column":16},"end":{"line":4,"column":28},"identifierName":"this"}, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":33,"end":41,"loc":{"start":{"line":4,"column":20},"end":{"line":4,"column":28}}, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":35,"end":41,"loc":{"start":{"line":4,"column":22},"end":{"line":4,"column":28}} + } + } + } + ], + "body": { + "type": "BlockStatement", + "start":42,"end":44,"loc":{"start":{"line":4,"column":29},"end":{"line":4,"column":31}}, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}} + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/object-method-type-this-not-first/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/object-method-type-this-not-first/input.js new file mode 100644 index 000000000000..59702554101e --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/object-method-type-this-not-first/input.js @@ -0,0 +1,3 @@ +type T = { + foo(a : number, this : number) : void +} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/object-method-type-this-not-first/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/object-method-type-this-not-first/output.json new file mode 100644 index 000000000000..8a93ef574818 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/object-method-type-this-not-first/output.json @@ -0,0 +1,92 @@ +{ + "type": "File", + "start":0,"end":54,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "errors": [ + "SyntaxError: The `this` parameter must be the first function parameter. (2:20)" + ], + "program": { + "type": "Program", + "start":0,"end":54,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TypeAlias", + "start":0,"end":54,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"T"}, + "name": "T" + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "start":9,"end":54,"loc":{"start":{"line":1,"column":9},"end":{"line":3,"column":1}}, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start":15,"end":52,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":41}}, + "key": { + "type": "Identifier", + "start":15,"end":18,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":7},"identifierName":"foo"}, + "name": "foo" + }, + "static": false, + "proto": false, + "kind": "init", + "method": true, + "value": { + "type": "FunctionTypeAnnotation", + "start":15,"end":52,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":41}}, + "params": [ + { + "type": "FunctionTypeParam", + "start":19,"end":29,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":18}}, + "name": { + "type": "Identifier", + "start":19,"end":20,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":9},"identifierName":"a"}, + "name": "a" + }, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":23,"end":29,"loc":{"start":{"line":2,"column":12},"end":{"line":2,"column":18}} + } + }, + { + "type": "FunctionTypeParam", + "start":31,"end":44,"loc":{"start":{"line":2,"column":20},"end":{"line":2,"column":33}}, + "name": { + "type": "Identifier", + "start":31,"end":35,"loc":{"start":{"line":2,"column":20},"end":{"line":2,"column":24},"identifierName":"this"}, + "name": "this" + }, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":38,"end":44,"loc":{"start":{"line":2,"column":27},"end":{"line":2,"column":33}} + } + } + ], + "rest": null, + "typeParameters": null, + "this": null, + "returnType": { + "type": "VoidTypeAnnotation", + "start":48,"end":52,"loc":{"start":{"line":2,"column":37},"end":{"line":2,"column":41}} + } + }, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": false + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/object-method-type/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/object-method-type/input.js new file mode 100644 index 000000000000..46171c399edd --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/object-method-type/input.js @@ -0,0 +1,3 @@ +type T = { + foo(this : number) : void +} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/object-method-type/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/object-method-type/output.json new file mode 100644 index 000000000000..f71f3acee7df --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/object-method-type/output.json @@ -0,0 +1,69 @@ +{ + "type": "File", + "start":0,"end":42,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":42,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TypeAlias", + "start":0,"end":42,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"T"}, + "name": "T" + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "start":9,"end":42,"loc":{"start":{"line":1,"column":9},"end":{"line":3,"column":1}}, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start":15,"end":40,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":29}}, + "key": { + "type": "Identifier", + "start":15,"end":18,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":7},"identifierName":"foo"}, + "name": "foo" + }, + "static": false, + "proto": false, + "kind": "init", + "method": true, + "value": { + "type": "FunctionTypeAnnotation", + "start":15,"end":40,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":29}}, + "params": [], + "rest": null, + "typeParameters": null, + "this": { + "type": "FunctionTypeParam", + "start":19,"end":32,"loc":{"start":{"line":2,"column":8},"end":{"line":2,"column":21}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":26,"end":32,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":21}} + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":36,"end":40,"loc":{"start":{"line":2,"column":25},"end":{"line":2,"column":29}} + } + }, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": false + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/object-type-constructor/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/object-type-constructor/input.js new file mode 100644 index 000000000000..7993687854c8 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/object-type-constructor/input.js @@ -0,0 +1,5 @@ +// @flow + +type T = { + constructor(this : number) : void +} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/object-type-constructor/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/object-type-constructor/output.json new file mode 100644 index 000000000000..8555aed34e47 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/object-type-constructor/output.json @@ -0,0 +1,83 @@ +{ + "type": "File", + "start":0,"end":60,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":60,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TypeAlias", + "start":10,"end":60,"loc":{"start":{"line":3,"column":0},"end":{"line":5,"column":1}}, + "leadingComments": [ + { + "type": "CommentLine", + "value": " @flow", + "start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}} + } + ], + "id": { + "type": "Identifier", + "start":15,"end":16,"loc":{"start":{"line":3,"column":5},"end":{"line":3,"column":6},"identifierName":"T"}, + "name": "T" + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "start":19,"end":60,"loc":{"start":{"line":3,"column":9},"end":{"line":5,"column":1}}, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start":25,"end":58,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":37}}, + "key": { + "type": "Identifier", + "start":25,"end":36,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":15},"identifierName":"constructor"}, + "name": "constructor" + }, + "static": false, + "proto": false, + "kind": "init", + "method": true, + "value": { + "type": "FunctionTypeAnnotation", + "start":25,"end":58,"loc":{"start":{"line":4,"column":4},"end":{"line":4,"column":37}}, + "params": [], + "rest": null, + "typeParameters": null, + "this": { + "type": "FunctionTypeParam", + "start":37,"end":50,"loc":{"start":{"line":4,"column":16},"end":{"line":4,"column":29}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":44,"end":50,"loc":{"start":{"line":4,"column":23},"end":{"line":4,"column":29}} + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":54,"end":58,"loc":{"start":{"line":4,"column":33},"end":{"line":4,"column":37}} + } + }, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": false + } + } + ], + "directives": [] + }, + "comments": [ + { + "type": "CommentLine", + "value": " @flow", + "start":0,"end":8,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":8}} + } + ] +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-arrow-function/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/this-arrow-function/input.js new file mode 100644 index 000000000000..cb37e78f7046 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-arrow-function/input.js @@ -0,0 +1 @@ +let x = (this : number) => 0 diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-arrow-function/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-arrow-function/output.json new file mode 100644 index 000000000000..954fd71984d6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-arrow-function/output.json @@ -0,0 +1,62 @@ +{ + "type": "File", + "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, + "errors": [ + "SyntaxError: Binding invalid left-hand side in function parameter list (1:9)" + ], + "program": { + "type": "Program", + "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "VariableDeclaration", + "start":0,"end":28,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":28}}, + "declarations": [ + { + "type": "VariableDeclarator", + "start":4,"end":28,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":28}}, + "id": { + "type": "Identifier", + "start":4,"end":5,"loc":{"start":{"line":1,"column":4},"end":{"line":1,"column":5},"identifierName":"x"}, + "name": "x" + }, + "init": { + "type": "ArrowFunctionExpression", + "start":8,"end":28,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":28}}, + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "ThisExpression", + "start":9,"end":22,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":22}}, + "typeAnnotation": { + "type": "TypeAnnotation", + "start":14,"end":22,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":22}}, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":16,"end":22,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":22}} + } + } + } + ], + "body": { + "type": "NumericLiteral", + "start":27,"end":28,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":28}}, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + } + } + ], + "kind": "let" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-constructor-declare/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/this-constructor-declare/input.js new file mode 100644 index 000000000000..6e9a7ca40c96 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-constructor-declare/input.js @@ -0,0 +1,3 @@ +declare class A { + constructor(this : number) : A; +} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-constructor-declare/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-constructor-declare/output.json new file mode 100644 index 000000000000..d3461e69afbc --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-constructor-declare/output.json @@ -0,0 +1,80 @@ +{ + "type": "File", + "start":0,"end":55,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "errors": [ + "SyntaxError: Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions. (2:16)" + ], + "program": { + "type": "Program", + "start":0,"end":55,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "DeclareClass", + "start":0,"end":55,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":14,"end":15,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":15},"identifierName":"A"}, + "name": "A" + }, + "typeParameters": null, + "extends": [], + "implements": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start":16,"end":55,"loc":{"start":{"line":1,"column":16},"end":{"line":3,"column":1}}, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start":22,"end":52,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":34}}, + "key": { + "type": "Identifier", + "start":22,"end":33,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":15},"identifierName":"constructor"}, + "name": "constructor" + }, + "static": false, + "proto": false, + "kind": "init", + "method": true, + "value": { + "type": "FunctionTypeAnnotation", + "start":22,"end":52,"loc":{"start":{"line":2,"column":4},"end":{"line":2,"column":34}}, + "params": [], + "rest": null, + "typeParameters": null, + "this": { + "type": "FunctionTypeParam", + "start":34,"end":47,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":29}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":41,"end":47,"loc":{"start":{"line":2,"column":23},"end":{"line":2,"column":29}} + } + }, + "returnType": { + "type": "GenericTypeAnnotation", + "start":51,"end":52,"loc":{"start":{"line":2,"column":33},"end":{"line":2,"column":34}}, + "typeParameters": null, + "id": { + "type": "Identifier", + "start":51,"end":52,"loc":{"start":{"line":2,"column":33},"end":{"line":2,"column":34},"identifierName":"A"}, + "name": "A" + } + } + }, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-constructor/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/this-constructor/input.js new file mode 100644 index 000000000000..69517defe8d1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-constructor/input.js @@ -0,0 +1,3 @@ +class A { + constructor(this: string) {} +} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-constructor/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-constructor/output.json new file mode 100644 index 000000000000..3ed70ed007b6 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-constructor/output.json @@ -0,0 +1,68 @@ +{ + "type": "File", + "start":0,"end":42,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "errors": [ + "SyntaxError: Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions. (2:2)" + ], + "program": { + "type": "Program", + "start":0,"end":42,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":42,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"A"}, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":8,"end":42,"loc":{"start":{"line":1,"column":8},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ClassMethod", + "start":12,"end":40,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":30}}, + "static": false, + "key": { + "type": "Identifier", + "start":12,"end":23,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":13},"identifierName":"constructor"}, + "name": "constructor" + }, + "computed": false, + "kind": "constructor", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":24,"end":36,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":26},"identifierName":"this"}, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":28,"end":36,"loc":{"start":{"line":2,"column":18},"end":{"line":2,"column":26}}, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start":30,"end":36,"loc":{"start":{"line":2,"column":20},"end":{"line":2,"column":26}} + } + } + } + ], + "body": { + "type": "BlockStatement", + "start":38,"end":40,"loc":{"start":{"line":2,"column":28},"end":{"line":2,"column":30}}, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter-type/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter-type/input.js new file mode 100644 index 000000000000..da0c98c60f2c --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter-type/input.js @@ -0,0 +1,3 @@ +type T = { + get foo(this: string) : void +} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter-type/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter-type/output.json new file mode 100644 index 000000000000..1d448d6fd698 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter-type/output.json @@ -0,0 +1,72 @@ +{ + "type": "File", + "start":0,"end":43,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "errors": [ + "SyntaxError: A getter cannot have a `this` parameter. (2:10)" + ], + "program": { + "type": "Program", + "start":0,"end":43,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TypeAlias", + "start":0,"end":43,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"T"}, + "name": "T" + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "start":9,"end":43,"loc":{"start":{"line":1,"column":9},"end":{"line":3,"column":1}}, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start":13,"end":41,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":30}}, + "key": { + "type": "Identifier", + "start":17,"end":20,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":9},"identifierName":"foo"}, + "name": "foo" + }, + "static": false, + "proto": false, + "kind": "get", + "method": true, + "value": { + "type": "FunctionTypeAnnotation", + "start":13,"end":41,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":30}}, + "params": [], + "rest": null, + "typeParameters": null, + "this": { + "type": "FunctionTypeParam", + "start":21,"end":33,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":22}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start":27,"end":33,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":22}} + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":37,"end":41,"loc":{"start":{"line":2,"column":26},"end":{"line":2,"column":30}} + } + }, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": false + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter/input.js new file mode 100644 index 000000000000..b822a1766aaa --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter/input.js @@ -0,0 +1,3 @@ +class Foo { + get foo(this: string) {} +} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter/output.json new file mode 100644 index 000000000000..320f898c90e4 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-getter/output.json @@ -0,0 +1,69 @@ +{ + "type": "File", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "errors": [ + "SyntaxError: getter must not have any formal parameters (2:2)", + "SyntaxError: A getter cannot have a `this` parameter. (2:10)" + ], + "program": { + "type": "Program", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":10,"end":40,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ClassMethod", + "start":14,"end":38,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":26}}, + "static": false, + "key": { + "type": "Identifier", + "start":18,"end":21,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":9},"identifierName":"foo"}, + "name": "foo" + }, + "computed": false, + "kind": "get", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":22,"end":34,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":22},"identifierName":"this"}, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":26,"end":34,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":22}}, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start":28,"end":34,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":22}} + } + } + } + ], + "body": { + "type": "BlockStatement", + "start":36,"end":38,"loc":{"start":{"line":2,"column":24},"end":{"line":2,"column":26}}, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-no-annot/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/this-no-annot/input.js new file mode 100644 index 000000000000..270cd80bc8b2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-no-annot/input.js @@ -0,0 +1 @@ +function foo (this) {} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-no-annot/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-no-annot/output.json new file mode 100644 index 000000000000..dbbbe1ef2f31 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-no-annot/output.json @@ -0,0 +1,40 @@ +{ + "type": "File", + "start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}}, + "errors": [ + "SyntaxError: A type annotation is required for the `this` parameter. (1:14)" + ], + "program": { + "type": "Program", + "start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}}, + "id": { + "type": "Identifier", + "start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12},"identifierName":"foo"}, + "name": "foo" + }, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":14,"end":18,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":18},"identifierName":"this"}, + "name": "this" + } + ], + "body": { + "type": "BlockStatement", + "start":20,"end":22,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":22}}, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-not-first-type/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/this-not-first-type/input.js new file mode 100644 index 000000000000..09ab5a69ee04 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-not-first-type/input.js @@ -0,0 +1 @@ +type T = (a : string, this : number) => void diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-not-first-type/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-not-first-type/output.json new file mode 100644 index 000000000000..e903a001115c --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-not-first-type/output.json @@ -0,0 +1,67 @@ +{ + "type": "File", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}}, + "errors": [ + "SyntaxError: The `this` parameter must be the first function parameter. (1:22)" + ], + "program": { + "type": "Program", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TypeAlias", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":44}}, + "id": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"T"}, + "name": "T" + }, + "typeParameters": null, + "right": { + "type": "FunctionTypeAnnotation", + "start":9,"end":44,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":44}}, + "params": [ + { + "type": "FunctionTypeParam", + "start":10,"end":20,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":20}}, + "name": { + "type": "Identifier", + "start":10,"end":11,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":11},"identifierName":"a"}, + "name": "a" + }, + "optional": false, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start":14,"end":20,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":20}} + } + }, + { + "type": "FunctionTypeParam", + "start":22,"end":35,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":35}}, + "name": { + "type": "Identifier", + "start":22,"end":26,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":26},"identifierName":"this"}, + "name": "this" + }, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":29,"end":35,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":35}} + } + } + ], + "rest": null, + "this": null, + "returnType": { + "type": "VoidTypeAnnotation", + "start":40,"end":44,"loc":{"start":{"line":1,"column":40},"end":{"line":1,"column":44}} + }, + "typeParameters": null + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-not-first/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/this-not-first/input.js new file mode 100644 index 000000000000..69e929f34f1f --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-not-first/input.js @@ -0,0 +1 @@ +function foo (a : string, this : number) {} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-not-first/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-not-first/output.json new file mode 100644 index 000000000000..02b00d783712 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-not-first/output.json @@ -0,0 +1,61 @@ +{ + "type": "File", + "start":0,"end":43,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":43}}, + "errors": [ + "SyntaxError: The `this` parameter must be the first function parameter. (1:26)" + ], + "program": { + "type": "Program", + "start":0,"end":43,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":43}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":43,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":43}}, + "id": { + "type": "Identifier", + "start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12},"identifierName":"foo"}, + "name": "foo" + }, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":14,"end":24,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":24},"identifierName":"a"}, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":16,"end":24,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":24}}, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start":18,"end":24,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":24}} + } + } + }, + { + "type": "Identifier", + "start":26,"end":39,"loc":{"start":{"line":1,"column":26},"end":{"line":1,"column":39},"identifierName":"this"}, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":31,"end":39,"loc":{"start":{"line":1,"column":31},"end":{"line":1,"column":39}}, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":33,"end":39,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":39}} + } + } + } + ], + "body": { + "type": "BlockStatement", + "start":41,"end":43,"loc":{"start":{"line":1,"column":41},"end":{"line":1,"column":43}}, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-optional-type/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/this-optional-type/input.js new file mode 100644 index 000000000000..0c28bd181dc2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-optional-type/input.js @@ -0,0 +1 @@ +type T = (this? : number) => void diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-optional-type/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-optional-type/output.json new file mode 100644 index 000000000000..6e19b60a59cb --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-optional-type/output.json @@ -0,0 +1,47 @@ +{ + "type": "File", + "start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}}, + "errors": [ + "SyntaxError: The `this` parameter cannot be optional. (1:10)" + ], + "program": { + "type": "Program", + "start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TypeAlias", + "start":0,"end":33,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":33}}, + "id": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"T"}, + "name": "T" + }, + "typeParameters": null, + "right": { + "type": "FunctionTypeAnnotation", + "start":9,"end":33,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":33}}, + "params": [], + "rest": null, + "this": { + "type": "FunctionTypeParam", + "start":10,"end":24,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":24}}, + "name": null, + "optional": true, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":18,"end":24,"loc":{"start":{"line":1,"column":18},"end":{"line":1,"column":24}} + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":29,"end":33,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":33}} + }, + "typeParameters": null + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-optional/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/this-optional/input.js new file mode 100644 index 000000000000..4b5c4782dff2 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-optional/input.js @@ -0,0 +1 @@ +function foo(this? : number) {} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-optional/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-optional/output.json new file mode 100644 index 000000000000..33bd48751feb --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-optional/output.json @@ -0,0 +1,49 @@ +{ + "type": "File", + "start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":31}}, + "errors": [ + "SyntaxError: The `this` parameter cannot be optional. (1:13)" + ], + "program": { + "type": "Program", + "start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":31}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "FunctionDeclaration", + "start":0,"end":31,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":31}}, + "id": { + "type": "Identifier", + "start":9,"end":12,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":12},"identifierName":"foo"}, + "name": "foo" + }, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":13,"end":27,"loc":{"start":{"line":1,"column":13},"end":{"line":1,"column":27},"identifierName":"this"}, + "name": "this", + "optional": true, + "typeAnnotation": { + "type": "TypeAnnotation", + "start":19,"end":27,"loc":{"start":{"line":1,"column":19},"end":{"line":1,"column":27}}, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":21,"end":27,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":27}} + } + } + } + ], + "body": { + "type": "BlockStatement", + "start":29,"end":31,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":31}}, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter-type/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter-type/input.js new file mode 100644 index 000000000000..a1f5eeb702d5 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter-type/input.js @@ -0,0 +1,3 @@ +type T = { + set foo(this: string) : void +} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter-type/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter-type/output.json new file mode 100644 index 000000000000..06408c4054a1 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter-type/output.json @@ -0,0 +1,73 @@ +{ + "type": "File", + "start":0,"end":43,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "errors": [ + "SyntaxError: A setter cannot have a `this` parameter. (2:10)", + "SyntaxError: setter must have exactly one formal parameter (2:2)" + ], + "program": { + "type": "Program", + "start":0,"end":43,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TypeAlias", + "start":0,"end":43,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"T"}, + "name": "T" + }, + "typeParameters": null, + "right": { + "type": "ObjectTypeAnnotation", + "start":9,"end":43,"loc":{"start":{"line":1,"column":9},"end":{"line":3,"column":1}}, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start":13,"end":41,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":30}}, + "key": { + "type": "Identifier", + "start":17,"end":20,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":9},"identifierName":"foo"}, + "name": "foo" + }, + "static": false, + "proto": false, + "kind": "set", + "method": true, + "value": { + "type": "FunctionTypeAnnotation", + "start":13,"end":41,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":30}}, + "params": [], + "rest": null, + "typeParameters": null, + "this": { + "type": "FunctionTypeParam", + "start":21,"end":33,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":22}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start":27,"end":33,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":22}} + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":37,"end":41,"loc":{"start":{"line":2,"column":26},"end":{"line":2,"column":30}} + } + }, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false, + "inexact": false + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter/input.js new file mode 100644 index 000000000000..4bada6fc7903 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter/input.js @@ -0,0 +1,3 @@ +class Foo { + set foo(this: string) {} +} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter/output.json new file mode 100644 index 000000000000..b71169d3ea5d --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-setter/output.json @@ -0,0 +1,68 @@ +{ + "type": "File", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "errors": [ + "SyntaxError: A setter cannot have a `this` parameter. (2:10)" + ], + "program": { + "type": "Program", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":40,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":9,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":9},"identifierName":"Foo"}, + "name": "Foo" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":10,"end":40,"loc":{"start":{"line":1,"column":10},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ClassMethod", + "start":14,"end":38,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":26}}, + "static": false, + "key": { + "type": "Identifier", + "start":18,"end":21,"loc":{"start":{"line":2,"column":6},"end":{"line":2,"column":9},"identifierName":"foo"}, + "name": "foo" + }, + "computed": false, + "kind": "set", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":22,"end":34,"loc":{"start":{"line":2,"column":10},"end":{"line":2,"column":22},"identifierName":"this"}, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":26,"end":34,"loc":{"start":{"line":2,"column":14},"end":{"line":2,"column":22}}, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start":28,"end":34,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":22}} + } + } + } + ], + "body": { + "type": "BlockStatement", + "start":36,"end":38,"loc":{"start":{"line":2,"column":24},"end":{"line":2,"column":26}}, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-string-literal-constructor/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/this-string-literal-constructor/input.js new file mode 100644 index 000000000000..5d2c3936713b --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-string-literal-constructor/input.js @@ -0,0 +1,3 @@ +class A { + "constructor"(this: string) {} +} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-string-literal-constructor/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-string-literal-constructor/output.json new file mode 100644 index 000000000000..c9c0891bdef7 --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-string-literal-constructor/output.json @@ -0,0 +1,72 @@ +{ + "type": "File", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "errors": [ + "SyntaxError: Constructors cannot have a `this` parameter; constructors don't bind `this` like other functions. (2:2)" + ], + "program": { + "type": "Program", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "ClassDeclaration", + "start":0,"end":44,"loc":{"start":{"line":1,"column":0},"end":{"line":3,"column":1}}, + "id": { + "type": "Identifier", + "start":6,"end":7,"loc":{"start":{"line":1,"column":6},"end":{"line":1,"column":7},"identifierName":"A"}, + "name": "A" + }, + "superClass": null, + "body": { + "type": "ClassBody", + "start":8,"end":44,"loc":{"start":{"line":1,"column":8},"end":{"line":3,"column":1}}, + "body": [ + { + "type": "ClassMethod", + "start":12,"end":42,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":32}}, + "static": false, + "key": { + "type": "StringLiteral", + "start":12,"end":25,"loc":{"start":{"line":2,"column":2},"end":{"line":2,"column":15}}, + "extra": { + "rawValue": "constructor", + "raw": "\"constructor\"" + }, + "value": "constructor" + }, + "computed": false, + "kind": "constructor", + "id": null, + "generator": false, + "async": false, + "params": [ + { + "type": "Identifier", + "start":26,"end":38,"loc":{"start":{"line":2,"column":16},"end":{"line":2,"column":28},"identifierName":"this"}, + "name": "this", + "typeAnnotation": { + "type": "TypeAnnotation", + "start":30,"end":38,"loc":{"start":{"line":2,"column":20},"end":{"line":2,"column":28}}, + "typeAnnotation": { + "type": "StringTypeAnnotation", + "start":32,"end":38,"loc":{"start":{"line":2,"column":22},"end":{"line":2,"column":28}} + } + } + } + ], + "body": { + "type": "BlockStatement", + "start":40,"end":42,"loc":{"start":{"line":2,"column":30},"end":{"line":2,"column":32}}, + "body": [], + "directives": [] + } + } + ] + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-type/input.js b/packages/babel-parser/test/fixtures/flow/this-annotation/this-type/input.js new file mode 100644 index 000000000000..f472d1c0182f --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-type/input.js @@ -0,0 +1,5 @@ +type T = (this, number) => void; + +declare class A { + fn(this, number): void; +} diff --git a/packages/babel-parser/test/fixtures/flow/this-annotation/this-type/output.json b/packages/babel-parser/test/fixtures/flow/this-annotation/this-type/output.json new file mode 100644 index 000000000000..6e7b440816db --- /dev/null +++ b/packages/babel-parser/test/fixtures/flow/this-annotation/this-type/output.json @@ -0,0 +1,125 @@ +{ + "type": "File", + "start":0,"end":79,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, + "program": { + "type": "Program", + "start":0,"end":79,"loc":{"start":{"line":1,"column":0},"end":{"line":5,"column":1}}, + "sourceType": "module", + "interpreter": null, + "body": [ + { + "type": "TypeAlias", + "start":0,"end":32,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":32}}, + "id": { + "type": "Identifier", + "start":5,"end":6,"loc":{"start":{"line":1,"column":5},"end":{"line":1,"column":6},"identifierName":"T"}, + "name": "T" + }, + "typeParameters": null, + "right": { + "type": "FunctionTypeAnnotation", + "start":9,"end":31,"loc":{"start":{"line":1,"column":9},"end":{"line":1,"column":31}}, + "params": [ + { + "type": "FunctionTypeParam", + "start":10,"end":15,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":15}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "ThisTypeAnnotation", + "start":10,"end":14,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":14}} + } + }, + { + "type": "FunctionTypeParam", + "start":16,"end":22,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":22}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":16,"end":22,"loc":{"start":{"line":1,"column":16},"end":{"line":1,"column":22}} + } + } + ], + "rest": null, + "this": null, + "returnType": { + "type": "VoidTypeAnnotation", + "start":27,"end":31,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":31}} + }, + "typeParameters": null + } + }, + { + "type": "DeclareClass", + "start":34,"end":79,"loc":{"start":{"line":3,"column":0},"end":{"line":5,"column":1}}, + "id": { + "type": "Identifier", + "start":48,"end":49,"loc":{"start":{"line":3,"column":14},"end":{"line":3,"column":15},"identifierName":"A"}, + "name": "A" + }, + "typeParameters": null, + "extends": [], + "implements": [], + "mixins": [], + "body": { + "type": "ObjectTypeAnnotation", + "start":50,"end":79,"loc":{"start":{"line":3,"column":16},"end":{"line":5,"column":1}}, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start":54,"end":76,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":24}}, + "key": { + "type": "Identifier", + "start":54,"end":56,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":4},"identifierName":"fn"}, + "name": "fn" + }, + "static": false, + "proto": false, + "kind": "init", + "method": true, + "value": { + "type": "FunctionTypeAnnotation", + "start":54,"end":76,"loc":{"start":{"line":4,"column":2},"end":{"line":4,"column":24}}, + "params": [ + { + "type": "FunctionTypeParam", + "start":63,"end":69,"loc":{"start":{"line":4,"column":11},"end":{"line":4,"column":17}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start":63,"end":69,"loc":{"start":{"line":4,"column":11},"end":{"line":4,"column":17}} + } + } + ], + "rest": null, + "typeParameters": null, + "this": { + "type": "FunctionTypeParam", + "start":57,"end":61,"loc":{"start":{"line":4,"column":5},"end":{"line":4,"column":9}}, + "name": null, + "optional": false, + "typeAnnotation": { + "type": "ThisTypeAnnotation", + "start":57,"end":61,"loc":{"start":{"line":4,"column":5},"end":{"line":4,"column":9}} + } + }, + "returnType": { + "type": "VoidTypeAnnotation", + "start":72,"end":76,"loc":{"start":{"line":4,"column":20},"end":{"line":4,"column":24}} + } + }, + "optional": false + } + ], + "indexers": [], + "internalSlots": [], + "exact": false + } + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/packages/babel-parser/test/fixtures/flow/type-alias/4/output.json b/packages/babel-parser/test/fixtures/flow/type-alias/4/output.json index 8592d1737fed..228f9b9abfc3 100644 --- a/packages/babel-parser/test/fixtures/flow/type-alias/4/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-alias/4/output.json @@ -126,6 +126,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":83,"end":89,"loc":{"start":{"line":7,"column":20},"end":{"line":7,"column":26}} @@ -152,6 +153,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "StringTypeAnnotation", "start":111,"end":117,"loc":{"start":{"line":8,"column":20},"end":{"line":8,"column":26}} diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/10/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/10/output.json index 7a545d1e6536..44873b5d54c2 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/10/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/10/output.json @@ -59,6 +59,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":47,"end":53,"loc":{"start":{"line":1,"column":47},"end":{"line":1,"column":53}} diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/11/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/11/output.json index eff1cf78a25e..68c4fdcd366f 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/11/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/11/output.json @@ -73,6 +73,7 @@ } } }, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":58,"end":64,"loc":{"start":{"line":1,"column":58},"end":{"line":1,"column":64}} diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/13/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/13/output.json index fe45c3c0e5dc..d2601c75d8f6 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/13/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/13/output.json @@ -27,6 +27,7 @@ "start":15,"end":25,"loc":{"start":{"line":1,"column":15},"end":{"line":1,"column":25}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":21,"end":25,"loc":{"start":{"line":1,"column":21},"end":{"line":1,"column":25}} diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/14/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/14/output.json index 9360adf64e81..eadf167279bf 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/14/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/14/output.json @@ -42,6 +42,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":27,"end":33,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":33}} diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/15/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/15/output.json index f74434914038..dcdb5c2b3efb 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/15/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/15/output.json @@ -42,6 +42,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":28,"end":34,"loc":{"start":{"line":1,"column":28},"end":{"line":1,"column":34}} diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/42/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/42/output.json index 3e4e5b09000f..d75964c3119d 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/42/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/42/output.json @@ -87,6 +87,7 @@ } }, "typeParameters": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":43,"end":47,"loc":{"start":{"line":1,"column":43},"end":{"line":1,"column":47}} diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/43/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/43/output.json index 049308dd2a06..89f3442c575b 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/43/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/43/output.json @@ -76,6 +76,7 @@ } ] }, + "this": null, "returnType": { "type": "GenericTypeAnnotation", "start":22,"end":23,"loc":{"start":{"line":1,"column":22},"end":{"line":1,"column":23}}, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/57/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/57/output.json index b19b04b9728f..817e35c3bbfd 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/57/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/57/output.json @@ -26,6 +26,7 @@ "start":8,"end":35,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":35}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "UnionTypeAnnotation", "start":14,"end":35,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":35}}, @@ -39,6 +40,7 @@ "start":23,"end":35,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":35}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "StringTypeAnnotation", "start":29,"end":35,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":35}} diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/7/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/7/output.json index b49204c7f0b3..9cbace9de416 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/7/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/7/output.json @@ -30,6 +30,7 @@ "start":23,"end":33,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":33}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":29,"end":33,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":33}} diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/8/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/8/output.json index cbfbdd516663..0527292f0ec7 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/8/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/8/output.json @@ -30,6 +30,7 @@ "start":23,"end":35,"loc":{"start":{"line":1,"column":23},"end":{"line":1,"column":35}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":29,"end":35,"loc":{"start":{"line":1,"column":29},"end":{"line":1,"column":35}} diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/86/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/86/output.json index 3f525d36038f..52ae1d2ec9dd 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/86/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/86/output.json @@ -54,6 +54,7 @@ } } }, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":33,"end":39,"loc":{"start":{"line":1,"column":33},"end":{"line":1,"column":39}} diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/87/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/87/output.json index 30d0d42c5f39..1aefc281d409 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/87/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/87/output.json @@ -59,6 +59,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "GenericTypeAnnotation", "start":27,"end":28,"loc":{"start":{"line":1,"column":27},"end":{"line":1,"column":28}}, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/88/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/88/output.json index 1b22c73f7400..8a5b0ea84ca2 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/88/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/88/output.json @@ -82,6 +82,7 @@ } } }, + "this": null, "returnType": { "type": "GenericTypeAnnotation", "start":37,"end":38,"loc":{"start":{"line":1,"column":37},"end":{"line":1,"column":38}}, diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/9/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/9/output.json index 7cb400a2d942..0ebc8fa0a1fa 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/9/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/9/output.json @@ -45,6 +45,7 @@ } ], "rest": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":35,"end":41,"loc":{"start":{"line":1,"column":35},"end":{"line":1,"column":41}} diff --git a/packages/babel-parser/test/fixtures/flow/type-annotations/object-type-method/output.json b/packages/babel-parser/test/fixtures/flow/type-annotations/object-type-method/output.json index b8e1ad4ce035..ab63de410053 100644 --- a/packages/babel-parser/test/fixtures/flow/type-annotations/object-type-method/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-annotations/object-type-method/output.json @@ -38,6 +38,7 @@ "start":14,"end":24,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":24}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":20,"end":24,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":24}} @@ -97,6 +98,7 @@ }, "params": [], "rest": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":52,"end":56,"loc":{"start":{"line":2,"column":24},"end":{"line":2,"column":28}} @@ -144,6 +146,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":77,"end":81,"loc":{"start":{"line":3,"column":17},"end":{"line":3,"column":21}} @@ -201,6 +204,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":105,"end":109,"loc":{"start":{"line":4,"column":20},"end":{"line":4,"column":24}} @@ -238,6 +242,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":130,"end":136,"loc":{"start":{"line":6,"column":16},"end":{"line":6,"column":22}} @@ -307,6 +312,7 @@ } ] }, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":163,"end":169,"loc":{"start":{"line":7,"column":23},"end":{"line":7,"column":29}} @@ -356,6 +362,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":200,"end":206,"loc":{"start":{"line":9,"column":26},"end":{"line":9,"column":32}} @@ -404,6 +411,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":243,"end":249,"loc":{"start":{"line":10,"column":33},"end":{"line":10,"column":39}} @@ -443,6 +451,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":276,"end":282,"loc":{"start":{"line":11,"column":23},"end":{"line":11,"column":29}} @@ -482,6 +491,7 @@ "params": [], "rest": null, "typeParameters": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":315,"end":321,"loc":{"start":{"line":12,"column":30},"end":{"line":12,"column":36}} diff --git a/packages/babel-parser/test/fixtures/flow/type-generics/async-arrow-like/output.json b/packages/babel-parser/test/fixtures/flow/type-generics/async-arrow-like/output.json index fa4b9aa787dd..a65cc3450814 100644 --- a/packages/babel-parser/test/fixtures/flow/type-generics/async-arrow-like/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-generics/async-arrow-like/output.json @@ -10,6 +10,18 @@ { "type": "ExpressionStatement", "start":0,"end":23,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":23}}, + "trailingComments": [ + { + "type": "CommentLine", + "value": " This looks A LOT like an async arrow function, but it isn't because", + "start":25,"end":95,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":70}} + }, + { + "type": "CommentLine", + "value": " T + U isn't a valid type parameter.", + "start":96,"end":134,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":38}} + } + ], "expression": { "type": "BinaryExpression", "start":0,"end":22,"loc":{"start":{"line":1,"column":0},"end":{"line":1,"column":22}}, @@ -32,6 +44,10 @@ "right": { "type": "TypeCastExpression", "start":10,"end":21,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":21}}, + "extra": { + "parenthesized": true, + "parenStart": 9 + }, "expression": { "type": "Identifier", "start":10,"end":12,"loc":{"start":{"line":1,"column":10},"end":{"line":1,"column":12},"identifierName":"fn"}, @@ -45,6 +61,7 @@ "start":14,"end":21,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":21}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "GenericTypeAnnotation", "start":20,"end":21,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":21}}, @@ -57,14 +74,14 @@ }, "typeParameters": null } - }, - "extra": { - "parenthesized": true, - "parenStart": 9 } } - }, - "trailingComments": [ + } + }, + { + "type": "ExpressionStatement", + "start":135,"end":167,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":32}}, + "leadingComments": [ { "type": "CommentLine", "value": " This looks A LOT like an async arrow function, but it isn't because", @@ -75,14 +92,14 @@ "value": " T + U isn't a valid type parameter.", "start":96,"end":134,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":38}} } - ] - }, - { - "type": "ExpressionStatement", - "start":135,"end":167,"loc":{"start":{"line":5,"column":0},"end":{"line":5,"column":32}}, + ], "expression": { "type": "TypeCastExpression", "start":136,"end":165,"loc":{"start":{"line":5,"column":1},"end":{"line":5,"column":30}}, + "extra": { + "parenthesized": true, + "parenStart": 135 + }, "expression": { "type": "BinaryExpression", "start":136,"end":156,"loc":{"start":{"line":5,"column":1},"end":{"line":5,"column":21}}, @@ -115,6 +132,10 @@ "right": { "type": "TypeCastExpression", "start":150,"end":155,"loc":{"start":{"line":5,"column":15},"end":{"line":5,"column":20}}, + "extra": { + "parenthesized": true, + "parenStart": 149 + }, "expression": { "type": "Identifier", "start":150,"end":152,"loc":{"start":{"line":5,"column":15},"end":{"line":5,"column":17},"identifierName":"fn"}, @@ -133,10 +154,6 @@ "name": "T" } } - }, - "extra": { - "parenthesized": true, - "parenStart": 149 } } }, @@ -177,24 +194,8 @@ }, "typeParameters": null } - }, - "extra": { - "parenthesized": true, - "parenStart": 135 - } - }, - "leadingComments": [ - { - "type": "CommentLine", - "value": " This looks A LOT like an async arrow function, but it isn't because", - "start":25,"end":95,"loc":{"start":{"line":3,"column":0},"end":{"line":3,"column":70}} - }, - { - "type": "CommentLine", - "value": " T + U isn't a valid type parameter.", - "start":96,"end":134,"loc":{"start":{"line":4,"column":0},"end":{"line":4,"column":38}} } - ] + } } ], "directives": [] diff --git a/packages/babel-parser/test/fixtures/flow/type-generics/async-arrow/output.json b/packages/babel-parser/test/fixtures/flow/type-generics/async-arrow/output.json index 3a4d934f13ec..b5cff2c4e4f4 100644 --- a/packages/babel-parser/test/fixtures/flow/type-generics/async-arrow/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-generics/async-arrow/output.json @@ -38,6 +38,7 @@ "start":14,"end":21,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":21}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "GenericTypeAnnotation", "start":20,"end":21,"loc":{"start":{"line":1,"column":20},"end":{"line":1,"column":21}}, diff --git a/packages/babel-parser/test/fixtures/flow/type-grouping/2/output.json b/packages/babel-parser/test/fixtures/flow/type-grouping/2/output.json index f2ee74dd938a..95b223ebc096 100644 --- a/packages/babel-parser/test/fixtures/flow/type-grouping/2/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-grouping/2/output.json @@ -30,6 +30,7 @@ "start":8,"end":20,"loc":{"start":{"line":1,"column":8},"end":{"line":1,"column":20}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":14,"end":20,"loc":{"start":{"line":1,"column":14},"end":{"line":1,"column":20}} @@ -41,6 +42,7 @@ "start":24,"end":36,"loc":{"start":{"line":1,"column":24},"end":{"line":1,"column":36}}, "params": [], "rest": null, + "this": null, "returnType": { "type": "StringTypeAnnotation", "start":30,"end":36,"loc":{"start":{"line":1,"column":30},"end":{"line":1,"column":36}} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/declare-class-method-reserved-word/output.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/declare-class-method-reserved-word/output.json index 1fcb8935c9e1..4d111fa58260 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/declare-class-method-reserved-word/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/declare-class-method-reserved-word/output.json @@ -53,6 +53,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":33,"end":37,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":19}} @@ -89,6 +90,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":54,"end":58,"loc":{"start":{"line":3,"column":15},"end":{"line":3,"column":19}} @@ -125,6 +127,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":74,"end":78,"loc":{"start":{"line":4,"column":14},"end":{"line":4,"column":18}} @@ -161,6 +164,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":91,"end":95,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":15}} @@ -197,6 +201,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":119,"end":123,"loc":{"start":{"line":6,"column":22},"end":{"line":6,"column":26}} @@ -233,6 +238,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":147,"end":151,"loc":{"start":{"line":7,"column":22},"end":{"line":7,"column":26}} @@ -269,6 +275,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":174,"end":178,"loc":{"start":{"line":8,"column":21},"end":{"line":8,"column":25}} @@ -305,6 +312,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":198,"end":202,"loc":{"start":{"line":9,"column":18},"end":{"line":9,"column":22}} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/declare-interface-method-reserved-word/output.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/declare-interface-method-reserved-word/output.json index b1a4c4bd1ddc..470c0092b769 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/declare-interface-method-reserved-word/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/declare-interface-method-reserved-word/output.json @@ -53,6 +53,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":37,"end":41,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":19}} @@ -89,6 +90,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":58,"end":62,"loc":{"start":{"line":3,"column":15},"end":{"line":3,"column":19}} @@ -125,6 +127,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":78,"end":82,"loc":{"start":{"line":4,"column":14},"end":{"line":4,"column":18}} @@ -161,6 +164,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":95,"end":99,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":15}} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/output.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/output.json index 767a8b87545a..615b9d52168f 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/default/output.json @@ -420,6 +420,10 @@ "expression": { "type": "ClassExpression", "start":297,"end":321,"loc":{"start":{"line":10,"column":2},"end":{"line":10,"column":26}}, + "extra": { + "parenthesized": true, + "parenStart": 296 + }, "id": { "type": "Identifier", "start":303,"end":306,"loc":{"start":{"line":10,"column":8},"end":{"line":10,"column":11},"identifierName":"A10"}, @@ -446,10 +450,6 @@ "type": "ClassBody", "start":319,"end":321,"loc":{"start":{"line":10,"column":24},"end":{"line":10,"column":26}}, "body": [] - }, - "extra": { - "parenthesized": true, - "parenStart": 296 } } }, @@ -459,6 +459,10 @@ "expression": { "type": "ClassExpression", "start":325,"end":358,"loc":{"start":{"line":11,"column":2},"end":{"line":11,"column":35}}, + "extra": { + "parenthesized": true, + "parenStart": 324 + }, "id": { "type": "Identifier", "start":331,"end":334,"loc":{"start":{"line":11,"column":8},"end":{"line":11,"column":11},"identifierName":"A11"}, @@ -497,10 +501,6 @@ "type": "ClassBody", "start":356,"end":358,"loc":{"start":{"line":11,"column":33},"end":{"line":11,"column":35}}, "body": [] - }, - "extra": { - "parenthesized": true, - "parenStart": 324 } } }, @@ -510,6 +510,10 @@ "expression": { "type": "ClassExpression", "start":362,"end":398,"loc":{"start":{"line":12,"column":2},"end":{"line":12,"column":38}}, + "extra": { + "parenthesized": true, + "parenStart": 361 + }, "id": { "type": "Identifier", "start":368,"end":371,"loc":{"start":{"line":12,"column":8},"end":{"line":12,"column":11},"identifierName":"A12"}, @@ -554,10 +558,6 @@ "type": "ClassBody", "start":396,"end":398,"loc":{"start":{"line":12,"column":36},"end":{"line":12,"column":38}}, "body": [] - }, - "extra": { - "parenthesized": true, - "parenStart": 361 } } }, @@ -567,6 +567,10 @@ "expression": { "type": "ClassExpression", "start":402,"end":447,"loc":{"start":{"line":13,"column":2},"end":{"line":13,"column":47}}, + "extra": { + "parenthesized": true, + "parenStart": 401 + }, "id": { "type": "Identifier", "start":408,"end":411,"loc":{"start":{"line":13,"column":8},"end":{"line":13,"column":11},"identifierName":"A13"}, @@ -615,10 +619,6 @@ "type": "ClassBody", "start":445,"end":447,"loc":{"start":{"line":13,"column":45},"end":{"line":13,"column":47}}, "body": [] - }, - "extra": { - "parenthesized": true, - "parenStart": 401 } } }, @@ -1101,6 +1101,10 @@ "expression": { "type": "ObjectExpression", "start":836,"end":860,"loc":{"start":{"line":24,"column":2},"end":{"line":24,"column":26}}, + "extra": { + "parenthesized": true, + "parenStart": 835 + }, "properties": [ { "type": "ObjectMethod", @@ -1140,11 +1144,7 @@ ] } } - ], - "extra": { - "parenthesized": true, - "parenStart": 835 - } + ] } }, { @@ -1211,6 +1211,10 @@ "expression": { "type": "ClassExpression", "start":902,"end":938,"loc":{"start":{"line":28,"column":2},"end":{"line":30,"column":1}}, + "extra": { + "parenthesized": true, + "parenStart": 901 + }, "id": { "type": "Identifier", "start":908,"end":911,"loc":{"start":{"line":28,"column":8},"end":{"line":28,"column":11},"identifierName":"A30"}, @@ -1260,10 +1264,6 @@ } } ] - }, - "extra": { - "parenthesized": true, - "parenStart": 901 } } }, @@ -1317,6 +1317,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":980,"end":984,"loc":{"start":{"line":31,"column":39},"end":{"line":31,"column":43}} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/interface-reserved-word/output.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/interface-reserved-word/output.json index fc8e1f196b8f..6b114cbbac93 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/interface-reserved-word/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/interface-reserved-word/output.json @@ -53,6 +53,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":29,"end":33,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":19}} @@ -89,6 +90,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":50,"end":54,"loc":{"start":{"line":3,"column":15},"end":{"line":3,"column":19}} @@ -125,6 +127,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":70,"end":74,"loc":{"start":{"line":4,"column":14},"end":{"line":4,"column":18}} @@ -161,6 +164,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":87,"end":91,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":15}} diff --git a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/type-object-reserved-word/output.json b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/type-object-reserved-word/output.json index 86e2ee528e18..093870a8b238 100644 --- a/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/type-object-reserved-word/output.json +++ b/packages/babel-parser/test/fixtures/flow/type-parameter-declaration/type-object-reserved-word/output.json @@ -50,6 +50,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":26,"end":30,"loc":{"start":{"line":2,"column":15},"end":{"line":2,"column":19}} @@ -86,6 +87,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":47,"end":51,"loc":{"start":{"line":3,"column":15},"end":{"line":3,"column":19}} @@ -122,6 +124,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":67,"end":71,"loc":{"start":{"line":4,"column":14},"end":{"line":4,"column":18}} @@ -158,6 +161,7 @@ } ] }, + "this": null, "returnType": { "type": "VoidTypeAnnotation", "start":84,"end":88,"loc":{"start":{"line":5,"column":11},"end":{"line":5,"column":15}} diff --git a/packages/babel-parser/test/fixtures/flow/typecasts/3/output.json b/packages/babel-parser/test/fixtures/flow/typecasts/3/output.json index 0e3ddeef5439..abd3347382a6 100644 --- a/packages/babel-parser/test/fixtures/flow/typecasts/3/output.json +++ b/packages/babel-parser/test/fixtures/flow/typecasts/3/output.json @@ -13,6 +13,10 @@ "expression": { "type": "TypeCastExpression", "start":1,"end":42,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":42}}, + "extra": { + "parenthesized": true, + "parenStart": 0 + }, "expression": { "type": "ArrowFunctionExpression", "start":1,"end":17,"loc":{"start":{"line":1,"column":1},"end":{"line":1,"column":17}}, @@ -69,16 +73,13 @@ } ], "rest": null, + "this": null, "returnType": { "type": "NumberTypeAnnotation", "start":36,"end":42,"loc":{"start":{"line":1,"column":36},"end":{"line":1,"column":42}} }, "typeParameters": null } - }, - "extra": { - "parenthesized": true, - "parenStart": 0 } } } diff --git a/packages/babel-plugin-transform-flow-strip-types/src/index.js b/packages/babel-plugin-transform-flow-strip-types/src/index.js index a5e0fed85d66..5d293ae474aa 100644 --- a/packages/babel-plugin-transform-flow-strip-types/src/index.js +++ b/packages/babel-plugin-transform-flow-strip-types/src/index.js @@ -130,6 +130,13 @@ export default declare((api, opts) => { Function({ node }) { if (skipStrip) return; + if ( + node.params.length > 0 && + node.params[0].type === "Identifier" && + node.params[0].name === "this" + ) { + node.params.shift(); + } for (let i = 0; i < node.params.length; i++) { const param = node.params[i]; param.optional = false; diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-this-param/input.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-this-param/input.js new file mode 100644 index 000000000000..0f879d0068d2 --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-this-param/input.js @@ -0,0 +1,26 @@ +function one (this : number) {} +function two (this : number, a) {} +function three (this : number, ...a) {} +function four (this : number, a, b, ...c) {} +function five (this : T) {} + +type six = (this : number) => void +type seven = { o(this : string) : void } +declare function eight (this : number) : void +declare class Nine { m (this : number) : void } + +class Ten { + m1 (this : number) {} + m2 (this : number, a) {} + m3 (this : number, ...a) {} + m4 (this : number, a, b, ...c) {} + m5 (this : T) {} +} + +let eleven = { + m1 (this : number) {}, + m2 (this : number, a) {}, + m3 (this : number, ...a) {}, + m4 (this : number, a, b, ...c) {}, + m5 (this : T) {} +} diff --git a/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-this-param/output.js b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-this-param/output.js new file mode 100644 index 000000000000..4111c826911e --- /dev/null +++ b/packages/babel-plugin-transform-flow-strip-types/test/fixtures/strip-types/strip-this-param/output.js @@ -0,0 +1,35 @@ +function one() {} + +function two(a) {} + +function three(...a) {} + +function four(a, b, ...c) {} + +function five() {} + +class Ten { + m1() {} + + m2(a) {} + + m3(...a) {} + + m4(a, b, ...c) {} + + m5() {} + +} + +let eleven = { + m1() {}, + + m2(a) {}, + + m3(...a) {}, + + m4(a, b, ...c) {}, + + m5() {} + +}; diff --git a/packages/babel-plugin-transform-parameters/test/fixtures/parameters/flow-this-param/input.js b/packages/babel-plugin-transform-parameters/test/fixtures/parameters/flow-this-param/input.js new file mode 100644 index 000000000000..0fc352021e80 --- /dev/null +++ b/packages/babel-plugin-transform-parameters/test/fixtures/parameters/flow-this-param/input.js @@ -0,0 +1,3 @@ +function foo (this : number, x : number, y : string, ...z : any) { + x + y + z[0]; +} diff --git a/packages/babel-plugin-transform-parameters/test/fixtures/parameters/flow-this-param/output.js b/packages/babel-plugin-transform-parameters/test/fixtures/parameters/flow-this-param/output.js new file mode 100644 index 000000000000..79906598b753 --- /dev/null +++ b/packages/babel-plugin-transform-parameters/test/fixtures/parameters/flow-this-param/output.js @@ -0,0 +1,3 @@ +function foo(this: number, x: number, y: string) { + x + y + (arguments.length <= 2 ? undefined : arguments[2]); +} diff --git a/packages/babel-types/src/ast-types/generated/index.ts b/packages/babel-types/src/ast-types/generated/index.ts index ae461bbae0d0..1fcc394c8cf6 100755 --- a/packages/babel-types/src/ast-types/generated/index.ts +++ b/packages/babel-types/src/ast-types/generated/index.ts @@ -1118,6 +1118,7 @@ export interface FunctionTypeAnnotation extends BaseNode { params: Array; rest?: FunctionTypeParam | null; returnType: FlowType; + this?: FunctionTypeParam | null; } export interface FunctionTypeParam extends BaseNode { diff --git a/packages/babel-types/src/definitions/flow.ts b/packages/babel-types/src/definitions/flow.ts index bb1015d18c0c..9204fe10b257 100644 --- a/packages/babel-types/src/definitions/flow.ts +++ b/packages/babel-types/src/definitions/flow.ts @@ -173,6 +173,7 @@ defineType("FunctionTypeAnnotation", { typeParameters: validateOptionalType("TypeParameterDeclaration"), params: validate(arrayOfType("FunctionTypeParam")), rest: validateOptionalType("FunctionTypeParam"), + this: validateOptionalType("FunctionTypeParam"), returnType: validateType("FlowType"), }, });