Skip to content
This repository has been archived by the owner on Oct 23, 2019. It is now read-only.

Commit

Permalink
Improving type handling for compiler
Browse files Browse the repository at this point in the history
  • Loading branch information
markfinger committed Aug 19, 2016
1 parent 4cd16c1 commit 117d83a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
4 changes: 3 additions & 1 deletion *.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ declare module "babel-types" {
function isLiteral(node: any): boolean
}
declare module "babel-traverse"
declare module "babel-generator"
declare module "babel-generator" {
export default function(ast: any, options?: any, text?: string): any
}
declare module "babylon" {
function parse(text: string, options?: any): any
}
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ node_modules

# Build artifacts
*.cpuprofile
typings/*
typings
*.js
16 changes: 7 additions & 9 deletions compiler/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {postcssAstDependencies} from './postcss_ast_dependencies';
import {parse5AstDependencies, rewriteParse5AstDependencies} from './parse5_ast_dependencies';
import {GraphOutput} from "../cyclic_dependency_graph/graph";

class File {
export class File {
fileName: string;
baseDirectory: string;
ext: string;
Expand All @@ -34,7 +34,7 @@ class File {
}
}

class FileScan {
export class FileScan {
file: File;
identifiers: string[];
ast: any;
Expand All @@ -43,7 +43,7 @@ class FileScan {
}
}

class FileDependencies {
export class FileDependencies {
scan: FileScan;
resolved: string[];
resolvedByIdentifier: any;
Expand All @@ -52,7 +52,7 @@ class FileDependencies {
}
}

class FileBuild {
export class FileBuild {
file: File;
scan: FileScan;
content: string | Buffer;
Expand All @@ -64,15 +64,13 @@ class FileBuild {
}
}

interface buildOutput {
export interface buildOutput {
graph: Graph,
files: ImmutableMap<string, File>
scans: ImmutableMap<string, FileScan>
built: ImmutableMap<string, FileBuild>
}

const NODE_MODULES = /node_modules/;

export class Compiler {
fileSystemCache = new FileSystemCache();
graph: CyclicDependencyGraph;
Expand Down Expand Up @@ -158,7 +156,7 @@ export class Compiler {
.then(([text, textHash]) => {
file.content = text;
file.hash = textHash;
const sourceType = NODE_MODULES.test(fileName) ? 'script' : 'module';
const sourceType = fileName.indexOf('node_modules') !== -1 ? 'script' : 'module';
const ast = babylon.parse(text, {
sourceType
});
Expand Down Expand Up @@ -245,7 +243,7 @@ export class Compiler {
sourceFileName: sourceUrl,
sourceMapTarget: outputUrl
},
file.content
file.content as string
);
const build = new FileBuild(file, scan);
build.url = outputUrl;
Expand Down
4 changes: 2 additions & 2 deletions compiler/tests/test_compiler_internals.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import test from 'ava';
import { Subject } from 'rxjs';
import { Compiler } from '../compiler';
import { Compiler, buildOutput } from '../compiler';
import { handleCompilerErrors } from './utils';
import { createVirtualFileSystemCache } from '../../file_system/test_utils';

Expand All @@ -21,7 +21,7 @@ test('should produce urls to the output of the assets', (t) => {
});
const obs = new Subject();
handleCompilerErrors(compiler, obs);
compiler.complete.subscribe(data => {
compiler.complete.subscribe((data: buildOutput) => {
const htmlFile = data.files.get('/foo/index.html');
const jsFile = data.files.get('/foo/bar/script.js');
const cssFile = data.files.get('/woz/styles.css');
Expand Down

0 comments on commit 117d83a

Please sign in to comment.