Skip to content

Commit cfc20a9

Browse files
authored
[Transforms] Merging Master to Transforms on 06/21 (#9294)
* 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 #8523 * check the declaration and use order if both are not in module file * Type guards using discriminant properties of string literal types * Fix #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 #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 (#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 (#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
1 parent 5f91b3c commit cfc20a9

File tree

133 files changed

+6477
-1543
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

133 files changed

+6477
-1543
lines changed

Diff for: Jakefile.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ var languageServiceLibrarySources = [
145145

146146
var harnessCoreSources = [
147147
"harness.ts",
148+
"virtualFileSystem.ts",
148149
"sourceMapRecorder.ts",
149150
"harnessLanguageService.ts",
150151
"fourslash.ts",
@@ -179,7 +180,8 @@ var harnessSources = harnessCoreSources.concat([
179180
"commandLineParsing.ts",
180181
"convertCompilerOptionsFromJson.ts",
181182
"convertTypingOptionsFromJson.ts",
182-
"tsserverProjectSystem.ts"
183+
"tsserverProjectSystem.ts",
184+
"matchFiles.ts"
183185
].map(function (f) {
184186
return path.join(unittestsDirectory, f);
185187
})).concat([

Diff for: src/compiler/binder.ts

+90-48
Original file line numberDiff line numberDiff line change
@@ -599,20 +599,14 @@ namespace ts {
599599
}
600600
}
601601

602-
function isNarrowableReference(expr: Expression): boolean {
603-
return expr.kind === SyntaxKind.Identifier ||
604-
expr.kind === SyntaxKind.ThisKeyword ||
605-
expr.kind === SyntaxKind.PropertyAccessExpression && isNarrowableReference((<PropertyAccessExpression>expr).expression);
606-
}
607-
608602
function isNarrowingExpression(expr: Expression): boolean {
609603
switch (expr.kind) {
610604
case SyntaxKind.Identifier:
611605
case SyntaxKind.ThisKeyword:
612606
case SyntaxKind.PropertyAccessExpression:
613607
return isNarrowableReference(expr);
614608
case SyntaxKind.CallExpression:
615-
return true;
609+
return hasNarrowableArgument(<CallExpression>expr);
616610
case SyntaxKind.ParenthesizedExpression:
617611
return isNarrowingExpression((<ParenthesizedExpression>expr).expression);
618612
case SyntaxKind.BinaryExpression:
@@ -623,6 +617,39 @@ namespace ts {
623617
return false;
624618
}
625619

620+
function isNarrowableReference(expr: Expression): boolean {
621+
return expr.kind === SyntaxKind.Identifier ||
622+
expr.kind === SyntaxKind.ThisKeyword ||
623+
expr.kind === SyntaxKind.PropertyAccessExpression && isNarrowableReference((<PropertyAccessExpression>expr).expression);
624+
}
625+
626+
function hasNarrowableArgument(expr: CallExpression) {
627+
if (expr.arguments) {
628+
for (const argument of expr.arguments) {
629+
if (isNarrowableReference(argument)) {
630+
return true;
631+
}
632+
}
633+
}
634+
if (expr.expression.kind === SyntaxKind.PropertyAccessExpression &&
635+
isNarrowableReference((<PropertyAccessExpression>expr.expression).expression)) {
636+
return true;
637+
}
638+
return false;
639+
}
640+
641+
function isNarrowingNullCheckOperands(expr1: Expression, expr2: Expression) {
642+
return (expr1.kind === SyntaxKind.NullKeyword || expr1.kind === SyntaxKind.Identifier && (<Identifier>expr1).text === "undefined") && isNarrowableOperand(expr2);
643+
}
644+
645+
function isNarrowingTypeofOperands(expr1: Expression, expr2: Expression) {
646+
return expr1.kind === SyntaxKind.TypeOfExpression && isNarrowableOperand((<TypeOfExpression>expr1).expression) && expr2.kind === SyntaxKind.StringLiteral;
647+
}
648+
649+
function isNarrowingDiscriminant(expr: Expression) {
650+
return expr.kind === SyntaxKind.PropertyAccessExpression && isNarrowableReference((<PropertyAccessExpression>expr).expression);
651+
}
652+
626653
function isNarrowingBinaryExpression(expr: BinaryExpression) {
627654
switch (expr.operatorToken.kind) {
628655
case SyntaxKind.EqualsToken:
@@ -631,34 +658,35 @@ namespace ts {
631658
case SyntaxKind.ExclamationEqualsToken:
632659
case SyntaxKind.EqualsEqualsEqualsToken:
633660
case SyntaxKind.ExclamationEqualsEqualsToken:
634-
if ((isNarrowingExpression(expr.left) && (expr.right.kind === SyntaxKind.NullKeyword || expr.right.kind === SyntaxKind.Identifier)) ||
635-
(isNarrowingExpression(expr.right) && (expr.left.kind === SyntaxKind.NullKeyword || expr.left.kind === SyntaxKind.Identifier))) {
636-
return true;
637-
}
638-
if (isTypeOfNarrowingBinaryExpression(expr)) {
639-
return true;
640-
}
641-
return false;
661+
return isNarrowingNullCheckOperands(expr.right, expr.left) || isNarrowingNullCheckOperands(expr.left, expr.right) ||
662+
isNarrowingTypeofOperands(expr.right, expr.left) || isNarrowingTypeofOperands(expr.left, expr.right) ||
663+
isNarrowingDiscriminant(expr.left) || isNarrowingDiscriminant(expr.right);
642664
case SyntaxKind.InstanceOfKeyword:
643-
return isNarrowingExpression(expr.left);
665+
return isNarrowableOperand(expr.left);
644666
case SyntaxKind.CommaToken:
645667
return isNarrowingExpression(expr.right);
646668
}
647669
return false;
648670
}
649671

650-
function isTypeOfNarrowingBinaryExpression(expr: BinaryExpression) {
651-
let typeOf: Expression;
652-
if (expr.left.kind === SyntaxKind.StringLiteral) {
653-
typeOf = expr.right;
654-
}
655-
else if (expr.right.kind === SyntaxKind.StringLiteral) {
656-
typeOf = expr.left;
657-
}
658-
else {
659-
typeOf = undefined;
672+
function isNarrowableOperand(expr: Expression): boolean {
673+
switch (expr.kind) {
674+
case SyntaxKind.ParenthesizedExpression:
675+
return isNarrowableOperand((<ParenthesizedExpression>expr).expression);
676+
case SyntaxKind.BinaryExpression:
677+
switch ((<BinaryExpression>expr).operatorToken.kind) {
678+
case SyntaxKind.EqualsToken:
679+
return isNarrowableOperand((<BinaryExpression>expr).left);
680+
case SyntaxKind.CommaToken:
681+
return isNarrowableOperand((<BinaryExpression>expr).right);
682+
}
660683
}
661-
return typeOf && typeOf.kind === SyntaxKind.TypeOfExpression && isNarrowingExpression((<TypeOfExpression>typeOf).expression);
684+
return isNarrowableReference(expr);
685+
}
686+
687+
function isNarrowingSwitchStatement(switchStatement: SwitchStatement) {
688+
const expr = switchStatement.expression;
689+
return expr.kind === SyntaxKind.PropertyAccessExpression && isNarrowableReference((<PropertyAccessExpression>expr).expression);
662690
}
663691

664692
function createBranchLabel(): FlowLabel {
@@ -704,8 +732,22 @@ namespace ts {
704732
setFlowNodeReferenced(antecedent);
705733
return <FlowCondition>{
706734
flags,
707-
antecedent,
708735
expression,
736+
antecedent
737+
};
738+
}
739+
740+
function createFlowSwitchClause(antecedent: FlowNode, switchStatement: SwitchStatement, clauseStart: number, clauseEnd: number): FlowNode {
741+
if (!isNarrowingSwitchStatement(switchStatement)) {
742+
return antecedent;
743+
}
744+
setFlowNodeReferenced(antecedent);
745+
return <FlowSwitchClause>{
746+
flags: FlowFlags.SwitchClause,
747+
switchStatement,
748+
clauseStart,
749+
clauseEnd,
750+
antecedent
709751
};
710752
}
711753

@@ -934,9 +976,12 @@ namespace ts {
934976
preSwitchCaseFlow = currentFlow;
935977
bind(node.caseBlock);
936978
addAntecedent(postSwitchLabel, currentFlow);
937-
const hasNonEmptyDefault = forEach(node.caseBlock.clauses, c => c.kind === SyntaxKind.DefaultClause && c.statements.length);
938-
if (!hasNonEmptyDefault) {
939-
addAntecedent(postSwitchLabel, preSwitchCaseFlow);
979+
const hasDefault = forEach(node.caseBlock.clauses, c => c.kind === SyntaxKind.DefaultClause);
980+
// We mark a switch statement as possibly exhaustive if it has no default clause and if all
981+
// case clauses have unreachable end points (e.g. they all return).
982+
node.possiblyExhaustive = !hasDefault && !postSwitchLabel.antecedents;
983+
if (!hasDefault) {
984+
addAntecedent(postSwitchLabel, createFlowSwitchClause(preSwitchCaseFlow, node, 0, 0));
940985
}
941986
currentBreakTarget = saveBreakTarget;
942987
preSwitchCaseFlow = savePreSwitchCaseFlow;
@@ -945,25 +990,22 @@ namespace ts {
945990

946991
function bindCaseBlock(node: CaseBlock): void {
947992
const clauses = node.clauses;
993+
let fallthroughFlow = unreachableFlow;
948994
for (let i = 0; i < clauses.length; i++) {
995+
const clauseStart = i;
996+
while (!clauses[i].statements.length && i + 1 < clauses.length) {
997+
bind(clauses[i]);
998+
i++;
999+
}
1000+
const preCaseLabel = createBranchLabel();
1001+
addAntecedent(preCaseLabel, createFlowSwitchClause(preSwitchCaseFlow, <SwitchStatement>node.parent, clauseStart, i + 1));
1002+
addAntecedent(preCaseLabel, fallthroughFlow);
1003+
currentFlow = finishFlowLabel(preCaseLabel);
9491004
const clause = clauses[i];
950-
if (clause.statements.length) {
951-
if (currentFlow.flags & FlowFlags.Unreachable) {
952-
currentFlow = preSwitchCaseFlow;
953-
}
954-
else {
955-
const preCaseLabel = createBranchLabel();
956-
addAntecedent(preCaseLabel, preSwitchCaseFlow);
957-
addAntecedent(preCaseLabel, currentFlow);
958-
currentFlow = finishFlowLabel(preCaseLabel);
959-
}
960-
bind(clause);
961-
if (!(currentFlow.flags & FlowFlags.Unreachable) && i !== clauses.length - 1 && options.noFallthroughCasesInSwitch) {
962-
errorOnFirstToken(clause, Diagnostics.Fallthrough_case_in_switch);
963-
}
964-
}
965-
else {
966-
bind(clause);
1005+
bind(clause);
1006+
fallthroughFlow = currentFlow;
1007+
if (!(currentFlow.flags & FlowFlags.Unreachable) && i !== clauses.length - 1 && options.noFallthroughCasesInSwitch) {
1008+
errorOnFirstToken(clause, Diagnostics.Fallthrough_case_in_switch);
9671009
}
9681010
}
9691011
}

0 commit comments

Comments
 (0)