<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>tools/jsmin.py</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -9,6 +9,9 @@ are:
     This code is copyrighted by Marc Alexander Lehmann. Both are dually
     licensed under MIT and GPL2.
 
+  - JSMin JavaScript minifier, located at tools/jsmin.py.  This code is
+    copyrighted by Douglas Crockford and Baruch Even and has an MIT license.
+
   - parseUri, a URI parser, is located in lib/http.js. This is just a small
     snippit. It is copyrighted 2007 by Steven Levithan and released under an
     MIT license.</diff>
      <filename>LICENSE</filename>
    </modified>
    <modified>
      <diff>@@ -44,7 +44,7 @@ website-upload: doc
 	scp doc/* linode:~/tinyclouds/node/
 
 clean:
-	@-rm doc/node.1 doc/api.xml doc/api.html
+	@-rm -f doc/node.1 doc/api.xml doc/api.html
 	@tools/waf-light clean
 
 distclean: clean</diff>
      <filename>Makefile</filename>
    </modified>
    <modified>
      <diff>@@ -45,10 +45,19 @@ def ToCArray(lines):
   return &quot;, &quot;.join(result)
 
 
-def RemoveCommentsAndTrailingWhitespace(lines):
-  lines = re.sub(r'//.*\n', '\n', lines) # end-of-line comments
-  lines = re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', lines) # comments.
-  lines = re.sub(r'\s+\n+', '\n', lines) # trailing whitespace
+def CompressScript(lines, do_jsmin):
+  # If we're not expecting this code to be user visible, we can run it through
+  # a more aggressive minifier.
+  if do_jsmin:
+    return jsmin.jsmin(lines)
+
+  # Remove stuff from the source that we don't want to appear when
+  # people print the source code using Function.prototype.toString().
+  # Note that we could easily compress the scripts mode but don't
+  # since we want it to remain readable.
+  #lines = re.sub('//.*\n', '\n', lines) # end-of-line comments
+  #lines = re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', lines) # comments.
+  #lines = re.sub('\s+\n+', '\n', lines) # trailing whitespace
   return lines
 
 
@@ -87,22 +96,6 @@ def ParseValue(string):
     return string
 
 
-EVAL_PATTERN = re.compile(r'\beval\s*\(');
-WITH_PATTERN = re.compile(r'\bwith\s*\(');
-
-
-def Validate(lines, file):
-  lines = RemoveCommentsAndTrailingWhitespace(lines)
-  # Because of simplified context setup, eval and with is not
-  # allowed in the natives files.
-  eval_match = EVAL_PATTERN.search(lines)
-  if eval_match:
-    raise (&quot;Eval disallowed in natives: %s&quot; % file)
-  with_match = WITH_PATTERN.search(lines)
-  if with_match:
-    raise (&quot;With statements disallowed in natives: %s&quot; % file)
-
-
 def ExpandConstants(lines, constants):
   for key, value in constants.items():
     lines = lines.replace(key, str(value))
@@ -162,9 +155,9 @@ class PythonMacro:
       args.append(mapping[arg])
     return str(self.fun(*args))
 
-CONST_PATTERN = re.compile(r'^const\s+([a-zA-Z0-9_]+)\s*=\s*([^;]*);$')
-MACRO_PATTERN = re.compile(r'^macro\s+([a-zA-Z0-9_]+)\s*\(([^)]*)\)\s*=\s*([^;]*);$')
-PYTHON_MACRO_PATTERN = re.compile(r'^python\s+macro\s+([a-zA-Z0-9_]+)\s*\(([^)]*)\)\s*=\s*([^;]*);$')
+CONST_PATTERN = re.compile('^const\s+([a-zA-Z0-9_]+)\s*=\s*([^;]*);$')
+MACRO_PATTERN = re.compile('^macro\s+([a-zA-Z0-9_]+)\s*\(([^)]*)\)\s*=\s*([^;]*);$')
+PYTHON_MACRO_PATTERN = re.compile('^python\s+macro\s+([a-zA-Z0-9_]+)\s*\(([^)]*)\)\s*=\s*([^;]*);$')
 
 def ReadMacros(lines):
   constants = { }
@@ -212,7 +205,7 @@ namespace node {
 
 
 SOURCE_DECLARATION = &quot;&quot;&quot;\
-  static const char %(id)s[] = { %(data)s };
+  static const char native_%(id)s[] = { %(data)s };
 &quot;&quot;&quot;
 
 
@@ -230,7 +223,7 @@ GET_DELAY_SCRIPT_NAME_CASE = &quot;&quot;&quot;\
     if (index == %(i)i) return Vector&lt;const char&gt;(&quot;%(name)s&quot;, %(length)i);
 &quot;&quot;&quot;
 
-def JS2C(source, target, env):
+def JS2C(source, target):
   ids = []
   delay_ids = []
   modules = []
@@ -245,20 +238,16 @@ def JS2C(source, target, env):
 
   # Build source code lines
   source_lines = [ ]
-
-  minifier = jsmin.JavaScriptMinifier()
-
   source_lines_empty = []
-  for module in modules:
-    filename = str(module)
-    delay = filename.endswith('-delay.js')
-    lines = ReadFile(filename)
+  for s in modules:
+    delay = str(s).endswith('-delay.js')
+    lines = ReadFile(str(s))
+    do_jsmin = lines.find('// jsminify this file, js2c: jsmin') != -1
     lines = ExpandConstants(lines, consts)
     lines = ExpandMacros(lines, macros)
-    Validate(lines, filename)
-    lines = minifier.JSMinify(lines)
+    lines = CompressScript(lines, do_jsmin)
     data = ToCArray(lines)
-    id = (os.path.split(filename)[1])[:-3]
+    id = (os.path.split(str(s))[1])[:-3]
     if delay: id = id[:-6]
     if delay:
       delay_ids.append((id, len(lines)))
@@ -266,7 +255,7 @@ def JS2C(source, target, env):
       ids.append((id, len(lines)))
     source_lines.append(SOURCE_DECLARATION % { 'id': id, 'data': data })
     source_lines_empty.append(SOURCE_DECLARATION % { 'id': id, 'data': 0 })
-
+  
   # Build delay support functions
   get_index_cases = [ ]
   get_script_source_cases = [ ]
@@ -311,8 +300,7 @@ def JS2C(source, target, env):
     'source_lines': &quot;\n&quot;.join(source_lines),
     'get_index_cases': &quot;&quot;.join(get_index_cases),
     'get_script_source_cases': &quot;&quot;.join(get_script_source_cases),
-    'get_script_name_cases': &quot;&quot;.join(get_script_name_cases),
-    'type': env['TYPE']
+    'get_script_name_cases': &quot;&quot;.join(get_script_name_cases)
   })
   output.close()
 
@@ -324,17 +312,6 @@ def JS2C(source, target, env):
       'source_lines': &quot;\n&quot;.join(source_lines_empty),
       'get_index_cases': &quot;&quot;.join(get_index_cases),
       'get_script_source_cases': &quot;&quot;.join(get_script_source_cases),
-      'get_script_name_cases': &quot;&quot;.join(get_script_name_cases),
-      'type': env['TYPE']
+      'get_script_name_cases': &quot;&quot;.join(get_script_name_cases)
     })
     output.close()
-
-def main():
-  natives = sys.argv[1]
-  natives_empty = sys.argv[2]
-  type = sys.argv[3]
-  source_files = sys.argv[4:]
-  JS2C(source_files, [natives, natives_empty], { 'TYPE': type })
-
-if __name__ == &quot;__main__&quot;:
-  main()</diff>
      <filename>tools/js2c.py</filename>
    </modified>
  </modified>
  <removed type="array">
    <removed>
      <filename>tools/jsmin.py</filename>
    </removed>
  </removed>
  <parents type="array">
    <parent>
      <id>e982349b169d35cecb5219de3020ce728f72ad4a</id>
    </parent>
  </parents>
  <author>
    <name>Ryan Dahl</name>
    <email>ry@tinyclouds.org</email>
  </author>
  <url>http://github.com/ry/node/commit/be2ca1ec8084cc7f5054795b3526d924f5acab3b</url>
  <id>be2ca1ec8084cc7f5054795b3526d924f5acab3b</id>
  <committed-date>2009-10-07T06:02:42-07:00</committed-date>
  <authored-date>2009-10-07T03:56:55-07:00</authored-date>
  <message>Fix build.

- Add -f flag to rm on make clean.
- Use old jsmin - the new one seems to be broken.</message>
  <tree>91adf6318977e25b11ac90d305e6bef2c139e5ad</tree>
  <committer>
    <name>Ryan Dahl</name>
    <email>ry@tinyclouds.org</email>
  </committer>
</commit>
