Skip to content

Commit 4a994a1

Browse files
authored
Merge pull request #244 from wechat-miniprogram/feat-advanced-class-style-binding
Add advanced class style binding
2 parents 2321904 + 1b7b564 commit 4a994a1

File tree

13 files changed

+960
-68
lines changed

13 files changed

+960
-68
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

glass-easel-template-compiler/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ js_bindings = []
2222
c_bindings = ["cbindgen"]
2323

2424
[dependencies]
25+
cssparser = "0.34"
2526
entities = "1"
2627
lazy_static = "1"
2728
regex = "^1.10.4"

glass-easel-template-compiler/src/parse/expr.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,12 @@ impl Expression {
12701270
}
12711271
}
12721272

1273-
pub(super) fn validate_scopes(&self, ps: &mut ParseState, scopes: &[(CompactString, Range<Position>)], limit: usize) -> bool {
1273+
pub(super) fn validate_scopes(
1274+
&self,
1275+
ps: &mut ParseState,
1276+
scopes: &[(CompactString, Range<Position>)],
1277+
limit: usize,
1278+
) -> bool {
12741279
let index = if let Self::DataField { name, location } = self {
12751280
scopes
12761281
.iter()

glass-easel-template-compiler/src/parse/mod.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,17 @@ impl Position {
423423
pub fn line_col_utf16<'s>(&self) -> (usize, usize) {
424424
(self.line as usize, self.utf16_col as usize)
425425
}
426+
427+
pub(crate) fn add_offset(&self, other: Self) -> Self {
428+
Self {
429+
line: self.line + other.line,
430+
utf16_col: if other.line == 0 {
431+
self.utf16_col + other.utf16_col
432+
} else {
433+
other.utf16_col
434+
},
435+
}
436+
}
426437
}
427438

428439
/// Template parsing error object.
@@ -504,6 +515,12 @@ pub enum ParseErrorKind {
504515
DeprecatedAttribute,
505516
IncompatibleWithWxAttribute,
506517
UninitializedScope,
518+
InvalidClassNames,
519+
DuplicatedClassNames,
520+
IncompatibleWithClassColonAttributes,
521+
InvalidInlineStyleString,
522+
DuplicatedStylePropertyNames,
523+
IncompatibleWithStyleColonAttributes,
507524
}
508525

509526
impl ParseErrorKind {
@@ -541,8 +558,22 @@ impl ParseErrorKind {
541558
Self::EmptyExpression => "the expression is empty",
542559
Self::InvalidEndTag => "invalid end tag",
543560
Self::DeprecatedAttribute => "this attribute is deprecated",
544-
Self::IncompatibleWithWxAttribute => "this attribute is incompatible with wx:* attribute",
561+
Self::IncompatibleWithWxAttribute => {
562+
"this attribute is incompatible with wx:* attribute"
563+
}
545564
Self::UninitializedScope => "this variable is uninitialized",
565+
Self::InvalidClassNames => "the class name list contains invalid identifiers",
566+
Self::DuplicatedClassNames => "the class name list contains duplicated class names",
567+
Self::IncompatibleWithClassColonAttributes => {
568+
"class data bindings are incompatible with `class:` attributes"
569+
}
570+
Self::InvalidInlineStyleString => "the inline style is invalid",
571+
Self::DuplicatedStylePropertyNames => {
572+
"the inline style contains duplicated style property names"
573+
}
574+
Self::IncompatibleWithStyleColonAttributes => {
575+
"style data bindings are incompatible with `style:` attributes"
576+
}
546577
}
547578
}
548579

@@ -582,6 +613,12 @@ impl ParseErrorKind {
582613
Self::DeprecatedAttribute => ParseErrorLevel::Warn,
583614
Self::IncompatibleWithWxAttribute => ParseErrorLevel::Error,
584615
Self::UninitializedScope => ParseErrorLevel::Error,
616+
Self::InvalidClassNames => ParseErrorLevel::Error,
617+
Self::DuplicatedClassNames => ParseErrorLevel::Error,
618+
Self::IncompatibleWithClassColonAttributes => ParseErrorLevel::Error,
619+
Self::InvalidInlineStyleString => ParseErrorLevel::Error,
620+
Self::DuplicatedStylePropertyNames => ParseErrorLevel::Error,
621+
Self::IncompatibleWithStyleColonAttributes => ParseErrorLevel::Error,
585622
}
586623
}
587624
}

0 commit comments

Comments
 (0)