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

for loops are now generated inline rather than in an IIFE #1983

Closed
wants to merge 2 commits into from

Conversation

alubbe
Copy link
Member

@alubbe alubbe commented Jun 6, 2015

This again improves performance a little bit (part of #1975).

The first change is to rename $index to $$iN, where N is the Nth for loop. The PR assumes this is safe. It also assumes it is safe to use variables that look like KEY__obj and KEY__l, where KEY is either $$iN or the KEY provided by the user.

@alubbe alubbe mentioned this pull request Jun 6, 2015
5 tasks
@@ -561,7 +562,8 @@ Lexer.prototype = {
if (captures = /^(?:- *)?(?:each|for) +([a-zA-Z_$][\w$]*)(?: *, *([a-zA-Z_$][\w$]*))? * in *([^\n]+)/.exec(this.input)) {
this.consume(captures[0].length);
var tok = this.tok('each', captures[1]);
tok.key = captures[2] || '$index';
tok.key = captures[2] || '$$i' + this.eachCount;
this.eachCount++;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is split into two lines on purpose for readability

@ForbesLindesay
Copy link
Member

This is great, but definitely a breaking change. Could you make this pull request against jade-code-gen project as well.

@alubbe alubbe added this to the 2.0.0 milestone Jun 8, 2015
@alubbe
Copy link
Member Author

alubbe commented Jun 8, 2015

Moved variable name generation out of the lexer.
As a side effect, all variable names now start with jade_, so if we consider those safe, the PR is now backwards-compatible.

@ForbesLindesay
Copy link
Member

Unfortunately I still don't consider this backwards compatible because:

  1. The immediately invoked function expression changes the scope of any variables the user defines within it.
  2. The $index variable that was previously implicitly created, could be used by users. I'm happy to break these users as part of the 2.0.0 release, but I don't want to break them as a point release.

I'm very excited for getting this done in the 2.0.0 release though :)

@alubbe
Copy link
Member Author

alubbe commented Jun 13, 2015

Now that we have started landing breaking changes in master, can we merge this or should it go straight into jade-code-gen?

@ForbesLindesay
Copy link
Member

It needs to go straight into jade-code-gen

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

Successfully merging this pull request may close these issues.

None yet

2 participants