From 501bfb53260a265f12b684fc36f2855587981b6a Mon Sep 17 00:00:00 2001 From: Mohamed Hegazy Date: Tue, 29 Nov 2016 17:15:17 -0800 Subject: [PATCH] Update LKG --- lib/lib.es2017.object.d.ts | 13 +++++- lib/protocol.d.ts | 28 ++++++++++++ lib/tsc.js | 21 ++++++--- lib/tsserver.js | 58 +++++++++++++++++++------ lib/tsserverlibrary.d.ts | 28 +++++++++++- lib/tsserverlibrary.js | 24 ++++++++--- lib/typescript.js | 29 +++++++++---- lib/typescriptServices.js | 29 +++++++++---- lib/typingsInstaller.js | 88 +++++++++++++++++++++----------------- 9 files changed, 236 insertions(+), 82 deletions(-) diff --git a/lib/lib.es2017.object.d.ts b/lib/lib.es2017.object.d.ts index dc3806835ef..695d8dcb4aa 100644 --- a/lib/lib.es2017.object.d.ts +++ b/lib/lib.es2017.object.d.ts @@ -24,11 +24,22 @@ interface ObjectConstructor { * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. */ values(o: { [s: string]: T }): T[]; + + /** + * Returns an array of values of the enumerable properties of an object + * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. + */ values(o: any): any[]; + + /** + * Returns an array of key/values of the enumerable properties of an object + * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. + */ + entries(o: { [s: string]: T }): [string, T][]; + /** * Returns an array of key/values of the enumerable properties of an object * @param o Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object. */ - entries(o: T): [keyof T, T[K]][]; entries(o: any): [string, any][]; } diff --git a/lib/protocol.d.ts b/lib/protocol.d.ts index c2577c2478a..63d79603503 100644 --- a/lib/protocol.d.ts +++ b/lib/protocol.d.ts @@ -1662,6 +1662,34 @@ declare namespace ts.server.protocol { */ typingsInstallerVersion: string; } + type BeginInstallTypesEventName = "beginInstallTypes"; + type EndInstallTypesEventName = "endInstallTypes"; + interface BeginInstallTypesEvent extends Event { + event: BeginInstallTypesEventName; + body: BeginInstallTypesEventBody; + } + interface EndInstallTypesEvent extends Event { + event: EndInstallTypesEventName; + body: EndInstallTypesEventBody; + } + interface InstallTypesEventBody { + /** + * correlation id to match begin and end events + */ + eventId: number; + /** + * list of packages to install + */ + packages: ReadonlyArray; + } + interface BeginInstallTypesEventBody extends InstallTypesEventBody { + } + interface EndInstallTypesEventBody extends InstallTypesEventBody { + /** + * true if installation succeeded, otherwise false + */ + success: boolean; + } interface NavBarResponse extends Response { body?: NavigationBarItem[]; } diff --git a/lib/tsc.js b/lib/tsc.js index 0e833de2c10..94ec709879f 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -2624,6 +2624,7 @@ var ts; Global_module_exports_may_only_appear_in_declaration_files: { code: 1315, category: ts.DiagnosticCategory.Error, key: "Global_module_exports_may_only_appear_in_declaration_files_1315", message: "Global module exports may only appear in declaration files." }, Global_module_exports_may_only_appear_at_top_level: { code: 1316, category: ts.DiagnosticCategory.Error, key: "Global_module_exports_may_only_appear_at_top_level_1316", message: "Global module exports may only appear at top level." }, A_parameter_property_cannot_be_declared_using_a_rest_parameter: { code: 1317, category: ts.DiagnosticCategory.Error, key: "A_parameter_property_cannot_be_declared_using_a_rest_parameter_1317", message: "A parameter property cannot be declared using a rest parameter." }, + An_abstract_accessor_cannot_have_an_implementation: { code: 1318, category: ts.DiagnosticCategory.Error, key: "An_abstract_accessor_cannot_have_an_implementation_1318", message: "An abstract accessor cannot have an implementation." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate_identifier_0_2300", message: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.DiagnosticCategory.Error, key: "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", message: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static_members_cannot_reference_class_type_parameters_2302", message: "Static members cannot reference class type parameters." }, @@ -23058,24 +23059,27 @@ var ts; setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined, undefined); var typeParameter = getTypeParameterFromMappedType(type); var constraintType = getConstraintTypeFromMappedType(type); + var isomorphicType = getIsomorphicTypeFromMappedType(type); var templateType = getTemplateTypeFromMappedType(type); - var isReadonly = !!type.declaration.readonlyToken; - var isOptional = !!type.declaration.questionToken; + var templateReadonly = !!type.declaration.readonlyToken; + var templateOptional = !!type.declaration.questionToken; var keyType = constraintType.flags & 16384 ? getApparentType(constraintType) : constraintType; var iterationType = keyType.flags & 262144 ? getIndexType(getApparentType(keyType.type)) : keyType; forEachType(iterationType, function (t) { var iterationMapper = createUnaryTypeMapper(typeParameter, t); var templateMapper = type.mapper ? combineTypeMappers(type.mapper, iterationMapper) : iterationMapper; var propType = instantiateType(templateType, templateMapper); - if (t.flags & (32 | 64 | 256)) { + if (t.flags & 32) { var propName = t.text; + var isomorphicProp = isomorphicType && getPropertyOfType(isomorphicType, propName); + var isOptional = templateOptional || !!(isomorphicProp && isomorphicProp.flags & 536870912); var prop = createSymbol(4 | 67108864 | (isOptional ? 536870912 : 0), propName); prop.type = addOptionality(propType, isOptional); - prop.isReadonly = isReadonly; + prop.isReadonly = templateReadonly || isomorphicProp && isReadonlySymbol(isomorphicProp); members[propName] = prop; } else if (t.flags & 2) { - stringIndexInfo = createIndexInfo(propType, isReadonly); + stringIndexInfo = createIndexInfo(propType, templateReadonly); } }); setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, undefined); @@ -23094,6 +23098,10 @@ var ts; instantiateType(getTypeFromTypeNode(type.declaration.type), type.mapper || identityMapper) : unknownType); } + function getIsomorphicTypeFromMappedType(type) { + var constraint = getConstraintDeclaration(getTypeParameterFromMappedType(type)); + return constraint.kind === 168 ? instantiateType(getTypeFromTypeNode(constraint.type), type.mapper || identityMapper) : undefined; + } function getErasedTemplateTypeFromMappedType(type) { return instantiateType(getTemplateTypeFromMappedType(type), createUnaryTypeMapper(getTypeParameterFromMappedType(type), anyType)); } @@ -35913,6 +35921,9 @@ var ts; else if (accessor.body === undefined && !(ts.getModifierFlags(accessor) & 128)) { return grammarErrorAtPos(ts.getSourceFileOfNode(accessor), accessor.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); } + else if (accessor.body && ts.getModifierFlags(accessor) & 128) { + return grammarErrorOnNode(accessor, ts.Diagnostics.An_abstract_accessor_cannot_have_an_implementation); + } else if (accessor.typeParameters) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters); } diff --git a/lib/tsserver.js b/lib/tsserver.js index 2daeee180fe..7450ef5ab69 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -2629,6 +2629,7 @@ var ts; Global_module_exports_may_only_appear_in_declaration_files: { code: 1315, category: ts.DiagnosticCategory.Error, key: "Global_module_exports_may_only_appear_in_declaration_files_1315", message: "Global module exports may only appear in declaration files." }, Global_module_exports_may_only_appear_at_top_level: { code: 1316, category: ts.DiagnosticCategory.Error, key: "Global_module_exports_may_only_appear_at_top_level_1316", message: "Global module exports may only appear at top level." }, A_parameter_property_cannot_be_declared_using_a_rest_parameter: { code: 1317, category: ts.DiagnosticCategory.Error, key: "A_parameter_property_cannot_be_declared_using_a_rest_parameter_1317", message: "A parameter property cannot be declared using a rest parameter." }, + An_abstract_accessor_cannot_have_an_implementation: { code: 1318, category: ts.DiagnosticCategory.Error, key: "An_abstract_accessor_cannot_have_an_implementation_1318", message: "An abstract accessor cannot have an implementation." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate_identifier_0_2300", message: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.DiagnosticCategory.Error, key: "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", message: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static_members_cannot_reference_class_type_parameters_2302", message: "Static members cannot reference class type parameters." }, @@ -6069,7 +6070,8 @@ var ts; (function (server) { server.ActionSet = "action::set"; server.ActionInvalidate = "action::invalidate"; - server.EventInstall = "event::install"; + server.EventBeginInstallTypes = "event::beginInstallTypes"; + server.EventEndInstallTypes = "event::endInstallTypes"; var Arguments; (function (Arguments) { Arguments.GlobalCacheLocation = "--globalTypingsCacheLocation"; @@ -24571,24 +24573,27 @@ var ts; setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined, undefined); var typeParameter = getTypeParameterFromMappedType(type); var constraintType = getConstraintTypeFromMappedType(type); + var isomorphicType = getIsomorphicTypeFromMappedType(type); var templateType = getTemplateTypeFromMappedType(type); - var isReadonly = !!type.declaration.readonlyToken; - var isOptional = !!type.declaration.questionToken; + var templateReadonly = !!type.declaration.readonlyToken; + var templateOptional = !!type.declaration.questionToken; var keyType = constraintType.flags & 16384 ? getApparentType(constraintType) : constraintType; var iterationType = keyType.flags & 262144 ? getIndexType(getApparentType(keyType.type)) : keyType; forEachType(iterationType, function (t) { var iterationMapper = createUnaryTypeMapper(typeParameter, t); var templateMapper = type.mapper ? combineTypeMappers(type.mapper, iterationMapper) : iterationMapper; var propType = instantiateType(templateType, templateMapper); - if (t.flags & (32 | 64 | 256)) { + if (t.flags & 32) { var propName = t.text; + var isomorphicProp = isomorphicType && getPropertyOfType(isomorphicType, propName); + var isOptional = templateOptional || !!(isomorphicProp && isomorphicProp.flags & 536870912); var prop = createSymbol(4 | 67108864 | (isOptional ? 536870912 : 0), propName); prop.type = addOptionality(propType, isOptional); - prop.isReadonly = isReadonly; + prop.isReadonly = templateReadonly || isomorphicProp && isReadonlySymbol(isomorphicProp); members[propName] = prop; } else if (t.flags & 2) { - stringIndexInfo = createIndexInfo(propType, isReadonly); + stringIndexInfo = createIndexInfo(propType, templateReadonly); } }); setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, undefined); @@ -24607,6 +24612,10 @@ var ts; instantiateType(getTypeFromTypeNode(type.declaration.type), type.mapper || identityMapper) : unknownType); } + function getIsomorphicTypeFromMappedType(type) { + var constraint = getConstraintDeclaration(getTypeParameterFromMappedType(type)); + return constraint.kind === 168 ? instantiateType(getTypeFromTypeNode(constraint.type), type.mapper || identityMapper) : undefined; + } function getErasedTemplateTypeFromMappedType(type) { return instantiateType(getTemplateTypeFromMappedType(type), createUnaryTypeMapper(getTypeParameterFromMappedType(type), anyType)); } @@ -37426,6 +37435,9 @@ var ts; else if (accessor.body === undefined && !(ts.getModifierFlags(accessor) & 128)) { return grammarErrorAtPos(ts.getSourceFileOfNode(accessor), accessor.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); } + else if (accessor.body && ts.getModifierFlags(accessor) & 128) { + return grammarErrorOnNode(accessor, ts.Diagnostics.An_abstract_accessor_cannot_have_an_implementation); + } else if (accessor.typeParameters) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters); } @@ -69090,7 +69102,7 @@ var ts; this.socket.write(server.formatMessage({ seq: seq, type: "event", event: event, body: body }, this.logger, Buffer.byteLength, this.newLine), "utf8"); }; NodeTypingsInstaller.prototype.setTelemetrySender = function (telemetrySender) { - this.telemetrySender = telemetrySender; + this.eventSender = telemetrySender; }; NodeTypingsInstaller.prototype.attach = function (projectService) { var _this = this; @@ -69148,9 +69160,24 @@ var ts; if (this.logger.hasLevel(server.LogLevel.verbose)) { this.logger.info("Received response: " + JSON.stringify(response)); } - if (response.kind === server.EventInstall) { - if (this.telemetrySender) { - var body = { + if (response.kind === server.EventBeginInstallTypes) { + if (!this.eventSender) { + return; + } + var body = { + eventId: response.eventId, + packages: response.packagesToInstall, + }; + var eventName = "beginInstallTypes"; + this.eventSender.event(body, eventName); + return; + } + if (response.kind === server.EventEndInstallTypes) { + if (!this.eventSender) { + return; + } + if (this.telemetryEnabled) { + var body_1 = { telemetryEventName: "typingsInstalled", payload: { installedPackages: response.packagesToInstall.join(","), @@ -69158,9 +69185,16 @@ var ts; typingsInstallerVersion: response.typingsInstallerVersion } }; - var eventName = "telemetry"; - this.telemetrySender.event(body, eventName); + var eventName_1 = "telemetry"; + this.eventSender.event(body_1, eventName_1); } + var body = { + eventId: response.eventId, + packages: response.packagesToInstall, + success: response.installSuccess, + }; + var eventName = "endInstallTypes"; + this.eventSender.event(body, eventName); return; } this.projectService.updateTypingsForProject(response); diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts index 6f19be9a51c..a93576fd993 100644 --- a/lib/tsserverlibrary.d.ts +++ b/lib/tsserverlibrary.d.ts @@ -718,6 +718,25 @@ declare namespace ts.server.protocol { installSuccess: boolean; typingsInstallerVersion: string; } + type BeginInstallTypesEventName = "beginInstallTypes"; + type EndInstallTypesEventName = "endInstallTypes"; + interface BeginInstallTypesEvent extends Event { + event: BeginInstallTypesEventName; + body: BeginInstallTypesEventBody; + } + interface EndInstallTypesEvent extends Event { + event: EndInstallTypesEventName; + body: EndInstallTypesEventBody; + } + interface InstallTypesEventBody { + eventId: number; + packages: ReadonlyArray; + } + interface BeginInstallTypesEventBody extends InstallTypesEventBody { + } + interface EndInstallTypesEventBody extends InstallTypesEventBody { + success: boolean; + } interface NavBarResponse extends Response { body?: NavigationBarItem[]; } @@ -5075,6 +5094,12 @@ declare namespace ts { key: string; message: string; }; + An_abstract_accessor_cannot_have_an_implementation: { + code: number; + category: DiagnosticCategory; + key: string; + message: string; + }; Duplicate_identifier_0: { code: number; category: DiagnosticCategory; @@ -8731,7 +8756,8 @@ declare namespace ts.JsTyping { declare namespace ts.server { const ActionSet: ActionSet; const ActionInvalidate: ActionInvalidate; - const EventInstall: EventInstall; + const EventBeginInstallTypes: EventBeginInstallTypes; + const EventEndInstallTypes: EventEndInstallTypes; namespace Arguments { const GlobalCacheLocation = "--globalTypingsCacheLocation"; const LogFile = "--logFile"; diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index 5101a2c2770..af13c561eeb 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -2629,6 +2629,7 @@ var ts; Global_module_exports_may_only_appear_in_declaration_files: { code: 1315, category: ts.DiagnosticCategory.Error, key: "Global_module_exports_may_only_appear_in_declaration_files_1315", message: "Global module exports may only appear in declaration files." }, Global_module_exports_may_only_appear_at_top_level: { code: 1316, category: ts.DiagnosticCategory.Error, key: "Global_module_exports_may_only_appear_at_top_level_1316", message: "Global module exports may only appear at top level." }, A_parameter_property_cannot_be_declared_using_a_rest_parameter: { code: 1317, category: ts.DiagnosticCategory.Error, key: "A_parameter_property_cannot_be_declared_using_a_rest_parameter_1317", message: "A parameter property cannot be declared using a rest parameter." }, + An_abstract_accessor_cannot_have_an_implementation: { code: 1318, category: ts.DiagnosticCategory.Error, key: "An_abstract_accessor_cannot_have_an_implementation_1318", message: "An abstract accessor cannot have an implementation." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate_identifier_0_2300", message: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.DiagnosticCategory.Error, key: "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", message: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static_members_cannot_reference_class_type_parameters_2302", message: "Static members cannot reference class type parameters." }, @@ -6069,7 +6070,8 @@ var ts; (function (server) { server.ActionSet = "action::set"; server.ActionInvalidate = "action::invalidate"; - server.EventInstall = "event::install"; + server.EventBeginInstallTypes = "event::beginInstallTypes"; + server.EventEndInstallTypes = "event::endInstallTypes"; var Arguments; (function (Arguments) { Arguments.GlobalCacheLocation = "--globalTypingsCacheLocation"; @@ -24571,24 +24573,27 @@ var ts; setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined, undefined); var typeParameter = getTypeParameterFromMappedType(type); var constraintType = getConstraintTypeFromMappedType(type); + var isomorphicType = getIsomorphicTypeFromMappedType(type); var templateType = getTemplateTypeFromMappedType(type); - var isReadonly = !!type.declaration.readonlyToken; - var isOptional = !!type.declaration.questionToken; + var templateReadonly = !!type.declaration.readonlyToken; + var templateOptional = !!type.declaration.questionToken; var keyType = constraintType.flags & 16384 ? getApparentType(constraintType) : constraintType; var iterationType = keyType.flags & 262144 ? getIndexType(getApparentType(keyType.type)) : keyType; forEachType(iterationType, function (t) { var iterationMapper = createUnaryTypeMapper(typeParameter, t); var templateMapper = type.mapper ? combineTypeMappers(type.mapper, iterationMapper) : iterationMapper; var propType = instantiateType(templateType, templateMapper); - if (t.flags & (32 | 64 | 256)) { + if (t.flags & 32) { var propName = t.text; + var isomorphicProp = isomorphicType && getPropertyOfType(isomorphicType, propName); + var isOptional = templateOptional || !!(isomorphicProp && isomorphicProp.flags & 536870912); var prop = createSymbol(4 | 67108864 | (isOptional ? 536870912 : 0), propName); prop.type = addOptionality(propType, isOptional); - prop.isReadonly = isReadonly; + prop.isReadonly = templateReadonly || isomorphicProp && isReadonlySymbol(isomorphicProp); members[propName] = prop; } else if (t.flags & 2) { - stringIndexInfo = createIndexInfo(propType, isReadonly); + stringIndexInfo = createIndexInfo(propType, templateReadonly); } }); setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, undefined); @@ -24607,6 +24612,10 @@ var ts; instantiateType(getTypeFromTypeNode(type.declaration.type), type.mapper || identityMapper) : unknownType); } + function getIsomorphicTypeFromMappedType(type) { + var constraint = getConstraintDeclaration(getTypeParameterFromMappedType(type)); + return constraint.kind === 168 ? instantiateType(getTypeFromTypeNode(constraint.type), type.mapper || identityMapper) : undefined; + } function getErasedTemplateTypeFromMappedType(type) { return instantiateType(getTemplateTypeFromMappedType(type), createUnaryTypeMapper(getTypeParameterFromMappedType(type), anyType)); } @@ -37426,6 +37435,9 @@ var ts; else if (accessor.body === undefined && !(ts.getModifierFlags(accessor) & 128)) { return grammarErrorAtPos(ts.getSourceFileOfNode(accessor), accessor.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); } + else if (accessor.body && ts.getModifierFlags(accessor) & 128) { + return grammarErrorOnNode(accessor, ts.Diagnostics.An_abstract_accessor_cannot_have_an_implementation); + } else if (accessor.typeParameters) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters); } diff --git a/lib/typescript.js b/lib/typescript.js index 4436b3436c9..29a7baad1a1 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -4066,6 +4066,7 @@ var ts; Global_module_exports_may_only_appear_in_declaration_files: { code: 1315, category: ts.DiagnosticCategory.Error, key: "Global_module_exports_may_only_appear_in_declaration_files_1315", message: "Global module exports may only appear in declaration files." }, Global_module_exports_may_only_appear_at_top_level: { code: 1316, category: ts.DiagnosticCategory.Error, key: "Global_module_exports_may_only_appear_at_top_level_1316", message: "Global module exports may only appear at top level." }, A_parameter_property_cannot_be_declared_using_a_rest_parameter: { code: 1317, category: ts.DiagnosticCategory.Error, key: "A_parameter_property_cannot_be_declared_using_a_rest_parameter_1317", message: "A parameter property cannot be declared using a rest parameter." }, + An_abstract_accessor_cannot_have_an_implementation: { code: 1318, category: ts.DiagnosticCategory.Error, key: "An_abstract_accessor_cannot_have_an_implementation_1318", message: "An abstract accessor cannot have an implementation." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate_identifier_0_2300", message: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.DiagnosticCategory.Error, key: "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", message: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static_members_cannot_reference_class_type_parameters_2302", message: "Static members cannot reference class type parameters." }, @@ -28224,12 +28225,14 @@ var ts; // Resolve upfront such that recursive references see an empty object type. setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined, undefined); // In { [P in K]: T }, we refer to P as the type parameter type, K as the constraint type, - // and T as the template type. + // and T as the template type. If K is of the form 'keyof S', the mapped type and S are + // isomorphic and we copy property modifiers from corresponding properties in S. var typeParameter = getTypeParameterFromMappedType(type); var constraintType = getConstraintTypeFromMappedType(type); + var isomorphicType = getIsomorphicTypeFromMappedType(type); var templateType = getTemplateTypeFromMappedType(type); - var isReadonly = !!type.declaration.readonlyToken; - var isOptional = !!type.declaration.questionToken; + var templateReadonly = !!type.declaration.readonlyToken; + var templateOptional = !!type.declaration.questionToken; // First, if the constraint type is a type parameter, obtain the base constraint. Then, // if the key type is a 'keyof X', obtain 'keyof C' where C is the base constraint of X. // Finally, iterate over the constituents of the resulting iteration type. @@ -28242,18 +28245,19 @@ var ts; var iterationMapper = createUnaryTypeMapper(typeParameter, t); var templateMapper = type.mapper ? combineTypeMappers(type.mapper, iterationMapper) : iterationMapper; var propType = instantiateType(templateType, templateMapper); - // If the current iteration type constituent is a literal type, create a property. - // Otherwise, for type string create a string index signature and for type number - // create a numeric index signature. - if (t.flags & (32 /* StringLiteral */ | 64 /* NumberLiteral */ | 256 /* EnumLiteral */)) { + // If the current iteration type constituent is a string literal type, create a property. + // Otherwise, for type string create a string index signature. + if (t.flags & 32 /* StringLiteral */) { var propName = t.text; + var isomorphicProp = isomorphicType && getPropertyOfType(isomorphicType, propName); + var isOptional = templateOptional || !!(isomorphicProp && isomorphicProp.flags & 536870912 /* Optional */); var prop = createSymbol(4 /* Property */ | 67108864 /* Transient */ | (isOptional ? 536870912 /* Optional */ : 0), propName); prop.type = addOptionality(propType, isOptional); - prop.isReadonly = isReadonly; + prop.isReadonly = templateReadonly || isomorphicProp && isReadonlySymbol(isomorphicProp); members[propName] = prop; } else if (t.flags & 2 /* String */) { - stringIndexInfo = createIndexInfo(propType, isReadonly); + stringIndexInfo = createIndexInfo(propType, templateReadonly); } }); setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, undefined); @@ -28272,6 +28276,10 @@ var ts; instantiateType(getTypeFromTypeNode(type.declaration.type), type.mapper || identityMapper) : unknownType); } + function getIsomorphicTypeFromMappedType(type) { + var constraint = getConstraintDeclaration(getTypeParameterFromMappedType(type)); + return constraint.kind === 168 /* TypeOperator */ ? instantiateType(getTypeFromTypeNode(constraint.type), type.mapper || identityMapper) : undefined; + } function getErasedTemplateTypeFromMappedType(type) { return instantiateType(getTemplateTypeFromMappedType(type), createUnaryTypeMapper(getTypeParameterFromMappedType(type), anyType)); } @@ -43412,6 +43420,9 @@ var ts; else if (accessor.body === undefined && !(ts.getModifierFlags(accessor) & 128 /* Abstract */)) { return grammarErrorAtPos(ts.getSourceFileOfNode(accessor), accessor.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); } + else if (accessor.body && ts.getModifierFlags(accessor) & 128 /* Abstract */) { + return grammarErrorOnNode(accessor, ts.Diagnostics.An_abstract_accessor_cannot_have_an_implementation); + } else if (accessor.typeParameters) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters); } diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 4436b3436c9..29a7baad1a1 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -4066,6 +4066,7 @@ var ts; Global_module_exports_may_only_appear_in_declaration_files: { code: 1315, category: ts.DiagnosticCategory.Error, key: "Global_module_exports_may_only_appear_in_declaration_files_1315", message: "Global module exports may only appear in declaration files." }, Global_module_exports_may_only_appear_at_top_level: { code: 1316, category: ts.DiagnosticCategory.Error, key: "Global_module_exports_may_only_appear_at_top_level_1316", message: "Global module exports may only appear at top level." }, A_parameter_property_cannot_be_declared_using_a_rest_parameter: { code: 1317, category: ts.DiagnosticCategory.Error, key: "A_parameter_property_cannot_be_declared_using_a_rest_parameter_1317", message: "A parameter property cannot be declared using a rest parameter." }, + An_abstract_accessor_cannot_have_an_implementation: { code: 1318, category: ts.DiagnosticCategory.Error, key: "An_abstract_accessor_cannot_have_an_implementation_1318", message: "An abstract accessor cannot have an implementation." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate_identifier_0_2300", message: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.DiagnosticCategory.Error, key: "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", message: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static_members_cannot_reference_class_type_parameters_2302", message: "Static members cannot reference class type parameters." }, @@ -28224,12 +28225,14 @@ var ts; // Resolve upfront such that recursive references see an empty object type. setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined, undefined); // In { [P in K]: T }, we refer to P as the type parameter type, K as the constraint type, - // and T as the template type. + // and T as the template type. If K is of the form 'keyof S', the mapped type and S are + // isomorphic and we copy property modifiers from corresponding properties in S. var typeParameter = getTypeParameterFromMappedType(type); var constraintType = getConstraintTypeFromMappedType(type); + var isomorphicType = getIsomorphicTypeFromMappedType(type); var templateType = getTemplateTypeFromMappedType(type); - var isReadonly = !!type.declaration.readonlyToken; - var isOptional = !!type.declaration.questionToken; + var templateReadonly = !!type.declaration.readonlyToken; + var templateOptional = !!type.declaration.questionToken; // First, if the constraint type is a type parameter, obtain the base constraint. Then, // if the key type is a 'keyof X', obtain 'keyof C' where C is the base constraint of X. // Finally, iterate over the constituents of the resulting iteration type. @@ -28242,18 +28245,19 @@ var ts; var iterationMapper = createUnaryTypeMapper(typeParameter, t); var templateMapper = type.mapper ? combineTypeMappers(type.mapper, iterationMapper) : iterationMapper; var propType = instantiateType(templateType, templateMapper); - // If the current iteration type constituent is a literal type, create a property. - // Otherwise, for type string create a string index signature and for type number - // create a numeric index signature. - if (t.flags & (32 /* StringLiteral */ | 64 /* NumberLiteral */ | 256 /* EnumLiteral */)) { + // If the current iteration type constituent is a string literal type, create a property. + // Otherwise, for type string create a string index signature. + if (t.flags & 32 /* StringLiteral */) { var propName = t.text; + var isomorphicProp = isomorphicType && getPropertyOfType(isomorphicType, propName); + var isOptional = templateOptional || !!(isomorphicProp && isomorphicProp.flags & 536870912 /* Optional */); var prop = createSymbol(4 /* Property */ | 67108864 /* Transient */ | (isOptional ? 536870912 /* Optional */ : 0), propName); prop.type = addOptionality(propType, isOptional); - prop.isReadonly = isReadonly; + prop.isReadonly = templateReadonly || isomorphicProp && isReadonlySymbol(isomorphicProp); members[propName] = prop; } else if (t.flags & 2 /* String */) { - stringIndexInfo = createIndexInfo(propType, isReadonly); + stringIndexInfo = createIndexInfo(propType, templateReadonly); } }); setStructuredTypeMembers(type, members, emptyArray, emptyArray, stringIndexInfo, undefined); @@ -28272,6 +28276,10 @@ var ts; instantiateType(getTypeFromTypeNode(type.declaration.type), type.mapper || identityMapper) : unknownType); } + function getIsomorphicTypeFromMappedType(type) { + var constraint = getConstraintDeclaration(getTypeParameterFromMappedType(type)); + return constraint.kind === 168 /* TypeOperator */ ? instantiateType(getTypeFromTypeNode(constraint.type), type.mapper || identityMapper) : undefined; + } function getErasedTemplateTypeFromMappedType(type) { return instantiateType(getTemplateTypeFromMappedType(type), createUnaryTypeMapper(getTypeParameterFromMappedType(type), anyType)); } @@ -43412,6 +43420,9 @@ var ts; else if (accessor.body === undefined && !(ts.getModifierFlags(accessor) & 128 /* Abstract */)) { return grammarErrorAtPos(ts.getSourceFileOfNode(accessor), accessor.end - 1, ";".length, ts.Diagnostics._0_expected, "{"); } + else if (accessor.body && ts.getModifierFlags(accessor) & 128 /* Abstract */) { + return grammarErrorOnNode(accessor, ts.Diagnostics.An_abstract_accessor_cannot_have_an_implementation); + } else if (accessor.typeParameters) { return grammarErrorOnNode(accessor.name, ts.Diagnostics.An_accessor_cannot_have_type_parameters); } diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index 21c0a8cfedb..1d9e78f7228 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -2629,6 +2629,7 @@ var ts; Global_module_exports_may_only_appear_in_declaration_files: { code: 1315, category: ts.DiagnosticCategory.Error, key: "Global_module_exports_may_only_appear_in_declaration_files_1315", message: "Global module exports may only appear in declaration files." }, Global_module_exports_may_only_appear_at_top_level: { code: 1316, category: ts.DiagnosticCategory.Error, key: "Global_module_exports_may_only_appear_at_top_level_1316", message: "Global module exports may only appear at top level." }, A_parameter_property_cannot_be_declared_using_a_rest_parameter: { code: 1317, category: ts.DiagnosticCategory.Error, key: "A_parameter_property_cannot_be_declared_using_a_rest_parameter_1317", message: "A parameter property cannot be declared using a rest parameter." }, + An_abstract_accessor_cannot_have_an_implementation: { code: 1318, category: ts.DiagnosticCategory.Error, key: "An_abstract_accessor_cannot_have_an_implementation_1318", message: "An abstract accessor cannot have an implementation." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "Duplicate_identifier_0_2300", message: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: ts.DiagnosticCategory.Error, key: "Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor_2301", message: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static_members_cannot_reference_class_type_parameters_2302", message: "Static members cannot reference class type parameters." }, @@ -6069,7 +6070,8 @@ var ts; (function (server) { server.ActionSet = "action::set"; server.ActionInvalidate = "action::invalidate"; - server.EventInstall = "event::install"; + server.EventBeginInstallTypes = "event::beginInstallTypes"; + server.EventEndInstallTypes = "event::endInstallTypes"; var Arguments; (function (Arguments) { Arguments.GlobalCacheLocation = "--globalTypingsCacheLocation"; @@ -6727,13 +6729,12 @@ var ts; } typingsInstaller.validatePackageName = validatePackageName; var TypingsInstaller = (function () { - function TypingsInstaller(installTypingHost, globalCachePath, safeListPath, throttleLimit, telemetryEnabled, log) { + function TypingsInstaller(installTypingHost, globalCachePath, safeListPath, throttleLimit, log) { if (log === void 0) { log = nullLog; } this.installTypingHost = installTypingHost; this.globalCachePath = globalCachePath; this.safeListPath = safeListPath; this.throttleLimit = throttleLimit; - this.telemetryEnabled = telemetryEnabled; this.log = log; this.packageNameToTypingLocation = ts.createMap(); this.missingTypingsSet = ts.createMap(); @@ -6924,45 +6925,55 @@ var ts; this.ensurePackageDirectoryExists(cachePath); var requestId = this.installRunCount; this.installRunCount++; + this.sendResponse({ + kind: server.EventBeginInstallTypes, + eventId: requestId, + typingsInstallerVersion: ts.version, + projectName: req.projectName + }); this.installTypingsAsync(requestId, scopedTypings, cachePath, function (ok) { - if (_this.telemetryEnabled) { + try { + if (!ok) { + if (_this.log.isEnabled()) { + _this.log.writeLine("install request failed, marking packages as missing to prevent repeated requests: " + JSON.stringify(filteredTypings)); + } + for (var _i = 0, filteredTypings_1 = filteredTypings; _i < filteredTypings_1.length; _i++) { + var typing = filteredTypings_1[_i]; + _this.missingTypingsSet[typing] = true; + } + return; + } + if (_this.log.isEnabled()) { + _this.log.writeLine("Installed typings " + JSON.stringify(scopedTypings)); + } + var installedTypingFiles = []; + for (var _a = 0, filteredTypings_2 = filteredTypings; _a < filteredTypings_2.length; _a++) { + var packageName = filteredTypings_2[_a]; + var typingFile = typingToFileName(cachePath, packageName, _this.installTypingHost, _this.log); + if (!typingFile) { + _this.missingTypingsSet[packageName] = true; + continue; + } + if (!_this.packageNameToTypingLocation[packageName]) { + _this.packageNameToTypingLocation[packageName] = typingFile; + } + installedTypingFiles.push(typingFile); + } + if (_this.log.isEnabled()) { + _this.log.writeLine("Installed typing files " + JSON.stringify(installedTypingFiles)); + } + _this.sendResponse(_this.createSetTypings(req, currentlyCachedTypings.concat(installedTypingFiles))); + } + finally { _this.sendResponse({ - kind: server.EventInstall, + kind: server.EventEndInstallTypes, + eventId: requestId, + projectName: req.projectName, packagesToInstall: scopedTypings, installSuccess: ok, typingsInstallerVersion: ts.version }); } - if (!ok) { - if (_this.log.isEnabled()) { - _this.log.writeLine("install request failed, marking packages as missing to prevent repeated requests: " + JSON.stringify(filteredTypings)); - } - for (var _i = 0, filteredTypings_1 = filteredTypings; _i < filteredTypings_1.length; _i++) { - var typing = filteredTypings_1[_i]; - _this.missingTypingsSet[typing] = true; - } - return; - } - if (_this.log.isEnabled()) { - _this.log.writeLine("Installed typings " + JSON.stringify(scopedTypings)); - } - var installedTypingFiles = []; - for (var _a = 0, filteredTypings_2 = filteredTypings; _a < filteredTypings_2.length; _a++) { - var packageName = filteredTypings_2[_a]; - var typingFile = typingToFileName(cachePath, packageName, _this.installTypingHost, _this.log); - if (!typingFile) { - _this.missingTypingsSet[packageName] = true; - continue; - } - if (!_this.packageNameToTypingLocation[packageName]) { - _this.packageNameToTypingLocation[packageName] = typingFile; - } - installedTypingFiles.push(typingFile); - } - if (_this.log.isEnabled()) { - _this.log.writeLine("Installed typing files " + JSON.stringify(installedTypingFiles)); - } - _this.sendResponse(_this.createSetTypings(req, currentlyCachedTypings.concat(installedTypingFiles))); }); }; TypingsInstaller.prototype.ensureDirectoryExists = function (directory, host) { @@ -7085,8 +7096,8 @@ var ts; } var NodeTypingsInstaller = (function (_super) { __extends(NodeTypingsInstaller, _super); - function NodeTypingsInstaller(globalTypingsCacheLocation, throttleLimit, telemetryEnabled, log) { - var _this = _super.call(this, ts.sys, globalTypingsCacheLocation, ts.toPath("typingSafeList.json", __dirname, ts.createGetCanonicalFileName(ts.sys.useCaseSensitiveFileNames)), throttleLimit, telemetryEnabled, log) || this; + function NodeTypingsInstaller(globalTypingsCacheLocation, throttleLimit, log) { + var _this = _super.call(this, ts.sys, globalTypingsCacheLocation, ts.toPath("typingSafeList.json", __dirname, ts.createGetCanonicalFileName(ts.sys.useCaseSensitiveFileNames)), throttleLimit, log) || this; if (_this.log.isEnabled()) { _this.log.writeLine("Process id: " + process.pid); } @@ -7155,7 +7166,6 @@ var ts; typingsInstaller.NodeTypingsInstaller = NodeTypingsInstaller; var logFilePath = server.findArgument(server.Arguments.LogFile); var globalTypingsCacheLocation = server.findArgument(server.Arguments.GlobalCacheLocation); - var telemetryEnabled = server.hasArgument(server.Arguments.EnableTelemetry); var log = new FileLog(logFilePath); if (log.isEnabled()) { process.on("uncaughtException", function (e) { @@ -7168,7 +7178,7 @@ var ts; } process.exit(0); }); - var installer = new NodeTypingsInstaller(globalTypingsCacheLocation, 5, telemetryEnabled, log); + var installer = new NodeTypingsInstaller(globalTypingsCacheLocation, 5, log); installer.listen(); })(typingsInstaller = server.typingsInstaller || (server.typingsInstaller = {})); })(server = ts.server || (ts.server = {}));