Skip to content

Commit

Permalink
[Transforms] Merging Master to Transforms on 06/21 (microsoft#9294)
Browse files Browse the repository at this point in the history
* Initial support for globs in tsconfig.json

* Added caching, more tests

* Added stubs to ChakraHost interface for readDirectoryNames/readFileNames

* Fixed typos in comments

* Changed name of 'reduce' method added to FileSet

* Heavily revised implementation that relies on an updated 'readDirectory' API.

* more tests

* Minor update to shims.ts for forthcoming VS support for globs.

* Detailed comments for regular expressions and renamed some files.

* Comment cleanup

* Fixed new linter warnings

* Add upper limit for the program size, fix readDirectory for the symlink files

* Add comments

* CR feedback / Change upper limit / Add disableSizeLimit compiler option

* online and offline CR feedback

* Don't count current opened client file if it's TS file

* Speed up file searching

* Make language service optional for a project

* Fix failed tests

* Fix project updateing issue after editing config file

* Fixing linter and test errors

* Bringing back excludes error and fixing faulty test

* Fixing lint errors

* Passing regular expressions to native hosts

* Fix merging issues and multiple project scenario

* Refactoring

* add test and spit commandLineParser changes to another PR

* Fix microsoft#8523

* check the declaration and use order if both are not in module file

* Type guards using discriminant properties of string literal types

* Fix microsoft#9098: report missing function impelementation errors for merged classes and namespaces

* Narrow type in case/default sections in switch on discriminant property

* No implicit returns following exhaustive switch statements

* Narrow non-union types to ensure consistent results

* Add tests

* No Need to store dot token when parsing property access expression

* Added tests.

* Accepted baselines.

* Check tuple types when getting the type node's type.

* Accepted baselines.

* Fix microsoft#9173: clear out lib and types before creating a program in transpileModule

* Added tests.

* Accepted baselines.

* Always check type assertion types.

* Clear out unused compiler options when transpiling

* Accepted baselines.

* improve error message for extending interface

* accept baselines

* Use helper functions to simplify range tests

* Remove String, Number, and Boolean from TypeFlags.Falsy

* Add regression test

* Accept new baselines

* Allow property declarations in .js files

* Remove old test

* Do not use Object.assing in test

* Fix comment

* Refactor code to make if statements cheaper

* ignore casing when converting a source file path to relative path

* add tests & add branches for module interface

* Using baselines for transpile unittests (microsoft#9195)

* Conver to Transpile unittest to use baselines instead

* Add baselines

* Fix linting error

* use resolveEntityName to find interface

* add new tests for extends interface

* address code style

* Refactor navigation bar

* routine dom update

* Updating readDirectory for tsserverProjectSystem unit tests

* Array#map -> ts.map.

* Responding to PR feedback

* Add conditional index signature for Canvas2DContextAttributes (microsoft#9244)

* Add libcheck tests

* Add missing worker types

* Accept webworker baselines

* Classify `this` in parameter position as a keyword

* Adding more matchFiles test cases

* Use implicit boolean casts; it doesn't hurt performance

* Use getCanonicalFileName

* export interface used by other exported functions

* Fix from merging with master

* Update tests and baselines from merging with master

* Remove using dotToken as it is no longer needed

* Update baselines from removing dotToken

* Address PR: Add NodeEmitFlags to no indent when emit

* Address PR; and refactor setting NodeEmitFlags for createMemberAccessForPropertyName

* Update baselines
  • Loading branch information
yuit authored Jul 11, 2016
1 parent 5f91b3c commit cfc20a9
Show file tree
Hide file tree
Showing 133 changed files with 6,477 additions and 1,543 deletions.
4 changes: 3 additions & 1 deletion Jakefile.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ var languageServiceLibrarySources = [

var harnessCoreSources = [
"harness.ts",
"virtualFileSystem.ts",
"sourceMapRecorder.ts",
"harnessLanguageService.ts",
"fourslash.ts",
Expand Down Expand Up @@ -179,7 +180,8 @@ var harnessSources = harnessCoreSources.concat([
"commandLineParsing.ts",
"convertCompilerOptionsFromJson.ts",
"convertTypingOptionsFromJson.ts",
"tsserverProjectSystem.ts"
"tsserverProjectSystem.ts",
"matchFiles.ts"
].map(function (f) {
return path.join(unittestsDirectory, f);
})).concat([
Expand Down
138 changes: 90 additions & 48 deletions src/compiler/binder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,20 +599,14 @@ namespace ts {
}
}

function isNarrowableReference(expr: Expression): boolean {
return expr.kind === SyntaxKind.Identifier ||
expr.kind === SyntaxKind.ThisKeyword ||
expr.kind === SyntaxKind.PropertyAccessExpression && isNarrowableReference((<PropertyAccessExpression>expr).expression);
}

function isNarrowingExpression(expr: Expression): boolean {
switch (expr.kind) {
case SyntaxKind.Identifier:
case SyntaxKind.ThisKeyword:
case SyntaxKind.PropertyAccessExpression:
return isNarrowableReference(expr);
case SyntaxKind.CallExpression:
return true;
return hasNarrowableArgument(<CallExpression>expr);
case SyntaxKind.ParenthesizedExpression:
return isNarrowingExpression((<ParenthesizedExpression>expr).expression);
case SyntaxKind.BinaryExpression:
Expand All @@ -623,6 +617,39 @@ namespace ts {
return false;
}

function isNarrowableReference(expr: Expression): boolean {
return expr.kind === SyntaxKind.Identifier ||
expr.kind === SyntaxKind.ThisKeyword ||
expr.kind === SyntaxKind.PropertyAccessExpression && isNarrowableReference((<PropertyAccessExpression>expr).expression);
}

function hasNarrowableArgument(expr: CallExpression) {
if (expr.arguments) {
for (const argument of expr.arguments) {
if (isNarrowableReference(argument)) {
return true;
}
}
}
if (expr.expression.kind === SyntaxKind.PropertyAccessExpression &&
isNarrowableReference((<PropertyAccessExpression>expr.expression).expression)) {
return true;
}
return false;
}

function isNarrowingNullCheckOperands(expr1: Expression, expr2: Expression) {
return (expr1.kind === SyntaxKind.NullKeyword || expr1.kind === SyntaxKind.Identifier && (<Identifier>expr1).text === "undefined") && isNarrowableOperand(expr2);
}

function isNarrowingTypeofOperands(expr1: Expression, expr2: Expression) {
return expr1.kind === SyntaxKind.TypeOfExpression && isNarrowableOperand((<TypeOfExpression>expr1).expression) && expr2.kind === SyntaxKind.StringLiteral;
}

function isNarrowingDiscriminant(expr: Expression) {
return expr.kind === SyntaxKind.PropertyAccessExpression && isNarrowableReference((<PropertyAccessExpression>expr).expression);
}

function isNarrowingBinaryExpression(expr: BinaryExpression) {
switch (expr.operatorToken.kind) {
case SyntaxKind.EqualsToken:
Expand All @@ -631,34 +658,35 @@ namespace ts {
case SyntaxKind.ExclamationEqualsToken:
case SyntaxKind.EqualsEqualsEqualsToken:
case SyntaxKind.ExclamationEqualsEqualsToken:
if ((isNarrowingExpression(expr.left) && (expr.right.kind === SyntaxKind.NullKeyword || expr.right.kind === SyntaxKind.Identifier)) ||
(isNarrowingExpression(expr.right) && (expr.left.kind === SyntaxKind.NullKeyword || expr.left.kind === SyntaxKind.Identifier))) {
return true;
}
if (isTypeOfNarrowingBinaryExpression(expr)) {
return true;
}
return false;
return isNarrowingNullCheckOperands(expr.right, expr.left) || isNarrowingNullCheckOperands(expr.left, expr.right) ||
isNarrowingTypeofOperands(expr.right, expr.left) || isNarrowingTypeofOperands(expr.left, expr.right) ||
isNarrowingDiscriminant(expr.left) || isNarrowingDiscriminant(expr.right);
case SyntaxKind.InstanceOfKeyword:
return isNarrowingExpression(expr.left);
return isNarrowableOperand(expr.left);
case SyntaxKind.CommaToken:
return isNarrowingExpression(expr.right);
}
return false;
}

function isTypeOfNarrowingBinaryExpression(expr: BinaryExpression) {
let typeOf: Expression;
if (expr.left.kind === SyntaxKind.StringLiteral) {
typeOf = expr.right;
}
else if (expr.right.kind === SyntaxKind.StringLiteral) {
typeOf = expr.left;
}
else {
typeOf = undefined;
function isNarrowableOperand(expr: Expression): boolean {
switch (expr.kind) {
case SyntaxKind.ParenthesizedExpression:
return isNarrowableOperand((<ParenthesizedExpression>expr).expression);
case SyntaxKind.BinaryExpression:
switch ((<BinaryExpression>expr).operatorToken.kind) {
case SyntaxKind.EqualsToken:
return isNarrowableOperand((<BinaryExpression>expr).left);
case SyntaxKind.CommaToken:
return isNarrowableOperand((<BinaryExpression>expr).right);
}
}
return typeOf && typeOf.kind === SyntaxKind.TypeOfExpression && isNarrowingExpression((<TypeOfExpression>typeOf).expression);
return isNarrowableReference(expr);
}

function isNarrowingSwitchStatement(switchStatement: SwitchStatement) {
const expr = switchStatement.expression;
return expr.kind === SyntaxKind.PropertyAccessExpression && isNarrowableReference((<PropertyAccessExpression>expr).expression);
}

function createBranchLabel(): FlowLabel {
Expand Down Expand Up @@ -704,8 +732,22 @@ namespace ts {
setFlowNodeReferenced(antecedent);
return <FlowCondition>{
flags,
antecedent,
expression,
antecedent
};
}

function createFlowSwitchClause(antecedent: FlowNode, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number): FlowNode {
if (!isNarrowingSwitchStatement(switchStatement)) {
return antecedent;
}
setFlowNodeReferenced(antecedent);
return <FlowSwitchClause>{
flags: FlowFlags.SwitchClause,
switchStatement,
clauseStart,
clauseEnd,
antecedent
};
}

Expand Down Expand Up @@ -934,9 +976,12 @@ namespace ts {
preSwitchCaseFlow = currentFlow;
bind(node.caseBlock);
addAntecedent(postSwitchLabel, currentFlow);
const hasNonEmptyDefault = forEach(node.caseBlock.clauses, c => c.kind === SyntaxKind.DefaultClause && c.statements.length);
if (!hasNonEmptyDefault) {
addAntecedent(postSwitchLabel, preSwitchCaseFlow);
const hasDefault = forEach(node.caseBlock.clauses, c => c.kind === SyntaxKind.DefaultClause);
// We mark a switch statement as possibly exhaustive if it has no default clause and if all
// case clauses have unreachable end points (e.g. they all return).
node.possiblyExhaustive = !hasDefault && !postSwitchLabel.antecedents;
if (!hasDefault) {
addAntecedent(postSwitchLabel, createFlowSwitchClause(preSwitchCaseFlow, node, 0, 0));
}
currentBreakTarget = saveBreakTarget;
preSwitchCaseFlow = savePreSwitchCaseFlow;
Expand All @@ -945,25 +990,22 @@ namespace ts {

function bindCaseBlock(node: CaseBlock): void {
const clauses = node.clauses;
let fallthroughFlow = unreachableFlow;
for (let i = 0; i < clauses.length; i++) {
const clauseStart = i;
while (!clauses[i].statements.length && i + 1 < clauses.length) {
bind(clauses[i]);
i++;
}
const preCaseLabel = createBranchLabel();
addAntecedent(preCaseLabel, createFlowSwitchClause(preSwitchCaseFlow, <SwitchStatement>node.parent, clauseStart, i + 1));
addAntecedent(preCaseLabel, fallthroughFlow);
currentFlow = finishFlowLabel(preCaseLabel);
const clause = clauses[i];
if (clause.statements.length) {
if (currentFlow.flags & FlowFlags.Unreachable) {
currentFlow = preSwitchCaseFlow;
}
else {
const preCaseLabel = createBranchLabel();
addAntecedent(preCaseLabel, preSwitchCaseFlow);
addAntecedent(preCaseLabel, currentFlow);
currentFlow = finishFlowLabel(preCaseLabel);
}
bind(clause);
if (!(currentFlow.flags & FlowFlags.Unreachable) && i !== clauses.length - 1 && options.noFallthroughCasesInSwitch) {
errorOnFirstToken(clause, Diagnostics.Fallthrough_case_in_switch);
}
}
else {
bind(clause);
bind(clause);
fallthroughFlow = currentFlow;
if (!(currentFlow.flags & FlowFlags.Unreachable) && i !== clauses.length - 1 && options.noFallthroughCasesInSwitch) {
errorOnFirstToken(clause, Diagnostics.Fallthrough_case_in_switch);
}
}
}
Expand Down
Loading

0 comments on commit cfc20a9

Please sign in to comment.