Sha256: c74fb22041071bae86365c4449bbd91db21d0e9a08cc6ee23694ca07e98d2809

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

const parseSync = require("../parser/parseSync");

// This function is responsible for taking an input string of text and returning
// to prettier a JavaScript object that is the equivalent AST that represents
// the code stored in that string. We accomplish this by spawning a new Ruby
// process of parser.rb and reading JSON off STDOUT.
function parse(text, _parsers, _opts) {
  return parseSync("rbs", text);
}

const pragmaPattern = /#\s*@(prettier|format)/;

// This function handles checking whether or not the source string has the
// pragma for prettier. This is an optional workflow for incremental adoption.
function hasPragma(text) {
  return pragmaPattern.test(text);
}

// This function is critical for comments and cursor support, and is responsible
// for returning the index of the character within the source string that is the
// beginning of the given node.
function locStart(node) {
  return (node.location || node.type.location).start_pos;
}

// This function is critical for comments and cursor support, and is responsible
// for returning the index of the character within the source string that is the
// ending of the given node.
function locEnd(node) {
  return (node.location || node.type.location).end_pos;
}

module.exports = {
  parse,
  astFormat: "rbs",
  hasPragma,
  locStart,
  locEnd
};

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
prettier-1.5.3 src/rbs/parser.js
prettier-1.5.2 src/rbs/parser.js
prettier-1.5.1 src/rbs/parser.js
prettier-1.5.0 src/rbs/parser.js
prettier-1.4.0 src/rbs/parser.js