Search in sources :

Example 96 with Compiler

use of com.google.javascript.jscomp.Compiler in project ow by vtst.

the class ClosureBuilder method fullBuild.

// **************************************************************************
// Full build
/**
 * Perform a full build of a project.
 * @param monitor  The project monitor.  This methods reports two units of work.
 * @param project  The project to build.
 * @throws CoreException, OperationCanceledException
 */
private void fullBuild(IProgressMonitor monitor, IProject project) throws CoreException {
    monitor.subTask(messages.format("build_prepare"));
    boolean forgetIfCanceled = true;
    Compiler compiler = CompilerUtils.makeCompiler(new ErrorManagerForProjectBuild(project));
    compiler.initOptions(CompilerUtils.makeOptionsForParsingAndErrorReporting());
    try {
        File pathOfClosureBase = ClosureCompiler.getPathOfClosureBase(project);
        if (pathOfClosureBase == null) {
            monitor.worked(1);
            return;
        }
        // Create or get the project
        JSProject jsProject = ResourceProperties.getOrCreateJSProject(project);
        boolean jsProjectUpdated = updateJSProjectIfNeeded(monitor, compiler, project, jsProject);
        // Set the compilation units
        Set<IFile> files = ClosureCompiler.getJavaScriptFilesOfProject(project);
        ResourceProperties.setJavaScriptFiles(project, files);
        List<CompilableJSUnit> units = new ArrayList<CompilableJSUnit>(files.size());
        for (IFile file : files) {
            Utils.checkCancel(monitor);
            CompilableJSUnit unit = ResourceProperties.getJSUnit(file);
            if (unit == null) {
                unit = new CompilableJSUnit(jsProject, file.getLocation().toFile(), pathOfClosureBase, new CompilationUnitProviderFromEclipseIFile(file));
                ResourceProperties.setJSUnit(file, unit);
            } else {
                if (jsProjectUpdated)
                    unit.clear();
            }
            units.add(unit);
        }
        try {
            jsProject.setUnits(compiler, units);
            monitor.worked(1);
            forgetIfCanceled = false;
            compileJavaScriptFiles(monitor, project, files, false);
        } catch (CircularDependencyException e) {
            CompilerUtils.reportError(compiler, JSError.make(CIRCULAR_DEPENDENCY_ERROR, e.getMessage()));
            forgetLastBuiltState();
        }
    } catch (OperationCanceledException e) {
        if (forgetIfCanceled)
            forgetLastBuiltState();
        throw e;
    } finally {
        compiler.getErrorManager().generateReport();
    }
}
Also used : ClosureCompiler(net.vtst.ow.eclipse.js.closure.compiler.ClosureCompiler) Compiler(com.google.javascript.jscomp.Compiler) AbstractJSProject(net.vtst.ow.closure.compiler.deps.AbstractJSProject) JSProject(net.vtst.ow.closure.compiler.deps.JSProject) IFile(org.eclipse.core.resources.IFile) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) CompilableJSUnit(net.vtst.ow.closure.compiler.compile.CompilableJSUnit) IFile(org.eclipse.core.resources.IFile) File(java.io.File) CircularDependencyException(com.google.javascript.jscomp.deps.SortedDependencies.CircularDependencyException)

Example 97 with Compiler

use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.

the class IntegrationTest method testCodingConvention.

@Test
public void testCodingConvention() {
    Compiler compiler = new Compiler();
    compiler.initOptions(new CompilerOptions());
    assertThat(compiler.getCodingConvention()).isInstanceOf(ClosureCodingConvention.class);
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) Test(org.junit.Test)

Example 98 with Compiler

use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.

the class IntegrationTest method testEs6ModuleEntryPointWithSquareBracketsInFilename.

