use of com.google.javascript.jscomp.SourceFile in project closure-compiler by google.
the class DepsGeneratorTest method testDepsAsSrcs.
/**
* Ensures that everything still works when both a deps.js and a deps-runfiles.js file are
* included. Also uses real files.
*/
public void testDepsAsSrcs() throws Exception {
final SourceFile depsFile1 = SourceFile.fromCode("/base/deps1.js", LINE_JOINER.join("// Test deps file 1.", "", "goog.addDependency('../prescanned1/file1.js', ['dep.string'], []);", "goog.addDependency('../prescanned1/file2.js', [], []);", "// Test that this appears only once in the output. It's also defined in deps2.js", "goog.addDependency('../this/is/defined/thrice.js', [], []);", "goog.addDependency('../this/is/defined/thrice.js', [], []);", ""));
final SourceFile depsFile2 = SourceFile.fromCode("/base/deps2.js", LINE_JOINER.join("// Test deps file 2.", "", "goog.addDependency(" + "'../prescanned2/file1.js', ['dep.bool', 'dep.number'], ['dep.string']);", "goog.addDependency('../prescanned2/file2.js', [], []);", "goog.addDependency('../prescanned2/generated.js', ['dep.generated'], []);", "goog.addDependency('../this/is/defined/thrice.js', [], []);", ""));
DepsGenerator depsGenerator = new DepsGenerator(ImmutableList.of(depsFile1), ImmutableList.of(depsFile2), DepsGenerator.InclusionStrategy.ALWAYS, PathUtil.makeAbsolute("/base/javascript/closure"), errorManager, new ModuleLoader(null, ImmutableList.of("/base/" + "/"), ImmutableList.<DependencyInfo>of(), ModuleLoader.PathResolver.ABSOLUTE, ModuleLoader.ResolutionMode.BROWSER));
String output = depsGenerator.computeDependencyCalls();
assertWithMessage("There should be output").that(output).isNotEmpty();
assertNoWarnings();
}
use of com.google.javascript.jscomp.SourceFile in project closure-compiler by google.
the class DepsGeneratorTest method testMergeStrategyHelper.
private String testMergeStrategyHelper(DepsGenerator.InclusionStrategy mergeStrategy) throws Exception {
SourceFile dep1 = SourceFile.fromCode("dep1.js", LINE_JOINER.join("goog.addDependency('../../a.js', ['a'], []);", "goog.addDependency('../../src1.js', ['b'], []);", "goog.addDependency('../../d.js', ['d'], []);\n"));
SourceFile src1 = SourceFile.fromCode("/base/" + "/src1.js", "goog.provide('b');\n");
SourceFile src2 = SourceFile.fromCode("/base/" + "/src2.js", LINE_JOINER.join("goog.provide('c');", "goog.require('d');"));
DepsGenerator depsGenerator = new DepsGenerator(ImmutableList.of(dep1), ImmutableList.of(src1, src2), mergeStrategy, PathUtil.makeAbsolute("/base/javascript/closure"), errorManager, new ModuleLoader(null, ImmutableList.of("/base/"), ImmutableList.<DependencyInfo>of(), ModuleLoader.PathResolver.ABSOLUTE, ModuleLoader.ResolutionMode.BROWSER));
String output = depsGenerator.computeDependencyCalls();
assertNoWarnings();
assertWithMessage("There should be output files").that(output).isNotEmpty();
return output;
}
use of com.google.javascript.jscomp.SourceFile in project closure-compiler by google.
the class DepsGeneratorTest method testUnknownNamespace.
public void testUnknownNamespace() throws Exception {
SourceFile dep1 = SourceFile.fromCode("dep1.js", "goog.addDependency('a.js', ['a'], []);\n");
SourceFile src1 = SourceFile.fromCode("src1.js", "goog.require('b');\n");
doErrorMessagesRun(ImmutableList.of(dep1), ImmutableList.of(src1), true, /* fatal */
"Namespace \"b\" is required but never provided.");
}
use of com.google.javascript.jscomp.SourceFile in project closure-compiler by google.
the class DepsGeneratorTest method testUnknownEs6Module.
public void testUnknownEs6Module() throws Exception {
SourceFile src1 = SourceFile.fromCode("src1.js", "import './missing.js';\n");
doErrorMessagesRun(ImmutableList.of(), ImmutableList.of(src1), true, /* fatal */
"Could not find file \"./missing.js\".");
}
use of com.google.javascript.jscomp.SourceFile in project closure-compiler by google.
the class JsDocInfoParserTest method testJsDocInfoPosition.
public void testJsDocInfoPosition() throws IOException {
SourceFile sourceFile = SourceFile.fromCode("comment-position-test.js", " \n" + " /**\n" + " * A comment\n" + " */\n" + " function f(x) {}");
Node script = parseFull(sourceFile.getCode());
checkState(script.isScript());
Node fn = script.getFirstChild();
checkState(fn.isFunction());
JSDocInfo jsdoc = fn.getJSDocInfo();
assertThat(jsdoc.getOriginalCommentPosition()).isEqualTo(6);
assertThat(sourceFile.getLineOfOffset(jsdoc.getOriginalCommentPosition())).isEqualTo(2);
assertThat(sourceFile.getColumnOfOffset(jsdoc.getOriginalCommentPosition())).isEqualTo(2);
}
Aggregations