From afd07c917257eea0e47b65acb66f7d92dbdc7b34 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 16 Feb 2015 22:36:20 +0700 Subject: [PATCH] Use `leven` module for levenshtein distance https://github.com/sindresorhus/leven No point in bundling code like this. Leven is also the fastest one: https://github.com/sindresorhus/leven#benchmark --- lib/babel/helpers/levenshtein.js | 38 ------------------- .../validation/undeclared-variable-check.js | 2 +- package.json | 1 + 3 files changed, 2 insertions(+), 39 deletions(-) delete mode 100644 lib/babel/helpers/levenshtein.js diff --git a/lib/babel/helpers/levenshtein.js b/lib/babel/helpers/levenshtein.js deleted file mode 100644 index b861f451f7..0000000000 --- a/lib/babel/helpers/levenshtein.js +++ /dev/null @@ -1,38 +0,0 @@ -// taken from stackoverflow, it's crap i know. - -module.exports = function (a, b) { - if (a.length === 0) return b.length; - if (b.length === 0) return a.length; - - var matrix = []; - - // increment along the first column of each row - var i; - for (i = 0; i <= b.length; i++) { - matrix[i] = [i]; - } - - // increment each column in the first row - var j; - for (j = 0; j <= a.length; j++) { - matrix[0][j] = j; - } - - // Fill in the rest of the matrix - for (i = 1; i <= b.length; i++) { - for (j = 1; j <= a.length; j++) { - if (b.charAt(i - 1) == a.charAt(j - 1)) { - matrix[i][j] = matrix[i - 1][j - 1]; - } else { - matrix[i][j] = Math.min( - matrix[i - 1][j - 1] + 1, // substitution - Math.min( - matrix[i][j - 1] + 1, // insertion - matrix[i - 1][j] + 1) // deletion - ); - } - } - } - - return matrix[b.length][a.length]; -}; diff --git a/lib/babel/transformation/transformers/validation/undeclared-variable-check.js b/lib/babel/transformation/transformers/validation/undeclared-variable-check.js index 3bea68ad80..125f0151fa 100644 --- a/lib/babel/transformation/transformers/validation/undeclared-variable-check.js +++ b/lib/babel/transformation/transformers/validation/undeclared-variable-check.js @@ -1,6 +1,6 @@ "use strict"; -var levenshtein = require("../../../helpers/levenshtein"); +var levenshtein = require("leven"); var messages = require("../../../messages"); var t = require("../../../types"); diff --git a/package.json b/package.json index 9b8681650b..4ee0971871 100644 --- a/package.json +++ b/package.json @@ -51,6 +51,7 @@ "fs-readdir-recursive": "0.1.0", "globals": "^5.1.0", "js-tokenizer": "1.3.3", + "leven": "^1.0.1", "lodash": "3.0.0", "output-file-sync": "1.1.0", "private": "0.1.6",