Fix 2699 : filename set at parsing stage + nodes.filename scope + filename in the Root
AST node
#2700
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What:
node.filename
changes so that it's easier to follow how this global variable is changedthis.filename
from the root node if not provided in the optionsWhy:
I am implementing a loader to retrieve all the variables defined in a stylus file (and its imports). The easiest way to do it is to look into
Evaluator.global.scope
. However, the setup adds builtin globals and filtering is necessary. The best way to filter is to check if the AST node's filename isnull
. However, the parser does not set the filename of the ast nodes.fix #2699
While implementing this, I encountered several problems with the
nodes.filename
global variable :This is why I added code to precisely mark the scope of the modification, and restore its previous value then.
How:
See commit changes (it's quite short)
Checklist:
I am waiting your review before writing changelogs etc.