You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// We track defined functions very carefully, so that we can remove them and
707
+
// the things they call, but other function scopes (like arrow functions and
708
+
// object methods) are trickier to track (object methods require knowing what
709
+
// object a function name is called on), so we do not track those. We consider
710
+
// all content inside them as top-level, which means it is used.
711
+
varspecialScopes=0;
712
+
702
713
fullWalk(ast,(node)=>{
703
714
if(isWasmImportsAssign(node)){
704
715
constassignedObject=getWasmImportsValue(node);
@@ -788,11 +799,14 @@ function emitDCEGraph(ast) {
788
799
emptyOut(node);
789
800
}
790
801
}elseif(node.type==='FunctionDeclaration'){
791
-
defuns.push(node);
792
-
constname=node.id.name;
793
-
nameToGraphName[name]=getGraphName(name,'defun');
794
-
emptyOut(node);// ignore this in the second pass; we scan defuns separately
802
+
if(!specialScopes){
803
+
defuns.push(node);
804
+
constname=node.id.name;
805
+
nameToGraphName[name]=getGraphName(name,'defun');
806
+
emptyOut(node);// ignore this in the second pass; we scan defuns separately
807
+
}
795
808
}elseif(node.type==='ArrowFunctionExpression'){
809
+
specialScopes--;
796
810
// Check if this is the minimal runtime exports function, which looks like
797
811
// (output) => { var wasmExports = output.instance.exports;
798
812
if(
@@ -857,9 +871,19 @@ function emitDCEGraph(ast) {
857
871
}
858
872
}
859
873
}
874
+
}elseif(node.type==='Property'&&node.method){
875
+
specialScopes--;
876
+
}
877
+
},(node)=>{
878
+
// Pre-walking logic. We note special scopes (see above).
879
+
if(node.type==='ArrowFunctionExpression'||
880
+
(node.type==='Property'&&node.method)){
881
+
specialScopes++;
860
882
}
861
883
});
862
-
// must find the info we need
884
+
// Scoping must balance out.
885
+
assert(specialScopes===0);
886
+
// We must have found the info we need.
863
887
assert(
864
888
foundWasmImportsAssign,
865
889
'could not find the assignment to "wasmImports". perhaps --pre-js or --post-js code moved it out of the global scope? (things like that should be done after emcc runs, as they do not need to be run through the optimizer which is the special thing about --pre-js/--post-js code)',
@@ -870,6 +894,7 @@ function emitDCEGraph(ast) {
870
894
saveAsmExport(exp[0],exp[1]);
871
895
}
872
896
}
897
+
873
898
// Second pass: everything used in the toplevel scope is rooted;
0 commit comments