Skip to content

Commit 63b5790

Browse files
author
Andy Hanson
committed
Merge branch 'master' into navbar_root
2 parents 58d69cd + 6304d79 commit 63b5790

File tree

9 files changed

+84
-30
lines changed

9 files changed

+84
-30
lines changed

src/compiler/binder.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,12 +1880,20 @@ namespace ts {
18801880
}
18811881

18821882
function bindThisPropertyAssignment(node: BinaryExpression) {
1883-
// Declare a 'member' in case it turns out the container was an ES5 class
1884-
if (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.FunctionDeclaration) {
1885-
container.symbol.members = container.symbol.members || {};
1886-
// It's acceptable for multiple 'this' assignments of the same identifier to occur
1887-
declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
1883+
// Declare a 'member' in case it turns out the container was an ES5 class or ES6 constructor
1884+
let assignee: Node;
1885+
if (container.kind === SyntaxKind.FunctionDeclaration || container.kind === SyntaxKind.FunctionDeclaration) {
1886+
assignee = container;
18881887
}
1888+
else if (container.kind === SyntaxKind.Constructor) {
1889+
assignee = container.parent;
1890+
}
1891+
else {
1892+
return;
1893+
}
1894+
assignee.symbol.members = assignee.symbol.members || {};
1895+
// It's acceptable for multiple 'this' assignments of the same identifier to occur
1896+
declareSymbol(assignee.symbol.members, assignee.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
18891897
}
18901898

18911899
function bindPrototypePropertyAssignment(node: BinaryExpression) {

src/compiler/emitter.ts

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5359,17 +5359,17 @@ const _super = (function (geti, seti) {
53595359
//
53605360
// TypeScript | Javascript
53615361
// --------------------------------|------------------------------------
5362-
// @dec | let C_1;
5363-
// class C { | let C = C_1 = class C {
5364-
// static x() { return C.y; } | static x() { return C_1.y; }
5365-
// static y = 1; | }
5362+
// @dec | let C_1 = class C {
5363+
// class C { | static x() { return C_1.y; }
5364+
// static x() { return C.y; } | }
5365+
// static y = 1; | let C = C_1;
53665366
// } | C.y = 1;
53675367
// | C = C_1 = __decorate([dec], C);
53685368
// --------------------------------|------------------------------------
5369-
// @dec | let C_1;
5370-
// export class C { | export let C = C_1 = class C {
5371-
// static x() { return C.y; } | static x() { return C_1.y; }
5372-
// static y = 1; | }
5369+
// @dec | let C_1 = class C {
5370+
// export class C { | static x() { return C_1.y; }
5371+
// static x() { return C.y; } | }
5372+
// static y = 1; | export let C = C_1;
53735373
// } | C.y = 1;
53745374
// | C = C_1 = __decorate([dec], C);
53755375
// ---------------------------------------------------------------------
@@ -5398,10 +5398,10 @@ const _super = (function (geti, seti) {
53985398
//
53995399
// TypeScript | Javascript
54005400
// --------------------------------|------------------------------------
5401-
// @dec | let C_1;
5402-
// export default class C { | let C = C_1 = class C {
5403-
// static x() { return C.y; } | static x() { return C_1.y; }
5404-
// static y = 1; | }
5401+
// @dec | let C_1 = class C {
5402+
// export default class C { | static x() { return C_1.y; }
5403+
// static x() { return C.y; } | };
5404+
// static y = 1; | let C = C_1;
54055405
// } | C.y = 1;
54065406
// | C = C_1 = __decorate([dec], C);
54075407
// | export default C;
@@ -5410,25 +5410,25 @@ const _super = (function (geti, seti) {
54105410
//
54115411

54125412
// NOTE: we reuse the same rewriting logic for cases when targeting ES6 and module kind is System.
5413-
// Because of hoisting top level class declaration need to be emitted as class expressions.
5413+
// Because of hoisting top level class declaration need to be emitted as class expressions.
54145414
// Double bind case is only required if node is decorated.
54155415
if (isDecorated && resolver.getNodeCheckFlags(node) & NodeCheckFlags.ClassWithBodyScopedClassBinding) {
54165416
decoratedClassAlias = unescapeIdentifier(makeUniqueName(node.name ? node.name.text : "default"));
54175417
decoratedClassAliases[getNodeId(node)] = decoratedClassAlias;
5418-
write(`let ${decoratedClassAlias};`);
5419-
writeLine();
54205418
}
54215419

5422-
if (isES6ExportedDeclaration(node) && !(node.flags & NodeFlags.Default)) {
5420+
if (isES6ExportedDeclaration(node) && !(node.flags & NodeFlags.Default) && decoratedClassAlias === undefined) {
54235421
write("export ");
54245422
}
54255423

54265424
if (!isHoistedDeclarationInSystemModule) {
54275425
write("let ");
54285426
}
5429-
emitDeclarationName(node);
54305427
if (decoratedClassAlias !== undefined) {
5431-
write(` = ${decoratedClassAlias}`);
5428+
write(`${decoratedClassAlias}`);
5429+
}
5430+
else {
5431+
emitDeclarationName(node);
54325432
}
54335433

54345434
write(" = ");
@@ -5490,6 +5490,16 @@ const _super = (function (geti, seti) {
54905490
emitToken(SyntaxKind.CloseBraceToken, node.members.end);
54915491

54925492
if (rewriteAsClassExpression) {
5493+
if (decoratedClassAlias !== undefined) {
5494+
write(";");
5495+
writeLine();
5496+
if (isES6ExportedDeclaration(node) && !(node.flags & NodeFlags.Default)) {
5497+
write("export ");
5498+
}
5499+
write("let ");
5500+
emitDeclarationName(node);
5501+
write(` = ${decoratedClassAlias}`);
5502+
}
54935503
decoratedClassAliases[getNodeId(node)] = undefined;
54945504
write(";");
54955505
}

src/services/navigationBar.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ namespace ts.NavigationBar {
9898
case SyntaxKind.ImportEqualsDeclaration:
9999
case SyntaxKind.ImportSpecifier:
100100
case SyntaxKind.ExportSpecifier:
101+
case SyntaxKind.TypeAliasDeclaration:
101102
childNodes.push(node);
102103
break;
103104
}
@@ -330,6 +331,8 @@ namespace ts.NavigationBar {
330331
case SyntaxKind.InterfaceDeclaration:
331332
return createItem(node, getTextOfNode((<InterfaceDeclaration>node).name), ts.ScriptElementKind.interfaceElement);
332333

334+
case SyntaxKind.TypeAliasDeclaration:
335+
return createItem(node, getTextOfNode((<TypeAliasDeclaration>node).name), ts.ScriptElementKind.typeElement);
333336

334337
case SyntaxKind.CallSignature:
335338
return createItem(node, "()", ts.ScriptElementKind.callSignatureElement);

tests/baselines/reference/decoratorOnClass5.es6.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
1616
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1717
return c > 3 && r && Object.defineProperty(target, key, r), r;
1818
};
19-
let C_1;
20-
let C = C_1 = class C {
19+
let C_1 = class C {
2120
static x() { return C_1.y; }
2221
};
22+
let C = C_1;
2323
C.y = 1;
2424
C = C_1 = __decorate([
2525
dec

tests/baselines/reference/decoratorOnClass6.es6.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
1616
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1717
return c > 3 && r && Object.defineProperty(target, key, r), r;
1818
};
19-
let C_1;
20-
export let C = C_1 = class C {
19+
let C_1 = class C {
2120
static x() { return C_1.y; }
2221
};
22+
export let C = C_1;
2323
C.y = 1;
2424
C = C_1 = __decorate([
2525
dec

tests/baselines/reference/decoratorOnClass7.es6.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
1616
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
1717
return c > 3 && r && Object.defineProperty(target, key, r), r;
1818
};
19-
let C_1;
20-
let C = C_1 = class C {
19+
let C_1 = class C {
2120
static x() { return C_1.y; }
2221
};
22+
let C = C_1;
2323
C.y = 1;
2424
C = C_1 = __decorate([
2525
dec

tests/cases/fourslash/navigationBarItemsTypeAlias.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ verify.navigationBar([
66
{
77
"text": "<global>",
88
"kind": "module",
9-
"childItems": [],
9+
"childItems": [
10+
{
11+
"text": "T",
12+
"kind": "type"
13+
}
14+
],
1015
"indent": 0
1116
},
1217
{
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @allowJs: true
4+
// @Filename: a.js
5+
////class C {
6+
//// constructor(y) {
7+
//// this./**/[|x|] = y;
8+
//// }
9+
////}
10+
////var t = new C(12);
11+
////t.[|x|] = 11;
12+
13+
goTo.marker();
14+
verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @allowJs: true
4+
// @Filename: a.js
5+
////class C {
6+
//// constructor(y) {
7+
//// this.[|x|] = y;
8+
//// }
9+
////}
10+
////var t = new C(12);
11+
////t./**/[|x|] = 11;
12+
13+
goTo.marker();
14+
verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false);

0 commit comments

Comments
 (0)