diff --git a/src/plugins/flow.js b/src/plugins/flow.js index 69139859fc..95cbefe4f7 100644 --- a/src/plugins/flow.js +++ b/src/plugins/flow.js @@ -335,7 +335,7 @@ pp.flowParseObjectTypeCallProperty = function (node, isStatic) { return this.finishNode(node, "ObjectTypeCallProperty"); }; -pp.flowParseObjectType = function (allowStatic) { +pp.flowParseObjectType = function (allowStatic, allowExact) { let nodeStart = this.startNode(); let node; let propertyKey; @@ -345,9 +345,21 @@ pp.flowParseObjectType = function (allowStatic) { nodeStart.properties = []; nodeStart.indexers = []; - this.expect(tt.braceL); + let endDelim; + let exact; + if (allowExact && this.match(tt.braceBarL)) { + this.expect(tt.braceBarL); + endDelim = tt.braceBarR; + exact = true; + } else { + this.expect(tt.braceL); + endDelim = tt.braceR; + exact = false; + } - while (!this.match(tt.braceR)) { + nodeStart.exact = exact; + + while (!this.match(endDelim)) { let optional = false; let startPos = this.state.start, startLoc = this.state.startLoc; node = this.startNode(); @@ -383,13 +395,14 @@ pp.flowParseObjectType = function (allowStatic) { } } - this.expect(tt.braceR); + this.expect(endDelim); return this.finishNode(nodeStart, "ObjectTypeAnnotation"); }; pp.flowObjectTypeSemicolon = function () { - if (!this.eat(tt.semi) && !this.eat(tt.comma) && !this.match(tt.braceR)) { + if (!this.eat(tt.semi) && !this.eat(tt.comma) && + !this.match(tt.braceR) && !this.match(tt.braceBarR)) { this.unexpected(); } }; @@ -510,7 +523,10 @@ pp.flowParsePrimaryType = function () { return this.flowIdentToTypeAnnotation(startPos, startLoc, node, this.parseIdentifier()); case tt.braceL: - return this.flowParseObjectType(); + return this.flowParseObjectType(false, false); + + case tt.braceBarL: + return this.flowParseObjectType(false, true); case tt.bracketL: return this.flowParseTupleType(); diff --git a/src/tokenizer/index.js b/src/tokenizer/index.js index 859735ba80..bd9a9403b7 100644 --- a/src/tokenizer/index.js +++ b/src/tokenizer/index.js @@ -322,6 +322,7 @@ export default class Tokenizer { let next = this.input.charCodeAt(this.state.pos + 1); if (next === code) return this.finishOp(code === 124 ? tt.logicalOR : tt.logicalAND, 2); if (next === 61) return this.finishOp(tt.assign, 2); + if (code === 124 && next === 125 && this.hasPlugin("flow")) return this.finishOp(tt.braceBarR, 2); return this.finishOp(code === 124 ? tt.bitwiseOR : tt.bitwiseAND, 1); } @@ -404,8 +405,17 @@ export default class Tokenizer { case 44: ++this.state.pos; return this.finishToken(tt.comma); case 91: ++this.state.pos; return this.finishToken(tt.bracketL); case 93: ++this.state.pos; return this.finishToken(tt.bracketR); - case 123: ++this.state.pos; return this.finishToken(tt.braceL); - case 125: ++this.state.pos; return this.finishToken(tt.braceR); + + case 123: + if (this.hasPlugin("flow") && this.input.charCodeAt(this.state.pos + 1) === 124) { + return this.finishOp(tt.braceBarL, 2); + } else { + ++this.state.pos; + return this.finishToken(tt.braceL); + } + + case 125: + ++this.state.pos; return this.finishToken(tt.braceR); case 58: if (this.hasPlugin("functionBind") && this.input.charCodeAt(this.state.pos + 1) === 58) { diff --git a/src/tokenizer/types.js b/src/tokenizer/types.js index c97e829287..86d49e10cb 100644 --- a/src/tokenizer/types.js +++ b/src/tokenizer/types.js @@ -48,7 +48,9 @@ export const types = { bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}), bracketR: new TokenType("]"), braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}), + braceBarL: new TokenType("{|", {beforeExpr: true, startsExpr: true}), braceR: new TokenType("}"), + braceBarR: new TokenType("|}"), parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}), parenR: new TokenType(")"), comma: new TokenType(",", beforeExpr), diff --git a/test/fixtures/flow/type-annotations/107/expected.json b/test/fixtures/flow/type-annotations/107/expected.json index 9f972ee738..b17400628a 100644 --- a/test/fixtures/flow/type-annotations/107/expected.json +++ b/test/fixtures/flow/type-annotations/107/expected.json @@ -256,4 +256,4 @@ ], "directives": [] } -} \ No newline at end of file +} diff --git a/test/fixtures/flow/type-annotations/108/actual.js b/test/fixtures/flow/type-annotations/108/actual.js new file mode 100644 index 0000000000..331128f97f --- /dev/null +++ b/test/fixtures/flow/type-annotations/108/actual.js @@ -0,0 +1,5 @@ +var a : {| x: number, y: string |} = { x: 0, y: 'foo' }; +var b : {| x: number, y: string, |} = { x: 0, y: 'foo' }; +var c : {| |} = {}; +var d : { a: {| x: number, y: string |}, b: boolean } = { a: { x: 0, y: 'foo' }, b: false }; +var e : {| a: { x: number, y: string }, b: boolean |} = { a: { x: 0, y: 'foo' }, b: false }; diff --git a/test/fixtures/flow/type-annotations/108/expected.json b/test/fixtures/flow/type-annotations/108/expected.json new file mode 100644 index 0000000000..c76a2032ef --- /dev/null +++ b/test/fixtures/flow/type-annotations/108/expected.json @@ -0,0 +1,1774 @@ +{ + "type": "File", + "start": 0, + "end": 320, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 92 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 320, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 5, + "column": 92 + } + }, + "sourceType": "module", + "body": [ + { + "type": "VariableDeclaration", + "start": 0, + "end": 56, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 56 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 4, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 55 + } + }, + "id": { + "type": "Identifier", + "start": 4, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 4 + }, + "end": { + "line": 1, + "column": 34 + }, + "identifierName": "a" + }, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 6, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 6 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "typeAnnotation": { + "type": "ObjectTypeAnnotation", + "start": 8, + "end": 34, + "loc": { + "start": { + "line": 1, + "column": 8 + }, + "end": { + "line": 1, + "column": 34 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 11, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "key": { + "type": "Identifier", + "start": 11, + "end": 12, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 12 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "NumberTypeAnnotation", + "start": 14, + "end": 20, + "loc": { + "start": { + "line": 1, + "column": 14 + }, + "end": { + "line": 1, + "column": 20 + } + } + }, + "optional": false + }, + { + "type": "ObjectTypeProperty", + "start": 22, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 31 + } + }, + "key": { + "type": "Identifier", + "start": 22, + "end": 23, + "loc": { + "start": { + "line": 1, + "column": 22 + }, + "end": { + "line": 1, + "column": 23 + }, + "identifierName": "y" + }, + "name": "y" + }, + "value": { + "type": "StringTypeAnnotation", + "start": 25, + "end": 31, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 31 + } + } + }, + "optional": false + } + ], + "indexers": [], + "exact": true + } + } + }, + "init": { + "type": "ObjectExpression", + "start": 37, + "end": 55, + "loc": { + "start": { + "line": 1, + "column": 37 + }, + "end": { + "line": 1, + "column": 55 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 39, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 39, + "end": 40, + "loc": { + "start": { + "line": 1, + "column": 39 + }, + "end": { + "line": 1, + "column": 40 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "NumericLiteral", + "start": 42, + "end": 43, + "loc": { + "start": { + "line": 1, + "column": 42 + }, + "end": { + "line": 1, + "column": 43 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ObjectProperty", + "start": 45, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 45 + }, + "end": { + "line": 1, + "column": 53 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 45, + "end": 46, + "loc": { + "start": { + "line": 1, + "column": 45 + }, + "end": { + "line": 1, + "column": 46 + }, + "identifierName": "y" + }, + "name": "y" + }, + "value": { + "type": "StringLiteral", + "start": 48, + "end": 53, + "loc": { + "start": { + "line": 1, + "column": 48 + }, + "end": { + "line": 1, + "column": 53 + } + }, + "extra": { + "rawValue": "foo", + "raw": "'foo'" + }, + "value": "foo" + } + } + ] + } + } + ], + "kind": "var" + }, + { + "type": "VariableDeclaration", + "start": 57, + "end": 114, + "loc": { + "start": { + "line": 2, + "column": 0 + }, + "end": { + "line": 2, + "column": 57 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 61, + "end": 113, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 56 + } + }, + "id": { + "type": "Identifier", + "start": 61, + "end": 92, + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 35 + }, + "identifierName": "b" + }, + "name": "b", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 63, + "end": 92, + "loc": { + "start": { + "line": 2, + "column": 6 + }, + "end": { + "line": 2, + "column": 35 + } + }, + "typeAnnotation": { + "type": "ObjectTypeAnnotation", + "start": 65, + "end": 92, + "loc": { + "start": { + "line": 2, + "column": 8 + }, + "end": { + "line": 2, + "column": 35 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 68, + "end": 78, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 21 + } + }, + "key": { + "type": "Identifier", + "start": 68, + "end": 69, + "loc": { + "start": { + "line": 2, + "column": 11 + }, + "end": { + "line": 2, + "column": 12 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "NumberTypeAnnotation", + "start": 71, + "end": 77, + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 20 + } + } + }, + "optional": false + }, + { + "type": "ObjectTypeProperty", + "start": 79, + "end": 89, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 32 + } + }, + "key": { + "type": "Identifier", + "start": 79, + "end": 80, + "loc": { + "start": { + "line": 2, + "column": 22 + }, + "end": { + "line": 2, + "column": 23 + }, + "identifierName": "y" + }, + "name": "y" + }, + "value": { + "type": "StringTypeAnnotation", + "start": 82, + "end": 88, + "loc": { + "start": { + "line": 2, + "column": 25 + }, + "end": { + "line": 2, + "column": 31 + } + } + }, + "optional": false + } + ], + "indexers": [], + "exact": true + } + } + }, + "init": { + "type": "ObjectExpression", + "start": 95, + "end": 113, + "loc": { + "start": { + "line": 2, + "column": 38 + }, + "end": { + "line": 2, + "column": 56 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 97, + "end": 101, + "loc": { + "start": { + "line": 2, + "column": 40 + }, + "end": { + "line": 2, + "column": 44 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 97, + "end": 98, + "loc": { + "start": { + "line": 2, + "column": 40 + }, + "end": { + "line": 2, + "column": 41 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "NumericLiteral", + "start": 100, + "end": 101, + "loc": { + "start": { + "line": 2, + "column": 43 + }, + "end": { + "line": 2, + "column": 44 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ObjectProperty", + "start": 103, + "end": 111, + "loc": { + "start": { + "line": 2, + "column": 46 + }, + "end": { + "line": 2, + "column": 54 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 103, + "end": 104, + "loc": { + "start": { + "line": 2, + "column": 46 + }, + "end": { + "line": 2, + "column": 47 + }, + "identifierName": "y" + }, + "name": "y" + }, + "value": { + "type": "StringLiteral", + "start": 106, + "end": 111, + "loc": { + "start": { + "line": 2, + "column": 49 + }, + "end": { + "line": 2, + "column": 54 + } + }, + "extra": { + "rawValue": "foo", + "raw": "'foo'" + }, + "value": "foo" + } + } + ] + } + } + ], + "kind": "var" + }, + { + "type": "VariableDeclaration", + "start": 115, + "end": 134, + "loc": { + "start": { + "line": 3, + "column": 0 + }, + "end": { + "line": 3, + "column": 19 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 119, + "end": 133, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "id": { + "type": "Identifier", + "start": 119, + "end": 128, + "loc": { + "start": { + "line": 3, + "column": 4 + }, + "end": { + "line": 3, + "column": 13 + }, + "identifierName": "c" + }, + "name": "c", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 121, + "end": 128, + "loc": { + "start": { + "line": 3, + "column": 6 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "typeAnnotation": { + "type": "ObjectTypeAnnotation", + "start": 123, + "end": 128, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "callProperties": [], + "properties": [], + "indexers": [], + "exact": true + } + } + }, + "init": { + "type": "ObjectExpression", + "start": 131, + "end": 133, + "loc": { + "start": { + "line": 3, + "column": 16 + }, + "end": { + "line": 3, + "column": 18 + } + }, + "properties": [] + } + } + ], + "kind": "var" + }, + { + "type": "VariableDeclaration", + "start": 135, + "end": 227, + "loc": { + "start": { + "line": 4, + "column": 0 + }, + "end": { + "line": 4, + "column": 92 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 139, + "end": 226, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 91 + } + }, + "id": { + "type": "Identifier", + "start": 139, + "end": 188, + "loc": { + "start": { + "line": 4, + "column": 4 + }, + "end": { + "line": 4, + "column": 53 + }, + "identifierName": "d" + }, + "name": "d", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 141, + "end": 188, + "loc": { + "start": { + "line": 4, + "column": 6 + }, + "end": { + "line": 4, + "column": 53 + } + }, + "typeAnnotation": { + "type": "ObjectTypeAnnotation", + "start": 143, + "end": 188, + "loc": { + "start": { + "line": 4, + "column": 8 + }, + "end": { + "line": 4, + "column": 53 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 145, + "end": 175, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 40 + } + }, + "key": { + "type": "Identifier", + "start": 145, + "end": 146, + "loc": { + "start": { + "line": 4, + "column": 10 + }, + "end": { + "line": 4, + "column": 11 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "ObjectTypeAnnotation", + "start": 148, + "end": 174, + "loc": { + "start": { + "line": 4, + "column": 13 + }, + "end": { + "line": 4, + "column": 39 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 151, + "end": 161, + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 26 + } + }, + "key": { + "type": "Identifier", + "start": 151, + "end": 152, + "loc": { + "start": { + "line": 4, + "column": 16 + }, + "end": { + "line": 4, + "column": 17 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "NumberTypeAnnotation", + "start": 154, + "end": 160, + "loc": { + "start": { + "line": 4, + "column": 19 + }, + "end": { + "line": 4, + "column": 25 + } + } + }, + "optional": false + }, + { + "type": "ObjectTypeProperty", + "start": 162, + "end": 171, + "loc": { + "start": { + "line": 4, + "column": 27 + }, + "end": { + "line": 4, + "column": 36 + } + }, + "key": { + "type": "Identifier", + "start": 162, + "end": 163, + "loc": { + "start": { + "line": 4, + "column": 27 + }, + "end": { + "line": 4, + "column": 28 + }, + "identifierName": "y" + }, + "name": "y" + }, + "value": { + "type": "StringTypeAnnotation", + "start": 165, + "end": 171, + "loc": { + "start": { + "line": 4, + "column": 30 + }, + "end": { + "line": 4, + "column": 36 + } + } + }, + "optional": false + } + ], + "indexers": [], + "exact": true + }, + "optional": false + }, + { + "type": "ObjectTypeProperty", + "start": 176, + "end": 186, + "loc": { + "start": { + "line": 4, + "column": 41 + }, + "end": { + "line": 4, + "column": 51 + } + }, + "key": { + "type": "Identifier", + "start": 176, + "end": 177, + "loc": { + "start": { + "line": 4, + "column": 41 + }, + "end": { + "line": 4, + "column": 42 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "BooleanTypeAnnotation", + "start": 179, + "end": 186, + "loc": { + "start": { + "line": 4, + "column": 44 + }, + "end": { + "line": 4, + "column": 51 + } + } + }, + "optional": false + } + ], + "indexers": [], + "exact": false + } + } + }, + "init": { + "type": "ObjectExpression", + "start": 191, + "end": 226, + "loc": { + "start": { + "line": 4, + "column": 56 + }, + "end": { + "line": 4, + "column": 91 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 193, + "end": 214, + "loc": { + "start": { + "line": 4, + "column": 58 + }, + "end": { + "line": 4, + "column": 79 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 193, + "end": 194, + "loc": { + "start": { + "line": 4, + "column": 58 + }, + "end": { + "line": 4, + "column": 59 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "ObjectExpression", + "start": 196, + "end": 214, + "loc": { + "start": { + "line": 4, + "column": 61 + }, + "end": { + "line": 4, + "column": 79 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 198, + "end": 202, + "loc": { + "start": { + "line": 4, + "column": 63 + }, + "end": { + "line": 4, + "column": 67 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 198, + "end": 199, + "loc": { + "start": { + "line": 4, + "column": 63 + }, + "end": { + "line": 4, + "column": 64 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "NumericLiteral", + "start": 201, + "end": 202, + "loc": { + "start": { + "line": 4, + "column": 66 + }, + "end": { + "line": 4, + "column": 67 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ObjectProperty", + "start": 204, + "end": 212, + "loc": { + "start": { + "line": 4, + "column": 69 + }, + "end": { + "line": 4, + "column": 77 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 204, + "end": 205, + "loc": { + "start": { + "line": 4, + "column": 69 + }, + "end": { + "line": 4, + "column": 70 + }, + "identifierName": "y" + }, + "name": "y" + }, + "value": { + "type": "StringLiteral", + "start": 207, + "end": 212, + "loc": { + "start": { + "line": 4, + "column": 72 + }, + "end": { + "line": 4, + "column": 77 + } + }, + "extra": { + "rawValue": "foo", + "raw": "'foo'" + }, + "value": "foo" + } + } + ] + } + }, + { + "type": "ObjectProperty", + "start": 216, + "end": 224, + "loc": { + "start": { + "line": 4, + "column": 81 + }, + "end": { + "line": 4, + "column": 89 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 216, + "end": 217, + "loc": { + "start": { + "line": 4, + "column": 81 + }, + "end": { + "line": 4, + "column": 82 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "BooleanLiteral", + "start": 219, + "end": 224, + "loc": { + "start": { + "line": 4, + "column": 84 + }, + "end": { + "line": 4, + "column": 89 + } + }, + "value": false + } + } + ] + } + } + ], + "kind": "var" + }, + { + "type": "VariableDeclaration", + "start": 228, + "end": 320, + "loc": { + "start": { + "line": 5, + "column": 0 + }, + "end": { + "line": 5, + "column": 92 + } + }, + "declarations": [ + { + "type": "VariableDeclarator", + "start": 232, + "end": 319, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 91 + } + }, + "id": { + "type": "Identifier", + "start": 232, + "end": 281, + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 53 + }, + "identifierName": "e" + }, + "name": "e", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 234, + "end": 281, + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 53 + } + }, + "typeAnnotation": { + "type": "ObjectTypeAnnotation", + "start": 236, + "end": 281, + "loc": { + "start": { + "line": 5, + "column": 8 + }, + "end": { + "line": 5, + "column": 53 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 239, + "end": 267, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 39 + } + }, + "key": { + "type": "Identifier", + "start": 239, + "end": 240, + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 12 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "ObjectTypeAnnotation", + "start": 242, + "end": 266, + "loc": { + "start": { + "line": 5, + "column": 14 + }, + "end": { + "line": 5, + "column": 38 + } + }, + "callProperties": [], + "properties": [ + { + "type": "ObjectTypeProperty", + "start": 244, + "end": 254, + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 26 + } + }, + "key": { + "type": "Identifier", + "start": 244, + "end": 245, + "loc": { + "start": { + "line": 5, + "column": 16 + }, + "end": { + "line": 5, + "column": 17 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "NumberTypeAnnotation", + "start": 247, + "end": 253, + "loc": { + "start": { + "line": 5, + "column": 19 + }, + "end": { + "line": 5, + "column": 25 + } + } + }, + "optional": false + }, + { + "type": "ObjectTypeProperty", + "start": 255, + "end": 264, + "loc": { + "start": { + "line": 5, + "column": 27 + }, + "end": { + "line": 5, + "column": 36 + } + }, + "key": { + "type": "Identifier", + "start": 255, + "end": 256, + "loc": { + "start": { + "line": 5, + "column": 27 + }, + "end": { + "line": 5, + "column": 28 + }, + "identifierName": "y" + }, + "name": "y" + }, + "value": { + "type": "StringTypeAnnotation", + "start": 258, + "end": 264, + "loc": { + "start": { + "line": 5, + "column": 30 + }, + "end": { + "line": 5, + "column": 36 + } + } + }, + "optional": false + } + ], + "indexers": [], + "exact": false + }, + "optional": false + }, + { + "type": "ObjectTypeProperty", + "start": 268, + "end": 278, + "loc": { + "start": { + "line": 5, + "column": 40 + }, + "end": { + "line": 5, + "column": 50 + } + }, + "key": { + "type": "Identifier", + "start": 268, + "end": 269, + "loc": { + "start": { + "line": 5, + "column": 40 + }, + "end": { + "line": 5, + "column": 41 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "BooleanTypeAnnotation", + "start": 271, + "end": 278, + "loc": { + "start": { + "line": 5, + "column": 43 + }, + "end": { + "line": 5, + "column": 50 + } + } + }, + "optional": false + } + ], + "indexers": [], + "exact": true + } + } + }, + "init": { + "type": "ObjectExpression", + "start": 284, + "end": 319, + "loc": { + "start": { + "line": 5, + "column": 56 + }, + "end": { + "line": 5, + "column": 91 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 286, + "end": 307, + "loc": { + "start": { + "line": 5, + "column": 58 + }, + "end": { + "line": 5, + "column": 79 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 286, + "end": 287, + "loc": { + "start": { + "line": 5, + "column": 58 + }, + "end": { + "line": 5, + "column": 59 + }, + "identifierName": "a" + }, + "name": "a" + }, + "value": { + "type": "ObjectExpression", + "start": 289, + "end": 307, + "loc": { + "start": { + "line": 5, + "column": 61 + }, + "end": { + "line": 5, + "column": 79 + } + }, + "properties": [ + { + "type": "ObjectProperty", + "start": 291, + "end": 295, + "loc": { + "start": { + "line": 5, + "column": 63 + }, + "end": { + "line": 5, + "column": 67 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 291, + "end": 292, + "loc": { + "start": { + "line": 5, + "column": 63 + }, + "end": { + "line": 5, + "column": 64 + }, + "identifierName": "x" + }, + "name": "x" + }, + "value": { + "type": "NumericLiteral", + "start": 294, + "end": 295, + "loc": { + "start": { + "line": 5, + "column": 66 + }, + "end": { + "line": 5, + "column": 67 + } + }, + "extra": { + "rawValue": 0, + "raw": "0" + }, + "value": 0 + } + }, + { + "type": "ObjectProperty", + "start": 297, + "end": 305, + "loc": { + "start": { + "line": 5, + "column": 69 + }, + "end": { + "line": 5, + "column": 77 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 297, + "end": 298, + "loc": { + "start": { + "line": 5, + "column": 69 + }, + "end": { + "line": 5, + "column": 70 + }, + "identifierName": "y" + }, + "name": "y" + }, + "value": { + "type": "StringLiteral", + "start": 300, + "end": 305, + "loc": { + "start": { + "line": 5, + "column": 72 + }, + "end": { + "line": 5, + "column": 77 + } + }, + "extra": { + "rawValue": "foo", + "raw": "'foo'" + }, + "value": "foo" + } + } + ] + } + }, + { + "type": "ObjectProperty", + "start": 309, + "end": 317, + "loc": { + "start": { + "line": 5, + "column": 81 + }, + "end": { + "line": 5, + "column": 89 + } + }, + "method": false, + "shorthand": false, + "computed": false, + "key": { + "type": "Identifier", + "start": 309, + "end": 310, + "loc": { + "start": { + "line": 5, + "column": 81 + }, + "end": { + "line": 5, + "column": 82 + }, + "identifierName": "b" + }, + "name": "b" + }, + "value": { + "type": "BooleanLiteral", + "start": 312, + "end": 317, + "loc": { + "start": { + "line": 5, + "column": 84 + }, + "end": { + "line": 5, + "column": 89 + } + }, + "value": false + } + } + ] + } + } + ], + "kind": "var" + } + ], + "directives": [] + } +} \ No newline at end of file diff --git a/test/fixtures/flow/type-annotations/109/actual.js b/test/fixtures/flow/type-annotations/109/actual.js new file mode 100644 index 0000000000..1923151279 --- /dev/null +++ b/test/fixtures/flow/type-annotations/109/actual.js @@ -0,0 +1 @@ +var a : { x: number{ y: string } } = { x: 0, y: 'foo' }; diff --git a/test/fixtures/flow/type-annotations/109/options.json b/test/fixtures/flow/type-annotations/109/options.json new file mode 100644 index 0000000000..d5583f7bc5 --- /dev/null +++ b/test/fixtures/flow/type-annotations/109/options.json @@ -0,0 +1,3 @@ +{ + "throws": "Unexpected token (1:19)" +}