Skip to content

Commit 188c6aa

Browse files
authored
fix: wrong end.offset - close #279 (#280)
1 parent b48311c commit 188c6aa

File tree

5 files changed

+1439
-1838
lines changed

5 files changed

+1439
-1838
lines changed

package.json

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,42 +13,38 @@
1313
"build": "run-p build:*",
1414
"build:r": "r -p",
1515
"build:ts": "tsc -b",
16-
"clean": "rimraf packages/*/{lib,*.tsbuildinfo}",
1716
"lint": "run-p lint:*",
1817
"lint:es": "cross-env PARSER_NO_WATCH=true eslint . --cache --ext js,md,ts -f friendly",
1918
"lint:ts": "tslint -p . -t stylish",
20-
"lint:tsc": "tsc",
2119
"postinstall": "yarn-deduplicate --strategy fewer || exit 0",
22-
"prelint": "yarn build:ts",
2320
"prerelease": "yarn build",
24-
"pretest": "yarn clean",
2521
"release": "lerna publish --conventional-commits --create-release github --yes",
2622
"test": "jest",
2723
"typecov": "type-coverage"
2824
},
2925
"devDependencies": {
3026
"@1stg/lib-config": "^1.1.9",
3127
"@1stg/tslint-config": "^1.1.0",
32-
"@types/eslint": "^7.2.6",
28+
"@types/eslint": "^7.2.7",
3329
"@types/jest": "^26.0.20",
34-
"@types/node": "^14.14.31",
35-
"@types/react": "^17.0.2",
30+
"@types/node": "^14.14.33",
31+
"@types/react": "^17.0.3",
3632
"@types/rebass": "^4.0.8",
3733
"@types/unist": "^2.0.3",
3834
"eslint-mdx": "link:packages/eslint-mdx/src",
3935
"eslint-plugin-mdx": "link:packages/eslint-plugin-mdx/src",
40-
"lerna": "^3.22.1",
36+
"lerna": "^4.0.0",
4137
"npm-run-all": "^4.1.5",
4238
"react": "^17.0.1",
43-
"ts-jest": "^26.5.2",
39+
"ts-jest": "^26.5.3",
4440
"ts-node": "^9.1.1",
4541
"tslint": "^6.1.3",
4642
"type-coverage": "^2.16.3",
47-
"typescript": "^4.2.2",
43+
"typescript": "^4.2.3",
4844
"yarn-deduplicate": "^3.1.0"
4945
},
5046
"resolutions": {
51-
"@babel/core": "^7.13.8",
47+
"@babel/core": "^7.13.10",
5248
"prettier": "^2.2.1",
5349
"tslib": "^2.1.0"
5450
},
@@ -88,7 +84,7 @@
8884
]
8985
},
9086
"typeCoverage": {
91-
"atLeast": 99.37,
87+
"atLeast": 99.76,
9288
"cache": true,
9389
"detail": true,
9490
"ignoreAsAssertion": true,

packages/eslint-mdx/src/traverse.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,23 @@ export class Traverse {
2020
this._enter = enter
2121
}
2222

23-
combineLeftJsxNodes(jsxNodes: Node[]) {
23+
combineLeftJsxNodes(jsxNodes: Node[], parent?: Parent): Node {
2424
const start = jsxNodes[0].position.start
25-
const end = last(jsxNodes).position.end
25+
const end = { ...last(jsxNodes).position.end }
26+
// fix #279
27+
if (parent && parent.position.indent?.length > 0) {
28+
end.offset += parent.position.indent.reduce(
29+
(acc, indent, index) => acc + (index ? indent + 1 : 0),
30+
0,
31+
)
32+
}
2633
return {
2734
type: 'jsx',
2835
data: jsxNodes[0].data,
2936
value: this.code.slice(start.offset, end.offset),
3037
position: {
31-
start: jsxNodes[0].position.start,
32-
end: last(jsxNodes).position.end,
38+
start,
39+
end,
3340
},
3441
}
3542
}
@@ -95,14 +102,17 @@ export class Traverse {
95102
)
96103
if (firstOpenTagIndex === -1) {
97104
if (hasOpenTag) {
98-
acc.push(this.combineLeftJsxNodes(jsxNodes))
105+
acc.push(this.combineLeftJsxNodes(jsxNodes, parent))
99106
} else {
100107
acc.push(...jsxNodes)
101108
}
102109
} else {
103110
acc.push(
104111
...jsxNodes.slice(0, firstOpenTagIndex),
105-
this.combineLeftJsxNodes(jsxNodes.slice(firstOpenTagIndex)),
112+
this.combineLeftJsxNodes(
113+
jsxNodes.slice(firstOpenTagIndex),
114+
parent,
115+
),
106116
)
107117
}
108118
jsxNodes.length = 0
@@ -114,7 +124,7 @@ export class Traverse {
114124
acc.push(node)
115125
}
116126
if (index === length - 1 && jsxNodes.length > 0) {
117-
acc.push(this.combineLeftJsxNodes(jsxNodes))
127+
acc.push(this.combineLeftJsxNodes(jsxNodes, parent))
118128
}
119129
return acc
120130
}, [])

test/__snapshots__/fixtures.test.ts.snap

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ Array [
104104
]
105105
`;
106106

107+
exports[`fixtures should match all snapshots: jsx-in-list.mdx 1`] = `Array []`;
108+
107109
exports[`fixtures should match all snapshots: leading-spaces.mdx 1`] = `Array []`;
108110

109111
exports[`fixtures should match all snapshots: markdown.md 1`] = `Array []`;

test/fixtures/jsx-in-list.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
- - <div kind="docs-packages-vuetify-preset" story="page">
2+
Vuetify preset
3+
</div>
4+
: some extra text describing the preset
5+
- <div kind="docs-packages-vuetify-preset" story="page">
6+
Vuetify preset
7+
</div>
8+
: some extra text describing the preset
9+
- <div kind="docs-packages-vuetify-preset" story="page">
10+
Vuetify preset
11+
</div>
12+
: some extra text describing the preset
13+
- - <div kind="docs-packages-vuetify-preset" story="page">
14+
Vuetify preset
15+
</div>
16+
: some extra text describing the preset
17+
- <div kind="docs-packages-vuetify-preset" story="page">
18+
Vuetify preset
19+
</div>
20+
: some extra text describing the preset
21+
- <div kind="docs-packages-vuetify-preset" story="page">
22+
Vuetify preset
23+
</div>
24+
: some extra text describing the preset

0 commit comments

Comments
 (0)