Skip to content

Commit e4b5166

Browse files
committed
Support @gentype.import as an alias to @genType.import in the compiler
See #6018
1 parent f828fb5 commit e4b5166

14 files changed

+47
-15
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- 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/6014
3232
- Fix formatting of `switch` expressions that contain braced `cases` inside https://github.com/rescript-lang/syntax/pull/735
3333
- Fix formatting of props spread for multiline JSX expression https://github.com/rescript-lang/syntax/pull/736
34+
- Support `@gentype.import` as an alias to `@genType.import` in the compiler https://github.com/rescript-lang/rescript-compiler/pull/6021
3435

3536
#### :rocket: New Feature
3637

jscomp/ext/literals.ml

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

153153
let node_current = "."
154154

155-
let gentype_import = "genType.import"
155+
let gentype_import1 = "genType.import"
156+
let gentype_import2 = "gentype.import"
156157

157158
let bsbuild_cache = ".bsbuild"
158159

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
@@ -230,7 +230,7 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string)
230230

231231
Ext_list.fold_left prim_attributes ([], init_st)
232232
(fun (attrs, st) (({ txt; loc }, payload) as attr) ->
233-
if txt = Literals.gentype_import then
233+
if txt = Literals.gentype_import1 || txt = Literals.gentype_import2 then
234234
let bundle =
235235
"./"
236236
^ 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.re' 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.re' 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);

lib/4.06.1/bsb_helper.ml

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

13411341
let node_current = "."
13421342

1343-
let gentype_import = "genType.import"
1343+
let gentype_import1 = "genType.import"
1344+
let gentype_import2 = "gentype.import"
13441345

13451346
let bsbuild_cache = ".bsbuild"
13461347

lib/4.06.1/rescript.ml

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

56195619
let node_current = "."
56205620

5621-
let gentype_import = "genType.import"
5621+
let gentype_import1 = "genType.import"
5622+
let gentype_import2 = "gentype.import"
56225623

56235624
let bsbuild_cache = ".bsbuild"
56245625

lib/4.06.1/unstable/all_ounit_tests.ml

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

58345834
let node_current = "."
58355835

5836-
let gentype_import = "genType.import"
5836+
let gentype_import1 = "genType.import"
5837+
let gentype_import2 = "gentype.import"
58375838

58385839
let bsbuild_cache = ".bsbuild"
58395840

lib/4.06.1/unstable/js_compiler.ml

+5-3
Original file line numberDiff line numberDiff line change
@@ -6530,7 +6530,8 @@ let node_parent = ".."
65306530

65316531
let node_current = "."
65326532

6533-
let gentype_import = "genType.import"
6533+
let gentype_import1 = "genType.import"
6534+
let gentype_import2 = "gentype.import"
65346535

65356536
let bsbuild_cache = ".bsbuild"
65366537

@@ -266200,7 +266201,8 @@ let external_attrs =
266200266201
"send";
266201266202
"new";
266202266203
"set_index";
266203-
Literals.gentype_import;
266204+
Literals.gentype_import1;
266205+
Literals.gentype_import2;
266204266206
|]
266205266207

266206266208
let first_char_special (x : string) =
@@ -270046,7 +270048,7 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string)
270046270048

270047270049
Ext_list.fold_left prim_attributes ([], init_st)
270048270050
(fun (attrs, st) (({ txt; loc }, payload) as attr) ->
270049-
if txt = Literals.gentype_import then
270051+
if txt = Literals.gentype_import1 || txt = Literals.gentype_import2 then
270050270052
let bundle =
270051270053
"./"
270052270054
^ Ext_filename.new_extension

lib/4.06.1/unstable/js_playground_compiler.ml

+5-3
Original file line numberDiff line numberDiff line change
@@ -6530,7 +6530,8 @@ let node_parent = ".."
65306530

65316531
let node_current = "."
65326532

6533-
let gentype_import = "genType.import"
6533+
let gentype_import1 = "genType.import"
6534+
let gentype_import2 = "gentype.import"
65346535

65356536
let bsbuild_cache = ".bsbuild"
65366537

@@ -266200,7 +266201,8 @@ let external_attrs =
266200266201
"send";
266201266202
"new";
266202266203
"set_index";
266203-
Literals.gentype_import;
266204+
Literals.gentype_import1;
266205+
Literals.gentype_import2;
266204266206
|]
266205266207

266206266208
let first_char_special (x : string) =
@@ -270046,7 +270048,7 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string)
270046270048

270047270049
Ext_list.fold_left prim_attributes ([], init_st)
270048270050
(fun (attrs, st) (({ txt; loc }, payload) as attr) ->
270049-
if txt = Literals.gentype_import then
270051+
if txt = Literals.gentype_import1 || txt = Literals.gentype_import2 then
270050270052
let bundle =
270051270053
"./"
270052270054
^ Ext_filename.new_extension

lib/4.06.1/whole_compiler.ml

+5-3
Original file line numberDiff line numberDiff line change
@@ -181378,7 +181378,8 @@ let node_parent = ".."
181378181378

181379181379
let node_current = "."
181380181380

181381-
let gentype_import = "genType.import"
181381+
let gentype_import1 = "genType.import"
181382+
let gentype_import2 = "gentype.import"
181382181383

181383181384
let bsbuild_cache = ".bsbuild"
181384181385

@@ -276587,7 +276588,8 @@ let external_attrs =
276587276588
"send";
276588276589
"new";
276589276590
"set_index";
276590-
Literals.gentype_import;
276591+
Literals.gentype_import1;
276592+
Literals.gentype_import2;
276591276593
|]
276592276594

276593276595
let first_char_special (x : string) =
@@ -280433,7 +280435,7 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string)
280433280435

280434280436
Ext_list.fold_left prim_attributes ([], init_st)
280435280437
(fun (attrs, st) (({ txt; loc }, payload) as attr) ->
280436-
if txt = Literals.gentype_import then
280438+
if txt = Literals.gentype_import1 || txt = Literals.gentype_import2 then
280437280439
let bundle =
280438280440
"./"
280439280441
^ Ext_filename.new_extension

0 commit comments

Comments
 (0)