-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1017 from Pauan/tree-shake-pure-es5-classes
Removes `new Foo(...)` when Foo is a pure function
- Loading branch information
Showing
25 changed files
with
274 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
description: 'omits ES5 classes which are pure (e.g. they only assign to `this`)' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
define(function () { 'use strict'; | ||
|
||
function Bar ( x ) { | ||
console.log( 'side effect' ); | ||
this.value = x; | ||
} | ||
|
||
function Baz ( x ) { | ||
this[ console.log( 'side effect' ) ] = x; | ||
} | ||
|
||
function Qux ( x ) { | ||
this.value = console.log( 'side effect' ); | ||
} | ||
|
||
function Corge ( x ) { | ||
this.value = x; | ||
} | ||
|
||
var Arrow = ( x ) => { | ||
undefined.value = x; | ||
}; | ||
|
||
console.log( 'before' ); | ||
|
||
var bar = new Bar(5); | ||
var baz = new Baz(5); | ||
var qux = new Qux(5); | ||
var corge = Corge(5); | ||
var arrow = new Arrow(5); | ||
|
||
console.log( 'after' ); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict'; | ||
|
||
function Bar ( x ) { | ||
console.log( 'side effect' ); | ||
this.value = x; | ||
} | ||
|
||
function Baz ( x ) { | ||
this[ console.log( 'side effect' ) ] = x; | ||
} | ||
|
||
function Qux ( x ) { | ||
this.value = console.log( 'side effect' ); | ||
} | ||
|
||
function Corge ( x ) { | ||
this.value = x; | ||
} | ||
|
||
var Arrow = ( x ) => { | ||
undefined.value = x; | ||
}; | ||
|
||
console.log( 'before' ); | ||
|
||
var bar = new Bar(5); | ||
var baz = new Baz(5); | ||
var qux = new Qux(5); | ||
var corge = Corge(5); | ||
var arrow = new Arrow(5); | ||
|
||
console.log( 'after' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
function Bar ( x ) { | ||
console.log( 'side effect' ); | ||
this.value = x; | ||
} | ||
|
||
function Baz ( x ) { | ||
this[ console.log( 'side effect' ) ] = x; | ||
} | ||
|
||
function Qux ( x ) { | ||
this.value = console.log( 'side effect' ); | ||
} | ||
|
||
function Corge ( x ) { | ||
this.value = x; | ||
} | ||
|
||
var Arrow = ( x ) => { | ||
undefined.value = x; | ||
}; | ||
|
||
console.log( 'before' ); | ||
|
||
var bar = new Bar(5); | ||
var baz = new Baz(5); | ||
var qux = new Qux(5); | ||
var corge = Corge(5); | ||
var arrow = new Arrow(5); | ||
|
||
console.log( 'after' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
function Bar ( x ) { | ||
console.log( 'side effect' ); | ||
this.value = x; | ||
} | ||
|
||
function Baz ( x ) { | ||
this[ console.log( 'side effect' ) ] = x; | ||
} | ||
|
||
function Qux ( x ) { | ||
this.value = console.log( 'side effect' ); | ||
} | ||
|
||
function Corge ( x ) { | ||
this.value = x; | ||
} | ||
|
||
var Arrow = ( x ) => { | ||
undefined.value = x; | ||
}; | ||
|
||
console.log( 'before' ); | ||
|
||
var bar = new Bar(5); | ||
var baz = new Baz(5); | ||
var qux = new Qux(5); | ||
var corge = Corge(5); | ||
var arrow = new Arrow(5); | ||
|
||
console.log( 'after' ); | ||
|
||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(factory()); | ||
}(this, (function () { 'use strict'; | ||
|
||
function Bar ( x ) { | ||
console.log( 'side effect' ); | ||
this.value = x; | ||
} | ||
|
||
function Baz ( x ) { | ||
this[ console.log( 'side effect' ) ] = x; | ||
} | ||
|
||
function Qux ( x ) { | ||
this.value = console.log( 'side effect' ); | ||
} | ||
|
||
function Corge ( x ) { | ||
this.value = x; | ||
} | ||
|
||
var Arrow = ( x ) => { | ||
undefined.value = x; | ||
}; | ||
|
||
console.log( 'before' ); | ||
|
||
var bar = new Bar(5); | ||
var baz = new Baz(5); | ||
var qux = new Qux(5); | ||
var corge = Corge(5); | ||
var arrow = new Arrow(5); | ||
|
||
console.log( 'after' ); | ||
|
||
}))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export var Arrow = ( x ) => { | ||
this.value = x; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function Bar ( x ) { | ||
console.log( 'side effect' ); | ||
this.value = x; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function Baz ( x ) { | ||
this[ console.log( 'side effect' ) ] = x; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function Corge ( x ) { | ||
this.value = x; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export function Foo ( x ) { | ||
this.value = x; | ||
this["string property"] = 20; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Foo } from './foo'; | ||
import { Bar } from './bar'; | ||
import { Baz } from './baz'; | ||
import { Qux } from './qux'; | ||
import { Corge } from './corge'; | ||
import { Arrow } from './arrow'; | ||
|
||
console.log( 'before' ); | ||
|
||
var foo = new Foo(5); | ||
var bar = new Bar(5); | ||
var baz = new Baz(5); | ||
var qux = new Qux(5); | ||
var corge = Corge(5); | ||
var arrow = new Arrow(5); | ||
|
||
console.log( 'after' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function Qux ( x ) { | ||
this.value = console.log( 'side effect' ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
define(function () { 'use strict'; | ||
|
||
var Foo = function () { | ||
console.log( 'side effect' ); | ||
this.isFoo = true; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
'use strict'; | ||
|
||
var Foo = function () { | ||
console.log( 'side effect' ); | ||
this.isFoo = true; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
var Foo = function () { | ||
console.log( 'side effect' ); | ||
this.isFoo = true; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
'use strict'; | ||
|
||
var Foo = function () { | ||
console.log( 'side effect' ); | ||
this.isFoo = true; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
var Foo = function () { | ||
console.log( 'side effect' ); | ||
this.isFoo = true; | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module.exports = { | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export function Foo ( x ) { | ||
this.value = x; | ||
} | ||
|
||
export function Bar ( x ) { | ||
this.value = x; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Foo, Bar } from './foo'; | ||
|
||
assert.equal( new Foo(5).value, 5 ); | ||
|
||
assert.throws( function () { | ||
Bar(5); | ||
}, /^TypeError: Cannot set property 'value' of undefined$/ ); |