@Test
@GwtIncompatible("AbstractCommandLineRunner.getBuiltinExterns()")
public void testEs6ModuleEntryPointWithSquareBracketsInFilename() throws Exception {
    List<SourceFile> inputs = ImmutableList.of(SourceFile.fromCode("/index[0].js", "import foo from './foo.js'; foo('hello');"), SourceFile.fromCode("/foo.js", "export default (foo) => { alert(foo); }"));
    List<ModuleIdentifier> entryPoints = ImmutableList.of(ModuleIdentifier.forFile("/index[0].js"));
    CompilerOptions options = new CompilerOptions();
    CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
    options.setDependencyOptions(DependencyOptions.pruneLegacyForEntryPoints(entryPoints));
    List<SourceFile> externs = AbstractCommandLineRunner.getBuiltinExterns(options.getEnvironment());
    Compiler compiler = new Compiler();
    compiler.compile(externs, inputs, options);
    Result result = compiler.getResult();
    assertThat(result.warnings).isEmpty();
    assertThat(result.errors).isEmpty();
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) SourceFile(com.google.javascript.jscomp.SourceFile) ModuleIdentifier(com.google.javascript.jscomp.ModuleIdentifier) Result(com.google.javascript.jscomp.Result) Test(org.junit.Test) GwtIncompatible(com.google.common.annotations.GwtIncompatible)

Example 99 with Compiler

use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.

the class ClosureIntegrationTest method testCrossChunkDepCheck_inModule_withRequire.

@Test
public void testCrossChunkDepCheck_inModule_withRequire() {
    CompilerOptions options = createCompilerOptions();
    options.setClosurePass(true);
    ImmutableList<JSChunk> code = ImmutableList.copyOf(JSChunkGraphBuilder.forStar().addChunk("// base").addChunk("goog.module('goog.Foo'); /** @constructor */ exports = function() {};").addChunk("goog.module('goog.Bar'); const Foo = goog.require('goog.Foo'); new Foo();").setFilenameFormat(inputFileNamePrefix + "%s" + inputFileNameSuffix).build());
    Compiler compiler = compile(options, code);
    assertThat(compiler.getErrors()).isEmpty();
    assertThat(compiler.getWarnings()).hasSize(1);
    assertWithMessage("Unexpected error " + compiler.getWarnings().get(0)).that(DiagnosticGroups.STRICT_MODULE_DEP_CHECK.matches(compiler.getWarnings().get(0))).isTrue();
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) JSChunk(com.google.javascript.jscomp.JSChunk) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) Test(org.junit.Test)

Example 100 with Compiler

use of com.google.javascript.jscomp.Compiler in project closure-compiler by google.

the class ClosureIntegrationTest method testCrossChunkDepCheck_forProvide_withRequire.

@Test
public void testCrossChunkDepCheck_forProvide_withRequire() {
    CompilerOptions options = createCompilerOptions();
    options.setClosurePass(true);
    ImmutableList<JSChunk> code = ImmutableList.copyOf(JSChunkGraphBuilder.forStar().addChunk("// base").addChunk("goog.provide('goog.Foo');/** @constructor */ goog.Foo = function() {};").addChunk("goog.require('goog.Foo'); new goog.Foo();").setFilenameFormat(inputFileNamePrefix + "%s" + inputFileNameSuffix).build());
    Compiler compiler = compile(options, code);
    assertThat(compiler.getErrors()).isEmpty();
    assertThat(compiler.getWarnings()).hasSize(1);
    assertWithMessage("Unexpected error " + compiler.getWarnings().get(0)).that(DiagnosticGroups.STRICT_MODULE_DEP_CHECK.matches(compiler.getWarnings().get(0))).isTrue();
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) JSChunk(com.google.javascript.jscomp.JSChunk) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) Test(org.junit.Test)

Aggregations

Compiler (com.google.javascript.jscomp.Compiler)172 Test (org.junit.Test)132 Node (com.google.javascript.rhino.Node)116 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)50 SourceFile (com.google.javascript.jscomp.SourceFile)22 NodeSubject.assertNode (com.google.javascript.rhino.testing.NodeSubject.assertNode)16 NoninjectingCompiler (com.google.javascript.jscomp.testing.NoninjectingCompiler)9 TestExternsBuilder (com.google.javascript.jscomp.testing.TestExternsBuilder)8 Result (com.google.javascript.jscomp.Result)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 File (java.io.File)4 BlackHoleErrorManager (com.google.javascript.jscomp.BlackHoleErrorManager)3 JSError (com.google.javascript.jscomp.JSError)3 InputId (com.google.javascript.rhino.InputId)3 GwtIncompatible (com.google.common.annotations.GwtIncompatible)2 AbstractCompiler (com.google.javascript.jscomp.AbstractCompiler)2 CompilerInput (com.google.javascript.jscomp.CompilerInput)2 JSChunk (com.google.javascript.jscomp.JSChunk)2 JSModule (com.google.javascript.jscomp.JSModule)2