Skip to content

Commit c9b490f

Browse files
committed
Merge branch 'master' into arozga/RemoveNavBarWhiteSpace
2 parents 82e8e43 + 3bdff73 commit c9b490f

52 files changed

Lines changed: 1493 additions & 290 deletions

File tree

Some content is hidden

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

src/compiler/binder.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ namespace ts {
10071007
currentFlow = finishFlowLabel(preFinallyLabel);
10081008
bind(node.finallyBlock);
10091009
// if flow after finally is unreachable - keep it
1010-
// otherwise check if flows after try and after catch are unreachable
1010+
// otherwise check if flows after try and after catch are unreachable
10111011
// if yes - convert current flow to unreachable
10121012
// i.e.
10131013
// try { return "1" } finally { console.log(1); }
@@ -2421,6 +2421,9 @@ namespace ts {
24212421
case SyntaxKind.HeritageClause:
24222422
return computeHeritageClause(<HeritageClause>node, subtreeFlags);
24232423

2424+
case SyntaxKind.CatchClause:
2425+
return computeCatchClause(<CatchClause>node, subtreeFlags);
2426+
24242427
case SyntaxKind.ExpressionWithTypeArguments:
24252428
return computeExpressionWithTypeArguments(<ExpressionWithTypeArguments>node, subtreeFlags);
24262429

@@ -2650,6 +2653,17 @@ namespace ts {
26502653
return transformFlags & ~TransformFlags.NodeExcludes;
26512654
}
26522655

2656+
function computeCatchClause(node: CatchClause, subtreeFlags: TransformFlags) {
2657+
let transformFlags = subtreeFlags;
2658+
2659+
if (node.variableDeclaration && isBindingPattern(node.variableDeclaration.name)) {
2660+
transformFlags |= TransformFlags.AssertES2015;
2661+
}
2662+
2663+
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
2664+
return transformFlags & ~TransformFlags.NodeExcludes;
2665+
}
2666+
26532667
function computeExpressionWithTypeArguments(node: ExpressionWithTypeArguments, subtreeFlags: TransformFlags) {
26542668
// An ExpressionWithTypeArguments is ES6 syntax, as it is used in the
26552669
// extends clause of a class.

src/compiler/checker.ts

Lines changed: 225 additions & 179 deletions
Large diffs are not rendered by default.

src/compiler/commandLineParser.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,13 @@ namespace ts {
599599
i++;
600600
break;
601601
case "boolean":
602-
options[opt.name] = true;
602+
// boolean flag has optional value true, false, others
603+
let optValue = args[i];
604+
options[opt.name] = optValue !== "false";
605+
// consume next argument as boolean flag value
606+
if (optValue === "false" || optValue === "true") {
607+
i++;
608+
}
603609
break;
604610
case "string":
605611
options[opt.name] = args[i] || "";
@@ -906,6 +912,9 @@ namespace ts {
906912
if (hasProperty(json, "files")) {
907913
if (isArray(json["files"])) {
908914
fileNames = <string[]>json["files"];
915+
if (fileNames.length === 0) {
916+
errors.push(createCompilerDiagnostic(Diagnostics.The_files_list_in_config_file_0_is_empty, configFileName || "tsconfig.json"));
917+
}
909918
}
910919
else {
911920
errors.push(createCompilerDiagnostic(Diagnostics.Compiler_option_0_requires_a_value_of_type_1, "files", "Array"));
@@ -948,7 +957,18 @@ namespace ts {
948957
includeSpecs = ["**/*"];
949958
}
950959

951-
return matchFileNames(fileNames, includeSpecs, excludeSpecs, basePath, options, host, errors);
960+
const result = matchFileNames(fileNames, includeSpecs, excludeSpecs, basePath, options, host, errors);
961+
962+
if (result.fileNames.length === 0 && !hasProperty(json, "files") && resolutionStack.length === 0) {
963+
errors.push(
964+
createCompilerDiagnostic(
965+
Diagnostics.No_inputs_were_found_in_config_file_0_Specified_include_paths_were_1_and_exclude_paths_were_2,
966+
configFileName || "tsconfig.json",
967+
JSON.stringify(includeSpecs || []),
968+
JSON.stringify(excludeSpecs || [])));
969+
}
970+
971+
return result;
952972
}
953973
}
954974

src/compiler/diagnosticMessages.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,6 @@
603603
"category": "Error",
604604
"code": 1194
605605
},
606-
"Catch clause variable name must be an identifier.": {
607-
"category": "Error",
608-
"code": 1195
609-
},
610606
"Catch clause variable cannot have a type annotation.": {
611607
"category": "Error",
612608
"code": 1196
@@ -3077,6 +3073,7 @@
30773073
"category": "Error",
30783074
"code": 17010
30793075
},
3076+
30803077
"Circularity detected while resolving configuration: {0}": {
30813078
"category": "Error",
30823079
"code": 18000
@@ -3085,6 +3082,15 @@
30853082
"category": "Error",
30863083
"code": 18001
30873084
},
3085+
"The 'files' list in config file '{0}' is empty.": {
3086+
"category": "Error",
3087+
"code": 18002
3088+
},
3089+
"No inputs were found in config file '{0}'. Specified 'include' paths were '{1}' and 'exclude' paths were '{2}'.": {
3090+
"category": "Error",
3091+
"code": 18003
3092+
},
3093+
30883094
"Add missing 'super()' call.": {
30893095
"category": "Message",
30903096
"code": 90001

src/compiler/factory.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,7 +1625,9 @@ namespace ts {
16251625
// flag and setting a parent node.
16261626
const react = createIdentifier(reactNamespace || "React");
16271627
react.flags &= ~NodeFlags.Synthesized;
1628-
react.parent = parent;
1628+
// Set the parent that is in parse tree
1629+
// this makes sure that parent chain is intact for checker to traverse complete scope tree
1630+
react.parent = getParseTreeNode(parent);
16291631
return react;
16301632
}
16311633

src/compiler/parser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5472,7 +5472,7 @@ namespace ts {
54725472

54735473
exportDeclaration.name = parseIdentifier();
54745474

5475-
parseExpected(SyntaxKind.SemicolonToken);
5475+
parseSemicolon();
54765476

54775477
return finishNode(exportDeclaration);
54785478
}

src/compiler/transformers/es2015.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,9 @@ namespace ts {
362362
case SyntaxKind.ObjectLiteralExpression:
363363
return visitObjectLiteralExpression(<ObjectLiteralExpression>node);
364364

365+
case SyntaxKind.CatchClause:
366+
return visitCatchClause(<CatchClause>node);
367+
365368
case SyntaxKind.ShorthandPropertyAssignment:
366369
return visitShorthandPropertyAssignment(<ShorthandPropertyAssignment>node);
367370

@@ -2622,6 +2625,24 @@ namespace ts {
26222625
return expression;
26232626
}
26242627

2628+
function visitCatchClause(node: CatchClause): CatchClause {
2629+
Debug.assert(isBindingPattern(node.variableDeclaration.name));
2630+
2631+
const temp = createTempVariable(undefined);
2632+
const newVariableDeclaration = createVariableDeclaration(temp, undefined, undefined, node.variableDeclaration);
2633+
2634+
const vars = flattenVariableDestructuring(node.variableDeclaration, temp, visitor);
2635+
const list = createVariableDeclarationList(vars, /*location*/node.variableDeclaration, /*flags*/node.variableDeclaration.flags);
2636+
const destructure = createVariableStatement(undefined, list);
2637+
2638+
return updateCatchClause(node, newVariableDeclaration, addStatementToStartOfBlock(node.block, destructure));
2639+
}
2640+
2641+
function addStatementToStartOfBlock(block: Block, statement: Statement): Block {
2642+
const transformedStatements = visitNodes(block.statements, visitor, isStatement);
2643+
return updateBlock(block, [statement].concat(transformedStatements));
2644+
}
2645+
26252646
/**
26262647
* Visits a MethodDeclaration of an ObjectLiteralExpression and transforms it into a
26272648
* PropertyAssignment.

src/compiler/types.ts

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2612,24 +2612,17 @@ namespace ts {
26122612
Null = 1 << 12,
26132613
Never = 1 << 13, // Never type
26142614
TypeParameter = 1 << 14, // Type parameter
2615-
Class = 1 << 15, // Class
2616-
Interface = 1 << 16, // Interface
2617-
Reference = 1 << 17, // Generic type reference
2618-
Tuple = 1 << 18, // Synthesized generic tuple type
2619-
Union = 1 << 19, // Union (T | U)
2620-
Intersection = 1 << 20, // Intersection (T & U)
2621-
Anonymous = 1 << 21, // Anonymous
2622-
Instantiated = 1 << 22, // Instantiated anonymous type
2615+
Object = 1 << 15, // Object type
2616+
Union = 1 << 16, // Union (T | U)
2617+
Intersection = 1 << 17, // Intersection (T & U)
26232618
/* @internal */
2624-
ObjectLiteral = 1 << 23, // Originates in an object literal
2619+
FreshLiteral = 1 << 18, // Fresh literal type
26252620
/* @internal */
2626-
FreshLiteral = 1 << 24, // Fresh literal type
2621+
ContainsWideningType = 1 << 19, // Type is or contains undefined or null widening type
26272622
/* @internal */
2628-
ContainsWideningType = 1 << 25, // Type is or contains undefined or null widening type
2623+
ContainsObjectLiteral = 1 << 20, // Type is or contains object literal type
26292624
/* @internal */
2630-
ContainsObjectLiteral = 1 << 26, // Type is or contains object literal type
2631-
/* @internal */
2632-
ContainsAnyFunctionType = 1 << 27, // Type is or contains object literal type
2625+
ContainsAnyFunctionType = 1 << 21, // Type is or contains object literal type
26332626

26342627
/* @internal */
26352628
Nullable = Undefined | Null,
@@ -2646,15 +2639,14 @@ namespace ts {
26462639
NumberLike = Number | NumberLiteral | Enum | EnumLiteral,
26472640
BooleanLike = Boolean | BooleanLiteral,
26482641
EnumLike = Enum | EnumLiteral,
2649-
ObjectType = Class | Interface | Reference | Tuple | Anonymous,
26502642
UnionOrIntersection = Union | Intersection,
2651-
StructuredType = ObjectType | Union | Intersection,
2643+
StructuredType = Object | Union | Intersection,
26522644
StructuredOrTypeParameter = StructuredType | TypeParameter,
26532645

26542646
// 'Narrowable' types are types where narrowing actually narrows.
26552647
// This *should* be every type other than null, undefined, void, and never
26562648
Narrowable = Any | StructuredType | TypeParameter | StringLike | NumberLike | BooleanLike | ESSymbol,
2657-
NotUnionOrUnit = Any | ESSymbol | ObjectType,
2649+
NotUnionOrUnit = Any | ESSymbol | Object,
26582650
/* @internal */
26592651
RequiresWidening = ContainsWideningType | ContainsObjectLiteral,
26602652
/* @internal */
@@ -2697,9 +2689,22 @@ namespace ts {
26972689
baseType: EnumType & UnionType; // Base enum type
26982690
}
26992691

2692+
export const enum ObjectFlags {
2693+
Class = 1 << 0, // Class
2694+
Interface = 1 << 1, // Interface
2695+
Reference = 1 << 2, // Generic type reference
2696+
Tuple = 1 << 3, // Synthesized generic tuple type
2697+
Anonymous = 1 << 4, // Anonymous
2698+
Instantiated = 1 << 5, // Instantiated anonymous type
2699+
ObjectLiteral = 1 << 6, // Originates in an object literal
2700+
EvolvingArray = 1 << 7, // Evolving array type
2701+
ObjectLiteralPatternWithComputedProperties = 1 << 8, // Object literal pattern with computed properties
2702+
ClassOrInterface = Class | Interface
2703+
}
2704+
27002705
// Object types (TypeFlags.ObjectType)
27012706
export interface ObjectType extends Type {
2702-
isObjectLiteralPatternWithComputedProperties?: boolean;
2707+
objectFlags: ObjectFlags;
27032708
}
27042709

27052710
// Class and interface types (TypeFlags.Class and TypeFlags.Interface)
@@ -2753,13 +2758,18 @@ namespace ts {
27532758

27542759
export interface IntersectionType extends UnionOrIntersectionType { }
27552760

2761+
export type StructuredType = ObjectType | UnionType | IntersectionType;
2762+
27562763
/* @internal */
27572764
// An instantiated anonymous type has a target and a mapper
27582765
export interface AnonymousType extends ObjectType {
27592766
target?: AnonymousType; // Instantiation target
27602767
mapper?: TypeMapper; // Instantiation mapper
2761-
elementType?: Type; // Element expressions of evolving array type
2762-
finalArrayType?: Type; // Final array type of evolving array type
2768+
}
2769+
2770+
export interface EvolvingArrayType extends ObjectType {
2771+
elementType: Type; // Element expressions of evolving array type
2772+
finalArrayType?: Type; // Final array type of evolving array type
27632773
}
27642774

27652775
/* @internal */

src/compiler/utilities.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,12 @@ namespace ts {
406406

407407
export function isBlockOrCatchScoped(declaration: Declaration) {
408408
return (getCombinedNodeFlags(declaration) & NodeFlags.BlockScoped) !== 0 ||
409-
isCatchClauseVariableDeclaration(declaration);
409+
isCatchClauseVariableDeclarationOrBindingElement(declaration);
410+
}
411+
412+
export function isCatchClauseVariableDeclarationOrBindingElement(declaration: Declaration) {
413+
const node = getRootDeclaration(declaration);
414+
return node.kind === SyntaxKind.VariableDeclaration && node.parent.kind === SyntaxKind.CatchClause;
410415
}
411416

412417
export function isAmbientModule(node: Node): boolean {
@@ -489,13 +494,6 @@ namespace ts {
489494
}
490495
}
491496

492-
export function isCatchClauseVariableDeclaration(declaration: Declaration) {
493-
return declaration &&
494-
declaration.kind === SyntaxKind.VariableDeclaration &&
495-
declaration.parent &&
496-
declaration.parent.kind === SyntaxKind.CatchClause;
497-
}
498-
499497
// Return display name of an identifier
500498
// Computed property names will just be emitted as "[<expr>]", where <expr> is the source
501499
// text of the expression in the computed property.

src/harness/unittests/commandLineParsing.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// <reference path="..\harness.ts" />
1+
/// <reference path="..\harness.ts" />
22
/// <reference path="..\..\compiler\commandLineParser.ts" />
33

44
namespace ts {
@@ -338,5 +338,38 @@ namespace ts {
338338
}
339339
});
340340
});
341+
342+
it("Parse explicit boolean flag value", () => {
343+
assertParseResult(["--strictNullChecks", "false", "0.ts"],
344+
{
345+
errors: [],
346+
fileNames: ["0.ts"],
347+
options: {
348+
strictNullChecks: false,
349+
}
350+
});
351+
});
352+
353+
it("Parse non boolean argument after boolean flag", () => {
354+
assertParseResult(["--noImplicitAny", "t", "0.ts"],
355+
{
356+
errors: [],
357+
fileNames: ["t", "0.ts"],
358+
options: {
359+
noImplicitAny: true,
360+
}
361+
});
362+
});
363+
364+
it("Parse implicit boolean flag value", () => {
365+
assertParseResult(["--strictNullChecks"],
366+
{
367+
errors: [],
368+
fileNames: [],
369+
options: {
370+
strictNullChecks: true,
371+
}
372+
});
373+
});
341374
});
342375
}

0 commit comments

Comments
 (0)