How to use the esutils.code function in esutils

To help you get started, we’ve selected a few esutils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github yize / xswitch / src / astutils.ts View on Github external
export function adjustMultilineComment(value: string, base: string = '', specialBase: any) {
  var array, i, len, line, j, spaces, previousBase, sn;

  array = value.split(/\r\n|[\r\n]/);
  spaces = Number.MAX_VALUE;

  // first line doesn't have indentation
  for (i = 1, len = array.length; i < len; ++i) {
      line = array[i];
      j = 0;
      while (j < line.length && esutils.code.isWhiteSpace(line.charCodeAt(j))) {
          ++j;
      }
      if (spaces > j) {
          spaces = j;
      }
  }

  if (typeof specialBase !== 'undefined') {
      // pattern like
      // {
      //   var t = 20;  /*
      //                 * this is comment
      //                 */
      // }
      previousBase = base;
      if (array[1][spaces] === '*') {
github estools / esmangle / bin / esmangle.js View on Github external
if (comment.type !== 'Line') {
                this.finishCurrent();
                this.result.push(new CommentBlock(comment));
                return this;
            }

            if (!this.current) {
                this.current = new CommentBlock(comment);
                return this;
            }

            // Both comment and this.current are single line comments.
            for (i = this.current.comments[this.current.comments.length - 1].range[1], iz = comment.range[0]; i < iz; ++i) {
                code = source.charCodeAt(i);
                if (!esutils.code.isLineTerminator(code) && !esutils.code.isWhiteSpace(code)) {
                    // Not contiguous.
                    this.finishCurrent();
                    this.current = new CommentBlock(comment);
                    return this;
                }
            }

            this.current.append(comment);

            return this;
        };
github shapesecurity / shift-codegen-js / dist / token_stream.js View on Github external
this.put(";");
        }
      }
      if (this.lastNumber !== null && tokenStr.length == 1) {
        if (tokenStr === ".") {
          this.result += numberDot(this.lastNumber);
          this.lastNumber = null;
          this.lastChar = ".";
          return;
        }
      }
      this.lastNumber = null;
      var rightChar = tokenStr.charAt(0);
      var lastChar = this.lastChar;
      this.lastChar = tokenStr.charAt(tokenStr.length - 1);
      if (lastChar && ((lastChar == "+" || lastChar == "-") && lastChar == rightChar || _esutils.code.isIdentifierPartES6(lastChar.charCodeAt(0)) && _esutils.code.isIdentifierPartES6(rightChar.charCodeAt(0)) || lastChar == "/" && rightChar == "i")) {
        this.result += " ";
      }

      this.result += tokenStr;
    }
  }]);
github habitlab / habitlab / src / jspm_packages / npm / shift-codegen@4.0.3 / dist / token_stream.js View on Github external
this.put(";");
        }
      }
      if (this.lastNumber !== null && tokenStr.length == 1) {
        if (tokenStr === ".") {
          this.result += numberDot(this.lastNumber);
          this.lastNumber = null;
          this.lastChar = ".";
          return;
        }
      }
      this.lastNumber = null;
      var rightChar = tokenStr.charAt(0);
      var lastChar = this.lastChar;
      this.lastChar = tokenStr.charAt(tokenStr.length - 1);
      if (lastChar && ((lastChar == "+" || lastChar == "-") && lastChar == rightChar || _esutils.code.isIdentifierPartES6(lastChar.charCodeAt(0)) && _esutils.code.isIdentifierPartES6(rightChar.charCodeAt(0)) || lastChar == "/" && rightChar == "i")) {
        this.result += " ";
      }

      this.result += tokenStr;
    }
  }]);