How to use the babylon/lib/parser.default.prototype 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-null-safe-accessor / src / patch-babylon.js View on Github external
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);
};

// Parse SafeMemberExpression.
const originalParseSubscripts = Parser.prototype.parseSubscripts;
Parser.prototype.parseSubscripts = function (base, startPos, startLoc, noCalls) {
  base = originalParseSubscripts.apply(this, arguments);
  for (;;) {
    if (this.eat(_tokenizerTypes.types.questionDot)) {
      var node = this.startNodeAt(startPos, startLoc);
      node.object = base;
      node.property = this.parseIdentifier(true);
      node.computed = false;
      base = this.finishNode(node, "SafeMemberExpression");
      base = originalParseSubscripts.call(this, base, startPos, startLoc, noCalls);
    } else if (!noCalls && this.eat(_tokenizerTypes.types.questionParenL)) {
      var node = this.startNodeAt(startPos, startLoc);
      node.callee = base;
      node.arguments = this.parseCallExpressionArguments(_tokenizerTypes.types.parenR, this.hasPlugin("trailingFunctionCommas"), false);
      base = this.finishNode(node, "SafeCallExpression");
      this.toReferencedList(node.arguments);
github shuhei / babel-plugin-null-safe-accessor / src / patch-babylon.js View on Github external
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);
};

// Parse SafeMemberExpression.
const originalParseSubscripts = Parser.prototype.parseSubscripts;
Parser.prototype.parseSubscripts = function (base, startPos, startLoc, noCalls) {
  base = originalParseSubscripts.apply(this, arguments);
  for (;;) {
    if (this.eat(_tokenizerTypes.types.questionDot)) {
      var node = this.startNodeAt(startPos, startLoc);
      node.object = base;
      node.property = this.parseIdentifier(true);
      node.computed = false;
      base = this.finishNode(node, "SafeMemberExpression");
      base = originalParseSubscripts.call(this, base, startPos, startLoc, noCalls);
    } else if (!noCalls && this.eat(_tokenizerTypes.types.questionParenL)) {
      var node = this.startNodeAt(startPos, startLoc);
      node.callee = base;
      node.arguments = this.parseCallExpressionArguments(_tokenizerTypes.types.parenR, this.hasPlugin("trailingFunctionCommas"), false);
      base = this.finishNode(node, "SafeCallExpression");
      this.toReferencedList(node.arguments);
      base = originalParseSubscripts.call(this, base, startPos, startLoc, noCalls);
github forivall / tacoscript / packages / babylon-plugin-cst / scripts / check-overrided-functions.js View on Github external
#!/usr/bin/env node

require("babylon");
var Parser = require("babylon/lib/parser").default;
var expect = require("chai").expect;
var functionHash = require("./_function-hash");
var pp = Parser.prototype;

expect(functionHash(pp.skipSpace)).to.equal('0aae7bd722190ba61b58881b6858e0cb');
expect(functionHash(pp.parseNew)).to.equal('db164cd9ab726f774a46f68cca32ecc1');
console.log("OK");