Skip to content

Commit

Permalink
fix: update JSX mode to reflect React JSX (#5451)
Browse files Browse the repository at this point in the history
  • Loading branch information
InspiredGuy authored Jan 8, 2024
1 parent 4c6cf13 commit 66789a7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 198 deletions.
3 changes: 0 additions & 3 deletions ace-modes.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,6 @@ declare module "ace-code/src/mode/jssm_highlight_rules" {
declare module "ace-code/src/mode/jsx" {
export const Mode: new () => import(".").Ace.SyntaxMode;
}
declare module "ace-code/src/mode/jsx_highlight_rules" {
export const JsxHighlightRules: new () => import(".").Ace.HighlightRules;
}
declare module "ace-code/src/mode/julia" {
export const Mode: new () => import(".").Ace.SyntaxMode;
}
Expand Down
16 changes: 8 additions & 8 deletions demo/kitchen-sink/docs/jsx.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*EXPECTED
hello world!
*/
class Test {
static function run() : void {
// console.log("hello world!");
log "hello world!";
}
import * as React from "react";

export default () => {
return (
<div variant="p">
Keywords here are not highlighted, for example class or instance.
</div>
);
}
2 changes: 1 addition & 1 deletion src/ext/modelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ var supportedModes = {
Jack: ["jack"],
Jade: ["jade|pug"],
Java: ["java"],
JavaScript: ["js|jsm|jsx|cjs|mjs"],
JavaScript: ["js|jsm|cjs|mjs"],
JEXL: ["jexl"],
JSON: ["json"],
JSON5: ["json5"],
Expand Down
69 changes: 40 additions & 29 deletions src/mode/_test/tokens_jsx.json
Original file line number Diff line number Diff line change
@@ -1,51 +1,62 @@
[[
"comment",
["comment","/*EXPECTED"]
],[
"comment",
["comment","hello world!"]
],[
"start",
["comment","*/"]
],[
"start",
["keyword","class"],
["keyword","import"],
["text"," "],
["language.support.class","Test"],
["keyword.operator","*"],
["text"," "],
["paren.lparen","{"]
["identifier","as"],
["text"," "],
["identifier","React"],
["text"," "],
["keyword","from"],
["text"," "],
["string","\"react\""],
["punctuation.operator",";"]
],[
"start"
],[
"start",
["text"," "],
["keyword","static"],
["keyword","export"],
["text"," "],
["storage.type","function"],
["keyword","default"],
["text"," "],
["entity.name.function","run"],
["paren.lparen","("],
["paren.rparen",")"],
["text"," "],
["punctuation.operator",":"],
["text"," "],
["keyword","void"],
["storage.type","=>"],
["text"," "],
["paren.lparen","{"]
],[
"start",
["text"," "],
["comment","// console.log(\"hello world!\");"]
],[
"start",
["text"," "],
["keyword","log"],
["text"," "],
["keyword","return"],
["text"," "],
["string","\"hello world!\""],
["punctuation.operator",";"]
["paren.lparen","("]
],[
"start",
["jsx",1],
["text"," "],
["paren.rparen","}"]
["meta.tag.punctuation.tag-open.xml","<"],
["meta.tag.tag-name.xml","div"],
["text.tag-whitespace.xml"," "],
["entity.other.attribute-name.xml","variant"],
["keyword.operator.attribute-equals.xml","="],
["string.attribute-value.xml","\"p\""],
["meta.tag.punctuation.tag-close.xml",">"]
],[
["jsx",1],
["string"," Keywords here are not highlighted, for example class or instance."]
],[
"start",
["string"," "],
["meta.tag.punctuation.end-tag-open.xml","</"],
["meta.tag.tag-name.xml","div"],
["meta.tag.punctuation.tag-close.xml",">"]
],[
"start",
["text"," "],
["paren.rparen",")"],
["punctuation.operator",";"]
],[
"no_regex",
["paren.rparen","}"]
]]
47 changes: 7 additions & 40 deletions src/mode/jsx.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,19 @@
"use strict";

var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var JsxHighlightRules = require("./jsx_highlight_rules").JsxHighlightRules;
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
var jsMode = require("./javascript").Mode;

function Mode() {
this.HighlightRules = JsxHighlightRules;
this.$outdent = new MatchingBraceOutdent();
this.$behaviour = this.$defaultBehaviour;
this.foldingRules = new CStyleFoldMode();
jsMode.call(this);
this.$highlightRuleConfig = {jsx: true};
}
oop.inherits(Mode, TextMode);
oop.inherits(Mode, jsMode);

(function() {

this.lineCommentStart = "//";
this.blockComment = {start: "/*", end: "*/"};

this.getNextLineIndent = function(state, line, tab) {
var indent = this.$getIndent(line);

var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
var tokens = tokenizedLine.tokens;

if (tokens.length && tokens[tokens.length-1].type == "comment") {
return indent;
}

if (state == "start") {
var match = line.match(/^.*[\{\(\[]\s*$/);
if (match) {
indent += tab;
}
}

return indent;
// disable jshint
this.createWorker = function() {
return null;
};

this.checkOutdent = function(state, line, input) {
return this.$outdent.checkOutdent(line, input);
};

this.autoOutdent = function(state, doc, row) {
this.$outdent.autoOutdent(doc, row);
};

this.$id = "ace/mode/jsx";
}).call(Mode.prototype);

Expand Down
117 changes: 0 additions & 117 deletions src/mode/jsx_highlight_rules.js

This file was deleted.

0 comments on commit 66789a7

Please sign in to comment.