1
0
mirror of https://github.com/mrclay/minify.git synced 2025-08-31 01:29:56 +02:00

Improve Minify_Lines algorithm and add tests

Fixes #531
Fixes #534
This commit is contained in:
Steve Clay
2016-05-18 17:01:59 -04:00
parent de39966e9c
commit 2045731d60
9 changed files with 247 additions and 59 deletions

View File

@@ -0,0 +1,66 @@
/*! is.js
(c) 2001 Douglas Crockford
2001 June 3
*/
// is
// The -is- object is used to identify the browser. Every browser edition
// identifies itself, but there is no standard way of doing it, and some of
// the identification is deceptive. This is because the authors of web
// browsers are liars. For example, Microsoft's IE browsers claim to be
// Mozilla 4. Netscape 6 claims to be version 5.
var is = {
ie: navigator.appName == 'Microsoft Internet Explorer',
java: navigator.javaEnabled(),
ns: navigator.appName == 'Netscape',
ua: navigator.userAgent.toLowerCase(),
version: parseFloat(navigator.appVersion.substr(21)) ||
parseFloat(navigator.appVersion),
win: navigator.platform == 'Win32'
}
/*!*
* preserve this comment, too
*/
is.mac = is.ua.indexOf('mac') >= 0;
if (is.ua.indexOf('opera') >= 0) {
is.ie = is.ns = false;
is.opera = true;
}
if (is.ua.indexOf('gecko') >= 0) {
is.ie = is.ns = false;
is.gecko = true;
}
/*@cc_on
/*@if (@_win32)
if (is.ie && is.win)
document.write("PASS: IE/win honored conditional comment.<br>");
@else @*/
if (is.ie && is.win)
document.write("FAIL: IE/win did not honor multi-line conditional comment.<br>");
else
document.write("PASS: Non-IE/win browser ignores multi-line conditional comment.<br>");
/*@end
@*/
var recognizesCondComm = true;
//@cc_on/*
recognizesCondComm = false;
//@cc_on*/
if ((is.ie && is.win) == recognizesCondComm)
document.write("PASS: IE/win honored single-line conditional comment.<br>");
else
document.write("FAIL: Non-IE/win browser did not ignore single-line conditional comment.<br>");
// hello
//@cc_on/*
// world
//@cc_on*/
//@cc_on/*
'hello';
/*!* preserved */
/*!* preserved */

View File

@@ -0,0 +1,72 @@
/* basic.in.js */
/* 1 */ /*! is.js
/* 2 *|
/* 3 *| (c) 2001 Douglas Crockford
/* 4 *| 2001 June 3
/* 5 *| */
/* 6 */
/* 7 */ // is
/* 8 */
/* 9 */ // The -is- object is used to identify the browser. Every browser edition
/* 10 */ // identifies itself, but there is no standard way of doing it, and some of
/* 11 */ // the identification is deceptive. This is because the authors of web
/* 12 */ // browsers are liars. For example, Microsoft's IE browsers claim to be
/* 13 */ // Mozilla 4. Netscape 6 claims to be version 5.
/* 14 */
/* 15 */ var is = {
/* 16 */ ie: navigator.appName == 'Microsoft Internet Explorer',
/* 17 */ java: navigator.javaEnabled(),
/* 18 */ ns: navigator.appName == 'Netscape',
/* 19 */ ua: navigator.userAgent.toLowerCase(),
/* 20 */ version: parseFloat(navigator.appVersion.substr(21)) ||
/* 21 */ parseFloat(navigator.appVersion),
/* 22 */ win: navigator.platform == 'Win32'
/* 23 */ }
/* 24 */ /*!*
/* 25 *| * preserve this comment, too
/* 26 *| */
/* 27 */ is.mac = is.ua.indexOf('mac') >= 0;
/* 28 */ if (is.ua.indexOf('opera') >= 0) {
/* 29 */ is.ie = is.ns = false;
/* 30 */ is.opera = true;
/* 31 */ }
/* 32 */ if (is.ua.indexOf('gecko') >= 0) {
/* 33 */ is.ie = is.ns = false;
/* 34 */ is.gecko = true;
/* 35 */ }
/* 36 */
/* 37 */ /*@cc_on
/* 38 *| /*@if (@_win32)
/* 39 *| if (is.ie && is.win)
/* 40 *| document.write("PASS: IE/win honored conditional comment.<br>");
/* 41 *| @else @*/
/* 42 */ if (is.ie && is.win)
/* 43 */ document.write("FAIL: IE/win did not honor multi-line conditional comment.<br>");
/* 44 */ else
/* 45 */ document.write("PASS: Non-IE/win browser ignores multi-line conditional comment.<br>");
/* 46 */ /*@end
/* 47 *| @*/
/* 48 */
/* 49 */ var recognizesCondComm = true;
/* 50 */ //@cc_on/*
/* basic.in.js */
/* 51 */ recognizesCondComm = false;
/* 52 */ //@cc_on*/
/* 53 */
/* 54 */ if ((is.ie && is.win) == recognizesCondComm)
/* 55 */ document.write("PASS: IE/win honored single-line conditional comment.<br>");
/* 56 */ else
/* 57 */ document.write("FAIL: Non-IE/win browser did not ignore single-line conditional comment.<br>");
/* 58 */
/* 59 */ // hello
/* 60 */ //@cc_on/*
/* 61 */ // world
/* 62 */ //@cc_on*/
/* 63 */ //@cc_on/*
/* 64 */ 'hello';
/* 65 */ /*!* preserved */
/* 66 */ /*!* preserved */

