Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export default class Bundle {
this.externalModules = [];
this.internalNamespaces = [];

this.context = String( options.context );
this.assumedGlobals = blank();

if ( typeof options.external === 'function' ) {
Expand Down
4 changes: 2 additions & 2 deletions src/Statement.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export default class Statement {
}

if ( node.type === 'ThisExpression' && contextDepth === 0 ) {
module.magicString.overwrite( node.start, node.end, 'undefined' );
module.bundle.onwarn( 'The `this` keyword is equivalent to `undefined` at the top level of an ES module, and has been rewritten' );
module.magicString.overwrite( node.start, node.end, module.bundle.context );
if ( module.bundle.context === 'undefined' ) module.bundle.onwarn( 'The `this` keyword is equivalent to `undefined` at the top level of an ES module, and has been rewritten' );
}

if ( node._scope ) scope = node._scope;
Expand Down
1 change: 1 addition & 0 deletions src/rollup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const ALLOWED_KEYS = [
'acorn',
'banner',
'cache',
'context',
'dest',
'entry',
'exports',
Expand Down
6 changes: 6 additions & 0 deletions test/form/custom-context/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
description: 'allows custom context',
options: {
context: `lolwut`
}
};
5 changes: 5 additions & 0 deletions test/form/custom-context/_expected/amd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
define(function () { 'use strict';

lolwut.prop = '???';

});
3 changes: 3 additions & 0 deletions test/form/custom-context/_expected/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

lolwut.prop = '???';
1 change: 1 addition & 0 deletions test/form/custom-context/_expected/es.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lolwut.prop = '???';
6 changes: 6 additions & 0 deletions test/form/custom-context/_expected/iife.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(function () {
'use strict';

lolwut.prop = '???';

}());
9 changes: 9 additions & 0 deletions test/form/custom-context/_expected/umd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory() :
typeof define === 'function' && define.amd ? define(factory) :
(factory());
}(this, (function () { 'use strict';

lolwut.prop = '???';

})));
1 change: 1 addition & 0 deletions test/form/custom-context/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this.prop = '???';
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ describe( 'rollup', function () {
return rollup.rollup({ entry: 'x', plUgins: [] }).then( () => {
throw new Error( 'Missing expected error' );
}, err => {
assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: acorn, banner, cache, dest, entry, exports, external, footer, format, globals, indent, intro, moduleId, moduleName, noConflict, onwarn, outro, paths, plugins, preferConst, sourceMap, sourceMapFile, targets, treeshake, useStrict' );
assert.equal( err.message, 'Unexpected key \'plUgins\' found, expected one of: acorn, banner, cache, context, dest, entry, exports, external, footer, format, globals, indent, intro, moduleId, moduleName, noConflict, onwarn, outro, paths, plugins, preferConst, sourceMap, sourceMapFile, targets, treeshake, useStrict' );
});
});
});
Expand Down