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

perf: replace_attr_values use std HashMap #32

Merged
merged 1 commit into from
Sep 21, 2024
Merged
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
21 changes: 15 additions & 6 deletions binding.d.ts
Original file line number Diff line number Diff line change
@@ -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
@@ -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};

@@ -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
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,
@@ -8,7 +9,7 @@ use swc_core::{
use super::core;

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

impl Visitor {
@@ -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());

@@ -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"/>;"#,
@@ -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"/>;"#,