Skip to content

Commit b5aec26

Browse files
authored
eager evaluate js_program (#6191)
1 parent faf65be commit b5aec26

File tree

7 files changed

+49
-51
lines changed

7 files changed

+49
-51
lines changed
Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,33 @@
1-
// https://github.com/rescript-lang/rescript-compiler/pull/5703#issuecomment-1518507161
2-
// const fs = require('fs')
3-
// const path = require('path')
4-
// const child_process = require('child_process')
5-
// const rescript_exe = require("../../../scripts/bin_path").rescript_exe
1+
const fs = require('fs')
2+
const path = require('path')
3+
const child_process = require('child_process')
4+
const rescript_exe = require("../../../scripts/bin_path").rescript_exe
65

7-
// const expectedFilePath = path.join(__dirname, 'out.expected')
6+
const expectedFilePath = path.join(__dirname, 'out.expected')
87

9-
// const updateTests = process.argv[2] === 'update'
8+
const updateTests = process.argv[2] === 'update'
109

11-
// function postProcessErrorOutput (output) {
12-
// output = output.trimRight()
13-
// output = output.replace(new RegExp(__dirname, 'gi'), '.')
14-
// return output
15-
// }
16-
// child_process.execSync(`${rescript_exe} clean -with-deps`,{cwd:__dirname})
17-
// child_process.exec(rescript_exe, {cwd: __dirname}, (err, stdout, stderr) => {
18-
// const actualErrorOutput = postProcessErrorOutput(stderr.toString())
19-
// if (updateTests) {
20-
// fs.writeFileSync(expectedFilePath, actualErrorOutput)
21-
// } else {
22-
// const expectedErrorOutput = postProcessErrorOutput(fs.readFileSync(expectedFilePath, {encoding: 'utf-8'}))
23-
// if (expectedErrorOutput !== actualErrorOutput) {
24-
// console.error(`The old and new error output aren't the same`)
25-
// console.error('\n=== Old:')
26-
// console.error(expectedErrorOutput)
27-
// console.error('\n=== New:')
28-
// console.error(actualErrorOutput)
29-
// process.exit(1)
30-
// }
31-
// }
32-
// })
10+
function postProcessErrorOutput (output) {
11+
output = output.trimRight()
12+
output = output.replace(new RegExp(__dirname, 'gi'), '.')
13+
return output
14+
}
15+
child_process.execSync(`${rescript_exe} clean -with-deps`,{cwd:__dirname})
16+
child_process.exec(rescript_exe, {cwd: __dirname}, (err, stdout, stderr) => {
17+
const actualErrorOutput = postProcessErrorOutput(stderr.toString())
18+
if (updateTests) {
19+
fs.writeFileSync(expectedFilePath, actualErrorOutput)
20+
} else {
21+
const expectedErrorOutput = postProcessErrorOutput(fs.readFileSync(expectedFilePath, {encoding: 'utf-8'}))
22+
if (expectedErrorOutput !== actualErrorOutput) {
23+
console.error(`The old and new error output aren't the same`)
24+
console.error('\n=== Old:')
25+
console.error(expectedErrorOutput)
26+
console.error('\n=== New:')
27+
console.error(actualErrorOutput)
28+
process.exit(1)
29+
}
30+
}
31+
})
3332

3433

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
// https://github.com/rescript-lang/rescript-compiler/pull/5703#issuecomment-1518507161
2-
// //@ts-check
3-
// var child_process = require("child_process");
4-
// var assert = require("assert");
5-
// var fs = require("fs")
6-
// var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
1+
//@ts-check
2+
var child_process = require("child_process");
3+
var assert = require("assert");
4+
var fs = require("fs")
5+
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
76

8-
// console.log(child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }));
7+
console.log(child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }));
98

10-
// assert(fs.existsSync("./node_modules/c/lib/js/tests/test.mjs"), "dev files of module 'c' were not built by 'a' even though 'c' is a transitive pinned dependency of 'a' through 'b'")
9+
assert(fs.existsSync("./node_modules/c/lib/js/tests/test.mjs"), "dev files of module 'c' were not built by 'a' even though 'c' is a transitive pinned dependency of 'a' through 'b'")
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
// https://github.com/rescript-lang/rescript-compiler/pull/5703#issuecomment-1518507161
2-
// //@ts-check
3-
// var child_process = require("child_process");
4-
// var assert = require("assert");
5-
// var fs = require("fs")
6-
// var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
1+
//@ts-check
2+
var child_process = require("child_process");
3+
var assert = require("assert");
4+
var fs = require("fs")
5+
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
76

8-
// console.log(child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }));
7+
console.log(child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }));
98

10-
// assert(!fs.existsSync("./node_modules/c/lib/js/tests/test.mjs"), "dev files of module 'c' were built by 'a' even though 'c' is not a pinned dependency of 'a'")
9+
assert(!fs.existsSync("./node_modules/c/lib/js/tests/test.mjs"), "dev files of module 'c' were built by 'a' even though 'c' is not a pinned dependency of 'a'")

jscomp/core/js_implementation.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) =
164164
let lambda, exports =
165165
Translmod.transl_implementation modulename typedtree_coercion
166166
in
167-
let js_program ~module_system =
167+
let js_program =
168168
print_if_pipe ppf Clflags.dump_rawlambda Printlambda.lambda lambda
169-
|> Lam_compile_main.compile outputprefix module_system exports
169+
|> Lam_compile_main.compile outputprefix NodeJS exports
170170
in
171171
if not !Js_config.cmj_only then
172172
Lam_compile_main.lambda_as_module js_program outputprefix);

jscomp/core/lam_compile_main.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,18 +288,18 @@ js
288288
let (//) = Filename.concat
289289

290290
let lambda_as_module
291-
(lambda_output : module_system: Js_packages_info.module_system -> J.deps_program)
291+
(lambda_output : J.deps_program)
292292
(output_prefix : string)
293293
: unit =
294294
let package_info = Js_packages_state.get_packages_info () in
295295
if Js_packages_info.is_empty package_info && !Js_config.js_stdout then begin
296-
Js_dump_program.dump_deps_program ~output_prefix NodeJS (lambda_output ~module_system: NodeJS) stdout
296+
Js_dump_program.dump_deps_program ~output_prefix NodeJS (lambda_output) stdout
297297
end else
298298
Js_packages_info.iter package_info (fun {module_system; path; suffix} ->
299299
let output_chan chan =
300300
Js_dump_program.dump_deps_program ~output_prefix
301301
module_system
302-
(lambda_output ~module_system)
302+
(lambda_output)
303303
chan in
304304
let basename =
305305
Ext_namespace.change_ext_ns_suffix

jscomp/core/lam_compile_main.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ val compile : string -> Js_packages_info.module_system -> Ident.t list -> Lambda
3232
{!Env.get_unit_name ()}
3333
*)
3434

35-
val lambda_as_module : (module_system: Js_packages_info.module_system -> J.deps_program) -> string -> unit
35+
val lambda_as_module : J.deps_program -> string -> unit

jscomp/test/Import.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)