Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): Avoid undefined object errors #28554

Merged
merged 2 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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