Skip to content

Commit

Permalink
Add --sourcemap_mode flag to Soy compiler and propagate to JS output …
Browse files Browse the repository at this point in the history
…code.

PiperOrigin-RevId: 706018607
  • Loading branch information
Jesse-Good authored and copybara-github committed Dec 16, 2024
1 parent 33c415b commit e775253
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
6 changes: 6 additions & 0 deletions java/src/com/google/template/soy/AbstractSoyCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.google.template.soy.base.SourceFilePath;
import com.google.template.soy.base.SourceLogicalPath;
import com.google.template.soy.base.internal.KytheMode;
import com.google.template.soy.base.internal.SourceMapMode;
import com.google.template.soy.base.internal.SoyFileKind;
import com.google.template.soy.error.SoyCompilationException;
import com.google.template.soy.plugin.java.DelegatingMethodChecker;
Expand Down Expand Up @@ -214,6 +215,11 @@ public abstract class AbstractSoyCompiler {
usage = "The kythe mode for generating kythe imputation metadata. Used by some compilers.")
protected KytheMode kytheMode = KytheMode.DISABLED;

@Option(
name = "--sourcemap_mode",
usage = "The mode for generating sourcemap metadata. Used by some compilers.")
protected SourceMapMode sourceMapMode = SourceMapMode.DISABLED;

/** The remaining arguments after parsing command-line flags. */
@Argument private List<String> arguments = new ArrayList<>();

Expand Down
1 change: 1 addition & 0 deletions java/src/com/google/template/soy/SoyToJsSrcCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ protected void compile(SoyFileSet.Builder sfsBuilder) throws IOException {
.setBidiGlobalDir(bidiGlobalDir)
.setUseGoogIsRtlForBidiGlobalDir(useGoogIsRtlForBidiGlobalDir)
.setKytheMode(kytheMode)
.setSourceMapMode(sourceMapMode)
.build();

// Compile.
Expand Down
31 changes: 31 additions & 0 deletions java/src/com/google/template/soy/base/internal/SourceMapMode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2024 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.google.template.soy.base.internal;

/** Compiler flag --sourcemap_mode. */
public enum SourceMapMode {
/** Output no Kythe metadata. */
DISABLED,
/** Output the standard base64 encoded proto. */
BASE64,
/** Output human "readable" text format of proto, for tests. */
TEXT;

public boolean isEnabled() {
return this != DISABLED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.google.auto.value.AutoValue;
import com.google.template.soy.base.internal.KytheMode;
import com.google.template.soy.base.internal.SourceMapMode;
import com.google.template.soy.jssrc.SoyJsSrcOptions;

/** Compilation options for incrementaldomsrc. */
Expand All @@ -32,11 +33,14 @@ public abstract class SoyIncrementalDomSrcOptions {

public abstract KytheMode kytheMode();

public abstract SourceMapMode sourceMapMode();

public static Builder builder() {
return new AutoValue_SoyIncrementalDomSrcOptions.Builder()
.setDependOnCssHeader(false)
.setGoogMsgsAreExternal(true)
.setKytheMode(KytheMode.DISABLED);
.setKytheMode(KytheMode.DISABLED)
.setSourceMapMode(SourceMapMode.DISABLED);
}

public abstract Builder toBuilder();
Expand All @@ -60,6 +64,8 @@ public abstract static class Builder {

public abstract Builder setKytheMode(KytheMode kytheMode);

public abstract Builder setSourceMapMode(SourceMapMode sourceMapMode);

public abstract SoyIncrementalDomSrcOptions build();
}

Expand All @@ -77,6 +83,7 @@ SoyJsSrcOptions toJsSrcOptions() {
.setUseGoogIsRtlForBidiGlobalDir(true)
.setDependOnCssHeader(dependOnCssHeader())
.setKytheMode(kytheMode())
.setSourceMapMode(sourceMapMode())
.build();
}
}
8 changes: 7 additions & 1 deletion java/src/com/google/template/soy/jssrc/SoyJsSrcOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.base.Preconditions;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.template.soy.base.internal.KytheMode;
import com.google.template.soy.base.internal.SourceMapMode;

/** Compilation options for the JS Src output target (backend). */
@AutoValue
Expand Down Expand Up @@ -90,6 +91,8 @@ public boolean shouldGenerateGoogModules() {

public abstract KytheMode kytheMode();

public abstract SourceMapMode sourceMapMode();

public static Builder builder() {
return new AutoValue_SoyJsSrcOptions.Builder()
.setDepsStrategy(JsDepsStrategy.NAMESPACES)
Expand All @@ -98,7 +101,8 @@ public static Builder builder() {
.setGoogMsgsAreExternal(false)
.setBidiGlobalDir(0)
.setUseGoogIsRtlForBidiGlobalDir(false)
.setKytheMode(KytheMode.DISABLED);
.setKytheMode(KytheMode.DISABLED)
.setSourceMapMode(SourceMapMode.DISABLED);
}

public abstract Builder toBuilder();
Expand Down Expand Up @@ -194,6 +198,8 @@ public Builder setShouldGenerateGoogModules(boolean shouldGenerateGoogModules) {

public abstract Builder setKytheMode(KytheMode kytheMode);

public abstract Builder setSourceMapMode(SourceMapMode sourceMapMode);

abstract SoyJsSrcOptions autoBuild();

public SoyJsSrcOptions build() {
Expand Down

0 comments on commit e775253

Please sign in to comment.