mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
Remove _this, _super, and _newTarget name conflict errors (#22890)
* Add new generated name kind for reused transpiler variables * Remove error on _super or _newTarget conflict * Add test with super helper conflict * Remove error on _this conflict * Fix lint * Use flags instead of generated kinds, inline some things * Accept rename * Remove trailing whitespace * Move helper emit into printer, rather than emitter" * passthru module and target * New test, accept baselines * Make members private
This commit is contained in:
parent
8543d30372
commit
9b558f9535
@ -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, <Identifier>node.name);
|
||||
checkCollisionWithCapturedThisVariable(node, <Identifier>node.name);
|
||||
checkCollisionWithCapturedNewTargetVariable(node, <Identifier>node.name);
|
||||
checkCollisionWithRequireExportsInGeneratedCode(node, <Identifier>node.name);
|
||||
checkCollisionWithGlobalPromiseInGeneratedCode(node, <Identifier>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);
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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<SourceFile>[]): 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<boolean>;
|
||||
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<boolean>();
|
||||
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 ? <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<boolean>();
|
||||
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 ? <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.");
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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")
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
@ -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);`
|
||||
|
||||
@ -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;
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -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<any>) => void;
|
||||
/*@internal*/ onAfterEmitNodeArray?: (nodes: NodeArray<any>) => 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;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<TKind extends SyntaxKind>(token: TKind): Token<TKind>;
|
||||
|
||||
@ -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<TKind extends SyntaxKind>(token: TKind): Token<TKind>;
|
||||
|
||||
111
tests/baselines/reference/asyncMethodWithSuperConflict_es6.js
Normal file
111
tests/baselines/reference/asyncMethodWithSuperConflict_es6.js
Normal file
@ -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 });
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
131
tests/baselines/reference/asyncMethodWithSuperConflict_es6.types
Normal file
131
tests/baselines/reference/asyncMethodWithSuperConflict_es6.types
Normal file
@ -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<void>
|
||||
|
||||
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<void>
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
@ -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.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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 () {
|
||||
|
||||
@ -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.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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() {
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
@ -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 () {
|
||||
|
||||
@ -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.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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() {
|
||||
|
||||
@ -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.
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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 () {
|
||||
|
||||
@ -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.
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
};
|
||||
|
||||
@ -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.
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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 () {
|
||||
|
||||
@ -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
|
||||
}
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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.
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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) {
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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.
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
@ -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
|
||||
|
||||
@ -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.
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
@ -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; };
|
||||
|
||||
@ -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;
|
||||
@ -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; };
|
||||
|
||||
@ -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;
|
||||
@ -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; };
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}; }
|
||||
};
|
||||
},
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}; }
|
||||
};
|
||||
}
|
||||
|
||||
@ -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); };
|
||||
}
|
||||
@ -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); });
|
||||
}
|
||||
|
||||
@ -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)));
|
||||
@ -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); }));
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}; }
|
||||
};
|
||||
};
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
@ -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; };
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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
|
||||
@ -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); });
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
@ -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; };
|
||||
|
||||
30
tests/baselines/reference/moduleNoneOutFile.js
Normal file
30
tests/baselines/reference/moduleNoneOutFile.js
Normal file
@ -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));
|
||||
9
tests/baselines/reference/moduleNoneOutFile.symbols
Normal file
9
tests/baselines/reference/moduleNoneOutFile.symbols
Normal file
@ -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))
|
||||
|
||||
9
tests/baselines/reference/moduleNoneOutFile.types
Normal file
9
tests/baselines/reference/moduleNoneOutFile.types
Normal file
@ -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
|
||||
|
||||
@ -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); });
|
||||
}
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
|
||||
@ -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.
|
||||
}
|
||||
@ -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));
|
||||
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
@ -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?"
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
// @target: es5
|
||||
function _super() { // No error
|
||||
}
|
||||
class Foo {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
// @target: es5
|
||||
var _super = 10; // No Error
|
||||
class Foo {
|
||||
get prop1(): number {
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
// @target: es5
|
||||
class Foo {
|
||||
a() {
|
||||
var lamda = (_super: number) => { // No Error
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
// @target: es5
|
||||
class class1 {
|
||||
get a(): number {
|
||||
var x2 = {
|
||||
|
||||
6
tests/cases/compiler/moduleNoneOutFile.ts
Normal file
6
tests/cases/compiler/moduleNoneOutFile.ts
Normal file
@ -0,0 +1,6 @@
|
||||
// @module: none
|
||||
// @outFile: bundle.js
|
||||
// @filename: first.ts
|
||||
class Foo {}
|
||||
// @filename: second.ts
|
||||
class Bar extends Foo {}
|
||||
@ -12,6 +12,7 @@ class C {
|
||||
|
||||
class D extends C {
|
||||
constructor() {
|
||||
super();
|
||||
var _this = "uh-oh?";
|
||||
}
|
||||
}
|
||||
@ -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 });
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user