use of com.google.javascript.jscomp.SourceFile in project closure-compiler by google.
the class DepsGeneratorTest method testWithDepsAndSources.
/**
* Ensures that deps files are handled correctly both when listed as deps and when listed as
* sources.
*/
public void testWithDepsAndSources() throws Exception {
final SourceFile depsFile1 = SourceFile.fromCode("/base/my-project/deps1.js", LINE_JOINER.join("goog.addDependency('../prescanned1/file1.js', ['dep.string'], []);", "goog.addDependency('../prescanned1/file2.js', [], []);", // Test that this appears only once in the output.
"goog.addDependency('../this/is/defined/thrice.js', [], []);", "goog.addDependency('../this/is/defined/thrice.js', [], []);", ""));
final SourceFile depsFile2 = SourceFile.fromCode("/base/my-project/deps2.js", LINE_JOINER.join("goog.addDependency(" + "'../prescanned2/file1.js'," + " ['dep.bool', 'dep.number']," + " ['dep.string']);", "goog.addDependency('../prescanned2/file2.js', [], []);", "goog.addDependency('../this/is/defined/thrice.js', [], []);", ""));
final SourceFile srcFile1 = SourceFile.fromCode("/base/my-project/src1.js", LINE_JOINER.join("goog.provide('makejsdeps.file1');", "goog.provide('makejsdeps.file1.Test');", "", // Ensure comments are stripped. These cause syntax errors if not stripped.
"/*", "goog.require('failure1)", "*/", "// goog.require('failure2)", "", "goog.require('makejsdeps.file2');", // 'goog' should be silently dropped.
"goog.require(\"goog\");", "goog.require(\"dep.string\");", "goog.require(\"dep.number\");", ""));
final SourceFile srcFile2 = SourceFile.fromCode("/base/my-project/src2.js", "goog.provide('makejsdeps.file2');");
String expected = LINE_JOINER.join("goog.addDependency(" + "'../../my-project/src1.js'," + " ['makejsdeps.file1', 'makejsdeps.file1.Test']," + " ['makejsdeps.file2', 'dep.string', 'dep.number']);", "goog.addDependency('../../my-project/src2.js', ['makejsdeps.file2'], []);", "", "// Included from: /base/my-project/deps1.js", "goog.addDependency('../prescanned1/file1.js', ['dep.string'], []);", "goog.addDependency('../prescanned1/file2.js', [], []);", "", "// Included from: /base/my-project/deps2.js", "goog.addDependency('../this/is/defined/thrice.js', [], []);", "goog.addDependency(" + "'../prescanned2/file1.js'," + " ['dep.bool', 'dep.number']," + " ['dep.string']);", "goog.addDependency('../prescanned2/file2.js', [], []);", "");
DepsGenerator depsGenerator = new DepsGenerator(ImmutableList.of(depsFile1, depsFile2), ImmutableList.of(srcFile1, srcFile2), DepsGenerator.InclusionStrategy.ALWAYS, "/base/javascript/closure", errorManager, new ModuleLoader(null, ImmutableList.of("/base/"), ImmutableList.<DependencyInfo>of(), ModuleLoader.PathResolver.ABSOLUTE, ModuleLoader.ResolutionMode.BROWSER));
String output = depsGenerator.computeDependencyCalls();
assertNoWarnings();
assertThat(output).isEqualTo(expected);
// Repeat the test with the deps files listed as sources.
// The only difference should be the addition of addDependency() calls for the deps files.
depsGenerator = new DepsGenerator(ImmutableList.<SourceFile>of(), ImmutableList.of(depsFile1, depsFile2, srcFile1, srcFile2), DepsGenerator.InclusionStrategy.ALWAYS, "/base/javascript/closure", errorManager, new ModuleLoader(null, ImmutableList.of("/base/"), ImmutableList.<DependencyInfo>of(), ModuleLoader.PathResolver.ABSOLUTE, ModuleLoader.ResolutionMode.BROWSER));
String expectedWithDepsAsSources = LINE_JOINER.join("goog.addDependency('../../my-project/deps1.js', [], []);", "goog.addDependency('../../my-project/deps2.js', [], []);", expected);
output = depsGenerator.computeDependencyCalls();
assertNoWarnings();
assertThat(output).isEqualTo(expectedWithDepsAsSources);
}
use of com.google.javascript.jscomp.SourceFile in project closure-compiler by google.
the class DepsGeneratorTest method testDuplicateProvides.
public void testDuplicateProvides() throws Exception {
SourceFile dep1 = SourceFile.fromCode("dep1.js", "goog.addDependency('a.js', ['a'], []);\n");
SourceFile src1 = SourceFile.fromCode("src1.js", "goog.provide('a');\n");
doErrorMessagesRun(ImmutableList.of(dep1), ImmutableList.of(src1), true, /* fatal */
"Namespace \"a\" is already provided in other file dep1.js");
}
use of com.google.javascript.jscomp.SourceFile in project closure-compiler by google.
the class DepsGeneratorTest method testDuplicateRequire.
public void testDuplicateRequire() throws Exception {
SourceFile dep1 = SourceFile.fromCode("dep1.js", "goog.addDependency('a.js', ['a'], []);\n");
SourceFile src1 = SourceFile.fromCode("src1.js", LINE_JOINER.join("goog.require('a');", "goog.require('a');", ""));
doErrorMessagesRun(ImmutableList.of(dep1), ImmutableList.of(src1), false, /* fatal */
"Namespace \"a\" is required multiple times");
}
use of com.google.javascript.jscomp.SourceFile in project closure-compiler by google.
the class DepsGeneratorTest method testSameFileProvideRequire.
public void testSameFileProvideRequire() 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.require('b');", ""));
doErrorMessagesRun(ImmutableList.of(dep1), ImmutableList.of(src1), false, /* fatal */
"Namespace \"b\" is both required and provided in the same file.");
}
use of com.google.javascript.jscomp.SourceFile in project closure-compiler by google.
the class DepsGeneratorTest method testNoDepsInDepsFile.
public void testNoDepsInDepsFile() throws Exception {
SourceFile dep1 = SourceFile.fromCode("dep1.js", "");
doErrorMessagesRun(ImmutableList.of(dep1), ImmutableList.<SourceFile>of(), false, /* fatal */
"No dependencies found in file");
}
Aggregations