Skip to content

Commit 441c86e

Browse files
committed
added emitVerboseMetadata and skipEmitVarForModule command line options
1 parent 3c9a3c5 commit 441c86e

File tree

5 files changed

+174
-94
lines changed

5 files changed

+174
-94
lines changed

bin/typescriptServices.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,8 @@ declare module ts {
11151115
watch?: boolean;
11161116
separateCompilation?: boolean;
11171117
emitDecoratorMetadata?: boolean;
1118+
emitVerboseMetadata?: boolean;
1119+
skipEmitVarForModule?: boolean;
11181120
[option: string]: string | number | boolean;
11191121
}
11201122
const enum ModuleKind {

src/compiler/checker.ts

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ module ts {
9393
let emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
9494
let anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
9595
let noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined);
96-
96+
9797
let anySignature = createSignature(undefined, undefined, emptyArray, anyType, 0, false, false);
9898
let unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, false, false);
9999

@@ -118,7 +118,7 @@ module ts {
118118
let getGlobalParameterDecoratorType: () => ObjectType;
119119
let getGlobalPropertyDecoratorType: () => ObjectType;
120120
let getGlobalMethodDecoratorType: () => ObjectType;
121-
121+
122122
let tupleTypes: Map<TupleType> = {};
123123
let unionTypes: Map<UnionType> = {};
124124
let stringLiteralTypes: Map<StringLiteralType> = {};
@@ -444,7 +444,7 @@ module ts {
444444
}
445445
break;
446446
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
448448
// or member would result in looking up locals in the method.
449449
//
450450
// function y() {}
@@ -1949,7 +1949,7 @@ module ts {
19491949
case SyntaxKind.ParenthesizedType:
19501950
return isDeclarationVisible(<Declaration>node.parent);
19511951

1952-
// Default binding, import specifier and namespace import is visible
1952+
// Default binding, import specifier and namespace import is visible
19531953
// only on demand so by default it is not visible
19541954
case SyntaxKind.ImportClause:
19551955
case SyntaxKind.NamespaceImport:
@@ -6030,15 +6030,15 @@ module ts {
60306030
// c is represented in the tree as a spread element in an array literal.
60316031
// But c really functions as a rest element, and its purpose is to provide
60326032
// 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
60346034
// if c is not iterable/array-like, we need to act as if we are trying to
60356035
// get the contextual element type from it. So we do something similar to
60366036
// getContextualTypeForElementExpression, which will crucially not error
60376037
// if there is no index type / iterated type.
60386038
let restArrayType = checkExpression((<SpreadElementExpression>e).expression, contextualMapper);
60396039
let restElementType = getIndexTypeOfType(restArrayType, IndexKind.Number) ||
60406040
(languageVersion >= ScriptTarget.ES6 ? checkIteratedType(restArrayType, /*expressionForError*/ undefined) : undefined);
6041-
6041+
60426042
if (restElementType) {
60436043
elementTypes.push(restElementType);
60446044
}
@@ -6939,7 +6939,7 @@ module ts {
69396939
if (!hasCorrectArity(node, args, originalCandidate)) {
69406940
continue;
69416941
}
6942-
6942+
69436943
let candidate: Signature;
69446944
let typeArgumentsAreValid: boolean;
69456945
let inferenceContext = originalCandidate.typeParameters
@@ -8137,7 +8137,7 @@ module ts {
81378137
if (node.questionToken && isBindingPattern(node.name) && func.body) {
81388138
error(node, Diagnostics.A_binding_pattern_parameter_cannot_be_optional_in_an_implementation_signature);
81398139
}
8140-
8140+
81418141
// Only check rest parameter type if it's not a binding pattern. Since binding patterns are
81428142
// not allowed in a rest parameter, we already have an error from checkGrammarParameterList.
81438143
if (node.dotDotDotToken && !isBindingPattern(node.name) && !isArrayType(getTypeOfSymbol(node.symbol))) {
@@ -8806,7 +8806,7 @@ module ts {
88068806
/** Checks a type reference node as an expression. */
88078807
function checkTypeNodeAsExpression(node: TypeNode) {
88088808
// 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
88108810
// serialize the type metadata.
88118811
if (node && node.kind === SyntaxKind.TypeReference) {
88128812
let type = getTypeFromTypeNode(node);
@@ -8821,7 +8821,7 @@ module ts {
88218821
}
88228822

88238823
/**
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
88258825
* an expression if it is a type reference to a type with a value declaration.
88268826
*/
88278827
function checkTypeAnnotationAsExpression(node: AccessorDeclaration | PropertyDeclaration | ParameterDeclaration | MethodDeclaration) {
@@ -8843,7 +8843,7 @@ module ts {
88438843
break;
88448844
}
88458845
}
8846-
8846+
88478847
/** Checks the type annotation of the parameters of a function/method or the constructor of a class as expressions */
88488848
function checkParameterTypeAnnotationsAsExpressions(node: FunctionLikeDeclaration) {
88498849
// ensure all type annotations with a value declaration are checked as an expression
@@ -9456,7 +9456,7 @@ module ts {
94569456
if (allowStringInput) {
94579457
return checkElementTypeOfArrayOrString(inputType, errorNode);
94589458
}
9459-
9459+
94609460
if (isArrayLikeType(inputType)) {
94619461
let indexType = getIndexTypeOfType(inputType, IndexKind.Number);
94629462
if (indexType) {
@@ -10493,9 +10493,9 @@ module ts {
1049310493
}
1049410494
}
1049510495

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,
1049710497
// we need to track this to ensure the correct emit.
10498-
let mergedClass = getDeclarationOfKind(symbol, SyntaxKind.ClassDeclaration);
10498+
let mergedClass = getDeclarationOfKind(symbol, SyntaxKind.ClassDeclaration);
1049910499
if (mergedClass &&
1050010500
inSameLexicalScope(node, mergedClass)) {
1050110501
getNodeLinks(node).flags |= NodeCheckFlags.LexicalModuleMergesWithClass;
@@ -11532,7 +11532,7 @@ module ts {
1153211532
}
1153311533

1153411534
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);
1153611536
if (symbol) {
1153711537
// Whan an identifier resolves to a parented symbol, it references an exported entity from
1153811538
// another declaration of the same internal module.
@@ -11674,6 +11674,23 @@ module ts {
1167411674
}
1167511675
}
1167611676

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+
1167711694
/** Serializes a TypeReferenceNode to an appropriate JS constructor value. Used by the __metadata decorator. */
1167811695
function serializeTypeReferenceNode(node: TypeReferenceNode, getGeneratedNameForNode: (Node: Node) => string): string | string[] {
1167911696
// serialization of a TypeReferenceNode uses the following rules:
@@ -11712,7 +11729,12 @@ module ts {
1171211729
return fallbackPath;
1171311730
}
1171411731
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+
}
1171611738
}
1171711739
else if (typeHasCallOrConstructSignatures(type)) {
1171811740
return "Function";
@@ -11764,7 +11786,7 @@ module ts {
1176411786
break;
1176511787
}
1176611788
}
11767-
11789+
1176811790
return "Object";
1176911791
}
1177011792

@@ -11778,7 +11800,7 @@ module ts {
1177811800
// * 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.
1177911801
// * The serialized type of any other FunctionLikeDeclaration is "Function".
1178011802
// * The serialized type of any other node is "void 0".
11781-
//
11803+
//
1178211804
// For rules on serializing type annotations, see `serializeTypeNode`.
1178311805
switch (node.kind) {
1178411806
case SyntaxKind.ClassDeclaration: return "Function";
@@ -11792,14 +11814,27 @@ module ts {
1179211814
}
1179311815
return "void 0";
1179411816
}
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+
1179611831
/** Serializes the parameter types of a function or the constructor of a class. Used by the __metadata decorator for a method or set accessor. */
1179711832
function serializeParameterTypesOfNode(node: Node, getGeneratedNameForNode: (Node: Node) => string): (string | string[])[] {
1179811833
// serialization of parameter types uses the following rules:
1179911834
//
1180011835
// * If the declaration is a class, the parameters of the first constructor with a body are used.
1180111836
// * If the declaration is function-like and has a body, the parameters of the function are used.
11802-
//
11837+
//
1180311838
// For the rules on serializing the type of each parameter declaration, see `serializeTypeOfDeclaration`.
1180411839
if (node) {
1180511840
var valueDeclaration: FunctionLikeDeclaration;
@@ -11892,7 +11927,7 @@ module ts {
1189211927
let isVariableDeclarationOrBindingElement =
1189311928
n.parent.kind === SyntaxKind.BindingElement || (n.parent.kind === SyntaxKind.VariableDeclaration && (<VariableDeclaration>n.parent).name === n);
1189411929

11895-
let symbol =
11930+
let symbol =
1189611931
(isVariableDeclarationOrBindingElement ? getSymbolOfNode(n.parent) : undefined) ||
1189711932
getNodeLinks(n).resolvedSymbol ||
1189811933
resolveName(n, n.text, SymbolFlags.Value | SymbolFlags.Alias, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined);
@@ -11920,7 +11955,7 @@ module ts {
1192011955
if (!signature) {
1192111956
return unknownType;
1192211957
}
11923-
11958+
1192411959
let instantiatedSignature = getSignatureInstantiation(signature, typeArguments);
1192511960
return getOrCreateTypeFromSignature(instantiatedSignature);
1192611961
}
@@ -11945,9 +11980,10 @@ module ts {
1194511980
collectLinkedAliases,
1194611981
getBlockScopedVariableId,
1194711982
getReferencedValueDeclaration,
11983+
serializeModuleOfNode,
1194811984
serializeTypeOfNode,
1194911985
serializeParameterTypesOfNode,
11950-
serializeReturnTypeOfNode,
11986+
serializeReturnTypeOfNode
1195111987
};
1195211988
}
1195311989

src/compiler/commandLineParser.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ module ts {
192192
name: "emitDecoratorMetadata",
193193
type: "boolean",
194194
experimental: true
195+
},
196+
{
197+
name: "emitVerboseMetadata",
198+
type: "boolean",
199+
experimental: true
200+
},
201+
{
202+
name: "skipEmitVarForModule",
203+
type: "boolean",
204+
experimental: true
195205
}
196206
];
197207

@@ -336,7 +346,7 @@ module ts {
336346
* Parse the contents of a config file (tsconfig.json).
337347
* @param json The contents of the config file to parse
338348
* @param basePath A root directory to resolve relative path entries in the config
339-
* file to. e.g. outDir
349+
* file to. e.g. outDir
340350
*/
341351
export function parseConfigFile(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine {
342352
var errors: Diagnostic[] = [];

0 commit comments

Comments
 (0)