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

feat: add ignoreUnclosed option to nextToken method #1191

Merged
merged 1 commit into from Sep 25, 2018
Merged

feat: add ignoreUnclosed option to nextToken method #1191

merged 1 commit into from Sep 25, 2018

Conversation

shellscape
Copy link
Contributor

This PR stems from an issue in postcss-less and a short discussion on twitter with @ai.

Use Case

PostCSS v7 has a wonderful parser class structure that enabled syntaxes to be created by inheriting from the base Parser class and selectively overriding methods to handle syntax nuances - all without having to reimplement a parser or tokenizer. That's a massive advantage to developers. However, there are some strict rules hardcoded into the tokenizer. Because the tokenizer is optimized for performance, it cannot be made a class to be inherited from. A mechanism is then needed to work around/with the hardcoded tokenizer rules.

In some situations it would be preferable to fetch the next token from a tokenizer while ignoring any unclosed errors for only the next token request. This is different than instantiating the tokenizer with the ignoreErrors options, as it only ignores unclosed for a single tokenizer.nextToken() request.

This PR implements an ignoreUnclosed option. The naming of that option was chosen because that option is only used on lines where the else cases result in the unclosed(...) method being called, and an "Unclosed X" error is thrown. Hence the naming is more specific, but should aid in usability and providing a distinction between the top-level tokenizer option ignoreErrors and this new nextToken method option.

Example Usage:

// default value for `nextToken` opts is `{}`
// default value for ignoreUnclosed is `false`
this.tokenizer.nextToken({ ignoreUnclosed: true });

@ai ai merged commit b08719b into postcss:master Sep 25, 2018
@shellscape
Copy link
Contributor Author

🎉 thank you!

@ai
Copy link
Member

ai commented Sep 25, 2018

Released in 7.0.3

@ai ai mentioned this pull request Jan 19, 2023
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