Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid name conflicts when inlining dynamic imports nested in functions (
#3256) * Avoid name conflicts when inlining dynamic imports nested in functions * Deduplicate code * Remove unneeded checks
- Loading branch information
1 parent
99a715a
commit 973c046
Showing
19 changed files
with
209 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
description: 'deconflicts variables when nested dynamic imports are inlined', | ||
options: { | ||
inlineDynamicImports: true | ||
} | ||
}; |
18 changes: 18 additions & 0 deletions
18
test/form/samples/nested-inlined-dynamic-import/_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,18 @@ | ||
define(function () { 'use strict'; | ||
|
||
async function main() { | ||
const foo$1 = 1; | ||
const ns = await Promise.resolve().then(function () { return foo; }); | ||
console.log(ns.value + foo$1); | ||
} | ||
|
||
main(); | ||
|
||
const value = 42; | ||
|
||
var foo = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
value: value | ||
}); | ||
|
||
}); |
16 changes: 16 additions & 0 deletions
16
test/form/samples/nested-inlined-dynamic-import/_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,16 @@ | ||
'use strict'; | ||
|
||
async function main() { | ||
const foo$1 = 1; | ||
const ns = await Promise.resolve().then(function () { return foo; }); | ||
console.log(ns.value + foo$1); | ||
} | ||
|
||
main(); | ||
|
||
const value = 42; | ||
|
||
var foo = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
value: value | ||
}); |
14 changes: 14 additions & 0 deletions
14
test/form/samples/nested-inlined-dynamic-import/_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,14 @@ | ||
async function main() { | ||
const foo$1 = 1; | ||
const ns = await Promise.resolve().then(function () { return foo; }); | ||
console.log(ns.value + foo$1); | ||
} | ||
|
||
main(); | ||
|
||
const value = 42; | ||
|
||
var foo = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
value: value | ||
}); |
19 changes: 19 additions & 0 deletions
19
test/form/samples/nested-inlined-dynamic-import/_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,19 @@ | ||
(function () { | ||
'use strict'; | ||
|
||
async function main() { | ||
const foo$1 = 1; | ||
const ns = await Promise.resolve().then(function () { return foo; }); | ||
console.log(ns.value + foo$1); | ||
} | ||
|
||
main(); | ||
|
||
const value = 42; | ||
|
||
var foo = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
value: value | ||
}); | ||
|
||
}()); |
23 changes: 23 additions & 0 deletions
23
test/form/samples/nested-inlined-dynamic-import/_expected/system.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,23 @@ | ||
System.register([], function () { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
|
||
async function main() { | ||
const foo$1 = 1; | ||
const ns = await Promise.resolve().then(function () { return foo; }); | ||
console.log(ns.value + foo$1); | ||
} | ||
|
||
main(); | ||
|
||
const value = 42; | ||
|
||
var foo = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
value: value | ||
}); | ||
|
||
} | ||
}; | ||
}); |
21 changes: 21 additions & 0 deletions
21
test/form/samples/nested-inlined-dynamic-import/_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,21 @@ | ||
(function (factory) { | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
factory(); | ||
}((function () { 'use strict'; | ||
|
||
async function main() { | ||
const foo$1 = 1; | ||
const ns = await Promise.resolve().then(function () { return foo; }); | ||
console.log(ns.value + foo$1); | ||
} | ||
|
||
main(); | ||
|
||
const value = 42; | ||
|
||
var foo = /*#__PURE__*/Object.freeze({ | ||
__proto__: null, | ||
value: value | ||
}); | ||
|
||
}))); |
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 @@ | ||
export const value = 42; |
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,7 @@ | ||
async function main() { | ||
const foo = 1; | ||
const ns = await import('./foo.js'); | ||
console.log(ns.value + foo); | ||
} | ||
|
||
main(); |
12 changes: 12 additions & 0 deletions
12
test/function/samples/nested-inlined-dynamic-import-1/_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,12 @@ | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
description: | ||
'deconflicts variables when nested dynamic imports are inlined via inlineDynamicImports', | ||
options: { | ||
inlineDynamicImports: true | ||
}, | ||
exports(exports) { | ||
return exports().then(result => assert.strictEqual(result, 43)); | ||
} | ||
}; |
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 @@ | ||
export const value = 42; |
4 changes: 4 additions & 0 deletions
4
test/function/samples/nested-inlined-dynamic-import-1/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default () => { | ||
const foo = 1; | ||
return import('./foo.js').then(ns => ns.value + foo); | ||
}; |
16 changes: 16 additions & 0 deletions
16
test/function/samples/nested-inlined-dynamic-import-2/_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,16 @@ | ||
const assert = require('assert'); | ||
|
||
module.exports = { | ||
description: 'deconflicts variables when nested dynamic imports are inlined', | ||
warnings: [ | ||
{ | ||
code: 'CIRCULAR_DEPENDENCY', | ||
cycle: ['lib1.js', 'lib2.js', 'lib1.js'], | ||
importer: 'lib1.js', | ||
message: 'Circular dependency: lib1.js -> lib2.js -> lib1.js' | ||
} | ||
], | ||
exports(exports) { | ||
return exports().then(result => assert.strictEqual(result, 43)); | ||
} | ||
}; |
6 changes: 6 additions & 0 deletions
6
test/function/samples/nested-inlined-dynamic-import-2/lib1.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,6 @@ | ||
import './lib2.js'; | ||
|
||
export default () => { | ||
const lib2 = 1; | ||
return import('./lib2.js').then(ns => ns.foo + lib2); | ||
}; |
3 changes: 3 additions & 0 deletions
3
test/function/samples/nested-inlined-dynamic-import-2/lib2.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,3 @@ | ||
import './lib1.js'; | ||
|
||
export const foo = 42; |
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 @@ | ||
export {default} from './lib1.js'; |