Skip to content

Commit

Permalink
fixes #2932 variable cast in typescript mode is highlighted as jsx
Browse files Browse the repository at this point in the history
  • Loading branch information
nightwing committed Apr 7, 2016
1 parent edd676b commit b4e4437
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 7 deletions.
2 changes: 1 addition & 1 deletion demo/kitchen-sink/docs/typescript.ts
Expand Up @@ -11,7 +11,7 @@ class Greeter {
var greeter = new Greeter("world");

var button = document.createElement('button')
button.innerText = "Say Hello"
button.innerText = <string>"Say Hello";
button.onclick = function() {
alert(greeter.greet())
}
Expand Down
39 changes: 39 additions & 0 deletions lib/ace/mode/_test/text_ejs.txt
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<title>Cloud9 Rocks!</title>
</head>
<body>

<table class="table">
<tr>
<th>Name</th>
<th>Size</th>
</tr>
<% if (!isRoot) { %>
<tr>
<td><a href="..">..</a></td>
<td></td></td>
</tr>
<% } %>
<% entries.forEach(function(entry) { %>
<tr>
<td>
<span class="glyphicon <%= entry.mime == 'directory' ? 'folder': 'file'%>"></span>
<a href="<%= entry.name %>"><%= entry.name %></a>
</td>
<td><%= entry.size %></td>
</tr>
<% }) %>
</table>
<input placeholder="Username or email"
<%
if (typeof window != 'undefined') {
%>
value="<%=window%>"
<%
}
%>
/>
</body>
</html>
30 changes: 30 additions & 0 deletions lib/ace/mode/_test/text_rust.txt
@@ -0,0 +1,30 @@
use core::rand::RngUtil;

fn main() {
for ["Alice", "Bob", "Carol"].each |&name| {
do spawn {
let v = rand::Rng().shuffle([1, 2, 3]);
for v.each |&num| {
print(fmt!("%s says: '%d'\n", name, num + 1))
}
}
}
}

/* nested /*
comments */ */

fn map<T, U>(vector: &[T], function: &fn(v: &T) -> U) -> ~[U] {
let mut accumulator = ~[];
for vec::each(vector) |element| {
accumulator.push(function(element));
}
return accumulator;
}


// numbers
14E-111_f64; 45isize 0x1i32 0o777u32 0b01 14f32 1_2.78f32 1_2.3E+7f32

// not numbers
14._E-111_f64; 0xi32 0b777u
30 changes: 30 additions & 0 deletions lib/ace/mode/_test/tokens_tsx.json
@@ -0,0 +1,30 @@
[[
["jsx",1],
["storage.type","var"],
["text"," "],
["identifier","mode"],
["text"," "],
["keyword.operator","="],
["text"," "],
["meta.tag.punctuation.tag-open.xml","<"],
["meta.tag.tag-name.xml","div"],
["meta.tag.punctuation.tag-close.xml",">"],
["string"," "]
],[
["jsx",1],
["string"," Typescript + "],
["meta.tag.punctuation.tag-open.xml","<"],
["meta.tag.tag-name.xml","b"],
["meta.tag.punctuation.tag-close.xml",">"],
["string"," JSX "],
["meta.tag.punctuation.end-tag-open.xml","</"],
["meta.tag.tag-name.xml","b"],
["meta.tag.punctuation.tag-close.xml",">"],
["string"," "]
],[
"start",
["meta.tag.punctuation.end-tag-open.xml","</"],
["meta.tag.tag-name.xml","div"],
["meta.tag.punctuation.tag-close.xml",">"],
["punctuation.operator",";"]
]]
8 changes: 6 additions & 2 deletions lib/ace/mode/_test/tokens_typescript.json
Expand Up @@ -100,14 +100,18 @@
["string","'button'"],
["paren.rparen",")"]
],[
"no_regex",
"start",
["identifier","button"],
["punctuation.operator","."],
["identifier","innerText"],
["text"," "],
["keyword.operator","="],
["text"," "],
["string","\"Say Hello\""]
["keyword.operator","<"],
["storage.type.variable.ts","string"],
["keyword.operator",">"],
["string","\"Say Hello\""],
["punctuation.operator",";"]
],[
"start",
["storage.type","button"],
Expand Down
2 changes: 1 addition & 1 deletion lib/ace/mode/coldfusion_highlight_rules.js
Expand Up @@ -75,7 +75,7 @@ var ColdfusionHighlightRules = function() {
this.$rules[s].unshift(cfTag);
}, this);

this.embedTagRules(new JavaScriptHighlightRules({noJSX: true}).getRules(), "cfjs-", "cfscript");
this.embedTagRules(new JavaScriptHighlightRules({jsx: false}).getRules(), "cfjs-", "cfscript");

this.normalizeRules();
};
Expand Down
2 changes: 1 addition & 1 deletion lib/ace/mode/html_highlight_rules.js
Expand Up @@ -99,7 +99,7 @@ var HtmlHighlightRules = function() {
});

this.embedTagRules(CssHighlightRules, "css-", "style");
this.embedTagRules(new JavaScriptHighlightRules({noJSX: true}).getRules(), "js-", "script");
this.embedTagRules(new JavaScriptHighlightRules({jsx: false}).getRules(), "js-", "script");

if (this.constructor === HtmlHighlightRules)
this.normalizeRules();
Expand Down
2 changes: 1 addition & 1 deletion lib/ace/mode/javascript_highlight_rules.js
Expand Up @@ -383,7 +383,7 @@ var JavaScriptHighlightRules = function(options) {
}]
});

if (!options || !options.noJSX)
if (!options || options.jsx != false)
JSX.call(this);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/ace/mode/typescript_highlight_rules.js
Expand Up @@ -86,7 +86,7 @@ var TypeScriptHighlightRules = function(options) {
}
];

var JSRules = new JavaScriptHighlightRules({jsx: options && options.jsx}).getRules();
var JSRules = new JavaScriptHighlightRules({jsx: (options && options.jsx) == true}).getRules();

JSRules.start = tsRules.concat(JSRules.start);
this.$rules = JSRules;
Expand Down

0 comments on commit b4e4437

Please sign in to comment.