import TokenProcessor from './TokenProcessor' ; import { parse } from "./parser" ; import RootTransformer from "./transformers/RootTransformer" ; class TransformResult { code : string ; constructor ( code ) { this . code = code ; } } export class SucraseContext { tokenProcessor : TokenProcessor ; constructor ( tokenProcessor ) { this . tokenProcessor = tokenProcessor ; } } export function transform ( code ) { const sucraseContext = getSucraseContext ( code ) ; const transformer = new RootTransformer ( sucraseContext ) ; let result = new TransformResult ( transformer . transform ( ) ) ; return result ; } /**
 * Return a string representation of the sucrase tokens, mostly useful for
 * diagnostic purposes.
 */ /**
 * Call into the parser/tokenizer and do some further preprocessing:
 * - Come up with a set of used names so that we can assign new names.
 * - Preprocess all import/export statements so we know which globals we are interested in.
 * - Compute situations where any of those globals are shadowed.
 *
 * In the future, some of these preprocessing steps can be skipped based on what actual work is
 * being done.
 */ function getSucraseContext ( code ) { const file = parse ( code ) ; const tokens = file . tokens ; const tokenProcessor = new TokenProcessor ( code , tokens ) ; return new SucraseContext ( tokenProcessor ) ; }