public void VisitNode(JSFunctionExpression fn) { VisitChildren(fn); foreach (var p in fn.Parameters) { if (!p.IsReference) continue; var vrat = new VariableReferenceAccessTransformer(JSIL, p); vrat.Visit(fn); } /* if (!fn.Method.Method.IsStatic) { var vrat = new VariableReferenceAccessTransformer(JSIL, Variables["this"]); vrat.Visit(fn); } */ foreach (var r in ReferencesToTransform) { var cr = GetConstructedReference(r); if (cr == null) { // We have already done the variable transform for this variable in the past. continue; } // For 'ref this', we need to replace each individual expression, because we can't // rename the this-variable. if (cr.IsThis) { var refThis = JSIL.NewReference(Variables["this"]); fn.ReplaceChildRecursive(r, refThis); continue; } var parameter = (from p in fn.Parameters where p.Identifier == cr.Identifier select p).FirstOrDefault(); if (parameter != null) { TransformParameterIntoReference(parameter, fn.Body); } else { var declaration = (from kvp in Declarations let vds = kvp.Key from ivd in vds.Declarations.Select((vd, i) => new { vd = vd, i = i }) where MatchesConstructedReference(ivd.vd.Left, cr) select new { vds = vds, vd = ivd.vd, i = ivd.i, block = kvp.Value }).FirstOrDefault(); if (declaration == null) throw new InvalidOperationException(String.Format("Could not locate declaration for {0}", cr)); TransformVariableIntoReference( (JSVariable)declaration.vd.Left, declaration.vds, declaration.i, declaration.block ); } var vrat = new VariableReferenceAccessTransformer(JSIL, cr); vrat.Visit(fn); } }
public void VisitNode(JSFunctionExpression fn) { VisitChildren(fn); foreach (var p in fn.Parameters) { if (!p.IsReference) { continue; } var vrat = new VariableReferenceAccessTransformer(JSIL, p); vrat.Visit(fn); } /* * if (!fn.Method.Method.IsStatic) { * var vrat = new VariableReferenceAccessTransformer(JSIL, Variables["this"]); * vrat.Visit(fn); * } */ foreach (var r in ReferencesToTransform) { var cr = GetConstructedReference(r); if (cr == null) { // We have already done the variable transform for this variable in the past. continue; } // For 'ref this', we need to replace each individual expression, because we can't // rename the this-variable. if (cr.IsThis) { var refThis = JSIL.NewReference(Variables["this"]); fn.ReplaceChildRecursive(r, refThis); continue; } var parameter = (from p in fn.Parameters where p.Identifier == cr.Identifier select p).FirstOrDefault(); if (parameter != null) { TransformParameterIntoReference(parameter, fn.Body); } else { var declaration = (from kvp in Declarations let vds = kvp.Key from ivd in vds.Declarations.Select((vd, i) => new { vd = vd, i = i }) where MatchesConstructedReference(ivd.vd.Left, cr) select new { vds = vds, vd = ivd.vd, i = ivd.i, block = kvp.Value }).FirstOrDefault(); if (declaration == null) { throw new InvalidOperationException(String.Format("Could not locate declaration for {0}", cr)); } TransformVariableIntoReference( (JSVariable)declaration.vd.Left, declaration.vds, declaration.i, declaration.block ); } var vrat = new VariableReferenceAccessTransformer(JSIL, cr); vrat.Visit(fn); } }