Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Populate end position for shorthand properties #176

Merged
merged 2 commits into from
Nov 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fuzzy-needles-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"svelte-parse": patch
---

Populate end position for shorthand properties and add position information for shorthand property expression values.
9 changes: 8 additions & 1 deletion packages/svelte-parse/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,12 @@ export function parseNode(opts: ParseNodeOptions): Result | undefined {

(current_node as BaseSvelteTag<''>).properties.push(_node as Property);
push_node(_node);
if (generatePositions)
if (generatePositions) {
//@ts-ignore
current_node.position = { start: place(), end: {} };
//@ts-ignore
(current_node as Property).value[0].position = { start: place(), end: {} };
}
chomp();
continue;
}
Expand Down Expand Up @@ -583,6 +586,10 @@ export function parseNode(opts: ParseNodeOptions): Result | undefined {
if (current_state === State.IN_SHORTHAND_ATTR) {
if (char === CLOSE_BRACE) {
(current_node as Property).value[0].value = (current_node as Property).name;
if (generatePositions) {
current_node.position.end = place();
(current_node as Property).value[0].position.end = place();
}
pop_state();
pop_node();
chomp();
Expand Down
60 changes: 54 additions & 6 deletions packages/svelte-parse/test/fixtures/01-Button/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,19 @@
"value": [
{
"type": "svelteExpression",
"value": "...props"
"value": "...props",
"position": {
"start": {
"line": 68,
"column": 5,
"offset": 1611
},
"end": {
"line": 68,
"column": 14,
"offset": 1620
}
}
}
],
"modifiers": [],
Expand All @@ -114,7 +126,11 @@
"column": 5,
"offset": 1611
},
"end": {}
"end": {
"line": 68,
"column": 14,
"offset": 1620
}
}
},
{
Expand Down Expand Up @@ -969,7 +985,19 @@
"value": [
{
"type": "svelteExpression",
"value": "href"
"value": "href",
"position": {
"start": {
"line": 87,
"column": 5,
"offset": 2054
},
"end": {
"line": 87,
"column": 10,
"offset": 2059
}
}
}
],
"modifiers": [],
Expand All @@ -980,7 +1008,11 @@
"column": 5,
"offset": 2054
},
"end": {}
"end": {
"line": 87,
"column": 10,
"offset": 2059
}
}
},
{
Expand All @@ -989,7 +1021,19 @@
"value": [
{
"type": "svelteExpression",
"value": "...props"
"value": "...props",
"position": {
"start": {
"line": 88,
"column": 5,
"offset": 2065
},
"end": {
"line": 88,
"column": 14,
"offset": 2074
}
}
}
],
"modifiers": [],
Expand All @@ -1000,7 +1044,11 @@
"column": 5,
"offset": 2065
},
"end": {}
"end": {
"line": 88,
"column": 14,
"offset": 2074
}
}
},
{
Expand Down
60 changes: 54 additions & 6 deletions packages/svelte-parse/test/fixtures/01-Dialog/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,19 @@
"value": [
{
"type": "svelteExpression",
"value": "icon"
"value": "icon",
"position": {
"start": {
"line": 236,
"column": 37,
"offset": 5581
},
"end": {
"line": 236,
"column": 42,
"offset": 5586
}
}
}
],
"modifiers": [],
Expand All @@ -1361,7 +1373,11 @@
"column": 37,
"offset": 5581
},
"end": {}
"end": {
"line": 236,
"column": 42,
"offset": 5586
}
}
},
{
Expand All @@ -1370,7 +1386,19 @@
"value": [
{
"type": "svelteExpression",
"value": "type"
"value": "type",
"position": {
"start": {
"line": 236,
"column": 44,
"offset": 5588
},
"end": {
"line": 236,
"column": 49,
"offset": 5593
}
}
}
],
"modifiers": [],
Expand All @@ -1381,7 +1409,11 @@
"column": 44,
"offset": 5588
},
"end": {}
"end": {
"line": 236,
"column": 49,
"offset": 5593
}
}
},
{
Expand Down Expand Up @@ -1931,7 +1963,19 @@
"value": [
{
"type": "svelteExpression",
"value": "...newInputProps"
"value": "...newInputProps",
"position": {
"start": {
"line": 249,
"column": 23,
"offset": 5992
},
"end": {
"line": 249,
"column": 40,
"offset": 6009
}
}
}
],
"modifiers": [],
Expand All @@ -1942,7 +1986,11 @@
"column": 23,
"offset": 5992
},
"end": {}
"end": {
"line": 249,
"column": 40,
"offset": 6009
}
}
},
{
Expand Down
20 changes: 18 additions & 2 deletions packages/svelte-parse/test/fixtures/01-Field/output.json
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,19 @@
"value": [
{
"type": "svelteExpression",
"value": "...props"
"value": "...props",
"position": {
"start": {
"line": 114,
"column": 6,
"offset": 2510
},
"end": {
"line": 114,
"column": 15,
"offset": 2519
}
}
}
],
"modifiers": [],
Expand All @@ -163,7 +175,11 @@
"column": 6,
"offset": 2510
},
"end": {}
"end": {
"line": 114,
"column": 15,
"offset": 2519
}
}
},
{
Expand Down
Loading