diff --git a/.changeset/witty-hotels-ring.md b/.changeset/witty-hotels-ring.md new file mode 100644 index 000000000..ab43afd37 --- /dev/null +++ b/.changeset/witty-hotels-ring.md @@ -0,0 +1,5 @@ +--- +"mobx-undecorate": patch +--- + +mobx-undecorate don't crash when node's loc is null diff --git a/packages/mobx-undecorate/src/undecorate.ts b/packages/mobx-undecorate/src/undecorate.ts index 8a52e5a5d..ea56a20f6 100644 --- a/packages/mobx-undecorate/src/undecorate.ts +++ b/packages/mobx-undecorate/src/undecorate.ts @@ -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`) + } } }