Skip to content

Commit 32af046

Browse files
committed
Merge branch 'master' into object-spread
2 parents 8f59993 + 1884c89 commit 32af046

45 files changed

Lines changed: 1318 additions & 301 deletions

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); }
@@ -2425,6 +2425,9 @@ namespace ts {
24252425
case SyntaxKind.HeritageClause:
24262426
return computeHeritageClause(<HeritageClause>node, subtreeFlags);
24272427

2428+
case SyntaxKind.CatchClause:
2429+
return computeCatchClause(<CatchClause>node, subtreeFlags);
2430+
24282431
case SyntaxKind.ExpressionWithTypeArguments:
24292432
return computeExpressionWithTypeArguments(<ExpressionWithTypeArguments>node, subtreeFlags);
24302433

@@ -2654,6 +2657,17 @@ namespace ts {
26542657
return transformFlags & ~TransformFlags.NodeExcludes;
26552658
}
26562659

2660+
function computeCatchClause(node: CatchClause, subtreeFlags: TransformFlags) {
2661+
let transformFlags = subtreeFlags;
2662+
2663+
if (node.variableDeclaration && isBindingPattern(node.variableDeclaration.name)) {
2664+
transformFlags |= TransformFlags.AssertES2015;
2665+
}
2666+
2667+
node.transformFlags = transformFlags | TransformFlags.HasComputedFlags;
2668+
return transformFlags & ~TransformFlags.NodeExcludes;
2669+
}
2670+
26572671
function computeExpressionWithTypeArguments(node: ExpressionWithTypeArguments, subtreeFlags: TransformFlags) {
26582672
// An ExpressionWithTypeArguments is ES6 syntax, as it is used in the
26592673
// extends clause of a class.

src/compiler/checker.ts

Lines changed: 211 additions & 188 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
@@ -3085,6 +3081,7 @@
30853081
"category": "Error",
30863082
"code": 17010
30873083
},
3084+
30883085
"Circularity detected while resolving configuration: {0}": {
30893086
"category": "Error",
30903087
"code": 18000
@@ -3093,6 +3090,15 @@
30933090
"category": "Error",
30943091
"code": 18001
30953092
},
3093+
"The 'files' list in config file '{0}' is empty.": {
3094+
"category": "Error",
3095+
"code": 18002
3096+
},
3097+
"No inputs were found in config file '{0}'. Specified 'include' paths were '{1}' and 'exclude' paths were '{2}'.": {
3098+
"category": "Error",
3099+
"code": 18003
3100+
},
3101+
30963102
"Add missing 'super()' call.": {
30973103
"category": "Message",
30983104
"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
@@ -5497,7 +5497,7 @@ namespace ts {
54975497

54985498
exportDeclaration.name = parseIdentifier();
54995499

5500-
parseExpected(SyntaxKind.SemicolonToken);
5500+
parseSemicolon();
55015501

55025502
return finishNode(exportDeclaration);
55035503
}

src/compiler/program.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ namespace ts {
474474
(oldOptions.baseUrl !== options.baseUrl) ||
475475
(oldOptions.maxNodeModuleJsDepth !== options.maxNodeModuleJsDepth) ||
476476
!arrayIsEqualTo(oldOptions.lib, options.lib) ||
477-
!arrayIsEqualTo(oldOptions.typeRoots, oldOptions.typeRoots) ||
477+
!arrayIsEqualTo(oldOptions.typeRoots, options.typeRoots) ||
478478
!arrayIsEqualTo(oldOptions.rootDirs, options.rootDirs) ||
479479
!equalOwnProperties(oldOptions.paths, options.paths)) {
480480
return false;

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: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,25 +2635,18 @@ namespace ts {
26352635
Null = 1 << 12,
26362636
Never = 1 << 13, // Never type
26372637
TypeParameter = 1 << 14, // Type parameter
2638-
Class = 1 << 15, // Class
2639-
Interface = 1 << 16, // Interface
2640-
Reference = 1 << 17, // Generic type reference
2641-
Tuple = 1 << 18, // Synthesized generic tuple type
2642-
Union = 1 << 19, // Union (T | U)
2643-
Intersection = 1 << 20, // Intersection (T & U)
2644-
Anonymous = 1 << 21, // Anonymous
2645-
Instantiated = 1 << 22, // Instantiated anonymous type
2638+
Object = 1 << 15, // Object type
2639+
Union = 1 << 16, // Union (T | U)
2640+
Intersection = 1 << 17, // Intersection (T & U)
26462641
/* @internal */
2647-
ObjectLiteral = 1 << 23, // Originates in an object literal
2642+
FreshLiteral = 1 << 18, // Fresh literal type
26482643
/* @internal */
2649-
FreshLiteral = 1 << 24, // Fresh literal type
2644+
ContainsWideningType = 1 << 19, // Type is or contains undefined or null widening type
26502645
/* @internal */
2651-
ContainsWideningType = 1 << 25, // Type is or contains undefined or null widening type
2646+
ContainsObjectLiteral = 1 << 20, // Type is or contains object literal type
26522647
/* @internal */
2653-
ContainsObjectLiteral = 1 << 26, // Type is or contains object literal type
2654-
/* @internal */
2655-
ContainsAnyFunctionType = 1 << 27, // Type is or contains object literal type
2656-
Spread = 1 << 28, // Spread types
2648+
ContainsAnyFunctionType = 1 << 21, // Type is or contains object literal type
2649+
Spread = 1 << 22, // Spread types
26572650

26582651
/* @internal */
26592652
Nullable = Undefined | Null,
@@ -2670,15 +2663,14 @@ namespace ts {
26702663
NumberLike = Number | NumberLiteral | Enum | EnumLiteral,
26712664
BooleanLike = Boolean | BooleanLiteral,
26722665
EnumLike = Enum | EnumLiteral,
2673-
ObjectType = Class | Interface | Reference | Tuple | Anonymous,
26742666
UnionOrIntersection = Union | Intersection,
2675-
StructuredType = ObjectType | Union | Intersection | Spread,
2667+
StructuredType = Object | Union | Intersection | Spread,
26762668
StructuredOrTypeParameter = StructuredType | TypeParameter,
26772669

26782670
// 'Narrowable' types are types where narrowing actually narrows.
26792671
// This *should* be every type other than null, undefined, void, and never
26802672
Narrowable = Any | StructuredType | TypeParameter | StringLike | NumberLike | BooleanLike | ESSymbol | Spread,
2681-
NotUnionOrUnit = Any | ESSymbol | ObjectType,
2673+
NotUnionOrUnit = Any | ESSymbol | Object,
26822674
/* @internal */
26832675
RequiresWidening = ContainsWideningType | ContainsObjectLiteral,
26842676
/* @internal */
@@ -2721,9 +2713,22 @@ namespace ts {
27212713
baseType: EnumType & UnionType; // Base enum type
27222714
}
27232715

2716+
export const enum ObjectFlags {
2717+
Class = 1 << 0, // Class
2718+
Interface = 1 << 1, // Interface
2719+
Reference = 1 << 2, // Generic type reference
2720+
Tuple = 1 << 3, // Synthesized generic tuple type
2721+
Anonymous = 1 << 4, // Anonymous
2722+
Instantiated = 1 << 5, // Instantiated anonymous type
2723+
ObjectLiteral = 1 << 6, // Originates in an object literal
2724+
EvolvingArray = 1 << 7, // Evolving array type
2725+
ObjectLiteralPatternWithComputedProperties = 1 << 8, // Object literal pattern with computed properties
2726+
ClassOrInterface = Class | Interface
2727+
}
2728+
27242729
// Object types (TypeFlags.ObjectType)
27252730
export interface ObjectType extends Type {
2726-
isObjectLiteralPatternWithComputedProperties?: boolean;
2731+
objectFlags: ObjectFlags;
27272732
}
27282733

27292734
// Class and interface types (TypeFlags.Class and TypeFlags.Interface)
@@ -2777,6 +2782,8 @@ namespace ts {
27772782

27782783
export interface IntersectionType extends UnionOrIntersectionType { }
27792784

2785+
export type StructuredType = ObjectType | UnionType | IntersectionType;
2786+
27802787
/* @internal */
27812788
export interface SpreadType extends Type {
27822789
left: SpreadType | ResolvedType;
@@ -2788,8 +2795,11 @@ namespace ts {
27882795
export interface AnonymousType extends ObjectType {
27892796
target?: AnonymousType; // Instantiation target
27902797
mapper?: TypeMapper; // Instantiation mapper
2791-
elementType?: Type; // Element expressions of evolving array type
2792-
finalArrayType?: Type; // Final array type of evolving array type
2798+
}
2799+
2800+
export interface EvolvingArrayType extends ObjectType {
2801+
elementType: Type; // Element expressions of evolving array type
2802+
finalArrayType?: Type; // Final array type of evolving array type
27932803
}
27942804

27952805
/* @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.

0 commit comments

Comments
 (0)