以下函数定义在编译时分别导致 {{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 (mapstrong1599,map1599$1,_){
return (function (){
var selfstrong = this;
var strong = this;
return ((function (,mapstrong1599,map1599$1,{
return (function (){
return "function within a-function body";
});
;})(,mapstrong1599,map1599_,$1)
});})(mapstrong1599,map1599$1,_))
;
duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1612.prototype.a_function = ((function (mapstrong1610,map1610$1,_){
return (function (){
var selfstrong = this;
var strong = this;
return ((function (,mapstrong1610,map1610$1,{
return (function (){
return "function within a-function body";
});
;})(,mapstrong1610,map1610_,$1)
});})(mapstrong1610,map1610$1,_))
;
`
(注意每个的第五行上的重复 {{}} 参数.)
以下则不会:
`
(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 (mapstrong1599,map1599$1,_){
return (function (){
var selfstrong_ = this;
var strong$1 = this;
return ((function (strong$_,$1,mapstrong1599,map1599_,$1){
return (function (){
return "function within a-function body";
});
;})(strong$_,$1,mapstrong1599,map1599_,$1))
});})(mapstrong1599,map1599_,$1))
;
duplicate_param_name_demo.core.t_duplicate_param_name_demo$core1612.prototype.a_function = ((function (mapstrong1610,map1610$1,_){
return (function (){
var selfstrong_ = this;
var strong$1 = this;
return ((function (strong$_,$1,mapstrong1610,map1610_,$1){
return (function (){
return "function within a-function body";
});
;})(strong$_,$1,mapstrong1610,map1610_,$1))
});})(mapstrong1610,map1610_,$1))
;
`
(注意其中一个 {{}} 参数变成了 {{$1}}.)
我的猜测,虽然我没有查看编译器代码,但编译器在参数冲突时会将 {{}} 转换为 {{__$1}},并将 {{-}} 转换为 {{}},但是当 ClojureScript 符号不同时,它没有注意到冲突。