Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf2c5233

Browse files
joeywattsmheiber
authored andcommitted
Add private named instance field transformation (#31)
Implements private instance fields on top of the class properties refactor.Signed-off-by: Joseph Watts <jwatts43@bloomberg.net>Signed-off-by: Max Heiber <max.heiber@gmail.com>
1 parent43cf208 commitf2c5233

File tree

56 files changed

+1740
-113
lines changed

Some content is hidden

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

56 files changed

+1740
-113
lines changed

‎src/compiler/transformers/classProperties.ts‎

Lines changed: 428 additions & 17 deletions
Large diffs are not rendered by default.

‎src/compiler/transformers/generators.ts‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -667,28 +667,6 @@ namespace ts {
667667
}
668668
}
669669

670-
functionisCompoundAssignment(kind:BinaryOperator):kind isCompoundAssignmentOperator{
671-
returnkind>=SyntaxKind.FirstCompoundAssignment
672-
&&kind<=SyntaxKind.LastCompoundAssignment;
673-
}
674-
675-
functiongetOperatorForCompoundAssignment(kind:CompoundAssignmentOperator):BitwiseOperatorOrHigher{
676-
switch(kind){
677-
caseSyntaxKind.PlusEqualsToken:returnSyntaxKind.PlusToken;
678-
caseSyntaxKind.MinusEqualsToken:returnSyntaxKind.MinusToken;
679-
caseSyntaxKind.AsteriskEqualsToken:returnSyntaxKind.AsteriskToken;
680-
caseSyntaxKind.AsteriskAsteriskEqualsToken:returnSyntaxKind.AsteriskAsteriskToken;
681-
caseSyntaxKind.SlashEqualsToken:returnSyntaxKind.SlashToken;
682-
caseSyntaxKind.PercentEqualsToken:returnSyntaxKind.PercentToken;
683-
caseSyntaxKind.LessThanLessThanEqualsToken:returnSyntaxKind.LessThanLessThanToken;
684-
caseSyntaxKind.GreaterThanGreaterThanEqualsToken:returnSyntaxKind.GreaterThanGreaterThanToken;
685-
caseSyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:returnSyntaxKind.GreaterThanGreaterThanGreaterThanToken;
686-
caseSyntaxKind.AmpersandEqualsToken:returnSyntaxKind.AmpersandToken;
687-
caseSyntaxKind.BarEqualsToken:returnSyntaxKind.BarToken;
688-
caseSyntaxKind.CaretEqualsToken:returnSyntaxKind.CaretToken;
689-
}
690-
}
691-
692670
/**
693671
* Visits a right-associative binary expression containing `yield`.
694672
*

‎src/compiler/transformers/utilities.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,28 @@ namespace ts {
250250
isWellKnownSymbolSyntactically(expression);
251251
}
252252

253+
exportfunctionisCompoundAssignment(kind:BinaryOperator):kind isCompoundAssignmentOperator{
254+
returnkind>=SyntaxKind.FirstCompoundAssignment
255+
&&kind<=SyntaxKind.LastCompoundAssignment;
256+
}
257+
258+
exportfunctiongetOperatorForCompoundAssignment(kind:CompoundAssignmentOperator):BitwiseOperatorOrHigher{
259+
switch(kind){
260+
caseSyntaxKind.PlusEqualsToken:returnSyntaxKind.PlusToken;
261+
caseSyntaxKind.MinusEqualsToken:returnSyntaxKind.MinusToken;
262+
caseSyntaxKind.AsteriskEqualsToken:returnSyntaxKind.AsteriskToken;
263+
caseSyntaxKind.AsteriskAsteriskEqualsToken:returnSyntaxKind.AsteriskAsteriskToken;
264+
caseSyntaxKind.SlashEqualsToken:returnSyntaxKind.SlashToken;
265+
caseSyntaxKind.PercentEqualsToken:returnSyntaxKind.PercentToken;
266+
caseSyntaxKind.LessThanLessThanEqualsToken:returnSyntaxKind.LessThanLessThanToken;
267+
caseSyntaxKind.GreaterThanGreaterThanEqualsToken:returnSyntaxKind.GreaterThanGreaterThanToken;
268+
caseSyntaxKind.GreaterThanGreaterThanGreaterThanEqualsToken:returnSyntaxKind.GreaterThanGreaterThanGreaterThanToken;
269+
caseSyntaxKind.AmpersandEqualsToken:returnSyntaxKind.AmpersandToken;
270+
caseSyntaxKind.BarEqualsToken:returnSyntaxKind.BarToken;
271+
caseSyntaxKind.CaretEqualsToken:returnSyntaxKind.CaretToken;
272+
}
273+
}
274+
253275
/**
254276
* Adds super call and preceding prologue directives into the list of statements.
255277
*

‎src/compiler/types.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,11 @@ namespace ts {
951951
initializer?:Expression;// Optional initializer
952952
}
953953

954+
/*@internal*/
955+
exportinterfacePrivateNamedPropertyDeclarationextendsPropertyDeclaration{
956+
name:PrivateName;
957+
}
958+
954959
exportinterfaceObjectLiteralElementextendsNamedDeclaration{
955960
_objectLiteralBrandBrand:any;
956961
name?:PropertyName;
@@ -1775,6 +1780,11 @@ namespace ts {
17751780
name:Identifier|PrivateName;
17761781
}
17771782

1783+
/*@internal*/
1784+
exportinterfacePrivateNamedPropertyAccessExpressionextendsPropertyAccessExpression{
1785+
name:PrivateName;
1786+
}
1787+
17781788
exportinterfaceSuperPropertyAccessExpressionextendsPropertyAccessExpression{
17791789
expression:SuperExpression;
17801790
}

‎src/compiler/utilities.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6341,6 +6341,16 @@ namespace ts {
63416341
||kind===SyntaxKind.ArrayBindingPattern;
63426342
}
63436343

6344+
/*@internal*/
6345+
exportfunctionisPrivateNamedPropertyDeclaration(node:Node):node isPrivateNamedPropertyDeclaration{
6346+
returnisPropertyDeclaration(node)&&isPrivateName(node.name);
6347+
}
6348+
6349+
/*@internal*/
6350+
exportfunctionisPrivateNamedPropertyAccessExpression(node:Node):node isPrivateNamedPropertyAccessExpression{
6351+
returnisPropertyAccessExpression(node)&&isPrivateName(node.name);
6352+
}
6353+
63446354
// Functions
63456355

63466356
exportfunctionisFunctionLike(node:Node):node isSignatureDeclaration{
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//// [privateNameDeclaration.ts]
2+
classA{
3+
#name:string;
4+
}
5+
6+
7+
//// [privateNameDeclaration.js]
8+
var_name;
9+
varA=/**@class */(function(){
10+
functionA(){
11+
_name.set(this,void0);
12+
}
13+
returnA;
14+
}());
15+
_name=newWeakMap();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/conformance/classes/members/privateNames/privateNameDeclaration.ts ===
2+
class A {
3+
>A : Symbol(A, Decl(privateNameDeclaration.ts, 0, 0))
4+
5+
#name: string;
6+
>#name : Symbol(A.#name, Decl(privateNameDeclaration.ts, 0, 9))
7+
}
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
=== tests/cases/conformance/classes/members/privateNames/privateNameDeclaration.ts ===
2+
class A {
3+
>A : A
4+
5+
#name: string;
6+
>#name : string
7+
}
8+

‎tests/baselines/reference/privateNameDuplicateField.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ class A {
88

99

1010
//// [privateNameDuplicateField.js]
11-
"use strict";
1211
//@target es6
12+
var_foo,_foo_1;
13+
"use strict";
1314
varA=/**@class */(function(){
1415
functionA(){
15-
this.#foo="foo";
16-
this.#foo="foo";
16+
_foo_1.set(this,"foo");
17+
_foo_1.set(this,"foo");
1718
}
1819
returnA;
1920
}());
21+
_foo=newWeakMap(),_foo_1=newWeakMap();

‎tests/baselines/reference/privateNameField.js‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ class A {
99
}
1010

1111
//// [privateNameField.js]
12-
"use strict";
1312
//@target es6
13+
var_classPrivateFieldSet=function(receiver,privateMap,value){if(!privateMap.has(receiver)){thrownewTypeError("attempted to set private field on non-instance");}privateMap.set(receiver,value);returnvalue;};
14+
var_name;
15+
"use strict";
1416
varA=/**@class */(function(){
1517
functionA(name){
16-
this.#name=name;
18+
_name.set(this,void0);
19+
_classPrivateFieldSet(this,_name,name);
1720
}
1821
returnA;
1922
}());
23+
_name=newWeakMap();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp