How to use the babylon.tokTypes.backQuote 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 brumbrum-it / styled-components-stylefmt / src / index.js View on Github external
export default function (inputPath: string, options?: Options = {}) {
  const input = fs.readFileSync(inputPath).toString()

  const EOL = detectNewline(input)
  const escapedEOL = escapeStringRegexp(EOL)

  const closingTokens = [tokTypes.bracketR, tokTypes.braceR, tokTypes.braceBarR, tokTypes.parenR, tokTypes.backQuote]
    .map(({ label }) => label)
    .map(escapeStringRegexp)

  const closingRegexp = new RegExp(`^\\s*((?:${closingTokens.join('|')}|\\s)+)\\s*${closingTokens[1]}.*$`, 'm')

  const getClosingLineTokens = (line: string) => {
    const matches = line.match(closingRegexp)

    return matches ? matches[1] : ''
  }

  const lines = input.split(EOL)
  let output = input
  let offset = 0

  const ast = parse(input, {
github ringcentral / ringcentral-js-widgets / packages / locale-loader / lib / getRawData / index.js View on Github external
let idx = startIdx;
  let token = tokens[idx];
  const keyArray = [];
  do {
    keyArray.push(typeof token.value !== 'undefined' ? token.value : token.type.label);
    idx += 1;
    token = tokens[idx];
  } while (token.type !== tokTypes.colon);
  const valueArray = [];
  const valueStart = idx + 1;
  let valueEnd;
  do {
    idx += 1;
    token = tokens[idx];
    if (
      token.type === tokTypes.backQuote
    ) {
      throw new Error('Template strings are not supported');
    } else {
      valueArray.push(typeof token.value !== 'undefined' ? token.value : token.type.label);
    }
    valueEnd = idx;
  } while (tokens[idx + 1].type !== tokTypes.comma && tokens[idx + 1].type !== tokTypes.braceR);
  const value = valueArray.join('');
  return {
    key: keyArray.join(''),
    value,
    startIdx,
    valueStart,
    valueEnd,
    endIdx: tokens[idx + 1].type === tokTypes.comma ? idx + 1 : idx,
  };