Search in sources :

Example 16 with SourceFile

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

Example 17 with SourceFile

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

Example 18 with SourceFile

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

Example 19 with SourceFile

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

Example 20 with SourceFile

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

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