forked from automenta/brackets-jsx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
73 lines (62 loc) · 2.37 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*jslint devel:true */
var define, brackets, CodeMirror;
define(function (require, exports, module) {
'use strict';
var LanguageManager = brackets.getModule("language/LanguageManager");
var CodeMirror = brackets.getModule("thirdparty/CodeMirror2/lib/codemirror");
CodeMirror.defineMode("jsx", function(config, parserConfig) {
var jsMode = CodeMirror.getMode(config, "javascript");
var xmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
function js(stream, state) {
if ((state.jsState.lastType == "operator"
|| state.jsState.lastType == "keyword c"
|| /^[\[{}\(,;:]$/.test(state.jsState.lastType))
&& stream.match(/^<[a-zA-Z]+/i, false)) {
state.token = xml;
return xmlMode.token(stream, state.localState);
state.localState = xmlMode.startState(jsMode.indent(state.jsState, ""));
state.localMode = xmlMode;
state.indented = stream.backUp(1);
return xml(stream, state);
}
return jsMode.token(stream, state.jsState);;
}
function xml(stream, state) {
if (!state.localState.context) {
state.token = js;
return jsMode.token(stream, state.jsState);
}
return xmlMode.token(stream, state.localState);;
}
return {
startState: function() {
var state = jsMode.startState();
var xmlState = xmlMode.startState();
return {token: js, localState: xmlState, jsState: state};
},
copyState: function(state) {
return {token: state.token,
localState: CodeMirror.copyState(xmlMode, state.localState),
jsState: CodeMirror.copyState(jsMode, state.jsState)};
},
token: function(stream, state) {
return state.token(stream, state);
},
indent: function(state, textAfter) {
if (state.token == js)
return jsMode.indent(state.jsState, textAfter);
else
return xmlMode.indent(state.localState, textAfter);
},
electricChars: "/{}:"
};
});
CodeMirror.defineMIME("text/jsx", "jsx");
LanguageManager.getLanguage("javascript").removeFileExtension('jsx');
LanguageManager.defineLanguage("jsx", {
"name": "JSX",
"mode": "jsx",
"fileExtensions": ["jsx", "react.js"],
"blockComment": ["/*", "*/"]
});
});