Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Allow filters in 'in' and 'as'-expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jellevandenhooff committed Oct 26, 2013
1 parent e208882 commit 054025c
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions third_party/esprima/esprima.js
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,7 @@
// "|" Filter
// Filters "|" Filter

function parseFilters(expr) {
delegate.createTopLevel(expr);
function parseFilters() {
while (match('|')) {
lex();
parseFilter();
Expand All @@ -961,33 +960,37 @@
// LabelledExpressions
// AsExpression
// InExpression
// Expression
// Expression Filters
// FilterExpression

// AsExpression ::
// Expression as Identifier
// FilterExpression as Identifier

// InExpression ::
// Identifier, Identifier in Expression
// Identifier in Expression
// Identifier, Identifier in FilterExpression
// Identifier in FilterExpression

// FilterExpression ::
// Expression
// Expression Filters

function parseTopLevel() {
skipWhitespace();
peek();

var expr = parseExpression();
if (expr) {
if (lookahead.value === 'as') {
parseAsExpression(expr);
} else if (lookahead.value === ',' || lookahead.value == 'in' &&
if (lookahead.value === ',' || lookahead.value == 'in' &&
expr.type === Syntax.Identifier) {
parseInExpression(expr);
} else if (match('|')) {
parseFilters(expr);
} else if (expr.type === Syntax.Identifier && match(':')) {
} else if (expr.type === Syntax.Identifier && match(':')) {
parseLabelledExpressions(expr);
} else {
delegate.createTopLevel(expr);
parseFilters();
if (lookahead.value === 'as') {
parseAsExpression(expr);
} else {
delegate.createTopLevel(expr);
}
}
}

Expand All @@ -1007,7 +1010,7 @@
function parseLabelledExpressions(expr) {
// TODO(arv): Link to documentation.
console.warn('Labelled expressions are deprecated. ' +
'Use tokenList filter instead');
'Use tokenList filter instead');
var label = expr.name;
expect(':');

Expand All @@ -1026,7 +1029,7 @@
}

return null;
}
}

function parseAsExpression(expr) {
lex(); // as
Expand All @@ -1045,6 +1048,7 @@

lex(); // in
var expr = parseExpression();
parseFilters();
delegate.createInExpression(identifier.name, indexName, expr);
}

Expand Down

0 comments on commit 054025c

Please sign in to comment.