autoprefixer icon indicating copy to clipboard operation
autoprefixer copied to clipboard

Warnings show incorrect file info (css string with map file)

Open glenn2223 opened this issue 4 years ago • 3 comments

My issue is specifically related to the grid: "autoplace" option. But I'd imagine it applies anywhere a warning is raised.

Actual warning snippet:

  • Line: 1
  • Column: 10
  • File: c:\Path\Sample\_AutoprefixExample\File-With-Import.scss (from node.source.input.file)

Expected warning snippet:

  • Line: 2
  • Column: 4
  • File: c:\Path\Sample\_AutoprefixExample\_import-me.scss

Code

const 
    prefixer = postcss(
            autoprefixer({
                overrideBrowserslist: [
                    '> 0.5%'
                    'last 2 versions'
                    'Firefox ESR'
                    'not dead'
                ],
                grid: "autoplace",
            })
        ),
    result = 
        await prefixer.process(
            "div.Test{grid-template-columns:1fr 3fr}",
            {
                from: 'c:\\Path\\Sample\\_AutoprefixExample\\File-With-Import.scss',
                to: 'c:\\Path\\Sample\\Assets\\Style\\File-With-Import.css',
                map: {
                    inline: false,
                    prev: map, // <-- See map below
                },
            }
        );

result.warnings().forEach((warn) => {
    const
        file = warn.node.source.input.file,
        line = warn.line,
        column = warn.column;
});

MAP

{
    "version":3,
    "sourceRoot":"",
    "sources":["../../_AutoprefixExample/_import-me.scss"],
    "names":[],
    "mappings":"AAAA,SACI",
    "file":"file:///c:/Path/Sample/_AutoprefixExample/File-With-Import.css"
}

File-With-Import.scss

@import 'import-me'

_import-me.scss

div.Test {
    grid-template-columns: 1fr 3fr;
}

glenn2223 avatar Jan 20 '21 15:01 glenn2223

Good idea. Do you want to send PR?

ai avatar Jan 20 '21 15:01 ai

I'm happy to take a look when I can. Where's a good place to start? Rather than trundling through all the files, can I ask: where are the warnings raised and maps parsed?

glenn2223 avatar Jan 20 '21 16:01 glenn2223

  1. Find all .warn( calls in Autoprefixer sources.
  2. Check Node#warn() in PostCSS. It should use the node origin. Debug why it is not happening.

ai avatar Jan 20 '21 16:01 ai