Package org.mozilla.javascript

Examples of org.mozilla.javascript.CompilerEnvirons


import java.io.StringReader;

//https://bugzilla.mozilla.org/show_bug.cgi?id=788070
public class Bug788070 implements NodeVisitor {
    public static void main(String[] args) throws IOException {
        CompilerEnvirons compilerEnv = new CompilerEnvirons();
        compilerEnv.setLanguageVersion(180);
        compilerEnv.setStrictMode(false);

        Bug788070 visitor = new Bug788070();
        addIncrement(new Parser(compilerEnv), visitor, "switch (x) {\n" +
                "case x:\n" +
                "  y = 0;\n" +
View Full Code Here


    private static IoUtils ioUtils = IoUtils.getInstance();

    public static void main(String args[]) throws Exception {
        String source = ioUtils.loadFromClassPath("/test.js");
//        String source = "let ({x: x0, y: y0} = point) {\n  print(x0);\n  print(y0);\n}";
        CompilerEnvirons compilerEnv = new CompilerEnvirons();
        compilerEnv.setLanguageVersion(180);
        Parser parser = new Parser(compilerEnv);
        AstRoot astRoot = parser.parse(new StringReader(source), null, 1);
        astRoot.visitAll(new InstrumentVisitor());
        System.out.println(astRoot.toSource());
//        System.out.println("****************************");
 
View Full Code Here

//        parseAndPrintSource("/^(\\w+)$/.exec(url);");
        //parseAndPrintSource("if (true)\n  ;\nx++;");
    }

    private static void parseAndPrintSource(String source) throws IOException {
        CompilerEnvirons compilerEnv = new CompilerEnvirons();
        compilerEnv.setLanguageVersion(180);
//        compilerEnv.setStrictMode(false);
        Parser parser = new Parser(compilerEnv);
        AstRoot astRoot = parser.parse(new StringReader(source), null, 1);
        System.out.println(astRoot.toSource());
    }
View Full Code Here

import java.io.StringReader;

//https://bugzilla.mozilla.org/show_bug.cgi?id=784651
public class Bug784651 implements NodeVisitor {
    public static void main(String[] args) throws IOException {
        CompilerEnvirons compilerEnv = new CompilerEnvirons();
        compilerEnv.setLanguageVersion(180);
        compilerEnv.setStrictMode(false);

        Bug784651 visitor = new Bug784651();
        addIncrement(new Parser(compilerEnv), visitor, "while (x)\n{\n  ;\n}");
        System.err.println("*************************");
        addIncrement(new Parser(compilerEnv), visitor, "while (x)\n  ;");
View Full Code Here

        }


        private Class compileClass( final Context pContext, final String pSourceName, final String pClassName, final Class pSuperClass, final Class[] pInterfaces) throws IOException {

            final CompilerEnvirons environments = new CompilerEnvirons();
            environments.initFromContext(pContext);
            final ClassCompiler compiler = new ClassCompiler(environments);

            if (pSuperClass != null) {
                compiler.setTargetExtends(pSuperClass);
            }
View Full Code Here

    public static final String compressScript(String source, int indent, int lineno, boolean escapeUnicode, String stripConsole) {
      return compressScript(source, indent, lineno, escapeUnicode, stripConsole, null);
    }
       
    public static final String compressScript(String source, int indent, int lineno, boolean escapeUnicode, String stripConsole, StringBuffer debugData) {
        CompilerEnvirons compilerEnv = new CompilerEnvirons();

        Parser parser = new Parser(compilerEnv, compilerEnv.getErrorReporter());
       
        ScriptOrFnNode tree = parser.parse(source, null, lineno);
        String encodedSource = parser.getEncodedSource();
        if (encodedSource.length() == 0) { return ""; }
       
View Full Code Here

  public ScriptOrFnNode parse() throws IOException {

    if (nodeTree == null) {
      Reader reader = new FileReader(jsFile);

      CompilerEnvirons compilerEnv = new CompilerEnvirons();
      ErrorReporter errorReporter = compilerEnv.getErrorReporter();

      Parser parser = new Parser(compilerEnv, errorReporter);

      String sourceURI;
View Full Code Here

    public static final String compressScript(String source, int indent, int lineno, boolean escapeUnicode, String stripConsole) {
      return compressScript(source, indent, lineno, escapeUnicode, stripConsole, null);
    }
       
    public static final String compressScript(String source, int indent, int lineno, boolean escapeUnicode, String stripConsole, StringBuffer debugData) {
        CompilerEnvirons compilerEnv = new CompilerEnvirons();

        Parser parser = new Parser(compilerEnv, compilerEnv.getErrorReporter());
       
        ScriptOrFnNode tree = parser.parse(source, null, lineno);
        String encodedSource = parser.getEncodedSource();
        if (encodedSource.length() == 0) { return ""; }
       
View Full Code Here

      compiler = new Codegen();
    }
    FileReader in = new FileReader(new File(baseDir, file));
    try {
      if (compilerEnv == null) {
        compilerEnv = new CompilerEnvirons();
        compilerEnv.initFromContext(cx);
        compilerEnv.setOptimizationLevel(1);
        compilerEnv.setGeneratingSource(false);
      }
      if (compilationErrorReporter == null) {
View Full Code Here

         */
        protected ScriptNode compile(CharSequence source) {
            final String mainMethodClassName = "Main";
            final String scriptClassName = "Main";

            CompilerEnvirons compilerEnv = new CompilerEnvirons();
            compilerEnv.initFromContext(cx);
            ErrorReporter compilationErrorReporter = compilerEnv
                    .getErrorReporter();
            Parser p = new Parser(compilerEnv, compilationErrorReporter);
            AstRoot ast = p.parse(source.toString(), "<eval>", 1);
            IRFactory irf = new IRFactory(compilerEnv);
            ScriptNode tree = irf.transformTree(ast);
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.CompilerEnvirons

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.