mirror of https://github.com/lukechilds/rollup.git
Rich Harris
9 years ago
133 changed files with 1429 additions and 409 deletions
@ -0,0 +1,230 @@ |
|||
import { blank, keys } from './utils/object.js'; |
|||
import run from './utils/run.js'; |
|||
|
|||
export default class Declaration { |
|||
constructor ( node, isParam ) { |
|||
if ( node ) { |
|||
if ( node.type === 'FunctionDeclaration' ) { |
|||
this.isFunctionDeclaration = true; |
|||
this.functionNode = node; |
|||
} else if ( node.type === 'VariableDeclarator' && node.init && /FunctionExpression/.test( node.init.type ) ) { |
|||
this.isFunctionDeclaration = true; |
|||
this.functionNode = node.init; |
|||
} |
|||
} |
|||
|
|||
this.statement = null; |
|||
this.name = null; |
|||
this.isParam = isParam; |
|||
|
|||
this.isReassigned = false; |
|||
this.aliases = []; |
|||
} |
|||
|
|||
addAlias ( declaration ) { |
|||
this.aliases.push( declaration ); |
|||
} |
|||
|
|||
addReference ( reference ) { |
|||
reference.declaration = this; |
|||
this.name = reference.name; // TODO handle differences of opinion
|
|||
|
|||
if ( reference.isReassignment ) this.isReassigned = true; |
|||
} |
|||
|
|||
render ( es6 ) { |
|||
if ( es6 ) return this.name; |
|||
if ( !this.isReassigned || !this.isExported ) return this.name; |
|||
|
|||
return `exports.${this.name}`; |
|||
} |
|||
|
|||
run ( strongDependencies ) { |
|||
if ( this.tested ) return this.hasSideEffects; |
|||
this.tested = true; |
|||
|
|||
if ( !this.statement || !this.functionNode ) { |
|||
this.hasSideEffects = true; // err on the side of caution. TODO handle unambiguous `var x; x = y => z` cases
|
|||
} else { |
|||
this.hasSideEffects = run( this.functionNode.body, this.functionNode._scope, this.statement, strongDependencies ); |
|||
} |
|||
|
|||
return this.hasSideEffects; |
|||
} |
|||
|
|||
use () { |
|||
this.isUsed = true; |
|||
if ( this.statement ) this.statement.mark(); |
|||
|
|||
this.aliases.forEach( alias => alias.use() ); |
|||
} |
|||
} |
|||
|
|||
export class SyntheticDefaultDeclaration { |
|||
constructor ( node, statement, name ) { |
|||
this.node = node; |
|||
this.statement = statement; |
|||
this.name = name; |
|||
|
|||
this.original = null; |
|||
this.isExported = false; |
|||
this.aliases = []; |
|||
} |
|||
|
|||
addAlias ( declaration ) { |
|||
this.aliases.push( declaration ); |
|||
} |
|||
|
|||
addReference ( reference ) { |
|||
// Don't change the name to `default`; it's not a valid identifier name.
|
|||
if ( reference.name === 'default' ) return; |
|||
|
|||
reference.declaration = this; |
|||
this.name = reference.name; |
|||
} |
|||
|
|||
bind ( declaration ) { |
|||
this.original = declaration; |
|||
} |
|||
|
|||
render () { |
|||
return !this.original || this.original.isReassigned ? |
|||
this.name : |
|||
this.original.render(); |
|||
} |
|||
|
|||
run ( strongDependencies ) { |
|||
if ( this.original ) { |
|||
return this.original.run( strongDependencies ); |
|||
} |
|||
|
|||
if ( /FunctionExpression/.test( this.node.declaration.type ) ) { |
|||
return run( this.node.declaration.body, this.statement.scope, this.statement, strongDependencies ); |
|||
} |
|||
} |
|||
|
|||
use () { |
|||
this.isUsed = true; |
|||
this.statement.mark(); |
|||
|
|||
if ( this.original ) this.original.use(); |
|||
|
|||
this.aliases.forEach( alias => alias.use() ); |
|||
} |
|||
} |
|||
|
|||
export class SyntheticNamespaceDeclaration { |
|||
constructor ( module ) { |
|||
this.module = module; |
|||
this.name = null; |
|||
|
|||
this.needsNamespaceBlock = false; |
|||
this.aliases = []; |
|||
|
|||
this.originals = blank(); |
|||
module.getExports().forEach( name => { |
|||
this.originals[ name ] = module.traceExport( name ); |
|||
}); |
|||
} |
|||
|
|||
addAlias ( declaration ) { |
|||
this.aliases.push( declaration ); |
|||
} |
|||
|
|||
addReference ( reference ) { |
|||
// if we have e.g. `foo.bar`, we can optimise
|
|||
// the reference by pointing directly to `bar`
|
|||
if ( reference.parts.length ) { |
|||
reference.name = reference.parts.shift(); |
|||
|
|||
reference.end += reference.name.length + 1; // TODO this is brittle
|
|||
|
|||
const original = this.originals[ reference.name ]; |
|||
|
|||
// throw with an informative error message if the reference doesn't exist.
|
|||
if ( !original ) { |
|||
this.module.bundle.onwarn( `Export '${reference.name}' is not defined by '${this.module.id}'` ); |
|||
reference.isUndefined = true; |
|||
return; |
|||
} |
|||
|
|||
original.addReference( reference ); |
|||
return; |
|||
} |
|||
|
|||
// otherwise we're accessing the namespace directly,
|
|||
// which means we need to mark all of this module's
|
|||
// exports and render a namespace block in the bundle
|
|||
if ( !this.needsNamespaceBlock ) { |
|||
this.needsNamespaceBlock = true; |
|||
this.module.bundle.internalNamespaces.push( this ); |
|||
} |
|||
|
|||
reference.declaration = this; |
|||
this.name = reference.name; |
|||
} |
|||
|
|||
renderBlock ( indentString ) { |
|||
const members = keys( this.originals ).map( name => { |
|||
const original = this.originals[ name ]; |
|||
|
|||
if ( original.isReassigned ) { |
|||
return `${indentString}get ${name} () { return ${original.render()}; }`; |
|||
} |
|||
|
|||
return `${indentString}${name}: ${original.render()}`; |
|||
}); |
|||
|
|||
return `var ${this.render()} = Object.freeze({\n${members.join( ',\n' )}\n});\n\n`; |
|||
} |
|||
|
|||
render () { |
|||
return this.name; |
|||
} |
|||
|
|||
use () { |
|||
keys( this.originals ).forEach( name => { |
|||
this.originals[ name ].use(); |
|||
}); |
|||
|
|||
this.aliases.forEach( alias => alias.use() ); |
|||
} |
|||
} |
|||
|
|||
export class ExternalDeclaration { |
|||
constructor ( module, name ) { |
|||
this.module = module; |
|||
this.name = name; |
|||
this.isExternal = true; |
|||
} |
|||
|
|||
addAlias () { |
|||
// noop
|
|||
} |
|||
|
|||
addReference ( reference ) { |
|||
reference.declaration = this; |
|||
|
|||
if ( this.name === 'default' || this.name === '*' ) { |
|||
this.module.suggestName( reference.name ); |
|||
} |
|||
} |
|||
|
|||
render ( es6 ) { |
|||
if ( this.name === '*' ) { |
|||
return this.module.name; |
|||
} |
|||
|
|||
if ( this.name === 'default' ) { |
|||
return !es6 && this.module.exportsNames ? |
|||
`${this.module.name}__default` : |
|||
this.module.name; |
|||
} |
|||
|
|||
return es6 ? this.name : `${this.module.name}.${this.name}`; |
|||
} |
|||
|
|||
use () { |
|||
// noop?
|
|||
} |
|||
} |
@ -0,0 +1,16 @@ |
|||
export default function flatten ( node ) { |
|||
let parts = []; |
|||
while ( node.type === 'MemberExpression' ) { |
|||
if ( node.computed ) return null; |
|||
parts.unshift( node.property.name ); |
|||
|
|||
node = node.object; |
|||
} |
|||
|
|||
if ( node.type !== 'Identifier' ) return null; |
|||
|
|||
const name = node.name; |
|||
parts.unshift( name ); |
|||
|
|||
return { name, keypath: parts.join( '.' ) }; |
|||
} |
@ -0,0 +1,6 @@ |
|||
export default function isFunctionDeclaration ( node ) { |
|||
if ( !node ) return false; |
|||
|
|||
return node.type === 'FunctionDeclaration' || |
|||
( node.type === 'VariableDeclaration' && node.init && /FunctionExpression/.test( node.init.type ) ); |
|||
} |
@ -0,0 +1,21 @@ |
|||
export default function isReference ( node, parent ) { |
|||
if ( node.type === 'MemberExpression' ) { |
|||
return !node.computed && isReference( node.object, node ); |
|||
} |
|||
|
|||
if ( node.type === 'Identifier' ) { |
|||
// TODO is this right?
|
|||
if ( parent.type === 'MemberExpression' ) return parent.computed || node === parent.object; |
|||
|
|||
// disregard the `bar` in { bar: foo }
|
|||
if ( parent.type === 'Property' && node !== parent.value ) return false; |
|||
|
|||
// disregard the `bar` in `class Foo { bar () {...} }`
|
|||
if ( parent.type === 'MethodDefinition' ) return false; |
|||
|
|||
// disregard the `bar` in `export { foo as bar }`
|
|||
if ( parent.type === 'ExportSpecifier' && node !== parent.local ) return; |
|||
|
|||
return true; |
|||
} |
|||
} |
@ -0,0 +1,4 @@ |
|||
export default { |
|||
AssignmentExpression: 'left', |
|||
UpdateExpression: 'argument' |
|||
}; |
@ -0,0 +1,139 @@ |
|||
import { walk } from 'estree-walker'; |
|||
import modifierNodes from '../ast/modifierNodes.js'; |
|||
import isReference from '../ast/isReference.js'; |
|||
import flatten from '../ast/flatten'; |
|||
|
|||
let pureFunctions = {}; |
|||
|
|||
const arrayTypes = 'Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split( ' ' ); |
|||
const simdTypes = 'Int8x16 Int16x8 Int32x4 Float32x4 Float64x2'.split( ' ' ); |
|||
const simdMethods = 'abs add and bool check div equal extractLane fromFloat32x4 fromFloat32x4Bits fromFloat64x2 fromFloat64x2Bits fromInt16x8Bits fromInt32x4 fromInt32x4Bits fromInt8x16Bits greaterThan greaterThanOrEqual lessThan lessThanOrEqual load max maxNum min minNum mul neg not notEqual or reciprocalApproximation reciprocalSqrtApproximation replaceLane select selectBits shiftLeftByScalar shiftRightArithmeticByScalar shiftRightLogicalByScalar shuffle splat sqrt store sub swizzle xor'.split( ' ' ); |
|||
let allSimdMethods = []; |
|||
simdTypes.forEach( t => { |
|||
simdMethods.forEach( m => { |
|||
allSimdMethods.push( `SIMD.${t}.${m}` ); |
|||
}); |
|||
}); |
|||
|
|||
[ |
|||
'Array.isArray', |
|||
'Error', 'EvalError', 'InternalError', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError', |
|||
'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'decodeURI', 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', 'escape', 'unescape', |
|||
'Object', 'Object.create', 'Object.getNotifier', 'Object.getOwn', 'Object.getOwnPropertyDescriptor', 'Object.getOwnPropertyNames', 'Object.getOwnPropertySymbols', 'Object.getPrototypeOf', 'Object.is', 'Object.isExtensible', 'Object.isFrozen', 'Object.isSealed', 'Object.keys', |
|||
'Function', 'Boolean', |
|||
'Number', 'Number.isFinite', 'Number.isInteger', 'Number.isNaN', 'Number.isSafeInteger', 'Number.parseFloat', 'Number.parseInt', |
|||
'Symbol', 'Symbol.for', 'Symbol.keyFor', |
|||
'Math.abs', 'Math.acos', 'Math.acosh', 'Math.asin', 'Math.asinh', 'Math.atan', 'Math.atan2', 'Math.atanh', 'Math.cbrt', 'Math.ceil', 'Math.clz32', 'Math.cos', 'Math.cosh', 'Math.exp', 'Math.expm1', 'Math.floor', 'Math.fround', 'Math.hypot', 'Math.imul', 'Math.log', 'Math.log10', 'Math.log1p', 'Math.log2', 'Math.max', 'Math.min', 'Math.pow', 'Math.random', 'Math.round', 'Math.sign', 'Math.sin', 'Math.sinh', 'Math.sqrt', 'Math.tan', 'Math.tanh', 'Math.trunc', |
|||
'Date', 'Date.UTC', 'Date.now', 'Date.parse', |
|||
'String', 'String.fromCharCode', 'String.fromCodePoint', 'String.raw', |
|||
'RegExp', |
|||
'Map', 'Set', 'WeakMap', 'WeakSet', |
|||
'ArrayBuffer', 'ArrayBuffer.isView', |
|||
'DataView', |
|||
'JSON.parse', 'JSON.stringify', |
|||
'Promise', 'Promise.all', 'Promise.race', 'Promise.reject', 'Promise.resolve', |
|||
'Intl.Collator', 'Intl.Collator.supportedLocalesOf', 'Intl.DateTimeFormat', 'Intl.DateTimeFormat.supportedLocalesOf', 'Intl.NumberFormat', 'Intl.NumberFormat.supportedLocalesOf' |
|||
|
|||
// TODO properties of e.g. window...
|
|||
].concat( |
|||
arrayTypes, |
|||
arrayTypes.map( t => `${t}.from` ), |
|||
arrayTypes.map( t => `${t}.of` ), |
|||
simdTypes.map( t => `SIMD.${t}` ), |
|||
allSimdMethods |
|||
).forEach( name => pureFunctions[ name ] = true ); |
|||
// TODO add others to this list from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
|
|||
|
|||
|
|||
|
|||
export default function run ( node, scope, statement, strongDependencies, force ) { |
|||
let hasSideEffect = false; |
|||
|
|||
walk( node, { |
|||
enter ( node, parent ) { |
|||
if ( !force && /Function/.test( node.type ) ) return this.skip(); |
|||
|
|||
if ( node._scope ) scope = node._scope; |
|||
|
|||
if ( isReference( node, parent ) ) { |
|||
const flattened = flatten( node ); |
|||
|
|||
if ( flattened.name === 'arguments' ) { |
|||
hasSideEffect = true; |
|||
} if ( !scope.contains( flattened.name ) ) { |
|||
const declaration = statement.module.trace( flattened.name ); |
|||
if ( declaration && !declaration.isExternal ) { |
|||
const module = declaration.module || declaration.statement.module; // TODO is this right?
|
|||
if ( !module.isExternal && !~strongDependencies.indexOf( module ) ) strongDependencies.push( module ); |
|||
} |
|||
} |
|||
} |
|||
|
|||
else if ( node.type === 'ThrowStatement' ) { |
|||
// we only care about errors thrown at the top level, otherwise
|
|||
// any function with error checking gets included if called
|
|||
if ( scope.isTopLevel ) hasSideEffect = true; |
|||
} |
|||
|
|||
else if ( node.type === 'CallExpression' || node.type === 'NewExpression' ) { |
|||
if ( node.callee.type === 'Identifier' ) { |
|||
const declaration = scope.findDeclaration( node.callee.name ) || |
|||
statement.module.trace( node.callee.name ); |
|||
|
|||
if ( declaration ) { |
|||
if ( declaration.isExternal || declaration.run( strongDependencies ) ) { |
|||
hasSideEffect = true; |
|||
} |
|||
} else if ( !pureFunctions[ node.callee.name ] ) { |
|||
hasSideEffect = true; |
|||
} |
|||
} |
|||
|
|||
else if ( node.callee.type === 'MemberExpression' ) { |
|||
const flattened = flatten( node.callee ); |
|||
|
|||
if ( flattened ) { |
|||
// if we're calling e.g. Object.keys(thing), there are no side-effects
|
|||
// TODO make pureFunctions configurable
|
|||
const declaration = scope.findDeclaration( flattened.name ) || statement.module.trace( flattened.name ); |
|||
|
|||
if ( !!declaration || !pureFunctions[ flattened.keypath ] ) { |
|||
hasSideEffect = true; |
|||
} |
|||
} else { |
|||
// is not a keypath like `foo.bar.baz` – could be e.g.
|
|||
// `(a || b).foo()`. Err on the side of caution
|
|||
hasSideEffect = true; |
|||
} |
|||
} |
|||
|
|||
// otherwise we're probably dealing with a function expression
|
|||
else if ( run( node.callee, scope, statement, strongDependencies, true ) ) { |
|||
hasSideEffect = true; |
|||
} |
|||
} |
|||
|
|||
else if ( node.type in modifierNodes ) { |
|||
let subject = node[ modifierNodes[ node.type ] ]; |
|||
while ( subject.type === 'MemberExpression' ) subject = subject.object; |
|||
|
|||
let declaration = scope.findDeclaration( subject.name ); |
|||
|
|||
if ( declaration ) { |
|||
if ( declaration.isParam ) hasSideEffect = true; |
|||
} else { |
|||
declaration = statement.module.trace( subject.name ); |
|||
|
|||
if ( !declaration || declaration.isExternal || declaration.isUsed ) { |
|||
hasSideEffect = true; |
|||
} |
|||
} |
|||
} |
|||
}, |
|||
leave ( node ) { |
|||
if ( node._scope ) scope = scope.parent; |
|||
} |
|||
}); |
|||
|
|||
return hasSideEffect; |
|||
} |
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
description: 'ignores side-effects outside entry module in aggressive mode', |
|||
options: { |
|||
aggressive: true |
|||
} |
|||
} |
@ -0,0 +1,9 @@ |
|||
define(function () { 'use strict'; |
|||
|
|||
function foo () { |
|||
return 42; |
|||
} |
|||
|
|||
assert.equal( foo(), 42 ); |
|||
|
|||
}); |
@ -0,0 +1,7 @@ |
|||
'use strict'; |
|||
|
|||
function foo () { |
|||
return 42; |
|||
} |
|||
|
|||
assert.equal( foo(), 42 ); |
@ -0,0 +1,5 @@ |
|||
function foo () { |
|||
return 42; |
|||
} |
|||
|
|||
assert.equal( foo(), 42 ); |
@ -0,0 +1,9 @@ |
|||
(function () { 'use strict'; |
|||
|
|||
function foo () { |
|||
return 42; |
|||
} |
|||
|
|||
assert.equal( foo(), 42 ); |
|||
|
|||
})(); |
@ -0,0 +1,13 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
|||
typeof define === 'function' && define.amd ? define(factory) : |
|||
factory(); |
|||
}(this, function () { 'use strict'; |
|||
|
|||
function foo () { |
|||
return 42; |
|||
} |
|||
|
|||
assert.equal( foo(), 42 ); |
|||
|
|||
})); |
@ -0,0 +1,9 @@ |
|||
function x () { |
|||
console.log( 'side-effect' ); |
|||
} |
|||
|
|||
x(); |
|||
|
|||
export function foo () { |
|||
return 42; |
|||
} |
@ -0,0 +1,3 @@ |
|||
import { foo } from './foo'; |
|||
|
|||
assert.equal( foo(), 42 ); |
@ -1,6 +1,7 @@ |
|||
module.exports = { |
|||
description: 'dedupes external imports', |
|||
options: { |
|||
external: [ 'external' ] |
|||
external: [ 'external' ], |
|||
moduleName: 'myBundle' |
|||
} |
|||
}; |
|||
|
@ -1,15 +1,19 @@ |
|||
define(function () { 'use strict'; |
|||
|
|||
function foo() { |
|||
}; |
|||
|
|||
function a() { |
|||
foo(); |
|||
foo(); |
|||
var a; |
|||
if (a.b) { |
|||
} |
|||
} |
|||
a(); |
|||
|
|||
}); |
|||
function foo () { |
|||
console.log( 'foo' ); |
|||
} |
|||
|
|||
function a () { |
|||
foo(); |
|||
foo(); |
|||
|
|||
var a; |
|||
if ( a.b ) { |
|||
// empty
|
|||
} |
|||
} |
|||
|
|||
a(); |
|||
|
|||
}); |
@ -1,13 +1,17 @@ |
|||
'use strict'; |
|||
|
|||
function foo() { |
|||
}; |
|||
|
|||
function a() { |
|||
foo(); |
|||
foo(); |
|||
var a; |
|||
if (a.b) { |
|||
} |
|||
function foo () { |
|||
console.log( 'foo' ); |
|||
} |
|||
a(); |
|||
|
|||
function a () { |
|||
foo(); |
|||
foo(); |
|||
|
|||
var a; |
|||
if ( a.b ) { |
|||
// empty
|
|||
} |
|||
} |
|||
|
|||
a(); |
@ -1,11 +1,15 @@ |
|||
function foo() { |
|||
}; |
|||
function foo () { |
|||
console.log( 'foo' ); |
|||
} |
|||
|
|||
function a () { |
|||
foo(); |
|||
foo(); |
|||
|
|||
function a() { |
|||
foo(); |
|||
foo(); |
|||
var a; |
|||
if (a.b) { |
|||
} |
|||
var a; |
|||
if ( a.b ) { |
|||
// empty
|
|||
} |
|||
} |
|||
a(); |
|||
|
|||
a(); |
@ -1,15 +1,19 @@ |
|||
(function () { 'use strict'; |
|||
|
|||
function foo() { |
|||
}; |
|||
|
|||
function a() { |
|||
foo(); |
|||
foo(); |
|||
var a; |
|||
if (a.b) { |
|||
} |
|||
} |
|||
a(); |
|||
|
|||
})(); |
|||
function foo () { |
|||
console.log( 'foo' ); |
|||
} |
|||
|
|||
function a () { |
|||
foo(); |
|||
foo(); |
|||
|
|||
var a; |
|||
if ( a.b ) { |
|||
// empty
|
|||
} |
|||
} |
|||
|
|||
a(); |
|||
|
|||
})(); |
@ -1,19 +1,23 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
|||
typeof define === 'function' && define.amd ? define(factory) : |
|||
factory(); |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : |
|||
typeof define === 'function' && define.amd ? define(factory) : |
|||
factory(); |
|||
}(this, function () { 'use strict'; |
|||
|
|||
function foo() { |
|||
}; |
|||
function foo () { |
|||
console.log( 'foo' ); |
|||
} |
|||
|
|||
function a() { |
|||
foo(); |
|||
foo(); |
|||
var a; |
|||
if (a.b) { |
|||
} |
|||
} |
|||
a(); |
|||
function a () { |
|||
foo(); |
|||
foo(); |
|||
|
|||
})); |
|||
var a; |
|||
if ( a.b ) { |
|||
// empty
|
|||
} |
|||
} |
|||
|
|||
a(); |
|||
|
|||
})); |
@ -1,2 +1,3 @@ |
|||
export function foo() { |
|||
}; |
|||
export function foo () { |
|||
console.log( 'foo' ); |
|||
} |
|||
|
@ -1,10 +1,13 @@ |
|||
import * as foo from './foo'; |
|||
|
|||
function a() { |
|||
foo.foo(); |
|||
foo.foo(); |
|||
var a; |
|||
if (a.b) { |
|||
} |
|||
function a () { |
|||
foo.foo(); |
|||
foo.foo(); |
|||
|
|||
var a; |
|||
if ( a.b ) { |
|||
// empty
|
|||
} |
|||
} |
|||
a(); |
|||
|
|||
a(); |
|||
|
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
description: 'discards IIFE with no side-effects', |
|||
options: { |
|||
moduleName: 'myBundle' |
|||
} |
|||
}; |
@ -0,0 +1,7 @@ |
|||
define(function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
}); |
@ -0,0 +1,5 @@ |
|||
'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
module.exports = main; |
@ -0,0 +1,3 @@ |
|||
var main = 42; |
|||
|
|||
export default main; |
@ -0,0 +1,7 @@ |
|||
var myBundle = (function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})(); |
@ -0,0 +1,11 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
|||
typeof define === 'function' && define.amd ? define(factory) : |
|||
global.myBundle = factory(); |
|||
}(this, function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})); |
@ -0,0 +1,8 @@ |
|||
var Unused = (function () { |
|||
function Unused () {} |
|||
Unused.prototype = {}; |
|||
|
|||
return Unused; |
|||
}()); |
|||
|
|||
export default 42; |
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
description: 'discards function with no side-effects', |
|||
options: { |
|||
moduleName: 'myBundle' |
|||
} |
|||
}; |
@ -0,0 +1,7 @@ |
|||
define(function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
}); |
@ -0,0 +1,5 @@ |
|||
'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
module.exports = main; |
@ -0,0 +1,3 @@ |
|||
var main = 42; |
|||
|
|||
export default main; |
@ -0,0 +1,7 @@ |
|||
var myBundle = (function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})(); |
@ -0,0 +1,11 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
|||
typeof define === 'function' && define.amd ? define(factory) : |
|||
global.myBundle = factory(); |
|||
}(this, function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})); |
@ -0,0 +1,10 @@ |
|||
var factory = function () { |
|||
function Unused () {} |
|||
Unused.prototype = {}; |
|||
|
|||
return Unused; |
|||
}; |
|||
|
|||
var Unused = factory(); |
|||
|
|||
export default 42; |
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
description: 'excludes functions that are known to be pure', |
|||
options: { |
|||
moduleName: 'myBundle' |
|||
} |
|||
}; |
@ -0,0 +1,7 @@ |
|||
define(function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
}); |
@ -0,0 +1,5 @@ |
|||
'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
module.exports = main; |
@ -0,0 +1,3 @@ |
|||
var main = 42; |
|||
|
|||
export default main; |
@ -0,0 +1,7 @@ |
|||
var myBundle = (function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})(); |
@ -0,0 +1,11 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
|||
typeof define === 'function' && define.amd ? define(factory) : |
|||
global.myBundle = factory(); |
|||
}(this, function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})); |
@ -0,0 +1,4 @@ |
|||
var obj = { foo: 1, bar: 2 }; |
|||
var keys = Object.keys( obj ); |
|||
|
|||
export default 42; |
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
description: 'accounts for local scopes when tested function purity', |
|||
options: { |
|||
moduleName: 'myBundle' |
|||
} |
|||
}; |
@ -0,0 +1,20 @@ |
|||
define(function () { 'use strict'; |
|||
|
|||
function foo () { |
|||
var Object = { |
|||
keys: function () { |
|||
console.log( 'side-effect' ); |
|||
} |
|||
}; |
|||
|
|||
var obj = { foo: 1, bar: 2 }; |
|||
var keys = Object.keys( obj ); |
|||
} |
|||
|
|||
foo(); |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
}); |
@ -0,0 +1,18 @@ |
|||
'use strict'; |
|||
|
|||
function foo () { |
|||
var Object = { |
|||
keys: function () { |
|||
console.log( 'side-effect' ); |
|||
} |
|||
}; |
|||
|
|||
var obj = { foo: 1, bar: 2 }; |
|||
var keys = Object.keys( obj ); |
|||
} |
|||
|
|||
foo(); |
|||
|
|||
var main = 42; |
|||
|
|||
module.exports = main; |
@ -0,0 +1,16 @@ |
|||
function foo () { |
|||
var Object = { |
|||
keys: function () { |
|||
console.log( 'side-effect' ); |
|||
} |
|||
}; |
|||
|
|||
var obj = { foo: 1, bar: 2 }; |
|||
var keys = Object.keys( obj ); |
|||
} |
|||
|
|||
foo(); |
|||
|
|||
var main = 42; |
|||
|
|||
export default main; |
@ -0,0 +1,20 @@ |
|||
var myBundle = (function () { 'use strict'; |
|||
|
|||
function foo () { |
|||
var Object = { |
|||
keys: function () { |
|||
console.log( 'side-effect' ); |
|||
} |
|||
}; |
|||
|
|||
var obj = { foo: 1, bar: 2 }; |
|||
var keys = Object.keys( obj ); |
|||
} |
|||
|
|||
foo(); |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})(); |
@ -0,0 +1,24 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
|||
typeof define === 'function' && define.amd ? define(factory) : |
|||
global.myBundle = factory(); |
|||
}(this, function () { 'use strict'; |
|||
|
|||
function foo () { |
|||
var Object = { |
|||
keys: function () { |
|||
console.log( 'side-effect' ); |
|||
} |
|||
}; |
|||
|
|||
var obj = { foo: 1, bar: 2 }; |
|||
var keys = Object.keys( obj ); |
|||
} |
|||
|
|||
foo(); |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})); |
@ -0,0 +1,14 @@ |
|||
function foo () { |
|||
var Object = { |
|||
keys: function () { |
|||
console.log( 'side-effect' ); |
|||
} |
|||
}; |
|||
|
|||
var obj = { foo: 1, bar: 2 }; |
|||
var keys = Object.keys( obj ); |
|||
} |
|||
|
|||
foo(); |
|||
|
|||
export default 42; |
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
description: 'disregards side-effects that are contained within a function', |
|||
options: { |
|||
moduleName: 'myBundle' |
|||
} |
|||
}; |
@ -0,0 +1,7 @@ |
|||
define(function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
}); |
@ -0,0 +1,5 @@ |
|||
'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
module.exports = main; |
@ -0,0 +1,3 @@ |
|||
var main = 42; |
|||
|
|||
export default main; |
@ -0,0 +1,7 @@ |
|||
var myBundle = (function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})(); |
@ -0,0 +1,11 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
|||
typeof define === 'function' && define.amd ? define(factory) : |
|||
global.myBundle = factory(); |
|||
}(this, function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})); |
@ -0,0 +1,8 @@ |
|||
function foo () { |
|||
var a, b, c; |
|||
b = 1; |
|||
} |
|||
|
|||
foo(); |
|||
|
|||
export default 42; |
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
description: 'excludes constructors that are known to be pure', |
|||
options: { |
|||
moduleName: 'myBundle' |
|||
} |
|||
}; |
@ -0,0 +1,7 @@ |
|||
define(function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
}); |
@ -0,0 +1,5 @@ |
|||
'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
module.exports = main; |
@ -0,0 +1,3 @@ |
|||
var main = 42; |
|||
|
|||
export default main; |
@ -0,0 +1,7 @@ |
|||
var myBundle = (function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})(); |
@ -0,0 +1,11 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
|||
typeof define === 'function' && define.amd ? define(factory) : |
|||
global.myBundle = factory(); |
|||
}(this, function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})); |
@ -0,0 +1,3 @@ |
|||
var err = new Error( 'this will be ignored' ); |
|||
|
|||
export default 42; |
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
description: 'excludes non-top-level throw statements', |
|||
options: { |
|||
moduleName: 'myBundle' |
|||
} |
|||
}; |
@ -0,0 +1,7 @@ |
|||
define(function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
}); |
@ -0,0 +1,5 @@ |
|||
'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
module.exports = main; |
@ -0,0 +1,3 @@ |
|||
var main = 42; |
|||
|
|||
export default main; |
@ -0,0 +1,7 @@ |
|||
var myBundle = (function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})(); |
@ -0,0 +1,11 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
|||
typeof define === 'function' && define.amd ? define(factory) : |
|||
global.myBundle = factory(); |
|||
}(this, function () { 'use strict'; |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})); |
@ -0,0 +1,9 @@ |
|||
function foo ( ok ) { |
|||
if ( !ok ) { |
|||
throw new Error( 'this will be ignored' ); |
|||
} |
|||
} |
|||
|
|||
foo(); |
|||
|
|||
export default 42; |
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
description: 'includes top-level throw statements', |
|||
options: { |
|||
moduleName: 'myBundle' |
|||
} |
|||
}; |
@ -0,0 +1,11 @@ |
|||
define(function () { 'use strict'; |
|||
|
|||
if ( !ok ) { |
|||
throw new Error( 'this will be included' ); |
|||
} |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
}); |
@ -0,0 +1,9 @@ |
|||
'use strict'; |
|||
|
|||
if ( !ok ) { |
|||
throw new Error( 'this will be included' ); |
|||
} |
|||
|
|||
var main = 42; |
|||
|
|||
module.exports = main; |
@ -0,0 +1,7 @@ |
|||
if ( !ok ) { |
|||
throw new Error( 'this will be included' ); |
|||
} |
|||
|
|||
var main = 42; |
|||
|
|||
export default main; |
@ -0,0 +1,11 @@ |
|||
var myBundle = (function () { 'use strict'; |
|||
|
|||
if ( !ok ) { |
|||
throw new Error( 'this will be included' ); |
|||
} |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})(); |
@ -0,0 +1,15 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
|||
typeof define === 'function' && define.amd ? define(factory) : |
|||
global.myBundle = factory(); |
|||
}(this, function () { 'use strict'; |
|||
|
|||
if ( !ok ) { |
|||
throw new Error( 'this will be included' ); |
|||
} |
|||
|
|||
var main = 42; |
|||
|
|||
return main; |
|||
|
|||
})); |
@ -0,0 +1,5 @@ |
|||
if ( !ok ) { |
|||
throw new Error( 'this will be included' ); |
|||
} |
|||
|
|||
export default 42; |
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
description: 'includes late function declarations with side-effects', |
|||
options: { |
|||
moduleName: 'myBundle' |
|||
} |
|||
}; |
@ -0,0 +1,11 @@ |
|||
define(function () { 'use strict'; |
|||
|
|||
var augment; |
|||
augment = x => x.augmented = true; |
|||
|
|||
function x () {} |
|||
augment( x ); |
|||
|
|||
return x; |
|||
|
|||
}); |
@ -0,0 +1,9 @@ |
|||
'use strict'; |
|||
|
|||
var augment; |
|||
augment = x => x.augmented = true; |
|||
|
|||
function x () {} |
|||
augment( x ); |
|||
|
|||
module.exports = x; |
@ -0,0 +1,7 @@ |
|||
var augment; |
|||
augment = x => x.augmented = true; |
|||
|
|||
function x () {} |
|||
augment( x ); |
|||
|
|||
export default x; |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue