change bind member operator to a hash - fixes #6
This commit is contained in:
parent
71bb9d6123
commit
8bef320d58
41
acorn.js
41
acorn.js
@ -425,9 +425,9 @@
|
||||
var _arrow = {type: "=>", beforeExpr: true}, _bquote = {type: "`"}, _dollarBraceL = {type: "${", beforeExpr: true};
|
||||
var _ltSlash = {type: "</"};
|
||||
var _ellipsis = {type: "...", prefix: true, beforeExpr: true};
|
||||
var _doubleColon = { type: "::", beforeExpr: true };
|
||||
var _paamayimNekudotayim = { type: "::", beforeExpr: true };
|
||||
var _at = { type: '@' };
|
||||
var _dotQuestion = { type: '.?' };
|
||||
var _hash = { type: '#' };
|
||||
|
||||
// Operators. These carry several kinds of properties to help the
|
||||
// parser use them properly (the presence of these properties is
|
||||
@ -475,7 +475,8 @@
|
||||
name: _name, eof: _eof, num: _num, regexp: _regexp, string: _string,
|
||||
arrow: _arrow, bquote: _bquote, dollarBraceL: _dollarBraceL, star: _star,
|
||||
assign: _assign, xjsName: _xjsName, xjsText: _xjsText,
|
||||
doubleColon: _doubleColon, exponent: _exponent, at: _at};
|
||||
paamayimNekudotayim: _paamayimNekudotayim, exponent: _exponent, at: _at,
|
||||
hash: _hash};
|
||||
for (var kw in keywordTypes) exports.tokTypes["_" + kw] = keywordTypes[kw];
|
||||
|
||||
// This is a trick taken from Esprima. It turns out that, on
|
||||
@ -883,13 +884,19 @@
|
||||
return finishToken(_at);
|
||||
}
|
||||
|
||||
case 35:
|
||||
if (options.playground) {
|
||||
++tokPos;
|
||||
return finishToken(_hash);
|
||||
}
|
||||
|
||||
case 58:
|
||||
++tokPos;
|
||||
if (options.ecmaVersion >= 7) {
|
||||
var next = input.charCodeAt(tokPos);
|
||||
if (next === 58) {
|
||||
++tokPos;
|
||||
return finishToken(_doubleColon);
|
||||
return finishToken(_paamayimNekudotayim);
|
||||
}
|
||||
}
|
||||
return finishToken(_colon);
|
||||
@ -2351,23 +2358,9 @@
|
||||
return finishNode(node, "AssignmentExpression");
|
||||
}
|
||||
node.test = expr;
|
||||
var consequent = node.consequent = parseExpression(true);
|
||||
if (consequent.type === "BindMemberExpression" && tokType !== _colon) {
|
||||
// this is a hack, revisit at a later date
|
||||
if (consequent.arguments.length) {
|
||||
node.alternate = {
|
||||
type: "CallExpression",
|
||||
arguments: consequent.arguments,
|
||||
callee: consequent.property
|
||||
};
|
||||
} else {
|
||||
node.alternate = consequent.property;
|
||||
}
|
||||
node.consequent = consequent.object;
|
||||
} else {
|
||||
expect(_colon);
|
||||
node.alternate = parseExpression(true, noIn);
|
||||
}
|
||||
node.consequent = parseExpression(true);
|
||||
expect(_colon);
|
||||
node.alternate = parseExpression(true, noIn);
|
||||
return finishNode(node, "ConditionalExpression");
|
||||
}
|
||||
return expr;
|
||||
@ -2447,7 +2440,7 @@
|
||||
}
|
||||
|
||||
function parseSubscripts(base, start, noCalls) {
|
||||
if (options.playground && eat(_colon)) {
|
||||
if (options.playground && eat(_hash)) {
|
||||
var node = startNodeAt(start);
|
||||
node.object = base;
|
||||
node.property = parseIdent(true);
|
||||
@ -2457,7 +2450,7 @@
|
||||
node.arguments = [];
|
||||
}
|
||||
return parseSubscripts(finishNode(node, "BindMemberExpression"), start, noCalls);
|
||||
} else if (eat(_doubleColon)) {
|
||||
} else if (eat(_paamayimNekudotayim)) {
|
||||
var node = startNodeAt(start);
|
||||
node.object = base;
|
||||
node.property = parseIdent(true);
|
||||
@ -2651,7 +2644,7 @@
|
||||
case _lt:
|
||||
return parseXJSElement();
|
||||
|
||||
case _colon:
|
||||
case _hash:
|
||||
return parseBindFunctionExpression();
|
||||
|
||||
default:
|
||||
|
||||
@ -245,95 +245,7 @@ test("obj.x ?= 2;", {
|
||||
|
||||
// Method binding
|
||||
|
||||
//- Make sure conditionals still work
|
||||
|
||||
test("y ? 1 : 2", {
|
||||
type: "Program",
|
||||
body: [
|
||||
{
|
||||
type: "ExpressionStatement",
|
||||
expression: {
|
||||
type: "ConditionalExpression",
|
||||
test: {
|
||||
type: "Identifier",
|
||||
name: "y",
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 0
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 1
|
||||
}
|
||||
}
|
||||
},
|
||||
consequent: {
|
||||
type: "Literal",
|
||||
value: 1,
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 4
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 5
|
||||
}
|
||||
}
|
||||
},
|
||||
alternate: {
|
||||
type: "Literal",
|
||||
value: 2,
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 8
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 9
|
||||
}
|
||||
}
|
||||
},
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 0
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 9
|
||||
}
|
||||
}
|
||||
},
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 0
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 9
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
loc: {
|
||||
start: {
|
||||
line: 1,
|
||||
column: 0
|
||||
},
|
||||
end: {
|
||||
line: 1,
|
||||
column: 9
|
||||
}
|
||||
}
|
||||
}, {
|
||||
playground: true
|
||||
});
|
||||
|
||||
test("var fn = obj:method", {
|
||||
test("var fn = obj#method", {
|
||||
type: "Program",
|
||||
start: 0,
|
||||
end: 19,
|
||||
@ -376,7 +288,7 @@ test("var fn = obj:method", {
|
||||
playground: true
|
||||
});
|
||||
|
||||
test("var fn = obj:method('foo', 5)", {
|
||||
test("var fn = obj#method('foo', 5)", {
|
||||
type: "Program",
|
||||
start: 0,
|
||||
end: 29,
|
||||
@ -434,7 +346,7 @@ test("var fn = obj:method('foo', 5)", {
|
||||
playground: true
|
||||
});
|
||||
|
||||
test("var fn = obj[foob]:method('foo', 5)", {
|
||||
test("var fn = obj[foob]#method('foo', 5)", {
|
||||
type: "Program",
|
||||
start: 0,
|
||||
end: 35,
|
||||
@ -504,7 +416,7 @@ test("var fn = obj[foob]:method('foo', 5)", {
|
||||
playground: true
|
||||
});
|
||||
|
||||
test("var fn = obj[foob].test:method('foo', 5)", {
|
||||
test("var fn = obj[foob].test#method('foo', 5)", {
|
||||
type: "Program",
|
||||
start: 0,
|
||||
end: 40,
|
||||
@ -589,7 +501,7 @@ test("var fn = obj[foob].test:method('foo', 5)", {
|
||||
});
|
||||
|
||||
|
||||
test("arr.map(:toUpperCase)", {
|
||||
test("arr.map(#toUpperCase)", {
|
||||
type: "Program",
|
||||
start: 0,
|
||||
end: 21,
|
||||
@ -637,7 +549,7 @@ test("arr.map(:toUpperCase)", {
|
||||
playground: true
|
||||
});
|
||||
|
||||
test("arr.map(:toFixed(2))", {
|
||||
test("arr.map(#toFixed(2))", {
|
||||
type: "Program",
|
||||
start: 0,
|
||||
end: 20,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user