├── .dockerignore ├── .github ├── ISSUE_TEMPLATE │ ├── config.yml │ └── ocaml_issue.md └── workflows │ └── ci.yml ├── .gitignore ├── .npmignore ├── .ocamlformat ├── .vscode └── settings.json ├── CONTRIBUTING.md ├── Changes.md ├── Dockerfile ├── EXCEPTION.md ├── LICENSE ├── README.md ├── TERMINATION.md ├── assets ├── genFlow.png ├── genFlowInAction.png ├── genFlowWrapJsComponent.png └── genTypeDemo.png ├── create-release.sh ├── dead-code-ppx ├── DeadCodePPX.ml └── dune ├── dist ├── .npmignore ├── README.md ├── postinstall.js ├── reanalyze.exe ├── vendor-darwin │ └── .keep ├── vendor-darwinarm64 │ └── .keep ├── vendor-linux │ └── .keep └── vendor-win32 │ └── .keep ├── dune ├── dune-project ├── examples ├── deadcode │ ├── .gitignore │ ├── .watchmanconfig │ ├── bsconfig.json │ ├── package-lock.json │ ├── package.json │ └── src │ │ ├── AutoAnnotate.bs.js │ │ ├── AutoAnnotate.gen.tsx │ │ ├── AutoAnnotate.res │ │ ├── BootloaderResource.bs.js │ │ ├── BootloaderResource.res │ │ ├── BucklescriptAnnotations.bs.js │ │ ├── BucklescriptAnnotations.gen.tsx │ │ ├── BucklescriptAnnotations.res │ │ ├── ComponentAsProp.bs.js │ │ ├── ComponentAsProp.gen.tsx │ │ ├── ComponentAsProp.res │ │ ├── CreateErrorHandler1.bs.js │ │ ├── CreateErrorHandler1.res │ │ ├── CreateErrorHandler2.bs.js │ │ ├── CreateErrorHandler2.res │ │ ├── DeadCodeImplementation.bs.js │ │ ├── DeadCodeImplementation.res │ │ ├── DeadCodeInterface.bs.js │ │ ├── DeadCodeInterface.res │ │ ├── DeadExn.bs.js │ │ ├── DeadExn.res │ │ ├── DeadExn.resi │ │ ├── DeadMl.bs.js │ │ ├── DeadMl.ml │ │ ├── DeadRT.bs.js │ │ ├── DeadRT.res │ │ ├── DeadRT.resi │ │ ├── DeadTest.bs.js │ │ ├── DeadTest.gen.tsx │ │ ├── DeadTest.res │ │ ├── DeadTestBlacklist.bs.js │ │ ├── DeadTestBlacklist.res │ │ ├── DeadTestWithInterface.bs.js │ │ ├── DeadTestWithInterface.res │ │ ├── DeadTestWithInterface.resi │ │ ├── DeadTypeTest.bs.js │ │ ├── DeadTypeTest.res │ │ ├── DeadTypeTest.resi │ │ ├── DeadValueTest.bs.js │ │ ├── DeadValueTest.res │ │ ├── DeadValueTest.resi │ │ ├── Docstrings.bs.js │ │ ├── Docstrings.gen.tsx │ │ ├── Docstrings.res │ │ ├── DynamicallyLoadedComponent.bs.js │ │ ├── DynamicallyLoadedComponent.res │ │ ├── EmptyArray.bs.js │ │ ├── EmptyArray.res │ │ ├── ErrorHandler.bs.js │ │ ├── ErrorHandler.res │ │ ├── ErrorHandler.resi │ │ ├── EverythingLiveHere.bs.js │ │ ├── EverythingLiveHere.res │ │ ├── FC.bs.js │ │ ├── FC.res │ │ ├── FirstClassModules.bs.js │ │ ├── FirstClassModules.gen.tsx │ │ ├── FirstClassModules.res │ │ ├── FirstClassModulesInterface.bs.js │ │ ├── FirstClassModulesInterface.gen.tsx │ │ ├── FirstClassModulesInterface.res │ │ ├── FirstClassModulesInterface.resi │ │ ├── Hooks.bs.js │ │ ├── Hooks.gen.tsx │ │ ├── Hooks.res │ │ ├── IgnoreInterface.bs.js │ │ ├── IgnoreInterface.gen.tsx │ │ ├── IgnoreInterface.res │ │ ├── IgnoreInterface.resi │ │ ├── ImmutableArray.bs.js │ │ ├── ImmutableArray.res │ │ ├── ImmutableArray.resi │ │ ├── ImportHookDefault.bs.js │ │ ├── ImportHookDefault.gen.tsx │ │ ├── ImportHookDefault.res │ │ ├── ImportHooks.bs.js │ │ ├── ImportHooks.gen.tsx │ │ ├── ImportHooks.res │ │ ├── ImportIndex.bs.js │ │ ├── ImportIndex.gen.tsx │ │ ├── ImportIndex.res │ │ ├── ImportJsValue.bs.js │ │ ├── ImportJsValue.gen.tsx │ │ ├── ImportJsValue.res │ │ ├── ImportMyBanner.bs.js │ │ ├── ImportMyBanner.gen.tsx │ │ ├── ImportMyBanner.res │ │ ├── JSResource.bs.js │ │ ├── JSResource.res │ │ ├── LetPrivate.bs.js │ │ ├── LetPrivate.gen.tsx │ │ ├── LetPrivate.res │ │ ├── ModuleAliases.bs.js │ │ ├── ModuleAliases.gen.tsx │ │ ├── ModuleAliases.res │ │ ├── ModuleAliases2.bs.js │ │ ├── ModuleAliases2.gen.tsx │ │ ├── ModuleAliases2.res │ │ ├── ModuleExceptionBug.bs.js │ │ ├── ModuleExceptionBug.res │ │ ├── NestedModules.bs.js │ │ ├── NestedModules.gen.tsx │ │ ├── NestedModules.res │ │ ├── NestedModulesInSignature.bs.js │ │ ├── NestedModulesInSignature.gen.tsx │ │ ├── NestedModulesInSignature.res │ │ ├── NestedModulesInSignature.resi │ │ ├── Newsyntax.bs.js │ │ ├── Newsyntax.res │ │ ├── Newton.bs.js │ │ ├── Newton.res │ │ ├── Opaque.bs.js │ │ ├── Opaque.gen.tsx │ │ ├── Opaque.res │ │ ├── OptArg.bs.js │ │ ├── OptArg.res │ │ ├── OptArg.resi │ │ ├── Records.bs.js │ │ ├── Records.gen.tsx │ │ ├── Records.res │ │ ├── References.bs.js │ │ ├── References.gen.tsx │ │ ├── References.res │ │ ├── RepeatedLabel.bs.js │ │ ├── RepeatedLabel.res │ │ ├── RequireCond.bs.js │ │ ├── RequireCond.res │ │ ├── Shadow.bs.js │ │ ├── Shadow.gen.tsx │ │ ├── Shadow.res │ │ ├── TestDeadExn.bs.js │ │ ├── TestDeadExn.res │ │ ├── TestEmitInnerModules.bs.js │ │ ├── TestEmitInnerModules.gen.tsx │ │ ├── TestEmitInnerModules.res │ │ ├── TestFirstClassModules.bs.js │ │ ├── TestFirstClassModules.gen.tsx │ │ ├── TestFirstClassModules.res │ │ ├── TestImmutableArray.bs.js │ │ ├── TestImmutableArray.gen.tsx │ │ ├── TestImmutableArray.res │ │ ├── TestImport.bs.js │ │ ├── TestImport.gen.tsx │ │ ├── TestImport.res │ │ ├── TestModuleAliases.bs.js │ │ ├── TestModuleAliases.gen.tsx │ │ ├── TestModuleAliases.res │ │ ├── TestOptArg.bs.js │ │ ├── TestOptArg.res │ │ ├── TestPromise.bs.js │ │ ├── TestPromise.gen.tsx │ │ ├── TestPromise.res │ │ ├── ToSuppress.bs.js │ │ ├── ToSuppress.res │ │ ├── TransitiveType1.bs.js │ │ ├── TransitiveType1.gen.tsx │ │ ├── TransitiveType1.res │ │ ├── TransitiveType2.bs.js │ │ ├── TransitiveType2.gen.tsx │ │ ├── TransitiveType2.res │ │ ├── TransitiveType3.bs.js │ │ ├── TransitiveType3.gen.tsx │ │ ├── TransitiveType3.res │ │ ├── Tuples.bs.js │ │ ├── Tuples.gen.tsx │ │ ├── Tuples.res │ │ ├── TypeParams1.bs.js │ │ ├── TypeParams1.gen.tsx │ │ ├── TypeParams1.res │ │ ├── TypeParams2.bs.js │ │ ├── TypeParams2.gen.tsx │ │ ├── TypeParams2.res │ │ ├── TypeParams3.bs.js │ │ ├── TypeParams3.gen.tsx │ │ ├── TypeParams3.res │ │ ├── Types.bs.js │ │ ├── Types.gen.tsx │ │ ├── Types.res │ │ ├── Unboxed.bs.js │ │ ├── Unboxed.gen.tsx │ │ ├── Unboxed.res │ │ ├── Uncurried.bs.js │ │ ├── Uncurried.gen.tsx │ │ ├── Uncurried.res │ │ ├── Unison.bs.js │ │ ├── Unison.res │ │ ├── UseImportJsValue.bs.js │ │ ├── UseImportJsValue.gen.tsx │ │ ├── UseImportJsValue.res │ │ ├── Variants.bs.js │ │ ├── Variants.gen.tsx │ │ ├── Variants.res │ │ ├── VariantsWithPayload.bs.js │ │ ├── VariantsWithPayload.gen.tsx │ │ ├── VariantsWithPayload.res │ │ ├── deadcode.txt │ │ ├── exception.txt │ │ ├── exception │ │ ├── Arr.bs.js │ │ ├── Arr.res │ │ ├── BeltTest.bs.js │ │ ├── BeltTest.res │ │ ├── BsJson.bs.js │ │ ├── BsJson.res │ │ ├── Exn.bs.js │ │ ├── Exn.res │ │ ├── ExnA.bs.js │ │ ├── ExnA.res │ │ ├── ExnB.bs.js │ │ ├── ExnB.res │ │ ├── ExportWithRename.bs.js │ │ ├── ExportWithRename.gen.tsx │ │ ├── ExportWithRename.res │ │ ├── InnerModules.bs.js │ │ ├── InnerModules.res │ │ ├── TestInnerModules.bs.js │ │ ├── TestInnerModules.res │ │ ├── TestYojson.bs.js │ │ ├── TestYojson.res │ │ ├── Yojson.bs.js │ │ └── Yojson.res │ │ ├── exportNestedValues.js │ │ ├── noalloc.txt │ │ └── noalloc │ │ ├── Chess.bs.js │ │ ├── Chess.res │ │ ├── Matrix.bs.js │ │ ├── Matrix.res │ │ ├── TestNoalloc.bs.js │ │ └── TestNoalloc.res └── termination │ ├── .gitignore │ ├── .watchmanconfig │ ├── Makefile │ ├── README.md │ ├── bsconfig.json │ ├── package-lock.json │ ├── package.json │ └── src │ ├── TestCyberTruck.bs.js │ ├── TestCyberTruck.res │ └── termination.txt ├── lazyload-ppx ├── LazyLoad.ml └── dune ├── package-lock.json ├── package.json ├── reanalyze.opam ├── scripts ├── bump_version_module.js ├── download_dist.js ├── prepare_release.js └── run_integration_tests.js └── src ├── Annotation.ml ├── Arnold.ml ├── CL.ml ├── Common.ml ├── Compat.ml ├── DeadCode.ml ├── DeadCommon.ml ├── DeadException.ml ├── DeadModules.ml ├── DeadOptionalArgs.ml ├── DeadType.ml ├── DeadValue.ml ├── EmitJson.ml ├── Exception.ml ├── Exceptions.ml ├── Exceptions.mli ├── Exn.ml ├── Exn.mli ├── ExnLib.ml ├── FindSourceFile.ml ├── Il.ml ├── Log_.ml ├── ModulePath.ml ├── Name.ml ├── Name.mli ├── Noalloc.ml ├── Paths.ml ├── Reanalyze.ml ├── RunConfig.ml ├── SideEffects.ml ├── Suppress.ml ├── Version.ml ├── compiler-libs-406 ├── ast_helper.ml ├── ast_helper.mli ├── ast_mapper.ml ├── ast_mapper.mli ├── asttypes.mli ├── bsc_warnings.ml ├── btype.ml ├── builtin_attributes.ml ├── builtin_attributes.mli ├── clflags.ml ├── clflags.mli ├── cmi_format.ml ├── cmi_format.mli ├── cmt_format.ml ├── cmt_format.mli ├── config.ml ├── config.mli ├── consistbl.ml ├── consistbl.mli ├── datarepr.ml ├── datarepr.mli ├── docstrings.ml ├── docstrings.mli ├── dune ├── env.ml ├── env.mli ├── ext_pervasives.ml ├── ident.ml ├── ident.mli ├── identifiable.ml ├── identifiable.mli ├── lexer.ml ├── lexer.mli ├── location.ml ├── location.mli ├── longident.ml ├── longident.mli ├── misc.ml ├── outcometree.mli ├── parser.ml ├── parser.mli ├── parsetree.mli ├── path.ml ├── path.mli ├── predef.ml ├── predef.mli ├── primitive.ml ├── primitive.mli ├── subst.ml ├── subst.mli ├── syntaxerr.ml ├── syntaxerr.mli ├── tast_mapper.ml ├── tast_mapper.mli ├── tbl.ml ├── tbl.mli ├── typedtree.ml ├── typedtree.mli ├── types.ml ├── types.mli └── warnings.ml ├── dune ├── dune.406 ├── ext ├── ext_json_parse.ml ├── ext_json_types.ml └── ext_position.ml └── vendor └── Json.ml /.dockerignore: -------------------------------------------------------------------------------- 1 | examples 2 | assets 3 | node_modules 4 | npm-debug.log 5 | Dockerfile* 6 | docker-compose* 7 | .dockerignore 8 | .git 9 | .gitignore 10 | README.md 11 | LICENSE 12 | .vscode 13 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Using Reanalyze with ReScript? 4 | url: https://github.com/rescript-lang/rescript-vscode/issues/new 5 | about: Reanalyze is being developed in the rescript-vscode repo. Please open your issue there. 6 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/ocaml_issue.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Using Reanalyze with OCaml? 3 | about: Create an issue here 4 | title: "" 5 | labels: "" 6 | assignees: "" 7 | --- 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.DS_Store* 2 | *.merlin* 3 | *.bsb.lock* 4 | *.coverage 5 | bundledOutputs/ 6 | _coverage/ 7 | 8 | lib/ 9 | node_modules/ 10 | /_build 11 | /_release 12 | /reanalyze.install 13 | /yarn-error.log 14 | 15 | # npm publish related stuff 16 | reanalyze-*.tgz 17 | 18 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | * 2 | !lib/gen*.tar.gz -------------------------------------------------------------------------------- /.ocamlformat: -------------------------------------------------------------------------------- 1 | cases-exp-indent = 2 2 | space-around-arrays = false 3 | space-around-lists = false 4 | space-around-records = false 5 | space-around-variants = false 6 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "ocaml.sandbox": { 3 | "switch": "4.06.1", 4 | "kind": "opam" 5 | } 6 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Development 2 | 3 | ## Build reanalyze 4 | 5 | Assumes opam with OCaml 4.08 or later. 6 | 7 | ``` 8 | # Installs all dependencies (if needed) and builds reanalyze 9 | npm install 10 | npm run build 11 | ``` 12 | 13 | To build targeting 4.06 compiler libs (needed for ReScript projects) whatever the compiler version used: 14 | 15 | ``` 16 | npm run build406 17 | ``` 18 | 19 | 20 | ## Test reanalyze 21 | 22 | Make sure to always run the tests before submitting any changes (CI usually takes 23 | longer to give you feedback). 24 | 25 | ``` 26 | npm run build406 27 | npm test 28 | ``` 29 | 30 | ## Releases (for Maintainers) 31 | 32 | The project is compatible with the [`npm 33 | version`](https://docs.npmjs.com/cli/version) workflow. After using the `npm 34 | version [major|minor|patch|...]` command, npm will automatically tag the 35 | current commit, bump all the necessary version numbers (also the number in 36 | `src/Version.ml`) and push it to the current remote branch. 37 | 38 | Use the `...` menu next to the [tag](https://github.com/rescript-association/reanalyze/tags) to create a release manually. (To be automated later). 39 | 40 | **Here are the concrete commands to run:** 41 | 42 | ``` 43 | # Make sure to commit & push all current changes, the working branch should be clean 44 | # and synced up with your remote branch 45 | 46 | # Also make sure that your current branch is explicitly set to the relevant remote 47 | # (`git push` instead of `git push origin master`) 48 | git status 49 | 50 | # For patches (0.0.X+1) 51 | npm version patch 52 | 53 | # For minor (0.X+1.0) 54 | npm version minor 55 | 56 | # For major (X+1.0.0) 57 | npm version major 58 | ``` 59 | 60 | ## Releasing to npm (Maintainers only) 61 | 62 | Use the GitHub web iterface to download the artifact `reanalyze-npm.tar` and zip it. 63 | 64 | ``` 65 | # Dry run for testing 66 | npm publish reanalyze-npm.tar.gz --dry-run 67 | 68 | # Publish package as @latest 69 | npm publish reanalyze-npm.tar.gz 70 | 71 | # Publish package with @beta tag 72 | npm publish reanalyze-npm.tar.gz --tag beta 73 | ``` 74 | 75 | Consult the [npm publish](https://docs.npmjs.com/cli/publish) documentation for more options. 76 | In case you get an `ENEEDAUTH` error, use `npm adduser` and authenticate with your npm account first. 77 | 78 | ## Releasing ot opam (Maintainers only) 79 | 80 | ``` 81 | docker build -t opam-publish --pull . 82 | docker run --rm -it -v ~/.ssh:/home/opam/.ssh -v `pwd`:/data opam-publish bash 83 | cd /data 84 | opam publish 85 | ``` 86 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ocaml/opam:debian-11-ocaml-4.14 2 | 3 | USER root 4 | RUN apt-get update \ 5 | && apt-get install -y pkg-config libgmp-dev libssl-dev \ 6 | && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 7 | 8 | USER opam 9 | RUN opam update 10 | RUN opam install opam-publish 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 reasonml 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /assets/genFlow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rescript-lang/reanalyze/650bd42a933feb3f7b9631a85b6910d8e7a97839/assets/genFlow.png -------------------------------------------------------------------------------- /assets/genFlowInAction.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rescript-lang/reanalyze/650bd42a933feb3f7b9631a85b6910d8e7a97839/assets/genFlowInAction.png -------------------------------------------------------------------------------- /assets/genFlowWrapJsComponent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rescript-lang/reanalyze/650bd42a933feb3f7b9631a85b6910d8e7a97839/assets/genFlowWrapJsComponent.png -------------------------------------------------------------------------------- /assets/genTypeDemo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rescript-lang/reanalyze/650bd42a933feb3f7b9631a85b6910d8e7a97839/assets/genTypeDemo.png -------------------------------------------------------------------------------- /create-release.sh: -------------------------------------------------------------------------------- 1 | set -e 2 | 3 | # Cleanup 4 | rm -f lib/reanalyze-*.tar.gz 5 | 6 | # MacOS 7 | npm install 8 | npm run clean && npm run build && npm run test 9 | tar czvf lib/reanalyze-macos.tar.gz -C src/lib/bs/native reanalyze.native 10 | 11 | 12 | # Linux 13 | # Copies package.json etc. and runs `npm install`. 14 | docker build -t reanalyze . 15 | 16 | # Mounts only the lib and src volume and runs `npm run build` 17 | docker run -it -v $PWD/lib:/reanalyze/lib -v $PWD/src:/reanalyze/src reanalyze bash -c "npm run clean && npm run build" 18 | 19 | tar czvf lib/reanalyze-linux.tar.gz -C src/lib/bs/native reanalyze.native 20 | -------------------------------------------------------------------------------- /dead-code-ppx/DeadCodePPX.ml: -------------------------------------------------------------------------------- 1 | open Compilerlibs406 2 | 3 | (* Remove code annotated with @dead *) 4 | 5 | let hasDeadAnnotation attributes = 6 | attributes 7 | |> List.exists (fun (({txt}, _) : Parsetree.attribute) -> txt = "dead") 8 | 9 | let rec filter_map l ~f = 10 | match l with 11 | | [] -> [] 12 | | x :: rest -> ( 13 | match f x with 14 | | None -> filter_map rest ~f 15 | | Some y -> y :: filter_map rest ~f) 16 | 17 | let value_binding_list mapper value_bindings = 18 | value_bindings 19 | |> filter_map ~f:(fun (value_binding : Parsetree.value_binding) -> 20 | if value_binding.pvb_attributes |> hasDeadAnnotation then None 21 | else 22 | Some (Ast_mapper.default_mapper.value_binding mapper value_binding)) 23 | 24 | let structure mapper structure = 25 | structure 26 | |> filter_map ~f:(fun (structure_item : Parsetree.structure_item) -> 27 | match structure_item.pstr_desc with 28 | | Pstr_value (rec_value, value_bindings) -> 29 | let value_bindings = value_binding_list mapper value_bindings in 30 | if value_bindings = [] then None 31 | else 32 | Some 33 | { 34 | structure_item with 35 | pstr_desc = Pstr_value (rec_value, value_bindings); 36 | } 37 | | Pstr_primitive {pval_attributes} -> 38 | if pval_attributes |> hasDeadAnnotation then None 39 | else 40 | Some 41 | (Ast_mapper.default_mapper.structure_item mapper structure_item) 42 | | Pstr_exception x -> 43 | if x.pext_attributes |> hasDeadAnnotation then None 44 | else 45 | Some 46 | (Ast_mapper.default_mapper.structure_item mapper structure_item) 47 | | _ -> 48 | Some (Ast_mapper.default_mapper.structure_item mapper structure_item)) 49 | 50 | let signature mapper signature = 51 | signature 52 | |> filter_map ~f:(fun (signature_item : Parsetree.signature_item) -> 53 | let test = 54 | match signature_item.psig_desc with 55 | | Psig_value {pval_attributes} -> 56 | not (pval_attributes |> hasDeadAnnotation) 57 | | _ -> true 58 | in 59 | if test then 60 | Some (Ast_mapper.default_mapper.signature_item mapper signature_item) 61 | else None) 62 | 63 | let () = 64 | Ast_mapper.register "DeadPPX" (fun _argv -> 65 | {Ast_mapper.default_mapper with signature; structure}) 66 | -------------------------------------------------------------------------------- /dead-code-ppx/dune: -------------------------------------------------------------------------------- 1 | (executable 2 | (name DeadCodePPX) 3 | (public_name deadcodeppx.exe) 4 | (preprocess 5 | (action 6 | (run %{bin:cppo} -V OCAML:%{ocaml_version} %{input-file}))) 7 | (libraries compilerlibs406) 8 | (flags 9 | (:standard -w -9))) 10 | -------------------------------------------------------------------------------- /dist/.npmignore: -------------------------------------------------------------------------------- 1 | **/.keep 2 | -------------------------------------------------------------------------------- /dist/README.md: -------------------------------------------------------------------------------- 1 | # reanalyze 2 | 3 | Please refer to the [Github repository](https://github.com/cristianoc/reanalyze) for now. -------------------------------------------------------------------------------- /dist/postinstall.js: -------------------------------------------------------------------------------- 1 | const path = require("path"); 2 | const fs = require("fs"); 3 | 4 | const platformAndArch = 5 | process.arch === "x64" ? process.platform : process.platform + process.arch; 6 | 7 | function fail(msg) { 8 | console.warn(msg); 9 | process.exit(1); 10 | } 11 | 12 | function movePlatformBinary() { 13 | const binDirName = "vendor-" + platformAndArch; 14 | const sourcePath = path.join(__dirname, binDirName, "reanalyze.exe"); 15 | 16 | if (!fs.existsSync(sourcePath)) { 17 | return fail("error: executable not found: " + sourcePath); 18 | } 19 | 20 | // We always use the .exe extension, no matter if unix / win32 21 | const targetPath = path.join(__dirname, "reanalyze.exe"); 22 | 23 | fs.renameSync(sourcePath, targetPath); 24 | fs.chmodSync(targetPath, 0777); 25 | } 26 | 27 | switch (platformAndArch) { 28 | case "win32": 29 | case "linux": 30 | case "darwin": 31 | case "darwinarm64": 32 | movePlatformBinary(); 33 | break; 34 | default: 35 | fail("error: no release built for the " + platform + " platform"); 36 | } 37 | -------------------------------------------------------------------------------- /dist/reanalyze.exe: -------------------------------------------------------------------------------- 1 | echo "reanalyze was not installed correctly" 2 | exit 1 3 | -------------------------------------------------------------------------------- /dist/vendor-darwin/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rescript-lang/reanalyze/650bd42a933feb3f7b9631a85b6910d8e7a97839/dist/vendor-darwin/.keep -------------------------------------------------------------------------------- /dist/vendor-darwinarm64/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rescript-lang/reanalyze/650bd42a933feb3f7b9631a85b6910d8e7a97839/dist/vendor-darwinarm64/.keep -------------------------------------------------------------------------------- /dist/vendor-linux/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rescript-lang/reanalyze/650bd42a933feb3f7b9631a85b6910d8e7a97839/dist/vendor-linux/.keep -------------------------------------------------------------------------------- /dist/vendor-win32/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rescript-lang/reanalyze/650bd42a933feb3f7b9631a85b6910d8e7a97839/dist/vendor-win32/.keep -------------------------------------------------------------------------------- /dune: -------------------------------------------------------------------------------- 1 | (dirs :standard \ node_modules examples) -------------------------------------------------------------------------------- /dune-project: -------------------------------------------------------------------------------- 1 | (lang dune 2.0) 2 | (name reanalyze) 3 | -------------------------------------------------------------------------------- /examples/deadcode/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /examples/deadcode/.watchmanconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rescript-lang/reanalyze/650bd42a933feb3f7b9631a85b6910d8e7a97839/examples/deadcode/.watchmanconfig -------------------------------------------------------------------------------- /examples/deadcode/bsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "reanalyze": { 3 | "analysis": ["dce"], 4 | "suppress": ["src/ToSuppress.res"], 5 | "unsuppress": [] 6 | }, 7 | "gentypeconfig": { 8 | "language": "typescript", 9 | "module": "es6", 10 | "importPath": "relative", 11 | "debug": { 12 | "all": false 13 | }, 14 | "exportInterfaces": false 15 | }, 16 | "name": "sample-typescript-app", 17 | "bsc-flags": ["-bs-super-errors -w a"], 18 | "ppx-flags": [ 19 | "../../_build/default/dead-code-ppx/DeadCodePPX.exe", 20 | "../../_build/default/lazyload-ppx/LazyLoad.exe" 21 | ], 22 | "reason": { "react-jsx": 3 }, 23 | "bs-dependencies": ["@rescript/react", "@glennsl/bs-json"], 24 | "sources": [ 25 | { 26 | "dir": "src", 27 | "subdirs": true 28 | } 29 | ], 30 | "package-specs": { 31 | "module": "es6", 32 | "in-source": true 33 | }, 34 | "suffix": ".bs.js", 35 | "refmt": 3 36 | } 37 | -------------------------------------------------------------------------------- /examples/deadcode/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "deadcode", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "rescript build -w", 7 | "build": "rescript build", 8 | "clean": "rescript clean -with-deps", 9 | "dce": "npx reanalyze.exe -config -debug -ci -exclude-paths src/noalloc,src/exception -live-names globallyLive1 -live-names globallyLive2,globallyLive3 >src/deadcode.txt", 10 | "exception": "npx reanalyze.exe -exception -ci -suppress src -unsuppress src/exception >src/exception.txt", 11 | "noalloc": "npx reanalyze.exe -ci -noalloc >src/noalloc.txt", 12 | "analyze": "npm run dce && npm run exception && npm run noalloc" 13 | }, 14 | "devDependencies": { 15 | "gentype": "^4.5.0", 16 | "react": "^16.13.1", 17 | "react-dom": "^16.8.6", 18 | "rescript": "^10.0.0-beta.3" 19 | }, 20 | "dependencies": { 21 | "@glennsl/bs-json": "^5.0.4", 22 | "@rescript/react": "^0.10.3", 23 | "reanalyze": "file:../.." 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /examples/deadcode/src/AutoAnnotate.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | /* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ 3 | -------------------------------------------------------------------------------- /examples/deadcode/src/AutoAnnotate.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from AutoAnnotate.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // tslint:disable-next-line:interface-over-type-literal 6 | export type variant = { tag: "R"; value: number }; 7 | 8 | // tslint:disable-next-line:interface-over-type-literal 9 | export type record = { readonly variant: variant }; 10 | 11 | // tslint:disable-next-line:interface-over-type-literal 12 | export type r2 = { readonly r2: number }; 13 | 14 | // tslint:disable-next-line:interface-over-type-literal 15 | export type r3 = { readonly r3: number }; 16 | 17 | // tslint:disable-next-line:interface-over-type-literal 18 | export type r4 = { readonly r4: number }; 19 | 20 | // tslint:disable-next-line:interface-over-type-literal 21 | export type annotatedVariant = 22 | { tag: "R2"; value: [r2, r3] } 23 | | { tag: "R4"; value: r4 }; 24 | -------------------------------------------------------------------------------- /examples/deadcode/src/AutoAnnotate.res: -------------------------------------------------------------------------------- 1 | type variant = R(int) 2 | 3 | @genType 4 | type record = {variant: variant} 5 | 6 | type r2 = {r2: int} 7 | 8 | type r3 = {r3: int} 9 | 10 | type r4 = {r4: int} 11 | 12 | @genType 13 | type annotatedVariant = 14 | | R2(r2, r3) 15 | | R4(r4) 16 | 17 | -------------------------------------------------------------------------------- /examples/deadcode/src/BootloaderResource.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | /* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ 3 | -------------------------------------------------------------------------------- /examples/deadcode/src/BootloaderResource.res: -------------------------------------------------------------------------------- 1 | /* NOTE: This is a spooky interface that provides no type safety. It should be 2 | * improved. Use with caution. */ 3 | @module("BootloaderResource") 4 | external read: JSResource.t<'a> => 'a = "read" 5 | 6 | -------------------------------------------------------------------------------- /examples/deadcode/src/BucklescriptAnnotations.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function bar(x) { 5 | var f = x.twoArgs; 6 | return f(3, "a"); 7 | } 8 | 9 | export { 10 | bar , 11 | } 12 | /* No side effect */ 13 | -------------------------------------------------------------------------------- /examples/deadcode/src/BucklescriptAnnotations.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from BucklescriptAnnotations.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // tslint:disable-next-line:interface-over-type-literal 6 | export type someMutableFields = { 7 | mutable0: string; 8 | readonly immutable: number; 9 | mutable1: string; 10 | mutable2: string 11 | }; 12 | 13 | // tslint:disable-next-line:interface-over-type-literal 14 | export type someMethods = { 15 | readonly send: (_1:string) => void; 16 | readonly on: (_1:string, _2:((_1:number) => void)) => void; 17 | readonly threeargs: (_1:number, _2:string, _3:number) => string; 18 | readonly twoArgs: (_1:number, _2:string) => number 19 | }; 20 | -------------------------------------------------------------------------------- /examples/deadcode/src/BucklescriptAnnotations.res: -------------------------------------------------------------------------------- 1 | @genType 2 | type someMutableFields = { 3 | @set 4 | "mutable0": string, 5 | "immutable": int, 6 | @set 7 | "mutable1": string, 8 | @set 9 | "mutable2": string, 10 | } 11 | 12 | @genType 13 | type someMethods = { 14 | @meth 15 | "send": string => unit, 16 | @meth 17 | "on": (string, (. int) => unit) => unit, 18 | @meth 19 | "threeargs": (int, string, int) => string, 20 | "twoArgs": (. int, string) => int, 21 | } 22 | 23 | // let foo = (x: someMethods) => x["threeargs"](3, "a", 4) 24 | 25 | let bar = (x: someMethods) => { 26 | let f = x["twoArgs"] 27 | f(. 3, "a") 28 | } 29 | 30 | -------------------------------------------------------------------------------- /examples/deadcode/src/ComponentAsProp.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as React from "react"; 4 | import * as Caml_option from "rescript/lib/es6/caml_option.js"; 5 | 6 | function ComponentAsProp(Props) { 7 | var title = Props.title; 8 | var description = Props.description; 9 | var button = Props.button; 10 | return React.createElement("div", undefined, React.createElement("div", undefined, title, description, button !== undefined ? Caml_option.valFromOption(button) : null)); 11 | } 12 | 13 | var make = ComponentAsProp; 14 | 15 | export { 16 | make , 17 | } 18 | /* react Not a pure module */ 19 | -------------------------------------------------------------------------------- /examples/deadcode/src/ComponentAsProp.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from ComponentAsProp.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | import * as React from 'react'; 6 | 7 | // @ts-ignore: Implicit any on import 8 | import * as ComponentAsPropBS__Es6Import from './ComponentAsProp.bs'; 9 | const ComponentAsPropBS: any = ComponentAsPropBS__Es6Import; 10 | 11 | // tslint:disable-next-line:interface-over-type-literal 12 | export type Props = { 13 | readonly button?: JSX.Element; 14 | readonly description: JSX.Element; 15 | readonly title: JSX.Element 16 | }; 17 | 18 | /** This is like declaring a normal ReasonReact component's `make` function, except the body is a the interop hook wrapJsForReason */ 19 | export const make: React.ComponentType<{ 20 | readonly button?: JSX.Element; 21 | readonly description: JSX.Element; 22 | readonly title: JSX.Element 23 | }> = ComponentAsPropBS.make; 24 | -------------------------------------------------------------------------------- /examples/deadcode/src/ComponentAsProp.res: -------------------------------------------------------------------------------- 1 | @ocaml.doc( 2 | " This is like declaring a normal ReasonReact component's `make` function, except the body is a the interop hook wrapJsForReason " 3 | ) 4 | @genType 5 | @react.component 6 | let make = (~title, ~description, ~button=?) => { 7 |
8 |
9 | title 10 | description 11 | {switch button { 12 | | Some(button) => button 13 | | None => React.null 14 | }} 15 |
16 |
17 | } 18 | -------------------------------------------------------------------------------- /examples/deadcode/src/CreateErrorHandler1.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Curry from "rescript/lib/es6/curry.js"; 4 | import * as ErrorHandler from "./ErrorHandler.bs.js"; 5 | 6 | function notification(s) { 7 | return [ 8 | s, 9 | s 10 | ]; 11 | } 12 | 13 | var Error1 = { 14 | notification: notification 15 | }; 16 | 17 | var MyErrorHandler = ErrorHandler.Make(Error1); 18 | 19 | Curry._1(MyErrorHandler.notify, "abc"); 20 | 21 | export { 22 | Error1 , 23 | MyErrorHandler , 24 | } 25 | /* MyErrorHandler Not a pure module */ 26 | -------------------------------------------------------------------------------- /examples/deadcode/src/CreateErrorHandler1.res: -------------------------------------------------------------------------------- 1 | module Error1 = { 2 | type t = string 3 | let notification = s => (s, s) 4 | } 5 | 6 | module MyErrorHandler = ErrorHandler.Make(Error1) 7 | 8 | MyErrorHandler.notify("abc") 9 | 10 | -------------------------------------------------------------------------------- /examples/deadcode/src/CreateErrorHandler2.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as ErrorHandler from "./ErrorHandler.bs.js"; 4 | 5 | function notification(n) { 6 | return [ 7 | String(n), 8 | "" 9 | ]; 10 | } 11 | 12 | var Error2 = { 13 | notification: notification 14 | }; 15 | 16 | var MyErrorHandler = ErrorHandler.Make(Error2); 17 | 18 | export { 19 | Error2 , 20 | MyErrorHandler , 21 | } 22 | /* MyErrorHandler Not a pure module */ 23 | -------------------------------------------------------------------------------- /examples/deadcode/src/CreateErrorHandler2.res: -------------------------------------------------------------------------------- 1 | module Error2 = { 2 | type t = int 3 | let notification = n => (string_of_int(n), "") 4 | } 5 | 6 | module MyErrorHandler = ErrorHandler.Make(Error2) /* MyErrorHandler.notify(42) */ 7 | 8 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadCodeImplementation.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var M = { 5 | x: 42 6 | }; 7 | 8 | export { 9 | M , 10 | } 11 | /* No side effect */ 12 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadCodeImplementation.res: -------------------------------------------------------------------------------- 1 | module M: DeadCodeInterface.T = { 2 | let x = 42 3 | } 4 | 5 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadCodeInterface.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | /* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ 3 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadCodeInterface.res: -------------------------------------------------------------------------------- 1 | module type T = { 2 | let x: int 3 | } 4 | 5 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadExn.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js"; 4 | 5 | var Etoplevel = /* @__PURE__ */Caml_exceptions.create("DeadExn.Etoplevel"); 6 | 7 | var Einside = /* @__PURE__ */Caml_exceptions.create("DeadExn.Inside.Einside"); 8 | 9 | var eInside = { 10 | RE_EXN_ID: Einside 11 | }; 12 | 13 | console.log(eInside); 14 | 15 | export { 16 | Etoplevel , 17 | } 18 | /* Not a pure module */ 19 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadExn.res: -------------------------------------------------------------------------------- 1 | exception Etoplevel 2 | 3 | module Inside = { 4 | exception Einside 5 | } 6 | 7 | exception DeadE 8 | let eToplevel = Etoplevel 9 | 10 | let eInside = Inside.Einside 11 | 12 | Js.log(eInside) 13 | 14 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadExn.resi: -------------------------------------------------------------------------------- 1 | // empty 2 | exception Etoplevel 3 | 4 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadMl.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Curry from "rescript/lib/es6/curry.js"; 4 | import * as Pervasives from "rescript/lib/es6/pervasives.js"; 5 | import * as Caml_option from "rescript/lib/es6/caml_option.js"; 6 | 7 | function thisSpansSeveralLines(x, y) { 8 | return x + y | 0; 9 | } 10 | 11 | var QQ = { 12 | thisSpansSeveralLines: thisSpansSeveralLines 13 | }; 14 | 15 | function thisIsInInterface(x) { 16 | return x; 17 | } 18 | 19 | var AA = { 20 | thisIsInInterface: thisIsInInterface 21 | }; 22 | 23 | var Bs_version = { 24 | version: "7.2.0-dev.4", 25 | header: "// Generated by BUCKLESCRIPT, PLEASE EDIT WITH CARE", 26 | package_name: "bs-platform" 27 | }; 28 | 29 | function map_split_opt(xs, f) { 30 | if (!xs) { 31 | return [ 32 | /* [] */0, 33 | /* [] */0 34 | ]; 35 | } 36 | var match = Curry._1(f, xs.hd); 37 | var d = match[1]; 38 | var c = match[0]; 39 | var match$1 = map_split_opt(xs.tl, f); 40 | var ds = match$1[1]; 41 | var cs = match$1[0]; 42 | return [ 43 | c !== undefined ? ({ 44 | hd: Caml_option.valFromOption(c), 45 | tl: cs 46 | }) : cs, 47 | d !== undefined ? ({ 48 | hd: Caml_option.valFromOption(d), 49 | tl: ds 50 | }) : ds 51 | ]; 52 | } 53 | 54 | var inline_threshold = 10 / 8; 55 | 56 | var Inner1 = { 57 | deadInner1: 0, 58 | liveInner2: 0 59 | }; 60 | 61 | var Inner2 = { 62 | liveInner3: 0 63 | }; 64 | 65 | var Scope = { 66 | dead1: 1, 67 | Inner1: Inner1, 68 | dead2: 2, 69 | Inner2: Inner2, 70 | live3: 3 71 | }; 72 | 73 | var WithSignature = { 74 | dead8: 8, 75 | live9: 9, 76 | dead10: 10, 77 | live11: 11 78 | }; 79 | 80 | var foo = Pervasives.print_int; 81 | 82 | var bar = Pervasives.print_int; 83 | 84 | var thisHasSemicolons = 3; 85 | 86 | var dead4 = 4; 87 | 88 | var live5 = 5; 89 | 90 | var dead5 = 5; 91 | 92 | var live6 = 6; 93 | 94 | var dead7 = 7; 95 | 96 | export { 97 | QQ , 98 | AA , 99 | thisHasSemicolons , 100 | Bs_version , 101 | map_split_opt , 102 | inline_threshold , 103 | Scope , 104 | dead4 , 105 | live5 , 106 | dead5 , 107 | live6 , 108 | dead7 , 109 | WithSignature , 110 | foo , 111 | bar , 112 | } 113 | /* No side effect */ 114 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadRT.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | console.log(/* Kaboom */0); 5 | 6 | export { 7 | 8 | } 9 | /* Not a pure module */ 10 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadRT.res: -------------------------------------------------------------------------------- 1 | type moduleAccessPath = 2 | | Root(string) 3 | | Kaboom 4 | 5 | let rec emitModuleAccessPath = moduleAccessPath => 6 | switch moduleAccessPath { 7 | | Root(s) => s 8 | | Kaboom => "" 9 | } 10 | 11 | let () = Js.log(Kaboom) 12 | 13 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadRT.resi: -------------------------------------------------------------------------------- 1 | type moduleAccessPath = 2 | | Root(string) 3 | | Kaboom 4 | 5 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadTest.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from DeadTest.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as DeadTestBS__Es6Import from './DeadTest.bs'; 7 | const DeadTestBS: any = DeadTestBS__Es6Import; 8 | 9 | export const fortyTwoButExported: number = DeadTestBS.fortyTwoButExported; 10 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadTestBlacklist.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var x = 34; 5 | 6 | export { 7 | x , 8 | } 9 | /* No side effect */ 10 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadTestBlacklist.res: -------------------------------------------------------------------------------- 1 | let x = 34 2 | 3 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadTestWithInterface.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | /* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ 3 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadTestWithInterface.res: -------------------------------------------------------------------------------- 1 | module Ext_buffer: { 2 | let x: int 3 | } = { 4 | let x = 42 5 | } 6 | 7 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadTestWithInterface.resi: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadTypeTest.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var a = /* A */0; 5 | 6 | export { 7 | a , 8 | } 9 | /* No side effect */ 10 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadTypeTest.res: -------------------------------------------------------------------------------- 1 | type t = 2 | | A 3 | | B 4 | let a = A 5 | 6 | type deadType = 7 | | OnlyInImplementation 8 | | OnlyInInterface 9 | | InBoth 10 | | InNeither 11 | 12 | let _ = OnlyInImplementation 13 | let _ = InBoth 14 | 15 | @live 16 | type record = {x: int, y: string, z: float} 17 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadTypeTest.resi: -------------------------------------------------------------------------------- 1 | type t = 2 | | A 3 | | B 4 | let a: t 5 | 6 | type deadType = 7 | | OnlyInImplementation 8 | | OnlyInInterface 9 | | InBoth 10 | | InNeither 11 | 12 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadValueTest.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var valueAlive = 1; 5 | 6 | var valueDead = 2; 7 | 8 | export { 9 | valueAlive , 10 | valueDead , 11 | } 12 | /* No side effect */ 13 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadValueTest.res: -------------------------------------------------------------------------------- 1 | let valueAlive = 1 2 | let valueDead = 2 3 | 4 | let valueOnlyInImplementation = 3 5 | 6 | let rec subList = (b, e, l) => 7 | switch l { 8 | | list{} => failwith("subList") 9 | | list{h, ...t} => 10 | let tail = if e == 0 { 11 | list{} 12 | } else { 13 | subList(b - 1, e - 1, t) 14 | } 15 | if b > 0 { 16 | tail 17 | } else { 18 | list{h, ...tail} 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /examples/deadcode/src/DeadValueTest.resi: -------------------------------------------------------------------------------- 1 | let valueAlive: int 2 | let valueDead: int 3 | 4 | -------------------------------------------------------------------------------- /examples/deadcode/src/Docstrings.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function signMessage(message, key) { 5 | return message + String(key); 6 | } 7 | 8 | function one(a) { 9 | return a + 0 | 0; 10 | } 11 | 12 | function two(a, b) { 13 | return (a + b | 0) + 0 | 0; 14 | } 15 | 16 | function tree(a, b, c) { 17 | return ((a + b | 0) + c | 0) + 0 | 0; 18 | } 19 | 20 | function oneU(a) { 21 | return a + 0 | 0; 22 | } 23 | 24 | function twoU(a, b) { 25 | return (a + b | 0) + 0 | 0; 26 | } 27 | 28 | function treeU(a, b, c) { 29 | return ((a + b | 0) + c | 0) + 0 | 0; 30 | } 31 | 32 | function useParam(param) { 33 | return param + 34 | 0; 34 | } 35 | 36 | function useParamU(param) { 37 | return param + 34 | 0; 38 | } 39 | 40 | function unnamed1(param) { 41 | return 34; 42 | } 43 | 44 | function unnamed1U(param) { 45 | return 34; 46 | } 47 | 48 | function unnamed2(param, param$1) { 49 | return 34; 50 | } 51 | 52 | function unnamed2U(param, param$1) { 53 | return 34; 54 | } 55 | 56 | function grouped(x, y, a, b, c, z) { 57 | return ((((x + y | 0) + a | 0) + b | 0) + c | 0) + z | 0; 58 | } 59 | 60 | function unitArgWithoutConversion(param) { 61 | return "abc"; 62 | } 63 | 64 | function unitArgWithoutConversionU() { 65 | return "abc"; 66 | } 67 | 68 | function unitArgWithConversion(param) { 69 | return /* A */0; 70 | } 71 | 72 | function unitArgWithConversionU() { 73 | return /* A */0; 74 | } 75 | 76 | var flat = 34; 77 | 78 | export { 79 | flat , 80 | signMessage , 81 | one , 82 | two , 83 | tree , 84 | oneU , 85 | twoU , 86 | treeU , 87 | useParam , 88 | useParamU , 89 | unnamed1 , 90 | unnamed1U , 91 | unnamed2 , 92 | unnamed2U , 93 | grouped , 94 | unitArgWithoutConversion , 95 | unitArgWithoutConversionU , 96 | unitArgWithConversion , 97 | unitArgWithConversionU , 98 | } 99 | /* No side effect */ 100 | -------------------------------------------------------------------------------- /examples/deadcode/src/Docstrings.res: -------------------------------------------------------------------------------- 1 | @ocaml.doc(" hello ") @genType 2 | let flat = 34 3 | 4 | @ocaml.doc(" 5 | * Sign a message with a key. 6 | * 7 | * @param message - A message to be signed 8 | * @param key - The key with which to sign the message 9 | * @returns A signed message 10 | ") 11 | @genType 12 | let signMessage = (. message, key) => message ++ string_of_int(key) 13 | 14 | @genType 15 | let one = a => a + 0 16 | 17 | @genType 18 | let two = (a, b) => a + b + 0 19 | 20 | @genType 21 | let tree = (a, b, c) => a + b + c + 0 22 | 23 | @genType 24 | let oneU = (. a) => a + 0 25 | 26 | @genType 27 | let twoU = (. a, b) => a + b + 0 28 | 29 | @genType 30 | let treeU = (. a, b, c) => a + b + c + 0 31 | 32 | @genType 33 | let useParam = param => param + 34 34 | 35 | @genType 36 | let useParamU = (. param) => param + 34 37 | 38 | @genType 39 | let unnamed1 = (_: int) => 34 40 | 41 | @genType 42 | let unnamed1U = (. _: int) => 34 43 | 44 | @genType 45 | let unnamed2 = (_: int, _: int) => 34 46 | 47 | @genType 48 | let unnamed2U = (. _: int, _: int) => 34 49 | 50 | @genType 51 | let grouped = (~x, ~y, a, b, c, ~z) => x + y + a + b + c + z 52 | 53 | @genType 54 | let unitArgWithoutConversion = () => "abc" 55 | 56 | @genType 57 | let unitArgWithoutConversionU = (. ()) => "abc" 58 | 59 | type t = 60 | | A 61 | | B 62 | 63 | @genType 64 | let unitArgWithConversion = () => A 65 | 66 | @genType 67 | let unitArgWithConversionU = (. ()) => A 68 | 69 | -------------------------------------------------------------------------------- /examples/deadcode/src/DynamicallyLoadedComponent.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function DynamicallyLoadedComponent(Props) { 5 | return Props.s; 6 | } 7 | 8 | var make = DynamicallyLoadedComponent; 9 | 10 | export { 11 | make , 12 | } 13 | /* No side effect */ 14 | -------------------------------------------------------------------------------- /examples/deadcode/src/DynamicallyLoadedComponent.res: -------------------------------------------------------------------------------- 1 | @react.component 2 | let make = (~s) => React.string(s) 3 | 4 | -------------------------------------------------------------------------------- /examples/deadcode/src/EmptyArray.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as React from "react"; 4 | 5 | function EmptyArray$Z(Props) { 6 | return React.createElement("br", undefined); 7 | } 8 | 9 | var Z = { 10 | make: EmptyArray$Z 11 | }; 12 | 13 | React.createElement(EmptyArray$Z, {}); 14 | 15 | export { 16 | Z , 17 | } 18 | /* Not a pure module */ 19 | -------------------------------------------------------------------------------- /examples/deadcode/src/EmptyArray.res: -------------------------------------------------------------------------------- 1 | // @@config({flags : ["-dsource"]}); 2 | 3 | module Z = { 4 | @react.component 5 | let make = () => { 6 |
7 | } 8 | } 9 | 10 | let _ = 11 | -------------------------------------------------------------------------------- /examples/deadcode/src/ErrorHandler.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Curry from "rescript/lib/es6/curry.js"; 4 | 5 | function Make($$Error) { 6 | var notify = function (x) { 7 | return Curry._1($$Error.notification, x); 8 | }; 9 | return { 10 | notify: notify 11 | }; 12 | } 13 | 14 | var x = 42; 15 | 16 | export { 17 | Make , 18 | x , 19 | } 20 | /* No side effect */ 21 | -------------------------------------------------------------------------------- /examples/deadcode/src/ErrorHandler.res: -------------------------------------------------------------------------------- 1 | module type Error = { 2 | type t 3 | let notification: t => (string, string) 4 | } 5 | 6 | module Make = (Error: Error) => { 7 | let notify = x => Error.notification(x) 8 | } 9 | 10 | // This is ignored as there's an interface file 11 | @genType 12 | let x = 42 13 | 14 | -------------------------------------------------------------------------------- /examples/deadcode/src/ErrorHandler.resi: -------------------------------------------------------------------------------- 1 | module type Error = { 2 | type t 3 | let notification: t => (string, string) 4 | } 5 | module Make: (Error: Error) => 6 | { 7 | let notify: Error.t => (string, string) 8 | } 9 | 10 | let x: int 11 | 12 | -------------------------------------------------------------------------------- /examples/deadcode/src/EverythingLiveHere.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var x = 1; 5 | 6 | var y = 3; 7 | 8 | var z = 4; 9 | 10 | export { 11 | x , 12 | y , 13 | z , 14 | } 15 | /* No side effect */ 16 | -------------------------------------------------------------------------------- /examples/deadcode/src/EverythingLiveHere.res: -------------------------------------------------------------------------------- 1 | let x = 1 2 | 3 | let y = 3 4 | 5 | let z = 4 6 | 7 | -------------------------------------------------------------------------------- /examples/deadcode/src/FC.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function foo(impl) { 5 | return impl.make; 6 | } 7 | 8 | console.log(foo); 9 | 10 | export { 11 | foo , 12 | } 13 | /* Not a pure module */ 14 | -------------------------------------------------------------------------------- /examples/deadcode/src/FC.res: -------------------------------------------------------------------------------- 1 | module type ReplacebleComponent = { 2 | @react.component 3 | let make: unit => React.element 4 | } 5 | 6 | let foo = (~impl: module(ReplacebleComponent)) => { 7 | let module(X) = impl 8 | X.make 9 | } 10 | 11 | Js.log(foo) 12 | 13 | -------------------------------------------------------------------------------- /examples/deadcode/src/FirstClassModules.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var y = "abc"; 5 | 6 | var EmptyInnerModule = {}; 7 | 8 | var InnerModule2 = { 9 | k: 4242 10 | }; 11 | 12 | function k3(x) { 13 | return x + 1 | 0; 14 | } 15 | 16 | var InnerModule3 = { 17 | k3: k3 18 | }; 19 | 20 | var Z = { 21 | u: [ 22 | 0, 23 | 0 24 | ] 25 | }; 26 | 27 | var M = { 28 | y: y, 29 | EmptyInnerModule: EmptyInnerModule, 30 | InnerModule2: InnerModule2, 31 | InnerModule3: InnerModule3, 32 | Z: Z, 33 | x: 42 34 | }; 35 | 36 | var firstClassModule = { 37 | x: 42, 38 | EmptyInnerModule: EmptyInnerModule, 39 | InnerModule2: InnerModule2, 40 | InnerModule3: InnerModule3, 41 | Z: Z, 42 | y: y 43 | }; 44 | 45 | function testConvert(m) { 46 | return m; 47 | } 48 | 49 | function SomeFunctor(X) { 50 | return { 51 | ww: X.y 52 | }; 53 | } 54 | 55 | function someFunctorAsFunction(x) { 56 | return { 57 | ww: x.y 58 | }; 59 | } 60 | 61 | export { 62 | M , 63 | firstClassModule , 64 | testConvert , 65 | SomeFunctor , 66 | someFunctorAsFunction , 67 | } 68 | /* No side effect */ 69 | -------------------------------------------------------------------------------- /examples/deadcode/src/FirstClassModules.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from FirstClassModules.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as FirstClassModulesBS__Es6Import from './FirstClassModules.bs'; 7 | const FirstClassModulesBS: any = FirstClassModulesBS__Es6Import; 8 | 9 | // tslint:disable-next-line:interface-over-type-literal 10 | export type MT_t = number; 11 | 12 | // tslint:disable-next-line:interface-over-type-literal 13 | export type MT_InnerModule3_inner = number; 14 | 15 | // tslint:disable-next-line:interface-over-type-literal 16 | export type firstClassModule = { 17 | readonly x: number; 18 | readonly EmptyInnerModule: { 19 | }; 20 | readonly InnerModule2: { 21 | readonly k: MT_t 22 | }; 23 | readonly InnerModule3: { 24 | readonly k3: (_1:MT_InnerModule3_inner) => MT_InnerModule3_inner 25 | }; 26 | readonly Z: unknown; 27 | readonly y: string 28 | }; 29 | 30 | export const firstClassModule: firstClassModule = FirstClassModulesBS.firstClassModule; 31 | 32 | export const testConvert: (m:{ 33 | readonly x: number; 34 | readonly EmptyInnerModule: { 35 | }; 36 | readonly InnerModule2: { 37 | readonly k: MT_t 38 | }; 39 | readonly InnerModule3: { 40 | readonly k3: ((_1:MT_InnerModule3_inner) => MT_InnerModule3_inner) 41 | }; 42 | readonly Z: unknown; 43 | readonly y: string 44 | }) => { 45 | readonly x: number; 46 | readonly EmptyInnerModule: { 47 | }; 48 | readonly InnerModule2: { 49 | readonly k: MT_t 50 | }; 51 | readonly InnerModule3: { 52 | readonly k3: (_1:MT_InnerModule3_inner) => MT_InnerModule3_inner 53 | }; 54 | readonly Z: unknown; 55 | readonly y: string 56 | } = FirstClassModulesBS.testConvert; 57 | 58 | export const someFunctorAsFunction: (x:{ 59 | readonly x: number; 60 | readonly EmptyInnerModule: { 61 | }; 62 | readonly InnerModule2: { 63 | readonly k: MT_t 64 | }; 65 | readonly InnerModule3: { 66 | readonly k3: ((_1:MT_InnerModule3_inner) => MT_InnerModule3_inner) 67 | }; 68 | readonly Z: unknown; 69 | readonly y: string 70 | }) => { readonly ww: string } = FirstClassModulesBS.someFunctorAsFunction; 71 | -------------------------------------------------------------------------------- /examples/deadcode/src/FirstClassModules.res: -------------------------------------------------------------------------------- 1 | module type MT = { 2 | let x: int 3 | type t = int 4 | @module("foo") external f: int => int = "f" 5 | module type MT2 = { 6 | type tt = string 7 | } 8 | module EmptyInnerModule: {} 9 | module InnerModule2: { 10 | let k: t 11 | } 12 | module InnerModule3: { 13 | type inner = int 14 | let k3: inner => inner 15 | } 16 | module type TT = { 17 | let u: (int, int) 18 | } 19 | module Z: TT 20 | let y: string 21 | } 22 | module M = { 23 | let y = "abc" 24 | module type MT2 = { 25 | type tt = string 26 | } 27 | module EmptyInnerModule = {} 28 | module InnerModule2 = { 29 | let k = 4242 30 | } 31 | module InnerModule3 = { 32 | type inner = int 33 | let k3 = x => x + 1 34 | } 35 | 36 | module type TT = { 37 | let u: (int, int) 38 | } 39 | module Z = { 40 | let u = (0, 0) 41 | } 42 | type t = int 43 | @module("foo") external f: int => int = "f" 44 | let x = 42 45 | } 46 | 47 | @genType 48 | type firstClassModule = module(MT) 49 | 50 | @genType 51 | let firstClassModule: firstClassModule = module(M) 52 | 53 | @genType 54 | let testConvert = (m: module(MT)) => m 55 | 56 | module type ResT = { 57 | let ww: string 58 | } 59 | 60 | module SomeFunctor = (X: MT): ResT => { 61 | let ww = X.y 62 | } 63 | 64 | @genType 65 | let someFunctorAsFunction = (x: module(MT)): module(ResT) => module(SomeFunctor(unpack(x))) 66 | 67 | -------------------------------------------------------------------------------- /examples/deadcode/src/FirstClassModulesInterface.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var r = { 5 | x: 3, 6 | y: "hello" 7 | }; 8 | 9 | export { 10 | r , 11 | } 12 | /* No side effect */ 13 | -------------------------------------------------------------------------------- /examples/deadcode/src/FirstClassModulesInterface.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from FirstClassModulesInterface.resi by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // tslint:disable-next-line:interface-over-type-literal 6 | export type record = { readonly x: number; readonly y: string }; 7 | 8 | // tslint:disable-next-line:interface-over-type-literal 9 | export type firstClassModule = { readonly x: number }; 10 | -------------------------------------------------------------------------------- /examples/deadcode/src/FirstClassModulesInterface.res: -------------------------------------------------------------------------------- 1 | type record = { 2 | x: int, 3 | y: string, 4 | } 5 | 6 | let r = {x: 3, y: "hello"} 7 | 8 | module type MT = { 9 | let x: int 10 | } 11 | 12 | type firstClassModule = module(MT) 13 | 14 | -------------------------------------------------------------------------------- /examples/deadcode/src/FirstClassModulesInterface.resi: -------------------------------------------------------------------------------- 1 | @genType 2 | type record = { 3 | x: int, 4 | y: string, 5 | } 6 | 7 | let r: record 8 | 9 | @genType 10 | module type MT = { 11 | let x: int 12 | } 13 | 14 | @genType 15 | type firstClassModule = module(MT) 16 | 17 | -------------------------------------------------------------------------------- /examples/deadcode/src/IgnoreInterface.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | /* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ 3 | -------------------------------------------------------------------------------- /examples/deadcode/src/IgnoreInterface.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from IgnoreInterface.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // tslint:disable-next-line:interface-over-type-literal 6 | export type t = number; 7 | -------------------------------------------------------------------------------- /examples/deadcode/src/IgnoreInterface.res: -------------------------------------------------------------------------------- 1 | @gentype 2 | type t = int 3 | 4 | -------------------------------------------------------------------------------- /examples/deadcode/src/IgnoreInterface.resi: -------------------------------------------------------------------------------- 1 | // Use the annotations, and definitions, from the .re file 2 | @@genType.ignoreInterface 3 | 4 | @genType 5 | type t 6 | 7 | -------------------------------------------------------------------------------- /examples/deadcode/src/ImportHookDefault.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import ImportHookDefaultGen from "./ImportHookDefault.gen"; 4 | import * as ImportHookDefaultGen$1 from "./ImportHookDefault.gen"; 5 | 6 | var make = ImportHookDefaultGen$1.make; 7 | 8 | var make2 = ImportHookDefaultGen; 9 | 10 | export { 11 | make , 12 | make2 , 13 | } 14 | /* make Not a pure module */ 15 | -------------------------------------------------------------------------------- /examples/deadcode/src/ImportHookDefault.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from ImportHookDefault.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | import {default as makeNotChecked} from './hookExample'; 6 | 7 | import {default as defaultNotChecked} from './hookExample'; 8 | 9 | // In case of type error, check the type of 'make' in 'ImportHookDefault.re' and './hookExample'. 10 | export const makeTypeChecked: React.ComponentType<{ 11 | readonly person: person; 12 | readonly children: React.ReactNode; 13 | readonly renderMe: ImportHooks_renderMe 14 | }> = makeNotChecked; 15 | 16 | // Export 'make' early to allow circular import from the '.bs.js' file. 17 | export const make: unknown = makeTypeChecked as React.ComponentType<{ 18 | readonly person: person; 19 | readonly children: React.ReactNode; 20 | readonly renderMe: ImportHooks_renderMe 21 | }>; 22 | 23 | // In case of type error, check the type of 'default' in 'ImportHookDefault.re' and './hookExample'. 24 | export const defaultTypeChecked: React.ComponentType<{ 25 | readonly person: person; 26 | readonly children: React.ReactNode; 27 | readonly renderMe: ImportHooks_renderMe 28 | }> = defaultNotChecked; 29 | 30 | // Export '$$default' early to allow circular import from the '.bs.js' file. 31 | export const $$default: unknown = defaultTypeChecked as React.ComponentType<{ 32 | readonly person: person; 33 | readonly children: React.ReactNode; 34 | readonly renderMe: ImportHooks_renderMe 35 | }>; 36 | 37 | import type {renderMe as ImportHooks_renderMe} from './ImportHooks.gen'; 38 | 39 | // tslint:disable-next-line:interface-over-type-literal 40 | export type person = { readonly name: string; readonly age: number }; 41 | 42 | export default $$default; 43 | -------------------------------------------------------------------------------- /examples/deadcode/src/ImportHookDefault.res: -------------------------------------------------------------------------------- 1 | type person = { 2 | name: string, 3 | age: int, 4 | } 5 | 6 | @genType.import(("./hookExample", "default")) @react.component 7 | external make: ( 8 | ~person: person, 9 | ~children: React.element, 10 | ~renderMe: ImportHooks.renderMe, 11 | ) => React.element = "make" 12 | 13 | @genType.import("./hookExample") @react.component 14 | external make2: ( 15 | ~person: person, 16 | ~children: React.element, 17 | ~renderMe: ImportHooks.renderMe, 18 | ) => React.element = "default" 19 | 20 | -------------------------------------------------------------------------------- /examples/deadcode/src/ImportHooks.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as ImportHooksGen from "./ImportHooks.gen"; 4 | 5 | var make = ImportHooksGen.makeRenamed; 6 | 7 | function foo(prim) { 8 | return ImportHooksGen.foo(prim); 9 | } 10 | 11 | export { 12 | make , 13 | foo , 14 | } 15 | /* make Not a pure module */ 16 | -------------------------------------------------------------------------------- /examples/deadcode/src/ImportHooks.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from ImportHooks.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | import {makeRenamed as makeRenamedNotChecked} from './hookExample'; 6 | 7 | import {foo as fooNotChecked} from './hookExample'; 8 | 9 | // In case of type error, check the type of 'makeRenamed' in 'ImportHooks.re' and './hookExample'. 10 | export const makeRenamedTypeChecked: React.ComponentType<{ 11 | readonly person: person; 12 | readonly children: React.ReactNode; 13 | readonly renderMe: renderMe 14 | }> = makeRenamedNotChecked; 15 | 16 | // Export 'makeRenamed' early to allow circular import from the '.bs.js' file. 17 | export const makeRenamed: unknown = makeRenamedTypeChecked as React.ComponentType<{ 18 | readonly person: person; 19 | readonly children: React.ReactNode; 20 | readonly renderMe: renderMe 21 | }>; 22 | 23 | // In case of type error, check the type of 'foo' in 'ImportHooks.re' and './hookExample'. 24 | export const fooTypeChecked: (_1:{ readonly person: person }) => string = fooNotChecked; 25 | 26 | // Export 'foo' early to allow circular import from the '.bs.js' file. 27 | export const foo: unknown = function (Argperson: any) { 28 | const result = fooTypeChecked({person:Argperson}); 29 | return result 30 | } as (_1:{ readonly person: person }) => string; 31 | 32 | // tslint:disable-next-line:interface-over-type-literal 33 | export type person = { readonly name: string; readonly age: number }; 34 | 35 | // tslint:disable-next-line:interface-over-type-literal 36 | export type renderMe = React.ComponentType<{ readonly randomString: string; readonly poly: a }>; 37 | -------------------------------------------------------------------------------- /examples/deadcode/src/ImportHooks.res: -------------------------------------------------------------------------------- 1 | @genType 2 | type person = { 3 | name: string, 4 | age: int, 5 | } 6 | 7 | @genType 8 | type renderMe<'a> = React.component<{ 9 | "randomString": string, 10 | "poly": 'a, 11 | }> 12 | 13 | @genType.import("./hookExample") @react.component 14 | external make: ( 15 | ~person: person, 16 | ~children: React.element, 17 | ~renderMe: renderMe<'a>, 18 | ) => React.element = "makeRenamed" 19 | 20 | @genType.import("./hookExample") 21 | external foo: (~person: person) => string = "foo" 22 | 23 | -------------------------------------------------------------------------------- /examples/deadcode/src/ImportIndex.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import ImportIndexGen from "./ImportIndex.gen"; 4 | 5 | var make = ImportIndexGen; 6 | 7 | export { 8 | make , 9 | } 10 | /* make Not a pure module */ 11 | -------------------------------------------------------------------------------- /examples/deadcode/src/ImportIndex.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from ImportIndex.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | import {default as defaultNotChecked} from './'; 6 | 7 | // In case of type error, check the type of 'default' in 'ImportIndex.re' and './'. 8 | export const defaultTypeChecked: React.ComponentType<{ readonly method?: "push" | "replace" }> = defaultNotChecked; 9 | 10 | // Export '$$default' early to allow circular import from the '.bs.js' file. 11 | export const $$default: unknown = defaultTypeChecked as React.ComponentType<{ readonly method?: "push" | "replace" }>; 12 | 13 | export default $$default; 14 | -------------------------------------------------------------------------------- /examples/deadcode/src/ImportIndex.res: -------------------------------------------------------------------------------- 1 | // TODO: rename metodd back once remmt bug is fixed 2 | @genType.import("./") @react.component 3 | external make: (~method: @string [#push | #replace]=?) => React.element = "default" 4 | 5 | -------------------------------------------------------------------------------- /examples/deadcode/src/ImportJsValue.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import ImportJsValueGen from "./ImportJsValue.gen"; 4 | import * as ImportJsValueGen$1 from "./ImportJsValue.gen"; 5 | 6 | function round(prim) { 7 | return ImportJsValueGen$1.round(prim); 8 | } 9 | 10 | function area(prim) { 11 | return ImportJsValueGen$1.area(prim); 12 | } 13 | 14 | function returnMixedArray(prim) { 15 | return ImportJsValueGen$1.returnMixedArray(); 16 | } 17 | 18 | var roundedNumber = ImportJsValueGen$1.round(1.8); 19 | 20 | var areaValue = ImportJsValueGen$1.area({ 21 | x: 3, 22 | y: undefined 23 | }); 24 | 25 | function getAbs(x) { 26 | return x.getAbs(); 27 | } 28 | 29 | var AbsoluteValue = { 30 | getAbs: getAbs 31 | }; 32 | 33 | function useGetProp(x) { 34 | return x.getProp() + 1 | 0; 35 | } 36 | 37 | function useGetAbs(x) { 38 | return x.getAbs() + 1 | 0; 39 | } 40 | 41 | function useColor(prim) { 42 | return ImportJsValueGen$1.useColor(prim); 43 | } 44 | 45 | function higherOrder(prim) { 46 | return ImportJsValueGen$1.higherOrder(prim); 47 | } 48 | 49 | var returnedFromHigherOrder = ImportJsValueGen$1.higherOrder(function (prim0, prim1) { 50 | return prim0 + prim1 | 0; 51 | }); 52 | 53 | function convertVariant(prim) { 54 | return ImportJsValueGen$1.convertVariant(prim); 55 | } 56 | 57 | function polymorphic(prim) { 58 | return ImportJsValueGen$1.polymorphic(prim); 59 | } 60 | 61 | var $$default = ImportJsValueGen; 62 | 63 | export { 64 | round , 65 | area , 66 | returnMixedArray , 67 | roundedNumber , 68 | areaValue , 69 | AbsoluteValue , 70 | useGetProp , 71 | useGetAbs , 72 | useColor , 73 | higherOrder , 74 | returnedFromHigherOrder , 75 | convertVariant , 76 | polymorphic , 77 | $$default , 78 | $$default as default, 79 | } 80 | /* roundedNumber Not a pure module */ 81 | -------------------------------------------------------------------------------- /examples/deadcode/src/ImportJsValue.res: -------------------------------------------------------------------------------- 1 | @ocaml.doc(" 2 | * Wrap JS values to be used from Reason 3 | ") 4 | @genType.import("./MyMath") 5 | external /* This is the module to import from. */ 6 | /* Name and type of the JS value to bind to. */ 7 | round: float => float = "round" 8 | 9 | @genType 10 | type point = { 11 | x: int, 12 | y: option, 13 | } 14 | 15 | @genType.import("./MyMath") 16 | external /* This is the module to import from. */ 17 | /* Name and type of the JS value to bind to. */ 18 | area: point => int = "area" 19 | 20 | @genType.import("./MyMath") 21 | type numberOrString 22 | 23 | @genType.import("./MyMath") 24 | external returnMixedArray: unit => array = "returnMixedArray" 25 | 26 | @genType 27 | let roundedNumber = round(1.8) 28 | 29 | @genType 30 | let areaValue = area({x: 3, y: None}) 31 | 32 | module AbsoluteValue = { 33 | @genType.import(("./MyMath", "AbsoluteValue")) 34 | type t = {"getAbs": (. unit) => int} 35 | 36 | /* This is untyped */ 37 | @send external getProp: t => int = "getProp" 38 | 39 | /* This is also untyped, as we "trust" the type declaration in absoluteVaue */ 40 | let getAbs = (x: t) => { 41 | let getAbs = x["getAbs"] 42 | getAbs(.) 43 | } 44 | } 45 | 46 | @genType 47 | let useGetProp = (x: AbsoluteValue.t) => x->AbsoluteValue.getProp + 1 48 | 49 | @genType 50 | let useGetAbs = (x: AbsoluteValue.t) => x->AbsoluteValue.getAbs + 1 51 | 52 | @genType.import("./MyMath") 53 | type stringFunction 54 | 55 | @genType 56 | type color = [#tomato | #gray] 57 | 58 | @genType.import("./MyMath") external useColor: color => int = "useColor" 59 | 60 | @genType.import("./MyMath") 61 | external higherOrder: ((int, int) => int) => int = "higherOrder" 62 | 63 | @genType 64 | let returnedFromHigherOrder = higherOrder(\"+") 65 | 66 | type variant = 67 | | I(int) 68 | | S(string) 69 | 70 | @genType.import("./MyMath") 71 | external convertVariant: variant => variant = "convertVariant" 72 | 73 | @genType.import("./MyMath") external polymorphic: 'a => 'a = "polymorphic" 74 | 75 | @genType.import("./MyMath") external default: int = "default" 76 | 77 | @genType.import(("./MyMath", "num")) 78 | type num 79 | 80 | @genType.import(("./MyMath", "num")) 81 | type myNum 82 | 83 | @genType.import("./MyMath") 84 | type polyType<'a> 85 | 86 | -------------------------------------------------------------------------------- /examples/deadcode/src/ImportMyBanner.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Caml_option from "rescript/lib/es6/caml_option.js"; 4 | import * as ImportMyBannerGen from "./ImportMyBanner.gen"; 5 | 6 | function make(prim0, prim1, prim2) { 7 | return ImportMyBannerGen.make(prim0, prim1 !== undefined ? Caml_option.valFromOption(prim1) : undefined, prim2); 8 | } 9 | 10 | export { 11 | make , 12 | } 13 | /* ./ImportMyBanner.gen Not a pure module */ 14 | -------------------------------------------------------------------------------- /examples/deadcode/src/ImportMyBanner.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from ImportMyBanner.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | import {make as makeNotChecked} from './MyBanner'; 6 | 7 | // In case of type error, check the type of 'make' in 'ImportMyBanner.re' and './MyBanner'. 8 | export const makeTypeChecked: (_1:{ readonly show: boolean; readonly message?: message }, _2:a) => JSX.Element = makeNotChecked; 9 | 10 | // Export 'make' early to allow circular import from the '.bs.js' file. 11 | export const make: unknown = function (Argshow: any, Argmessage: any, Arg2: any) { 12 | const result = makeTypeChecked({show:Argshow, message:Argmessage}, Arg2); 13 | return result 14 | } as (_1:{ readonly show: boolean; readonly message?: message }, _2:a) => JSX.Element; 15 | 16 | // tslint:disable-next-line:interface-over-type-literal 17 | export type message = { readonly text: string }; 18 | -------------------------------------------------------------------------------- /examples/deadcode/src/ImportMyBanner.res: -------------------------------------------------------------------------------- 1 | @ocaml.doc(" 2 | * Wrap component MyBanner to be used from Reason. 3 | ") 4 | @genType 5 | type message = {text: string} 6 | 7 | @genType.import("./MyBanner") 8 | external /* Module with the JS component to be wrapped. */ 9 | /* The make function will be automatically generated from the types below. */ 10 | make: (~show: bool, ~message: option=?, 'a) => React.element = "make" 11 | 12 | let make = make 13 | -------------------------------------------------------------------------------- /examples/deadcode/src/JSResource.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | /* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ 3 | -------------------------------------------------------------------------------- /examples/deadcode/src/JSResource.res: -------------------------------------------------------------------------------- 1 | type t<'a> 2 | 3 | @module external jSResource: string => t<'a> = "JSResource" 4 | 5 | -------------------------------------------------------------------------------- /examples/deadcode/src/LetPrivate.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var y = 34; 5 | 6 | export { 7 | y , 8 | } 9 | /* No side effect */ 10 | -------------------------------------------------------------------------------- /examples/deadcode/src/LetPrivate.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from LetPrivate.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as LetPrivateBS__Es6Import from './LetPrivate.bs'; 7 | const LetPrivateBS: any = LetPrivateBS__Es6Import; 8 | 9 | export const y: number = LetPrivateBS.y; 10 | -------------------------------------------------------------------------------- /examples/deadcode/src/LetPrivate.res: -------------------------------------------------------------------------------- 1 | %%private( 2 | @genType 3 | let x = 34 4 | ) 5 | 6 | @genType 7 | let y = x 8 | 9 | -------------------------------------------------------------------------------- /examples/deadcode/src/ModuleAliases.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var Inner = {}; 5 | 6 | var Outer = { 7 | Inner: Inner 8 | }; 9 | 10 | var InnerNested = {}; 11 | 12 | var Inner2 = { 13 | InnerNested: InnerNested, 14 | OuterInnerAlias2: undefined 15 | }; 16 | 17 | var Outer2 = { 18 | OuterInnerAlias: undefined, 19 | Inner2: Inner2 20 | }; 21 | 22 | function testNested(x) { 23 | return x; 24 | } 25 | 26 | function testInner(x) { 27 | return x; 28 | } 29 | 30 | function testInner2(x) { 31 | return x; 32 | } 33 | 34 | var Outer2Alias; 35 | 36 | var InnerNestedAlias; 37 | 38 | export { 39 | Outer , 40 | Outer2 , 41 | Outer2Alias , 42 | InnerNestedAlias , 43 | testNested , 44 | testInner , 45 | testInner2 , 46 | } 47 | /* No side effect */ 48 | -------------------------------------------------------------------------------- /examples/deadcode/src/ModuleAliases.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from ModuleAliases.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as ModuleAliasesBS__Es6Import from './ModuleAliases.bs'; 7 | const ModuleAliasesBS: any = ModuleAliasesBS__Es6Import; 8 | 9 | // tslint:disable-next-line:interface-over-type-literal 10 | export type Outer_Inner_innerT = { readonly inner: string }; 11 | 12 | // tslint:disable-next-line:interface-over-type-literal 13 | export type Outer2_Inner2_InnerNested_t = { readonly nested: number }; 14 | 15 | // tslint:disable-next-line:interface-over-type-literal 16 | export type Outer2_OuterInnerAlias_innerT = Outer_Inner_innerT; 17 | 18 | // tslint:disable-next-line:interface-over-type-literal 19 | export type Outer2_Inner2_OuterInnerAlias2_innerT = Outer2_OuterInnerAlias_innerT; 20 | 21 | // tslint:disable-next-line:interface-over-type-literal 22 | export type Outer2Alias_OuterInnerAlias_innerT = Outer2_OuterInnerAlias_innerT; 23 | 24 | // tslint:disable-next-line:interface-over-type-literal 25 | export type Outer2Alias_Inner2_OuterInnerAlias2_innerT = Outer2_Inner2_OuterInnerAlias2_innerT; 26 | 27 | // tslint:disable-next-line:interface-over-type-literal 28 | export type InnerNestedAlias_t = Outer2_Inner2_InnerNested_t; 29 | 30 | export const testNested: (x:InnerNestedAlias_t) => InnerNestedAlias_t = ModuleAliasesBS.testNested; 31 | 32 | export const testInner: (x:Outer2Alias_OuterInnerAlias_innerT) => Outer2Alias_OuterInnerAlias_innerT = ModuleAliasesBS.testInner; 33 | 34 | export const testInner2: (x:Outer2Alias_Inner2_OuterInnerAlias2_innerT) => Outer2Alias_Inner2_OuterInnerAlias2_innerT = ModuleAliasesBS.testInner2; 35 | -------------------------------------------------------------------------------- /examples/deadcode/src/ModuleAliases.res: -------------------------------------------------------------------------------- 1 | module Outer = { 2 | module Inner = { 3 | type innerT = {inner: string} 4 | } 5 | } 6 | 7 | module Outer2 = { 8 | module OuterInnerAlias = Outer.Inner 9 | module Inner2 = { 10 | module InnerNested = { 11 | type t = {nested: int} 12 | } 13 | module OuterInnerAlias2 = OuterInnerAlias 14 | } 15 | } 16 | 17 | module Outer2Alias = Outer2 18 | 19 | module InnerNestedAlias = Outer2.Inner2.InnerNested 20 | 21 | @genType 22 | let testNested = (x: InnerNestedAlias.t) => x 23 | 24 | @genType 25 | let testInner = (x: Outer2Alias.OuterInnerAlias.innerT) => x 26 | 27 | @genType 28 | let testInner2 = (x: Outer2Alias.Inner2.OuterInnerAlias2.innerT) => x 29 | 30 | -------------------------------------------------------------------------------- /examples/deadcode/src/ModuleAliases2.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var Inner = {}; 5 | 6 | var Outer = { 7 | Inner: Inner 8 | }; 9 | 10 | var OuterAlias; 11 | 12 | var InnerAlias; 13 | 14 | var q = 42; 15 | 16 | export { 17 | Outer , 18 | OuterAlias , 19 | InnerAlias , 20 | q , 21 | } 22 | /* No side effect */ 23 | -------------------------------------------------------------------------------- /examples/deadcode/src/ModuleAliases2.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from ModuleAliases2.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // tslint:disable-next-line:interface-over-type-literal 6 | export type record = { readonly x: number; readonly y: string }; 7 | 8 | // tslint:disable-next-line:interface-over-type-literal 9 | export type Outer_outer = { readonly outer: string }; 10 | 11 | // tslint:disable-next-line:interface-over-type-literal 12 | export type Outer_Inner_inner = { readonly inner: string }; 13 | 14 | // tslint:disable-next-line:interface-over-type-literal 15 | export type OuterAlias_outer = Outer_outer; 16 | 17 | // tslint:disable-next-line:interface-over-type-literal 18 | export type OuterAlias_Inner_inner = Outer_Inner_inner; 19 | 20 | // tslint:disable-next-line:interface-over-type-literal 21 | export type InnerAlias_inner = OuterAlias_Inner_inner; 22 | -------------------------------------------------------------------------------- /examples/deadcode/src/ModuleAliases2.res: -------------------------------------------------------------------------------- 1 | @genType 2 | type record = { 3 | x: int, 4 | y: string, 5 | } 6 | 7 | module Outer = { 8 | @genType 9 | type outer = {outer: string} 10 | 11 | module Inner = { 12 | @genType 13 | type inner = {inner: string} 14 | } 15 | } 16 | 17 | module OuterAlias = Outer 18 | 19 | module InnerAlias = OuterAlias.Inner 20 | 21 | let q = 42 22 | 23 | -------------------------------------------------------------------------------- /examples/deadcode/src/ModuleExceptionBug.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js"; 4 | 5 | function customDouble(foo) { 6 | return (foo << 1); 7 | } 8 | 9 | var Dep = { 10 | customDouble: customDouble 11 | }; 12 | 13 | var MyOtherException = /* @__PURE__ */Caml_exceptions.create("ModuleExceptionBug.MyOtherException"); 14 | 15 | console.log(34); 16 | 17 | var ddjdj = 34; 18 | 19 | export { 20 | Dep , 21 | MyOtherException , 22 | ddjdj , 23 | } 24 | /* Not a pure module */ 25 | -------------------------------------------------------------------------------- /examples/deadcode/src/ModuleExceptionBug.res: -------------------------------------------------------------------------------- 1 | module Dep = { 2 | let customDouble = foo => foo * 2 3 | } 4 | 5 | exception MyOtherException 6 | 7 | let ddjdj = 34 8 | Js.log(ddjdj) 9 | -------------------------------------------------------------------------------- /examples/deadcode/src/NestedModules.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function nested3Function(x) { 5 | return x; 6 | } 7 | 8 | var Nested3 = { 9 | x: 0, 10 | y: 1, 11 | z: 2, 12 | w: 3, 13 | nested3Value: "nested3Value", 14 | nested3Function: nested3Function 15 | }; 16 | 17 | function nested2Function(x) { 18 | return x; 19 | } 20 | 21 | var Nested2 = { 22 | x: 0, 23 | nested2Value: 1, 24 | y: 2, 25 | Nested3: Nested3, 26 | nested2Function: nested2Function 27 | }; 28 | 29 | var Universe = { 30 | theAnswer: 42, 31 | notExported: 33, 32 | Nested2: Nested2, 33 | someString: "some exported string" 34 | }; 35 | 36 | var notNested = 1; 37 | 38 | export { 39 | notNested , 40 | Universe , 41 | } 42 | /* No side effect */ 43 | -------------------------------------------------------------------------------- /examples/deadcode/src/NestedModules.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from NestedModules.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as NestedModulesBS__Es6Import from './NestedModules.bs'; 7 | const NestedModulesBS: any = NestedModulesBS__Es6Import; 8 | 9 | // tslint:disable-next-line:interface-over-type-literal 10 | export type Universe_nestedType = string[]; 11 | 12 | // tslint:disable-next-line:interface-over-type-literal 13 | export type Universe_Nested2_nested2Type = Array; 14 | 15 | // tslint:disable-next-line:interface-over-type-literal 16 | export type Universe_Nested2_Nested3_nested3Type = Array>; 17 | 18 | // tslint:disable-next-line:interface-over-type-literal 19 | export type Universe_variant = "A" | { tag: "B"; value: string }; 20 | 21 | export const notNested: number = NestedModulesBS.notNested; 22 | 23 | export const Universe_theAnswer: number = NestedModulesBS.Universe.theAnswer; 24 | 25 | export const Universe_Nested2_nested2Value: number = NestedModulesBS.Universe.Nested2.nested2Value; 26 | 27 | export const Universe_Nested2_Nested3_nested3Value: string = NestedModulesBS.Universe.Nested2.Nested3.nested3Value; 28 | 29 | export const Universe_Nested2_Nested3_nested3Function: (x:Universe_Nested2_nested2Type) => Universe_Nested2_nested2Type = NestedModulesBS.Universe.Nested2.Nested3.nested3Function; 30 | 31 | export const Universe_Nested2_nested2Function: (x:Universe_Nested2_Nested3_nested3Type) => Universe_Nested2_Nested3_nested3Type = NestedModulesBS.Universe.Nested2.nested2Function; 32 | 33 | export const Universe_someString: string = NestedModulesBS.Universe.someString; 34 | 35 | export const Universe: { 36 | theAnswer: number; 37 | Nested2: { 38 | nested2Function: (x:Universe_Nested2_Nested3_nested3Type) => Universe_Nested2_Nested3_nested3Type; 39 | nested2Value: number; 40 | Nested3: { 41 | nested3Value: string; 42 | nested3Function: (x:Universe_Nested2_nested2Type) => Universe_Nested2_nested2Type 43 | } 44 | }; 45 | someString: string 46 | } = NestedModulesBS.Universe 47 | -------------------------------------------------------------------------------- /examples/deadcode/src/NestedModules.res: -------------------------------------------------------------------------------- 1 | @genType 2 | let notNested = 1 3 | 4 | module Universe = { 5 | @genType 6 | let theAnswer = 42 7 | 8 | let notExported = 33 9 | 10 | @genType 11 | type nestedType = array 12 | 13 | module Nested2 = { 14 | let x = 0 15 | 16 | @genType 17 | let nested2Value = 1 18 | 19 | let y = 2 20 | 21 | @genType 22 | type nested2Type = array> 23 | 24 | module Nested3 = { 25 | let x = 0 26 | let y = 1 27 | let z = 2 28 | let w = 3 29 | 30 | @genType 31 | type nested3Type = array>> 32 | 33 | @genType 34 | let nested3Value = "nested3Value" 35 | 36 | @genType 37 | let nested3Function = (x: nested2Type) => x 38 | } 39 | 40 | @genType 41 | let nested2Function = (x: Nested3.nested3Type) => x 42 | } 43 | 44 | @genType 45 | type variant = 46 | | A 47 | | B(string) 48 | 49 | @genType 50 | let someString = "some exported string" 51 | } 52 | 53 | -------------------------------------------------------------------------------- /examples/deadcode/src/NestedModulesInSignature.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var Universe = { 5 | theAnswer: 42 6 | }; 7 | 8 | export { 9 | Universe , 10 | } 11 | /* No side effect */ 12 | -------------------------------------------------------------------------------- /examples/deadcode/src/NestedModulesInSignature.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from NestedModulesInSignature.resi by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as NestedModulesInSignatureBS__Es6Import from './NestedModulesInSignature.bs'; 7 | const NestedModulesInSignatureBS: any = NestedModulesInSignatureBS__Es6Import; 8 | 9 | export const Universe_theAnswer: number = NestedModulesInSignatureBS.Universe.theAnswer; 10 | 11 | export const Universe: { theAnswer: number } = NestedModulesInSignatureBS.Universe 12 | -------------------------------------------------------------------------------- /examples/deadcode/src/NestedModulesInSignature.res: -------------------------------------------------------------------------------- 1 | module Universe = { 2 | let theAnswer = 42 3 | } 4 | 5 | -------------------------------------------------------------------------------- /examples/deadcode/src/NestedModulesInSignature.resi: -------------------------------------------------------------------------------- 1 | module Universe: { 2 | @genType 3 | let theAnswer: int 4 | } 5 | 6 | -------------------------------------------------------------------------------- /examples/deadcode/src/Newsyntax.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var x = 34; 5 | 6 | var y = 11; 7 | 8 | export { 9 | x , 10 | y , 11 | } 12 | /* No side effect */ 13 | -------------------------------------------------------------------------------- /examples/deadcode/src/Newsyntax.res: -------------------------------------------------------------------------------- 1 | let x = 34 2 | 3 | let y = 11 4 | 5 | type record = { 6 | xxx: int, 7 | yyy: int, 8 | } 9 | 10 | type variant = A | B(int)|C 11 | 12 | type record2 = {xx:int,yy:int} 13 | -------------------------------------------------------------------------------- /examples/deadcode/src/Newton.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Curry from "rescript/lib/es6/curry.js"; 4 | 5 | function $neg(prim0, prim1) { 6 | return prim0 - prim1; 7 | } 8 | 9 | function $plus(prim0, prim1) { 10 | return prim0 + prim1; 11 | } 12 | 13 | function $star(prim0, prim1) { 14 | return prim0 * prim1; 15 | } 16 | 17 | function $slash(prim0, prim1) { 18 | return prim0 / prim1; 19 | } 20 | 21 | function newton(f, fPrimed, initial, threshold) { 22 | var current = { 23 | contents: initial 24 | }; 25 | var iterateMore = function (previous, next) { 26 | var delta = next >= previous ? next - previous : previous - next; 27 | current.contents = next; 28 | return delta >= threshold; 29 | }; 30 | var _param; 31 | while(true) { 32 | var previous = current.contents; 33 | var next = previous - Curry._1(f, previous) / Curry._1(fPrimed, previous); 34 | if (!iterateMore(previous, next)) { 35 | return current.contents; 36 | } 37 | _param = undefined; 38 | continue ; 39 | }; 40 | } 41 | 42 | function f(x) { 43 | return x * x * x - 2.0 * x * x - 11.0 * x + 12.0; 44 | } 45 | 46 | function fPrimed(x) { 47 | return 3.0 * x * x - 4.0 * x - 11.0; 48 | } 49 | 50 | var result = newton(f, fPrimed, 5.0, 0.0003); 51 | 52 | console.log(result, f(result)); 53 | 54 | export { 55 | $neg , 56 | $plus , 57 | $star , 58 | $slash , 59 | newton , 60 | f , 61 | fPrimed , 62 | result , 63 | } 64 | /* result Not a pure module */ 65 | -------------------------------------------------------------------------------- /examples/deadcode/src/Newton.res: -------------------------------------------------------------------------------- 1 | let \"-" = \"-." 2 | let \"+" = \"+." 3 | let \"*" = \"*." 4 | let \"/" = \"/." 5 | 6 | let newton = (~f, ~fPrimed, ~initial, ~threshold) => { 7 | let current = ref(initial) 8 | let iterateMore = (previous, next) => { 9 | let delta = next >= previous ? next - previous : previous - next 10 | current := next 11 | !(delta < threshold) 12 | } 13 | @progress(iterateMore) 14 | let rec loop = () => { 15 | let previous = current.contents 16 | let next = previous - f(previous) / fPrimed(previous) 17 | if iterateMore(previous, next) { 18 | loop() 19 | } else { 20 | current.contents 21 | } 22 | } 23 | loop() 24 | } 25 | let f = x => x * x * x - 2.0 * x * x - 11.0 * x + 12.0 26 | 27 | let fPrimed = x => 3.0 * x * x - 4.0 * x - 11.0 28 | 29 | let result = newton(~f, ~fPrimed, ~initial=5.0, ~threshold=0.0003) 30 | 31 | Js.log2(result, f(result)) 32 | 33 | -------------------------------------------------------------------------------- /examples/deadcode/src/Opaque.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function noConversion(x) { 5 | return x; 6 | } 7 | 8 | function testConvertNestedRecordFromOtherFile(x) { 9 | return x; 10 | } 11 | 12 | export { 13 | noConversion , 14 | testConvertNestedRecordFromOtherFile , 15 | } 16 | /* No side effect */ 17 | -------------------------------------------------------------------------------- /examples/deadcode/src/Opaque.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from Opaque.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as OpaqueBS__Es6Import from './Opaque.bs'; 7 | const OpaqueBS: any = OpaqueBS__Es6Import; 8 | 9 | import type {business as Records_business} from './Records.gen'; 10 | 11 | // tslint:disable-next-line:max-classes-per-file 12 | // tslint:disable-next-line:class-name 13 | export abstract class opaqueFromRecords { protected opaque!: any }; /* simulate opaque types */ 14 | 15 | // tslint:disable-next-line:interface-over-type-literal 16 | export type pair = [opaqueFromRecords, opaqueFromRecords]; 17 | 18 | export const noConversion: (x:opaqueFromRecords) => opaqueFromRecords = OpaqueBS.noConversion; 19 | 20 | export const testConvertNestedRecordFromOtherFile: (x:Records_business) => Records_business = OpaqueBS.testConvertNestedRecordFromOtherFile; 21 | -------------------------------------------------------------------------------- /examples/deadcode/src/Opaque.res: -------------------------------------------------------------------------------- 1 | @genType.opaque 2 | type opaqueFromRecords = A(Records.coord) 3 | 4 | @genType 5 | let noConversion = (x: opaqueFromRecords) => x 6 | 7 | @genType 8 | type pair = (opaqueFromRecords, opaqueFromRecords) 9 | 10 | @genType 11 | let testConvertNestedRecordFromOtherFile = (x: Records.business) => x 12 | 13 | -------------------------------------------------------------------------------- /examples/deadcode/src/OptArg.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function foo(xOpt, yOpt, zOpt, w) { 5 | var x = xOpt !== undefined ? xOpt : 1; 6 | var y = yOpt !== undefined ? yOpt : 2; 7 | var z = zOpt !== undefined ? zOpt : 3; 8 | return ((x + y | 0) + z | 0) + w | 0; 9 | } 10 | 11 | function bar(x, y, z, w) { 12 | return y + w | 0; 13 | } 14 | 15 | console.log(foo(3, undefined, undefined, 4)); 16 | 17 | console.log(7); 18 | 19 | function threeArgs(aOpt, bOpt, cOpt, d) { 20 | var a = aOpt !== undefined ? aOpt : 1; 21 | var b = bOpt !== undefined ? bOpt : 2; 22 | var c = cOpt !== undefined ? cOpt : 3; 23 | return ((a + b | 0) + c | 0) + d | 0; 24 | } 25 | 26 | console.log(threeArgs(4, undefined, 7, 1)); 27 | 28 | console.log(threeArgs(4, undefined, undefined, 1)); 29 | 30 | function twoArgs(aOpt, bOpt, c) { 31 | var a = aOpt !== undefined ? aOpt : 1; 32 | var b = bOpt !== undefined ? bOpt : 2; 33 | return (a + b | 0) + c | 0; 34 | } 35 | 36 | console.log(twoArgs(undefined, undefined, 1)); 37 | 38 | var a = 3; 39 | 40 | console.log(a + 44 | 0); 41 | 42 | function wrapfourArgs(a, b, c, n) { 43 | var dOpt; 44 | var a$1 = a !== undefined ? a : 1; 45 | var b$1 = b !== undefined ? b : 2; 46 | var c$1 = c !== undefined ? c : 3; 47 | var d = dOpt !== undefined ? dOpt : 4; 48 | return (((a$1 + b$1 | 0) + c$1 | 0) + d | 0) + n | 0; 49 | } 50 | 51 | console.log(wrapfourArgs(3, undefined, 44, 44)); 52 | 53 | console.log(wrapfourArgs(undefined, 4, 44, 44)); 54 | 55 | export { 56 | foo , 57 | bar , 58 | } 59 | /* Not a pure module */ 60 | -------------------------------------------------------------------------------- /examples/deadcode/src/OptArg.res: -------------------------------------------------------------------------------- 1 | let foo = (~x=1, ~y=2, ~z=3, w) => x + y + z + w 2 | 3 | let bar = (~x=?, ~y, ~z=?, w) => y + w 4 | 5 | Js.log(foo(~x=3, 4)) 6 | 7 | Js.log(bar(~y=3, 4)) 8 | 9 | let threeArgs = (~a=1, ~b=2, ~c=3, d) => a + b + c + d 10 | 11 | Js.log(threeArgs(~a=4, ~c=7, 1)) 12 | Js.log(threeArgs(~a=4, 1)) 13 | 14 | let twoArgs = (~a=1, ~b=2, c) => a + b + c 15 | 16 | Js.log(1 |> twoArgs) 17 | 18 | let oneArg = (~a=1, ~z, b) => a + b 19 | 20 | let wrapOneArg = (~a=?, n) => oneArg(~a?, ~z=33, n) 21 | 22 | Js.log(wrapOneArg(~a=3, 44)) 23 | 24 | let fourArgs = (~a=1, ~b=2, ~c=3, ~d=4, n) => a + b + c + d + n 25 | 26 | let wrapfourArgs = (~a=?, ~b=?, ~c=?, n) => fourArgs(~a?, ~b?, ~c?, n) 27 | 28 | Js.log(wrapfourArgs(~a=3, ~c=44, 44)) 29 | Js.log(wrapfourArgs(~b=4, ~c=44, 44)) 30 | 31 | -------------------------------------------------------------------------------- /examples/deadcode/src/OptArg.resi: -------------------------------------------------------------------------------- 1 | let foo: (~x: int=?, ~y: int=?, ~z: int=?, int) => int 2 | let bar: (~x: 'a=?, ~y: int, ~z: 'b=?, int) => int 3 | 4 | -------------------------------------------------------------------------------- /examples/deadcode/src/References.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function create(x) { 5 | return { 6 | contents: x 7 | }; 8 | } 9 | 10 | function access(r) { 11 | return r.contents + 1 | 0; 12 | } 13 | 14 | function update(r) { 15 | r.contents = r.contents + 1 | 0; 16 | } 17 | 18 | function get(r) { 19 | return r.contents; 20 | } 21 | 22 | function make(prim) { 23 | return { 24 | contents: prim 25 | }; 26 | } 27 | 28 | function set(r, v) { 29 | r.contents = v; 30 | } 31 | 32 | var R = { 33 | get: get, 34 | make: make, 35 | set: set 36 | }; 37 | 38 | function destroysRefIdentity(x) { 39 | return x; 40 | } 41 | 42 | function preserveRefIdentity(x) { 43 | return x; 44 | } 45 | 46 | export { 47 | create , 48 | access , 49 | update , 50 | R , 51 | get , 52 | make , 53 | set , 54 | destroysRefIdentity , 55 | preserveRefIdentity , 56 | } 57 | /* No side effect */ 58 | -------------------------------------------------------------------------------- /examples/deadcode/src/References.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from References.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as Curry__Es6Import from 'rescript/lib/es6/curry.js'; 7 | const Curry: any = Curry__Es6Import; 8 | 9 | // @ts-ignore: Implicit any on import 10 | import * as ReferencesBS__Es6Import from './References.bs'; 11 | const ReferencesBS: any = ReferencesBS__Es6Import; 12 | 13 | // tslint:disable-next-line:max-classes-per-file 14 | export abstract class R_t { protected opaque!: a }; /* simulate opaque types */ 15 | 16 | // tslint:disable-next-line:interface-over-type-literal 17 | export type t = R_t; 18 | 19 | // tslint:disable-next-line:interface-over-type-literal 20 | export type requiresConversion = { readonly x: number }; 21 | 22 | export const create: (x:number) => { contents: number } = ReferencesBS.create; 23 | 24 | export const access: (r:{ contents: number }) => number = ReferencesBS.access; 25 | 26 | export const update: (r:{ contents: number }) => void = ReferencesBS.update; 27 | 28 | export const get: (_1:R_t) => T1 = ReferencesBS.get; 29 | 30 | export const make: (_1:T1) => R_t = ReferencesBS.make; 31 | 32 | export const set: (_1:R_t, _2:T1) => void = function (Arg1: any, Arg2: any) { 33 | const result = Curry._2(ReferencesBS.set, Arg1, Arg2); 34 | return result 35 | }; 36 | 37 | export const destroysRefIdentity: (x:{ contents: requiresConversion }) => { contents: requiresConversion } = ReferencesBS.destroysRefIdentity; 38 | 39 | export const preserveRefIdentity: (x:R_t) => R_t = ReferencesBS.preserveRefIdentity; 40 | -------------------------------------------------------------------------------- /examples/deadcode/src/References.res: -------------------------------------------------------------------------------- 1 | // Test pervasive references 2 | 3 | @genType 4 | let create = (x: int) => ref(x) 5 | 6 | @genType 7 | let access = r => r.contents + 1 8 | 9 | @genType 10 | let update = r => r.contents = r.contents + 1 11 | 12 | // Abstract version of references: works when conversion is required. 13 | 14 | module R: { 15 | @genType 16 | type t<'a> 17 | let get: t<'a> => 'a 18 | let make: 'a => t<'a> 19 | let set: (t<'a>, 'a) => unit 20 | } = { 21 | type t<'a> = ref<'a> 22 | let get = r => r.contents 23 | let make = ref 24 | let set = (r, v) => r.contents = v 25 | } 26 | 27 | @genType 28 | type t<'a> = R.t<'a> 29 | 30 | @genType 31 | let get = R.get 32 | 33 | @gentype 34 | let make = R.make 35 | 36 | @genType 37 | let set = R.set 38 | 39 | type requiresConversion = {x: int} 40 | 41 | // Careful: conversion makes a copy and destroys the reference identity. 42 | @genType 43 | let destroysRefIdentity = (x: ref) => x 44 | 45 | // Using abstract references preserves the identity. 46 | @genType 47 | let preserveRefIdentity = (x: R.t) => x 48 | 49 | -------------------------------------------------------------------------------- /examples/deadcode/src/RepeatedLabel.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function userData(param) { 5 | return { 6 | a: param.a, 7 | b: param.b 8 | }; 9 | } 10 | 11 | console.log(userData); 12 | 13 | export { 14 | userData , 15 | } 16 | /* Not a pure module */ 17 | -------------------------------------------------------------------------------- /examples/deadcode/src/RepeatedLabel.res: -------------------------------------------------------------------------------- 1 | type userData = { 2 | a: bool, 3 | b: int, 4 | } 5 | 6 | type tabState = { 7 | a: bool, 8 | b: int, 9 | f: string, 10 | } 11 | 12 | let userData = ({a, b}): userData => {a: a, b: b} 13 | 14 | Js.log(userData) 15 | 16 | -------------------------------------------------------------------------------- /examples/deadcode/src/RequireCond.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | /* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */ 3 | -------------------------------------------------------------------------------- /examples/deadcode/src/RequireCond.res: -------------------------------------------------------------------------------- 1 | @module 2 | @deprecated( 3 | "Please use this syntax to guarantee safe usage: [%requireCond(`gk, \"gk_name\", ConditionalModule)]" 4 | ) 5 | external make: ( 6 | @string [@as("qe.bool") #qeBool | @as("gk") #gk], 7 | string, 8 | string, 9 | ) => Js.Nullable.t<'a> = "requireCond" 10 | 11 | @module 12 | @deprecated( 13 | "Please use this syntax to guarantee safe usage: [%requireCond(`gk, \"gk_name\", {\"true\": ModuleA, \"false\": ModuleB})]" 14 | ) 15 | external either: ( 16 | @string [@as("qe.bool") #qeBool | @as("gk") #gk], 17 | string, 18 | {"true": string, "false": string}, 19 | ) => 'b = "requireCond" 20 | 21 | -------------------------------------------------------------------------------- /examples/deadcode/src/Shadow.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function test(param) { 5 | return "a"; 6 | } 7 | 8 | function test$1(param) { 9 | return "a"; 10 | } 11 | 12 | var M = { 13 | test: test$1 14 | }; 15 | 16 | export { 17 | test , 18 | M , 19 | } 20 | /* No side effect */ 21 | -------------------------------------------------------------------------------- /examples/deadcode/src/Shadow.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from Shadow.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as ShadowBS__Es6Import from './Shadow.bs'; 7 | const ShadowBS: any = ShadowBS__Es6Import; 8 | 9 | export const test: () => string = ShadowBS.test; 10 | -------------------------------------------------------------------------------- /examples/deadcode/src/Shadow.res: -------------------------------------------------------------------------------- 1 | @genType 2 | let test = () => 3 3 | 4 | @genType 5 | let test = () => "a" 6 | 7 | module M = { 8 | @genType 9 | let test = () => 3 10 | 11 | let test = () => "a" 12 | } 13 | 14 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestDeadExn.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as DeadExn from "./DeadExn.bs.js"; 4 | 5 | console.log({ 6 | RE_EXN_ID: DeadExn.Etoplevel 7 | }); 8 | 9 | export { 10 | 11 | } 12 | /* Not a pure module */ 13 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestDeadExn.res: -------------------------------------------------------------------------------- 1 | Js.log(DeadExn.Etoplevel) 2 | 3 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestEmitInnerModules.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var Inner = { 5 | x: 34, 6 | y: "hello" 7 | }; 8 | 9 | var Inner$1 = { 10 | y: 44 11 | }; 12 | 13 | var Medium = { 14 | Inner: Inner$1 15 | }; 16 | 17 | var Outer = { 18 | Medium: Medium 19 | }; 20 | 21 | export { 22 | Inner , 23 | Outer , 24 | } 25 | /* No side effect */ 26 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestEmitInnerModules.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from TestEmitInnerModules.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as TestEmitInnerModulesBS__Es6Import from './TestEmitInnerModules.bs'; 7 | const TestEmitInnerModulesBS: any = TestEmitInnerModulesBS__Es6Import; 8 | 9 | export const Inner_x: number = TestEmitInnerModulesBS.Inner.x; 10 | 11 | export const Inner_y: string = TestEmitInnerModulesBS.Inner.y; 12 | 13 | export const Outer_Medium_Inner_y: number = TestEmitInnerModulesBS.Outer.Medium.Inner.y; 14 | 15 | export const Inner: { x: number; y: string } = TestEmitInnerModulesBS.Inner 16 | 17 | export const Outer: { Medium: { Inner: { y: number } } } = TestEmitInnerModulesBS.Outer 18 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestEmitInnerModules.res: -------------------------------------------------------------------------------- 1 | module Inner = { 2 | @genType 3 | let x = 34 4 | @genType 5 | let y = "hello" 6 | } 7 | 8 | module Outer = { 9 | module Medium = { 10 | module Inner = { 11 | @genType 12 | let y = 44 13 | } 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestFirstClassModules.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function convert(x) { 5 | return x; 6 | } 7 | 8 | function convertInterface(x) { 9 | return x; 10 | } 11 | 12 | function convertRecord(x) { 13 | return x; 14 | } 15 | 16 | function convertFirstClassModuleWithTypeEquations(x) { 17 | return x; 18 | } 19 | 20 | export { 21 | convert , 22 | convertInterface , 23 | convertRecord , 24 | convertFirstClassModuleWithTypeEquations , 25 | } 26 | /* No side effect */ 27 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestFirstClassModules.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from TestFirstClassModules.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as TestFirstClassModulesBS__Es6Import from './TestFirstClassModules.bs'; 7 | const TestFirstClassModulesBS: any = TestFirstClassModulesBS__Es6Import; 8 | 9 | import type {firstClassModule as FirstClassModulesInterface_firstClassModule} from './FirstClassModulesInterface.gen'; 10 | 11 | import type {firstClassModule as FirstClassModules_firstClassModule} from './FirstClassModules.gen'; 12 | 13 | import type {record as FirstClassModulesInterface_record} from './FirstClassModulesInterface.gen'; 14 | 15 | // tslint:disable-next-line:interface-over-type-literal 16 | export type firstClassModuleWithTypeEquations = { readonly out: (_1:o) => o; readonly Inner: { readonly inn: (_1:i) => i } }; 17 | 18 | export const convert: (x:FirstClassModules_firstClassModule) => FirstClassModules_firstClassModule = TestFirstClassModulesBS.convert; 19 | 20 | export const convertInterface: (x:FirstClassModulesInterface_firstClassModule) => FirstClassModulesInterface_firstClassModule = TestFirstClassModulesBS.convertInterface; 21 | 22 | export const convertRecord: (x:FirstClassModulesInterface_record) => FirstClassModulesInterface_record = TestFirstClassModulesBS.convertRecord; 23 | 24 | export const convertFirstClassModuleWithTypeEquations: (x:{ readonly out: ((_1:T1) => T1); readonly Inner: { readonly inn: ((_1:T2) => T2) } }) => { readonly out: (_1:T1) => T1; readonly Inner: { readonly inn: (_1:T2) => T2 } } = TestFirstClassModulesBS.convertFirstClassModuleWithTypeEquations; 25 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestFirstClassModules.res: -------------------------------------------------------------------------------- 1 | @genType 2 | let convert = (x: FirstClassModules.firstClassModule) => x 3 | 4 | @genType 5 | let convertInterface = (x: FirstClassModulesInterface.firstClassModule) => x 6 | 7 | @genType 8 | let convertRecord = (x: FirstClassModulesInterface.record) => x 9 | 10 | module type MT = { 11 | type outer 12 | let out: outer => outer 13 | 14 | module Inner: { 15 | type inner 16 | let inn: inner => inner 17 | } 18 | } 19 | 20 | @genType 21 | type firstClassModuleWithTypeEquations<'i, 'o> = module(MT with 22 | type Inner.inner = 'i 23 | and type outer = 'o 24 | ) 25 | 26 | @genType 27 | let convertFirstClassModuleWithTypeEquations = ( 28 | type o i, 29 | x: module(MT with type Inner.inner = i and type outer = o), 30 | ) => x 31 | 32 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestImmutableArray.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Belt_Array from "rescript/lib/es6/belt_Array.js"; 4 | import * as ImmutableArray from "./ImmutableArray.bs.js"; 5 | 6 | function testImmutableArrayGet(arr) { 7 | return ImmutableArray.$$Array.get(arr, 3); 8 | } 9 | 10 | function testBeltArrayGet(arr) { 11 | return Belt_Array.get(arr, 3); 12 | } 13 | 14 | function testBeltArraySet(arr) { 15 | return Belt_Array.set(arr, 3, 4); 16 | } 17 | 18 | export { 19 | testImmutableArrayGet , 20 | testBeltArrayGet , 21 | testBeltArraySet , 22 | } 23 | /* No side effect */ 24 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestImmutableArray.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from TestImmutableArray.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as TestImmutableArrayBS__Es6Import from './TestImmutableArray.bs'; 7 | const TestImmutableArrayBS: any = TestImmutableArrayBS__Es6Import; 8 | 9 | export const testImmutableArrayGet: (arr:ReadonlyArray) => (null | undefined | T1) = TestImmutableArrayBS.testImmutableArrayGet; 10 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestImmutableArray.res: -------------------------------------------------------------------------------- 1 | @genType 2 | let testImmutableArrayGet = arr => { 3 | open ImmutableArray 4 | arr[3] 5 | } 6 | 7 | /* 8 | type error 9 | let testImmutableArraySet = arr => ImmutableArray.(arr[3] = 4); 10 | */ 11 | 12 | let testBeltArrayGet = arr => { 13 | open Belt 14 | arr[3] 15 | } 16 | 17 | let testBeltArraySet = arr => { 18 | open Belt 19 | arr[3] = 4 20 | } 21 | 22 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestImport.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Caml_option from "rescript/lib/es6/caml_option.js"; 4 | import * as TestImportGen from "./TestImport.gen"; 5 | 6 | var innerStuffContents = TestImportGen.innerStuffContents; 7 | 8 | var innerStuffContentsAsEmptyObject = TestImportGen.innerStuffContentsAsEmptyObject; 9 | 10 | var valueStartingWithUpperCaseLetter = TestImportGen.valueStartingWithUpperCaseLetter; 11 | 12 | var defaultValue = TestImportGen.defaultValue; 13 | 14 | function make(prim0, prim1, prim2) { 15 | return TestImportGen.make(prim0, prim1 !== undefined ? Caml_option.valFromOption(prim1) : undefined, prim2); 16 | } 17 | 18 | var defaultValue2 = TestImportGen.defaultValue2; 19 | 20 | export { 21 | innerStuffContentsAsEmptyObject , 22 | innerStuffContents , 23 | valueStartingWithUpperCaseLetter , 24 | defaultValue , 25 | make , 26 | defaultValue2 , 27 | } 28 | /* innerStuffContents Not a pure module */ 29 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestImport.res: -------------------------------------------------------------------------------- 1 | @genType.import(( 2 | "./exportNestedValues", 3 | "TopLevelClass.MiddleLevelElements.stuff.InnerStuff.innerStuffContents", 4 | )) 5 | external innerStuffContents: {"x": int} = "innerStuffContents" 6 | 7 | @genType.import(( 8 | "./exportNestedValues", 9 | "TopLevelClass.MiddleLevelElements.stuff.InnerStuff.innerStuffContents", 10 | )) 11 | external innerStuffContentsAsEmptyObject: {.} = "innerStuffContentsAsEmptyObject" 12 | 13 | let innerStuffContents = innerStuffContents 14 | 15 | @genType.import(("./exportNestedValues", "ValueStartingWithUpperCaseLetter")) 16 | external valueStartingWithUpperCaseLetter: string = "valueStartingWithUpperCaseLetter" 17 | 18 | @genType.import(("./exportNestedValues", "default")) 19 | external defaultValue: int = "defaultValue" 20 | 21 | @genType 22 | type message = {text: string} 23 | 24 | @genType.import(("./MyBanner", "TopLevelClass.MiddleLevelElements.MyBannerInternal")) 25 | external make: (~show: bool, ~message: option=?, 'a) => React.element = "make" 26 | 27 | let make = make 28 | 29 | @genType.import(("./exportNestedValues", "default")) 30 | external defaultValue2: int = "defaultValue2" 31 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestModuleAliases.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function testInner1(x) { 5 | return x; 6 | } 7 | 8 | function testInner1Expanded(x) { 9 | return x; 10 | } 11 | 12 | function testInner2(x) { 13 | return x; 14 | } 15 | 16 | function testInner2Expanded(x) { 17 | return x; 18 | } 19 | 20 | var OtherFile; 21 | 22 | var OtherFileAlias; 23 | 24 | var OuterAlias; 25 | 26 | var OtherFile1; 27 | 28 | var Outer2; 29 | 30 | var Inner2; 31 | 32 | export { 33 | OtherFile , 34 | OtherFileAlias , 35 | OuterAlias , 36 | OtherFile1 , 37 | Outer2 , 38 | Inner2 , 39 | testInner1 , 40 | testInner1Expanded , 41 | testInner2 , 42 | testInner2Expanded , 43 | } 44 | /* No side effect */ 45 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestModuleAliases.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from TestModuleAliases.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as TestModuleAliasesBS__Es6Import from './TestModuleAliases.bs'; 7 | const TestModuleAliasesBS: any = TestModuleAliasesBS__Es6Import; 8 | 9 | import type {InnerAlias_inner as ModuleAliases2_InnerAlias_inner} from './ModuleAliases2.gen'; 10 | 11 | import type {Outer_Inner_inner as ModuleAliases2_Outer_Inner_inner} from './ModuleAliases2.gen'; 12 | 13 | import type {Outer_outer as ModuleAliases2_Outer_outer} from './ModuleAliases2.gen'; 14 | 15 | import type {record as ModuleAliases2_record} from './ModuleAliases2.gen'; 16 | 17 | // tslint:disable-next-line:interface-over-type-literal 18 | export type record = ModuleAliases2_record; 19 | 20 | // tslint:disable-next-line:interface-over-type-literal 21 | export type record2 = ModuleAliases2_record; 22 | 23 | // tslint:disable-next-line:interface-over-type-literal 24 | export type outer = ModuleAliases2_Outer_outer; 25 | 26 | // tslint:disable-next-line:interface-over-type-literal 27 | export type outer2 = ModuleAliases2_Outer_outer; 28 | 29 | // tslint:disable-next-line:interface-over-type-literal 30 | export type my2 = ModuleAliases2_Outer_Inner_inner; 31 | 32 | // tslint:disable-next-line:interface-over-type-literal 33 | export type inner1 = ModuleAliases2_InnerAlias_inner; 34 | 35 | // tslint:disable-next-line:interface-over-type-literal 36 | export type inner2 = ModuleAliases2_Outer_Inner_inner; 37 | 38 | export const testInner1: (x:inner1) => inner1 = TestModuleAliasesBS.testInner1; 39 | 40 | export const testInner1Expanded: (x:ModuleAliases2_InnerAlias_inner) => ModuleAliases2_InnerAlias_inner = TestModuleAliasesBS.testInner1Expanded; 41 | 42 | export const testInner2: (x:inner2) => inner2 = TestModuleAliasesBS.testInner2; 43 | 44 | export const testInner2Expanded: (x:ModuleAliases2_Outer_Inner_inner) => ModuleAliases2_Outer_Inner_inner = TestModuleAliasesBS.testInner2Expanded; 45 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestModuleAliases.res: -------------------------------------------------------------------------------- 1 | module OtherFile = ModuleAliases2 2 | module OtherFileAlias = OtherFile 3 | 4 | @genType 5 | type record = OtherFile.record 6 | 7 | @genType 8 | type record2 = OtherFileAlias.record 9 | 10 | module OuterAlias = OtherFile.Outer 11 | 12 | @genType 13 | type outer = OtherFileAlias.Outer.outer 14 | 15 | @genType 16 | type outer2 = OuterAlias.outer 17 | 18 | module OtherFile1 = OtherFile 19 | module Outer2 = OtherFile1.Outer 20 | module Inner2 = Outer2.Inner 21 | 22 | @genType 23 | type my2 = Inner2.inner 24 | 25 | @genType 26 | type inner1 = OtherFile.InnerAlias.inner 27 | 28 | @genType 29 | type inner2 = OtherFile.Outer.Inner.inner 30 | 31 | @genType 32 | let testInner1 = (x: inner1) => x 33 | 34 | @genType 35 | let testInner1Expanded = (x: OtherFile.InnerAlias.inner) => x 36 | 37 | @genType 38 | let testInner2 = (x: inner2) => x 39 | 40 | @genType 41 | let testInner2Expanded = (x: OtherFile.Outer.Inner.inner) => x 42 | 43 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestOptArg.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as OptArg from "./OptArg.bs.js"; 4 | 5 | console.log(OptArg.bar(undefined, 3, 3, 4)); 6 | 7 | function foo(xOpt, y) { 8 | var x = xOpt !== undefined ? xOpt : 3; 9 | return x + y | 0; 10 | } 11 | 12 | function bar(param) { 13 | var x = 12; 14 | return x + 3 | 0; 15 | } 16 | 17 | console.log(bar); 18 | 19 | function notSuppressesOptArgs(xOpt, yOpt, zOpt, w) { 20 | var x = xOpt !== undefined ? xOpt : 1; 21 | var y = yOpt !== undefined ? yOpt : 2; 22 | var z = zOpt !== undefined ? zOpt : 3; 23 | return ((x + y | 0) + z | 0) + w | 0; 24 | } 25 | 26 | notSuppressesOptArgs(undefined, undefined, undefined, 3); 27 | 28 | function liveSuppressesOptArgs(xOpt, yOpt, zOpt, w) { 29 | var x = xOpt !== undefined ? xOpt : 1; 30 | var y = yOpt !== undefined ? yOpt : 2; 31 | var z = zOpt !== undefined ? zOpt : 3; 32 | return ((x + y | 0) + z | 0) + w | 0; 33 | } 34 | 35 | liveSuppressesOptArgs(3, undefined, undefined, 3); 36 | 37 | export { 38 | foo , 39 | bar , 40 | notSuppressesOptArgs , 41 | liveSuppressesOptArgs , 42 | } 43 | /* Not a pure module */ 44 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestOptArg.res: -------------------------------------------------------------------------------- 1 | Js.log(OptArg.bar(~z=3, ~y=3, 4)) 2 | 3 | let foo = (~x=3, y) => x + y 4 | 5 | let bar = () => foo(~x=12, 3) 6 | 7 | Js.log(bar) 8 | 9 | let notSuppressesOptArgs = (~x=1, ~y=2, ~z=3, w) => x + y + z + w 10 | 11 | let _ = notSuppressesOptArgs(3) 12 | 13 | @live 14 | let liveSuppressesOptArgs = (~x=1, ~y=2, ~z=3, w) => x + y + z + w 15 | 16 | let _ = liveSuppressesOptArgs(~x=3, 3) 17 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestPromise.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Js_promise from "rescript/lib/es6/js_promise.js"; 4 | 5 | function convert(param) { 6 | return Js_promise.then_((function (param) { 7 | return Promise.resolve({ 8 | result: param.s 9 | }); 10 | }), param); 11 | } 12 | 13 | export { 14 | convert , 15 | } 16 | /* No side effect */ 17 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestPromise.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from TestPromise.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as TestPromiseBS__Es6Import from './TestPromise.bs'; 7 | const TestPromiseBS: any = TestPromiseBS__Es6Import; 8 | 9 | // tslint:disable-next-line:interface-over-type-literal 10 | export type promise = Promise; 11 | 12 | // tslint:disable-next-line:interface-over-type-literal 13 | export type fromPayload = { readonly x: number; readonly s: string }; 14 | 15 | // tslint:disable-next-line:interface-over-type-literal 16 | export type toPayload = { readonly result: string }; 17 | 18 | export const convert: (_1:Promise) => Promise = TestPromiseBS.convert; 19 | -------------------------------------------------------------------------------- /examples/deadcode/src/TestPromise.res: -------------------------------------------------------------------------------- 1 | @genType 2 | type promise<'a> = Js.Promise.t<'a> 3 | 4 | @genType 5 | type fromPayload = { 6 | x: int, 7 | s: string, 8 | } 9 | 10 | @genType 11 | type toPayload = {result: string} 12 | 13 | @genType 14 | let convert = Js.Promise.then_(({s}) => Js.Promise.resolve({result: s})) 15 | 16 | -------------------------------------------------------------------------------- /examples/deadcode/src/ToSuppress.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var toSuppress = 0; 5 | 6 | export { 7 | toSuppress , 8 | } 9 | /* No side effect */ 10 | -------------------------------------------------------------------------------- /examples/deadcode/src/ToSuppress.res: -------------------------------------------------------------------------------- 1 | let toSuppress = 0 2 | -------------------------------------------------------------------------------- /examples/deadcode/src/TransitiveType1.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function convert(x) { 5 | return x; 6 | } 7 | 8 | function convertAlias(x) { 9 | return x; 10 | } 11 | 12 | export { 13 | convert , 14 | convertAlias , 15 | } 16 | /* No side effect */ 17 | -------------------------------------------------------------------------------- /examples/deadcode/src/TransitiveType1.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from TransitiveType1.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as TransitiveType1BS__Es6Import from './TransitiveType1.bs'; 7 | const TransitiveType1BS: any = TransitiveType1BS__Es6Import; 8 | 9 | import type {t2Alias as TransitiveType2_t2Alias} from './TransitiveType2.gen'; 10 | 11 | import type {t2 as TransitiveType2_t2} from './TransitiveType2.gen'; 12 | 13 | export const convert: (x:TransitiveType2_t2) => TransitiveType2_t2 = function (Arg1: any) { 14 | const result = TransitiveType1BS.convert((Arg1 == null ? undefined : Arg1)); 15 | return result 16 | }; 17 | 18 | export const convertAlias: (x:TransitiveType2_t2Alias) => TransitiveType2_t2Alias = function (Arg1: any) { 19 | const result = TransitiveType1BS.convertAlias((Arg1 == null ? undefined : Arg1)); 20 | return result 21 | }; 22 | -------------------------------------------------------------------------------- /examples/deadcode/src/TransitiveType1.res: -------------------------------------------------------------------------------- 1 | @genType 2 | let convert = (x: TransitiveType2.t2) => x 3 | 4 | @genType 5 | let convertAlias = (x: TransitiveType2.t2Alias) => x 6 | 7 | -------------------------------------------------------------------------------- /examples/deadcode/src/TransitiveType2.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function convertT2(x) { 5 | return x; 6 | } 7 | 8 | export { 9 | convertT2 , 10 | } 11 | /* No side effect */ 12 | -------------------------------------------------------------------------------- /examples/deadcode/src/TransitiveType2.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from TransitiveType2.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | import type {t3 as TransitiveType3_t3} from './TransitiveType3.gen'; 6 | 7 | // tslint:disable-next-line:interface-over-type-literal 8 | export type t2 = (null | undefined | TransitiveType3_t3); 9 | 10 | // tslint:disable-next-line:interface-over-type-literal 11 | export type t2Alias = t2; 12 | -------------------------------------------------------------------------------- /examples/deadcode/src/TransitiveType2.res: -------------------------------------------------------------------------------- 1 | @genType 2 | type t2 = option 3 | 4 | @genType 5 | type t2Alias = t2 6 | 7 | let convertT2 = (x: t2) => x 8 | 9 | -------------------------------------------------------------------------------- /examples/deadcode/src/TransitiveType3.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function convertT3(x) { 5 | return x; 6 | } 7 | 8 | export { 9 | convertT3 , 10 | } 11 | /* No side effect */ 12 | -------------------------------------------------------------------------------- /examples/deadcode/src/TransitiveType3.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from TransitiveType3.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as TransitiveType3BS__Es6Import from './TransitiveType3.bs'; 7 | const TransitiveType3BS: any = TransitiveType3BS__Es6Import; 8 | 9 | // tslint:disable-next-line:interface-over-type-literal 10 | export type t3 = { readonly i: number; readonly s: string }; 11 | 12 | export const convertT3: (x:t3) => t3 = TransitiveType3BS.convertT3; 13 | -------------------------------------------------------------------------------- /examples/deadcode/src/TransitiveType3.res: -------------------------------------------------------------------------------- 1 | @genType 2 | type t3 = { 3 | i: int, 4 | s: string, 5 | } 6 | 7 | @genType 8 | let convertT3 = (x: t3) => x 9 | 10 | -------------------------------------------------------------------------------- /examples/deadcode/src/Tuples.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Belt_Option from "rescript/lib/es6/belt_Option.js"; 4 | 5 | function testTuple(param) { 6 | return param[0] + param[1] | 0; 7 | } 8 | 9 | function computeArea(param) { 10 | return Math.imul(Math.imul(param[0], param[1]), Belt_Option.mapWithDefault(param[2], 1, (function (n) { 11 | return n; 12 | }))); 13 | } 14 | 15 | function computeAreaWithIdent(param) { 16 | return Math.imul(Math.imul(param[0], param[1]), Belt_Option.mapWithDefault(param[2], 1, (function (n) { 17 | return n; 18 | }))); 19 | } 20 | 21 | function computeAreaNoConverters(param) { 22 | return Math.imul(param[0], param[1]); 23 | } 24 | 25 | function coord2d(x, y) { 26 | return [ 27 | x, 28 | y, 29 | undefined 30 | ]; 31 | } 32 | 33 | function getFirstName(param) { 34 | return param[0].name; 35 | } 36 | 37 | function marry(first, second) { 38 | return [ 39 | first, 40 | second 41 | ]; 42 | } 43 | 44 | function changeSecondAge(param) { 45 | var second = param[1]; 46 | return [ 47 | param[0], 48 | { 49 | name: second.name, 50 | age: second.age + 1 | 0 51 | } 52 | ]; 53 | } 54 | 55 | var origin = [ 56 | 0, 57 | 0, 58 | 0 59 | ]; 60 | 61 | export { 62 | testTuple , 63 | origin , 64 | computeArea , 65 | computeAreaWithIdent , 66 | computeAreaNoConverters , 67 | coord2d , 68 | getFirstName , 69 | marry , 70 | changeSecondAge , 71 | } 72 | /* No side effect */ 73 | -------------------------------------------------------------------------------- /examples/deadcode/src/Tuples.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from Tuples.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as Curry__Es6Import from 'rescript/lib/es6/curry.js'; 7 | const Curry: any = Curry__Es6Import; 8 | 9 | // @ts-ignore: Implicit any on import 10 | import * as TuplesBS__Es6Import from './Tuples.bs'; 11 | const TuplesBS: any = TuplesBS__Es6Import; 12 | 13 | // tslint:disable-next-line:interface-over-type-literal 14 | export type coord = [number, number, (null | undefined | number)]; 15 | 16 | // tslint:disable-next-line:interface-over-type-literal 17 | export type coord2 = [number, number, (null | undefined | number)]; 18 | 19 | // tslint:disable-next-line:interface-over-type-literal 20 | export type person = { readonly name: string; readonly age: number }; 21 | 22 | // tslint:disable-next-line:interface-over-type-literal 23 | export type couple = [person, person]; 24 | 25 | export const testTuple: (param:[number, number]) => number = TuplesBS.testTuple; 26 | 27 | export const origin: [number, number, (null | undefined | number)] = TuplesBS.origin; 28 | 29 | export const computeArea: (param:[number, number, (null | undefined | number)]) => number = function (Arg1: any) { 30 | const result = TuplesBS.computeArea([Arg1[0], Arg1[1], (Arg1[2] == null ? undefined : Arg1[2])]); 31 | return result 32 | }; 33 | 34 | export const computeAreaWithIdent: (param:coord) => number = function (Arg1: any) { 35 | const result = TuplesBS.computeAreaWithIdent([Arg1[0], Arg1[1], (Arg1[2] == null ? undefined : Arg1[2])]); 36 | return result 37 | }; 38 | 39 | export const computeAreaNoConverters: (param:[number, number]) => number = TuplesBS.computeAreaNoConverters; 40 | 41 | export const coord2d: (x:T1, y:T2) => [T1, T2, (null | undefined | T3)] = function (Arg1: any, Arg2: any) { 42 | const result = Curry._2(TuplesBS.coord2d, Arg1, Arg2); 43 | return result 44 | }; 45 | 46 | export const getFirstName: (param:couple) => string = TuplesBS.getFirstName; 47 | 48 | export const marry: (first:person, second:person) => couple = function (Arg1: any, Arg2: any) { 49 | const result = Curry._2(TuplesBS.marry, Arg1, Arg2); 50 | return result 51 | }; 52 | 53 | export const changeSecondAge: (param:couple) => couple = TuplesBS.changeSecondAge; 54 | -------------------------------------------------------------------------------- /examples/deadcode/src/Tuples.res: -------------------------------------------------------------------------------- 1 | open Belt 2 | 3 | @genType 4 | let testTuple = ((a, b)) => a + b 5 | 6 | @genType 7 | type coord = (int, int, option) 8 | 9 | @genType 10 | let origin = (0, 0, Some(0)) 11 | 12 | @genType 13 | let computeArea = ((x, y, z)) => { 14 | open Option 15 | x * y * z->mapWithDefault(1, n => n) 16 | } 17 | 18 | @genType 19 | let computeAreaWithIdent = ((x, y, z): coord) => { 20 | open Option 21 | x * y * z->mapWithDefault(1, n => n) 22 | } 23 | 24 | @genType 25 | let computeAreaNoConverters = ((x: int, y: int)) => x * y 26 | 27 | @genType 28 | let coord2d = (x, y) => (x, y, None) 29 | 30 | @genType 31 | type coord2 = (int, int, Js.Nullable.t) 32 | 33 | @genType 34 | type person = { 35 | name: string, 36 | age: int, 37 | } 38 | 39 | @genType 40 | type couple = (person, person) 41 | 42 | @genType 43 | let getFirstName = ((first, _second): couple) => first.name 44 | 45 | @genType 46 | let marry = (first, second): couple => (first, second) 47 | 48 | @genType 49 | let changeSecondAge = ((first, second): couple): couple => (first, {...second, age: second.age + 1}) 50 | 51 | -------------------------------------------------------------------------------- /examples/deadcode/src/TypeParams1.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var exportSomething = 10; 5 | 6 | export { 7 | exportSomething , 8 | } 9 | /* No side effect */ 10 | -------------------------------------------------------------------------------- /examples/deadcode/src/TypeParams1.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from TypeParams1.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // tslint:disable-next-line:interface-over-type-literal 6 | export type ocaml_array = a[]; 7 | -------------------------------------------------------------------------------- /examples/deadcode/src/TypeParams1.res: -------------------------------------------------------------------------------- 1 | @gentype 2 | type ocaml_array<'a> = array<'a> 3 | 4 | let exportSomething = 10 5 | 6 | -------------------------------------------------------------------------------- /examples/deadcode/src/TypeParams2.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | var exportSomething = 10; 5 | 6 | export { 7 | exportSomething , 8 | } 9 | /* No side effect */ 10 | -------------------------------------------------------------------------------- /examples/deadcode/src/TypeParams2.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from TypeParams2.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | import type {ocaml_array as TypeParams1_ocaml_array} from './TypeParams1.gen'; 6 | 7 | // tslint:disable-next-line:interface-over-type-literal 8 | export type item = { readonly id: number }; 9 | 10 | // tslint:disable-next-line:interface-over-type-literal 11 | export type items = TypeParams1_ocaml_array; 12 | 13 | // tslint:disable-next-line:interface-over-type-literal 14 | export type items2 = item[]; 15 | -------------------------------------------------------------------------------- /examples/deadcode/src/TypeParams2.res: -------------------------------------------------------------------------------- 1 | @genType 2 | type item = {id: int} 3 | 4 | @genType 5 | type items = TypeParams1.ocaml_array 6 | 7 | @genType 8 | type items2 = array 9 | 10 | let exportSomething = 10 11 | 12 | -------------------------------------------------------------------------------- /examples/deadcode/src/TypeParams3.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function test(x) { 5 | return x; 6 | } 7 | 8 | function test2(x) { 9 | return x; 10 | } 11 | 12 | export { 13 | test , 14 | test2 , 15 | } 16 | /* No side effect */ 17 | -------------------------------------------------------------------------------- /examples/deadcode/src/TypeParams3.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from TypeParams3.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as TypeParams3BS__Es6Import from './TypeParams3.bs'; 7 | const TypeParams3BS: any = TypeParams3BS__Es6Import; 8 | 9 | import type {items2 as TypeParams2_items2} from './TypeParams2.gen'; 10 | 11 | import type {items as TypeParams2_items} from './TypeParams2.gen'; 12 | 13 | export const test: (x:TypeParams2_items) => TypeParams2_items = TypeParams3BS.test; 14 | 15 | export const test2: (x:TypeParams2_items2) => TypeParams2_items2 = TypeParams3BS.test2; 16 | -------------------------------------------------------------------------------- /examples/deadcode/src/TypeParams3.res: -------------------------------------------------------------------------------- 1 | @genType 2 | let test = (x: TypeParams2.items) => x 3 | 4 | @genType 5 | let test2 = (x: TypeParams2.items2) => x 6 | 7 | -------------------------------------------------------------------------------- /examples/deadcode/src/Types.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as List from "rescript/lib/es6/list.js"; 4 | import * as Curry from "rescript/lib/es6/curry.js"; 5 | import * as Belt_Option from "rescript/lib/es6/belt_Option.js"; 6 | 7 | function swap(tree) { 8 | return { 9 | label: tree.label, 10 | left: Belt_Option.map(tree.right, swap), 11 | right: Belt_Option.map(tree.left, swap) 12 | }; 13 | } 14 | 15 | function selfRecursiveConverter(param) { 16 | return param.self; 17 | } 18 | 19 | function mutuallyRecursiveConverter(param) { 20 | return param.b; 21 | } 22 | 23 | function testFunctionOnOptionsAsArgument(a, foo) { 24 | return Curry._1(foo, a); 25 | } 26 | 27 | function jsonStringify(prim) { 28 | return JSON.stringify(prim); 29 | } 30 | 31 | function testConvertNull(x) { 32 | return x; 33 | } 34 | 35 | var testMarshalFields = { 36 | rec: "rec", 37 | _switch: "_switch", 38 | switch: "switch", 39 | __: "__", 40 | _: "_", 41 | foo: "foo", 42 | _foo: "_foo", 43 | Uppercase: "Uppercase", 44 | _Uppercase: "_Uppercase" 45 | }; 46 | 47 | function setMatch(x) { 48 | x.match = 34; 49 | } 50 | 51 | function testInstantiateTypeParameter(x) { 52 | return x; 53 | } 54 | 55 | var currentTime = new Date(); 56 | 57 | var optFunction = (function (param) { 58 | return 3; 59 | }); 60 | 61 | var ObjectId = {}; 62 | 63 | var someIntList = { 64 | hd: 1, 65 | tl: { 66 | hd: 2, 67 | tl: { 68 | hd: 3, 69 | tl: /* [] */0 70 | } 71 | } 72 | }; 73 | 74 | var map = List.map; 75 | 76 | var stringT = "a"; 77 | 78 | var jsStringT = "a"; 79 | 80 | var jsString2T = "a"; 81 | 82 | var i64Const = [ 83 | 0, 84 | 34 85 | ]; 86 | 87 | export { 88 | someIntList , 89 | map , 90 | swap , 91 | selfRecursiveConverter , 92 | mutuallyRecursiveConverter , 93 | testFunctionOnOptionsAsArgument , 94 | stringT , 95 | jsStringT , 96 | jsString2T , 97 | jsonStringify , 98 | testConvertNull , 99 | testMarshalFields , 100 | setMatch , 101 | testInstantiateTypeParameter , 102 | currentTime , 103 | i64Const , 104 | optFunction , 105 | ObjectId , 106 | } 107 | /* currentTime Not a pure module */ 108 | -------------------------------------------------------------------------------- /examples/deadcode/src/Unboxed.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function testV1(x) { 5 | return x; 6 | } 7 | 8 | function r2Test(x) { 9 | return x; 10 | } 11 | 12 | export { 13 | testV1 , 14 | r2Test , 15 | } 16 | /* No side effect */ 17 | -------------------------------------------------------------------------------- /examples/deadcode/src/Unboxed.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from Unboxed.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as UnboxedBS__Es6Import from './Unboxed.bs'; 7 | const UnboxedBS: any = UnboxedBS__Es6Import; 8 | 9 | // tslint:disable-next-line:interface-over-type-literal 10 | export type v1 = number; 11 | 12 | // tslint:disable-next-line:interface-over-type-literal 13 | export type v2 = number; 14 | 15 | // tslint:disable-next-line:interface-over-type-literal 16 | export type r1 = number; 17 | 18 | // tslint:disable-next-line:interface-over-type-literal 19 | export type r2 = string; 20 | 21 | export const testV1: (x:v1) => v1 = UnboxedBS.testV1; 22 | 23 | export const r2Test: (x:r2) => r2 = UnboxedBS.r2Test; 24 | -------------------------------------------------------------------------------- /examples/deadcode/src/Unboxed.res: -------------------------------------------------------------------------------- 1 | @genType @ocaml.unboxed 2 | type v1 = A(int) 3 | 4 | @genType @unboxed 5 | type v2 = A(int) 6 | 7 | @genType 8 | let testV1 = (x: v1) => x 9 | 10 | @genType @unboxed 11 | type r1 = {x: int} 12 | 13 | @genType @ocaml.unboxed 14 | type r2 = B({g: string}) 15 | 16 | @genType 17 | let r2Test = (x: r2) => x 18 | 19 | -------------------------------------------------------------------------------- /examples/deadcode/src/Uncurried.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Curry from "rescript/lib/es6/curry.js"; 4 | 5 | function uncurried0() { 6 | return ""; 7 | } 8 | 9 | function uncurried1(x) { 10 | return String(x); 11 | } 12 | 13 | function uncurried2(x, y) { 14 | return String(x) + y; 15 | } 16 | 17 | function uncurried3(x, y, z) { 18 | return String(x) + (y + String(z)); 19 | } 20 | 21 | function curried3(x, y, z) { 22 | return String(x) + (y + String(z)); 23 | } 24 | 25 | function callback(cb) { 26 | return String(Curry._1(cb, undefined)); 27 | } 28 | 29 | function callback2(auth) { 30 | return Curry._1(auth.login, undefined); 31 | } 32 | 33 | function callback2U(auth) { 34 | return auth.loginU(); 35 | } 36 | 37 | function sumU(n, m) { 38 | console.log("sumU 2nd arg", m, "result", n + m | 0); 39 | } 40 | 41 | function sumU2(n) { 42 | return function (m) { 43 | console.log("sumU2 2nd arg", m, "result", n + m | 0); 44 | }; 45 | } 46 | 47 | function sumCurried(n) { 48 | console.log("sumCurried 1st arg", n); 49 | return function (m) { 50 | console.log("sumCurried 2nd arg", m, "result", n + m | 0); 51 | }; 52 | } 53 | 54 | function sumLblCurried(s, n) { 55 | console.log(s, "sumLblCurried 1st arg", n); 56 | return function (m) { 57 | console.log("sumLblCurried 2nd arg", m, "result", n + m | 0); 58 | }; 59 | } 60 | 61 | export { 62 | uncurried0 , 63 | uncurried1 , 64 | uncurried2 , 65 | uncurried3 , 66 | curried3 , 67 | callback , 68 | callback2 , 69 | callback2U , 70 | sumU , 71 | sumU2 , 72 | sumCurried , 73 | sumLblCurried , 74 | } 75 | /* No side effect */ 76 | -------------------------------------------------------------------------------- /examples/deadcode/src/Uncurried.res: -------------------------------------------------------------------------------- 1 | @genType 2 | type u0 = (. unit) => string 3 | 4 | @genType 5 | type u1 = (. int) => string 6 | 7 | @genType 8 | type u2 = (. int, string) => string 9 | 10 | @genType 11 | type u3 = (. int, string, int) => string 12 | 13 | @genType 14 | let uncurried0 = (. ()) => "" 15 | 16 | @genType 17 | let uncurried1 = (. x) => x |> string_of_int 18 | 19 | @genType 20 | let uncurried2 = (. x, y) => (x |> string_of_int) ++ y 21 | 22 | @genType 23 | let uncurried3 = (. x, y, z) => (x |> string_of_int) ++ (y ++ (z |> string_of_int)) 24 | 25 | @genType 26 | let curried3 = (x, y, z) => (x |> string_of_int) ++ (y ++ (z |> string_of_int)) 27 | 28 | @genType 29 | let callback = cb => cb() |> string_of_int 30 | 31 | type auth = {login: unit => string} 32 | type authU = {loginU: (. unit) => string} 33 | 34 | @genType 35 | let callback2 = auth => auth.login() 36 | 37 | @genType 38 | let callback2U = auth => auth.loginU(.) 39 | 40 | @genType 41 | let sumU = (. n, m) => Js.log4("sumU 2nd arg", m, "result", n + m) 42 | 43 | @genType 44 | let sumU2 = (. n, . m) => Js.log4("sumU2 2nd arg", m, "result", n + m) 45 | 46 | @genType 47 | let sumCurried = n => { 48 | Js.log2("sumCurried 1st arg", n) 49 | m => Js.log4("sumCurried 2nd arg", m, "result", n + m) 50 | } 51 | 52 | @genType 53 | let sumLblCurried = (s: string, ~n) => { 54 | Js.log3(s, "sumLblCurried 1st arg", n) 55 | (~m) => Js.log4("sumLblCurried 2nd arg", m, "result", n + m) 56 | } 57 | 58 | -------------------------------------------------------------------------------- /examples/deadcode/src/Unison.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function group(breakOpt, doc) { 5 | var $$break = breakOpt !== undefined ? breakOpt : /* IfNeed */0; 6 | return { 7 | break: $$break, 8 | doc: doc 9 | }; 10 | } 11 | 12 | function fits(_w, _stack) { 13 | while(true) { 14 | var stack = _stack; 15 | var w = _w; 16 | if (w < 0) { 17 | return false; 18 | } 19 | if (!stack) { 20 | return true; 21 | } 22 | _stack = stack._1; 23 | _w = w - stack._0.doc.length | 0; 24 | continue ; 25 | }; 26 | } 27 | 28 | function toString(width, stack) { 29 | if (!stack) { 30 | return ""; 31 | } 32 | var stack$1 = stack._1; 33 | var match = stack._0; 34 | var doc = match.doc; 35 | switch (match.break) { 36 | case /* IfNeed */0 : 37 | return ( 38 | fits(width, stack$1) ? "fits " : "no " 39 | ) + toString(width - 1 | 0, stack$1); 40 | case /* Never */1 : 41 | return "never " + (doc + toString(width - 1 | 0, stack$1)); 42 | case /* Always */2 : 43 | return "always " + (doc + toString(width - 1 | 0, stack$1)); 44 | 45 | } 46 | } 47 | 48 | toString(80, /* Empty */0); 49 | 50 | var $$break = /* Never */1; 51 | 52 | toString(80, /* Cons */{ 53 | _0: { 54 | break: $$break, 55 | doc: "abc" 56 | }, 57 | _1: /* Empty */0 58 | }); 59 | 60 | var $$break$1 = /* Always */2; 61 | 62 | toString(80, /* Cons */{ 63 | _0: { 64 | break: $$break$1, 65 | doc: "d" 66 | }, 67 | _1: /* Empty */0 68 | }); 69 | 70 | export { 71 | group , 72 | fits , 73 | toString , 74 | } 75 | /* Not a pure module */ 76 | -------------------------------------------------------------------------------- /examples/deadcode/src/Unison.res: -------------------------------------------------------------------------------- 1 | // Exmple of several DCE checks operating in unison 2 | 3 | type break = 4 | | IfNeed 5 | | Never 6 | | Always 7 | 8 | type t = { 9 | break: break, 10 | doc: string, 11 | } 12 | 13 | type rec stack = 14 | | Empty 15 | | Cons(t, stack) 16 | 17 | let group = (~break=IfNeed, doc) => {break: break, doc: doc} 18 | 19 | let rec fits = (w, stack) => 20 | switch stack { 21 | | _ when w < 0 => false 22 | | Empty => true 23 | | Cons({doc}, stack) => fits(w - String.length(doc), stack) 24 | } 25 | 26 | let rec toString = (~width, stack) => 27 | switch stack { 28 | | Cons({break, doc}, stack) => 29 | switch break { 30 | | IfNeed => (fits(width, stack) ? "fits " : "no ") ++ (stack |> toString(~width=width - 1)) 31 | | Never => "never " ++ (doc ++ (stack |> toString(~width=width - 1))) 32 | | Always => "always " ++ (doc ++ (stack |> toString(~width=width - 1))) 33 | } 34 | | Empty => "" 35 | } 36 | 37 | toString(~width=80, Empty) 38 | toString(~width=80, Cons(group(~break=Never, "abc"), Empty)) 39 | toString(~width=80, Cons(group(~break=Always, "d"), Empty)) 40 | 41 | -------------------------------------------------------------------------------- /examples/deadcode/src/UseImportJsValue.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function useGetProp(x) { 5 | return x.getProp() + 1 | 0; 6 | } 7 | 8 | function useTypeImportedInOtherModule(x) { 9 | return x; 10 | } 11 | 12 | export { 13 | useGetProp , 14 | useTypeImportedInOtherModule , 15 | } 16 | /* No side effect */ 17 | -------------------------------------------------------------------------------- /examples/deadcode/src/UseImportJsValue.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from UseImportJsValue.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | // @ts-ignore: Implicit any on import 6 | import * as UseImportJsValueBS__Es6Import from './UseImportJsValue.bs'; 7 | const UseImportJsValueBS: any = UseImportJsValueBS__Es6Import; 8 | 9 | import type {AbsoluteValue_t as ImportJsValue_AbsoluteValue_t} from './ImportJsValue.gen'; 10 | 11 | import type {stringFunction as ImportJsValue_stringFunction} from './ImportJsValue.gen'; 12 | 13 | export const useGetProp: (x:ImportJsValue_AbsoluteValue_t) => number = UseImportJsValueBS.useGetProp; 14 | 15 | export const useTypeImportedInOtherModule: (x:ImportJsValue_stringFunction) => ImportJsValue_stringFunction = UseImportJsValueBS.useTypeImportedInOtherModule; 16 | -------------------------------------------------------------------------------- /examples/deadcode/src/UseImportJsValue.res: -------------------------------------------------------------------------------- 1 | @genType 2 | let useGetProp = (x: ImportJsValue.AbsoluteValue.t) => x->ImportJsValue.AbsoluteValue.getProp + 1 3 | 4 | @genType 5 | let useTypeImportedInOtherModule = (x: ImportJsValue.stringFunction) => x 6 | 7 | -------------------------------------------------------------------------------- /examples/deadcode/src/Variants.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function isWeekend(x) { 5 | if (x === "sunday") { 6 | return true; 7 | } else { 8 | return x === "saturday"; 9 | } 10 | } 11 | 12 | function onlySunday(param) { 13 | 14 | } 15 | 16 | function swap(x) { 17 | if (x === "sunday") { 18 | return "saturday"; 19 | } else { 20 | return "sunday"; 21 | } 22 | } 23 | 24 | function testConvert(x) { 25 | return x; 26 | } 27 | 28 | function testConvert2(x) { 29 | return x; 30 | } 31 | 32 | function testConvert3(x) { 33 | return x; 34 | } 35 | 36 | function testConvert2to3(x) { 37 | return x; 38 | } 39 | 40 | function id1(x) { 41 | return x; 42 | } 43 | 44 | function id2(x) { 45 | return x; 46 | } 47 | 48 | function polyWithOpt(foo) { 49 | if (foo === "bar") { 50 | return ; 51 | } else if (foo !== "baz") { 52 | return { 53 | NAME: "One", 54 | VAL: foo 55 | }; 56 | } else { 57 | return { 58 | NAME: "Two", 59 | VAL: 1 60 | }; 61 | } 62 | } 63 | 64 | function restResult1(x) { 65 | return x; 66 | } 67 | 68 | function restResult2(x) { 69 | return x; 70 | } 71 | 72 | function restResult3(x) { 73 | return x; 74 | } 75 | 76 | var monday = "monday"; 77 | 78 | var saturday = "saturday"; 79 | 80 | var sunday = "sunday"; 81 | 82 | var fortytwoOK = "fortytwo"; 83 | 84 | var fortytwoBAD = "fortytwo"; 85 | 86 | export { 87 | isWeekend , 88 | monday , 89 | saturday , 90 | sunday , 91 | onlySunday , 92 | swap , 93 | testConvert , 94 | fortytwoOK , 95 | fortytwoBAD , 96 | testConvert2 , 97 | testConvert3 , 98 | testConvert2to3 , 99 | id1 , 100 | id2 , 101 | polyWithOpt , 102 | restResult1 , 103 | restResult2 , 104 | restResult3 , 105 | } 106 | /* No side effect */ 107 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/Arr.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Belt_Array from "rescript/lib/es6/belt_Array.js"; 4 | 5 | function ff(a) { 6 | Belt_Array.get(a, 3); 7 | return 11; 8 | } 9 | 10 | var MM = { 11 | ff: ff 12 | }; 13 | 14 | var B; 15 | 16 | var $$Array; 17 | 18 | export { 19 | B , 20 | $$Array , 21 | MM , 22 | } 23 | /* No side effect */ 24 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/Arr.res: -------------------------------------------------------------------------------- 1 | module B = Belt 2 | module Array = B.Array 3 | 4 | module MM = { 5 | let ff = a => 6 | switch a[3] { 7 | | _ => 11 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/BeltTest.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Belt_Map from "rescript/lib/es6/belt_Map.js"; 4 | import * as Belt_List from "rescript/lib/es6/belt_List.js"; 5 | import * as Belt_MapInt from "rescript/lib/es6/belt_MapInt.js"; 6 | import * as Belt_MapString from "rescript/lib/es6/belt_MapString.js"; 7 | 8 | var lstHead1 = Belt_List.headExn; 9 | 10 | var lstHead2 = Belt_List.headExn; 11 | 12 | var mapGetExn1 = Belt_MapInt.getExn; 13 | 14 | var mapGetExn2 = Belt_MapInt.getExn; 15 | 16 | var mapGetExn3 = Belt_MapInt.getExn; 17 | 18 | var mapGetExn4 = Belt_MapString.getExn; 19 | 20 | var mapGetExn5 = Belt_MapString.getExn; 21 | 22 | var mapGetExn6 = Belt_MapString.getExn; 23 | 24 | var mapGetExn7 = Belt_Map.getExn; 25 | 26 | var mapGetExn8 = Belt_Map.getExn; 27 | 28 | export { 29 | lstHead1 , 30 | lstHead2 , 31 | mapGetExn1 , 32 | mapGetExn2 , 33 | mapGetExn3 , 34 | mapGetExn4 , 35 | mapGetExn5 , 36 | mapGetExn6 , 37 | mapGetExn7 , 38 | mapGetExn8 , 39 | } 40 | /* No side effect */ 41 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/BeltTest.res: -------------------------------------------------------------------------------- 1 | open Belt.List 2 | 3 | @raises(Not_found) 4 | let lstHead1 = l => l->Belt.List.headExn 5 | 6 | @raises(Not_found) 7 | let lstHead2 = l => l->Belt_List.headExn 8 | 9 | @raises(Not_found) 10 | let mapGetExn1 = (s, k) => s->Belt.Map.Int.getExn(k) 11 | 12 | @raises(Not_found) 13 | let mapGetExn2 = (s, k) => s->Belt_Map.Int.getExn(k) 14 | 15 | @raises(Not_found) 16 | let mapGetExn3 = (s, k) => s->Belt_MapInt.getExn(k) 17 | 18 | @raises(Not_found) 19 | let mapGetExn4 = (s, k) => s->Belt.Map.String.getExn(k) 20 | 21 | @raises(Not_found) 22 | let mapGetExn5 = (s, k) => s->Belt_Map.String.getExn(k) 23 | 24 | @raises(Not_found) 25 | let mapGetExn6 = (s, k) => s->Belt_MapString.getExn(k) 26 | 27 | @raises(Not_found) 28 | let mapGetExn7 = (s, k) => s->Belt.Map.getExn(k) 29 | 30 | @raises(Not_found) 31 | let mapGetExn8 = (s, k) => s->Belt_Map.getExn(k) 32 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/BsJson.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Json_decode from "@glennsl/bs-json/src/Json_decode.bs.js"; 4 | 5 | var testBsJson = Json_decode.string; 6 | 7 | var testBsJson2 = Json_decode.string; 8 | 9 | export { 10 | testBsJson , 11 | testBsJson2 , 12 | } 13 | /* No side effect */ 14 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/BsJson.res: -------------------------------------------------------------------------------- 1 | @raise(DecodeError) 2 | let testBsJson = x => Json_decode.string(x) 3 | 4 | @raise(DecodeError) 5 | let testBsJson2 = x => Json.Decode.string(x) 6 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/Exn.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js"; 4 | 5 | function raises(param) { 6 | throw { 7 | RE_EXN_ID: "Not_found", 8 | Error: new Error() 9 | }; 10 | } 11 | 12 | var catches1; 13 | 14 | try { 15 | catches1 = undefined; 16 | } 17 | catch (raw_exn){ 18 | var exn = Caml_js_exceptions.internalToOCamlException(raw_exn); 19 | if (exn.RE_EXN_ID === "Not_found") { 20 | catches1 = undefined; 21 | } else { 22 | throw exn; 23 | } 24 | } 25 | 26 | var catches2; 27 | 28 | try { 29 | catches2 = undefined; 30 | } 31 | catch (raw_exn$1){ 32 | var exn$1 = Caml_js_exceptions.internalToOCamlException(raw_exn$1); 33 | if (exn$1.RE_EXN_ID === "Not_found") { 34 | catches2 = undefined; 35 | } else { 36 | throw exn$1; 37 | } 38 | } 39 | 40 | var raiseAndCatch; 41 | 42 | try { 43 | throw { 44 | RE_EXN_ID: "Not_found", 45 | Error: new Error() 46 | }; 47 | } 48 | catch (exn$2){ 49 | raiseAndCatch = undefined; 50 | } 51 | 52 | function raisesWithAnnotaion(param) { 53 | throw { 54 | RE_EXN_ID: "Not_found", 55 | Error: new Error() 56 | }; 57 | } 58 | 59 | throw { 60 | RE_EXN_ID: "Not_found", 61 | Error: new Error() 62 | }; 63 | 64 | export { 65 | raises , 66 | catches1 , 67 | catches2 , 68 | raiseAndCatch , 69 | raisesWithAnnotaion , 70 | callsRaiseWithAnnotation , 71 | callsRaiseWithAnnotationAndIsAnnotated , 72 | z , 73 | incompleteMatch , 74 | A , 75 | B , 76 | twoRaises , 77 | sequencing , 78 | wrongCatch , 79 | C , 80 | wrongCatch2 , 81 | raise2Annotate3 , 82 | $$Error , 83 | parse_json_from_file , 84 | reRaise , 85 | switchWithCatchAll , 86 | raiseInInternalLet , 87 | indirectCall , 88 | array , 89 | id , 90 | tryChar , 91 | StringHash , 92 | specializedHash , 93 | genericHash , 94 | raiseAtAt , 95 | raisePipe , 96 | raiseArrow , 97 | bar , 98 | foo , 99 | stringMake1 , 100 | stringMake2 , 101 | stringMake3 , 102 | severalCases , 103 | genericRaiseIsNotSupported , 104 | redundant , 105 | redundant2 , 106 | redundant3 , 107 | redundant4 , 108 | exits , 109 | redundantAnnotation , 110 | _x , 111 | onFunction , 112 | onResult , 113 | onFunctionPipe , 114 | onResultPipeWrong , 115 | } 116 | /* catches1 Not a pure module */ 117 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/ExnA.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as ExnB from "./ExnB.bs.js"; 4 | 5 | function bar(param) { 6 | return ExnB.foo(undefined); 7 | } 8 | 9 | export { 10 | bar , 11 | } 12 | /* No side effect */ 13 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/ExnA.res: -------------------------------------------------------------------------------- 1 | let bar = () => ExnB.foo() 2 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/ExnB.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function foo(param) { 5 | throw { 6 | RE_EXN_ID: "Not_found", 7 | Error: new Error() 8 | }; 9 | } 10 | 11 | export { 12 | foo , 13 | } 14 | /* No side effect */ 15 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/ExnB.res: -------------------------------------------------------------------------------- 1 | @raises(Not_found) 2 | let foo = () => raise(Not_found) 3 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/ExportWithRename.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function ExportWithRename(Props) { 5 | return Props.s; 6 | } 7 | 8 | var make = ExportWithRename; 9 | 10 | export { 11 | make , 12 | } 13 | /* No side effect */ 14 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/ExportWithRename.gen.tsx: -------------------------------------------------------------------------------- 1 | /* TypeScript file generated from ExportWithRename.res by genType. */ 2 | /* eslint-disable import/first */ 3 | 4 | 5 | import * as React from 'react'; 6 | 7 | // @ts-ignore: Implicit any on import 8 | import * as ExportWithRenameBS__Es6Import from './ExportWithRename.bs'; 9 | const ExportWithRenameBS: any = ExportWithRenameBS__Es6Import; 10 | 11 | // tslint:disable-next-line:interface-over-type-literal 12 | export type Props = { readonly s: string }; 13 | 14 | export const ExportWithRename: React.ComponentType<{ readonly s: string }> = ExportWithRenameBS.make; 15 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/ExportWithRename.res: -------------------------------------------------------------------------------- 1 | @genType("ExportWithRename") @react.component 2 | let make = (~s) => React.string(s) 3 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/InnerModules.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Pervasives from "rescript/lib/es6/pervasives.js"; 4 | 5 | var wrapExitTop = Pervasives.exit; 6 | 7 | var wrapExitM1 = Pervasives.exit; 8 | 9 | var callLocally = Pervasives.exit; 10 | 11 | var callTop = Pervasives.exit; 12 | 13 | var wrapExitM2 = Pervasives.exit; 14 | 15 | var callM1 = Pervasives.exit; 16 | 17 | var callTop$1 = Pervasives.exit; 18 | 19 | var M2 = { 20 | wrapExitM2: wrapExitM2, 21 | callM1: callM1, 22 | callTop: callTop$1 23 | }; 24 | 25 | var M1 = { 26 | wrapExitM1: wrapExitM1, 27 | callLocally: callLocally, 28 | callTop: callTop, 29 | M2: M2 30 | }; 31 | 32 | var callM1$1 = Pervasives.exit; 33 | 34 | export { 35 | wrapExitTop , 36 | M1 , 37 | callM1$1 as callM1, 38 | } 39 | /* No side effect */ 40 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/InnerModules.res: -------------------------------------------------------------------------------- 1 | @raises(exit) 2 | let wrapExitTop = x => exit(x) 3 | 4 | module M1 = { 5 | @raises(exit) 6 | let wrapExitM1 = x => exit(x) 7 | 8 | @raises(exit) 9 | let callLocally = x => wrapExitM1(x) 10 | 11 | @raises(exit) 12 | let callTop = x => wrapExitTop(x) 13 | 14 | module M2 = { 15 | @raises(exit) 16 | let wrapExitM2 = x => exit(x) 17 | 18 | @raises(exit) 19 | let callM1 = x => wrapExitM1(x) 20 | 21 | @raises(exit) 22 | let callTop = x => wrapExitTop(x) 23 | } 24 | } 25 | 26 | @raises(exit) 27 | let callM1 = x => M1.wrapExitM1(x) 28 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/TestInnerModules.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Curry from "rescript/lib/es6/curry.js"; 4 | import * as InnerModules from "./InnerModules.bs.js"; 5 | 6 | var testTop = InnerModules.wrapExitTop; 7 | 8 | function testM1(x) { 9 | return InnerModules.M1.wrapExitM1(x); 10 | } 11 | 12 | function testM2(x) { 13 | return Curry._1(InnerModules.M1.M2.wrapExitM2, x); 14 | } 15 | 16 | export { 17 | testTop , 18 | testM1 , 19 | testM2 , 20 | } 21 | /* No side effect */ 22 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/TestInnerModules.res: -------------------------------------------------------------------------------- 1 | @raises(exit) 2 | let testTop = x => InnerModules.wrapExitTop(x) 3 | 4 | @raises(exit) 5 | let testM1 = x => InnerModules.M1.wrapExitM1(x) 6 | 7 | @raises(exit) 8 | let testM2 = x => InnerModules.M1.M2.wrapExitM2(x) 9 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/TestYojson.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Curry from "rescript/lib/es6/curry.js"; 4 | import * as Yojson from "./Yojson.bs.js"; 5 | import * as Caml_obj from "rescript/lib/es6/caml_obj.js"; 6 | import * as Caml_js_exceptions from "rescript/lib/es6/caml_js_exceptions.js"; 7 | 8 | function foo(x) { 9 | return Yojson.Basic.from_string(x); 10 | } 11 | 12 | function bar(str, json) { 13 | try { 14 | return Curry._2(Yojson.Basic.Util.member, str, json); 15 | } 16 | catch (raw_exn){ 17 | var exn = Caml_js_exceptions.internalToOCamlException(raw_exn); 18 | if (exn.RE_EXN_ID === Yojson.Basic.Util.Type_error) { 19 | if (exn._1 === "a") { 20 | if (Caml_obj.equal(exn._2, json)) { 21 | return json; 22 | } 23 | throw exn; 24 | } 25 | throw exn; 26 | } 27 | throw exn; 28 | } 29 | } 30 | 31 | function toString(x) { 32 | return Curry._1(Yojson.Basic.Util.to_string, x); 33 | } 34 | 35 | function toInt(x) { 36 | return Curry._1(Yojson.Basic.Util.to_int, x); 37 | } 38 | 39 | export { 40 | foo , 41 | bar , 42 | toString , 43 | toInt , 44 | } 45 | /* No side effect */ 46 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/TestYojson.res: -------------------------------------------------------------------------------- 1 | @raises(Yojson.Json_error) 2 | let foo = x => Yojson.Basic.from_string(x) 3 | 4 | let bar = (str, json) => 5 | switch { 6 | open Yojson.Basic.Util 7 | json |> member(str) 8 | } { 9 | | j => j 10 | | exception Yojson.Basic.Util.Type_error("a", d) when d == json => json 11 | } 12 | 13 | @raises(Yojson.Basic.Util.Type_error) 14 | let toString = x => Yojson.Basic.Util.to_string(x) 15 | 16 | @raises(Yojson.Basic.Util.Type_error) 17 | let toInt = x => Yojson.Basic.Util.to_int(x) 18 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/Yojson.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | import * as Caml_exceptions from "rescript/lib/es6/caml_exceptions.js"; 4 | 5 | var Json_error = /* @__PURE__ */Caml_exceptions.create("Yojson.Json_error"); 6 | 7 | function from_string(param) { 8 | throw { 9 | RE_EXN_ID: Json_error, 10 | _1: "Basic.from_string", 11 | Error: new Error() 12 | }; 13 | } 14 | 15 | var Type_error = /* @__PURE__ */Caml_exceptions.create("Yojson.Basic.Util.Type_error"); 16 | 17 | function member(_s, j) { 18 | throw { 19 | RE_EXN_ID: Type_error, 20 | _1: "Basic.Util.member", 21 | _2: j, 22 | Error: new Error() 23 | }; 24 | } 25 | 26 | function to_int(param) { 27 | return 34; 28 | } 29 | 30 | function to_string(param) { 31 | return ""; 32 | } 33 | 34 | var Util = { 35 | Type_error: Type_error, 36 | member: member, 37 | to_int: to_int, 38 | to_string: to_string 39 | }; 40 | 41 | var Basic = { 42 | from_string: from_string, 43 | Util: Util 44 | }; 45 | 46 | export { 47 | Json_error , 48 | Basic , 49 | } 50 | /* No side effect */ 51 | -------------------------------------------------------------------------------- /examples/deadcode/src/exception/Yojson.res: -------------------------------------------------------------------------------- 1 | exception Json_error(string) 2 | 3 | module Basic = { 4 | type t 5 | 6 | @raises(Json_error) 7 | let from_string: string => t = _ => raise(Json_error("Basic.from_string")) 8 | 9 | module Util = { 10 | exception Type_error(string, t) 11 | 12 | @raises(Type_error) 13 | let member: (string, t) => t = (_s, j) => raise(Type_error("Basic.Util.member", j)) 14 | 15 | let to_int: t => int = _ => 34 16 | 17 | let to_string: t => string = _ => "" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/deadcode/src/exportNestedValues.js: -------------------------------------------------------------------------------- 1 | /* @flow strict */ 2 | 3 | class InnerClass { 4 | static InnerStuff = { 5 | innerStuffContents: { x: 34 } 6 | }; 7 | } 8 | 9 | export class TopLevelClass { 10 | static MiddleLevelElements = { 11 | stuff: InnerClass 12 | }; 13 | } 14 | 15 | export const ValueStartingWithUpperCaseLetter = "ValueStartingWithUpperCaseLetter"; 16 | 17 | export default 42; -------------------------------------------------------------------------------- /examples/deadcode/src/noalloc/Chess.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | throw { 5 | RE_EXN_ID: "Assert_failure", 6 | _1: [ 7 | "Chess.res", 8 | 6, 9 | 56 10 | ], 11 | Error: new Error() 12 | }; 13 | 14 | export { 15 | computeScore , 16 | findNextMoves , 17 | makeMove , 18 | chess , 19 | } 20 | /* computeScore Not a pure module */ 21 | -------------------------------------------------------------------------------- /examples/deadcode/src/noalloc/Chess.res: -------------------------------------------------------------------------------- 1 | type pos // positions 2 | type board 3 | type score 4 | type move 5 | 6 | let computeScore: (~board: board, ~pos: pos) => score = assert false 7 | let findNextMoves: (~board: board, ~pos: pos) => list = assert false 8 | let makeMove: (move, ~board: board, ~pos: pos) => (board, pos) = assert false 9 | 10 | let rec chess = (~pos, ~board, ~n) => { 11 | if n == 0 { 12 | list{computeScore(~board, ~pos)} 13 | } else { 14 | let nextMoves = findNextMoves(~board, ~pos) 15 | nextMoves 16 | ->Belt.List.map(move => { 17 | let (nextBoard, nextPos) = makeMove(move, ~board, ~pos) 18 | 19 | @local 20 | chess(~board=nextBoard, ~pos=nextPos, ~n=n - 1) 21 | }) 22 | ->Belt.List.flatten 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /examples/deadcode/src/noalloc/Matrix.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function sumVec(v) { 5 | var match = v[1]; 6 | var match$1 = v[0]; 7 | return [ 8 | match$1[0] + match[0] | 0, 9 | match$1[1] + match[1] | 0 10 | ]; 11 | } 12 | 13 | function rotation(a) { 14 | return [ 15 | [ 16 | 0.0, 17 | -1.0 * a, 18 | 0.0 19 | ], 20 | [ 21 | a, 22 | 0.0, 23 | 0.0 24 | ], 25 | [ 26 | 0.0, 27 | 0.0, 28 | a 29 | ] 30 | ]; 31 | } 32 | 33 | function mulVecVec(v1, v2) { 34 | var x = v1[0] * v2[0]; 35 | var y = v1[1] * v2[1]; 36 | var z = v1[2] * v2[2]; 37 | return x + y + z; 38 | } 39 | 40 | function mulMatVec(m, v) { 41 | var x = mulVecVec(m[0], v); 42 | var y = mulVecVec(m[1], v); 43 | var z = mulVecVec(m[2], v); 44 | return [ 45 | x, 46 | y, 47 | z 48 | ]; 49 | } 50 | 51 | function scale(s) { 52 | return [ 53 | [ 54 | s, 55 | 1.0, 56 | 1.0 57 | ], 58 | [ 59 | 1.0, 60 | s, 61 | 1.0 62 | ], 63 | [ 64 | 1.0, 65 | 1.0, 66 | s 67 | ] 68 | ]; 69 | } 70 | 71 | function restMatrix(v) { 72 | return mulMatVec(rotation(0.123), mulMatVec(scale(2.0), v)); 73 | } 74 | 75 | var scale2 = [ 76 | [ 77 | 2.0, 78 | 1.0, 79 | 1.0 80 | ], 81 | [ 82 | 1.0, 83 | 2.0, 84 | 1.0 85 | ], 86 | [ 87 | 1.0, 88 | 1.0, 89 | 2.0 90 | ] 91 | ]; 92 | 93 | function restMatrix2(v) { 94 | return mulMatVec(rotation(0.123), mulMatVec(scale2, v)); 95 | } 96 | 97 | export { 98 | sumVec , 99 | rotation , 100 | mulVecVec , 101 | mulMatVec , 102 | scale , 103 | restMatrix , 104 | scale2 , 105 | restMatrix2 , 106 | } 107 | /* No side effect */ 108 | -------------------------------------------------------------------------------- /examples/deadcode/src/noalloc/Matrix.res: -------------------------------------------------------------------------------- 1 | @noalloc 2 | let sumVec = v => { 3 | let ((x1, x2), (y1, y2)) = v 4 | (x1 + y1, x2 + y2) 5 | } 6 | 7 | @noalloc 8 | let rotation = a => ((0.0, -1.0 *. a, 0.0), (a, 0.0, 0.0), (0.0, 0.0, a)) 9 | 10 | @noalloc 11 | let mulVecVec = (v1, v2) => { 12 | let (x1, y1, z1) = v1 13 | let (x2, y2, z2) = v2 14 | let x = x1 *. x2 15 | let y = y1 *. y2 16 | let z = z1 *. z2 17 | x +. y +. z 18 | } 19 | 20 | @noalloc 21 | let mulMatVec = (m, v) => { 22 | let (row1, row2, row3) = m 23 | let x = mulVecVec(row1, v) 24 | let y = mulVecVec(row2, v) 25 | let z = mulVecVec(row3, v) 26 | (x, y, z) 27 | } 28 | 29 | @noalloc 30 | let scale = s => ((s, 1.0, 1.0), (1.0, s, 1.0), (1.0, 1.0, s)) 31 | 32 | @noalloc 33 | let restMatrix = v => mulMatVec(rotation(0.123), mulMatVec(scale(2.0), v)) 34 | 35 | @noalloc 36 | let scale2 = ((2.0, 1.0, 1.0), (1.0, 2.0, 1.0), (1.0, 1.0, 2.0)) 37 | 38 | @noalloc 39 | let restMatrix2 = v => mulMatVec(rotation(0.123), mulMatVec(scale2, v)) 40 | -------------------------------------------------------------------------------- /examples/deadcode/src/noalloc/TestNoalloc.bs.js: -------------------------------------------------------------------------------- 1 | // Generated by ReScript, PLEASE EDIT WITH CARE 2 | 3 | 4 | function foo(x, y) { 5 | return x + y | 0; 6 | } 7 | 8 | function bar(x) { 9 | return (x + x | 0) + 1 | 0; 10 | } 11 | 12 | function pair(x, y) { 13 | return [ 14 | x, 15 | y 16 | ]; 17 | } 18 | 19 | function unpair(param) { 20 | return param[0] + param[1] | 0; 21 | } 22 | 23 | function mixed(param, param$1) { 24 | var match = param$1[1]; 25 | var match$1 = match[2]; 26 | return [ 27 | (param[0] + param[1] | 0) + param[2] | 0, 28 | (((((param$1[0] + match[0] | 0) + match[1] | 0) + match$1[0] | 0) + match$1[1] | 0) + match$1[2] | 0) + param$1[2] | 0 29 | ]; 30 | } 31 | 32 | function duplicate(x) { 33 | return [ 34 | x, 35 | x 36 | ]; 37 | } 38 | 39 | function local(n) { 40 | return 34 + n | 0; 41 | } 42 | 43 | function quad(x) { 44 | var a_1 = x + 1 | 0; 45 | var a = [ 46 | x, 47 | a_1 48 | ]; 49 | return [ 50 | a, 51 | a 52 | ]; 53 | } 54 | 55 | function unpair2(v) { 56 | return v[0] + v[1] | 0; 57 | } 58 | 59 | function id(x) { 60 | return x; 61 | } 62 | 63 | function id2(x) { 64 | return x; 65 | } 66 | 67 | function retGlobal(param) { 68 | return 35; 69 | } 70 | 71 | function extractFromGlobalTuple(param) { 72 | return 1; 73 | } 74 | 75 | function recordCreation(param) { 76 | return [ 77 | 3, 78 | "abcd" 79 | ]; 80 | } 81 | 82 | var x = 34; 83 | 84 | var fl = 2; 85 | 86 | var y = 34; 87 | 88 | var globalTuple = [ 89 | 1, 90 | 2, 91 | 3 92 | ]; 93 | 94 | export { 95 | x , 96 | foo , 97 | bar , 98 | pair , 99 | unpair , 100 | mixed , 101 | duplicate , 102 | local , 103 | quad , 104 | fl , 105 | unpair2 , 106 | id , 107 | id2 , 108 | y , 109 | retGlobal , 110 | globalTuple , 111 | extractFromGlobalTuple , 112 | recordCreation , 113 | } 114 | /* No side effect */ 115 | -------------------------------------------------------------------------------- /examples/deadcode/src/noalloc/TestNoalloc.res: -------------------------------------------------------------------------------- 1 | @noalloc 2 | let x = 34 3 | 4 | @noalloc 5 | let foo = (x, y) => x + y 6 | 7 | @noalloc 8 | let bar = x => foo(x, x) + 1 9 | 10 | @noalloc 11 | let pair = (x, y) => (x, y) 12 | 13 | @noalloc 14 | let unpair = ((x, y)) => x + y 15 | 16 | @noalloc 17 | let mixed = ((p0, p1, p2), (p3, (p4, p5, (p6, p7, p8)), p9)) => ( 18 | p0 + p1 + p2, 19 | p3 + p4 + p5 + p6 + p7 + p8 + p9, 20 | ) 21 | 22 | @noalloc 23 | let duplicate = (x: (int, int)) => (x, x) 24 | 25 | @noalloc 26 | let local = n => { 27 | let a = 34 28 | a + n 29 | } 30 | 31 | @noalloc 32 | let quad = x => { 33 | let a = (x, x + 1) 34 | (a, a) 35 | } 36 | 37 | @noalloc 38 | let fl = 2. 39 | 40 | @noalloc 41 | let unpair2 = v => { 42 | let (x, y) = v 43 | x + y 44 | } 45 | 46 | @noalloc 47 | let id = x => x 48 | 49 | @noalloc 50 | let id2 = (x: (int, int)) => id(x) 51 | 52 | @noalloc 53 | let y = x 54 | 55 | @noalloc 56 | let retGlobal = () => y + 1 57 | 58 | @noalloc 59 | let globalTuple = (1, 2, 3) 60 | 61 | @noalloc 62 | let extractFromGlobalTuple = () => { 63 | let (x, _, _) = globalTuple 64 | x 65 | } 66 | 67 | type r = {x: int, y: int, name: string} 68 | 69 | @noalloc 70 | let recordCreation = () => { 71 | let r = {x: 3, y: 4, name: "abcd"} 72 | (r.x, r.name) 73 | } 74 | -------------------------------------------------------------------------------- /examples/termination/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | 6 | # testing 7 | /coverage 8 | 9 | # production 10 | /build 11 | 12 | # misc 13 | .DS_Store 14 | .env.local 15 | .env.development.local 16 | .env.test.local 17 | .env.production.local 18 | 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | -------------------------------------------------------------------------------- /examples/termination/.watchmanconfig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rescript-lang/reanalyze/650bd42a933feb3f7b9631a85b6910d8e7a97839/examples/termination/.watchmanconfig -------------------------------------------------------------------------------- /examples/termination/Makefile: -------------------------------------------------------------------------------- 1 | build: 2 | ./node_modules/.bin/bsb -make-world 3 | clean: 4 | ./node_modules/.bin/bsb -clean 5 | 6 | test: build 7 | time ../reanalyze.exe -termination >deadcode.txt 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /examples/termination/bsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "reanalyze": { 3 | "analysis": ["termination"], 4 | "suppress": [], 5 | "unsuppress": [] 6 | }, 7 | "name": "arnold", 8 | "bsc-flags": ["-bs-super-errors"], 9 | "reason": { "react-jsx": 3 }, 10 | "bs-dependencies": [], 11 | "sources": [ 12 | { 13 | "dir": "src", 14 | "subdirs": true 15 | } 16 | ], 17 | "package-specs": { 18 | "module": "es6", 19 | "in-source": true 20 | }, 21 | "suffix": ".bs.js" 22 | } 23 | -------------------------------------------------------------------------------- /examples/termination/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "termination", 3 | "version": "0.1.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "termination", 9 | "version": "0.1.0", 10 | "dependencies": { 11 | "reanalyze": "file:../.." 12 | }, 13 | "devDependencies": { 14 | "gentype": "^4.4.0", 15 | "rescript": "^9.1.4" 16 | } 17 | }, 18 | "../..": { 19 | "version": "2.21.0", 20 | "license": "MIT", 21 | "bin": { 22 | "reanalyze.exe": "_build/install/default/bin/reanalyze.exe" 23 | } 24 | }, 25 | "node_modules/gentype": { 26 | "version": "4.4.0", 27 | "resolved": "https://registry.npmjs.org/gentype/-/gentype-4.4.0.tgz", 28 | "integrity": "sha512-hLcKmMhD3DJzHffDqwYUkEZfdGSWJk6ehYmdzGHBs35mTJa2dhiAp31WqmhjkZIqKvD+A+gFEE+//QHG5dZfwg==", 29 | "dev": true, 30 | "hasInstallScript": true, 31 | "bin": { 32 | "gentype": "gentype.exe" 33 | } 34 | }, 35 | "node_modules/reanalyze": { 36 | "resolved": "../..", 37 | "link": true 38 | }, 39 | "node_modules/rescript": { 40 | "version": "9.1.4", 41 | "resolved": "https://registry.npmjs.org/rescript/-/rescript-9.1.4.tgz", 42 | "integrity": "sha512-aXANK4IqecJzdnDpJUsU6pxMViCR5ogAxzuqS0mOr8TloMnzAjJFu63fjD6LCkWrKAhlMkFFzQvVQYaAaVkFXw==", 43 | "dev": true, 44 | "hasInstallScript": true, 45 | "bin": { 46 | "bsc": "bsc", 47 | "bsrefmt": "bsrefmt", 48 | "bstracing": "lib/bstracing", 49 | "rescript": "rescript" 50 | } 51 | } 52 | }, 53 | "dependencies": { 54 | "gentype": { 55 | "version": "4.4.0", 56 | "resolved": "https://registry.npmjs.org/gentype/-/gentype-4.4.0.tgz", 57 | "integrity": "sha512-hLcKmMhD3DJzHffDqwYUkEZfdGSWJk6ehYmdzGHBs35mTJa2dhiAp31WqmhjkZIqKvD+A+gFEE+//QHG5dZfwg==", 58 | "dev": true 59 | }, 60 | "reanalyze": { 61 | "version": "file:../.." 62 | }, 63 | "rescript": { 64 | "version": "9.1.4", 65 | "resolved": "https://registry.npmjs.org/rescript/-/rescript-9.1.4.tgz", 66 | "integrity": "sha512-aXANK4IqecJzdnDpJUsU6pxMViCR5ogAxzuqS0mOr8TloMnzAjJFu63fjD6LCkWrKAhlMkFFzQvVQYaAaVkFXw==", 67 | "dev": true 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /examples/termination/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "termination", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "start": "rescript build -w", 7 | "build": "rescript build", 8 | "clean": "rescript clean -with-deps", 9 | "analyze": "npx reanalyze.exe -config -ci -debug >src/termination.txt" 10 | }, 11 | "devDependencies": { 12 | "gentype": "^4.4.0", 13 | "rescript": "^9.1.4" 14 | }, 15 | "dependencies": { 16 | "reanalyze": "file:../.." 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lazyload-ppx/dune: -------------------------------------------------------------------------------- 1 | (executable 2 | (name LazyLoad) 3 | (public_name lazyLoad.exe) 4 | (preprocess 5 | (action 6 | (run %{bin:cppo} -V OCAML:%{ocaml_version} %{input-file}))) 7 | (libraries compilerlibs406) 8 | (flags 9 | (:standard -w -9))) 10 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "reanalyze", 3 | "version": "2.25.1", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "reanalyze", 9 | "version": "2.25.1", 10 | "license": "MIT", 11 | "bin": { 12 | "reanalyze.exe": "_build/install/default/bin/reanalyze.exe" 13 | } 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "reanalyze", 3 | "version": "2.25.1", 4 | "private": true, 5 | "description": "Analyzers for Dead Code/Types and termination", 6 | "license": "MIT", 7 | "scripts": { 8 | "build": "dune build", 9 | "build406": "cp src/dune src/dune.saved && cp src/dune.406 src/dune && npm run build && mv src/dune.saved src/dune || mv src/dune.saved src/dune", 10 | "clean": "dune clean -p reanalyze", 11 | "test": "node ./scripts/run_integration_tests.js", 12 | "install:examples": "(cd examples/deadcode && npm install) & (cd examples/termination && npm install)", 13 | "build:examples": "(cd examples/deadcode && npm run clean && npm run build && npm run analyze) & (cd examples/termination && npm run clean && npm run build && npm run analyze)", 14 | "dce": "dune build && dune exec reanalyze.exe -- -suppress dead-code-ppx,src/compiler-libs-406 -unsuppress doesnotexist -dce-cmt _build", 15 | "exception": "dune build && dune exec reanalyze.exe -- -exclude-paths src/compiler-libs-406/parser.ml -suppress src/ext,src/compiler-libs-406 -exception-cmt _build", 16 | "preversion": "npm test", 17 | "version": "node scripts/bump_version_module.js && git add -A src/", 18 | "postversion": "git push && git push --tags" 19 | }, 20 | "bin": { 21 | "reanalyze.exe": "./_build/install/default/bin/reanalyze.exe" 22 | }, 23 | "author": "Cristiano Calcagno", 24 | "keywords": [ 25 | "rescript", 26 | "tooling" 27 | ], 28 | "bugs": { 29 | "url": "https://github.com/cristianoc/reanalyze/issues" 30 | }, 31 | "homepage": "https://github.com/cristianoc/reanalyze#readme" 32 | } 33 | -------------------------------------------------------------------------------- /reanalyze.opam: -------------------------------------------------------------------------------- 1 | opam-version: "2.0" 2 | synopsis: "Dead values/types, exception, and termination analysis for OCaml/ReScript" 3 | description: """ 4 | Experimental analyses for ReScript/OCaml/Reason: for globally dead values/types, exception analysis, and termination analysis. 5 | """ 6 | maintainer: ["Cristiano Calcagno"] 7 | authors: ["Cristiano Calcagno"] 8 | license: "MIT" 9 | homepage: "https://github.com/rescript-association/reanalyze" 10 | bug-reports: "https://github.com/rescript-association/reanalyze/issues" 11 | depends: [ 12 | "dune" {>= "2.0"} 13 | "ocaml" {>= "4.08.0" & < "5.3"} 14 | "cppo" {build} 15 | ] 16 | build: [ 17 | ["dune" "subst"] {dev} 18 | [ 19 | "dune" 20 | "build" 21 | "-p" 22 | name 23 | "-j" 24 | jobs 25 | "@install" 26 | "@runtest" {with-test} 27 | "@doc" {with-doc} 28 | ] 29 | ] 30 | dev-repo: "git+https://github.com/rescript-association/reanalyze.git" 31 | -------------------------------------------------------------------------------- /scripts/bump_version_module.js: -------------------------------------------------------------------------------- 1 | const fs = require("fs"); 2 | const pjson = require("../package.json"); 3 | const path = require("path"); 4 | 5 | const targetFile = path.join(__dirname, "..", "src", "Version.ml"); 6 | 7 | const content = ` 8 | (* CREATED BY reanalyze/scripts/bump_version_module.js *) 9 | (* DO NOT MODIFY BY HAND, WILL BE AUTOMATICALLY UPDATED BY npm version *) 10 | 11 | let version = "${pjson.version}"; 12 | `; 13 | 14 | fs.writeFileSync(targetFile, content, "utf8"); 15 | -------------------------------------------------------------------------------- /scripts/download_dist.js: -------------------------------------------------------------------------------- 1 | /* 2 | PLEASE NOTE: 3 | This script is intended to be used on unix-like systems and used for publishing npm packages. 4 | */ 5 | 6 | const child_process = require("child_process"); 7 | const pjson = require("../package.json"); 8 | const path = require("path"); 9 | 10 | const projectRoot = path.join(__dirname, ".."); 11 | 12 | const filename = `reanalyze-v${pjson.version}.tgz`; 13 | 14 | const targetLink = (version) => 15 | `https://github.com/cristianoc/reanalyze/releases/download/v${version}/${filename}`; 16 | 17 | const target = targetLink(pjson.version); 18 | 19 | console.log(`Download release: "${target}" ...`); 20 | try { 21 | child_process.execSync( 22 | `curl -f -O -L ${target}`, 23 | { stdio: [0, 1, 2] } 24 | ); 25 | console.log(`File downloaded to ${projectRoot}/${filename}`); 26 | console.log("------------"); 27 | console.log(`Run \`npm publish ${filename} --dry-run\` before release!`); 28 | console.log("------------"); 29 | } catch (e) { 30 | console.error( 31 | `Download failed... Is the package ${filename} actually released?` 32 | ); 33 | console.error(e); 34 | process.exit(1); 35 | } 36 | -------------------------------------------------------------------------------- /scripts/prepare_release.js: -------------------------------------------------------------------------------- 1 | // This script will prepare the dist/ folder by adding the right meta 2 | // data such as the package.json, LICENSE and README file 3 | 4 | const fs = require("fs"); 5 | const path = require("path"); 6 | 7 | console.log("Creating package.json"); 8 | 9 | if (!fs.existsSync('package.json')) { 10 | console.error("No package.json in project root found"); 11 | process.exit(1); 12 | } 13 | 14 | // We need that for the package metadata 15 | const pjson = require(path.join('..', 'package.json')); 16 | 17 | const packageJson = JSON.stringify( 18 | { 19 | name: pjson.name, 20 | version: pjson.version, 21 | author: pjson.author, 22 | bugs: pjson.bugs, 23 | homepage: pjson.homepage, 24 | license: pjson.license, 25 | description: pjson.description, 26 | repository: pjson.repository, 27 | scripts: { 28 | postinstall: "node ./postinstall.js" 29 | }, 30 | bin: { "reanalyze": "reanalyze.exe" }, 31 | files: [ 32 | // Dummy file 33 | "reanalyze.exe", 34 | "postinstall.js", 35 | "vendor-linux/", 36 | "vendor-darwin/", 37 | "vendor-darwinarm64/", 38 | "vendor-win32/", 39 | ], 40 | }, 41 | null, 42 | 2 43 | ); 44 | 45 | fs.writeFileSync( 46 | path.join(__dirname, "..", "dist", "package.json"), 47 | packageJson, 48 | { 49 | encoding: "utf8" 50 | } 51 | ); 52 | 53 | try { 54 | console.log("Copying LICENSE"); 55 | fs.copyFileSync( 56 | path.join(__dirname, "..", "LICENSE"), 57 | path.join(__dirname, "..", "dist", "LICENSE") 58 | ); 59 | } catch (e) { 60 | console.warn("No LICENSE found"); 61 | } 62 | 63 | console.log("Copying README.md"); 64 | fs.copyFileSync( 65 | path.join(__dirname, "..", "README.md"), 66 | path.join(__dirname, "..", "dist", "README.md") 67 | ); 68 | -------------------------------------------------------------------------------- /src/CL.ml: -------------------------------------------------------------------------------- 1 | (* Compiler libs: use the host compiler libs except on 4.06 use vendored ones. 2 | This allows to target 4.06 on any compiler by overriding OCAML_VERSION. *) 3 | 4 | #if OCAML_VERSION <= (4, 06, 1) 5 | include Compilerlibs406 6 | #else 7 | module Asttypes = Asttypes 8 | module Cmt_format = Cmt_format 9 | module Ident = Ident 10 | module Location = Location 11 | module Longident = Longident 12 | module Misc = Misc 13 | module Parsetree = Parsetree 14 | module Path = Path 15 | module Tast_mapper = Tast_mapper 16 | module Typedtree = Typedtree 17 | module Types = Types 18 | #endif 19 | -------------------------------------------------------------------------------- /src/DeadCode.ml: -------------------------------------------------------------------------------- 1 | open DeadCommon 2 | 3 | let processSignature ~doValues ~doTypes (signature : CL.Types.signature) = 4 | signature 5 | |> List.iter (fun sig_item -> 6 | DeadValue.processSignatureItem ~doValues ~doTypes 7 | ~moduleLoc:CL.Location.none 8 | ~path:[!Common.currentModuleName] 9 | sig_item) 10 | 11 | let processCmt ~cmtFilePath (cmt_infos : CL.Cmt_format.cmt_infos) = 12 | (match cmt_infos.cmt_annots with 13 | | Interface signature -> 14 | ProcessDeadAnnotations.signature signature; 15 | processSignature ~doValues:true ~doTypes:true signature.sig_type 16 | | Implementation structure -> 17 | let cmtiExists = 18 | Sys.file_exists ((cmtFilePath |> Filename.remove_extension) ^ ".cmti") 19 | in 20 | ProcessDeadAnnotations.structure ~doGenType:(not cmtiExists) structure; 21 | processSignature ~doValues:true ~doTypes:false structure.str_type; 22 | let doExternals = 23 | (* This is already handled at the interface level, avoid issues in inconsistent locations 24 | https://github.com/BuckleScript/syntax/pull/54 25 | Ideally, the handling should be less location-based, just like other language aspects. *) 26 | false 27 | in 28 | DeadValue.processStructure ~doTypes:true ~doExternals 29 | ~cmt_value_dependencies:cmt_infos.cmt_value_dependencies structure 30 | | _ -> ()); 31 | DeadType.TypeDependencies.forceDelayedItems (); 32 | DeadType.TypeDependencies.clear () 33 | -------------------------------------------------------------------------------- /src/DeadException.ml: -------------------------------------------------------------------------------- 1 | open DeadCommon 2 | open Common 3 | 4 | type item = {exceptionPath : Path.t; locFrom : CL.Location.t} 5 | 6 | let delayedItems = ref [] 7 | let declarations = Hashtbl.create 1 8 | 9 | let add ~path ~loc ~(strLoc : CL.Location.t) name = 10 | let exceptionPath = name :: path in 11 | Hashtbl.add declarations exceptionPath loc; 12 | name 13 | |> addDeclaration_ ~posEnd:strLoc.loc_end ~posStart:strLoc.loc_start 14 | ~declKind:Exception ~moduleLoc:(ModulePath.getCurrent ()).loc ~path ~loc 15 | 16 | let forceDelayedItems () = 17 | let items = !delayedItems |> List.rev in 18 | delayedItems := []; 19 | items 20 | |> List.iter (fun {exceptionPath; locFrom} -> 21 | match Hashtbl.find_opt declarations exceptionPath with 22 | | None -> () 23 | | Some locTo -> 24 | addValueReference ~addFileReference:true ~locFrom ~locTo) 25 | 26 | let markAsUsed ~(locFrom : CL.Location.t) ~(locTo : CL.Location.t) path_ = 27 | if locTo.loc_ghost then 28 | (* Probably defined in another file, delay processing and check at the end *) 29 | let exceptionPath = 30 | path_ |> Path.fromPathT |> Path.moduleToImplementation 31 | in 32 | delayedItems := {exceptionPath; locFrom} :: !delayedItems 33 | else addValueReference ~addFileReference:true ~locFrom ~locTo 34 | -------------------------------------------------------------------------------- /src/DeadModules.ml: -------------------------------------------------------------------------------- 1 | let active () = true 2 | 3 | let table = Hashtbl.create 1 4 | 5 | let markDead ~isType ~loc path = 6 | if active () then 7 | let moduleName = path |> Common.Path.toModuleName ~isType in 8 | match Hashtbl.find_opt table moduleName with 9 | | Some _ -> () 10 | | _ -> Hashtbl.replace table moduleName (false, loc) 11 | 12 | let markLive ~isType ~(loc : CL.Location.t) path = 13 | if active () then 14 | let moduleName = path |> Common.Path.toModuleName ~isType in 15 | match Hashtbl.find_opt table moduleName with 16 | | None -> Hashtbl.replace table moduleName (true, loc) 17 | | Some (false, loc) -> Hashtbl.replace table moduleName (true, loc) 18 | | Some (true, _) -> () 19 | 20 | let checkModuleDead ~fileName:pos_fname moduleName = 21 | if active () then 22 | match Hashtbl.find_opt table moduleName with 23 | | Some (false, loc) -> 24 | Hashtbl.remove table moduleName; 25 | (* only report once *) 26 | let loc = 27 | if loc.loc_ghost then 28 | let pos = 29 | {Lexing.pos_fname; pos_lnum = 0; pos_bol = 0; pos_cnum = 0} 30 | in 31 | {CL.Location.loc_start = pos; loc_end = pos; loc_ghost = false} 32 | else loc 33 | in 34 | Log_.warning ~loc ~name:"Warning Dead Module" (fun ppf () -> 35 | Format.fprintf ppf "@{%s@} %s" moduleName 36 | "is a dead module as all its items are dead.") 37 | | _ -> () 38 | -------------------------------------------------------------------------------- /src/EmitJson.ml: -------------------------------------------------------------------------------- 1 | let items = ref 0 2 | 3 | let start () = Format.fprintf Format.std_formatter "[" 4 | 5 | let finish () = Format.fprintf Format.std_formatter "\n]@." 6 | 7 | let emitClose () = Format.fprintf Format.std_formatter "\n}" 8 | 9 | let emitItem ~name ~kind ~file ~range ~message = 10 | let open Format in 11 | items := !items + 1; 12 | let ppf = std_formatter in 13 | let startLine, startCharacter, endLine, endCharacter = range in 14 | fprintf ppf "%s{\n" (if !items = 1 then "\n" else ",\n"); 15 | fprintf ppf " \"name\": \"%s\",\n" name; 16 | fprintf ppf " \"kind\": \"%s\",\n" kind; 17 | fprintf ppf " \"file\": \"%s\",\n" file; 18 | fprintf ppf " \"range\": [%d,%d,%d,%d],\n" startLine startCharacter endLine 19 | endCharacter; 20 | fprintf ppf " \"message\": \"%s\"" message 21 | 22 | let locToPos (loc : CL.Location.t) = 23 | (loc.loc_start.pos_lnum - 1, loc.loc_start.pos_cnum - loc.loc_start.pos_bol) 24 | 25 | let emitAnnotate ~pos ~text ~action = 26 | let line, character = pos in 27 | Format.fprintf Format.std_formatter 28 | ",\n\ 29 | \ \"annotate\": { \"line\": %d, \"character\": %d, \"text\": \"%s\", \ 30 | \"action\": \"%s\"}" 31 | line character text action 32 | -------------------------------------------------------------------------------- /src/Exceptions.ml: -------------------------------------------------------------------------------- 1 | open Common 2 | module ExnSet = Set.Make (Exn) 3 | 4 | type t = ExnSet.t 5 | 6 | let add = ExnSet.add 7 | 8 | let diff = ExnSet.diff 9 | 10 | let empty = ExnSet.empty 11 | 12 | let fromList = ExnSet.of_list 13 | 14 | let toList = ExnSet.elements 15 | 16 | let isEmpty = ExnSet.is_empty 17 | 18 | let iter = ExnSet.iter 19 | 20 | let union = ExnSet.union 21 | 22 | let pp ~exnTable ppf exceptions = 23 | let isFirst = ref true in 24 | let ppExn exn = 25 | let separator = if !isFirst then "" else ", " in 26 | isFirst := false; 27 | let name = Exn.toString exn in 28 | match exnTable with 29 | | Some exnTable -> ( 30 | match Hashtbl.find_opt exnTable exn with 31 | | Some locSet -> 32 | let positions = 33 | locSet |> Common.LocSet.elements 34 | |> List.map (fun loc -> loc.CL.Location.loc_start) 35 | in 36 | Format.fprintf ppf "%s@{%s@} (@{%s@})" separator name 37 | (positions |> List.map posToString |> String.concat " ") 38 | | None -> Format.fprintf ppf "%s@{%s@}" separator name) 39 | | None -> Format.fprintf ppf "%s@{%s@}" separator name 40 | in 41 | let isList = exceptions |> ExnSet.cardinal > 1 in 42 | if isList then Format.fprintf ppf "["; 43 | exceptions |> ExnSet.iter ppExn; 44 | if isList then Format.fprintf ppf "]" 45 | -------------------------------------------------------------------------------- /src/Exceptions.mli: -------------------------------------------------------------------------------- 1 | type t 2 | val add : Exn.t -> t -> t 3 | val diff : t -> t -> t 4 | val empty : t 5 | val isEmpty : t -> bool 6 | val iter : (Exn.t -> unit) -> t -> unit 7 | val fromList : Exn.t list -> t 8 | val pp : 9 | exnTable:(Exn.t, Common.LocSet.t) Hashtbl.t option -> 10 | Format.formatter -> t -> unit 11 | val toList : t -> Exn.t list 12 | val union : t -> t -> t -------------------------------------------------------------------------------- /src/Exn.ml: -------------------------------------------------------------------------------- 1 | type t = string 2 | 3 | let compare = String.compare 4 | let decodeError = "DecodeError" 5 | let assertFailure = "Assert_failure" 6 | let divisionByZero = "Division_by_zero" 7 | let endOfFile = "End_of_file" 8 | let exit = "exit" 9 | let failure = "Failure" 10 | let invalidArgument = "Invalid_argument" 11 | let jsExnError = "Js.Exn.Error" 12 | let matchFailure = "Match_failure" 13 | let notFound = "Not_found" 14 | let sysError = "Sys_error" 15 | let fromLid lid = lid |> CL.Longident.flatten |> String.concat "." 16 | let fromString s = s 17 | let toString s = s 18 | let yojsonJsonError = "Yojson.Json_error" 19 | let yojsonTypeError = "Yojson.Basic.Util.Type_error" -------------------------------------------------------------------------------- /src/Exn.mli: -------------------------------------------------------------------------------- 1 | type t 2 | 3 | val compare : t -> t -> int 4 | val assertFailure : t 5 | val decodeError : t 6 | val divisionByZero : t 7 | val endOfFile : t 8 | val exit : t 9 | val failure : t 10 | val fromLid : CL.Longident.t -> t 11 | val fromString : string -> t 12 | val invalidArgument : t 13 | val jsExnError : t 14 | val matchFailure : t 15 | val notFound : t 16 | val sysError : t 17 | val toString : t -> string 18 | val yojsonJsonError : t 19 | val yojsonTypeError : t -------------------------------------------------------------------------------- /src/FindSourceFile.ml: -------------------------------------------------------------------------------- 1 | (** Prepend nativeBuildTarget to fname when provided (-native-build-target) *) 2 | let nativeFilePath fname = 3 | match !Common.Cli.nativeBuildTarget with 4 | | None -> fname 5 | | Some nativeBuildTarget -> Filename.concat nativeBuildTarget fname 6 | 7 | let rec interface items = 8 | match items with 9 | | {CL.Typedtree.sig_loc} :: rest -> ( 10 | match 11 | not (Sys.file_exists (nativeFilePath sig_loc.loc_start.pos_fname)) 12 | with 13 | | true -> interface rest 14 | | false -> Some sig_loc.loc_start.pos_fname) 15 | | [] -> None 16 | 17 | let rec implementation items = 18 | match items with 19 | | {CL.Typedtree.str_loc} :: rest -> ( 20 | match 21 | not (Sys.file_exists (nativeFilePath str_loc.loc_start.pos_fname)) 22 | with 23 | | true -> implementation rest 24 | | false -> Some str_loc.loc_start.pos_fname) 25 | | [] -> None 26 | 27 | let cmt cmt_annots = 28 | match cmt_annots with 29 | | CL.Cmt_format.Interface signature -> 30 | if !Common.Cli.debug && signature.sig_items = [] then 31 | Log_.item "Interface %d@." (signature.sig_items |> List.length); 32 | interface signature.sig_items 33 | | Implementation structure -> 34 | if !Common.Cli.debug && structure.str_items = [] then 35 | Log_.item "Implementation %d@." (structure.str_items |> List.length); 36 | implementation structure.str_items 37 | | _ -> None 38 | -------------------------------------------------------------------------------- /src/ModulePath.ml: -------------------------------------------------------------------------------- 1 | open Common 2 | module NameMap = Map.Make (Name) 3 | 4 | (* Keep track of the module path while traversing with Tast_mapper *) 5 | type t = {aliases : Path.t NameMap.t; loc : CL.Location.t; path : Path.t} 6 | 7 | let initial = ({aliases = NameMap.empty; loc = CL.Location.none; path = []} : t) 8 | let current = (ref initial : t ref) 9 | let init () = current := initial 10 | 11 | let normalizePath ~aliases path = 12 | match path |> List.rev with 13 | | name :: restRev when restRev <> [] -> ( 14 | match aliases |> NameMap.find_opt name with 15 | | None -> path 16 | | Some path1 -> 17 | let newPath = List.rev (path1 @ restRev) in 18 | if !Common.Cli.debug then 19 | Log_.item "Resolve Alias: %s to %s@." 20 | (path |> Common.Path.toString) 21 | (newPath |> Common.Path.toString); 22 | newPath) 23 | | _ -> path 24 | 25 | let addAlias ~name ~path = 26 | let aliases = !current.aliases in 27 | let pathNormalized = path |> normalizePath ~aliases in 28 | if !Common.Cli.debug then 29 | Log_.item "Module Alias: %s = %s@." (name |> Name.toString) 30 | (Path.toString pathNormalized); 31 | current := {!current with aliases = NameMap.add name pathNormalized aliases} 32 | 33 | let resolveAlias path = path |> normalizePath ~aliases:!current.aliases 34 | let getCurrent () = !current 35 | let setCurrent p = current := p 36 | -------------------------------------------------------------------------------- /src/Name.ml: -------------------------------------------------------------------------------- 1 | type t = string 2 | 3 | let compare = String.compare 4 | 5 | let create ?(isInterface = true) s = 6 | match isInterface with true -> s | false -> "+" ^ s 7 | 8 | let isInterface s = try s.[0] <> '+' with Invalid_argument _ -> false 9 | 10 | let isUnderscore s = s = "_" || s = "+_" 11 | 12 | let startsWithUnderscore s = 13 | s |> String.length >= 2 14 | && 15 | try s.[0] = '_' || (s.[0] = '+' && s.[1] = '_') 16 | with Invalid_argument _ -> false 17 | 18 | let toInterface s = 19 | match isInterface s with 20 | | true -> s 21 | | false -> ( 22 | try String.sub s 1 (String.length s - 1) with Invalid_argument _ -> s) 23 | 24 | let toImplementation s = match isInterface s with true -> "+" ^ s | false -> s 25 | 26 | let toString s = s 27 | -------------------------------------------------------------------------------- /src/Name.mli: -------------------------------------------------------------------------------- 1 | type t 2 | 3 | val compare : t -> t -> int 4 | 5 | val create : ?isInterface:bool -> string -> t 6 | 7 | val isUnderscore : t -> bool 8 | 9 | val startsWithUnderscore : t -> bool 10 | 11 | val toImplementation : t -> t 12 | 13 | val toInterface : t -> t 14 | 15 | val toString : t -> string 16 | -------------------------------------------------------------------------------- /src/RunConfig.ml: -------------------------------------------------------------------------------- 1 | type t = { 2 | mutable bsbProjectRoot : string; 3 | mutable dce : bool; 4 | mutable exception_ : bool; 5 | mutable noalloc : bool; 6 | mutable projectRoot : string; 7 | mutable suppress : string list; 8 | mutable termination : bool; 9 | mutable unsuppress : string list; 10 | } 11 | 12 | let runConfig = 13 | { 14 | bsbProjectRoot = ""; 15 | dce = false; 16 | exception_ = false; 17 | noalloc = false; 18 | projectRoot = ""; 19 | suppress = []; 20 | termination = false; 21 | unsuppress = []; 22 | } 23 | 24 | let all () = 25 | runConfig.dce <- true; 26 | runConfig.exception_ <- true; 27 | runConfig.termination <- true 28 | 29 | let dce () = runConfig.dce <- true 30 | 31 | let exception_ () = runConfig.exception_ <- true 32 | 33 | let noalloc () = runConfig.noalloc <- true 34 | 35 | let termination () = runConfig.termination <- true 36 | -------------------------------------------------------------------------------- /src/Suppress.ml: -------------------------------------------------------------------------------- 1 | open Common 2 | 3 | let checkPrefix prefix_ = 4 | let prefix = 5 | match runConfig.projectRoot = "" with 6 | | true -> prefix_ 7 | | false -> Filename.concat runConfig.projectRoot prefix_ 8 | in 9 | let prefixLen = prefix |> String.length in 10 | fun sourceDir -> 11 | try String.sub sourceDir 0 prefixLen = prefix 12 | with Invalid_argument _ -> false 13 | 14 | let suppressSourceDir = 15 | lazy 16 | (fun sourceDir -> 17 | runConfig.suppress 18 | |> List.exists (fun prefix -> checkPrefix prefix sourceDir)) 19 | 20 | let unsuppressSourceDir = 21 | lazy 22 | (fun sourceDir -> 23 | runConfig.unsuppress 24 | |> List.exists (fun prefix -> checkPrefix prefix sourceDir)) 25 | 26 | let posInSuppress (pos : Lexing.position) = 27 | pos.pos_fname |> Lazy.force suppressSourceDir 28 | 29 | let posInUnsuppress (pos : Lexing.position) = 30 | pos.pos_fname |> Lazy.force unsuppressSourceDir 31 | 32 | (** First suppress list, then override with unsuppress list *) 33 | let filter pos = (not (posInSuppress pos)) || posInUnsuppress pos 34 | -------------------------------------------------------------------------------- /src/Version.ml: -------------------------------------------------------------------------------- 1 | 2 | (* CREATED BY reanalyze/scripts/bump_version_module.js *) 3 | (* DO NOT MODIFY BY HAND, WILL BE AUTOMATICALLY UPDATED BY npm version *) 4 | 5 | let version = "2.25.1"; 6 | -------------------------------------------------------------------------------- /src/compiler-libs-406/asttypes.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* OCaml *) 4 | (* *) 5 | (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) 6 | (* *) 7 | (* Copyright 1996 Institut National de Recherche en Informatique et *) 8 | (* en Automatique. *) 9 | (* *) 10 | (* All rights reserved. This file is distributed under the terms of *) 11 | (* the GNU Lesser General Public License version 2.1, with the *) 12 | (* special exception on linking described in the file LICENSE. *) 13 | (* *) 14 | (**************************************************************************) 15 | 16 | (** Auxiliary AST types used by parsetree and typedtree. *) 17 | 18 | type constant = 19 | Const_int of int 20 | | Const_char of char 21 | | Const_string of string * string option 22 | | Const_float of string 23 | | Const_int32 of int32 24 | | Const_int64 of int64 25 | | Const_nativeint of nativeint 26 | 27 | type rec_flag = Nonrecursive | Recursive 28 | 29 | type direction_flag = Upto | Downto 30 | 31 | (* Order matters, used in polymorphic comparison *) 32 | type private_flag = Private | Public 33 | 34 | type mutable_flag = Immutable | Mutable 35 | 36 | type virtual_flag = Virtual | Concrete 37 | 38 | type override_flag = Override | Fresh 39 | 40 | type closed_flag = Closed | Open 41 | 42 | type label = string 43 | 44 | type arg_label = 45 | Nolabel 46 | | Labelled of string (* label:T -> ... *) 47 | | Optional of string (* ?label:T -> ... *) 48 | 49 | type 'a loc = 'a Location.loc = { 50 | txt : 'a; 51 | loc : Location.t; 52 | } 53 | 54 | 55 | type variance = 56 | | Covariant 57 | | Contravariant 58 | | Invariant 59 | -------------------------------------------------------------------------------- /src/compiler-libs-406/clflags.ml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | let output_name = ref (None : string option) (* -o *) 6 | and include_dirs = ref ([] : string list)(* -I *) 7 | and debug = ref false (* -g *) 8 | and fast = ref false (* -unsafe *) 9 | 10 | and nopervasives = ref false (* -nopervasives *) 11 | and preprocessor = ref(None : string option) (* -pp *) 12 | and all_ppx = ref ([] : string list) (* -ppx *) 13 | let annotations = ref false (* -annot *) 14 | let binary_annotations = ref false (* -annot *) 15 | and noassert = ref false (* -noassert *) 16 | and verbose = ref false (* -verbose *) 17 | and open_modules = ref [] (* -open *) 18 | and principal = ref false (* -principal *) 19 | and real_paths = ref true (* -short-paths *) 20 | and applicative_functors = ref true (* -no-app-funct *) 21 | and error_size = ref 500 (* -error-size *) 22 | and transparent_modules = ref false (* -trans-mod *) 23 | let dump_source = ref false (* -dsource *) 24 | let dump_parsetree = ref false (* -dparsetree *) 25 | and dump_typedtree = ref false (* -dtypedtree *) 26 | and dump_rawlambda = ref false (* -drawlambda *) 27 | and dump_lambda = ref false (* -dlambda *) 28 | 29 | 30 | let dont_write_files = ref false (* set to true under ocamldoc *) 31 | 32 | 33 | let reset_dump_state () = begin 34 | dump_source := false; 35 | dump_parsetree := false; 36 | dump_typedtree := false; 37 | dump_rawlambda := false 38 | end 39 | 40 | 41 | 42 | 43 | let keep_docs = ref false (* -keep-docs *) 44 | let keep_locs = ref true (* -keep-locs *) 45 | 46 | 47 | 48 | 49 | let parse_color_setting = function 50 | | "auto" -> Some Misc.Color.Auto 51 | | "always" -> Some Misc.Color.Always 52 | | "never" -> Some Misc.Color.Never 53 | | _ -> None 54 | let color = ref None ;; (* -color *) 55 | 56 | let unboxed_types = ref false 57 | 58 | 59 | 60 | 61 | type mli_status = Mli_exists | Mli_non_exists 62 | let assume_no_mli = ref Mli_non_exists 63 | let bs_vscode = 64 | try ignore @@ Sys.getenv "BS_VSCODE" ; true with _ -> false 65 | (* We get it from environment variable mostly due to 66 | we don't want to rebuild when flip on or off 67 | *) 68 | let dont_record_crc_unit : string option ref = ref None 69 | let bs_gentype = ref None 70 | let no_assert_false = ref false 71 | let dump_location = ref true 72 | -------------------------------------------------------------------------------- /src/compiler-libs-406/clflags.mli: -------------------------------------------------------------------------------- 1 | val output_name : string option ref 2 | val include_dirs : string list ref 3 | 4 | val debug : bool ref 5 | val fast : bool ref 6 | 7 | val nopervasives : bool ref 8 | val open_modules : string list ref 9 | val preprocessor : string option ref 10 | val all_ppx : string list ref 11 | val annotations : bool ref 12 | val binary_annotations : bool ref 13 | val noassert : bool ref 14 | val verbose : bool ref 15 | val principal : bool ref 16 | val real_paths : bool ref 17 | val applicative_functors : bool ref 18 | val error_size : int ref 19 | val transparent_modules : bool ref 20 | val dump_source : bool ref 21 | val dump_parsetree : bool ref 22 | val dump_typedtree : bool ref 23 | val dump_rawlambda : bool ref 24 | val dump_lambda : bool ref 25 | val dont_write_files : bool ref 26 | val keep_docs : bool ref 27 | val keep_locs : bool ref 28 | 29 | 30 | val parse_color_setting : string -> Misc.Color.setting option 31 | val color : Misc.Color.setting option ref 32 | 33 | val unboxed_types : bool ref 34 | 35 | val reset_dump_state: unit -> unit 36 | 37 | 38 | type mli_status = Mli_exists | Mli_non_exists 39 | val assume_no_mli : mli_status ref 40 | val bs_vscode : bool 41 | val dont_record_crc_unit : string option ref 42 | val bs_gentype : string option ref 43 | val no_assert_false : bool ref 44 | val dump_location : bool ref 45 | 46 | -------------------------------------------------------------------------------- /src/compiler-libs-406/cmi_format.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* OCaml *) 4 | (* *) 5 | (* Fabrice Le Fessant, INRIA Saclay *) 6 | (* *) 7 | (* Copyright 2012 Institut National de Recherche en Informatique et *) 8 | (* en Automatique. *) 9 | (* *) 10 | (* All rights reserved. This file is distributed under the terms of *) 11 | (* the GNU Lesser General Public License version 2.1, with the *) 12 | (* special exception on linking described in the file LICENSE. *) 13 | (* *) 14 | (**************************************************************************) 15 | 16 | type pers_flags = 17 | | Rectypes 18 | | Deprecated of string 19 | | Opaque 20 | | Unsafe_string 21 | 22 | type cmi_infos = { 23 | cmi_name : string; 24 | cmi_sign : Types.signature_item list; 25 | cmi_crcs : (string * Digest.t option) list; 26 | cmi_flags : pers_flags list; 27 | } 28 | 29 | (* write the magic + the cmi information *) 30 | val output_cmi : string -> out_channel -> cmi_infos -> Digest.t 31 | 32 | val create_cmi : ?check_exists:unit -> string -> cmi_infos -> Digest.t 33 | 34 | (* read the cmi information (the magic is supposed to have already been read) *) 35 | val input_cmi : in_channel -> cmi_infos 36 | 37 | (* read a cmi from a filename, checking the magic *) 38 | val read_cmi : string -> cmi_infos 39 | 40 | (* Error report *) 41 | 42 | type error = 43 | Not_an_interface of string 44 | | Wrong_version_interface of string * string 45 | | Corrupted_interface of string 46 | 47 | exception Error of error 48 | 49 | open Format 50 | 51 | val report_error: formatter -> error -> unit 52 | -------------------------------------------------------------------------------- /src/compiler-libs-406/config.ml: -------------------------------------------------------------------------------- 1 | let version = "4.06.1+BS" 2 | let standard_library = 3 | let (//) = Filename.concat in 4 | Filename.dirname Sys.executable_name // Filename.parent_dir_name // "lib" // "ocaml" 5 | let standard_library_default = standard_library 6 | let syntax_kind = ref `ml 7 | let bs_only = ref true 8 | let unsafe_empty_array = ref true 9 | 10 | 11 | and cmi_magic_number = "Caml1999I022" 12 | 13 | and ast_impl_magic_number = "Caml1999M022" 14 | and ast_intf_magic_number = "Caml1999N022" 15 | and cmt_magic_number = "Caml1999T022" 16 | 17 | let load_path = ref ([] : string list) 18 | 19 | let interface_suffix = ref ".mli" 20 | 21 | 22 | (* This is normally the same as in obj.ml, but we have to define it 23 | separately because it can differ when we're in the middle of a 24 | bootstrapping phase. *) 25 | 26 | 27 | 28 | let default_uncurry = ref false 29 | 30 | let print_config oc = 31 | let p name valu = Printf.fprintf oc "%s: %s\n" name valu in 32 | p "version" version; 33 | p "standard_library_default" standard_library_default; 34 | p "standard_library" standard_library; 35 | (* print the magic number *) 36 | 37 | p "cmi_magic_number" cmi_magic_number; 38 | p "ast_impl_magic_number" ast_impl_magic_number; 39 | p "ast_intf_magic_number" ast_intf_magic_number; 40 | p "cmt_magic_number" cmt_magic_number; 41 | flush oc; 42 | ;; 43 | -------------------------------------------------------------------------------- /src/compiler-libs-406/config.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* OCaml *) 4 | (* *) 5 | (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) 6 | (* *) 7 | (* Copyright 1996 Institut National de Recherche en Informatique et *) 8 | (* en Automatique. *) 9 | (* *) 10 | (* All rights reserved. This file is distributed under the terms of *) 11 | (* the GNU Lesser General Public License version 2.1, with the *) 12 | (* special exception on linking described in the file LICENSE. *) 13 | (* *) 14 | (**************************************************************************) 15 | 16 | (* System configuration *) 17 | 18 | val version: string 19 | (* The current version number of the system *) 20 | 21 | val standard_library: string 22 | (* The directory containing the standard libraries *) 23 | 24 | val syntax_kind : [ `ml | `reason | `rescript ] ref 25 | 26 | val bs_only : bool ref 27 | 28 | val unsafe_empty_array: bool ref 29 | 30 | 31 | val load_path: string list ref 32 | (* Directories in the search path for .cmi and .cmo files *) 33 | 34 | val interface_suffix: string ref 35 | (* Suffix for interface file names *) 36 | 37 | val cmi_magic_number: string 38 | (* Magic number for compiled interface files *) 39 | val ast_intf_magic_number: string 40 | (* Magic number for file holding an interface syntax tree *) 41 | val ast_impl_magic_number: string 42 | (* Magic number for file holding an implementation syntax tree *) 43 | val cmt_magic_number: string 44 | (* Magic number for compiled interface files *) 45 | 46 | 47 | val default_uncurry : bool ref 48 | val print_config : out_channel -> unit;; 49 | 50 | 51 | -------------------------------------------------------------------------------- /src/compiler-libs-406/datarepr.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* OCaml *) 4 | (* *) 5 | (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) 6 | (* *) 7 | (* Copyright 1996 Institut National de Recherche en Informatique et *) 8 | (* en Automatique. *) 9 | (* *) 10 | (* All rights reserved. This file is distributed under the terms of *) 11 | (* the GNU Lesser General Public License version 2.1, with the *) 12 | (* special exception on linking described in the file LICENSE. *) 13 | (* *) 14 | (**************************************************************************) 15 | 16 | (* Compute constructor and label descriptions from type declarations, 17 | determining their representation. *) 18 | 19 | open Types 20 | 21 | val constructor_has_optional_shape: 22 | Types.constructor_description -> bool 23 | 24 | val extension_descr: 25 | Path.t -> extension_constructor -> constructor_description 26 | 27 | val labels_of_type: 28 | Path.t -> type_declaration -> 29 | (Ident.t * label_description) list 30 | val constructors_of_type: 31 | Path.t -> type_declaration -> 32 | (Ident.t * constructor_description) list 33 | 34 | 35 | exception Constr_not_found 36 | 37 | val find_constr_by_tag: 38 | constructor_tag -> constructor_declaration list -> 39 | constructor_declaration 40 | 41 | val constructor_existentials : 42 | constructor_arguments -> type_expr option -> type_expr list * type_expr list 43 | (** Takes [cd_args] and [cd_res] from a [constructor_declaration] and 44 | returns: 45 | - the types of the constructor's arguments 46 | - the existential variables introduced by the constructor 47 | *) 48 | 49 | 50 | (* Set the polymorphic variant row_name field *) 51 | val set_row_name : type_declaration -> Path.t -> unit 52 | -------------------------------------------------------------------------------- /src/compiler-libs-406/dune: -------------------------------------------------------------------------------- 1 | (library 2 | (name compilerlibs406) 3 | (flags "-w" "-9") 4 | (modules_without_implementation asttypes outcometree parsetree) 5 | (libraries )) -------------------------------------------------------------------------------- /src/compiler-libs-406/longident.ml: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* OCaml *) 4 | (* *) 5 | (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) 6 | (* *) 7 | (* Copyright 1996 Institut National de Recherche en Informatique et *) 8 | (* en Automatique. *) 9 | (* *) 10 | (* All rights reserved. This file is distributed under the terms of *) 11 | (* the GNU Lesser General Public License version 2.1, with the *) 12 | (* special exception on linking described in the file LICENSE. *) 13 | (* *) 14 | (**************************************************************************) 15 | 16 | type t = 17 | Lident of string 18 | | Ldot of t * string 19 | | Lapply of t * t 20 | 21 | let rec flat accu = function 22 | Lident s -> s :: accu 23 | | Ldot(lid, s) -> flat (s :: accu) lid 24 | | Lapply(_, _) -> Misc.fatal_error "Longident.flat" 25 | 26 | let flatten lid = flat [] lid 27 | 28 | let last = function 29 | Lident s -> s 30 | | Ldot(_, s) -> s 31 | | Lapply(_, _) -> Misc.fatal_error "Longident.last" 32 | 33 | let rec split_at_dots s pos = 34 | try 35 | let dot = String.index_from s pos '.' in 36 | String.sub s pos (dot - pos) :: split_at_dots s (dot + 1) 37 | with Not_found -> 38 | [String.sub s pos (String.length s - pos)] 39 | 40 | let unflatten l = 41 | match l with 42 | | [] -> None 43 | | hd :: tl -> Some (List.fold_left (fun p s -> Ldot(p, s)) (Lident hd) tl) 44 | 45 | let parse s = 46 | match unflatten (split_at_dots s 0) with 47 | | None -> Lident "" (* should not happen, but don't put assert false 48 | so as not to crash the toplevel (see Genprintval) *) 49 | | Some v -> v 50 | -------------------------------------------------------------------------------- /src/compiler-libs-406/longident.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* OCaml *) 4 | (* *) 5 | (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) 6 | (* *) 7 | (* Copyright 1996 Institut National de Recherche en Informatique et *) 8 | (* en Automatique. *) 9 | (* *) 10 | (* All rights reserved. This file is distributed under the terms of *) 11 | (* the GNU Lesser General Public License version 2.1, with the *) 12 | (* special exception on linking described in the file LICENSE. *) 13 | (* *) 14 | (**************************************************************************) 15 | 16 | (** Long identifiers, used in parsetree. *) 17 | 18 | type t = 19 | Lident of string 20 | | Ldot of t * string 21 | | Lapply of t * t 22 | 23 | val flatten: t -> string list 24 | val unflatten: string list -> t option 25 | val last: t -> string 26 | val parse: string -> t 27 | -------------------------------------------------------------------------------- /src/compiler-libs-406/path.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* OCaml *) 4 | (* *) 5 | (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) 6 | (* *) 7 | (* Copyright 1996 Institut National de Recherche en Informatique et *) 8 | (* en Automatique. *) 9 | (* *) 10 | (* All rights reserved. This file is distributed under the terms of *) 11 | (* the GNU Lesser General Public License version 2.1, with the *) 12 | (* special exception on linking described in the file LICENSE. *) 13 | (* *) 14 | (**************************************************************************) 15 | 16 | (* Access paths *) 17 | 18 | type t = 19 | Pident of Ident.t 20 | | Pdot of t * string * int 21 | | Papply of t * t 22 | 23 | val same: t -> t -> bool 24 | val compare: t -> t -> int 25 | val isfree: Ident.t -> t -> bool 26 | val binding_time: t -> int 27 | val flatten : t -> [ `Contains_apply | `Ok of Ident.t * string list ] 28 | 29 | val nopos: int 30 | 31 | val name: ?paren:(string -> bool) -> t -> string 32 | (* [paren] tells whether a path suffix needs parentheses *) 33 | val head: t -> Ident.t 34 | 35 | val heads: t -> Ident.t list 36 | 37 | val last: t -> string 38 | 39 | type typath = 40 | | Regular of t 41 | | Ext of t * string 42 | | LocalExt of Ident.t 43 | | Cstr of t * string 44 | 45 | val constructor_typath: t -> typath 46 | val is_constructor_typath: t -> bool 47 | -------------------------------------------------------------------------------- /src/compiler-libs-406/syntaxerr.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* OCaml *) 4 | (* *) 5 | (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) 6 | (* *) 7 | (* Copyright 1997 Institut National de Recherche en Informatique et *) 8 | (* en Automatique. *) 9 | (* *) 10 | (* All rights reserved. This file is distributed under the terms of *) 11 | (* the GNU Lesser General Public License version 2.1, with the *) 12 | (* special exception on linking described in the file LICENSE. *) 13 | (* *) 14 | (**************************************************************************) 15 | 16 | (** Auxiliary type for reporting syntax errors *) 17 | 18 | open Format 19 | 20 | type error = 21 | Unclosed of Location.t * string * Location.t * string 22 | | Expecting of Location.t * string 23 | | Not_expecting of Location.t * string 24 | | Applicative_path of Location.t 25 | | Variable_in_scope of Location.t * string 26 | | Other of Location.t 27 | | Ill_formed_ast of Location.t * string 28 | | Invalid_package_type of Location.t * string 29 | 30 | exception Error of error 31 | exception Escape_error 32 | 33 | val report_error: formatter -> error -> unit 34 | (** @deprecated Use {!Location.error_of_exn}, {!Location.report_error}. *) 35 | 36 | val location_of_error: error -> Location.t 37 | val ill_formed_ast: Location.t -> string -> 'a 38 | -------------------------------------------------------------------------------- /src/compiler-libs-406/tbl.mli: -------------------------------------------------------------------------------- 1 | (**************************************************************************) 2 | (* *) 3 | (* OCaml *) 4 | (* *) 5 | (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) 6 | (* *) 7 | (* Copyright 1996 Institut National de Recherche en Informatique et *) 8 | (* en Automatique. *) 9 | (* *) 10 | (* All rights reserved. This file is distributed under the terms of *) 11 | (* the GNU Lesser General Public License version 2.1, with the *) 12 | (* special exception on linking described in the file LICENSE. *) 13 | (* *) 14 | (**************************************************************************) 15 | 16 | (* Association tables from any ordered type to any type. 17 | We use the generic ordering to compare keys. *) 18 | 19 | type ('k, 'v) t 20 | 21 | val empty: ('k, 'v) t 22 | val add: 'k -> 'v -> ('k, 'v) t -> ('k, 'v) t 23 | val find: 'k -> ('k, 'v) t -> 'v 24 | val find_str: string -> (string, 'v) t -> 'v 25 | val mem: 'k -> ('k, 'v) t -> bool 26 | val remove: 'k -> ('k, 'v) t -> ('k, 'v) t 27 | val iter: ('k -> 'v -> unit) -> ('k, 'v) t -> unit 28 | val map: ('k -> 'v1 -> 'v2) -> ('k, 'v1) t -> ('k, 'v2) t 29 | val fold: ('k -> 'v -> 'acc -> 'acc) -> ('k, 'v) t -> 'acc -> 'acc 30 | 31 | open Format 32 | 33 | val print: (formatter -> 'k -> unit) -> (formatter -> 'v -> unit) -> 34 | formatter -> ('k, 'v) t -> unit 35 | -------------------------------------------------------------------------------- /src/dune: -------------------------------------------------------------------------------- 1 | (copy_files# ext/*.{ml,mli}) 2 | (copy_files# vendor/*.{ml,mli}) 3 | 4 | (executable 5 | (public_name reanalyze.exe) 6 | (modes byte exe) 7 | (preprocess 8 | (action 9 | (run %{bin:cppo} -V OCAML:%{ocaml_version} %{input-file}))) 10 | ; The main module that will become the binary. 11 | (name Reanalyze) 12 | (flags "-w" "+6+26+27+32+33+39") 13 | ; Depends on: 14 | (libraries unix str compiler-libs.common compilerlibs406)) 15 | -------------------------------------------------------------------------------- /src/dune.406: -------------------------------------------------------------------------------- 1 | (copy_files# ext/*.{ml,mli}) 2 | (copy_files# vendor/*.{ml,mli}) 3 | 4 | (executable 5 | (public_name reanalyze.exe) 6 | (modes byte exe) 7 | (preprocess 8 | (action 9 | (run %{bin:cppo} -V OCAML:4.06.1 %{input-file}))) 10 | ; The main module that will become the binary. 11 | (name Reanalyze) 12 | (flags "-w" "+6+26+27+32+33+39") 13 | ; Depends on: 14 | (libraries unix str compiler-libs.common compilerlibs406)) 15 | -------------------------------------------------------------------------------- /src/ext/ext_json_types.ml: -------------------------------------------------------------------------------- 1 | (* Copyright (C) 2015-2017 Bloomberg Finance L.P. 2 | * 3 | * This program is free software: you can redistribute it and/or modify 4 | * it under the terms of the GNU Lesser General Public License as published by 5 | * the Free Software Foundation, either version 3 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * In addition to the permissions granted to you by the LGPL, you may combine 9 | * or link a "work that uses the Library" with a publicly distributed version 10 | * of this file to produce a combined library or application, then distribute 11 | * that combined work under the terms of your choosing, with no requirement 12 | * to comply with the obligations normally placed on you by section 4 of the 13 | * LGPL version 3 (or the corresponding section of a later version of the LGPL 14 | * should you choose to use a later version). 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU Lesser General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU Lesser General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) 24 | 25 | type loc = Lexing.position 26 | type json_str = string 27 | 28 | type json_flo = string 29 | 30 | module StringMap = Map.Make(String) 31 | 32 | type json_array = t array 33 | 34 | and json_map = t StringMap.t 35 | 36 | and t = 37 | | True of loc 38 | | False of loc 39 | | Null of loc 40 | | Flo of json_flo 41 | | Str of json_str 42 | | Arr of json_array 43 | | Obj of json_map 44 | -------------------------------------------------------------------------------- /src/ext/ext_position.ml: -------------------------------------------------------------------------------- 1 | (* Copyright (C) 2015-2016 Bloomberg Finance L.P. 2 | * 3 | * This program is free software: you can redistribute it and/or modify 4 | * it under the terms of the GNU Lesser General Public License as published by 5 | * the Free Software Foundation, either version 3 of the License, or 6 | * (at your option) any later version. 7 | * 8 | * In addition to the permissions granted to you by the LGPL, you may combine 9 | * or link a "work that uses the Library" with a publicly distributed version 10 | * of this file to produce a combined library or application, then distribute 11 | * that combined work under the terms of your choosing, with no requirement 12 | * to comply with the obligations normally placed on you by section 4 of the 13 | * LGPL version 3 (or the corresponding section of a later version of the LGPL 14 | * should you choose to use a later version). 15 | * 16 | * This program is distributed in the hope that it will be useful, 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 | * GNU Lesser General Public License for more details. 20 | * 21 | * You should have received a copy of the GNU Lesser General Public License 22 | * along with this program; if not, write to the Free Software 23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) 24 | 25 | 26 | type t = Lexing.position = { 27 | pos_fname : string ; [@dead] 28 | pos_lnum : int ; 29 | pos_bol : int ; 30 | pos_cnum : int 31 | } 32 | 33 | let print fmt (pos : t) = 34 | Format.fprintf fmt "(line %d, column %d)" pos.pos_lnum (pos.pos_cnum - pos.pos_bol) 35 | 36 | 37 | 38 | let lexbuf_from_channel_with_fname ic fname = 39 | let x = Lexing.from_function (fun buf n -> input ic buf 0 n) in 40 | let pos : t = { 41 | pos_fname = fname ; 42 | pos_lnum = 1; 43 | pos_bol = 0; 44 | pos_cnum = 0 (* copied from zero_pos*) 45 | } in 46 | x.lex_start_p <- pos; 47 | x.lex_curr_p <- pos ; 48 | x 49 | [@@raises Invalid_argument] 50 | --------------------------------------------------------------------------------