Removing/Reverting do ->

This commit is contained in:
Jeremy Ashkenas 2010-10-24 20:34:50 -04:00
parent 101a044219
commit 5b16d4790c
9 changed files with 205 additions and 247 deletions

View File

@ -57,7 +57,6 @@ task 'build:parser', 'rebuild the Jison parser (run build first)', ->
require 'jison'
parser = require('./lib/grammar').parser
js = parser.generate()
# TODO: Remove this when the Jison patch is released.
js = js.replace 'if (require.main === module)', "if (typeof module !== 'undefined' && require.main === module)"
fs.writeFile 'lib/parser.js', js
@ -99,8 +98,12 @@ task 'loc', 'count the lines of source code in the CoffeeScript compiler', ->
runTests = (CoffeeScript) ->
startTime = Date.now()
passedTests = failedTests = 0
for all name, func of require 'assert' then do (name, func) =>
global[name] = -> ++passedTests; func arguments...
wrap = (name, func) ->
global[name] = ->
passedTests += 1
func arguments...
for all name, func of require 'assert'
wrap name, func
global.eq = global.strictEqual
global.CoffeeScript = CoffeeScript
process.on 'exit', ->

View File

@ -38,7 +38,7 @@
return new Literal($1);
})
],
Expression: [o("Value"), o("Invocation"), o("Code"), o("Operation"), o("Assign"), o("If"), o("Try"), o("While"), o("For"), o("Switch"), o("Extends"), o("Class"), o("Existence"), o("Comment"), o("Do")],
Expression: [o("Value"), o("Invocation"), o("Code"), o("Operation"), o("Assign"), o("If"), o("Try"), o("While"), o("For"), o("Switch"), o("Extends"), o("Class"), o("Existence"), o("Comment")],
Block: [
o("INDENT Body OUTDENT", function() {
return $2;
@ -104,11 +104,6 @@
return new Existence($1);
})
],
Do: [
o("DO Code", function() {
return $2["do"]();
})
],
Code: [
o("PARAM_START ParamList PARAM_END FuncGlyph Block", function() {
return new Code($2, $5, $4);
@ -596,7 +591,7 @@
})
]
};
operators = [["left", 'CALL_START', 'CALL_END'], ["nonassoc", '++', '--'], ["left", '?'], ["right", 'UNARY'], ["left", 'MATH'], ["left", '+', '-'], ["left", 'SHIFT'], ["left", 'RELATION'], ["left", 'COMPARE'], ["left", 'LOGIC'], ["left", '.'], ["nonassoc", 'INDENT', 'OUTDENT'], ["right", '=', ':', 'COMPOUND_ASSIGN', 'RETURN'], ["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY', 'THROW', 'IF', 'UNLESS', 'POST_IF', 'POST_UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS']];
operators = [['left', 'CALL_START', 'CALL_END'], ['nonassoc', '++', '--'], ['left', '?'], ['right', 'UNARY'], ['left', 'MATH'], ['left', '+', '-'], ['left', 'SHIFT'], ['left', 'RELATION'], ['left', 'COMPARE'], ['left', 'LOGIC'], ['left', '.'], ['nonassoc', 'INDENT', 'OUTDENT'], ['right', '=', ':', 'COMPOUND_ASSIGN', 'RETURN'], ['right', 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY', 'THROW', 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS'], ['right', 'POST_IF', 'POST_UNLESS']];
tokens = [];
for (name in grammar) {
alternatives = grammar[name];

View File

@ -585,7 +585,7 @@
};
return Lexer;
})();
JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'if', 'else', 'switch', 'for', 'while', 'try', 'catch', 'finally', 'class', 'extends', 'super', 'do'];
JS_KEYWORDS = ['true', 'false', 'null', 'this', 'new', 'delete', 'typeof', 'in', 'instanceof', 'return', 'throw', 'break', 'continue', 'debugger', 'if', 'else', 'switch', 'for', 'while', 'try', 'catch', 'finally', 'class', 'extends', 'super'];
COFFEE_KEYWORDS = ['then', 'unless', 'until', 'loop', 'of', 'by', 'when'];
for (op in COFFEE_ALIASES = {
and: '&&',
@ -600,7 +600,7 @@
}) {
COFFEE_KEYWORDS.push(op);
}
RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice'];
RESERVED = ['case', 'default', 'function', 'var', 'void', 'with', 'do', 'const', 'let', 'enum', 'export', 'import', 'native', '__hasProp', '__extends', '__slice'];
JS_FORBIDDEN = JS_KEYWORDS.concat(RESERVED);
IDENTIFIER = /^([$A-Za-z_][$\w]*)([^\n\S]*:(?!:))?/;
NUMBER = /^0x[\da-f]+|^(?:\d+(\.\d+)?|\.\d+)(?:e[+-]?\d+)?/i;

