mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-04-11 03:00:13 -04:00
Issue #633. 'not instanceof'
This commit is contained in:
@@ -588,20 +588,22 @@
|
|||||||
return new OpNode($2, $1, $3);
|
return new OpNode($2, $1, $3);
|
||||||
}), o("Value COMPOUND_ASSIGN INDENT Expression OUTDENT", function() {
|
}), o("Value COMPOUND_ASSIGN INDENT Expression OUTDENT", function() {
|
||||||
return new OpNode($2, $1, $4);
|
return new OpNode($2, $1, $4);
|
||||||
}), o("Expression INSTANCEOF Expression", function() {
|
|
||||||
return new OpNode('instanceof', $1, $3);
|
|
||||||
}), o("Expression IN Expression", function() {
|
}), o("Expression IN Expression", function() {
|
||||||
return new InNode($1, $3);
|
return new InNode($1, $3);
|
||||||
}), o("Expression OF Expression", function() {
|
}), o("Expression OF Expression", function() {
|
||||||
return new OpNode('in', $1, $3);
|
return new OpNode('in', $1, $3);
|
||||||
|
}), o("Expression INSTANCEOF Expression", function() {
|
||||||
|
return new OpNode('instanceof', $1, $3);
|
||||||
}), o("Expression UNARY IN Expression", function() {
|
}), o("Expression UNARY IN Expression", function() {
|
||||||
return new OpNode($2, new InNode($1, $4));
|
return new OpNode($2, new InNode($1, $4));
|
||||||
}), o("Expression UNARY OF Expression", function() {
|
}), o("Expression UNARY OF Expression", function() {
|
||||||
return new OpNode($2, new ParentheticalNode(new OpNode('in', $1, $4)));
|
return new OpNode($2, new ParentheticalNode(new OpNode('in', $1, $4)));
|
||||||
|
}), o("Expression UNARY INSTANCEOF Expression", function() {
|
||||||
|
return new OpNode($2, new ParentheticalNode(new OpNode('instanceof', $1, $4)));
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
operators = [["right", '?'], ["nonassoc", '++', '--'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'COMPARE'], ["left", 'INSTANCEOF'], ["left", '==', '!='], ["left", 'LOGIC'], ["right", 'COMPOUND_ASSIGN'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'IN', 'OF', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'NEW', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
|
operators = [["right", '?', 'NEW'], ["nonassoc", '++', '--'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'COMPARE'], ["left", 'INSTANCEOF'], ["left", '==', '!='], ["left", 'LOGIC'], ["right", 'COMPOUND_ASSIGN'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", 'WHEN', 'LEADING_WHEN', 'IN', 'OF', 'BY', 'THROW'], ["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ["right", '=', ':', 'RETURN'], ["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']];
|
||||||
tokens = [];
|
tokens = [];
|
||||||
_a = grammar;
|
_a = grammar;
|
||||||
for (name in _a) {
|
for (name in _a) {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -197,7 +197,7 @@
|
|||||||
if (include(LINEBREAKS, token[0])) {
|
if (include(LINEBREAKS, token[0])) {
|
||||||
classLine = false;
|
classLine = false;
|
||||||
}
|
}
|
||||||
if (prev && (prev.spaced && include(IMPLICIT_FUNC, prev[0]) && include(IMPLICIT_CALL, token[0]) && !(token[0] === 'UNARY' && (('IN' === (_c = this.tag(i + 1)) || 'OF' === _c)))) || callObject) {
|
if (prev && (prev.spaced && include(IMPLICIT_FUNC, prev[0]) && include(IMPLICIT_CALL, token[0]) && !(token[0] === 'UNARY' && (('IN' === (_c = this.tag(i + 1)) || 'OF' === _c || 'INSTANCEOF' === _c)))) || callObject) {
|
||||||
this.tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
|
this.tokens.splice(i, 0, ['CALL_START', '(', token[2]]);
|
||||||
condition = function(token, i) {
|
condition = function(token, i) {
|
||||||
return (!token.generated && this.tokens[i - 1][0] !== ',' && include(IMPLICIT_END, token[0]) && !(token[0] === 'INDENT' && (include(IMPLICIT_BLOCK, this.tag(i - 1)) || this.tag(i - 2) === 'CLASS'))) || token[0] === 'PROPERTY_ACCESS' && this.tag(i - 1) === 'OUTDENT';
|
return (!token.generated && this.tokens[i - 1][0] !== ',' && include(IMPLICIT_END, token[0]) && !(token[0] === 'INDENT' && (include(IMPLICIT_BLOCK, this.tag(i - 1)) || this.tag(i - 2) === 'CLASS'))) || token[0] === 'PROPERTY_ACCESS' && this.tag(i - 1) === 'OUTDENT';
|
||||||
|
|||||||
@@ -552,11 +552,12 @@ grammar =
|
|||||||
o "Value COMPOUND_ASSIGN Expression", -> new OpNode $2, $1, $3
|
o "Value COMPOUND_ASSIGN Expression", -> new OpNode $2, $1, $3
|
||||||
o "Value COMPOUND_ASSIGN INDENT Expression OUTDENT", -> new OpNode $2, $1, $4
|
o "Value COMPOUND_ASSIGN INDENT Expression OUTDENT", -> new OpNode $2, $1, $4
|
||||||
|
|
||||||
o "Expression INSTANCEOF Expression", -> new OpNode 'instanceof', $1, $3
|
|
||||||
o "Expression IN Expression", -> new InNode $1, $3
|
o "Expression IN Expression", -> new InNode $1, $3
|
||||||
o "Expression OF Expression", -> new OpNode 'in', $1, $3
|
o "Expression OF Expression", -> new OpNode 'in', $1, $3
|
||||||
|
o "Expression INSTANCEOF Expression", -> new OpNode 'instanceof', $1, $3
|
||||||
o "Expression UNARY IN Expression", -> new OpNode $2, new InNode $1, $4
|
o "Expression UNARY IN Expression", -> new OpNode $2, new InNode $1, $4
|
||||||
o "Expression UNARY OF Expression", -> new OpNode $2, new ParentheticalNode new OpNode 'in', $1, $4
|
o "Expression UNARY OF Expression", -> new OpNode $2, new ParentheticalNode new OpNode 'in', $1, $4
|
||||||
|
o "Expression UNARY INSTANCEOF Expression", -> new OpNode $2, new ParentheticalNode new OpNode 'instanceof', $1, $4
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -572,7 +573,7 @@ grammar =
|
|||||||
#
|
#
|
||||||
# (2 + 3) * 4
|
# (2 + 3) * 4
|
||||||
operators = [
|
operators = [
|
||||||
["right", '?']
|
["right", '?', 'NEW']
|
||||||
["nonassoc", '++', '--']
|
["nonassoc", '++', '--']
|
||||||
["right", 'UNARY']
|
["right", 'UNARY']
|
||||||
["left", 'MATH']
|
["left", 'MATH']
|
||||||
@@ -586,7 +587,7 @@ operators = [
|
|||||||
["left", '.']
|
["left", '.']
|
||||||
["nonassoc", 'INDENT', 'OUTDENT']
|
["nonassoc", 'INDENT', 'OUTDENT']
|
||||||
["right", 'WHEN', 'LEADING_WHEN', 'IN', 'OF', 'BY', 'THROW']
|
["right", 'WHEN', 'LEADING_WHEN', 'IN', 'OF', 'BY', 'THROW']
|
||||||
["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'NEW', 'SUPER', 'CLASS', 'EXTENDS']
|
["right", 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS']
|
||||||
["right", '=', ':', 'RETURN']
|
["right", '=', ':', 'RETURN']
|
||||||
["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']
|
["right", '->', '=>', 'UNLESS', 'POST_IF', 'POST_UNLESS']
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ exports.BaseNode = class BaseNode
|
|||||||
del @options, 'chainRoot' unless this instanceof AccessorNode or this instanceof IndexNode
|
del @options, 'chainRoot' unless this instanceof AccessorNode or this instanceof IndexNode
|
||||||
top = if @topSensitive() then @options.top else del @options, 'top'
|
top = if @topSensitive() then @options.top else del @options, 'top'
|
||||||
closure = @isStatement(o) and not @isPureStatement() and not top and
|
closure = @isStatement(o) and not @isPureStatement() and not top and
|
||||||
not @options.asStatement and not (this instanceof CommentNode) and
|
not @options.asStatement and this not instanceof CommentNode and
|
||||||
not @containsPureStatement()
|
not @containsPureStatement()
|
||||||
if closure then @compileClosure(@options) else @compileNode(@options)
|
if closure then @compileClosure(@options) else @compileNode(@options)
|
||||||
|
|
||||||
@@ -644,7 +644,7 @@ exports.ObjectNode = class ObjectNode extends BaseNode
|
|||||||
compileNode: (o) ->
|
compileNode: (o) ->
|
||||||
top = del o, 'top'
|
top = del o, 'top'
|
||||||
o.indent = @idt 1
|
o.indent = @idt 1
|
||||||
nonComments = prop for prop in @properties when not (prop instanceof CommentNode)
|
nonComments = prop for prop in @properties when (prop not instanceof CommentNode)
|
||||||
lastNoncom = nonComments[nonComments.length - 1]
|
lastNoncom = nonComments[nonComments.length - 1]
|
||||||
props = for prop, i in @properties
|
props = for prop, i in @properties
|
||||||
join = ",\n"
|
join = ",\n"
|
||||||
@@ -1009,7 +1009,7 @@ exports.SplatNode = class SplatNode extends BaseNode
|
|||||||
for arg, i in list
|
for arg, i in list
|
||||||
code = arg.compile o
|
code = arg.compile o
|
||||||
prev = args[last = args.length - 1]
|
prev = args[last = args.length - 1]
|
||||||
if not (arg instanceof SplatNode)
|
if arg not instanceof SplatNode
|
||||||
if prev and starts(prev, '[') and ends(prev, ']')
|
if prev and starts(prev, '[') and ends(prev, ']')
|
||||||
args[last] = "#{prev.substr(0, prev.length - 1)}, #{code}]"
|
args[last] = "#{prev.substr(0, prev.length - 1)}, #{code}]"
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ exports.Rewriter = class Rewriter
|
|||||||
idx = 2 if callObject
|
idx = 2 if callObject
|
||||||
classLine = no if include(LINEBREAKS, token[0])
|
classLine = no if include(LINEBREAKS, token[0])
|
||||||
if prev and (prev.spaced and include(IMPLICIT_FUNC, prev[0]) and include(IMPLICIT_CALL, token[0]) and
|
if prev and (prev.spaced and include(IMPLICIT_FUNC, prev[0]) and include(IMPLICIT_CALL, token[0]) and
|
||||||
not (token[0] is 'UNARY' and (@tag(i + 1) in ['IN', 'OF']))) or callObject
|
not (token[0] is 'UNARY' and (@tag(i + 1) in ['IN', 'OF', 'INSTANCEOF']))) or callObject
|
||||||
@tokens.splice i, 0, ['CALL_START', '(', token[2]]
|
@tokens.splice i, 0, ['CALL_START', '(', token[2]]
|
||||||
condition = (token, i) ->
|
condition = (token, i) ->
|
||||||
(not token.generated and @tokens[i - 1][0] isnt ',' and include(IMPLICIT_END, token[0]) and
|
(not token.generated and @tokens[i - 1][0] isnt ',' and include(IMPLICIT_END, token[0]) and
|
||||||
|
|||||||
@@ -138,3 +138,8 @@ ok (a + b += c) is 6
|
|||||||
ok a is 1
|
ok a is 1
|
||||||
ok b is 5
|
ok b is 5
|
||||||
ok c is 3
|
ok c is 3
|
||||||
|
|
||||||
|
|
||||||
|
# Instanceof.
|
||||||
|
ok new String instanceof String
|
||||||
|
ok new Number not instanceof String
|
||||||
|
|||||||
Reference in New Issue
Block a user