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

Dev #193

Merged
merged 4 commits into from
Dec 24, 2023
Merged

Dev #193

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions integrations/vscode/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions integrations/vscode/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vscode-paperclip",
"displayName": "Paperclip",
"version": "20.3.8",
"version": "20.3.10",
"publisher": "crcn",
"preview": true,
"private": true,
Expand Down Expand Up @@ -99,9 +99,9 @@
},
"dependencies": {
"@improbable-eng/grpc-web-node-http-transport": "^0.15.0",
"@paperclip-ui/common": "^20.3.8",
"@paperclip-ui/proto": "^20.3.8",
"@paperclip-ui/releases": "^20.3.8",
"@paperclip-ui/common": "^20.3.10",
"@paperclip-ui/proto": "^20.3.10",
"@paperclip-ui/releases": "^20.3.10",
"color": "^4.2.3",
"execa": "^5.1.1",
"get-port": "^3.2.0",
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"useNx": true,
"npmClient": "yarn",
"version": "20.3.8"
"version": "20.3.10"
}
30 changes: 28 additions & 2 deletions libs/compiler-react/src/code_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ fn compile_document(document: &ast::Document, context: &mut Context) {

collect_imports(document, &mut imports, context);
compile_imports(&imports, context);
compile_utils(context);
compile_nested_components(document, context);
for item in &document.body {
match item.get_inner() {
Expand Down Expand Up @@ -265,6 +266,25 @@ fn compile_imports(imports: &BTreeMap<String, Option<String>>, context: &mut Con
}
}

fn compile_utils(context: &mut Context) {
context.add_buffer("\n");
context.add_buffer("const omit = (obj, keys) => {\n");
context.start_block();
context.add_buffer("const newObj = {};\n");
context.add_buffer("for (const key in obj) {\n");
context.start_block();
context.add_buffer("if (!keys.includes(key)) {\n");
context.start_block();
context.add_buffer("newObj[key] = obj[key];\n");
context.end_block();
context.add_buffer("}\n");
context.end_block();
context.add_buffer("}\n");
context.add_buffer("return newObj;\n");
context.end_block();
context.add_buffer("};\n");
}

macro_rules! compile_children {
($expr: expr, $cb: expr, $context: expr, $include_ary: expr) => {{
if $include_ary {
Expand Down Expand Up @@ -458,7 +478,13 @@ fn compile_element(element: &ast::Element, info: &Info, context: &mut Context) {
context.add_buffer("React.createElement(");

if let Some(name) = &element.name {
context.add_buffer(format!("{}.{}.as || ", context.ctx_name, name).as_str());
context.add_buffer(
format!(
"{}.{} && {}.{}.as || ",
context.ctx_name, name, context.ctx_name, name
)
.as_str(),
);
}

context.add_buffer(format!("{}, ", tag_name).as_str());
Expand Down Expand Up @@ -546,7 +572,7 @@ fn compile_element_parameters(element: &ast::Element, info: &Info, context: &mut
context.add_buffer("{\n");
context.start_block();
if let Some(name) = &element.name {
context.add_buffer(format!("...{}.{},\n", context.ctx_name, name).as_str());
context.add_buffer(format!("...omit({}.{}, [\"as\"]),\n", context.ctx_name, name).as_str());
}

let mut attrs = raw_attrs.iter().peekable();
Expand Down
Loading
Loading