Skip to content

Commit

Permalink
upgrade to 1.5: core compilation works
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinr authored and gscshoyru committed Apr 9, 2015
1 parent 430dfec commit 9faab71
Show file tree
Hide file tree
Showing 8 changed files with 657 additions and 518 deletions.
1 change: 0 additions & 1 deletion lib/tslint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ declare module Lint {
protected visitSwitchStatement(node: ts.SwitchStatement): void;
protected visitTemplateExpression(node: ts.TemplateExpression): void;
protected visitThrowStatement(node: ts.ThrowStatement): void;
protected visitTryBlock(node: ts.Block): void;
protected visitTryStatement(node: ts.TryStatement): void;
protected visitTypeAssertionExpression(node: ts.TypeAssertion): void;
protected visitTypeLiteral(node: ts.TypeLiteralNode): void;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"grunt-mocha-test": "~0.6.2",
"grunt-ts": "~1.12.1",
"grunt-tslint": "~2.0.0",
"typescript": "1.4.1"
"typescript": "1.5.0-alpha"
},
"license": "Apache 2.0"
}
2 changes: 1 addition & 1 deletion src/language/languageServiceHost.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module Lint {
getCurrentDirectory: () => "",
getScriptIsOpen: () => true,
getCompilationSettings: () => Lint.createCompilerOptions(),
getDefaultLibFilename: (options) => "lib.d.ts",
getDefaultLibFileName: () => "lib.d.ts",
log: (message) => { /* */ }
};

Expand Down
4 changes: 2 additions & 2 deletions src/language/rule/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ module Lint {
ruleName: string) {

this.sourceFile = sourceFile;
this.fileName = sourceFile.filename;
this.fileName = sourceFile.fileName;
this.startPosition = this.createFailurePosition(start);
this.endPosition = this.createFailurePosition(end);
this.failure = failure;
Expand Down Expand Up @@ -131,7 +131,7 @@ module Lint {
}

private createFailurePosition(position: number): RuleFailurePosition {
var lineAndCharacter = this.sourceFile.getLineAndCharacterFromPosition(position);
var lineAndCharacter = this.sourceFile.getLineAndCharacterOfPosition(position);
var failurePosition = new RuleFailurePosition(position, lineAndCharacter);
return failurePosition;
}
Expand Down
16 changes: 11 additions & 5 deletions src/language/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,30 @@ module Lint {
var normalizedName = path.normalize(fileName).replace(/\\/g, "/");
var compilerOptions = createCompilerOptions();

// TODO: use ts.createCompilerHost instead
var compilerHost = {
getSourceFile: function (filenameToGet: string) {
if (filenameToGet === normalizedName) {
return ts.createSourceFile(filenameToGet, source, compilerOptions.target, "1", true);
return ts.createSourceFile(filenameToGet, source, compilerOptions.target, true);
}
},
writeFile: () => null,
getDefaultLibFilename: () => "lib.d.ts",
getDefaultLibFileName: () => "lib.d.ts",
useCaseSensitiveFileNames: () => true,
getCanonicalFileName: (filename: string) => filename,
getCurrentDirectory: () => "",
getNewLine: () => "\n"
};

var program = ts.createProgram([normalizedName], compilerOptions, compilerHost);
// this will force the binder to properly set up parent pointers, which will allow getSourceFile to work on all nodes,
// and will therefore allow our code to work even if the source doesn't compile
program.getTypeChecker(true);

// TODO: check if this is now necessary, because of setParentNodes in ts.createSourceFile

// this will force the binder to properly set up parent pointers, which will allow
// getSourceFile to work on all nodes, and will therefore allow our code to work
// even if the source doesn't compile
program.getTypeChecker();

return program.getSourceFile(normalizedName);
}

Expand Down
2 changes: 1 addition & 1 deletion src/language/walker/scopeAwareRuleWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module Lint {
|| node.kind === ts.SyntaxKind.FunctionExpression
|| node.kind === ts.SyntaxKind.PropertyAssignment
|| node.kind === ts.SyntaxKind.ShorthandPropertyAssignment
|| node.kind === ts.SyntaxKind.Method
|| node.kind === ts.SyntaxKind.MethodDeclaration
|| node.kind === ts.SyntaxKind.Constructor
|| node.kind === ts.SyntaxKind.ModuleDeclaration
|| node.kind === ts.SyntaxKind.ArrowFunction
Expand Down
12 changes: 2 additions & 10 deletions src/language/walker/syntaxWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,6 @@ module Lint {
this.walkChildren(node);
}

protected visitTryBlock(node: ts.Block) {
this.walkChildren(node);
}

protected visitTryStatement(node: ts.TryStatement) {
this.walkChildren(node);
}
Expand Down Expand Up @@ -376,7 +372,7 @@ module Lint {
this.visitLabeledStatement(<ts.LabeledStatement> node);
break;

case ts.SyntaxKind.Method:
case ts.SyntaxKind.MethodDeclaration:
this.visitMethodDeclaration(<ts.MethodDeclaration> node);
break;

Expand Down Expand Up @@ -412,7 +408,7 @@ module Lint {
this.visitPropertyAssignment(<ts.PropertyAssignment> node);
break;

case ts.SyntaxKind.Property:
case ts.SyntaxKind.PropertyDeclaration:
this.visitPropertyDeclaration(<ts.PropertyDeclaration> node);
break;

Expand Down Expand Up @@ -444,10 +440,6 @@ module Lint {
this.visitThrowStatement(<ts.ThrowStatement> node);
break;

case ts.SyntaxKind.TryBlock:
this.visitTryBlock(<ts.Block> node);
break;

case ts.SyntaxKind.TryStatement:
this.visitTryStatement(<ts.TryStatement> node);
break;
Expand Down
Loading

0 comments on commit 9faab71

Please sign in to comment.