Skip to content

Commit 689b8fa

Browse files
committed
Support @gentype.import as an alias to @genType.import in the compiler
See #6018
1 parent 095abc8 commit 689b8fa

File tree

8 files changed

+26
-3
lines changed

8 files changed

+26
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ These are only breaking changes for unformatted code.
6767
- Fix issue in the compiler back-end where async functions passed to an `@uncurry` external would be inlined and transformed in a way that loses async https://github.com/rescript-lang/rescript-compiler/pull/6010
6868
- Fix location issue for the treatment of `async` functions where hovering on the body with a type error would show `'a => promise<'a>` everywhere https://github.com/rescript-lang/rescript-compiler/pull/6012
6969
- Fix formatting of `switch` expressions that contain brace `cases` inside https://github.com/rescript-lang/rescript-compiler/pull/6015
70+
- Support `@gentype.import` as an alias to `@genType.import` in the compiler https://github.com/rescript-lang/rescript-compiler/pull/6020
7071

7172
#### :nail_care: Polish
7273

jscomp/ext/literals.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ let node_parent = ".."
148148

149149
let node_current = "."
150150

151-
let gentype_import = "genType.import"
151+
let gentype_import1 = "genType.import"
152+
let gentype_import2 = "gentype.import"
152153

153154
let bsbuild_cache = ".bsbuild"
154155

jscomp/frontend/ast_attributes.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ let external_attrs =
119119
"send";
120120
"new";
121121
"set_index";
122-
Literals.gentype_import;
122+
Literals.gentype_import1;
123+
Literals.gentype_import2;
123124
|]
124125

125126
let first_char_special (x : string) =

jscomp/frontend/ast_external_process.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string)
235235

236236
Ext_list.fold_left prim_attributes ([], init_st)
237237
(fun (attrs, st) (({ txt; loc }, payload) as attr) ->
238-
if txt = Literals.gentype_import then
238+
if txt = Literals.gentype_import1 || txt = Literals.gentype_import2 then
239239
let bundle =
240240
"./"
241241
^ Ext_filename.new_extension

jscomp/gentype_tests/typescript-react-example/src/ImportJsValue.bs.js

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/gentype_tests/typescript-react-example/src/ImportJsValue.gen.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import {round as roundNotChecked} from './MyMath';
66

7+
import {round2 as round2NotChecked} from './MyMath';
8+
79
import {area as areaNotChecked} from './MyMath';
810

911
import {returnMixedArray as returnMixedArrayNotChecked} from './MyMath';
@@ -28,6 +30,12 @@ export const roundTypeChecked: (_1:number) => number = roundNotChecked;
2830
// Export 'round' early to allow circular import from the '.bs.js' file.
2931
export const round: unknown = roundTypeChecked as (_1:number) => number;
3032

33+
// In case of type error, check the type of 'round2' in 'ImportJsValue.res' and './MyMath'.
34+
export const round2TypeChecked: (_1:number) => number = round2NotChecked;
35+
36+
// Export 'round2' early to allow circular import from the '.bs.js' file.
37+
export const round2: unknown = round2TypeChecked as (_1:number) => number;
38+
3139
// In case of type error, check the type of 'area' in 'ImportJsValue.res' and './MyMath'.
3240
export const areaTypeChecked: (_1:point) => number = areaNotChecked;
3341

jscomp/gentype_tests/typescript-react-example/src/ImportJsValue.res

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ external /* This is the module to import from. */
66
/* Name and type of the JS value to bind to. */
77
round: float => float = "round"
88

9+
@gentype.import("./MyMath")
10+
external round2: float => float = "round2"
11+
12+
let _ = round2
13+
914
@genType
1015
type point = {
1116
x: int,

jscomp/gentype_tests/typescript-react-example/src/MyMath.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
export const round: (_: number) => number = Math.round;
44

5+
export const round2 = round;
6+
57
// tslint:disable-next-line:only-arrow-functions
68
export const area = function(point: { x: number; y?: number }): number {
79
return point.x * (point.y === undefined ? 1 : point.y);

0 commit comments

Comments
 (0)