Skip to content

Commit 1cfce12

Browse files
author
Kanchalai Tanglertsampan
committed
Merge branch 'release-1.8' into checksuperbeforethislexically
2 parents 47a2f3b + 06d62ed commit 1cfce12

File tree

154 files changed

+3632
-160
lines changed

Some content is hidden

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

154 files changed

+3632
-160
lines changed

src/compiler/binder.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,7 @@ namespace ts {
13841384
// Export assignment in some sort of block construct
13851385
bindAnonymousDeclaration(node, SymbolFlags.Alias, getDeclarationName(node));
13861386
}
1387-
else if (boundExpression.kind === SyntaxKind.Identifier) {
1387+
else if (boundExpression.kind === SyntaxKind.Identifier && node.kind === SyntaxKind.ExportAssignment) {
13881388
// An export default clause with an identifier exports all meanings of that identifier
13891389
declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes);
13901390
}
@@ -1435,7 +1435,8 @@ namespace ts {
14351435
// Declare a 'member' in case it turns out the container was an ES5 class
14361436
if (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.FunctionDeclaration) {
14371437
container.symbol.members = container.symbol.members || {};
1438-
declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
1438+
// It's acceptable for multiple 'this' assignments of the same identifier to occur
1439+
declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
14391440
}
14401441
}
14411442

