diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d3d8ac1bc1b52..f4d2c2bc02602 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -864,7 +864,7 @@ namespace ts { } // Resolves a qualified name and any involved aliases - function resolveEntityName(name: EntityName | Expression, meaning: SymbolFlags): Symbol { + function resolveEntityName(name: EntityName | Expression, meaning: SymbolFlags, ignoreErrors?: boolean): Symbol { if (nodeIsMissing(name)) { return undefined; } @@ -873,7 +873,7 @@ namespace ts { if (name.kind === SyntaxKind.Identifier) { let message = meaning === SymbolFlags.Namespace ? Diagnostics.Cannot_find_namespace_0 : Diagnostics.Cannot_find_name_0; - symbol = resolveName(name, (name).text, meaning, message, name); + symbol = resolveName(name, (name).text, meaning, !ignoreErrors ? message : undefined, name); if (!symbol) { return undefined; } @@ -882,13 +882,15 @@ namespace ts { let left = name.kind === SyntaxKind.QualifiedName ? (name).left : (name).expression; let right = name.kind === SyntaxKind.QualifiedName ? (name).right : (name).name; - let namespace = resolveEntityName(left, SymbolFlags.Namespace); + let namespace = resolveEntityName(left, SymbolFlags.Namespace, ignoreErrors); if (!namespace || namespace === unknownSymbol || nodeIsMissing(right)) { return undefined; } symbol = getSymbol(getExportsOfSymbol(namespace), right.text, meaning); if (!symbol) { - error(right, Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), declarationNameToString(right)); + if (!ignoreErrors) { + error(right, Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(namespace), declarationNameToString(right)); + } return undefined; } } @@ -2461,10 +2463,6 @@ namespace ts { return links.type; } - function getSetAccessorTypeAnnotationNode(accessor: AccessorDeclaration): TypeNode { - return accessor && accessor.parameters.length > 0 && accessor.parameters[0].type; - } - function getAnnotatedAccessorType(accessor: AccessorDeclaration): Type { if (accessor) { if (accessor.kind === SyntaxKind.GetAccessor) { @@ -3321,6 +3319,15 @@ namespace ts { return getSignaturesOfObjectOrUnionType(getApparentType(type), kind); } + function typeHasConstructSignatures(type: Type): boolean { + let apparentType = getApparentType(type); + if (apparentType.flags & (TypeFlags.ObjectType | TypeFlags.Union)) { + let resolved = resolveObjectOrUnionTypeMembers(type); + return resolved.constructSignatures.length > 0; + } + return false; + } + function typeHasCallOrConstructSignatures(type: Type): boolean { let apparentType = getApparentType(type); if (apparentType.flags & (TypeFlags.ObjectType | TypeFlags.Union)) { @@ -10836,13 +10843,10 @@ namespace ts { // as if it were an expression so that we can emit the type in a value position when we // serialize the type metadata. if (node && node.kind === SyntaxKind.TypeReference) { - let type = getTypeFromTypeNode(node); - let shouldCheckIfUnknownType = type === unknownType && compilerOptions.isolatedModules; - if (!type || (!shouldCheckIfUnknownType && type.flags & (TypeFlags.Intrinsic | TypeFlags.NumberLike | TypeFlags.StringLike))) { - return; - } - if (shouldCheckIfUnknownType || type.symbol.valueDeclaration) { - checkExpression((node).typeName); + let root = getFirstIdentifier((node).typeName); + let rootSymbol = resolveName(root, root.text, SymbolFlags.Value, /*nameNotFoundMessage*/ undefined, /*nameArg*/ undefined); + if (rootSymbol && rootSymbol.flags & SymbolFlags.Alias && !isInTypeQuery(node) && !isConstEnumOrConstEnumOnlyModule(resolveAlias(rootSymbol))) { + markAliasSymbolAsReferenced(rootSymbol); } } } @@ -12680,7 +12684,7 @@ namespace ts { Debug.assert(node.kind === SyntaxKind.Identifier); return node; } - + function checkExternalImportOrExportDeclaration(node: ImportDeclaration | ImportEqualsDeclaration | ExportDeclaration): boolean { let moduleName = getExternalModuleName(node); if (!nodeIsMissing(moduleName) && moduleName.kind !== SyntaxKind.StringLiteral) { @@ -13781,202 +13785,52 @@ namespace ts { return undefined; } - /** Serializes an EntityName (with substitutions) to an appropriate JS constructor value. Used by the __metadata decorator. */ - function serializeEntityName(node: EntityName, fallbackPath?: string[]): string { - if (node.kind === SyntaxKind.Identifier) { - // TODO(ron.buckton): The getExpressionNameSubstitution function has been removed, but calling it - // here has no effect anyway as an identifier in a type name is not an expression. - // var substitution = getExpressionNameSubstitution(node, getGeneratedNameForNode); - // var text = substitution || (node).text; - var text = (node).text; - if (fallbackPath) { - fallbackPath.push(text); - } - else { - return text; - } - } - else { - var left = serializeEntityName((node).left, fallbackPath); - var right = serializeEntityName((node).right, fallbackPath); - if (!fallbackPath) { - return left + "." + right; - } - } + function isFunctionType(type: Type): boolean { + return type.flags & TypeFlags.ObjectType && getSignaturesOfType(type, SignatureKind.Call).length > 0; } + + function isTypeWithValue(node: TypeReferenceNode): TypeWithValueResolutionResult { + // Resolve the symbol as a value to ensure the type can be reached at runtime during emit. + let symbol = resolveEntityName(node.typeName, SymbolFlags.Value, /*ignoreErrors*/ true); + let constructorType = symbol ? getTypeOfSymbol(symbol) : undefined; + if (constructorType && isConstructorType(constructorType)) { + return TypeWithValueResolutionResult.ConstructorTypeWithValue; + } - /** Serializes a TypeReferenceNode to an appropriate JS constructor value. Used by the __metadata decorator. */ - function serializeTypeReferenceNode(node: TypeReferenceNode): string | string[] { - // serialization of a TypeReferenceNode uses the following rules: - // - // * The serialized type of a TypeReference that is `void` is "void 0". - // * The serialized type of a TypeReference that is a `boolean` is "Boolean". - // * The serialized type of a TypeReference that is an enum or `number` is "Number". - // * The serialized type of a TypeReference that is a string literal or `string` is "String". - // * The serialized type of a TypeReference that is a tuple is "Array". - // * The serialized type of a TypeReference that is a `symbol` is "Symbol". - // * The serialized type of a TypeReference with a value declaration is its entity name. - // * The serialized type of a TypeReference with a call or construct signature is "Function". - // * The serialized type of any other type is "Object". let type = getTypeFromTypeNode(node); - if (type.flags & TypeFlags.Void) { - return "void 0"; + if (type === unknownType) { + return TypeWithValueResolutionResult.Unknown; } - else if (type.flags & TypeFlags.Boolean) { - return "Boolean"; + else if (type.flags & TypeFlags.Any) { + return TypeWithValueResolutionResult.ObjectType; } - else if (type.flags & TypeFlags.NumberLike) { - return "Number"; + else if (allConstituentTypesHaveKind(type, TypeFlags.Void)) { + return TypeWithValueResolutionResult.VoidType; } - else if (type.flags & TypeFlags.StringLike) { - return "String"; + else if (allConstituentTypesHaveKind(type, TypeFlags.Boolean)) { + return TypeWithValueResolutionResult.BooleanType; } - else if (type.flags & TypeFlags.Tuple) { - return "Array"; + else if (allConstituentTypesHaveKind(type, TypeFlags.NumberLike)) { + return TypeWithValueResolutionResult.NumberType; } - else if (type.flags & TypeFlags.ESSymbol) { - return "Symbol"; + else if (allConstituentTypesHaveKind(type, TypeFlags.StringLike)) { + return TypeWithValueResolutionResult.StringType; } - else if (type === unknownType) { - var fallbackPath: string[] = []; - serializeEntityName(node.typeName, fallbackPath); - return fallbackPath; + else if (allConstituentTypesHaveKind(type, TypeFlags.Tuple)) { + return TypeWithValueResolutionResult.ArrayType; } - else if (type.symbol && type.symbol.valueDeclaration) { - return serializeEntityName(node.typeName); + else if (allConstituentTypesHaveKind(type, TypeFlags.ESSymbol)) { + return TypeWithValueResolutionResult.ESSymbolType; } - else if (typeHasCallOrConstructSignatures(type)) { - return "Function"; + else if (isFunctionType(type)) { + return TypeWithValueResolutionResult.FunctionType; } - - return "Object"; - } - - /** Serializes a TypeNode to an appropriate JS constructor value. Used by the __metadata decorator. */ - function serializeTypeNode(node: TypeNode | LiteralExpression): string | string[] { - // serialization of a TypeNode uses the following rules: - // - // * The serialized type of `void` is "void 0" (undefined). - // * The serialized type of a parenthesized type is the serialized type of its nested type. - // * The serialized type of a Function or Constructor type is "Function". - // * The serialized type of an Array or Tuple type is "Array". - // * The serialized type of `boolean` is "Boolean". - // * The serialized type of `string` or a string-literal type is "String". - // * The serialized type of a type reference is handled by `serializeTypeReferenceNode`. - // * The serialized type of any other type node is "Object". - if (node) { - switch (node.kind) { - case SyntaxKind.VoidKeyword: - return "void 0"; - case SyntaxKind.ParenthesizedType: - return serializeTypeNode((node).type); - case SyntaxKind.FunctionType: - case SyntaxKind.ConstructorType: - return "Function"; - case SyntaxKind.ArrayType: - case SyntaxKind.TupleType: - return "Array"; - case SyntaxKind.BooleanKeyword: - return "Boolean"; - case SyntaxKind.StringKeyword: - case SyntaxKind.StringLiteral: - return "String"; - case SyntaxKind.NumberKeyword: - return "Number"; - case SyntaxKind.TypeReference: - return serializeTypeReferenceNode(node); - case SyntaxKind.TypeQuery: - case SyntaxKind.TypeLiteral: - case SyntaxKind.UnionType: - case SyntaxKind.AnyKeyword: - break; - default: - Debug.fail("Cannot serialize unexpected type node."); - break; - } + else if (isArrayType(type)) { + return TypeWithValueResolutionResult.ArrayType; } - - return "Object"; - } - - /** Serializes the type of a declaration to an appropriate JS constructor value. Used by the __metadata decorator for a class member. */ - function serializeTypeOfNode(node: Node): string | string[] { - // serialization of the type of a declaration uses the following rules: - // - // * The serialized type of a ClassDeclaration is "Function" - // * The serialized type of a ParameterDeclaration is the serialized type of its type annotation. - // * The serialized type of a PropertyDeclaration is the serialized type of its type annotation. - // * 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. - // * The serialized type of any other FunctionLikeDeclaration is "Function". - // * The serialized type of any other node is "void 0". - // - // For rules on serializing type annotations, see `serializeTypeNode`. - switch (node.kind) { - case SyntaxKind.ClassDeclaration: return "Function"; - case SyntaxKind.PropertyDeclaration: return serializeTypeNode((node).type); - case SyntaxKind.Parameter: return serializeTypeNode((node).type); - case SyntaxKind.GetAccessor: return serializeTypeNode((node).type); - case SyntaxKind.SetAccessor: return serializeTypeNode(getSetAccessorTypeAnnotationNode(node)); - } - if (isFunctionLike(node)) { - return "Function"; - } - return "void 0"; - } - - /** Serializes the parameter types of a function or the constructor of a class. Used by the __metadata decorator for a method or set accessor. */ - function serializeParameterTypesOfNode(node: Node): (string | string[])[] { - // serialization of parameter types uses the following rules: - // - // * If the declaration is a class, the parameters of the first constructor with a body are used. - // * If the declaration is function-like and has a body, the parameters of the function are used. - // - // For the rules on serializing the type of each parameter declaration, see `serializeTypeOfDeclaration`. - if (node) { - var valueDeclaration: FunctionLikeDeclaration; - if (node.kind === SyntaxKind.ClassDeclaration) { - valueDeclaration = getFirstConstructorWithBody(node); - } - else if (isFunctionLike(node) && nodeIsPresent((node).body)) { - valueDeclaration = node; - } - if (valueDeclaration) { - var result: (string | string[])[]; - var parameters = valueDeclaration.parameters; - var parameterCount = parameters.length; - if (parameterCount > 0) { - result = new Array(parameterCount); - for (var i = 0; i < parameterCount; i++) { - if (parameters[i].dotDotDotToken) { - var parameterType = parameters[i].type; - if (parameterType.kind === SyntaxKind.ArrayType) { - parameterType = (parameterType).elementType; - } - else if (parameterType.kind === SyntaxKind.TypeReference && (parameterType).typeArguments && (parameterType).typeArguments.length === 1) { - parameterType = (parameterType).typeArguments[0]; - } - else { - parameterType = undefined; - } - result[i] = serializeTypeNode(parameterType); - } - else { - result[i] = serializeTypeOfNode(parameters[i]); - } - } - return result; - } - } - } - return emptyArray; - } - - /** Serializes the return type of function. Used by the __metadata decorator for a method. */ - function serializeReturnTypeOfNode(node: Node): string | string[] { - if (node && isFunctionLike(node)) { - return serializeTypeNode((node).type); + else { + return TypeWithValueResolutionResult.ObjectType; } - return "void 0"; } function writeTypeOfDeclaration(declaration: AccessorDeclaration | VariableLikeDeclaration, enclosingDeclaration: Node, flags: TypeFormatFlags, writer: SymbolWriter) { @@ -14076,9 +13930,7 @@ namespace ts { collectLinkedAliases, getBlockScopedVariableId, getReferencedValueDeclaration, - serializeTypeOfNode, - serializeParameterTypesOfNode, - serializeReturnTypeOfNode, + isTypeWithValue, }; } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 9a05f145e6d8a..e0f86b0411816 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -2069,13 +2069,52 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi emit(node.name); decreaseIndentIf(indentedBeforeDot, indentedAfterDot); } - + function emitQualifiedName(node: QualifiedName) { emit(node.left); write("."); emit(node.right); } + function emitQualifiedNameAsExpression(node: QualifiedName, useFallback: boolean) { + if (node.left.kind === SyntaxKind.Identifier) { + emitEntityNameAsExpression(node.left, useFallback); + } + else if (useFallback) { + let temp = createAndRecordTempVariable(TempFlags.Auto); + write("("); + emitNodeWithoutSourceMap(temp); + write(" = "); + emitEntityNameAsExpression(node.left, /*useFallback*/ true); + write(") && "); + emitNodeWithoutSourceMap(temp); + } + else { + emitEntityNameAsExpression(node.left, /*useFallback*/ false); + } + + write("."); + emitNodeWithoutSourceMap(node.right); + } + + function emitEntityNameAsExpression(node: EntityName, useFallback: boolean) { + switch (node.kind) { + case SyntaxKind.Identifier: + if (useFallback) { + write("typeof "); + emitExpressionIdentifier(node); + write(" !== 'undefined' && "); + } + + emitExpressionIdentifier(node); + break; + + case SyntaxKind.QualifiedName: + emitQualifiedNameAsExpression(node, useFallback); + break; + } + } + function emitIndexedAccess(node: ElementAccessExpression) { if (tryEmitConstantValue(node)) { return; @@ -4750,83 +4789,265 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi } return false; } + + /** Serializes the type of a declaration to an appropriate JS constructor value. Used by the __metadata decorator for a class member. */ + function emitSerializedTypeOfNode(node: Node) { + // serialization of the type of a declaration uses the following rules: + // + // * The serialized type of a ClassDeclaration is "Function" + // * The serialized type of a ParameterDeclaration is the serialized type of its type annotation. + // * The serialized type of a PropertyDeclaration is the serialized type of its type annotation. + // * 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. + // * The serialized type of any other FunctionLikeDeclaration is "Function". + // * The serialized type of any other node is "void 0". + // + // For rules on serializing type annotations, see `serializeTypeNode`. + switch (node.kind) { + case SyntaxKind.ClassDeclaration: + write("Function"); + return; + + case SyntaxKind.PropertyDeclaration: + emitSerializedTypeNode((node).type); + return; + + case SyntaxKind.Parameter: + emitSerializedTypeNode((node).type); + return; + + case SyntaxKind.GetAccessor: + emitSerializedTypeNode((node).type); + return; + + case SyntaxKind.SetAccessor: + emitSerializedTypeNode(getSetAccessorTypeAnnotationNode(node)); + return; + + } + + if (isFunctionLike(node)) { + write("Function"); + return; + } + + write("void 0"); + } + + function emitSerializedTypeNode(node: TypeNode) { + switch (node.kind) { + case SyntaxKind.VoidKeyword: + write("void 0"); + return; + + case SyntaxKind.ParenthesizedType: + emitSerializedTypeNode((node).type); + return; + + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + write("Function"); + return; + + case SyntaxKind.ArrayType: + case SyntaxKind.TupleType: + write("Array"); + return; + + case SyntaxKind.BooleanKeyword: + write("Boolean"); + return; + case SyntaxKind.StringKeyword: + case SyntaxKind.StringLiteral: + write("String"); + return; + + case SyntaxKind.NumberKeyword: + write("Number"); + return; + + case SyntaxKind.SymbolKeyword: + write("Symbol"); + return; + + case SyntaxKind.TypeReference: + emitSerializedTypeReferenceNode(node); + return; + + case SyntaxKind.TypeQuery: + case SyntaxKind.TypeLiteral: + case SyntaxKind.UnionType: + case SyntaxKind.AnyKeyword: + break; + + default: + Debug.fail("Cannot serialize unexpected type node."); + break; + } + + write("Object"); + } + + /** Serializes a TypeReferenceNode to an appropriate JS constructor value. Used by the __metadata decorator. */ + function emitSerializedTypeReferenceNode(node: TypeReferenceNode) { + let typeName = node.typeName; + let result = resolver.isTypeWithValue(node); + switch (result) { + case TypeWithValueResolutionResult.Unknown: + let temp = createAndRecordTempVariable(TempFlags.Auto); + write("(typeof ("); + emitNodeWithoutSourceMap(temp); + write(" = ") + emitEntityNameAsExpression(typeName, /*useFallback*/ true); + write(") === 'function' && "); + emitNodeWithoutSourceMap(temp); + write(") || Object"); + break; + + case TypeWithValueResolutionResult.ConstructorTypeWithValue: + emitEntityNameAsExpression(typeName, /*useFallback*/ false); + break; + + case TypeWithValueResolutionResult.VoidType: + write("void 0"); + break; + + case TypeWithValueResolutionResult.BooleanType: + write("Boolean"); + break; + + case TypeWithValueResolutionResult.NumberType: + write("Number"); + break; + + case TypeWithValueResolutionResult.StringType: + write("String"); + break; + + case TypeWithValueResolutionResult.ArrayType: + write("Array"); + break; + + case TypeWithValueResolutionResult.ESSymbolType: + if (languageVersion < ScriptTarget.ES6) { + write("typeof Symbol === 'function' ? Symbol : Object"); + } + else { + write("Symbol"); + } + break; + + case TypeWithValueResolutionResult.FunctionType: + write("Function"); + break; + + case TypeWithValueResolutionResult.ObjectType: + write("Object"); + break; + } + } + + /** Serializes the parameter types of a function or the constructor of a class. Used by the __metadata decorator for a method or set accessor. */ + function emitSerializedParameterTypesOfNode(node: Node) { + // serialization of parameter types uses the following rules: + // + // * If the declaration is a class, the parameters of the first constructor with a body are used. + // * If the declaration is function-like and has a body, the parameters of the function are used. + // + // For the rules on serializing the type of each parameter declaration, see `serializeTypeOfDeclaration`. + if (node) { + var valueDeclaration: FunctionLikeDeclaration; + if (node.kind === SyntaxKind.ClassDeclaration) { + valueDeclaration = getFirstConstructorWithBody(node); + } + else if (isFunctionLike(node) && nodeIsPresent((node).body)) { + valueDeclaration = node; + } + + if (valueDeclaration) { + var parameters = valueDeclaration.parameters; + var parameterCount = parameters.length; + if (parameterCount > 0) { + for (var i = 0; i < parameterCount; i++) { + if (i > 0) { + write(", "); + } + + if (parameters[i].dotDotDotToken) { + var parameterType = parameters[i].type; + if (parameterType.kind === SyntaxKind.ArrayType) { + parameterType = (parameterType).elementType; + } + else if (parameterType.kind === SyntaxKind.TypeReference && (parameterType).typeArguments && (parameterType).typeArguments.length === 1) { + parameterType = (parameterType).typeArguments[0]; + } + else { + parameterType = undefined; + } + + emitSerializedTypeNode(parameterType); + } + else { + emitSerializedTypeOfNode(parameters[i]); + } + } + } + } + } + } + + /** Serializes the return type of function. Used by the __metadata decorator for a method. */ + function emitSerializedReturnTypeOfNode(node: Node): string | string[] { + if (node && isFunctionLike(node)) { + emitSerializedTypeNode((node).type); + return; + } + + write("void 0"); + } + + function emitSerializedTypeMetadata(node: Declaration, writeComma: boolean): number { // This method emits the serialized type metadata for a decorator target. // The caller should have already tested whether the node has decorators. let argumentsWritten = 0; if (compilerOptions.emitDecoratorMetadata) { if (shouldEmitTypeMetadata(node)) { - var serializedType = resolver.serializeTypeOfNode(node); - if (serializedType) { - if (writeComma) { - write(", "); - } - writeLine(); - write("__metadata('design:type', "); - emitSerializedType(node, serializedType); - write(")"); - argumentsWritten++; + if (writeComma) { + write(", "); } + writeLine(); + write("__metadata('design:type', "); + emitSerializedTypeOfNode(node); + write(")"); + argumentsWritten++; } if (shouldEmitParamTypesMetadata(node)) { - var serializedTypes = resolver.serializeParameterTypesOfNode(node); - if (serializedTypes) { - if (writeComma || argumentsWritten) { - write(", "); - } - writeLine(); - write("__metadata('design:paramtypes', ["); - for (var i = 0; i < serializedTypes.length; ++i) { - if (i > 0) { - write(", "); - } - emitSerializedType(node, serializedTypes[i]); - } - write("])"); - argumentsWritten++; + if (writeComma || argumentsWritten) { + write(", "); } + writeLine(); + write("__metadata('design:paramtypes', ["); + emitSerializedParameterTypesOfNode(node); + write("])"); + argumentsWritten++; } if (shouldEmitReturnTypeMetadata(node)) { - var serializedType = resolver.serializeReturnTypeOfNode(node); - if (serializedType) { - if (writeComma || argumentsWritten) { - write(", "); - } - writeLine(); - write("__metadata('design:returntype', "); - emitSerializedType(node, serializedType); - write(")"); - argumentsWritten++; + if (writeComma || argumentsWritten) { + write(", "); } + + writeLine(); + write("__metadata('design:returntype', "); + emitSerializedReturnTypeOfNode(node); + write(")"); + argumentsWritten++; } } + return argumentsWritten; } - - function serializeTypeNameSegment(location: Node, path: string[], index: number): string { - switch (index) { - case 0: - return `typeof ${path[index]} !== 'undefined' && ${path[index]}`; - case 1: - return `${serializeTypeNameSegment(location, path, index - 1) }.${path[index]}`; - default: - let temp = createAndRecordTempVariable(TempFlags.Auto).text; - return `(${temp} = ${serializeTypeNameSegment(location, path, index - 1) }) && ${temp}.${path[index]}`; - } - } - - function emitSerializedType(location: Node, name: string | string[]): void { - if (typeof name === "string") { - write(name); - return; - } - else { - Debug.assert(name.length > 0, "Invalid serialized type name"); - write(`(${serializeTypeNameSegment(location, name, name.length - 1) }) || Object`); - } - } - + function emitInterfaceDeclaration(node: InterfaceDeclaration) { emitOnlyPinnedOrTripleSlashComments(node); } @@ -5933,6 +6154,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi Debug.assert(!exportFunctionForFile); // make sure that name of 'exports' function does not conflict with existing identifiers exportFunctionForFile = makeUniqueName("exports"); + writeLine(); write("System.register("); if (node.moduleName) { write(`"${node.moduleName}", `); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 4617ad98b0240..6b0e930dadedd 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1514,6 +1514,20 @@ namespace ts { export interface SymbolAccessiblityResult extends SymbolVisibilityResult { errorModuleName?: string // If the symbol is not visible from module, module's name } + + /* @internal */ + export enum TypeWithValueResolutionResult { + Unknown, + ConstructorTypeWithValue, + VoidType, + NumberType, + StringType, + BooleanType, + ArrayType, + ESSymbolType, + FunctionType, + ObjectType, + } /* @internal */ export interface EmitResolver { @@ -1538,9 +1552,7 @@ namespace ts { getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number; getBlockScopedVariableId(node: Identifier): number; getReferencedValueDeclaration(reference: Identifier): Declaration; - serializeTypeOfNode(node: Node): string | string[]; - serializeParameterTypesOfNode(node: Node): (string | string[])[]; - serializeReturnTypeOfNode(node: Node): string | string[]; + isTypeWithValue(node: TypeReferenceNode): TypeWithValueResolutionResult; } export const enum SymbolFlags { diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index e66e1925519ed..3f36f451df944 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -1704,6 +1704,10 @@ namespace ts { }); } + export function getSetAccessorTypeAnnotationNode(accessor: AccessorDeclaration): TypeNode { + return accessor && accessor.parameters.length > 0 && accessor.parameters[0].type; + } + export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean { if (!isDeclarationFile(sourceFile)) { if ((isExternalModule(sourceFile) || !compilerOptions.out)) {