smparkes-envjs 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/envjsrb +157 -73
- data/bin/jquery-1.3.2-test.js +11 -4
- data/lib/envjs/env.js +935 -11028
- data/lib/envjs/net/cgi.rb +94 -0
- data/lib/envjs/net/file.rb +4 -4
- data/lib/envjs/runtime.rb +80 -24
- data/test/call-load-test.js +0 -2
- data/test/firebug/errorIcon.png +0 -0
- data/test/firebug/firebug.css +209 -0
- data/test/firebug/firebug.html +23 -0
- data/test/firebug/firebug.js +672 -0
- data/test/firebug/firebugx.js +10 -0
- data/test/firebug/infoIcon.png +0 -0
- data/test/firebug/warningIcon.png +0 -0
- data/test/fixtures/html/events.html +171 -0
- data/test/fixtures/html/iframe1.html +46 -0
- data/test/fixtures/html/iframe1a.html +46 -0
- data/test/fixtures/html/iframe2.html +45 -0
- data/test/fixtures/html/iframe3.html +28 -0
- data/test/fixtures/html/iframeN.html +57 -0
- data/test/fixtures/html/malformed.html +181 -0
- data/test/fixtures/html/scope.html +81 -0
- data/test/fixtures/html/trivial.html +19 -0
- data/test/fixtures/html/with_js.html +26 -0
- data/test/fixtures/images/icon-blue.png +0 -0
- data/test/fixtures/js/external_script.js +1 -0
- data/test/fixtures/js/script.js +1 -0
- data/test/fixtures/js/script_error.js +2 -0
- data/test/html/malformed.html +1 -0
- data/test/index.html +21 -19
- data/test/{primaryTests.js → primary-tests.js} +1 -3
- data/test/{prototype.js → prototype-test.js} +0 -2
- data/test/qunit/qunit/qunit.css +0 -0
- data/test/qunit/qunit/qunit.js +2 -2
- data/test/{qunit/qunit/qunit.js.smp → specs/dist/env.spec.js} +539 -7
- data/test/specs/envjs.spec.css +46 -0
- data/test/specs/parser/html.js +31 -0
- data/test/specs/parser/spec.html +40 -0
- data/test/specs/parser/xml.js +31 -0
- data/test/specs/qunit.bdd.js +210 -0
- data/test/{qunit.smp/qunit → specs}/qunit.css +0 -0
- data/test/{qunit.smp/qunit → specs}/qunit.js +2 -2
- data/test/specs/template/spec-0.js +31 -0
- data/test/specs/template/spec-1.js +31 -0
- data/test/specs/template/spec.html +40 -0
- data/test/specs/window/css.js +23 -0
- data/test/specs/window/dialog.js +25 -0
- data/test/specs/window/document.js +23 -0
- data/test/specs/window/event.js +25 -0
- data/test/specs/window/history.js +34 -0
- data/test/specs/window/location.js +34 -0
- data/test/specs/window/navigator.js +71 -0
- data/test/specs/window/screen.js +42 -0
- data/test/specs/window/spec.html +48 -0
- data/test/specs/window/timer.js +26 -0
- data/test/specs/window/window.js +53 -0
- data/test/specs/xhr/spec.html +47 -0
- data/test/specs/xhr/xhr.js +31 -0
- data/test/test.js +10 -0
- data/test/unit/elementmembers.js +31 -0
- data/test/unit/nu.validator.js +34 -0
- data/test/unit/onload.js +1 -3
- data/test/unit/parser.js +106 -98
- data/test/unit/prototypecompat.js +2 -2
- data/test/vendor/jQuery/1.3.2/ChangeLog.txt +98 -0
- data/test/vendor/jQuery/1.3.2/GPL-LICENSE.txt +278 -0
- data/test/vendor/jQuery/1.3.2/MIT-LICENSE.txt +20 -0
- data/test/vendor/jQuery/1.3.2/Makefile +154 -0
- data/test/vendor/jQuery/1.3.2/README +67 -0
- data/test/vendor/jQuery/1.3.2/build/ant-contrib-0.6.jar +0 -0
- data/test/vendor/jQuery/1.3.2/build/build/min.js +11 -0
- data/test/vendor/jQuery/1.3.2/build/build/pack.js +19 -0
- data/test/vendor/jQuery/1.3.2/build/js/Packer.js +209 -0
- data/test/vendor/jQuery/1.3.2/build/js/ParseMaster.js +106 -0
- data/test/vendor/jQuery/1.3.2/build/js/Words.js +62 -0
- data/test/vendor/jQuery/1.3.2/build/js/base2.js +978 -0
- data/test/vendor/jQuery/1.3.2/build/js/jsmin.js +316 -0
- data/test/vendor/jQuery/1.3.2/build/js/json.js +117 -0
- data/test/vendor/jQuery/1.3.2/build/js/pack.js +316 -0
- data/test/vendor/jQuery/1.3.2/build/js/parse.js +105 -0
- data/test/vendor/jQuery/1.3.2/build/js/writeFile.js +19 -0
- data/test/vendor/jQuery/1.3.2/build/js/xml.js +25 -0
- data/test/vendor/jQuery/1.3.2/build/js.jar +0 -0
- data/test/vendor/jQuery/1.3.2/build/runtest/env.js +1 -0
- data/test/vendor/jQuery/1.3.2/build/runtest/test.js +106 -0
- data/test/vendor/jQuery/1.3.2/build/runtest/testrunner.js +197 -0
- data/test/vendor/jQuery/1.3.2/build/speed/benchmarker.css +65 -0
- data/test/vendor/jQuery/1.3.2/build/speed/benchmarker.js +181 -0
- data/test/vendor/jQuery/1.3.2/build/speed/index.html +72 -0
- data/test/vendor/jQuery/1.3.2/build/speed/jquery-basis.js +3549 -0
- data/test/vendor/jQuery/1.3.2/build/style.xsl +99 -0
- data/test/vendor/jQuery/1.3.2/build/yuicompressor-2.4.2.jar +0 -0
- data/test/vendor/jQuery/1.3.2/build.xml +123 -0
- data/test/vendor/jQuery/1.3.2/dist/jquery.js +4376 -0
- data/test/vendor/jQuery/1.3.2/reminder.txt +3 -0
- data/test/vendor/jQuery/1.3.2/src/ajax.js +541 -0
- data/test/vendor/jQuery/1.3.2/src/core.js +1255 -0
- data/test/vendor/jQuery/1.3.2/src/data.js +145 -0
- data/test/vendor/jQuery/1.3.2/src/dimensions.js +49 -0
- data/test/vendor/jQuery/1.3.2/src/event.js +684 -0
- data/test/vendor/jQuery/1.3.2/src/fx.js +407 -0
- data/test/vendor/jQuery/1.3.2/src/intro.js +13 -0
- data/test/vendor/jQuery/1.3.2/src/offset.js +155 -0
- data/test/vendor/jQuery/1.3.2/src/outro.js +1 -0
- data/test/vendor/jQuery/1.3.2/src/selector.js +1015 -0
- data/test/vendor/jQuery/1.3.2/src/support.js +112 -0
- data/test/vendor/jQuery/1.3.2/test/data/cow.jpg +0 -0
- data/test/vendor/jQuery/1.3.2/test/data/dashboard.xml +11 -0
- data/test/vendor/jQuery/1.3.2/test/data/echoQuery.php +1 -0
- data/test/vendor/jQuery/1.3.2/test/data/iframe.html +8 -0
- data/test/vendor/jQuery/1.3.2/test/data/json.php +9 -0
- data/test/vendor/jQuery/1.3.2/test/data/json_assigned_obj.js +1 -0
- data/test/vendor/jQuery/1.3.2/test/data/json_obj.js +1 -0
- data/test/vendor/jQuery/1.3.2/test/data/jsonp.php +10 -0
- data/test/vendor/jQuery/1.3.2/test/data/name.html +1 -0
- data/test/vendor/jQuery/1.3.2/test/data/name.php +29 -0
- data/test/vendor/jQuery/1.3.2/test/data/offset/absolute.html +39 -0
- data/test/vendor/jQuery/1.3.2/test/data/offset/body.html +24 -0
- data/test/vendor/jQuery/1.3.2/test/data/offset/fixed.html +33 -0
- data/test/vendor/jQuery/1.3.2/test/data/offset/relative.html +31 -0
- data/test/vendor/jQuery/1.3.2/test/data/offset/scroll.html +39 -0
- data/test/vendor/jQuery/1.3.2/test/data/offset/static.html +31 -0
- data/test/vendor/jQuery/1.3.2/test/data/offset/table.html +43 -0
- data/test/vendor/jQuery/1.3.2/test/data/params_html.php +12 -0
- data/test/vendor/jQuery/1.3.2/test/data/test.html +7 -0
- data/test/vendor/jQuery/1.3.2/test/data/test.js +3 -0
- data/test/vendor/jQuery/1.3.2/test/data/test.php +7 -0
- data/test/vendor/jQuery/1.3.2/test/data/test2.html +5 -0
- data/test/vendor/jQuery/1.3.2/test/data/test3.html +3 -0
- data/test/vendor/jQuery/1.3.2/test/data/testrunner.js +1 -0
- data/test/vendor/jQuery/1.3.2/test/data/text.php +12 -0
- data/test/vendor/jQuery/1.3.2/test/data/with_fries.xml +25 -0
- data/test/vendor/jQuery/1.3.2/test/index.html +229 -0
- data/test/vendor/jQuery/1.3.2/test/jqenv-1259090275493.html +247 -0
- data/test/vendor/jQuery/1.3.2/test/jqenv-1259091671501.html +247 -0
- data/test/vendor/jQuery/1.3.2/test/jqenv-1259175319655.html +247 -0
- data/test/vendor/jQuery/1.3.2/test/offset.html +28 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/jquery/1.2.1/jquery.js +11 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/jquery/1.2.3/jquery.js +11 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/mootools/1.11/mootools.js +1577 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/prototype/1.6.0.2/prototype.js +4221 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/builder.js +131 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/controls.js +835 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/dragdrop.js +944 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/effects.js +1090 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/scriptaculous.js +51 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/slider.js +278 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.7.0/unittest.js +564 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/builder.js +136 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/controls.js +965 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/dragdrop.js +974 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/effects.js +1122 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/scriptaculous.js +58 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/slider.js +275 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/sound.js +55 -0
- data/test/vendor/jQuery/1.3.2/test/otherlibs/scriptaculous/1.8.1/unittest.js +568 -0
- data/test/vendor/jQuery/1.3.2/test/polluted.php +64 -0
- data/test/vendor/jQuery/1.3.2/test/qunit/testrunner.js +780 -0
- data/test/vendor/jQuery/1.3.2/test/qunit/testsuite.css +120 -0
- data/test/vendor/jQuery/1.3.2/test/test.js +41 -0
- data/test/vendor/jQuery/1.3.2/test/unit/ajax.js +856 -0
- data/test/vendor/jQuery/1.3.2/test/unit/core.js +1872 -0
- data/test/vendor/jQuery/1.3.2/test/unit/data.js +160 -0
- data/test/vendor/jQuery/1.3.2/test/unit/dimensions.js +86 -0
- data/test/vendor/jQuery/1.3.2/test/unit/event.js +670 -0
- data/test/vendor/jQuery/1.3.2/test/unit/fx.js +451 -0
- data/test/vendor/jQuery/1.3.2/test/unit/offset.js +173 -0
- data/test/vendor/jQuery/1.3.2/test/unit/selector.js +395 -0
- data/test/vendor/jQuery/1.3.2/test/xhtml.php +5 -0
- data/test/vendor/jQuery/1.3.2/version.txt +1 -0
- metadata +158 -22
- data/lib/envjs/runtime.rb.smp +0 -133
- data/test/envjs-call-load-test.js +0 -5
- data/test/envjs-prototype.js +0 -5
- data/test/qunit/package.json +0 -21
- data/test/qunit/test/index.html +0 -17
- data/test/qunit/test/same.js +0 -1368
- data/test/qunit/test/test.js +0 -136
- data/test/qunit.smp/package.json +0 -21
- data/test/qunit.smp/test/index.html +0 -17
- data/test/qunit.smp/test/same.js +0 -1368
- data/test/qunit.smp/test/test.js +0 -136
- data/test/rhino-call-load-test.js +0 -5
- data/test/rhino-prototype.js +0 -5
- data/test/test-with-envs-jar.js +0 -8
- data/test/test-with-rhino-jar.js +0 -9
@@ -0,0 +1,209 @@
|
|
1
|
+
/*
|
2
|
+
Packer version 3.0 (beta 8) - copyright 2004-2007, Dean Edwards
|
3
|
+
http://www.opensource.org/licenses/mit-license
|
4
|
+
*/
|
5
|
+
|
6
|
+
eval(base2.namespace);
|
7
|
+
|
8
|
+
var IGNORE = RegGrp.IGNORE;
|
9
|
+
var REMOVE = "";
|
10
|
+
var SPACE = " ";
|
11
|
+
var WORDS = /\w+/g;
|
12
|
+
|
13
|
+
var Packer = Base.extend({
|
14
|
+
minify: function(script) {
|
15
|
+
script = script.replace(Packer.CONTINUE, "");
|
16
|
+
script = Packer.data.exec(script);
|
17
|
+
script = Packer.whitespace.exec(script);
|
18
|
+
script = Packer.clean.exec(script);
|
19
|
+
return script;
|
20
|
+
},
|
21
|
+
|
22
|
+
pack: function(script, base62, shrink) {
|
23
|
+
script = this.minify(script + "\n");
|
24
|
+
if (shrink) script = this._shrinkVariables(script);
|
25
|
+
if (base62) script = this._base62Encode(script);
|
26
|
+
return script;
|
27
|
+
},
|
28
|
+
|
29
|
+
_base62Encode: function(script) {
|
30
|
+
var words = new Words(script);
|
31
|
+
var encode = function(word) {
|
32
|
+
return words.fetch(word).encoded;
|
33
|
+
};
|
34
|
+
|
35
|
+
/* build the packed script */
|
36
|
+
|
37
|
+
var p = this._escape(script.replace(WORDS, encode));
|
38
|
+
var a = Math.min(Math.max(words.count(), 2), 62);
|
39
|
+
var c = words.count();
|
40
|
+
var k = words;
|
41
|
+
var e = Packer["ENCODE" + (a > 10 ? a > 36 ? 62 : 36 : 10)];
|
42
|
+
var r = a > 10 ? "e(c)" : "c";
|
43
|
+
|
44
|
+
// the whole thing
|
45
|
+
return format(Packer.UNPACK, p,a,c,k,e,r);
|
46
|
+
},
|
47
|
+
|
48
|
+
_escape: function(script) {
|
49
|
+
// single quotes wrap the final string so escape them
|
50
|
+
// also escape new lines required by conditional comments
|
51
|
+
return script.replace(/([\\'])/g, "\\$1").replace(/[\r\n]+/g, "\\n");
|
52
|
+
},
|
53
|
+
|
54
|
+
_shrinkVariables: function(script) {
|
55
|
+
// Windows Scripting Host cannot do regexp.test() on global regexps.
|
56
|
+
var global = function(regexp) {
|
57
|
+
// This function creates a global version of the passed regexp.
|
58
|
+
return new RegExp(regexp.source, "g");
|
59
|
+
};
|
60
|
+
|
61
|
+
var data = []; // encoded strings and regular expressions
|
62
|
+
var REGEXP = /^[^'"]\//;
|
63
|
+
var store = function(string) {
|
64
|
+
var replacement = "#" + data.length;
|
65
|
+
if (REGEXP.test(string)) {
|
66
|
+
replacement = string.charAt(0) + replacement;
|
67
|
+
string = string.slice(1);
|
68
|
+
}
|
69
|
+
data.push(string);
|
70
|
+
return replacement;
|
71
|
+
};
|
72
|
+
|
73
|
+
// Base52 encoding (a-Z)
|
74
|
+
var encode52 = function(c) {
|
75
|
+
return (c < 52 ? '' : arguments.callee(parseInt(c / 52))) +
|
76
|
+
((c = c % 52) > 25 ? String.fromCharCode(c + 39) : String.fromCharCode(c + 97));
|
77
|
+
};
|
78
|
+
|
79
|
+
// identify blocks, particularly identify function blocks (which define scope)
|
80
|
+
var BLOCK = /(function\s*[\w$]*\s*\(\s*([^\)]*)\s*\)\s*)?(\{([^{}]*)\})/;
|
81
|
+
var VAR_ = /var\s+/g;
|
82
|
+
var VAR_NAME = /var\s+[\w$]+/g;
|
83
|
+
var COMMA = /\s*,\s*/;
|
84
|
+
var blocks = []; // store program blocks (anything between braces {})
|
85
|
+
// encoder for program blocks
|
86
|
+
var encode = function(block, func, args) {
|
87
|
+
if (func) { // the block is a function block
|
88
|
+
|
89
|
+
// decode the function block (THIS IS THE IMPORTANT BIT)
|
90
|
+
// We are retrieving all sub-blocks and will re-parse them in light
|
91
|
+
// of newly shrunk variables
|
92
|
+
block = decode(block);
|
93
|
+
|
94
|
+
// create the list of variable and argument names
|
95
|
+
var vars = match(block, VAR_NAME).join(",").replace(VAR_, "");
|
96
|
+
var ids = Array2.combine(args.split(COMMA).concat(vars.split(COMMA)));
|
97
|
+
|
98
|
+
// process each identifier
|
99
|
+
var count = 0, shortId;
|
100
|
+
forEach (ids, function(id) {
|
101
|
+
id = trim(id);
|
102
|
+
if (id && id.length > 1) { // > 1 char
|
103
|
+
id = rescape(id);
|
104
|
+
// find the next free short name (check everything in the current scope)
|
105
|
+
do shortId = encode52(count++);
|
106
|
+
while (new RegExp("[^\\w$.]" + shortId + "[^\\w$:]").test(block));
|
107
|
+
// replace the long name with the short name
|
108
|
+
var reg = new RegExp("([^\\w$.])" + id + "([^\\w$:])");
|
109
|
+
while (reg.test(block)) block = block.replace(global(reg), "$1" + shortId + "$2");
|
110
|
+
var reg = new RegExp("([^{,])" + id + ":", "g");
|
111
|
+
block = block.replace(reg, "$1" + shortId + ":");
|
112
|
+
}
|
113
|
+
});
|
114
|
+
}
|
115
|
+
var replacement = "~" + blocks.length + "~";
|
116
|
+
blocks.push(block);
|
117
|
+
return replacement;
|
118
|
+
};
|
119
|
+
|
120
|
+
// decoder for program blocks
|
121
|
+
var ENCODED = /~(\d+)~/;
|
122
|
+
var decode = function(script) {
|
123
|
+
while (ENCODED.test(script)) {
|
124
|
+
script = script.replace(global(ENCODED), function(match, index) {
|
125
|
+
return blocks[index];
|
126
|
+
});
|
127
|
+
}
|
128
|
+
return script;
|
129
|
+
};
|
130
|
+
|
131
|
+
// encode strings and regular expressions
|
132
|
+
script = Packer.data.exec(script, store);
|
133
|
+
|
134
|
+
// remove closures (this is for base2 namespaces only)
|
135
|
+
script = script.replace(/new function\(_\)\s*\{/g, "{;#;");
|
136
|
+
|
137
|
+
// encode blocks, as we encode we replace variable and argument names
|
138
|
+
while (BLOCK.test(script)) {
|
139
|
+
script = script.replace(global(BLOCK), encode);
|
140
|
+
}
|
141
|
+
|
142
|
+
// put the blocks back
|
143
|
+
script = decode(script);
|
144
|
+
|
145
|
+
// put back the closure (for base2 namespaces only)
|
146
|
+
script = script.replace(/\{;#;/g, "new function(_){");
|
147
|
+
|
148
|
+
// put strings and regular expressions back
|
149
|
+
script = script.replace(/#(\d+)/g, function(match, index) {
|
150
|
+
return data[index];
|
151
|
+
});
|
152
|
+
|
153
|
+
return script;
|
154
|
+
}
|
155
|
+
}, {
|
156
|
+
CONTINUE: /\\\r?\n/g,
|
157
|
+
|
158
|
+
ENCODE10: "String",
|
159
|
+
ENCODE36: "function(c){return c.toString(a)}",
|
160
|
+
ENCODE62: "function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))}",
|
161
|
+
|
162
|
+
UNPACK: "eval(function(p,a,c,k,e,r){e=%5;if(!''.replace(/^/,String)){while(c--)r[%6]=k[c]" +
|
163
|
+
"||%6;k=[function(e){return r[e]}];e=function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p." +
|
164
|
+
"replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('%1',%2,%3,'%4'.split('|'),0,{}))",
|
165
|
+
|
166
|
+
init: function() {
|
167
|
+
this.data = reduce(this.data, function(data, replacement, expression) {
|
168
|
+
data.store(this.javascript.exec(expression), replacement);
|
169
|
+
return data;
|
170
|
+
}, new RegGrp, this);
|
171
|
+
this.clean = this.data.union(this.clean);
|
172
|
+
this.whitespace = this.data.union(this.whitespace);
|
173
|
+
},
|
174
|
+
|
175
|
+
clean: {
|
176
|
+
"\\(\\s*;\\s*;\\s*\\)": "(;;)", // for (;;) loops
|
177
|
+
"throw[^};]+[};]": IGNORE, // a safari 1.3 bug
|
178
|
+
";+\\s*([};])": "$1"
|
179
|
+
},
|
180
|
+
|
181
|
+
data: {
|
182
|
+
// strings
|
183
|
+
"STRING1": IGNORE,
|
184
|
+
'STRING2': IGNORE,
|
185
|
+
"CONDITIONAL": IGNORE, // conditional comments
|
186
|
+
"(COMMENT1)\\n\\s*(REGEXP)?": "\n$3",
|
187
|
+
"(COMMENT2)\\s*(REGEXP)?": " $3",
|
188
|
+
"([\\[(\\^=,{}:;&|!*?])\\s*(REGEXP)": "$1$2"
|
189
|
+
},
|
190
|
+
|
191
|
+
javascript: new RegGrp({
|
192
|
+
COMMENT1: /(\/\/|;;;)[^\n]*/.source,
|
193
|
+
COMMENT2: /\/\*[^*]*\*+([^\/][^*]*\*+)*\//.source,
|
194
|
+
CONDITIONAL: /\/\*@|@\*\/|\/\/@[^\n]*\n/.source,
|
195
|
+
REGEXP: /\/(\\[\/\\]|[^*\/])(\\.|[^\/\n\\])*\/[gim]*/.source,
|
196
|
+
STRING1: /'(\\.|[^'\\])*'/.source,
|
197
|
+
STRING2: /"(\\.|[^"\\])*"/.source
|
198
|
+
}),
|
199
|
+
|
200
|
+
whitespace: {
|
201
|
+
"(\\d)\\s+(\\.\\s*[a-z\\$_\\[(])": "$1 $2", // http://dean.edwards.name/weblog/2007/04/packer3/#comment84066
|
202
|
+
"([+-])\\s+([+-])": "$1 $2", // c = a++ +b;
|
203
|
+
"\\b\\s+\\$\\s+\\b": " $ ", // var $ in
|
204
|
+
"\\$\\s+\\b": "$ ", // object$ in
|
205
|
+
"\\b\\s+\\$": " $", // return $object
|
206
|
+
"\\b\\s+\\b": SPACE,
|
207
|
+
"\\s+": REMOVE
|
208
|
+
}
|
209
|
+
});
|
@@ -0,0 +1,106 @@
|
|
1
|
+
/*
|
2
|
+
ParseMaster, version 1.0.2 (2005-08-19)
|
3
|
+
Copyright 2005, Dean Edwards
|
4
|
+
License: http://creativecommons.org/licenses/LGPL/2.1/
|
5
|
+
*/
|
6
|
+
|
7
|
+
/* a multi-pattern parser */
|
8
|
+
|
9
|
+
// KNOWN BUG: erroneous behavior when using escapeChar with a replacement value that is a function
|
10
|
+
|
11
|
+
function ParseMaster() {
|
12
|
+
// constants
|
13
|
+
var $EXPRESSION = 0, $REPLACEMENT = 1, $LENGTH = 2;
|
14
|
+
// used to determine nesting levels
|
15
|
+
var $GROUPS = /\(/g, $SUB_REPLACE = /\$\d/, $INDEXED = /^\$\d+$/,
|
16
|
+
$TRIM = /(['"])\1\+(.*)\+\1\1$/, $$ESCAPE = /\\./g, $QUOTE = /'/,
|
17
|
+
$$DELETED = /\x01[^\x01]*\x01/g;
|
18
|
+
var self = this;
|
19
|
+
// public
|
20
|
+
this.add = function($expression, $replacement) {
|
21
|
+
if (!$replacement) $replacement = "";
|
22
|
+
// count the number of sub-expressions
|
23
|
+
// - add one because each pattern is itself a sub-expression
|
24
|
+
var $length = (_internalEscape(String($expression)).match($GROUPS) || "").length + 1;
|
25
|
+
// does the pattern deal with sub-expressions?
|
26
|
+
if ($SUB_REPLACE.test($replacement)) {
|
27
|
+
// a simple lookup? (e.g. "$2")
|
28
|
+
if ($INDEXED.test($replacement)) {
|
29
|
+
// store the index (used for fast retrieval of matched strings)
|
30
|
+
$replacement = parseInt($replacement.slice(1)) - 1;
|
31
|
+
} else { // a complicated lookup (e.g. "Hello $2 $1")
|
32
|
+
// build a function to do the lookup
|
33
|
+
var i = $length;
|
34
|
+
var $quote = $QUOTE.test(_internalEscape($replacement)) ? '"' : "'";
|
35
|
+
while (i) $replacement = $replacement.split("$" + i--).join($quote + "+a[o+" + i + "]+" + $quote);
|
36
|
+
$replacement = new Function("a,o", "return" + $quote + $replacement.replace($TRIM, "$1") + $quote);
|
37
|
+
}
|
38
|
+
}
|
39
|
+
// pass the modified arguments
|
40
|
+
_add($expression || "/^$/", $replacement, $length);
|
41
|
+
};
|
42
|
+
// execute the global replacement
|
43
|
+
this.exec = function($string) {
|
44
|
+
_escaped.length = 0;
|
45
|
+
return _unescape(_escape($string, this.escapeChar).replace(
|
46
|
+
new RegExp(_patterns, this.ignoreCase ? "gi" : "g"), _replacement), this.escapeChar).replace($$DELETED, "");
|
47
|
+
};
|
48
|
+
// clear the patterns collection so that this object may be re-used
|
49
|
+
this.reset = function() {
|
50
|
+
_patterns.length = 0;
|
51
|
+
};
|
52
|
+
|
53
|
+
// private
|
54
|
+
var _escaped = []; // escaped characters
|
55
|
+
var _patterns = []; // patterns stored by index
|
56
|
+
var _toString = function(){return "(" + String(this[$EXPRESSION]).slice(1, -1) + ")"};
|
57
|
+
_patterns.toString = function(){return this.join("|")};
|
58
|
+
// create and add a new pattern to the patterns collection
|
59
|
+
function _add() {
|
60
|
+
arguments.toString = _toString;
|
61
|
+
// store the pattern - as an arguments object (i think this is quicker..?)
|
62
|
+
_patterns[_patterns.length] = arguments;
|
63
|
+
}
|
64
|
+
// this is the global replace function (it's quite complicated)
|
65
|
+
function _replacement() {
|
66
|
+
if (!arguments[0]) return "";
|
67
|
+
var i = 1, j = 0, $pattern;
|
68
|
+
// loop through the patterns
|
69
|
+
while ($pattern = _patterns[j++]) {
|
70
|
+
// do we have a result?
|
71
|
+
if (arguments[i]) {
|
72
|
+
var $replacement = $pattern[$REPLACEMENT];
|
73
|
+
switch (typeof $replacement) {
|
74
|
+
case "function": return $replacement(arguments, i);
|
75
|
+
case "number": return arguments[$replacement + i];
|
76
|
+
}
|
77
|
+
var $delete = (arguments[i].indexOf(self.escapeChar) == -1) ? "" :
|
78
|
+
"\x01" + arguments[i] + "\x01";
|
79
|
+
return $delete + $replacement;
|
80
|
+
// skip over references to sub-expressions
|
81
|
+
} else i += $pattern[$LENGTH];
|
82
|
+
}
|
83
|
+
};
|
84
|
+
// encode escaped characters
|
85
|
+
function _escape($string, $escapeChar) {
|
86
|
+
return $escapeChar ? $string.replace(new RegExp("\\" + $escapeChar + "(.)", "g"), function($match, $char) {
|
87
|
+
_escaped[_escaped.length] = $char;
|
88
|
+
return $escapeChar;
|
89
|
+
}) : $string;
|
90
|
+
};
|
91
|
+
// decode escaped characters
|
92
|
+
function _unescape($string, $escapeChar) {
|
93
|
+
var i = 0;
|
94
|
+
return $escapeChar ? $string.replace(new RegExp("\\" + $escapeChar, "g"), function() {
|
95
|
+
return $escapeChar + (_escaped[i++] || "");
|
96
|
+
}) : $string;
|
97
|
+
};
|
98
|
+
function _internalEscape($string) {
|
99
|
+
return $string.replace($$ESCAPE, "");
|
100
|
+
};
|
101
|
+
};
|
102
|
+
ParseMaster.prototype = {
|
103
|
+
constructor: ParseMaster,
|
104
|
+
ignoreCase: false,
|
105
|
+
escapeChar: ""
|
106
|
+
};
|
@@ -0,0 +1,62 @@
|
|
1
|
+
|
2
|
+
var Words = Collection.extend({
|
3
|
+
constructor: function(script) {
|
4
|
+
this.base();
|
5
|
+
forEach (script.match(WORDS), this.add, this);
|
6
|
+
this.encode();
|
7
|
+
},
|
8
|
+
|
9
|
+
add: function(word) {
|
10
|
+
if (!this.exists(word)) this.base(word);
|
11
|
+
word = this.fetch(word);
|
12
|
+
word.count++;
|
13
|
+
return word;
|
14
|
+
},
|
15
|
+
|
16
|
+
encode: function() {
|
17
|
+
// sort by frequency
|
18
|
+
this.sort(function(word1, word2) {
|
19
|
+
return word2.count - word1.count;
|
20
|
+
});
|
21
|
+
|
22
|
+
eval("var a=62,e=" + Packer.ENCODE62);
|
23
|
+
var encode = e;
|
24
|
+
var encoded = new Collection; // a dictionary of base62 -> base10
|
25
|
+
var count = this.count();
|
26
|
+
for (var i = 0; i < count; i++) {
|
27
|
+
encoded.store(encode(i), i);
|
28
|
+
}
|
29
|
+
|
30
|
+
var empty = function() {return ""};
|
31
|
+
var index = 0;
|
32
|
+
forEach (this, function(word) {
|
33
|
+
if (encoded.exists(word)) {
|
34
|
+
word.index = encoded.fetch(word);
|
35
|
+
word.toString = empty;
|
36
|
+
} else {
|
37
|
+
while (this.exists(encode(index))) index++;
|
38
|
+
word.index = index++;
|
39
|
+
}
|
40
|
+
word.encoded = encode(word.index);
|
41
|
+
}, this);
|
42
|
+
|
43
|
+
// sort by encoding
|
44
|
+
this.sort(function(word1, word2) {
|
45
|
+
return word1.index - word2.index;
|
46
|
+
});
|
47
|
+
},
|
48
|
+
|
49
|
+
toString: function() {
|
50
|
+
return this.values().join("|");
|
51
|
+
}
|
52
|
+
}, {
|
53
|
+
Item: {
|
54
|
+
constructor: function(word) {
|
55
|
+
this.toString = function() {return word};
|
56
|
+
},
|
57
|
+
|
58
|
+
count: 0,
|
59
|
+
encoded: "",
|
60
|
+
index: -1
|
61
|
+
}
|
62
|
+
});
|