(aside from a slightly confusing issue title)
Imagine the following two files:
a.js:
import {Vector} from "mymath";
export function addWithoutOperatorOverloading(v1, v2) {
return v1 + v2;
}
with operators from Vector;
export function addWithOperatorOverloading(v1, v2) {
return v1 + v2;
}
b.js
import {addWithoutOperatorOverloading, addWithOperatorOverloading} from "./a.js";
import {Vector} from "mymath";
const v1 = new Vector(1, 2);
const v2 = new Vector(3, 4);
const r1 = addWithOperatorOverloading(v1, v2); // will work as intended
const r2 = addWithoutOperatorOverloading(v1, v2); // ???
const r3 = v1 + v2; // NaN because "with operators from" is not present in this file
what will r2 be? The with operators from statement in a.js is already parsed as addWithOperatorOverloading was used which is defined below that statement. Having the result depend on how far the file is parsed/executed would cause a lot of ambiguity and would be a hassle for the engine to sort out but having the statement have effects on higher lines in the file would clearly be unintentional.
And how are bundlers like rollup supposed to handle this? The following (naive, but in line with how bundlers work) approach would not be acceptable as it would cause intended leak of operator overloading into higher code:
bundle.js
import {Vector} from "mymath";
function addWithoutOperatorOverloading(v1, v2) {
return v1 + v2;
}
with operators from Vector;
function addWithOperatorOverloading(v1, v2) {
return v1 + v2;
}
const v1 = new Vector(1, 2);
const v2 = new Vector(3, 4);
const r1 = addWithOperatorOverloading(v1, v2); // will work as intended
const r2 = addWithoutOperatorOverloading(v1, v2); // ????
const r3 = v1 + v2; // suddenly the same as r1, clearly wrong
Here the value of r2 would be even more ambiguous as addWithoutOperatorOverloading is clearly called below the with operators from statement.
(aside from a slightly confusing issue title)
Imagine the following two files:
a.js:
b.js
what will r2 be? The
with operators fromstatement in a.js is already parsed asaddWithOperatorOverloadingwas used which is defined below that statement. Having the result depend on how far the file is parsed/executed would cause a lot of ambiguity and would be a hassle for the engine to sort out but having the statement have effects on higher lines in the file would clearly be unintentional.And how are bundlers like rollup supposed to handle this? The following (naive, but in line with how bundlers work) approach would not be acceptable as it would cause intended leak of operator overloading into higher code:
bundle.js
Here the value of r2 would be even more ambiguous as
addWithoutOperatorOverloadingis clearly called below thewith operators fromstatement.