Skip to content

Commit

Permalink
- Issue #82: More specific error message in case of file resolution f…
Browse files Browse the repository at this point in the history
…ails related to //css_import
  • Loading branch information
oleg-shilo committed Aug 10, 2017
1 parent f5805f3 commit d5ac9ee
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 36 deletions.
8 changes: 7 additions & 1 deletion Source/csparser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,8 @@ public ImportInfo(string statement, string parentScript)

string[] parts = CSharpParser.SplitByDelimiter(statementToParse, DirectiveDelimiters);

this.file = parts[0];
this.file =
this.rawStatement = parts[0];

if (!Path.IsPathRooted(this.file) && ResolveRelativeFromParentScriptLocation)
this.file = Path.Combine(Path.GetDirectoryName(parentScript), this.file);
Expand Down Expand Up @@ -323,6 +324,11 @@ private void InternalInit(string[] statementParts, int startIndex)
/// </summary>
public string file;

/// <summary>
/// The original name of the file to be imported.
/// </summary>
public string rawStatement;

/// <summary>
/// Renaming instructions (old_name vs. new_name)
/// </summary>
Expand Down
79 changes: 44 additions & 35 deletions Source/fileparser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public static int Compare(ParsingParams xPrams, ParsingParams yPrams)
}

public bool preserveMain = false;
public string rawStatement;

#endregion Public interface...

Expand All @@ -122,6 +123,7 @@ class ScriptInfo
public ScriptInfo(CSharpParser.ImportInfo info)
{
this.fileName = info.file;
parseParams.rawStatement = info.rawStatement;
parseParams.AddRenameNamespaceMap(info.renaming);
parseParams.preserveMain = info.preserveMain;
}
Expand Down Expand Up @@ -809,54 +811,61 @@ void Init(string fileName, string[] searchDirs)

void ProcessFile(ScriptInfo fileInfo)
{
FileParserComparer fileComparer = new FileParserComparer();

FileParser importedFile = new FileParser(fileInfo.fileName, fileInfo.parseParams, false, true, this.SearchDirs, throwOnError); //do not parse it yet (the third param is false)
if (fileParsers.BinarySearch(importedFile, fileComparer) < 0)
try
{
if (File.Exists(importedFile.fileName))
FileParserComparer fileComparer = new FileParserComparer();

FileParser importedFile = new FileParser(fileInfo.fileName, fileInfo.parseParams, false, true, this.SearchDirs, throwOnError); //do not parse it yet (the third param is false)
if (fileParsers.BinarySearch(importedFile, fileComparer) < 0)
{
importedFile.ProcessFile(); //parse now namespaces, ref. assemblies and scripts; also it will do namespace renaming
if (File.Exists(importedFile.fileName))
{
importedFile.ProcessFile(); //parse now namespaces, ref. assemblies and scripts; also it will do namespace renaming

this.fileParsers.Add(importedFile);
this.fileParsers.Sort(fileComparer);
this.fileParsers.Add(importedFile);
this.fileParsers.Sort(fileComparer);

foreach (string namespaceName in importedFile.ReferencedNamespaces)
PushNamespace(namespaceName);
foreach (string namespaceName in importedFile.ReferencedNamespaces)
PushNamespace(namespaceName);

foreach (string asmName in importedFile.ReferencedAssemblies)
PushAssembly(asmName);
foreach (string asmName in importedFile.ReferencedAssemblies)
PushAssembly(asmName);

foreach (string packageName in importedFile.Packages)
PushPackage(packageName);
foreach (string packageName in importedFile.Packages)
PushPackage(packageName);

foreach (string file in importedFile.Precompilers)
PushPrecompiler(file);
foreach (string file in importedFile.Precompilers)
PushPrecompiler(file);

foreach (ScriptInfo scriptFile in importedFile.ReferencedScripts)
ProcessFile(scriptFile);
foreach (ScriptInfo scriptFile in importedFile.ReferencedScripts)
ProcessFile(scriptFile);

foreach (string resFile in importedFile.ReferencedResources)
PushResource(resFile);
foreach (string resFile in importedFile.ReferencedResources)
PushResource(resFile);

foreach (string file in importedFile.IgnoreNamespaces)
PushIgnoreNamespace(file);
foreach (string file in importedFile.IgnoreNamespaces)
PushIgnoreNamespace(file);

List<string> dirs = new List<string>(this.SearchDirs);
foreach (string dir in importedFile.ExtraSearchDirs)
if (Path.IsPathRooted(dir))
dirs.Add(Path.GetFullPath(dir));
else
dirs.Add(Path.Combine(Path.GetDirectoryName(importedFile.fileName), dir));
this.SearchDirs = dirs.ToArray();
}
else
{
importedFile.fileNameImported = importedFile.fileName;
this.fileParsers.Add(importedFile);
this.fileParsers.Sort(fileComparer);
List<string> dirs = new List<string>(this.SearchDirs);
foreach (string dir in importedFile.ExtraSearchDirs)
if (Path.IsPathRooted(dir))
dirs.Add(Path.GetFullPath(dir));
else
dirs.Add(Path.Combine(Path.GetDirectoryName(importedFile.fileName), dir));
this.SearchDirs = dirs.ToArray();
}
else
{
importedFile.fileNameImported = importedFile.fileName;
this.fileParsers.Add(importedFile);
this.fileParsers.Sort(fileComparer);
}
}
}
catch (Exception e)
{
throw new Exception("Cannot import '" + fileInfo.parseParams.rawStatement + "' from the '" + this.scriptPath + "' script.", e);
}
}

List<FileParser> fileParsers = new List<FileParser>();
Expand Down

0 comments on commit d5ac9ee

Please sign in to comment.