mirror of https://github.com/lukechilds/rollup.git
Rich-Harris
10 years ago
8 changed files with 97 additions and 11 deletions
@ -1,3 +1,39 @@ |
|||
import { has } from '../utils/object'; |
|||
import { getName, quoteId } from '../utils/map-helpers'; |
|||
|
|||
export default function amd ( bundle, magicString, exportMode, options ) { |
|||
throw new Error( 'TODO' ); |
|||
const indentStr = magicString.getIndentString(); |
|||
|
|||
let deps = bundle.externalModules.map( quoteId ); |
|||
let args = bundle.externalModules.map( getName ); |
|||
|
|||
if ( exportMode === 'named' ) { |
|||
args.unshift( `exports` ); |
|||
deps.unshift( `'exports'` ); |
|||
} |
|||
|
|||
const params = |
|||
( has( options, 'moduleId' ) ? `['${options.moduleId}'], ` : `` ) + |
|||
( deps.length ? `[${deps.join( ', ' )}], ` : `` ); |
|||
|
|||
const intro = `define(${params}function (${args.join( ', ' )}) { 'use strict';\n\n`; |
|||
|
|||
const exports = bundle.entryModule.exports; |
|||
|
|||
let exportBlock; |
|||
|
|||
if ( exportMode === 'default' ) { |
|||
exportBlock = `return ${bundle.entryModule.getCanonicalName('default')};`; |
|||
} else { |
|||
exportBlock = '\n\n' + Object.keys( exports ).map( name => { |
|||
return `exports.${name} = ${exports[name].localName};`; |
|||
}).join( '\n' ); |
|||
} |
|||
|
|||
return magicString |
|||
.append( exportBlock ) |
|||
.trim() |
|||
.indent() |
|||
.append( '\n\n});' ) |
|||
.prepend( intro ); |
|||
} |
|||
|
@ -1,3 +1,7 @@ |
|||
export default function es6 ( bundle, magicString, exportMode, options ) { |
|||
throw new Error( 'TODO' ); |
|||
// TODO
|
|||
const introBlock = ''; |
|||
const exportBlock = ''; |
|||
|
|||
return magicString.trim(); |
|||
} |
|||
|
@ -1,3 +1,11 @@ |
|||
export function getName ( x ) { |
|||
return x.name; |
|||
} |
|||
} |
|||
|
|||
export function quoteId ( x ) { |
|||
return `'${x.id}'` |
|||
} |
|||
|
|||
export function req ( x ) { |
|||
return `require('${x.id}')` |
|||
} |
|||
|
Loading…
Reference in new issue