01: /* -*- mode: Java; c-basic-offset: 2; -*- */
02:
03: /**
04: * Javascript 'Compressor'
05: *
06: * Based on Legal's JavascriptGenerator
07: *
08: * @author steele@osteele.com
09: * @author ptw@openlaszlo.org
10: * @description: JavaScript -> JavaScript translator
11: *
12: * Transform the parse tree, expanding #pragma, replacing local
13: * variables. Includes analyzing constraint functions and generating
14: * their dependencies. Leaves other transforms alone.
15: */package org.openlaszlo.sc;
16:
17: import java.io.*;
18: import java.util.*;
19:
20: import org.openlaszlo.sc.parser.*;
21:
22: public class JavascriptCompressor extends JavascriptGenerator {
23:
24: public SimpleNode compress(SimpleNode program) {
25: // Here is your opportunity to set any sort of flags you might
26: // want to to neuter translations that are not needed.
27: options.putBoolean(Compiler.ALLOW_ROOT, true);
28: return super .translate(program);
29: }
30:
31: // Don't evaluate for compression
32: Boolean evaluateCompileTimeConditional(SimpleNode node) {
33: Object value = null;
34: return (Boolean) value;
35: }
36:
37: // Don't transform super calls for compression
38: public SimpleNode visitSuperCallExpression(SimpleNode node,
39: boolean isReferenced, SimpleNode[] children) {
40: assert children.length == 3;
41: for (int i = 0, len = children.length; i < len; i++) {
42: SimpleNode child = children[i];
43: children[i] = visitExpression(child, isReferenced);
44: }
45: return node;
46: }
47:
48: }
49:
50: /**
51: * @copyright Copyright 2006-2007 Laszlo Systems, Inc. All Rights
52: * Reserved. Use is subject to license terms.
53: */
|