From 033a83d44ae91c8014a846dc5e81920e3bb13748 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 10 Mar 2015 12:12:41 -0700 Subject: [PATCH 01/26] Basic emit for class constructor without static property assignment --- src/compiler/checker.ts | 4 +- src/compiler/emitter.ts | 145 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 142 insertions(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8908501593c..135cecca730 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -9273,7 +9273,9 @@ module ts { var staticType = getTypeOfSymbol(symbol); var baseTypeNode = getClassBaseTypeNode(node); if (baseTypeNode) { - emitExtends = emitExtends || !isInAmbientContext(node); + if (languageVersion < ScriptTarget.ES6) { + emitExtends = emitExtends || !isInAmbientContext(node); + } checkTypeReference(baseTypeNode); } if (type.baseTypes.length) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8947314a6f6..fc5479144eb 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3169,14 +3169,19 @@ module ts { } var superCall = false; if (node.expression.kind === SyntaxKind.SuperKeyword) { - write("_super"); + if (languageVersion < ScriptTarget.ES6) { + write("_super"); + } + else { + write("super"); + } superCall = true; } else { emit(node.expression); superCall = node.expression.kind === SyntaxKind.PropertyAccessExpression && (node.expression).expression.kind === SyntaxKind.SuperKeyword; } - if (superCall) { + if (superCall && languageVersion < ScriptTarget.ES6) { write(".call("); emitThis(node.expression); if (node.arguments.length) { @@ -3185,6 +3190,13 @@ module ts { } write(")"); } + else if (superCall && languageVersion >= ScriptTarget.ES6) { + write("("); + if (node.arguments.length) { + emitCommaList(node.arguments); + } + write(")"); + } else { write("("); emitCommaList(node.arguments); @@ -4502,7 +4514,128 @@ module ts { }); } - function emitClassDeclaration(node: ClassDeclaration) { + function emitConstructorOfClass(node: ClassDeclaration, baseTypeNode: TypeReferenceNode) { + var saveTempCount = tempCount; + var saveTempVariables = tempVariables; + var saveTempParameters = tempParameters; + tempCount = 0; + tempVariables = undefined; + tempParameters = undefined; + + var popFrame = enterNameScope(); + + // Emit the constructor overload pinned comments + forEach(node.members, member => { + if (member.kind === SyntaxKind.Constructor && !(member).body) { + emitPinnedOrTripleSlashComments(member); + } + }); + + var ctor = getFirstConstructorWithBody(node); + if (ctor) { + emitLeadingComments(ctor); + } + emitStart(ctor || node); + + if (languageVersion < ScriptTarget.ES6) { + write("function "); + emitDeclarationName(node); + emitSignatureParameters(ctor); + } + else { + Debug.assert(languageVersion >= ScriptTarget.ES6, "Expected Script Target to be ES6 or above"); + write("constructor"); + if (ctor) { + emitSignatureParameters(ctor); + } + else { + // Based on EcmaScript6 section 14.15.14: Runtime Semantics: ClassDefinitionEvaluation. + // If constructor is empty, then, + // If ClassHeritageopt is present, then + // Let constructor be the result of parsing the String "constructor(... args){ super (...args);}" using the syntactic grammar with the goal symbol MethodDefinition. + // Else, + // Let constructor be the result of parsing the String "constructor( ){ }" using the syntactic grammar with the goal symbol MethodDefinition + if (baseTypeNode) { + write("(...args)"); + } + else { + write("()"); + } + } + } + write(" {"); + scopeEmitStart(node, "constructor"); + increaseIndent(); + if (ctor) { + emitDetachedComments((ctor.body).statements); + } + emitCaptureThisForNodeIfNecessary(node); + if (ctor) { + emitDefaultValueAssignments(ctor); + emitRestParameter(ctor); + if (baseTypeNode) { + var superCall = findInitialSuperCall(ctor); + if (superCall) { + writeLine(); + emit(superCall); + } + } + emitParameterPropertyAssignments(ctor); + } + else { + if (baseTypeNode) { + writeLine(); + emitStart(baseTypeNode); + languageVersion < ScriptTarget.ES6 ? write("_super.apply(this, arguments);") : write("super(...args);"); + emitEnd(baseTypeNode); + } + } + emitMemberAssignments(node, /*nonstatic*/0); + if (ctor) { + var statements: Node[] = (ctor.body).statements; + if (superCall) statements = statements.slice(1); + emitLines(statements); + } + emitTempDeclarations(/*newLine*/ true); + writeLine(); + if (ctor) { + emitLeadingCommentsOfPosition((ctor.body).statements.end); + } + decreaseIndent(); + emitToken(SyntaxKind.CloseBraceToken, ctor ? (ctor.body).statements.end : node.members.end); + scopeEmitEnd(); + emitEnd(ctor || node); + if (ctor) { + emitTrailingComments(ctor); + } + + exitNameScope(popFrame); + + tempCount = saveTempCount; + tempVariables = saveTempVariables; + tempParameters = saveTempParameters; + } + + function emitClassDeclarationAboveES6(node: ClassDeclaration) { + write("class "); + emitDeclarationName(node); + var baseTypeNode = getClassBaseTypeNode(node); + if (baseTypeNode) { + write(" extends "); + emitDeclarationName(node); + } + write(" {"); + increaseIndent(); + scopeEmitStart(node); + writeLine(); + emitConstructorOfClass(node, baseTypeNode); + writeLine(); + scopeEmitEnd(); + decreaseIndent(); + write("}"); + } + + function emitClassDeclarationBelowES6(node: ClassDeclaration) { write("var "); emitDeclarationName(node); write(" = (function ("); @@ -4522,7 +4655,7 @@ module ts { emitEnd(baseTypeNode); } writeLine(); - emitConstructorOfClass(); + emitConstructorOfClass(node, baseTypeNode); emitMemberFunctions(node); emitMemberAssignments(node, NodeFlags.Static); writeLine(); @@ -4555,7 +4688,7 @@ module ts { emitExportMemberAssignments(node.name); } - function emitConstructorOfClass() { + function emitConstructorOfClassOLD() { var saveTempCount = tempCount; var saveTempVariables = tempVariables; var saveTempParameters = tempParameters; @@ -5352,7 +5485,7 @@ module ts { case SyntaxKind.VariableDeclaration: return emitVariableDeclaration(node); case SyntaxKind.ClassDeclaration: - return emitClassDeclaration(node); + return languageVersion < ScriptTarget.ES6 ? emitClassDeclarationBelowES6(node) : emitClassDeclarationAboveES6(node); case SyntaxKind.InterfaceDeclaration: return emitInterfaceDeclaration(node); case SyntaxKind.EnumDeclaration: From d3205ef9551ccc015a48bb37d3d4d4dfc457cb1c Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 10 Mar 2015 15:21:38 -0700 Subject: [PATCH 02/26] Remove redundant sourcemap span and comment. Differentiate between emit for below ES6 and above ES6 --- src/compiler/emitter.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index fc5479144eb..15b51ea2068 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4436,7 +4436,7 @@ module ts { }); } - function emitMemberFunctions(node: ClassDeclaration) { + function emitMemberFunctionsBelowES6(node: ClassDeclaration) { forEach(node.members, member => { if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { @@ -4446,19 +4446,14 @@ module ts { writeLine(); emitLeadingComments(member); emitStart(member); - emitStart((member).name); emitDeclarationName(node); if (!(member.flags & NodeFlags.Static)) { write(".prototype"); } emitMemberAccessForPropertyName((member).name); - emitEnd((member).name); write(" = "); - // TODO (drosen): Should we performing emitStart twice on emitStart(member)? - emitStart(member); emitFunctionDeclaration(member); emitEnd(member); - emitEnd(member); write(";"); emitTrailingComments(member); } @@ -4656,7 +4651,7 @@ module ts { } writeLine(); emitConstructorOfClass(node, baseTypeNode); - emitMemberFunctions(node); + emitMemberFunctionsBelowES6(node); emitMemberAssignments(node, NodeFlags.Static); writeLine(); emitToken(SyntaxKind.CloseBraceToken, node.members.end, () => { From 8576282975d2124139d618ec515276bfd157be1a Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 10 Mar 2015 15:41:41 -0700 Subject: [PATCH 03/26] Emit non-getter/setter member function --- src/compiler/emitter.ts | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 15b51ea2068..8047d911ca7 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4407,7 +4407,9 @@ module ts { emitComputedPropertyName(memberName); } else { - write("."); + if (languageVersion < ScriptTarget.ES6) { + write("."); + } emitNodeWithoutSourceMap(memberName); } } @@ -4509,6 +4511,27 @@ module ts { }); } + function emitMemberFunctionsAboveES6(node: ClassDeclaration) { + forEach(node.members, member => { + if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { + if (!(member).body) { + return emitPinnedOrTripleSlashComments(member); + } + + writeLine(); + emitLeadingComments(member); + emitStart(member); + if (member.flags & NodeFlags.Static) { + write("static "); + } + emitMemberAccessForPropertyName((member).name); + emitSignatureAndBody(member); + emitEnd(member); + emitTrailingComments(member); + } + }); + } + function emitConstructorOfClass(node: ClassDeclaration, baseTypeNode: TypeReferenceNode) { var saveTempCount = tempCount; var saveTempVariables = tempVariables; @@ -4624,6 +4647,7 @@ module ts { scopeEmitStart(node); writeLine(); emitConstructorOfClass(node, baseTypeNode); + emitMemberFunctionsAboveES6(node); writeLine(); scopeEmitEnd(); decreaseIndent(); From 1b84f1d1d09f57cde9d02c49f8b07b7cb05c8a83 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 10 Mar 2015 17:22:33 -0700 Subject: [PATCH 04/26] emit get/set member function --- src/compiler/emitter.ts | 35 +++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8047d911ca7..db1cdee432c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4465,15 +4465,12 @@ module ts { writeLine(); emitStart(member); write("Object.defineProperty("); - emitStart((member).name); emitDeclarationName(node); if (!(member.flags & NodeFlags.Static)) { write(".prototype"); } write(", "); - // TODO: Shouldn't emitStart on name occur *here*? emitExpressionForPropertyName((member).name); - emitEnd((member).name); write(", {"); increaseIndent(); if (accessors.getAccessor) { @@ -4529,6 +4526,36 @@ module ts { emitEnd(member); emitTrailingComments(member); } + else if (member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { + var accessors = getAllAccessorDeclarations(node.members, member); + if (member === accessors.firstAccessor) { + writeLine(); + if (accessors.getAccessor) { + emitLeadingComments(accessors.getAccessor); + emitStart(accessors.getAccessor); + if (member.flags & NodeFlags.Static) { + write("static "); + } + write("get "); + emitMemberAccessForPropertyName((member).name); + emitSignatureAndBody(accessors.getAccessor); + emitEnd(accessors.getAccessor); + emitTrailingComments(accessors.getAccessor); + } + else if (accessors.setAccessor) { + emitLeadingComments(accessors.setAccessor); + emitStart(accessors.setAccessor); + if (member.flags & NodeFlags.Static) { + write("static "); + } + write("set "); + emitMemberAccessForPropertyName((member).name); + emitSignatureAndBody(accessors.setAccessor); + emitEnd(accessors.setAccessor); + emitTrailingComments(accessors.setAccessor);; + } + } + } }); } @@ -4567,7 +4594,7 @@ module ts { emitSignatureParameters(ctor); } else { - // Based on EcmaScript6 section 14.15.14: Runtime Semantics: ClassDefinitionEvaluation. + // Based on EcmaScript6 section 14.5.14: Runtime Semantics: ClassDefinitionEvaluation. // If constructor is empty, then, // If ClassHeritageopt is present, then // Let constructor be the result of parsing the String "constructor(... args){ super (...args);}" using the syntactic grammar with the goal symbol MethodDefinition. From 890aa4a84de28621503b6a620b0b02b17878a3f8 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 10 Mar 2015 17:39:13 -0700 Subject: [PATCH 05/26] test cases for constructor overload, non-static property assignment, getter/setter, method, static method, --- ...DeclarationWithConstructorOverloadInES6.js | 21 +++++++ ...larationWithConstructorOverloadInES6.types | 22 ++++++++ ...nWithConstructorPropertyAssignmentInES6.js | 51 +++++++++++++++++ ...thConstructorPropertyAssignmentInES6.types | 56 +++++++++++++++++++ ...itClassDeclarationWithGetterSetterInES6.js | 38 +++++++++++++ ...lassDeclarationWithGetterSetterInES6.types | 35 ++++++++++++ .../emitClassDeclarationWithMethodInES6.js | 34 +++++++++++ .../emitClassDeclarationWithMethodInES6.types | 27 +++++++++ ...itClassDeclarationWithStaticMethodInES6.js | 37 ++++++++++++ ...lassDeclarationWithStaticMethodInES6.types | 32 +++++++++++ ...DeclarationWithConstructorOverloadInES6.ts | 11 ++++ ...nWithConstructorPropertyAssignmentInES6.ts | 25 +++++++++ ...itClassDeclarationWithGetterSetterInES6.ts | 17 ++++++ .../emitClassDeclarationWithMethodInES6.ts | 13 +++++ ...itClassDeclarationWithStaticMethodInES6.ts | 13 +++++ 15 files changed, 432 insertions(+) create mode 100644 tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithMethodInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithMethodInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.js b/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.js new file mode 100644 index 00000000000..b7fe4f0cda7 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.js @@ -0,0 +1,21 @@ +//// [emitClassDeclarationWithConstructorOverloadInES6.ts] +class C { + constructor(y: any) + constructor(x: number) { + } +} + +class D { + constructor(y: any) + constructor(x: number, z="hello") {} +} + +//// [emitClassDeclarationWithConstructorOverloadInES6.js] +class C { + constructor(x) { + } +} +class D { + constructor(x, z = "hello") { + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.types b/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.types new file mode 100644 index 00000000000..96e9f25549e --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts === +class C { +>C : C + + constructor(y: any) +>y : any + + constructor(x: number) { +>x : number + } +} + +class D { +>D : D + + constructor(y: any) +>y : any + + constructor(x: number, z="hello") {} +>x : number +>z : string +} diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js b/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js new file mode 100644 index 00000000000..4f57c6345cf --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js @@ -0,0 +1,51 @@ +//// [emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts] +class C { + x: string = "Hello world"; +} + +class D { + x: string = "Hello world"; + y: number; + constructor() { + this.y = 10; + } +} + +class E extends D{ + z: boolean = true; +} + +class F extends D{ + z: boolean = true; + j: string; + constructor() { + super(); + this.j = "HI"; + } +} + +//// [emitClassDeclarationWithConstructorPropertyAssignmentInES6.js] +class C { + constructor() { + thisx = "Hello world"; + } +} +class D { + constructor() { + thisx = "Hello world"; + this.y = 10; + } +} +class E extends E { + constructor(...args) { + super(...args); + thisz = true; + } +} +class F extends F { + constructor() { + super(); + thisz = true; + this.j = "HI"; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.types b/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.types new file mode 100644 index 00000000000..c121f936dbb --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.types @@ -0,0 +1,56 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts === +class C { +>C : C + + x: string = "Hello world"; +>x : string +} + +class D { +>D : D + + x: string = "Hello world"; +>x : string + + y: number; +>y : number + + constructor() { + this.y = 10; +>this.y = 10 : number +>this.y : number +>this : D +>y : number + } +} + +class E extends D{ +>E : E +>D : D + + z: boolean = true; +>z : boolean +} + +class F extends D{ +>F : F +>D : D + + z: boolean = true; +>z : boolean + + j: string; +>j : string + + constructor() { + super(); +>super() : void +>super : typeof D + + this.j = "HI"; +>this.j = "HI" : string +>this.j : string +>this : F +>j : string + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js new file mode 100644 index 00000000000..5d4a4fff6d6 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js @@ -0,0 +1,38 @@ +//// [emitClassDeclarationWithGetterSetterInES6.ts] +class C { + _name: string; + get name(): string { + return this._name; + } + static get name2(): string { + return "BYE"; + } + static get ["computedname"]() { + return ""; + } + + set foo(a: string) { } + static set bar(b: number) { } + static set ["computedname"](b: string) { } +} + +//// [emitClassDeclarationWithGetterSetterInES6.js] +class C { + constructor() { + } + get name() { + return this._name; + } + static get name2() { + return "BYE"; + } + static get ["computedname"]() { + return ""; + } + set foo(a) { + } + static set bar(b) { + } + static set ["computedname"](b) { + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types new file mode 100644 index 00000000000..4e4673a228f --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types @@ -0,0 +1,35 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts === +class C { +>C : C + + _name: string; +>_name : string + + get name(): string { +>name : string + + return this._name; +>this._name : string +>this : C +>_name : string + } + static get name2(): string { +>name2 : string + + return "BYE"; + } + static get ["computedname"]() { + return ""; + } + + set foo(a: string) { } +>foo : string +>a : string + + static set bar(b: number) { } +>bar : number +>b : number + + static set ["computedname"](b: string) { } +>b : string +} diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js new file mode 100644 index 00000000000..c443c0f0cfa --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js @@ -0,0 +1,34 @@ +//// [emitClassDeclarationWithMethodInES6.ts] +class D { + foo() { } + ["computedName"]() { } + ["computedName"](a: string) { } + ["computedName"](a: string): number { return 1; } + bar(): string { + return "HI"; + } + baz(a: any, x: string): string { + return "HELLO"; + } +} + +//// [emitClassDeclarationWithMethodInES6.js] +class D { + constructor() { + } + foo() { + } + ["computedName"]() { + } + ["computedName"](a) { + } + ["computedName"](a) { + return 1; + } + bar() { + return "HI"; + } + baz(a, x) { + return "HELLO"; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types new file mode 100644 index 00000000000..38031711378 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types @@ -0,0 +1,27 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts === +class D { +>D : D + + foo() { } +>foo : () => void + + ["computedName"]() { } + ["computedName"](a: string) { } +>a : string + + ["computedName"](a: string): number { return 1; } +>a : string + + bar(): string { +>bar : () => string + + return "HI"; + } + baz(a: any, x: string): string { +>baz : (a: any, x: string) => string +>a : any +>x : string + + return "HELLO"; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js b/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js new file mode 100644 index 00000000000..b0809ab57b8 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js @@ -0,0 +1,37 @@ +//// [emitClassDeclarationWithStaticMethodInES6.ts] +class E { + normalMethod() { } + static ["computedname"]() { } + static ["computedname"](a:string) { } + static ["computedname"](a: string): boolean { return true; } + static staticMethod() { + var x = 1 + 2; + return x + } + static foo(a: string) { } + static bar(a: string): number { return 1; } +} + +//// [emitClassDeclarationWithStaticMethodInES6.js] +class E { + constructor() { + } + normalMethod() { + } + static ["computedname"]() { + } + static ["computedname"](a) { + } + static ["computedname"](a) { + return true; + } + static staticMethod() { + var x = 1 + 2; + return x; + } + static foo(a) { + } + static bar(a) { + return 1; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types b/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types new file mode 100644 index 00000000000..63bec899622 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts === +class E { +>E : E + + normalMethod() { } +>normalMethod : () => void + + static ["computedname"]() { } + static ["computedname"](a:string) { } +>a : string + + static ["computedname"](a: string): boolean { return true; } +>a : string + + static staticMethod() { +>staticMethod : () => number + + var x = 1 + 2; +>x : number +>1 + 2 : number + + return x +>x : number + } + static foo(a: string) { } +>foo : (a: string) => void +>a : string + + static bar(a: string): number { return 1; } +>bar : (a: string) => number +>a : string +} diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts new file mode 100644 index 00000000000..776d0b45847 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts @@ -0,0 +1,11 @@ +// @target: es6 +class C { + constructor(y: any) + constructor(x: number) { + } +} + +class D { + constructor(y: any) + constructor(x: number, z="hello") {} +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts new file mode 100644 index 00000000000..dd97cfc85f3 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts @@ -0,0 +1,25 @@ +// @target:es6 +class C { + x: string = "Hello world"; +} + +class D { + x: string = "Hello world"; + y: number; + constructor() { + this.y = 10; + } +} + +class E extends D{ + z: boolean = true; +} + +class F extends D{ + z: boolean = true; + j: string; + constructor() { + super(); + this.j = "HI"; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts new file mode 100644 index 00000000000..18ff3fa424d --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts @@ -0,0 +1,17 @@ +// @target:es6 +class C { + _name: string; + get name(): string { + return this._name; + } + static get name2(): string { + return "BYE"; + } + static get ["computedname"]() { + return ""; + } + + set foo(a: string) { } + static set bar(b: number) { } + static set ["computedname"](b: string) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts new file mode 100644 index 00000000000..458a4bd3328 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts @@ -0,0 +1,13 @@ +// @target:es6 +class D { + foo() { } + ["computedName"]() { } + ["computedName"](a: string) { } + ["computedName"](a: string): number { return 1; } + bar(): string { + return "HI"; + } + baz(a: any, x: string): string { + return "HELLO"; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts new file mode 100644 index 00000000000..7a040649d74 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts @@ -0,0 +1,13 @@ +// @target:es6 +class E { + normalMethod() { } + static ["computedname"]() { } + static ["computedname"](a:string) { } + static ["computedname"](a: string): boolean { return true; } + static staticMethod() { + var x = 1 + 2; + return x + } + static foo(a: string) { } + static bar(a: string): number { return 1; } +} \ No newline at end of file From da12d465d0bcfcc7c26931e3b7f6f20c45275f6b Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 10 Mar 2015 19:11:07 -0700 Subject: [PATCH 06/26] Add tests for extension, type arguments, overload --- src/compiler/emitter.ts | 6 +- ...mitClassDeclarationWithConstructorInES6.js | 26 +++++++ ...ClassDeclarationWithConstructorInES6.types | 32 ++++++++ ...nWithConstructorPropertyAssignmentInES6.js | 12 +-- ...rationWithExtensionAndTypeArgumentInES6.js | 27 +++++++ ...ionWithExtensionAndTypeArgumentInES6.types | 29 +++++++ .../emitClassDeclarationWithExtensionInES6.js | 25 +++++++ ...itClassDeclarationWithExtensionInES6.types | 19 +++++ .../emitClassDeclarationWithMethodInES6.js | 30 +++++++- .../emitClassDeclarationWithMethodInES6.types | 32 +++++++- ...ClassDeclarationWithMethodOverloadInES6.js | 22 ++++++ ...ssDeclarationWithMethodOverloadInES6.types | 29 +++++++ ...DeclarationWithRestAndDefaultArguements.js | 20 +++++ ...larationWithRestAndDefaultArguements.types | 25 +++++++ ...itClassDeclarationWithStaticMethodInES6.js | 37 --------- ...lassDeclarationWithStaticMethodInES6.types | 32 -------- ...sDeclarationWithTypeArgumentAndOverload.js | 39 ++++++++++ ...clarationWithTypeArgumentAndOverload.types | 75 +++++++++++++++++++ ...itClassDeclarationWithTypeArgumentInES6.js | 31 ++++++++ ...lassDeclarationWithTypeArgumentInES6.types | 53 +++++++++++++ ...mitClassDeclarationWithConstructorInES6.ts | 14 ++++ ...rationWithExtensionAndTypeArgumentInES6.ts | 11 +++ .../emitClassDeclarationWithExtensionInES6.ts | 8 ++ .../emitClassDeclarationWithMethodInES6.ts | 12 ++- ...ClassDeclarationWithMethodOverloadInES6.ts | 11 +++ ...DeclarationWithRestAndDefaultArguements.ts | 8 ++ ...itClassDeclarationWithStaticMethodInES6.ts | 13 ---- ...sDeclarationWithTypeArgumentAndOverload.ts | 23 ++++++ ...itClassDeclarationWithTypeArgumentInES6.ts | 15 ++++ 29 files changed, 622 insertions(+), 94 deletions(-) create mode 100644 tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types delete mode 100644 tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js delete mode 100644 tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.types create mode 100644 tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.types create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts delete mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentInES6.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index db1cdee432c..fa3854f1592 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4407,7 +4407,9 @@ module ts { emitComputedPropertyName(memberName); } else { - if (languageVersion < ScriptTarget.ES6) { + // For script-target that is ES6 or above, we want to emit memberName by itself without prefix "." if the memberName is a name of method. + // If the memberName is the name of property, we need to emit it with prefix ".". + if (languageVersion < ScriptTarget.ES6 || memberName.parent.kind === SyntaxKind.PropertyDeclaration) { write("."); } emitNodeWithoutSourceMap(memberName); @@ -4667,7 +4669,7 @@ module ts { var baseTypeNode = getClassBaseTypeNode(node); if (baseTypeNode) { write(" extends "); - emitDeclarationName(node); + emitNodeWithoutSourceMap(baseTypeNode.typeName); } write(" {"); increaseIndent(); diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js new file mode 100644 index 00000000000..7877c957b29 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js @@ -0,0 +1,26 @@ +//// [emitClassDeclarationWithConstructorInES6.ts] +class C { + y: number; + constructor(x: number) { + } +} + +class D { + y: number; + x: string = "hello"; + constructor(x: number, z = "hello") { + this.y = 10; + } +} + +//// [emitClassDeclarationWithConstructorInES6.js] +class C { + constructor(x) { + } +} +class D { + constructor(x, z = "hello") { + this.x = "hello"; + this.y = 10; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types new file mode 100644 index 00000000000..359e58a4b32 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types @@ -0,0 +1,32 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts === +class C { +>C : C + + y: number; +>y : number + + constructor(x: number) { +>x : number + } +} + +class D { +>D : D + + y: number; +>y : number + + x: string = "hello"; +>x : string + + constructor(x: number, z = "hello") { +>x : number +>z : string + + this.y = 10; +>this.y = 10 : number +>this.y : number +>this : D +>y : number + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js b/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js index 4f57c6345cf..8f65c8f9fdb 100644 --- a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js @@ -27,25 +27,25 @@ class F extends D{ //// [emitClassDeclarationWithConstructorPropertyAssignmentInES6.js] class C { constructor() { - thisx = "Hello world"; + this.x = "Hello world"; } } class D { constructor() { - thisx = "Hello world"; + this.x = "Hello world"; this.y = 10; } } -class E extends E { +class E extends D { constructor(...args) { super(...args); - thisz = true; + this.z = true; } } -class F extends F { +class F extends D { constructor() { super(); - thisz = true; + this.z = true; this.j = "HI"; } } diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js new file mode 100644 index 00000000000..2409ebc0b66 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js @@ -0,0 +1,27 @@ +//// [emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts] +class B { + constructor(a: T) { } +} +class C extends B { } +class D extends B { + constructor(a: any) + constructor(b: number) { + super(b); + } +} + +//// [emitClassDeclarationWithExtensionAndTypeArgumentInES6.js] +class B { + constructor(a) { + } +} +class C extends B { + constructor(...args) { + super(...args); + } +} +class D extends B { + constructor(b) { + super(b); + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.types b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.types new file mode 100644 index 00000000000..0f546fa7b86 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts === +class B { +>B : B +>T : T + + constructor(a: T) { } +>a : T +>T : T +} +class C extends B { } +>C : C +>B : B + +class D extends B { +>D : D +>B : B + + constructor(a: any) +>a : any + + constructor(b: number) { +>b : number + + super(b); +>super(b) : void +>super : typeof B +>b : number + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js new file mode 100644 index 00000000000..389d18d37a3 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js @@ -0,0 +1,25 @@ +//// [emitClassDeclarationWithExtensionInES6.ts] +class B { } +class C extends B { } +class D extends B { + constructor() { + super(); + } +} + + +//// [emitClassDeclarationWithExtensionInES6.js] +class B { + constructor() { + } +} +class C extends B { + constructor(...args) { + super(...args); + } +} +class D extends B { + constructor() { + super(); + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types new file mode 100644 index 00000000000..f410340b509 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts === +class B { } +>B : B + +class C extends B { } +>C : C +>B : B + +class D extends B { +>D : D +>B : B + + constructor() { + super(); +>super() : void +>super : typeof B + } +} + diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js index c443c0f0cfa..fd8a3079f8b 100644 --- a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js @@ -1,15 +1,25 @@ //// [emitClassDeclarationWithMethodInES6.ts] class D { + _bar: string; foo() { } ["computedName"]() { } ["computedName"](a: string) { } ["computedName"](a: string): number { return 1; } bar(): string { - return "HI"; + return this._bar; } baz(a: any, x: string): string { return "HELLO"; } + static ["computedname"]() { } + static ["computedname"](a: string) { } + static ["computedname"](a: string): boolean { return true; } + static staticMethod() { + var x = 1 + 2; + return x + } + static foo(a: string) { } + static bar(a: string): number { return 1; } } //// [emitClassDeclarationWithMethodInES6.js] @@ -26,9 +36,25 @@ class D { return 1; } bar() { - return "HI"; + return this._bar; } baz(a, x) { return "HELLO"; } + static ["computedname"]() { + } + static ["computedname"](a) { + } + static ["computedname"](a) { + return true; + } + static staticMethod() { + var x = 1 + 2; + return x; + } + static foo(a) { + } + static bar(a) { + return 1; + } } diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types index 38031711378..f26a9f87e6d 100644 --- a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types +++ b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.types @@ -2,6 +2,9 @@ class D { >D : D + _bar: string; +>_bar : string + foo() { } >foo : () => void @@ -15,7 +18,10 @@ class D { bar(): string { >bar : () => string - return "HI"; + return this._bar; +>this._bar : string +>this : D +>_bar : string } baz(a: any, x: string): string { >baz : (a: any, x: string) => string @@ -24,4 +30,28 @@ class D { return "HELLO"; } + static ["computedname"]() { } + static ["computedname"](a: string) { } +>a : string + + static ["computedname"](a: string): boolean { return true; } +>a : string + + static staticMethod() { +>staticMethod : () => number + + var x = 1 + 2; +>x : number +>1 + 2 : number + + return x +>x : number + } + static foo(a: string) { } +>foo : (a: string) => void +>a : string + + static bar(a: string): number { return 1; } +>bar : (a: string) => number +>a : string } diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js b/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js new file mode 100644 index 00000000000..252a44122eb --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js @@ -0,0 +1,22 @@ +//// [emitClassDeclarationWithMethodOverloadInES6.ts] +class D { + _bar: string; + foo(a: any); + foo() { } + + baz(...args): string; + baz(z:string, v: number): string { + return this._bar; + } +} + +//// [emitClassDeclarationWithMethodOverloadInES6.js] +class D { + constructor() { + } + foo() { + } + baz(z, v) { + return this._bar; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types b/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types new file mode 100644 index 00000000000..3017908e576 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts === +class D { +>D : D + + _bar: string; +>_bar : string + + foo(a: any); +>foo : (a: any) => any +>a : any + + foo() { } +>foo : (a: any) => any + + baz(...args): string; +>baz : (...args: any[]) => string +>args : any[] + + baz(z:string, v: number): string { +>baz : (...args: any[]) => string +>z : string +>v : number + + return this._bar; +>this._bar : string +>this : D +>_bar : string + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js b/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js new file mode 100644 index 00000000000..179818387da --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js @@ -0,0 +1,20 @@ +//// [emitClassDeclarationWithRestAndDefaultArguements.ts] +class B { + constructor(y = 10, ...p) { } + foo(a = "hi") { } + bar(b = 10, ...p) { } + far(...p) + far(a: any) { } +} + +//// [emitClassDeclarationWithRestAndDefaultArguements.js] +class B { + constructor(y = 10, ...p) { + } + foo(a = "hi") { + } + bar(b = 10, ...p) { + } + far(a) { + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types b/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types new file mode 100644 index 00000000000..6f59f8220ad --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts === +class B { +>B : B + + constructor(y = 10, ...p) { } +>y : number +>p : any[] + + foo(a = "hi") { } +>foo : (a?: string) => void +>a : string + + bar(b = 10, ...p) { } +>bar : (b?: number, ...p: any[]) => void +>b : number +>p : any[] + + far(...p) +>far : (...p: any[]) => any +>p : any[] + + far(a: any) { } +>far : (...p: any[]) => any +>a : any +} diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js b/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js deleted file mode 100644 index b0809ab57b8..00000000000 --- a/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.js +++ /dev/null @@ -1,37 +0,0 @@ -//// [emitClassDeclarationWithStaticMethodInES6.ts] -class E { - normalMethod() { } - static ["computedname"]() { } - static ["computedname"](a:string) { } - static ["computedname"](a: string): boolean { return true; } - static staticMethod() { - var x = 1 + 2; - return x - } - static foo(a: string) { } - static bar(a: string): number { return 1; } -} - -//// [emitClassDeclarationWithStaticMethodInES6.js] -class E { - constructor() { - } - normalMethod() { - } - static ["computedname"]() { - } - static ["computedname"](a) { - } - static ["computedname"](a) { - return true; - } - static staticMethod() { - var x = 1 + 2; - return x; - } - static foo(a) { - } - static bar(a) { - return 1; - } -} diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types b/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types deleted file mode 100644 index 63bec899622..00000000000 --- a/tests/baselines/reference/emitClassDeclarationWithStaticMethodInES6.types +++ /dev/null @@ -1,32 +0,0 @@ -=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts === -class E { ->E : E - - normalMethod() { } ->normalMethod : () => void - - static ["computedname"]() { } - static ["computedname"](a:string) { } ->a : string - - static ["computedname"](a: string): boolean { return true; } ->a : string - - static staticMethod() { ->staticMethod : () => number - - var x = 1 + 2; ->x : number ->1 + 2 : number - - return x ->x : number - } - static foo(a: string) { } ->foo : (a: string) => void ->a : string - - static bar(a: string): number { return 1; } ->bar : (a: string) => number ->a : string -} diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.js b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.js new file mode 100644 index 00000000000..69801d6be12 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.js @@ -0,0 +1,39 @@ +//// [emitClassDeclarationWithTypeArgumentAndOverload.ts] +class B { + x: T; + B: T; + + constructor(a: any) + constructor(a: any,b: T) + constructor(a: T) { this.B = a;} + + foo(a: T) + foo(a: any) + foo(b: string) + foo(): T { + return this.x; + } + + get BB(): T { + return this.B; + } + set BBWith(c: T) { + this.B = c; + } +} + +//// [emitClassDeclarationWithTypeArgumentAndOverload.js] +class B { + constructor(a) { + this.B = a; + } + foo() { + return this.x; + } + get BB() { + return this.B; + } + set BBWith(c) { + this.B = c; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.types b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.types new file mode 100644 index 00000000000..8b0feb72d2b --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.types @@ -0,0 +1,75 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts === +class B { +>B : B +>T : T + + x: T; +>x : T +>T : T + + B: T; +>B : T +>T : T + + constructor(a: any) +>a : any + + constructor(a: any,b: T) +>a : any +>b : T +>T : T + + constructor(a: T) { this.B = a;} +>a : T +>T : T +>this.B = a : T +>this.B : T +>this : B +>B : T +>a : T + + foo(a: T) +>foo : { (a: T): any; (a: any): any; (b: string): any; } +>a : T +>T : T + + foo(a: any) +>foo : { (a: T): any; (a: any): any; (b: string): any; } +>a : any + + foo(b: string) +>foo : { (a: T): any; (a: any): any; (b: string): any; } +>b : string + + foo(): T { +>foo : { (a: T): any; (a: any): any; (b: string): any; } +>T : T + + return this.x; +>this.x : T +>this : B +>x : T + } + + get BB(): T { +>BB : T +>T : T + + return this.B; +>this.B : T +>this : B +>B : T + } + set BBWith(c: T) { +>BBWith : T +>c : T +>T : T + + this.B = c; +>this.B = c : T +>this.B : T +>this : B +>B : T +>c : T + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.js b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.js new file mode 100644 index 00000000000..4e2872b4f06 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.js @@ -0,0 +1,31 @@ +//// [emitClassDeclarationWithTypeArgumentInES6.ts] +class B { + x: T; + B: T; + constructor(a: T) { this.B = a;} + foo(): T { + return this.x; + } + get BB(): T { + return this.B; + } + set BBWith(c: T) { + this.B = c; + } +} + +//// [emitClassDeclarationWithTypeArgumentInES6.js] +class B { + constructor(a) { + this.B = a; + } + foo() { + return this.x; + } + get BB() { + return this.B; + } + set BBWith(c) { + this.B = c; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.types b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.types new file mode 100644 index 00000000000..8081d044e35 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentInES6.types @@ -0,0 +1,53 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentInES6.ts === +class B { +>B : B +>T : T + + x: T; +>x : T +>T : T + + B: T; +>B : T +>T : T + + constructor(a: T) { this.B = a;} +>a : T +>T : T +>this.B = a : T +>this.B : T +>this : B +>B : T +>a : T + + foo(): T { +>foo : () => T +>T : T + + return this.x; +>this.x : T +>this : B +>x : T + } + get BB(): T { +>BB : T +>T : T + + return this.B; +>this.B : T +>this : B +>B : T + } + set BBWith(c: T) { +>BBWith : T +>c : T +>T : T + + this.B = c; +>this.B = c : T +>this.B : T +>this : B +>B : T +>c : T + } +} diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts new file mode 100644 index 00000000000..9e06636da7e --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts @@ -0,0 +1,14 @@ +// @target: es6 +class C { + y: number; + constructor(x: number) { + } +} + +class D { + y: number; + x: string = "hello"; + constructor(x: number, z = "hello") { + this.y = 10; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts new file mode 100644 index 00000000000..c27723e3391 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionAndTypeArgumentInES6.ts @@ -0,0 +1,11 @@ +// @target: es6 +class B { + constructor(a: T) { } +} +class C extends B { } +class D extends B { + constructor(a: any) + constructor(b: number) { + super(b); + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts new file mode 100644 index 00000000000..519af626850 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts @@ -0,0 +1,8 @@ +// @target: es6 +class B { } +class C extends B { } +class D extends B { + constructor() { + super(); + } +} diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts index 458a4bd3328..c5d95bc6cb1 100644 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodInES6.ts @@ -1,13 +1,23 @@ // @target:es6 class D { + _bar: string; foo() { } ["computedName"]() { } ["computedName"](a: string) { } ["computedName"](a: string): number { return 1; } bar(): string { - return "HI"; + return this._bar; } baz(a: any, x: string): string { return "HELLO"; } + static ["computedname"]() { } + static ["computedname"](a: string) { } + static ["computedname"](a: string): boolean { return true; } + static staticMethod() { + var x = 1 + 2; + return x + } + static foo(a: string) { } + static bar(a: string): number { return 1; } } \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts new file mode 100644 index 00000000000..e1b277fae51 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts @@ -0,0 +1,11 @@ +// @target:es6 +class D { + _bar: string; + foo(a: any); + foo() { } + + baz(...args): string; + baz(z:string, v: number): string { + return this._bar; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts new file mode 100644 index 00000000000..20c251b2cfa --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts @@ -0,0 +1,8 @@ +// @target: es6 +class B { + constructor(y = 10, ...p) { } + foo(a = "hi") { } + bar(b = 10, ...p) { } + far(...p) + far(a: any) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts deleted file mode 100644 index 7a040649d74..00000000000 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticMethodInES6.ts +++ /dev/null @@ -1,13 +0,0 @@ -// @target:es6 -class E { - normalMethod() { } - static ["computedname"]() { } - static ["computedname"](a:string) { } - static ["computedname"](a: string): boolean { return true; } - static staticMethod() { - var x = 1 + 2; - return x - } - static foo(a: string) { } - static bar(a: string): number { return 1; } -} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts new file mode 100644 index 00000000000..945b2101012 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts @@ -0,0 +1,23 @@ +// @target: es6 +class B { + x: T; + B: T; + + constructor(a: any) + constructor(a: any,b: T) + constructor(a: T) { this.B = a;} + + foo(a: T) + foo(a: any) + foo(b: string) + foo(): T { + return this.x; + } + + get BB(): T { + return this.B; + } + set BBWith(c: T) { + this.B = c; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentInES6.ts new file mode 100644 index 00000000000..078356f6f15 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentInES6.ts @@ -0,0 +1,15 @@ +// @target: es6 +class B { + x: T; + B: T; + constructor(a: T) { this.B = a;} + foo(): T { + return this.x; + } + get BB(): T { + return this.B; + } + set BBWith(c: T) { + this.B = c; + } +} \ No newline at end of file From a0a506b11b226a0762e03c1b42bb6388f202313b Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 11 Mar 2015 16:13:08 -0700 Subject: [PATCH 07/26] Emit class declaration with static property assignment --- src/compiler/emitter.ts | 13 ++++++++--- ...DeclarationWithPropertyAssignmentInES6.js} | 4 ++-- ...larationWithPropertyAssignmentInES6.types} | 2 +- ...rationWithStaticPropertyAssignmentInES6.js | 23 +++++++++++++++++++ ...ionWithStaticPropertyAssignmentInES6.types | 18 +++++++++++++++ ...DeclarationWithPropertyAssignmentInES6.ts} | 0 ...rationWithStaticPropertyAssignmentInES6.ts | 9 ++++++++ 7 files changed, 63 insertions(+), 6 deletions(-) rename tests/baselines/reference/{emitClassDeclarationWithConstructorPropertyAssignmentInES6.js => emitClassDeclarationWithPropertyAssignmentInES6.js} (80%) rename tests/baselines/reference/{emitClassDeclarationWithConstructorPropertyAssignmentInES6.types => emitClassDeclarationWithPropertyAssignmentInES6.types} (86%) create mode 100644 tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.types rename tests/cases/conformance/es6/classDeclaration/{emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts => emitClassDeclarationWithPropertyAssignmentInES6.ts} (100%) create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticPropertyAssignmentInES6.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index fa3854f1592..d4434c9bf4b 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4677,10 +4677,17 @@ module ts { writeLine(); emitConstructorOfClass(node, baseTypeNode); emitMemberFunctionsAboveES6(node); - writeLine(); - scopeEmitEnd(); decreaseIndent(); - write("}"); + writeLine(); + emitToken(SyntaxKind.CloseBraceToken, node.members.end); + scopeEmitEnd(); + + // Emit static property assignment. Because classDeclaration is lexically evaluated, it is safe to emit static property assignment after classDeclaration + // From ES6 specification: + // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using + // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. + writeLine(); + emitMemberAssignments(node, NodeFlags.Static); } function emitClassDeclarationBelowES6(node: ClassDeclaration) { diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js b/tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.js similarity index 80% rename from tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js rename to tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.js index 8f65c8f9fdb..03fb45b806e 100644 --- a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.js @@ -1,4 +1,4 @@ -//// [emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts] +//// [emitClassDeclarationWithPropertyAssignmentInES6.ts] class C { x: string = "Hello world"; } @@ -24,7 +24,7 @@ class F extends D{ } } -//// [emitClassDeclarationWithConstructorPropertyAssignmentInES6.js] +//// [emitClassDeclarationWithPropertyAssignmentInES6.js] class C { constructor() { this.x = "Hello world"; diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.types b/tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.types similarity index 86% rename from tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.types rename to tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.types index c121f936dbb..5e7ebbc167c 100644 --- a/tests/baselines/reference/emitClassDeclarationWithConstructorPropertyAssignmentInES6.types +++ b/tests/baselines/reference/emitClassDeclarationWithPropertyAssignmentInES6.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts === +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithPropertyAssignmentInES6.ts === class C { >C : C diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js new file mode 100644 index 00000000000..69da64765a3 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js @@ -0,0 +1,23 @@ +//// [emitClassDeclarationWithStaticPropertyAssignmentInES6.ts] +class C { + static z: string = "Foo"; +} + +class D { + x = 20000; + static b = true; +} + + +//// [emitClassDeclarationWithStaticPropertyAssignmentInES6.js] +class C { + constructor() { + } +} +C.z = "Foo"; +class D { + constructor() { + this.x = 20000; + } +} +D.b = true; diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.types b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.types new file mode 100644 index 00000000000..6003b85b590 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.types @@ -0,0 +1,18 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticPropertyAssignmentInES6.ts === +class C { +>C : C + + static z: string = "Foo"; +>z : string +} + +class D { +>D : D + + x = 20000; +>x : number + + static b = true; +>b : boolean +} + diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithPropertyAssignmentInES6.ts similarity index 100% rename from tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorPropertyAssignmentInES6.ts rename to tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithPropertyAssignmentInES6.ts diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticPropertyAssignmentInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticPropertyAssignmentInES6.ts new file mode 100644 index 00000000000..7ed36bb22a2 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithStaticPropertyAssignmentInES6.ts @@ -0,0 +1,9 @@ +// @target:es6 +class C { + static z: string = "Foo"; +} + +class D { + x = 20000; + static b = true; +} From 7ee587c43f737ed3823562260b091394d80df4c2 Mon Sep 17 00:00:00 2001 From: Yui T Date: Wed, 11 Mar 2015 16:45:55 -0700 Subject: [PATCH 08/26] Emit class with export and export default --- src/compiler/emitter.ts | 7 ++++++ .../emitClassDeclarationWithExport.errors.txt | 16 +++++++++++++ .../emitClassDeclarationWithExport.js | 23 +++++++++++++++++++ .../emitClassDeclarationWithExport.ts | 8 +++++++ 4 files changed, 54 insertions(+) create mode 100644 tests/baselines/reference/emitClassDeclarationWithExport.errors.txt create mode 100644 tests/baselines/reference/emitClassDeclarationWithExport.js create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index d4434c9bf4b..606bd22f2c9 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4664,6 +4664,13 @@ module ts { } function emitClassDeclarationAboveES6(node: ClassDeclaration) { + if (node.flags & NodeFlags.Export) { + write("export "); + + if (node.flags & NodeFlags.Default) { + write("default "); + } + } write("class "); emitDeclarationName(node); var baseTypeNode = getClassBaseTypeNode(node); diff --git a/tests/baselines/reference/emitClassDeclarationWithExport.errors.txt b/tests/baselines/reference/emitClassDeclarationWithExport.errors.txt new file mode 100644 index 00000000000..11b1de11bf6 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExport.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts(1,14): error TS1148: Cannot compile external modules unless the '--module' flag is provided. +tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts(5,22): error TS2309: An export assignment cannot be used in a module with other exported elements. + + +==== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts (2 errors) ==== + export class C { + ~ +!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. + foo() { } + } + + export default class D { + ~ +!!! error TS2309: An export assignment cannot be used in a module with other exported elements. + bar() { } + } \ No newline at end of file diff --git a/tests/baselines/reference/emitClassDeclarationWithExport.js b/tests/baselines/reference/emitClassDeclarationWithExport.js new file mode 100644 index 00000000000..5a6c84389f3 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithExport.js @@ -0,0 +1,23 @@ +//// [emitClassDeclarationWithExport.ts] +export class C { + foo() { } +} + +export default class D { + bar() { } +} + +//// [emitClassDeclarationWithExport.js] +export class C { + constructor() { + } + foo() { + } +} +export default class D { + constructor() { + } + bar() { + } +} +module.exports = D; diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts new file mode 100644 index 00000000000..f3ed5eb95d8 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts @@ -0,0 +1,8 @@ +// @target: es6 +export class C { + foo() { } +} + +export default class D { + bar() { } +} \ No newline at end of file From 56839604da355d1121f55a7fd40e026e5ce2a771 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 12 Mar 2015 08:40:09 -0700 Subject: [PATCH 09/26] Disallow refering to static property in computed property name --- src/compiler/checker.ts | 23 ++++++++++++++++ .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 4 +++ ...PropertyNamesWithStaticProperty.errors.txt | 22 ++++++++++++++++ ...computedPropertyNamesWithStaticProperty.js | 26 +++++++++++++++++++ ...computedPropertyNamesWithStaticProperty.ts | 11 ++++++++ 6 files changed, 87 insertions(+) create mode 100644 tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNamesWithStaticProperty.js create mode 100644 tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 135cecca730..28b3b74b271 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5696,6 +5696,29 @@ module ts { if (!links.resolvedType) { links.resolvedType = checkExpression(node.expression); + // Disallow using static property in computedPropertyName because classDeclaration is binded lexically in ES6 + // and its static property assignment will be emitted after classDeclaration. + // Therefore, using static property inside computedPropertyName will cause use-before-definition + // Example: + // * TypeScript + // class C { + // static p = 10; + // [C.p]() {} + // } + // * JavaScript + // class C { + // [C.p]() {} // Use before definition error + // } + // C.p = 10; + if (languageVersion >= ScriptTarget.ES6 && links.resolvedSymbol) { + var declarations = links.resolvedSymbol.declarations; + forEach(declarations, (declaration) => { + if (declaration.flags & NodeFlags.Static) { + error(node, Diagnostics.A_computed_property_name_cannot_reference_a_static_property); + } + }); + } + // This will allow types number, string, symbol or any. It will also allow enums, the unknown // type, and any union of these types (like string | number). if (!allConstituentTypesHaveKind(links.resolvedType, TypeFlags.Any | TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.ESSymbol)) { diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 24ed8ce4e99..a8b41e2159d 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -157,6 +157,7 @@ module ts { Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." }, An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, + A_computed_property_name_cannot_reference_a_static_property: { code: 1200, category: DiagnosticCategory.Error, key: "A computed property name cannot reference a static property" }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 40f7d55f9f0..489c929821d 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -619,6 +619,10 @@ "category": "Error", "code": 1199 }, + "A computed property name cannot reference a static property": { + "category": "Error", + "code": 1200 + }, "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 diff --git a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt new file mode 100644 index 00000000000..f078365f600 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt @@ -0,0 +1,22 @@ +tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts(3,9): error TS1200: A computed property name cannot reference a static property +tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts(6,9): error TS1200: A computed property name cannot reference a static property +tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts(9,5): error TS1200: A computed property name cannot reference a static property + + +==== tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts (3 errors) ==== + class C { + static staticProp = 10; + get [C.staticProp]() { + ~~~~~~~~~~~~~~ +!!! error TS1200: A computed property name cannot reference a static property + return "hello"; + } + set [C.staticProp](x: string) { + ~~~~~~~~~~~~~~ +!!! error TS1200: A computed property name cannot reference a static property + var y = x; + } + [C.staticProp]() { } + ~~~~~~~~~~~~~~ +!!! error TS1200: A computed property name cannot reference a static property + } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js new file mode 100644 index 00000000000..f7506d7904d --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js @@ -0,0 +1,26 @@ +//// [computedPropertyNamesWithStaticProperty.ts] +class C { + static staticProp = 10; + get [C.staticProp]() { + return "hello"; + } + set [C.staticProp](x: string) { + var y = x; + } + [C.staticProp]() { } +} + +//// [computedPropertyNamesWithStaticProperty.js] +class C { + constructor() { + } + get [C.staticProp]() { + return "hello"; + } + set [C.staticProp](x) { + var y = x; + } + [C.staticProp]() { + } +} +C.staticProp = 10; diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts new file mode 100644 index 00000000000..4cd9047581f --- /dev/null +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts @@ -0,0 +1,11 @@ +// @target: es6 +class C { + static staticProp = 10; + get [C.staticProp]() { + return "hello"; + } + set [C.staticProp](x: string) { + var y = x; + } + [C.staticProp]() { } +} \ No newline at end of file From 0672923323b35711cd65bf233955d4e848e449ef Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 12 Mar 2015 15:19:45 -0700 Subject: [PATCH 10/26] Parse classDeclaration in strict mode code for ES6 --- src/compiler/checker.ts | 6 ++- src/compiler/parser.ts | 22 ++++++++++- ...ationInStrictModeByDefaultInES6.errors.txt | 31 +++++++++++++++ ...ssDeclarationInStrictModeByDefaultInES6.js | 23 +++++++++++ ...ssDeclarationInStrictModeByDefaultInES6.ts | 9 +++++ tests/cases/unittests/incrementalParser.ts | 39 +++++++++++++++++++ 6 files changed, 128 insertions(+), 2 deletions(-) create mode 100644 tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt create mode 100644 tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.js create mode 100644 tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 28b3b74b271..689f27af867 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11891,7 +11891,11 @@ module ts { var identifier = name; if (contextNode && (contextNode.parserContextFlags & ParserContextFlags.StrictMode) && isEvalOrArgumentsIdentifier(identifier)) { var nameText = declarationNameToString(identifier); - return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); + + // Always report 'eval' and 'arguments' invalid usage in strict mode code regardless of parser diagnostics + var sourceFile = getSourceFileOfNode(identifier); + diagnostics.add(createDiagnosticForNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText)); + return true; } } } diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 0d6f002a3da..7658a49bc48 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4372,6 +4372,12 @@ module ts { function parsePropertyOrMethodDeclaration(fullStart: number, modifiers: ModifiersArray): ClassElement { var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); + + // From ES6 Specification, "implements", "interface", "let", "package", "private", "protected", "public", "static", and "yield" are reserved words within strict mode code + if (inStrictModeContext() && (token > SyntaxKind.LastReservedWord)) { + parseErrorAtCurrentToken(Diagnostics.Invalid_use_of_0_in_strict_mode, tokenToString(token)); + } + var name = parsePropertyName(); // Note: this is not legal as per the grammar. But we allow it in the parser and @@ -4517,6 +4523,12 @@ module ts { } function parseClassDeclaration(fullStart: number, modifiers: ModifiersArray): ClassDeclaration { + // In ES6 specification, All parts of a ClassDeclaration or a ClassExpression are strict mode code + if (languageVersion >= ScriptTarget.ES6) { + var savedStrictModeContext = inStrictModeContext(); + setStrictModeContext(true); + } + var node = createNode(SyntaxKind.ClassDeclaration, fullStart); setModifiers(node, modifiers); parseExpected(SyntaxKind.ClassKeyword); @@ -4537,7 +4549,15 @@ module ts { else { node.members = createMissingList(); } - return finishNode(node); + + var finishedNode = finishNode(node); + if (languageVersion >= ScriptTarget.ES6) { + setStrictModeContext(savedStrictModeContext); + return finishedNode; + } + else { + return finishedNode; + } } function parseHeritageClauses(isClassHeritageClause: boolean): NodeArray { diff --git a/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt new file mode 100644 index 00000000000..04ac8b28a8b --- /dev/null +++ b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt @@ -0,0 +1,31 @@ +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(2,5): error TS1100: Invalid use of 'interface' in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(3,12): error TS1100: Invalid use of 'implements' in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(4,16): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(5,17): error TS1100: Invalid use of 'eval' in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS1100: Invalid use of 'arguments' in strict mode. +tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS2322: Type 'string' is not assignable to type 'IArguments'. + Property 'callee' is missing in type 'String'. + + +==== tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts (6 errors) ==== + class C { + interface = 10; + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'interface' in strict mode. + public implements() { } + ~~~~~~~~~~ +!!! error TS1100: Invalid use of 'implements' in strict mode. + public foo(arguments: any) { } + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. + private bar(eval:any) { + ~~~~ +!!! error TS1100: Invalid use of 'eval' in strict mode. + arguments = "hello"; + ~~~~~~~~~ +!!! error TS1100: Invalid use of 'arguments' in strict mode. + ~~~~~~~~~ +!!! error TS2322: Type 'string' is not assignable to type 'IArguments'. +!!! error TS2322: Property 'callee' is missing in type 'String'. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.js b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.js new file mode 100644 index 00000000000..2a8d75dde60 --- /dev/null +++ b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.js @@ -0,0 +1,23 @@ +//// [parseClassDeclarationInStrictModeByDefaultInES6.ts] +class C { + interface = 10; + public implements() { } + public foo(arguments: any) { } + private bar(eval:any) { + arguments = "hello"; + } +} + +//// [parseClassDeclarationInStrictModeByDefaultInES6.js] +class C { + constructor() { + this.interface = 10; + } + implements() { + } + foo(arguments) { + } + bar(eval) { + arguments = "hello"; + } +} diff --git a/tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts b/tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts new file mode 100644 index 00000000000..b2517d89657 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts @@ -0,0 +1,9 @@ +// @target: es6 +class C { + interface = 10; + public implements() { } + public foo(arguments: any) { } + private bar(eval:any) { + arguments = "hello"; + } +} \ No newline at end of file diff --git a/tests/cases/unittests/incrementalParser.ts b/tests/cases/unittests/incrementalParser.ts index e785f1cdf00..87c0c3701f3 100644 --- a/tests/cases/unittests/incrementalParser.ts +++ b/tests/cases/unittests/incrementalParser.ts @@ -719,6 +719,16 @@ module m3 { }\ var oldText = ScriptSnapshot.fromString(source); var newTextAndChange = withChange(oldText, 0, "var v =".length, "class C"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. + }); + + it('Moving methods from object literal to class in strict mode', () => { + debugger; + var source = "\"use strict\"; var v = { public A() { } public B() { } public C() { } }" + + var oldText = ScriptSnapshot.fromString(source); + var newTextAndChange = withChange(oldText, 14, "var v =".length, "class C"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); }); @@ -728,6 +738,15 @@ module m3 { }\ var oldText = ScriptSnapshot.fromString(source); var newTextAndChange = withChange(oldText, 0, "class".length, "interface"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. + }); + + it('Moving index signatures from class to interface in strict mode', () => { + var source = "\"use strict\"; class C { public [a: number]: string; public [a: number]: string; public [a: number]: string }" + + var oldText = ScriptSnapshot.fromString(source); + var newTextAndChange = withChange(oldText, 14, "class".length, "interface"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 18); }); @@ -737,6 +756,16 @@ module m3 { }\ var oldText = ScriptSnapshot.fromString(source); var newTextAndChange = withChange(oldText, 0, "interface".length, "class"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. + }); + + + it('Moving index signatures from interface to class in strict mode', () => { + var source = "\"use strict\"; interface C { public [a: number]: string; public [a: number]: string; public [a: number]: string }" + + var oldText = ScriptSnapshot.fromString(source); + var newTextAndChange = withChange(oldText, 14, "interface".length, "class"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 18); }); @@ -755,6 +784,16 @@ module m3 { }\ var oldText = ScriptSnapshot.fromString(source); var newTextAndChange = withChange(oldText, 0, "var v =".length, "class C"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 0); // As specified in ES6 specification, all parts of a ClassDeclaration or a ClassExpression are strict mode code. + }); + + + it('Moving accessors from object literal to class in strict mode', () => { + var source = "\"use strict\"; var v = { public get A() { } public get B() { } public get C() { } }" + + var oldText = ScriptSnapshot.fromString(source); + var newTextAndChange = withChange(oldText, 14, "var v =".length, "class C"); + compareTrees(oldText, newTextAndChange.text, newTextAndChange.textChangeRange, 4); }); From 800c523f4f106fd8b5ebfd60287fe0375583e3b2 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 12 Mar 2015 16:02:43 -0700 Subject: [PATCH 11/26] Clean up redundant tests --- ...s => emitClassDeclarationOverloadInES6.js} | 4 +-- ...> emitClassDeclarationOverloadInES6.types} | 2 +- ...ClassDeclarationWithMethodOverloadInES6.js | 22 -------------- ...ssDeclarationWithMethodOverloadInES6.types | 29 ------------------- ...DeclarationWithRestAndDefaultArguements.js | 20 ------------- ...larationWithRestAndDefaultArguements.types | 25 ---------------- ...s => emitClassDeclarationOverloadInES6.ts} | 0 ...mitClassDeclarationWithConstructorInES6.ts | 18 +++++++++--- .../emitClassDeclarationWithExport.ts | 4 +-- .../emitClassDeclarationWithExtensionInES6.ts | 21 ++++++++++++-- ...ClassDeclarationWithMethodOverloadInES6.ts | 11 ------- ...DeclarationWithRestAndDefaultArguements.ts | 8 ----- .../emitClassDeclarationWithThisKeyword.ts | 18 ++++++++++++ 13 files changed, 55 insertions(+), 127 deletions(-) rename tests/baselines/reference/{emitClassDeclarationWithConstructorOverloadInES6.js => emitClassDeclarationOverloadInES6.js} (64%) rename tests/baselines/reference/{emitClassDeclarationWithConstructorOverloadInES6.types => emitClassDeclarationOverloadInES6.types} (81%) delete mode 100644 tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js delete mode 100644 tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types delete mode 100644 tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js delete mode 100644 tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types rename tests/cases/conformance/es6/classDeclaration/{emitClassDeclarationWithConstructorOverloadInES6.ts => emitClassDeclarationOverloadInES6.ts} (100%) delete mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts delete mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.js b/tests/baselines/reference/emitClassDeclarationOverloadInES6.js similarity index 64% rename from tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.js rename to tests/baselines/reference/emitClassDeclarationOverloadInES6.js index b7fe4f0cda7..4cf96778f3f 100644 --- a/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.js +++ b/tests/baselines/reference/emitClassDeclarationOverloadInES6.js @@ -1,4 +1,4 @@ -//// [emitClassDeclarationWithConstructorOverloadInES6.ts] +//// [emitClassDeclarationOverloadInES6.ts] class C { constructor(y: any) constructor(x: number) { @@ -10,7 +10,7 @@ class D { constructor(x: number, z="hello") {} } -//// [emitClassDeclarationWithConstructorOverloadInES6.js] +//// [emitClassDeclarationOverloadInES6.js] class C { constructor(x) { } diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.types b/tests/baselines/reference/emitClassDeclarationOverloadInES6.types similarity index 81% rename from tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.types rename to tests/baselines/reference/emitClassDeclarationOverloadInES6.types index 96e9f25549e..850a5aa5456 100644 --- a/tests/baselines/reference/emitClassDeclarationWithConstructorOverloadInES6.types +++ b/tests/baselines/reference/emitClassDeclarationOverloadInES6.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts === +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationOverloadInES6.ts === class C { >C : C diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js b/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js deleted file mode 100644 index 252a44122eb..00000000000 --- a/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.js +++ /dev/null @@ -1,22 +0,0 @@ -//// [emitClassDeclarationWithMethodOverloadInES6.ts] -class D { - _bar: string; - foo(a: any); - foo() { } - - baz(...args): string; - baz(z:string, v: number): string { - return this._bar; - } -} - -//// [emitClassDeclarationWithMethodOverloadInES6.js] -class D { - constructor() { - } - foo() { - } - baz(z, v) { - return this._bar; - } -} diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types b/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types deleted file mode 100644 index 3017908e576..00000000000 --- a/tests/baselines/reference/emitClassDeclarationWithMethodOverloadInES6.types +++ /dev/null @@ -1,29 +0,0 @@ -=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts === -class D { ->D : D - - _bar: string; ->_bar : string - - foo(a: any); ->foo : (a: any) => any ->a : any - - foo() { } ->foo : (a: any) => any - - baz(...args): string; ->baz : (...args: any[]) => string ->args : any[] - - baz(z:string, v: number): string { ->baz : (...args: any[]) => string ->z : string ->v : number - - return this._bar; ->this._bar : string ->this : D ->_bar : string - } -} diff --git a/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js b/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js deleted file mode 100644 index 179818387da..00000000000 --- a/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.js +++ /dev/null @@ -1,20 +0,0 @@ -//// [emitClassDeclarationWithRestAndDefaultArguements.ts] -class B { - constructor(y = 10, ...p) { } - foo(a = "hi") { } - bar(b = 10, ...p) { } - far(...p) - far(a: any) { } -} - -//// [emitClassDeclarationWithRestAndDefaultArguements.js] -class B { - constructor(y = 10, ...p) { - } - foo(a = "hi") { - } - bar(b = 10, ...p) { - } - far(a) { - } -} diff --git a/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types b/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types deleted file mode 100644 index 6f59f8220ad..00000000000 --- a/tests/baselines/reference/emitClassDeclarationWithRestAndDefaultArguements.types +++ /dev/null @@ -1,25 +0,0 @@ -=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts === -class B { ->B : B - - constructor(y = 10, ...p) { } ->y : number ->p : any[] - - foo(a = "hi") { } ->foo : (a?: string) => void ->a : string - - bar(b = 10, ...p) { } ->bar : (b?: number, ...p: any[]) => void ->b : number ->p : any[] - - far(...p) ->far : (...p: any[]) => any ->p : any[] - - far(a: any) { } ->far : (...p: any[]) => any ->a : any -} diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationOverloadInES6.ts similarity index 100% rename from tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorOverloadInES6.ts rename to tests/cases/conformance/es6/classDeclaration/emitClassDeclarationOverloadInES6.ts diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts index 9e06636da7e..e6c71b06740 100644 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts @@ -1,14 +1,24 @@ // @target: es6 -class C { +class A { y: number; constructor(x: number) { } + foo(a: any); + foo() { } } -class D { +class B { y: number; x: string = "hello"; - constructor(x: number, z = "hello") { + _bar: string; + + constructor(x: number, z = "hello", ...args) { this.y = 10; } -} \ No newline at end of file + baz(...args): string; + baz(z: string, v: number): string { + return this._bar; + } +} + + diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts index f3ed5eb95d8..c7fd43cb9e2 100644 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts @@ -1,8 +1,8 @@ // @target: es6 export class C { - foo() { } + foo(y: string, ...args: any) { } } export default class D { - bar() { } + bar(k = 10) {} } \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts index 519af626850..9b79d1b003b 100644 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts @@ -1,8 +1,23 @@ // @target: es6 -class B { } -class C extends B { } -class D extends B { +class B { + baz(a: string, y = 10) { } +} +class C extends B { + foo() { } + baz(a: string, y:number) { + super.baz(a, y); + } +} +class D extends C { constructor() { super(); } + + foo() { + super.foo(); + } + + baz() { + super.baz("hello", 10); + } } diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts deleted file mode 100644 index e1b277fae51..00000000000 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithMethodOverloadInES6.ts +++ /dev/null @@ -1,11 +0,0 @@ -// @target:es6 -class D { - _bar: string; - foo(a: any); - foo() { } - - baz(...args): string; - baz(z:string, v: number): string { - return this._bar; - } -} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts deleted file mode 100644 index 20c251b2cfa..00000000000 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithRestAndDefaultArguements.ts +++ /dev/null @@ -1,8 +0,0 @@ -// @target: es6 -class B { - constructor(y = 10, ...p) { } - foo(a = "hi") { } - bar(b = 10, ...p) { } - far(...p) - far(a: any) { } -} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts new file mode 100644 index 00000000000..f78e012bc20 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts @@ -0,0 +1,18 @@ +// @target: es6 +class B { + x = 10; + constructor() { + this.x = 10; + } + foo() { + console.log(this.x); + } + + get X() { + return this.x; + } + + set bX(y: number) { + this.x = y; + } +} \ No newline at end of file From af05afdc50617f783713b002470012d14b9e37e1 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 12 Mar 2015 16:34:06 -0700 Subject: [PATCH 12/26] Emit Super as super --- src/compiler/emitter.ts | 23 +++++--- .../emitClassDeclarationWithThisKeyword.js | 38 ++++++++++++++ .../emitClassDeclarationWithThisKeyword.types | 52 +++++++++++++++++++ .../emitClassDeclarationWithThisKeyword.ts | 3 +- 4 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 tests/baselines/reference/emitClassDeclarationWithThisKeyword.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithThisKeyword.types diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 606bd22f2c9..a0303610a3d 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2630,15 +2630,21 @@ module ts { } function emitSuper(node: Node) { - var flags = resolver.getNodeCheckFlags(node); - if (flags & NodeCheckFlags.SuperInstance) { - write("_super.prototype"); - } - else if (flags & NodeCheckFlags.SuperStatic) { - write("_super"); + if (languageVersion >= ScriptTarget.ES6) { + write("super"); } else { - write("super"); + Debug.assert(languageVersion < ScriptTarget.ES6) + var flags = resolver.getNodeCheckFlags(node); + if (flags & NodeCheckFlags.SuperInstance) { + write("_super.prototype"); + } + else if (flags & NodeCheckFlags.SuperStatic) { + write("_super"); + } + else { + write("super"); + } } } @@ -4544,7 +4550,8 @@ module ts { emitEnd(accessors.getAccessor); emitTrailingComments(accessors.getAccessor); } - else if (accessors.setAccessor) { + if (accessors.setAccessor) { + // We will only write new line if we just emit getAccessor emitLeadingComments(accessors.setAccessor); emitStart(accessors.setAccessor); if (member.flags & NodeFlags.Static) { diff --git a/tests/baselines/reference/emitClassDeclarationWithThisKeyword.js b/tests/baselines/reference/emitClassDeclarationWithThisKeyword.js new file mode 100644 index 00000000000..de100457aa9 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithThisKeyword.js @@ -0,0 +1,38 @@ +//// [emitClassDeclarationWithThisKeyword.ts] +class B { + x = 10; + constructor() { + this.x = 10; + } + static log(a: number) { } + foo() { + B.log(this.x); + } + + get X() { + return this.x; + } + + set bX(y: number) { + this.x = y; + } +} + +//// [emitClassDeclarationWithThisKeyword.js] +class B { + constructor() { + this.x = 10; + this.x = 10; + } + static log(a) { + } + foo() { + B.log(this.x); + } + get X() { + return this.x; + } + set bX(y) { + this.x = y; + } +} diff --git a/tests/baselines/reference/emitClassDeclarationWithThisKeyword.types b/tests/baselines/reference/emitClassDeclarationWithThisKeyword.types new file mode 100644 index 00000000000..ebb6f26598d --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithThisKeyword.types @@ -0,0 +1,52 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts === +class B { +>B : B + + x = 10; +>x : number + + constructor() { + this.x = 10; +>this.x = 10 : number +>this.x : number +>this : B +>x : number + } + static log(a: number) { } +>log : (a: number) => void +>a : number + + foo() { +>foo : () => void + + B.log(this.x); +>B.log(this.x) : void +>B.log : (a: number) => void +>B : typeof B +>log : (a: number) => void +>this.x : number +>this : B +>x : number + } + + get X() { +>X : number + + return this.x; +>this.x : number +>this : B +>x : number + } + + set bX(y: number) { +>bX : number +>y : number + + this.x = y; +>this.x = y : number +>this.x : number +>this : B +>x : number +>y : number + } +} diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts index f78e012bc20..4356fcce2ab 100644 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts @@ -4,8 +4,9 @@ class B { constructor() { this.x = 10; } + static log(a: number) { } foo() { - console.log(this.x); + B.log(this.x); } get X() { From a6a8a9624985bd7d70583154f6dc3f2868c1a0a3 Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Thu, 12 Mar 2015 22:52:54 -0700 Subject: [PATCH 13/26] Support an optional type annotation on export default statement --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 34 ++++++++++++++----- .../diagnosticInformationMap.generated.ts | 1 + src/compiler/diagnosticMessages.json | 7 +++- src/compiler/parser.ts | 12 +++++-- src/compiler/types.ts | 3 +- src/services/breakpoints.ts | 4 +++ .../baselines/reference/APISample_compile.js | 3 +- .../reference/APISample_compile.types | 6 +++- tests/baselines/reference/APISample_linter.js | 3 +- .../reference/APISample_linter.types | 6 +++- .../reference/APISample_transform.js | 3 +- .../reference/APISample_transform.types | 6 +++- .../baselines/reference/APISample_watcher.js | 3 +- .../reference/APISample_watcher.types | 6 +++- .../exportDefaultTypeAnnoation.errors.txt | 8 +++++ .../reference/exportDefaultTypeAnnoation.js | 6 ++++ .../reference/exportDefaultTypeAnnoation2.js | 7 ++++ .../exportDefaultTypeAnnoation2.types | 6 ++++ .../exportDefaultTypeAnnoation3.errors.txt | 21 ++++++++++++ .../reference/exportDefaultTypeAnnoation3.js | 22 ++++++++++++ .../compiler/exportDefaultTypeAnnoation.ts | 4 +++ .../compiler/exportDefaultTypeAnnoation2.ts | 6 ++++ .../compiler/exportDefaultTypeAnnoation3.ts | 15 ++++++++ 24 files changed, 172 insertions(+), 22 deletions(-) create mode 100644 tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt create mode 100644 tests/baselines/reference/exportDefaultTypeAnnoation.js create mode 100644 tests/baselines/reference/exportDefaultTypeAnnoation2.js create mode 100644 tests/baselines/reference/exportDefaultTypeAnnoation2.types create mode 100644 tests/baselines/reference/exportDefaultTypeAnnoation3.errors.txt create mode 100644 tests/baselines/reference/exportDefaultTypeAnnoation3.js create mode 100644 tests/cases/compiler/exportDefaultTypeAnnoation.ts create mode 100644 tests/cases/compiler/exportDefaultTypeAnnoation2.ts create mode 100644 tests/cases/compiler/exportDefaultTypeAnnoation3.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index e325b2033e7..af496db7ded 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -504,7 +504,7 @@ module ts { bindChildren(node, 0, /*isBlockScopeContainer*/ false); break; case SyntaxKind.ExportAssignment: - if ((node).expression.kind === SyntaxKind.Identifier) { + if ((node).expression && (node).expression.kind === SyntaxKind.Identifier) { // An export default clause with an identifier exports all meanings of that identifier declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.AliasExcludes); } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 1500a47f197..a8713c50afc 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -566,7 +566,7 @@ module ts { } function getTargetOfExportAssignment(node: ExportAssignment): Symbol { - return resolveEntityName(node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); + return node.expression && resolveEntityName(node.expression, SymbolFlags.Value | SymbolFlags.Type | SymbolFlags.Namespace); } function getTargetOfImportDeclaration(node: Declaration): Symbol { @@ -622,7 +622,7 @@ module ts { if (!links.referenced) { links.referenced = true; var node = getDeclarationOfAliasSymbol(symbol); - if (node.kind === SyntaxKind.ExportAssignment) { + if (node.kind === SyntaxKind.ExportAssignment && (node).expression) { // export default checkExpressionCached((node).expression); } @@ -2061,7 +2061,16 @@ module ts { } // Handle export default expressions if (declaration.kind === SyntaxKind.ExportAssignment) { - return links.type = checkExpression((declaration).expression); + var exportAssignment = (declaration); + if (exportAssignment.expression) { + return links.type = checkExpression(exportAssignment.expression); + } + else if (exportAssignment.type) { + return links.type = getTypeFromTypeNode(exportAssignment.type); + } + else { + return links.type = anyType; + } } // Handle variable, parameter or property links.type = resolvingType; @@ -10039,12 +10048,21 @@ module ts { if (!checkGrammarModifiers(node) && (node.flags & NodeFlags.Modifier)) { grammarErrorOnFirstToken(node, Diagnostics.An_export_assignment_cannot_have_modifiers); } - if (node.expression.kind === SyntaxKind.Identifier) { - markExportAsReferenced(node); + if (node.expression) { + if (node.expression.kind === SyntaxKind.Identifier) { + markExportAsReferenced(node); + } + else { + checkExpressionCached(node.expression); + } } - else { - checkExpressionCached(node.expression); + if (node.type) { + checkSourceElement(node.type); + if (!isInAmbientContext(node)) { + grammarErrorOnFirstToken(node.type, Diagnostics.Type_annotation_on_export_statements_are_only_allowed_in_ambient_module_declarations); + } } + checkExternalModuleExports(container); } @@ -10880,7 +10898,7 @@ module ts { } function generateNameForExportAssignment(node: ExportAssignment) { - if (node.expression.kind !== SyntaxKind.Identifier) { + if (node.expression && node.expression.kind !== SyntaxKind.Identifier) { assignGeneratedName(node, makeUniqueName("default")); } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index d40fcd25ce0..5d3bafc45a7 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -157,6 +157,7 @@ module ts { Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." }, An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, + Type_annotation_on_export_statements_are_only_allowed_in_ambient_module_declarations: { code: 1200, category: DiagnosticCategory.Error, key: "Type annotation on export statements are only allowed in ambient module declarations." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index c4121e92251..779e3891766 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -617,8 +617,13 @@ }, "Unterminated Unicode escape sequence.": { "category": "Error", - "code": 1199 + "code": 1199 }, + "Type annotation on export statements are only allowed in ambient module declarations.": { + "category": "Error", + "code": 1200 + }, + "Duplicate identifier '{0}'.": { "category": "Error", "code": 2300 diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 6e444eb23c7..d76385ff9c0 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -282,7 +282,8 @@ module ts { visitNode(cbNode, (node).name); case SyntaxKind.ExportAssignment: return visitNodes(cbNodes, node.modifiers) || - visitNode(cbNode, (node).expression); + visitNode(cbNode, (node).expression) || + visitNode(cbNode, (node).type); case SyntaxKind.TemplateExpression: return visitNode(cbNode, (node).head) || visitNodes(cbNodes, (node).templateSpans); case SyntaxKind.TemplateSpan: @@ -4862,12 +4863,17 @@ module ts { setModifiers(node, modifiers); if (parseOptional(SyntaxKind.EqualsToken)) { node.isExportEquals = true; + node.expression = parseAssignmentExpressionOrHigher(); } else { parseExpected(SyntaxKind.DefaultKeyword); + if (parseOptional(SyntaxKind.ColonToken)) { + node.type = parseType(); + } + else { + node.expression = parseAssignmentExpressionOrHigher(); + } } - //node.exportName = parseIdentifier(); - node.expression = parseAssignmentExpressionOrHigher(); parseSemicolon(); return finishNode(node); } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 7301e087ae1..a893c36c359 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -940,7 +940,8 @@ module ts { export interface ExportAssignment extends Declaration, ModuleElement { isExportEquals?: boolean; - expression: Expression; + expression?: Expression; + type?: TypeNode; } export interface FileReference extends TextRange { diff --git a/src/services/breakpoints.ts b/src/services/breakpoints.ts index 1f87ae40745..e3d8fa9256e 100644 --- a/src/services/breakpoints.ts +++ b/src/services/breakpoints.ts @@ -173,6 +173,10 @@ module ts.BreakpointResolver { return textSpan(node, (node).expression); case SyntaxKind.ExportAssignment: + if (!(node).expression) { + return undefined; + } + // span on export = id return textSpan(node, (node).expression); diff --git a/tests/baselines/reference/APISample_compile.js b/tests/baselines/reference/APISample_compile.js index 6e6adb2cd45..abe0700f66b 100644 --- a/tests/baselines/reference/APISample_compile.js +++ b/tests/baselines/reference/APISample_compile.js @@ -762,7 +762,8 @@ declare module "typescript" { type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Declaration, ModuleElement { isExportEquals?: boolean; - expression: Expression; + expression?: Expression; + type?: TypeNode; } interface FileReference extends TextRange { fileName: string; diff --git a/tests/baselines/reference/APISample_compile.types b/tests/baselines/reference/APISample_compile.types index 17ce175ebdf..088424863e8 100644 --- a/tests/baselines/reference/APISample_compile.types +++ b/tests/baselines/reference/APISample_compile.types @@ -2324,9 +2324,13 @@ declare module "typescript" { isExportEquals?: boolean; >isExportEquals : boolean - expression: Expression; + expression?: Expression; >expression : Expression >Expression : Expression + + type?: TypeNode; +>type : TypeNode +>TypeNode : TypeNode } interface FileReference extends TextRange { >FileReference : FileReference diff --git a/tests/baselines/reference/APISample_linter.js b/tests/baselines/reference/APISample_linter.js index 4f1fc899a89..f24be65ecb9 100644 --- a/tests/baselines/reference/APISample_linter.js +++ b/tests/baselines/reference/APISample_linter.js @@ -793,7 +793,8 @@ declare module "typescript" { type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Declaration, ModuleElement { isExportEquals?: boolean; - expression: Expression; + expression?: Expression; + type?: TypeNode; } interface FileReference extends TextRange { fileName: string; diff --git a/tests/baselines/reference/APISample_linter.types b/tests/baselines/reference/APISample_linter.types index d1dcad98d85..cafe25ed5bc 100644 --- a/tests/baselines/reference/APISample_linter.types +++ b/tests/baselines/reference/APISample_linter.types @@ -2470,9 +2470,13 @@ declare module "typescript" { isExportEquals?: boolean; >isExportEquals : boolean - expression: Expression; + expression?: Expression; >expression : Expression >Expression : Expression + + type?: TypeNode; +>type : TypeNode +>TypeNode : TypeNode } interface FileReference extends TextRange { >FileReference : FileReference diff --git a/tests/baselines/reference/APISample_transform.js b/tests/baselines/reference/APISample_transform.js index 3ef3d7bc0f5..2ce87d5c9ef 100644 --- a/tests/baselines/reference/APISample_transform.js +++ b/tests/baselines/reference/APISample_transform.js @@ -794,7 +794,8 @@ declare module "typescript" { type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Declaration, ModuleElement { isExportEquals?: boolean; - expression: Expression; + expression?: Expression; + type?: TypeNode; } interface FileReference extends TextRange { fileName: string; diff --git a/tests/baselines/reference/APISample_transform.types b/tests/baselines/reference/APISample_transform.types index 4bfac42f571..afc61a39fdf 100644 --- a/tests/baselines/reference/APISample_transform.types +++ b/tests/baselines/reference/APISample_transform.types @@ -2420,9 +2420,13 @@ declare module "typescript" { isExportEquals?: boolean; >isExportEquals : boolean - expression: Expression; + expression?: Expression; >expression : Expression >Expression : Expression + + type?: TypeNode; +>type : TypeNode +>TypeNode : TypeNode } interface FileReference extends TextRange { >FileReference : FileReference diff --git a/tests/baselines/reference/APISample_watcher.js b/tests/baselines/reference/APISample_watcher.js index c85be654c89..b1124e6c64f 100644 --- a/tests/baselines/reference/APISample_watcher.js +++ b/tests/baselines/reference/APISample_watcher.js @@ -831,7 +831,8 @@ declare module "typescript" { type ExportSpecifier = ImportOrExportSpecifier; interface ExportAssignment extends Declaration, ModuleElement { isExportEquals?: boolean; - expression: Expression; + expression?: Expression; + type?: TypeNode; } interface FileReference extends TextRange { fileName: string; diff --git a/tests/baselines/reference/APISample_watcher.types b/tests/baselines/reference/APISample_watcher.types index e4b53feeac0..36958c9320d 100644 --- a/tests/baselines/reference/APISample_watcher.types +++ b/tests/baselines/reference/APISample_watcher.types @@ -2593,9 +2593,13 @@ declare module "typescript" { isExportEquals?: boolean; >isExportEquals : boolean - expression: Expression; + expression?: Expression; >expression : Expression >Expression : Expression + + type?: TypeNode; +>type : TypeNode +>TypeNode : TypeNode } interface FileReference extends TextRange { >FileReference : FileReference diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt b/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt new file mode 100644 index 00000000000..fa7806a17dd --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/exportDefaultTypeAnnoation.ts(2,18): error TS1200: Type annotation on export statements are only allowed in ambient module declarations. + + +==== tests/cases/compiler/exportDefaultTypeAnnoation.ts (1 errors) ==== + + export default : number; + ~~~~~~ +!!! error TS1200: Type annotation on export statements are only allowed in ambient module declarations. \ No newline at end of file diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation.js b/tests/baselines/reference/exportDefaultTypeAnnoation.js new file mode 100644 index 00000000000..8adf31a5f18 --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation.js @@ -0,0 +1,6 @@ +//// [exportDefaultTypeAnnoation.ts] + +export default : number; + +//// [exportDefaultTypeAnnoation.js] +module.exports = ; diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation2.js b/tests/baselines/reference/exportDefaultTypeAnnoation2.js new file mode 100644 index 00000000000..2c918954702 --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation2.js @@ -0,0 +1,7 @@ +//// [exportDefaultTypeAnnoation2.ts] + +declare module "mod" { + export default : number; +} + +//// [exportDefaultTypeAnnoation2.js] diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation2.types b/tests/baselines/reference/exportDefaultTypeAnnoation2.types new file mode 100644 index 00000000000..53ca78586cc --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation2.types @@ -0,0 +1,6 @@ +=== tests/cases/compiler/exportDefaultTypeAnnoation2.ts === + +No type information for this code.declare module "mod" { +No type information for this code. export default : number; +No type information for this code.} +No type information for this code. \ No newline at end of file diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation3.errors.txt b/tests/baselines/reference/exportDefaultTypeAnnoation3.errors.txt new file mode 100644 index 00000000000..326713e059e --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation3.errors.txt @@ -0,0 +1,21 @@ +tests/cases/compiler/reference1.ts(2,5): error TS2322: Type 'number' is not assignable to type 'string'. +tests/cases/compiler/reference2.ts(2,5): error TS2322: Type 'number' is not assignable to type 'string'. + + +==== tests/cases/compiler/mod.d.ts (0 errors) ==== + + declare module "mod" { + export default : number; + } + +==== tests/cases/compiler/reference1.ts (1 errors) ==== + import d from "mod"; + var s: string = d; // Error + ~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. + +==== tests/cases/compiler/reference2.ts (1 errors) ==== + import { default as d } from "mod"; + var s: string = d; // Error + ~ +!!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation3.js b/tests/baselines/reference/exportDefaultTypeAnnoation3.js new file mode 100644 index 00000000000..069c8385e77 --- /dev/null +++ b/tests/baselines/reference/exportDefaultTypeAnnoation3.js @@ -0,0 +1,22 @@ +//// [tests/cases/compiler/exportDefaultTypeAnnoation3.ts] //// + +//// [mod.d.ts] + +declare module "mod" { + export default : number; +} + +//// [reference1.ts] +import d from "mod"; +var s: string = d; // Error + +//// [reference2.ts] +import { default as d } from "mod"; +var s: string = d; // Error + +//// [reference1.js] +var d = require("mod"); +var s = d; // Error +//// [reference2.js] +var _mod = require("mod"); +var s = _mod.default; // Error diff --git a/tests/cases/compiler/exportDefaultTypeAnnoation.ts b/tests/cases/compiler/exportDefaultTypeAnnoation.ts new file mode 100644 index 00000000000..d7fd24d5be3 --- /dev/null +++ b/tests/cases/compiler/exportDefaultTypeAnnoation.ts @@ -0,0 +1,4 @@ +// @target: es5 +// @module: commonjs + +export default : number; \ No newline at end of file diff --git a/tests/cases/compiler/exportDefaultTypeAnnoation2.ts b/tests/cases/compiler/exportDefaultTypeAnnoation2.ts new file mode 100644 index 00000000000..ddb317bd8fc --- /dev/null +++ b/tests/cases/compiler/exportDefaultTypeAnnoation2.ts @@ -0,0 +1,6 @@ +// @target: es5 +// @module: commonjs + +declare module "mod" { + export default : number; +} \ No newline at end of file diff --git a/tests/cases/compiler/exportDefaultTypeAnnoation3.ts b/tests/cases/compiler/exportDefaultTypeAnnoation3.ts new file mode 100644 index 00000000000..88a45de2d32 --- /dev/null +++ b/tests/cases/compiler/exportDefaultTypeAnnoation3.ts @@ -0,0 +1,15 @@ +// @target: es5 +// @module: commonjs + +// @fileName: mod.d.ts +declare module "mod" { + export default : number; +} + +// @fileName: reference1.ts +import d from "mod"; +var s: string = d; // Error + +// @fileName: reference2.ts +import { default as d } from "mod"; +var s: string = d; // Error \ No newline at end of file From 13e55ae8cbfff8ebb44e3285f7146163d00b3848 Mon Sep 17 00:00:00 2001 From: Yui T Date: Sat, 14 Mar 2015 16:53:33 -0700 Subject: [PATCH 14/26] Address code review --- src/compiler/checker.ts | 12 ++-- src/compiler/emitter.ts | 137 +++++++++------------------------------- src/compiler/parser.ts | 6 -- 3 files changed, 36 insertions(+), 119 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 689f27af867..feb95b4da16 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5696,9 +5696,9 @@ module ts { if (!links.resolvedType) { links.resolvedType = checkExpression(node.expression); - // Disallow using static property in computedPropertyName because classDeclaration is binded lexically in ES6 + // Disallow using a static property in computedPropertyName because classDeclaration is bound lexically in ES6 // and its static property assignment will be emitted after classDeclaration. - // Therefore, using static property inside computedPropertyName will cause use-before-definition + // Therefore, using static property inside computedPropertyName will cause an use-before-definition error // Example: // * TypeScript // class C { @@ -5710,9 +5710,9 @@ module ts { // [C.p]() {} // Use before definition error // } // C.p = 10; - if (languageVersion >= ScriptTarget.ES6 && links.resolvedSymbol) { + if (links.resolvedSymbol) { var declarations = links.resolvedSymbol.declarations; - forEach(declarations, (declaration) => { + forEach(declarations, declaration => { if (declaration.flags & NodeFlags.Static) { error(node, Diagnostics.A_computed_property_name_cannot_reference_a_static_property); } @@ -9296,9 +9296,7 @@ module ts { var staticType = getTypeOfSymbol(symbol); var baseTypeNode = getClassBaseTypeNode(node); if (baseTypeNode) { - if (languageVersion < ScriptTarget.ES6) { - emitExtends = emitExtends || !isInAmbientContext(node); - } + emitExtends = emitExtends || !isInAmbientContext(node); checkTypeReference(baseTypeNode); } if (type.baseTypes.length) { diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a0303610a3d..96c34ae743d 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2634,7 +2634,6 @@ module ts { write("super"); } else { - Debug.assert(languageVersion < ScriptTarget.ES6) var flags = resolver.getNodeCheckFlags(node); if (flags & NodeCheckFlags.SuperInstance) { write("_super.prototype"); @@ -3175,12 +3174,7 @@ module ts { } var superCall = false; if (node.expression.kind === SyntaxKind.SuperKeyword) { - if (languageVersion < ScriptTarget.ES6) { - write("_super"); - } - else { - write("super"); - } + emitSuper(node.expression); superCall = true; } else { @@ -3196,18 +3190,13 @@ module ts { } write(")"); } - else if (superCall && languageVersion >= ScriptTarget.ES6) { + else { write("("); if (node.arguments.length) { emitCommaList(node.arguments); } write(")"); } - else { - write("("); - emitCommaList(node.arguments); - write(")"); - } } function emitNewExpression(node: NewExpression) { @@ -4413,8 +4402,20 @@ module ts { emitComputedPropertyName(memberName); } else { - // For script-target that is ES6 or above, we want to emit memberName by itself without prefix "." if the memberName is a name of method. - // If the memberName is the name of property, we need to emit it with prefix ".". + // For ES6 and above, we want to emit memberName by itself without prefix ".", + // For ES5 and below, we want to prefix memberName with ".". For example, + // Typescript: + // class C { + // x = 10; + // foo () {} + // } + // Javascript: + // var C = (function () { + // function C() { + // this.x = 10; // Property "x" need to be prefixed with "." + // } + // C.prototype.foo = function() {}; // Similarly property "foo" need to be prefixed with "." + // } if (languageVersion < ScriptTarget.ES6 || memberName.parent.kind === SyntaxKind.PropertyDeclaration) { write("."); } @@ -4446,7 +4447,7 @@ module ts { }); } - function emitMemberFunctionsBelowES6(node: ClassDeclaration) { + function emitMemberFunctionsForES5AndLower(node: ClassDeclaration) { forEach(node.members, member => { if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { @@ -4516,7 +4517,7 @@ module ts { }); } - function emitMemberFunctionsAboveES6(node: ClassDeclaration) { + function emitMemberFunctionsForES6AndHigher(node: ClassDeclaration) { forEach(node.members, member => { if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { if (!(member).body) { @@ -4568,7 +4569,7 @@ module ts { }); } - function emitConstructorOfClass(node: ClassDeclaration, baseTypeNode: TypeReferenceNode) { + function emitConstructor(node: ClassDeclaration, baseTypeNode: TypeReferenceNode) { var saveTempCount = tempCount; var saveTempVariables = tempVariables; var saveTempParameters = tempParameters; @@ -4597,7 +4598,6 @@ module ts { emitSignatureParameters(ctor); } else { - Debug.assert(languageVersion >= ScriptTarget.ES6, "Expected Script Target to be ES6 or above"); write("constructor"); if (ctor) { emitSignatureParameters(ctor); @@ -4670,7 +4670,7 @@ module ts { tempParameters = saveTempParameters; } - function emitClassDeclarationAboveES6(node: ClassDeclaration) { + function emitClassDeclarationForES6AndHigher(node: ClassDeclaration) { if (node.flags & NodeFlags.Export) { write("export "); @@ -4683,20 +4683,21 @@ module ts { var baseTypeNode = getClassBaseTypeNode(node); if (baseTypeNode) { write(" extends "); - emitNodeWithoutSourceMap(baseTypeNode.typeName); + emit(baseTypeNode.typeName); } write(" {"); increaseIndent(); scopeEmitStart(node); writeLine(); - emitConstructorOfClass(node, baseTypeNode); - emitMemberFunctionsAboveES6(node); + emitConstructor(node, baseTypeNode); + emitMemberFunctionsForES6AndHigher(node); decreaseIndent(); writeLine(); emitToken(SyntaxKind.CloseBraceToken, node.members.end); scopeEmitEnd(); - // Emit static property assignment. Because classDeclaration is lexically evaluated, it is safe to emit static property assignment after classDeclaration + // Emit static property assignment. Because classDeclaration is lexically evaluated, + // it is safe to emit static property assignment after classDeclaration // From ES6 specification: // HasLexicalDeclaration (N) : Determines if the argument identifier has a binding in this environment record that was created using // a lexical declaration such as a LexicalDeclaration or a ClassDeclaration. @@ -4724,8 +4725,8 @@ module ts { emitEnd(baseTypeNode); } writeLine(); - emitConstructorOfClass(node, baseTypeNode); - emitMemberFunctionsBelowES6(node); + emitConstructor(node, baseTypeNode); + emitMemberFunctionsForES5AndLower(node); emitMemberAssignments(node, NodeFlags.Static); writeLine(); emitToken(SyntaxKind.CloseBraceToken, node.members.end, () => { @@ -4756,84 +4757,6 @@ module ts { if (languageVersion < ScriptTarget.ES6 && node.parent === currentSourceFile && node.name) { emitExportMemberAssignments(node.name); } - - function emitConstructorOfClassOLD() { - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; - tempCount = 0; - tempVariables = undefined; - tempParameters = undefined; - - var popFrame = enterNameScope(); - - // Emit the constructor overload pinned comments - forEach(node.members, member => { - if (member.kind === SyntaxKind.Constructor && !(member).body) { - emitPinnedOrTripleSlashComments(member); - } - }); - - var ctor = getFirstConstructorWithBody(node); - if (ctor) { - emitLeadingComments(ctor); - } - emitStart(ctor || node); - write("function "); - emitDeclarationName(node); - emitSignatureParameters(ctor); - write(" {"); - scopeEmitStart(node, "constructor"); - increaseIndent(); - if (ctor) { - emitDetachedComments((ctor.body).statements); - } - emitCaptureThisForNodeIfNecessary(node); - if (ctor) { - emitDefaultValueAssignments(ctor); - emitRestParameter(ctor); - if (baseTypeNode) { - var superCall = findInitialSuperCall(ctor); - if (superCall) { - writeLine(); - emit(superCall); - } - } - emitParameterPropertyAssignments(ctor); - } - else { - if (baseTypeNode) { - writeLine(); - emitStart(baseTypeNode); - write("_super.apply(this, arguments);"); - emitEnd(baseTypeNode); - } - } - emitMemberAssignments(node, /*nonstatic*/0); - if (ctor) { - var statements: Node[] = (ctor.body).statements; - if (superCall) statements = statements.slice(1); - emitLines(statements); - } - emitTempDeclarations(/*newLine*/ true); - writeLine(); - if (ctor) { - emitLeadingCommentsOfPosition((ctor.body).statements.end); - } - decreaseIndent(); - emitToken(SyntaxKind.CloseBraceToken, ctor ? (ctor.body).statements.end : node.members.end); - scopeEmitEnd(); - emitEnd(ctor || node); - if (ctor) { - emitTrailingComments(ctor); - } - - exitNameScope(popFrame); - - tempCount = saveTempCount; - tempVariables = saveTempVariables; - tempParameters = saveTempParameters; - } } function emitInterfaceDeclaration(node: InterfaceDeclaration) { @@ -5322,7 +5245,9 @@ module ts { // emit prologue directives prior to __extends var startIndex = emitDirectivePrologues(node.statements, /*startWithNewLine*/ false); - if (!extendsEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitExtends) { + // Only Emit __extends function when target ES5. + // For target ES6 and above, we can emit classDeclaration as if. + if ((languageVersion < ScriptTarget.ES6) && (!extendsEmitted && resolver.getNodeCheckFlags(node) & NodeCheckFlags.EmitExtends)) { writeLine(); write("var __extends = this.__extends || function (d, b) {"); increaseIndent(); @@ -5554,7 +5479,7 @@ module ts { case SyntaxKind.VariableDeclaration: return emitVariableDeclaration(node); case SyntaxKind.ClassDeclaration: - return languageVersion < ScriptTarget.ES6 ? emitClassDeclarationBelowES6(node) : emitClassDeclarationAboveES6(node); + return languageVersion < ScriptTarget.ES6 ? emitClassDeclarationBelowES6(node) : emitClassDeclarationForES6AndHigher(node); case SyntaxKind.InterfaceDeclaration: return emitInterfaceDeclaration(node); case SyntaxKind.EnumDeclaration: diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 7658a49bc48..5a07b22153d 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4372,12 +4372,6 @@ module ts { function parsePropertyOrMethodDeclaration(fullStart: number, modifiers: ModifiersArray): ClassElement { var asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); - - // From ES6 Specification, "implements", "interface", "let", "package", "private", "protected", "public", "static", and "yield" are reserved words within strict mode code - if (inStrictModeContext() && (token > SyntaxKind.LastReservedWord)) { - parseErrorAtCurrentToken(Diagnostics.Invalid_use_of_0_in_strict_mode, tokenToString(token)); - } - var name = parsePropertyName(); // Note: this is not legal as per the grammar. But we allow it in the parser and From 2a07d3f8db9e4bf8da8a74f8c3d184082a1d5e57 Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 15 Mar 2015 12:33:29 -0700 Subject: [PATCH 15/26] Address code review: do not emit default constructor --- src/compiler/emitter.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 96c34ae743d..b3b305dd6c4 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4578,15 +4578,29 @@ module ts { tempParameters = undefined; var popFrame = enterNameScope(); + // Check if we have property assignment inside class declaration. + // If there is property assignment, we need to emit constructor whether users define it or not + // If there is no property assignment, we can omit constructor if users do not define it + var hasPropertyAssignment = false; // Emit the constructor overload pinned comments forEach(node.members, member => { if (member.kind === SyntaxKind.Constructor && !(member).body) { emitPinnedOrTripleSlashComments(member); } + if (member.kind === SyntaxKind.PropertyDeclaration && (member).initializer) { + hasPropertyAssignment = true; + } }); var ctor = getFirstConstructorWithBody(node); + + // For target ES6 and above, if there is no user-defined constructor and there is no property assignment + // do not emit constructor in class declaration. + if (languageVersion >= ScriptTarget.ES6 && !ctor && !hasPropertyAssignment) { + return; + } + if (ctor) { emitLeadingComments(ctor); } @@ -4617,6 +4631,7 @@ module ts { } } } + write(" {"); scopeEmitStart(node, "constructor"); increaseIndent(); From 44a5343c1ecb295835b21247e572d4c9c760fc4e Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Sun, 15 Mar 2015 14:37:12 -0700 Subject: [PATCH 16/26] Upate error message --- src/compiler/checker.ts | 4 ++-- src/compiler/diagnosticInformationMap.generated.ts | 2 +- src/compiler/diagnosticMessages.json | 2 +- .../baselines/reference/exportDefaultTypeAnnoation.errors.txt | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c79ca2f1fd2..66f31790028 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2073,7 +2073,7 @@ module ts { } // Handle export default expressions if (declaration.kind === SyntaxKind.ExportAssignment) { - var exportAssignment = (declaration); + var exportAssignment = declaration; if (exportAssignment.expression) { return links.type = checkExpression(exportAssignment.expression); } @@ -10095,7 +10095,7 @@ module ts { if (node.type) { checkSourceElement(node.type); if (!isInAmbientContext(node)) { - grammarErrorOnFirstToken(node.type, Diagnostics.Type_annotation_on_export_statements_are_only_allowed_in_ambient_module_declarations); + grammarErrorOnFirstToken(node.type, Diagnostics.A_type_annotation_on_an_export_statement_is_only_allowed_in_an_ambient_external_module_declaration); } } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 5d3bafc45a7..e3bb7aa8f43 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -157,7 +157,7 @@ module ts { Catch_clause_variable_cannot_have_an_initializer: { code: 1197, category: DiagnosticCategory.Error, key: "Catch clause variable cannot have an initializer." }, An_extended_Unicode_escape_value_must_be_between_0x0_and_0x10FFFF_inclusive: { code: 1198, category: DiagnosticCategory.Error, key: "An extended Unicode escape value must be between 0x0 and 0x10FFFF inclusive." }, Unterminated_Unicode_escape_sequence: { code: 1199, category: DiagnosticCategory.Error, key: "Unterminated Unicode escape sequence." }, - Type_annotation_on_export_statements_are_only_allowed_in_ambient_module_declarations: { code: 1200, category: DiagnosticCategory.Error, key: "Type annotation on export statements are only allowed in ambient module declarations." }, + A_type_annotation_on_an_export_statement_is_only_allowed_in_an_ambient_external_module_declaration: { code: 1200, category: DiagnosticCategory.Error, key: "A type annotation on an export statement is only allowed in an ambient external module declaration." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 779e3891766..3c8ecadee02 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -619,7 +619,7 @@ "category": "Error", "code": 1199 }, - "Type annotation on export statements are only allowed in ambient module declarations.": { + "A type annotation on an export statement is only allowed in an ambient external module declaration.": { "category": "Error", "code": 1200 }, diff --git a/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt b/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt index fa7806a17dd..472dc0c74c1 100644 --- a/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt +++ b/tests/baselines/reference/exportDefaultTypeAnnoation.errors.txt @@ -1,8 +1,8 @@ -tests/cases/compiler/exportDefaultTypeAnnoation.ts(2,18): error TS1200: Type annotation on export statements are only allowed in ambient module declarations. +tests/cases/compiler/exportDefaultTypeAnnoation.ts(2,18): error TS1200: A type annotation on an export statement is only allowed in an ambient external module declaration. ==== tests/cases/compiler/exportDefaultTypeAnnoation.ts (1 errors) ==== export default : number; ~~~~~~ -!!! error TS1200: Type annotation on export statements are only allowed in ambient module declarations. \ No newline at end of file +!!! error TS1200: A type annotation on an export statement is only allowed in an ambient external module declaration. \ No newline at end of file From 9bf5a11befa3c25ddccc8b7ef444f9d9ecf41d83 Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 15 Mar 2015 16:29:41 -0700 Subject: [PATCH 17/26] Update baselines --- src/compiler/emitter.ts | 9 +- .../baselines/reference/callWithSpreadES6.js | 37 +++--- .../reference/computedPropertyNames12_ES6.js | 9 +- .../reference/computedPropertyNames13_ES6.js | 49 ++++---- .../reference/computedPropertyNames14_ES6.js | 29 +++-- .../reference/computedPropertyNames15_ES6.js | 17 ++- .../reference/computedPropertyNames16_ES6.js | 105 +++++------------- .../reference/computedPropertyNames17_ES6.js | 59 +++------- .../reference/computedPropertyNames21_ES6.js | 15 +-- .../reference/computedPropertyNames22_ES6.js | 11 +- .../reference/computedPropertyNames23_ES6.js | 17 ++- .../reference/computedPropertyNames24_ES6.js | 28 ++--- .../reference/computedPropertyNames25_ES6.js | 30 ++--- .../reference/computedPropertyNames26_ES6.js | 32 ++---- .../reference/computedPropertyNames27_ES6.js | 24 +--- .../reference/computedPropertyNames28_ES6.js | 25 ++--- .../reference/computedPropertyNames29_ES6.js | 11 +- .../reference/computedPropertyNames2_ES6.js | 45 +++----- .../reference/computedPropertyNames30_ES6.js | 25 ++--- .../reference/computedPropertyNames31_ES6.js | 30 ++--- .../reference/computedPropertyNames32_ES6.js | 15 +-- .../reference/computedPropertyNames33_ES6.js | 11 +- .../reference/computedPropertyNames34_ES6.js | 11 +- .../reference/computedPropertyNames36_ES6.js | 37 ++---- .../reference/computedPropertyNames37_ES6.js | 37 ++---- .../reference/computedPropertyNames38_ES6.js | 37 ++---- .../reference/computedPropertyNames39_ES6.js | 37 ++---- .../computedPropertyNames3_ES6.errors.txt | 5 +- .../reference/computedPropertyNames3_ES6.js | 49 +++----- .../reference/computedPropertyNames40_ES6.js | 29 ++--- .../reference/computedPropertyNames41_ES6.js | 25 ++--- .../reference/computedPropertyNames42_ES6.js | 21 +--- .../reference/computedPropertyNames43_ES6.js | 52 ++------- .../reference/computedPropertyNames44_ES6.js | 50 ++------- .../reference/computedPropertyNames45_ES6.js | 50 ++------- ...mputedPropertyNamesDeclarationEmit1_ES6.js | 27 ++--- ...mputedPropertyNamesDeclarationEmit2_ES6.js | 27 ++--- .../computedPropertyNamesOnOverloads_ES6.js | 9 +- ...computedPropertyNamesSourceMap1_ES5.js.map | 2 +- ...dPropertyNamesSourceMap1_ES5.sourcemap.txt | 8 +- .../computedPropertyNamesSourceMap1_ES6.js | 11 +- ...computedPropertyNamesSourceMap1_ES6.js.map | 2 +- ...dPropertyNamesSourceMap1_ES6.sourcemap.txt | 96 +++++----------- .../reference/constDeclarations-scopes.js | 33 +++--- .../constDeclarations-validContexts.js | 29 ++--- .../destructuringParameterProperties4.js | 40 +++---- .../emitDefaultParametersMethodES6.js | 37 +++--- .../reference/emitRestParametersMethodES6.js | 30 +++-- 48 files changed, 454 insertions(+), 970 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b3b305dd6c4..a079994e5c8 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2630,6 +2630,7 @@ module ts { } function emitSuper(node: Node) { + debugger; if (languageVersion >= ScriptTarget.ES6) { write("super"); } @@ -2638,11 +2639,11 @@ module ts { if (flags & NodeCheckFlags.SuperInstance) { write("_super.prototype"); } - else if (flags & NodeCheckFlags.SuperStatic) { + else if ((flags & NodeCheckFlags.SuperStatic) || (node.parent.kind === SyntaxKind.Constructor)) { write("_super"); } else { - write("super"); + write("_super"); } } } @@ -4538,8 +4539,8 @@ module ts { else if (member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { var accessors = getAllAccessorDeclarations(node.members, member); if (member === accessors.firstAccessor) { - writeLine(); if (accessors.getAccessor) { + writeLine(); emitLeadingComments(accessors.getAccessor); emitStart(accessors.getAccessor); if (member.flags & NodeFlags.Static) { @@ -4553,6 +4554,7 @@ module ts { } if (accessors.setAccessor) { // We will only write new line if we just emit getAccessor + writeLine(); emitLeadingComments(accessors.setAccessor); emitStart(accessors.setAccessor); if (member.flags & NodeFlags.Static) { @@ -4570,6 +4572,7 @@ module ts { } function emitConstructor(node: ClassDeclaration, baseTypeNode: TypeReferenceNode) { + debugger; var saveTempCount = tempCount; var saveTempVariables = tempVariables; var saveTempParameters = tempParameters; diff --git a/tests/baselines/reference/callWithSpreadES6.js b/tests/baselines/reference/callWithSpreadES6.js index 0becb4c6e3e..d1589d7f6fa 100644 --- a/tests/baselines/reference/callWithSpreadES6.js +++ b/tests/baselines/reference/callWithSpreadES6.js @@ -55,12 +55,6 @@ var c = new C(1, 2, ...a); //// [callWithSpreadES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; function foo(x, y, ...z) { } var a; @@ -84,26 +78,23 @@ xa[1].foo(...[ 2, "abc" ]); -var C = (function () { - function C(x, y, ...z) { +class C { + constructor(x, y, ...z) { this.foo(x, y); this.foo(x, y, ...z); } - C.prototype.foo = function (x, y, ...z) { - }; - return C; -})(); -var D = (function (_super) { - __extends(D, _super); - function D() { - _super.call(this, 1, 2); - _super.call(this, 1, 2, ...a); + foo(x, y, ...z) { } - D.prototype.foo = function () { - _super.prototype.foo.call(this, 1, 2); - _super.prototype.foo.call(this, 1, 2, ...a); - }; - return D; -})(C); +} +class D extends C { + constructor() { + super(1, 2); + super(1, 2, ...a); + } + foo() { + super.foo(1, 2); + super.foo(1, 2, ...a); + } +} // Only supported in when target is ES6 var c = new C(1, 2, ...a); diff --git a/tests/baselines/reference/computedPropertyNames12_ES6.js b/tests/baselines/reference/computedPropertyNames12_ES6.js index 5ab6e4c09b3..fd6ccb6e486 100644 --- a/tests/baselines/reference/computedPropertyNames12_ES6.js +++ b/tests/baselines/reference/computedPropertyNames12_ES6.js @@ -20,12 +20,11 @@ class C { var s; var n; var a; -var C = (function () { - function C() { +class C { + constructor() { this[n] = n; this[s + n] = 2; this[`hello bye`] = 0; } - C[`hello ${a} bye`] = 0; - return C; -})(); +} +C[`hello ${a} bye`] = 0; diff --git a/tests/baselines/reference/computedPropertyNames13_ES6.js b/tests/baselines/reference/computedPropertyNames13_ES6.js index 07aa1673aba..18d81fcec59 100644 --- a/tests/baselines/reference/computedPropertyNames13_ES6.js +++ b/tests/baselines/reference/computedPropertyNames13_ES6.js @@ -20,30 +20,27 @@ class C { var s; var n; var a; -var C = (function () { - function C() { +class C { + [s]() { } - C.prototype[s] = function () { - }; - C.prototype[n] = function () { - }; - C[s + s] = function () { - }; - C.prototype[s + n] = function () { - }; - C.prototype[+s] = function () { - }; - C[""] = function () { - }; - C.prototype[0] = function () { - }; - C.prototype[a] = function () { - }; - C[true] = function () { - }; - C.prototype[`hello bye`] = function () { - }; - C[`hello ${a} bye`] = function () { - }; - return C; -})(); + [n]() { + } + static [s + s]() { + } + [s + n]() { + } + [+s]() { + } + static [""]() { + } + [0]() { + } + [a]() { + } + static [true]() { + } + [`hello bye`]() { + } + static [`hello ${a} bye`]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames14_ES6.js b/tests/baselines/reference/computedPropertyNames14_ES6.js index 7a58ad9a80a..b1b2a9bf285 100644 --- a/tests/baselines/reference/computedPropertyNames14_ES6.js +++ b/tests/baselines/reference/computedPropertyNames14_ES6.js @@ -11,20 +11,17 @@ class C { //// [computedPropertyNames14_ES6.js] var b; -var C = (function () { - function C() { +class C { + [b]() { } - C.prototype[b] = function () { - }; - C[true] = function () { - }; - C.prototype[[]] = function () { - }; - C[{}] = function () { - }; - C.prototype[undefined] = function () { - }; - C[null] = function () { - }; - return C; -})(); + static [true]() { + } + [[]]() { + } + static [{}]() { + } + [undefined]() { + } + static [null]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames15_ES6.js b/tests/baselines/reference/computedPropertyNames15_ES6.js index 70c2e7b451c..1a9141ab13d 100644 --- a/tests/baselines/reference/computedPropertyNames15_ES6.js +++ b/tests/baselines/reference/computedPropertyNames15_ES6.js @@ -12,14 +12,11 @@ class C { var p1; var p2; var p3; -var C = (function () { - function C() { +class C { + [p1]() { } - C.prototype[p1] = function () { - }; - C.prototype[p2] = function () { - }; - C.prototype[p3] = function () { - }; - return C; -})(); + [p2]() { + } + [p3]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames16_ES6.js b/tests/baselines/reference/computedPropertyNames16_ES6.js index 90f15f6cf2e..96e175976da 100644 --- a/tests/baselines/reference/computedPropertyNames16_ES6.js +++ b/tests/baselines/reference/computedPropertyNames16_ES6.js @@ -20,80 +20,33 @@ class C { var s; var n; var a; -var C = (function () { - function C() { +class C { + get [s]() { + return 0; } - Object.defineProperty(C.prototype, s, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, n, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, s + s, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, s + n, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, +s, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, "", { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, 0, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, a, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, true, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, `hello bye`, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, `hello ${a} bye`, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + set [n](v) { + } + static get [s + s]() { + return 0; + } + set [s + n](v) { + } + get [+s]() { + return 0; + } + static set [""](v) { + } + get [0]() { + return 0; + } + set [a](v) { + } + static get [true]() { + return 0; + } + set [`hello bye`](v) { + } + get [`hello ${a} bye`]() { + return 0; + } +} diff --git a/tests/baselines/reference/computedPropertyNames17_ES6.js b/tests/baselines/reference/computedPropertyNames17_ES6.js index e9b19202e08..a181a61004e 100644 --- a/tests/baselines/reference/computedPropertyNames17_ES6.js +++ b/tests/baselines/reference/computedPropertyNames17_ES6.js @@ -11,47 +11,20 @@ class C { //// [computedPropertyNames17_ES6.js] var b; -var C = (function () { - function C() { +class C { + get [b]() { + return 0; } - Object.defineProperty(C.prototype, b, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, true, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, [], { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, {}, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, undefined, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, null, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + static set [true](v) { + } + get [[]]() { + return 0; + } + set [{}](v) { + } + static get [undefined]() { + return 0; + } + set [null](v) { + } +} diff --git a/tests/baselines/reference/computedPropertyNames21_ES6.js b/tests/baselines/reference/computedPropertyNames21_ES6.js index f51f6faed24..c5f6b4e22b1 100644 --- a/tests/baselines/reference/computedPropertyNames21_ES6.js +++ b/tests/baselines/reference/computedPropertyNames21_ES6.js @@ -7,13 +7,10 @@ class C { } //// [computedPropertyNames21_ES6.js] -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { return 0; - }; - C.prototype[this.bar()] = function () { - }; - return C; -})(); + } + [this.bar()]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames22_ES6.js b/tests/baselines/reference/computedPropertyNames22_ES6.js index 9872605c20e..c88ceb6bc8f 100644 --- a/tests/baselines/reference/computedPropertyNames22_ES6.js +++ b/tests/baselines/reference/computedPropertyNames22_ES6.js @@ -9,15 +9,12 @@ class C { } //// [computedPropertyNames22_ES6.js] -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { var obj = { [this.bar()]() { } }; return 0; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames23_ES6.js b/tests/baselines/reference/computedPropertyNames23_ES6.js index f5687952b88..0bae1abdad2 100644 --- a/tests/baselines/reference/computedPropertyNames23_ES6.js +++ b/tests/baselines/reference/computedPropertyNames23_ES6.js @@ -9,15 +9,12 @@ class C { } //// [computedPropertyNames23_ES6.js] -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { return 0; - }; - C.prototype[{ + } + [{ [this.bar()]: 1 - }[0]] = function () { - }; - return C; -})(); + }[0]]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames24_ES6.js b/tests/baselines/reference/computedPropertyNames24_ES6.js index 12aef633963..8d33db10f71 100644 --- a/tests/baselines/reference/computedPropertyNames24_ES6.js +++ b/tests/baselines/reference/computedPropertyNames24_ES6.js @@ -11,28 +11,14 @@ class C extends Base { } //// [computedPropertyNames24_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - Base.prototype.bar = function () { +class Base { + bar() { return 0; - }; - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); } +} +class C extends Base { // Gets emitted as super, not _super, which is consistent with // use of super in static properties initializers. - C.prototype[super.bar.call(this)] = function () { - }; - return C; -})(Base); + [super.bar()]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames25_ES6.js b/tests/baselines/reference/computedPropertyNames25_ES6.js index 1a600df5040..cc6a0670b21 100644 --- a/tests/baselines/reference/computedPropertyNames25_ES6.js +++ b/tests/baselines/reference/computedPropertyNames25_ES6.js @@ -14,31 +14,17 @@ class C extends Base { } //// [computedPropertyNames25_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - Base.prototype.bar = function () { +class Base { + bar() { return 0; - }; - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); } - C.prototype.foo = function () { +} +class C extends Base { + foo() { var obj = { - [_super.prototype.bar.call(this)]() { + [super.bar()]() { } }; return 0; - }; - return C; -})(Base); + } +} diff --git a/tests/baselines/reference/computedPropertyNames26_ES6.js b/tests/baselines/reference/computedPropertyNames26_ES6.js index fc53d91e627..4526368de7a 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES6.js +++ b/tests/baselines/reference/computedPropertyNames26_ES6.js @@ -13,30 +13,16 @@ class C extends Base { } //// [computedPropertyNames26_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - Base.prototype.bar = function () { +class Base { + bar() { return 0; - }; - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); } +} +class C extends Base { // Gets emitted as super, not _super, which is consistent with // use of super in static properties initializers. - C.prototype[{ - [super.bar.call(this)]: 1 - }[0]] = function () { - }; - return C; -})(Base); + [{ + [super.bar()]: 1 + }[0]]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames27_ES6.js b/tests/baselines/reference/computedPropertyNames27_ES6.js index 54a20a52200..57589dfcaf5 100644 --- a/tests/baselines/reference/computedPropertyNames27_ES6.js +++ b/tests/baselines/reference/computedPropertyNames27_ES6.js @@ -6,23 +6,9 @@ class C extends Base { } //// [computedPropertyNames27_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { +class Base { +} +class C extends Base { + [(super(), "prop")]() { } - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); - } - C.prototype[(_super.call(this), "prop")] = function () { - }; - return C; -})(Base); +} diff --git a/tests/baselines/reference/computedPropertyNames28_ES6.js b/tests/baselines/reference/computedPropertyNames28_ES6.js index 09e1b33bf98..bc0e32593de 100644 --- a/tests/baselines/reference/computedPropertyNames28_ES6.js +++ b/tests/baselines/reference/computedPropertyNames28_ES6.js @@ -11,25 +11,14 @@ class C extends Base { } //// [computedPropertyNames28_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.call(this); +class Base { +} +class C extends Base { + constructor() { + super(); var obj = { - [(_super.call(this), "prop")]() { + [(super(), "prop")]() { } }; } - return C; -})(Base); +} diff --git a/tests/baselines/reference/computedPropertyNames29_ES6.js b/tests/baselines/reference/computedPropertyNames29_ES6.js index e1e6be51b21..35958b372b0 100644 --- a/tests/baselines/reference/computedPropertyNames29_ES6.js +++ b/tests/baselines/reference/computedPropertyNames29_ES6.js @@ -11,10 +11,8 @@ class C { } //// [computedPropertyNames29_ES6.js] -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { (() => { var obj = { [this.bar()]() { @@ -22,6 +20,5 @@ var C = (function () { }; }); return 0; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames2_ES6.js b/tests/baselines/reference/computedPropertyNames2_ES6.js index e5fcfaac8f9..4287cb2c4b8 100644 --- a/tests/baselines/reference/computedPropertyNames2_ES6.js +++ b/tests/baselines/reference/computedPropertyNames2_ES6.js @@ -13,36 +13,17 @@ class C { //// [computedPropertyNames2_ES6.js] var methodName = "method"; var accessorName = "accessor"; -var C = (function () { - function C() { +class C { + [methodName]() { } - C.prototype[methodName] = function () { - }; - C[methodName] = function () { - }; - Object.defineProperty(C.prototype, accessorName, { - get: function () { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, accessorName, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, accessorName, { - get: function () { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, accessorName, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + static [methodName]() { + } + get [accessorName]() { + } + set [accessorName](v) { + } + static get [accessorName]() { + } + static set [accessorName](v) { + } +} diff --git a/tests/baselines/reference/computedPropertyNames30_ES6.js b/tests/baselines/reference/computedPropertyNames30_ES6.js index c88fa98be5e..cda2a278d47 100644 --- a/tests/baselines/reference/computedPropertyNames30_ES6.js +++ b/tests/baselines/reference/computedPropertyNames30_ES6.js @@ -16,30 +16,19 @@ class C extends Base { } //// [computedPropertyNames30_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.call(this); +class Base { +} +class C extends Base { + constructor() { + super(); (() => { var obj = { // Ideally, we would capture this. But the reference is // illegal, and not capturing this is consistent with //treatment of other similar violations. - [(_super.call(this), "prop")]() { + [(super(), "prop")]() { } }; }); } - return C; -})(Base); +} diff --git a/tests/baselines/reference/computedPropertyNames31_ES6.js b/tests/baselines/reference/computedPropertyNames31_ES6.js index 33f5319ded9..777e03bbcac 100644 --- a/tests/baselines/reference/computedPropertyNames31_ES6.js +++ b/tests/baselines/reference/computedPropertyNames31_ES6.js @@ -16,34 +16,20 @@ class C extends Base { } //// [computedPropertyNames31_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Base = (function () { - function Base() { - } - Base.prototype.bar = function () { +class Base { + bar() { return 0; - }; - return Base; -})(); -var C = (function (_super) { - __extends(C, _super); - function C() { - _super.apply(this, arguments); } - C.prototype.foo = function () { +} +class C extends Base { + foo() { var _this = this; (() => { var obj = { - [_super.prototype.bar.call(_this)]() { + [super.bar()]() { } // needs capture }; }); return 0; - }; - return C; -})(Base); + } +} diff --git a/tests/baselines/reference/computedPropertyNames32_ES6.js b/tests/baselines/reference/computedPropertyNames32_ES6.js index a87f7715d89..198c5e9981e 100644 --- a/tests/baselines/reference/computedPropertyNames32_ES6.js +++ b/tests/baselines/reference/computedPropertyNames32_ES6.js @@ -11,13 +11,10 @@ class C { function foo() { return ''; } -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { return 0; - }; - C.prototype[foo()] = function () { - }; - return C; -})(); + } + [foo()]() { + } +} diff --git a/tests/baselines/reference/computedPropertyNames33_ES6.js b/tests/baselines/reference/computedPropertyNames33_ES6.js index 03c503caec4..7fb08d2852d 100644 --- a/tests/baselines/reference/computedPropertyNames33_ES6.js +++ b/tests/baselines/reference/computedPropertyNames33_ES6.js @@ -13,15 +13,12 @@ class C { function foo() { return ''; } -var C = (function () { - function C() { - } - C.prototype.bar = function () { +class C { + bar() { var obj = { [foo()]() { } }; return 0; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames34_ES6.js b/tests/baselines/reference/computedPropertyNames34_ES6.js index 62e2e151cd3..e73d349bcd7 100644 --- a/tests/baselines/reference/computedPropertyNames34_ES6.js +++ b/tests/baselines/reference/computedPropertyNames34_ES6.js @@ -13,15 +13,12 @@ class C { function foo() { return ''; } -var C = (function () { - function C() { - } - C.bar = function () { +class C { + static bar() { var obj = { [foo()]() { } }; return 0; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames36_ES6.js b/tests/baselines/reference/computedPropertyNames36_ES6.js index 5b71326fbc4..573b8fa0c17 100644 --- a/tests/baselines/reference/computedPropertyNames36_ES6.js +++ b/tests/baselines/reference/computedPropertyNames36_ES6.js @@ -11,32 +11,15 @@ class C { } //// [computedPropertyNames36_ES6.js] -var Foo = (function () { - function Foo() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get ["get1"]() { + return new Foo; } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { + set ["set1"](p) { } - return Foo2; -})(); -var C = (function () { - function C() { - } - Object.defineProperty(C.prototype, "get1", { - // Computed properties - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, "set1", { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/computedPropertyNames37_ES6.js b/tests/baselines/reference/computedPropertyNames37_ES6.js index 992035f6865..d62c95e6f8c 100644 --- a/tests/baselines/reference/computedPropertyNames37_ES6.js +++ b/tests/baselines/reference/computedPropertyNames37_ES6.js @@ -11,32 +11,15 @@ class C { } //// [computedPropertyNames37_ES6.js] -var Foo = (function () { - function Foo() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get ["get1"]() { + return new Foo; } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { + set ["set1"](p) { } - return Foo2; -})(); -var C = (function () { - function C() { - } - Object.defineProperty(C.prototype, "get1", { - // Computed properties - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, "set1", { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/computedPropertyNames38_ES6.js b/tests/baselines/reference/computedPropertyNames38_ES6.js index 0fdcdb1d63c..cf1d01873f2 100644 --- a/tests/baselines/reference/computedPropertyNames38_ES6.js +++ b/tests/baselines/reference/computedPropertyNames38_ES6.js @@ -11,32 +11,15 @@ class C { } //// [computedPropertyNames38_ES6.js] -var Foo = (function () { - function Foo() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get [1 << 6]() { + return new Foo; } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { + set [1 << 6](p) { } - return Foo2; -})(); -var C = (function () { - function C() { - } - Object.defineProperty(C.prototype, 1 << 6, { - // Computed properties - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, 1 << 6, { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/computedPropertyNames39_ES6.js b/tests/baselines/reference/computedPropertyNames39_ES6.js index 8e458ad83d7..9afd60b6464 100644 --- a/tests/baselines/reference/computedPropertyNames39_ES6.js +++ b/tests/baselines/reference/computedPropertyNames39_ES6.js @@ -11,32 +11,15 @@ class C { } //// [computedPropertyNames39_ES6.js] -var Foo = (function () { - function Foo() { +class Foo { +} +class Foo2 { +} +class C { + // Computed properties + get [1 << 6]() { + return new Foo; } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { + set [1 << 6](p) { } - return Foo2; -})(); -var C = (function () { - function C() { - } - Object.defineProperty(C.prototype, 1 << 6, { - // Computed properties - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, 1 << 6, { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/computedPropertyNames3_ES6.errors.txt b/tests/baselines/reference/computedPropertyNames3_ES6.errors.txt index 3df6d6d9744..b9009112347 100644 --- a/tests/baselines/reference/computedPropertyNames3_ES6.errors.txt +++ b/tests/baselines/reference/computedPropertyNames3_ES6.errors.txt @@ -1,12 +1,13 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(5,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. +tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(5,17): error TS1102: 'delete' cannot be called on an identifier in strict mode. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(6,9): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(7,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(7,16): error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. -==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts (6 errors) ==== +==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts (7 errors) ==== var id; class C { [0 + 1]() { } @@ -18,6 +19,8 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames3_ES6.ts(7,1 !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. ~~~~~~~~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. + ~~ +!!! error TS1102: 'delete' cannot be called on an identifier in strict mode. set [[0, 1]](v) { } ~~~~~~~~ !!! error TS2464: A computed property name must be of type 'string', 'number', 'symbol', or 'any'. diff --git a/tests/baselines/reference/computedPropertyNames3_ES6.js b/tests/baselines/reference/computedPropertyNames3_ES6.js index 1a9c9ee465b..b5fb9e88001 100644 --- a/tests/baselines/reference/computedPropertyNames3_ES6.js +++ b/tests/baselines/reference/computedPropertyNames3_ES6.js @@ -11,40 +11,21 @@ class C { //// [computedPropertyNames3_ES6.js] var id; -var C = (function () { - function C() { +class C { + [0 + 1]() { } - C.prototype[0 + 1] = function () { - }; - C[() => { - }] = function () { - }; - Object.defineProperty(C.prototype, delete id, { - get: function () { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, [ + static [() => { + }]() { + } + get [delete id]() { + } + set [[ 0, 1 - ], { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, "", { - get: function () { - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, id.toString(), { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + ]](v) { + } + static get [""]() { + } + static set [id.toString()](v) { + } +} diff --git a/tests/baselines/reference/computedPropertyNames40_ES6.js b/tests/baselines/reference/computedPropertyNames40_ES6.js index 99d28688a29..c4820e0ca98 100644 --- a/tests/baselines/reference/computedPropertyNames40_ES6.js +++ b/tests/baselines/reference/computedPropertyNames40_ES6.js @@ -11,25 +11,16 @@ class C { } //// [computedPropertyNames40_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { - } - return Foo2; -})(); -var C = (function () { - function C() { - } +class Foo { +} +class Foo2 { +} +class C { // Computed properties - C.prototype[""] = function () { + [""]() { return new Foo; - }; - C.prototype[""] = function () { + } + [""]() { return new Foo2; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames41_ES6.js b/tests/baselines/reference/computedPropertyNames41_ES6.js index f0c386706a3..5773f892fd5 100644 --- a/tests/baselines/reference/computedPropertyNames41_ES6.js +++ b/tests/baselines/reference/computedPropertyNames41_ES6.js @@ -10,22 +10,13 @@ class C { } //// [computedPropertyNames41_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { - } - return Foo2; -})(); -var C = (function () { - function C() { - } +class Foo { +} +class Foo2 { +} +class C { // Computed properties - C[""] = function () { + static [""]() { return new Foo; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/computedPropertyNames42_ES6.js b/tests/baselines/reference/computedPropertyNames42_ES6.js index 8538088f450..b6114f06bac 100644 --- a/tests/baselines/reference/computedPropertyNames42_ES6.js +++ b/tests/baselines/reference/computedPropertyNames42_ES6.js @@ -10,18 +10,9 @@ class C { } //// [computedPropertyNames42_ES6.js] -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { - } - return Foo2; -})(); -var C = (function () { - function C() { - } - return C; -})(); +class Foo { +} +class Foo2 { +} +class C { +} diff --git a/tests/baselines/reference/computedPropertyNames43_ES6.js b/tests/baselines/reference/computedPropertyNames43_ES6.js index ba0c228c307..ab9d09834d2 100644 --- a/tests/baselines/reference/computedPropertyNames43_ES6.js +++ b/tests/baselines/reference/computedPropertyNames43_ES6.js @@ -13,45 +13,17 @@ class D extends C { } //// [computedPropertyNames43_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Foo = (function () { - function Foo() { +class Foo { +} +class Foo2 { +} +class C { +} +class D extends C { + // Computed properties + get ["get1"]() { + return new Foo; } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { + set ["set1"](p) { } - return Foo2; -})(); -var C = (function () { - function C() { - } - return C; -})(); -var D = (function (_super) { - __extends(D, _super); - function D() { - _super.apply(this, arguments); - } - Object.defineProperty(D.prototype, "get1", { - // Computed properties - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(D.prototype, "set1", { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return D; -})(C); +} diff --git a/tests/baselines/reference/computedPropertyNames44_ES6.js b/tests/baselines/reference/computedPropertyNames44_ES6.js index 72729054e07..13d46131e92 100644 --- a/tests/baselines/reference/computedPropertyNames44_ES6.js +++ b/tests/baselines/reference/computedPropertyNames44_ES6.js @@ -12,44 +12,16 @@ class D extends C { } //// [computedPropertyNames44_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Foo = (function () { - function Foo() { +class Foo { +} +class Foo2 { +} +class C { + get ["get1"]() { + return new Foo; } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { +} +class D extends C { + set ["set1"](p) { } - return Foo2; -})(); -var C = (function () { - function C() { - } - Object.defineProperty(C.prototype, "get1", { - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - return C; -})(); -var D = (function (_super) { - __extends(D, _super); - function D() { - _super.apply(this, arguments); - } - Object.defineProperty(D.prototype, "set1", { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return D; -})(C); +} diff --git a/tests/baselines/reference/computedPropertyNames45_ES6.js b/tests/baselines/reference/computedPropertyNames45_ES6.js index 23dccc77956..bea5f5211ea 100644 --- a/tests/baselines/reference/computedPropertyNames45_ES6.js +++ b/tests/baselines/reference/computedPropertyNames45_ES6.js @@ -13,44 +13,16 @@ class D extends C { } //// [computedPropertyNames45_ES6.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var Foo = (function () { - function Foo() { +class Foo { +} +class Foo2 { +} +class C { + get ["get1"]() { + return new Foo; } - return Foo; -})(); -var Foo2 = (function () { - function Foo2() { +} +class D extends C { + set ["set1"](p) { } - return Foo2; -})(); -var C = (function () { - function C() { - } - Object.defineProperty(C.prototype, "get1", { - get: function () { - return new Foo; - }, - enumerable: true, - configurable: true - }); - return C; -})(); -var D = (function (_super) { - __extends(D, _super); - function D() { - _super.apply(this, arguments); - } - Object.defineProperty(D.prototype, "set1", { - set: function (p) { - }, - enumerable: true, - configurable: true - }); - return D; -})(C); +} diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit1_ES6.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit1_ES6.js index eb7dab0b660..f234ae0d97e 100644 --- a/tests/baselines/reference/computedPropertyNamesDeclarationEmit1_ES6.js +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit1_ES6.js @@ -6,26 +6,15 @@ class C { } //// [computedPropertyNamesDeclarationEmit1_ES6.js] -var C = (function () { - function C() { +class C { + ["" + ""]() { } - C.prototype["" + ""] = function () { - }; - Object.defineProperty(C.prototype, "" + "", { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, "" + "", { - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + get ["" + ""]() { + return 0; + } + set ["" + ""](x) { + } +} //// [computedPropertyNamesDeclarationEmit1_ES6.d.ts] diff --git a/tests/baselines/reference/computedPropertyNamesDeclarationEmit2_ES6.js b/tests/baselines/reference/computedPropertyNamesDeclarationEmit2_ES6.js index 3912113905c..b5e70193b0d 100644 --- a/tests/baselines/reference/computedPropertyNamesDeclarationEmit2_ES6.js +++ b/tests/baselines/reference/computedPropertyNamesDeclarationEmit2_ES6.js @@ -6,26 +6,15 @@ class C { } //// [computedPropertyNamesDeclarationEmit2_ES6.js] -var C = (function () { - function C() { +class C { + static ["" + ""]() { } - C["" + ""] = function () { - }; - Object.defineProperty(C, "" + "", { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C, "" + "", { - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + static get ["" + ""]() { + return 0; + } + static set ["" + ""](x) { + } +} //// [computedPropertyNamesDeclarationEmit2_ES6.d.ts] diff --git a/tests/baselines/reference/computedPropertyNamesOnOverloads_ES6.js b/tests/baselines/reference/computedPropertyNamesOnOverloads_ES6.js index 264a6a75074..ced0a8d449a 100644 --- a/tests/baselines/reference/computedPropertyNamesOnOverloads_ES6.js +++ b/tests/baselines/reference/computedPropertyNamesOnOverloads_ES6.js @@ -10,10 +10,7 @@ class C { //// [computedPropertyNamesOnOverloads_ES6.js] var methodName = "method"; var accessorName = "accessor"; -var C = (function () { - function C() { +class C { + [methodName](v) { } - C.prototype[methodName] = function (v) { - }; - return C; -})(); +} diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map index c47fcfcad31..3457187e78a 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map @@ -1,2 +1,2 @@ //// [computedPropertyNamesSourceMap1_ES5.js.map] -{"version":3,"file":"computedPropertyNamesSourceMap1_ES5.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES5.ts"],"names":["C","C.constructor","C[\"hello\"]"],"mappings":"AAAA;IAAAA;IAIAC,CAACA;IAHGD,YAACA,OAAOA,CAACA,GAATA;QACIE,QAAQA,CAACA;IACbA,CAACA;IACLF,QAACA;AAADA,CAACA,AAJD,IAIC"} \ No newline at end of file +{"version":3,"file":"computedPropertyNamesSourceMap1_ES5.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES5.ts"],"names":["C","C.constructor","C[\"hello\"]"],"mappings":"AAAA;IAAAA;IAIAC,CAACA;IAHGD,YAACA,OAAOA;QACJE,QAAQA,CAACA;IACbA,CAACA;IACLF,QAACA;AAADA,CAACA,AAJD,IAIC"} \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt index df0af71fb02..be0f79edd17 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt @@ -37,24 +37,18 @@ sourceFile:computedPropertyNamesSourceMap1_ES5.ts 1->^^^^ 2 > ^^^^^^^^^^^^ 3 > ^^^^^^^ -4 > ^ -5 > ^^^ 1-> 2 > [ 3 > "hello" -4 > ] -5 > 1->Emitted(4, 5) Source(2, 5) + SourceIndex(0) name (C) 2 >Emitted(4, 17) Source(2, 6) + SourceIndex(0) name (C) 3 >Emitted(4, 24) Source(2, 13) + SourceIndex(0) name (C) -4 >Emitted(4, 25) Source(2, 14) + SourceIndex(0) name (C) -5 >Emitted(4, 28) Source(2, 5) + SourceIndex(0) name (C) --- >>> debugger; 1 >^^^^^^^^ 2 > ^^^^^^^^ 3 > ^ -1 >["hello"]() { +1 >]() { > 2 > debugger 3 > ; diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js index f7dc9e17836..749ab99b18b 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js @@ -6,12 +6,9 @@ class C { } //// [computedPropertyNamesSourceMap1_ES6.js] -var C = (function () { - function C() { - } - C.prototype["hello"] = function () { +class C { + ["hello"]() { debugger; - }; - return C; -})(); + } +} //# sourceMappingURL=computedPropertyNamesSourceMap1_ES6.js.map \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map index 20765a5b2d4..ff47df55493 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map @@ -1,2 +1,2 @@ //// [computedPropertyNamesSourceMap1_ES6.js.map] -{"version":3,"file":"computedPropertyNamesSourceMap1_ES6.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES6.ts"],"names":["C","C.constructor","C[\"hello\"]"],"mappings":"AAAA;IAAAA;IAIAC,CAACA;IAHGD,YAACA,OAAOA,CAACA,GAATA;QACIE,QAAQA,CAACA;IACbA,CAACA;IACLF,QAACA;AAADA,CAACA,AAJD,IAIC"} \ No newline at end of file +{"version":3,"file":"computedPropertyNamesSourceMap1_ES6.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES6.ts"],"names":["C","C[\"hello\"]"],"mappings":"AAAA;IACIA,CAACA,OAAOA;QACJC,QAAQA,CAACA;IACbA,CAACA;AACLD,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt index 64713447e43..36535c1aa4f 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt @@ -8,96 +8,58 @@ sources: computedPropertyNamesSourceMap1_ES6.ts emittedFile:tests/cases/conformance/es6/computedProperties/computedPropertyNamesSourceMap1_ES6.js sourceFile:computedPropertyNamesSourceMap1_ES6.ts ------------------------------------------------------------------- ->>>var C = (function () { +>>>class C { 1 > -2 >^^^^^^^^^^^^^^^^^^^-> +2 >^^^^^^^^^^^^^^^^^^-> 1 > 1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0) --- ->>> function C() { -1->^^^^ -2 > ^^-> -1-> -1->Emitted(2, 5) Source(1, 1) + SourceIndex(0) name (C) ---- ->>> } +>>> ["hello"]() { 1->^^^^ 2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^^^ +4 > ^^^^^^-> 1->class C { - > ["hello"]() { - > debugger; - > } - > -2 > } -1->Emitted(3, 5) Source(5, 1) + SourceIndex(0) name (C.constructor) -2 >Emitted(3, 6) Source(5, 2) + SourceIndex(0) name (C.constructor) ---- ->>> C.prototype["hello"] = function () { -1->^^^^ -2 > ^^^^^^^^^^^^ -3 > ^^^^^^^ -4 > ^ -5 > ^^^ -1-> + > 2 > [ -3 > "hello" -4 > ] -5 > -1->Emitted(4, 5) Source(2, 5) + SourceIndex(0) name (C) -2 >Emitted(4, 17) Source(2, 6) + SourceIndex(0) name (C) -3 >Emitted(4, 24) Source(2, 13) + SourceIndex(0) name (C) -4 >Emitted(4, 25) Source(2, 14) + SourceIndex(0) name (C) -5 >Emitted(4, 28) Source(2, 5) + SourceIndex(0) name (C) +3 > "hello" +1->Emitted(2, 5) Source(2, 5) + SourceIndex(0) name (C) +2 >Emitted(2, 6) Source(2, 6) + SourceIndex(0) name (C) +3 >Emitted(2, 13) Source(2, 13) + SourceIndex(0) name (C) --- >>> debugger; -1 >^^^^^^^^ +1->^^^^^^^^ 2 > ^^^^^^^^ 3 > ^ -1 >["hello"]() { +1->]() { > 2 > debugger 3 > ; -1 >Emitted(5, 9) Source(3, 9) + SourceIndex(0) name (C["hello"]) -2 >Emitted(5, 17) Source(3, 17) + SourceIndex(0) name (C["hello"]) -3 >Emitted(5, 18) Source(3, 18) + SourceIndex(0) name (C["hello"]) +1->Emitted(3, 9) Source(3, 9) + SourceIndex(0) name (C["hello"]) +2 >Emitted(3, 17) Source(3, 17) + SourceIndex(0) name (C["hello"]) +3 >Emitted(3, 18) Source(3, 18) + SourceIndex(0) name (C["hello"]) --- ->>> }; +>>> } 1 >^^^^ 2 > ^ -3 > ^^^^^^^^^-> 1 > > 2 > } -1 >Emitted(6, 5) Source(4, 5) + SourceIndex(0) name (C["hello"]) -2 >Emitted(6, 6) Source(4, 6) + SourceIndex(0) name (C["hello"]) +1 >Emitted(4, 5) Source(4, 5) + SourceIndex(0) name (C["hello"]) +2 >Emitted(4, 6) Source(4, 6) + SourceIndex(0) name (C["hello"]) --- ->>> return C; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(5, 1) + SourceIndex(0) name (C) -2 >Emitted(7, 13) Source(5, 2) + SourceIndex(0) name (C) ---- ->>>})(); +>>>} 1 > 2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > 2 >} -3 > -4 > class C { - > ["hello"]() { - > debugger; - > } - > } -1 >Emitted(8, 1) Source(5, 1) + SourceIndex(0) name (C) -2 >Emitted(8, 2) Source(5, 2) + SourceIndex(0) name (C) -3 >Emitted(8, 2) Source(1, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(5, 2) + SourceIndex(0) +1 >Emitted(5, 1) Source(5, 1) + SourceIndex(0) name (C) +2 >Emitted(5, 2) Source(5, 2) + SourceIndex(0) name (C) --- ->>>//# sourceMappingURL=computedPropertyNamesSourceMap1_ES6.js.map \ No newline at end of file +>>>//# sourceMappingURL=computedPropertyNamesSourceMap1_ES6.js.map1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> +1->Emitted(6, 1) Source(5, 2) + SourceIndex(0) +--- \ No newline at end of file diff --git a/tests/baselines/reference/constDeclarations-scopes.js b/tests/baselines/reference/constDeclarations-scopes.js index f8fbc47312b..b144b4f83a5 100644 --- a/tests/baselines/reference/constDeclarations-scopes.js +++ b/tests/baselines/reference/constDeclarations-scopes.js @@ -242,30 +242,25 @@ var m; } })(m || (m = {})); // methods -var C = (function () { - function C() { +class C { + constructor() { const c = 0; n = c; } - C.prototype.method = function () { + method() { const c = 0; n = c; - }; - Object.defineProperty(C.prototype, "v", { - get: function () { - const c = 0; - n = c; - return n; - }, - set: function (value) { - const c = 0; - n = c; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + } + get v() { + const c = 0; + n = c; + return n; + } + set v(value) { + const c = 0; + n = c; + } +} // object literals var o = { f() { diff --git a/tests/baselines/reference/constDeclarations-validContexts.js b/tests/baselines/reference/constDeclarations-validContexts.js index 5a54e915713..7d3269c6683 100644 --- a/tests/baselines/reference/constDeclarations-validContexts.js +++ b/tests/baselines/reference/constDeclarations-validContexts.js @@ -201,26 +201,21 @@ var m; } })(m || (m = {})); // methods -var C = (function () { - function C() { +class C { + constructor() { const c24 = 0; } - C.prototype.method = function () { + method() { const c25 = 0; - }; - Object.defineProperty(C.prototype, "v", { - get: function () { - const c26 = 0; - return c26; - }, - set: function (value) { - const c27 = value; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + } + get v() { + const c26 = 0; + return c26; + } + set v(value) { + const c27 = value; + } +} // object literals var o = { f() { diff --git a/tests/baselines/reference/destructuringParameterProperties4.js b/tests/baselines/reference/destructuringParameterProperties4.js index 6da6f53a4fe..cd6334c8568 100644 --- a/tests/baselines/reference/destructuringParameterProperties4.js +++ b/tests/baselines/reference/destructuringParameterProperties4.js @@ -28,38 +28,26 @@ class C2 extends C1 { //// [destructuringParameterProperties4.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function () { - function C1(k, [a, b, c]) { +class C1 { + constructor(k, [a, b, c]) { this.k = k; this.[a, b, c] = [a, b, c]; if ((b === undefined && c === undefined) || (this.b === undefined && this.c === undefined)) { this.a = a || k; } } - C1.prototype.getA = function () { + getA() { return this.a; - }; - C1.prototype.getB = function () { - return this.b; - }; - C1.prototype.getC = function () { - return this.c; - }; - return C1; -})(); -var C2 = (function (_super) { - __extends(C2, _super); - function C2() { - _super.apply(this, arguments); } - C2.prototype.doSomethingWithSuperProperties = function () { + getB() { + return this.b; + } + getC() { + return this.c; + } +} +class C2 extends C1 { + doSomethingWithSuperProperties() { return `${this.a} ${this.b} ${this.c}`; - }; - return C2; -})(C1); + } +} diff --git a/tests/baselines/reference/emitDefaultParametersMethodES6.js b/tests/baselines/reference/emitDefaultParametersMethodES6.js index bf96e00e375..3981ddcba3c 100644 --- a/tests/baselines/reference/emitDefaultParametersMethodES6.js +++ b/tests/baselines/reference/emitDefaultParametersMethodES6.js @@ -17,26 +17,23 @@ class E { } //// [emitDefaultParametersMethodES6.js] -var C = (function () { - function C(t, z, x, y = "hello") { +class C { + constructor(t, z, x, y = "hello") { } - C.prototype.foo = function (x, t = false) { - }; - C.prototype.foo1 = function (x, t = false, ...rest) { - }; - C.prototype.bar = function (t = false) { - }; - C.prototype.boo = function (t = false, ...rest) { - }; - return C; -})(); -var D = (function () { - function D(y = "hello") { + foo(x, t = false) { } - return D; -})(); -var E = (function () { - function E(y = "hello", ...rest) { + foo1(x, t = false, ...rest) { } - return E; -})(); + bar(t = false) { + } + boo(t = false, ...rest) { + } +} +class D { + constructor(y = "hello") { + } +} +class E { + constructor(y = "hello", ...rest) { + } +} diff --git a/tests/baselines/reference/emitRestParametersMethodES6.js b/tests/baselines/reference/emitRestParametersMethodES6.js index d0a0e2a120c..fba6ed01e67 100644 --- a/tests/baselines/reference/emitRestParametersMethodES6.js +++ b/tests/baselines/reference/emitRestParametersMethodES6.js @@ -15,21 +15,19 @@ class D { //// [emitRestParametersMethodES6.js] -var C = (function () { - function C(name, ...rest) { +class C { + constructor(name, ...rest) { } - C.prototype.bar = function (...rest) { - }; - C.prototype.foo = function (x, ...rest) { - }; - return C; -})(); -var D = (function () { - function D(...rest) { + bar(...rest) { } - D.prototype.bar = function (...rest) { - }; - D.prototype.foo = function (x, ...rest) { - }; - return D; -})(); + foo(x, ...rest) { + } +} +class D { + constructor(...rest) { + } + bar(...rest) { + } + foo(x, ...rest) { + } +} From c70385c2573e230742aa3be04aa9a1e7158b212f Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 15 Mar 2015 21:27:54 -0700 Subject: [PATCH 18/26] Update baselines --- tests/baselines/reference/for-of14.js | 11 ++++------- tests/baselines/reference/for-of15.js | 15 ++++++--------- tests/baselines/reference/for-of16.js | 11 ++++------- tests/baselines/reference/for-of17.js | 15 ++++++--------- tests/baselines/reference/for-of18.js | 15 ++++++--------- tests/baselines/reference/for-of19.js | 22 ++++++++-------------- tests/baselines/reference/for-of20.js | 22 ++++++++-------------- tests/baselines/reference/for-of21.js | 22 ++++++++-------------- tests/baselines/reference/for-of22.js | 22 ++++++++-------------- tests/baselines/reference/for-of23.js | 22 ++++++++-------------- tests/baselines/reference/for-of25.js | 11 ++++------- tests/baselines/reference/for-of26.js | 15 ++++++--------- tests/baselines/reference/for-of27.js | 7 ++----- tests/baselines/reference/for-of28.js | 11 ++++------- tests/baselines/reference/for-of30.js | 15 +++++++-------- tests/baselines/reference/for-of31.js | 15 ++++++--------- tests/baselines/reference/for-of33.js | 11 ++++------- tests/baselines/reference/for-of34.js | 15 ++++++--------- tests/baselines/reference/for-of35.js | 15 ++++++--------- 19 files changed, 111 insertions(+), 181 deletions(-) diff --git a/tests/baselines/reference/for-of14.js b/tests/baselines/reference/for-of14.js index 65ac7119fb6..958e621c8aa 100644 --- a/tests/baselines/reference/for-of14.js +++ b/tests/baselines/reference/for-of14.js @@ -12,11 +12,8 @@ class StringIterator { var v; for (v of new StringIterator) { } // Should fail because the iterator is not iterable -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return ""; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of15.js b/tests/baselines/reference/for-of15.js index 74e34c2b2ae..2b4846ec8be 100644 --- a/tests/baselines/reference/for-of15.js +++ b/tests/baselines/reference/for-of15.js @@ -15,14 +15,11 @@ class StringIterator { var v; for (v of new StringIterator) { } // Should fail -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return ""; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of16.js b/tests/baselines/reference/for-of16.js index 526dc277be7..1cdf72c26ac 100644 --- a/tests/baselines/reference/for-of16.js +++ b/tests/baselines/reference/for-of16.js @@ -12,11 +12,8 @@ class StringIterator { var v; for (v of new StringIterator) { } // Should fail -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype[Symbol.iterator] = function () { +class StringIterator { + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of17.js b/tests/baselines/reference/for-of17.js index 268ead7ee18..3fb4fac91d6 100644 --- a/tests/baselines/reference/for-of17.js +++ b/tests/baselines/reference/for-of17.js @@ -18,17 +18,14 @@ class NumberIterator { var v; for (v of new NumberIterator) { } // Should succeed -var NumberIterator = (function () { - function NumberIterator() { - } - NumberIterator.prototype.next = function () { +class NumberIterator { + next() { return { value: 0, done: false }; - }; - NumberIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return NumberIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of18.js b/tests/baselines/reference/for-of18.js index 3be876409dc..ae3a9e130f0 100644 --- a/tests/baselines/reference/for-of18.js +++ b/tests/baselines/reference/for-of18.js @@ -18,17 +18,14 @@ class StringIterator { var v; for (v of new StringIterator) { } // Should succeed -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return { value: "", done: false }; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of19.js b/tests/baselines/reference/for-of19.js index eefb9339f18..d0f95caa1e2 100644 --- a/tests/baselines/reference/for-of19.js +++ b/tests/baselines/reference/for-of19.js @@ -20,22 +20,16 @@ class FooIterator { for (var v of new FooIterator) { v; } -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var FooIterator = (function () { - function FooIterator() { - } - FooIterator.prototype.next = function () { +class Foo { +} +class FooIterator { + next() { return { value: new Foo, done: false }; - }; - FooIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return FooIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of20.js b/tests/baselines/reference/for-of20.js index 39b1081954b..c098abd2f73 100644 --- a/tests/baselines/reference/for-of20.js +++ b/tests/baselines/reference/for-of20.js @@ -20,22 +20,16 @@ class FooIterator { for (let v of new FooIterator) { v; } -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var FooIterator = (function () { - function FooIterator() { - } - FooIterator.prototype.next = function () { +class Foo { +} +class FooIterator { + next() { return { value: new Foo, done: false }; - }; - FooIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return FooIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of21.js b/tests/baselines/reference/for-of21.js index 5deaad3c2d8..27da28e3b4f 100644 --- a/tests/baselines/reference/for-of21.js +++ b/tests/baselines/reference/for-of21.js @@ -20,22 +20,16 @@ class FooIterator { for (const v of new FooIterator) { v; } -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var FooIterator = (function () { - function FooIterator() { - } - FooIterator.prototype.next = function () { +class Foo { +} +class FooIterator { + next() { return { value: new Foo, done: false }; - }; - FooIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return FooIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of22.js b/tests/baselines/reference/for-of22.js index d38accb6cd8..886e8dba7c3 100644 --- a/tests/baselines/reference/for-of22.js +++ b/tests/baselines/reference/for-of22.js @@ -21,22 +21,16 @@ class FooIterator { v; for (var v of new FooIterator) { } -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var FooIterator = (function () { - function FooIterator() { - } - FooIterator.prototype.next = function () { +class Foo { +} +class FooIterator { + next() { return { value: new Foo, done: false }; - }; - FooIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return FooIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of23.js b/tests/baselines/reference/for-of23.js index 87bb1fd428d..f5649128c11 100644 --- a/tests/baselines/reference/for-of23.js +++ b/tests/baselines/reference/for-of23.js @@ -20,22 +20,16 @@ class FooIterator { for (const v of new FooIterator) { const v = 0; // new scope } -var Foo = (function () { - function Foo() { - } - return Foo; -})(); -var FooIterator = (function () { - function FooIterator() { - } - FooIterator.prototype.next = function () { +class Foo { +} +class FooIterator { + next() { return { value: new Foo, done: false }; - }; - FooIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return FooIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of25.js b/tests/baselines/reference/for-of25.js index 86c175f861e..2c85a4dc2fd 100644 --- a/tests/baselines/reference/for-of25.js +++ b/tests/baselines/reference/for-of25.js @@ -12,11 +12,8 @@ class StringIterator { var x; for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype[Symbol.iterator] = function () { +class StringIterator { + [Symbol.iterator]() { return x; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of26.js b/tests/baselines/reference/for-of26.js index edb6b4c38b2..e048caf1006 100644 --- a/tests/baselines/reference/for-of26.js +++ b/tests/baselines/reference/for-of26.js @@ -15,14 +15,11 @@ class StringIterator { var x; for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return x; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of27.js b/tests/baselines/reference/for-of27.js index 379b95c5b09..8b44ca03ef4 100644 --- a/tests/baselines/reference/for-of27.js +++ b/tests/baselines/reference/for-of27.js @@ -8,8 +8,5 @@ class StringIterator { //// [for-of27.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - return StringIterator; -})(); +class StringIterator { +} diff --git a/tests/baselines/reference/for-of28.js b/tests/baselines/reference/for-of28.js index 79b1590e12f..69c8ccab727 100644 --- a/tests/baselines/reference/for-of28.js +++ b/tests/baselines/reference/for-of28.js @@ -11,11 +11,8 @@ class StringIterator { //// [for-of28.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype[Symbol.iterator] = function () { +class StringIterator { + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of30.js b/tests/baselines/reference/for-of30.js index 759c7823e63..0ed6caaf81e 100644 --- a/tests/baselines/reference/for-of30.js +++ b/tests/baselines/reference/for-of30.js @@ -19,18 +19,17 @@ class StringIterator { //// [for-of30.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { +class StringIterator { + constructor() { this.return = 0; } - StringIterator.prototype.next = function () { + next() { return { done: false, value: "" }; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of31.js b/tests/baselines/reference/for-of31.js index 6773c8a3452..d38c1fa017d 100644 --- a/tests/baselines/reference/for-of31.js +++ b/tests/baselines/reference/for-of31.js @@ -17,17 +17,14 @@ class StringIterator { //// [for-of31.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return { // no done property value: "" }; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of33.js b/tests/baselines/reference/for-of33.js index f3a75eec137..66097f777c8 100644 --- a/tests/baselines/reference/for-of33.js +++ b/tests/baselines/reference/for-of33.js @@ -10,11 +10,8 @@ class StringIterator { //// [for-of33.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype[Symbol.iterator] = function () { +class StringIterator { + [Symbol.iterator]() { return v; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of34.js b/tests/baselines/reference/for-of34.js index 521b4f3c2a4..568a9f73535 100644 --- a/tests/baselines/reference/for-of34.js +++ b/tests/baselines/reference/for-of34.js @@ -14,14 +14,11 @@ class StringIterator { //// [for-of34.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return v; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} diff --git a/tests/baselines/reference/for-of35.js b/tests/baselines/reference/for-of35.js index cb6dc0e532f..a157d5e2e8e 100644 --- a/tests/baselines/reference/for-of35.js +++ b/tests/baselines/reference/for-of35.js @@ -17,17 +17,14 @@ class StringIterator { //// [for-of35.js] for (var v of new StringIterator) { } -var StringIterator = (function () { - function StringIterator() { - } - StringIterator.prototype.next = function () { +class StringIterator { + next() { return { done: true, value: v }; - }; - StringIterator.prototype[Symbol.iterator] = function () { + } + [Symbol.iterator]() { return this; - }; - return StringIterator; -})(); + } +} From 3bb4b50b4fe5b7424087732329a34e9ce91d9b7e Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 15 Mar 2015 21:33:39 -0700 Subject: [PATCH 19/26] Update baselines for symbol --- tests/baselines/reference/symbolProperty10.js | 7 ++--- tests/baselines/reference/symbolProperty11.js | 7 ++--- tests/baselines/reference/symbolProperty12.js | 7 ++--- tests/baselines/reference/symbolProperty13.js | 7 ++--- tests/baselines/reference/symbolProperty14.js | 7 ++--- tests/baselines/reference/symbolProperty15.js | 7 ++--- tests/baselines/reference/symbolProperty16.js | 7 ++--- tests/baselines/reference/symbolProperty23.js | 11 +++----- tests/baselines/reference/symbolProperty24.js | 11 +++----- tests/baselines/reference/symbolProperty25.js | 11 +++----- tests/baselines/reference/symbolProperty26.js | 28 +++++-------------- tests/baselines/reference/symbolProperty27.js | 28 +++++-------------- tests/baselines/reference/symbolProperty28.js | 24 ++++------------ tests/baselines/reference/symbolProperty29.js | 11 +++----- tests/baselines/reference/symbolProperty30.js | 11 +++----- tests/baselines/reference/symbolProperty31.js | 24 ++++------------ tests/baselines/reference/symbolProperty32.js | 24 ++++------------ tests/baselines/reference/symbolProperty33.js | 24 ++++------------ tests/baselines/reference/symbolProperty34.js | 24 ++++------------ tests/baselines/reference/symbolProperty39.js | 15 ++++------ tests/baselines/reference/symbolProperty40.js | 11 +++----- tests/baselines/reference/symbolProperty41.js | 11 +++----- tests/baselines/reference/symbolProperty42.js | 11 +++----- tests/baselines/reference/symbolProperty43.js | 7 ++--- tests/baselines/reference/symbolProperty44.js | 15 +++------- tests/baselines/reference/symbolProperty45.js | 25 +++++------------ tests/baselines/reference/symbolProperty46.js | 21 +++++--------- tests/baselines/reference/symbolProperty47.js | 21 +++++--------- tests/baselines/reference/symbolProperty48.js | 9 ++---- tests/baselines/reference/symbolProperty49.js | 9 ++---- tests/baselines/reference/symbolProperty50.js | 9 ++---- tests/baselines/reference/symbolProperty51.js | 9 ++---- tests/baselines/reference/symbolProperty6.js | 21 ++++++-------- tests/baselines/reference/symbolProperty7.js | 21 ++++++-------- tests/baselines/reference/symbolProperty9.js | 7 ++--- 35 files changed, 148 insertions(+), 354 deletions(-) diff --git a/tests/baselines/reference/symbolProperty10.js b/tests/baselines/reference/symbolProperty10.js index 5b4e44f11ab..74bcf886461 100644 --- a/tests/baselines/reference/symbolProperty10.js +++ b/tests/baselines/reference/symbolProperty10.js @@ -11,11 +11,8 @@ i = new C; var c: C = i; //// [symbolProperty10.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} var i; i = new C; var c = i; diff --git a/tests/baselines/reference/symbolProperty11.js b/tests/baselines/reference/symbolProperty11.js index 83a380c79e7..97fa4fc992f 100644 --- a/tests/baselines/reference/symbolProperty11.js +++ b/tests/baselines/reference/symbolProperty11.js @@ -9,11 +9,8 @@ i = new C; var c: C = i; //// [symbolProperty11.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} var i; i = new C; var c = i; diff --git a/tests/baselines/reference/symbolProperty12.js b/tests/baselines/reference/symbolProperty12.js index 9f63f86bc18..474ec4a0ffa 100644 --- a/tests/baselines/reference/symbolProperty12.js +++ b/tests/baselines/reference/symbolProperty12.js @@ -11,11 +11,8 @@ i = new C; var c: C = i; //// [symbolProperty12.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} var i; i = new C; var c = i; diff --git a/tests/baselines/reference/symbolProperty13.js b/tests/baselines/reference/symbolProperty13.js index 1cf24a49c7e..d7620d01159 100644 --- a/tests/baselines/reference/symbolProperty13.js +++ b/tests/baselines/reference/symbolProperty13.js @@ -17,11 +17,8 @@ var i: I; bar(i); //// [symbolProperty13.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} foo(new C); var i; bar(i); diff --git a/tests/baselines/reference/symbolProperty14.js b/tests/baselines/reference/symbolProperty14.js index 0283cb01b79..716bc68b430 100644 --- a/tests/baselines/reference/symbolProperty14.js +++ b/tests/baselines/reference/symbolProperty14.js @@ -17,11 +17,8 @@ var i: I; bar(i); //// [symbolProperty14.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} foo(new C); var i; bar(i); diff --git a/tests/baselines/reference/symbolProperty15.js b/tests/baselines/reference/symbolProperty15.js index 0c198037093..dec61964252 100644 --- a/tests/baselines/reference/symbolProperty15.js +++ b/tests/baselines/reference/symbolProperty15.js @@ -15,11 +15,8 @@ var i: I; bar(i); //// [symbolProperty15.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} foo(new C); var i; bar(i); diff --git a/tests/baselines/reference/symbolProperty16.js b/tests/baselines/reference/symbolProperty16.js index 1a1f3f857af..1382d913104 100644 --- a/tests/baselines/reference/symbolProperty16.js +++ b/tests/baselines/reference/symbolProperty16.js @@ -17,11 +17,8 @@ var i: I; bar(i); //// [symbolProperty16.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} foo(new C); var i; bar(i); diff --git a/tests/baselines/reference/symbolProperty23.js b/tests/baselines/reference/symbolProperty23.js index b3291ad34e8..3210f6dfed7 100644 --- a/tests/baselines/reference/symbolProperty23.js +++ b/tests/baselines/reference/symbolProperty23.js @@ -10,11 +10,8 @@ class C implements I { } //// [symbolProperty23.js] -var C = (function () { - function C() { - } - C.prototype[Symbol.toPrimitive] = function () { +class C { + [Symbol.toPrimitive]() { return true; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/symbolProperty24.js b/tests/baselines/reference/symbolProperty24.js index b5d059dd29f..3d582d80254 100644 --- a/tests/baselines/reference/symbolProperty24.js +++ b/tests/baselines/reference/symbolProperty24.js @@ -10,11 +10,8 @@ class C implements I { } //// [symbolProperty24.js] -var C = (function () { - function C() { - } - C.prototype[Symbol.toPrimitive] = function () { +class C { + [Symbol.toPrimitive]() { return ""; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/symbolProperty25.js b/tests/baselines/reference/symbolProperty25.js index c932da1e3eb..33c398a6c0e 100644 --- a/tests/baselines/reference/symbolProperty25.js +++ b/tests/baselines/reference/symbolProperty25.js @@ -10,11 +10,8 @@ class C implements I { } //// [symbolProperty25.js] -var C = (function () { - function C() { - } - C.prototype[Symbol.toStringTag] = function () { +class C { + [Symbol.toStringTag]() { return ""; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/symbolProperty26.js b/tests/baselines/reference/symbolProperty26.js index 9e98027603d..837ef5837b0 100644 --- a/tests/baselines/reference/symbolProperty26.js +++ b/tests/baselines/reference/symbolProperty26.js @@ -12,27 +12,13 @@ class C2 extends C1 { } //// [symbolProperty26.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function () { - function C1() { - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 { + [Symbol.toStringTag]() { return ""; - }; - return C1; -})(); -var C2 = (function (_super) { - __extends(C2, _super); - function C2() { - _super.apply(this, arguments); } - C2.prototype[Symbol.toStringTag] = function () { +} +class C2 extends C1 { + [Symbol.toStringTag]() { return ""; - }; - return C2; -})(C1); + } +} diff --git a/tests/baselines/reference/symbolProperty27.js b/tests/baselines/reference/symbolProperty27.js index f19d05233cb..d4eb6fcafa7 100644 --- a/tests/baselines/reference/symbolProperty27.js +++ b/tests/baselines/reference/symbolProperty27.js @@ -12,27 +12,13 @@ class C2 extends C1 { } //// [symbolProperty27.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function () { - function C1() { - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 { + [Symbol.toStringTag]() { return {}; - }; - return C1; -})(); -var C2 = (function (_super) { - __extends(C2, _super); - function C2() { - _super.apply(this, arguments); } - C2.prototype[Symbol.toStringTag] = function () { +} +class C2 extends C1 { + [Symbol.toStringTag]() { return ""; - }; - return C2; -})(C1); + } +} diff --git a/tests/baselines/reference/symbolProperty28.js b/tests/baselines/reference/symbolProperty28.js index 57c826cb7ab..ed53a88f957 100644 --- a/tests/baselines/reference/symbolProperty28.js +++ b/tests/baselines/reference/symbolProperty28.js @@ -11,28 +11,14 @@ var c: C2; var obj = c[Symbol.toStringTag]().x; //// [symbolProperty28.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function () { - function C1() { - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 { + [Symbol.toStringTag]() { return { x: "" }; - }; - return C1; -})(); -var C2 = (function (_super) { - __extends(C2, _super); - function C2() { - _super.apply(this, arguments); } - return C2; -})(C1); +} +class C2 extends C1 { +} var c; var obj = c[Symbol.toStringTag]().x; diff --git a/tests/baselines/reference/symbolProperty29.js b/tests/baselines/reference/symbolProperty29.js index da6afdc6420..759a7754826 100644 --- a/tests/baselines/reference/symbolProperty29.js +++ b/tests/baselines/reference/symbolProperty29.js @@ -7,13 +7,10 @@ class C1 { } //// [symbolProperty29.js] -var C1 = (function () { - function C1() { - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 { + [Symbol.toStringTag]() { return { x: "" }; - }; - return C1; -})(); + } +} diff --git a/tests/baselines/reference/symbolProperty30.js b/tests/baselines/reference/symbolProperty30.js index af151e0efd5..263fdc1041b 100644 --- a/tests/baselines/reference/symbolProperty30.js +++ b/tests/baselines/reference/symbolProperty30.js @@ -7,13 +7,10 @@ class C1 { } //// [symbolProperty30.js] -var C1 = (function () { - function C1() { - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 { + [Symbol.toStringTag]() { return { x: "" }; - }; - return C1; -})(); + } +} diff --git a/tests/baselines/reference/symbolProperty31.js b/tests/baselines/reference/symbolProperty31.js index e8388225dd7..a9db50061b3 100644 --- a/tests/baselines/reference/symbolProperty31.js +++ b/tests/baselines/reference/symbolProperty31.js @@ -9,26 +9,12 @@ class C2 extends C1 { } //// [symbolProperty31.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function () { - function C1() { - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 { + [Symbol.toStringTag]() { return { x: "" }; - }; - return C1; -})(); -var C2 = (function (_super) { - __extends(C2, _super); - function C2() { - _super.apply(this, arguments); } - return C2; -})(C1); +} +class C2 extends C1 { +} diff --git a/tests/baselines/reference/symbolProperty32.js b/tests/baselines/reference/symbolProperty32.js index b544c60da7e..52db43bb9de 100644 --- a/tests/baselines/reference/symbolProperty32.js +++ b/tests/baselines/reference/symbolProperty32.js @@ -9,26 +9,12 @@ class C2 extends C1 { } //// [symbolProperty32.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function () { - function C1() { - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 { + [Symbol.toStringTag]() { return { x: "" }; - }; - return C1; -})(); -var C2 = (function (_super) { - __extends(C2, _super); - function C2() { - _super.apply(this, arguments); } - return C2; -})(C1); +} +class C2 extends C1 { +} diff --git a/tests/baselines/reference/symbolProperty33.js b/tests/baselines/reference/symbolProperty33.js index 082c0fe7e65..8a0e3f691b5 100644 --- a/tests/baselines/reference/symbolProperty33.js +++ b/tests/baselines/reference/symbolProperty33.js @@ -9,26 +9,12 @@ class C2 { } //// [symbolProperty33.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function (_super) { - __extends(C1, _super); - function C1() { - _super.apply(this, arguments); - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 extends C2 { + [Symbol.toStringTag]() { return { x: "" }; - }; - return C1; -})(C2); -var C2 = (function () { - function C2() { } - return C2; -})(); +} +class C2 { +} diff --git a/tests/baselines/reference/symbolProperty34.js b/tests/baselines/reference/symbolProperty34.js index de7d722227b..b8bcd54487f 100644 --- a/tests/baselines/reference/symbolProperty34.js +++ b/tests/baselines/reference/symbolProperty34.js @@ -9,26 +9,12 @@ class C2 { } //// [symbolProperty34.js] -var __extends = this.__extends || function (d, b) { - for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; - function __() { this.constructor = d; } - __.prototype = b.prototype; - d.prototype = new __(); -}; -var C1 = (function (_super) { - __extends(C1, _super); - function C1() { - _super.apply(this, arguments); - } - C1.prototype[Symbol.toStringTag] = function () { +class C1 extends C2 { + [Symbol.toStringTag]() { return { x: "" }; - }; - return C1; -})(C2); -var C2 = (function () { - function C2() { } - return C2; -})(); +} +class C2 { +} diff --git a/tests/baselines/reference/symbolProperty39.js b/tests/baselines/reference/symbolProperty39.js index 18551d20c0b..6454d4a983f 100644 --- a/tests/baselines/reference/symbolProperty39.js +++ b/tests/baselines/reference/symbolProperty39.js @@ -11,14 +11,11 @@ class C { } //// [symbolProperty39.js] -var C = (function () { - function C() { +class C { + [Symbol.iterator](x) { + return undefined; } - C.prototype[Symbol.iterator] = function (x) { + [Symbol.iterator](x) { return undefined; - }; - C.prototype[Symbol.iterator] = function (x) { - return undefined; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/symbolProperty40.js b/tests/baselines/reference/symbolProperty40.js index 15d8c5c6fba..cf5a3c4396d 100644 --- a/tests/baselines/reference/symbolProperty40.js +++ b/tests/baselines/reference/symbolProperty40.js @@ -13,14 +13,11 @@ c[Symbol.iterator](0); //// [symbolProperty40.js] -var C = (function () { - function C() { - } - C.prototype[Symbol.iterator] = function (x) { +class C { + [Symbol.iterator](x) { return undefined; - }; - return C; -})(); + } +} var c = new C; c[Symbol.iterator](""); c[Symbol.iterator](0); diff --git a/tests/baselines/reference/symbolProperty41.js b/tests/baselines/reference/symbolProperty41.js index d26b2c7682a..fd9d58082b6 100644 --- a/tests/baselines/reference/symbolProperty41.js +++ b/tests/baselines/reference/symbolProperty41.js @@ -13,14 +13,11 @@ c[Symbol.iterator]("hello"); //// [symbolProperty41.js] -var C = (function () { - function C() { - } - C.prototype[Symbol.iterator] = function (x) { +class C { + [Symbol.iterator](x) { return undefined; - }; - return C; -})(); + } +} var c = new C; c[Symbol.iterator](""); c[Symbol.iterator]("hello"); diff --git a/tests/baselines/reference/symbolProperty42.js b/tests/baselines/reference/symbolProperty42.js index 1990f54066c..082e862f0fc 100644 --- a/tests/baselines/reference/symbolProperty42.js +++ b/tests/baselines/reference/symbolProperty42.js @@ -8,11 +8,8 @@ class C { } //// [symbolProperty42.js] -var C = (function () { - function C() { - } - C.prototype[Symbol.iterator] = function (x) { +class C { + [Symbol.iterator](x) { return undefined; - }; - return C; -})(); + } +} diff --git a/tests/baselines/reference/symbolProperty43.js b/tests/baselines/reference/symbolProperty43.js index fcb1fd3f8e5..fdeb52ca893 100644 --- a/tests/baselines/reference/symbolProperty43.js +++ b/tests/baselines/reference/symbolProperty43.js @@ -5,8 +5,5 @@ class C { } //// [symbolProperty43.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/symbolProperty44.js b/tests/baselines/reference/symbolProperty44.js index d4824e79318..a3de33640af 100644 --- a/tests/baselines/reference/symbolProperty44.js +++ b/tests/baselines/reference/symbolProperty44.js @@ -9,15 +9,8 @@ class C { } //// [symbolProperty44.js] -var C = (function () { - function C() { +class C { + get [Symbol.hasInstance]() { + return ""; } - Object.defineProperty(C.prototype, Symbol.hasInstance, { - get: function () { - return ""; - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/symbolProperty45.js b/tests/baselines/reference/symbolProperty45.js index d056aba9f56..97b1252b825 100644 --- a/tests/baselines/reference/symbolProperty45.js +++ b/tests/baselines/reference/symbolProperty45.js @@ -9,22 +9,11 @@ class C { } //// [symbolProperty45.js] -var C = (function () { - function C() { +class C { + get [Symbol.hasInstance]() { + return ""; } - Object.defineProperty(C.prototype, Symbol.hasInstance, { - get: function () { - return ""; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, Symbol.toPrimitive, { - get: function () { - return ""; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + get [Symbol.toPrimitive]() { + return ""; + } +} diff --git a/tests/baselines/reference/symbolProperty46.js b/tests/baselines/reference/symbolProperty46.js index 255fbac0809..1d4a373f03c 100644 --- a/tests/baselines/reference/symbolProperty46.js +++ b/tests/baselines/reference/symbolProperty46.js @@ -12,20 +12,13 @@ class C { (new C)[Symbol.hasInstance] = ""; //// [symbolProperty46.js] -var C = (function () { - function C() { +class C { + get [Symbol.hasInstance]() { + return ""; } - Object.defineProperty(C.prototype, Symbol.hasInstance, { - get: function () { - return ""; - }, - // Should take a string - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + // Should take a string + set [Symbol.hasInstance](x) { + } +} (new C)[Symbol.hasInstance] = 0; (new C)[Symbol.hasInstance] = ""; diff --git a/tests/baselines/reference/symbolProperty47.js b/tests/baselines/reference/symbolProperty47.js index 92429c720c1..7c6886f280b 100644 --- a/tests/baselines/reference/symbolProperty47.js +++ b/tests/baselines/reference/symbolProperty47.js @@ -12,20 +12,13 @@ class C { (new C)[Symbol.hasInstance] = ""; //// [symbolProperty47.js] -var C = (function () { - function C() { +class C { + get [Symbol.hasInstance]() { + return ""; } - Object.defineProperty(C.prototype, Symbol.hasInstance, { - get: function () { - return ""; - }, - // Should take a string - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + // Should take a string + set [Symbol.hasInstance](x) { + } +} (new C)[Symbol.hasInstance] = 0; (new C)[Symbol.hasInstance] = ""; diff --git a/tests/baselines/reference/symbolProperty48.js b/tests/baselines/reference/symbolProperty48.js index b0dc2b46dba..283c3d0d2c5 100644 --- a/tests/baselines/reference/symbolProperty48.js +++ b/tests/baselines/reference/symbolProperty48.js @@ -11,11 +11,8 @@ module M { var M; (function (M) { var Symbol; - var C = (function () { - function C() { + class C { + [Symbol.iterator]() { } - C.prototype[Symbol.iterator] = function () { - }; - return C; - })(); + } })(M || (M = {})); diff --git a/tests/baselines/reference/symbolProperty49.js b/tests/baselines/reference/symbolProperty49.js index ea6e6f2c523..027b76f76d1 100644 --- a/tests/baselines/reference/symbolProperty49.js +++ b/tests/baselines/reference/symbolProperty49.js @@ -11,11 +11,8 @@ module M { var M; (function (M) { M.Symbol; - var C = (function () { - function C() { + class C { + [M.Symbol.iterator]() { } - C.prototype[M.Symbol.iterator] = function () { - }; - return C; - })(); + } })(M || (M = {})); diff --git a/tests/baselines/reference/symbolProperty50.js b/tests/baselines/reference/symbolProperty50.js index 0a668e95509..30c911e8fab 100644 --- a/tests/baselines/reference/symbolProperty50.js +++ b/tests/baselines/reference/symbolProperty50.js @@ -10,11 +10,8 @@ module M { //// [symbolProperty50.js] var M; (function (M) { - var C = (function () { - function C() { + class C { + [Symbol.iterator]() { } - C.prototype[Symbol.iterator] = function () { - }; - return C; - })(); + } })(M || (M = {})); diff --git a/tests/baselines/reference/symbolProperty51.js b/tests/baselines/reference/symbolProperty51.js index b3b9902fcd6..a9a79098424 100644 --- a/tests/baselines/reference/symbolProperty51.js +++ b/tests/baselines/reference/symbolProperty51.js @@ -10,11 +10,8 @@ module M { //// [symbolProperty51.js] var M; (function (M) { - var C = (function () { - function C() { + class C { + [Symbol.iterator]() { } - C.prototype[Symbol.iterator] = function () { - }; - return C; - })(); + } })(M || (M = {})); diff --git a/tests/baselines/reference/symbolProperty6.js b/tests/baselines/reference/symbolProperty6.js index 114999dc873..311baf2c187 100644 --- a/tests/baselines/reference/symbolProperty6.js +++ b/tests/baselines/reference/symbolProperty6.js @@ -9,18 +9,13 @@ class C { } //// [symbolProperty6.js] -var C = (function () { - function C() { +class C { + constructor() { this[Symbol.iterator] = 0; } - C.prototype[Symbol.isRegExp] = function () { - }; - Object.defineProperty(C.prototype, Symbol.toStringTag, { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + [Symbol.isRegExp]() { + } + get [Symbol.toStringTag]() { + return 0; + } +} diff --git a/tests/baselines/reference/symbolProperty7.js b/tests/baselines/reference/symbolProperty7.js index 42d19616ce3..b833eecff32 100644 --- a/tests/baselines/reference/symbolProperty7.js +++ b/tests/baselines/reference/symbolProperty7.js @@ -9,18 +9,13 @@ class C { } //// [symbolProperty7.js] -var C = (function () { - function C() { +class C { + constructor() { this[Symbol()] = 0; } - C.prototype[Symbol()] = function () { - }; - Object.defineProperty(C.prototype, Symbol(), { - get: function () { - return 0; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + [Symbol()]() { + } + get [Symbol()]() { + return 0; + } +} diff --git a/tests/baselines/reference/symbolProperty9.js b/tests/baselines/reference/symbolProperty9.js index f97a1d44a21..e6c8f7299a9 100644 --- a/tests/baselines/reference/symbolProperty9.js +++ b/tests/baselines/reference/symbolProperty9.js @@ -11,11 +11,8 @@ i = new C; var c: C = i; //// [symbolProperty9.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} var i; i = new C; var c = i; From 0eeb7ce7b8d3c854493972ec28e06f15b5c2ae96 Mon Sep 17 00:00:00 2001 From: Yui T Date: Sun, 15 Mar 2015 21:40:15 -0700 Subject: [PATCH 20/26] Update baselines --- ...mitClassDeclarationWithConstructorInES6.js | 30 ++++++++--- ...ClassDeclarationWithConstructorInES6.types | 39 +++++++++++--- ...rationWithExtensionAndTypeArgumentInES6.js | 3 -- .../emitClassDeclarationWithExtensionInES6.js | 37 ++++++++++--- ...itClassDeclarationWithExtensionInES6.types | 52 +++++++++++++++++-- ...itClassDeclarationWithGetterSetterInES6.js | 2 - .../emitClassDeclarationWithMethodInES6.js | 2 - .../reference/symbolDeclarationEmit1.js | 7 +-- .../reference/symbolDeclarationEmit11.js | 27 ++++------ .../reference/symbolDeclarationEmit12.js | 28 ++++------ .../reference/symbolDeclarationEmit13.js | 23 +++----- .../reference/symbolDeclarationEmit14.js | 25 +++------ .../reference/symbolDeclarationEmit2.js | 7 ++- .../reference/symbolDeclarationEmit3.js | 9 ++-- .../reference/symbolDeclarationEmit4.js | 19 +++---- ...plateStringsArrayTypeRedefinedInES6Mode.js | 7 +-- 16 files changed, 183 insertions(+), 134 deletions(-) diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js index 7877c957b29..8c115b17e9c 100644 --- a/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.js @@ -1,26 +1,42 @@ //// [emitClassDeclarationWithConstructorInES6.ts] -class C { +class A { y: number; constructor(x: number) { } + foo(a: any); + foo() { } } -class D { +class B { y: number; x: string = "hello"; - constructor(x: number, z = "hello") { + _bar: string; + + constructor(x: number, z = "hello", ...args) { this.y = 10; } -} + baz(...args): string; + baz(z: string, v: number): string { + return this._bar; + } +} + + + //// [emitClassDeclarationWithConstructorInES6.js] -class C { +class A { constructor(x) { } + foo() { + } } -class D { - constructor(x, z = "hello") { +class B { + constructor(x, z = "hello", ...args) { this.x = "hello"; this.y = 10; } + baz(z, v) { + return this._bar; + } } diff --git a/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types index 359e58a4b32..10244bf6170 100644 --- a/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types +++ b/tests/baselines/reference/emitClassDeclarationWithConstructorInES6.types @@ -1,6 +1,6 @@ === tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithConstructorInES6.ts === -class C { ->C : C +class A { +>A : A y: number; >y : number @@ -8,10 +8,16 @@ class C { constructor(x: number) { >x : number } + foo(a: any); +>foo : (a: any) => any +>a : any + + foo() { } +>foo : (a: any) => any } -class D { ->D : D +class B { +>B : B y: number; >y : number @@ -19,14 +25,35 @@ class D { x: string = "hello"; >x : string - constructor(x: number, z = "hello") { + _bar: string; +>_bar : string + + constructor(x: number, z = "hello", ...args) { >x : number >z : string +>args : any[] this.y = 10; >this.y = 10 : number >this.y : number ->this : D +>this : B >y : number } + baz(...args): string; +>baz : (...args: any[]) => string +>args : any[] + + baz(z: string, v: number): string { +>baz : (...args: any[]) => string +>z : string +>v : number + + return this._bar; +>this._bar : string +>this : B +>_bar : string + } } + + + diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js index 2409ebc0b66..cd217af6a81 100644 --- a/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionAndTypeArgumentInES6.js @@ -16,9 +16,6 @@ class B { } } class C extends B { - constructor(...args) { - super(...args); - } } class D extends B { constructor(b) { diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js index 389d18d37a3..5c64aebd16a 100644 --- a/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.js @@ -1,25 +1,48 @@ //// [emitClassDeclarationWithExtensionInES6.ts] -class B { } -class C extends B { } -class D extends B { +class B { + baz(a: string, y = 10) { } +} +class C extends B { + foo() { } + baz(a: string, y:number) { + super.baz(a, y); + } +} +class D extends C { constructor() { super(); } + + foo() { + super.foo(); + } + + baz() { + super.baz("hello", 10); + } } //// [emitClassDeclarationWithExtensionInES6.js] class B { - constructor() { + baz(a, y = 10) { } } class C extends B { - constructor(...args) { - super(...args); + foo() { + } + baz(a, y) { + super.baz(a, y); } } -class D extends B { +class D extends C { constructor() { super(); } + foo() { + super.foo(); + } + baz() { + super.baz("hello", 10); + } } diff --git a/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types index f410340b509..a1549be5df4 100644 --- a/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types +++ b/tests/baselines/reference/emitClassDeclarationWithExtensionInES6.types @@ -1,19 +1,61 @@ === tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExtensionInES6.ts === -class B { } +class B { >B : B -class C extends B { } + baz(a: string, y = 10) { } +>baz : (a: string, y?: number) => void +>a : string +>y : number +} +class C extends B { >C : C >B : B -class D extends B { + foo() { } +>foo : () => void + + baz(a: string, y:number) { +>baz : (a: string, y: number) => void +>a : string +>y : number + + super.baz(a, y); +>super.baz(a, y) : void +>super.baz : (a: string, y?: number) => void +>super : B +>baz : (a: string, y?: number) => void +>a : string +>y : number + } +} +class D extends C { >D : D ->B : B +>C : C constructor() { super(); >super() : void ->super : typeof B +>super : typeof C + } + + foo() { +>foo : () => void + + super.foo(); +>super.foo() : void +>super.foo : () => void +>super : C +>foo : () => void + } + + baz() { +>baz : () => void + + super.baz("hello", 10); +>super.baz("hello", 10) : void +>super.baz : (a: string, y: number) => void +>super : C +>baz : (a: string, y: number) => void } } diff --git a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js index 5d4a4fff6d6..55d72a8b8d5 100644 --- a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js @@ -18,8 +18,6 @@ class C { //// [emitClassDeclarationWithGetterSetterInES6.js] class C { - constructor() { - } get name() { return this._name; } diff --git a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js index fd8a3079f8b..20f58b4274e 100644 --- a/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithMethodInES6.js @@ -24,8 +24,6 @@ class D { //// [emitClassDeclarationWithMethodInES6.js] class D { - constructor() { - } foo() { } ["computedName"]() { diff --git a/tests/baselines/reference/symbolDeclarationEmit1.js b/tests/baselines/reference/symbolDeclarationEmit1.js index 16d208db5eb..7c3b39b9d86 100644 --- a/tests/baselines/reference/symbolDeclarationEmit1.js +++ b/tests/baselines/reference/symbolDeclarationEmit1.js @@ -4,11 +4,8 @@ class C { } //// [symbolDeclarationEmit1.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} //// [symbolDeclarationEmit1.d.ts] diff --git a/tests/baselines/reference/symbolDeclarationEmit11.js b/tests/baselines/reference/symbolDeclarationEmit11.js index c9c819eefa2..8af17c95815 100644 --- a/tests/baselines/reference/symbolDeclarationEmit11.js +++ b/tests/baselines/reference/symbolDeclarationEmit11.js @@ -7,23 +7,18 @@ class C { } //// [symbolDeclarationEmit11.js] -var C = (function () { - function C() { +class C { + constructor() { } - C[Symbol.toPrimitive] = function () { - }; - Object.defineProperty(C, Symbol.isRegExp, { - get: function () { - return ""; - }, - set: function (x) { - }, - enumerable: true, - configurable: true - }); - C[Symbol.iterator] = 0; - return C; -})(); + static [Symbol.toPrimitive]() { + } + static get [Symbol.isRegExp]() { + return ""; + } + static set [Symbol.isRegExp](x) { + } +} +C[Symbol.iterator] = 0; //// [symbolDeclarationEmit11.d.ts] diff --git a/tests/baselines/reference/symbolDeclarationEmit12.js b/tests/baselines/reference/symbolDeclarationEmit12.js index 49ff8b35976..9a75f6d573c 100644 --- a/tests/baselines/reference/symbolDeclarationEmit12.js +++ b/tests/baselines/reference/symbolDeclarationEmit12.js @@ -15,24 +15,16 @@ module M { //// [symbolDeclarationEmit12.js] var M; (function (M) { - var C = (function () { - function C() { + export class C { + [Symbol.toPrimitive](x) { } - C.prototype[Symbol.toPrimitive] = function (x) { - }; - C.prototype[Symbol.isConcatSpreadable] = function () { + [Symbol.isConcatSpreadable]() { return undefined; - }; - Object.defineProperty(C.prototype, Symbol.isRegExp, { - get: function () { - return undefined; - }, - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; - })(); - M.C = C; + } + get [Symbol.isRegExp]() { + return undefined; + } + set [Symbol.isRegExp](x) { + } + } })(M || (M = {})); diff --git a/tests/baselines/reference/symbolDeclarationEmit13.js b/tests/baselines/reference/symbolDeclarationEmit13.js index 51b6edcece5..f48a918a6f2 100644 --- a/tests/baselines/reference/symbolDeclarationEmit13.js +++ b/tests/baselines/reference/symbolDeclarationEmit13.js @@ -5,24 +5,13 @@ class C { } //// [symbolDeclarationEmit13.js] -var C = (function () { - function C() { +class C { + get [Symbol.isRegExp]() { + return ""; } - Object.defineProperty(C.prototype, Symbol.isRegExp, { - get: function () { - return ""; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, Symbol.toStringTag, { - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + set [Symbol.toStringTag](x) { + } +} //// [symbolDeclarationEmit13.d.ts] diff --git a/tests/baselines/reference/symbolDeclarationEmit14.js b/tests/baselines/reference/symbolDeclarationEmit14.js index d81bc329927..6197ffa2b4f 100644 --- a/tests/baselines/reference/symbolDeclarationEmit14.js +++ b/tests/baselines/reference/symbolDeclarationEmit14.js @@ -5,25 +5,14 @@ class C { } //// [symbolDeclarationEmit14.js] -var C = (function () { - function C() { +class C { + get [Symbol.isRegExp]() { + return ""; } - Object.defineProperty(C.prototype, Symbol.isRegExp, { - get: function () { - return ""; - }, - enumerable: true, - configurable: true - }); - Object.defineProperty(C.prototype, Symbol.toStringTag, { - get: function () { - return ""; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + get [Symbol.toStringTag]() { + return ""; + } +} //// [symbolDeclarationEmit14.d.ts] diff --git a/tests/baselines/reference/symbolDeclarationEmit2.js b/tests/baselines/reference/symbolDeclarationEmit2.js index 2112f9e7748..5558bebc64e 100644 --- a/tests/baselines/reference/symbolDeclarationEmit2.js +++ b/tests/baselines/reference/symbolDeclarationEmit2.js @@ -4,12 +4,11 @@ class C { } //// [symbolDeclarationEmit2.js] -var C = (function () { - function C() { +class C { + constructor() { this[Symbol.isRegExp] = ""; } - return C; -})(); +} //// [symbolDeclarationEmit2.d.ts] diff --git a/tests/baselines/reference/symbolDeclarationEmit3.js b/tests/baselines/reference/symbolDeclarationEmit3.js index 6d06c09bd69..6f513b053c7 100644 --- a/tests/baselines/reference/symbolDeclarationEmit3.js +++ b/tests/baselines/reference/symbolDeclarationEmit3.js @@ -6,13 +6,10 @@ class C { } //// [symbolDeclarationEmit3.js] -var C = (function () { - function C() { +class C { + [Symbol.isRegExp](x) { } - C.prototype[Symbol.isRegExp] = function (x) { - }; - return C; -})(); +} //// [symbolDeclarationEmit3.d.ts] diff --git a/tests/baselines/reference/symbolDeclarationEmit4.js b/tests/baselines/reference/symbolDeclarationEmit4.js index cd3fc53a5bb..14f50a03ee7 100644 --- a/tests/baselines/reference/symbolDeclarationEmit4.js +++ b/tests/baselines/reference/symbolDeclarationEmit4.js @@ -5,20 +5,13 @@ class C { } //// [symbolDeclarationEmit4.js] -var C = (function () { - function C() { +class C { + get [Symbol.isRegExp]() { + return ""; } - Object.defineProperty(C.prototype, Symbol.isRegExp, { - get: function () { - return ""; - }, - set: function (x) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); + set [Symbol.isRegExp](x) { + } +} //// [symbolDeclarationEmit4.d.ts] diff --git a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.js b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.js index 22ce6831f00..95ab43743ae 100644 --- a/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.js +++ b/tests/baselines/reference/templateStringsArrayTypeRedefinedInES6Mode.js @@ -11,11 +11,8 @@ f({}, 10, 10); f `abcdef${ 1234 }${ 5678 }ghijkl`; //// [templateStringsArrayTypeRedefinedInES6Mode.js] -var TemplateStringsArray = (function () { - function TemplateStringsArray() { - } - return TemplateStringsArray; -})(); +class TemplateStringsArray { +} function f(x, y, z) { } f({}, 10, 10); From 2c7ea7f6b26faadf61ad7d7d48a77594248b2287 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 16 Mar 2015 14:28:29 -0700 Subject: [PATCH 21/26] Update Baselines --- .../computedPropertyNames24_ES5.errors.txt | 4 +- .../reference/computedPropertyNames24_ES5.js | 6 +- .../computedPropertyNames26_ES5.errors.txt | 4 +- .../reference/computedPropertyNames26_ES5.js | 6 +- ...computedPropertyNamesSourceMap1_ES5.js.map | 2 +- ...dPropertyNamesSourceMap1_ES5.sourcemap.txt | 8 ++- ...computedPropertyNamesSourceMap1_ES6.js.map | 2 +- ...dPropertyNamesSourceMap1_ES6.sourcemap.txt | 7 +- ...computedPropertyNamesWithStaticProperty.js | 2 - .../emitClassDeclarationWithExport.errors.txt | 16 ----- .../emitClassDeclarationWithExport.js | 23 ------ ...rationWithStaticPropertyAssignmentInES6.js | 2 - .../reference/emitThisInSuperMethodCall.js | 6 +- .../reference/errorSuperPropertyAccess.js | 26 +++---- tests/baselines/reference/es6-amd.js | 11 ++- tests/baselines/reference/es6-amd.js.map | 2 +- .../baselines/reference/es6-amd.sourcemap.txt | 70 ++++++------------- .../reference/es6-declaration-amd.js | 11 ++- .../reference/es6-declaration-amd.js.map | 2 +- .../es6-declaration-amd.sourcemap.txt | 70 ++++++------------- .../baselines/reference/es6-sourcemap-amd.js | 11 ++- .../reference/es6-sourcemap-amd.js.map | 2 +- .../reference/es6-sourcemap-amd.sourcemap.txt | 70 ++++++------------- .../reference/letDeclarations-scopes.js | 33 ++++----- .../letDeclarations-validContexts.js | 29 ++++---- ...ationInStrictModeByDefaultInES6.errors.txt | 8 +-- .../reference/parserComputedPropertyName10.js | 7 +- .../reference/parserComputedPropertyName11.js | 7 +- .../reference/parserComputedPropertyName12.js | 9 +-- .../reference/parserComputedPropertyName24.js | 13 +--- .../reference/parserComputedPropertyName25.js | 7 +- .../reference/parserComputedPropertyName27.js | 7 +- .../reference/parserComputedPropertyName28.js | 7 +- .../reference/parserComputedPropertyName29.js | 7 +- .../reference/parserComputedPropertyName31.js | 7 +- .../reference/parserComputedPropertyName33.js | 7 +- .../parserComputedPropertyName36.errors.txt | 15 ++-- .../reference/parserComputedPropertyName36.js | 7 +- .../parserComputedPropertyName38.errors.txt | 20 ++++-- .../reference/parserComputedPropertyName38.js | 11 ++- .../reference/parserComputedPropertyName39.js | 7 +- .../reference/parserComputedPropertyName40.js | 9 +-- .../reference/parserComputedPropertyName7.js | 7 +- .../reference/parserComputedPropertyName8.js | 7 +- .../reference/parserComputedPropertyName9.js | 7 +- .../reference/parserSuperExpression1.js | 4 +- .../reference/parserSuperExpression2.js | 2 +- .../reference/parserSuperExpression4.js | 4 +- .../reference/parserSymbolIndexer2.js | 7 +- .../reference/parserSymbolIndexer3.js | 7 +- .../reference/parserSymbolProperty5.js | 7 +- .../reference/parserSymbolProperty6.js | 7 +- .../reference/parserSymbolProperty7.js | 9 +-- tests/baselines/reference/properties.js.map | 2 +- .../reference/properties.sourcemap.txt | 11 ++- .../reference/sourceMapValidationClass.js.map | 2 +- .../sourceMapValidationClass.sourcemap.txt | 13 ++-- tests/baselines/reference/super.js | 2 +- tests/baselines/reference/super1.js | 2 +- tests/baselines/reference/superAccess2.js | 2 +- tests/baselines/reference/superErrors.js | 16 ++--- ...side-object-literal-getters-and-setters.js | 8 +-- .../reference/symbolDeclarationEmit11.js | 2 - .../emitClassDeclarationWithExport.ts | 8 --- .../computedPropertyNames24_ES5.ts | 2 - .../computedPropertyNames26_ES5.ts | 2 - 66 files changed, 261 insertions(+), 459 deletions(-) delete mode 100644 tests/baselines/reference/emitClassDeclarationWithExport.errors.txt delete mode 100644 tests/baselines/reference/emitClassDeclarationWithExport.js delete mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts diff --git a/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt index a1290e06956..121b39450a6 100644 --- a/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames24_ES5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts(9,6): error TS2466: 'super' cannot be referenced in a computed property name. +tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts(7,6): error TS2466: 'super' cannot be referenced in a computed property name. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts (1 errors) ==== @@ -8,8 +8,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts(9, } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [super.bar()]() { } ~~~~~ !!! error TS2466: 'super' cannot be referenced in a computed property name. diff --git a/tests/baselines/reference/computedPropertyNames24_ES5.js b/tests/baselines/reference/computedPropertyNames24_ES5.js index d24f406c1ad..cea5240003b 100644 --- a/tests/baselines/reference/computedPropertyNames24_ES5.js +++ b/tests/baselines/reference/computedPropertyNames24_ES5.js @@ -5,8 +5,6 @@ class Base { } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [super.bar()]() { } } @@ -30,9 +28,7 @@ var C = (function (_super) { function C() { _super.apply(this, arguments); } - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. - C.prototype[super.bar.call(this)] = function () { + C.prototype[_super.bar.call(this)] = function () { }; return C; })(Base); diff --git a/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt b/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt index 77408f0a9f8..e7039712734 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt +++ b/tests/baselines/reference/computedPropertyNames26_ES5.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts(10,12): error TS2466: 'super' cannot be referenced in a computed property name. +tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts(8,12): error TS2466: 'super' cannot be referenced in a computed property name. ==== tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts (1 errors) ==== @@ -8,8 +8,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts(10 } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [ { [super.bar()]: 1 }[0] ~~~~~ diff --git a/tests/baselines/reference/computedPropertyNames26_ES5.js b/tests/baselines/reference/computedPropertyNames26_ES5.js index 217a0dfc74c..5651ee266c9 100644 --- a/tests/baselines/reference/computedPropertyNames26_ES5.js +++ b/tests/baselines/reference/computedPropertyNames26_ES5.js @@ -5,8 +5,6 @@ class Base { } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [ { [super.bar()]: 1 }[0] ]() { } @@ -32,10 +30,8 @@ var C = (function (_super) { function C() { _super.apply(this, arguments); } - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. C.prototype[(_a = {}, - _a[super.bar.call(this)] = 1, + _a[_super.bar.call(this)] = 1, _a)[0]] = function () { }; return C; diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map index 3457187e78a..c47fcfcad31 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.js.map @@ -1,2 +1,2 @@ //// [computedPropertyNamesSourceMap1_ES5.js.map] -{"version":3,"file":"computedPropertyNamesSourceMap1_ES5.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES5.ts"],"names":["C","C.constructor","C[\"hello\"]"],"mappings":"AAAA;IAAAA;IAIAC,CAACA;IAHGD,YAACA,OAAOA;QACJE,QAAQA,CAACA;IACbA,CAACA;IACLF,QAACA;AAADA,CAACA,AAJD,IAIC"} \ No newline at end of file +{"version":3,"file":"computedPropertyNamesSourceMap1_ES5.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES5.ts"],"names":["C","C.constructor","C[\"hello\"]"],"mappings":"AAAA;IAAAA;IAIAC,CAACA;IAHGD,YAACA,OAAOA,CAACA,GAATA;QACIE,QAAQA,CAACA;IACbA,CAACA;IACLF,QAACA;AAADA,CAACA,AAJD,IAIC"} \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt index be0f79edd17..df0af71fb02 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES5.sourcemap.txt @@ -37,18 +37,24 @@ sourceFile:computedPropertyNamesSourceMap1_ES5.ts 1->^^^^ 2 > ^^^^^^^^^^^^ 3 > ^^^^^^^ +4 > ^ +5 > ^^^ 1-> 2 > [ 3 > "hello" +4 > ] +5 > 1->Emitted(4, 5) Source(2, 5) + SourceIndex(0) name (C) 2 >Emitted(4, 17) Source(2, 6) + SourceIndex(0) name (C) 3 >Emitted(4, 24) Source(2, 13) + SourceIndex(0) name (C) +4 >Emitted(4, 25) Source(2, 14) + SourceIndex(0) name (C) +5 >Emitted(4, 28) Source(2, 5) + SourceIndex(0) name (C) --- >>> debugger; 1 >^^^^^^^^ 2 > ^^^^^^^^ 3 > ^ -1 >]() { +1 >["hello"]() { > 2 > debugger 3 > ; diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map index ff47df55493..9a2dd60999e 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.js.map @@ -1,2 +1,2 @@ //// [computedPropertyNamesSourceMap1_ES6.js.map] -{"version":3,"file":"computedPropertyNamesSourceMap1_ES6.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES6.ts"],"names":["C","C[\"hello\"]"],"mappings":"AAAA;IACIA,CAACA,OAAOA;QACJC,QAAQA,CAACA;IACbA,CAACA;AACLD,CAACA;AAAA"} \ No newline at end of file +{"version":3,"file":"computedPropertyNamesSourceMap1_ES6.js","sourceRoot":"","sources":["computedPropertyNamesSourceMap1_ES6.ts"],"names":["C","C[\"hello\"]"],"mappings":"AAAA;IACIA,CAACA,OAAOA,CAACA;QACLC,QAAQA,CAACA;IACbA,CAACA;AACLD,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt index 36535c1aa4f..30493b97347 100644 --- a/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt +++ b/tests/baselines/reference/computedPropertyNamesSourceMap1_ES6.sourcemap.txt @@ -18,20 +18,23 @@ sourceFile:computedPropertyNamesSourceMap1_ES6.ts 1->^^^^ 2 > ^ 3 > ^^^^^^^ -4 > ^^^^^^-> +4 > ^ +5 > ^^^^^-> 1->class C { > 2 > [ 3 > "hello" +4 > ] 1->Emitted(2, 5) Source(2, 5) + SourceIndex(0) name (C) 2 >Emitted(2, 6) Source(2, 6) + SourceIndex(0) name (C) 3 >Emitted(2, 13) Source(2, 13) + SourceIndex(0) name (C) +4 >Emitted(2, 14) Source(2, 14) + SourceIndex(0) name (C) --- >>> debugger; 1->^^^^^^^^ 2 > ^^^^^^^^ 3 > ^ -1->]() { +1->() { > 2 > debugger 3 > ; diff --git a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js index f7506d7904d..e6b7bd5aae2 100644 --- a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js +++ b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.js @@ -12,8 +12,6 @@ class C { //// [computedPropertyNamesWithStaticProperty.js] class C { - constructor() { - } get [C.staticProp]() { return "hello"; } diff --git a/tests/baselines/reference/emitClassDeclarationWithExport.errors.txt b/tests/baselines/reference/emitClassDeclarationWithExport.errors.txt deleted file mode 100644 index 11b1de11bf6..00000000000 --- a/tests/baselines/reference/emitClassDeclarationWithExport.errors.txt +++ /dev/null @@ -1,16 +0,0 @@ -tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts(1,14): error TS1148: Cannot compile external modules unless the '--module' flag is provided. -tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts(5,22): error TS2309: An export assignment cannot be used in a module with other exported elements. - - -==== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts (2 errors) ==== - export class C { - ~ -!!! error TS1148: Cannot compile external modules unless the '--module' flag is provided. - foo() { } - } - - export default class D { - ~ -!!! error TS2309: An export assignment cannot be used in a module with other exported elements. - bar() { } - } \ No newline at end of file diff --git a/tests/baselines/reference/emitClassDeclarationWithExport.js b/tests/baselines/reference/emitClassDeclarationWithExport.js deleted file mode 100644 index 5a6c84389f3..00000000000 --- a/tests/baselines/reference/emitClassDeclarationWithExport.js +++ /dev/null @@ -1,23 +0,0 @@ -//// [emitClassDeclarationWithExport.ts] -export class C { - foo() { } -} - -export default class D { - bar() { } -} - -//// [emitClassDeclarationWithExport.js] -export class C { - constructor() { - } - foo() { - } -} -export default class D { - constructor() { - } - bar() { - } -} -module.exports = D; diff --git a/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js index 69da64765a3..8e0bf3de06b 100644 --- a/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithStaticPropertyAssignmentInES6.js @@ -11,8 +11,6 @@ class D { //// [emitClassDeclarationWithStaticPropertyAssignmentInES6.js] class C { - constructor() { - } } C.z = "Foo"; class D { diff --git a/tests/baselines/reference/emitThisInSuperMethodCall.js b/tests/baselines/reference/emitThisInSuperMethodCall.js index 383da7d419f..de47b0b95af 100644 --- a/tests/baselines/reference/emitThisInSuperMethodCall.js +++ b/tests/baselines/reference/emitThisInSuperMethodCall.js @@ -49,20 +49,20 @@ var RegisteredUser = (function (_super) { RegisteredUser.prototype.f = function () { (function () { function inner() { - super.sayHello.call(this); + _super.sayHello.call(this); } }); }; RegisteredUser.prototype.g = function () { function inner() { (function () { - super.sayHello.call(this); + _super.sayHello.call(this); }); } }; RegisteredUser.prototype.h = function () { function inner() { - super.sayHello.call(this); + _super.sayHello.call(this); } }; return RegisteredUser; diff --git a/tests/baselines/reference/errorSuperPropertyAccess.js b/tests/baselines/reference/errorSuperPropertyAccess.js index 17cd2c265ed..4ddcca530f1 100644 --- a/tests/baselines/reference/errorSuperPropertyAccess.js +++ b/tests/baselines/reference/errorSuperPropertyAccess.js @@ -140,27 +140,27 @@ var __extends = this.__extends || function (d, b) { //super property access in instance member accessor(get and set) of class with no base type var NoBase = (function () { function NoBase() { - this.m = super.prototype; - this.n = super.hasOwnProperty.call(this, ''); - var a = super.prototype; - var b = super.hasOwnProperty.call(this, ''); + this.m = _super.prototype; + this.n = _super.hasOwnProperty.call(this, ''); + var a = _super.prototype; + var b = _super.hasOwnProperty.call(this, ''); } NoBase.prototype.fn = function () { - var a = super.prototype; - var b = super.hasOwnProperty.call(this, ''); + var a = _super.prototype; + var b = _super.hasOwnProperty.call(this, ''); }; //super static property access in static member function of class with no base type //super static property access in static member accessor(get and set) of class with no base type NoBase.static1 = function () { - super.hasOwnProperty.call(this, ''); + _super.hasOwnProperty.call(this, ''); }; Object.defineProperty(NoBase, "static2", { get: function () { - super.hasOwnProperty.call(this, ''); + _super.hasOwnProperty.call(this, ''); return ''; }, set: function (n) { - super.hasOwnProperty.call(this, ''); + _super.hasOwnProperty.call(this, ''); }, enumerable: true, configurable: true @@ -210,11 +210,11 @@ var SomeDerived1 = (function (_super) { }); SomeDerived1.prototype.fn2 = function () { function inner() { - super.publicFunc.call(this); + _super.publicFunc.call(this); } var x = { test: function () { - return super.publicFunc.call(this); + return _super.publicFunc.call(this); } }; }; @@ -278,6 +278,6 @@ var SomeDerived3 = (function (_super) { })(SomeBase); // In object literal var obj = { - n: super.wat, - p: super.foo.call(this) + n: _super.wat, + p: _super.foo.call(this) }; diff --git a/tests/baselines/reference/es6-amd.js b/tests/baselines/reference/es6-amd.js index 0cce3af0446..74f3037303e 100644 --- a/tests/baselines/reference/es6-amd.js +++ b/tests/baselines/reference/es6-amd.js @@ -14,14 +14,13 @@ class A } //// [es6-amd.js] -var A = (function () { - function A() { +class A { + constructor() { } - A.prototype.B = function () { + B() { return 42; - }; - return A; -})(); + } +} //# sourceMappingURL=es6-amd.js.map //// [es6-amd.d.ts] diff --git a/tests/baselines/reference/es6-amd.js.map b/tests/baselines/reference/es6-amd.js.map index c9866d87884..fe234f8424b 100644 --- a/tests/baselines/reference/es6-amd.js.map +++ b/tests/baselines/reference/es6-amd.js.map @@ -1,2 +1,2 @@ //// [es6-amd.js.map] -{"version":3,"file":"es6-amd.js","sourceRoot":"","sources":["es6-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file +{"version":3,"file":"es6-amd.js","sourceRoot":"","sources":["es6-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-amd.sourcemap.txt b/tests/baselines/reference/es6-amd.sourcemap.txt index 2b271099401..1ab547073c6 100644 --- a/tests/baselines/reference/es6-amd.sourcemap.txt +++ b/tests/baselines/reference/es6-amd.sourcemap.txt @@ -8,14 +8,14 @@ sources: es6-amd.ts emittedFile:tests/cases/compiler/es6-amd.js sourceFile:es6-amd.ts ------------------------------------------------------------------- ->>>var A = (function () { +>>>class A { 1 > -2 >^^^^^^^^^^^^^^^^^^^-> +2 >^^^^^^^^^^^^^^^^^^^^-> 1 > > 1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) --- ->>> function A() { +>>> constructor() { 1->^^^^ 2 > ^^-> 1->class A @@ -26,7 +26,7 @@ sourceFile:es6-amd.ts >>> } 1->^^^^ 2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^-> 1->constructor () > { > @@ -35,81 +35,57 @@ sourceFile:es6-amd.ts 1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) 2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) --- ->>> A.prototype.B = function () { +>>> B() { 1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^-> 1-> > > public 2 > B -3 > 1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) --- >>> return 42; -1 >^^^^^^^^ +1->^^^^^^^^ 2 > ^^^^^^ 3 > ^ 4 > ^^ 5 > ^ -1 >public B() +1->() > { > 2 > return 3 > 4 > 42 5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) 2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) 3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) 4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) 5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) --- ->>> }; +>>> } 1 >^^^^ 2 > ^ -3 > ^^^^^^^^^-> 1 > > 2 > } 1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) 2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) --- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); +>>>} 1 > 2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > 2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) --- ->>>//# sourceMappingURL=es6-amd.js.map \ No newline at end of file +>>>//# sourceMappingURL=es6-amd.js.map1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> +1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) +--- \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.js b/tests/baselines/reference/es6-declaration-amd.js index 471f96b223d..aeba23e0b6e 100644 --- a/tests/baselines/reference/es6-declaration-amd.js +++ b/tests/baselines/reference/es6-declaration-amd.js @@ -14,14 +14,13 @@ class A } //// [es6-declaration-amd.js] -var A = (function () { - function A() { +class A { + constructor() { } - A.prototype.B = function () { + B() { return 42; - }; - return A; -})(); + } +} //# sourceMappingURL=es6-declaration-amd.js.map //// [es6-declaration-amd.d.ts] diff --git a/tests/baselines/reference/es6-declaration-amd.js.map b/tests/baselines/reference/es6-declaration-amd.js.map index 03f79f6c667..ca1899e03f5 100644 --- a/tests/baselines/reference/es6-declaration-amd.js.map +++ b/tests/baselines/reference/es6-declaration-amd.js.map @@ -1,2 +1,2 @@ //// [es6-declaration-amd.js.map] -{"version":3,"file":"es6-declaration-amd.js","sourceRoot":"","sources":["es6-declaration-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file +{"version":3,"file":"es6-declaration-amd.js","sourceRoot":"","sources":["es6-declaration-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-declaration-amd.sourcemap.txt b/tests/baselines/reference/es6-declaration-amd.sourcemap.txt index 198a68633b1..9061bc1ed7c 100644 --- a/tests/baselines/reference/es6-declaration-amd.sourcemap.txt +++ b/tests/baselines/reference/es6-declaration-amd.sourcemap.txt @@ -8,14 +8,14 @@ sources: es6-declaration-amd.ts emittedFile:tests/cases/compiler/es6-declaration-amd.js sourceFile:es6-declaration-amd.ts ------------------------------------------------------------------- ->>>var A = (function () { +>>>class A { 1 > -2 >^^^^^^^^^^^^^^^^^^^-> +2 >^^^^^^^^^^^^^^^^^^^^-> 1 > > 1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) --- ->>> function A() { +>>> constructor() { 1->^^^^ 2 > ^^-> 1->class A @@ -26,7 +26,7 @@ sourceFile:es6-declaration-amd.ts >>> } 1->^^^^ 2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^-> 1->constructor () > { > @@ -35,81 +35,57 @@ sourceFile:es6-declaration-amd.ts 1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) 2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) --- ->>> A.prototype.B = function () { +>>> B() { 1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^-> 1-> > > public 2 > B -3 > 1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) --- >>> return 42; -1 >^^^^^^^^ +1->^^^^^^^^ 2 > ^^^^^^ 3 > ^ 4 > ^^ 5 > ^ -1 >public B() +1->() > { > 2 > return 3 > 4 > 42 5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) 2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) 3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) 4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) 5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) --- ->>> }; +>>> } 1 >^^^^ 2 > ^ -3 > ^^^^^^^^^-> 1 > > 2 > } 1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) 2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) --- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); +>>>} 1 > 2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > 2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) --- ->>>//# sourceMappingURL=es6-declaration-amd.js.map \ No newline at end of file +>>>//# sourceMappingURL=es6-declaration-amd.js.map1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> +1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) +--- \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.js b/tests/baselines/reference/es6-sourcemap-amd.js index 805e56cf830..106726c0f2c 100644 --- a/tests/baselines/reference/es6-sourcemap-amd.js +++ b/tests/baselines/reference/es6-sourcemap-amd.js @@ -14,12 +14,11 @@ class A } //// [es6-sourcemap-amd.js] -var A = (function () { - function A() { +class A { + constructor() { } - A.prototype.B = function () { + B() { return 42; - }; - return A; -})(); + } +} //# sourceMappingURL=es6-sourcemap-amd.js.map \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.js.map b/tests/baselines/reference/es6-sourcemap-amd.js.map index ef22eb4638c..779c13b1296 100644 --- a/tests/baselines/reference/es6-sourcemap-amd.js.map +++ b/tests/baselines/reference/es6-sourcemap-amd.js.map @@ -1,2 +1,2 @@ //// [es6-sourcemap-amd.js.map] -{"version":3,"file":"es6-sourcemap-amd.js","sourceRoot":"","sources":["es6-sourcemap-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,aAACA,GAARA;QAEIE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;IACLF,QAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file +{"version":3,"file":"es6-sourcemap-amd.js","sourceRoot":"","sources":["es6-sourcemap-amd.ts"],"names":["A","A.constructor","A.B"],"mappings":"AACA;IAEIA;IAGAC,CAACA;IAEMD,CAACA;QAEJE,MAAMA,CAACA,EAAEA,CAACA;IACdA,CAACA;AACLF,CAACA;AAAA"} \ No newline at end of file diff --git a/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt b/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt index bcfc33d0405..179dd79ba17 100644 --- a/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt +++ b/tests/baselines/reference/es6-sourcemap-amd.sourcemap.txt @@ -8,14 +8,14 @@ sources: es6-sourcemap-amd.ts emittedFile:tests/cases/compiler/es6-sourcemap-amd.js sourceFile:es6-sourcemap-amd.ts ------------------------------------------------------------------- ->>>var A = (function () { +>>>class A { 1 > -2 >^^^^^^^^^^^^^^^^^^^-> +2 >^^^^^^^^^^^^^^^^^^^^-> 1 > > 1 >Emitted(1, 1) Source(2, 1) + SourceIndex(0) --- ->>> function A() { +>>> constructor() { 1->^^^^ 2 > ^^-> 1->class A @@ -26,7 +26,7 @@ sourceFile:es6-sourcemap-amd.ts >>> } 1->^^^^ 2 > ^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +3 > ^^^^^-> 1->constructor () > { > @@ -35,81 +35,57 @@ sourceFile:es6-sourcemap-amd.ts 1->Emitted(3, 5) Source(7, 5) + SourceIndex(0) name (A.constructor) 2 >Emitted(3, 6) Source(7, 6) + SourceIndex(0) name (A.constructor) --- ->>> A.prototype.B = function () { +>>> B() { 1->^^^^ -2 > ^^^^^^^^^^^^^ -3 > ^^^ +2 > ^ +3 > ^^^^^^^^^^^^^^-> 1-> > > public 2 > B -3 > 1->Emitted(4, 5) Source(9, 12) + SourceIndex(0) name (A) -2 >Emitted(4, 18) Source(9, 13) + SourceIndex(0) name (A) -3 >Emitted(4, 21) Source(9, 5) + SourceIndex(0) name (A) +2 >Emitted(4, 6) Source(9, 13) + SourceIndex(0) name (A) --- >>> return 42; -1 >^^^^^^^^ +1->^^^^^^^^ 2 > ^^^^^^ 3 > ^ 4 > ^^ 5 > ^ -1 >public B() +1->() > { > 2 > return 3 > 4 > 42 5 > ; -1 >Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) +1->Emitted(5, 9) Source(11, 9) + SourceIndex(0) name (A.B) 2 >Emitted(5, 15) Source(11, 15) + SourceIndex(0) name (A.B) 3 >Emitted(5, 16) Source(11, 16) + SourceIndex(0) name (A.B) 4 >Emitted(5, 18) Source(11, 18) + SourceIndex(0) name (A.B) 5 >Emitted(5, 19) Source(11, 19) + SourceIndex(0) name (A.B) --- ->>> }; +>>> } 1 >^^^^ 2 > ^ -3 > ^^^^^^^^^-> 1 > > 2 > } 1 >Emitted(6, 5) Source(12, 5) + SourceIndex(0) name (A.B) 2 >Emitted(6, 6) Source(12, 6) + SourceIndex(0) name (A.B) --- ->>> return A; -1->^^^^ -2 > ^^^^^^^^ -1-> - > -2 > } -1->Emitted(7, 5) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(7, 13) Source(13, 2) + SourceIndex(0) name (A) ---- ->>>})(); +>>>} 1 > 2 >^ -3 > -4 > ^^^^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> -1 > +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1 > + > 2 >} -3 > -4 > class A - > { - > constructor () - > { - > - > } - > - > public B() - > { - > return 42; - > } - > } -1 >Emitted(8, 1) Source(13, 1) + SourceIndex(0) name (A) -2 >Emitted(8, 2) Source(13, 2) + SourceIndex(0) name (A) -3 >Emitted(8, 2) Source(2, 1) + SourceIndex(0) -4 >Emitted(8, 6) Source(13, 2) + SourceIndex(0) +1 >Emitted(7, 1) Source(13, 1) + SourceIndex(0) name (A) +2 >Emitted(7, 2) Source(13, 2) + SourceIndex(0) name (A) --- ->>>//# sourceMappingURL=es6-sourcemap-amd.js.map \ No newline at end of file +>>>//# sourceMappingURL=es6-sourcemap-amd.js.map1-> +2 >^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +1-> +1->Emitted(8, 1) Source(13, 2) + SourceIndex(0) +--- \ No newline at end of file diff --git a/tests/baselines/reference/letDeclarations-scopes.js b/tests/baselines/reference/letDeclarations-scopes.js index fc721807994..d0489820d0b 100644 --- a/tests/baselines/reference/letDeclarations-scopes.js +++ b/tests/baselines/reference/letDeclarations-scopes.js @@ -259,30 +259,25 @@ var m; lable: let l2 = 0; })(m || (m = {})); // methods -var C = (function () { - function C() { +class C { + constructor() { let l = 0; n = l; } - C.prototype.method = function () { + method() { let l = 0; n = l; - }; - Object.defineProperty(C.prototype, "v", { - get: function () { - let l = 0; - n = l; - return n; - }, - set: function (value) { - let l = 0; - n = l; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + } + get v() { + let l = 0; + n = l; + return n; + } + set v(value) { + let l = 0; + n = l; + } +} // object literals var o = { f() { diff --git a/tests/baselines/reference/letDeclarations-validContexts.js b/tests/baselines/reference/letDeclarations-validContexts.js index f6d404135f6..b11a1922383 100644 --- a/tests/baselines/reference/letDeclarations-validContexts.js +++ b/tests/baselines/reference/letDeclarations-validContexts.js @@ -221,26 +221,21 @@ var m; } })(m || (m = {})); // methods -var C = (function () { - function C() { +class C { + constructor() { let l24 = 0; } - C.prototype.method = function () { + method() { let l25 = 0; - }; - Object.defineProperty(C.prototype, "v", { - get: function () { - let l26 = 0; - return l26; - }, - set: function (value) { - let l27 = value; - }, - enumerable: true, - configurable: true - }); - return C; -})(); + } + get v() { + let l26 = 0; + return l26; + } + set v(value) { + let l27 = value; + } +} // object literals var o = { f() { diff --git a/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt index 04ac8b28a8b..d109b048085 100644 --- a/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt +++ b/tests/baselines/reference/parseClassDeclarationInStrictModeByDefaultInES6.errors.txt @@ -1,5 +1,3 @@ -tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(2,5): error TS1100: Invalid use of 'interface' in strict mode. -tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(3,12): error TS1100: Invalid use of 'implements' in strict mode. tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(4,16): error TS1100: Invalid use of 'arguments' in strict mode. tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(5,17): error TS1100: Invalid use of 'eval' in strict mode. tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts(6,9): error TS1100: Invalid use of 'arguments' in strict mode. @@ -7,14 +5,10 @@ tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeBy Property 'callee' is missing in type 'String'. -==== tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts (6 errors) ==== +==== tests/cases/conformance/es6/classDeclaration/parseClassDeclarationInStrictModeByDefaultInES6.ts (4 errors) ==== class C { interface = 10; - ~~~~~~~~~ -!!! error TS1100: Invalid use of 'interface' in strict mode. public implements() { } - ~~~~~~~~~~ -!!! error TS1100: Invalid use of 'implements' in strict mode. public foo(arguments: any) { } ~~~~~~~~~ !!! error TS1100: Invalid use of 'arguments' in strict mode. diff --git a/tests/baselines/reference/parserComputedPropertyName10.js b/tests/baselines/reference/parserComputedPropertyName10.js index c00d3292f7e..eba480ba810 100644 --- a/tests/baselines/reference/parserComputedPropertyName10.js +++ b/tests/baselines/reference/parserComputedPropertyName10.js @@ -4,9 +4,8 @@ class C { } //// [parserComputedPropertyName10.js] -var C = (function () { - function C() { +class C { + constructor() { this[e] = 1; } - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName11.js b/tests/baselines/reference/parserComputedPropertyName11.js index 1b9575184f2..dc63d6385d8 100644 --- a/tests/baselines/reference/parserComputedPropertyName11.js +++ b/tests/baselines/reference/parserComputedPropertyName11.js @@ -4,8 +4,5 @@ class C { } //// [parserComputedPropertyName11.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserComputedPropertyName12.js b/tests/baselines/reference/parserComputedPropertyName12.js index 96e62b626e7..71cf1d352f4 100644 --- a/tests/baselines/reference/parserComputedPropertyName12.js +++ b/tests/baselines/reference/parserComputedPropertyName12.js @@ -4,10 +4,7 @@ class C { } //// [parserComputedPropertyName12.js] -var C = (function () { - function C() { +class C { + [e]() { } - C.prototype[e] = function () { - }; - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName24.js b/tests/baselines/reference/parserComputedPropertyName24.js index 0b9467fb26d..8fc0a5be3a5 100644 --- a/tests/baselines/reference/parserComputedPropertyName24.js +++ b/tests/baselines/reference/parserComputedPropertyName24.js @@ -4,14 +4,7 @@ class C { } //// [parserComputedPropertyName24.js] -var C = (function () { - function C() { +class C { + set [e](v) { } - Object.defineProperty(C.prototype, e, { - set: function (v) { - }, - enumerable: true, - configurable: true - }); - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName25.js b/tests/baselines/reference/parserComputedPropertyName25.js index a00cec2e6dd..47670fe14b8 100644 --- a/tests/baselines/reference/parserComputedPropertyName25.js +++ b/tests/baselines/reference/parserComputedPropertyName25.js @@ -6,10 +6,9 @@ class C { } //// [parserComputedPropertyName25.js] -var C = (function () { - function C() { +class C { + constructor() { // No ASI this[e] = 0[e2] = 1; } - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName27.js b/tests/baselines/reference/parserComputedPropertyName27.js index 03b156af840..f872e95e7e6 100644 --- a/tests/baselines/reference/parserComputedPropertyName27.js +++ b/tests/baselines/reference/parserComputedPropertyName27.js @@ -6,10 +6,9 @@ class C { } //// [parserComputedPropertyName27.js] -var C = (function () { - function C() { +class C { + constructor() { // No ASI this[e] = 0[e2]; } - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName28.js b/tests/baselines/reference/parserComputedPropertyName28.js index 60fb25dfa20..998f60db914 100644 --- a/tests/baselines/reference/parserComputedPropertyName28.js +++ b/tests/baselines/reference/parserComputedPropertyName28.js @@ -5,9 +5,8 @@ class C { } //// [parserComputedPropertyName28.js] -var C = (function () { - function C() { +class C { + constructor() { this[e] = 0; } - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName29.js b/tests/baselines/reference/parserComputedPropertyName29.js index 05ced020aff..a100cbf1791 100644 --- a/tests/baselines/reference/parserComputedPropertyName29.js +++ b/tests/baselines/reference/parserComputedPropertyName29.js @@ -6,10 +6,9 @@ class C { } //// [parserComputedPropertyName29.js] -var C = (function () { - function C() { +class C { + constructor() { // yes ASI this[e] = id++; } - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName31.js b/tests/baselines/reference/parserComputedPropertyName31.js index 2a07155a2f0..cee09fb0ab7 100644 --- a/tests/baselines/reference/parserComputedPropertyName31.js +++ b/tests/baselines/reference/parserComputedPropertyName31.js @@ -6,8 +6,5 @@ class C { } //// [parserComputedPropertyName31.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserComputedPropertyName33.js b/tests/baselines/reference/parserComputedPropertyName33.js index 1cc06c06780..64239bc1284 100644 --- a/tests/baselines/reference/parserComputedPropertyName33.js +++ b/tests/baselines/reference/parserComputedPropertyName33.js @@ -6,12 +6,11 @@ class C { } //// [parserComputedPropertyName33.js] -var C = (function () { - function C() { +class C { + constructor() { // No ASI this[e] = 0[e2](); } - return C; -})(); +} { } diff --git a/tests/baselines/reference/parserComputedPropertyName36.errors.txt b/tests/baselines/reference/parserComputedPropertyName36.errors.txt index 07e937b3b42..8c647be13c9 100644 --- a/tests/baselines/reference/parserComputedPropertyName36.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName36.errors.txt @@ -1,12 +1,15 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,5): error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol. -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,6): error TS2304: Cannot find name 'public'. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,6): error TS1109: Expression expected. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts(2,14): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts (2 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName36.ts (3 errors) ==== class C { [public ]: string; - ~~~~~~~~~ -!!! error TS1166: A computed property name in a class property declaration must directly refer to a built-in symbol. ~~~~~~ -!!! error TS2304: Cannot find name 'public'. +!!! error TS1109: Expression expected. + ~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. } \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName36.js b/tests/baselines/reference/parserComputedPropertyName36.js index 264a3512075..fd6f376ef2b 100644 --- a/tests/baselines/reference/parserComputedPropertyName36.js +++ b/tests/baselines/reference/parserComputedPropertyName36.js @@ -4,8 +4,5 @@ class C { } //// [parserComputedPropertyName36.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserComputedPropertyName38.errors.txt b/tests/baselines/reference/parserComputedPropertyName38.errors.txt index 4322abf44ed..28daf322748 100644 --- a/tests/baselines/reference/parserComputedPropertyName38.errors.txt +++ b/tests/baselines/reference/parserComputedPropertyName38.errors.txt @@ -1,9 +1,21 @@ -tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,6): error TS2304: Cannot find name 'public'. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,6): error TS1109: Expression expected. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,12): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,13): error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(2,16): error TS1005: '=>' expected. +tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts(3,1): error TS1128: Declaration or statement expected. -==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts (1 errors) ==== +==== tests/cases/conformance/parser/ecmascript6/ComputedPropertyNames/parserComputedPropertyName38.ts (5 errors) ==== class C { [public]() { } ~~~~~~ -!!! error TS2304: Cannot find name 'public'. - } \ No newline at end of file +!!! error TS1109: Expression expected. + ~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~ +!!! error TS1068: Unexpected token. A constructor, method, accessor, or property was expected. + ~ +!!! error TS1005: '=>' expected. + } + ~ +!!! error TS1128: Declaration or statement expected. \ No newline at end of file diff --git a/tests/baselines/reference/parserComputedPropertyName38.js b/tests/baselines/reference/parserComputedPropertyName38.js index 487ff4078fd..e5c9512ad2d 100644 --- a/tests/baselines/reference/parserComputedPropertyName38.js +++ b/tests/baselines/reference/parserComputedPropertyName38.js @@ -4,10 +4,7 @@ class C { } //// [parserComputedPropertyName38.js] -var C = (function () { - function C() { - } - C.prototype[public] = function () { - }; - return C; -})(); +class C { +} +(() => { +}); diff --git a/tests/baselines/reference/parserComputedPropertyName39.js b/tests/baselines/reference/parserComputedPropertyName39.js index c37312f0034..cee81ccc3d0 100644 --- a/tests/baselines/reference/parserComputedPropertyName39.js +++ b/tests/baselines/reference/parserComputedPropertyName39.js @@ -6,10 +6,7 @@ class C { //// [parserComputedPropertyName39.js] "use strict"; -var C = (function () { - function C() { - } - return C; -})(); +class C { +} (() => { }); diff --git a/tests/baselines/reference/parserComputedPropertyName40.js b/tests/baselines/reference/parserComputedPropertyName40.js index 5f6381360fc..417e37067d1 100644 --- a/tests/baselines/reference/parserComputedPropertyName40.js +++ b/tests/baselines/reference/parserComputedPropertyName40.js @@ -4,10 +4,7 @@ class C { } //// [parserComputedPropertyName40.js] -var C = (function () { - function C() { +class C { + [a ? "" : ""]() { } - C.prototype[a ? "" : ""] = function () { - }; - return C; -})(); +} diff --git a/tests/baselines/reference/parserComputedPropertyName7.js b/tests/baselines/reference/parserComputedPropertyName7.js index 70ed8b7b073..aa18db09bc6 100644 --- a/tests/baselines/reference/parserComputedPropertyName7.js +++ b/tests/baselines/reference/parserComputedPropertyName7.js @@ -4,8 +4,5 @@ class C { } //// [parserComputedPropertyName7.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserComputedPropertyName8.js b/tests/baselines/reference/parserComputedPropertyName8.js index 4b79c459663..bab7c3198bd 100644 --- a/tests/baselines/reference/parserComputedPropertyName8.js +++ b/tests/baselines/reference/parserComputedPropertyName8.js @@ -4,8 +4,5 @@ class C { } //// [parserComputedPropertyName8.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserComputedPropertyName9.js b/tests/baselines/reference/parserComputedPropertyName9.js index 4b62cc0ecd9..3ba028a4a1c 100644 --- a/tests/baselines/reference/parserComputedPropertyName9.js +++ b/tests/baselines/reference/parserComputedPropertyName9.js @@ -4,8 +4,5 @@ class C { } //// [parserComputedPropertyName9.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserSuperExpression1.js b/tests/baselines/reference/parserSuperExpression1.js index d0d7f4dcd52..0d312f79104 100644 --- a/tests/baselines/reference/parserSuperExpression1.js +++ b/tests/baselines/reference/parserSuperExpression1.js @@ -18,7 +18,7 @@ var C = (function () { function C() { } C.prototype.foo = function () { - super.foo.call(this); + _super.foo.call(this); }; return C; })(); @@ -30,7 +30,7 @@ var M1; function C() { } C.prototype.foo = function () { - super.foo.call(this); + _super.foo.call(this); }; return C; })(); diff --git a/tests/baselines/reference/parserSuperExpression2.js b/tests/baselines/reference/parserSuperExpression2.js index 8d0c6cf3698..7a77c28ef52 100644 --- a/tests/baselines/reference/parserSuperExpression2.js +++ b/tests/baselines/reference/parserSuperExpression2.js @@ -10,7 +10,7 @@ var C = (function () { function C() { } C.prototype.M = function () { - super..call(this, 0); + _super..call(this, 0); }; return C; })(); diff --git a/tests/baselines/reference/parserSuperExpression4.js b/tests/baselines/reference/parserSuperExpression4.js index a36981416df..46ffc65f57c 100644 --- a/tests/baselines/reference/parserSuperExpression4.js +++ b/tests/baselines/reference/parserSuperExpression4.js @@ -18,7 +18,7 @@ var C = (function () { function C() { } C.prototype.foo = function () { - super.foo = 1; + _super.foo = 1; }; return C; })(); @@ -30,7 +30,7 @@ var M1; function C() { } C.prototype.foo = function () { - super.foo = 1; + _super.foo = 1; }; return C; })(); diff --git a/tests/baselines/reference/parserSymbolIndexer2.js b/tests/baselines/reference/parserSymbolIndexer2.js index 563614e1c8c..4bfe400de53 100644 --- a/tests/baselines/reference/parserSymbolIndexer2.js +++ b/tests/baselines/reference/parserSymbolIndexer2.js @@ -4,8 +4,5 @@ class C { } //// [parserSymbolIndexer2.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserSymbolIndexer3.js b/tests/baselines/reference/parserSymbolIndexer3.js index 917945193ae..36247ea2a13 100644 --- a/tests/baselines/reference/parserSymbolIndexer3.js +++ b/tests/baselines/reference/parserSymbolIndexer3.js @@ -4,8 +4,5 @@ class C { } //// [parserSymbolIndexer3.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserSymbolProperty5.js b/tests/baselines/reference/parserSymbolProperty5.js index 922e1fb0323..a8b1d564fa8 100644 --- a/tests/baselines/reference/parserSymbolProperty5.js +++ b/tests/baselines/reference/parserSymbolProperty5.js @@ -4,8 +4,5 @@ class C { } //// [parserSymbolProperty5.js] -var C = (function () { - function C() { - } - return C; -})(); +class C { +} diff --git a/tests/baselines/reference/parserSymbolProperty6.js b/tests/baselines/reference/parserSymbolProperty6.js index cbc06cd2951..d2aa55fe085 100644 --- a/tests/baselines/reference/parserSymbolProperty6.js +++ b/tests/baselines/reference/parserSymbolProperty6.js @@ -4,9 +4,8 @@ class C { } //// [parserSymbolProperty6.js] -var C = (function () { - function C() { +class C { + constructor() { this[Symbol.toStringTag] = ""; } - return C; -})(); +} diff --git a/tests/baselines/reference/parserSymbolProperty7.js b/tests/baselines/reference/parserSymbolProperty7.js index 9d34b9e3bce..a3061ee1b58 100644 --- a/tests/baselines/reference/parserSymbolProperty7.js +++ b/tests/baselines/reference/parserSymbolProperty7.js @@ -4,10 +4,7 @@ class C { } //// [parserSymbolProperty7.js] -var C = (function () { - function C() { +class C { + [Symbol.toStringTag]() { } - C.prototype[Symbol.toStringTag] = function () { - }; - return C; -})(); +} diff --git a/tests/baselines/reference/properties.js.map b/tests/baselines/reference/properties.js.map index 6e68d36e346..e55d2942734 100644 --- a/tests/baselines/reference/properties.js.map +++ b/tests/baselines/reference/properties.js.map @@ -1,2 +1,2 @@ //// [properties.js.map] -{"version":3,"file":"properties.js","sourceRoot":"","sources":["properties.ts"],"names":["MyClass","MyClass.constructor","MyClass.Count"],"mappings":"AACA;IAAAA;IAWAC,CAACA;IATGD,sBAAWA,0BAAKA;aAAhBA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;aAEDF,UAAiBA,KAAaA;YAE1BE,EAAEA;QACNA,CAACA;;;OALAF;IAMLA,cAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file +{"version":3,"file":"properties.js","sourceRoot":"","sources":["properties.ts"],"names":["MyClass","MyClass.constructor","MyClass.Count"],"mappings":"AACA;IAAAA;IAWAC,CAACA;IATcD,gDAAKA;aAAhBA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;aAEDF,UAAiBA,KAAaA;YAE1BE,EAAEA;QACNA,CAACA;;;OALAF;IAMLA,cAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/properties.sourcemap.txt b/tests/baselines/reference/properties.sourcemap.txt index 9ff77cc2c5d..caf72da0b7b 100644 --- a/tests/baselines/reference/properties.sourcemap.txt +++ b/tests/baselines/reference/properties.sourcemap.txt @@ -43,14 +43,11 @@ sourceFile:properties.ts --- >>> Object.defineProperty(MyClass.prototype, "Count", { 1->^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> -2 > public get -3 > Count -1->Emitted(4, 5) Source(4, 5) + SourceIndex(0) name (MyClass) -2 >Emitted(4, 27) Source(4, 16) + SourceIndex(0) name (MyClass) -3 >Emitted(4, 53) Source(4, 21) + SourceIndex(0) name (MyClass) +2 > Count +1->Emitted(4, 5) Source(4, 16) + SourceIndex(0) name (MyClass) +2 >Emitted(4, 53) Source(4, 21) + SourceIndex(0) name (MyClass) --- >>> get: function () { 1 >^^^^^^^^^^^^^ diff --git a/tests/baselines/reference/sourceMapValidationClass.js.map b/tests/baselines/reference/sourceMapValidationClass.js.map index 8693cf5d0fe..79ae9de95ee 100644 --- a/tests/baselines/reference/sourceMapValidationClass.js.map +++ b/tests/baselines/reference/sourceMapValidationClass.js.map @@ -1,2 +1,2 @@ //// [sourceMapValidationClass.js.map] -{"version":3,"file":"sourceMapValidationClass.js","sourceRoot":"","sources":["sourceMapValidationClass.ts"],"names":["Greeter","Greeter.constructor","Greeter.greet","Greeter.fn","Greeter.greetings"],"mappings":"AAAA;IACIA,iBAAmBA,QAAgBA;QAAEC,WAAcA;aAAdA,WAAcA,CAAdA,sBAAcA,CAAdA,IAAcA;YAAdA,0BAAcA;;QAAhCA,aAAQA,GAARA,QAAQA,CAAQA;QAM3BA,OAAEA,GAAWA,EAAEA,CAACA;IALxBA,CAACA;IACDD,uBAAKA,GAALA;QACIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;IAC5CA,CAACA;IAGOF,oBAAEA,GAAVA;QACIG,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;IACzBA,CAACA;IACDH,sBAAIA,8BAASA;aAAbA;YACII,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;QACzBA,CAACA;aACDJ,UAAcA,SAAiBA;YAC3BI,IAAIA,CAACA,QAAQA,GAAGA,SAASA,CAACA;QAC9BA,CAACA;;;OAHAJ;IAILA,cAACA;AAADA,CAACA,AAjBD,IAiBC"} \ No newline at end of file +{"version":3,"file":"sourceMapValidationClass.js","sourceRoot":"","sources":["sourceMapValidationClass.ts"],"names":["Greeter","Greeter.constructor","Greeter.greet","Greeter.fn","Greeter.greetings"],"mappings":"AAAA;IACIA,iBAAmBA,QAAgBA;QAAEC,WAAcA;aAAdA,WAAcA,CAAdA,sBAAcA,CAAdA,IAAcA;YAAdA,0BAAcA;;QAAhCA,aAAQA,GAARA,QAAQA,CAAQA;QAM3BA,OAAEA,GAAWA,EAAEA,CAACA;IALxBA,CAACA;IACDD,uBAAKA,GAALA;QACIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;IAC5CA,CAACA;IAGOF,oBAAEA,GAAVA;QACIG,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;IACzBA,CAACA;IACGH,oDAASA;aAAbA;YACII,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;QACzBA,CAACA;aACDJ,UAAcA,SAAiBA;YAC3BI,IAAIA,CAACA,QAAQA,GAAGA,SAASA,CAACA;QAC9BA,CAACA;;;OAHAJ;IAILA,cAACA;AAADA,CAACA,AAjBD,IAiBC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt b/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt index 0e019b487bb..d4c4e0ed365 100644 --- a/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt @@ -223,15 +223,12 @@ sourceFile:sourceMapValidationClass.ts --- >>> Object.defineProperty(Greeter.prototype, "greetings", { 1->^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^^ -3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> - > -2 > get -3 > greetings -1->Emitted(16, 5) Source(12, 5) + SourceIndex(0) name (Greeter) -2 >Emitted(16, 27) Source(12, 9) + SourceIndex(0) name (Greeter) -3 >Emitted(16, 57) Source(12, 18) + SourceIndex(0) name (Greeter) + > get +2 > greetings +1->Emitted(16, 5) Source(12, 9) + SourceIndex(0) name (Greeter) +2 >Emitted(16, 57) Source(12, 18) + SourceIndex(0) name (Greeter) --- >>> get: function () { 1 >^^^^^^^^^^^^^ diff --git a/tests/baselines/reference/super.js b/tests/baselines/reference/super.js index 5c3102cd877..453eb820ddb 100644 --- a/tests/baselines/reference/super.js +++ b/tests/baselines/reference/super.js @@ -80,7 +80,7 @@ var Base2 = (function () { function Base2() { } Base2.prototype.foo = function () { - super.foo.call(this); + _super.foo.call(this); }; return Base2; })(); diff --git a/tests/baselines/reference/super1.js b/tests/baselines/reference/super1.js index acc5b4072f5..ab982aa8fdf 100644 --- a/tests/baselines/reference/super1.js +++ b/tests/baselines/reference/super1.js @@ -166,7 +166,7 @@ var Base4; function Sub4E() { } Sub4E.prototype.x = function () { - return super.x.call(this); + return _super.x.call(this); }; return Sub4E; })(); diff --git a/tests/baselines/reference/superAccess2.js b/tests/baselines/reference/superAccess2.js index cd3d9c63e41..259afb1af0f 100644 --- a/tests/baselines/reference/superAccess2.js +++ b/tests/baselines/reference/superAccess2.js @@ -64,6 +64,6 @@ var Q = (function (_super) { _super.x.call(this); // error _super.y.call(this); }; - Q.yy = super.; // error for static initializer accessing super + Q.yy = _super.; // error for static initializer accessing super return Q; })(P); diff --git a/tests/baselines/reference/superErrors.js b/tests/baselines/reference/superErrors.js index 2dc2db1a3d4..2b1a5082617 100644 --- a/tests/baselines/reference/superErrors.js +++ b/tests/baselines/reference/superErrors.js @@ -60,14 +60,14 @@ var __extends = this.__extends || function (d, b) { }; function foo() { // super in a non class context - var x = super.; + var x = _super.; var y = function () { - return super.; + return _super.; }; var z = function () { return function () { return function () { - return super.; + return _super.; }; }; }; @@ -88,18 +88,18 @@ var RegisteredUser = (function (_super) { this.name = "Frank"; // super call in an inner function in a constructor function inner() { - super.sayHello.call(this); + _super.sayHello.call(this); } // super call in a lambda in an inner function in a constructor function inner2() { var x = function () { - return super.sayHello.call(this); + return _super.sayHello.call(this); }; } // super call in a lambda in a function expression in a constructor (function () { return function () { - return super.; + return _super.; }; })(); } @@ -109,13 +109,13 @@ var RegisteredUser = (function (_super) { // super call in a lambda in an inner function in a method function inner() { var x = function () { - return super.sayHello.call(this); + return _super.sayHello.call(this); }; } // super call in a lambda in a function expression in a constructor (function () { return function () { - return super.; + return _super.; }; })(); }; diff --git a/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js b/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js index 48ae609cdc6..c4ced2a9dcc 100644 --- a/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js +++ b/tests/baselines/reference/super_inside-object-literal-getters-and-setters.js @@ -39,13 +39,13 @@ var ObjectLiteral; var ThisInObjectLiteral = { _foo: '1', get foo() { - return super._foo; + return _super._foo; }, set foo(value) { - super._foo = value; + _super._foo = value; }, test: function () { - return super._foo; + return _super._foo; } }; })(ObjectLiteral || (ObjectLiteral = {})); @@ -65,7 +65,7 @@ var SuperObjectTest = (function (_super) { SuperObjectTest.prototype.testing = function () { var test = { get F() { - return super.test.call(this); + return _super.test.call(this); } }; }; diff --git a/tests/baselines/reference/symbolDeclarationEmit11.js b/tests/baselines/reference/symbolDeclarationEmit11.js index 8af17c95815..599f7393f4b 100644 --- a/tests/baselines/reference/symbolDeclarationEmit11.js +++ b/tests/baselines/reference/symbolDeclarationEmit11.js @@ -8,8 +8,6 @@ class C { //// [symbolDeclarationEmit11.js] class C { - constructor() { - } static [Symbol.toPrimitive]() { } static get [Symbol.isRegExp]() { diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts deleted file mode 100644 index c7fd43cb9e2..00000000000 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithExport.ts +++ /dev/null @@ -1,8 +0,0 @@ -// @target: es6 -export class C { - foo(y: string, ...args: any) { } -} - -export default class D { - bar(k = 10) {} -} \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts index ff94b6c9617..ac9ffd50fd6 100644 --- a/tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames24_ES5.ts @@ -5,7 +5,5 @@ class Base { } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [super.bar()]() { } } \ No newline at end of file diff --git a/tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts b/tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts index 4b0d794b1a7..3b2f66fe588 100644 --- a/tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts +++ b/tests/cases/conformance/es6/computedProperties/computedPropertyNames26_ES5.ts @@ -5,8 +5,6 @@ class Base { } } class C extends Base { - // Gets emitted as super, not _super, which is consistent with - // use of super in static properties initializers. [ { [super.bar()]: 1 }[0] ]() { } From e573461745b52e23490fdd6aa3ec98323846f0d3 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 16 Mar 2015 14:43:53 -0700 Subject: [PATCH 22/26] Address code review. Use-before-def check will be added to separate work item --- src/compiler/checker.ts | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index feb95b4da16..05c6e71ef43 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5696,29 +5696,6 @@ module ts { if (!links.resolvedType) { links.resolvedType = checkExpression(node.expression); - // Disallow using a static property in computedPropertyName because classDeclaration is bound lexically in ES6 - // and its static property assignment will be emitted after classDeclaration. - // Therefore, using static property inside computedPropertyName will cause an use-before-definition error - // Example: - // * TypeScript - // class C { - // static p = 10; - // [C.p]() {} - // } - // * JavaScript - // class C { - // [C.p]() {} // Use before definition error - // } - // C.p = 10; - if (links.resolvedSymbol) { - var declarations = links.resolvedSymbol.declarations; - forEach(declarations, declaration => { - if (declaration.flags & NodeFlags.Static) { - error(node, Diagnostics.A_computed_property_name_cannot_reference_a_static_property); - } - }); - } - // This will allow types number, string, symbol or any. It will also allow enums, the unknown // type, and any union of these types (like string | number). if (!allConstituentTypesHaveKind(links.resolvedType, TypeFlags.Any | TypeFlags.NumberLike | TypeFlags.StringLike | TypeFlags.ESSymbol)) { @@ -11891,9 +11868,7 @@ module ts { var nameText = declarationNameToString(identifier); // Always report 'eval' and 'arguments' invalid usage in strict mode code regardless of parser diagnostics - var sourceFile = getSourceFileOfNode(identifier); - diagnostics.add(createDiagnosticForNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText)); - return true; + return grammarErrorOnNode(identifier, Diagnostics.Invalid_use_of_0_in_strict_mode, nameText); } } } From 88933d54cc24eb98f1013e0d09aafacade4a0374 Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 16 Mar 2015 15:20:40 -0700 Subject: [PATCH 23/26] Address code review --- src/compiler/emitter.ts | 66 ++++++++----------- src/compiler/parser.ts | 11 +--- ...PropertyNamesWithStaticProperty.errors.txt | 22 ------- ...putedPropertyNamesWithStaticProperty.types | 29 ++++++++ tests/baselines/reference/properties.js.map | 2 +- .../reference/properties.sourcemap.txt | 11 ++-- .../reference/sourceMapValidationClass.js.map | 2 +- .../sourceMapValidationClass.sourcemap.txt | 13 ++-- 8 files changed, 77 insertions(+), 79 deletions(-) delete mode 100644 tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt create mode 100644 tests/baselines/reference/computedPropertyNamesWithStaticProperty.types diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index a079994e5c8..8e53b3e96c4 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2630,7 +2630,6 @@ module ts { } function emitSuper(node: Node) { - debugger; if (languageVersion >= ScriptTarget.ES6) { write("super"); } @@ -2639,9 +2638,6 @@ module ts { if (flags & NodeCheckFlags.SuperInstance) { write("_super.prototype"); } - else if ((flags & NodeCheckFlags.SuperStatic) || (node.parent.kind === SyntaxKind.Constructor)) { - write("_super"); - } else { write("_super"); } @@ -4403,23 +4399,7 @@ module ts { emitComputedPropertyName(memberName); } else { - // For ES6 and above, we want to emit memberName by itself without prefix ".", - // For ES5 and below, we want to prefix memberName with ".". For example, - // Typescript: - // class C { - // x = 10; - // foo () {} - // } - // Javascript: - // var C = (function () { - // function C() { - // this.x = 10; // Property "x" need to be prefixed with "." - // } - // C.prototype.foo = function() {}; // Similarly property "foo" need to be prefixed with "." - // } - if (languageVersion < ScriptTarget.ES6 || memberName.parent.kind === SyntaxKind.PropertyDeclaration) { - write("."); - } + write("."); emitNodeWithoutSourceMap(memberName); } } @@ -4458,14 +4438,18 @@ module ts { writeLine(); emitLeadingComments(member); emitStart(member); + emitStart((member).name); emitDeclarationName(node); if (!(member.flags & NodeFlags.Static)) { write(".prototype"); } emitMemberAccessForPropertyName((member).name); + emitEnd((member).name); write(" = "); + emitStart(member); emitFunctionDeclaration(member); emitEnd(member); + emitEnd(member); write(";"); emitTrailingComments(member); } @@ -4475,12 +4459,14 @@ module ts { writeLine(); emitStart(member); write("Object.defineProperty("); + emitStart((member).name); emitDeclarationName(node); if (!(member.flags & NodeFlags.Static)) { write(".prototype"); } write(", "); emitExpressionForPropertyName((member).name); + emitEnd((member).name); write(", {"); increaseIndent(); if (accessors.getAccessor) { @@ -4531,7 +4517,7 @@ module ts { if (member.flags & NodeFlags.Static) { write("static "); } - emitMemberAccessForPropertyName((member).name); + emit((member).name); emitSignatureAndBody(member); emitEnd(member); emitTrailingComments(member); @@ -4539,6 +4525,7 @@ module ts { else if (member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { var accessors = getAllAccessorDeclarations(node.members, member); if (member === accessors.firstAccessor) { + writeLine(); if (accessors.getAccessor) { writeLine(); emitLeadingComments(accessors.getAccessor); @@ -4547,7 +4534,7 @@ module ts { write("static "); } write("get "); - emitMemberAccessForPropertyName((member).name); + emit((member).name); emitSignatureAndBody(accessors.getAccessor); emitEnd(accessors.getAccessor); emitTrailingComments(accessors.getAccessor); @@ -4561,7 +4548,7 @@ module ts { write("static "); } write("set "); - emitMemberAccessForPropertyName((member).name); + emit((member).name); emitSignatureAndBody(accessors.setAccessor); emitEnd(accessors.setAccessor); emitTrailingComments(accessors.setAccessor);; @@ -4572,42 +4559,42 @@ module ts { } function emitConstructor(node: ClassDeclaration, baseTypeNode: TypeReferenceNode) { - debugger; - var saveTempCount = tempCount; - var saveTempVariables = tempVariables; - var saveTempParameters = tempParameters; + let saveTempCount = tempCount; + let saveTempVariables = tempVariables; + let saveTempParameters = tempParameters; tempCount = 0; tempVariables = undefined; tempParameters = undefined; - var popFrame = enterNameScope(); + let popFrame = enterNameScope(); // Check if we have property assignment inside class declaration. // If there is property assignment, we need to emit constructor whether users define it or not // If there is no property assignment, we can omit constructor if users do not define it - var hasPropertyAssignment = false; + let hasInstancePropertyWithInitializer = false; // Emit the constructor overload pinned comments forEach(node.members, member => { if (member.kind === SyntaxKind.Constructor && !(member).body) { emitPinnedOrTripleSlashComments(member); } - if (member.kind === SyntaxKind.PropertyDeclaration && (member).initializer) { - hasPropertyAssignment = true; + // Check if there is any non-static property assignment + if (member.kind === SyntaxKind.PropertyDeclaration && (member).initializer && (member.flags & NodeFlags.Static) === 0) { + hasInstancePropertyWithInitializer = true; } }); - var ctor = getFirstConstructorWithBody(node); + let ctor = getFirstConstructorWithBody(node); // For target ES6 and above, if there is no user-defined constructor and there is no property assignment // do not emit constructor in class declaration. - if (languageVersion >= ScriptTarget.ES6 && !ctor && !hasPropertyAssignment) { + if (languageVersion >= ScriptTarget.ES6 && !ctor && !hasInstancePropertyWithInitializer) { return; } if (ctor) { emitLeadingComments(ctor); } - emitStart(ctor || node); + emitStart(ctor || node); if (languageVersion < ScriptTarget.ES6) { write("function "); @@ -4639,7 +4626,7 @@ module ts { scopeEmitStart(node, "constructor"); increaseIndent(); if (ctor) { - emitDetachedComments((ctor.body).statements); + emitDetachedComments(ctor.body.statements); } emitCaptureThisForNodeIfNecessary(node); if (ctor) { @@ -4662,10 +4649,12 @@ module ts { emitEnd(baseTypeNode); } } - emitMemberAssignments(node, /*nonstatic*/0); + emitMemberAssignments(node, /*staticFlag*/0); if (ctor) { var statements: Node[] = (ctor.body).statements; - if (superCall) statements = statements.slice(1); + if (superCall) { + statements = statements.slice(1); + } emitLines(statements); } emitTempDeclarations(/*newLine*/ true); @@ -4696,6 +4685,7 @@ module ts { write("default "); } } + write("class "); emitDeclarationName(node); var baseTypeNode = getClassBaseTypeNode(node); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 5a07b22153d..48ece8b1b79 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -4518,8 +4518,8 @@ module ts { function parseClassDeclaration(fullStart: number, modifiers: ModifiersArray): ClassDeclaration { // In ES6 specification, All parts of a ClassDeclaration or a ClassExpression are strict mode code + let savedStrictModeContext = inStrictModeContext(); if (languageVersion >= ScriptTarget.ES6) { - var savedStrictModeContext = inStrictModeContext(); setStrictModeContext(true); } @@ -4545,13 +4545,8 @@ module ts { } var finishedNode = finishNode(node); - if (languageVersion >= ScriptTarget.ES6) { - setStrictModeContext(savedStrictModeContext); - return finishedNode; - } - else { - return finishedNode; - } + setStrictModeContext(savedStrictModeContext); + return finishedNode; } function parseHeritageClauses(isClassHeritageClause: boolean): NodeArray { diff --git a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt deleted file mode 100644 index f078365f600..00000000000 --- a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.errors.txt +++ /dev/null @@ -1,22 +0,0 @@ -tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts(3,9): error TS1200: A computed property name cannot reference a static property -tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts(6,9): error TS1200: A computed property name cannot reference a static property -tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts(9,5): error TS1200: A computed property name cannot reference a static property - - -==== tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts (3 errors) ==== - class C { - static staticProp = 10; - get [C.staticProp]() { - ~~~~~~~~~~~~~~ -!!! error TS1200: A computed property name cannot reference a static property - return "hello"; - } - set [C.staticProp](x: string) { - ~~~~~~~~~~~~~~ -!!! error TS1200: A computed property name cannot reference a static property - var y = x; - } - [C.staticProp]() { } - ~~~~~~~~~~~~~~ -!!! error TS1200: A computed property name cannot reference a static property - } \ No newline at end of file diff --git a/tests/baselines/reference/computedPropertyNamesWithStaticProperty.types b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.types new file mode 100644 index 00000000000..b23d986f894 --- /dev/null +++ b/tests/baselines/reference/computedPropertyNamesWithStaticProperty.types @@ -0,0 +1,29 @@ +=== tests/cases/conformance/es6/computedProperties/computedPropertyNamesWithStaticProperty.ts === +class C { +>C : C + + static staticProp = 10; +>staticProp : number + + get [C.staticProp]() { +>C.staticProp : number +>C : typeof C +>staticProp : number + + return "hello"; + } + set [C.staticProp](x: string) { +>C.staticProp : number +>C : typeof C +>staticProp : number +>x : string + + var y = x; +>y : string +>x : string + } + [C.staticProp]() { } +>C.staticProp : number +>C : typeof C +>staticProp : number +} diff --git a/tests/baselines/reference/properties.js.map b/tests/baselines/reference/properties.js.map index e55d2942734..6e68d36e346 100644 --- a/tests/baselines/reference/properties.js.map +++ b/tests/baselines/reference/properties.js.map @@ -1,2 +1,2 @@ //// [properties.js.map] -{"version":3,"file":"properties.js","sourceRoot":"","sources":["properties.ts"],"names":["MyClass","MyClass.constructor","MyClass.Count"],"mappings":"AACA;IAAAA;IAWAC,CAACA;IATcD,gDAAKA;aAAhBA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;aAEDF,UAAiBA,KAAaA;YAE1BE,EAAEA;QACNA,CAACA;;;OALAF;IAMLA,cAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file +{"version":3,"file":"properties.js","sourceRoot":"","sources":["properties.ts"],"names":["MyClass","MyClass.constructor","MyClass.Count"],"mappings":"AACA;IAAAA;IAWAC,CAACA;IATGD,sBAAWA,0BAAKA;aAAhBA;YAEIE,MAAMA,CAACA,EAAEA,CAACA;QACdA,CAACA;aAEDF,UAAiBA,KAAaA;YAE1BE,EAAEA;QACNA,CAACA;;;OALAF;IAMLA,cAACA;AAADA,CAACA,AAXD,IAWC"} \ No newline at end of file diff --git a/tests/baselines/reference/properties.sourcemap.txt b/tests/baselines/reference/properties.sourcemap.txt index caf72da0b7b..9ff77cc2c5d 100644 --- a/tests/baselines/reference/properties.sourcemap.txt +++ b/tests/baselines/reference/properties.sourcemap.txt @@ -43,11 +43,14 @@ sourceFile:properties.ts --- >>> Object.defineProperty(MyClass.prototype, "Count", { 1->^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> -2 > Count -1->Emitted(4, 5) Source(4, 16) + SourceIndex(0) name (MyClass) -2 >Emitted(4, 53) Source(4, 21) + SourceIndex(0) name (MyClass) +2 > public get +3 > Count +1->Emitted(4, 5) Source(4, 5) + SourceIndex(0) name (MyClass) +2 >Emitted(4, 27) Source(4, 16) + SourceIndex(0) name (MyClass) +3 >Emitted(4, 53) Source(4, 21) + SourceIndex(0) name (MyClass) --- >>> get: function () { 1 >^^^^^^^^^^^^^ diff --git a/tests/baselines/reference/sourceMapValidationClass.js.map b/tests/baselines/reference/sourceMapValidationClass.js.map index 79ae9de95ee..8693cf5d0fe 100644 --- a/tests/baselines/reference/sourceMapValidationClass.js.map +++ b/tests/baselines/reference/sourceMapValidationClass.js.map @@ -1,2 +1,2 @@ //// [sourceMapValidationClass.js.map] -{"version":3,"file":"sourceMapValidationClass.js","sourceRoot":"","sources":["sourceMapValidationClass.ts"],"names":["Greeter","Greeter.constructor","Greeter.greet","Greeter.fn","Greeter.greetings"],"mappings":"AAAA;IACIA,iBAAmBA,QAAgBA;QAAEC,WAAcA;aAAdA,WAAcA,CAAdA,sBAAcA,CAAdA,IAAcA;YAAdA,0BAAcA;;QAAhCA,aAAQA,GAARA,QAAQA,CAAQA;QAM3BA,OAAEA,GAAWA,EAAEA,CAACA;IALxBA,CAACA;IACDD,uBAAKA,GAALA;QACIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;IAC5CA,CAACA;IAGOF,oBAAEA,GAAVA;QACIG,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;IACzBA,CAACA;IACGH,oDAASA;aAAbA;YACII,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;QACzBA,CAACA;aACDJ,UAAcA,SAAiBA;YAC3BI,IAAIA,CAACA,QAAQA,GAAGA,SAASA,CAACA;QAC9BA,CAACA;;;OAHAJ;IAILA,cAACA;AAADA,CAACA,AAjBD,IAiBC"} \ No newline at end of file +{"version":3,"file":"sourceMapValidationClass.js","sourceRoot":"","sources":["sourceMapValidationClass.ts"],"names":["Greeter","Greeter.constructor","Greeter.greet","Greeter.fn","Greeter.greetings"],"mappings":"AAAA;IACIA,iBAAmBA,QAAgBA;QAAEC,WAAcA;aAAdA,WAAcA,CAAdA,sBAAcA,CAAdA,IAAcA;YAAdA,0BAAcA;;QAAhCA,aAAQA,GAARA,QAAQA,CAAQA;QAM3BA,OAAEA,GAAWA,EAAEA,CAACA;IALxBA,CAACA;IACDD,uBAAKA,GAALA;QACIE,MAAMA,CAACA,MAAMA,GAAGA,IAAIA,CAACA,QAAQA,GAAGA,OAAOA,CAACA;IAC5CA,CAACA;IAGOF,oBAAEA,GAAVA;QACIG,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;IACzBA,CAACA;IACDH,sBAAIA,8BAASA;aAAbA;YACII,MAAMA,CAACA,IAAIA,CAACA,QAAQA,CAACA;QACzBA,CAACA;aACDJ,UAAcA,SAAiBA;YAC3BI,IAAIA,CAACA,QAAQA,GAAGA,SAASA,CAACA;QAC9BA,CAACA;;;OAHAJ;IAILA,cAACA;AAADA,CAACA,AAjBD,IAiBC"} \ No newline at end of file diff --git a/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt b/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt index d4c4e0ed365..0e019b487bb 100644 --- a/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt +++ b/tests/baselines/reference/sourceMapValidationClass.sourcemap.txt @@ -223,12 +223,15 @@ sourceFile:sourceMapValidationClass.ts --- >>> Object.defineProperty(Greeter.prototype, "greetings", { 1->^^^^ -2 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +2 > ^^^^^^^^^^^^^^^^^^^^^^ +3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 1-> - > get -2 > greetings -1->Emitted(16, 5) Source(12, 9) + SourceIndex(0) name (Greeter) -2 >Emitted(16, 57) Source(12, 18) + SourceIndex(0) name (Greeter) + > +2 > get +3 > greetings +1->Emitted(16, 5) Source(12, 5) + SourceIndex(0) name (Greeter) +2 >Emitted(16, 27) Source(12, 9) + SourceIndex(0) name (Greeter) +3 >Emitted(16, 57) Source(12, 18) + SourceIndex(0) name (Greeter) --- >>> get: function () { 1 >^^^^^^^^^^^^^ From 91c5bae6e5b86834b9dd88f7777ec4e5ddde971d Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 16 Mar 2015 15:41:51 -0700 Subject: [PATCH 24/26] Address code review --- src/compiler/emitter.ts | 42 ++++--------------- ...itClassDeclarationWithGetterSetterInES6.js | 21 ++++++++++ ...lassDeclarationWithGetterSetterInES6.types | 13 ++++++ ...DeclarationWithLiteralPropertyNameInES6.js | 37 ++++++++++++++++ ...larationWithLiteralPropertyNameInES6.types | 19 +++++++++ ...itClassDeclarationWithThisKeywordInES6.js} | 4 +- ...lassDeclarationWithThisKeywordInES6.types} | 2 +- ...rationWithTypeArgumentAndOverloadInES6.js} | 4 +- ...ionWithTypeArgumentAndOverloadInES6.types} | 2 +- tests/baselines/reference/symbolProperty44.js | 3 ++ ...itClassDeclarationWithGetterSetterInES6.ts | 11 +++++ ...DeclarationWithLiteralPropertyNameInES6.ts | 15 +++++++ ...itClassDeclarationWithThisKeywordInES6.ts} | 0 ...rationWithTypeArgumentAndOverloadInES6.ts} | 0 14 files changed, 134 insertions(+), 39 deletions(-) create mode 100644 tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.js create mode 100644 tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.types rename tests/baselines/reference/{emitClassDeclarationWithThisKeyword.js => emitClassDeclarationWithThisKeywordInES6.js} (79%) rename tests/baselines/reference/{emitClassDeclarationWithThisKeyword.types => emitClassDeclarationWithThisKeywordInES6.types} (89%) rename tests/baselines/reference/{emitClassDeclarationWithTypeArgumentAndOverload.js => emitClassDeclarationWithTypeArgumentAndOverloadInES6.js} (77%) rename tests/baselines/reference/{emitClassDeclarationWithTypeArgumentAndOverload.types => emitClassDeclarationWithTypeArgumentAndOverloadInES6.types} (88%) create mode 100644 tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithLiteralPropertyNameInES6.ts rename tests/cases/conformance/es6/classDeclaration/{emitClassDeclarationWithThisKeyword.ts => emitClassDeclarationWithThisKeywordInES6.ts} (100%) rename tests/cases/conformance/es6/classDeclaration/{emitClassDeclarationWithTypeArgumentAndOverload.ts => emitClassDeclarationWithTypeArgumentAndOverloadInES6.ts} (100%) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 8e53b3e96c4..fbaaf2493c7 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4511,50 +4511,26 @@ module ts { return emitPinnedOrTripleSlashComments(member); } + } + if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { writeLine(); emitLeadingComments(member); emitStart(member); if (member.flags & NodeFlags.Static) { write("static "); } + + if (member.kind === SyntaxKind.GetAccessor) { + write("get "); + } + else if (member.kind === SyntaxKind.SetAccessor) { + write("set "); + } emit((member).name); emitSignatureAndBody(member); emitEnd(member); emitTrailingComments(member); } - else if (member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { - var accessors = getAllAccessorDeclarations(node.members, member); - if (member === accessors.firstAccessor) { - writeLine(); - if (accessors.getAccessor) { - writeLine(); - emitLeadingComments(accessors.getAccessor); - emitStart(accessors.getAccessor); - if (member.flags & NodeFlags.Static) { - write("static "); - } - write("get "); - emit((member).name); - emitSignatureAndBody(accessors.getAccessor); - emitEnd(accessors.getAccessor); - emitTrailingComments(accessors.getAccessor); - } - if (accessors.setAccessor) { - // We will only write new line if we just emit getAccessor - writeLine(); - emitLeadingComments(accessors.setAccessor); - emitStart(accessors.setAccessor); - if (member.flags & NodeFlags.Static) { - write("static "); - } - write("set "); - emit((member).name); - emitSignatureAndBody(accessors.setAccessor); - emitEnd(accessors.setAccessor); - emitTrailingComments(accessors.setAccessor);; - } - } - } }); } diff --git a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js index 55d72a8b8d5..68ccd1568ed 100644 --- a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js +++ b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.js @@ -10,6 +10,17 @@ class C { static get ["computedname"]() { return ""; } + get ["computedname"]() { + return ""; + } + get ["computedname"]() { + return ""; + } + + set ["computedname"](x: any) { + } + set ["computedname"](y: string) { + } set foo(a: string) { } static set bar(b: number) { } @@ -27,6 +38,16 @@ class C { static get ["computedname"]() { return ""; } + get ["computedname"]() { + return ""; + } + get ["computedname"]() { + return ""; + } + set ["computedname"](x) { + } + set ["computedname"](y) { + } set foo(a) { } static set bar(b) { diff --git a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types index 4e4673a228f..83d4fcd0d80 100644 --- a/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types +++ b/tests/baselines/reference/emitClassDeclarationWithGetterSetterInES6.types @@ -21,6 +21,19 @@ class C { static get ["computedname"]() { return ""; } + get ["computedname"]() { + return ""; + } + get ["computedname"]() { + return ""; + } + + set ["computedname"](x: any) { +>x : any + } + set ["computedname"](y: string) { +>y : string + } set foo(a: string) { } >foo : string diff --git a/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.js b/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.js new file mode 100644 index 00000000000..d82750f276f --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.js @@ -0,0 +1,37 @@ +//// [emitClassDeclarationWithLiteralPropertyNameInES6.ts] +class B { + "hello" = 10; + 0b110 = "world"; + 0o23534 = "WORLD"; + 20 = "twenty"; + "foo"() { } + 0b1110() {} + 11() { } + interface() { } + static "hi" = 10000; + static 22 = "twenty-two"; + static 0b101 = "binary"; + static 0o3235 = "octal"; +} + +//// [emitClassDeclarationWithLiteralPropertyNameInES6.js] +class B { + constructor() { + this["hello"] = 10; + this[0b110] = "world"; + this[0o23534] = "WORLD"; + this[20] = "twenty"; + } + "foo"() { + } + 0b1110() { + } + 11() { + } + interface() { + } +} +B["hi"] = 10000; +B[22] = "twenty-two"; +B[0b101] = "binary"; +B[0o3235] = "octal"; diff --git a/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.types b/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.types new file mode 100644 index 00000000000..65ba8f7d2b9 --- /dev/null +++ b/tests/baselines/reference/emitClassDeclarationWithLiteralPropertyNameInES6.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithLiteralPropertyNameInES6.ts === +class B { +>B : B + + "hello" = 10; + 0b110 = "world"; + 0o23534 = "WORLD"; + 20 = "twenty"; + "foo"() { } + 0b1110() {} + 11() { } + interface() { } +>interface : () => void + + static "hi" = 10000; + static 22 = "twenty-two"; + static 0b101 = "binary"; + static 0o3235 = "octal"; +} diff --git a/tests/baselines/reference/emitClassDeclarationWithThisKeyword.js b/tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.js similarity index 79% rename from tests/baselines/reference/emitClassDeclarationWithThisKeyword.js rename to tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.js index de100457aa9..14f74682c00 100644 --- a/tests/baselines/reference/emitClassDeclarationWithThisKeyword.js +++ b/tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.js @@ -1,4 +1,4 @@ -//// [emitClassDeclarationWithThisKeyword.ts] +//// [emitClassDeclarationWithThisKeywordInES6.ts] class B { x = 10; constructor() { @@ -18,7 +18,7 @@ class B { } } -//// [emitClassDeclarationWithThisKeyword.js] +//// [emitClassDeclarationWithThisKeywordInES6.js] class B { constructor() { this.x = 10; diff --git a/tests/baselines/reference/emitClassDeclarationWithThisKeyword.types b/tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.types similarity index 89% rename from tests/baselines/reference/emitClassDeclarationWithThisKeyword.types rename to tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.types index ebb6f26598d..bb0f7e99939 100644 --- a/tests/baselines/reference/emitClassDeclarationWithThisKeyword.types +++ b/tests/baselines/reference/emitClassDeclarationWithThisKeywordInES6.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts === +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeywordInES6.ts === class B { >B : B diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.js b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.js similarity index 77% rename from tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.js rename to tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.js index 69801d6be12..8dc5b6cddaa 100644 --- a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.js +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.js @@ -1,4 +1,4 @@ -//// [emitClassDeclarationWithTypeArgumentAndOverload.ts] +//// [emitClassDeclarationWithTypeArgumentAndOverloadInES6.ts] class B { x: T; B: T; @@ -22,7 +22,7 @@ class B { } } -//// [emitClassDeclarationWithTypeArgumentAndOverload.js] +//// [emitClassDeclarationWithTypeArgumentAndOverloadInES6.js] class B { constructor(a) { this.B = a; diff --git a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.types b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.types similarity index 88% rename from tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.types rename to tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.types index 8b0feb72d2b..ba515168a5d 100644 --- a/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverload.types +++ b/tests/baselines/reference/emitClassDeclarationWithTypeArgumentAndOverloadInES6.types @@ -1,4 +1,4 @@ -=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts === +=== tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverloadInES6.ts === class B { >B : B >T : T diff --git a/tests/baselines/reference/symbolProperty44.js b/tests/baselines/reference/symbolProperty44.js index a3de33640af..1f4aaf73b3c 100644 --- a/tests/baselines/reference/symbolProperty44.js +++ b/tests/baselines/reference/symbolProperty44.js @@ -13,4 +13,7 @@ class C { get [Symbol.hasInstance]() { return ""; } + get [Symbol.hasInstance]() { + return ""; + } } diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts index 18ff3fa424d..70c0b35763e 100644 --- a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithGetterSetterInES6.ts @@ -10,6 +10,17 @@ class C { static get ["computedname"]() { return ""; } + get ["computedname"]() { + return ""; + } + get ["computedname"]() { + return ""; + } + + set ["computedname"](x: any) { + } + set ["computedname"](y: string) { + } set foo(a: string) { } static set bar(b: number) { } diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithLiteralPropertyNameInES6.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithLiteralPropertyNameInES6.ts new file mode 100644 index 00000000000..87114db7739 --- /dev/null +++ b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithLiteralPropertyNameInES6.ts @@ -0,0 +1,15 @@ +// @target: es6 +class B { + "hello" = 10; + 0b110 = "world"; + 0o23534 = "WORLD"; + 20 = "twenty"; + "foo"() { } + 0b1110() {} + 11() { } + interface() { } + static "hi" = 10000; + static 22 = "twenty-two"; + static 0b101 = "binary"; + static 0o3235 = "octal"; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeywordInES6.ts similarity index 100% rename from tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeyword.ts rename to tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithThisKeywordInES6.ts diff --git a/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts b/tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverloadInES6.ts similarity index 100% rename from tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverload.ts rename to tests/cases/conformance/es6/classDeclaration/emitClassDeclarationWithTypeArgumentAndOverloadInES6.ts From c51983df3cae44d239454f554a9d6758c6379e2a Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 16 Mar 2015 15:48:03 -0700 Subject: [PATCH 25/26] Address code review --- src/compiler/emitter.ts | 4 +--- tests/cases/unittests/incrementalParser.ts | 2 -- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index fbaaf2493c7..196aeabe638 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -3189,9 +3189,7 @@ module ts { } else { write("("); - if (node.arguments.length) { - emitCommaList(node.arguments); - } + emitCommaList(node.arguments); write(")"); } } diff --git a/tests/cases/unittests/incrementalParser.ts b/tests/cases/unittests/incrementalParser.ts index 87c0c3701f3..422675e9e0a 100644 --- a/tests/cases/unittests/incrementalParser.ts +++ b/tests/cases/unittests/incrementalParser.ts @@ -686,7 +686,6 @@ module m3 { }\ }); it('Surrounding function declarations with block',() => { - debugger; var source = "declare function F1() { } export function F2() { } declare export function F3() { }" var oldText = ScriptSnapshot.fromString(source); @@ -723,7 +722,6 @@ module m3 { }\ }); it('Moving methods from object literal to class in strict mode', () => { - debugger; var source = "\"use strict\"; var v = { public A() { } public B() { } public C() { } }" var oldText = ScriptSnapshot.fromString(source); From 9b3fccd5c4885fc88e40a14fac6fa761a8739cff Mon Sep 17 00:00:00 2001 From: Yui T Date: Mon, 16 Mar 2015 16:24:40 -0700 Subject: [PATCH 26/26] Address code review; Use for..of and use if-statement --- src/compiler/emitter.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 522679adb0a..4cae7d0749c 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4706,14 +4706,11 @@ module ts { } function emitMemberFunctionsForES6AndHigher(node: ClassDeclaration) { - forEach(node.members, member => { - if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) { - if (!(member).body) { - return emitPinnedOrTripleSlashComments(member); - } - + for (let member of node.members) { + if ((member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature) && !(member).body) { + emitPinnedOrTripleSlashComments(member); } - if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { + else if (member.kind === SyntaxKind.MethodDeclaration || node.kind === SyntaxKind.MethodSignature || member.kind === SyntaxKind.GetAccessor || member.kind === SyntaxKind.SetAccessor) { writeLine(); emitLeadingComments(member); emitStart(member); @@ -4732,7 +4729,7 @@ module ts { emitEnd(member); emitTrailingComments(member); } - }); + } } function emitConstructor(node: ClassDeclaration, baseTypeNode: TypeReferenceNode) { @@ -4822,7 +4819,12 @@ module ts { if (baseTypeNode) { writeLine(); emitStart(baseTypeNode); - languageVersion < ScriptTarget.ES6 ? write("_super.apply(this, arguments);") : write("super(...args);"); + if (languageVersion < ScriptTarget.ES6) { + write("_super.apply(this, arguments);"); + } + else { + write("super(...args);"); + } emitEnd(baseTypeNode); } }