3
3
use super :: * ;
4
4
use serde_json:: to_string_pretty;
5
5
6
- macro_rules! test_input {
7
- ( $input: expr) => {
8
- let input = $input;
9
- let strip_exports: Option <Vec <JsWord >> = input
10
- . strip_exports
11
- . map( |v| v. into_iter( ) . map( |s| JsWord :: from( s) ) . collect( ) ) ;
12
-
13
- let reg_ctx_name: Option <Vec <JsWord >> = input
14
- . reg_ctx_name
15
- . map( |v| v. into_iter( ) . map( |s| JsWord :: from( s) ) . collect( ) ) ;
16
-
17
- let strip_ctx_name: Option <Vec <JsWord >> = input
18
- . strip_ctx_name
19
- . map( |v| v. into_iter( ) . map( |s| JsWord :: from( s) ) . collect( ) ) ;
20
-
21
- let res = transform_modules( TransformModulesOptions {
22
- src_dir: input. src_dir,
23
- root_dir: input. root_dir,
24
- input: vec![ TransformModuleInput {
25
- code: input. code. clone( ) ,
26
- path: input. filename,
27
- } ] ,
28
- source_maps: true ,
29
- minify: input. minify,
30
- transpile_ts: input. transpile_ts,
31
- transpile_jsx: input. transpile_jsx,
32
- preserve_filenames: input. preserve_filenames,
33
- explicit_extensions: input. explicit_extensions,
34
- manual_chunks: input. manual_chunks,
35
- entry_strategy: input. entry_strategy,
36
- mode: input. mode,
37
- scope: input. scope,
38
- core_module: input. core_module,
39
- strip_exports,
40
- strip_ctx_name,
41
- reg_ctx_name,
42
- strip_event_handlers: input. strip_event_handlers,
43
- is_server: input. is_server,
44
- } ) ;
45
- if input. snapshot {
46
- let input = input. code. to_string( ) ;
47
- let output = format!( "==INPUT==\n \n {}" , input) ;
48
- snapshot_res!( & res, output) ;
49
- }
50
- drop( res)
51
- } ;
52
- }
53
-
54
6
macro_rules! snapshot_res {
55
7
( $res: expr, $prefix: expr) => {
56
8
match $res {
@@ -68,8 +20,6 @@ macro_rules! snapshot_res {
68
20
let hook = to_string_pretty( & hook) . unwrap( ) ;
69
21
output += & format!( "\n /*\n {}\n */" , hook) ;
70
22
}
71
- // let map = if let Some(map) = s.map { map } else { "".to_string() };
72
- // output += format!("\n== MAP ==\n{}", map).as_str();
73
23
}
74
24
output += format!(
75
25
"\n == DIAGNOSTICS ==\n \n {}" ,
@@ -85,6 +35,56 @@ macro_rules! snapshot_res {
85
35
} ;
86
36
}
87
37
38
+ macro_rules! test_input {
39
+ ( $input: expr) => { {
40
+ let input = $input;
41
+ let code = input. code. to_string( ) ;
42
+ let snapshot = input. snapshot;
43
+ let res = test_input_fn( input) ;
44
+ if snapshot {
45
+ snapshot_res!( & res, format!( "==INPUT==\n \n {}" , code. to_string( ) ) ) ;
46
+ }
47
+ res
48
+ } } ;
49
+ }
50
+
51
+ fn test_input_fn ( input : TestInput ) -> Result < TransformOutput , anyhow:: Error > {
52
+ let strip_exports: Option < Vec < JsWord > > = input
53
+ . strip_exports
54
+ . map ( |v| v. into_iter ( ) . map ( |s| JsWord :: from ( s) ) . collect ( ) ) ;
55
+ let reg_ctx_name: Option < Vec < JsWord > > = input
56
+ . reg_ctx_name
57
+ . map ( |v| v. into_iter ( ) . map ( |s| JsWord :: from ( s) ) . collect ( ) ) ;
58
+ let strip_ctx_name: Option < Vec < JsWord > > = input
59
+ . strip_ctx_name
60
+ . map ( |v| v. into_iter ( ) . map ( |s| JsWord :: from ( s) ) . collect ( ) ) ;
61
+
62
+ transform_modules ( TransformModulesOptions {
63
+ src_dir : input. src_dir ,
64
+ root_dir : input. root_dir ,
65
+ input : vec ! [ TransformModuleInput {
66
+ code: input. code. clone( ) ,
67
+ path: input. filename,
68
+ } ] ,
69
+ source_maps : true ,
70
+ minify : input. minify ,
71
+ transpile_ts : input. transpile_ts ,
72
+ transpile_jsx : input. transpile_jsx ,
73
+ preserve_filenames : input. preserve_filenames ,
74
+ explicit_extensions : input. explicit_extensions ,
75
+ manual_chunks : input. manual_chunks ,
76
+ entry_strategy : input. entry_strategy ,
77
+ mode : input. mode ,
78
+ scope : input. scope ,
79
+ core_module : input. core_module ,
80
+ strip_exports,
81
+ strip_ctx_name,
82
+ reg_ctx_name,
83
+ strip_event_handlers : input. strip_event_handlers ,
84
+ is_server : input. is_server ,
85
+ } )
86
+ }
87
+
88
88
#[ test]
89
89
fn example_1 ( ) {
90
90
test_input ! ( TestInput {
@@ -1857,7 +1857,7 @@ export const Parent = component$(() => {
1857
1857
transpile_ts: true ,
1858
1858
transpile_jsx: true ,
1859
1859
entry_strategy: EntryStrategy :: Inline ,
1860
- strip_ctx_name: Some ( vec![ "useClientMount$" . into( ) , ] ) ,
1860
+ strip_ctx_name: Some ( vec![ "useClientMount$" . into( ) ] ) ,
1861
1861
strip_event_handlers: true ,
1862
1862
..TestInput :: default ( )
1863
1863
} ) ;
@@ -1943,34 +1943,34 @@ export const Greeter = component$(() => {
1943
1943
} ) ;
1944
1944
}
1945
1945
1946
- #[ cfg( target_os = "windows" ) ]
1947
1946
#[ test]
1948
- fn issue_188 ( ) {
1949
- let res = test_input ! ( {
1947
+ fn support_windows_paths ( ) {
1948
+ let res = test_input ! ( TestInput {
1950
1949
filename: r"components\apps\apps.tsx" . to_string( ) ,
1951
1950
src_dir: r"C:\users\apps" . to_string( ) ,
1952
1951
code: r#"
1953
- import { component$, $ } from '@builder.io/qwik';
1954
-
1955
- export const Greeter = component$(() => {
1956
- return $(() => {
1957
- return (
1958
- <div/>
1959
- )
1960
- });
1961
- });
1962
-
1963
- const d = $(()=>console.log('thing'));
1952
+ import { component$ } from '@builder.io/qwik';
1953
+ export const Greeter = component$(() => <div/>)
1964
1954
"#
1965
1955
. to_string( ) ,
1966
- transpile_ts: true ,
1967
1956
transpile_jsx: true ,
1968
- snapshot: false ,
1957
+ is_server: Some ( false ) ,
1958
+ entry_strategy: EntryStrategy :: Hook ,
1959
+ ..TestInput :: default ( )
1969
1960
} )
1970
1961
. unwrap ( ) ;
1971
- let last_module = res. modules . last ( ) . unwrap ( ) ;
1972
- assert_eq ! ( last_module. path, r"C:/users/apps/components/apps/apps.tsx" )
1962
+ // verify that none of the modules have a path that contains backslashes
1963
+ for module in res. modules {
1964
+ assert ! ( !module. path. contains( '\\' ) ) ;
1965
+ }
1973
1966
}
1967
+ // filler to retain assertion line numbers
1968
+ //
1969
+ //
1970
+ //
1971
+ //
1972
+ //
1973
+
1974
1974
#[ test]
1975
1975
fn issue_476 ( ) {
1976
1976
test_input ! ( TestInput {
0 commit comments