New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rollup removes correct code #3264
Comments
Rollup handles |
Actually this is what Rollup does for ALL function calls at the moment. The reason is performance, as previous attempts at this turned out to have a very negative effect. This might change in the future, but probably not for console.log. |
Sorry, I read this the wrong way around. The reason it is removed is of course that the condition is always true. |
Actually my code is more complex that this and it seems impossible to me to predict the axis because it depends of the content. And even in this case the condition is removed. When testing the code I don't have the same result if I add the console.log or remove it. My code is only working if I leave this console.log inside. export function fromSIV(content) {
let allLines = content.split(/[\r\n]+/);
let sampleMeta = parseS(allLines.filter((line) => line.match(/X S_/)));
let instrumentMeta = parseV(allLines.filter((line) => line.match(/X V_/)));
let date = parseDate(allLines.filter((line) => line.match(/X d_t/))[0]);
let parts = content.split('WAVES\t');
let spectra = [];
for (let part of parts) {
let lines = part.split(/[\r\n]+/);
let ys = lines
.filter((line) => line.match(/^[\t 0-9.eE-]+$/))
.map((line) => Number(line));
if (ys.length < 10) continue;
let kind = lines[0].trim();
let metaLines = lines
.filter((line) => line.match(/^X /))
.map((line) => line.substring(2));
let axis = parseScale(metaLines[0], ys.length);
// removing the following line corrupt the build ???!!!
// console.log(axis);
if (axis.x === undefined || axis.x.unit !== 'V') {
// eslint-disable-next-line no-console
console.log('Unknown X axis:', axis.kind, axis.unit);
continue;
}
if (axis.y === undefined || axis.y.unit !== 'A') {
// eslint-disable-next-line no-console
console.log('Unknown Y axis:', axis.kind, axis.unit);
continue;
}
// let note = parseNote(metaLines[1]);
let xs = axis.x.values;
let data = {
x: xs,
y: ys,
};
let meta = {
...sampleMeta,
date,
experiment: kind,
...instrumentMeta,
};
console.log({ meta });
spectra.push(new Spectrum(data.x, data.y, spectra.length + 1, { meta }));
}
return spectra;
}
function parseDate(line) {
let dateString = line
.replace('X d_t=', '')
.trim()
.replace(/"/g, '');
let date = new Date(dateString);
return date;
}
function parseScale(line, nbValues) {
let result = {};
line = line.replace(/ ([xy]) /g, ',$1,');
let parts = line.split('; ');
for (let part of parts) {
let parsedPart = parseScalePart(part, nbValues);
result[parsedPart.axis] = parsedPart;
}
return result;
}
function parseS(lines) {
let result = {};
for (let line of lines) {
let key = line.replace(/X ._([^=]*)=(.*)/, '$1').trim();
key = getFieldName(key);
let value = line.replace(/X ._([^=]*)=(.*)/, '$2').trim();
value = value.replace(/^"(.*)"$/, '$1');
if (!isNaN(value)) value = Number(value);
result[key] = value;
}
return result;
}
function parseV(lines) {
let result = {};
for (let line of lines) {
let key = line.replace(/X ._([^=]*)=(.*)/, '$1').trim();
key = getFieldName(key);
let value = line.replace(/X ._([^=]*)=(.*)/, '$2').trim();
value = value.replace(/^"(.*)"$/, '$1');
if (!isNaN(value)) value = Number(value);
result[key] = value;
}
return result;
}
// eslint-disable-next-line no-unused-vars
function parseNote(line) {
line = line.replace(/"/g, '').replace(/\\r/g, ';');
let parts = line.split(/ *[;,] */);
let result = {};
for (let part of parts) {
let semiColumn = part.indexOf(':');
let key = part.substring(0, semiColumn);
key = getFieldName(key);
let value = part.substring(semiColumn + 1).trim();
value = value.replace(/^"(.*)"$/, '$1');
if (!isNaN(value)) value = Number(value);
if (!key) continue;
result[key] = value;
}
}
function parseScalePart(scale, nbValues) {
let parts = scale.split(',');
let result = {};
result.axis = parts[1];
result.kind = parts[0];
result.unit = parts[4].replace(/"/g, '');
if (result.kind === 'SetScale/P') {
let from = Number(parts[2]);
let step = Number(parts[3]);
let values = [];
for (let i = 0; i < nbValues; i++) {
values.push(from);
from += step;
result.values = values;
}
}
return result;
}
function getFieldName(key) {
const mapping = {
CE: 'counterElectrodeType',
Calibrationfile: 'calibrationFile',
Username: 'username',
WE: 'workingElectrodeGlass',
cellname: 'cellname',
electrolyte: 'electrolyteZ960',
layer: 'semicondutorLayer',
specification: 'remarks',
temp: 'workingTemperature',
type: 'typeOfCell',
AR: 'cellActiveArea',
IT: 'powerIn',
};
return mapping[key] || key;
} |
Here is a code that you can actually test and run in node: If you run the code there will be written If you remove fromSIV(`BEGIN
0.0022139272
0.0023900089
0.002451069
3.2340083e-08
2.5559748e-08
1.623679e-08
4.3712021e-09
END
X SetScale/P x 1.19,-0.01,"V", DarkCurrent; SetScale y 0,0,"A", DarkCurrent
X Note DarkCurrent, "IT:0.101656;AR:0.158;FT:7e-06;CM:0.002;ST:0.1;SV:1.19;ET:0"
`);
function fromSIV(content) {
let allLines = content.split(/[\r\n]+/);
let sampleMeta = parseS(allLines.filter((line) => line.match(/X S_/)));
let instrumentMeta = parseV(allLines.filter((line) => line.match(/X V_/)));
let parts = content.split('WAVES\t');
let spectra = [];
for (let part of parts) {
let lines = part.split(/[\r\n]+/);
let ys = lines
.filter((line) => line.match(/^[\t 0-9.eE-]+$/))
.map((line) => Number(line));
let kind = lines[0].trim();
let metaLines = lines
.filter((line) => line.match(/^X /))
.map((line) => line.substring(2));
console.log({ metaLines });
let axis = parseScale(metaLines[0], ys.length);
// removing the following line corrupt the build ???!!!
console.log(axis);
if (axis.x === undefined || axis.x.unit !== 'V') {
// eslint-disable-next-line no-console
console.log('Unknown X axis:', axis.kind, axis.unit);
continue;
}
if (axis.y === undefined || axis.y.unit !== 'A') {
// eslint-disable-next-line no-console
console.log('Unknown Y axis:', axis.kind, axis.unit);
continue;
}
console.log('IT WORKS');
// let note = parseNote(metaLines[1]);
let xs = axis.x.values;
let data = {
x: xs,
y: ys,
};
let meta = {
...sampleMeta,
experiment: kind,
...instrumentMeta,
};
}
return spectra;
}
function parseScale(line, nbValues) {
console.log(line);
let result = {};
line = line.replace(/ ([xy]) /g, ',$1,');
let parts = line.split('; ');
for (let part of parts) {
let parsedPart = parseScalePart(part, nbValues);
result[parsedPart.axis] = parsedPart;
}
return result;
}
function parseS(lines) {
let result = {};
for (let line of lines) {
let key = line.replace(/X ._([^=]*)=(.*)/, '$1').trim();
key = getFieldName(key);
let value = line.replace(/X ._([^=]*)=(.*)/, '$2').trim();
value = value.replace(/^"(.*)"$/, '$1');
if (!isNaN(value)) value = Number(value);
result[key] = value;
}
return result;
}
function parseV(lines) {
let result = {};
for (let line of lines) {
let key = line.replace(/X ._([^=]*)=(.*)/, '$1').trim();
key = getFieldName(key);
let value = line.replace(/X ._([^=]*)=(.*)/, '$2').trim();
value = value.replace(/^"(.*)"$/, '$1');
if (!isNaN(value)) value = Number(value);
result[key] = value;
}
return result;
}
// eslint-disable-next-line no-unused-vars
function parseNote(line) {
line = line.replace(/"/g, '').replace(/\\r/g, ';');
let parts = line.split(/ *[;,] */);
let result = {};
for (let part of parts) {
let semiColumn = part.indexOf(':');
let key = part.substring(0, semiColumn);
key = getFieldName(key);
let value = part.substring(semiColumn + 1).trim();
value = value.replace(/^"(.*)"$/, '$1');
if (!isNaN(value)) value = Number(value);
if (!key) continue;
result[key] = value;
}
}
function parseScalePart(scale, nbValues) {
let parts = scale.split(',');
let result = {};
result.axis = parts[1];
result.kind = parts[0];
result.unit = parts[4].replace(/"/g, '');
if (result.kind === 'SetScale/P') {
let from = Number(parts[2]);
let step = Number(parts[3]);
let values = [];
for (let i = 0; i < nbValues; i++) {
values.push(from);
from += step;
result.values = values;
}
}
return result;
}
function getFieldName(key) {
const mapping = {
CE: 'counterElectrodeType',
Calibrationfile: 'calibrationFile',
Username: 'username',
WE: 'workingElectrodeGlass',
cellname: 'cellname',
electrolyte: 'electrolyteZ960',
layer: 'semicondutorLayer',
specification: 'remarks',
temp: 'workingTemperature',
type: 'typeOfCell',
AR: 'cellActiveArea',
IT: 'powerIn',
};
return mapping[key] || key;
} |
This bug was introduced between version 1.9.2 and 1.9.3. Commit: v1.9.2...v1.9.3 |
Definitely a bug, thanks for spotting. I will see if I can reduce it further. |
Here is a very simplified version. It is indeed a tricky bug: Note that when the function is moved to the top, the bug is not triggered: I hope I find some time soon to look into this further. |
I just tested it and I can confirm it works correctly using this PR |
* Workaround for various object literal mutation bugs. Some necessary minor regressions related to previously unsafe object literal optimizations. fixes #2345 fixes #2473 fixes #3027 fixes #3093 fixes #3192 fixes #3264 * Remove special logic to handle deoptimizing properties, always deopt `this` by default
How Do We Reproduce?
Can be reproduce on repl
Demo
rollup with remove the condition
(axis.x === undefined || axis.x.unit !== 'V')
but will not remove it if you uncomment the lineconsole.log(axis)
Expected Behavior
Should convert to
Actual Behavior
Returns
The condition has disappeared only if you comment the console.log(axis);
The text was updated successfully, but these errors were encountered: