Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/cm_web_modes/javascript.js

Issue 2862603003: Revert of DevTools: Roll CodeMirror to 5.25.1
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others 1 // CodeMirror, copyright (c) by Marijn Haverbeke and others
2 // Distributed under an MIT license: http://codemirror.net/LICENSE 2 // Distributed under an MIT license: http://codemirror.net/LICENSE
3 3
4 (function(mod) { 4 (function(mod) {
5 if (typeof exports == "object" && typeof module == "object") // CommonJS 5 if (typeof exports == "object" && typeof module == "object") // CommonJS
6 mod(require("../../lib/codemirror")); 6 mod(require("../../lib/codemirror"));
7 else if (typeof define == "function" && define.amd) // AMD 7 else if (typeof define == "function" && define.amd) // AMD
8 define(["../../lib/codemirror"], mod); 8 define(["../../lib/codemirror"], mod);
9 else // Plain browser env 9 else // Plain browser env
10 mod(CodeMirror); 10 mod(CodeMirror);
11 })(function(CodeMirror) { 11 })(function(CodeMirror) {
12 "use strict"; 12 "use strict";
13 13
14 function expressionAllowed(stream, state, backUp) { 14 function expressionAllowed(stream, state, backUp) {
15 return /^(?:operator|sof|keyword c|case|new|export|default|[\[{}\(,;:]|=>)$/.t est(state.lastType) || 15 return /^(?:operator|sof|keyword c|case|new|[\[{}\(,;:]|=>)$/.test(state.lastT ype) ||
16 (state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.po s - (backUp || 0)))) 16 (state.lastType == "quasi" && /\{\s*$/.test(stream.string.slice(0, stream.po s - (backUp || 0))))
17 } 17 }
18 18
19 CodeMirror.defineMode("javascript", function(config, parserConfig) { 19 CodeMirror.defineMode("javascript", function(config, parserConfig) {
20 var indentUnit = config.indentUnit; 20 var indentUnit = config.indentUnit;
21 var statementIndent = parserConfig.statementIndent; 21 var statementIndent = parserConfig.statementIndent;
22 var jsonldMode = parserConfig.jsonld; 22 var jsonldMode = parserConfig.jsonld;
23 var jsonMode = parserConfig.json || jsonldMode; 23 var jsonMode = parserConfig.json || jsonldMode;
24 var isTS = parserConfig.typescript; 24 var isTS = parserConfig.typescript;
25 var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/; 25 var wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/;
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 stream.eatWhile(isOperatorChar); 139 stream.eatWhile(isOperatorChar);
140 return ret("operator", "operator", stream.current()); 140 return ret("operator", "operator", stream.current());
141 } 141 }
142 } else if (ch == "`") { 142 } else if (ch == "`") {
143 state.tokenize = tokenQuasi; 143 state.tokenize = tokenQuasi;
144 return tokenQuasi(stream, state); 144 return tokenQuasi(stream, state);
145 } else if (ch == "#") { 145 } else if (ch == "#") {
146 stream.skipToEnd(); 146 stream.skipToEnd();
147 return ret("error", "error"); 147 return ret("error", "error");
148 } else if (isOperatorChar.test(ch)) { 148 } else if (isOperatorChar.test(ch)) {
149 if (ch != ">" || !state.lexical || state.lexical.type != ">") 149 stream.eatWhile(isOperatorChar);
150 stream.eatWhile(isOperatorChar);
151 return ret("operator", "operator", stream.current()); 150 return ret("operator", "operator", stream.current());
152 } else if (wordRE.test(ch)) { 151 } else if (wordRE.test(ch)) {
153 stream.eatWhile(wordRE); 152 stream.eatWhile(wordRE);
154 var word = stream.current(), known = keywords.propertyIsEnumerable(word) & & keywords[word]; 153 var word = stream.current(), known = keywords.propertyIsEnumerable(word) & & keywords[word];
155 return (known && state.lastType != ".") ? ret(known.type, known.style, wor d) : 154 return (known && state.lastType != ".") ? ret(known.type, known.style, wor d) :
156 ret("variable", "variable", word); 155 ret("variable", "variable", word);
157 } 156 }
158 } 157 }
159 158
160 function tokenString(quote) { 159 function tokenString(quote) {
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 } 497 }
499 function getterSetter(type) { 498 function getterSetter(type) {
500 if (type != "variable") return pass(afterprop); 499 if (type != "variable") return pass(afterprop);
501 cx.marked = "property"; 500 cx.marked = "property";
502 return cont(functiondef); 501 return cont(functiondef);
503 } 502 }
504 function afterprop(type) { 503 function afterprop(type) {
505 if (type == ":") return cont(expressionNoComma); 504 if (type == ":") return cont(expressionNoComma);
506 if (type == "(") return pass(functiondef); 505 if (type == "(") return pass(functiondef);
507 } 506 }
508 function commasep(what, end, sep) { 507 function commasep(what, end) {
509 function proceed(type, value) { 508 function proceed(type, value) {
510 if (sep ? sep.indexOf(type) > -1 : type == ",") { 509 if (type == ",") {
511 var lex = cx.state.lexical; 510 var lex = cx.state.lexical;
512 if (lex.info == "call") lex.pos = (lex.pos || 0) + 1; 511 if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
513 return cont(function(type, value) { 512 return cont(function(type, value) {
514 if (type == end || value == end) return pass() 513 if (type == end || value == end) return pass()
515 return pass(what) 514 return pass(what)
516 }, proceed); 515 }, proceed);
517 } 516 }
518 if (type == end || value == end) return cont(); 517 if (type == end || value == end) return cont();
519 return cont(expect(end)); 518 return cont(expect(end));
520 } 519 }
(...skipping 12 matching lines...) Expand all
533 return pass(statement, block); 532 return pass(statement, block);
534 } 533 }
535 function maybetype(type, value) { 534 function maybetype(type, value) {
536 if (isTS) { 535 if (isTS) {
537 if (type == ":") return cont(typeexpr); 536 if (type == ":") return cont(typeexpr);
538 if (value == "?") return cont(maybetype); 537 if (value == "?") return cont(maybetype);
539 } 538 }
540 } 539 }
541 function typeexpr(type) { 540 function typeexpr(type) {
542 if (type == "variable") {cx.marked = "variable-3"; return cont(afterType);} 541 if (type == "variable") {cx.marked = "variable-3"; return cont(afterType);}
543 if (type == "string" || type == "number" || type == "atom") return cont(afte rType); 542 if (type == "{") return cont(commasep(typeprop, "}"))
544 if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), po plex)
545 if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType) 543 if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType)
546 } 544 }
547 function maybeReturnType(type) { 545 function maybeReturnType(type) {
548 if (type == "=>") return cont(typeexpr) 546 if (type == "=>") return cont(typeexpr)
549 } 547 }
550 function typeprop(type, value) { 548 function typeprop(type) {
551 if (type == "variable" || cx.style == "keyword") { 549 if (type == "variable" || cx.style == "keyword") {
552 cx.marked = "property" 550 cx.marked = "property"
553 return cont(typeprop) 551 return cont(typeprop)
554 } else if (value == "?") {
555 return cont(typeprop)
556 } else if (type == ":") { 552 } else if (type == ":") {
557 return cont(typeexpr) 553 return cont(typeexpr)
558 } 554 }
559 } 555 }
560 function typearg(type) { 556 function typearg(type) {
561 if (type == "variable") return cont(typearg) 557 if (type == "variable") return cont(typearg)
562 else if (type == ":") return cont(typeexpr) 558 else if (type == ":") return cont(typeexpr)
563 } 559 }
564 function afterType(type, value) { 560 function afterType(type, value) {
565 if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType) 561 if (value == "<") return cont(commasep(typeexpr, ">"), afterType)
566 if (value == "|" || type == ".") return cont(typeexpr)
567 if (type == "[") return cont(expect("]"), afterType) 562 if (type == "[") return cont(expect("]"), afterType)
568 } 563 }
569 function vardef() { 564 function vardef() {
570 return pass(pattern, maybetype, maybeAssign, vardefCont); 565 return pass(pattern, maybetype, maybeAssign, vardefCont);
571 } 566 }
572 function pattern(type, value) { 567 function pattern(type, value) {
573 if (type == "modifier") return cont(pattern) 568 if (type == "modifier") return cont(pattern)
574 if (type == "variable") { register(value); return cont(); } 569 if (type == "variable") { register(value); return cont(); }
575 if (type == "spread") return cont(pattern); 570 if (type == "spread") return cont(pattern);
576 if (type == "[") return contCommasep(pattern, "]"); 571 if (type == "[") return contCommasep(pattern, "]");
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 } 622 }
628 function classExpression(type, value) { 623 function classExpression(type, value) {
629 // Class expressions may have an optional name. 624 // Class expressions may have an optional name.
630 if (type == "variable") return className(type, value); 625 if (type == "variable") return className(type, value);
631 return classNameAfter(type, value); 626 return classNameAfter(type, value);
632 } 627 }
633 function className(type, value) { 628 function className(type, value) {
634 if (type == "variable") {register(value); return cont(classNameAfter);} 629 if (type == "variable") {register(value); return cont(classNameAfter);}
635 } 630 }
636 function classNameAfter(type, value) { 631 function classNameAfter(type, value) {
637 if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, classNameAfter) 632 if (value == "extends" || value == "implements") return cont(isTS ? typeexpr : expression, classNameAfter);
638 if (value == "extends" || value == "implements" || (isTS && type == ","))
639 return cont(isTS ? typeexpr : expression, classNameAfter);
640 if (type == "{") return cont(pushlex("}"), classBody, poplex); 633 if (type == "{") return cont(pushlex("}"), classBody, poplex);
641 } 634 }
642 function classBody(type, value) { 635 function classBody(type, value) {
643 if (type == "variable" || cx.style == "keyword") { 636 if (type == "variable" || cx.style == "keyword") {
644 if ((value == "async" || value == "static" || value == "get" || value == " set" || 637 if ((value == "static" || value == "get" || value == "set" ||
645 (isTS && (value == "public" || value == "private" || value == "protec ted" || value == "readonly" || value == "abstract"))) && 638 (isTS && (value == "public" || value == "private" || value == "protec ted" || value == "readonly" || value == "abstract"))) &&
646 cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false)) { 639 cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false)) {
647 cx.marked = "keyword"; 640 cx.marked = "keyword";
648 return cont(classBody); 641 return cont(classBody);
649 } 642 }
650 cx.marked = "property"; 643 cx.marked = "property";
651 return cont(isTS ? classfield : functiondef, classBody); 644 return cont(isTS ? classfield : functiondef, classBody);
652 } 645 }
653 if (type == "[")
654 return cont(expression, expect("]"), isTS ? classfield : functiondef, clas sBody)
655 if (value == "*") { 646 if (value == "*") {
656 cx.marked = "keyword"; 647 cx.marked = "keyword";
657 return cont(classBody); 648 return cont(classBody);
658 } 649 }
659 if (type == ";") return cont(classBody); 650 if (type == ";") return cont(classBody);
660 if (type == "}") return cont(); 651 if (type == "}") return cont();
661 } 652 }
662 function classfield(type, value) { 653 function classfield(type, value) {
663 if (value == "?") return cont(classfield) 654 if (value == "?") return cont(classfield)
664 if (type == ":") return cont(typeexpr, maybeAssign) 655 if (type == ":") return cont(typeexpr, maybeAssign)
665 if (value == "=") return cont(expressionNoComma)
666 return pass(functiondef) 656 return pass(functiondef)
667 } 657 }
668 function afterExport(type, value) { 658 function afterExport(_type, value) {
669 if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";" )); } 659 if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";" )); }
670 if (value == "default") { cx.marked = "keyword"; return cont(expression, exp ect(";")); } 660 if (value == "default") { cx.marked = "keyword"; return cont(expression, exp ect(";")); }
671 if (type == "{") return cont(commasep(exportField, "}"), maybeFrom, expect(" ;"));
672 return pass(statement); 661 return pass(statement);
673 } 662 }
674 function exportField(type, value) {
675 if (value == "as") { cx.marked = "keyword"; return cont(expect("variable")); }
676 if (type == "variable") return pass(expressionNoComma, exportField);
677 }
678 function afterImport(type) { 663 function afterImport(type) {
679 if (type == "string") return cont(); 664 if (type == "string") return cont();
680 return pass(importSpec, maybeMoreImports, maybeFrom); 665 return pass(importSpec, maybeFrom);
681 } 666 }
682 function importSpec(type, value) { 667 function importSpec(type, value) {
683 if (type == "{") return contCommasep(importSpec, "}"); 668 if (type == "{") return contCommasep(importSpec, "}");
684 if (type == "variable") register(value); 669 if (type == "variable") register(value);
685 if (value == "*") cx.marked = "keyword"; 670 if (value == "*") cx.marked = "keyword";
686 return cont(maybeAs); 671 return cont(maybeAs);
687 } 672 }
688 function maybeMoreImports(type) {
689 if (type == ",") return cont(importSpec, maybeMoreImports)
690 }
691 function maybeAs(_type, value) { 673 function maybeAs(_type, value) {
692 if (value == "as") { cx.marked = "keyword"; return cont(importSpec); } 674 if (value == "as") { cx.marked = "keyword"; return cont(importSpec); }
693 } 675 }
694 function maybeFrom(_type, value) { 676 function maybeFrom(_type, value) {
695 if (value == "from") { cx.marked = "keyword"; return cont(expression); } 677 if (value == "from") { cx.marked = "keyword"; return cont(expression); }
696 } 678 }
697 function arrayLiteral(type) { 679 function arrayLiteral(type) {
698 if (type == "]") return cont(); 680 if (type == "]") return cont();
699 return pass(commasep(expressionNoComma, "]")); 681 return pass(commasep(expressionNoComma, "]"));
700 } 682 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 CodeMirror.defineMIME("application/javascript", "javascript"); 775 CodeMirror.defineMIME("application/javascript", "javascript");
794 CodeMirror.defineMIME("application/x-javascript", "javascript"); 776 CodeMirror.defineMIME("application/x-javascript", "javascript");
795 CodeMirror.defineMIME("application/ecmascript", "javascript"); 777 CodeMirror.defineMIME("application/ecmascript", "javascript");
796 CodeMirror.defineMIME("application/json", {name: "javascript", json: true}); 778 CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
797 CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true}); 779 CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true});
798 CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true}) ; 780 CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true}) ;
799 CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true }); 781 CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
800 CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript : true }); 782 CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript : true });
801 783
802 }); 784 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698