Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
emit correct code for reexport unused exports
- Loading branch information
Showing
8 changed files
with
77 additions
and
9 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
9 changes: 9 additions & 0 deletions
9
test/configCases/deep-scope-analysis/remove-export-scope-hoisting/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,9 @@ | ||
import { test, unused } from "./module"; | ||
|
||
it("should run the test", () => { | ||
expect(test()).toEqual({ | ||
used: "used", | ||
unused: undefined | ||
}); | ||
expect(unused).toEqual(undefined); | ||
}); |
10 changes: 10 additions & 0 deletions
10
test/configCases/deep-scope-analysis/remove-export-scope-hoisting/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,10 @@ | ||
import { used, unused } from "./reference"; | ||
|
||
export function test() { | ||
return { | ||
used, | ||
unused | ||
}; | ||
} | ||
|
||
export { unused } |
3 changes: 3 additions & 0 deletions
3
test/configCases/deep-scope-analysis/remove-export-scope-hoisting/reference.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 @@ | ||
export var used = "used"; | ||
|
||
export var unused = "unused"; |
34 changes: 34 additions & 0 deletions
34
test/configCases/deep-scope-analysis/remove-export-scope-hoisting/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,34 @@ | ||
const DependencyReference = require("../../../../").dependencies | ||
.DependencyReference; | ||
module.exports = { | ||
optimization: { | ||
usedExports: true, | ||
concatenateModules: true | ||
}, | ||
plugins: [ | ||
function() { | ||
this.hooks.compilation.tap("Test", compilation => { | ||
compilation.hooks.dependencyReference.tap( | ||
"Test", | ||
(ref, dep, module) => { | ||
if ( | ||
module.identifier().endsWith("module.js") && | ||
ref.module && | ||
ref.module.identifier().endsWith("reference.js") && | ||
Array.isArray(ref.importedNames) && | ||
ref.importedNames.includes("unused") | ||
) { | ||
return new DependencyReference( | ||
ref.module, | ||
ref.importedNames.filter(item => item !== "unused"), | ||
ref.weak, | ||
ref.order | ||
); | ||
} | ||
return ref; | ||
} | ||
); | ||
}); | ||
} | ||
] | ||
}; |
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 |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import { test } from "./module"; | ||
import { test, unused } from "./module"; | ||
|
||
it("should run the test", () => { | ||
expect(test()).toEqual({ | ||
used: "used", | ||
unused: undefined | ||
}) | ||
}); | ||
expect(unused).toEqual(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 |
---|---|---|
|
@@ -6,3 +6,5 @@ export function test() { | |
unused | ||
}; | ||
} | ||
|
||
export { unused } |