tagging more nodes as keys.

This commit is contained in:
Jeremy Ashkenas
2010-12-23 12:14:47 -08:00
parent 97a29f9c50
commit df8a6529ac
2 changed files with 10 additions and 6 deletions

View File

@@ -696,7 +696,7 @@
__extends(Access, Base);
function Access(name, tag) {
this.name = name;
this.name.accessed = true;
this.name.asKey = true;
this.proto = tag === 'proto' ? '.prototype' : '';
this.soak = tag === 'soak';
}
@@ -858,6 +858,9 @@
} else if (!(prop instanceof Assign) && !(prop instanceof Comment)) {
prop = new Assign(prop, prop, 'object');
}
if (prop instanceof Value) {
prop.variable.base.asKey = true;
}
_results.push(indent + prop.compile(o, LEVEL_TOP) + join);
}
return _results;
@@ -2122,10 +2125,10 @@
}
},
literalArgs: function(node) {
return node instanceof Literal && node.value === 'arguments' && !node.accessed;
return node instanceof Literal && node.value === 'arguments' && !node.asKey;
},
literalThis: function(node) {
return (node instanceof Literal && node.value === 'this' && !node.accessed) || (node instanceof Code && node.bound);
return (node instanceof Literal && node.value === 'this' && !node.asKey) || (node instanceof Code && node.bound);
}
};
unfoldSoak = function(o, parent, name) {

View File

@@ -557,7 +557,7 @@ exports.Extends = class Extends extends Base
# an access into the object's prototype.
exports.Access = class Access extends Base
constructor: (@name, tag) ->
@name.accessed = yes
@name.asKey = yes
@proto = if tag is 'proto' then '.prototype' else ''
@soak = tag is 'soak'
@@ -707,6 +707,7 @@ exports.Obj = class Obj extends Base
prop = new Assign prop.properties[0].name, prop, 'object'
else if prop not instanceof Assign and prop not instanceof Comment
prop = new Assign prop, prop, 'object'
prop.variable.base.asKey = yes if prop instanceof Value
indent + prop.compile(o, LEVEL_TOP) + join
props = props.join ''
obj = "{#{ props and '\n' + props + '\n' + @tab }}"
@@ -1673,9 +1674,9 @@ Closure =
if statement then Expressions.wrap [call] else call
literalArgs: (node) ->
node instanceof Literal and node.value is 'arguments' and not node.accessed
node instanceof Literal and node.value is 'arguments' and not node.asKey
literalThis: (node) ->
(node instanceof Literal and node.value is 'this' and not node.accessed) or
(node instanceof Literal and node.value is 'this' and not node.asKey) or
(node instanceof Code and node.bound)
# Unfold a node's child if soak, then tuck the node under created `If`