diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d1716a5d14b..307680d941e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13647,9 +13647,6 @@ namespace ts { } } - checkCollisionWithCapturedSuperVariable(node, node); - checkCollisionWithCapturedThisVariable(node, node); - checkCollisionWithCapturedNewTargetVariable(node, node); checkNestedBlockScopedBinding(node, symbol); const type = getConstraintForLocation(getTypeOfSymbol(localOrExportSymbol), node); @@ -18852,12 +18849,6 @@ namespace ts { } } - if (produceDiagnostics && node.kind !== SyntaxKind.MethodDeclaration) { - checkCollisionWithCapturedSuperVariable(node, node.name); - checkCollisionWithCapturedThisVariable(node, node.name); - checkCollisionWithCapturedNewTargetVariable(node, node.name); - } - return type; } @@ -21585,9 +21576,6 @@ namespace ts { if (produceDiagnostics) { checkFunctionOrMethodDeclaration(node); checkGrammarForGenerator(node); - checkCollisionWithCapturedSuperVariable(node, node.name); - checkCollisionWithCapturedThisVariable(node, node.name); - checkCollisionWithCapturedNewTargetVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } @@ -22012,18 +22000,6 @@ namespace ts { return true; } - function checkCollisionWithCapturedThisVariable(node: Node, name: Identifier): void { - if (languageVersion <= ScriptTarget.ES5 && !compilerOptions.noEmit && needCollisionCheckForIdentifier(node, name, "_this")) { - potentialThisCollisions.push(node); - } - } - - function checkCollisionWithCapturedNewTargetVariable(node: Node, name: Identifier): void { - if (languageVersion <= ScriptTarget.ES5 && !compilerOptions.noEmit && needCollisionCheckForIdentifier(node, name, "_newTarget")) { - potentialNewTargetCollisions.push(node); - } - } - // this function will run after checking the source file so 'CaptureThis' is correct for all nodes function checkIfThisIsCapturedInEnclosingScope(node: Node): void { findAncestor(node, current => { @@ -22055,33 +22031,6 @@ namespace ts { }); } - function checkCollisionWithCapturedSuperVariable(node: Node, name: Identifier) { - if (languageVersion >= ScriptTarget.ES2015 || compilerOptions.noEmit) { - return; - } - - if (!needCollisionCheckForIdentifier(node, name, "_super")) { - return; - } - - // bubble up and find containing type - const enclosingClass = getContainingClass(node); - // if containing type was not found or it is ambient - exit (no codegen) - if (!enclosingClass || enclosingClass.flags & NodeFlags.Ambient) { - return; - } - - if (getClassExtendsHeritageClauseElement(enclosingClass)) { - const isDeclaration = node.kind !== SyntaxKind.Identifier; - if (isDeclaration) { - error(node, Diagnostics.Duplicate_identifier_super_Compiler_uses_super_to_capture_base_class_reference); - } - else { - error(node, Diagnostics.Expression_resolves_to_super_that_compiler_uses_to_capture_base_class_reference); - } - } - } - function checkCollisionWithRequireExportsInGeneratedCode(node: Node, name: Identifier) { // No need to check for require or exports for ES6 modules and later if (modulekind >= ModuleKind.ES2015 || compilerOptions.noEmit) { @@ -22378,9 +22327,6 @@ namespace ts { if (node.kind === SyntaxKind.VariableDeclaration || node.kind === SyntaxKind.BindingElement) { checkVarDeclaredNamesNotShadowed(node); } - checkCollisionWithCapturedSuperVariable(node, node.name); - checkCollisionWithCapturedThisVariable(node, node.name); - checkCollisionWithCapturedNewTargetVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } @@ -23377,8 +23323,6 @@ namespace ts { checkDecorators(node); if (node.name) { checkTypeNameIsReserved(node.name, Diagnostics.Class_name_cannot_be_0); - checkCollisionWithCapturedThisVariable(node, node.name); - checkCollisionWithCapturedNewTargetVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } @@ -23907,8 +23851,6 @@ namespace ts { checkGrammarDecoratorsAndModifiers(node); checkTypeNameIsReserved(node.name, Diagnostics.Enum_name_cannot_be_0); - checkCollisionWithCapturedThisVariable(node, node.name); - checkCollisionWithCapturedNewTargetVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); checkExportsOnMergedDeclarations(node); @@ -24014,7 +23956,6 @@ namespace ts { } if (isIdentifier(node.name)) { - checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); } @@ -24222,7 +24163,6 @@ namespace ts { } function checkImportBinding(node: ImportEqualsDeclaration | ImportClause | NamespaceImport | ImportSpecifier) { - checkCollisionWithCapturedThisVariable(node, node.name); checkCollisionWithRequireExportsInGeneratedCode(node, node.name); checkCollisionWithGlobalPromiseInGeneratedCode(node, node.name); checkAliasSymbol(node); diff --git a/src/compiler/core.ts b/src/compiler/core.ts index 017d3545206..ae7e8de2ae1 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -2034,7 +2034,7 @@ namespace ts { return compilerOptions.target || ScriptTarget.ES3; } - export function getEmitModuleKind(compilerOptions: CompilerOptions) { + export function getEmitModuleKind(compilerOptions: {module?: CompilerOptions["module"], target?: CompilerOptions["target"]}) { return typeof compilerOptions.module === "number" ? compilerOptions.module : getEmitScriptTarget(compilerOptions) >= ScriptTarget.ES2015 ? ModuleKind.ES2015 : ModuleKind.CommonJS; diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 34fef4e431f..072b5f9608a 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -89,7 +89,6 @@ namespace ts { // targetSourceFile is when users only want one file in entire project to be emitted. This is used in compileOnSave feature export function emitFiles(resolver: EmitResolver, host: EmitHost, targetSourceFile: SourceFile, emitOnlyDtsFiles?: boolean, transformers?: TransformerFactory[]): EmitResult { const compilerOptions = host.getCompilerOptions(); - const moduleKind = getEmitModuleKind(compilerOptions); const sourceMapDataList: SourceMapData[] = (compilerOptions.sourceMap || compilerOptions.inlineSourceMap || getAreDeclarationMapsEnabled(compilerOptions)) ? [] : undefined; const emittedFilesList: string[] = compilerOptions.listEmittedFiles ? [] : undefined; const emitterDiagnostics = createDiagnosticCollection(); @@ -104,9 +103,6 @@ namespace ts { // Explicitly do not passthru either `inline` option }); - let currentSourceFile: SourceFile; - let bundledHelpers: Map; - let isOwnFileEmit: boolean; let emitSkipped = false; // Emit each output file @@ -153,7 +149,7 @@ namespace ts { const transform = transformNodes(resolver, host, compilerOptions, sourceFiles, transformers, /*allowDtsFiles*/ false); // Create a printer to print the nodes - const printer = createPrinter(compilerOptions, { + const printer = createPrinter({ ...compilerOptions, noEmitHelpers: compilerOptions.noEmitHelpers } as PrinterOptions, { // resolver hooks hasGlobalName: resolver.hasGlobalName, @@ -167,7 +163,6 @@ namespace ts { onEmitSourceMapOfPosition: sourceMap.emitPos, // emitter hooks - onEmitHelpers: emitHelpers, onSetSourceFile: setSourceFile, }); @@ -191,7 +186,7 @@ namespace ts { emitterDiagnostics.add(diagnostic); } } - const declarationPrinter = createPrinter({ ...compilerOptions, onlyPrintJsDocStyle: true } as PrinterOptions, { + const declarationPrinter = createPrinter({ ...compilerOptions, onlyPrintJsDocStyle: true, noEmitHelpers: true } as PrinterOptions, { // resolver hooks hasGlobalName: resolver.hasGlobalName, @@ -220,12 +215,9 @@ namespace ts { mapRecorder.initialize(jsFilePath, sourceMapFilePath || "", sourceFileOrBundle, sourceMapDataList); if (bundle) { - bundledHelpers = createMap(); - isOwnFileEmit = false; printer.writeBundle(bundle, writer); } else { - isOwnFileEmit = true; printer.writeFile(sourceFile, writer); } @@ -247,67 +239,15 @@ namespace ts { // Reset state mapRecorder.reset(); writer.clear(); - - currentSourceFile = undefined; - bundledHelpers = undefined; - isOwnFileEmit = false; } function setSourceFile(node: SourceFile) { - currentSourceFile = node; sourceMap.setSourceFile(node); } function setSourceFileForDeclarationSourceMaps(node: SourceFile) { - currentSourceFile = node; declarationSourceMap.setSourceFile(node); } - - function emitHelpers(node: Node, writeLines: (text: string) => void) { - let helpersEmitted = false; - const bundle = node.kind === SyntaxKind.Bundle ? node : undefined; - if (bundle && moduleKind === ModuleKind.None) { - return; - } - - const numNodes = bundle ? bundle.sourceFiles.length : 1; - for (let i = 0; i < numNodes; i++) { - const currentNode = bundle ? bundle.sourceFiles[i] : node; - const sourceFile = isSourceFile(currentNode) ? currentNode : currentSourceFile; - const shouldSkip = compilerOptions.noEmitHelpers || getExternalHelpersModuleName(sourceFile) !== undefined; - const shouldBundle = isSourceFile(currentNode) && !isOwnFileEmit; - const helpers = getEmitHelpers(currentNode); - if (helpers) { - for (const helper of stableSort(helpers, compareEmitHelpers)) { - if (!helper.scoped) { - // Skip the helper if it can be skipped and the noEmitHelpers compiler - // option is set, or if it can be imported and the importHelpers compiler - // option is set. - if (shouldSkip) continue; - - // Skip the helper if it can be bundled but hasn't already been emitted and we - // are emitting a bundled module. - if (shouldBundle) { - if (bundledHelpers.get(helper.name)) { - continue; - } - - bundledHelpers.set(helper.name, true); - } - } - else if (bundle) { - // Skip the helper if it is scoped and we are emitting bundled helpers - continue; - } - - writeLines(helper.text); - helpersEmitted = true; - } - } - } - - return helpersEmitted; - } } export function createPrinter(printerOptions: PrinterOptions = {}, handlers: PrintHandlers = {}): Printer { @@ -317,7 +257,6 @@ namespace ts { onEmitSourceMapOfToken, onEmitSourceMapOfPosition, onEmitNode, - onEmitHelpers, onSetSourceFile, substituteNode, onBeforeEmitNodeArray, @@ -355,6 +294,9 @@ namespace ts { writeSemicolon = deferWriteSemicolon; } const syntheticParent: TextRange = { pos: -1, end: -1 }; + const moduleKind = getEmitModuleKind(printerOptions); + const bundledHelpers = createMap(); + let isOwnFileEmit: boolean; reset(); return { @@ -431,11 +373,12 @@ namespace ts { } function writeBundle(bundle: Bundle, output: EmitTextWriter) { + isOwnFileEmit = false; const previousWriter = writer; setWriter(output); emitShebangIfNeeded(bundle); emitPrologueDirectivesIfNeeded(bundle); - emitHelpersIndirect(bundle); + emitHelpers(bundle); emitSyntheticTripleSlashReferencesIfNeeded(bundle); for (const sourceFile of bundle.sourceFiles) { print(EmitHint.SourceFile, sourceFile, sourceFile); @@ -445,6 +388,7 @@ namespace ts { } function writeFile(sourceFile: SourceFile, output: EmitTextWriter) { + isOwnFileEmit = true; const previousWriter = writer; setWriter(output); emitShebangIfNeeded(sourceFile); @@ -949,10 +893,55 @@ namespace ts { return node && substituteNode && substituteNode(hint, node) || node; } - function emitHelpersIndirect(node: Node) { - if (onEmitHelpers) { - onEmitHelpers(node, writeLines); + function emitHelpers(node: Node) { + let helpersEmitted = false; + const bundle = node.kind === SyntaxKind.Bundle ? node : undefined; + if (bundle && moduleKind === ModuleKind.None) { + return; } + + const numNodes = bundle ? bundle.sourceFiles.length : 1; + for (let i = 0; i < numNodes; i++) { + const currentNode = bundle ? bundle.sourceFiles[i] : node; + const sourceFile = isSourceFile(currentNode) ? currentNode : currentSourceFile; + const shouldSkip = printerOptions.noEmitHelpers || getExternalHelpersModuleName(sourceFile) !== undefined; + const shouldBundle = isSourceFile(currentNode) && !isOwnFileEmit; + const helpers = getEmitHelpers(currentNode); + if (helpers) { + for (const helper of stableSort(helpers, compareEmitHelpers)) { + if (!helper.scoped) { + // Skip the helper if it can be skipped and the noEmitHelpers compiler + // option is set, or if it can be imported and the importHelpers compiler + // option is set. + if (shouldSkip) continue; + + // Skip the helper if it can be bundled but hasn't already been emitted and we + // are emitting a bundled module. + if (shouldBundle) { + if (bundledHelpers.get(helper.name)) { + continue; + } + + bundledHelpers.set(helper.name, true); + } + } + else if (bundle) { + // Skip the helper if it is scoped and we are emitting bundled helpers + continue; + } + + if (typeof helper.text === "string") { + writeLines(helper.text); + } + else { + writeLines(helper.text(makeFileLevelOptmiisticUniqueName)); + } + helpersEmitted = true; + } + } + } + + return helpersEmitted; } // @@ -2006,7 +1995,7 @@ namespace ts { // Emit all the prologue directives (like "use strict"). const statementOffset = emitPrologueDirectives(body.statements, /*startWithNewLine*/ true); const pos = writer.getTextPos(); - emitHelpersIndirect(body); + emitHelpers(body); if (statementOffset === 0 && pos === writer.getTextPos() && emitBlockFunctionBodyOnSingleLine) { decreaseIndent(); emitList(body, body.statements, ListFormat.SingleLineFunctionBodyStatements); @@ -2513,7 +2502,7 @@ namespace ts { function emitSourceFileWorker(node: SourceFile) { const statements = node.statements; pushNameGenerationScope(node); - emitHelpersIndirect(node); + emitHelpers(node); const index = findIndex(statements, statement => !isPrologueDirective(statement)); emitTripleSlashDirectivesIfNeeded(node); emitList(node, statements, ListFormat.MultiLine, index === -1 ? statements.length : index); @@ -3256,12 +3245,18 @@ namespace ts { * or within the NameGenerator. */ function isUniqueName(name: string): boolean { - return !(hasGlobalName && hasGlobalName(name)) - && !currentSourceFile.identifiers.has(name) + return isFileLevelUniqueName(name) && !generatedNames.has(name) && !(reservedNames && reservedNames.has(name)); } + /** + * Returns a value indicating whether a name is unique globally or within the current file. + */ + function isFileLevelUniqueName(name: string) { + return ts.isFileLevelUniqueName(currentSourceFile, name, hasGlobalName); + } + /** * Returns a value indicating whether a name is unique within a container. */ @@ -3319,9 +3314,9 @@ namespace ts { * makeUniqueName are guaranteed to never conflict. * If `optimistic` is set, the first instance will use 'baseName' verbatim instead of 'baseName_1' */ - function makeUniqueName(baseName: string, optimistic?: boolean): string { + function makeUniqueName(baseName: string, checkFn: (name: string) => boolean = isUniqueName, optimistic?: boolean): string { if (optimistic) { - if (isUniqueName(baseName)) { + if (checkFn(baseName)) { generatedNames.set(baseName, true); return baseName; } @@ -3333,7 +3328,7 @@ namespace ts { let i = 1; while (true) { const generatedName = baseName + i; - if (isUniqueName(generatedName)) { + if (checkFn(generatedName)) { generatedNames.set(generatedName, true); return generatedName; } @@ -3341,6 +3336,10 @@ namespace ts { } } + function makeFileLevelOptmiisticUniqueName(name: string) { + return makeUniqueName(name, isFileLevelUniqueName, /*optimistic*/ true); + } + /** * Generates a unique name for a ModuleDeclaration or EnumDeclaration. */ @@ -3419,9 +3418,11 @@ namespace ts { case GeneratedIdentifierFlags.Loop: return makeTempVariableName(TempFlags._i, !!(name.autoGenerateFlags & GeneratedIdentifierFlags.ReservedInNestedScopes)); case GeneratedIdentifierFlags.Unique: - return makeUniqueName(idText(name)); - case GeneratedIdentifierFlags.OptimisticUnique: - return makeUniqueName(idText(name), /*optimistic*/ true); + return makeUniqueName( + idText(name), + (name.autoGenerateFlags & GeneratedIdentifierFlags.FileLevel) ? isFileLevelUniqueName : isUniqueName, + !!(name.autoGenerateFlags & GeneratedIdentifierFlags.Optimistic) + ); } Debug.fail("Unsupported GeneratedIdentifierKind."); diff --git a/src/compiler/factory.ts b/src/compiler/factory.ts index 1b951c5b0b7..c83ffd056af 100644 --- a/src/compiler/factory.ts +++ b/src/compiler/factory.ts @@ -177,12 +177,19 @@ namespace ts { /** Create a unique name based on the supplied text. */ export function createOptimisticUniqueName(text: string): Identifier { const name = createIdentifier(text); - name.autoGenerateFlags = GeneratedIdentifierFlags.OptimisticUnique; + name.autoGenerateFlags = GeneratedIdentifierFlags.Unique | GeneratedIdentifierFlags.Optimistic; name.autoGenerateId = nextAutoGenerateId; nextAutoGenerateId++; return name; } + /** Create a unique name based on the supplied text. This does not consider names injected by the transformer. */ + export function createFileLevelUniqueName(text: string): Identifier { + const name = createOptimisticUniqueName(text); + name.autoGenerateFlags |= GeneratedIdentifierFlags.FileLevel; + return name; + } + /** Create a unique name generated for a node. */ export function getGeneratedNameForNode(node: Node): Identifier; /* @internal */ export function getGeneratedNameForNode(node: Node, shouldSkipNameGenerationScope?: boolean): Identifier; // tslint:disable-line unified-signatures diff --git a/src/compiler/transformers/es2015.ts b/src/compiler/transformers/es2015.ts index 17c02052e60..72068688f9d 100644 --- a/src/compiler/transformers/es2015.ts +++ b/src/compiler/transformers/es2015.ts @@ -561,7 +561,7 @@ namespace ts { } function returnCapturedThis(node: Node): ReturnStatement { - return setOriginalNode(createReturn(createIdentifier("_this")), node); + return setOriginalNode(createReturn(createFileLevelUniqueName("_this")), node); } function visitReturnStatement(node: ReturnStatement): Statement { @@ -779,7 +779,7 @@ namespace ts { /*asteriskToken*/ undefined, /*name*/ undefined, /*typeParameters*/ undefined, - extendsClauseElement ? [createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, "_super")] : [], + extendsClauseElement ? [createParameter(/*decorators*/ undefined, /*modifiers*/ undefined, /*dotDotDotToken*/ undefined, createFileLevelUniqueName("_super"))] : [], /*type*/ undefined, transformClassBody(node, extendsClauseElement) ); @@ -978,7 +978,7 @@ namespace ts { && !(constructor && isSufficientlyCoveredByReturnStatements(constructor.body))) { statements.push( createReturn( - createIdentifier("_this") + createFileLevelUniqueName("_this") ) ); } @@ -1142,11 +1142,11 @@ namespace ts { return createLogicalOr( createLogicalAnd( createStrictInequality( - createIdentifier("_super"), + createFileLevelUniqueName("_super"), createNull() ), createFunctionApply( - createIdentifier("_super"), + createFileLevelUniqueName("_super"), createActualThis(), createIdentifier("arguments"), ) @@ -1452,7 +1452,7 @@ namespace ts { /*modifiers*/ undefined, createVariableDeclarationList([ createVariableDeclaration( - "_this", + createFileLevelUniqueName("_this"), /*type*/ undefined, initializer ) @@ -1517,7 +1517,7 @@ namespace ts { /*modifiers*/ undefined, createVariableDeclarationList([ createVariableDeclaration( - "_newTarget", + createFileLevelUniqueName("_newTarget"), /*type*/ undefined, newTarget ) @@ -3490,7 +3490,7 @@ namespace ts { actualThis ); resultingCall = assignToCapturedThis - ? createAssignment(createIdentifier("_this"), initializer) + ? createAssignment(createFileLevelUniqueName("_this"), initializer) : initializer; } return setOriginalNode(resultingCall, node); @@ -3811,8 +3811,8 @@ namespace ts { function visitSuperKeyword(isExpressionOfCall: boolean): LeftHandSideExpression { return hierarchyFacts & HierarchyFacts.NonStaticClassElement && !isExpressionOfCall - ? createPropertyAccess(createIdentifier("_super"), "prototype") - : createIdentifier("_super"); + ? createPropertyAccess(createFileLevelUniqueName("_super"), "prototype") + : createFileLevelUniqueName("_super"); } function visitMetaProperty(node: MetaProperty) { @@ -3823,7 +3823,7 @@ namespace ts { else { hierarchyFacts |= HierarchyFacts.NewTarget; } - return createIdentifier("_newTarget"); + return createFileLevelUniqueName("_newTarget"); } return node; } @@ -4000,7 +4000,7 @@ namespace ts { function substituteThisKeyword(node: PrimaryExpression): PrimaryExpression { if (enabledSubstitutions & ES2015SubstitutionFlags.CapturedThis && hierarchyFacts & HierarchyFacts.CapturesThis) { - return setTextRange(createIdentifier("_this"), node); + return setTextRange(createFileLevelUniqueName("_this"), node); } return node; } @@ -4052,7 +4052,7 @@ namespace ts { /*typeArguments*/ undefined, [ name, - createIdentifier("_super") + createFileLevelUniqueName("_super") ] ); } diff --git a/src/compiler/transformers/es2017.ts b/src/compiler/transformers/es2017.ts index bee99cdf533..f2a5aeb35d2 100644 --- a/src/compiler/transformers/es2017.ts +++ b/src/compiler/transformers/es2017.ts @@ -600,7 +600,7 @@ namespace ts { return setTextRange( createPropertyAccess( createCall( - createIdentifier("_super"), + createFileLevelUniqueName("_super"), /*typeArguments*/ undefined, [argumentExpression] ), @@ -612,7 +612,7 @@ namespace ts { else { return setTextRange( createCall( - createIdentifier("_super"), + createFileLevelUniqueName("_super"), /*typeArguments*/ undefined, [argumentExpression] ), @@ -668,15 +668,15 @@ namespace ts { export const asyncSuperHelper: EmitHelper = { name: "typescript:async-super", scoped: true, - text: ` - const _super = name => super[name];` + text: helperString` + const ${"_super"} = name => super[name];` }; export const advancedAsyncSuperHelper: EmitHelper = { name: "typescript:advanced-async-super", scoped: true, - text: ` - const _super = (function (geti, seti) { + text: helperString` + 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);` diff --git a/src/compiler/transformers/utilities.ts b/src/compiler/transformers/utilities.ts index 55adeba0b76..935f5b0ffd4 100644 --- a/src/compiler/transformers/utilities.ts +++ b/src/compiler/transformers/utilities.ts @@ -219,4 +219,20 @@ namespace ts { isKeyword(expression.kind) || isIdentifier(expression); } + + /** + * @param input Template string input strings + * @param args Names which need to be made file-level unique + */ + export function helperString(input: TemplateStringsArray, ...args: string[]) { + return (uniqueName: EmitHelperUniqueNameCallback) => { + let result = ""; + for (let i = 0; i < args.length; i++) { + result += input[i]; + result += uniqueName(args[i]); + } + result += input[input.length - 1]; + return result; + }; + } } \ No newline at end of file diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 6f4d556107d..b92e371febe 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -699,12 +699,13 @@ namespace ts { Loop = 2, // Automatically generated identifier with a preference for '_i'. Unique = 3, // Unique name based on the 'text' property. Node = 4, // Unique name based on the node in the 'original' property. - OptimisticUnique = 5, // Unique name based on the 'text' property, first instance won't use '_#' if there's no conflict KindMask = 7, // Mask to extract the kind of identifier from its flags. // Flags SkipNameGenerationScope = 1 << 3, // Should skip a name generation scope when generating the name for this identifier ReservedInNestedScopes = 1 << 4, // Reserve the generated name in nested scopes + Optimistic = 1 << 5, // First instance won't use '_#' if there's no conflict + FileLevel = 1 << 6, // Use only the file identifiers list and not generated names to search for conflicts } export interface Identifier extends PrimaryExpression, Declaration { @@ -4755,12 +4756,17 @@ namespace ts { } export interface EmitHelper { - readonly name: string; // A unique name for this helper. - readonly scoped: boolean; // Indicates whether the helper MUST be emitted in the current scope. - readonly text: string; // ES3-compatible raw script text. - readonly priority?: number; // Helpers with a higher priority are emitted earlier than other helpers on the node. + readonly name: string; // A unique name for this helper. + readonly scoped: boolean; // Indicates whether the helper MUST be emitted in the current scope. + readonly text: string | ((node: EmitHelperUniqueNameCallback) => string); // ES3-compatible raw script text, or a function yielding such a string + readonly priority?: number; // Helpers with a higher priority are emitted earlier than other helpers on the node. } + /* @internal */ + export type UniqueNameHandler = (baseName: string, checkFn?: (name: string) => boolean, optimistic?: boolean) => string; + + export type EmitHelperUniqueNameCallback = (name: string) => string; + /** * Used by the checker, this enum keeps track of external emit helpers that should be type * checked. @@ -5024,7 +5030,6 @@ namespace ts { /*@internal*/ onEmitSourceMapOfNode?: (hint: EmitHint, node: Node, emitCallback: (hint: EmitHint, node: Node) => void) => void; /*@internal*/ onEmitSourceMapOfToken?: (node: Node, token: SyntaxKind, writer: (s: string) => void, pos: number, emitCallback: (token: SyntaxKind, writer: (s: string) => void, pos: number) => number) => number; /*@internal*/ onEmitSourceMapOfPosition?: (pos: number) => void; - /*@internal*/ onEmitHelpers?: (node: Node, writeLines: (text: string) => void) => void; /*@internal*/ onSetSourceFile?: (node: SourceFile) => void; /*@internal*/ onBeforeEmitNodeArray?: (nodes: NodeArray) => void; /*@internal*/ onAfterEmitNodeArray?: (nodes: NodeArray) => void; @@ -5036,6 +5041,9 @@ namespace ts { removeComments?: boolean; newLine?: NewLineKind; omitTrailingSemicolon?: boolean; + noEmitHelpers?: boolean; + /*@internal*/ module?: CompilerOptions["module"]; + /*@internal*/ target?: CompilerOptions["target"]; /*@internal*/ sourceMap?: boolean; /*@internal*/ inlineSourceMap?: boolean; /*@internal*/ extendedDiagnostics?: boolean; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 9a6fbcc8c21..b85c7dfe3cf 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -229,6 +229,14 @@ namespace ts { } } + /** + * Returns a value indicating whether a name is unique globally or within the current file + */ + export function isFileLevelUniqueName(currentSourceFile: SourceFile, name: string, hasGlobalName?: PrintHandlers["hasGlobalName"]): boolean { + return !(hasGlobalName && hasGlobalName(name)) + && !currentSourceFile.identifiers.has(name); + } + // Returns true if this node is missing from the actual source code. A 'missing' node is different // from 'undefined/defined'. When a node is undefined (which can happen for optional nodes // in the tree), it is definitely missing. However, a node may be defined, but still be diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index 1d499a9e5e4..a8d31ef8fe9 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -2585,9 +2585,10 @@ declare namespace ts { interface EmitHelper { readonly name: string; readonly scoped: boolean; - readonly text: string; + readonly text: string | ((node: EmitHelperUniqueNameCallback) => string); readonly priority?: number; } + type EmitHelperUniqueNameCallback = (name: string) => string; enum EmitHint { SourceFile = 0, Expression = 1, @@ -2759,6 +2760,7 @@ declare namespace ts { removeComments?: boolean; newLine?: NewLineKind; omitTrailingSemicolon?: boolean; + noEmitHelpers?: boolean; } /** @deprecated See comment on SymbolWriter */ interface SymbolTracker { @@ -3451,6 +3453,8 @@ declare namespace ts { function createUniqueName(text: string): Identifier; /** Create a unique name based on the supplied text. */ function createOptimisticUniqueName(text: string): Identifier; + /** Create a unique name based on the supplied text. This does not consider names injected by the transformer. */ + function createFileLevelUniqueName(text: string): Identifier; /** Create a unique name generated for a node. */ function getGeneratedNameForNode(node: Node): Identifier; function createToken(token: TKind): Token; diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 5a8196f9bdf..76dbc06058b 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -2585,9 +2585,10 @@ declare namespace ts { interface EmitHelper { readonly name: string; readonly scoped: boolean; - readonly text: string; + readonly text: string | ((node: EmitHelperUniqueNameCallback) => string); readonly priority?: number; } + type EmitHelperUniqueNameCallback = (name: string) => string; enum EmitHint { SourceFile = 0, Expression = 1, @@ -2759,6 +2760,7 @@ declare namespace ts { removeComments?: boolean; newLine?: NewLineKind; omitTrailingSemicolon?: boolean; + noEmitHelpers?: boolean; } /** @deprecated See comment on SymbolWriter */ interface SymbolTracker { @@ -3398,6 +3400,8 @@ declare namespace ts { function createUniqueName(text: string): Identifier; /** Create a unique name based on the supplied text. */ function createOptimisticUniqueName(text: string): Identifier; + /** Create a unique name based on the supplied text. This does not consider names injected by the transformer. */ + function createFileLevelUniqueName(text: string): Identifier; /** Create a unique name generated for a node. */ function getGeneratedNameForNode(node: Node): Identifier; function createToken(token: TKind): Token; diff --git a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.js b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.js new file mode 100644 index 00000000000..4b33d8492e9 --- /dev/null +++ b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.js @@ -0,0 +1,111 @@ +//// [asyncMethodWithSuperConflict_es6.ts] +class A { + x() { + } +} + +class B extends A { + // async method with only call/get on 'super' does not require a binding + async simple() { + const _super = null; + // call with property access + super.x(); + + // call with element access + super["x"](); + + // property access (read) + const a = super.x; + + // element access (read) + const b = super["x"]; + } + + // async method with assignment/destructuring on 'super' requires a binding + async advanced() { + const _super = null; + const f = () => {}; + + // call with property access + super.x(); + + // call with element access + super["x"](); + + // property access (read) + const a = super.x; + + // element access (read) + const b = super["x"]; + + // property access (assign) + super.x = f; + + // element access (assign) + super["x"] = f; + + // destructuring assign with property access + ({ f: super.x } = { f }); + + // destructuring assign with element access + ({ f: super["x"] } = { f }); + } +} + +//// [asyncMethodWithSuperConflict_es6.js] +var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +}; +class A { + x() { + } +} +class B extends A { + // async method with only call/get on 'super' does not require a binding + simple() { + const _super_1 = name => super[name]; + return __awaiter(this, void 0, void 0, function* () { + const _super = null; + // call with property access + _super_1("x").call(this); + // call with element access + _super_1("x").call(this); + // property access (read) + const a = _super_1("x"); + // element access (read) + const b = _super_1("x"); + }); + } + // async method with assignment/destructuring on 'super' requires a binding + advanced() { + const _super_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); + return __awaiter(this, void 0, void 0, function* () { + const _super = null; + const f = () => { }; + // call with property access + _super_1("x").value.call(this); + // call with element access + _super_1("x").value.call(this); + // property access (read) + const a = _super_1("x").value; + // element access (read) + const b = _super_1("x").value; + // property access (assign) + _super_1("x").value = f; + // element access (assign) + _super_1("x").value = f; + // destructuring assign with property access + ({ f: _super_1("x").value } = { 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 new file mode 100644 index 00000000000..ddc8fdf013c --- /dev/null +++ b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.symbols @@ -0,0 +1,108 @@ +=== tests/cases/conformance/async/es2017/asyncMethodWithSuperConflict_es6.ts === +class A { +>A : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) + + x() { +>x : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) + } +} + +class B extends A { +>B : Symbol(B, Decl(asyncMethodWithSuperConflict_es6.ts, 3, 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)) + + const _super = null; +>_super : Symbol(_super, Decl(asyncMethodWithSuperConflict_es6.ts, 8, 13)) + + // call with property access + super.x(); +>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)) + + // call with element access + super["x"](); +>super : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) +>"x" : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) + + // property access (read) + const a = super.x; +>a : Symbol(a, Decl(asyncMethodWithSuperConflict_es6.ts, 16, 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)) +>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)) + + const _super = null; +>_super : Symbol(_super, Decl(asyncMethodWithSuperConflict_es6.ts, 24, 13)) + + const f = () => {}; +>f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 25, 13)) + + // call with property access + super.x(); +>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)) + + // call with element access + super["x"](); +>super : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) +>"x" : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) + + // property access (read) + const a = super.x; +>a : Symbol(a, Decl(asyncMethodWithSuperConflict_es6.ts, 34, 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)) +>super : Symbol(A, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 0)) +>"x" : Symbol(A.x, Decl(asyncMethodWithSuperConflict_es6.ts, 0, 9)) + + // property access (assign) + super.x = f; +>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)) + + // 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)) + + // destructuring assign with property access + ({ f: super.x } = { f }); +>f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 46, 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)) + + // destructuring assign with element access + ({ f: super["x"] } = { f }); +>f : Symbol(f, Decl(asyncMethodWithSuperConflict_es6.ts, 49, 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)) + } +} diff --git a/tests/baselines/reference/asyncMethodWithSuperConflict_es6.types b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.types new file mode 100644 index 00000000000..ac82440a3d8 --- /dev/null +++ b/tests/baselines/reference/asyncMethodWithSuperConflict_es6.types @@ -0,0 +1,131 @@ +=== tests/cases/conformance/async/es2017/asyncMethodWithSuperConflict_es6.ts === +class A { +>A : A + + x() { +>x : () => void + } +} + +class B extends A { +>B : B +>A : A + + // async method with only call/get on 'super' does not require a binding + async simple() { +>simple : () => Promise + + const _super = null; +>_super : any +>null : null + + // call with property access + super.x(); +>super.x() : void +>super.x : () => void +>super : A +>x : () => void + + // call with element access + super["x"](); +>super["x"]() : void +>super["x"] : () => void +>super : A +>"x" : "x" + + // property access (read) + const a = super.x; +>a : () => void +>super.x : () => void +>super : A +>x : () => void + + // element access (read) + const b = super["x"]; +>b : () => void +>super["x"] : () => void +>super : A +>"x" : "x" + } + + // async method with assignment/destructuring on 'super' requires a binding + async advanced() { +>advanced : () => Promise + + const _super = null; +>_super : any +>null : null + + const f = () => {}; +>f : () => void +>() => {} : () => void + + // call with property access + super.x(); +>super.x() : void +>super.x : () => void +>super : A +>x : () => void + + // call with element access + super["x"](); +>super["x"]() : void +>super["x"] : () => void +>super : A +>"x" : "x" + + // property access (read) + const a = super.x; +>a : () => void +>super.x : () => void +>super : A +>x : () => void + + // element access (read) + const b = super["x"]; +>b : () => void +>super["x"] : () => void +>super : A +>"x" : "x" + + // property access (assign) + super.x = f; +>super.x = f : () => void +>super.x : () => void +>super : A +>x : () => void +>f : () => void + + // element access (assign) + super["x"] = f; +>super["x"] = f : () => void +>super["x"] : () => void +>super : A +>"x" : "x" +>f : () => void + + // destructuring assign with property access + ({ f: super.x } = { f }); +>({ f: super.x } = { f }) : { f: () => void; } +>{ f: super.x } = { f } : { f: () => void; } +>{ f: super.x } : { f: () => void; } +>f : () => void +>super.x : () => void +>super : A +>x : () => void +>{ f } : { f: () => void; } +>f : () => void + + // destructuring assign with element access + ({ f: super["x"] } = { f }); +>({ f: super["x"] } = { f }) : { f: () => void; } +>{ f: super["x"] } = { f } : { f: () => void; } +>{ f: super["x"] } : { f: () => void; } +>f : () => void +>super["x"] : () => void +>super : A +>"x" : "x" +>{ f } : { f: () => void; } +>f : () => void + } +} diff --git a/tests/baselines/reference/collisionSuperAndLocalFunctionInAccessors.errors.txt b/tests/baselines/reference/collisionSuperAndLocalFunctionInAccessors.errors.txt deleted file mode 100644 index 16b4edced7b..00000000000 --- a/tests/baselines/reference/collisionSuperAndLocalFunctionInAccessors.errors.txt +++ /dev/null @@ -1,72 +0,0 @@ -tests/cases/compiler/collisionSuperAndLocalFunctionInAccessors.ts(4,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionSuperAndLocalFunctionInAccessors.ts(9,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionSuperAndLocalFunctionInAccessors.ts(15,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionSuperAndLocalFunctionInAccessors.ts(16,18): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndLocalFunctionInAccessors.ts(20,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionSuperAndLocalFunctionInAccessors.ts(21,18): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndLocalFunctionInAccessors.ts(26,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionSuperAndLocalFunctionInAccessors.ts(28,22): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndLocalFunctionInAccessors.ts(33,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionSuperAndLocalFunctionInAccessors.ts(35,22): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - - -==== tests/cases/compiler/collisionSuperAndLocalFunctionInAccessors.ts (10 errors) ==== - function _super() { // No error - } - class Foo { - get prop1(): number { - ~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - function _super() { // No error - } - return 10; - } - set prop1(val: number) { - ~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - function _super() { // No error - } - } - } - class b extends Foo { - get prop2(): number { - ~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - function _super() { // Should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - return 10; - } - set prop2(val: number) { - ~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - function _super() { // Should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - } - class c extends Foo { - get prop2(): number { - ~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var x = () => { - function _super() { // Should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - return 10; - } - set prop2(val: number) { - ~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var x = () => { - function _super() { // Should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionSuperAndLocalFunctionInAccessors.js b/tests/baselines/reference/collisionSuperAndLocalFunctionInAccessors.js index 000c3cfe35e..9c9dfa787ea 100644 --- a/tests/baselines/reference/collisionSuperAndLocalFunctionInAccessors.js +++ b/tests/baselines/reference/collisionSuperAndLocalFunctionInAccessors.js @@ -70,10 +70,10 @@ var Foo = /** @class */ (function () { }); return Foo; }()); -var b = /** @class */ (function (_super) { - __extends(b, _super); +var b = /** @class */ (function (_super_1) { + __extends(b, _super_1); function b() { - return _super !== null && _super.apply(this, arguments) || this; + return _super_1 !== null && _super_1.apply(this, arguments) || this; } Object.defineProperty(b.prototype, "prop2", { get: function () { @@ -90,10 +90,10 @@ var b = /** @class */ (function (_super) { }); return b; }(Foo)); -var c = /** @class */ (function (_super) { - __extends(c, _super); +var c = /** @class */ (function (_super_1) { + __extends(c, _super_1); function c() { - return _super !== null && _super.apply(this, arguments) || this; + return _super_1 !== null && _super_1.apply(this, arguments) || this; } Object.defineProperty(c.prototype, "prop2", { get: function () { diff --git a/tests/baselines/reference/collisionSuperAndLocalFunctionInConstructor.errors.txt b/tests/baselines/reference/collisionSuperAndLocalFunctionInConstructor.errors.txt deleted file mode 100644 index 5e1ec686bfd..00000000000 --- a/tests/baselines/reference/collisionSuperAndLocalFunctionInConstructor.errors.txt +++ /dev/null @@ -1,33 +0,0 @@ -tests/cases/compiler/collisionSuperAndLocalFunctionInConstructor.ts(12,18): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndLocalFunctionInConstructor.ts(20,22): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - - -==== tests/cases/compiler/collisionSuperAndLocalFunctionInConstructor.ts (2 errors) ==== - function _super() { // No error - } - class Foo { - constructor() { - function _super() { // No error - } - } - } - class b extends Foo { - constructor() { - super(); - function _super() { // Should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - } - class c extends Foo { - constructor() { - super(); - var x = () => { - function _super() { // Should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionSuperAndLocalFunctionInConstructor.js b/tests/baselines/reference/collisionSuperAndLocalFunctionInConstructor.js index 4c2d6fce349..368a05ed9a9 100644 --- a/tests/baselines/reference/collisionSuperAndLocalFunctionInConstructor.js +++ b/tests/baselines/reference/collisionSuperAndLocalFunctionInConstructor.js @@ -44,20 +44,20 @@ var Foo = /** @class */ (function () { } return Foo; }()); -var b = /** @class */ (function (_super) { - __extends(b, _super); +var b = /** @class */ (function (_super_1) { + __extends(b, _super_1); function b() { - var _this = _super.call(this) || this; + var _this = _super_1.call(this) || this; function _super() { } return _this; } return b; }(Foo)); -var c = /** @class */ (function (_super) { - __extends(c, _super); +var c = /** @class */ (function (_super_1) { + __extends(c, _super_1); function c() { - var _this = _super.call(this) || this; + var _this = _super_1.call(this) || this; var x = function () { function _super() { } diff --git a/tests/baselines/reference/collisionSuperAndLocalFunctionInMethod.errors.txt b/tests/baselines/reference/collisionSuperAndLocalFunctionInMethod.errors.txt deleted file mode 100644 index e899858fcc9..00000000000 --- a/tests/baselines/reference/collisionSuperAndLocalFunctionInMethod.errors.txt +++ /dev/null @@ -1,37 +0,0 @@ -tests/cases/compiler/collisionSuperAndLocalFunctionInMethod.ts(13,18): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndLocalFunctionInMethod.ts(22,22): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - - -==== tests/cases/compiler/collisionSuperAndLocalFunctionInMethod.ts (2 errors) ==== - function _super() { // No error - } - class Foo { - x() { - function _super() { // No error - } - } - _super() { // No error - } - } - class b extends Foo { - public foo() { - function _super() { // should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - _super() { // No Error - } - } - class c extends Foo { - public foo() { - var x = () => { - function _super() { // should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - } - _super() { // No error - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionSuperAndLocalFunctionInMethod.js b/tests/baselines/reference/collisionSuperAndLocalFunctionInMethod.js index 74ca7f80ce4..ec36afb9c7e 100644 --- a/tests/baselines/reference/collisionSuperAndLocalFunctionInMethod.js +++ b/tests/baselines/reference/collisionSuperAndLocalFunctionInMethod.js @@ -52,10 +52,10 @@ var Foo = /** @class */ (function () { }; return Foo; }()); -var b = /** @class */ (function (_super) { - __extends(b, _super); +var b = /** @class */ (function (_super_1) { + __extends(b, _super_1); function b() { - return _super !== null && _super.apply(this, arguments) || this; + return _super_1 !== null && _super_1.apply(this, arguments) || this; } b.prototype.foo = function () { function _super() { @@ -65,10 +65,10 @@ var b = /** @class */ (function (_super) { }; return b; }(Foo)); -var c = /** @class */ (function (_super) { - __extends(c, _super); +var c = /** @class */ (function (_super_1) { + __extends(c, _super_1); function c() { - return _super !== null && _super.apply(this, arguments) || this; + return _super_1 !== null && _super_1.apply(this, arguments) || this; } c.prototype.foo = function () { var x = function () { diff --git a/tests/baselines/reference/collisionSuperAndLocalFunctionInProperty.errors.txt b/tests/baselines/reference/collisionSuperAndLocalFunctionInProperty.errors.txt deleted file mode 100644 index f5c585525e0..00000000000 --- a/tests/baselines/reference/collisionSuperAndLocalFunctionInProperty.errors.txt +++ /dev/null @@ -1,24 +0,0 @@ -tests/cases/compiler/collisionSuperAndLocalFunctionInProperty.ts(14,22): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - - -==== tests/cases/compiler/collisionSuperAndLocalFunctionInProperty.ts (1 errors) ==== - function _super() { // No error - } - class Foo { - public prop1 = { - doStuff: () => { - function _super() { // No error - } - } - } - } - class b extends Foo { - public prop2 = { - doStuff: () => { - function _super() { // error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionSuperAndLocalFunctionInProperty.js b/tests/baselines/reference/collisionSuperAndLocalFunctionInProperty.js index 586315b1607..dcff481846f 100644 --- a/tests/baselines/reference/collisionSuperAndLocalFunctionInProperty.js +++ b/tests/baselines/reference/collisionSuperAndLocalFunctionInProperty.js @@ -42,10 +42,10 @@ var Foo = /** @class */ (function () { } return Foo; }()); -var b = /** @class */ (function (_super) { - __extends(b, _super); +var b = /** @class */ (function (_super_1) { + __extends(b, _super_1); function b() { - var _this = _super !== null && _super.apply(this, arguments) || this; + var _this = _super_1 !== null && _super_1.apply(this, arguments) || this; _this.prop2 = { doStuff: function () { function _super() { diff --git a/tests/baselines/reference/collisionSuperAndLocalVarInAccessors.errors.txt b/tests/baselines/reference/collisionSuperAndLocalVarInAccessors.errors.txt deleted file mode 100644 index 7e0f80f0658..00000000000 --- a/tests/baselines/reference/collisionSuperAndLocalVarInAccessors.errors.txt +++ /dev/null @@ -1,65 +0,0 @@ -tests/cases/compiler/collisionSuperAndLocalVarInAccessors.ts(3,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionSuperAndLocalVarInAccessors.ts(7,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionSuperAndLocalVarInAccessors.ts(12,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionSuperAndLocalVarInAccessors.ts(13,13): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndLocalVarInAccessors.ts(16,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionSuperAndLocalVarInAccessors.ts(17,13): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndLocalVarInAccessors.ts(21,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionSuperAndLocalVarInAccessors.ts(23,17): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndLocalVarInAccessors.ts(27,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionSuperAndLocalVarInAccessors.ts(29,17): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - - -==== tests/cases/compiler/collisionSuperAndLocalVarInAccessors.ts (10 errors) ==== - var _super = 10; // No Error - class Foo { - get prop1(): number { - ~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var _super = 10; // No error - return 10; - } - set prop1(val: number) { - ~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var _super = 10; // No error - } - } - class b extends Foo { - get prop2(): number { - ~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var _super = 10; // Should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - return 10; - } - set prop2(val: number) { - ~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var _super = 10; // Should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - class c extends Foo { - get prop2(): number { - ~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var x = () => { - var _super = 10; // Should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - return 10; - } - set prop2(val: number) { - ~~~~~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var x = () => { - var _super = 10; // Should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionSuperAndLocalVarInAccessors.js b/tests/baselines/reference/collisionSuperAndLocalVarInAccessors.js index d5541889a81..7339e62c6ac 100644 --- a/tests/baselines/reference/collisionSuperAndLocalVarInAccessors.js +++ b/tests/baselines/reference/collisionSuperAndLocalVarInAccessors.js @@ -60,10 +60,10 @@ var Foo = /** @class */ (function () { }); return Foo; }()); -var b = /** @class */ (function (_super) { - __extends(b, _super); +var b = /** @class */ (function (_super_1) { + __extends(b, _super_1); function b() { - return _super !== null && _super.apply(this, arguments) || this; + return _super_1 !== null && _super_1.apply(this, arguments) || this; } Object.defineProperty(b.prototype, "prop2", { get: function () { @@ -78,10 +78,10 @@ var b = /** @class */ (function (_super) { }); return b; }(Foo)); -var c = /** @class */ (function (_super) { - __extends(c, _super); +var c = /** @class */ (function (_super_1) { + __extends(c, _super_1); function c() { - return _super !== null && _super.apply(this, arguments) || this; + return _super_1 !== null && _super_1.apply(this, arguments) || this; } Object.defineProperty(c.prototype, "prop2", { get: function () { diff --git a/tests/baselines/reference/collisionSuperAndLocalVarInConstructor.errors.txt b/tests/baselines/reference/collisionSuperAndLocalVarInConstructor.errors.txt deleted file mode 100644 index 4097187c3bf..00000000000 --- a/tests/baselines/reference/collisionSuperAndLocalVarInConstructor.errors.txt +++ /dev/null @@ -1,29 +0,0 @@ -tests/cases/compiler/collisionSuperAndLocalVarInConstructor.ts(10,13): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndLocalVarInConstructor.ts(17,17): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - - -==== tests/cases/compiler/collisionSuperAndLocalVarInConstructor.ts (2 errors) ==== - var _super = 10; // No Error - class Foo { - constructor() { - var _super = 10; // No error - } - } - class b extends Foo { - constructor() { - super(); - var _super = 10; // Should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - class c extends Foo { - constructor() { - super(); - var x = () => { - var _super = 10; // Should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionSuperAndLocalVarInConstructor.js b/tests/baselines/reference/collisionSuperAndLocalVarInConstructor.js index e586b4dc55e..c5725e59906 100644 --- a/tests/baselines/reference/collisionSuperAndLocalVarInConstructor.js +++ b/tests/baselines/reference/collisionSuperAndLocalVarInConstructor.js @@ -38,19 +38,19 @@ var Foo = /** @class */ (function () { } return Foo; }()); -var b = /** @class */ (function (_super) { - __extends(b, _super); +var b = /** @class */ (function (_super_1) { + __extends(b, _super_1); function b() { - var _this = _super.call(this) || this; + var _this = _super_1.call(this) || this; var _super = 10; // Should be error return _this; } return b; }(Foo)); -var c = /** @class */ (function (_super) { - __extends(c, _super); +var c = /** @class */ (function (_super_1) { + __extends(c, _super_1); function c() { - var _this = _super.call(this) || this; + var _this = _super_1.call(this) || this; var x = function () { var _super = 10; // Should be error }; diff --git a/tests/baselines/reference/collisionSuperAndLocalVarInMethod.errors.txt b/tests/baselines/reference/collisionSuperAndLocalVarInMethod.errors.txt deleted file mode 100644 index 72e19e20094..00000000000 --- a/tests/baselines/reference/collisionSuperAndLocalVarInMethod.errors.txt +++ /dev/null @@ -1,27 +0,0 @@ -tests/cases/compiler/collisionSuperAndLocalVarInMethod.ts(9,13): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndLocalVarInMethod.ts(15,17): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - - -==== tests/cases/compiler/collisionSuperAndLocalVarInMethod.ts (2 errors) ==== - var _super = 10; // No Error - class Foo { - x() { - var _super = 10; // No error - } - } - class b extends Foo { - public foo() { - var _super = 10; // Should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - class c extends Foo { - public foo() { - var x = () => { - var _super = 10; // Should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionSuperAndLocalVarInMethod.js b/tests/baselines/reference/collisionSuperAndLocalVarInMethod.js index 54ed127b6c1..883219d0a5a 100644 --- a/tests/baselines/reference/collisionSuperAndLocalVarInMethod.js +++ b/tests/baselines/reference/collisionSuperAndLocalVarInMethod.js @@ -38,20 +38,20 @@ var Foo = /** @class */ (function () { }; return Foo; }()); -var b = /** @class */ (function (_super) { - __extends(b, _super); +var b = /** @class */ (function (_super_1) { + __extends(b, _super_1); function b() { - return _super !== null && _super.apply(this, arguments) || this; + return _super_1 !== null && _super_1.apply(this, arguments) || this; } b.prototype.foo = function () { var _super = 10; // Should be error }; return b; }(Foo)); -var c = /** @class */ (function (_super) { - __extends(c, _super); +var c = /** @class */ (function (_super_1) { + __extends(c, _super_1); function c() { - return _super !== null && _super.apply(this, arguments) || this; + return _super_1 !== null && _super_1.apply(this, arguments) || this; } c.prototype.foo = function () { var x = function () { diff --git a/tests/baselines/reference/collisionSuperAndLocalVarInProperty.errors.txt b/tests/baselines/reference/collisionSuperAndLocalVarInProperty.errors.txt deleted file mode 100644 index 6c786c83d8a..00000000000 --- a/tests/baselines/reference/collisionSuperAndLocalVarInProperty.errors.txt +++ /dev/null @@ -1,23 +0,0 @@ -tests/cases/compiler/collisionSuperAndLocalVarInProperty.ts(13,17): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - - -==== tests/cases/compiler/collisionSuperAndLocalVarInProperty.ts (1 errors) ==== - var _super = 10; // No Error - class Foo { - public prop1 = { - doStuff: () => { - var _super = 10; // No error - } - } - public _super = 10; // No error - } - class b extends Foo { - public prop2 = { - doStuff: () => { - var _super = 10; // Should be error - ~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - public _super = 10; // No error - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionSuperAndLocalVarInProperty.js b/tests/baselines/reference/collisionSuperAndLocalVarInProperty.js index b7b9490a115..9dfc8cb86bf 100644 --- a/tests/baselines/reference/collisionSuperAndLocalVarInProperty.js +++ b/tests/baselines/reference/collisionSuperAndLocalVarInProperty.js @@ -40,10 +40,10 @@ var Foo = /** @class */ (function () { } return Foo; }()); -var b = /** @class */ (function (_super) { - __extends(b, _super); +var b = /** @class */ (function (_super_1) { + __extends(b, _super_1); function b() { - var _this = _super !== null && _super.apply(this, arguments) || this; + var _this = _super_1 !== null && _super_1.apply(this, arguments) || this; _this.prop2 = { doStuff: function () { var _super = 10; // Should be error diff --git a/tests/baselines/reference/collisionSuperAndNameResolution.errors.txt b/tests/baselines/reference/collisionSuperAndNameResolution.errors.txt deleted file mode 100644 index ea874952320..00000000000 --- a/tests/baselines/reference/collisionSuperAndNameResolution.errors.txt +++ /dev/null @@ -1,17 +0,0 @@ -tests/cases/compiler/collisionSuperAndNameResolution.ts(9,21): error TS2402: Expression resolves to '_super' that compiler uses to capture base class reference. - - -==== tests/cases/compiler/collisionSuperAndNameResolution.ts (1 errors) ==== - var console: { - log(message: any); - } - var _super = 10; // No error - class base { - } - class Foo extends base { - x() { - console.log(_super); // Error as this doesnt not resolve to user defined _super - ~~~~~~ -!!! error TS2402: Expression resolves to '_super' that compiler uses to capture base class reference. - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionSuperAndNameResolution.js b/tests/baselines/reference/collisionSuperAndNameResolution.js index c8489e006a8..933e3f5f204 100644 --- a/tests/baselines/reference/collisionSuperAndNameResolution.js +++ b/tests/baselines/reference/collisionSuperAndNameResolution.js @@ -29,10 +29,10 @@ var base = /** @class */ (function () { } return base; }()); -var Foo = /** @class */ (function (_super) { - __extends(Foo, _super); +var Foo = /** @class */ (function (_super_1) { + __extends(Foo, _super_1); function Foo() { - return _super !== null && _super.apply(this, arguments) || this; + return _super_1 !== null && _super_1.apply(this, arguments) || this; } Foo.prototype.x = function () { console.log(_super); // Error as this doesnt not resolve to user defined _super diff --git a/tests/baselines/reference/collisionSuperAndParameter.errors.txt b/tests/baselines/reference/collisionSuperAndParameter.errors.txt deleted file mode 100644 index 65dddd95d48..00000000000 --- a/tests/baselines/reference/collisionSuperAndParameter.errors.txt +++ /dev/null @@ -1,92 +0,0 @@ -tests/cases/compiler/collisionSuperAndParameter.ts(12,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionSuperAndParameter.ts(17,22): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndParameter.ts(21,7): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndParameter.ts(26,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionSuperAndParameter.ts(26,11): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndParameter.ts(32,19): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndParameter.ts(35,17): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndParameter.ts(52,17): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndParameter.ts(57,7): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - - -==== tests/cases/compiler/collisionSuperAndParameter.ts (9 errors) ==== - class Foo { - a() { - var lamda = (_super: number) => { // No Error - return x => this; // New scope. So should inject new _this capture - } - } - b(_super: number) { // No Error - var lambda = () => { - return x => this; // New scope. So should inject new _this capture - } - } - set c(_super: number) { // No error - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - } - } - class Foo2 extends Foo { - x() { - var lamda = (_super: number) => { // Error - ~~~~~~~~~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - return x => this; // New scope. So should inject new _this capture - } - } - y(_super: number) { // Error - ~~~~~~~~~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - var lambda = () => { - return x => this; // New scope. So should inject new _this capture - } - } - set z(_super: number) { // Error - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - ~~~~~~~~~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - public prop3: { - doStuff: (_super: number) => void; // no error - no code gen - } - public prop4 = { - doStuff: (_super: number) => { // should be error - ~~~~~~~~~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - constructor(_super: number) { // should be error - ~~~~~~~~~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - super(); - } - } - declare class Foo3 extends Foo { - x(); - y(_super: number); // No error - no code gen - constructor(_super: number); // No error - no code gen - public prop2: { - doStuff: (_super: number) => void; // no error - no code gen - }; - public _super: number; // No error - } - - class Foo4 extends Foo { - constructor(_super: number); // no code gen - no error - constructor(_super: string);// no code gen - no error - constructor(_super: any) { // should be error - ~~~~~~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - super(); - } - y(_super: number); // no code gen - no error - y(_super: string); // no code gen - no error - y(_super: any) { // Error - ~~~~~~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - var lambda = () => { - return x => this; // New scope. So should inject new _this capture - } - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionSuperAndParameter.js b/tests/baselines/reference/collisionSuperAndParameter.js index 9ee69713883..cde7eef54e1 100644 --- a/tests/baselines/reference/collisionSuperAndParameter.js +++ b/tests/baselines/reference/collisionSuperAndParameter.js @@ -96,10 +96,10 @@ var Foo = /** @class */ (function () { }); return Foo; }()); -var Foo2 = /** @class */ (function (_super) { - __extends(Foo2, _super); +var Foo2 = /** @class */ (function (_super_1) { + __extends(Foo2, _super_1); function Foo2(_super) { - var _this = _super.call(this) || this; + var _this = _super_1.call(this) || this; _this.prop4 = { doStuff: function (_super) { } @@ -126,10 +126,10 @@ var Foo2 = /** @class */ (function (_super) { }); return Foo2; }(Foo)); -var Foo4 = /** @class */ (function (_super) { - __extends(Foo4, _super); +var Foo4 = /** @class */ (function (_super_1) { + __extends(Foo4, _super_1); function Foo4(_super) { - return _super.call(this) || this; + return _super_1.call(this) || this; } Foo4.prototype.y = function (_super) { var _this = this; diff --git a/tests/baselines/reference/collisionSuperAndParameter1.errors.txt b/tests/baselines/reference/collisionSuperAndParameter1.errors.txt deleted file mode 100644 index 361ecc1668e..00000000000 --- a/tests/baselines/reference/collisionSuperAndParameter1.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/collisionSuperAndParameter1.ts(6,23): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - - -==== tests/cases/compiler/collisionSuperAndParameter1.ts (1 errors) ==== - class Foo { - } - - class Foo2 extends Foo { - x() { - var lambda = (_super: number) => { // Error - ~~~~~~~~~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - } - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionSuperAndParameter1.js b/tests/baselines/reference/collisionSuperAndParameter1.js index f665a5d03df..65f4ca4d10c 100644 --- a/tests/baselines/reference/collisionSuperAndParameter1.js +++ b/tests/baselines/reference/collisionSuperAndParameter1.js @@ -25,10 +25,10 @@ var Foo = /** @class */ (function () { } return Foo; }()); -var Foo2 = /** @class */ (function (_super) { - __extends(Foo2, _super); +var Foo2 = /** @class */ (function (_super_1) { + __extends(Foo2, _super_1); function Foo2() { - return _super !== null && _super.apply(this, arguments) || this; + return _super_1 !== null && _super_1.apply(this, arguments) || this; } Foo2.prototype.x = function () { var lambda = function (_super) { diff --git a/tests/baselines/reference/collisionSuperAndPropertyNameAsConstuctorParameter.errors.txt b/tests/baselines/reference/collisionSuperAndPropertyNameAsConstuctorParameter.errors.txt deleted file mode 100644 index 20e71ee1b7a..00000000000 --- a/tests/baselines/reference/collisionSuperAndPropertyNameAsConstuctorParameter.errors.txt +++ /dev/null @@ -1,45 +0,0 @@ -tests/cases/compiler/collisionSuperAndPropertyNameAsConstuctorParameter.ts(5,17): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndPropertyNameAsConstuctorParameter.ts(11,17): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndPropertyNameAsConstuctorParameter.ts(19,17): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. -tests/cases/compiler/collisionSuperAndPropertyNameAsConstuctorParameter.ts(27,17): error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - - -==== tests/cases/compiler/collisionSuperAndPropertyNameAsConstuctorParameter.ts (4 errors) ==== - class a { - } - - class b1 extends a { - constructor(_super: number) { // should be error - ~~~~~~~~~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - super(); - } - } - - class b2 extends a { - constructor(private _super: number) { // should be error - ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - super(); - } - } - - class b3 extends a { - constructor(_super: number); // no code gen - no error - constructor(_super: string);// no code gen - no error - constructor(_super: any) { // should be error - ~~~~~~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - super(); - } - } - - class b4 extends a { - constructor(_super: number); // no code gen - no error - constructor(_super: string);// no code gen - no error - constructor(private _super: any) { // should be error - ~~~~~~~~~~~~~~~~~~~ -!!! error TS2401: Duplicate identifier '_super'. Compiler uses '_super' to capture base class reference. - super(); - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionSuperAndPropertyNameAsConstuctorParameter.js b/tests/baselines/reference/collisionSuperAndPropertyNameAsConstuctorParameter.js index a98bb021c55..9bc347b4361 100644 --- a/tests/baselines/reference/collisionSuperAndPropertyNameAsConstuctorParameter.js +++ b/tests/baselines/reference/collisionSuperAndPropertyNameAsConstuctorParameter.js @@ -46,33 +46,33 @@ var a = /** @class */ (function () { } return a; }()); -var b1 = /** @class */ (function (_super) { - __extends(b1, _super); +var b1 = /** @class */ (function (_super_1) { + __extends(b1, _super_1); function b1(_super) { - return _super.call(this) || this; + return _super_1.call(this) || this; } return b1; }(a)); -var b2 = /** @class */ (function (_super) { - __extends(b2, _super); +var b2 = /** @class */ (function (_super_1) { + __extends(b2, _super_1); function b2(_super) { - var _this = _super.call(this) || this; + var _this = _super_1.call(this) || this; _this._super = _super; return _this; } return b2; }(a)); -var b3 = /** @class */ (function (_super) { - __extends(b3, _super); +var b3 = /** @class */ (function (_super_1) { + __extends(b3, _super_1); function b3(_super) { - return _super.call(this) || this; + return _super_1.call(this) || this; } return b3; }(a)); -var b4 = /** @class */ (function (_super) { - __extends(b4, _super); +var b4 = /** @class */ (function (_super_1) { + __extends(b4, _super_1); function b4(_super) { - var _this = _super.call(this) || this; + var _this = _super_1.call(this) || this; _this._super = _super; return _this; } diff --git a/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.errors.txt b/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.errors.txt deleted file mode 100644 index 96f05d6bfcc..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.errors.txt +++ /dev/null @@ -1,11 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndAliasInGlobal.ts(5,8): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndAliasInGlobal.ts (1 errors) ==== - module a { - export var b = 10; - } - var f = () => this; - import _this = a; // Error - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.js b/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.js index 1f613798642..423b685c8d6 100644 --- a/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.js +++ b/tests/baselines/reference/collisionThisExpressionAndAliasInGlobal.js @@ -6,10 +6,10 @@ var f = () => this; import _this = a; // Error //// [collisionThisExpressionAndAliasInGlobal.js] -var _this = this; +var _this_1 = this; var a; (function (a) { a.b = 10; })(a || (a = {})); -var f = function () { return _this; }; +var f = function () { return _this_1; }; var _this = a; // Error diff --git a/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.errors.txt b/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.errors.txt deleted file mode 100644 index 562f0d2a94a..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndAmbientClassInGlobal.ts(4,13): error TS2400: Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndAmbientClassInGlobal.ts (1 errors) ==== - declare class _this { // no error - as no code generation - } - var f = () => this; - var a = new _this(); // Error - ~~~~~ -!!! error TS2400: Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference. \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.js b/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.js index b99311b0c3e..8e9cb96df1a 100644 --- a/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.js +++ b/tests/baselines/reference/collisionThisExpressionAndAmbientClassInGlobal.js @@ -5,6 +5,6 @@ var f = () => this; var a = new _this(); // Error //// [collisionThisExpressionAndAmbientClassInGlobal.js] -var _this = this; -var f = function () { return _this; }; +var _this_1 = this; +var f = function () { return _this_1; }; var a = new _this(); // Error diff --git a/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.errors.txt b/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.errors.txt deleted file mode 100644 index 412b2c8e18d..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndAmbientVarInGlobal.ts(3,1): error TS2400: Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndAmbientVarInGlobal.ts (1 errors) ==== - declare var _this: number; // no error as no code gen - var f = () => this; - _this = 10; // Error - ~~~~~ -!!! error TS2400: Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference. \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.js b/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.js index c6c54869056..3f7e2c80d49 100644 --- a/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.js +++ b/tests/baselines/reference/collisionThisExpressionAndAmbientVarInGlobal.js @@ -4,6 +4,6 @@ var f = () => this; _this = 10; // Error //// [collisionThisExpressionAndAmbientVarInGlobal.js] -var _this = this; -var f = function () { return _this; }; +var _this_1 = this; +var f = function () { return _this_1; }; _this = 10; // Error diff --git a/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.errors.txt b/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.errors.txt deleted file mode 100644 index 26e37d4b327..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndClassInGlobal.ts(1,7): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndClassInGlobal.ts (1 errors) ==== - class _this { - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - } - var f = () => this; \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.js b/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.js index f3158047a54..2b1ffbe1182 100644 --- a/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.js +++ b/tests/baselines/reference/collisionThisExpressionAndClassInGlobal.js @@ -4,10 +4,10 @@ class _this { var f = () => this; //// [collisionThisExpressionAndClassInGlobal.js] -var _this = this; +var _this_1 = this; var _this = /** @class */ (function () { function _this() { } return _this; }()); -var f = function () { return _this; }; +var f = function () { return _this_1; }; diff --git a/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.errors.txt b/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.errors.txt deleted file mode 100644 index e6c7b70216c..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.errors.txt +++ /dev/null @@ -1,11 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndEnumInGlobal.ts(1,6): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndEnumInGlobal.ts (1 errors) ==== - enum _this { // Error - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - _thisVal1, - _thisVal2, - } - var f = () => this; \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.js b/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.js index 4ab929a3877..c2dc1db265b 100644 --- a/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.js +++ b/tests/baselines/reference/collisionThisExpressionAndEnumInGlobal.js @@ -6,10 +6,10 @@ enum _this { // Error var f = () => this; //// [collisionThisExpressionAndEnumInGlobal.js] -var _this = this; +var _this_1 = this; var _this; (function (_this) { _this[_this["_thisVal1"] = 0] = "_thisVal1"; _this[_this["_thisVal2"] = 1] = "_thisVal2"; })(_this || (_this = {})); -var f = function () { return _this; }; +var f = function () { return _this_1; }; diff --git a/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.errors.txt b/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.errors.txt deleted file mode 100644 index 30fa4a444e2..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndFunctionInGlobal.ts(1,10): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndFunctionInGlobal.ts (1 errors) ==== - function _this() { //Error - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - return 10; - } - var f = () => this; \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.js b/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.js index 3c6232ba0ba..eabf46e9ae6 100644 --- a/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.js +++ b/tests/baselines/reference/collisionThisExpressionAndFunctionInGlobal.js @@ -5,8 +5,8 @@ function _this() { //Error var f = () => this; //// [collisionThisExpressionAndFunctionInGlobal.js] -var _this = this; +var _this_1 = this; function _this() { return 10; } -var f = function () { return _this; }; +var f = function () { return _this_1; }; diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInAccessors.errors.txt b/tests/baselines/reference/collisionThisExpressionAndLocalVarInAccessors.errors.txt deleted file mode 100644 index cbe371c5934..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInAccessors.errors.txt +++ /dev/null @@ -1,70 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndLocalVarInAccessors.ts(2,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionThisExpressionAndLocalVarInAccessors.ts(5,21): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndLocalVarInAccessors.ts(12,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionThisExpressionAndLocalVarInAccessors.ts(15,21): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndLocalVarInAccessors.ts(24,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionThisExpressionAndLocalVarInAccessors.ts(25,13): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndLocalVarInAccessors.ts(34,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/compiler/collisionThisExpressionAndLocalVarInAccessors.ts(35,13): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndLocalVarInAccessors.ts (8 errors) ==== - class class1 { - get a(): number { - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var x2 = { - doStuff: (callback) => () => { - var _this = 2; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - return callback(this); - } - } - - return 10; - } - set a(val: number) { - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var x2 = { - doStuff: (callback) => () => { - var _this = 2; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - return callback(this); - } - } - - } - } - - class class2 { - get a(): number { - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var _this = 2; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - var x2 = { - doStuff: (callback) => () => { - return callback(this); - } - } - - return 10; - } - set a(val: number) { - ~ -!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. - var _this = 2; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - var x2 = { - doStuff: (callback) => () => { - return callback(this); - } - } - - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInAccessors.js b/tests/baselines/reference/collisionThisExpressionAndLocalVarInAccessors.js index 4a7875bfe40..ffa350a04ef 100644 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInAccessors.js +++ b/tests/baselines/reference/collisionThisExpressionAndLocalVarInAccessors.js @@ -49,21 +49,21 @@ var class1 = /** @class */ (function () { } Object.defineProperty(class1.prototype, "a", { get: function () { - var _this = this; + var _this_1 = this; var x2 = { doStuff: function (callback) { return function () { var _this = 2; - return callback(_this); + return callback(_this_1); }; } }; return 10; }, set: function (val) { - var _this = this; + var _this_1 = this; var x2 = { doStuff: function (callback) { return function () { var _this = 2; - return callback(_this); + return callback(_this_1); }; } }; }, @@ -77,21 +77,21 @@ var class2 = /** @class */ (function () { } Object.defineProperty(class2.prototype, "a", { get: function () { - var _this = this; + var _this_1 = this; var _this = 2; var x2 = { doStuff: function (callback) { return function () { - return callback(_this); + return callback(_this_1); }; } }; return 10; }, set: function (val) { - var _this = this; + var _this_1 = this; var _this = 2; var x2 = { doStuff: function (callback) { return function () { - return callback(_this); + return callback(_this_1); }; } }; }, diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInConstructor.errors.txt b/tests/baselines/reference/collisionThisExpressionAndLocalVarInConstructor.errors.txt deleted file mode 100644 index af1b43786a4..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInConstructor.errors.txt +++ /dev/null @@ -1,30 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndLocalVarInConstructor.ts(5,21): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndLocalVarInConstructor.ts(14,13): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndLocalVarInConstructor.ts (2 errors) ==== - class class1 { - constructor() { - var x2 = { - doStuff: (callback) => () => { - var _this = 2; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - return callback(this); - } - } - } - } - - class class2 { - constructor() { - var _this = 2; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - var x2 = { - doStuff: (callback) => () => { - return callback(this); - } - } - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInConstructor.js b/tests/baselines/reference/collisionThisExpressionAndLocalVarInConstructor.js index ab60d6244a1..e5e2a92d9d1 100644 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInConstructor.js +++ b/tests/baselines/reference/collisionThisExpressionAndLocalVarInConstructor.js @@ -24,11 +24,11 @@ class class2 { //// [collisionThisExpressionAndLocalVarInConstructor.js] var class1 = /** @class */ (function () { function class1() { - var _this = this; + var _this_1 = this; var x2 = { doStuff: function (callback) { return function () { var _this = 2; - return callback(_this); + return callback(_this_1); }; } }; } @@ -36,11 +36,11 @@ var class1 = /** @class */ (function () { }()); var class2 = /** @class */ (function () { function class2() { - var _this = this; + var _this_1 = this; var _this = 2; var x2 = { doStuff: function (callback) { return function () { - return callback(_this); + return callback(_this_1); }; } }; } diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInFunction.errors.txt b/tests/baselines/reference/collisionThisExpressionAndLocalVarInFunction.errors.txt deleted file mode 100644 index 3dd4f6e31a3..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInFunction.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndLocalVarInFunction.ts(5,9): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndLocalVarInFunction.ts (1 errors) ==== - var console: { - log(val: any); - } - function x() { - var _this = 5; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - x => { console.log(this.x); }; - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInFunction.js b/tests/baselines/reference/collisionThisExpressionAndLocalVarInFunction.js index 879dd83d778..27de7125b8e 100644 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInFunction.js +++ b/tests/baselines/reference/collisionThisExpressionAndLocalVarInFunction.js @@ -10,7 +10,7 @@ function x() { //// [collisionThisExpressionAndLocalVarInFunction.js] var console; function x() { - var _this = this; + var _this_1 = this; var _this = 5; - (function (x) { console.log(_this.x); }); + (function (x) { console.log(_this_1.x); }); } diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.errors.txt b/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.errors.txt deleted file mode 100644 index 3b6e8cb4cca..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.errors.txt +++ /dev/null @@ -1,15 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndLocalVarInLambda.ts(5,13): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndLocalVarInLambda.ts (1 errors) ==== - declare function alert(message?: any): void; - - var x = { - doStuff: (callback) => () => { - var _this = 2; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - return callback(this); - } - } - alert(x.doStuff(x => alert(x))); \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.js b/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.js index e8b7a0db7f3..be2785ddfba 100644 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.js +++ b/tests/baselines/reference/collisionThisExpressionAndLocalVarInLambda.js @@ -10,11 +10,11 @@ var x = { alert(x.doStuff(x => alert(x))); //// [collisionThisExpressionAndLocalVarInLambda.js] -var _this = this; +var _this_1 = this; var x = { doStuff: function (callback) { return function () { var _this = 2; - return callback(_this); + return callback(_this_1); }; } }; alert(x.doStuff(function (x) { return alert(x); })); diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInMethod.errors.txt b/tests/baselines/reference/collisionThisExpressionAndLocalVarInMethod.errors.txt deleted file mode 100644 index 018f3bb49d2..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInMethod.errors.txt +++ /dev/null @@ -1,27 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndLocalVarInMethod.ts(5,21): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndLocalVarInMethod.ts(11,13): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndLocalVarInMethod.ts (2 errors) ==== - class a { - method1() { - return { - doStuff: (callback) => () => { - var _this = 2; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - return callback(this); - } - } - } - method2() { - var _this = 2; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - return { - doStuff: (callback) => () => { - return callback(this); - } - } - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInMethod.js b/tests/baselines/reference/collisionThisExpressionAndLocalVarInMethod.js index 2d5de593909..16f288174a5 100644 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInMethod.js +++ b/tests/baselines/reference/collisionThisExpressionAndLocalVarInMethod.js @@ -23,20 +23,20 @@ var a = /** @class */ (function () { function a() { } a.prototype.method1 = function () { - var _this = this; + var _this_1 = this; return { doStuff: function (callback) { return function () { var _this = 2; - return callback(_this); + return callback(_this_1); }; } }; }; a.prototype.method2 = function () { - var _this = this; + var _this_1 = this; var _this = 2; return { doStuff: function (callback) { return function () { - return callback(_this); + return callback(_this_1); }; } }; }; diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInProperty.errors.txt b/tests/baselines/reference/collisionThisExpressionAndLocalVarInProperty.errors.txt deleted file mode 100644 index 4c166ac13ac..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInProperty.errors.txt +++ /dev/null @@ -1,28 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndLocalVarInProperty.ts(4,17): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndLocalVarInProperty.ts(12,13): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndLocalVarInProperty.ts (2 errors) ==== - class class1 { - public prop1 = { - doStuff: (callback) => () => { - var _this = 2; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - return callback(this); - } - } - } - - class class2 { - constructor() { - var _this = 2; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - } - public prop1 = { - doStuff: (callback) => () => { - return callback(this); - } - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarInProperty.js b/tests/baselines/reference/collisionThisExpressionAndLocalVarInProperty.js index 4ce4f08a778..70760396df6 100644 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarInProperty.js +++ b/tests/baselines/reference/collisionThisExpressionAndLocalVarInProperty.js @@ -22,11 +22,11 @@ class class2 { //// [collisionThisExpressionAndLocalVarInProperty.js] var class1 = /** @class */ (function () { function class1() { - var _this = this; + var _this_1 = this; this.prop1 = { doStuff: function (callback) { return function () { var _this = 2; - return callback(_this); + return callback(_this_1); }; } }; } @@ -34,10 +34,10 @@ var class1 = /** @class */ (function () { }()); var class2 = /** @class */ (function () { function class2() { - var _this = this; + var _this_1 = this; this.prop1 = { doStuff: function (callback) { return function () { - return callback(_this); + return callback(_this_1); }; } }; var _this = 2; diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarWithSuperExperssion.errors.txt b/tests/baselines/reference/collisionThisExpressionAndLocalVarWithSuperExperssion.errors.txt deleted file mode 100644 index df308b894f1..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarWithSuperExperssion.errors.txt +++ /dev/null @@ -1,27 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndLocalVarWithSuperExperssion.ts(7,13): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndLocalVarWithSuperExperssion.ts(14,17): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndLocalVarWithSuperExperssion.ts (2 errors) ==== - class a { - public foo() { - } - } - class b extends a { - public foo() { - var _this = 10; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - var f = () => super.foo(); - } - } - class b2 extends a { - public foo() { - var f = () => { - var _this = 10; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - return super.foo() - } - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndLocalVarWithSuperExperssion.js b/tests/baselines/reference/collisionThisExpressionAndLocalVarWithSuperExperssion.js index a1bc5d36965..6e99ba3ba0c 100644 --- a/tests/baselines/reference/collisionThisExpressionAndLocalVarWithSuperExperssion.js +++ b/tests/baselines/reference/collisionThisExpressionAndLocalVarWithSuperExperssion.js @@ -42,9 +42,9 @@ var b = /** @class */ (function (_super) { return _super !== null && _super.apply(this, arguments) || this; } b.prototype.foo = function () { - var _this = this; + var _this_1 = this; var _this = 10; - var f = function () { return _super.prototype.foo.call(_this); }; + var f = function () { return _super.prototype.foo.call(_this_1); }; }; return b; }(a)); @@ -54,10 +54,10 @@ var b2 = /** @class */ (function (_super) { return _super !== null && _super.apply(this, arguments) || this; } b2.prototype.foo = function () { - var _this = this; + var _this_1 = this; var f = function () { var _this = 10; - return _super.prototype.foo.call(_this); + return _super.prototype.foo.call(_this_1); }; }; return b2; diff --git a/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.errors.txt b/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.errors.txt deleted file mode 100644 index bcc719972dc..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.errors.txt +++ /dev/null @@ -1,11 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndModuleInGlobal.ts(1,8): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndModuleInGlobal.ts (1 errors) ==== - module _this { //Error - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - class c { - } - } - var f = () => this; \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.js b/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.js index 36dca587068..14627f19959 100644 --- a/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.js +++ b/tests/baselines/reference/collisionThisExpressionAndModuleInGlobal.js @@ -6,7 +6,7 @@ module _this { //Error var f = () => this; //// [collisionThisExpressionAndModuleInGlobal.js] -var _this = this; +var _this_1 = this; var _this; (function (_this) { var c = /** @class */ (function () { @@ -15,4 +15,4 @@ var _this; return c; }()); })(_this || (_this = {})); -var f = function () { return _this; }; +var f = function () { return _this_1; }; diff --git a/tests/baselines/reference/collisionThisExpressionAndNameResolution.errors.txt b/tests/baselines/reference/collisionThisExpressionAndNameResolution.errors.txt deleted file mode 100644 index 76875f46e46..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndNameResolution.errors.txt +++ /dev/null @@ -1,18 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndNameResolution.ts(8,25): error TS2400: Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndNameResolution.ts (1 errors) ==== - var console : { - log(message: any); - } - class Foo { - x() { - var _this = 10; // Local var. No this capture in x(), so no conflict. - function inner() { - console.log(_this); // Error as this doesnt not resolve to user defined _this - ~~~~~ -!!! error TS2400: Expression resolves to variable declaration '_this' that compiler uses to capture 'this' reference. - return x => this; // New scope. So should inject new _this capture into function inner - } - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndNameResolution.js b/tests/baselines/reference/collisionThisExpressionAndNameResolution.js index 2e981ad33d9..380449edc21 100644 --- a/tests/baselines/reference/collisionThisExpressionAndNameResolution.js +++ b/tests/baselines/reference/collisionThisExpressionAndNameResolution.js @@ -20,9 +20,9 @@ var Foo = /** @class */ (function () { Foo.prototype.x = function () { var _this = 10; // Local var. No this capture in x(), so no conflict. function inner() { - var _this = this; + var _this_1 = this; console.log(_this); // Error as this doesnt not resolve to user defined _this - return function (x) { return _this; }; // New scope. So should inject new _this capture into function inner + return function (x) { return _this_1; }; // New scope. So should inject new _this capture into function inner } }; return Foo; diff --git a/tests/baselines/reference/collisionThisExpressionAndParameter.errors.txt b/tests/baselines/reference/collisionThisExpressionAndParameter.errors.txt deleted file mode 100644 index d2bf00483e4..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndParameter.errors.txt +++ /dev/null @@ -1,120 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndParameter.ts(4,24): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndParameter.ts(9,22): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndParameter.ts(13,7): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndParameter.ts(34,17): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndParameter.ts(46,13): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndParameter.ts(59,17): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndParameter.ts(69,7): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndParameter.ts(81,13): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndParameter.ts (8 errors) ==== - class Foo { - x() { - var _this = 10; // Local var. No this capture in x(), so no conflict. - function inner(_this: number) { // Error - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - return x => this; // New scope. So should inject new _this capture into function inner - } - } - y() { - var lamda = (_this: number) => { // Error - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - return x => this; // New scope. So should inject new _this capture - } - } - z(_this: number) { // Error - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - var lambda = () => { - return x => this; // New scope. So should inject new _this capture - } - } - - x1() { - var _this = 10; // Local var. No this capture in x(), so no conflict. - function inner(_this: number) { // No Error - } - } - y1() { - var lamda = (_this: number) => { // No Error - } - } - z1(_this: number) { // No Error - var lambda = () => { - } - } - } - class Foo1 { - constructor(_this: number) { // Error - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - var x2 = { - doStuff: (callback) => () => { - return callback(this); - } - } - } - } - declare var console: { - log(msg: any); - } - - function f1(_this: number) { - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - x => { console.log(this.x); }; - } - - declare class Foo2 { - constructor(_this: number); // no error - no code gen - z(_this: number); // no error - no code gen - } - declare function f2(_this: number); // no error - - class Foo3 { - constructor(_this: string); // no code gen - no error - constructor(_this: number); // no code gen - no error - constructor(_this: any) { // Error - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - var x2 = { - doStuff: (callback) => () => { - return callback(this); - } - } - } - - z(_this: string); // no code gen - no error - z(_this: number); // no code gen - no error - z(_this: any) { // Error - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - var lambda = () => { - return x => this; // New scope. So should inject new _this capture - } - } - } - declare var console: { - log(msg: any); - } - - function f3(_this: number); // no code gen - no error - function f3(_this: string); // no code gen - no error - function f3(_this: any) { - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - x => { console.log(this.x); }; - } - - declare class Foo4 { - constructor(_this: string); // no code gen - no error - constructor(_this: number); // no code gen - no error - z(_this: string); // no code gen - no error - z(_this: number); // no code gen - no error - } - - declare function f4(_this: number); // no code gen - no error - declare function f4(_this: string); // no code gen - no error \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndParameter.js b/tests/baselines/reference/collisionThisExpressionAndParameter.js index acaceb9170b..b6367480e02 100644 --- a/tests/baselines/reference/collisionThisExpressionAndParameter.js +++ b/tests/baselines/reference/collisionThisExpressionAndParameter.js @@ -100,20 +100,20 @@ var Foo = /** @class */ (function () { Foo.prototype.x = function () { var _this = 10; // Local var. No this capture in x(), so no conflict. function inner(_this) { - var _this = this; - return function (x) { return _this; }; // New scope. So should inject new _this capture into function inner + var _this_1 = this; + return function (x) { return _this_1; }; // New scope. So should inject new _this capture into function inner } }; Foo.prototype.y = function () { - var _this = this; + var _this_1 = this; var lamda = function (_this) { - return function (x) { return _this; }; // New scope. So should inject new _this capture + return function (x) { return _this_1; }; // New scope. So should inject new _this capture }; }; Foo.prototype.z = function (_this) { - var _this = this; + var _this_1 = this; var lambda = function () { - return function (x) { return _this; }; // New scope. So should inject new _this capture + return function (x) { return _this_1; }; // New scope. So should inject new _this capture }; }; Foo.prototype.x1 = function () { @@ -133,37 +133,37 @@ var Foo = /** @class */ (function () { }()); var Foo1 = /** @class */ (function () { function Foo1(_this) { - var _this = this; + var _this_1 = this; var x2 = { doStuff: function (callback) { return function () { - return callback(_this); + return callback(_this_1); }; } }; } return Foo1; }()); function f1(_this) { - var _this = this; - (function (x) { console.log(_this.x); }); + var _this_1 = this; + (function (x) { console.log(_this_1.x); }); } var Foo3 = /** @class */ (function () { function Foo3(_this) { - var _this = this; + var _this_1 = this; var x2 = { doStuff: function (callback) { return function () { - return callback(_this); + return callback(_this_1); }; } }; } Foo3.prototype.z = function (_this) { - var _this = this; + var _this_1 = this; var lambda = function () { - return function (x) { return _this; }; // New scope. So should inject new _this capture + return function (x) { return _this_1; }; // New scope. So should inject new _this capture }; }; return Foo3; }()); function f3(_this) { - var _this = this; - (function (x) { console.log(_this.x); }); + var _this_1 = this; + (function (x) { console.log(_this_1.x); }); } diff --git a/tests/baselines/reference/collisionThisExpressionAndPropertyNameAsConstuctorParameter.errors.txt b/tests/baselines/reference/collisionThisExpressionAndPropertyNameAsConstuctorParameter.errors.txt deleted file mode 100644 index fda0ebc930d..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndPropertyNameAsConstuctorParameter.errors.txt +++ /dev/null @@ -1,50 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndPropertyNameAsConstuctorParameter.ts(2,17): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndPropertyNameAsConstuctorParameter.ts(10,25): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndPropertyNameAsConstuctorParameter.ts(20,17): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. -tests/cases/compiler/collisionThisExpressionAndPropertyNameAsConstuctorParameter.ts(30,25): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndPropertyNameAsConstuctorParameter.ts (4 errors) ==== - class Foo2 { - constructor(_this: number) { //Error - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - var lambda = () => { - return x => this; // New scope. So should inject new _this capture - } - } - } - - class Foo3 { - constructor(private _this: number) { // Error - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - var lambda = () => { - return x => this; // New scope. So should inject new _this capture - } - } - } - - class Foo4 { - constructor(_this: number); // No code gen - no error - constructor(_this: string); // No code gen - no error - constructor(_this: any) { // Error - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - var lambda = () => { - return x => this; // New scope. So should inject new _this capture - } - } - } - - class Foo5 { - constructor(_this: number); // No code gen - no error - constructor(_this: string); // No code gen - no error - constructor(private _this: any) { // Error - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - var lambda = () => { - return x => this; // New scope. So should inject new _this capture - } - } - } \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndPropertyNameAsConstuctorParameter.js b/tests/baselines/reference/collisionThisExpressionAndPropertyNameAsConstuctorParameter.js index 3758cfdecda..360b147ad24 100644 --- a/tests/baselines/reference/collisionThisExpressionAndPropertyNameAsConstuctorParameter.js +++ b/tests/baselines/reference/collisionThisExpressionAndPropertyNameAsConstuctorParameter.js @@ -38,38 +38,38 @@ class Foo5 { //// [collisionThisExpressionAndPropertyNameAsConstuctorParameter.js] var Foo2 = /** @class */ (function () { function Foo2(_this) { - var _this = this; + var _this_1 = this; var lambda = function () { - return function (x) { return _this; }; // New scope. So should inject new _this capture + return function (x) { return _this_1; }; // New scope. So should inject new _this capture }; } return Foo2; }()); var Foo3 = /** @class */ (function () { function Foo3(_this) { - var _this = this; + var _this_1 = this; this._this = _this; var lambda = function () { - return function (x) { return _this; }; // New scope. So should inject new _this capture + return function (x) { return _this_1; }; // New scope. So should inject new _this capture }; } return Foo3; }()); var Foo4 = /** @class */ (function () { function Foo4(_this) { - var _this = this; + var _this_1 = this; var lambda = function () { - return function (x) { return _this; }; // New scope. So should inject new _this capture + return function (x) { return _this_1; }; // New scope. So should inject new _this capture }; } return Foo4; }()); var Foo5 = /** @class */ (function () { function Foo5(_this) { - var _this = this; + var _this_1 = this; this._this = _this; var lambda = function () { - return function (x) { return _this; }; // New scope. So should inject new _this capture + return function (x) { return _this_1; }; // New scope. So should inject new _this capture }; } return Foo5; diff --git a/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.errors.txt b/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.errors.txt deleted file mode 100644 index 31e37f9c255..00000000000 --- a/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.errors.txt +++ /dev/null @@ -1,8 +0,0 @@ -tests/cases/compiler/collisionThisExpressionAndVarInGlobal.ts(1,5): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/collisionThisExpressionAndVarInGlobal.ts (1 errors) ==== - var _this = 1; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - var f = () => this; \ No newline at end of file diff --git a/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.js b/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.js index 7057ad7ac55..954b9c47d24 100644 --- a/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.js +++ b/tests/baselines/reference/collisionThisExpressionAndVarInGlobal.js @@ -3,6 +3,6 @@ var _this = 1; var f = () => this; //// [collisionThisExpressionAndVarInGlobal.js] -var _this = this; +var _this_1 = this; var _this = 1; -var f = function () { return _this; }; +var f = function () { return _this_1; }; diff --git a/tests/baselines/reference/moduleNoneOutFile.js b/tests/baselines/reference/moduleNoneOutFile.js new file mode 100644 index 00000000000..865e9fbae91 --- /dev/null +++ b/tests/baselines/reference/moduleNoneOutFile.js @@ -0,0 +1,30 @@ +//// [tests/cases/compiler/moduleNoneOutFile.ts] //// + +//// [first.ts] +class Foo {} +//// [second.ts] +class Bar extends Foo {} + +//// [bundle.js] +var Foo = /** @class */ (function () { + function Foo() { + } + return Foo; +}()); +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +var Bar = /** @class */ (function (_super) { + __extends(Bar, _super); + function Bar() { + return _super !== null && _super.apply(this, arguments) || this; + } + return Bar; +}(Foo)); diff --git a/tests/baselines/reference/moduleNoneOutFile.symbols b/tests/baselines/reference/moduleNoneOutFile.symbols new file mode 100644 index 00000000000..e6b770085da --- /dev/null +++ b/tests/baselines/reference/moduleNoneOutFile.symbols @@ -0,0 +1,9 @@ +=== tests/cases/compiler/first.ts === +class Foo {} +>Foo : Symbol(Foo, Decl(first.ts, 0, 0)) + +=== tests/cases/compiler/second.ts === +class Bar extends Foo {} +>Bar : Symbol(Bar, Decl(second.ts, 0, 0)) +>Foo : Symbol(Foo, Decl(first.ts, 0, 0)) + diff --git a/tests/baselines/reference/moduleNoneOutFile.types b/tests/baselines/reference/moduleNoneOutFile.types new file mode 100644 index 00000000000..0748898110c --- /dev/null +++ b/tests/baselines/reference/moduleNoneOutFile.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/first.ts === +class Foo {} +>Foo : Foo + +=== tests/cases/compiler/second.ts === +class Bar extends Foo {} +>Bar : Bar +>Foo : Foo + diff --git a/tests/baselines/reference/noCollisionThisExpressionInFunctionAndVarInGlobal.js b/tests/baselines/reference/noCollisionThisExpressionInFunctionAndVarInGlobal.js index b3677681822..a1e76c48212 100644 --- a/tests/baselines/reference/noCollisionThisExpressionInFunctionAndVarInGlobal.js +++ b/tests/baselines/reference/noCollisionThisExpressionInFunctionAndVarInGlobal.js @@ -11,6 +11,6 @@ function x() { var console; var _this = 5; function x() { - var _this = this; - (function (x) { console.log(_this); }); + var _this_1 = this; + (function (x) { console.log(_this_1); }); } diff --git a/tests/baselines/reference/underscoreThisInDerivedClass01.errors.txt b/tests/baselines/reference/underscoreThisInDerivedClass01.errors.txt deleted file mode 100644 index 3828825cb6b..00000000000 --- a/tests/baselines/reference/underscoreThisInDerivedClass01.errors.txt +++ /dev/null @@ -1,29 +0,0 @@ -tests/cases/compiler/underscoreThisInDerivedClass01.ts(20,13): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/underscoreThisInDerivedClass01.ts (1 errors) ==== - // @target es5 - - // Original test intent: - // When arrow functions capture 'this', the lexical 'this' owner - // currently captures 'this' using a variable named '_this'. - // That means that '_this' becomes a reserved identifier in certain places. - // - // Constructors have adopted the same identifier name ('_this') - // for capturing any potential return values from super calls, - // so we expect the same behavior. - - class C { - constructor() { - return {}; - } - } - - class D extends C { - constructor() { - var _this = "uh-oh?"; - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - super(); - } - } \ No newline at end of file diff --git a/tests/baselines/reference/underscoreThisInDerivedClass01.js b/tests/baselines/reference/underscoreThisInDerivedClass01.js index 4663b4f75ec..f544fa7cb7d 100644 --- a/tests/baselines/reference/underscoreThisInDerivedClass01.js +++ b/tests/baselines/reference/underscoreThisInDerivedClass01.js @@ -52,10 +52,10 @@ var C = /** @class */ (function () { var D = /** @class */ (function (_super) { __extends(D, _super); function D() { - var _this = this; + var _this_1 = this; var _this = "uh-oh?"; - _this = _super.call(this) || this; - return _this; + _this_1 = _super.call(this) || this; + return _this_1; } return D; }(C)); diff --git a/tests/baselines/reference/underscoreThisInDerivedClass02.errors.txt b/tests/baselines/reference/underscoreThisInDerivedClass02.errors.txt deleted file mode 100644 index 5569ebf1af6..00000000000 --- a/tests/baselines/reference/underscoreThisInDerivedClass02.errors.txt +++ /dev/null @@ -1,28 +0,0 @@ -tests/cases/compiler/underscoreThisInDerivedClass02.ts(14,5): error TS2377: Constructors for derived classes must contain a 'super' call. -tests/cases/compiler/underscoreThisInDerivedClass02.ts(15,13): error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - - -==== tests/cases/compiler/underscoreThisInDerivedClass02.ts (2 errors) ==== - // @target es5 - - // Original test intent: - // Errors on '_this' should be reported in derived constructors, - // even if 'super()' is not called. - - class C { - constructor() { - return {}; - } - } - - class D extends C { - constructor() { - ~~~~~~~~~~~~~~~ - var _this = "uh-oh?"; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ~~~~~ -!!! error TS2399: Duplicate identifier '_this'. Compiler uses variable declaration '_this' to capture 'this' reference. - } - ~~~~~ -!!! error TS2377: Constructors for derived classes must contain a 'super' call. - } \ No newline at end of file diff --git a/tests/baselines/reference/underscoreThisInDerivedClass02.js b/tests/baselines/reference/underscoreThisInDerivedClass02.js index d88f8eba101..4b0ef6e1e73 100644 --- a/tests/baselines/reference/underscoreThisInDerivedClass02.js +++ b/tests/baselines/reference/underscoreThisInDerivedClass02.js @@ -13,6 +13,7 @@ class C { class D extends C { constructor() { + super(); var _this = "uh-oh?"; } } @@ -41,9 +42,9 @@ var C = /** @class */ (function () { var D = /** @class */ (function (_super) { __extends(D, _super); function D() { - var _this = this; + var _this_1 = _super.call(this) || this; var _this = "uh-oh?"; - return _this; + return _this_1; } return D; }(C)); diff --git a/tests/baselines/reference/underscoreThisInDerivedClass02.symbols b/tests/baselines/reference/underscoreThisInDerivedClass02.symbols index dd2a2df81b7..5ccf39a1375 100644 --- a/tests/baselines/reference/underscoreThisInDerivedClass02.symbols +++ b/tests/baselines/reference/underscoreThisInDerivedClass02.symbols @@ -18,7 +18,10 @@ class D extends C { >C : Symbol(C, Decl(underscoreThisInDerivedClass02.ts, 0, 0)) constructor() { + super(); +>super : Symbol(C, Decl(underscoreThisInDerivedClass02.ts, 0, 0)) + var _this = "uh-oh?"; ->_this : Symbol(_this, Decl(underscoreThisInDerivedClass02.ts, 14, 11)) +>_this : Symbol(_this, Decl(underscoreThisInDerivedClass02.ts, 15, 11)) } } diff --git a/tests/baselines/reference/underscoreThisInDerivedClass02.types b/tests/baselines/reference/underscoreThisInDerivedClass02.types index 3b12cdc0b05..0c206e0887c 100644 --- a/tests/baselines/reference/underscoreThisInDerivedClass02.types +++ b/tests/baselines/reference/underscoreThisInDerivedClass02.types @@ -19,6 +19,10 @@ class D extends C { >C : C constructor() { + super(); +>super() : void +>super : typeof C + var _this = "uh-oh?"; >_this : string >"uh-oh?" : "uh-oh?" diff --git a/tests/cases/compiler/collisionSuperAndLocalFunctionInAccessors.ts b/tests/cases/compiler/collisionSuperAndLocalFunctionInAccessors.ts index aa635990b94..14252622a4a 100644 --- a/tests/cases/compiler/collisionSuperAndLocalFunctionInAccessors.ts +++ b/tests/cases/compiler/collisionSuperAndLocalFunctionInAccessors.ts @@ -1,3 +1,4 @@ +// @target: es5 function _super() { // No error } class Foo { diff --git a/tests/cases/compiler/collisionSuperAndLocalVarInAccessors.ts b/tests/cases/compiler/collisionSuperAndLocalVarInAccessors.ts index e8a1e1e417b..0f45a469abd 100644 --- a/tests/cases/compiler/collisionSuperAndLocalVarInAccessors.ts +++ b/tests/cases/compiler/collisionSuperAndLocalVarInAccessors.ts @@ -1,3 +1,4 @@ +// @target: es5 var _super = 10; // No Error class Foo { get prop1(): number { diff --git a/tests/cases/compiler/collisionSuperAndParameter.ts b/tests/cases/compiler/collisionSuperAndParameter.ts index 4e3c0c5832d..88c0235a5b5 100644 --- a/tests/cases/compiler/collisionSuperAndParameter.ts +++ b/tests/cases/compiler/collisionSuperAndParameter.ts @@ -1,3 +1,4 @@ +// @target: es5 class Foo { a() { var lamda = (_super: number) => { // No Error diff --git a/tests/cases/compiler/collisionThisExpressionAndLocalVarInAccessors.ts b/tests/cases/compiler/collisionThisExpressionAndLocalVarInAccessors.ts index 23df5b01b94..d3546733e10 100644 --- a/tests/cases/compiler/collisionThisExpressionAndLocalVarInAccessors.ts +++ b/tests/cases/compiler/collisionThisExpressionAndLocalVarInAccessors.ts @@ -1,3 +1,4 @@ +// @target: es5 class class1 { get a(): number { var x2 = { diff --git a/tests/cases/compiler/moduleNoneOutFile.ts b/tests/cases/compiler/moduleNoneOutFile.ts new file mode 100644 index 00000000000..f3213619fcf --- /dev/null +++ b/tests/cases/compiler/moduleNoneOutFile.ts @@ -0,0 +1,6 @@ +// @module: none +// @outFile: bundle.js +// @filename: first.ts +class Foo {} +// @filename: second.ts +class Bar extends Foo {} \ No newline at end of file diff --git a/tests/cases/compiler/underscoreThisInDerivedClass02.ts b/tests/cases/compiler/underscoreThisInDerivedClass02.ts index da197258a73..66fe1389392 100644 --- a/tests/cases/compiler/underscoreThisInDerivedClass02.ts +++ b/tests/cases/compiler/underscoreThisInDerivedClass02.ts @@ -12,6 +12,7 @@ class C { class D extends C { constructor() { + super(); var _this = "uh-oh?"; } } \ No newline at end of file diff --git a/tests/cases/conformance/async/es2017/asyncMethodWithSuperConflict_es6.ts b/tests/cases/conformance/async/es2017/asyncMethodWithSuperConflict_es6.ts new file mode 100644 index 00000000000..364f0264b23 --- /dev/null +++ b/tests/cases/conformance/async/es2017/asyncMethodWithSuperConflict_es6.ts @@ -0,0 +1,53 @@ +// @target: es6 +class A { + x() { + } +} + +class B extends A { + // async method with only call/get on 'super' does not require a binding + async simple() { + const _super = null; + // call with property access + super.x(); + + // call with element access + super["x"](); + + // property access (read) + const a = super.x; + + // element access (read) + const b = super["x"]; + } + + // async method with assignment/destructuring on 'super' requires a binding + async advanced() { + const _super = null; + const f = () => {}; + + // call with property access + super.x(); + + // call with element access + super["x"](); + + // property access (read) + const a = super.x; + + // element access (read) + const b = super["x"]; + + // property access (assign) + super.x = f; + + // element access (assign) + super["x"] = f; + + // destructuring assign with property access + ({ f: super.x } = { f }); + + // destructuring assign with element access + ({ f: super["x"] } = { f }); + } +} \ No newline at end of file