mirror of https://github.com/lukechilds/rollup.git
Rich Harris
8 years ago
committed by
GitHub
20 changed files with 172 additions and 46 deletions
@ -1,15 +1,19 @@ |
|||
export default function getGlobalNameMaker ( globals, bundle ) { |
|||
export default function getGlobalNameMaker ( globals, bundle, fallback = null ) { |
|||
const fn = typeof globals === 'function' ? globals : id => globals[ id ]; |
|||
|
|||
return function ( module ) { |
|||
const name = fn( module.id ); |
|||
if ( name ) return name; |
|||
|
|||
bundle.warn({ |
|||
code: 'MISSING_GLOBAL_NAME', |
|||
message: `No name was provided for external module '${module.id}' in options.globals – guessing '${module.name}'` |
|||
}); |
|||
if ( Object.keys( module.declarations ).length > 0 ) { |
|||
bundle.warn({ |
|||
code: 'MISSING_GLOBAL_NAME', |
|||
message: `No name was provided for external module '${module.id}' in options.globals – guessing '${module.name}'` |
|||
}); |
|||
|
|||
return module.name; |
|||
return module.name; |
|||
} |
|||
|
|||
return fallback; |
|||
}; |
|||
} |
|||
|
@ -1,18 +0,0 @@ |
|||
// Generate strings which dereference dotted properties, but use array notation `['prop-deref']`
|
|||
// if the property name isn't trivial
|
|||
|
|||
const shouldUseDot = /^[a-zA-Z$_][a-zA-Z0-9$_]*$/; |
|||
const dereferenceString = prop => |
|||
prop.match(shouldUseDot) ? `.${prop}` : `['${prop}']`; |
|||
|
|||
/** |
|||
* returns a function which generates property dereference strings for the given name |
|||
* |
|||
* const getGlobalProp = propertyStringFor('global'); |
|||
* getGlobalProp('foo.bar-baz.qux') => `global.bar['bar-baz'].qux` |
|||
*/ |
|||
const propertyStringFor = objName => propName => |
|||
objName + propName.split('.').map(dereferenceString).join(''); |
|||
|
|||
|
|||
export default propertyStringFor; |
@ -0,0 +1,11 @@ |
|||
// Generate strings which dereference dotted properties, but use array notation `['prop-deref']`
|
|||
// if the property name isn't trivial
|
|||
const shouldUseDot = /^[a-zA-Z$_][a-zA-Z0-9$_]*$/; |
|||
|
|||
export function property ( prop ) { |
|||
return shouldUseDot.test( prop ) ? `.${prop}` : `['${prop}']`; |
|||
} |
|||
|
|||
export function keypath ( keypath ) { |
|||
return keypath.split( '.' ).map( property ).join( '' ); |
|||
} |
@ -0,0 +1,12 @@ |
|||
export default function trimEmptyImports ( modules ) { |
|||
let i = modules.length; |
|||
|
|||
while ( i-- ) { |
|||
const module = modules[i]; |
|||
if ( Object.keys( module.declarations ).length > 0 ) { |
|||
return modules.slice( 0, i + 1 ); |
|||
} |
|||
} |
|||
|
|||
return []; |
|||
} |
@ -0,0 +1,11 @@ |
|||
module.exports = { |
|||
description: 'does not expect a global to be provided for empty imports (#1217)', |
|||
options: { |
|||
external: [ 'babel-polyfill', 'other' ], |
|||
moduleName: 'myBundle', |
|||
globals: { other: 'other' }, |
|||
onwarn ( warning ) { |
|||
throw new Error( warning.message ); |
|||
} |
|||
} |
|||
}; |
@ -0,0 +1,9 @@ |
|||
define(['babel-polyfill', 'other'], function (babelPolyfill, other) { 'use strict'; |
|||
|
|||
other.x(); |
|||
|
|||
var main = new WeakMap(); |
|||
|
|||
return main; |
|||
|
|||
}); |
@ -0,0 +1,10 @@ |
|||
'use strict'; |
|||
|
|||
require('babel-polyfill'); |
|||
var other = require('other'); |
|||
|
|||
other.x(); |
|||
|
|||
var main = new WeakMap(); |
|||
|
|||
module.exports = main; |
@ -0,0 +1,8 @@ |
|||
import 'babel-polyfill'; |
|||
import { x } from 'other'; |
|||
|
|||
x(); |
|||
|
|||
var main = new WeakMap(); |
|||
|
|||
export default main; |
@ -0,0 +1,10 @@ |
|||
var myBundle = (function (babelPolyfill,other) { |
|||
'use strict'; |
|||
|
|||
other.x(); |
|||
|
|||
var main = new WeakMap(); |
|||
|
|||
return main; |
|||
|
|||
}(null,other)); |
@ -0,0 +1,13 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('babel-polyfill'), require('other')) : |
|||
typeof define === 'function' && define.amd ? define(['babel-polyfill', 'other'], factory) : |
|||
(global.myBundle = factory(null,global.other)); |
|||
}(this, (function (babelPolyfill,other) { 'use strict'; |
|||
|
|||
other.x(); |
|||
|
|||
var main = new WeakMap(); |
|||
|
|||
return main; |
|||
|
|||
}))); |
@ -0,0 +1,6 @@ |
|||
import 'babel-polyfill'; |
|||
import { x } from 'other'; |
|||
|
|||
x(); |
|||
|
|||
export default new WeakMap(); |
@ -0,0 +1,10 @@ |
|||
module.exports = { |
|||
description: 'does not expect a global to be provided for empty imports (#1217)', |
|||
options: { |
|||
external: [ 'babel-polyfill' ], |
|||
moduleName: 'myBundle', |
|||
onwarn ( warning ) { |
|||
throw new Error( warning.message ); |
|||
} |
|||
} |
|||
}; |
@ -0,0 +1,7 @@ |
|||
define(['babel-polyfill'], function (babelPolyfill) { 'use strict'; |
|||
|
|||
var main = new WeakMap(); |
|||
|
|||
return main; |
|||
|
|||
}); |
@ -0,0 +1,7 @@ |
|||
'use strict'; |
|||
|
|||
require('babel-polyfill'); |
|||
|
|||
var main = new WeakMap(); |
|||
|
|||
module.exports = main; |
@ -0,0 +1,5 @@ |
|||
import 'babel-polyfill'; |
|||
|
|||
var main = new WeakMap(); |
|||
|
|||
export default main; |
@ -0,0 +1,8 @@ |
|||
var myBundle = (function () { |
|||
'use strict'; |
|||
|
|||
var main = new WeakMap(); |
|||
|
|||
return main; |
|||
|
|||
}()); |
@ -0,0 +1,11 @@ |
|||
(function (global, factory) { |
|||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('babel-polyfill')) : |
|||
typeof define === 'function' && define.amd ? define(['babel-polyfill'], factory) : |
|||
(global.myBundle = factory()); |
|||
}(this, (function () { 'use strict'; |
|||
|
|||
var main = new WeakMap(); |
|||
|
|||
return main; |
|||
|
|||
}))); |
@ -0,0 +1,3 @@ |
|||
import 'babel-polyfill'; |
|||
|
|||
export default new WeakMap(); |
Loading…
Reference in new issue