Browse Source

use of arguments is assumed to create side-effects

better-aggressive
Rich-Harris 9 years ago
parent
commit
df9e67eec9
  1. 4
      src/utils/testForSideEffects.js
  2. 8
      test/form/side-effect-k/_config.js
  3. 5
      test/form/side-effect-k/_expected/amd.js
  4. 1
      test/form/side-effect-k/_expected/cjs.js
  5. 0
      test/form/side-effect-k/_expected/es6.js
  6. 0
      test/form/side-effect-k/_expected/iife.js
  7. 0
      test/form/side-effect-k/_expected/umd.js
  8. 19
      test/form/side-effect-k/foo.js
  9. 4
      test/form/side-effect-k/main.js

4
src/utils/testForSideEffects.js

@ -24,7 +24,9 @@ export default function testForSideEffects ( node, scope, statement, strongDepen
if ( isReference( node, parent ) ) {
const flattened = flatten( node );
if ( !scope.contains( flattened.name ) ) {
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?

8
test/form/side-effect-k/_config.js

@ -0,0 +1,8 @@
module.exports = {
solo: true,
show: true,
description: 'use of arguments is treated as a side-effect',
options: {
moduleName: 'myBundle'
}
};

5
test/form/side-effect-k/_expected/amd.js

@ -0,0 +1,5 @@
define(function () { 'use strict';
});

1
test/form/side-effect-k/_expected/cjs.js

@ -0,0 +1 @@
'use strict';

0
test/form/side-effect-k/_expected/es6.js

0
test/form/side-effect-k/_expected/iife.js

0
test/form/side-effect-k/_expected/umd.js

19
test/form/side-effect-k/foo.js

@ -0,0 +1,19 @@
export function augment ( x ) {
var prop, source;
var i = arguments.length;
var sources = Array( i - 1 );
while ( i-- ) {
sources[i-1] = arguments[i];
}
while (source = sources.shift()) {
for (prop in source) {
if (hasOwn.call(source, prop)) {
x[prop] = source[prop];
}
}
}
return x;
}

4
test/form/side-effect-k/main.js

@ -0,0 +1,4 @@
import { augment } from './foo.js';
export default function x () {}
augment( x.prototype );
Loading…
Cancel
Save