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 #5261 from webpack/bugfix/import-context-strict-this
Fixes for import call context
- Loading branch information
Showing
12 changed files
with
160 additions
and
16 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
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,14 @@ | ||
function returnThis() { | ||
if(typeof this === "undefined") return "undefined"; | ||
return this; | ||
} | ||
|
||
var a = returnThis; | ||
var b = returnThis; | ||
|
||
export { | ||
a, | ||
b | ||
} | ||
|
||
export default returnThis; |
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,28 @@ | ||
"use strict"; | ||
|
||
import d, {a, b as B} from "./abc"; | ||
|
||
import * as abc from "./abc"; | ||
|
||
function x() { throw new Error("should not be executed"); } | ||
it("should have this = undefined on imported non-strict functions", function() { | ||
x | ||
d().should.be.eql("undefined"); | ||
x | ||
a().should.be.eql("undefined"); | ||
x | ||
B().should.be.eql("undefined"); | ||
}); | ||
|
||
import C2, { C } from "./new"; | ||
|
||
import * as New from "./new"; | ||
|
||
it("should be possible to use new correctly", function() { | ||
x | ||
new C().should.match({ok: true}); | ||
x | ||
new C2().should.match({ok: true}); | ||
x | ||
new New.C().should.match({ok: true}); | ||
}); |
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 @@ | ||
function C() { | ||
this.ok = this.pok; | ||
} | ||
|
||
C.prototype.pok = true; | ||
|
||
export default C; | ||
export { | ||
C | ||
}; |
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,14 @@ | ||
function returnThis() { | ||
if(typeof this === "undefined") return "undefined"; | ||
return this; | ||
} | ||
|
||
var a = returnThis; | ||
var b = returnThis; | ||
|
||
export { | ||
a, | ||
b | ||
} | ||
|
||
export default returnThis; |
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,33 @@ | ||
"use strict"; | ||
|
||
import d, {a, b as B} from "./abc"; | ||
|
||
import * as abc from "./abc"; | ||
|
||
function x() { throw new Error("should not be executed"); } | ||
it("should have this = undefined on imported non-strict functions", function() { | ||
x | ||
d().should.be.eql("undefined"); | ||
x | ||
a().should.be.eql("undefined"); | ||
x | ||
B().should.be.eql("undefined"); | ||
x | ||
abc.a().should.be.type("object"); | ||
x | ||
var thing = abc.a(); | ||
Object.keys(thing).should.be.eql(["a", "b", "default"]); | ||
}); | ||
|
||
import C2, { C } from "./new"; | ||
|
||
import * as New from "./new"; | ||
|
||
it("should be possible to use new correctly", function() { | ||
x | ||
new C().should.match({ok: true}); | ||
x | ||
new C2().should.match({ok: true}); | ||
x | ||
new New.C().should.match({ok: true}); | ||
}); |
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 @@ | ||
function C() { | ||
this.ok = this.pok; | ||
} | ||
|
||
C.prototype.pok = true; | ||
|
||
export default C; | ||
export { | ||
C | ||
}; |
9 changes: 9 additions & 0 deletions
9
test/configCases/parsing/harmony-this-concat/webpack.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,9 @@ | ||
var webpack = require("../../../../"); | ||
module.exports = { | ||
module: { | ||
strictThisContextOnImports: true | ||
}, | ||
plugins: [ | ||
new webpack.optimize.ModuleConcatenationPlugin() | ||
] | ||
}; |
11 changes: 11 additions & 0 deletions
11
test/configCases/scope-hoisting/strictThisContextOnImports/index.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,11 @@ | ||
import value, { identity } from "./module"; | ||
import * as m from "./module"; | ||
|
||
it("should parse and translate identifiers correctly", function() { | ||
identity(value).should.be.eql(1234); | ||
m.identity(value).should.be.eql(1234); | ||
m.identity(identity).should.be.eql(identity); | ||
m.identity(m.identity).should.be.eql(m.identity); | ||
identity(m.identity).should.be.eql(m.identity); | ||
identity(m.default).should.be.eql(1234); | ||
}); |
2 changes: 2 additions & 0 deletions
2
test/configCases/scope-hoisting/strictThisContextOnImports/module.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,2 @@ | ||
export function identity(a) { return a; } | ||
export default 1234; |
9 changes: 9 additions & 0 deletions
9
test/configCases/scope-hoisting/strictThisContextOnImports/webpack.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,9 @@ | ||
var webpack = require("../../../../"); | ||
module.exports = { | ||
module: { | ||
strictThisContextOnImports: true | ||
}, | ||
plugins: [ | ||
new webpack.optimize.ModuleConcatenationPlugin() | ||
] | ||
}; |