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 #707 from rollup/undefined-this
rewrite top-level this as undefined
- Loading branch information
Showing
9 changed files
with
115 additions
and
8 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,3 @@ | ||
module.exports = { | ||
description: 'top-level `this` expression is rewritten as `undefined`' | ||
}; |
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,21 @@ | ||
define(function () { 'use strict'; | ||
|
||
const fooContext = {}; | ||
|
||
function foo () { | ||
// inside a function, `this` should be untouched... | ||
assert.strictEqual( this, fooContext ); | ||
} | ||
|
||
const bar = () => { | ||
// ...unless it's an arrow function | ||
assert.strictEqual( undefined, undefined ); | ||
} | ||
|
||
foo.call( fooContext ); | ||
bar.call( {} ); | ||
|
||
// outside a function, `this` is undefined | ||
assert.strictEqual( undefined, undefined ); | ||
|
||
}); |
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,19 @@ | ||
'use strict'; | ||
|
||
const fooContext = {}; | ||
|
||
function foo () { | ||
// inside a function, `this` should be untouched... | ||
assert.strictEqual( this, fooContext ); | ||
} | ||
|
||
const bar = () => { | ||
// ...unless it's an arrow function | ||
assert.strictEqual( undefined, undefined ); | ||
} | ||
|
||
foo.call( fooContext ); | ||
bar.call( {} ); | ||
|
||
// outside a function, `this` is undefined | ||
assert.strictEqual( undefined, undefined ); |
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,17 @@ | ||
const fooContext = {}; | ||
|
||
function foo () { | ||
// inside a function, `this` should be untouched... | ||
assert.strictEqual( this, fooContext ); | ||
} | ||
|
||
const bar = () => { | ||
// ...unless it's an arrow function | ||
assert.strictEqual( undefined, undefined ); | ||
} | ||
|
||
foo.call( fooContext ); | ||
bar.call( {} ); | ||
|
||
// outside a function, `this` is undefined | ||
assert.strictEqual( undefined, undefined ); |
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 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
const fooContext = {}; | ||
|
||
function foo () { | ||
// inside a function, `this` should be untouched... | ||
assert.strictEqual( this, fooContext ); | ||
} | ||
|
||
const bar = () => { | ||
// ...unless it's an arrow function | ||
assert.strictEqual( undefined, undefined ); | ||
} | ||
|
||
foo.call( fooContext ); | ||
bar.call( {} ); | ||
|
||
// outside a function, `this` is undefined | ||
assert.strictEqual( undefined, undefined ); | ||
|
||
}()); |
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,25 @@ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(factory()); | ||
}(this, function () { 'use strict'; | ||
|
||
const fooContext = {}; | ||
|
||
function foo () { | ||
// inside a function, `this` should be untouched... | ||
assert.strictEqual( this, fooContext ); | ||
} | ||
|
||
const bar = () => { | ||
// ...unless it's an arrow function | ||
assert.strictEqual( undefined, undefined ); | ||
} | ||
|
||
foo.call( fooContext ); | ||
bar.call( {} ); | ||
|
||
// outside a function, `this` is undefined | ||
assert.strictEqual( undefined, undefined ); | ||
|
||
})); |
2 changes: 1 addition & 1 deletion
2
test/function/this-is-undefined/main.js → test/form/this-is-undefined/main.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
This file was deleted.
Oops, something went wrong.