Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1747 from adrianheine/master
Use globals map for export name
- Loading branch information
Showing
10 changed files
with
84 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { property } from './sanitize.js'; | ||
|
||
export default function setupNamespace ( name, root, forAssignment, globals ) { | ||
const parts = name.split( '.' ); | ||
if (globals) { | ||
parts[0] = (typeof globals === 'function' ? globals( parts[0] ) : globals[ parts[ 0 ] ]) || parts[0]; | ||
} | ||
|
||
const last = parts.pop(); | ||
|
||
let acc = root; | ||
if (forAssignment) { | ||
return parts | ||
.map( part => ( acc += property( part ), `${acc} = ${acc} || {}` ) ) | ||
.concat( `${acc}${property( last )}` ) | ||
.join( ', ' ); | ||
} else { | ||
return parts | ||
.map( part => ( acc += property( part ), `${acc} = ${acc} || {};` ) ) | ||
.join( '\n' ) + '\n'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
test/form/samples/use-global-map-for-export-name/_config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
description: 'applies globals to output name', | ||
options: { | ||
name: 'leaflet.terminator', | ||
external: [ 'leaflet' ], | ||
globals: { | ||
'leaflet': 'L' | ||
} | ||
} | ||
}; |
8 changes: 8 additions & 0 deletions
8
test/form/samples/use-global-map-for-export-name/_expected/amd.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
define(['leaflet'], function (L) { 'use strict'; | ||
|
||
L = L && L.hasOwnProperty('default') ? L['default'] : L; | ||
|
||
L.terminator = function(options) { | ||
}; | ||
|
||
}); |
8 changes: 8 additions & 0 deletions
8
test/form/samples/use-global-map-for-export-name/_expected/cjs.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
|
||
var L = _interopDefault(require('leaflet')); | ||
|
||
L.terminator = function(options) { | ||
}; |
4 changes: 4 additions & 0 deletions
4
test/form/samples/use-global-map-for-export-name/_expected/es.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import L from 'leaflet'; | ||
|
||
L.terminator = function(options) { | ||
}; |
10 changes: 10 additions & 0 deletions
10
test/form/samples/use-global-map-for-export-name/_expected/iife.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
this.L = this.L || {}; | ||
(function (L) { | ||
'use strict'; | ||
|
||
L = L && L.hasOwnProperty('default') ? L['default'] : L; | ||
|
||
L.terminator = function(options) { | ||
}; | ||
|
||
}(L)); |
12 changes: 12 additions & 0 deletions
12
test/form/samples/use-global-map-for-export-name/_expected/umd.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('leaflet')) : | ||
typeof define === 'function' && define.amd ? define(['leaflet'], factory) : | ||
(factory(global.L)); | ||
}(this, (function (L) { 'use strict'; | ||
|
||
L = L && L.hasOwnProperty('default') ? L['default'] : L; | ||
|
||
L.terminator = function(options) { | ||
}; | ||
|
||
}))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import L from 'leaflet'; | ||
|
||
L.terminator = function(options) { | ||
}; |