Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep directive prologues at top of function #248

Closed
TiddoLangerak opened this issue Jun 2, 2016 · 2 comments
Closed

Keep directive prologues at top of function #248

TiddoLangerak opened this issue Jun 2, 2016 · 2 comments

Comments

@TiddoLangerak
Copy link

TiddoLangerak commented Jun 2, 2016

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.

@benjamn
Copy link
Collaborator

benjamn commented Jun 2, 2016

Why not keep them at the top of the foo function? That's where any variables will be declared, in case that's relevant.

@TiddoLangerak
Copy link
Author

Yes, I think that makes most sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants