<commit_before>namespace ts.pxt {
    export const assert = Util.assert;
    export const oops = Util.oops;
    export type StringMap<T> = Util.Map<T>;
    export import U = ts.pxt.Util;

    export const BINARY_JS = "binary.js";
    export const BINARY_HEX = "binary.hex";
    export const BINARY_ASM = "binary.asm";

    let EK = ir.EK;
    export const SK = SyntaxKind;

    export const numReservedGlobals = 1;

    export function stringKind(n: Node) {
        if (!n) return "<null>"
        return (<any>ts).SyntaxKind[n.kind]
    }

    function inspect(n: Node) {
        console.log(stringKind(n))
    }

    // next free error 9253
    function userError(code: number, msg: string, secondary = false): Error {
        let e = new Error(msg);
        (<any>e).ksEmitterUserError = true;
        (<any>e).ksErrorCode = code;
        if (secondary && inCatchErrors) {
            if (!lastSecondaryError) {
                lastSecondaryError = msg
                lastSecondaryErrorCode = code
            }
            return e
        }
        debugger;
        throw e;
    }

    function isRefType(t: Type) {
        checkType(t);
        if (t.flags & TypeFlags.ThisType)
            return true
        if (t.flags & TypeFlags.Null)
            return false
        if (t.flags & TypeFlags.Undefined)
            return false
        if (t.flags & TypeFlags.TypeParameter) {
            let b = lookupTypeParameter(t)
            if (b) return b.isRef
            U.oops("unbound type parameter: " + checker.typeToString(t))
        }
        return !(t.flags & (TypeFlags.Number | TypeFlags.Boolean | TypeFlags.Enum))
    }

    function isRefDecl(def: Declaration) {
        if ((<any>def).isThisParameter)
            return true;
        //let tp = checker.getDeclaredTypeOfSymbol(def.symbol)
        let tp = typeOf(def)
        return isRefType(tp)
    }

    export function setCellProps(l: ir.Cell) {
        l._isRef = isRefDecl(l.def)
        l._isLocal = isLocalVar(l.def) || isParameter(l.def)
        l._isGlobal = isGlobalVar(l.def)
        if (!l.isRef() && typeOf(l.def).flags & TypeFlags.Void) {
            oops("void-typed variable, " + l.toString())
        }
    }

    function isStringLiteral(node: Node) {
        switch (node.kind) {
            case SK.TemplateHead:
            case SK.TemplateMiddle:
            case SK.TemplateTail:
            case SK.StringLiteral:
            case SK.NoSubstitutionTemplateLiteral:
                return true;
            default: return false;
        }
    }

    function isEmptyStringLiteral(e: Expression | TemplateLiteralFragment) {
        return isStringLiteral(e) && (e as LiteralExpression).text == ""
    }

    function isStatic(node: Declaration) {
        return node.modifiers && node.modifiers.some(m => m.kind == SK.StaticKeyword)
    }

    function getEnclosingMethod(node: Node): MethodDeclaration {
        if (!node) return null;
        if (node.kind == SK.MethodDeclaration || node.kind == SK.Constructor)
            return <MethodDeclaration>node;
        return getEnclosingMethod(node.parent)
    }

    function isInAnyWayGeneric(node: FunctionLikeDeclaration) {
        return isGenericFunction(node) || hasGenericParent(node)
    }

    function hasGenericParent(node: Node): boolean {
        let par = getEnclosingFunction(node)
        if (par)
            return isGenericFunction(par) || hasGenericParent(par)
        return false
    }

    function getEnclosingFunction(node0: Node) {
        let node = node0
        while (true) {
            node = node.parent
            if (!node)
                userError(9229, lf("cannot determine parent of {0}", stringKind(node0)))
            if (node.kind == SK.FunctionDeclaration ||
                node.kind == SK.ArrowFunction ||
                node.kind == SK.FunctionExpression ||
                node.kind == SK.MethodDeclaration ||
                node.kind == SK.Constructor)
                return <FunctionLikeDeclaration>node
            if (node.kind == SK.SourceFile) return null
        }
    }

    function isGlobalVar(d: Declaration) {
        return (d.kind == SK.VariableDeclaration && !getEnclosingFunction(d)) ||
            (d.kind == SK.PropertyDeclaration && isStatic(d))
    }

    function isLocalVar(d: Declaration) {
        return d.kind == SK.VariableDeclaration && !isGlobalVar(d);
    }
<commit_msg>Fix build crash<commit_after>namespace ts.pxt {
    export const assert = Util.assert;
    export const oops = Util.oops;
    export type StringMap<T> = Util.Map<T>;
    export import U = ts.pxt.Util;

    export const BINARY_JS = "binary.js";
    export const BINARY_HEX = "binary.hex";
    export const BINARY_ASM = "binary.asm";

    let EK = ir.EK;
    export const SK = SyntaxKind;

    export const numReservedGlobals = 1;

    export function stringKind(n: Node) {
        if (!n) return "<null>"
        return (<any>ts).SyntaxKind[n.kind]
    }

    function inspect(n: Node) {
        console.log(stringKind(n))
    }

    // next free error 9253
    function userError(code: number, msg: string, secondary = false): Error {
        let e = new Error(msg);
        (<any>e).ksEmitterUserError = true;
        (<any>e).ksErrorCode = code;
        if (secondary && inCatchErrors) {
            if (!lastSecondaryError) {
                lastSecondaryError = msg
                lastSecondaryErrorCode = code
            }
            return e
        }
        debugger;
        throw e;
    }

    function isRefType(t: Type) {
        checkType(t);
        if (t.flags & TypeFlags.ThisType)
            return true
        if (t.flags & TypeFlags.Null)
            return false
        if (t.flags & TypeFlags.Undefined)
            return false
        if (t.flags & TypeFlags.TypeParameter) {
            let b = lookupTypeParameter(t)
            if (b) return b.isRef
            U.oops("unbound type parameter: " + checker.typeToString(t))
        }
        return !(t.flags & (TypeFlags.Number | TypeFlags.Boolean | TypeFlags.Enum))
    }

    function isRefDecl(def: Declaration) {
        if ((<any>def).isThisParameter)
            return true;
        //let tp = checker.getDeclaredTypeOfSymbol(def.symbol)
        let tp = typeOf(def)
        return isRefType(tp)
    }

    export function setCellProps(l: ir.Cell) {
        l._isRef = isRefDecl(l.def)
        l._isLocal = isLocalVar(l.def) || isParameter(l.def)
        l._isGlobal = isGlobalVar(l.def)
        if (!l.isRef() && typeOf(l.def).flags & TypeFlags.Void) {
            oops("void-typed variable, " + l.toString())
        }
    }

    function isStringLiteral(node: Node) {
        switch (node.kind) {
            case SK.TemplateHead:
            case SK.TemplateMiddle:
            case SK.TemplateTail:
            case SK.StringLiteral:
            case SK.NoSubstitutionTemplateLiteral:
                return true;
            default: return false;
        }
    }

    function isEmptyStringLiteral(e: Expression | TemplateLiteralFragment) {
        return isStringLiteral(e) && (e as LiteralExpression).text == ""
    }

    function isStatic(node: Declaration) {
        return node.modifiers && node.modifiers.some(m => m.kind == SK.StaticKeyword)
    }

    function getEnclosingMethod(node: Node): MethodDeclaration {
        if (!node) return null;
        if (node.kind == SK.MethodDeclaration || node.kind == SK.Constructor)
            return <MethodDeclaration>node;
        return getEnclosingMethod(node.parent)
    }

    function isInAnyWayGeneric(node: FunctionLikeDeclaration) {
        return isGenericFunction(node) || hasGenericParent(node)
    }

    function hasGenericParent(node: Node): boolean {
        let par = getEnclosingFunction(node)
        if (par)
            return isGenericFunction(par) || hasGenericParent(par)
        return false
    }

    function getEnclosingFunction(node0: Node) {
        let node = node0
        while (true) {
            node = node.parent
            if (!node)
                userError(9229, lf("cannot determine parent of {0}", stringKind(node0)))
            if (node.kind == SK.FunctionDeclaration ||
                node.kind == SK.ArrowFunction ||
                node.kind == SK.FunctionExpression ||
                node.kind == SK.MethodDeclaration ||
                node.kind == SK.Constructor)
                return <FunctionLikeDeclaration>node
            if (node.kind == SK.SourceFile) return null
        }
    }

    function isGlobalVar(d: Declaration) {
        if (!d) return false
        return (d.kind == SK.VariableDeclaration && !getEnclosingFunction(d)) ||
            (d.kind == SK.PropertyDeclaration && isStatic(d))
    }

    function isLocalVar(d: Declaration) {
        return d.kind == SK.VariableDeclaration && !isGlobalVar(d);
    }

{'fraction_non_alphanumeric': 0.10811728744480924, 'fraction_numerical': 0.0029435073021623456, 'mean_word_length': 2.055690072639225, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6855339', 'n_tokens_mistral': 2599, 'n_tokens_neox': 2510, 'n_words': 582}