From 839338b2704962098f7f0da786198219e0457734 Mon Sep 17 00:00:00 2001 From: Ingvar Stepanyan Date: Wed, 23 Jul 2014 21:07:57 +0300 Subject: [PATCH] Added octal and binary number support; added ES6 version checks. --- acorn.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/acorn.js b/acorn.js index c4fe618c6b..b866d7042f 100644 --- a/acorn.js +++ b/acorn.js @@ -692,10 +692,13 @@ case 58: ++tokPos; return finishToken(_colon); case 63: ++tokPos; return finishToken(_question); - // '0x' is a hexadecimal number. case 48: // '0' var next = input.charCodeAt(tokPos + 1); - if (next === 120 || next === 88) return readHexNumber(); + if (next === 120 || next === 88) return readRadixNumber(16); // '0x', '0X' - hex number + if (options.ecmaVersion >= 6) { + if (next === 111 || next === 79) return readRadixNumber(8); // '0o', '0O' - octal number + if (next === 98 || next === 66) return readRadixNumber(2); // '0b', '0B' - binary number + } // Anything else beginning with a digit is an integer, octal // number, or float. case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57: // 1-9 @@ -821,10 +824,10 @@ return total; } - function readHexNumber() { + function readRadixNumber(radix) { tokPos += 2; // 0x - var val = readInt(16); - if (val == null) raise(tokStart + 2, "Expected hexadecimal number"); + var val = readInt(radix); + if (val == null) raise(tokStart + 2, "Expected number in radix " + radix); if (isIdentifierStart(input.charCodeAt(tokPos))) raise(tokPos, "Identifier directly after number"); return finishToken(_num, val); } @@ -862,6 +865,7 @@ var ch = input.charCodeAt(tokPos), code; if (ch === 123) { + if (options.ecmaVersion < 6) unexpected(); ++tokPos; code = readHexChar(); ch = input.charCodeAt(tokPos++); @@ -1776,6 +1780,9 @@ else if (isStatement) unexpected(); else node.id = null; node.params = []; + if (options.ecmaVersion >= 6) { + node.defaults = []; + } node.rest = null; expect(_parenL); for (;;) {