diff --git a/pom.xml b/pom.xml index 6fed2842..c2b47072 100644 --- a/pom.xml +++ b/pom.xml @@ -80,7 +80,7 @@ UTF-8 UTF-8 1.7 - 19.0 + 20.0 @@ -186,7 +186,7 @@ com.google.javascript closure-compiler-unshaded - v20160713 + v20170218 diff --git a/src/com/google/common/css/JobDescription.java b/src/com/google/common/css/JobDescription.java index f9c94e2e..8c1c4fec 100644 --- a/src/com/google/common/css/JobDescription.java +++ b/src/com/google/common/css/JobDescription.java @@ -25,7 +25,6 @@ import java.util.Map; import java.util.Set; - /** * Provides inputs and options to Closure Stylesheets. * To construct an instance, use a {@link JobDescriptionBuilder}. @@ -69,6 +68,7 @@ public class JobDescription { public final Map compileConstants; public final boolean createSourceMap; public final SourceMapDetailLevel sourceMapLevel; + public final boolean sourceMapIncludeContent; public final boolean preserveImportantComments; static final String CONDITION_FOR_LTR = "GSS_LTR"; @@ -142,6 +142,7 @@ public enum SourceMapDetailLevel { ALL, DEFAULT } boolean suppressDependencyCheck, Map compileConstants, boolean createSourceMap, SourceMapDetailLevel sourceMapLevel, + boolean sourceMapIncludeContent, boolean preserveImportantComments) { this.allowUndefinedConstants = allowUndefinedConstants; Preconditions.checkArgument(!inputs.contains(null)); @@ -190,6 +191,7 @@ public enum SourceMapDetailLevel { ALL, DEFAULT } this.compileConstants = ImmutableMap.copyOf(compileConstants); this.createSourceMap = createSourceMap; this.sourceMapLevel = sourceMapLevel; + this.sourceMapIncludeContent = sourceMapIncludeContent; this.preserveImportantComments = preserveImportantComments; } diff --git a/src/com/google/common/css/JobDescriptionBuilder.java b/src/com/google/common/css/JobDescriptionBuilder.java index 0f4a9d5e..9132a250 100644 --- a/src/com/google/common/css/JobDescriptionBuilder.java +++ b/src/com/google/common/css/JobDescriptionBuilder.java @@ -75,6 +75,7 @@ public class JobDescriptionBuilder { JobDescription job = null; boolean createSourceMap; SourceMapDetailLevel sourceMapLevel; + boolean sourceMapIncludeContent; public JobDescriptionBuilder() { this.inputs = Lists.newArrayList(); @@ -111,6 +112,7 @@ public JobDescriptionBuilder() { this.compileConstants = new HashMap<>(); this.createSourceMap = false; this.sourceMapLevel = SourceMapDetailLevel.DEFAULT; + this.sourceMapIncludeContent = false; this.preserveImportantComments = false; } @@ -151,6 +153,7 @@ public JobDescriptionBuilder copyFrom(JobDescription jobToCopy) { setCompileConstants(jobToCopy.compileConstants); this.createSourceMap = jobToCopy.createSourceMap; this.sourceMapLevel = jobToCopy.sourceMapLevel; + this.sourceMapIncludeContent = jobToCopy.sourceMapIncludeContent; this.preserveImportantComments = jobToCopy.preserveImportantComments; return this; } @@ -495,7 +498,8 @@ public JobDescription getJobDescription() { gssFunctionMapProvider, cssSubstitutionMapProvider, outputRenamingMapFormat, inputRenamingMap, preserveComments, suppressDependencyCheck, compileConstants, - createSourceMap, sourceMapLevel, preserveImportantComments); + createSourceMap, sourceMapLevel, sourceMapIncludeContent, + preserveImportantComments); return job; } @@ -509,4 +513,8 @@ public JobDescriptionBuilder setCreateSourceMap(boolean createSourceMap) { return this; } + public JobDescriptionBuilder setSourceMapIncludeContent(boolean sourceMapIncludeContent) { + this.sourceMapIncludeContent = sourceMapIncludeContent; + return this; + } } diff --git a/src/com/google/common/css/compiler/commandline/ClosureCommandLineCompiler.java b/src/com/google/common/css/compiler/commandline/ClosureCommandLineCompiler.java index 48eac76e..9630626e 100644 --- a/src/com/google/common/css/compiler/commandline/ClosureCommandLineCompiler.java +++ b/src/com/google/common/css/compiler/commandline/ClosureCommandLineCompiler.java @@ -145,6 +145,11 @@ static class Flags { + "mappings, and ALL, which outputs mappings for all elements.") private SourceMapDetailLevel sourceMapLevel = SourceMapDetailLevel.DEFAULT; + @Option(name = "--source_map_include_content", usage = "Includes sources " + + "content into source map. Greatly increases the size of source maps " + + "but offers greater portability (default: false)") + private boolean sourceMapIncludeContent = false; + @Option(name = "--copyright-notice", usage = "Copyright notice to prepend to the output") private String copyrightNotice = null; @@ -259,6 +264,7 @@ JobDescription createJobDescription() { getGssFunctionMapProviderForName(gssFunctionMapProviderClassName); builder.setGssFunctionMapProvider(gssFunctionMapProvider); builder.setSourceMapLevel(sourceMapLevel); + builder.setSourceMapIncludeContent(sourceMapIncludeContent); builder.setCreateSourceMap(!Strings.isNullOrEmpty(sourceMapFile)); if (inputRenamingMapFileName != null) { diff --git a/src/com/google/common/css/compiler/commandline/DefaultCommandLineCompiler.java b/src/com/google/common/css/compiler/commandline/DefaultCommandLineCompiler.java index 9126e22d..4e30f88f 100644 --- a/src/com/google/common/css/compiler/commandline/DefaultCommandLineCompiler.java +++ b/src/com/google/common/css/compiler/commandline/DefaultCommandLineCompiler.java @@ -81,7 +81,7 @@ private GssSourceMapGenerator createSourceMapGenerator(JobDescription job) { if (!job.createSourceMap) { return new NullGssSourceMapGenerator(); } - return new DefaultGssSourceMapGenerator(job.sourceMapLevel); + return new DefaultGssSourceMapGenerator(job.sourceMapLevel, job.sourceMapIncludeContent); } /** diff --git a/src/com/google/common/css/compiler/passes/DefaultGssSourceMapGenerator.java b/src/com/google/common/css/compiler/passes/DefaultGssSourceMapGenerator.java index d81177a3..27d2cc22 100644 --- a/src/com/google/common/css/compiler/passes/DefaultGssSourceMapGenerator.java +++ b/src/com/google/common/css/compiler/passes/DefaultGssSourceMapGenerator.java @@ -89,6 +89,8 @@ static class Mapping { private SourceMapDetailLevel sourceMapDetailLevel; + private boolean sourceMapIncludeContent; + /** Predicate to determine whether to include current node under visit into {@code mappings}. **/ private Predicate detailLevelPredicate; @@ -96,13 +98,16 @@ static class Mapping { * Constructor to get source map class to use. * * @param sourceMapDetailLevel used to control the output details of source map + * @param sourceMapIncludeContent used to include content in source map */ - public DefaultGssSourceMapGenerator(SourceMapDetailLevel sourceMapDetailLevel) { + public DefaultGssSourceMapGenerator(SourceMapDetailLevel sourceMapDetailLevel, + boolean sourceMapIncludeContent) { Preconditions.checkState(sourceMapDetailLevel != null); this.mappings = new ArrayDeque<>(); this.generator = SourceMapGeneratorFactory.getInstance(SourceMapFormat.V3); this.allMappings = new ArrayList<>(); this.sourceMapDetailLevel = sourceMapDetailLevel; + this.sourceMapIncludeContent = sourceMapIncludeContent; this.detailLevelPredicate = DETAIL_LEVEL_PREDICATES.get(this.sourceMapDetailLevel); } @@ -202,12 +207,18 @@ private void generateSourceMap() { completeMapping.sourceFile, null, completeMapping.inputStart, completeMapping.outputStart, completeMapping.outputEnd); + + if (sourceMapIncludeContent) { + generator.addSourcesContent( + completeMapping.sourceFile, completeMapping.sourceContents); + } } } private static final class CompleteMapping implements Comparable { final String sourceFile; + final String sourceContents; final FilePosition inputStart; final FilePosition outputStart; final FilePosition outputEnd; @@ -215,6 +226,7 @@ private static final class CompleteMapping implements Comparable sources = new ArrayList<>(); private TestErrorManager errorManager = new TestErrorManager(new String[0]); private GssSourceMapGenerator generator = - new DefaultGssSourceMapGenerator(SourceMapDetailLevel.ALL); + new DefaultGssSourceMapGenerator(SourceMapDetailLevel.ALL, true); private String output = null; private SourceMapping sourceMap = null; private String sourceMapString = null;