Skip to content

Latest commit

 

History

History
48 lines (38 loc) · 815 Bytes

optimizations.md

File metadata and controls

48 lines (38 loc) · 815 Bytes

Optimizations

Compile-time constant

The following should output a plain object, but compile-time accesses translate directly to constants.

const Q = {
    x: 10;
};
trace(Q.x); // trace(10);

Subtype

Example 1:

let v = o instanceof RegExp ? o.source : ''; // new local for RegExp
if (v instanceof Date && v.getSeconds() > 0) {
    // new local for Date
}

Example 2:

function f(a: number | string) {
    if (typeof a == 'number') {
        // new local for Number (note the "return")
        return;
    }
    // new local for String
}

Example 3:

try {
    //
} catch (error) {
    if (!(error instanceof ReferenceError)) {
        throw error;
    }
    // new local for ReferenceError
}