@@ -1444,8 +1445,16 @@ namespace ts {
14441445

14451446
// Look up the function in the local scope, since prototype assignments should
14461447
// follow the function declaration
1447-
const classId = <Identifier>(<PropertyAccessExpression>(<PropertyAccessExpression>node.left).expression).expression;
1448-
const funcSymbol = container.locals[classId.text];
1448+
const leftSideOfAssignment = node.left as PropertyAccessExpression;
1449+
const classPrototype = leftSideOfAssignment.expression as PropertyAccessExpression;
1450+
const constructorFunction = classPrototype.expression as Identifier;
1451+
1452+
// Fix up parent pointers since we're going to use these nodes before we bind into them
1453+
leftSideOfAssignment.parent = node;
1454+
constructorFunction.parent = classPrototype;
1455+
classPrototype.parent = leftSideOfAssignment;
1456+
1457+
const funcSymbol = container.locals[constructorFunction.text];
14491458
if (!funcSymbol || !(funcSymbol.flags & SymbolFlags.Function)) {
14501459
return;
14511460
}
@@ -1456,7 +1465,7 @@ namespace ts {
14561465
}
14571466

14581467
// Declare the method/property
1459-
declareSymbol(funcSymbol.members, funcSymbol, <PropertyAccessExpression>node.left, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
1468+
declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
14601469
}
14611470

14621471
function bindCallExpression(node: CallExpression) {

src/compiler/checker.ts

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2845,7 +2845,7 @@ namespace ts {
28452845
}
28462846
// Handle module.exports = expr
28472847
if (declaration.kind === SyntaxKind.BinaryExpression) {
2848-
return links.type = checkExpression((<BinaryExpression>declaration).right);
2848+
return links.type = getUnionType(map(symbol.declarations, (decl: BinaryExpression) => checkExpressionCached(decl.right)));
28492849
}
28502850
if (declaration.kind === SyntaxKind.PropertyAccessExpression) {
28512851
// Declarations only exist for property access expressions for certain
@@ -7242,6 +7242,15 @@ namespace ts {
72427242
// mark iteration statement as containing block-scoped binding captured in some function
72437243
getNodeLinks(current).flags |= NodeCheckFlags.LoopWithCapturedBlockScopedBinding;
72447244
}
7245+
7246+
// mark variables that are declared in loop initializer and reassigned inside the body of ForStatement.
7247+
// if body of ForStatement will be converted to function then we'll need a extra machinery to propagate reassigned values back.
7248+
if (container.kind === SyntaxKind.ForStatement &&
7249+
getAncestor(symbol.valueDeclaration, SyntaxKind.VariableDeclarationList).parent === container &&
7250+
isAssignedInBodyOfForStatement(node, <ForStatement>container)) {
7251+
getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.NeedsLoopOutParameter;
7252+
}
7253+
72457254
// set 'declared inside loop' bit on the block-scoped binding
72467255
getNodeLinks(symbol.valueDeclaration).flags |= NodeCheckFlags.BlockScopedBindingInLoop;
72477256
}
@@ -7251,6 +7260,41 @@ namespace ts {
72517260
}
72527261
}
72537262

7263+
function isAssignedInBodyOfForStatement(node: Identifier, container: ForStatement): boolean {
7264+
let current: Node = node;
7265+
// skip parenthesized nodes
7266+
while (current.parent.kind === SyntaxKind.ParenthesizedExpression) {
7267+
current = current.parent;
7268+
}
7269+
7270+
// check if node is used as LHS in some assignment expression
7271+
let isAssigned = false;
7272+
if (current.parent.kind === SyntaxKind.BinaryExpression) {
7273+
isAssigned = (<BinaryExpression>current.parent).left === current && isAssignmentOperator((<BinaryExpression>current.parent).operatorToken.kind);
7274+
}
7275+
7276+
if ((current.parent.kind === SyntaxKind.PrefixUnaryExpression || current.parent.kind === SyntaxKind.PostfixUnaryExpression)) {
7277+
const expr = <PrefixUnaryExpression | PostfixUnaryExpression>current.parent;
7278+
isAssigned = expr.operator === SyntaxKind.PlusPlusToken || expr.operator === SyntaxKind.MinusMinusToken;
7279+
}
7280+
7281+
if (!isAssigned) {
7282+
return false;
7283+
}
7284+
7285+
// at this point we know that node is the target of assignment
7286+
// now check that modification happens inside the statement part of the ForStatement
7287+
while (current !== container) {
7288+
if (current === container.statement) {
7289+
return true;
7290+
}
7291+
else {
7292+
current = current.parent;
7293+
}
7294+
}
7295+
return false;
7296+
}
7297+
72547298
function captureLexicalThis(node: Node, container: Node): void {
72557299
getNodeLinks(node).flags |= NodeCheckFlags.LexicalThis;
72567300
if (container.kind === SyntaxKind.PropertyDeclaration || container.kind === SyntaxKind.Constructor) {
@@ -10412,9 +10456,11 @@ namespace ts {
1041210456

1041310457
function getReturnTypeFromJSDocComment(func: SignatureDeclaration | FunctionDeclaration): Type {
1041410458
const returnTag = getJSDocReturnTag(func);
10415-
if (returnTag) {
10459+
if (returnTag && returnTag.typeExpression) {
1041610460
return getTypeFromTypeNode(returnTag.typeExpression.type);
1041710461
}
10462+
10463+
return undefined;
1041810464
}
1041910465

1042010466
function createPromiseType(promisedType: Type): Type {
@@ -10489,7 +10535,8 @@ namespace ts {
1048910535
}
1049010536
else {
1049110537
error(func, Diagnostics.No_best_common_type_exists_among_return_expressions);
10492-
return unknownType;
10538+
// Defer to unioning the return types so we get a) downstream errors earlier and b) better Salsa experience
10539+
return getUnionType(types);
1049310540
}
1049410541
}
1049510542

@@ -15400,6 +15447,20 @@ namespace ts {
1540015447
return getSymbolOfNode(entityName.parent);
1540115448
}
1540215449

15450+
if (isInJavaScriptFile(entityName) && entityName.parent.kind === SyntaxKind.PropertyAccessExpression) {
15451+
const specialPropertyAssignmentKind = getSpecialPropertyAssignmentKind(entityName.parent.parent);
15452+
switch (specialPropertyAssignmentKind) {
15453+
case SpecialPropertyAssignmentKind.ExportsProperty:
15454+
case SpecialPropertyAssignmentKind.PrototypeProperty:
15455+
return getSymbolOfNode(entityName.parent);
15456+
case SpecialPropertyAssignmentKind.ThisProperty:
15457+
case SpecialPropertyAssignmentKind.ModuleExports:
15458+
return getSymbolOfNode(entityName.parent.parent);
15459+
default:
15460+
// Fall through if it is not a special property assignment
15461+
}
15462+
}
15463+
1540315464
if (entityName.parent.kind === SyntaxKind.ExportAssignment) {
1540415465
return resolveEntityName(<Identifier>entityName,
1540515466
/*all meanings*/ SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace | SymbolFlags.Alias);

src/compiler/commandLineParser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,11 @@ namespace ts {
294294
name: "allowJs",
295295
type: "boolean",
296296
description: Diagnostics.Allow_javascript_files_to_be_compiled
297+
},
298+
{
299+
name: "noImplicitUseStrict",
300+
type: "boolean",
301+
description: Diagnostics.Do_not_emit_use_strict_directives_in_module_output
297302
}
298303
];
299304

src/compiler/declarationEmitter.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -695,10 +695,6 @@ namespace ts {
695695
}
696696

697697
function writeImportDeclaration(node: ImportDeclaration) {
698-
if (!node.importClause && !(node.flags & NodeFlags.Export)) {
699-
// do not write non-exported import declarations that don't have import clauses
700-
return;
701-
}
702698
emitJsDocComments(node);
703699
if (node.flags & NodeFlags.Export) {
704700
write("export ");

src/compiler/diagnosticMessages.json

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{
1+
{
22
"Unterminated string literal.": {
33
"category": "Error",
44
"code": 1002
@@ -2171,6 +2171,7 @@
21712171
"category": "Error",
21722172
"code": 5059
21732173
},
2174+
21742175

21752176
"Concatenate and emit output to single file.": {
21762177
"category": "Message",
@@ -2216,10 +2217,10 @@
22162217
"category": "Message",
22172218
"code": 6011
22182219
},
2219-
"Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015' (experimental)": {
2220-
"category": "Message",
2221-
"code": 6015
2222-
},
2220+
"Specify ECMAScript target version: 'ES3' (default), 'ES5', or 'ES2015' (experimental)": {
2221+
"category": "Message",
2222+
"code": 6015
2223+
},
22232224
"Specify module code generation: 'commonjs', 'amd', 'system', 'umd' or 'es2015'": {
22242225
"category": "Message",
22252226
"code": 6016
@@ -2445,6 +2446,10 @@
24452446
"category": "Message",
24462447
"code": 6084
24472448
},
2449+
"Do not emit 'use strict' directives in module output.": {
2450+
"category": "Message",
2451+
"code": 6112
2452+
},
24482453

24492454
"Variable '{0}' implicitly has an '{1}' type.": {
24502455
"category": "Error",
@@ -2632,23 +2637,23 @@
26322637
"code": 17004
26332638
},
26342639
"A constructor cannot contain a 'super' call when its class extends 'null'": {
2635-
"category": "Error",
2636-
"code": 17005
2640+
"category": "Error",
2641+
"code": 17005
26372642
},
26382643
"An unary expression with the '{0}' operator is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": {
2639-
"category": "Error",
2640-
"code": 17006
2644+
"category": "Error",
2645+
"code": 17006
26412646
},
26422647
"A type assertion expression is not allowed in the left-hand side of an exponentiation expression. Consider enclosing the expression in parentheses.": {
2643-
"category": "Error",
2644-
"code": 17007
2648+
"category": "Error",
2649+
"code": 17007
26452650
},
26462651
"JSX element '{0}' has no corresponding closing tag.": {
2647-
"category": "Error",
2648-
"code": 17008
2652+
"category": "Error",
2653+
"code": 17008
26492654
},
26502655
"'super' must be called before accessing 'this' in the constructor of a derived class.": {
2651-
"category": "Error",
2652-
"code": 17009
2656+
"category": "Error",
2657+
"code": 17009
26532658
}
2654-
}
2659+
}

0 commit comments

Comments
 (0)