mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into 6229-known-length-tuples
This commit is contained in:
+2
-1
@@ -16,4 +16,5 @@ Jakefile.js
|
||||
.gitattributes
|
||||
.settings/
|
||||
.travis.yml
|
||||
.vscode/
|
||||
.vscode/
|
||||
test.config
|
||||
@@ -16,6 +16,7 @@ matrix:
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
- release-2.5
|
||||
|
||||
install:
|
||||
- npm uninstall typescript --no-save
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
"name": "typescript",
|
||||
"author": "Microsoft Corp.",
|
||||
"homepage": "http://typescriptlang.org/",
|
||||
"version": "2.5.0",
|
||||
"version": "2.6.0",
|
||||
"license": "Apache-2.0",
|
||||
"description": "TypeScript is a language for application scale JavaScript development",
|
||||
"keywords": [
|
||||
|
||||
@@ -7,11 +7,15 @@ function endsWith(s: string, suffix: string) {
|
||||
return s.lastIndexOf(suffix, s.length - suffix.length) !== -1;
|
||||
}
|
||||
|
||||
function isStringEnum(declaration: ts.EnumDeclaration) {
|
||||
return declaration.members.length && declaration.members.every(m => m.initializer && m.initializer.kind === ts.SyntaxKind.StringLiteral);
|
||||
}
|
||||
|
||||
class DeclarationsWalker {
|
||||
private visitedTypes: ts.Type[] = [];
|
||||
private text = "";
|
||||
private removedTypes: ts.Type[] = [];
|
||||
|
||||
|
||||
private constructor(private typeChecker: ts.TypeChecker, private protocolFile: ts.SourceFile) {
|
||||
}
|
||||
|
||||
@@ -19,7 +23,7 @@ class DeclarationsWalker {
|
||||
let text = "declare namespace ts.server.protocol {\n";
|
||||
var walker = new DeclarationsWalker(typeChecker, protocolFile);
|
||||
walker.visitTypeNodes(protocolFile);
|
||||
text = walker.text
|
||||
text = walker.text
|
||||
? `declare namespace ts.server.protocol {\n${walker.text}}`
|
||||
: "";
|
||||
if (walker.removedTypes) {
|
||||
@@ -52,7 +56,7 @@ class DeclarationsWalker {
|
||||
if (sourceFile === this.protocolFile || path.basename(sourceFile.fileName) === "lib.d.ts") {
|
||||
return;
|
||||
}
|
||||
if (decl.kind === ts.SyntaxKind.EnumDeclaration) {
|
||||
if (decl.kind === ts.SyntaxKind.EnumDeclaration && !isStringEnum(decl as ts.EnumDeclaration)) {
|
||||
this.removedTypes.push(type);
|
||||
return;
|
||||
}
|
||||
@@ -91,7 +95,7 @@ class DeclarationsWalker {
|
||||
for (const type of heritageClauses[0].types) {
|
||||
this.processTypeOfNode(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -110,7 +114,7 @@ class DeclarationsWalker {
|
||||
this.processType(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function writeProtocolFile(outputFile: string, protocolTs: string, typeScriptServicesDts: string) {
|
||||
|
||||
+65
-63
@@ -139,6 +139,9 @@ namespace ts {
|
||||
node = getParseTreeNode(node, isExportSpecifier);
|
||||
return node ? getExportSpecifierLocalTargetSymbol(node) : undefined;
|
||||
},
|
||||
getExportSymbolOfSymbol(symbol) {
|
||||
return getMergedSymbol(symbol.exportSymbol || symbol);
|
||||
},
|
||||
getTypeAtLocation: node => {
|
||||
node = getParseTreeNode(node);
|
||||
return node ? getTypeOfNode(node) : unknownType;
|
||||
@@ -1692,7 +1695,6 @@ namespace ts {
|
||||
if (ambientModule) {
|
||||
return ambientModule;
|
||||
}
|
||||
const isRelative = isExternalModuleNameRelative(moduleReference);
|
||||
const resolvedModule = getResolvedModule(getSourceFileOfNode(location), moduleReference);
|
||||
const resolutionDiagnostic = resolvedModule && getResolutionDiagnostic(compilerOptions, resolvedModule);
|
||||
const sourceFile = resolvedModule && !resolutionDiagnostic && host.getSourceFile(resolvedModule.resolvedFileName);
|
||||
@@ -1716,7 +1718,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// May be an untyped module. If so, ignore resolutionDiagnostic.
|
||||
if (!isRelative && resolvedModule && !extensionIsTypeScript(resolvedModule.extension)) {
|
||||
if (resolvedModule && resolvedModule.isExternalLibraryImport && !extensionIsTypeScript(resolvedModule.extension)) {
|
||||
if (isForAugmentation) {
|
||||
const diag = Diagnostics.Invalid_module_name_in_augmentation_Module_0_resolves_to_an_untyped_module_at_1_which_cannot_be_augmented;
|
||||
error(errorNode, diag, moduleReference, resolvedModule.resolvedFileName);
|
||||
@@ -2154,6 +2156,11 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function isTypeSymbolAccessible(typeSymbol: Symbol, enclosingDeclaration: Node): boolean {
|
||||
const access = isSymbolAccessible(typeSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false);
|
||||
return access.accessibility === SymbolAccessibility.Accessible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given symbol in given enclosing declaration is accessible and mark all associated alias to be visible if requested
|
||||
*
|
||||
@@ -2484,8 +2491,7 @@ namespace ts {
|
||||
// Ignore constraint/default when creating a usage (as opposed to declaration) of a type parameter.
|
||||
return createTypeReferenceNode(name, /*typeArguments*/ undefined);
|
||||
}
|
||||
if (!inTypeAlias && type.aliasSymbol &&
|
||||
isSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false).accessibility === SymbolAccessibility.Accessible) {
|
||||
if (!inTypeAlias && type.aliasSymbol && isTypeSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration)) {
|
||||
const name = symbolToTypeReferenceName(type.aliasSymbol);
|
||||
const typeArgumentNodes = mapToTypeNodes(type.aliasTypeArguments, context);
|
||||
return createTypeReferenceNode(name, typeArgumentNodes);
|
||||
@@ -3252,7 +3258,7 @@ namespace ts {
|
||||
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, nextFlags);
|
||||
}
|
||||
else if (!(flags & TypeFormatFlags.InTypeAlias) && type.aliasSymbol &&
|
||||
isSymbolAccessible(type.aliasSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false).accessibility === SymbolAccessibility.Accessible) {
|
||||
((flags & TypeFormatFlags.UseAliasDefinedOutsideCurrentScope) || isTypeSymbolAccessible(type.aliasSymbol, enclosingDeclaration))) {
|
||||
const typeArguments = type.aliasTypeArguments;
|
||||
writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, length(typeArguments), nextFlags);
|
||||
}
|
||||
@@ -4924,7 +4930,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function resolveBaseTypesOfClass(type: InterfaceType): void {
|
||||
type.resolvedBaseTypes = type.resolvedBaseTypes || emptyArray;
|
||||
type.resolvedBaseTypes = emptyArray;
|
||||
const baseConstructorType = getApparentType(getBaseConstructorTypeOfClass(type));
|
||||
if (!(baseConstructorType.flags & (TypeFlags.Object | TypeFlags.Intersection | TypeFlags.Any))) {
|
||||
return;
|
||||
@@ -4971,17 +4977,12 @@ namespace ts {
|
||||
error(baseTypeNode.expression, Diagnostics.Base_constructor_return_type_0_is_not_a_class_or_interface_type, typeToString(baseType));
|
||||
return;
|
||||
}
|
||||
if (type === baseType || hasBaseType(<BaseType>baseType, type)) {
|
||||
if (type === baseType || hasBaseType(baseType, type)) {
|
||||
error(valueDecl, Diagnostics.Type_0_recursively_references_itself_as_a_base_type,
|
||||
typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType));
|
||||
return;
|
||||
}
|
||||
if (type.resolvedBaseTypes === emptyArray) {
|
||||
type.resolvedBaseTypes = [<ObjectType>baseType];
|
||||
}
|
||||
else {
|
||||
type.resolvedBaseTypes.push(<ObjectType>baseType);
|
||||
}
|
||||
type.resolvedBaseTypes = [baseType];
|
||||
}
|
||||
|
||||
function areAllOuterTypeParametersApplied(type: Type): boolean {
|
||||
@@ -4998,7 +4999,7 @@ namespace ts {
|
||||
|
||||
// A valid base type is `any`, any non-generic object type or intersection of non-generic
|
||||
// object types.
|
||||
function isValidBaseType(type: Type): boolean {
|
||||
function isValidBaseType(type: Type): type is BaseType {
|
||||
return type.flags & (TypeFlags.Object | TypeFlags.NonPrimitive | TypeFlags.Any) && !isGenericMappedType(type) ||
|
||||
type.flags & TypeFlags.Intersection && !forEach((<IntersectionType>type).types, t => !isValidBaseType(t));
|
||||
}
|
||||
@@ -5011,12 +5012,12 @@ namespace ts {
|
||||
const baseType = getTypeFromTypeNode(node);
|
||||
if (baseType !== unknownType) {
|
||||
if (isValidBaseType(baseType)) {
|
||||
if (type !== baseType && !hasBaseType(<BaseType>baseType, type)) {
|
||||
if (type !== baseType && !hasBaseType(baseType, type)) {
|
||||
if (type.resolvedBaseTypes === emptyArray) {
|
||||
type.resolvedBaseTypes = [<ObjectType>baseType];
|
||||
}
|
||||
else {
|
||||
type.resolvedBaseTypes.push(<ObjectType>baseType);
|
||||
type.resolvedBaseTypes.push(baseType);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -5652,17 +5653,12 @@ namespace ts {
|
||||
else {
|
||||
// Combinations of function, class, enum and module
|
||||
let members = emptySymbols;
|
||||
let constructSignatures: Signature[] = emptyArray;
|
||||
let stringIndexInfo: IndexInfo = undefined;
|
||||
if (symbol.exports) {
|
||||
members = getExportsOfSymbol(symbol);
|
||||
}
|
||||
if (symbol.flags & SymbolFlags.Class) {
|
||||
const classType = getDeclaredTypeOfClassOrInterface(symbol);
|
||||
constructSignatures = getSignaturesOfSymbol(symbol.members.get(InternalSymbolName.Constructor));
|
||||
if (!constructSignatures.length) {
|
||||
constructSignatures = getDefaultConstructSignatures(classType);
|
||||
}
|
||||
const baseConstructorType = getBaseConstructorTypeOfClass(classType);
|
||||
if (baseConstructorType.flags & (TypeFlags.Object | TypeFlags.Intersection | TypeFlags.TypeVariable)) {
|
||||
members = createSymbolTable(getNamedMembers(members));
|
||||
@@ -5673,7 +5669,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
const numberIndexInfo = symbol.flags & SymbolFlags.Enum ? enumNumberIndexInfo : undefined;
|
||||
setStructuredTypeMembers(type, members, emptyArray, constructSignatures, stringIndexInfo, numberIndexInfo);
|
||||
setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, numberIndexInfo);
|
||||
// We resolve the members before computing the signatures because a signature may use
|
||||
// typeof with a qualified name expression that circularly references the type we are
|
||||
// in the process of resolving (see issue #6072). The temporarily empty signature list
|
||||
@@ -5681,6 +5677,15 @@ namespace ts {
|
||||
if (symbol.flags & (SymbolFlags.Function | SymbolFlags.Method)) {
|
||||
(<ResolvedType>type).callSignatures = getSignaturesOfSymbol(symbol);
|
||||
}
|
||||
// And likewise for construct signatures for classes
|
||||
if (symbol.flags & SymbolFlags.Class) {
|
||||
const classType = getDeclaredTypeOfClassOrInterface(symbol);
|
||||
let constructSignatures = getSignaturesOfSymbol(symbol.members.get(InternalSymbolName.Constructor));
|
||||
if (!constructSignatures.length) {
|
||||
constructSignatures = getDefaultConstructSignatures(classType);
|
||||
}
|
||||
(<ResolvedType>type).constructSignatures = constructSignatures;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6576,6 +6581,10 @@ namespace ts {
|
||||
return signature.resolvedReturnType;
|
||||
}
|
||||
|
||||
function isResolvingReturnTypeOfSignature(signature: Signature) {
|
||||
return !signature.resolvedReturnType && findResolutionCycleStartIndex(signature, TypeSystemPropertyName.ResolvedReturnType) >= 0;
|
||||
}
|
||||
|
||||
function getRestTypeOfSignature(signature: Signature): Type {
|
||||
if (signature.hasRestParameter) {
|
||||
const type = getTypeOfSymbol(lastOrUndefined(signature.parameters));
|
||||
@@ -7572,7 +7581,6 @@ namespace ts {
|
||||
if (indexInfo) {
|
||||
if (accessExpression && indexInfo.isReadonly && (isAssignmentTarget(accessExpression) || isDeleteTarget(accessExpression))) {
|
||||
error(accessExpression, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(objectType));
|
||||
return unknownType;
|
||||
}
|
||||
return indexInfo.type;
|
||||
}
|
||||
@@ -7613,7 +7621,6 @@ namespace ts {
|
||||
}
|
||||
if (accessNode.kind === SyntaxKind.ElementAccessExpression && isAssignmentTarget(accessNode) && type.declaration.readonlyToken) {
|
||||
error(accessNode, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(type));
|
||||
return unknownType;
|
||||
}
|
||||
}
|
||||
const mapper = createTypeMapper([getTypeParameterFromMappedType(type)], [indexType]);
|
||||
@@ -12955,7 +12962,7 @@ namespace ts {
|
||||
// Otherwise, if the containing function is contextually typed by a function type with exactly one call signature
|
||||
// and that call signature is non-generic, return statements are contextually typed by the return type of the signature
|
||||
const signature = getContextualSignatureForFunctionLikeDeclaration(<FunctionExpression>functionDecl);
|
||||
if (signature) {
|
||||
if (signature && !isResolvingReturnTypeOfSignature(signature)) {
|
||||
return getReturnTypeOfSignature(signature);
|
||||
}
|
||||
|
||||
@@ -14611,9 +14618,12 @@ namespace ts {
|
||||
}
|
||||
const prop = getPropertyOfType(apparentType, right.escapedText);
|
||||
if (!prop) {
|
||||
const stringIndexType = getIndexTypeOfType(apparentType, IndexKind.String);
|
||||
if (stringIndexType) {
|
||||
return stringIndexType;
|
||||
const indexInfo = getIndexInfoOfType(apparentType, IndexKind.String);
|
||||
if (indexInfo && indexInfo.type) {
|
||||
if (indexInfo.isReadonly && (isAssignmentTarget(node) || isDeleteTarget(node))) {
|
||||
error(node, Diagnostics.Index_signature_in_type_0_only_permits_reading, typeToString(apparentType));
|
||||
}
|
||||
return indexInfo.type;
|
||||
}
|
||||
if (right.escapedText && !checkAndReportErrorForExtendingInterface(node)) {
|
||||
reportNonexistentProperty(right, type.flags & TypeFlags.TypeParameter && (type as TypeParameter).isThisType ? apparentType : type);
|
||||
@@ -16358,7 +16368,7 @@ namespace ts {
|
||||
*/
|
||||
function checkCallExpression(node: CallExpression | NewExpression): Type {
|
||||
// Grammar checking; stop grammar-checking if checkGrammarTypeArguments return true
|
||||
checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node, node.arguments);
|
||||
checkGrammarTypeArguments(node, node.typeArguments) || checkGrammarArguments(node.arguments);
|
||||
|
||||
const signature = getResolvedSignature(node);
|
||||
|
||||
@@ -16406,7 +16416,7 @@ namespace ts {
|
||||
|
||||
function checkImportCallExpression(node: ImportCall): Type {
|
||||
// Check grammar of dynamic import
|
||||
checkGrammarArguments(node, node.arguments) || checkGrammarImportCallExpression(node);
|
||||
checkGrammarArguments(node.arguments) || checkGrammarImportCallExpression(node);
|
||||
|
||||
if (node.arguments.length === 0) {
|
||||
return createPromiseReturnType(node, anyType);
|
||||
@@ -17134,7 +17144,9 @@ namespace ts {
|
||||
if (operandType === silentNeverType) {
|
||||
return silentNeverType;
|
||||
}
|
||||
const ok = checkArithmeticOperandType(node.operand, checkNonNullType(operandType, node.operand),
|
||||
const ok = checkArithmeticOperandType(
|
||||
node.operand,
|
||||
checkNonNullType(operandType, node.operand),
|
||||
Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_or_an_enum_type);
|
||||
if (ok) {
|
||||
// run check only if former checks succeeded to avoid reporting cascading errors
|
||||
@@ -18693,7 +18705,7 @@ namespace ts {
|
||||
function checkTypeReferenceNode(node: TypeReferenceNode | ExpressionWithTypeArguments) {
|
||||
checkGrammarTypeArguments(node, node.typeArguments);
|
||||
if (node.kind === SyntaxKind.TypeReference && node.typeName.jsdocDotPos !== undefined && !isInJavaScriptFile(node) && !isInJSDoc(node)) {
|
||||
grammarErrorAtPos(getSourceFileOfNode(node), node.typeName.jsdocDotPos, 1, Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments);
|
||||
grammarErrorAtPos(node, node.typeName.jsdocDotPos, 1, Diagnostics.JSDoc_types_can_only_be_used_inside_documentation_comments);
|
||||
|
||||
}
|
||||
const type = getTypeFromTypeReference(node);
|
||||
@@ -18765,13 +18777,10 @@ namespace ts {
|
||||
if (isTypeAssignableTo(indexType, getIndexType(objectType))) {
|
||||
return type;
|
||||
}
|
||||
// Check if we're indexing with a numeric type and the object type is a generic
|
||||
// type with a constraint that has a numeric index signature.
|
||||
if (maybeTypeOfKind(objectType, TypeFlags.TypeVariable) && isTypeAssignableToKind(indexType, TypeFlags.NumberLike)) {
|
||||
const constraint = getBaseConstraintOfType(objectType);
|
||||
if (constraint && getIndexInfoOfType(constraint, IndexKind.Number)) {
|
||||
return type;
|
||||
}
|
||||
// Check if we're indexing with a numeric type and if either object or index types
|
||||
// is a generic type with a constraint that has a numeric index signature.
|
||||
if (getIndexInfoOfType(getApparentType(objectType), IndexKind.Number) && isTypeAssignableToKind(indexType, TypeFlags.NumberLike)) {
|
||||
return type;
|
||||
}
|
||||
error(accessNode, Diagnostics.Type_0_cannot_be_used_to_index_type_1, typeToString(indexType), typeToString(objectType));
|
||||
return type;
|
||||
@@ -19651,7 +19660,7 @@ namespace ts {
|
||||
// checkFunctionOrConstructorSymbol wouldn't be called if we didnt ignore javascript function.
|
||||
const firstDeclaration = find(localSymbol.declarations,
|
||||
// Get first non javascript function declaration
|
||||
declaration => declaration.kind === node.kind && !isSourceFileJavaScript(getSourceFileOfNode(declaration)));
|
||||
declaration => declaration.kind === node.kind && !(declaration.flags & NodeFlags.JavaScriptFile));
|
||||
|
||||
// Only type check the symbol once
|
||||
if (node === firstDeclaration) {
|
||||
@@ -22917,10 +22926,7 @@ namespace ts {
|
||||
// index access
|
||||
if (node.parent.kind === SyntaxKind.ElementAccessExpression && (<ElementAccessExpression>node.parent).argumentExpression === node) {
|
||||
const objectType = getTypeOfExpression((<ElementAccessExpression>node.parent).expression);
|
||||
if (objectType === unknownType) return undefined;
|
||||
const apparentType = getApparentType(objectType);
|
||||
if (apparentType === unknownType) return undefined;
|
||||
return getPropertyOfType(apparentType, (<NumericLiteral>node).text as __String);
|
||||
return getPropertyOfType(objectType, (<NumericLiteral>node).text as __String);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -24135,8 +24141,7 @@ namespace ts {
|
||||
if (list && list.hasTrailingComma) {
|
||||
const start = list.end - ",".length;
|
||||
const end = list.end;
|
||||
const sourceFile = getSourceFileOfNode(list[0]);
|
||||
return grammarErrorAtPos(sourceFile, start, end - start, Diagnostics.Trailing_comma_not_allowed);
|
||||
return grammarErrorAtPos(list[0], start, end - start, Diagnostics.Trailing_comma_not_allowed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24264,19 +24269,18 @@ namespace ts {
|
||||
checkGrammarForAtLeastOneTypeArgument(node, typeArguments);
|
||||
}
|
||||
|
||||
function checkGrammarForOmittedArgument(node: CallExpression | NewExpression, args: NodeArray<Expression>): boolean {
|
||||
function checkGrammarForOmittedArgument(args: NodeArray<Expression>): boolean {
|
||||
if (args) {
|
||||
const sourceFile = getSourceFileOfNode(node);
|
||||
for (const arg of args) {
|
||||
if (arg.kind === SyntaxKind.OmittedExpression) {
|
||||
return grammarErrorAtPos(sourceFile, arg.pos, 0, Diagnostics.Argument_expression_expected);
|
||||
return grammarErrorAtPos(arg, arg.pos, 0, Diagnostics.Argument_expression_expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkGrammarArguments(node: CallExpression | NewExpression, args: NodeArray<Expression>): boolean {
|
||||
return checkGrammarForOmittedArgument(node, args);
|
||||
function checkGrammarArguments(args: NodeArray<Expression>): boolean {
|
||||
return checkGrammarForOmittedArgument(args);
|
||||
}
|
||||
|
||||
function checkGrammarHeritageClause(node: HeritageClause): boolean {
|
||||
@@ -24286,8 +24290,7 @@ namespace ts {
|
||||
}
|
||||
if (types && types.length === 0) {
|
||||
const listType = tokenToString(node.token);
|
||||
const sourceFile = getSourceFileOfNode(node);
|
||||
return grammarErrorAtPos(sourceFile, types.pos, 0, Diagnostics._0_list_cannot_be_empty, listType);
|
||||
return grammarErrorAtPos(node, types.pos, 0, Diagnostics._0_list_cannot_be_empty, listType);
|
||||
}
|
||||
return forEach(types, checkGrammarExpressionWithTypeArguments);
|
||||
}
|
||||
@@ -24565,7 +24568,7 @@ namespace ts {
|
||||
return grammarErrorOnNode(accessor.name, Diagnostics.An_accessor_cannot_be_declared_in_an_ambient_context);
|
||||
}
|
||||
else if (accessor.body === undefined && !hasModifier(accessor, ModifierFlags.Abstract)) {
|
||||
return grammarErrorAtPos(getSourceFileOfNode(accessor), accessor.end - 1, ";".length, Diagnostics._0_expected, "{");
|
||||
return grammarErrorAtPos(accessor, accessor.end - 1, ";".length, Diagnostics._0_expected, "{");
|
||||
}
|
||||
else if (accessor.body && hasModifier(accessor, ModifierFlags.Abstract)) {
|
||||
return grammarErrorOnNode(accessor, Diagnostics.An_abstract_accessor_cannot_have_an_implementation);
|
||||
@@ -24630,7 +24633,7 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
else if (node.body === undefined) {
|
||||
return grammarErrorAtPos(getSourceFileOfNode(node), node.end - 1, ";".length, Diagnostics._0_expected, "{");
|
||||
return grammarErrorAtPos(node, node.end - 1, ";".length, Diagnostics._0_expected, "{");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24722,7 +24725,7 @@ namespace ts {
|
||||
|
||||
if (node.initializer) {
|
||||
// Error on equals token which immediately precedes the initializer
|
||||
return grammarErrorAtPos(getSourceFileOfNode(node), node.initializer.pos - 1, 1, Diagnostics.A_rest_element_cannot_have_an_initializer);
|
||||
return grammarErrorAtPos(node, node.initializer.pos - 1, 1, Diagnostics.A_rest_element_cannot_have_an_initializer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24745,15 +24748,13 @@ namespace ts {
|
||||
else {
|
||||
// Error on equals token which immediate precedes the initializer
|
||||
const equalsTokenLength = "=".length;
|
||||
return grammarErrorAtPos(getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength,
|
||||
equalsTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
|
||||
return grammarErrorAtPos(node, node.initializer.pos - equalsTokenLength, equalsTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
|
||||
}
|
||||
}
|
||||
if (node.initializer && !(isConst(node) && isStringOrNumberLiteralExpression(node.initializer))) {
|
||||
// Error on equals token which immediate precedes the initializer
|
||||
const equalsTokenLength = "=".length;
|
||||
return grammarErrorAtPos(getSourceFileOfNode(node), node.initializer.pos - equalsTokenLength,
|
||||
equalsTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
|
||||
return grammarErrorAtPos(node, node.initializer.pos - equalsTokenLength, equalsTokenLength, Diagnostics.Initializers_are_not_allowed_in_ambient_contexts);
|
||||
}
|
||||
}
|
||||
else if (!node.initializer) {
|
||||
@@ -24822,7 +24823,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (!declarationList.declarations.length) {
|
||||
return grammarErrorAtPos(getSourceFileOfNode(declarationList), declarations.pos, declarations.end - declarations.pos, Diagnostics.Variable_declaration_list_cannot_be_empty);
|
||||
return grammarErrorAtPos(declarationList, declarations.pos, declarations.end - declarations.pos, Diagnostics.Variable_declaration_list_cannot_be_empty);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24875,7 +24876,8 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function grammarErrorAtPos(sourceFile: SourceFile, start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
|
||||
function grammarErrorAtPos(nodeForSourceFile: Node, start: number, length: number, message: DiagnosticMessage, arg0?: any, arg1?: any, arg2?: any): boolean {
|
||||
const sourceFile = getSourceFileOfNode(nodeForSourceFile);
|
||||
if (!hasParseDiagnostics(sourceFile)) {
|
||||
diagnostics.add(createFileDiagnostic(sourceFile, start, length, message, arg0, arg1, arg2));
|
||||
return true;
|
||||
@@ -24892,7 +24894,7 @@ namespace ts {
|
||||
|
||||
function checkGrammarConstructorTypeParameters(node: ConstructorDeclaration) {
|
||||
if (node.typeParameters) {
|
||||
return grammarErrorAtPos(getSourceFileOfNode(node), node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
|
||||
return grammarErrorAtPos(node, node.typeParameters.pos, node.typeParameters.end - node.typeParameters.pos, Diagnostics.Type_parameters_cannot_appear_on_a_constructor_declaration);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+10
-6
@@ -4,7 +4,7 @@
|
||||
namespace ts {
|
||||
// WARNING: The script `configureNightly.ts` uses a regexp to parse out these values.
|
||||
// If changing the text in this section, be sure to test `configureNightly` too.
|
||||
export const versionMajorMinor = "2.5";
|
||||
export const versionMajorMinor = "2.6";
|
||||
/** The version of the TypeScript compiler release */
|
||||
export const version = `${versionMajorMinor}.0`;
|
||||
}
|
||||
@@ -1543,16 +1543,20 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function normalizePath(path: string): string {
|
||||
return normalizePathAndParts(path).path;
|
||||
}
|
||||
|
||||
export function normalizePathAndParts(path: string): { path: string, parts: string[] } {
|
||||
path = normalizeSlashes(path);
|
||||
const rootLength = getRootLength(path);
|
||||
const root = path.substr(0, rootLength);
|
||||
const normalized = getNormalizedParts(path, rootLength);
|
||||
if (normalized.length) {
|
||||
const joinedParts = root + normalized.join(directorySeparator);
|
||||
return pathEndsWithDirectorySeparator(path) ? joinedParts + directorySeparator : joinedParts;
|
||||
const parts = getNormalizedParts(path, rootLength);
|
||||
if (parts.length) {
|
||||
const joinedParts = root + parts.join(directorySeparator);
|
||||
return { path: pathEndsWithDirectorySeparator(path) ? joinedParts + directorySeparator : joinedParts, parts };
|
||||
}
|
||||
else {
|
||||
return root;
|
||||
return { path: root, parts };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -349,7 +349,6 @@ namespace ts {
|
||||
errorNameNode = declaration.name;
|
||||
const format = TypeFormatFlags.UseTypeOfFunction |
|
||||
TypeFormatFlags.WriteClassExpressionAsTypeLiteral |
|
||||
TypeFormatFlags.UseTypeAliasValue |
|
||||
(shouldUseResolverType ? TypeFormatFlags.AddUndefined : 0);
|
||||
resolver.writeTypeOfDeclaration(declaration, enclosingDeclaration, format, writer);
|
||||
errorNameNode = undefined;
|
||||
@@ -368,7 +367,7 @@ namespace ts {
|
||||
resolver.writeReturnTypeOfSignatureDeclaration(
|
||||
signature,
|
||||
enclosingDeclaration,
|
||||
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.UseTypeAliasValue | TypeFormatFlags.WriteClassExpressionAsTypeLiteral,
|
||||
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.WriteClassExpressionAsTypeLiteral,
|
||||
writer);
|
||||
errorNameNode = undefined;
|
||||
}
|
||||
@@ -633,7 +632,7 @@ namespace ts {
|
||||
resolver.writeTypeOfExpression(
|
||||
expr,
|
||||
enclosingDeclaration,
|
||||
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.UseTypeAliasValue | TypeFormatFlags.WriteClassExpressionAsTypeLiteral,
|
||||
TypeFormatFlags.UseTypeOfFunction | TypeFormatFlags.WriteClassExpressionAsTypeLiteral,
|
||||
writer);
|
||||
write(";");
|
||||
writeLine();
|
||||
|
||||
@@ -201,7 +201,7 @@ namespace ts {
|
||||
let resolvedTypeReferenceDirective: ResolvedTypeReferenceDirective | undefined;
|
||||
if (resolved) {
|
||||
if (!options.preserveSymlinks) {
|
||||
resolved = realpath(resolved, host, traceEnabled);
|
||||
resolved = realPath(resolved, host, traceEnabled);
|
||||
}
|
||||
|
||||
if (traceEnabled) {
|
||||
@@ -741,20 +741,21 @@ namespace ts {
|
||||
|
||||
let resolvedValue = resolved.value;
|
||||
if (!compilerOptions.preserveSymlinks) {
|
||||
resolvedValue = resolvedValue && { ...resolved.value, path: realpath(resolved.value.path, host, traceEnabled), extension: resolved.value.extension };
|
||||
resolvedValue = resolvedValue && { ...resolved.value, path: realPath(resolved.value.path, host, traceEnabled), extension: resolved.value.extension };
|
||||
}
|
||||
// For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files.
|
||||
return { value: resolvedValue && { resolved: resolvedValue, isExternalLibraryImport: true } };
|
||||
}
|
||||
else {
|
||||
const candidate = normalizePath(combinePaths(containingDirectory, moduleName));
|
||||
const { path: candidate, parts } = normalizePathAndParts(combinePaths(containingDirectory, moduleName));
|
||||
const resolved = nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, /*onlyRecordFailures*/ false, state, /*considerPackageJson*/ true);
|
||||
return resolved && toSearchResult({ resolved, isExternalLibraryImport: false });
|
||||
// Treat explicit "node_modules" import as an external library import.
|
||||
return resolved && toSearchResult({ resolved, isExternalLibraryImport: contains(parts, "node_modules") });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function realpath(path: string, host: ModuleResolutionHost, traceEnabled: boolean): string {
|
||||
function realPath(path: string, host: ModuleResolutionHost, traceEnabled: boolean): string {
|
||||
if (!host.realpath) {
|
||||
return path;
|
||||
}
|
||||
|
||||
@@ -840,7 +840,7 @@ namespace ts {
|
||||
outer.end = skipTrivia(currentText, node.pos);
|
||||
setEmitFlags(outer, EmitFlags.NoComments);
|
||||
|
||||
return createParen(
|
||||
const result = createParen(
|
||||
createCall(
|
||||
outer,
|
||||
/*typeArguments*/ undefined,
|
||||
@@ -849,6 +849,8 @@ namespace ts {
|
||||
: []
|
||||
)
|
||||
);
|
||||
addSyntheticLeadingComment(result, SyntaxKind.MultiLineCommentTrivia, "* @class ");
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -151,7 +151,17 @@ namespace ts {
|
||||
break;
|
||||
}
|
||||
|
||||
recordEmittedDeclarationInScope(node);
|
||||
// Record these declarations provided that they have a name.
|
||||
if ((node as ClassDeclaration | FunctionDeclaration).name) {
|
||||
recordEmittedDeclarationInScope(node as ClassDeclaration | FunctionDeclaration);
|
||||
}
|
||||
else {
|
||||
// These nodes should always have names unless they are default-exports;
|
||||
// however, class declaration parsing allows for undefined names, so syntactically invalid
|
||||
// programs may also have an undefined name.
|
||||
Debug.assert(node.kind === SyntaxKind.ClassDeclaration || hasModifier(node, ModifierFlags.Default));
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2639,36 +2649,33 @@ namespace ts {
|
||||
/**
|
||||
* Records that a declaration was emitted in the current scope, if it was the first
|
||||
* declaration for the provided symbol.
|
||||
*
|
||||
* NOTE: if there is ever a transformation above this one, we may not be able to rely
|
||||
* on symbol names.
|
||||
*/
|
||||
function recordEmittedDeclarationInScope(node: Node) {
|
||||
const name = node.symbol && node.symbol.escapedName;
|
||||
if (name) {
|
||||
if (!currentScopeFirstDeclarationsOfName) {
|
||||
currentScopeFirstDeclarationsOfName = createUnderscoreEscapedMap<Node>();
|
||||
}
|
||||
function recordEmittedDeclarationInScope(node: FunctionDeclaration | ClassDeclaration | ModuleDeclaration | EnumDeclaration) {
|
||||
if (!currentScopeFirstDeclarationsOfName) {
|
||||
currentScopeFirstDeclarationsOfName = createUnderscoreEscapedMap<Node>();
|
||||
}
|
||||
|
||||
if (!currentScopeFirstDeclarationsOfName.has(name)) {
|
||||
currentScopeFirstDeclarationsOfName.set(name, node);
|
||||
}
|
||||
const name = declaredNameInScope(node);
|
||||
if (!currentScopeFirstDeclarationsOfName.has(name)) {
|
||||
currentScopeFirstDeclarationsOfName.set(name, node);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a declaration is the first declaration with the same name emitted
|
||||
* in the current scope.
|
||||
* Determines whether a declaration is the first declaration with
|
||||
* the same name emitted in the current scope.
|
||||
*/
|
||||
function isFirstEmittedDeclarationInScope(node: Node) {
|
||||
function isFirstEmittedDeclarationInScope(node: ModuleDeclaration | EnumDeclaration) {
|
||||
if (currentScopeFirstDeclarationsOfName) {
|
||||
const name = node.symbol && node.symbol.escapedName;
|
||||
if (name) {
|
||||
return currentScopeFirstDeclarationsOfName.get(name) === node;
|
||||
}
|
||||
const name = declaredNameInScope(node);
|
||||
return currentScopeFirstDeclarationsOfName.get(name) === node;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
function declaredNameInScope(node: FunctionDeclaration | ClassDeclaration | ModuleDeclaration | EnumDeclaration): __String {
|
||||
Debug.assertNode(node.name, isIdentifier);
|
||||
return (node.name as Identifier).escapedText;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2746,7 +2753,7 @@ namespace ts {
|
||||
return createNotEmittedStatement(node);
|
||||
}
|
||||
|
||||
Debug.assert(isIdentifier(node.name), "TypeScript module should have an Identifier name.");
|
||||
Debug.assertNode(node.name, isIdentifier, "A TypeScript namespace should have an Identifier name.");
|
||||
enableSubstitutionForNamespaceExports();
|
||||
|
||||
const statements: Statement[] = [];
|
||||
|
||||
+14
-9
@@ -2568,6 +2568,15 @@ namespace ts {
|
||||
getSymbolsOfParameterPropertyDeclaration(parameter: ParameterDeclaration, parameterName: string): Symbol[];
|
||||
getShorthandAssignmentValueSymbol(location: Node): Symbol | undefined;
|
||||
getExportSpecifierLocalTargetSymbol(location: ExportSpecifier): Symbol | undefined;
|
||||
/**
|
||||
* If a symbol is a local symbol with an associated exported symbol, returns the exported symbol.
|
||||
* Otherwise returns its input.
|
||||
* For example, at `export type T = number;`:
|
||||
* - `getSymbolAtLocation` at the location `T` will return the exported symbol for `T`.
|
||||
* - But the result of `getSymbolsInScope` will contain the *local* symbol for `T`, not the exported symbol.
|
||||
* - Calling `getExportSymbolOfSymbol` on that local symbol will return the exported symbol.
|
||||
*/
|
||||
getExportSymbolOfSymbol(symbol: Symbol): Symbol;
|
||||
getPropertySymbolOfDestructuringAssignment(location: Identifier): Symbol | undefined;
|
||||
getTypeAtLocation(node: Node): Type;
|
||||
getTypeFromTypeNode(node: TypeNode): Type;
|
||||
@@ -2708,11 +2717,12 @@ namespace ts {
|
||||
UseFullyQualifiedType = 1 << 8, // Write out the fully qualified type name (eg. Module.Type, instead of Type)
|
||||
InFirstTypeArgument = 1 << 9, // Writing first type argument of the instantiated type
|
||||
InTypeAlias = 1 << 10, // Writing type in type alias declaration
|
||||
UseTypeAliasValue = 1 << 11, // Serialize the type instead of using type-alias. This is needed when we emit declaration file.
|
||||
SuppressAnyReturnType = 1 << 12, // If the return type is any-like, don't offer a return type.
|
||||
AddUndefined = 1 << 13, // Add undefined to types of initialized, non-optional parameters
|
||||
WriteClassExpressionAsTypeLiteral = 1 << 14, // Write a type literal instead of (Anonymous class)
|
||||
InArrayType = 1 << 15, // Writing an array element type
|
||||
UseAliasDefinedOutsideCurrentScope = 1 << 16, // For a `type T = ... ` defined in a different file, write `T` instead of its value,
|
||||
// even though `T` can't be accessed in the current scope.
|
||||
}
|
||||
|
||||
export const enum SymbolFormatFlags {
|
||||
@@ -2921,7 +2931,7 @@ namespace ts {
|
||||
|
||||
export interface Symbol {
|
||||
flags: SymbolFlags; // Symbol flags
|
||||
escapedName: __String; // Name of symbol
|
||||
escapedName: __String; // Name of symbol
|
||||
declarations?: Declaration[]; // Declarations associated with this symbol
|
||||
valueDeclaration?: Declaration; // First value declaration of the symbol
|
||||
members?: SymbolTable; // Class, interface or literal instance members
|
||||
@@ -3126,7 +3136,7 @@ namespace ts {
|
||||
/* @internal */
|
||||
ContainsObjectLiteral = 1 << 22, // Type is or contains object literal type
|
||||
/* @internal */
|
||||
ContainsAnyFunctionType = 1 << 23, // Type is or contains object literal type
|
||||
ContainsAnyFunctionType = 1 << 23, // Type is or contains the anyFunctionType
|
||||
NonPrimitive = 1 << 24, // intrinsic object type
|
||||
/* @internal */
|
||||
JsxAttributes = 1 << 25, // Jsx attributes type
|
||||
@@ -3944,12 +3954,7 @@ namespace ts {
|
||||
export interface ResolvedModule {
|
||||
/** Path of the file the module was resolved to. */
|
||||
resolvedFileName: string;
|
||||
/**
|
||||
* Denotes if 'resolvedFileName' is isExternalLibraryImport and thus should be a proper external module:
|
||||
* - be a .d.ts file
|
||||
* - use top level imports\exports
|
||||
* - don't use tripleslash references
|
||||
*/
|
||||
/** True if `resolvedFileName` comes from `node_modules`. */
|
||||
isExternalLibraryImport?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -647,7 +647,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function getLeadingCommentRangesOfNode(node: Node, sourceFileOfNode: SourceFile) {
|
||||
return getLeadingCommentRanges(sourceFileOfNode.text, node.pos);
|
||||
return node.kind !== SyntaxKind.JsxText ? getLeadingCommentRanges(sourceFileOfNode.text, node.pos) : undefined;
|
||||
}
|
||||
|
||||
export function getJSDocCommentRanges(node: Node, text: string) {
|
||||
|
||||
@@ -2508,6 +2508,23 @@ namespace FourSlash {
|
||||
}
|
||||
}
|
||||
|
||||
public verifySpanOfEnclosingComment(negative: boolean, onlyMultiLineDiverges?: boolean) {
|
||||
const expected = !negative;
|
||||
const position = this.currentCaretPosition;
|
||||
const fileName = this.activeFile.fileName;
|
||||
const actual = !!this.languageService.getSpanOfEnclosingComment(fileName, position, /*onlyMultiLine*/ false);
|
||||
const actualOnlyMultiLine = !!this.languageService.getSpanOfEnclosingComment(fileName, position, /*onlyMultiLine*/ true);
|
||||
if (expected !== actual || onlyMultiLineDiverges === (actual === actualOnlyMultiLine)) {
|
||||
this.raiseError(`verifySpanOfEnclosingComment failed:
|
||||
position: '${position}'
|
||||
fileName: '${fileName}'
|
||||
onlyMultiLineDiverges: '${onlyMultiLineDiverges}'
|
||||
actual: '${actual}'
|
||||
actualOnlyMultiLine: '${actualOnlyMultiLine}'
|
||||
expected: '${expected}'.`);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Check number of navigationItems which match both searchValue and matchKind,
|
||||
if a filename is passed in, limit the results to that file.
|
||||
@@ -3648,6 +3665,10 @@ namespace FourSlashInterface {
|
||||
this.state.verifyBraceCompletionAtPosition(this.negative, openingBrace);
|
||||
}
|
||||
|
||||
public isInCommentAtPosition(onlyMultiLineDiverges?: boolean) {
|
||||
this.state.verifySpanOfEnclosingComment(this.negative, onlyMultiLineDiverges);
|
||||
}
|
||||
|
||||
public codeFixAvailable() {
|
||||
this.state.verifyCodeFixAvailable(this.negative);
|
||||
}
|
||||
|
||||
@@ -487,6 +487,9 @@ namespace Harness.LanguageService {
|
||||
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean {
|
||||
return unwrapJSONCallResult(this.shim.isValidBraceCompletionAtPosition(fileName, position, openingBrace));
|
||||
}
|
||||
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): ts.TextSpan {
|
||||
return unwrapJSONCallResult(this.shim.getSpanOfEnclosingComment(fileName, position, onlyMultiLine));
|
||||
}
|
||||
getCodeFixesAtPosition(): ts.CodeAction[] {
|
||||
throw new Error("Not supported on the shim.");
|
||||
}
|
||||
@@ -686,7 +689,7 @@ namespace Harness.LanguageService {
|
||||
this.host.log(message);
|
||||
}
|
||||
|
||||
err(message: string): void {
|
||||
msg(message: string): void {
|
||||
this.host.log(message);
|
||||
}
|
||||
|
||||
@@ -702,7 +705,8 @@ namespace Harness.LanguageService {
|
||||
return false;
|
||||
}
|
||||
|
||||
group() { throw ts.notImplemented(); }
|
||||
startGroup() { throw ts.notImplemented(); }
|
||||
endGroup() { throw ts.notImplemented(); }
|
||||
|
||||
perftrc(message: string): void {
|
||||
return this.host.log(message);
|
||||
|
||||
@@ -90,9 +90,16 @@ namespace RWC {
|
||||
ts.setConfigFileInOptions(opts.options, configParseResult.options.configFile);
|
||||
}
|
||||
|
||||
// Load the files
|
||||
// Deduplicate files so they are only printed once in baselines (they are deduplicated within the compiler already)
|
||||
const uniqueNames = ts.createMap<true>();
|
||||
for (const fileName of fileNames) {
|
||||
inputFiles.push(getHarnessCompilerInputUnit(fileName));
|
||||
// Must maintain order, build result list while checking map
|
||||
const normalized = ts.normalizeSlashes(fileName);
|
||||
if (!uniqueNames.has(normalized)) {
|
||||
uniqueNames.set(normalized, true);
|
||||
// Load the file
|
||||
inputFiles.push(getHarnessCompilerInputUnit(fileName));
|
||||
}
|
||||
}
|
||||
|
||||
// Add files to compilation
|
||||
|
||||
@@ -74,6 +74,70 @@ namespace ts {
|
||||
}
|
||||
}).outputText;
|
||||
});
|
||||
|
||||
testBaseline("rewrittenNamespace", () => {
|
||||
return ts.transpileModule(`namespace Reflect { const x = 1; }`, {
|
||||
transformers: {
|
||||
before: [forceNamespaceRewrite],
|
||||
},
|
||||
compilerOptions: {
|
||||
newLine: NewLineKind.CarriageReturnLineFeed,
|
||||
}
|
||||
}).outputText;
|
||||
});
|
||||
|
||||
testBaseline("rewrittenNamespaceFollowingClass", () => {
|
||||
return ts.transpileModule(`
|
||||
class C { foo = 10; static bar = 20 }
|
||||
namespace C { export let x = 10; }
|
||||
`, {
|
||||
transformers: {
|
||||
before: [forceNamespaceRewrite],
|
||||
},
|
||||
compilerOptions: {
|
||||
target: ts.ScriptTarget.ESNext,
|
||||
newLine: NewLineKind.CarriageReturnLineFeed,
|
||||
}
|
||||
}).outputText;
|
||||
});
|
||||
|
||||
testBaseline("synthesizedClassAndNamespaceCombination", () => {
|
||||
return ts.transpileModule("", {
|
||||
transformers: {
|
||||
before: [replaceWithClassAndNamespace],
|
||||
},
|
||||
compilerOptions: {
|
||||
target: ts.ScriptTarget.ESNext,
|
||||
newLine: NewLineKind.CarriageReturnLineFeed,
|
||||
}
|
||||
}).outputText;
|
||||
|
||||
function replaceWithClassAndNamespace() {
|
||||
return (sourceFile: ts.SourceFile) => {
|
||||
const result = getMutableClone(sourceFile);
|
||||
result.statements = ts.createNodeArray([
|
||||
ts.createClassDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, "Foo", /*typeParameters*/ undefined, /*heritageClauses*/ undefined, /*members*/ undefined),
|
||||
ts.createModuleDeclaration(/*decorators*/ undefined, /*modifiers*/ undefined, createIdentifier("Foo"), createModuleBlock([createEmptyStatement()]))
|
||||
]);
|
||||
return result;
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
function forceNamespaceRewrite(context: ts.TransformationContext) {
|
||||
return (sourceFile: ts.SourceFile): ts.SourceFile => {
|
||||
return visitNode(sourceFile);
|
||||
|
||||
function visitNode<T extends ts.Node>(node: T): T {
|
||||
if (node.kind === ts.SyntaxKind.ModuleBlock) {
|
||||
const block = node as T & ts.ModuleBlock;
|
||||
const statements = ts.createNodeArray([...block.statements]);
|
||||
return ts.updateModuleBlock(block, statements) as typeof block;
|
||||
}
|
||||
return ts.visitEachChild(node, visitNode, context);
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -39,8 +39,9 @@ namespace ts.projectSystem {
|
||||
loggingEnabled: () => false,
|
||||
perftrc: noop,
|
||||
info: noop,
|
||||
err: noop,
|
||||
group: noop,
|
||||
msg: noop,
|
||||
startGroup: noop,
|
||||
endGroup: noop,
|
||||
getLogFileName: (): string => undefined
|
||||
};
|
||||
|
||||
|
||||
Vendored
+4
-4
@@ -980,12 +980,12 @@ interface ReadonlyArray<T> {
|
||||
* Combines two or more arrays.
|
||||
* @param items Additional items to add to the end of array1.
|
||||
*/
|
||||
concat(...items: T[][]): T[];
|
||||
concat(...items: ReadonlyArray<T>[]): T[];
|
||||
/**
|
||||
* Combines two or more arrays.
|
||||
* @param items Additional items to add to the end of array1.
|
||||
*/
|
||||
concat(...items: (T | T[])[]): T[];
|
||||
concat(...items: (T | ReadonlyArray<T>)[]): T[];
|
||||
/**
|
||||
* Adds all the elements of an array separated by the specified separator string.
|
||||
* @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
|
||||
@@ -1099,12 +1099,12 @@ interface Array<T> {
|
||||
* Combines two or more arrays.
|
||||
* @param items Additional items to add to the end of array1.
|
||||
*/
|
||||
concat(...items: T[][]): T[];
|
||||
concat(...items: ReadonlyArray<T>[]): T[];
|
||||
/**
|
||||
* Combines two or more arrays.
|
||||
* @param items Additional items to add to the end of array1.
|
||||
*/
|
||||
concat(...items: (T | T[])[]): T[];
|
||||
concat(...items: (T | ReadonlyArray<T>)[]): T[];
|
||||
/**
|
||||
* Adds all the elements of an array separated by the specified separator string.
|
||||
* @param separator A string used to separate one element of an array from the next in the resulting String. If omitted, the array elements are separated with a comma.
|
||||
|
||||
@@ -527,6 +527,10 @@ namespace ts.server {
|
||||
return notImplemented();
|
||||
}
|
||||
|
||||
getSpanOfEnclosingComment(_fileName: string, _position: number, _onlyMultiLine: boolean): TextSpan {
|
||||
return notImplemented();
|
||||
}
|
||||
|
||||
getCodeFixesAtPosition(file: string, start: number, end: number, errorCodes: number[]): CodeAction[] {
|
||||
const args: protocol.CodeFixRequestArgs = { ...this.createFileRangeRequestArgs(file, start, end), errorCodes };
|
||||
|
||||
|
||||
@@ -958,28 +958,28 @@ namespace ts.server {
|
||||
return;
|
||||
}
|
||||
|
||||
this.logger.group(info => {
|
||||
let counter = 0;
|
||||
counter = printProjects(this.externalProjects, info, counter);
|
||||
counter = printProjects(this.configuredProjects, info, counter);
|
||||
printProjects(this.inferredProjects, info, counter);
|
||||
|
||||
info("Open files: ");
|
||||
for (const rootFile of this.openFiles) {
|
||||
info(`\t${rootFile.fileName}`);
|
||||
}
|
||||
});
|
||||
|
||||
function printProjects(projects: Project[], info: (msg: string) => void, counter: number): number {
|
||||
this.logger.startGroup();
|
||||
let counter = 0;
|
||||
const printProjects = (projects: Project[], counter: number): number => {
|
||||
for (const project of projects) {
|
||||
project.updateGraph();
|
||||
info(`Project '${project.getProjectName()}' (${ProjectKind[project.projectKind]}) ${counter}`);
|
||||
info(project.filesToString());
|
||||
info("-----------------------------------------------");
|
||||
this.logger.info(`Project '${project.getProjectName()}' (${ProjectKind[project.projectKind]}) ${counter}`);
|
||||
this.logger.info(project.filesToString());
|
||||
this.logger.info("-----------------------------------------------");
|
||||
counter++;
|
||||
}
|
||||
return counter;
|
||||
};
|
||||
counter = printProjects(this.externalProjects, counter);
|
||||
counter = printProjects(this.configuredProjects, counter);
|
||||
printProjects(this.inferredProjects, counter);
|
||||
|
||||
this.logger.info("Open files: ");
|
||||
for (const rootFile of this.openFiles) {
|
||||
this.logger.info(`\t${rootFile.fileName}`);
|
||||
}
|
||||
|
||||
this.logger.endGroup();
|
||||
}
|
||||
|
||||
private findConfiguredProjectByProjectName(configFileName: NormalizedPath) {
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace ts.server.protocol {
|
||||
/* @internal */
|
||||
BraceFull = "brace-full",
|
||||
BraceCompletion = "braceCompletion",
|
||||
GetSpanOfEnclosingComment = "getSpanOfEnclosingComment",
|
||||
Change = "change",
|
||||
Close = "close",
|
||||
Completions = "completions",
|
||||
@@ -241,6 +242,21 @@ namespace ts.server.protocol {
|
||||
body?: TodoComment[];
|
||||
}
|
||||
|
||||
/**
|
||||
* A request to determine if the caret is inside a comment.
|
||||
*/
|
||||
export interface SpanOfEnclosingCommentRequest extends FileLocationRequest {
|
||||
command: CommandTypes.GetSpanOfEnclosingComment;
|
||||
arguments: SpanOfEnclosingCommentRequestArgs;
|
||||
}
|
||||
|
||||
export interface SpanOfEnclosingCommentRequestArgs extends FileLocationRequestArgs {
|
||||
/**
|
||||
* Requires that the enclosing span be a multi-line comment, or else the request returns undefined.
|
||||
*/
|
||||
onlyMultiLine: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request to obtain outlining spans in file.
|
||||
*/
|
||||
@@ -2474,6 +2490,7 @@ namespace ts.server.protocol {
|
||||
System = "System",
|
||||
ES6 = "ES6",
|
||||
ES2015 = "ES2015",
|
||||
ESNext = "ESNext"
|
||||
}
|
||||
|
||||
export const enum ModuleResolutionKind {
|
||||
@@ -2491,5 +2508,8 @@ namespace ts.server.protocol {
|
||||
ES5 = "ES5",
|
||||
ES6 = "ES6",
|
||||
ES2015 = "ES2015",
|
||||
ES2016 = "ES2016",
|
||||
ES2017 = "ES2017",
|
||||
ESNext = "ESNext"
|
||||
}
|
||||
}
|
||||
|
||||
+15
-13
@@ -140,6 +140,8 @@ namespace ts.server {
|
||||
class Logger implements server.Logger {
|
||||
private fd = -1;
|
||||
private seq = 0;
|
||||
private inGroup = false;
|
||||
private firstInGroup = true;
|
||||
|
||||
constructor(private readonly logFilename: string,
|
||||
private readonly traceToConsole: boolean,
|
||||
@@ -169,24 +171,24 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
perftrc(s: string) {
|
||||
this.msg(s, "Perf");
|
||||
this.msg(s, Msg.Perf);
|
||||
}
|
||||
|
||||
info(s: string) {
|
||||
this.msg(s, "Info");
|
||||
this.msg(s, Msg.Info);
|
||||
}
|
||||
|
||||
err(s: string) {
|
||||
this.msg(s, "Err");
|
||||
this.msg(s, Msg.Err);
|
||||
}
|
||||
|
||||
group(logGroupEntries: (log: (msg: string) => void) => void) {
|
||||
let firstInGroup = false;
|
||||
logGroupEntries(s => {
|
||||
this.msg(s, "Info", /*inGroup*/ true, firstInGroup);
|
||||
firstInGroup = false;
|
||||
});
|
||||
this.seq++;
|
||||
startGroup() {
|
||||
this.inGroup = true;
|
||||
this.firstInGroup = true;
|
||||
}
|
||||
|
||||
endGroup() {
|
||||
this.inGroup = false;
|
||||
}
|
||||
|
||||
loggingEnabled() {
|
||||
@@ -197,16 +199,16 @@ namespace ts.server {
|
||||
return this.loggingEnabled() && this.level >= level;
|
||||
}
|
||||
|
||||
private msg(s: string, type: string, inGroup = false, firstInGroup = false) {
|
||||
msg(s: string, type: Msg.Types = Msg.Err) {
|
||||
if (!this.canWrite) return;
|
||||
|
||||
s = `[${nowString()}] ${s}\n`;
|
||||
if (!inGroup || firstInGroup) {
|
||||
if (!this.inGroup || this.firstInGroup) {
|
||||
const prefix = Logger.padStringRight(type + " " + this.seq.toString(), " ");
|
||||
s = prefix + s;
|
||||
}
|
||||
this.write(s);
|
||||
if (!inGroup) {
|
||||
if (!this.inGroup) {
|
||||
this.seq++;
|
||||
}
|
||||
}
|
||||
|
||||
+19
-11
@@ -368,7 +368,7 @@ namespace ts.server {
|
||||
msg += "\n" + (<StackTraceError>err).stack;
|
||||
}
|
||||
}
|
||||
this.logger.err(msg);
|
||||
this.logger.msg(msg, Msg.Err);
|
||||
}
|
||||
|
||||
public send(msg: protocol.Message) {
|
||||
@@ -626,7 +626,7 @@ namespace ts.server {
|
||||
|
||||
const definitions = project.getLanguageService().getTypeDefinitionAtPosition(file, position);
|
||||
if (!definitions) {
|
||||
return undefined;
|
||||
return emptyArray;
|
||||
}
|
||||
|
||||
return definitions.map(def => {
|
||||
@@ -716,7 +716,7 @@ namespace ts.server {
|
||||
const documentHighlights = project.getLanguageService().getDocumentHighlights(file, position, args.filesToSearch);
|
||||
|
||||
if (!documentHighlights) {
|
||||
return undefined;
|
||||
return emptyArray;
|
||||
}
|
||||
|
||||
if (simplifiedResult) {
|
||||
@@ -903,7 +903,7 @@ namespace ts.server {
|
||||
}
|
||||
}
|
||||
|
||||
private getReferences(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.ReferencesResponseBody | ReadonlyArray<ReferencedSymbol> {
|
||||
private getReferences(args: protocol.FileLocationRequestArgs, simplifiedResult: boolean): protocol.ReferencesResponseBody | undefined | ReadonlyArray<ReferencedSymbol> {
|
||||
const file = toNormalizedPath(args.file);
|
||||
const projects = this.getProjects(args);
|
||||
|
||||
@@ -913,7 +913,7 @@ namespace ts.server {
|
||||
if (simplifiedResult) {
|
||||
const nameInfo = defaultProject.getLanguageService().getQuickInfoAtPosition(file, position);
|
||||
if (!nameInfo) {
|
||||
return emptyArray;
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const displayString = displayPartsToString(nameInfo.displayParts);
|
||||
@@ -1025,6 +1025,14 @@ namespace ts.server {
|
||||
return project.getLanguageService(/*ensureSynchronized*/ false).getDocCommentTemplateAtPosition(file, position);
|
||||
}
|
||||
|
||||
private getSpanOfEnclosingComment(args: protocol.SpanOfEnclosingCommentRequestArgs) {
|
||||
const { file, project } = this.getFileAndProjectWithoutRefreshingInferredProjects(args);
|
||||
const scriptInfo = project.getScriptInfoForNormalizedPath(file);
|
||||
const onlyMultiLine = args.onlyMultiLine;
|
||||
const position = this.getPosition(args, scriptInfo);
|
||||
return project.getLanguageService(/*ensureSynchronized*/ false).getSpanOfEnclosingComment(file, position, onlyMultiLine);
|
||||
}
|
||||
|
||||
private getIndentation(args: protocol.IndentationRequestArgs) {
|
||||
const { file, project } = this.getFileAndProjectWithoutRefreshingInferredProjects(args);
|
||||
const position = this.getPosition(args, project.getScriptInfoForNormalizedPath(file));
|
||||
@@ -1167,7 +1175,7 @@ namespace ts.server {
|
||||
});
|
||||
}
|
||||
|
||||
private getCompletions(args: protocol.CompletionsRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.CompletionEntry> | CompletionInfo {
|
||||
private getCompletions(args: protocol.CompletionsRequestArgs, simplifiedResult: boolean): ReadonlyArray<protocol.CompletionEntry> | CompletionInfo | undefined {
|
||||
const prefix = args.prefix || "";
|
||||
const { file, project } = this.getFileAndProject(args);
|
||||
|
||||
@@ -1175,11 +1183,8 @@ namespace ts.server {
|
||||
const position = this.getPosition(args, scriptInfo);
|
||||
|
||||
const completions = project.getLanguageService().getCompletionsAtPosition(file, position);
|
||||
if (!completions) {
|
||||
return emptyArray;
|
||||
}
|
||||
if (simplifiedResult) {
|
||||
return mapDefined(completions.entries, entry => {
|
||||
return mapDefined(completions && completions.entries, entry => {
|
||||
if (completions.isMemberCompletion || (entry.name.toLowerCase().indexOf(prefix.toLowerCase()) === 0)) {
|
||||
const { name, kind, kindModifiers, sortText, replacementSpan } = entry;
|
||||
const convertedSpan = replacementSpan ? this.decorateSpan(replacementSpan, scriptInfo) : undefined;
|
||||
@@ -1768,6 +1773,9 @@ namespace ts.server {
|
||||
[CommandNames.DocCommentTemplate]: (request: protocol.DocCommentTemplateRequest) => {
|
||||
return this.requiredResponse(this.getDocCommentTemplate(request.arguments));
|
||||
},
|
||||
[CommandNames.GetSpanOfEnclosingComment]: (request: protocol.SpanOfEnclosingCommentRequest) => {
|
||||
return this.requiredResponse(this.getSpanOfEnclosingComment(request.arguments));
|
||||
},
|
||||
[CommandNames.Format]: (request: protocol.FormatRequest) => {
|
||||
return this.requiredResponse(this.getFormattingEditsForRange(request.arguments));
|
||||
},
|
||||
@@ -1950,7 +1958,7 @@ namespace ts.server {
|
||||
return this.executeWithRequestId(request.seq, () => handler(request));
|
||||
}
|
||||
else {
|
||||
this.logger.err(`Unrecognized JSON command: ${JSON.stringify(request)}`);
|
||||
this.logger.msg(`Unrecognized JSON command: ${JSON.stringify(request)}`, Msg.Err);
|
||||
this.output(undefined, CommandNames.Unknown, request.seq, `Unrecognized JSON command: ${request.command}`);
|
||||
return { responseRequired: false };
|
||||
}
|
||||
|
||||
+13
-4
@@ -17,11 +17,22 @@ namespace ts.server {
|
||||
loggingEnabled(): boolean;
|
||||
perftrc(s: string): void;
|
||||
info(s: string): void;
|
||||
err(s: string): void;
|
||||
group(logGroupEntries: (log: (msg: string) => void) => void): void;
|
||||
startGroup(): void;
|
||||
endGroup(): void;
|
||||
msg(s: string, type?: Msg.Types): void;
|
||||
getLogFileName(): string;
|
||||
}
|
||||
|
||||
export namespace Msg {
|
||||
export type Err = "Err";
|
||||
export const Err: Err = "Err";
|
||||
export type Info = "Info";
|
||||
export const Info: Info = "Info";
|
||||
export type Perf = "Perf";
|
||||
export const Perf: Perf = "Perf";
|
||||
export type Types = Err | Info | Perf;
|
||||
}
|
||||
|
||||
function getProjectRootPath(project: Project): Path {
|
||||
switch (project.projectKind) {
|
||||
case ProjectKind.Configured:
|
||||
@@ -115,9 +126,7 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
export function createNormalizedPathMap<T>(): NormalizedPathMap<T> {
|
||||
/* tslint:disable:no-null-keyword */
|
||||
const map = createMap<T>();
|
||||
/* tslint:enable:no-null-keyword */
|
||||
return {
|
||||
get(path) {
|
||||
return map.get(path);
|
||||
|
||||
@@ -398,7 +398,6 @@ namespace ts.formatting {
|
||||
|
||||
// formatting context is used by rules provider
|
||||
const formattingContext = new FormattingContext(sourceFile, requestKind, options);
|
||||
let previousRangeHasError: boolean;
|
||||
let previousRange: TextRangeWithKind;
|
||||
let previousParent: Node;
|
||||
let previousRangeStartLine: number;
|
||||
@@ -883,7 +882,7 @@ namespace ts.formatting {
|
||||
|
||||
const rangeHasError = rangeContainsError(range);
|
||||
let lineAdded: boolean;
|
||||
if (!rangeHasError && !previousRangeHasError) {
|
||||
if (!rangeHasError) {
|
||||
if (!previousRange) {
|
||||
// trim whitespaces starting from the beginning of the span up to the current line
|
||||
const originalStart = sourceFile.getLineAndCharacterOfPosition(originalRange.pos);
|
||||
@@ -898,7 +897,6 @@ namespace ts.formatting {
|
||||
previousRange = range;
|
||||
previousParent = parent;
|
||||
previousRangeStartLine = rangeStart.line;
|
||||
previousRangeHasError = rangeHasError;
|
||||
|
||||
return lineAdded;
|
||||
}
|
||||
@@ -1152,6 +1150,56 @@ namespace ts.formatting {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param precedingToken pass `null` if preceding token was already computed and result was `undefined`.
|
||||
*/
|
||||
export function getRangeOfEnclosingComment(
|
||||
sourceFile: SourceFile,
|
||||
position: number,
|
||||
onlyMultiLine: boolean,
|
||||
precedingToken?: Node | null, // tslint:disable-line:no-null-keyword
|
||||
tokenAtPosition = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ false),
|
||||
predicate?: (c: CommentRange) => boolean): CommentRange | undefined {
|
||||
const tokenStart = tokenAtPosition.getStart(sourceFile);
|
||||
if (tokenStart <= position && position < tokenAtPosition.getEnd()) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (precedingToken === undefined) {
|
||||
precedingToken = findPrecedingToken(position, sourceFile);
|
||||
}
|
||||
|
||||
// Between two consecutive tokens, all comments are either trailing on the former
|
||||
// or leading on the latter (and none are in both lists).
|
||||
const trailingRangesOfPreviousToken = precedingToken && getTrailingCommentRanges(sourceFile.text, precedingToken.end);
|
||||
const leadingCommentRangesOfNextToken = getLeadingCommentRangesOfNode(tokenAtPosition, sourceFile);
|
||||
const commentRanges = trailingRangesOfPreviousToken && leadingCommentRangesOfNextToken ?
|
||||
trailingRangesOfPreviousToken.concat(leadingCommentRangesOfNextToken) :
|
||||
trailingRangesOfPreviousToken || leadingCommentRangesOfNextToken;
|
||||
if (commentRanges) {
|
||||
for (const range of commentRanges) {
|
||||
// The end marker of a single-line comment does not include the newline character.
|
||||
// With caret at `^`, in the following case, we are inside a comment (^ denotes the cursor position):
|
||||
//
|
||||
// // asdf ^\n
|
||||
//
|
||||
// But for closed multi-line comments, we don't want to be inside the comment in the following case:
|
||||
//
|
||||
// /* asdf */^
|
||||
//
|
||||
// However, unterminated multi-line comments *do* contain their end.
|
||||
//
|
||||
// Internally, we represent the end of the comment at the newline and closing '/', respectively.
|
||||
//
|
||||
if ((range.pos < position && position < range.end ||
|
||||
position === range.end && (range.kind === SyntaxKind.SingleLineCommentTrivia || position === sourceFile.getFullWidth()))) {
|
||||
return (range.kind === SyntaxKind.MultiLineCommentTrivia || !onlyMultiLine) && (!predicate || predicate(range)) ? range : undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function getOpenTokenForList(node: Node, list: ReadonlyArray<Node>) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Constructor:
|
||||
|
||||
@@ -32,13 +32,36 @@ namespace ts.formatting {
|
||||
}
|
||||
|
||||
const precedingToken = findPrecedingToken(position, sourceFile);
|
||||
|
||||
const enclosingCommentRange = getRangeOfEnclosingComment(sourceFile, position, /*onlyMultiLine*/ true, precedingToken || null); // tslint:disable-line:no-null-keyword
|
||||
if (enclosingCommentRange) {
|
||||
const previousLine = getLineAndCharacterOfPosition(sourceFile, position).line - 1;
|
||||
const commentStartLine = getLineAndCharacterOfPosition(sourceFile, enclosingCommentRange.pos).line;
|
||||
|
||||
Debug.assert(commentStartLine >= 0);
|
||||
|
||||
if (previousLine <= commentStartLine) {
|
||||
return findFirstNonWhitespaceColumn(getStartPositionOfLine(commentStartLine, sourceFile), position, sourceFile, options);
|
||||
}
|
||||
|
||||
const startPostionOfLine = getStartPositionOfLine(previousLine, sourceFile);
|
||||
const { column, character } = findFirstNonWhitespaceCharacterAndColumn(startPostionOfLine, position, sourceFile, options);
|
||||
|
||||
if (column === 0) {
|
||||
return column;
|
||||
}
|
||||
|
||||
const firstNonWhitespaceCharacterCode = sourceFile.text.charCodeAt(startPostionOfLine + character);
|
||||
return firstNonWhitespaceCharacterCode === CharacterCodes.asterisk ? column - 1 : column;
|
||||
}
|
||||
|
||||
if (!precedingToken) {
|
||||
return getBaseIndentation(options);
|
||||
}
|
||||
|
||||
// no indentation in string \regex\template literals
|
||||
const precedingTokenIsLiteral = isStringOrRegularExpressionOrTemplateLiteral(precedingToken.kind);
|
||||
if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && precedingToken.end > position) {
|
||||
if (precedingTokenIsLiteral && precedingToken.getStart(sourceFile) <= position && position < precedingToken.end) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -405,13 +428,13 @@ namespace ts.formatting {
|
||||
return findFirstNonWhitespaceColumn(lineStart, lineStart + lineAndCharacter.character, sourceFile, options);
|
||||
}
|
||||
|
||||
/*
|
||||
Character is the actual index of the character since the beginning of the line.
|
||||
Column - position of the character after expanding tabs to spaces
|
||||
"0\t2$"
|
||||
value of 'character' for '$' is 3
|
||||
value of 'column' for '$' is 6 (assuming that tab size is 4)
|
||||
*/
|
||||
/**
|
||||
* Character is the actual index of the character since the beginning of the line.
|
||||
* Column - position of the character after expanding tabs to spaces.
|
||||
* "0\t2$"
|
||||
* value of 'character' for '$' is 3
|
||||
* value of 'column' for '$' is 6 (assuming that tab size is 4)
|
||||
*/
|
||||
export function findFirstNonWhitespaceCharacterAndColumn(startPos: number, endPos: number, sourceFile: SourceFileLike, options: EditorSettings) {
|
||||
let character = 0;
|
||||
let column = 0;
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
/* @internal */
|
||||
namespace ts.OutliningElementsCollector {
|
||||
const collapseText = "...";
|
||||
const maxDepth = 20;
|
||||
|
||||
export function collectElements(sourceFile: SourceFile, cancellationToken: CancellationToken): OutliningSpan[] {
|
||||
const elements: OutliningSpan[] = [];
|
||||
const collapseText = "...";
|
||||
let depth = 0;
|
||||
|
||||
function addOutliningSpan(hintSpanNode: Node, startElement: Node, endElement: Node, autoCollapse: boolean) {
|
||||
walk(sourceFile);
|
||||
return elements;
|
||||
|
||||
/** If useFullStart is true, then the collapsing span includes leading whitespace, including linebreaks. */
|
||||
function addOutliningSpan(hintSpanNode: Node, startElement: Node, endElement: Node, autoCollapse: boolean, useFullStart: boolean) {
|
||||
if (hintSpanNode && startElement && endElement) {
|
||||
const span: OutliningSpan = {
|
||||
textSpan: createTextSpanFromBounds(startElement.pos, endElement.end),
|
||||
textSpan: createTextSpanFromBounds(useFullStart ? startElement.getFullStart() : startElement.getStart(), endElement.getEnd()),
|
||||
hintSpan: createTextSpanFromNode(hintSpanNode, sourceFile),
|
||||
bannerText: collapseText,
|
||||
autoCollapse,
|
||||
@@ -82,8 +89,6 @@ namespace ts.OutliningElementsCollector {
|
||||
return isFunctionBlock(node) && node.parent.kind !== SyntaxKind.ArrowFunction;
|
||||
}
|
||||
|
||||
let depth = 0;
|
||||
const maxDepth = 20;
|
||||
function walk(n: Node): void {
|
||||
cancellationToken.throwIfCancellationRequested();
|
||||
if (depth > maxDepth) {
|
||||
@@ -113,7 +118,7 @@ namespace ts.OutliningElementsCollector {
|
||||
parent.kind === SyntaxKind.WithStatement ||
|
||||
parent.kind === SyntaxKind.CatchClause) {
|
||||
|
||||
addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n));
|
||||
addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n), /*useFullStart*/ true);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -121,13 +126,13 @@ namespace ts.OutliningElementsCollector {
|
||||
// Could be the try-block, or the finally-block.
|
||||
const tryStatement = <TryStatement>parent;
|
||||
if (tryStatement.tryBlock === n) {
|
||||
addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n));
|
||||
addOutliningSpan(parent, openBrace, closeBrace, autoCollapse(n), /*useFullStart*/ true);
|
||||
break;
|
||||
}
|
||||
else if (tryStatement.finallyBlock === n) {
|
||||
const finallyKeyword = findChildOfKind(tryStatement, SyntaxKind.FinallyKeyword, sourceFile);
|
||||
if (finallyKeyword) {
|
||||
addOutliningSpan(finallyKeyword, openBrace, closeBrace, autoCollapse(n));
|
||||
addOutliningSpan(finallyKeyword, openBrace, closeBrace, autoCollapse(n), /*useFullStart*/ true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -151,31 +156,35 @@ namespace ts.OutliningElementsCollector {
|
||||
case SyntaxKind.ModuleBlock: {
|
||||
const openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);
|
||||
const closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile);
|
||||
addOutliningSpan(n.parent, openBrace, closeBrace, autoCollapse(n));
|
||||
addOutliningSpan(n.parent, openBrace, closeBrace, autoCollapse(n), /*useFullStart*/ true);
|
||||
break;
|
||||
}
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.InterfaceDeclaration:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
case SyntaxKind.CaseBlock: {
|
||||
const openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);
|
||||
const closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile);
|
||||
addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n));
|
||||
addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n), /*useFullStart*/ true);
|
||||
break;
|
||||
}
|
||||
// If the block has no leading keywords and is inside an array literal,
|
||||
// we only want to collapse the span of the block.
|
||||
// Otherwise, the collapsed section will include the end of the previous line.
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
const openBrace = findChildOfKind(n, SyntaxKind.OpenBraceToken, sourceFile);
|
||||
const closeBrace = findChildOfKind(n, SyntaxKind.CloseBraceToken, sourceFile);
|
||||
addOutliningSpan(n, openBrace, closeBrace, autoCollapse(n), /*useFullStart*/ !isArrayLiteralExpression(n.parent));
|
||||
break;
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
const openBracket = findChildOfKind(n, SyntaxKind.OpenBracketToken, sourceFile);
|
||||
const closeBracket = findChildOfKind(n, SyntaxKind.CloseBracketToken, sourceFile);
|
||||
addOutliningSpan(n, openBracket, closeBracket, autoCollapse(n));
|
||||
addOutliningSpan(n, openBracket, closeBracket, autoCollapse(n), /*useFullStart*/ !isArrayLiteralExpression(n.parent));
|
||||
break;
|
||||
}
|
||||
depth++;
|
||||
forEachChild(n, walk);
|
||||
depth--;
|
||||
}
|
||||
|
||||
walk(sourceFile);
|
||||
return elements;
|
||||
}
|
||||
}
|
||||
@@ -830,10 +830,6 @@ namespace ts.refactor.extractMethod {
|
||||
}
|
||||
}
|
||||
|
||||
function isModuleBlock(n: Node): n is ModuleBlock {
|
||||
return n.kind === SyntaxKind.ModuleBlock;
|
||||
}
|
||||
|
||||
function isReadonlyArray(v: any): v is ReadonlyArray<any> {
|
||||
return isArray(v);
|
||||
}
|
||||
@@ -860,13 +856,13 @@ namespace ts.refactor.extractMethod {
|
||||
Write = 2
|
||||
}
|
||||
|
||||
interface UsageEntry {
|
||||
export interface UsageEntry {
|
||||
readonly usage: Usage;
|
||||
readonly symbol: Symbol;
|
||||
readonly node: Node;
|
||||
}
|
||||
|
||||
interface ScopeUsages {
|
||||
export interface ScopeUsages {
|
||||
usages: Map<UsageEntry>;
|
||||
substitutions: Map<Node>;
|
||||
}
|
||||
|
||||
+24
-12
@@ -107,12 +107,14 @@ namespace ts {
|
||||
scanner.setTextPos(pos);
|
||||
while (pos < end) {
|
||||
const token = scanner.scan();
|
||||
Debug.assert(token !== SyntaxKind.EndOfFileToken); // Else it would infinitely loop
|
||||
const textPos = scanner.getTextPos();
|
||||
if (textPos <= end) {
|
||||
nodes.push(createNode(token, pos, textPos, this));
|
||||
}
|
||||
pos = textPos;
|
||||
if (token === SyntaxKind.EndOfFileToken) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
@@ -1757,17 +1759,20 @@ namespace ts {
|
||||
function getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[] {
|
||||
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
|
||||
const settings = toEditorSettings(options);
|
||||
if (key === "{") {
|
||||
return formatting.formatOnOpeningCurly(position, sourceFile, getRuleProvider(settings), settings);
|
||||
}
|
||||
else if (key === "}") {
|
||||
return formatting.formatOnClosingCurly(position, sourceFile, getRuleProvider(settings), settings);
|
||||
}
|
||||
else if (key === ";") {
|
||||
return formatting.formatOnSemicolon(position, sourceFile, getRuleProvider(settings), settings);
|
||||
}
|
||||
else if (key === "\n") {
|
||||
return formatting.formatOnEnter(position, sourceFile, getRuleProvider(settings), settings);
|
||||
|
||||
if (!isInComment(sourceFile, position)) {
|
||||
if (key === "{") {
|
||||
return formatting.formatOnOpeningCurly(position, sourceFile, getRuleProvider(settings), settings);
|
||||
}
|
||||
else if (key === "}") {
|
||||
return formatting.formatOnClosingCurly(position, sourceFile, getRuleProvider(settings), settings);
|
||||
}
|
||||
else if (key === ";") {
|
||||
return formatting.formatOnSemicolon(position, sourceFile, getRuleProvider(settings), settings);
|
||||
}
|
||||
else if (key === "\n") {
|
||||
return formatting.formatOnEnter(position, sourceFile, getRuleProvider(settings), settings);
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
@@ -1826,6 +1831,12 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
|
||||
function getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean) {
|
||||
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
|
||||
const range = ts.formatting.getRangeOfEnclosingComment(sourceFile, position, onlyMultiLine);
|
||||
return range && createTextSpanFromRange(range);
|
||||
}
|
||||
|
||||
function getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[] {
|
||||
// Note: while getting todo comments seems like a syntactic operation, we actually
|
||||
// treat it as a semantic operation here. This is because we expect our host to call
|
||||
@@ -2050,6 +2061,7 @@ namespace ts {
|
||||
getFormattingEditsAfterKeystroke,
|
||||
getDocCommentTemplateAtPosition,
|
||||
isValidBraceCompletionAtPosition,
|
||||
getSpanOfEnclosingComment,
|
||||
getCodeFixesAtPosition,
|
||||
getEmitOutput,
|
||||
getNonBoundSourceFile,
|
||||
|
||||
+13
-1
@@ -254,6 +254,11 @@ namespace ts {
|
||||
*/
|
||||
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): string;
|
||||
|
||||
/**
|
||||
* Returns a JSON-encoded TextSpan | undefined indicating the range of the enclosing comment, if it exists.
|
||||
*/
|
||||
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): string;
|
||||
|
||||
getEmitOutput(fileName: string): string;
|
||||
getEmitOutputObject(fileName: string): EmitOutput;
|
||||
}
|
||||
@@ -815,6 +820,13 @@ namespace ts {
|
||||
);
|
||||
}
|
||||
|
||||
public getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): string {
|
||||
return this.forwardJSONCall(
|
||||
`getSpanOfEnclosingComment('${fileName}', ${position})`,
|
||||
() => this.languageService.getSpanOfEnclosingComment(fileName, position, onlyMultiLine)
|
||||
);
|
||||
}
|
||||
|
||||
/// GET SMART INDENT
|
||||
public getIndentationAtPosition(fileName: string, position: number, options: string /*Services.EditorOptions*/): string {
|
||||
return this.forwardJSONCall(
|
||||
@@ -1222,4 +1234,4 @@ namespace TypeScript.Services {
|
||||
// TODO: it should be moved into a namespace though.
|
||||
|
||||
/* @internal */
|
||||
const toolsVersion = "2.5";
|
||||
const toolsVersion = "2.6";
|
||||
|
||||
+108
-107
@@ -111,124 +111,123 @@ namespace ts.SymbolDisplay {
|
||||
|
||||
let signature: Signature;
|
||||
type = isThisExpression ? typeChecker.getTypeAtLocation(location) : typeChecker.getTypeOfSymbolAtLocation(symbol.exportSymbol || symbol, location);
|
||||
if (type) {
|
||||
if (location.parent && location.parent.kind === SyntaxKind.PropertyAccessExpression) {
|
||||
const right = (<PropertyAccessExpression>location.parent).name;
|
||||
// Either the location is on the right of a property access, or on the left and the right is missing
|
||||
if (right === location || (right && right.getFullWidth() === 0)) {
|
||||
location = location.parent;
|
||||
|
||||
if (location.parent && location.parent.kind === SyntaxKind.PropertyAccessExpression) {
|
||||
const right = (<PropertyAccessExpression>location.parent).name;
|
||||
// Either the location is on the right of a property access, or on the left and the right is missing
|
||||
if (right === location || (right && right.getFullWidth() === 0)) {
|
||||
location = location.parent;
|
||||
}
|
||||
}
|
||||
|
||||
// try get the call/construct signature from the type if it matches
|
||||
let callExpressionLike: CallExpression | NewExpression | JsxOpeningLikeElement;
|
||||
if (isCallOrNewExpression(location)) {
|
||||
callExpressionLike = <CallExpression | NewExpression>location;
|
||||
}
|
||||
else if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) {
|
||||
callExpressionLike = <CallExpression | NewExpression>location.parent;
|
||||
}
|
||||
else if (location.parent && isJsxOpeningLikeElement(location.parent) && isFunctionLike(symbol.valueDeclaration)) {
|
||||
callExpressionLike = <JsxOpeningLikeElement>location.parent;
|
||||
}
|
||||
|
||||
if (callExpressionLike) {
|
||||
const candidateSignatures: Signature[] = [];
|
||||
signature = typeChecker.getResolvedSignature(callExpressionLike, candidateSignatures);
|
||||
if (!signature && candidateSignatures.length) {
|
||||
// Use the first candidate:
|
||||
signature = candidateSignatures[0];
|
||||
}
|
||||
|
||||
const useConstructSignatures = callExpressionLike.kind === SyntaxKind.NewExpression || (isCallExpression(callExpressionLike) && callExpressionLike.expression.kind === SyntaxKind.SuperKeyword);
|
||||
|
||||
const allSignatures = useConstructSignatures ? type.getConstructSignatures() : type.getCallSignatures();
|
||||
|
||||
if (!contains(allSignatures, signature.target) && !contains(allSignatures, signature)) {
|
||||
// Get the first signature if there is one -- allSignatures may contain
|
||||
// either the original signature or its target, so check for either
|
||||
signature = allSignatures.length ? allSignatures[0] : undefined;
|
||||
}
|
||||
|
||||
if (signature) {
|
||||
if (useConstructSignatures && (symbolFlags & SymbolFlags.Class)) {
|
||||
// Constructor
|
||||
symbolKind = ScriptElementKind.constructorImplementationElement;
|
||||
addPrefixForAnyFunctionOrVar(type.symbol, symbolKind);
|
||||
}
|
||||
}
|
||||
|
||||
// try get the call/construct signature from the type if it matches
|
||||
let callExpressionLike: CallExpression | NewExpression | JsxOpeningLikeElement;
|
||||
if (isCallOrNewExpression(location)) {
|
||||
callExpressionLike = <CallExpression | NewExpression>location;
|
||||
}
|
||||
else if (isCallExpressionTarget(location) || isNewExpressionTarget(location)) {
|
||||
callExpressionLike = <CallExpression | NewExpression>location.parent;
|
||||
}
|
||||
else if (location.parent && isJsxOpeningLikeElement(location.parent) && isFunctionLike(symbol.valueDeclaration)) {
|
||||
callExpressionLike = <JsxOpeningLikeElement>location.parent;
|
||||
}
|
||||
|
||||
if (callExpressionLike) {
|
||||
const candidateSignatures: Signature[] = [];
|
||||
signature = typeChecker.getResolvedSignature(callExpressionLike, candidateSignatures);
|
||||
if (!signature && candidateSignatures.length) {
|
||||
// Use the first candidate:
|
||||
signature = candidateSignatures[0];
|
||||
}
|
||||
|
||||
const useConstructSignatures = callExpressionLike.kind === SyntaxKind.NewExpression || (isCallExpression(callExpressionLike) && callExpressionLike.expression.kind === SyntaxKind.SuperKeyword);
|
||||
|
||||
const allSignatures = useConstructSignatures ? type.getConstructSignatures() : type.getCallSignatures();
|
||||
|
||||
if (!contains(allSignatures, signature.target) && !contains(allSignatures, signature)) {
|
||||
// Get the first signature if there is one -- allSignatures may contain
|
||||
// either the original signature or its target, so check for either
|
||||
signature = allSignatures.length ? allSignatures[0] : undefined;
|
||||
}
|
||||
|
||||
if (signature) {
|
||||
if (useConstructSignatures && (symbolFlags & SymbolFlags.Class)) {
|
||||
// Constructor
|
||||
symbolKind = ScriptElementKind.constructorImplementationElement;
|
||||
addPrefixForAnyFunctionOrVar(type.symbol, symbolKind);
|
||||
else if (symbolFlags & SymbolFlags.Alias) {
|
||||
symbolKind = ScriptElementKind.alias;
|
||||
pushTypePart(symbolKind);
|
||||
displayParts.push(spacePart());
|
||||
if (useConstructSignatures) {
|
||||
displayParts.push(keywordPart(SyntaxKind.NewKeyword));
|
||||
displayParts.push(spacePart());
|
||||
}
|
||||
else if (symbolFlags & SymbolFlags.Alias) {
|
||||
symbolKind = ScriptElementKind.alias;
|
||||
pushTypePart(symbolKind);
|
||||
addFullSymbolName(symbol);
|
||||
}
|
||||
else {
|
||||
addPrefixForAnyFunctionOrVar(symbol, symbolKind);
|
||||
}
|
||||
|
||||
switch (symbolKind) {
|
||||
case ScriptElementKind.jsxAttribute:
|
||||
case ScriptElementKind.memberVariableElement:
|
||||
case ScriptElementKind.variableElement:
|
||||
case ScriptElementKind.constElement:
|
||||
case ScriptElementKind.letElement:
|
||||
case ScriptElementKind.parameterElement:
|
||||
case ScriptElementKind.localVariableElement:
|
||||
// If it is call or construct signature of lambda's write type name
|
||||
displayParts.push(punctuationPart(SyntaxKind.ColonToken));
|
||||
displayParts.push(spacePart());
|
||||
if (useConstructSignatures) {
|
||||
displayParts.push(keywordPart(SyntaxKind.NewKeyword));
|
||||
displayParts.push(spacePart());
|
||||
}
|
||||
addFullSymbolName(symbol);
|
||||
}
|
||||
else {
|
||||
addPrefixForAnyFunctionOrVar(symbol, symbolKind);
|
||||
}
|
||||
if (!(type.flags & TypeFlags.Object && (<ObjectType>type).objectFlags & ObjectFlags.Anonymous) && type.symbol) {
|
||||
addRange(displayParts, symbolToDisplayParts(typeChecker, type.symbol, enclosingDeclaration, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments));
|
||||
}
|
||||
addSignatureDisplayParts(signature, allSignatures, TypeFormatFlags.WriteArrowStyleSignature);
|
||||
break;
|
||||
|
||||
switch (symbolKind) {
|
||||
case ScriptElementKind.jsxAttribute:
|
||||
case ScriptElementKind.memberVariableElement:
|
||||
case ScriptElementKind.variableElement:
|
||||
case ScriptElementKind.constElement:
|
||||
case ScriptElementKind.letElement:
|
||||
case ScriptElementKind.parameterElement:
|
||||
case ScriptElementKind.localVariableElement:
|
||||
// If it is call or construct signature of lambda's write type name
|
||||
displayParts.push(punctuationPart(SyntaxKind.ColonToken));
|
||||
displayParts.push(spacePart());
|
||||
if (useConstructSignatures) {
|
||||
displayParts.push(keywordPart(SyntaxKind.NewKeyword));
|
||||
displayParts.push(spacePart());
|
||||
}
|
||||
if (!(type.flags & TypeFlags.Object && (<ObjectType>type).objectFlags & ObjectFlags.Anonymous) && type.symbol) {
|
||||
addRange(displayParts, symbolToDisplayParts(typeChecker, type.symbol, enclosingDeclaration, /*meaning*/ undefined, SymbolFormatFlags.WriteTypeParametersOrArguments));
|
||||
}
|
||||
addSignatureDisplayParts(signature, allSignatures, TypeFormatFlags.WriteArrowStyleSignature);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Just signature
|
||||
addSignatureDisplayParts(signature, allSignatures);
|
||||
}
|
||||
hasAddedSymbolInfo = true;
|
||||
default:
|
||||
// Just signature
|
||||
addSignatureDisplayParts(signature, allSignatures);
|
||||
}
|
||||
hasAddedSymbolInfo = true;
|
||||
}
|
||||
else if ((isNameOfFunctionDeclaration(location) && !(symbolFlags & SymbolFlags.Accessor)) || // name of function declaration
|
||||
(location.kind === SyntaxKind.ConstructorKeyword && location.parent.kind === SyntaxKind.Constructor)) { // At constructor keyword of constructor declaration
|
||||
// get the signature from the declaration and write it
|
||||
const functionDeclaration = <FunctionLike>location.parent;
|
||||
// Use function declaration to write the signatures only if the symbol corresponding to this declaration
|
||||
const locationIsSymbolDeclaration = find(symbol.declarations, declaration =>
|
||||
declaration === (location.kind === SyntaxKind.ConstructorKeyword ? functionDeclaration.parent : functionDeclaration));
|
||||
}
|
||||
else if ((isNameOfFunctionDeclaration(location) && !(symbolFlags & SymbolFlags.Accessor)) || // name of function declaration
|
||||
(location.kind === SyntaxKind.ConstructorKeyword && location.parent.kind === SyntaxKind.Constructor)) { // At constructor keyword of constructor declaration
|
||||
// get the signature from the declaration and write it
|
||||
const functionDeclaration = <FunctionLike>location.parent;
|
||||
// Use function declaration to write the signatures only if the symbol corresponding to this declaration
|
||||
const locationIsSymbolDeclaration = find(symbol.declarations, declaration =>
|
||||
declaration === (location.kind === SyntaxKind.ConstructorKeyword ? functionDeclaration.parent : functionDeclaration));
|
||||
|
||||
if (locationIsSymbolDeclaration) {
|
||||
const allSignatures = functionDeclaration.kind === SyntaxKind.Constructor ? type.getNonNullableType().getConstructSignatures() : type.getNonNullableType().getCallSignatures();
|
||||
if (!typeChecker.isImplementationOfOverload(functionDeclaration)) {
|
||||
signature = typeChecker.getSignatureFromDeclaration(functionDeclaration);
|
||||
}
|
||||
else {
|
||||
signature = allSignatures[0];
|
||||
}
|
||||
|
||||
if (functionDeclaration.kind === SyntaxKind.Constructor) {
|
||||
// show (constructor) Type(...) signature
|
||||
symbolKind = ScriptElementKind.constructorImplementationElement;
|
||||
addPrefixForAnyFunctionOrVar(type.symbol, symbolKind);
|
||||
}
|
||||
else {
|
||||
// (function/method) symbol(..signature)
|
||||
addPrefixForAnyFunctionOrVar(functionDeclaration.kind === SyntaxKind.CallSignature &&
|
||||
!(type.symbol.flags & SymbolFlags.TypeLiteral || type.symbol.flags & SymbolFlags.ObjectLiteral) ? type.symbol : symbol, symbolKind);
|
||||
}
|
||||
|
||||
addSignatureDisplayParts(signature, allSignatures);
|
||||
hasAddedSymbolInfo = true;
|
||||
if (locationIsSymbolDeclaration) {
|
||||
const allSignatures = functionDeclaration.kind === SyntaxKind.Constructor ? type.getNonNullableType().getConstructSignatures() : type.getNonNullableType().getCallSignatures();
|
||||
if (!typeChecker.isImplementationOfOverload(functionDeclaration)) {
|
||||
signature = typeChecker.getSignatureFromDeclaration(functionDeclaration);
|
||||
}
|
||||
else {
|
||||
signature = allSignatures[0];
|
||||
}
|
||||
|
||||
if (functionDeclaration.kind === SyntaxKind.Constructor) {
|
||||
// show (constructor) Type(...) signature
|
||||
symbolKind = ScriptElementKind.constructorImplementationElement;
|
||||
addPrefixForAnyFunctionOrVar(type.symbol, symbolKind);
|
||||
}
|
||||
else {
|
||||
// (function/method) symbol(..signature)
|
||||
addPrefixForAnyFunctionOrVar(functionDeclaration.kind === SyntaxKind.CallSignature &&
|
||||
!(type.symbol.flags & SymbolFlags.TypeLiteral || type.symbol.flags & SymbolFlags.ObjectLiteral) ? type.symbol : symbol, symbolKind);
|
||||
}
|
||||
|
||||
addSignatureDisplayParts(signature, allSignatures);
|
||||
hasAddedSymbolInfo = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -417,7 +416,9 @@ namespace ts.SymbolDisplay {
|
||||
symbolFlags & SymbolFlags.Accessor ||
|
||||
symbolKind === ScriptElementKind.memberFunctionElement) {
|
||||
const allSignatures = type.getNonNullableType().getCallSignatures();
|
||||
addSignatureDisplayParts(allSignatures[0], allSignatures);
|
||||
if (allSignatures.length) {
|
||||
addSignatureDisplayParts(allSignatures[0], allSignatures);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace ts.textChanges {
|
||||
*/
|
||||
export type ConfigurableStartEnd = ConfigurableStart & ConfigurableEnd;
|
||||
|
||||
interface InsertNodeOptions {
|
||||
export interface InsertNodeOptions {
|
||||
/**
|
||||
* Text to be inserted before the new node
|
||||
*/
|
||||
@@ -96,7 +96,7 @@ namespace ts.textChanges {
|
||||
readonly range: TextRange;
|
||||
}
|
||||
|
||||
interface ChangeNodeOptions extends ConfigurableStartEnd, InsertNodeOptions {
|
||||
export interface ChangeNodeOptions extends ConfigurableStartEnd, InsertNodeOptions {
|
||||
readonly useIndentationFromFile?: boolean;
|
||||
}
|
||||
interface ReplaceWithSingleNode extends BaseChange {
|
||||
@@ -111,7 +111,7 @@ namespace ts.textChanges {
|
||||
readonly options?: never;
|
||||
}
|
||||
|
||||
interface ChangeMultipleNodesOptions extends ChangeNodeOptions {
|
||||
export interface ChangeMultipleNodesOptions extends ChangeNodeOptions {
|
||||
nodeSeparator: string;
|
||||
}
|
||||
interface ReplaceWithMultipleNodes extends BaseChange {
|
||||
|
||||
@@ -270,6 +270,8 @@ namespace ts {
|
||||
|
||||
isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean;
|
||||
|
||||
getSpanOfEnclosingComment(fileName: string, position: number, onlyMultiLine: boolean): TextSpan;
|
||||
|
||||
getCodeFixesAtPosition(fileName: string, start: number, end: number, errorCodes: number[], formatOptions: FormatCodeSettings): CodeAction[];
|
||||
getApplicableRefactors(fileName: string, positionOrRaneg: number | TextRange): ApplicableRefactorInfo[];
|
||||
getEditsForRefactor(fileName: string, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string): RefactorEditInfo | undefined;
|
||||
|
||||
+36
-50
@@ -720,8 +720,14 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node, includeJsDoc?: boolean): Node {
|
||||
return find(startNode || sourceFile);
|
||||
/**
|
||||
* Finds the rightmost token satisfying `token.end <= position`,
|
||||
* excluding `JsxText` tokens containing only whitespace.
|
||||
*/
|
||||
export function findPrecedingToken(position: number, sourceFile: SourceFile, startNode?: Node, includeJsDoc?: boolean): Node | undefined {
|
||||
const result = find(startNode || sourceFile);
|
||||
Debug.assert(!(result && isWhiteSpaceOnlyJsxText(result)));
|
||||
return result;
|
||||
|
||||
function findRightmostToken(n: Node): Node {
|
||||
if (isToken(n)) {
|
||||
@@ -742,19 +748,17 @@ namespace ts {
|
||||
const children = n.getChildren();
|
||||
for (let i = 0; i < children.length; i++) {
|
||||
const child = children[i];
|
||||
// condition 'position < child.end' checks if child node end after the position
|
||||
// in the example below this condition will be false for 'aaaa' and 'bbbb' and true for 'ccc'
|
||||
// aaaa___bbbb___$__ccc
|
||||
// after we found child node with end after the position we check if start of the node is after the position.
|
||||
// if yes - then position is in the trivia and we need to look into the previous child to find the token in question.
|
||||
// if no - position is in the node itself so we should recurse in it.
|
||||
// NOTE: JsxText is a weird kind of node that can contain only whitespaces (since they are not counted as trivia).
|
||||
// if this is the case - then we should assume that token in question is located in previous child.
|
||||
if (position < child.end && (nodeHasTokens(child) || child.kind === SyntaxKind.JsxText)) {
|
||||
// Note that the span of a node's tokens is [node.getStart(...), node.end).
|
||||
// Given that `position < child.end` and child has constituent tokens, we distinguish these cases:
|
||||
// 1) `position` precedes `child`'s tokens or `child` has no tokens (ie: in a comment or whitespace preceding `child`):
|
||||
// we need to find the last token in a previous child.
|
||||
// 2) `position` is within the same span: we recurse on `child`.
|
||||
if (position < child.end) {
|
||||
const start = child.getStart(sourceFile, includeJsDoc);
|
||||
const lookInPreviousChild =
|
||||
(start >= position) || // cursor in the leading trivia
|
||||
(child.kind === SyntaxKind.JsxText && start === child.end); // whitespace only JsxText
|
||||
!nodeHasTokens(child) ||
|
||||
isWhiteSpaceOnlyJsxText(child);
|
||||
|
||||
if (lookInPreviousChild) {
|
||||
// actual start of the node is past the position - previous token should be at the end of previous child
|
||||
@@ -780,10 +784,17 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
/// finds last node that is considered as candidate for search (isCandidate(node) === true) starting from 'exclusiveStartPosition'
|
||||
/**
|
||||
* Finds the rightmost child to the left of `children[exclusiveStartPosition]` which is a non-all-whitespace token or has constituent tokens.
|
||||
*/
|
||||
function findRightmostChildNodeWithTokens(children: Node[], exclusiveStartPosition: number): Node {
|
||||
for (let i = exclusiveStartPosition - 1; i >= 0; i--) {
|
||||
if (nodeHasTokens(children[i])) {
|
||||
const child = children[i];
|
||||
|
||||
if (isWhiteSpaceOnlyJsxText(child)) {
|
||||
Debug.assert(i > 0, "`JsxText` tokens should not be the first child of `JsxElement | JsxSelfClosingElement`");
|
||||
}
|
||||
else if (nodeHasTokens(children[i])) {
|
||||
return children[i];
|
||||
}
|
||||
}
|
||||
@@ -851,6 +862,10 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isWhiteSpaceOnlyJsxText(node: Node): node is JsxText {
|
||||
return isJsxText(node) && node.containsOnlyWhiteSpaces;
|
||||
}
|
||||
|
||||
export function isInTemplateString(sourceFile: SourceFile, position: number) {
|
||||
const token = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ false);
|
||||
return isTemplateLiteralKind(token.kind) && position > token.getStart(sourceFile);
|
||||
@@ -863,41 +878,11 @@ namespace ts {
|
||||
* @param predicate Additional predicate to test on the comment range.
|
||||
*/
|
||||
export function isInComment(
|
||||
sourceFile: SourceFile,
|
||||
position: number,
|
||||
tokenAtPosition = getTokenAtPosition(sourceFile, position, /*includeJsDocComment*/ false),
|
||||
predicate?: (c: CommentRange) => boolean): boolean {
|
||||
return position <= tokenAtPosition.getStart(sourceFile) &&
|
||||
(isInCommentRange(getLeadingCommentRanges(sourceFile.text, tokenAtPosition.pos)) ||
|
||||
isInCommentRange(getTrailingCommentRanges(sourceFile.text, tokenAtPosition.pos)));
|
||||
|
||||
function isInCommentRange(commentRanges: CommentRange[]): boolean {
|
||||
return forEach(commentRanges, c => isPositionInCommentRange(c, position, sourceFile.text) && (!predicate || predicate(c)));
|
||||
}
|
||||
}
|
||||
|
||||
function isPositionInCommentRange({ pos, end, kind }: ts.CommentRange, position: number, text: string): boolean {
|
||||
if (pos < position && position < end) {
|
||||
return true;
|
||||
}
|
||||
else if (position === end) {
|
||||
// The end marker of a single-line comment does not include the newline character.
|
||||
// In the following case, we are inside a comment (^ denotes the cursor position):
|
||||
//
|
||||
// // asdf ^\n
|
||||
//
|
||||
// But for multi-line comments, we don't want to be inside the comment in the following case:
|
||||
//
|
||||
// /* asdf */^
|
||||
//
|
||||
// Internally, we represent the end of the comment at the newline and closing '/', respectively.
|
||||
return kind === SyntaxKind.SingleLineCommentTrivia ||
|
||||
// true for unterminated multi-line comment
|
||||
!(text.charCodeAt(end - 1) === CharacterCodes.slash && text.charCodeAt(end - 2) === CharacterCodes.asterisk);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
sourceFile: SourceFile,
|
||||
position: number,
|
||||
tokenAtPosition?: Node,
|
||||
predicate?: (c: CommentRange) => boolean): boolean {
|
||||
return !!formatting.getRangeOfEnclosingComment(sourceFile, position, /*onlyMultiLine*/ false, /*precedingToken*/ undefined, tokenAtPosition, predicate);
|
||||
}
|
||||
|
||||
export function hasDocComment(sourceFile: SourceFile, position: number) {
|
||||
@@ -916,7 +901,7 @@ namespace ts {
|
||||
|
||||
function nodeHasTokens(n: Node): boolean {
|
||||
// If we have a token or node that has a non-zero width, it must have tokens.
|
||||
// Note, that getWidth() does not take trivia into account.
|
||||
// Note: getWidth() does not take trivia into account.
|
||||
return n.getWidth() !== 0;
|
||||
}
|
||||
|
||||
@@ -1261,6 +1246,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function signatureToDisplayParts(typechecker: TypeChecker, signature: Signature, enclosingDeclaration?: Node, flags?: TypeFormatFlags): SymbolDisplayPart[] {
|
||||
flags |= TypeFormatFlags.UseAliasDefinedOutsideCurrentScope;
|
||||
return mapToDisplayParts(writer => {
|
||||
typechecker.getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags);
|
||||
});
|
||||
|
||||
@@ -16,17 +16,17 @@ class Board {
|
||||
}
|
||||
|
||||
//// [2dArrays.js]
|
||||
var Cell = (function () {
|
||||
var Cell = /** @class */ (function () {
|
||||
function Cell() {
|
||||
}
|
||||
return Cell;
|
||||
}());
|
||||
var Ship = (function () {
|
||||
var Ship = /** @class */ (function () {
|
||||
function Ship() {
|
||||
}
|
||||
return Ship;
|
||||
}());
|
||||
var Board = (function () {
|
||||
var Board = /** @class */ (function () {
|
||||
function Board() {
|
||||
}
|
||||
Board.prototype.allShipsSunk = function () {
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ var p = new A.Point(0, 0); // unexpected error here, bug 840000
|
||||
//// [classPoint.js]
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
+6
-6
@@ -51,7 +51,7 @@ module clodule4 {
|
||||
|
||||
//// [ClassAndModuleThatMergeWithModuleMemberThatUsesClassTypeParameter.js]
|
||||
// all expected to be errors
|
||||
var clodule1 = (function () {
|
||||
var clodule1 = /** @class */ (function () {
|
||||
function clodule1() {
|
||||
}
|
||||
return clodule1;
|
||||
@@ -59,20 +59,20 @@ var clodule1 = (function () {
|
||||
(function (clodule1) {
|
||||
function f(x) { }
|
||||
})(clodule1 || (clodule1 = {}));
|
||||
var clodule2 = (function () {
|
||||
var clodule2 = /** @class */ (function () {
|
||||
function clodule2() {
|
||||
}
|
||||
return clodule2;
|
||||
}());
|
||||
(function (clodule2) {
|
||||
var x;
|
||||
var D = (function () {
|
||||
var D = /** @class */ (function () {
|
||||
function D() {
|
||||
}
|
||||
return D;
|
||||
}());
|
||||
})(clodule2 || (clodule2 = {}));
|
||||
var clodule3 = (function () {
|
||||
var clodule3 = /** @class */ (function () {
|
||||
function clodule3() {
|
||||
}
|
||||
return clodule3;
|
||||
@@ -80,13 +80,13 @@ var clodule3 = (function () {
|
||||
(function (clodule3) {
|
||||
clodule3.y = { id: T };
|
||||
})(clodule3 || (clodule3 = {}));
|
||||
var clodule4 = (function () {
|
||||
var clodule4 = /** @class */ (function () {
|
||||
function clodule4() {
|
||||
}
|
||||
return clodule4;
|
||||
}());
|
||||
(function (clodule4) {
|
||||
var D = (function () {
|
||||
var D = /** @class */ (function () {
|
||||
function D() {
|
||||
}
|
||||
return D;
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ module clodule {
|
||||
|
||||
|
||||
//// [ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndGenericClassStaticFunctionOfTheSameName.js]
|
||||
var clodule = (function () {
|
||||
var clodule = /** @class */ (function () {
|
||||
function clodule() {
|
||||
}
|
||||
clodule.fn = function (id) { };
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ module clodule {
|
||||
|
||||
|
||||
//// [ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndNonGenericClassStaticFunctionOfTheSameName.js]
|
||||
var clodule = (function () {
|
||||
var clodule = /** @class */ (function () {
|
||||
function clodule() {
|
||||
}
|
||||
clodule.fn = function (id) { };
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ module clodule {
|
||||
|
||||
|
||||
//// [ClassAndModuleThatMergeWithModulesExportedStaticFunctionUsingClassPrivateStatics.js]
|
||||
var clodule = (function () {
|
||||
var clodule = /** @class */ (function () {
|
||||
function clodule() {
|
||||
}
|
||||
clodule.sfn = function (id) { return 42; };
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ module A {
|
||||
}
|
||||
|
||||
//// [ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.js]
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -37,7 +37,7 @@ var Point = (function () {
|
||||
})(Point || (Point = {}));
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ module A {
|
||||
}
|
||||
|
||||
//// [ClassAndModuleThatMergeWithStaticFunctionAndNonExportedFunctionThatShareAName.js]
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -36,7 +36,7 @@ var Point = (function () {
|
||||
})(Point || (Point = {}));
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ module A {
|
||||
}
|
||||
|
||||
//// [ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.js]
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -36,7 +36,7 @@ var Point = (function () {
|
||||
})(Point || (Point = {}));
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ module A {
|
||||
}
|
||||
|
||||
//// [ClassAndModuleThatMergeWithStaticVariableAndNonExportedVarThatShareAName.js]
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -36,7 +36,7 @@ var Point = (function () {
|
||||
})(Point || (Point = {}));
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
@@ -45,7 +45,7 @@ var X;
|
||||
(function (X) {
|
||||
var Y;
|
||||
(function (Y) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -71,7 +71,7 @@ var X;
|
||||
var cl = new X.Y.Point(1, 1);
|
||||
var cl = X.Y.Point.Origin; // error not expected here same as bug 83996 ?
|
||||
//// [simple.js]
|
||||
var A = (function () {
|
||||
var A = /** @class */ (function () {
|
||||
function A() {
|
||||
}
|
||||
return A;
|
||||
|
||||
@@ -5,7 +5,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [ClassDeclaration10.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
|
||||
@@ -5,7 +5,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [ClassDeclaration11.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.foo = function () { };
|
||||
|
||||
@@ -5,7 +5,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [ClassDeclaration13.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.bar = function () { };
|
||||
|
||||
@@ -5,7 +5,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [ClassDeclaration14.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
|
||||
@@ -5,7 +5,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [ClassDeclaration15.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
|
||||
@@ -5,7 +5,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [ClassDeclaration21.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype[1] = function () { };
|
||||
|
||||
@@ -5,7 +5,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [ClassDeclaration22.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype["bar"] = function () { };
|
||||
|
||||
@@ -3,7 +3,7 @@ class any {
|
||||
}
|
||||
|
||||
//// [ClassDeclaration24.js]
|
||||
var any = (function () {
|
||||
var any = /** @class */ (function () {
|
||||
function any() {
|
||||
}
|
||||
return any;
|
||||
|
||||
@@ -10,7 +10,7 @@ class List<U> implements IList<U> {
|
||||
|
||||
|
||||
//// [ClassDeclaration25.js]
|
||||
var List = (function () {
|
||||
var List = /** @class */ (function () {
|
||||
function List() {
|
||||
}
|
||||
return List;
|
||||
|
||||
@@ -6,7 +6,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [ClassDeclaration26.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
this.foo = 10;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [ClassDeclaration8.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
|
||||
@@ -4,7 +4,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [ClassDeclaration9.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
|
||||
@@ -4,7 +4,7 @@ class AtomicNumbers {
|
||||
}
|
||||
|
||||
//// [ClassDeclarationWithInvalidConstOnPropertyDeclaration.js]
|
||||
var AtomicNumbers = (function () {
|
||||
var AtomicNumbers = /** @class */ (function () {
|
||||
function AtomicNumbers() {
|
||||
}
|
||||
AtomicNumbers.H = 1;
|
||||
|
||||
@@ -5,7 +5,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [ClassDeclarationWithInvalidConstOnPropertyDeclaration2.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
this.x = 10;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ for (var v of new StringIterator) { }
|
||||
|
||||
//// [ES5For-ofTypeCheck10.js]
|
||||
// In ES3/5, you cannot for...of over an arbitrary iterable.
|
||||
var StringIterator = (function () {
|
||||
var StringIterator = /** @class */ (function () {
|
||||
function StringIterator() {
|
||||
}
|
||||
StringIterator.prototype.next = function () {
|
||||
|
||||
@@ -14,7 +14,7 @@ module M {
|
||||
var M;
|
||||
(function (M) {
|
||||
var Symbol;
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype[Symbol.iterator] = function () { };
|
||||
|
||||
@@ -9,7 +9,7 @@ class C {
|
||||
|
||||
//// [ES5SymbolProperty3.js]
|
||||
var Symbol;
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype[Symbol.iterator] = function () { };
|
||||
|
||||
@@ -9,7 +9,7 @@ class C {
|
||||
|
||||
//// [ES5SymbolProperty4.js]
|
||||
var Symbol;
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype[Symbol.iterator] = function () { };
|
||||
|
||||
@@ -9,7 +9,7 @@ class C {
|
||||
|
||||
//// [ES5SymbolProperty5.js]
|
||||
var Symbol;
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype[Symbol.iterator] = function () { };
|
||||
|
||||
@@ -6,7 +6,7 @@ class C {
|
||||
(new C)[Symbol.iterator]
|
||||
|
||||
//// [ES5SymbolProperty6.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype[Symbol.iterator] = function () { };
|
||||
|
||||
@@ -9,7 +9,7 @@ class C {
|
||||
|
||||
//// [ES5SymbolProperty7.js]
|
||||
var Symbol;
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype[Symbol.iterator] = function () { };
|
||||
|
||||
@@ -23,7 +23,7 @@ var enumdule;
|
||||
enumdule[enumdule["Blue"] = 1] = "Blue";
|
||||
})(enumdule || (enumdule = {}));
|
||||
(function (enumdule) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
@@ -6,7 +6,7 @@ export = B;
|
||||
|
||||
//// [ExportAssignment7.js]
|
||||
"use strict";
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
|
||||
@@ -6,7 +6,7 @@ export class C {
|
||||
|
||||
//// [ExportAssignment8.js]
|
||||
"use strict";
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
|
||||
@@ -22,7 +22,7 @@ module A {
|
||||
//// [ExportClassWhichExtendsInterfaceWithInaccessibleType.js]
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point2d = (function () {
|
||||
var Point2d = /** @class */ (function () {
|
||||
function Point2d(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
+3
-3
@@ -33,14 +33,14 @@ var __extends = (this && this.__extends) || (function () {
|
||||
})();
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point() {
|
||||
}
|
||||
return Point;
|
||||
}());
|
||||
A.Point = Point;
|
||||
A.Origin = { x: 0, y: 0 };
|
||||
var Point3d = (function (_super) {
|
||||
var Point3d = /** @class */ (function (_super) {
|
||||
__extends(Point3d, _super);
|
||||
function Point3d() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
@@ -49,7 +49,7 @@ var A;
|
||||
}(Point));
|
||||
A.Point3d = Point3d;
|
||||
A.Origin3d = { x: 0, y: 0, z: 0 };
|
||||
var Line = (function () {
|
||||
var Line = /** @class */ (function () {
|
||||
function Line(start, end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
|
||||
+2
-2
@@ -18,12 +18,12 @@ module A {
|
||||
//// [ExportClassWithInaccessibleTypeInIndexerTypeAnnotations.js]
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point() {
|
||||
}
|
||||
return Point;
|
||||
}());
|
||||
var points = (function () {
|
||||
var points = /** @class */ (function () {
|
||||
function points() {
|
||||
}
|
||||
return points;
|
||||
|
||||
+3
-3
@@ -37,13 +37,13 @@ var __extends = (this && this.__extends) || (function () {
|
||||
})();
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point() {
|
||||
}
|
||||
return Point;
|
||||
}());
|
||||
A.Origin = { x: 0, y: 0 };
|
||||
var Point3d = (function (_super) {
|
||||
var Point3d = /** @class */ (function (_super) {
|
||||
__extends(Point3d, _super);
|
||||
function Point3d() {
|
||||
return _super !== null && _super.apply(this, arguments) || this;
|
||||
@@ -52,7 +52,7 @@ var A;
|
||||
}(Point));
|
||||
A.Point3d = Point3d;
|
||||
A.Origin3d = { x: 0, y: 0, z: 0 };
|
||||
var Line = (function () {
|
||||
var Line = /** @class */ (function () {
|
||||
function Line(start, end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
|
||||
+2
-2
@@ -18,13 +18,13 @@ module A {
|
||||
//// [ExportFunctionWithAccessibleTypesInParameterAndReturnTypeAnnotation.js]
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point() {
|
||||
}
|
||||
return Point;
|
||||
}());
|
||||
A.Point = Point;
|
||||
var Line = (function () {
|
||||
var Line = /** @class */ (function () {
|
||||
function Line(start, end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
|
||||
+2
-2
@@ -18,12 +18,12 @@ module A {
|
||||
//// [ExportFunctionWithInaccessibleTypesInParameterTypeAnnotation.js]
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point() {
|
||||
}
|
||||
return Point;
|
||||
}());
|
||||
var Line = (function () {
|
||||
var Line = /** @class */ (function () {
|
||||
function Line(start, end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
|
||||
+2
-2
@@ -18,13 +18,13 @@ module A {
|
||||
//// [ExportFunctionWithInaccessibleTypesInReturnTypeAnnotation.js]
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point() {
|
||||
}
|
||||
return Point;
|
||||
}());
|
||||
A.Point = Point;
|
||||
var Line = (function () {
|
||||
var Line = /** @class */ (function () {
|
||||
function Line(start, end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
|
||||
@@ -23,7 +23,7 @@ module A {
|
||||
//// [ExportModuleWithAccessibleTypesOnItsExportedMembers.js]
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -34,7 +34,7 @@ var A;
|
||||
var B;
|
||||
(function (B) {
|
||||
B.Origin = new Point(0, 0);
|
||||
var Line = (function () {
|
||||
var Line = /** @class */ (function () {
|
||||
function Line(start, end) {
|
||||
}
|
||||
Line.fromOrigin = function (p) {
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ module A {
|
||||
//// [ExportObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInMemberTypeAnnotations.js]
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ module A {
|
||||
//// [ExportObjectLiteralAndObjectTypeLiteralWithAccessibleTypesInNestedMemberTypeAnnotations.js]
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ module A {
|
||||
//// [ExportVariableOfGenericTypeWithInaccessibleTypeAsTypeArgument.js]
|
||||
var A;
|
||||
(function (A) {
|
||||
var B = (function () {
|
||||
var B = /** @class */ (function () {
|
||||
function B() {
|
||||
}
|
||||
return B;
|
||||
|
||||
@@ -4,7 +4,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [MemberAccessorDeclaration15.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
Object.defineProperty(C.prototype, "Foo", {
|
||||
|
||||
@@ -48,7 +48,7 @@ var X;
|
||||
var Y;
|
||||
(function (Y) {
|
||||
// duplicate identifier
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -64,7 +64,7 @@ var A;
|
||||
A.Instance = new A();
|
||||
})(A || (A = {}));
|
||||
// duplicate identifier
|
||||
var A = (function () {
|
||||
var A = /** @class */ (function () {
|
||||
function A() {
|
||||
}
|
||||
return A;
|
||||
|
||||
@@ -19,7 +19,7 @@ var y = new enumdule.Point(0, 0);
|
||||
//// [ModuleAndEnumWithSameNameAndCommonRoot.js]
|
||||
var enumdule;
|
||||
(function (enumdule) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point(x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
|
||||
@@ -36,24 +36,24 @@ var ag2 = new A.A2<string, number>();
|
||||
//// [ModuleWithExportedAndNonExportedClasses.js]
|
||||
var A;
|
||||
(function (A_1) {
|
||||
var A = (function () {
|
||||
var A = /** @class */ (function () {
|
||||
function A() {
|
||||
}
|
||||
return A;
|
||||
}());
|
||||
A_1.A = A;
|
||||
var AG = (function () {
|
||||
var AG = /** @class */ (function () {
|
||||
function AG() {
|
||||
}
|
||||
return AG;
|
||||
}());
|
||||
A_1.AG = AG;
|
||||
var A2 = (function () {
|
||||
var A2 = /** @class */ (function () {
|
||||
function A2() {
|
||||
}
|
||||
return A2;
|
||||
}());
|
||||
var AG2 = (function () {
|
||||
var AG2 = /** @class */ (function () {
|
||||
function AG2() {
|
||||
}
|
||||
return AG2;
|
||||
|
||||
@@ -42,7 +42,7 @@ var line = Geometry.Lines.Line;
|
||||
//// [ModuleWithExportedAndNonExportedImportAlias.js]
|
||||
var B;
|
||||
(function (B) {
|
||||
var Line = (function () {
|
||||
var Line = /** @class */ (function () {
|
||||
function Line(start, end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
|
||||
@@ -40,7 +40,7 @@ var Inner;
|
||||
var ;
|
||||
let;
|
||||
var ;
|
||||
var A = (function () {
|
||||
var A = /** @class */ (function () {
|
||||
function A() {
|
||||
}
|
||||
return A;
|
||||
@@ -58,7 +58,7 @@ var Inner;
|
||||
Inner.b1 = 1;
|
||||
Inner.c1 = 'a';
|
||||
Inner.d1 = 1;
|
||||
var D = (function () {
|
||||
var D = /** @class */ (function () {
|
||||
function D() {
|
||||
}
|
||||
return D;
|
||||
|
||||
@@ -5,7 +5,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [ParameterList6.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C(C) {
|
||||
}
|
||||
return C;
|
||||
|
||||
@@ -6,7 +6,7 @@ class C1 {
|
||||
}
|
||||
|
||||
//// [ParameterList7.js]
|
||||
var C1 = (function () {
|
||||
var C1 = /** @class */ (function () {
|
||||
function C1(p3) {
|
||||
this.p3 = p3;
|
||||
} // OK
|
||||
|
||||
@@ -3,7 +3,7 @@ protected class C {
|
||||
}
|
||||
|
||||
//// [Protected1.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
|
||||
@@ -4,7 +4,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [Protected3.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
return C;
|
||||
|
||||
@@ -4,7 +4,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [Protected4.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.m = function () { };
|
||||
|
||||
@@ -4,7 +4,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [Protected5.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
C.m = function () { };
|
||||
|
||||
@@ -4,7 +4,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [Protected6.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
C.m = function () { };
|
||||
|
||||
@@ -4,7 +4,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [Protected7.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C() {
|
||||
}
|
||||
C.prototype.m = function () { };
|
||||
|
||||
@@ -4,7 +4,7 @@ class C {
|
||||
}
|
||||
|
||||
//// [Protected9.js]
|
||||
var C = (function () {
|
||||
var C = /** @class */ (function () {
|
||||
function C(p) {
|
||||
this.p = p;
|
||||
}
|
||||
|
||||
+4
-4
@@ -43,7 +43,7 @@ var l: X.Y.Z.Line;
|
||||
//// [TwoInternalModulesThatMergeEachWithExportedAndNonExportedClassesOfTheSameName.js]
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point() {
|
||||
}
|
||||
return Point;
|
||||
@@ -51,7 +51,7 @@ var A;
|
||||
A.Point = Point;
|
||||
})(A || (A = {}));
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point() {
|
||||
}
|
||||
Point.prototype.fromCarthesian = function (p) {
|
||||
@@ -69,7 +69,7 @@ var X;
|
||||
(function (Y) {
|
||||
var Z;
|
||||
(function (Z) {
|
||||
var Line = (function () {
|
||||
var Line = /** @class */ (function () {
|
||||
function Line() {
|
||||
}
|
||||
return Line;
|
||||
@@ -83,7 +83,7 @@ var X;
|
||||
(function (Y) {
|
||||
var Z;
|
||||
(function (Z) {
|
||||
var Line = (function () {
|
||||
var Line = /** @class */ (function () {
|
||||
function Line() {
|
||||
}
|
||||
return Line;
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ var A;
|
||||
var Origin = "0,0";
|
||||
var Utils;
|
||||
(function (Utils) {
|
||||
var Plane = (function () {
|
||||
var Plane = /** @class */ (function () {
|
||||
function Plane(tl, br) {
|
||||
this.tl = tl;
|
||||
this.br = br;
|
||||
|
||||
+4
-4
@@ -35,7 +35,7 @@ module X {
|
||||
//// [TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.js]
|
||||
var A;
|
||||
(function (A) {
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point() {
|
||||
}
|
||||
return Point;
|
||||
@@ -44,7 +44,7 @@ var A;
|
||||
})(A || (A = {}));
|
||||
(function (A) {
|
||||
// expected error
|
||||
var Point = (function () {
|
||||
var Point = /** @class */ (function () {
|
||||
function Point() {
|
||||
}
|
||||
return Point;
|
||||
@@ -57,7 +57,7 @@ var X;
|
||||
(function (Y) {
|
||||
var Z;
|
||||
(function (Z) {
|
||||
var Line = (function () {
|
||||
var Line = /** @class */ (function () {
|
||||
function Line() {
|
||||
}
|
||||
return Line;
|
||||
@@ -72,7 +72,7 @@ var X;
|
||||
var Z;
|
||||
(function (Z) {
|
||||
// expected error
|
||||
var Line = (function () {
|
||||
var Line = /** @class */ (function () {
|
||||
function Line() {
|
||||
}
|
||||
return Line;
|
||||
|
||||
+1
-1
@@ -52,7 +52,7 @@ var A;
|
||||
A.Origin = { x: 0, y: 0 };
|
||||
var Utils;
|
||||
(function (Utils) {
|
||||
var Plane = (function () {
|
||||
var Plane = /** @class */ (function () {
|
||||
function Plane(tl, br) {
|
||||
this.tl = tl;
|
||||
this.br = br;
|
||||
|
||||
+2
-2
@@ -55,7 +55,7 @@ var X;
|
||||
(function (Y) {
|
||||
var Z;
|
||||
(function (Z) {
|
||||
var Line = (function () {
|
||||
var Line = /** @class */ (function () {
|
||||
function Line() {
|
||||
}
|
||||
return Line;
|
||||
@@ -69,7 +69,7 @@ var X;
|
||||
(function (Y) {
|
||||
var Z;
|
||||
(function (Z) {
|
||||
var Line = (function () {
|
||||
var Line = /** @class */ (function () {
|
||||
function Line() {
|
||||
}
|
||||
return Line;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user