Skip to content

Commit

Permalink
fix: mobx-undecorate don't crash when node's loc is null (#2767)
Browse files Browse the repository at this point in the history
  • Loading branch information
iChenLei authored Jan 30, 2021
1 parent 522765d commit 3f5087c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/witty-hotels-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mobx-undecorate": patch
---

mobx-undecorate don't crash when node's loc is null
24 changes: 14 additions & 10 deletions packages/mobx-undecorate/src/undecorate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,19 @@ export default function transform(
if (process.env.NODE_ENV === "test") {
return
}
const line = lines[node.loc!.start.line - 1]
const shortline = line.replace(/^\s*/, "")
console.warn(
`[mobx:undecorate] ${msg} at (${fileInfo.path}:${node.loc!.start.line}:${
node.loc!.start.column
}):\n\t${shortline}\n\t${"^".padStart(
node.loc!.start.column + 1 - line.indexOf(shortline),
" "
)}\n`
)
if (node.loc) {
const line = lines[node.loc.start.line - 1]
const shortline = line.replace(/^\s*/, "")
console.warn(
`[mobx:undecorate] ${msg} at (${fileInfo.path}:${node.loc.start.line}:${
node.loc.start.column
}):\n\t${shortline}\n\t${"^".padStart(
node.loc.start.column + 1 - line.indexOf(shortline),
" "
)}\n`
)
} else {
console.warn(`[mobx:undecorate] ${msg} at (${fileInfo.path})\n`)
}
}
}

0 comments on commit 3f5087c

Please sign in to comment.