Skip to content

Commit

Permalink
Merge branch 'master' into glob2
Browse files Browse the repository at this point in the history
  • Loading branch information
rbuckton committed Jan 4, 2016
2 parents c224917 + 669e733 commit cde12ef
Show file tree
Hide file tree
Showing 221 changed files with 5,651 additions and 2,193 deletions.
25 changes: 12 additions & 13 deletions Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,6 @@ var serverCoreSources = [
return path.join(serverDirectory, f);
});

var scriptSources = [
"tslint/booleanTriviaRule.ts",
"tslint/nextLineRule.ts",
"tslint/noNullRule.ts",
"tslint/preferConstRule.ts",
"tslint/typeOperatorSpacingRule.ts",
"tslint/noInOperatorRule.ts"
].map(function (f) {
return path.join(scriptsDirectory, f);
});

var serverSources = serverCoreSources.concat(servicesSources);

var languageServiceLibrarySources = [
Expand Down Expand Up @@ -880,7 +869,8 @@ var tslintRules = ([
"preferConstRule",
"booleanTriviaRule",
"typeOperatorSpacingRule",
"noInOperatorRule"
"noInOperatorRule",
"noIncrementDecrementRule"
]);
var tslintRulesFiles = tslintRules.map(function(p) {
return path.join(tslintRuleDir, p + ".ts");
Expand Down Expand Up @@ -923,10 +913,19 @@ function lintFileAsync(options, path, cb) {
});
}

var servicesLintTargets = [
"services.ts",
"outliningElementsCollector.ts",
"navigateTo.ts",
"patternMatcher.ts",
].map(function (s) {
return path.join(servicesDirectory, s);
});
var lintTargets = compilerSources
.concat(harnessCoreSources)
.concat(serverCoreSources)
.concat(scriptSources);
.concat(tslintRulesFiles)
.concat(servicesLintTargets);

desc("Runs tslint on the compiler sources");
task("lint", ["build-rules"], function() {
Expand Down
7 changes: 7 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
This directory contains miscellaneous documentation such as the TypeScript language specification and logo.
If you are looking for more introductory material, you might want to take a look at the [TypeScript Handbook](https://github.com/Microsoft/TypeScript-Handbook).

# Spec Contributions

The specification is first authored as a Microsoft Word (docx) file and then generated into Markdown and PDF formats.
Due to the binary format of docx files, and the merging difficulties that may come with it, it is preferred that any suggestions or problems found in the spec should be [filed as issues](https://github.com/Microsoft/TypeScript/issues/new) rather than sent as pull requests.
Binary file modified doc/TypeScript Language Specification.docx
Binary file not shown.
Binary file added doc/images/image1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/image2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/image3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/image4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions doc/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function f() {

To benefit from this inference, a programmer can use the TypeScript language service. For example, a code editor can incorporate the TypeScript language service and use the service to find the members of a string object as in the following screen shot.

/
  ![](images/image1.png)

In this example, the programmer benefits from type inference without providing type annotations. Some beneficial tools, however, do require the programmer to provide type annotations. In TypeScript, we can express a parameter requirement as in the following code fragment.

Expand Down Expand Up @@ -410,7 +410,7 @@ This signature denotes that a function may be passed as the parameter of the '$'
A typical client would not need to add any additional typing but could just use a community-supplied typing to discover (through statement completion with documentation tips) and verify (through static checking) correct use of the library, as in the following screen shot.
/
  ![](images/image2.png)
Section [3.3](#3.3) provides additional information about object types.
Expand Down Expand Up @@ -627,7 +627,7 @@ An important goal of TypeScript is to provide accurate and straightforward types

JavaScript programming interfaces often include functions whose behavior is discriminated by a string constant passed to the function. The Document Object Model makes heavy use of this pattern. For example, the following screen shot shows that the 'createElement' method of the 'document' object has multiple signatures, some of which identify the types returned when specific strings are passed into the method.

/
  ![](images/image3.png)

The following code fragment uses this feature. Because the 'span' variable is inferred to have the type 'HTMLSpanElement', the code can reference without static error the 'isMultiline' property of 'span'.

Expand All @@ -638,7 +638,7 @@ span.isMultiLine = false; // OK: HTMLSpanElement has isMultiline property

In the following screen shot, a programming tool combines information from overloading on string parameters with contextual typing to infer that the type of the variable 'e' is 'MouseEvent' and that therefore 'e' has a 'clientX' property.

/
  ![](images/image4.png)

Section [3.9.2.4](#3.9.2.4) provides details on how to use string literals in function signatures.

Expand Down
8 changes: 6 additions & 2 deletions scripts/tslint/booleanTriviaRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class BooleanTriviaWalker extends Lint.RuleWalker {
for (let index = 0; index < targetParameters.length; index++) {
const param = targetParameters[index];
const arg = node.arguments[index];
if (!(arg && param)) continue;
if (!(arg && param)) {
continue;
}

const argType = this.checker.getContextualType(arg);
if (argType && (argType.getFlags() & ts.TypeFlags.Boolean)) {
Expand All @@ -38,7 +40,9 @@ class BooleanTriviaWalker extends Lint.RuleWalker {
if (ranges && ranges.length === 1 && ranges[0].kind === ts.SyntaxKind.MultiLineCommentTrivia) {
triviaContent = arg.getFullText().slice(ranges[0].pos + 2, ranges[0].end - 2); // +/-2 to remove /**/
}
if (triviaContent !== param.getName()) {

const paramName = param.getName();
if (triviaContent !== paramName && triviaContent !== paramName + ":") {
this.addFailure(this.createFailure(arg.getStart(source), arg.getWidth(source), Rule.FAILURE_STRING_FACTORY(param.getName(), triviaContent)));
}
}
Expand Down
37 changes: 37 additions & 0 deletions scripts/tslint/noIncrementDecrementRule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as Lint from "tslint/lib/lint";
import * as ts from "typescript";


export class Rule extends Lint.Rules.AbstractRule {
public static POSTFIX_FAILURE_STRING = "Don't use '++' or '--' postfix operators outside statements or for loops.";
public static PREFIX_FAILURE_STRING = "Don't use '++' or '--' prefix operators.";

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new IncrementDecrementWalker(sourceFile, this.getOptions()));
}
}

class IncrementDecrementWalker extends Lint.RuleWalker {

visitPostfixUnaryExpression(node: ts.PostfixUnaryExpression) {
super.visitPostfixUnaryExpression(node);
if (node.operator === ts.SyntaxKind.PlusPlusToken || node.operator == ts.SyntaxKind.MinusMinusToken) {
this.visitIncrementDecrement(node);
}
}

visitPrefixUnaryExpression(node: ts.PrefixUnaryExpression) {
super.visitPrefixUnaryExpression(node);
if (node.operator === ts.SyntaxKind.PlusPlusToken || node.operator == ts.SyntaxKind.MinusMinusToken) {
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.PREFIX_FAILURE_STRING));
}
}

visitIncrementDecrement(node: ts.UnaryExpression) {
if (node.parent && (node.parent.kind === ts.SyntaxKind.ExpressionStatement ||
node.parent.kind === ts.SyntaxKind.ForStatement)) {
return;
}
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.POSTFIX_FAILURE_STRING));
}
}
235 changes: 0 additions & 235 deletions scripts/word2md.js

This file was deleted.

Loading

0 comments on commit cde12ef

Please sign in to comment.