mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
Merge branch 'master' of github.com:jashkenas/coffee-script
This commit is contained in:
@@ -48,7 +48,7 @@
|
||||
}
|
||||
forcedIdentifier = colon || (prev = last(this.tokens)) && (((_ref2 = prev[0]) === '.' || _ref2 === '?.' || _ref2 === '::') || !prev.spaced && prev[0] === '@');
|
||||
tag = 'IDENTIFIER';
|
||||
if (__indexOf.call(JS_KEYWORDS, id) >= 0 || !forcedIdentifier && __indexOf.call(COFFEE_KEYWORDS, id) >= 0) {
|
||||
if (!forcedIdentifier && (__indexOf.call(JS_KEYWORDS, id) >= 0 || __indexOf.call(COFFEE_KEYWORDS, id) >= 0)) {
|
||||
tag = id.toUpperCase();
|
||||
if (tag === 'WHEN' && (_ref3 = this.tag(), __indexOf.call(LINE_BREAK, _ref3) >= 0)) {
|
||||
tag = 'LEADING_WHEN';
|
||||
|
||||
@@ -575,7 +575,7 @@
|
||||
Call.prototype.newInstance = function() {
|
||||
var base;
|
||||
base = this.variable.base || this.variable;
|
||||
if (base instanceof Call) {
|
||||
if (base instanceof Call && !base.isNew) {
|
||||
base.newInstance();
|
||||
} else {
|
||||
this.isNew = true;
|
||||
@@ -1141,6 +1141,9 @@
|
||||
this.param = options && options.param;
|
||||
}
|
||||
Assign.prototype.children = ['variable', 'value'];
|
||||
Assign.prototype.isStatement = function(o) {
|
||||
return (o != null ? o.level : void 0) === LEVEL_TOP && __indexOf.call(this.context, "?") >= 0;
|
||||
};
|
||||
Assign.prototype.assigns = function(name) {
|
||||
return this[this.context === 'object' ? 'value' : 'variable'].assigns(name);
|
||||
};
|
||||
@@ -1596,7 +1599,7 @@
|
||||
return call;
|
||||
}
|
||||
if (op === 'new') {
|
||||
if (first instanceof Call && !first["do"]) {
|
||||
if (first instanceof Call && !first["do"] && !first.isNew) {
|
||||
return first.newInstance();
|
||||
}
|
||||
if (first instanceof Code && first.bound || first["do"]) {
|
||||
@@ -1822,7 +1825,7 @@
|
||||
var catchPart, errorPart;
|
||||
o.indent += TAB;
|
||||
errorPart = this.error ? " (" + (this.error.compile(o)) + ") " : ' ';
|
||||
catchPart = this.recovery ? " catch" + errorPart + "{\n" + (this.recovery.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" : !(this.ensure || this.recovery) ? ' catch (_e) {}' : void 0;
|
||||
catchPart = this.recovery ? (o.scope.add(this.error.value, 'param'), " catch" + errorPart + "{\n" + (this.recovery.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}") : !(this.ensure || this.recovery) ? ' catch (_e) {}' : void 0;
|
||||
return ("" + this.tab + "try {\n" + (this.attempt.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" + (catchPart || '')) + (this.ensure ? " finally {\n" + (this.ensure.compile(o, LEVEL_TOP)) + "\n" + this.tab + "}" : '');
|
||||
};
|
||||
return Try;
|
||||
|
||||
@@ -84,8 +84,7 @@ exports.Lexer = class Lexer
|
||||
not prev.spaced and prev[0] is '@')
|
||||
tag = 'IDENTIFIER'
|
||||
|
||||
if id in JS_KEYWORDS or
|
||||
not forcedIdentifier and id in COFFEE_KEYWORDS
|
||||
if not forcedIdentifier and (id in JS_KEYWORDS or id in COFFEE_KEYWORDS)
|
||||
tag = id.toUpperCase()
|
||||
if tag is 'WHEN' and @tag() in LINE_BREAK
|
||||
tag = 'LEADING_WHEN'
|
||||
|
||||
@@ -455,7 +455,7 @@ exports.Call = class Call extends Base
|
||||
# Tag this invocation as creating a new instance.
|
||||
newInstance: ->
|
||||
base = @variable.base or @variable
|
||||
if base instanceof Call
|
||||
if base instanceof Call and not base.isNew
|
||||
base.newInstance()
|
||||
else
|
||||
@isNew = true
|
||||
@@ -911,6 +911,9 @@ exports.Assign = class Assign extends Base
|
||||
|
||||
children: ['variable', 'value']
|
||||
|
||||
isStatement: (o) ->
|
||||
o?.level is LEVEL_TOP and "?" in @context
|
||||
|
||||
assigns: (name) ->
|
||||
@[if @context is 'object' then 'value' else 'variable'].assigns name
|
||||
|
||||
@@ -1236,7 +1239,7 @@ exports.Op = class Op extends Base
|
||||
call.do = yes
|
||||
return call
|
||||
if op is 'new'
|
||||
return first.newInstance() if first instanceof Call and not first.do
|
||||
return first.newInstance() if first instanceof Call and not first.do and not first.isNew
|
||||
first = new Parens first if first instanceof Code and first.bound or first.do
|
||||
@operator = CONVERSIONS[op] or op
|
||||
@first = first
|
||||
@@ -1402,6 +1405,7 @@ exports.Try = class Try extends Base
|
||||
o.indent += TAB
|
||||
errorPart = if @error then " (#{ @error.compile o }) " else ' '
|
||||
catchPart = if @recovery
|
||||
o.scope.add @error.value, 'param'
|
||||
" catch#{errorPart}{\n#{ @recovery.compile o, LEVEL_TOP }\n#{@tab}}"
|
||||
else unless @ensure or @recovery
|
||||
' catch (_e) {}'
|
||||
|
||||
@@ -487,7 +487,22 @@ test "implicit call against control structures", ->
|
||||
eq result, 'caught2'
|
||||
|
||||
|
||||
test "#1420: things like `(fn() ->)`; there are no words for this one",
|
||||
test "#1420: things like `(fn() ->)`; there are no words for this one", ->
|
||||
fn = -> (f) -> f()
|
||||
nonce = {}
|
||||
eq nonce, (fn() -> nonce)
|
||||
|
||||
test "#1416: don't omit one 'new' when compiling 'new new'", ->
|
||||
nonce = {}
|
||||
obj = new new -> -> {prop: nonce}
|
||||
eq obj.prop, nonce
|
||||
|
||||
test "#1416: don't omit one 'new' when compiling 'new new fn()()'", ->
|
||||
nonce = {}
|
||||
argNonceA = {}
|
||||
argNonceB = {}
|
||||
fn = (a) -> (b) -> {a, b, prop: nonce}
|
||||
obj = new new fn(argNonceA)(argNonceB)
|
||||
eq obj.prop, nonce
|
||||
eq obj.a, argNonceA
|
||||
eq obj.b, argNonceB
|
||||
|
||||
@@ -215,3 +215,9 @@ test "#1274: `{} = a()` compiles to `false` instead of `a()`", ->
|
||||
fn = -> a = true
|
||||
{} = fn()
|
||||
ok a
|
||||
|
||||
test "#1436: `for` etc. work as normal property names", ->
|
||||
obj = {}
|
||||
eq no, obj.hasOwnProperty 'for'
|
||||
obj.for = 'foo' of obj
|
||||
eq yes, obj.hasOwnProperty 'for'
|
||||
|
||||
@@ -26,3 +26,9 @@ test "siblings of variadic arguments shouldn't break out.", ->
|
||||
oops = (x,args...) ->
|
||||
oops(20, 1,2,3)
|
||||
eq x, 10
|
||||
|
||||
test "catch statements should introduce their argument to scope", ->
|
||||
try throw ''
|
||||
catch e
|
||||
do -> e = 5
|
||||
eq 5, e
|
||||
|
||||
Reference in New Issue
Block a user