Skip to content

Commit

Permalink
Fix import compilation of none-project #38
Browse files Browse the repository at this point in the history
  • Loading branch information
nilq committed Jul 7, 2020
1 parent c038489 commit 043f504
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/wu/compiler/compiler.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::*;

use std::collections::HashMap;
use std::path::Path;
use std::path::{Path, Component};
use std::ffi::OsStr;

#[derive(Clone, PartialEq)]
pub enum FlagImplicit {
Expand Down Expand Up @@ -182,7 +183,7 @@ impl<'g> Generator<'g> {
}

Import(ref name, ref specifics) => {
let file_path = if let Some(new_path) = self.import_map.get(&statement.pos) {
let mut file_path = if let Some(new_path) = self.import_map.get(&statement.pos) {
format!(
"{}",
new_path
Expand All @@ -197,6 +198,16 @@ impl<'g> Generator<'g> {
format!("{}/{}", my_folder.to_str().unwrap(), name)
};

if file_path.starts_with("./") {
file_path = file_path[2..].to_string()
}

let real_path = &Path::new(&file_path)
.iter()
.map(|x: &OsStr| format!("{}", x.to_str().unwrap()))
.collect::<Vec<String>>()
.join(".");

let mut result = String::new();

if let Some(abs_path) = self.import_map.get(&statement.pos) {
Expand All @@ -207,7 +218,7 @@ impl<'g> Generator<'g> {
);
result.push_str(&format!("local {0} = require('{0}')\n", name))
} else {
result = format!("local {} = require('{}')\n", name, file_path)
result = format!("local {} = require('{}')\n", name, real_path)
}

for specific in specifics {
Expand Down

0 comments on commit 043f504

Please sign in to comment.