How to use the decaffeinate-parser.parse function in decaffeinate-parser

To help you get started, we’ve selected a few decaffeinate-parser 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 decaffeinate / decaffeinate / src / patchers / tester.js View on Github external
stdin.on('end', () => {
  let magicString = new MagicString(input);
  let ast = parse(input);
  console.log(ast.context.tokens);
  let patcher = makePatcher(ast, ast.context, magicString);

  patcher.patch();
  console.log(magicString.toString());
});
github decaffeinate / decaffeinate / src / index.ts View on Github external
const tokens = useCS2 ? getCoffee2Tokens(source) : getCoffee1Tokens(source);
    return {
      code: formatCoffeeScriptLexerTokens(tokens, context)
    };
  } else if (stageName === 'coffeescript-parser') {
    const nodes = useCS2 ? getCoffee2Nodes(source) : getCoffee1Nodes(source);
    return {
      code: formatCoffeeScriptAst(nodes, context)
    };
  } else if (stageName === 'coffee-lex') {
    return {
      code: formatCoffeeLexTokens(lex(source, { useCS2 }), context)
    };
  } else if (stageName === 'decaffeinate-parser') {
    return {
      code: formatDecaffeinateParserAst(decaffeinateParse(source, { useCS2 }), context)
    };
  } else {
    throw new Error(`Unrecognized stage name: ${stageName}`);
  }
}
github decaffeinate / decaffeinate / src / utils / parse.js View on Github external
export default function parse(source: string): Node {
  let ast = decaffeinateParse(source);
  traverse(ast, attachScope);
  return ast;
}
github decaffeinate / decaffeinate / src / utils / DecaffeinateContext.ts View on Github external
static create(source: string, useCS2: boolean): DecaffeinateContext {
    const program = decaffeinateParse(source, { useCS2 });
    return new DecaffeinateContext(
      program,
      source,
      program.context.sourceTokens,
      program.context.ast,
      program.context.linesAndColumns,
      computeParentMap(program),
      computeScopeMap(program)
    );
  }

decaffeinate-parser

A better AST for CoffeeScript, inspired by CoffeeScriptRedux.

MIT
Latest version published 2 years ago

Package Health Score

48 / 100
Full package analysis

Popular decaffeinate-parser functions