Skip to content

Commit

Permalink
Add error message for paring unnamed params
Browse files Browse the repository at this point in the history
Summary:
We're currently not supporting this kind of params

```
+sample(string):void
````

and here's special exception for it.

Reviewed By: RSNara

Differential Revision: D16708583

fbshipit-source-id: 809f9808b77108857c8363536b896089e9cb957f
  • Loading branch information
osdnk authored and facebook-github-bot committed Aug 15, 2019
1 parent 958b7aa commit 996ea88
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,31 @@ export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
`;

const NATIVE_MODULES_WITH_UNNAMED_PARAMS = `
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
import type {TurboModule} from '../RCTExport';
import * as TurboModuleRegistry from '../TurboModuleRegistry';
export interface Spec extends TurboModule {
+getBool: (boolean) => boolean;
}
export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
`;

const NATIVE_MODULES_WITH_PROMISE_WITHOUT_TYPE = `
/**
* Copyright (c) Facebook, Inc. and its affiliates.
Expand Down Expand Up @@ -186,6 +211,7 @@ export interface Spec2 extends TurboModule {

module.exports = {
NATIVE_MODULES_WITH_READ_ONLY_OBJECT_NO_TYPE_FOR_CONTENT,
NATIVE_MODULES_WITH_UNNAMED_PARAMS,
NATIVE_MODULES_WITH_PROMISE_WITHOUT_TYPE,
NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT_AS_PARAM,
NATIVE_MODULES_WITH_ARRAY_WITH_NO_TYPE_FOR_CONTENT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ exports[`RN Codegen Flow Parser Fails with error message NATIVE_MODULES_WITH_PRO

exports[`RN Codegen Flow Parser Fails with error message NATIVE_MODULES_WITH_READ_ONLY_OBJECT_NO_TYPE_FOR_CONTENT 1`] = `"Unsupported param for method \\"getString\\", param \\"arg\\". No type specified for $ReadOnly"`;

exports[`RN Codegen Flow Parser Fails with error message NATIVE_MODULES_WITH_UNNAMED_PARAMS 1`] = `"Unsupported type for getBool. Please provide a name for every parameter."`;

exports[`RN Codegen Flow Parser Fails with error message TWO_NATIVE_EXTENDING_TURBO_MODULE 1`] = `"Found two types extending \\"TurboModule\\" is one file. Split them into separated files."`;

exports[`RN Codegen Flow Parser Fails with error message TWO_NATIVE_MODULES_EXPORTED_WITH_DEFAULT 1`] = `
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ function getObjectProperties(
let optional = objectTypeProperty.optional;
let value = objectTypeProperty.value;
if (value.type === 'NullableTypeAnnotation') {
optional = true;
if (
objectTypeProperty.value.typeAnnotation.type !== 'StringTypeAnnotation'
) {
optional = true;
}
value = objectTypeProperty.value.typeAnnotation;
}
return {
Expand Down Expand Up @@ -145,6 +149,11 @@ function getTypeAnnotationForParam(
types: TypeMap,
): FunctionTypeAnnotationParam {
let param = paramAnnotation;
if (param.name === null) {
throw new Error(
`Unsupported type for ${name}. Please provide a name for every parameter.`,
);
}
let paramName = param.name.name;
let nullable = false;
if (param.typeAnnotation.type === 'NullableTypeAnnotation') {
Expand Down

0 comments on commit 996ea88

Please sign in to comment.