[Bug]: rest operator produces global variables
See original GitHub issueš»
- Would you like to work on a fix?
How are you using Babel?
Programmatic API (babel.transform
, babel.parse
)
Input code
`export const Event = (function init() { function getsomething(){ let o = { āsiteIdsā:122, āsitenameā:ātestā, āsitecityā: āsan franā }; return o; } const { siteIds, ā¦rest } = getsomething();
return {getsomething}; })();
In v7.15.3 -> the compiled output creates a global variable called _excluded. in v7.13.17 -> the compiled output does not create a global variable, instead it places the array inline.
Is this expected? is there a way to turn this off and revert to use v7.13.17 behavior?
Multiple scripts will collide with same global variable.
Configuration file name
No response
Configuration
No response
Current and expected behavior
In v7.15.3 -> the compiled output creates a global variable called _excluded. in v7.13.17 -> the compiled output does not create a global variable, instead it places the array inline.
Is this expected? is there a way to turn this off and revert to use v7.13.17 behavior?
Multiple scripts will collide with same global variable.
Environment
Possible solution
No response
Additional context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Thanks for the responses. This issue arises from our setup actually. We are using babel to transpile typescript back to a 3rd party SaaS platform as javascript files. The final destination of the script files are recompiled into basically a single JS file for the sake of this argument.
Are there ways or options to work around this and keep the original behavior of inline placement of the variables?
Appreciate the help and assistance on this matter.
unexpected output
`āuse strictā;
Object.defineProperty(exports, ā__esModuleā, { value: true }); exports.Event = void 0; var _excluded = [āsiteIdsā];
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
var Event = function init() { function getsomething() { var o = { āsiteIdsā: 122, āsitenameā: ātestā, āsitecityā: āsan franā }; return o; }
var _getsomething = getsomething(), siteIds = _getsomething.siteIds, rest = _objectWithoutProperties(_getsomething, _excluded);
return { getsomething: getsomething }; }();
exports.Event = Event;`
Expected Output
āuse strictā;
Object.defineProperty(exports, ā__esModuleā, { value: true }); exports.Event = void 0;
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
var Event = function init() { function getsomething() { var o = { āsiteIdsā: 122, āsitenameā: ātestā, āsitecityā: āsan franā }; return o; }
var _getsomething = getsomething(), siteIds = _getsomething.siteIds, rest = _objectWithoutProperties(_getsomething, [āsiteIdsā]);
return { getsomething: getsomething }; }();
exports.Event = Event;