jackbsteinberg / get-originals-rewriter

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

Window methods #21

Closed jackbsteinberg closed 5 years ago

jackbsteinberg commented 5 years ago

Window methods like setTimeout() are going to cause difficulty because they don't follow the same pattern as other method calls and won't get detected and modified.

Additionally, Window isn't in the globals-set.js file to begin with, so isGlobal(Window) would return false anyway.

This is looking like it's going to have to be its own separate case to be handled.

domenic commented 5 years ago

You have a web example here with setTimeout(). A JS spec example would be parseFloat().

domenic commented 5 years ago

For accessors, you can figure out if they were declared in one of the built-in TypeScript definitions via code such as

// In a binary expressionstatement
const identifierNode = node.getExpression().getFirstChild();
const symbol = identifierNode.getSymbol();

    return symbol.getDeclarations()[0].getSourceFile().path
        .includes('/node_modules/typescript');
jackbsteinberg commented 5 years ago

What about the case when you're not using Window accessors in a binary expression statement? If I want to use a window value elsewhere (e.g. formatURL(location, ...)) then I don't think this would work

domenic commented 5 years ago

Sure, in that case just get the identifierNode from somewhere else, ignoring the first line of the code sample.