Skip to content

Commit 1af8505

Browse files
authored
GenType: ensure JS import works regardless moduleResolution (#6541)
1 parent c65f360 commit 1af8505

File tree

151 files changed

+354
-332
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+354
-332
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
- GenType: support `@deriving(accessors)` outputs. https://github.com/rescript-lang/rescript-compiler/pull/6537
1818
- Allow coercing ints and floats to unboxed variants that have a catch-all unboxed int or float case. https://github.com/rescript-lang/rescript-compiler/pull/6540
1919

20+
#### :bug: Bug Fix
21+
22+
- GenType: now emits full suffix on JS import path to be compatible with `.res.js`. https://github.com/rescript-lang/rescript-compiler/pull/6541
23+
2024
# 11.0.0-rc.8
2125

2226
#### :rocket: New Feature

jscomp/gentype/EmitJs.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ let emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName
247247
|> ModuleResolver.resolveModule ~config ~importExtension:config.suffix
248248
~outputFileRelative ~resolver ~useBsDependencies:false
249249
in
250-
let fileNameBs = fileName |> ModuleName.forBsFile in
250+
let fileNameJs = fileName |> ModuleName.forJsFile in
251251
let envWithRequires =
252-
fileNameBs |> requireModule ~import:false ~env ~importPath
252+
fileNameJs |> requireModule ~import:false ~env ~importPath
253253
in
254254
let default = "default" in
255255
let make = "make" in
@@ -358,7 +358,7 @@ let emitCodeItem ~config ~emitters ~moduleItemsEmitter ~env ~fileName
358358
| _ -> emitters
359359
in
360360
let emitters =
361-
(fileNameBs |> ModuleName.toString)
361+
(fileNameJs |> ModuleName.toString)
362362
^ "."
363363
^ (moduleAccessPath |> Runtime.emitModuleAccessPath ~config)
364364
|> EmitType.emitExportConst ~config ~docString ~early:false ~emitters

jscomp/gentype/EmitType.ml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -378,13 +378,6 @@ let emitImportValueAsEarly ~emitters ~name ~nameAs importPath =
378378

379379
let emitRequire ~importedValueOrComponent ~early ~emitters ~(config : Config.t)
380380
~moduleName importPath =
381-
let importPath =
382-
match config.moduleResolution with
383-
| Node ->
384-
importPath
385-
|> ImportPath.chopExtensionSafe (* for backward compatibility *)
386-
| _ -> importPath
387-
in
388381
let moduleNameString = ModuleName.toString moduleName in
389382
let importPathString = ImportPath.emit importPath in
390383
let output =

jscomp/gentype/ModuleName.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ let sanitizeId s =
1717
then s
1818
else "_" ^ s
1919

20-
let forBsFile s = sanitizeId s ^ "BS"
20+
let forJsFile s = sanitizeId s ^ "JS"
2121

2222
let forInnerModule ~fileName ~innerModuleName =
23-
(fileName |> forBsFile) ^ "." ^ innerModuleName
23+
(fileName |> forJsFile) ^ "." ^ innerModuleName
2424

2525
let fromStringUnsafe s = s
2626
let toString s = s

jscomp/gentype/ModuleName.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ type t
22

33
val compare : t -> t -> int
44
val curry : t
5-
val forBsFile : t -> t
5+
val forJsFile : t -> t
66
val forInnerModule : fileName:t -> innerModuleName:string -> t
77

88
val fromStringUnsafe : string -> t

jscomp/gentype_tests/typescript-react-example/.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55
],
66
"parser": "@typescript-eslint/parser",
77
"plugins": ["@typescript-eslint"],
8-
"ignorePatterns": ["src/**/*.bs.js"],
8+
"ignorePatterns": ["src/**/*.res.js"],
99
"root": true
1010
}

jscomp/gentype_tests/typescript-react-example/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ test:
77
npm run lint
88

