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

@license comments on inlined functions leads to broken code output #597

Closed
mbudde opened this issue Mar 13, 2020 · 3 comments
Closed

@license comments on inlined functions leads to broken code output #597

mbudde opened this issue Mar 13, 2020 · 3 comments
Labels

Comments

@mbudde
Copy link

mbudde commented Mar 13, 2020

Bug report or Feature request?
Bug

Version (complete output of terser -V or specific git commit)
4.6.6

Complete CLI command or minify() options used

terser dawa-autocomplete2.es.js -c -o terser-output.js 

terser input
https://cdn.jsdelivr.net/npm/dawa-autocomplete2@1.0.2/dist/js/unfilled/dawa-autocomplete2.es.js

terser output or error
terser outputs code with a newline after a return statement. The return statement is followed by the @license comment and then the inlined function. The newline causes a semicolon to be injected which means the rest of the function becomes unreachable code.

grep -A17 -E 'return$' terser-output.js
 */function isElement(node){return 1===node.nodeType}var getRootNode=Node.prototype.getRootNode||function(){for(var cur
=this,prev=cur;cur;)prev=cur,cur=cur.parentNode;return prev};function getFocusedPath(node,root){var activeElement=funct
ion(node){var root=getRootNode.call(node);return
/**
 * @license
 * Copyright 2018 The Incremental DOM Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS-IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
function(node){return 11===node.nodeType||9===node.nodeType}(root)?root.activeElement:null}(node);return activeElement&
&node.contains(activeElement)?function(node,root){for(var ancestry=[],cur=node;cur!==root;){var n=cur;ancestry.push(n),
cur=n.parentNode}return ancestry}(activeElement,root):[]}
--
 */function isElement(node){return 1===node.nodeType}var getRootNode=Node.prototype.getRootNode||function(){for(var cur
=this,prev=cur;cur;)prev=cur,cur=cur.parentNode;return prev};function getFocusedPath(node,root){var activeElement=funct
ion(node){var root=getRootNode.call(node);return
/**
 * @license
 * Copyright 2018 The Incremental DOM Authors. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS-IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
function(node){return 11===node.nodeType||9===node.nodeType}(root)?root.activeElement:null}(node);return activeElement&
&node.contains(activeElement)?function(node,root){for(var ancestry=[],cur=node;cur!==root;){var n=cur;ancestry.push(n),
cur=n.parentNode}return ancestry}(activeElement,root):[]}

Expected result
That terser doesn't output broken code. In this case I'm not quite sure what the correct solution is. Some options could be to thrown an error or not to inline functions with @license comments or perhaps removing the newline before and after the comment.

Sorry in advance for the large testcase. I'm having trouble triggering the bug in a reduced example.

@fabiosantoscode
Copy link
Collaborator

Thanks very much for this test case. I've narrowed the issue down and am working on a fix right now.

@mbudde
Copy link
Author

mbudde commented Mar 15, 2020

Awesome! Thank you for fixing this so quickly 👍

@fabiosantoscode
Copy link
Collaborator

No problem!

Releases are during the week so on monday I'll ship it :)

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

No branches or pull requests

2 participants