1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

adding back '@static: value' syntax for classes

This commit is contained in:
Jeremy Ashkenas 2010-11-13 15:52:30 -05:00
parent 2aedbc2e42
commit cb6793f56b
7 changed files with 17 additions and 38 deletions

View file

@ -82,9 +82,9 @@
}), o('ObjAssignable :\
INDENT Expression OUTDENT', function() {
return new Assign(new Value($1), $4, 'object');
}), o('ThisProperty'), o('Comment')
}), o('Comment')
],
ObjAssignable: [o('Identifier'), o('AlphaNumeric'), o('Parenthetical')],
ObjAssignable: [o('Identifier'), o('AlphaNumeric'), o('Parenthetical'), o('ThisProperty')],
Return: [
o('RETURN Expression', function() {
return new Return($2);

View file

@ -851,7 +851,9 @@
base = assign.variable.base;
delete assign.context;
func = assign.value;
if (!assign.variable["this"]) {
assign.variable = new Value(lname, [new Accessor(base, 'proto')]);
}
if (func instanceof Code && func.bound) {
boundFuncs.push(base);
func.bound = false;

File diff suppressed because one or more lines are too long

View file

@ -146,7 +146,6 @@ grammar =
o 'ObjAssignable : Expression', -> new Assign new Value($1), $3, 'object'
o 'ObjAssignable :
INDENT Expression OUTDENT', -> new Assign new Value($1), $4, 'object'
o 'ThisProperty'
o 'Comment'
]
@ -154,6 +153,7 @@ grammar =
o 'Identifier'
o 'AlphaNumeric'
o 'Parenthetical'
o 'ThisProperty'
]
# A return statement from a function body.

View file

@ -246,7 +246,7 @@ exports.Expressions = class Expressions extends Base
# Wrap up the given nodes as an **Expressions**, unless it already happens
# to be one.
@wrap = (nodes) ->
@wrap: (nodes) ->
return nodes[0] if nodes.length is 1 and nodes[0] instanceof Expressions
new Expressions nodes
@ -695,6 +695,7 @@ exports.Class = class Class extends Base
base = assign.variable.base
delete assign.context
func = assign.value
unless assign.variable.this
assign.variable = new Value(lname, [new Accessor(base, 'proto')])
if func instanceof Code and func.bound
boundFuncs.push base
@ -976,7 +977,7 @@ exports.Splat = class Splat extends Base
# Utility function that converts arbitrary number of elements, mixed with
# splats, to a proper array.
@compileSplattedArray = (o, list, apply) ->
@compileSplattedArray: (o, list, apply) ->
index = -1
continue while (node = list[++index]) and node not instanceof Splat
return '' if index >= list.length

View file

@ -11,7 +11,7 @@
exports.Scope = class Scope
# The top-level **Scope** object.
@root = null
@root: null
# Initialize a scope with its parent, for lookups up the chain,
# as well as a reference to the **Expressions** node is belongs to, which is

View file

@ -3,7 +3,7 @@ class Base
func: (string) ->
"zero/#{string}"
@static = (string) ->
@static: (string) ->
"static/#{string}"
class FirstChild extends Base
@ -55,7 +55,7 @@ ok (new SubClass).prop is 'top-super-sub'
class OneClass
@new = 'new'
@new: 'new'
function: 'function'
(name) -> @name = name
@ -212,30 +212,6 @@ c.method 1, 2, 3, 4
ok c.args.join(' ') is '1 2 3 4'
# # Test `extended` callback.
# class Base
# @extended = (subclass) ->
# for key, value of @
# subclass[key] = value
#
# class Element extends Base
# @fromHTML = (html) ->
# node = "..."
# new @(node)
#
# (node) ->
# @node = node
#
# ok Element.extended is Base.extended
# ok Element.__super__ is Base.prototype
#
# class MyElement extends Element
#
# ok MyElement.extended is Base.extended
# ok MyElement.fromHTML is Element.fromHTML
# ok MyElement.__super__ is Element.prototype
# Test classes wrapped in decorators.
func = (klass) ->
klass::prop = 'value'
@ -309,7 +285,7 @@ eq a.c, undefined
# Light metaprogramming.
class Base
@attr = (name) ->
@attr: (name) ->
@::[name] = (val) ->
if arguments.length > 0
@["_#{name}"] = val