Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc deprecation #30

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type LogEvent struct {
// Type is the type of log event.
Type LogEventType

// DeprecationType is set if Type is LogEventTypeDeprecated.
DeprecationType string

// Message on the form url:line:col message.
Message string
}
Expand Down Expand Up @@ -133,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 Expand Up @@ -238,3 +244,10 @@ func ParseSourceSyntax(s string) SourceSyntax {
return SourceSyntaxSCSS
}
}

func stringPointerToString(s *string) string {
if s == nil {
return ""
}
return *s
}
11 changes: 7 additions & 4 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 Expand Up @@ -413,13 +414,15 @@ func (t *Transpiler) input() {
}
u, _ = url.QueryUnescape(u)
logEvent = LogEvent{
Type: LogEventType(e.Type),
Message: fmt.Sprintf("%s:%d:%d: %s", u, e.Span.Start.Line, e.Span.Start.Column, c.LogEvent.GetMessage()),
Type: LogEventType(e.Type),
DeprecationType: stringPointerToString(e.DeprecationType),
Message: fmt.Sprintf("%s:%d:%d: %s", u, e.Span.Start.Line, e.Span.Start.Column, c.LogEvent.GetMessage()),
}
} else {
logEvent = LogEvent{
Type: LogEventType(e.Type),
Message: e.GetMessage(),
Type: LogEventType(e.Type),
DeprecationType: stringPointerToString(e.DeprecationType),
Message: e.GetMessage(),
}
}

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
Loading