Open henry-kiho opened 7 years ago
Hi, could you give me the Stylus code with which it happens?
The probable cause would be a semi-colon in a variable declaration:
@foo: ";"
I know this should be valid Stylus code but the pattern in the RegExp : [^;]+
does not allow it.
If you can confirm the problem, I can fix it in my fork:
https://github.com/kylekatarnls/Stylus.php (composer require kylekatarnls/stylus
) and propose here a pull-request.
Seems to be three different issues, all of which should be addressed.
1) Undefined offset 1
in the function addVariable
, most likely because the regex failed to match. This seems to be what @kylekatarnls describes and is a bit tricky. It should probably check if the string is enclosed in quotes and parse that differently...
2) The missing variable $indent
in the function isVariableDeclaration
, this should probably be set to an empty string, or maybe just removed...
3) The invalid value of $this->blocks
inside convertBlocksToCSS
, I think that this should be initialized into an empty array in the constructor...
PRs welcome for any or all of the problems 💌
All this is fixed here: https://github.com/AustP/Stylus.php/compare/master...kylekatarnls:master (+ the @
rules implemented) so I can cherry-pick on a branch and propose the pull request. @LinusU do you have write access on https://github.com/AustP/Stylus.php?
Hmm, I believe that preg_match('~^([\$a-zA-Z0-9_-]+)\s*=\s*(.*[^;]);*$~', $line, $matches);
wouldn't quite cut it. I think that all of the following examples needs to pass:
@foo: 1
@foo: 1;
@foo: 1;;;;
@foo: 1;@bar: 2
@foo: 1;@bar: 2;
@foo: ";;;";
@foo: ";;;";@bar: ";;"
@foo: ";;;";@bar: ";;";
And they all pass.
Maybe I'm missing something here, but won't e.g. @foo: 1;@bar: 2;
get added as { "foo": "1;@bar: 2" }
whereas before it wouldn't? The correct behaviour would be { "foo": "1", "bar": "2" }
?
Note: @
is not valid in Stylus syntax.
The current case : [^;]+
so ; is completly forbidden, you can have only one variable declaration per line.
My RegExp, just allow anything and trim semi-colon(s) at the end. But it still can handle only one declaration per line.
Multiple declaration are another thing that never worked. For that, we need a stronger string parsing like this for example: ~^(([\$a-zA-Z0-9_-]+)\s*=\s*([^;]*|"(\\\\.|[^\\\\"])*"|\'(\\\\.|[^\\\\\'])*\');*)*~
But you get in another problem: multiple lines for one value:
var = "
my text
"
body
content var
The code above is valid Stylus and here, it's no longer about the good RegExp to parse a line, but replace the line-by-line parser with a real lexer/parser/compiler system.