99
clean:
10-
rm -rf node_modules lib src/*.bs.js src/*.gen.tsx
10+
rm -rf node_modules lib src/*.res.js src/*.gen.tsx
1111

1212
.DEFAULT_GOAL := test
1313

jscomp/gentype_tests/typescript-react-example/rescript.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@
2929
"module": "es6",
3030
"in-source": true
3131
},
32-
"suffix": ".bs.js"
32+
"suffix": ".res.js"
3333
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* eslint-disable */
44
/* tslint:disable */
55

6-
import * as CommentsBS from './Comments.bs';
6+
import * as CommentsJS from './Comments.res.js';
77

88
export type DecideSubject_payload = {
99
/** A hint to use as a guide when thinking of your poem. */
@@ -23,8 +23,8 @@ export type DecideSubject_output = {
2323
};
2424

2525
/** Decide on a subject matter for a poem. */
26-
export const DecideSubject__placeholder: (run:string, times:number) => void = CommentsBS.DecideSubject._placeholder as any;
26+
export const DecideSubject__placeholder: (run:string, times:number) => void = CommentsJS.DecideSubject._placeholder as any;
2727

2828
export const DecideSubject: {
2929
/** Decide on a subject matter for a poem. */
30-
_placeholder: (run:string, times:number) => void } = CommentsBS.DecideSubject as any;
30+
_placeholder: (run:string, times:number) => void } = CommentsJS.DecideSubject as any;

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,54 +19,54 @@ export const someFunWithNullUndefinedArgTypeChecked: (_1:(null | undefined | str
1919
// Export 'someFunWithNullUndefinedArg' early to allow circular import from the '.bs.js' file.
2020
export const someFunWithNullUndefinedArg: unknown = someFunWithNullUndefinedArgTypeChecked as (_1:(null | undefined | string), _2:number) => string as any;
2121

22-
const CoreBS = require('./Core.bs');
22+
const CoreJS = require('./Core.res.js');
2323

2424
export type variant = "A" | { TAG: "B"; _0: string };
2525

2626
export type t1 = { readonly x?: string };
2727

2828
export type t2 = { readonly x: (undefined | string) };
2929

30-
export const null0: (x:(null | number)) => (null | number) = CoreBS.null0 as any;
30+
export const null0: (x:(null | number)) => (null | number) = CoreJS.null0 as any;
3131

32-
export const null1: (x:(null | number)) => (null | number) = CoreBS.null1 as any;
32+
export const null1: (x:(null | number)) => (null | number) = CoreJS.null1 as any;
3333

34-
export const nullable0: (x:(null | undefined | number)) => (null | undefined | number) = CoreBS.nullable0 as any;
34+
export const nullable0: (x:(null | undefined | number)) => (null | undefined | number) = CoreJS.nullable0 as any;
3535

36-
export const nullable1: (x:(null | undefined | number)) => (null | undefined | number) = CoreBS.nullable1 as any;
36+
export const nullable1: (x:(null | undefined | number)) => (null | undefined | number) = CoreJS.nullable1 as any;
3737

38-
export const undefined0: (x:(undefined | number)) => (undefined | number) = CoreBS.undefined0 as any;
38+
export const undefined0: (x:(undefined | number)) => (undefined | number) = CoreJS.undefined0 as any;
3939

40-
export const undefined1: (x:(undefined | number)) => (undefined | number) = CoreBS.undefined1 as any;
40+
export const undefined1: (x:(undefined | number)) => (undefined | number) = CoreJS.undefined1 as any;
4141

42-
export const dict0: (x:{[id: string]: string}) => {[id: string]: string} = CoreBS.dict0 as any;
42+
export const dict0: (x:{[id: string]: string}) => {[id: string]: string} = CoreJS.dict0 as any;
4343

44-
export const dict1: (x:{[id: string]: string}) => {[id: string]: string} = CoreBS.dict1 as any;
44+
export const dict1: (x:{[id: string]: string}) => {[id: string]: string} = CoreJS.dict1 as any;
4545

46-
export const promise0: (x:Promise<string>) => Promise<string> = CoreBS.promise0 as any;
46+
export const promise0: (x:Promise<string>) => Promise<string> = CoreJS.promise0 as any;
4747

48-
export const promise1: (x:Promise<string>) => Promise<string> = CoreBS.promise1 as any;
48+
export const promise1: (x:Promise<string>) => Promise<string> = CoreJS.promise1 as any;
4949

50-
export const date0: (x:Date) => Date = CoreBS.date0 as any;
50+
export const date0: (x:Date) => Date = CoreJS.date0 as any;
5151

52-
export const date1: (x:Date) => Date = CoreBS.date1 as any;
52+
export const date1: (x:Date) => Date = CoreJS.date1 as any;
5353

54-
export const bigint0: (x:BigInt) => BigInt = CoreBS.bigint0 as any;
54+
export const bigint0: (x:BigInt) => BigInt = CoreJS.bigint0 as any;
5555

56-
export const bigint1: (x:BigInt) => BigInt = CoreBS.bigint1 as any;
56+
export const bigint1: (x:BigInt) => BigInt = CoreJS.bigint1 as any;
5757

58-
export const regexp0: (x:RegExp) => RegExp = CoreBS.regexp0 as any;
58+
export const regexp0: (x:RegExp) => RegExp = CoreJS.regexp0 as any;
5959

60-
export const regexp1: (x:RegExp) => RegExp = CoreBS.regexp1 as any;
60+
export const regexp1: (x:RegExp) => RegExp = CoreJS.regexp1 as any;
6161

62-
export const map1: (x:Map<string,number>) => Map<string,number> = CoreBS.map1 as any;
62+
export const map1: (x:Map<string,number>) => Map<string,number> = CoreJS.map1 as any;
6363

64-
export const weakmap1: (x:WeakMap<number[],number>) => WeakMap<number[],number> = CoreBS.weakmap1 as any;
64+
export const weakmap1: (x:WeakMap<number[],number>) => WeakMap<number[],number> = CoreJS.weakmap1 as any;
6565

66-
export const set1: (x:Set<string>) => Set<string> = CoreBS.set1 as any;
66+
export const set1: (x:Set<string>) => Set<string> = CoreJS.set1 as any;
6767

68-
export const weakset1: (x:WeakSet<number[]>) => WeakSet<number[]> = CoreBS.weakset1 as any;
68+
export const weakset1: (x:WeakSet<number[]>) => WeakSet<number[]> = CoreJS.weakset1 as any;
6969

70-
export const option0: (x:(undefined | string)) => (undefined | string) = CoreBS.option0 as any;
70+
export const option0: (x:(undefined | string)) => (undefined | string) = CoreJS.option0 as any;
7171

72-
export const option1: (x:(undefined | variant)) => (undefined | variant) = CoreBS.option1 as any;
72+
export const option1: (x:(undefined | variant)) => (undefined | variant) = CoreJS.option1 as any;

jscomp/gentype_tests/typescript-react-example/src/CreateErrorHandler1.bs.js renamed to jscomp/gentype_tests/typescript-react-example/src/CreateErrorHandler1.res.js

Lines changed: 1 addition & 1 deletion
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/CreateErrorHandler2.bs.js renamed to jscomp/gentype_tests/typescript-react-example/src/CreateErrorHandler2.res.js

Lines changed: 1 addition & 1 deletion
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/Derivings.gen.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
/* eslint-disable */
44
/* tslint:disable */
55

6-
import * as DerivingsBS from './Derivings.bs';
6+
import * as DerivingsJS from './Derivings.res.js';
77

88
export type action =
99
"Click"
1010
| "Cancel"
1111
| { TAG: "Submit"; _0: string };
1212

13-
export const click: action = DerivingsBS.click as any;
13+
export const click: action = DerivingsJS.click as any;
1414

15-
export const submit: (_1:string) => action = DerivingsBS.submit as any;
15+
export const submit: (_1:string) => action = DerivingsJS.submit as any;
1616

17-
export const cancel: action = DerivingsBS.cancel as any;
17+
export const cancel: action = DerivingsJS.cancel as any;

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

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,46 @@
33
/* eslint-disable */
44
/* tslint:disable */
55

6-
import * as DocstringsBS from './Docstrings.bs';
6+
import * as DocstringsJS from './Docstrings.res.js';
77

88
export type t = "A" | "B";
99

1010
/** hello */
11-
export const flat: number = DocstringsBS.flat as any;
11+
export const flat: number = DocstringsJS.flat as any;
1212

1313
/** \n * Sign a message with a key.\n *\n * @param message - A message to be signed\n * @param key - The key with which to sign the message\n * @returns A signed message\n */
14-
export const signMessage: (message:string, key:number) => string = DocstringsBS.signMessage as any;
14+
export const signMessage: (message:string, key:number) => string = DocstringsJS.signMessage as any;
1515

16-
export const one: (a:number) => number = DocstringsBS.one as any;
16+
export const one: (a:number) => number = DocstringsJS.one as any;
1717

18-
export const two: (a:number, b:number) => number = DocstringsBS.two as any;
18+
export const two: (a:number, b:number) => number = DocstringsJS.two as any;
1919

20-
export const tree: (a:number, b:number, c:number) => number = DocstringsBS.tree as any;
20+
export const tree: (a:number, b:number, c:number) => number = DocstringsJS.tree as any;
2121

22-
export const oneU: (a:number) => number = DocstringsBS.oneU as any;
22+
export const oneU: (a:number) => number = DocstringsJS.oneU as any;
2323

24-
export const twoU: (a:number, b:number) => number = DocstringsBS.twoU as any;
24+
export const twoU: (a:number, b:number) => number = DocstringsJS.twoU as any;
2525

26-
export const treeU: (a:number, b:number, c:number) => number = DocstringsBS.treeU as any;
26+
export const treeU: (a:number, b:number, c:number) => number = DocstringsJS.treeU as any;
2727

28-
export const useParam: (param:number) => number = DocstringsBS.useParam as any;
28+
export const useParam: (param:number) => number = DocstringsJS.useParam as any;
2929

30-
export const useParamU: (param:number) => number = DocstringsBS.useParamU as any;
30+
export const useParamU: (param:number) => number = DocstringsJS.useParamU as any;
3131

32-
export const unnamed1: (param:number) => number = DocstringsBS.unnamed1 as any;
32+
export const unnamed1: (param:number) => number = DocstringsJS.unnamed1 as any;
3333

34-
export const unnamed1U: (param:number) => number = DocstringsBS.unnamed1U as any;
34+
export const unnamed1U: (param:number) => number = DocstringsJS.unnamed1U as any;
3535

36-
export const unnamed2: (param_0:number, param_1:number) => number = DocstringsBS.unnamed2 as any;
36+
export const unnamed2: (param_0:number, param_1:number) => number = DocstringsJS.unnamed2 as any;
3737

38-
export const unnamed2U: (param_0:number, param_1:number) => number = DocstringsBS.unnamed2U as any;
38+
export const unnamed2U: (param_0:number, param_1:number) => number = DocstringsJS.unnamed2U as any;
3939

40-
export const grouped: (x:number, y:number, a:number, b:number, c:number, z:number) => number = DocstringsBS.grouped as any;
40+
export const grouped: (x:number, y:number, a:number, b:number, c:number, z:number) => number = DocstringsJS.grouped as any;
4141

42-
export const unitArgWithoutConversion: () => string = DocstringsBS.unitArgWithoutConversion as any;
42+
export const unitArgWithoutConversion: () => string = DocstringsJS.unitArgWithoutConversion as any;
4343

44-
export const unitArgWithoutConversionU: () => string = DocstringsBS.unitArgWithoutConversionU as any;
44+
export const unitArgWithoutConversionU: () => string = DocstringsJS.unitArgWithoutConversionU as any;
4545

46-
export const unitArgWithConversion: () => t = DocstringsBS.unitArgWithConversion as any;
46+
export const unitArgWithConversion: () => t = DocstringsJS.unitArgWithConversion as any;
4747

48-
export const unitArgWithConversionU: () => t = DocstringsBS.unitArgWithConversionU as any;
48+
export const unitArgWithConversionU: () => t = DocstringsJS.unitArgWithConversionU as any;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
/* eslint-disable */
44
/* tslint:disable */
55

6-
import * as EmitModuleIfNoConversionBS from './EmitModuleIfNoConversion.bs';
6+
import * as EmitModuleIfNoConversionJS from './EmitModuleIfNoConversion.res.js';
77

88
export type t = "A" | { TAG: "B"; readonly name: string };
99

10-
export const X_foo: (t:t) => void = EmitModuleIfNoConversionBS.X.foo as any;
10+
export const X_foo: (t:t) => void = EmitModuleIfNoConversionJS.X.foo as any;
1111

12-
export const X_x: number = EmitModuleIfNoConversionBS.X.x as any;
12+
export const X_x: number = EmitModuleIfNoConversionJS.X.x as any;
1313

14-
export const Y_x: string = EmitModuleIfNoConversionBS.Y.x as any;
14+
export const Y_x: string = EmitModuleIfNoConversionJS.Y.x as any;
1515

16-
export const Y: { x: string } = EmitModuleIfNoConversionBS.Y as any;
16+
export const Y: { x: string } = EmitModuleIfNoConversionJS.Y as any;
1717

18-
export const X: { x: number; foo: (t:t) => void } = EmitModuleIfNoConversionBS.X as any;
18+
export const X: { x: number; foo: (t:t) => void } = EmitModuleIfNoConversionJS.X as any;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
import * as React from 'react';
77

8-
import * as ExportWithRenameBS from './ExportWithRename.bs';
8+
import * as ExportWithRenameJS from './ExportWithRename.res.js';
99

1010
export type Props = { readonly s: string };
1111

12-
export const Renamed: React.ComponentType<{ readonly s: string }> = ExportWithRenameBS.make as any;
12+
export const Renamed: React.ComponentType<{ readonly s: string }> = ExportWithRenameJS.make as any;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* eslint-disable */
44
/* tslint:disable */
55

6-
import * as FirstClassModulesBS from './FirstClassModules.bs';
6+
import * as FirstClassModulesJS from './FirstClassModules.res.js';
77

88
export type MT_t = number;
99

@@ -23,7 +23,7 @@ export type firstClassModule = {
2323
readonly y: string
2424
};
2525

26-
export const firstClassModule: firstClassModule = FirstClassModulesBS.firstClassModule as any;
26+
export const firstClassModule: firstClassModule = FirstClassModulesJS.firstClassModule as any;
2727

2828
export const testConvert: (m:{
2929
readonly x: number;
@@ -49,7 +49,7 @@ export const testConvert: (m:{
4949
};
5050
readonly Z: unknown;
5151
readonly y: string
52-
} = FirstClassModulesBS.testConvert as any;
52+
} = FirstClassModulesJS.testConvert as any;
5353

5454
export const someFunctorAsFunction: (x:{
5555
readonly x: number;
@@ -63,4 +63,4 @@ export const someFunctorAsFunction: (x:{
6363
};
6464
readonly Z: unknown;
6565
readonly y: string
66-
}) => { readonly ww: string } = FirstClassModulesBS.someFunctorAsFunction as any;
66+
}) => { readonly ww: string } = FirstClassModulesJS.someFunctorAsFunction as any;

0 commit comments

Comments
 (0)