mirror of https://github.com/lukechilds/rollup.git
Rich-Harris
9 years ago
6 changed files with 48 additions and 5 deletions
@ -0,0 +1,11 @@ |
|||||
|
// Given a `fallback` and a `preferred` function,
|
||||
|
// return a function that attempts to call the `preferred`.
|
||||
|
// If it fails, or returns undefined, call the fallback and return its value.
|
||||
|
export default function attempt ( fallback, preferred ) { |
||||
|
return function ( ...args ) { |
||||
|
const boundFallback = () => fallback( ...args ); |
||||
|
|
||||
|
return Promise.resolve( preferred( ...args ) ) |
||||
|
.then( res => res === undefined ? boundFallback() : res, boundFallback ); |
||||
|
}; |
||||
|
} |
@ -0,0 +1,23 @@ |
|||||
|
var path = require( 'path' ); |
||||
|
var assert = require( 'assert' ); |
||||
|
|
||||
|
module.exports = { |
||||
|
description: 'uses custom path resolvers (plural)', |
||||
|
options: { |
||||
|
resolveId: [ |
||||
|
function ( importee ) { |
||||
|
if ( importee[0] === '@' ) |
||||
|
return path.resolve( __dirname, 'globals-' + importee.slice( 1 ).toLowerCase() + '.js' ); |
||||
|
}, |
||||
|
function ( importee ) { |
||||
|
if ( importee[0] === '!' ) return '<empty>'; |
||||
|
} |
||||
|
], |
||||
|
load: function ( id ) { |
||||
|
if ( id === '<empty>' ) return ''; |
||||
|
} |
||||
|
}, |
||||
|
exports: function ( exports ) { |
||||
|
assert.strictEqual( exports.res, 0 ); |
||||
|
} |
||||
|
}; |
@ -0,0 +1,2 @@ |
|||||
|
export var sin = Math.sin; |
||||
|
export var cos = Math.cos; |
@ -0,0 +1,4 @@ |
|||||
|
import { sin } from '@Math'; |
||||
|
import '!path'; |
||||
|
|
||||
|
export var res = sin( 0 ); |
Loading…
Reference in new issue