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

Flow parsing errors #306

Closed
fagerbua opened this issue Aug 31, 2018 · 4 comments
Closed

Flow parsing errors #306

fagerbua opened this issue Aug 31, 2018 · 4 comments
Labels

Comments

@fagerbua
Copy link

Describe the bug
Flow blows up with a load of parsing errors when lingui packages are added to the project.

To Reproduce
Minimal reproduction:

yarn init
yarn add @lingui/core @lingui/react @lingui/cli flow-bin
yarn flow init
yarn flow

Result:

yarn run v1.9.2
$ /Users/XXX/src/testproject/node_modules/.bin/flow
Launching Flow server for XXX
Spawned flow server (pid=20303)
Logs will go to /private/tmp/flow/XXX.log
Monitor logs will go to /private/tmp/flow/XXX.monitor_log
Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/@lingui/cli/api/catalog.js.flow:11:32

Unexpected token (

      8│ import mkdirp from "mkdirp";
      9│ import path from "path";
     10│ import fs from "fs";
     11│ declare export default function(config: $Exact<{fallbackLocale: string, format: "lingui" | "minimal" | "po", localeDir: string, rootDir: string, sourceLocale: string, srcPathDirs: Array<string>, srcPathIgnorePatterns: Array<string>}>): {+addLocale: (locale: string) => [boolean, ?T], +formatFilename: <string>(pattern: string, locale: string) => string, +getLocales: () => Array<string>, +getTranslation: (catalogs: {[locale: string]: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}}, locale: string, msgId: string, options: $Exact<{fallbackLocale: string, sourceLocale: string}>) => ?string, +merge: (prevCatalogs: {[locale: string]: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}}, catalog: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}, options?: {[key: string]: any}) => {[locale: string]: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}}, +read: (locale: string) => ?{[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}, +readAll: () => {[locale: string]: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}}, +write: (locale: string, catalog: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}) => [boolean, ?T], +writeCompiled: <string>(locale: string, content: string) => string};
     12│


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/@lingui/cli/api/types.js.flow:4:92

Unexpected reserved type

     1│ // @flow
     2│
     3│ export type AllCatalogsType = {[locale: string]: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}};
     4│ export type CatalogApi = {+addLocale: (locale: string) => [boolean, ?T], +formatFilename: <string>(pattern: string, locale: string) => string, +getLocales: () => Array<string>, +getTranslation: (catalogs: {[locale: string]: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}}, locale: string, msgId: string, options: $Exact<{fallbackLocale: string, sourceLocale: string}>) => ?string, +merge: (prevCatalogs: {[locale: string]: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}}, catalog: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}, options?: {[key: string]: any}) => {[locale: string]: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}}, +read: (locale: string) => ?{[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}, +readAll: () => {[locale: string]: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}}, +write: (locale: string, catalog: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}) => [boolean, ?T], +writeCompiled: <string>(locale: string, content: string) => string};
     5│ export type CatalogType = {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}};
     6│ export type IdempotentResult<T> = [boolean, ?T];
     7│


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/@lingui/cli/lingui-add-locale.js.flow:8:32

Unexpected token (

      5│ import {getConfig} from "@lingui/conf";
      6│ import program from "commander";
      7│ import chalk from "chalk";
      8│ declare export default function(config: $Exact<{fallbackLocale: string, format: "lingui" | "minimal" | "po", localeDir: string, rootDir: string, sourceLocale: string, srcPathDirs: Array<string>, srcPathIgnorePatterns: Array<string>}>, locales: Array<string>): void;
      9│


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/@lingui/cli/lingui-extract.js.flow:15:32

Unexpected token (

     12│ import mkdirp from "mkdirp";
     13│ import path from "path";
     14│ import fs from "fs";
     15│ declare export default function(config: $Exact<{fallbackLocale: string, format: "lingui" | "minimal" | "po", localeDir: string, rootDir: string, sourceLocale: string, srcPathDirs: Array<string>, srcPathIgnorePatterns: Array<string>}>, options: $Exact<{babelOptions: Object, clean: boolean, overwrite: boolean, prevFormat: ?{+addLocale: (locale: string) => [boolean, ?T], +formatFilename: <string>(pattern: string, locale: string) => string, +getLocales: () => Array<string>, +getTranslation: (catalogs: {[locale: string]: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}}, locale: string, msgId: string, options: $Exact<{fallbackLocale: string, sourceLocale: string}>) => ?string, +merge: (prevCatalogs: {[locale: string]: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}}, catalog: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}, options?: {[key: string]: any}) => {[locale: string]: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}}, +read: (locale: string) => ?{[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}, +readAll: () => {[locale: string]: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}}, +write: (locale: string, catalog: {[msgId: string]: {defaults: ?string, origin: Array<[number, string]>, translation: string}}) => [boolean, ?T], +writeCompiled: <string>(locale: string, content: string) => string}, verbose: boolean}>): boolean;
     16│


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/@lingui/core/formats.js.flow:11:45

