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

Fixes less#3675 - LESS detects @apply as variable (ISSUE) #3798

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

opike
Copy link

@opike opike commented May 11, 2023

Issue #3675 - LESS detects @apply as variable (ISSUE)

Issue was identified as a bug

Checklist:

  • Documentation N/A
  • Added/updated unit tests
  • Code complete

This is my first PR - all the tests are passing and I added a new test that is confirmed to fail without the changes.

@opike
Copy link
Author

opike commented May 12, 2023

My bad with the failing tests. Something was off with my set up prior to submitting the PR where for some reason only a subset of the tests were being run and they were all passing:
Screenshot on 2023-05-11 at 21-52-03

I'm going back and taking another look now.

@opike
Copy link
Author

opike commented May 12, 2023

I updated the fix however there's still one test that is failing, which I don't yet have a clear idea how to resolve.
[LessError: '@file_to_import' wasn't found. Tried - /Volumes/github-image/less.js/packages/test-data/less/_main/@file_to_import.less,/Volumes/github-image/less.js/packages/test-data/less/_main/@file_to_import.less,npm://@file_to_import,npm://@file_to_import.less,@file_to_import.less] { stack: undefined, type: 'File', filename: '/Volumes/github-image/less.js/packages/test-data/less/_main/urls.less', index: 2168, line: 70, column: 0, callLine: NaN, callExtract: undefined, extract: [ '.add_an_import(@file_to_import) {', '@import "@{file_to_import}";', '}' ] }

With this code:
.add_an_import(@file_to_import) {
@import "@{file_to_import}";
}

A distinction needs to be made between the @{file_to_import} variable reference and an arbitrary at-rule such as @apply. Presuming the overall direction I took is appropriate with the fix, I believe that could be done through the context in this code block:

https://github.com/opike/less.js/blob/7cf515abac3fdac9f3be8adfad62734b01ccc60a/packages/less/src/less/tree/quoted.js#L36

Although it's not yet apparent to me specifically where in the context to key off of.

@matthew-dean
Copy link
Member

So, if I recall correctly, what I originally did was basically hack custom properties to consider the whole value as a kind of "escaped quoted value" so that it wouldn't try to tokenize any particular bit, and then would over-rode the regex statements to treat "variable-like" statements as variable lookups.

Now, I'm not sure the latter part was the best idea (maybe we should have required at-rule tokens to be escaped, just like in a quote, if in a custom property), but one thing with your change -- will it not miss errors now with variables that are in quotes?

@matthew-dean
Copy link
Member

In regards to this:

.add_an_import(@file_to_import) {
  @import "@{file_to_import}";
}

...where are you getting this code block from?

@opike
Copy link
Author

opike commented May 12, 2023 via email

@opike
Copy link
Author

opike commented May 12, 2023 via email

@matthew-dean
Copy link
Member

@opike Oh, I see. I wasn't aware variable replacement worked in an import in a mixin call. Imports are very tricky (and using variable replacement in them leads to unexpected results) because the import blends variable scope. So an import may rely on a variable defined in another import, and whether or not to import that import may rely on yet another variable.

So, imports are sort of evaluated early in the parsing cycle and, to be honest, I'm not sure exactly how they work.

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