Less.js: Source Maps Has No Mapping for a Closing Bracket

Created on 1 Mar 2020  路  4Comments  路  Source: less/less.js

When i generate a source map for the following file using version 3.11.1

.example {
  display: grid;
  transition: all 0.5s;
  user-select: none;
  background: linear-gradient(to bottom, white, black);
}

@color: "blue";

#my-div {
  color: @color;
}

with the following command in a node script

less.render(lessFileContents, { sourceMap: { sourceMapFileInline: false } })
  .then(function (output) {},

Then i look at the Source Map and run it in the https://sokra.github.io/source-map-visualization/#custom tool

{"version":3,"sources":["input"],"names":[],"mappings":"AAAA;EACE,aAAA;EACA,oBAAA;EACA,iBAAA;EACA,YAAY,wCAAZ;;AAKF;EACE,OAHM,MAGN"}

You can see the empty line in between these two mappings wCAAZ;;AAKF where the mapping for the } should be. This becomes and issue when you are making a source map where this generated map is an intermediate step that you are using to get back to the original Less file.

As an update I have tried Stylus and node-sass and they all do not have a mapping for the closing brackets in the generated file back to the original files. Is this just a limitation of pre processors in general?

stale

Most helpful comment

just wanted to say that Less is awesome

All 4 comments

The simple answer is that Less (currently) has a very simple parser that only tracks source start and not source end, mostly because it was created before source maps were a concept.

I've been re-writing a Less parser from scratch using Chevrotain to use for 4.x, and have done a significant amount of work on it, but without financial support (a la Open Collective), I can really only work on it in limited free time. I still intend to, but it might take a while.

that makes alot of sense, thanks for the quick response. Ill make a contribution to the open collective on friday. Im excited about the new parser now that I know its coming in the future. I signed up as a monthly contributor and made an announcement in the Meteor Slack channel and on LinkedIn. I will keep trying to gather support for LESS as well moving forward. Its one of my favorite projects

just wanted to say that Less is awesome

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings