[Pkg-javascript-commits] [node-lexical-scope] 67/83: mine.js copied from @creationix's module, reformatted

Bastien Roucariès rouca at moszumanska.debian.org
Fri Dec 15 09:45:52 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-lexical-scope.

commit a093f1a607cc74f013d86ffbaa6f45f86fe27e23
Author: James Halliday <mail at substack.net>
Date:   Fri Feb 7 18:12:27 2014 -0800

    mine.js copied from @creationix's module, reformatted
---
 mine.js | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 119 insertions(+)

diff --git a/mine.js b/mine.js
new file mode 100644
index 0000000..2f27964
--- /dev/null
+++ b/mine.js
@@ -0,0 +1,119 @@
+module.exports = mine;
+
+function mine (js) {
+    js = String(js);
+    var names = [];
+    var state = 0;
+    var ident;
+    var quote;
+    var name;
+    var start;
+
+    var isIdent = /[a-z0-9_.]/i;
+    var isWhitespace = /[ \r\n\t]/;
+
+    function $start (char) {
+        if (char === "/") {
+            return $slash;
+        }
+        if (char === "'" || char === '"') {
+            quote = char;
+            return $string;
+        }
+        if (isIdent.test(char)) {
+            ident = char;
+            return $ident;
+        }
+        return $start;
+    }
+    
+    function $ident (char) {
+        if (isIdent.test(char)) {
+            ident += char;
+            return $ident;
+        }
+        if (char === "(" && ident === "require") {
+            ident = undefined;
+            return $call;
+        }
+        else if (isWhitespace.test(char)){
+            if (ident !== 'yield' && ident !== 'return'){
+                return $ident;
+            }
+        }
+        return $start(char);
+    }
+    
+    function $call (char) {
+        if (isWhitespace.test(char)) return $call;
+        if (char === "'" || char === '"') {
+            quote = char;
+            name = "";
+            start = i + 1;
+            return $name;
+        }
+        return $start(char);
+    }
+    
+    function $name (char) {
+        if (char === quote) {
+            return $close;
+        }
+        name += char;
+        return $name;
+    }
+    
+    function $close (char) {
+        if (isWhitespace.test(char)) return $close;
+        if (char === ")" || char === ',') {
+            names.push({
+                name: name,
+                offset: start
+            });
+        }
+        name = undefined;
+        return $start(char);
+    }
+    
+    function $string (char) {
+        if (char === "\\") {
+            return $escape;
+        }
+        if (char === quote) {
+            return $start;
+        }
+        return $string;
+    }
+    
+    function $escape (char) {
+        return $string;
+    }
+    
+    function $slash (char) {
+        if (char === "/") return $lineComment;
+        if (char === "*") return $multilineComment;
+        return $start(char);
+    }
+    
+    function $lineComment (char) {
+        if (char === "\r" || char === "\n") return $start;
+        return $lineComment;
+    }
+    
+    function $multilineComment (char) {
+        if (char === "*") return $multilineEnding;
+        return $multilineComment;
+    }
+    
+    function $multilineEnding (char) {
+        if (char === "/") return $start;
+        if (char === "*") return $multilineEnding;
+        return $multilineComment;
+    }
+    
+    var state = $start;
+    for (var i = 0, l = js.length; i < l; i++) {
+        state = state(js[i]);
+    }
+    return names;
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-lexical-scope.git



More information about the Pkg-javascript-commits mailing list