Skip to content

Commit d7e1d34

Browse files
committed
Merge branch 'master' of https://github.com/Microsoft/TypeScript into fixLargeProjectTry2
2 parents c8e0b00 + 279fec7 commit d7e1d34

File tree

1,237 files changed

+7817
-6931
lines changed

Some content is hidden

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

1,237 files changed

+7817
-6931
lines changed

src/compiler/checker.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,12 +1444,6 @@ namespace ts {
14441444
return result;
14451445
}
14461446
break;
1447-
case SyntaxKind.ClassDeclaration:
1448-
case SyntaxKind.InterfaceDeclaration:
1449-
if (result = callback(getSymbolOfNode(location).members)) {
1450-
return result;
1451-
}
1452-
break;
14531447
}
14541448
}
14551449

@@ -1515,7 +1509,9 @@ namespace ts {
15151509
}
15161510

15171511
if (symbol) {
1518-
return forEachSymbolTableInScope(enclosingDeclaration, getAccessibleSymbolChainFromSymbolTable);
1512+
if (!(isPropertyOrMethodDeclarationSymbol(symbol))) {
1513+
return forEachSymbolTableInScope(enclosingDeclaration, getAccessibleSymbolChainFromSymbolTable);
1514+
}
15191515
}
15201516
}
15211517

@@ -1548,6 +1544,24 @@ namespace ts {
15481544
return qualify;
15491545
}
15501546

