mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-05-03 03:00:14 -04:00
allowing Klass::['dynamic-property'] syntax. Issue #392
This commit is contained in:
@@ -264,8 +264,12 @@
|
||||
Index: [
|
||||
o("INDEX_START Expression INDEX_END", function() {
|
||||
return new IndexNode($2);
|
||||
}), o("SOAKED_INDEX_START Expression SOAKED_INDEX_END", function() {
|
||||
return new IndexNode($2, 'soak');
|
||||
}), o("INDEX_SOAK Index", function() {
|
||||
$2.soak_node = true;
|
||||
return $2;
|
||||
}), o("INDEX_PROTO Index", function() {
|
||||
$2.proto = true;
|
||||
return $2;
|
||||
})
|
||||
],
|
||||
// In CoffeeScript, an object literal is simply a list of assignments.
|
||||
|
||||
18
lib/lexer.js
18
lib/lexer.js
@@ -383,19 +383,17 @@
|
||||
}
|
||||
} else if (value === ';') {
|
||||
tag = 'TERMINATOR';
|
||||
} else if (value === '[' && this.tag() === '?' && !prev_spaced) {
|
||||
tag = 'SOAKED_INDEX_START';
|
||||
this.soaked_index = true;
|
||||
this.tokens.pop();
|
||||
} else if (value === ']' && this.soaked_index) {
|
||||
tag = 'SOAKED_INDEX_END';
|
||||
this.soaked_index = false;
|
||||
} else if (include(CALLABLE, this.tag()) && !prev_spaced) {
|
||||
if (value === '(') {
|
||||
tag = 'CALL_START';
|
||||
}
|
||||
if (value === '[') {
|
||||
} else if (value === '[') {
|
||||
tag = 'INDEX_START';
|
||||
if (this.tag() === '?') {
|
||||
this.tag(1, 'INDEX_SOAK');
|
||||
}
|
||||
if (this.tag() === '::') {
|
||||
this.tag(1, 'INDEX_PROTO');
|
||||
}
|
||||
}
|
||||
}
|
||||
this.i += value.length;
|
||||
@@ -692,7 +690,7 @@
|
||||
// Tokens which could legitimately be invoked or indexed. A opening
|
||||
// parentheses or bracket following these tokens will be recorded as the start
|
||||
// of a function invocation or indexing operation.
|
||||
CALLABLE = ['IDENTIFIER', 'SUPER', ')', ']', '}', 'STRING', '@', 'THIS'];
|
||||
CALLABLE = ['IDENTIFIER', 'SUPER', ')', ']', '}', 'STRING', '@', 'THIS', '?', '::'];
|
||||
// Tokens that, when immediately preceding a `WHEN`, indicate that the `WHEN`
|
||||
// occurs at the start of a line. We disambiguate these from trailing whens to
|
||||
// avoid an ambiguity in the grammar.
|
||||
|
||||
@@ -700,19 +700,19 @@
|
||||
//### IndexNode
|
||||
// A `[ ... ]` indexed accessor into an array or object.
|
||||
exports.IndexNode = (function() {
|
||||
IndexNode = function(index, tag) {
|
||||
IndexNode = function(index) {
|
||||
this.index = index;
|
||||
this.soak_node = tag === 'soak';
|
||||
return this;
|
||||
};
|
||||
__extends(IndexNode, BaseNode);
|
||||
IndexNode.prototype.type = 'IndexNode';
|
||||
IndexNode.prototype.children = ['index'];
|
||||
IndexNode.prototype.compile_node = function(o) {
|
||||
var idx;
|
||||
var idx, prefix;
|
||||
o.chain_root.wrapped = o.chain_root.wrapped || this.soak_node;
|
||||
idx = this.index.compile(o);
|
||||
return "[" + idx + "]";
|
||||
prefix = this.proto ? '.prototype' : '';
|
||||
return "" + prefix + "[" + idx + "]";
|
||||
};
|
||||
return IndexNode;
|
||||
})();
|
||||
|
||||
274
lib/parser.js
274
lib/parser.js
File diff suppressed because one or more lines are too long
@@ -350,7 +350,7 @@
|
||||
// Constants
|
||||
// ---------
|
||||
// List of the token pairs that must be balanced.
|
||||
BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], ['INDENT', 'OUTDENT'], ['PARAM_START', 'PARAM_END'], ['CALL_START', 'CALL_END'], ['INDEX_START', 'INDEX_END'], ['SOAKED_INDEX_START', 'SOAKED_INDEX_END']];
|
||||
BALANCED_PAIRS = [['(', ')'], ['[', ']'], ['{', '}'], ['INDENT', 'OUTDENT'], ['PARAM_START', 'PARAM_END'], ['CALL_START', 'CALL_END'], ['INDEX_START', 'INDEX_END']];
|
||||
// The inverse mappings of `BALANCED_PAIRS` we're trying to fix up, so we can
|
||||
// look things up from either end.
|
||||
INVERSES = {};
|
||||
|
||||
Reference in New Issue
Block a user