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

Reserved Keyword breaks minifying by YUICompressor #437

Closed
janwidmer opened this issue Sep 29, 2017 · 3 comments
Closed

Reserved Keyword breaks minifying by YUICompressor #437

janwidmer opened this issue Sep 29, 2017 · 3 comments
Labels
feature This would be nice to have. PRIORITY: low TARGETS: core Utility functions, lifecycle, core library stuff.

Comments

@janwidmer
Copy link

janwidmer commented Sep 29, 2017

We are using popper.js within the CMS System AEM. Because of several technical restrictions, we are forced to use YUIcompressor for asset minification in the backend.

YUIcompressor seems to be more strict about reserved keywords and fails to compress javascript code containing reserved keywords as function / property names.

Popper.js and popper-utils.js seem to contain such function names both in that function:

function runModifiers(modifiers, data, ends) {
  var modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex(modifiers, 'name', ends));

  modifiersToRun.forEach(function (modifier) {
    if (modifier.function) {
      console.warn('`modifier.function` is deprecated, use `modifier.fn`!');
    }
    var fn = modifier.function || modifier.fn;
    if (modifier.enabled && isFunction(fn)) {
      data = fn(data, modifier);
    }
  });

  return data;
}

Would it be possible to replace them by this code:

function runModifiers(modifiers, data, ends) {
  var modifiersToRun = ends === undefined ? modifiers : modifiers.slice(0, findIndex(modifiers, 'name', ends));

  modifiersToRun.forEach(function (modifier) {
-   if (modifier.function) {
+   if (modifier['function']) {
      console.warn('`modifier.function` is deprecated, use `modifier.fn`!');
    }

-   var fn = modifier.function || modifier.fn;
+   var fn = modifier['function'] || modifier.fn;
    if (modifier.enabled && isFunction(fn)) {
      data = fn(data, modifier);
    }
  });

  return data;
}

This passes the YUIcompressor.

Steps to reproduce the problem

  1. Code can be tested here: https://99webtools.com/yui-compressor.php#output

What is the expected behavior?

Minification by the YUIcompressor works without errors

What went wrong?

Javascript code contains functions named after reserved keywords.

@FezVrasta
Copy link
Member

That's a very good idea! Please may you send a PR for it?

@janwidmer
Copy link
Author

I will do that next week :-)

@FezVrasta FezVrasta added feature This would be nice to have. DIFFICULTY: low PRIORITY: low TARGETS: core Utility functions, lifecycle, core library stuff. labels Sep 30, 2017
@janwidmer
Copy link
Author

Pullrequest created: #444

janwidmer added a commit to janwidmer/popper.js that referenced this issue Oct 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This would be nice to have. PRIORITY: low TARGETS: core Utility functions, lifecycle, core library stuff.
Projects
None yet
Development

No branches or pull requests

2 participants