View File

@@ -0,0 +1,14 @@
// sections from Prototype 1.6.1
var xpath = ".//*[local-name()='ul' or local-name()='UL']" +
"//*[local-name()='li' or local-name()='LI']";
this.matcher = ['.//*'];
xpath = {
descendant: "//*",
child: "/*",
f: 0
};
document._getElementsByXPath('.//*' + cond, element);
// from angular 1.4.8
var URL_REGEXP = /^[a-z][a-z\d.+-]*:\/*(?:[^:@]+(?::[^@]+)?@)?(?:[^\s:/?#]+|\[[a-f\d:]+\])(?::\d+)?(?:\/[^?#]*)?(?:\?[^#]*)?(?:#.*)?$/i;

View File

@@ -0,0 +1,18 @@
/* misc.in.js */
/* 1 */ // sections from Prototype 1.6.1
/* 2 */ var xpath = ".//*[local-name()='ul' or local-name()='UL']" +
/* 3 */ "//*[local-name()='li' or local-name()='LI']";
/* 4 */ this.matcher = ['.//*'];
/* 5 */ xpath = {
/* 6 */ descendant: "//*",
/* 7 */ child: "/*",
/* 8 */ f: 0
/* 9 */ };
/* 10 */ document._getElementsByXPath('.//*' + cond, element);
/* 11 */
/* 12 */ // from angular 1.4.8
/* 13 */ var URL_REGEXP = /^[a-z][a-z\d.+-]*:\/*(?:[^:@]+(?::[^@]+)?@)?(?:[^\s:/?#]+|\[[a-f\d:]+\])(?::\d+)?(?:\/[^?#]*)?(?:\?[^#]*)?(?:#.*)?$/i;
/* 14 */
/* 15 */

View File

@@ -0,0 +1,13 @@
foo; /* http://example.com */
bar;
foo; /*
http://example.com */
bar;
foo = "http://example.com"; /* hello */
bar;
foo = "http://example.com"; /*
hello */
bar;

View File

@@ -0,0 +1,17 @@
/* url.in.js */
/* 1 */ foo; /* http://example.com */
/* 2 */ bar;
/* 3 */
/* 4 */ foo; /*
/* 5 *| http://example.com */
/* 6 */ bar;
/* 7 */
/* 8 */ foo = "http://example.com"; /* hello */
/* 9 */ bar;
/* 10 */
/* 11 */ foo = "http://example.com"; /*
/* 12 *| hello */
/* 13 */ bar;
/* 14 */