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

"LeftCurlyBracket is expected" error when using parseSelector: false #56

Closed
davidkudera opened this issue Sep 10, 2017 · 4 comments
Closed

Comments

@davidkudera
Copy link

@davidkudera davidkudera commented Sep 10, 2017

Hi, I wanted to parse some styles with parseSelector: false, but when I do that I see following error:

Parse error: LeftCurlyBracket is expected
    1 |div {}
-------------^

Steps to reproduce:

$ mkdir css-test && cd css-test
$ npm install css-tree

Create index.js file with this code:

var parse = require('css-tree').parse;

try {
	var ast = parse('div {}', {
		parseSelector: false
	});

	console.log(ast);
} catch (e) {
	console.log(e.formattedMessage);
}

and run

$ node index.js

Interesting is that when I clone this repository and try to write the code above as test, it works just fine.

Versions: both 1.0.0-alpha22 and 171664a.

@peterbe
Copy link
Contributor

@peterbe peterbe commented Sep 10, 2017

I get this too

> const csstree = require('css-tree')
undefined
> const text = `body, p { font-weight: bold; }
... body { border: 1px solid red; }
... `
undefined
>
> const ast =csstree.parse(text, {parseValue: false, parseSelector: false})
CssSyntaxError: LeftCurlyBracket is expected

> csstree.parse(text.trim(), {parseValue: false, parseSelector: true})
{ type: 'StyleSheet',
  loc: null,
  children:
   List {
     cursor: null,
     head: { prev: null, next: [Object], data: [Object] },
     tail: { prev: [Object], next: null, data: [Object] } } }

@lahmatiy lahmatiy closed this in 97b4920 Sep 10, 2017
@lahmatiy
Copy link
Member

@lahmatiy lahmatiy commented Sep 10, 2017

Your case let me to confirm a problem that I could not reproduce in the tests. It's a bit complicated and all around balance finding in tokenizer (can be reproduced only when token count less that input length; my test case was ? { } – input length equal to token count).
You could not reproduce the problem it in the tests because parser re-use tokenizer and last one re-use buffers. Therefore previous tests "fix" up your test by data left in the buffer.
Never mind... now it fixed, release is coming.
Good finding. Thank you!

@davidkudera
Copy link
Author

@davidkudera davidkudera commented Sep 10, 2017

awesome, thank you 👏

@lahmatiy
Copy link
Member

@lahmatiy lahmatiy commented Sep 10, 2017

1.0.0-alpha23 with fix is out :)

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.