💻
How are you using Babel?
Programmatic API (babel.transform, babel.parse)
Input code
This is a complete standalone reproduction:
const babel = require("@babel/core");
const assert = require("assert");
let src = `
function example() {
let value = [];
value.push(Math.random());
return value;
}
`;
babel.transform(src, {
plugins: [
function () {
return {
visitor: {
ReturnStatement(path) {
let result = path.get("argument").evaluate();
assert.equal(result.confident, false);
},
},
};
},
],
});
Configuration file name
No response
Configuration
No response
Current and expected behavior
The assertion in my repro program above fails, because Babel believes it can statically evaluate the value of the return statement. path.evaluate() returns { confident: true, depot: null, value: [] }.
Instead, it should return { confident: false }, because it's not possible to statically determine the return value of this code snippet.
Environment
Tested against @babel/core 7.16.12 in Node 16.
Possible solution
No response
Additional context
No response
💻
How are you using Babel?
Programmatic API (
babel.transform,babel.parse)Input code
This is a complete standalone reproduction:
Configuration file name
No response
Configuration
No response
Current and expected behavior
The assertion in my repro program above fails, because Babel believes it can statically evaluate the value of the return statement.
path.evaluate()returns{ confident: true, depot: null, value: [] }.Instead, it should return
{ confident: false }, because it's not possible to statically determine the return value of this code snippet.Environment
Tested against
@babel/core7.16.12 in Node 16.Possible solution
No response
Additional context
No response