Skip to content

Fails on stateless functions. #3

@beckend

Description

@beckend

cloned the repo and ran agains this file:

/* tslint:disable: variable-name */
import * as React from 'react';
import { defineMessages, FormattedMessage } from 'react-intl';
import 'react-toolbox/lib/tooltip/theme.scss';
import { AppBar, Navigation, Link } from 'react-toolbox';

const { Grid, Row, Col } = require('react-flexbox-grid');

const translations = defineMessages({
  predefinedTranslation: {
    id: 'PREDEFINED',
    defaultMessage: 'Hello {name}, I am predefined',
    description: 'This translation is defined in a defineMessage.'
  }
});

interface IPageProps { }
const Page: React.SFC<IPageProps> = ({ children }) => {
  return (
    <Grid>
      <Row>
        <Col xs={ 6 } md={ 3 }>
          <AppBar fixed flat>
          <Navigation type='vertical'>
            <Link href='http://' label='Inbox' icon='inbox' />
            <Link href='http://' active label='Profile' icon='person' />
          </Navigation>
            <a href='/home'>React Toolbox Docs</a>
            This is from Main Page
            <FormattedMessage
              { ...translations.predefinedTranslation }
              values={ { name: 'World' } }
            />
          </AppBar>
          { children }
        </Col>
      </Row>
    </Grid>
  );
};

Page.displayName = 'Mobile-page-Main';
export { Page };

Tried test of the file will fail:

  1. <FormattedMessage/>
  TypeError: Cannot read property 'text' of undefined
    index.ts:94:8
    index.ts:92:28
    main (index.ts:90:24)
    Test.t [as fn] (test/index.js:28:15)

findFirstJsxOpeningLikeElementWithName will yield on the stateless function:

{
    "pos": 1003,
    "end": 1059,
    "flags": 0,
    "kind": 251,
    "expression": {
        "pos": 1023,
        "end": 1057,
        "flags": 0,
        "kind": 177,
        "expression": {
            "pos": 1023,
            "end": 1035,
            "flags": 0,
            "text": "translations"
        },
        "name": {
            "pos": 1036,
            "end": 1057,
            "flags": 0,
            "text": "predefinedTranslation"
        }
    }
}

And thus will fail.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions