-
Notifications
You must be signed in to change notification settings - Fork 9
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: initial implementation of key value block attributes #49
Conversation
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.
Hi, thank you for contribution.
Since you anyway plan to use transform_block
why you need using of NodeBlock
at all?
The aim of this enum is to save blocks of unparsable rust code aka InvalidBlock
mainly for IDE purposes (or better error reporting).
It also can be used as replacement for transform_block in some cases.
But if we decide to keep NodeBlock in position of attribute value, i'd recommend to rename this type.
From the rustdoc of
I don't get what you mean. Should I implement this inside // Code copied from NodeBlock::parse_recoverable
Err(e) if parser.config().recover_block => {
parser.push_diagnostic(e);
NodeBlock::Invalid(parser.parse_simple(input)?)
}
Err(e) => {
parser.push_diagnostic(e);
return None;
} |
You can simply add You don't need to implement |
I have updated the implementation to reflect the discussion in #54.
Demos:
Parse result:NodeElement {
open_tag: OpenTag {
token_lt: Lt,
name: Path(
ExprPath {
attrs: [],
qself: None,
path: Path {
leading_colon: None,
segments: [
PathSegment {
ident: Ident {
sym: MyComponent,
},
arguments: PathArguments::None,
},
],
},
},
),
generics: Generics {
lt_token: None,
params: [],
gt_token: None,
where_clause: None,
},
attributes: [
Attribute(
KeyedAttribute {
key: Path(
ExprPath {
attrs: [],
qself: None,
path: Path {
leading_colon: None,
segments: [
PathSegment {
ident: Ident {
sym: style,
},
arguments: PathArguments::None,
},
],
},
},
),
possible_value: Value(
KeyValueAttribute {
token_eq: Eq,
value: Braced(
InvalidBlock {
brace: Brace,
body: TokenStream [
Group {
delimiter: Brace,
stream: TokenStream [
Ident {
sym: width,
},
Punct {
char: ':',
spacing: Alone,
},
Literal {
lit: "20vw",
span: bytes(1..7),
},
],
},
],
},
),
},
),
},
),
],
end_tag: OpenTagEnd {
token_solidus: Some(
Slash,
),
token_gt: Gt,
},
},
children: [],
close_tag: None,
},
<Suspend fallback={<div> Loading </div>}>
<MyView />
</Suspend> Parse result:NodeElement {
open_tag: OpenTag {
token_lt: Lt,
name: Path(
ExprPath {
attrs: [],
qself: None,
path: Path {
leading_colon: None,
segments: [
PathSegment {
ident: Ident {
sym: Suspend,
},
arguments: PathArguments::None,
},
],
},
},
),
generics: Generics {
lt_token: None,
params: [],
gt_token: None,
where_clause: None,
},
attributes: [
Attribute(
KeyedAttribute {
key: Path(
ExprPath {
attrs: [],
qself: None,
path: Path {
leading_colon: None,
segments: [
PathSegment {
ident: Ident {
sym: fallback,
},
arguments: PathArguments::None,
},
],
},
},
),
possible_value: Value(
AttributeValueExpr {
token_eq: Eq,
value: Braced(
InvalidBlock {
brace: Brace,
body: TokenStream [
Punct {
char: '<',
spacing: Alone,
},
Ident {
sym: div,
},
Punct {
char: '>',
spacing: Alone,
},
Ident {
sym: Loading,
},
Punct {
char: '<',
spacing: Alone,
},
Punct {
char: '/',
spacing: Alone,
},
Ident {
sym: div,
},
Punct {
char: '>',
spacing: Alone,
},
],
},
),
},
),
},
),
],
end_tag: OpenTagEnd {
token_solidus: None,
token_gt: Gt,
},
},
children: [
Element(
NodeElement {
open_tag: OpenTag {
token_lt: Lt,
name: Path(
ExprPath {
attrs: [],
qself: None,
path: Path {
leading_colon: None,
segments: [
PathSegment {
ident: Ident {
sym: MyView,
},
arguments: PathArguments::None,
},
],
},
},
),
generics: Generics {
lt_token: None,
params: [],
gt_token: None,
where_clause: None,
},
attributes: [],
end_tag: OpenTagEnd {
token_solidus: Some(
Slash,
),
token_gt: Gt,
},
},
children: [],
close_tag: None,
},
),
],
close_tag: Some(
CloseTag {
start_tag: CloseTagStart {
token_lt: Lt,
token_solidus: Slash,
},
name: Path(
ExprPath {
attrs: [],
qself: None,
path: Path {
leading_colon: None,
segments: [
PathSegment {
ident: Ident {
sym: Suspend,
},
arguments: PathArguments::None,
},
],
},
},
),
generics: Generics {
lt_token: None,
params: [],
gt_token: None,
where_clause: None,
},
token_gt: Gt,
},
),
} Let me know if you have any suggestions. |
Also add tests and remove unused structure.
@tachibanayui I have added some minor changes directly to your PR, please review, if you approve i am ready to merge it. Forgot to mention it first, Thanks for contribution! awesome work! |
Hi, I have checked your commit and it's look good to me. Thanks for approving my work! |
This is my initial attempt at implementing block support for the Key-value attribute described in #48 by adding another variant of
NodeBlock
intoKeyedAttributeValue
. I also implementParseRecoverable
trait forKeyedAttribute
so thattransform_block()
will work inside key-value attributes.