diff --git a/src/script/index.ts b/src/script/index.ts index d19275ee..75107118 100644 --- a/src/script/index.ts +++ b/src/script/index.ts @@ -461,16 +461,15 @@ function parseFilter( range: [callee.range[0], callee.range[1] - 2], loc: { start: callee.loc.start, - end: { - line: callee.loc.end.line, - column: callee.loc.end.column - 2, - }, + end: locationCalculator.getLocation( + callee.range[1] - callee.range[0] - 1, + ), }, name: String(callee.value), } tokens.push({ type: "Identifier", - value: calleeCode, + value: calleeCode.trim(), range: expression.callee.range, loc: expression.callee.loc, }) diff --git a/test/fixtures/ast/filters-2/ast.json b/test/fixtures/ast/filters-2/ast.json index d27961fb..e1a0926b 100644 --- a/test/fixtures/ast/filters-2/ast.json +++ b/test/fixtures/ast/filters-2/ast.json @@ -555,7 +555,7 @@ }, { "type": "Identifier", - "value": " f1 ", + "value": "f1", "range": [ 31, 33 @@ -591,7 +591,7 @@ }, { "type": "Identifier", - "value": " f2", + "value": "f2", "range": [ 36, 38 @@ -667,7 +667,7 @@ }, { "type": "Identifier", - "value": " f3", + "value": "f3", "range": [ 43, 45 diff --git a/test/fixtures/ast/filters-3/ast.json b/test/fixtures/ast/filters-3/ast.json index cbfcc091..74c4433d 100644 --- a/test/fixtures/ast/filters-3/ast.json +++ b/test/fixtures/ast/filters-3/ast.json @@ -617,7 +617,7 @@ }, { "type": "Identifier", - "value": " f1 ", + "value": "f1", "range": [ 35, 37 @@ -653,7 +653,7 @@ }, { "type": "Identifier", - "value": " f2", + "value": "f2", "range": [ 40, 42 @@ -729,7 +729,7 @@ }, { "type": "Identifier", - "value": " f3", + "value": "f3", "range": [ 47, 49 diff --git a/test/fixtures/ast/filters-4/ast.json b/test/fixtures/ast/filters-4/ast.json new file mode 100644 index 00000000..466bfdfe --- /dev/null +++ b/test/fixtures/ast/filters-4/ast.json @@ -0,0 +1,668 @@ +{ + "type": "Program", + "start": 0, + "end": 0, + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 0 + } + }, + "range": [ + 0, + 0 + ], + "body": [], + "sourceType": "script", + "comments": [], + "tokens": [], + "templateBody": { + "type": "VElement", + "range": [ + 0, + 87 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "name": "template", + "rawName": "template", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 0, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "selfClosing": false, + "attributes": [] + }, + "children": [ + { + "type": "VText", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "VElement", + "range": [ + 15, + 75 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "name": "div", + "rawName": "div", + "namespace": "http://www.w3.org/1999/xhtml", + "startTag": { + "type": "VStartTag", + "range": [ + 15, + 69 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "selfClosing": false, + "attributes": [ + { + "type": "VAttribute", + "range": [ + 20, + 68 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "directive": true, + "key": { + "type": "VDirectiveKey", + "range": [ + 20, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "name": "bind", + "argument": "attr", + "modifiers": [], + "shorthand": true, + "raw": { + "name": "bind", + "argument": "attr", + "modifiers": [] + } + }, + "value": { + "type": "VExpressionContainer", + "range": [ + 26, + 68 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "expression": { + "type": "VFilterSequenceExpression", + "expression": { + "type": "Identifier", + "start": 36, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "range": [ + 36, + 41 + ], + "name": "value" + }, + "filters": [ + { + "type": "VFilter", + "range": [ + 56, + 62 + ], + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 20 + } + }, + "callee": { + "type": "Identifier", + "range": [ + 56, + 62 + ], + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 20 + } + }, + "name": "filter" + }, + "arguments": [] + } + ], + "range": [ + 36, + 62 + ], + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 4, + "column": 20 + } + } + }, + "references": [ + { + "id": { + "type": "Identifier", + "start": 36, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "range": [ + 36, + 41 + ], + "name": "value" + }, + "mode": "r" + } + ] + } + } + ] + }, + "children": [], + "endTag": { + "type": "VEndTag", + "range": [ + 69, + 75 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 12 + } + } + }, + "variables": [] + }, + { + "type": "VText", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 5, + "column": 12 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n" + } + ], + "endTag": { + "type": "VEndTag", + "range": [ + 76, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 11 + } + } + }, + "variables": [], + "tokens": [ + { + "type": "HTMLTagOpen", + "range": [ + 0, + 9 + ], + "loc": { + "start": { + "line": 1, + "column": 0 + }, + "end": { + "line": 1, + "column": 9 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 9, + 10 + ], + "loc": { + "start": { + "line": 1, + "column": 9 + }, + "end": { + "line": 1, + "column": 10 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 10, + 15 + ], + "loc": { + "start": { + "line": 1, + "column": 10 + }, + "end": { + "line": 2, + "column": 4 + } + }, + "value": "\n " + }, + { + "type": "HTMLTagOpen", + "range": [ + 15, + 19 + ], + "loc": { + "start": { + "line": 2, + "column": 4 + }, + "end": { + "line": 2, + "column": 8 + } + }, + "value": "div" + }, + { + "type": "HTMLIdentifier", + "range": [ + 20, + 25 + ], + "loc": { + "start": { + "line": 2, + "column": 9 + }, + "end": { + "line": 2, + "column": 14 + } + }, + "value": ":attr" + }, + { + "type": "HTMLAssociation", + "range": [ + 25, + 26 + ], + "loc": { + "start": { + "line": 2, + "column": 14 + }, + "end": { + "line": 2, + "column": 15 + } + }, + "value": "" + }, + { + "type": "Punctuator", + "range": [ + 26, + 27 + ], + "loc": { + "start": { + "line": 2, + "column": 15 + }, + "end": { + "line": 2, + "column": 16 + } + }, + "value": "\"" + }, + { + "type": "Identifier", + "value": "value", + "start": 36, + "end": 41, + "loc": { + "start": { + "line": 3, + "column": 8 + }, + "end": { + "line": 3, + "column": 13 + } + }, + "range": [ + 36, + 41 + ] + }, + { + "type": "Punctuator", + "value": "|", + "range": [ + 54, + 55 + ], + "loc": { + "start": { + "line": 4, + "column": 12 + }, + "end": { + "line": 4, + "column": 13 + } + } + }, + { + "type": "Identifier", + "value": "filter", + "range": [ + 56, + 62 + ], + "loc": { + "start": { + "line": 4, + "column": 14 + }, + "end": { + "line": 4, + "column": 20 + } + } + }, + { + "type": "Punctuator", + "range": [ + 67, + 68 + ], + "loc": { + "start": { + "line": 5, + "column": 4 + }, + "end": { + "line": 5, + "column": 5 + } + }, + "value": "\"" + }, + { + "type": "HTMLTagClose", + "range": [ + 68, + 69 + ], + "loc": { + "start": { + "line": 5, + "column": 5 + }, + "end": { + "line": 5, + "column": 6 + } + }, + "value": "" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 69, + 74 + ], + "loc": { + "start": { + "line": 5, + "column": 6 + }, + "end": { + "line": 5, + "column": 11 + } + }, + "value": "div" + }, + { + "type": "HTMLTagClose", + "range": [ + 74, + 75 + ], + "loc": { + "start": { + "line": 5, + "column": 11 + }, + "end": { + "line": 5, + "column": 12 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 75, + 76 + ], + "loc": { + "start": { + "line": 5, + "column": 12 + }, + "end": { + "line": 6, + "column": 0 + } + }, + "value": "\n" + }, + { + "type": "HTMLEndTagOpen", + "range": [ + 76, + 86 + ], + "loc": { + "start": { + "line": 6, + "column": 0 + }, + "end": { + "line": 6, + "column": 10 + } + }, + "value": "template" + }, + { + "type": "HTMLTagClose", + "range": [ + 86, + 87 + ], + "loc": { + "start": { + "line": 6, + "column": 10 + }, + "end": { + "line": 6, + "column": 11 + } + }, + "value": "" + }, + { + "type": "HTMLWhitespace", + "range": [ + 87, + 88 + ], + "loc": { + "start": { + "line": 6, + "column": 11 + }, + "end": { + "line": 7, + "column": 0 + } + }, + "value": "\n" + } + ], + "comments": [], + "errors": [] + } +} \ No newline at end of file diff --git a/test/fixtures/ast/filters-4/source.vue b/test/fixtures/ast/filters-4/source.vue new file mode 100644 index 00000000..47a2568b --- /dev/null +++ b/test/fixtures/ast/filters-4/source.vue @@ -0,0 +1,6 @@ + diff --git a/test/fixtures/ast/filters-4/token-ranges.json b/test/fixtures/ast/filters-4/token-ranges.json new file mode 100644 index 00000000..1d38a9fb --- /dev/null +++ b/test/fixtures/ast/filters-4/token-ranges.json @@ -0,0 +1,20 @@ +[ + "", + "\n ", + "", + "", + "\n", + "", + "\n" +] \ No newline at end of file diff --git a/test/fixtures/ast/filters-4/tree.json b/test/fixtures/ast/filters-4/tree.json new file mode 100644 index 00000000..5f409a26 --- /dev/null +++ b/test/fixtures/ast/filters-4/tree.json @@ -0,0 +1,84 @@ +[ + { + "type": "VElement", + "text": "", + "children": [ + { + "type": "VStartTag", + "text": "", + "children": [] + } + ] + } +] \ No newline at end of file diff --git a/test/fixtures/ast/filters/ast.json b/test/fixtures/ast/filters/ast.json index 1bc9f78e..ef0c5853 100644 --- a/test/fixtures/ast/filters/ast.json +++ b/test/fixtures/ast/filters/ast.json @@ -541,7 +541,7 @@ }, { "type": "Identifier", - "value": " luxon:locale", + "value": "luxon:locale", "range": [ 42, 54