use of com.google.javascript.jscomp.SourceFile in project closure-compiler by google.
the class DepsGeneratorTest method testDuplicateProvidesSameFile.
public void testDuplicateProvidesSameFile() throws Exception {
SourceFile dep1 = SourceFile.fromCode("dep1.js", "goog.addDependency('a.js', ['a'], []);\n");
SourceFile src1 = SourceFile.fromCode("src1.js", LINE_JOINER.join("goog.provide('b');", "goog.provide('b');\n"));
doErrorMessagesRun(ImmutableList.of(dep1), ImmutableList.of(src1), false, /* fatal */
"Multiple calls to goog.provide(\"b\")");
}
use of com.google.javascript.jscomp.SourceFile in project closure-compiler by google.
the class DepsGeneratorTest method testDuplicateProvidesErrorThrownIfBadClosurePathSpecified.
/**
* Ensures that an error is thrown when the closure_path flag is set incorrectly.
*/
public void testDuplicateProvidesErrorThrownIfBadClosurePathSpecified() throws Exception {
// Create a stub Closure Library.
SourceFile fauxClosureDeps = SourceFile.fromCode("dep1.js", "goog.addDependency('foo/a.js', ['a'], []);\n");
SourceFile fauxClosureSrc = SourceFile.fromCode("path/to/closure/foo/a.js", "goog.provide('a');\n");
// Create a source file that depends on the stub Closure Library.
SourceFile userSrc = SourceFile.fromCode("my/package/script.js", "goog.require('a');\n" + "goog.provide('my.package.script');\n");
// doErrorMessagesRun uses closure_path //javascript/closure and therefore
// fails to recognize and de-dupe the stub Closure Library at
// //path/to/closure.
doErrorMessagesRun(ImmutableList.of(fauxClosureDeps), ImmutableList.of(fauxClosureSrc, userSrc), true, /* fatal */
"Namespace \"a\" is already provided in other file dep1.js");
}
use of com.google.javascript.jscomp.SourceFile in project ow by vtst.
the class ClosureCompilerLaunchConfigurationDelegate method getExterns.
private List<SourceFile> getExterns(AbstractCompiler compiler, IProgressMonitor monitor, IReadOnlyStore store) throws CoreException {
List<JSExtern> externs = includesProvider.getExterns(compiler, monitor, store);
List<SourceFile> sourceFiles = new ArrayList<SourceFile>(externs.size());
for (JSExtern extern : externs) sourceFiles.add(extern.getSourceFile());
return sourceFiles;
}
use of com.google.javascript.jscomp.SourceFile in project closure-compiler by google.
the class DepsGenerator method parseSources.
/**
* Parses all source files for dependency information.
* @param preparsedFiles A set of closure-relative paths.
* Files in this set are not parsed if they are encountered in srcs.
* @return Returns a map of closure-relative paths -> DependencyInfo for the
* newly parsed files.
* @throws IOException Occurs upon an IO error.
*/
private Map<String, DependencyInfo> parseSources(Set<String> preparsedFiles) throws IOException {
Map<String, DependencyInfo> parsedFiles = new LinkedHashMap<>();
JsFileParser jsParser = new JsFileParser(errorManager).setModuleLoader(loader);
Compiler compiler = new Compiler();
compiler.init(ImmutableList.of(), ImmutableList.of(), new CompilerOptions());
for (SourceFile file : srcs) {
String closureRelativePath = PathUtil.makeRelative(closurePathAbs, PathUtil.makeAbsolute(file.getName()));
if (logger.isLoggable(Level.FINE)) {
logger.fine("Closure-relative path: " + closureRelativePath);
}
if (InclusionStrategy.WHEN_IN_SRCS == mergeStrategy || !preparsedFiles.contains(closureRelativePath)) {
DependencyInfo depInfo = jsParser.parseFile(file.getName(), closureRelativePath, file.getCode());
depInfo = new LazyParsedDependencyInfo(depInfo, new JsAst(file), compiler);
// Kick the source out of memory.
file.clearCachedSource();
parsedFiles.put(closureRelativePath, depInfo);
}
}
return parsedFiles;
}
use of com.google.javascript.jscomp.SourceFile in project closure-compiler by google.
the class DepsGenerator method parseDepsFiles.
/**
* Parses all deps.js files in the deps list and creates a map of
* closure-relative path -> DependencyInfo.
*/
private Map<String, DependencyInfo> parseDepsFiles() throws IOException {
DepsFileParser depsParser = createDepsFileParser();
Map<String, DependencyInfo> depsFiles = new LinkedHashMap<>();
for (SourceFile file : deps) {
if (!shouldSkipDepsFile(file)) {
List<DependencyInfo> depInfos = depsParser.parseFileReader(file.getName(), file.getCodeReader());
if (depInfos.isEmpty()) {
reportNoDepsInDepsFile(file.getName());
} else {
for (DependencyInfo info : depInfos) {
// DepsFileParser adds an ES6 module's relative path to closure as a provide so that
// the resulting depgraph is valid. But we don't want to write this "fake" provide
// back out, so remove it here.
depsFiles.put(info.getPathRelativeToClosureBase(), SimpleDependencyInfo.Builder.from(info).setProvides(info.getProvides().stream().filter(p -> !p.equals(info.getPathRelativeToClosureBase())).collect(Collectors.toList())).build());
}
}
}
}
// calls as well.
for (SourceFile src : srcs) {
if (!shouldSkipDepsFile(src)) {
List<DependencyInfo> srcInfos = depsParser.parseFileReader(src.getName(), src.getCodeReader());
for (DependencyInfo info : srcInfos) {
depsFiles.put(info.getPathRelativeToClosureBase(), info);
}
}
}
return depsFiles;
}
Aggregations