Skip to content

Allow for feature detection #1

Description

@fabiosantoscode

In javascript, it's very important to detect what features you have access to.

In the case of js2cpp, we don't have things like a window or a document or a global (not yet, for another issue). Unfortunately the c++ compiler doesn't allow us to compile if dead code calls something that doesn't exist.

If someone writes some isomorphic code which contains a feature detection, for example:

if (typeof location !== 'undefined') { location.reload(); }

We should remove the entire condition if this feature is not present.

A new option, which lists what is defined in the global scope, should be defined. Early returns such as

if (typeof location !== 'undefined') { return; }
// use location...

should also remove the code that follows them.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions