Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge branch 'treeshake-babel-helpers' into release-0.53.4
  • Loading branch information
lukastaegert committed Jan 10, 2018
2 parents 25c1588 + 89149b6 commit 7b6686b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
17 changes: 9 additions & 8 deletions src/ast/variables/GlobalVariable.ts
Expand Up @@ -21,18 +21,19 @@ export default class GlobalVariable extends Variable {
hasEffectsWhenAccessedAtPath (path: ObjectPath) {
// path.length == 0 can also have an effect but we postpone this for now
return (
path.length > 0 &&
!pureFunctions[[this.name, ...path].join('.')] &&
!pureFunctions[[this.name, ...path.slice(0, -1)].join('.')] &&
!(
path.length > 1 &&
pureFunctions[[this.name, ...path.slice(0, -2)].join('.')] &&
path[path.length - 2] === 'prototype'
)
path.length > 0
&& !this.isPureFunctionMember(path)
&& !(this.name === 'Reflect' && path.length === 1)
);
}

hasEffectsWhenCalledAtPath (path: ObjectPath) {
return !pureFunctions[[this.name, ...path].join('.')];
}

private isPureFunctionMember (path: ObjectPath) {
return pureFunctions[[this.name, ...path].join('.')]
|| (path.length >= 1 && pureFunctions[[this.name, ...path.slice(0, -1)].join('.')])
|| (path.length >= 2 && pureFunctions[[this.name, ...path.slice(0, -2)].join('.')] && path[path.length - 2] === 'prototype');
}
}
2 changes: 1 addition & 1 deletion test/form/samples/removes-unused-babel-helpers/_config.js
@@ -1,5 +1,5 @@
const assert = require( 'assert' );

module.exports = {
description: 'Removes unused babel helpers from the build (#1595)'
description: 'Removes unused babel helpers from the build (#1595)',
};
13 changes: 13 additions & 0 deletions test/form/samples/removes-unused-babel-helpers/main.js
Expand Up @@ -5,6 +5,19 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};

var _sPO = Object.setPrototypeOf || function _sPO(o, p) {
o.__proto__ = p;
return o;
};

var _construct = typeof Reflect === "object" && Reflect.construct || function _construct(Parent, args, Class) {
var Constructor,
a = [null];
a.push.apply(a, args);
Constructor = Parent.bind.apply(Parent, a);
return _sPO(new Constructor(), Class.prototype);
};

var jsx = function () {
var REACT_ELEMENT_TYPE = typeof Symbol === "function" && Symbol.for && Symbol.for("react.element") || 0xeac7;
return function createRawReactElement(type, props, key, children) {
Expand Down

0 comments on commit 7b6686b

Please sign in to comment.