Skip to content

Commit

Permalink
Assume that accessing members of a pure global function or its prototype
Browse files Browse the repository at this point in the history
is never a side-effect.
  • Loading branch information
lukastaegert committed Nov 8, 2017
1 parent 75f36d1 commit ba7f8b2
Show file tree
Hide file tree
Showing 17 changed files with 631 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/ast/nodes/CallExpression.js
@@ -1,6 +1,5 @@
import Node from '../Node.js';
import CallOptions from '../CallOptions';
import ExecutionPathOptions from '../ExecutionPathOptions';

export default class CallExpression extends Node {
bindAssignmentAtPath ( path, expression, options ) {
Expand Down
1 change: 0 additions & 1 deletion src/ast/nodes/NewExpression.js
@@ -1,6 +1,5 @@
import Node from '../Node.js';
import CallOptions from '../CallOptions';
import ExecutionPathOptions from '../ExecutionPathOptions';

export default class NewExpression extends Node {
hasEffects ( options ) {
Expand Down
6 changes: 5 additions & 1 deletion src/ast/variables/GlobalVariable.js
Expand Up @@ -17,7 +17,11 @@ export default class GlobalVariable extends Variable {
hasEffectsWhenAccessedAtPath ( path ) {
// 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 ].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');
}

hasEffectsWhenCalledAtPath ( path ) {
Expand Down
@@ -0,0 +1,5 @@
var path = require('path');

module.exports = {
description: 'accessing members of pure functions and their prototypes is not a side-effect'
};
@@ -0,0 +1,6 @@
define(function () { 'use strict';

Unknown.staticMember;
Unknown.prototype.method;

});
@@ -0,0 +1,4 @@
'use strict';

Unknown.staticMember;
Unknown.prototype.method;
@@ -0,0 +1,2 @@
Unknown.staticMember;
Unknown.prototype.method;
@@ -0,0 +1,7 @@
(function () {
'use strict';

Unknown.staticMember;
Unknown.prototype.method;

}());
@@ -0,0 +1,10 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
}(this, (function () { 'use strict';

Unknown.staticMember;
Unknown.prototype.method;

})));
@@ -0,0 +1,6 @@
Symbol.iterator;
Array.prototype.reverse;
Object.prototype.hasOwnProperty;

Unknown.staticMember;
Unknown.prototype.method;
5 changes: 5 additions & 0 deletions test/form/samples/removes-unused-babel-helpers/_config.js
@@ -0,0 +1,5 @@
const assert = require( 'assert' );

module.exports = {
description: 'Removes unused babel helpers from the build (#1595)'
};
@@ -0,0 +1,5 @@
define(function () { 'use strict';



});
@@ -0,0 +1,2 @@
'use strict';

@@ -0,0 +1 @@

@@ -0,0 +1,6 @@
(function () {
'use strict';



}());
@@ -0,0 +1,9 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
}(this, (function () { 'use strict';



})));

0 comments on commit ba7f8b2

Please sign in to comment.