From fd1f5194e5f274d9b901d2ccc56bdcb6b491969a Mon Sep 17 00:00:00 2001 From: owjs3901 Date: Fri, 17 Jan 2025 17:26:14 +0900 Subject: [PATCH] Add some properties to special properties --- .changeset/dirty-wolves-destroy.md | 5 +++ libs/extractor/src/lib.rs | 13 +++++++ ...ractor__tests__ignore_special_props-2.snap | 8 +++++ libs/extractor/src/utils.rs | 34 ++++++++++++++----- 4 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 .changeset/dirty-wolves-destroy.md create mode 100644 libs/extractor/src/snapshots/extractor__tests__ignore_special_props-2.snap diff --git a/.changeset/dirty-wolves-destroy.md b/.changeset/dirty-wolves-destroy.md new file mode 100644 index 00000000..4ccefa31 --- /dev/null +++ b/.changeset/dirty-wolves-destroy.md @@ -0,0 +1,5 @@ +--- +"@devup-ui/wasm": patch +--- + +Add placeholder, maxLength, minLength to special properties diff --git a/libs/extractor/src/lib.rs b/libs/extractor/src/lib.rs index 59a5ce42..fd205ae4 100644 --- a/libs/extractor/src/lib.rs +++ b/libs/extractor/src/lib.rs @@ -168,6 +168,19 @@ mod tests { } ) .unwrap()); + + reset_class_map(); + assert_debug_snapshot!(extract( + "test.tsx", + r#"import {Input} from '@devup-ui/core' + + "#, + ExtractOption { + package: "@devup-ui/core".to_string(), + css_file: None + } + ) + .unwrap()); } #[test] #[serial] diff --git a/libs/extractor/src/snapshots/extractor__tests__ignore_special_props-2.snap b/libs/extractor/src/snapshots/extractor__tests__ignore_special_props-2.snap new file mode 100644 index 00000000..e821c06c --- /dev/null +++ b/libs/extractor/src/snapshots/extractor__tests__ignore_special_props-2.snap @@ -0,0 +1,8 @@ +--- +source: libs/extractor/src/lib.rs +expression: "extract(\"test.tsx\",\nr#\"import {Input} from '@devup-ui/core'\n \n \"#,\nExtractOption\n{ package: \"@devup-ui/core\".to_string(), css_file: None }).unwrap()" +--- +ExtractOutput { + styles: [], + code: ";\n", +} diff --git a/libs/extractor/src/utils.rs b/libs/extractor/src/utils.rs index 2d1cfc8a..b7b70088 100644 --- a/libs/extractor/src/utils.rs +++ b/libs/extractor/src/utils.rs @@ -1,3 +1,6 @@ +use once_cell::sync::Lazy; +use std::collections::HashSet; + /// Convert a value to a pixel value pub fn convert_value(value: &str) -> String { let value = value.to_string(); @@ -8,18 +11,31 @@ pub fn convert_value(value: &str) -> String { value } +static SPECIAL_PROPERTIES: Lazy> = Lazy::new(|| { + let mut set = HashSet::<&str>::new(); + for prop in [ + "style", + "className", + "role", + "ref", + "key", + "alt", + "src", + "children", + "placeholder", + "maxLength", + "minLength", + ] { + set.insert(prop); + } + set +}); + pub fn is_special_property(name: &str) -> bool { - name == "style" - || name == "className" - || name.starts_with("on") + name.starts_with("on") || name.starts_with("data-") || name.starts_with("aria-") - || name == "role" - || name == "ref" - || name == "key" - || name == "alt" - || name == "src" - || name == "children" + || SPECIAL_PROPERTIES.contains(name) } #[cfg(test)]