Obfuscator constructor

Obfuscator(
  1. AST ast, {
  2. List<String> prelude = const [],
})

Constructor walks the AST, generates a prelude of remapped variables, and stores the result in content.

Implementation

Obfuscator(AST ast, {List<String> prelude = const []}) {
  pscope = _populatePrelude(prelude);
  global = Scope(pscope)..resetNextIdFrom(pscope);
  current = global;
  content = visitAST(ast);

  // Identifiers for std library needs to be preserved
  // so lua VMs can run them.
  final p =
    pscope.ids.entries.map((m) => '${m.value} = ${m.key}').join(_sep);

  content = '$p$_sep$content';
}