Search in sources :

Example 26 with SourceFile

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();
}
Also used : SourceFile(com.google.javascript.jscomp.SourceFile)

Example 27 with SourceFile

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;
}
Also used : SourceFile(com.google.javascript.jscomp.SourceFile)

Example 28 with SourceFile

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.");
}
Also used : SourceFile(com.google.javascript.jscomp.SourceFile)

Example 29 with SourceFile

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\".");
}
Also used : SourceFile(com.google.javascript.jscomp.SourceFile)

Example 30 with SourceFile

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);
}
Also used : Node(com.google.javascript.rhino.Node) NodeSubject.assertNode(com.google.javascript.jscomp.testing.NodeSubject.assertNode) SourceFile(com.google.javascript.jscomp.SourceFile) SimpleSourceFile(com.google.javascript.rhino.SimpleSourceFile) StaticSourceFile(com.google.javascript.rhino.StaticSourceFile) JSDocInfo(com.google.javascript.rhino.JSDocInfo)

Aggregations

SourceFile (com.google.javascript.jscomp.SourceFile)32 Compiler (com.google.javascript.jscomp.Compiler)9 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)7 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 Result (com.google.javascript.jscomp.Result)3 StaticSourceFile (com.google.javascript.rhino.StaticSourceFile)3 EntryPoint (com.google.gwt.core.client.EntryPoint)2 LazyParsedDependencyInfo (com.google.javascript.jscomp.LazyParsedDependencyInfo)2 SourceMapInput (com.google.javascript.jscomp.SourceMapInput)2 ParserRunner (com.google.javascript.jscomp.parsing.ParserRunner)2 Node (com.google.javascript.rhino.Node)2 File (java.io.File)2 LinkedHashMap (java.util.LinkedHashMap)2 JSExtern (net.vtst.ow.closure.compiler.deps.JSExtern)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ErrorManager (com.google.javascript.jscomp.ErrorManager)1 JsAst (com.google.javascript.jscomp.JsAst)1 Config (com.google.javascript.jscomp.parsing.Config)1 Comment (com.google.javascript.jscomp.parsing.parser.trees.Comment)1