From f0826cfeaaa7d02c831fe7322f46b119fc7c0412 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Tue, 28 Aug 2018 10:35:16 +0200 Subject: [PATCH 1/4] Per-property super accessors in async functions. TypeScript must hoist accessors for super properties when converting async method bodies to the `__awaiter` pattern for targets before ES2016. Previously, TypeScript would reify all property accesses into element accesses, i.e. convert the property name into a string parameter and pass it to `super[...]`. That breaks optimizers like Closure Compiler or Uglify in advanced mode, when property renaming is enabled, as it mixes quoted and un-quoted property access (`super['x']` vs just `x` at the declaration site). This change creates a variable `_superProps` that contains accessors for each property accessed on super within the async method. This allows accessing the properties by name (instead of quoted string), which fixes the quoted/unquoted confusion. The change keeps the generic accessor for element access statements to match quoting behaviour. Fixes #21088. --- src/compiler/checker.ts | 20 +-- src/compiler/transformers/es2017.ts | 153 ++++++++++++++++-- src/compiler/transformers/esnext.ts | 97 +++++++---- .../asyncMethodWithSuperConflict_es6.js | 34 +++- .../asyncMethodWithSuperConflict_es6.symbols | 48 ++++-- .../asyncMethodWithSuperConflict_es6.types | 19 +++ .../reference/asyncMethodWithSuper_es2017.js | 11 +- .../asyncMethodWithSuper_es2017.symbols | 38 +++-- .../asyncMethodWithSuper_es2017.types | 11 ++ .../reference/asyncMethodWithSuper_es5.js | 11 +- .../asyncMethodWithSuper_es5.symbols | 38 +++-- .../reference/asyncMethodWithSuper_es5.types | 11 ++ .../reference/asyncMethodWithSuper_es6.js | 30 +++- .../asyncMethodWithSuper_es6.symbols | 38 +++-- .../reference/asyncMethodWithSuper_es6.types | 11 ++ ...ter.asyncGenerators.classMethods.es2015.js | 6 +- .../asyncMethodWithSuperConflict_es6.ts | 8 +- .../es2017/asyncMethodWithSuper_es2017.ts | 6 +- .../async/es5/asyncMethodWithSuper_es5.ts | 6 +- .../async/es6/asyncMethodWithSuper_es6.ts | 6 +- 20 files changed, 471 insertions(+), 131 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 8248042879034..eb29c5eba066d 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16180,9 +16180,9 @@ namespace ts { // // js // ... // asyncMethod() { - // const _super = name => super[name]; + // const _super_asyncMethod = name => super.asyncMethod; // return __awaiter(this, arguments, Promise, function *() { - // let x = yield _super("asyncMethod").call(this); + // let x = yield _super_asyncMethod.call(this); // return x; // }); // } @@ -16201,19 +16201,19 @@ namespace ts { // // js // ... // asyncMethod(ar) { - // const _super = (function (geti, seti) { - // const cache = Object.create(null); - // return name => cache[name] || (cache[name] = { get value() { return geti(name); }, set value(v) { seti(name, v); } }); - // })(name => super[name], (name, value) => super[name] = value); + // const _super_a = {get value() { return super.a; }, set value(v) { super.a = v; }}; + // const _super_b = {get value() { return super.b; }, set value(v) { super.b = v; }}; // return __awaiter(this, arguments, Promise, function *() { - // [_super("a").value, _super("b").value] = yield ar; + // [_super_a.value, _super_b.value] = yield ar; // }); // } // ... // - // This helper creates an object with a "value" property that wraps the `super` property or indexed access for both get and set. - // This is required for destructuring assignments, as a call expression cannot be used as the target of a destructuring assignment - // while a property access can. + // This helper creates an object with a "value" property that wraps the `super` property for both get and set. This is required for + // destructuring assignments, as a call expression cannot be used as the target of a destructuring assignment while a property + // access can. + // + // For element access expressions (`super[x]`), we emit a generic helper that forwards the element access in both situations. if (container.kind === SyntaxKind.MethodDeclaration && hasModifier(container, ModifierFlags.Async)) { if (isSuperProperty(node.parent) && isAssignmentTarget(node.parent)) { getNodeLinks(container).flags |= NodeCheckFlags.AsyncMethodWithSuperBinding; diff --git a/src/compiler/transformers/es2017.ts b/src/compiler/transformers/es2017.ts index f58a24fb0a9fa..8b2f5a700a046 100644 --- a/src/compiler/transformers/es2017.ts +++ b/src/compiler/transformers/es2017.ts @@ -32,6 +32,15 @@ namespace ts { let enclosingFunctionParameterNames: UnderscoreEscapedMap; + /** + * Keeps track of property names accessed on super (`super.x`) within async functions. + */ + let capturedSuperProperties: UnderscoreEscapedMap; + /** Whether the async function contains an element access on super (`super[x]`). */ + let hasSuperElementAccess: boolean; + /** A set of node IDs for generated super accessors (variable statements). */ + const substitutedSuperAccessors: boolean[] = []; + // Save the previous transformation hooks. const previousOnEmitNode = context.onEmitNode; const previousOnSubstituteNode = context.onSubstituteNode; @@ -53,10 +62,6 @@ namespace ts { } function visitor(node: Node): VisitResult { - if ((node.transformFlags & TransformFlags.ContainsES2017) === 0) { - return node; - } - switch (node.kind) { case SyntaxKind.AsyncKeyword: // ES2017 async modifier should be elided for targets < ES2017 @@ -77,6 +82,18 @@ namespace ts { case SyntaxKind.ArrowFunction: return visitArrowFunction(node); + case SyntaxKind.PropertyAccessExpression: + if (capturedSuperProperties && isPropertyAccessExpression(node) && node.expression.kind === SyntaxKind.SuperKeyword) { + capturedSuperProperties.set(node.name.escapedText, true); + } + return visitEachChild(node, visitor, context); + + case SyntaxKind.ElementAccessExpression: + if (capturedSuperProperties && (node).expression.kind === SyntaxKind.SuperKeyword) { + hasSuperElementAccess = true; + } + return visitEachChild(node, visitor, context); + default: return visitEachChild(node, visitor, context); } @@ -398,6 +415,11 @@ namespace ts { recordDeclarationName(parameter, enclosingFunctionParameterNames); } + const savedCapturedSuperProperties = capturedSuperProperties; + const savedHasSuperElementAccess = hasSuperElementAccess; + capturedSuperProperties = createUnderscoreEscapedMap(); + hasSuperElementAccess = false; + let result: ConciseBody; if (!isArrowFunction) { const statements: Statement[] = []; @@ -415,18 +437,26 @@ namespace ts { addStatementsAfterPrologue(statements, endLexicalEnvironment()); + // Minor optimization, emit `_super` helper to capture `super` access in an arrow. + // This step isn't needed if we eventually transform this to ES5. + const emitSuperHelpers = languageVersion >= ScriptTarget.ES2015 && resolver.getNodeCheckFlags(node) & (NodeCheckFlags.AsyncMethodWithSuperBinding | NodeCheckFlags.AsyncMethodWithSuper); + + if (emitSuperHelpers) { + enableSubstitutionForAsyncMethodsWithSuper(); + const variableStatement = createSuperAccessVariableStatement(resolver, node, capturedSuperProperties); + substitutedSuperAccessors[getNodeId(variableStatement)] = true; + addStatementsAfterPrologue(statements, [variableStatement]); + } + const block = createBlock(statements, /*multiLine*/ true); setTextRange(block, node.body); - // Minor optimization, emit `_super` helper to capture `super` access in an arrow. - // This step isn't needed if we eventually transform this to ES5. - if (languageVersion >= ScriptTarget.ES2015) { + if (emitSuperHelpers && hasSuperElementAccess) { + // Emit helpers for super element access expressions (`super[x]`). if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.AsyncMethodWithSuperBinding) { - enableSubstitutionForAsyncMethodsWithSuper(); addEmitHelper(block, advancedAsyncSuperHelper); } else if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.AsyncMethodWithSuper) { - enableSubstitutionForAsyncMethodsWithSuper(); addEmitHelper(block, asyncSuperHelper); } } @@ -452,6 +482,8 @@ namespace ts { } enclosingFunctionParameterNames = savedEnclosingFunctionParameterNames; + capturedSuperProperties = savedCapturedSuperProperties; + hasSuperElementAccess = savedHasSuperElementAccess; return result; } @@ -493,6 +525,8 @@ namespace ts { context.enableEmitNotification(SyntaxKind.GetAccessor); context.enableEmitNotification(SyntaxKind.SetAccessor); context.enableEmitNotification(SyntaxKind.Constructor); + // We need to be notified when entering the generated accessor arrow functions. + context.enableEmitNotification(SyntaxKind.VariableStatement); } } @@ -516,6 +550,14 @@ namespace ts { return; } } + // Disable substitution in the generated super accessor itself. + else if (enabledSubstitutions && substitutedSuperAccessors[getNodeId(node)]) { + const savedEnclosingSuperContainerFlags = enclosingSuperContainerFlags; + enclosingSuperContainerFlags = 0 as NodeCheckFlags; + previousOnEmitNode(hint, node, emitCallback); + enclosingSuperContainerFlags = savedEnclosingSuperContainerFlags; + return; + } previousOnEmitNode(hint, node, emitCallback); } @@ -548,8 +590,10 @@ namespace ts { function substitutePropertyAccessExpression(node: PropertyAccessExpression) { if (node.expression.kind === SyntaxKind.SuperKeyword) { - return createSuperAccessInAsyncMethod( - createLiteral(idText(node.name)), + return setTextRange( + createPropertyAccess( + createFileLevelUniqueName("_superProps"), + node.name), node ); } @@ -558,7 +602,7 @@ namespace ts { function substituteElementAccessExpression(node: ElementAccessExpression) { if (node.expression.kind === SyntaxKind.SuperKeyword) { - return createSuperAccessInAsyncMethod( + return createSuperElementAccessInAsyncMethod( node.argumentExpression, node ); @@ -593,7 +637,7 @@ namespace ts { || kind === SyntaxKind.SetAccessor; } - function createSuperAccessInAsyncMethod(argumentExpression: Expression, location: TextRange): LeftHandSideExpression { + function createSuperElementAccessInAsyncMethod(argumentExpression: Expression, location: TextRange): LeftHandSideExpression { if (enclosingSuperContainerFlags & NodeCheckFlags.AsyncMethodWithSuperBinding) { return setTextRange( createPropertyAccess( @@ -620,6 +664,89 @@ namespace ts { } } + /** Creates a variable named `_superProps` with accessor properties for the given property names. */ + export function createSuperAccessVariableStatement(resolver: EmitResolver, node: FunctionLikeDeclaration, names: UnderscoreEscapedMap) { + // Create a variable declaration with a getter/setter (if binding) definition for each name: + // const _superProps = Object.create(null, { x: { get: () => super.x, set: (v) => super.x = v }, ... }); + const hasBinding = (resolver.getNodeCheckFlags(node) & NodeCheckFlags.AsyncMethodWithSuperBinding) !== 0; + const accessors: PropertyAssignment[] = []; + names.forEach((_, key) => { + const name = unescapeLeadingUnderscores(key); + const getterAndSetter: PropertyAssignment[] = []; + getterAndSetter.push(createPropertyAssignment( + "get", + createArrowFunction( + /* modifiers */ undefined, + /* typeParameters */ undefined, + /* parameters */ [], + /* type */ undefined, + /* equalsGreaterThanToken */ undefined, + createPropertyAccess( + createSuper(), + name + ) + ) + )); + if (hasBinding) { + getterAndSetter.push( + createPropertyAssignment( + "set", + createArrowFunction( + /* modifiers */ undefined, + /* typeParameters */ undefined, + /* parameters */ [ + createParameter( + /* decorators */ undefined, + /* modifiers */ undefined, + /* dotDotDotToken */ undefined, + "v", + /* questionToken */ undefined, + /* type */ undefined, + /* initializer */ undefined + ) + ], + /* type */ undefined, + /* equalsGreaterThanToken */ undefined, + createAssignment( + createPropertyAccess( + createSuper(), + name), + createIdentifier("v") + ) + ) + ) + ); + } + accessors.push( + createPropertyAssignment( + name, + createObjectLiteral(getterAndSetter), + ) + ); + }); + return createVariableStatement( + /* modifiers */ undefined, + createVariableDeclarationList( + [ + createVariableDeclaration( + createFileLevelUniqueName("_superProps"), + /* type */ undefined, + createCall( + createPropertyAccess( + createIdentifier("Object"), + "create" + ), + /* typeArguments */ undefined, + [ + createNull(), + createObjectLiteral(accessors, /* multiline */ true) + ] + ) + ) + ], + NodeFlags.Const)); + } + const awaiterHelper: EmitHelper = { name: "typescript:awaiter", scoped: false, diff --git a/src/compiler/transformers/esnext.ts b/src/compiler/transformers/esnext.ts index b121eb315db84..32f2c70a73969 100644 --- a/src/compiler/transformers/esnext.ts +++ b/src/compiler/transformers/esnext.ts @@ -26,6 +26,13 @@ namespace ts { let enclosingFunctionFlags: FunctionFlags; let enclosingSuperContainerFlags: NodeCheckFlags = 0; + /** Keeps track of property names accessed on super (`super.x`) within async functions. */ + let capturedSuperProperties: UnderscoreEscapedMap; + /** Whether the async function contains an element access on super (`super[x]`). */ + let hasSuperElementAccess: boolean; + /** A set of node IDs for generated super accessors. */ + const substitutedSuperAccessors: boolean[] = []; + return chainBundle(transformSourceFile); function transformSourceFile(node: SourceFile) { @@ -54,10 +61,6 @@ namespace ts { } function visitorWorker(node: Node, noDestructuringValue: boolean): VisitResult { - if ((node.transformFlags & TransformFlags.ContainsESNext) === 0) { - return node; - } - switch (node.kind) { case SyntaxKind.AwaitExpression: return visitAwaitExpression(node as AwaitExpression); @@ -101,6 +104,16 @@ namespace ts { return visitParenthesizedExpression(node as ParenthesizedExpression, noDestructuringValue); case SyntaxKind.CatchClause: return visitCatchClause(node as CatchClause); + case SyntaxKind.PropertyAccessExpression: + if (capturedSuperProperties && isPropertyAccessExpression(node) && node.expression.kind === SyntaxKind.SuperKeyword) { + capturedSuperProperties.set(node.name.escapedText, true); + } + return visitEachChild(node, visitor, context); + case SyntaxKind.ElementAccessExpression: + if (capturedSuperProperties && (node).expression.kind === SyntaxKind.SuperKeyword) { + hasSuperElementAccess = true; + } + return visitEachChild(node, visitor, context); default: return visitEachChild(node, visitor, context); } @@ -655,41 +668,57 @@ namespace ts { const statementOffset = addPrologue(statements, node.body!.statements, /*ensureUseStrict*/ false, visitor); appendObjectRestAssignmentsIfNeeded(statements, node); - statements.push( - createReturn( - createAsyncGeneratorHelper( - context, - createFunctionExpression( - /*modifiers*/ undefined, - createToken(SyntaxKind.AsteriskToken), - node.name && getGeneratedNameForNode(node.name), - /*typeParameters*/ undefined, - /*parameters*/ [], - /*type*/ undefined, - updateBlock( - node.body!, - visitLexicalEnvironment(node.body!.statements, visitor, context, statementOffset) - ) + const savedCapturedSuperProperties = capturedSuperProperties; + const savedHasSuperElementAccess = hasSuperElementAccess; + capturedSuperProperties = createUnderscoreEscapedMap(); + hasSuperElementAccess = false; + + const returnStatement = createReturn( + createAsyncGeneratorHelper( + context, + createFunctionExpression( + /*modifiers*/ undefined, + createToken(SyntaxKind.AsteriskToken), + node.name && getGeneratedNameForNode(node.name), + /*typeParameters*/ undefined, + /*parameters*/ [], + /*type*/ undefined, + updateBlock( + node.body!, + visitLexicalEnvironment(node.body!.statements, visitor, context, statementOffset) ) ) ) ); + // Minor optimization, emit `_super` helper to capture `super` access in an arrow. + // This step isn't needed if we eventually transform this to ES5. + const emitSuperHelpers = languageVersion >= ScriptTarget.ES2015 && resolver.getNodeCheckFlags(node) & (NodeCheckFlags.AsyncMethodWithSuperBinding | NodeCheckFlags.AsyncMethodWithSuper); + + if (emitSuperHelpers) { + enableSubstitutionForAsyncMethodsWithSuper(); + const variableStatement = createSuperAccessVariableStatement(resolver, node, capturedSuperProperties); + substitutedSuperAccessors[getNodeId(variableStatement)] = true; + addStatementsAfterPrologue(statements, [variableStatement]); + } + + statements.push(returnStatement); + addStatementsAfterPrologue(statements, endLexicalEnvironment()); const block = updateBlock(node.body!, statements); - // Minor optimization, emit `_super` helper to capture `super` access in an arrow. - // This step isn't needed if we eventually transform this to ES5. - if (languageVersion >= ScriptTarget.ES2015) { + if (emitSuperHelpers && hasSuperElementAccess) { if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.AsyncMethodWithSuperBinding) { - enableSubstitutionForAsyncMethodsWithSuper(); addEmitHelper(block, advancedAsyncSuperHelper); } else if (resolver.getNodeCheckFlags(node) & NodeCheckFlags.AsyncMethodWithSuper) { - enableSubstitutionForAsyncMethodsWithSuper(); addEmitHelper(block, asyncSuperHelper); } } + + capturedSuperProperties = savedCapturedSuperProperties; + hasSuperElementAccess = savedHasSuperElementAccess; + return block; } @@ -758,6 +787,8 @@ namespace ts { context.enableEmitNotification(SyntaxKind.GetAccessor); context.enableEmitNotification(SyntaxKind.SetAccessor); context.enableEmitNotification(SyntaxKind.Constructor); + // We need to be notified when entering the generated accessor arrow functions. + context.enableEmitNotification(SyntaxKind.VariableStatement); } } @@ -781,6 +812,14 @@ namespace ts { return; } } + // Disable substitution in the generated super accessor itself. + else if (enabledSubstitutions && substitutedSuperAccessors[getNodeId(node)]) { + const savedEnclosingSuperContainerFlags = enclosingSuperContainerFlags; + enclosingSuperContainerFlags = 0 as NodeCheckFlags; + previousOnEmitNode(hint, node, emitCallback); + enclosingSuperContainerFlags = savedEnclosingSuperContainerFlags; + return; + } previousOnEmitNode(hint, node, emitCallback); } @@ -813,8 +852,10 @@ namespace ts { function substitutePropertyAccessExpression(node: PropertyAccessExpression) { if (node.expression.kind === SyntaxKind.SuperKeyword) { - return createSuperAccessInAsyncMethod( - createLiteral(idText(node.name)), + return setTextRange( + createPropertyAccess( + createFileLevelUniqueName("_superProps"), + node.name), node ); } @@ -823,7 +864,7 @@ namespace ts { function substituteElementAccessExpression(node: ElementAccessExpression) { if (node.expression.kind === SyntaxKind.SuperKeyword) { - return createSuperAccessInAsyncMethod( + return createSuperElementAccessInAsyncMethod( node.argumentExpression, node ); @@ -858,7 +899,7 @@ namespace ts { || kind === SyntaxKind.SetAccessor; } - function createSuperAccessInAsyncMethod(argumentExpression: Expression, location: TextRange): LeftHandSideExpression { + function createSuperElementAccessInAsyncMethod(argumentExpression: Expression, location: TextRange): LeftHandSideExpression { if (enclosingSuperContainerFlags & NodeCheckFlags.AsyncMethodWithSuperBinding) { return setTextRange( createPropertyAccess( diff --git a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.js b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.js index 4b33d8492e94a..6b953843dd858 100644 --- a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.js +++ b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.js @@ -2,14 +2,19 @@ class A { x() { } + y() { + } } class B extends A { // async method with only call/get on 'super' does not require a binding async simple() { const _super = null; + const _superProps = null; // call with property access super.x(); + // call additional property. + super.y(); // call with element access super["x"](); @@ -24,6 +29,7 @@ class B extends A { // async method with assignment/destructuring on 'super' requires a binding async advanced() { const _super = null; + const _superProps = null; const f = () => {}; // call with property access @@ -50,7 +56,8 @@ class B extends A { // destructuring assign with element access ({ f: super["x"] } = { f }); } -} +} + //// [asyncMethodWithSuperConflict_es6.js] var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { @@ -64,19 +71,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge class A { x() { } + y() { + } } class B extends A { // async method with only call/get on 'super' does not require a binding simple() { const _super_1 = name => super[name]; + const _superProps_1 = Object.create(null, { + x: { get: () => super.x }, + y: { get: () => super.y } + }); return __awaiter(this, void 0, void 0, function* () { const _super = null; + const _superProps = null; // call with property access - _super_1("x").call(this); + _superProps_1.x.call(this); + // call additional property. + _superProps_1.y.call(this); // call with element access _super_1("x").call(this); // property access (read) - const a = _super_1("x"); + const a = _superProps_1.x; // element access (read) const b = _super_1("x"); }); @@ -87,23 +103,27 @@ class B extends A { const cache = Object.create(null); return name => cache[name] || (cache[name] = { get value() { return geti(name); }, set value(v) { seti(name, v); } }); })(name => super[name], (name, value) => super[name] = value); + const _superProps_1 = Object.create(null, { + x: { get: () => super.x, set: v => super.x = v } + }); return __awaiter(this, void 0, void 0, function* () { const _super = null; + const _superProps = null; const f = () => { }; // call with property access - _super_1("x").value.call(this); + _superProps_1.x.call(this); // call with element access _super_1("x").value.call(this); // property access (read) - const a = _super_1("x").value; + const a = _superProps_1.x; // element access (read) const b = _super_1("x").value; // property access (assign) - _super_1("x").value = f; + _superProps_1.x = f; // element access (assign) _super_1("x").value = f; // destructuring assign with property access - ({ f: _super_1("x").value } = { f }); + ({ f: _superProps_1.x } = { f }); // destructuring assign with element access ({ f: _super_1("x").value } = { f }); }); diff --git a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.symbols b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.symbols index ddc8fdf013cdb..b1fddf408ac69 100644 --- a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.symbols +++ b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.symbols @@ -5,18 +5,24 @@ class A { x() { >x : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) } + y() { +>y : Symbol(A.y, Decl(asyncMethodWithSuperConflict_es6.ts, 2, 5)) + } } class B extends A { ->B : Symbol(B, Decl(asyncMethodWithSuperConflict_es6.ts, 3, 1)) +>B : Symbol(B, Decl(asyncMethodWithSuperConflict_es6.ts, 5, 1)) >A : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) // async method with only call/get on 'super' does not require a binding async simple() { ->simple : Symbol(B.simple, Decl(asyncMethodWithSuperConflict_es6.ts, 5, 19)) +>simple : Symbol(B.simple, Decl(asyncMethodWithSuperConflict_es6.ts, 7, 19)) const _super = null; ->_super : Symbol(_super, Decl(asyncMethodWithSuperConflict_es6.ts, 8, 13)) +>_super : Symbol(_super, Decl(asyncMethodWithSuperConflict_es6.ts, 10, 13)) + + const _superProps = null; +>_superProps : Symbol(_superProps, Decl(asyncMethodWithSuperConflict_es6.ts, 11, 13)) // call with property access super.x(); @@ -24,6 +30,12 @@ class B extends A { >super : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) + // call additional property. + super.y(); +>super.y : Symbol(A.y, Decl(asyncMethodWithSuperConflict_es6.ts, 2, 5)) +>super : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) +>y : Symbol(A.y, Decl(asyncMethodWithSuperConflict_es6.ts, 2, 5)) + // call with element access super["x"](); >super : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) @@ -31,27 +43,30 @@ class B extends A { // property access (read) const a = super.x; ->a : Symbol(a, Decl(asyncMethodWithSuperConflict_es6.ts, 16, 13)) +>a : Symbol(a, Decl(asyncMethodWithSuperConflict_es6.ts, 21, 13)) >super.x : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) // element access (read) const b = super["x"]; ->b : Symbol(b, Decl(asyncMethodWithSuperConflict_es6.ts, 19, 13)) +>b : Symbol(b, Decl(asyncMethodWithSuperConflict_es6.ts, 24, 13)) >super : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) } // async method with assignment/destructuring on 'super' requires a binding async advanced() { ->advanced : Symbol(B.advanced, Decl(asyncMethodWithSuperConflict_es6.ts, 20, 5)) +>advanced : Symbol(B.advanced, Decl(asyncMethodWithSuperConflict_es6.ts, 25, 5)) const _super = null; ->_super : Symbol(_super, Decl(asyncMethodWithSuperConflict_es6.ts, 24, 13)) +>_super : Symbol(_super, Decl(asyncMethodWithSuperConflict_es6.ts, 29, 13)) + + const _superProps = null; +>_superProps : Symbol(_superProps, Decl(asyncMethodWithSuperConflict_es6.ts, 30, 13)) const f = () => {}; ->f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 25, 13)) +>f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 31, 13)) // call with property access super.x(); @@ -66,14 +81,14 @@ class B extends A { // property access (read) const a = super.x; ->a : Symbol(a, Decl(asyncMethodWithSuperConflict_es6.ts, 34, 13)) +>a : Symbol(a, Decl(asyncMethodWithSuperConflict_es6.ts, 40, 13)) >super.x : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) // element access (read) const b = super["x"]; ->b : Symbol(b, Decl(asyncMethodWithSuperConflict_es6.ts, 37, 13)) +>b : Symbol(b, Decl(asyncMethodWithSuperConflict_es6.ts, 43, 13)) >super : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) @@ -82,27 +97,28 @@ class B extends A { >super.x : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 25, 13)) +>f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 31, 13)) // element access (assign) super["x"] = f; >super : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 25, 13)) +>f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 31, 13)) // destructuring assign with property access ({ f: super.x } = { f }); ->f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 46, 10)) +>f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 52, 10)) >super.x : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 46, 27)) +>f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 52, 27)) // destructuring assign with element access ({ f: super["x"] } = { f }); ->f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 49, 10)) +>f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 55, 10)) >super : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 49, 30)) +>f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 55, 30)) } } + diff --git a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.types b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.types index ac82440a3d89d..a839fd44a8075 100644 --- a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.types +++ b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.types @@ -5,6 +5,9 @@ class A { x() { >x : () => void } + y() { +>y : () => void + } } class B extends A { @@ -17,6 +20,10 @@ class B extends A { const _super = null; >_super : any +>null : null + + const _superProps = null; +>_superProps : any >null : null // call with property access @@ -26,6 +33,13 @@ class B extends A { >super : A >x : () => void + // call additional property. + super.y(); +>super.y() : void +>super.y : () => void +>super : A +>y : () => void + // call with element access super["x"](); >super["x"]() : void @@ -54,6 +68,10 @@ class B extends A { const _super = null; >_super : any +>null : null + + const _superProps = null; +>_superProps : any >null : null const f = () => {}; @@ -129,3 +147,4 @@ class B extends A { >f : () => void } } + diff --git a/tests/baselines/reference/asyncMethodWithSuper_es2017.js b/tests/baselines/reference/asyncMethodWithSuper_es2017.js index b692579316380..4c5a7aa9866fc 100644 --- a/tests/baselines/reference/asyncMethodWithSuper_es2017.js +++ b/tests/baselines/reference/asyncMethodWithSuper_es2017.js @@ -2,6 +2,8 @@ class A { x() { } + y() { + } } class B extends A { @@ -9,6 +11,8 @@ class B extends A { async simple() { // call with property access super.x(); + // call additional property. + super.y(); // call with element access super["x"](); @@ -48,18 +52,23 @@ class B extends A { // destructuring assign with element access ({ f: super["x"] } = { f }); } -} +} + //// [asyncMethodWithSuper_es2017.js] class A { x() { } + y() { + } } class B extends A { // async method with only call/get on 'super' does not require a binding async simple() { // call with property access super.x(); + // call additional property. + super.y(); // call with element access super["x"](); // property access (read) diff --git a/tests/baselines/reference/asyncMethodWithSuper_es2017.symbols b/tests/baselines/reference/asyncMethodWithSuper_es2017.symbols index 39ed91d7acb4f..bee97d8a0069f 100644 --- a/tests/baselines/reference/asyncMethodWithSuper_es2017.symbols +++ b/tests/baselines/reference/asyncMethodWithSuper_es2017.symbols @@ -5,15 +5,18 @@ class A { x() { >x : Symbol(A.x, Decl(asyncMethodWithSuper_es2017.ts, 0, 9)) } + y() { +>y : Symbol(A.y, Decl(asyncMethodWithSuper_es2017.ts, 2, 5)) + } } class B extends A { ->B : Symbol(B, Decl(asyncMethodWithSuper_es2017.ts, 3, 1)) +>B : Symbol(B, Decl(asyncMethodWithSuper_es2017.ts, 5, 1)) >A : Symbol(A, Decl(asyncMethodWithSuper_es2017.ts, 0, 0)) // async method with only call/get on 'super' does not require a binding async simple() { ->simple : Symbol(B.simple, Decl(asyncMethodWithSuper_es2017.ts, 5, 19)) +>simple : Symbol(B.simple, Decl(asyncMethodWithSuper_es2017.ts, 7, 19)) // call with property access super.x(); @@ -21,6 +24,12 @@ class B extends A { >super : Symbol(A, Decl(asyncMethodWithSuper_es2017.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuper_es2017.ts, 0, 9)) + // call additional property. + super.y(); +>super.y : Symbol(A.y, Decl(asyncMethodWithSuper_es2017.ts, 2, 5)) +>super : Symbol(A, Decl(asyncMethodWithSuper_es2017.ts, 0, 0)) +>y : Symbol(A.y, Decl(asyncMethodWithSuper_es2017.ts, 2, 5)) + // call with element access super["x"](); >super : Symbol(A, Decl(asyncMethodWithSuper_es2017.ts, 0, 0)) @@ -28,24 +37,24 @@ class B extends A { // property access (read) const a = super.x; ->a : Symbol(a, Decl(asyncMethodWithSuper_es2017.ts, 15, 13)) +>a : Symbol(a, Decl(asyncMethodWithSuper_es2017.ts, 19, 13)) >super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es2017.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuper_es2017.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuper_es2017.ts, 0, 9)) // element access (read) const b = super["x"]; ->b : Symbol(b, Decl(asyncMethodWithSuper_es2017.ts, 18, 13)) +>b : Symbol(b, Decl(asyncMethodWithSuper_es2017.ts, 22, 13)) >super : Symbol(A, Decl(asyncMethodWithSuper_es2017.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es2017.ts, 0, 9)) } // async method with assignment/destructuring on 'super' requires a binding async advanced() { ->advanced : Symbol(B.advanced, Decl(asyncMethodWithSuper_es2017.ts, 19, 5)) +>advanced : Symbol(B.advanced, Decl(asyncMethodWithSuper_es2017.ts, 23, 5)) const f = () => {}; ->f : Symbol(f, Decl(asyncMethodWithSuper_es2017.ts, 23, 13)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es2017.ts, 27, 13)) // call with property access super.x(); @@ -60,14 +69,14 @@ class B extends A { // property access (read) const a = super.x; ->a : Symbol(a, Decl(asyncMethodWithSuper_es2017.ts, 32, 13)) +>a : Symbol(a, Decl(asyncMethodWithSuper_es2017.ts, 36, 13)) >super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es2017.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuper_es2017.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuper_es2017.ts, 0, 9)) // element access (read) const b = super["x"]; ->b : Symbol(b, Decl(asyncMethodWithSuper_es2017.ts, 35, 13)) +>b : Symbol(b, Decl(asyncMethodWithSuper_es2017.ts, 39, 13)) >super : Symbol(A, Decl(asyncMethodWithSuper_es2017.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es2017.ts, 0, 9)) @@ -76,27 +85,28 @@ class B extends A { >super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es2017.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuper_es2017.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuper_es2017.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuper_es2017.ts, 23, 13)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es2017.ts, 27, 13)) // element access (assign) super["x"] = f; >super : Symbol(A, Decl(asyncMethodWithSuper_es2017.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es2017.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuper_es2017.ts, 23, 13)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es2017.ts, 27, 13)) // destructuring assign with property access ({ f: super.x } = { f }); ->f : Symbol(f, Decl(asyncMethodWithSuper_es2017.ts, 44, 10)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es2017.ts, 48, 10)) >super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es2017.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuper_es2017.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuper_es2017.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuper_es2017.ts, 44, 27)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es2017.ts, 48, 27)) // destructuring assign with element access ({ f: super["x"] } = { f }); ->f : Symbol(f, Decl(asyncMethodWithSuper_es2017.ts, 47, 10)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es2017.ts, 51, 10)) >super : Symbol(A, Decl(asyncMethodWithSuper_es2017.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es2017.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuper_es2017.ts, 47, 30)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es2017.ts, 51, 30)) } } + diff --git a/tests/baselines/reference/asyncMethodWithSuper_es2017.types b/tests/baselines/reference/asyncMethodWithSuper_es2017.types index b2678e8b8379d..b76b13798b868 100644 --- a/tests/baselines/reference/asyncMethodWithSuper_es2017.types +++ b/tests/baselines/reference/asyncMethodWithSuper_es2017.types @@ -5,6 +5,9 @@ class A { x() { >x : () => void } + y() { +>y : () => void + } } class B extends A { @@ -22,6 +25,13 @@ class B extends A { >super : A >x : () => void + // call additional property. + super.y(); +>super.y() : void +>super.y : () => void +>super : A +>y : () => void + // call with element access super["x"](); >super["x"]() : void @@ -121,3 +131,4 @@ class B extends A { >f : () => void } } + diff --git a/tests/baselines/reference/asyncMethodWithSuper_es5.js b/tests/baselines/reference/asyncMethodWithSuper_es5.js index a2931b9f8e15d..441ad8875c412 100644 --- a/tests/baselines/reference/asyncMethodWithSuper_es5.js +++ b/tests/baselines/reference/asyncMethodWithSuper_es5.js @@ -2,6 +2,8 @@ class A { x() { } + y() { + } } class B extends A { @@ -9,6 +11,8 @@ class B extends A { async simple() { // call with property access super.x(); + // call additional property. + super.y(); // call with element access super["x"](); @@ -48,7 +52,8 @@ class B extends A { // destructuring assign with element access ({ f: super["x"] } = { f }); } -} +} + //// [asyncMethodWithSuper_es5.js] var A = /** @class */ (function () { @@ -56,6 +61,8 @@ var A = /** @class */ (function () { } A.prototype.x = function () { }; + A.prototype.y = function () { + }; return A; }()); var B = /** @class */ (function (_super) { @@ -70,6 +77,8 @@ var B = /** @class */ (function (_super) { return __generator(this, function (_a) { // call with property access _super.prototype.x.call(this); + // call additional property. + _super.prototype.y.call(this); // call with element access _super.prototype["x"].call(this); a = _super.prototype.x; diff --git a/tests/baselines/reference/asyncMethodWithSuper_es5.symbols b/tests/baselines/reference/asyncMethodWithSuper_es5.symbols index e05f00a8e97c2..c013058c85a4f 100644 --- a/tests/baselines/reference/asyncMethodWithSuper_es5.symbols +++ b/tests/baselines/reference/asyncMethodWithSuper_es5.symbols @@ -5,15 +5,18 @@ class A { x() { >x : Symbol(A.x, Decl(asyncMethodWithSuper_es5.ts, 0, 9)) } + y() { +>y : Symbol(A.y, Decl(asyncMethodWithSuper_es5.ts, 2, 5)) + } } class B extends A { ->B : Symbol(B, Decl(asyncMethodWithSuper_es5.ts, 3, 1)) +>B : Symbol(B, Decl(asyncMethodWithSuper_es5.ts, 5, 1)) >A : Symbol(A, Decl(asyncMethodWithSuper_es5.ts, 0, 0)) // async method with only call/get on 'super' does not require a binding async simple() { ->simple : Symbol(B.simple, Decl(asyncMethodWithSuper_es5.ts, 5, 19)) +>simple : Symbol(B.simple, Decl(asyncMethodWithSuper_es5.ts, 7, 19)) // call with property access super.x(); @@ -21,6 +24,12 @@ class B extends A { >super : Symbol(A, Decl(asyncMethodWithSuper_es5.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuper_es5.ts, 0, 9)) + // call additional property. + super.y(); +>super.y : Symbol(A.y, Decl(asyncMethodWithSuper_es5.ts, 2, 5)) +>super : Symbol(A, Decl(asyncMethodWithSuper_es5.ts, 0, 0)) +>y : Symbol(A.y, Decl(asyncMethodWithSuper_es5.ts, 2, 5)) + // call with element access super["x"](); >super : Symbol(A, Decl(asyncMethodWithSuper_es5.ts, 0, 0)) @@ -28,24 +37,24 @@ class B extends A { // property access (read) const a = super.x; ->a : Symbol(a, Decl(asyncMethodWithSuper_es5.ts, 15, 13)) +>a : Symbol(a, Decl(asyncMethodWithSuper_es5.ts, 19, 13)) >super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es5.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuper_es5.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuper_es5.ts, 0, 9)) // element access (read) const b = super["x"]; ->b : Symbol(b, Decl(asyncMethodWithSuper_es5.ts, 18, 13)) +>b : Symbol(b, Decl(asyncMethodWithSuper_es5.ts, 22, 13)) >super : Symbol(A, Decl(asyncMethodWithSuper_es5.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es5.ts, 0, 9)) } // async method with assignment/destructuring on 'super' requires a binding async advanced() { ->advanced : Symbol(B.advanced, Decl(asyncMethodWithSuper_es5.ts, 19, 5)) +>advanced : Symbol(B.advanced, Decl(asyncMethodWithSuper_es5.ts, 23, 5)) const f = () => {}; ->f : Symbol(f, Decl(asyncMethodWithSuper_es5.ts, 23, 13)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es5.ts, 27, 13)) // call with property access super.x(); @@ -60,14 +69,14 @@ class B extends A { // property access (read) const a = super.x; ->a : Symbol(a, Decl(asyncMethodWithSuper_es5.ts, 32, 13)) +>a : Symbol(a, Decl(asyncMethodWithSuper_es5.ts, 36, 13)) >super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es5.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuper_es5.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuper_es5.ts, 0, 9)) // element access (read) const b = super["x"]; ->b : Symbol(b, Decl(asyncMethodWithSuper_es5.ts, 35, 13)) +>b : Symbol(b, Decl(asyncMethodWithSuper_es5.ts, 39, 13)) >super : Symbol(A, Decl(asyncMethodWithSuper_es5.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es5.ts, 0, 9)) @@ -76,27 +85,28 @@ class B extends A { >super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es5.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuper_es5.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuper_es5.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuper_es5.ts, 23, 13)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es5.ts, 27, 13)) // element access (assign) super["x"] = f; >super : Symbol(A, Decl(asyncMethodWithSuper_es5.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es5.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuper_es5.ts, 23, 13)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es5.ts, 27, 13)) // destructuring assign with property access ({ f: super.x } = { f }); ->f : Symbol(f, Decl(asyncMethodWithSuper_es5.ts, 44, 10)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es5.ts, 48, 10)) >super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es5.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuper_es5.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuper_es5.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuper_es5.ts, 44, 27)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es5.ts, 48, 27)) // destructuring assign with element access ({ f: super["x"] } = { f }); ->f : Symbol(f, Decl(asyncMethodWithSuper_es5.ts, 47, 10)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es5.ts, 51, 10)) >super : Symbol(A, Decl(asyncMethodWithSuper_es5.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es5.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuper_es5.ts, 47, 30)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es5.ts, 51, 30)) } } + diff --git a/tests/baselines/reference/asyncMethodWithSuper_es5.types b/tests/baselines/reference/asyncMethodWithSuper_es5.types index 4622d83a67994..58f545dc93b25 100644 --- a/tests/baselines/reference/asyncMethodWithSuper_es5.types +++ b/tests/baselines/reference/asyncMethodWithSuper_es5.types @@ -5,6 +5,9 @@ class A { x() { >x : () => void } + y() { +>y : () => void + } } class B extends A { @@ -22,6 +25,13 @@ class B extends A { >super : A >x : () => void + // call additional property. + super.y(); +>super.y() : void +>super.y : () => void +>super : A +>y : () => void + // call with element access super["x"](); >super["x"]() : void @@ -121,3 +131,4 @@ class B extends A { >f : () => void } } + diff --git a/tests/baselines/reference/asyncMethodWithSuper_es6.js b/tests/baselines/reference/asyncMethodWithSuper_es6.js index eacb0a882b2f7..c05114c2fff9d 100644 --- a/tests/baselines/reference/asyncMethodWithSuper_es6.js +++ b/tests/baselines/reference/asyncMethodWithSuper_es6.js @@ -2,6 +2,8 @@ class A { x() { } + y() { + } } class B extends A { @@ -9,6 +11,8 @@ class B extends A { async simple() { // call with property access super.x(); + // call additional property. + super.y(); // call with element access super["x"](); @@ -48,24 +52,33 @@ class B extends A { // destructuring assign with element access ({ f: super["x"] } = { f }); } -} +} + //// [asyncMethodWithSuper_es6.js] class A { x() { } + y() { + } } class B extends A { // async method with only call/get on 'super' does not require a binding simple() { const _super = name => super[name]; + const _superProps = Object.create(null, { + x: { get: () => super.x }, + y: { get: () => super.y } + }); return __awaiter(this, void 0, void 0, function* () { // call with property access - _super("x").call(this); + _superProps.x.call(this); + // call additional property. + _superProps.y.call(this); // call with element access _super("x").call(this); // property access (read) - const a = _super("x"); + const a = _superProps.x; // element access (read) const b = _super("x"); }); @@ -76,22 +89,25 @@ class B extends A { const cache = Object.create(null); return name => cache[name] || (cache[name] = { get value() { return geti(name); }, set value(v) { seti(name, v); } }); })(name => super[name], (name, value) => super[name] = value); + const _superProps = Object.create(null, { + x: { get: () => super.x, set: v => super.x = v } + }); return __awaiter(this, void 0, void 0, function* () { const f = () => { }; // call with property access - _super("x").value.call(this); + _superProps.x.call(this); // call with element access _super("x").value.call(this); // property access (read) - const a = _super("x").value; + const a = _superProps.x; // element access (read) const b = _super("x").value; // property access (assign) - _super("x").value = f; + _superProps.x = f; // element access (assign) _super("x").value = f; // destructuring assign with property access - ({ f: _super("x").value } = { f }); + ({ f: _superProps.x } = { f }); // destructuring assign with element access ({ f: _super("x").value } = { f }); }); diff --git a/tests/baselines/reference/asyncMethodWithSuper_es6.symbols b/tests/baselines/reference/asyncMethodWithSuper_es6.symbols index 268ad90f20322..d33bcf3449ae5 100644 --- a/tests/baselines/reference/asyncMethodWithSuper_es6.symbols +++ b/tests/baselines/reference/asyncMethodWithSuper_es6.symbols @@ -5,15 +5,18 @@ class A { x() { >x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) } + y() { +>y : Symbol(A.y, Decl(asyncMethodWithSuper_es6.ts, 2, 5)) + } } class B extends A { ->B : Symbol(B, Decl(asyncMethodWithSuper_es6.ts, 3, 1)) +>B : Symbol(B, Decl(asyncMethodWithSuper_es6.ts, 5, 1)) >A : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) // async method with only call/get on 'super' does not require a binding async simple() { ->simple : Symbol(B.simple, Decl(asyncMethodWithSuper_es6.ts, 5, 19)) +>simple : Symbol(B.simple, Decl(asyncMethodWithSuper_es6.ts, 7, 19)) // call with property access super.x(); @@ -21,6 +24,12 @@ class B extends A { >super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) + // call additional property. + super.y(); +>super.y : Symbol(A.y, Decl(asyncMethodWithSuper_es6.ts, 2, 5)) +>super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) +>y : Symbol(A.y, Decl(asyncMethodWithSuper_es6.ts, 2, 5)) + // call with element access super["x"](); >super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) @@ -28,24 +37,24 @@ class B extends A { // property access (read) const a = super.x; ->a : Symbol(a, Decl(asyncMethodWithSuper_es6.ts, 15, 13)) +>a : Symbol(a, Decl(asyncMethodWithSuper_es6.ts, 19, 13)) >super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) // element access (read) const b = super["x"]; ->b : Symbol(b, Decl(asyncMethodWithSuper_es6.ts, 18, 13)) +>b : Symbol(b, Decl(asyncMethodWithSuper_es6.ts, 22, 13)) >super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) } // async method with assignment/destructuring on 'super' requires a binding async advanced() { ->advanced : Symbol(B.advanced, Decl(asyncMethodWithSuper_es6.ts, 19, 5)) +>advanced : Symbol(B.advanced, Decl(asyncMethodWithSuper_es6.ts, 23, 5)) const f = () => {}; ->f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 23, 13)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 27, 13)) // call with property access super.x(); @@ -60,14 +69,14 @@ class B extends A { // property access (read) const a = super.x; ->a : Symbol(a, Decl(asyncMethodWithSuper_es6.ts, 32, 13)) +>a : Symbol(a, Decl(asyncMethodWithSuper_es6.ts, 36, 13)) >super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) // element access (read) const b = super["x"]; ->b : Symbol(b, Decl(asyncMethodWithSuper_es6.ts, 35, 13)) +>b : Symbol(b, Decl(asyncMethodWithSuper_es6.ts, 39, 13)) >super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) @@ -76,27 +85,28 @@ class B extends A { >super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 23, 13)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 27, 13)) // element access (assign) super["x"] = f; >super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 23, 13)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 27, 13)) // destructuring assign with property access ({ f: super.x } = { f }); ->f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 44, 10)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 48, 10)) >super.x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) >super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) >x : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 44, 27)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 48, 27)) // destructuring assign with element access ({ f: super["x"] } = { f }); ->f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 47, 10)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 51, 10)) >super : Symbol(A, Decl(asyncMethodWithSuper_es6.ts, 0, 0)) >"x" : Symbol(A.x, Decl(asyncMethodWithSuper_es6.ts, 0, 9)) ->f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 47, 30)) +>f : Symbol(f, Decl(asyncMethodWithSuper_es6.ts, 51, 30)) } } + diff --git a/tests/baselines/reference/asyncMethodWithSuper_es6.types b/tests/baselines/reference/asyncMethodWithSuper_es6.types index 030c9fe4e6ad2..1333beb8f0484 100644 --- a/tests/baselines/reference/asyncMethodWithSuper_es6.types +++ b/tests/baselines/reference/asyncMethodWithSuper_es6.types @@ -5,6 +5,9 @@ class A { x() { >x : () => void } + y() { +>y : () => void + } } class B extends A { @@ -22,6 +25,13 @@ class B extends A { >super : A >x : () => void + // call additional property. + super.y(); +>super.y() : void +>super.y : () => void +>super : A +>y : () => void + // call with element access super["x"](); >super["x"]() : void @@ -121,3 +131,4 @@ class B extends A { >f : () => void } } + diff --git a/tests/baselines/reference/emitter.asyncGenerators.classMethods.es2015.js b/tests/baselines/reference/emitter.asyncGenerators.classMethods.es2015.js index 33b80e78d8e29..12119908d64cd 100644 --- a/tests/baselines/reference/emitter.asyncGenerators.classMethods.es2015.js +++ b/tests/baselines/reference/emitter.asyncGenerators.classMethods.es2015.js @@ -263,9 +263,11 @@ class B9 { } class C9 extends B9 { f() { - const _super = name => super[name]; + const _superProps = Object.create(null, { + g: { get: () => super.g } + }); return __asyncGenerator(this, arguments, function* f_1() { - _super("g").call(this); + _superProps.g.call(this); }); } } diff --git a/tests/cases/conformance/async/es2017/asyncMethodWithSuperConflict_es6.ts b/tests/cases/conformance/async/es2017/asyncMethodWithSuperConflict_es6.ts index 364f0264b23c4..924106b39b81e 100644 --- a/tests/cases/conformance/async/es2017/asyncMethodWithSuperConflict_es6.ts +++ b/tests/cases/conformance/async/es2017/asyncMethodWithSuperConflict_es6.ts @@ -2,14 +2,19 @@ class A { x() { } + y() { + } } class B extends A { // async method with only call/get on 'super' does not require a binding async simple() { const _super = null; + const _superProps = null; // call with property access super.x(); + // call additional property. + super.y(); // call with element access super["x"](); @@ -24,6 +29,7 @@ class B extends A { // async method with assignment/destructuring on 'super' requires a binding async advanced() { const _super = null; + const _superProps = null; const f = () => {}; // call with property access @@ -50,4 +56,4 @@ class B extends A { // destructuring assign with element access ({ f: super["x"] } = { f }); } -} \ No newline at end of file +} diff --git a/tests/cases/conformance/async/es2017/asyncMethodWithSuper_es2017.ts b/tests/cases/conformance/async/es2017/asyncMethodWithSuper_es2017.ts index b9005c4859657..892acfd6dd2af 100644 --- a/tests/cases/conformance/async/es2017/asyncMethodWithSuper_es2017.ts +++ b/tests/cases/conformance/async/es2017/asyncMethodWithSuper_es2017.ts @@ -3,6 +3,8 @@ class A { x() { } + y() { + } } class B extends A { @@ -10,6 +12,8 @@ class B extends A { async simple() { // call with property access super.x(); + // call additional property. + super.y(); // call with element access super["x"](); @@ -49,4 +53,4 @@ class B extends A { // destructuring assign with element access ({ f: super["x"] } = { f }); } -} \ No newline at end of file +} diff --git a/tests/cases/conformance/async/es5/asyncMethodWithSuper_es5.ts b/tests/cases/conformance/async/es5/asyncMethodWithSuper_es5.ts index 496d8d1c80247..c89369d02b7a0 100644 --- a/tests/cases/conformance/async/es5/asyncMethodWithSuper_es5.ts +++ b/tests/cases/conformance/async/es5/asyncMethodWithSuper_es5.ts @@ -4,6 +4,8 @@ class A { x() { } + y() { + } } class B extends A { @@ -11,6 +13,8 @@ class B extends A { async simple() { // call with property access super.x(); + // call additional property. + super.y(); // call with element access super["x"](); @@ -50,4 +54,4 @@ class B extends A { // destructuring assign with element access ({ f: super["x"] } = { f }); } -} \ No newline at end of file +} diff --git a/tests/cases/conformance/async/es6/asyncMethodWithSuper_es6.ts b/tests/cases/conformance/async/es6/asyncMethodWithSuper_es6.ts index 795fe7defb0b5..79d110e3d8595 100644 --- a/tests/cases/conformance/async/es6/asyncMethodWithSuper_es6.ts +++ b/tests/cases/conformance/async/es6/asyncMethodWithSuper_es6.ts @@ -3,6 +3,8 @@ class A { x() { } + y() { + } } class B extends A { @@ -10,6 +12,8 @@ class B extends A { async simple() { // call with property access super.x(); + // call additional property. + super.y(); // call with element access super["x"](); @@ -49,4 +53,4 @@ class B extends A { // destructuring assign with element access ({ f: super["x"] } = { f }); } -} \ No newline at end of file +} From e618d752b691972d3d96a0a6e3d1559bc461e5ef Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Fri, 31 Aug 2018 11:01:59 +0200 Subject: [PATCH 2/4] Fixes for review comments. * rename _super to _superIndex and _superProps to _super. * reinstate early exit for transformers by marking super accesses as esnext/es2017 in `binder.ts`. * adjust comment in `checker.ts` to new emit. --- src/compiler/binder.ts | 8 +++-- src/compiler/checker.ts | 21 +++++++----- src/compiler/transformers/es2017.ts | 17 ++++++---- src/compiler/transformers/esnext.ts | 9 +++-- .../asyncMethodWithSuperConflict_es6.js | 34 +++++++++---------- .../reference/asyncMethodWithSuper_es6.js | 34 +++++++++---------- ...ter.asyncGenerators.classMethods.es2015.js | 4 +-- 7 files changed, 70 insertions(+), 57 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index a66a45547a05c..774f1e21771c3 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -3445,7 +3445,9 @@ namespace ts { // ES6 syntax, and requires a lexical `this` binding. if (transformFlags & TransformFlags.Super) { transformFlags ^= TransformFlags.Super; - transformFlags |= TransformFlags.ContainsSuper; + // super inside of an async function requires hoisting the super access (ES2017). + // same for super inside of an async generator, which is ESNext. + transformFlags |= TransformFlags.ContainsSuper | TransformFlags.ContainsES2017 | TransformFlags.ContainsESNext; } node.transformFlags = transformFlags | TransformFlags.HasComputedFlags; @@ -3461,7 +3463,9 @@ namespace ts { // ES6 syntax, and requires a lexical `this` binding. if (expressionFlags & TransformFlags.Super) { transformFlags &= ~TransformFlags.Super; - transformFlags |= TransformFlags.ContainsSuper; + // super inside of an async function requires hoisting the super access (ES2017). + // same for super inside of an async generator, which is ESNext. + transformFlags |= TransformFlags.ContainsSuper | TransformFlags.ContainsES2017 | TransformFlags.ContainsESNext; } node.transformFlags = transformFlags | TransformFlags.HasComputedFlags; diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index eb29c5eba066d..21e9af9260475 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16180,16 +16180,18 @@ namespace ts { // // js // ... // asyncMethod() { - // const _super_asyncMethod = name => super.asyncMethod; + // const _super = Object.create(null, { + // asyncMethod: { get: () => super.asyncMethod }, + // }); // return __awaiter(this, arguments, Promise, function *() { - // let x = yield _super_asyncMethod.call(this); + // let x = yield _super.asyncMethod.call(this); // return x; // }); // } // ... // // The more complex case is when we wish to assign a value, especially as part of a destructuring assignment. As both cases - // are legal in ES6, but also likely less frequent, we emit the same more complex helper for both scenarios: + // are legal in ES6, but also likely less frequent, we only emit setters if there is an assignment: // // // ts // ... @@ -16201,17 +16203,18 @@ namespace ts { // // js // ... // asyncMethod(ar) { - // const _super_a = {get value() { return super.a; }, set value(v) { super.a = v; }}; - // const _super_b = {get value() { return super.b; }, set value(v) { super.b = v; }}; + // const _super = Object.create(null, { + // a: { get: () => super.a, set: (v) => super.a = v }, + // b: { get: () => super.b, set: (v) => super.b = v } + // }; // return __awaiter(this, arguments, Promise, function *() { - // [_super_a.value, _super_b.value] = yield ar; + // [_super.a, _super.b] = yield ar; // }); // } // ... // - // This helper creates an object with a "value" property that wraps the `super` property for both get and set. This is required for - // destructuring assignments, as a call expression cannot be used as the target of a destructuring assignment while a property - // access can. + // Creating an object that has getter and setters instead of just an accessor funtion is required for destructuring assignments + // as a call expression cannot be used as the target of a destructuring assignment while a property access can. // // For element access expressions (`super[x]`), we emit a generic helper that forwards the element access in both situations. if (container.kind === SyntaxKind.MethodDeclaration && hasModifier(container, ModifierFlags.Async)) { diff --git a/src/compiler/transformers/es2017.ts b/src/compiler/transformers/es2017.ts index 8b2f5a700a046..64a126a63c879 100644 --- a/src/compiler/transformers/es2017.ts +++ b/src/compiler/transformers/es2017.ts @@ -62,6 +62,9 @@ namespace ts { } function visitor(node: Node): VisitResult { + if ((node.transformFlags & TransformFlags.ContainsES2017) === 0) { + return node; + } switch (node.kind) { case SyntaxKind.AsyncKeyword: // ES2017 async modifier should be elided for targets < ES2017 @@ -553,7 +556,7 @@ namespace ts { // Disable substitution in the generated super accessor itself. else if (enabledSubstitutions && substitutedSuperAccessors[getNodeId(node)]) { const savedEnclosingSuperContainerFlags = enclosingSuperContainerFlags; - enclosingSuperContainerFlags = 0 as NodeCheckFlags; + enclosingSuperContainerFlags = 0; previousOnEmitNode(hint, node, emitCallback); enclosingSuperContainerFlags = savedEnclosingSuperContainerFlags; return; @@ -592,7 +595,7 @@ namespace ts { if (node.expression.kind === SyntaxKind.SuperKeyword) { return setTextRange( createPropertyAccess( - createFileLevelUniqueName("_superProps"), + createFileLevelUniqueName("_super"), node.name), node ); @@ -642,7 +645,7 @@ namespace ts { return setTextRange( createPropertyAccess( createCall( - createFileLevelUniqueName("_super"), + createFileLevelUniqueName("_superIndex"), /*typeArguments*/ undefined, [argumentExpression] ), @@ -654,7 +657,7 @@ namespace ts { else { return setTextRange( createCall( - createFileLevelUniqueName("_super"), + createFileLevelUniqueName("_superIndex"), /*typeArguments*/ undefined, [argumentExpression] ), @@ -729,7 +732,7 @@ namespace ts { createVariableDeclarationList( [ createVariableDeclaration( - createFileLevelUniqueName("_superProps"), + createFileLevelUniqueName("_super"), /* type */ undefined, createCall( createPropertyAccess( @@ -794,14 +797,14 @@ namespace ts { name: "typescript:async-super", scoped: true, text: helperString` - const ${"_super"} = name => super[name];` + const ${"_superIndex"} = name => super[name];` }; export const advancedAsyncSuperHelper: EmitHelper = { name: "typescript:advanced-async-super", scoped: true, text: helperString` - const ${"_super"} = (function (geti, seti) { + const ${"_superIndex"} = (function (geti, seti) { const cache = Object.create(null); return name => cache[name] || (cache[name] = { get value() { return geti(name); }, set value(v) { seti(name, v); } }); })(name => super[name], (name, value) => super[name] = value);` diff --git a/src/compiler/transformers/esnext.ts b/src/compiler/transformers/esnext.ts index 32f2c70a73969..6d8c5d4931256 100644 --- a/src/compiler/transformers/esnext.ts +++ b/src/compiler/transformers/esnext.ts @@ -61,6 +61,9 @@ namespace ts { } function visitorWorker(node: Node, noDestructuringValue: boolean): VisitResult { + if ((node.transformFlags & TransformFlags.ContainsESNext) === 0) { + return node; + } switch (node.kind) { case SyntaxKind.AwaitExpression: return visitAwaitExpression(node as AwaitExpression); @@ -854,7 +857,7 @@ namespace ts { if (node.expression.kind === SyntaxKind.SuperKeyword) { return setTextRange( createPropertyAccess( - createFileLevelUniqueName("_superProps"), + createFileLevelUniqueName("_super"), node.name), node ); @@ -904,7 +907,7 @@ namespace ts { return setTextRange( createPropertyAccess( createCall( - createIdentifier("_super"), + createIdentifier("_superIndex"), /*typeArguments*/ undefined, [argumentExpression] ), @@ -916,7 +919,7 @@ namespace ts { else { return setTextRange( createCall( - createIdentifier("_super"), + createIdentifier("_superIndex"), /*typeArguments*/ undefined, [argumentExpression] ), diff --git a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.js b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.js index 6b953843dd858..4ea8c16667a29 100644 --- a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.js +++ b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.js @@ -77,8 +77,8 @@ class A { class B extends A { // async method with only call/get on 'super' does not require a binding simple() { - const _super_1 = name => super[name]; - const _superProps_1 = Object.create(null, { + const _superIndex = name => super[name]; + const _super_1 = Object.create(null, { x: { get: () => super.x }, y: { get: () => super.y } }); @@ -86,24 +86,24 @@ class B extends A { const _super = null; const _superProps = null; // call with property access - _superProps_1.x.call(this); + _super_1.x.call(this); // call additional property. - _superProps_1.y.call(this); + _super_1.y.call(this); // call with element access - _super_1("x").call(this); + _superIndex("x").call(this); // property access (read) - const a = _superProps_1.x; + const a = _super_1.x; // element access (read) - const b = _super_1("x"); + const b = _superIndex("x"); }); } // async method with assignment/destructuring on 'super' requires a binding advanced() { - const _super_1 = (function (geti, seti) { + const _superIndex = (function (geti, seti) { const cache = Object.create(null); return name => cache[name] || (cache[name] = { get value() { return geti(name); }, set value(v) { seti(name, v); } }); })(name => super[name], (name, value) => super[name] = value); - const _superProps_1 = Object.create(null, { + const _super_1 = Object.create(null, { x: { get: () => super.x, set: v => super.x = v } }); return __awaiter(this, void 0, void 0, function* () { @@ -111,21 +111,21 @@ class B extends A { const _superProps = null; const f = () => { }; // call with property access - _superProps_1.x.call(this); + _super_1.x.call(this); // call with element access - _super_1("x").value.call(this); + _superIndex("x").value.call(this); // property access (read) - const a = _superProps_1.x; + const a = _super_1.x; // element access (read) - const b = _super_1("x").value; + const b = _superIndex("x").value; // property access (assign) - _superProps_1.x = f; + _super_1.x = f; // element access (assign) - _super_1("x").value = f; + _superIndex("x").value = f; // destructuring assign with property access - ({ f: _superProps_1.x } = { f }); + ({ f: _super_1.x } = { f }); // destructuring assign with element access - ({ f: _super_1("x").value } = { f }); + ({ f: _superIndex("x").value } = { f }); }); } } diff --git a/tests/baselines/reference/asyncMethodWithSuper_es6.js b/tests/baselines/reference/asyncMethodWithSuper_es6.js index c05114c2fff9d..5ff89d26e9404 100644 --- a/tests/baselines/reference/asyncMethodWithSuper_es6.js +++ b/tests/baselines/reference/asyncMethodWithSuper_es6.js @@ -65,51 +65,51 @@ class A { class B extends A { // async method with only call/get on 'super' does not require a binding simple() { - const _super = name => super[name]; - const _superProps = Object.create(null, { + const _superIndex = name => super[name]; + const _super = Object.create(null, { x: { get: () => super.x }, y: { get: () => super.y } }); return __awaiter(this, void 0, void 0, function* () { // call with property access - _superProps.x.call(this); + _super.x.call(this); // call additional property. - _superProps.y.call(this); + _super.y.call(this); // call with element access - _super("x").call(this); + _superIndex("x").call(this); // property access (read) - const a = _superProps.x; + const a = _super.x; // element access (read) - const b = _super("x"); + const b = _superIndex("x"); }); } // async method with assignment/destructuring on 'super' requires a binding advanced() { - const _super = (function (geti, seti) { + const _superIndex = (function (geti, seti) { const cache = Object.create(null); return name => cache[name] || (cache[name] = { get value() { return geti(name); }, set value(v) { seti(name, v); } }); })(name => super[name], (name, value) => super[name] = value); - const _superProps = Object.create(null, { + const _super = Object.create(null, { x: { get: () => super.x, set: v => super.x = v } }); return __awaiter(this, void 0, void 0, function* () { const f = () => { }; // call with property access - _superProps.x.call(this); + _super.x.call(this); // call with element access - _super("x").value.call(this); + _superIndex("x").value.call(this); // property access (read) - const a = _superProps.x; + const a = _super.x; // element access (read) - const b = _super("x").value; + const b = _superIndex("x").value; // property access (assign) - _superProps.x = f; + _super.x = f; // element access (assign) - _super("x").value = f; + _superIndex("x").value = f; // destructuring assign with property access - ({ f: _superProps.x } = { f }); + ({ f: _super.x } = { f }); // destructuring assign with element access - ({ f: _super("x").value } = { f }); + ({ f: _superIndex("x").value } = { f }); }); } } diff --git a/tests/baselines/reference/emitter.asyncGenerators.classMethods.es2015.js b/tests/baselines/reference/emitter.asyncGenerators.classMethods.es2015.js index 12119908d64cd..c7cd212d2a464 100644 --- a/tests/baselines/reference/emitter.asyncGenerators.classMethods.es2015.js +++ b/tests/baselines/reference/emitter.asyncGenerators.classMethods.es2015.js @@ -263,11 +263,11 @@ class B9 { } class C9 extends B9 { f() { - const _superProps = Object.create(null, { + const _super = Object.create(null, { g: { get: () => super.g } }); return __asyncGenerator(this, arguments, function* f_1() { - _superProps.g.call(this); + _super.g.call(this); }); } } From e58ffcf509a3ffa00f3899cabf67b00f72aef902 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Tue, 28 Aug 2018 10:35:16 +0200 Subject: [PATCH 3/4] fix comments --- src/compiler/checker.ts | 2 +- src/compiler/transformers/es2017.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 21e9af9260475..93ddf21024d36 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -16213,7 +16213,7 @@ namespace ts { // } // ... // - // Creating an object that has getter and setters instead of just an accessor funtion is required for destructuring assignments + // Creating an object that has getter and setters instead of just an accessor function is required for destructuring assignments // as a call expression cannot be used as the target of a destructuring assignment while a property access can. // // For element access expressions (`super[x]`), we emit a generic helper that forwards the element access in both situations. diff --git a/src/compiler/transformers/es2017.ts b/src/compiler/transformers/es2017.ts index 64a126a63c879..b509c6dd00354 100644 --- a/src/compiler/transformers/es2017.ts +++ b/src/compiler/transformers/es2017.ts @@ -667,10 +667,10 @@ namespace ts { } } - /** Creates a variable named `_superProps` with accessor properties for the given property names. */ + /** Creates a variable named `_super` with accessor properties for the given property names. */ export function createSuperAccessVariableStatement(resolver: EmitResolver, node: FunctionLikeDeclaration, names: UnderscoreEscapedMap) { // Create a variable declaration with a getter/setter (if binding) definition for each name: - // const _superProps = Object.create(null, { x: { get: () => super.x, set: (v) => super.x = v }, ... }); + // const _super = Object.create(null, { x: { get: () => super.x, set: (v) => super.x = v }, ... }); const hasBinding = (resolver.getNodeCheckFlags(node) & NodeCheckFlags.AsyncMethodWithSuperBinding) !== 0; const accessors: PropertyAssignment[] = []; names.forEach((_, key) => { From 539c4559428d1548af331764807b76f20f54d619 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Tue, 28 Aug 2018 10:35:16 +0200 Subject: [PATCH 4/4] Rename to _superIndex to test conflict Change-Id: I30af09343446126ba73ed40199ecc3f0ed515b3e --- .../asyncMethodWithSuperConflict_es6.js | 24 +++++++++---------- .../asyncMethodWithSuperConflict_es6.symbols | 8 +++---- .../asyncMethodWithSuperConflict_es6.types | 8 +++---- .../asyncMethodWithSuperConflict_es6.ts | 4 ++-- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.js b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.js index 4ea8c16667a29..2a91022670358 100644 --- a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.js +++ b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.js @@ -10,7 +10,7 @@ class B extends A { // async method with only call/get on 'super' does not require a binding async simple() { const _super = null; - const _superProps = null; + const _superIndex = null; // call with property access super.x(); // call additional property. @@ -29,7 +29,7 @@ class B extends A { // async method with assignment/destructuring on 'super' requires a binding async advanced() { const _super = null; - const _superProps = null; + const _superIndex = null; const f = () => {}; // call with property access @@ -77,29 +77,29 @@ class A { class B extends A { // async method with only call/get on 'super' does not require a binding simple() { - const _superIndex = name => super[name]; + const _superIndex_1 = name => super[name]; const _super_1 = Object.create(null, { x: { get: () => super.x }, y: { get: () => super.y } }); return __awaiter(this, void 0, void 0, function* () { const _super = null; - const _superProps = null; + const _superIndex = null; // call with property access _super_1.x.call(this); // call additional property. _super_1.y.call(this); // call with element access - _superIndex("x").call(this); + _superIndex_1("x").call(this); // property access (read) const a = _super_1.x; // element access (read) - const b = _superIndex("x"); + const b = _superIndex_1("x"); }); } // async method with assignment/destructuring on 'super' requires a binding advanced() { - const _superIndex = (function (geti, seti) { + const _superIndex_1 = (function (geti, seti) { const cache = Object.create(null); return name => cache[name] || (cache[name] = { get value() { return geti(name); }, set value(v) { seti(name, v); } }); })(name => super[name], (name, value) => super[name] = value); @@ -108,24 +108,24 @@ class B extends A { }); return __awaiter(this, void 0, void 0, function* () { const _super = null; - const _superProps = null; + const _superIndex = null; const f = () => { }; // call with property access _super_1.x.call(this); // call with element access - _superIndex("x").value.call(this); + _superIndex_1("x").value.call(this); // property access (read) const a = _super_1.x; // element access (read) - const b = _superIndex("x").value; + const b = _superIndex_1("x").value; // property access (assign) _super_1.x = f; // element access (assign) - _superIndex("x").value = f; + _superIndex_1("x").value = f; // destructuring assign with property access ({ f: _super_1.x } = { f }); // destructuring assign with element access - ({ f: _superIndex("x").value } = { f }); + ({ f: _superIndex_1("x").value } = { f }); }); } } diff --git a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.symbols b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.symbols index b1fddf408ac69..161b6eca39b7b 100644 --- a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.symbols +++ b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.symbols @@ -21,8 +21,8 @@ class B extends A { const _super = null; >_super : Symbol(_super, Decl(asyncMethodWithSuperConflict_es6.ts, 10, 13)) - const _superProps = null; ->_superProps : Symbol(_superProps, Decl(asyncMethodWithSuperConflict_es6.ts, 11, 13)) + const _superIndex = null; +>_superIndex : Symbol(_superIndex, Decl(asyncMethodWithSuperConflict_es6.ts, 11, 13)) // call with property access super.x(); @@ -62,8 +62,8 @@ class B extends A { const _super = null; >_super : Symbol(_super, Decl(asyncMethodWithSuperConflict_es6.ts, 29, 13)) - const _superProps = null; ->_superProps : Symbol(_superProps, Decl(asyncMethodWithSuperConflict_es6.ts, 30, 13)) + const _superIndex = null; +>_superIndex : Symbol(_superIndex, Decl(asyncMethodWithSuperConflict_es6.ts, 30, 13)) const f = () => {}; >f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 31, 13)) diff --git a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.types b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.types index a839fd44a8075..9efebc2f192de 100644 --- a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.types +++ b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.types @@ -22,8 +22,8 @@ class B extends A { >_super : any >null : null - const _superProps = null; ->_superProps : any + const _superIndex = null; +>_superIndex : any >null : null // call with property access @@ -70,8 +70,8 @@ class B extends A { >_super : any >null : null - const _superProps = null; ->_superProps : any + const _superIndex = null; +>_superIndex : any >null : null const f = () => {}; diff --git a/tests/cases/conformance/async/es2017/asyncMethodWithSuperConflict_es6.ts b/tests/cases/conformance/async/es2017/asyncMethodWithSuperConflict_es6.ts index 924106b39b81e..88ed3eea5fff4 100644 --- a/tests/cases/conformance/async/es2017/asyncMethodWithSuperConflict_es6.ts +++ b/tests/cases/conformance/async/es2017/asyncMethodWithSuperConflict_es6.ts @@ -10,7 +10,7 @@ class B extends A { // async method with only call/get on 'super' does not require a binding async simple() { const _super = null; - const _superProps = null; + const _superIndex = null; // call with property access super.x(); // call additional property. @@ -29,7 +29,7 @@ class B extends A { // async method with assignment/destructuring on 'super' requires a binding async advanced() { const _super = null; - const _superProps = null; + const _superIndex = null; const f = () => {}; // call with property access