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

Testing all leading comments against being PURE comments #2305

Merged
merged 1 commit into from
Sep 9, 2017

Conversation

Andarist
Copy link
Contributor

@Andarist Andarist commented Sep 9, 2017

As discussed under https://github.com/mishoo/UglifyJS2/pull/1448/files#r137827678

Change is pretty straight-forward. It allows i.e. babel plugins to insert PURE comments easier, allowing easier interoperability with other automatically inserted annotations.

&& (pure_comment = find_if(function (comment) {
return /[@#]__PURE__/.test(comment.value);
}, comments))) {
pure = pure_comment;
Copy link
Contributor

Choose a reason for hiding this comment

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

@alexlamsl Are you okay with the efficiency of find_if in this scenario? If so, LGTM.

Copy link
Collaborator

Choose a reason for hiding this comment

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

pure & pure_comment now feels redundant as find_if() will return undefined, e.g. falsy, if no comment has matched.

Copy link
Contributor

Choose a reason for hiding this comment

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

pure & pure_comment now feels redundant as find_if() will return undefined, e.g. falsy, if no comment has matched.

It's not redundant. It would screw up the caching of return this.pure = pure;. undefined is not falsey in this scenario - it means "not set". false means no pure annotation found previously and no need to scan again.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah okay - thanks for the clarification 👍

Copy link
Contributor

@kzc kzc Sep 9, 2017

Choose a reason for hiding this comment

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

@alexlamsl I see your point. Could get rid of var pure and just:

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should work:

-        return this.pure = pure;
+        return this.pure = pure_comment || false;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

its already initialized with false few line above

Copy link
Contributor

@kzc kzc Sep 9, 2017

Choose a reason for hiding this comment

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

Assuming we want to eliminate var pure ...

pure_comment is not initialized to false:

https://github.com/mishoo/UglifyJS2/pull/2305/files#diff-230c53e13e3ee367aec7d49470eb42caR1983

and find_if returns undefined if nothing found.

Copy link
Contributor

Choose a reason for hiding this comment

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

Assuming we want to eliminate var pure ...

Or just leave PR as is. It works.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, don't sweat too much over my OCD... 😅

"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:84,33]",
"WARN: Dropping unused variable iife1 [test/compress/issue-1261.js:84,12]",
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:100,45]",
"WARN: Dropping unused variable MyClass [test/compress/issue-1261.js:100,12]"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I'd prefer trailing commas.

@alexlamsl
Copy link
Collaborator

@Andarist thanks for the work - LGTM with minor nits.

"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:145,24]",
"WARN: Condition always true [test/compress/issue-1261.js:145,8]",
"WARN: Dropping __PURE__ call [test/compress/issue-1261.js:146,31]",
"WARN: Condition always false [test/compress/issue-1261.js:146,8]"
Copy link
Contributor

Choose a reason for hiding this comment

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

please add trailing comma

@Andarist
Copy link
Contributor Author

Andarist commented Sep 9, 2017

ive added missing trailing commas

@alexlamsl alexlamsl merged commit 8158b1b into mishoo:master Sep 9, 2017
@alexlamsl
Copy link
Collaborator

@Andarist thanks again for the patch.

I'm going to restart test/ufuzz.js - had 1MFuzz without incident earlier today.

So there should probably be a new release before Monday.

@Andarist Andarist deleted the pure-comments-any-index branch September 9, 2017 19:56
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

3 participants