@@ -93,7 +93,7 @@ module ts {
93
93
let emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
94
94
let anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
95
95
let noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
96
-
96
+
97
97
let anySignature = createSignature(undefined, undefined, emptyArray, anyType, 0, false, false);
98
98
let unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, false, false);
99
99
@@ -118,7 +118,7 @@ module ts {
118
118
let getGlobalParameterDecoratorType: () => ObjectType;
119
119
let getGlobalPropertyDecoratorType: () => ObjectType;
120
120
let getGlobalMethodDecoratorType: () => ObjectType;
121
-
121
+
122
122
let tupleTypes: Map<TupleType> = {};
123
123
let unionTypes: Map<UnionType> = {};
124
124
let stringLiteralTypes: Map<StringLiteralType> = {};
@@ -444,7 +444,7 @@ module ts {
444
444
}
445
445
break;
446
446
case SyntaxKind.Decorator:
447
- // Decorators are resolved at the class declaration. Resolving at the parameter
447
+ // Decorators are resolved at the class declaration. Resolving at the parameter
448
448
// or member would result in looking up locals in the method.
449
449
//
450
450
// function y() {}
@@ -1949,7 +1949,7 @@ module ts {
1949
1949
case SyntaxKind.ParenthesizedType:
1950
1950
return isDeclarationVisible(<Declaration>node.parent);
1951
1951
1952
- // Default binding, import specifier and namespace import is visible
1952
+ // Default binding, import specifier and namespace import is visible
1953
1953
// only on demand so by default it is not visible
1954
1954
case SyntaxKind.ImportClause:
1955
1955
case SyntaxKind.NamespaceImport:
@@ -6030,15 +6030,15 @@ module ts {
6030
6030
// c is represented in the tree as a spread element in an array literal.
6031
6031
// But c really functions as a rest element, and its purpose is to provide
6032
6032
// a contextual type for the right hand side of the assignment. Therefore,
6033
- // instead of calling checkExpression on "...c", which will give an error
6033
+ // instead of calling checkExpression on "...c", which will give an error
6034
6034
// if c is not iterable/array-like, we need to act as if we are trying to
6035
6035
// get the contextual element type from it. So we do something similar to
6036
6036
// getContextualTypeForElementExpression, which will crucially not error
6037
6037
// if there is no index type / iterated type.
6038
6038
let restArrayType = checkExpression((<SpreadElementExpression>e).expression, contextualMapper);
6039
6039
let restElementType = getIndexTypeOfType(restArrayType, IndexKind.Number) ||
6040
6040
(languageVersion >= ScriptTarget.ES6 ? checkIteratedType(restArrayType, /*expressionForError*/ undefined) : undefined);
6041
-
6041
+
6042
6042
if (restElementType) {
6043
6043
elementTypes.push(restElementType);
6044
6044
}
@@ -6939,7 +6939,7 @@ module ts {
6939
6939
if (!hasCorrectArity(node, args, originalCandidate)) {
6940
6940
continue;
6941
6941
}
6942
-
6942
+
6943
6943
let candidate: Signature;
6944
6944
let typeArgumentsAreValid: boolean;
6945
6945
let inferenceContext = originalCandidate.typeParameters
@@ -8137,7 +8137,7 @@ module ts {
8137
8137
if (node.questionToken && isBindingPattern(node.name) && func.body) {
8138
8138
error(node, Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature);
8139
8139
}
8140
-
8140
+
8141
8141
// Only check rest parameter type if it's not a binding pattern. Since binding patterns are
8142
8142
// not allowed in a rest parameter, we already have an error from checkGrammarParameterList.
8143
8143
if (node.dotDotDotToken && !isBindingPattern(node.name) && !isArrayType(getTypeOfSymbol(node.symbol))) {
@@ -8806,7 +8806,7 @@ module ts {
8806
8806
/** Checks a type reference node as an expression. */
8807
8807
function checkTypeNodeAsExpression(node: TypeNode) {
8808
8808
// When we are emitting type metadata for decorators, we need to try to check the type
8809
- // as if it were an expression so that we can emit the type in a value position when we
8809
+ // as if it were an expression so that we can emit the type in a value position when we
8810
8810
// serialize the type metadata.
8811
8811
if (node && node.kind === SyntaxKind.TypeReference) {
8812
8812
let type = getTypeFromTypeNode(node);
@@ -8821,7 +8821,7 @@ module ts {
8821
8821
}
8822
8822
8823
8823
/**
8824
- * Checks the type annotation of an accessor declaration or property declaration as
8824
+ * Checks the type annotation of an accessor declaration or property declaration as
8825
8825
* an expression if it is a type reference to a type with a value declaration.
8826
8826
*/
8827
8827
function checkTypeAnnotationAsExpression(node: AccessorDeclaration | PropertyDeclaration | ParameterDeclaration | MethodDeclaration) {
@@ -8843,7 +8843,7 @@ module ts {
8843
8843
break;
8844
8844
}
8845
8845
}
8846
-
8846
+
8847
8847
/** Checks the type annotation of the parameters of a function/method or the constructor of a class as expressions */
8848
8848
function checkParameterTypeAnnotationsAsExpressions(node: FunctionLikeDeclaration) {
8849
8849
// ensure all type annotations with a value declaration are checked as an expression
@@ -9456,7 +9456,7 @@ module ts {
9456
9456
if (allowStringInput) {
9457
9457
return checkElementTypeOfArrayOrString(inputType, errorNode);
9458
9458
}
9459
-
9459
+
9460
9460
if (isArrayLikeType(inputType)) {
9461
9461
let indexType = getIndexTypeOfType(inputType, IndexKind.Number);
9462
9462
if (indexType) {
@@ -10493,9 +10493,9 @@ module ts {
10493
10493
}
10494
10494
}
10495
10495
10496
- // if the module merges with a class declaration in the same lexical scope,
10496
+ // if the module merges with a class declaration in the same lexical scope,
10497
10497
// we need to track this to ensure the correct emit.
10498
- let mergedClass = getDeclarationOfKind(symbol, SyntaxKind.ClassDeclaration);
10498
+ let mergedClass = getDeclarationOfKind(symbol, SyntaxKind.ClassDeclaration);
10499
10499
if (mergedClass &&
10500
10500
inSameLexicalScope(node, mergedClass)) {
10501
10501
getNodeLinks(node).flags |= NodeCheckFlags.LexicalModuleMergesWithClass;
@@ -11532,7 +11532,7 @@ module ts {
11532
11532
}
11533
11533
11534
11534
function getExpressionNameSubstitution(node: Identifier, getGeneratedNameForNode: (Node: Node) => string): string {
11535
- let symbol = getNodeLinks (node).resolvedSymbol || (isDeclarationName(node) ? getSymbolOfNode(node.parent) : undefined);
11535
+ let symbol = getResolvedSymbol (node) || (isDeclarationName(node) ? getSymbolOfNode(node.parent) : undefined);
11536
11536
if (symbol) {
11537
11537
// Whan an identifier resolves to a parented symbol, it references an exported entity from
11538
11538
// another declaration of the same internal module.
@@ -11674,6 +11674,23 @@ module ts {
11674
11674
}
11675
11675
}
11676
11676
11677
+ /** Serializes an Entity. Used by the __metadata decorator. */
11678
+ function serializeEntity(node: TypeReferenceNode, getGeneratedNameForNode: (Node: Node) => string): string {
11679
+ var text = "{kind: " + serializeEntityName(node.typeName, getGeneratedNameForNode);
11680
+ if (node.typeArguments) {
11681
+ text += ', typeArguments: [';
11682
+ node.typeArguments.forEach(function(node, i) {
11683
+ if (i) {
11684
+ text += ', ';
11685
+ }
11686
+ text += serializeEntityName((<TypeReferenceNode>node).typeName, getGeneratedNameForNode);
11687
+ });
11688
+ text += ']';
11689
+ }
11690
+ text += '}';
11691
+ return text;
11692
+ }
11693
+
11677
11694
/** Serializes a TypeReferenceNode to an appropriate JS constructor value. Used by the __metadata decorator. */
11678
11695
function serializeTypeReferenceNode(node: TypeReferenceNode, getGeneratedNameForNode: (Node: Node) => string): string | string[] {
11679
11696
// serialization of a TypeReferenceNode uses the following rules:
@@ -11712,7 +11729,12 @@ module ts {
11712
11729
return fallbackPath;
11713
11730
}
11714
11731
else if (type.symbol && type.symbol.valueDeclaration) {
11715
- return serializeEntityName(node.typeName, getGeneratedNameForNode);
11732
+ if (compilerOptions.emitVerboseMetadata) {
11733
+ return serializeEntity(node, getGeneratedNameForNode);
11734
+ }
11735
+ else {
11736
+ return serializeEntityName(node.typeName, getGeneratedNameForNode);
11737
+ }
11716
11738
}
11717
11739
else if (typeHasCallOrConstructSignatures(type)) {
11718
11740
return "Function";
@@ -11764,7 +11786,7 @@ module ts {
11764
11786
break;
11765
11787
}
11766
11788
}
11767
-
11789
+
11768
11790
return "Object";
11769
11791
}
11770
11792
@@ -11778,7 +11800,7 @@ module ts {
11778
11800
// * The serialized type of an AccessorDeclaration is the serialized type of the return type annotation of its getter or parameter type annotation of its setter.
11779
11801
// * The serialized type of any other FunctionLikeDeclaration is "Function".
11780
11802
// * The serialized type of any other node is "void 0".
11781
- //
11803
+ //
11782
11804
// For rules on serializing type annotations, see `serializeTypeNode`.
11783
11805
switch (node.kind) {
11784
11806
case SyntaxKind.ClassDeclaration: return "Function";
@@ -11792,14 +11814,27 @@ module ts {
11792
11814
}
11793
11815
return "void 0";
11794
11816
}
11795
-
11817
+
11818
+ /** Serializes the module of a declaration to a strong value. Used by the __metadata decorator for a class member. */
11819
+ function serializeModuleOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): string | string[] {
11820
+ var moduleDeclaration = <ModuleDeclaration>node.parent.parent;
11821
+ var text = moduleDeclaration.name.text;
11822
+ if (moduleDeclaration.parent && moduleDeclaration.parent.kind === SyntaxKind.ModuleBlock) {
11823
+ text += '.' + serializeModuleOfNode(moduleDeclaration, getGeneratedNameForNode);
11824
+ }
11825
+ if (moduleDeclaration.parent && moduleDeclaration.parent.kind === SyntaxKind.ModuleDeclaration) {
11826
+ text += '.' + serializeModuleOfNode(node.parent, getGeneratedNameForNode);
11827
+ }
11828
+ return text;
11829
+ }
11830
+
11796
11831
/** Serializes the parameter types of a function or the constructor of a class. Used by the __metadata decorator for a method or set accessor. */
11797
11832
function serializeParameterTypesOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): (string | string[])[] {
11798
11833
// serialization of parameter types uses the following rules:
11799
11834
//
11800
11835
// * If the declaration is a class, the parameters of the first constructor with a body are used.
11801
11836
// * If the declaration is function-like and has a body, the parameters of the function are used.
11802
- //
11837
+ //
11803
11838
// For the rules on serializing the type of each parameter declaration, see `serializeTypeOfDeclaration`.
11804
11839
if (node) {
11805
11840
var valueDeclaration: FunctionLikeDeclaration;
@@ -11892,7 +11927,7 @@ module ts {
11892
11927
let isVariableDeclarationOrBindingElement =
11893
11928
n.parent.kind === SyntaxKind.BindingElement || (n.parent.kind === SyntaxKind.VariableDeclaration && (<VariableDeclaration>n.parent).name === n);
11894
11929
11895
- let symbol =
11930
+ let symbol =
11896
11931
(isVariableDeclarationOrBindingElement ? getSymbolOfNode(n.parent) : undefined) ||
11897
11932
getNodeLinks(n).resolvedSymbol ||
11898
11933
resolveName(n, n.text, SymbolFlags.Value | SymbolFlags.Alias, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined);
@@ -11920,7 +11955,7 @@ module ts {
11920
11955
if (!signature) {
11921
11956
return unknownType;
11922
11957
}
11923
-
11958
+
11924
11959
let instantiatedSignature = getSignatureInstantiation(signature, typeArguments);
11925
11960
return getOrCreateTypeFromSignature(instantiatedSignature);
11926
11961
}
@@ -11945,9 +11980,10 @@ module ts {
11945
11980
collectLinkedAliases,
11946
11981
getBlockScopedVariableId,
11947
11982
getReferencedValueDeclaration,
11983
+ serializeModuleOfNode,
11948
11984
serializeTypeOfNode,
11949
11985
serializeParameterTypesOfNode,
11950
- serializeReturnTypeOfNode,
11986
+ serializeReturnTypeOfNode
11951
11987
};
11952
11988
}
11953
11989
0 commit comments