mirror of https://github.com/lukechilds/rollup.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
654 B
34 lines
654 B
export default function transform ( source, id, transformers ) {
|
|
let sourceMapChain = [];
|
|
|
|
if ( typeof source === 'string' ) {
|
|
source = {
|
|
code: source,
|
|
ast: null
|
|
};
|
|
}
|
|
|
|
let originalCode = source.code;
|
|
let ast = source.ast;
|
|
|
|
let code = transformers.reduce( ( previous, transformer ) => {
|
|
let result = transformer( previous, id );
|
|
|
|
if ( result == null ) return previous;
|
|
|
|
if ( typeof result === 'string' ) {
|
|
result = {
|
|
code: result,
|
|
ast: null,
|
|
map: null
|
|
};
|
|
}
|
|
|
|
sourceMapChain.push( result.map );
|
|
ast = result.ast;
|
|
|
|
return result.code;
|
|
}, source.code );
|
|
|
|
return { code, originalCode, ast, sourceMapChain };
|
|
}
|
|
|