Unexpected token ;

      8│
      9│   $key: $SymbolToPrimitive;
     10│   $value: (hint: "string" | "default" | "number") => string | number;
     11│   mixed /* UNEXPECTED TYPE: IntersectionT */;
     12│   getDate(): number;
     13│   getDay(): number;
     14│   getFullYear(): number;


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/@lingui/core/index.js.flow:10:45

Unexpected token ;

      7│
      8│   $key: $SymbolToPrimitive;
      9│   $value: (hint: "string" | "default" | "number") => string | number;
     10│   mixed /* UNEXPECTED TYPE: IntersectionT */;
     11│   getDate(): number;
     12│   getDay(): number;
     13│   getFullYear(): number;


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/@lingui/core/t.js.flow:3:32

Unexpected token (

     1│ // @flow
     2│
     3│ declare export default function(strings: Array<string>, ...values: Array<any>): string;
     4│


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/@lingui/react/I18n.js.flow:5:30

Unexpected token extends

     2│
     3│ import PropTypes from "prop-types";
     4│ import * as React from "react";
     5│ declare export default class extends React$Component<mixed /* UNEXPECTED TYPE: ExistsT */, mixed /* UNEXPECTED TYPE: ExistsT */> {
     6│   static contextTypes: {linguiPublisher: React$PropType$Primitive<Object>};
     7│   static defaultProps: {update: boolean, withHash: boolean};
     8│


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/@lingui/react/I18nProvider.js.flow:10:30

Unexpected token extends

      7│ import * as React from "react";
      8│ export type I18nProviderProps = {catalogs?: any, children?: any, defaultRender: ?any, i18n?: any, language: string, locales?: any, missing?: string | Function};
      9│ declare export function LinguiPublisher(i18n: any): {getSubscribers: () => Array<Function>, i18n: any, i18nHash: null, subscribe: (callback: Function) => void, unsubscribe: (callback: Function) => void, update: (_?: {catalogs?: any, language?: string, locales?: string}) => void};
     10│ declare export default class extends React$Component<{catalogs?: any, children?: any, defaultRender: ?any, i18n?: any, language: string, locales?: any, missing?: string | Function}> {
     11│   static childContextTypes: {linguiDefaultRender: React$PropType$Primitive<any>, linguiPublisher: React$PropType$Primitive<Object>};
     12│   static defaultProps: {defaultRender: null};
     13│


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/@lingui/react/Render.js.flow:6:30

Unexpected token extends

     3│ import PropTypes from "prop-types";
     4│ import * as React from "react";
     5│ export type RenderProps = {className?: string, render?: any};
     6│ declare export default class extends React$Component<{value: string | ?Array<any>} & {className?: string, render?: any}> {
     7│   static contextTypes: {linguiDefaultRender: React$PropType$Primitive<any>};
     8│
     9│   props: {value: string | ?Array<any>} & {className?: string, render?: any};


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/@lingui/react/Select.js.flow:9:59

Unexpected token =

      6│ import withI18n from "./withI18n";
      7│ import type {Locales} from "@lingui/core";
      8│ import * as React from "react";
      9│ declare class Class0 extends React$Component<Props, State = void><mixed /* UNEXPECTED TYPE: ExistsT */, {few?: any, locales?: any, many?: any, offset?: number | string, one?: any, other: any, two?: any, value: number | string, zero?: any} & {i18n: any} & {className?: string, render?: any}> {
     10│   static defaultProps: {offset: number};
     11│
     12│   displayName: string | string;


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/@lingui/react/Trans.js.flow:9:59

Unexpected token =

      6│ import type {withI18nProps} from "./withI18n";
      7│ import withI18n from "./withI18n";
      8│ import * as React from "react";
      9│ declare class Class0 extends React$Component<Props, State = void><{children?: any, components?: Array<$Exact<{+key: string | number | null, +props: mixed /* UNEXPECTED TYPE: EvalT */, +ref: any, +type: ElementType}>>, defaults?: string, formats?: Object, i18n: Object, id?: string, values?: Object} & {i18n: any} & {className?: string, render?: any}> {
     10│
     11│   props: {children?: any, components?: Array<$Exact<{+key: string | number | null, +props: mixed /* UNEXPECTED TYPE: EvalT */, +ref: any, +type: ElementType}>>, defaults?: string, formats?: Object, i18n: Object, id?: string, values?: Object} & {i18n: any} & {className?: string, render?: any};
     12│   componentDidMount<any>(): void;


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/@lingui/react/createFormat.js.flow:7:32

Unexpected token <

      4│ import type {RenderProps} from "./Render";
      5│ import type {Locales} from "@lingui/core";
      6│ import * as React from "react";
      7│ declare export default function<V, FormatOptions>(formatFunction: (language: any, format?: FormatOptions) => (value: V) => string): (_: {format?: FormatOptions, i18n: {language: string, locales?: any}, value: V} & {className?: string, render?: any} | {format?: FormatOptions, i18n: {language: string, locales?: any}, value: V} & {className?: string, render?: any} | {format?: FormatOptions, i18n: {language: string, locales?: any}, value: V} & {className?: string, render?: any}) => $Exact<{+key: string | number | null, +props: mixed /* UNEXPECTED TYPE: EvalT */, +ref: any, +type: ElementType}> | $Exact<{+key: string | number | null, +props: mixed /* UNEXPECTED TYPE: EvalT */, +ref: any, +type: ElementType}> | $Exact<{+key: string | number | null, +props: mixed /* UNEXPECTED TYPE: EvalT */, +ref: any, +type: ElementType}>;
      8│
      9│


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/@lingui/react/index.js.flow:10:59

Unexpected token =

      7│ import I18n from "./I18n";
      8│ import I18nProvider from "./I18nProvider";
      9│ import {date, number} from "@lingui/core";
     10│ declare class Class0 extends React$Component<Props, State = void><{value: string | ?Array<any>} & {className?: string, render?: any}> {
     11│   static contextTypes: {linguiDefaultRender: React$PropType$Primitive<any>} | any;
     12│
     13│   props: {value: string | ?Array<any>} & {className?: string, render?: any};


Error ┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈ node_modules/@lingui/react/withI18n.js.flow:8:32

Unexpected token (

      5│ import hoistStatics from "hoist-non-react-statics";
      6│ import PropTypes from "prop-types";
      7│ import * as React from "react";
      8│ declare export default function(options?: {update?: boolean, withHash?: boolean, withRef?: boolean}): <P, C: {contextTypes?: any, displayName?: ?string, propTypes?: any} | Class<React$Component<Props, any>>>(WrappedComponent: C) => C & {contextTypes?: any, displayName?: ?string, propTypes?: any} | Class<React$Component<Props, any>>;
      9│ export type withI18nProps = {i18n: any};
     10│



Found 15 errors

Expected behavior
No parsing errors should be introduced.

Additional context

I ran into this error in a real project when upgrading from Lingui 1 to the most recent version earlier this week. I suspect it's related to #250, as degrading to Lingui 2.3.0 made the errors go away. That again may possibly be related to facebook/flow#2830?

package.json in my minimal reproduction looks like this:

{
  "name": "testproject",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "dependencies": {
    "@lingui/cli": "^2.5.0",
    "@lingui/core": "^2.5.0",
    "@lingui/react": "^2.5.0",
    "flow-bin": "^0.79.1"
  }
}
  • jsLingui version lingui --version: 2.5.0
  • Running MacOS High Sierra, 10.13.6, yarn 1.9.2
@tricoder42
Copy link
Contributor

Hey @fagerbua, you're right, this is upstream issue. It's also reported here facebook/flow#5169

I think in the next version I'll simply copy source files and add .flow extension how it was done in previous versions of Lingui. It's not perfect, but good enough until we find a better way to export flow types.

Meanwhile I can only recommend to ignore @lingui packages in flowconfig...

What's your opinion on this?

@tricoder42 tricoder42 added the bug label Aug 31, 2018
@tricoder42
Copy link
Contributor

Actually, another workaround might be possible: generate flow types using gen-flow-types, edit incorrect files manually and commit them to each package. This would be probably better, because the API doesn't change so much often.

@fagerbua
Copy link
Author

@tricoder42 Thanks for looking into this. If you'd care to correct the files manually until gen-flow-types is fixed, it'd be great!

In the meantime I'll add node_modules/@lingui to the [ignore] section of my .flowconfig, and run flow-typed create-stub @lingui/cli @lingui/core @lingui/cli to get rid of the Cannot resolve module errors that result from just ignoring the library.

@tricoder42
Copy link
Contributor

Released in v2.7.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants