Skip to content

Gentype import v10 #6021

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- 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
- Fix formatting of `switch` expressions that contain braced `cases` inside https://github.com/rescript-lang/syntax/pull/735
- Fix formatting of props spread for multiline JSX expression https://github.com/rescript-lang/syntax/pull/736
- Support `@gentype.import` as an alias to `@genType.import` in the compiler https://github.com/rescript-lang/rescript-compiler/pull/6021

#### :rocket: New Feature

Expand Down
3 changes: 2 additions & 1 deletion jscomp/ext/literals.ml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ let node_parent = ".."

let node_current = "."

let gentype_import = "genType.import"
let gentype_import1 = "genType.import"
let gentype_import2 = "gentype.import"

let bsbuild_cache = ".bsbuild"

Expand Down
3 changes: 2 additions & 1 deletion jscomp/frontend/ast_attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ let external_attrs =
"send";
"new";
"set_index";
Literals.gentype_import;
Literals.gentype_import1;
Literals.gentype_import2;
|]

let first_char_special (x : string) =
Expand Down
2 changes: 1 addition & 1 deletion jscomp/frontend/ast_external_process.ml
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string)

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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

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

import {round2 as round2NotChecked} from './MyMath';

import {area as areaNotChecked} from './MyMath';

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

// In case of type error, check the type of 'round2' in 'ImportJsValue.re' and './MyMath'.
export const round2TypeChecked: (_1:number) => number = round2NotChecked;

// Export 'round2' early to allow circular import from the '.bs.js' file.
export const round2: unknown = round2TypeChecked as (_1:number) => number;

// In case of type error, check the type of 'area' in 'ImportJsValue.re' and './MyMath'.
export const areaTypeChecked: (_1:point) => number = areaNotChecked;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ external /* This is the module to import from. */
/* Name and type of the JS value to bind to. */
round: float => float = "round"

@gentype.import("./MyMath")
external round2: float => float = "round2"

let _ = round2

@genType
type point = {
x: int,
Expand Down
2 changes: 2 additions & 0 deletions jscomp/gentype_tests/typescript-react-example/src/MyMath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

export const round2 = round;

// tslint:disable-next-line:only-arrow-functions
export const area = function(point: { x: number; y?: number }): number {
return point.x * (point.y === undefined ? 1 : point.y);
Expand Down
3 changes: 2 additions & 1 deletion lib/4.06.1/bsb_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,8 @@ let node_parent = ".."

let node_current = "."

let gentype_import = "genType.import"
let gentype_import1 = "genType.import"
let gentype_import2 = "gentype.import"

let bsbuild_cache = ".bsbuild"

Expand Down
3 changes: 2 additions & 1 deletion lib/4.06.1/rescript.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5618,7 +5618,8 @@ let node_parent = ".."

let node_current = "."

let gentype_import = "genType.import"
let gentype_import1 = "genType.import"
let gentype_import2 = "gentype.import"

let bsbuild_cache = ".bsbuild"

Expand Down
3 changes: 2 additions & 1 deletion lib/4.06.1/unstable/all_ounit_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5833,7 +5833,8 @@ let node_parent = ".."

let node_current = "."

let gentype_import = "genType.import"
let gentype_import1 = "genType.import"
let gentype_import2 = "gentype.import"

let bsbuild_cache = ".bsbuild"

Expand Down
8 changes: 5 additions & 3 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6530,7 +6530,8 @@ let node_parent = ".."

let node_current = "."

let gentype_import = "genType.import"
let gentype_import1 = "genType.import"
let gentype_import2 = "gentype.import"

let bsbuild_cache = ".bsbuild"

Expand Down Expand Up @@ -266200,7 +266201,8 @@ let external_attrs =
"send";
"new";
"set_index";
Literals.gentype_import;
Literals.gentype_import1;
Literals.gentype_import2;
|]

let first_char_special (x : string) =
Expand Down Expand Up @@ -270046,7 +270048,7 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string)

Ext_list.fold_left prim_attributes ([], init_st)
(fun (attrs, st) (({ txt; loc }, payload) as attr) ->
if txt = Literals.gentype_import then
if txt = Literals.gentype_import1 || txt = Literals.gentype_import2 then
let bundle =
"./"
^ Ext_filename.new_extension
Expand Down
8 changes: 5 additions & 3 deletions lib/4.06.1/unstable/js_playground_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6530,7 +6530,8 @@ let node_parent = ".."

let node_current = "."

let gentype_import = "genType.import"
let gentype_import1 = "genType.import"
let gentype_import2 = "gentype.import"

let bsbuild_cache = ".bsbuild"

Expand Down Expand Up @@ -266200,7 +266201,8 @@ let external_attrs =
"send";
"new";
"set_index";
Literals.gentype_import;
Literals.gentype_import1;
Literals.gentype_import2;
|]

let first_char_special (x : string) =
Expand Down Expand Up @@ -270046,7 +270048,7 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string)

Ext_list.fold_left prim_attributes ([], init_st)
(fun (attrs, st) (({ txt; loc }, payload) as attr) ->
if txt = Literals.gentype_import then
if txt = Literals.gentype_import1 || txt = Literals.gentype_import2 then
let bundle =
"./"
^ Ext_filename.new_extension
Expand Down
8 changes: 5 additions & 3 deletions lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -181378,7 +181378,8 @@ let node_parent = ".."

let node_current = "."

let gentype_import = "genType.import"
let gentype_import1 = "genType.import"
let gentype_import2 = "gentype.import"

let bsbuild_cache = ".bsbuild"

Expand Down Expand Up @@ -276587,7 +276588,8 @@ let external_attrs =
"send";
"new";
"set_index";
Literals.gentype_import;
Literals.gentype_import1;
Literals.gentype_import2;
|]

let first_char_special (x : string) =
Expand Down Expand Up @@ -280433,7 +280435,7 @@ let parse_external_attributes (no_arguments : bool) (prim_name_check : string)

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