From b86ad77c21bb9c4cc4323a98f242764e401cf3c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20Siedlarek?= Date: Sat, 19 Nov 2022 20:49:22 +0100 Subject: [PATCH] Expose the option to embed sources in the source map. --- options.go | 3 +++ transpiler.go | 3 ++- transpiler_test.go | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/options.go b/options.go index ee642f7..53fee32 100644 --- a/options.go +++ b/options.go @@ -106,6 +106,9 @@ type Args struct { // If enabled, a sourcemap will be generated and returned in Result. EnableSourceMap bool + // If enabled, sources will be embedded in the generated source map. + SourceMapIncludeSources bool + // Custom resolver to use to resolve imports. // If set, this will be the first in the resolver chain. ImportResolver ImportResolver diff --git a/transpiler.go b/transpiler.go index 624eb59..879f0ee 100644 --- a/transpiler.go +++ b/transpiler.go @@ -162,7 +162,8 @@ func (t *Transpiler) Execute(args Args) (Result, error) { Url: args.URL, }, }, - SourceMap: args.EnableSourceMap, + SourceMap: args.EnableSourceMap, + SourceMapIncludeSources: args.SourceMapIncludeSources, }, } diff --git a/transpiler_test.go b/transpiler_test.go index b0bcc1a..b9c618f 100644 --- a/transpiler_test.go +++ b/transpiler_test.go @@ -78,6 +78,7 @@ func TestTranspilerVariants(t *testing.T) { }{ {"Output style compressed", Options{}, Args{Source: "div { color: #ccc; }", OutputStyle: OutputStyleCompressed}, Result{CSS: "div{color:#ccc}"}}, {"Enable Source Map", Options{}, Args{Source: "div{color:blue;}", URL: "file://myproject/main.scss", OutputStyle: OutputStyleCompressed, EnableSourceMap: true}, Result{CSS: "div{color:blue}", SourceMap: "{\"version\":3,\"sourceRoot\":\"\",\"sources\":[\"file://myproject/main.scss\"],\"names\":[],\"mappings\":\"AAAA\"}"}}, + {"Enable Source Map with sources", Options{}, Args{Source: "div{color:blue;}", URL: "file://myproject/main.scss", OutputStyle: OutputStyleCompressed, EnableSourceMap: true, SourceMapIncludeSources: true}, Result{CSS: "div{color:blue}", SourceMap: "{\"version\":3,\"sourceRoot\":\"\",\"sources\":[\"file://myproject/main.scss\"],\"names\":[],\"mappings\":\"AAAA\",\"sourcesContent\":[\"div{color:blue;}\"]}"}}, {"Sass syntax", Options{}, Args{ Source: `$font-stack: Helvetica, sans-serif $primary-color: #333