typescript4j icon indicating copy to clipboard operation
typescript4j copied to clipboard

Error including files with relative paths

Open ruediste opened this issue 10 years ago • 1 comments

When a .ts file contains a reference in the form

///<reference path="../es6-promise/es6-promise.d.ts"/>

the referenced file is looked up relative to the base path of the CompilationContext instead of the current source.

ruediste avatar Sep 10 '15 11:09 ruediste

The following patch in typescript.compile.js fixed the issue, however I think the logic is better placed in the CompilationContext

Line 74:      var fileReferencesInSource = TypeScript.getReferencedFiles(sourceToParse.path, code);

        // patch start
        for( var i = 0; i < fileReferencesInSource.length; i++ ){
            var ref = fileReferencesInSource[i];
            var idx=sourceToParse.path.lastIndexOf('/');
            if (idx > 0)
              // prepend the path of the source file to the include
              ref.path = new java.lang.String(sourceToParse.path.substring(0,idx)+'/' + ref.path);
        }
        // patch end

        var referencedSourceUnits = compilationContext.resolveFiles(fileReferencesInSource);

ruediste avatar Sep 10 '15 12:09 ruediste