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

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

Issue 2772343006: DevTools: Roll CodeMirror to 5.25.1 (Closed)
Patch Set: stray space Created 3 years, 8 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|[\[{}\(,;:]|=>)$/.test(state.lastT ype) || 15 return /^(?:operator|sof|keyword c|case|new|export|default|[\[{}\(,;:]|=>)$/.t est(state.lastType) ||
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 stream.eatWhile(isOperatorChar); 149 if (ch != ">" || !state.lexical || state.lexical.type != ">")
150 stream.eatWhile(isOperatorChar);
150 return ret("operator", "operator", stream.current()); 151 return ret("operator", "operator", stream.current());
151 } else if (wordRE.test(ch)) { 152 } else if (wordRE.test(ch)) {
152 stream.eatWhile(wordRE); 153 stream.eatWhile(wordRE);
153 var word = stream.current(), known = keywords.propertyIsEnumerable(word) & & keywords[word]; 154 var word = stream.current(), known = keywords.propertyIsEnumerable(word) & & keywords[word];
154 return (known && state.lastType != ".") ? ret(known.type, known.style, wor d) : 155 return (known && state.lastType != ".") ? ret(known.type, known.style, wor d) :
155 ret("variable", "variable", word); 156 ret("variable", "variable", word);
156 } 157 }
157 } 158 }
158 159
159 function tokenString(quote) { 160 function tokenString(quote) {
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 } 498 }
498 function getterSetter(type) { 499 function getterSetter(type) {
499 if (type != "variable") return pass(afterprop); 500 if (type != "variable") return pass(afterprop);
500 cx.marked = "property"; 501 cx.marked = "property";
501 return cont(functiondef); 502 return cont(functiondef);
502 } 503 }
503 function afterprop(type) { 504 function afterprop(type) {
504 if (type == ":") return cont(expressionNoComma); 505 if (type == ":") return cont(expressionNoComma);
505 if (type == "(") return pass(functiondef); 506 if (type == "(") return pass(functiondef);
506 } 507 }
507 function commasep(what, end) { 508 function commasep(what, end, sep) {
508 function proceed(type, value) { 509 function proceed(type, value) {
509 if (type == ",") { 510 if (sep ? sep.indexOf(type) > -1 : type == ",") {
510 var lex = cx.state.lexical; 511 var lex = cx.state.lexical;
511 if (lex.info == "call") lex.pos = (lex.pos || 0) + 1; 512 if (lex.info == "call") lex.pos = (lex.pos || 0) + 1;
512 return cont(function(type, value) { 513 return cont(function(type, value) {
513 if (type == end || value == end) return pass() 514 if (type == end || value == end) return pass()
514 return pass(what) 515 return pass(what)
515 }, proceed); 516 }, proceed);
516 } 517 }
517 if (type == end || value == end) return cont(); 518 if (type == end || value == end) return cont();
518 return cont(expect(end)); 519 return cont(expect(end));
519 } 520 }
(...skipping 12 matching lines...) Expand all
532 return pass(statement, block); 533 return pass(statement, block);
533 } 534 }
534 function maybetype(type, value) { 535 function maybetype(type, value) {
535 if (isTS) { 536 if (isTS) {
536 if (type == ":") return cont(typeexpr); 537 if (type == ":") return cont(typeexpr);
537 if (value == "?") return cont(maybetype); 538 if (value == "?") return cont(maybetype);
538 } 539 }
539 } 540 }
540 function typeexpr(type) { 541 function typeexpr(type) {
541 if (type == "variable") {cx.marked = "variable-3"; return cont(afterType);} 542 if (type == "variable") {cx.marked = "variable-3"; return cont(afterType);}
542 if (type == "{") return cont(commasep(typeprop, "}")) 543 if (type == "string" || type == "number" || type == "atom") return cont(afte rType);
544 if (type == "{") return cont(pushlex("}"), commasep(typeprop, "}", ",;"), po plex)
543 if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType) 545 if (type == "(") return cont(commasep(typearg, ")"), maybeReturnType)
544 } 546 }
545 function maybeReturnType(type) { 547 function maybeReturnType(type) {
546 if (type == "=>") return cont(typeexpr) 548 if (type == "=>") return cont(typeexpr)
547 } 549 }
548 function typeprop(type) { 550 function typeprop(type, value) {
549 if (type == "variable" || cx.style == "keyword") { 551 if (type == "variable" || cx.style == "keyword") {
550 cx.marked = "property" 552 cx.marked = "property"
551 return cont(typeprop) 553 return cont(typeprop)
554 } else if (value == "?") {
555 return cont(typeprop)
552 } else if (type == ":") { 556 } else if (type == ":") {
553 return cont(typeexpr) 557 return cont(typeexpr)
554 } 558 }
555 } 559 }
556 function typearg(type) { 560 function typearg(type) {
557 if (type == "variable") return cont(typearg) 561 if (type == "variable") return cont(typearg)
558 else if (type == ":") return cont(typeexpr) 562 else if (type == ":") return cont(typeexpr)
559 } 563 }
560 function afterType(type, value) { 564 function afterType(type, value) {
561 if (value == "<") return cont(commasep(typeexpr, ">"), afterType) 565 if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, afterType)
566 if (value == "|" || type == ".") return cont(typeexpr)
562 if (type == "[") return cont(expect("]"), afterType) 567 if (type == "[") return cont(expect("]"), afterType)
563 } 568 }
564 function vardef() { 569 function vardef() {
565 return pass(pattern, maybetype, maybeAssign, vardefCont); 570 return pass(pattern, maybetype, maybeAssign, vardefCont);
566 } 571 }
567 function pattern(type, value) { 572 function pattern(type, value) {
568 if (type == "modifier") return cont(pattern) 573 if (type == "modifier") return cont(pattern)
569 if (type == "variable") { register(value); return cont(); } 574 if (type == "variable") { register(value); return cont(); }
570 if (type == "spread") return cont(pattern); 575 if (type == "spread") return cont(pattern);
571 if (type == "[") return contCommasep(pattern, "]"); 576 if (type == "[") return contCommasep(pattern, "]");
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 } 627 }
623 function classExpression(type, value) { 628 function classExpression(type, value) {
624 // Class expressions may have an optional name. 629 // Class expressions may have an optional name.
625 if (type == "variable") return className(type, value); 630 if (type == "variable") return className(type, value);
626 return classNameAfter(type, value); 631 return classNameAfter(type, value);
627 } 632 }
628 function className(type, value) { 633 function className(type, value) {
629 if (type == "variable") {register(value); return cont(classNameAfter);} 634 if (type == "variable") {register(value); return cont(classNameAfter);}
630 } 635 }
631 function classNameAfter(type, value) { 636 function classNameAfter(type, value) {
632 if (value == "extends" || value == "implements") return cont(isTS ? typeexpr : expression, classNameAfter); 637 if (value == "<") return cont(pushlex(">"), commasep(typeexpr, ">"), poplex, classNameAfter)
638 if (value == "extends" || value == "implements" || (isTS && type == ","))
639 return cont(isTS ? typeexpr : expression, classNameAfter);
633 if (type == "{") return cont(pushlex("}"), classBody, poplex); 640 if (type == "{") return cont(pushlex("}"), classBody, poplex);
634 } 641 }
635 function classBody(type, value) { 642 function classBody(type, value) {
636 if (type == "variable" || cx.style == "keyword") { 643 if (type == "variable" || cx.style == "keyword") {
637 if ((value == "static" || value == "get" || value == "set" || 644 if ((value == "async" || value == "static" || value == "get" || value == " set" ||
638 (isTS && (value == "public" || value == "private" || value == "protec ted" || value == "readonly" || value == "abstract"))) && 645 (isTS && (value == "public" || value == "private" || value == "protec ted" || value == "readonly" || value == "abstract"))) &&
639 cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false)) { 646 cx.stream.match(/^\s+[\w$\xa1-\uffff]/, false)) {
640 cx.marked = "keyword"; 647 cx.marked = "keyword";
641 return cont(classBody); 648 return cont(classBody);
642 } 649 }
643 cx.marked = "property"; 650 cx.marked = "property";
644 return cont(isTS ? classfield : functiondef, classBody); 651 return cont(isTS ? classfield : functiondef, classBody);
645 } 652 }
653 if (type == "[")
654 return cont(expression, expect("]"), isTS ? classfield : functiondef, clas sBody)
646 if (value == "*") { 655 if (value == "*") {
647 cx.marked = "keyword"; 656 cx.marked = "keyword";
648 return cont(classBody); 657 return cont(classBody);
649 } 658 }
650 if (type == ";") return cont(classBody); 659 if (type == ";") return cont(classBody);
651 if (type == "}") return cont(); 660 if (type == "}") return cont();
652 } 661 }
653 function classfield(type, value) { 662 function classfield(type, value) {
654 if (value == "?") return cont(classfield) 663 if (value == "?") return cont(classfield)
655 if (type == ":") return cont(typeexpr, maybeAssign) 664 if (type == ":") return cont(typeexpr, maybeAssign)
665 if (value == "=") return cont(expressionNoComma)
656 return pass(functiondef) 666 return pass(functiondef)
657 } 667 }
658 function afterExport(_type, value) { 668 function afterExport(type, value) {
659 if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";" )); } 669 if (value == "*") { cx.marked = "keyword"; return cont(maybeFrom, expect(";" )); }
660 if (value == "default") { cx.marked = "keyword"; return cont(expression, exp ect(";")); } 670 if (value == "default") { cx.marked = "keyword"; return cont(expression, exp ect(";")); }
671 if (type == "{") return cont(commasep(exportField, "}"), maybeFrom, expect(" ;"));
661 return pass(statement); 672 return pass(statement);
662 } 673 }
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 }
663 function afterImport(type) { 678 function afterImport(type) {
664 if (type == "string") return cont(); 679 if (type == "string") return cont();
665 return pass(importSpec, maybeFrom); 680 return pass(importSpec, maybeMoreImports, maybeFrom);
666 } 681 }
667 function importSpec(type, value) { 682 function importSpec(type, value) {
668 if (type == "{") return contCommasep(importSpec, "}"); 683 if (type == "{") return contCommasep(importSpec, "}");
669 if (type == "variable") register(value); 684 if (type == "variable") register(value);
670 if (value == "*") cx.marked = "keyword"; 685 if (value == "*") cx.marked = "keyword";
671 return cont(maybeAs); 686 return cont(maybeAs);
672 } 687 }
688 function maybeMoreImports(type) {
689 if (type == ",") return cont(importSpec, maybeMoreImports)
690 }
673 function maybeAs(_type, value) { 691 function maybeAs(_type, value) {
674 if (value == "as") { cx.marked = "keyword"; return cont(importSpec); } 692 if (value == "as") { cx.marked = "keyword"; return cont(importSpec); }
675 } 693 }
676 function maybeFrom(_type, value) { 694 function maybeFrom(_type, value) {
677 if (value == "from") { cx.marked = "keyword"; return cont(expression); } 695 if (value == "from") { cx.marked = "keyword"; return cont(expression); }
678 } 696 }
679 function arrayLiteral(type) { 697 function arrayLiteral(type) {
680 if (type == "]") return cont(); 698 if (type == "]") return cont();
681 return pass(commasep(expressionNoComma, "]")); 699 return pass(commasep(expressionNoComma, "]"));
682 } 700 }
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 CodeMirror.defineMIME("application/javascript", "javascript"); 793 CodeMirror.defineMIME("application/javascript", "javascript");
776 CodeMirror.defineMIME("application/x-javascript", "javascript"); 794 CodeMirror.defineMIME("application/x-javascript", "javascript");
777 CodeMirror.defineMIME("application/ecmascript", "javascript"); 795 CodeMirror.defineMIME("application/ecmascript", "javascript");
778 CodeMirror.defineMIME("application/json", {name: "javascript", json: true}); 796 CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
779 CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true}); 797 CodeMirror.defineMIME("application/x-json", {name: "javascript", json: true});
780 CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true}) ; 798 CodeMirror.defineMIME("application/ld+json", {name: "javascript", jsonld: true}) ;
781 CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true }); 799 CodeMirror.defineMIME("text/typescript", { name: "javascript", typescript: true });
782 CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript : true }); 800 CodeMirror.defineMIME("application/typescript", { name: "javascript", typescript : true });
783 801
784 }); 802 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698