View File

@ -1087,14 +1087,6 @@
Code.prototype.traverseChildren = function(crossScope, func) {
return crossScope ? Code.__super__.traverseChildren.call(this, crossScope, func) : undefined;
};
Code.prototype["do"] = function() {
if (this.bound) {
this.bound = false;
return new Call(new Value(this, [new Accessor(new Literal('call'))]), [new Literal('this')].concat(this.params));
} else {
return new Call(this);
}
};
return Code;
})();
exports.Param = (function() {

File diff suppressed because one or more lines are too long

View File

@ -103,7 +103,6 @@ grammar =
o "Class"
o "Existence"
o "Comment"
o "Do"
]
# An indented block of expressions. Note that the [Rewriter](rewriter.html)
@ -175,10 +174,6 @@ grammar =
o "Expression ?", -> new Existence $1
]
Do: [
o "DO Code", -> $2.do()
]
# The **Code** node is the function literal. It's defined by an indented block
# of **Expressions** preceded by a function arrow, with an optional parameter
# list.
@ -557,22 +552,23 @@ grammar =
#
# (2 + 3) * 4
operators = [
["left", 'CALL_START', 'CALL_END']
["nonassoc", '++', '--']
["left", '?']
["right", 'UNARY']
["left", 'MATH']
["left", '+', '-']
["left", 'SHIFT']
["left", 'RELATION']
["left", 'COMPARE']
["left", 'LOGIC']
["left", '.']
["nonassoc", 'INDENT', 'OUTDENT']
["right", '=', ':', 'COMPOUND_ASSIGN', 'RETURN']
["right", 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY',
'THROW', 'IF', 'UNLESS', 'POST_IF', 'POST_UNLESS', 'ELSE',
'FOR', 'WHILE', 'UNTIL', 'LOOP', 'SUPER', 'CLASS', 'EXTENDS']
['left', 'CALL_START', 'CALL_END']
['nonassoc', '++', '--']
['left', '?']
['right', 'UNARY']
['left', 'MATH']
['left', '+', '-']
['left', 'SHIFT']
['left', 'RELATION']
['left', 'COMPARE']
['left', 'LOGIC']
['left', '.']
['nonassoc', 'INDENT', 'OUTDENT']
['right', '=', ':', 'COMPOUND_ASSIGN', 'RETURN']
['right', 'WHEN', 'LEADING_WHEN', 'FORIN', 'FOROF', 'FROM', 'TO', 'BY',
'THROW', 'IF', 'UNLESS', 'ELSE', 'FOR', 'WHILE', 'UNTIL', 'LOOP',
'SUPER', 'CLASS', 'EXTENDS']
['right', 'POST_IF', 'POST_UNLESS']
]
# Wrapping Up

View File

@ -515,7 +515,7 @@ JS_KEYWORDS = [
'new', 'delete', 'typeof', 'in', 'instanceof'
'return', 'throw', 'break', 'continue', 'debugger'
'if', 'else', 'switch', 'for', 'while', 'try', 'catch', 'finally'
'class', 'extends', 'super', 'do'
'class', 'extends', 'super'
]
# CoffeeScript-only keywords.
@ -535,7 +535,7 @@ COFFEE_KEYWORDS.push op for all op of COFFEE_ALIASES =
# used by CoffeeScript internally. We throw an error when these are encountered,
# to avoid having a JavaScript error at runtime.
RESERVED = [
'case', 'default', 'function', 'var', 'void', 'with'
'case', 'default', 'function', 'var', 'void', 'with', 'do'
'const', 'let', 'enum', 'export', 'import', 'native'
'__hasProp', '__extends', '__slice'
]

View File

@ -897,15 +897,6 @@ exports.Code = class Code extends Base
# unless `crossScope` is `true`.
traverseChildren: (crossScope, func) -> super(crossScope, func) if crossScope
# Automatically calls the defined function.
do: ->
if @bound
@bound = no
new Call new Value(this, [new Accessor new Literal 'call']),
[new Literal 'this'].concat this.params
else
new Call this
#### Param
# A parameter in a function definition. Beyond a typical Javascript parameter,

View File

@ -345,18 +345,3 @@ eq ok, new ->
ok
### Should `return` implicitly ###
### even with trailing comments. ###
# Rescoping with the `do` keyword.
v1 = 1
v2 = 2
do (v1) ->
v1 = 3
v2 = 4
ok v1 is 1
ok v2 is 4
cxt = {}
val = null
(-> do => val = this).call cxt
ok val is cxt