Skip to content

Commit 3b4797d

Browse files
committed
fix: handler jsx parsing error, correct column info
1 parent a799955 commit 3b4797d

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

.travis.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@ cache:
1010
before_install:
1111
- curl -o- -L https://yarnpkg.com/install.sh | bash
1212
- export PATH="$HOME/.yarn/bin:$PATH"
13-
- curl -o $HOME/gpgkey.asc $GPG_KEY
14-
- gpg --import $HOME/gpgkey.asc
15-
- git config --global user.name 'JounQin'
16-
- git config --global user.email 'admin@1stg.me'
17-
- git config --global commit.gpgsign true
18-
- git config --global tag.gpgsign true
13+
- git config --global user.name "JounQin"
14+
- git config --global user.email "admin@1stg.me"
1915

2016
install: yarn --frozen-lockfile
2117

2218
script:
23-
- set -e
2419
- yarn lint
2520
- yarn build
2621
- yarn test

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "http://json.schemastore.org/lerna",
3-
"version": "0.9.6",
3+
"version": "0.9.7",
44
"npmClient": "yarn",
55
"useWorkspaces": true,
66
"changelog": {

packages/eslint-mdx/src/parser.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,25 @@ export class Parser {
196196
const value = node.value as string
197197

198198
// wrap into single Fragment, so that it won't break on adjacent JSX nodes
199-
const program = this._eslintParse(`<>${value}</>`).ast
199+
let program: AST.Program
200+
201+
try {
202+
program = this._eslintParse(`<>${value}</>`).ast
203+
} catch (e) {
204+
if (hasProperties<LocationError>(e, LOC_ERROR_PROPERTIES)) {
205+
const {
206+
position: { start },
207+
} = node
208+
209+
e.index += start.offset - 3
210+
e.column = e.lineNumber > 1 ? e.column : e.column + start.column - 3
211+
e.lineNumber += start.line - 1
212+
213+
throw e
214+
}
215+
216+
return node
217+
}
200218

201219
const { expression } = program.body[0] as ExpressionStatement
202220

@@ -266,7 +284,7 @@ export class Parser {
266284
} catch (e) {
267285
if (hasProperties<LocationError>(e, LOC_ERROR_PROPERTIES)) {
268286
e.index += start
269-
e.column += loc.start.column
287+
e.column = e.lineNumber > 1 ? e.column : e.column + loc.start.column
270288
e.lineNumber += startLine
271289
}
272290

0 commit comments

Comments
 (0)