From 8bef320d58a6ae5c569ca9c1972f3143dc5adc79 Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Sat, 13 Dec 2014 00:47:13 +1100 Subject: [PATCH] change bind member operator to a hash - fixes #6 --- acorn.js | 41 ++++++-------- test/tests-6to5-playground.js | 100 ++-------------------------------- 2 files changed, 23 insertions(+), 118 deletions(-) diff --git a/acorn.js b/acorn.js index 439d85aebc..9da6054829 100644 --- a/acorn.js +++ b/acorn.js @@ -425,9 +425,9 @@ var _arrow = {type: "=>", beforeExpr: true}, _bquote = {type: "`"}, _dollarBraceL = {type: "${", beforeExpr: true}; var _ltSlash = {type: "= 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: diff --git a/test/tests-6to5-playground.js b/test/tests-6to5-playground.js index d8076b886c..9412804de7 100644 --- a/test/tests-6to5-playground.js +++ b/test/tests-6to5-playground.js @@ -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,