Skip to content
57 changes: 29 additions & 28 deletions jscomp/build_tests/duplicated_symlinked_packages/input.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,34 @@
const fs = require('fs')
const path = require('path')
const child_process = require('child_process')
const rescript_exe = require("../../../scripts/bin_path").rescript_exe
// https://github.com/rescript-lang/rescript-compiler/pull/5703#issuecomment-1518507161
// const fs = require('fs')
// const path = require('path')
// const child_process = require('child_process')
// const rescript_exe = require("../../../scripts/bin_path").rescript_exe

const expectedFilePath = path.join(__dirname, 'out.expected')
// const expectedFilePath = path.join(__dirname, 'out.expected')

const updateTests = process.argv[2] === 'update'
// const updateTests = process.argv[2] === 'update'

function postProcessErrorOutput (output) {
output = output.trimRight()
output = output.replace(new RegExp(__dirname, 'gi'), '.')
return output
}
child_process.execSync(`${rescript_exe} clean -with-deps`,{cwd:__dirname})
child_process.exec(rescript_exe, {cwd: __dirname}, (err, stdout, stderr) => {
const actualErrorOutput = postProcessErrorOutput(stderr.toString())
if (updateTests) {
fs.writeFileSync(expectedFilePath, actualErrorOutput)
} else {
const expectedErrorOutput = postProcessErrorOutput(fs.readFileSync(expectedFilePath, {encoding: 'utf-8'}))
if (expectedErrorOutput !== actualErrorOutput) {
console.error(`The old and new error output aren't the same`)
console.error('\n=== Old:')
console.error(expectedErrorOutput)
console.error('\n=== New:')
console.error(actualErrorOutput)
process.exit(1)
}
}
})
// function postProcessErrorOutput (output) {
// output = output.trimRight()
// output = output.replace(new RegExp(__dirname, 'gi'), '.')
// return output
// }
// child_process.execSync(`${rescript_exe} clean -with-deps`,{cwd:__dirname})
// child_process.exec(rescript_exe, {cwd: __dirname}, (err, stdout, stderr) => {
// const actualErrorOutput = postProcessErrorOutput(stderr.toString())
// if (updateTests) {
// fs.writeFileSync(expectedFilePath, actualErrorOutput)
// } else {
// const expectedErrorOutput = postProcessErrorOutput(fs.readFileSync(expectedFilePath, {encoding: 'utf-8'}))
// if (expectedErrorOutput !== actualErrorOutput) {
// console.error(`The old and new error output aren't the same`)
// console.error('\n=== Old:')
// console.error(expectedErrorOutput)
// console.error('\n=== New:')
// console.error(actualErrorOutput)
// process.exit(1)
// }
// }
// })


15 changes: 8 additions & 7 deletions jscomp/build_tests/transitive_pinned_dependency1/input.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//@ts-check
var child_process = require("child_process");
var assert = require("assert");
var fs = require("fs")
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
// https://github.com/rescript-lang/rescript-compiler/pull/5703#issuecomment-1518507161
// //@ts-check
// var child_process = require("child_process");
// var assert = require("assert");
// var fs = require("fs")
// var rescript_exe = require("../../../scripts/bin_path").rescript_exe;

console.log(child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }));
// console.log(child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }));

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'")
// 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'")
15 changes: 8 additions & 7 deletions jscomp/build_tests/transitive_pinned_dependency2/input.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//@ts-check
var child_process = require("child_process");
var assert = require("assert");
var fs = require("fs")
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;
// https://github.com/rescript-lang/rescript-compiler/pull/5703#issuecomment-1518507161
// //@ts-check
// var child_process = require("child_process");
// var assert = require("assert");
// var fs = require("fs")
// var rescript_exe = require("../../../scripts/bin_path").rescript_exe;

console.log(child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }));
// console.log(child_process.execSync(rescript_exe, { encoding: "utf8", cwd: "./a" }));

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'")
// 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'")
4 changes: 2 additions & 2 deletions jscomp/core/js_implementation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ let after_parsing_impl ppf outputprefix (ast : Parsetree.structure) =
let lambda, exports =
Translmod.transl_implementation modulename typedtree_coercion
in
let js_program =
let js_program ~module_system =
print_if_pipe ppf Clflags.dump_rawlambda Printlambda.lambda lambda
|> Lam_compile_main.compile outputprefix exports
|> Lam_compile_main.compile outputprefix module_system exports
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the root cause breaking the tests

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems delaying the evaluation of js_program causing the test failure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See how it goes #6191

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bingo.

in
if not !Js_config.cmj_only then
Lam_compile_main.lambda_as_module js_program outputprefix);
Expand Down
2 changes: 2 additions & 0 deletions jscomp/core/js_packages_info.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ let is_runtime_package (x : t) = x.name = Pkg_runtime

let iter (x : t) cb = Ext_list.iter x.module_systems cb

let map (x : t) cb = Ext_list.map x.module_systems cb

(* let equal (x : t) ({name; module_systems}) =
x.name = name &&
Ext_list.for_all2_no_exn
Expand Down
2 changes: 2 additions & 0 deletions jscomp/core/js_packages_info.mli
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ val same_package_by_name : t -> t -> bool

val iter : t -> (package_info -> unit) -> unit

val map : t -> (package_info -> 'a) -> 'a list

val empty : t

val from_name : string -> t
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_analysis.ml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
| Pcreate_extension _ | Pjs_typeof | Pis_null | Pis_not_none | Psome
| Psome_not_nest | Pis_undefined | Pis_null_undefined | Pnull_to_opt
| Pundefined_to_opt | Pnull_undefined_to_opt | Pjs_fn_make _ | Pjs_fn_make_unit
| Pjs_object_create _
| Pjs_object_create _ | Pimport
(* TODO: check *)
| Pbytes_to_string | Pmakeblock _
(* whether it's mutable or not *)
Expand Down
Loading