@@ -107,6 +107,9 @@ exports.Base = class Base
107
107
@ compileCommentFragments o, node, fragments
108
108
fragments
109
109
110
+ compileToFragmentsWithoutComments : (o , lvl ) ->
111
+ @ compileWithoutComments o, lvl, ' compileToFragments'
112
+
110
113
# Statements converted into expressions via closure-wrapping share a scope
111
114
# object with their parent closure, to preserve the expected lexical scope.
112
115
compileClosure : (o ) ->
@@ -2626,11 +2629,7 @@ exports.Code = class Code extends Base
2626
2629
# compilation, so that they get output the “real” time this param
2627
2630
# is compiled.
2628
2631
paramToAddToScope = if param .value ? then param else ref
2629
- if paramToAddToScope .name ? .comments
2630
- salvagedComments = paramToAddToScope .name .comments
2631
- delete paramToAddToScope .name .comments
2632
- o .scope .parameter fragmentsToText paramToAddToScope .compileToFragments o
2633
- paramToAddToScope .name .comments = salvagedComments if salvagedComments
2632
+ o .scope .parameter fragmentsToText paramToAddToScope .compileToFragmentsWithoutComments o
2634
2633
params .push ref
2635
2634
else
2636
2635
paramsAfterSplat .push param
@@ -2675,7 +2674,14 @@ exports.Code = class Code extends Base
2675
2674
for param, i in params
2676
2675
signature .push @ makeCode ' , ' if i isnt 0
2677
2676
signature .push @ makeCode ' ...' if haveSplatParam and i is params .length - 1
2677
+ # Compile this parameter, but if any generated variables get created
2678
+ # (e.g. `ref`), shift those into the parent scope since we can’t put a
2679
+ # `var` line inside a function parameter list.
2680
+ scopeVariablesCount = o .scope .variables .length
2678
2681
signature .push param .compileToFragments (o)...
2682
+ if scopeVariablesCount isnt o .scope .variables .length
2683
+ generatedVariables = o .scope .variables .splice scopeVariablesCount
2684
+ o .scope .parent .variables .push generatedVariables...
2679
2685
signature .push @ makeCode ' )'
2680
2686
# Block comments between `)` and `->`/`=>` get output between `)` and `{`.
2681
2687
if @funcGlyph ? .comments ?
@@ -2774,6 +2780,9 @@ exports.Param = class Param extends Base
2774
2780
compileToFragments : (o ) ->
2775
2781
@name .compileToFragments o, LEVEL_LIST
2776
2782
2783
+ compileToFragmentsWithoutComments : (o ) ->
2784
+ @name .compileToFragmentsWithoutComments o, LEVEL_LIST
2785
+
2777
2786
asReference : (o ) ->
2778
2787
return @reference if @reference
2779
2788
node = @name
0 commit comments