以下函数定义在编译时都会因为 {{ERROR: JSC_DUPLICATEPARAM. 解析错误。重复参数名称 ""}} 而引发错误,这是在 {{:advanced}} 编译模式下发生的。
`
(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 stronghold = 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诺基亚());
});
;})(_$1,map1610,map1610_$1,))
});})(map1610,map1610_$1,))
;
`
(注意其中一个 {{_}} 参数变成了 {{___$1}}。)
虽然我没有查看编译器的代码,但我的猜测是,编译器会在与另一个 {{}} 冲突时将 {{_}} 转换为 {{__$1}},并且它将 {{-}} 转换为 {{_}},但是当 {{ClojureScript}} 符号不同时,它没有注意到冲突。