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

Built-in functions are not available in certain contexts (impl. details). #3054

Open
seven-phases-max opened this issue Apr 21, 2017 · 10 comments

Comments

@seven-phases-max
Copy link
Member

seven-phases-max commented Apr 21, 2017

Example:

@bar: pi();
@import "foo-@{bar}.less";

Result:

SyntaxError: Cannot read property 'get' of undefined in *.less on line 2, column 1

The error simply means that the pi function is undefined at that point.
This happens because each context/frame has its own copy of the functions set, but the set is copied there too late to be available for a (preeval only?) visitor (e.g. like the import visitor above). This obviously prevents any (preeval?) visitor to be able to evaluate any code involving a function call.
Not sure if it still applies to the 3.x branch.

@calvinjuarez
Copy link
Member

calvinjuarez commented Apr 22, 2017

Output's a little different in 3.x, but it still errors.

$ lessc -v
lessc 3.0.0 (Less Compiler) [JavaScript]

$ lessc test.less test.css
TypeError: Cannot read property 'then' of undefined
    at parseLessFile (/Users/calvin/Sites/_contributing/less.js/bin/lessc:287:13)
    at /Users/calvin/Sites/_contributing/less.js/node_modules/graceful-fs/graceful-fs.js:78:16
    at tryToString (fs.js:449:3)
    at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:436:12)

(using the same example)

@seven-phases-max
Copy link
Member Author

Output's a little different in 3.x, but it still errors.

This is simply because lessc is broken after b782411 (or so). Not really related to above issue.

@calvinjuarez
Copy link
Member

Whoops, my bad.

@matthew-dean
Copy link
Member

I assume this is fixed by bad9be8 9440842 ? (sorry for the dupe... my git skills still need improvement. Any help there is welcome.)

@seven-phases-max @calvinjuarez All tests should be passing now. At least they are locally. But AppVeyor / Travis are still saying things are broken, which I haven't had time to look into.

Otherwise, can you test the above code against alpha 3 and see if this issue can be closed?

@matthew-dean
Copy link
Member

@seven-phases-max I just realized you said lessc was broken, which isn't covered by tests. We should add that as a to-do. To my knowledge, that's not actually tested anywhere.

@matthew-dean
Copy link
Member

@seven-phases-max Was there a bug report I missed about lessc being broken?

@matthew-dean
Copy link
Member

matthew-dean commented Oct 10, 2017

This issue is a possible dupe of #3112. (But should be checked against current fix.)

@matthew-dean
Copy link
Member

Should this be closed? Still occurring?

@matthew-dean
Copy link
Member

This happens because each context/frame has its own copy of the functions set, but the set is copied there too late to be available for a (preeval only?) visitor (e.g. like the import visitor above). This obviously prevents any (preeval?) visitor to be able to evaluate any code involving a function call.

I took a look at this with a function called by a plugin. It definitely isn't eval'd in time, but this is beyond my current understanding of the Less tree. @seven-phases-max can you explain (as best you can) the way context/frames are defined within the Less engine? Maybe that could be documentation added to the code.

@seven-phases-max
Copy link
Member Author

seven-phases-max commented Oct 10, 2018

Should this be closed? Still occurring?

Just try the initial example and if it fails then the issue is still there.

can you explain (as best you can) the way context/frames are defined within the Less engine?

Uh... That would be not so easy. Personalty each time I had to deal with them I almost always went with console.log(context.frames) and then feeding the compiler with code of interest to see what I have there.
Basically frames is an array of objects representing all scopes from "the current" up to the top (the global) one. Thus context is a sort of "the state of the compiler" at the current point of execution like "scope (sort of 'pointer' to the current node in AST) + all the options + everything else".
Example of traversing through frames to build the "parent selector list".
But I guess (by looking at all recent Less changes) you already get most of this on you own (so my apologizes for the late reply).

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

No branches or pull requests

3 participants