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();
}
}
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);
}
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();
}
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();
}
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();
}
Aggregations