Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve context for amd/cjs dynamic non-arrow requires
Resolves #3092
- Loading branch information
1 parent
9d3b104
commit 431bd28
Showing
33 changed files
with
534 additions
and
87 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
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
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,12 @@ | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
description: 'uses correct "this" in dynamic imports when using arrow functions', | ||
options: { | ||
external: ['input', 'output'], | ||
output: { | ||
generatedCode: { arrowFunctions: true }, | ||
name: 'bundle' | ||
} | ||
} | ||
}; |
37 changes: 37 additions & 0 deletions
37
test/form/samples/dynamic-import-this-arrow/_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,37 @@ | ||
define(['require', 'exports', 'input'], ((require, exports, input) => { 'use strict'; | ||
|
||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(k => { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: () => e[k] | ||
}); | ||
} | ||
}); | ||
} | ||
n["default"] = e; | ||
return Object.freeze(n); | ||
} | ||
|
||
class Importer { | ||
constructor() { | ||
this.outputPath = input.outputPath; | ||
} | ||
|
||
getImport() { | ||
return new Promise((resolve, reject) => require([this.outputPath], m => resolve(/*#__PURE__*/_interopNamespace(m)), reject)); | ||
} | ||
} | ||
|
||
const promise = new Importer().getImport(); | ||
|
||
exports.promise = promise; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
})); |
37 changes: 37 additions & 0 deletions
37
test/form/samples/dynamic-import-this-arrow/_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,37 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
var input = require('input'); | ||
|
||
function _interopNamespace(e) { | ||
if (e && e.__esModule) return e; | ||
var n = Object.create(null); | ||
if (e) { | ||
Object.keys(e).forEach(k => { | ||
if (k !== 'default') { | ||
var d = Object.getOwnPropertyDescriptor(e, k); | ||
Object.defineProperty(n, k, d.get ? d : { | ||
enumerable: true, | ||
get: () => e[k] | ||
}); | ||
} | ||
}); | ||
} | ||
n["default"] = e; | ||
return Object.freeze(n); | ||
} | ||
|
||
class Importer { | ||
constructor() { | ||
this.outputPath = input.outputPath; | ||
} | ||
|
||
getImport() { | ||
return Promise.resolve().then(() => /*#__PURE__*/_interopNamespace(require(this.outputPath))); | ||
} | ||
} | ||
|
||
const promise = new Importer().getImport(); | ||
|
||
exports.promise = promise; |
15 changes: 15 additions & 0 deletions
15
test/form/samples/dynamic-import-this-arrow/_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,15 @@ | ||
import { outputPath } from 'input'; | ||
|
||
class Importer { | ||
constructor() { | ||
this.outputPath = outputPath; | ||
} | ||
|
||
getImport() { | ||
return import(this.outputPath); | ||
} | ||
} | ||
|
||
const promise = new Importer().getImport(); | ||
|
||
export { promise }; |
22 changes: 22 additions & 0 deletions
22
test/form/samples/dynamic-import-this-arrow/_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,22 @@ | ||
var bundle = ((exports, input) => { | ||
'use strict'; | ||
|
||
class Importer { | ||
constructor() { | ||
this.outputPath = input.outputPath; | ||
} | ||
|
||
getImport() { | ||
return import(this.outputPath); | ||
} | ||
} | ||
|
||
const promise = new Importer().getImport(); | ||
|
||
exports.promise = promise; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
return exports; | ||
|
||
})({}, input); |
Oops, something went wrong.