mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-19 03:44:23 -05:00
can't use indexing[] into strings cross-browser, use substr() instead.
This commit is contained in:
@@ -485,11 +485,11 @@
|
|||||||
code = arg.compile(o);
|
code = arg.compile(o);
|
||||||
if (!(arg instanceof SplatNode)) {
|
if (!(arg instanceof SplatNode)) {
|
||||||
prev = args[i - 1];
|
prev = args[i - 1];
|
||||||
if (i === 1 && prev[0] === '[' && prev[prev.length - 1] === ']') {
|
if (i === 1 && prev.substr(0, 1) === '[' && prev.substr(prev.length - 1, 1) === ']') {
|
||||||
args[i - 1] = '' + (prev.slice(0, prev.length - 1)) + ", " + code + "]";
|
args[i - 1] = '' + (prev.substr(0, prev.length - 2)) + ", " + code + "]";
|
||||||
continue;
|
continue;
|
||||||
} else if (i > 1 && prev[8] === '[' && prev[prev.length - 2] === ']') {
|
} else if (i > 1 && prev.substr(8, 1) === '[' && prev.substr(prev.length - 2, 1) === ']') {
|
||||||
args[i - 1] = '' + (prev.slice(0, prev.length - 2)) + ", " + code + "])";
|
args[i - 1] = '' + (prev.substr(0, prev.length - 3)) + ", " + code + "])";
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
code = "[" + code + "]";
|
code = "[" + code + "]";
|
||||||
|
|||||||
@@ -364,8 +364,8 @@ exports.CallNode: class CallNode extends BaseNode
|
|||||||
obj: temp
|
obj: temp
|
||||||
meth: "($temp = ${ @variable.source })${ @variable.last }"
|
meth: "($temp = ${ @variable.source })${ @variable.last }"
|
||||||
"$@prefix${meth}.apply($obj, ${ @compile_splat_arguments(o) })"
|
"$@prefix${meth}.apply($obj, ${ @compile_splat_arguments(o) })"
|
||||||
|
|
||||||
# Converts arbitrary number of arguments, mixed with splats, to
|
# Converts arbitrary number of arguments, mixed with splats, to
|
||||||
# a proper array to pass to an `.apply()` call
|
# a proper array to pass to an `.apply()` call
|
||||||
compile_splat_arguments: (o) ->
|
compile_splat_arguments: (o) ->
|
||||||
args: []
|
args: []
|
||||||
@@ -374,15 +374,15 @@ exports.CallNode: class CallNode extends BaseNode
|
|||||||
code: arg.compile o
|
code: arg.compile o
|
||||||
if not (arg instanceof SplatNode)
|
if not (arg instanceof SplatNode)
|
||||||
prev: args[i - 1]
|
prev: args[i - 1]
|
||||||
if i is 1 and prev[0] is '[' and prev[prev.length - 1] is ']'
|
if i is 1 and prev.substr(0, 1) is '[' and prev.substr(prev.length - 1, 1) is ']'
|
||||||
args[i - 1] = "${prev[0...prev.length - 1]}, $code]"
|
args[i - 1]: "${prev.substr(0, prev.length - 2)}, $code]"
|
||||||
continue
|
continue
|
||||||
else if i > 1 and prev[8] is '[' and prev[prev.length - 2] is ']'
|
else if i > 1 and prev.substr(8, 1) is '[' and prev.substr(prev.length - 2, 1) is ']'
|
||||||
args[i - 1] = "${prev[0...prev.length - 2]}, $code])"
|
args[i - 1]: "${prev.substr(0, prev.length - 3)}, $code])"
|
||||||
continue
|
continue
|
||||||
else
|
else
|
||||||
code: "[$code]"
|
code: "[$code]"
|
||||||
args.push(if i is 0 then code else ".concat($code)")
|
args.push(if i is 0 then code else ".concat($code)")
|
||||||
i += 1
|
i += 1
|
||||||
args.join('')
|
args.join('')
|
||||||
|
|
||||||
@@ -783,7 +783,7 @@ exports.SplatNode: class SplatNode extends BaseNode
|
|||||||
o.scope.assign(trailing.compile(o), "arguments[arguments.length - $@trailings.length + $i]")
|
o.scope.assign(trailing.compile(o), "arguments[arguments.length - $@trailings.length + $i]")
|
||||||
i += 1
|
i += 1
|
||||||
"$name = Array.prototype.slice.call(arguments, $@index, arguments.length - ${@trailings.length})"
|
"$name = Array.prototype.slice.call(arguments, $@index, arguments.length - ${@trailings.length})"
|
||||||
|
|
||||||
# A compiling a splat as a destructuring assignment means slicing arguments
|
# A compiling a splat as a destructuring assignment means slicing arguments
|
||||||
# from the right-hand-side's corresponding array.
|
# from the right-hand-side's corresponding array.
|
||||||
compile_value: (o, name, index) ->
|
compile_value: (o, name, index) ->
|
||||||
|
|||||||
Reference in New Issue
Block a user