Skip to content

Commit 42a8f6f

Browse files
committed
Do not crash shellcheck parser
1 parent b776c7f commit 42a8f6f

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

server/src/util/__tests__/sourcing.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ describe('getSourcedUris', () => {
173173
174174
# shellcheck source-path=SCRIPTDIR # note that this is already the behaviour of bash language server
175175
source ./testing/fixtures/issue101.sh
176+
177+
source # not finished
176178
`
177179

178180
const sourceCommands = getSourceCommands({

server/src/util/sourcing.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ function getSourcedPathInfoFromNode({
5959
}): null | { sourcedPath?: string; parseError?: string } {
6060
if (node.type === 'command') {
6161
const [commandNameNode, argumentNode] = node.namedChildren
62+
63+
if (!commandNameNode || !argumentNode) {
64+
return null
65+
}
66+
6267
if (
6368
commandNameNode.type === 'command_name' &&
6469
SOURCING_COMMANDS.includes(commandNameNode.text)

0 commit comments

Comments
 (0)