Search in sources :

Example 1 with JSChunk

use of com.google.javascript.jscomp.JSChunk in project closure-compiler by google.

the class JSChunkGraphBuilder method build.

public JSChunk[] build() {
    JSChunk[] chunks = new JSChunk[this.chunks.size()];
    for (int i = 0; i < this.chunks.size(); i++) {
        String chunkName = this.chunkNames.getOrDefault(i, "m" + i);
        JSChunk chunk = chunks[i] = new JSChunk(chunkName);
        chunk.add(SourceFile.fromCode(Strings.lenientFormat(this.filenameFormat, i), this.chunks.get(i)));
    }
    this.graphType.addDependencyEdges(chunks);
    return chunks;
}
Also used : JSChunk(com.google.javascript.jscomp.JSChunk)

Example 2 with JSChunk

use of com.google.javascript.jscomp.JSChunk in project closure-compiler by google.

the class ClosureIntegrationTest method testCrossChunkDepCheck_inModule_withRequire.

@Test
public void testCrossChunkDepCheck_inModule_withRequire() {
    CompilerOptions options = createCompilerOptions();
    options.setClosurePass(true);
    ImmutableList<JSChunk> code = ImmutableList.copyOf(JSChunkGraphBuilder.forStar().addChunk("// base").addChunk("goog.module('goog.Foo'); /** @constructor */ exports = function() {};").addChunk("goog.module('goog.Bar'); const Foo = goog.require('goog.Foo'); new Foo();").setFilenameFormat(inputFileNamePrefix + "%s" + inputFileNameSuffix).build());
    Compiler compiler = compile(options, code);
    assertThat(compiler.getErrors()).isEmpty();
    assertThat(compiler.getWarnings()).hasSize(1);
    assertWithMessage("Unexpected error " + compiler.getWarnings().get(0)).that(DiagnosticGroups.STRICT_MODULE_DEP_CHECK.matches(compiler.getWarnings().get(0))).isTrue();
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) JSChunk(com.google.javascript.jscomp.JSChunk) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) Test(org.junit.Test)

Example 3 with JSChunk

use of com.google.javascript.jscomp.JSChunk in project closure-compiler by google.

the class ClosureIntegrationTest method testCrossChunkDepCheck_forProvide_withRequire.

@Test
public void testCrossChunkDepCheck_forProvide_withRequire() {
    CompilerOptions options = createCompilerOptions();
    options.setClosurePass(true);
    ImmutableList<JSChunk> code = ImmutableList.copyOf(JSChunkGraphBuilder.forStar().addChunk("// base").addChunk("goog.provide('goog.Foo');/** @constructor */ goog.Foo = function() {};").addChunk("goog.require('goog.Foo'); new goog.Foo();").setFilenameFormat(inputFileNamePrefix + "%s" + inputFileNameSuffix).build());
    Compiler compiler = compile(options, code);
    assertThat(compiler.getErrors()).isEmpty();
    assertThat(compiler.getWarnings()).hasSize(1);
    assertWithMessage("Unexpected error " + compiler.getWarnings().get(0)).that(DiagnosticGroups.STRICT_MODULE_DEP_CHECK.matches(compiler.getWarnings().get(0))).isTrue();
}
Also used : Compiler(com.google.javascript.jscomp.Compiler) JSChunk(com.google.javascript.jscomp.JSChunk) CompilerOptions(com.google.javascript.jscomp.CompilerOptions) Test(org.junit.Test)

Aggregations

JSChunk (com.google.javascript.jscomp.JSChunk)3 Compiler (com.google.javascript.jscomp.Compiler)2 CompilerOptions (com.google.javascript.jscomp.CompilerOptions)2 Test (org.junit.Test)2