以下函数定义会导致在编译时与 {{:advanced}} 编译一起出现以下错误:{{ERROR: JSC_DUPLICATEPARAM. 解析错误。重复的参数名称 ""}}:
`
(defn causes-duplicate-param [{_ :foo}]
(reify
Object
(a-function [-]
(fn [] "arbitrary function inside a-function body"))))
(defn causes-duplicate-param [{- :foo}]
(reify
Object
(a-function [_]
(fn [] "arbitrary function inside a-function body"))))
`
它们分别生成
`
duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1601.prototype.a_function = ((function (map1599,map1599$1,_){
return (function (){
var self = this;
var = this;
return ((function (,map1599,map1599$1,){
return (function (){
return "a-function body 内部的任意函数";
});
;})(,map1599,map1599_$1,))
});})(map1599,map1599$1,_))
;
duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1612.prototype.a_function = ((function (map1610,map1610$1,_){
return (function (){
var self = this;
var = this;
return ((function (,map1610,map1610$1,){
return (function (){
return "a-function body 内部的任意函数";
});
;})(,map1610,map1610_$1,))
});})(map1610,map1610$1,_))
;
`
(注意每个函数的第 5 行重复的 {{_}} 参数。
以下不会
`
(defn causes-duplicate-param [{- :foo}]
(reify
Object
(a-function [-]
(fn [] "arbitrary function inside a-function body"))))
(defn causes-duplicate-param [{_ :foo}]
(reify
Object
(a-function [_]
(fn [] "arbitrary function inside a-function body"))))
`
它们将生成
`
duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1601.prototype.a_function = ((function (map1599,map1599$1,_){
return (function (){
var self_ = this;
var $1 = this;
return ((function (_$1,map1599,map1599_$1,){
return (function (){
return "a-function body 内部的任意函数";
});
;})(_$1,map1599,map1599_$1,))
});})(map1599,map1599_$1,))
;
duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1612.prototype.a_function = ((function (map1610,map1610$1,_){
return (function (){
var self_ = this;
var $1 = this;
return ((function (_$1,map1610,map1610_$1,){
return (function (){
return "a-function body 内部的任意函数";
});
;})(_$1,map1610,map1610_$1,))
});})(map1610,map1610_$1,))
;
`
(注意其中一个 {{_}} 参数变成了 {{___$1}}。
尽管我没有查看编译器代码,但我的猜测是编译器将 {{_}} 转逃逸为 {{__$1}} 以避免与另一个 {{}冲突,并且它将 {{-}} 转换为 {{_}},但是在处理不同的 {{ClojureScript}} 符号时没有注意到冲突。