Skip to content
This repository was archived by the owner on Feb 1, 2025. It is now read-only.
This repository was archived by the owner on Feb 1, 2025. It is now read-only.

Keep directive prologues at top of function #248

@TiddoLangerak

Description

@TiddoLangerak

Consider the following simple function:

function* foo() {
    "myPrologue";

    bar();
    return;
}

Transforming this with regenerator gives:

var marked0$0 = [foo].map(regeneratorRuntime.mark);
function foo() {
    return regeneratorRuntime.wrap(function foo$(context$1$0) {
        while (1) switch (context$1$0.prev = context$1$0.next) {
        case 0:
            'myPrologue';
            return context$1$0.abrupt("return", bar());
        case 2:
        case "end":
            return context$1$0.stop();
        }
    }, marked0$0[0], this);
}

However, this breaks the prologue since it's no longer at the top of the function. I think the directives should instead be kept at the top of the function:

var marked0$0 = [foo].map(regeneratorRuntime.mark);
function foo() {
    'myPrologue';
    return regeneratorRuntime.wrap(function foo$(context$1$0) {
        while (1) switch (context$1$0.prev = context$1$0.next) {
        case 0:
            return context$1$0.abrupt("return", bar());
        case 2:
        case "end":
            return context$1$0.stop();
        }
    }, marked0$0[0], this);
}

Some pre-processors, like ng-annotate, make use of directive prologues to work properly, but this is currently incompatible with regenerator.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions