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

Exclude function from imported file if its arguments are overridden by the importing file #3667

Closed
wants to merge 1 commit into from

Conversation

rgroothuijsen
Copy link
Contributor

This addresses issue #3563 by excluding functions in an imported file whose variable arguments are overridden by the file that is importing it. For every argument in the function, 3 things are checked:

  1. Is there a difference between filename and rootFilename for this file, i.e. is this a file that is being imported by another file?
  2. Does the root file contain a redefinition of the variable?
  3. Is this a variable argument?

If all 3 of these conditions are met for any of the arguments, the function is excluded from the final output, and any variables using this function to obtain a value remain undefined. Since silently ignoring these functions might lead to unexpected behaviors, perhaps Less could signal to the user in some way that it's doing this?

// Do not call function with variable argument if this file is being imported by another file
// and said variable is being redefined by the importing file
if (fileInfo.filename !== fileInfo.rootFilename
&& imports.contents[fileInfo.rootFilename].match(arg.name + '\\s*:')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't feel right that this should be in the parser, or have anything to do with arguments. Isn't this an evaluation issue? Does this only happen with functions, or is this just an issue with lazy evaluation in general?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it seems you're absolutely right. I got a bit ahead of myself because the problem in the linked issue was about functions, but upon closer inspection it seems to be a more general issue with variables in imports not being evaluated -- the same thing applies, for example, to operators. So yes, this would have been the wrong approach.

Edit: correction, it doesn't even seen to be triggered by imports, but rather by the variables being overridden, even if it's the same file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reducing the test-case down to the minimum number of failing lines makes it clearer why the crash happened:
@base-color: var(--primary-color); @dark-color: darken(@base-color, 50%); which makes sense as the function was trying to process arguments that will be defined later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants