Skip to content

Commit

Permalink
Add Args.SilenceDeprecations option
Browse files Browse the repository at this point in the history
  • Loading branch information
bep committed Nov 18, 2024
1 parent 0aa345d commit 8eb162a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ type Args struct {
// Additional file paths to uses to resolve imports.
IncludePaths []string

// Deprecation IDs to silence, e.g. "import".
SilenceDeprecations []string

sassOutputStyle embeddedsass.OutputStyle
sassSourceSyntax embeddedsass.Syntax

Expand Down
1 change: 1 addition & 0 deletions transpiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func (t *Transpiler) Execute(args Args) (Result, error) {
},
SourceMap: args.EnableSourceMap,
SourceMapIncludeSources: args.SourceMapIncludeSources,
SilenceDeprecation: args.SilenceDeprecations,
},
}

Expand Down
36 changes: 36 additions & 0 deletions transpiler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,42 @@ div { p { color: $moo; } }`
c.Assert(result.CSS, qt.Equals, "content{color:#ccc}div p{color:#f442d1}")
}

func TestSilenceDeprecations(t *testing.T) {
dir1 := t.TempDir()
colors := filepath.Join(dir1, "_colors.scss")

os.WriteFile(colors, []byte(`
$moo: #f442d1 !default;
`), 0o644)

c := qt.New(t)
src := `
@import "colors";
div { p { color: $moo; } }`

var loggedImportDeprecation bool
transpiler, clean := newTestTranspiler(c, godartsass.Options{
LogEventHandler: func(e godartsass.LogEvent) {
if e.DeprecationType == "import" {
loggedImportDeprecation = true
}
},
})
defer clean()

result, err := transpiler.Execute(
godartsass.Args{
Source: src,
OutputStyle: godartsass.OutputStyleCompressed,
IncludePaths: []string{dir1},
SilenceDeprecations: []string{"import"},
},
)
c.Assert(err, qt.IsNil)
c.Assert(loggedImportDeprecation, qt.IsFalse)
c.Assert(result.CSS, qt.Equals, "div p{color:#f442d1}")
}

func TestTranspilerParallel(t *testing.T) {
c := qt.New(t)
transpiler, clean := newTestTranspiler(c, godartsass.Options{})
Expand Down

0 comments on commit 8eb162a

Please sign in to comment.