From 53bc931c372a58ca36e039f76b17850cce9b4f42 Mon Sep 17 00:00:00 2001 From: Giff Song Date: Sat, 28 May 2016 01:42:49 +0900 Subject: [PATCH] Update esprima --- package.json | 2 +- test/test.es6 | 27 +++++++++++++++++++++++++++ test/test.js | 22 ++++++++++++++++++---- 3 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 test/test.es6 diff --git a/package.json b/package.json index b3e8c4e..f7aaa5c 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "test": "test" }, "dependencies": { - "esprima": "^1.0.3", + "esprima": "^2.7.2", "uniq": "^1.0.0" }, "devDependencies": { diff --git a/test/test.es6 b/test/test.es6 new file mode 100644 index 0000000..3db30c4 --- /dev/null +++ b/test/test.es6 @@ -0,0 +1,27 @@ +"use strict" + +var parse = require("../index.js") + +require("tape")("es6 tests", function(t) { + + var parsed = parse((a, b, c) => { + a += b + c = Math.cos(b) + }) + + t.equals(parsed.args.length, 3) + + t.equals(parsed.args[0].lvalue, true) + t.equals(parsed.args[0].rvalue, true) + t.equals(parsed.args[0].count, 1) + + t.equals(parsed.args[1].lvalue, false) + t.equals(parsed.args[1].rvalue, true) + t.equals(parsed.args[1].count, 2) + + t.equals(parsed.args[2].lvalue, true) + t.equals(parsed.args[2].rvalue, false) + t.equals(parsed.args[2].count, 1) + + t.end() +}) diff --git a/test/test.js b/test/test.js index 47132d3..1436877 100644 --- a/test/test.js +++ b/test/test.js @@ -8,9 +8,9 @@ require("tape")("basic tests", function(t) { a += b c = Math.cos(b) }) - + t.equals(parsed.args.length, 3) - + t.equals(parsed.args[0].lvalue, true) t.equals(parsed.args[0].rvalue, true) t.equals(parsed.args[0].count, 1) @@ -18,10 +18,24 @@ require("tape")("basic tests", function(t) { t.equals(parsed.args[1].lvalue, false) t.equals(parsed.args[1].rvalue, true) t.equals(parsed.args[1].count, 2) - + t.equals(parsed.args[2].lvalue, true) t.equals(parsed.args[2].rvalue, false) t.equals(parsed.args[2].count, 1) t.end() -}) \ No newline at end of file +}) + + +function isArrowFunctionSupported() { + try { + new Function('() => {}'); + } catch (err) { + return false; + } + return true; +} + +if (isArrowFunctionSupported()) { + require('./test.es6'); +}