Skip to content
This repository has been archived by the owner on Nov 13, 2023. It is now read-only.

Commit

Permalink
Experimental: Add support for pairs in @genType.import to encode rena…
Browse files Browse the repository at this point in the history
…me information.

Instead of typing
```
[@genType.import "foo"]
[@genType.as "bar"]
```
support the use of
```
[@genType.import ("foo", "bar")]
```

See #117.
  • Loading branch information
cristianoc committed Jan 20, 2019
1 parent 4c5d1e6 commit 72ce194
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
8 changes: 8 additions & 0 deletions examples/typescript-react-example/src/TestImport.gen.tsx
Expand Up @@ -12,6 +12,8 @@ import {TopLevelClass as TopLevelClass} from './MyBanner';

import * as React from 'react';

import {default as defaultValue2NotChecked} from './exportNestedValues';

// tslint:disable-next-line:no-var-requires
const ReasonReact = require('reason-react/src/ReasonReact.js');

Expand Down Expand Up @@ -50,5 +52,11 @@ export function MyBannerInternalTypeChecked(props: Props) {
// Export 'make' early to allow circular import from the '.bs.js' file.
export const make: unknown = function _(show: any, message: any, children: any) { return ReasonReact.wrapJsForReason(TopLevelClass.MiddleLevelElements.MyBannerInternal, {show: show, message: (message == null ? message : {text:message[0]})}, children); };

// In case of type error, check the type of 'defaultValue2' in 'TestImport.re' and './exportNestedValues'.
export const defaultValue2TypeChecked: number = defaultValue2NotChecked;

// Export 'defaultValue2' early to allow circular import from the '.bs.js' file.
export const defaultValue2: unknown = defaultValue2TypeChecked as number;

// tslint:disable-next-line:interface-over-type-literal
export type message = { readonly text: string };
6 changes: 5 additions & 1 deletion examples/typescript-react-example/src/TestImport.re
Expand Up @@ -39,4 +39,8 @@ external make:
) =
"";

let make = make;
let make = make;

[@genType.import ("./exportNestedValues", "default")]
[@bs.module "./TestImport.gen"]
external defaultValue2: int = "";
17 changes: 16 additions & 1 deletion src/Annotation.re
Expand Up @@ -112,7 +112,22 @@ let getAttributeImportRenaming = attributes => {
let attributeImport = attributes |> getAttributePayload(tagIsGenTypeImport);
let attributeRenaming = attributes |> getAttributeRenaming;
switch (attributeImport, attributeRenaming) {
| (Some(StringPayload(s)), _) => (Some(s), attributeRenaming)
| (Some(StringPayload(importString)), _) => (
Some(importString),
attributeRenaming,
)
| (
Some(
TuplePayload([
StringPayload(importString),
StringPayload(renameString),
]),
),
_,
) => (
Some(importString),
Some(renameString),
)
| _ => (None, attributeRenaming)
};
};
Expand Down

0 comments on commit 72ce194

Please sign in to comment.