Skip to content

Commit

Permalink
fix: fix an unexpected crash (#110)
Browse files Browse the repository at this point in the history
fix: fix an unexpected crash
  • Loading branch information
akameco committed Mar 19, 2020
2 parents feb210e + c8c8ec1 commit 14f4145
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/__tests__/__snapshots__/hook.test.ts.snap
Expand Up @@ -114,6 +114,21 @@ intl.formatMessage({
`;
exports[`default with a variable as the defaultMessage: with a variable as the defaultMessage 2`] = `
import { useIntl } from 'react-intl';
import { message } from './messages'
intl.formatMessage(messages);
↓ ↓ ↓ ↓ ↓ ↓
import { useIntl } from 'react-intl';
import { message } from './messages';
intl.formatMessage(messages);
`;
exports[`default with custom properties in formatMessage call: with custom properties in formatMessage call 1`] = `
import { useIntl } from 'react-intl';
Expand Down
15 changes: 15 additions & 0 deletions src/__tests__/__snapshots__/injection.test.ts.snap
Expand Up @@ -133,6 +133,21 @@ intl.formatMessage({
`;
exports[`default with a variable as the defaultMessage: with a variable as the defaultMessage 2`] = `
import { injectIntl } from 'react-intl';
import { message } from './messages';
intl.formatMessage(message);
↓ ↓ ↓ ↓ ↓ ↓
import { injectIntl } from 'react-intl';
import { message } from './messages';
intl.formatMessage(message);
`;
exports[`default with custom properties in formatMessage call: with custom properties in formatMessage call 1`] = `
import { injectIntl } from 'react-intl';
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/hook.test.ts
Expand Up @@ -43,6 +43,16 @@ intl.formatMessage({ defaultMessage: message });
`,
}

const withVariableMessageDescriptor = {
title: 'with a variable as the defaultMessage',
code: `
import { useIntl } from 'react-intl';
import { message } from './messages'
intl.formatMessage(messages);
`,
}

const withCustomProperties = {
title: 'with custom properties in formatMessage call',
code: `
Expand Down Expand Up @@ -119,6 +129,7 @@ const tests = [
multiUseTest,
withValueInMessageTest,
withVariableMessageTest,
withVariableMessageDescriptor,
withCustomProperties,
someSupportedUseCases,
importAsTest,
Expand Down
11 changes: 11 additions & 0 deletions src/__tests__/injection.test.ts
Expand Up @@ -43,6 +43,16 @@ intl.formatMessage({ defaultMessage: message });
`,
}

const withVariableMessageDescriptor = {
title: 'with a variable as the defaultMessage',
code: `
import { injectIntl } from 'react-intl';
import { message } from './messages';
intl.formatMessage(message);
`,
}

const withCustomProperties = {
title: 'with custom properties in formatMessage call',
code: `
Expand Down Expand Up @@ -119,6 +129,7 @@ const tests = [
multiUseTest,
withValueInMessageTest,
withVariableMessageTest,
withVariableMessageDescriptor,
withCustomProperties,
someSupportedUseCases,
importAsTest,
Expand Down
4 changes: 4 additions & 0 deletions src/utils/index.ts
Expand Up @@ -34,6 +34,10 @@ export function getObjectProperties(path: NodePath) {
if (!binding) {
return null
}
const init = binding.path.get('init')
if (!Array.isArray(init) && !init.type) {
return null
}
const properties = binding.path.get('init.properties')
if (Array.isArray(properties) && isObjectProperties(properties)) {
return properties
Expand Down

0 comments on commit 14f4145

Please sign in to comment.