coffeescript解析器告诉我这不行:
{ one: 1,
two: 2
}
但这是:
{
one: 1,
two: 2
}
这是一个简单的语法规则,还是此示例中其他内容的副作用?
答案 0 :(得分:0)
Coffee-script是对空白区域敏感的,并且具有可选的令牌以增强可读性。
在没有查看解析器的内部结构的情况下,我的理解是咖啡脚本在解析阶段剥离了可选部分 - 比如......
# original...
x = { one: 1,
two: 2
}
# ignore curlies, leaving...
x = one: 1,
two: 2
# remove comma leaving incorrectly indented code...
x = one: 1
two: 2
通过写入偏移的白色空间敏感样式......
# new style
x = {
one: 1,
two: 2
}
# remove the curlies
x =
one: 1,
two: 2
# remove the comma, and nice clear whitespace sensitive definition remains...
x =
one: 1
two: 2