mirror of https://github.com/lukechilds/rollup.git
Rich Harris
10 years ago
94 changed files with 509 additions and 19 deletions
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 'maintains live bindings' |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/bindings
|
@ -0,0 +1,5 @@ |
|||
export var count = 0; |
|||
|
|||
export function incr() { |
|||
count++; |
|||
} |
@ -0,0 +1,5 @@ |
|||
import { count, incr } from './foo'; |
|||
|
|||
assert.equal (count, 0 ); |
|||
incr(); |
|||
assert.equal( count, 1 ); |
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 'cycles work with default exports' |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/cycles-defaults
|
@ -0,0 +1,3 @@ |
|||
import b from './b'; |
|||
|
|||
export default { a: 1, get b() { return b.b; } }; |
@ -0,0 +1,3 @@ |
|||
import a from './a'; |
|||
|
|||
export default { b: 2, get a() { return a.a; } }; |
@ -0,0 +1,7 @@ |
|||
import a from './a'; |
|||
import b from './b'; |
|||
|
|||
assert.equal( a.a, 1 ); |
|||
assert.equal( a.b, 2 ); |
|||
assert.equal( b.a, 1 ); |
|||
assert.equal( b.b, 2 ); |
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 'handles cycles where imports are immediately used' |
|||
}; |
|||
|
|||
// Test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/cycles-immediate
|
@ -0,0 +1,18 @@ |
|||
import { nextOdd } from './odds'; |
|||
|
|||
/** |
|||
* We go through these gymnastics to eager-bind to nextOdd. This is done to |
|||
* ensure that both this module and the 'odds' module eagerly use something |
|||
* from the other. |
|||
*/ |
|||
export var nextEven = (function() { |
|||
return function(n) { |
|||
var no = nextOdd(n); |
|||
return (no === n + 2) ? |
|||
no - 1 : no; |
|||
}; |
|||
})(nextOdd); |
|||
|
|||
export function isEven(n) { |
|||
return n % 2 === 0; |
|||
} |
@ -0,0 +1,22 @@ |
|||
import { nextEven, isEven } from './evens'; |
|||
import { nextOdd, isOdd } from './odds'; |
|||
|
|||
/** |
|||
* The 'evens' and 'odds' modules are configured in such a way that they both |
|||
* have two exported functions: isEven, nextEven, isOdd, and nextOdd. Normally |
|||
* these four functions could be in any order regardless of which depends on |
|||
* which because of JavaScript function hoisting. |
|||
* |
|||
* For the purposes of our test we need to prevent function hoisting, so it has |
|||
* been arranged that two of them will be function expressions assigned to |
|||
* variables. Specifically, isOdd and nextEven both eagerly evaluate their |
|||
* dependencies (i.e. isEven and nextOdd). This allows us to test that exported |
|||
* function declarations are available before what would be a module's |
|||
* "execute" step, per the spec. |
|||
*/ |
|||
assert.equal(nextEven(1), 2); |
|||
assert.equal(nextOdd(1), 3); |
|||
assert.ok(isOdd(1)); |
|||
assert.ok(!isOdd(0)); |
|||
assert.ok(isEven(0)); |
|||
assert.ok(!isEven(1)); |
@ -0,0 +1,16 @@ |
|||
import { isEven } from './evens'; |
|||
|
|||
export function nextOdd(n) { |
|||
return isEven(n) ? n + 1 : n + 2; |
|||
} |
|||
|
|||
/** |
|||
* We go through these gymnastics to eager-bind to isEven. This is done to |
|||
* ensure that both this module and the 'evens' module eagerly use something |
|||
* from the other. |
|||
*/ |
|||
export var isOdd = (function(isEven) { |
|||
return function(n) { |
|||
return !isEven(n); |
|||
}; |
|||
})(isEven); |
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 'does not bind default exports' |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-default
|
@ -0,0 +1,12 @@ |
|||
var a = 42; |
|||
|
|||
export function change() { |
|||
a++; |
|||
} |
|||
|
|||
export default a; |
|||
|
|||
// Any replacement for the `export default` above needs to happen in the same
|
|||
// location. It cannot be done, say, at the end of the file. Otherwise the new
|
|||
// value of `a` will be used and will be incorrect.
|
|||
a = 0; |
@ -0,0 +1,6 @@ |
|||
import value from './foo'; |
|||
import { change } from './foo'; |
|||
|
|||
assert.equal(value, 42); |
|||
change(); |
|||
assert.equal( value, 42, 'default export should not be bound' ); |
@ -0,0 +1,10 @@ |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'disallows duplicate imports', |
|||
error: function ( err ) { |
|||
assert.ok( false ); // TK - pick an error message
|
|||
} |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/duplicate-import-fails
|
@ -0,0 +1 @@ |
|||
export var a = 1; |
@ -0,0 +1,4 @@ |
|||
import { a } from './foo'; |
|||
import { a } from './foo'; |
|||
|
|||
assert.equal(a, 1); |
@ -0,0 +1,10 @@ |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'disallows duplicate import specifiers', |
|||
error: function ( err ) { |
|||
assert.ok( false ); // TK - pick an error message
|
|||
} |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/duplicate-import-specifier-fails
|
@ -0,0 +1 @@ |
|||
export var a = 1; |
@ -0,0 +1,2 @@ |
|||
import { a, a } from './exporter'; |
|||
assert.equal(a, 1); |
@ -0,0 +1,3 @@ |
|||
module.exports = { |
|||
description: 'empty imports are assumed to contain side-effects' |
|||
}; |
@ -0,0 +1 @@ |
|||
global.answer = 42; |
@ -0,0 +1,3 @@ |
|||
import './foo'; |
|||
|
|||
assert.equal( global.answer, 42 ); |
@ -1,6 +1,8 @@ |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'correctly exports deconflicted names', |
|||
exports: function ( exports, assert ) { |
|||
exports: function ( exports ) { |
|||
assert.equal( exports.bar(), 'bar' ); |
|||
} |
|||
}; |
|||
}; |
|||
|
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 'export from works with default exports' |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-from-default
|
@ -0,0 +1 @@ |
|||
export default 1; |
@ -0,0 +1,2 @@ |
|||
import a from './second'; |
|||
assert.equal(a, 1); |
@ -0,0 +1 @@ |
|||
export { default } from './first'; |
@ -1,6 +1,8 @@ |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'exports from an internal module', |
|||
exports: function ( exports, assert ) { |
|||
exports: function ( exports ) { |
|||
assert.equal( exports.foo, 42 ); |
|||
} |
|||
}; |
|||
}; |
|||
|
@ -0,0 +1,11 @@ |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'export from does not create a local binding', |
|||
|
|||
error: function () { |
|||
assert.ok( false, 'TODO: assertion is skipped because it is not used... we need to implement something like /*rollup: include */') |
|||
} |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-from
|
@ -0,0 +1 @@ |
|||
export var a = 1; |
@ -0,0 +1,2 @@ |
|||
import { a } from './second'; |
|||
assert.equal(a, 1); |
@ -0,0 +1,5 @@ |
|||
export { a } from './first'; |
|||
|
|||
// This `a` reference should not be re-written because this export is not
|
|||
// creating a local binding.
|
|||
assert.equal(typeof a, 'undefined'); |
@ -0,0 +1,8 @@ |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'disallows non-top-level exports', |
|||
error: function ( err ) { |
|||
assert.ok( false, 'TODO: pick an error message' ); |
|||
} |
|||
}; |
@ -0,0 +1,3 @@ |
|||
function foo() { |
|||
export { foo }; |
|||
} |
@ -1,6 +1,8 @@ |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'exports named values from the bundle entry module', |
|||
exports: function ( exports, assert ) { |
|||
exports: function ( exports ) { |
|||
assert.equal( exports.answer, 42 ); |
|||
} |
|||
}; |
|||
}; |
|||
|
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 'renames named and default imports' |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/import-as
|
@ -0,0 +1,5 @@ |
|||
/* jshint esnext:true */ |
|||
|
|||
export var a = 'a'; |
|||
export var b = 'b'; |
|||
export default 'DEF'; |
@ -0,0 +1,5 @@ |
|||
import { a as b, b as a, default as def } from './foo'; |
|||
|
|||
assert.equal(b, 'a'); |
|||
assert.equal(a, 'b'); |
|||
assert.equal(def, 'DEF'); |
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 'imports chained exports' |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/import-chain
|
@ -0,0 +1 @@ |
|||
export var value = 42; |
@ -0,0 +1,2 @@ |
|||
import { value } from './second'; |
|||
assert.equal(value, 42); |
@ -0,0 +1,2 @@ |
|||
import { value } from './first'; |
|||
export { value }; |
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 'imports default and named exports in same declaration' |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-default-named-function
|
@ -0,0 +1,7 @@ |
|||
export default function foo() { |
|||
return 1; |
|||
} |
|||
|
|||
export function callsFoo() { |
|||
return foo(); |
|||
} |
@ -0,0 +1,4 @@ |
|||
import foo, { callsFoo } from './foo'; |
|||
|
|||
assert.strictEqual(foo(), 1); |
|||
assert.strictEqual(callsFoo(), 1); |
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 'imports a default export by a name' |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-default-function
|
@ -0,0 +1,3 @@ |
|||
export default function () { |
|||
return 1; |
|||
} |
@ -0,0 +1,6 @@ |
|||
import fn1 from './foo'; |
|||
|
|||
import { default as fn2 } from './foo'; |
|||
|
|||
assert.equal(fn1(), 1); |
|||
assert.equal(fn2(), 1); |
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
description: 'imports a default class', |
|||
babel: [ 'es6.classes' ] |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-default-class
|
@ -0,0 +1,4 @@ |
|||
import Point from './exporter'; |
|||
|
|||
assert.strictEqual(new Point(1, 2).x, 1); |
|||
assert.strictEqual(new Point(1, 2).y, 2); |
@ -0,0 +1,6 @@ |
|||
export default class Point { |
|||
constructor(x, y) { |
|||
this.x = x; |
|||
this.y = y; |
|||
} |
|||
} |
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
description: 'imports a named class', |
|||
babel: [ 'es6.classes' ] |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-named-class
|
@ -0,0 +1,2 @@ |
|||
class Foo {} |
|||
export { Foo }; |
@ -0,0 +1,3 @@ |
|||
import { Foo } from './foo'; |
|||
|
|||
assert.strictEqual(new Foo().constructor, Foo); |
@ -0,0 +1,6 @@ |
|||
module.exports = { |
|||
description: 'imports a nameless class expression', |
|||
babel: [ 'es6.classes' ] |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/export-class-expression
|
@ -0,0 +1 @@ |
|||
export default class {}; |
@ -0,0 +1,3 @@ |
|||
import Foo from './foo'; |
|||
|
|||
assert.strictEqual(new Foo().constructor, Foo); |
@ -0,0 +1,8 @@ |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'disallows non-top-level imports', |
|||
error: function ( err ) { |
|||
assert.ok( false, 'TODO: pick an error message' ); |
|||
} |
|||
}; |
@ -0,0 +1,3 @@ |
|||
function foo() { |
|||
import foo from './foo'; |
|||
} |
@ -0,0 +1,10 @@ |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'disallows reassignments to namespace exports', |
|||
error: function ( err ) { |
|||
assert.ok( false, 'TODO figure out correct error' ); |
|||
} |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/namespace-reassign-import-fails
|
@ -0,0 +1 @@ |
|||
export var foo = 1; |
@ -0,0 +1,3 @@ |
|||
import * as exp from './foo'; |
|||
|
|||
exp.foo = 2; |
@ -0,0 +1,10 @@ |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'disallows updates to namespace exports', |
|||
error: function ( err ) { |
|||
assert.ok( false, 'TODO figure out correct error' ); |
|||
} |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/namespace-update-import-fails
|
@ -0,0 +1 @@ |
|||
export var foo = 1; |
@ -0,0 +1,3 @@ |
|||
import * as exp from './foo'; |
|||
|
|||
exp['foo']++; |
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 'imports a namespace from an internal module' |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/namespaces
|
@ -0,0 +1,3 @@ |
|||
export var a = 'a'; |
|||
export var b = 'b'; |
|||
export default 'DEF'; |
@ -0,0 +1,11 @@ |
|||
import * as foo from './foo'; |
|||
|
|||
assert.equal(foo['default'], 'DEF'); |
|||
assert.equal(foo.b, 'b'); |
|||
assert.equal(foo.a, 'a'); |
|||
|
|||
var keys = []; |
|||
for (var key in foo) { |
|||
keys.push(key); |
|||
} |
|||
assert.deepEqual(keys.sort(), ['a', 'b', 'default']); |
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 're-exports a default import' |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/re-export-default-import
|
@ -0,0 +1,3 @@ |
|||
export default function hi() { |
|||
return 'hi'; |
|||
} |
@ -0,0 +1,2 @@ |
|||
import { hi } from './second'; |
|||
assert.equal(hi(), 'hi'); |
@ -0,0 +1,2 @@ |
|||
import hi from './first'; |
|||
export { hi }; |
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 're-exports a namespace import' |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/re-export-namespace-import
|
@ -0,0 +1,2 @@ |
|||
export var a = 1; |
|||
export var b = 2; |
@ -0,0 +1,4 @@ |
|||
import { mod } from './second'; |
|||
|
|||
assert.strictEqual(mod.a, 1); |
|||
assert.strictEqual(mod.b, 2); |
@ -0,0 +1,2 @@ |
|||
import * as mod from './first'; |
|||
export { mod }; |
@ -0,0 +1,10 @@ |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'disallows assignments to imported bindings', |
|||
error: function ( err ) { |
|||
assert.ok( false, 'TODO choose error' ); |
|||
} |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/reassign-import-fails
|
@ -0,0 +1 @@ |
|||
export var x = 1; |
@ -0,0 +1,8 @@ |
|||
import { x } from './foo'; |
|||
|
|||
(function() { |
|||
for(var x = 0; x < 1; x++){} |
|||
for(var x = 0; x < 1; x++){} |
|||
}); |
|||
|
|||
x = 10; |
@ -0,0 +1,10 @@ |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'disallows assignments to imported bindings not at the top level', |
|||
error: function ( err ) { |
|||
assert.ok( false, 'TODO choose error' ); |
|||
} |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/reassign-import-fails
|
@ -0,0 +1 @@ |
|||
export var x = 1; |
@ -0,0 +1,8 @@ |
|||
import { x } from './foo'; |
|||
|
|||
export function foo () { |
|||
var x = 1; |
|||
} |
|||
export function bar () { |
|||
x = 1; |
|||
} |
@ -0,0 +1,5 @@ |
|||
module.exports = { |
|||
description: 'renames shadowed variables correctly' |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/named-function-expression
|
@ -0,0 +1 @@ |
|||
export var a = 1; |
@ -0,0 +1,9 @@ |
|||
import { a } from './foo'; |
|||
|
|||
var getA = function getA() { |
|||
var a = 2; |
|||
return a; |
|||
}; |
|||
|
|||
assert.strictEqual(a, 1); |
|||
assert.strictEqual(getA(), 2); |
@ -0,0 +1,3 @@ |
|||
module.exports = { |
|||
description: 'this at top level is undefined' |
|||
}; |
@ -0,0 +1 @@ |
|||
assert.strictEqual( this, undefined ); |
@ -0,0 +1,10 @@ |
|||
var assert = require( 'assert' ); |
|||
|
|||
module.exports = { |
|||
description: 'disallows updates to imported bindings', |
|||
error: function ( err ) { |
|||
assert.ok( false, 'TODO choose error' ); |
|||
} |
|||
}; |
|||
|
|||
// test copied from https://github.com/esnext/es6-module-transpiler/tree/master/test/examples/update-expression-of-import-fails
|
@ -0,0 +1 @@ |
|||
export var a = 0; |
@ -0,0 +1,3 @@ |
|||
import { a } from './foo'; |
|||
|
|||
a++; |
Loading…
Reference in new issue