guillaumepotier / Parsley.js

Validate your forms, frontend, without writing a single line of javascript
http://parsleyjs.org
MIT License
9.04k stars 1.31k forks source link

Parsley 2.6.2 fails to minify correctly using YUI Compressor 2.4.8 #1175

Closed ducretp closed 7 years ago

ducretp commented 7 years ago

Impossible to minify Parsely.js Source (non-minified) with YUI Compressor. Other related post, same problem with Rhino https://github.com/guillaumepotier/Parsley.js/issues/1070

The part of code with problem : (when i remove this code, minify is OK)

`var requirementConverters = { string: function string(_string) { return _string; }, integer: function integer(string) { if (isNaN(string)) throw 'Requirement is not an integer: "' + string + '"'; return parseInt(string, 10); }, number: function number(string) { if (isNaN(string)) throw 'Requirement is not a number: "' + string + '"'; return parseFloat(string); }, reference: function reference(string) { // Unused for now var result = $(string); if (result.length === 0) throw 'No such reference: "' + string + '"'; return result; }, boolean: function boolean(string) { return string !== 'false'; }, object: function object(string) { return ParsleyUtils__default.deserializeValue(string); }, regexp: function regexp(_regexp) { var flags = '';

        // Test if RegExp is literal, if not, nothing to be done, otherwise, we need to isolate flags and pattern
        if (/^\/.*\/(?:[gimy]*)$/.test(_regexp)) {
            // Replace the regexp literal string with the first match group: ([gimy]*)
            // If no flag is present, this will be a blank string
            flags = _regexp.replace(/.*\/([gimy]*)$/, '$1');
            // Again, replace the regexp literal string with the first match group:
            // everything excluding the opening and closing slashes and the flags
            _regexp = _regexp.replace(new RegExp('^/(.*?)/' + flags + '$'), '$1');
        } else {
            // Anchor regexp:
            _regexp = '^' + _regexp + '$';
        }
        return new RegExp(_regexp, flags);
    }
};`

This bug is already announced and in processing? What is the best workaround?

marcandre commented 7 years ago

Looks like it was only due to the 'boolean' keyword. Fixed and released as 2.6.5