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

Commit

Permalink
Remove deprecated way of wrapping JS components.
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianoc committed Oct 15, 2018
1 parent 901c810 commit 9c38882
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 148 deletions.
19 changes: 0 additions & 19 deletions src/CodeItem.re
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,6 @@ type componentBinding = {
typ,
};

type wrapJsComponentDeprecated = {
componentName: string,
importPath: ImportPath.t,
};

type wrapJsValue = {
valueName: string,
importString: string,
Expand All @@ -62,7 +57,6 @@ type valueBinding = {

type t =
| ImportType(importType)
| WrapJsComponentDeprecated(wrapJsComponentDeprecated)
| WrapJsValue(wrapJsValue)
| WrapJsComponent(wrapJsComponent)
| ValueBinding(valueBinding)
Expand Down Expand Up @@ -115,8 +109,6 @@ let toString = (~language, codeItem) =>
switch (codeItem) {
| ImportType(importType) =>
"ImportType " ++ getImportTypeUniqueName(importType)
| WrapJsComponentDeprecated(externalReactClass) =>
"WrapJsComponentDeprecated " ++ externalReactClass.componentName
| WrapJsValue(wrapJsValue) => "WrapJsValue " ++ wrapJsValue.valueName
| WrapJsComponent(wrapJsComponent) =>
"WrapJsComponent " ++ wrapJsComponent.importString
Expand Down Expand Up @@ -409,24 +401,13 @@ let translatePrimitive =
let typeExprTranslation =
valueDescription.val_desc.ctyp_type
|> Dependencies.translateTypeExpr(~language);
let genTypeKind = valueDescription.val_attributes |> getGenTypeKind;
let genTypeImportPayload =
valueDescription.val_attributes |> getAttributePayload(tagIsGenTypeImport);
switch (
typeExprTranslation.typ,
valueDescription.val_prim,
genTypeImportPayload,
) {
| (Ident("ReasonReact_reactClass", []), [path, ..._], _)
when path != "" && genTypeKind == GenType => {
dependencies: [],
codeItems: [
WrapJsComponentDeprecated({
componentName: valueName |> String.capitalize,
importPath: path |> ImportPath.fromStringUnsafe,
}),
],
}
| (
Function({
argTypes: [_, ..._],
Expand Down
160 changes: 32 additions & 128 deletions src/EmitJs.re
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ type typeMap = StringMap.t((list(string), typ));
type env = {
requiresEarly: ModuleNameMap.t(ImportPath.t),
requires: ModuleNameMap.t(ImportPath.t),
wrapJsComponentDeprecated: list(CodeItem.wrapJsComponentDeprecated),
/* For each .cmt we import types from, keep the map of exported types. */
cmtExportTypeMapCache: StringMap.t(typeMap),
/* Map of types imported from other files. */
Expand Down Expand Up @@ -45,7 +44,6 @@ let createExportTypeMap = (~language, codeItems): typeMap => {
| ImportType(_)
| ExportVariantType(_)
| ConstructorBinding(_)
| WrapJsComponentDeprecated(_)
| WrapJsComponent(_)
| WrapJsValue(_) => exportTypeMap
};
Expand Down Expand Up @@ -124,65 +122,6 @@ let emitExportType =
~comment,
);

let emitCheckJsWrapperType =
(
~emitters,
~config,
~env,
~propsTypeName,
~exportType: CodeItem.exportType,
) =>
switch (env.wrapJsComponentDeprecated) {
| [] => None

| [{componentName, _}] =>
let s =
"("
++ (
"props"
|> EmitTyp.ofType(
~language=config.language,
~typ=Ident(propsTypeName, []),
)
)
++ ") {\n return <"
++ componentName
++ " {...props}/>;\n }";
let exportTypeNoChildren =
switch (exportType.typ) {
| GroupOfLabeledArgs(fields) =>
switch (fields |> List.rev) {
| [_child, ...propFieldsRev] =>
let typNoChildren = GroupOfLabeledArgs(propFieldsRev |> List.rev);
{...exportType, typ: typNoChildren};
| [] => exportType
}
| _ => exportType
};
let emitters =
emitExportType(
~language=config.language,
~emitters,
exportTypeNoChildren,
);
let emitters =
EmitTyp.emitExportFunction(
~early=false,
~emitters,
~name="checkJsWrapperType",
~config,
s,
);

Some(emitters);

| [_, ..._] =>
Some(
"// genType warning: found more than one external component annotated with @genType"
|> Emitters.export(~emitters),
)
};

let emitCodeItem =
(
~config,
Expand Down Expand Up @@ -367,75 +306,44 @@ let emitCodeItem =
| _ => [jsPropsDot("children")]
};

switch (
emitCheckJsWrapperType(
let emitters = emitExportType(~emitters, ~language, exportType);
let emitters =
EmitTyp.emitExportConstMany(
~emitters,
~name,
~typ=componentType,
~config,
~env,
~propsTypeName,
~exportType,
)
) {
| Some(emitters) => (env, emitters)
| None =>
let emitters = emitExportType(~emitters, ~language, exportType);
let emitters =
EmitTyp.emitExportConstMany(
~emitters,
~name,
~typ=componentType,
~config,
[
"ReasonReact.wrapReasonForJs(",
" " ++ ModuleName.toString(moduleNameBs) ++ ".component" ++ ",",
" (function _("
++ EmitTyp.ofType(
~language,
~typ=Ident(propsTypeName, []),
jsProps,
)
++ ") {",
" return "
++ ModuleName.toString(moduleNameBs)
++ "."
++ "make"
++ EmitText.parens(args)
++ ";",
" }));",
],
);
[
"ReasonReact.wrapReasonForJs(",
" " ++ ModuleName.toString(moduleNameBs) ++ ".component" ++ ",",
" (function _("
++ EmitTyp.ofType(
~language,
~typ=Ident(propsTypeName, []),
jsProps,
)
++ ") {",
" return "
++ ModuleName.toString(moduleNameBs)
++ "."
++ "make"
++ EmitText.parens(args)
++ ";",
" }));",
],
);

let emitters = EmitTyp.emitExportDefault(~emitters, ~config, name);
let emitters = EmitTyp.emitExportDefault(~emitters, ~config, name);

let envBs =
moduleNameBs |> requireModule(~early=false, ~env, ~importPath);
let requiresWithReasonReact =
envBs.requires
|> ModuleNameMap.add(
ModuleName.reasonReact,
ImportPath.reasonReactPath(~config),
);
({...envBs, requires: requiresWithReasonReact}, emitters);
};

| WrapJsComponentDeprecated(
{componentName, importPath} as wrapJsComponentDeprecated,
) =>
let requires =
env.requires
let envBs =
moduleNameBs |> requireModule(~early=false, ~env, ~importPath);
let requiresWithReasonReact =
envBs.requires
|> ModuleNameMap.add(
ModuleName.fromStringUnsafe(componentName),
importPath,
ModuleName.reasonReact,
ImportPath.reasonReactPath(~config),
);
let newEnv = {
...env,
requires,
wrapJsComponentDeprecated: [
wrapJsComponentDeprecated,
...env.wrapJsComponentDeprecated,
],
};
(newEnv, emitters);
({...envBs, requires: requiresWithReasonReact}, emitters);

| WrapJsValue({valueName, importString, typ, moduleName}) =>
let importPath = importString |> ImportPath.fromStringUnsafe;
Expand Down Expand Up @@ -650,7 +558,6 @@ let emitCodeItems =
let initialEnv = {
requires: ModuleNameMap.empty,
requiresEarly: ModuleNameMap.empty,
wrapJsComponentDeprecated: [],
cmtExportTypeMapCache: StringMap.empty,
typesFromOtherFiles: StringMap.empty,
};
Expand Down Expand Up @@ -678,9 +585,6 @@ let emitCodeItems =
finalEnv.requiresEarly,
emitters,
);
let emitters =
finalEnv.wrapJsComponentDeprecated != [] ?
EmitTyp.emitRequireReact(~early=false, ~emitters, ~language) : emitters;
let emitters =
ModuleNameMap.fold(
(moduleName, importPath, emitters) =>
Expand Down
1 change: 0 additions & 1 deletion src/GenTypeMain.re
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ open GenTypeCommon;
let getPriority = x =>
switch (x) {
| CodeItem.ImportType(_)
| WrapJsComponentDeprecated(_)
| WrapJsComponent(_)
| WrapJsValue(_) => "2low"
| ValueBinding(_)
Expand Down

0 comments on commit 9c38882

Please sign in to comment.