Skip to content

Commit

Permalink
track global variables alongside locals in the parser state
Browse files Browse the repository at this point in the history
  • Loading branch information
iwehrman authored and marijnh committed Dec 13, 2012
1 parent 2c6294f commit 1bcc976
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions mode/javascript/javascript.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,19 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
return true;
}
function register(varname) {
function inList(list) {
for (var v = list; v; v = v.next)
if (v.name == varname) return true;
return false;
}
var state = cx.state;
if (state.context) {
cx.marked = "def";
for (var v = state.localVars; v; v = v.next)
if (v.name == varname) return;
if (inList(state.localVars)) return;
state.localVars = {name: varname, next: state.localVars};
} else {
if (inList(state.globalVars)) return;
state.globalVars = {name: varname, next: state.globalVars};
}
}

Expand Down Expand Up @@ -364,6 +371,7 @@ CodeMirror.defineMode("javascript", function(config, parserConfig) {
cc: [],
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
localVars: parserConfig.localVars,
globalVars: parserConfig.globalVars,
context: parserConfig.localVars && {vars: parserConfig.localVars},
indented: 0
};
Expand Down

0 comments on commit 1bcc976

Please sign in to comment.