Skip to content

Commit

Permalink
perf: replace_attr_values use std HashMap
Browse files Browse the repository at this point in the history
  • Loading branch information
SyMind committed Sep 21, 2024
1 parent 719cb9f commit b5dc5f3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
21 changes: 15 additions & 6 deletions binding.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@

/* auto-generated by NAPI-RS */

export interface TransformOutput {
code: string
map?: string
output?: string
}
export interface Caller {
name?: string
previousExport?: string
Expand All @@ -25,4 +20,18 @@ export interface State {
*/
caller?: Caller
}
export declare function transform(code: string, config: Buffer, state?: State | undefined | null): Promise<string>
export interface TransformOutput {
code: string
map?: string
output?: string
}
export interface JsCaller {
name?: string
previousExport?: string
}
export interface JsState {
filePath?: string
componentName?: string
caller?: JsCaller
}
export declare function transform(code: string, config: Buffer, jsState?: JsState | undefined | null): Promise<string>
4 changes: 3 additions & 1 deletion crates/core/src/core/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashMap;

use linked_hash_map::LinkedHashMap;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -159,7 +161,7 @@ pub struct Config {
/// Replace an attribute value by an other.
/// The main usage of this option is to change an icon color to "currentColor" in order to inherit from text color.
#[serde(default)]
pub replace_attr_values: Option<LinkedHashMap<String, String>>,
pub replace_attr_values: Option<HashMap<String, String>>,

/// Specify a JSX runtime to use.
/// * "classic": adds `import * as React from 'react'` on the top of file
Expand Down
11 changes: 6 additions & 5 deletions crates/core/src/replace_jsx_attribute.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use linked_hash_map::LinkedHashMap;
use std::collections::HashMap;

use swc_core::common::SyntaxContext;
use swc_core::{
common::DUMMY_SP,
Expand All @@ -8,7 +9,7 @@ use swc_core::{
use super::core;

pub struct Visitor {
values: LinkedHashMap<String, String>,
values: HashMap<String, String>,
}

impl Visitor {
Expand Down Expand Up @@ -77,7 +78,7 @@ mod tests {

use super::*;

fn code_test(input: &str, replace_attr_values: LinkedHashMap<String, String>, expected: &str) {
fn code_test(input: &str, replace_attr_values: HashMap<String, String>, expected: &str) {
let cm = Arc::<SourceMap>::default();
let fm = cm.new_source_file(FileName::Anon.into(), input.to_string());

Expand Down Expand Up @@ -115,7 +116,7 @@ mod tests {

#[test]
fn should_replace_attribute_values_1() {
let mut replace_attr_values = LinkedHashMap::new();
let mut replace_attr_values = HashMap::new();
replace_attr_values.insert("cool".to_string(), "not cool".to_string());
code_test(
r#"<div something="cool"/>;"#,
Expand All @@ -126,7 +127,7 @@ mod tests {

#[test]
fn should_replace_attribute_values_2() {
let mut replace_attr_values = LinkedHashMap::new();
let mut replace_attr_values = HashMap::new();
replace_attr_values.insert("cool".to_string(), "{props.color}".to_string());
code_test(
r#"<div something="cool"/>;"#,
Expand Down

0 comments on commit b5dc5f3

Please sign in to comment.