Skip to content

Commit 6f59eb8

Browse files
committed
fix(sentence): fix column position
1 parent 759b2cd commit 6f59eb8

File tree

4 files changed

+108
-8
lines changed

4 files changed

+108
-8
lines changed

src/parser/SourceCode.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ export class SourceCode {
2828
this.index = this.startOffset;
2929
// before line count of Paragraph node
3030
const lineBreaks = Array.from(new Array(this.sourceNode.loc.start.line - 1)).fill("\n");
31-
const offset = Array.from(new Array(this.startOffset - lineBreaks.length));
32-
this.textCharacters = lineBreaks.concat(offset, input.raw.split(""));
31+
// filled with dummy text
32+
const offset = Array.from(new Array(this.startOffset - lineBreaks.length)).fill("∯");
33+
this.textCharacters = offset.concat(lineBreaks, input.raw.split(""));
3334
this.source = new StructureSource(this.textCharacters.join(""));
3435
if (this.sourceNode.children[0]) {
3536
// Header Node's children does not start with index 0
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"type": "Paragraph",
3+
"children": [
4+
{
5+
"type": "Str",
6+
"value": "ルールは、設定値などがJavaScriptで表現でき、npmで共有できる作りになっている",
7+
"loc": {
8+
"start": {
9+
"line": 3,
10+
"column": 2
11+
},
12+
"end": {
13+
"line": 3,
14+
"column": 46
15+
}
16+
},
17+
"range": [
18+
42,
19+
86
20+
],
21+
"raw": "ルールは、設定値などがJavaScriptで表現でき、npmで共有できる作りになっている"
22+
}
23+
],
24+
"loc": {
25+
"start": {
26+
"line": 3,
27+
"column": 2
28+
},
29+
"end": {
30+
"line": 3,
31+
"column": 46
32+
}
33+
},
34+
"range": [
35+
42,
36+
86
37+
],
38+
"raw": "ルールは、設定値などがJavaScriptで表現でき、npmで共有できる作りになっている"
39+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"type": "Paragraph",
3+
"children": [
4+
{
5+
"type": "Sentence",
6+
"raw": "ルールは、設定値などがJavaScriptで表現でき、npmで共有できる作りになっている",
7+
"value": "ルールは、設定値などがJavaScriptで表現でき、npmで共有できる作りになっている",
8+
"loc": {
9+
"start": {
10+
"line": 3,
11+
"column": 0
12+
},
13+
"end": {
14+
"line": 3,
15+
"column": 44
16+
}
17+
},
18+
"range": [
19+
42,
20+
86
21+
],
22+
"children": [
23+
{
24+
"type": "Str",
25+
"raw": "ルールは、設定値などがJavaScriptで表現でき、npmで共有できる作りになっている",
26+
"value": "ルールは、設定値などがJavaScriptで表現でき、npmで共有できる作りになっている",
27+
"loc": {
28+
"start": {
29+
"line": 3,
30+
"column": 0
31+
},
32+
"end": {
33+
"line": 3,
34+
"column": 44
35+
}
36+
},
37+
"range": [
38+
42,
39+
86
40+
]
41+
}
42+
]
43+
}
44+
],
45+
"loc": {
46+
"start": {
47+
"line": 3,
48+
"column": 2
49+
},
50+
"end": {
51+
"line": 3,
52+
"column": 46
53+
}
54+
},
55+
"range": [
56+
42,
57+
86
58+
],
59+
"raw": "ルールは、設定値などがJavaScriptで表現でき、npmで共有できる作りになっている"
60+
}

test/fixtures/list-item-paragraph/output.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"loc": {
99
"start": {
1010
"line": 5,
11-
"column": 86
11+
"column": 0
1212
},
1313
"end": {
1414
"line": 5,
15-
"column": 139
15+
"column": 53
1616
}
1717
},
1818
"range": [
@@ -27,11 +27,11 @@
2727
"loc": {
2828
"start": {
2929
"line": 5,
30-
"column": 86
30+
"column": 0
3131
},
3232
"end": {
3333
"line": 5,
34-
"column": 138
34+
"column": 52
3535
}
3636
},
3737
"range": [
@@ -46,11 +46,11 @@
4646
"loc": {
4747
"start": {
4848
"line": 5,
49-
"column": 138
49+
"column": 52
5050
},
5151
"end": {
5252
"line": 5,
53-
"column": 139
53+
"column": 53
5454
}
5555
},
5656
"range": [

0 commit comments

Comments
 (0)