Skip to content

Commit

Permalink
fix(gatsby): Avoid undefined object errors (#28554)
Browse files Browse the repository at this point in the history
* fix(gatsby): Null check for file parser

* Never heard of optional chaining, eslint?
  • Loading branch information
ascorbic authored Dec 9, 2020
1 parent 56c2b4c commit 39995ae
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions packages/babel-plugin-remove-graphql-queries/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-unused-expressions */
/* eslint-disable new-cap */
import graphql from "gatsby/graphql"
import { murmurhash } from "./murmur"
Expand Down Expand Up @@ -103,7 +104,7 @@ const isGlobalIdentifier = (
tag.isIdentifier({ name: tagName }) && tag.scope.hasGlobal(tagName)

export function followVariableDeclarations(binding: Binding): Binding {
const node = binding.path?.node
const node = binding?.path?.node
if (
node?.type === `VariableDeclarator` &&
node?.id.type === `Identifier` &&
Expand Down Expand Up @@ -493,7 +494,7 @@ export default function ({ types: t }): PluginObj {
const binding = hookPath.scope.getBinding(varName)

if (binding) {
followVariableDeclarations(binding).path.traverse({
followVariableDeclarations(binding)?.path?.traverse({
TaggedTemplateExpression,
})
}
Expand Down
5 changes: 3 additions & 2 deletions packages/gatsby/src/query/file-parser.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-unused-expressions */
// @flow
const fs = require(`fs-extra`)
const crypto = require(`crypto`)
Expand Down Expand Up @@ -42,7 +43,7 @@ const generateQueryName = ({ def, hash, file }) => {
// taken from `babel-plugin-remove-graphql-queries`, in the future import from
// there
function followVariableDeclarations(binding) {
const node = binding.path?.node
const node = binding?.path?.node
if (
node?.type === `VariableDeclarator` &&
node?.id.type === `Identifier` &&
Expand Down Expand Up @@ -376,7 +377,7 @@ async function findGraphQLTags(
const binding = followVariableDeclarations(
path.scope.getBinding(path.node.local.name)
)
binding.path.traverse({ TaggedTemplateExpression })
binding?.path?.traverse({ TaggedTemplateExpression })
},
})
},
Expand Down

0 comments on commit 39995ae

Please sign in to comment.