jackbsteinberg / get-originals-rewriter

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

Document restrictions on input, specifically identifier names #19

Open domenic opened 5 years ago

domenic commented 5 years ago

We're starting to introduce new identifiers, specifically via imports, and depend on them. But consider the following program:

const Document_createElement = 5;
const x = document.createElement('div');

this will get transformed in to

import { createElement as Document_createElement } from "std:global/Document";
const Document_createElement = 5;
const x = call(a, Document_createElement, ['div']);

which is an error (double declaration of Document_createElement).

We could do something complicated, detecting existing bindings and routing around them (e.g. instead of the import being named Document_createElement it could be named Document_createElement1).

But that would be overkill. We should instead just make it clear up front that input code should not contain identifiers with underscores in it. We can recommend the ESLint rule which checks this, even.

If we felt that was too restrictive, we could alias everything to have some prefix (e.g. o_Document_createElement or $Document_createElement) and then document that restriction instead.