1547+
function isPropertyOrMethodDeclarationSymbol(symbol: Symbol) {
1548+
if (symbol.declarations && symbol.declarations.length) {
1549+
for (const declaration of symbol.declarations) {
1550+
switch (declaration.kind) {
1551+
case SyntaxKind.PropertyDeclaration:
1552+
case SyntaxKind.MethodDeclaration:
1553+
case SyntaxKind.GetAccessor:
1554+
case SyntaxKind.SetAccessor:
1555+
continue;
1556+
default:
1557+
return false;
1558+
}
1559+
}
1560+
return true;
1561+
}
1562+
return false;
1563+
}
1564+
15511565
function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessibilityResult {
15521566
if (symbol && enclosingDeclaration && !(symbol.flags & SymbolFlags.TypeParameter)) {
15531567
const initialSymbol = symbol;

src/compiler/emitter.ts

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4218,12 +4218,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
42184218

42194219
function emitVariableDeclaration(node: VariableDeclaration) {
42204220
if (isBindingPattern(node.name)) {
4221-
if (languageVersion < ScriptTarget.ES6) {
4222-
emitDestructuring(node, /*isAssignmentExpressionStatement*/ false);
4223-
}
4224-
else {
4221+
const isExported = getCombinedNodeFlags(node) & NodeFlags.Export;
4222+
if (languageVersion >= ScriptTarget.ES6 && (!isExported || modulekind === ModuleKind.ES6)) {
4223+
// emit ES6 destructuring only if target module is ES6 or variable is not exported
4224+
// exported variables in CJS/AMD are prefixed with 'exports.' so result javascript { exports.toString } = 1; is illegal
4225+
4226+
const isTopLevelDeclarationInSystemModule =
4227+
modulekind === ModuleKind.System &&
4228+
shouldHoistVariable(node, /*checkIfSourceFileLevelDecl*/true);
4229+
4230+
if (isTopLevelDeclarationInSystemModule) {
4231+
// In System modules top level variables are hoisted
4232+
// so variable declarations with destructuring are turned into destructuring assignments.
4233+
// As a result, they will need parentheses to disambiguate object binding assignments from blocks.
4234+
write("(");
4235+
}
4236+
42254237
emit(node.name);
42264238
emitOptional(" = ", node.initializer);
4239+
4240+
if (isTopLevelDeclarationInSystemModule) {
4241+
write(")");
4242+
}
4243+
}
4244+
else {
4245+
emitDestructuring(node, /*isAssignmentExpressionStatement*/ false);
42274246
}
42284247
}
42294248
else {
@@ -5278,9 +5297,11 @@ const _super = (function (geti, seti) {
52785297

52795298
function emitClassLikeDeclarationForES6AndHigher(node: ClassLikeDeclaration) {
52805299
let decoratedClassAlias: string;
5281-
const thisNodeIsDecorated = nodeIsDecorated(node);
5300+
const isHoistedDeclarationInSystemModule = shouldHoistDeclarationInSystemJsModule(node);
5301+
const isDecorated = nodeIsDecorated(node);
5302+
const rewriteAsClassExpression = isDecorated || isHoistedDeclarationInSystemModule;
52825303
if (node.kind === SyntaxKind.ClassDeclaration) {
5283-
if (thisNodeIsDecorated) {
5304+
if (rewriteAsClassExpression) {
52845305
// When we emit an ES6 class that has a class decorator, we must tailor the
52855306
// emit to certain specific cases.
52865307
//
@@ -5361,7 +5382,10 @@ const _super = (function (geti, seti) {
53615382
// [Example 4]
53625383
//
53635384

5364-
if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithBodyScopedClassBinding) {
5385+
// NOTE: we reuse the same rewriting logic for cases when targeting ES6 and module kind is System.
5386+
// Because of hoisting top level class declaration need to be emitted as class expressions.
5387+
// Double bind case is only required if node is decorated.
5388+
if (isDecorated && resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithBodyScopedClassBinding) {
53655389
decoratedClassAlias = unescapeIdentifier(makeUniqueName(node.name ? node.name.text : "default"));
53665390
decoratedClassAliases[getNodeId(node)] = decoratedClassAlias;
53675391
write(`let ${decoratedClassAlias};`);
@@ -5372,7 +5396,9 @@ const _super = (function (geti, seti) {
53725396
write("export ");
53735397
}
53745398

5375-
write("let ");
5399+
if (!isHoistedDeclarationInSystemModule) {
5400+
write("let ");
5401+
}
53765402
emitDeclarationName(node);
53775403
if (decoratedClassAlias !== undefined) {
53785404
write(` = ${decoratedClassAlias}`);
@@ -5416,7 +5442,7 @@ const _super = (function (geti, seti) {
54165442
// emit name if
54175443
// - node has a name
54185444
// - this is default export with static initializers
5419-
if (node.name || (node.flags & NodeFlags.Default && (staticProperties.length > 0 || modulekind !== ModuleKind.ES6) && !thisNodeIsDecorated)) {
5445+
if (node.name || (node.flags & NodeFlags.Default && (staticProperties.length > 0 || modulekind !== ModuleKind.ES6) && !rewriteAsClassExpression)) {
54205446
write(" ");
54215447
emitDeclarationName(node);
54225448
}
@@ -5436,7 +5462,7 @@ const _super = (function (geti, seti) {
54365462
writeLine();
54375463
emitToken(SyntaxKind.CloseBraceToken, node.members.end);
54385464

5439-
if (thisNodeIsDecorated) {
5465+
if (rewriteAsClassExpression) {
54405466
decoratedClassAliases[getNodeId(node)] = undefined;
54415467
write(";");
54425468
}
@@ -5476,7 +5502,7 @@ const _super = (function (geti, seti) {
54765502
// module), export it
54775503
if (node.flags & NodeFlags.Default) {
54785504
// if this is a top level default export of decorated class, write the export after the declaration.
5479-
if (thisNodeIsDecorated) {
5505+
if (isDecorated) {
54805506
writeLine();
54815507
write("export default ");
54825508
emitDeclarationName(node);

src/services/services.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3505,7 +3505,18 @@ namespace ts {
35053505
// We don't want to complete using the type acquired by the shape
35063506
// of the binding pattern; we are only interested in types acquired
35073507
// through type declaration or inference.
3508-
if (rootDeclaration.initializer || rootDeclaration.type) {
3508+
// Also proceed if rootDeclaration is parameter and if its containing function expression\arrow function is contextually typed -
3509+
// type of parameter will flow in from the contextual type of the function
3510+
let canGetType = !!(rootDeclaration.initializer || rootDeclaration.type);
3511+
if (!canGetType && rootDeclaration.kind === SyntaxKind.Parameter) {
3512+
if (isExpression(rootDeclaration.parent)) {
3513+
canGetType = !!typeChecker.getContextualType(<Expression>rootDeclaration.parent);
3514+
}
3515+
else if (rootDeclaration.parent.kind === SyntaxKind.MethodDeclaration || rootDeclaration.parent.kind === SyntaxKind.SetAccessor) {
3516+
canGetType = isExpression(rootDeclaration.parent.parent) && !!typeChecker.getContextualType(<Expression>rootDeclaration.parent.parent);
3517+
}
3518+
}
3519+
if (canGetType) {
35093520
typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer);
35103521
existingMembers = (<BindingPattern>objectLikeContainer).elements;
35113522
}

0 commit comments

Comments
 (0)