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
}

0 commit comments

Comments
 (0)