vaderjs 1.3.3-alpha-90 → 1.3.3-alpha-92

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/vader.js +23 -9
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "vaderjs",
3
3
  "description": "A Reactive library aimed to helping you build reactive applications inspired by react.js",
4
4
  "module": "vader.js",
5
- "version": "1.3.3-alpha-90",
5
+ "version": "1.3.3-alpha-92",
6
6
  "bin": {
7
7
  "vader": "./vader.js"
8
8
  },
package/vader.js CHANGED
@@ -559,7 +559,9 @@ function Compiler(func, file) {
559
559
  if (line.includes('import')) {
560
560
  // Regular expression for matching import() statements
561
561
  let asyncimportMatch = line.match(/import\s*\((.*)\)/gs);
562
- let regularimportMatch = line.match(/import\s+([\w\s{},]*)\s*from\s*(['"][^'"]+['"])(?![^<]*>)/gs);
562
+ // handle named imports and unnamed import 'path'
563
+ let regularimportMatch = line.match(/import\s*([a-zA-Z0-9_-]+)?\s*from\s*('(.*)'|"(.*)")|import\s*('(.*)'|"(.*)")/gs);
564
+
563
565
 
564
566
  if (asyncimportMatch) {
565
567
  asyncimportMatch.forEach(async (match) => {
@@ -574,6 +576,9 @@ function Compiler(func, file) {
574
576
 
575
577
  break;
576
578
  case path && path.includes('module.css'):
579
+
580
+
581
+
577
582
  let css = await fs.readFileSync(process.cwd() + path, 'utf8')
578
583
  css = css.replaceAll('.', '')
579
584
 
@@ -609,11 +614,22 @@ function Compiler(func, file) {
609
614
 
610
615
  if (regularimportMatch) {
611
616
  for (let match of regularimportMatch) {
612
- let beforeimport = match
613
- let path = match.split('from')[1].trim() || match.split('import')[1]
617
+ let beforeimport = match
618
+ // import {name} from 'path' or import 'path'
619
+ let path = match.split('from')[1] ? match.split('from')[1].trim() : match.split('import')[1].trim()
614
620
  let newImport = ''
615
621
  let name = match.split('import')[1].split('from')[0].trim()
616
-
622
+
623
+ path = path.replace(/'/g, '').trim().replace(/"/g, '').trim()
624
+ let deep = path.split('/').length - 1
625
+ for (let i = 0; i < deep; i++) {
626
+ path = path.split('../').join('')
627
+ path = path.split('./').join('')
628
+ }
629
+ path = path.replace(/'/g, '').trim().replace(/"/g, '').trim()
630
+ // remove double / from path
631
+ path = path.split('//').join('/')
632
+
617
633
  switch (true) {
618
634
  case path && path.includes('json'):
619
635
  path = path.replace(';', '')
@@ -624,8 +640,7 @@ function Compiler(func, file) {
624
640
 
625
641
  path = path.replace(';', '')
626
642
  path = path.replace(/'/g, '').trim().replace(/"/g, '').trim()
627
- path = path.replaceAll('.jsx', '.js');
628
- path = path.replaceAll('../', '');
643
+ path = path.replaceAll('.jsx', '.js');
629
644
 
630
645
  let css = fs.readFileSync(process.cwd() + '/' + path, 'utf8')
631
646
 
@@ -633,8 +648,7 @@ function Compiler(func, file) {
633
648
  newImport = `let ${name} = ${JSON.stringify(parse(css))}`
634
649
  string = string.replace(beforeimport, newImport)
635
650
  break;
636
- case path && path.endsWith('.css'):
637
- console.log(path)
651
+ case path && path.endsWith('.css'):
638
652
  string = string.replace(beforeimport, '')
639
653
  newImport = ``
640
654
  break;
@@ -657,7 +671,7 @@ function Compiler(func, file) {
657
671
  path = path.replaceAll('.jsx', '.js');
658
672
 
659
673
 
660
- string = string.replace(beforePath, "'" + path + "'")
674
+ string = string.replace(beforePath, path)
661
675
  break;
662
676
 
663
677
  }