mirror of https://github.com/lukechilds/rollup.git
Rich-Harris
10 years ago
3 changed files with 61 additions and 17 deletions
@ -0,0 +1,35 @@ |
|||
var acorn = require( 'acorn' ); |
|||
|
|||
var modules = { |
|||
'main': 'import foo from \'foo\';\nfoo();', |
|||
|
|||
// the code points to './bar' but the AST points to './baz', so we
|
|||
// can check the AST is being used
|
|||
'foo': { |
|||
code: 'import bar from \'bar\';\nexport default function foo () {\n\tconsole.log( bar );\n}', |
|||
ast: acorn.parse( 'import bar from \'baz\';\nexport default function foo () {\n\tconsole.log( bar );\n}', { |
|||
ecmaVersion: 6, |
|||
sourceType: 'module' |
|||
}) |
|||
}, |
|||
|
|||
'baz': 'export default 42;' |
|||
}; |
|||
|
|||
module.exports = { |
|||
description: 'uses supplied AST', |
|||
options: { |
|||
resolveId: function ( importee, importer ) { |
|||
if ( !importer ) return 'main'; |
|||
return importee; |
|||
}, |
|||
load: function ( id ) { |
|||
if ( id === 'bar' ) { |
|||
throw new Error( 'loaded incorrect module' ); |
|||
} |
|||
|
|||
return modules[ id ]; |
|||
} |
|||
}, |
|||
solo: true |
|||
}; |
Loading…
Reference in new issue