mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
[turbopack] Tree shake w/ bar['foo'] syntax for star imports (#96319)
This adds tree-shaking support for this syntax: ```javascript import * as ns from './lib'; ns["foo"] ``` Instead of expanding the usage to `All` for this one, we can restrict ourself to just "foo". See attached fixture.
This commit is contained in:
@@ -1336,7 +1336,12 @@ impl Visit for Analyzer<'_> {
|
||||
|
||||
if matches!(
|
||||
&node.prop,
|
||||
MemberProp::Ident(..) | MemberProp::PrivateName(..)
|
||||
MemberProp::Ident(..)
|
||||
| MemberProp::PrivateName(..)
|
||||
| MemberProp::Computed(ComputedPropName {
|
||||
expr: box Expr::Lit(Lit::Str(_)),
|
||||
..
|
||||
})
|
||||
) && let Expr::Ident(ident) = &*node.obj
|
||||
{
|
||||
// Intentionally skipping over visit_expr(node.obj) here so that it doesn't get added to
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
import * as lit from './lit.js'
|
||||
|
||||
// A string-literal key narrows to `foo`, so `unused` leaves the bundle.
|
||||
console.log(lit['foo'])
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export function foo() {}
|
||||
export function unused() {}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"scopeHoisting": false,
|
||||
"removeUnusedImports": true,
|
||||
"removeUnusedExports": true,
|
||||
"followReexports": true,
|
||||
"minifyType": {
|
||||
"Minify": {
|
||||
"mangle": "optimal-size"
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["output/1ece_tests_snapshot_remove-unused-imports_star-import-string-key_input_index_1fhdw9l.js",{otherChunks:["output/1jsg_tests_snapshot_remove-unused-imports_star-import-string-key_input_03-1fx5._.js"],runtimeModuleIds:["[project]/turbopack/crates/turbopack-tests/tests/snapshot/remove-unused-imports/star-import-string-key/input/index.js [test] (ecmascript)"]}]);
|
||||
|
||||
//# sourceMappingURL=1jsg_tests_snapshot_remove-unused-imports_star-import-string-key_input_index_1fhdw9l.js.map
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["output/1jsg_tests_snapshot_remove-unused-imports_star-import-string-key_input_03-1fx5._.js","[project]/turbopack/crates/turbopack-tests/tests/snapshot/remove-unused-imports/star-import-string-key/input/index.js [test] (ecmascript)",t=>{"use strict";console.log(t.i("[project]/turbopack/crates/turbopack-tests/tests/snapshot/remove-unused-imports/star-import-string-key/input/lit.js [test] (ecmascript)").foo),t.s([])},"[project]/turbopack/crates/turbopack-tests/tests/snapshot/remove-unused-imports/star-import-string-key/input/lit.js [test] (ecmascript)",t=>{"use strict";t.s(["foo",0,function(){}])}]);
|
||||
|
||||
//# sourceMappingURL=1jsg_tests_snapshot_remove-unused-imports_star-import-string-key_input_03-1fx5._.js.map
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":["turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/remove-unused-imports/star-import-string-key/input/index.js","turbopack:///[project]/turbopack/crates/turbopack-tests/tests/snapshot/remove-unused-imports/star-import-string-key/input/lit.js"],"sourcesContent":["import * as lit from './lit.js'\n\n// A string-literal key narrows to `foo`, so `unused` leaves the bundle.\nconsole.log(lit['foo'])\n","export function foo() {}\nexport function unused() {}\n"],"names":["console","log","foo","unused"],"mappings":"kTAGAA,QAAQC,GAAG,CAHX,AAGY,EAHZ,CAAA,CAAA,2IAGY,GAAU,mLCHf,SAASC,EAAO"}
|
||||
+1
@@ -0,0 +1 @@
|
||||
{"version":3,"sources":[],"names":[],"mappings":""}
|
||||
Reference in New Issue
Block a user