jackbsteinberg / get-originals-rewriter

BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

be conservative or reject code we can't make safe #76

Open fergald opened 5 years ago

fergald commented 5 years ago
function f(arg) {
  if (!arg) {
    arg = document.createElement("div");
  }
  arg.scrollIntoView();
}

is currently rewritten to

    import { createElement as Document_createElement } from "std:global/Document";
    import { apply as Reflect_apply } from "std:global/Reflect";
    import { document_get as Window_document_get } from "std:global/Window";
    function f(arg) {
        if (!arg) {
            arg = Reflect_apply(Document_createElement, Window_document_get(), ["div"]);
        }
        arg.scrollIntoView();
    }

I think ts-morph gives us enough info to know that arg is HTMLDivElement|Any and so we should either be conservative and rewrite it to be assume the worse case (HTMLDivElement) or refuse to rewrite it.