From 1c3fbf6cb009a5041b8e62981609c1834002abdc Mon Sep 17 00:00:00 2001 From: David Majda Date: Tue, 30 Aug 2016 16:37:05 +0200 Subject: [PATCH] Replace "... instanceof Array" with "Array.isArray(...)" See #441. --- lib/compiler/passes/generate-bytecode.js | 4 ++-- lib/compiler/passes/generate-js.js | 2 +- lib/parser.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/compiler/passes/generate-bytecode.js b/lib/compiler/passes/generate-bytecode.js index 7bf673e..b0c1c8f 100644 --- a/lib/compiler/passes/generate-bytecode.js +++ b/lib/compiler/passes/generate-bytecode.js @@ -575,7 +575,7 @@ function generateBytecode(ast) { regexp = '/^[' + (node.inverted ? '^' : '') + node.parts.map(function(part) { - return part instanceof Array + return Array.isArray(part) ? js.regexpClassEscape(part[0]) + '-' + js.regexpClassEscape(part[1]) @@ -592,7 +592,7 @@ function generateBytecode(ast) { parts = '[' + node.parts.map(function(part) { - return part instanceof Array + return Array.isArray(part) ? '["' + js.stringEscape(part[0]) + '", "' + js.stringEscape(part[1]) + '"]' : '"' + js.stringEscape(part) + '"'; }).join(', ') diff --git a/lib/compiler/passes/generate-js.js b/lib/compiler/passes/generate-js.js index 5f34c29..82d1ea4 100644 --- a/lib/compiler/passes/generate-js.js +++ b/lib/compiler/passes/generate-js.js @@ -790,7 +790,7 @@ function generateJS(ast, options) { ' i;', '', ' for (i = 0; i < expectation.parts.length; i++) {', - ' escapedParts += expectation.parts[i] instanceof Array', + ' escapedParts += Array.isArray(expectation.parts[i])', ' ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1])', ' : classEscape(expectation.parts[i]);', ' }', diff --git a/lib/parser.js b/lib/parser.js index 429dc84..5337aa7 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -40,7 +40,7 @@ peg$SyntaxError.buildMessage = function(expected, found) { i; for (i = 0; i < expectation.parts.length; i++) { - escapedParts += expectation.parts[i] instanceof Array + escapedParts += Array.isArray(expectation.parts[i]) ? classEscape(expectation.parts[i][0]) + "-" + classEscape(expectation.parts[i][1]) : classEscape(expectation.parts[i]); }