diff --git a/src/acorn/plugins/flow.js b/src/acorn/plugins/flow.js index 189395b6fa..c4b8490829 100644 --- a/src/acorn/plugins/flow.js +++ b/src/acorn/plugins/flow.js @@ -415,6 +415,9 @@ pp.flow_identToTypeAnnotation = function (start, node, id) { case "boolean": return this.finishNode(node, "BooleanTypeAnnotation") + case "mixed": + return this.finishNode(node, "MixedTypeAnnotation") + case "number": return this.finishNode(node, "NumberTypeAnnotation") diff --git a/src/babel/generation/generators/flow.js b/src/babel/generation/generators/flow.js index 44c147e65d..3685c076bc 100644 --- a/src/babel/generation/generators/flow.js +++ b/src/babel/generation/generators/flow.js @@ -103,6 +103,10 @@ export function IntersectionTypeAnnotation(node, print) { print.join(node.types, { separator: " & " }); } +export function MixedTypeAnnotation() { + this.push("mixed"); +} + export function NullableTypeAnnotation(node, print) { this.push("?"); print.plain(node.typeAnnotation); diff --git a/src/babel/types/alias-keys.json b/src/babel/types/alias-keys.json index 901df4ae94..649c56586b 100644 --- a/src/babel/types/alias-keys.json +++ b/src/babel/types/alias-keys.json @@ -93,6 +93,7 @@ "InterfaceExtends": ["Flow"], "InterfaceDeclaration": ["Flow", "Statement", "Declaration"], "IntersectionTypeAnnotation": ["Flow"], + "MixedTypeAnnotation": ["Flow"], "NullableTypeAnnotation": ["Flow"], "NumberTypeAnnotation": ["Flow"], "StringLiteralTypeAnnotation": ["Flow"], diff --git a/src/babel/types/visitor-keys.json b/src/babel/types/visitor-keys.json index 0dc2d97b6e..7fbb4fdef6 100644 --- a/src/babel/types/visitor-keys.json +++ b/src/babel/types/visitor-keys.json @@ -91,6 +91,7 @@ "InterfaceExtends": ["id", "typeParameters"], "InterfaceDeclaration": ["id", "typeParameters", "extends", "body"], "IntersectionTypeAnnotation": ["types"], + "MixedTypeAnnotation": [], "NullableTypeAnnotation": ["typeAnnotation"], "NumberTypeAnnotation": [], "StringLiteralTypeAnnotation": [], diff --git a/test/acorn/tests-flow.js b/test/acorn/tests-flow.js index 77bb2a4841..9092d98028 100644 --- a/test/acorn/tests-flow.js +++ b/test/acorn/tests-flow.js @@ -2,7 +2,7 @@ var fbTestFixture = { 'Type Annotations': { - 'function foo(numVal: any){}': { + 'function foo(numVal: any, otherVal: mixed){}': { type: 'FunctionDeclaration', id: { type: 'Identifier', @@ -37,22 +37,47 @@ var fbTestFixture = { start: { line: 1, column: 13 }, end: { line: 1, column: 24 } } + }, + { + type: 'Identifier', + name: 'otherVal', + typeAnnotation: { + type: 'TypeAnnotation', + typeAnnotation: { + type: 'MixedTypeAnnotation', + range: [36, 41], + loc: { + start: { line: 1, column: 36 }, + end: { line: 1, column: 41 } + } + }, + range: [34, 41], + loc: { + start: { line: 1, column: 34 }, + end: { line: 1, column: 41 } + } + }, + range: [26, 41], + loc: { + start: { line: 1, column: 26 }, + end: { line: 1, column: 41 } + } }], body: { type: 'BlockStatement', body: [], - range: [25, 27], + range: [42, 44], loc: { - start: { line: 1, column: 25 }, - end: { line: 1, column: 27 } + start: { line: 1, column: 42 }, + end: { line: 1, column: 44 } } }, generator: false, expression: false, - range: [0, 27], + range: [0, 44], loc: { start: { line: 1, column: 0 }, - end: { line: 1, column: 27 } + end: { line: 1, column: 44 } } }, 'function foo(numVal: number){}': {