{"size": 2368, "ext": "js", "max_stars_repo_path": "src/typescript.js", "max_stars_repo_name": "mtaran-google/google-modes", "max_stars_repo_stars_event_min_datetime": "2017-07-08T05:11:37.000Z", "max_stars_repo_stars_event_max_datetime": "2021-06-26T18:39:32.000Z", "max_issues_repo_path": "src/typescript.js", "max_issues_repo_name": "mtaran-google/google-modes", "max_issues_repo_issues_event_min_datetime": "2017-07-07T17:56:38.000Z", "max_issues_repo_issues_event_max_datetime": "2021-12-17T11:02:25.000Z", "max_forks_repo_path": "src/typescript.js", "max_forks_repo_name": "mtaran-google/google-modes", "max_forks_repo_forks_event_min_datetime": "2017-07-07T17:43:35.000Z", "max_forks_repo_forks_event_max_datetime": "2022-02-20T05:25:42.000Z"}
{"max_stars_count": 33, "max_issues_count": 330, "max_forks_count": 28, "avg_line_length": 33.8285714286, "max_line_length": 102, "alphanum_fraction": 0.6820101351}
import * as CodeMirror from "codemirror"
import "codemirror-grammar-mode"
import * as grammar from "./typescript.mode"
import {markLocals} from "./locals"
import {indent} from "./c_indent"
import {canInsertSemi} from "./js_semi"
import {TemplateTokenizer} from "./template_string_inline_language";

const scopes = ["Block", "FunctionDef", "ArrowFunc", "ForStatement", "ParamListSpec"]

class TSMode extends CodeMirror.GrammarMode {
  constructor(conf, modeConf) {
    super(grammar, {
      predicates: {canInsertSemi: modeConf.requireSemicolons === false ? canInsertSemi : () => false}
    })
    this.templateTokenizer = new TemplateTokenizer(conf);
    this.indentConf = {doubleIndentBrackets: ">)", dontCloseBrackets: ")",
                       tabSize: conf.tabSize, indentUnit: conf.indentUnit,
                       forceContent: true}
  }

  startState() {
    const state = super.startState();
    state.embeddedParserState = this.templateTokenizer.startState();
    return state;
  }

  copyState(state) {
    const copy = super.copyState(state);
    copy.embeddedParserState =
        this.templateTokenizer.copyState(state.embeddedParserState);
    return copy;
  }

  token(stream, state) {
    const templateTokenizerState = state.embeddedParserState;
    if (this.templateTokenizer
          .shouldInterceptTokenizing(templateTokenizerState)) {
      const {handled, style} = this.templateTokenizer
          .interceptTokenizing(stream, templateTokenizerState);
      if (handled) {
        return style;
      }
    }
    const style = super.token(stream, state);
    this.templateTokenizer.trackState(style, stream, templateTokenizerState);
    return markLocals(style, scopes, stream, state)
  }

  indent(state, textAfter, line) {
    if (!textAfter) textAfter = line = "x" // Force getContextAt to terminate the statement, if needed
    return indent(state, textAfter, line, this.indentConf)
  }
}

let meta = {
  electricInput: /^\s*(?:case .*?:|default:|\{|\})$/,
  blockCommentStart: "/*",
  blockCommentEnd: "*/",
  blockCommentContinue: " * ",
  lineComment: "//",
  fold: "brace",
  closeBrackets: "()[]{}''\"\"``"
}
for (let prop in meta) TSMode.prototype[prop] = meta[prop]

CodeMirror.registerHelper("wordChars", "google-typescript", /[\w$]/)

CodeMirror.defineMode("google-typescript", (conf, modeConf) => new TSMode(conf, modeConf))
