mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into LessAggresiveCompletionList
This commit is contained in:
@@ -43,3 +43,4 @@ scripts/word2md.js
|
||||
scripts/ior.js
|
||||
scripts/*.js.map
|
||||
coverage/
|
||||
internal/
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/// <reference path="..\src\harness\external\node.d.ts" />
|
||||
|
||||
import cp = require('child_process');
|
||||
import fs = require('fs');
|
||||
|
||||
// Slice off 'node bisect-test.js' from the commandline args
|
||||
var args = process.argv.slice(2);
|
||||
|
||||
function tsc(tscArgs: string, onExit: (exitCode: number) => void) {
|
||||
var tsc = cp.exec('node built/local/tsc.js ' + tscArgs,() => void 0);
|
||||
tsc.on('close', tscExitCode => {
|
||||
onExit(tscExitCode);
|
||||
});
|
||||
}
|
||||
|
||||
var jake = cp.exec('jake clean local', () => void 0);
|
||||
jake.on('close', jakeExitCode => {
|
||||
if (jakeExitCode === 0) {
|
||||
// See what we're being asked to do
|
||||
if (args[1] === 'compiles' || args[1] === '!compiles') {
|
||||
tsc(args[0], tscExitCode => {
|
||||
if ((tscExitCode === 0) === (args[1] === 'compiles')) {
|
||||
console.log('Good');
|
||||
process.exit(0); // Good
|
||||
} else {
|
||||
console.log('Bad');
|
||||
process.exit(1); // Bad
|
||||
}
|
||||
});
|
||||
} else if (args[1] === 'emits' || args[1] === '!emits') {
|
||||
tsc(args[0], tscExitCode => {
|
||||
fs.readFile(args[2], 'utf-8', (err, data) => {
|
||||
var doesContains = data.indexOf(args[3]) >= 0;
|
||||
if (doesContains === (args[1] === 'emits')) {
|
||||
console.log('Good');
|
||||
process.exit(0); // Good
|
||||
} else {
|
||||
console.log('Bad');
|
||||
process.exit(1); // Bad
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
console.log('Unknown command line arguments.');
|
||||
console.log('Usage (compile errors): git bisect run scripts\bisect.js "foo.ts --module amd" compiles');
|
||||
console.log('Usage (emit check): git bisect run scripts\bisect.js bar.ts emits bar.js "_this = this"');
|
||||
// Aborts the 'git bisect run' process
|
||||
process.exit(-1);
|
||||
}
|
||||
} else {
|
||||
// Compiler build failed; skip this commit
|
||||
console.log('Skip');
|
||||
process.exit(125); // bisect skip
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
echo off
|
||||
IF NOT EXIST scripts\bisect.cmd GOTO :wrongdir
|
||||
IF "%1" == "" GOTO :usage
|
||||
IF "%1" == "GO" GOTO :run
|
||||
GOTO :copy
|
||||
|
||||
:usage
|
||||
echo Usage: bisect GoodCommit BadCommit test.ts compiles
|
||||
echo Usage: bisect GoodCommit BadCommit test.ts emits test.js "var x = 3"
|
||||
GOTO :eof
|
||||
|
||||
:copy
|
||||
copy scripts\bisect.cmd scripts\bisect-fresh.cmd
|
||||
scripts\bisect-fresh GO %*
|
||||
GOTO :eof
|
||||
|
||||
:run
|
||||
call jake local
|
||||
node built/local/tsc.js scripts/bisect-test.ts --module commonjs
|
||||
git bisect start %2 %3
|
||||
git bisect run node scripts/bisect-test.js %4 %5 %6 %7
|
||||
del scripts\bisect-test.js
|
||||
del scripts\bisect-fresh.cmd
|
||||
GOTO :eof
|
||||
|
||||
:wrongdir
|
||||
@echo Run this file from the repo folder, not the scripts folder
|
||||
GOTO :eof
|
||||
|
||||
:eof
|
||||
+23
-17
@@ -50,12 +50,13 @@ module ts {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns false if any of the following are true:
|
||||
* 1. declaration has no name
|
||||
* 2. declaration has a literal name (not computed)
|
||||
* 3. declaration has a computed property name that is a known symbol
|
||||
* A declaration has a dynamic name if both of the following are true:
|
||||
* 1. The declaration has a computed property name
|
||||
* 2. The computed name is *not* expressed as Symbol.<name>, where name
|
||||
* is a property of the Symbol constructor that denotes a built in
|
||||
* Symbol.
|
||||
*/
|
||||
export function hasComputedNameButNotSymbol(declaration: Declaration): boolean {
|
||||
export function hasDynamicName(declaration: Declaration): boolean {
|
||||
return declaration.name && declaration.name.kind === SyntaxKind.ComputedPropertyName;
|
||||
}
|
||||
|
||||
@@ -96,7 +97,7 @@ module ts {
|
||||
if (node.kind === SyntaxKind.ModuleDeclaration && node.name.kind === SyntaxKind.StringLiteral) {
|
||||
return '"' + (<LiteralExpression>node.name).text + '"';
|
||||
}
|
||||
Debug.assert(!hasComputedNameButNotSymbol(node));
|
||||
Debug.assert(!hasDynamicName(node));
|
||||
return (<Identifier | LiteralExpression>node.name).text;
|
||||
}
|
||||
switch (node.kind) {
|
||||
@@ -118,11 +119,7 @@ module ts {
|
||||
}
|
||||
|
||||
function declareSymbol(symbols: SymbolTable, parent: Symbol, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags): Symbol {
|
||||
// Nodes with computed property names will not get symbols, because the type checker
|
||||
// does not make properties for them.
|
||||
if (hasComputedNameButNotSymbol(node)) {
|
||||
return undefined;
|
||||
}
|
||||
Debug.assert(!hasDynamicName(node));
|
||||
|
||||
var name = getDeclarationName(node);
|
||||
if (name !== undefined) {
|
||||
@@ -395,14 +392,14 @@ module ts {
|
||||
break;
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.PropertySignature:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Property | ((<PropertyDeclaration>node).questionToken ? SymbolFlags.Optional : 0), SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
|
||||
bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.Property | ((<PropertyDeclaration>node).questionToken ? SymbolFlags.Optional : 0), SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
|
||||
bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.EnumMember:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes, /*isBlockScopeContainer*/ false);
|
||||
bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes, /*isBlockScopeContainer*/ false);
|
||||
break;
|
||||
case SyntaxKind.CallSignature:
|
||||
case SyntaxKind.ConstructSignature:
|
||||
@@ -415,7 +412,7 @@ module ts {
|
||||
// as other properties in the object literal. So we use SymbolFlags.PropertyExcludes
|
||||
// so that it will conflict with any other object literal members with the same
|
||||
// name.
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Method | ((<MethodDeclaration>node).questionToken ? SymbolFlags.Optional : 0),
|
||||
bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.Method | ((<MethodDeclaration>node).questionToken ? SymbolFlags.Optional : 0),
|
||||
isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true);
|
||||
break;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
@@ -425,10 +422,10 @@ module ts {
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.Constructor, /*symbolExcludes:*/ 0, /*isBlockScopeContainer:*/ true);
|
||||
break;
|
||||
case SyntaxKind.GetAccessor:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes, /*isBlockScopeContainer*/ true);
|
||||
bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes, /*isBlockScopeContainer*/ true);
|
||||
break;
|
||||
case SyntaxKind.SetAccessor:
|
||||
bindDeclaration(<Declaration>node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes, /*isBlockScopeContainer*/ true);
|
||||
bindPropertyOrMethodOrAccessor(<Declaration>node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes, /*isBlockScopeContainer*/ true);
|
||||
break;
|
||||
|
||||
case SyntaxKind.FunctionType:
|
||||
@@ -510,5 +507,14 @@ module ts {
|
||||
declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
|
||||
}
|
||||
}
|
||||
|
||||
function bindPropertyOrMethodOrAccessor(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags, isBlockScopeContainer: boolean) {
|
||||
if (hasDynamicName(node)) {
|
||||
bindAnonymousDeclaration(node, symbolKind, "__computed", isBlockScopeContainer);
|
||||
}
|
||||
else {
|
||||
bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+362
-205
@@ -66,8 +66,8 @@ module ts {
|
||||
var numberType = createIntrinsicType(TypeFlags.Number, "number");
|
||||
var booleanType = createIntrinsicType(TypeFlags.Boolean, "boolean");
|
||||
var voidType = createIntrinsicType(TypeFlags.Void, "void");
|
||||
var undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.Unwidened, "undefined");
|
||||
var nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.Unwidened, "null");
|
||||
var undefinedType = createIntrinsicType(TypeFlags.Undefined | TypeFlags.ContainsUndefinedOrNull, "undefined");
|
||||
var nullType = createIntrinsicType(TypeFlags.Null | TypeFlags.ContainsUndefinedOrNull, "null");
|
||||
var unknownType = createIntrinsicType(TypeFlags.Any, "unknown");
|
||||
var resolvingType = createIntrinsicType(TypeFlags.Any, "__resolving__");
|
||||
|
||||
@@ -107,6 +107,21 @@ module ts {
|
||||
var diagnostics: Diagnostic[] = [];
|
||||
var diagnosticsModified: boolean = false;
|
||||
|
||||
var primitiveTypeInfo: Map<{ type: Type; flags: TypeFlags }> = {
|
||||
"string": {
|
||||
type: stringType,
|
||||
flags: TypeFlags.StringLike
|
||||
},
|
||||
"number": {
|
||||
type: numberType,
|
||||
flags: TypeFlags.NumberLike
|
||||
},
|
||||
"boolean": {
|
||||
type: booleanType,
|
||||
flags: TypeFlags.Boolean
|
||||
}
|
||||
};
|
||||
|
||||
function addDiagnostic(diagnostic: Diagnostic) {
|
||||
diagnostics.push(diagnostic);
|
||||
diagnosticsModified = true;
|
||||
@@ -337,6 +352,25 @@ module ts {
|
||||
break loop;
|
||||
}
|
||||
break;
|
||||
|
||||
// It is not legal to reference a class's own type parameters from a computed property name that
|
||||
// belongs to the class. For example:
|
||||
//
|
||||
// function foo<T>() { return '' }
|
||||
// class C<T> { // <-- Class's own type parameter T
|
||||
// [foo<T>()]() { } // <-- Reference to T from class's own computed property
|
||||
// }
|
||||
//
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
var grandparent = location.parent.parent;
|
||||
if (grandparent.kind === SyntaxKind.ClassDeclaration || grandparent.kind === SyntaxKind.InterfaceDeclaration) {
|
||||
// A reference to this grandparent's type parameters would be an error
|
||||
if (result = getSymbol(getSymbolOfNode(grandparent).members, name, meaning & SymbolFlags.Type)) {
|
||||
error(errorLocation, Diagnostics.A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type);
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.Constructor:
|
||||
@@ -1660,7 +1694,7 @@ module ts {
|
||||
// Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature,
|
||||
// or otherwise the type of the string index signature.
|
||||
var type = getTypeOfPropertyOfType(parentType, name.text) ||
|
||||
isNumericName(name.text) && getIndexTypeOfType(parentType, IndexKind.Number) ||
|
||||
isNumericLiteralName(name.text) && getIndexTypeOfType(parentType, IndexKind.Number) ||
|
||||
getIndexTypeOfType(parentType, IndexKind.String);
|
||||
if (!type) {
|
||||
error(name, Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), declarationNameToString(name));
|
||||
@@ -1706,7 +1740,7 @@ module ts {
|
||||
if (declaration.kind === SyntaxKind.Parameter) {
|
||||
var func = <FunctionLikeDeclaration>declaration.parent;
|
||||
// For a parameter of a set accessor, use the type of the get accessor if one is present
|
||||
if (func.kind === SyntaxKind.SetAccessor && !hasComputedNameButNotSymbol(func)) {
|
||||
if (func.kind === SyntaxKind.SetAccessor && !hasDynamicName(func)) {
|
||||
var getter = <AccessorDeclaration>getDeclarationOfKind(declaration.parent.symbol, SyntaxKind.GetAccessor);
|
||||
if (getter) {
|
||||
return getReturnTypeOfSignature(getSignatureFromDeclaration(getter));
|
||||
@@ -2622,7 +2656,7 @@ module ts {
|
||||
else {
|
||||
// TypeScript 1.0 spec (April 2014):
|
||||
// If only one accessor includes a type annotation, the other behaves as if it had the same type annotation.
|
||||
if (declaration.kind === SyntaxKind.GetAccessor && !hasComputedNameButNotSymbol(declaration)) {
|
||||
if (declaration.kind === SyntaxKind.GetAccessor && !hasDynamicName(declaration)) {
|
||||
var setter = <AccessorDeclaration>getDeclarationOfKind(declaration.symbol, SyntaxKind.SetAccessor);
|
||||
returnType = getAnnotatedAccessorType(setter);
|
||||
}
|
||||
@@ -2807,15 +2841,22 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function getUnwidenedFlagOfTypes(types: Type[]): TypeFlags {
|
||||
return forEach(types, t => t.flags & TypeFlags.Unwidened) || 0;
|
||||
// This function is used to propagate widening flags when creating new object types references and union types.
|
||||
// It is only necessary to do so if a constituent type might be the undefined type, the null type, or the type
|
||||
// of an object literal (since those types have widening related information we need to track).
|
||||
function getWideningFlagsOfTypes(types: Type[]): TypeFlags {
|
||||
var result: TypeFlags = 0;
|
||||
for (var i = 0; i < types.length; i++) {
|
||||
result |= types[i].flags;
|
||||
}
|
||||
return result & TypeFlags.RequiresWidening;
|
||||
}
|
||||
|
||||
function createTypeReference(target: GenericType, typeArguments: Type[]): TypeReference {
|
||||
var id = getTypeListId(typeArguments);
|
||||
var type = target.instantiations[id];
|
||||
if (!type) {
|
||||
var flags = TypeFlags.Reference | getUnwidenedFlagOfTypes(typeArguments);
|
||||
var flags = TypeFlags.Reference | getWideningFlagsOfTypes(typeArguments);
|
||||
type = target.instantiations[id] = <TypeReference>createObjectType(flags, target.symbol);
|
||||
type.target = target;
|
||||
type.typeArguments = typeArguments;
|
||||
@@ -3076,7 +3117,7 @@ module ts {
|
||||
var id = getTypeListId(sortedTypes);
|
||||
var type = unionTypes[id];
|
||||
if (!type) {
|
||||
type = unionTypes[id] = <UnionType>createObjectType(TypeFlags.Union | getUnwidenedFlagOfTypes(sortedTypes));
|
||||
type = unionTypes[id] = <UnionType>createObjectType(TypeFlags.Union | getWideningFlagsOfTypes(sortedTypes));
|
||||
type.types = sortedTypes;
|
||||
}
|
||||
return type;
|
||||
@@ -3367,9 +3408,9 @@ module ts {
|
||||
|
||||
// TYPE CHECKING
|
||||
|
||||
var subtypeRelation: Map<boolean> = {};
|
||||
var assignableRelation: Map<boolean> = {};
|
||||
var identityRelation: Map<boolean> = {};
|
||||
var subtypeRelation: Map<RelationComparisonResult> = {};
|
||||
var assignableRelation: Map<RelationComparisonResult> = {};
|
||||
var identityRelation: Map<RelationComparisonResult> = {};
|
||||
|
||||
function isTypeIdenticalTo(source: Type, target: Type): boolean {
|
||||
return checkTypeRelatedTo(source, target, identityRelation, /*errorNode*/ undefined);
|
||||
@@ -3404,7 +3445,7 @@ module ts {
|
||||
function checkTypeRelatedTo(
|
||||
source: Type,
|
||||
target: Type,
|
||||
relation: Map<boolean>,
|
||||
relation: Map<RelationComparisonResult>,
|
||||
errorNode: Node,
|
||||
headMessage?: DiagnosticMessage,
|
||||
containingMessageChain?: DiagnosticMessageChain): boolean {
|
||||
@@ -3412,7 +3453,7 @@ module ts {
|
||||
var errorInfo: DiagnosticMessageChain;
|
||||
var sourceStack: ObjectType[];
|
||||
var targetStack: ObjectType[];
|
||||
var maybeStack: Map<boolean>[];
|
||||
var maybeStack: Map<RelationComparisonResult>[];
|
||||
var expandingFlags: number;
|
||||
var depth = 0;
|
||||
var overflow = false;
|
||||
@@ -3424,6 +3465,14 @@ module ts {
|
||||
error(errorNode, Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target));
|
||||
}
|
||||
else if (errorInfo) {
|
||||
// If we already computed this relation, but in a context where we didn't want to report errors (e.g. overload resolution),
|
||||
// then we'll only have a top-level error (e.g. 'Class X does not implement interface Y') without any details. If this happened,
|
||||
// request a recompuation to get a complete error message. This will be skipped if we've already done this computation in a context
|
||||
// where errors were being reported.
|
||||
if (errorInfo.next === undefined) {
|
||||
errorInfo = undefined;
|
||||
isRelatedTo(source, target, errorNode !== undefined, headMessage, /* elaborateErrors */ true);
|
||||
}
|
||||
if (containingMessageChain) {
|
||||
errorInfo = concatenateDiagnosticMessageChains(containingMessageChain, errorInfo);
|
||||
}
|
||||
@@ -3439,7 +3488,7 @@ module ts {
|
||||
// Ternary.True if they are related with no assumptions,
|
||||
// Ternary.Maybe if they are related with assumptions of other relationships, or
|
||||
// Ternary.False if they are not related.
|
||||
function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage): Ternary {
|
||||
function isRelatedTo(source: Type, target: Type, reportErrors?: boolean, headMessage?: DiagnosticMessage, elaborateErrors = false): Ternary {
|
||||
var result: Ternary;
|
||||
// both types are the same - covers 'they are the same primitive type or both are Any' or the same type parameter cases
|
||||
if (source === target) return Ternary.True;
|
||||
@@ -3506,7 +3555,7 @@ module ts {
|
||||
// identity relation does not use apparent type
|
||||
var sourceOrApparentType = relation === identityRelation ? source : getApparentType(source);
|
||||
if (sourceOrApparentType.flags & TypeFlags.ObjectType && target.flags & TypeFlags.ObjectType &&
|
||||
(result = objectTypeRelatedTo(sourceOrApparentType, <ObjectType>target, reportStructuralErrors))) {
|
||||
(result = objectTypeRelatedTo(sourceOrApparentType, <ObjectType>target, reportStructuralErrors, elaborateErrors))) {
|
||||
errorInfo = saveErrorInfo;
|
||||
return result;
|
||||
}
|
||||
@@ -3597,14 +3646,19 @@ module ts {
|
||||
// Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are
|
||||
// equal and infinitely expanding. Fourth, if we have reached a depth of 100 nested comparisons, assume we have runaway recursion
|
||||
// and issue an error. Otherwise, actually compare the structure of the two types.
|
||||
function objectTypeRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean): Ternary {
|
||||
function objectTypeRelatedTo(source: ObjectType, target: ObjectType, reportErrors: boolean, elaborateErrors = false): Ternary {
|
||||
if (overflow) {
|
||||
return Ternary.False;
|
||||
}
|
||||
var id = relation !== identityRelation || source.id < target.id ? source.id + "," + target.id : target.id + "," + source.id;
|
||||
var related = relation[id];
|
||||
//var related: RelationComparisonResult = undefined; // relation[id];
|
||||
if (related !== undefined) {
|
||||
return related ? Ternary.True : Ternary.False;
|
||||
// If we computed this relation already and it was failed and reported, or if we're not being asked to elaborate
|
||||
// errors, we can use the cached value. Otherwise, recompute the relation
|
||||
if (!elaborateErrors || (related === RelationComparisonResult.FailedAndReported)) {
|
||||
return related === RelationComparisonResult.Succeeded ? Ternary.True : Ternary.False;
|
||||
}
|
||||
}
|
||||
if (depth > 0) {
|
||||
for (var i = 0; i < depth; i++) {
|
||||
@@ -3627,7 +3681,7 @@ module ts {
|
||||
sourceStack[depth] = source;
|
||||
targetStack[depth] = target;
|
||||
maybeStack[depth] = {};
|
||||
maybeStack[depth][id] = true;
|
||||
maybeStack[depth][id] = RelationComparisonResult.Succeeded;
|
||||
depth++;
|
||||
var saveExpandingFlags = expandingFlags;
|
||||
if (!(expandingFlags & 1) && isDeeplyNestedGeneric(source, sourceStack)) expandingFlags |= 1;
|
||||
@@ -3655,13 +3709,13 @@ module ts {
|
||||
if (result) {
|
||||
var maybeCache = maybeStack[depth];
|
||||
// If result is definitely true, copy assumptions to global cache, else copy to next level up
|
||||
var destinationCache = result === Ternary.True || depth === 0 ? relation : maybeStack[depth - 1];
|
||||
copyMap(/*source*/maybeCache, /*target*/destinationCache);
|
||||
var destinationCache = (result === Ternary.True || depth === 0) ? relation : maybeStack[depth - 1];
|
||||
copyMap(maybeCache, destinationCache);
|
||||
}
|
||||
else {
|
||||
// A false result goes straight into global cache (when something is false under assumptions it
|
||||
// will also be false without assumptions)
|
||||
relation[id] = false;
|
||||
relation[id] = reportErrors ? RelationComparisonResult.FailedAndReported : RelationComparisonResult.Failed;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -3692,12 +3746,13 @@ module ts {
|
||||
}
|
||||
var result = Ternary.True;
|
||||
var properties = getPropertiesOfObjectType(target);
|
||||
var requireOptionalProperties = relation === subtypeRelation && !(source.flags & TypeFlags.ObjectLiteral);
|
||||
for (var i = 0; i < properties.length; i++) {
|
||||
var targetProp = properties[i];
|
||||
var sourceProp = getPropertyOfType(source, targetProp.name);
|
||||
if (sourceProp !== targetProp) {
|
||||
if (!sourceProp) {
|
||||
if (relation === subtypeRelation || !(targetProp.flags & SymbolFlags.Optional)) {
|
||||
if (!(targetProp.flags & SymbolFlags.Optional) || requireOptionalProperties) {
|
||||
if (reportErrors) {
|
||||
reportError(Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source));
|
||||
}
|
||||
@@ -4088,10 +4143,6 @@ module ts {
|
||||
errorMessageChainHead);
|
||||
}
|
||||
|
||||
function isTypeOfObjectLiteral(type: Type): boolean {
|
||||
return (type.flags & TypeFlags.Anonymous) && type.symbol && (type.symbol.flags & SymbolFlags.ObjectLiteral) ? true : false;
|
||||
}
|
||||
|
||||
function isArrayType(type: Type): boolean {
|
||||
return type.flags & TypeFlags.Reference && (<TypeReference>type).target === globalArrayType;
|
||||
}
|
||||
@@ -4104,13 +4155,18 @@ module ts {
|
||||
var properties = getPropertiesOfObjectType(type);
|
||||
var members: SymbolTable = {};
|
||||
forEach(properties, p => {
|
||||
var symbol = <TransientSymbol>createSymbol(p.flags | SymbolFlags.Transient, p.name);
|
||||
symbol.declarations = p.declarations;
|
||||
symbol.parent = p.parent;
|
||||
symbol.type = getWidenedType(getTypeOfSymbol(p));
|
||||
symbol.target = p;
|
||||
if (p.valueDeclaration) symbol.valueDeclaration = p.valueDeclaration;
|
||||
members[symbol.name] = symbol;
|
||||
var propType = getTypeOfSymbol(p);
|
||||
var widenedType = getWidenedType(propType);
|
||||
if (propType !== widenedType) {
|
||||
var symbol = <TransientSymbol>createSymbol(p.flags | SymbolFlags.Transient, p.name);
|
||||
symbol.declarations = p.declarations;
|
||||
symbol.parent = p.parent;
|
||||
symbol.type = widenedType;
|
||||
symbol.target = p;
|
||||
if (p.valueDeclaration) symbol.valueDeclaration = p.valueDeclaration;
|
||||
p = symbol;
|
||||
}
|
||||
members[p.name] = p;
|
||||
});
|
||||
var stringIndexType = getIndexTypeOfType(type, IndexKind.String);
|
||||
var numberIndexType = getIndexTypeOfType(type, IndexKind.Number);
|
||||
@@ -4120,16 +4176,16 @@ module ts {
|
||||
}
|
||||
|
||||
function getWidenedType(type: Type): Type {
|
||||
if (type.flags & TypeFlags.Unwidened) {
|
||||
if (type.flags & TypeFlags.RequiresWidening) {
|
||||
if (type.flags & (TypeFlags.Undefined | TypeFlags.Null)) {
|
||||
return anyType;
|
||||
}
|
||||
if (type.flags & TypeFlags.ObjectLiteral) {
|
||||
return getWidenedTypeOfObjectLiteral(type);
|
||||
}
|
||||
if (type.flags & TypeFlags.Union) {
|
||||
return getUnionType(map((<UnionType>type).types, getWidenedType));
|
||||
}
|
||||
if (isTypeOfObjectLiteral(type)) {
|
||||
return getWidenedTypeOfObjectLiteral(type);
|
||||
}
|
||||
if (isArrayType(type)) {
|
||||
return createArrayType(getWidenedType((<TypeReference>type).typeArguments[0]));
|
||||
}
|
||||
@@ -4150,11 +4206,11 @@ module ts {
|
||||
if (isArrayType(type)) {
|
||||
return reportWideningErrorsInType((<TypeReference>type).typeArguments[0]);
|
||||
}
|
||||
if (isTypeOfObjectLiteral(type)) {
|
||||
if (type.flags & TypeFlags.ObjectLiteral) {
|
||||
var errorReported = false;
|
||||
forEach(getPropertiesOfObjectType(type), p => {
|
||||
var t = getTypeOfSymbol(p);
|
||||
if (t.flags & TypeFlags.Unwidened) {
|
||||
if (t.flags & TypeFlags.ContainsUndefinedOrNull) {
|
||||
if (!reportWideningErrorsInType(t)) {
|
||||
error(p.valueDeclaration, Diagnostics.Object_literal_s_property_0_implicitly_has_an_1_type, p.name, typeToString(getWidenedType(t)));
|
||||
}
|
||||
@@ -4198,7 +4254,7 @@ module ts {
|
||||
}
|
||||
|
||||
function reportErrorsFromWidening(declaration: Declaration, type: Type) {
|
||||
if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & TypeFlags.Unwidened) {
|
||||
if (produceDiagnostics && compilerOptions.noImplicitAny && type.flags & TypeFlags.ContainsUndefinedOrNull) {
|
||||
// Report implicit any error within type if possible, otherwise report error on declaration
|
||||
if (!reportWideningErrorsInType(type)) {
|
||||
reportImplicitAnyError(declaration, type);
|
||||
@@ -4454,12 +4510,17 @@ module ts {
|
||||
Debug.fail("should not get here");
|
||||
}
|
||||
|
||||
// Remove one or more primitive types from a union type
|
||||
function subtractPrimitiveTypes(type: Type, subtractMask: TypeFlags): Type {
|
||||
// For a union type, remove all constituent types that are of the given type kind (when isOfTypeKind is true)
|
||||
// or not of the given type kind (when isOfTypeKind is false)
|
||||
function removeTypesFromUnionType(type: Type, typeKind: TypeFlags, isOfTypeKind: boolean): Type {
|
||||
if (type.flags & TypeFlags.Union) {
|
||||
var types = (<UnionType>type).types;
|
||||
if (forEach(types, t => t.flags & subtractMask)) {
|
||||
return getUnionType(filter(types, t => !(t.flags & subtractMask)));
|
||||
if (forEach(types, t => !!(t.flags & typeKind) === isOfTypeKind)) {
|
||||
// Above we checked if we have anything to remove, now use the opposite test to do the removal
|
||||
var narrowedType = getUnionType(filter(types, t => !(t.flags & typeKind) === isOfTypeKind));
|
||||
if (narrowedType !== emptyObjectType) {
|
||||
return narrowedType;
|
||||
}
|
||||
}
|
||||
}
|
||||
return type;
|
||||
@@ -4635,8 +4696,8 @@ module ts {
|
||||
// Stop at the first containing function or module declaration
|
||||
break loop;
|
||||
}
|
||||
// Use narrowed type if it is a subtype and construct contains no assignments to variable
|
||||
if (narrowedType !== type && isTypeSubtypeOf(narrowedType, type)) {
|
||||
// Use narrowed type if construct contains no assignments to variable
|
||||
if (narrowedType !== type) {
|
||||
if (isVariableAssignedWithin(symbol, node)) {
|
||||
break;
|
||||
}
|
||||
@@ -4656,20 +4717,30 @@ module ts {
|
||||
if (left.expression.kind !== SyntaxKind.Identifier || getResolvedSymbol(<Identifier>left.expression) !== symbol) {
|
||||
return type;
|
||||
}
|
||||
var t = right.text;
|
||||
var checkType: Type = t === "string" ? stringType : t === "number" ? numberType : t === "boolean" ? booleanType : emptyObjectType;
|
||||
var typeInfo = primitiveTypeInfo[right.text];
|
||||
if (expr.operator === SyntaxKind.ExclamationEqualsEqualsToken) {
|
||||
assumeTrue = !assumeTrue;
|
||||
}
|
||||
if (assumeTrue) {
|
||||
// The assumed result is true. If check was for a primitive type, that type is the narrowed type. Otherwise we can
|
||||
// remove the primitive types from the narrowed type.
|
||||
return checkType === emptyObjectType ? subtractPrimitiveTypes(type, TypeFlags.String | TypeFlags.Number | TypeFlags.Boolean) : checkType;
|
||||
// Assumed result is true. If check was not for a primitive type, remove all primitive types
|
||||
if (!typeInfo) {
|
||||
return removeTypesFromUnionType(type, /*typeKind*/ TypeFlags.StringLike | TypeFlags.NumberLike | TypeFlags.Boolean, /*isOfTypeKind*/ true);
|
||||
}
|
||||
// Check was for a primitive type, return that primitive type if it is a subtype
|
||||
if (isTypeSubtypeOf(typeInfo.type, type)) {
|
||||
return typeInfo.type;
|
||||
}
|
||||
// Otherwise, remove all types that aren't of the primitive type kind. This can happen when the type is
|
||||
// union of enum types and other types.
|
||||
return removeTypesFromUnionType(type, /*typeKind*/ typeInfo.flags, /*isOfTypeKind*/ false);
|
||||
}
|
||||
else {
|
||||
// The assumed result is false. If check was for a primitive type we can remove that type from the narrowed type.
|
||||
// Assumed result is false. If check was for a primitive type, remove that primitive type
|
||||
if (typeInfo) {
|
||||
return removeTypesFromUnionType(type, /*typeKind*/ typeInfo.flags, /*isOfTypeKind*/ true);
|
||||
}
|
||||
// Otherwise we don't have enough information to do anything.
|
||||
return checkType === emptyObjectType ? type : subtractPrimitiveTypes(type, checkType.flags);
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4730,7 +4801,8 @@ module ts {
|
||||
return type;
|
||||
}
|
||||
|
||||
// Narrow the given type based on the given expression having the assumed boolean value
|
||||
// Narrow the given type based on the given expression having the assumed boolean value. The returned type
|
||||
// will be a subtype or the same type as the argument.
|
||||
function narrowType(type: Type, expr: Expression, assumeTrue: boolean): Type {
|
||||
switch (expr.kind) {
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
@@ -4759,6 +4831,7 @@ module ts {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
/*Transitively mark all linked imports as referenced*/
|
||||
function markLinkedImportsAsReferenced(node: ImportDeclaration): void {
|
||||
var nodeLinks = getNodeLinks(node);
|
||||
@@ -4855,6 +4928,9 @@ module ts {
|
||||
// do not return here so in case if lexical this is captured - it will be reflected in flags on NodeLinks
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
error(node, Diagnostics.this_cannot_be_referenced_in_a_computed_property_name);
|
||||
break;
|
||||
}
|
||||
|
||||
if (needToCaptureLexicalThis) {
|
||||
@@ -4869,26 +4945,6 @@ module ts {
|
||||
return anyType;
|
||||
}
|
||||
|
||||
function getSuperContainer(node: Node): Node {
|
||||
while (true) {
|
||||
node = node.parent;
|
||||
if (!node) return node;
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.PropertySignature:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.MethodSignature:
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
return node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isInConstructorArgumentInitializer(node: Node, constructorDecl: Node): boolean {
|
||||
for (var n = node; n && n !== constructorDecl; n = n.parent) {
|
||||
if (n.kind === SyntaxKind.Parameter) {
|
||||
@@ -4912,7 +4968,7 @@ module ts {
|
||||
return unknownType;
|
||||
}
|
||||
|
||||
var container = getSuperContainer(node);
|
||||
var container = getSuperContainer(node, /*includeFunctions*/ true);
|
||||
|
||||
if (container) {
|
||||
var canUseSuperExpression = false;
|
||||
@@ -4930,7 +4986,7 @@ module ts {
|
||||
// super property access might appear in arrow functions with arbitrary deep nesting
|
||||
var needToCaptureLexicalThis = false;
|
||||
while (container && container.kind === SyntaxKind.ArrowFunction) {
|
||||
container = getSuperContainer(container);
|
||||
container = getSuperContainer(container, /*includeFunctions*/ true);
|
||||
needToCaptureLexicalThis = true;
|
||||
}
|
||||
|
||||
@@ -4985,7 +5041,10 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
if (isCallExpression) {
|
||||
if (container.kind === SyntaxKind.ComputedPropertyName) {
|
||||
error(node, Diagnostics.super_cannot_be_referenced_in_a_computed_property_name);
|
||||
}
|
||||
else if (isCallExpression) {
|
||||
error(node, Diagnostics.Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors);
|
||||
}
|
||||
else {
|
||||
@@ -5167,13 +5226,22 @@ module ts {
|
||||
function getContextualTypeForObjectLiteralElement(element: ObjectLiteralElement) {
|
||||
var objectLiteral = <ObjectLiteralExpression>element.parent;
|
||||
var type = getContextualType(objectLiteral);
|
||||
// TODO(jfreeman): Handle this case for computed names and symbols
|
||||
var name = (<Identifier>element.name).text;
|
||||
if (type && name) {
|
||||
return getTypeOfPropertyOfContextualType(type, name) ||
|
||||
isNumericName(name) && getIndexTypeOfContextualType(type, IndexKind.Number) ||
|
||||
if (type) {
|
||||
if (!hasDynamicName(element)) {
|
||||
// For a (non-symbol) computed property, there is no reason to look up the name
|
||||
// in the type. It will just be "__computed", which does not appear in any
|
||||
// SymbolTable.
|
||||
var symbolName = getSymbolOfNode(element).name;
|
||||
var propertyType = getTypeOfPropertyOfContextualType(type, symbolName);
|
||||
if (propertyType) {
|
||||
return propertyType;
|
||||
}
|
||||
}
|
||||
|
||||
return isNumericName(element.name) && getIndexTypeOfContextualType(type, IndexKind.Number) ||
|
||||
getIndexTypeOfContextualType(type, IndexKind.String);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -5372,7 +5440,17 @@ module ts {
|
||||
return createArrayType(getUnionType(elementTypes));
|
||||
}
|
||||
|
||||
function isNumericName(name: string) {
|
||||
function isNumericName(name: DeclarationName): boolean {
|
||||
return name.kind === SyntaxKind.ComputedPropertyName ? isNumericComputedName(<ComputedPropertyName>name) : isNumericLiteralName((<Identifier>name).text);
|
||||
}
|
||||
|
||||
function isNumericComputedName(name: ComputedPropertyName): boolean {
|
||||
// It seems odd to consider an expression of type Any to result in a numeric name,
|
||||
// but this behavior is consistent with checkIndexedAccess
|
||||
return isTypeOfKind(checkComputedPropertyName(name), TypeFlags.Any | TypeFlags.NumberLike);
|
||||
}
|
||||
|
||||
function isNumericLiteralName(name: string) {
|
||||
// The intent of numeric names is that
|
||||
// - they are names with text in a numeric form, and that
|
||||
// - setting properties/indexing with them is always equivalent to doing so with the numeric literal 'numLit',
|
||||
@@ -5397,84 +5475,101 @@ module ts {
|
||||
return (+name).toString() === name;
|
||||
}
|
||||
|
||||
function checkComputedPropertyName(node: ComputedPropertyName): Type {
|
||||
var links = getNodeLinks(node.expression);
|
||||
if (!links.resolvedType) {
|
||||
links.resolvedType = checkExpression(node.expression);
|
||||
|
||||
// This will allow types number, string, or any. It will also allow enums, the unknown
|
||||
// type, and any union of these types (like string | number).
|
||||
if (!isTypeOfKind(links.resolvedType, TypeFlags.Any | TypeFlags.NumberLike | TypeFlags.StringLike)) {
|
||||
error(node, Diagnostics.A_computed_property_name_must_be_of_type_string_number_or_any);
|
||||
}
|
||||
}
|
||||
|
||||
return links.resolvedType;
|
||||
}
|
||||
|
||||
function checkObjectLiteral(node: ObjectLiteralExpression, contextualMapper?: TypeMapper): Type {
|
||||
// Grammar checking
|
||||
checkGrammarObjectLiteralExpression(node);
|
||||
|
||||
var members = node.symbol.members;
|
||||
var properties: SymbolTable = {};
|
||||
var propertiesTable: SymbolTable = {};
|
||||
var propertiesArray: Symbol[] = [];
|
||||
var contextualType = getContextualType(node);
|
||||
var typeFlags: TypeFlags;
|
||||
|
||||
for (var id in members) {
|
||||
if (hasProperty(members, id)) {
|
||||
var member = members[id];
|
||||
if (member.flags & SymbolFlags.Property || isObjectLiteralMethod(member.declarations[0])) {
|
||||
var memberDecl = <ObjectLiteralElement>member.declarations[0];
|
||||
if (memberDecl.kind === SyntaxKind.PropertyAssignment) {
|
||||
var type = checkExpression((<PropertyAssignment>memberDecl).initializer, contextualMapper);
|
||||
}
|
||||
else if (memberDecl.kind === SyntaxKind.MethodDeclaration) {
|
||||
var type = checkObjectLiteralMethod(<MethodDeclaration>memberDecl, contextualMapper);
|
||||
}
|
||||
else {
|
||||
Debug.assert(memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment);
|
||||
var type = memberDecl.name.kind === SyntaxKind.ComputedPropertyName
|
||||
? unknownType
|
||||
: checkExpression(<Identifier>memberDecl.name, contextualMapper);
|
||||
}
|
||||
typeFlags |= type.flags;
|
||||
var prop = <TransientSymbol>createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name);
|
||||
prop.declarations = member.declarations;
|
||||
prop.parent = member.parent;
|
||||
if (member.valueDeclaration) {
|
||||
prop.valueDeclaration = member.valueDeclaration;
|
||||
}
|
||||
|
||||
prop.type = type;
|
||||
prop.target = member;
|
||||
member = prop;
|
||||
for (var i = 0; i < node.properties.length; i++) {
|
||||
var memberDecl = node.properties[i];
|
||||
var member = memberDecl.symbol;
|
||||
if (memberDecl.kind === SyntaxKind.PropertyAssignment ||
|
||||
memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment ||
|
||||
isObjectLiteralMethod(memberDecl)) {
|
||||
if (memberDecl.kind === SyntaxKind.PropertyAssignment) {
|
||||
var type = checkPropertyAssignment(<PropertyAssignment>memberDecl, contextualMapper);
|
||||
}
|
||||
else if (memberDecl.kind === SyntaxKind.MethodDeclaration) {
|
||||
var type = checkObjectLiteralMethod(<MethodDeclaration>memberDecl, contextualMapper);
|
||||
}
|
||||
else {
|
||||
// TypeScript 1.0 spec (April 2014)
|
||||
// A get accessor declaration is processed in the same manner as
|
||||
// an ordinary function declaration(section 6.1) with no parameters.
|
||||
// A set accessor declaration is processed in the same manner
|
||||
// as an ordinary function declaration with a single parameter and a Void return type.
|
||||
var getAccessor = <AccessorDeclaration>getDeclarationOfKind(member, SyntaxKind.GetAccessor);
|
||||
if (getAccessor) {
|
||||
checkAccessorDeclaration(getAccessor);
|
||||
}
|
||||
|
||||
var setAccessor = <AccessorDeclaration>getDeclarationOfKind(member, SyntaxKind.SetAccessor);
|
||||
if (setAccessor) {
|
||||
checkAccessorDeclaration(setAccessor);
|
||||
}
|
||||
Debug.assert(memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment);
|
||||
var type = memberDecl.name.kind === SyntaxKind.ComputedPropertyName
|
||||
? unknownType
|
||||
: checkExpression(<Identifier>memberDecl.name, contextualMapper);
|
||||
}
|
||||
properties[member.name] = member;
|
||||
typeFlags |= type.flags;
|
||||
var prop = <TransientSymbol>createSymbol(SymbolFlags.Property | SymbolFlags.Transient | member.flags, member.name);
|
||||
prop.declarations = member.declarations;
|
||||
prop.parent = member.parent;
|
||||
if (member.valueDeclaration) {
|
||||
prop.valueDeclaration = member.valueDeclaration;
|
||||
}
|
||||
|
||||
prop.type = type;
|
||||
prop.target = member;
|
||||
member = prop;
|
||||
}
|
||||
else {
|
||||
// TypeScript 1.0 spec (April 2014)
|
||||
// A get accessor declaration is processed in the same manner as
|
||||
// an ordinary function declaration(section 6.1) with no parameters.
|
||||
// A set accessor declaration is processed in the same manner
|
||||
// as an ordinary function declaration with a single parameter and a Void return type.
|
||||
Debug.assert(memberDecl.kind === SyntaxKind.GetAccessor || memberDecl.kind === SyntaxKind.SetAccessor);
|
||||
checkAccessorDeclaration(<AccessorDeclaration>memberDecl);
|
||||
}
|
||||
|
||||
if (!hasDynamicName(memberDecl)) {
|
||||
propertiesTable[member.name] = member;
|
||||
}
|
||||
propertiesArray.push(member);
|
||||
}
|
||||
|
||||
var stringIndexType = getIndexType(IndexKind.String);
|
||||
var numberIndexType = getIndexType(IndexKind.Number);
|
||||
var result = createAnonymousType(node.symbol, properties, emptyArray, emptyArray, stringIndexType, numberIndexType);
|
||||
result.flags |= (typeFlags & TypeFlags.Unwidened);
|
||||
var result = createAnonymousType(node.symbol, propertiesTable, emptyArray, emptyArray, stringIndexType, numberIndexType);
|
||||
result.flags |= TypeFlags.ObjectLiteral | TypeFlags.ContainsObjectLiteral | (typeFlags & TypeFlags.ContainsUndefinedOrNull);
|
||||
return result;
|
||||
|
||||
function getIndexType(kind: IndexKind) {
|
||||
if (contextualType && contextualTypeHasIndexSignature(contextualType, kind)) {
|
||||
var propTypes: Type[] = [];
|
||||
for (var id in properties) {
|
||||
if (hasProperty(properties, id)) {
|
||||
if (kind === IndexKind.String || isNumericName(id)) {
|
||||
var type = getTypeOfSymbol(properties[id]);
|
||||
if (!contains(propTypes, type)) {
|
||||
propTypes.push(type);
|
||||
}
|
||||
for (var i = 0; i < propertiesArray.length; i++) {
|
||||
var propertyDecl = node.properties[i];
|
||||
if (kind === IndexKind.String || isNumericName(propertyDecl.name)) {
|
||||
// Do not call getSymbolOfNode(propertyDecl), as that will get the
|
||||
// original symbol for the node. We actually want to get the symbol
|
||||
// created by checkObjectLiteral, since that will be appropriately
|
||||
// contextually typed and resolved.
|
||||
var type = getTypeOfSymbol(propertiesArray[i]);
|
||||
if (!contains(propTypes, type)) {
|
||||
propTypes.push(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
return propTypes.length ? getUnionType(propTypes) : undefinedType;
|
||||
var result = propTypes.length ? getUnionType(propTypes) : undefinedType;
|
||||
typeFlags |= result.flags;
|
||||
return result;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
@@ -5867,7 +5962,7 @@ module ts {
|
||||
return typeArgumentsAreAssignable;
|
||||
}
|
||||
|
||||
function checkApplicableSignature(node: CallLikeExpression, args: Node[], signature: Signature, relation: Map<boolean>, excludeArgument: boolean[], reportErrors: boolean) {
|
||||
function checkApplicableSignature(node: CallLikeExpression, args: Node[], signature: Signature, relation: Map<RelationComparisonResult>, excludeArgument: boolean[], reportErrors: boolean) {
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
var arg = args[i];
|
||||
var argType: Type;
|
||||
@@ -5927,11 +6022,41 @@ module ts {
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* In a 'super' call, type arguments are not provided within the CallExpression node itself.
|
||||
* Instead, they must be fetched from the class declaration's base type node.
|
||||
*
|
||||
* If 'node' is a 'super' call (e.g. super(...), new super(...)), then we attempt to fetch
|
||||
* the type arguments off the containing class's first heritage clause (if one exists). Note that if
|
||||
* type arguments are supplied on the 'super' call, they are ignored (though this is syntactically incorrect).
|
||||
*
|
||||
* In all other cases, the call's explicit type arguments are returned.
|
||||
*/
|
||||
function getEffectiveTypeArguments(callExpression: CallExpression): TypeNode[] {
|
||||
if (callExpression.expression.kind === SyntaxKind.SuperKeyword) {
|
||||
var containingClass = <ClassDeclaration>getAncestor(callExpression, SyntaxKind.ClassDeclaration);
|
||||
var baseClassTypeNode = containingClass && getClassBaseTypeNode(containingClass);
|
||||
return baseClassTypeNode && baseClassTypeNode.typeArguments;
|
||||
}
|
||||
else {
|
||||
// Ordinary case - simple function invocation.
|
||||
return callExpression.typeArguments;
|
||||
}
|
||||
}
|
||||
|
||||
function resolveCall(node: CallLikeExpression, signatures: Signature[], candidatesOutArray: Signature[]): Signature {
|
||||
var isTaggedTemplate = node.kind === SyntaxKind.TaggedTemplateExpression;
|
||||
|
||||
var typeArguments = isTaggedTemplate ? undefined : (<CallExpression>node).typeArguments;
|
||||
forEach(typeArguments, checkSourceElement);
|
||||
var typeArguments: TypeNode[];
|
||||
|
||||
if (!isTaggedTemplate) {
|
||||
typeArguments = getEffectiveTypeArguments(<CallExpression>node);
|
||||
|
||||
// We already perform checking on the type arguments on the class declaration itself.
|
||||
if ((<CallExpression>node).expression.kind !== SyntaxKind.SuperKeyword) {
|
||||
forEach(typeArguments, checkSourceElement);
|
||||
}
|
||||
}
|
||||
|
||||
var candidates = candidatesOutArray || [];
|
||||
// collectCandidates fills up the candidates array directly
|
||||
@@ -6061,7 +6186,7 @@ module ts {
|
||||
|
||||
return resolveErrorCall(node);
|
||||
|
||||
function chooseOverload(candidates: Signature[], relation: Map<boolean>) {
|
||||
function chooseOverload(candidates: Signature[], relation: Map<RelationComparisonResult>) {
|
||||
for (var i = 0; i < candidates.length; i++) {
|
||||
if (!hasCorrectArity(node, args, candidates[i])) {
|
||||
continue;
|
||||
@@ -6197,7 +6322,7 @@ module ts {
|
||||
// Another error has already been reported
|
||||
return resolveErrorCall(node);
|
||||
}
|
||||
|
||||
|
||||
// Technically, this signatures list may be incomplete. We are taking the apparent type,
|
||||
// but we are not including call signatures that may have been added to the Object or
|
||||
// Function interface, since they have none by default. This is a bit of a leap of faith
|
||||
@@ -6738,7 +6863,7 @@ module ts {
|
||||
// and the right operand to be of type Any or a subtype of the 'Function' interface type.
|
||||
// The result is always of the Boolean primitive type.
|
||||
// NOTE: do not raise error if leftType is unknown as related error was already reported
|
||||
if (!isTypeOfKind(leftType, TypeFlags.Any | TypeFlags.ObjectType | TypeFlags.TypeParameter)) {
|
||||
if (isTypeOfKind(leftType, TypeFlags.Primitive)) {
|
||||
error(node.left, Diagnostics.The_left_hand_side_of_an_instanceof_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
|
||||
}
|
||||
// NOTE: do not raise error if right is unknown as related error was already reported
|
||||
@@ -6771,7 +6896,7 @@ module ts {
|
||||
var name = <Identifier>(<PropertyAssignment>p).name;
|
||||
var type = sourceType.flags & TypeFlags.Any ? sourceType :
|
||||
getTypeOfPropertyOfType(sourceType, name.text) ||
|
||||
isNumericName(name.text) && getIndexTypeOfType(sourceType, IndexKind.Number) ||
|
||||
isNumericLiteralName(name.text) && getIndexTypeOfType(sourceType, IndexKind.Number) ||
|
||||
getIndexTypeOfType(sourceType, IndexKind.String);
|
||||
if (type) {
|
||||
checkDestructuringAssignment((<PropertyAssignment>p).initializer || name, type);
|
||||
@@ -7052,10 +7177,22 @@ module ts {
|
||||
return links.resolvedType;
|
||||
}
|
||||
|
||||
function checkPropertyAssignment(node: PropertyAssignment, contextualMapper?: TypeMapper): Type {
|
||||
if (hasDynamicName(node)) {
|
||||
checkComputedPropertyName(<ComputedPropertyName>node.name);
|
||||
}
|
||||
|
||||
return checkExpression((<PropertyAssignment>node).initializer, contextualMapper);
|
||||
}
|
||||
|
||||
function checkObjectLiteralMethod(node: MethodDeclaration, contextualMapper?: TypeMapper): Type {
|
||||
// Grammar checking
|
||||
checkGrammarMethod(node);
|
||||
|
||||
if (hasDynamicName(node)) {
|
||||
checkComputedPropertyName(<ComputedPropertyName>node.name);
|
||||
}
|
||||
|
||||
var uninstantiatedType = checkFunctionExpressionOrObjectLiteralMethod(node, contextualMapper);
|
||||
return instantiateTypeWithSingleGenericCallSignature(node, uninstantiatedType, contextualMapper);
|
||||
}
|
||||
@@ -7426,7 +7563,7 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasComputedNameButNotSymbol(node)) {
|
||||
if (!hasDynamicName(node)) {
|
||||
// TypeScript 1.0 spec (April 2014): 8.4.3
|
||||
// Accessors for the same member name must specify the same accessibility.
|
||||
var otherKind = node.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor;
|
||||
@@ -7446,9 +7583,9 @@ module ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checkAndStoreTypeOfAccessors(getSymbolOfNode(node));
|
||||
}
|
||||
|
||||
checkAndStoreTypeOfAccessors(getSymbolOfNode(node));
|
||||
}
|
||||
|
||||
checkFunctionLikeDeclaration(node);
|
||||
@@ -7864,7 +8001,12 @@ module ts {
|
||||
function checkFunctionLikeDeclaration(node: FunctionLikeDeclaration): void {
|
||||
checkSignatureDeclaration(node);
|
||||
|
||||
if (!hasComputedNameButNotSymbol(node)) {
|
||||
if (hasDynamicName(node)) {
|
||||
// This check will account for methods in class/interface declarations,
|
||||
// as well as accessors in classes/object literals
|
||||
checkComputedPropertyName(<ComputedPropertyName>node.name);
|
||||
}
|
||||
else {
|
||||
// first we want to check the local symbol that contain this declaration
|
||||
// - if node.localSymbol !== undefined - this is current declaration is exported and localSymbol points to the local symbol
|
||||
// - if node.localSymbol === undefined - this node is non-exported so we can just pick the result of getSymbolOfNode
|
||||
@@ -8093,7 +8235,8 @@ module ts {
|
||||
function checkVariableLikeDeclaration(node: VariableLikeDeclaration) {
|
||||
checkSourceElement(node.type);
|
||||
// For a computed property, just check the initializer and exit
|
||||
if (hasComputedNameButNotSymbol(node)) {
|
||||
if (hasDynamicName(node)) {
|
||||
checkComputedPropertyName(<ComputedPropertyName>node.name);
|
||||
if (node.initializer) {
|
||||
checkExpressionCached(node.initializer);
|
||||
}
|
||||
@@ -8436,45 +8579,7 @@ module ts {
|
||||
if (node.finallyBlock) checkBlock(node.finallyBlock);
|
||||
}
|
||||
|
||||
function checkIndexConstraints(type: Type) {
|
||||
|
||||
function checkIndexConstraintForProperty(prop: Symbol, propertyType: Type, indexDeclaration: Declaration, indexType: Type, indexKind: IndexKind): void {
|
||||
if (!indexType) {
|
||||
return;
|
||||
}
|
||||
|
||||
// index is numeric and property name is not valid numeric literal
|
||||
if (indexKind === IndexKind.Number && !isNumericName(prop.name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// perform property check if property or indexer is declared in 'type'
|
||||
// this allows to rule out cases when both property and indexer are inherited from the base class
|
||||
var errorNode: Node;
|
||||
if (prop.parent === type.symbol) {
|
||||
errorNode = prop.valueDeclaration;
|
||||
}
|
||||
else if (indexDeclaration) {
|
||||
errorNode = indexDeclaration;
|
||||
}
|
||||
|
||||
else if (type.flags & TypeFlags.Interface) {
|
||||
// for interfaces property and indexer might be inherited from different bases
|
||||
// check if any base class already has both property and indexer.
|
||||
// check should be performed only if 'type' is the first type that brings property\indexer together
|
||||
var someBaseClassHasBothPropertyAndIndexer = forEach((<InterfaceType>type).baseTypes, base => getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind));
|
||||
errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : type.symbol.declarations[0];
|
||||
}
|
||||
|
||||
if (errorNode && !isTypeAssignableTo(propertyType, indexType)) {
|
||||
var errorMessage =
|
||||
indexKind === IndexKind.String
|
||||
? Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2
|
||||
: Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2;
|
||||
error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType));
|
||||
}
|
||||
}
|
||||
|
||||
function checkIndexConstraints(type: Type) {
|
||||
var declaredNumberIndexer = getIndexDeclarationOfSymbol(type.symbol, IndexKind.Number);
|
||||
var declaredStringIndexer = getIndexDeclarationOfSymbol(type.symbol, IndexKind.String);
|
||||
|
||||
@@ -8484,9 +8589,24 @@ module ts {
|
||||
if (stringIndexType || numberIndexType) {
|
||||
forEach(getPropertiesOfObjectType(type), prop => {
|
||||
var propType = getTypeOfSymbol(prop);
|
||||
checkIndexConstraintForProperty(prop, propType, declaredStringIndexer, stringIndexType, IndexKind.String);
|
||||
checkIndexConstraintForProperty(prop, propType, declaredNumberIndexer, numberIndexType, IndexKind.Number);
|
||||
checkIndexConstraintForProperty(prop, propType, type, declaredStringIndexer, stringIndexType, IndexKind.String);
|
||||
checkIndexConstraintForProperty(prop, propType, type, declaredNumberIndexer, numberIndexType, IndexKind.Number);
|
||||
});
|
||||
|
||||
if (type.flags & TypeFlags.Class && type.symbol.valueDeclaration.kind === SyntaxKind.ClassDeclaration) {
|
||||
var classDeclaration = <ClassDeclaration>type.symbol.valueDeclaration;
|
||||
for (var i = 0; i < classDeclaration.members.length; i++) {
|
||||
var member = classDeclaration.members[i];
|
||||
// Only process instance properties with computed names here.
|
||||
// Static properties cannot be in conflict with indexers,
|
||||
// and properties with literal names were already checked.
|
||||
if (!(member.flags & NodeFlags.Static) && hasDynamicName(member)) {
|
||||
var propType = getTypeOfSymbol(member.symbol);
|
||||
checkIndexConstraintForProperty(member.symbol, propType, type, declaredStringIndexer, stringIndexType, IndexKind.String);
|
||||
checkIndexConstraintForProperty(member.symbol, propType, type, declaredNumberIndexer, numberIndexType, IndexKind.Number);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var errorNode: Node;
|
||||
@@ -8503,9 +8623,51 @@ module ts {
|
||||
error(errorNode, Diagnostics.Numeric_index_type_0_is_not_assignable_to_string_index_type_1,
|
||||
typeToString(numberIndexType), typeToString(stringIndexType));
|
||||
}
|
||||
|
||||
function checkIndexConstraintForProperty(
|
||||
prop: Symbol,
|
||||
propertyType: Type,
|
||||
containingType: Type,
|
||||
indexDeclaration: Declaration,
|
||||
indexType: Type,
|
||||
indexKind: IndexKind): void {
|
||||
|
||||
if (!indexType) {
|
||||
return;
|
||||
}
|
||||
|
||||
// index is numeric and property name is not valid numeric literal
|
||||
if (indexKind === IndexKind.Number && !isNumericName(prop.valueDeclaration.name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// perform property check if property or indexer is declared in 'type'
|
||||
// this allows to rule out cases when both property and indexer are inherited from the base class
|
||||
var errorNode: Node;
|
||||
if (prop.valueDeclaration.name.kind === SyntaxKind.ComputedPropertyName || prop.parent === containingType.symbol) {
|
||||
errorNode = prop.valueDeclaration;
|
||||
}
|
||||
else if (indexDeclaration) {
|
||||
errorNode = indexDeclaration;
|
||||
}
|
||||
else if (containingType.flags & TypeFlags.Interface) {
|
||||
// for interfaces property and indexer might be inherited from different bases
|
||||
// check if any base class already has both property and indexer.
|
||||
// check should be performed only if 'type' is the first type that brings property\indexer together
|
||||
var someBaseClassHasBothPropertyAndIndexer = forEach((<InterfaceType>containingType).baseTypes, base => getPropertyOfObjectType(base, prop.name) && getIndexTypeOfType(base, indexKind));
|
||||
errorNode = someBaseClassHasBothPropertyAndIndexer ? undefined : containingType.symbol.declarations[0];
|
||||
}
|
||||
|
||||
if (errorNode && !isTypeAssignableTo(propertyType, indexType)) {
|
||||
var errorMessage =
|
||||
indexKind === IndexKind.String
|
||||
? Diagnostics.Property_0_of_type_1_is_not_assignable_to_string_index_type_2
|
||||
: Diagnostics.Property_0_of_type_1_is_not_assignable_to_numeric_index_type_2;
|
||||
error(errorNode, errorMessage, symbolToString(prop), typeToString(propertyType), typeToString(indexType));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO(jfreeman): Decide what to do for computed properties
|
||||
function checkTypeNameIsReserved(name: DeclarationName, message: DiagnosticMessage): void {
|
||||
// TS 1.0 spec (April 2014): 3.6.1
|
||||
// The predefined type keywords are reserved and cannot be used as names of user defined types.
|
||||
@@ -8799,8 +8961,7 @@ module ts {
|
||||
var enumIsConst = isConst(node);
|
||||
|
||||
forEach(node.members, member => {
|
||||
// TODO(jfreeman): Check that it is not a computed name
|
||||
if(isNumericName((<Identifier>member.name).text)) {
|
||||
if (member.name.kind !== SyntaxKind.ComputedPropertyName && isNumericLiteralName((<Identifier>member.name).text)) {
|
||||
error(member.name, Diagnostics.An_enum_member_cannot_have_a_numeric_name);
|
||||
}
|
||||
var initializer = member.initializer;
|
||||
@@ -9990,8 +10151,8 @@ module ts {
|
||||
if (symbol && (symbol.flags & SymbolFlags.EnumMember)) {
|
||||
var declaration = symbol.valueDeclaration;
|
||||
var constantValue: number;
|
||||
if (declaration.kind === SyntaxKind.EnumMember && (constantValue = getNodeLinks(declaration).enumMemberValue) !== undefined) {
|
||||
return constantValue;
|
||||
if (declaration.kind === SyntaxKind.EnumMember) {
|
||||
return getEnumMemberValue(<EnumMember>declaration);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10427,22 +10588,18 @@ module ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function checkGrammarComputedPropertyName(node: Node): void {
|
||||
function checkGrammarComputedPropertyName(node: Node): boolean {
|
||||
// If node is not a computedPropertyName, just skip the grammar checking
|
||||
if (node.kind !== SyntaxKind.ComputedPropertyName) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
// Since computed properties are not supported in the type checker, disallow them in TypeScript 1.4
|
||||
// Once full support is added, remove this error.
|
||||
grammarErrorOnNode(node, Diagnostics.Computed_property_names_are_not_currently_supported);
|
||||
return;
|
||||
|
||||
var computedPropertyName = <ComputedPropertyName>node;
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
grammarErrorOnNode(node, Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher);
|
||||
return grammarErrorOnNode(node, Diagnostics.Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher);
|
||||
}
|
||||
else if (computedPropertyName.expression.kind === SyntaxKind.BinaryExpression && (<BinaryExpression>computedPropertyName.expression).operator === SyntaxKind.CommaToken) {
|
||||
grammarErrorOnNode(computedPropertyName.expression, Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name);
|
||||
return grammarErrorOnNode(computedPropertyName.expression, Diagnostics.A_comma_expression_is_not_allowed_in_a_computed_property_name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -299,6 +299,10 @@ module ts {
|
||||
Type_0_is_not_an_array_type: { code: 2461, category: DiagnosticCategory.Error, key: "Type '{0}' is not an array type." },
|
||||
A_rest_element_must_be_last_in_an_array_destructuring_pattern: { code: 2462, category: DiagnosticCategory.Error, key: "A rest element must be last in an array destructuring pattern" },
|
||||
A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature: { code: 2463, category: DiagnosticCategory.Error, key: "A binding pattern parameter cannot be optional in an implementation signature." },
|
||||
A_computed_property_name_must_be_of_type_string_number_or_any: { code: 2464, category: DiagnosticCategory.Error, key: "A computed property name must be of type 'string', 'number', or 'any'." },
|
||||
this_cannot_be_referenced_in_a_computed_property_name: { code: 2465, category: DiagnosticCategory.Error, key: "'this' cannot be referenced in a computed property name." },
|
||||
super_cannot_be_referenced_in_a_computed_property_name: { code: 2466, category: DiagnosticCategory.Error, key: "'super' cannot be referenced in a computed property name." },
|
||||
A_computed_property_name_cannot_reference_a_type_parameter_from_its_containing_type: { code: 2466, category: DiagnosticCategory.Error, key: "A computed property name cannot reference a type parameter from its containing type." },
|
||||
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
|
||||
@@ -448,6 +452,5 @@ module ts {
|
||||
You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." },
|
||||
yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported.", isEarly: true },
|
||||
Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported.", isEarly: true },
|
||||
Computed_property_names_are_not_currently_supported: { code: 9002, category: DiagnosticCategory.Error, key: "Computed property names are not currently supported.", isEarly: true },
|
||||
};
|
||||
}
|
||||
@@ -675,7 +675,7 @@
|
||||
},
|
||||
"A parameter property may not be a binding pattern.": {
|
||||
"category": "Error",
|
||||
"code": 1187
|
||||
"code": 1187
|
||||
},
|
||||
|
||||
"Duplicate identifier '{0}'.": {
|
||||
@@ -1288,7 +1288,23 @@
|
||||
},
|
||||
"A binding pattern parameter cannot be optional in an implementation signature.": {
|
||||
"category": "Error",
|
||||
"code": 2463
|
||||
"code": 2463
|
||||
},
|
||||
"A computed property name must be of type 'string', 'number', or 'any'.": {
|
||||
"category": "Error",
|
||||
"code": 2464
|
||||
},
|
||||
"'this' cannot be referenced in a computed property name.": {
|
||||
"category": "Error",
|
||||
"code": 2465
|
||||
},
|
||||
"'super' cannot be referenced in a computed property name.": {
|
||||
"category": "Error",
|
||||
"code": 2466
|
||||
},
|
||||
"A computed property name cannot reference a type parameter from its containing type.": {
|
||||
"category": "Error",
|
||||
"code": 2466
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
@@ -1892,10 +1908,5 @@
|
||||
"category": "Error",
|
||||
"code": 9001,
|
||||
"isEarly": true
|
||||
},
|
||||
"Computed property names are not currently supported.": {
|
||||
"category": "Error",
|
||||
"code": 9002,
|
||||
"isEarly": true
|
||||
}
|
||||
}
|
||||
|
||||
+127
-77
@@ -932,6 +932,10 @@ module ts {
|
||||
}
|
||||
|
||||
function emitPropertyDeclaration(node: Declaration) {
|
||||
if (hasDynamicName(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
emitJsDocComments(node);
|
||||
emitClassMemberDeclarationFlags(node);
|
||||
emitVariableDeclaration(<VariableDeclaration>node);
|
||||
@@ -939,11 +943,13 @@ module ts {
|
||||
writeLine();
|
||||
}
|
||||
|
||||
// TODO(jfreeman): Factor out common part of property definition, but treat name differently
|
||||
function emitVariableDeclaration(node: VariableDeclaration) {
|
||||
// If we are emitting property it isn't moduleElement and hence we already know it needs to be emitted
|
||||
// so there is no check needed to see if declaration is visible
|
||||
if (node.kind !== SyntaxKind.VariableDeclaration || resolver.isDeclarationVisible(node)) {
|
||||
// If this node is a computed name, it can only be a symbol, because we've already skipped
|
||||
// it if it's not a well known symbol. In that case, the text of the name will be exactly
|
||||
// what we want, namely the name expression enclosed in brackets.
|
||||
writeTextOfNode(currentSourceFile, node.name);
|
||||
// If optional property emit ?
|
||||
if ((node.kind === SyntaxKind.PropertyDeclaration || node.kind === SyntaxKind.PropertySignature) && hasQuestionToken(node)) {
|
||||
@@ -1030,6 +1036,10 @@ module ts {
|
||||
}
|
||||
|
||||
function emitAccessorDeclaration(node: AccessorDeclaration) {
|
||||
if (hasDynamicName(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
var accessors = getAllAccessorDeclarations(<ClassDeclaration>node.parent, node);
|
||||
if (node === accessors.firstAccessor) {
|
||||
emitJsDocComments(accessors.getAccessor);
|
||||
@@ -1107,6 +1117,10 @@ module ts {
|
||||
}
|
||||
|
||||
function emitFunctionDeclaration(node: FunctionLikeDeclaration) {
|
||||
if (hasDynamicName(node)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If we are emitting Method/Constructor it isn't moduleElement and hence already determined to be emitting
|
||||
// so no need to verify if the declaration is visible
|
||||
if ((node.kind !== SyntaxKind.FunctionDeclaration || resolver.isDeclarationVisible(node)) &&
|
||||
@@ -1723,7 +1737,14 @@ module ts {
|
||||
if (scopeName) {
|
||||
var parentIndex = getSourceMapNameIndex();
|
||||
if (parentIndex !== -1) {
|
||||
scopeName = sourceMapData.sourceMapNames[parentIndex] + "." + scopeName;
|
||||
// Child scopes are always shown with a dot (even if they have no name),
|
||||
// unless it is a computed property. Then it is shown with brackets,
|
||||
// but the brackets are included in the name.
|
||||
var name = (<Declaration>node).name;
|
||||
if (!name || name.kind !== SyntaxKind.ComputedPropertyName) {
|
||||
scopeName = "." + scopeName;
|
||||
}
|
||||
scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName;
|
||||
}
|
||||
|
||||
scopeNameIndex = getProperty(sourceMapNameIndexMap, scopeName);
|
||||
@@ -1751,8 +1772,11 @@ module ts {
|
||||
node.kind === SyntaxKind.EnumDeclaration) {
|
||||
// Declaration and has associated name use it
|
||||
if ((<Declaration>node).name) {
|
||||
// TODO(jfreeman): Ask shkamat about what this name should be for source maps
|
||||
scopeName = (<Identifier>(<Declaration>node).name).text;
|
||||
var name = (<Declaration>node).name;
|
||||
// For computed property names, the text will include the brackets
|
||||
scopeName = name.kind === SyntaxKind.ComputedPropertyName
|
||||
? getTextOfNode(name)
|
||||
: (<Identifier>(<Declaration>node).name).text;
|
||||
}
|
||||
recordScopeNameStart(scopeName);
|
||||
}
|
||||
@@ -2403,28 +2427,20 @@ module ts {
|
||||
}
|
||||
|
||||
function emitMethod(node: MethodDeclaration) {
|
||||
if (!isObjectLiteralMethod(node)) {
|
||||
return;
|
||||
}
|
||||
emitLeadingComments(node);
|
||||
emit(node.name);
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
write(": function ");
|
||||
}
|
||||
emitSignatureAndBody(node);
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitPropertyAssignment(node: PropertyDeclaration) {
|
||||
emitLeadingComments(node);
|
||||
emit(node.name);
|
||||
write(": ");
|
||||
emit(node.initializer);
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitShorthandPropertyAssignment(node: ShorthandPropertyAssignment) {
|
||||
emitLeadingComments(node);
|
||||
emit(node.name);
|
||||
// If short-hand property has a prefix, then regardless of the target version, we will emit it as normal property assignment. For example:
|
||||
// module m {
|
||||
@@ -2441,7 +2457,6 @@ module ts {
|
||||
// Short-hand, { x }, is equivalent of normal form { x: x }
|
||||
emitExpressionIdentifier(node.name);
|
||||
}
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function tryEmitConstantValue(node: PropertyAccessExpression | ElementAccessExpression): boolean {
|
||||
@@ -2661,14 +2676,11 @@ module ts {
|
||||
}
|
||||
|
||||
function emitExpressionStatement(node: ExpressionStatement) {
|
||||
emitLeadingComments(node);
|
||||
emitParenthesized(node.expression, /*parenthesized*/ node.expression.kind === SyntaxKind.ArrowFunction);
|
||||
write(";");
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitIfStatement(node: IfStatement) {
|
||||
emitLeadingComments(node);
|
||||
var endPos = emitToken(SyntaxKind.IfKeyword, node.pos);
|
||||
write(" ");
|
||||
endPos = emitToken(SyntaxKind.OpenParenToken, endPos);
|
||||
@@ -2686,7 +2698,6 @@ module ts {
|
||||
emitEmbeddedStatement(node.elseStatement);
|
||||
}
|
||||
}
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitDoStatement(node: DoStatement) {
|
||||
@@ -2774,11 +2785,9 @@ module ts {
|
||||
}
|
||||
|
||||
function emitReturnStatement(node: ReturnStatement) {
|
||||
emitLeadingComments(node);
|
||||
emitToken(SyntaxKind.ReturnKeyword, node.pos);
|
||||
emitOptional(" ", node.expression);
|
||||
write(";");
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitWithStatement(node: WhileStatement) {
|
||||
@@ -3102,7 +3111,6 @@ module ts {
|
||||
}
|
||||
|
||||
function emitVariableDeclaration(node: VariableDeclaration) {
|
||||
emitLeadingComments(node);
|
||||
if (isBindingPattern(node.name)) {
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
emitDestructuring(node);
|
||||
@@ -3116,11 +3124,9 @@ module ts {
|
||||
emitModuleMemberName(node);
|
||||
emitOptional(" = ", node.initializer);
|
||||
}
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitVariableStatement(node: VariableStatement) {
|
||||
emitLeadingComments(node);
|
||||
if (!(node.flags & NodeFlags.Export)) {
|
||||
if (isLet(node.declarationList)) {
|
||||
write("let ");
|
||||
@@ -3134,11 +3140,9 @@ module ts {
|
||||
}
|
||||
emitCommaList(node.declarationList.declarations);
|
||||
write(";");
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitParameter(node: ParameterDeclaration) {
|
||||
emitLeadingComments(node);
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
if (isBindingPattern(node.name)) {
|
||||
var name = createTempVariable(node);
|
||||
@@ -3159,7 +3163,6 @@ module ts {
|
||||
emit(node.name);
|
||||
emitOptional(" = ", node.initializer);
|
||||
}
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitDefaultValueAssignments(node: FunctionLikeDeclaration) {
|
||||
@@ -3232,11 +3235,9 @@ module ts {
|
||||
}
|
||||
|
||||
function emitAccessor(node: AccessorDeclaration) {
|
||||
emitLeadingComments(node);
|
||||
write(node.kind === SyntaxKind.GetAccessor ? "get " : "set ");
|
||||
emit(node.name);
|
||||
emitSignatureAndBody(node);
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitFunctionDeclaration(node: FunctionLikeDeclaration) {
|
||||
@@ -3306,7 +3307,10 @@ module ts {
|
||||
write(" ");
|
||||
emitStart(node.body);
|
||||
write("return ");
|
||||
emitNode(node.body);
|
||||
|
||||
// Don't emit comments on this body. We'll have already taken care of it above
|
||||
// when we called emitDetachedComments.
|
||||
emitNode(node.body, /*disableComments:*/ true);
|
||||
emitEnd(node.body);
|
||||
write(";");
|
||||
emitTempDeclarations(/*newLine*/ false);
|
||||
@@ -3323,7 +3327,7 @@ module ts {
|
||||
writeLine();
|
||||
emitLeadingComments(node.body);
|
||||
write("return ");
|
||||
emit(node.body);
|
||||
emit(node.body, /*disableComments:*/ true);
|
||||
write(";");
|
||||
emitTrailingComments(node.body);
|
||||
}
|
||||
@@ -3504,7 +3508,6 @@ module ts {
|
||||
}
|
||||
|
||||
function emitClassDeclaration(node: ClassDeclaration) {
|
||||
emitLeadingComments(node);
|
||||
write("var ");
|
||||
emit(node.name);
|
||||
write(" = (function (");
|
||||
@@ -3554,7 +3557,6 @@ module ts {
|
||||
emitEnd(node);
|
||||
write(";");
|
||||
}
|
||||
emitTrailingComments(node);
|
||||
|
||||
function emitConstructorOfClass() {
|
||||
var saveTempCount = tempCount;
|
||||
@@ -3633,13 +3635,17 @@ module ts {
|
||||
emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
|
||||
function shouldEmitEnumDeclaration(node: EnumDeclaration) {
|
||||
var isConstEnum = isConst(node);
|
||||
return !isConstEnum || compilerOptions.preserveConstEnums;
|
||||
}
|
||||
|
||||
function emitEnumDeclaration(node: EnumDeclaration) {
|
||||
// const enums are completely erased during compilation.
|
||||
var isConstEnum = isConst(node);
|
||||
if (isConstEnum && !compilerOptions.preserveConstEnums) {
|
||||
if (!shouldEmitEnumDeclaration(node)) {
|
||||
return;
|
||||
}
|
||||
emitLeadingComments(node);
|
||||
|
||||
if (!(node.flags & NodeFlags.Export)) {
|
||||
emitStart(node);
|
||||
write("var ");
|
||||
@@ -3656,7 +3662,7 @@ module ts {
|
||||
write(") {");
|
||||
increaseIndent();
|
||||
scopeEmitStart(node);
|
||||
emitEnumMemberDeclarations(isConstEnum);
|
||||
emitLines(node.members);
|
||||
decreaseIndent();
|
||||
writeLine();
|
||||
emitToken(SyntaxKind.CloseBraceToken, node.members.end);
|
||||
@@ -3677,32 +3683,27 @@ module ts {
|
||||
emitEnd(node);
|
||||
write(";");
|
||||
}
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitEnumMemberDeclarations(isConstEnum: boolean) {
|
||||
forEach(node.members, member => {
|
||||
writeLine();
|
||||
emitLeadingComments(member);
|
||||
emitStart(member);
|
||||
write(resolver.getLocalNameOfContainer(node));
|
||||
write("[");
|
||||
write(resolver.getLocalNameOfContainer(node));
|
||||
write("[");
|
||||
emitExpressionForPropertyName(member.name);
|
||||
write("] = ");
|
||||
if (member.initializer && !isConstEnum) {
|
||||
emit(member.initializer);
|
||||
}
|
||||
else {
|
||||
write(resolver.getEnumMemberValue(member).toString());
|
||||
}
|
||||
write("] = ");
|
||||
emitExpressionForPropertyName(member.name);
|
||||
emitEnd(member);
|
||||
write(";");
|
||||
emitTrailingComments(member);
|
||||
});
|
||||
function emitEnumMember(node: EnumMember) {
|
||||
var enumParent = <EnumDeclaration>node.parent;
|
||||
emitStart(node);
|
||||
write(resolver.getLocalNameOfContainer(enumParent));
|
||||
write("[");
|
||||
write(resolver.getLocalNameOfContainer(enumParent));
|
||||
write("[");
|
||||
emitExpressionForPropertyName(node.name);
|
||||
write("] = ");
|
||||
if (node.initializer && !isConst(enumParent)) {
|
||||
emit(node.initializer);
|
||||
}
|
||||
else {
|
||||
write(resolver.getEnumMemberValue(node).toString());
|
||||
}
|
||||
write("] = ");
|
||||
emitExpressionForPropertyName(node.name);
|
||||
emitEnd(node);
|
||||
write(";");
|
||||
}
|
||||
|
||||
function getInnerMostModuleDeclarationFromDottedModule(moduleDeclaration: ModuleDeclaration): ModuleDeclaration {
|
||||
@@ -3712,14 +3713,18 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function shouldEmitModuleDeclaration(node: ModuleDeclaration) {
|
||||
return isInstantiatedModule(node, compilerOptions.preserveConstEnums);
|
||||
}
|
||||
|
||||
function emitModuleDeclaration(node: ModuleDeclaration) {
|
||||
// Emit only if this module is non-ambient.
|
||||
var shouldEmit = isInstantiatedModule(node, compilerOptions.preserveConstEnums);
|
||||
var shouldEmit = shouldEmitModuleDeclaration(node);
|
||||
|
||||
if (!shouldEmit) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
emitLeadingComments(node);
|
||||
|
||||
emitStart(node);
|
||||
write("var ");
|
||||
emit(node.name);
|
||||
@@ -3764,7 +3769,6 @@ module ts {
|
||||
emitModuleMemberName(node);
|
||||
write(" = {}));");
|
||||
emitEnd(node);
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
|
||||
function emitImportDeclaration(node: ImportDeclaration) {
|
||||
@@ -3954,7 +3958,7 @@ module ts {
|
||||
emitLeadingComments(node.endOfFileToken);
|
||||
}
|
||||
|
||||
function emitNode(node: Node): void {
|
||||
function emitNode(node: Node, disableComments?:boolean): void {
|
||||
if (!node) {
|
||||
return;
|
||||
}
|
||||
@@ -3962,6 +3966,46 @@ module ts {
|
||||
if (node.flags & NodeFlags.Ambient) {
|
||||
return emitPinnedOrTripleSlashComments(node);
|
||||
}
|
||||
|
||||
var emitComments = !disableComments && shouldEmitLeadingAndTrailingComments(node);
|
||||
if (emitComments) {
|
||||
emitLeadingComments(node);
|
||||
}
|
||||
|
||||
emitJavaScriptWorker(node);
|
||||
|
||||
if (emitComments) {
|
||||
emitTrailingComments(node);
|
||||
}
|
||||
}
|
||||
|
||||
function shouldEmitLeadingAndTrailingComments(node: Node) {
|
||||
switch (node.kind) {
|
||||
// All of these entities are emitted in a specialized fashion. As such, we allow
|
||||
// the specilized methods for each to handle the comments on the nodes.
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
case SyntaxKind.ExportAssignment:
|
||||
return false;
|
||||
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
// Only emit the leading/trailing comments for a module if we're actually
|
||||
// emitting the module as well.
|
||||
return shouldEmitModuleDeclaration(<ModuleDeclaration>node);
|
||||
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
// Only emit the leading/trailing comments for an enum if we're actually
|
||||
// emitting the module as well.
|
||||
return shouldEmitEnumDeclaration(<EnumDeclaration>node);
|
||||
}
|
||||
|
||||
// Emit comments for everything else.
|
||||
return true;
|
||||
}
|
||||
|
||||
function emitJavaScriptWorker(node: Node) {
|
||||
// Check if the node can be emitted regardless of the ScriptTarget
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
@@ -4099,6 +4143,8 @@ module ts {
|
||||
return emitInterfaceDeclaration(<InterfaceDeclaration>node);
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
return emitEnumDeclaration(<EnumDeclaration>node);
|
||||
case SyntaxKind.EnumMember:
|
||||
return emitEnumMember(<EnumMember>node);
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
return emitModuleDeclaration(<ModuleDeclaration>node);
|
||||
case SyntaxKind.ImportDeclaration:
|
||||
@@ -4128,17 +4174,19 @@ module ts {
|
||||
|
||||
function getLeadingCommentsToEmit(node: Node) {
|
||||
// Emit the leading comments only if the parent's pos doesn't match because parent should take care of emitting these comments
|
||||
if (node.parent.kind === SyntaxKind.SourceFile || node.pos !== node.parent.pos) {
|
||||
var leadingComments: CommentRange[];
|
||||
if (hasDetachedComments(node.pos)) {
|
||||
// get comments without detached comments
|
||||
leadingComments = getLeadingCommentsWithoutDetachedComments();
|
||||
if (node.parent) {
|
||||
if (node.parent.kind === SyntaxKind.SourceFile || node.pos !== node.parent.pos) {
|
||||
var leadingComments: CommentRange[];
|
||||
if (hasDetachedComments(node.pos)) {
|
||||
// get comments without detached comments
|
||||
leadingComments = getLeadingCommentsWithoutDetachedComments();
|
||||
}
|
||||
else {
|
||||
// get the leading comments from the node
|
||||
leadingComments = getLeadingCommentRangesOfNode(node, currentSourceFile);
|
||||
}
|
||||
return leadingComments;
|
||||
}
|
||||
else {
|
||||
// get the leading comments from the node
|
||||
leadingComments = getLeadingCommentRangesOfNode(node, currentSourceFile);
|
||||
}
|
||||
return leadingComments;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4151,10 +4199,12 @@ module ts {
|
||||
|
||||
function emitTrailingDeclarationComments(node: Node) {
|
||||
// Emit the trailing comments only if the parent's end doesn't match
|
||||
if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) {
|
||||
var trailingComments = getTrailingCommentRanges(currentSourceFile.text, node.end);
|
||||
// trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/
|
||||
emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment);
|
||||
if (node.parent) {
|
||||
if (node.parent.kind === SyntaxKind.SourceFile || node.end !== node.parent.end) {
|
||||
var trailingComments = getTrailingCommentRanges(currentSourceFile.text, node.end);
|
||||
// trailing comments are emitted at space/*trailing comment1 */space/*trailing comment*/
|
||||
emitComments(currentSourceFile, writer, trailingComments, /*trailingSeparator*/ false, newLine, writeComment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+28
-18
@@ -330,6 +330,12 @@ module ts {
|
||||
HasAggregatedChildData = 1 << 6
|
||||
}
|
||||
|
||||
export const enum RelationComparisonResult {
|
||||
Succeeded = 1, // Should be truthy
|
||||
Failed = 2,
|
||||
FailedAndReported = 3
|
||||
}
|
||||
|
||||
export interface Node extends TextRange {
|
||||
kind: SyntaxKind;
|
||||
flags: NodeFlags;
|
||||
@@ -1266,29 +1272,33 @@ module ts {
|
||||
}
|
||||
|
||||
export const enum TypeFlags {
|
||||
Any = 0x00000001,
|
||||
String = 0x00000002,
|
||||
Number = 0x00000004,
|
||||
Boolean = 0x00000008,
|
||||
Void = 0x00000010,
|
||||
Undefined = 0x00000020,
|
||||
Null = 0x00000040,
|
||||
Enum = 0x00000080, // Enum type
|
||||
StringLiteral = 0x00000100, // String literal type
|
||||
TypeParameter = 0x00000200, // Type parameter
|
||||
Class = 0x00000400, // Class
|
||||
Interface = 0x00000800, // Interface
|
||||
Reference = 0x00001000, // Generic type reference
|
||||
Tuple = 0x00002000, // Tuple
|
||||
Union = 0x00004000, // Union
|
||||
Anonymous = 0x00008000, // Anonymous
|
||||
FromSignature = 0x00010000, // Created for signature assignment check
|
||||
Unwidened = 0x00020000, // Unwidened type (is or contains Undefined or Null type)
|
||||
Any = 0x00000001,
|
||||
String = 0x00000002,
|
||||
Number = 0x00000004,
|
||||
Boolean = 0x00000008,
|
||||
Void = 0x00000010,
|
||||
Undefined = 0x00000020,
|
||||
Null = 0x00000040,
|
||||
Enum = 0x00000080, // Enum type
|
||||
StringLiteral = 0x00000100, // String literal type
|
||||
TypeParameter = 0x00000200, // Type parameter
|
||||
Class = 0x00000400, // Class
|
||||
Interface = 0x00000800, // Interface
|
||||
Reference = 0x00001000, // Generic type reference
|
||||
Tuple = 0x00002000, // Tuple
|
||||
Union = 0x00004000, // Union
|
||||
Anonymous = 0x00008000, // Anonymous
|
||||
FromSignature = 0x00010000, // Created for signature assignment check
|
||||
ObjectLiteral = 0x00020000, // Originates in an object literal
|
||||
ContainsUndefinedOrNull = 0x00040000, // Type is or contains Undefined or Null type
|
||||
ContainsObjectLiteral = 0x00080000, // Type is or contains object literal type
|
||||
|
||||
Intrinsic = Any | String | Number | Boolean | Void | Undefined | Null,
|
||||
Primitive = String | Number | Boolean | Void | Undefined | Null | StringLiteral | Enum,
|
||||
StringLike = String | StringLiteral,
|
||||
NumberLike = Number | Enum,
|
||||
ObjectType = Class | Interface | Reference | Tuple | Anonymous,
|
||||
RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral
|
||||
}
|
||||
|
||||
// Properties common to all types
|
||||
|
||||
@@ -399,6 +399,21 @@ module ts {
|
||||
return undefined;
|
||||
}
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
// If the grandparent node is an object literal (as opposed to a class),
|
||||
// then the computed property is not a 'this' container.
|
||||
// A computed property name in a class needs to be a this container
|
||||
// so that we can error on it.
|
||||
if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
|
||||
return node;
|
||||
}
|
||||
// If this is a computed property, then the parent should not
|
||||
// make it a this container. The parent might be a property
|
||||
// in an object literal, like a method or accessor. But in order for
|
||||
// such a parent to be a this container, the reference must be in
|
||||
// the *body* of the container.
|
||||
node = node.parent;
|
||||
break;
|
||||
case SyntaxKind.ArrowFunction:
|
||||
if (!includeArrowFunctions) {
|
||||
continue;
|
||||
@@ -421,13 +436,32 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function getSuperContainer(node: Node): Node {
|
||||
export function getSuperContainer(node: Node, includeFunctions: boolean): Node {
|
||||
while (true) {
|
||||
node = node.parent;
|
||||
if (!node) {
|
||||
return undefined;
|
||||
}
|
||||
if (!node) return node;
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
// If the grandparent node is an object literal (as opposed to a class),
|
||||
// then the computed property is not a 'super' container.
|
||||
// A computed property name in a class needs to be a super container
|
||||
// so that we can error on it.
|
||||
if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
|
||||
return node;
|
||||
}
|
||||
// If this is a computed property, then the parent should not
|
||||
// make it a super container. The parent might be a property
|
||||
// in an object literal, like a method or accessor. But in order for
|
||||
// such a parent to be a super container, the reference must be in
|
||||
// the *body* of the container.
|
||||
node = node.parent;
|
||||
break;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
if (!includeFunctions) {
|
||||
continue;
|
||||
}
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.PropertySignature:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
@@ -527,6 +561,8 @@ module ts {
|
||||
return node === (<TypeAssertion>parent).expression;
|
||||
case SyntaxKind.TemplateSpan:
|
||||
return node === (<TemplateSpan>parent).expression;
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
return node === (<ComputedPropertyName>parent).expression;
|
||||
default:
|
||||
if (isExpression(parent)) {
|
||||
return true;
|
||||
|
||||
@@ -548,6 +548,18 @@ module FourSlash {
|
||||
}
|
||||
}
|
||||
|
||||
public verifyGetEmitOutputForCurrentFile(expected: string): void {
|
||||
var emit = this.languageService.getEmitOutput(this.activeFile.fileName);
|
||||
if (emit.outputFiles.length !== 1) {
|
||||
throw new Error("Expected exactly one output from emit of " + this.activeFile.fileName);
|
||||
}
|
||||
this.taoInvalidReason = 'verifyGetEmitOutputForCurrentFile impossible';
|
||||
var actual = emit.outputFiles[0].text;
|
||||
if (actual !== expected) {
|
||||
this.raiseError("Expected emit output to be '" + expected + "', but got '" + actual + "'");
|
||||
}
|
||||
}
|
||||
|
||||
public verifyMemberListContains(symbol: string, text?: string, documentation?: string, kind?: string) {
|
||||
this.scenarioActions.push('<ShowCompletionList />');
|
||||
this.scenarioActions.push('<VerifyCompletionContainsItem ItemName="' + symbol + '"/>');
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='references.ts' />
|
||||
|
||||
module TypeScript {
|
||||
export interface Logger {
|
||||
log(s: string): void;
|
||||
}
|
||||
|
||||
export class NullLogger implements Logger {
|
||||
public log(s: string): void {
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,266 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path="references.ts" />
|
||||
|
||||
module TypeScript {
|
||||
export interface IOptions {
|
||||
name?: string;
|
||||
flag?: boolean;
|
||||
short?: string;
|
||||
usage?: {
|
||||
locCode: string; // DiagnosticCode
|
||||
args: string[]
|
||||
};
|
||||
set?: (s: string) => void;
|
||||
type?: string; // DiagnosticCode
|
||||
experimental?: boolean;
|
||||
}
|
||||
|
||||
export class OptionsParser {
|
||||
private DEFAULT_SHORT_FLAG = "-";
|
||||
private DEFAULT_LONG_FLAG = "--";
|
||||
|
||||
private printedVersion: boolean = false;
|
||||
|
||||
// Find the option record for the given string. Returns null if not found.
|
||||
private findOption(arg: string) {
|
||||
var upperCaseArg = arg && arg.toUpperCase();
|
||||
|
||||
for (var i = 0; i < this.options.length; i++) {
|
||||
var current = this.options[i];
|
||||
|
||||
if (upperCaseArg === (current.short && current.short.toUpperCase()) ||
|
||||
upperCaseArg === (current.name && current.name.toUpperCase())) {
|
||||
return current;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public unnamed: string[] = [];
|
||||
|
||||
public options: IOptions[] = [];
|
||||
|
||||
constructor(public host: IEnvironment, public version: string) {
|
||||
}
|
||||
|
||||
public printUsage() {
|
||||
this.printVersion();
|
||||
|
||||
var optionsWord = getLocalizedText(DiagnosticCode.options, null);
|
||||
var fileWord = getLocalizedText(DiagnosticCode.file1, null);
|
||||
var tscSyntax = "tsc [" + optionsWord + "] [" + fileWord + " ..]";
|
||||
var syntaxHelp = getLocalizedText(DiagnosticCode.Syntax_0, [tscSyntax]);
|
||||
this.host.standardOut.WriteLine(syntaxHelp);
|
||||
this.host.standardOut.WriteLine("");
|
||||
this.host.standardOut.WriteLine(getLocalizedText(DiagnosticCode.Examples, null) + " tsc hello.ts");
|
||||
this.host.standardOut.WriteLine(" tsc --out foo.js foo.ts");
|
||||
this.host.standardOut.WriteLine(" tsc @args.txt");
|
||||
this.host.standardOut.WriteLine("");
|
||||
this.host.standardOut.WriteLine(getLocalizedText(DiagnosticCode.Options, null));
|
||||
|
||||
var output: string[][] = [];
|
||||
var maxLength = 0;
|
||||
var i = 0;
|
||||
|
||||
this.options = this.options.sort(function (a, b) {
|
||||
var aName = a.name.toLowerCase();
|
||||
var bName = b.name.toLowerCase();
|
||||
|
||||
if (aName > bName) {
|
||||
return 1;
|
||||
} else if (aName < bName) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
|
||||
// Build up output array
|
||||
for (i = 0; i < this.options.length; i++) {
|
||||
var option = this.options[i];
|
||||
|
||||
if (option.experimental) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!option.usage) {
|
||||
break;
|
||||
}
|
||||
|
||||
var usageString = " ";
|
||||
var type = option.type ? (" " + TypeScript.getLocalizedText(option.type, null)) : "";
|
||||
|
||||
if (option.short) {
|
||||
usageString += this.DEFAULT_SHORT_FLAG + option.short + type + ", ";
|
||||
}
|
||||
|
||||
usageString += this.DEFAULT_LONG_FLAG + option.name + type;
|
||||
|
||||
output.push([usageString, TypeScript.getLocalizedText(option.usage.locCode, option.usage.args)]);
|
||||
|
||||
if (usageString.length > maxLength) {
|
||||
maxLength = usageString.length;
|
||||
}
|
||||
}
|
||||
|
||||
var fileDescription = getLocalizedText(DiagnosticCode.Insert_command_line_options_and_files_from_a_file, null);
|
||||
output.push([" @<" + fileWord + ">", fileDescription]);
|
||||
|
||||
// Print padded output
|
||||
for (i = 0; i < output.length; i++) {
|
||||
this.host.standardOut.WriteLine(output[i][0] + (new Array(maxLength - output[i][0].length + 3)).join(" ") + output[i][1]);
|
||||
}
|
||||
}
|
||||
|
||||
public printVersion() {
|
||||
if (!this.printedVersion) {
|
||||
this.host.standardOut.WriteLine(getLocalizedText(DiagnosticCode.Version_0, [this.version]));
|
||||
this.printedVersion = true;
|
||||
}
|
||||
}
|
||||
|
||||
public option(name: string, config: IOptions, short?: string) {
|
||||
if (!config) {
|
||||
config = <any>short;
|
||||
short = null;
|
||||
}
|
||||
|
||||
config.name = name;
|
||||
config.short = short;
|
||||
config.flag = false;
|
||||
|
||||
this.options.push(config);
|
||||
}
|
||||
|
||||
public flag(name: string, config: IOptions, short?: string) {
|
||||
if (!config) {
|
||||
config = <any>short;
|
||||
short = null;
|
||||
}
|
||||
|
||||
config.name = name;
|
||||
config.short = short;
|
||||
config.flag = true;
|
||||
|
||||
this.options.push(config);
|
||||
}
|
||||
|
||||
// Parse an arguments string
|
||||
public parseString(argString: string) {
|
||||
var position = 0;
|
||||
var tokens = argString.match(/\s+|"|[^\s"]+/g);
|
||||
|
||||
function peek() {
|
||||
return tokens[position];
|
||||
}
|
||||
|
||||
function consume() {
|
||||
return tokens[position++];
|
||||
}
|
||||
|
||||
function consumeQuotedString() {
|
||||
var value = '';
|
||||
consume(); // skip opening quote.
|
||||
|
||||
var token = peek();
|
||||
|
||||
while (token && token !== '"') {
|
||||
consume();
|
||||
|
||||
value += token;
|
||||
|
||||
token = peek();
|
||||
}
|
||||
|
||||
consume(); // skip ending quote;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
var args: string[] = [];
|
||||
var currentArg = '';
|
||||
|
||||
while (position < tokens.length) {
|
||||
var token = peek();
|
||||
|
||||
if (token === '"') {
|
||||
currentArg += consumeQuotedString();
|
||||
} else if (token.match(/\s/)) {
|
||||
if (currentArg.length > 0) {
|
||||
args.push(currentArg);
|
||||
currentArg = '';
|
||||
}
|
||||
|
||||
consume();
|
||||
} else {
|
||||
consume();
|
||||
currentArg += token;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentArg.length > 0) {
|
||||
args.push(currentArg);
|
||||
}
|
||||
|
||||
this.parse(args);
|
||||
}
|
||||
|
||||
// Parse arguments as they come from the platform: split into arguments.
|
||||
public parse(args: string[]) {
|
||||
var position = 0;
|
||||
|
||||
function consume() {
|
||||
return args[position++];
|
||||
}
|
||||
|
||||
while (position < args.length) {
|
||||
var current = consume();
|
||||
var match = current.match(/^(--?|@)(.*)/);
|
||||
var value: any = null;
|
||||
|
||||
if (match) {
|
||||
if (match[1] === '@') {
|
||||
this.parseString(this.host.readFile(match[2], null).contents);
|
||||
} else {
|
||||
var arg = match[2];
|
||||
var option = this.findOption(arg);
|
||||
|
||||
if (option === null) {
|
||||
this.host.standardOut.WriteLine(getDiagnosticMessage(DiagnosticCode.Unknown_compiler_option_0, [arg]));
|
||||
this.host.standardOut.WriteLine(getLocalizedText(DiagnosticCode.Use_the_0_flag_to_see_options, ["--help"]));
|
||||
} else {
|
||||
if (!option.flag) {
|
||||
value = consume();
|
||||
if (value === undefined) {
|
||||
// No value provided
|
||||
this.host.standardOut.WriteLine(getDiagnosticMessage(DiagnosticCode.Option_0_specified_without_1, [arg, getLocalizedText(option.type, null)]));
|
||||
this.host.standardOut.WriteLine(getLocalizedText(DiagnosticCode.Use_the_0_flag_to_see_options, ["--help"]));
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
option.set(value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.unnamed.push(current);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,736 +0,0 @@
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
///<reference path='typescript.ts'/>
|
||||
///<reference path='io.ts'/>
|
||||
///<reference path='optionsParser.ts'/>
|
||||
|
||||
module TypeScript {
|
||||
class SourceFile {
|
||||
constructor(public scriptSnapshot: IScriptSnapshot, public byteOrderMark: ByteOrderMark) {
|
||||
}
|
||||
}
|
||||
|
||||
class DiagnosticsLogger implements ILogger {
|
||||
constructor(public ioHost: IEnvironment) {
|
||||
}
|
||||
public information(): boolean { return false; }
|
||||
public debug(): boolean { return false; }
|
||||
public warning(): boolean { return false; }
|
||||
public error(): boolean { return false; }
|
||||
public fatal(): boolean { return false; }
|
||||
public log(s: string): void {
|
||||
this.ioHost.standardOut.WriteLine(s);
|
||||
}
|
||||
}
|
||||
|
||||
export class BatchCompiler implements IReferenceResolverHost {
|
||||
public compilerVersion = "1.0.1.0";
|
||||
private inputFiles: string[] = [];
|
||||
private compilationSettings: ImmutableCompilationSettings;
|
||||
private resolvedFiles: IResolvedFile[] = [];
|
||||
private fileNameToSourceFile = new StringHashTable<SourceFile>();
|
||||
private hasErrors: boolean = false;
|
||||
private logger: ILogger = null;
|
||||
|
||||
constructor(private ioHost: IEnvironment) {
|
||||
}
|
||||
|
||||
// Begin batch compilation
|
||||
public batchCompile() {
|
||||
// Parse command line options
|
||||
if (this.parseOptions()) {
|
||||
var start = new Date().getTime();
|
||||
|
||||
if (this.compilationSettings.gatherDiagnostics()) {
|
||||
this.logger = new DiagnosticsLogger(this.ioHost);
|
||||
} else {
|
||||
this.logger = new NullLogger();
|
||||
}
|
||||
|
||||
if (this.compilationSettings.watch()) {
|
||||
// Watch will cause the program to stick around as long as the files exist
|
||||
this.watchFiles();
|
||||
return;
|
||||
}
|
||||
|
||||
// Resolve the compilation environemnt
|
||||
this.resolve();
|
||||
|
||||
this.compile();
|
||||
|
||||
if (this.compilationSettings.gatherDiagnostics()) {
|
||||
this.logger.log("");
|
||||
this.logger.log("File resolution time: " + TypeScript.fileResolutionTime);
|
||||
this.logger.log(" file read: " + TypeScript.fileResolutionIOTime);
|
||||
this.logger.log(" scan imports: " + TypeScript.fileResolutionScanImportsTime);
|
||||
this.logger.log(" import search: " + TypeScript.fileResolutionImportFileSearchTime);
|
||||
this.logger.log(" get lib.d.ts: " + TypeScript.fileResolutionGetDefaultLibraryTime);
|
||||
|
||||
this.logger.log("SyntaxTree parse time: " + TypeScript.syntaxTreeParseTime);
|
||||
this.logger.log("Syntax Diagnostics time: " + TypeScript.syntaxDiagnosticsTime);
|
||||
this.logger.log("Create declarations time: " + TypeScript.createDeclarationsTime);
|
||||
this.logger.log("");
|
||||
this.logger.log("Type check time: " + TypeScript.typeCheckTime);
|
||||
this.logger.log("");
|
||||
this.logger.log("Emit time: " + TypeScript.emitTime);
|
||||
this.logger.log("Declaration emit time: " + TypeScript.declarationEmitTime);
|
||||
|
||||
this.logger.log("Total number of symbols created: " + TypeScript.pullSymbolID);
|
||||
this.logger.log("Specialized types created: " + TypeScript.nSpecializationsCreated);
|
||||
this.logger.log("Specialized signatures created: " + TypeScript.nSpecializedSignaturesCreated);
|
||||
|
||||
this.logger.log(" IsExternallyVisibleTime: " + TypeScript.declarationEmitIsExternallyVisibleTime);
|
||||
this.logger.log(" TypeSignatureTime: " + TypeScript.declarationEmitTypeSignatureTime);
|
||||
this.logger.log(" GetBoundDeclTypeTime: " + TypeScript.declarationEmitGetBoundDeclTypeTime);
|
||||
this.logger.log(" IsOverloadedCallSignatureTime: " + TypeScript.declarationEmitIsOverloadedCallSignatureTime);
|
||||
this.logger.log(" FunctionDeclarationGetSymbolTime: " + TypeScript.declarationEmitFunctionDeclarationGetSymbolTime);
|
||||
this.logger.log(" GetBaseTypeTime: " + TypeScript.declarationEmitGetBaseTypeTime);
|
||||
this.logger.log(" GetAccessorFunctionTime: " + TypeScript.declarationEmitGetAccessorFunctionTime);
|
||||
this.logger.log(" GetTypeParameterSymbolTime: " + TypeScript.declarationEmitGetTypeParameterSymbolTime);
|
||||
this.logger.log(" GetImportDeclarationSymbolTime: " + TypeScript.declarationEmitGetImportDeclarationSymbolTime);
|
||||
|
||||
this.logger.log("Emit write file time: " + TypeScript.emitWriteFileTime);
|
||||
|
||||
this.logger.log("Compiler resolve path time: " + TypeScript.compilerResolvePathTime);
|
||||
this.logger.log("Compiler directory name time: " + TypeScript.compilerDirectoryNameTime);
|
||||
this.logger.log("Compiler directory exists time: " + TypeScript.compilerDirectoryExistsTime);
|
||||
this.logger.log("Compiler file exists time: " + TypeScript.compilerFileExistsTime);
|
||||
|
||||
this.logger.log("IO host resolve path time: " + TypeScript.ioHostResolvePathTime);
|
||||
this.logger.log("IO host directory name time: " + TypeScript.ioHostDirectoryNameTime);
|
||||
this.logger.log("IO host create directory structure time: " + TypeScript.ioHostCreateDirectoryStructureTime);
|
||||
this.logger.log("IO host write file time: " + TypeScript.ioHostWriteFileTime);
|
||||
|
||||
this.logger.log("Node make directory time: " + TypeScript.nodeMakeDirectoryTime);
|
||||
this.logger.log("Node writeFileSync time: " + TypeScript.nodeWriteFileSyncTime);
|
||||
this.logger.log("Node createBuffer time: " + TypeScript.nodeCreateBufferTime);
|
||||
|
||||
this.logger.log("Total time: " + (new Date().getTime() - start));
|
||||
}
|
||||
}
|
||||
|
||||
// Exit with the appropriate error code
|
||||
this.ioHost.quit(this.hasErrors ? 1 : 0);
|
||||
}
|
||||
|
||||
private resolve() {
|
||||
// Resolve file dependencies, if requested
|
||||
var includeDefaultLibrary = !this.compilationSettings.noLib();
|
||||
var resolvedFiles: IResolvedFile[] = [];
|
||||
|
||||
var start = new Date().getTime();
|
||||
|
||||
if (!this.compilationSettings.noResolve()) {
|
||||
// Resolve references
|
||||
var resolutionResults = ReferenceResolver.resolve(this.inputFiles, this, this.compilationSettings.useCaseSensitiveFileResolution());
|
||||
resolvedFiles = resolutionResults.resolvedFiles;
|
||||
|
||||
// Only include the library if useDefaultLib is set to true and did not see any 'no-default-lib' comments
|
||||
includeDefaultLibrary = !this.compilationSettings.noLib() && !resolutionResults.seenNoDefaultLibTag;
|
||||
|
||||
// Populate any diagnostic messages generated during resolution
|
||||
resolutionResults.diagnostics.forEach(d => this.addDiagnostic(d));
|
||||
}
|
||||
else {
|
||||
for (var i = 0, n = this.inputFiles.length; i < n; i++) {
|
||||
var inputFile = this.inputFiles[i];
|
||||
var referencedFiles: string[] = [];
|
||||
var importedFiles: string[] = [];
|
||||
|
||||
// If declaration files are going to be emitted, preprocess the file contents and add in referenced files as well
|
||||
if (this.compilationSettings.generateDeclarationFiles()) {
|
||||
var references = getReferencedFiles(inputFile, this.getScriptSnapshot(inputFile));
|
||||
for (var j = 0; j < references.length; j++) {
|
||||
referencedFiles.push(references[j].path);
|
||||
}
|
||||
|
||||
inputFile = this.resolvePath(inputFile);
|
||||
}
|
||||
|
||||
resolvedFiles.push({
|
||||
path: inputFile,
|
||||
referencedFiles: referencedFiles,
|
||||
importedFiles: importedFiles
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var defaultLibStart = new Date().getTime();
|
||||
if (includeDefaultLibrary) {
|
||||
var libraryResolvedFile: IResolvedFile = {
|
||||
path: this.getDefaultLibraryFilePath(),
|
||||
referencedFiles: [],
|
||||
importedFiles: []
|
||||
};
|
||||
|
||||
// Prepend the library to the resolved list
|
||||
resolvedFiles = [libraryResolvedFile].concat(resolvedFiles);
|
||||
}
|
||||
TypeScript.fileResolutionGetDefaultLibraryTime += new Date().getTime() - defaultLibStart;
|
||||
|
||||
this.resolvedFiles = resolvedFiles;
|
||||
|
||||
TypeScript.fileResolutionTime = new Date().getTime() - start;
|
||||
}
|
||||
|
||||
// Returns true if compilation failed from some reason.
|
||||
private compile(): void {
|
||||
var compiler = new TypeScriptCompiler(this.logger, this.compilationSettings);
|
||||
|
||||
this.resolvedFiles.forEach(resolvedFile => {
|
||||
var sourceFile = this.getSourceFile(resolvedFile.path);
|
||||
compiler.addFile(resolvedFile.path, sourceFile.scriptSnapshot, sourceFile.byteOrderMark, /*version:*/ 0, /*isOpen:*/ false, resolvedFile.referencedFiles);
|
||||
});
|
||||
|
||||
for (var it = compiler.compile((path: string) => this.resolvePath(path)); it.moveNext();) {
|
||||
var result = it.current();
|
||||
|
||||
result.diagnostics.forEach(d => this.addDiagnostic(d));
|
||||
if (!this.tryWriteOutputFiles(result.outputFiles)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Parse command line options
|
||||
private parseOptions() {
|
||||
var opts = new OptionsParser(this.ioHost, this.compilerVersion);
|
||||
|
||||
var mutableSettings = new CompilationSettings();
|
||||
opts.option('out', {
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Concatenate_and_emit_output_to_single_file,
|
||||
args: null
|
||||
},
|
||||
type: DiagnosticCode.file2,
|
||||
set: (str) => {
|
||||
mutableSettings.outFileOption = str;
|
||||
}
|
||||
});
|
||||
|
||||
opts.option('outDir', {
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Redirect_output_structure_to_the_directory,
|
||||
args: null
|
||||
},
|
||||
type: DiagnosticCode.DIRECTORY,
|
||||
set: (str) => {
|
||||
mutableSettings.outDirOption = str;
|
||||
}
|
||||
});
|
||||
|
||||
opts.flag('sourcemap', {
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Generates_corresponding_0_file,
|
||||
args: ['.map']
|
||||
},
|
||||
set: () => {
|
||||
mutableSettings.mapSourceFiles = true;
|
||||
}
|
||||
});
|
||||
|
||||
opts.option('mapRoot', {
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations,
|
||||
args: null
|
||||
},
|
||||
type: DiagnosticCode.LOCATION,
|
||||
set: (str) => {
|
||||
mutableSettings.mapRoot = str;
|
||||
}
|
||||
});
|
||||
|
||||
opts.option('sourceRoot', {
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations,
|
||||
args: null
|
||||
},
|
||||
type: DiagnosticCode.LOCATION,
|
||||
set: (str) => {
|
||||
mutableSettings.sourceRoot = str;
|
||||
}
|
||||
});
|
||||
|
||||
opts.flag('declaration', {
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Generates_corresponding_0_file,
|
||||
args: ['.d.ts']
|
||||
},
|
||||
set: () => {
|
||||
mutableSettings.generateDeclarationFiles = true;
|
||||
}
|
||||
}, 'd');
|
||||
|
||||
if (this.ioHost.watchFile) {
|
||||
opts.flag('watch', {
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Watch_input_files,
|
||||
args: null
|
||||
},
|
||||
set: () => {
|
||||
mutableSettings.watch = true;
|
||||
}
|
||||
}, 'w');
|
||||
}
|
||||
|
||||
opts.flag('propagateEnumConstants', {
|
||||
experimental: true,
|
||||
set: () => { mutableSettings.propagateEnumConstants = true; }
|
||||
});
|
||||
|
||||
opts.flag('removeComments', {
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Do_not_emit_comments_to_output,
|
||||
args: null
|
||||
},
|
||||
set: () => {
|
||||
mutableSettings.removeComments = true;
|
||||
}
|
||||
});
|
||||
|
||||
opts.flag('noResolve', {
|
||||
experimental: true,
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Skip_resolution_and_preprocessing,
|
||||
args: null
|
||||
},
|
||||
set: () => {
|
||||
mutableSettings.noResolve = true;
|
||||
}
|
||||
});
|
||||
|
||||
opts.flag('noLib', {
|
||||
experimental: true,
|
||||
set: () => {
|
||||
mutableSettings.noLib = true;
|
||||
}
|
||||
});
|
||||
|
||||
opts.flag('diagnostics', {
|
||||
experimental: true,
|
||||
set: () => {
|
||||
mutableSettings.gatherDiagnostics = true;
|
||||
}
|
||||
});
|
||||
|
||||
opts.option('target', {
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Specify_ECMAScript_target_version_0_default_or_1,
|
||||
args: ['ES3', 'ES5']
|
||||
},
|
||||
type: DiagnosticCode.VERSION,
|
||||
set: (type) => {
|
||||
type = type.toLowerCase();
|
||||
|
||||
if (type === 'es3') {
|
||||
mutableSettings.codeGenTarget = LanguageVersion.EcmaScript3;
|
||||
}
|
||||
else if (type === 'es5') {
|
||||
mutableSettings.codeGenTarget = LanguageVersion.EcmaScript5;
|
||||
}
|
||||
else {
|
||||
this.addDiagnostic(
|
||||
new Diagnostic(null, null, 0, 0, DiagnosticCode.Argument_for_0_option_must_be_1_or_2, ["target", "ES3", "ES5"]));
|
||||
}
|
||||
}
|
||||
}, 't');
|
||||
|
||||
opts.option('module', {
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Specify_module_code_generation_0_or_1,
|
||||
args: ['commonjs', 'amd']
|
||||
},
|
||||
type: DiagnosticCode.KIND,
|
||||
set: (type) => {
|
||||
type = type.toLowerCase();
|
||||
|
||||
if (type === 'commonjs') {
|
||||
mutableSettings.moduleGenTarget = ModuleGenTarget.Synchronous;
|
||||
}
|
||||
else if (type === 'amd') {
|
||||
mutableSettings.moduleGenTarget = ModuleGenTarget.Asynchronous;
|
||||
}
|
||||
else {
|
||||
this.addDiagnostic(
|
||||
new Diagnostic(null, null, 0, 0, DiagnosticCode.Argument_for_0_option_must_be_1_or_2, ["module", "commonjs", "amd"]));
|
||||
}
|
||||
}
|
||||
}, 'm');
|
||||
|
||||
var needsHelp = false;
|
||||
opts.flag('help', {
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Print_this_message,
|
||||
args: null
|
||||
},
|
||||
set: () => {
|
||||
needsHelp = true;
|
||||
}
|
||||
}, 'h');
|
||||
|
||||
opts.flag('useCaseSensitiveFileResolution', {
|
||||
experimental: true,
|
||||
set: () => {
|
||||
mutableSettings.useCaseSensitiveFileResolution = true;
|
||||
}
|
||||
});
|
||||
var shouldPrintVersionOnly = false;
|
||||
opts.flag('version', {
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Print_the_compiler_s_version_0,
|
||||
args: [this.compilerVersion]
|
||||
},
|
||||
set: () => {
|
||||
shouldPrintVersionOnly = true;
|
||||
}
|
||||
}, 'v');
|
||||
|
||||
var locale: string = null;
|
||||
opts.option('locale', {
|
||||
experimental: true,
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Specify_locale_for_errors_and_messages_For_example_0_or_1,
|
||||
args: ['en', 'ja-jp']
|
||||
},
|
||||
type: DiagnosticCode.STRING,
|
||||
set: (value) => {
|
||||
locale = value;
|
||||
}
|
||||
});
|
||||
|
||||
opts.flag('noImplicitAny', {
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Raise_error_on_expressions_and_declarations_with_an_implied_any_type,
|
||||
args: null
|
||||
},
|
||||
set: () => {
|
||||
mutableSettings.noImplicitAny = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (Environment.supportsCodePage()) {
|
||||
opts.option('codepage', {
|
||||
usage: {
|
||||
locCode: DiagnosticCode.Specify_the_codepage_to_use_when_opening_source_files,
|
||||
args: null
|
||||
},
|
||||
type: DiagnosticCode.NUMBER,
|
||||
set: (arg) => {
|
||||
mutableSettings.codepage = parseInt(arg, 10);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
opts.parse(this.ioHost.arguments);
|
||||
|
||||
this.compilationSettings = ImmutableCompilationSettings.fromCompilationSettings(mutableSettings);
|
||||
|
||||
if (locale) {
|
||||
if (!this.setLocale(locale)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
this.inputFiles.push.apply(this.inputFiles, opts.unnamed);
|
||||
|
||||
if (shouldPrintVersionOnly) {
|
||||
opts.printVersion();
|
||||
return false;
|
||||
}
|
||||
// If no source files provided to compiler - print usage information
|
||||
else if (this.inputFiles.length === 0 || needsHelp) {
|
||||
opts.printUsage();
|
||||
return false;
|
||||
}
|
||||
|
||||
return !this.hasErrors;
|
||||
}
|
||||
|
||||
private setLocale(locale: string): boolean {
|
||||
var matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase());
|
||||
if (!matchResult) {
|
||||
this.addDiagnostic(new Diagnostic(null, null, 0, 0, DiagnosticCode.Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1, ['en', 'ja-jp']));
|
||||
return false;
|
||||
}
|
||||
|
||||
var language = matchResult[1];
|
||||
var territory = matchResult[3];
|
||||
|
||||
// First try the entire locale, then fall back to just language if that's all we have.
|
||||
if (!this.setLanguageAndTerritory(language, territory) &&
|
||||
!this.setLanguageAndTerritory(language, null)) {
|
||||
|
||||
this.addDiagnostic(new Diagnostic(null, null, 0, 0, DiagnosticCode.Unsupported_locale_0, [locale]));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private setLanguageAndTerritory(language: string, territory: string): boolean {
|
||||
|
||||
var compilerFilePath = this.ioHost.executingFilePath();
|
||||
var containingDirectoryPath = this.ioHost.directoryName(compilerFilePath);
|
||||
|
||||
var filePath = IOUtils.combine(containingDirectoryPath, language);
|
||||
if (territory) {
|
||||
filePath = filePath + "-" + territory;
|
||||
}
|
||||
|
||||
filePath = this.resolvePath(IOUtils.combine(filePath, "diagnosticMessages.generated.json"));
|
||||
|
||||
if (!this.fileExists(filePath)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var fileContents = this.ioHost.readFile(filePath, this.compilationSettings.codepage());
|
||||
TypeScript.LocalizedDiagnosticMessages = JSON.parse(fileContents.contents);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Handle -watch switch
|
||||
private watchFiles() {
|
||||
if (!this.ioHost.watchFile) {
|
||||
this.addDiagnostic(
|
||||
new Diagnostic(null, null, 0, 0, DiagnosticCode.Current_host_does_not_support_0_option, ['-w[atch]']));
|
||||
return;
|
||||
}
|
||||
|
||||
var lastResolvedFileSet: string[] = []
|
||||
var watchers: { [x: string]: IFileWatcher; } = {};
|
||||
var firstTime = true;
|
||||
|
||||
var addWatcher = (fileName: string) => {
|
||||
if (!watchers[fileName]) {
|
||||
var watcher = this.ioHost.watchFile(fileName, onWatchedFileChange);
|
||||
watchers[fileName] = watcher;
|
||||
}
|
||||
};
|
||||
|
||||
var removeWatcher = (fileName: string) => {
|
||||
if (watchers[fileName]) {
|
||||
watchers[fileName].close();
|
||||
delete watchers[fileName];
|
||||
}
|
||||
};
|
||||
|
||||
var onWatchedFileChange = () => {
|
||||
// Clean errors for previous compilation
|
||||
this.hasErrors = false;
|
||||
|
||||
// Clear out any source file data we've cached.
|
||||
this.fileNameToSourceFile = new StringHashTable<SourceFile>();
|
||||
|
||||
// Resolve file dependencies, if requested
|
||||
this.resolve();
|
||||
|
||||
// Check if any new files were added to the environment as a result of the file change
|
||||
var oldFiles = lastResolvedFileSet;
|
||||
var newFiles = this.resolvedFiles.map(resolvedFile => resolvedFile.path).sort();
|
||||
|
||||
var i = 0, j = 0;
|
||||
while (i < oldFiles.length && j < newFiles.length) {
|
||||
|
||||
var compareResult = oldFiles[i].localeCompare(newFiles[j]);
|
||||
if (compareResult === 0) {
|
||||
// No change here
|
||||
i++;
|
||||
j++;
|
||||
}
|
||||
else if (compareResult < 0) {
|
||||
// Entry in old list does not exist in the new one, it was removed
|
||||
removeWatcher(oldFiles[i]);
|
||||
i++;
|
||||
}
|
||||
else {
|
||||
// Entry in new list does exist in the new one, it was added
|
||||
addWatcher(newFiles[j]);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
// All remaining unmatched items in the old list have been removed
|
||||
for (var k = i; k < oldFiles.length; k++) {
|
||||
removeWatcher(oldFiles[k]);
|
||||
}
|
||||
|
||||
// All remaing unmatched items in the new list have been added
|
||||
for (k = j; k < newFiles.length; k++) {
|
||||
addWatcher(newFiles[k]);
|
||||
}
|
||||
|
||||
// Update the state
|
||||
lastResolvedFileSet = newFiles;
|
||||
|
||||
// Print header
|
||||
if (!firstTime) {
|
||||
var fileNames = "";
|
||||
for (var k = 0; k < lastResolvedFileSet.length; k++) {
|
||||
fileNames += Environment.newLine + " " + lastResolvedFileSet[k];
|
||||
}
|
||||
this.ioHost.standardError.WriteLine(getLocalizedText(DiagnosticCode.NL_Recompiling_0, [fileNames]));
|
||||
}
|
||||
else {
|
||||
firstTime = false;
|
||||
}
|
||||
|
||||
// Trigger a new compilation
|
||||
this.compile();
|
||||
};
|
||||
|
||||
// Switch to using stdout for all error messages
|
||||
this.ioHost.standardOut = this.ioHost.standardOut;
|
||||
|
||||
onWatchedFileChange();
|
||||
}
|
||||
|
||||
private getSourceFile(fileName: string): SourceFile {
|
||||
var sourceFile: SourceFile = this.fileNameToSourceFile.lookup(fileName);
|
||||
if (!sourceFile) {
|
||||
// Attempt to read the file
|
||||
var fileInformation: FileInformation;
|
||||
|
||||
try {
|
||||
fileInformation = this.ioHost.readFile(fileName, this.compilationSettings.codepage());
|
||||
}
|
||||
catch (e) {
|
||||
this.addDiagnostic(new Diagnostic(null, null, 0, 0, DiagnosticCode.Cannot_read_file_0_1, [fileName, e.message]));
|
||||
fileInformation = new FileInformation("", ByteOrderMark.None);
|
||||
}
|
||||
|
||||
var snapshot = ScriptSnapshot.fromString(fileInformation.contents);
|
||||
var sourceFile = new SourceFile(snapshot, fileInformation.byteOrderMark);
|
||||
this.fileNameToSourceFile.add(fileName, sourceFile);
|
||||
}
|
||||
|
||||
return sourceFile;
|
||||
}
|
||||
|
||||
private getDefaultLibraryFilePath(): string {
|
||||
var compilerFilePath = this.ioHost.executingFilePath();
|
||||
var containingDirectoryPath = this.ioHost.directoryName(compilerFilePath);
|
||||
var libraryFilePath = this.resolvePath(IOUtils.combine(containingDirectoryPath, "lib.d.ts"));
|
||||
|
||||
return libraryFilePath;
|
||||
}
|
||||
|
||||
/// IReferenceResolverHost methods
|
||||
getScriptSnapshot(fileName: string): IScriptSnapshot {
|
||||
return this.getSourceFile(fileName).scriptSnapshot;
|
||||
}
|
||||
|
||||
resolveRelativePath(path: string, directory: string): string {
|
||||
var unQuotedPath = stripStartAndEndQuotes(path);
|
||||
var normalizedPath: string;
|
||||
|
||||
if (isRooted(unQuotedPath) || !directory) {
|
||||
normalizedPath = unQuotedPath;
|
||||
} else {
|
||||
normalizedPath = IOUtils.combine(directory, unQuotedPath);
|
||||
}
|
||||
|
||||
// get the absolute path
|
||||
normalizedPath = this.resolvePath(normalizedPath);
|
||||
|
||||
// Switch to forward slashes
|
||||
normalizedPath = switchToForwardSlashes(normalizedPath);
|
||||
|
||||
return normalizedPath;
|
||||
}
|
||||
|
||||
private fileExistsCache = createIntrinsicsObject<boolean>();
|
||||
|
||||
fileExists(path: string): boolean {
|
||||
var exists = this.fileExistsCache[path];
|
||||
if (exists === undefined) {
|
||||
var start = new Date().getTime();
|
||||
exists = this.ioHost.fileExists(path);
|
||||
this.fileExistsCache[path] = exists;
|
||||
TypeScript.compilerFileExistsTime += new Date().getTime() - start;
|
||||
}
|
||||
|
||||
return exists;
|
||||
}
|
||||
|
||||
getParentDirectory(path: string): string {
|
||||
var start = new Date().getTime();
|
||||
var result = this.ioHost.directoryName(path);
|
||||
TypeScript.compilerDirectoryNameTime += new Date().getTime() - start;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
private addDiagnostic(diagnostic: Diagnostic): void {
|
||||
var diagnosticInfo = diagnostic.info();
|
||||
if (diagnosticInfo.category === DiagnosticCategory.Error) {
|
||||
this.hasErrors = true;
|
||||
}
|
||||
|
||||
this.ioHost.standardError.Write(TypeScriptCompiler.getFullDiagnosticText(diagnostic, path => this.resolvePath(path)));
|
||||
}
|
||||
|
||||
private tryWriteOutputFiles(outputFiles: OutputFile[]): boolean {
|
||||
for (var i = 0, n = outputFiles.length; i < n; i++) {
|
||||
var outputFile = outputFiles[i];
|
||||
|
||||
try {
|
||||
this.writeFile(outputFile.name, outputFile.text, outputFile.writeByteOrderMark);
|
||||
}
|
||||
catch (e) {
|
||||
this.addDiagnostic(
|
||||
new Diagnostic(outputFile.name, null, 0, 0, DiagnosticCode.Emit_Error_0, [e.message]));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
writeFile(fileName: string, contents: string, writeByteOrderMark: boolean): void {
|
||||
var start = new Date().getTime();
|
||||
IOUtils.writeFileAndFolderStructure(this.ioHost, fileName, contents, writeByteOrderMark);
|
||||
TypeScript.emitWriteFileTime += new Date().getTime() - start;
|
||||
}
|
||||
|
||||
directoryExists(path: string): boolean {
|
||||
var start = new Date().getTime();
|
||||
var result = this.ioHost.directoryExists(path);
|
||||
TypeScript.compilerDirectoryExistsTime += new Date().getTime() - start;
|
||||
return result;
|
||||
}
|
||||
|
||||
// For performance reasons we cache the results of resolvePath. This avoids costly lookup
|
||||
// on the disk once we've already resolved a path once.
|
||||
private resolvePathCache = createIntrinsicsObject<string>();
|
||||
|
||||
resolvePath(path: string): string {
|
||||
var cachedValue = this.resolvePathCache[path];
|
||||
if (!cachedValue) {
|
||||
var start = new Date().getTime();
|
||||
cachedValue = this.ioHost.absolutePath(path);
|
||||
this.resolvePathCache[path] = cachedValue;
|
||||
TypeScript.compilerResolvePathTime += new Date().getTime() - start;
|
||||
}
|
||||
|
||||
return cachedValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Start the batch compilation using the current hosts IO
|
||||
var batch = new TypeScript.BatchCompiler(Environment);
|
||||
batch.batchCompile();
|
||||
}
|
||||
@@ -50,8 +50,9 @@ module ts.NavigationBar {
|
||||
case SyntaxKind.ArrayBindingPattern:
|
||||
forEach((<BindingPattern>node).elements, visit);
|
||||
break;
|
||||
case SyntaxKind.BindingElement:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
if (isBindingPattern(node)) {
|
||||
if (isBindingPattern((<VariableDeclaration>node).name)) {
|
||||
visit((<VariableDeclaration>node).name);
|
||||
break;
|
||||
}
|
||||
@@ -262,17 +263,34 @@ module ts.NavigationBar {
|
||||
return createItem(node, getTextOfNode((<FunctionLikeDeclaration>node).name), ts.ScriptElementKind.functionElement);
|
||||
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
if (isBindingPattern((<VariableDeclaration>node).name)) {
|
||||
break;
|
||||
}
|
||||
if (isConst(node)) {
|
||||
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.constElement);
|
||||
}
|
||||
else if (isLet(node)) {
|
||||
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.letElement);
|
||||
case SyntaxKind.BindingElement:
|
||||
var variableDeclarationNode: Node;
|
||||
var name: Node;
|
||||
|
||||
if (node.kind === SyntaxKind.BindingElement) {
|
||||
name = (<BindingElement>node).name;
|
||||
variableDeclarationNode = node;
|
||||
// binding elements are added only for variable declarations
|
||||
// bubble up to the containing variable declaration
|
||||
while (variableDeclarationNode && variableDeclarationNode.kind !== SyntaxKind.VariableDeclaration) {
|
||||
variableDeclarationNode = variableDeclarationNode.parent;
|
||||
}
|
||||
Debug.assert(variableDeclarationNode !== undefined);
|
||||
}
|
||||
else {
|
||||
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.variableElement);
|
||||
Debug.assert(!isBindingPattern((<VariableDeclaration>node).name));
|
||||
variableDeclarationNode = node;
|
||||
name = (<VariableDeclaration>node).name;
|
||||
}
|
||||
|
||||
if (isConst(variableDeclarationNode)) {
|
||||
return createItem(node, getTextOfNode(name), ts.ScriptElementKind.constElement);
|
||||
}
|
||||
else if (isLet(variableDeclarationNode)) {
|
||||
return createItem(node, getTextOfNode(name), ts.ScriptElementKind.letElement);
|
||||
}
|
||||
else {
|
||||
return createItem(node, getTextOfNode(name), ts.ScriptElementKind.variableElement);
|
||||
}
|
||||
|
||||
case SyntaxKind.Constructor:
|
||||
|
||||
@@ -402,19 +402,13 @@ module TypeScript {
|
||||
Option_0_specified_without_1: "Option '{0}' specified without '{1}'",
|
||||
codepage_option_not_supported_on_current_platform: "'codepage' option not supported on current platform.",
|
||||
Concatenate_and_emit_output_to_single_file: "Concatenate and emit output to single file.",
|
||||
Generates_corresponding_0_file: "Generates corresponding {0} file.",
|
||||
Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: "Specifies the location where debugger should locate map files instead of generated locations.",
|
||||
Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: "Specifies the location where debugger should locate TypeScript files instead of source locations.",
|
||||
Watch_input_files: "Watch input files.",
|
||||
Redirect_output_structure_to_the_directory: "Redirect output structure to the directory.",
|
||||
Do_not_emit_comments_to_output: "Do not emit comments to output.",
|
||||
Skip_resolution_and_preprocessing: "Skip resolution and preprocessing.",
|
||||
Specify_ECMAScript_target_version_0_default_or_1: "Specify ECMAScript target version: '{0}' (default), or '{1}'",
|
||||
Specify_module_code_generation_0_or_1: "Specify module code generation: '{0}' or '{1}'",
|
||||
Print_this_message: "Print this message.",
|
||||
Print_the_compiler_s_version_0: "Print the compiler's version: {0}",
|
||||
Allow_use_of_deprecated_0_keyword_when_referencing_an_external_module: "Allow use of deprecated '{0}' keyword when referencing an external module.",
|
||||
Specify_locale_for_errors_and_messages_For_example_0_or_1: "Specify locale for errors and messages. For example '{0}' or '{1}'",
|
||||
Syntax_0: "Syntax: {0}",
|
||||
options: "options",
|
||||
file1: "file",
|
||||
@@ -431,7 +425,6 @@ module TypeScript {
|
||||
LOCATION: "LOCATION",
|
||||
DIRECTORY: "DIRECTORY",
|
||||
NUMBER: "NUMBER",
|
||||
Specify_the_codepage_to_use_when_opening_source_files: "Specify the codepage to use when opening source files.",
|
||||
Additional_locations: "Additional locations:",
|
||||
This_version_of_the_Javascript_runtime_does_not_support_the_0_function: "This version of the Javascript runtime does not support the '{0}' function.",
|
||||
Unknown_rule: "Unknown rule.",
|
||||
|
||||
+95
-44
@@ -59,7 +59,7 @@ module ts {
|
||||
isOpen: boolean;
|
||||
version: string;
|
||||
scriptSnapshot: IScriptSnapshot;
|
||||
|
||||
nameTable: Map<string>;
|
||||
getNamedDeclarations(): Declaration[];
|
||||
}
|
||||
|
||||
@@ -335,36 +335,44 @@ module ts {
|
||||
var paramTag = "@param";
|
||||
var jsDocCommentParts: SymbolDisplayPart[] = [];
|
||||
|
||||
ts.forEach(declarations, declaration => {
|
||||
var sourceFileOfDeclaration = getSourceFileOfNode(declaration);
|
||||
// If it is parameter - try and get the jsDoc comment with @param tag from function declaration's jsDoc comments
|
||||
if (canUseParsedParamTagComments && declaration.kind === SyntaxKind.Parameter) {
|
||||
ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), jsDocCommentTextRange => {
|
||||
var cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration);
|
||||
if (cleanedParamJsDocComment) {
|
||||
jsDocCommentParts.push.apply(jsDocCommentParts, cleanedParamJsDocComment);
|
||||
}
|
||||
});
|
||||
ts.forEach(declarations, (declaration, indexOfDeclaration) => {
|
||||
// Make sure we are collecting doc comment from declaration once,
|
||||
// In case of union property there might be same declaration multiple times
|
||||
// which only varies in type parameter
|
||||
// Eg. var a: Array<string> | Array<number>; a.length
|
||||
// The property length will have two declarations of property length coming
|
||||
// from Array<T> - Array<string> and Array<number>
|
||||
if (indexOf(declarations, declaration) === indexOfDeclaration) {
|
||||
var sourceFileOfDeclaration = getSourceFileOfNode(declaration);
|
||||
// If it is parameter - try and get the jsDoc comment with @param tag from function declaration's jsDoc comments
|
||||
if (canUseParsedParamTagComments && declaration.kind === SyntaxKind.Parameter) {
|
||||
ts.forEach(getJsDocCommentTextRange(declaration.parent, sourceFileOfDeclaration), jsDocCommentTextRange => {
|
||||
var cleanedParamJsDocComment = getCleanedParamJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration);
|
||||
if (cleanedParamJsDocComment) {
|
||||
jsDocCommentParts.push.apply(jsDocCommentParts, cleanedParamJsDocComment);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// If this is left side of dotted module declaration, there is no doc comments associated with this node
|
||||
if (declaration.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>declaration).body.kind === SyntaxKind.ModuleDeclaration) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If this is dotted module name, get the doc comments from the parent
|
||||
while (declaration.kind === SyntaxKind.ModuleDeclaration && declaration.parent.kind === SyntaxKind.ModuleDeclaration) {
|
||||
declaration = <ModuleDeclaration>declaration.parent;
|
||||
}
|
||||
|
||||
// Get the cleaned js doc comment text from the declaration
|
||||
ts.forEach(getJsDocCommentTextRange(
|
||||
declaration.kind === SyntaxKind.VariableDeclaration ? declaration.parent.parent : declaration, sourceFileOfDeclaration), jsDocCommentTextRange => {
|
||||
var cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration);
|
||||
if (cleanedJsDocComment) {
|
||||
jsDocCommentParts.push.apply(jsDocCommentParts, cleanedJsDocComment);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// If this is left side of dotted module declaration, there is no doc comments associated with this node
|
||||
if (declaration.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>declaration).body.kind === SyntaxKind.ModuleDeclaration) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If this is dotted module name, get the doc comments from the parent
|
||||
while (declaration.kind === SyntaxKind.ModuleDeclaration && declaration.parent.kind === SyntaxKind.ModuleDeclaration) {
|
||||
declaration = <ModuleDeclaration>declaration.parent;
|
||||
}
|
||||
|
||||
// Get the cleaned js doc comment text from the declaration
|
||||
ts.forEach(getJsDocCommentTextRange(
|
||||
declaration.kind === SyntaxKind.VariableDeclaration ? declaration.parent.parent : declaration, sourceFileOfDeclaration), jsDocCommentTextRange => {
|
||||
var cleanedJsDocComment = getCleanedJsDocComment(jsDocCommentTextRange.pos, jsDocCommentTextRange.end, sourceFileOfDeclaration);
|
||||
if (cleanedJsDocComment) {
|
||||
jsDocCommentParts.push.apply(jsDocCommentParts, cleanedJsDocComment);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return jsDocCommentParts;
|
||||
@@ -750,6 +758,7 @@ module ts {
|
||||
public isOpen: boolean;
|
||||
public languageVersion: ScriptTarget;
|
||||
public identifiers: Map<string>;
|
||||
public nameTable: Map<string>;
|
||||
|
||||
private namedDeclarations: Declaration[];
|
||||
|
||||
@@ -1547,6 +1556,8 @@ module ts {
|
||||
export function createLanguageServiceSourceFile(filename: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, isOpen: boolean, setNodeParents: boolean): SourceFile {
|
||||
var sourceFile = createSourceFile(filename, scriptSnapshot.getText(0, scriptSnapshot.getLength()), scriptTarget, setNodeParents);
|
||||
setSourceFileFields(sourceFile, scriptSnapshot, version, isOpen);
|
||||
// after full parsing we can use table with interned strings as name table
|
||||
sourceFile.nameTable = sourceFile.identifiers;
|
||||
return sourceFile;
|
||||
}
|
||||
|
||||
@@ -1578,6 +1589,9 @@ module ts {
|
||||
if (!disableIncrementalParsing) {
|
||||
var newSourceFile = sourceFile.update(scriptSnapshot.getText(0, scriptSnapshot.getLength()), textChangeRange);
|
||||
setSourceFileFields(newSourceFile, scriptSnapshot, version, isOpen);
|
||||
// after incremental parsing nameTable might not be up-to-date
|
||||
// drop it so it can be lazily recreated later
|
||||
newSourceFile.nameTable = undefined;
|
||||
return newSourceFile;
|
||||
}
|
||||
}
|
||||
@@ -3285,7 +3299,7 @@ module ts {
|
||||
|
||||
if (node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.ThisKeyword || node.kind === SyntaxKind.SuperKeyword ||
|
||||
isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || isNameOfExternalModuleImportOrDeclaration(node)) {
|
||||
return getReferencesForNode(node, [sourceFile], /*findInStrings:*/ false, /*findInComments:*/ false);
|
||||
return getReferencesForNode(node, [sourceFile], /*searchOnlyInCurrentFile*/ true, /*findInStrings:*/ false, /*findInComments:*/ false);
|
||||
}
|
||||
|
||||
switch (node.kind) {
|
||||
@@ -3838,10 +3852,31 @@ module ts {
|
||||
}
|
||||
|
||||
Debug.assert(node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.NumericLiteral || node.kind === SyntaxKind.StringLiteral);
|
||||
return getReferencesForNode(node, program.getSourceFiles(), findInStrings, findInComments);
|
||||
return getReferencesForNode(node, program.getSourceFiles(), /*searchOnlyInCurrentFile*/ false, findInStrings, findInComments);
|
||||
}
|
||||
|
||||
function getReferencesForNode(node: Node, sourceFiles: SourceFile[], findInStrings: boolean, findInComments: boolean): ReferenceEntry[] {
|
||||
function initializeNameTable(sourceFile: SourceFile): void {
|
||||
var nameTable: Map<string> = {};
|
||||
|
||||
walk(sourceFile);
|
||||
sourceFile.nameTable = nameTable;
|
||||
|
||||
function walk(node: Node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
nameTable[(<Identifier>node).text] = (<Identifier>node).text;
|
||||
break;
|
||||
case SyntaxKind.StringLiteral:
|
||||
case SyntaxKind.NumericLiteral:
|
||||
nameTable[(<LiteralExpression>node).text] = (<LiteralExpression>node).text;
|
||||
break;
|
||||
default:
|
||||
forEachChild(node, walk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getReferencesForNode(node: Node, sourceFiles: SourceFile[], searchOnlyInCurrentFile: boolean, findInStrings: boolean, findInComments: boolean): ReferenceEntry[] {
|
||||
// Labels
|
||||
if (isLabelName(node)) {
|
||||
if (isJumpStatementTarget(node)) {
|
||||
@@ -3897,15 +3932,28 @@ module ts {
|
||||
getReferencesInNode(scope, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result);
|
||||
}
|
||||
else {
|
||||
var internedName = getInternedName(symbol, declarations)
|
||||
forEach(sourceFiles, sourceFile => {
|
||||
cancellationToken.throwIfCancellationRequested();
|
||||
if (searchOnlyInCurrentFile) {
|
||||
Debug.assert(sourceFiles.length === 1);
|
||||
result = [];
|
||||
getReferencesInNode(sourceFiles[0], symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result);
|
||||
}
|
||||
else {
|
||||
var internedName = getInternedName(symbol, declarations)
|
||||
forEach(sourceFiles, sourceFile => {
|
||||
cancellationToken.throwIfCancellationRequested();
|
||||
|
||||
if (lookUp(sourceFile.identifiers, internedName)) {
|
||||
result = result || [];
|
||||
getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result);
|
||||
}
|
||||
});
|
||||
if (!sourceFile.nameTable) {
|
||||
initializeNameTable(sourceFile)
|
||||
}
|
||||
|
||||
Debug.assert(sourceFile.nameTable !== undefined);
|
||||
|
||||
if (lookUp(sourceFile.nameTable, internedName)) {
|
||||
result = result || [];
|
||||
getReferencesInNode(sourceFile, symbol, declaredName, node, searchMeaning, findInStrings, findInComments, result);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -3953,7 +4001,8 @@ module ts {
|
||||
}
|
||||
|
||||
// if this symbol is visible from its parent container, e.g. exported, then bail out
|
||||
if (symbol.parent) {
|
||||
// if symbol correspond to the union property - bail out
|
||||
if (symbol.parent || (symbol.getFlags() & SymbolFlags.UnionProperty)) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
@@ -4164,7 +4213,7 @@ module ts {
|
||||
}
|
||||
|
||||
function getReferencesForSuperKeyword(superKeyword: Node): ReferenceEntry[] {
|
||||
var searchSpaceNode = getSuperContainer(superKeyword);
|
||||
var searchSpaceNode = getSuperContainer(superKeyword, /*includeFunctions*/ false);
|
||||
if (!searchSpaceNode) {
|
||||
return undefined;
|
||||
}
|
||||
@@ -4199,7 +4248,7 @@ module ts {
|
||||
return;
|
||||
}
|
||||
|
||||
var container = getSuperContainer(node);
|
||||
var container = getSuperContainer(node, /*includeFunctions*/ false);
|
||||
|
||||
// If we have a 'super' container, we must have an enclosing class.
|
||||
// Now make sure the owning class is the same as the search-space
|
||||
@@ -4241,6 +4290,8 @@ module ts {
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
break;
|
||||
// Computed properties in classes are not handled here because references to this are illegal,
|
||||
// so there is no point finding references to them.
|
||||
default:
|
||||
return undefined;
|
||||
}
|
||||
|
||||
-7
@@ -383,19 +383,13 @@ declare module TypeScript {
|
||||
Option_0_specified_without_1: string;
|
||||
codepage_option_not_supported_on_current_platform: string;
|
||||
Concatenate_and_emit_output_to_single_file: string;
|
||||
Generates_corresponding_0_file: string;
|
||||
Specifies_the_location_where_debugger_should_locate_map_files_instead_of_generated_locations: string;
|
||||
Specifies_the_location_where_debugger_should_locate_TypeScript_files_instead_of_source_locations: string;
|
||||
Watch_input_files: string;
|
||||
Redirect_output_structure_to_the_directory: string;
|
||||
Do_not_emit_comments_to_output: string;
|
||||
Skip_resolution_and_preprocessing: string;
|
||||
Specify_ECMAScript_target_version_0_default_or_1: string;
|
||||
Specify_module_code_generation_0_or_1: string;
|
||||
Print_this_message: string;
|
||||
Print_the_compiler_s_version_0: string;
|
||||
Allow_use_of_deprecated_0_keyword_when_referencing_an_external_module: string;
|
||||
Specify_locale_for_errors_and_messages_For_example_0_or_1: string;
|
||||
Syntax_0: string;
|
||||
options: string;
|
||||
file1: string;
|
||||
@@ -412,7 +406,6 @@ declare module TypeScript {
|
||||
LOCATION: string;
|
||||
DIRECTORY: string;
|
||||
NUMBER: string;
|
||||
Specify_the_codepage_to_use_when_opening_source_files: string;
|
||||
Additional_locations: string;
|
||||
This_version_of_the_Javascript_runtime_does_not_support_the_0_function: string;
|
||||
Unknown_rule: string;
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts(1,11): error TS9002: Computed property names are not currently supported.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts(1,11): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts(1,12): error TS2304: Cannot find name 'yield'.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts(1,20): error TS2304: Cannot find name 'foo'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts (1 errors) ====
|
||||
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration8_es6.ts (3 errors) ====
|
||||
var v = { [yield]: foo }
|
||||
~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
|
||||
~~~~~
|
||||
!!! error TS2304: Cannot find name 'yield'.
|
||||
~~~
|
||||
!!! error TS2304: Cannot find name 'foo'.
|
||||
@@ -1,12 +1,15 @@
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(1,10): error TS9001: Generators are not currently supported.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(2,13): error TS9002: Computed property names are not currently supported.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(2,13): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
|
||||
tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(2,14): error TS9000: 'yield' expressions are not currently supported.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts (2 errors) ====
|
||||
==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts (3 errors) ====
|
||||
function * foo() {
|
||||
~
|
||||
!!! error TS9001: Generators are not currently supported.
|
||||
var v = { [yield]: foo }
|
||||
~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
|
||||
~~~~~
|
||||
!!! error TS9000: 'yield' expressions are not currently supported.
|
||||
}
|
||||
@@ -1,7 +1,13 @@
|
||||
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,12): error TS9002: Computed property names are not currently supported.
|
||||
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,11): error TS9001: Generators are not currently supported.
|
||||
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,12): error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
|
||||
tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,13): error TS2304: Cannot find name 'foo'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (1 errors) ====
|
||||
==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (3 errors) ====
|
||||
var v = { *[foo()]() { } }
|
||||
~
|
||||
!!! error TS9001: Generators are not currently supported.
|
||||
~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
!!! error TS1167: Computed property names are only available when targeting ECMAScript 6 and higher.
|
||||
~~~
|
||||
!!! error TS2304: Cannot find name 'foo'.
|
||||
@@ -1,9 +1,12 @@
|
||||
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts(2,4): error TS9001: Generators are not currently supported.
|
||||
tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts(2,6): error TS2304: Cannot find name 'foo'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts (1 errors) ====
|
||||
==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts (2 errors) ====
|
||||
class C {
|
||||
*[foo]() { }
|
||||
~
|
||||
!!! error TS9001: Generators are not currently supported.
|
||||
~~~
|
||||
!!! error TS2304: Cannot find name 'foo'.
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
//// [TypeGuardWithEnumUnion.ts]
|
||||
enum Color { R, G, B }
|
||||
|
||||
function f1(x: Color | string) {
|
||||
if (typeof x === "number") {
|
||||
var y = x;
|
||||
var y: Color;
|
||||
}
|
||||
else {
|
||||
var z = x;
|
||||
var z: string;
|
||||
}
|
||||
}
|
||||
|
||||
function f2(x: Color | string | string[]) {
|
||||
if (typeof x === "object") {
|
||||
var y = x;
|
||||
var y: string[];
|
||||
}
|
||||
if (typeof x === "number") {
|
||||
var z = x;
|
||||
var z: Color;
|
||||
}
|
||||
else {
|
||||
var w = x;
|
||||
var w: string | string[];
|
||||
}
|
||||
if (typeof x === "string") {
|
||||
var a = x;
|
||||
var a: string;
|
||||
}
|
||||
else {
|
||||
var b = x;
|
||||
var b: Color | string[];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//// [TypeGuardWithEnumUnion.js]
|
||||
var Color;
|
||||
(function (Color) {
|
||||
Color[Color["R"] = 0] = "R";
|
||||
Color[Color["G"] = 1] = "G";
|
||||
Color[Color["B"] = 2] = "B";
|
||||
})(Color || (Color = {}));
|
||||
function f1(x) {
|
||||
if (typeof x === "number") {
|
||||
var y = x;
|
||||
var y;
|
||||
}
|
||||
else {
|
||||
var z = x;
|
||||
var z;
|
||||
}
|
||||
}
|
||||
function f2(x) {
|
||||
if (typeof x === "object") {
|
||||
var y = x;
|
||||
var y;
|
||||
}
|
||||
if (typeof x === "number") {
|
||||
var z = x;
|
||||
var z;
|
||||
}
|
||||
else {
|
||||
var w = x;
|
||||
var w;
|
||||
}
|
||||
if (typeof x === "string") {
|
||||
var a = x;
|
||||
var a;
|
||||
}
|
||||
else {
|
||||
var b = x;
|
||||
var b;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
=== tests/cases/conformance/expressions/typeGuards/TypeGuardWithEnumUnion.ts ===
|
||||
enum Color { R, G, B }
|
||||
>Color : Color
|
||||
>R : Color
|
||||
>G : Color
|
||||
>B : Color
|
||||
|
||||
function f1(x: Color | string) {
|
||||
>f1 : (x: string | Color) => void
|
||||
>x : string | Color
|
||||
>Color : Color
|
||||
|
||||
if (typeof x === "number") {
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : string | Color
|
||||
|
||||
var y = x;
|
||||
>y : Color
|
||||
>x : Color
|
||||
|
||||
var y: Color;
|
||||
>y : Color
|
||||
>Color : Color
|
||||
}
|
||||
else {
|
||||
var z = x;
|
||||
>z : string
|
||||
>x : string
|
||||
|
||||
var z: string;
|
||||
>z : string
|
||||
}
|
||||
}
|
||||
|
||||
function f2(x: Color | string | string[]) {
|
||||
>f2 : (x: string | string[] | Color) => void
|
||||
>x : string | string[] | Color
|
||||
>Color : Color
|
||||
|
||||
if (typeof x === "object") {
|
||||
>typeof x === "object" : boolean
|
||||
>typeof x : string
|
||||
>x : string | string[] | Color
|
||||
|
||||
var y = x;
|
||||
>y : string[]
|
||||
>x : string[]
|
||||
|
||||
var y: string[];
|
||||
>y : string[]
|
||||
}
|
||||
if (typeof x === "number") {
|
||||
>typeof x === "number" : boolean
|
||||
>typeof x : string
|
||||
>x : string | string[] | Color
|
||||
|
||||
var z = x;
|
||||
>z : Color
|
||||
>x : Color
|
||||
|
||||
var z: Color;
|
||||
>z : Color
|
||||
>Color : Color
|
||||
}
|
||||
else {
|
||||
var w = x;
|
||||
>w : string | string[]
|
||||
>x : string | string[]
|
||||
|
||||
var w: string | string[];
|
||||
>w : string | string[]
|
||||
}
|
||||
if (typeof x === "string") {
|
||||
>typeof x === "string" : boolean
|
||||
>typeof x : string
|
||||
>x : string | string[] | Color
|
||||
|
||||
var a = x;
|
||||
>a : string
|
||||
>x : string
|
||||
|
||||
var a: string;
|
||||
>a : string
|
||||
}
|
||||
else {
|
||||
var b = x;
|
||||
>b : string[] | Color
|
||||
>x : string[] | Color
|
||||
|
||||
var b: Color | string[];
|
||||
>b : string[] | Color
|
||||
>Color : Color
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
tests/cases/compiler/arrayAssignmentTest3.ts(12,25): error TS2345: Argument of type 'B' is not assignable to parameter of type 'B[]'.
|
||||
Property 'length' is missing in type 'B'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/arrayAssignmentTest3.ts (1 errors) ====
|
||||
@@ -16,5 +17,6 @@ tests/cases/compiler/arrayAssignmentTest3.ts(12,25): error TS2345: Argument of t
|
||||
var xx = new a(null, 7, new B());
|
||||
~~~~~~~
|
||||
!!! error TS2345: Argument of type 'B' is not assignable to parameter of type 'B[]'.
|
||||
!!! error TS2345: Property 'length' is missing in type 'B'.
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
tests/cases/compiler/arrayCast.ts(3,1): error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other.
|
||||
Type '{ foo: string; }' is not assignable to type '{ id: number; }'.
|
||||
Property 'id' is missing in type '{ foo: string; }'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/arrayCast.ts (1 errors) ====
|
||||
@@ -9,6 +10,7 @@ tests/cases/compiler/arrayCast.ts(3,1): error TS2352: Neither type '{ foo: strin
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2352: Neither type '{ foo: string; }[]' nor type '{ id: number; }[]' is assignable to the other.
|
||||
!!! error TS2352: Type '{ foo: string; }' is not assignable to type '{ id: number; }'.
|
||||
!!! error TS2352: Property 'id' is missing in type '{ foo: string; }'.
|
||||
|
||||
// Should succeed, as the {} element causes the type of the array to be {}[]
|
||||
<{ id: number; }[]>[{ foo: "s" }, {}];
|
||||
@@ -103,6 +103,7 @@ var __extends = this.__extends || function (d, b) {
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
// Arrow function used in with statement
|
||||
with (window) {
|
||||
var p = function () { return this; };
|
||||
}
|
||||
@@ -142,6 +143,7 @@ var M;
|
||||
// Repeat above for module members that are functions? (necessary to redo all of them?)
|
||||
var M2;
|
||||
(function (M2) {
|
||||
// Arrow function used in with statement
|
||||
with (window) {
|
||||
var p = function () { return this; };
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@ tests/cases/compiler/assignmentCompatBug5.ts(2,6): error TS2345: Argument of typ
|
||||
tests/cases/compiler/assignmentCompatBug5.ts(5,6): error TS2345: Argument of type 'string[]' is not assignable to parameter of type 'number[]'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/assignmentCompatBug5.ts(8,6): error TS2345: Argument of type '(s: string) => void' is not assignable to parameter of type '(n: number) => number'.
|
||||
Types of parameters 's' and 'n' are incompatible.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/assignmentCompatBug5.ts(9,6): error TS2345: Argument of type '(n: number) => void' is not assignable to parameter of type '(n: number) => number'.
|
||||
Type 'void' is not assignable to type 'number'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/assignmentCompatBug5.ts (4 errors) ====
|
||||
@@ -23,8 +26,11 @@ tests/cases/compiler/assignmentCompatBug5.ts(9,6): error TS2345: Argument of typ
|
||||
foo3((s:string) => { });
|
||||
~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '(s: string) => void' is not assignable to parameter of type '(n: number) => number'.
|
||||
!!! error TS2345: Types of parameters 's' and 'n' are incompatible.
|
||||
!!! error TS2345: Type 'string' is not assignable to type 'number'.
|
||||
foo3((n) => { return; });
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '(n: number) => void' is not assignable to parameter of type '(n: number) => number'.
|
||||
!!! error TS2345: Type 'void' is not assignable to type 'number'.
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
tests/cases/compiler/assignmentCompatInterfaceWithStringIndexSignature.ts(15,5): error TS2345: Argument of type 'Foo' is not assignable to parameter of type 'IHandlerMap'.
|
||||
Index signature is missing in type 'Foo'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/assignmentCompatInterfaceWithStringIndexSignature.ts (1 errors) ====
|
||||
@@ -19,4 +20,5 @@ tests/cases/compiler/assignmentCompatInterfaceWithStringIndexSignature.ts(15,5):
|
||||
Biz(new Foo());
|
||||
~~~~~~~~~
|
||||
!!! error TS2345: Argument of type 'Foo' is not assignable to parameter of type 'IHandlerMap'.
|
||||
!!! error TS2345: Index signature is missing in type 'Foo'.
|
||||
|
||||
@@ -31,7 +31,7 @@ var e2;
|
||||
(function (e2) {
|
||||
e2[e2["One"] = 0] = "One";
|
||||
})(e2 || (e2 = {}));
|
||||
;
|
||||
; // error
|
||||
var e2 = (function () {
|
||||
function e2() {
|
||||
}
|
||||
|
||||
@@ -47,5 +47,5 @@ var i3;
|
||||
(function (i3) {
|
||||
i3[i3["One"] = 0] = "One";
|
||||
})(i3 || (i3 = {}));
|
||||
;
|
||||
; // error
|
||||
//import i4 = require(''); // error
|
||||
|
||||
@@ -124,21 +124,21 @@ var m1d;
|
||||
var m1d = 1; // error
|
||||
function m2() {
|
||||
}
|
||||
;
|
||||
; // ok since the module is not instantiated
|
||||
var m2a;
|
||||
(function (m2a) {
|
||||
var y = 2;
|
||||
})(m2a || (m2a = {}));
|
||||
function m2a() {
|
||||
}
|
||||
;
|
||||
; // error since the module is instantiated
|
||||
var m2b;
|
||||
(function (m2b) {
|
||||
m2b.y = 2;
|
||||
})(m2b || (m2b = {}));
|
||||
function m2b() {
|
||||
}
|
||||
;
|
||||
; // error since the module is instantiated
|
||||
// should be errors to have function first
|
||||
function m2c() {
|
||||
}
|
||||
|
||||
@@ -31,21 +31,21 @@ module m2g { export class C { foo() { } } }
|
||||
//// [augmentedTypesModules2.js]
|
||||
function m2() {
|
||||
}
|
||||
;
|
||||
; // ok since the module is not instantiated
|
||||
var m2a;
|
||||
(function (m2a) {
|
||||
var y = 2;
|
||||
})(m2a || (m2a = {}));
|
||||
function m2a() {
|
||||
}
|
||||
;
|
||||
; // error since the module is instantiated
|
||||
var m2b;
|
||||
(function (m2b) {
|
||||
m2b.y = 2;
|
||||
})(m2b || (m2b = {}));
|
||||
function m2b() {
|
||||
}
|
||||
;
|
||||
; // error since the module is instantiated
|
||||
function m2c() {
|
||||
}
|
||||
;
|
||||
@@ -59,7 +59,7 @@ var m2cc;
|
||||
})(m2cc || (m2cc = {}));
|
||||
function m2cc() {
|
||||
}
|
||||
;
|
||||
; // error to have module first
|
||||
function m2f() {
|
||||
}
|
||||
;
|
||||
|
||||
+3
-1
@@ -1,4 +1,5 @@
|
||||
tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.ts(19,59): error TS2345: Argument of type '(c: C) => B' is not assignable to parameter of type '(x: C) => C'.
|
||||
Type 'B' is not assignable to type 'C'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter.ts (1 errors) ====
|
||||
@@ -22,4 +23,5 @@ tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParamete
|
||||
// Ok to go down the chain, but error to try to climb back up
|
||||
(new Chain(new A)).then(a => new B).then(b => new C).then(c => new B).then(b => new A);
|
||||
~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '(c: C) => B' is not assignable to parameter of type '(x: C) => C'.
|
||||
!!! error TS2345: Argument of type '(c: C) => B' is not assignable to parameter of type '(x: C) => C'.
|
||||
!!! error TS2345: Type 'B' is not assignable to type 'C'.
|
||||
+4
@@ -1,5 +1,7 @@
|
||||
tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter2.ts(7,43): error TS2345: Argument of type '(ss: S) => T' is not assignable to parameter of type '(x: S) => S'.
|
||||
Type 'T' is not assignable to type 'S'.
|
||||
tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter2.ts(10,29): error TS2345: Argument of type '(ss: S) => T' is not assignable to parameter of type '(x: S) => S'.
|
||||
Type 'T' is not assignable to type 'S'.
|
||||
tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter2.ts(32,9): error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter2.ts(36,9): error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParameter2.ts(37,9): error TS2322: Type 'string' is not assignable to type 'number'.
|
||||
@@ -15,11 +17,13 @@ tests/cases/compiler/chainedCallsWithTypeParameterConstrainedToOtherTypeParamete
|
||||
(new Chain(t)).then(tt => s).then(ss => t);
|
||||
~~~~~~~
|
||||
!!! error TS2345: Argument of type '(ss: S) => T' is not assignable to parameter of type '(x: S) => S'.
|
||||
!!! error TS2345: Type 'T' is not assignable to type 'S'.
|
||||
|
||||
// But error to try to climb up the chain
|
||||
(new Chain(s)).then(ss => t);
|
||||
~~~~~~~
|
||||
!!! error TS2345: Argument of type '(ss: S) => T' is not assignable to parameter of type '(x: S) => S'.
|
||||
!!! error TS2345: Type 'T' is not assignable to type 'S'.
|
||||
|
||||
// Staying at T or S should be fine
|
||||
(new Chain(t)).then(tt => t).then(tt => t).then(tt => t);
|
||||
|
||||
@@ -22,6 +22,7 @@ function foo1<T1, T2>()
|
||||
|
||||
|
||||
//// [commaOperatorOtherValidOperation.js]
|
||||
//Comma operator in for loop
|
||||
for (var i = 0, j = 10; i < j; i++, j--) {
|
||||
}
|
||||
//Comma operator in fuction arguments and return
|
||||
|
||||
@@ -8,4 +8,8 @@ var Person = makeClass(
|
||||
);
|
||||
|
||||
//// [commentsOnObjectLiteral1.js]
|
||||
var Person = makeClass({});
|
||||
var Person = makeClass(
|
||||
/**
|
||||
@scope Person
|
||||
*/
|
||||
{});
|
||||
|
||||
@@ -66,7 +66,9 @@ var n = 30;
|
||||
/** var deckaration with comment on type as well*/
|
||||
var y = 20;
|
||||
/// var deckaration with comment on type as well
|
||||
var yy = 20;
|
||||
var yy =
|
||||
/// value comment
|
||||
20;
|
||||
/** comment2 */
|
||||
var z = function (x, y) { return x + y; };
|
||||
var z2;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
tests/cases/compiler/complicatedPrivacy.ts(24,38): error TS1005: ';' expected.
|
||||
tests/cases/compiler/complicatedPrivacy.ts(35,6): error TS2304: Cannot find name 'number'.
|
||||
tests/cases/compiler/complicatedPrivacy.ts(73,49): error TS2305: Module 'mglo5' has no exported member 'i6'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/complicatedPrivacy.ts (2 errors) ====
|
||||
==== tests/cases/compiler/complicatedPrivacy.ts (3 errors) ====
|
||||
module m1 {
|
||||
export module m2 {
|
||||
|
||||
@@ -39,7 +40,9 @@ tests/cases/compiler/complicatedPrivacy.ts(73,49): error TS2305: Module 'mglo5'
|
||||
|
||||
export function f4(arg1:
|
||||
{
|
||||
[number]: C1;
|
||||
[number]: C1; // Used to be indexer, now it is a computed property
|
||||
~~~~~~
|
||||
!!! error TS2304: Cannot find name 'number'.
|
||||
}) {
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames1.ts(2,9): error TS9002: Computed property names are not currently supported.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames1.ts(3,9): error TS9002: Computed property names are not currently supported.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames1.ts (2 errors) ====
|
||||
var v = {
|
||||
get [0 + 1]() { return 0 },
|
||||
~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
set [0 + 1](v: string) { } //No error
|
||||
~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
//// [computedPropertyNames1.ts]
|
||||
var v = {
|
||||
get [0 + 1]() { return 0 },
|
||||
set [0 + 1](v: string) { } //No error
|
||||
}
|
||||
|
||||
//// [computedPropertyNames1.js]
|
||||
var v = {
|
||||
get [0 + 1]() {
|
||||
return 0;
|
||||
},
|
||||
set [0 + 1](v) {
|
||||
} //No error
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames1.ts ===
|
||||
var v = {
|
||||
>v : {}
|
||||
>{ get [0 + 1]() { return 0 }, set [0 + 1](v: string) { } //No error} : {}
|
||||
|
||||
get [0 + 1]() { return 0 },
|
||||
>0 + 1 : number
|
||||
|
||||
set [0 + 1](v: string) { } //No error
|
||||
>0 + 1 : number
|
||||
>v : string
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
//// [computedPropertyNames10.ts]
|
||||
var s: string;
|
||||
var n: number;
|
||||
var a: any;
|
||||
var v = {
|
||||
[s]() { },
|
||||
[n]() { },
|
||||
[s + s]() { },
|
||||
[s + n]() { },
|
||||
[+s]() { },
|
||||
[""]() { },
|
||||
[0]() { },
|
||||
[a]() { },
|
||||
[<any>true]() { },
|
||||
[`hello bye`]() { },
|
||||
[`hello ${a} bye`]() { }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames10.js]
|
||||
var s;
|
||||
var n;
|
||||
var a;
|
||||
var v = {
|
||||
[s]() {
|
||||
},
|
||||
[n]() {
|
||||
},
|
||||
[s + s]() {
|
||||
},
|
||||
[s + n]() {
|
||||
},
|
||||
[+s]() {
|
||||
},
|
||||
[""]() {
|
||||
},
|
||||
[0]() {
|
||||
},
|
||||
[a]() {
|
||||
},
|
||||
[true]() {
|
||||
},
|
||||
[`hello bye`]() {
|
||||
},
|
||||
[`hello ${a} bye`]() {
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames10.ts ===
|
||||
var s: string;
|
||||
>s : string
|
||||
|
||||
var n: number;
|
||||
>n : number
|
||||
|
||||
var a: any;
|
||||
>a : any
|
||||
|
||||
var v = {
|
||||
>v : {}
|
||||
>{ [s]() { }, [n]() { }, [s + s]() { }, [s + n]() { }, [+s]() { }, [""]() { }, [0]() { }, [a]() { }, [<any>true]() { }, [`hello bye`]() { }, [`hello ${a} bye`]() { }} : {}
|
||||
|
||||
[s]() { },
|
||||
>s : string
|
||||
|
||||
[n]() { },
|
||||
>n : number
|
||||
|
||||
[s + s]() { },
|
||||
>s + s : string
|
||||
>s : string
|
||||
>s : string
|
||||
|
||||
[s + n]() { },
|
||||
>s + n : string
|
||||
>s : string
|
||||
>n : number
|
||||
|
||||
[+s]() { },
|
||||
>+s : number
|
||||
>s : string
|
||||
|
||||
[""]() { },
|
||||
[0]() { },
|
||||
[a]() { },
|
||||
>a : any
|
||||
|
||||
[<any>true]() { },
|
||||
><any>true : any
|
||||
|
||||
[`hello bye`]() { },
|
||||
[`hello ${a} bye`]() { }
|
||||
>a : any
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
//// [computedPropertyNames11.ts]
|
||||
var s: string;
|
||||
var n: number;
|
||||
var a: any;
|
||||
var v = {
|
||||
get [s]() { return 0; },
|
||||
set [n](v) { },
|
||||
get [s + s]() { return 0; },
|
||||
set [s + n](v) { },
|
||||
get [+s]() { return 0; },
|
||||
set [""](v) { },
|
||||
get [0]() { return 0; },
|
||||
set [a](v) { },
|
||||
get [<any>true]() { return 0; },
|
||||
set [`hello bye`](v) { },
|
||||
get [`hello ${a} bye`]() { return 0; }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames11.js]
|
||||
var s;
|
||||
var n;
|
||||
var a;
|
||||
var v = {
|
||||
get [s]() {
|
||||
return 0;
|
||||
},
|
||||
set [n](v) {
|
||||
},
|
||||
get [s + s]() {
|
||||
return 0;
|
||||
},
|
||||
set [s + n](v) {
|
||||
},
|
||||
get [+s]() {
|
||||
return 0;
|
||||
},
|
||||
set [""](v) {
|
||||
},
|
||||
get [0]() {
|
||||
return 0;
|
||||
},
|
||||
set [a](v) {
|
||||
},
|
||||
get [true]() {
|
||||
return 0;
|
||||
},
|
||||
set [`hello bye`](v) {
|
||||
},
|
||||
get [`hello ${a} bye`]() {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames11.ts ===
|
||||
var s: string;
|
||||
>s : string
|
||||
|
||||
var n: number;
|
||||
>n : number
|
||||
|
||||
var a: any;
|
||||
>a : any
|
||||
|
||||
var v = {
|
||||
>v : {}
|
||||
>{ get [s]() { return 0; }, set [n](v) { }, get [s + s]() { return 0; }, set [s + n](v) { }, get [+s]() { return 0; }, set [""](v) { }, get [0]() { return 0; }, set [a](v) { }, get [<any>true]() { return 0; }, set [`hello bye`](v) { }, get [`hello ${a} bye`]() { return 0; }} : {}
|
||||
|
||||
get [s]() { return 0; },
|
||||
>s : string
|
||||
|
||||
set [n](v) { },
|
||||
>n : number
|
||||
>v : any
|
||||
|
||||
get [s + s]() { return 0; },
|
||||
>s + s : string
|
||||
>s : string
|
||||
>s : string
|
||||
|
||||
set [s + n](v) { },
|
||||
>s + n : string
|
||||
>s : string
|
||||
>n : number
|
||||
>v : any
|
||||
|
||||
get [+s]() { return 0; },
|
||||
>+s : number
|
||||
>s : string
|
||||
|
||||
set [""](v) { },
|
||||
>v : any
|
||||
|
||||
get [0]() { return 0; },
|
||||
set [a](v) { },
|
||||
>a : any
|
||||
>v : any
|
||||
|
||||
get [<any>true]() { return 0; },
|
||||
><any>true : any
|
||||
|
||||
set [`hello bye`](v) { },
|
||||
>v : any
|
||||
|
||||
get [`hello ${a} bye`]() { return 0; }
|
||||
>a : any
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(5,5): error TS1166: Computed property names are not allowed in class property declarations.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(6,5): error TS1166: Computed property names are not allowed in class property declarations.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(7,12): error TS1166: Computed property names are not allowed in class property declarations.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(8,5): error TS1166: Computed property names are not allowed in class property declarations.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(9,5): error TS1166: Computed property names are not allowed in class property declarations.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(10,12): error TS1166: Computed property names are not allowed in class property declarations.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(11,5): error TS1166: Computed property names are not allowed in class property declarations.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(12,5): error TS1166: Computed property names are not allowed in class property declarations.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(13,12): error TS1166: Computed property names are not allowed in class property declarations.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(14,5): error TS1166: Computed property names are not allowed in class property declarations.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts(15,12): error TS1166: Computed property names are not allowed in class property declarations.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames12.ts (11 errors) ====
|
||||
var s: string;
|
||||
var n: number;
|
||||
var a: any;
|
||||
class C {
|
||||
[s]: number;
|
||||
~~~
|
||||
!!! error TS1166: Computed property names are not allowed in class property declarations.
|
||||
[n] = n;
|
||||
~~~
|
||||
!!! error TS1166: Computed property names are not allowed in class property declarations.
|
||||
static [s + s]: string;
|
||||
~~~~~~~
|
||||
!!! error TS1166: Computed property names are not allowed in class property declarations.
|
||||
[s + n] = 2;
|
||||
~~~~~~~
|
||||
!!! error TS1166: Computed property names are not allowed in class property declarations.
|
||||
[+s]: typeof s;
|
||||
~~~~
|
||||
!!! error TS1166: Computed property names are not allowed in class property declarations.
|
||||
static [""]: number;
|
||||
~~~~
|
||||
!!! error TS1166: Computed property names are not allowed in class property declarations.
|
||||
[0]: number;
|
||||
~~~
|
||||
!!! error TS1166: Computed property names are not allowed in class property declarations.
|
||||
[a]: number;
|
||||
~~~
|
||||
!!! error TS1166: Computed property names are not allowed in class property declarations.
|
||||
static [<any>true]: number;
|
||||
~~~~~~~~~~~
|
||||
!!! error TS1166: Computed property names are not allowed in class property declarations.
|
||||
[`hello bye`] = 0;
|
||||
~~~~~~~~~~~~~
|
||||
!!! error TS1166: Computed property names are not allowed in class property declarations.
|
||||
static [`hello ${a} bye`] = 0
|
||||
~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS1166: Computed property names are not allowed in class property declarations.
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
//// [computedPropertyNames13.ts]
|
||||
var s: string;
|
||||
var n: number;
|
||||
var a: any;
|
||||
class C {
|
||||
[s]() {}
|
||||
[n]() { }
|
||||
static [s + s]() { }
|
||||
[s + n]() { }
|
||||
[+s]() { }
|
||||
static [""]() { }
|
||||
[0]() { }
|
||||
[a]() { }
|
||||
static [<any>true]() { }
|
||||
[`hello bye`]() { }
|
||||
static [`hello ${a} bye`]() { }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames13.js]
|
||||
var s;
|
||||
var n;
|
||||
var a;
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype[s] = function () {
|
||||
};
|
||||
C.prototype[n] = function () {
|
||||
};
|
||||
C[s + s] = function () {
|
||||
};
|
||||
C.prototype[s + n] = function () {
|
||||
};
|
||||
C.prototype[+s] = function () {
|
||||
};
|
||||
C[""] = function () {
|
||||
};
|
||||
C.prototype[0] = function () {
|
||||
};
|
||||
C.prototype[a] = function () {
|
||||
};
|
||||
C[true] = function () {
|
||||
};
|
||||
C.prototype[`hello bye`] = function () {
|
||||
};
|
||||
C[`hello ${a} bye`] = function () {
|
||||
};
|
||||
return C;
|
||||
})();
|
||||
@@ -0,0 +1,45 @@
|
||||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames13.ts ===
|
||||
var s: string;
|
||||
>s : string
|
||||
|
||||
var n: number;
|
||||
>n : number
|
||||
|
||||
var a: any;
|
||||
>a : any
|
||||
|
||||
class C {
|
||||
>C : C
|
||||
|
||||
[s]() {}
|
||||
>s : string
|
||||
|
||||
[n]() { }
|
||||
>n : number
|
||||
|
||||
static [s + s]() { }
|
||||
>s + s : string
|
||||
>s : string
|
||||
>s : string
|
||||
|
||||
[s + n]() { }
|
||||
>s + n : string
|
||||
>s : string
|
||||
>n : number
|
||||
|
||||
[+s]() { }
|
||||
>+s : number
|
||||
>s : string
|
||||
|
||||
static [""]() { }
|
||||
[0]() { }
|
||||
[a]() { }
|
||||
>a : any
|
||||
|
||||
static [<any>true]() { }
|
||||
><any>true : any
|
||||
|
||||
[`hello bye`]() { }
|
||||
static [`hello ${a} bye`]() { }
|
||||
>a : any
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(3,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(5,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(6,12): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(7,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts(8,12): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames14.ts (6 errors) ====
|
||||
var b: boolean;
|
||||
class C {
|
||||
[b]() {}
|
||||
~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
static [true]() { }
|
||||
~~~~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
[[]]() { }
|
||||
~~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
static [{}]() { }
|
||||
~~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
[undefined]() { }
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
static [null]() { }
|
||||
~~~~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//// [computedPropertyNames14.ts]
|
||||
var b: boolean;
|
||||
class C {
|
||||
[b]() {}
|
||||
static [true]() { }
|
||||
[[]]() { }
|
||||
static [{}]() { }
|
||||
[undefined]() { }
|
||||
static [null]() { }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames14.js]
|
||||
var b;
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype[b] = function () {
|
||||
};
|
||||
C[true] = function () {
|
||||
};
|
||||
C.prototype[[]] = function () {
|
||||
};
|
||||
C[{}] = function () {
|
||||
};
|
||||
C.prototype[undefined] = function () {
|
||||
};
|
||||
C[null] = function () {
|
||||
};
|
||||
return C;
|
||||
})();
|
||||
@@ -0,0 +1,17 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(6,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts(7,5): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames15.ts (2 errors) ====
|
||||
var p1: number | string;
|
||||
var p2: number | number[];
|
||||
var p3: string | boolean;
|
||||
class C {
|
||||
[p1]() { }
|
||||
[p2]() { }
|
||||
~~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
[p3]() { }
|
||||
~~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
//// [computedPropertyNames15.ts]
|
||||
var p1: number | string;
|
||||
var p2: number | number[];
|
||||
var p3: string | boolean;
|
||||
class C {
|
||||
[p1]() { }
|
||||
[p2]() { }
|
||||
[p3]() { }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames15.js]
|
||||
var p1;
|
||||
var p2;
|
||||
var p3;
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype[p1] = function () {
|
||||
};
|
||||
C.prototype[p2] = function () {
|
||||
};
|
||||
C.prototype[p3] = function () {
|
||||
};
|
||||
return C;
|
||||
})();
|
||||
@@ -0,0 +1,99 @@
|
||||
//// [computedPropertyNames16.ts]
|
||||
var s: string;
|
||||
var n: number;
|
||||
var a: any;
|
||||
class C {
|
||||
get [s]() { return 0;}
|
||||
set [n](v) { }
|
||||
static get [s + s]() { return 0; }
|
||||
set [s + n](v) { }
|
||||
get [+s]() { return 0; }
|
||||
static set [""](v) { }
|
||||
get [0]() { return 0; }
|
||||
set [a](v) { }
|
||||
static get [<any>true]() { return 0; }
|
||||
set [`hello bye`](v) { }
|
||||
get [`hello ${a} bye`]() { return 0; }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames16.js]
|
||||
var s;
|
||||
var n;
|
||||
var a;
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
Object.defineProperty(C.prototype, s, {
|
||||
get: function () {
|
||||
return 0;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, n, {
|
||||
set: function (v) {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, s + s, {
|
||||
get: function () {
|
||||
return 0;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, s + n, {
|
||||
set: function (v) {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, +s, {
|
||||
get: function () {
|
||||
return 0;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, "", {
|
||||
set: function (v) {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, 0, {
|
||||
get: function () {
|
||||
return 0;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, a, {
|
||||
set: function (v) {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, true, {
|
||||
get: function () {
|
||||
return 0;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, `hello bye`, {
|
||||
set: function (v) {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, `hello ${a} bye`, {
|
||||
get: function () {
|
||||
return 0;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return C;
|
||||
})();
|
||||
@@ -0,0 +1,52 @@
|
||||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames16.ts ===
|
||||
var s: string;
|
||||
>s : string
|
||||
|
||||
var n: number;
|
||||
>n : number
|
||||
|
||||
var a: any;
|
||||
>a : any
|
||||
|
||||
class C {
|
||||
>C : C
|
||||
|
||||
get [s]() { return 0;}
|
||||
>s : string
|
||||
|
||||
set [n](v) { }
|
||||
>n : number
|
||||
>v : any
|
||||
|
||||
static get [s + s]() { return 0; }
|
||||
>s + s : string
|
||||
>s : string
|
||||
>s : string
|
||||
|
||||
set [s + n](v) { }
|
||||
>s + n : string
|
||||
>s : string
|
||||
>n : number
|
||||
>v : any
|
||||
|
||||
get [+s]() { return 0; }
|
||||
>+s : number
|
||||
>s : string
|
||||
|
||||
static set [""](v) { }
|
||||
>v : any
|
||||
|
||||
get [0]() { return 0; }
|
||||
set [a](v) { }
|
||||
>a : any
|
||||
>v : any
|
||||
|
||||
static get [<any>true]() { return 0; }
|
||||
><any>true : any
|
||||
|
||||
set [`hello bye`](v) { }
|
||||
>v : any
|
||||
|
||||
get [`hello ${a} bye`]() { return 0; }
|
||||
>a : any
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(3,9): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(4,16): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(5,9): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(6,9): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(7,16): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts(8,9): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames17.ts (6 errors) ====
|
||||
var b: boolean;
|
||||
class C {
|
||||
get [b]() { return 0;}
|
||||
~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
static set [true](v) { }
|
||||
~~~~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
get [[]]() { return 0; }
|
||||
~~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
set [{}](v) { }
|
||||
~~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
static get [undefined]() { return 0; }
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
set [null](v) { }
|
||||
~~~~~~
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
//// [computedPropertyNames17.ts]
|
||||
var b: boolean;
|
||||
class C {
|
||||
get [b]() { return 0;}
|
||||
static set [true](v) { }
|
||||
get [[]]() { return 0; }
|
||||
set [{}](v) { }
|
||||
static get [undefined]() { return 0; }
|
||||
set [null](v) { }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames17.js]
|
||||
var b;
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
Object.defineProperty(C.prototype, b, {
|
||||
get: function () {
|
||||
return 0;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, true, {
|
||||
set: function (v) {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, [], {
|
||||
get: function () {
|
||||
return 0;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, {}, {
|
||||
set: function (v) {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, undefined, {
|
||||
get: function () {
|
||||
return 0;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, null, {
|
||||
set: function (v) {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return C;
|
||||
})();
|
||||
@@ -0,0 +1,13 @@
|
||||
//// [computedPropertyNames18.ts]
|
||||
function foo() {
|
||||
var obj = {
|
||||
[this.bar]: 0
|
||||
}
|
||||
}
|
||||
|
||||
//// [computedPropertyNames18.js]
|
||||
function foo() {
|
||||
var obj = {
|
||||
[this.bar]: 0
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames18.ts ===
|
||||
function foo() {
|
||||
>foo : () => void
|
||||
|
||||
var obj = {
|
||||
>obj : {}
|
||||
>{ [this.bar]: 0 } : {}
|
||||
|
||||
[this.bar]: 0
|
||||
>this.bar : any
|
||||
>this : any
|
||||
>bar : any
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames19.ts(3,10): error TS2331: 'this' cannot be referenced in a module body.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames19.ts (1 errors) ====
|
||||
module M {
|
||||
var obj = {
|
||||
[this.bar]: 0
|
||||
~~~~
|
||||
!!! error TS2331: 'this' cannot be referenced in a module body.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
//// [computedPropertyNames19.ts]
|
||||
module M {
|
||||
var obj = {
|
||||
[this.bar]: 0
|
||||
}
|
||||
}
|
||||
|
||||
//// [computedPropertyNames19.js]
|
||||
var M;
|
||||
(function (M) {
|
||||
var obj = {
|
||||
[this.bar]: 0
|
||||
};
|
||||
})(M || (M = {}));
|
||||
@@ -1,37 +1,19 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(4,5): error TS9002: Computed property names are not currently supported.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(5,12): error TS9002: Computed property names are not currently supported.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(6,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(6,9): error TS9002: Computed property names are not currently supported.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(7,9): error TS9002: Computed property names are not currently supported.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(8,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(8,16): error TS9002: Computed property names are not currently supported.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts(9,16): error TS9002: Computed property names are not currently supported.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts (8 errors) ====
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames2.ts (2 errors) ====
|
||||
var methodName = "method";
|
||||
var accessorName = "accessor";
|
||||
class C {
|
||||
[methodName]() { }
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
static [methodName]() { }
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
get [accessorName]() { }
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
set [accessorName](v) { }
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
static get [accessorName]() { }
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
static set [accessorName](v) { }
|
||||
~~~~~~~~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
//// [computedPropertyNames2.ts]
|
||||
var methodName = "method";
|
||||
var accessorName = "accessor";
|
||||
class C {
|
||||
[methodName]() { }
|
||||
static [methodName]() { }
|
||||
get [accessorName]() { }
|
||||
set [accessorName](v) { }
|
||||
static get [accessorName]() { }
|
||||
static set [accessorName](v) { }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames2.js]
|
||||
var methodName = "method";
|
||||
var accessorName = "accessor";
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype[methodName] = function () {
|
||||
};
|
||||
C[methodName] = function () {
|
||||
};
|
||||
Object.defineProperty(C.prototype, accessorName, {
|
||||
get: function () {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, accessorName, {
|
||||
set: function (v) {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, accessorName, {
|
||||
get: function () {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, accessorName, {
|
||||
set: function (v) {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return C;
|
||||
})();
|
||||
@@ -0,0 +1,9 @@
|
||||
//// [computedPropertyNames20.ts]
|
||||
var obj = {
|
||||
[this.bar]: 0
|
||||
}
|
||||
|
||||
//// [computedPropertyNames20.js]
|
||||
var obj = {
|
||||
[this.bar]: 0
|
||||
};
|
||||
@@ -0,0 +1,10 @@
|
||||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames20.ts ===
|
||||
var obj = {
|
||||
>obj : {}
|
||||
>{ [this.bar]: 0} : {}
|
||||
|
||||
[this.bar]: 0
|
||||
>this.bar : any
|
||||
>this : any
|
||||
>bar : any
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames21.ts(5,6): error TS2465: 'this' cannot be referenced in a computed property name.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames21.ts (1 errors) ====
|
||||
class C {
|
||||
bar() {
|
||||
return 0;
|
||||
}
|
||||
[this.bar()]() { }
|
||||
~~~~
|
||||
!!! error TS2465: 'this' cannot be referenced in a computed property name.
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//// [computedPropertyNames21.ts]
|
||||
class C {
|
||||
bar() {
|
||||
return 0;
|
||||
}
|
||||
[this.bar()]() { }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames21.js]
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.bar = function () {
|
||||
return 0;
|
||||
};
|
||||
C.prototype[this.bar()] = function () {
|
||||
};
|
||||
return C;
|
||||
})();
|
||||
@@ -0,0 +1,23 @@
|
||||
//// [computedPropertyNames22.ts]
|
||||
class C {
|
||||
bar() {
|
||||
var obj = {
|
||||
[this.bar()]() { }
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//// [computedPropertyNames22.js]
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.bar = function () {
|
||||
var obj = {
|
||||
[this.bar()]() {
|
||||
}
|
||||
};
|
||||
return 0;
|
||||
};
|
||||
return C;
|
||||
})();
|
||||
@@ -0,0 +1,21 @@
|
||||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames22.ts ===
|
||||
class C {
|
||||
>C : C
|
||||
|
||||
bar() {
|
||||
>bar : () => number
|
||||
|
||||
var obj = {
|
||||
>obj : {}
|
||||
>{ [this.bar()]() { } } : {}
|
||||
|
||||
[this.bar()]() { }
|
||||
>this.bar() : number
|
||||
>this.bar : () => number
|
||||
>this : C
|
||||
>bar : () => number
|
||||
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames23.ts(6,12): error TS2465: 'this' cannot be referenced in a computed property name.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames23.ts (1 errors) ====
|
||||
class C {
|
||||
bar() {
|
||||
return 0;
|
||||
}
|
||||
[
|
||||
{ [this.bar()]: 1 }[0]
|
||||
~~~~
|
||||
!!! error TS2465: 'this' cannot be referenced in a computed property name.
|
||||
]() { }
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
//// [computedPropertyNames23.ts]
|
||||
class C {
|
||||
bar() {
|
||||
return 0;
|
||||
}
|
||||
[
|
||||
{ [this.bar()]: 1 }[0]
|
||||
]() { }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames23.js]
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.bar = function () {
|
||||
return 0;
|
||||
};
|
||||
C.prototype[{ [this.bar()]: 1 }[0]] = function () {
|
||||
};
|
||||
return C;
|
||||
})();
|
||||
@@ -0,0 +1,16 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames24.ts(9,6): error TS2466: 'super' cannot be referenced in a computed property name.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames24.ts (1 errors) ====
|
||||
class Base {
|
||||
bar() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
class C extends Base {
|
||||
// Gets emitted as super, not _super, which is consistent with
|
||||
// use of super in static properties initializers.
|
||||
[super.bar()]() { }
|
||||
~~~~~
|
||||
!!! error TS2466: 'super' cannot be referenced in a computed property name.
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
//// [computedPropertyNames24.ts]
|
||||
class Base {
|
||||
bar() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
class C extends Base {
|
||||
// Gets emitted as super, not _super, which is consistent with
|
||||
// use of super in static properties initializers.
|
||||
[super.bar()]() { }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames24.js]
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var Base = (function () {
|
||||
function Base() {
|
||||
}
|
||||
Base.prototype.bar = function () {
|
||||
return 0;
|
||||
};
|
||||
return Base;
|
||||
})();
|
||||
var C = (function (_super) {
|
||||
__extends(C, _super);
|
||||
function C() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
// Gets emitted as super, not _super, which is consistent with
|
||||
// use of super in static properties initializers.
|
||||
C.prototype[super.bar.call(this)] = function () {
|
||||
};
|
||||
return C;
|
||||
})(Base);
|
||||
@@ -0,0 +1,44 @@
|
||||
//// [computedPropertyNames25.ts]
|
||||
class Base {
|
||||
bar() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
class C extends Base {
|
||||
foo() {
|
||||
var obj = {
|
||||
[super.bar()]() { }
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//// [computedPropertyNames25.js]
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var Base = (function () {
|
||||
function Base() {
|
||||
}
|
||||
Base.prototype.bar = function () {
|
||||
return 0;
|
||||
};
|
||||
return Base;
|
||||
})();
|
||||
var C = (function (_super) {
|
||||
__extends(C, _super);
|
||||
function C() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
C.prototype.foo = function () {
|
||||
var obj = {
|
||||
[_super.prototype.bar.call(this)]() {
|
||||
}
|
||||
};
|
||||
return 0;
|
||||
};
|
||||
return C;
|
||||
})(Base);
|
||||
@@ -0,0 +1,31 @@
|
||||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames25.ts ===
|
||||
class Base {
|
||||
>Base : Base
|
||||
|
||||
bar() {
|
||||
>bar : () => number
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
class C extends Base {
|
||||
>C : C
|
||||
>Base : Base
|
||||
|
||||
foo() {
|
||||
>foo : () => number
|
||||
|
||||
var obj = {
|
||||
>obj : {}
|
||||
>{ [super.bar()]() { } } : {}
|
||||
|
||||
[super.bar()]() { }
|
||||
>super.bar() : number
|
||||
>super.bar : () => number
|
||||
>super : Base
|
||||
>bar : () => number
|
||||
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames26.ts(10,12): error TS2466: 'super' cannot be referenced in a computed property name.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames26.ts (1 errors) ====
|
||||
class Base {
|
||||
bar() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
class C extends Base {
|
||||
// Gets emitted as super, not _super, which is consistent with
|
||||
// use of super in static properties initializers.
|
||||
[
|
||||
{ [super.bar()]: 1 }[0]
|
||||
~~~~~
|
||||
!!! error TS2466: 'super' cannot be referenced in a computed property name.
|
||||
]() { }
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
//// [computedPropertyNames26.ts]
|
||||
class Base {
|
||||
bar() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
class C extends Base {
|
||||
// Gets emitted as super, not _super, which is consistent with
|
||||
// use of super in static properties initializers.
|
||||
[
|
||||
{ [super.bar()]: 1 }[0]
|
||||
]() { }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames26.js]
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var Base = (function () {
|
||||
function Base() {
|
||||
}
|
||||
Base.prototype.bar = function () {
|
||||
return 0;
|
||||
};
|
||||
return Base;
|
||||
})();
|
||||
var C = (function (_super) {
|
||||
__extends(C, _super);
|
||||
function C() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
// Gets emitted as super, not _super, which is consistent with
|
||||
// use of super in static properties initializers.
|
||||
C.prototype[{ [super.bar.call(this)]: 1 }[0]] = function () {
|
||||
};
|
||||
return C;
|
||||
})(Base);
|
||||
@@ -0,0 +1,11 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames27.ts(4,7): error TS2466: 'super' cannot be referenced in a computed property name.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames27.ts (1 errors) ====
|
||||
class Base {
|
||||
}
|
||||
class C extends Base {
|
||||
[(super(), "prop")]() { }
|
||||
~~~~~
|
||||
!!! error TS2466: 'super' cannot be referenced in a computed property name.
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//// [computedPropertyNames27.ts]
|
||||
class Base {
|
||||
}
|
||||
class C extends Base {
|
||||
[(super(), "prop")]() { }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames27.js]
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var Base = (function () {
|
||||
function Base() {
|
||||
}
|
||||
return Base;
|
||||
})();
|
||||
var C = (function (_super) {
|
||||
__extends(C, _super);
|
||||
function C() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
C.prototype[(_super.call(this), "prop")] = function () {
|
||||
};
|
||||
return C;
|
||||
})(Base);
|
||||
@@ -0,0 +1,35 @@
|
||||
//// [computedPropertyNames28.ts]
|
||||
class Base {
|
||||
}
|
||||
class C extends Base {
|
||||
constructor() {
|
||||
super();
|
||||
var obj = {
|
||||
[(super(), "prop")]() { }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
//// [computedPropertyNames28.js]
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var Base = (function () {
|
||||
function Base() {
|
||||
}
|
||||
return Base;
|
||||
})();
|
||||
var C = (function (_super) {
|
||||
__extends(C, _super);
|
||||
function C() {
|
||||
_super.call(this);
|
||||
var obj = {
|
||||
[(_super.call(this), "prop")]() {
|
||||
}
|
||||
};
|
||||
}
|
||||
return C;
|
||||
})(Base);
|
||||
@@ -0,0 +1,26 @@
|
||||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames28.ts ===
|
||||
class Base {
|
||||
>Base : Base
|
||||
}
|
||||
class C extends Base {
|
||||
>C : C
|
||||
>Base : Base
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
>super() : void
|
||||
>super : typeof Base
|
||||
|
||||
var obj = {
|
||||
>obj : {}
|
||||
>{ [(super(), "prop")]() { } } : {}
|
||||
|
||||
[(super(), "prop")]() { }
|
||||
>(super(), "prop") : string
|
||||
>super(), "prop" : string
|
||||
>super() : void
|
||||
>super : typeof Base
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
//// [computedPropertyNames29.ts]
|
||||
class C {
|
||||
bar() {
|
||||
() => {
|
||||
var obj = {
|
||||
[this.bar()]() { } // needs capture
|
||||
};
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//// [computedPropertyNames29.js]
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.bar = function () {
|
||||
var _this = this;
|
||||
(function () {
|
||||
var obj = {
|
||||
[_this.bar()]() {
|
||||
} // needs capture
|
||||
};
|
||||
});
|
||||
return 0;
|
||||
};
|
||||
return C;
|
||||
})();
|
||||
@@ -0,0 +1,25 @@
|
||||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames29.ts ===
|
||||
class C {
|
||||
>C : C
|
||||
|
||||
bar() {
|
||||
>bar : () => number
|
||||
|
||||
() => {
|
||||
>() => { var obj = { [this.bar()]() { } // needs capture }; } : () => void
|
||||
|
||||
var obj = {
|
||||
>obj : {}
|
||||
>{ [this.bar()]() { } // needs capture } : {}
|
||||
|
||||
[this.bar()]() { } // needs capture
|
||||
>this.bar() : number
|
||||
>this.bar : () => number
|
||||
>this : C
|
||||
>bar : () => number
|
||||
|
||||
};
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,30 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(3,5): error TS9002: Computed property names are not currently supported.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(4,12): error TS9002: Computed property names are not currently supported.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(4,12): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(5,9): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(5,9): error TS9002: Computed property names are not currently supported.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(6,9): error TS9002: Computed property names are not currently supported.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(5,9): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(6,9): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): error TS9002: Computed property names are not currently supported.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(8,16): error TS9002: Computed property names are not currently supported.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts(7,16): error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts (8 errors) ====
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames3.ts (6 errors) ====
|
||||
var id;
|
||||
class C {
|
||||
[0 + 1]() { }
|
||||
~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
static [() => { }]() { }
|
||||
~~~~~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
get [delete id]() { }
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
|
||||
~~~~~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
set [[0, 1]](v) { }
|
||||
~~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
static get [<String>""]() { }
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement.
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
!!! error TS2464: A computed property name must be of type 'string', 'number', or 'any'.
|
||||
static set [id.toString()](v) { }
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS9002: Computed property names are not currently supported.
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
//// [computedPropertyNames3.ts]
|
||||
var id;
|
||||
class C {
|
||||
[0 + 1]() { }
|
||||
static [() => { }]() { }
|
||||
get [delete id]() { }
|
||||
set [[0, 1]](v) { }
|
||||
static get [<String>""]() { }
|
||||
static set [id.toString()](v) { }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames3.js]
|
||||
var id;
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype[0 + 1] = function () {
|
||||
};
|
||||
C[function () {
|
||||
}] = function () {
|
||||
};
|
||||
Object.defineProperty(C.prototype, delete id, {
|
||||
get: function () {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, [0, 1], {
|
||||
set: function (v) {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, "", {
|
||||
get: function () {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C, id.toString(), {
|
||||
set: function (v) {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return C;
|
||||
})();
|
||||
@@ -0,0 +1,21 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames30.ts(11,19): error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames30.ts (1 errors) ====
|
||||
class Base {
|
||||
}
|
||||
class C extends Base {
|
||||
constructor() {
|
||||
super();
|
||||
() => {
|
||||
var obj = {
|
||||
// Ideally, we would capture this. But the reference is
|
||||
// illegal, and not capturing this is consistent with
|
||||
//treatment of other similar violations.
|
||||
[(super(), "prop")]() { }
|
||||
~~~~~
|
||||
!!! error TS2337: Super calls are not permitted outside constructors or in nested functions inside constructors
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
//// [computedPropertyNames30.ts]
|
||||
class Base {
|
||||
}
|
||||
class C extends Base {
|
||||
constructor() {
|
||||
super();
|
||||
() => {
|
||||
var obj = {
|
||||
// Ideally, we would capture this. But the reference is
|
||||
// illegal, and not capturing this is consistent with
|
||||
//treatment of other similar violations.
|
||||
[(super(), "prop")]() { }
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//// [computedPropertyNames30.js]
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var Base = (function () {
|
||||
function Base() {
|
||||
}
|
||||
return Base;
|
||||
})();
|
||||
var C = (function (_super) {
|
||||
__extends(C, _super);
|
||||
function C() {
|
||||
_super.call(this);
|
||||
(function () {
|
||||
var obj = {
|
||||
// Ideally, we would capture this. But the reference is
|
||||
// illegal, and not capturing this is consistent with
|
||||
//treatment of other similar violations.
|
||||
[(_super.call(this), "prop")]() {
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
return C;
|
||||
})(Base);
|
||||
@@ -0,0 +1,49 @@
|
||||
//// [computedPropertyNames31.ts]
|
||||
class Base {
|
||||
bar() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
class C extends Base {
|
||||
foo() {
|
||||
() => {
|
||||
var obj = {
|
||||
[super.bar()]() { } // needs capture
|
||||
};
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//// [computedPropertyNames31.js]
|
||||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
var Base = (function () {
|
||||
function Base() {
|
||||
}
|
||||
Base.prototype.bar = function () {
|
||||
return 0;
|
||||
};
|
||||
return Base;
|
||||
})();
|
||||
var C = (function (_super) {
|
||||
__extends(C, _super);
|
||||
function C() {
|
||||
_super.apply(this, arguments);
|
||||
}
|
||||
C.prototype.foo = function () {
|
||||
var _this = this;
|
||||
(function () {
|
||||
var obj = {
|
||||
[_super.prototype.bar.call(_this)]() {
|
||||
} // needs capture
|
||||
};
|
||||
});
|
||||
return 0;
|
||||
};
|
||||
return C;
|
||||
})(Base);
|
||||
@@ -0,0 +1,35 @@
|
||||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames31.ts ===
|
||||
class Base {
|
||||
>Base : Base
|
||||
|
||||
bar() {
|
||||
>bar : () => number
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
class C extends Base {
|
||||
>C : C
|
||||
>Base : Base
|
||||
|
||||
foo() {
|
||||
>foo : () => number
|
||||
|
||||
() => {
|
||||
>() => { var obj = { [super.bar()]() { } // needs capture }; } : () => void
|
||||
|
||||
var obj = {
|
||||
>obj : {}
|
||||
>{ [super.bar()]() { } // needs capture } : {}
|
||||
|
||||
[super.bar()]() { } // needs capture
|
||||
>super.bar() : number
|
||||
>super.bar : () => number
|
||||
>super : Base
|
||||
>bar : () => number
|
||||
|
||||
};
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames32.ts(6,10): error TS2466: A computed property name cannot reference a type parameter from its containing type.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames32.ts (1 errors) ====
|
||||
function foo<T>() { return '' }
|
||||
class C<T> {
|
||||
bar() {
|
||||
return 0;
|
||||
}
|
||||
[foo<T>()]() { }
|
||||
~
|
||||
!!! error TS2466: A computed property name cannot reference a type parameter from its containing type.
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
//// [computedPropertyNames32.ts]
|
||||
function foo<T>() { return '' }
|
||||
class C<T> {
|
||||
bar() {
|
||||
return 0;
|
||||
}
|
||||
[foo<T>()]() { }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames32.js]
|
||||
function foo() {
|
||||
return '';
|
||||
}
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.bar = function () {
|
||||
return 0;
|
||||
};
|
||||
C.prototype[foo()] = function () {
|
||||
};
|
||||
return C;
|
||||
})();
|
||||
@@ -0,0 +1,27 @@
|
||||
//// [computedPropertyNames33.ts]
|
||||
function foo<T>() { return '' }
|
||||
class C<T> {
|
||||
bar() {
|
||||
var obj = {
|
||||
[foo<T>()]() { }
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//// [computedPropertyNames33.js]
|
||||
function foo() {
|
||||
return '';
|
||||
}
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.bar = function () {
|
||||
var obj = {
|
||||
[foo()]() {
|
||||
}
|
||||
};
|
||||
return 0;
|
||||
};
|
||||
return C;
|
||||
})();
|
||||
@@ -0,0 +1,25 @@
|
||||
=== tests/cases/conformance/es6/computedProperties/computedPropertyNames33.ts ===
|
||||
function foo<T>() { return '' }
|
||||
>foo : <T>() => string
|
||||
>T : T
|
||||
|
||||
class C<T> {
|
||||
>C : C<T>
|
||||
>T : T
|
||||
|
||||
bar() {
|
||||
>bar : () => number
|
||||
|
||||
var obj = {
|
||||
>obj : {}
|
||||
>{ [foo<T>()]() { } } : {}
|
||||
|
||||
[foo<T>()]() { }
|
||||
>foo<T>() : string
|
||||
>foo : <T>() => string
|
||||
>T : T
|
||||
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames34.ts(5,18): error TS2302: Static members cannot reference class type parameters.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames34.ts (1 errors) ====
|
||||
function foo<T>() { return '' }
|
||||
class C<T> {
|
||||
static bar() {
|
||||
var obj = {
|
||||
[foo<T>()]() { }
|
||||
~
|
||||
!!! error TS2302: Static members cannot reference class type parameters.
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
//// [computedPropertyNames34.ts]
|
||||
function foo<T>() { return '' }
|
||||
class C<T> {
|
||||
static bar() {
|
||||
var obj = {
|
||||
[foo<T>()]() { }
|
||||
};
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
//// [computedPropertyNames34.js]
|
||||
function foo() {
|
||||
return '';
|
||||
}
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
C.bar = function () {
|
||||
var obj = {
|
||||
[foo()]() {
|
||||
}
|
||||
};
|
||||
return 0;
|
||||
};
|
||||
return C;
|
||||
})();
|
||||
@@ -0,0 +1,14 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames35.ts(4,5): error TS1169: Computed property names are not allowed in interfaces.
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames35.ts(4,10): error TS2466: A computed property name cannot reference a type parameter from its containing type.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames35.ts (2 errors) ====
|
||||
function foo<T>() { return '' }
|
||||
interface I<T> {
|
||||
bar(): string;
|
||||
[foo<T>()](): void;
|
||||
~~~~~~~~~~
|
||||
!!! error TS1169: Computed property names are not allowed in interfaces.
|
||||
~
|
||||
!!! error TS2466: A computed property name cannot reference a type parameter from its containing type.
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
tests/cases/conformance/es6/computedProperties/computedPropertyNames36.ts(8,5): error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/computedProperties/computedPropertyNames36.ts (1 errors) ====
|
||||
class Foo { x }
|
||||
class Foo2 { x; y }
|
||||
|
||||
class C {
|
||||
[s: string]: Foo2;
|
||||
|
||||
// Computed properties
|
||||
get ["get1"]() { return new Foo }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2411: Property '["get1"]' of type 'Foo' is not assignable to string index type 'Foo2'.
|
||||
set ["set1"](p: Foo2) { }
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
//// [computedPropertyNames36.ts]
|
||||
class Foo { x }
|
||||
class Foo2 { x; y }
|
||||
|
||||
class C {
|
||||
[s: string]: Foo2;
|
||||
|
||||
// Computed properties
|
||||
get ["get1"]() { return new Foo }
|
||||
set ["set1"](p: Foo2) { }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames36.js]
|
||||
var Foo = (function () {
|
||||
function Foo() {
|
||||
}
|
||||
return Foo;
|
||||
})();
|
||||
var Foo2 = (function () {
|
||||
function Foo2() {
|
||||
}
|
||||
return Foo2;
|
||||
})();
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
Object.defineProperty(C.prototype, "get1", {
|
||||
// Computed properties
|
||||
get: function () {
|
||||
return new Foo;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, "set1", {
|
||||
set: function (p) {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return C;
|
||||
})();
|
||||
@@ -0,0 +1,42 @@
|
||||
//// [computedPropertyNames37.ts]
|
||||
class Foo { x }
|
||||
class Foo2 { x; y }
|
||||
|
||||
class C {
|
||||
[s: number]: Foo2;
|
||||
|
||||
// Computed properties
|
||||
get ["get1"]() { return new Foo }
|
||||
set ["set1"](p: Foo2) { }
|
||||
}
|
||||
|
||||
//// [computedPropertyNames37.js]
|
||||
var Foo = (function () {
|
||||
function Foo() {
|
||||
}
|
||||
return Foo;
|
||||
})();
|
||||
var Foo2 = (function () {
|
||||
function Foo2() {
|
||||
}
|
||||
return Foo2;
|
||||
})();
|
||||
var C = (function () {
|
||||
function C() {
|
||||
}
|
||||
Object.defineProperty(C.prototype, "get1", {
|
||||
// Computed properties
|
||||
get: function () {
|
||||
return new Foo;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(C.prototype, "set1", {
|
||||
set: function (p) {
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return C;
|
||||
})();
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user