Use the same "heuristic" as TypeScript for public modules
This commit is contained in:
parent
2db55b5df2
commit
179796d26f
|
@ -104,6 +104,7 @@ export async function compileScript(path: string, options?: ts.CompilerOptions):
|
|||
|
||||
return <Script>{
|
||||
root: root,
|
||||
files: files,
|
||||
diagnostics: muDiagnostics,
|
||||
tree: tree,
|
||||
};
|
||||
|
@ -128,6 +129,7 @@ function transformDiagnostics(root: string, diagnostics: ts.Diagnostic[]): diag.
|
|||
// The result of script compilation.
|
||||
export interface Script {
|
||||
root: string; // the root directory for the compilation.
|
||||
files: string[]; // the files that are considered part of this script's package.
|
||||
diagnostics: diag.Diagnostic[]; // any diagnostics resulting from compilation.
|
||||
tree: ts.Program | undefined; // the resulting TypeScript program object.
|
||||
}
|
||||
|
|
|
@ -177,13 +177,8 @@ export class Transformer {
|
|||
// Enumerate all source files (each of which is a module in ECMAScript), and transform it.
|
||||
let modules: ast.Modules = {};
|
||||
for (let sourceFile of this.script.tree!.getSourceFiles()) {
|
||||
// By default, skip declaration files, since they are "dependencies."
|
||||
// TODO(joe): how to handle re-exports in ECMAScript, such as index aggregation.
|
||||
// TODO(joe): this isn't a perfect heuristic. But ECMAScript is all source dependencies, so there isn't a
|
||||
// true notion of source versus binary dependency. We could crack open the dependencies to see if they
|
||||
// exist within an otherwise known package, but that seems a little hokey. TypeScript seems to based
|
||||
// this on whether the file appears in the `tsconfig.json` file or not, which seems fine.
|
||||
if (!sourceFile.isDeclarationFile) {
|
||||
// If the file exists in this script's package list, we will export it as a module.
|
||||
if (this.script.files.indexOf(sourceFile.fileName) !== -1) {
|
||||
let mod: ast.Module = this.transformSourceFile(sourceFile);
|
||||
modules[mod.name.ident] = mod;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue