pakmanaged.js
function(checks) {
        var tokenType;
        var value = "";
        var ch;
        var startLine = this.line;
        var startChar = this.char;
        var depth = this.templateStarts.length;
    
        if (!state.option.esnext) {
          // Only lex template strings in ESNext mode.
          return null;
        } else if (this.peek() === "`") {
          // Template must start with a backtick.
          tokenType = Token.TemplateHead;
          this.templateStarts.push({ line: this.line, char: this.char });
          depth = this.templateStarts.length;
          this.skip(1);
          this.pushContext(Context.Template);
        } else if (this.inContext(Context.Template) && this.peek() === "}") {
          // If we're in a template context, and we have a '}', lex a TemplateMiddle.
          tokenType = Token.TemplateMiddle;
        } else {
          // Go lex something else.
          return null;
        }
    
        while (this.peek() !== "`") {
          while ((ch = this.peek()) === "") {
            value += "\n";
            if (!this.nextLine()) {
              // Unclosed template literal --- point to the starting "`"
              var startPos = this.templateStarts.pop();
              this.trigger("error", {
                code: "E052",
                line: startPos.line,
                character: startPos.char
              });
              return {
                type: tokenType,
                value: value,
                startLine: startLine,
                startChar: startChar,
                isUnclosed: true,
                depth: depth,
                context: this.popContext()
              };
            }
          }
    
          if (ch === '$' && this.peek(1) === '{') {
            value += '${';
            this.skip(2);
            return {
              type: tokenType,
              value: value,
              startLine: startLine,
              startChar: startChar,
              isUnclosed: false,
              depth: depth,
              context: this.currentContext()
            };
          } else if (ch === '\\') {
            var escape = this.scanEscapeSequence(checks);
            value += escape.char;
            this.skip(escape.jump);
          } else if (ch !== '`') {
            // Otherwise, append the value and continue.
            value += ch;
            this.skip(1);
          }
        }
    
        // Final value is either NoSubstTemplate or TemplateTail
        tokenType = tokenType === Token.TemplateHead ? Token.NoSubstTemplate : Token.TemplateTail;
        this.skip(1);
        this.templateStarts.pop();
    
        return {
          type: tokenType,
          value: value,
          startLine: startLine,
          startChar: startChar,
          isUnclosed: false,
          depth: depth,
          context: this.popContext()
        };
      }
function(checks) {
        var tokenType;
        var value = "";
        var ch;
        var startLine = this.line;
        var startChar = this.char;
        var depth = this.templateStarts.length;
    
        if (!state.option.esnext) {
          // Only lex template strings in ESNext mode.
          return null;
        } else if (this.peek() === "`") {
          // Template must start with a backtick.
          tokenType = Token.TemplateHead;
          this.templateStarts.push({ line: this.line, char: this.char });
          depth = this.templateStarts.length;
          this.skip(1);
          this.pushContext(Context.Template);
        } else if (this.inContext(Context.Template) && this.peek() === "}") {
          // If we're in a template context, and we have a '}', lex a TemplateMiddle.
          tokenType = Token.TemplateMiddle;
        } else {
          // Go lex something else.
          return null;
        }
    
        while (this.peek() !== "`") {
          while ((ch = this.peek()) === "") {
            value += "\n";
            if (!this.nextLine()) {
              // Unclosed template literal --- point to the starting "`"
              var startPos = this.templateStarts.pop();
              this.trigger("error", {
                code: "E052",
                line: startPos.line,
                character: startPos.char
              });
              return {
                type: tokenType,
                value: value,
                startLine: startLine,
                startChar: startChar,
                isUnclosed: true,
                depth: depth,
                context: this.popContext()
              };
            }
          }
    
          if (ch === '$' && this.peek(1) === '{') {
            value += '${';
            this.skip(2);
            return {
              type: tokenType,
              value: value,
              startLine: startLine,
              startChar: startChar,
              isUnclosed: false,
              depth: depth,
              context: this.currentContext()
            };
          } else if (ch === '\\') {
            var escape = this.scanEscapeSequence(checks);
            value += escape.char;
            this.skip(escape.jump);
          } else if (ch !== '`') {
            // Otherwise, append the value and continue.
            value += ch;
            this.skip(1);
          }
        }
    
        // Final value is either NoSubstTemplate or TemplateTail
        tokenType = tokenType === Token.TemplateHead ? Token.NoSubstTemplate : Token.TemplateTail;
        this.skip(1);
        this.templateStarts.pop();
    
        return {
          type: tokenType,
          value: value,
          startLine: startLine,
          startChar: startChar,
          isUnclosed: false,
          depth: depth,
          context: this.popContext()
        };
      }
/*
Extract a template literal out of the next sequence of characters
and/or lines or return 'null' if its not possible. Since template
literals can span across multiple lines, this method has to move
the char pointer.