-
Notifications
You must be signed in to change notification settings - Fork 357
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
Add sass-parser
support for the @use
rule
#2389
Open
nex3
wants to merge
13
commits into
main
Choose a base branch
from
parser-use
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
91cb758
Add `sass-parser` support for the `@use` rule
nex3 355ee32
Update other packages
nex3 6613bb8
Don't add spaces at the end of `toCssIdentifier()`
nex3 c28d3fa
Add tests for stringifying `ConfiguredVariable`
nex3 c997979
Rename ConfiguredVariable.name to variable and .value to expression
nex3 292c821
Merge branch 'main' of github.com:sass/dart-sass into parser-use
nex3 fbfc008
Fix test failures
nex3 4216c16
Reformat
nex3 5fad9d1
Rename ConfiguredVariable.variable to .variableName
nex3 3878e5a
Apply suggestions from code review
nex3 65f0578
Code review
nex3 764ab63
Merge branch 'parser-use' of github.com:sass/dart-sass into parser-use
nex3 a8d887c
Merge branch 'main' of github.com:sass/dart-sass into parser-use
nex3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
// Copyright 2024 Google Inc. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import 'package:charcode/charcode.dart'; | ||
import 'package:string_scanner/string_scanner.dart'; | ||
|
||
import 'character.dart'; | ||
|
||
extension StringExtension on String { | ||
/// Returns a minimally-escaped CSS identifiers whose contents evaluates to | ||
nex3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// [text]. | ||
/// | ||
/// Throws a [FormatException] if [text] cannot be represented as a CSS | ||
/// identifier (such as the empty string). | ||
String toCssIdentifier() { | ||
var buffer = StringBuffer(); | ||
var scanner = SpanScanner(this); | ||
|
||
void writeEscape(int character) { | ||
buffer.writeCharCode($backslash); | ||
buffer.write(character.toRadixString(16)); | ||
if (scanner.peekChar() case int(isHex: true) || null) { | ||
buffer.writeCharCode($space); | ||
} | ||
} | ||
|
||
void consumeSurrogatePair(int character) { | ||
if (scanner.peekChar(1) case null || int(isLowSurrogate: false)) { | ||
scanner.error( | ||
"An individual surrogates can't be represented as a CSS " | ||
nex3 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"identifier.", | ||
length: 1); | ||
} else if (character.isPrivateUseHighSurrogate) { | ||
writeEscape(combineSurrogates(scanner.readChar(), scanner.readChar())); | ||
} else { | ||
buffer.writeCharCode(scanner.readChar()); | ||
buffer.writeCharCode(scanner.readChar()); | ||
} | ||
} | ||
|
||
void consumeBody() { | ||
loop: | ||
while (true) { | ||
switch (scanner.peekChar()) { | ||
case null: | ||
break loop; | ||
|
||
case 0: | ||
scanner | ||
.error("The U+0000 can't be represented as a CSS identifier."); | ||
|
||
case int character when character.isHighSurrogate: | ||
consumeSurrogatePair(character); | ||
|
||
case int(isLowSurrogate: true): | ||
scanner.error( | ||
"An individual surrogate can't be represented as a CSS " | ||
"identifier.", | ||
length: 1); | ||
|
||
case int(isName: true, isPrivateUseBMP: false): | ||
buffer.writeCharCode(scanner.readChar()); | ||
|
||
case _: | ||
writeEscape(scanner.readChar()); | ||
} | ||
} | ||
} | ||
|
||
if (scanner.scanChar($dash)) { | ||
if (scanner.isDone) return '\\2d'; | ||
|
||
buffer.writeCharCode($dash); | ||
|
||
if (scanner.scanChar($dash)) { | ||
buffer.writeCharCode($dash); | ||
consumeBody(); | ||
return buffer.toString(); | ||
} | ||
} | ||
|
||
switch (scanner.peekChar()) { | ||
case null: | ||
scanner.error( | ||
"The empty string can't be represented as a CSS identifier."); | ||
|
||
case 0: | ||
scanner.error("The U+0000 can't be represented as a CSS identifier."); | ||
|
||
case int character when character.isHighSurrogate: | ||
consumeSurrogatePair(character); | ||
|
||
case int(isLowSurrogate: true): | ||
scanner.error( | ||
"An individual surrogate can't be represented as a CSS " | ||
"identifier.", | ||
length: 1); | ||
|
||
case int(isNameStart: true, isPrivateUseBMP: false): | ||
buffer.writeCharCode(scanner.readChar()); | ||
|
||
case _: | ||
writeEscape(scanner.readChar()); | ||
} | ||
|
||
consumeBody(); | ||
return buffer.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.2.7 | ||
|
||
* Add support for parsing the `@use` rule. | ||
|
||
## 0.2.6 | ||
|
||
* No user-visible changes. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it is intended, 1.79.6 has not been released.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, thanks