How to use the babylon/lib/tokenizer/types.types function in babylon

To help you get started, we’ve selected a few babylon 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 shuhei / babel-plugin-angular2-annotations / src / patch.js View on Github external
export default function patch() {
  let Parser;
  let tt;
  try {
    Parser = require('babylon/lib/parser').default;
    tt = require('babylon/lib/tokenizer/types').types;
  } catch(e) {
    console.error('Install `babylon` as a top-level package.');
    throw e;
  }

  // HACK: Monkey patching to parse parameter decorators.
  // Based on the compiled output of babel-core 6.0.14.
  Parser.prototype.parseBindingList = function (close, allowEmpty, allowTrailingComma) {
    let elts = [];
    let first = true;
    while (!this.eat(close)) {
      if (first) {
        first = false;
      } else {
        this.expect(tt.comma);
      }
github shuhei / babel-plugin-null-safe-accessor / src / patch-babylon.js View on Github external
var Parser = require('babylon/lib/parser').default;
var _tokenizerTypes = require('babylon/lib/tokenizer/types');
var Tokenizer = require('babylon/lib/tokenizer').default;

// Add tokenizer type.
_tokenizerTypes.types.questionDot = new _tokenizerTypes.TokenType("?.", { beforeExpr: true });
_tokenizerTypes.types.questionParenL = new _tokenizerTypes.TokenType("?(", { beforeExpr: true, startsExpr: true });

// Tokenize "?(" and "?.".
const originalGetTokenFromCode = Tokenizer.prototype.getTokenFromCode;
Tokenizer.prototype.getTokenFromCode = function getTokenFromCode(code) {
  if (code === 63) {
    var next = this.input.charCodeAt(this.state.pos + 1);
    switch (next) {
      case 40:
        this.state.pos += 2;
        return this.finishToken(_tokenizerTypes.types.questionParenL);
      case 46:
        this.state.pos += 2;
        return this.finishToken(_tokenizerTypes.types.questionDot);
    }
  }
  return originalGetTokenFromCode.apply(this, arguments);
github shuhei / babel-plugin-null-safe-accessor / src / patch-babylon.js View on Github external
var Parser = require('babylon/lib/parser').default;
var _tokenizerTypes = require('babylon/lib/tokenizer/types');
var Tokenizer = require('babylon/lib/tokenizer').default;

// Add tokenizer type.
_tokenizerTypes.types.questionDot = new _tokenizerTypes.TokenType("?.", { beforeExpr: true });
_tokenizerTypes.types.questionParenL = new _tokenizerTypes.TokenType("?(", { beforeExpr: true, startsExpr: true });

// Tokenize "?(" and "?.".
const originalGetTokenFromCode = Tokenizer.prototype.getTokenFromCode;
Tokenizer.prototype.getTokenFromCode = function getTokenFromCode(code) {
  if (code === 63) {
    var next = this.input.charCodeAt(this.state.pos + 1);
    switch (next) {
      case 40:
        this.state.pos += 2;
        return this.finishToken(_tokenizerTypes.types.questionParenL);
      case 46:
        this.state.pos += 2;
        return this.finishToken(_tokenizerTypes.types.questionDot);
    }
  }
github eponymous-labs / babel-plugin-top-level-await / dist / top-level-await.js View on Github external
return function (file, program) {
            program.sourceType = this.options.sourceType;

            // set state to inAsync to allow awaits
            this.state.inAsync = true;

            // allow strings at the top of a script
            // plus the only useful directive is "use strict"
            // which gets added by babel anyways

            var allowDirectives = false;
            this.parseBlockBody(program, allowDirectives, true, _types.types.eof);

            file.program = this.finishNode(program, "Program");
            file.comments = this.state.comments;
            file.tokens = this.state.tokens;

            return this.finishNode(file, "File");
        };
    });
github nikaspran / coffee-to-ts / lib / babel / import.js View on Github external
_parser2.default.prototype.tsParseImportRequire = function (node) {
	this.next();
	node.local = this.parseIdentifier();

	this.eat(_types.types.eq);
	this.eatContextual('require');
	this.eat(_types.types.parenL);

	node.source = this.match(_types.types.string) ? this.parseExprAtom() : this.unexpected();
	this.eat(_types.types.parenR);
	this.semicolon();
	return this.finishNode(node, 'ImportRequire');
};
github nikaspran / coffee-to-ts / lib / babel / import.js View on Github external
_parser2.default.prototype.tsParseImportRequire = function (node) {
	this.next();
	node.local = this.parseIdentifier();

	this.eat(_types.types.eq);
	this.eatContextual('require');
	this.eat(_types.types.parenL);

	node.source = this.match(_types.types.string) ? this.parseExprAtom() : this.unexpected();
	this.eat(_types.types.parenR);
	this.semicolon();
	return this.finishNode(node, 'ImportRequire');
};
github shuhei / babel-plugin-null-safe-accessor / src / patch-babylon.js View on Github external
Tokenizer.prototype.getTokenFromCode = function getTokenFromCode(code) {
  if (code === 63) {
    var next = this.input.charCodeAt(this.state.pos + 1);
    switch (next) {
      case 40:
        this.state.pos += 2;
        return this.finishToken(_tokenizerTypes.types.questionParenL);
      case 46:
        this.state.pos += 2;
        return this.finishToken(_tokenizerTypes.types.questionDot);
    }
  }
  return originalGetTokenFromCode.apply(this, arguments);
};