From 34a82f716e8274cce1b4d8db195a70053b395200 Mon Sep 17 00:00:00 2001 From: Daniel Tschinder Date: Wed, 6 Jul 2016 23:48:47 +0200 Subject: [PATCH] Fix the location of params, when flow and default value used (#68) Fixes #67 --- src/parser/lval.js | 2 +- .../flow/type-annotations/105/actual.js | 1 + .../flow/type-annotations/105/expected.json | 249 ++++++++++++++++++ 3 files changed, 251 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/flow/type-annotations/105/actual.js create mode 100644 test/fixtures/flow/type-annotations/105/expected.json diff --git a/src/parser/lval.js b/src/parser/lval.js index e3b485eb71..fb23747094 100644 --- a/src/parser/lval.js +++ b/src/parser/lval.js @@ -171,7 +171,7 @@ pp.parseBindingList = function (close, allowEmpty, allowTrailingComma) { left.decorators = decorators; } this.parseAssignableListItemTypes(left); - elts.push(this.parseMaybeDefault(null, null, left)); + elts.push(this.parseMaybeDefault(left.start, left.loc.start, left)); } } return elts; diff --git a/test/fixtures/flow/type-annotations/105/actual.js b/test/fixtures/flow/type-annotations/105/actual.js new file mode 100644 index 0000000000..457dd3366d --- /dev/null +++ b/test/fixtures/flow/type-annotations/105/actual.js @@ -0,0 +1 @@ +function g(a:number=1, e=1:number) {} diff --git a/test/fixtures/flow/type-annotations/105/expected.json b/test/fixtures/flow/type-annotations/105/expected.json new file mode 100644 index 0000000000..48c65c3448 --- /dev/null +++ b/test/fixtures/flow/type-annotations/105/expected.json @@ -0,0 +1,249 @@ +{ + "type": "File", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "program": { + "type": "Program", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "sourceType": "module", + "body": [ + { + "type": "FunctionDeclaration", + "start": 0, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "id": { + "type": "Identifier", + "start": 9, + "end": 10, + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "name": "g" + }, + "generator": false, + "expression": false, + "async": false, + "params": [ + { + "type": "AssignmentPattern", + "start": 11, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "left": { + "type": "Identifier", + "start": 11, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 11 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "name": "a", + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 12, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 12 + }, + "end": { + "line": 1, + "column": 19 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 13, + "end": 19, + "loc": { + "start": { + "line": 1, + "column": 13 + }, + "end": { + "line": 1, + "column": 19 + } + } + } + } + }, + "right": { + "type": "NumericLiteral", + "start": 20, + "end": 21, + "loc": { + "start": { + "line": 1, + "column": 20 + }, + "end": { + "line": 1, + "column": 21 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + } + }, + { + "type": "AssignmentPattern", + "start": 23, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "left": { + "type": "Identifier", + "start": 23, + "end": 24, + "loc": { + "start": { + "line": 1, + "column": 23 + }, + "end": { + "line": 1, + "column": 24 + } + }, + "name": "e" + }, + "right": { + "type": "NumericLiteral", + "start": 25, + "end": 26, + "loc": { + "start": { + "line": 1, + "column": 25 + }, + "end": { + "line": 1, + "column": 26 + } + }, + "extra": { + "rawValue": 1, + "raw": "1" + }, + "value": 1 + }, + "typeAnnotation": { + "type": "TypeAnnotation", + "start": 26, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 26 + }, + "end": { + "line": 1, + "column": 33 + } + }, + "typeAnnotation": { + "type": "NumberTypeAnnotation", + "start": 27, + "end": 33, + "loc": { + "start": { + "line": 1, + "column": 27 + }, + "end": { + "line": 1, + "column": 33 + } + } + } + } + } + ], + "body": { + "type": "BlockStatement", + "start": 35, + "end": 37, + "loc": { + "start": { + "line": 1, + "column": 35 + }, + "end": { + "line": 1, + "column": 37 + } + }, + "body": [], + "directives": [] + } + } + ], + "directives": [] + } +}