diff --git a/.gitattributes b/.gitattributes index 74f5f4a640..811a89b549 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ -*.js linguist-language=TypeScript \ No newline at end of file +*.js linguist-language=TypeScript +* -text diff --git a/.gitignore b/.gitignore index f487ea6dd2..3147b8e872 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ tests/services/baselines/local/* tests/baselines/prototyping/local/* tests/baselines/rwc/* tests/baselines/test262/* +tests/baselines/reference/projectOutput/* tests/baselines/local/projectOutput/* tests/services/baselines/prototyping/local/* tests/services/browser/typescriptServices.js @@ -46,4 +47,5 @@ scripts/*.js.map coverage/ internal/ **/.DS_Store -.settings/ +.settings/* +!.settings/tasks.json diff --git a/.settings/tasks.json b/.settings/tasks.json new file mode 100644 index 0000000000..e617f22837 --- /dev/null +++ b/.settings/tasks.json @@ -0,0 +1,23 @@ +// Available variables which can be used inside of strings. +// ${workspaceRoot}: the root folder of the team +// ${file}: the current opened file +// ${fileBasename}: the current opened file's basename +// ${fileDirname}: the current opened file's dirname +// ${fileExtname}: the current opened file's extension +// ${cwd}: the current working directory of the spawned process +{ + "version": "0.1.0", + "command": "jake", + "isShellCommand": true, + "showOutput": "silent", + "tasks": [ + { + "taskName": "local", + "isBuildCommand": true, + "showOutput": "silent", + "problemMatcher": [ + "$tsc" + ] + } + ] +} \ No newline at end of file diff --git a/Jakefile.js b/Jakefile.js index cb53b47950..afe0ffd3ce 100644 --- a/Jakefile.js +++ b/Jakefile.js @@ -123,6 +123,7 @@ var harnessSources = [ return path.join(harnessDirectory, f); }).concat([ "incrementalParser.ts", + "jsDocParsing.ts", "services/colorization.ts", "services/documentRegistry.ts", "services/preProcessFile.ts", diff --git a/README.md b/README.md index ac00ef085b..ee32547ca9 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,8 @@ [![Downloads](http://img.shields.io/npm/dm/TypeScript.svg)](https://npmjs.org/package/typescript) # TypeScript + +[![Join the chat at https://gitter.im/Microsoft/TypeScript](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/Microsoft/TypeScript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [TypeScript](http://www.typescriptlang.org/) is a language for application-scale JavaScript. TypeScript adds optional types, classes, and modules to JavaScript. TypeScript supports tools for large-scale JavaScript applications for any browser, for any host, on any OS. TypeScript compiles to readable, standards-based JavaScript. Try it out at the [playground](http://www.typescriptlang.org/Playground), and stay up to date via [our blog](http://blogs.msdn.com/typescript) and [twitter account](https://twitter.com/typescriptlang). @@ -29,7 +31,7 @@ There are many ways to [contribute](https://github.com/Microsoft/TypeScript/blob ## Building -In order to build the TypeScript compiler, ensure that you have [Git](http://git-scm.com/downloads) and [Node.js](http://nodejs.org/) installed. +In order to build the TypeScript compiler, ensure that you have [Git](http://git-scm.com/downloads) and [Node.js](http://nodejs.org/) installed. Note that you need to have autocrlf off as we track whitespace changes (`git config --global core.autocrlf false`). Clone a copy of the repo: diff --git a/bin/lib.core.es6.d.ts b/bin/lib.core.es6.d.ts index 86e2fa3ad7..1213967b97 100644 --- a/bin/lib.core.es6.d.ts +++ b/bin/lib.core.es6.d.ts @@ -1502,6 +1502,11 @@ interface Array { copyWithin(target: number, start: number, end?: number): T[]; } +interface IArguments { + /** Iterator */ + [Symbol.iterator](): IterableIterator; +} + interface ArrayConstructor { /** * Creates an array from an array-like object. @@ -1686,14 +1691,6 @@ interface GeneratorFunctionConstructor { } declare var GeneratorFunction: GeneratorFunctionConstructor; -interface Generator extends IterableIterator { - next(value?: any): IteratorResult; - throw(exception: any): IteratorResult; - return(value: T): IteratorResult; - [Symbol.iterator](): Generator; - [Symbol.toStringTag]: string; -} - interface Math { /** * Returns the number of leading zero bits in the 32-bit binary representation of a number. diff --git a/bin/lib.d.ts b/bin/lib.d.ts index e583f1ac78..7497c30616 100644 --- a/bin/lib.d.ts +++ b/bin/lib.d.ts @@ -3552,10 +3552,10 @@ declare module Intl { resolvedOptions(): ResolvedNumberFormatOptions; } var NumberFormat: { - new (locales?: string[], options?: NumberFormatOptions): Collator; - new (locale?: string, options?: NumberFormatOptions): Collator; - (locales?: string[], options?: NumberFormatOptions): Collator; - (locale?: string, options?: NumberFormatOptions): Collator; + new (locales?: string[], options?: NumberFormatOptions): NumberFormat; + new (locale?: string, options?: NumberFormatOptions): NumberFormat; + (locales?: string[], options?: NumberFormatOptions): NumberFormat; + (locale?: string, options?: NumberFormatOptions): NumberFormat; supportedLocalesOf(locales: string[], options?: NumberFormatOptions): string[]; supportedLocalesOf(locale: string, options?: NumberFormatOptions): string[]; } @@ -3597,10 +3597,10 @@ declare module Intl { resolvedOptions(): ResolvedDateTimeFormatOptions; } var DateTimeFormat: { - new (locales?: string[], options?: DateTimeFormatOptions): Collator; - new (locale?: string, options?: DateTimeFormatOptions): Collator; - (locales?: string[], options?: DateTimeFormatOptions): Collator; - (locale?: string, options?: DateTimeFormatOptions): Collator; + new (locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat; + new (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat; + (locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat; + (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat; supportedLocalesOf(locales: string[], options?: DateTimeFormatOptions): string[]; supportedLocalesOf(locale: string, options?: DateTimeFormatOptions): string[]; } diff --git a/bin/lib.dom.d.ts b/bin/lib.dom.d.ts index 142486a166..1df0e2f736 100644 --- a/bin/lib.dom.d.ts +++ b/bin/lib.dom.d.ts @@ -2382,10 +2382,10 @@ declare module Intl { resolvedOptions(): ResolvedNumberFormatOptions; } var NumberFormat: { - new (locales?: string[], options?: NumberFormatOptions): Collator; - new (locale?: string, options?: NumberFormatOptions): Collator; - (locales?: string[], options?: NumberFormatOptions): Collator; - (locale?: string, options?: NumberFormatOptions): Collator; + new (locales?: string[], options?: NumberFormatOptions): NumberFormat; + new (locale?: string, options?: NumberFormatOptions): NumberFormat; + (locales?: string[], options?: NumberFormatOptions): NumberFormat; + (locale?: string, options?: NumberFormatOptions): NumberFormat; supportedLocalesOf(locales: string[], options?: NumberFormatOptions): string[]; supportedLocalesOf(locale: string, options?: NumberFormatOptions): string[]; } @@ -2427,10 +2427,10 @@ declare module Intl { resolvedOptions(): ResolvedDateTimeFormatOptions; } var DateTimeFormat: { - new (locales?: string[], options?: DateTimeFormatOptions): Collator; - new (locale?: string, options?: DateTimeFormatOptions): Collator; - (locales?: string[], options?: DateTimeFormatOptions): Collator; - (locale?: string, options?: DateTimeFormatOptions): Collator; + new (locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat; + new (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat; + (locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat; + (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat; supportedLocalesOf(locales: string[], options?: DateTimeFormatOptions): string[]; supportedLocalesOf(locale: string, options?: DateTimeFormatOptions): string[]; } diff --git a/bin/lib.es6.d.ts b/bin/lib.es6.d.ts index d6ca724514..b91bd34cf5 100644 --- a/bin/lib.es6.d.ts +++ b/bin/lib.es6.d.ts @@ -1502,6 +1502,11 @@ interface Array { copyWithin(target: number, start: number, end?: number): T[]; } +interface IArguments { + /** Iterator */ + [Symbol.iterator](): IterableIterator; +} + interface ArrayConstructor { /** * Creates an array from an array-like object. @@ -1686,14 +1691,6 @@ interface GeneratorFunctionConstructor { } declare var GeneratorFunction: GeneratorFunctionConstructor; -interface Generator extends IterableIterator { - next(value?: any): IteratorResult; - throw(exception: any): IteratorResult; - return(value: T): IteratorResult; - [Symbol.iterator](): Generator; - [Symbol.toStringTag]: string; -} - interface Math { /** * Returns the number of leading zero bits in the 32-bit binary representation of a number. @@ -4933,10 +4930,10 @@ declare module Intl { resolvedOptions(): ResolvedNumberFormatOptions; } var NumberFormat: { - new (locales?: string[], options?: NumberFormatOptions): Collator; - new (locale?: string, options?: NumberFormatOptions): Collator; - (locales?: string[], options?: NumberFormatOptions): Collator; - (locale?: string, options?: NumberFormatOptions): Collator; + new (locales?: string[], options?: NumberFormatOptions): NumberFormat; + new (locale?: string, options?: NumberFormatOptions): NumberFormat; + (locales?: string[], options?: NumberFormatOptions): NumberFormat; + (locale?: string, options?: NumberFormatOptions): NumberFormat; supportedLocalesOf(locales: string[], options?: NumberFormatOptions): string[]; supportedLocalesOf(locale: string, options?: NumberFormatOptions): string[]; } @@ -4978,10 +4975,10 @@ declare module Intl { resolvedOptions(): ResolvedDateTimeFormatOptions; } var DateTimeFormat: { - new (locales?: string[], options?: DateTimeFormatOptions): Collator; - new (locale?: string, options?: DateTimeFormatOptions): Collator; - (locales?: string[], options?: DateTimeFormatOptions): Collator; - (locale?: string, options?: DateTimeFormatOptions): Collator; + new (locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat; + new (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat; + (locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat; + (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat; supportedLocalesOf(locales: string[], options?: DateTimeFormatOptions): string[]; supportedLocalesOf(locale: string, options?: DateTimeFormatOptions): string[]; } diff --git a/bin/lib.webworker.d.ts b/bin/lib.webworker.d.ts index 1704e07f75..79eac80a8f 100644 --- a/bin/lib.webworker.d.ts +++ b/bin/lib.webworker.d.ts @@ -2382,10 +2382,10 @@ declare module Intl { resolvedOptions(): ResolvedNumberFormatOptions; } var NumberFormat: { - new (locales?: string[], options?: NumberFormatOptions): Collator; - new (locale?: string, options?: NumberFormatOptions): Collator; - (locales?: string[], options?: NumberFormatOptions): Collator; - (locale?: string, options?: NumberFormatOptions): Collator; + new (locales?: string[], options?: NumberFormatOptions): NumberFormat; + new (locale?: string, options?: NumberFormatOptions): NumberFormat; + (locales?: string[], options?: NumberFormatOptions): NumberFormat; + (locale?: string, options?: NumberFormatOptions): NumberFormat; supportedLocalesOf(locales: string[], options?: NumberFormatOptions): string[]; supportedLocalesOf(locale: string, options?: NumberFormatOptions): string[]; } @@ -2427,10 +2427,10 @@ declare module Intl { resolvedOptions(): ResolvedDateTimeFormatOptions; } var DateTimeFormat: { - new (locales?: string[], options?: DateTimeFormatOptions): Collator; - new (locale?: string, options?: DateTimeFormatOptions): Collator; - (locales?: string[], options?: DateTimeFormatOptions): Collator; - (locale?: string, options?: DateTimeFormatOptions): Collator; + new (locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat; + new (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat; + (locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat; + (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat; supportedLocalesOf(locales: string[], options?: DateTimeFormatOptions): string[]; supportedLocalesOf(locale: string, options?: DateTimeFormatOptions): string[]; } diff --git a/bin/tsc.js b/bin/tsc.js index 47c6769ae8..ef13d5d9e3 100644 --- a/bin/tsc.js +++ b/bin/tsc.js @@ -145,6 +145,16 @@ var ts; } } ts.addRange = addRange; + function rangeEquals(array1, array2, pos, end) { + while (pos < end) { + if (array1[pos] !== array2[pos]) { + return false; + } + pos++; + } + return true; + } + ts.rangeEquals = rangeEquals; function lastOrUndefined(array) { if (array.length === 0) { return undefined; @@ -301,8 +311,10 @@ var ts; var end = start + length; Debug.assert(start >= 0, "start must be non-negative, is " + start); Debug.assert(length >= 0, "length must be non-negative, is " + length); - Debug.assert(start <= file.text.length, "start must be within the bounds of the file. " + start + " > " + file.text.length); - Debug.assert(end <= file.text.length, "end must be the bounds of the file. " + end + " > " + file.text.length); + if (file) { + Debug.assert(start <= file.text.length, "start must be within the bounds of the file. " + start + " > " + file.text.length); + Debug.assert(end <= file.text.length, "end must be the bounds of the file. " + end + " > " + file.text.length); + } var text = getLocaleSpecificMessage(message.key); if (arguments.length > 4) { text = formatStringFromArgs(text, arguments, 4); @@ -837,7 +849,7 @@ var ts; for (var _i = 0; _i < files.length; _i++) { var current = files[_i]; var name = ts.combinePaths(path, current); - var stat = _fs.lstatSync(name); + var stat = _fs.statSync(name); if (stat.isFile()) { if (!extension || ts.fileExtensionIs(name, extension)) { result.push(name); @@ -1039,7 +1051,7 @@ var ts; Unterminated_template_literal: { code: 1160, category: ts.DiagnosticCategory.Error, key: "Unterminated template literal." }, Unterminated_regular_expression_literal: { code: 1161, category: ts.DiagnosticCategory.Error, key: "Unterminated regular expression literal." }, An_object_member_cannot_be_declared_optional: { code: 1162, category: ts.DiagnosticCategory.Error, key: "An object member cannot be declared optional." }, - yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: ts.DiagnosticCategory.Error, key: "'yield' expression must be contained_within a generator declaration." }, + A_yield_expression_is_only_allowed_in_a_generator_body: { code: 1163, category: ts.DiagnosticCategory.Error, key: "A 'yield' expression is only allowed in a generator body." }, Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: ts.DiagnosticCategory.Error, key: "Computed property names are not allowed in enums." }, A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol: { code: 1165, category: ts.DiagnosticCategory.Error, key: "A computed property name in an ambient context must directly refer to a built-in symbol." }, A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol: { code: 1166, category: ts.DiagnosticCategory.Error, key: "A computed property name in a class property declaration must directly refer to a built-in symbol." }, @@ -1084,8 +1096,8 @@ var ts; Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: ts.DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." }, Decorators_are_not_valid_here: { code: 1206, category: ts.DiagnosticCategory.Error, key: "Decorators are not valid here." }, Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: ts.DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, - Cannot_compile_namespaces_when_the_separateCompilation_flag_is_provided: { code: 1208, category: ts.DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--separateCompilation' flag is provided." }, - Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: ts.DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, + Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided: { code: 1208, category: ts.DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--isolatedModules' flag is provided." }, + Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided: { code: 1209, category: ts.DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--isolatedModules' flag is provided." }, Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." }, A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: ts.DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" }, @@ -1093,6 +1105,11 @@ var ts; Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" }, Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: ts.DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." }, + Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning: { code: 1219, category: ts.DiagnosticCategory.Error, key: "Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning." }, + Generators_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 1220, category: ts.DiagnosticCategory.Error, key: "Generators are only available when targeting ECMAScript 6 or higher." }, + Generators_are_not_allowed_in_an_ambient_context: { code: 1221, category: ts.DiagnosticCategory.Error, key: "Generators are not allowed in an ambient context." }, + An_overload_signature_cannot_be_declared_as_a_generator: { code: 1222, category: ts.DiagnosticCategory.Error, key: "An overload signature cannot be declared as a generator." }, + _0_tag_already_specified: { code: 1223, category: ts.DiagnosticCategory.Error, key: "'{0}' tag already specified." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "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." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -1253,7 +1270,7 @@ var ts; The_0_operator_cannot_be_applied_to_type_symbol: { code: 2469, category: ts.DiagnosticCategory.Error, key: "The '{0}' operator cannot be applied to type 'symbol'." }, Symbol_reference_does_not_refer_to_the_global_Symbol_constructor_object: { code: 2470, category: ts.DiagnosticCategory.Error, key: "'Symbol' reference does not refer to the global Symbol constructor object." }, A_computed_property_name_of_the_form_0_must_be_of_type_symbol: { code: 2471, category: ts.DiagnosticCategory.Error, key: "A computed property name of the form '{0}' must be of type 'symbol'." }, - Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher: { code: 2472, category: ts.DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher." }, + Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher: { code: 2472, category: ts.DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher." }, Enum_declarations_must_all_be_const_or_non_const: { code: 2473, category: ts.DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." }, In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 2474, category: ts.DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression." }, const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment: { code: 2475, category: ts.DiagnosticCategory.Error, key: "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment." }, @@ -1284,6 +1301,8 @@ var ts; A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: ts.DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." }, _0_is_referenced_directly_or_indirectly_in_its_own_type_annotation: { code: 2502, category: ts.DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own type annotation." }, Cannot_find_namespace_0: { code: 2503, category: ts.DiagnosticCategory.Error, key: "Cannot find namespace '{0}'." }, + No_best_common_type_exists_among_yield_expressions: { code: 2504, category: ts.DiagnosticCategory.Error, key: "No best common type exists among yield expressions." }, + A_generator_cannot_have_a_void_type_annotation: { code: 2505, category: ts.DiagnosticCategory.Error, key: "A generator cannot have a 'void' type annotation." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1368,11 +1387,11 @@ var ts; Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." }, Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." }, Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: ts.DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." }, - Option_sourceMap_cannot_be_specified_with_option_separateCompilation: { code: 5043, category: ts.DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'separateCompilation'." }, - Option_declaration_cannot_be_specified_with_option_separateCompilation: { code: 5044, category: ts.DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'separateCompilation'." }, - Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation: { code: 5045, category: ts.DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'separateCompilation'." }, - Option_out_cannot_be_specified_with_option_separateCompilation: { code: 5046, category: ts.DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'separateCompilation'." }, - Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: ts.DiagnosticCategory.Error, key: "Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." }, + Option_sourceMap_cannot_be_specified_with_option_isolatedModules: { code: 5043, category: ts.DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'isolatedModules'." }, + Option_declaration_cannot_be_specified_with_option_isolatedModules: { code: 5044, category: ts.DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'isolatedModules'." }, + Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules: { code: 5045, category: ts.DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'isolatedModules'." }, + Option_out_cannot_be_specified_with_option_isolatedModules: { code: 5046, category: ts.DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'isolatedModules'." }, + Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: ts.DiagnosticCategory.Error, key: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." }, Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap: { code: 5048, category: ts.DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'inlineSourceMap'." }, Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5049, category: ts.DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'." }, Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5050, category: ts.DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified with option 'inlineSourceMap'." }, @@ -1426,6 +1445,9 @@ var ts; Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: ts.DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." }, NEWLINE: { code: 6061, category: ts.DiagnosticCategory.Message, key: "NEWLINE" }, Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: ts.DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." }, + Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified: { code: 6064, category: ts.DiagnosticCategory.Error, key: "Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified." }, + Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." }, + Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." }, @@ -1441,6 +1463,7 @@ var ts; _0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." }, _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: ts.DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, + Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: ts.DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." }, You_cannot_rename_this_element: { code: 8000, category: ts.DiagnosticCategory.Error, key: "You cannot rename this element." }, You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: ts.DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." }, import_can_only_be_used_in_a_ts_file: { code: 8002, category: ts.DiagnosticCategory.Error, key: "'import ... =' can only be used in a .ts file." }, @@ -1454,16 +1477,12 @@ var ts; types_can_only_be_used_in_a_ts_file: { code: 8010, category: ts.DiagnosticCategory.Error, key: "'types' can only be used in a .ts file." }, type_arguments_can_only_be_used_in_a_ts_file: { code: 8011, category: ts.DiagnosticCategory.Error, key: "'type arguments' can only be used in a .ts file." }, parameter_modifiers_can_only_be_used_in_a_ts_file: { code: 8012, category: ts.DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in a .ts file." }, - can_only_be_used_in_a_ts_file: { code: 8013, category: ts.DiagnosticCategory.Error, key: "'?' can only be used in a .ts file." }, property_declarations_can_only_be_used_in_a_ts_file: { code: 8014, category: ts.DiagnosticCategory.Error, key: "'property declarations' can only be used in a .ts file." }, enum_declarations_can_only_be_used_in_a_ts_file: { code: 8015, category: ts.DiagnosticCategory.Error, key: "'enum declarations' can only be used in a .ts file." }, type_assertion_expressions_can_only_be_used_in_a_ts_file: { code: 8016, category: ts.DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in a .ts file." }, decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: ts.DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." }, - yield_expressions_are_not_currently_supported: { code: 9000, category: ts.DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, - Generators_are_not_currently_supported: { code: 9001, category: ts.DiagnosticCategory.Error, key: "Generators are not currently supported." }, Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: ts.DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." }, - class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." }, - class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration: { code: 9004, category: ts.DiagnosticCategory.Error, key: "'class' declarations are only supported directly inside a module or as a top level declaration." } + class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." } }; })(ts || (ts = {})); /// @@ -2764,34 +2783,30 @@ var ts; var symbolCount = 0; var Symbol = ts.objectAllocator.getSymbolConstructor(); if (!file.locals) { - file.locals = {}; - container = file; - setBlockScopeContainer(file, false); bind(file); file.symbolCount = symbolCount; } + return; function createSymbol(flags, name) { symbolCount++; return new Symbol(flags, name); } - function setBlockScopeContainer(node, cleanLocals) { - blockScopeContainer = node; - if (cleanLocals) { - blockScopeContainer.locals = undefined; - } - } - function addDeclarationToSymbol(symbol, node, symbolKind) { - symbol.flags |= symbolKind; - if (!symbol.declarations) - symbol.declarations = []; - symbol.declarations.push(node); - if (symbolKind & 1952 && !symbol.exports) - symbol.exports = {}; - if (symbolKind & 6240 && !symbol.members) - symbol.members = {}; + function addDeclarationToSymbol(symbol, node, symbolFlags) { + symbol.flags |= symbolFlags; node.symbol = symbol; - if (symbolKind & 107455 && !symbol.valueDeclaration) + if (!symbol.declarations) { + symbol.declarations = []; + } + symbol.declarations.push(node); + if (symbolFlags & 1952 && !symbol.exports) { + symbol.exports = {}; + } + if (symbolFlags & 6240 && !symbol.members) { + symbol.members = {}; + } + if (symbolFlags & 107455 && !symbol.valueDeclaration) { symbol.valueDeclaration = node; + } } function getDeclarationName(node) { if (node.name) { @@ -2806,12 +2821,12 @@ var ts; return node.name.text; } switch (node.kind) { - case 144: case 136: return "__constructor"; case 143: case 139: return "__call"; + case 144: case 140: return "__new"; case 141: @@ -2828,12 +2843,14 @@ var ts; function getDisplayName(node) { return node.name ? ts.declarationNameToString(node.name) : getDeclarationName(node); } - function declareSymbol(symbols, parent, node, includes, excludes) { + function declareSymbol(symbolTable, parent, node, includes, excludes) { ts.Debug.assert(!ts.hasDynamicName(node)); var name = node.flags & 256 && parent ? "default" : getDeclarationName(node); var symbol; if (name !== undefined) { - symbol = ts.hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name)); + symbol = ts.hasProperty(symbolTable, name) + ? symbolTable[name] + : (symbolTable[name] = createSymbol(0, name)); if (symbol.flags & excludes) { if (node.name) { node.name.parent = node; @@ -2853,79 +2870,115 @@ var ts; } addDeclarationToSymbol(symbol, node, includes); symbol.parent = parent; - if ((node.kind === 202 || node.kind === 175) && symbol.exports) { - var prototypeSymbol = createSymbol(4 | 134217728, "prototype"); - if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) { - if (node.name) { - node.name.parent = node; - } - file.bindDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name)); - } - symbol.exports[prototypeSymbol.name] = prototypeSymbol; - prototypeSymbol.parent = symbol; - } return symbol; } - function declareModuleMember(node, symbolKind, symbolExcludes) { + function declareModuleMember(node, symbolFlags, symbolExcludes) { var hasExportModifier = ts.getCombinedNodeFlags(node) & 1; - if (symbolKind & 8388608) { + if (symbolFlags & 8388608) { if (node.kind === 218 || (node.kind === 209 && hasExportModifier)) { - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); + return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); } else { - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); + return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } else { if (hasExportModifier || container.flags & 65536) { - var exportKind = (symbolKind & 107455 ? 1048576 : 0) | - (symbolKind & 793056 ? 2097152 : 0) | - (symbolKind & 1536 ? 4194304 : 0); + var exportKind = (symbolFlags & 107455 ? 1048576 : 0) | + (symbolFlags & 793056 ? 2097152 : 0) | + (symbolFlags & 1536 ? 4194304 : 0); var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); - local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); + local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); node.localSymbol = local; + return local; } else { - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); + return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } } - function bindChildren(node, symbolKind, isBlockScopeContainer) { - if (symbolKind & 255504) { - node.locals = {}; - } + function bindChildren(node) { var saveParent = parent; var saveContainer = container; var savedBlockScopeContainer = blockScopeContainer; parent = node; - if (symbolKind & 262128) { - container = node; + var containerFlags = getContainerFlags(node); + if (containerFlags & 1) { + container = blockScopeContainer = node; + if (containerFlags & 4) { + container.locals = {}; + } addToContainerChain(container); } - if (isBlockScopeContainer) { - setBlockScopeContainer(node, (symbolKind & 255504) === 0 && node.kind !== 228); + else if (containerFlags & 2) { + blockScopeContainer = node; + blockScopeContainer.locals = undefined; } ts.forEachChild(node, bind); container = saveContainer; parent = saveParent; blockScopeContainer = savedBlockScopeContainer; } - function addToContainerChain(node) { - if (lastContainer) { - lastContainer.nextContainer = node; + function getContainerFlags(node) { + switch (node.kind) { + case 175: + case 202: + case 203: + case 205: + case 146: + case 155: + return 1; + case 139: + case 140: + case 141: + case 135: + case 134: + case 201: + case 136: + case 137: + case 138: + case 143: + case 144: + case 163: + case 164: + case 206: + case 228: + return 5; + case 224: + case 187: + case 188: + case 189: + case 208: + return 2; + case 180: + return ts.isFunctionLike(node.parent) ? 0 : 2; } - lastContainer = node; + return 0; } - function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) { + function addToContainerChain(next) { + if (lastContainer) { + lastContainer.nextContainer = next; + } + lastContainer = next; + } + function declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes) { + declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes); + } + function declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes) { switch (container.kind) { case 206: - declareModuleMember(node, symbolKind, symbolExcludes); - break; + return declareModuleMember(node, symbolFlags, symbolExcludes); case 228: - if (ts.isExternalModule(container)) { - declareModuleMember(node, symbolKind, symbolExcludes); - break; - } + return declareSourceFileMember(node, symbolFlags, symbolExcludes); + case 175: + case 202: + return declareClassMember(node, symbolFlags, symbolExcludes); + case 205: + return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); + case 146: + case 155: + case 203: + return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); case 143: case 144: case 139: @@ -2939,29 +2992,24 @@ var ts; case 201: case 163: case 164: - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); - break; - case 175: - case 202: - if (node.flags & 128) { - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); - break; - } - case 146: - case 155: - case 203: - declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes); - break; - case 205: - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); - break; + return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } - bindChildren(node, symbolKind, isBlockScopeContainer); + } + function declareClassMember(node, symbolFlags, symbolExcludes) { + return node.flags & 128 + ? declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes) + : declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); + } + function declareSourceFileMember(node, symbolFlags, symbolExcludes) { + return ts.isExternalModule(file) + ? declareModuleMember(node, symbolFlags, symbolExcludes) + : declareSymbol(file.locals, undefined, node, symbolFlags, symbolExcludes); } function isAmbientContext(node) { while (node) { - if (node.flags & 2) + if (node.flags & 2) { return true; + } node = node.parent; } return false; @@ -2989,15 +3037,15 @@ var ts; function bindModuleDeclaration(node) { setExportContextFlag(node); if (node.name.kind === 8) { - bindDeclaration(node, 512, 106639, true); + declareSymbolAndAddToSymbolTable(node, 512, 106639); } else { var state = getModuleInstanceState(node); if (state === 0) { - bindDeclaration(node, 1024, 0, true); + declareSymbolAndAddToSymbolTable(node, 1024, 0); } else { - bindDeclaration(node, 512, 106639, true); + declareSymbolAndAddToSymbolTable(node, 512, 106639); var currentModuleIsConstEnumOnly = state === 2; if (node.symbol.constEnumOnlyModule === undefined) { node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly; @@ -3009,36 +3057,25 @@ var ts; } } function bindFunctionOrConstructorType(node) { - // For a given function symbol "<...>(...) => T" we want to generate a symbol identical - // to the one we would get for: { <...>(...): T } - // - // We do that by making an anonymous type literal symbol, and then setting the function - // symbol as its sole member. To the rest of the system, this symbol will be indistinguishable - // from an actual type literal symbol you would have gotten had you used the long form. var symbol = createSymbol(131072, getDeclarationName(node)); addDeclarationToSymbol(symbol, node, 131072); - bindChildren(node, 131072, false); var typeLiteralSymbol = createSymbol(2048, "__type"); addDeclarationToSymbol(typeLiteralSymbol, node, 2048); - typeLiteralSymbol.members = {}; - typeLiteralSymbol.members[node.kind === 143 ? "__call" : "__new"] = symbol; + typeLiteralSymbol.members = (_a = {}, _a[symbol.name] = symbol, _a); + var _a; } - function bindAnonymousDeclaration(node, symbolKind, name, isBlockScopeContainer) { - var symbol = createSymbol(symbolKind, name); - addDeclarationToSymbol(symbol, node, symbolKind); - bindChildren(node, symbolKind, isBlockScopeContainer); + function bindAnonymousDeclaration(node, symbolFlags, name) { + var symbol = createSymbol(symbolFlags, name); + addDeclarationToSymbol(symbol, node, symbolFlags); } - function bindCatchVariableDeclaration(node) { - bindChildren(node, 0, true); - } - function bindBlockScopedDeclaration(node, symbolKind, symbolExcludes) { + function bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) { switch (blockScopeContainer.kind) { case 206: - declareModuleMember(node, symbolKind, symbolExcludes); + declareModuleMember(node, symbolFlags, symbolExcludes); break; case 228: if (ts.isExternalModule(container)) { - declareModuleMember(node, symbolKind, symbolExcludes); + declareModuleMember(node, symbolFlags, symbolExcludes); break; } default: @@ -3046,9 +3083,8 @@ var ts; blockScopeContainer.locals = {}; addToContainerChain(blockScopeContainer); } - declareSymbol(blockScopeContainer.locals, undefined, node, symbolKind, symbolExcludes); + declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes); } - bindChildren(node, symbolKind, false); } function bindBlockScopedVariableDeclaration(node) { bindBlockScopedDeclaration(node, 2, 107455); @@ -3058,158 +3094,143 @@ var ts; } function bind(node) { node.parent = parent; + bindWorker(node); + bindChildren(node); + } + function bindWorker(node) { switch (node.kind) { case 129: - bindDeclaration(node, 262144, 530912, false); - break; + return declareSymbolAndAddToSymbolTable(node, 262144, 530912); case 130: - bindParameter(node); - break; + return bindParameter(node); case 199: case 153: - if (ts.isBindingPattern(node.name)) { - bindChildren(node, 0, false); - } - else if (ts.isBlockOrCatchScoped(node)) { - bindBlockScopedVariableDeclaration(node); - } - else if (ts.isParameterDeclaration(node)) { - bindDeclaration(node, 1, 107455, false); - } - else { - bindDeclaration(node, 1, 107454, false); - } - break; + return bindVariableDeclarationOrBindingElement(node); case 133: case 132: - bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455, false); - break; + return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455); case 225: case 226: - bindPropertyOrMethodOrAccessor(node, 4, 107455, false); - break; + return bindPropertyOrMethodOrAccessor(node, 4, 107455); case 227: - bindPropertyOrMethodOrAccessor(node, 8, 107455, false); - break; + return bindPropertyOrMethodOrAccessor(node, 8, 107455); case 139: case 140: case 141: - bindDeclaration(node, 131072, 0, false); - break; + return declareSymbolAndAddToSymbolTable(node, 131072, 0); case 135: case 134: - bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263, true); - break; + return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263); case 201: - bindDeclaration(node, 16, 106927, true); - break; + return declareSymbolAndAddToSymbolTable(node, 16, 106927); case 136: - bindDeclaration(node, 16384, 0, true); - break; + return declareSymbolAndAddToSymbolTable(node, 16384, 0); case 137: - bindPropertyOrMethodOrAccessor(node, 32768, 41919, true); - break; + return bindPropertyOrMethodOrAccessor(node, 32768, 41919); case 138: - bindPropertyOrMethodOrAccessor(node, 65536, 74687, true); - break; + return bindPropertyOrMethodOrAccessor(node, 65536, 74687); case 143: case 144: - bindFunctionOrConstructorType(node); - break; + return bindFunctionOrConstructorType(node); case 146: - bindAnonymousDeclaration(node, 2048, "__type", false); - break; + return bindAnonymousDeclaration(node, 2048, "__type"); case 155: - bindAnonymousDeclaration(node, 4096, "__object", false); - break; + return bindAnonymousDeclaration(node, 4096, "__object"); case 163: case 164: - bindAnonymousDeclaration(node, 16, "__function", true); - break; + return bindAnonymousDeclaration(node, 16, "__function"); case 175: - bindAnonymousDeclaration(node, 32, "__class", false); - break; - case 224: - bindCatchVariableDeclaration(node); - break; case 202: - bindBlockScopedDeclaration(node, 32, 899583); - break; + return bindClassLikeDeclaration(node); case 203: - bindDeclaration(node, 64, 792992, false); - break; + return bindBlockScopedDeclaration(node, 64, 792992); case 204: - bindDeclaration(node, 524288, 793056, false); - break; + return bindBlockScopedDeclaration(node, 524288, 793056); case 205: - if (ts.isConst(node)) { - bindDeclaration(node, 128, 899967, false); - } - else { - bindDeclaration(node, 256, 899327, false); - } - break; + return bindEnumDeclaration(node); case 206: - bindModuleDeclaration(node); - break; + return bindModuleDeclaration(node); case 209: case 212: case 214: case 218: - bindDeclaration(node, 8388608, 8388608, false); - break; + return declareSymbolAndAddToSymbolTable(node, 8388608, 8388608); case 211: - if (node.name) { - bindDeclaration(node, 8388608, 8388608, false); - } - else { - bindChildren(node, 0, false); - } - break; + return bindImportClause(node); case 216: - if (!node.exportClause) { - declareSymbol(container.symbol.exports, container.symbol, node, 1073741824, 0); - } - bindChildren(node, 0, false); - break; + return bindExportDeclaration(node); case 215: - if (node.expression.kind === 65) { - declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608); - } - else { - declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455 | 8388608); - } - bindChildren(node, 0, false); - break; + return bindExportAssignment(node); case 228: - setExportContextFlag(node); - if (ts.isExternalModule(node)) { - bindAnonymousDeclaration(node, 512, '"' + ts.removeFileExtension(node.fileName) + '"', true); - break; - } - case 180: - bindChildren(node, 0, !ts.isFunctionLike(node.parent)); - break; - case 224: - case 187: - case 188: - case 189: - case 208: - bindChildren(node, 0, true); - break; - default: - var saveParent = parent; - parent = node; - ts.forEachChild(node, bind); - parent = saveParent; + return bindSourceFileIfExternalModule(); + } + } + function bindSourceFileIfExternalModule() { + setExportContextFlag(file); + if (ts.isExternalModule(file)) { + bindAnonymousDeclaration(file, 512, '"' + ts.removeFileExtension(file.fileName) + '"'); + } + } + function bindExportAssignment(node) { + if (node.expression.kind === 65) { + declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608); + } + else { + declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455 | 8388608); + } + } + function bindExportDeclaration(node) { + if (!node.exportClause) { + declareSymbol(container.symbol.exports, container.symbol, node, 1073741824, 0); + } + } + function bindImportClause(node) { + if (node.name) { + declareSymbolAndAddToSymbolTable(node, 8388608, 8388608); + } + } + function bindClassLikeDeclaration(node) { + if (node.kind === 202) { + bindBlockScopedDeclaration(node, 32, 899583); + } + else { + bindAnonymousDeclaration(node, 32, "__class"); + } + var symbol = node.symbol; + var prototypeSymbol = createSymbol(4 | 134217728, "prototype"); + if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) { + if (node.name) { + node.name.parent = node; + } + file.bindDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name)); + } + symbol.exports[prototypeSymbol.name] = prototypeSymbol; + prototypeSymbol.parent = symbol; + } + function bindEnumDeclaration(node) { + return ts.isConst(node) + ? bindBlockScopedDeclaration(node, 128, 899967) + : bindBlockScopedDeclaration(node, 256, 899327); + } + function bindVariableDeclarationOrBindingElement(node) { + if (!ts.isBindingPattern(node.name)) { + if (ts.isBlockOrCatchScoped(node)) { + bindBlockScopedVariableDeclaration(node); + } + else if (ts.isParameterDeclaration(node)) { + declareSymbolAndAddToSymbolTable(node, 1, 107455); + } + else { + declareSymbolAndAddToSymbolTable(node, 1, 107454); + } } } function bindParameter(node) { if (ts.isBindingPattern(node.name)) { - bindAnonymousDeclaration(node, 1, getDestructuringParameterName(node), false); + bindAnonymousDeclaration(node, 1, getDestructuringParameterName(node)); } else { - bindDeclaration(node, 1, 107455, false); + declareSymbolAndAddToSymbolTable(node, 1, 107455); } if (node.flags & 112 && node.parent.kind === 136 && @@ -3218,13 +3239,10 @@ var ts; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455); } } - function bindPropertyOrMethodOrAccessor(node, symbolKind, symbolExcludes, isBlockScopeContainer) { - if (ts.hasDynamicName(node)) { - bindAnonymousDeclaration(node, symbolKind, "__computed", isBlockScopeContainer); - } - else { - bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer); - } + function bindPropertyOrMethodOrAccessor(node, symbolFlags, symbolExcludes) { + return ts.hasDynamicName(node) + ? bindAnonymousDeclaration(node, symbolFlags, "__computed") + : declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes); } } })(ts || (ts = {})); @@ -3277,17 +3295,17 @@ var ts; ts.getFullWidth = getFullWidth; function containsParseError(node) { aggregateChildData(node); - return (node.parserContextFlags & 64) !== 0; + return (node.parserContextFlags & 128) !== 0; } ts.containsParseError = containsParseError; function aggregateChildData(node) { - if (!(node.parserContextFlags & 128)) { + if (!(node.parserContextFlags & 256)) { var thisNodeOrAnySubNodesHasError = ((node.parserContextFlags & 32) !== 0) || ts.forEachChild(node, containsParseError); if (thisNodeOrAnySubNodesHasError) { - node.parserContextFlags |= 64; + node.parserContextFlags |= 128; } - node.parserContextFlags |= 128; + node.parserContextFlags |= 256; } } function getSourceFileOfNode(node) { @@ -3530,6 +3548,75 @@ var ts; } ts.getJsDocComments = getJsDocComments; ts.fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/; + function isTypeNode(node) { + if (142 <= node.kind && node.kind <= 150) { + return true; + } + switch (node.kind) { + case 112: + case 120: + case 122: + case 113: + case 123: + return true; + case 99: + return node.parent.kind !== 167; + case 8: + return node.parent.kind === 130; + case 177: + return true; + case 65: + if (node.parent.kind === 127 && node.parent.right === node) { + node = node.parent; + } + else if (node.parent.kind === 156 && node.parent.name === node) { + node = node.parent; + } + case 127: + case 156: + ts.Debug.assert(node.kind === 65 || node.kind === 127 || node.kind === 156, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); + var parent_1 = node.parent; + if (parent_1.kind === 145) { + return false; + } + if (142 <= parent_1.kind && parent_1.kind <= 150) { + return true; + } + switch (parent_1.kind) { + case 177: + return true; + case 129: + return node === parent_1.constraint; + case 133: + case 132: + case 130: + case 199: + return node === parent_1.type; + case 201: + case 163: + case 164: + case 136: + case 135: + case 134: + case 137: + case 138: + return node === parent_1.type; + case 139: + case 140: + case 141: + return node === parent_1.type; + case 161: + return node === parent_1.type; + case 158: + case 159: + return parent_1.typeArguments && ts.indexOf(parent_1.typeArguments, node) >= 0; + case 160: + return false; + } + } + return false; + } + ts.isTypeNode = isTypeNode; function forEachReturnStatement(body, visitor) { return traverse(body); function traverse(node) { @@ -3556,6 +3643,37 @@ var ts; } } ts.forEachReturnStatement = forEachReturnStatement; + function forEachYieldExpression(body, visitor) { + return traverse(body); + function traverse(node) { + switch (node.kind) { + case 173: + visitor(node); + var operand = node.expression; + if (operand) { + traverse(operand); + } + case 205: + case 203: + case 206: + case 204: + case 202: + return; + default: + if (isFunctionLike(node)) { + var name_3 = node.name; + if (name_3 && name_3.kind === 128) { + traverse(name_3.expression); + return; + } + } + else if (!isTypeNode(node)) { + ts.forEachChild(node, traverse); + } + } + } + } + ts.forEachYieldExpression = forEachYieldExpression; function isVariableLike(node) { if (node) { switch (node.kind) { @@ -3584,6 +3702,12 @@ var ts; return false; } ts.isAccessor = isAccessor; + function isClassLike(node) { + if (node) { + return node.kind === 202 || node.kind === 175; + } + } + ts.isClassLike = isClassLike; function isFunctionLike(node) { if (node) { switch (node.kind) { @@ -3800,6 +3924,7 @@ var ts; case 172: case 10: case 176: + case 173: return true; case 127: while (node.parent.kind === 127) { @@ -3812,8 +3937,8 @@ var ts; } case 7: case 8: - var parent_1 = node.parent; - switch (parent_1.kind) { + var parent_2 = node.parent; + switch (parent_2.kind) { case 199: case 130: case 133: @@ -3821,7 +3946,7 @@ var ts; case 227: case 225: case 153: - return parent_1.initializer === node; + return parent_2.initializer === node; case 183: case 184: case 185: @@ -3832,27 +3957,27 @@ var ts; case 221: case 196: case 194: - return parent_1.expression === node; + return parent_2.expression === node; case 187: - var forStatement = parent_1; + var forStatement = parent_2; return (forStatement.initializer === node && forStatement.initializer.kind !== 200) || forStatement.condition === node || forStatement.incrementor === node; case 188: case 189: - var forInStatement = parent_1; + var forInStatement = parent_2; return (forInStatement.initializer === node && forInStatement.initializer.kind !== 200) || forInStatement.expression === node; case 161: - return node === parent_1.expression; + return node === parent_2.expression; case 178: - return node === parent_1.expression; + return node === parent_2.expression; case 128: - return node === parent_1.expression; + return node === parent_2.expression; case 131: return true; default: - if (isExpression(parent_1)) { + if (isExpression(parent_2)) { return true; } } @@ -3894,10 +4019,6 @@ var ts; } } ts.getExternalModuleName = getExternalModuleName; - function hasDotDotDotToken(node) { - return node && node.kind === 130 && node.dotDotDotToken !== undefined; - } - ts.hasDotDotDotToken = hasDotDotDotToken; function hasQuestionToken(node) { if (node) { switch (node.kind) { @@ -3916,10 +4037,72 @@ var ts; return false; } ts.hasQuestionToken = hasQuestionToken; - function hasRestParameters(s) { - return s.parameters.length > 0 && ts.lastOrUndefined(s.parameters).dotDotDotToken !== undefined; + function isJSDocConstructSignature(node) { + return node.kind === 241 && + node.parameters.length > 0 && + node.parameters[0].type.kind === 243; } - ts.hasRestParameters = hasRestParameters; + ts.isJSDocConstructSignature = isJSDocConstructSignature; + function getJSDocTag(node, kind) { + if (node && node.jsDocComment) { + for (var _i = 0, _a = node.jsDocComment.tags; _i < _a.length; _i++) { + var tag = _a[_i]; + if (tag.kind === kind) { + return tag; + } + } + } + } + function getJSDocTypeTag(node) { + return getJSDocTag(node, 249); + } + ts.getJSDocTypeTag = getJSDocTypeTag; + function getJSDocReturnTag(node) { + return getJSDocTag(node, 248); + } + ts.getJSDocReturnTag = getJSDocReturnTag; + function getJSDocTemplateTag(node) { + return getJSDocTag(node, 250); + } + ts.getJSDocTemplateTag = getJSDocTemplateTag; + function getCorrespondingJSDocParameterTag(parameter) { + if (parameter.name && parameter.name.kind === 65) { + var parameterName = parameter.name.text; + var docComment = parameter.parent.jsDocComment; + if (docComment) { + return ts.forEach(docComment.tags, function (t) { + if (t.kind === 247) { + var parameterTag = t; + var name_4 = parameterTag.preParameterName || parameterTag.postParameterName; + if (name_4.text === parameterName) { + return t; + } + } + }); + } + } + } + ts.getCorrespondingJSDocParameterTag = getCorrespondingJSDocParameterTag; + function hasRestParameter(s) { + return isRestParameter(ts.lastOrUndefined(s.parameters)); + } + ts.hasRestParameter = hasRestParameter; + function isRestParameter(node) { + if (node) { + if (node.parserContextFlags & 64) { + if (node.type && node.type.kind === 242) { + return true; + } + var paramTag = getCorrespondingJSDocParameterTag(node); + if (paramTag && paramTag.typeExpression) { + return paramTag.typeExpression.type.kind === 242; + } + } + return node.dotDotDotToken !== undefined; + } + return false; + } + ts.isRestParameter = isRestParameter; function isLiteralKind(kind) { return 7 <= kind && kind <= 10; } @@ -4427,7 +4610,7 @@ var ts; function shouldEmitToOwnFile(sourceFile, compilerOptions) { if (!isDeclarationFile(sourceFile)) { if ((isExternalModule(sourceFile) || !compilerOptions.out)) { - return compilerOptions.separateCompilation || !ts.fileExtensionIs(sourceFile.fileName, ".js"); + return compilerOptions.isolatedModules || !ts.fileExtensionIs(sourceFile.fileName, ".js"); } return false; } @@ -4643,6 +4826,10 @@ var ts; return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & 256) ? symbol.valueDeclaration.localSymbol : undefined; } ts.getLocalSymbolForExportDefault = getLocalSymbolForExportDefault; + function isJavaScript(fileName) { + return ts.fileExtensionIs(fileName, ".js"); + } + ts.isJavaScript = isJavaScript; function getExpandedCharCodes(input) { var output = []; var length = input.length; @@ -4813,12 +5000,22 @@ var ts; return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); } ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; + function getTypeParameterOwner(d) { + if (d && d.kind === 129) { + for (var current = d; current; current = current.parent) { + if (ts.isFunctionLike(current) || ts.isClassLike(current) || current.kind === 203) { + return current; + } + } + } + } + ts.getTypeParameterOwner = getTypeParameterOwner; })(ts || (ts = {})); /// /// var ts; (function (ts) { - var nodeConstructors = new Array(230); + var nodeConstructors = new Array(252); ts.parseTime = 0; function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); @@ -5121,6 +5318,49 @@ var ts; return visitNode(cbNode, node.expression); case 219: return visitNodes(cbNodes, node.decorators); + case 229: + return visitNode(cbNode, node.type); + case 233: + return visitNodes(cbNodes, node.types); + case 234: + return visitNodes(cbNodes, node.types); + case 232: + return visitNode(cbNode, node.elementType); + case 236: + return visitNode(cbNode, node.type); + case 235: + return visitNode(cbNode, node.type); + case 237: + return visitNodes(cbNodes, node.members); + case 239: + return visitNode(cbNode, node.name) || + visitNodes(cbNodes, node.typeArguments); + case 240: + return visitNode(cbNode, node.type); + case 241: + return visitNodes(cbNodes, node.parameters) || + visitNode(cbNode, node.type); + case 242: + return visitNode(cbNode, node.type); + case 243: + return visitNode(cbNode, node.type); + case 244: + return visitNode(cbNode, node.type); + case 238: + return visitNode(cbNode, node.name) || + visitNode(cbNode, node.type); + case 245: + return visitNodes(cbNodes, node.tags); + case 247: + return visitNode(cbNode, node.preParameterName) || + visitNode(cbNode, node.typeExpression) || + visitNode(cbNode, node.postParameterName); + case 248: + return visitNode(cbNode, node.typeExpression); + case 249: + return visitNode(cbNode, node.typeExpression); + case 250: + return visitNodes(cbNodes, node.typeParameters); } } ts.forEachChild = forEachChild; @@ -5136,11 +5376,20 @@ var ts; return IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks); } ts.updateSourceFile = updateSourceFile; + function parseIsolatedJSDocComment(content, start, length) { + return Parser.JSDocParser.parseIsolatedJSDocComment(content, start, length); + } + ts.parseIsolatedJSDocComment = parseIsolatedJSDocComment; + function parseJSDocTypeExpressionForTests(content, start, length) { + return Parser.JSDocParser.parseJSDocTypeExpressionForTests(content, start, length); + } + ts.parseJSDocTypeExpressionForTests = parseJSDocTypeExpressionForTests; var Parser; (function (Parser) { var scanner = ts.createScanner(2, true); var disallowInAndDecoratorContext = 2 | 16; var sourceFile; + var parseDiagnostics; var syntaxCursor; var token; var sourceText; @@ -5148,21 +5397,40 @@ var ts; var identifiers; var identifierCount; var parsingContext; - var contextFlags = 0; + var contextFlags; var parseErrorBeforeNextFinishedNode = false; function parseSourceFile(fileName, _sourceText, languageVersion, _syntaxCursor, setParentNodes) { + initializeState(fileName, _sourceText, languageVersion, _syntaxCursor); + var result = parseSourceFileWorker(fileName, languageVersion, setParentNodes); + clearState(); + return result; + } + Parser.parseSourceFile = parseSourceFile; + function initializeState(fileName, _sourceText, languageVersion, _syntaxCursor) { sourceText = _sourceText; syntaxCursor = _syntaxCursor; + parseDiagnostics = []; parsingContext = 0; identifiers = {}; identifierCount = 0; nodeCount = 0; - contextFlags = 0; + contextFlags = ts.isJavaScript(fileName) ? 64 : 0; parseErrorBeforeNextFinishedNode = false; - createSourceFile(fileName, languageVersion); scanner.setText(sourceText); scanner.setOnError(scanError); scanner.setScriptTarget(languageVersion); + } + function clearState() { + scanner.setText(""); + scanner.setOnError(undefined); + parseDiagnostics = undefined; + sourceFile = undefined; + identifiers = undefined; + syntaxCursor = undefined; + sourceText = undefined; + } + function parseSourceFileWorker(fileName, languageVersion, setParentNodes) { + sourceFile = createSourceFile(fileName, languageVersion); token = nextToken(); processReferenceComments(sourceFile); sourceFile.statements = parseList(0, true, parseSourceElement); @@ -5172,20 +5440,40 @@ var ts; sourceFile.nodeCount = nodeCount; sourceFile.identifierCount = identifierCount; sourceFile.identifiers = identifiers; + sourceFile.parseDiagnostics = parseDiagnostics; if (setParentNodes) { fixupParentReferences(sourceFile); } - syntaxCursor = undefined; - scanner.setText(""); - scanner.setOnError(undefined); - var result = sourceFile; - sourceFile = undefined; - identifiers = undefined; - syntaxCursor = undefined; - sourceText = undefined; - return result; + if (ts.isJavaScript(fileName)) { + addJSDocComments(); + } + return sourceFile; + } + function addJSDocComments() { + forEachChild(sourceFile, visit); + return; + function visit(node) { + switch (node.kind) { + case 181: + case 201: + case 130: + addJSDocComment(node); + } + forEachChild(node, visit); + } + } + function addJSDocComment(node) { + var comments = ts.getLeadingCommentRangesOfNode(node, sourceFile); + if (comments) { + for (var _i = 0; _i < comments.length; _i++) { + var comment = comments[_i]; + var jsDocComment = JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos); + if (jsDocComment) { + node.jsDocComment = jsDocComment; + } + } + } } - Parser.parseSourceFile = parseSourceFile; function fixupParentReferences(sourceFile) { // normally parent references are set during binding. However, for clients that only need // a syntax tree, and no semantic features, then the binding process is an unnecessary @@ -5204,16 +5492,17 @@ var ts; } } } + Parser.fixupParentReferences = fixupParentReferences; function createSourceFile(fileName, languageVersion) { - sourceFile = createNode(228, 0); + var sourceFile = createNode(228, 0); sourceFile.pos = 0; sourceFile.end = sourceText.length; sourceFile.text = sourceText; - sourceFile.parseDiagnostics = []; sourceFile.bindDiagnostics = []; sourceFile.languageVersion = languageVersion; sourceFile.fileName = ts.normalizePath(fileName); sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 2048 : 0; + return sourceFile; } function setContextFlag(val, flag) { if (val) { @@ -5314,9 +5603,9 @@ var ts; parseErrorAtPosition(start, length, message, arg0); } function parseErrorAtPosition(start, length, message, arg0) { - var lastError = ts.lastOrUndefined(sourceFile.parseDiagnostics); + var lastError = ts.lastOrUndefined(parseDiagnostics); if (!lastError || start !== lastError.start) { - sourceFile.parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, start, length, message, arg0)); + parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, start, length, message, arg0)); } parseErrorBeforeNextFinishedNode = true; } @@ -5347,7 +5636,7 @@ var ts; } function speculationHelper(callback, isLookAhead) { var saveToken = token; - var saveParseDiagnosticsLength = sourceFile.parseDiagnostics.length; + var saveParseDiagnosticsLength = parseDiagnostics.length; var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; var saveContextFlags = contextFlags; var result = isLookAhead @@ -5356,7 +5645,7 @@ var ts; ts.Debug.assert(saveContextFlags === contextFlags); if (!result || isLookAhead) { token = saveToken; - sourceFile.parseDiagnostics.length = saveParseDiagnosticsLength; + parseDiagnostics.length = saveParseDiagnosticsLength; parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode; } return result; @@ -5438,8 +5727,8 @@ var ts; node.end = pos; return node; } - function finishNode(node) { - node.end = scanner.getStartPos(); + function finishNode(node, end) { + node.end = end === undefined ? scanner.getStartPos() : end; if (contextFlags) { node.parserContextFlags = contextFlags; } @@ -5488,15 +5777,24 @@ var ts; token === 8 || token === 7; } - function parsePropertyName() { + function parsePropertyNameWorker(allowComputedPropertyNames) { if (token === 8 || token === 7) { return parseLiteralNode(true); } - if (token === 18) { + if (allowComputedPropertyNames && token === 18) { return parseComputedPropertyName(); } return parseIdentifierName(); } + function parsePropertyName() { + return parsePropertyNameWorker(true); + } + function parseSimplePropertyName() { + return parsePropertyNameWorker(false); + } + function isSimplePropertyName() { + return token === 8 || token === 7 || isIdentifierOrKeyword(); + } function parseComputedPropertyName() { var node = createNode(128); parseExpected(18); @@ -5552,10 +5850,10 @@ var ts; switch (parsingContext) { case 0: case 1: - return isSourceElement(inErrorRecovery); + return !(token === 22 && inErrorRecovery) && isStartOfModuleElement(); case 2: case 4: - return isStartOfStatement(inErrorRecovery); + return !(token === 22 && inErrorRecovery) && isStartOfStatement(); case 3: return token === 67 || token === 73; case 5: @@ -5596,6 +5894,12 @@ var ts; return isHeritageClause(); case 20: return isIdentifierOrKeyword(); + case 21: + case 22: + case 24: + return JSDocParser.isJSDocType(); + case 23: + return isSimplePropertyName(); } ts.Debug.fail("Non-exhaustive case in 'isListElement'."); } @@ -5657,6 +5961,14 @@ var ts; return token === 25 || token === 16; case 19: return token === 14 || token === 15; + case 21: + return token === 17 || token === 51 || token === 15; + case 22: + return token === 25 || token === 15; + case 24: + return token === 19 || token === 15; + case 23: + return token === 15; } } function isVariableDeclaratorListTerminator() { @@ -5672,7 +5984,7 @@ var ts; return false; } function isInSomeParsingContext() { - for (var kind = 0; kind < 21; kind++) { + for (var kind = 0; kind < 25; kind++) { if (parsingContext & (1 << kind)) { if (isListElement(kind, true) || isListTerminator(kind)) { return true; @@ -5693,7 +6005,7 @@ var ts; result.push(element); if (checkForStrictMode && !inStrictModeContext()) { if (ts.isPrologueDirective(element)) { - if (isUseStrictPrologueDirective(sourceFile, element)) { + if (isUseStrictPrologueDirective(element)) { setStrictModeContext(true); checkForStrictMode = false; } @@ -5713,9 +6025,9 @@ var ts; parsingContext = saveParsingContext; return result; } - function isUseStrictPrologueDirective(sourceFile, node) { + function isUseStrictPrologueDirective(node) { ts.Debug.assert(ts.isPrologueDirective(node)); - var nodeText = ts.getSourceTextOfNodeFromSourceFile(sourceFile, node.expression); + var nodeText = ts.getTextOfNodeFromSourceText(sourceText, node.expression); return nodeText === '"use strict"' || nodeText === "'use strict'"; } function parseListElement(parsingContext, parseElement) { @@ -5916,6 +6228,10 @@ var ts; case 18: return ts.Diagnostics.Type_expected; case 19: return ts.Diagnostics.Unexpected_token_expected; case 20: return ts.Diagnostics.Identifier_expected; + case 21: return ts.Diagnostics.Parameter_declaration_expected; + case 22: return ts.Diagnostics.Type_argument_expected; + case 24: return ts.Diagnostics.Type_expected; + case 23: return ts.Diagnostics.Property_assignment_expected; } } ; @@ -6564,11 +6880,6 @@ var ts; nextToken(); return !scanner.hasPrecedingLineBreak() && isIdentifier(); } - function nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine() { - nextToken(); - return !scanner.hasPrecedingLineBreak() && - (isIdentifier() || token === 14 || token === 18); - } function parseYieldExpression() { var node = createNode(173); nextToken(); @@ -6677,10 +6988,11 @@ var ts; if (token === 14) { return parseFunctionBlock(false, false); } - if (isStartOfStatement(true) && - !isStartOfExpressionStatement() && + if (token !== 22 && token !== 83 && - token !== 69) { + token !== 69 && + isStartOfStatement() && + !isStartOfExpressionStatement()) { return parseFunctionBlock(false, true); } return parseAssignmentExpressionOrHigher(); @@ -7323,21 +7635,68 @@ var ts; return finishNode(expressionStatement); } } - function isStartOfStatement(inErrorRecovery) { - if (ts.isModifier(token)) { - var result = lookAhead(parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers); - if (result) { - return true; + function isIdentifierOrKeyword() { + return token >= 65; + } + function nextTokenIsIdentifierOrKeywordOnSameLine() { + nextToken(); + return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak(); + } + function parseDeclarationFlags() { + while (true) { + switch (token) { + case 98: + case 104: + case 70: + case 83: + case 69: + case 77: + return 1; + case 103: + case 124: + nextToken(); + return isIdentifierOrKeyword() ? 1 : 0; + case 117: + case 118: + nextToken(); + return isIdentifierOrKeyword() || token === 8 ? 2 : 0; + case 85: + nextToken(); + return token === 8 || token === 35 || + token === 14 || isIdentifierOrKeyword() ? + 2 : 0; + case 78: + nextToken(); + if (token === 53 || token === 35 || + token === 14 || token === 73) { + return 2; + } + continue; + case 115: + case 108: + case 106: + case 107: + case 109: + nextToken(); + continue; + default: + return 0; } } + } + function getDeclarationFlags() { + return lookAhead(parseDeclarationFlags); + } + function getStatementFlags() { switch (token) { + case 52: case 22: - return !inErrorRecovery; case 14: case 98: case 104: case 83: case 69: + case 77: case 84: case 75: case 100: @@ -7352,50 +7711,67 @@ var ts; case 72: case 68: case 81: - return true; + return 1; case 70: - var isConstEnum = lookAhead(nextTokenIsEnumKeyword); - return !isConstEnum; + case 78: + case 85: + return getDeclarationFlags(); + case 115: case 103: case 117: case 118: - case 77: case 124: - if (isDeclarationStart()) { - return false; - } + return getDeclarationFlags() || 1; case 108: case 106: case 107: case 109: - if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine)) { - return false; - } + return getDeclarationFlags() || + (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine) ? 0 : 1); default: - return isStartOfExpression(); + return isStartOfExpression() ? 1 : 0; } } - function nextTokenIsEnumKeyword() { - nextToken(); - return token === 77; + function isStartOfStatement() { + return (getStatementFlags() & 1) !== 0; } - function nextTokenIsIdentifierOrKeywordOnSameLine() { + function isStartOfModuleElement() { + return (getStatementFlags() & 3) !== 0; + } + function nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine() { nextToken(); - return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak(); + return !scanner.hasPrecedingLineBreak() && + (isIdentifier() || token === 14 || token === 18); + } + function isLetDeclaration() { + return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine); } function parseStatement() { + return parseModuleElementOfKind(1); + } + function parseModuleElement() { + return parseModuleElementOfKind(3); + } + function parseSourceElement() { + return parseModuleElementOfKind(3); + } + function parseModuleElementOfKind(flags) { switch (token) { + case 22: + return parseEmptyStatement(); case 14: return parseBlock(false, false); case 98: - case 70: return parseVariableStatement(scanner.getStartPos(), undefined, undefined); + case 104: + if (isLetDeclaration()) { + return parseVariableStatement(scanner.getStartPos(), undefined, undefined); + } + break; case 83: return parseFunctionDeclaration(scanner.getStartPos(), undefined, undefined); case 69: return parseClassDeclaration(scanner.getStartPos(), undefined, undefined); - case 22: - return parseEmptyStatement(); case 84: return parseIfStatement(); case 75: @@ -7422,44 +7798,66 @@ var ts; return parseTryStatement(); case 72: return parseDebuggerStatement(); - case 104: - if (isLetDeclaration()) { - return parseVariableStatement(scanner.getStartPos(), undefined, undefined); + case 52: + return parseDeclaration(); + case 70: + case 115: + case 77: + case 78: + case 85: + case 103: + case 117: + case 118: + case 106: + case 107: + case 108: + case 109: + case 124: + if (getDeclarationFlags() & flags) { + return parseDeclaration(); } - default: - if (ts.isModifier(token) || token === 52) { - var result = tryParse(parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers); - if (result) { - return result; - } - } - return parseExpressionOrLabeledStatement(); + break; } + return parseExpressionOrLabeledStatement(); } - function parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers() { - var start = scanner.getStartPos(); + function parseDeclaration() { + var fullStart = getNodePos(); var decorators = parseDecorators(); var modifiers = parseModifiers(); switch (token) { - case 70: - var nextTokenIsEnum = lookAhead(nextTokenIsEnumKeyword); - if (nextTokenIsEnum) { - return undefined; - } - return parseVariableStatement(start, decorators, modifiers); - case 104: - if (!isLetDeclaration()) { - return undefined; - } - return parseVariableStatement(start, decorators, modifiers); case 98: - return parseVariableStatement(start, decorators, modifiers); + case 104: + case 70: + return parseVariableStatement(fullStart, decorators, modifiers); case 83: - return parseFunctionDeclaration(start, decorators, modifiers); + return parseFunctionDeclaration(fullStart, decorators, modifiers); case 69: - return parseClassDeclaration(start, decorators, modifiers); + return parseClassDeclaration(fullStart, decorators, modifiers); + case 103: + return parseInterfaceDeclaration(fullStart, decorators, modifiers); + case 124: + return parseTypeAliasDeclaration(fullStart, decorators, modifiers); + case 77: + return parseEnumDeclaration(fullStart, decorators, modifiers); + case 117: + case 118: + return parseModuleDeclaration(fullStart, decorators, modifiers); + case 85: + return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); + case 78: + nextToken(); + return token === 73 || token === 53 ? + parseExportAssignment(fullStart, decorators, modifiers) : + parseExportDeclaration(fullStart, decorators, modifiers); + default: + if (decorators) { + var node = createMissingNode(219, true, ts.Diagnostics.Declaration_expected); + node.pos = fullStart; + node.decorators = decorators; + setModifiers(node, modifiers); + return finishNode(node); + } } - return undefined; } function parseFunctionBlockOrSemicolon(isGenerator, diagnosticMessage) { if (token !== 14 && canParseSemicolon()) { @@ -7603,7 +8001,9 @@ var ts; property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); - property.initializer = allowInAnd(parseNonParameterInitializer); + property.initializer = modifiers && modifiers.flags & 128 + ? allowInAnd(parseNonParameterInitializer) + : doOutsideOfContext(4 | 2, parseNonParameterInitializer); parseSemicolon(); return finishNode(property); } @@ -7749,8 +8149,8 @@ var ts; return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } if (decorators) { - var name_3 = createMissingNode(65, true, ts.Diagnostics.Declaration_expected); - return parsePropertyDeclaration(fullStart, decorators, modifiers, name_3, undefined); + var name_5 = createMissingNode(65, true, ts.Diagnostics.Declaration_expected); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name_5, undefined); } ts.Debug.fail("Should not have attempted to parse class member declaration."); } @@ -8057,125 +8457,6 @@ var ts; parseSemicolon(); return finishNode(node); } - function isLetDeclaration() { - return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine); - } - function isDeclarationStart(followsModifier) { - switch (token) { - case 98: - case 70: - case 83: - return true; - case 104: - return isLetDeclaration(); - case 69: - case 103: - case 77: - case 124: - return lookAhead(nextTokenIsIdentifierOrKeyword); - case 85: - return lookAhead(nextTokenCanFollowImportKeyword); - case 117: - case 118: - return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral); - case 78: - return lookAhead(nextTokenCanFollowExportKeyword); - case 115: - case 108: - case 106: - case 107: - case 109: - return lookAhead(nextTokenIsDeclarationStart); - case 52: - return !followsModifier; - } - } - function isIdentifierOrKeyword() { - return token >= 65; - } - function nextTokenIsIdentifierOrKeyword() { - nextToken(); - return isIdentifierOrKeyword(); - } - function nextTokenIsIdentifierOrKeywordOrStringLiteral() { - nextToken(); - return isIdentifierOrKeyword() || token === 8; - } - function nextTokenCanFollowImportKeyword() { - nextToken(); - return isIdentifierOrKeyword() || token === 8 || - token === 35 || token === 14; - } - function nextTokenCanFollowExportKeyword() { - nextToken(); - return token === 53 || token === 35 || - token === 14 || token === 73 || isDeclarationStart(true); - } - function nextTokenIsDeclarationStart() { - nextToken(); - return isDeclarationStart(true); - } - function nextTokenIsAsKeyword() { - return nextToken() === 111; - } - function parseDeclaration() { - var fullStart = getNodePos(); - var decorators = parseDecorators(); - var modifiers = parseModifiers(); - if (token === 78) { - nextToken(); - if (token === 73 || token === 53) { - return parseExportAssignment(fullStart, decorators, modifiers); - } - if (token === 35 || token === 14) { - return parseExportDeclaration(fullStart, decorators, modifiers); - } - } - switch (token) { - case 98: - case 104: - case 70: - return parseVariableStatement(fullStart, decorators, modifiers); - case 83: - return parseFunctionDeclaration(fullStart, decorators, modifiers); - case 69: - return parseClassDeclaration(fullStart, decorators, modifiers); - case 103: - return parseInterfaceDeclaration(fullStart, decorators, modifiers); - case 124: - return parseTypeAliasDeclaration(fullStart, decorators, modifiers); - case 77: - return parseEnumDeclaration(fullStart, decorators, modifiers); - case 117: - case 118: - return parseModuleDeclaration(fullStart, decorators, modifiers); - case 85: - return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); - default: - if (decorators) { - var node = createMissingNode(219, true, ts.Diagnostics.Declaration_expected); - node.pos = fullStart; - node.decorators = decorators; - setModifiers(node, modifiers); - return finishNode(node); - } - ts.Debug.fail("Mismatch between isDeclarationStart and parseDeclaration"); - } - } - function isSourceElement(inErrorRecovery) { - return isDeclarationStart() || isStartOfStatement(inErrorRecovery); - } - function parseSourceElement() { - return parseSourceElementOrModuleElement(); - } - function parseModuleElement() { - return parseSourceElementOrModuleElement(); - } - function parseSourceElementOrModuleElement() { - return isDeclarationStart() - ? parseDeclaration() - : parseStatement(); - } function processReferenceComments(sourceFile) { var triviaScanner = ts.createScanner(sourceFile.languageVersion, false, sourceText); var referencedFiles = []; @@ -8200,7 +8481,7 @@ var ts; referencedFiles.push(fileReference); } if (diagnosticMessage) { - sourceFile.parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage)); + parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage)); } } else { @@ -8208,7 +8489,7 @@ var ts; var amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment); if (amdModuleNameMatchResult) { if (amdModuleName) { - sourceFile.parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, ts.Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments)); + parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, ts.Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments)); } amdModuleName = amdModuleNameMatchResult[2]; } @@ -8241,6 +8522,514 @@ var ts; : undefined; }); } + var JSDocParser; + (function (JSDocParser) { + function isJSDocType() { + switch (token) { + case 35: + case 50: + case 16: + case 18: + case 46: + case 14: + case 83: + case 21: + case 88: + case 93: + return true; + } + return isIdentifierOrKeyword(); + } + JSDocParser.isJSDocType = isJSDocType; + function parseJSDocTypeExpressionForTests(content, start, length) { + initializeState("file.js", content, 2, undefined); + var jsDocTypeExpression = parseJSDocTypeExpression(start, length); + var diagnostics = parseDiagnostics; + clearState(); + return jsDocTypeExpression ? { jsDocTypeExpression: jsDocTypeExpression, diagnostics: diagnostics } : undefined; + } + JSDocParser.parseJSDocTypeExpressionForTests = parseJSDocTypeExpressionForTests; + function parseJSDocTypeExpression(start, length) { + scanner.setText(sourceText, start, length); + token = nextToken(); + var result = createNode(229); + parseExpected(14); + result.type = parseJSDocTopLevelType(); + parseExpected(15); + fixupParentReferences(result); + return finishNode(result); + } + JSDocParser.parseJSDocTypeExpression = parseJSDocTypeExpression; + function parseJSDocTopLevelType() { + var type = parseJSDocType(); + if (token === 44) { + var unionType = createNode(233, type.pos); + unionType.types = parseJSDocTypeList(type); + type = finishNode(unionType); + } + if (token === 53) { + var optionalType = createNode(240, type.pos); + nextToken(); + optionalType.type = type; + type = finishNode(optionalType); + } + return type; + } + function parseJSDocType() { + var type = parseBasicTypeExpression(); + while (true) { + if (token === 18) { + var arrayType = createNode(232, type.pos); + arrayType.elementType = type; + nextToken(); + parseExpected(19); + type = finishNode(arrayType); + } + else if (token === 50) { + var nullableType = createNode(235, type.pos); + nullableType.type = type; + nextToken(); + type = finishNode(nullableType); + } + else if (token === 46) { + var nonNullableType = createNode(236, type.pos); + nonNullableType.type = type; + nextToken(); + type = finishNode(nonNullableType); + } + else { + break; + } + } + return type; + } + function parseBasicTypeExpression() { + switch (token) { + case 35: + return parseJSDocAllType(); + case 50: + return parseJSDocUnknownOrNullableType(); + case 16: + return parseJSDocUnionType(); + case 18: + return parseJSDocTupleType(); + case 46: + return parseJSDocNonNullableType(); + case 14: + return parseJSDocRecordType(); + case 83: + return parseJSDocFunctionType(); + case 21: + return parseJSDocVariadicType(); + case 88: + return parseJSDocConstructorType(); + case 93: + return parseJSDocThisType(); + case 112: + case 122: + case 120: + case 113: + case 123: + case 99: + return parseTokenNode(); + } + return parseJSDocTypeReference(); + } + function parseJSDocThisType() { + var result = createNode(244); + nextToken(); + parseExpected(51); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocConstructorType() { + var result = createNode(243); + nextToken(); + parseExpected(51); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocVariadicType() { + var result = createNode(242); + nextToken(); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocFunctionType() { + var result = createNode(241); + nextToken(); + parseExpected(16); + result.parameters = parseDelimitedList(21, parseJSDocParameter); + checkForTrailingComma(result.parameters); + parseExpected(17); + if (token === 51) { + nextToken(); + result.type = parseJSDocType(); + } + return finishNode(result); + } + function parseJSDocParameter() { + var parameter = createNode(130); + parameter.type = parseJSDocType(); + return finishNode(parameter); + } + function parseJSDocOptionalType(type) { + var result = createNode(240, type.pos); + nextToken(); + result.type = type; + return finishNode(result); + } + function parseJSDocTypeReference() { + var result = createNode(239); + result.name = parseSimplePropertyName(); + while (parseOptional(20)) { + if (token === 24) { + result.typeArguments = parseTypeArguments(); + break; + } + else { + result.name = parseQualifiedName(result.name); + } + } + return finishNode(result); + } + function parseTypeArguments() { + nextToken(); + var typeArguments = parseDelimitedList(22, parseJSDocType); + checkForTrailingComma(typeArguments); + checkForEmptyTypeArgumentList(typeArguments); + parseExpected(25); + return typeArguments; + } + function checkForEmptyTypeArgumentList(typeArguments) { + if (parseDiagnostics.length === 0 && typeArguments && typeArguments.length === 0) { + var start = typeArguments.pos - "<".length; + var end = ts.skipTrivia(sourceText, typeArguments.end) + ">".length; + return parseErrorAtPosition(start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty); + } + } + function parseQualifiedName(left) { + var result = createNode(127, left.pos); + result.left = left; + result.right = parseIdentifierName(); + return finishNode(result); + } + function parseJSDocRecordType() { + var result = createNode(237); + nextToken(); + result.members = parseDelimitedList(23, parseJSDocRecordMember); + checkForTrailingComma(result.members); + parseExpected(15); + return finishNode(result); + } + function parseJSDocRecordMember() { + var result = createNode(238); + result.name = parseSimplePropertyName(); + if (token === 51) { + nextToken(); + result.type = parseJSDocType(); + } + return finishNode(result); + } + function parseJSDocNonNullableType() { + var result = createNode(236); + nextToken(); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocTupleType() { + var result = createNode(234); + nextToken(); + result.types = parseDelimitedList(24, parseJSDocType); + checkForTrailingComma(result.types); + parseExpected(19); + return finishNode(result); + } + function checkForTrailingComma(list) { + if (parseDiagnostics.length === 0 && list.hasTrailingComma) { + var start = list.end - ",".length; + parseErrorAtPosition(start, ",".length, ts.Diagnostics.Trailing_comma_not_allowed); + } + } + function parseJSDocUnionType() { + var result = createNode(233); + nextToken(); + result.types = parseJSDocTypeList(parseJSDocType()); + parseExpected(17); + return finishNode(result); + } + function parseJSDocTypeList(firstType) { + ts.Debug.assert(!!firstType); + var types = []; + types.pos = firstType.pos; + types.push(firstType); + while (parseOptional(44)) { + types.push(parseJSDocType()); + } + types.end = scanner.getStartPos(); + return types; + } + function parseJSDocAllType() { + var result = createNode(230); + nextToken(); + return finishNode(result); + } + function parseJSDocUnknownOrNullableType() { + var pos = scanner.getStartPos(); + nextToken(); + if (token === 23 || + token === 15 || + token === 17 || + token === 25 || + token === 53 || + token === 44) { + var result = createNode(231, pos); + return finishNode(result); + } + else { + var result = createNode(235, pos); + result.type = parseJSDocType(); + return finishNode(result); + } + } + function parseIsolatedJSDocComment(content, start, length) { + initializeState("file.js", content, 2, undefined); + var jsDocComment = parseJSDocComment(undefined, start, length); + var diagnostics = parseDiagnostics; + clearState(); + return jsDocComment ? { jsDocComment: jsDocComment, diagnostics: diagnostics } : undefined; + } + JSDocParser.parseIsolatedJSDocComment = parseIsolatedJSDocComment; + function parseJSDocComment(parent, start, length) { + var comment = parseJSDocCommentWorker(start, length); + if (comment) { + fixupParentReferences(comment); + comment.parent = parent; + } + return comment; + } + JSDocParser.parseJSDocComment = parseJSDocComment; + function parseJSDocCommentWorker(start, length) { + var content = sourceText; + start = start || 0; + var end = length === undefined ? content.length : start + length; + length = end - start; + ts.Debug.assert(start >= 0); + ts.Debug.assert(start <= end); + ts.Debug.assert(end <= content.length); + var tags; + var pos; + if (length >= "/** */".length) { + if (content.charCodeAt(start) === 47 && + content.charCodeAt(start + 1) === 42 && + content.charCodeAt(start + 2) === 42 && + content.charCodeAt(start + 3) !== 42) { + var canParseTag = true; + var seenAsterisk = true; + for (pos = start + "/**".length; pos < end;) { + var ch = content.charCodeAt(pos); + pos++; + if (ch === 64 && canParseTag) { + parseTag(); + canParseTag = false; + continue; + } + if (ts.isLineBreak(ch)) { + canParseTag = true; + seenAsterisk = false; + continue; + } + if (ts.isWhiteSpace(ch)) { + continue; + } + if (ch === 42) { + if (seenAsterisk) { + canParseTag = false; + } + seenAsterisk = true; + continue; + } + canParseTag = false; + } + } + } + return createJSDocComment(); + function createJSDocComment() { + if (!tags) { + return undefined; + } + var result = createNode(245, start); + result.tags = tags; + return finishNode(result, end); + } + function skipWhitespace() { + while (pos < end && ts.isWhiteSpace(content.charCodeAt(pos))) { + pos++; + } + } + function parseTag() { + ts.Debug.assert(content.charCodeAt(pos - 1) === 64); + var atToken = createNode(52, pos - 1); + atToken.end = pos; + var startPos = pos; + var tagName = scanIdentifier(); + if (!tagName) { + return; + } + var tag = handleTag(atToken, tagName) || handleUnknownTag(atToken, tagName); + addTag(tag); + } + function handleTag(atToken, tagName) { + if (tagName) { + switch (tagName.text) { + case "param": + return handleParamTag(atToken, tagName); + case "return": + case "returns": + return handleReturnTag(atToken, tagName); + case "template": + return handleTemplateTag(atToken, tagName); + case "type": + return handleTypeTag(atToken, tagName); + } + } + return undefined; + } + function handleUnknownTag(atToken, tagName) { + var result = createNode(246, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + return finishNode(result, pos); + } + function addTag(tag) { + if (tag) { + if (!tags) { + tags = []; + tags.pos = tag.pos; + } + tags.push(tag); + tags.end = tag.end; + } + } + function tryParseTypeExpression() { + skipWhitespace(); + if (content.charCodeAt(pos) !== 123) { + return undefined; + } + var typeExpression = parseJSDocTypeExpression(pos, end - pos); + pos = typeExpression.end; + return typeExpression; + } + function handleParamTag(atToken, tagName) { + var typeExpression = tryParseTypeExpression(); + skipWhitespace(); + var name; + var isBracketed; + if (content.charCodeAt(pos) === 91) { + pos++; + skipWhitespace(); + name = scanIdentifier(); + isBracketed = true; + } + else { + name = scanIdentifier(); + } + if (!name) { + parseErrorAtPosition(pos, 0, ts.Diagnostics.Identifier_expected); + return undefined; + } + var preName, postName; + if (typeExpression) { + postName = name; + } + else { + preName = name; + } + if (!typeExpression) { + typeExpression = tryParseTypeExpression(); + } + var result = createNode(247, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.preParameterName = preName; + result.typeExpression = typeExpression; + result.postParameterName = postName; + result.isBracketed = isBracketed; + return finishNode(result, pos); + } + function handleReturnTag(atToken, tagName) { + if (ts.forEach(tags, function (t) { return t.kind === 248; })) { + parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); + } + var result = createNode(248, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.typeExpression = tryParseTypeExpression(); + return finishNode(result, pos); + } + function handleTypeTag(atToken, tagName) { + if (ts.forEach(tags, function (t) { return t.kind === 249; })) { + parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); + } + var result = createNode(249, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.typeExpression = tryParseTypeExpression(); + return finishNode(result, pos); + } + function handleTemplateTag(atToken, tagName) { + if (ts.forEach(tags, function (t) { return t.kind === 250; })) { + parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); + } + var typeParameters = []; + typeParameters.pos = pos; + while (true) { + skipWhitespace(); + var startPos = pos; + var name_6 = scanIdentifier(); + if (!name_6) { + parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); + return undefined; + } + var typeParameter = createNode(129, name_6.pos); + typeParameter.name = name_6; + finishNode(typeParameter, pos); + typeParameters.push(typeParameter); + skipWhitespace(); + if (content.charCodeAt(pos) !== 44) { + break; + } + pos++; + } + typeParameters.end = pos; + var result = createNode(250, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.typeParameters = typeParameters; + return finishNode(result, pos); + } + function scanIdentifier() { + var startPos = pos; + for (; pos < end; pos++) { + var ch = content.charCodeAt(pos); + if (pos === startPos && ts.isIdentifierStart(ch, 2)) { + continue; + } + else if (pos > startPos && ts.isIdentifierPart(ch, 2)) { + continue; + } + break; + } + if (startPos === pos) { + return undefined; + } + var result = createNode(65, startPos); + result.text = content.substring(startPos, pos); + return finishNode(result, pos); + } + } + JSDocParser.parseJSDocCommentWorker = parseJSDocCommentWorker; + })(JSDocParser = Parser.JSDocParser || (Parser.JSDocParser = {})); })(Parser || (Parser = {})); var IncrementalParser; (function (IncrementalParser) { @@ -8281,7 +9070,12 @@ var ts; if (aggressiveChecks && shouldCheckNode(node)) { var text = oldText.substring(node.pos, node.end); } - node._children = undefined; + if (node._children) { + node._children = undefined; + } + if (node.jsDocComment) { + node.jsDocComment = undefined; + } node.pos += delta; node.end += delta; if (aggressiveChecks && shouldCheckNode(node)) { @@ -8597,13 +9391,15 @@ var ts; var undefinedType = createIntrinsicType(32 | 262144, "undefined"); var nullType = createIntrinsicType(64 | 262144, "null"); var unknownType = createIntrinsicType(1, "unknown"); + var circularType = createIntrinsicType(1, "__circular__"); var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + var emptyGenericType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + emptyGenericType.instantiations = {}; var anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); var noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); var anySignature = createSignature(undefined, undefined, emptyArray, anyType, 0, false, false); var unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, false, false); var globals = {}; - var globalArraySymbol; var globalESSymbolConstructorSymbol; var globalObjectType; var globalFunctionType; @@ -8615,6 +9411,8 @@ var ts; var globalTemplateStringsArrayType; var globalESSymbolType; var globalIterableType; + var globalIteratorType; + var globalIterableIteratorType; var anyArrayType; var getGlobalClassDecoratorType; var getGlobalParameterDecoratorType; @@ -8831,7 +9629,13 @@ var ts; loop: while (location) { if (location.locals && !isGlobalSourceFile(location)) { if (result = getSymbol(location.locals, name, meaning)) { - break loop; + if (!(meaning & 793056) || + !(result.flags & (793056 & ~262144)) || + !ts.isFunctionLike(location) || + lastLocation === location.body) { + break loop; + } + result = undefined; } } switch (location.kind) { @@ -8897,27 +9701,31 @@ var ts; case 138: case 201: case 164: - if (name === "arguments") { + if (meaning & 3 && name === "arguments") { result = argumentsSymbol; break loop; } break; case 163: - if (name === "arguments") { + if (meaning & 3 && name === "arguments") { result = argumentsSymbol; break loop; } - var functionName = location.name; - if (functionName && name === functionName.text) { - result = location.symbol; - break loop; + if (meaning & 16) { + var functionName = location.name; + if (functionName && name === functionName.text) { + result = location.symbol; + break loop; + } } break; case 175: - var className = location.name; - if (className && name === className.text) { - result = location.symbol; - break loop; + if (meaning & 32) { + var className = location.name; + if (className && name === className.text) { + result = location.symbol; + break loop; + } } break; case 131: @@ -9063,15 +9871,15 @@ var ts; var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier); if (targetSymbol) { - var name_4 = specifier.propertyName || specifier.name; - if (name_4.text) { - var symbolFromModule = getExportOfModule(targetSymbol, name_4.text); - var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_4.text); + var name_7 = specifier.propertyName || specifier.name; + if (name_7.text) { + var symbolFromModule = getExportOfModule(targetSymbol, name_7.text); + var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_7.text); var symbol = symbolFromModule && symbolFromVariable ? combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - error(name_4, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_4)); + error(name_7, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_7)); } return symbol; } @@ -9130,7 +9938,7 @@ var ts; var symbol = getSymbolOfNode(node); var target = resolveAlias(symbol); if (target) { - var markAlias = (target === unknownSymbol && compilerOptions.separateCompilation) || + var markAlias = (target === unknownSymbol && compilerOptions.isolatedModules) || (target !== unknownSymbol && (target.flags & 107455) && !isConstEnumOrConstEnumOnlyModule(target)); if (markAlias) { markAliasSymbolAsReferenced(symbol); @@ -9719,17 +10527,46 @@ var ts; writeType(types[i], union ? 64 : 0); } } + function writeSymbolTypeReference(symbol, typeArguments, pos, end) { + if (!isReservedMemberName(symbol.name)) { + buildSymbolDisplay(symbol, writer, enclosingDeclaration, 793056); + } + if (pos < end) { + writePunctuation(writer, 24); + writeType(typeArguments[pos++], 0); + while (pos < end) { + writePunctuation(writer, 23); + writeSpace(writer); + writeType(typeArguments[pos++], 0); + } + writePunctuation(writer, 25); + } + } function writeTypeReference(type, flags) { + var typeArguments = type.typeArguments; if (type.target === globalArrayType && !(flags & 1)) { - writeType(type.typeArguments[0], 64); + writeType(typeArguments[0], 64); writePunctuation(writer, 18); writePunctuation(writer, 19); } else { - buildSymbolDisplay(type.target.symbol, writer, enclosingDeclaration, 793056); - writePunctuation(writer, 24); - writeTypeList(type.typeArguments, false); - writePunctuation(writer, 25); + var outerTypeParameters = type.target.outerTypeParameters; + var i = 0; + if (outerTypeParameters) { + var length_1 = outerTypeParameters.length; + while (i < length_1) { + var start = i; + var parent_3 = getParentSymbolOfTypeParameter(outerTypeParameters[i]); + do { + i++; + } while (i < length_1 && getParentSymbolOfTypeParameter(outerTypeParameters[i]) === parent_3); + if (!ts.rangeEquals(outerTypeParameters, typeArguments, start, i)) { + writeSymbolTypeReference(parent_3, typeArguments, start, i); + writePunctuation(writer, 20); + } + } + } + writeSymbolTypeReference(type.symbol, typeArguments, i, typeArguments.length); } } function writeTupleType(type) { @@ -9908,7 +10745,7 @@ var ts; function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) { var targetSymbol = getTargetSymbol(symbol); if (targetSymbol.flags & 32 || targetSymbol.flags & 64) { - buildDisplayForTypeParametersAndDelimiters(getTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); + buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); } } function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { @@ -9922,11 +10759,12 @@ var ts; } } function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { - if (ts.hasDotDotDotToken(p.valueDeclaration)) { + var parameterNode = p.valueDeclaration; + if (ts.isRestParameter(parameterNode)) { writePunctuation(writer, 21); } appendSymbolNameOnly(p, writer); - if (ts.hasQuestionToken(p.valueDeclaration) || p.valueDeclaration.initializer) { + if (isOptionalParameter(parameterNode)) { writePunctuation(writer, 50); } writePunctuation(writer, 51); @@ -10071,12 +10909,12 @@ var ts; case 201: case 205: case 209: - var parent_2 = getDeclarationContainer(node); + var parent_4 = getDeclarationContainer(node); if (!(ts.getCombinedNodeFlags(node) & 1) && - !(node.kind !== 209 && parent_2.kind !== 228 && ts.isInAmbientContext(parent_2))) { - return isGlobalSourceFile(parent_2); + !(node.kind !== 209 && parent_4.kind !== 228 && ts.isInAmbientContext(parent_4))) { + return isGlobalSourceFile(parent_4); } - return isDeclarationVisible(parent_2); + return isDeclarationVisible(parent_4); case 133: case 132: case 137: @@ -10197,12 +11035,12 @@ var ts; } var type; if (pattern.kind === 151) { - var name_5 = declaration.propertyName || declaration.name; - type = getTypeOfPropertyOfType(parentType, name_5.text) || - isNumericLiteralName(name_5.text) && getIndexTypeOfType(parentType, 1) || + var name_8 = declaration.propertyName || declaration.name; + type = getTypeOfPropertyOfType(parentType, name_8.text) || + isNumericLiteralName(name_8.text) && getIndexTypeOfType(parentType, 1) || getIndexTypeOfType(parentType, 0); if (!type) { - error(name_5, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_5)); + error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_8)); return unknownType; } } @@ -10480,26 +11318,55 @@ var ts; return target === checkBase || ts.forEach(getBaseTypes(target), check); } } - function getTypeParametersOfClassOrInterface(symbol) { - var result; - ts.forEach(symbol.declarations, function (node) { - if (node.kind === 203 || node.kind === 202) { - var declaration = node; - if (declaration.typeParameters && declaration.typeParameters.length) { - ts.forEach(declaration.typeParameters, function (node) { - var tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node)); - if (!result) { - result = [tp]; - } - else if (!ts.contains(result, tp)) { - result.push(tp); - } - }); + function appendTypeParameters(typeParameters, declarations) { + for (var _i = 0; _i < declarations.length; _i++) { + var declaration = declarations[_i]; + var tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(declaration)); + if (!typeParameters) { + typeParameters = [tp]; + } + else if (!ts.contains(typeParameters, tp)) { + typeParameters.push(tp); + } + } + return typeParameters; + } + function appendOuterTypeParameters(typeParameters, node) { + while (true) { + node = node.parent; + if (!node) { + return typeParameters; + } + if (node.kind === 202 || node.kind === 201 || + node.kind === 163 || node.kind === 135 || + node.kind === 164) { + var declarations = node.typeParameters; + if (declarations) { + return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations); } } - }); + } + } + function getOuterTypeParametersOfClassOrInterface(symbol) { + var kind = symbol.flags & 32 ? 202 : 203; + return appendOuterTypeParameters(undefined, ts.getDeclarationOfKind(symbol, kind)); + } + function getLocalTypeParametersOfClassOrInterface(symbol) { + var result; + for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { + var node = _a[_i]; + if (node.kind === 203 || node.kind === 202) { + var declaration = node; + if (declaration.typeParameters) { + result = appendTypeParameters(result, declaration.typeParameters); + } + } + } return result; } + function getTypeParametersOfClassOrInterface(symbol) { + return ts.concatenate(getOuterTypeParametersOfClassOrInterface(symbol), getLocalTypeParametersOfClassOrInterface(symbol)); + } function getBaseTypes(type) { var typeWithBaseTypes = type; if (!typeWithBaseTypes.baseTypes) { @@ -10566,10 +11433,13 @@ var ts; if (!links.declaredType) { var kind = symbol.flags & 32 ? 1024 : 2048; var type = links.declaredType = createObjectType(kind, symbol); - var typeParameters = getTypeParametersOfClassOrInterface(symbol); - if (typeParameters) { + var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol); + var localTypeParameters = getLocalTypeParametersOfClassOrInterface(symbol); + if (outerTypeParameters || localTypeParameters) { type.flags |= 4096; - type.typeParameters = typeParameters; + type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters); + type.outerTypeParameters = outerTypeParameters; + type.localTypeParameters = localTypeParameters; type.instantiations = {}; type.instantiations[getTypeListId(type.typeParameters)] = type; type.target = type; @@ -10745,12 +11615,12 @@ var ts; return ts.map(baseSignatures, function (baseSignature) { var signature = baseType.flags & 4096 ? getSignatureInstantiation(baseSignature, baseType.typeArguments) : cloneSignature(baseSignature); - signature.typeParameters = classType.typeParameters; + signature.typeParameters = classType.localTypeParameters; signature.resolvedReturnType = classType; return signature; }); } - return [createSignature(undefined, classType.typeParameters, emptyArray, classType, 0, false, false)]; + return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, 0, false, false)]; } function createTupleTypeMemberSymbols(memberTypes) { var members = {}; @@ -11052,11 +11922,14 @@ var ts; } return result; } + function isOptionalParameter(node) { + return ts.hasQuestionToken(node) || !!node.initializer; + } function getSignatureFromDeclaration(declaration) { var links = getNodeLinks(declaration); if (!links.resolvedSignature) { var classType = declaration.kind === 136 ? getDeclaredTypeOfClassOrInterface(declaration.parent.symbol) : undefined; - var typeParameters = classType ? classType.typeParameters : + var typeParameters = classType ? classType.localTypeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; var parameters = []; var hasStringLiterals = false; @@ -11092,7 +11965,7 @@ var ts; returnType = anyType; } } - links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, minArgumentCount, ts.hasRestParameters(declaration), hasStringLiterals); + links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals); } return links.resolvedSignature; } @@ -11234,6 +12107,9 @@ var ts; } return type.constraint === noConstraintType ? undefined : type.constraint; } + function getParentSymbolOfTypeParameter(typeParameter) { + return getSymbolOfNode(ts.getDeclarationOfKind(typeParameter.symbol, 129).parent); + } function getTypeListId(types) { switch (types.length) { case 1: @@ -11318,23 +12194,7 @@ var ts; type = unknownType; } else { - type = getDeclaredTypeOfSymbol(symbol); - if (type.flags & (1024 | 2048) && type.flags & 4096) { - var typeParameters = type.typeParameters; - if (node.typeArguments && node.typeArguments.length === typeParameters.length) { - type = createTypeReference(type, ts.map(node.typeArguments, getTypeFromTypeNode)); - } - else { - error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, undefined, 1), typeParameters.length); - type = undefined; - } - } - else { - if (node.typeArguments) { - error(node, ts.Diagnostics.Type_0_is_not_generic, typeToString(type)); - type = undefined; - } - } + type = createTypeReferenceIfGeneric(getDeclaredTypeOfSymbol(symbol), node, node.typeArguments); } } } @@ -11342,6 +12202,29 @@ var ts; } return links.resolvedType; } + function createTypeReferenceIfGeneric(type, node, typeArguments) { + if (type.flags & (1024 | 2048) && type.flags & 4096) { + var localTypeParameters = type.localTypeParameters; + var expectedTypeArgCount = localTypeParameters ? localTypeParameters.length : 0; + var typeArgCount = typeArguments ? typeArguments.length : 0; + if (typeArgCount === expectedTypeArgCount) { + if (typeArgCount) { + return createTypeReference(type, ts.concatenate(type.outerTypeParameters, ts.map(typeArguments, getTypeFromTypeNode))); + } + } + else { + error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, undefined, 1), expectedTypeArgCount); + return undefined; + } + } + else { + if (typeArguments) { + error(node, ts.Diagnostics.Type_0_is_not_generic, typeToString(type)); + return undefined; + } + } + return type; + } function getTypeFromTypeQueryNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { @@ -11363,16 +12246,16 @@ var ts; } } if (!symbol) { - return emptyObjectType; + return arity ? emptyGenericType : emptyObjectType; } var type = getDeclaredTypeOfSymbol(symbol); if (!(type.flags & 48128)) { error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name); - return emptyObjectType; + return arity ? emptyGenericType : emptyObjectType; } if ((type.typeParameters ? type.typeParameters.length : 0) !== arity) { error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity); - return emptyObjectType; + return arity ? emptyGenericType : emptyObjectType; } return type; } @@ -11392,12 +12275,17 @@ var ts; function getGlobalESSymbolConstructorSymbol() { return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol")); } + function createTypeFromGenericGlobalType(genericGlobalType, elementType) { + return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, [elementType]) : emptyObjectType; + } function createIterableType(elementType) { - return globalIterableType !== emptyObjectType ? createTypeReference(globalIterableType, [elementType]) : emptyObjectType; + return createTypeFromGenericGlobalType(globalIterableType, elementType); + } + function createIterableIteratorType(elementType) { + return createTypeFromGenericGlobalType(globalIterableIteratorType, elementType); } function createArrayType(elementType) { - var arrayType = globalArrayType || getDeclaredTypeOfSymbol(globalArraySymbol); - return arrayType !== emptyObjectType ? createTypeReference(arrayType, [elementType]) : emptyObjectType; + return createTypeFromGenericGlobalType(globalArrayType, elementType); } function getTypeFromArrayTypeNode(node) { var links = getNodeLinks(node); @@ -11452,13 +12340,7 @@ var ts; } return false; } - var removeSubtypesStack = []; function removeSubtypes(types) { - var typeListId = getTypeListId(types); - if (removeSubtypesStack.lastIndexOf(typeListId) >= 0) { - return; - } - removeSubtypesStack.push(typeListId); var i = types.length; while (i > 0) { i--; @@ -11466,7 +12348,6 @@ var ts; types.splice(i, 1); } } - removeSubtypesStack.pop(); } function containsAnyType(types) { for (var _i = 0; _i < types.length; _i++) { @@ -11516,7 +12397,14 @@ var ts; } function getReducedTypeOfUnionType(type) { if (!type.reducedType) { - type.reducedType = getUnionType(type.types, false); + type.reducedType = circularType; + var reducedType = getUnionType(type.types, false); + if (type.reducedType === circularType) { + type.reducedType = reducedType; + } + } + else if (type.reducedType === circularType) { + type.reducedType = type; } return type.reducedType; } @@ -11700,6 +12588,15 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { + if (mapper.mappings) { + var cached = mapper.mappings[type.id]; + if (cached) { + return cached; + } + } + else { + mapper.mappings = {}; + } var result = createObjectType(32768, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); @@ -11711,6 +12608,7 @@ var ts; result.stringIndexType = instantiateType(stringIndexType, mapper); if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper); + mapper.mappings[type.id] = result; return result; } function instantiateType(type, mapper) { @@ -11719,7 +12617,7 @@ var ts; return mapper(type); } if (type.flags & 32768) { - return type.symbol && type.symbol.flags & (16 | 8192 | 2048 | 4096) ? + return type.symbol && type.symbol.flags & (16 | 8192 | 32 | 2048 | 4096) ? instantiateAnonymousType(type, mapper) : type; } if (type.flags & 4096) { @@ -12896,10 +13794,10 @@ var ts; } function resolveLocation(node) { var containerNodes = []; - for (var parent_3 = node.parent; parent_3; parent_3 = parent_3.parent) { - if ((ts.isExpression(parent_3) || ts.isObjectLiteralMethod(node)) && - isContextSensitive(parent_3)) { - containerNodes.unshift(parent_3); + for (var parent_5 = node.parent; parent_5; parent_5 = parent_5.parent) { + if ((ts.isExpression(parent_5) || ts.isObjectLiteralMethod(node)) && + isContextSensitive(parent_5)) { + containerNodes.unshift(parent_5); } } ts.forEach(containerNodes, function (node) { getTypeOfNode(node); }); @@ -13270,7 +14168,7 @@ var ts; if (isContextSensitive(func)) { var contextualSignature = getContextualSignature(func); if (contextualSignature) { - var funcHasRestParameters = ts.hasRestParameters(func); + var funcHasRestParameters = ts.hasRestParameter(func); var len = func.parameters.length - (funcHasRestParameters ? 1 : 0); var indexOfParameter = ts.indexOf(func.parameters, parameter); if (indexOfParameter < len) { @@ -13304,18 +14202,36 @@ var ts; return undefined; } function getContextualTypeForReturnExpression(node) { + var func = ts.getContainingFunction(node); + if (func && !func.asteriskToken) { + return getContextualReturnType(func); + } + return undefined; + } + function getContextualTypeForYieldOperand(node) { var func = ts.getContainingFunction(node); if (func) { - if (func.type || func.kind === 136 || func.kind === 137 && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(func.symbol, 138))) { - return getReturnTypeOfSignature(getSignatureFromDeclaration(func)); - } - var signature = getContextualSignatureForFunctionLikeDeclaration(func); - if (signature) { - return getReturnTypeOfSignature(signature); + var contextualReturnType = getContextualReturnType(func); + if (contextualReturnType) { + return node.asteriskToken + ? contextualReturnType + : getElementTypeOfIterableIterator(contextualReturnType); } } return undefined; } + function getContextualReturnType(functionDecl) { + if (functionDecl.type || + functionDecl.kind === 136 || + functionDecl.kind === 137 && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(functionDecl.symbol, 138))) { + return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl)); + } + var signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl); + if (signature) { + return getReturnTypeOfSignature(signature); + } + return undefined; + } function getContextualTypeForArgument(callTarget, arg) { var args = getEffectiveCallArguments(callTarget); var argIndex = ts.indexOf(args, arg); @@ -13417,7 +14333,7 @@ var ts; var index = ts.indexOf(arrayLiteral.elements, node); return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, 1) - || (languageVersion >= 2 ? checkIteratedType(type, undefined) : undefined); + || (languageVersion >= 2 ? getElementTypeOfIterable(type, undefined) : undefined); } return undefined; } @@ -13443,6 +14359,8 @@ var ts; case 164: case 192: return getContextualTypeForReturnExpression(node); + case 173: + return getContextualTypeForYieldOperand(parent); case 158: case 159: return getContextualTypeForArgument(parent, node); @@ -13477,7 +14395,9 @@ var ts; return node.kind === 163 || node.kind === 164; } function getContextualSignatureForFunctionLikeDeclaration(node) { - return isFunctionExpressionOrArrowFunction(node) ? getContextualSignature(node) : undefined; + return isFunctionExpressionOrArrowFunction(node) || ts.isObjectLiteralMethod(node) + ? getContextualSignature(node) + : undefined; } function getContextualSignature(node) { ts.Debug.assert(node.kind !== 135 || ts.isObjectLiteralMethod(node)); @@ -13552,7 +14472,7 @@ var ts; if (inDestructuringPattern && e.kind === 174) { var restArrayType = checkExpression(e.expression, contextualMapper); var restElementType = getIndexTypeOfType(restArrayType, 1) || - (languageVersion >= 2 ? checkIteratedType(restArrayType, undefined) : undefined); + (languageVersion >= 2 ? getElementTypeOfIterable(restArrayType, undefined) : undefined); if (restElementType) { elementTypes.push(restElementType); } @@ -13775,15 +14695,15 @@ var ts; return unknownType; } if (node.argumentExpression) { - var name_6 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); - if (name_6 !== undefined) { - var prop = getPropertyOfType(objectType, name_6); + var name_9 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); + if (name_9 !== undefined) { + var prop = getPropertyOfType(objectType, name_9); if (prop) { getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } else if (isConstEnum) { - error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_6, symbolToString(objectType.symbol)); + error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_9, symbolToString(objectType.symbol)); return unknownType; } } @@ -13873,19 +14793,19 @@ var ts; for (var _i = 0; _i < signatures.length; _i++) { var signature = signatures[_i]; var symbol = signature.declaration && getSymbolOfNode(signature.declaration); - var parent_4 = signature.declaration && signature.declaration.parent; + var parent_6 = signature.declaration && signature.declaration.parent; if (!lastSymbol || symbol === lastSymbol) { - if (lastParent && parent_4 === lastParent) { + if (lastParent && parent_6 === lastParent) { index++; } else { - lastParent = parent_4; + lastParent = parent_6; index = cutoffIndex; } } else { index = cutoffIndex = result.length; - lastParent = parent_4; + lastParent = parent_6; } lastSymbol = symbol; if (signature.hasStringLiterals) { @@ -14224,10 +15144,10 @@ var ts; return resolveCall(node, callSignatures, candidatesOutArray); } function resolveNewExpression(node, candidatesOutArray) { - if (node.arguments && languageVersion < 2) { + if (node.arguments && languageVersion < 1) { var spreadIndex = getSpreadArgumentIndex(node.arguments); if (spreadIndex >= 0) { - error(node.arguments[spreadIndex], ts.Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher); + error(node.arguments[spreadIndex], ts.Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher); } } var expressionType = checkExpression(node.expression); @@ -14353,14 +15273,37 @@ var ts; type = checkExpressionCached(func.body, contextualMapper); } else { - var types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); - if (types.length === 0) { - return voidType; + var types; + var funcIsGenerator = !!func.asteriskToken; + if (funcIsGenerator) { + types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); + if (types.length === 0) { + var iterableIteratorAny = createIterableIteratorType(anyType); + if (compilerOptions.noImplicitAny) { + error(func.asteriskToken, ts.Diagnostics.Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type, typeToString(iterableIteratorAny)); + } + return iterableIteratorAny; + } + } + else { + types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); + if (types.length === 0) { + return voidType; + } } type = contextualSignature ? getUnionType(types) : getCommonSupertype(types); if (!type) { - error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions); - return unknownType; + if (funcIsGenerator) { + error(func, ts.Diagnostics.No_best_common_type_exists_among_yield_expressions); + return createIterableIteratorType(unknownType); + } + else { + error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions); + return unknownType; + } + } + if (funcIsGenerator) { + type = createIterableIteratorType(type); } } if (!contextualSignature) { @@ -14368,6 +15311,22 @@ var ts; } return getWidenedType(type); } + function checkAndAggregateYieldOperandTypes(body, contextualMapper) { + var aggregatedTypes = []; + ts.forEachYieldExpression(body, function (yieldExpression) { + var expr = yieldExpression.expression; + if (expr) { + var type = checkExpressionCached(expr, contextualMapper); + if (yieldExpression.asteriskToken) { + type = checkElementTypeOfIterable(type, yieldExpression.expression); + } + if (!ts.contains(aggregatedTypes, type)) { + aggregatedTypes.push(type); + } + } + }); + return aggregatedTypes; + } function checkAndAggregateReturnExpressionTypes(body, contextualMapper) { var aggregatedTypes = []; ts.forEachReturnStatement(body, function (returnStatement) { @@ -14503,8 +15462,8 @@ var ts; var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8) { - var name_7 = index.text; - var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_7); + var name_10 = index.text; + var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_10); return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192) !== 0; } return false; @@ -14635,16 +15594,16 @@ var ts; for (var _i = 0; _i < properties.length; _i++) { var p = properties[_i]; if (p.kind === 225 || p.kind === 226) { - var name_8 = p.name; + var name_11 = p.name; var type = sourceType.flags & 1 ? sourceType : - getTypeOfPropertyOfType(sourceType, name_8.text) || - isNumericLiteralName(name_8.text) && getIndexTypeOfType(sourceType, 1) || + getTypeOfPropertyOfType(sourceType, name_11.text) || + isNumericLiteralName(name_11.text) && getIndexTypeOfType(sourceType, 1) || getIndexTypeOfType(sourceType, 0); if (type) { - checkDestructuringAssignment(p.initializer || name_8, type); + checkDestructuringAssignment(p.initializer || name_11, type); } else { - error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_8)); + error(name_11, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_11)); } } else { @@ -14859,13 +15818,46 @@ var ts; error(node, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(node.operatorToken.kind), typeToString(leftType), typeToString(rightType)); } } + function isYieldExpressionInClass(node) { + var current = node; + var parent = node.parent; + while (parent) { + if (ts.isFunctionLike(parent) && current === parent.body) { + return false; + } + else if (current.kind === 202 || current.kind === 175) { + return true; + } + current = parent; + parent = parent.parent; + } + return false; + } function checkYieldExpression(node) { - if (!(node.parserContextFlags & 4)) { - grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration); + if (!(node.parserContextFlags & 4) || isYieldExpressionInClass(node)) { + grammarErrorOnFirstToken(node, ts.Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body); } - else { - grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expressions_are_not_currently_supported); + if (node.expression) { + var func = ts.getContainingFunction(node); + if (func && func.asteriskToken) { + var expressionType = checkExpressionCached(node.expression, undefined); + var expressionElementType; + var nodeIsYieldStar = !!node.asteriskToken; + if (nodeIsYieldStar) { + expressionElementType = checkElementTypeOfIterable(expressionType, node.expression); + } + if (func.type) { + var signatureElementType = getElementTypeOfIterableIterator(getTypeFromTypeNode(func.type)) || anyType; + if (nodeIsYieldStar) { + checkTypeAssignableTo(expressionElementType, signatureElementType, node.expression, undefined); + } + else { + checkTypeAssignableTo(expressionType, signatureElementType, node.expression, undefined); + } + } + } } + return anyType; } function checkConditionalExpression(node, contextualMapper) { checkExpression(node.condition); @@ -15012,8 +16004,7 @@ var ts; case 176: return undefinedType; case 173: - checkYieldExpression(node); - return unknownType; + return checkYieldExpression(node); } return unknownType; } @@ -15051,6 +16042,14 @@ var ts; error(node, ts.Diagnostics.A_rest_parameter_must_be_of_an_array_type); } } + function isSyntacticallyValidGenerator(node) { + if (!node.asteriskToken || !node.body) { + return false; + } + return node.kind === 135 || + node.kind === 201 || + node.kind === 163; + } function checkSignatureDeclaration(node) { if (node.kind === 141) { checkGrammarIndexSignature(node); @@ -15077,6 +16076,19 @@ var ts; break; } } + if (node.type) { + if (languageVersion >= 2 && isSyntacticallyValidGenerator(node)) { + var returnType = getTypeFromTypeNode(node.type); + if (returnType === voidType) { + error(node.type, ts.Diagnostics.A_generator_cannot_have_a_void_type_annotation); + } + else { + var generatorElementType = getElementTypeOfIterableIterator(returnType) || anyType; + var iterableIteratorInstantiation = createIterableIteratorType(generatorElementType); + checkTypeAssignableTo(iterableIteratorInstantiation, returnType, node.type); + } + } + } } checkSpecializedSignatureDeclaration(node); } @@ -15549,7 +16561,7 @@ var ts; function checkTypeNodeAsExpression(node) { if (node && node.kind === 142) { var type = getTypeFromTypeNode(node); - var shouldCheckIfUnknownType = type === unknownType && compilerOptions.separateCompilation; + var shouldCheckIfUnknownType = type === unknownType && compilerOptions.isolatedModules; if (!type || (!shouldCheckIfUnknownType && type.flags & (1048703 | 132 | 258))) { return; } @@ -15590,6 +16602,9 @@ var ts; if (!ts.nodeCanBeDecorated(node)) { return; } + if (!compilerOptions.experimentalDecorators) { + error(node, ts.Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning); + } if (compilerOptions.emitDecoratorMetadata) { switch (node.kind) { case 202: @@ -15617,7 +16632,6 @@ var ts; function checkFunctionDeclaration(node) { if (produceDiagnostics) { checkFunctionLikeDeclaration(node) || - checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); checkCollisionWithCapturedSuperVariable(node, node.name); @@ -15649,8 +16663,13 @@ var ts; if (node.type && !isAccessor(node.kind) && !node.asteriskToken) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !node.type && !isPrivateWithinAmbient(node)) { - reportImplicitAnyError(node, anyType); + if (produceDiagnostics && !node.type) { + if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !isPrivateWithinAmbient(node)) { + reportImplicitAnyError(node, anyType); + } + if (node.asteriskToken && ts.nodeIsPresent(node.body)) { + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } } } function checkBlock(node) { @@ -15663,7 +16682,7 @@ var ts; } } function checkCollisionWithArgumentsInGeneratedCode(node) { - if (!ts.hasRestParameters(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) { + if (!ts.hasRestParameter(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) { return; } ts.forEach(node.parameters, function (p) { @@ -15771,8 +16790,8 @@ var ts; container.kind === 206 || container.kind === 228); if (!namesShareScope) { - var name_9 = symbolToString(localDeclarationSymbol); - error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_9, name_9); + var name_12 = symbolToString(localDeclarationSymbol); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_12, name_12); } } } @@ -15865,7 +16884,7 @@ var ts; return checkVariableLikeDeclaration(node); } function checkVariableStatement(node) { - checkGrammarDecorators(node) || checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); ts.forEach(node.declarationList.declarations, checkSourceElement); } function checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) { @@ -15988,7 +17007,7 @@ var ts; return inputType; } if (languageVersion >= 2) { - return checkIteratedType(inputType, errorNode) || anyType; + return checkElementTypeOfIterable(inputType, errorNode); } if (allowStringInput) { return checkElementTypeOfArrayOrString(inputType, errorNode); @@ -16002,84 +17021,85 @@ var ts; error(errorNode, ts.Diagnostics.Type_0_is_not_an_array_type, typeToString(inputType)); return unknownType; } - function checkIteratedType(iterable, errorNode) { - ts.Debug.assert(languageVersion >= 2); - var iteratedType = getIteratedType(iterable, errorNode); - if (errorNode && iteratedType) { - checkTypeAssignableTo(iterable, createIterableType(iteratedType), errorNode); + function checkElementTypeOfIterable(iterable, errorNode) { + var elementType = getElementTypeOfIterable(iterable, errorNode); + if (errorNode && elementType) { + checkTypeAssignableTo(iterable, createIterableType(elementType), errorNode); } - return iteratedType; - function getIteratedType(iterable, errorNode) { - // We want to treat type as an iterable, and get the type it is an iterable of. The iterable - // must have the following structure (annotated with the names of the variables below): - // - // { // iterable - // [Symbol.iterator]: { // iteratorFunction - // (): { // iterator - // next: { // iteratorNextFunction - // (): { // iteratorNextResult - // value: T // iteratorNextValue - // } - // } - // } - // } - // } - // - // T is the type we are after. At every level that involves analyzing return types - // of signatures, we union the return types of all the signatures. - // - // Another thing to note is that at any step of this process, we could run into a dead end, - // meaning either the property is missing, or we run into the anyType. If either of these things - // happens, we return undefined to signal that we could not find the iterated type. If a property - // is missing, and the previous step did not result in 'any', then we also give an error if the - // caller requested it. Then the caller can decide what to do in the case where there is no iterated - // type. This is different from returning anyType, because that would signify that we have matched the - // whole pattern and that T (above) is 'any'. - if (allConstituentTypesHaveKind(iterable, 1)) { - return undefined; - } - if ((iterable.flags & 4096) && iterable.target === globalIterableType) { - return iterable.typeArguments[0]; - } - var iteratorFunction = getTypeOfPropertyOfType(iterable, ts.getPropertyNameForKnownSymbolName("iterator")); - if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, 1)) { - return undefined; - } - var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0) : emptyArray; - if (iteratorFunctionSignatures.length === 0) { - if (errorNode) { - error(errorNode, ts.Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator); - } - return undefined; - } - var iterator = getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature)); - if (allConstituentTypesHaveKind(iterator, 1)) { - return undefined; - } - var iteratorNextFunction = getTypeOfPropertyOfType(iterator, "next"); - if (iteratorNextFunction && allConstituentTypesHaveKind(iteratorNextFunction, 1)) { - return undefined; - } - var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0) : emptyArray; - if (iteratorNextFunctionSignatures.length === 0) { - if (errorNode) { - error(errorNode, ts.Diagnostics.An_iterator_must_have_a_next_method); - } - return undefined; - } - var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); - if (allConstituentTypesHaveKind(iteratorNextResult, 1)) { - return undefined; - } - var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); - if (!iteratorNextValue) { - if (errorNode) { - error(errorNode, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property); - } - return undefined; - } - return iteratorNextValue; + return elementType || anyType; + } + function getElementTypeOfIterable(type, errorNode) { + if (type.flags & 1) { + return undefined; } + var typeAsIterable = type; + if (!typeAsIterable.iterableElementType) { + if ((type.flags & 4096) && type.target === globalIterableType) { + typeAsIterable.iterableElementType = type.typeArguments[0]; + } + else { + var iteratorFunction = getTypeOfPropertyOfType(type, ts.getPropertyNameForKnownSymbolName("iterator")); + if (iteratorFunction && iteratorFunction.flags & 1) { + return undefined; + } + var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0) : emptyArray; + if (iteratorFunctionSignatures.length === 0) { + if (errorNode) { + error(errorNode, ts.Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator); + } + return undefined; + } + typeAsIterable.iterableElementType = getElementTypeOfIterator(getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature)), errorNode); + } + } + return typeAsIterable.iterableElementType; + } + function getElementTypeOfIterator(type, errorNode) { + if (type.flags & 1) { + return undefined; + } + var typeAsIterator = type; + if (!typeAsIterator.iteratorElementType) { + if ((type.flags & 4096) && type.target === globalIteratorType) { + typeAsIterator.iteratorElementType = type.typeArguments[0]; + } + else { + var iteratorNextFunction = getTypeOfPropertyOfType(type, "next"); + if (iteratorNextFunction && iteratorNextFunction.flags & 1) { + return undefined; + } + var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0) : emptyArray; + if (iteratorNextFunctionSignatures.length === 0) { + if (errorNode) { + error(errorNode, ts.Diagnostics.An_iterator_must_have_a_next_method); + } + return undefined; + } + var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); + if (iteratorNextResult.flags & 1) { + return undefined; + } + var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); + if (!iteratorNextValue) { + if (errorNode) { + error(errorNode, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property); + } + return undefined; + } + typeAsIterator.iteratorElementType = iteratorNextValue; + } + } + return typeAsIterator.iteratorElementType; + } + function getElementTypeOfIterableIterator(type) { + if (type.flags & 1) { + return undefined; + } + if ((type.flags & 4096) && type.target === globalIterableIteratorType) { + return type.typeArguments[0]; + } + return getElementTypeOfIterable(type, undefined) || + getElementTypeOfIterator(type, undefined); } function checkElementTypeOfArrayOrString(arrayOrStringType, errorNode) { ts.Debug.assert(languageVersion < 2); @@ -16131,19 +17151,20 @@ var ts; if (func) { var returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(func)); var exprType = checkExpressionCached(node.expression); + if (func.asteriskToken) { + return; + } if (func.kind === 138) { error(node.expression, ts.Diagnostics.Setters_cannot_return_a_value); } - else { - if (func.kind === 136) { - if (!isTypeAssignableTo(exprType, returnType)) { - error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); - } - } - else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func)) { - checkTypeAssignableTo(exprType, returnType, node.expression, undefined); + else if (func.kind === 136) { + if (!isTypeAssignableTo(exprType, returnType)) { + error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); } } + else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func)) { + checkTypeAssignableTo(exprType, returnType, node.expression, undefined); + } } } } @@ -16337,9 +17358,6 @@ var ts; } function checkClassDeclaration(node) { checkGrammarDeclarationNameInStrictMode(node); - if (node.parent.kind !== 207 && node.parent.kind !== 228) { - grammarErrorOnNode(node, ts.Diagnostics.class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration); - } if (!node.name && !(node.flags & 256)) { grammarErrorOnFirstToken(node, ts.Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } @@ -16376,7 +17394,7 @@ var ts; checkKindsOfPropertyMemberOverrides(type, baseType); } } - if (baseTypes.length || (baseTypeNode && compilerOptions.separateCompilation)) { + if (baseTypes.length || (baseTypeNode && compilerOptions.isolatedModules)) { checkExpressionOrQualifiedName(baseTypeNode.expression); } var implementedTypeNodes = ts.getClassImplementsHeritageClauseElements(node); @@ -16720,8 +17738,8 @@ var ts; checkExportsOnMergedDeclarations(node); computeEnumMemberValues(node); var enumIsConst = ts.isConst(node); - if (compilerOptions.separateCompilation && enumIsConst && ts.isInAmbientContext(node)) { - error(node.name, ts.Diagnostics.Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided); + if (compilerOptions.isolatedModules && enumIsConst && ts.isInAmbientContext(node)) { + error(node.name, ts.Diagnostics.Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided); } var enumSymbol = getSymbolOfNode(node); var firstDeclaration = ts.getDeclarationOfKind(enumSymbol, node.kind); @@ -16793,7 +17811,7 @@ var ts; if (symbol.flags & 512 && symbol.declarations.length > 1 && !ts.isInAmbientContext(node) - && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.separateCompilation)) { + && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules)) { var firstNonAmbientClassOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); if (firstNonAmbientClassOrFunc) { if (ts.getSourceFileOfNode(node) !== ts.getSourceFileOfNode(firstNonAmbientClassOrFunc)) { @@ -17120,6 +18138,7 @@ var ts; break; case 135: case 134: + ts.forEach(node.decorators, checkFunctionExpressionBodies); ts.forEach(node.parameters, checkFunctionExpressionBodies); if (ts.isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); @@ -17134,6 +18153,7 @@ var ts; case 193: checkFunctionExpressionBodies(node.expression); break; + case 131: case 130: case 133: case 132: @@ -17377,74 +18397,6 @@ var ts; } return node.parent && node.parent.kind === 177; } - function isTypeNode(node) { - if (142 <= node.kind && node.kind <= 150) { - return true; - } - switch (node.kind) { - case 112: - case 120: - case 122: - case 113: - case 123: - return true; - case 99: - return node.parent.kind !== 167; - case 8: - return node.parent.kind === 130; - case 177: - return true; - case 65: - if (node.parent.kind === 127 && node.parent.right === node) { - node = node.parent; - } - else if (node.parent.kind === 156 && node.parent.name === node) { - node = node.parent; - } - case 127: - case 156: - ts.Debug.assert(node.kind === 65 || node.kind === 127 || node.kind === 156, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); - var parent_5 = node.parent; - if (parent_5.kind === 145) { - return false; - } - if (142 <= parent_5.kind && parent_5.kind <= 150) { - return true; - } - switch (parent_5.kind) { - case 177: - return true; - case 129: - return node === parent_5.constraint; - case 133: - case 132: - case 130: - case 199: - return node === parent_5.type; - case 201: - case 163: - case 164: - case 136: - case 135: - case 134: - case 137: - case 138: - return node === parent_5.type; - case 139: - case 140: - case 141: - return node === parent_5.type; - case 161: - return node === parent_5.type; - case 158: - case 159: - return parent_5.typeArguments && ts.indexOf(parent_5.typeArguments, node) >= 0; - case 160: - return false; - } - } - return false; - } function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide) { while (nodeOnRightSide.parent.kind === 127) { nodeOnRightSide = nodeOnRightSide.parent; @@ -17569,7 +18521,7 @@ var ts; if (isInsideWithStatementBody(node)) { return unknownType; } - if (isTypeNode(node)) { + if (ts.isTypeNode(node)) { return getTypeFromTypeNode(node); } if (ts.isExpression(node)) { @@ -17619,9 +18571,9 @@ var ts; function getRootSymbols(symbol) { if (symbol.flags & 268435456) { var symbols = []; - var name_10 = symbol.name; + var name_13 = symbol.name; ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { - symbols.push(getPropertyOfType(t, name_10)); + symbols.push(getPropertyOfType(t, name_13)); }); return symbols; } @@ -17715,7 +18667,7 @@ var ts; } function isAliasResolvedToValue(symbol) { var target = resolveAlias(symbol); - if (target === unknownSymbol && compilerOptions.separateCompilation) { + if (target === unknownSymbol && compilerOptions.isolatedModules) { return true; } return target !== unknownSymbol && target && target.flags & 107455 && !isConstEnumOrConstEnumOnlyModule(target); @@ -17999,8 +18951,7 @@ var ts; getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments"); getSymbolLinks(unknownSymbol).type = unknownType; globals[undefinedSymbol.name] = undefinedSymbol; - globalArraySymbol = getGlobalTypeSymbol("Array"); - globalArrayType = getTypeOfGlobalSymbol(globalArraySymbol, 1); + globalArrayType = getGlobalType("Array", 1); globalObjectType = getGlobalType("Object"); globalFunctionType = getGlobalType("Function"); globalStringType = getGlobalType("String"); @@ -18016,11 +18967,16 @@ var ts; globalESSymbolType = getGlobalType("Symbol"); globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"); globalIterableType = getGlobalType("Iterable", 1); + globalIteratorType = getGlobalType("Iterator", 1); + globalIterableIteratorType = getGlobalType("IterableIterator", 1); } else { globalTemplateStringsArrayType = unknownType; globalESSymbolType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); globalESSymbolConstructorSymbol = undefined; + globalIterableType = emptyGenericType; + globalIteratorType = emptyGenericType; + globalIterableIteratorType = emptyGenericType; } anyArrayType = createArrayType(anyType); } @@ -18040,20 +18996,20 @@ var ts; if (impotClause.namedBindings) { var nameBindings = impotClause.namedBindings; if (nameBindings.kind === 212) { - var name_11 = nameBindings.name; - if (isReservedWordInStrictMode(name_11)) { - var nameText = ts.declarationNameToString(name_11); - return grammarErrorOnNode(name_11, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_14 = nameBindings.name; + if (isReservedWordInStrictMode(name_14)) { + var nameText = ts.declarationNameToString(name_14); + return grammarErrorOnNode(name_14, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } else if (nameBindings.kind === 213) { var reportError = false; for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { var element = _a[_i]; - var name_12 = element.name; - if (isReservedWordInStrictMode(name_12)) { - var nameText = ts.declarationNameToString(name_12); - reportError = reportError || grammarErrorOnNode(name_12, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_15 = element.name; + if (isReservedWordInStrictMode(name_15)) { + var nameText = ts.declarationNameToString(name_15); + reportError = reportError || grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } return reportError; @@ -18151,19 +19107,28 @@ var ts; case 135: case 134: case 141: - case 202: - case 203: case 206: - case 205: - case 181: - case 201: - case 204: case 210: case 209: case 216: case 215: case 130: break; + case 202: + case 203: + case 181: + case 201: + case 204: + if (node.modifiers && node.parent.kind !== 207 && node.parent.kind !== 228) { + return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + } + break; + case 205: + if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 70) && + node.parent.kind !== 207 && node.parent.kind !== 228) { + return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + } + break; default: return false; } @@ -18261,9 +19226,6 @@ var ts; else if ((node.kind === 210 || node.kind === 209) && flags & 2) { return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); } - else if (node.kind === 203 && flags & 2) { - return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); - } else if (node.kind === 130 && (flags & 112) && ts.isBindingPattern(node.name)) { return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); } @@ -18475,7 +19437,18 @@ var ts; } function checkGrammarForGenerator(node) { if (node.asteriskToken) { - return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_currently_supported); + ts.Debug.assert(node.kind === 201 || + node.kind === 163 || + node.kind === 135); + if (ts.isInAmbientContext(node)) { + return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_allowed_in_an_ambient_context); + } + if (!node.body) { + return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.An_overload_signature_cannot_be_declared_as_a_generator); + } + if (languageVersion < 2) { + return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_only_available_when_targeting_ECMAScript_6_or_higher); + } } } function checkGrammarFunctionName(name) { @@ -18495,17 +19468,17 @@ var ts; var inStrictMode = (node.parserContextFlags & 1) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_13 = prop.name; + var name_16 = prop.name; if (prop.kind === 176 || - name_13.kind === 128) { - checkGrammarComputedPropertyName(name_13); + name_16.kind === 128) { + checkGrammarComputedPropertyName(name_16); continue; } var currentKind = void 0; if (prop.kind === 225 || prop.kind === 226) { checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_13.kind === 7) { - checkGrammarNumericLiteral(name_13); + if (name_16.kind === 7) { + checkGrammarNumericLiteral(name_16); } currentKind = Property; } @@ -18521,26 +19494,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_13.text)) { - seen[name_13.text] = currentKind; + if (!ts.hasProperty(seen, name_16.text)) { + seen[name_16.text] = currentKind; } else { - var existingKind = seen[name_13.text]; + var existingKind = seen[name_16.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_13.text] = currentKind | existingKind; + seen[name_16.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -19319,9 +20292,9 @@ var ts; } var count = 0; while (true) { - var name_14 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_14)) { - return name_14; + var name_17 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_17)) { + return name_17; } } } @@ -20405,9 +21378,9 @@ var ts; var count = tempFlags & 268435455; tempFlags++; if (count !== 8 && count !== 13) { - var name_15 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); - if (isUniqueName(name_15)) { - return name_15; + var name_18 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); + if (isUniqueName(name_18)) { + return name_18; } } } @@ -20435,8 +21408,8 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65) { - var name_16 = node.name.text; - assignGeneratedName(node, isUniqueLocalName(name_16, node) ? name_16 : makeUniqueName(name_16)); + var name_19 = node.name.text; + assignGeneratedName(node, isUniqueLocalName(name_19, node) ? name_19 : makeUniqueName(name_19)); } } function generateNameForImportOrExportDeclaration(node) { @@ -20622,8 +21595,8 @@ var ts; if (scopeName) { var parentIndex = getSourceMapNameIndex(); if (parentIndex !== -1) { - var name_17 = node.name; - if (!name_17 || name_17.kind !== 128) { + var name_20 = node.name; + if (!name_20 || name_20.kind !== 128) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -20650,9 +21623,9 @@ var ts; node.kind === 202 || node.kind === 205) { if (node.name) { - var name_18 = node.name; - scopeName = name_18.kind === 128 - ? ts.getTextOfNode(name_18) + var name_21 = node.name; + scopeName = name_21.kind === 128 + ? ts.getTextOfNode(name_21) : node.name.text; } recordScopeNameStart(scopeName); @@ -21273,15 +22246,15 @@ var ts; } return true; } - function emitListWithSpread(elements, alwaysCopy, multiLine, trailingComma) { + function emitListWithSpread(elements, needsUniqueCopy, multiLine, trailingComma, useConcat) { var pos = 0; var group = 0; var length = elements.length; while (pos < length) { - if (group === 1) { + if (group === 1 && useConcat) { write(".concat("); } - else if (group > 1) { + else if (group > 0) { write(", "); } var e = elements[pos]; @@ -21289,7 +22262,7 @@ var ts; e = e.expression; emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); pos++; - if (pos === length && group === 0 && alwaysCopy && e.kind !== 154) { + if (pos === length && group === 0 && needsUniqueCopy && e.kind !== 154) { write(".slice()"); } } @@ -21312,7 +22285,9 @@ var ts; group++; } if (group > 1) { - write(")"); + if (useConcat) { + write(")"); + } } } function isSpreadElementExpression(node) { @@ -21329,7 +22304,7 @@ var ts; write("]"); } else { - emitListWithSpread(elements, true, (node.flags & 512) !== 0, elements.hasTrailingComma); + emitListWithSpread(elements, true, (node.flags & 512) !== 0, elements.hasTrailingComma, true); } } function emitObjectLiteralBody(node, numElements) { @@ -21545,7 +22520,7 @@ var ts; } } function tryEmitConstantValue(node) { - if (compilerOptions.separateCompilation) { + if (compilerOptions.isolatedModules) { return false; } var constantValue = resolver.getConstantValue(node); @@ -21655,7 +22630,7 @@ var ts; write("void 0"); } write(", "); - emitListWithSpread(node.arguments, false, false, false); + emitListWithSpread(node.arguments, false, false, false, true); write(")"); } function emitCallExpression(node) { @@ -21689,11 +22664,25 @@ var ts; } function emitNewExpression(node) { write("new "); - emit(node.expression); - if (node.arguments) { + if (languageVersion === 1 && + node.arguments && + hasSpreadElement(node.arguments)) { write("("); - emitCommaList(node.arguments); - write(")"); + var target = emitCallTarget(node.expression); + write(".bind.apply("); + emit(target); + write(", [void 0].concat("); + emitListWithSpread(node.arguments, false, false, false, false); + write(")))"); + write("()"); + } + else { + emit(node.expression); + if (node.arguments) { + write("("); + emitCommaList(node.arguments); + write(")"); + } } } function emitTaggedTemplateExpression(node) { @@ -22645,15 +23634,30 @@ var ts; ts.forEach(node.declarationList.declarations, emitExportVariableAssignments); } } + function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node) { + if (!(node.flags & 1)) { + return true; + } + if (isES6ExportedDeclaration(node)) { + return true; + } + for (var _a = 0, _b = node.declarationList.declarations; _a < _b.length; _a++) { + var declaration = _b[_a]; + if (declaration.initializer) { + return true; + } + } + return false; + } function emitParameter(node) { if (languageVersion < 2) { if (ts.isBindingPattern(node.name)) { - var name_19 = createTempVariable(0); + var name_22 = createTempVariable(0); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_19); - emit(name_19); + tempParameters.push(name_22); + emit(name_22); } else { emit(node.name); @@ -22700,7 +23704,7 @@ var ts; } } function emitRestParameter(node) { - if (languageVersion < 2 && ts.hasRestParameters(node)) { + if (languageVersion < 2 && ts.hasRestParameter(node)) { var restIndex = node.parameters.length - 1; var restParam = node.parameters[restIndex]; if (ts.isBindingPattern(restParam.name)) { @@ -22808,7 +23812,7 @@ var ts; write("("); if (node) { var parameters = node.parameters; - var omitCount = languageVersion < 2 && ts.hasRestParameters(node) ? 1 : 0; + var omitCount = languageVersion < 2 && ts.hasRestParameter(node) ? 1 : 0; emitList(parameters, 0, parameters.length - omitCount, false, false); } write(")"); @@ -23641,7 +24645,7 @@ var ts; } function shouldEmitEnumDeclaration(node) { var isConstEnum = ts.isConst(node); - return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.separateCompilation; + return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules; } function emitEnumDeclaration(node) { if (!shouldEmitEnumDeclaration(node)) { @@ -23736,7 +24740,7 @@ var ts; } } function shouldEmitModuleDeclaration(node) { - return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.separateCompilation); + return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules); } function isModuleMergedWithES6Class(node) { return languageVersion === 2 && !!(resolver.getNodeCheckFlags(node) & 2048); @@ -24113,8 +25117,8 @@ var ts; else { for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_20 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_20] || (exportSpecifiers[name_20] = [])).push(specifier); + var name_23 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_23] || (exportSpecifiers[name_23] = [])).push(specifier); } } break; @@ -24287,11 +25291,11 @@ var ts; var seen = {}; for (var i = 0; i < hoistedVars.length; ++i) { var local = hoistedVars[i]; - var name_21 = local.kind === 65 + var name_24 = local.kind === 65 ? local : local.name; - if (name_21) { - var text = ts.unescapeIdentifier(name_21.text); + if (name_24) { + var text = ts.unescapeIdentifier(name_24.text); if (ts.hasProperty(seen, text)) { continue; } @@ -24370,15 +25374,15 @@ var ts; } if (node.kind === 199 || node.kind === 153) { if (shouldHoistVariable(node, false)) { - var name_22 = node.name; - if (name_22.kind === 65) { + var name_25 = node.name; + if (name_25.kind === 65) { if (!hoistedVars) { hoistedVars = []; } - hoistedVars.push(name_22); + hoistedVars.push(name_25); } else { - ts.forEachChild(name_22, visit); + ts.forEachChild(name_25, visit); } } return; @@ -24692,7 +25696,7 @@ var ts; paramEmitted = true; } } - if (ts.isExternalModule(node) || compilerOptions.separateCompilation) { + if (ts.isExternalModule(node) || compilerOptions.isolatedModules) { if (languageVersion >= 2) { emitES6Module(node, startIndex); } @@ -24745,6 +25749,8 @@ var ts; case 204: case 215: return false; + case 181: + return shouldEmitLeadingAndTrailingCommentsForVariableStatement(node); case 206: return shouldEmitModuleDeclaration(node); case 205: @@ -25048,7 +26054,7 @@ var ts; ts.emitTime = 0; ts.ioReadTime = 0; ts.ioWriteTime = 0; - ts.version = "1.5.2"; + ts.version = "1.5.3"; var carriageReturnLineFeed = "\r\n"; var lineFeed = "\n"; function findConfigFile(searchPath) { @@ -25470,18 +26476,18 @@ var ts; return allFilesBelongToPath; } function verifyCompilerOptions() { - if (options.separateCompilation) { + if (options.isolatedModules) { if (options.sourceMap) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceMap_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceMap_cannot_be_specified_with_option_isolatedModules)); } if (options.declaration) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_declaration_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_declaration_cannot_be_specified_with_option_isolatedModules)); } if (options.noEmitOnError) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules)); } if (options.out) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_out_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_out_cannot_be_specified_with_option_isolatedModules)); } } if (options.inlineSourceMap) { @@ -25511,14 +26517,14 @@ var ts; } var languageVersion = options.target || 0; var firstExternalModuleSourceFile = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); - if (options.separateCompilation) { + if (options.isolatedModules) { if (!options.module && languageVersion < 2) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); } var firstNonExternalModuleSourceFile = ts.forEach(files, function (f) { return !ts.isExternalModule(f) && !ts.isDeclarationFile(f) ? f : undefined; }); if (firstNonExternalModuleSourceFile) { var span = ts.getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile); - diagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_separateCompilation_flag_is_provided)); + diagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); } } else if (firstExternalModuleSourceFile && languageVersion < 2 && !options.module) { @@ -25550,6 +26556,10 @@ var ts; diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration)); } } + if (options.emitDecoratorMetadata && + !options.experimentalDecorators) { + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified)); + } } } ts.createProgram = createProgram; @@ -25697,7 +26707,7 @@ var ts; paramType: ts.Diagnostics.LOCATION }, { - name: "separateCompilation", + name: "isolatedModules", type: "boolean" }, { @@ -25743,10 +26753,16 @@ var ts; type: "boolean", description: ts.Diagnostics.Watch_input_files }, + { + name: "experimentalDecorators", + type: "boolean", + description: ts.Diagnostics.Enables_experimental_support_for_ES7_decorators + }, { name: "emitDecoratorMetadata", type: "boolean", - experimental: true + experimental: true, + description: ts.Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators } ]; function parseCommandLine(commandLine) { diff --git a/bin/tsserver.js b/bin/tsserver.js index f617ae545f..a6d4dc601d 100644 --- a/bin/tsserver.js +++ b/bin/tsserver.js @@ -145,6 +145,16 @@ var ts; } } ts.addRange = addRange; + function rangeEquals(array1, array2, pos, end) { + while (pos < end) { + if (array1[pos] !== array2[pos]) { + return false; + } + pos++; + } + return true; + } + ts.rangeEquals = rangeEquals; function lastOrUndefined(array) { if (array.length === 0) { return undefined; @@ -301,8 +311,10 @@ var ts; var end = start + length; Debug.assert(start >= 0, "start must be non-negative, is " + start); Debug.assert(length >= 0, "length must be non-negative, is " + length); - Debug.assert(start <= file.text.length, "start must be within the bounds of the file. " + start + " > " + file.text.length); - Debug.assert(end <= file.text.length, "end must be the bounds of the file. " + end + " > " + file.text.length); + if (file) { + Debug.assert(start <= file.text.length, "start must be within the bounds of the file. " + start + " > " + file.text.length); + Debug.assert(end <= file.text.length, "end must be the bounds of the file. " + end + " > " + file.text.length); + } var text = getLocaleSpecificMessage(message.key); if (arguments.length > 4) { text = formatStringFromArgs(text, arguments, 4); @@ -837,7 +849,7 @@ var ts; for (var _i = 0; _i < files.length; _i++) { var current = files[_i]; var name = ts.combinePaths(path, current); - var stat = _fs.lstatSync(name); + var stat = _fs.statSync(name); if (stat.isFile()) { if (!extension || ts.fileExtensionIs(name, extension)) { result.push(name); @@ -1039,7 +1051,7 @@ var ts; Unterminated_template_literal: { code: 1160, category: ts.DiagnosticCategory.Error, key: "Unterminated template literal." }, Unterminated_regular_expression_literal: { code: 1161, category: ts.DiagnosticCategory.Error, key: "Unterminated regular expression literal." }, An_object_member_cannot_be_declared_optional: { code: 1162, category: ts.DiagnosticCategory.Error, key: "An object member cannot be declared optional." }, - yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: ts.DiagnosticCategory.Error, key: "'yield' expression must be contained_within a generator declaration." }, + A_yield_expression_is_only_allowed_in_a_generator_body: { code: 1163, category: ts.DiagnosticCategory.Error, key: "A 'yield' expression is only allowed in a generator body." }, Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: ts.DiagnosticCategory.Error, key: "Computed property names are not allowed in enums." }, A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol: { code: 1165, category: ts.DiagnosticCategory.Error, key: "A computed property name in an ambient context must directly refer to a built-in symbol." }, A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol: { code: 1166, category: ts.DiagnosticCategory.Error, key: "A computed property name in a class property declaration must directly refer to a built-in symbol." }, @@ -1084,8 +1096,8 @@ var ts; Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: ts.DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." }, Decorators_are_not_valid_here: { code: 1206, category: ts.DiagnosticCategory.Error, key: "Decorators are not valid here." }, Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: ts.DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, - Cannot_compile_namespaces_when_the_separateCompilation_flag_is_provided: { code: 1208, category: ts.DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--separateCompilation' flag is provided." }, - Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: ts.DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, + Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided: { code: 1208, category: ts.DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--isolatedModules' flag is provided." }, + Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided: { code: 1209, category: ts.DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--isolatedModules' flag is provided." }, Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." }, A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: ts.DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" }, @@ -1093,6 +1105,11 @@ var ts; Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" }, Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: ts.DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." }, + Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning: { code: 1219, category: ts.DiagnosticCategory.Error, key: "Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning." }, + Generators_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 1220, category: ts.DiagnosticCategory.Error, key: "Generators are only available when targeting ECMAScript 6 or higher." }, + Generators_are_not_allowed_in_an_ambient_context: { code: 1221, category: ts.DiagnosticCategory.Error, key: "Generators are not allowed in an ambient context." }, + An_overload_signature_cannot_be_declared_as_a_generator: { code: 1222, category: ts.DiagnosticCategory.Error, key: "An overload signature cannot be declared as a generator." }, + _0_tag_already_specified: { code: 1223, category: ts.DiagnosticCategory.Error, key: "'{0}' tag already specified." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "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." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -1253,7 +1270,7 @@ var ts; The_0_operator_cannot_be_applied_to_type_symbol: { code: 2469, category: ts.DiagnosticCategory.Error, key: "The '{0}' operator cannot be applied to type 'symbol'." }, Symbol_reference_does_not_refer_to_the_global_Symbol_constructor_object: { code: 2470, category: ts.DiagnosticCategory.Error, key: "'Symbol' reference does not refer to the global Symbol constructor object." }, A_computed_property_name_of_the_form_0_must_be_of_type_symbol: { code: 2471, category: ts.DiagnosticCategory.Error, key: "A computed property name of the form '{0}' must be of type 'symbol'." }, - Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher: { code: 2472, category: ts.DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher." }, + Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher: { code: 2472, category: ts.DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher." }, Enum_declarations_must_all_be_const_or_non_const: { code: 2473, category: ts.DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." }, In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 2474, category: ts.DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression." }, const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment: { code: 2475, category: ts.DiagnosticCategory.Error, key: "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment." }, @@ -1284,6 +1301,8 @@ var ts; A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: ts.DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." }, _0_is_referenced_directly_or_indirectly_in_its_own_type_annotation: { code: 2502, category: ts.DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own type annotation." }, Cannot_find_namespace_0: { code: 2503, category: ts.DiagnosticCategory.Error, key: "Cannot find namespace '{0}'." }, + No_best_common_type_exists_among_yield_expressions: { code: 2504, category: ts.DiagnosticCategory.Error, key: "No best common type exists among yield expressions." }, + A_generator_cannot_have_a_void_type_annotation: { code: 2505, category: ts.DiagnosticCategory.Error, key: "A generator cannot have a 'void' type annotation." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -1368,11 +1387,11 @@ var ts; Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." }, Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." }, Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: ts.DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." }, - Option_sourceMap_cannot_be_specified_with_option_separateCompilation: { code: 5043, category: ts.DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'separateCompilation'." }, - Option_declaration_cannot_be_specified_with_option_separateCompilation: { code: 5044, category: ts.DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'separateCompilation'." }, - Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation: { code: 5045, category: ts.DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'separateCompilation'." }, - Option_out_cannot_be_specified_with_option_separateCompilation: { code: 5046, category: ts.DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'separateCompilation'." }, - Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: ts.DiagnosticCategory.Error, key: "Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." }, + Option_sourceMap_cannot_be_specified_with_option_isolatedModules: { code: 5043, category: ts.DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'isolatedModules'." }, + Option_declaration_cannot_be_specified_with_option_isolatedModules: { code: 5044, category: ts.DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'isolatedModules'." }, + Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules: { code: 5045, category: ts.DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'isolatedModules'." }, + Option_out_cannot_be_specified_with_option_isolatedModules: { code: 5046, category: ts.DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'isolatedModules'." }, + Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: ts.DiagnosticCategory.Error, key: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." }, Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap: { code: 5048, category: ts.DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'inlineSourceMap'." }, Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5049, category: ts.DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'." }, Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5050, category: ts.DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified with option 'inlineSourceMap'." }, @@ -1426,6 +1445,9 @@ var ts; Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: ts.DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." }, NEWLINE: { code: 6061, category: ts.DiagnosticCategory.Message, key: "NEWLINE" }, Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: ts.DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." }, + Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified: { code: 6064, category: ts.DiagnosticCategory.Error, key: "Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified." }, + Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." }, + Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." }, @@ -1441,6 +1463,7 @@ var ts; _0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." }, _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: ts.DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, + Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: ts.DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." }, You_cannot_rename_this_element: { code: 8000, category: ts.DiagnosticCategory.Error, key: "You cannot rename this element." }, You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: ts.DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." }, import_can_only_be_used_in_a_ts_file: { code: 8002, category: ts.DiagnosticCategory.Error, key: "'import ... =' can only be used in a .ts file." }, @@ -1454,16 +1477,12 @@ var ts; types_can_only_be_used_in_a_ts_file: { code: 8010, category: ts.DiagnosticCategory.Error, key: "'types' can only be used in a .ts file." }, type_arguments_can_only_be_used_in_a_ts_file: { code: 8011, category: ts.DiagnosticCategory.Error, key: "'type arguments' can only be used in a .ts file." }, parameter_modifiers_can_only_be_used_in_a_ts_file: { code: 8012, category: ts.DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in a .ts file." }, - can_only_be_used_in_a_ts_file: { code: 8013, category: ts.DiagnosticCategory.Error, key: "'?' can only be used in a .ts file." }, property_declarations_can_only_be_used_in_a_ts_file: { code: 8014, category: ts.DiagnosticCategory.Error, key: "'property declarations' can only be used in a .ts file." }, enum_declarations_can_only_be_used_in_a_ts_file: { code: 8015, category: ts.DiagnosticCategory.Error, key: "'enum declarations' can only be used in a .ts file." }, type_assertion_expressions_can_only_be_used_in_a_ts_file: { code: 8016, category: ts.DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in a .ts file." }, decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: ts.DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." }, - yield_expressions_are_not_currently_supported: { code: 9000, category: ts.DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, - Generators_are_not_currently_supported: { code: 9001, category: ts.DiagnosticCategory.Error, key: "Generators are not currently supported." }, Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: ts.DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." }, - class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." }, - class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration: { code: 9004, category: ts.DiagnosticCategory.Error, key: "'class' declarations are only supported directly inside a module or as a top level declaration." } + class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." } }; })(ts || (ts = {})); /// @@ -2855,7 +2874,7 @@ var ts; paramType: ts.Diagnostics.LOCATION }, { - name: "separateCompilation", + name: "isolatedModules", type: "boolean" }, { @@ -2901,10 +2920,16 @@ var ts; type: "boolean", description: ts.Diagnostics.Watch_input_files }, + { + name: "experimentalDecorators", + type: "boolean", + description: ts.Diagnostics.Enables_experimental_support_for_ES7_decorators + }, { name: "emitDecoratorMetadata", type: "boolean", - experimental: true + experimental: true, + description: ts.Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators } ]; function parseCommandLine(commandLine) { @@ -3145,17 +3170,17 @@ var ts; ts.getFullWidth = getFullWidth; function containsParseError(node) { aggregateChildData(node); - return (node.parserContextFlags & 64) !== 0; + return (node.parserContextFlags & 128) !== 0; } ts.containsParseError = containsParseError; function aggregateChildData(node) { - if (!(node.parserContextFlags & 128)) { + if (!(node.parserContextFlags & 256)) { var thisNodeOrAnySubNodesHasError = ((node.parserContextFlags & 32) !== 0) || ts.forEachChild(node, containsParseError); if (thisNodeOrAnySubNodesHasError) { - node.parserContextFlags |= 64; + node.parserContextFlags |= 128; } - node.parserContextFlags |= 128; + node.parserContextFlags |= 256; } } function getSourceFileOfNode(node) { @@ -3398,6 +3423,75 @@ var ts; } ts.getJsDocComments = getJsDocComments; ts.fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/; + function isTypeNode(node) { + if (142 <= node.kind && node.kind <= 150) { + return true; + } + switch (node.kind) { + case 112: + case 120: + case 122: + case 113: + case 123: + return true; + case 99: + return node.parent.kind !== 167; + case 8: + return node.parent.kind === 130; + case 177: + return true; + case 65: + if (node.parent.kind === 127 && node.parent.right === node) { + node = node.parent; + } + else if (node.parent.kind === 156 && node.parent.name === node) { + node = node.parent; + } + case 127: + case 156: + ts.Debug.assert(node.kind === 65 || node.kind === 127 || node.kind === 156, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); + var parent_1 = node.parent; + if (parent_1.kind === 145) { + return false; + } + if (142 <= parent_1.kind && parent_1.kind <= 150) { + return true; + } + switch (parent_1.kind) { + case 177: + return true; + case 129: + return node === parent_1.constraint; + case 133: + case 132: + case 130: + case 199: + return node === parent_1.type; + case 201: + case 163: + case 164: + case 136: + case 135: + case 134: + case 137: + case 138: + return node === parent_1.type; + case 139: + case 140: + case 141: + return node === parent_1.type; + case 161: + return node === parent_1.type; + case 158: + case 159: + return parent_1.typeArguments && ts.indexOf(parent_1.typeArguments, node) >= 0; + case 160: + return false; + } + } + return false; + } + ts.isTypeNode = isTypeNode; function forEachReturnStatement(body, visitor) { return traverse(body); function traverse(node) { @@ -3424,6 +3518,37 @@ var ts; } } ts.forEachReturnStatement = forEachReturnStatement; + function forEachYieldExpression(body, visitor) { + return traverse(body); + function traverse(node) { + switch (node.kind) { + case 173: + visitor(node); + var operand = node.expression; + if (operand) { + traverse(operand); + } + case 205: + case 203: + case 206: + case 204: + case 202: + return; + default: + if (isFunctionLike(node)) { + var name_3 = node.name; + if (name_3 && name_3.kind === 128) { + traverse(name_3.expression); + return; + } + } + else if (!isTypeNode(node)) { + ts.forEachChild(node, traverse); + } + } + } + } + ts.forEachYieldExpression = forEachYieldExpression; function isVariableLike(node) { if (node) { switch (node.kind) { @@ -3452,6 +3577,12 @@ var ts; return false; } ts.isAccessor = isAccessor; + function isClassLike(node) { + if (node) { + return node.kind === 202 || node.kind === 175; + } + } + ts.isClassLike = isClassLike; function isFunctionLike(node) { if (node) { switch (node.kind) { @@ -3668,6 +3799,7 @@ var ts; case 172: case 10: case 176: + case 173: return true; case 127: while (node.parent.kind === 127) { @@ -3680,8 +3812,8 @@ var ts; } case 7: case 8: - var parent_1 = node.parent; - switch (parent_1.kind) { + var parent_2 = node.parent; + switch (parent_2.kind) { case 199: case 130: case 133: @@ -3689,7 +3821,7 @@ var ts; case 227: case 225: case 153: - return parent_1.initializer === node; + return parent_2.initializer === node; case 183: case 184: case 185: @@ -3700,27 +3832,27 @@ var ts; case 221: case 196: case 194: - return parent_1.expression === node; + return parent_2.expression === node; case 187: - var forStatement = parent_1; + var forStatement = parent_2; return (forStatement.initializer === node && forStatement.initializer.kind !== 200) || forStatement.condition === node || forStatement.incrementor === node; case 188: case 189: - var forInStatement = parent_1; + var forInStatement = parent_2; return (forInStatement.initializer === node && forInStatement.initializer.kind !== 200) || forInStatement.expression === node; case 161: - return node === parent_1.expression; + return node === parent_2.expression; case 178: - return node === parent_1.expression; + return node === parent_2.expression; case 128: - return node === parent_1.expression; + return node === parent_2.expression; case 131: return true; default: - if (isExpression(parent_1)) { + if (isExpression(parent_2)) { return true; } } @@ -3762,10 +3894,6 @@ var ts; } } ts.getExternalModuleName = getExternalModuleName; - function hasDotDotDotToken(node) { - return node && node.kind === 130 && node.dotDotDotToken !== undefined; - } - ts.hasDotDotDotToken = hasDotDotDotToken; function hasQuestionToken(node) { if (node) { switch (node.kind) { @@ -3784,10 +3912,72 @@ var ts; return false; } ts.hasQuestionToken = hasQuestionToken; - function hasRestParameters(s) { - return s.parameters.length > 0 && ts.lastOrUndefined(s.parameters).dotDotDotToken !== undefined; + function isJSDocConstructSignature(node) { + return node.kind === 241 && + node.parameters.length > 0 && + node.parameters[0].type.kind === 243; } - ts.hasRestParameters = hasRestParameters; + ts.isJSDocConstructSignature = isJSDocConstructSignature; + function getJSDocTag(node, kind) { + if (node && node.jsDocComment) { + for (var _i = 0, _a = node.jsDocComment.tags; _i < _a.length; _i++) { + var tag = _a[_i]; + if (tag.kind === kind) { + return tag; + } + } + } + } + function getJSDocTypeTag(node) { + return getJSDocTag(node, 249); + } + ts.getJSDocTypeTag = getJSDocTypeTag; + function getJSDocReturnTag(node) { + return getJSDocTag(node, 248); + } + ts.getJSDocReturnTag = getJSDocReturnTag; + function getJSDocTemplateTag(node) { + return getJSDocTag(node, 250); + } + ts.getJSDocTemplateTag = getJSDocTemplateTag; + function getCorrespondingJSDocParameterTag(parameter) { + if (parameter.name && parameter.name.kind === 65) { + var parameterName = parameter.name.text; + var docComment = parameter.parent.jsDocComment; + if (docComment) { + return ts.forEach(docComment.tags, function (t) { + if (t.kind === 247) { + var parameterTag = t; + var name_4 = parameterTag.preParameterName || parameterTag.postParameterName; + if (name_4.text === parameterName) { + return t; + } + } + }); + } + } + } + ts.getCorrespondingJSDocParameterTag = getCorrespondingJSDocParameterTag; + function hasRestParameter(s) { + return isRestParameter(ts.lastOrUndefined(s.parameters)); + } + ts.hasRestParameter = hasRestParameter; + function isRestParameter(node) { + if (node) { + if (node.parserContextFlags & 64) { + if (node.type && node.type.kind === 242) { + return true; + } + var paramTag = getCorrespondingJSDocParameterTag(node); + if (paramTag && paramTag.typeExpression) { + return paramTag.typeExpression.type.kind === 242; + } + } + return node.dotDotDotToken !== undefined; + } + return false; + } + ts.isRestParameter = isRestParameter; function isLiteralKind(kind) { return 7 <= kind && kind <= 10; } @@ -4295,7 +4485,7 @@ var ts; function shouldEmitToOwnFile(sourceFile, compilerOptions) { if (!isDeclarationFile(sourceFile)) { if ((isExternalModule(sourceFile) || !compilerOptions.out)) { - return compilerOptions.separateCompilation || !ts.fileExtensionIs(sourceFile.fileName, ".js"); + return compilerOptions.isolatedModules || !ts.fileExtensionIs(sourceFile.fileName, ".js"); } return false; } @@ -4511,6 +4701,10 @@ var ts; return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & 256) ? symbol.valueDeclaration.localSymbol : undefined; } ts.getLocalSymbolForExportDefault = getLocalSymbolForExportDefault; + function isJavaScript(fileName) { + return ts.fileExtensionIs(fileName, ".js"); + } + ts.isJavaScript = isJavaScript; function getExpandedCharCodes(input) { var output = []; var length = input.length; @@ -4681,12 +4875,22 @@ var ts; return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); } ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; + function getTypeParameterOwner(d) { + if (d && d.kind === 129) { + for (var current = d; current; current = current.parent) { + if (ts.isFunctionLike(current) || ts.isClassLike(current) || current.kind === 203) { + return current; + } + } + } + } + ts.getTypeParameterOwner = getTypeParameterOwner; })(ts || (ts = {})); /// /// var ts; (function (ts) { - var nodeConstructors = new Array(230); + var nodeConstructors = new Array(252); ts.parseTime = 0; function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); @@ -4989,6 +5193,49 @@ var ts; return visitNode(cbNode, node.expression); case 219: return visitNodes(cbNodes, node.decorators); + case 229: + return visitNode(cbNode, node.type); + case 233: + return visitNodes(cbNodes, node.types); + case 234: + return visitNodes(cbNodes, node.types); + case 232: + return visitNode(cbNode, node.elementType); + case 236: + return visitNode(cbNode, node.type); + case 235: + return visitNode(cbNode, node.type); + case 237: + return visitNodes(cbNodes, node.members); + case 239: + return visitNode(cbNode, node.name) || + visitNodes(cbNodes, node.typeArguments); + case 240: + return visitNode(cbNode, node.type); + case 241: + return visitNodes(cbNodes, node.parameters) || + visitNode(cbNode, node.type); + case 242: + return visitNode(cbNode, node.type); + case 243: + return visitNode(cbNode, node.type); + case 244: + return visitNode(cbNode, node.type); + case 238: + return visitNode(cbNode, node.name) || + visitNode(cbNode, node.type); + case 245: + return visitNodes(cbNodes, node.tags); + case 247: + return visitNode(cbNode, node.preParameterName) || + visitNode(cbNode, node.typeExpression) || + visitNode(cbNode, node.postParameterName); + case 248: + return visitNode(cbNode, node.typeExpression); + case 249: + return visitNode(cbNode, node.typeExpression); + case 250: + return visitNodes(cbNodes, node.typeParameters); } } ts.forEachChild = forEachChild; @@ -5004,11 +5251,20 @@ var ts; return IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks); } ts.updateSourceFile = updateSourceFile; + function parseIsolatedJSDocComment(content, start, length) { + return Parser.JSDocParser.parseIsolatedJSDocComment(content, start, length); + } + ts.parseIsolatedJSDocComment = parseIsolatedJSDocComment; + function parseJSDocTypeExpressionForTests(content, start, length) { + return Parser.JSDocParser.parseJSDocTypeExpressionForTests(content, start, length); + } + ts.parseJSDocTypeExpressionForTests = parseJSDocTypeExpressionForTests; var Parser; (function (Parser) { var scanner = ts.createScanner(2, true); var disallowInAndDecoratorContext = 2 | 16; var sourceFile; + var parseDiagnostics; var syntaxCursor; var token; var sourceText; @@ -5016,21 +5272,40 @@ var ts; var identifiers; var identifierCount; var parsingContext; - var contextFlags = 0; + var contextFlags; var parseErrorBeforeNextFinishedNode = false; function parseSourceFile(fileName, _sourceText, languageVersion, _syntaxCursor, setParentNodes) { + initializeState(fileName, _sourceText, languageVersion, _syntaxCursor); + var result = parseSourceFileWorker(fileName, languageVersion, setParentNodes); + clearState(); + return result; + } + Parser.parseSourceFile = parseSourceFile; + function initializeState(fileName, _sourceText, languageVersion, _syntaxCursor) { sourceText = _sourceText; syntaxCursor = _syntaxCursor; + parseDiagnostics = []; parsingContext = 0; identifiers = {}; identifierCount = 0; nodeCount = 0; - contextFlags = 0; + contextFlags = ts.isJavaScript(fileName) ? 64 : 0; parseErrorBeforeNextFinishedNode = false; - createSourceFile(fileName, languageVersion); scanner.setText(sourceText); scanner.setOnError(scanError); scanner.setScriptTarget(languageVersion); + } + function clearState() { + scanner.setText(""); + scanner.setOnError(undefined); + parseDiagnostics = undefined; + sourceFile = undefined; + identifiers = undefined; + syntaxCursor = undefined; + sourceText = undefined; + } + function parseSourceFileWorker(fileName, languageVersion, setParentNodes) { + sourceFile = createSourceFile(fileName, languageVersion); token = nextToken(); processReferenceComments(sourceFile); sourceFile.statements = parseList(0, true, parseSourceElement); @@ -5040,20 +5315,40 @@ var ts; sourceFile.nodeCount = nodeCount; sourceFile.identifierCount = identifierCount; sourceFile.identifiers = identifiers; + sourceFile.parseDiagnostics = parseDiagnostics; if (setParentNodes) { fixupParentReferences(sourceFile); } - syntaxCursor = undefined; - scanner.setText(""); - scanner.setOnError(undefined); - var result = sourceFile; - sourceFile = undefined; - identifiers = undefined; - syntaxCursor = undefined; - sourceText = undefined; - return result; + if (ts.isJavaScript(fileName)) { + addJSDocComments(); + } + return sourceFile; + } + function addJSDocComments() { + forEachChild(sourceFile, visit); + return; + function visit(node) { + switch (node.kind) { + case 181: + case 201: + case 130: + addJSDocComment(node); + } + forEachChild(node, visit); + } + } + function addJSDocComment(node) { + var comments = ts.getLeadingCommentRangesOfNode(node, sourceFile); + if (comments) { + for (var _i = 0; _i < comments.length; _i++) { + var comment = comments[_i]; + var jsDocComment = JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos); + if (jsDocComment) { + node.jsDocComment = jsDocComment; + } + } + } } - Parser.parseSourceFile = parseSourceFile; function fixupParentReferences(sourceFile) { // normally parent references are set during binding. However, for clients that only need // a syntax tree, and no semantic features, then the binding process is an unnecessary @@ -5072,16 +5367,17 @@ var ts; } } } + Parser.fixupParentReferences = fixupParentReferences; function createSourceFile(fileName, languageVersion) { - sourceFile = createNode(228, 0); + var sourceFile = createNode(228, 0); sourceFile.pos = 0; sourceFile.end = sourceText.length; sourceFile.text = sourceText; - sourceFile.parseDiagnostics = []; sourceFile.bindDiagnostics = []; sourceFile.languageVersion = languageVersion; sourceFile.fileName = ts.normalizePath(fileName); sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 2048 : 0; + return sourceFile; } function setContextFlag(val, flag) { if (val) { @@ -5182,9 +5478,9 @@ var ts; parseErrorAtPosition(start, length, message, arg0); } function parseErrorAtPosition(start, length, message, arg0) { - var lastError = ts.lastOrUndefined(sourceFile.parseDiagnostics); + var lastError = ts.lastOrUndefined(parseDiagnostics); if (!lastError || start !== lastError.start) { - sourceFile.parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, start, length, message, arg0)); + parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, start, length, message, arg0)); } parseErrorBeforeNextFinishedNode = true; } @@ -5215,7 +5511,7 @@ var ts; } function speculationHelper(callback, isLookAhead) { var saveToken = token; - var saveParseDiagnosticsLength = sourceFile.parseDiagnostics.length; + var saveParseDiagnosticsLength = parseDiagnostics.length; var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; var saveContextFlags = contextFlags; var result = isLookAhead @@ -5224,7 +5520,7 @@ var ts; ts.Debug.assert(saveContextFlags === contextFlags); if (!result || isLookAhead) { token = saveToken; - sourceFile.parseDiagnostics.length = saveParseDiagnosticsLength; + parseDiagnostics.length = saveParseDiagnosticsLength; parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode; } return result; @@ -5306,8 +5602,8 @@ var ts; node.end = pos; return node; } - function finishNode(node) { - node.end = scanner.getStartPos(); + function finishNode(node, end) { + node.end = end === undefined ? scanner.getStartPos() : end; if (contextFlags) { node.parserContextFlags = contextFlags; } @@ -5356,15 +5652,24 @@ var ts; token === 8 || token === 7; } - function parsePropertyName() { + function parsePropertyNameWorker(allowComputedPropertyNames) { if (token === 8 || token === 7) { return parseLiteralNode(true); } - if (token === 18) { + if (allowComputedPropertyNames && token === 18) { return parseComputedPropertyName(); } return parseIdentifierName(); } + function parsePropertyName() { + return parsePropertyNameWorker(true); + } + function parseSimplePropertyName() { + return parsePropertyNameWorker(false); + } + function isSimplePropertyName() { + return token === 8 || token === 7 || isIdentifierOrKeyword(); + } function parseComputedPropertyName() { var node = createNode(128); parseExpected(18); @@ -5420,10 +5725,10 @@ var ts; switch (parsingContext) { case 0: case 1: - return isSourceElement(inErrorRecovery); + return !(token === 22 && inErrorRecovery) && isStartOfModuleElement(); case 2: case 4: - return isStartOfStatement(inErrorRecovery); + return !(token === 22 && inErrorRecovery) && isStartOfStatement(); case 3: return token === 67 || token === 73; case 5: @@ -5464,6 +5769,12 @@ var ts; return isHeritageClause(); case 20: return isIdentifierOrKeyword(); + case 21: + case 22: + case 24: + return JSDocParser.isJSDocType(); + case 23: + return isSimplePropertyName(); } ts.Debug.fail("Non-exhaustive case in 'isListElement'."); } @@ -5525,6 +5836,14 @@ var ts; return token === 25 || token === 16; case 19: return token === 14 || token === 15; + case 21: + return token === 17 || token === 51 || token === 15; + case 22: + return token === 25 || token === 15; + case 24: + return token === 19 || token === 15; + case 23: + return token === 15; } } function isVariableDeclaratorListTerminator() { @@ -5540,7 +5859,7 @@ var ts; return false; } function isInSomeParsingContext() { - for (var kind = 0; kind < 21; kind++) { + for (var kind = 0; kind < 25; kind++) { if (parsingContext & (1 << kind)) { if (isListElement(kind, true) || isListTerminator(kind)) { return true; @@ -5561,7 +5880,7 @@ var ts; result.push(element); if (checkForStrictMode && !inStrictModeContext()) { if (ts.isPrologueDirective(element)) { - if (isUseStrictPrologueDirective(sourceFile, element)) { + if (isUseStrictPrologueDirective(element)) { setStrictModeContext(true); checkForStrictMode = false; } @@ -5581,9 +5900,9 @@ var ts; parsingContext = saveParsingContext; return result; } - function isUseStrictPrologueDirective(sourceFile, node) { + function isUseStrictPrologueDirective(node) { ts.Debug.assert(ts.isPrologueDirective(node)); - var nodeText = ts.getSourceTextOfNodeFromSourceFile(sourceFile, node.expression); + var nodeText = ts.getTextOfNodeFromSourceText(sourceText, node.expression); return nodeText === '"use strict"' || nodeText === "'use strict'"; } function parseListElement(parsingContext, parseElement) { @@ -5784,6 +6103,10 @@ var ts; case 18: return ts.Diagnostics.Type_expected; case 19: return ts.Diagnostics.Unexpected_token_expected; case 20: return ts.Diagnostics.Identifier_expected; + case 21: return ts.Diagnostics.Parameter_declaration_expected; + case 22: return ts.Diagnostics.Type_argument_expected; + case 24: return ts.Diagnostics.Type_expected; + case 23: return ts.Diagnostics.Property_assignment_expected; } } ; @@ -6432,11 +6755,6 @@ var ts; nextToken(); return !scanner.hasPrecedingLineBreak() && isIdentifier(); } - function nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine() { - nextToken(); - return !scanner.hasPrecedingLineBreak() && - (isIdentifier() || token === 14 || token === 18); - } function parseYieldExpression() { var node = createNode(173); nextToken(); @@ -6545,10 +6863,11 @@ var ts; if (token === 14) { return parseFunctionBlock(false, false); } - if (isStartOfStatement(true) && - !isStartOfExpressionStatement() && + if (token !== 22 && token !== 83 && - token !== 69) { + token !== 69 && + isStartOfStatement() && + !isStartOfExpressionStatement()) { return parseFunctionBlock(false, true); } return parseAssignmentExpressionOrHigher(); @@ -7191,21 +7510,68 @@ var ts; return finishNode(expressionStatement); } } - function isStartOfStatement(inErrorRecovery) { - if (ts.isModifier(token)) { - var result = lookAhead(parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers); - if (result) { - return true; + function isIdentifierOrKeyword() { + return token >= 65; + } + function nextTokenIsIdentifierOrKeywordOnSameLine() { + nextToken(); + return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak(); + } + function parseDeclarationFlags() { + while (true) { + switch (token) { + case 98: + case 104: + case 70: + case 83: + case 69: + case 77: + return 1; + case 103: + case 124: + nextToken(); + return isIdentifierOrKeyword() ? 1 : 0; + case 117: + case 118: + nextToken(); + return isIdentifierOrKeyword() || token === 8 ? 2 : 0; + case 85: + nextToken(); + return token === 8 || token === 35 || + token === 14 || isIdentifierOrKeyword() ? + 2 : 0; + case 78: + nextToken(); + if (token === 53 || token === 35 || + token === 14 || token === 73) { + return 2; + } + continue; + case 115: + case 108: + case 106: + case 107: + case 109: + nextToken(); + continue; + default: + return 0; } } + } + function getDeclarationFlags() { + return lookAhead(parseDeclarationFlags); + } + function getStatementFlags() { switch (token) { + case 52: case 22: - return !inErrorRecovery; case 14: case 98: case 104: case 83: case 69: + case 77: case 84: case 75: case 100: @@ -7220,50 +7586,67 @@ var ts; case 72: case 68: case 81: - return true; + return 1; case 70: - var isConstEnum = lookAhead(nextTokenIsEnumKeyword); - return !isConstEnum; + case 78: + case 85: + return getDeclarationFlags(); + case 115: case 103: case 117: case 118: - case 77: case 124: - if (isDeclarationStart()) { - return false; - } + return getDeclarationFlags() || 1; case 108: case 106: case 107: case 109: - if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine)) { - return false; - } + return getDeclarationFlags() || + (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine) ? 0 : 1); default: - return isStartOfExpression(); + return isStartOfExpression() ? 1 : 0; } } - function nextTokenIsEnumKeyword() { - nextToken(); - return token === 77; + function isStartOfStatement() { + return (getStatementFlags() & 1) !== 0; } - function nextTokenIsIdentifierOrKeywordOnSameLine() { + function isStartOfModuleElement() { + return (getStatementFlags() & 3) !== 0; + } + function nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine() { nextToken(); - return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak(); + return !scanner.hasPrecedingLineBreak() && + (isIdentifier() || token === 14 || token === 18); + } + function isLetDeclaration() { + return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine); } function parseStatement() { + return parseModuleElementOfKind(1); + } + function parseModuleElement() { + return parseModuleElementOfKind(3); + } + function parseSourceElement() { + return parseModuleElementOfKind(3); + } + function parseModuleElementOfKind(flags) { switch (token) { + case 22: + return parseEmptyStatement(); case 14: return parseBlock(false, false); case 98: - case 70: return parseVariableStatement(scanner.getStartPos(), undefined, undefined); + case 104: + if (isLetDeclaration()) { + return parseVariableStatement(scanner.getStartPos(), undefined, undefined); + } + break; case 83: return parseFunctionDeclaration(scanner.getStartPos(), undefined, undefined); case 69: return parseClassDeclaration(scanner.getStartPos(), undefined, undefined); - case 22: - return parseEmptyStatement(); case 84: return parseIfStatement(); case 75: @@ -7290,44 +7673,66 @@ var ts; return parseTryStatement(); case 72: return parseDebuggerStatement(); - case 104: - if (isLetDeclaration()) { - return parseVariableStatement(scanner.getStartPos(), undefined, undefined); + case 52: + return parseDeclaration(); + case 70: + case 115: + case 77: + case 78: + case 85: + case 103: + case 117: + case 118: + case 106: + case 107: + case 108: + case 109: + case 124: + if (getDeclarationFlags() & flags) { + return parseDeclaration(); } - default: - if (ts.isModifier(token) || token === 52) { - var result = tryParse(parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers); - if (result) { - return result; - } - } - return parseExpressionOrLabeledStatement(); + break; } + return parseExpressionOrLabeledStatement(); } - function parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers() { - var start = scanner.getStartPos(); + function parseDeclaration() { + var fullStart = getNodePos(); var decorators = parseDecorators(); var modifiers = parseModifiers(); switch (token) { - case 70: - var nextTokenIsEnum = lookAhead(nextTokenIsEnumKeyword); - if (nextTokenIsEnum) { - return undefined; - } - return parseVariableStatement(start, decorators, modifiers); - case 104: - if (!isLetDeclaration()) { - return undefined; - } - return parseVariableStatement(start, decorators, modifiers); case 98: - return parseVariableStatement(start, decorators, modifiers); + case 104: + case 70: + return parseVariableStatement(fullStart, decorators, modifiers); case 83: - return parseFunctionDeclaration(start, decorators, modifiers); + return parseFunctionDeclaration(fullStart, decorators, modifiers); case 69: - return parseClassDeclaration(start, decorators, modifiers); + return parseClassDeclaration(fullStart, decorators, modifiers); + case 103: + return parseInterfaceDeclaration(fullStart, decorators, modifiers); + case 124: + return parseTypeAliasDeclaration(fullStart, decorators, modifiers); + case 77: + return parseEnumDeclaration(fullStart, decorators, modifiers); + case 117: + case 118: + return parseModuleDeclaration(fullStart, decorators, modifiers); + case 85: + return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); + case 78: + nextToken(); + return token === 73 || token === 53 ? + parseExportAssignment(fullStart, decorators, modifiers) : + parseExportDeclaration(fullStart, decorators, modifiers); + default: + if (decorators) { + var node = createMissingNode(219, true, ts.Diagnostics.Declaration_expected); + node.pos = fullStart; + node.decorators = decorators; + setModifiers(node, modifiers); + return finishNode(node); + } } - return undefined; } function parseFunctionBlockOrSemicolon(isGenerator, diagnosticMessage) { if (token !== 14 && canParseSemicolon()) { @@ -7471,7 +7876,9 @@ var ts; property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); - property.initializer = allowInAnd(parseNonParameterInitializer); + property.initializer = modifiers && modifiers.flags & 128 + ? allowInAnd(parseNonParameterInitializer) + : doOutsideOfContext(4 | 2, parseNonParameterInitializer); parseSemicolon(); return finishNode(property); } @@ -7617,8 +8024,8 @@ var ts; return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers); } if (decorators) { - var name_3 = createMissingNode(65, true, ts.Diagnostics.Declaration_expected); - return parsePropertyDeclaration(fullStart, decorators, modifiers, name_3, undefined); + var name_5 = createMissingNode(65, true, ts.Diagnostics.Declaration_expected); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name_5, undefined); } ts.Debug.fail("Should not have attempted to parse class member declaration."); } @@ -7925,125 +8332,6 @@ var ts; parseSemicolon(); return finishNode(node); } - function isLetDeclaration() { - return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine); - } - function isDeclarationStart(followsModifier) { - switch (token) { - case 98: - case 70: - case 83: - return true; - case 104: - return isLetDeclaration(); - case 69: - case 103: - case 77: - case 124: - return lookAhead(nextTokenIsIdentifierOrKeyword); - case 85: - return lookAhead(nextTokenCanFollowImportKeyword); - case 117: - case 118: - return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral); - case 78: - return lookAhead(nextTokenCanFollowExportKeyword); - case 115: - case 108: - case 106: - case 107: - case 109: - return lookAhead(nextTokenIsDeclarationStart); - case 52: - return !followsModifier; - } - } - function isIdentifierOrKeyword() { - return token >= 65; - } - function nextTokenIsIdentifierOrKeyword() { - nextToken(); - return isIdentifierOrKeyword(); - } - function nextTokenIsIdentifierOrKeywordOrStringLiteral() { - nextToken(); - return isIdentifierOrKeyword() || token === 8; - } - function nextTokenCanFollowImportKeyword() { - nextToken(); - return isIdentifierOrKeyword() || token === 8 || - token === 35 || token === 14; - } - function nextTokenCanFollowExportKeyword() { - nextToken(); - return token === 53 || token === 35 || - token === 14 || token === 73 || isDeclarationStart(true); - } - function nextTokenIsDeclarationStart() { - nextToken(); - return isDeclarationStart(true); - } - function nextTokenIsAsKeyword() { - return nextToken() === 111; - } - function parseDeclaration() { - var fullStart = getNodePos(); - var decorators = parseDecorators(); - var modifiers = parseModifiers(); - if (token === 78) { - nextToken(); - if (token === 73 || token === 53) { - return parseExportAssignment(fullStart, decorators, modifiers); - } - if (token === 35 || token === 14) { - return parseExportDeclaration(fullStart, decorators, modifiers); - } - } - switch (token) { - case 98: - case 104: - case 70: - return parseVariableStatement(fullStart, decorators, modifiers); - case 83: - return parseFunctionDeclaration(fullStart, decorators, modifiers); - case 69: - return parseClassDeclaration(fullStart, decorators, modifiers); - case 103: - return parseInterfaceDeclaration(fullStart, decorators, modifiers); - case 124: - return parseTypeAliasDeclaration(fullStart, decorators, modifiers); - case 77: - return parseEnumDeclaration(fullStart, decorators, modifiers); - case 117: - case 118: - return parseModuleDeclaration(fullStart, decorators, modifiers); - case 85: - return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); - default: - if (decorators) { - var node = createMissingNode(219, true, ts.Diagnostics.Declaration_expected); - node.pos = fullStart; - node.decorators = decorators; - setModifiers(node, modifiers); - return finishNode(node); - } - ts.Debug.fail("Mismatch between isDeclarationStart and parseDeclaration"); - } - } - function isSourceElement(inErrorRecovery) { - return isDeclarationStart() || isStartOfStatement(inErrorRecovery); - } - function parseSourceElement() { - return parseSourceElementOrModuleElement(); - } - function parseModuleElement() { - return parseSourceElementOrModuleElement(); - } - function parseSourceElementOrModuleElement() { - return isDeclarationStart() - ? parseDeclaration() - : parseStatement(); - } function processReferenceComments(sourceFile) { var triviaScanner = ts.createScanner(sourceFile.languageVersion, false, sourceText); var referencedFiles = []; @@ -8068,7 +8356,7 @@ var ts; referencedFiles.push(fileReference); } if (diagnosticMessage) { - sourceFile.parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage)); + parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage)); } } else { @@ -8076,7 +8364,7 @@ var ts; var amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment); if (amdModuleNameMatchResult) { if (amdModuleName) { - sourceFile.parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, ts.Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments)); + parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, ts.Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments)); } amdModuleName = amdModuleNameMatchResult[2]; } @@ -8109,6 +8397,514 @@ var ts; : undefined; }); } + var JSDocParser; + (function (JSDocParser) { + function isJSDocType() { + switch (token) { + case 35: + case 50: + case 16: + case 18: + case 46: + case 14: + case 83: + case 21: + case 88: + case 93: + return true; + } + return isIdentifierOrKeyword(); + } + JSDocParser.isJSDocType = isJSDocType; + function parseJSDocTypeExpressionForTests(content, start, length) { + initializeState("file.js", content, 2, undefined); + var jsDocTypeExpression = parseJSDocTypeExpression(start, length); + var diagnostics = parseDiagnostics; + clearState(); + return jsDocTypeExpression ? { jsDocTypeExpression: jsDocTypeExpression, diagnostics: diagnostics } : undefined; + } + JSDocParser.parseJSDocTypeExpressionForTests = parseJSDocTypeExpressionForTests; + function parseJSDocTypeExpression(start, length) { + scanner.setText(sourceText, start, length); + token = nextToken(); + var result = createNode(229); + parseExpected(14); + result.type = parseJSDocTopLevelType(); + parseExpected(15); + fixupParentReferences(result); + return finishNode(result); + } + JSDocParser.parseJSDocTypeExpression = parseJSDocTypeExpression; + function parseJSDocTopLevelType() { + var type = parseJSDocType(); + if (token === 44) { + var unionType = createNode(233, type.pos); + unionType.types = parseJSDocTypeList(type); + type = finishNode(unionType); + } + if (token === 53) { + var optionalType = createNode(240, type.pos); + nextToken(); + optionalType.type = type; + type = finishNode(optionalType); + } + return type; + } + function parseJSDocType() { + var type = parseBasicTypeExpression(); + while (true) { + if (token === 18) { + var arrayType = createNode(232, type.pos); + arrayType.elementType = type; + nextToken(); + parseExpected(19); + type = finishNode(arrayType); + } + else if (token === 50) { + var nullableType = createNode(235, type.pos); + nullableType.type = type; + nextToken(); + type = finishNode(nullableType); + } + else if (token === 46) { + var nonNullableType = createNode(236, type.pos); + nonNullableType.type = type; + nextToken(); + type = finishNode(nonNullableType); + } + else { + break; + } + } + return type; + } + function parseBasicTypeExpression() { + switch (token) { + case 35: + return parseJSDocAllType(); + case 50: + return parseJSDocUnknownOrNullableType(); + case 16: + return parseJSDocUnionType(); + case 18: + return parseJSDocTupleType(); + case 46: + return parseJSDocNonNullableType(); + case 14: + return parseJSDocRecordType(); + case 83: + return parseJSDocFunctionType(); + case 21: + return parseJSDocVariadicType(); + case 88: + return parseJSDocConstructorType(); + case 93: + return parseJSDocThisType(); + case 112: + case 122: + case 120: + case 113: + case 123: + case 99: + return parseTokenNode(); + } + return parseJSDocTypeReference(); + } + function parseJSDocThisType() { + var result = createNode(244); + nextToken(); + parseExpected(51); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocConstructorType() { + var result = createNode(243); + nextToken(); + parseExpected(51); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocVariadicType() { + var result = createNode(242); + nextToken(); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocFunctionType() { + var result = createNode(241); + nextToken(); + parseExpected(16); + result.parameters = parseDelimitedList(21, parseJSDocParameter); + checkForTrailingComma(result.parameters); + parseExpected(17); + if (token === 51) { + nextToken(); + result.type = parseJSDocType(); + } + return finishNode(result); + } + function parseJSDocParameter() { + var parameter = createNode(130); + parameter.type = parseJSDocType(); + return finishNode(parameter); + } + function parseJSDocOptionalType(type) { + var result = createNode(240, type.pos); + nextToken(); + result.type = type; + return finishNode(result); + } + function parseJSDocTypeReference() { + var result = createNode(239); + result.name = parseSimplePropertyName(); + while (parseOptional(20)) { + if (token === 24) { + result.typeArguments = parseTypeArguments(); + break; + } + else { + result.name = parseQualifiedName(result.name); + } + } + return finishNode(result); + } + function parseTypeArguments() { + nextToken(); + var typeArguments = parseDelimitedList(22, parseJSDocType); + checkForTrailingComma(typeArguments); + checkForEmptyTypeArgumentList(typeArguments); + parseExpected(25); + return typeArguments; + } + function checkForEmptyTypeArgumentList(typeArguments) { + if (parseDiagnostics.length === 0 && typeArguments && typeArguments.length === 0) { + var start = typeArguments.pos - "<".length; + var end = ts.skipTrivia(sourceText, typeArguments.end) + ">".length; + return parseErrorAtPosition(start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty); + } + } + function parseQualifiedName(left) { + var result = createNode(127, left.pos); + result.left = left; + result.right = parseIdentifierName(); + return finishNode(result); + } + function parseJSDocRecordType() { + var result = createNode(237); + nextToken(); + result.members = parseDelimitedList(23, parseJSDocRecordMember); + checkForTrailingComma(result.members); + parseExpected(15); + return finishNode(result); + } + function parseJSDocRecordMember() { + var result = createNode(238); + result.name = parseSimplePropertyName(); + if (token === 51) { + nextToken(); + result.type = parseJSDocType(); + } + return finishNode(result); + } + function parseJSDocNonNullableType() { + var result = createNode(236); + nextToken(); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocTupleType() { + var result = createNode(234); + nextToken(); + result.types = parseDelimitedList(24, parseJSDocType); + checkForTrailingComma(result.types); + parseExpected(19); + return finishNode(result); + } + function checkForTrailingComma(list) { + if (parseDiagnostics.length === 0 && list.hasTrailingComma) { + var start = list.end - ",".length; + parseErrorAtPosition(start, ",".length, ts.Diagnostics.Trailing_comma_not_allowed); + } + } + function parseJSDocUnionType() { + var result = createNode(233); + nextToken(); + result.types = parseJSDocTypeList(parseJSDocType()); + parseExpected(17); + return finishNode(result); + } + function parseJSDocTypeList(firstType) { + ts.Debug.assert(!!firstType); + var types = []; + types.pos = firstType.pos; + types.push(firstType); + while (parseOptional(44)) { + types.push(parseJSDocType()); + } + types.end = scanner.getStartPos(); + return types; + } + function parseJSDocAllType() { + var result = createNode(230); + nextToken(); + return finishNode(result); + } + function parseJSDocUnknownOrNullableType() { + var pos = scanner.getStartPos(); + nextToken(); + if (token === 23 || + token === 15 || + token === 17 || + token === 25 || + token === 53 || + token === 44) { + var result = createNode(231, pos); + return finishNode(result); + } + else { + var result = createNode(235, pos); + result.type = parseJSDocType(); + return finishNode(result); + } + } + function parseIsolatedJSDocComment(content, start, length) { + initializeState("file.js", content, 2, undefined); + var jsDocComment = parseJSDocComment(undefined, start, length); + var diagnostics = parseDiagnostics; + clearState(); + return jsDocComment ? { jsDocComment: jsDocComment, diagnostics: diagnostics } : undefined; + } + JSDocParser.parseIsolatedJSDocComment = parseIsolatedJSDocComment; + function parseJSDocComment(parent, start, length) { + var comment = parseJSDocCommentWorker(start, length); + if (comment) { + fixupParentReferences(comment); + comment.parent = parent; + } + return comment; + } + JSDocParser.parseJSDocComment = parseJSDocComment; + function parseJSDocCommentWorker(start, length) { + var content = sourceText; + start = start || 0; + var end = length === undefined ? content.length : start + length; + length = end - start; + ts.Debug.assert(start >= 0); + ts.Debug.assert(start <= end); + ts.Debug.assert(end <= content.length); + var tags; + var pos; + if (length >= "/** */".length) { + if (content.charCodeAt(start) === 47 && + content.charCodeAt(start + 1) === 42 && + content.charCodeAt(start + 2) === 42 && + content.charCodeAt(start + 3) !== 42) { + var canParseTag = true; + var seenAsterisk = true; + for (pos = start + "/**".length; pos < end;) { + var ch = content.charCodeAt(pos); + pos++; + if (ch === 64 && canParseTag) { + parseTag(); + canParseTag = false; + continue; + } + if (ts.isLineBreak(ch)) { + canParseTag = true; + seenAsterisk = false; + continue; + } + if (ts.isWhiteSpace(ch)) { + continue; + } + if (ch === 42) { + if (seenAsterisk) { + canParseTag = false; + } + seenAsterisk = true; + continue; + } + canParseTag = false; + } + } + } + return createJSDocComment(); + function createJSDocComment() { + if (!tags) { + return undefined; + } + var result = createNode(245, start); + result.tags = tags; + return finishNode(result, end); + } + function skipWhitespace() { + while (pos < end && ts.isWhiteSpace(content.charCodeAt(pos))) { + pos++; + } + } + function parseTag() { + ts.Debug.assert(content.charCodeAt(pos - 1) === 64); + var atToken = createNode(52, pos - 1); + atToken.end = pos; + var startPos = pos; + var tagName = scanIdentifier(); + if (!tagName) { + return; + } + var tag = handleTag(atToken, tagName) || handleUnknownTag(atToken, tagName); + addTag(tag); + } + function handleTag(atToken, tagName) { + if (tagName) { + switch (tagName.text) { + case "param": + return handleParamTag(atToken, tagName); + case "return": + case "returns": + return handleReturnTag(atToken, tagName); + case "template": + return handleTemplateTag(atToken, tagName); + case "type": + return handleTypeTag(atToken, tagName); + } + } + return undefined; + } + function handleUnknownTag(atToken, tagName) { + var result = createNode(246, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + return finishNode(result, pos); + } + function addTag(tag) { + if (tag) { + if (!tags) { + tags = []; + tags.pos = tag.pos; + } + tags.push(tag); + tags.end = tag.end; + } + } + function tryParseTypeExpression() { + skipWhitespace(); + if (content.charCodeAt(pos) !== 123) { + return undefined; + } + var typeExpression = parseJSDocTypeExpression(pos, end - pos); + pos = typeExpression.end; + return typeExpression; + } + function handleParamTag(atToken, tagName) { + var typeExpression = tryParseTypeExpression(); + skipWhitespace(); + var name; + var isBracketed; + if (content.charCodeAt(pos) === 91) { + pos++; + skipWhitespace(); + name = scanIdentifier(); + isBracketed = true; + } + else { + name = scanIdentifier(); + } + if (!name) { + parseErrorAtPosition(pos, 0, ts.Diagnostics.Identifier_expected); + return undefined; + } + var preName, postName; + if (typeExpression) { + postName = name; + } + else { + preName = name; + } + if (!typeExpression) { + typeExpression = tryParseTypeExpression(); + } + var result = createNode(247, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.preParameterName = preName; + result.typeExpression = typeExpression; + result.postParameterName = postName; + result.isBracketed = isBracketed; + return finishNode(result, pos); + } + function handleReturnTag(atToken, tagName) { + if (ts.forEach(tags, function (t) { return t.kind === 248; })) { + parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); + } + var result = createNode(248, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.typeExpression = tryParseTypeExpression(); + return finishNode(result, pos); + } + function handleTypeTag(atToken, tagName) { + if (ts.forEach(tags, function (t) { return t.kind === 249; })) { + parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); + } + var result = createNode(249, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.typeExpression = tryParseTypeExpression(); + return finishNode(result, pos); + } + function handleTemplateTag(atToken, tagName) { + if (ts.forEach(tags, function (t) { return t.kind === 250; })) { + parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); + } + var typeParameters = []; + typeParameters.pos = pos; + while (true) { + skipWhitespace(); + var startPos = pos; + var name_6 = scanIdentifier(); + if (!name_6) { + parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); + return undefined; + } + var typeParameter = createNode(129, name_6.pos); + typeParameter.name = name_6; + finishNode(typeParameter, pos); + typeParameters.push(typeParameter); + skipWhitespace(); + if (content.charCodeAt(pos) !== 44) { + break; + } + pos++; + } + typeParameters.end = pos; + var result = createNode(250, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.typeParameters = typeParameters; + return finishNode(result, pos); + } + function scanIdentifier() { + var startPos = pos; + for (; pos < end; pos++) { + var ch = content.charCodeAt(pos); + if (pos === startPos && ts.isIdentifierStart(ch, 2)) { + continue; + } + else if (pos > startPos && ts.isIdentifierPart(ch, 2)) { + continue; + } + break; + } + if (startPos === pos) { + return undefined; + } + var result = createNode(65, startPos); + result.text = content.substring(startPos, pos); + return finishNode(result, pos); + } + } + JSDocParser.parseJSDocCommentWorker = parseJSDocCommentWorker; + })(JSDocParser = Parser.JSDocParser || (Parser.JSDocParser = {})); })(Parser || (Parser = {})); var IncrementalParser; (function (IncrementalParser) { @@ -8149,7 +8945,12 @@ var ts; if (aggressiveChecks && shouldCheckNode(node)) { var text = oldText.substring(node.pos, node.end); } - node._children = undefined; + if (node._children) { + node._children = undefined; + } + if (node.jsDocComment) { + node.jsDocComment = undefined; + } node.pos += delta; node.end += delta; if (aggressiveChecks && shouldCheckNode(node)) { @@ -8438,34 +9239,30 @@ var ts; var symbolCount = 0; var Symbol = ts.objectAllocator.getSymbolConstructor(); if (!file.locals) { - file.locals = {}; - container = file; - setBlockScopeContainer(file, false); bind(file); file.symbolCount = symbolCount; } + return; function createSymbol(flags, name) { symbolCount++; return new Symbol(flags, name); } - function setBlockScopeContainer(node, cleanLocals) { - blockScopeContainer = node; - if (cleanLocals) { - blockScopeContainer.locals = undefined; - } - } - function addDeclarationToSymbol(symbol, node, symbolKind) { - symbol.flags |= symbolKind; - if (!symbol.declarations) - symbol.declarations = []; - symbol.declarations.push(node); - if (symbolKind & 1952 && !symbol.exports) - symbol.exports = {}; - if (symbolKind & 6240 && !symbol.members) - symbol.members = {}; + function addDeclarationToSymbol(symbol, node, symbolFlags) { + symbol.flags |= symbolFlags; node.symbol = symbol; - if (symbolKind & 107455 && !symbol.valueDeclaration) + if (!symbol.declarations) { + symbol.declarations = []; + } + symbol.declarations.push(node); + if (symbolFlags & 1952 && !symbol.exports) { + symbol.exports = {}; + } + if (symbolFlags & 6240 && !symbol.members) { + symbol.members = {}; + } + if (symbolFlags & 107455 && !symbol.valueDeclaration) { symbol.valueDeclaration = node; + } } function getDeclarationName(node) { if (node.name) { @@ -8480,12 +9277,12 @@ var ts; return node.name.text; } switch (node.kind) { - case 144: case 136: return "__constructor"; case 143: case 139: return "__call"; + case 144: case 140: return "__new"; case 141: @@ -8502,12 +9299,14 @@ var ts; function getDisplayName(node) { return node.name ? ts.declarationNameToString(node.name) : getDeclarationName(node); } - function declareSymbol(symbols, parent, node, includes, excludes) { + function declareSymbol(symbolTable, parent, node, includes, excludes) { ts.Debug.assert(!ts.hasDynamicName(node)); var name = node.flags & 256 && parent ? "default" : getDeclarationName(node); var symbol; if (name !== undefined) { - symbol = ts.hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name)); + symbol = ts.hasProperty(symbolTable, name) + ? symbolTable[name] + : (symbolTable[name] = createSymbol(0, name)); if (symbol.flags & excludes) { if (node.name) { node.name.parent = node; @@ -8527,79 +9326,115 @@ var ts; } addDeclarationToSymbol(symbol, node, includes); symbol.parent = parent; - if ((node.kind === 202 || node.kind === 175) && symbol.exports) { - var prototypeSymbol = createSymbol(4 | 134217728, "prototype"); - if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) { - if (node.name) { - node.name.parent = node; - } - file.bindDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name)); - } - symbol.exports[prototypeSymbol.name] = prototypeSymbol; - prototypeSymbol.parent = symbol; - } return symbol; } - function declareModuleMember(node, symbolKind, symbolExcludes) { + function declareModuleMember(node, symbolFlags, symbolExcludes) { var hasExportModifier = ts.getCombinedNodeFlags(node) & 1; - if (symbolKind & 8388608) { + if (symbolFlags & 8388608) { if (node.kind === 218 || (node.kind === 209 && hasExportModifier)) { - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); + return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); } else { - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); + return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } else { if (hasExportModifier || container.flags & 65536) { - var exportKind = (symbolKind & 107455 ? 1048576 : 0) | - (symbolKind & 793056 ? 2097152 : 0) | - (symbolKind & 1536 ? 4194304 : 0); + var exportKind = (symbolFlags & 107455 ? 1048576 : 0) | + (symbolFlags & 793056 ? 2097152 : 0) | + (symbolFlags & 1536 ? 4194304 : 0); var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); - local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); + local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); node.localSymbol = local; + return local; } else { - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); + return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } } - function bindChildren(node, symbolKind, isBlockScopeContainer) { - if (symbolKind & 255504) { - node.locals = {}; - } + function bindChildren(node) { var saveParent = parent; var saveContainer = container; var savedBlockScopeContainer = blockScopeContainer; parent = node; - if (symbolKind & 262128) { - container = node; + var containerFlags = getContainerFlags(node); + if (containerFlags & 1) { + container = blockScopeContainer = node; + if (containerFlags & 4) { + container.locals = {}; + } addToContainerChain(container); } - if (isBlockScopeContainer) { - setBlockScopeContainer(node, (symbolKind & 255504) === 0 && node.kind !== 228); + else if (containerFlags & 2) { + blockScopeContainer = node; + blockScopeContainer.locals = undefined; } ts.forEachChild(node, bind); container = saveContainer; parent = saveParent; blockScopeContainer = savedBlockScopeContainer; } - function addToContainerChain(node) { - if (lastContainer) { - lastContainer.nextContainer = node; + function getContainerFlags(node) { + switch (node.kind) { + case 175: + case 202: + case 203: + case 205: + case 146: + case 155: + return 1; + case 139: + case 140: + case 141: + case 135: + case 134: + case 201: + case 136: + case 137: + case 138: + case 143: + case 144: + case 163: + case 164: + case 206: + case 228: + return 5; + case 224: + case 187: + case 188: + case 189: + case 208: + return 2; + case 180: + return ts.isFunctionLike(node.parent) ? 0 : 2; } - lastContainer = node; + return 0; } - function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) { + function addToContainerChain(next) { + if (lastContainer) { + lastContainer.nextContainer = next; + } + lastContainer = next; + } + function declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes) { + declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes); + } + function declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes) { switch (container.kind) { case 206: - declareModuleMember(node, symbolKind, symbolExcludes); - break; + return declareModuleMember(node, symbolFlags, symbolExcludes); case 228: - if (ts.isExternalModule(container)) { - declareModuleMember(node, symbolKind, symbolExcludes); - break; - } + return declareSourceFileMember(node, symbolFlags, symbolExcludes); + case 175: + case 202: + return declareClassMember(node, symbolFlags, symbolExcludes); + case 205: + return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); + case 146: + case 155: + case 203: + return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); case 143: case 144: case 139: @@ -8613,29 +9448,24 @@ var ts; case 201: case 163: case 164: - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); - break; - case 175: - case 202: - if (node.flags & 128) { - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); - break; - } - case 146: - case 155: - case 203: - declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes); - break; - case 205: - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); - break; + return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } - bindChildren(node, symbolKind, isBlockScopeContainer); + } + function declareClassMember(node, symbolFlags, symbolExcludes) { + return node.flags & 128 + ? declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes) + : declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); + } + function declareSourceFileMember(node, symbolFlags, symbolExcludes) { + return ts.isExternalModule(file) + ? declareModuleMember(node, symbolFlags, symbolExcludes) + : declareSymbol(file.locals, undefined, node, symbolFlags, symbolExcludes); } function isAmbientContext(node) { while (node) { - if (node.flags & 2) + if (node.flags & 2) { return true; + } node = node.parent; } return false; @@ -8663,15 +9493,15 @@ var ts; function bindModuleDeclaration(node) { setExportContextFlag(node); if (node.name.kind === 8) { - bindDeclaration(node, 512, 106639, true); + declareSymbolAndAddToSymbolTable(node, 512, 106639); } else { var state = getModuleInstanceState(node); if (state === 0) { - bindDeclaration(node, 1024, 0, true); + declareSymbolAndAddToSymbolTable(node, 1024, 0); } else { - bindDeclaration(node, 512, 106639, true); + declareSymbolAndAddToSymbolTable(node, 512, 106639); var currentModuleIsConstEnumOnly = state === 2; if (node.symbol.constEnumOnlyModule === undefined) { node.symbol.constEnumOnlyModule = currentModuleIsConstEnumOnly; @@ -8683,36 +9513,25 @@ var ts; } } function bindFunctionOrConstructorType(node) { - // For a given function symbol "<...>(...) => T" we want to generate a symbol identical - // to the one we would get for: { <...>(...): T } - // - // We do that by making an anonymous type literal symbol, and then setting the function - // symbol as its sole member. To the rest of the system, this symbol will be indistinguishable - // from an actual type literal symbol you would have gotten had you used the long form. var symbol = createSymbol(131072, getDeclarationName(node)); addDeclarationToSymbol(symbol, node, 131072); - bindChildren(node, 131072, false); var typeLiteralSymbol = createSymbol(2048, "__type"); addDeclarationToSymbol(typeLiteralSymbol, node, 2048); - typeLiteralSymbol.members = {}; - typeLiteralSymbol.members[node.kind === 143 ? "__call" : "__new"] = symbol; + typeLiteralSymbol.members = (_a = {}, _a[symbol.name] = symbol, _a); + var _a; } - function bindAnonymousDeclaration(node, symbolKind, name, isBlockScopeContainer) { - var symbol = createSymbol(symbolKind, name); - addDeclarationToSymbol(symbol, node, symbolKind); - bindChildren(node, symbolKind, isBlockScopeContainer); + function bindAnonymousDeclaration(node, symbolFlags, name) { + var symbol = createSymbol(symbolFlags, name); + addDeclarationToSymbol(symbol, node, symbolFlags); } - function bindCatchVariableDeclaration(node) { - bindChildren(node, 0, true); - } - function bindBlockScopedDeclaration(node, symbolKind, symbolExcludes) { + function bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) { switch (blockScopeContainer.kind) { case 206: - declareModuleMember(node, symbolKind, symbolExcludes); + declareModuleMember(node, symbolFlags, symbolExcludes); break; case 228: if (ts.isExternalModule(container)) { - declareModuleMember(node, symbolKind, symbolExcludes); + declareModuleMember(node, symbolFlags, symbolExcludes); break; } default: @@ -8720,9 +9539,8 @@ var ts; blockScopeContainer.locals = {}; addToContainerChain(blockScopeContainer); } - declareSymbol(blockScopeContainer.locals, undefined, node, symbolKind, symbolExcludes); + declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes); } - bindChildren(node, symbolKind, false); } function bindBlockScopedVariableDeclaration(node) { bindBlockScopedDeclaration(node, 2, 107455); @@ -8732,158 +9550,143 @@ var ts; } function bind(node) { node.parent = parent; + bindWorker(node); + bindChildren(node); + } + function bindWorker(node) { switch (node.kind) { case 129: - bindDeclaration(node, 262144, 530912, false); - break; + return declareSymbolAndAddToSymbolTable(node, 262144, 530912); case 130: - bindParameter(node); - break; + return bindParameter(node); case 199: case 153: - if (ts.isBindingPattern(node.name)) { - bindChildren(node, 0, false); - } - else if (ts.isBlockOrCatchScoped(node)) { - bindBlockScopedVariableDeclaration(node); - } - else if (ts.isParameterDeclaration(node)) { - bindDeclaration(node, 1, 107455, false); - } - else { - bindDeclaration(node, 1, 107454, false); - } - break; + return bindVariableDeclarationOrBindingElement(node); case 133: case 132: - bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455, false); - break; + return bindPropertyOrMethodOrAccessor(node, 4 | (node.questionToken ? 536870912 : 0), 107455); case 225: case 226: - bindPropertyOrMethodOrAccessor(node, 4, 107455, false); - break; + return bindPropertyOrMethodOrAccessor(node, 4, 107455); case 227: - bindPropertyOrMethodOrAccessor(node, 8, 107455, false); - break; + return bindPropertyOrMethodOrAccessor(node, 8, 107455); case 139: case 140: case 141: - bindDeclaration(node, 131072, 0, false); - break; + return declareSymbolAndAddToSymbolTable(node, 131072, 0); case 135: case 134: - bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263, true); - break; + return bindPropertyOrMethodOrAccessor(node, 8192 | (node.questionToken ? 536870912 : 0), ts.isObjectLiteralMethod(node) ? 107455 : 99263); case 201: - bindDeclaration(node, 16, 106927, true); - break; + return declareSymbolAndAddToSymbolTable(node, 16, 106927); case 136: - bindDeclaration(node, 16384, 0, true); - break; + return declareSymbolAndAddToSymbolTable(node, 16384, 0); case 137: - bindPropertyOrMethodOrAccessor(node, 32768, 41919, true); - break; + return bindPropertyOrMethodOrAccessor(node, 32768, 41919); case 138: - bindPropertyOrMethodOrAccessor(node, 65536, 74687, true); - break; + return bindPropertyOrMethodOrAccessor(node, 65536, 74687); case 143: case 144: - bindFunctionOrConstructorType(node); - break; + return bindFunctionOrConstructorType(node); case 146: - bindAnonymousDeclaration(node, 2048, "__type", false); - break; + return bindAnonymousDeclaration(node, 2048, "__type"); case 155: - bindAnonymousDeclaration(node, 4096, "__object", false); - break; + return bindAnonymousDeclaration(node, 4096, "__object"); case 163: case 164: - bindAnonymousDeclaration(node, 16, "__function", true); - break; + return bindAnonymousDeclaration(node, 16, "__function"); case 175: - bindAnonymousDeclaration(node, 32, "__class", false); - break; - case 224: - bindCatchVariableDeclaration(node); - break; case 202: - bindBlockScopedDeclaration(node, 32, 899583); - break; + return bindClassLikeDeclaration(node); case 203: - bindDeclaration(node, 64, 792992, false); - break; + return bindBlockScopedDeclaration(node, 64, 792992); case 204: - bindDeclaration(node, 524288, 793056, false); - break; + return bindBlockScopedDeclaration(node, 524288, 793056); case 205: - if (ts.isConst(node)) { - bindDeclaration(node, 128, 899967, false); - } - else { - bindDeclaration(node, 256, 899327, false); - } - break; + return bindEnumDeclaration(node); case 206: - bindModuleDeclaration(node); - break; + return bindModuleDeclaration(node); case 209: case 212: case 214: case 218: - bindDeclaration(node, 8388608, 8388608, false); - break; + return declareSymbolAndAddToSymbolTable(node, 8388608, 8388608); case 211: - if (node.name) { - bindDeclaration(node, 8388608, 8388608, false); - } - else { - bindChildren(node, 0, false); - } - break; + return bindImportClause(node); case 216: - if (!node.exportClause) { - declareSymbol(container.symbol.exports, container.symbol, node, 1073741824, 0); - } - bindChildren(node, 0, false); - break; + return bindExportDeclaration(node); case 215: - if (node.expression.kind === 65) { - declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608); - } - else { - declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455 | 8388608); - } - bindChildren(node, 0, false); - break; + return bindExportAssignment(node); case 228: - setExportContextFlag(node); - if (ts.isExternalModule(node)) { - bindAnonymousDeclaration(node, 512, '"' + ts.removeFileExtension(node.fileName) + '"', true); - break; - } - case 180: - bindChildren(node, 0, !ts.isFunctionLike(node.parent)); - break; - case 224: - case 187: - case 188: - case 189: - case 208: - bindChildren(node, 0, true); - break; - default: - var saveParent = parent; - parent = node; - ts.forEachChild(node, bind); - parent = saveParent; + return bindSourceFileIfExternalModule(); + } + } + function bindSourceFileIfExternalModule() { + setExportContextFlag(file); + if (ts.isExternalModule(file)) { + bindAnonymousDeclaration(file, 512, '"' + ts.removeFileExtension(file.fileName) + '"'); + } + } + function bindExportAssignment(node) { + if (node.expression.kind === 65) { + declareSymbol(container.symbol.exports, container.symbol, node, 8388608, 107455 | 8388608); + } + else { + declareSymbol(container.symbol.exports, container.symbol, node, 4, 107455 | 8388608); + } + } + function bindExportDeclaration(node) { + if (!node.exportClause) { + declareSymbol(container.symbol.exports, container.symbol, node, 1073741824, 0); + } + } + function bindImportClause(node) { + if (node.name) { + declareSymbolAndAddToSymbolTable(node, 8388608, 8388608); + } + } + function bindClassLikeDeclaration(node) { + if (node.kind === 202) { + bindBlockScopedDeclaration(node, 32, 899583); + } + else { + bindAnonymousDeclaration(node, 32, "__class"); + } + var symbol = node.symbol; + var prototypeSymbol = createSymbol(4 | 134217728, "prototype"); + if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) { + if (node.name) { + node.name.parent = node; + } + file.bindDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name)); + } + symbol.exports[prototypeSymbol.name] = prototypeSymbol; + prototypeSymbol.parent = symbol; + } + function bindEnumDeclaration(node) { + return ts.isConst(node) + ? bindBlockScopedDeclaration(node, 128, 899967) + : bindBlockScopedDeclaration(node, 256, 899327); + } + function bindVariableDeclarationOrBindingElement(node) { + if (!ts.isBindingPattern(node.name)) { + if (ts.isBlockOrCatchScoped(node)) { + bindBlockScopedVariableDeclaration(node); + } + else if (ts.isParameterDeclaration(node)) { + declareSymbolAndAddToSymbolTable(node, 1, 107455); + } + else { + declareSymbolAndAddToSymbolTable(node, 1, 107454); + } } } function bindParameter(node) { if (ts.isBindingPattern(node.name)) { - bindAnonymousDeclaration(node, 1, getDestructuringParameterName(node), false); + bindAnonymousDeclaration(node, 1, getDestructuringParameterName(node)); } else { - bindDeclaration(node, 1, 107455, false); + declareSymbolAndAddToSymbolTable(node, 1, 107455); } if (node.flags & 112 && node.parent.kind === 136 && @@ -8892,13 +9695,10 @@ var ts; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4, 107455); } } - function bindPropertyOrMethodOrAccessor(node, symbolKind, symbolExcludes, isBlockScopeContainer) { - if (ts.hasDynamicName(node)) { - bindAnonymousDeclaration(node, symbolKind, "__computed", isBlockScopeContainer); - } - else { - bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer); - } + function bindPropertyOrMethodOrAccessor(node, symbolFlags, symbolExcludes) { + return ts.hasDynamicName(node) + ? bindAnonymousDeclaration(node, symbolFlags, "__computed") + : declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes); } } })(ts || (ts = {})); @@ -8981,13 +9781,15 @@ var ts; var undefinedType = createIntrinsicType(32 | 262144, "undefined"); var nullType = createIntrinsicType(64 | 262144, "null"); var unknownType = createIntrinsicType(1, "unknown"); + var circularType = createIntrinsicType(1, "__circular__"); var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + var emptyGenericType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + emptyGenericType.instantiations = {}; var anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); var noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); var anySignature = createSignature(undefined, undefined, emptyArray, anyType, 0, false, false); var unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, false, false); var globals = {}; - var globalArraySymbol; var globalESSymbolConstructorSymbol; var globalObjectType; var globalFunctionType; @@ -8999,6 +9801,8 @@ var ts; var globalTemplateStringsArrayType; var globalESSymbolType; var globalIterableType; + var globalIteratorType; + var globalIterableIteratorType; var anyArrayType; var getGlobalClassDecoratorType; var getGlobalParameterDecoratorType; @@ -9215,7 +10019,13 @@ var ts; loop: while (location) { if (location.locals && !isGlobalSourceFile(location)) { if (result = getSymbol(location.locals, name, meaning)) { - break loop; + if (!(meaning & 793056) || + !(result.flags & (793056 & ~262144)) || + !ts.isFunctionLike(location) || + lastLocation === location.body) { + break loop; + } + result = undefined; } } switch (location.kind) { @@ -9281,27 +10091,31 @@ var ts; case 138: case 201: case 164: - if (name === "arguments") { + if (meaning & 3 && name === "arguments") { result = argumentsSymbol; break loop; } break; case 163: - if (name === "arguments") { + if (meaning & 3 && name === "arguments") { result = argumentsSymbol; break loop; } - var functionName = location.name; - if (functionName && name === functionName.text) { - result = location.symbol; - break loop; + if (meaning & 16) { + var functionName = location.name; + if (functionName && name === functionName.text) { + result = location.symbol; + break loop; + } } break; case 175: - var className = location.name; - if (className && name === className.text) { - result = location.symbol; - break loop; + if (meaning & 32) { + var className = location.name; + if (className && name === className.text) { + result = location.symbol; + break loop; + } } break; case 131: @@ -9447,15 +10261,15 @@ var ts; var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier); if (targetSymbol) { - var name_4 = specifier.propertyName || specifier.name; - if (name_4.text) { - var symbolFromModule = getExportOfModule(targetSymbol, name_4.text); - var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_4.text); + var name_7 = specifier.propertyName || specifier.name; + if (name_7.text) { + var symbolFromModule = getExportOfModule(targetSymbol, name_7.text); + var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_7.text); var symbol = symbolFromModule && symbolFromVariable ? combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - error(name_4, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_4)); + error(name_7, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_7)); } return symbol; } @@ -9514,7 +10328,7 @@ var ts; var symbol = getSymbolOfNode(node); var target = resolveAlias(symbol); if (target) { - var markAlias = (target === unknownSymbol && compilerOptions.separateCompilation) || + var markAlias = (target === unknownSymbol && compilerOptions.isolatedModules) || (target !== unknownSymbol && (target.flags & 107455) && !isConstEnumOrConstEnumOnlyModule(target)); if (markAlias) { markAliasSymbolAsReferenced(symbol); @@ -10103,17 +10917,46 @@ var ts; writeType(types[i], union ? 64 : 0); } } + function writeSymbolTypeReference(symbol, typeArguments, pos, end) { + if (!isReservedMemberName(symbol.name)) { + buildSymbolDisplay(symbol, writer, enclosingDeclaration, 793056); + } + if (pos < end) { + writePunctuation(writer, 24); + writeType(typeArguments[pos++], 0); + while (pos < end) { + writePunctuation(writer, 23); + writeSpace(writer); + writeType(typeArguments[pos++], 0); + } + writePunctuation(writer, 25); + } + } function writeTypeReference(type, flags) { + var typeArguments = type.typeArguments; if (type.target === globalArrayType && !(flags & 1)) { - writeType(type.typeArguments[0], 64); + writeType(typeArguments[0], 64); writePunctuation(writer, 18); writePunctuation(writer, 19); } else { - buildSymbolDisplay(type.target.symbol, writer, enclosingDeclaration, 793056); - writePunctuation(writer, 24); - writeTypeList(type.typeArguments, false); - writePunctuation(writer, 25); + var outerTypeParameters = type.target.outerTypeParameters; + var i = 0; + if (outerTypeParameters) { + var length_1 = outerTypeParameters.length; + while (i < length_1) { + var start = i; + var parent_3 = getParentSymbolOfTypeParameter(outerTypeParameters[i]); + do { + i++; + } while (i < length_1 && getParentSymbolOfTypeParameter(outerTypeParameters[i]) === parent_3); + if (!ts.rangeEquals(outerTypeParameters, typeArguments, start, i)) { + writeSymbolTypeReference(parent_3, typeArguments, start, i); + writePunctuation(writer, 20); + } + } + } + writeSymbolTypeReference(type.symbol, typeArguments, i, typeArguments.length); } } function writeTupleType(type) { @@ -10292,7 +11135,7 @@ var ts; function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) { var targetSymbol = getTargetSymbol(symbol); if (targetSymbol.flags & 32 || targetSymbol.flags & 64) { - buildDisplayForTypeParametersAndDelimiters(getTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); + buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); } } function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { @@ -10306,11 +11149,12 @@ var ts; } } function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { - if (ts.hasDotDotDotToken(p.valueDeclaration)) { + var parameterNode = p.valueDeclaration; + if (ts.isRestParameter(parameterNode)) { writePunctuation(writer, 21); } appendSymbolNameOnly(p, writer); - if (ts.hasQuestionToken(p.valueDeclaration) || p.valueDeclaration.initializer) { + if (isOptionalParameter(parameterNode)) { writePunctuation(writer, 50); } writePunctuation(writer, 51); @@ -10455,12 +11299,12 @@ var ts; case 201: case 205: case 209: - var parent_2 = getDeclarationContainer(node); + var parent_4 = getDeclarationContainer(node); if (!(ts.getCombinedNodeFlags(node) & 1) && - !(node.kind !== 209 && parent_2.kind !== 228 && ts.isInAmbientContext(parent_2))) { - return isGlobalSourceFile(parent_2); + !(node.kind !== 209 && parent_4.kind !== 228 && ts.isInAmbientContext(parent_4))) { + return isGlobalSourceFile(parent_4); } - return isDeclarationVisible(parent_2); + return isDeclarationVisible(parent_4); case 133: case 132: case 137: @@ -10581,12 +11425,12 @@ var ts; } var type; if (pattern.kind === 151) { - var name_5 = declaration.propertyName || declaration.name; - type = getTypeOfPropertyOfType(parentType, name_5.text) || - isNumericLiteralName(name_5.text) && getIndexTypeOfType(parentType, 1) || + var name_8 = declaration.propertyName || declaration.name; + type = getTypeOfPropertyOfType(parentType, name_8.text) || + isNumericLiteralName(name_8.text) && getIndexTypeOfType(parentType, 1) || getIndexTypeOfType(parentType, 0); if (!type) { - error(name_5, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_5)); + error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_8)); return unknownType; } } @@ -10864,26 +11708,55 @@ var ts; return target === checkBase || ts.forEach(getBaseTypes(target), check); } } - function getTypeParametersOfClassOrInterface(symbol) { - var result; - ts.forEach(symbol.declarations, function (node) { - if (node.kind === 203 || node.kind === 202) { - var declaration = node; - if (declaration.typeParameters && declaration.typeParameters.length) { - ts.forEach(declaration.typeParameters, function (node) { - var tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node)); - if (!result) { - result = [tp]; - } - else if (!ts.contains(result, tp)) { - result.push(tp); - } - }); + function appendTypeParameters(typeParameters, declarations) { + for (var _i = 0; _i < declarations.length; _i++) { + var declaration = declarations[_i]; + var tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(declaration)); + if (!typeParameters) { + typeParameters = [tp]; + } + else if (!ts.contains(typeParameters, tp)) { + typeParameters.push(tp); + } + } + return typeParameters; + } + function appendOuterTypeParameters(typeParameters, node) { + while (true) { + node = node.parent; + if (!node) { + return typeParameters; + } + if (node.kind === 202 || node.kind === 201 || + node.kind === 163 || node.kind === 135 || + node.kind === 164) { + var declarations = node.typeParameters; + if (declarations) { + return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations); } } - }); + } + } + function getOuterTypeParametersOfClassOrInterface(symbol) { + var kind = symbol.flags & 32 ? 202 : 203; + return appendOuterTypeParameters(undefined, ts.getDeclarationOfKind(symbol, kind)); + } + function getLocalTypeParametersOfClassOrInterface(symbol) { + var result; + for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { + var node = _a[_i]; + if (node.kind === 203 || node.kind === 202) { + var declaration = node; + if (declaration.typeParameters) { + result = appendTypeParameters(result, declaration.typeParameters); + } + } + } return result; } + function getTypeParametersOfClassOrInterface(symbol) { + return ts.concatenate(getOuterTypeParametersOfClassOrInterface(symbol), getLocalTypeParametersOfClassOrInterface(symbol)); + } function getBaseTypes(type) { var typeWithBaseTypes = type; if (!typeWithBaseTypes.baseTypes) { @@ -10950,10 +11823,13 @@ var ts; if (!links.declaredType) { var kind = symbol.flags & 32 ? 1024 : 2048; var type = links.declaredType = createObjectType(kind, symbol); - var typeParameters = getTypeParametersOfClassOrInterface(symbol); - if (typeParameters) { + var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol); + var localTypeParameters = getLocalTypeParametersOfClassOrInterface(symbol); + if (outerTypeParameters || localTypeParameters) { type.flags |= 4096; - type.typeParameters = typeParameters; + type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters); + type.outerTypeParameters = outerTypeParameters; + type.localTypeParameters = localTypeParameters; type.instantiations = {}; type.instantiations[getTypeListId(type.typeParameters)] = type; type.target = type; @@ -11129,12 +12005,12 @@ var ts; return ts.map(baseSignatures, function (baseSignature) { var signature = baseType.flags & 4096 ? getSignatureInstantiation(baseSignature, baseType.typeArguments) : cloneSignature(baseSignature); - signature.typeParameters = classType.typeParameters; + signature.typeParameters = classType.localTypeParameters; signature.resolvedReturnType = classType; return signature; }); } - return [createSignature(undefined, classType.typeParameters, emptyArray, classType, 0, false, false)]; + return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, 0, false, false)]; } function createTupleTypeMemberSymbols(memberTypes) { var members = {}; @@ -11436,11 +12312,14 @@ var ts; } return result; } + function isOptionalParameter(node) { + return ts.hasQuestionToken(node) || !!node.initializer; + } function getSignatureFromDeclaration(declaration) { var links = getNodeLinks(declaration); if (!links.resolvedSignature) { var classType = declaration.kind === 136 ? getDeclaredTypeOfClassOrInterface(declaration.parent.symbol) : undefined; - var typeParameters = classType ? classType.typeParameters : + var typeParameters = classType ? classType.localTypeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; var parameters = []; var hasStringLiterals = false; @@ -11476,7 +12355,7 @@ var ts; returnType = anyType; } } - links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, minArgumentCount, ts.hasRestParameters(declaration), hasStringLiterals); + links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals); } return links.resolvedSignature; } @@ -11618,6 +12497,9 @@ var ts; } return type.constraint === noConstraintType ? undefined : type.constraint; } + function getParentSymbolOfTypeParameter(typeParameter) { + return getSymbolOfNode(ts.getDeclarationOfKind(typeParameter.symbol, 129).parent); + } function getTypeListId(types) { switch (types.length) { case 1: @@ -11702,23 +12584,7 @@ var ts; type = unknownType; } else { - type = getDeclaredTypeOfSymbol(symbol); - if (type.flags & (1024 | 2048) && type.flags & 4096) { - var typeParameters = type.typeParameters; - if (node.typeArguments && node.typeArguments.length === typeParameters.length) { - type = createTypeReference(type, ts.map(node.typeArguments, getTypeFromTypeNode)); - } - else { - error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, undefined, 1), typeParameters.length); - type = undefined; - } - } - else { - if (node.typeArguments) { - error(node, ts.Diagnostics.Type_0_is_not_generic, typeToString(type)); - type = undefined; - } - } + type = createTypeReferenceIfGeneric(getDeclaredTypeOfSymbol(symbol), node, node.typeArguments); } } } @@ -11726,6 +12592,29 @@ var ts; } return links.resolvedType; } + function createTypeReferenceIfGeneric(type, node, typeArguments) { + if (type.flags & (1024 | 2048) && type.flags & 4096) { + var localTypeParameters = type.localTypeParameters; + var expectedTypeArgCount = localTypeParameters ? localTypeParameters.length : 0; + var typeArgCount = typeArguments ? typeArguments.length : 0; + if (typeArgCount === expectedTypeArgCount) { + if (typeArgCount) { + return createTypeReference(type, ts.concatenate(type.outerTypeParameters, ts.map(typeArguments, getTypeFromTypeNode))); + } + } + else { + error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, undefined, 1), expectedTypeArgCount); + return undefined; + } + } + else { + if (typeArguments) { + error(node, ts.Diagnostics.Type_0_is_not_generic, typeToString(type)); + return undefined; + } + } + return type; + } function getTypeFromTypeQueryNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { @@ -11747,16 +12636,16 @@ var ts; } } if (!symbol) { - return emptyObjectType; + return arity ? emptyGenericType : emptyObjectType; } var type = getDeclaredTypeOfSymbol(symbol); if (!(type.flags & 48128)) { error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name); - return emptyObjectType; + return arity ? emptyGenericType : emptyObjectType; } if ((type.typeParameters ? type.typeParameters.length : 0) !== arity) { error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity); - return emptyObjectType; + return arity ? emptyGenericType : emptyObjectType; } return type; } @@ -11776,12 +12665,17 @@ var ts; function getGlobalESSymbolConstructorSymbol() { return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol")); } + function createTypeFromGenericGlobalType(genericGlobalType, elementType) { + return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, [elementType]) : emptyObjectType; + } function createIterableType(elementType) { - return globalIterableType !== emptyObjectType ? createTypeReference(globalIterableType, [elementType]) : emptyObjectType; + return createTypeFromGenericGlobalType(globalIterableType, elementType); + } + function createIterableIteratorType(elementType) { + return createTypeFromGenericGlobalType(globalIterableIteratorType, elementType); } function createArrayType(elementType) { - var arrayType = globalArrayType || getDeclaredTypeOfSymbol(globalArraySymbol); - return arrayType !== emptyObjectType ? createTypeReference(arrayType, [elementType]) : emptyObjectType; + return createTypeFromGenericGlobalType(globalArrayType, elementType); } function getTypeFromArrayTypeNode(node) { var links = getNodeLinks(node); @@ -11836,13 +12730,7 @@ var ts; } return false; } - var removeSubtypesStack = []; function removeSubtypes(types) { - var typeListId = getTypeListId(types); - if (removeSubtypesStack.lastIndexOf(typeListId) >= 0) { - return; - } - removeSubtypesStack.push(typeListId); var i = types.length; while (i > 0) { i--; @@ -11850,7 +12738,6 @@ var ts; types.splice(i, 1); } } - removeSubtypesStack.pop(); } function containsAnyType(types) { for (var _i = 0; _i < types.length; _i++) { @@ -11900,7 +12787,14 @@ var ts; } function getReducedTypeOfUnionType(type) { if (!type.reducedType) { - type.reducedType = getUnionType(type.types, false); + type.reducedType = circularType; + var reducedType = getUnionType(type.types, false); + if (type.reducedType === circularType) { + type.reducedType = reducedType; + } + } + else if (type.reducedType === circularType) { + type.reducedType = type; } return type.reducedType; } @@ -12084,6 +12978,15 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { + if (mapper.mappings) { + var cached = mapper.mappings[type.id]; + if (cached) { + return cached; + } + } + else { + mapper.mappings = {}; + } var result = createObjectType(32768, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); @@ -12095,6 +12998,7 @@ var ts; result.stringIndexType = instantiateType(stringIndexType, mapper); if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper); + mapper.mappings[type.id] = result; return result; } function instantiateType(type, mapper) { @@ -12103,7 +13007,7 @@ var ts; return mapper(type); } if (type.flags & 32768) { - return type.symbol && type.symbol.flags & (16 | 8192 | 2048 | 4096) ? + return type.symbol && type.symbol.flags & (16 | 8192 | 32 | 2048 | 4096) ? instantiateAnonymousType(type, mapper) : type; } if (type.flags & 4096) { @@ -13280,10 +14184,10 @@ var ts; } function resolveLocation(node) { var containerNodes = []; - for (var parent_3 = node.parent; parent_3; parent_3 = parent_3.parent) { - if ((ts.isExpression(parent_3) || ts.isObjectLiteralMethod(node)) && - isContextSensitive(parent_3)) { - containerNodes.unshift(parent_3); + for (var parent_5 = node.parent; parent_5; parent_5 = parent_5.parent) { + if ((ts.isExpression(parent_5) || ts.isObjectLiteralMethod(node)) && + isContextSensitive(parent_5)) { + containerNodes.unshift(parent_5); } } ts.forEach(containerNodes, function (node) { getTypeOfNode(node); }); @@ -13654,7 +14558,7 @@ var ts; if (isContextSensitive(func)) { var contextualSignature = getContextualSignature(func); if (contextualSignature) { - var funcHasRestParameters = ts.hasRestParameters(func); + var funcHasRestParameters = ts.hasRestParameter(func); var len = func.parameters.length - (funcHasRestParameters ? 1 : 0); var indexOfParameter = ts.indexOf(func.parameters, parameter); if (indexOfParameter < len) { @@ -13688,18 +14592,36 @@ var ts; return undefined; } function getContextualTypeForReturnExpression(node) { + var func = ts.getContainingFunction(node); + if (func && !func.asteriskToken) { + return getContextualReturnType(func); + } + return undefined; + } + function getContextualTypeForYieldOperand(node) { var func = ts.getContainingFunction(node); if (func) { - if (func.type || func.kind === 136 || func.kind === 137 && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(func.symbol, 138))) { - return getReturnTypeOfSignature(getSignatureFromDeclaration(func)); - } - var signature = getContextualSignatureForFunctionLikeDeclaration(func); - if (signature) { - return getReturnTypeOfSignature(signature); + var contextualReturnType = getContextualReturnType(func); + if (contextualReturnType) { + return node.asteriskToken + ? contextualReturnType + : getElementTypeOfIterableIterator(contextualReturnType); } } return undefined; } + function getContextualReturnType(functionDecl) { + if (functionDecl.type || + functionDecl.kind === 136 || + functionDecl.kind === 137 && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(functionDecl.symbol, 138))) { + return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl)); + } + var signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl); + if (signature) { + return getReturnTypeOfSignature(signature); + } + return undefined; + } function getContextualTypeForArgument(callTarget, arg) { var args = getEffectiveCallArguments(callTarget); var argIndex = ts.indexOf(args, arg); @@ -13801,7 +14723,7 @@ var ts; var index = ts.indexOf(arrayLiteral.elements, node); return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, 1) - || (languageVersion >= 2 ? checkIteratedType(type, undefined) : undefined); + || (languageVersion >= 2 ? getElementTypeOfIterable(type, undefined) : undefined); } return undefined; } @@ -13827,6 +14749,8 @@ var ts; case 164: case 192: return getContextualTypeForReturnExpression(node); + case 173: + return getContextualTypeForYieldOperand(parent); case 158: case 159: return getContextualTypeForArgument(parent, node); @@ -13861,7 +14785,9 @@ var ts; return node.kind === 163 || node.kind === 164; } function getContextualSignatureForFunctionLikeDeclaration(node) { - return isFunctionExpressionOrArrowFunction(node) ? getContextualSignature(node) : undefined; + return isFunctionExpressionOrArrowFunction(node) || ts.isObjectLiteralMethod(node) + ? getContextualSignature(node) + : undefined; } function getContextualSignature(node) { ts.Debug.assert(node.kind !== 135 || ts.isObjectLiteralMethod(node)); @@ -13936,7 +14862,7 @@ var ts; if (inDestructuringPattern && e.kind === 174) { var restArrayType = checkExpression(e.expression, contextualMapper); var restElementType = getIndexTypeOfType(restArrayType, 1) || - (languageVersion >= 2 ? checkIteratedType(restArrayType, undefined) : undefined); + (languageVersion >= 2 ? getElementTypeOfIterable(restArrayType, undefined) : undefined); if (restElementType) { elementTypes.push(restElementType); } @@ -14159,15 +15085,15 @@ var ts; return unknownType; } if (node.argumentExpression) { - var name_6 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); - if (name_6 !== undefined) { - var prop = getPropertyOfType(objectType, name_6); + var name_9 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); + if (name_9 !== undefined) { + var prop = getPropertyOfType(objectType, name_9); if (prop) { getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } else if (isConstEnum) { - error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_6, symbolToString(objectType.symbol)); + error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_9, symbolToString(objectType.symbol)); return unknownType; } } @@ -14257,19 +15183,19 @@ var ts; for (var _i = 0; _i < signatures.length; _i++) { var signature = signatures[_i]; var symbol = signature.declaration && getSymbolOfNode(signature.declaration); - var parent_4 = signature.declaration && signature.declaration.parent; + var parent_6 = signature.declaration && signature.declaration.parent; if (!lastSymbol || symbol === lastSymbol) { - if (lastParent && parent_4 === lastParent) { + if (lastParent && parent_6 === lastParent) { index++; } else { - lastParent = parent_4; + lastParent = parent_6; index = cutoffIndex; } } else { index = cutoffIndex = result.length; - lastParent = parent_4; + lastParent = parent_6; } lastSymbol = symbol; if (signature.hasStringLiterals) { @@ -14608,10 +15534,10 @@ var ts; return resolveCall(node, callSignatures, candidatesOutArray); } function resolveNewExpression(node, candidatesOutArray) { - if (node.arguments && languageVersion < 2) { + if (node.arguments && languageVersion < 1) { var spreadIndex = getSpreadArgumentIndex(node.arguments); if (spreadIndex >= 0) { - error(node.arguments[spreadIndex], ts.Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher); + error(node.arguments[spreadIndex], ts.Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher); } } var expressionType = checkExpression(node.expression); @@ -14737,14 +15663,37 @@ var ts; type = checkExpressionCached(func.body, contextualMapper); } else { - var types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); - if (types.length === 0) { - return voidType; + var types; + var funcIsGenerator = !!func.asteriskToken; + if (funcIsGenerator) { + types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); + if (types.length === 0) { + var iterableIteratorAny = createIterableIteratorType(anyType); + if (compilerOptions.noImplicitAny) { + error(func.asteriskToken, ts.Diagnostics.Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type, typeToString(iterableIteratorAny)); + } + return iterableIteratorAny; + } + } + else { + types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); + if (types.length === 0) { + return voidType; + } } type = contextualSignature ? getUnionType(types) : getCommonSupertype(types); if (!type) { - error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions); - return unknownType; + if (funcIsGenerator) { + error(func, ts.Diagnostics.No_best_common_type_exists_among_yield_expressions); + return createIterableIteratorType(unknownType); + } + else { + error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions); + return unknownType; + } + } + if (funcIsGenerator) { + type = createIterableIteratorType(type); } } if (!contextualSignature) { @@ -14752,6 +15701,22 @@ var ts; } return getWidenedType(type); } + function checkAndAggregateYieldOperandTypes(body, contextualMapper) { + var aggregatedTypes = []; + ts.forEachYieldExpression(body, function (yieldExpression) { + var expr = yieldExpression.expression; + if (expr) { + var type = checkExpressionCached(expr, contextualMapper); + if (yieldExpression.asteriskToken) { + type = checkElementTypeOfIterable(type, yieldExpression.expression); + } + if (!ts.contains(aggregatedTypes, type)) { + aggregatedTypes.push(type); + } + } + }); + return aggregatedTypes; + } function checkAndAggregateReturnExpressionTypes(body, contextualMapper) { var aggregatedTypes = []; ts.forEachReturnStatement(body, function (returnStatement) { @@ -14887,8 +15852,8 @@ var ts; var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8) { - var name_7 = index.text; - var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_7); + var name_10 = index.text; + var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_10); return prop && (prop.flags & 3) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192) !== 0; } return false; @@ -15019,16 +15984,16 @@ var ts; for (var _i = 0; _i < properties.length; _i++) { var p = properties[_i]; if (p.kind === 225 || p.kind === 226) { - var name_8 = p.name; + var name_11 = p.name; var type = sourceType.flags & 1 ? sourceType : - getTypeOfPropertyOfType(sourceType, name_8.text) || - isNumericLiteralName(name_8.text) && getIndexTypeOfType(sourceType, 1) || + getTypeOfPropertyOfType(sourceType, name_11.text) || + isNumericLiteralName(name_11.text) && getIndexTypeOfType(sourceType, 1) || getIndexTypeOfType(sourceType, 0); if (type) { - checkDestructuringAssignment(p.initializer || name_8, type); + checkDestructuringAssignment(p.initializer || name_11, type); } else { - error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_8)); + error(name_11, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_11)); } } else { @@ -15243,13 +16208,46 @@ var ts; error(node, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(node.operatorToken.kind), typeToString(leftType), typeToString(rightType)); } } + function isYieldExpressionInClass(node) { + var current = node; + var parent = node.parent; + while (parent) { + if (ts.isFunctionLike(parent) && current === parent.body) { + return false; + } + else if (current.kind === 202 || current.kind === 175) { + return true; + } + current = parent; + parent = parent.parent; + } + return false; + } function checkYieldExpression(node) { - if (!(node.parserContextFlags & 4)) { - grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration); + if (!(node.parserContextFlags & 4) || isYieldExpressionInClass(node)) { + grammarErrorOnFirstToken(node, ts.Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body); } - else { - grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expressions_are_not_currently_supported); + if (node.expression) { + var func = ts.getContainingFunction(node); + if (func && func.asteriskToken) { + var expressionType = checkExpressionCached(node.expression, undefined); + var expressionElementType; + var nodeIsYieldStar = !!node.asteriskToken; + if (nodeIsYieldStar) { + expressionElementType = checkElementTypeOfIterable(expressionType, node.expression); + } + if (func.type) { + var signatureElementType = getElementTypeOfIterableIterator(getTypeFromTypeNode(func.type)) || anyType; + if (nodeIsYieldStar) { + checkTypeAssignableTo(expressionElementType, signatureElementType, node.expression, undefined); + } + else { + checkTypeAssignableTo(expressionType, signatureElementType, node.expression, undefined); + } + } + } } + return anyType; } function checkConditionalExpression(node, contextualMapper) { checkExpression(node.condition); @@ -15396,8 +16394,7 @@ var ts; case 176: return undefinedType; case 173: - checkYieldExpression(node); - return unknownType; + return checkYieldExpression(node); } return unknownType; } @@ -15435,6 +16432,14 @@ var ts; error(node, ts.Diagnostics.A_rest_parameter_must_be_of_an_array_type); } } + function isSyntacticallyValidGenerator(node) { + if (!node.asteriskToken || !node.body) { + return false; + } + return node.kind === 135 || + node.kind === 201 || + node.kind === 163; + } function checkSignatureDeclaration(node) { if (node.kind === 141) { checkGrammarIndexSignature(node); @@ -15461,6 +16466,19 @@ var ts; break; } } + if (node.type) { + if (languageVersion >= 2 && isSyntacticallyValidGenerator(node)) { + var returnType = getTypeFromTypeNode(node.type); + if (returnType === voidType) { + error(node.type, ts.Diagnostics.A_generator_cannot_have_a_void_type_annotation); + } + else { + var generatorElementType = getElementTypeOfIterableIterator(returnType) || anyType; + var iterableIteratorInstantiation = createIterableIteratorType(generatorElementType); + checkTypeAssignableTo(iterableIteratorInstantiation, returnType, node.type); + } + } + } } checkSpecializedSignatureDeclaration(node); } @@ -15933,7 +16951,7 @@ var ts; function checkTypeNodeAsExpression(node) { if (node && node.kind === 142) { var type = getTypeFromTypeNode(node); - var shouldCheckIfUnknownType = type === unknownType && compilerOptions.separateCompilation; + var shouldCheckIfUnknownType = type === unknownType && compilerOptions.isolatedModules; if (!type || (!shouldCheckIfUnknownType && type.flags & (1048703 | 132 | 258))) { return; } @@ -15974,6 +16992,9 @@ var ts; if (!ts.nodeCanBeDecorated(node)) { return; } + if (!compilerOptions.experimentalDecorators) { + error(node, ts.Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning); + } if (compilerOptions.emitDecoratorMetadata) { switch (node.kind) { case 202: @@ -16001,7 +17022,6 @@ var ts; function checkFunctionDeclaration(node) { if (produceDiagnostics) { checkFunctionLikeDeclaration(node) || - checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); checkCollisionWithCapturedSuperVariable(node, node.name); @@ -16033,8 +17053,13 @@ var ts; if (node.type && !isAccessor(node.kind) && !node.asteriskToken) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !node.type && !isPrivateWithinAmbient(node)) { - reportImplicitAnyError(node, anyType); + if (produceDiagnostics && !node.type) { + if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !isPrivateWithinAmbient(node)) { + reportImplicitAnyError(node, anyType); + } + if (node.asteriskToken && ts.nodeIsPresent(node.body)) { + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } } } function checkBlock(node) { @@ -16047,7 +17072,7 @@ var ts; } } function checkCollisionWithArgumentsInGeneratedCode(node) { - if (!ts.hasRestParameters(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) { + if (!ts.hasRestParameter(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) { return; } ts.forEach(node.parameters, function (p) { @@ -16155,8 +17180,8 @@ var ts; container.kind === 206 || container.kind === 228); if (!namesShareScope) { - var name_9 = symbolToString(localDeclarationSymbol); - error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_9, name_9); + var name_12 = symbolToString(localDeclarationSymbol); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_12, name_12); } } } @@ -16249,7 +17274,7 @@ var ts; return checkVariableLikeDeclaration(node); } function checkVariableStatement(node) { - checkGrammarDecorators(node) || checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); ts.forEach(node.declarationList.declarations, checkSourceElement); } function checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) { @@ -16372,7 +17397,7 @@ var ts; return inputType; } if (languageVersion >= 2) { - return checkIteratedType(inputType, errorNode) || anyType; + return checkElementTypeOfIterable(inputType, errorNode); } if (allowStringInput) { return checkElementTypeOfArrayOrString(inputType, errorNode); @@ -16386,84 +17411,85 @@ var ts; error(errorNode, ts.Diagnostics.Type_0_is_not_an_array_type, typeToString(inputType)); return unknownType; } - function checkIteratedType(iterable, errorNode) { - ts.Debug.assert(languageVersion >= 2); - var iteratedType = getIteratedType(iterable, errorNode); - if (errorNode && iteratedType) { - checkTypeAssignableTo(iterable, createIterableType(iteratedType), errorNode); + function checkElementTypeOfIterable(iterable, errorNode) { + var elementType = getElementTypeOfIterable(iterable, errorNode); + if (errorNode && elementType) { + checkTypeAssignableTo(iterable, createIterableType(elementType), errorNode); } - return iteratedType; - function getIteratedType(iterable, errorNode) { - // We want to treat type as an iterable, and get the type it is an iterable of. The iterable - // must have the following structure (annotated with the names of the variables below): - // - // { // iterable - // [Symbol.iterator]: { // iteratorFunction - // (): { // iterator - // next: { // iteratorNextFunction - // (): { // iteratorNextResult - // value: T // iteratorNextValue - // } - // } - // } - // } - // } - // - // T is the type we are after. At every level that involves analyzing return types - // of signatures, we union the return types of all the signatures. - // - // Another thing to note is that at any step of this process, we could run into a dead end, - // meaning either the property is missing, or we run into the anyType. If either of these things - // happens, we return undefined to signal that we could not find the iterated type. If a property - // is missing, and the previous step did not result in 'any', then we also give an error if the - // caller requested it. Then the caller can decide what to do in the case where there is no iterated - // type. This is different from returning anyType, because that would signify that we have matched the - // whole pattern and that T (above) is 'any'. - if (allConstituentTypesHaveKind(iterable, 1)) { - return undefined; - } - if ((iterable.flags & 4096) && iterable.target === globalIterableType) { - return iterable.typeArguments[0]; - } - var iteratorFunction = getTypeOfPropertyOfType(iterable, ts.getPropertyNameForKnownSymbolName("iterator")); - if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, 1)) { - return undefined; - } - var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0) : emptyArray; - if (iteratorFunctionSignatures.length === 0) { - if (errorNode) { - error(errorNode, ts.Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator); - } - return undefined; - } - var iterator = getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature)); - if (allConstituentTypesHaveKind(iterator, 1)) { - return undefined; - } - var iteratorNextFunction = getTypeOfPropertyOfType(iterator, "next"); - if (iteratorNextFunction && allConstituentTypesHaveKind(iteratorNextFunction, 1)) { - return undefined; - } - var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0) : emptyArray; - if (iteratorNextFunctionSignatures.length === 0) { - if (errorNode) { - error(errorNode, ts.Diagnostics.An_iterator_must_have_a_next_method); - } - return undefined; - } - var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); - if (allConstituentTypesHaveKind(iteratorNextResult, 1)) { - return undefined; - } - var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); - if (!iteratorNextValue) { - if (errorNode) { - error(errorNode, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property); - } - return undefined; - } - return iteratorNextValue; + return elementType || anyType; + } + function getElementTypeOfIterable(type, errorNode) { + if (type.flags & 1) { + return undefined; } + var typeAsIterable = type; + if (!typeAsIterable.iterableElementType) { + if ((type.flags & 4096) && type.target === globalIterableType) { + typeAsIterable.iterableElementType = type.typeArguments[0]; + } + else { + var iteratorFunction = getTypeOfPropertyOfType(type, ts.getPropertyNameForKnownSymbolName("iterator")); + if (iteratorFunction && iteratorFunction.flags & 1) { + return undefined; + } + var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0) : emptyArray; + if (iteratorFunctionSignatures.length === 0) { + if (errorNode) { + error(errorNode, ts.Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator); + } + return undefined; + } + typeAsIterable.iterableElementType = getElementTypeOfIterator(getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature)), errorNode); + } + } + return typeAsIterable.iterableElementType; + } + function getElementTypeOfIterator(type, errorNode) { + if (type.flags & 1) { + return undefined; + } + var typeAsIterator = type; + if (!typeAsIterator.iteratorElementType) { + if ((type.flags & 4096) && type.target === globalIteratorType) { + typeAsIterator.iteratorElementType = type.typeArguments[0]; + } + else { + var iteratorNextFunction = getTypeOfPropertyOfType(type, "next"); + if (iteratorNextFunction && iteratorNextFunction.flags & 1) { + return undefined; + } + var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0) : emptyArray; + if (iteratorNextFunctionSignatures.length === 0) { + if (errorNode) { + error(errorNode, ts.Diagnostics.An_iterator_must_have_a_next_method); + } + return undefined; + } + var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); + if (iteratorNextResult.flags & 1) { + return undefined; + } + var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); + if (!iteratorNextValue) { + if (errorNode) { + error(errorNode, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property); + } + return undefined; + } + typeAsIterator.iteratorElementType = iteratorNextValue; + } + } + return typeAsIterator.iteratorElementType; + } + function getElementTypeOfIterableIterator(type) { + if (type.flags & 1) { + return undefined; + } + if ((type.flags & 4096) && type.target === globalIterableIteratorType) { + return type.typeArguments[0]; + } + return getElementTypeOfIterable(type, undefined) || + getElementTypeOfIterator(type, undefined); } function checkElementTypeOfArrayOrString(arrayOrStringType, errorNode) { ts.Debug.assert(languageVersion < 2); @@ -16515,19 +17541,20 @@ var ts; if (func) { var returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(func)); var exprType = checkExpressionCached(node.expression); + if (func.asteriskToken) { + return; + } if (func.kind === 138) { error(node.expression, ts.Diagnostics.Setters_cannot_return_a_value); } - else { - if (func.kind === 136) { - if (!isTypeAssignableTo(exprType, returnType)) { - error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); - } - } - else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func)) { - checkTypeAssignableTo(exprType, returnType, node.expression, undefined); + else if (func.kind === 136) { + if (!isTypeAssignableTo(exprType, returnType)) { + error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); } } + else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func)) { + checkTypeAssignableTo(exprType, returnType, node.expression, undefined); + } } } } @@ -16721,9 +17748,6 @@ var ts; } function checkClassDeclaration(node) { checkGrammarDeclarationNameInStrictMode(node); - if (node.parent.kind !== 207 && node.parent.kind !== 228) { - grammarErrorOnNode(node, ts.Diagnostics.class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration); - } if (!node.name && !(node.flags & 256)) { grammarErrorOnFirstToken(node, ts.Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } @@ -16760,7 +17784,7 @@ var ts; checkKindsOfPropertyMemberOverrides(type, baseType); } } - if (baseTypes.length || (baseTypeNode && compilerOptions.separateCompilation)) { + if (baseTypes.length || (baseTypeNode && compilerOptions.isolatedModules)) { checkExpressionOrQualifiedName(baseTypeNode.expression); } var implementedTypeNodes = ts.getClassImplementsHeritageClauseElements(node); @@ -17104,8 +18128,8 @@ var ts; checkExportsOnMergedDeclarations(node); computeEnumMemberValues(node); var enumIsConst = ts.isConst(node); - if (compilerOptions.separateCompilation && enumIsConst && ts.isInAmbientContext(node)) { - error(node.name, ts.Diagnostics.Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided); + if (compilerOptions.isolatedModules && enumIsConst && ts.isInAmbientContext(node)) { + error(node.name, ts.Diagnostics.Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided); } var enumSymbol = getSymbolOfNode(node); var firstDeclaration = ts.getDeclarationOfKind(enumSymbol, node.kind); @@ -17177,7 +18201,7 @@ var ts; if (symbol.flags & 512 && symbol.declarations.length > 1 && !ts.isInAmbientContext(node) - && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.separateCompilation)) { + && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules)) { var firstNonAmbientClassOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); if (firstNonAmbientClassOrFunc) { if (ts.getSourceFileOfNode(node) !== ts.getSourceFileOfNode(firstNonAmbientClassOrFunc)) { @@ -17504,6 +18528,7 @@ var ts; break; case 135: case 134: + ts.forEach(node.decorators, checkFunctionExpressionBodies); ts.forEach(node.parameters, checkFunctionExpressionBodies); if (ts.isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); @@ -17518,6 +18543,7 @@ var ts; case 193: checkFunctionExpressionBodies(node.expression); break; + case 131: case 130: case 133: case 132: @@ -17761,74 +18787,6 @@ var ts; } return node.parent && node.parent.kind === 177; } - function isTypeNode(node) { - if (142 <= node.kind && node.kind <= 150) { - return true; - } - switch (node.kind) { - case 112: - case 120: - case 122: - case 113: - case 123: - return true; - case 99: - return node.parent.kind !== 167; - case 8: - return node.parent.kind === 130; - case 177: - return true; - case 65: - if (node.parent.kind === 127 && node.parent.right === node) { - node = node.parent; - } - else if (node.parent.kind === 156 && node.parent.name === node) { - node = node.parent; - } - case 127: - case 156: - ts.Debug.assert(node.kind === 65 || node.kind === 127 || node.kind === 156, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); - var parent_5 = node.parent; - if (parent_5.kind === 145) { - return false; - } - if (142 <= parent_5.kind && parent_5.kind <= 150) { - return true; - } - switch (parent_5.kind) { - case 177: - return true; - case 129: - return node === parent_5.constraint; - case 133: - case 132: - case 130: - case 199: - return node === parent_5.type; - case 201: - case 163: - case 164: - case 136: - case 135: - case 134: - case 137: - case 138: - return node === parent_5.type; - case 139: - case 140: - case 141: - return node === parent_5.type; - case 161: - return node === parent_5.type; - case 158: - case 159: - return parent_5.typeArguments && ts.indexOf(parent_5.typeArguments, node) >= 0; - case 160: - return false; - } - } - return false; - } function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide) { while (nodeOnRightSide.parent.kind === 127) { nodeOnRightSide = nodeOnRightSide.parent; @@ -17953,7 +18911,7 @@ var ts; if (isInsideWithStatementBody(node)) { return unknownType; } - if (isTypeNode(node)) { + if (ts.isTypeNode(node)) { return getTypeFromTypeNode(node); } if (ts.isExpression(node)) { @@ -18003,9 +18961,9 @@ var ts; function getRootSymbols(symbol) { if (symbol.flags & 268435456) { var symbols = []; - var name_10 = symbol.name; + var name_13 = symbol.name; ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { - symbols.push(getPropertyOfType(t, name_10)); + symbols.push(getPropertyOfType(t, name_13)); }); return symbols; } @@ -18099,7 +19057,7 @@ var ts; } function isAliasResolvedToValue(symbol) { var target = resolveAlias(symbol); - if (target === unknownSymbol && compilerOptions.separateCompilation) { + if (target === unknownSymbol && compilerOptions.isolatedModules) { return true; } return target !== unknownSymbol && target && target.flags & 107455 && !isConstEnumOrConstEnumOnlyModule(target); @@ -18383,8 +19341,7 @@ var ts; getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments"); getSymbolLinks(unknownSymbol).type = unknownType; globals[undefinedSymbol.name] = undefinedSymbol; - globalArraySymbol = getGlobalTypeSymbol("Array"); - globalArrayType = getTypeOfGlobalSymbol(globalArraySymbol, 1); + globalArrayType = getGlobalType("Array", 1); globalObjectType = getGlobalType("Object"); globalFunctionType = getGlobalType("Function"); globalStringType = getGlobalType("String"); @@ -18400,11 +19357,16 @@ var ts; globalESSymbolType = getGlobalType("Symbol"); globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"); globalIterableType = getGlobalType("Iterable", 1); + globalIteratorType = getGlobalType("Iterator", 1); + globalIterableIteratorType = getGlobalType("IterableIterator", 1); } else { globalTemplateStringsArrayType = unknownType; globalESSymbolType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); globalESSymbolConstructorSymbol = undefined; + globalIterableType = emptyGenericType; + globalIteratorType = emptyGenericType; + globalIterableIteratorType = emptyGenericType; } anyArrayType = createArrayType(anyType); } @@ -18424,20 +19386,20 @@ var ts; if (impotClause.namedBindings) { var nameBindings = impotClause.namedBindings; if (nameBindings.kind === 212) { - var name_11 = nameBindings.name; - if (isReservedWordInStrictMode(name_11)) { - var nameText = ts.declarationNameToString(name_11); - return grammarErrorOnNode(name_11, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_14 = nameBindings.name; + if (isReservedWordInStrictMode(name_14)) { + var nameText = ts.declarationNameToString(name_14); + return grammarErrorOnNode(name_14, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } else if (nameBindings.kind === 213) { var reportError = false; for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { var element = _a[_i]; - var name_12 = element.name; - if (isReservedWordInStrictMode(name_12)) { - var nameText = ts.declarationNameToString(name_12); - reportError = reportError || grammarErrorOnNode(name_12, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_15 = element.name; + if (isReservedWordInStrictMode(name_15)) { + var nameText = ts.declarationNameToString(name_15); + reportError = reportError || grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } return reportError; @@ -18535,19 +19497,28 @@ var ts; case 135: case 134: case 141: - case 202: - case 203: case 206: - case 205: - case 181: - case 201: - case 204: case 210: case 209: case 216: case 215: case 130: break; + case 202: + case 203: + case 181: + case 201: + case 204: + if (node.modifiers && node.parent.kind !== 207 && node.parent.kind !== 228) { + return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + } + break; + case 205: + if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 70) && + node.parent.kind !== 207 && node.parent.kind !== 228) { + return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + } + break; default: return false; } @@ -18645,9 +19616,6 @@ var ts; else if ((node.kind === 210 || node.kind === 209) && flags & 2) { return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); } - else if (node.kind === 203 && flags & 2) { - return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); - } else if (node.kind === 130 && (flags & 112) && ts.isBindingPattern(node.name)) { return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); } @@ -18859,7 +19827,18 @@ var ts; } function checkGrammarForGenerator(node) { if (node.asteriskToken) { - return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_currently_supported); + ts.Debug.assert(node.kind === 201 || + node.kind === 163 || + node.kind === 135); + if (ts.isInAmbientContext(node)) { + return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_allowed_in_an_ambient_context); + } + if (!node.body) { + return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.An_overload_signature_cannot_be_declared_as_a_generator); + } + if (languageVersion < 2) { + return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_only_available_when_targeting_ECMAScript_6_or_higher); + } } } function checkGrammarFunctionName(name) { @@ -18879,17 +19858,17 @@ var ts; var inStrictMode = (node.parserContextFlags & 1) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_13 = prop.name; + var name_16 = prop.name; if (prop.kind === 176 || - name_13.kind === 128) { - checkGrammarComputedPropertyName(name_13); + name_16.kind === 128) { + checkGrammarComputedPropertyName(name_16); continue; } var currentKind = void 0; if (prop.kind === 225 || prop.kind === 226) { checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_13.kind === 7) { - checkGrammarNumericLiteral(name_13); + if (name_16.kind === 7) { + checkGrammarNumericLiteral(name_16); } currentKind = Property; } @@ -18905,26 +19884,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_13.text)) { - seen[name_13.text] = currentKind; + if (!ts.hasProperty(seen, name_16.text)) { + seen[name_16.text] = currentKind; } else { - var existingKind = seen[name_13.text]; + var existingKind = seen[name_16.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_13.text] = currentKind | existingKind; + seen[name_16.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -19703,9 +20682,9 @@ var ts; } var count = 0; while (true) { - var name_14 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_14)) { - return name_14; + var name_17 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_17)) { + return name_17; } } } @@ -20789,9 +21768,9 @@ var ts; var count = tempFlags & 268435455; tempFlags++; if (count !== 8 && count !== 13) { - var name_15 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); - if (isUniqueName(name_15)) { - return name_15; + var name_18 = count < 26 ? "_" + String.fromCharCode(97 + count) : "_" + (count - 26); + if (isUniqueName(name_18)) { + return name_18; } } } @@ -20819,8 +21798,8 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65) { - var name_16 = node.name.text; - assignGeneratedName(node, isUniqueLocalName(name_16, node) ? name_16 : makeUniqueName(name_16)); + var name_19 = node.name.text; + assignGeneratedName(node, isUniqueLocalName(name_19, node) ? name_19 : makeUniqueName(name_19)); } } function generateNameForImportOrExportDeclaration(node) { @@ -21006,8 +21985,8 @@ var ts; if (scopeName) { var parentIndex = getSourceMapNameIndex(); if (parentIndex !== -1) { - var name_17 = node.name; - if (!name_17 || name_17.kind !== 128) { + var name_20 = node.name; + if (!name_20 || name_20.kind !== 128) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -21034,9 +22013,9 @@ var ts; node.kind === 202 || node.kind === 205) { if (node.name) { - var name_18 = node.name; - scopeName = name_18.kind === 128 - ? ts.getTextOfNode(name_18) + var name_21 = node.name; + scopeName = name_21.kind === 128 + ? ts.getTextOfNode(name_21) : node.name.text; } recordScopeNameStart(scopeName); @@ -21657,15 +22636,15 @@ var ts; } return true; } - function emitListWithSpread(elements, alwaysCopy, multiLine, trailingComma) { + function emitListWithSpread(elements, needsUniqueCopy, multiLine, trailingComma, useConcat) { var pos = 0; var group = 0; var length = elements.length; while (pos < length) { - if (group === 1) { + if (group === 1 && useConcat) { write(".concat("); } - else if (group > 1) { + else if (group > 0) { write(", "); } var e = elements[pos]; @@ -21673,7 +22652,7 @@ var ts; e = e.expression; emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); pos++; - if (pos === length && group === 0 && alwaysCopy && e.kind !== 154) { + if (pos === length && group === 0 && needsUniqueCopy && e.kind !== 154) { write(".slice()"); } } @@ -21696,7 +22675,9 @@ var ts; group++; } if (group > 1) { - write(")"); + if (useConcat) { + write(")"); + } } } function isSpreadElementExpression(node) { @@ -21713,7 +22694,7 @@ var ts; write("]"); } else { - emitListWithSpread(elements, true, (node.flags & 512) !== 0, elements.hasTrailingComma); + emitListWithSpread(elements, true, (node.flags & 512) !== 0, elements.hasTrailingComma, true); } } function emitObjectLiteralBody(node, numElements) { @@ -21929,7 +22910,7 @@ var ts; } } function tryEmitConstantValue(node) { - if (compilerOptions.separateCompilation) { + if (compilerOptions.isolatedModules) { return false; } var constantValue = resolver.getConstantValue(node); @@ -22039,7 +23020,7 @@ var ts; write("void 0"); } write(", "); - emitListWithSpread(node.arguments, false, false, false); + emitListWithSpread(node.arguments, false, false, false, true); write(")"); } function emitCallExpression(node) { @@ -22073,11 +23054,25 @@ var ts; } function emitNewExpression(node) { write("new "); - emit(node.expression); - if (node.arguments) { + if (languageVersion === 1 && + node.arguments && + hasSpreadElement(node.arguments)) { write("("); - emitCommaList(node.arguments); - write(")"); + var target = emitCallTarget(node.expression); + write(".bind.apply("); + emit(target); + write(", [void 0].concat("); + emitListWithSpread(node.arguments, false, false, false, false); + write(")))"); + write("()"); + } + else { + emit(node.expression); + if (node.arguments) { + write("("); + emitCommaList(node.arguments); + write(")"); + } } } function emitTaggedTemplateExpression(node) { @@ -23029,15 +24024,30 @@ var ts; ts.forEach(node.declarationList.declarations, emitExportVariableAssignments); } } + function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node) { + if (!(node.flags & 1)) { + return true; + } + if (isES6ExportedDeclaration(node)) { + return true; + } + for (var _a = 0, _b = node.declarationList.declarations; _a < _b.length; _a++) { + var declaration = _b[_a]; + if (declaration.initializer) { + return true; + } + } + return false; + } function emitParameter(node) { if (languageVersion < 2) { if (ts.isBindingPattern(node.name)) { - var name_19 = createTempVariable(0); + var name_22 = createTempVariable(0); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_19); - emit(name_19); + tempParameters.push(name_22); + emit(name_22); } else { emit(node.name); @@ -23084,7 +24094,7 @@ var ts; } } function emitRestParameter(node) { - if (languageVersion < 2 && ts.hasRestParameters(node)) { + if (languageVersion < 2 && ts.hasRestParameter(node)) { var restIndex = node.parameters.length - 1; var restParam = node.parameters[restIndex]; if (ts.isBindingPattern(restParam.name)) { @@ -23192,7 +24202,7 @@ var ts; write("("); if (node) { var parameters = node.parameters; - var omitCount = languageVersion < 2 && ts.hasRestParameters(node) ? 1 : 0; + var omitCount = languageVersion < 2 && ts.hasRestParameter(node) ? 1 : 0; emitList(parameters, 0, parameters.length - omitCount, false, false); } write(")"); @@ -24025,7 +25035,7 @@ var ts; } function shouldEmitEnumDeclaration(node) { var isConstEnum = ts.isConst(node); - return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.separateCompilation; + return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules; } function emitEnumDeclaration(node) { if (!shouldEmitEnumDeclaration(node)) { @@ -24120,7 +25130,7 @@ var ts; } } function shouldEmitModuleDeclaration(node) { - return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.separateCompilation); + return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules); } function isModuleMergedWithES6Class(node) { return languageVersion === 2 && !!(resolver.getNodeCheckFlags(node) & 2048); @@ -24497,8 +25507,8 @@ var ts; else { for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_20 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_20] || (exportSpecifiers[name_20] = [])).push(specifier); + var name_23 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_23] || (exportSpecifiers[name_23] = [])).push(specifier); } } break; @@ -24671,11 +25681,11 @@ var ts; var seen = {}; for (var i = 0; i < hoistedVars.length; ++i) { var local = hoistedVars[i]; - var name_21 = local.kind === 65 + var name_24 = local.kind === 65 ? local : local.name; - if (name_21) { - var text = ts.unescapeIdentifier(name_21.text); + if (name_24) { + var text = ts.unescapeIdentifier(name_24.text); if (ts.hasProperty(seen, text)) { continue; } @@ -24754,15 +25764,15 @@ var ts; } if (node.kind === 199 || node.kind === 153) { if (shouldHoistVariable(node, false)) { - var name_22 = node.name; - if (name_22.kind === 65) { + var name_25 = node.name; + if (name_25.kind === 65) { if (!hoistedVars) { hoistedVars = []; } - hoistedVars.push(name_22); + hoistedVars.push(name_25); } else { - ts.forEachChild(name_22, visit); + ts.forEachChild(name_25, visit); } } return; @@ -25076,7 +26086,7 @@ var ts; paramEmitted = true; } } - if (ts.isExternalModule(node) || compilerOptions.separateCompilation) { + if (ts.isExternalModule(node) || compilerOptions.isolatedModules) { if (languageVersion >= 2) { emitES6Module(node, startIndex); } @@ -25129,6 +26139,8 @@ var ts; case 204: case 215: return false; + case 181: + return shouldEmitLeadingAndTrailingCommentsForVariableStatement(node); case 206: return shouldEmitModuleDeclaration(node); case 205: @@ -25432,7 +26444,7 @@ var ts; ts.emitTime = 0; ts.ioReadTime = 0; ts.ioWriteTime = 0; - ts.version = "1.5.2"; + ts.version = "1.5.3"; var carriageReturnLineFeed = "\r\n"; var lineFeed = "\n"; function findConfigFile(searchPath) { @@ -25854,18 +26866,18 @@ var ts; return allFilesBelongToPath; } function verifyCompilerOptions() { - if (options.separateCompilation) { + if (options.isolatedModules) { if (options.sourceMap) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceMap_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceMap_cannot_be_specified_with_option_isolatedModules)); } if (options.declaration) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_declaration_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_declaration_cannot_be_specified_with_option_isolatedModules)); } if (options.noEmitOnError) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules)); } if (options.out) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_out_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_out_cannot_be_specified_with_option_isolatedModules)); } } if (options.inlineSourceMap) { @@ -25895,14 +26907,14 @@ var ts; } var languageVersion = options.target || 0; var firstExternalModuleSourceFile = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); - if (options.separateCompilation) { + if (options.isolatedModules) { if (!options.module && languageVersion < 2) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); } var firstNonExternalModuleSourceFile = ts.forEach(files, function (f) { return !ts.isExternalModule(f) && !ts.isDeclarationFile(f) ? f : undefined; }); if (firstNonExternalModuleSourceFile) { var span = ts.getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile); - diagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_separateCompilation_flag_is_provided)); + diagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); } } else if (firstExternalModuleSourceFile && languageVersion < 2 && !options.module) { @@ -25934,6 +26946,10 @@ var ts; diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration)); } } + if (options.emitDecoratorMetadata && + !options.experimentalDecorators) { + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified)); + } } } ts.createProgram = createProgram; @@ -26384,24 +27400,24 @@ var ts; switch (n.kind) { case 180: if (!ts.isFunctionBlock(n)) { - var parent_6 = n.parent; + var parent_7 = n.parent; var openBrace = ts.findChildOfKind(n, 14, sourceFile); var closeBrace = ts.findChildOfKind(n, 15, sourceFile); - if (parent_6.kind === 185 || - parent_6.kind === 188 || - parent_6.kind === 189 || - parent_6.kind === 187 || - parent_6.kind === 184 || - parent_6.kind === 186 || - parent_6.kind === 193 || - parent_6.kind === 224) { - addOutliningSpan(parent_6, openBrace, closeBrace, autoCollapse(n)); + if (parent_7.kind === 185 || + parent_7.kind === 188 || + parent_7.kind === 189 || + parent_7.kind === 187 || + parent_7.kind === 184 || + parent_7.kind === 186 || + parent_7.kind === 193 || + parent_7.kind === 224) { + addOutliningSpan(parent_7, openBrace, closeBrace, autoCollapse(n)); break; } - if (parent_6.kind === 197) { - var tryStatement = parent_6; + if (parent_7.kind === 197) { + var tryStatement = parent_7; if (tryStatement.tryBlock === n) { - addOutliningSpan(parent_6, openBrace, closeBrace, autoCollapse(n)); + addOutliningSpan(parent_7, openBrace, closeBrace, autoCollapse(n)); break; } else if (tryStatement.finallyBlock === n) { @@ -26463,10 +27479,10 @@ var ts; ts.forEach(program.getSourceFiles(), function (sourceFile) { cancellationToken.throwIfCancellationRequested(); var nameToDeclarations = sourceFile.getNamedDeclarations(); - for (var name_23 in nameToDeclarations) { - var declarations = ts.getProperty(nameToDeclarations, name_23); + for (var name_26 in nameToDeclarations) { + var declarations = ts.getProperty(nameToDeclarations, name_26); if (declarations) { - var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_23); + var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_26); if (!matches) { continue; } @@ -26477,14 +27493,14 @@ var ts; if (!containers) { return undefined; } - matches = patternMatcher.getMatches(containers, name_23); + matches = patternMatcher.getMatches(containers, name_26); if (!matches) { continue; } } var fileName = sourceFile.fileName; var matchKind = bestMatchKind(matches); - rawItems.push({ name: name_23, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); + rawItems.push({ name: name_26, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } } } @@ -26814,9 +27830,9 @@ var ts; case 199: case 153: var variableDeclarationNode; - var name_24; + var name_27; if (node.kind === 153) { - name_24 = node.name; + name_27 = node.name; variableDeclarationNode = node; while (variableDeclarationNode && variableDeclarationNode.kind !== 199) { variableDeclarationNode = variableDeclarationNode.parent; @@ -26826,16 +27842,16 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_24 = node.name; + name_27 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.variableElement); } case 136: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -27924,7 +28940,7 @@ var ts; ts.findChildOfKind = findChildOfKind; function findContainingList(node) { var syntaxList = ts.forEach(node.parent.getChildren(), function (c) { - if (c.kind === 229 && c.pos <= node.pos && c.end >= node.end) { + if (c.kind === 251 && c.pos <= node.pos && c.end >= node.end) { return c; } }); @@ -28294,10 +29310,6 @@ var ts; }); } ts.signatureToDisplayParts = signatureToDisplayParts; - function isJavaScript(fileName) { - return ts.fileExtensionIs(fileName, ".js"); - } - ts.isJavaScript = isJavaScript; })(ts || (ts = {})); /// /// @@ -28701,7 +29713,7 @@ var ts; this.NoSpaceBeforeOpenBracket = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 18), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.NoSpaceAfterOpenBracket = new formatting.Rule(formatting.RuleDescriptor.create3(18, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.NoSpaceBeforeCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 19), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); - this.NoSpaceAfterCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create3(19, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); + this.NoSpaceAfterCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create3(19, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBeforeBlockInFunctionDeclarationContext), 8)); this.FunctionOpenBraceLeftTokenRange = formatting.Shared.TokenRange.AnyIncludingMultilineComments; this.SpaceBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 14), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2), 1); this.TypeScriptOpenBraceLeftTokenRange = formatting.Shared.TokenRange.FromTokens([65, 3]); @@ -28754,6 +29766,10 @@ var ts; this.SpaceBeforeAt = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 52), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2)); this.NoSpaceAfterAt = new formatting.Rule(formatting.RuleDescriptor.create3(52, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8)); this.SpaceAfterDecorator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([65, 78, 73, 69, 109, 108, 106, 107, 116, 121, 18, 35])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), 2)); + this.NoSpaceBetweenFunctionKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(83, 35), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 8)); + this.SpaceAfterStarInGeneratorDeclaration = new formatting.Rule(formatting.RuleDescriptor.create3(35, formatting.Shared.TokenRange.FromTokens([65, 16])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 2)); + this.NoSpaceBetweenYieldKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(110, 35), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 8)); + this.SpaceBetweenYieldOrYieldStarAndOperand = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([110, 35]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 2)); this.HighPriorityCommonRules = [ this.IgnoreBeforeComment, this.IgnoreAfterLineComment, @@ -28770,7 +29786,9 @@ var ts; this.NoSpaceAfterCloseBrace, this.SpaceAfterOpenBrace, this.SpaceBeforeCloseBrace, this.NewLineBeforeCloseBraceInBlockContext, this.SpaceAfterCloseBrace, this.SpaceBetweenCloseBraceAndElse, this.SpaceBetweenCloseBraceAndWhile, this.NoSpaceBetweenEmptyBraceBrackets, + this.NoSpaceBetweenFunctionKeywordAndStar, this.SpaceAfterStarInGeneratorDeclaration, this.SpaceAfterFunctionInFuncDecl, this.NewLineAfterOpenBraceInBlockContext, this.SpaceAfterGetSetInMember, + this.NoSpaceBetweenYieldKeywordAndStar, this.SpaceBetweenYieldOrYieldStarAndOperand, this.NoSpaceBetweenReturnAndSemicolon, this.SpaceAfterCertainKeywords, this.SpaceAfterLetConstInVariableDeclaration, @@ -28827,9 +29845,9 @@ var ts; } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_25 in o) { - if (o[name_25] === rule) { - return name_25; + for (var name_28 in o) { + if (o[name_28] === rule) { + return name_28; } } throw new Error("Unknown rule"); @@ -28930,6 +29948,9 @@ var ts; } return false; }; + Rules.IsFunctionDeclarationOrFunctionExpressionContext = function (context) { + return context.contextNode.kind === 201 || context.contextNode.kind === 163; + }; Rules.IsTypeScriptDeclWithBlockContext = function (context) { return Rules.NodeIsTypeScriptDeclWithBlockContext(context.contextNode); }; @@ -28992,6 +30013,9 @@ var ts; Rules.IsSameLineTokenContext = function (context) { return context.TokensAreOnSameLine(); }; + Rules.IsNotBeforeBlockInFunctionDeclarationContext = function (context) { + return !Rules.IsFunctionDeclContext(context) && !Rules.IsBeforeBlockContext(context); + }; Rules.IsEndOfDecoratorContextOnSameLine = function (context) { return context.TokensAreOnSameLine() && context.contextNode.decorators && @@ -29046,6 +30070,9 @@ var ts; Rules.IsVoidOpContext = function (context) { return context.currentTokenSpan.kind === 99 && context.currentTokenParent.kind === 167; }; + Rules.IsYieldOrYieldStarWithOperand = function (context) { + return context.contextNode.kind === 173 && context.contextNode.expression !== undefined; + }; return Rules; })(); formatting.Rules = Rules; @@ -30545,7 +31572,7 @@ var ts; return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(229, nodes.pos, nodes.end, 1024, this); + var list = createNode(251, nodes.pos, nodes.end, 1024, this); list._children = []; var pos = nodes.pos; for (var _i = 0; _i < nodes.length; _i++) { @@ -31204,6 +32231,7 @@ var ts; ClassificationTypeNames.typeParameterName = "type parameter name"; ClassificationTypeNames.typeAliasName = "type alias name"; ClassificationTypeNames.parameterName = "parameter name"; + ClassificationTypeNames.docCommentTagName = "doc comment tag name"; return ClassificationTypeNames; })(); ts.ClassificationTypeNames = ClassificationTypeNames; @@ -31225,8 +32253,8 @@ var ts; if (declaration.kind !== 199 && declaration.kind !== 201) { return false; } - for (var parent_7 = declaration.parent; !ts.isFunctionBlock(parent_7); parent_7 = parent_7.parent) { - if (parent_7.kind === 228 || parent_7.kind === 207) { + for (var parent_8 = declaration.parent; !ts.isFunctionBlock(parent_8); parent_8 = parent_8.parent) { + if (parent_8.kind === 228 || parent_8.kind === 207) { return false; } } @@ -31359,7 +32387,7 @@ var ts; } function transpile(input, compilerOptions, fileName, diagnostics) { var options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); - options.separateCompilation = true; + options.isolatedModules = true; options.allowNonTsExtensions = true; var inputFileName = fileName || "module.ts"; var sourceFile = ts.createSourceFile(inputFileName, input, options.target); @@ -31389,7 +32417,8 @@ var ts; } ts.transpile = transpile; function createLanguageServiceSourceFile(fileName, scriptSnapshot, scriptTarget, version, setNodeParents) { - var sourceFile = ts.createSourceFile(fileName, scriptSnapshot.getText(0, scriptSnapshot.getLength()), scriptTarget, setNodeParents); + var text = scriptSnapshot.getText(0, scriptSnapshot.getLength()); + var sourceFile = ts.createSourceFile(fileName, text, scriptTarget, setNodeParents); setSourceFileFields(sourceFile, scriptSnapshot, version); sourceFile.nameTable = sourceFile.identifiers; return sourceFile; @@ -31400,7 +32429,25 @@ var ts; if (textChangeRange) { if (version !== sourceFile.version) { if (!ts.disableIncrementalParsing) { - var newSourceFile = ts.updateSourceFile(sourceFile, scriptSnapshot.getText(0, scriptSnapshot.getLength()), textChangeRange, aggressiveChecks); + var newText; + var prefix = textChangeRange.span.start !== 0 + ? sourceFile.text.substr(0, textChangeRange.span.start) + : ""; + var suffix = ts.textSpanEnd(textChangeRange.span) !== sourceFile.text.length + ? sourceFile.text.substr(ts.textSpanEnd(textChangeRange.span)) + : ""; + if (textChangeRange.newLength === 0) { + newText = prefix && suffix ? prefix + suffix : prefix || suffix; + } + else { + var changedText = scriptSnapshot.getText(textChangeRange.span.start, textChangeRange.span.start + textChangeRange.newLength); + newText = prefix && suffix + ? prefix + changedText + suffix + : prefix + ? (prefix + changedText) + : (changedText + suffix); + } + var newSourceFile = ts.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks); setSourceFileFields(newSourceFile, scriptSnapshot, version); newSourceFile.nameTable = undefined; return newSourceFile; @@ -31878,10 +32925,12 @@ var ts; } } } + hostCache = undefined; program = newProgram; program.getTypeChecker(); return; function getOrCreateSourceFile(fileName) { + ts.Debug.assert(hostCache !== undefined); var hostFileInformation = hostCache.getOrCreateEntry(fileName); if (!hostFileInformation) { return undefined; @@ -32027,7 +33076,7 @@ var ts; return true; } if (parameter.questionToken) { - diagnostics.push(ts.createDiagnosticForNode(parameter.questionToken, ts.Diagnostics.can_only_be_used_in_a_ts_file)); + diagnostics.push(ts.createDiagnosticForNode(parameter.questionToken, ts.Diagnostics._0_can_only_be_used_in_a_ts_file, '?')); return true; } if (parameter.type) { @@ -32136,6 +33185,7 @@ var ts; var typeChecker = program.getTypeChecker(); var syntacticStart = new Date().getTime(); var sourceFile = getValidSourceFile(fileName); + var isJavaScriptFile = ts.isJavaScript(fileName); var start = new Date().getTime(); var currentToken = ts.getTokenAtPosition(sourceFile, position); log("getCompletionData: Get current token: " + (new Date().getTime() - start)); @@ -32203,12 +33253,23 @@ var ts; } } var type = typeChecker.getTypeAtLocation(node); + addTypeProperties(type); + } + function addTypeProperties(type) { if (type) { - ts.forEach(type.getApparentProperties(), function (symbol) { + for (var _i = 0, _a = type.getApparentProperties(); _i < _a.length; _i++) { + var symbol = _a[_i]; if (typeChecker.isValidPropertyAccess((node.parent), symbol.name)) { symbols.push(symbol); } - }); + } + if (isJavaScriptFile && type.flags & 16384) { + var unionType = type; + for (var _b = 0, _c = unionType.types; _b < _c.length; _b++) { + var elementType = _c[_b]; + addTypeProperties(elementType); + } + } } } function tryGetGlobalSymbols() { @@ -32335,8 +33396,9 @@ var ts; if (start_3 < position && position < end) { return true; } - else if (position === end) { - return !!previousToken.isUnterminated; + if (position === end) { + return !!previousToken.isUnterminated || + previousToken.kind === 9; } } return false; @@ -32344,12 +33406,12 @@ var ts; function getContainingObjectLiteralApplicableForCompletion(previousToken) { // The locations in an object literal expression that are applicable for completion are property name definition locations. if (previousToken) { - var parent_8 = previousToken.parent; + var parent_9 = previousToken.parent; switch (previousToken.kind) { case 14: case 23: - if (parent_8 && parent_8.kind === 155) { - return parent_8; + if (parent_9 && parent_9.kind === 155) { + return parent_9; } break; } @@ -32527,10 +33589,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_26 in nameTable) { - if (!allNames[name_26]) { - allNames[name_26] = name_26; - var displayName = getCompletionEntryDisplayName(name_26, target, true); + for (var name_29 in nameTable) { + if (!allNames[name_29]) { + allNames[name_29] = name_29; + var displayName = getCompletionEntryDisplayName(name_29, target, true); if (displayName) { var entry = { name: displayName, @@ -33366,17 +34428,17 @@ var ts; function getThrowStatementOwner(throwStatement) { var child = throwStatement; while (child.parent) { - var parent_9 = child.parent; - if (ts.isFunctionBlock(parent_9) || parent_9.kind === 228) { - return parent_9; + var parent_10 = child.parent; + if (ts.isFunctionBlock(parent_10) || parent_10.kind === 228) { + return parent_10; } - if (parent_9.kind === 197) { - var tryStatement = parent_9; + if (parent_10.kind === 197) { + var tryStatement = parent_10; if (tryStatement.tryBlock === child && tryStatement.catchClause) { return child; } } - child = parent_9; + child = parent_10; } return undefined; } @@ -34209,17 +35271,17 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeChecker.getContextualType(objectLiteral); - var name_27 = node.text; + var name_30 = node.text; if (contextualType) { if (contextualType.flags & 16384) { - var unionProperty = contextualType.getProperty(name_27); + var unionProperty = contextualType.getProperty(name_30); if (unionProperty) { return [unionProperty]; } else { var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_27); + var symbol = t.getProperty(name_30); if (symbol) { result_4.push(symbol); } @@ -34228,7 +35290,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_27); + var symbol_1 = contextualType.getProperty(name_30); if (symbol_1) { return [symbol_1]; } @@ -34565,6 +35627,7 @@ var ts; case 15: return ClassificationTypeNames.typeParameterName; case 16: return ClassificationTypeNames.typeAliasName; case 17: return ClassificationTypeNames.parameterName; + case 18: return ClassificationTypeNames.docCommentTagName; } } function convertClassifications(classifications) { @@ -34610,7 +35673,7 @@ var ts; } if (ts.textSpanIntersectsWith(span, start, width)) { if (ts.isComment(kind)) { - pushClassification(start, width, 1); + classifyComment(token, kind, start, width); continue; } if (kind === 6) { @@ -34626,6 +35689,74 @@ var ts; } } } + function classifyComment(token, kind, start, width) { + if (kind === 3) { + var docCommentAndDiagnostics = ts.parseIsolatedJSDocComment(sourceFile.text, start, width); + if (docCommentAndDiagnostics && docCommentAndDiagnostics.jsDocComment) { + docCommentAndDiagnostics.jsDocComment.parent = token; + classifyJSDocComment(docCommentAndDiagnostics.jsDocComment); + return; + } + } + pushCommentRange(start, width); + } + function pushCommentRange(start, width) { + pushClassification(start, width, 1); + } + function classifyJSDocComment(docComment) { + var pos = docComment.pos; + for (var _i = 0, _a = docComment.tags; _i < _a.length; _i++) { + var tag = _a[_i]; + if (tag.pos !== pos) { + pushCommentRange(pos, tag.pos - pos); + } + pushClassification(tag.atToken.pos, tag.atToken.end - tag.atToken.pos, 10); + pushClassification(tag.tagName.pos, tag.tagName.end - tag.tagName.pos, 18); + pos = tag.tagName.end; + switch (tag.kind) { + case 247: + processJSDocParameterTag(tag); + break; + case 250: + processJSDocTemplateTag(tag); + break; + case 249: + processElement(tag.typeExpression); + break; + case 248: + processElement(tag.typeExpression); + break; + } + pos = tag.end; + } + if (pos !== docComment.end) { + pushCommentRange(pos, docComment.end - pos); + } + return; + function processJSDocParameterTag(tag) { + if (tag.preParameterName) { + pushCommentRange(pos, tag.preParameterName.pos - pos); + pushClassification(tag.preParameterName.pos, tag.preParameterName.end - tag.preParameterName.pos, 17); + pos = tag.preParameterName.end; + } + if (tag.typeExpression) { + pushCommentRange(pos, tag.typeExpression.pos - pos); + processElement(tag.typeExpression); + pos = tag.typeExpression.end; + } + if (tag.postParameterName) { + pushCommentRange(pos, tag.postParameterName.pos - pos); + pushClassification(tag.postParameterName.pos, tag.postParameterName.end - tag.postParameterName.pos, 17); + pos = tag.postParameterName.end; + } + } + } + function processJSDocTemplateTag(tag) { + for (var _i = 0, _a = tag.getChildren(); _i < _a.length; _i++) { + var child = _a[_i]; + processElement(child); + } + } function classifyDisabledMergeCode(text, start, end) { for (var i = start; i < end; i++) { if (ts.isLineBreak(text.charCodeAt(i))) { @@ -34734,8 +35865,11 @@ var ts; } } function processElement(element) { + if (!element) { + return; + } if (ts.textSpanIntersectsWith(span, element.getFullStart(), element.getFullWidth())) { - var children = element.getChildren(); + var children = element.getChildren(sourceFile); for (var _i = 0; _i < children.length; _i++) { var child = children[_i]; if (ts.isToken(child)) { @@ -35039,7 +36173,7 @@ var ts; var lastEnd = 0; for (var i = 0, n = dense.length; i < n; i += 3) { var start = dense[i]; - var length_1 = dense[i + 1]; + var length_2 = dense[i + 1]; var type = dense[i + 2]; if (lastEnd >= 0) { var whitespaceLength_1 = start - lastEnd; @@ -35047,8 +36181,8 @@ var ts; entries.push({ length: whitespaceLength_1, classification: TokenClass.Whitespace }); } } - entries.push({ length: length_1, classification: convertClassification(type) }); - lastEnd = start + length_1; + entries.push({ length: length_2, classification: convertClassification(type) }); + lastEnd = start + length_2; } var whitespaceLength = text.length - lastEnd; if (whitespaceLength > 0) { @@ -35451,6 +36585,7 @@ var ts; CommandNames.Saveto = "saveto"; CommandNames.SignatureHelp = "signatureHelp"; CommandNames.TypeDefinition = "typeDefinition"; + CommandNames.ProjectInfo = "projectInfo"; CommandNames.Unknown = "unknown"; })(CommandNames = server.CommandNames || (server.CommandNames = {})); var Errors; @@ -35664,6 +36799,17 @@ var ts; }; }); }; + Session.prototype.getProjectInfo = function (fileName, needFileNameList) { + fileName = ts.normalizePath(fileName); + var project = this.projectService.getProjectForFile(fileName); + var projectInfo = { + configFileName: project.projectFilename + }; + if (needFileNameList) { + projectInfo.fileNameList = project.getFileNameList(); + } + return projectInfo; + }; Session.prototype.getRenameLocations = function (line, offset, fileName, findInComments, findInStrings) { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); @@ -36205,6 +37351,11 @@ var ts; response = this.getOccurrences(line, offset, fileName); break; } + case CommandNames.ProjectInfo: { + var _b = request.arguments, file = _b.file, needFileNameList = _b.needFileNameList; + response = this.getProjectInfo(file, needFileNameList); + break; + } default: { this.projectService.log("Unrecognized JSON command: " + message); this.output(undefined, CommandNames.Unknown, request.seq, "Unrecognized JSON command: " + request.command); @@ -36477,6 +37628,10 @@ var ts; Project.prototype.openReferencedFile = function (filename) { return this.projectService.openFile(filename, false); }; + Project.prototype.getFileNameList = function () { + var sourceFiles = this.program.getSourceFiles(); + return sourceFiles.map(function (sourceFile) { return sourceFile.fileName; }); + }; Project.prototype.getSourceFile = function (info) { return this.filenameToSourceFile[info.fileName]; }; diff --git a/bin/typescript.d.ts b/bin/typescript.d.ts index bcb379ed52..58b03102d3 100644 --- a/bin/typescript.d.ts +++ b/bin/typescript.d.ts @@ -251,8 +251,30 @@ declare module "typescript" { ShorthandPropertyAssignment = 226, EnumMember = 227, SourceFile = 228, - SyntaxList = 229, - Count = 230, + JSDocTypeExpression = 229, + JSDocAllType = 230, + JSDocUnknownType = 231, + JSDocArrayType = 232, + JSDocUnionType = 233, + JSDocTupleType = 234, + JSDocNullableType = 235, + JSDocNonNullableType = 236, + JSDocRecordType = 237, + JSDocRecordMember = 238, + JSDocTypeReference = 239, + JSDocOptionalType = 240, + JSDocFunctionType = 241, + JSDocVariadicType = 242, + JSDocConstructorType = 243, + JSDocThisType = 244, + JSDocComment = 245, + JSDocTag = 246, + JSDocParameterTag = 247, + JSDocReturnTag = 248, + JSDocTypeTag = 249, + JSDocTemplateTag = 250, + SyntaxList = 251, + Count = 252, FirstAssignment = 53, LastAssignment = 64, FirstReservedWord = 66, @@ -495,7 +517,7 @@ declare module "typescript" { } interface YieldExpression extends Expression { asteriskToken?: Node; - expression: Expression; + expression?: Expression; } interface BinaryExpression extends Expression { left: Expression; @@ -666,7 +688,7 @@ declare module "typescript" { interface ClassElement extends Declaration { _classElementBrand: any; } - interface InterfaceDeclaration extends Declaration, ModuleElement { + interface InterfaceDeclaration extends Declaration, Statement { name: Identifier; typeParameters?: NodeArray; heritageClauses?: NodeArray; @@ -676,7 +698,7 @@ declare module "typescript" { token: SyntaxKind; types?: NodeArray; } - interface TypeAliasDeclaration extends Declaration, ModuleElement { + interface TypeAliasDeclaration extends Declaration, Statement { name: Identifier; type: TypeNode; } @@ -684,7 +706,7 @@ declare module "typescript" { name: DeclarationName; initializer?: Expression; } - interface EnumDeclaration extends Declaration, ModuleElement { + interface EnumDeclaration extends Declaration, Statement { name: Identifier; members: NodeArray; } @@ -739,6 +761,82 @@ declare module "typescript" { hasTrailingNewLine?: boolean; kind: SyntaxKind; } + interface JSDocTypeExpression extends Node { + type: JSDocType; + } + interface JSDocType extends TypeNode { + _jsDocTypeBrand: any; + } + interface JSDocAllType extends JSDocType { + _JSDocAllTypeBrand: any; + } + interface JSDocUnknownType extends JSDocType { + _JSDocUnknownTypeBrand: any; + } + interface JSDocArrayType extends JSDocType { + elementType: JSDocType; + } + interface JSDocUnionType extends JSDocType { + types: NodeArray; + } + interface JSDocTupleType extends JSDocType { + types: NodeArray; + } + interface JSDocNonNullableType extends JSDocType { + type: JSDocType; + } + interface JSDocNullableType extends JSDocType { + type: JSDocType; + } + interface JSDocRecordType extends JSDocType, TypeLiteralNode { + members: NodeArray; + } + interface JSDocTypeReference extends JSDocType { + name: EntityName; + typeArguments: NodeArray; + } + interface JSDocOptionalType extends JSDocType { + type: JSDocType; + } + interface JSDocFunctionType extends JSDocType, SignatureDeclaration { + parameters: NodeArray; + type: JSDocType; + } + interface JSDocVariadicType extends JSDocType { + type: JSDocType; + } + interface JSDocConstructorType extends JSDocType { + type: JSDocType; + } + interface JSDocThisType extends JSDocType { + type: JSDocType; + } + interface JSDocRecordMember extends PropertyDeclaration { + name: Identifier | LiteralExpression; + type?: JSDocType; + } + interface JSDocComment extends Node { + tags: NodeArray; + } + interface JSDocTag extends Node { + atToken: Node; + tagName: Identifier; + } + interface JSDocTemplateTag extends JSDocTag { + typeParameters: NodeArray; + } + interface JSDocReturnTag extends JSDocTag { + typeExpression: JSDocTypeExpression; + } + interface JSDocTypeTag extends JSDocTag { + typeExpression: JSDocTypeExpression; + } + interface JSDocParameterTag extends JSDocTag { + preParameterName?: Identifier; + typeExpression?: JSDocTypeExpression; + postParameterName?: Identifier; + isBracketed: boolean; + } interface SourceFile extends Declaration { statements: NodeArray; endOfFileToken: Node; @@ -901,6 +999,7 @@ declare module "typescript" { UseOnlyExternalAliasing = 2, } const enum SymbolFlags { + None = 0, FunctionScopedVariable = 1, BlockScopedVariable = 2, Property = 4, @@ -959,10 +1058,8 @@ declare module "typescript" { AliasExcludes = 8388608, ModuleMember = 8914931, ExportHasLocal = 944, - HasLocals = 255504, HasExports = 1952, HasMembers = 6240, - IsContainer = 262128, PropertyOrAccessor = 98308, Export = 7340032, } @@ -970,9 +1067,9 @@ declare module "typescript" { flags: SymbolFlags; name: string; declarations?: Declaration[]; + valueDeclaration?: Declaration; members?: SymbolTable; exports?: SymbolTable; - valueDeclaration?: Declaration; } interface SymbolTable { [index: string]: Symbol; @@ -1011,6 +1108,8 @@ declare module "typescript" { } interface InterfaceType extends ObjectType { typeParameters: TypeParameter[]; + outerTypeParameters: TypeParameter[]; + localTypeParameters: TypeParameter[]; } interface InterfaceTypeWithBaseTypes extends InterfaceType { baseTypes: ObjectType[]; @@ -1114,7 +1213,8 @@ declare module "typescript" { target?: ScriptTarget; version?: boolean; watch?: boolean; - separateCompilation?: boolean; + isolatedModules?: boolean; + experimentalDecorators?: boolean; emitDecoratorMetadata?: boolean; [option: string]: string | number | boolean; } @@ -1226,8 +1326,6 @@ declare module "typescript" { function getTrailingCommentRanges(text: string, pos: number): CommentRange[]; function isIdentifierStart(ch: number, languageVersion: ScriptTarget): boolean; function isIdentifierPart(ch: number, languageVersion: ScriptTarget): boolean; - /** Creates a scanner over a (possibly unspecified) range of a piece of text. */ - function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, text?: string, onError?: ErrorCallback, start?: number, length?: number): Scanner; } declare module "typescript" { function getDefaultLibFileName(options: CompilerOptions): string; @@ -1256,6 +1354,7 @@ declare module "typescript" { * Vn. */ function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; + function getTypeParameterOwner(d: Declaration): Declaration; } declare module "typescript" { function getNodeConstructor(kind: SyntaxKind): new () => Node; @@ -1812,6 +1911,7 @@ declare module "typescript" { static typeParameterName: string; static typeAliasName: string; static parameterName: string; + static docCommentTagName: string; } const enum ClassificationType { comment = 1, @@ -1831,6 +1931,7 @@ declare module "typescript" { typeParameterName = 15, typeAliasName = 16, parameterName = 17, + docCommentTagName = 18, } interface DisplayPartsSymbolWriter extends SymbolWriter { displayParts(): SymbolDisplayPart[]; diff --git a/bin/typescript.js b/bin/typescript.js index 4cab75bfcb..2b3f25998a 100644 --- a/bin/typescript.js +++ b/bin/typescript.js @@ -270,10 +270,35 @@ var ts; SyntaxKind[SyntaxKind["EnumMember"] = 227] = "EnumMember"; // Top-level nodes SyntaxKind[SyntaxKind["SourceFile"] = 228] = "SourceFile"; + // JSDoc nodes. + SyntaxKind[SyntaxKind["JSDocTypeExpression"] = 229] = "JSDocTypeExpression"; + // The * type. + SyntaxKind[SyntaxKind["JSDocAllType"] = 230] = "JSDocAllType"; + // The ? type. + SyntaxKind[SyntaxKind["JSDocUnknownType"] = 231] = "JSDocUnknownType"; + SyntaxKind[SyntaxKind["JSDocArrayType"] = 232] = "JSDocArrayType"; + SyntaxKind[SyntaxKind["JSDocUnionType"] = 233] = "JSDocUnionType"; + SyntaxKind[SyntaxKind["JSDocTupleType"] = 234] = "JSDocTupleType"; + SyntaxKind[SyntaxKind["JSDocNullableType"] = 235] = "JSDocNullableType"; + SyntaxKind[SyntaxKind["JSDocNonNullableType"] = 236] = "JSDocNonNullableType"; + SyntaxKind[SyntaxKind["JSDocRecordType"] = 237] = "JSDocRecordType"; + SyntaxKind[SyntaxKind["JSDocRecordMember"] = 238] = "JSDocRecordMember"; + SyntaxKind[SyntaxKind["JSDocTypeReference"] = 239] = "JSDocTypeReference"; + SyntaxKind[SyntaxKind["JSDocOptionalType"] = 240] = "JSDocOptionalType"; + SyntaxKind[SyntaxKind["JSDocFunctionType"] = 241] = "JSDocFunctionType"; + SyntaxKind[SyntaxKind["JSDocVariadicType"] = 242] = "JSDocVariadicType"; + SyntaxKind[SyntaxKind["JSDocConstructorType"] = 243] = "JSDocConstructorType"; + SyntaxKind[SyntaxKind["JSDocThisType"] = 244] = "JSDocThisType"; + SyntaxKind[SyntaxKind["JSDocComment"] = 245] = "JSDocComment"; + SyntaxKind[SyntaxKind["JSDocTag"] = 246] = "JSDocTag"; + SyntaxKind[SyntaxKind["JSDocParameterTag"] = 247] = "JSDocParameterTag"; + SyntaxKind[SyntaxKind["JSDocReturnTag"] = 248] = "JSDocReturnTag"; + SyntaxKind[SyntaxKind["JSDocTypeTag"] = 249] = "JSDocTypeTag"; + SyntaxKind[SyntaxKind["JSDocTemplateTag"] = 250] = "JSDocTemplateTag"; // Synthesized list - SyntaxKind[SyntaxKind["SyntaxList"] = 229] = "SyntaxList"; + SyntaxKind[SyntaxKind["SyntaxList"] = 251] = "SyntaxList"; // Enum value count - SyntaxKind[SyntaxKind["Count"] = 230] = "Count"; + SyntaxKind[SyntaxKind["Count"] = 252] = "Count"; // Markers SyntaxKind[SyntaxKind["FirstAssignment"] = 53] = "FirstAssignment"; SyntaxKind[SyntaxKind["LastAssignment"] = 64] = "LastAssignment"; @@ -323,6 +348,7 @@ var ts; var NodeFlags = ts.NodeFlags; /* @internal */ (function (ParserContextFlags) { + ParserContextFlags[ParserContextFlags["None"] = 0] = "None"; // Set if this node was parsed in strict mode. Used for grammar error checks, as well as // checking if the node can be reused in incremental settings. ParserContextFlags[ParserContextFlags["StrictMode"] = 1] = "StrictMode"; @@ -338,14 +364,17 @@ var ts; // the parser only sets this directly on the node it creates right after encountering the // error. ParserContextFlags[ParserContextFlags["ThisNodeHasError"] = 32] = "ThisNodeHasError"; + // This node was parsed in a JavaScript file and can be processed differently. For example + // its type can be specified usign a JSDoc comment. + ParserContextFlags[ParserContextFlags["JavaScriptFile"] = 64] = "JavaScriptFile"; // Context flags set directly by the parser. ParserContextFlags[ParserContextFlags["ParserGeneratedFlags"] = 63] = "ParserGeneratedFlags"; // Context flags computed by aggregating child flags upwards. // Used during incremental parsing to determine if this node or any of its children had an // error. Computed only once and then cached. - ParserContextFlags[ParserContextFlags["ThisNodeOrAnySubNodesHasError"] = 64] = "ThisNodeOrAnySubNodesHasError"; + ParserContextFlags[ParserContextFlags["ThisNodeOrAnySubNodesHasError"] = 128] = "ThisNodeOrAnySubNodesHasError"; // Used to know if we've computed data from children and cached it in this node. - ParserContextFlags[ParserContextFlags["HasAggregatedChildData"] = 128] = "HasAggregatedChildData"; + ParserContextFlags[ParserContextFlags["HasAggregatedChildData"] = 256] = "HasAggregatedChildData"; })(ts.ParserContextFlags || (ts.ParserContextFlags = {})); var ParserContextFlags = ts.ParserContextFlags; /* @internal */ @@ -400,6 +429,7 @@ var ts; })(ts.SymbolAccessibility || (ts.SymbolAccessibility = {})); var SymbolAccessibility = ts.SymbolAccessibility; (function (SymbolFlags) { + SymbolFlags[SymbolFlags["None"] = 0] = "None"; SymbolFlags[SymbolFlags["FunctionScopedVariable"] = 1] = "FunctionScopedVariable"; SymbolFlags[SymbolFlags["BlockScopedVariable"] = 2] = "BlockScopedVariable"; SymbolFlags[SymbolFlags["Property"] = 4] = "Property"; @@ -462,10 +492,8 @@ var ts; SymbolFlags[SymbolFlags["AliasExcludes"] = 8388608] = "AliasExcludes"; SymbolFlags[SymbolFlags["ModuleMember"] = 8914931] = "ModuleMember"; SymbolFlags[SymbolFlags["ExportHasLocal"] = 944] = "ExportHasLocal"; - SymbolFlags[SymbolFlags["HasLocals"] = 255504] = "HasLocals"; SymbolFlags[SymbolFlags["HasExports"] = 1952] = "HasExports"; SymbolFlags[SymbolFlags["HasMembers"] = 6240] = "HasMembers"; - SymbolFlags[SymbolFlags["IsContainer"] = 262128] = "IsContainer"; SymbolFlags[SymbolFlags["PropertyOrAccessor"] = 98308] = "PropertyOrAccessor"; SymbolFlags[SymbolFlags["Export"] = 7340032] = "Export"; })(ts.SymbolFlags || (ts.SymbolFlags = {})); @@ -826,6 +854,16 @@ var ts; } } ts.addRange = addRange; + function rangeEquals(array1, array2, pos, end) { + while (pos < end) { + if (array1[pos] !== array2[pos]) { + return false; + } + pos++; + } + return true; + } + ts.rangeEquals = rangeEquals; /** * Returns the last element of an array if non-empty, undefined otherwise. */ @@ -995,8 +1033,10 @@ var ts; var end = start + length; Debug.assert(start >= 0, "start must be non-negative, is " + start); Debug.assert(length >= 0, "length must be non-negative, is " + length); - Debug.assert(start <= file.text.length, "start must be within the bounds of the file. " + start + " > " + file.text.length); - Debug.assert(end <= file.text.length, "end must be the bounds of the file. " + end + " > " + file.text.length); + if (file) { + Debug.assert(start <= file.text.length, "start must be within the bounds of the file. " + start + " > " + file.text.length); + Debug.assert(end <= file.text.length, "end must be the bounds of the file. " + end + " > " + file.text.length); + } var text = getLocaleSpecificMessage(message.key); if (arguments.length > 4) { text = formatStringFromArgs(text, arguments, 4); @@ -1584,7 +1624,7 @@ var ts; for (var _i = 0; _i < files.length; _i++) { var current = files[_i]; var name = ts.combinePaths(path, current); - var stat = _fs.lstatSync(name); + var stat = _fs.statSync(name); if (stat.isFile()) { if (!extension || ts.fileExtensionIs(name, extension)) { result.push(name); @@ -1790,7 +1830,7 @@ var ts; Unterminated_template_literal: { code: 1160, category: ts.DiagnosticCategory.Error, key: "Unterminated template literal." }, Unterminated_regular_expression_literal: { code: 1161, category: ts.DiagnosticCategory.Error, key: "Unterminated regular expression literal." }, An_object_member_cannot_be_declared_optional: { code: 1162, category: ts.DiagnosticCategory.Error, key: "An object member cannot be declared optional." }, - yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: ts.DiagnosticCategory.Error, key: "'yield' expression must be contained_within a generator declaration." }, + A_yield_expression_is_only_allowed_in_a_generator_body: { code: 1163, category: ts.DiagnosticCategory.Error, key: "A 'yield' expression is only allowed in a generator body." }, Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: ts.DiagnosticCategory.Error, key: "Computed property names are not allowed in enums." }, A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol: { code: 1165, category: ts.DiagnosticCategory.Error, key: "A computed property name in an ambient context must directly refer to a built-in symbol." }, A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol: { code: 1166, category: ts.DiagnosticCategory.Error, key: "A computed property name in a class property declaration must directly refer to a built-in symbol." }, @@ -1835,8 +1875,8 @@ var ts; Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: ts.DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." }, Decorators_are_not_valid_here: { code: 1206, category: ts.DiagnosticCategory.Error, key: "Decorators are not valid here." }, Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: ts.DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, - Cannot_compile_namespaces_when_the_separateCompilation_flag_is_provided: { code: 1208, category: ts.DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--separateCompilation' flag is provided." }, - Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: ts.DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, + Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided: { code: 1208, category: ts.DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--isolatedModules' flag is provided." }, + Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided: { code: 1209, category: ts.DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--isolatedModules' flag is provided." }, Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." }, A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: ts.DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" }, @@ -1844,6 +1884,11 @@ var ts; Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" }, Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: ts.DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." }, + Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning: { code: 1219, category: ts.DiagnosticCategory.Error, key: "Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning." }, + Generators_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 1220, category: ts.DiagnosticCategory.Error, key: "Generators are only available when targeting ECMAScript 6 or higher." }, + Generators_are_not_allowed_in_an_ambient_context: { code: 1221, category: ts.DiagnosticCategory.Error, key: "Generators are not allowed in an ambient context." }, + An_overload_signature_cannot_be_declared_as_a_generator: { code: 1222, category: ts.DiagnosticCategory.Error, key: "An overload signature cannot be declared as a generator." }, + _0_tag_already_specified: { code: 1223, category: ts.DiagnosticCategory.Error, key: "'{0}' tag already specified." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "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." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -2004,7 +2049,7 @@ var ts; The_0_operator_cannot_be_applied_to_type_symbol: { code: 2469, category: ts.DiagnosticCategory.Error, key: "The '{0}' operator cannot be applied to type 'symbol'." }, Symbol_reference_does_not_refer_to_the_global_Symbol_constructor_object: { code: 2470, category: ts.DiagnosticCategory.Error, key: "'Symbol' reference does not refer to the global Symbol constructor object." }, A_computed_property_name_of_the_form_0_must_be_of_type_symbol: { code: 2471, category: ts.DiagnosticCategory.Error, key: "A computed property name of the form '{0}' must be of type 'symbol'." }, - Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher: { code: 2472, category: ts.DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher." }, + Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher: { code: 2472, category: ts.DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher." }, Enum_declarations_must_all_be_const_or_non_const: { code: 2473, category: ts.DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." }, In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 2474, category: ts.DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression." }, const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment: { code: 2475, category: ts.DiagnosticCategory.Error, key: "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment." }, @@ -2035,6 +2080,8 @@ var ts; A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: ts.DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." }, _0_is_referenced_directly_or_indirectly_in_its_own_type_annotation: { code: 2502, category: ts.DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own type annotation." }, Cannot_find_namespace_0: { code: 2503, category: ts.DiagnosticCategory.Error, key: "Cannot find namespace '{0}'." }, + No_best_common_type_exists_among_yield_expressions: { code: 2504, category: ts.DiagnosticCategory.Error, key: "No best common type exists among yield expressions." }, + A_generator_cannot_have_a_void_type_annotation: { code: 2505, category: ts.DiagnosticCategory.Error, key: "A generator cannot have a 'void' type annotation." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -2119,11 +2166,11 @@ var ts; Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." }, Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." }, Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: ts.DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." }, - Option_sourceMap_cannot_be_specified_with_option_separateCompilation: { code: 5043, category: ts.DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'separateCompilation'." }, - Option_declaration_cannot_be_specified_with_option_separateCompilation: { code: 5044, category: ts.DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'separateCompilation'." }, - Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation: { code: 5045, category: ts.DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'separateCompilation'." }, - Option_out_cannot_be_specified_with_option_separateCompilation: { code: 5046, category: ts.DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'separateCompilation'." }, - Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: ts.DiagnosticCategory.Error, key: "Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." }, + Option_sourceMap_cannot_be_specified_with_option_isolatedModules: { code: 5043, category: ts.DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'isolatedModules'." }, + Option_declaration_cannot_be_specified_with_option_isolatedModules: { code: 5044, category: ts.DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'isolatedModules'." }, + Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules: { code: 5045, category: ts.DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'isolatedModules'." }, + Option_out_cannot_be_specified_with_option_isolatedModules: { code: 5046, category: ts.DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'isolatedModules'." }, + Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: ts.DiagnosticCategory.Error, key: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." }, Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap: { code: 5048, category: ts.DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'inlineSourceMap'." }, Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5049, category: ts.DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'." }, Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5050, category: ts.DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified with option 'inlineSourceMap'." }, @@ -2177,6 +2224,9 @@ var ts; Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: ts.DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." }, NEWLINE: { code: 6061, category: ts.DiagnosticCategory.Message, key: "NEWLINE" }, Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: ts.DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." }, + Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified: { code: 6064, category: ts.DiagnosticCategory.Error, key: "Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified." }, + Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." }, + Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." }, @@ -2192,6 +2242,7 @@ var ts; _0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." }, _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: ts.DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, + Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: ts.DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." }, You_cannot_rename_this_element: { code: 8000, category: ts.DiagnosticCategory.Error, key: "You cannot rename this element." }, You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: ts.DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." }, import_can_only_be_used_in_a_ts_file: { code: 8002, category: ts.DiagnosticCategory.Error, key: "'import ... =' can only be used in a .ts file." }, @@ -2205,16 +2256,12 @@ var ts; types_can_only_be_used_in_a_ts_file: { code: 8010, category: ts.DiagnosticCategory.Error, key: "'types' can only be used in a .ts file." }, type_arguments_can_only_be_used_in_a_ts_file: { code: 8011, category: ts.DiagnosticCategory.Error, key: "'type arguments' can only be used in a .ts file." }, parameter_modifiers_can_only_be_used_in_a_ts_file: { code: 8012, category: ts.DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in a .ts file." }, - can_only_be_used_in_a_ts_file: { code: 8013, category: ts.DiagnosticCategory.Error, key: "'?' can only be used in a .ts file." }, property_declarations_can_only_be_used_in_a_ts_file: { code: 8014, category: ts.DiagnosticCategory.Error, key: "'property declarations' can only be used in a .ts file." }, enum_declarations_can_only_be_used_in_a_ts_file: { code: 8015, category: ts.DiagnosticCategory.Error, key: "'enum declarations' can only be used in a .ts file." }, type_assertion_expressions_can_only_be_used_in_a_ts_file: { code: 8016, category: ts.DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in a .ts file." }, decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: ts.DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." }, - yield_expressions_are_not_currently_supported: { code: 9000, category: ts.DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, - Generators_are_not_currently_supported: { code: 9001, category: ts.DiagnosticCategory.Error, key: "Generators are not currently supported." }, Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: ts.DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." }, - class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." }, - class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration: { code: 9004, category: ts.DiagnosticCategory.Error, key: "'class' declarations are only supported directly inside a module or as a top level declaration." } + class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." } }; })(ts || (ts = {})); /// @@ -2750,12 +2797,17 @@ var ts; ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierPart(ch, languageVersion); } ts.isIdentifierPart = isIdentifierPart; - /** Creates a scanner over a (possibly unspecified) range of a piece of text. */ + /* @internal */ + // Creates a scanner over a (possibly unspecified) range of a piece of text. function createScanner(languageVersion, skipTrivia, text, onError, start, length) { - var pos; // Current position (end position of text of current token) - var end; // end of text - var startPos; // Start position of whitespace before current token - var tokenPos; // Start position of text of current token + // Current position (end position of text of current token) + var pos; + // end of text + var end; + // Start position of whitespace before current token + var startPos; + // Start position of text of current token + var tokenPos; var token; var tokenValue; var precedingLineBreak; @@ -3635,6 +3687,27 @@ var ts; } } ts.getModuleInstanceState = getModuleInstanceState; + var ContainerFlags; + (function (ContainerFlags) { + // The current node is not a container, and no container manipulation should happen before + // recursing into it. + ContainerFlags[ContainerFlags["None"] = 0] = "None"; + // The current node is a container. It should be set as the current container (and block- + // container) before recursing into it. The current node does not have locals. Examples: + // + // Classes, ObjectLiterals, TypeLiterals, Interfaces... + ContainerFlags[ContainerFlags["IsContainer"] = 1] = "IsContainer"; + // The current node is a block-scoped-container. It should be set as the current block- + // container before recursing into it. Examples: + // + // Blocks (when not parented by functions), Catch clauses, For/For-in/For-of statements... + ContainerFlags[ContainerFlags["IsBlockScopedContainer"] = 2] = "IsBlockScopedContainer"; + ContainerFlags[ContainerFlags["HasLocals"] = 4] = "HasLocals"; + // If the current node is a container that also container that also contains locals. Examples: + // + // Functions, Methods, Modules, Source-files. + ContainerFlags[ContainerFlags["IsContainerWithLocals"] = 5] = "IsContainerWithLocals"; + })(ContainerFlags || (ContainerFlags = {})); function bindSourceFile(file) { var start = new Date().getTime(); bindSourceFileWorker(file); @@ -3649,34 +3722,30 @@ var ts; var symbolCount = 0; var Symbol = ts.objectAllocator.getSymbolConstructor(); if (!file.locals) { - file.locals = {}; - container = file; - setBlockScopeContainer(file, false); bind(file); file.symbolCount = symbolCount; } + return; function createSymbol(flags, name) { symbolCount++; return new Symbol(flags, name); } - function setBlockScopeContainer(node, cleanLocals) { - blockScopeContainer = node; - if (cleanLocals) { - blockScopeContainer.locals = undefined; - } - } - function addDeclarationToSymbol(symbol, node, symbolKind) { - symbol.flags |= symbolKind; - if (!symbol.declarations) - symbol.declarations = []; - symbol.declarations.push(node); - if (symbolKind & 1952 /* HasExports */ && !symbol.exports) - symbol.exports = {}; - if (symbolKind & 6240 /* HasMembers */ && !symbol.members) - symbol.members = {}; + function addDeclarationToSymbol(symbol, node, symbolFlags) { + symbol.flags |= symbolFlags; node.symbol = symbol; - if (symbolKind & 107455 /* Value */ && !symbol.valueDeclaration) + if (!symbol.declarations) { + symbol.declarations = []; + } + symbol.declarations.push(node); + if (symbolFlags & 1952 /* HasExports */ && !symbol.exports) { + symbol.exports = {}; + } + if (symbolFlags & 6240 /* HasMembers */ && !symbol.members) { + symbol.members = {}; + } + if (symbolFlags & 107455 /* Value */ && !symbol.valueDeclaration) { symbol.valueDeclaration = node; + } } // Should not be called on a declaration with a computed property name, // unless it is a well known Symbol. @@ -3693,12 +3762,12 @@ var ts; return node.name.text; } switch (node.kind) { - case 144 /* ConstructorType */: case 136 /* Constructor */: return "__constructor"; case 143 /* FunctionType */: case 139 /* CallSignature */: return "__call"; + case 144 /* ConstructorType */: case 140 /* ConstructSignature */: return "__new"; case 141 /* IndexSignature */: @@ -3715,13 +3784,33 @@ var ts; function getDisplayName(node) { return node.name ? ts.declarationNameToString(node.name) : getDeclarationName(node); } - function declareSymbol(symbols, parent, node, includes, excludes) { + function declareSymbol(symbolTable, parent, node, includes, excludes) { ts.Debug.assert(!ts.hasDynamicName(node)); // The exported symbol for an export default function/class node is always named "default" var name = node.flags & 256 /* Default */ && parent ? "default" : getDeclarationName(node); var symbol; if (name !== undefined) { - symbol = ts.hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name)); + // Check and see if the symbol table already has a symbol with this name. If not, + // create a new symbol with this name and add it to the table. Note that we don't + // give the new symbol any flags *yet*. This ensures that it will not conflict + // witht he 'excludes' flags we pass in. + // + // If we do get an existing symbol, see if it conflicts with the new symbol we're + // creating. For example, a 'var' symbol and a 'class' symbol will conflict within + // the same symbol table. If we have a conflict, report the issue on each + // declaration we have for this symbol, and then create a new symbol for this + // declaration. + // + // If we created a new symbol, either because we didn't have a symbol with this name + // in the symbol table, or we conflicted with an existing symbol, then just add this + // node as the sole declaration of the new symbol. + // + // Otherwise, we'll be merging into a compatible existing symbol (for example when + // you have multiple 'vars' with the same name in the same container). In this case + // just add this node into the declarations list of the symbol. + symbol = ts.hasProperty(symbolTable, name) + ? symbolTable[name] + : (symbolTable[name] = createSymbol(0 /* None */, name)); if (symbol.flags & excludes) { if (node.name) { node.name.parent = node; @@ -3735,39 +3824,24 @@ var ts; file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration))); }); file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name || node, message, getDisplayName(node))); - symbol = createSymbol(0, name); + symbol = createSymbol(0 /* None */, name); } } else { - symbol = createSymbol(0, "__missing"); + symbol = createSymbol(0 /* None */, "__missing"); } addDeclarationToSymbol(symbol, node, includes); symbol.parent = parent; - if ((node.kind === 202 /* ClassDeclaration */ || node.kind === 175 /* ClassExpression */) && symbol.exports) { - // TypeScript 1.0 spec (April 2014): 8.4 - // Every class automatically contains a static property member named 'prototype', - // the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter. - // It is an error to explicitly declare a static property member with the name 'prototype'. - var prototypeSymbol = createSymbol(4 /* Property */ | 134217728 /* Prototype */, "prototype"); - if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) { - if (node.name) { - node.name.parent = node; - } - file.bindDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name)); - } - symbol.exports[prototypeSymbol.name] = prototypeSymbol; - prototypeSymbol.parent = symbol; - } return symbol; } - function declareModuleMember(node, symbolKind, symbolExcludes) { + function declareModuleMember(node, symbolFlags, symbolExcludes) { var hasExportModifier = ts.getCombinedNodeFlags(node) & 1 /* Export */; - if (symbolKind & 8388608 /* Alias */) { + if (symbolFlags & 8388608 /* Alias */) { if (node.kind === 218 /* ExportSpecifier */ || (node.kind === 209 /* ImportEqualsDeclaration */ && hasExportModifier)) { - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); + return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); } else { - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); + return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } else { @@ -3783,62 +3857,150 @@ var ts; // but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way // when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope. if (hasExportModifier || container.flags & 65536 /* ExportContext */) { - var exportKind = (symbolKind & 107455 /* Value */ ? 1048576 /* ExportValue */ : 0) | - (symbolKind & 793056 /* Type */ ? 2097152 /* ExportType */ : 0) | - (symbolKind & 1536 /* Namespace */ ? 4194304 /* ExportNamespace */ : 0); + var exportKind = (symbolFlags & 107455 /* Value */ ? 1048576 /* ExportValue */ : 0) | + (symbolFlags & 793056 /* Type */ ? 2097152 /* ExportType */ : 0) | + (symbolFlags & 1536 /* Namespace */ ? 4194304 /* ExportNamespace */ : 0); var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); - local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); + local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); node.localSymbol = local; + return local; } else { - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); + return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } } - // All container nodes are kept on a linked list in declaration order. This list is used by the getLocalNameOfContainer function - // in the type checker to validate that the local name used for a container is unique. - function bindChildren(node, symbolKind, isBlockScopeContainer) { - if (symbolKind & 255504 /* HasLocals */) { - node.locals = {}; - } + // All container nodes are kept on a linked list in declaration order. This list is used by + // the getLocalNameOfContainer function in the type checker to validate that the local name + // used for a container is unique. + function bindChildren(node) { + // Before we recurse into a node's chilren, we first save the existing parent, container + // and block-container. Then after we pop out of processing the children, we restore + // these saved values. var saveParent = parent; var saveContainer = container; var savedBlockScopeContainer = blockScopeContainer; + // This node will now be set as the parent of all of its children as we recurse into them. parent = node; - if (symbolKind & 262128 /* IsContainer */) { - container = node; + // Depending on what kind of node this is, we may have to adjust the current container + // and block-container. If the current node is a container, then it is automatically + // considered the current block-container as well. Also, for containers that we know + // may contain locals, we proactively initialize the .locals field. We do this because + // it's highly likely that the .locals will be needed to place some child in (for example, + // a parameter, or variable declaration). + // + // However, we do not proactively create the .locals for block-containers because it's + // totally normal and common for block-containers to never actually have a block-scoped + // variable in them. We don't want to end up allocating an object for every 'block' we + // run into when most of them won't be necessary. + // + // Finally, if this is a block-container, then we clear out any existing .locals object + // it may contain within it. This happens in incremental scenarios. Because we can be + // reusing a node from a previous compilation, that node may have had 'locals' created + // for it. We must clear this so we don't accidently move any stale data forward from + // a previous compilation. + var containerFlags = getContainerFlags(node); + if (containerFlags & 1 /* IsContainer */) { + container = blockScopeContainer = node; + if (containerFlags & 4 /* HasLocals */) { + container.locals = {}; + } addToContainerChain(container); } - if (isBlockScopeContainer) { - // in incremental scenarios we might reuse nodes that already have locals being allocated - // during the bind step these locals should be dropped to prevent using stale data. - // locals should always be dropped unless they were previously initialized by the binder - // these cases are: - // - node has locals (symbolKind & HasLocals) !== 0 - // - node is a source file - setBlockScopeContainer(node, (symbolKind & 255504 /* HasLocals */) === 0 && node.kind !== 228 /* SourceFile */); + else if (containerFlags & 2 /* IsBlockScopedContainer */) { + blockScopeContainer = node; + blockScopeContainer.locals = undefined; } ts.forEachChild(node, bind); container = saveContainer; parent = saveParent; blockScopeContainer = savedBlockScopeContainer; } - function addToContainerChain(node) { - if (lastContainer) { - lastContainer.nextContainer = node; - } - lastContainer = node; - } - function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) { - switch (container.kind) { + function getContainerFlags(node) { + switch (node.kind) { + case 175 /* ClassExpression */: + case 202 /* ClassDeclaration */: + case 203 /* InterfaceDeclaration */: + case 205 /* EnumDeclaration */: + case 146 /* TypeLiteral */: + case 155 /* ObjectLiteralExpression */: + return 1 /* IsContainer */; + case 139 /* CallSignature */: + case 140 /* ConstructSignature */: + case 141 /* IndexSignature */: + case 135 /* MethodDeclaration */: + case 134 /* MethodSignature */: + case 201 /* FunctionDeclaration */: + case 136 /* Constructor */: + case 137 /* GetAccessor */: + case 138 /* SetAccessor */: + case 143 /* FunctionType */: + case 144 /* ConstructorType */: + case 163 /* FunctionExpression */: + case 164 /* ArrowFunction */: case 206 /* ModuleDeclaration */: - declareModuleMember(node, symbolKind, symbolExcludes); - break; case 228 /* SourceFile */: - if (ts.isExternalModule(container)) { - declareModuleMember(node, symbolKind, symbolExcludes); - break; - } + return 5 /* IsContainerWithLocals */; + case 224 /* CatchClause */: + case 187 /* ForStatement */: + case 188 /* ForInStatement */: + case 189 /* ForOfStatement */: + case 208 /* CaseBlock */: + return 2 /* IsBlockScopedContainer */; + case 180 /* Block */: + // do not treat blocks directly inside a function as a block-scoped-container. + // Locals that reside in this block should go to the function locals. Othewise 'x' + // would not appear to be a redeclaration of a block scoped local in the following + // example: + // + // function foo() { + // var x; + // let x; + // } + // + // If we placed 'var x' into the function locals and 'let x' into the locals of + // the block, then there would be no collision. + // + // By not creating a new block-scoped-container here, we ensure that both 'var x' + // and 'let x' go into the Function-container's locals, and we do get a collision + // conflict. + return ts.isFunctionLike(node.parent) ? 0 /* None */ : 2 /* IsBlockScopedContainer */; + } + return 0 /* None */; + } + function addToContainerChain(next) { + if (lastContainer) { + lastContainer.nextContainer = next; + } + lastContainer = next; + } + function declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes) { + // Just call this directly so that the return type of this function stays "void". + declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes); + } + function declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes) { + switch (container.kind) { + // Modules, source files, and classes need specialized handling for how their + // members are declared (for example, a member of a class will go into a specific + // symbol table depending on if it is static or not). As such, we defer to + // specialized handlers to take care of declaring these child members. + case 206 /* ModuleDeclaration */: + return declareModuleMember(node, symbolFlags, symbolExcludes); + case 228 /* SourceFile */: + return declareSourceFileMember(node, symbolFlags, symbolExcludes); + case 175 /* ClassExpression */: + case 202 /* ClassDeclaration */: + return declareClassMember(node, symbolFlags, symbolExcludes); + case 205 /* EnumDeclaration */: + return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); + case 146 /* TypeLiteral */: + case 155 /* ObjectLiteralExpression */: + case 203 /* InterfaceDeclaration */: + // Interface/Object-types always have their children added to the 'members' of + // their container. They are only accessible through an instance of their + // container, and are never in scope otherwise (even inside the body of the + // object / type / interface declaring them). + return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); case 143 /* FunctionType */: case 144 /* ConstructorType */: case 139 /* CallSignature */: @@ -3852,29 +4014,30 @@ var ts; case 201 /* FunctionDeclaration */: case 163 /* FunctionExpression */: case 164 /* ArrowFunction */: - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); - break; - case 175 /* ClassExpression */: - case 202 /* ClassDeclaration */: - if (node.flags & 128 /* Static */) { - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); - break; - } - case 146 /* TypeLiteral */: - case 155 /* ObjectLiteralExpression */: - case 203 /* InterfaceDeclaration */: - declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes); - break; - case 205 /* EnumDeclaration */: - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); - break; + // All the children of these container types are never visible through another + // symbol (i.e. through another symbol's 'exports' or 'members'). Instead, + // they're only accessed 'lexically' (i.e. from code that exists underneath + // their container in the tree. To accomplish this, we simply add their declared + // symbol to the 'locals' of the container. These symbols can then be found as + // the type checker walks up the containers, checking them for matching names. + return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } - bindChildren(node, symbolKind, isBlockScopeContainer); + } + function declareClassMember(node, symbolFlags, symbolExcludes) { + return node.flags & 128 /* Static */ + ? declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes) + : declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); + } + function declareSourceFileMember(node, symbolFlags, symbolExcludes) { + return ts.isExternalModule(file) + ? declareModuleMember(node, symbolFlags, symbolExcludes) + : declareSymbol(file.locals, undefined, node, symbolFlags, symbolExcludes); } function isAmbientContext(node) { while (node) { - if (node.flags & 2 /* Ambient */) + if (node.flags & 2 /* Ambient */) { return true; + } node = node.parent; } return false; @@ -3904,15 +4067,15 @@ var ts; function bindModuleDeclaration(node) { setExportContextFlag(node); if (node.name.kind === 8 /* StringLiteral */) { - bindDeclaration(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */, true); + declareSymbolAndAddToSymbolTable(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */); } else { var state = getModuleInstanceState(node); if (state === 0 /* NonInstantiated */) { - bindDeclaration(node, 1024 /* NamespaceModule */, 0 /* NamespaceModuleExcludes */, true); + declareSymbolAndAddToSymbolTable(node, 1024 /* NamespaceModule */, 0 /* NamespaceModuleExcludes */); } else { - bindDeclaration(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */, true); + declareSymbolAndAddToSymbolTable(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */); var currentModuleIsConstEnumOnly = state === 2 /* ConstEnumOnly */; if (node.symbol.constEnumOnlyModule === undefined) { // non-merged case - use the current state @@ -3934,28 +4097,23 @@ var ts; // from an actual type literal symbol you would have gotten had you used the long form. var symbol = createSymbol(131072 /* Signature */, getDeclarationName(node)); addDeclarationToSymbol(symbol, node, 131072 /* Signature */); - bindChildren(node, 131072 /* Signature */, false); var typeLiteralSymbol = createSymbol(2048 /* TypeLiteral */, "__type"); addDeclarationToSymbol(typeLiteralSymbol, node, 2048 /* TypeLiteral */); - typeLiteralSymbol.members = {}; - typeLiteralSymbol.members[node.kind === 143 /* FunctionType */ ? "__call" : "__new"] = symbol; + typeLiteralSymbol.members = (_a = {}, _a[symbol.name] = symbol, _a); + var _a; } - function bindAnonymousDeclaration(node, symbolKind, name, isBlockScopeContainer) { - var symbol = createSymbol(symbolKind, name); - addDeclarationToSymbol(symbol, node, symbolKind); - bindChildren(node, symbolKind, isBlockScopeContainer); + function bindAnonymousDeclaration(node, symbolFlags, name) { + var symbol = createSymbol(symbolFlags, name); + addDeclarationToSymbol(symbol, node, symbolFlags); } - function bindCatchVariableDeclaration(node) { - bindChildren(node, 0, true); - } - function bindBlockScopedDeclaration(node, symbolKind, symbolExcludes) { + function bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) { switch (blockScopeContainer.kind) { case 206 /* ModuleDeclaration */: - declareModuleMember(node, symbolKind, symbolExcludes); + declareModuleMember(node, symbolFlags, symbolExcludes); break; case 228 /* SourceFile */: if (ts.isExternalModule(container)) { - declareModuleMember(node, symbolKind, symbolExcludes); + declareModuleMember(node, symbolFlags, symbolExcludes); break; } // fall through. @@ -3964,9 +4122,8 @@ var ts; blockScopeContainer.locals = {}; addToContainerChain(blockScopeContainer); } - declareSymbol(blockScopeContainer.locals, undefined, node, symbolKind, symbolExcludes); + declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes); } - bindChildren(node, symbolKind, false); } function bindBlockScopedVariableDeclaration(node) { bindBlockScopedDeclaration(node, 2 /* BlockScopedVariable */, 107455 /* BlockScopedVariableExcludes */); @@ -3976,182 +4133,182 @@ var ts; } function bind(node) { node.parent = parent; + // First we bind declaration nodes to a symbol if possible. We'll both create a symbol + // and then potentially add the symbol to an appropriate symbol table. Possible + // destination symbol tables are: + // + // 1) The 'exports' table of the current container's symbol. + // 2) The 'members' table of the current container's symbol. + // 3) The 'locals' table of the current container. + // + // However, not all symbols will end up in any of these tables. 'Anonymous' symbols + // (like TypeLiterals for example) will not be put in any table. + bindWorker(node); + // Then we recurse into the children of the node to bind them as well. For certain + // symbols we do specialized work when we recurse. For example, we'll keep track of + // the current 'container' node when it changes. This helps us know which symbol table + // a local should go into for example. + bindChildren(node); + } + function bindWorker(node) { switch (node.kind) { case 129 /* TypeParameter */: - bindDeclaration(node, 262144 /* TypeParameter */, 530912 /* TypeParameterExcludes */, false); - break; + return declareSymbolAndAddToSymbolTable(node, 262144 /* TypeParameter */, 530912 /* TypeParameterExcludes */); case 130 /* Parameter */: - bindParameter(node); - break; + return bindParameter(node); case 199 /* VariableDeclaration */: case 153 /* BindingElement */: - if (ts.isBindingPattern(node.name)) { - bindChildren(node, 0, false); - } - else if (ts.isBlockOrCatchScoped(node)) { - bindBlockScopedVariableDeclaration(node); - } - else if (ts.isParameterDeclaration(node)) { - // It is safe to walk up parent chain to find whether the node is a destructing parameter declaration - // because its parent chain has already been set up, since parents are set before descending into children. - // - // If node is a binding element in parameter declaration, we need to use ParameterExcludes. - // Using ParameterExcludes flag allows the compiler to report an error on duplicate identifiers in Parameter Declaration - // For example: - // function foo([a,a]) {} // Duplicate Identifier error - // function bar(a,a) {} // Duplicate Identifier error, parameter declaration in this case is handled in bindParameter - // // which correctly set excluded symbols - bindDeclaration(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */, false); - } - else { - bindDeclaration(node, 1 /* FunctionScopedVariable */, 107454 /* FunctionScopedVariableExcludes */, false); - } - break; + return bindVariableDeclarationOrBindingElement(node); case 133 /* PropertyDeclaration */: case 132 /* PropertySignature */: - bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0), 107455 /* PropertyExcludes */, false); - break; + return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 107455 /* PropertyExcludes */); case 225 /* PropertyAssignment */: case 226 /* ShorthandPropertyAssignment */: - bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 107455 /* PropertyExcludes */, false); - break; + return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 107455 /* PropertyExcludes */); case 227 /* EnumMember */: - bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */, false); - break; + return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */); case 139 /* CallSignature */: case 140 /* ConstructSignature */: case 141 /* IndexSignature */: - bindDeclaration(node, 131072 /* Signature */, 0, false); - break; + return declareSymbolAndAddToSymbolTable(node, 131072 /* Signature */, 0 /* None */); case 135 /* MethodDeclaration */: case 134 /* MethodSignature */: // If this is an ObjectLiteralExpression method, then it sits in the same space // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. - bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0), ts.isObjectLiteralMethod(node) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */, true); - break; + return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */); case 201 /* FunctionDeclaration */: - bindDeclaration(node, 16 /* Function */, 106927 /* FunctionExcludes */, true); - break; + return declareSymbolAndAddToSymbolTable(node, 16 /* Function */, 106927 /* FunctionExcludes */); case 136 /* Constructor */: - bindDeclaration(node, 16384 /* Constructor */, 0, true); - break; + return declareSymbolAndAddToSymbolTable(node, 16384 /* Constructor */, 0 /* None */); case 137 /* GetAccessor */: - bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */, true); - break; + return bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */); case 138 /* SetAccessor */: - bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */, true); - break; + return bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */); case 143 /* FunctionType */: case 144 /* ConstructorType */: - bindFunctionOrConstructorType(node); - break; + return bindFunctionOrConstructorType(node); case 146 /* TypeLiteral */: - bindAnonymousDeclaration(node, 2048 /* TypeLiteral */, "__type", false); - break; + return bindAnonymousDeclaration(node, 2048 /* TypeLiteral */, "__type"); case 155 /* ObjectLiteralExpression */: - bindAnonymousDeclaration(node, 4096 /* ObjectLiteral */, "__object", false); - break; + return bindAnonymousDeclaration(node, 4096 /* ObjectLiteral */, "__object"); case 163 /* FunctionExpression */: case 164 /* ArrowFunction */: - bindAnonymousDeclaration(node, 16 /* Function */, "__function", true); - break; + return bindAnonymousDeclaration(node, 16 /* Function */, "__function"); case 175 /* ClassExpression */: - bindAnonymousDeclaration(node, 32 /* Class */, "__class", false); - break; - case 224 /* CatchClause */: - bindCatchVariableDeclaration(node); - break; case 202 /* ClassDeclaration */: - bindBlockScopedDeclaration(node, 32 /* Class */, 899583 /* ClassExcludes */); - break; + return bindClassLikeDeclaration(node); case 203 /* InterfaceDeclaration */: - bindDeclaration(node, 64 /* Interface */, 792992 /* InterfaceExcludes */, false); - break; + return bindBlockScopedDeclaration(node, 64 /* Interface */, 792992 /* InterfaceExcludes */); case 204 /* TypeAliasDeclaration */: - bindDeclaration(node, 524288 /* TypeAlias */, 793056 /* TypeAliasExcludes */, false); - break; + return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793056 /* TypeAliasExcludes */); case 205 /* EnumDeclaration */: - if (ts.isConst(node)) { - bindDeclaration(node, 128 /* ConstEnum */, 899967 /* ConstEnumExcludes */, false); - } - else { - bindDeclaration(node, 256 /* RegularEnum */, 899327 /* RegularEnumExcludes */, false); - } - break; + return bindEnumDeclaration(node); case 206 /* ModuleDeclaration */: - bindModuleDeclaration(node); - break; + return bindModuleDeclaration(node); case 209 /* ImportEqualsDeclaration */: case 212 /* NamespaceImport */: case 214 /* ImportSpecifier */: case 218 /* ExportSpecifier */: - bindDeclaration(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */, false); - break; + return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); case 211 /* ImportClause */: - if (node.name) { - bindDeclaration(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */, false); - } - else { - bindChildren(node, 0, false); - } - break; + return bindImportClause(node); case 216 /* ExportDeclaration */: - if (!node.exportClause) { - // All export * declarations are collected in an __export symbol - declareSymbol(container.symbol.exports, container.symbol, node, 1073741824 /* ExportStar */, 0); - } - bindChildren(node, 0, false); - break; + return bindExportDeclaration(node); case 215 /* ExportAssignment */: - if (node.expression.kind === 65 /* Identifier */) { - // An export default clause with an identifier exports all meanings of that identifier - declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); - } - else { - // An export default clause with an expression exports a value - declareSymbol(container.symbol.exports, container.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); - } - bindChildren(node, 0, false); - break; + return bindExportAssignment(node); case 228 /* SourceFile */: - setExportContextFlag(node); - if (ts.isExternalModule(node)) { - bindAnonymousDeclaration(node, 512 /* ValueModule */, '"' + ts.removeFileExtension(node.fileName) + '"', true); - break; - } - case 180 /* Block */: - // do not treat function block a block-scope container - // all block-scope locals that reside in this block should go to the function locals. - // Otherwise this won't be considered as redeclaration of a block scoped local: - // function foo() { - // let x; - // let x; - // } - // 'let x' will be placed into the function locals and 'let x' - into the locals of the block - bindChildren(node, 0, !ts.isFunctionLike(node.parent)); - break; - case 224 /* CatchClause */: - case 187 /* ForStatement */: - case 188 /* ForInStatement */: - case 189 /* ForOfStatement */: - case 208 /* CaseBlock */: - bindChildren(node, 0, true); - break; - default: - var saveParent = parent; - parent = node; - ts.forEachChild(node, bind); - parent = saveParent; + return bindSourceFileIfExternalModule(); + } + } + function bindSourceFileIfExternalModule() { + setExportContextFlag(file); + if (ts.isExternalModule(file)) { + bindAnonymousDeclaration(file, 512 /* ValueModule */, '"' + ts.removeFileExtension(file.fileName) + '"'); + } + } + function bindExportAssignment(node) { + if (node.expression.kind === 65 /* Identifier */) { + // An export default clause with an identifier exports all meanings of that identifier + declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); + } + else { + // An export default clause with an expression exports a value + declareSymbol(container.symbol.exports, container.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); + } + } + function bindExportDeclaration(node) { + if (!node.exportClause) { + // All export * declarations are collected in an __export symbol + declareSymbol(container.symbol.exports, container.symbol, node, 1073741824 /* ExportStar */, 0 /* None */); + } + } + function bindImportClause(node) { + if (node.name) { + declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); + } + } + function bindClassLikeDeclaration(node) { + if (node.kind === 202 /* ClassDeclaration */) { + bindBlockScopedDeclaration(node, 32 /* Class */, 899583 /* ClassExcludes */); + } + else { + bindAnonymousDeclaration(node, 32 /* Class */, "__class"); + } + var symbol = node.symbol; + // TypeScript 1.0 spec (April 2014): 8.4 + // Every class automatically contains a static property member named 'prototype', the + // type of which is an instantiation of the class type with type Any supplied as a type + // argument for each type parameter. It is an error to explicitly declare a static + // property member with the name 'prototype'. + // + // Note: we check for this here because this class may be merging into a module. The + // module might have an exported variable called 'prototype'. We can't allow that as + // that would clash with the built-in 'prototype' for the class. + var prototypeSymbol = createSymbol(4 /* Property */ | 134217728 /* Prototype */, "prototype"); + if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) { + if (node.name) { + node.name.parent = node; + } + file.bindDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name)); + } + symbol.exports[prototypeSymbol.name] = prototypeSymbol; + prototypeSymbol.parent = symbol; + } + function bindEnumDeclaration(node) { + return ts.isConst(node) + ? bindBlockScopedDeclaration(node, 128 /* ConstEnum */, 899967 /* ConstEnumExcludes */) + : bindBlockScopedDeclaration(node, 256 /* RegularEnum */, 899327 /* RegularEnumExcludes */); + } + function bindVariableDeclarationOrBindingElement(node) { + if (!ts.isBindingPattern(node.name)) { + if (ts.isBlockOrCatchScoped(node)) { + bindBlockScopedVariableDeclaration(node); + } + else if (ts.isParameterDeclaration(node)) { + // It is safe to walk up parent chain to find whether the node is a destructing parameter declaration + // because its parent chain has already been set up, since parents are set before descending into children. + // + // If node is a binding element in parameter declaration, we need to use ParameterExcludes. + // Using ParameterExcludes flag allows the compiler to report an error on duplicate identifiers in Parameter Declaration + // For example: + // function foo([a,a]) {} // Duplicate Identifier error + // function bar(a,a) {} // Duplicate Identifier error, parameter declaration in this case is handled in bindParameter + // // which correctly set excluded symbols + declareSymbolAndAddToSymbolTable(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */); + } + else { + declareSymbolAndAddToSymbolTable(node, 1 /* FunctionScopedVariable */, 107454 /* FunctionScopedVariableExcludes */); + } } } function bindParameter(node) { if (ts.isBindingPattern(node.name)) { - bindAnonymousDeclaration(node, 1 /* FunctionScopedVariable */, getDestructuringParameterName(node), false); + bindAnonymousDeclaration(node, 1 /* FunctionScopedVariable */, getDestructuringParameterName(node)); } else { - bindDeclaration(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */, false); + declareSymbolAndAddToSymbolTable(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */); } // If this is a property-parameter, then also declare the property symbol into the // containing class. @@ -4162,13 +4319,10 @@ var ts; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */); } } - function bindPropertyOrMethodOrAccessor(node, symbolKind, symbolExcludes, isBlockScopeContainer) { - if (ts.hasDynamicName(node)) { - bindAnonymousDeclaration(node, symbolKind, "__computed", isBlockScopeContainer); - } - else { - bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer); - } + function bindPropertyOrMethodOrAccessor(node, symbolFlags, symbolExcludes) { + return ts.hasDynamicName(node) + ? bindAnonymousDeclaration(node, symbolFlags, "__computed") + : declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes); } } })(ts || (ts = {})); @@ -4226,11 +4380,11 @@ var ts; // Returns true if this node contains a parse error anywhere underneath it. function containsParseError(node) { aggregateChildData(node); - return (node.parserContextFlags & 64 /* ThisNodeOrAnySubNodesHasError */) !== 0; + return (node.parserContextFlags & 128 /* ThisNodeOrAnySubNodesHasError */) !== 0; } ts.containsParseError = containsParseError; function aggregateChildData(node) { - if (!(node.parserContextFlags & 128 /* HasAggregatedChildData */)) { + if (!(node.parserContextFlags & 256 /* HasAggregatedChildData */)) { // A node is considered to contain a parse error if: // a) the parser explicitly marked that it had an error // b) any of it's children reported that it had an error. @@ -4238,12 +4392,12 @@ var ts; ts.forEachChild(node, containsParseError); // If so, mark ourselves accordingly. if (thisNodeOrAnySubNodesHasError) { - node.parserContextFlags |= 64 /* ThisNodeOrAnySubNodesHasError */; + node.parserContextFlags |= 128 /* ThisNodeOrAnySubNodesHasError */; } // Also mark that we've propogated the child information to this node. This way we can // always consult the bit directly on this node without needing to check its children // again. - node.parserContextFlags |= 128 /* HasAggregatedChildData */; + node.parserContextFlags |= 256 /* HasAggregatedChildData */; } } function getSourceFileOfNode(node) { @@ -4530,6 +4684,88 @@ var ts; } ts.getJsDocComments = getJsDocComments; ts.fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/; + function isTypeNode(node) { + if (142 /* FirstTypeNode */ <= node.kind && node.kind <= 150 /* LastTypeNode */) { + return true; + } + switch (node.kind) { + case 112 /* AnyKeyword */: + case 120 /* NumberKeyword */: + case 122 /* StringKeyword */: + case 113 /* BooleanKeyword */: + case 123 /* SymbolKeyword */: + return true; + case 99 /* VoidKeyword */: + return node.parent.kind !== 167 /* VoidExpression */; + case 8 /* StringLiteral */: + // Specialized signatures can have string literals as their parameters' type names + return node.parent.kind === 130 /* Parameter */; + case 177 /* ExpressionWithTypeArguments */: + return true; + // Identifiers and qualified names may be type nodes, depending on their context. Climb + // above them to find the lowest container + case 65 /* Identifier */: + // If the identifier is the RHS of a qualified name, then it's a type iff its parent is. + if (node.parent.kind === 127 /* QualifiedName */ && node.parent.right === node) { + node = node.parent; + } + else if (node.parent.kind === 156 /* PropertyAccessExpression */ && node.parent.name === node) { + node = node.parent; + } + // fall through + case 127 /* QualifiedName */: + case 156 /* PropertyAccessExpression */: + // At this point, node is either a qualified name or an identifier + ts.Debug.assert(node.kind === 65 /* Identifier */ || node.kind === 127 /* QualifiedName */ || node.kind === 156 /* PropertyAccessExpression */, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); + var parent_1 = node.parent; + if (parent_1.kind === 145 /* TypeQuery */) { + return false; + } + // Do not recursively call isTypeNode on the parent. In the example: + // + // let a: A.B.C; + // + // Calling isTypeNode would consider the qualified name A.B a type node. Only C or + // A.B.C is a type node. + if (142 /* FirstTypeNode */ <= parent_1.kind && parent_1.kind <= 150 /* LastTypeNode */) { + return true; + } + switch (parent_1.kind) { + case 177 /* ExpressionWithTypeArguments */: + return true; + case 129 /* TypeParameter */: + return node === parent_1.constraint; + case 133 /* PropertyDeclaration */: + case 132 /* PropertySignature */: + case 130 /* Parameter */: + case 199 /* VariableDeclaration */: + return node === parent_1.type; + case 201 /* FunctionDeclaration */: + case 163 /* FunctionExpression */: + case 164 /* ArrowFunction */: + case 136 /* Constructor */: + case 135 /* MethodDeclaration */: + case 134 /* MethodSignature */: + case 137 /* GetAccessor */: + case 138 /* SetAccessor */: + return node === parent_1.type; + case 139 /* CallSignature */: + case 140 /* ConstructSignature */: + case 141 /* IndexSignature */: + return node === parent_1.type; + case 161 /* TypeAssertionExpression */: + return node === parent_1.type; + case 158 /* CallExpression */: + case 159 /* NewExpression */: + return parent_1.typeArguments && ts.indexOf(parent_1.typeArguments, node) >= 0; + case 160 /* TaggedTemplateExpression */: + // TODO (drosen): TaggedTemplateExpressions may eventually support type arguments. + return false; + } + } + return false; + } + ts.isTypeNode = isTypeNode; // Warning: This has the same semantics as the forEach family of functions, // in that traversal terminates in the event that 'visitor' supplies a truthy value. function forEachReturnStatement(body, visitor) { @@ -4558,6 +4794,44 @@ var ts; } } ts.forEachReturnStatement = forEachReturnStatement; + function forEachYieldExpression(body, visitor) { + return traverse(body); + function traverse(node) { + switch (node.kind) { + case 173 /* YieldExpression */: + visitor(node); + var operand = node.expression; + if (operand) { + traverse(operand); + } + case 205 /* EnumDeclaration */: + case 203 /* InterfaceDeclaration */: + case 206 /* ModuleDeclaration */: + case 204 /* TypeAliasDeclaration */: + case 202 /* ClassDeclaration */: + // These are not allowed inside a generator now, but eventually they may be allowed + // as local types. Regardless, any yield statements contained within them should be + // skipped in this traversal. + return; + default: + if (isFunctionLike(node)) { + var name_3 = node.name; + if (name_3 && name_3.kind === 128 /* ComputedPropertyName */) { + // Note that we will not include methods/accessors of a class because they would require + // first descending into the class. This is by design. + traverse(name_3.expression); + return; + } + } + else if (!isTypeNode(node)) { + // This is the general case, which should include mostly expressions and statements. + // Also includes NodeArrays. + ts.forEachChild(node, traverse); + } + } + } + } + ts.forEachYieldExpression = forEachYieldExpression; function isVariableLike(node) { if (node) { switch (node.kind) { @@ -4586,6 +4860,12 @@ var ts; return false; } ts.isAccessor = isAccessor; + function isClassLike(node) { + if (node) { + return node.kind === 202 /* ClassDeclaration */ || node.kind === 175 /* ClassExpression */; + } + } + ts.isClassLike = isClassLike; function isFunctionLike(node) { if (node) { switch (node.kind) { @@ -4836,6 +5116,7 @@ var ts; case 172 /* TemplateExpression */: case 10 /* NoSubstitutionTemplateLiteral */: case 176 /* OmittedExpression */: + case 173 /* YieldExpression */: return true; case 127 /* QualifiedName */: while (node.parent.kind === 127 /* QualifiedName */) { @@ -4849,8 +5130,8 @@ var ts; // fall through case 7 /* NumericLiteral */: case 8 /* StringLiteral */: - var parent_1 = node.parent; - switch (parent_1.kind) { + var parent_2 = node.parent; + switch (parent_2.kind) { case 199 /* VariableDeclaration */: case 130 /* Parameter */: case 133 /* PropertyDeclaration */: @@ -4858,7 +5139,7 @@ var ts; case 227 /* EnumMember */: case 225 /* PropertyAssignment */: case 153 /* BindingElement */: - return parent_1.initializer === node; + return parent_2.initializer === node; case 183 /* ExpressionStatement */: case 184 /* IfStatement */: case 185 /* DoStatement */: @@ -4869,27 +5150,27 @@ var ts; case 221 /* CaseClause */: case 196 /* ThrowStatement */: case 194 /* SwitchStatement */: - return parent_1.expression === node; + return parent_2.expression === node; case 187 /* ForStatement */: - var forStatement = parent_1; + var forStatement = parent_2; return (forStatement.initializer === node && forStatement.initializer.kind !== 200 /* VariableDeclarationList */) || forStatement.condition === node || forStatement.incrementor === node; case 188 /* ForInStatement */: case 189 /* ForOfStatement */: - var forInStatement = parent_1; + var forInStatement = parent_2; return (forInStatement.initializer === node && forInStatement.initializer.kind !== 200 /* VariableDeclarationList */) || forInStatement.expression === node; case 161 /* TypeAssertionExpression */: - return node === parent_1.expression; + return node === parent_2.expression; case 178 /* TemplateSpan */: - return node === parent_1.expression; + return node === parent_2.expression; case 128 /* ComputedPropertyName */: - return node === parent_1.expression; + return node === parent_2.expression; case 131 /* Decorator */: return true; default: - if (isExpression(parent_1)) { + if (isExpression(parent_2)) { return true; } } @@ -4931,10 +5212,6 @@ var ts; } } ts.getExternalModuleName = getExternalModuleName; - function hasDotDotDotToken(node) { - return node && node.kind === 130 /* Parameter */ && node.dotDotDotToken !== undefined; - } - ts.hasDotDotDotToken = hasDotDotDotToken; function hasQuestionToken(node) { if (node) { switch (node.kind) { @@ -4953,10 +5230,74 @@ var ts; return false; } ts.hasQuestionToken = hasQuestionToken; - function hasRestParameters(s) { - return s.parameters.length > 0 && ts.lastOrUndefined(s.parameters).dotDotDotToken !== undefined; + function isJSDocConstructSignature(node) { + return node.kind === 241 /* JSDocFunctionType */ && + node.parameters.length > 0 && + node.parameters[0].type.kind === 243 /* JSDocConstructorType */; } - ts.hasRestParameters = hasRestParameters; + ts.isJSDocConstructSignature = isJSDocConstructSignature; + function getJSDocTag(node, kind) { + if (node && node.jsDocComment) { + for (var _i = 0, _a = node.jsDocComment.tags; _i < _a.length; _i++) { + var tag = _a[_i]; + if (tag.kind === kind) { + return tag; + } + } + } + } + function getJSDocTypeTag(node) { + return getJSDocTag(node, 249 /* JSDocTypeTag */); + } + ts.getJSDocTypeTag = getJSDocTypeTag; + function getJSDocReturnTag(node) { + return getJSDocTag(node, 248 /* JSDocReturnTag */); + } + ts.getJSDocReturnTag = getJSDocReturnTag; + function getJSDocTemplateTag(node) { + return getJSDocTag(node, 250 /* JSDocTemplateTag */); + } + ts.getJSDocTemplateTag = getJSDocTemplateTag; + function getCorrespondingJSDocParameterTag(parameter) { + if (parameter.name && parameter.name.kind === 65 /* Identifier */) { + // If it's a parameter, see if the parent has a jsdoc comment with an @param + // annotation. + var parameterName = parameter.name.text; + var docComment = parameter.parent.jsDocComment; + if (docComment) { + return ts.forEach(docComment.tags, function (t) { + if (t.kind === 247 /* JSDocParameterTag */) { + var parameterTag = t; + var name_4 = parameterTag.preParameterName || parameterTag.postParameterName; + if (name_4.text === parameterName) { + return t; + } + } + }); + } + } + } + ts.getCorrespondingJSDocParameterTag = getCorrespondingJSDocParameterTag; + function hasRestParameter(s) { + return isRestParameter(ts.lastOrUndefined(s.parameters)); + } + ts.hasRestParameter = hasRestParameter; + function isRestParameter(node) { + if (node) { + if (node.parserContextFlags & 64 /* JavaScriptFile */) { + if (node.type && node.type.kind === 242 /* JSDocVariadicType */) { + return true; + } + var paramTag = getCorrespondingJSDocParameterTag(node); + if (paramTag && paramTag.typeExpression) { + return paramTag.typeExpression.type.kind === 242 /* JSDocVariadicType */; + } + } + return node.dotDotDotToken !== undefined; + } + return false; + } + ts.isRestParameter = isRestParameter; function isLiteralKind(kind) { return 7 /* FirstLiteralToken */ <= kind && kind <= 10 /* LastLiteralToken */; } @@ -5502,7 +5843,7 @@ var ts; if ((isExternalModule(sourceFile) || !compilerOptions.out)) { // 1. in-browser single file compilation scenario // 2. non .js file - return compilerOptions.separateCompilation || !ts.fileExtensionIs(sourceFile.fileName, ".js"); + return compilerOptions.isolatedModules || !ts.fileExtensionIs(sourceFile.fileName, ".js"); } return false; } @@ -5747,6 +6088,10 @@ var ts; return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & 256 /* Default */) ? symbol.valueDeclaration.localSymbol : undefined; } ts.getLocalSymbolForExportDefault = getLocalSymbolForExportDefault; + function isJavaScript(fileName) { + return ts.fileExtensionIs(fileName, ".js"); + } + ts.isJavaScript = isJavaScript; /** * Replace each instance of non-ascii characters by one, two, three, or four escape sequences * representing the UTF-8 encoding of the character, and return the expanded char code list. @@ -6020,12 +6365,22 @@ var ts; return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); } ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; + function getTypeParameterOwner(d) { + if (d && d.kind === 129 /* TypeParameter */) { + for (var current = d; current; current = current.parent) { + if (ts.isFunctionLike(current) || ts.isClassLike(current) || current.kind === 203 /* InterfaceDeclaration */) { + return current; + } + } + } + } + ts.getTypeParameterOwner = getTypeParameterOwner; })(ts || (ts = {})); /// /// var ts; (function (ts) { - var nodeConstructors = new Array(230 /* Count */); + var nodeConstructors = new Array(252 /* Count */); /* @internal */ ts.parseTime = 0; function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); @@ -6335,6 +6690,49 @@ var ts; return visitNode(cbNode, node.expression); case 219 /* MissingDeclaration */: return visitNodes(cbNodes, node.decorators); + case 229 /* JSDocTypeExpression */: + return visitNode(cbNode, node.type); + case 233 /* JSDocUnionType */: + return visitNodes(cbNodes, node.types); + case 234 /* JSDocTupleType */: + return visitNodes(cbNodes, node.types); + case 232 /* JSDocArrayType */: + return visitNode(cbNode, node.elementType); + case 236 /* JSDocNonNullableType */: + return visitNode(cbNode, node.type); + case 235 /* JSDocNullableType */: + return visitNode(cbNode, node.type); + case 237 /* JSDocRecordType */: + return visitNodes(cbNodes, node.members); + case 239 /* JSDocTypeReference */: + return visitNode(cbNode, node.name) || + visitNodes(cbNodes, node.typeArguments); + case 240 /* JSDocOptionalType */: + return visitNode(cbNode, node.type); + case 241 /* JSDocFunctionType */: + return visitNodes(cbNodes, node.parameters) || + visitNode(cbNode, node.type); + case 242 /* JSDocVariadicType */: + return visitNode(cbNode, node.type); + case 243 /* JSDocConstructorType */: + return visitNode(cbNode, node.type); + case 244 /* JSDocThisType */: + return visitNode(cbNode, node.type); + case 238 /* JSDocRecordMember */: + return visitNode(cbNode, node.name) || + visitNode(cbNode, node.type); + case 245 /* JSDocComment */: + return visitNodes(cbNodes, node.tags); + case 247 /* JSDocParameterTag */: + return visitNode(cbNode, node.preParameterName) || + visitNode(cbNode, node.typeExpression) || + visitNode(cbNode, node.postParameterName); + case 248 /* JSDocReturnTag */: + return visitNode(cbNode, node.typeExpression); + case 249 /* JSDocTypeTag */: + return visitNode(cbNode, node.typeExpression); + case 250 /* JSDocTemplateTag */: + return visitNodes(cbNodes, node.typeParameters); } } ts.forEachChild = forEachChild; @@ -6359,6 +6757,17 @@ var ts; return IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks); } ts.updateSourceFile = updateSourceFile; + /* @internal */ + function parseIsolatedJSDocComment(content, start, length) { + return Parser.JSDocParser.parseIsolatedJSDocComment(content, start, length); + } + ts.parseIsolatedJSDocComment = parseIsolatedJSDocComment; + /* @internal */ + // Exposed only for testing. + function parseJSDocTypeExpressionForTests(content, start, length) { + return Parser.JSDocParser.parseJSDocTypeExpressionForTests(content, start, length); + } + ts.parseJSDocTypeExpressionForTests = parseJSDocTypeExpressionForTests; // Implement the parser as a singleton module. We do this for perf reasons because creating // parser instances can actually be expensive enough to impact us on projects with many source // files. @@ -6369,6 +6778,7 @@ var ts; var scanner = ts.createScanner(2 /* Latest */, true); var disallowInAndDecoratorContext = 2 /* DisallowIn */ | 16 /* Decorator */; var sourceFile; + var parseDiagnostics; var syntaxCursor; var token; var sourceText; @@ -6422,7 +6832,7 @@ var ts; // Note: it should not be necessary to save/restore these flags during speculative/lookahead // parsing. These context flags are naturally stored and restored through normal recursive // descent parsing and unwinding. - var contextFlags = 0; + var contextFlags; // Whether or not we've had a parse error since creating the last AST node. If we have // encountered an error, it will be stored on the next AST node we create. Parse errors // can be broken down into three categories: @@ -6451,20 +6861,49 @@ var ts; // Note: any errors at the end of the file that do not precede a regular node, should get // attached to the EOF token. var parseErrorBeforeNextFinishedNode = false; + (function (StatementFlags) { + StatementFlags[StatementFlags["None"] = 0] = "None"; + StatementFlags[StatementFlags["Statement"] = 1] = "Statement"; + StatementFlags[StatementFlags["ModuleElement"] = 2] = "ModuleElement"; + StatementFlags[StatementFlags["StatementOrModuleElement"] = 3] = "StatementOrModuleElement"; + })(Parser.StatementFlags || (Parser.StatementFlags = {})); + var StatementFlags = Parser.StatementFlags; function parseSourceFile(fileName, _sourceText, languageVersion, _syntaxCursor, setParentNodes) { + initializeState(fileName, _sourceText, languageVersion, _syntaxCursor); + var result = parseSourceFileWorker(fileName, languageVersion, setParentNodes); + clearState(); + return result; + } + Parser.parseSourceFile = parseSourceFile; + function initializeState(fileName, _sourceText, languageVersion, _syntaxCursor) { sourceText = _sourceText; syntaxCursor = _syntaxCursor; + parseDiagnostics = []; parsingContext = 0; identifiers = {}; identifierCount = 0; nodeCount = 0; - contextFlags = 0; + contextFlags = ts.isJavaScript(fileName) ? 64 /* JavaScriptFile */ : 0 /* None */; parseErrorBeforeNextFinishedNode = false; - createSourceFile(fileName, languageVersion); // Initialize and prime the scanner before parsing the source elements. scanner.setText(sourceText); scanner.setOnError(scanError); scanner.setScriptTarget(languageVersion); + } + function clearState() { + // Clear out the text the scanner is pointing at, so it doesn't keep anything alive unnecessarily. + scanner.setText(""); + scanner.setOnError(undefined); + // Clear any data. We don't want to accidently hold onto it for too long. + parseDiagnostics = undefined; + sourceFile = undefined; + identifiers = undefined; + syntaxCursor = undefined; + sourceText = undefined; + } + function parseSourceFileWorker(fileName, languageVersion, setParentNodes) { + sourceFile = createSourceFile(fileName, languageVersion); + // Prime the scanner. token = nextToken(); processReferenceComments(sourceFile); sourceFile.statements = parseList(0 /* SourceElements */, true, parseSourceElement); @@ -6474,22 +6913,45 @@ var ts; sourceFile.nodeCount = nodeCount; sourceFile.identifierCount = identifierCount; sourceFile.identifiers = identifiers; + sourceFile.parseDiagnostics = parseDiagnostics; if (setParentNodes) { fixupParentReferences(sourceFile); } - syntaxCursor = undefined; - // Clear out the text the scanner is pointing at, so it doesn't keep anything alive unnecessarily. - scanner.setText(""); - scanner.setOnError(undefined); - var result = sourceFile; - // Clear any data. We don't want to accidently hold onto it for too long. - sourceFile = undefined; - identifiers = undefined; - syntaxCursor = undefined; - sourceText = undefined; - return result; + // If this is a javascript file, proactively see if we can get JSDoc comments for + // relevant nodes in the file. We'll use these to provide typing informaion if they're + // available. + if (ts.isJavaScript(fileName)) { + addJSDocComments(); + } + return sourceFile; + } + function addJSDocComments() { + forEachChild(sourceFile, visit); + return; + function visit(node) { + // Add additional cases as necessary depending on how we see JSDoc comments used + // in the wild. + switch (node.kind) { + case 181 /* VariableStatement */: + case 201 /* FunctionDeclaration */: + case 130 /* Parameter */: + addJSDocComment(node); + } + forEachChild(node, visit); + } + } + function addJSDocComment(node) { + var comments = ts.getLeadingCommentRangesOfNode(node, sourceFile); + if (comments) { + for (var _i = 0; _i < comments.length; _i++) { + var comment = comments[_i]; + var jsDocComment = JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos); + if (jsDocComment) { + node.jsDocComment = jsDocComment; + } + } + } } - Parser.parseSourceFile = parseSourceFile; function fixupParentReferences(sourceFile) { // normally parent references are set during binding. However, for clients that only need // a syntax tree, and no semantic features, then the binding process is an unnecessary @@ -6511,16 +6973,17 @@ var ts; } } } + Parser.fixupParentReferences = fixupParentReferences; function createSourceFile(fileName, languageVersion) { - sourceFile = createNode(228 /* SourceFile */, 0); + var sourceFile = createNode(228 /* SourceFile */, 0); sourceFile.pos = 0; sourceFile.end = sourceText.length; sourceFile.text = sourceText; - sourceFile.parseDiagnostics = []; sourceFile.bindDiagnostics = []; sourceFile.languageVersion = languageVersion; sourceFile.fileName = ts.normalizePath(fileName); sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 2048 /* DeclarationFile */ : 0; + return sourceFile; } function setContextFlag(val, flag) { if (val) { @@ -6628,9 +7091,9 @@ var ts; } function parseErrorAtPosition(start, length, message, arg0) { // Don't report another error if it would just be at the same position as the last error. - var lastError = ts.lastOrUndefined(sourceFile.parseDiagnostics); + var lastError = ts.lastOrUndefined(parseDiagnostics); if (!lastError || start !== lastError.start) { - sourceFile.parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, start, length, message, arg0)); + parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, start, length, message, arg0)); } // Mark that we've encountered an error. We'll set an appropriate bit on the next // node we finish so that it can't be reused incrementally. @@ -6665,7 +7128,7 @@ var ts; // Keep track of the state we'll need to rollback to if lookahead fails (or if the // caller asked us to always reset our state). var saveToken = token; - var saveParseDiagnosticsLength = sourceFile.parseDiagnostics.length; + var saveParseDiagnosticsLength = parseDiagnostics.length; var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; // Note: it is not actually necessary to save/restore the context flags here. That's // because the saving/restorating of these flags happens naturally through the recursive @@ -6683,7 +7146,7 @@ var ts; // then unconditionally restore us to where we were. if (!result || isLookAhead) { token = saveToken; - sourceFile.parseDiagnostics.length = saveParseDiagnosticsLength; + parseDiagnostics.length = saveParseDiagnosticsLength; parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode; } return result; @@ -6779,8 +7242,8 @@ var ts; node.end = pos; return node; } - function finishNode(node) { - node.end = scanner.getStartPos(); + function finishNode(node, end) { + node.end = end === undefined ? scanner.getStartPos() : end; if (contextFlags) { node.parserContextFlags = contextFlags; } @@ -6836,15 +7299,24 @@ var ts; token === 8 /* StringLiteral */ || token === 7 /* NumericLiteral */; } - function parsePropertyName() { + function parsePropertyNameWorker(allowComputedPropertyNames) { if (token === 8 /* StringLiteral */ || token === 7 /* NumericLiteral */) { return parseLiteralNode(true); } - if (token === 18 /* OpenBracketToken */) { + if (allowComputedPropertyNames && token === 18 /* OpenBracketToken */) { return parseComputedPropertyName(); } return parseIdentifierName(); } + function parsePropertyName() { + return parsePropertyNameWorker(true); + } + function parseSimplePropertyName() { + return parsePropertyNameWorker(false); + } + function isSimplePropertyName() { + return token === 8 /* StringLiteral */ || token === 7 /* NumericLiteral */ || isIdentifierOrKeyword(); + } function parseComputedPropertyName() { // PropertyName[Yield,GeneratorParameter] : // LiteralPropertyName @@ -6913,10 +7385,17 @@ var ts; switch (parsingContext) { case 0 /* SourceElements */: case 1 /* ModuleElements */: - return isSourceElement(inErrorRecovery); + // If we're in error recovery, then we don't want to treat ';' as an empty statement. + // The problem is that ';' can show up in far too many contexts, and if we see one + // and assume it's a statement, then we may bail out inappropriately from whatever + // we're parsing. For example, if we have a semicolon in the middle of a class, then + // we really don't want to assume the class is over and we're on a statement in the + // outer module. We just want to consume and move on. + return !(token === 22 /* SemicolonToken */ && inErrorRecovery) && isStartOfModuleElement(); case 2 /* BlockStatements */: case 4 /* SwitchClauseStatements */: - return isStartOfStatement(inErrorRecovery); + // During error recovery we don't treat empty statements as statements + return !(token === 22 /* SemicolonToken */ && inErrorRecovery) && isStartOfStatement(); case 3 /* SwitchClauses */: return token === 67 /* CaseKeyword */ || token === 73 /* DefaultKeyword */; case 5 /* TypeMembers */: @@ -6968,6 +7447,12 @@ var ts; return isHeritageClause(); case 20 /* ImportOrExportSpecifiers */: return isIdentifierOrKeyword(); + case 21 /* JSDocFunctionParameters */: + case 22 /* JSDocTypeArguments */: + case 24 /* JSDocTupleTypes */: + return JSDocParser.isJSDocType(); + case 23 /* JSDocRecordMembers */: + return isSimplePropertyName(); } ts.Debug.fail("Non-exhaustive case in 'isListElement'."); } @@ -7042,6 +7527,14 @@ var ts; return token === 25 /* GreaterThanToken */ || token === 16 /* OpenParenToken */; case 19 /* HeritageClauses */: return token === 14 /* OpenBraceToken */ || token === 15 /* CloseBraceToken */; + case 21 /* JSDocFunctionParameters */: + return token === 17 /* CloseParenToken */ || token === 51 /* ColonToken */ || token === 15 /* CloseBraceToken */; + case 22 /* JSDocTypeArguments */: + return token === 25 /* GreaterThanToken */ || token === 15 /* CloseBraceToken */; + case 24 /* JSDocTupleTypes */: + return token === 19 /* CloseBracketToken */ || token === 15 /* CloseBraceToken */; + case 23 /* JSDocRecordMembers */: + return token === 15 /* CloseBraceToken */; } } function isVariableDeclaratorListTerminator() { @@ -7067,7 +7560,7 @@ var ts; } // True if positioned at element or terminator of the current list or any enclosing list function isInSomeParsingContext() { - for (var kind = 0; kind < 21 /* Count */; kind++) { + for (var kind = 0; kind < 25 /* Count */; kind++) { if (parsingContext & (1 << kind)) { if (isListElement(kind, true) || isListTerminator(kind)) { return true; @@ -7090,7 +7583,7 @@ var ts; // test elements only if we are not already in strict mode if (checkForStrictMode && !inStrictModeContext()) { if (ts.isPrologueDirective(element)) { - if (isUseStrictPrologueDirective(sourceFile, element)) { + if (isUseStrictPrologueDirective(element)) { setStrictModeContext(true); checkForStrictMode = false; } @@ -7111,9 +7604,9 @@ var ts; return result; } /// Should be called only on prologue directives (isPrologueDirective(node) should be true) - function isUseStrictPrologueDirective(sourceFile, node) { + function isUseStrictPrologueDirective(node) { ts.Debug.assert(ts.isPrologueDirective(node)); - var nodeText = ts.getSourceTextOfNodeFromSourceFile(sourceFile, node.expression); + var nodeText = ts.getTextOfNodeFromSourceText(sourceText, node.expression); // Note: the node text must be exactly "use strict" or 'use strict'. It is not ok for the // string to contain unicode escapes (as per ES5). return nodeText === '"use strict"' || nodeText === "'use strict'"; @@ -7386,6 +7879,10 @@ var ts; case 18 /* TupleElementTypes */: return ts.Diagnostics.Type_expected; case 19 /* HeritageClauses */: return ts.Diagnostics.Unexpected_token_expected; case 20 /* ImportOrExportSpecifiers */: return ts.Diagnostics.Identifier_expected; + case 21 /* JSDocFunctionParameters */: return ts.Diagnostics.Parameter_declaration_expected; + case 22 /* JSDocTypeArguments */: return ts.Diagnostics.Type_argument_expected; + case 24 /* JSDocTupleTypes */: return ts.Diagnostics.Type_expected; + case 23 /* JSDocRecordMembers */: return ts.Diagnostics.Property_assignment_expected; } } ; @@ -8245,11 +8742,6 @@ var ts; nextToken(); return !scanner.hasPrecedingLineBreak() && isIdentifier(); } - function nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine() { - nextToken(); - return !scanner.hasPrecedingLineBreak() && - (isIdentifier() || token === 14 /* OpenBraceToken */ || token === 18 /* OpenBracketToken */); - } function parseYieldExpression() { var node = createNode(173 /* YieldExpression */); // YieldExpression[In] : @@ -8421,10 +8913,11 @@ var ts; if (token === 14 /* OpenBraceToken */) { return parseFunctionBlock(false, false); } - if (isStartOfStatement(true) && - !isStartOfExpressionStatement() && + if (token !== 22 /* SemicolonToken */ && token !== 83 /* FunctionKeyword */ && - token !== 69 /* ClassKeyword */) { + token !== 69 /* ClassKeyword */ && + isStartOfStatement() && + !isStartOfExpressionStatement()) { // Check if we got a plain statement (i.e. no expression-statements, no function/class expressions/declarations) // // Here we try to recover from a potential error situation in the case where the @@ -9213,33 +9706,68 @@ var ts; return finishNode(expressionStatement); } } - function isStartOfStatement(inErrorRecovery) { - // Functions, variable statements and classes are allowed as a statement. But as per - // the grammar, they also allow modifiers. So we have to check for those statements - // that might be following modifiers.This ensures that things work properly when - // incrementally parsing as the parser will produce the same FunctionDeclaraiton, - // VariableStatement or ClassDeclaration, if it has the same text regardless of whether - // it is inside a block or not. - if (ts.isModifier(token)) { - var result = lookAhead(parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers); - if (result) { - return true; + function isIdentifierOrKeyword() { + return token >= 65 /* Identifier */; + } + function nextTokenIsIdentifierOrKeywordOnSameLine() { + nextToken(); + return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak(); + } + function parseDeclarationFlags() { + while (true) { + switch (token) { + case 98 /* VarKeyword */: + case 104 /* LetKeyword */: + case 70 /* ConstKeyword */: + case 83 /* FunctionKeyword */: + case 69 /* ClassKeyword */: + case 77 /* EnumKeyword */: + return 1 /* Statement */; + case 103 /* InterfaceKeyword */: + case 124 /* TypeKeyword */: + nextToken(); + return isIdentifierOrKeyword() ? 1 /* Statement */ : 0 /* None */; + case 117 /* ModuleKeyword */: + case 118 /* NamespaceKeyword */: + nextToken(); + return isIdentifierOrKeyword() || token === 8 /* StringLiteral */ ? 2 /* ModuleElement */ : 0 /* None */; + case 85 /* ImportKeyword */: + nextToken(); + return token === 8 /* StringLiteral */ || token === 35 /* AsteriskToken */ || + token === 14 /* OpenBraceToken */ || isIdentifierOrKeyword() ? + 2 /* ModuleElement */ : 0 /* None */; + case 78 /* ExportKeyword */: + nextToken(); + if (token === 53 /* EqualsToken */ || token === 35 /* AsteriskToken */ || + token === 14 /* OpenBraceToken */ || token === 73 /* DefaultKeyword */) { + return 2 /* ModuleElement */; + } + continue; + case 115 /* DeclareKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: + case 109 /* StaticKeyword */: + nextToken(); + continue; + default: + return 0 /* None */; } } + } + function getDeclarationFlags() { + return lookAhead(parseDeclarationFlags); + } + function getStatementFlags() { switch (token) { + case 52 /* AtToken */: case 22 /* SemicolonToken */: - // If we're in error recovery, then we don't want to treat ';' as an empty statement. - // The problem is that ';' can show up in far too many contexts, and if we see one - // and assume it's a statement, then we may bail out inappropriately from whatever - // we're parsing. For example, if we have a semicolon in the middle of a class, then - // we really don't want to assume the class is over and we're on a statement in the - // outer module. We just want to consume and move on. - return !inErrorRecovery; case 14 /* OpenBraceToken */: case 98 /* VarKeyword */: case 104 /* LetKeyword */: case 83 /* FunctionKeyword */: case 69 /* ClassKeyword */: + case 77 /* EnumKeyword */: case 84 /* IfKeyword */: case 75 /* DoKeyword */: case 100 /* WhileKeyword */: @@ -9256,58 +9784,72 @@ var ts; // however, we say they are here so that we may gracefully parse them and error later. case 68 /* CatchKeyword */: case 81 /* FinallyKeyword */: - return true; + return 1 /* Statement */; case 70 /* ConstKeyword */: - // const keyword can precede enum keyword when defining constant enums - // 'const enum' do not start statement. - // In ES 6 'enum' is a future reserved keyword, so it should not be used as identifier - var isConstEnum = lookAhead(nextTokenIsEnumKeyword); - return !isConstEnum; + case 78 /* ExportKeyword */: + case 85 /* ImportKeyword */: + return getDeclarationFlags(); + case 115 /* DeclareKeyword */: case 103 /* InterfaceKeyword */: case 117 /* ModuleKeyword */: case 118 /* NamespaceKeyword */: - case 77 /* EnumKeyword */: case 124 /* TypeKeyword */: - // When followed by an identifier, these do not start a statement but might - // instead be following declarations - if (isDeclarationStart()) { - return false; - } + // When these don't start a declaration, they're an identifier in an expression statement + return getDeclarationFlags() || 1 /* Statement */; case 108 /* PublicKeyword */: case 106 /* PrivateKeyword */: case 107 /* ProtectedKeyword */: case 109 /* StaticKeyword */: - // When followed by an identifier or keyword, these do not start a statement but - // might instead be following type members - if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine)) { - return false; - } + // When these don't start a declaration, they may be the start of a class member if an identifier + // immediately follows. Otherwise they're an identifier in an expression statement. + return getDeclarationFlags() || + (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine) ? 0 /* None */ : 1 /* Statement */); default: - return isStartOfExpression(); + return isStartOfExpression() ? 1 /* Statement */ : 0 /* None */; } } - function nextTokenIsEnumKeyword() { - nextToken(); - return token === 77 /* EnumKeyword */; + function isStartOfStatement() { + return (getStatementFlags() & 1 /* Statement */) !== 0; } - function nextTokenIsIdentifierOrKeywordOnSameLine() { + function isStartOfModuleElement() { + return (getStatementFlags() & 3 /* StatementOrModuleElement */) !== 0; + } + function nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine() { nextToken(); - return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak(); + return !scanner.hasPrecedingLineBreak() && + (isIdentifier() || token === 14 /* OpenBraceToken */ || token === 18 /* OpenBracketToken */); + } + function isLetDeclaration() { + // It is let declaration if in strict mode or next token is identifier\open bracket\open curly on same line. + // otherwise it needs to be treated like identifier + return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine); } function parseStatement() { + return parseModuleElementOfKind(1 /* Statement */); + } + function parseModuleElement() { + return parseModuleElementOfKind(3 /* StatementOrModuleElement */); + } + function parseSourceElement() { + return parseModuleElementOfKind(3 /* StatementOrModuleElement */); + } + function parseModuleElementOfKind(flags) { switch (token) { + case 22 /* SemicolonToken */: + return parseEmptyStatement(); case 14 /* OpenBraceToken */: return parseBlock(false, false); case 98 /* VarKeyword */: - case 70 /* ConstKeyword */: - // const here should always be parsed as const declaration because of check in 'isStatement' return parseVariableStatement(scanner.getStartPos(), undefined, undefined); + case 104 /* LetKeyword */: + if (isLetDeclaration()) { + return parseVariableStatement(scanner.getStartPos(), undefined, undefined); + } + break; case 83 /* FunctionKeyword */: return parseFunctionDeclaration(scanner.getStartPos(), undefined, undefined); case 69 /* ClassKeyword */: return parseClassDeclaration(scanner.getStartPos(), undefined, undefined); - case 22 /* SemicolonToken */: - return parseEmptyStatement(); case 84 /* IfKeyword */: return parseIfStatement(); case 75 /* DoKeyword */: @@ -9335,54 +9877,68 @@ var ts; return parseTryStatement(); case 72 /* DebuggerKeyword */: return parseDebuggerStatement(); - case 104 /* LetKeyword */: - // If let follows identifier on the same line, it is declaration parse it as variable statement - if (isLetDeclaration()) { - return parseVariableStatement(scanner.getStartPos(), undefined, undefined); + case 52 /* AtToken */: + return parseDeclaration(); + case 70 /* ConstKeyword */: + case 115 /* DeclareKeyword */: + case 77 /* EnumKeyword */: + case 78 /* ExportKeyword */: + case 85 /* ImportKeyword */: + case 103 /* InterfaceKeyword */: + case 117 /* ModuleKeyword */: + case 118 /* NamespaceKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: + case 108 /* PublicKeyword */: + case 109 /* StaticKeyword */: + case 124 /* TypeKeyword */: + if (getDeclarationFlags() & flags) { + return parseDeclaration(); } - // Else parse it like identifier - fall through - default: - // Functions and variable statements are allowed as a statement. But as per - // the grammar, they also allow modifiers. So we have to check for those - // statements that might be following modifiers. This ensures that things - // work properly when incrementally parsing as the parser will produce the - // same FunctionDeclaraiton or VariableStatement if it has the same text - // regardless of whether it is inside a block or not. - // Even though variable statements and function declarations cannot have decorators, - // we parse them here to provide better error recovery. - if (ts.isModifier(token) || token === 52 /* AtToken */) { - var result = tryParse(parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers); - if (result) { - return result; - } - } - return parseExpressionOrLabeledStatement(); + break; } + return parseExpressionOrLabeledStatement(); } - function parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers() { - var start = scanner.getStartPos(); + function parseDeclaration() { + var fullStart = getNodePos(); var decorators = parseDecorators(); var modifiers = parseModifiers(); switch (token) { - case 70 /* ConstKeyword */: - var nextTokenIsEnum = lookAhead(nextTokenIsEnumKeyword); - if (nextTokenIsEnum) { - return undefined; - } - return parseVariableStatement(start, decorators, modifiers); - case 104 /* LetKeyword */: - if (!isLetDeclaration()) { - return undefined; - } - return parseVariableStatement(start, decorators, modifiers); case 98 /* VarKeyword */: - return parseVariableStatement(start, decorators, modifiers); + case 104 /* LetKeyword */: + case 70 /* ConstKeyword */: + return parseVariableStatement(fullStart, decorators, modifiers); case 83 /* FunctionKeyword */: - return parseFunctionDeclaration(start, decorators, modifiers); + return parseFunctionDeclaration(fullStart, decorators, modifiers); case 69 /* ClassKeyword */: - return parseClassDeclaration(start, decorators, modifiers); + return parseClassDeclaration(fullStart, decorators, modifiers); + case 103 /* InterfaceKeyword */: + return parseInterfaceDeclaration(fullStart, decorators, modifiers); + case 124 /* TypeKeyword */: + return parseTypeAliasDeclaration(fullStart, decorators, modifiers); + case 77 /* EnumKeyword */: + return parseEnumDeclaration(fullStart, decorators, modifiers); + case 117 /* ModuleKeyword */: + case 118 /* NamespaceKeyword */: + return parseModuleDeclaration(fullStart, decorators, modifiers); + case 85 /* ImportKeyword */: + return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); + case 78 /* ExportKeyword */: + nextToken(); + return token === 73 /* DefaultKeyword */ || token === 53 /* EqualsToken */ ? + parseExportAssignment(fullStart, decorators, modifiers) : + parseExportDeclaration(fullStart, decorators, modifiers); + default: + if (decorators) { + // We reached this point because we encountered decorators and/or modifiers and assumed a declaration + // would follow. For recovery and error reporting purposes, return an incomplete declaration. + var node = createMissingNode(219 /* MissingDeclaration */, true, ts.Diagnostics.Declaration_expected); + node.pos = fullStart; + node.decorators = decorators; + setModifiers(node, modifiers); + return finishNode(node); + } } - return undefined; } function parseFunctionBlockOrSemicolon(isGenerator, diagnosticMessage) { if (token !== 14 /* OpenBraceToken */ && canParseSemicolon()) { @@ -9537,7 +10093,18 @@ var ts; property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); - property.initializer = allowInAnd(parseNonParameterInitializer); + // For instance properties specifically, since they are evaluated inside the constructor, + // we do *not * want to parse yield expressions, so we specifically turn the yield context + // off. The grammar would look something like this: + // + // MemberVariableDeclaration[Yield]: + // AccessibilityModifier_opt PropertyName TypeAnnotation_opt Initialiser_opt[In]; + // AccessibilityModifier_opt static_opt PropertyName TypeAnnotation_opt Initialiser_opt[In, ?Yield]; + // + // The checker may still error in the static case to explicitly disallow the yield expression. + property.initializer = modifiers && modifiers.flags & 128 /* Static */ + ? allowInAnd(parseNonParameterInitializer) + : doOutsideOfContext(4 /* Yield */ | 2 /* DisallowIn */, parseNonParameterInitializer); parseSemicolon(); return finishNode(property); } @@ -9707,17 +10274,17 @@ var ts; } if (decorators) { // treat this as a property declaration with a missing name. - var name_3 = createMissingNode(65 /* Identifier */, true, ts.Diagnostics.Declaration_expected); - return parsePropertyDeclaration(fullStart, decorators, modifiers, name_3, undefined); + var name_5 = createMissingNode(65 /* Identifier */, true, ts.Diagnostics.Declaration_expected); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name_5, undefined); } // 'isClassMemberStart' should have hinted not to attempt parsing. ts.Debug.fail("Should not have attempted to parse class member declaration."); } function parseClassExpression() { return parseClassDeclarationOrExpression( - /*fullStart:*/ scanner.getStartPos(), - /*decorators:*/ undefined, - /*modifiers:*/ undefined, 175 /* ClassExpression */); + /*fullStart*/ scanner.getStartPos(), + /*decorators*/ undefined, + /*modifiers*/ undefined, 175 /* ClassExpression */); } function parseClassDeclaration(fullStart, decorators, modifiers) { return parseClassDeclarationOrExpression(fullStart, decorators, modifiers, 202 /* ClassDeclaration */); @@ -10059,136 +10626,6 @@ var ts; parseSemicolon(); return finishNode(node); } - function isLetDeclaration() { - // It is let declaration if in strict mode or next token is identifier\open bracket\open curly on same line. - // otherwise it needs to be treated like identifier - return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine); - } - function isDeclarationStart(followsModifier) { - switch (token) { - case 98 /* VarKeyword */: - case 70 /* ConstKeyword */: - case 83 /* FunctionKeyword */: - return true; - case 104 /* LetKeyword */: - return isLetDeclaration(); - case 69 /* ClassKeyword */: - case 103 /* InterfaceKeyword */: - case 77 /* EnumKeyword */: - case 124 /* TypeKeyword */: - // Not true keywords so ensure an identifier follows - return lookAhead(nextTokenIsIdentifierOrKeyword); - case 85 /* ImportKeyword */: - // Not true keywords so ensure an identifier follows or is string literal or asterisk or open brace - return lookAhead(nextTokenCanFollowImportKeyword); - case 117 /* ModuleKeyword */: - case 118 /* NamespaceKeyword */: - // Not a true keyword so ensure an identifier or string literal follows - return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral); - case 78 /* ExportKeyword */: - // Check for export assignment or modifier on source element - return lookAhead(nextTokenCanFollowExportKeyword); - case 115 /* DeclareKeyword */: - case 108 /* PublicKeyword */: - case 106 /* PrivateKeyword */: - case 107 /* ProtectedKeyword */: - case 109 /* StaticKeyword */: - // Check for modifier on source element - return lookAhead(nextTokenIsDeclarationStart); - case 52 /* AtToken */: - // a lookahead here is too costly, and decorators are only valid on a declaration. - // We will assume we are parsing a declaration here and report an error later - return !followsModifier; - } - } - function isIdentifierOrKeyword() { - return token >= 65 /* Identifier */; - } - function nextTokenIsIdentifierOrKeyword() { - nextToken(); - return isIdentifierOrKeyword(); - } - function nextTokenIsIdentifierOrKeywordOrStringLiteral() { - nextToken(); - return isIdentifierOrKeyword() || token === 8 /* StringLiteral */; - } - function nextTokenCanFollowImportKeyword() { - nextToken(); - return isIdentifierOrKeyword() || token === 8 /* StringLiteral */ || - token === 35 /* AsteriskToken */ || token === 14 /* OpenBraceToken */; - } - function nextTokenCanFollowExportKeyword() { - nextToken(); - return token === 53 /* EqualsToken */ || token === 35 /* AsteriskToken */ || - token === 14 /* OpenBraceToken */ || token === 73 /* DefaultKeyword */ || isDeclarationStart(true); - } - function nextTokenIsDeclarationStart() { - nextToken(); - return isDeclarationStart(true); - } - function nextTokenIsAsKeyword() { - return nextToken() === 111 /* AsKeyword */; - } - function parseDeclaration() { - var fullStart = getNodePos(); - var decorators = parseDecorators(); - var modifiers = parseModifiers(); - if (token === 78 /* ExportKeyword */) { - nextToken(); - if (token === 73 /* DefaultKeyword */ || token === 53 /* EqualsToken */) { - return parseExportAssignment(fullStart, decorators, modifiers); - } - if (token === 35 /* AsteriskToken */ || token === 14 /* OpenBraceToken */) { - return parseExportDeclaration(fullStart, decorators, modifiers); - } - } - switch (token) { - case 98 /* VarKeyword */: - case 104 /* LetKeyword */: - case 70 /* ConstKeyword */: - return parseVariableStatement(fullStart, decorators, modifiers); - case 83 /* FunctionKeyword */: - return parseFunctionDeclaration(fullStart, decorators, modifiers); - case 69 /* ClassKeyword */: - return parseClassDeclaration(fullStart, decorators, modifiers); - case 103 /* InterfaceKeyword */: - return parseInterfaceDeclaration(fullStart, decorators, modifiers); - case 124 /* TypeKeyword */: - return parseTypeAliasDeclaration(fullStart, decorators, modifiers); - case 77 /* EnumKeyword */: - return parseEnumDeclaration(fullStart, decorators, modifiers); - case 117 /* ModuleKeyword */: - case 118 /* NamespaceKeyword */: - return parseModuleDeclaration(fullStart, decorators, modifiers); - case 85 /* ImportKeyword */: - return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); - default: - if (decorators) { - // We reached this point because we encountered an AtToken and assumed a declaration would - // follow. For recovery and error reporting purposes, return an incomplete declaration. - var node = createMissingNode(219 /* MissingDeclaration */, true, ts.Diagnostics.Declaration_expected); - node.pos = fullStart; - node.decorators = decorators; - setModifiers(node, modifiers); - return finishNode(node); - } - ts.Debug.fail("Mismatch between isDeclarationStart and parseDeclaration"); - } - } - function isSourceElement(inErrorRecovery) { - return isDeclarationStart() || isStartOfStatement(inErrorRecovery); - } - function parseSourceElement() { - return parseSourceElementOrModuleElement(); - } - function parseModuleElement() { - return parseSourceElementOrModuleElement(); - } - function parseSourceElementOrModuleElement() { - return isDeclarationStart() - ? parseDeclaration() - : parseStatement(); - } function processReferenceComments(sourceFile) { var triviaScanner = ts.createScanner(sourceFile.languageVersion, false, sourceText); var referencedFiles = []; @@ -10216,7 +10653,7 @@ var ts; referencedFiles.push(fileReference); } if (diagnosticMessage) { - sourceFile.parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage)); + parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage)); } } else { @@ -10224,7 +10661,7 @@ var ts; var amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment); if (amdModuleNameMatchResult) { if (amdModuleName) { - sourceFile.parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, ts.Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments)); + parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, ts.Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments)); } amdModuleName = amdModuleNameMatchResult[2]; } @@ -10280,7 +10717,11 @@ var ts; ParsingContext[ParsingContext["TupleElementTypes"] = 18] = "TupleElementTypes"; ParsingContext[ParsingContext["HeritageClauses"] = 19] = "HeritageClauses"; ParsingContext[ParsingContext["ImportOrExportSpecifiers"] = 20] = "ImportOrExportSpecifiers"; - ParsingContext[ParsingContext["Count"] = 21] = "Count"; // Number of parsing contexts + ParsingContext[ParsingContext["JSDocFunctionParameters"] = 21] = "JSDocFunctionParameters"; + ParsingContext[ParsingContext["JSDocTypeArguments"] = 22] = "JSDocTypeArguments"; + ParsingContext[ParsingContext["JSDocRecordMembers"] = 23] = "JSDocRecordMembers"; + ParsingContext[ParsingContext["JSDocTupleTypes"] = 24] = "JSDocTupleTypes"; + ParsingContext[ParsingContext["Count"] = 25] = "Count"; // Number of parsing contexts })(ParsingContext || (ParsingContext = {})); var Tristate; (function (Tristate) { @@ -10288,6 +10729,546 @@ var ts; Tristate[Tristate["True"] = 1] = "True"; Tristate[Tristate["Unknown"] = 2] = "Unknown"; })(Tristate || (Tristate = {})); + var JSDocParser; + (function (JSDocParser) { + function isJSDocType() { + switch (token) { + case 35 /* AsteriskToken */: + case 50 /* QuestionToken */: + case 16 /* OpenParenToken */: + case 18 /* OpenBracketToken */: + case 46 /* ExclamationToken */: + case 14 /* OpenBraceToken */: + case 83 /* FunctionKeyword */: + case 21 /* DotDotDotToken */: + case 88 /* NewKeyword */: + case 93 /* ThisKeyword */: + return true; + } + return isIdentifierOrKeyword(); + } + JSDocParser.isJSDocType = isJSDocType; + function parseJSDocTypeExpressionForTests(content, start, length) { + initializeState("file.js", content, 2 /* Latest */, undefined); + var jsDocTypeExpression = parseJSDocTypeExpression(start, length); + var diagnostics = parseDiagnostics; + clearState(); + return jsDocTypeExpression ? { jsDocTypeExpression: jsDocTypeExpression, diagnostics: diagnostics } : undefined; + } + JSDocParser.parseJSDocTypeExpressionForTests = parseJSDocTypeExpressionForTests; + // Parses out a JSDoc type expression. The starting position should be right at the open + // curly in the type expression. Returns 'undefined' if it encounters any errors while parsing. + /* @internal */ + function parseJSDocTypeExpression(start, length) { + scanner.setText(sourceText, start, length); + // Prime the first token for us to start processing. + token = nextToken(); + var result = createNode(229 /* JSDocTypeExpression */); + parseExpected(14 /* OpenBraceToken */); + result.type = parseJSDocTopLevelType(); + parseExpected(15 /* CloseBraceToken */); + fixupParentReferences(result); + return finishNode(result); + } + JSDocParser.parseJSDocTypeExpression = parseJSDocTypeExpression; + function parseJSDocTopLevelType() { + var type = parseJSDocType(); + if (token === 44 /* BarToken */) { + var unionType = createNode(233 /* JSDocUnionType */, type.pos); + unionType.types = parseJSDocTypeList(type); + type = finishNode(unionType); + } + if (token === 53 /* EqualsToken */) { + var optionalType = createNode(240 /* JSDocOptionalType */, type.pos); + nextToken(); + optionalType.type = type; + type = finishNode(optionalType); + } + return type; + } + function parseJSDocType() { + var type = parseBasicTypeExpression(); + while (true) { + if (token === 18 /* OpenBracketToken */) { + var arrayType = createNode(232 /* JSDocArrayType */, type.pos); + arrayType.elementType = type; + nextToken(); + parseExpected(19 /* CloseBracketToken */); + type = finishNode(arrayType); + } + else if (token === 50 /* QuestionToken */) { + var nullableType = createNode(235 /* JSDocNullableType */, type.pos); + nullableType.type = type; + nextToken(); + type = finishNode(nullableType); + } + else if (token === 46 /* ExclamationToken */) { + var nonNullableType = createNode(236 /* JSDocNonNullableType */, type.pos); + nonNullableType.type = type; + nextToken(); + type = finishNode(nonNullableType); + } + else { + break; + } + } + return type; + } + function parseBasicTypeExpression() { + switch (token) { + case 35 /* AsteriskToken */: + return parseJSDocAllType(); + case 50 /* QuestionToken */: + return parseJSDocUnknownOrNullableType(); + case 16 /* OpenParenToken */: + return parseJSDocUnionType(); + case 18 /* OpenBracketToken */: + return parseJSDocTupleType(); + case 46 /* ExclamationToken */: + return parseJSDocNonNullableType(); + case 14 /* OpenBraceToken */: + return parseJSDocRecordType(); + case 83 /* FunctionKeyword */: + return parseJSDocFunctionType(); + case 21 /* DotDotDotToken */: + return parseJSDocVariadicType(); + case 88 /* NewKeyword */: + return parseJSDocConstructorType(); + case 93 /* ThisKeyword */: + return parseJSDocThisType(); + case 112 /* AnyKeyword */: + case 122 /* StringKeyword */: + case 120 /* NumberKeyword */: + case 113 /* BooleanKeyword */: + case 123 /* SymbolKeyword */: + case 99 /* VoidKeyword */: + return parseTokenNode(); + } + return parseJSDocTypeReference(); + } + function parseJSDocThisType() { + var result = createNode(244 /* JSDocThisType */); + nextToken(); + parseExpected(51 /* ColonToken */); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocConstructorType() { + var result = createNode(243 /* JSDocConstructorType */); + nextToken(); + parseExpected(51 /* ColonToken */); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocVariadicType() { + var result = createNode(242 /* JSDocVariadicType */); + nextToken(); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocFunctionType() { + var result = createNode(241 /* JSDocFunctionType */); + nextToken(); + parseExpected(16 /* OpenParenToken */); + result.parameters = parseDelimitedList(21 /* JSDocFunctionParameters */, parseJSDocParameter); + checkForTrailingComma(result.parameters); + parseExpected(17 /* CloseParenToken */); + if (token === 51 /* ColonToken */) { + nextToken(); + result.type = parseJSDocType(); + } + return finishNode(result); + } + function parseJSDocParameter() { + var parameter = createNode(130 /* Parameter */); + parameter.type = parseJSDocType(); + return finishNode(parameter); + } + function parseJSDocOptionalType(type) { + var result = createNode(240 /* JSDocOptionalType */, type.pos); + nextToken(); + result.type = type; + return finishNode(result); + } + function parseJSDocTypeReference() { + var result = createNode(239 /* JSDocTypeReference */); + result.name = parseSimplePropertyName(); + while (parseOptional(20 /* DotToken */)) { + if (token === 24 /* LessThanToken */) { + result.typeArguments = parseTypeArguments(); + break; + } + else { + result.name = parseQualifiedName(result.name); + } + } + return finishNode(result); + } + function parseTypeArguments() { + // Move past the < + nextToken(); + var typeArguments = parseDelimitedList(22 /* JSDocTypeArguments */, parseJSDocType); + checkForTrailingComma(typeArguments); + checkForEmptyTypeArgumentList(typeArguments); + parseExpected(25 /* GreaterThanToken */); + return typeArguments; + } + function checkForEmptyTypeArgumentList(typeArguments) { + if (parseDiagnostics.length === 0 && typeArguments && typeArguments.length === 0) { + var start = typeArguments.pos - "<".length; + var end = ts.skipTrivia(sourceText, typeArguments.end) + ">".length; + return parseErrorAtPosition(start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty); + } + } + function parseQualifiedName(left) { + var result = createNode(127 /* QualifiedName */, left.pos); + result.left = left; + result.right = parseIdentifierName(); + return finishNode(result); + } + function parseJSDocRecordType() { + var result = createNode(237 /* JSDocRecordType */); + nextToken(); + result.members = parseDelimitedList(23 /* JSDocRecordMembers */, parseJSDocRecordMember); + checkForTrailingComma(result.members); + parseExpected(15 /* CloseBraceToken */); + return finishNode(result); + } + function parseJSDocRecordMember() { + var result = createNode(238 /* JSDocRecordMember */); + result.name = parseSimplePropertyName(); + if (token === 51 /* ColonToken */) { + nextToken(); + result.type = parseJSDocType(); + } + return finishNode(result); + } + function parseJSDocNonNullableType() { + var result = createNode(236 /* JSDocNonNullableType */); + nextToken(); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocTupleType() { + var result = createNode(234 /* JSDocTupleType */); + nextToken(); + result.types = parseDelimitedList(24 /* JSDocTupleTypes */, parseJSDocType); + checkForTrailingComma(result.types); + parseExpected(19 /* CloseBracketToken */); + return finishNode(result); + } + function checkForTrailingComma(list) { + if (parseDiagnostics.length === 0 && list.hasTrailingComma) { + var start = list.end - ",".length; + parseErrorAtPosition(start, ",".length, ts.Diagnostics.Trailing_comma_not_allowed); + } + } + function parseJSDocUnionType() { + var result = createNode(233 /* JSDocUnionType */); + nextToken(); + result.types = parseJSDocTypeList(parseJSDocType()); + parseExpected(17 /* CloseParenToken */); + return finishNode(result); + } + function parseJSDocTypeList(firstType) { + ts.Debug.assert(!!firstType); + var types = []; + types.pos = firstType.pos; + types.push(firstType); + while (parseOptional(44 /* BarToken */)) { + types.push(parseJSDocType()); + } + types.end = scanner.getStartPos(); + return types; + } + function parseJSDocAllType() { + var result = createNode(230 /* JSDocAllType */); + nextToken(); + return finishNode(result); + } + function parseJSDocUnknownOrNullableType() { + var pos = scanner.getStartPos(); + // skip the ? + nextToken(); + // Need to lookahead to decide if this is a nullable or unknown type. + // Here are cases where we'll pick the unknown type: + // + // Foo(?, + // { a: ? } + // Foo(?) + // Foo + // Foo(?= + // (?| + if (token === 23 /* CommaToken */ || + token === 15 /* CloseBraceToken */ || + token === 17 /* CloseParenToken */ || + token === 25 /* GreaterThanToken */ || + token === 53 /* EqualsToken */ || + token === 44 /* BarToken */) { + var result = createNode(231 /* JSDocUnknownType */, pos); + return finishNode(result); + } + else { + var result = createNode(235 /* JSDocNullableType */, pos); + result.type = parseJSDocType(); + return finishNode(result); + } + } + function parseIsolatedJSDocComment(content, start, length) { + initializeState("file.js", content, 2 /* Latest */, undefined); + var jsDocComment = parseJSDocComment(undefined, start, length); + var diagnostics = parseDiagnostics; + clearState(); + return jsDocComment ? { jsDocComment: jsDocComment, diagnostics: diagnostics } : undefined; + } + JSDocParser.parseIsolatedJSDocComment = parseIsolatedJSDocComment; + function parseJSDocComment(parent, start, length) { + var comment = parseJSDocCommentWorker(start, length); + if (comment) { + fixupParentReferences(comment); + comment.parent = parent; + } + return comment; + } + JSDocParser.parseJSDocComment = parseJSDocComment; + function parseJSDocCommentWorker(start, length) { + var content = sourceText; + start = start || 0; + var end = length === undefined ? content.length : start + length; + length = end - start; + ts.Debug.assert(start >= 0); + ts.Debug.assert(start <= end); + ts.Debug.assert(end <= content.length); + var tags; + var pos; + // NOTE(cyrusn): This is essentially a handwritten scanner for JSDocComments. I + // considered using an actual Scanner, but this would complicate things. The + // scanner would need to know it was in a Doc Comment. Otherwise, it would then + // produce comments *inside* the doc comment. In the end it was just easier to + // write a simple scanner rather than go that route. + if (length >= "/** */".length) { + if (content.charCodeAt(start) === 47 /* slash */ && + content.charCodeAt(start + 1) === 42 /* asterisk */ && + content.charCodeAt(start + 2) === 42 /* asterisk */ && + content.charCodeAt(start + 3) !== 42 /* asterisk */) { + // Initially we can parse out a tag. We also have seen a starting asterisk. + // This is so that /** * @type */ doesn't parse. + var canParseTag = true; + var seenAsterisk = true; + for (pos = start + "/**".length; pos < end;) { + var ch = content.charCodeAt(pos); + pos++; + if (ch === 64 /* at */ && canParseTag) { + parseTag(); + // Once we parse out a tag, we cannot keep parsing out tags on this line. + canParseTag = false; + continue; + } + if (ts.isLineBreak(ch)) { + // After a line break, we can parse a tag, and we haven't seen as asterisk + // on the next line yet. + canParseTag = true; + seenAsterisk = false; + continue; + } + if (ts.isWhiteSpace(ch)) { + // Whitespace doesn't affect any of our parsing. + continue; + } + // Ignore the first asterisk on a line. + if (ch === 42 /* asterisk */) { + if (seenAsterisk) { + // If we've already seen an asterisk, then we can no longer parse a tag + // on this line. + canParseTag = false; + } + seenAsterisk = true; + continue; + } + // Anything else is doc comment text. We can't do anything with it. Because it + // wasn't a tag, we can no longer parse a tag on this line until we hit the next + // line break. + canParseTag = false; + } + } + } + return createJSDocComment(); + function createJSDocComment() { + if (!tags) { + return undefined; + } + var result = createNode(245 /* JSDocComment */, start); + result.tags = tags; + return finishNode(result, end); + } + function skipWhitespace() { + while (pos < end && ts.isWhiteSpace(content.charCodeAt(pos))) { + pos++; + } + } + function parseTag() { + ts.Debug.assert(content.charCodeAt(pos - 1) === 64 /* at */); + var atToken = createNode(52 /* AtToken */, pos - 1); + atToken.end = pos; + var startPos = pos; + var tagName = scanIdentifier(); + if (!tagName) { + return; + } + var tag = handleTag(atToken, tagName) || handleUnknownTag(atToken, tagName); + addTag(tag); + } + function handleTag(atToken, tagName) { + if (tagName) { + switch (tagName.text) { + case "param": + return handleParamTag(atToken, tagName); + case "return": + case "returns": + return handleReturnTag(atToken, tagName); + case "template": + return handleTemplateTag(atToken, tagName); + case "type": + return handleTypeTag(atToken, tagName); + } + } + return undefined; + } + function handleUnknownTag(atToken, tagName) { + var result = createNode(246 /* JSDocTag */, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + return finishNode(result, pos); + } + function addTag(tag) { + if (tag) { + if (!tags) { + tags = []; + tags.pos = tag.pos; + } + tags.push(tag); + tags.end = tag.end; + } + } + function tryParseTypeExpression() { + skipWhitespace(); + if (content.charCodeAt(pos) !== 123 /* openBrace */) { + return undefined; + } + var typeExpression = parseJSDocTypeExpression(pos, end - pos); + pos = typeExpression.end; + return typeExpression; + } + function handleParamTag(atToken, tagName) { + var typeExpression = tryParseTypeExpression(); + skipWhitespace(); + var name; + var isBracketed; + if (content.charCodeAt(pos) === 91 /* openBracket */) { + pos++; + skipWhitespace(); + name = scanIdentifier(); + isBracketed = true; + } + else { + name = scanIdentifier(); + } + if (!name) { + parseErrorAtPosition(pos, 0, ts.Diagnostics.Identifier_expected); + return undefined; + } + var preName, postName; + if (typeExpression) { + postName = name; + } + else { + preName = name; + } + if (!typeExpression) { + typeExpression = tryParseTypeExpression(); + } + var result = createNode(247 /* JSDocParameterTag */, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.preParameterName = preName; + result.typeExpression = typeExpression; + result.postParameterName = postName; + result.isBracketed = isBracketed; + return finishNode(result, pos); + } + function handleReturnTag(atToken, tagName) { + if (ts.forEach(tags, function (t) { return t.kind === 248 /* JSDocReturnTag */; })) { + parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); + } + var result = createNode(248 /* JSDocReturnTag */, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.typeExpression = tryParseTypeExpression(); + return finishNode(result, pos); + } + function handleTypeTag(atToken, tagName) { + if (ts.forEach(tags, function (t) { return t.kind === 249 /* JSDocTypeTag */; })) { + parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); + } + var result = createNode(249 /* JSDocTypeTag */, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.typeExpression = tryParseTypeExpression(); + return finishNode(result, pos); + } + function handleTemplateTag(atToken, tagName) { + if (ts.forEach(tags, function (t) { return t.kind === 250 /* JSDocTemplateTag */; })) { + parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); + } + var typeParameters = []; + typeParameters.pos = pos; + while (true) { + skipWhitespace(); + var startPos = pos; + var name_6 = scanIdentifier(); + if (!name_6) { + parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); + return undefined; + } + var typeParameter = createNode(129 /* TypeParameter */, name_6.pos); + typeParameter.name = name_6; + finishNode(typeParameter, pos); + typeParameters.push(typeParameter); + skipWhitespace(); + if (content.charCodeAt(pos) !== 44 /* comma */) { + break; + } + pos++; + } + typeParameters.end = pos; + var result = createNode(250 /* JSDocTemplateTag */, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.typeParameters = typeParameters; + return finishNode(result, pos); + } + function scanIdentifier() { + var startPos = pos; + for (; pos < end; pos++) { + var ch = content.charCodeAt(pos); + if (pos === startPos && ts.isIdentifierStart(ch, 2 /* Latest */)) { + continue; + } + else if (pos > startPos && ts.isIdentifierPart(ch, 2 /* Latest */)) { + continue; + } + break; + } + if (startPos === pos) { + return undefined; + } + var result = createNode(65 /* Identifier */, startPos); + result.text = content.substring(startPos, pos); + return finishNode(result, pos); + } + } + JSDocParser.parseJSDocCommentWorker = parseJSDocCommentWorker; + })(JSDocParser = Parser.JSDocParser || (Parser.JSDocParser = {})); })(Parser || (Parser = {})); var IncrementalParser; (function (IncrementalParser) { @@ -10375,7 +11356,12 @@ var ts; } // Ditch any existing LS children we may have created. This way we can avoid // moving them forward. - node._children = undefined; + if (node._children) { + node._children = undefined; + } + if (node.jsDocComment) { + node.jsDocComment = undefined; + } node.pos += delta; node.end += delta; if (aggressiveChecks && shouldCheckNode(node)) { @@ -10835,13 +11821,15 @@ var ts; var undefinedType = createIntrinsicType(32 /* Undefined */ | 262144 /* ContainsUndefinedOrNull */, "undefined"); var nullType = createIntrinsicType(64 /* Null */ | 262144 /* ContainsUndefinedOrNull */, "null"); var unknownType = createIntrinsicType(1 /* Any */, "unknown"); + var circularType = createIntrinsicType(1 /* Any */, "__circular__"); var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + var emptyGenericType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + emptyGenericType.instantiations = {}; var anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); var noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); var anySignature = createSignature(undefined, undefined, emptyArray, anyType, 0, false, false); var unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, false, false); var globals = {}; - var globalArraySymbol; var globalESSymbolConstructorSymbol; var globalObjectType; var globalFunctionType; @@ -10853,6 +11841,8 @@ var ts; var globalTemplateStringsArrayType; var globalESSymbolType; var globalIterableType; + var globalIteratorType; + var globalIterableIteratorType; var anyArrayType; var getGlobalClassDecoratorType; var getGlobalParameterDecoratorType; @@ -11079,7 +12069,15 @@ var ts; // Locals of a source file are not in scope (because they get merged into the global symbol table) if (location.locals && !isGlobalSourceFile(location)) { if (result = getSymbol(location.locals, name, meaning)) { - break loop; + // Type parameters of a function are in scope in the entire function declaration, including the parameter + // list and return type. However, local types are only in scope in the function body. + if (!(meaning & 793056 /* Type */) || + !(result.flags & (793056 /* Type */ & ~262144 /* TypeParameter */)) || + !ts.isFunctionLike(location) || + lastLocation === location.body) { + break loop; + } + result = undefined; } } switch (location.kind) { @@ -11164,27 +12162,31 @@ var ts; case 138 /* SetAccessor */: case 201 /* FunctionDeclaration */: case 164 /* ArrowFunction */: - if (name === "arguments") { + if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 163 /* FunctionExpression */: - if (name === "arguments") { + if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } - var functionName = location.name; - if (functionName && name === functionName.text) { - result = location.symbol; - break loop; + if (meaning & 16 /* Function */) { + var functionName = location.name; + if (functionName && name === functionName.text) { + result = location.symbol; + break loop; + } } break; case 175 /* ClassExpression */: - var className = location.name; - if (className && name === className.text) { - result = location.symbol; - break loop; + if (meaning & 32 /* Class */) { + var className = location.name; + if (className && name === className.text) { + result = location.symbol; + break loop; + } } break; case 131 /* Decorator */: @@ -11381,15 +12383,15 @@ var ts; var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier); if (targetSymbol) { - var name_4 = specifier.propertyName || specifier.name; - if (name_4.text) { - var symbolFromModule = getExportOfModule(targetSymbol, name_4.text); - var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_4.text); + var name_7 = specifier.propertyName || specifier.name; + if (name_7.text) { + var symbolFromModule = getExportOfModule(targetSymbol, name_7.text); + var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_7.text); var symbol = symbolFromModule && symbolFromVariable ? combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - error(name_4, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_4)); + error(name_7, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_7)); } return symbol; } @@ -11448,7 +12450,7 @@ var ts; var symbol = getSymbolOfNode(node); var target = resolveAlias(symbol); if (target) { - var markAlias = (target === unknownSymbol && compilerOptions.separateCompilation) || + var markAlias = (target === unknownSymbol && compilerOptions.isolatedModules) || (target !== unknownSymbol && (target.flags & 107455 /* Value */) && !isConstEnumOrConstEnumOnlyModule(target)); if (markAlias) { markAliasSymbolAsReferenced(symbol); @@ -12146,17 +13148,54 @@ var ts; writeType(types[i], union ? 64 /* InElementType */ : 0 /* None */); } } + function writeSymbolTypeReference(symbol, typeArguments, pos, end) { + // Unnamed function expressions, arrow functions, and unnamed class expressions have reserved names that + // we don't want to display + if (!isReservedMemberName(symbol.name)) { + buildSymbolDisplay(symbol, writer, enclosingDeclaration, 793056 /* Type */); + } + if (pos < end) { + writePunctuation(writer, 24 /* LessThanToken */); + writeType(typeArguments[pos++], 0 /* None */); + while (pos < end) { + writePunctuation(writer, 23 /* CommaToken */); + writeSpace(writer); + writeType(typeArguments[pos++], 0 /* None */); + } + writePunctuation(writer, 25 /* GreaterThanToken */); + } + } function writeTypeReference(type, flags) { + var typeArguments = type.typeArguments; if (type.target === globalArrayType && !(flags & 1 /* WriteArrayAsGenericType */)) { - writeType(type.typeArguments[0], 64 /* InElementType */); + writeType(typeArguments[0], 64 /* InElementType */); writePunctuation(writer, 18 /* OpenBracketToken */); writePunctuation(writer, 19 /* CloseBracketToken */); } else { - buildSymbolDisplay(type.target.symbol, writer, enclosingDeclaration, 793056 /* Type */); - writePunctuation(writer, 24 /* LessThanToken */); - writeTypeList(type.typeArguments, false); - writePunctuation(writer, 25 /* GreaterThanToken */); + // Write the type reference in the format f.g.C where A and B are type arguments + // for outer type parameters, and f and g are the respective declaring containers of those + // type parameters. + var outerTypeParameters = type.target.outerTypeParameters; + var i = 0; + if (outerTypeParameters) { + var length_1 = outerTypeParameters.length; + while (i < length_1) { + // Find group of type arguments for type parameters with the same declaring container. + var start = i; + var parent_3 = getParentSymbolOfTypeParameter(outerTypeParameters[i]); + do { + i++; + } while (i < length_1 && getParentSymbolOfTypeParameter(outerTypeParameters[i]) === parent_3); + // When type parameters are their own type arguments for the whole group (i.e. we have + // the default outer type arguments), we don't show the group. + if (!ts.rangeEquals(outerTypeParameters, typeArguments, start, i)) { + writeSymbolTypeReference(parent_3, typeArguments, start, i); + writePunctuation(writer, 20 /* DotToken */); + } + } + } + writeSymbolTypeReference(type.symbol, typeArguments, i, typeArguments.length); } } function writeTupleType(type) { @@ -12344,7 +13383,7 @@ var ts; function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) { var targetSymbol = getTargetSymbol(symbol); if (targetSymbol.flags & 32 /* Class */ || targetSymbol.flags & 64 /* Interface */) { - buildDisplayForTypeParametersAndDelimiters(getTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); + buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); } } function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { @@ -12358,11 +13397,12 @@ var ts; } } function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { - if (ts.hasDotDotDotToken(p.valueDeclaration)) { + var parameterNode = p.valueDeclaration; + if (ts.isRestParameter(parameterNode)) { writePunctuation(writer, 21 /* DotDotDotToken */); } appendSymbolNameOnly(p, writer); - if (ts.hasQuestionToken(p.valueDeclaration) || p.valueDeclaration.initializer) { + if (isOptionalParameter(parameterNode)) { writePunctuation(writer, 50 /* QuestionToken */); } writePunctuation(writer, 51 /* ColonToken */); @@ -12517,14 +13557,14 @@ var ts; case 201 /* FunctionDeclaration */: case 205 /* EnumDeclaration */: case 209 /* ImportEqualsDeclaration */: - var parent_2 = getDeclarationContainer(node); + var parent_4 = getDeclarationContainer(node); // If the node is not exported or it is not ambient module element (except import declaration) if (!(ts.getCombinedNodeFlags(node) & 1 /* Export */) && - !(node.kind !== 209 /* ImportEqualsDeclaration */ && parent_2.kind !== 228 /* SourceFile */ && ts.isInAmbientContext(parent_2))) { - return isGlobalSourceFile(parent_2); + !(node.kind !== 209 /* ImportEqualsDeclaration */ && parent_4.kind !== 228 /* SourceFile */ && ts.isInAmbientContext(parent_4))) { + return isGlobalSourceFile(parent_4); } // Exported members/ambient module elements (exception import declaration) are visible if parent is visible - return isDeclarationVisible(parent_2); + return isDeclarationVisible(parent_4); case 133 /* PropertyDeclaration */: case 132 /* PropertySignature */: case 137 /* GetAccessor */: @@ -12675,14 +13715,14 @@ var ts; var type; if (pattern.kind === 151 /* ObjectBindingPattern */) { // Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form) - var name_5 = declaration.propertyName || declaration.name; + var name_8 = declaration.propertyName || declaration.name; // Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature, // or otherwise the type of the string index signature. - type = getTypeOfPropertyOfType(parentType, name_5.text) || - isNumericLiteralName(name_5.text) && getIndexTypeOfType(parentType, 1 /* Number */) || + type = getTypeOfPropertyOfType(parentType, name_8.text) || + isNumericLiteralName(name_8.text) && getIndexTypeOfType(parentType, 1 /* Number */) || getIndexTypeOfType(parentType, 0 /* String */); if (!type) { - error(name_5, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_5)); + error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_8)); return unknownType; } } @@ -12727,7 +13767,7 @@ var ts; // checkRightHandSideOfForOf will return undefined if the for-of expression type was // missing properties/signatures required to get its iteratedType (like // [Symbol.iterator] or next). This may be because we accessed properties from anyType, - // or it may have led to an error inside getIteratedType. + // or it may have led to an error inside getElementTypeOfIterable. return checkRightHandSideOfForOf(declaration.parent.parent.expression) || anyType; } if (ts.isBindingPattern(declaration.parent)) { @@ -13020,29 +14060,65 @@ var ts; return target === checkBase || ts.forEach(getBaseTypes(target), check); } } - // Return combined list of type parameters from all declarations of a class or interface. Elsewhere we check they're all - // the same, but even if they're not we still need the complete list to ensure instantiations supply type arguments - // for all type parameters. - function getTypeParametersOfClassOrInterface(symbol) { - var result; - ts.forEach(symbol.declarations, function (node) { - if (node.kind === 203 /* InterfaceDeclaration */ || node.kind === 202 /* ClassDeclaration */) { - var declaration = node; - if (declaration.typeParameters && declaration.typeParameters.length) { - ts.forEach(declaration.typeParameters, function (node) { - var tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node)); - if (!result) { - result = [tp]; - } - else if (!ts.contains(result, tp)) { - result.push(tp); - } - }); + // Appends the type parameters given by a list of declarations to a set of type parameters and returns the resulting set. + // The function allocates a new array if the input type parameter set is undefined, but otherwise it modifies the set + // in-place and returns the same array. + function appendTypeParameters(typeParameters, declarations) { + for (var _i = 0; _i < declarations.length; _i++) { + var declaration = declarations[_i]; + var tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(declaration)); + if (!typeParameters) { + typeParameters = [tp]; + } + else if (!ts.contains(typeParameters, tp)) { + typeParameters.push(tp); + } + } + return typeParameters; + } + // Appends the outer type parameters of a node to a set of type parameters and returns the resulting set. The function + // allocates a new array if the input type parameter set is undefined, but otherwise it modifies the set in-place and + // returns the same array. + function appendOuterTypeParameters(typeParameters, node) { + while (true) { + node = node.parent; + if (!node) { + return typeParameters; + } + if (node.kind === 202 /* ClassDeclaration */ || node.kind === 201 /* FunctionDeclaration */ || + node.kind === 163 /* FunctionExpression */ || node.kind === 135 /* MethodDeclaration */ || + node.kind === 164 /* ArrowFunction */) { + var declarations = node.typeParameters; + if (declarations) { + return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations); } } - }); + } + } + // The outer type parameters are those defined by enclosing generic classes, methods, or functions. + function getOuterTypeParametersOfClassOrInterface(symbol) { + var kind = symbol.flags & 32 /* Class */ ? 202 /* ClassDeclaration */ : 203 /* InterfaceDeclaration */; + return appendOuterTypeParameters(undefined, ts.getDeclarationOfKind(symbol, kind)); + } + // The local type parameters are the combined set of type parameters from all declarations of the class or interface. + function getLocalTypeParametersOfClassOrInterface(symbol) { + var result; + for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { + var node = _a[_i]; + if (node.kind === 203 /* InterfaceDeclaration */ || node.kind === 202 /* ClassDeclaration */) { + var declaration = node; + if (declaration.typeParameters) { + result = appendTypeParameters(result, declaration.typeParameters); + } + } + } return result; } + // The full set of type parameters for a generic class or interface type consists of its outer type parameters plus + // its locally declared type parameters. + function getTypeParametersOfClassOrInterface(symbol) { + return ts.concatenate(getOuterTypeParametersOfClassOrInterface(symbol), getLocalTypeParametersOfClassOrInterface(symbol)); + } function getBaseTypes(type) { var typeWithBaseTypes = type; if (!typeWithBaseTypes.baseTypes) { @@ -13109,10 +14185,13 @@ var ts; if (!links.declaredType) { var kind = symbol.flags & 32 /* Class */ ? 1024 /* Class */ : 2048 /* Interface */; var type = links.declaredType = createObjectType(kind, symbol); - var typeParameters = getTypeParametersOfClassOrInterface(symbol); - if (typeParameters) { + var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol); + var localTypeParameters = getLocalTypeParametersOfClassOrInterface(symbol); + if (outerTypeParameters || localTypeParameters) { type.flags |= 4096 /* Reference */; - type.typeParameters = typeParameters; + type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters); + type.outerTypeParameters = outerTypeParameters; + type.localTypeParameters = localTypeParameters; type.instantiations = {}; type.instantiations[getTypeListId(type.typeParameters)] = type; type.target = type; @@ -13290,12 +14369,12 @@ var ts; return ts.map(baseSignatures, function (baseSignature) { var signature = baseType.flags & 4096 /* Reference */ ? getSignatureInstantiation(baseSignature, baseType.typeArguments) : cloneSignature(baseSignature); - signature.typeParameters = classType.typeParameters; + signature.typeParameters = classType.localTypeParameters; signature.resolvedReturnType = classType; return signature; }); } - return [createSignature(undefined, classType.typeParameters, emptyArray, classType, 0, false, false)]; + return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, 0, false, false)]; } function createTupleTypeMemberSymbols(memberTypes) { var members = {}; @@ -13619,11 +14698,14 @@ var ts; } return result; } + function isOptionalParameter(node) { + return ts.hasQuestionToken(node) || !!node.initializer; + } function getSignatureFromDeclaration(declaration) { var links = getNodeLinks(declaration); if (!links.resolvedSignature) { var classType = declaration.kind === 136 /* Constructor */ ? getDeclaredTypeOfClassOrInterface(declaration.parent.symbol) : undefined; - var typeParameters = classType ? classType.typeParameters : + var typeParameters = classType ? classType.localTypeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; var parameters = []; var hasStringLiterals = false; @@ -13661,7 +14743,7 @@ var ts; returnType = anyType; } } - links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, minArgumentCount, ts.hasRestParameters(declaration), hasStringLiterals); + links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals); } return links.resolvedSignature; } @@ -13810,6 +14892,9 @@ var ts; } return type.constraint === noConstraintType ? undefined : type.constraint; } + function getParentSymbolOfTypeParameter(typeParameter) { + return getSymbolOfNode(ts.getDeclarationOfKind(typeParameter.symbol, 129 /* TypeParameter */).parent); + } function getTypeListId(types) { switch (types.length) { case 1: @@ -13913,23 +14998,7 @@ var ts; type = unknownType; } else { - type = getDeclaredTypeOfSymbol(symbol); - if (type.flags & (1024 /* Class */ | 2048 /* Interface */) && type.flags & 4096 /* Reference */) { - var typeParameters = type.typeParameters; - if (node.typeArguments && node.typeArguments.length === typeParameters.length) { - type = createTypeReference(type, ts.map(node.typeArguments, getTypeFromTypeNode)); - } - else { - error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, undefined, 1 /* WriteArrayAsGenericType */), typeParameters.length); - type = undefined; - } - } - else { - if (node.typeArguments) { - error(node, ts.Diagnostics.Type_0_is_not_generic, typeToString(type)); - type = undefined; - } - } + type = createTypeReferenceIfGeneric(getDeclaredTypeOfSymbol(symbol), node, node.typeArguments); } } } @@ -13937,6 +15006,34 @@ var ts; } return links.resolvedType; } + function createTypeReferenceIfGeneric(type, node, typeArguments) { + if (type.flags & (1024 /* Class */ | 2048 /* Interface */) && type.flags & 4096 /* Reference */) { + // In a type reference, the outer type parameters of the referenced class or interface are automatically + // supplied as type arguments and the type reference only specifies arguments for the local type parameters + // of the class or interface. + var localTypeParameters = type.localTypeParameters; + var expectedTypeArgCount = localTypeParameters ? localTypeParameters.length : 0; + var typeArgCount = typeArguments ? typeArguments.length : 0; + if (typeArgCount === expectedTypeArgCount) { + // When no type arguments are expected we already have the right type because all outer type parameters + // have themselves as default type arguments. + if (typeArgCount) { + return createTypeReference(type, ts.concatenate(type.outerTypeParameters, ts.map(typeArguments, getTypeFromTypeNode))); + } + } + else { + error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, undefined, 1 /* WriteArrayAsGenericType */), expectedTypeArgCount); + return undefined; + } + } + else { + if (typeArguments) { + error(node, ts.Diagnostics.Type_0_is_not_generic, typeToString(type)); + return undefined; + } + } + return type; + } function getTypeFromTypeQueryNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { @@ -13962,16 +15059,16 @@ var ts; } } if (!symbol) { - return emptyObjectType; + return arity ? emptyGenericType : emptyObjectType; } var type = getDeclaredTypeOfSymbol(symbol); if (!(type.flags & 48128 /* ObjectType */)) { error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name); - return emptyObjectType; + return arity ? emptyGenericType : emptyObjectType; } if ((type.typeParameters ? type.typeParameters.length : 0) !== arity) { error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity); - return emptyObjectType; + return arity ? emptyGenericType : emptyObjectType; } return type; } @@ -13991,15 +15088,20 @@ var ts; function getGlobalESSymbolConstructorSymbol() { return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol")); } + /** + * Instantiates a global type that is generic with some element type, and returns that instantiation. + */ + function createTypeFromGenericGlobalType(genericGlobalType, elementType) { + return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, [elementType]) : emptyObjectType; + } function createIterableType(elementType) { - return globalIterableType !== emptyObjectType ? createTypeReference(globalIterableType, [elementType]) : emptyObjectType; + return createTypeFromGenericGlobalType(globalIterableType, elementType); + } + function createIterableIteratorType(elementType) { + return createTypeFromGenericGlobalType(globalIterableIteratorType, elementType); } function createArrayType(elementType) { - // globalArrayType will be undefined if we get here during creation of the Array type. This for example happens if - // user code augments the Array type with call or construct signatures that have an array type as the return type. - // We instead use globalArraySymbol to obtain the (not yet fully constructed) Array type. - var arrayType = globalArrayType || getDeclaredTypeOfSymbol(globalArraySymbol); - return arrayType !== emptyObjectType ? createTypeReference(arrayType, [elementType]) : emptyObjectType; + return createTypeFromGenericGlobalType(globalArrayType, elementType); } function getTypeFromArrayTypeNode(node) { var links = getNodeLinks(node); @@ -14054,17 +15156,7 @@ var ts; } return false; } - // Since removeSubtypes checks the subtype relation, and the subtype relation on a union - // may attempt to reduce a union, it is possible that removeSubtypes could be called - // recursively on the same set of types. The removeSubtypesStack is used to track which - // sets of types are currently undergoing subtype reduction. - var removeSubtypesStack = []; function removeSubtypes(types) { - var typeListId = getTypeListId(types); - if (removeSubtypesStack.lastIndexOf(typeListId) >= 0) { - return; - } - removeSubtypesStack.push(typeListId); var i = types.length; while (i > 0) { i--; @@ -14072,7 +15164,6 @@ var ts; types.splice(i, 1); } } - removeSubtypesStack.pop(); } function containsAnyType(types) { for (var _i = 0; _i < types.length; _i++) { @@ -14124,10 +15215,20 @@ var ts; } return type; } + // Subtype reduction is basically an optimization we do to avoid excessively large union types, which take longer + // to process and look strange in quick info and error messages. Semantically there is no difference between the + // reduced type and the type itself. So, when we detect a circularity we simply say that the reduced type is the + // type itself. function getReducedTypeOfUnionType(type) { - // If union type was created without subtype reduction, perform the deferred reduction now if (!type.reducedType) { - type.reducedType = getUnionType(type.types, false); + type.reducedType = circularType; + var reducedType = getUnionType(type.types, false); + if (type.reducedType === circularType) { + type.reducedType = reducedType; + } + } + else if (type.reducedType === circularType) { + type.reducedType = type; } return type.reducedType; } @@ -14319,6 +15420,18 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { + // If this type has already been instantiated using this mapper, returned the cached result. This guards against + // infinite instantiations of cyclic types, e.g. "var x: { a: T, b: typeof x };" + if (mapper.mappings) { + var cached = mapper.mappings[type.id]; + if (cached) { + return cached; + } + } + else { + mapper.mappings = {}; + } + // Instantiate the given type using the given mapper and cache the result var result = createObjectType(32768 /* Anonymous */, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); @@ -14330,6 +15443,7 @@ var ts; result.stringIndexType = instantiateType(stringIndexType, mapper); if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper); + mapper.mappings[type.id] = result; return result; } function instantiateType(type, mapper) { @@ -14338,7 +15452,7 @@ var ts; return mapper(type); } if (type.flags & 32768 /* Anonymous */) { - return type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) ? + return type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) ? instantiateAnonymousType(type, mapper) : type; } if (type.flags & 4096 /* Reference */) { @@ -15613,10 +16727,10 @@ var ts; // Resolve location from top down towards node if it is a context sensitive expression // That helps in making sure not assigning types as any when resolved out of order var containerNodes = []; - for (var parent_3 = node.parent; parent_3; parent_3 = parent_3.parent) { - if ((ts.isExpression(parent_3) || ts.isObjectLiteralMethod(node)) && - isContextSensitive(parent_3)) { - containerNodes.unshift(parent_3); + for (var parent_5 = node.parent; parent_5; parent_5 = parent_5.parent) { + if ((ts.isExpression(parent_5) || ts.isObjectLiteralMethod(node)) && + isContextSensitive(parent_5)) { + containerNodes.unshift(parent_5); } } ts.forEach(containerNodes, function (node) { getTypeOfNode(node); }); @@ -16061,7 +17175,7 @@ var ts; if (isContextSensitive(func)) { var contextualSignature = getContextualSignature(func); if (contextualSignature) { - var funcHasRestParameters = ts.hasRestParameters(func); + var funcHasRestParameters = ts.hasRestParameter(func); var len = func.parameters.length - (funcHasRestParameters ? 1 : 0); var indexOfParameter = ts.indexOf(func.parameters, parameter); if (indexOfParameter < len) { @@ -16101,22 +17215,40 @@ var ts; return undefined; } function getContextualTypeForReturnExpression(node) { + var func = ts.getContainingFunction(node); + if (func && !func.asteriskToken) { + return getContextualReturnType(func); + } + return undefined; + } + function getContextualTypeForYieldOperand(node) { var func = ts.getContainingFunction(node); if (func) { - // If the containing function has a return type annotation, is a constructor, or is a get accessor whose - // corresponding set accessor has a type annotation, return statements in the function are contextually typed - if (func.type || func.kind === 136 /* Constructor */ || func.kind === 137 /* GetAccessor */ && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(func.symbol, 138 /* SetAccessor */))) { - return getReturnTypeOfSignature(getSignatureFromDeclaration(func)); - } - // 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 - var signature = getContextualSignatureForFunctionLikeDeclaration(func); - if (signature) { - return getReturnTypeOfSignature(signature); + var contextualReturnType = getContextualReturnType(func); + if (contextualReturnType) { + return node.asteriskToken + ? contextualReturnType + : getElementTypeOfIterableIterator(contextualReturnType); } } return undefined; } + function getContextualReturnType(functionDecl) { + // If the containing function has a return type annotation, is a constructor, or is a get accessor whose + // corresponding set accessor has a type annotation, return statements in the function are contextually typed + if (functionDecl.type || + functionDecl.kind === 136 /* Constructor */ || + functionDecl.kind === 137 /* GetAccessor */ && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(functionDecl.symbol, 138 /* SetAccessor */))) { + return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl)); + } + // 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 + var signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl); + if (signature) { + return getReturnTypeOfSignature(signature); + } + return undefined; + } // In a typed function call, an argument or substitution expression is contextually typed by the type of the corresponding parameter. function getContextualTypeForArgument(callTarget, arg) { var args = getEffectiveCallArguments(callTarget); @@ -16238,7 +17370,7 @@ var ts; var index = ts.indexOf(arrayLiteral.elements, node); return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, 1 /* Number */) - || (languageVersion >= 2 /* ES6 */ ? checkIteratedType(type, undefined) : undefined); + || (languageVersion >= 2 /* ES6 */ ? getElementTypeOfIterable(type, undefined) : undefined); } return undefined; } @@ -16268,6 +17400,8 @@ var ts; case 164 /* ArrowFunction */: case 192 /* ReturnStatement */: return getContextualTypeForReturnExpression(node); + case 173 /* YieldExpression */: + return getContextualTypeForYieldOperand(parent); case 158 /* CallExpression */: case 159 /* NewExpression */: return getContextualTypeForArgument(parent, node); @@ -16304,8 +17438,10 @@ var ts; return node.kind === 163 /* FunctionExpression */ || node.kind === 164 /* ArrowFunction */; } function getContextualSignatureForFunctionLikeDeclaration(node) { - // Only function expressions and arrow functions are contextually typed. - return isFunctionExpressionOrArrowFunction(node) ? getContextualSignature(node) : undefined; + // Only function expressions, arrow functions, and object literal methods are contextually typed. + return isFunctionExpressionOrArrowFunction(node) || ts.isObjectLiteralMethod(node) + ? getContextualSignature(node) + : undefined; } // Return the contextual signature for a given expression node. A contextual type provides a // contextual signature if it has a single call signature and if that call signature is non-generic. @@ -16415,7 +17551,7 @@ var ts; // if there is no index type / iterated type. var restArrayType = checkExpression(e.expression, contextualMapper); var restElementType = getIndexTypeOfType(restArrayType, 1 /* Number */) || - (languageVersion >= 2 /* ES6 */ ? checkIteratedType(restArrayType, undefined) : undefined); + (languageVersion >= 2 /* ES6 */ ? getElementTypeOfIterable(restArrayType, undefined) : undefined); if (restElementType) { elementTypes.push(restElementType); } @@ -16703,15 +17839,15 @@ var ts; // - Otherwise, if IndexExpr is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any. // See if we can index as a property. if (node.argumentExpression) { - var name_6 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); - if (name_6 !== undefined) { - var prop = getPropertyOfType(objectType, name_6); + var name_9 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); + if (name_9 !== undefined) { + var prop = getPropertyOfType(objectType, name_9); if (prop) { getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } else if (isConstEnum) { - error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_6, symbolToString(objectType.symbol)); + error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_9, symbolToString(objectType.symbol)); return unknownType; } } @@ -16832,13 +17968,13 @@ var ts; for (var _i = 0; _i < signatures.length; _i++) { var signature = signatures[_i]; var symbol = signature.declaration && getSymbolOfNode(signature.declaration); - var parent_4 = signature.declaration && signature.declaration.parent; + var parent_6 = signature.declaration && signature.declaration.parent; if (!lastSymbol || symbol === lastSymbol) { - if (lastParent && parent_4 === lastParent) { + if (lastParent && parent_6 === lastParent) { index++; } else { - lastParent = parent_4; + lastParent = parent_6; index = cutoffIndex; } } @@ -16846,7 +17982,7 @@ var ts; // current declaration belongs to a different symbol // set cutoffIndex so re-orderings in the future won't change result set from 0 to cutoffIndex index = cutoffIndex = result.length; - lastParent = parent_4; + lastParent = parent_6; } lastSymbol = symbol; // specialized signatures always need to be placed before non-specialized signatures regardless @@ -17331,10 +18467,10 @@ var ts; return resolveCall(node, callSignatures, candidatesOutArray); } function resolveNewExpression(node, candidatesOutArray) { - if (node.arguments && languageVersion < 2 /* ES6 */) { + if (node.arguments && languageVersion < 1 /* ES5 */) { var spreadIndex = getSpreadArgumentIndex(node.arguments); if (spreadIndex >= 0) { - error(node.arguments[spreadIndex], ts.Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher); + error(node.arguments[spreadIndex], ts.Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher); } } var expressionType = checkExpression(node.expression); @@ -17350,7 +18486,7 @@ var ts; // If ConstructExpr's apparent type(section 3.8.1) is an object type with one or // more construct signatures, the expression is processed in the same manner as a // function call, but using the construct signatures as the initial set of candidate - // signatures for overload resolution.The result type of the function call becomes + // signatures for overload resolution. The result type of the function call becomes // the result type of the operation. expressionType = getApparentType(expressionType); if (expressionType === unknownType) { @@ -17486,17 +18622,39 @@ var ts; type = checkExpressionCached(func.body, contextualMapper); } else { - // Aggregate the types of expressions within all the return statements. - var types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); - if (types.length === 0) { - return voidType; + var types; + var funcIsGenerator = !!func.asteriskToken; + if (funcIsGenerator) { + types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); + if (types.length === 0) { + var iterableIteratorAny = createIterableIteratorType(anyType); + if (compilerOptions.noImplicitAny) { + error(func.asteriskToken, ts.Diagnostics.Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type, typeToString(iterableIteratorAny)); + } + return iterableIteratorAny; + } } - // When return statements are contextually typed we allow the return type to be a union type. Otherwise we require the - // return expressions to have a best common supertype. + else { + types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); + if (types.length === 0) { + return voidType; + } + } + // When yield/return statements are contextually typed we allow the return type to be a union type. + // Otherwise we require the yield/return expressions to have a best common supertype. type = contextualSignature ? getUnionType(types) : getCommonSupertype(types); if (!type) { - error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions); - return unknownType; + if (funcIsGenerator) { + error(func, ts.Diagnostics.No_best_common_type_exists_among_yield_expressions); + return createIterableIteratorType(unknownType); + } + else { + error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions); + return unknownType; + } + } + if (funcIsGenerator) { + type = createIterableIteratorType(type); } } if (!contextualSignature) { @@ -17504,7 +18662,23 @@ var ts; } return getWidenedType(type); } - /// Returns a set of types relating to every return expression relating to a function block. + function checkAndAggregateYieldOperandTypes(body, contextualMapper) { + var aggregatedTypes = []; + ts.forEachYieldExpression(body, function (yieldExpression) { + var expr = yieldExpression.expression; + if (expr) { + var type = checkExpressionCached(expr, contextualMapper); + if (yieldExpression.asteriskToken) { + // A yield* expression effectively yields everything that its operand yields + type = checkElementTypeOfIterable(type, yieldExpression.expression); + } + if (!ts.contains(aggregatedTypes, type)) { + aggregatedTypes.push(type); + } + } + }); + return aggregatedTypes; + } function checkAndAggregateReturnExpressionTypes(body, contextualMapper) { var aggregatedTypes = []; ts.forEachReturnStatement(body, function (returnStatement) { @@ -17673,8 +18847,8 @@ var ts; var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8 /* StringLiteral */) { - var name_7 = index.text; - var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_7); + var name_10 = index.text; + var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_10); return prop && (prop.flags & 3 /* Variable */) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192 /* Const */) !== 0; } return false; @@ -17832,16 +19006,16 @@ var ts; var p = properties[_i]; if (p.kind === 225 /* PropertyAssignment */ || p.kind === 226 /* ShorthandPropertyAssignment */) { // TODO(andersh): Computed property support - var name_8 = p.name; + var name_11 = p.name; var type = sourceType.flags & 1 /* Any */ ? sourceType : - getTypeOfPropertyOfType(sourceType, name_8.text) || - isNumericLiteralName(name_8.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || + getTypeOfPropertyOfType(sourceType, name_11.text) || + isNumericLiteralName(name_11.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || getIndexTypeOfType(sourceType, 0 /* String */); if (type) { - checkDestructuringAssignment(p.initializer || name_8, type); + checkDestructuringAssignment(p.initializer || name_11, type); } else { - error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_8)); + error(name_11, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_11)); } } else { @@ -18091,14 +19265,53 @@ var ts; error(node, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(node.operatorToken.kind), typeToString(leftType), typeToString(rightType)); } } + function isYieldExpressionInClass(node) { + var current = node; + var parent = node.parent; + while (parent) { + if (ts.isFunctionLike(parent) && current === parent.body) { + return false; + } + else if (current.kind === 202 /* ClassDeclaration */ || current.kind === 175 /* ClassExpression */) { + return true; + } + current = parent; + parent = parent.parent; + } + return false; + } function checkYieldExpression(node) { // Grammar checking - if (!(node.parserContextFlags & 4 /* Yield */)) { - grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration); + if (!(node.parserContextFlags & 4 /* Yield */) || isYieldExpressionInClass(node)) { + grammarErrorOnFirstToken(node, ts.Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body); } - else { - grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expressions_are_not_currently_supported); + if (node.expression) { + var func = ts.getContainingFunction(node); + // If the user's code is syntactically correct, the func should always have a star. After all, + // we are in a yield context. + if (func && func.asteriskToken) { + var expressionType = checkExpressionCached(node.expression, undefined); + var expressionElementType; + var nodeIsYieldStar = !!node.asteriskToken; + if (nodeIsYieldStar) { + expressionElementType = checkElementTypeOfIterable(expressionType, node.expression); + } + // There is no point in doing an assignability check if the function + // has no explicit return type because the return type is directly computed + // from the yield expressions. + if (func.type) { + var signatureElementType = getElementTypeOfIterableIterator(getTypeFromTypeNode(func.type)) || anyType; + if (nodeIsYieldStar) { + checkTypeAssignableTo(expressionElementType, signatureElementType, node.expression, undefined); + } + else { + checkTypeAssignableTo(expressionType, signatureElementType, node.expression, undefined); + } + } + } } + // Both yield and yield* expressions have type 'any' + return anyType; } function checkConditionalExpression(node, contextualMapper) { checkExpression(node.condition); @@ -18269,8 +19482,7 @@ var ts; case 176 /* OmittedExpression */: return undefinedType; case 173 /* YieldExpression */: - checkYieldExpression(node); - return unknownType; + return checkYieldExpression(node); } return unknownType; } @@ -18314,6 +19526,14 @@ var ts; error(node, ts.Diagnostics.A_rest_parameter_must_be_of_an_array_type); } } + function isSyntacticallyValidGenerator(node) { + if (!node.asteriskToken || !node.body) { + return false; + } + return node.kind === 135 /* MethodDeclaration */ || + node.kind === 201 /* FunctionDeclaration */ || + node.kind === 163 /* FunctionExpression */; + } function checkSignatureDeclaration(node) { // Grammar checking if (node.kind === 141 /* IndexSignature */) { @@ -18341,6 +19561,25 @@ var ts; break; } } + if (node.type) { + if (languageVersion >= 2 /* ES6 */ && isSyntacticallyValidGenerator(node)) { + var returnType = getTypeFromTypeNode(node.type); + if (returnType === voidType) { + error(node.type, ts.Diagnostics.A_generator_cannot_have_a_void_type_annotation); + } + else { + var generatorElementType = getElementTypeOfIterableIterator(returnType) || anyType; + var iterableIteratorInstantiation = createIterableIteratorType(generatorElementType); + // Naively, one could check that IterableIterator is assignable to the return type annotation. + // However, that would not catch the error in the following case. + // + // interface BadGenerator extends Iterable, Iterator { } + // function* g(): BadGenerator { } // Iterable and Iterator have different types! + // + checkTypeAssignableTo(iterableIteratorInstantiation, returnType, node.type); + } + } + } } checkSpecializedSignatureDeclaration(node); } @@ -18898,7 +20137,7 @@ var ts; // serialize the type metadata. if (node && node.kind === 142 /* TypeReference */) { var type = getTypeFromTypeNode(node); - var shouldCheckIfUnknownType = type === unknownType && compilerOptions.separateCompilation; + var shouldCheckIfUnknownType = type === unknownType && compilerOptions.isolatedModules; if (!type || (!shouldCheckIfUnknownType && type.flags & (1048703 /* Intrinsic */ | 132 /* NumberLike */ | 258 /* StringLike */))) { return; } @@ -18948,6 +20187,9 @@ var ts; if (!ts.nodeCanBeDecorated(node)) { return; } + if (!compilerOptions.experimentalDecorators) { + error(node, ts.Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning); + } if (compilerOptions.emitDecoratorMetadata) { // we only need to perform these checks if we are emitting serialized type metadata for the target of a decorator. switch (node.kind) { @@ -18977,7 +20219,6 @@ var ts; function checkFunctionDeclaration(node) { if (produceDiagnostics) { checkFunctionLikeDeclaration(node) || - checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); checkCollisionWithCapturedSuperVariable(node, node.name); @@ -19020,10 +20261,18 @@ var ts; if (node.type && !isAccessor(node.kind) && !node.asteriskToken) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - // Report an implicit any error if there is no body, no explicit return type, and node is not a private method - // in an ambient context - if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !node.type && !isPrivateWithinAmbient(node)) { - reportImplicitAnyError(node, anyType); + if (produceDiagnostics && !node.type) { + // Report an implicit any error if there is no body, no explicit return type, and node is not a private method + // in an ambient context + if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !isPrivateWithinAmbient(node)) { + reportImplicitAnyError(node, anyType); + } + if (node.asteriskToken && ts.nodeIsPresent(node.body)) { + // A generator with a body and no type annotation can still cause errors. It can error if the + // yielded values have no common supertype, or it can give an implicit any error if it has no + // yielded values. The only way to trigger these errors is to try checking its return type. + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } } } function checkBlock(node) { @@ -19038,7 +20287,7 @@ var ts; } function checkCollisionWithArgumentsInGeneratedCode(node) { // no rest parameters \ declaration context \ overload - no codegen impact - if (!ts.hasRestParameters(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) { + if (!ts.hasRestParameter(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) { return; } ts.forEach(node.parameters, function (p) { @@ -19184,8 +20433,8 @@ var ts; // otherwise if variable has an initializer - show error that initialization will fail // since LHS will be block scoped name instead of function scoped if (!namesShareScope) { - var name_9 = symbolToString(localDeclarationSymbol); - error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_9, name_9); + var name_12 = symbolToString(localDeclarationSymbol); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_12, name_12); } } } @@ -19295,7 +20544,7 @@ var ts; } function checkVariableStatement(node) { // Grammar checking - checkGrammarDecorators(node) || checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); ts.forEach(node.declarationList.declarations, checkSourceElement); } function checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) { @@ -19385,7 +20634,7 @@ var ts; // iteratedType will be undefined if the rightType was missing properties/signatures // required to get its iteratedType (like [Symbol.iterator] or next). This may be // because we accessed properties from anyType, or it may have led to an error inside - // getIteratedType. + // getElementTypeOfIterable. if (iteratedType) { checkTypeAssignableTo(iteratedType, leftType, varExpr, undefined); } @@ -19451,7 +20700,7 @@ var ts; return inputType; } if (languageVersion >= 2 /* ES6 */) { - return checkIteratedType(inputType, errorNode) || anyType; + return checkElementTypeOfIterable(inputType, errorNode); } if (allowStringInput) { return checkElementTypeOfArrayOrString(inputType, errorNode); @@ -19468,88 +20717,127 @@ var ts; /** * When errorNode is undefined, it means we should not report any errors. */ - function checkIteratedType(iterable, errorNode) { - ts.Debug.assert(languageVersion >= 2 /* ES6 */); - var iteratedType = getIteratedType(iterable, errorNode); + function checkElementTypeOfIterable(iterable, errorNode) { + var elementType = getElementTypeOfIterable(iterable, errorNode); // Now even though we have extracted the iteratedType, we will have to validate that the type // passed in is actually an Iterable. - if (errorNode && iteratedType) { - checkTypeAssignableTo(iterable, createIterableType(iteratedType), errorNode); + if (errorNode && elementType) { + checkTypeAssignableTo(iterable, createIterableType(elementType), errorNode); } - return iteratedType; - function getIteratedType(iterable, errorNode) { - // We want to treat type as an iterable, and get the type it is an iterable of. The iterable - // must have the following structure (annotated with the names of the variables below): - // - // { // iterable - // [Symbol.iterator]: { // iteratorFunction - // (): { // iterator - // next: { // iteratorNextFunction - // (): { // iteratorNextResult - // value: T // iteratorNextValue - // } - // } - // } - // } - // } - // - // T is the type we are after. At every level that involves analyzing return types - // of signatures, we union the return types of all the signatures. - // - // Another thing to note is that at any step of this process, we could run into a dead end, - // meaning either the property is missing, or we run into the anyType. If either of these things - // happens, we return undefined to signal that we could not find the iterated type. If a property - // is missing, and the previous step did not result in 'any', then we also give an error if the - // caller requested it. Then the caller can decide what to do in the case where there is no iterated - // type. This is different from returning anyType, because that would signify that we have matched the - // whole pattern and that T (above) is 'any'. - if (allConstituentTypesHaveKind(iterable, 1 /* Any */)) { - return undefined; - } + return elementType || anyType; + } + /** + * We want to treat type as an iterable, and get the type it is an iterable of. The iterable + * must have the following structure (annotated with the names of the variables below): + * + * { // iterable + * [Symbol.iterator]: { // iteratorFunction + * (): Iterator + * } + * } + * + * T is the type we are after. At every level that involves analyzing return types + * of signatures, we union the return types of all the signatures. + * + * Another thing to note is that at any step of this process, we could run into a dead end, + * meaning either the property is missing, or we run into the anyType. If either of these things + * happens, we return undefined to signal that we could not find the iterated type. If a property + * is missing, and the previous step did not result in 'any', then we also give an error if the + * caller requested it. Then the caller can decide what to do in the case where there is no iterated + * type. This is different from returning anyType, because that would signify that we have matched the + * whole pattern and that T (above) is 'any'. + */ + function getElementTypeOfIterable(type, errorNode) { + if (type.flags & 1 /* Any */) { + return undefined; + } + var typeAsIterable = type; + if (!typeAsIterable.iterableElementType) { // As an optimization, if the type is instantiated directly using the globalIterableType (Iterable), // then just grab its type argument. - if ((iterable.flags & 4096 /* Reference */) && iterable.target === globalIterableType) { - return iterable.typeArguments[0]; + if ((type.flags & 4096 /* Reference */) && type.target === globalIterableType) { + typeAsIterable.iterableElementType = type.typeArguments[0]; } - var iteratorFunction = getTypeOfPropertyOfType(iterable, ts.getPropertyNameForKnownSymbolName("iterator")); - if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, 1 /* Any */)) { - return undefined; - } - var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0 /* Call */) : emptyArray; - if (iteratorFunctionSignatures.length === 0) { - if (errorNode) { - error(errorNode, ts.Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator); + else { + var iteratorFunction = getTypeOfPropertyOfType(type, ts.getPropertyNameForKnownSymbolName("iterator")); + if (iteratorFunction && iteratorFunction.flags & 1 /* Any */) { + return undefined; } - return undefined; - } - var iterator = getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature)); - if (allConstituentTypesHaveKind(iterator, 1 /* Any */)) { - return undefined; - } - var iteratorNextFunction = getTypeOfPropertyOfType(iterator, "next"); - if (iteratorNextFunction && allConstituentTypesHaveKind(iteratorNextFunction, 1 /* Any */)) { - return undefined; - } - var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0 /* Call */) : emptyArray; - if (iteratorNextFunctionSignatures.length === 0) { - if (errorNode) { - error(errorNode, ts.Diagnostics.An_iterator_must_have_a_next_method); + var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0 /* Call */) : emptyArray; + if (iteratorFunctionSignatures.length === 0) { + if (errorNode) { + error(errorNode, ts.Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator); + } + return undefined; } - return undefined; + typeAsIterable.iterableElementType = getElementTypeOfIterator(getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature)), errorNode); } - var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); - if (allConstituentTypesHaveKind(iteratorNextResult, 1 /* Any */)) { - return undefined; - } - var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); - if (!iteratorNextValue) { - if (errorNode) { - error(errorNode, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property); - } - return undefined; - } - return iteratorNextValue; } + return typeAsIterable.iterableElementType; + } + /** + * This function has very similar logic as getElementTypeOfIterable, except that it operates on + * Iterators instead of Iterables. Here is the structure: + * + * { // iterator + * next: { // iteratorNextFunction + * (): { // iteratorNextResult + * value: T // iteratorNextValue + * } + * } + * } + * + */ + function getElementTypeOfIterator(type, errorNode) { + if (type.flags & 1 /* Any */) { + return undefined; + } + var typeAsIterator = type; + if (!typeAsIterator.iteratorElementType) { + // As an optimization, if the type is instantiated directly using the globalIteratorType (Iterator), + // then just grab its type argument. + if ((type.flags & 4096 /* Reference */) && type.target === globalIteratorType) { + typeAsIterator.iteratorElementType = type.typeArguments[0]; + } + else { + var iteratorNextFunction = getTypeOfPropertyOfType(type, "next"); + if (iteratorNextFunction && iteratorNextFunction.flags & 1 /* Any */) { + return undefined; + } + var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0 /* Call */) : emptyArray; + if (iteratorNextFunctionSignatures.length === 0) { + if (errorNode) { + error(errorNode, ts.Diagnostics.An_iterator_must_have_a_next_method); + } + return undefined; + } + var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); + if (iteratorNextResult.flags & 1 /* Any */) { + return undefined; + } + var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); + if (!iteratorNextValue) { + if (errorNode) { + error(errorNode, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property); + } + return undefined; + } + typeAsIterator.iteratorElementType = iteratorNextValue; + } + } + return typeAsIterator.iteratorElementType; + } + function getElementTypeOfIterableIterator(type) { + if (type.flags & 1 /* Any */) { + return undefined; + } + // As an optimization, if the type is instantiated directly using the globalIterableIteratorType (IterableIterator), + // then just grab its type argument. + if ((type.flags & 4096 /* Reference */) && type.target === globalIterableIteratorType) { + return type.typeArguments[0]; + } + return getElementTypeOfIterable(type, undefined) || + getElementTypeOfIterator(type, undefined); } /** * This function does the following steps: @@ -19630,19 +20918,24 @@ var ts; if (func) { var returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(func)); var exprType = checkExpressionCached(node.expression); + if (func.asteriskToken) { + // A generator does not need its return expressions checked against its return type. + // Instead, the yield expressions are checked against the element type. + // TODO: Check return expressions of generators when return type tracking is added + // for generators. + return; + } if (func.kind === 138 /* SetAccessor */) { error(node.expression, ts.Diagnostics.Setters_cannot_return_a_value); } - else { - if (func.kind === 136 /* Constructor */) { - if (!isTypeAssignableTo(exprType, returnType)) { - error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); - } - } - else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func)) { - checkTypeAssignableTo(exprType, returnType, node.expression, undefined); + else if (func.kind === 136 /* Constructor */) { + if (!isTypeAssignableTo(exprType, returnType)) { + error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); } } + else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func)) { + checkTypeAssignableTo(exprType, returnType, node.expression, undefined); + } } } } @@ -19863,9 +21156,6 @@ var ts; function checkClassDeclaration(node) { checkGrammarDeclarationNameInStrictMode(node); // Grammar checking - if (node.parent.kind !== 207 /* ModuleBlock */ && node.parent.kind !== 228 /* SourceFile */) { - grammarErrorOnNode(node, ts.Diagnostics.class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration); - } if (!node.name && !(node.flags & 256 /* Default */)) { grammarErrorOnFirstToken(node, ts.Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } @@ -19902,7 +21192,7 @@ var ts; checkKindsOfPropertyMemberOverrides(type, baseType); } } - if (baseTypes.length || (baseTypeNode && compilerOptions.separateCompilation)) { + if (baseTypes.length || (baseTypeNode && compilerOptions.isolatedModules)) { // Check that base type can be evaluated as expression checkExpressionOrQualifiedName(baseTypeNode.expression); } @@ -20271,8 +21561,8 @@ var ts; checkExportsOnMergedDeclarations(node); computeEnumMemberValues(node); var enumIsConst = ts.isConst(node); - if (compilerOptions.separateCompilation && enumIsConst && ts.isInAmbientContext(node)) { - error(node.name, ts.Diagnostics.Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided); + if (compilerOptions.isolatedModules && enumIsConst && ts.isInAmbientContext(node)) { + error(node.name, ts.Diagnostics.Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided); } // Spec 2014 - Section 9.3: // It isn't possible for one enum declaration to continue the automatic numbering sequence of another, @@ -20354,7 +21644,7 @@ var ts; if (symbol.flags & 512 /* ValueModule */ && symbol.declarations.length > 1 && !ts.isInAmbientContext(node) - && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.separateCompilation)) { + && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules)) { var firstNonAmbientClassOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); if (firstNonAmbientClassOrFunc) { if (ts.getSourceFileOfNode(node) !== ts.getSourceFileOfNode(firstNonAmbientClassOrFunc)) { @@ -20705,6 +21995,7 @@ var ts; break; case 135 /* MethodDeclaration */: case 134 /* MethodSignature */: + ts.forEach(node.decorators, checkFunctionExpressionBodies); ts.forEach(node.parameters, checkFunctionExpressionBodies); if (ts.isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); @@ -20719,6 +22010,7 @@ var ts; case 193 /* WithStatement */: checkFunctionExpressionBodies(node.expression); break; + case 131 /* Decorator */: case 130 /* Parameter */: case 133 /* PropertyDeclaration */: case 132 /* PropertySignature */: @@ -20969,87 +22261,6 @@ var ts; } return node.parent && node.parent.kind === 177 /* ExpressionWithTypeArguments */; } - function isTypeNode(node) { - if (142 /* FirstTypeNode */ <= node.kind && node.kind <= 150 /* LastTypeNode */) { - return true; - } - switch (node.kind) { - case 112 /* AnyKeyword */: - case 120 /* NumberKeyword */: - case 122 /* StringKeyword */: - case 113 /* BooleanKeyword */: - case 123 /* SymbolKeyword */: - return true; - case 99 /* VoidKeyword */: - return node.parent.kind !== 167 /* VoidExpression */; - case 8 /* StringLiteral */: - // Specialized signatures can have string literals as their parameters' type names - return node.parent.kind === 130 /* Parameter */; - case 177 /* ExpressionWithTypeArguments */: - return true; - // Identifiers and qualified names may be type nodes, depending on their context. Climb - // above them to find the lowest container - case 65 /* Identifier */: - // If the identifier is the RHS of a qualified name, then it's a type iff its parent is. - if (node.parent.kind === 127 /* QualifiedName */ && node.parent.right === node) { - node = node.parent; - } - else if (node.parent.kind === 156 /* PropertyAccessExpression */ && node.parent.name === node) { - node = node.parent; - } - // fall through - case 127 /* QualifiedName */: - case 156 /* PropertyAccessExpression */: - // At this point, node is either a qualified name or an identifier - ts.Debug.assert(node.kind === 65 /* Identifier */ || node.kind === 127 /* QualifiedName */ || node.kind === 156 /* PropertyAccessExpression */, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); - var parent_5 = node.parent; - if (parent_5.kind === 145 /* TypeQuery */) { - return false; - } - // Do not recursively call isTypeNode on the parent. In the example: - // - // let a: A.B.C; - // - // Calling isTypeNode would consider the qualified name A.B a type node. Only C or - // A.B.C is a type node. - if (142 /* FirstTypeNode */ <= parent_5.kind && parent_5.kind <= 150 /* LastTypeNode */) { - return true; - } - switch (parent_5.kind) { - case 177 /* ExpressionWithTypeArguments */: - return true; - case 129 /* TypeParameter */: - return node === parent_5.constraint; - case 133 /* PropertyDeclaration */: - case 132 /* PropertySignature */: - case 130 /* Parameter */: - case 199 /* VariableDeclaration */: - return node === parent_5.type; - case 201 /* FunctionDeclaration */: - case 163 /* FunctionExpression */: - case 164 /* ArrowFunction */: - case 136 /* Constructor */: - case 135 /* MethodDeclaration */: - case 134 /* MethodSignature */: - case 137 /* GetAccessor */: - case 138 /* SetAccessor */: - return node === parent_5.type; - case 139 /* CallSignature */: - case 140 /* ConstructSignature */: - case 141 /* IndexSignature */: - return node === parent_5.type; - case 161 /* TypeAssertionExpression */: - return node === parent_5.type; - case 158 /* CallExpression */: - case 159 /* NewExpression */: - return parent_5.typeArguments && ts.indexOf(parent_5.typeArguments, node) >= 0; - case 160 /* TaggedTemplateExpression */: - // TODO (drosen): TaggedTemplateExpressions may eventually support type arguments. - return false; - } - } - return false; - } function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide) { while (nodeOnRightSide.parent.kind === 127 /* QualifiedName */) { nodeOnRightSide = nodeOnRightSide.parent; @@ -21192,7 +22403,7 @@ var ts; // We cannot answer semantic questions within a with block, do not proceed any further return unknownType; } - if (isTypeNode(node)) { + if (ts.isTypeNode(node)) { return getTypeFromTypeNode(node); } if (ts.isExpression(node)) { @@ -21246,9 +22457,9 @@ var ts; function getRootSymbols(symbol) { if (symbol.flags & 268435456 /* UnionProperty */) { var symbols = []; - var name_10 = symbol.name; + var name_13 = symbol.name; ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { - symbols.push(getPropertyOfType(t, name_10)); + symbols.push(getPropertyOfType(t, name_13)); }); return symbols; } @@ -21356,7 +22567,7 @@ var ts; } function isAliasResolvedToValue(symbol) { var target = resolveAlias(symbol); - if (target === unknownSymbol && compilerOptions.separateCompilation) { + if (target === unknownSymbol && compilerOptions.isolatedModules) { return true; } // const enums and modules that contain only const enums are not considered values from the emit perespective @@ -21703,8 +22914,7 @@ var ts; getSymbolLinks(unknownSymbol).type = unknownType; globals[undefinedSymbol.name] = undefinedSymbol; // Initialize special types - globalArraySymbol = getGlobalTypeSymbol("Array"); - globalArrayType = getTypeOfGlobalSymbol(globalArraySymbol, 1); + globalArrayType = getGlobalType("Array", 1); globalObjectType = getGlobalType("Object"); globalFunctionType = getGlobalType("Function"); globalStringType = getGlobalType("String"); @@ -21722,6 +22932,8 @@ var ts; globalESSymbolType = getGlobalType("Symbol"); globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"); globalIterableType = getGlobalType("Iterable", 1); + globalIteratorType = getGlobalType("Iterator", 1); + globalIterableIteratorType = getGlobalType("IterableIterator", 1); } else { globalTemplateStringsArrayType = unknownType; @@ -21730,6 +22942,9 @@ var ts; // a global Symbol already, particularly if it is a class. globalESSymbolType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); globalESSymbolConstructorSymbol = undefined; + globalIterableType = emptyGenericType; + globalIteratorType = emptyGenericType; + globalIterableIteratorType = emptyGenericType; } anyArrayType = createArrayType(anyType); } @@ -21754,20 +22969,20 @@ var ts; if (impotClause.namedBindings) { var nameBindings = impotClause.namedBindings; if (nameBindings.kind === 212 /* NamespaceImport */) { - var name_11 = nameBindings.name; - if (isReservedWordInStrictMode(name_11)) { - var nameText = ts.declarationNameToString(name_11); - return grammarErrorOnNode(name_11, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_14 = nameBindings.name; + if (isReservedWordInStrictMode(name_14)) { + var nameText = ts.declarationNameToString(name_14); + return grammarErrorOnNode(name_14, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } else if (nameBindings.kind === 213 /* NamedImports */) { var reportError = false; for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { var element = _a[_i]; - var name_12 = element.name; - if (isReservedWordInStrictMode(name_12)) { - var nameText = ts.declarationNameToString(name_12); - reportError = reportError || grammarErrorOnNode(name_12, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_15 = element.name; + if (isReservedWordInStrictMode(name_15)) { + var nameText = ts.declarationNameToString(name_15); + reportError = reportError || grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } return reportError; @@ -21893,19 +23108,28 @@ var ts; case 135 /* MethodDeclaration */: case 134 /* MethodSignature */: case 141 /* IndexSignature */: - case 202 /* ClassDeclaration */: - case 203 /* InterfaceDeclaration */: case 206 /* ModuleDeclaration */: - case 205 /* EnumDeclaration */: - case 181 /* VariableStatement */: - case 201 /* FunctionDeclaration */: - case 204 /* TypeAliasDeclaration */: case 210 /* ImportDeclaration */: case 209 /* ImportEqualsDeclaration */: case 216 /* ExportDeclaration */: case 215 /* ExportAssignment */: case 130 /* Parameter */: break; + case 202 /* ClassDeclaration */: + case 203 /* InterfaceDeclaration */: + case 181 /* VariableStatement */: + case 201 /* FunctionDeclaration */: + case 204 /* TypeAliasDeclaration */: + if (node.modifiers && node.parent.kind !== 207 /* ModuleBlock */ && node.parent.kind !== 228 /* SourceFile */) { + return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + } + break; + case 205 /* EnumDeclaration */: + if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 70 /* ConstKeyword */) && + node.parent.kind !== 207 /* ModuleBlock */ && node.parent.kind !== 228 /* SourceFile */) { + return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + } + break; default: return false; } @@ -22003,9 +23227,6 @@ var ts; else if ((node.kind === 210 /* ImportDeclaration */ || node.kind === 209 /* ImportEqualsDeclaration */) && flags & 2 /* Ambient */) { return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); } - else if (node.kind === 203 /* InterfaceDeclaration */ && flags & 2 /* Ambient */) { - return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); - } else if (node.kind === 130 /* Parameter */ && (flags & 112 /* AccessibilityModifier */) && ts.isBindingPattern(node.name)) { return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); } @@ -22222,7 +23443,18 @@ var ts; } function checkGrammarForGenerator(node) { if (node.asteriskToken) { - return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_currently_supported); + ts.Debug.assert(node.kind === 201 /* FunctionDeclaration */ || + node.kind === 163 /* FunctionExpression */ || + node.kind === 135 /* MethodDeclaration */); + if (ts.isInAmbientContext(node)) { + return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_allowed_in_an_ambient_context); + } + if (!node.body) { + return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.An_overload_signature_cannot_be_declared_as_a_generator); + } + if (languageVersion < 2 /* ES6 */) { + return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_only_available_when_targeting_ECMAScript_6_or_higher); + } } } function checkGrammarFunctionName(name) { @@ -22243,11 +23475,11 @@ var ts; var inStrictMode = (node.parserContextFlags & 1 /* StrictMode */) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_13 = prop.name; + var name_16 = prop.name; if (prop.kind === 176 /* OmittedExpression */ || - name_13.kind === 128 /* ComputedPropertyName */) { + name_16.kind === 128 /* ComputedPropertyName */) { // If the name is not a ComputedPropertyName, the grammar checking will skip it - checkGrammarComputedPropertyName(name_13); + checkGrammarComputedPropertyName(name_16); continue; } // ECMA-262 11.1.5 Object Initialiser @@ -22262,8 +23494,8 @@ var ts; if (prop.kind === 225 /* PropertyAssignment */ || prop.kind === 226 /* ShorthandPropertyAssignment */) { // Grammar checking for computedPropertName and shorthandPropertyAssignment checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_13.kind === 7 /* NumericLiteral */) { - checkGrammarNumericLiteral(name_13); + if (name_16.kind === 7 /* NumericLiteral */) { + checkGrammarNumericLiteral(name_16); } currentKind = Property; } @@ -22279,26 +23511,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_13.text)) { - seen[name_13.text] = currentKind; + if (!ts.hasProperty(seen, name_16.text)) { + seen[name_16.text] = currentKind; } else { - var existingKind = seen[name_13.text]; + var existingKind = seen[name_16.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_13.text] = currentKind | existingKind; + seen[name_16.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -23159,9 +24391,9 @@ var ts; } var count = 0; while (true) { - var name_14 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_14)) { - return name_14; + var name_17 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_17)) { + return name_17; } } } @@ -24370,9 +25602,9 @@ var ts; tempFlags++; // Skip over 'i' and 'n' if (count !== 8 && count !== 13) { - var name_15 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); - if (isUniqueName(name_15)) { - return name_15; + var name_18 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); + if (isUniqueName(name_18)) { + return name_18; } } } @@ -24405,9 +25637,9 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65 /* Identifier */) { - var name_16 = node.name.text; + var name_19 = node.name.text; // Use module/enum name itself if it is unique, otherwise make a unique variation - assignGeneratedName(node, isUniqueLocalName(name_16, node) ? name_16 : makeUniqueName(name_16)); + assignGeneratedName(node, isUniqueLocalName(name_19, node) ? name_19 : makeUniqueName(name_19)); } } function generateNameForImportOrExportDeclaration(node) { @@ -24626,8 +25858,8 @@ var ts; // Child scopes are always shown with a dot (even if they have no name), // unless it is a computed property. Then it is shown with brackets, // but the brackets are included in the name. - var name_17 = node.name; - if (!name_17 || name_17.kind !== 128 /* ComputedPropertyName */) { + var name_20 = node.name; + if (!name_20 || name_20.kind !== 128 /* ComputedPropertyName */) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -24656,10 +25888,10 @@ var ts; node.kind === 205 /* EnumDeclaration */) { // Declaration and has associated name use it if (node.name) { - var name_18 = node.name; + var name_21 = node.name; // For computed property names, the text will include the brackets - scopeName = name_18.kind === 128 /* ComputedPropertyName */ - ? ts.getTextOfNode(name_18) + scopeName = name_21.kind === 128 /* ComputedPropertyName */ + ? ts.getTextOfNode(name_21) : node.name.text; } recordScopeNameStart(scopeName); @@ -25360,16 +26592,16 @@ var ts; } return true; } - function emitListWithSpread(elements, alwaysCopy, multiLine, trailingComma) { + function emitListWithSpread(elements, needsUniqueCopy, multiLine, trailingComma, useConcat) { var pos = 0; var group = 0; var length = elements.length; while (pos < length) { // Emit using the pattern .concat(, , ...) - if (group === 1) { + if (group === 1 && useConcat) { write(".concat("); } - else if (group > 1) { + else if (group > 0) { write(", "); } var e = elements[pos]; @@ -25377,7 +26609,7 @@ var ts; e = e.expression; emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); pos++; - if (pos === length && group === 0 && alwaysCopy && e.kind !== 154 /* ArrayLiteralExpression */) { + if (pos === length && group === 0 && needsUniqueCopy && e.kind !== 154 /* ArrayLiteralExpression */) { write(".slice()"); } } @@ -25400,7 +26632,9 @@ var ts; group++; } if (group > 1) { - write(")"); + if (useConcat) { + write(")"); + } } } function isSpreadElementExpression(node) { @@ -25418,7 +26652,7 @@ var ts; } else { emitListWithSpread(elements, true, (node.flags & 512 /* MultiLine */) !== 0, - /*trailingComma*/ elements.hasTrailingComma); + /*trailingComma*/ elements.hasTrailingComma, true); } } function emitObjectLiteralBody(node, numElements) { @@ -25669,7 +26903,7 @@ var ts; } } function tryEmitConstantValue(node) { - if (compilerOptions.separateCompilation) { + if (compilerOptions.isolatedModules) { // do not inline enum values in separate compilation mode return false; } @@ -25789,7 +27023,7 @@ var ts; write("void 0"); } write(", "); - emitListWithSpread(node.arguments, false, false, false); + emitListWithSpread(node.arguments, false, false, false, true); write(")"); } function emitCallExpression(node) { @@ -25823,11 +27057,42 @@ var ts; } function emitNewExpression(node) { write("new "); - emit(node.expression); - if (node.arguments) { + // Spread operator logic can be supported in new expressions in ES5 using a combination + // of Function.prototype.bind() and Function.prototype.apply(). + // + // Example: + // + // var arguments = [1, 2, 3, 4, 5]; + // new Array(...arguments); + // + // Could be transpiled into ES5: + // + // var arguments = [1, 2, 3, 4, 5]; + // new (Array.bind.apply(Array, [void 0].concat(arguments))); + // + // `[void 0]` is the first argument which represents `thisArg` to the bind method above. + // And `thisArg` will be set to the return value of the constructor when instantiated + // with the new operator — regardless of any value we set `thisArg` to. Thus, we set it + // to an undefined, `void 0`. + if (languageVersion === 1 /* ES5 */ && + node.arguments && + hasSpreadElement(node.arguments)) { write("("); - emitCommaList(node.arguments); - write(")"); + var target = emitCallTarget(node.expression); + write(".bind.apply("); + emit(target); + write(", [void 0].concat("); + emitListWithSpread(node.arguments, false, false, false, false); + write(")))"); + write("()"); + } + else { + emit(node.expression); + if (node.arguments) { + write("("); + emitCommaList(node.arguments); + write(")"); + } } } function emitTaggedTemplateExpression(node) { @@ -26127,9 +27392,10 @@ var ts; write(")"); emitEmbeddedStatement(node.statement); } - /* Returns true if start of variable declaration list was emitted. - * Return false if nothing was written - this can happen for source file level variable declarations - * in system modules - such variable declarations are hoisted. + /** + * Returns true if start of variable declaration list was emitted. + * Returns false if nothing was written - this can happen for source file level variable declarations + * in system modules where such variable declarations are hoisted. */ function tryEmitStartOfVariableDeclarationList(decl, startPos) { if (shouldHoistVariable(decl, true)) { @@ -26892,15 +28158,35 @@ var ts; ts.forEach(node.declarationList.declarations, emitExportVariableAssignments); } } + function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node) { + // If we're not exporting the variables, there's nothing special here. + // Always emit comments for these nodes. + if (!(node.flags & 1 /* Export */)) { + return true; + } + // If we are exporting, but it's a top-level ES6 module exports, + // we'll emit the declaration list verbatim, so emit comments too. + if (isES6ExportedDeclaration(node)) { + return true; + } + // Otherwise, only emit if we have at least one initializer present. + for (var _a = 0, _b = node.declarationList.declarations; _a < _b.length; _a++) { + var declaration = _b[_a]; + if (declaration.initializer) { + return true; + } + } + return false; + } function emitParameter(node) { if (languageVersion < 2 /* ES6 */) { if (ts.isBindingPattern(node.name)) { - var name_19 = createTempVariable(0 /* Auto */); + var name_22 = createTempVariable(0 /* Auto */); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_19); - emit(name_19); + tempParameters.push(name_22); + emit(name_22); } else { emit(node.name); @@ -26949,7 +28235,7 @@ var ts; } } function emitRestParameter(node) { - if (languageVersion < 2 /* ES6 */ && ts.hasRestParameters(node)) { + if (languageVersion < 2 /* ES6 */ && ts.hasRestParameter(node)) { var restIndex = node.parameters.length - 1; var restParam = node.parameters[restIndex]; // A rest parameter cannot have a binding pattern, so let's just ignore it if it does. @@ -27063,7 +28349,7 @@ var ts; write("("); if (node) { var parameters = node.parameters; - var omitCount = languageVersion < 2 /* ES6 */ && ts.hasRestParameters(node) ? 1 : 0; + var omitCount = languageVersion < 2 /* ES6 */ && ts.hasRestParameter(node) ? 1 : 0; emitList(parameters, 0, parameters.length - omitCount, false, false); } write(")"); @@ -28066,7 +29352,7 @@ var ts; } function shouldEmitEnumDeclaration(node) { var isConstEnum = ts.isConst(node); - return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.separateCompilation; + return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules; } function emitEnumDeclaration(node) { // const enums are completely erased during compilation. @@ -28165,7 +29451,7 @@ var ts; } } function shouldEmitModuleDeclaration(node) { - return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.separateCompilation); + return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules); } function isModuleMergedWithES6Class(node) { return languageVersion === 2 /* ES6 */ && !!(resolver.getNodeCheckFlags(node) & 2048 /* LexicalModuleMergesWithClass */); @@ -28568,8 +29854,8 @@ var ts; // export { x, y } for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_20 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_20] || (exportSpecifiers[name_20] = [])).push(specifier); + var name_23 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_23] || (exportSpecifiers[name_23] = [])).push(specifier); } } break; @@ -28769,12 +30055,12 @@ var ts; var seen = {}; for (var i = 0; i < hoistedVars.length; ++i) { var local = hoistedVars[i]; - var name_21 = local.kind === 65 /* Identifier */ + var name_24 = local.kind === 65 /* Identifier */ ? local : local.name; - if (name_21) { + if (name_24) { // do not emit duplicate entries (in case of declaration merging) in the list of hoisted variables - var text = ts.unescapeIdentifier(name_21.text); + var text = ts.unescapeIdentifier(name_24.text); if (ts.hasProperty(seen, text)) { continue; } @@ -28853,15 +30139,15 @@ var ts; } if (node.kind === 199 /* VariableDeclaration */ || node.kind === 153 /* BindingElement */) { if (shouldHoistVariable(node, false)) { - var name_22 = node.name; - if (name_22.kind === 65 /* Identifier */) { + var name_25 = node.name; + if (name_25.kind === 65 /* Identifier */) { if (!hoistedVars) { hoistedVars = []; } - hoistedVars.push(name_22); + hoistedVars.push(name_25); } else { - ts.forEachChild(name_22, visit); + ts.forEachChild(name_25, visit); } } return; @@ -29265,7 +30551,7 @@ var ts; paramEmitted = true; } } - if (ts.isExternalModule(node) || compilerOptions.separateCompilation) { + if (ts.isExternalModule(node) || compilerOptions.isolatedModules) { if (languageVersion >= 2 /* ES6 */) { emitES6Module(node, startIndex); } @@ -29320,6 +30606,8 @@ var ts; case 204 /* TypeAliasDeclaration */: case 215 /* ExportAssignment */: return false; + case 181 /* VariableStatement */: + return shouldEmitLeadingAndTrailingCommentsForVariableStatement(node); case 206 /* ModuleDeclaration */: // Only emit the leading/trailing comments for a module if we're actually // emitting the module as well. @@ -29656,7 +30944,7 @@ var ts; /* @internal */ ts.ioReadTime = 0; /* @internal */ ts.ioWriteTime = 0; /** The version of the TypeScript compiler release */ - ts.version = "1.5.2"; + ts.version = "1.5.3"; var carriageReturnLineFeed = "\r\n"; var lineFeed = "\n"; function findConfigFile(searchPath) { @@ -30108,18 +31396,18 @@ var ts; return allFilesBelongToPath; } function verifyCompilerOptions() { - if (options.separateCompilation) { + if (options.isolatedModules) { if (options.sourceMap) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceMap_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceMap_cannot_be_specified_with_option_isolatedModules)); } if (options.declaration) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_declaration_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_declaration_cannot_be_specified_with_option_isolatedModules)); } if (options.noEmitOnError) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules)); } if (options.out) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_out_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_out_cannot_be_specified_with_option_isolatedModules)); } } if (options.inlineSourceMap) { @@ -30150,14 +31438,14 @@ var ts; } var languageVersion = options.target || 0 /* ES3 */; var firstExternalModuleSourceFile = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); - if (options.separateCompilation) { + if (options.isolatedModules) { if (!options.module && languageVersion < 2 /* ES6 */) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); } var firstNonExternalModuleSourceFile = ts.forEach(files, function (f) { return !ts.isExternalModule(f) && !ts.isDeclarationFile(f) ? f : undefined; }); if (firstNonExternalModuleSourceFile) { var span = ts.getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile); - diagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_separateCompilation_flag_is_provided)); + diagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); } } else if (firstExternalModuleSourceFile && languageVersion < 2 /* ES6 */ && !options.module) { @@ -30198,6 +31486,10 @@ var ts; diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration)); } } + if (options.emitDecoratorMetadata && + !options.experimentalDecorators) { + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified)); + } } } ts.createProgram = createProgram; @@ -30346,7 +31638,7 @@ var ts; paramType: ts.Diagnostics.LOCATION }, { - name: "separateCompilation", + name: "isolatedModules", type: "boolean" }, { @@ -30392,10 +31684,16 @@ var ts; type: "boolean", description: ts.Diagnostics.Watch_input_files }, + { + name: "experimentalDecorators", + type: "boolean", + description: ts.Diagnostics.Enables_experimental_support_for_ES7_decorators + }, { name: "emitDecoratorMetadata", type: "boolean", - experimental: true + experimental: true, + description: ts.Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators } ]; function parseCommandLine(commandLine) { @@ -30691,28 +31989,28 @@ var ts; switch (n.kind) { case 180 /* Block */: if (!ts.isFunctionBlock(n)) { - var parent_6 = n.parent; + var parent_7 = n.parent; var openBrace = ts.findChildOfKind(n, 14 /* OpenBraceToken */, sourceFile); var closeBrace = ts.findChildOfKind(n, 15 /* CloseBraceToken */, sourceFile); // Check if the block is standalone, or 'attached' to some parent statement. // If the latter, we want to collaps the block, but consider its hint span // to be the entire span of the parent. - if (parent_6.kind === 185 /* DoStatement */ || - parent_6.kind === 188 /* ForInStatement */ || - parent_6.kind === 189 /* ForOfStatement */ || - parent_6.kind === 187 /* ForStatement */ || - parent_6.kind === 184 /* IfStatement */ || - parent_6.kind === 186 /* WhileStatement */ || - parent_6.kind === 193 /* WithStatement */ || - parent_6.kind === 224 /* CatchClause */) { - addOutliningSpan(parent_6, openBrace, closeBrace, autoCollapse(n)); + if (parent_7.kind === 185 /* DoStatement */ || + parent_7.kind === 188 /* ForInStatement */ || + parent_7.kind === 189 /* ForOfStatement */ || + parent_7.kind === 187 /* ForStatement */ || + parent_7.kind === 184 /* IfStatement */ || + parent_7.kind === 186 /* WhileStatement */ || + parent_7.kind === 193 /* WithStatement */ || + parent_7.kind === 224 /* CatchClause */) { + addOutliningSpan(parent_7, openBrace, closeBrace, autoCollapse(n)); break; } - if (parent_6.kind === 197 /* TryStatement */) { + if (parent_7.kind === 197 /* TryStatement */) { // Could be the try-block, or the finally-block. - var tryStatement = parent_6; + var tryStatement = parent_7; if (tryStatement.tryBlock === n) { - addOutliningSpan(parent_6, openBrace, closeBrace, autoCollapse(n)); + addOutliningSpan(parent_7, openBrace, closeBrace, autoCollapse(n)); break; } else if (tryStatement.finallyBlock === n) { @@ -30779,12 +32077,12 @@ var ts; ts.forEach(program.getSourceFiles(), function (sourceFile) { cancellationToken.throwIfCancellationRequested(); var nameToDeclarations = sourceFile.getNamedDeclarations(); - for (var name_23 in nameToDeclarations) { - var declarations = ts.getProperty(nameToDeclarations, name_23); + for (var name_26 in nameToDeclarations) { + var declarations = ts.getProperty(nameToDeclarations, name_26); if (declarations) { // First do a quick check to see if the name of the declaration matches the // last portion of the (possibly) dotted name they're searching for. - var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_23); + var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_26); if (!matches) { continue; } @@ -30797,14 +32095,14 @@ var ts; if (!containers) { return undefined; } - matches = patternMatcher.getMatches(containers, name_23); + matches = patternMatcher.getMatches(containers, name_26); if (!matches) { continue; } } var fileName = sourceFile.fileName; var matchKind = bestMatchKind(matches); - rawItems.push({ name: name_23, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); + rawItems.push({ name: name_26, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } } } @@ -31187,9 +32485,9 @@ var ts; case 199 /* VariableDeclaration */: case 153 /* BindingElement */: var variableDeclarationNode; - var name_24; + var name_27; if (node.kind === 153 /* BindingElement */) { - name_24 = node.name; + name_27 = node.name; variableDeclarationNode = node; // binding elements are added only for variable declarations // bubble up to the containing variable declaration @@ -31201,16 +32499,16 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_24 = node.name; + name_27 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.variableElement); } case 136 /* Constructor */: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -32732,7 +34030,7 @@ var ts; // for the position of the relevant node (or comma). var syntaxList = ts.forEach(node.parent.getChildren(), function (c) { // find syntax list that covers the span of the node - if (c.kind === 229 /* SyntaxList */ && c.pos <= node.pos && c.end >= node.end) { + if (c.kind === 251 /* SyntaxList */ && c.pos <= node.pos && c.end >= node.end) { return c; } }); @@ -33139,10 +34437,6 @@ var ts; }); } ts.signatureToDisplayParts = signatureToDisplayParts; - function isJavaScript(fileName) { - return ts.fileExtensionIs(fileName, ".js"); - } - ts.isJavaScript = isJavaScript; })(ts || (ts = {})); /// /// @@ -33625,7 +34919,7 @@ var ts; this.NoSpaceBeforeOpenBracket = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 18 /* OpenBracketToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); this.NoSpaceAfterOpenBracket = new formatting.Rule(formatting.RuleDescriptor.create3(18 /* OpenBracketToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); this.NoSpaceBeforeCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 19 /* CloseBracketToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.NoSpaceAfterCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create3(19 /* CloseBracketToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceAfterCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create3(19 /* CloseBracketToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBeforeBlockInFunctionDeclarationContext), 8 /* Delete */)); // Place a space before open brace in a function declaration this.FunctionOpenBraceLeftTokenRange = formatting.Shared.TokenRange.AnyIncludingMultilineComments; this.SpaceBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 14 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); @@ -33708,6 +35002,10 @@ var ts; this.SpaceBeforeAt = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 52 /* AtToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); this.NoSpaceAfterAt = new formatting.Rule(formatting.RuleDescriptor.create3(52 /* AtToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); this.SpaceAfterDecorator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([65 /* Identifier */, 78 /* ExportKeyword */, 73 /* DefaultKeyword */, 69 /* ClassKeyword */, 109 /* StaticKeyword */, 108 /* PublicKeyword */, 106 /* PrivateKeyword */, 107 /* ProtectedKeyword */, 116 /* GetKeyword */, 121 /* SetKeyword */, 18 /* OpenBracketToken */, 35 /* AsteriskToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), 2 /* Space */)); + this.NoSpaceBetweenFunctionKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(83 /* FunctionKeyword */, 35 /* AsteriskToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 8 /* Delete */)); + this.SpaceAfterStarInGeneratorDeclaration = new formatting.Rule(formatting.RuleDescriptor.create3(35 /* AsteriskToken */, formatting.Shared.TokenRange.FromTokens([65 /* Identifier */, 16 /* OpenParenToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 2 /* Space */)); + this.NoSpaceBetweenYieldKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(110 /* YieldKeyword */, 35 /* AsteriskToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 8 /* Delete */)); + this.SpaceBetweenYieldOrYieldStarAndOperand = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([110 /* YieldKeyword */, 35 /* AsteriskToken */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 2 /* Space */)); // These rules are higher in priority than user-configurable rules. this.HighPriorityCommonRules = [ @@ -33725,7 +35023,9 @@ var ts; this.NoSpaceAfterCloseBrace, this.SpaceAfterOpenBrace, this.SpaceBeforeCloseBrace, this.NewLineBeforeCloseBraceInBlockContext, this.SpaceAfterCloseBrace, this.SpaceBetweenCloseBraceAndElse, this.SpaceBetweenCloseBraceAndWhile, this.NoSpaceBetweenEmptyBraceBrackets, + this.NoSpaceBetweenFunctionKeywordAndStar, this.SpaceAfterStarInGeneratorDeclaration, this.SpaceAfterFunctionInFuncDecl, this.NewLineAfterOpenBraceInBlockContext, this.SpaceAfterGetSetInMember, + this.NoSpaceBetweenYieldKeywordAndStar, this.SpaceBetweenYieldOrYieldStarAndOperand, this.NoSpaceBetweenReturnAndSemicolon, this.SpaceAfterCertainKeywords, this.SpaceAfterLetConstInVariableDeclaration, @@ -33797,9 +35097,9 @@ var ts; } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_25 in o) { - if (o[name_25] === rule) { - return name_25; + for (var name_28 in o) { + if (o[name_28] === rule) { + return name_28; } } throw new Error("Unknown rule"); @@ -33918,6 +35218,9 @@ var ts; } return false; }; + Rules.IsFunctionDeclarationOrFunctionExpressionContext = function (context) { + return context.contextNode.kind === 201 /* FunctionDeclaration */ || context.contextNode.kind === 163 /* FunctionExpression */; + }; Rules.IsTypeScriptDeclWithBlockContext = function (context) { return Rules.NodeIsTypeScriptDeclWithBlockContext(context.contextNode); }; @@ -33982,6 +35285,9 @@ var ts; Rules.IsSameLineTokenContext = function (context) { return context.TokensAreOnSameLine(); }; + Rules.IsNotBeforeBlockInFunctionDeclarationContext = function (context) { + return !Rules.IsFunctionDeclContext(context) && !Rules.IsBeforeBlockContext(context); + }; Rules.IsEndOfDecoratorContextOnSameLine = function (context) { return context.TokensAreOnSameLine() && context.contextNode.decorators && @@ -34036,6 +35342,9 @@ var ts; Rules.IsVoidOpContext = function (context) { return context.currentTokenSpan.kind === 99 /* VoidKeyword */ && context.currentTokenParent.kind === 167 /* VoidExpression */; }; + Rules.IsYieldOrYieldStarWithOperand = function (context) { + return context.contextNode.kind === 173 /* YieldExpression */ && context.contextNode.expression !== undefined; + }; return Rules; })(); formatting.Rules = Rules; @@ -35740,7 +37049,7 @@ var ts; return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(229 /* SyntaxList */, nodes.pos, nodes.end, 1024 /* Synthetic */, this); + var list = createNode(251 /* SyntaxList */, nodes.pos, nodes.end, 1024 /* Synthetic */, this); list._children = []; var pos = nodes.pos; for (var _i = 0; _i < nodes.length; _i++) { @@ -36495,6 +37804,7 @@ var ts; ClassificationTypeNames.typeParameterName = "type parameter name"; ClassificationTypeNames.typeAliasName = "type alias name"; ClassificationTypeNames.parameterName = "parameter name"; + ClassificationTypeNames.docCommentTagName = "doc comment tag name"; return ClassificationTypeNames; })(); ts.ClassificationTypeNames = ClassificationTypeNames; @@ -36516,6 +37826,7 @@ var ts; ClassificationType[ClassificationType["typeParameterName"] = 15] = "typeParameterName"; ClassificationType[ClassificationType["typeAliasName"] = 16] = "typeAliasName"; ClassificationType[ClassificationType["parameterName"] = 17] = "parameterName"; + ClassificationType[ClassificationType["docCommentTagName"] = 18] = "docCommentTagName"; })(ts.ClassificationType || (ts.ClassificationType = {})); var ClassificationType = ts.ClassificationType; function displayPartsToString(displayParts) { @@ -36538,9 +37849,9 @@ var ts; return false; } // If the parent is not sourceFile or module block it is local variable - for (var parent_7 = declaration.parent; !ts.isFunctionBlock(parent_7); parent_7 = parent_7.parent) { + for (var parent_8 = declaration.parent; !ts.isFunctionBlock(parent_8); parent_8 = parent_8.parent) { // Reached source file or module block - if (parent_7.kind === 228 /* SourceFile */ || parent_7.kind === 207 /* ModuleBlock */) { + if (parent_8.kind === 228 /* SourceFile */ || parent_8.kind === 207 /* ModuleBlock */) { return false; } } @@ -36687,12 +37998,12 @@ var ts; * This function will compile source text from 'input' argument using specified compiler options. * If not options are provided - it will use a set of default compiler options. * Extra compiler options that will unconditionally be used bu this function are: - * - separateCompilation = true + * - isolatedModules = true * - allowNonTsExtensions = true */ function transpile(input, compilerOptions, fileName, diagnostics) { var options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); - options.separateCompilation = true; + options.isolatedModules = true; // Filename can be non-ts file. options.allowNonTsExtensions = true; // Parse @@ -36728,7 +38039,8 @@ var ts; } ts.transpile = transpile; function createLanguageServiceSourceFile(fileName, scriptSnapshot, scriptTarget, version, setNodeParents) { - var sourceFile = ts.createSourceFile(fileName, scriptSnapshot.getText(0, scriptSnapshot.getLength()), scriptTarget, setNodeParents); + var text = scriptSnapshot.getText(0, scriptSnapshot.getLength()); + var sourceFile = ts.createSourceFile(fileName, text, scriptTarget, setNodeParents); setSourceFileFields(sourceFile, scriptSnapshot, version); // after full parsing we can use table with interned strings as name table sourceFile.nameTable = sourceFile.identifiers; @@ -36743,7 +38055,30 @@ var ts; if (version !== sourceFile.version) { // Once incremental parsing is ready, then just call into this function. if (!ts.disableIncrementalParsing) { - var newSourceFile = ts.updateSourceFile(sourceFile, scriptSnapshot.getText(0, scriptSnapshot.getLength()), textChangeRange, aggressiveChecks); + var newText; + // grab the fragment from the beginning of the original text to the beginning of the span + var prefix = textChangeRange.span.start !== 0 + ? sourceFile.text.substr(0, textChangeRange.span.start) + : ""; + // grab the fragment from the end of the span till the end of the original text + var suffix = ts.textSpanEnd(textChangeRange.span) !== sourceFile.text.length + ? sourceFile.text.substr(ts.textSpanEnd(textChangeRange.span)) + : ""; + if (textChangeRange.newLength === 0) { + // edit was a deletion - just combine prefix and suffix + newText = prefix && suffix ? prefix + suffix : prefix || suffix; + } + else { + // it was actual edit, fetch the fragment of new text that correspond to new span + var changedText = scriptSnapshot.getText(textChangeRange.span.start, textChangeRange.span.start + textChangeRange.newLength); + // combine prefix, changed text and suffix + newText = prefix && suffix + ? prefix + changedText + suffix + : prefix + ? (prefix + changedText) + : (changedText + suffix); + } + var newSourceFile = ts.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks); setSourceFileFields(newSourceFile, scriptSnapshot, version); // after incremental parsing nameTable might not be up-to-date // drop it so it can be lazily recreated later @@ -37299,12 +38634,16 @@ var ts; } } } + // hostCache is captured in the closure for 'getOrCreateSourceFile' but it should not be used past this point. + // It needs to be cleared to allow all collected snapshots to be released + hostCache = undefined; program = newProgram; // Make sure all the nodes in the program are both bound, and have their parent // pointers set property. program.getTypeChecker(); return; function getOrCreateSourceFile(fileName) { + ts.Debug.assert(hostCache !== undefined); // The program is asking for this file, check first if the host can locate it. // If the host can not locate the file, then it does not exist. return undefined // to the program to allow reporting of errors for missing files. @@ -37495,7 +38834,7 @@ var ts; return true; } if (parameter.questionToken) { - diagnostics.push(ts.createDiagnosticForNode(parameter.questionToken, ts.Diagnostics.can_only_be_used_in_a_ts_file)); + diagnostics.push(ts.createDiagnosticForNode(parameter.questionToken, ts.Diagnostics._0_can_only_be_used_in_a_ts_file, '?')); return true; } if (parameter.type) { @@ -37612,6 +38951,7 @@ var ts; var typeChecker = program.getTypeChecker(); var syntacticStart = new Date().getTime(); var sourceFile = getValidSourceFile(fileName); + var isJavaScriptFile = ts.isJavaScript(fileName); var start = new Date().getTime(); var currentToken = ts.getTokenAtPosition(sourceFile, position); log("getCompletionData: Get current token: " + (new Date().getTime() - start)); @@ -37694,13 +39034,29 @@ var ts; } } var type = typeChecker.getTypeAtLocation(node); + addTypeProperties(type); + } + function addTypeProperties(type) { if (type) { // Filter private properties - ts.forEach(type.getApparentProperties(), function (symbol) { + for (var _i = 0, _a = type.getApparentProperties(); _i < _a.length; _i++) { + var symbol = _a[_i]; if (typeChecker.isValidPropertyAccess((node.parent), symbol.name)) { symbols.push(symbol); } - }); + } + if (isJavaScriptFile && type.flags & 16384 /* Union */) { + // In javascript files, for union types, we don't just get the members that + // the individual types have in common, we also include all the members that + // each individual type has. This is because we're going to add all identifiers + // anyways. So we might as well elevate the members that were at least part + // of the individual types to a higher status since we know what they are. + var unionType = type; + for (var _b = 0, _c = unionType.types; _b < _c.length; _b++) { + var elementType = _c[_b]; + addTypeProperties(elementType); + } + } } } function tryGetGlobalSymbols() { @@ -37861,15 +39217,18 @@ var ts; if (previousToken.kind === 8 /* StringLiteral */ || previousToken.kind === 9 /* RegularExpressionLiteral */ || ts.isTemplateLiteralKind(previousToken.kind)) { - // The position has to be either: 1. entirely within the token text, or - // 2. at the end position of an unterminated token. var start_3 = previousToken.getStart(); var end = previousToken.getEnd(); + // To be "in" one of these literals, the position has to be: + // 1. entirely within the token text. + // 2. at the end position of an unterminated token. + // 3. at the end of a regular expression (due to trailing flags like '/foo/g'). if (start_3 < position && position < end) { return true; } - else if (position === end) { - return !!previousToken.isUnterminated; + if (position === end) { + return !!previousToken.isUnterminated || + previousToken.kind === 9 /* RegularExpressionLiteral */; } } return false; @@ -37877,12 +39236,12 @@ var ts; function getContainingObjectLiteralApplicableForCompletion(previousToken) { // The locations in an object literal expression that are applicable for completion are property name definition locations. if (previousToken) { - var parent_8 = previousToken.parent; + var parent_9 = previousToken.parent; switch (previousToken.kind) { case 14 /* OpenBraceToken */: // let x = { | case 23 /* CommaToken */: - if (parent_8 && parent_8.kind === 155 /* ObjectLiteralExpression */) { - return parent_8; + if (parent_9 && parent_9.kind === 155 /* ObjectLiteralExpression */) { + return parent_9; } break; } @@ -38065,10 +39424,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_26 in nameTable) { - if (!allNames[name_26]) { - allNames[name_26] = name_26; - var displayName = getCompletionEntryDisplayName(name_26, target, true); + for (var name_29 in nameTable) { + if (!allNames[name_29]) { + allNames[name_29] = name_29; + var displayName = getCompletionEntryDisplayName(name_29, target, true); if (displayName) { var entry = { name: displayName, @@ -38976,19 +40335,19 @@ var ts; function getThrowStatementOwner(throwStatement) { var child = throwStatement; while (child.parent) { - var parent_9 = child.parent; - if (ts.isFunctionBlock(parent_9) || parent_9.kind === 228 /* SourceFile */) { - return parent_9; + var parent_10 = child.parent; + if (ts.isFunctionBlock(parent_10) || parent_10.kind === 228 /* SourceFile */) { + return parent_10; } // A throw-statement is only owned by a try-statement if the try-statement has // a catch clause, and if the throw-statement occurs within the try block. - if (parent_9.kind === 197 /* TryStatement */) { - var tryStatement = parent_9; + if (parent_10.kind === 197 /* TryStatement */) { + var tryStatement = parent_10; if (tryStatement.tryBlock === child && tryStatement.catchClause) { return child; } } - child = parent_9; + child = parent_10; } return undefined; } @@ -39950,19 +41309,19 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeChecker.getContextualType(objectLiteral); - var name_27 = node.text; + var name_30 = node.text; if (contextualType) { if (contextualType.flags & 16384 /* Union */) { // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) // if not, search the constituent types for the property - var unionProperty = contextualType.getProperty(name_27); + var unionProperty = contextualType.getProperty(name_30); if (unionProperty) { return [unionProperty]; } else { var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_27); + var symbol = t.getProperty(name_30); if (symbol) { result_4.push(symbol); } @@ -39971,7 +41330,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_27); + var symbol_1 = contextualType.getProperty(name_30); if (symbol_1) { return [symbol_1]; } @@ -40348,6 +41707,7 @@ var ts; case 15 /* typeParameterName */: return ClassificationTypeNames.typeParameterName; case 16 /* typeAliasName */: return ClassificationTypeNames.typeAliasName; case 17 /* parameterName */: return ClassificationTypeNames.parameterName; + case 18 /* docCommentTagName */: return ClassificationTypeNames.docCommentTagName; } } function convertClassifications(classifications) { @@ -40398,8 +41758,7 @@ var ts; // Only bother with the trivia if it at least intersects the span of interest. if (ts.textSpanIntersectsWith(span, start, width)) { if (ts.isComment(kind)) { - // Simple comment. Just add as is. - pushClassification(start, width, 1 /* comment */); + classifyComment(token, kind, start, width); continue; } if (kind === 6 /* ConflictMarkerTrivia */) { @@ -40419,6 +41778,79 @@ var ts; } } } + function classifyComment(token, kind, start, width) { + if (kind === 3 /* MultiLineCommentTrivia */) { + // See if this is a doc comment. If so, we'll classify certain portions of it + // specially. + var docCommentAndDiagnostics = ts.parseIsolatedJSDocComment(sourceFile.text, start, width); + if (docCommentAndDiagnostics && docCommentAndDiagnostics.jsDocComment) { + docCommentAndDiagnostics.jsDocComment.parent = token; + classifyJSDocComment(docCommentAndDiagnostics.jsDocComment); + return; + } + } + // Simple comment. Just add as is. + pushCommentRange(start, width); + } + function pushCommentRange(start, width) { + pushClassification(start, width, 1 /* comment */); + } + function classifyJSDocComment(docComment) { + var pos = docComment.pos; + for (var _i = 0, _a = docComment.tags; _i < _a.length; _i++) { + var tag = _a[_i]; + // As we walk through each tag, classify the portion of text from the end of + // the last tag (or the start of the entire doc comment) as 'comment'. + if (tag.pos !== pos) { + pushCommentRange(pos, tag.pos - pos); + } + pushClassification(tag.atToken.pos, tag.atToken.end - tag.atToken.pos, 10 /* punctuation */); + pushClassification(tag.tagName.pos, tag.tagName.end - tag.tagName.pos, 18 /* docCommentTagName */); + pos = tag.tagName.end; + switch (tag.kind) { + case 247 /* JSDocParameterTag */: + processJSDocParameterTag(tag); + break; + case 250 /* JSDocTemplateTag */: + processJSDocTemplateTag(tag); + break; + case 249 /* JSDocTypeTag */: + processElement(tag.typeExpression); + break; + case 248 /* JSDocReturnTag */: + processElement(tag.typeExpression); + break; + } + pos = tag.end; + } + if (pos !== docComment.end) { + pushCommentRange(pos, docComment.end - pos); + } + return; + function processJSDocParameterTag(tag) { + if (tag.preParameterName) { + pushCommentRange(pos, tag.preParameterName.pos - pos); + pushClassification(tag.preParameterName.pos, tag.preParameterName.end - tag.preParameterName.pos, 17 /* parameterName */); + pos = tag.preParameterName.end; + } + if (tag.typeExpression) { + pushCommentRange(pos, tag.typeExpression.pos - pos); + processElement(tag.typeExpression); + pos = tag.typeExpression.end; + } + if (tag.postParameterName) { + pushCommentRange(pos, tag.postParameterName.pos - pos); + pushClassification(tag.postParameterName.pos, tag.postParameterName.end - tag.postParameterName.pos, 17 /* parameterName */); + pos = tag.postParameterName.end; + } + } + } + function processJSDocTemplateTag(tag) { + for (var _i = 0, _a = tag.getChildren(); _i < _a.length; _i++) { + var child = _a[_i]; + processElement(child); + } + } function classifyDisabledMergeCode(text, start, end) { // Classify the line that the ======= marker is on as a comment. Then just lex // all further tokens and add them to the result. @@ -40539,9 +41971,12 @@ var ts; } } function processElement(element) { + if (!element) { + return; + } // Ignore nodes that don't intersect the original span to classify. if (ts.textSpanIntersectsWith(span, element.getFullStart(), element.getFullWidth())) { - var children = element.getChildren(); + var children = element.getChildren(sourceFile); for (var _i = 0; _i < children.length; _i++) { var child = children[_i]; if (ts.isToken(child)) { @@ -40952,7 +42387,7 @@ var ts; var lastEnd = 0; for (var i = 0, n = dense.length; i < n; i += 3) { var start = dense[i]; - var length_1 = dense[i + 1]; + var length_2 = dense[i + 1]; var type = dense[i + 2]; // Make a whitespace entry between the last item and this one. if (lastEnd >= 0) { @@ -40961,8 +42396,8 @@ var ts; entries.push({ length: whitespaceLength_1, classification: TokenClass.Whitespace }); } } - entries.push({ length: length_1, classification: convertClassification(type) }); - lastEnd = start + length_1; + entries.push({ length: length_2, classification: convertClassification(type) }); + lastEnd = start + length_2; } var whitespaceLength = text.length - lastEnd; if (whitespaceLength > 0) { @@ -42444,4 +43879,4 @@ var TypeScript; })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); /* @internal */ -var toolsVersion = "1.4"; +var toolsVersion = "1.5"; diff --git a/bin/typescriptServices.d.ts b/bin/typescriptServices.d.ts index f03a7a00e4..ea7d2a352e 100644 --- a/bin/typescriptServices.d.ts +++ b/bin/typescriptServices.d.ts @@ -251,8 +251,30 @@ declare module ts { ShorthandPropertyAssignment = 226, EnumMember = 227, SourceFile = 228, - SyntaxList = 229, - Count = 230, + JSDocTypeExpression = 229, + JSDocAllType = 230, + JSDocUnknownType = 231, + JSDocArrayType = 232, + JSDocUnionType = 233, + JSDocTupleType = 234, + JSDocNullableType = 235, + JSDocNonNullableType = 236, + JSDocRecordType = 237, + JSDocRecordMember = 238, + JSDocTypeReference = 239, + JSDocOptionalType = 240, + JSDocFunctionType = 241, + JSDocVariadicType = 242, + JSDocConstructorType = 243, + JSDocThisType = 244, + JSDocComment = 245, + JSDocTag = 246, + JSDocParameterTag = 247, + JSDocReturnTag = 248, + JSDocTypeTag = 249, + JSDocTemplateTag = 250, + SyntaxList = 251, + Count = 252, FirstAssignment = 53, LastAssignment = 64, FirstReservedWord = 66, @@ -495,7 +517,7 @@ declare module ts { } interface YieldExpression extends Expression { asteriskToken?: Node; - expression: Expression; + expression?: Expression; } interface BinaryExpression extends Expression { left: Expression; @@ -666,7 +688,7 @@ declare module ts { interface ClassElement extends Declaration { _classElementBrand: any; } - interface InterfaceDeclaration extends Declaration, ModuleElement { + interface InterfaceDeclaration extends Declaration, Statement { name: Identifier; typeParameters?: NodeArray; heritageClauses?: NodeArray; @@ -676,7 +698,7 @@ declare module ts { token: SyntaxKind; types?: NodeArray; } - interface TypeAliasDeclaration extends Declaration, ModuleElement { + interface TypeAliasDeclaration extends Declaration, Statement { name: Identifier; type: TypeNode; } @@ -684,7 +706,7 @@ declare module ts { name: DeclarationName; initializer?: Expression; } - interface EnumDeclaration extends Declaration, ModuleElement { + interface EnumDeclaration extends Declaration, Statement { name: Identifier; members: NodeArray; } @@ -739,6 +761,82 @@ declare module ts { hasTrailingNewLine?: boolean; kind: SyntaxKind; } + interface JSDocTypeExpression extends Node { + type: JSDocType; + } + interface JSDocType extends TypeNode { + _jsDocTypeBrand: any; + } + interface JSDocAllType extends JSDocType { + _JSDocAllTypeBrand: any; + } + interface JSDocUnknownType extends JSDocType { + _JSDocUnknownTypeBrand: any; + } + interface JSDocArrayType extends JSDocType { + elementType: JSDocType; + } + interface JSDocUnionType extends JSDocType { + types: NodeArray; + } + interface JSDocTupleType extends JSDocType { + types: NodeArray; + } + interface JSDocNonNullableType extends JSDocType { + type: JSDocType; + } + interface JSDocNullableType extends JSDocType { + type: JSDocType; + } + interface JSDocRecordType extends JSDocType, TypeLiteralNode { + members: NodeArray; + } + interface JSDocTypeReference extends JSDocType { + name: EntityName; + typeArguments: NodeArray; + } + interface JSDocOptionalType extends JSDocType { + type: JSDocType; + } + interface JSDocFunctionType extends JSDocType, SignatureDeclaration { + parameters: NodeArray; + type: JSDocType; + } + interface JSDocVariadicType extends JSDocType { + type: JSDocType; + } + interface JSDocConstructorType extends JSDocType { + type: JSDocType; + } + interface JSDocThisType extends JSDocType { + type: JSDocType; + } + interface JSDocRecordMember extends PropertyDeclaration { + name: Identifier | LiteralExpression; + type?: JSDocType; + } + interface JSDocComment extends Node { + tags: NodeArray; + } + interface JSDocTag extends Node { + atToken: Node; + tagName: Identifier; + } + interface JSDocTemplateTag extends JSDocTag { + typeParameters: NodeArray; + } + interface JSDocReturnTag extends JSDocTag { + typeExpression: JSDocTypeExpression; + } + interface JSDocTypeTag extends JSDocTag { + typeExpression: JSDocTypeExpression; + } + interface JSDocParameterTag extends JSDocTag { + preParameterName?: Identifier; + typeExpression?: JSDocTypeExpression; + postParameterName?: Identifier; + isBracketed: boolean; + } interface SourceFile extends Declaration { statements: NodeArray; endOfFileToken: Node; @@ -901,6 +999,7 @@ declare module ts { UseOnlyExternalAliasing = 2, } const enum SymbolFlags { + None = 0, FunctionScopedVariable = 1, BlockScopedVariable = 2, Property = 4, @@ -959,10 +1058,8 @@ declare module ts { AliasExcludes = 8388608, ModuleMember = 8914931, ExportHasLocal = 944, - HasLocals = 255504, HasExports = 1952, HasMembers = 6240, - IsContainer = 262128, PropertyOrAccessor = 98308, Export = 7340032, } @@ -970,9 +1067,9 @@ declare module ts { flags: SymbolFlags; name: string; declarations?: Declaration[]; + valueDeclaration?: Declaration; members?: SymbolTable; exports?: SymbolTable; - valueDeclaration?: Declaration; } interface SymbolTable { [index: string]: Symbol; @@ -1011,6 +1108,8 @@ declare module ts { } interface InterfaceType extends ObjectType { typeParameters: TypeParameter[]; + outerTypeParameters: TypeParameter[]; + localTypeParameters: TypeParameter[]; } interface InterfaceTypeWithBaseTypes extends InterfaceType { baseTypes: ObjectType[]; @@ -1114,7 +1213,8 @@ declare module ts { target?: ScriptTarget; version?: boolean; watch?: boolean; - separateCompilation?: boolean; + isolatedModules?: boolean; + experimentalDecorators?: boolean; emitDecoratorMetadata?: boolean; [option: string]: string | number | boolean; } @@ -1226,8 +1326,6 @@ declare module ts { function getTrailingCommentRanges(text: string, pos: number): CommentRange[]; function isIdentifierStart(ch: number, languageVersion: ScriptTarget): boolean; function isIdentifierPart(ch: number, languageVersion: ScriptTarget): boolean; - /** Creates a scanner over a (possibly unspecified) range of a piece of text. */ - function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, text?: string, onError?: ErrorCallback, start?: number, length?: number): Scanner; } declare module ts { function getDefaultLibFileName(options: CompilerOptions): string; @@ -1256,6 +1354,7 @@ declare module ts { * Vn. */ function collapseTextChangeRangesAcrossMultipleVersions(changes: TextChangeRange[]): TextChangeRange; + function getTypeParameterOwner(d: Declaration): Declaration; } declare module ts { function getNodeConstructor(kind: SyntaxKind): new () => Node; @@ -1812,6 +1911,7 @@ declare module ts { static typeParameterName: string; static typeAliasName: string; static parameterName: string; + static docCommentTagName: string; } const enum ClassificationType { comment = 1, @@ -1831,6 +1931,7 @@ declare module ts { typeParameterName = 15, typeAliasName = 16, parameterName = 17, + docCommentTagName = 18, } interface DisplayPartsSymbolWriter extends SymbolWriter { displayParts(): SymbolDisplayPart[]; diff --git a/bin/typescriptServices.js b/bin/typescriptServices.js index 4cab75bfcb..2b3f25998a 100644 --- a/bin/typescriptServices.js +++ b/bin/typescriptServices.js @@ -270,10 +270,35 @@ var ts; SyntaxKind[SyntaxKind["EnumMember"] = 227] = "EnumMember"; // Top-level nodes SyntaxKind[SyntaxKind["SourceFile"] = 228] = "SourceFile"; + // JSDoc nodes. + SyntaxKind[SyntaxKind["JSDocTypeExpression"] = 229] = "JSDocTypeExpression"; + // The * type. + SyntaxKind[SyntaxKind["JSDocAllType"] = 230] = "JSDocAllType"; + // The ? type. + SyntaxKind[SyntaxKind["JSDocUnknownType"] = 231] = "JSDocUnknownType"; + SyntaxKind[SyntaxKind["JSDocArrayType"] = 232] = "JSDocArrayType"; + SyntaxKind[SyntaxKind["JSDocUnionType"] = 233] = "JSDocUnionType"; + SyntaxKind[SyntaxKind["JSDocTupleType"] = 234] = "JSDocTupleType"; + SyntaxKind[SyntaxKind["JSDocNullableType"] = 235] = "JSDocNullableType"; + SyntaxKind[SyntaxKind["JSDocNonNullableType"] = 236] = "JSDocNonNullableType"; + SyntaxKind[SyntaxKind["JSDocRecordType"] = 237] = "JSDocRecordType"; + SyntaxKind[SyntaxKind["JSDocRecordMember"] = 238] = "JSDocRecordMember"; + SyntaxKind[SyntaxKind["JSDocTypeReference"] = 239] = "JSDocTypeReference"; + SyntaxKind[SyntaxKind["JSDocOptionalType"] = 240] = "JSDocOptionalType"; + SyntaxKind[SyntaxKind["JSDocFunctionType"] = 241] = "JSDocFunctionType"; + SyntaxKind[SyntaxKind["JSDocVariadicType"] = 242] = "JSDocVariadicType"; + SyntaxKind[SyntaxKind["JSDocConstructorType"] = 243] = "JSDocConstructorType"; + SyntaxKind[SyntaxKind["JSDocThisType"] = 244] = "JSDocThisType"; + SyntaxKind[SyntaxKind["JSDocComment"] = 245] = "JSDocComment"; + SyntaxKind[SyntaxKind["JSDocTag"] = 246] = "JSDocTag"; + SyntaxKind[SyntaxKind["JSDocParameterTag"] = 247] = "JSDocParameterTag"; + SyntaxKind[SyntaxKind["JSDocReturnTag"] = 248] = "JSDocReturnTag"; + SyntaxKind[SyntaxKind["JSDocTypeTag"] = 249] = "JSDocTypeTag"; + SyntaxKind[SyntaxKind["JSDocTemplateTag"] = 250] = "JSDocTemplateTag"; // Synthesized list - SyntaxKind[SyntaxKind["SyntaxList"] = 229] = "SyntaxList"; + SyntaxKind[SyntaxKind["SyntaxList"] = 251] = "SyntaxList"; // Enum value count - SyntaxKind[SyntaxKind["Count"] = 230] = "Count"; + SyntaxKind[SyntaxKind["Count"] = 252] = "Count"; // Markers SyntaxKind[SyntaxKind["FirstAssignment"] = 53] = "FirstAssignment"; SyntaxKind[SyntaxKind["LastAssignment"] = 64] = "LastAssignment"; @@ -323,6 +348,7 @@ var ts; var NodeFlags = ts.NodeFlags; /* @internal */ (function (ParserContextFlags) { + ParserContextFlags[ParserContextFlags["None"] = 0] = "None"; // Set if this node was parsed in strict mode. Used for grammar error checks, as well as // checking if the node can be reused in incremental settings. ParserContextFlags[ParserContextFlags["StrictMode"] = 1] = "StrictMode"; @@ -338,14 +364,17 @@ var ts; // the parser only sets this directly on the node it creates right after encountering the // error. ParserContextFlags[ParserContextFlags["ThisNodeHasError"] = 32] = "ThisNodeHasError"; + // This node was parsed in a JavaScript file and can be processed differently. For example + // its type can be specified usign a JSDoc comment. + ParserContextFlags[ParserContextFlags["JavaScriptFile"] = 64] = "JavaScriptFile"; // Context flags set directly by the parser. ParserContextFlags[ParserContextFlags["ParserGeneratedFlags"] = 63] = "ParserGeneratedFlags"; // Context flags computed by aggregating child flags upwards. // Used during incremental parsing to determine if this node or any of its children had an // error. Computed only once and then cached. - ParserContextFlags[ParserContextFlags["ThisNodeOrAnySubNodesHasError"] = 64] = "ThisNodeOrAnySubNodesHasError"; + ParserContextFlags[ParserContextFlags["ThisNodeOrAnySubNodesHasError"] = 128] = "ThisNodeOrAnySubNodesHasError"; // Used to know if we've computed data from children and cached it in this node. - ParserContextFlags[ParserContextFlags["HasAggregatedChildData"] = 128] = "HasAggregatedChildData"; + ParserContextFlags[ParserContextFlags["HasAggregatedChildData"] = 256] = "HasAggregatedChildData"; })(ts.ParserContextFlags || (ts.ParserContextFlags = {})); var ParserContextFlags = ts.ParserContextFlags; /* @internal */ @@ -400,6 +429,7 @@ var ts; })(ts.SymbolAccessibility || (ts.SymbolAccessibility = {})); var SymbolAccessibility = ts.SymbolAccessibility; (function (SymbolFlags) { + SymbolFlags[SymbolFlags["None"] = 0] = "None"; SymbolFlags[SymbolFlags["FunctionScopedVariable"] = 1] = "FunctionScopedVariable"; SymbolFlags[SymbolFlags["BlockScopedVariable"] = 2] = "BlockScopedVariable"; SymbolFlags[SymbolFlags["Property"] = 4] = "Property"; @@ -462,10 +492,8 @@ var ts; SymbolFlags[SymbolFlags["AliasExcludes"] = 8388608] = "AliasExcludes"; SymbolFlags[SymbolFlags["ModuleMember"] = 8914931] = "ModuleMember"; SymbolFlags[SymbolFlags["ExportHasLocal"] = 944] = "ExportHasLocal"; - SymbolFlags[SymbolFlags["HasLocals"] = 255504] = "HasLocals"; SymbolFlags[SymbolFlags["HasExports"] = 1952] = "HasExports"; SymbolFlags[SymbolFlags["HasMembers"] = 6240] = "HasMembers"; - SymbolFlags[SymbolFlags["IsContainer"] = 262128] = "IsContainer"; SymbolFlags[SymbolFlags["PropertyOrAccessor"] = 98308] = "PropertyOrAccessor"; SymbolFlags[SymbolFlags["Export"] = 7340032] = "Export"; })(ts.SymbolFlags || (ts.SymbolFlags = {})); @@ -826,6 +854,16 @@ var ts; } } ts.addRange = addRange; + function rangeEquals(array1, array2, pos, end) { + while (pos < end) { + if (array1[pos] !== array2[pos]) { + return false; + } + pos++; + } + return true; + } + ts.rangeEquals = rangeEquals; /** * Returns the last element of an array if non-empty, undefined otherwise. */ @@ -995,8 +1033,10 @@ var ts; var end = start + length; Debug.assert(start >= 0, "start must be non-negative, is " + start); Debug.assert(length >= 0, "length must be non-negative, is " + length); - Debug.assert(start <= file.text.length, "start must be within the bounds of the file. " + start + " > " + file.text.length); - Debug.assert(end <= file.text.length, "end must be the bounds of the file. " + end + " > " + file.text.length); + if (file) { + Debug.assert(start <= file.text.length, "start must be within the bounds of the file. " + start + " > " + file.text.length); + Debug.assert(end <= file.text.length, "end must be the bounds of the file. " + end + " > " + file.text.length); + } var text = getLocaleSpecificMessage(message.key); if (arguments.length > 4) { text = formatStringFromArgs(text, arguments, 4); @@ -1584,7 +1624,7 @@ var ts; for (var _i = 0; _i < files.length; _i++) { var current = files[_i]; var name = ts.combinePaths(path, current); - var stat = _fs.lstatSync(name); + var stat = _fs.statSync(name); if (stat.isFile()) { if (!extension || ts.fileExtensionIs(name, extension)) { result.push(name); @@ -1790,7 +1830,7 @@ var ts; Unterminated_template_literal: { code: 1160, category: ts.DiagnosticCategory.Error, key: "Unterminated template literal." }, Unterminated_regular_expression_literal: { code: 1161, category: ts.DiagnosticCategory.Error, key: "Unterminated regular expression literal." }, An_object_member_cannot_be_declared_optional: { code: 1162, category: ts.DiagnosticCategory.Error, key: "An object member cannot be declared optional." }, - yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: ts.DiagnosticCategory.Error, key: "'yield' expression must be contained_within a generator declaration." }, + A_yield_expression_is_only_allowed_in_a_generator_body: { code: 1163, category: ts.DiagnosticCategory.Error, key: "A 'yield' expression is only allowed in a generator body." }, Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: ts.DiagnosticCategory.Error, key: "Computed property names are not allowed in enums." }, A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol: { code: 1165, category: ts.DiagnosticCategory.Error, key: "A computed property name in an ambient context must directly refer to a built-in symbol." }, A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol: { code: 1166, category: ts.DiagnosticCategory.Error, key: "A computed property name in a class property declaration must directly refer to a built-in symbol." }, @@ -1835,8 +1875,8 @@ var ts; Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: ts.DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." }, Decorators_are_not_valid_here: { code: 1206, category: ts.DiagnosticCategory.Error, key: "Decorators are not valid here." }, Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: ts.DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, - Cannot_compile_namespaces_when_the_separateCompilation_flag_is_provided: { code: 1208, category: ts.DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--separateCompilation' flag is provided." }, - Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: ts.DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, + Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided: { code: 1208, category: ts.DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--isolatedModules' flag is provided." }, + Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided: { code: 1209, category: ts.DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--isolatedModules' flag is provided." }, Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: ts.DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." }, A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: ts.DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: ts.DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" }, @@ -1844,6 +1884,11 @@ var ts; Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" }, Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: ts.DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: ts.DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." }, + Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning: { code: 1219, category: ts.DiagnosticCategory.Error, key: "Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning." }, + Generators_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 1220, category: ts.DiagnosticCategory.Error, key: "Generators are only available when targeting ECMAScript 6 or higher." }, + Generators_are_not_allowed_in_an_ambient_context: { code: 1221, category: ts.DiagnosticCategory.Error, key: "Generators are not allowed in an ambient context." }, + An_overload_signature_cannot_be_declared_as_a_generator: { code: 1222, category: ts.DiagnosticCategory.Error, key: "An overload signature cannot be declared as a generator." }, + _0_tag_already_specified: { code: 1223, category: ts.DiagnosticCategory.Error, key: "'{0}' tag already specified." }, Duplicate_identifier_0: { code: 2300, category: ts.DiagnosticCategory.Error, key: "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." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: ts.DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -2004,7 +2049,7 @@ var ts; The_0_operator_cannot_be_applied_to_type_symbol: { code: 2469, category: ts.DiagnosticCategory.Error, key: "The '{0}' operator cannot be applied to type 'symbol'." }, Symbol_reference_does_not_refer_to_the_global_Symbol_constructor_object: { code: 2470, category: ts.DiagnosticCategory.Error, key: "'Symbol' reference does not refer to the global Symbol constructor object." }, A_computed_property_name_of_the_form_0_must_be_of_type_symbol: { code: 2471, category: ts.DiagnosticCategory.Error, key: "A computed property name of the form '{0}' must be of type 'symbol'." }, - Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher: { code: 2472, category: ts.DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher." }, + Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher: { code: 2472, category: ts.DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher." }, Enum_declarations_must_all_be_const_or_non_const: { code: 2473, category: ts.DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." }, In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 2474, category: ts.DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression." }, const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment: { code: 2475, category: ts.DiagnosticCategory.Error, key: "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment." }, @@ -2035,6 +2080,8 @@ var ts; A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: ts.DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." }, _0_is_referenced_directly_or_indirectly_in_its_own_type_annotation: { code: 2502, category: ts.DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own type annotation." }, Cannot_find_namespace_0: { code: 2503, category: ts.DiagnosticCategory.Error, key: "Cannot find namespace '{0}'." }, + No_best_common_type_exists_among_yield_expressions: { code: 2504, category: ts.DiagnosticCategory.Error, key: "No best common type exists among yield expressions." }, + A_generator_cannot_have_a_void_type_annotation: { code: 2505, category: ts.DiagnosticCategory.Error, key: "A generator cannot have a 'void' type annotation." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: ts.DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: ts.DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -2119,11 +2166,11 @@ var ts; Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." }, Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: ts.DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." }, Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: ts.DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." }, - Option_sourceMap_cannot_be_specified_with_option_separateCompilation: { code: 5043, category: ts.DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'separateCompilation'." }, - Option_declaration_cannot_be_specified_with_option_separateCompilation: { code: 5044, category: ts.DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'separateCompilation'." }, - Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation: { code: 5045, category: ts.DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'separateCompilation'." }, - Option_out_cannot_be_specified_with_option_separateCompilation: { code: 5046, category: ts.DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'separateCompilation'." }, - Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: ts.DiagnosticCategory.Error, key: "Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." }, + Option_sourceMap_cannot_be_specified_with_option_isolatedModules: { code: 5043, category: ts.DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'isolatedModules'." }, + Option_declaration_cannot_be_specified_with_option_isolatedModules: { code: 5044, category: ts.DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'isolatedModules'." }, + Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules: { code: 5045, category: ts.DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'isolatedModules'." }, + Option_out_cannot_be_specified_with_option_isolatedModules: { code: 5046, category: ts.DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'isolatedModules'." }, + Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: ts.DiagnosticCategory.Error, key: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." }, Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap: { code: 5048, category: ts.DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'inlineSourceMap'." }, Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5049, category: ts.DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'." }, Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5050, category: ts.DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified with option 'inlineSourceMap'." }, @@ -2177,6 +2224,9 @@ var ts; Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: ts.DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." }, NEWLINE: { code: 6061, category: ts.DiagnosticCategory.Message, key: "NEWLINE" }, Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: ts.DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." }, + Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified: { code: 6064, category: ts.DiagnosticCategory.Error, key: "Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified." }, + Enables_experimental_support_for_ES7_decorators: { code: 6065, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." }, + Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: ts.DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: ts.DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: ts.DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: ts.DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." }, @@ -2192,6 +2242,7 @@ var ts; _0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." }, _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: ts.DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: ts.DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, + Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: ts.DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." }, You_cannot_rename_this_element: { code: 8000, category: ts.DiagnosticCategory.Error, key: "You cannot rename this element." }, You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: ts.DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." }, import_can_only_be_used_in_a_ts_file: { code: 8002, category: ts.DiagnosticCategory.Error, key: "'import ... =' can only be used in a .ts file." }, @@ -2205,16 +2256,12 @@ var ts; types_can_only_be_used_in_a_ts_file: { code: 8010, category: ts.DiagnosticCategory.Error, key: "'types' can only be used in a .ts file." }, type_arguments_can_only_be_used_in_a_ts_file: { code: 8011, category: ts.DiagnosticCategory.Error, key: "'type arguments' can only be used in a .ts file." }, parameter_modifiers_can_only_be_used_in_a_ts_file: { code: 8012, category: ts.DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in a .ts file." }, - can_only_be_used_in_a_ts_file: { code: 8013, category: ts.DiagnosticCategory.Error, key: "'?' can only be used in a .ts file." }, property_declarations_can_only_be_used_in_a_ts_file: { code: 8014, category: ts.DiagnosticCategory.Error, key: "'property declarations' can only be used in a .ts file." }, enum_declarations_can_only_be_used_in_a_ts_file: { code: 8015, category: ts.DiagnosticCategory.Error, key: "'enum declarations' can only be used in a .ts file." }, type_assertion_expressions_can_only_be_used_in_a_ts_file: { code: 8016, category: ts.DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in a .ts file." }, decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: ts.DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." }, - yield_expressions_are_not_currently_supported: { code: 9000, category: ts.DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, - Generators_are_not_currently_supported: { code: 9001, category: ts.DiagnosticCategory.Error, key: "Generators are not currently supported." }, Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: ts.DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." }, - class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." }, - class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration: { code: 9004, category: ts.DiagnosticCategory.Error, key: "'class' declarations are only supported directly inside a module or as a top level declaration." } + class_expressions_are_not_currently_supported: { code: 9003, category: ts.DiagnosticCategory.Error, key: "'class' expressions are not currently supported." } }; })(ts || (ts = {})); /// @@ -2750,12 +2797,17 @@ var ts; ch > 127 /* maxAsciiCharacter */ && isUnicodeIdentifierPart(ch, languageVersion); } ts.isIdentifierPart = isIdentifierPart; - /** Creates a scanner over a (possibly unspecified) range of a piece of text. */ + /* @internal */ + // Creates a scanner over a (possibly unspecified) range of a piece of text. function createScanner(languageVersion, skipTrivia, text, onError, start, length) { - var pos; // Current position (end position of text of current token) - var end; // end of text - var startPos; // Start position of whitespace before current token - var tokenPos; // Start position of text of current token + // Current position (end position of text of current token) + var pos; + // end of text + var end; + // Start position of whitespace before current token + var startPos; + // Start position of text of current token + var tokenPos; var token; var tokenValue; var precedingLineBreak; @@ -3635,6 +3687,27 @@ var ts; } } ts.getModuleInstanceState = getModuleInstanceState; + var ContainerFlags; + (function (ContainerFlags) { + // The current node is not a container, and no container manipulation should happen before + // recursing into it. + ContainerFlags[ContainerFlags["None"] = 0] = "None"; + // The current node is a container. It should be set as the current container (and block- + // container) before recursing into it. The current node does not have locals. Examples: + // + // Classes, ObjectLiterals, TypeLiterals, Interfaces... + ContainerFlags[ContainerFlags["IsContainer"] = 1] = "IsContainer"; + // The current node is a block-scoped-container. It should be set as the current block- + // container before recursing into it. Examples: + // + // Blocks (when not parented by functions), Catch clauses, For/For-in/For-of statements... + ContainerFlags[ContainerFlags["IsBlockScopedContainer"] = 2] = "IsBlockScopedContainer"; + ContainerFlags[ContainerFlags["HasLocals"] = 4] = "HasLocals"; + // If the current node is a container that also container that also contains locals. Examples: + // + // Functions, Methods, Modules, Source-files. + ContainerFlags[ContainerFlags["IsContainerWithLocals"] = 5] = "IsContainerWithLocals"; + })(ContainerFlags || (ContainerFlags = {})); function bindSourceFile(file) { var start = new Date().getTime(); bindSourceFileWorker(file); @@ -3649,34 +3722,30 @@ var ts; var symbolCount = 0; var Symbol = ts.objectAllocator.getSymbolConstructor(); if (!file.locals) { - file.locals = {}; - container = file; - setBlockScopeContainer(file, false); bind(file); file.symbolCount = symbolCount; } + return; function createSymbol(flags, name) { symbolCount++; return new Symbol(flags, name); } - function setBlockScopeContainer(node, cleanLocals) { - blockScopeContainer = node; - if (cleanLocals) { - blockScopeContainer.locals = undefined; - } - } - function addDeclarationToSymbol(symbol, node, symbolKind) { - symbol.flags |= symbolKind; - if (!symbol.declarations) - symbol.declarations = []; - symbol.declarations.push(node); - if (symbolKind & 1952 /* HasExports */ && !symbol.exports) - symbol.exports = {}; - if (symbolKind & 6240 /* HasMembers */ && !symbol.members) - symbol.members = {}; + function addDeclarationToSymbol(symbol, node, symbolFlags) { + symbol.flags |= symbolFlags; node.symbol = symbol; - if (symbolKind & 107455 /* Value */ && !symbol.valueDeclaration) + if (!symbol.declarations) { + symbol.declarations = []; + } + symbol.declarations.push(node); + if (symbolFlags & 1952 /* HasExports */ && !symbol.exports) { + symbol.exports = {}; + } + if (symbolFlags & 6240 /* HasMembers */ && !symbol.members) { + symbol.members = {}; + } + if (symbolFlags & 107455 /* Value */ && !symbol.valueDeclaration) { symbol.valueDeclaration = node; + } } // Should not be called on a declaration with a computed property name, // unless it is a well known Symbol. @@ -3693,12 +3762,12 @@ var ts; return node.name.text; } switch (node.kind) { - case 144 /* ConstructorType */: case 136 /* Constructor */: return "__constructor"; case 143 /* FunctionType */: case 139 /* CallSignature */: return "__call"; + case 144 /* ConstructorType */: case 140 /* ConstructSignature */: return "__new"; case 141 /* IndexSignature */: @@ -3715,13 +3784,33 @@ var ts; function getDisplayName(node) { return node.name ? ts.declarationNameToString(node.name) : getDeclarationName(node); } - function declareSymbol(symbols, parent, node, includes, excludes) { + function declareSymbol(symbolTable, parent, node, includes, excludes) { ts.Debug.assert(!ts.hasDynamicName(node)); // The exported symbol for an export default function/class node is always named "default" var name = node.flags & 256 /* Default */ && parent ? "default" : getDeclarationName(node); var symbol; if (name !== undefined) { - symbol = ts.hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name)); + // Check and see if the symbol table already has a symbol with this name. If not, + // create a new symbol with this name and add it to the table. Note that we don't + // give the new symbol any flags *yet*. This ensures that it will not conflict + // witht he 'excludes' flags we pass in. + // + // If we do get an existing symbol, see if it conflicts with the new symbol we're + // creating. For example, a 'var' symbol and a 'class' symbol will conflict within + // the same symbol table. If we have a conflict, report the issue on each + // declaration we have for this symbol, and then create a new symbol for this + // declaration. + // + // If we created a new symbol, either because we didn't have a symbol with this name + // in the symbol table, or we conflicted with an existing symbol, then just add this + // node as the sole declaration of the new symbol. + // + // Otherwise, we'll be merging into a compatible existing symbol (for example when + // you have multiple 'vars' with the same name in the same container). In this case + // just add this node into the declarations list of the symbol. + symbol = ts.hasProperty(symbolTable, name) + ? symbolTable[name] + : (symbolTable[name] = createSymbol(0 /* None */, name)); if (symbol.flags & excludes) { if (node.name) { node.name.parent = node; @@ -3735,39 +3824,24 @@ var ts; file.bindDiagnostics.push(ts.createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration))); }); file.bindDiagnostics.push(ts.createDiagnosticForNode(node.name || node, message, getDisplayName(node))); - symbol = createSymbol(0, name); + symbol = createSymbol(0 /* None */, name); } } else { - symbol = createSymbol(0, "__missing"); + symbol = createSymbol(0 /* None */, "__missing"); } addDeclarationToSymbol(symbol, node, includes); symbol.parent = parent; - if ((node.kind === 202 /* ClassDeclaration */ || node.kind === 175 /* ClassExpression */) && symbol.exports) { - // TypeScript 1.0 spec (April 2014): 8.4 - // Every class automatically contains a static property member named 'prototype', - // the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter. - // It is an error to explicitly declare a static property member with the name 'prototype'. - var prototypeSymbol = createSymbol(4 /* Property */ | 134217728 /* Prototype */, "prototype"); - if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) { - if (node.name) { - node.name.parent = node; - } - file.bindDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name)); - } - symbol.exports[prototypeSymbol.name] = prototypeSymbol; - prototypeSymbol.parent = symbol; - } return symbol; } - function declareModuleMember(node, symbolKind, symbolExcludes) { + function declareModuleMember(node, symbolFlags, symbolExcludes) { var hasExportModifier = ts.getCombinedNodeFlags(node) & 1 /* Export */; - if (symbolKind & 8388608 /* Alias */) { + if (symbolFlags & 8388608 /* Alias */) { if (node.kind === 218 /* ExportSpecifier */ || (node.kind === 209 /* ImportEqualsDeclaration */ && hasExportModifier)) { - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); + return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); } else { - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); + return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } else { @@ -3783,62 +3857,150 @@ var ts; // but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way // when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope. if (hasExportModifier || container.flags & 65536 /* ExportContext */) { - var exportKind = (symbolKind & 107455 /* Value */ ? 1048576 /* ExportValue */ : 0) | - (symbolKind & 793056 /* Type */ ? 2097152 /* ExportType */ : 0) | - (symbolKind & 1536 /* Namespace */ ? 4194304 /* ExportNamespace */ : 0); + var exportKind = (symbolFlags & 107455 /* Value */ ? 1048576 /* ExportValue */ : 0) | + (symbolFlags & 793056 /* Type */ ? 2097152 /* ExportType */ : 0) | + (symbolFlags & 1536 /* Namespace */ ? 4194304 /* ExportNamespace */ : 0); var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); - local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); + local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); node.localSymbol = local; + return local; } else { - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); + return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } } - // All container nodes are kept on a linked list in declaration order. This list is used by the getLocalNameOfContainer function - // in the type checker to validate that the local name used for a container is unique. - function bindChildren(node, symbolKind, isBlockScopeContainer) { - if (symbolKind & 255504 /* HasLocals */) { - node.locals = {}; - } + // All container nodes are kept on a linked list in declaration order. This list is used by + // the getLocalNameOfContainer function in the type checker to validate that the local name + // used for a container is unique. + function bindChildren(node) { + // Before we recurse into a node's chilren, we first save the existing parent, container + // and block-container. Then after we pop out of processing the children, we restore + // these saved values. var saveParent = parent; var saveContainer = container; var savedBlockScopeContainer = blockScopeContainer; + // This node will now be set as the parent of all of its children as we recurse into them. parent = node; - if (symbolKind & 262128 /* IsContainer */) { - container = node; + // Depending on what kind of node this is, we may have to adjust the current container + // and block-container. If the current node is a container, then it is automatically + // considered the current block-container as well. Also, for containers that we know + // may contain locals, we proactively initialize the .locals field. We do this because + // it's highly likely that the .locals will be needed to place some child in (for example, + // a parameter, or variable declaration). + // + // However, we do not proactively create the .locals for block-containers because it's + // totally normal and common for block-containers to never actually have a block-scoped + // variable in them. We don't want to end up allocating an object for every 'block' we + // run into when most of them won't be necessary. + // + // Finally, if this is a block-container, then we clear out any existing .locals object + // it may contain within it. This happens in incremental scenarios. Because we can be + // reusing a node from a previous compilation, that node may have had 'locals' created + // for it. We must clear this so we don't accidently move any stale data forward from + // a previous compilation. + var containerFlags = getContainerFlags(node); + if (containerFlags & 1 /* IsContainer */) { + container = blockScopeContainer = node; + if (containerFlags & 4 /* HasLocals */) { + container.locals = {}; + } addToContainerChain(container); } - if (isBlockScopeContainer) { - // in incremental scenarios we might reuse nodes that already have locals being allocated - // during the bind step these locals should be dropped to prevent using stale data. - // locals should always be dropped unless they were previously initialized by the binder - // these cases are: - // - node has locals (symbolKind & HasLocals) !== 0 - // - node is a source file - setBlockScopeContainer(node, (symbolKind & 255504 /* HasLocals */) === 0 && node.kind !== 228 /* SourceFile */); + else if (containerFlags & 2 /* IsBlockScopedContainer */) { + blockScopeContainer = node; + blockScopeContainer.locals = undefined; } ts.forEachChild(node, bind); container = saveContainer; parent = saveParent; blockScopeContainer = savedBlockScopeContainer; } - function addToContainerChain(node) { - if (lastContainer) { - lastContainer.nextContainer = node; - } - lastContainer = node; - } - function bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer) { - switch (container.kind) { + function getContainerFlags(node) { + switch (node.kind) { + case 175 /* ClassExpression */: + case 202 /* ClassDeclaration */: + case 203 /* InterfaceDeclaration */: + case 205 /* EnumDeclaration */: + case 146 /* TypeLiteral */: + case 155 /* ObjectLiteralExpression */: + return 1 /* IsContainer */; + case 139 /* CallSignature */: + case 140 /* ConstructSignature */: + case 141 /* IndexSignature */: + case 135 /* MethodDeclaration */: + case 134 /* MethodSignature */: + case 201 /* FunctionDeclaration */: + case 136 /* Constructor */: + case 137 /* GetAccessor */: + case 138 /* SetAccessor */: + case 143 /* FunctionType */: + case 144 /* ConstructorType */: + case 163 /* FunctionExpression */: + case 164 /* ArrowFunction */: case 206 /* ModuleDeclaration */: - declareModuleMember(node, symbolKind, symbolExcludes); - break; case 228 /* SourceFile */: - if (ts.isExternalModule(container)) { - declareModuleMember(node, symbolKind, symbolExcludes); - break; - } + return 5 /* IsContainerWithLocals */; + case 224 /* CatchClause */: + case 187 /* ForStatement */: + case 188 /* ForInStatement */: + case 189 /* ForOfStatement */: + case 208 /* CaseBlock */: + return 2 /* IsBlockScopedContainer */; + case 180 /* Block */: + // do not treat blocks directly inside a function as a block-scoped-container. + // Locals that reside in this block should go to the function locals. Othewise 'x' + // would not appear to be a redeclaration of a block scoped local in the following + // example: + // + // function foo() { + // var x; + // let x; + // } + // + // If we placed 'var x' into the function locals and 'let x' into the locals of + // the block, then there would be no collision. + // + // By not creating a new block-scoped-container here, we ensure that both 'var x' + // and 'let x' go into the Function-container's locals, and we do get a collision + // conflict. + return ts.isFunctionLike(node.parent) ? 0 /* None */ : 2 /* IsBlockScopedContainer */; + } + return 0 /* None */; + } + function addToContainerChain(next) { + if (lastContainer) { + lastContainer.nextContainer = next; + } + lastContainer = next; + } + function declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes) { + // Just call this directly so that the return type of this function stays "void". + declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes); + } + function declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes) { + switch (container.kind) { + // Modules, source files, and classes need specialized handling for how their + // members are declared (for example, a member of a class will go into a specific + // symbol table depending on if it is static or not). As such, we defer to + // specialized handlers to take care of declaring these child members. + case 206 /* ModuleDeclaration */: + return declareModuleMember(node, symbolFlags, symbolExcludes); + case 228 /* SourceFile */: + return declareSourceFileMember(node, symbolFlags, symbolExcludes); + case 175 /* ClassExpression */: + case 202 /* ClassDeclaration */: + return declareClassMember(node, symbolFlags, symbolExcludes); + case 205 /* EnumDeclaration */: + return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); + case 146 /* TypeLiteral */: + case 155 /* ObjectLiteralExpression */: + case 203 /* InterfaceDeclaration */: + // Interface/Object-types always have their children added to the 'members' of + // their container. They are only accessible through an instance of their + // container, and are never in scope otherwise (even inside the body of the + // object / type / interface declaring them). + return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); case 143 /* FunctionType */: case 144 /* ConstructorType */: case 139 /* CallSignature */: @@ -3852,29 +4014,30 @@ var ts; case 201 /* FunctionDeclaration */: case 163 /* FunctionExpression */: case 164 /* ArrowFunction */: - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); - break; - case 175 /* ClassExpression */: - case 202 /* ClassDeclaration */: - if (node.flags & 128 /* Static */) { - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); - break; - } - case 146 /* TypeLiteral */: - case 155 /* ObjectLiteralExpression */: - case 203 /* InterfaceDeclaration */: - declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes); - break; - case 205 /* EnumDeclaration */: - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); - break; + // All the children of these container types are never visible through another + // symbol (i.e. through another symbol's 'exports' or 'members'). Instead, + // they're only accessed 'lexically' (i.e. from code that exists underneath + // their container in the tree. To accomplish this, we simply add their declared + // symbol to the 'locals' of the container. These symbols can then be found as + // the type checker walks up the containers, checking them for matching names. + return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } - bindChildren(node, symbolKind, isBlockScopeContainer); + } + function declareClassMember(node, symbolFlags, symbolExcludes) { + return node.flags & 128 /* Static */ + ? declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes) + : declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); + } + function declareSourceFileMember(node, symbolFlags, symbolExcludes) { + return ts.isExternalModule(file) + ? declareModuleMember(node, symbolFlags, symbolExcludes) + : declareSymbol(file.locals, undefined, node, symbolFlags, symbolExcludes); } function isAmbientContext(node) { while (node) { - if (node.flags & 2 /* Ambient */) + if (node.flags & 2 /* Ambient */) { return true; + } node = node.parent; } return false; @@ -3904,15 +4067,15 @@ var ts; function bindModuleDeclaration(node) { setExportContextFlag(node); if (node.name.kind === 8 /* StringLiteral */) { - bindDeclaration(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */, true); + declareSymbolAndAddToSymbolTable(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */); } else { var state = getModuleInstanceState(node); if (state === 0 /* NonInstantiated */) { - bindDeclaration(node, 1024 /* NamespaceModule */, 0 /* NamespaceModuleExcludes */, true); + declareSymbolAndAddToSymbolTable(node, 1024 /* NamespaceModule */, 0 /* NamespaceModuleExcludes */); } else { - bindDeclaration(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */, true); + declareSymbolAndAddToSymbolTable(node, 512 /* ValueModule */, 106639 /* ValueModuleExcludes */); var currentModuleIsConstEnumOnly = state === 2 /* ConstEnumOnly */; if (node.symbol.constEnumOnlyModule === undefined) { // non-merged case - use the current state @@ -3934,28 +4097,23 @@ var ts; // from an actual type literal symbol you would have gotten had you used the long form. var symbol = createSymbol(131072 /* Signature */, getDeclarationName(node)); addDeclarationToSymbol(symbol, node, 131072 /* Signature */); - bindChildren(node, 131072 /* Signature */, false); var typeLiteralSymbol = createSymbol(2048 /* TypeLiteral */, "__type"); addDeclarationToSymbol(typeLiteralSymbol, node, 2048 /* TypeLiteral */); - typeLiteralSymbol.members = {}; - typeLiteralSymbol.members[node.kind === 143 /* FunctionType */ ? "__call" : "__new"] = symbol; + typeLiteralSymbol.members = (_a = {}, _a[symbol.name] = symbol, _a); + var _a; } - function bindAnonymousDeclaration(node, symbolKind, name, isBlockScopeContainer) { - var symbol = createSymbol(symbolKind, name); - addDeclarationToSymbol(symbol, node, symbolKind); - bindChildren(node, symbolKind, isBlockScopeContainer); + function bindAnonymousDeclaration(node, symbolFlags, name) { + var symbol = createSymbol(symbolFlags, name); + addDeclarationToSymbol(symbol, node, symbolFlags); } - function bindCatchVariableDeclaration(node) { - bindChildren(node, 0, true); - } - function bindBlockScopedDeclaration(node, symbolKind, symbolExcludes) { + function bindBlockScopedDeclaration(node, symbolFlags, symbolExcludes) { switch (blockScopeContainer.kind) { case 206 /* ModuleDeclaration */: - declareModuleMember(node, symbolKind, symbolExcludes); + declareModuleMember(node, symbolFlags, symbolExcludes); break; case 228 /* SourceFile */: if (ts.isExternalModule(container)) { - declareModuleMember(node, symbolKind, symbolExcludes); + declareModuleMember(node, symbolFlags, symbolExcludes); break; } // fall through. @@ -3964,9 +4122,8 @@ var ts; blockScopeContainer.locals = {}; addToContainerChain(blockScopeContainer); } - declareSymbol(blockScopeContainer.locals, undefined, node, symbolKind, symbolExcludes); + declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes); } - bindChildren(node, symbolKind, false); } function bindBlockScopedVariableDeclaration(node) { bindBlockScopedDeclaration(node, 2 /* BlockScopedVariable */, 107455 /* BlockScopedVariableExcludes */); @@ -3976,182 +4133,182 @@ var ts; } function bind(node) { node.parent = parent; + // First we bind declaration nodes to a symbol if possible. We'll both create a symbol + // and then potentially add the symbol to an appropriate symbol table. Possible + // destination symbol tables are: + // + // 1) The 'exports' table of the current container's symbol. + // 2) The 'members' table of the current container's symbol. + // 3) The 'locals' table of the current container. + // + // However, not all symbols will end up in any of these tables. 'Anonymous' symbols + // (like TypeLiterals for example) will not be put in any table. + bindWorker(node); + // Then we recurse into the children of the node to bind them as well. For certain + // symbols we do specialized work when we recurse. For example, we'll keep track of + // the current 'container' node when it changes. This helps us know which symbol table + // a local should go into for example. + bindChildren(node); + } + function bindWorker(node) { switch (node.kind) { case 129 /* TypeParameter */: - bindDeclaration(node, 262144 /* TypeParameter */, 530912 /* TypeParameterExcludes */, false); - break; + return declareSymbolAndAddToSymbolTable(node, 262144 /* TypeParameter */, 530912 /* TypeParameterExcludes */); case 130 /* Parameter */: - bindParameter(node); - break; + return bindParameter(node); case 199 /* VariableDeclaration */: case 153 /* BindingElement */: - if (ts.isBindingPattern(node.name)) { - bindChildren(node, 0, false); - } - else if (ts.isBlockOrCatchScoped(node)) { - bindBlockScopedVariableDeclaration(node); - } - else if (ts.isParameterDeclaration(node)) { - // It is safe to walk up parent chain to find whether the node is a destructing parameter declaration - // because its parent chain has already been set up, since parents are set before descending into children. - // - // If node is a binding element in parameter declaration, we need to use ParameterExcludes. - // Using ParameterExcludes flag allows the compiler to report an error on duplicate identifiers in Parameter Declaration - // For example: - // function foo([a,a]) {} // Duplicate Identifier error - // function bar(a,a) {} // Duplicate Identifier error, parameter declaration in this case is handled in bindParameter - // // which correctly set excluded symbols - bindDeclaration(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */, false); - } - else { - bindDeclaration(node, 1 /* FunctionScopedVariable */, 107454 /* FunctionScopedVariableExcludes */, false); - } - break; + return bindVariableDeclarationOrBindingElement(node); case 133 /* PropertyDeclaration */: case 132 /* PropertySignature */: - bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0), 107455 /* PropertyExcludes */, false); - break; + return bindPropertyOrMethodOrAccessor(node, 4 /* Property */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), 107455 /* PropertyExcludes */); case 225 /* PropertyAssignment */: case 226 /* ShorthandPropertyAssignment */: - bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 107455 /* PropertyExcludes */, false); - break; + return bindPropertyOrMethodOrAccessor(node, 4 /* Property */, 107455 /* PropertyExcludes */); case 227 /* EnumMember */: - bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */, false); - break; + return bindPropertyOrMethodOrAccessor(node, 8 /* EnumMember */, 107455 /* EnumMemberExcludes */); case 139 /* CallSignature */: case 140 /* ConstructSignature */: case 141 /* IndexSignature */: - bindDeclaration(node, 131072 /* Signature */, 0, false); - break; + return declareSymbolAndAddToSymbolTable(node, 131072 /* Signature */, 0 /* None */); case 135 /* MethodDeclaration */: case 134 /* MethodSignature */: // If this is an ObjectLiteralExpression method, then it sits in the same space // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. - bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0), ts.isObjectLiteralMethod(node) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */, true); - break; + return bindPropertyOrMethodOrAccessor(node, 8192 /* Method */ | (node.questionToken ? 536870912 /* Optional */ : 0 /* None */), ts.isObjectLiteralMethod(node) ? 107455 /* PropertyExcludes */ : 99263 /* MethodExcludes */); case 201 /* FunctionDeclaration */: - bindDeclaration(node, 16 /* Function */, 106927 /* FunctionExcludes */, true); - break; + return declareSymbolAndAddToSymbolTable(node, 16 /* Function */, 106927 /* FunctionExcludes */); case 136 /* Constructor */: - bindDeclaration(node, 16384 /* Constructor */, 0, true); - break; + return declareSymbolAndAddToSymbolTable(node, 16384 /* Constructor */, 0 /* None */); case 137 /* GetAccessor */: - bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */, true); - break; + return bindPropertyOrMethodOrAccessor(node, 32768 /* GetAccessor */, 41919 /* GetAccessorExcludes */); case 138 /* SetAccessor */: - bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */, true); - break; + return bindPropertyOrMethodOrAccessor(node, 65536 /* SetAccessor */, 74687 /* SetAccessorExcludes */); case 143 /* FunctionType */: case 144 /* ConstructorType */: - bindFunctionOrConstructorType(node); - break; + return bindFunctionOrConstructorType(node); case 146 /* TypeLiteral */: - bindAnonymousDeclaration(node, 2048 /* TypeLiteral */, "__type", false); - break; + return bindAnonymousDeclaration(node, 2048 /* TypeLiteral */, "__type"); case 155 /* ObjectLiteralExpression */: - bindAnonymousDeclaration(node, 4096 /* ObjectLiteral */, "__object", false); - break; + return bindAnonymousDeclaration(node, 4096 /* ObjectLiteral */, "__object"); case 163 /* FunctionExpression */: case 164 /* ArrowFunction */: - bindAnonymousDeclaration(node, 16 /* Function */, "__function", true); - break; + return bindAnonymousDeclaration(node, 16 /* Function */, "__function"); case 175 /* ClassExpression */: - bindAnonymousDeclaration(node, 32 /* Class */, "__class", false); - break; - case 224 /* CatchClause */: - bindCatchVariableDeclaration(node); - break; case 202 /* ClassDeclaration */: - bindBlockScopedDeclaration(node, 32 /* Class */, 899583 /* ClassExcludes */); - break; + return bindClassLikeDeclaration(node); case 203 /* InterfaceDeclaration */: - bindDeclaration(node, 64 /* Interface */, 792992 /* InterfaceExcludes */, false); - break; + return bindBlockScopedDeclaration(node, 64 /* Interface */, 792992 /* InterfaceExcludes */); case 204 /* TypeAliasDeclaration */: - bindDeclaration(node, 524288 /* TypeAlias */, 793056 /* TypeAliasExcludes */, false); - break; + return bindBlockScopedDeclaration(node, 524288 /* TypeAlias */, 793056 /* TypeAliasExcludes */); case 205 /* EnumDeclaration */: - if (ts.isConst(node)) { - bindDeclaration(node, 128 /* ConstEnum */, 899967 /* ConstEnumExcludes */, false); - } - else { - bindDeclaration(node, 256 /* RegularEnum */, 899327 /* RegularEnumExcludes */, false); - } - break; + return bindEnumDeclaration(node); case 206 /* ModuleDeclaration */: - bindModuleDeclaration(node); - break; + return bindModuleDeclaration(node); case 209 /* ImportEqualsDeclaration */: case 212 /* NamespaceImport */: case 214 /* ImportSpecifier */: case 218 /* ExportSpecifier */: - bindDeclaration(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */, false); - break; + return declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); case 211 /* ImportClause */: - if (node.name) { - bindDeclaration(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */, false); - } - else { - bindChildren(node, 0, false); - } - break; + return bindImportClause(node); case 216 /* ExportDeclaration */: - if (!node.exportClause) { - // All export * declarations are collected in an __export symbol - declareSymbol(container.symbol.exports, container.symbol, node, 1073741824 /* ExportStar */, 0); - } - bindChildren(node, 0, false); - break; + return bindExportDeclaration(node); case 215 /* ExportAssignment */: - if (node.expression.kind === 65 /* Identifier */) { - // An export default clause with an identifier exports all meanings of that identifier - declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); - } - else { - // An export default clause with an expression exports a value - declareSymbol(container.symbol.exports, container.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); - } - bindChildren(node, 0, false); - break; + return bindExportAssignment(node); case 228 /* SourceFile */: - setExportContextFlag(node); - if (ts.isExternalModule(node)) { - bindAnonymousDeclaration(node, 512 /* ValueModule */, '"' + ts.removeFileExtension(node.fileName) + '"', true); - break; - } - case 180 /* Block */: - // do not treat function block a block-scope container - // all block-scope locals that reside in this block should go to the function locals. - // Otherwise this won't be considered as redeclaration of a block scoped local: - // function foo() { - // let x; - // let x; - // } - // 'let x' will be placed into the function locals and 'let x' - into the locals of the block - bindChildren(node, 0, !ts.isFunctionLike(node.parent)); - break; - case 224 /* CatchClause */: - case 187 /* ForStatement */: - case 188 /* ForInStatement */: - case 189 /* ForOfStatement */: - case 208 /* CaseBlock */: - bindChildren(node, 0, true); - break; - default: - var saveParent = parent; - parent = node; - ts.forEachChild(node, bind); - parent = saveParent; + return bindSourceFileIfExternalModule(); + } + } + function bindSourceFileIfExternalModule() { + setExportContextFlag(file); + if (ts.isExternalModule(file)) { + bindAnonymousDeclaration(file, 512 /* ValueModule */, '"' + ts.removeFileExtension(file.fileName) + '"'); + } + } + function bindExportAssignment(node) { + if (node.expression.kind === 65 /* Identifier */) { + // An export default clause with an identifier exports all meanings of that identifier + declareSymbol(container.symbol.exports, container.symbol, node, 8388608 /* Alias */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); + } + else { + // An export default clause with an expression exports a value + declareSymbol(container.symbol.exports, container.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */ | 8388608 /* AliasExcludes */); + } + } + function bindExportDeclaration(node) { + if (!node.exportClause) { + // All export * declarations are collected in an __export symbol + declareSymbol(container.symbol.exports, container.symbol, node, 1073741824 /* ExportStar */, 0 /* None */); + } + } + function bindImportClause(node) { + if (node.name) { + declareSymbolAndAddToSymbolTable(node, 8388608 /* Alias */, 8388608 /* AliasExcludes */); + } + } + function bindClassLikeDeclaration(node) { + if (node.kind === 202 /* ClassDeclaration */) { + bindBlockScopedDeclaration(node, 32 /* Class */, 899583 /* ClassExcludes */); + } + else { + bindAnonymousDeclaration(node, 32 /* Class */, "__class"); + } + var symbol = node.symbol; + // TypeScript 1.0 spec (April 2014): 8.4 + // Every class automatically contains a static property member named 'prototype', the + // type of which is an instantiation of the class type with type Any supplied as a type + // argument for each type parameter. It is an error to explicitly declare a static + // property member with the name 'prototype'. + // + // Note: we check for this here because this class may be merging into a module. The + // module might have an exported variable called 'prototype'. We can't allow that as + // that would clash with the built-in 'prototype' for the class. + var prototypeSymbol = createSymbol(4 /* Property */ | 134217728 /* Prototype */, "prototype"); + if (ts.hasProperty(symbol.exports, prototypeSymbol.name)) { + if (node.name) { + node.name.parent = node; + } + file.bindDiagnostics.push(ts.createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], ts.Diagnostics.Duplicate_identifier_0, prototypeSymbol.name)); + } + symbol.exports[prototypeSymbol.name] = prototypeSymbol; + prototypeSymbol.parent = symbol; + } + function bindEnumDeclaration(node) { + return ts.isConst(node) + ? bindBlockScopedDeclaration(node, 128 /* ConstEnum */, 899967 /* ConstEnumExcludes */) + : bindBlockScopedDeclaration(node, 256 /* RegularEnum */, 899327 /* RegularEnumExcludes */); + } + function bindVariableDeclarationOrBindingElement(node) { + if (!ts.isBindingPattern(node.name)) { + if (ts.isBlockOrCatchScoped(node)) { + bindBlockScopedVariableDeclaration(node); + } + else if (ts.isParameterDeclaration(node)) { + // It is safe to walk up parent chain to find whether the node is a destructing parameter declaration + // because its parent chain has already been set up, since parents are set before descending into children. + // + // If node is a binding element in parameter declaration, we need to use ParameterExcludes. + // Using ParameterExcludes flag allows the compiler to report an error on duplicate identifiers in Parameter Declaration + // For example: + // function foo([a,a]) {} // Duplicate Identifier error + // function bar(a,a) {} // Duplicate Identifier error, parameter declaration in this case is handled in bindParameter + // // which correctly set excluded symbols + declareSymbolAndAddToSymbolTable(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */); + } + else { + declareSymbolAndAddToSymbolTable(node, 1 /* FunctionScopedVariable */, 107454 /* FunctionScopedVariableExcludes */); + } } } function bindParameter(node) { if (ts.isBindingPattern(node.name)) { - bindAnonymousDeclaration(node, 1 /* FunctionScopedVariable */, getDestructuringParameterName(node), false); + bindAnonymousDeclaration(node, 1 /* FunctionScopedVariable */, getDestructuringParameterName(node)); } else { - bindDeclaration(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */, false); + declareSymbolAndAddToSymbolTable(node, 1 /* FunctionScopedVariable */, 107455 /* ParameterExcludes */); } // If this is a property-parameter, then also declare the property symbol into the // containing class. @@ -4162,13 +4319,10 @@ var ts; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, 4 /* Property */, 107455 /* PropertyExcludes */); } } - function bindPropertyOrMethodOrAccessor(node, symbolKind, symbolExcludes, isBlockScopeContainer) { - if (ts.hasDynamicName(node)) { - bindAnonymousDeclaration(node, symbolKind, "__computed", isBlockScopeContainer); - } - else { - bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer); - } + function bindPropertyOrMethodOrAccessor(node, symbolFlags, symbolExcludes) { + return ts.hasDynamicName(node) + ? bindAnonymousDeclaration(node, symbolFlags, "__computed") + : declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes); } } })(ts || (ts = {})); @@ -4226,11 +4380,11 @@ var ts; // Returns true if this node contains a parse error anywhere underneath it. function containsParseError(node) { aggregateChildData(node); - return (node.parserContextFlags & 64 /* ThisNodeOrAnySubNodesHasError */) !== 0; + return (node.parserContextFlags & 128 /* ThisNodeOrAnySubNodesHasError */) !== 0; } ts.containsParseError = containsParseError; function aggregateChildData(node) { - if (!(node.parserContextFlags & 128 /* HasAggregatedChildData */)) { + if (!(node.parserContextFlags & 256 /* HasAggregatedChildData */)) { // A node is considered to contain a parse error if: // a) the parser explicitly marked that it had an error // b) any of it's children reported that it had an error. @@ -4238,12 +4392,12 @@ var ts; ts.forEachChild(node, containsParseError); // If so, mark ourselves accordingly. if (thisNodeOrAnySubNodesHasError) { - node.parserContextFlags |= 64 /* ThisNodeOrAnySubNodesHasError */; + node.parserContextFlags |= 128 /* ThisNodeOrAnySubNodesHasError */; } // Also mark that we've propogated the child information to this node. This way we can // always consult the bit directly on this node without needing to check its children // again. - node.parserContextFlags |= 128 /* HasAggregatedChildData */; + node.parserContextFlags |= 256 /* HasAggregatedChildData */; } } function getSourceFileOfNode(node) { @@ -4530,6 +4684,88 @@ var ts; } ts.getJsDocComments = getJsDocComments; ts.fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/; + function isTypeNode(node) { + if (142 /* FirstTypeNode */ <= node.kind && node.kind <= 150 /* LastTypeNode */) { + return true; + } + switch (node.kind) { + case 112 /* AnyKeyword */: + case 120 /* NumberKeyword */: + case 122 /* StringKeyword */: + case 113 /* BooleanKeyword */: + case 123 /* SymbolKeyword */: + return true; + case 99 /* VoidKeyword */: + return node.parent.kind !== 167 /* VoidExpression */; + case 8 /* StringLiteral */: + // Specialized signatures can have string literals as their parameters' type names + return node.parent.kind === 130 /* Parameter */; + case 177 /* ExpressionWithTypeArguments */: + return true; + // Identifiers and qualified names may be type nodes, depending on their context. Climb + // above them to find the lowest container + case 65 /* Identifier */: + // If the identifier is the RHS of a qualified name, then it's a type iff its parent is. + if (node.parent.kind === 127 /* QualifiedName */ && node.parent.right === node) { + node = node.parent; + } + else if (node.parent.kind === 156 /* PropertyAccessExpression */ && node.parent.name === node) { + node = node.parent; + } + // fall through + case 127 /* QualifiedName */: + case 156 /* PropertyAccessExpression */: + // At this point, node is either a qualified name or an identifier + ts.Debug.assert(node.kind === 65 /* Identifier */ || node.kind === 127 /* QualifiedName */ || node.kind === 156 /* PropertyAccessExpression */, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); + var parent_1 = node.parent; + if (parent_1.kind === 145 /* TypeQuery */) { + return false; + } + // Do not recursively call isTypeNode on the parent. In the example: + // + // let a: A.B.C; + // + // Calling isTypeNode would consider the qualified name A.B a type node. Only C or + // A.B.C is a type node. + if (142 /* FirstTypeNode */ <= parent_1.kind && parent_1.kind <= 150 /* LastTypeNode */) { + return true; + } + switch (parent_1.kind) { + case 177 /* ExpressionWithTypeArguments */: + return true; + case 129 /* TypeParameter */: + return node === parent_1.constraint; + case 133 /* PropertyDeclaration */: + case 132 /* PropertySignature */: + case 130 /* Parameter */: + case 199 /* VariableDeclaration */: + return node === parent_1.type; + case 201 /* FunctionDeclaration */: + case 163 /* FunctionExpression */: + case 164 /* ArrowFunction */: + case 136 /* Constructor */: + case 135 /* MethodDeclaration */: + case 134 /* MethodSignature */: + case 137 /* GetAccessor */: + case 138 /* SetAccessor */: + return node === parent_1.type; + case 139 /* CallSignature */: + case 140 /* ConstructSignature */: + case 141 /* IndexSignature */: + return node === parent_1.type; + case 161 /* TypeAssertionExpression */: + return node === parent_1.type; + case 158 /* CallExpression */: + case 159 /* NewExpression */: + return parent_1.typeArguments && ts.indexOf(parent_1.typeArguments, node) >= 0; + case 160 /* TaggedTemplateExpression */: + // TODO (drosen): TaggedTemplateExpressions may eventually support type arguments. + return false; + } + } + return false; + } + ts.isTypeNode = isTypeNode; // Warning: This has the same semantics as the forEach family of functions, // in that traversal terminates in the event that 'visitor' supplies a truthy value. function forEachReturnStatement(body, visitor) { @@ -4558,6 +4794,44 @@ var ts; } } ts.forEachReturnStatement = forEachReturnStatement; + function forEachYieldExpression(body, visitor) { + return traverse(body); + function traverse(node) { + switch (node.kind) { + case 173 /* YieldExpression */: + visitor(node); + var operand = node.expression; + if (operand) { + traverse(operand); + } + case 205 /* EnumDeclaration */: + case 203 /* InterfaceDeclaration */: + case 206 /* ModuleDeclaration */: + case 204 /* TypeAliasDeclaration */: + case 202 /* ClassDeclaration */: + // These are not allowed inside a generator now, but eventually they may be allowed + // as local types. Regardless, any yield statements contained within them should be + // skipped in this traversal. + return; + default: + if (isFunctionLike(node)) { + var name_3 = node.name; + if (name_3 && name_3.kind === 128 /* ComputedPropertyName */) { + // Note that we will not include methods/accessors of a class because they would require + // first descending into the class. This is by design. + traverse(name_3.expression); + return; + } + } + else if (!isTypeNode(node)) { + // This is the general case, which should include mostly expressions and statements. + // Also includes NodeArrays. + ts.forEachChild(node, traverse); + } + } + } + } + ts.forEachYieldExpression = forEachYieldExpression; function isVariableLike(node) { if (node) { switch (node.kind) { @@ -4586,6 +4860,12 @@ var ts; return false; } ts.isAccessor = isAccessor; + function isClassLike(node) { + if (node) { + return node.kind === 202 /* ClassDeclaration */ || node.kind === 175 /* ClassExpression */; + } + } + ts.isClassLike = isClassLike; function isFunctionLike(node) { if (node) { switch (node.kind) { @@ -4836,6 +5116,7 @@ var ts; case 172 /* TemplateExpression */: case 10 /* NoSubstitutionTemplateLiteral */: case 176 /* OmittedExpression */: + case 173 /* YieldExpression */: return true; case 127 /* QualifiedName */: while (node.parent.kind === 127 /* QualifiedName */) { @@ -4849,8 +5130,8 @@ var ts; // fall through case 7 /* NumericLiteral */: case 8 /* StringLiteral */: - var parent_1 = node.parent; - switch (parent_1.kind) { + var parent_2 = node.parent; + switch (parent_2.kind) { case 199 /* VariableDeclaration */: case 130 /* Parameter */: case 133 /* PropertyDeclaration */: @@ -4858,7 +5139,7 @@ var ts; case 227 /* EnumMember */: case 225 /* PropertyAssignment */: case 153 /* BindingElement */: - return parent_1.initializer === node; + return parent_2.initializer === node; case 183 /* ExpressionStatement */: case 184 /* IfStatement */: case 185 /* DoStatement */: @@ -4869,27 +5150,27 @@ var ts; case 221 /* CaseClause */: case 196 /* ThrowStatement */: case 194 /* SwitchStatement */: - return parent_1.expression === node; + return parent_2.expression === node; case 187 /* ForStatement */: - var forStatement = parent_1; + var forStatement = parent_2; return (forStatement.initializer === node && forStatement.initializer.kind !== 200 /* VariableDeclarationList */) || forStatement.condition === node || forStatement.incrementor === node; case 188 /* ForInStatement */: case 189 /* ForOfStatement */: - var forInStatement = parent_1; + var forInStatement = parent_2; return (forInStatement.initializer === node && forInStatement.initializer.kind !== 200 /* VariableDeclarationList */) || forInStatement.expression === node; case 161 /* TypeAssertionExpression */: - return node === parent_1.expression; + return node === parent_2.expression; case 178 /* TemplateSpan */: - return node === parent_1.expression; + return node === parent_2.expression; case 128 /* ComputedPropertyName */: - return node === parent_1.expression; + return node === parent_2.expression; case 131 /* Decorator */: return true; default: - if (isExpression(parent_1)) { + if (isExpression(parent_2)) { return true; } } @@ -4931,10 +5212,6 @@ var ts; } } ts.getExternalModuleName = getExternalModuleName; - function hasDotDotDotToken(node) { - return node && node.kind === 130 /* Parameter */ && node.dotDotDotToken !== undefined; - } - ts.hasDotDotDotToken = hasDotDotDotToken; function hasQuestionToken(node) { if (node) { switch (node.kind) { @@ -4953,10 +5230,74 @@ var ts; return false; } ts.hasQuestionToken = hasQuestionToken; - function hasRestParameters(s) { - return s.parameters.length > 0 && ts.lastOrUndefined(s.parameters).dotDotDotToken !== undefined; + function isJSDocConstructSignature(node) { + return node.kind === 241 /* JSDocFunctionType */ && + node.parameters.length > 0 && + node.parameters[0].type.kind === 243 /* JSDocConstructorType */; } - ts.hasRestParameters = hasRestParameters; + ts.isJSDocConstructSignature = isJSDocConstructSignature; + function getJSDocTag(node, kind) { + if (node && node.jsDocComment) { + for (var _i = 0, _a = node.jsDocComment.tags; _i < _a.length; _i++) { + var tag = _a[_i]; + if (tag.kind === kind) { + return tag; + } + } + } + } + function getJSDocTypeTag(node) { + return getJSDocTag(node, 249 /* JSDocTypeTag */); + } + ts.getJSDocTypeTag = getJSDocTypeTag; + function getJSDocReturnTag(node) { + return getJSDocTag(node, 248 /* JSDocReturnTag */); + } + ts.getJSDocReturnTag = getJSDocReturnTag; + function getJSDocTemplateTag(node) { + return getJSDocTag(node, 250 /* JSDocTemplateTag */); + } + ts.getJSDocTemplateTag = getJSDocTemplateTag; + function getCorrespondingJSDocParameterTag(parameter) { + if (parameter.name && parameter.name.kind === 65 /* Identifier */) { + // If it's a parameter, see if the parent has a jsdoc comment with an @param + // annotation. + var parameterName = parameter.name.text; + var docComment = parameter.parent.jsDocComment; + if (docComment) { + return ts.forEach(docComment.tags, function (t) { + if (t.kind === 247 /* JSDocParameterTag */) { + var parameterTag = t; + var name_4 = parameterTag.preParameterName || parameterTag.postParameterName; + if (name_4.text === parameterName) { + return t; + } + } + }); + } + } + } + ts.getCorrespondingJSDocParameterTag = getCorrespondingJSDocParameterTag; + function hasRestParameter(s) { + return isRestParameter(ts.lastOrUndefined(s.parameters)); + } + ts.hasRestParameter = hasRestParameter; + function isRestParameter(node) { + if (node) { + if (node.parserContextFlags & 64 /* JavaScriptFile */) { + if (node.type && node.type.kind === 242 /* JSDocVariadicType */) { + return true; + } + var paramTag = getCorrespondingJSDocParameterTag(node); + if (paramTag && paramTag.typeExpression) { + return paramTag.typeExpression.type.kind === 242 /* JSDocVariadicType */; + } + } + return node.dotDotDotToken !== undefined; + } + return false; + } + ts.isRestParameter = isRestParameter; function isLiteralKind(kind) { return 7 /* FirstLiteralToken */ <= kind && kind <= 10 /* LastLiteralToken */; } @@ -5502,7 +5843,7 @@ var ts; if ((isExternalModule(sourceFile) || !compilerOptions.out)) { // 1. in-browser single file compilation scenario // 2. non .js file - return compilerOptions.separateCompilation || !ts.fileExtensionIs(sourceFile.fileName, ".js"); + return compilerOptions.isolatedModules || !ts.fileExtensionIs(sourceFile.fileName, ".js"); } return false; } @@ -5747,6 +6088,10 @@ var ts; return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & 256 /* Default */) ? symbol.valueDeclaration.localSymbol : undefined; } ts.getLocalSymbolForExportDefault = getLocalSymbolForExportDefault; + function isJavaScript(fileName) { + return ts.fileExtensionIs(fileName, ".js"); + } + ts.isJavaScript = isJavaScript; /** * Replace each instance of non-ascii characters by one, two, three, or four escape sequences * representing the UTF-8 encoding of the character, and return the expanded char code list. @@ -6020,12 +6365,22 @@ var ts; return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), newEndN - oldStartN); } ts.collapseTextChangeRangesAcrossMultipleVersions = collapseTextChangeRangesAcrossMultipleVersions; + function getTypeParameterOwner(d) { + if (d && d.kind === 129 /* TypeParameter */) { + for (var current = d; current; current = current.parent) { + if (ts.isFunctionLike(current) || ts.isClassLike(current) || current.kind === 203 /* InterfaceDeclaration */) { + return current; + } + } + } + } + ts.getTypeParameterOwner = getTypeParameterOwner; })(ts || (ts = {})); /// /// var ts; (function (ts) { - var nodeConstructors = new Array(230 /* Count */); + var nodeConstructors = new Array(252 /* Count */); /* @internal */ ts.parseTime = 0; function getNodeConstructor(kind) { return nodeConstructors[kind] || (nodeConstructors[kind] = ts.objectAllocator.getNodeConstructor(kind)); @@ -6335,6 +6690,49 @@ var ts; return visitNode(cbNode, node.expression); case 219 /* MissingDeclaration */: return visitNodes(cbNodes, node.decorators); + case 229 /* JSDocTypeExpression */: + return visitNode(cbNode, node.type); + case 233 /* JSDocUnionType */: + return visitNodes(cbNodes, node.types); + case 234 /* JSDocTupleType */: + return visitNodes(cbNodes, node.types); + case 232 /* JSDocArrayType */: + return visitNode(cbNode, node.elementType); + case 236 /* JSDocNonNullableType */: + return visitNode(cbNode, node.type); + case 235 /* JSDocNullableType */: + return visitNode(cbNode, node.type); + case 237 /* JSDocRecordType */: + return visitNodes(cbNodes, node.members); + case 239 /* JSDocTypeReference */: + return visitNode(cbNode, node.name) || + visitNodes(cbNodes, node.typeArguments); + case 240 /* JSDocOptionalType */: + return visitNode(cbNode, node.type); + case 241 /* JSDocFunctionType */: + return visitNodes(cbNodes, node.parameters) || + visitNode(cbNode, node.type); + case 242 /* JSDocVariadicType */: + return visitNode(cbNode, node.type); + case 243 /* JSDocConstructorType */: + return visitNode(cbNode, node.type); + case 244 /* JSDocThisType */: + return visitNode(cbNode, node.type); + case 238 /* JSDocRecordMember */: + return visitNode(cbNode, node.name) || + visitNode(cbNode, node.type); + case 245 /* JSDocComment */: + return visitNodes(cbNodes, node.tags); + case 247 /* JSDocParameterTag */: + return visitNode(cbNode, node.preParameterName) || + visitNode(cbNode, node.typeExpression) || + visitNode(cbNode, node.postParameterName); + case 248 /* JSDocReturnTag */: + return visitNode(cbNode, node.typeExpression); + case 249 /* JSDocTypeTag */: + return visitNode(cbNode, node.typeExpression); + case 250 /* JSDocTemplateTag */: + return visitNodes(cbNodes, node.typeParameters); } } ts.forEachChild = forEachChild; @@ -6359,6 +6757,17 @@ var ts; return IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks); } ts.updateSourceFile = updateSourceFile; + /* @internal */ + function parseIsolatedJSDocComment(content, start, length) { + return Parser.JSDocParser.parseIsolatedJSDocComment(content, start, length); + } + ts.parseIsolatedJSDocComment = parseIsolatedJSDocComment; + /* @internal */ + // Exposed only for testing. + function parseJSDocTypeExpressionForTests(content, start, length) { + return Parser.JSDocParser.parseJSDocTypeExpressionForTests(content, start, length); + } + ts.parseJSDocTypeExpressionForTests = parseJSDocTypeExpressionForTests; // Implement the parser as a singleton module. We do this for perf reasons because creating // parser instances can actually be expensive enough to impact us on projects with many source // files. @@ -6369,6 +6778,7 @@ var ts; var scanner = ts.createScanner(2 /* Latest */, true); var disallowInAndDecoratorContext = 2 /* DisallowIn */ | 16 /* Decorator */; var sourceFile; + var parseDiagnostics; var syntaxCursor; var token; var sourceText; @@ -6422,7 +6832,7 @@ var ts; // Note: it should not be necessary to save/restore these flags during speculative/lookahead // parsing. These context flags are naturally stored and restored through normal recursive // descent parsing and unwinding. - var contextFlags = 0; + var contextFlags; // Whether or not we've had a parse error since creating the last AST node. If we have // encountered an error, it will be stored on the next AST node we create. Parse errors // can be broken down into three categories: @@ -6451,20 +6861,49 @@ var ts; // Note: any errors at the end of the file that do not precede a regular node, should get // attached to the EOF token. var parseErrorBeforeNextFinishedNode = false; + (function (StatementFlags) { + StatementFlags[StatementFlags["None"] = 0] = "None"; + StatementFlags[StatementFlags["Statement"] = 1] = "Statement"; + StatementFlags[StatementFlags["ModuleElement"] = 2] = "ModuleElement"; + StatementFlags[StatementFlags["StatementOrModuleElement"] = 3] = "StatementOrModuleElement"; + })(Parser.StatementFlags || (Parser.StatementFlags = {})); + var StatementFlags = Parser.StatementFlags; function parseSourceFile(fileName, _sourceText, languageVersion, _syntaxCursor, setParentNodes) { + initializeState(fileName, _sourceText, languageVersion, _syntaxCursor); + var result = parseSourceFileWorker(fileName, languageVersion, setParentNodes); + clearState(); + return result; + } + Parser.parseSourceFile = parseSourceFile; + function initializeState(fileName, _sourceText, languageVersion, _syntaxCursor) { sourceText = _sourceText; syntaxCursor = _syntaxCursor; + parseDiagnostics = []; parsingContext = 0; identifiers = {}; identifierCount = 0; nodeCount = 0; - contextFlags = 0; + contextFlags = ts.isJavaScript(fileName) ? 64 /* JavaScriptFile */ : 0 /* None */; parseErrorBeforeNextFinishedNode = false; - createSourceFile(fileName, languageVersion); // Initialize and prime the scanner before parsing the source elements. scanner.setText(sourceText); scanner.setOnError(scanError); scanner.setScriptTarget(languageVersion); + } + function clearState() { + // Clear out the text the scanner is pointing at, so it doesn't keep anything alive unnecessarily. + scanner.setText(""); + scanner.setOnError(undefined); + // Clear any data. We don't want to accidently hold onto it for too long. + parseDiagnostics = undefined; + sourceFile = undefined; + identifiers = undefined; + syntaxCursor = undefined; + sourceText = undefined; + } + function parseSourceFileWorker(fileName, languageVersion, setParentNodes) { + sourceFile = createSourceFile(fileName, languageVersion); + // Prime the scanner. token = nextToken(); processReferenceComments(sourceFile); sourceFile.statements = parseList(0 /* SourceElements */, true, parseSourceElement); @@ -6474,22 +6913,45 @@ var ts; sourceFile.nodeCount = nodeCount; sourceFile.identifierCount = identifierCount; sourceFile.identifiers = identifiers; + sourceFile.parseDiagnostics = parseDiagnostics; if (setParentNodes) { fixupParentReferences(sourceFile); } - syntaxCursor = undefined; - // Clear out the text the scanner is pointing at, so it doesn't keep anything alive unnecessarily. - scanner.setText(""); - scanner.setOnError(undefined); - var result = sourceFile; - // Clear any data. We don't want to accidently hold onto it for too long. - sourceFile = undefined; - identifiers = undefined; - syntaxCursor = undefined; - sourceText = undefined; - return result; + // If this is a javascript file, proactively see if we can get JSDoc comments for + // relevant nodes in the file. We'll use these to provide typing informaion if they're + // available. + if (ts.isJavaScript(fileName)) { + addJSDocComments(); + } + return sourceFile; + } + function addJSDocComments() { + forEachChild(sourceFile, visit); + return; + function visit(node) { + // Add additional cases as necessary depending on how we see JSDoc comments used + // in the wild. + switch (node.kind) { + case 181 /* VariableStatement */: + case 201 /* FunctionDeclaration */: + case 130 /* Parameter */: + addJSDocComment(node); + } + forEachChild(node, visit); + } + } + function addJSDocComment(node) { + var comments = ts.getLeadingCommentRangesOfNode(node, sourceFile); + if (comments) { + for (var _i = 0; _i < comments.length; _i++) { + var comment = comments[_i]; + var jsDocComment = JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos); + if (jsDocComment) { + node.jsDocComment = jsDocComment; + } + } + } } - Parser.parseSourceFile = parseSourceFile; function fixupParentReferences(sourceFile) { // normally parent references are set during binding. However, for clients that only need // a syntax tree, and no semantic features, then the binding process is an unnecessary @@ -6511,16 +6973,17 @@ var ts; } } } + Parser.fixupParentReferences = fixupParentReferences; function createSourceFile(fileName, languageVersion) { - sourceFile = createNode(228 /* SourceFile */, 0); + var sourceFile = createNode(228 /* SourceFile */, 0); sourceFile.pos = 0; sourceFile.end = sourceText.length; sourceFile.text = sourceText; - sourceFile.parseDiagnostics = []; sourceFile.bindDiagnostics = []; sourceFile.languageVersion = languageVersion; sourceFile.fileName = ts.normalizePath(fileName); sourceFile.flags = ts.fileExtensionIs(sourceFile.fileName, ".d.ts") ? 2048 /* DeclarationFile */ : 0; + return sourceFile; } function setContextFlag(val, flag) { if (val) { @@ -6628,9 +7091,9 @@ var ts; } function parseErrorAtPosition(start, length, message, arg0) { // Don't report another error if it would just be at the same position as the last error. - var lastError = ts.lastOrUndefined(sourceFile.parseDiagnostics); + var lastError = ts.lastOrUndefined(parseDiagnostics); if (!lastError || start !== lastError.start) { - sourceFile.parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, start, length, message, arg0)); + parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, start, length, message, arg0)); } // Mark that we've encountered an error. We'll set an appropriate bit on the next // node we finish so that it can't be reused incrementally. @@ -6665,7 +7128,7 @@ var ts; // Keep track of the state we'll need to rollback to if lookahead fails (or if the // caller asked us to always reset our state). var saveToken = token; - var saveParseDiagnosticsLength = sourceFile.parseDiagnostics.length; + var saveParseDiagnosticsLength = parseDiagnostics.length; var saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; // Note: it is not actually necessary to save/restore the context flags here. That's // because the saving/restorating of these flags happens naturally through the recursive @@ -6683,7 +7146,7 @@ var ts; // then unconditionally restore us to where we were. if (!result || isLookAhead) { token = saveToken; - sourceFile.parseDiagnostics.length = saveParseDiagnosticsLength; + parseDiagnostics.length = saveParseDiagnosticsLength; parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode; } return result; @@ -6779,8 +7242,8 @@ var ts; node.end = pos; return node; } - function finishNode(node) { - node.end = scanner.getStartPos(); + function finishNode(node, end) { + node.end = end === undefined ? scanner.getStartPos() : end; if (contextFlags) { node.parserContextFlags = contextFlags; } @@ -6836,15 +7299,24 @@ var ts; token === 8 /* StringLiteral */ || token === 7 /* NumericLiteral */; } - function parsePropertyName() { + function parsePropertyNameWorker(allowComputedPropertyNames) { if (token === 8 /* StringLiteral */ || token === 7 /* NumericLiteral */) { return parseLiteralNode(true); } - if (token === 18 /* OpenBracketToken */) { + if (allowComputedPropertyNames && token === 18 /* OpenBracketToken */) { return parseComputedPropertyName(); } return parseIdentifierName(); } + function parsePropertyName() { + return parsePropertyNameWorker(true); + } + function parseSimplePropertyName() { + return parsePropertyNameWorker(false); + } + function isSimplePropertyName() { + return token === 8 /* StringLiteral */ || token === 7 /* NumericLiteral */ || isIdentifierOrKeyword(); + } function parseComputedPropertyName() { // PropertyName[Yield,GeneratorParameter] : // LiteralPropertyName @@ -6913,10 +7385,17 @@ var ts; switch (parsingContext) { case 0 /* SourceElements */: case 1 /* ModuleElements */: - return isSourceElement(inErrorRecovery); + // If we're in error recovery, then we don't want to treat ';' as an empty statement. + // The problem is that ';' can show up in far too many contexts, and if we see one + // and assume it's a statement, then we may bail out inappropriately from whatever + // we're parsing. For example, if we have a semicolon in the middle of a class, then + // we really don't want to assume the class is over and we're on a statement in the + // outer module. We just want to consume and move on. + return !(token === 22 /* SemicolonToken */ && inErrorRecovery) && isStartOfModuleElement(); case 2 /* BlockStatements */: case 4 /* SwitchClauseStatements */: - return isStartOfStatement(inErrorRecovery); + // During error recovery we don't treat empty statements as statements + return !(token === 22 /* SemicolonToken */ && inErrorRecovery) && isStartOfStatement(); case 3 /* SwitchClauses */: return token === 67 /* CaseKeyword */ || token === 73 /* DefaultKeyword */; case 5 /* TypeMembers */: @@ -6968,6 +7447,12 @@ var ts; return isHeritageClause(); case 20 /* ImportOrExportSpecifiers */: return isIdentifierOrKeyword(); + case 21 /* JSDocFunctionParameters */: + case 22 /* JSDocTypeArguments */: + case 24 /* JSDocTupleTypes */: + return JSDocParser.isJSDocType(); + case 23 /* JSDocRecordMembers */: + return isSimplePropertyName(); } ts.Debug.fail("Non-exhaustive case in 'isListElement'."); } @@ -7042,6 +7527,14 @@ var ts; return token === 25 /* GreaterThanToken */ || token === 16 /* OpenParenToken */; case 19 /* HeritageClauses */: return token === 14 /* OpenBraceToken */ || token === 15 /* CloseBraceToken */; + case 21 /* JSDocFunctionParameters */: + return token === 17 /* CloseParenToken */ || token === 51 /* ColonToken */ || token === 15 /* CloseBraceToken */; + case 22 /* JSDocTypeArguments */: + return token === 25 /* GreaterThanToken */ || token === 15 /* CloseBraceToken */; + case 24 /* JSDocTupleTypes */: + return token === 19 /* CloseBracketToken */ || token === 15 /* CloseBraceToken */; + case 23 /* JSDocRecordMembers */: + return token === 15 /* CloseBraceToken */; } } function isVariableDeclaratorListTerminator() { @@ -7067,7 +7560,7 @@ var ts; } // True if positioned at element or terminator of the current list or any enclosing list function isInSomeParsingContext() { - for (var kind = 0; kind < 21 /* Count */; kind++) { + for (var kind = 0; kind < 25 /* Count */; kind++) { if (parsingContext & (1 << kind)) { if (isListElement(kind, true) || isListTerminator(kind)) { return true; @@ -7090,7 +7583,7 @@ var ts; // test elements only if we are not already in strict mode if (checkForStrictMode && !inStrictModeContext()) { if (ts.isPrologueDirective(element)) { - if (isUseStrictPrologueDirective(sourceFile, element)) { + if (isUseStrictPrologueDirective(element)) { setStrictModeContext(true); checkForStrictMode = false; } @@ -7111,9 +7604,9 @@ var ts; return result; } /// Should be called only on prologue directives (isPrologueDirective(node) should be true) - function isUseStrictPrologueDirective(sourceFile, node) { + function isUseStrictPrologueDirective(node) { ts.Debug.assert(ts.isPrologueDirective(node)); - var nodeText = ts.getSourceTextOfNodeFromSourceFile(sourceFile, node.expression); + var nodeText = ts.getTextOfNodeFromSourceText(sourceText, node.expression); // Note: the node text must be exactly "use strict" or 'use strict'. It is not ok for the // string to contain unicode escapes (as per ES5). return nodeText === '"use strict"' || nodeText === "'use strict'"; @@ -7386,6 +7879,10 @@ var ts; case 18 /* TupleElementTypes */: return ts.Diagnostics.Type_expected; case 19 /* HeritageClauses */: return ts.Diagnostics.Unexpected_token_expected; case 20 /* ImportOrExportSpecifiers */: return ts.Diagnostics.Identifier_expected; + case 21 /* JSDocFunctionParameters */: return ts.Diagnostics.Parameter_declaration_expected; + case 22 /* JSDocTypeArguments */: return ts.Diagnostics.Type_argument_expected; + case 24 /* JSDocTupleTypes */: return ts.Diagnostics.Type_expected; + case 23 /* JSDocRecordMembers */: return ts.Diagnostics.Property_assignment_expected; } } ; @@ -8245,11 +8742,6 @@ var ts; nextToken(); return !scanner.hasPrecedingLineBreak() && isIdentifier(); } - function nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine() { - nextToken(); - return !scanner.hasPrecedingLineBreak() && - (isIdentifier() || token === 14 /* OpenBraceToken */ || token === 18 /* OpenBracketToken */); - } function parseYieldExpression() { var node = createNode(173 /* YieldExpression */); // YieldExpression[In] : @@ -8421,10 +8913,11 @@ var ts; if (token === 14 /* OpenBraceToken */) { return parseFunctionBlock(false, false); } - if (isStartOfStatement(true) && - !isStartOfExpressionStatement() && + if (token !== 22 /* SemicolonToken */ && token !== 83 /* FunctionKeyword */ && - token !== 69 /* ClassKeyword */) { + token !== 69 /* ClassKeyword */ && + isStartOfStatement() && + !isStartOfExpressionStatement()) { // Check if we got a plain statement (i.e. no expression-statements, no function/class expressions/declarations) // // Here we try to recover from a potential error situation in the case where the @@ -9213,33 +9706,68 @@ var ts; return finishNode(expressionStatement); } } - function isStartOfStatement(inErrorRecovery) { - // Functions, variable statements and classes are allowed as a statement. But as per - // the grammar, they also allow modifiers. So we have to check for those statements - // that might be following modifiers.This ensures that things work properly when - // incrementally parsing as the parser will produce the same FunctionDeclaraiton, - // VariableStatement or ClassDeclaration, if it has the same text regardless of whether - // it is inside a block or not. - if (ts.isModifier(token)) { - var result = lookAhead(parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers); - if (result) { - return true; + function isIdentifierOrKeyword() { + return token >= 65 /* Identifier */; + } + function nextTokenIsIdentifierOrKeywordOnSameLine() { + nextToken(); + return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak(); + } + function parseDeclarationFlags() { + while (true) { + switch (token) { + case 98 /* VarKeyword */: + case 104 /* LetKeyword */: + case 70 /* ConstKeyword */: + case 83 /* FunctionKeyword */: + case 69 /* ClassKeyword */: + case 77 /* EnumKeyword */: + return 1 /* Statement */; + case 103 /* InterfaceKeyword */: + case 124 /* TypeKeyword */: + nextToken(); + return isIdentifierOrKeyword() ? 1 /* Statement */ : 0 /* None */; + case 117 /* ModuleKeyword */: + case 118 /* NamespaceKeyword */: + nextToken(); + return isIdentifierOrKeyword() || token === 8 /* StringLiteral */ ? 2 /* ModuleElement */ : 0 /* None */; + case 85 /* ImportKeyword */: + nextToken(); + return token === 8 /* StringLiteral */ || token === 35 /* AsteriskToken */ || + token === 14 /* OpenBraceToken */ || isIdentifierOrKeyword() ? + 2 /* ModuleElement */ : 0 /* None */; + case 78 /* ExportKeyword */: + nextToken(); + if (token === 53 /* EqualsToken */ || token === 35 /* AsteriskToken */ || + token === 14 /* OpenBraceToken */ || token === 73 /* DefaultKeyword */) { + return 2 /* ModuleElement */; + } + continue; + case 115 /* DeclareKeyword */: + case 108 /* PublicKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: + case 109 /* StaticKeyword */: + nextToken(); + continue; + default: + return 0 /* None */; } } + } + function getDeclarationFlags() { + return lookAhead(parseDeclarationFlags); + } + function getStatementFlags() { switch (token) { + case 52 /* AtToken */: case 22 /* SemicolonToken */: - // If we're in error recovery, then we don't want to treat ';' as an empty statement. - // The problem is that ';' can show up in far too many contexts, and if we see one - // and assume it's a statement, then we may bail out inappropriately from whatever - // we're parsing. For example, if we have a semicolon in the middle of a class, then - // we really don't want to assume the class is over and we're on a statement in the - // outer module. We just want to consume and move on. - return !inErrorRecovery; case 14 /* OpenBraceToken */: case 98 /* VarKeyword */: case 104 /* LetKeyword */: case 83 /* FunctionKeyword */: case 69 /* ClassKeyword */: + case 77 /* EnumKeyword */: case 84 /* IfKeyword */: case 75 /* DoKeyword */: case 100 /* WhileKeyword */: @@ -9256,58 +9784,72 @@ var ts; // however, we say they are here so that we may gracefully parse them and error later. case 68 /* CatchKeyword */: case 81 /* FinallyKeyword */: - return true; + return 1 /* Statement */; case 70 /* ConstKeyword */: - // const keyword can precede enum keyword when defining constant enums - // 'const enum' do not start statement. - // In ES 6 'enum' is a future reserved keyword, so it should not be used as identifier - var isConstEnum = lookAhead(nextTokenIsEnumKeyword); - return !isConstEnum; + case 78 /* ExportKeyword */: + case 85 /* ImportKeyword */: + return getDeclarationFlags(); + case 115 /* DeclareKeyword */: case 103 /* InterfaceKeyword */: case 117 /* ModuleKeyword */: case 118 /* NamespaceKeyword */: - case 77 /* EnumKeyword */: case 124 /* TypeKeyword */: - // When followed by an identifier, these do not start a statement but might - // instead be following declarations - if (isDeclarationStart()) { - return false; - } + // When these don't start a declaration, they're an identifier in an expression statement + return getDeclarationFlags() || 1 /* Statement */; case 108 /* PublicKeyword */: case 106 /* PrivateKeyword */: case 107 /* ProtectedKeyword */: case 109 /* StaticKeyword */: - // When followed by an identifier or keyword, these do not start a statement but - // might instead be following type members - if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine)) { - return false; - } + // When these don't start a declaration, they may be the start of a class member if an identifier + // immediately follows. Otherwise they're an identifier in an expression statement. + return getDeclarationFlags() || + (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine) ? 0 /* None */ : 1 /* Statement */); default: - return isStartOfExpression(); + return isStartOfExpression() ? 1 /* Statement */ : 0 /* None */; } } - function nextTokenIsEnumKeyword() { - nextToken(); - return token === 77 /* EnumKeyword */; + function isStartOfStatement() { + return (getStatementFlags() & 1 /* Statement */) !== 0; } - function nextTokenIsIdentifierOrKeywordOnSameLine() { + function isStartOfModuleElement() { + return (getStatementFlags() & 3 /* StatementOrModuleElement */) !== 0; + } + function nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine() { nextToken(); - return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak(); + return !scanner.hasPrecedingLineBreak() && + (isIdentifier() || token === 14 /* OpenBraceToken */ || token === 18 /* OpenBracketToken */); + } + function isLetDeclaration() { + // It is let declaration if in strict mode or next token is identifier\open bracket\open curly on same line. + // otherwise it needs to be treated like identifier + return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine); } function parseStatement() { + return parseModuleElementOfKind(1 /* Statement */); + } + function parseModuleElement() { + return parseModuleElementOfKind(3 /* StatementOrModuleElement */); + } + function parseSourceElement() { + return parseModuleElementOfKind(3 /* StatementOrModuleElement */); + } + function parseModuleElementOfKind(flags) { switch (token) { + case 22 /* SemicolonToken */: + return parseEmptyStatement(); case 14 /* OpenBraceToken */: return parseBlock(false, false); case 98 /* VarKeyword */: - case 70 /* ConstKeyword */: - // const here should always be parsed as const declaration because of check in 'isStatement' return parseVariableStatement(scanner.getStartPos(), undefined, undefined); + case 104 /* LetKeyword */: + if (isLetDeclaration()) { + return parseVariableStatement(scanner.getStartPos(), undefined, undefined); + } + break; case 83 /* FunctionKeyword */: return parseFunctionDeclaration(scanner.getStartPos(), undefined, undefined); case 69 /* ClassKeyword */: return parseClassDeclaration(scanner.getStartPos(), undefined, undefined); - case 22 /* SemicolonToken */: - return parseEmptyStatement(); case 84 /* IfKeyword */: return parseIfStatement(); case 75 /* DoKeyword */: @@ -9335,54 +9877,68 @@ var ts; return parseTryStatement(); case 72 /* DebuggerKeyword */: return parseDebuggerStatement(); - case 104 /* LetKeyword */: - // If let follows identifier on the same line, it is declaration parse it as variable statement - if (isLetDeclaration()) { - return parseVariableStatement(scanner.getStartPos(), undefined, undefined); + case 52 /* AtToken */: + return parseDeclaration(); + case 70 /* ConstKeyword */: + case 115 /* DeclareKeyword */: + case 77 /* EnumKeyword */: + case 78 /* ExportKeyword */: + case 85 /* ImportKeyword */: + case 103 /* InterfaceKeyword */: + case 117 /* ModuleKeyword */: + case 118 /* NamespaceKeyword */: + case 106 /* PrivateKeyword */: + case 107 /* ProtectedKeyword */: + case 108 /* PublicKeyword */: + case 109 /* StaticKeyword */: + case 124 /* TypeKeyword */: + if (getDeclarationFlags() & flags) { + return parseDeclaration(); } - // Else parse it like identifier - fall through - default: - // Functions and variable statements are allowed as a statement. But as per - // the grammar, they also allow modifiers. So we have to check for those - // statements that might be following modifiers. This ensures that things - // work properly when incrementally parsing as the parser will produce the - // same FunctionDeclaraiton or VariableStatement if it has the same text - // regardless of whether it is inside a block or not. - // Even though variable statements and function declarations cannot have decorators, - // we parse them here to provide better error recovery. - if (ts.isModifier(token) || token === 52 /* AtToken */) { - var result = tryParse(parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers); - if (result) { - return result; - } - } - return parseExpressionOrLabeledStatement(); + break; } + return parseExpressionOrLabeledStatement(); } - function parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers() { - var start = scanner.getStartPos(); + function parseDeclaration() { + var fullStart = getNodePos(); var decorators = parseDecorators(); var modifiers = parseModifiers(); switch (token) { - case 70 /* ConstKeyword */: - var nextTokenIsEnum = lookAhead(nextTokenIsEnumKeyword); - if (nextTokenIsEnum) { - return undefined; - } - return parseVariableStatement(start, decorators, modifiers); - case 104 /* LetKeyword */: - if (!isLetDeclaration()) { - return undefined; - } - return parseVariableStatement(start, decorators, modifiers); case 98 /* VarKeyword */: - return parseVariableStatement(start, decorators, modifiers); + case 104 /* LetKeyword */: + case 70 /* ConstKeyword */: + return parseVariableStatement(fullStart, decorators, modifiers); case 83 /* FunctionKeyword */: - return parseFunctionDeclaration(start, decorators, modifiers); + return parseFunctionDeclaration(fullStart, decorators, modifiers); case 69 /* ClassKeyword */: - return parseClassDeclaration(start, decorators, modifiers); + return parseClassDeclaration(fullStart, decorators, modifiers); + case 103 /* InterfaceKeyword */: + return parseInterfaceDeclaration(fullStart, decorators, modifiers); + case 124 /* TypeKeyword */: + return parseTypeAliasDeclaration(fullStart, decorators, modifiers); + case 77 /* EnumKeyword */: + return parseEnumDeclaration(fullStart, decorators, modifiers); + case 117 /* ModuleKeyword */: + case 118 /* NamespaceKeyword */: + return parseModuleDeclaration(fullStart, decorators, modifiers); + case 85 /* ImportKeyword */: + return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); + case 78 /* ExportKeyword */: + nextToken(); + return token === 73 /* DefaultKeyword */ || token === 53 /* EqualsToken */ ? + parseExportAssignment(fullStart, decorators, modifiers) : + parseExportDeclaration(fullStart, decorators, modifiers); + default: + if (decorators) { + // We reached this point because we encountered decorators and/or modifiers and assumed a declaration + // would follow. For recovery and error reporting purposes, return an incomplete declaration. + var node = createMissingNode(219 /* MissingDeclaration */, true, ts.Diagnostics.Declaration_expected); + node.pos = fullStart; + node.decorators = decorators; + setModifiers(node, modifiers); + return finishNode(node); + } } - return undefined; } function parseFunctionBlockOrSemicolon(isGenerator, diagnosticMessage) { if (token !== 14 /* OpenBraceToken */ && canParseSemicolon()) { @@ -9537,7 +10093,18 @@ var ts; property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); - property.initializer = allowInAnd(parseNonParameterInitializer); + // For instance properties specifically, since they are evaluated inside the constructor, + // we do *not * want to parse yield expressions, so we specifically turn the yield context + // off. The grammar would look something like this: + // + // MemberVariableDeclaration[Yield]: + // AccessibilityModifier_opt PropertyName TypeAnnotation_opt Initialiser_opt[In]; + // AccessibilityModifier_opt static_opt PropertyName TypeAnnotation_opt Initialiser_opt[In, ?Yield]; + // + // The checker may still error in the static case to explicitly disallow the yield expression. + property.initializer = modifiers && modifiers.flags & 128 /* Static */ + ? allowInAnd(parseNonParameterInitializer) + : doOutsideOfContext(4 /* Yield */ | 2 /* DisallowIn */, parseNonParameterInitializer); parseSemicolon(); return finishNode(property); } @@ -9707,17 +10274,17 @@ var ts; } if (decorators) { // treat this as a property declaration with a missing name. - var name_3 = createMissingNode(65 /* Identifier */, true, ts.Diagnostics.Declaration_expected); - return parsePropertyDeclaration(fullStart, decorators, modifiers, name_3, undefined); + var name_5 = createMissingNode(65 /* Identifier */, true, ts.Diagnostics.Declaration_expected); + return parsePropertyDeclaration(fullStart, decorators, modifiers, name_5, undefined); } // 'isClassMemberStart' should have hinted not to attempt parsing. ts.Debug.fail("Should not have attempted to parse class member declaration."); } function parseClassExpression() { return parseClassDeclarationOrExpression( - /*fullStart:*/ scanner.getStartPos(), - /*decorators:*/ undefined, - /*modifiers:*/ undefined, 175 /* ClassExpression */); + /*fullStart*/ scanner.getStartPos(), + /*decorators*/ undefined, + /*modifiers*/ undefined, 175 /* ClassExpression */); } function parseClassDeclaration(fullStart, decorators, modifiers) { return parseClassDeclarationOrExpression(fullStart, decorators, modifiers, 202 /* ClassDeclaration */); @@ -10059,136 +10626,6 @@ var ts; parseSemicolon(); return finishNode(node); } - function isLetDeclaration() { - // It is let declaration if in strict mode or next token is identifier\open bracket\open curly on same line. - // otherwise it needs to be treated like identifier - return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine); - } - function isDeclarationStart(followsModifier) { - switch (token) { - case 98 /* VarKeyword */: - case 70 /* ConstKeyword */: - case 83 /* FunctionKeyword */: - return true; - case 104 /* LetKeyword */: - return isLetDeclaration(); - case 69 /* ClassKeyword */: - case 103 /* InterfaceKeyword */: - case 77 /* EnumKeyword */: - case 124 /* TypeKeyword */: - // Not true keywords so ensure an identifier follows - return lookAhead(nextTokenIsIdentifierOrKeyword); - case 85 /* ImportKeyword */: - // Not true keywords so ensure an identifier follows or is string literal or asterisk or open brace - return lookAhead(nextTokenCanFollowImportKeyword); - case 117 /* ModuleKeyword */: - case 118 /* NamespaceKeyword */: - // Not a true keyword so ensure an identifier or string literal follows - return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral); - case 78 /* ExportKeyword */: - // Check for export assignment or modifier on source element - return lookAhead(nextTokenCanFollowExportKeyword); - case 115 /* DeclareKeyword */: - case 108 /* PublicKeyword */: - case 106 /* PrivateKeyword */: - case 107 /* ProtectedKeyword */: - case 109 /* StaticKeyword */: - // Check for modifier on source element - return lookAhead(nextTokenIsDeclarationStart); - case 52 /* AtToken */: - // a lookahead here is too costly, and decorators are only valid on a declaration. - // We will assume we are parsing a declaration here and report an error later - return !followsModifier; - } - } - function isIdentifierOrKeyword() { - return token >= 65 /* Identifier */; - } - function nextTokenIsIdentifierOrKeyword() { - nextToken(); - return isIdentifierOrKeyword(); - } - function nextTokenIsIdentifierOrKeywordOrStringLiteral() { - nextToken(); - return isIdentifierOrKeyword() || token === 8 /* StringLiteral */; - } - function nextTokenCanFollowImportKeyword() { - nextToken(); - return isIdentifierOrKeyword() || token === 8 /* StringLiteral */ || - token === 35 /* AsteriskToken */ || token === 14 /* OpenBraceToken */; - } - function nextTokenCanFollowExportKeyword() { - nextToken(); - return token === 53 /* EqualsToken */ || token === 35 /* AsteriskToken */ || - token === 14 /* OpenBraceToken */ || token === 73 /* DefaultKeyword */ || isDeclarationStart(true); - } - function nextTokenIsDeclarationStart() { - nextToken(); - return isDeclarationStart(true); - } - function nextTokenIsAsKeyword() { - return nextToken() === 111 /* AsKeyword */; - } - function parseDeclaration() { - var fullStart = getNodePos(); - var decorators = parseDecorators(); - var modifiers = parseModifiers(); - if (token === 78 /* ExportKeyword */) { - nextToken(); - if (token === 73 /* DefaultKeyword */ || token === 53 /* EqualsToken */) { - return parseExportAssignment(fullStart, decorators, modifiers); - } - if (token === 35 /* AsteriskToken */ || token === 14 /* OpenBraceToken */) { - return parseExportDeclaration(fullStart, decorators, modifiers); - } - } - switch (token) { - case 98 /* VarKeyword */: - case 104 /* LetKeyword */: - case 70 /* ConstKeyword */: - return parseVariableStatement(fullStart, decorators, modifiers); - case 83 /* FunctionKeyword */: - return parseFunctionDeclaration(fullStart, decorators, modifiers); - case 69 /* ClassKeyword */: - return parseClassDeclaration(fullStart, decorators, modifiers); - case 103 /* InterfaceKeyword */: - return parseInterfaceDeclaration(fullStart, decorators, modifiers); - case 124 /* TypeKeyword */: - return parseTypeAliasDeclaration(fullStart, decorators, modifiers); - case 77 /* EnumKeyword */: - return parseEnumDeclaration(fullStart, decorators, modifiers); - case 117 /* ModuleKeyword */: - case 118 /* NamespaceKeyword */: - return parseModuleDeclaration(fullStart, decorators, modifiers); - case 85 /* ImportKeyword */: - return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); - default: - if (decorators) { - // We reached this point because we encountered an AtToken and assumed a declaration would - // follow. For recovery and error reporting purposes, return an incomplete declaration. - var node = createMissingNode(219 /* MissingDeclaration */, true, ts.Diagnostics.Declaration_expected); - node.pos = fullStart; - node.decorators = decorators; - setModifiers(node, modifiers); - return finishNode(node); - } - ts.Debug.fail("Mismatch between isDeclarationStart and parseDeclaration"); - } - } - function isSourceElement(inErrorRecovery) { - return isDeclarationStart() || isStartOfStatement(inErrorRecovery); - } - function parseSourceElement() { - return parseSourceElementOrModuleElement(); - } - function parseModuleElement() { - return parseSourceElementOrModuleElement(); - } - function parseSourceElementOrModuleElement() { - return isDeclarationStart() - ? parseDeclaration() - : parseStatement(); - } function processReferenceComments(sourceFile) { var triviaScanner = ts.createScanner(sourceFile.languageVersion, false, sourceText); var referencedFiles = []; @@ -10216,7 +10653,7 @@ var ts; referencedFiles.push(fileReference); } if (diagnosticMessage) { - sourceFile.parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage)); + parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage)); } } else { @@ -10224,7 +10661,7 @@ var ts; var amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment); if (amdModuleNameMatchResult) { if (amdModuleName) { - sourceFile.parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, ts.Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments)); + parseDiagnostics.push(ts.createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, ts.Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments)); } amdModuleName = amdModuleNameMatchResult[2]; } @@ -10280,7 +10717,11 @@ var ts; ParsingContext[ParsingContext["TupleElementTypes"] = 18] = "TupleElementTypes"; ParsingContext[ParsingContext["HeritageClauses"] = 19] = "HeritageClauses"; ParsingContext[ParsingContext["ImportOrExportSpecifiers"] = 20] = "ImportOrExportSpecifiers"; - ParsingContext[ParsingContext["Count"] = 21] = "Count"; // Number of parsing contexts + ParsingContext[ParsingContext["JSDocFunctionParameters"] = 21] = "JSDocFunctionParameters"; + ParsingContext[ParsingContext["JSDocTypeArguments"] = 22] = "JSDocTypeArguments"; + ParsingContext[ParsingContext["JSDocRecordMembers"] = 23] = "JSDocRecordMembers"; + ParsingContext[ParsingContext["JSDocTupleTypes"] = 24] = "JSDocTupleTypes"; + ParsingContext[ParsingContext["Count"] = 25] = "Count"; // Number of parsing contexts })(ParsingContext || (ParsingContext = {})); var Tristate; (function (Tristate) { @@ -10288,6 +10729,546 @@ var ts; Tristate[Tristate["True"] = 1] = "True"; Tristate[Tristate["Unknown"] = 2] = "Unknown"; })(Tristate || (Tristate = {})); + var JSDocParser; + (function (JSDocParser) { + function isJSDocType() { + switch (token) { + case 35 /* AsteriskToken */: + case 50 /* QuestionToken */: + case 16 /* OpenParenToken */: + case 18 /* OpenBracketToken */: + case 46 /* ExclamationToken */: + case 14 /* OpenBraceToken */: + case 83 /* FunctionKeyword */: + case 21 /* DotDotDotToken */: + case 88 /* NewKeyword */: + case 93 /* ThisKeyword */: + return true; + } + return isIdentifierOrKeyword(); + } + JSDocParser.isJSDocType = isJSDocType; + function parseJSDocTypeExpressionForTests(content, start, length) { + initializeState("file.js", content, 2 /* Latest */, undefined); + var jsDocTypeExpression = parseJSDocTypeExpression(start, length); + var diagnostics = parseDiagnostics; + clearState(); + return jsDocTypeExpression ? { jsDocTypeExpression: jsDocTypeExpression, diagnostics: diagnostics } : undefined; + } + JSDocParser.parseJSDocTypeExpressionForTests = parseJSDocTypeExpressionForTests; + // Parses out a JSDoc type expression. The starting position should be right at the open + // curly in the type expression. Returns 'undefined' if it encounters any errors while parsing. + /* @internal */ + function parseJSDocTypeExpression(start, length) { + scanner.setText(sourceText, start, length); + // Prime the first token for us to start processing. + token = nextToken(); + var result = createNode(229 /* JSDocTypeExpression */); + parseExpected(14 /* OpenBraceToken */); + result.type = parseJSDocTopLevelType(); + parseExpected(15 /* CloseBraceToken */); + fixupParentReferences(result); + return finishNode(result); + } + JSDocParser.parseJSDocTypeExpression = parseJSDocTypeExpression; + function parseJSDocTopLevelType() { + var type = parseJSDocType(); + if (token === 44 /* BarToken */) { + var unionType = createNode(233 /* JSDocUnionType */, type.pos); + unionType.types = parseJSDocTypeList(type); + type = finishNode(unionType); + } + if (token === 53 /* EqualsToken */) { + var optionalType = createNode(240 /* JSDocOptionalType */, type.pos); + nextToken(); + optionalType.type = type; + type = finishNode(optionalType); + } + return type; + } + function parseJSDocType() { + var type = parseBasicTypeExpression(); + while (true) { + if (token === 18 /* OpenBracketToken */) { + var arrayType = createNode(232 /* JSDocArrayType */, type.pos); + arrayType.elementType = type; + nextToken(); + parseExpected(19 /* CloseBracketToken */); + type = finishNode(arrayType); + } + else if (token === 50 /* QuestionToken */) { + var nullableType = createNode(235 /* JSDocNullableType */, type.pos); + nullableType.type = type; + nextToken(); + type = finishNode(nullableType); + } + else if (token === 46 /* ExclamationToken */) { + var nonNullableType = createNode(236 /* JSDocNonNullableType */, type.pos); + nonNullableType.type = type; + nextToken(); + type = finishNode(nonNullableType); + } + else { + break; + } + } + return type; + } + function parseBasicTypeExpression() { + switch (token) { + case 35 /* AsteriskToken */: + return parseJSDocAllType(); + case 50 /* QuestionToken */: + return parseJSDocUnknownOrNullableType(); + case 16 /* OpenParenToken */: + return parseJSDocUnionType(); + case 18 /* OpenBracketToken */: + return parseJSDocTupleType(); + case 46 /* ExclamationToken */: + return parseJSDocNonNullableType(); + case 14 /* OpenBraceToken */: + return parseJSDocRecordType(); + case 83 /* FunctionKeyword */: + return parseJSDocFunctionType(); + case 21 /* DotDotDotToken */: + return parseJSDocVariadicType(); + case 88 /* NewKeyword */: + return parseJSDocConstructorType(); + case 93 /* ThisKeyword */: + return parseJSDocThisType(); + case 112 /* AnyKeyword */: + case 122 /* StringKeyword */: + case 120 /* NumberKeyword */: + case 113 /* BooleanKeyword */: + case 123 /* SymbolKeyword */: + case 99 /* VoidKeyword */: + return parseTokenNode(); + } + return parseJSDocTypeReference(); + } + function parseJSDocThisType() { + var result = createNode(244 /* JSDocThisType */); + nextToken(); + parseExpected(51 /* ColonToken */); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocConstructorType() { + var result = createNode(243 /* JSDocConstructorType */); + nextToken(); + parseExpected(51 /* ColonToken */); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocVariadicType() { + var result = createNode(242 /* JSDocVariadicType */); + nextToken(); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocFunctionType() { + var result = createNode(241 /* JSDocFunctionType */); + nextToken(); + parseExpected(16 /* OpenParenToken */); + result.parameters = parseDelimitedList(21 /* JSDocFunctionParameters */, parseJSDocParameter); + checkForTrailingComma(result.parameters); + parseExpected(17 /* CloseParenToken */); + if (token === 51 /* ColonToken */) { + nextToken(); + result.type = parseJSDocType(); + } + return finishNode(result); + } + function parseJSDocParameter() { + var parameter = createNode(130 /* Parameter */); + parameter.type = parseJSDocType(); + return finishNode(parameter); + } + function parseJSDocOptionalType(type) { + var result = createNode(240 /* JSDocOptionalType */, type.pos); + nextToken(); + result.type = type; + return finishNode(result); + } + function parseJSDocTypeReference() { + var result = createNode(239 /* JSDocTypeReference */); + result.name = parseSimplePropertyName(); + while (parseOptional(20 /* DotToken */)) { + if (token === 24 /* LessThanToken */) { + result.typeArguments = parseTypeArguments(); + break; + } + else { + result.name = parseQualifiedName(result.name); + } + } + return finishNode(result); + } + function parseTypeArguments() { + // Move past the < + nextToken(); + var typeArguments = parseDelimitedList(22 /* JSDocTypeArguments */, parseJSDocType); + checkForTrailingComma(typeArguments); + checkForEmptyTypeArgumentList(typeArguments); + parseExpected(25 /* GreaterThanToken */); + return typeArguments; + } + function checkForEmptyTypeArgumentList(typeArguments) { + if (parseDiagnostics.length === 0 && typeArguments && typeArguments.length === 0) { + var start = typeArguments.pos - "<".length; + var end = ts.skipTrivia(sourceText, typeArguments.end) + ">".length; + return parseErrorAtPosition(start, end - start, ts.Diagnostics.Type_argument_list_cannot_be_empty); + } + } + function parseQualifiedName(left) { + var result = createNode(127 /* QualifiedName */, left.pos); + result.left = left; + result.right = parseIdentifierName(); + return finishNode(result); + } + function parseJSDocRecordType() { + var result = createNode(237 /* JSDocRecordType */); + nextToken(); + result.members = parseDelimitedList(23 /* JSDocRecordMembers */, parseJSDocRecordMember); + checkForTrailingComma(result.members); + parseExpected(15 /* CloseBraceToken */); + return finishNode(result); + } + function parseJSDocRecordMember() { + var result = createNode(238 /* JSDocRecordMember */); + result.name = parseSimplePropertyName(); + if (token === 51 /* ColonToken */) { + nextToken(); + result.type = parseJSDocType(); + } + return finishNode(result); + } + function parseJSDocNonNullableType() { + var result = createNode(236 /* JSDocNonNullableType */); + nextToken(); + result.type = parseJSDocType(); + return finishNode(result); + } + function parseJSDocTupleType() { + var result = createNode(234 /* JSDocTupleType */); + nextToken(); + result.types = parseDelimitedList(24 /* JSDocTupleTypes */, parseJSDocType); + checkForTrailingComma(result.types); + parseExpected(19 /* CloseBracketToken */); + return finishNode(result); + } + function checkForTrailingComma(list) { + if (parseDiagnostics.length === 0 && list.hasTrailingComma) { + var start = list.end - ",".length; + parseErrorAtPosition(start, ",".length, ts.Diagnostics.Trailing_comma_not_allowed); + } + } + function parseJSDocUnionType() { + var result = createNode(233 /* JSDocUnionType */); + nextToken(); + result.types = parseJSDocTypeList(parseJSDocType()); + parseExpected(17 /* CloseParenToken */); + return finishNode(result); + } + function parseJSDocTypeList(firstType) { + ts.Debug.assert(!!firstType); + var types = []; + types.pos = firstType.pos; + types.push(firstType); + while (parseOptional(44 /* BarToken */)) { + types.push(parseJSDocType()); + } + types.end = scanner.getStartPos(); + return types; + } + function parseJSDocAllType() { + var result = createNode(230 /* JSDocAllType */); + nextToken(); + return finishNode(result); + } + function parseJSDocUnknownOrNullableType() { + var pos = scanner.getStartPos(); + // skip the ? + nextToken(); + // Need to lookahead to decide if this is a nullable or unknown type. + // Here are cases where we'll pick the unknown type: + // + // Foo(?, + // { a: ? } + // Foo(?) + // Foo + // Foo(?= + // (?| + if (token === 23 /* CommaToken */ || + token === 15 /* CloseBraceToken */ || + token === 17 /* CloseParenToken */ || + token === 25 /* GreaterThanToken */ || + token === 53 /* EqualsToken */ || + token === 44 /* BarToken */) { + var result = createNode(231 /* JSDocUnknownType */, pos); + return finishNode(result); + } + else { + var result = createNode(235 /* JSDocNullableType */, pos); + result.type = parseJSDocType(); + return finishNode(result); + } + } + function parseIsolatedJSDocComment(content, start, length) { + initializeState("file.js", content, 2 /* Latest */, undefined); + var jsDocComment = parseJSDocComment(undefined, start, length); + var diagnostics = parseDiagnostics; + clearState(); + return jsDocComment ? { jsDocComment: jsDocComment, diagnostics: diagnostics } : undefined; + } + JSDocParser.parseIsolatedJSDocComment = parseIsolatedJSDocComment; + function parseJSDocComment(parent, start, length) { + var comment = parseJSDocCommentWorker(start, length); + if (comment) { + fixupParentReferences(comment); + comment.parent = parent; + } + return comment; + } + JSDocParser.parseJSDocComment = parseJSDocComment; + function parseJSDocCommentWorker(start, length) { + var content = sourceText; + start = start || 0; + var end = length === undefined ? content.length : start + length; + length = end - start; + ts.Debug.assert(start >= 0); + ts.Debug.assert(start <= end); + ts.Debug.assert(end <= content.length); + var tags; + var pos; + // NOTE(cyrusn): This is essentially a handwritten scanner for JSDocComments. I + // considered using an actual Scanner, but this would complicate things. The + // scanner would need to know it was in a Doc Comment. Otherwise, it would then + // produce comments *inside* the doc comment. In the end it was just easier to + // write a simple scanner rather than go that route. + if (length >= "/** */".length) { + if (content.charCodeAt(start) === 47 /* slash */ && + content.charCodeAt(start + 1) === 42 /* asterisk */ && + content.charCodeAt(start + 2) === 42 /* asterisk */ && + content.charCodeAt(start + 3) !== 42 /* asterisk */) { + // Initially we can parse out a tag. We also have seen a starting asterisk. + // This is so that /** * @type */ doesn't parse. + var canParseTag = true; + var seenAsterisk = true; + for (pos = start + "/**".length; pos < end;) { + var ch = content.charCodeAt(pos); + pos++; + if (ch === 64 /* at */ && canParseTag) { + parseTag(); + // Once we parse out a tag, we cannot keep parsing out tags on this line. + canParseTag = false; + continue; + } + if (ts.isLineBreak(ch)) { + // After a line break, we can parse a tag, and we haven't seen as asterisk + // on the next line yet. + canParseTag = true; + seenAsterisk = false; + continue; + } + if (ts.isWhiteSpace(ch)) { + // Whitespace doesn't affect any of our parsing. + continue; + } + // Ignore the first asterisk on a line. + if (ch === 42 /* asterisk */) { + if (seenAsterisk) { + // If we've already seen an asterisk, then we can no longer parse a tag + // on this line. + canParseTag = false; + } + seenAsterisk = true; + continue; + } + // Anything else is doc comment text. We can't do anything with it. Because it + // wasn't a tag, we can no longer parse a tag on this line until we hit the next + // line break. + canParseTag = false; + } + } + } + return createJSDocComment(); + function createJSDocComment() { + if (!tags) { + return undefined; + } + var result = createNode(245 /* JSDocComment */, start); + result.tags = tags; + return finishNode(result, end); + } + function skipWhitespace() { + while (pos < end && ts.isWhiteSpace(content.charCodeAt(pos))) { + pos++; + } + } + function parseTag() { + ts.Debug.assert(content.charCodeAt(pos - 1) === 64 /* at */); + var atToken = createNode(52 /* AtToken */, pos - 1); + atToken.end = pos; + var startPos = pos; + var tagName = scanIdentifier(); + if (!tagName) { + return; + } + var tag = handleTag(atToken, tagName) || handleUnknownTag(atToken, tagName); + addTag(tag); + } + function handleTag(atToken, tagName) { + if (tagName) { + switch (tagName.text) { + case "param": + return handleParamTag(atToken, tagName); + case "return": + case "returns": + return handleReturnTag(atToken, tagName); + case "template": + return handleTemplateTag(atToken, tagName); + case "type": + return handleTypeTag(atToken, tagName); + } + } + return undefined; + } + function handleUnknownTag(atToken, tagName) { + var result = createNode(246 /* JSDocTag */, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + return finishNode(result, pos); + } + function addTag(tag) { + if (tag) { + if (!tags) { + tags = []; + tags.pos = tag.pos; + } + tags.push(tag); + tags.end = tag.end; + } + } + function tryParseTypeExpression() { + skipWhitespace(); + if (content.charCodeAt(pos) !== 123 /* openBrace */) { + return undefined; + } + var typeExpression = parseJSDocTypeExpression(pos, end - pos); + pos = typeExpression.end; + return typeExpression; + } + function handleParamTag(atToken, tagName) { + var typeExpression = tryParseTypeExpression(); + skipWhitespace(); + var name; + var isBracketed; + if (content.charCodeAt(pos) === 91 /* openBracket */) { + pos++; + skipWhitespace(); + name = scanIdentifier(); + isBracketed = true; + } + else { + name = scanIdentifier(); + } + if (!name) { + parseErrorAtPosition(pos, 0, ts.Diagnostics.Identifier_expected); + return undefined; + } + var preName, postName; + if (typeExpression) { + postName = name; + } + else { + preName = name; + } + if (!typeExpression) { + typeExpression = tryParseTypeExpression(); + } + var result = createNode(247 /* JSDocParameterTag */, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.preParameterName = preName; + result.typeExpression = typeExpression; + result.postParameterName = postName; + result.isBracketed = isBracketed; + return finishNode(result, pos); + } + function handleReturnTag(atToken, tagName) { + if (ts.forEach(tags, function (t) { return t.kind === 248 /* JSDocReturnTag */; })) { + parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); + } + var result = createNode(248 /* JSDocReturnTag */, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.typeExpression = tryParseTypeExpression(); + return finishNode(result, pos); + } + function handleTypeTag(atToken, tagName) { + if (ts.forEach(tags, function (t) { return t.kind === 249 /* JSDocTypeTag */; })) { + parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); + } + var result = createNode(249 /* JSDocTypeTag */, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.typeExpression = tryParseTypeExpression(); + return finishNode(result, pos); + } + function handleTemplateTag(atToken, tagName) { + if (ts.forEach(tags, function (t) { return t.kind === 250 /* JSDocTemplateTag */; })) { + parseErrorAtPosition(tagName.pos, pos - tagName.pos, ts.Diagnostics._0_tag_already_specified, tagName.text); + } + var typeParameters = []; + typeParameters.pos = pos; + while (true) { + skipWhitespace(); + var startPos = pos; + var name_6 = scanIdentifier(); + if (!name_6) { + parseErrorAtPosition(startPos, 0, ts.Diagnostics.Identifier_expected); + return undefined; + } + var typeParameter = createNode(129 /* TypeParameter */, name_6.pos); + typeParameter.name = name_6; + finishNode(typeParameter, pos); + typeParameters.push(typeParameter); + skipWhitespace(); + if (content.charCodeAt(pos) !== 44 /* comma */) { + break; + } + pos++; + } + typeParameters.end = pos; + var result = createNode(250 /* JSDocTemplateTag */, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.typeParameters = typeParameters; + return finishNode(result, pos); + } + function scanIdentifier() { + var startPos = pos; + for (; pos < end; pos++) { + var ch = content.charCodeAt(pos); + if (pos === startPos && ts.isIdentifierStart(ch, 2 /* Latest */)) { + continue; + } + else if (pos > startPos && ts.isIdentifierPart(ch, 2 /* Latest */)) { + continue; + } + break; + } + if (startPos === pos) { + return undefined; + } + var result = createNode(65 /* Identifier */, startPos); + result.text = content.substring(startPos, pos); + return finishNode(result, pos); + } + } + JSDocParser.parseJSDocCommentWorker = parseJSDocCommentWorker; + })(JSDocParser = Parser.JSDocParser || (Parser.JSDocParser = {})); })(Parser || (Parser = {})); var IncrementalParser; (function (IncrementalParser) { @@ -10375,7 +11356,12 @@ var ts; } // Ditch any existing LS children we may have created. This way we can avoid // moving them forward. - node._children = undefined; + if (node._children) { + node._children = undefined; + } + if (node.jsDocComment) { + node.jsDocComment = undefined; + } node.pos += delta; node.end += delta; if (aggressiveChecks && shouldCheckNode(node)) { @@ -10835,13 +11821,15 @@ var ts; var undefinedType = createIntrinsicType(32 /* Undefined */ | 262144 /* ContainsUndefinedOrNull */, "undefined"); var nullType = createIntrinsicType(64 /* Null */ | 262144 /* ContainsUndefinedOrNull */, "null"); var unknownType = createIntrinsicType(1 /* Any */, "unknown"); + var circularType = createIntrinsicType(1 /* Any */, "__circular__"); var emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + var emptyGenericType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + emptyGenericType.instantiations = {}; var anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); var noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); var anySignature = createSignature(undefined, undefined, emptyArray, anyType, 0, false, false); var unknownSignature = createSignature(undefined, undefined, emptyArray, unknownType, 0, false, false); var globals = {}; - var globalArraySymbol; var globalESSymbolConstructorSymbol; var globalObjectType; var globalFunctionType; @@ -10853,6 +11841,8 @@ var ts; var globalTemplateStringsArrayType; var globalESSymbolType; var globalIterableType; + var globalIteratorType; + var globalIterableIteratorType; var anyArrayType; var getGlobalClassDecoratorType; var getGlobalParameterDecoratorType; @@ -11079,7 +12069,15 @@ var ts; // Locals of a source file are not in scope (because they get merged into the global symbol table) if (location.locals && !isGlobalSourceFile(location)) { if (result = getSymbol(location.locals, name, meaning)) { - break loop; + // Type parameters of a function are in scope in the entire function declaration, including the parameter + // list and return type. However, local types are only in scope in the function body. + if (!(meaning & 793056 /* Type */) || + !(result.flags & (793056 /* Type */ & ~262144 /* TypeParameter */)) || + !ts.isFunctionLike(location) || + lastLocation === location.body) { + break loop; + } + result = undefined; } } switch (location.kind) { @@ -11164,27 +12162,31 @@ var ts; case 138 /* SetAccessor */: case 201 /* FunctionDeclaration */: case 164 /* ArrowFunction */: - if (name === "arguments") { + if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } break; case 163 /* FunctionExpression */: - if (name === "arguments") { + if (meaning & 3 /* Variable */ && name === "arguments") { result = argumentsSymbol; break loop; } - var functionName = location.name; - if (functionName && name === functionName.text) { - result = location.symbol; - break loop; + if (meaning & 16 /* Function */) { + var functionName = location.name; + if (functionName && name === functionName.text) { + result = location.symbol; + break loop; + } } break; case 175 /* ClassExpression */: - var className = location.name; - if (className && name === className.text) { - result = location.symbol; - break loop; + if (meaning & 32 /* Class */) { + var className = location.name; + if (className && name === className.text) { + result = location.symbol; + break loop; + } } break; case 131 /* Decorator */: @@ -11381,15 +12383,15 @@ var ts; var moduleSymbol = resolveExternalModuleName(node, node.moduleSpecifier); var targetSymbol = resolveESModuleSymbol(moduleSymbol, node.moduleSpecifier); if (targetSymbol) { - var name_4 = specifier.propertyName || specifier.name; - if (name_4.text) { - var symbolFromModule = getExportOfModule(targetSymbol, name_4.text); - var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_4.text); + var name_7 = specifier.propertyName || specifier.name; + if (name_7.text) { + var symbolFromModule = getExportOfModule(targetSymbol, name_7.text); + var symbolFromVariable = getPropertyOfVariable(targetSymbol, name_7.text); var symbol = symbolFromModule && symbolFromVariable ? combineValueAndTypeSymbols(symbolFromVariable, symbolFromModule) : symbolFromModule || symbolFromVariable; if (!symbol) { - error(name_4, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_4)); + error(name_7, ts.Diagnostics.Module_0_has_no_exported_member_1, getFullyQualifiedName(moduleSymbol), ts.declarationNameToString(name_7)); } return symbol; } @@ -11448,7 +12450,7 @@ var ts; var symbol = getSymbolOfNode(node); var target = resolveAlias(symbol); if (target) { - var markAlias = (target === unknownSymbol && compilerOptions.separateCompilation) || + var markAlias = (target === unknownSymbol && compilerOptions.isolatedModules) || (target !== unknownSymbol && (target.flags & 107455 /* Value */) && !isConstEnumOrConstEnumOnlyModule(target)); if (markAlias) { markAliasSymbolAsReferenced(symbol); @@ -12146,17 +13148,54 @@ var ts; writeType(types[i], union ? 64 /* InElementType */ : 0 /* None */); } } + function writeSymbolTypeReference(symbol, typeArguments, pos, end) { + // Unnamed function expressions, arrow functions, and unnamed class expressions have reserved names that + // we don't want to display + if (!isReservedMemberName(symbol.name)) { + buildSymbolDisplay(symbol, writer, enclosingDeclaration, 793056 /* Type */); + } + if (pos < end) { + writePunctuation(writer, 24 /* LessThanToken */); + writeType(typeArguments[pos++], 0 /* None */); + while (pos < end) { + writePunctuation(writer, 23 /* CommaToken */); + writeSpace(writer); + writeType(typeArguments[pos++], 0 /* None */); + } + writePunctuation(writer, 25 /* GreaterThanToken */); + } + } function writeTypeReference(type, flags) { + var typeArguments = type.typeArguments; if (type.target === globalArrayType && !(flags & 1 /* WriteArrayAsGenericType */)) { - writeType(type.typeArguments[0], 64 /* InElementType */); + writeType(typeArguments[0], 64 /* InElementType */); writePunctuation(writer, 18 /* OpenBracketToken */); writePunctuation(writer, 19 /* CloseBracketToken */); } else { - buildSymbolDisplay(type.target.symbol, writer, enclosingDeclaration, 793056 /* Type */); - writePunctuation(writer, 24 /* LessThanToken */); - writeTypeList(type.typeArguments, false); - writePunctuation(writer, 25 /* GreaterThanToken */); + // Write the type reference in the format f.g.C where A and B are type arguments + // for outer type parameters, and f and g are the respective declaring containers of those + // type parameters. + var outerTypeParameters = type.target.outerTypeParameters; + var i = 0; + if (outerTypeParameters) { + var length_1 = outerTypeParameters.length; + while (i < length_1) { + // Find group of type arguments for type parameters with the same declaring container. + var start = i; + var parent_3 = getParentSymbolOfTypeParameter(outerTypeParameters[i]); + do { + i++; + } while (i < length_1 && getParentSymbolOfTypeParameter(outerTypeParameters[i]) === parent_3); + // When type parameters are their own type arguments for the whole group (i.e. we have + // the default outer type arguments), we don't show the group. + if (!ts.rangeEquals(outerTypeParameters, typeArguments, start, i)) { + writeSymbolTypeReference(parent_3, typeArguments, start, i); + writePunctuation(writer, 20 /* DotToken */); + } + } + } + writeSymbolTypeReference(type.symbol, typeArguments, i, typeArguments.length); } } function writeTupleType(type) { @@ -12344,7 +13383,7 @@ var ts; function buildTypeParameterDisplayFromSymbol(symbol, writer, enclosingDeclaraiton, flags) { var targetSymbol = getTargetSymbol(symbol); if (targetSymbol.flags & 32 /* Class */ || targetSymbol.flags & 64 /* Interface */) { - buildDisplayForTypeParametersAndDelimiters(getTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); + buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); } } function buildTypeParameterDisplay(tp, writer, enclosingDeclaration, flags, typeStack) { @@ -12358,11 +13397,12 @@ var ts; } } function buildParameterDisplay(p, writer, enclosingDeclaration, flags, typeStack) { - if (ts.hasDotDotDotToken(p.valueDeclaration)) { + var parameterNode = p.valueDeclaration; + if (ts.isRestParameter(parameterNode)) { writePunctuation(writer, 21 /* DotDotDotToken */); } appendSymbolNameOnly(p, writer); - if (ts.hasQuestionToken(p.valueDeclaration) || p.valueDeclaration.initializer) { + if (isOptionalParameter(parameterNode)) { writePunctuation(writer, 50 /* QuestionToken */); } writePunctuation(writer, 51 /* ColonToken */); @@ -12517,14 +13557,14 @@ var ts; case 201 /* FunctionDeclaration */: case 205 /* EnumDeclaration */: case 209 /* ImportEqualsDeclaration */: - var parent_2 = getDeclarationContainer(node); + var parent_4 = getDeclarationContainer(node); // If the node is not exported or it is not ambient module element (except import declaration) if (!(ts.getCombinedNodeFlags(node) & 1 /* Export */) && - !(node.kind !== 209 /* ImportEqualsDeclaration */ && parent_2.kind !== 228 /* SourceFile */ && ts.isInAmbientContext(parent_2))) { - return isGlobalSourceFile(parent_2); + !(node.kind !== 209 /* ImportEqualsDeclaration */ && parent_4.kind !== 228 /* SourceFile */ && ts.isInAmbientContext(parent_4))) { + return isGlobalSourceFile(parent_4); } // Exported members/ambient module elements (exception import declaration) are visible if parent is visible - return isDeclarationVisible(parent_2); + return isDeclarationVisible(parent_4); case 133 /* PropertyDeclaration */: case 132 /* PropertySignature */: case 137 /* GetAccessor */: @@ -12675,14 +13715,14 @@ var ts; var type; if (pattern.kind === 151 /* ObjectBindingPattern */) { // Use explicitly specified property name ({ p: xxx } form), or otherwise the implied name ({ p } form) - var name_5 = declaration.propertyName || declaration.name; + var name_8 = declaration.propertyName || declaration.name; // Use type of the specified property, or otherwise, for a numeric name, the type of the numeric index signature, // or otherwise the type of the string index signature. - type = getTypeOfPropertyOfType(parentType, name_5.text) || - isNumericLiteralName(name_5.text) && getIndexTypeOfType(parentType, 1 /* Number */) || + type = getTypeOfPropertyOfType(parentType, name_8.text) || + isNumericLiteralName(name_8.text) && getIndexTypeOfType(parentType, 1 /* Number */) || getIndexTypeOfType(parentType, 0 /* String */); if (!type) { - error(name_5, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_5)); + error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(parentType), ts.declarationNameToString(name_8)); return unknownType; } } @@ -12727,7 +13767,7 @@ var ts; // checkRightHandSideOfForOf will return undefined if the for-of expression type was // missing properties/signatures required to get its iteratedType (like // [Symbol.iterator] or next). This may be because we accessed properties from anyType, - // or it may have led to an error inside getIteratedType. + // or it may have led to an error inside getElementTypeOfIterable. return checkRightHandSideOfForOf(declaration.parent.parent.expression) || anyType; } if (ts.isBindingPattern(declaration.parent)) { @@ -13020,29 +14060,65 @@ var ts; return target === checkBase || ts.forEach(getBaseTypes(target), check); } } - // Return combined list of type parameters from all declarations of a class or interface. Elsewhere we check they're all - // the same, but even if they're not we still need the complete list to ensure instantiations supply type arguments - // for all type parameters. - function getTypeParametersOfClassOrInterface(symbol) { - var result; - ts.forEach(symbol.declarations, function (node) { - if (node.kind === 203 /* InterfaceDeclaration */ || node.kind === 202 /* ClassDeclaration */) { - var declaration = node; - if (declaration.typeParameters && declaration.typeParameters.length) { - ts.forEach(declaration.typeParameters, function (node) { - var tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node)); - if (!result) { - result = [tp]; - } - else if (!ts.contains(result, tp)) { - result.push(tp); - } - }); + // Appends the type parameters given by a list of declarations to a set of type parameters and returns the resulting set. + // The function allocates a new array if the input type parameter set is undefined, but otherwise it modifies the set + // in-place and returns the same array. + function appendTypeParameters(typeParameters, declarations) { + for (var _i = 0; _i < declarations.length; _i++) { + var declaration = declarations[_i]; + var tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(declaration)); + if (!typeParameters) { + typeParameters = [tp]; + } + else if (!ts.contains(typeParameters, tp)) { + typeParameters.push(tp); + } + } + return typeParameters; + } + // Appends the outer type parameters of a node to a set of type parameters and returns the resulting set. The function + // allocates a new array if the input type parameter set is undefined, but otherwise it modifies the set in-place and + // returns the same array. + function appendOuterTypeParameters(typeParameters, node) { + while (true) { + node = node.parent; + if (!node) { + return typeParameters; + } + if (node.kind === 202 /* ClassDeclaration */ || node.kind === 201 /* FunctionDeclaration */ || + node.kind === 163 /* FunctionExpression */ || node.kind === 135 /* MethodDeclaration */ || + node.kind === 164 /* ArrowFunction */) { + var declarations = node.typeParameters; + if (declarations) { + return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations); } } - }); + } + } + // The outer type parameters are those defined by enclosing generic classes, methods, or functions. + function getOuterTypeParametersOfClassOrInterface(symbol) { + var kind = symbol.flags & 32 /* Class */ ? 202 /* ClassDeclaration */ : 203 /* InterfaceDeclaration */; + return appendOuterTypeParameters(undefined, ts.getDeclarationOfKind(symbol, kind)); + } + // The local type parameters are the combined set of type parameters from all declarations of the class or interface. + function getLocalTypeParametersOfClassOrInterface(symbol) { + var result; + for (var _i = 0, _a = symbol.declarations; _i < _a.length; _i++) { + var node = _a[_i]; + if (node.kind === 203 /* InterfaceDeclaration */ || node.kind === 202 /* ClassDeclaration */) { + var declaration = node; + if (declaration.typeParameters) { + result = appendTypeParameters(result, declaration.typeParameters); + } + } + } return result; } + // The full set of type parameters for a generic class or interface type consists of its outer type parameters plus + // its locally declared type parameters. + function getTypeParametersOfClassOrInterface(symbol) { + return ts.concatenate(getOuterTypeParametersOfClassOrInterface(symbol), getLocalTypeParametersOfClassOrInterface(symbol)); + } function getBaseTypes(type) { var typeWithBaseTypes = type; if (!typeWithBaseTypes.baseTypes) { @@ -13109,10 +14185,13 @@ var ts; if (!links.declaredType) { var kind = symbol.flags & 32 /* Class */ ? 1024 /* Class */ : 2048 /* Interface */; var type = links.declaredType = createObjectType(kind, symbol); - var typeParameters = getTypeParametersOfClassOrInterface(symbol); - if (typeParameters) { + var outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol); + var localTypeParameters = getLocalTypeParametersOfClassOrInterface(symbol); + if (outerTypeParameters || localTypeParameters) { type.flags |= 4096 /* Reference */; - type.typeParameters = typeParameters; + type.typeParameters = ts.concatenate(outerTypeParameters, localTypeParameters); + type.outerTypeParameters = outerTypeParameters; + type.localTypeParameters = localTypeParameters; type.instantiations = {}; type.instantiations[getTypeListId(type.typeParameters)] = type; type.target = type; @@ -13290,12 +14369,12 @@ var ts; return ts.map(baseSignatures, function (baseSignature) { var signature = baseType.flags & 4096 /* Reference */ ? getSignatureInstantiation(baseSignature, baseType.typeArguments) : cloneSignature(baseSignature); - signature.typeParameters = classType.typeParameters; + signature.typeParameters = classType.localTypeParameters; signature.resolvedReturnType = classType; return signature; }); } - return [createSignature(undefined, classType.typeParameters, emptyArray, classType, 0, false, false)]; + return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, 0, false, false)]; } function createTupleTypeMemberSymbols(memberTypes) { var members = {}; @@ -13619,11 +14698,14 @@ var ts; } return result; } + function isOptionalParameter(node) { + return ts.hasQuestionToken(node) || !!node.initializer; + } function getSignatureFromDeclaration(declaration) { var links = getNodeLinks(declaration); if (!links.resolvedSignature) { var classType = declaration.kind === 136 /* Constructor */ ? getDeclaredTypeOfClassOrInterface(declaration.parent.symbol) : undefined; - var typeParameters = classType ? classType.typeParameters : + var typeParameters = classType ? classType.localTypeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; var parameters = []; var hasStringLiterals = false; @@ -13661,7 +14743,7 @@ var ts; returnType = anyType; } } - links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, minArgumentCount, ts.hasRestParameters(declaration), hasStringLiterals); + links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, minArgumentCount, ts.hasRestParameter(declaration), hasStringLiterals); } return links.resolvedSignature; } @@ -13810,6 +14892,9 @@ var ts; } return type.constraint === noConstraintType ? undefined : type.constraint; } + function getParentSymbolOfTypeParameter(typeParameter) { + return getSymbolOfNode(ts.getDeclarationOfKind(typeParameter.symbol, 129 /* TypeParameter */).parent); + } function getTypeListId(types) { switch (types.length) { case 1: @@ -13913,23 +14998,7 @@ var ts; type = unknownType; } else { - type = getDeclaredTypeOfSymbol(symbol); - if (type.flags & (1024 /* Class */ | 2048 /* Interface */) && type.flags & 4096 /* Reference */) { - var typeParameters = type.typeParameters; - if (node.typeArguments && node.typeArguments.length === typeParameters.length) { - type = createTypeReference(type, ts.map(node.typeArguments, getTypeFromTypeNode)); - } - else { - error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, undefined, 1 /* WriteArrayAsGenericType */), typeParameters.length); - type = undefined; - } - } - else { - if (node.typeArguments) { - error(node, ts.Diagnostics.Type_0_is_not_generic, typeToString(type)); - type = undefined; - } - } + type = createTypeReferenceIfGeneric(getDeclaredTypeOfSymbol(symbol), node, node.typeArguments); } } } @@ -13937,6 +15006,34 @@ var ts; } return links.resolvedType; } + function createTypeReferenceIfGeneric(type, node, typeArguments) { + if (type.flags & (1024 /* Class */ | 2048 /* Interface */) && type.flags & 4096 /* Reference */) { + // In a type reference, the outer type parameters of the referenced class or interface are automatically + // supplied as type arguments and the type reference only specifies arguments for the local type parameters + // of the class or interface. + var localTypeParameters = type.localTypeParameters; + var expectedTypeArgCount = localTypeParameters ? localTypeParameters.length : 0; + var typeArgCount = typeArguments ? typeArguments.length : 0; + if (typeArgCount === expectedTypeArgCount) { + // When no type arguments are expected we already have the right type because all outer type parameters + // have themselves as default type arguments. + if (typeArgCount) { + return createTypeReference(type, ts.concatenate(type.outerTypeParameters, ts.map(typeArguments, getTypeFromTypeNode))); + } + } + else { + error(node, ts.Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, undefined, 1 /* WriteArrayAsGenericType */), expectedTypeArgCount); + return undefined; + } + } + else { + if (typeArguments) { + error(node, ts.Diagnostics.Type_0_is_not_generic, typeToString(type)); + return undefined; + } + } + return type; + } function getTypeFromTypeQueryNode(node) { var links = getNodeLinks(node); if (!links.resolvedType) { @@ -13962,16 +15059,16 @@ var ts; } } if (!symbol) { - return emptyObjectType; + return arity ? emptyGenericType : emptyObjectType; } var type = getDeclaredTypeOfSymbol(symbol); if (!(type.flags & 48128 /* ObjectType */)) { error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name); - return emptyObjectType; + return arity ? emptyGenericType : emptyObjectType; } if ((type.typeParameters ? type.typeParameters.length : 0) !== arity) { error(getTypeDeclaration(symbol), ts.Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity); - return emptyObjectType; + return arity ? emptyGenericType : emptyObjectType; } return type; } @@ -13991,15 +15088,20 @@ var ts; function getGlobalESSymbolConstructorSymbol() { return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol")); } + /** + * Instantiates a global type that is generic with some element type, and returns that instantiation. + */ + function createTypeFromGenericGlobalType(genericGlobalType, elementType) { + return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, [elementType]) : emptyObjectType; + } function createIterableType(elementType) { - return globalIterableType !== emptyObjectType ? createTypeReference(globalIterableType, [elementType]) : emptyObjectType; + return createTypeFromGenericGlobalType(globalIterableType, elementType); + } + function createIterableIteratorType(elementType) { + return createTypeFromGenericGlobalType(globalIterableIteratorType, elementType); } function createArrayType(elementType) { - // globalArrayType will be undefined if we get here during creation of the Array type. This for example happens if - // user code augments the Array type with call or construct signatures that have an array type as the return type. - // We instead use globalArraySymbol to obtain the (not yet fully constructed) Array type. - var arrayType = globalArrayType || getDeclaredTypeOfSymbol(globalArraySymbol); - return arrayType !== emptyObjectType ? createTypeReference(arrayType, [elementType]) : emptyObjectType; + return createTypeFromGenericGlobalType(globalArrayType, elementType); } function getTypeFromArrayTypeNode(node) { var links = getNodeLinks(node); @@ -14054,17 +15156,7 @@ var ts; } return false; } - // Since removeSubtypes checks the subtype relation, and the subtype relation on a union - // may attempt to reduce a union, it is possible that removeSubtypes could be called - // recursively on the same set of types. The removeSubtypesStack is used to track which - // sets of types are currently undergoing subtype reduction. - var removeSubtypesStack = []; function removeSubtypes(types) { - var typeListId = getTypeListId(types); - if (removeSubtypesStack.lastIndexOf(typeListId) >= 0) { - return; - } - removeSubtypesStack.push(typeListId); var i = types.length; while (i > 0) { i--; @@ -14072,7 +15164,6 @@ var ts; types.splice(i, 1); } } - removeSubtypesStack.pop(); } function containsAnyType(types) { for (var _i = 0; _i < types.length; _i++) { @@ -14124,10 +15215,20 @@ var ts; } return type; } + // Subtype reduction is basically an optimization we do to avoid excessively large union types, which take longer + // to process and look strange in quick info and error messages. Semantically there is no difference between the + // reduced type and the type itself. So, when we detect a circularity we simply say that the reduced type is the + // type itself. function getReducedTypeOfUnionType(type) { - // If union type was created without subtype reduction, perform the deferred reduction now if (!type.reducedType) { - type.reducedType = getUnionType(type.types, false); + type.reducedType = circularType; + var reducedType = getUnionType(type.types, false); + if (type.reducedType === circularType) { + type.reducedType = reducedType; + } + } + else if (type.reducedType === circularType) { + type.reducedType = type; } return type.reducedType; } @@ -14319,6 +15420,18 @@ var ts; return result; } function instantiateAnonymousType(type, mapper) { + // If this type has already been instantiated using this mapper, returned the cached result. This guards against + // infinite instantiations of cyclic types, e.g. "var x: { a: T, b: typeof x };" + if (mapper.mappings) { + var cached = mapper.mappings[type.id]; + if (cached) { + return cached; + } + } + else { + mapper.mappings = {}; + } + // Instantiate the given type using the given mapper and cache the result var result = createObjectType(32768 /* Anonymous */, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); @@ -14330,6 +15443,7 @@ var ts; result.stringIndexType = instantiateType(stringIndexType, mapper); if (numberIndexType) result.numberIndexType = instantiateType(numberIndexType, mapper); + mapper.mappings[type.id] = result; return result; } function instantiateType(type, mapper) { @@ -14338,7 +15452,7 @@ var ts; return mapper(type); } if (type.flags & 32768 /* Anonymous */) { - return type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) ? + return type.symbol && type.symbol.flags & (16 /* Function */ | 8192 /* Method */ | 32 /* Class */ | 2048 /* TypeLiteral */ | 4096 /* ObjectLiteral */) ? instantiateAnonymousType(type, mapper) : type; } if (type.flags & 4096 /* Reference */) { @@ -15613,10 +16727,10 @@ var ts; // Resolve location from top down towards node if it is a context sensitive expression // That helps in making sure not assigning types as any when resolved out of order var containerNodes = []; - for (var parent_3 = node.parent; parent_3; parent_3 = parent_3.parent) { - if ((ts.isExpression(parent_3) || ts.isObjectLiteralMethod(node)) && - isContextSensitive(parent_3)) { - containerNodes.unshift(parent_3); + for (var parent_5 = node.parent; parent_5; parent_5 = parent_5.parent) { + if ((ts.isExpression(parent_5) || ts.isObjectLiteralMethod(node)) && + isContextSensitive(parent_5)) { + containerNodes.unshift(parent_5); } } ts.forEach(containerNodes, function (node) { getTypeOfNode(node); }); @@ -16061,7 +17175,7 @@ var ts; if (isContextSensitive(func)) { var contextualSignature = getContextualSignature(func); if (contextualSignature) { - var funcHasRestParameters = ts.hasRestParameters(func); + var funcHasRestParameters = ts.hasRestParameter(func); var len = func.parameters.length - (funcHasRestParameters ? 1 : 0); var indexOfParameter = ts.indexOf(func.parameters, parameter); if (indexOfParameter < len) { @@ -16101,22 +17215,40 @@ var ts; return undefined; } function getContextualTypeForReturnExpression(node) { + var func = ts.getContainingFunction(node); + if (func && !func.asteriskToken) { + return getContextualReturnType(func); + } + return undefined; + } + function getContextualTypeForYieldOperand(node) { var func = ts.getContainingFunction(node); if (func) { - // If the containing function has a return type annotation, is a constructor, or is a get accessor whose - // corresponding set accessor has a type annotation, return statements in the function are contextually typed - if (func.type || func.kind === 136 /* Constructor */ || func.kind === 137 /* GetAccessor */ && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(func.symbol, 138 /* SetAccessor */))) { - return getReturnTypeOfSignature(getSignatureFromDeclaration(func)); - } - // 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 - var signature = getContextualSignatureForFunctionLikeDeclaration(func); - if (signature) { - return getReturnTypeOfSignature(signature); + var contextualReturnType = getContextualReturnType(func); + if (contextualReturnType) { + return node.asteriskToken + ? contextualReturnType + : getElementTypeOfIterableIterator(contextualReturnType); } } return undefined; } + function getContextualReturnType(functionDecl) { + // If the containing function has a return type annotation, is a constructor, or is a get accessor whose + // corresponding set accessor has a type annotation, return statements in the function are contextually typed + if (functionDecl.type || + functionDecl.kind === 136 /* Constructor */ || + functionDecl.kind === 137 /* GetAccessor */ && getSetAccessorTypeAnnotationNode(ts.getDeclarationOfKind(functionDecl.symbol, 138 /* SetAccessor */))) { + return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl)); + } + // 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 + var signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl); + if (signature) { + return getReturnTypeOfSignature(signature); + } + return undefined; + } // In a typed function call, an argument or substitution expression is contextually typed by the type of the corresponding parameter. function getContextualTypeForArgument(callTarget, arg) { var args = getEffectiveCallArguments(callTarget); @@ -16238,7 +17370,7 @@ var ts; var index = ts.indexOf(arrayLiteral.elements, node); return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, 1 /* Number */) - || (languageVersion >= 2 /* ES6 */ ? checkIteratedType(type, undefined) : undefined); + || (languageVersion >= 2 /* ES6 */ ? getElementTypeOfIterable(type, undefined) : undefined); } return undefined; } @@ -16268,6 +17400,8 @@ var ts; case 164 /* ArrowFunction */: case 192 /* ReturnStatement */: return getContextualTypeForReturnExpression(node); + case 173 /* YieldExpression */: + return getContextualTypeForYieldOperand(parent); case 158 /* CallExpression */: case 159 /* NewExpression */: return getContextualTypeForArgument(parent, node); @@ -16304,8 +17438,10 @@ var ts; return node.kind === 163 /* FunctionExpression */ || node.kind === 164 /* ArrowFunction */; } function getContextualSignatureForFunctionLikeDeclaration(node) { - // Only function expressions and arrow functions are contextually typed. - return isFunctionExpressionOrArrowFunction(node) ? getContextualSignature(node) : undefined; + // Only function expressions, arrow functions, and object literal methods are contextually typed. + return isFunctionExpressionOrArrowFunction(node) || ts.isObjectLiteralMethod(node) + ? getContextualSignature(node) + : undefined; } // Return the contextual signature for a given expression node. A contextual type provides a // contextual signature if it has a single call signature and if that call signature is non-generic. @@ -16415,7 +17551,7 @@ var ts; // if there is no index type / iterated type. var restArrayType = checkExpression(e.expression, contextualMapper); var restElementType = getIndexTypeOfType(restArrayType, 1 /* Number */) || - (languageVersion >= 2 /* ES6 */ ? checkIteratedType(restArrayType, undefined) : undefined); + (languageVersion >= 2 /* ES6 */ ? getElementTypeOfIterable(restArrayType, undefined) : undefined); if (restElementType) { elementTypes.push(restElementType); } @@ -16703,15 +17839,15 @@ var ts; // - Otherwise, if IndexExpr is of type Any, the String or Number primitive type, or an enum type, the property access is of type Any. // See if we can index as a property. if (node.argumentExpression) { - var name_6 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); - if (name_6 !== undefined) { - var prop = getPropertyOfType(objectType, name_6); + var name_9 = getPropertyNameForIndexedAccess(node.argumentExpression, indexType); + if (name_9 !== undefined) { + var prop = getPropertyOfType(objectType, name_9); if (prop) { getNodeLinks(node).resolvedSymbol = prop; return getTypeOfSymbol(prop); } else if (isConstEnum) { - error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_6, symbolToString(objectType.symbol)); + error(node.argumentExpression, ts.Diagnostics.Property_0_does_not_exist_on_const_enum_1, name_9, symbolToString(objectType.symbol)); return unknownType; } } @@ -16832,13 +17968,13 @@ var ts; for (var _i = 0; _i < signatures.length; _i++) { var signature = signatures[_i]; var symbol = signature.declaration && getSymbolOfNode(signature.declaration); - var parent_4 = signature.declaration && signature.declaration.parent; + var parent_6 = signature.declaration && signature.declaration.parent; if (!lastSymbol || symbol === lastSymbol) { - if (lastParent && parent_4 === lastParent) { + if (lastParent && parent_6 === lastParent) { index++; } else { - lastParent = parent_4; + lastParent = parent_6; index = cutoffIndex; } } @@ -16846,7 +17982,7 @@ var ts; // current declaration belongs to a different symbol // set cutoffIndex so re-orderings in the future won't change result set from 0 to cutoffIndex index = cutoffIndex = result.length; - lastParent = parent_4; + lastParent = parent_6; } lastSymbol = symbol; // specialized signatures always need to be placed before non-specialized signatures regardless @@ -17331,10 +18467,10 @@ var ts; return resolveCall(node, callSignatures, candidatesOutArray); } function resolveNewExpression(node, candidatesOutArray) { - if (node.arguments && languageVersion < 2 /* ES6 */) { + if (node.arguments && languageVersion < 1 /* ES5 */) { var spreadIndex = getSpreadArgumentIndex(node.arguments); if (spreadIndex >= 0) { - error(node.arguments[spreadIndex], ts.Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher); + error(node.arguments[spreadIndex], ts.Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher); } } var expressionType = checkExpression(node.expression); @@ -17350,7 +18486,7 @@ var ts; // If ConstructExpr's apparent type(section 3.8.1) is an object type with one or // more construct signatures, the expression is processed in the same manner as a // function call, but using the construct signatures as the initial set of candidate - // signatures for overload resolution.The result type of the function call becomes + // signatures for overload resolution. The result type of the function call becomes // the result type of the operation. expressionType = getApparentType(expressionType); if (expressionType === unknownType) { @@ -17486,17 +18622,39 @@ var ts; type = checkExpressionCached(func.body, contextualMapper); } else { - // Aggregate the types of expressions within all the return statements. - var types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); - if (types.length === 0) { - return voidType; + var types; + var funcIsGenerator = !!func.asteriskToken; + if (funcIsGenerator) { + types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); + if (types.length === 0) { + var iterableIteratorAny = createIterableIteratorType(anyType); + if (compilerOptions.noImplicitAny) { + error(func.asteriskToken, ts.Diagnostics.Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type, typeToString(iterableIteratorAny)); + } + return iterableIteratorAny; + } } - // When return statements are contextually typed we allow the return type to be a union type. Otherwise we require the - // return expressions to have a best common supertype. + else { + types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); + if (types.length === 0) { + return voidType; + } + } + // When yield/return statements are contextually typed we allow the return type to be a union type. + // Otherwise we require the yield/return expressions to have a best common supertype. type = contextualSignature ? getUnionType(types) : getCommonSupertype(types); if (!type) { - error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions); - return unknownType; + if (funcIsGenerator) { + error(func, ts.Diagnostics.No_best_common_type_exists_among_yield_expressions); + return createIterableIteratorType(unknownType); + } + else { + error(func, ts.Diagnostics.No_best_common_type_exists_among_return_expressions); + return unknownType; + } + } + if (funcIsGenerator) { + type = createIterableIteratorType(type); } } if (!contextualSignature) { @@ -17504,7 +18662,23 @@ var ts; } return getWidenedType(type); } - /// Returns a set of types relating to every return expression relating to a function block. + function checkAndAggregateYieldOperandTypes(body, contextualMapper) { + var aggregatedTypes = []; + ts.forEachYieldExpression(body, function (yieldExpression) { + var expr = yieldExpression.expression; + if (expr) { + var type = checkExpressionCached(expr, contextualMapper); + if (yieldExpression.asteriskToken) { + // A yield* expression effectively yields everything that its operand yields + type = checkElementTypeOfIterable(type, yieldExpression.expression); + } + if (!ts.contains(aggregatedTypes, type)) { + aggregatedTypes.push(type); + } + } + }); + return aggregatedTypes; + } function checkAndAggregateReturnExpressionTypes(body, contextualMapper) { var aggregatedTypes = []; ts.forEachReturnStatement(body, function (returnStatement) { @@ -17673,8 +18847,8 @@ var ts; var index = n.argumentExpression; var symbol = findSymbol(n.expression); if (symbol && index && index.kind === 8 /* StringLiteral */) { - var name_7 = index.text; - var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_7); + var name_10 = index.text; + var prop = getPropertyOfType(getTypeOfSymbol(symbol), name_10); return prop && (prop.flags & 3 /* Variable */) !== 0 && (getDeclarationFlagsFromSymbol(prop) & 8192 /* Const */) !== 0; } return false; @@ -17832,16 +19006,16 @@ var ts; var p = properties[_i]; if (p.kind === 225 /* PropertyAssignment */ || p.kind === 226 /* ShorthandPropertyAssignment */) { // TODO(andersh): Computed property support - var name_8 = p.name; + var name_11 = p.name; var type = sourceType.flags & 1 /* Any */ ? sourceType : - getTypeOfPropertyOfType(sourceType, name_8.text) || - isNumericLiteralName(name_8.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || + getTypeOfPropertyOfType(sourceType, name_11.text) || + isNumericLiteralName(name_11.text) && getIndexTypeOfType(sourceType, 1 /* Number */) || getIndexTypeOfType(sourceType, 0 /* String */); if (type) { - checkDestructuringAssignment(p.initializer || name_8, type); + checkDestructuringAssignment(p.initializer || name_11, type); } else { - error(name_8, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_8)); + error(name_11, ts.Diagnostics.Type_0_has_no_property_1_and_no_string_index_signature, typeToString(sourceType), ts.declarationNameToString(name_11)); } } else { @@ -18091,14 +19265,53 @@ var ts; error(node, ts.Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2, ts.tokenToString(node.operatorToken.kind), typeToString(leftType), typeToString(rightType)); } } + function isYieldExpressionInClass(node) { + var current = node; + var parent = node.parent; + while (parent) { + if (ts.isFunctionLike(parent) && current === parent.body) { + return false; + } + else if (current.kind === 202 /* ClassDeclaration */ || current.kind === 175 /* ClassExpression */) { + return true; + } + current = parent; + parent = parent.parent; + } + return false; + } function checkYieldExpression(node) { // Grammar checking - if (!(node.parserContextFlags & 4 /* Yield */)) { - grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration); + if (!(node.parserContextFlags & 4 /* Yield */) || isYieldExpressionInClass(node)) { + grammarErrorOnFirstToken(node, ts.Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body); } - else { - grammarErrorOnFirstToken(node, ts.Diagnostics.yield_expressions_are_not_currently_supported); + if (node.expression) { + var func = ts.getContainingFunction(node); + // If the user's code is syntactically correct, the func should always have a star. After all, + // we are in a yield context. + if (func && func.asteriskToken) { + var expressionType = checkExpressionCached(node.expression, undefined); + var expressionElementType; + var nodeIsYieldStar = !!node.asteriskToken; + if (nodeIsYieldStar) { + expressionElementType = checkElementTypeOfIterable(expressionType, node.expression); + } + // There is no point in doing an assignability check if the function + // has no explicit return type because the return type is directly computed + // from the yield expressions. + if (func.type) { + var signatureElementType = getElementTypeOfIterableIterator(getTypeFromTypeNode(func.type)) || anyType; + if (nodeIsYieldStar) { + checkTypeAssignableTo(expressionElementType, signatureElementType, node.expression, undefined); + } + else { + checkTypeAssignableTo(expressionType, signatureElementType, node.expression, undefined); + } + } + } } + // Both yield and yield* expressions have type 'any' + return anyType; } function checkConditionalExpression(node, contextualMapper) { checkExpression(node.condition); @@ -18269,8 +19482,7 @@ var ts; case 176 /* OmittedExpression */: return undefinedType; case 173 /* YieldExpression */: - checkYieldExpression(node); - return unknownType; + return checkYieldExpression(node); } return unknownType; } @@ -18314,6 +19526,14 @@ var ts; error(node, ts.Diagnostics.A_rest_parameter_must_be_of_an_array_type); } } + function isSyntacticallyValidGenerator(node) { + if (!node.asteriskToken || !node.body) { + return false; + } + return node.kind === 135 /* MethodDeclaration */ || + node.kind === 201 /* FunctionDeclaration */ || + node.kind === 163 /* FunctionExpression */; + } function checkSignatureDeclaration(node) { // Grammar checking if (node.kind === 141 /* IndexSignature */) { @@ -18341,6 +19561,25 @@ var ts; break; } } + if (node.type) { + if (languageVersion >= 2 /* ES6 */ && isSyntacticallyValidGenerator(node)) { + var returnType = getTypeFromTypeNode(node.type); + if (returnType === voidType) { + error(node.type, ts.Diagnostics.A_generator_cannot_have_a_void_type_annotation); + } + else { + var generatorElementType = getElementTypeOfIterableIterator(returnType) || anyType; + var iterableIteratorInstantiation = createIterableIteratorType(generatorElementType); + // Naively, one could check that IterableIterator is assignable to the return type annotation. + // However, that would not catch the error in the following case. + // + // interface BadGenerator extends Iterable, Iterator { } + // function* g(): BadGenerator { } // Iterable and Iterator have different types! + // + checkTypeAssignableTo(iterableIteratorInstantiation, returnType, node.type); + } + } + } } checkSpecializedSignatureDeclaration(node); } @@ -18898,7 +20137,7 @@ var ts; // serialize the type metadata. if (node && node.kind === 142 /* TypeReference */) { var type = getTypeFromTypeNode(node); - var shouldCheckIfUnknownType = type === unknownType && compilerOptions.separateCompilation; + var shouldCheckIfUnknownType = type === unknownType && compilerOptions.isolatedModules; if (!type || (!shouldCheckIfUnknownType && type.flags & (1048703 /* Intrinsic */ | 132 /* NumberLike */ | 258 /* StringLike */))) { return; } @@ -18948,6 +20187,9 @@ var ts; if (!ts.nodeCanBeDecorated(node)) { return; } + if (!compilerOptions.experimentalDecorators) { + error(node, ts.Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning); + } if (compilerOptions.emitDecoratorMetadata) { // we only need to perform these checks if we are emitting serialized type metadata for the target of a decorator. switch (node.kind) { @@ -18977,7 +20219,6 @@ var ts; function checkFunctionDeclaration(node) { if (produceDiagnostics) { checkFunctionLikeDeclaration(node) || - checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); checkCollisionWithCapturedSuperVariable(node, node.name); @@ -19020,10 +20261,18 @@ var ts; if (node.type && !isAccessor(node.kind) && !node.asteriskToken) { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - // Report an implicit any error if there is no body, no explicit return type, and node is not a private method - // in an ambient context - if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !node.type && !isPrivateWithinAmbient(node)) { - reportImplicitAnyError(node, anyType); + if (produceDiagnostics && !node.type) { + // Report an implicit any error if there is no body, no explicit return type, and node is not a private method + // in an ambient context + if (compilerOptions.noImplicitAny && ts.nodeIsMissing(node.body) && !isPrivateWithinAmbient(node)) { + reportImplicitAnyError(node, anyType); + } + if (node.asteriskToken && ts.nodeIsPresent(node.body)) { + // A generator with a body and no type annotation can still cause errors. It can error if the + // yielded values have no common supertype, or it can give an implicit any error if it has no + // yielded values. The only way to trigger these errors is to try checking its return type. + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } } } function checkBlock(node) { @@ -19038,7 +20287,7 @@ var ts; } function checkCollisionWithArgumentsInGeneratedCode(node) { // no rest parameters \ declaration context \ overload - no codegen impact - if (!ts.hasRestParameters(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) { + if (!ts.hasRestParameter(node) || ts.isInAmbientContext(node) || ts.nodeIsMissing(node.body)) { return; } ts.forEach(node.parameters, function (p) { @@ -19184,8 +20433,8 @@ var ts; // otherwise if variable has an initializer - show error that initialization will fail // since LHS will be block scoped name instead of function scoped if (!namesShareScope) { - var name_9 = symbolToString(localDeclarationSymbol); - error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_9, name_9); + var name_12 = symbolToString(localDeclarationSymbol); + error(node, ts.Diagnostics.Cannot_initialize_outer_scoped_variable_0_in_the_same_scope_as_block_scoped_declaration_1, name_12, name_12); } } } @@ -19295,7 +20544,7 @@ var ts; } function checkVariableStatement(node) { // Grammar checking - checkGrammarDecorators(node) || checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); ts.forEach(node.declarationList.declarations, checkSourceElement); } function checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) { @@ -19385,7 +20634,7 @@ var ts; // iteratedType will be undefined if the rightType was missing properties/signatures // required to get its iteratedType (like [Symbol.iterator] or next). This may be // because we accessed properties from anyType, or it may have led to an error inside - // getIteratedType. + // getElementTypeOfIterable. if (iteratedType) { checkTypeAssignableTo(iteratedType, leftType, varExpr, undefined); } @@ -19451,7 +20700,7 @@ var ts; return inputType; } if (languageVersion >= 2 /* ES6 */) { - return checkIteratedType(inputType, errorNode) || anyType; + return checkElementTypeOfIterable(inputType, errorNode); } if (allowStringInput) { return checkElementTypeOfArrayOrString(inputType, errorNode); @@ -19468,88 +20717,127 @@ var ts; /** * When errorNode is undefined, it means we should not report any errors. */ - function checkIteratedType(iterable, errorNode) { - ts.Debug.assert(languageVersion >= 2 /* ES6 */); - var iteratedType = getIteratedType(iterable, errorNode); + function checkElementTypeOfIterable(iterable, errorNode) { + var elementType = getElementTypeOfIterable(iterable, errorNode); // Now even though we have extracted the iteratedType, we will have to validate that the type // passed in is actually an Iterable. - if (errorNode && iteratedType) { - checkTypeAssignableTo(iterable, createIterableType(iteratedType), errorNode); + if (errorNode && elementType) { + checkTypeAssignableTo(iterable, createIterableType(elementType), errorNode); } - return iteratedType; - function getIteratedType(iterable, errorNode) { - // We want to treat type as an iterable, and get the type it is an iterable of. The iterable - // must have the following structure (annotated with the names of the variables below): - // - // { // iterable - // [Symbol.iterator]: { // iteratorFunction - // (): { // iterator - // next: { // iteratorNextFunction - // (): { // iteratorNextResult - // value: T // iteratorNextValue - // } - // } - // } - // } - // } - // - // T is the type we are after. At every level that involves analyzing return types - // of signatures, we union the return types of all the signatures. - // - // Another thing to note is that at any step of this process, we could run into a dead end, - // meaning either the property is missing, or we run into the anyType. If either of these things - // happens, we return undefined to signal that we could not find the iterated type. If a property - // is missing, and the previous step did not result in 'any', then we also give an error if the - // caller requested it. Then the caller can decide what to do in the case where there is no iterated - // type. This is different from returning anyType, because that would signify that we have matched the - // whole pattern and that T (above) is 'any'. - if (allConstituentTypesHaveKind(iterable, 1 /* Any */)) { - return undefined; - } + return elementType || anyType; + } + /** + * We want to treat type as an iterable, and get the type it is an iterable of. The iterable + * must have the following structure (annotated with the names of the variables below): + * + * { // iterable + * [Symbol.iterator]: { // iteratorFunction + * (): Iterator + * } + * } + * + * T is the type we are after. At every level that involves analyzing return types + * of signatures, we union the return types of all the signatures. + * + * Another thing to note is that at any step of this process, we could run into a dead end, + * meaning either the property is missing, or we run into the anyType. If either of these things + * happens, we return undefined to signal that we could not find the iterated type. If a property + * is missing, and the previous step did not result in 'any', then we also give an error if the + * caller requested it. Then the caller can decide what to do in the case where there is no iterated + * type. This is different from returning anyType, because that would signify that we have matched the + * whole pattern and that T (above) is 'any'. + */ + function getElementTypeOfIterable(type, errorNode) { + if (type.flags & 1 /* Any */) { + return undefined; + } + var typeAsIterable = type; + if (!typeAsIterable.iterableElementType) { // As an optimization, if the type is instantiated directly using the globalIterableType (Iterable), // then just grab its type argument. - if ((iterable.flags & 4096 /* Reference */) && iterable.target === globalIterableType) { - return iterable.typeArguments[0]; + if ((type.flags & 4096 /* Reference */) && type.target === globalIterableType) { + typeAsIterable.iterableElementType = type.typeArguments[0]; } - var iteratorFunction = getTypeOfPropertyOfType(iterable, ts.getPropertyNameForKnownSymbolName("iterator")); - if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, 1 /* Any */)) { - return undefined; - } - var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0 /* Call */) : emptyArray; - if (iteratorFunctionSignatures.length === 0) { - if (errorNode) { - error(errorNode, ts.Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator); + else { + var iteratorFunction = getTypeOfPropertyOfType(type, ts.getPropertyNameForKnownSymbolName("iterator")); + if (iteratorFunction && iteratorFunction.flags & 1 /* Any */) { + return undefined; } - return undefined; - } - var iterator = getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature)); - if (allConstituentTypesHaveKind(iterator, 1 /* Any */)) { - return undefined; - } - var iteratorNextFunction = getTypeOfPropertyOfType(iterator, "next"); - if (iteratorNextFunction && allConstituentTypesHaveKind(iteratorNextFunction, 1 /* Any */)) { - return undefined; - } - var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0 /* Call */) : emptyArray; - if (iteratorNextFunctionSignatures.length === 0) { - if (errorNode) { - error(errorNode, ts.Diagnostics.An_iterator_must_have_a_next_method); + var iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, 0 /* Call */) : emptyArray; + if (iteratorFunctionSignatures.length === 0) { + if (errorNode) { + error(errorNode, ts.Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator); + } + return undefined; } - return undefined; + typeAsIterable.iterableElementType = getElementTypeOfIterator(getUnionType(ts.map(iteratorFunctionSignatures, getReturnTypeOfSignature)), errorNode); } - var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); - if (allConstituentTypesHaveKind(iteratorNextResult, 1 /* Any */)) { - return undefined; - } - var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); - if (!iteratorNextValue) { - if (errorNode) { - error(errorNode, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property); - } - return undefined; - } - return iteratorNextValue; } + return typeAsIterable.iterableElementType; + } + /** + * This function has very similar logic as getElementTypeOfIterable, except that it operates on + * Iterators instead of Iterables. Here is the structure: + * + * { // iterator + * next: { // iteratorNextFunction + * (): { // iteratorNextResult + * value: T // iteratorNextValue + * } + * } + * } + * + */ + function getElementTypeOfIterator(type, errorNode) { + if (type.flags & 1 /* Any */) { + return undefined; + } + var typeAsIterator = type; + if (!typeAsIterator.iteratorElementType) { + // As an optimization, if the type is instantiated directly using the globalIteratorType (Iterator), + // then just grab its type argument. + if ((type.flags & 4096 /* Reference */) && type.target === globalIteratorType) { + typeAsIterator.iteratorElementType = type.typeArguments[0]; + } + else { + var iteratorNextFunction = getTypeOfPropertyOfType(type, "next"); + if (iteratorNextFunction && iteratorNextFunction.flags & 1 /* Any */) { + return undefined; + } + var iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, 0 /* Call */) : emptyArray; + if (iteratorNextFunctionSignatures.length === 0) { + if (errorNode) { + error(errorNode, ts.Diagnostics.An_iterator_must_have_a_next_method); + } + return undefined; + } + var iteratorNextResult = getUnionType(ts.map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); + if (iteratorNextResult.flags & 1 /* Any */) { + return undefined; + } + var iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); + if (!iteratorNextValue) { + if (errorNode) { + error(errorNode, ts.Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property); + } + return undefined; + } + typeAsIterator.iteratorElementType = iteratorNextValue; + } + } + return typeAsIterator.iteratorElementType; + } + function getElementTypeOfIterableIterator(type) { + if (type.flags & 1 /* Any */) { + return undefined; + } + // As an optimization, if the type is instantiated directly using the globalIterableIteratorType (IterableIterator), + // then just grab its type argument. + if ((type.flags & 4096 /* Reference */) && type.target === globalIterableIteratorType) { + return type.typeArguments[0]; + } + return getElementTypeOfIterable(type, undefined) || + getElementTypeOfIterator(type, undefined); } /** * This function does the following steps: @@ -19630,19 +20918,24 @@ var ts; if (func) { var returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(func)); var exprType = checkExpressionCached(node.expression); + if (func.asteriskToken) { + // A generator does not need its return expressions checked against its return type. + // Instead, the yield expressions are checked against the element type. + // TODO: Check return expressions of generators when return type tracking is added + // for generators. + return; + } if (func.kind === 138 /* SetAccessor */) { error(node.expression, ts.Diagnostics.Setters_cannot_return_a_value); } - else { - if (func.kind === 136 /* Constructor */) { - if (!isTypeAssignableTo(exprType, returnType)) { - error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); - } - } - else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func)) { - checkTypeAssignableTo(exprType, returnType, node.expression, undefined); + else if (func.kind === 136 /* Constructor */) { + if (!isTypeAssignableTo(exprType, returnType)) { + error(node.expression, ts.Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); } } + else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func)) { + checkTypeAssignableTo(exprType, returnType, node.expression, undefined); + } } } } @@ -19863,9 +21156,6 @@ var ts; function checkClassDeclaration(node) { checkGrammarDeclarationNameInStrictMode(node); // Grammar checking - if (node.parent.kind !== 207 /* ModuleBlock */ && node.parent.kind !== 228 /* SourceFile */) { - grammarErrorOnNode(node, ts.Diagnostics.class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration); - } if (!node.name && !(node.flags & 256 /* Default */)) { grammarErrorOnFirstToken(node, ts.Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } @@ -19902,7 +21192,7 @@ var ts; checkKindsOfPropertyMemberOverrides(type, baseType); } } - if (baseTypes.length || (baseTypeNode && compilerOptions.separateCompilation)) { + if (baseTypes.length || (baseTypeNode && compilerOptions.isolatedModules)) { // Check that base type can be evaluated as expression checkExpressionOrQualifiedName(baseTypeNode.expression); } @@ -20271,8 +21561,8 @@ var ts; checkExportsOnMergedDeclarations(node); computeEnumMemberValues(node); var enumIsConst = ts.isConst(node); - if (compilerOptions.separateCompilation && enumIsConst && ts.isInAmbientContext(node)) { - error(node.name, ts.Diagnostics.Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided); + if (compilerOptions.isolatedModules && enumIsConst && ts.isInAmbientContext(node)) { + error(node.name, ts.Diagnostics.Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided); } // Spec 2014 - Section 9.3: // It isn't possible for one enum declaration to continue the automatic numbering sequence of another, @@ -20354,7 +21644,7 @@ var ts; if (symbol.flags & 512 /* ValueModule */ && symbol.declarations.length > 1 && !ts.isInAmbientContext(node) - && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.separateCompilation)) { + && ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules)) { var firstNonAmbientClassOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); if (firstNonAmbientClassOrFunc) { if (ts.getSourceFileOfNode(node) !== ts.getSourceFileOfNode(firstNonAmbientClassOrFunc)) { @@ -20705,6 +21995,7 @@ var ts; break; case 135 /* MethodDeclaration */: case 134 /* MethodSignature */: + ts.forEach(node.decorators, checkFunctionExpressionBodies); ts.forEach(node.parameters, checkFunctionExpressionBodies); if (ts.isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); @@ -20719,6 +22010,7 @@ var ts; case 193 /* WithStatement */: checkFunctionExpressionBodies(node.expression); break; + case 131 /* Decorator */: case 130 /* Parameter */: case 133 /* PropertyDeclaration */: case 132 /* PropertySignature */: @@ -20969,87 +22261,6 @@ var ts; } return node.parent && node.parent.kind === 177 /* ExpressionWithTypeArguments */; } - function isTypeNode(node) { - if (142 /* FirstTypeNode */ <= node.kind && node.kind <= 150 /* LastTypeNode */) { - return true; - } - switch (node.kind) { - case 112 /* AnyKeyword */: - case 120 /* NumberKeyword */: - case 122 /* StringKeyword */: - case 113 /* BooleanKeyword */: - case 123 /* SymbolKeyword */: - return true; - case 99 /* VoidKeyword */: - return node.parent.kind !== 167 /* VoidExpression */; - case 8 /* StringLiteral */: - // Specialized signatures can have string literals as their parameters' type names - return node.parent.kind === 130 /* Parameter */; - case 177 /* ExpressionWithTypeArguments */: - return true; - // Identifiers and qualified names may be type nodes, depending on their context. Climb - // above them to find the lowest container - case 65 /* Identifier */: - // If the identifier is the RHS of a qualified name, then it's a type iff its parent is. - if (node.parent.kind === 127 /* QualifiedName */ && node.parent.right === node) { - node = node.parent; - } - else if (node.parent.kind === 156 /* PropertyAccessExpression */ && node.parent.name === node) { - node = node.parent; - } - // fall through - case 127 /* QualifiedName */: - case 156 /* PropertyAccessExpression */: - // At this point, node is either a qualified name or an identifier - ts.Debug.assert(node.kind === 65 /* Identifier */ || node.kind === 127 /* QualifiedName */ || node.kind === 156 /* PropertyAccessExpression */, "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); - var parent_5 = node.parent; - if (parent_5.kind === 145 /* TypeQuery */) { - return false; - } - // Do not recursively call isTypeNode on the parent. In the example: - // - // let a: A.B.C; - // - // Calling isTypeNode would consider the qualified name A.B a type node. Only C or - // A.B.C is a type node. - if (142 /* FirstTypeNode */ <= parent_5.kind && parent_5.kind <= 150 /* LastTypeNode */) { - return true; - } - switch (parent_5.kind) { - case 177 /* ExpressionWithTypeArguments */: - return true; - case 129 /* TypeParameter */: - return node === parent_5.constraint; - case 133 /* PropertyDeclaration */: - case 132 /* PropertySignature */: - case 130 /* Parameter */: - case 199 /* VariableDeclaration */: - return node === parent_5.type; - case 201 /* FunctionDeclaration */: - case 163 /* FunctionExpression */: - case 164 /* ArrowFunction */: - case 136 /* Constructor */: - case 135 /* MethodDeclaration */: - case 134 /* MethodSignature */: - case 137 /* GetAccessor */: - case 138 /* SetAccessor */: - return node === parent_5.type; - case 139 /* CallSignature */: - case 140 /* ConstructSignature */: - case 141 /* IndexSignature */: - return node === parent_5.type; - case 161 /* TypeAssertionExpression */: - return node === parent_5.type; - case 158 /* CallExpression */: - case 159 /* NewExpression */: - return parent_5.typeArguments && ts.indexOf(parent_5.typeArguments, node) >= 0; - case 160 /* TaggedTemplateExpression */: - // TODO (drosen): TaggedTemplateExpressions may eventually support type arguments. - return false; - } - } - return false; - } function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide) { while (nodeOnRightSide.parent.kind === 127 /* QualifiedName */) { nodeOnRightSide = nodeOnRightSide.parent; @@ -21192,7 +22403,7 @@ var ts; // We cannot answer semantic questions within a with block, do not proceed any further return unknownType; } - if (isTypeNode(node)) { + if (ts.isTypeNode(node)) { return getTypeFromTypeNode(node); } if (ts.isExpression(node)) { @@ -21246,9 +22457,9 @@ var ts; function getRootSymbols(symbol) { if (symbol.flags & 268435456 /* UnionProperty */) { var symbols = []; - var name_10 = symbol.name; + var name_13 = symbol.name; ts.forEach(getSymbolLinks(symbol).unionType.types, function (t) { - symbols.push(getPropertyOfType(t, name_10)); + symbols.push(getPropertyOfType(t, name_13)); }); return symbols; } @@ -21356,7 +22567,7 @@ var ts; } function isAliasResolvedToValue(symbol) { var target = resolveAlias(symbol); - if (target === unknownSymbol && compilerOptions.separateCompilation) { + if (target === unknownSymbol && compilerOptions.isolatedModules) { return true; } // const enums and modules that contain only const enums are not considered values from the emit perespective @@ -21703,8 +22914,7 @@ var ts; getSymbolLinks(unknownSymbol).type = unknownType; globals[undefinedSymbol.name] = undefinedSymbol; // Initialize special types - globalArraySymbol = getGlobalTypeSymbol("Array"); - globalArrayType = getTypeOfGlobalSymbol(globalArraySymbol, 1); + globalArrayType = getGlobalType("Array", 1); globalObjectType = getGlobalType("Object"); globalFunctionType = getGlobalType("Function"); globalStringType = getGlobalType("String"); @@ -21722,6 +22932,8 @@ var ts; globalESSymbolType = getGlobalType("Symbol"); globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"); globalIterableType = getGlobalType("Iterable", 1); + globalIteratorType = getGlobalType("Iterator", 1); + globalIterableIteratorType = getGlobalType("IterableIterator", 1); } else { globalTemplateStringsArrayType = unknownType; @@ -21730,6 +22942,9 @@ var ts; // a global Symbol already, particularly if it is a class. globalESSymbolType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); globalESSymbolConstructorSymbol = undefined; + globalIterableType = emptyGenericType; + globalIteratorType = emptyGenericType; + globalIterableIteratorType = emptyGenericType; } anyArrayType = createArrayType(anyType); } @@ -21754,20 +22969,20 @@ var ts; if (impotClause.namedBindings) { var nameBindings = impotClause.namedBindings; if (nameBindings.kind === 212 /* NamespaceImport */) { - var name_11 = nameBindings.name; - if (isReservedWordInStrictMode(name_11)) { - var nameText = ts.declarationNameToString(name_11); - return grammarErrorOnNode(name_11, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_14 = nameBindings.name; + if (isReservedWordInStrictMode(name_14)) { + var nameText = ts.declarationNameToString(name_14); + return grammarErrorOnNode(name_14, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } else if (nameBindings.kind === 213 /* NamedImports */) { var reportError = false; for (var _i = 0, _a = nameBindings.elements; _i < _a.length; _i++) { var element = _a[_i]; - var name_12 = element.name; - if (isReservedWordInStrictMode(name_12)) { - var nameText = ts.declarationNameToString(name_12); - reportError = reportError || grammarErrorOnNode(name_12, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); + var name_15 = element.name; + if (isReservedWordInStrictMode(name_15)) { + var nameText = ts.declarationNameToString(name_15); + reportError = reportError || grammarErrorOnNode(name_15, ts.Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode, nameText); } } return reportError; @@ -21893,19 +23108,28 @@ var ts; case 135 /* MethodDeclaration */: case 134 /* MethodSignature */: case 141 /* IndexSignature */: - case 202 /* ClassDeclaration */: - case 203 /* InterfaceDeclaration */: case 206 /* ModuleDeclaration */: - case 205 /* EnumDeclaration */: - case 181 /* VariableStatement */: - case 201 /* FunctionDeclaration */: - case 204 /* TypeAliasDeclaration */: case 210 /* ImportDeclaration */: case 209 /* ImportEqualsDeclaration */: case 216 /* ExportDeclaration */: case 215 /* ExportAssignment */: case 130 /* Parameter */: break; + case 202 /* ClassDeclaration */: + case 203 /* InterfaceDeclaration */: + case 181 /* VariableStatement */: + case 201 /* FunctionDeclaration */: + case 204 /* TypeAliasDeclaration */: + if (node.modifiers && node.parent.kind !== 207 /* ModuleBlock */ && node.parent.kind !== 228 /* SourceFile */) { + return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + } + break; + case 205 /* EnumDeclaration */: + if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== 70 /* ConstKeyword */) && + node.parent.kind !== 207 /* ModuleBlock */ && node.parent.kind !== 228 /* SourceFile */) { + return grammarErrorOnFirstToken(node, ts.Diagnostics.Modifiers_cannot_appear_here); + } + break; default: return false; } @@ -22003,9 +23227,6 @@ var ts; else if ((node.kind === 210 /* ImportDeclaration */ || node.kind === 209 /* ImportEqualsDeclaration */) && flags & 2 /* Ambient */) { return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); } - else if (node.kind === 203 /* InterfaceDeclaration */ && flags & 2 /* Ambient */) { - return grammarErrorOnNode(lastDeclare, ts.Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); - } else if (node.kind === 130 /* Parameter */ && (flags & 112 /* AccessibilityModifier */) && ts.isBindingPattern(node.name)) { return grammarErrorOnNode(node, ts.Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); } @@ -22222,7 +23443,18 @@ var ts; } function checkGrammarForGenerator(node) { if (node.asteriskToken) { - return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_currently_supported); + ts.Debug.assert(node.kind === 201 /* FunctionDeclaration */ || + node.kind === 163 /* FunctionExpression */ || + node.kind === 135 /* MethodDeclaration */); + if (ts.isInAmbientContext(node)) { + return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_not_allowed_in_an_ambient_context); + } + if (!node.body) { + return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.An_overload_signature_cannot_be_declared_as_a_generator); + } + if (languageVersion < 2 /* ES6 */) { + return grammarErrorOnNode(node.asteriskToken, ts.Diagnostics.Generators_are_only_available_when_targeting_ECMAScript_6_or_higher); + } } } function checkGrammarFunctionName(name) { @@ -22243,11 +23475,11 @@ var ts; var inStrictMode = (node.parserContextFlags & 1 /* StrictMode */) !== 0; for (var _i = 0, _a = node.properties; _i < _a.length; _i++) { var prop = _a[_i]; - var name_13 = prop.name; + var name_16 = prop.name; if (prop.kind === 176 /* OmittedExpression */ || - name_13.kind === 128 /* ComputedPropertyName */) { + name_16.kind === 128 /* ComputedPropertyName */) { // If the name is not a ComputedPropertyName, the grammar checking will skip it - checkGrammarComputedPropertyName(name_13); + checkGrammarComputedPropertyName(name_16); continue; } // ECMA-262 11.1.5 Object Initialiser @@ -22262,8 +23494,8 @@ var ts; if (prop.kind === 225 /* PropertyAssignment */ || prop.kind === 226 /* ShorthandPropertyAssignment */) { // Grammar checking for computedPropertName and shorthandPropertyAssignment checkGrammarForInvalidQuestionMark(prop, prop.questionToken, ts.Diagnostics.An_object_member_cannot_be_declared_optional); - if (name_13.kind === 7 /* NumericLiteral */) { - checkGrammarNumericLiteral(name_13); + if (name_16.kind === 7 /* NumericLiteral */) { + checkGrammarNumericLiteral(name_16); } currentKind = Property; } @@ -22279,26 +23511,26 @@ var ts; else { ts.Debug.fail("Unexpected syntax kind:" + prop.kind); } - if (!ts.hasProperty(seen, name_13.text)) { - seen[name_13.text] = currentKind; + if (!ts.hasProperty(seen, name_16.text)) { + seen[name_16.text] = currentKind; } else { - var existingKind = seen[name_13.text]; + var existingKind = seen[name_16.text]; if (currentKind === Property && existingKind === Property) { if (inStrictMode) { - grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); + grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_properties_with_the_same_name_in_strict_mode); } } else if ((currentKind & GetOrSetAccessor) && (existingKind & GetOrSetAccessor)) { if (existingKind !== GetOrSetAccessor && currentKind !== existingKind) { - seen[name_13.text] = currentKind | existingKind; + seen[name_16.text] = currentKind | existingKind; } else { - return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); + return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_multiple_get_Slashset_accessors_with_the_same_name); } } else { - return grammarErrorOnNode(name_13, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); + return grammarErrorOnNode(name_16, ts.Diagnostics.An_object_literal_cannot_have_property_and_accessor_with_the_same_name); } } } @@ -23159,9 +24391,9 @@ var ts; } var count = 0; while (true) { - var name_14 = baseName + "_" + (++count); - if (!ts.hasProperty(currentSourceFile.identifiers, name_14)) { - return name_14; + var name_17 = baseName + "_" + (++count); + if (!ts.hasProperty(currentSourceFile.identifiers, name_17)) { + return name_17; } } } @@ -24370,9 +25602,9 @@ var ts; tempFlags++; // Skip over 'i' and 'n' if (count !== 8 && count !== 13) { - var name_15 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); - if (isUniqueName(name_15)) { - return name_15; + var name_18 = count < 26 ? "_" + String.fromCharCode(97 /* a */ + count) : "_" + (count - 26); + if (isUniqueName(name_18)) { + return name_18; } } } @@ -24405,9 +25637,9 @@ var ts; } function generateNameForModuleOrEnum(node) { if (node.name.kind === 65 /* Identifier */) { - var name_16 = node.name.text; + var name_19 = node.name.text; // Use module/enum name itself if it is unique, otherwise make a unique variation - assignGeneratedName(node, isUniqueLocalName(name_16, node) ? name_16 : makeUniqueName(name_16)); + assignGeneratedName(node, isUniqueLocalName(name_19, node) ? name_19 : makeUniqueName(name_19)); } } function generateNameForImportOrExportDeclaration(node) { @@ -24626,8 +25858,8 @@ var ts; // Child scopes are always shown with a dot (even if they have no name), // unless it is a computed property. Then it is shown with brackets, // but the brackets are included in the name. - var name_17 = node.name; - if (!name_17 || name_17.kind !== 128 /* ComputedPropertyName */) { + var name_20 = node.name; + if (!name_20 || name_20.kind !== 128 /* ComputedPropertyName */) { scopeName = "." + scopeName; } scopeName = sourceMapData.sourceMapNames[parentIndex] + scopeName; @@ -24656,10 +25888,10 @@ var ts; node.kind === 205 /* EnumDeclaration */) { // Declaration and has associated name use it if (node.name) { - var name_18 = node.name; + var name_21 = node.name; // For computed property names, the text will include the brackets - scopeName = name_18.kind === 128 /* ComputedPropertyName */ - ? ts.getTextOfNode(name_18) + scopeName = name_21.kind === 128 /* ComputedPropertyName */ + ? ts.getTextOfNode(name_21) : node.name.text; } recordScopeNameStart(scopeName); @@ -25360,16 +26592,16 @@ var ts; } return true; } - function emitListWithSpread(elements, alwaysCopy, multiLine, trailingComma) { + function emitListWithSpread(elements, needsUniqueCopy, multiLine, trailingComma, useConcat) { var pos = 0; var group = 0; var length = elements.length; while (pos < length) { // Emit using the pattern .concat(, , ...) - if (group === 1) { + if (group === 1 && useConcat) { write(".concat("); } - else if (group > 1) { + else if (group > 0) { write(", "); } var e = elements[pos]; @@ -25377,7 +26609,7 @@ var ts; e = e.expression; emitParenthesizedIf(e, group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); pos++; - if (pos === length && group === 0 && alwaysCopy && e.kind !== 154 /* ArrayLiteralExpression */) { + if (pos === length && group === 0 && needsUniqueCopy && e.kind !== 154 /* ArrayLiteralExpression */) { write(".slice()"); } } @@ -25400,7 +26632,9 @@ var ts; group++; } if (group > 1) { - write(")"); + if (useConcat) { + write(")"); + } } } function isSpreadElementExpression(node) { @@ -25418,7 +26652,7 @@ var ts; } else { emitListWithSpread(elements, true, (node.flags & 512 /* MultiLine */) !== 0, - /*trailingComma*/ elements.hasTrailingComma); + /*trailingComma*/ elements.hasTrailingComma, true); } } function emitObjectLiteralBody(node, numElements) { @@ -25669,7 +26903,7 @@ var ts; } } function tryEmitConstantValue(node) { - if (compilerOptions.separateCompilation) { + if (compilerOptions.isolatedModules) { // do not inline enum values in separate compilation mode return false; } @@ -25789,7 +27023,7 @@ var ts; write("void 0"); } write(", "); - emitListWithSpread(node.arguments, false, false, false); + emitListWithSpread(node.arguments, false, false, false, true); write(")"); } function emitCallExpression(node) { @@ -25823,11 +27057,42 @@ var ts; } function emitNewExpression(node) { write("new "); - emit(node.expression); - if (node.arguments) { + // Spread operator logic can be supported in new expressions in ES5 using a combination + // of Function.prototype.bind() and Function.prototype.apply(). + // + // Example: + // + // var arguments = [1, 2, 3, 4, 5]; + // new Array(...arguments); + // + // Could be transpiled into ES5: + // + // var arguments = [1, 2, 3, 4, 5]; + // new (Array.bind.apply(Array, [void 0].concat(arguments))); + // + // `[void 0]` is the first argument which represents `thisArg` to the bind method above. + // And `thisArg` will be set to the return value of the constructor when instantiated + // with the new operator — regardless of any value we set `thisArg` to. Thus, we set it + // to an undefined, `void 0`. + if (languageVersion === 1 /* ES5 */ && + node.arguments && + hasSpreadElement(node.arguments)) { write("("); - emitCommaList(node.arguments); - write(")"); + var target = emitCallTarget(node.expression); + write(".bind.apply("); + emit(target); + write(", [void 0].concat("); + emitListWithSpread(node.arguments, false, false, false, false); + write(")))"); + write("()"); + } + else { + emit(node.expression); + if (node.arguments) { + write("("); + emitCommaList(node.arguments); + write(")"); + } } } function emitTaggedTemplateExpression(node) { @@ -26127,9 +27392,10 @@ var ts; write(")"); emitEmbeddedStatement(node.statement); } - /* Returns true if start of variable declaration list was emitted. - * Return false if nothing was written - this can happen for source file level variable declarations - * in system modules - such variable declarations are hoisted. + /** + * Returns true if start of variable declaration list was emitted. + * Returns false if nothing was written - this can happen for source file level variable declarations + * in system modules where such variable declarations are hoisted. */ function tryEmitStartOfVariableDeclarationList(decl, startPos) { if (shouldHoistVariable(decl, true)) { @@ -26892,15 +28158,35 @@ var ts; ts.forEach(node.declarationList.declarations, emitExportVariableAssignments); } } + function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node) { + // If we're not exporting the variables, there's nothing special here. + // Always emit comments for these nodes. + if (!(node.flags & 1 /* Export */)) { + return true; + } + // If we are exporting, but it's a top-level ES6 module exports, + // we'll emit the declaration list verbatim, so emit comments too. + if (isES6ExportedDeclaration(node)) { + return true; + } + // Otherwise, only emit if we have at least one initializer present. + for (var _a = 0, _b = node.declarationList.declarations; _a < _b.length; _a++) { + var declaration = _b[_a]; + if (declaration.initializer) { + return true; + } + } + return false; + } function emitParameter(node) { if (languageVersion < 2 /* ES6 */) { if (ts.isBindingPattern(node.name)) { - var name_19 = createTempVariable(0 /* Auto */); + var name_22 = createTempVariable(0 /* Auto */); if (!tempParameters) { tempParameters = []; } - tempParameters.push(name_19); - emit(name_19); + tempParameters.push(name_22); + emit(name_22); } else { emit(node.name); @@ -26949,7 +28235,7 @@ var ts; } } function emitRestParameter(node) { - if (languageVersion < 2 /* ES6 */ && ts.hasRestParameters(node)) { + if (languageVersion < 2 /* ES6 */ && ts.hasRestParameter(node)) { var restIndex = node.parameters.length - 1; var restParam = node.parameters[restIndex]; // A rest parameter cannot have a binding pattern, so let's just ignore it if it does. @@ -27063,7 +28349,7 @@ var ts; write("("); if (node) { var parameters = node.parameters; - var omitCount = languageVersion < 2 /* ES6 */ && ts.hasRestParameters(node) ? 1 : 0; + var omitCount = languageVersion < 2 /* ES6 */ && ts.hasRestParameter(node) ? 1 : 0; emitList(parameters, 0, parameters.length - omitCount, false, false); } write(")"); @@ -28066,7 +29352,7 @@ var ts; } function shouldEmitEnumDeclaration(node) { var isConstEnum = ts.isConst(node); - return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.separateCompilation; + return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules; } function emitEnumDeclaration(node) { // const enums are completely erased during compilation. @@ -28165,7 +29451,7 @@ var ts; } } function shouldEmitModuleDeclaration(node) { - return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.separateCompilation); + return ts.isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules); } function isModuleMergedWithES6Class(node) { return languageVersion === 2 /* ES6 */ && !!(resolver.getNodeCheckFlags(node) & 2048 /* LexicalModuleMergesWithClass */); @@ -28568,8 +29854,8 @@ var ts; // export { x, y } for (var _c = 0, _d = node.exportClause.elements; _c < _d.length; _c++) { var specifier = _d[_c]; - var name_20 = (specifier.propertyName || specifier.name).text; - (exportSpecifiers[name_20] || (exportSpecifiers[name_20] = [])).push(specifier); + var name_23 = (specifier.propertyName || specifier.name).text; + (exportSpecifiers[name_23] || (exportSpecifiers[name_23] = [])).push(specifier); } } break; @@ -28769,12 +30055,12 @@ var ts; var seen = {}; for (var i = 0; i < hoistedVars.length; ++i) { var local = hoistedVars[i]; - var name_21 = local.kind === 65 /* Identifier */ + var name_24 = local.kind === 65 /* Identifier */ ? local : local.name; - if (name_21) { + if (name_24) { // do not emit duplicate entries (in case of declaration merging) in the list of hoisted variables - var text = ts.unescapeIdentifier(name_21.text); + var text = ts.unescapeIdentifier(name_24.text); if (ts.hasProperty(seen, text)) { continue; } @@ -28853,15 +30139,15 @@ var ts; } if (node.kind === 199 /* VariableDeclaration */ || node.kind === 153 /* BindingElement */) { if (shouldHoistVariable(node, false)) { - var name_22 = node.name; - if (name_22.kind === 65 /* Identifier */) { + var name_25 = node.name; + if (name_25.kind === 65 /* Identifier */) { if (!hoistedVars) { hoistedVars = []; } - hoistedVars.push(name_22); + hoistedVars.push(name_25); } else { - ts.forEachChild(name_22, visit); + ts.forEachChild(name_25, visit); } } return; @@ -29265,7 +30551,7 @@ var ts; paramEmitted = true; } } - if (ts.isExternalModule(node) || compilerOptions.separateCompilation) { + if (ts.isExternalModule(node) || compilerOptions.isolatedModules) { if (languageVersion >= 2 /* ES6 */) { emitES6Module(node, startIndex); } @@ -29320,6 +30606,8 @@ var ts; case 204 /* TypeAliasDeclaration */: case 215 /* ExportAssignment */: return false; + case 181 /* VariableStatement */: + return shouldEmitLeadingAndTrailingCommentsForVariableStatement(node); case 206 /* ModuleDeclaration */: // Only emit the leading/trailing comments for a module if we're actually // emitting the module as well. @@ -29656,7 +30944,7 @@ var ts; /* @internal */ ts.ioReadTime = 0; /* @internal */ ts.ioWriteTime = 0; /** The version of the TypeScript compiler release */ - ts.version = "1.5.2"; + ts.version = "1.5.3"; var carriageReturnLineFeed = "\r\n"; var lineFeed = "\n"; function findConfigFile(searchPath) { @@ -30108,18 +31396,18 @@ var ts; return allFilesBelongToPath; } function verifyCompilerOptions() { - if (options.separateCompilation) { + if (options.isolatedModules) { if (options.sourceMap) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceMap_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_sourceMap_cannot_be_specified_with_option_isolatedModules)); } if (options.declaration) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_declaration_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_declaration_cannot_be_specified_with_option_isolatedModules)); } if (options.noEmitOnError) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules)); } if (options.out) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_out_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_out_cannot_be_specified_with_option_isolatedModules)); } } if (options.inlineSourceMap) { @@ -30150,14 +31438,14 @@ var ts; } var languageVersion = options.target || 0 /* ES3 */; var firstExternalModuleSourceFile = ts.forEach(files, function (f) { return ts.isExternalModule(f) ? f : undefined; }); - if (options.separateCompilation) { + if (options.isolatedModules) { if (!options.module && languageVersion < 2 /* ES6 */) { - diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); } var firstNonExternalModuleSourceFile = ts.forEach(files, function (f) { return !ts.isExternalModule(f) && !ts.isDeclarationFile(f) ? f : undefined; }); if (firstNonExternalModuleSourceFile) { var span = ts.getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile); - diagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_separateCompilation_flag_is_provided)); + diagnostics.add(ts.createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, ts.Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); } } else if (firstExternalModuleSourceFile && languageVersion < 2 /* ES6 */ && !options.module) { @@ -30198,6 +31486,10 @@ var ts; diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration)); } } + if (options.emitDecoratorMetadata && + !options.experimentalDecorators) { + diagnostics.add(ts.createCompilerDiagnostic(ts.Diagnostics.Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified)); + } } } ts.createProgram = createProgram; @@ -30346,7 +31638,7 @@ var ts; paramType: ts.Diagnostics.LOCATION }, { - name: "separateCompilation", + name: "isolatedModules", type: "boolean" }, { @@ -30392,10 +31684,16 @@ var ts; type: "boolean", description: ts.Diagnostics.Watch_input_files }, + { + name: "experimentalDecorators", + type: "boolean", + description: ts.Diagnostics.Enables_experimental_support_for_ES7_decorators + }, { name: "emitDecoratorMetadata", type: "boolean", - experimental: true + experimental: true, + description: ts.Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators } ]; function parseCommandLine(commandLine) { @@ -30691,28 +31989,28 @@ var ts; switch (n.kind) { case 180 /* Block */: if (!ts.isFunctionBlock(n)) { - var parent_6 = n.parent; + var parent_7 = n.parent; var openBrace = ts.findChildOfKind(n, 14 /* OpenBraceToken */, sourceFile); var closeBrace = ts.findChildOfKind(n, 15 /* CloseBraceToken */, sourceFile); // Check if the block is standalone, or 'attached' to some parent statement. // If the latter, we want to collaps the block, but consider its hint span // to be the entire span of the parent. - if (parent_6.kind === 185 /* DoStatement */ || - parent_6.kind === 188 /* ForInStatement */ || - parent_6.kind === 189 /* ForOfStatement */ || - parent_6.kind === 187 /* ForStatement */ || - parent_6.kind === 184 /* IfStatement */ || - parent_6.kind === 186 /* WhileStatement */ || - parent_6.kind === 193 /* WithStatement */ || - parent_6.kind === 224 /* CatchClause */) { - addOutliningSpan(parent_6, openBrace, closeBrace, autoCollapse(n)); + if (parent_7.kind === 185 /* DoStatement */ || + parent_7.kind === 188 /* ForInStatement */ || + parent_7.kind === 189 /* ForOfStatement */ || + parent_7.kind === 187 /* ForStatement */ || + parent_7.kind === 184 /* IfStatement */ || + parent_7.kind === 186 /* WhileStatement */ || + parent_7.kind === 193 /* WithStatement */ || + parent_7.kind === 224 /* CatchClause */) { + addOutliningSpan(parent_7, openBrace, closeBrace, autoCollapse(n)); break; } - if (parent_6.kind === 197 /* TryStatement */) { + if (parent_7.kind === 197 /* TryStatement */) { // Could be the try-block, or the finally-block. - var tryStatement = parent_6; + var tryStatement = parent_7; if (tryStatement.tryBlock === n) { - addOutliningSpan(parent_6, openBrace, closeBrace, autoCollapse(n)); + addOutliningSpan(parent_7, openBrace, closeBrace, autoCollapse(n)); break; } else if (tryStatement.finallyBlock === n) { @@ -30779,12 +32077,12 @@ var ts; ts.forEach(program.getSourceFiles(), function (sourceFile) { cancellationToken.throwIfCancellationRequested(); var nameToDeclarations = sourceFile.getNamedDeclarations(); - for (var name_23 in nameToDeclarations) { - var declarations = ts.getProperty(nameToDeclarations, name_23); + for (var name_26 in nameToDeclarations) { + var declarations = ts.getProperty(nameToDeclarations, name_26); if (declarations) { // First do a quick check to see if the name of the declaration matches the // last portion of the (possibly) dotted name they're searching for. - var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_23); + var matches = patternMatcher.getMatchesForLastSegmentOfPattern(name_26); if (!matches) { continue; } @@ -30797,14 +32095,14 @@ var ts; if (!containers) { return undefined; } - matches = patternMatcher.getMatches(containers, name_23); + matches = patternMatcher.getMatches(containers, name_26); if (!matches) { continue; } } var fileName = sourceFile.fileName; var matchKind = bestMatchKind(matches); - rawItems.push({ name: name_23, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); + rawItems.push({ name: name_26, fileName: fileName, matchKind: matchKind, isCaseSensitive: allMatchesAreCaseSensitive(matches), declaration: declaration }); } } } @@ -31187,9 +32485,9 @@ var ts; case 199 /* VariableDeclaration */: case 153 /* BindingElement */: var variableDeclarationNode; - var name_24; + var name_27; if (node.kind === 153 /* BindingElement */) { - name_24 = node.name; + name_27 = node.name; variableDeclarationNode = node; // binding elements are added only for variable declarations // bubble up to the containing variable declaration @@ -31201,16 +32499,16 @@ var ts; else { ts.Debug.assert(!ts.isBindingPattern(node.name)); variableDeclarationNode = node; - name_24 = node.name; + name_27 = node.name; } if (ts.isConst(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.constElement); + return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.constElement); } else if (ts.isLet(variableDeclarationNode)) { - return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.letElement); + return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.letElement); } else { - return createItem(node, getTextOfNode(name_24), ts.ScriptElementKind.variableElement); + return createItem(node, getTextOfNode(name_27), ts.ScriptElementKind.variableElement); } case 136 /* Constructor */: return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement); @@ -32732,7 +34030,7 @@ var ts; // for the position of the relevant node (or comma). var syntaxList = ts.forEach(node.parent.getChildren(), function (c) { // find syntax list that covers the span of the node - if (c.kind === 229 /* SyntaxList */ && c.pos <= node.pos && c.end >= node.end) { + if (c.kind === 251 /* SyntaxList */ && c.pos <= node.pos && c.end >= node.end) { return c; } }); @@ -33139,10 +34437,6 @@ var ts; }); } ts.signatureToDisplayParts = signatureToDisplayParts; - function isJavaScript(fileName) { - return ts.fileExtensionIs(fileName, ".js"); - } - ts.isJavaScript = isJavaScript; })(ts || (ts = {})); /// /// @@ -33625,7 +34919,7 @@ var ts; this.NoSpaceBeforeOpenBracket = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 18 /* OpenBracketToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); this.NoSpaceAfterOpenBracket = new formatting.Rule(formatting.RuleDescriptor.create3(18 /* OpenBracketToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); this.NoSpaceBeforeCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 19 /* CloseBracketToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); - this.NoSpaceAfterCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create3(19 /* CloseBracketToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); + this.NoSpaceAfterCloseBracket = new formatting.Rule(formatting.RuleDescriptor.create3(19 /* CloseBracketToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBeforeBlockInFunctionDeclarationContext), 8 /* Delete */)); // Place a space before open brace in a function declaration this.FunctionOpenBraceLeftTokenRange = formatting.Shared.TokenRange.AnyIncludingMultilineComments; this.SpaceBeforeOpenBraceInFunction = new formatting.Rule(formatting.RuleDescriptor.create2(this.FunctionOpenBraceLeftTokenRange, 14 /* OpenBraceToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclContext, Rules.IsBeforeBlockContext, Rules.IsNotFormatOnEnter, Rules.IsSameLineTokenOrBeforeMultilineBlockContext), 2 /* Space */), 1 /* CanDeleteNewLines */); @@ -33708,6 +35002,10 @@ var ts; this.SpaceBeforeAt = new formatting.Rule(formatting.RuleDescriptor.create2(formatting.Shared.TokenRange.Any, 52 /* AtToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 2 /* Space */)); this.NoSpaceAfterAt = new formatting.Rule(formatting.RuleDescriptor.create3(52 /* AtToken */, formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext), 8 /* Delete */)); this.SpaceAfterDecorator = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.Any, formatting.Shared.TokenRange.FromTokens([65 /* Identifier */, 78 /* ExportKeyword */, 73 /* DefaultKeyword */, 69 /* ClassKeyword */, 109 /* StaticKeyword */, 108 /* PublicKeyword */, 106 /* PrivateKeyword */, 107 /* ProtectedKeyword */, 116 /* GetKeyword */, 121 /* SetKeyword */, 18 /* OpenBracketToken */, 35 /* AsteriskToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), 2 /* Space */)); + this.NoSpaceBetweenFunctionKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(83 /* FunctionKeyword */, 35 /* AsteriskToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 8 /* Delete */)); + this.SpaceAfterStarInGeneratorDeclaration = new formatting.Rule(formatting.RuleDescriptor.create3(35 /* AsteriskToken */, formatting.Shared.TokenRange.FromTokens([65 /* Identifier */, 16 /* OpenParenToken */])), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), 2 /* Space */)); + this.NoSpaceBetweenYieldKeywordAndStar = new formatting.Rule(formatting.RuleDescriptor.create1(110 /* YieldKeyword */, 35 /* AsteriskToken */), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 8 /* Delete */)); + this.SpaceBetweenYieldOrYieldStarAndOperand = new formatting.Rule(formatting.RuleDescriptor.create4(formatting.Shared.TokenRange.FromTokens([110 /* YieldKeyword */, 35 /* AsteriskToken */]), formatting.Shared.TokenRange.Any), formatting.RuleOperation.create2(new formatting.RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), 2 /* Space */)); // These rules are higher in priority than user-configurable rules. this.HighPriorityCommonRules = [ @@ -33725,7 +35023,9 @@ var ts; this.NoSpaceAfterCloseBrace, this.SpaceAfterOpenBrace, this.SpaceBeforeCloseBrace, this.NewLineBeforeCloseBraceInBlockContext, this.SpaceAfterCloseBrace, this.SpaceBetweenCloseBraceAndElse, this.SpaceBetweenCloseBraceAndWhile, this.NoSpaceBetweenEmptyBraceBrackets, + this.NoSpaceBetweenFunctionKeywordAndStar, this.SpaceAfterStarInGeneratorDeclaration, this.SpaceAfterFunctionInFuncDecl, this.NewLineAfterOpenBraceInBlockContext, this.SpaceAfterGetSetInMember, + this.NoSpaceBetweenYieldKeywordAndStar, this.SpaceBetweenYieldOrYieldStarAndOperand, this.NoSpaceBetweenReturnAndSemicolon, this.SpaceAfterCertainKeywords, this.SpaceAfterLetConstInVariableDeclaration, @@ -33797,9 +35097,9 @@ var ts; } Rules.prototype.getRuleName = function (rule) { var o = this; - for (var name_25 in o) { - if (o[name_25] === rule) { - return name_25; + for (var name_28 in o) { + if (o[name_28] === rule) { + return name_28; } } throw new Error("Unknown rule"); @@ -33918,6 +35218,9 @@ var ts; } return false; }; + Rules.IsFunctionDeclarationOrFunctionExpressionContext = function (context) { + return context.contextNode.kind === 201 /* FunctionDeclaration */ || context.contextNode.kind === 163 /* FunctionExpression */; + }; Rules.IsTypeScriptDeclWithBlockContext = function (context) { return Rules.NodeIsTypeScriptDeclWithBlockContext(context.contextNode); }; @@ -33982,6 +35285,9 @@ var ts; Rules.IsSameLineTokenContext = function (context) { return context.TokensAreOnSameLine(); }; + Rules.IsNotBeforeBlockInFunctionDeclarationContext = function (context) { + return !Rules.IsFunctionDeclContext(context) && !Rules.IsBeforeBlockContext(context); + }; Rules.IsEndOfDecoratorContextOnSameLine = function (context) { return context.TokensAreOnSameLine() && context.contextNode.decorators && @@ -34036,6 +35342,9 @@ var ts; Rules.IsVoidOpContext = function (context) { return context.currentTokenSpan.kind === 99 /* VoidKeyword */ && context.currentTokenParent.kind === 167 /* VoidExpression */; }; + Rules.IsYieldOrYieldStarWithOperand = function (context) { + return context.contextNode.kind === 173 /* YieldExpression */ && context.contextNode.expression !== undefined; + }; return Rules; })(); formatting.Rules = Rules; @@ -35740,7 +37049,7 @@ var ts; return pos; }; NodeObject.prototype.createSyntaxList = function (nodes) { - var list = createNode(229 /* SyntaxList */, nodes.pos, nodes.end, 1024 /* Synthetic */, this); + var list = createNode(251 /* SyntaxList */, nodes.pos, nodes.end, 1024 /* Synthetic */, this); list._children = []; var pos = nodes.pos; for (var _i = 0; _i < nodes.length; _i++) { @@ -36495,6 +37804,7 @@ var ts; ClassificationTypeNames.typeParameterName = "type parameter name"; ClassificationTypeNames.typeAliasName = "type alias name"; ClassificationTypeNames.parameterName = "parameter name"; + ClassificationTypeNames.docCommentTagName = "doc comment tag name"; return ClassificationTypeNames; })(); ts.ClassificationTypeNames = ClassificationTypeNames; @@ -36516,6 +37826,7 @@ var ts; ClassificationType[ClassificationType["typeParameterName"] = 15] = "typeParameterName"; ClassificationType[ClassificationType["typeAliasName"] = 16] = "typeAliasName"; ClassificationType[ClassificationType["parameterName"] = 17] = "parameterName"; + ClassificationType[ClassificationType["docCommentTagName"] = 18] = "docCommentTagName"; })(ts.ClassificationType || (ts.ClassificationType = {})); var ClassificationType = ts.ClassificationType; function displayPartsToString(displayParts) { @@ -36538,9 +37849,9 @@ var ts; return false; } // If the parent is not sourceFile or module block it is local variable - for (var parent_7 = declaration.parent; !ts.isFunctionBlock(parent_7); parent_7 = parent_7.parent) { + for (var parent_8 = declaration.parent; !ts.isFunctionBlock(parent_8); parent_8 = parent_8.parent) { // Reached source file or module block - if (parent_7.kind === 228 /* SourceFile */ || parent_7.kind === 207 /* ModuleBlock */) { + if (parent_8.kind === 228 /* SourceFile */ || parent_8.kind === 207 /* ModuleBlock */) { return false; } } @@ -36687,12 +37998,12 @@ var ts; * This function will compile source text from 'input' argument using specified compiler options. * If not options are provided - it will use a set of default compiler options. * Extra compiler options that will unconditionally be used bu this function are: - * - separateCompilation = true + * - isolatedModules = true * - allowNonTsExtensions = true */ function transpile(input, compilerOptions, fileName, diagnostics) { var options = compilerOptions ? ts.clone(compilerOptions) : getDefaultCompilerOptions(); - options.separateCompilation = true; + options.isolatedModules = true; // Filename can be non-ts file. options.allowNonTsExtensions = true; // Parse @@ -36728,7 +38039,8 @@ var ts; } ts.transpile = transpile; function createLanguageServiceSourceFile(fileName, scriptSnapshot, scriptTarget, version, setNodeParents) { - var sourceFile = ts.createSourceFile(fileName, scriptSnapshot.getText(0, scriptSnapshot.getLength()), scriptTarget, setNodeParents); + var text = scriptSnapshot.getText(0, scriptSnapshot.getLength()); + var sourceFile = ts.createSourceFile(fileName, text, scriptTarget, setNodeParents); setSourceFileFields(sourceFile, scriptSnapshot, version); // after full parsing we can use table with interned strings as name table sourceFile.nameTable = sourceFile.identifiers; @@ -36743,7 +38055,30 @@ var ts; if (version !== sourceFile.version) { // Once incremental parsing is ready, then just call into this function. if (!ts.disableIncrementalParsing) { - var newSourceFile = ts.updateSourceFile(sourceFile, scriptSnapshot.getText(0, scriptSnapshot.getLength()), textChangeRange, aggressiveChecks); + var newText; + // grab the fragment from the beginning of the original text to the beginning of the span + var prefix = textChangeRange.span.start !== 0 + ? sourceFile.text.substr(0, textChangeRange.span.start) + : ""; + // grab the fragment from the end of the span till the end of the original text + var suffix = ts.textSpanEnd(textChangeRange.span) !== sourceFile.text.length + ? sourceFile.text.substr(ts.textSpanEnd(textChangeRange.span)) + : ""; + if (textChangeRange.newLength === 0) { + // edit was a deletion - just combine prefix and suffix + newText = prefix && suffix ? prefix + suffix : prefix || suffix; + } + else { + // it was actual edit, fetch the fragment of new text that correspond to new span + var changedText = scriptSnapshot.getText(textChangeRange.span.start, textChangeRange.span.start + textChangeRange.newLength); + // combine prefix, changed text and suffix + newText = prefix && suffix + ? prefix + changedText + suffix + : prefix + ? (prefix + changedText) + : (changedText + suffix); + } + var newSourceFile = ts.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks); setSourceFileFields(newSourceFile, scriptSnapshot, version); // after incremental parsing nameTable might not be up-to-date // drop it so it can be lazily recreated later @@ -37299,12 +38634,16 @@ var ts; } } } + // hostCache is captured in the closure for 'getOrCreateSourceFile' but it should not be used past this point. + // It needs to be cleared to allow all collected snapshots to be released + hostCache = undefined; program = newProgram; // Make sure all the nodes in the program are both bound, and have their parent // pointers set property. program.getTypeChecker(); return; function getOrCreateSourceFile(fileName) { + ts.Debug.assert(hostCache !== undefined); // The program is asking for this file, check first if the host can locate it. // If the host can not locate the file, then it does not exist. return undefined // to the program to allow reporting of errors for missing files. @@ -37495,7 +38834,7 @@ var ts; return true; } if (parameter.questionToken) { - diagnostics.push(ts.createDiagnosticForNode(parameter.questionToken, ts.Diagnostics.can_only_be_used_in_a_ts_file)); + diagnostics.push(ts.createDiagnosticForNode(parameter.questionToken, ts.Diagnostics._0_can_only_be_used_in_a_ts_file, '?')); return true; } if (parameter.type) { @@ -37612,6 +38951,7 @@ var ts; var typeChecker = program.getTypeChecker(); var syntacticStart = new Date().getTime(); var sourceFile = getValidSourceFile(fileName); + var isJavaScriptFile = ts.isJavaScript(fileName); var start = new Date().getTime(); var currentToken = ts.getTokenAtPosition(sourceFile, position); log("getCompletionData: Get current token: " + (new Date().getTime() - start)); @@ -37694,13 +39034,29 @@ var ts; } } var type = typeChecker.getTypeAtLocation(node); + addTypeProperties(type); + } + function addTypeProperties(type) { if (type) { // Filter private properties - ts.forEach(type.getApparentProperties(), function (symbol) { + for (var _i = 0, _a = type.getApparentProperties(); _i < _a.length; _i++) { + var symbol = _a[_i]; if (typeChecker.isValidPropertyAccess((node.parent), symbol.name)) { symbols.push(symbol); } - }); + } + if (isJavaScriptFile && type.flags & 16384 /* Union */) { + // In javascript files, for union types, we don't just get the members that + // the individual types have in common, we also include all the members that + // each individual type has. This is because we're going to add all identifiers + // anyways. So we might as well elevate the members that were at least part + // of the individual types to a higher status since we know what they are. + var unionType = type; + for (var _b = 0, _c = unionType.types; _b < _c.length; _b++) { + var elementType = _c[_b]; + addTypeProperties(elementType); + } + } } } function tryGetGlobalSymbols() { @@ -37861,15 +39217,18 @@ var ts; if (previousToken.kind === 8 /* StringLiteral */ || previousToken.kind === 9 /* RegularExpressionLiteral */ || ts.isTemplateLiteralKind(previousToken.kind)) { - // The position has to be either: 1. entirely within the token text, or - // 2. at the end position of an unterminated token. var start_3 = previousToken.getStart(); var end = previousToken.getEnd(); + // To be "in" one of these literals, the position has to be: + // 1. entirely within the token text. + // 2. at the end position of an unterminated token. + // 3. at the end of a regular expression (due to trailing flags like '/foo/g'). if (start_3 < position && position < end) { return true; } - else if (position === end) { - return !!previousToken.isUnterminated; + if (position === end) { + return !!previousToken.isUnterminated || + previousToken.kind === 9 /* RegularExpressionLiteral */; } } return false; @@ -37877,12 +39236,12 @@ var ts; function getContainingObjectLiteralApplicableForCompletion(previousToken) { // The locations in an object literal expression that are applicable for completion are property name definition locations. if (previousToken) { - var parent_8 = previousToken.parent; + var parent_9 = previousToken.parent; switch (previousToken.kind) { case 14 /* OpenBraceToken */: // let x = { | case 23 /* CommaToken */: - if (parent_8 && parent_8.kind === 155 /* ObjectLiteralExpression */) { - return parent_8; + if (parent_9 && parent_9.kind === 155 /* ObjectLiteralExpression */) { + return parent_9; } break; } @@ -38065,10 +39424,10 @@ var ts; for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) { var sourceFile = _a[_i]; var nameTable = getNameTable(sourceFile); - for (var name_26 in nameTable) { - if (!allNames[name_26]) { - allNames[name_26] = name_26; - var displayName = getCompletionEntryDisplayName(name_26, target, true); + for (var name_29 in nameTable) { + if (!allNames[name_29]) { + allNames[name_29] = name_29; + var displayName = getCompletionEntryDisplayName(name_29, target, true); if (displayName) { var entry = { name: displayName, @@ -38976,19 +40335,19 @@ var ts; function getThrowStatementOwner(throwStatement) { var child = throwStatement; while (child.parent) { - var parent_9 = child.parent; - if (ts.isFunctionBlock(parent_9) || parent_9.kind === 228 /* SourceFile */) { - return parent_9; + var parent_10 = child.parent; + if (ts.isFunctionBlock(parent_10) || parent_10.kind === 228 /* SourceFile */) { + return parent_10; } // A throw-statement is only owned by a try-statement if the try-statement has // a catch clause, and if the throw-statement occurs within the try block. - if (parent_9.kind === 197 /* TryStatement */) { - var tryStatement = parent_9; + if (parent_10.kind === 197 /* TryStatement */) { + var tryStatement = parent_10; if (tryStatement.tryBlock === child && tryStatement.catchClause) { return child; } } - child = parent_9; + child = parent_10; } return undefined; } @@ -39950,19 +41309,19 @@ var ts; if (isNameOfPropertyAssignment(node)) { var objectLiteral = node.parent.parent; var contextualType = typeChecker.getContextualType(objectLiteral); - var name_27 = node.text; + var name_30 = node.text; if (contextualType) { if (contextualType.flags & 16384 /* Union */) { // This is a union type, first see if the property we are looking for is a union property (i.e. exists in all types) // if not, search the constituent types for the property - var unionProperty = contextualType.getProperty(name_27); + var unionProperty = contextualType.getProperty(name_30); if (unionProperty) { return [unionProperty]; } else { var result_4 = []; ts.forEach(contextualType.types, function (t) { - var symbol = t.getProperty(name_27); + var symbol = t.getProperty(name_30); if (symbol) { result_4.push(symbol); } @@ -39971,7 +41330,7 @@ var ts; } } else { - var symbol_1 = contextualType.getProperty(name_27); + var symbol_1 = contextualType.getProperty(name_30); if (symbol_1) { return [symbol_1]; } @@ -40348,6 +41707,7 @@ var ts; case 15 /* typeParameterName */: return ClassificationTypeNames.typeParameterName; case 16 /* typeAliasName */: return ClassificationTypeNames.typeAliasName; case 17 /* parameterName */: return ClassificationTypeNames.parameterName; + case 18 /* docCommentTagName */: return ClassificationTypeNames.docCommentTagName; } } function convertClassifications(classifications) { @@ -40398,8 +41758,7 @@ var ts; // Only bother with the trivia if it at least intersects the span of interest. if (ts.textSpanIntersectsWith(span, start, width)) { if (ts.isComment(kind)) { - // Simple comment. Just add as is. - pushClassification(start, width, 1 /* comment */); + classifyComment(token, kind, start, width); continue; } if (kind === 6 /* ConflictMarkerTrivia */) { @@ -40419,6 +41778,79 @@ var ts; } } } + function classifyComment(token, kind, start, width) { + if (kind === 3 /* MultiLineCommentTrivia */) { + // See if this is a doc comment. If so, we'll classify certain portions of it + // specially. + var docCommentAndDiagnostics = ts.parseIsolatedJSDocComment(sourceFile.text, start, width); + if (docCommentAndDiagnostics && docCommentAndDiagnostics.jsDocComment) { + docCommentAndDiagnostics.jsDocComment.parent = token; + classifyJSDocComment(docCommentAndDiagnostics.jsDocComment); + return; + } + } + // Simple comment. Just add as is. + pushCommentRange(start, width); + } + function pushCommentRange(start, width) { + pushClassification(start, width, 1 /* comment */); + } + function classifyJSDocComment(docComment) { + var pos = docComment.pos; + for (var _i = 0, _a = docComment.tags; _i < _a.length; _i++) { + var tag = _a[_i]; + // As we walk through each tag, classify the portion of text from the end of + // the last tag (or the start of the entire doc comment) as 'comment'. + if (tag.pos !== pos) { + pushCommentRange(pos, tag.pos - pos); + } + pushClassification(tag.atToken.pos, tag.atToken.end - tag.atToken.pos, 10 /* punctuation */); + pushClassification(tag.tagName.pos, tag.tagName.end - tag.tagName.pos, 18 /* docCommentTagName */); + pos = tag.tagName.end; + switch (tag.kind) { + case 247 /* JSDocParameterTag */: + processJSDocParameterTag(tag); + break; + case 250 /* JSDocTemplateTag */: + processJSDocTemplateTag(tag); + break; + case 249 /* JSDocTypeTag */: + processElement(tag.typeExpression); + break; + case 248 /* JSDocReturnTag */: + processElement(tag.typeExpression); + break; + } + pos = tag.end; + } + if (pos !== docComment.end) { + pushCommentRange(pos, docComment.end - pos); + } + return; + function processJSDocParameterTag(tag) { + if (tag.preParameterName) { + pushCommentRange(pos, tag.preParameterName.pos - pos); + pushClassification(tag.preParameterName.pos, tag.preParameterName.end - tag.preParameterName.pos, 17 /* parameterName */); + pos = tag.preParameterName.end; + } + if (tag.typeExpression) { + pushCommentRange(pos, tag.typeExpression.pos - pos); + processElement(tag.typeExpression); + pos = tag.typeExpression.end; + } + if (tag.postParameterName) { + pushCommentRange(pos, tag.postParameterName.pos - pos); + pushClassification(tag.postParameterName.pos, tag.postParameterName.end - tag.postParameterName.pos, 17 /* parameterName */); + pos = tag.postParameterName.end; + } + } + } + function processJSDocTemplateTag(tag) { + for (var _i = 0, _a = tag.getChildren(); _i < _a.length; _i++) { + var child = _a[_i]; + processElement(child); + } + } function classifyDisabledMergeCode(text, start, end) { // Classify the line that the ======= marker is on as a comment. Then just lex // all further tokens and add them to the result. @@ -40539,9 +41971,12 @@ var ts; } } function processElement(element) { + if (!element) { + return; + } // Ignore nodes that don't intersect the original span to classify. if (ts.textSpanIntersectsWith(span, element.getFullStart(), element.getFullWidth())) { - var children = element.getChildren(); + var children = element.getChildren(sourceFile); for (var _i = 0; _i < children.length; _i++) { var child = children[_i]; if (ts.isToken(child)) { @@ -40952,7 +42387,7 @@ var ts; var lastEnd = 0; for (var i = 0, n = dense.length; i < n; i += 3) { var start = dense[i]; - var length_1 = dense[i + 1]; + var length_2 = dense[i + 1]; var type = dense[i + 2]; // Make a whitespace entry between the last item and this one. if (lastEnd >= 0) { @@ -40961,8 +42396,8 @@ var ts; entries.push({ length: whitespaceLength_1, classification: TokenClass.Whitespace }); } } - entries.push({ length: length_1, classification: convertClassification(type) }); - lastEnd = start + length_1; + entries.push({ length: length_2, classification: convertClassification(type) }); + lastEnd = start + length_2; } var whitespaceLength = text.length - lastEnd; if (whitespaceLength > 0) { @@ -42444,4 +43879,4 @@ var TypeScript; })(Services = TypeScript.Services || (TypeScript.Services = {})); })(TypeScript || (TypeScript = {})); /* @internal */ -var toolsVersion = "1.4"; +var toolsVersion = "1.5"; diff --git a/package.json b/package.json index 88d5db51f7..d6a8f538b7 100644 --- a/package.json +++ b/package.json @@ -2,13 +2,8 @@ "name": "typescript", "author": "Microsoft Corp.", "homepage": "http://typescriptlang.org/", - "version": "1.5.2", - "licenses": [ - { - "type": "Apache License 2.0", - "url": "https://github.com/Microsoft/TypeScript/blob/master/LICENSE.txt" - } - ], + "version": "1.5.3", + "license": "Apache-2.0", "description": "TypeScript is a language for application scale JavaScript development", "keywords": [ "TypeScript", diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index b66497fc40..ea58989124 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -52,13 +52,38 @@ module ts { } } - export function bindSourceFile(file: SourceFile): void { + const enum ContainerFlags { + // The current node is not a container, and no container manipulation should happen before + // recursing into it. + None = 0, + + // The current node is a container. It should be set as the current container (and block- + // container) before recursing into it. The current node does not have locals. Examples: + // + // Classes, ObjectLiterals, TypeLiterals, Interfaces... + IsContainer = 1 << 0, + + // The current node is a block-scoped-container. It should be set as the current block- + // container before recursing into it. Examples: + // + // Blocks (when not parented by functions), Catch clauses, For/For-in/For-of statements... + IsBlockScopedContainer = 1 << 1, + + HasLocals = 1 << 2, + + // If the current node is a container that also container that also contains locals. Examples: + // + // Functions, Methods, Modules, Source-files. + IsContainerWithLocals = IsContainer | HasLocals + } + + export function bindSourceFile(file: SourceFile) { let start = new Date().getTime(); bindSourceFileWorker(file); bindTime += new Date().getTime() - start; } - function bindSourceFileWorker(file: SourceFile): void { + function bindSourceFileWorker(file: SourceFile) { let parent: Node; let container: Node; let blockScopeContainer: Node; @@ -67,33 +92,38 @@ module ts { let Symbol = objectAllocator.getSymbolConstructor(); if (!file.locals) { - file.locals = {}; - container = file; - setBlockScopeContainer(file, /*cleanLocals*/ false); bind(file); file.symbolCount = symbolCount; } + return; + function createSymbol(flags: SymbolFlags, name: string): Symbol { symbolCount++; return new Symbol(flags, name); } - function setBlockScopeContainer(node: Node, cleanLocals: boolean) { - blockScopeContainer = node; - if (cleanLocals) { - blockScopeContainer.locals = undefined; - } - } + function addDeclarationToSymbol(symbol: Symbol, node: Declaration, symbolFlags: SymbolFlags) { + symbol.flags |= symbolFlags; - function addDeclarationToSymbol(symbol: Symbol, node: Declaration, symbolKind: SymbolFlags) { - symbol.flags |= symbolKind; - if (!symbol.declarations) symbol.declarations = []; - symbol.declarations.push(node); - if (symbolKind & SymbolFlags.HasExports && !symbol.exports) symbol.exports = {}; - if (symbolKind & SymbolFlags.HasMembers && !symbol.members) symbol.members = {}; node.symbol = symbol; - if (symbolKind & SymbolFlags.Value && !symbol.valueDeclaration) symbol.valueDeclaration = node; + + if (!symbol.declarations) { + symbol.declarations = []; + } + symbol.declarations.push(node); + + if (symbolFlags & SymbolFlags.HasExports && !symbol.exports) { + symbol.exports = {}; + } + + if (symbolFlags & SymbolFlags.HasMembers && !symbol.members) { + symbol.members = {}; + } + + if (symbolFlags & SymbolFlags.Value && !symbol.valueDeclaration) { + symbol.valueDeclaration = node; + } } // Should not be called on a declaration with a computed property name, @@ -111,12 +141,12 @@ module ts { return (node.name).text; } switch (node.kind) { - case SyntaxKind.ConstructorType: case SyntaxKind.Constructor: return "__constructor"; case SyntaxKind.FunctionType: case SyntaxKind.CallSignature: return "__call"; + case SyntaxKind.ConstructorType: case SyntaxKind.ConstructSignature: return "__new"; case SyntaxKind.IndexSignature: @@ -135,7 +165,7 @@ module ts { return node.name ? declarationNameToString(node.name) : getDeclarationName(node); } - function declareSymbol(symbols: SymbolTable, parent: Symbol, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags): Symbol { + function declareSymbol(symbolTable: SymbolTable, parent: Symbol, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags): Symbol { Debug.assert(!hasDynamicName(node)); // The exported symbol for an export default function/class node is always named "default" @@ -143,7 +173,27 @@ module ts { let symbol: Symbol; if (name !== undefined) { - symbol = hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name)); + // Check and see if the symbol table already has a symbol with this name. If not, + // create a new symbol with this name and add it to the table. Note that we don't + // give the new symbol any flags *yet*. This ensures that it will not conflict + // witht he 'excludes' flags we pass in. + // + // If we do get an existing symbol, see if it conflicts with the new symbol we're + // creating. For example, a 'var' symbol and a 'class' symbol will conflict within + // the same symbol table. If we have a conflict, report the issue on each + // declaration we have for this symbol, and then create a new symbol for this + // declaration. + // + // If we created a new symbol, either because we didn't have a symbol with this name + // in the symbol table, or we conflicted with an existing symbol, then just add this + // node as the sole declaration of the new symbol. + // + // Otherwise, we'll be merging into a compatible existing symbol (for example when + // you have multiple 'vars' with the same name in the same container). In this case + // just add this node into the declarations list of the symbol. + symbol = hasProperty(symbolTable, name) + ? symbolTable[name] + : (symbolTable[name] = createSymbol(SymbolFlags.None, name)); if (symbol.flags & excludes) { if (node.name) { node.name.parent = node; @@ -152,51 +202,34 @@ module ts { // Report errors every position with duplicate declaration // Report errors on previous encountered declarations let message = symbol.flags & SymbolFlags.BlockScopedVariable - ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 + ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0; - forEach(symbol.declarations, declaration => { file.bindDiagnostics.push(createDiagnosticForNode(declaration.name || declaration, message, getDisplayName(declaration))); }); file.bindDiagnostics.push(createDiagnosticForNode(node.name || node, message, getDisplayName(node))); - symbol = createSymbol(0, name); + symbol = createSymbol(SymbolFlags.None, name); } } else { - symbol = createSymbol(0, "__missing"); + symbol = createSymbol(SymbolFlags.None, "__missing"); } + addDeclarationToSymbol(symbol, node, includes); symbol.parent = parent; - if ((node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression) && symbol.exports) { - // TypeScript 1.0 spec (April 2014): 8.4 - // Every class automatically contains a static property member named 'prototype', - // the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter. - // It is an error to explicitly declare a static property member with the name 'prototype'. - let prototypeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Prototype, "prototype"); - if (hasProperty(symbol.exports, prototypeSymbol.name)) { - if (node.name) { - node.name.parent = node; - } - file.bindDiagnostics.push(createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], - Diagnostics.Duplicate_identifier_0, prototypeSymbol.name)); - } - symbol.exports[prototypeSymbol.name] = prototypeSymbol; - prototypeSymbol.parent = symbol; - } - return symbol; } - function declareModuleMember(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags) { + function declareModuleMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags): Symbol { let hasExportModifier = getCombinedNodeFlags(node) & NodeFlags.Export; - if (symbolKind & SymbolFlags.Alias) { + if (symbolFlags & SymbolFlags.Alias) { if (node.kind === SyntaxKind.ExportSpecifier || (node.kind === SyntaxKind.ImportEqualsDeclaration && hasExportModifier)) { - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); + return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); } else { - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); + return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } else { @@ -212,70 +245,172 @@ module ts { // but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way // when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope. if (hasExportModifier || container.flags & NodeFlags.ExportContext) { - let exportKind = (symbolKind & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) | - (symbolKind & SymbolFlags.Type ? SymbolFlags.ExportType : 0) | - (symbolKind & SymbolFlags.Namespace ? SymbolFlags.ExportNamespace : 0); + let exportKind = + (symbolFlags & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) | + (symbolFlags & SymbolFlags.Type ? SymbolFlags.ExportType : 0) | + (symbolFlags & SymbolFlags.Namespace ? SymbolFlags.ExportNamespace : 0); let local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); - local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); + local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); node.localSymbol = local; + return local; } else { - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); + return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } } } - // All container nodes are kept on a linked list in declaration order. This list is used by the getLocalNameOfContainer function - // in the type checker to validate that the local name used for a container is unique. - function bindChildren(node: Node, symbolKind: SymbolFlags, isBlockScopeContainer: boolean) { - if (symbolKind & SymbolFlags.HasLocals) { - node.locals = {}; - } - + // All container nodes are kept on a linked list in declaration order. This list is used by + // the getLocalNameOfContainer function in the type checker to validate that the local name + // used for a container is unique. + function bindChildren(node: Node) { + // Before we recurse into a node's chilren, we first save the existing parent, container + // and block-container. Then after we pop out of processing the children, we restore + // these saved values. let saveParent = parent; let saveContainer = container; let savedBlockScopeContainer = blockScopeContainer; + + // This node will now be set as the parent of all of its children as we recurse into them. parent = node; - if (symbolKind & SymbolFlags.IsContainer) { - container = node; + + // Depending on what kind of node this is, we may have to adjust the current container + // and block-container. If the current node is a container, then it is automatically + // considered the current block-container as well. Also, for containers that we know + // may contain locals, we proactively initialize the .locals field. We do this because + // it's highly likely that the .locals will be needed to place some child in (for example, + // a parameter, or variable declaration). + // + // However, we do not proactively create the .locals for block-containers because it's + // totally normal and common for block-containers to never actually have a block-scoped + // variable in them. We don't want to end up allocating an object for every 'block' we + // run into when most of them won't be necessary. + // + // Finally, if this is a block-container, then we clear out any existing .locals object + // it may contain within it. This happens in incremental scenarios. Because we can be + // reusing a node from a previous compilation, that node may have had 'locals' created + // for it. We must clear this so we don't accidently move any stale data forward from + // a previous compilation. + let containerFlags = getContainerFlags(node); + if (containerFlags & ContainerFlags.IsContainer) { + container = blockScopeContainer = node; + + if (containerFlags & ContainerFlags.HasLocals) { + container.locals = {}; + } addToContainerChain(container); } - - if (isBlockScopeContainer) { - // in incremental scenarios we might reuse nodes that already have locals being allocated - // during the bind step these locals should be dropped to prevent using stale data. - // locals should always be dropped unless they were previously initialized by the binder - // these cases are: - // - node has locals (symbolKind & HasLocals) !== 0 - // - node is a source file - setBlockScopeContainer(node, /*cleanLocals*/ (symbolKind & SymbolFlags.HasLocals) === 0 && node.kind !== SyntaxKind.SourceFile); + else if (containerFlags & ContainerFlags.IsBlockScopedContainer) { + blockScopeContainer = node; + blockScopeContainer.locals = undefined; } forEachChild(node, bind); + container = saveContainer; parent = saveParent; blockScopeContainer = savedBlockScopeContainer; } - function addToContainerChain(node: Node) { - if (lastContainer) { - lastContainer.nextContainer = node; + function getContainerFlags(node: Node): ContainerFlags { + switch (node.kind) { + case SyntaxKind.ClassExpression: + case SyntaxKind.ClassDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.EnumDeclaration: + case SyntaxKind.TypeLiteral: + case SyntaxKind.ObjectLiteralExpression: + return ContainerFlags.IsContainer; + + case SyntaxKind.CallSignature: + case SyntaxKind.ConstructSignature: + case SyntaxKind.IndexSignature: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.Constructor: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + case SyntaxKind.FunctionType: + case SyntaxKind.ConstructorType: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.SourceFile: + return ContainerFlags.IsContainerWithLocals; + + case SyntaxKind.CatchClause: + case SyntaxKind.ForStatement: + case SyntaxKind.ForInStatement: + case SyntaxKind.ForOfStatement: + case SyntaxKind.CaseBlock: + return ContainerFlags.IsBlockScopedContainer; + + case SyntaxKind.Block: + // do not treat blocks directly inside a function as a block-scoped-container. + // Locals that reside in this block should go to the function locals. Othewise 'x' + // would not appear to be a redeclaration of a block scoped local in the following + // example: + // + // function foo() { + // var x; + // let x; + // } + // + // If we placed 'var x' into the function locals and 'let x' into the locals of + // the block, then there would be no collision. + // + // By not creating a new block-scoped-container here, we ensure that both 'var x' + // and 'let x' go into the Function-container's locals, and we do get a collision + // conflict. + return isFunctionLike(node.parent) ? ContainerFlags.None : ContainerFlags.IsBlockScopedContainer; } - lastContainer = node; + return ContainerFlags.None; } - function bindDeclaration(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags, isBlockScopeContainer: boolean) { + function addToContainerChain(next: Node) { + if (lastContainer) { + lastContainer.nextContainer = next; + } + + lastContainer = next; + } + + function declareSymbolAndAddToSymbolTable(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags): void { + // Just call this directly so that the return type of this function stays "void". + declareSymbolAndAddToSymbolTableWorker(node, symbolFlags, symbolExcludes); + } + + function declareSymbolAndAddToSymbolTableWorker(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags): Symbol { switch (container.kind) { + // Modules, source files, and classes need specialized handling for how their + // members are declared (for example, a member of a class will go into a specific + // symbol table depending on if it is static or not). As such, we defer to + // specialized handlers to take care of declaring these child members. case SyntaxKind.ModuleDeclaration: - declareModuleMember(node, symbolKind, symbolExcludes); - break; + return declareModuleMember(node, symbolFlags, symbolExcludes); + case SyntaxKind.SourceFile: - if (isExternalModule(container)) { - declareModuleMember(node, symbolKind, symbolExcludes); - break; - } + return declareSourceFileMember(node, symbolFlags, symbolExcludes); + + case SyntaxKind.ClassExpression: + case SyntaxKind.ClassDeclaration: + return declareClassMember(node, symbolFlags, symbolExcludes); + + case SyntaxKind.EnumDeclaration: + return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes); + + case SyntaxKind.TypeLiteral: + case SyntaxKind.ObjectLiteralExpression: + case SyntaxKind.InterfaceDeclaration: + // Interface/Object-types always have their children added to the 'members' of + // their container. They are only accessible through an instance of their + // container, and are never in scope otherwise (even inside the body of the + // object / type / interface declaring them). + return declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); + case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: case SyntaxKind.CallSignature: @@ -289,29 +424,34 @@ module ts { case SyntaxKind.FunctionDeclaration: case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - declareSymbol(container.locals, undefined, node, symbolKind, symbolExcludes); - break; - case SyntaxKind.ClassExpression: - case SyntaxKind.ClassDeclaration: - if (node.flags & NodeFlags.Static) { - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); - break; - } - case SyntaxKind.TypeLiteral: - case SyntaxKind.ObjectLiteralExpression: - case SyntaxKind.InterfaceDeclaration: - declareSymbol(container.symbol.members, container.symbol, node, symbolKind, symbolExcludes); - break; - case SyntaxKind.EnumDeclaration: - declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); - break; + // All the children of these container types are never visible through another + // symbol (i.e. through another symbol's 'exports' or 'members'). Instead, + // they're only accessed 'lexically' (i.e. from code that exists underneath + // their container in the tree. To accomplish this, we simply add their declared + // symbol to the 'locals' of the container. These symbols can then be found as + // the type checker walks up the containers, checking them for matching names. + return declareSymbol(container.locals, undefined, node, symbolFlags, symbolExcludes); } - bindChildren(node, symbolKind, isBlockScopeContainer); + } + + function declareClassMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) { + return node.flags & NodeFlags.Static + ? declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes) + : declareSymbol(container.symbol.members, container.symbol, node, symbolFlags, symbolExcludes); + } + + function declareSourceFileMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) { + return isExternalModule(file) + ? declareModuleMember(node, symbolFlags, symbolExcludes) + : declareSymbol(file.locals, undefined, node, symbolFlags, symbolExcludes); } function isAmbientContext(node: Node): boolean { while (node) { - if (node.flags & NodeFlags.Ambient) return true; + if (node.flags & NodeFlags.Ambient) { + return true; + } + node = node.parent; } return false; @@ -343,15 +483,16 @@ module ts { function bindModuleDeclaration(node: ModuleDeclaration) { setExportContextFlag(node); if (node.name.kind === SyntaxKind.StringLiteral) { - bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true); + declareSymbolAndAddToSymbolTable(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes); } else { let state = getModuleInstanceState(node); if (state === ModuleInstanceState.NonInstantiated) { - bindDeclaration(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes, /*isBlockScopeContainer*/ true); + declareSymbolAndAddToSymbolTable(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes); } else { - bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true); + declareSymbolAndAddToSymbolTable(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes); + let currentModuleIsConstEnumOnly = state === ModuleInstanceState.ConstEnumOnly; if (node.symbol.constEnumOnlyModule === undefined) { // non-merged case - use the current state @@ -372,35 +513,27 @@ module ts { // We do that by making an anonymous type literal symbol, and then setting the function // symbol as its sole member. To the rest of the system, this symbol will be indistinguishable // from an actual type literal symbol you would have gotten had you used the long form. - let symbol = createSymbol(SymbolFlags.Signature, getDeclarationName(node)); addDeclarationToSymbol(symbol, node, SymbolFlags.Signature); - bindChildren(node, SymbolFlags.Signature, /*isBlockScopeContainer:*/ false); let typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type"); addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral); - typeLiteralSymbol.members = {}; - typeLiteralSymbol.members[node.kind === SyntaxKind.FunctionType ? "__call" : "__new"] = symbol + typeLiteralSymbol.members = { [symbol.name]: symbol }; } - function bindAnonymousDeclaration(node: Declaration, symbolKind: SymbolFlags, name: string, isBlockScopeContainer: boolean) { - let symbol = createSymbol(symbolKind, name); - addDeclarationToSymbol(symbol, node, symbolKind); - bindChildren(node, symbolKind, isBlockScopeContainer); + function bindAnonymousDeclaration(node: Declaration, symbolFlags: SymbolFlags, name: string) { + let symbol = createSymbol(symbolFlags, name); + addDeclarationToSymbol(symbol, node, symbolFlags); } - function bindCatchVariableDeclaration(node: CatchClause) { - bindChildren(node, /*symbolKind:*/ 0, /*isBlockScopeContainer:*/ true); - } - - function bindBlockScopedDeclaration(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags) { + function bindBlockScopedDeclaration(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) { switch (blockScopeContainer.kind) { case SyntaxKind.ModuleDeclaration: - declareModuleMember(node, symbolKind, symbolExcludes); + declareModuleMember(node, symbolFlags, symbolExcludes); break; case SyntaxKind.SourceFile: if (isExternalModule(container)) { - declareModuleMember(node, symbolKind, symbolExcludes); + declareModuleMember(node, symbolFlags, symbolExcludes); break; } // fall through. @@ -409,9 +542,8 @@ module ts { blockScopeContainer.locals = {}; addToContainerChain(blockScopeContainer); } - declareSymbol(blockScopeContainer.locals, undefined, node, symbolKind, symbolExcludes); + declareSymbol(blockScopeContainer.locals, undefined, node, symbolFlags, symbolExcludes); } - bindChildren(node, symbolKind, /*isBlockScopeContainer*/ false); } function bindBlockScopedVariableDeclaration(node: Declaration) { @@ -424,187 +556,197 @@ module ts { function bind(node: Node) { node.parent = parent; - + + // First we bind declaration nodes to a symbol if possible. We'll both create a symbol + // and then potentially add the symbol to an appropriate symbol table. Possible + // destination symbol tables are: + // + // 1) The 'exports' table of the current container's symbol. + // 2) The 'members' table of the current container's symbol. + // 3) The 'locals' table of the current container. + // + // However, not all symbols will end up in any of these tables. 'Anonymous' symbols + // (like TypeLiterals for example) will not be put in any table. + bindWorker(node); + + // Then we recurse into the children of the node to bind them as well. For certain + // symbols we do specialized work when we recurse. For example, we'll keep track of + // the current 'container' node when it changes. This helps us know which symbol table + // a local should go into for example. + bindChildren(node); + } + + function bindWorker(node: Node) { switch (node.kind) { case SyntaxKind.TypeParameter: - bindDeclaration(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes, /*isBlockScopeContainer*/ false); - break; + return declareSymbolAndAddToSymbolTable(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes); case SyntaxKind.Parameter: - bindParameter(node); - break; + return bindParameter(node); case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: - if (isBindingPattern((node).name)) { - bindChildren(node, 0, /*isBlockScopeContainer*/ false); - } - else if (isBlockOrCatchScoped(node)) { - bindBlockScopedVariableDeclaration(node); - } - else if (isParameterDeclaration(node)) { - // It is safe to walk up parent chain to find whether the node is a destructing parameter declaration - // because its parent chain has already been set up, since parents are set before descending into children. - // - // If node is a binding element in parameter declaration, we need to use ParameterExcludes. - // Using ParameterExcludes flag allows the compiler to report an error on duplicate identifiers in Parameter Declaration - // For example: - // function foo([a,a]) {} // Duplicate Identifier error - // function bar(a,a) {} // Duplicate Identifier error, parameter declaration in this case is handled in bindParameter - // // which correctly set excluded symbols - bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false); - } - else { - bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes, /*isBlockScopeContainer*/ false); - } - break; + return bindVariableDeclarationOrBindingElement(node); case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: - bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property | ((node).questionToken ? SymbolFlags.Optional : 0), SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); - break; + return bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property | ((node).questionToken ? SymbolFlags.Optional : SymbolFlags.None), SymbolFlags.PropertyExcludes); case SyntaxKind.PropertyAssignment: case SyntaxKind.ShorthandPropertyAssignment: - bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); - break; + return bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); case SyntaxKind.EnumMember: - bindPropertyOrMethodOrAccessor(node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes, /*isBlockScopeContainer*/ false); - break; + return bindPropertyOrMethodOrAccessor(node, SymbolFlags.EnumMember, SymbolFlags.EnumMemberExcludes); case SyntaxKind.CallSignature: case SyntaxKind.ConstructSignature: case SyntaxKind.IndexSignature: - bindDeclaration(node, SymbolFlags.Signature, 0, /*isBlockScopeContainer*/ false); - break; + return declareSymbolAndAddToSymbolTable(node, SymbolFlags.Signature, SymbolFlags.None); case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: // If this is an ObjectLiteralExpression method, then it sits in the same space // as other properties in the object literal. So we use SymbolFlags.PropertyExcludes // so that it will conflict with any other object literal members with the same // name. - bindPropertyOrMethodOrAccessor(node, SymbolFlags.Method | ((node).questionToken ? SymbolFlags.Optional : 0), - isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes, /*isBlockScopeContainer*/ true); - break; + return bindPropertyOrMethodOrAccessor(node, SymbolFlags.Method | ((node).questionToken ? SymbolFlags.Optional : SymbolFlags.None), + isObjectLiteralMethod(node) ? SymbolFlags.PropertyExcludes : SymbolFlags.MethodExcludes); case SyntaxKind.FunctionDeclaration: - bindDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes, /*isBlockScopeContainer*/ true); - break; + return declareSymbolAndAddToSymbolTable(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes); case SyntaxKind.Constructor: - bindDeclaration(node, SymbolFlags.Constructor, /*symbolExcludes:*/ 0, /*isBlockScopeContainer:*/ true); - break; + return declareSymbolAndAddToSymbolTable(node, SymbolFlags.Constructor, /*symbolExcludes:*/ SymbolFlags.None); case SyntaxKind.GetAccessor: - bindPropertyOrMethodOrAccessor(node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes, /*isBlockScopeContainer*/ true); - break; + return bindPropertyOrMethodOrAccessor(node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes); case SyntaxKind.SetAccessor: - bindPropertyOrMethodOrAccessor(node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes, /*isBlockScopeContainer*/ true); - break; - + return bindPropertyOrMethodOrAccessor(node, SymbolFlags.SetAccessor, SymbolFlags.SetAccessorExcludes); case SyntaxKind.FunctionType: case SyntaxKind.ConstructorType: - bindFunctionOrConstructorType(node); - break; - + return bindFunctionOrConstructorType(node); case SyntaxKind.TypeLiteral: - bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type", /*isBlockScopeContainer*/ false); - break; + return bindAnonymousDeclaration(node, SymbolFlags.TypeLiteral, "__type"); case SyntaxKind.ObjectLiteralExpression: - bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, "__object", /*isBlockScopeContainer*/ false); - break; + return bindAnonymousDeclaration(node, SymbolFlags.ObjectLiteral, "__object"); case SyntaxKind.FunctionExpression: case SyntaxKind.ArrowFunction: - bindAnonymousDeclaration(node, SymbolFlags.Function, "__function", /*isBlockScopeContainer*/ true); - break; + return bindAnonymousDeclaration(node, SymbolFlags.Function, "__function"); case SyntaxKind.ClassExpression: - bindAnonymousDeclaration(node, SymbolFlags.Class, "__class", /*isBlockScopeContainer*/ false); - break; - case SyntaxKind.CatchClause: - bindCatchVariableDeclaration(node); - break; case SyntaxKind.ClassDeclaration: - bindBlockScopedDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes); - break; + return bindClassLikeDeclaration(node); case SyntaxKind.InterfaceDeclaration: - bindDeclaration(node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes, /*isBlockScopeContainer*/ false); - break; + return bindBlockScopedDeclaration(node, SymbolFlags.Interface, SymbolFlags.InterfaceExcludes); case SyntaxKind.TypeAliasDeclaration: - bindDeclaration(node, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes, /*isBlockScopeContainer*/ false); - break; + return bindBlockScopedDeclaration(node, SymbolFlags.TypeAlias, SymbolFlags.TypeAliasExcludes); case SyntaxKind.EnumDeclaration: - if (isConst(node)) { - bindDeclaration(node, SymbolFlags.ConstEnum, SymbolFlags.ConstEnumExcludes, /*isBlockScopeContainer*/ false); - } - else { - bindDeclaration(node, SymbolFlags.RegularEnum, SymbolFlags.RegularEnumExcludes, /*isBlockScopeContainer*/ false); - } - break; + return bindEnumDeclaration(node); case SyntaxKind.ModuleDeclaration: - bindModuleDeclaration(node); - break; + return bindModuleDeclaration(node); case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.NamespaceImport: case SyntaxKind.ImportSpecifier: case SyntaxKind.ExportSpecifier: - bindDeclaration(node, SymbolFlags.Alias, SymbolFlags.AliasExcludes, /*isBlockScopeContainer*/ false); - break; + return declareSymbolAndAddToSymbolTable(node, SymbolFlags.Alias, SymbolFlags.AliasExcludes); case SyntaxKind.ImportClause: - if ((node).name) { - bindDeclaration(node, SymbolFlags.Alias, SymbolFlags.AliasExcludes, /*isBlockScopeContainer*/ false); - } - else { - bindChildren(node, 0, /*isBlockScopeContainer*/ false); - } - break; + return bindImportClause(node); case SyntaxKind.ExportDeclaration: - if (!(node).exportClause) { - // All export * declarations are collected in an __export symbol - declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.ExportStar, 0); - } - bindChildren(node, 0, /*isBlockScopeContainer*/ false); - break; + return bindExportDeclaration(node); case SyntaxKind.ExportAssignment: - if ((node).expression.kind === SyntaxKind.Identifier) { - // An export default clause with an identifier exports all meanings of that identifier - declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes); - } - else { - // An export default clause with an expression exports a value - declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes); - } - bindChildren(node, 0, /*isBlockScopeContainer*/ false); - break; + return bindExportAssignment(node); case SyntaxKind.SourceFile: - setExportContextFlag(node); - if (isExternalModule(node)) { - bindAnonymousDeclaration(node, SymbolFlags.ValueModule, '"' + removeFileExtension((node).fileName) + '"', /*isBlockScopeContainer*/ true); - break; - } - case SyntaxKind.Block: - // do not treat function block a block-scope container - // all block-scope locals that reside in this block should go to the function locals. - // Otherwise this won't be considered as redeclaration of a block scoped local: - // function foo() { - // let x; - // let x; - // } - // 'let x' will be placed into the function locals and 'let x' - into the locals of the block - bindChildren(node, 0, /*isBlockScopeContainer*/ !isFunctionLike(node.parent)); - break; - case SyntaxKind.CatchClause: - case SyntaxKind.ForStatement: - case SyntaxKind.ForInStatement: - case SyntaxKind.ForOfStatement: - case SyntaxKind.CaseBlock: - bindChildren(node, 0, /*isBlockScopeContainer*/ true); - break; - default: - let saveParent = parent; - parent = node; - forEachChild(node, bind); - parent = saveParent; + return bindSourceFileIfExternalModule(); + } + } + + function bindSourceFileIfExternalModule() { + setExportContextFlag(file); + if (isExternalModule(file)) { + bindAnonymousDeclaration(file, SymbolFlags.ValueModule, '"' + removeFileExtension(file.fileName) + '"'); + } + } + + function bindExportAssignment(node: ExportAssignment) { + if (node.expression.kind === SyntaxKind.Identifier) { + // An export default clause with an identifier exports all meanings of that identifier + declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Alias, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes); + } + else { + // An export default clause with an expression exports a value + declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes | SymbolFlags.AliasExcludes); + } + } + + function bindExportDeclaration(node: ExportDeclaration) { + if (!node.exportClause) { + // All export * declarations are collected in an __export symbol + declareSymbol(container.symbol.exports, container.symbol, node, SymbolFlags.ExportStar, SymbolFlags.None); + } + } + + function bindImportClause(node: ImportClause) { + if (node.name) { + declareSymbolAndAddToSymbolTable(node, SymbolFlags.Alias, SymbolFlags.AliasExcludes); + } + } + + function bindClassLikeDeclaration(node: ClassLikeDeclaration) { + if (node.kind === SyntaxKind.ClassDeclaration) { + bindBlockScopedDeclaration(node, SymbolFlags.Class, SymbolFlags.ClassExcludes); + } + else { + bindAnonymousDeclaration(node, SymbolFlags.Class, "__class"); + } + + let symbol = node.symbol; + + // TypeScript 1.0 spec (April 2014): 8.4 + // Every class automatically contains a static property member named 'prototype', the + // type of which is an instantiation of the class type with type Any supplied as a type + // argument for each type parameter. It is an error to explicitly declare a static + // property member with the name 'prototype'. + // + // Note: we check for this here because this class may be merging into a module. The + // module might have an exported variable called 'prototype'. We can't allow that as + // that would clash with the built-in 'prototype' for the class. + let prototypeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Prototype, "prototype"); + if (hasProperty(symbol.exports, prototypeSymbol.name)) { + if (node.name) { + node.name.parent = node; + } + file.bindDiagnostics.push(createDiagnosticForNode(symbol.exports[prototypeSymbol.name].declarations[0], + Diagnostics.Duplicate_identifier_0, prototypeSymbol.name)); + } + symbol.exports[prototypeSymbol.name] = prototypeSymbol; + prototypeSymbol.parent = symbol; + } + + function bindEnumDeclaration(node: EnumDeclaration) { + return isConst(node) + ? bindBlockScopedDeclaration(node, SymbolFlags.ConstEnum, SymbolFlags.ConstEnumExcludes) + : bindBlockScopedDeclaration(node, SymbolFlags.RegularEnum, SymbolFlags.RegularEnumExcludes); + } + + function bindVariableDeclarationOrBindingElement(node: VariableDeclaration | BindingElement) { + if (!isBindingPattern(node.name)) { + if (isBlockOrCatchScoped(node)) { + bindBlockScopedVariableDeclaration(node); + } + else if (isParameterDeclaration(node)) { + // It is safe to walk up parent chain to find whether the node is a destructing parameter declaration + // because its parent chain has already been set up, since parents are set before descending into children. + // + // If node is a binding element in parameter declaration, we need to use ParameterExcludes. + // Using ParameterExcludes flag allows the compiler to report an error on duplicate identifiers in Parameter Declaration + // For example: + // function foo([a,a]) {} // Duplicate Identifier error + // function bar(a,a) {} // Duplicate Identifier error, parameter declaration in this case is handled in bindParameter + // // which correctly set excluded symbols + declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes); + } + else { + declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.FunctionScopedVariableExcludes); + } } } function bindParameter(node: ParameterDeclaration) { if (isBindingPattern(node.name)) { - bindAnonymousDeclaration(node, SymbolFlags.FunctionScopedVariable, getDestructuringParameterName(node), /*isBlockScopeContainer*/ false); + bindAnonymousDeclaration(node, SymbolFlags.FunctionScopedVariable, getDestructuringParameterName(node)); } else { - bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false); + declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes); } // If this is a property-parameter, then also declare the property symbol into the @@ -618,13 +760,10 @@ module ts { } } - function bindPropertyOrMethodOrAccessor(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags, isBlockScopeContainer: boolean) { - if (hasDynamicName(node)) { - bindAnonymousDeclaration(node, symbolKind, "__computed", isBlockScopeContainer); - } - else { - bindDeclaration(node, symbolKind, symbolExcludes, isBlockScopeContainer); - } + function bindPropertyOrMethodOrAccessor(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags) { + return hasDynamicName(node) + ? bindAnonymousDeclaration(node, symbolFlags, "__computed") + : declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes); } } } diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 5d26a30c3b..6f59a4a25f 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -91,6 +91,9 @@ module ts { let circularType = createIntrinsicType(TypeFlags.Any, "__circular__"); let emptyObjectType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + let emptyGenericType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); + emptyGenericType.instantiations = {}; + let anyFunctionType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); let noConstraintType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); @@ -99,19 +102,20 @@ module ts { let globals: SymbolTable = {}; - let globalArraySymbol: Symbol; let globalESSymbolConstructorSymbol: Symbol; let globalObjectType: ObjectType; let globalFunctionType: ObjectType; - let globalArrayType: ObjectType; + let globalArrayType: GenericType; let globalStringType: ObjectType; let globalNumberType: ObjectType; let globalBooleanType: ObjectType; let globalRegExpType: ObjectType; let globalTemplateStringsArrayType: ObjectType; let globalESSymbolType: ObjectType; - let globalIterableType: ObjectType; + let globalIterableType: GenericType; + let globalIteratorType: GenericType; + let globalIterableIteratorType: GenericType; let anyArrayType: Type; let getGlobalClassDecoratorType: () => ObjectType; @@ -338,7 +342,15 @@ module ts { // Locals of a source file are not in scope (because they get merged into the global symbol table) if (location.locals && !isGlobalSourceFile(location)) { if (result = getSymbol(location.locals, name, meaning)) { - break loop; + // Type parameters of a function are in scope in the entire function declaration, including the parameter + // list and return type. However, local types are only in scope in the function body. + if (!(meaning & SymbolFlags.Type) || + !(result.flags & (SymbolFlags.Type & ~SymbolFlags.TypeParameter)) || + !isFunctionLike(location) || + lastLocation === (location).body) { + break loop; + } + result = undefined; } } switch (location.kind) { @@ -423,27 +435,32 @@ module ts { case SyntaxKind.SetAccessor: case SyntaxKind.FunctionDeclaration: case SyntaxKind.ArrowFunction: - if (name === "arguments") { + if (meaning & SymbolFlags.Variable && name === "arguments") { result = argumentsSymbol; break loop; } break; case SyntaxKind.FunctionExpression: - if (name === "arguments") { + if (meaning & SymbolFlags.Variable && name === "arguments") { result = argumentsSymbol; break loop; } - let functionName = (location).name; - if (functionName && name === functionName.text) { - result = location.symbol; - break loop; + + if (meaning & SymbolFlags.Function) { + let functionName = (location).name; + if (functionName && name === functionName.text) { + result = location.symbol; + break loop; + } } break; case SyntaxKind.ClassExpression: - let className = (location).name; - if (className && name === className.text) { - result = location.symbol; - break loop; + if (meaning & SymbolFlags.Class) { + let className = (location).name; + if (className && name === className.text) { + result = location.symbol; + break loop; + } } break; case SyntaxKind.Decorator: @@ -733,7 +750,7 @@ module ts { let target = resolveAlias(symbol); if (target) { let markAlias = - (target === unknownSymbol && compilerOptions.separateCompilation) || + (target === unknownSymbol && compilerOptions.isolatedModules) || (target !== unknownSymbol && (target.flags & SymbolFlags.Value) && !isConstEnumOrConstEnumOnlyModule(target)); if (markAlias) { @@ -1468,7 +1485,7 @@ module ts { return appendParentTypeArgumentsAndSymbolName(symbol); } - function buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, typeStack?: Type[]) { + function buildTypeDisplay(type: Type, writer: SymbolWriter, enclosingDeclaration?: Node, globalFlags?: TypeFormatFlags, symbolStack?: Symbol[]) { let globalFlagsToPass = globalFlags & TypeFormatFlags.WriteOwnNameForAnyLike; return writeType(type, globalFlags); @@ -1522,17 +1539,55 @@ module ts { } } + function writeSymbolTypeReference(symbol: Symbol, typeArguments: Type[], pos: number, end: number) { + // Unnamed function expressions, arrow functions, and unnamed class expressions have reserved names that + // we don't want to display + if (!isReservedMemberName(symbol.name)) { + buildSymbolDisplay(symbol, writer, enclosingDeclaration, SymbolFlags.Type); + } + if (pos < end) { + writePunctuation(writer, SyntaxKind.LessThanToken); + writeType(typeArguments[pos++], TypeFormatFlags.None); + while (pos < end) { + writePunctuation(writer, SyntaxKind.CommaToken); + writeSpace(writer); + writeType(typeArguments[pos++], TypeFormatFlags.None); + } + writePunctuation(writer, SyntaxKind.GreaterThanToken); + } + } + function writeTypeReference(type: TypeReference, flags: TypeFormatFlags) { + let typeArguments = type.typeArguments; if (type.target === globalArrayType && !(flags & TypeFormatFlags.WriteArrayAsGenericType)) { - writeType(type.typeArguments[0], TypeFormatFlags.InElementType); + writeType(typeArguments[0], TypeFormatFlags.InElementType); writePunctuation(writer, SyntaxKind.OpenBracketToken); writePunctuation(writer, SyntaxKind.CloseBracketToken); } else { - buildSymbolDisplay(type.target.symbol, writer, enclosingDeclaration, SymbolFlags.Type); - writePunctuation(writer, SyntaxKind.LessThanToken); - writeTypeList(type.typeArguments, /*union*/ false); - writePunctuation(writer, SyntaxKind.GreaterThanToken); + // Write the type reference in the format f.g.C where A and B are type arguments + // for outer type parameters, and f and g are the respective declaring containers of those + // type parameters. + let outerTypeParameters = type.target.outerTypeParameters; + let i = 0; + if (outerTypeParameters) { + let length = outerTypeParameters.length; + while (i < length) { + // Find group of type arguments for type parameters with the same declaring container. + let start = i; + let parent = getParentSymbolOfTypeParameter(outerTypeParameters[i]); + do { + i++; + } while (i < length && getParentSymbolOfTypeParameter(outerTypeParameters[i]) === parent); + // When type parameters are their own type arguments for the whole group (i.e. we have + // the default outer type arguments), we don't show the group. + if (!rangeEquals(outerTypeParameters, typeArguments, start, i)) { + writeSymbolTypeReference(parent, typeArguments, start, i); + writePunctuation(writer, SyntaxKind.DotToken); + } + } + } + writeSymbolTypeReference(type.symbol, typeArguments, i, typeArguments.length); } } @@ -1553,49 +1608,54 @@ module ts { } function writeAnonymousType(type: ObjectType, flags: TypeFormatFlags) { - // Always use 'typeof T' for type of class, enum, and module objects - if (type.symbol && type.symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) { - writeTypeofSymbol(type, flags); - } - // Use 'typeof T' for types of functions and methods that circularly reference themselves - else if (shouldWriteTypeOfFunctionSymbol()) { - writeTypeofSymbol(type, flags); - } - else if (typeStack && contains(typeStack, type)) { - // If type is an anonymous type literal in a type alias declaration, use type alias name - let typeAlias = getTypeAliasForTypeLiteral(type); - if (typeAlias) { - // The specified symbol flags need to be reinterpreted as type flags - buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags); + let symbol = type.symbol; + if (symbol) { + // Always use 'typeof T' for type of class, enum, and module objects + if (symbol.flags & (SymbolFlags.Class | SymbolFlags.Enum | SymbolFlags.ValueModule)) { + writeTypeofSymbol(type, flags); + } + else if (shouldWriteTypeOfFunctionSymbol()) { + writeTypeofSymbol(type, flags); + } + else if (contains(symbolStack, symbol)) { + // If type is an anonymous type literal in a type alias declaration, use type alias name + let typeAlias = getTypeAliasForTypeLiteral(type); + if (typeAlias) { + // The specified symbol flags need to be reinterpreted as type flags + buildSymbolDisplay(typeAlias, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, flags); + } + else { + // Recursive usage, use any + writeKeyword(writer, SyntaxKind.AnyKeyword); + } } else { - // Recursive usage, use any - writeKeyword(writer, SyntaxKind.AnyKeyword); + // Since instantiations of the same anonymous type have the same symbol, tracking symbols instead + // of types allows us to catch circular references to instantiations of the same anonymous type + if (!symbolStack) { + symbolStack = []; + } + symbolStack.push(symbol); + writeLiteralType(type, flags); + symbolStack.pop(); } } else { - if (!typeStack) { - typeStack = []; - } - typeStack.push(type); + // Anonymous types with no symbol are never circular writeLiteralType(type, flags); - typeStack.pop(); } function shouldWriteTypeOfFunctionSymbol() { - if (type.symbol) { - let isStaticMethodSymbol = !!(type.symbol.flags & SymbolFlags.Method && // typeof static method - ts.forEach(type.symbol.declarations, declaration => declaration.flags & NodeFlags.Static)); - let isNonLocalFunctionSymbol = !!(type.symbol.flags & SymbolFlags.Function) && - (type.symbol.parent || // is exported function symbol - ts.forEach(type.symbol.declarations, declaration => - declaration.parent.kind === SyntaxKind.SourceFile || declaration.parent.kind === SyntaxKind.ModuleBlock)); - - if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { - // typeof is allowed only for static/non local functions - return !!(flags & TypeFormatFlags.UseTypeOfFunction) || // use typeof if format flags specify it - (typeStack && contains(typeStack, type)); // it is type of the symbol uses itself recursively - } + let isStaticMethodSymbol = !!(symbol.flags & SymbolFlags.Method && // typeof static method + forEach(symbol.declarations, declaration => declaration.flags & NodeFlags.Static)); + let isNonLocalFunctionSymbol = !!(symbol.flags & SymbolFlags.Function) && + (symbol.parent || // is exported function symbol + forEach(symbol.declarations, declaration => + declaration.parent.kind === SyntaxKind.SourceFile || declaration.parent.kind === SyntaxKind.ModuleBlock)); + if (isStaticMethodSymbol || isNonLocalFunctionSymbol) { + // typeof is allowed only for static/non local functions + return !!(flags & TypeFormatFlags.UseTypeOfFunction) || // use typeof if format flags specify it + (contains(symbolStack, symbol)); // it is type of the symbol uses itself recursively } } } @@ -1630,7 +1690,7 @@ module ts { if (flags & TypeFormatFlags.InElementType) { writePunctuation(writer, SyntaxKind.OpenParenToken); } - buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, typeStack); + buildSignatureDisplay(resolved.callSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, symbolStack); if (flags & TypeFormatFlags.InElementType) { writePunctuation(writer, SyntaxKind.CloseParenToken); } @@ -1642,7 +1702,7 @@ module ts { } writeKeyword(writer, SyntaxKind.NewKeyword); writeSpace(writer); - buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, typeStack); + buildSignatureDisplay(resolved.constructSignatures[0], writer, enclosingDeclaration, globalFlagsToPass | TypeFormatFlags.WriteArrowStyleSignature, symbolStack); if (flags & TypeFormatFlags.InElementType) { writePunctuation(writer, SyntaxKind.CloseParenToken); } @@ -1654,7 +1714,7 @@ module ts { writer.writeLine(); writer.increaseIndent(); for (let signature of resolved.callSignatures) { - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, SyntaxKind.SemicolonToken); writer.writeLine(); } @@ -1662,7 +1722,7 @@ module ts { writeKeyword(writer, SyntaxKind.NewKeyword); writeSpace(writer); - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, SyntaxKind.SemicolonToken); writer.writeLine(); } @@ -1703,7 +1763,7 @@ module ts { if (p.flags & SymbolFlags.Optional) { writePunctuation(writer, SyntaxKind.QuestionToken); } - buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, typeStack); + buildSignatureDisplay(signature, writer, enclosingDeclaration, globalFlagsToPass, symbolStack); writePunctuation(writer, SyntaxKind.SemicolonToken); writer.writeLine(); } @@ -1728,36 +1788,37 @@ module ts { function buildTypeParameterDisplayFromSymbol(symbol: Symbol, writer: SymbolWriter, enclosingDeclaraiton?: Node, flags?: TypeFormatFlags) { let targetSymbol = getTargetSymbol(symbol); if (targetSymbol.flags & SymbolFlags.Class || targetSymbol.flags & SymbolFlags.Interface) { - buildDisplayForTypeParametersAndDelimiters(getTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); + buildDisplayForTypeParametersAndDelimiters(getLocalTypeParametersOfClassOrInterface(symbol), writer, enclosingDeclaraiton, flags); } } - function buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildTypeParameterDisplay(tp: TypeParameter, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { appendSymbolNameOnly(tp.symbol, writer); let constraint = getConstraintOfTypeParameter(tp); if (constraint) { writeSpace(writer); writeKeyword(writer, SyntaxKind.ExtendsKeyword); writeSpace(writer); - buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(constraint, writer, enclosingDeclaration, flags, symbolStack); } } - function buildParameterDisplay(p: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { - if (hasDotDotDotToken(p.valueDeclaration)) { + function buildParameterDisplay(p: Symbol, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { + let parameterNode = p.valueDeclaration; + if (isRestParameter(parameterNode)) { writePunctuation(writer, SyntaxKind.DotDotDotToken); } appendSymbolNameOnly(p, writer); - if (hasQuestionToken(p.valueDeclaration) || (p.valueDeclaration).initializer) { + if (isOptionalParameter(parameterNode)) { writePunctuation(writer, SyntaxKind.QuestionToken); } writePunctuation(writer, SyntaxKind.ColonToken); writeSpace(writer); - buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getTypeOfSymbol(p), writer, enclosingDeclaration, flags, symbolStack); } - function buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildDisplayForTypeParametersAndDelimiters(typeParameters: TypeParameter[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { if (typeParameters && typeParameters.length) { writePunctuation(writer, SyntaxKind.LessThanToken); for (let i = 0; i < typeParameters.length; i++) { @@ -1765,13 +1826,13 @@ module ts { writePunctuation(writer, SyntaxKind.CommaToken); writeSpace(writer); } - buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, typeStack); + buildTypeParameterDisplay(typeParameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, SyntaxKind.GreaterThanToken); } } - function buildDisplayForTypeArgumentsAndDelimiters(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildDisplayForTypeArgumentsAndDelimiters(typeParameters: TypeParameter[], mapper: TypeMapper, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { if (typeParameters && typeParameters.length) { writePunctuation(writer, SyntaxKind.LessThanToken); for (let i = 0; i < typeParameters.length; i++) { @@ -1785,19 +1846,19 @@ module ts { } } - function buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildDisplayForParametersAndDelimiters(parameters: Symbol[], writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { writePunctuation(writer, SyntaxKind.OpenParenToken); for (let i = 0; i < parameters.length; i++) { if (i > 0) { writePunctuation(writer, SyntaxKind.CommaToken); writeSpace(writer); } - buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, typeStack); + buildParameterDisplay(parameters[i], writer, enclosingDeclaration, flags, symbolStack); } writePunctuation(writer, SyntaxKind.CloseParenToken); } - function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildReturnTypeDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { if (flags & TypeFormatFlags.WriteArrowStyleSignature) { writeSpace(writer); writePunctuation(writer, SyntaxKind.EqualsGreaterThanToken); @@ -1806,21 +1867,21 @@ module ts { writePunctuation(writer, SyntaxKind.ColonToken); } writeSpace(writer); - buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, typeStack); + buildTypeDisplay(getReturnTypeOfSignature(signature), writer, enclosingDeclaration, flags, symbolStack); } - function buildSignatureDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, typeStack?: Type[]) { + function buildSignatureDisplay(signature: Signature, writer: SymbolWriter, enclosingDeclaration?: Node, flags?: TypeFormatFlags, symbolStack?: Symbol[]) { if (signature.target && (flags & TypeFormatFlags.WriteTypeArgumentsOfSignature)) { // Instantiated signature, write type arguments instead // This is achieved by passing in the mapper separately buildDisplayForTypeArgumentsAndDelimiters(signature.target.typeParameters, signature.mapper, writer, enclosingDeclaration); } else { - buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForTypeParametersAndDelimiters(signature.typeParameters, writer, enclosingDeclaration, flags, symbolStack); } - buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, typeStack); - buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, typeStack); + buildDisplayForParametersAndDelimiters(signature.parameters, writer, enclosingDeclaration, flags, symbolStack); + buildReturnTypeDisplay(signature, writer, enclosingDeclaration, flags, symbolStack); } return _displayBuilder || (_displayBuilder = { @@ -2150,7 +2211,7 @@ module ts { // checkRightHandSideOfForOf will return undefined if the for-of expression type was // missing properties/signatures required to get its iteratedType (like // [Symbol.iterator] or next). This may be because we accessed properties from anyType, - // or it may have led to an error inside getIteratedType. + // or it may have led to an error inside getElementTypeOfIterable. return checkRightHandSideOfForOf((declaration.parent.parent).expression) || anyType; } if (isBindingPattern(declaration.parent)) { @@ -2317,7 +2378,7 @@ module ts { // Variable has initializer that circularly references the variable itself type = anyType; if (compilerOptions.noImplicitAny) { - error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, + error(symbol.valueDeclaration, Diagnostics._0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer, symbolToString(symbol)); } } @@ -2465,30 +2526,68 @@ module ts { } } - // Return combined list of type parameters from all declarations of a class or interface. Elsewhere we check they're all - // the same, but even if they're not we still need the complete list to ensure instantiations supply type arguments - // for all type parameters. - function getTypeParametersOfClassOrInterface(symbol: Symbol): TypeParameter[] { - let result: TypeParameter[]; - forEach(symbol.declarations, node => { - if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.ClassDeclaration) { - let declaration = node; - if (declaration.typeParameters && declaration.typeParameters.length) { - forEach(declaration.typeParameters, node => { - let tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node)); - if (!result) { - result = [tp]; - } - else if (!contains(result, tp)) { - result.push(tp); - } - }); + // Appends the type parameters given by a list of declarations to a set of type parameters and returns the resulting set. + // The function allocates a new array if the input type parameter set is undefined, but otherwise it modifies the set + // in-place and returns the same array. + function appendTypeParameters(typeParameters: TypeParameter[], declarations: TypeParameterDeclaration[]): TypeParameter[] { + for (let declaration of declarations) { + let tp = getDeclaredTypeOfTypeParameter(getSymbolOfNode(declaration)); + if (!typeParameters) { + typeParameters = [tp]; + } + else if (!contains(typeParameters, tp)) { + typeParameters.push(tp); + } + } + return typeParameters; + } + + // Appends the outer type parameters of a node to a set of type parameters and returns the resulting set. The function + // allocates a new array if the input type parameter set is undefined, but otherwise it modifies the set in-place and + // returns the same array. + function appendOuterTypeParameters(typeParameters: TypeParameter[], node: Node): TypeParameter[]{ + while (true) { + node = node.parent; + if (!node) { + return typeParameters; + } + if (node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.FunctionDeclaration || + node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.MethodDeclaration || + node.kind === SyntaxKind.ArrowFunction) { + let declarations = (node).typeParameters; + if (declarations) { + return appendTypeParameters(appendOuterTypeParameters(typeParameters, node), declarations); } } - }); + } + } + + // The outer type parameters are those defined by enclosing generic classes, methods, or functions. + function getOuterTypeParametersOfClassOrInterface(symbol: Symbol): TypeParameter[] { + var kind = symbol.flags & SymbolFlags.Class ? SyntaxKind.ClassDeclaration : SyntaxKind.InterfaceDeclaration; + return appendOuterTypeParameters(undefined, getDeclarationOfKind(symbol, kind)); + } + + // The local type parameters are the combined set of type parameters from all declarations of the class or interface. + function getLocalTypeParametersOfClassOrInterface(symbol: Symbol): TypeParameter[] { + let result: TypeParameter[]; + for (let node of symbol.declarations) { + if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.ClassDeclaration) { + let declaration = node; + if (declaration.typeParameters) { + result = appendTypeParameters(result, declaration.typeParameters); + } + } + } return result; } + // The full set of type parameters for a generic class or interface type consists of its outer type parameters plus + // its locally declared type parameters. + function getTypeParametersOfClassOrInterface(symbol: Symbol): TypeParameter[] { + return concatenate(getOuterTypeParametersOfClassOrInterface(symbol), getLocalTypeParametersOfClassOrInterface(symbol)); + } + function getBaseTypes(type: InterfaceType): ObjectType[] { let typeWithBaseTypes = type; if (!typeWithBaseTypes.baseTypes) { @@ -2558,10 +2657,13 @@ module ts { if (!links.declaredType) { let kind = symbol.flags & SymbolFlags.Class ? TypeFlags.Class : TypeFlags.Interface; let type = links.declaredType = createObjectType(kind, symbol); - let typeParameters = getTypeParametersOfClassOrInterface(symbol); - if (typeParameters) { + let outerTypeParameters = getOuterTypeParametersOfClassOrInterface(symbol); + let localTypeParameters = getLocalTypeParametersOfClassOrInterface(symbol); + if (outerTypeParameters || localTypeParameters) { type.flags |= TypeFlags.Reference; - type.typeParameters = typeParameters; + type.typeParameters = concatenate(outerTypeParameters, localTypeParameters); + type.outerTypeParameters = outerTypeParameters; + type.localTypeParameters = localTypeParameters; (type).instantiations = {}; (type).instantiations[getTypeListId(type.typeParameters)] = type; (type).target = type; @@ -2751,12 +2853,12 @@ module ts { return map(baseSignatures, baseSignature => { let signature = baseType.flags & TypeFlags.Reference ? getSignatureInstantiation(baseSignature, (baseType).typeArguments) : cloneSignature(baseSignature); - signature.typeParameters = classType.typeParameters; + signature.typeParameters = classType.localTypeParameters; signature.resolvedReturnType = classType; return signature; }); } - return [createSignature(undefined, classType.typeParameters, emptyArray, classType, 0, false, false)]; + return [createSignature(undefined, classType.localTypeParameters, emptyArray, classType, 0, false, false)]; } function createTupleTypeMemberSymbols(memberTypes: Type[]): SymbolTable { @@ -3101,11 +3203,15 @@ module ts { return result; } + function isOptionalParameter(node: ParameterDeclaration) { + return hasQuestionToken(node) || !!node.initializer; + } + function getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature { let links = getNodeLinks(declaration); if (!links.resolvedSignature) { let classType = declaration.kind === SyntaxKind.Constructor ? getDeclaredTypeOfClassOrInterface((declaration.parent).symbol) : undefined; - let typeParameters = classType ? classType.typeParameters : + let typeParameters = classType ? classType.localTypeParameters : declaration.typeParameters ? getTypeParametersFromDeclaration(declaration.typeParameters) : undefined; let parameters: Symbol[] = []; let hasStringLiterals = false; @@ -3148,7 +3254,7 @@ module ts { } links.resolvedSignature = createSignature(declaration, typeParameters, parameters, returnType, - minArgumentCount, hasRestParameters(declaration), hasStringLiterals); + minArgumentCount, hasRestParameter(declaration), hasStringLiterals); } return links.resolvedSignature; } @@ -3307,6 +3413,10 @@ module ts { return type.constraint === noConstraintType ? undefined : type.constraint; } + function getParentSymbolOfTypeParameter(typeParameter: TypeParameter): Symbol { + return getSymbolOfNode(getDeclarationOfKind(typeParameter.symbol, SyntaxKind.TypeParameter).parent); + } + function getTypeListId(types: Type[]) { switch (types.length) { case 1: @@ -3420,32 +3530,50 @@ module ts { type = unknownType; } else { - type = getDeclaredTypeOfSymbol(symbol); - if (type.flags & (TypeFlags.Class | TypeFlags.Interface) && type.flags & TypeFlags.Reference) { - let typeParameters = (type).typeParameters; - if (node.typeArguments && node.typeArguments.length === typeParameters.length) { - type = createTypeReference(type, map(node.typeArguments, getTypeFromTypeNode)); - } - else { - error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType), typeParameters.length); - type = undefined; - } - } - else { - if (node.typeArguments) { - error(node, Diagnostics.Type_0_is_not_generic, typeToString(type)); - type = undefined; - } - } + type = createTypeReferenceIfGeneric( + getDeclaredTypeOfSymbol(symbol), + node, node.typeArguments); } } } links.resolvedType = type || unknownType; } + return links.resolvedType; } + function createTypeReferenceIfGeneric(type: Type, node: Node, typeArguments: NodeArray): Type { + if (type.flags & (TypeFlags.Class | TypeFlags.Interface) && type.flags & TypeFlags.Reference) { + // In a type reference, the outer type parameters of the referenced class or interface are automatically + // supplied as type arguments and the type reference only specifies arguments for the local type parameters + // of the class or interface. + let localTypeParameters = (type).localTypeParameters; + let expectedTypeArgCount = localTypeParameters ? localTypeParameters.length : 0; + let typeArgCount = typeArguments ? typeArguments.length : 0; + if (typeArgCount === expectedTypeArgCount) { + // When no type arguments are expected we already have the right type because all outer type parameters + // have themselves as default type arguments. + if (typeArgCount) { + return createTypeReference(type, concatenate((type).outerTypeParameters, + map(typeArguments, getTypeFromTypeNode))); + } + } + else { + error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType), expectedTypeArgCount); + return undefined; + } + } + else { + if (typeArguments) { + error(node, Diagnostics.Type_0_is_not_generic, typeToString(type)); + return undefined; + } + } + + return type; + } + function getTypeFromTypeQueryNode(node: TypeQueryNode): Type { let links = getNodeLinks(node); if (!links.resolvedType) { @@ -3473,16 +3601,16 @@ module ts { } if (!symbol) { - return emptyObjectType; + return arity ? emptyGenericType : emptyObjectType; } let type = getDeclaredTypeOfSymbol(symbol); if (!(type.flags & TypeFlags.ObjectType)) { error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_be_a_class_or_interface_type, symbol.name); - return emptyObjectType; + return arity ? emptyGenericType : emptyObjectType; } if (((type).typeParameters ? (type).typeParameters.length : 0) !== arity) { error(getTypeDeclaration(symbol), Diagnostics.Global_type_0_must_have_1_type_parameter_s, symbol.name, arity); - return emptyObjectType; + return arity ? emptyGenericType : emptyObjectType; } return type; } @@ -3507,16 +3635,23 @@ module ts { return globalESSymbolConstructorSymbol || (globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol")); } + /** + * Instantiates a global type that is generic with some element type, and returns that instantiation. + */ + function createTypeFromGenericGlobalType(genericGlobalType: GenericType, elementType: Type): Type { + return genericGlobalType !== emptyGenericType ? createTypeReference(genericGlobalType, [elementType]) : emptyObjectType; + } + function createIterableType(elementType: Type): Type { - return globalIterableType !== emptyObjectType ? createTypeReference(globalIterableType, [elementType]) : emptyObjectType; + return createTypeFromGenericGlobalType(globalIterableType, elementType); + } + + function createIterableIteratorType(elementType: Type): Type { + return createTypeFromGenericGlobalType(globalIterableIteratorType, elementType); } function createArrayType(elementType: Type): Type { - // globalArrayType will be undefined if we get here during creation of the Array type. This for example happens if - // user code augments the Array type with call or construct signatures that have an array type as the return type. - // We instead use globalArraySymbol to obtain the (not yet fully constructed) Array type. - let arrayType = globalArrayType || getDeclaredTypeOfSymbol(globalArraySymbol); - return arrayType !== emptyObjectType ? createTypeReference(arrayType, [elementType]) : emptyObjectType; + return createTypeFromGenericGlobalType(globalArrayType, elementType); } function getTypeFromArrayTypeNode(node: ArrayTypeNode): Type { @@ -3866,7 +4001,8 @@ module ts { } function instantiateAnonymousType(type: ObjectType, mapper: TypeMapper): ObjectType { - let result = createObjectType(TypeFlags.Anonymous, type.symbol); + // Mark the anonymous type as instantiated such that our infinite instantiation detection logic can recognize it + let result = createObjectType(TypeFlags.Anonymous | TypeFlags.Instantiated, type.symbol); result.properties = instantiateList(getPropertiesOfObjectType(type), mapper, instantiateSymbol); result.members = createSymbolTable(result.properties); result.callSignatures = instantiateList(getSignaturesOfType(type, SignatureKind.Call), mapper, instantiateSignature); @@ -3884,7 +4020,7 @@ module ts { return mapper(type); } if (type.flags & TypeFlags.Anonymous) { - return type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) ? + return type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) ? instantiateAnonymousType(type, mapper) : type; } if (type.flags & TypeFlags.Reference) { @@ -4289,12 +4425,13 @@ module ts { // Effectively, we will generate a false positive when two types are structurally equal to at least 10 levels, but unequal at // some level beyond that. function isDeeplyNestedGeneric(type: ObjectType, stack: ObjectType[]): boolean { - if (type.flags & TypeFlags.Reference && depth >= 10) { - let target = (type).target; + // We track type references (created by createTypeReference) and instantiated types (created by instantiateType) + if (type.flags & (TypeFlags.Reference | TypeFlags.Instantiated) && depth >= 10) { + let symbol = type.symbol; let count = 0; for (let i = 0; i < depth; i++) { let t = stack[i]; - if (t.flags & TypeFlags.Reference && (t).target === target) { + if (t.flags & (TypeFlags.Reference | TypeFlags.Instantiated) && t.symbol === symbol) { count++; if (count >= 10) return true; } @@ -5728,7 +5865,7 @@ module ts { let contextualSignature = getContextualSignature(func); if (contextualSignature) { - let funcHasRestParameters = hasRestParameters(func); + let funcHasRestParameters = hasRestParameter(func); let len = func.parameters.length - (funcHasRestParameters ? 1 : 0); let indexOfParameter = indexOf(func.parameters, parameter); if (indexOfParameter < len) { @@ -5771,20 +5908,44 @@ module ts { } function getContextualTypeForReturnExpression(node: Expression): Type { + let func = getContainingFunction(node); + if (func && !func.asteriskToken) { + return getContextualReturnType(func); + } + + return undefined; + } + + function getContextualTypeForYieldOperand(node: YieldExpression): Type { let func = getContainingFunction(node); if (func) { - // If the containing function has a return type annotation, is a constructor, or is a get accessor whose - // corresponding set accessor has a type annotation, return statements in the function are contextually typed - if (func.type || func.kind === SyntaxKind.Constructor || func.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(getDeclarationOfKind(func.symbol, SyntaxKind.SetAccessor))) { - return getReturnTypeOfSignature(getSignatureFromDeclaration(func)); - } - // 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 - let signature = getContextualSignatureForFunctionLikeDeclaration(func); - if (signature) { - return getReturnTypeOfSignature(signature); + let contextualReturnType = getContextualReturnType(func); + if (contextualReturnType) { + return node.asteriskToken + ? contextualReturnType + : getElementTypeOfIterableIterator(contextualReturnType); } } + + return undefined; + } + + function getContextualReturnType(functionDecl: FunctionLikeDeclaration): Type { + // If the containing function has a return type annotation, is a constructor, or is a get accessor whose + // corresponding set accessor has a type annotation, return statements in the function are contextually typed + if (functionDecl.type || + functionDecl.kind === SyntaxKind.Constructor || + functionDecl.kind === SyntaxKind.GetAccessor && getSetAccessorTypeAnnotationNode(getDeclarationOfKind(functionDecl.symbol, SyntaxKind.SetAccessor))) { + return getReturnTypeOfSignature(getSignatureFromDeclaration(functionDecl)); + } + + // 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 + let signature = getContextualSignatureForFunctionLikeDeclaration(functionDecl); + if (signature) { + return getReturnTypeOfSignature(signature); + } + return undefined; } @@ -5922,7 +6083,7 @@ module ts { let index = indexOf(arrayLiteral.elements, node); return getTypeOfPropertyOfContextualType(type, "" + index) || getIndexTypeOfContextualType(type, IndexKind.Number) - || (languageVersion >= ScriptTarget.ES6 ? checkIteratedType(type, /*expressionForError*/ undefined) : undefined); + || (languageVersion >= ScriptTarget.ES6 ? getElementTypeOfIterable(type, /*errorNode*/ undefined) : undefined); } return undefined; } @@ -5954,6 +6115,8 @@ module ts { case SyntaxKind.ArrowFunction: case SyntaxKind.ReturnStatement: return getContextualTypeForReturnExpression(node); + case SyntaxKind.YieldExpression: + return getContextualTypeForYieldOperand(parent); case SyntaxKind.CallExpression: case SyntaxKind.NewExpression: return getContextualTypeForArgument(parent, node); @@ -5993,8 +6156,10 @@ module ts { } function getContextualSignatureForFunctionLikeDeclaration(node: FunctionLikeDeclaration): Signature { - // Only function expressions and arrow functions are contextually typed. - return isFunctionExpressionOrArrowFunction(node) ? getContextualSignature(node) : undefined; + // Only function expressions, arrow functions, and object literal methods are contextually typed. + return isFunctionExpressionOrArrowFunction(node) || isObjectLiteralMethod(node) + ? getContextualSignature(node) + : undefined; } // Return the contextual signature for a given expression node. A contextual type provides a @@ -6109,7 +6274,7 @@ module ts { // if there is no index type / iterated type. let restArrayType = checkExpression((e).expression, contextualMapper); let restElementType = getIndexTypeOfType(restArrayType, IndexKind.Number) || - (languageVersion >= ScriptTarget.ES6 ? checkIteratedType(restArrayType, /*expressionForError*/ undefined) : undefined); + (languageVersion >= ScriptTarget.ES6 ? getElementTypeOfIterable(restArrayType, /*errorNode*/ undefined) : undefined); if (restElementType) { elementTypes.push(restElementType); @@ -7127,10 +7292,10 @@ module ts { } function resolveNewExpression(node: NewExpression, candidatesOutArray: Signature[]): Signature { - if (node.arguments && languageVersion < ScriptTarget.ES6) { + if (node.arguments && languageVersion < ScriptTarget.ES5) { let spreadIndex = getSpreadArgumentIndex(node.arguments); if (spreadIndex >= 0) { - error(node.arguments[spreadIndex], Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher); + error(node.arguments[spreadIndex], Diagnostics.Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher); } } @@ -7148,7 +7313,7 @@ module ts { // If ConstructExpr's apparent type(section 3.8.1) is an object type with one or // more construct signatures, the expression is processed in the same manner as a // function call, but using the construct signatures as the initial set of candidate - // signatures for overload resolution.The result type of the function call becomes + // signatures for overload resolution. The result type of the function call becomes // the result type of the operation. expressionType = getApparentType(expressionType); if (expressionType === unknownType) { @@ -7303,17 +7468,42 @@ module ts { type = checkExpressionCached(func.body, contextualMapper); } else { - // Aggregate the types of expressions within all the return statements. - let types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); - if (types.length === 0) { - return voidType; + let types: Type[]; + let funcIsGenerator = !!func.asteriskToken; + if (funcIsGenerator) { + types = checkAndAggregateYieldOperandTypes(func.body, contextualMapper); + if (types.length === 0) { + let iterableIteratorAny = createIterableIteratorType(anyType); + if (compilerOptions.noImplicitAny) { + error(func.asteriskToken, + Diagnostics.Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type, typeToString(iterableIteratorAny)); + } + return iterableIteratorAny; + } } - // When return statements are contextually typed we allow the return type to be a union type. Otherwise we require the - // return expressions to have a best common supertype. + else { + types = checkAndAggregateReturnExpressionTypes(func.body, contextualMapper); + if (types.length === 0) { + return voidType; + } + } + + // When yield/return statements are contextually typed we allow the return type to be a union type. + // Otherwise we require the yield/return expressions to have a best common supertype. type = contextualSignature ? getUnionType(types) : getCommonSupertype(types); if (!type) { - error(func, Diagnostics.No_best_common_type_exists_among_return_expressions); - return unknownType; + if (funcIsGenerator) { + error(func, Diagnostics.No_best_common_type_exists_among_yield_expressions); + return createIterableIteratorType(unknownType); + } + else { + error(func, Diagnostics.No_best_common_type_exists_among_return_expressions); + return unknownType; + } + } + + if (funcIsGenerator) { + type = createIterableIteratorType(type); } } if (!contextualSignature) { @@ -7322,7 +7512,28 @@ module ts { return getWidenedType(type); } - /// Returns a set of types relating to every return expression relating to a function block. + function checkAndAggregateYieldOperandTypes(body: Block, contextualMapper?: TypeMapper): Type[] { + let aggregatedTypes: Type[] = []; + + forEachYieldExpression(body, yieldExpression => { + let expr = yieldExpression.expression; + if (expr) { + let type = checkExpressionCached(expr, contextualMapper); + + if (yieldExpression.asteriskToken) { + // A yield* expression effectively yields everything that its operand yields + type = checkElementTypeOfIterable(type, yieldExpression.expression); + } + + if (!contains(aggregatedTypes, type)) { + aggregatedTypes.push(type); + } + } + }); + + return aggregatedTypes; + } + function checkAndAggregateReturnExpressionTypes(body: Block, contextualMapper?: TypeMapper): Type[] { let aggregatedTypes: Type[] = []; @@ -7440,6 +7651,15 @@ module ts { } if (node.body) { + if (!node.type) { + // There are some checks that are only performed in getReturnTypeFromBody, that may produce errors + // we need. An example is the noImplicitAny errors resulting from widening the return expression + // of a function. Because checking of function expression bodies is deferred, there was never an + // appropriate time to do this during the main walk of the file (see the comment at the top of + // checkFunctionExpressionBodies). So it must be done now. + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } + if (node.body.kind === SyntaxKind.Block) { checkSourceElement(node.body); } @@ -7965,14 +8185,58 @@ module ts { } } - function checkYieldExpression(node: YieldExpression): void { + function isYieldExpressionInClass(node: YieldExpression): boolean { + let current: Node = node + let parent = node.parent; + while (parent) { + if (isFunctionLike(parent) && current === (parent).body) { + return false; + } + else if (current.kind === SyntaxKind.ClassDeclaration || current.kind === SyntaxKind.ClassExpression) { + return true; + } + + current = parent; + parent = parent.parent; + } + + return false; + } + + function checkYieldExpression(node: YieldExpression): Type { // Grammar checking - if (!(node.parserContextFlags & ParserContextFlags.Yield)) { - grammarErrorOnFirstToken(node, Diagnostics.yield_expression_must_be_contained_within_a_generator_declaration); + if (!(node.parserContextFlags & ParserContextFlags.Yield) || isYieldExpressionInClass(node)) { + grammarErrorOnFirstToken(node, Diagnostics.A_yield_expression_is_only_allowed_in_a_generator_body); } - else { - grammarErrorOnFirstToken(node, Diagnostics.yield_expressions_are_not_currently_supported); + + if (node.expression) { + let func = getContainingFunction(node); + // If the user's code is syntactically correct, the func should always have a star. After all, + // we are in a yield context. + if (func && func.asteriskToken) { + let expressionType = checkExpressionCached(node.expression, /*contextualMapper*/ undefined); + let expressionElementType: Type; + let nodeIsYieldStar = !!node.asteriskToken; + if (nodeIsYieldStar) { + expressionElementType = checkElementTypeOfIterable(expressionType, node.expression); + } + // There is no point in doing an assignability check if the function + // has no explicit return type because the return type is directly computed + // from the yield expressions. + if (func.type) { + let signatureElementType = getElementTypeOfIterableIterator(getTypeFromTypeNode(func.type)) || anyType; + if (nodeIsYieldStar) { + checkTypeAssignableTo(expressionElementType, signatureElementType, node.expression, /*headMessage*/ undefined); + } + else { + checkTypeAssignableTo(expressionType, signatureElementType, node.expression, /*headMessage*/ undefined); + } + } + } } + + // Both yield and yield* expressions have type 'any' + return anyType; } function checkConditionalExpression(node: ConditionalExpression, contextualMapper?: TypeMapper): Type { @@ -8162,8 +8426,7 @@ module ts { case SyntaxKind.OmittedExpression: return undefinedType; case SyntaxKind.YieldExpression: - checkYieldExpression(node); - return unknownType; + return checkYieldExpression(node); } return unknownType; } @@ -8216,6 +8479,16 @@ module ts { } } + function isSyntacticallyValidGenerator(node: SignatureDeclaration): boolean { + if (!(node).asteriskToken || !(node).body) { + return false; + } + + return node.kind === SyntaxKind.MethodDeclaration || + node.kind === SyntaxKind.FunctionDeclaration || + node.kind === SyntaxKind.FunctionExpression; + } + function checkSignatureDeclaration(node: SignatureDeclaration) { // Grammar checking if (node.kind === SyntaxKind.IndexSignature) { @@ -8248,6 +8521,27 @@ module ts { break; } } + + if (node.type) { + if (languageVersion >= ScriptTarget.ES6 && isSyntacticallyValidGenerator(node)) { + let returnType = getTypeFromTypeNode(node.type); + if (returnType === voidType) { + error(node.type, Diagnostics.A_generator_cannot_have_a_void_type_annotation); + } + else { + let generatorElementType = getElementTypeOfIterableIterator(returnType) || anyType; + let iterableIteratorInstantiation = createIterableIteratorType(generatorElementType); + + // Naively, one could check that IterableIterator is assignable to the return type annotation. + // However, that would not catch the error in the following case. + // + // interface BadGenerator extends Iterable, Iterator { } + // function* g(): BadGenerator { } // Iterable and Iterator have different types! + // + checkTypeAssignableTo(iterableIteratorInstantiation, returnType, node.type); + } + } + } } checkSpecializedSignatureDeclaration(node); @@ -8880,7 +9174,7 @@ module ts { // serialize the type metadata. if (node && node.kind === SyntaxKind.TypeReference) { let type = getTypeFromTypeNode(node); - let shouldCheckIfUnknownType = type === unknownType && compilerOptions.separateCompilation; + let shouldCheckIfUnknownType = type === unknownType && compilerOptions.isolatedModules; if (!type || (!shouldCheckIfUnknownType && type.flags & (TypeFlags.Intrinsic | TypeFlags.NumberLike | TypeFlags.StringLike))) { return; } @@ -8933,6 +9227,10 @@ module ts { if (!nodeCanBeDecorated(node)) { return; } + + if (!compilerOptions.experimentalDecorators) { + error(node, Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning); + } if (compilerOptions.emitDecoratorMetadata) { // we only need to perform these checks if we are emitting serialized type metadata for the target of a decorator. @@ -8968,7 +9266,6 @@ module ts { function checkFunctionDeclaration(node: FunctionDeclaration): void { if (produceDiagnostics) { checkFunctionLikeDeclaration(node) || - checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarFunctionName(node.name) || checkGrammarForGenerator(node); @@ -9019,10 +9316,19 @@ module ts { checkIfNonVoidFunctionHasReturnExpressionsOrSingleThrowStatment(node, getTypeFromTypeNode(node.type)); } - // Report an implicit any error if there is no body, no explicit return type, and node is not a private method - // in an ambient context - if (compilerOptions.noImplicitAny && nodeIsMissing(node.body) && !node.type && !isPrivateWithinAmbient(node)) { - reportImplicitAnyError(node, anyType); + if (produceDiagnostics && !node.type) { + // Report an implicit any error if there is no body, no explicit return type, and node is not a private method + // in an ambient context + if (compilerOptions.noImplicitAny && nodeIsMissing(node.body) && !isPrivateWithinAmbient(node)) { + reportImplicitAnyError(node, anyType); + } + + if (node.asteriskToken && nodeIsPresent(node.body)) { + // A generator with a body and no type annotation can still cause errors. It can error if the + // yielded values have no common supertype, or it can give an implicit any error if it has no + // yielded values. The only way to trigger these errors is to try checking its return type. + getReturnTypeOfSignature(getSignatureFromDeclaration(node)); + } } } @@ -9040,7 +9346,7 @@ module ts { function checkCollisionWithArgumentsInGeneratedCode(node: SignatureDeclaration) { // no rest parameters \ declaration context \ overload - no codegen impact - if (!hasRestParameters(node) || isInAmbientContext(node) || nodeIsMissing((node).body)) { + if (!hasRestParameter(node) || isInAmbientContext(node) || nodeIsMissing((node).body)) { return; } @@ -9330,7 +9636,7 @@ module ts { function checkVariableStatement(node: VariableStatement) { // Grammar checking - checkGrammarDecorators(node) || checkGrammarDisallowedModifiersInBlockOrObjectLiteralExpression(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); + checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarVariableDeclarationList(node.declarationList) || checkGrammarForDisallowedLetOrConstStatement(node); forEach(node.declarationList.declarations, checkSourceElement); } @@ -9437,7 +9743,7 @@ module ts { // iteratedType will be undefined if the rightType was missing properties/signatures // required to get its iteratedType (like [Symbol.iterator] or next). This may be // because we accessed properties from anyType, or it may have led to an error inside - // getIteratedType. + // getElementTypeOfIterable. if (iteratedType) { checkTypeAssignableTo(iteratedType, leftType, varExpr, /*headMessage*/ undefined); } @@ -9513,7 +9819,7 @@ module ts { } if (languageVersion >= ScriptTarget.ES6) { - return checkIteratedType(inputType, errorNode) || anyType; + return checkElementTypeOfIterable(inputType, errorNode); } if (allowStringInput) { @@ -9534,100 +9840,143 @@ module ts { /** * When errorNode is undefined, it means we should not report any errors. */ - function checkIteratedType(iterable: Type, errorNode: Node): Type { - Debug.assert(languageVersion >= ScriptTarget.ES6); - let iteratedType = getIteratedType(iterable, errorNode); + function checkElementTypeOfIterable(iterable: Type, errorNode: Node): Type { + let elementType = getElementTypeOfIterable(iterable, errorNode); // Now even though we have extracted the iteratedType, we will have to validate that the type // passed in is actually an Iterable. - if (errorNode && iteratedType) { - checkTypeAssignableTo(iterable, createIterableType(iteratedType), errorNode); + if (errorNode && elementType) { + checkTypeAssignableTo(iterable, createIterableType(elementType), errorNode); } - return iteratedType; - - function getIteratedType(iterable: Type, errorNode: Node) { - // We want to treat type as an iterable, and get the type it is an iterable of. The iterable - // must have the following structure (annotated with the names of the variables below): - // - // { // iterable - // [Symbol.iterator]: { // iteratorFunction - // (): { // iterator - // next: { // iteratorNextFunction - // (): { // iteratorNextResult - // value: T // iteratorNextValue - // } - // } - // } - // } - // } - // - // T is the type we are after. At every level that involves analyzing return types - // of signatures, we union the return types of all the signatures. - // - // Another thing to note is that at any step of this process, we could run into a dead end, - // meaning either the property is missing, or we run into the anyType. If either of these things - // happens, we return undefined to signal that we could not find the iterated type. If a property - // is missing, and the previous step did not result in 'any', then we also give an error if the - // caller requested it. Then the caller can decide what to do in the case where there is no iterated - // type. This is different from returning anyType, because that would signify that we have matched the - // whole pattern and that T (above) is 'any'. - - if (allConstituentTypesHaveKind(iterable, TypeFlags.Any)) { - return undefined; - } + return elementType || anyType; + } + + /** + * We want to treat type as an iterable, and get the type it is an iterable of. The iterable + * must have the following structure (annotated with the names of the variables below): + * + * { // iterable + * [Symbol.iterator]: { // iteratorFunction + * (): Iterator + * } + * } + * + * T is the type we are after. At every level that involves analyzing return types + * of signatures, we union the return types of all the signatures. + * + * Another thing to note is that at any step of this process, we could run into a dead end, + * meaning either the property is missing, or we run into the anyType. If either of these things + * happens, we return undefined to signal that we could not find the iterated type. If a property + * is missing, and the previous step did not result in 'any', then we also give an error if the + * caller requested it. Then the caller can decide what to do in the case where there is no iterated + * type. This is different from returning anyType, because that would signify that we have matched the + * whole pattern and that T (above) is 'any'. + */ + function getElementTypeOfIterable(type: Type, errorNode: Node): Type { + if (type.flags & TypeFlags.Any) { + return undefined; + } + let typeAsIterable = type; + if (!typeAsIterable.iterableElementType) { // As an optimization, if the type is instantiated directly using the globalIterableType (Iterable), // then just grab its type argument. - if ((iterable.flags & TypeFlags.Reference) && (iterable).target === globalIterableType) { - return (iterable).typeArguments[0]; + if ((type.flags & TypeFlags.Reference) && (type).target === globalIterableType) { + typeAsIterable.iterableElementType = (type).typeArguments[0]; } - - let iteratorFunction = getTypeOfPropertyOfType(iterable, getPropertyNameForKnownSymbolName("iterator")); - if (iteratorFunction && allConstituentTypesHaveKind(iteratorFunction, TypeFlags.Any)) { - return undefined; - } - - let iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, SignatureKind.Call) : emptyArray; - if (iteratorFunctionSignatures.length === 0) { - if (errorNode) { - error(errorNode, Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator); + else { + let iteratorFunction = getTypeOfPropertyOfType(type, getPropertyNameForKnownSymbolName("iterator")); + if (iteratorFunction && iteratorFunction.flags & TypeFlags.Any) { + return undefined; } - return undefined; - } - let iterator = getUnionType(map(iteratorFunctionSignatures, getReturnTypeOfSignature)); - if (allConstituentTypesHaveKind(iterator, TypeFlags.Any)) { - return undefined; - } - - let iteratorNextFunction = getTypeOfPropertyOfType(iterator, "next"); - if (iteratorNextFunction && allConstituentTypesHaveKind(iteratorNextFunction, TypeFlags.Any)) { - return undefined; - } - - let iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, SignatureKind.Call) : emptyArray; - if (iteratorNextFunctionSignatures.length === 0) { - if (errorNode) { - error(errorNode, Diagnostics.An_iterator_must_have_a_next_method); + let iteratorFunctionSignatures = iteratorFunction ? getSignaturesOfType(iteratorFunction, SignatureKind.Call) : emptyArray; + if (iteratorFunctionSignatures.length === 0) { + if (errorNode) { + error(errorNode, Diagnostics.Type_must_have_a_Symbol_iterator_method_that_returns_an_iterator); + } + return undefined; } - return undefined; - } - let iteratorNextResult = getUnionType(map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); - if (allConstituentTypesHaveKind(iteratorNextResult, TypeFlags.Any)) { - return undefined; + typeAsIterable.iterableElementType = getElementTypeOfIterator(getUnionType(map(iteratorFunctionSignatures, getReturnTypeOfSignature)), errorNode); } - - let iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); - if (!iteratorNextValue) { - if (errorNode) { - error(errorNode, Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property); - } - return undefined; - } - - return iteratorNextValue; } + + return typeAsIterable.iterableElementType; + } + + /** + * This function has very similar logic as getElementTypeOfIterable, except that it operates on + * Iterators instead of Iterables. Here is the structure: + * + * { // iterator + * next: { // iteratorNextFunction + * (): { // iteratorNextResult + * value: T // iteratorNextValue + * } + * } + * } + * + */ + function getElementTypeOfIterator(type: Type, errorNode: Node): Type { + if (type.flags & TypeFlags.Any) { + return undefined; + } + + let typeAsIterator = type; + if (!typeAsIterator.iteratorElementType) { + // As an optimization, if the type is instantiated directly using the globalIteratorType (Iterator), + // then just grab its type argument. + if ((type.flags & TypeFlags.Reference) && (type).target === globalIteratorType) { + typeAsIterator.iteratorElementType = (type).typeArguments[0]; + } + else { + let iteratorNextFunction = getTypeOfPropertyOfType(type, "next"); + if (iteratorNextFunction && iteratorNextFunction.flags & TypeFlags.Any) { + return undefined; + } + + let iteratorNextFunctionSignatures = iteratorNextFunction ? getSignaturesOfType(iteratorNextFunction, SignatureKind.Call) : emptyArray; + if (iteratorNextFunctionSignatures.length === 0) { + if (errorNode) { + error(errorNode, Diagnostics.An_iterator_must_have_a_next_method); + } + return undefined; + } + + let iteratorNextResult = getUnionType(map(iteratorNextFunctionSignatures, getReturnTypeOfSignature)); + if (iteratorNextResult.flags & TypeFlags.Any) { + return undefined; + } + + let iteratorNextValue = getTypeOfPropertyOfType(iteratorNextResult, "value"); + if (!iteratorNextValue) { + if (errorNode) { + error(errorNode, Diagnostics.The_type_returned_by_the_next_method_of_an_iterator_must_have_a_value_property); + } + return undefined; + } + + typeAsIterator.iteratorElementType = iteratorNextValue; + } + } + + return typeAsIterator.iteratorElementType; + } + + function getElementTypeOfIterableIterator(type: Type): Type { + if (type.flags & TypeFlags.Any) { + return undefined; + } + + // As an optimization, if the type is instantiated directly using the globalIterableIteratorType (IterableIterator), + // then just grab its type argument. + if ((type.flags & TypeFlags.Reference) && (type).target === globalIterableIteratorType) { + return (type).typeArguments[0]; + } + + return getElementTypeOfIterable(type, /*errorNode*/ undefined) || + getElementTypeOfIterator(type, /*errorNode*/ undefined); } /** @@ -9721,19 +10070,26 @@ module ts { if (func) { let returnType = getReturnTypeOfSignature(getSignatureFromDeclaration(func)); let exprType = checkExpressionCached(node.expression); + + if (func.asteriskToken) { + // A generator does not need its return expressions checked against its return type. + // Instead, the yield expressions are checked against the element type. + // TODO: Check return expressions of generators when return type tracking is added + // for generators. + return; + } + if (func.kind === SyntaxKind.SetAccessor) { error(node.expression, Diagnostics.Setters_cannot_return_a_value); } - else { - if (func.kind === SyntaxKind.Constructor) { - if (!isTypeAssignableTo(exprType, returnType)) { - error(node.expression, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); - } - } - else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func)) { - checkTypeAssignableTo(exprType, returnType, node.expression, /*headMessage*/ undefined); + else if (func.kind === SyntaxKind.Constructor) { + if (!isTypeAssignableTo(exprType, returnType)) { + error(node.expression, Diagnostics.Return_type_of_constructor_signature_must_be_assignable_to_the_instance_type_of_the_class); } } + else if (func.type || isGetAccessorWithAnnotatatedSetAccessor(func)) { + checkTypeAssignableTo(exprType, returnType, node.expression, /*headMessage*/ undefined); + } } } } @@ -9992,10 +10348,6 @@ module ts { function checkClassDeclaration(node: ClassDeclaration) { checkGrammarDeclarationNameInStrictMode(node); // Grammar checking - if (node.parent.kind !== SyntaxKind.ModuleBlock && node.parent.kind !== SyntaxKind.SourceFile) { - grammarErrorOnNode(node, Diagnostics.class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration); - } - if (!node.name && !(node.flags & NodeFlags.Default)) { grammarErrorOnFirstToken(node, Diagnostics.A_class_declaration_without_the_default_modifier_must_have_a_name); } @@ -10038,7 +10390,7 @@ module ts { } } - if (baseTypes.length || (baseTypeNode && compilerOptions.separateCompilation)) { + if (baseTypes.length || (baseTypeNode && compilerOptions.isolatedModules)) { // Check that base type can be evaluated as expression checkExpressionOrQualifiedName(baseTypeNode.expression); } @@ -10454,8 +10806,8 @@ module ts { computeEnumMemberValues(node); let enumIsConst = isConst(node); - if (compilerOptions.separateCompilation && enumIsConst && isInAmbientContext(node)) { - error(node.name, Diagnostics.Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided); + if (compilerOptions.isolatedModules && enumIsConst && isInAmbientContext(node)) { + error(node.name, Diagnostics.Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided); } // Spec 2014 - Section 9.3: @@ -10545,7 +10897,7 @@ module ts { if (symbol.flags & SymbolFlags.ValueModule && symbol.declarations.length > 1 && !isInAmbientContext(node) - && isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.separateCompilation)) { + && isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules)) { let firstNonAmbientClassOrFunc = getFirstNonAmbientClassOrFunctionDeclaration(symbol); if (firstNonAmbientClassOrFunc) { if (getSourceFileOfNode(node) !== getSourceFileOfNode(firstNonAmbientClassOrFunc)) { @@ -10914,6 +11266,7 @@ module ts { break; case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: + forEach(node.decorators, checkFunctionExpressionBodies); forEach((node).parameters, checkFunctionExpressionBodies); if (isObjectLiteralMethod(node)) { checkFunctionExpressionOrObjectLiteralMethodBody(node); @@ -10928,6 +11281,7 @@ module ts { case SyntaxKind.WithStatement: checkFunctionExpressionBodies((node).expression); break; + case SyntaxKind.Decorator: case SyntaxKind.Parameter: case SyntaxKind.PropertyDeclaration: case SyntaxKind.PropertySignature: @@ -11212,93 +11566,6 @@ module ts { return node.parent && node.parent.kind === SyntaxKind.ExpressionWithTypeArguments; } - function isTypeNode(node: Node): boolean { - if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) { - return true; - } - - switch (node.kind) { - case SyntaxKind.AnyKeyword: - case SyntaxKind.NumberKeyword: - case SyntaxKind.StringKeyword: - case SyntaxKind.BooleanKeyword: - case SyntaxKind.SymbolKeyword: - return true; - case SyntaxKind.VoidKeyword: - return node.parent.kind !== SyntaxKind.VoidExpression; - case SyntaxKind.StringLiteral: - // Specialized signatures can have string literals as their parameters' type names - return node.parent.kind === SyntaxKind.Parameter; - case SyntaxKind.ExpressionWithTypeArguments: - return true; - - // Identifiers and qualified names may be type nodes, depending on their context. Climb - // above them to find the lowest container - case SyntaxKind.Identifier: - // If the identifier is the RHS of a qualified name, then it's a type iff its parent is. - if (node.parent.kind === SyntaxKind.QualifiedName && (node.parent).right === node) { - node = node.parent; - } - else if (node.parent.kind === SyntaxKind.PropertyAccessExpression && (node.parent).name === node) { - node = node.parent; - } - // fall through - case SyntaxKind.QualifiedName: - case SyntaxKind.PropertyAccessExpression: - // At this point, node is either a qualified name or an identifier - Debug.assert(node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.PropertyAccessExpression, - "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); - - let parent = node.parent; - if (parent.kind === SyntaxKind.TypeQuery) { - return false; - } - // Do not recursively call isTypeNode on the parent. In the example: - // - // let a: A.B.C; - // - // Calling isTypeNode would consider the qualified name A.B a type node. Only C or - // A.B.C is a type node. - if (SyntaxKind.FirstTypeNode <= parent.kind && parent.kind <= SyntaxKind.LastTypeNode) { - return true; - } - switch (parent.kind) { - case SyntaxKind.ExpressionWithTypeArguments: - return true; - case SyntaxKind.TypeParameter: - return node === (parent).constraint; - case SyntaxKind.PropertyDeclaration: - case SyntaxKind.PropertySignature: - case SyntaxKind.Parameter: - case SyntaxKind.VariableDeclaration: - return node === (parent).type; - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.FunctionExpression: - case SyntaxKind.ArrowFunction: - case SyntaxKind.Constructor: - case SyntaxKind.MethodDeclaration: - case SyntaxKind.MethodSignature: - case SyntaxKind.GetAccessor: - case SyntaxKind.SetAccessor: - return node === (parent).type; - case SyntaxKind.CallSignature: - case SyntaxKind.ConstructSignature: - case SyntaxKind.IndexSignature: - return node === (parent).type; - case SyntaxKind.TypeAssertionExpression: - return node === (parent).type; - case SyntaxKind.CallExpression: - case SyntaxKind.NewExpression: - return (parent).typeArguments && indexOf((parent).typeArguments, node) >= 0; - case SyntaxKind.TaggedTemplateExpression: - // TODO (drosen): TaggedTemplateExpressions may eventually support type arguments. - return false; - } - } - - return false; - } - function getLeftSideOfImportEqualsOrExportAssignment(nodeOnRightSide: EntityName): ImportEqualsDeclaration | ExportAssignment { while (nodeOnRightSide.parent.kind === SyntaxKind.QualifiedName) { nodeOnRightSide = nodeOnRightSide.parent; @@ -11645,7 +11912,7 @@ module ts { function isAliasResolvedToValue(symbol: Symbol): boolean { let target = resolveAlias(symbol); - if (target === unknownSymbol && compilerOptions.separateCompilation) { + if (target === unknownSymbol && compilerOptions.isolatedModules) { return true; } // const enums and modules that contain only const enums are not considered values from the emit perespective @@ -12033,8 +12300,7 @@ module ts { getSymbolLinks(unknownSymbol).type = unknownType; globals[undefinedSymbol.name] = undefinedSymbol; // Initialize special types - globalArraySymbol = getGlobalTypeSymbol("Array"); - globalArrayType = getTypeOfGlobalSymbol(globalArraySymbol, /*arity*/ 1); + globalArrayType = getGlobalType("Array", /*arity*/ 1); globalObjectType = getGlobalType("Object"); globalFunctionType = getGlobalType("Function"); globalStringType = getGlobalType("String"); @@ -12052,7 +12318,9 @@ module ts { globalTemplateStringsArrayType = getGlobalType("TemplateStringsArray"); globalESSymbolType = getGlobalType("Symbol"); globalESSymbolConstructorSymbol = getGlobalValueSymbol("Symbol"); - globalIterableType = getGlobalType("Iterable", /*arity*/ 1); + globalIterableType = getGlobalType("Iterable", /*arity*/ 1); + globalIteratorType = getGlobalType("Iterator", /*arity*/ 1); + globalIterableIteratorType = getGlobalType("IterableIterator", /*arity*/ 1); } else { globalTemplateStringsArrayType = unknownType; @@ -12062,6 +12330,9 @@ module ts { // a global Symbol already, particularly if it is a class. globalESSymbolType = createAnonymousType(undefined, emptySymbols, emptyArray, emptyArray, undefined, undefined); globalESSymbolConstructorSymbol = undefined; + globalIterableType = emptyGenericType; + globalIteratorType = emptyGenericType; + globalIterableIteratorType = emptyGenericType; } anyArrayType = createArrayType(anyType); @@ -12245,19 +12516,28 @@ module ts { case SyntaxKind.MethodDeclaration: case SyntaxKind.MethodSignature: case SyntaxKind.IndexSignature: - case SyntaxKind.ClassDeclaration: - case SyntaxKind.InterfaceDeclaration: case SyntaxKind.ModuleDeclaration: - case SyntaxKind.EnumDeclaration: - case SyntaxKind.VariableStatement: - case SyntaxKind.FunctionDeclaration: - case SyntaxKind.TypeAliasDeclaration: case SyntaxKind.ImportDeclaration: case SyntaxKind.ImportEqualsDeclaration: case SyntaxKind.ExportDeclaration: case SyntaxKind.ExportAssignment: case SyntaxKind.Parameter: break; + case SyntaxKind.ClassDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.VariableStatement: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.TypeAliasDeclaration: + if (node.modifiers && node.parent.kind !== SyntaxKind.ModuleBlock && node.parent.kind !== SyntaxKind.SourceFile) { + return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here); + } + break; + case SyntaxKind.EnumDeclaration: + if (node.modifiers && (node.modifiers.length > 1 || node.modifiers[0].kind !== SyntaxKind.ConstKeyword) && + node.parent.kind !== SyntaxKind.ModuleBlock && node.parent.kind !== SyntaxKind.SourceFile) { + return grammarErrorOnFirstToken(node, Diagnostics.Modifiers_cannot_appear_here); + } + break; default: return false; } @@ -12361,9 +12641,6 @@ module ts { else if ((node.kind === SyntaxKind.ImportDeclaration || node.kind === SyntaxKind.ImportEqualsDeclaration) && flags & NodeFlags.Ambient) { return grammarErrorOnNode(lastDeclare, Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); } - else if (node.kind === SyntaxKind.InterfaceDeclaration && flags & NodeFlags.Ambient) { - return grammarErrorOnNode(lastDeclare, Diagnostics.A_declare_modifier_cannot_be_used_with_an_interface_declaration, "declare"); - } else if (node.kind === SyntaxKind.Parameter && (flags & NodeFlags.AccessibilityModifier) && isBindingPattern((node).name)) { return grammarErrorOnNode(node, Diagnostics.A_parameter_property_may_not_be_a_binding_pattern); } @@ -12612,7 +12889,19 @@ module ts { function checkGrammarForGenerator(node: FunctionLikeDeclaration) { if (node.asteriskToken) { - return grammarErrorOnNode(node.asteriskToken, Diagnostics.Generators_are_not_currently_supported); + Debug.assert( + node.kind === SyntaxKind.FunctionDeclaration || + node.kind === SyntaxKind.FunctionExpression || + node.kind === SyntaxKind.MethodDeclaration); + if (isInAmbientContext(node)) { + return grammarErrorOnNode(node.asteriskToken, Diagnostics.Generators_are_not_allowed_in_an_ambient_context); + } + if (!node.body) { + return grammarErrorOnNode(node.asteriskToken, Diagnostics.An_overload_signature_cannot_be_declared_as_a_generator); + } + if (languageVersion < ScriptTarget.ES6) { + return grammarErrorOnNode(node.asteriskToken, Diagnostics.Generators_are_only_available_when_targeting_ECMAScript_6_or_higher); + } } } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 1de9188aed..61739fceca 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -142,7 +142,7 @@ module ts { paramType: Diagnostics.LOCATION, }, { - name: "separateCompilation", + name: "isolatedModules", type: "boolean", }, { @@ -188,10 +188,16 @@ module ts { type: "boolean", description: Diagnostics.Watch_input_files, }, + { + name: "experimentalDecorators", + type: "boolean", + description: Diagnostics.Enables_experimental_support_for_ES7_decorators + }, { name: "emitDecoratorMetadata", type: "boolean", - experimental: true + experimental: true, + description: Diagnostics.Enables_experimental_support_for_emitting_type_metadata_for_decorators } ]; diff --git a/src/compiler/core.ts b/src/compiler/core.ts index ef7c892be9..281bfa36ec 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -129,6 +129,16 @@ module ts { } } + export function rangeEquals(array1: T[], array2: T[], pos: number, end: number) { + while (pos < end) { + if (array1[pos] !== array2[pos]) { + return false; + } + pos++; + } + return true; + } + /** * Returns the last element of an array if non-empty, undefined otherwise. */ @@ -312,8 +322,11 @@ module ts { Debug.assert(start >= 0, "start must be non-negative, is " + start); Debug.assert(length >= 0, "length must be non-negative, is " + length); - Debug.assert(start <= file.text.length, `start must be within the bounds of the file. ${ start } > ${ file.text.length }`); - Debug.assert(end <= file.text.length, `end must be the bounds of the file. ${ end } > ${ file.text.length }`); + + if (file) { + Debug.assert(start <= file.text.length, `start must be within the bounds of the file. ${ start } > ${ file.text.length }`); + Debug.assert(end <= file.text.length, `end must be the bounds of the file. ${ end } > ${ file.text.length }`); + } let text = getLocaleSpecificMessage(message.key); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 32dc590eee..f0b46b26dc 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -120,7 +120,7 @@ module ts { Unterminated_template_literal: { code: 1160, category: DiagnosticCategory.Error, key: "Unterminated template literal." }, Unterminated_regular_expression_literal: { code: 1161, category: DiagnosticCategory.Error, key: "Unterminated regular expression literal." }, An_object_member_cannot_be_declared_optional: { code: 1162, category: DiagnosticCategory.Error, key: "An object member cannot be declared optional." }, - yield_expression_must_be_contained_within_a_generator_declaration: { code: 1163, category: DiagnosticCategory.Error, key: "'yield' expression must be contained_within a generator declaration." }, + A_yield_expression_is_only_allowed_in_a_generator_body: { code: 1163, category: DiagnosticCategory.Error, key: "A 'yield' expression is only allowed in a generator body." }, Computed_property_names_are_not_allowed_in_enums: { code: 1164, category: DiagnosticCategory.Error, key: "Computed property names are not allowed in enums." }, A_computed_property_name_in_an_ambient_context_must_directly_refer_to_a_built_in_symbol: { code: 1165, category: DiagnosticCategory.Error, key: "A computed property name in an ambient context must directly refer to a built-in symbol." }, A_computed_property_name_in_a_class_property_declaration_must_directly_refer_to_a_built_in_symbol: { code: 1166, category: DiagnosticCategory.Error, key: "A computed property name in a class property declaration must directly refer to a built-in symbol." }, @@ -165,8 +165,8 @@ module ts { Decorators_are_only_available_when_targeting_ECMAScript_5_and_higher: { code: 1205, category: DiagnosticCategory.Error, key: "Decorators are only available when targeting ECMAScript 5 and higher." }, Decorators_are_not_valid_here: { code: 1206, category: DiagnosticCategory.Error, key: "Decorators are not valid here." }, Decorators_cannot_be_applied_to_multiple_get_Slashset_accessors_of_the_same_name: { code: 1207, category: DiagnosticCategory.Error, key: "Decorators cannot be applied to multiple get/set accessors of the same name." }, - Cannot_compile_namespaces_when_the_separateCompilation_flag_is_provided: { code: 1208, category: DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--separateCompilation' flag is provided." }, - Ambient_const_enums_are_not_allowed_when_the_separateCompilation_flag_is_provided: { code: 1209, category: DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--separateCompilation' flag is provided." }, + Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided: { code: 1208, category: DiagnosticCategory.Error, key: "Cannot compile namespaces when the '--isolatedModules' flag is provided." }, + Ambient_const_enums_are_not_allowed_when_the_isolatedModules_flag_is_provided: { code: 1209, category: DiagnosticCategory.Error, key: "Ambient const enums are not allowed when the '--isolatedModules' flag is provided." }, Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode: { code: 1210, category: DiagnosticCategory.Error, key: "Invalid use of '{0}'. Class definitions are automatically in strict mode." }, A_class_declaration_without_the_default_modifier_must_have_a_name: { code: 1211, category: DiagnosticCategory.Error, key: "A class declaration without the 'default' modifier must have a name" }, Identifier_expected_0_is_a_reserved_word_in_strict_mode: { code: 1212, category: DiagnosticCategory.Error, key: "Identifier expected. '{0}' is a reserved word in strict mode" }, @@ -174,6 +174,11 @@ module ts { Type_expected_0_is_a_reserved_word_in_strict_mode: { code: 1215, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode" }, Type_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode: { code: 1216, category: DiagnosticCategory.Error, key: "Type expected. '{0}' is a reserved word in strict mode. Class definitions are automatically in strict mode." }, Export_assignment_is_not_supported_when_module_flag_is_system: { code: 1218, category: DiagnosticCategory.Error, key: "Export assignment is not supported when '--module' flag is 'system'." }, + Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Specify_experimentalDecorators_to_remove_this_warning: { code: 1219, category: DiagnosticCategory.Error, key: "Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning." }, + Generators_are_only_available_when_targeting_ECMAScript_6_or_higher: { code: 1220, category: DiagnosticCategory.Error, key: "Generators are only available when targeting ECMAScript 6 or higher." }, + Generators_are_not_allowed_in_an_ambient_context: { code: 1221, category: DiagnosticCategory.Error, key: "Generators are not allowed in an ambient context." }, + An_overload_signature_cannot_be_declared_as_a_generator: { code: 1222, category: DiagnosticCategory.Error, key: "An overload signature cannot be declared as a generator." }, + _0_tag_already_specified: { code: 1223, category: DiagnosticCategory.Error, key: "'{0}' tag already specified." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -334,7 +339,7 @@ module ts { The_0_operator_cannot_be_applied_to_type_symbol: { code: 2469, category: DiagnosticCategory.Error, key: "The '{0}' operator cannot be applied to type 'symbol'." }, Symbol_reference_does_not_refer_to_the_global_Symbol_constructor_object: { code: 2470, category: DiagnosticCategory.Error, key: "'Symbol' reference does not refer to the global Symbol constructor object." }, A_computed_property_name_of_the_form_0_must_be_of_type_symbol: { code: 2471, category: DiagnosticCategory.Error, key: "A computed property name of the form '{0}' must be of type 'symbol'." }, - Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_6_and_higher: { code: 2472, category: DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher." }, + Spread_operator_in_new_expressions_is_only_available_when_targeting_ECMAScript_5_and_higher: { code: 2472, category: DiagnosticCategory.Error, key: "Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher." }, Enum_declarations_must_all_be_const_or_non_const: { code: 2473, category: DiagnosticCategory.Error, key: "Enum declarations must all be const or non-const." }, In_const_enum_declarations_member_initializer_must_be_constant_expression: { code: 2474, category: DiagnosticCategory.Error, key: "In 'const' enum declarations member initializer must be constant expression." }, const_enums_can_only_be_used_in_property_or_index_access_expressions_or_the_right_hand_side_of_an_import_declaration_or_export_assignment: { code: 2475, category: DiagnosticCategory.Error, key: "'const' enums can only be used in property or index access expressions or the right hand side of an import declaration or export assignment." }, @@ -365,6 +370,8 @@ module ts { A_rest_element_cannot_contain_a_binding_pattern: { code: 2501, category: DiagnosticCategory.Error, key: "A rest element cannot contain a binding pattern." }, _0_is_referenced_directly_or_indirectly_in_its_own_type_annotation: { code: 2502, category: DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own type annotation." }, Cannot_find_namespace_0: { code: 2503, category: DiagnosticCategory.Error, key: "Cannot find namespace '{0}'." }, + No_best_common_type_exists_among_yield_expressions: { code: 2504, category: DiagnosticCategory.Error, key: "No best common type exists among yield expressions." }, + A_generator_cannot_have_a_void_type_annotation: { code: 2505, category: DiagnosticCategory.Error, key: "A generator cannot have a 'void' type annotation." }, Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." }, Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." }, Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." }, @@ -449,11 +456,11 @@ module ts { Option_noEmit_cannot_be_specified_with_option_out_or_outDir: { code: 5040, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'out' or 'outDir'." }, Option_noEmit_cannot_be_specified_with_option_declaration: { code: 5041, category: DiagnosticCategory.Error, key: "Option 'noEmit' cannot be specified with option 'declaration'." }, Option_project_cannot_be_mixed_with_source_files_on_a_command_line: { code: 5042, category: DiagnosticCategory.Error, key: "Option 'project' cannot be mixed with source files on a command line." }, - Option_sourceMap_cannot_be_specified_with_option_separateCompilation: { code: 5043, category: DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'separateCompilation'." }, - Option_declaration_cannot_be_specified_with_option_separateCompilation: { code: 5044, category: DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'separateCompilation'." }, - Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation: { code: 5045, category: DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'separateCompilation'." }, - Option_out_cannot_be_specified_with_option_separateCompilation: { code: 5046, category: DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'separateCompilation'." }, - Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: DiagnosticCategory.Error, key: "Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." }, + Option_sourceMap_cannot_be_specified_with_option_isolatedModules: { code: 5043, category: DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'isolatedModules'." }, + Option_declaration_cannot_be_specified_with_option_isolatedModules: { code: 5044, category: DiagnosticCategory.Error, key: "Option 'declaration' cannot be specified with option 'isolatedModules'." }, + Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules: { code: 5045, category: DiagnosticCategory.Error, key: "Option 'noEmitOnError' cannot be specified with option 'isolatedModules'." }, + Option_out_cannot_be_specified_with_option_isolatedModules: { code: 5046, category: DiagnosticCategory.Error, key: "Option 'out' cannot be specified with option 'isolatedModules'." }, + Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher: { code: 5047, category: DiagnosticCategory.Error, key: "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher." }, Option_sourceMap_cannot_be_specified_with_option_inlineSourceMap: { code: 5048, category: DiagnosticCategory.Error, key: "Option 'sourceMap' cannot be specified with option 'inlineSourceMap'." }, Option_sourceRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5049, category: DiagnosticCategory.Error, key: "Option 'sourceRoot' cannot be specified with option 'inlineSourceMap'." }, Option_mapRoot_cannot_be_specified_with_option_inlineSourceMap: { code: 5050, category: DiagnosticCategory.Error, key: "Option 'mapRoot' cannot be specified with option 'inlineSourceMap'." }, @@ -507,6 +514,9 @@ module ts { Specifies_the_end_of_line_sequence_to_be_used_when_emitting_files_Colon_CRLF_dos_or_LF_unix: { code: 6060, category: DiagnosticCategory.Message, key: "Specifies the end of line sequence to be used when emitting files: 'CRLF' (dos) or 'LF' (unix)." }, NEWLINE: { code: 6061, category: DiagnosticCategory.Message, key: "NEWLINE" }, Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." }, + Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified: { code: 6064, category: DiagnosticCategory.Error, key: "Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified." }, + Enables_experimental_support_for_ES7_decorators: { code: 6065, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." }, + Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." }, Variable_0_implicitly_has_an_1_type: { code: 7005, category: DiagnosticCategory.Error, key: "Variable '{0}' implicitly has an '{1}' type." }, Parameter_0_implicitly_has_an_1_type: { code: 7006, category: DiagnosticCategory.Error, key: "Parameter '{0}' implicitly has an '{1}' type." }, Member_0_implicitly_has_an_1_type: { code: 7008, category: DiagnosticCategory.Error, key: "Member '{0}' implicitly has an '{1}' type." }, @@ -519,9 +529,10 @@ module ts { Object_literal_s_property_0_implicitly_has_an_1_type: { code: 7018, category: DiagnosticCategory.Error, key: "Object literal's property '{0}' implicitly has an '{1}' type." }, Rest_parameter_0_implicitly_has_an_any_type: { code: 7019, category: DiagnosticCategory.Error, key: "Rest parameter '{0}' implicitly has an 'any[]' type." }, Call_signature_which_lacks_return_type_annotation_implicitly_has_an_any_return_type: { code: 7020, category: DiagnosticCategory.Error, key: "Call signature, which lacks return-type annotation, implicitly has an 'any' return type." }, - _0_implicitly_has_type_any_because_it_is_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer." }, + _0_implicitly_has_type_any_because_it_does_not_have_a_type_annotation_and_is_referenced_directly_or_indirectly_in_its_own_initializer: { code: 7022, category: DiagnosticCategory.Error, key: "'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer." }, _0_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7023, category: DiagnosticCategory.Error, key: "'{0}' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, Function_implicitly_has_return_type_any_because_it_does_not_have_a_return_type_annotation_and_is_referenced_directly_or_indirectly_in_one_of_its_return_expressions: { code: 7024, category: DiagnosticCategory.Error, key: "Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions." }, + Generator_implicitly_has_type_0_because_it_does_not_yield_any_values_Consider_supplying_a_return_type: { code: 7025, category: DiagnosticCategory.Error, key: "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type." }, You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." }, You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library: { code: 8001, category: DiagnosticCategory.Error, key: "You cannot rename elements that are defined in the standard TypeScript library." }, import_can_only_be_used_in_a_ts_file: { code: 8002, category: DiagnosticCategory.Error, key: "'import ... =' can only be used in a .ts file." }, @@ -535,15 +546,11 @@ module ts { types_can_only_be_used_in_a_ts_file: { code: 8010, category: DiagnosticCategory.Error, key: "'types' can only be used in a .ts file." }, type_arguments_can_only_be_used_in_a_ts_file: { code: 8011, category: DiagnosticCategory.Error, key: "'type arguments' can only be used in a .ts file." }, parameter_modifiers_can_only_be_used_in_a_ts_file: { code: 8012, category: DiagnosticCategory.Error, key: "'parameter modifiers' can only be used in a .ts file." }, - can_only_be_used_in_a_ts_file: { code: 8013, category: DiagnosticCategory.Error, key: "'?' can only be used in a .ts file." }, property_declarations_can_only_be_used_in_a_ts_file: { code: 8014, category: DiagnosticCategory.Error, key: "'property declarations' can only be used in a .ts file." }, enum_declarations_can_only_be_used_in_a_ts_file: { code: 8015, category: DiagnosticCategory.Error, key: "'enum declarations' can only be used in a .ts file." }, type_assertion_expressions_can_only_be_used_in_a_ts_file: { code: 8016, category: DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in a .ts file." }, decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." }, - yield_expressions_are_not_currently_supported: { code: 9000, category: DiagnosticCategory.Error, key: "'yield' expressions are not currently supported." }, - Generators_are_not_currently_supported: { code: 9001, category: DiagnosticCategory.Error, key: "Generators are not currently supported." }, Only_identifiers_Slashqualified_names_with_optional_type_arguments_are_currently_supported_in_a_class_extends_clauses: { code: 9002, category: DiagnosticCategory.Error, key: "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses." }, class_expressions_are_not_currently_supported: { code: 9003, category: DiagnosticCategory.Error, key: "'class' expressions are not currently supported." }, - class_declarations_are_only_supported_directly_inside_a_module_or_as_a_top_level_declaration: { code: 9004, category: DiagnosticCategory.Error, key: "'class' declarations are only supported directly inside a module or as a top level declaration." }, }; } \ No newline at end of file diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index a3dfd62d34..4e32272594 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -467,7 +467,7 @@ "category": "Error", "code": 1162 }, - "'yield' expression must be contained_within a generator declaration.": { + "A 'yield' expression is only allowed in a generator body.": { "category": "Error", "code": 1163 }, @@ -647,11 +647,11 @@ "category": "Error", "code": 1207 }, - "Cannot compile namespaces when the '--separateCompilation' flag is provided.": { + "Cannot compile namespaces when the '--isolatedModules' flag is provided.": { "category": "Error", "code": 1208 }, - "Ambient const enums are not allowed when the '--separateCompilation' flag is provided.": { + "Ambient const enums are not allowed when the '--isolatedModules' flag is provided.": { "category": "Error", "code": 1209 }, @@ -683,6 +683,26 @@ "category": "Error", "code": 1218 }, + "Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.": { + "category": "Error", + "code": 1219 + }, + "Generators are only available when targeting ECMAScript 6 or higher.": { + "category": "Error", + "code": 1220 + }, + "Generators are not allowed in an ambient context.": { + "category": "Error", + "code": 1221 + }, + "An overload signature cannot be declared as a generator.": { + "category": "Error", + "code": 1222 + }, + "'{0}' tag already specified.": { + "category": "Error", + "code": 1223 + }, "Duplicate identifier '{0}'.": { "category": "Error", @@ -1324,7 +1344,7 @@ "category": "Error", "code": 2471 }, - "Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher.": { + "Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher.": { "category": "Error", "code": 2472 }, @@ -1448,6 +1468,14 @@ "category": "Error", "code": 2503 }, + "No best common type exists among yield expressions.": { + "category": "Error", + "code": 2504 + }, + "A generator cannot have a 'void' type annotation.": { + "category": "Error", + "code": 2505 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", @@ -1785,23 +1813,23 @@ "category": "Error", "code": 5042 }, - "Option 'sourceMap' cannot be specified with option 'separateCompilation'.": { + "Option 'sourceMap' cannot be specified with option 'isolatedModules'.": { "category": "Error", "code": 5043 }, - "Option 'declaration' cannot be specified with option 'separateCompilation'.": { + "Option 'declaration' cannot be specified with option 'isolatedModules'.": { "category": "Error", "code": 5044 }, - "Option 'noEmitOnError' cannot be specified with option 'separateCompilation'.": { + "Option 'noEmitOnError' cannot be specified with option 'isolatedModules'.": { "category": "Error", "code": 5045 }, - "Option 'out' cannot be specified with option 'separateCompilation'.": { + "Option 'out' cannot be specified with option 'isolatedModules'.": { "category": "Error", "code": 5046 }, - "Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher.": { + "Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher.": { "category": "Error", "code": 5047 }, @@ -2018,7 +2046,18 @@ "category": "Error", "code": 6062 }, - + "Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified.": { + "category": "Error", + "code": 6064 + }, + "Enables experimental support for ES7 decorators.": { + "category": "Message", + "code": 6065 + }, + "Enables experimental support for emitting type metadata for decorators.": { + "category": "Message", + "code": 6066 + }, "Variable '{0}' implicitly has an '{1}' type.": { "category": "Error", @@ -2068,7 +2107,7 @@ "category": "Error", "code": 7020 }, - "'{0}' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer.": { + "'{0}' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer.": { "category": "Error", "code": 7022 }, @@ -2080,6 +2119,10 @@ "category": "Error", "code": 7024 }, + "Generator implicitly has type '{0}' because it does not yield any values. Consider supplying a return type.": { + "category": "Error", + "code": 7025 + }, "You cannot rename this element.": { "category": "Error", "code": 8000 @@ -2132,10 +2175,6 @@ "category": "Error", "code": 8012 }, - "'?' can only be used in a .ts file.": { - "category": "Error", - "code": 8013 - }, "'property declarations' can only be used in a .ts file.": { "category": "Error", "code": 8014 @@ -2153,14 +2192,6 @@ "code": 8017 }, - "'yield' expressions are not currently supported.": { - "category": "Error", - "code": 9000 - }, - "Generators are not currently supported.": { - "category": "Error", - "code": 9001 - }, "Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses.": { "category": "Error", "code": 9002 @@ -2168,9 +2199,5 @@ "'class' expressions are not currently supported.": { "category": "Error", "code": 9003 - }, - "'class' declarations are only supported directly inside a module or as a top level declaration.": { - "category": "Error", - "code": 9004 } } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index c9d23ec5ce..d0d65aec2f 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1366,16 +1366,16 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { return true; } - function emitListWithSpread(elements: Expression[], alwaysCopy: boolean, multiLine: boolean, trailingComma: boolean) { + function emitListWithSpread(elements: Expression[], needsUniqueCopy: boolean, multiLine: boolean, trailingComma: boolean, useConcat: boolean) { let pos = 0; let group = 0; let length = elements.length; while (pos < length) { // Emit using the pattern .concat(, , ...) - if (group === 1) { + if (group === 1 && useConcat) { write(".concat("); } - else if (group > 1) { + else if (group > 0) { write(", "); } let e = elements[pos]; @@ -1383,7 +1383,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { e = (e).expression; emitParenthesizedIf(e, /*parenthesized*/ group === 0 && needsParenthesisForPropertyAccessOrInvocation(e)); pos++; - if (pos === length && group === 0 && alwaysCopy && e.kind !== SyntaxKind.ArrayLiteralExpression) { + if (pos === length && group === 0 && needsUniqueCopy && e.kind !== SyntaxKind.ArrayLiteralExpression) { write(".slice()"); } } @@ -1406,7 +1406,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { group++; } if (group > 1) { - write(")"); + if(useConcat) { + write(")"); + } } } @@ -1425,8 +1427,8 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write("]"); } else { - emitListWithSpread(elements, /*alwaysCopy*/ true, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0, - /*trailingComma*/ elements.hasTrailingComma); + emitListWithSpread(elements, /*needsUniqueCopy*/ true, /*multiLine*/(node.flags & NodeFlags.MultiLine) !== 0, + /*trailingComma*/ elements.hasTrailingComma, /*useConcat*/ true); } } @@ -1717,7 +1719,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } function tryEmitConstantValue(node: PropertyAccessExpression | ElementAccessExpression): boolean { - if (compilerOptions.separateCompilation) { + if (compilerOptions.isolatedModules) { // do not inline enum values in separate compilation mode return false; } @@ -1850,7 +1852,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write("void 0"); } write(", "); - emitListWithSpread(node.arguments, /*alwaysCopy*/ false, /*multiLine*/ false, /*trailingComma*/ false); + emitListWithSpread(node.arguments, /*needsUniqueCopy*/ false, /*multiLine*/ false, /*trailingComma*/ false, /*useConcat*/ true); write(")"); } @@ -1886,11 +1888,44 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { function emitNewExpression(node: NewExpression) { write("new "); - emit(node.expression); - if (node.arguments) { + + // Spread operator logic can be supported in new expressions in ES5 using a combination + // of Function.prototype.bind() and Function.prototype.apply(). + // + // Example: + // + // var arguments = [1, 2, 3, 4, 5]; + // new Array(...arguments); + // + // Could be transpiled into ES5: + // + // var arguments = [1, 2, 3, 4, 5]; + // new (Array.bind.apply(Array, [void 0].concat(arguments))); + // + // `[void 0]` is the first argument which represents `thisArg` to the bind method above. + // And `thisArg` will be set to the return value of the constructor when instantiated + // with the new operator — regardless of any value we set `thisArg` to. Thus, we set it + // to an undefined, `void 0`. + if (languageVersion === ScriptTarget.ES5 && + node.arguments && + hasSpreadElement(node.arguments)) { + write("("); - emitCommaList(node.arguments); - write(")"); + let target = emitCallTarget(node.expression); + write(".bind.apply("); + emit(target); + write(", [void 0].concat("); + emitListWithSpread(node.arguments, /*needsUniqueCopy*/ false, /*multiline*/ false, /*trailingComma*/ false, /*useConcat*/ false); + write(")))"); + write("()"); + } + else { + emit(node.expression); + if (node.arguments) { + write("("); + emitCommaList(node.arguments); + write(")"); + } } } @@ -2229,9 +2264,10 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { emitEmbeddedStatement(node.statement); } - /* Returns true if start of variable declaration list was emitted. - * Return false if nothing was written - this can happen for source file level variable declarations - * in system modules - such variable declarations are hoisted. + /** + * Returns true if start of variable declaration list was emitted. + * Returns false if nothing was written - this can happen for source file level variable declarations + * in system modules where such variable declarations are hoisted. */ function tryEmitStartOfVariableDeclarationList(decl: VariableDeclarationList, startPos?: number): boolean { if (shouldHoistVariable(decl, /*checkIfSourceFileLevelDecl*/ true)) { @@ -2500,7 +2536,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write(";"); } - function emitWithStatement(node: WhileStatement) { + function emitWithStatement(node: WithStatement) { write("with ("); emit(node.expression); write(")"); @@ -3060,6 +3096,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { function emitVariableStatement(node: VariableStatement) { let startIsEmitted = false; + if (node.flags & NodeFlags.Export) { if (isES6ExportedDeclaration(node)) { // Exported ES6 module member @@ -3070,6 +3107,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { else { startIsEmitted = tryEmitStartOfVariableDeclarationList(node.declarationList); } + if (startIsEmitted) { emitCommaList(node.declarationList.declarations); write(";"); @@ -3085,6 +3123,28 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } } + function shouldEmitLeadingAndTrailingCommentsForVariableStatement(node: VariableStatement) { + // If we're not exporting the variables, there's nothing special here. + // Always emit comments for these nodes. + if (!(node.flags & NodeFlags.Export)) { + return true; + } + + // If we are exporting, but it's a top-level ES6 module exports, + // we'll emit the declaration list verbatim, so emit comments too. + if (isES6ExportedDeclaration(node)) { + return true; + } + + // Otherwise, only emit if we have at least one initializer present. + for (let declaration of node.declarationList.declarations) { + if (declaration.initializer) { + return true; + } + } + return false; + } + function emitParameter(node: ParameterDeclaration) { if (languageVersion < ScriptTarget.ES6) { if (isBindingPattern(node.name)) { @@ -3145,7 +3205,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } function emitRestParameter(node: FunctionLikeDeclaration) { - if (languageVersion < ScriptTarget.ES6 && hasRestParameters(node)) { + if (languageVersion < ScriptTarget.ES6 && hasRestParameter(node)) { let restIndex = node.parameters.length - 1; let restParam = node.parameters[restIndex]; @@ -3273,7 +3333,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { write("("); if (node) { let parameters = node.parameters; - let omitCount = languageVersion < ScriptTarget.ES6 && hasRestParameters(node) ? 1 : 0; + let omitCount = languageVersion < ScriptTarget.ES6 && hasRestParameter(node) ? 1 : 0; emitList(parameters, 0, parameters.length - omitCount, /*multiLine*/ false, /*trailingComma*/ false); } write(")"); @@ -4370,7 +4430,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { function shouldEmitEnumDeclaration(node: EnumDeclaration) { let isConstEnum = isConst(node); - return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.separateCompilation; + return !isConstEnum || compilerOptions.preserveConstEnums || compilerOptions.isolatedModules; } function emitEnumDeclaration(node: EnumDeclaration) { @@ -4475,7 +4535,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } function shouldEmitModuleDeclaration(node: ModuleDeclaration) { - return isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.separateCompilation); + return isInstantiatedModule(node, compilerOptions.preserveConstEnums || compilerOptions.isolatedModules); } function isModuleMergedWithES6Class(node: ModuleDeclaration) { @@ -5684,7 +5744,7 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { } } - if (isExternalModule(node) || compilerOptions.separateCompilation) { + if (isExternalModule(node) || compilerOptions.isolatedModules) { if (languageVersion >= ScriptTarget.ES6) { emitES6Module(node, startIndex); } @@ -5747,6 +5807,9 @@ var __param = (this && this.__param) || function (paramIndex, decorator) { case SyntaxKind.ExportAssignment: return false; + case SyntaxKind.VariableStatement: + return shouldEmitLeadingAndTrailingCommentsForVariableStatement(node); + case SyntaxKind.ModuleDeclaration: // Only emit the leading/trailing comments for a module if we're actually // emitting the module as well. diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index af9b486a1d..80c70a250f 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -315,6 +315,49 @@ module ts { return visitNode(cbNode, (node).expression); case SyntaxKind.MissingDeclaration: return visitNodes(cbNodes, node.decorators); + case SyntaxKind.JSDocTypeExpression: + return visitNode(cbNode, (node).type); + case SyntaxKind.JSDocUnionType: + return visitNodes(cbNodes, (node).types); + case SyntaxKind.JSDocTupleType: + return visitNodes(cbNodes, (node).types); + case SyntaxKind.JSDocArrayType: + return visitNode(cbNode, (node).elementType); + case SyntaxKind.JSDocNonNullableType: + return visitNode(cbNode, (node).type); + case SyntaxKind.JSDocNullableType: + return visitNode(cbNode, (node).type); + case SyntaxKind.JSDocRecordType: + return visitNodes(cbNodes, (node).members); + case SyntaxKind.JSDocTypeReference: + return visitNode(cbNode, (node).name) || + visitNodes(cbNodes, (node).typeArguments); + case SyntaxKind.JSDocOptionalType: + return visitNode(cbNode, (node).type); + case SyntaxKind.JSDocFunctionType: + return visitNodes(cbNodes, (node).parameters) || + visitNode(cbNode, (node).type); + case SyntaxKind.JSDocVariadicType: + return visitNode(cbNode, (node).type); + case SyntaxKind.JSDocConstructorType: + return visitNode(cbNode, (node).type); + case SyntaxKind.JSDocThisType: + return visitNode(cbNode, (node).type); + case SyntaxKind.JSDocRecordMember: + return visitNode(cbNode, (node).name) || + visitNode(cbNode, (node).type); + case SyntaxKind.JSDocComment: + return visitNodes(cbNodes, (node).tags); + case SyntaxKind.JSDocParameterTag: + return visitNode(cbNode, (node).preParameterName) || + visitNode(cbNode, (node).typeExpression) || + visitNode(cbNode, (node).postParameterName); + case SyntaxKind.JSDocReturnTag: + return visitNode(cbNode, (node).typeExpression); + case SyntaxKind.JSDocTypeTag: + return visitNode(cbNode, (node).typeExpression); + case SyntaxKind.JSDocTemplateTag: + return visitNodes(cbNodes, (node).typeParameters); } } @@ -338,6 +381,17 @@ module ts { export function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile { return IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks); } + + /* @internal */ + export function parseIsolatedJSDocComment(content: string, start?: number, length?: number) { + return Parser.JSDocParser.parseIsolatedJSDocComment(content, start, length); + } + + /* @internal */ + // Exposed only for testing. + export function parseJSDocTypeExpressionForTests(content: string, start?: number, length?: number) { + return Parser.JSDocParser.parseJSDocTypeExpressionForTests(content, start, length); + } // Implement the parser as a singleton module. We do this for perf reasons because creating // parser instances can actually be expensive enough to impact us on projects with many source @@ -345,10 +399,11 @@ module ts { module Parser { // Share a single scanner across all calls to parse a source file. This helps speed things // up by avoiding the cost of creating/compiling scanners over and over again. - const scanner = createScanner(ScriptTarget.Latest, /*skipTrivia:*/ true); + const scanner = createScanner(ScriptTarget.Latest, /*skipTrivia*/ true); const disallowInAndDecoratorContext = ParserContextFlags.DisallowIn | ParserContextFlags.Decorator; let sourceFile: SourceFile; + let parseDiagnostics: Diagnostic[]; let syntaxCursor: IncrementalParser.SyntaxCursor; let token: SyntaxKind; @@ -405,7 +460,7 @@ module ts { // Note: it should not be necessary to save/restore these flags during speculative/lookahead // parsing. These context flags are naturally stored and restored through normal recursive // descent parsing and unwinding. - let contextFlags: ParserContextFlags = 0; + let contextFlags: ParserContextFlags; // Whether or not we've had a parse error since creating the last AST node. If we have // encountered an error, it will be stored on the next AST node we create. Parse errors @@ -436,26 +491,60 @@ module ts { // attached to the EOF token. let parseErrorBeforeNextFinishedNode: boolean = false; + export const enum StatementFlags { + None = 0, + Statement = 1, + ModuleElement = 2, + StatementOrModuleElement = Statement | ModuleElement + } + export function parseSourceFile(fileName: string, _sourceText: string, languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor, setParentNodes?: boolean): SourceFile { + initializeState(fileName, _sourceText, languageVersion, _syntaxCursor); + + let result = parseSourceFileWorker(fileName, languageVersion, setParentNodes); + + clearState(); + + return result; + } + + function initializeState(fileName: string, _sourceText: string, languageVersion: ScriptTarget, _syntaxCursor: IncrementalParser.SyntaxCursor) { sourceText = _sourceText; syntaxCursor = _syntaxCursor; + parseDiagnostics = []; parsingContext = 0; identifiers = {}; identifierCount = 0; nodeCount = 0; - contextFlags = 0; + contextFlags = isJavaScript(fileName) ? ParserContextFlags.JavaScriptFile : ParserContextFlags.None; parseErrorBeforeNextFinishedNode = false; - createSourceFile(fileName, languageVersion); - // Initialize and prime the scanner before parsing the source elements. scanner.setText(sourceText); scanner.setOnError(scanError); scanner.setScriptTarget(languageVersion); - token = nextToken(); + } + function clearState() { + // Clear out the text the scanner is pointing at, so it doesn't keep anything alive unnecessarily. + scanner.setText(""); + scanner.setOnError(undefined); + + // Clear any data. We don't want to accidently hold onto it for too long. + parseDiagnostics = undefined; + sourceFile = undefined; + identifiers = undefined; + syntaxCursor = undefined; + sourceText = undefined; + } + + function parseSourceFileWorker(fileName: string, languageVersion: ScriptTarget, setParentNodes: boolean): SourceFile { + sourceFile = createSourceFile(fileName, languageVersion); + + // Prime the scanner. + token = nextToken(); processReferenceComments(sourceFile); sourceFile.statements = parseList(ParsingContext.SourceElements, /*checkForStrictMode*/ true, parseSourceElement); @@ -467,29 +556,53 @@ module ts { sourceFile.nodeCount = nodeCount; sourceFile.identifierCount = identifierCount; sourceFile.identifiers = identifiers; + sourceFile.parseDiagnostics = parseDiagnostics; if (setParentNodes) { fixupParentReferences(sourceFile); } - syntaxCursor = undefined; + // If this is a javascript file, proactively see if we can get JSDoc comments for + // relevant nodes in the file. We'll use these to provide typing informaion if they're + // available. + if (isJavaScript(fileName)) { + addJSDocComments(); + } - // Clear out the text the scanner is pointing at, so it doesn't keep anything alive unnecessarily. - scanner.setText(""); - scanner.setOnError(undefined); - - let result = sourceFile; - - // Clear any data. We don't want to accidently hold onto it for too long. - sourceFile = undefined; - identifiers = undefined; - syntaxCursor = undefined; - sourceText = undefined; - - return result; + return sourceFile; } - function fixupParentReferences(sourceFile: SourceFile) { + function addJSDocComments() { + forEachChild(sourceFile, visit); + return; + + function visit(node: Node) { + // Add additional cases as necessary depending on how we see JSDoc comments used + // in the wild. + switch (node.kind) { + case SyntaxKind.VariableStatement: + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.Parameter: + addJSDocComment(node); + } + + forEachChild(node, visit); + } + } + + function addJSDocComment(node: Node) { + let comments = getLeadingCommentRangesOfNode(node, sourceFile); + if (comments) { + for (let comment of comments) { + let jsDocComment = JSDocParser.parseJSDocComment(node, comment.pos, comment.end - comment.pos); + if (jsDocComment) { + node.jsDocComment = jsDocComment; + } + } + } + } + + export function fixupParentReferences(sourceFile: Node) { // normally parent references are set during binding. However, for clients that only need // a syntax tree, and no semantic features, then the binding process is an unnecessary // overhead. This functions allows us to set all the parents, without all the expense of @@ -514,18 +627,18 @@ module ts { } } - function createSourceFile(fileName: string, languageVersion: ScriptTarget) { - sourceFile = createNode(SyntaxKind.SourceFile, /*pos*/ 0); + function createSourceFile(fileName: string, languageVersion: ScriptTarget): SourceFile { + let sourceFile = createNode(SyntaxKind.SourceFile, /*pos*/ 0); sourceFile.pos = 0; sourceFile.end = sourceText.length; sourceFile.text = sourceText; - - sourceFile.parseDiagnostics = []; sourceFile.bindDiagnostics = []; sourceFile.languageVersion = languageVersion; sourceFile.fileName = normalizePath(fileName); sourceFile.flags = fileExtensionIs(sourceFile.fileName, ".d.ts") ? NodeFlags.DeclarationFile : 0; + + return sourceFile; } function setContextFlag(val: Boolean, flag: ParserContextFlags) { @@ -659,9 +772,9 @@ module ts { function parseErrorAtPosition(start: number, length: number, message: DiagnosticMessage, arg0?: any): void { // Don't report another error if it would just be at the same position as the last error. - let lastError = lastOrUndefined(sourceFile.parseDiagnostics); + let lastError = lastOrUndefined(parseDiagnostics); if (!lastError || start !== lastError.start) { - sourceFile.parseDiagnostics.push(createFileDiagnostic(sourceFile, start, length, message, arg0)); + parseDiagnostics.push(createFileDiagnostic(sourceFile, start, length, message, arg0)); } // Mark that we've encountered an error. We'll set an appropriate bit on the next @@ -706,7 +819,7 @@ module ts { // Keep track of the state we'll need to rollback to if lookahead fails (or if the // caller asked us to always reset our state). let saveToken = token; - let saveParseDiagnosticsLength = sourceFile.parseDiagnostics.length; + let saveParseDiagnosticsLength = parseDiagnostics.length; let saveParseErrorBeforeNextFinishedNode = parseErrorBeforeNextFinishedNode; // Note: it is not actually necessary to save/restore the context flags here. That's @@ -728,7 +841,7 @@ module ts { // then unconditionally restore us to where we were. if (!result || isLookAhead) { token = saveToken; - sourceFile.parseDiagnostics.length = saveParseDiagnosticsLength; + parseDiagnostics.length = saveParseDiagnosticsLength; parseErrorBeforeNextFinishedNode = saveParseErrorBeforeNextFinishedNode; } @@ -739,7 +852,7 @@ module ts { // was in immediately prior to invoking the callback. The result of invoking the callback // is returned from this function. function lookAhead(callback: () => T): T { - return speculationHelper(callback, /*isLookAhead:*/ true); + return speculationHelper(callback, /*isLookAhead*/ true); } // Invokes the provided callback. If the callback returns something falsy, then it restores @@ -747,7 +860,7 @@ module ts { // callback returns something truthy, then the parser state is not rolled back. The result // of invoking the callback is returned from this function. function tryParse(callback: () => T): T { - return speculationHelper(callback, /*isLookAhead:*/ false); + return speculationHelper(callback, /*isLookAhead*/ false); } // Ignore strict mode flag because we will report an error in type checker instead. @@ -843,8 +956,8 @@ module ts { return node; } - function finishNode(node: T): T { - node.end = scanner.getStartPos(); + function finishNode(node: T, end?: number): T { + node.end = end === undefined ? scanner.getStartPos() : end; if (contextFlags) { node.parserContextFlags = contextFlags; @@ -896,7 +1009,7 @@ module ts { return finishNode(node); } - return createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition:*/ false, diagnosticMessage || Diagnostics.Identifier_expected); + return createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ false, diagnosticMessage || Diagnostics.Identifier_expected); } function parseIdentifier(diagnosticMessage?: DiagnosticMessage): Identifier { @@ -913,16 +1026,28 @@ module ts { token === SyntaxKind.NumericLiteral; } - function parsePropertyName(): DeclarationName { + function parsePropertyNameWorker(allowComputedPropertyNames: boolean): DeclarationName { if (token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral) { - return parseLiteralNode(/*internName:*/ true); + return parseLiteralNode(/*internName*/ true); } - if (token === SyntaxKind.OpenBracketToken) { + if (allowComputedPropertyNames && token === SyntaxKind.OpenBracketToken) { return parseComputedPropertyName(); } return parseIdentifierName(); } + function parsePropertyName(): DeclarationName { + return parsePropertyNameWorker(/*allowComputedPropertyNames:*/ true); + } + + function parseSimplePropertyName(): Identifier | LiteralExpression { + return parsePropertyNameWorker(/*allowComputedPropertyNames:*/ false); + } + + function isSimplePropertyName() { + return token === SyntaxKind.StringLiteral || token === SyntaxKind.NumericLiteral || isIdentifierOrKeyword(); + } + function parseComputedPropertyName(): ComputedPropertyName { // PropertyName[Yield,GeneratorParameter] : // LiteralPropertyName @@ -1001,10 +1126,17 @@ module ts { switch (parsingContext) { case ParsingContext.SourceElements: case ParsingContext.ModuleElements: - return isSourceElement(inErrorRecovery); + // If we're in error recovery, then we don't want to treat ';' as an empty statement. + // The problem is that ';' can show up in far too many contexts, and if we see one + // and assume it's a statement, then we may bail out inappropriately from whatever + // we're parsing. For example, if we have a semicolon in the middle of a class, then + // we really don't want to assume the class is over and we're on a statement in the + // outer module. We just want to consume and move on. + return !(token === SyntaxKind.SemicolonToken && inErrorRecovery) && isStartOfModuleElement(); case ParsingContext.BlockStatements: case ParsingContext.SwitchClauseStatements: - return isStartOfStatement(inErrorRecovery); + // During error recovery we don't treat empty statements as statements + return !(token === SyntaxKind.SemicolonToken && inErrorRecovery) && isStartOfStatement(); case ParsingContext.SwitchClauses: return token === SyntaxKind.CaseKeyword || token === SyntaxKind.DefaultKeyword; case ParsingContext.TypeMembers: @@ -1057,6 +1189,12 @@ module ts { return isHeritageClause(); case ParsingContext.ImportOrExportSpecifiers: return isIdentifierOrKeyword(); + case ParsingContext.JSDocFunctionParameters: + case ParsingContext.JSDocTypeArguments: + case ParsingContext.JSDocTupleTypes: + return JSDocParser.isJSDocType(); + case ParsingContext.JSDocRecordMembers: + return isSimplePropertyName(); } Debug.fail("Non-exhaustive case in 'isListElement'."); @@ -1142,6 +1280,14 @@ module ts { return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.OpenParenToken; case ParsingContext.HeritageClauses: return token === SyntaxKind.OpenBraceToken || token === SyntaxKind.CloseBraceToken; + case ParsingContext.JSDocFunctionParameters: + return token === SyntaxKind.CloseParenToken || token === SyntaxKind.ColonToken || token === SyntaxKind.CloseBraceToken; + case ParsingContext.JSDocTypeArguments: + return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.CloseBraceToken; + case ParsingContext.JSDocTupleTypes: + return token === SyntaxKind.CloseBracketToken || token === SyntaxKind.CloseBraceToken; + case ParsingContext.JSDocRecordMembers: + return token === SyntaxKind.CloseBraceToken; } } @@ -1199,7 +1345,7 @@ module ts { // test elements only if we are not already in strict mode if (checkForStrictMode && !inStrictModeContext()) { if (isPrologueDirective(element)) { - if (isUseStrictPrologueDirective(sourceFile, element)) { + if (isUseStrictPrologueDirective(element)) { setStrictModeContext(true); checkForStrictMode = false; } @@ -1224,9 +1370,9 @@ module ts { } /// Should be called only on prologue directives (isPrologueDirective(node) should be true) - function isUseStrictPrologueDirective(sourceFile: SourceFile, node: Node): boolean { + function isUseStrictPrologueDirective(node: Node): boolean { Debug.assert(isPrologueDirective(node)); - let nodeText = getSourceTextOfNodeFromSourceFile(sourceFile, (node).expression); + let nodeText = getTextOfNodeFromSourceText(sourceText, (node).expression); // Note: the node text must be exactly "use strict" or 'use strict'. It is not ok for the // string to contain unicode escapes (as per ES5). @@ -1547,6 +1693,10 @@ module ts { case ParsingContext.TupleElementTypes: return Diagnostics.Type_expected; case ParsingContext.HeritageClauses: return Diagnostics.Unexpected_token_expected; case ParsingContext.ImportOrExportSpecifiers: return Diagnostics.Identifier_expected; + case ParsingContext.JSDocFunctionParameters: return Diagnostics.Parameter_declaration_expected; + case ParsingContext.JSDocTypeArguments: return Diagnostics.Type_argument_expected; + case ParsingContext.JSDocTupleTypes: return Diagnostics.Type_expected; + case ParsingContext.JSDocRecordMembers: return Diagnostics.Property_assignment_expected; } }; @@ -1667,7 +1817,7 @@ module ts { // Report that we need an identifier. However, report it right after the dot, // and not on the next token. This is because the next token might actually // be an identifier and the error woudl be quite confusing. - return createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentToken:*/ true, Diagnostics.Identifier_expected); + return createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentToken*/ true, Diagnostics.Identifier_expected); } } @@ -1705,7 +1855,7 @@ module ts { literal = parseLiteralNode(); } else { - literal = parseExpectedToken(SyntaxKind.TemplateTail, /*reportAtCurrentPosition:*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.CloseBraceToken)); + literal = parseExpectedToken(SyntaxKind.TemplateTail, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.CloseBraceToken)); } span.literal = literal; @@ -1798,7 +1948,7 @@ module ts { function parseParameterType(): TypeNode { if (parseOptional(SyntaxKind.ColonToken)) { return token === SyntaxKind.StringLiteral - ? parseLiteralNode(/*internName:*/ true) + ? parseLiteralNode(/*internName*/ true) : parseType(); } @@ -1939,7 +2089,7 @@ module ts { if (kind === SyntaxKind.ConstructSignature) { parseExpected(SyntaxKind.NewKeyword); } - fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, node); + fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ false, /*requireCompleteParameterList*/ false, node); parseTypeMemberSemicolon(); return finishNode(node); } @@ -2029,7 +2179,7 @@ module ts { // Method signatues don't exist in expression contexts. So they have neither // [Yield] nor [GeneratorParameter] - fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, method); + fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ false, /*requireCompleteParameterList*/ false, method); parseTypeMemberSemicolon(); return finishNode(method); } @@ -2086,7 +2236,7 @@ module ts { case SyntaxKind.OpenBracketToken: // Indexer or computed property return isIndexSignature() - ? parseIndexSignatureDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined) + ? parseIndexSignatureDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined) : parsePropertyOrMethodSignature(); case SyntaxKind.NewKeyword: if (lookAhead(isStartOfConstructSignature)) { @@ -2168,7 +2318,7 @@ module ts { if (kind === SyntaxKind.ConstructorType) { parseExpected(SyntaxKind.NewKeyword); } - fillSignature(SyntaxKind.EqualsGreaterThanToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, node); + fillSignature(SyntaxKind.EqualsGreaterThanToken, /*yieldAndGeneratorParameterContext*/ false, /*requireCompleteParameterList*/ false, node); return finishNode(node); } @@ -2477,7 +2627,7 @@ module ts { // Otherwise, we try to parse out the conditional expression bit. We want to allow any // binary expression here, so we pass in the 'lowest' precedence here so that it matches // and consumes anything. - let expr = parseBinaryExpressionOrHigher(/*precedence:*/ 0); + let expr = parseBinaryExpressionOrHigher(/*precedence*/ 0); // To avoid a look-ahead, we did not handle the case of an arrow function with a single un-parenthesized // parameter ('x => ...') above. We handle it here by checking if the parsed expression was a single @@ -2539,12 +2689,6 @@ module ts { return !scanner.hasPrecedingLineBreak() && isIdentifier() } - function nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine() { - nextToken(); - return !scanner.hasPrecedingLineBreak() && - (isIdentifier() || token === SyntaxKind.OpenBraceToken || token === SyntaxKind.OpenBracketToken); - } - function parseYieldExpression(): YieldExpression { let node = createNode(SyntaxKind.YieldExpression); @@ -2599,7 +2743,7 @@ module ts { // it out, but don't allow any ambiguity, and return 'undefined' if this could be an // expression instead. let arrowFunction = triState === Tristate.True - ? parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity:*/ true) + ? parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity*/ true) : tryParse(parsePossibleParenthesizedArrowFunctionExpressionHead); if (!arrowFunction) { @@ -2610,7 +2754,7 @@ module ts { // If we have an arrow, then try to parse the body. Even if not, try to parse if we // have an opening brace, just in case we're in an error state. var lastToken = token; - arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, /*reportAtCurrentPosition:*/false, Diagnostics._0_expected, "=>"); + arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, /*reportAtCurrentPosition*/false, Diagnostics._0_expected, "=>"); arrowFunction.body = (lastToken === SyntaxKind.EqualsGreaterThanToken || lastToken === SyntaxKind.OpenBraceToken) ? parseArrowFunctionExpressionBody() : parseIdentifier(); @@ -2708,7 +2852,7 @@ module ts { } function parsePossibleParenthesizedArrowFunctionExpressionHead(): ArrowFunction { - return parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity:*/ false); + return parseParenthesizedArrowFunctionExpressionHead(/*allowAmbiguity*/ false); } function parseParenthesizedArrowFunctionExpressionHead(allowAmbiguity: boolean): ArrowFunction { @@ -2720,7 +2864,7 @@ module ts { // a => (b => c) // And think that "(b =>" was actually a parenthesized arrow function with a missing // close paren. - fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ !allowAmbiguity, node); + fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ false, /*requireCompleteParameterList*/ !allowAmbiguity, node); // If we couldn't get parameters, we definitely could not parse out an arrow function. if (!node.parameters) { @@ -2745,14 +2889,14 @@ module ts { function parseArrowFunctionExpressionBody(): Block | Expression { if (token === SyntaxKind.OpenBraceToken) { - return parseFunctionBlock(/*allowYield:*/ false, /* ignoreMissingOpenBrace */ false); + return parseFunctionBlock(/*allowYield*/ false, /*ignoreMissingOpenBrace*/ false); } - if (isStartOfStatement(/*inErrorRecovery:*/ true) && - !isStartOfExpressionStatement() && + if (token !== SyntaxKind.SemicolonToken && token !== SyntaxKind.FunctionKeyword && - token !== SyntaxKind.ClassKeyword) { - + token !== SyntaxKind.ClassKeyword && + isStartOfStatement() && + !isStartOfExpressionStatement()) { // Check if we got a plain statement (i.e. no expression-statements, no function/class expressions/declarations) // // Here we try to recover from a potential error situation in the case where the @@ -2767,7 +2911,7 @@ module ts { // up preemptively closing the containing construct. // // Note: even when 'ignoreMissingOpenBrace' is passed as true, parseBody will still error. - return parseFunctionBlock(/*allowYield:*/ false, /* ignoreMissingOpenBrace */ true); + return parseFunctionBlock(/*allowYield*/ false, /*ignoreMissingOpenBrace*/ true); } return parseAssignmentExpressionOrHigher(); @@ -2786,7 +2930,7 @@ module ts { node.condition = leftOperand; node.questionToken = questionToken; node.whenTrue = doOutsideOfContext(disallowInAndDecoratorContext, parseAssignmentExpressionOrHigher); - node.colonToken = parseExpectedToken(SyntaxKind.ColonToken, /*reportAtCurrentPosition:*/ false, + node.colonToken = parseExpectedToken(SyntaxKind.ColonToken, /*reportAtCurrentPosition*/ false, Diagnostics._0_expected, tokenToString(SyntaxKind.ColonToken)); node.whenFalse = parseAssignmentExpressionOrHigher(); return finishNode(node); @@ -3050,8 +3194,8 @@ module ts { // If it wasn't then just try to parse out a '.' and report an error. let node = createNode(SyntaxKind.PropertyAccessExpression, expression.pos); node.expression = expression; - node.dotToken = parseExpectedToken(SyntaxKind.DotToken, /*reportAtCurrentPosition:*/ false, Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); - node.name = parseRightSideOfDot(/*allowIdentifierNames:*/ true); + node.dotToken = parseExpectedToken(SyntaxKind.DotToken, /*reportAtCurrentPosition*/ false, Diagnostics.super_must_be_followed_by_an_argument_list_or_member_access); + node.name = parseRightSideOfDot(/*allowIdentifierNames*/ true); return finishNode(node); } @@ -3071,7 +3215,7 @@ module ts { let propertyAccess = createNode(SyntaxKind.PropertyAccessExpression, expression.pos); propertyAccess.expression = expression; propertyAccess.dotToken = dotToken; - propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames:*/ true); + propertyAccess.name = parseRightSideOfDot(/*allowIdentifierNames*/ true); expression = finishNode(propertyAccess); continue; } @@ -3334,7 +3478,7 @@ module ts { node.flags |= NodeFlags.MultiLine; } - node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralElement, /*considerSemicolonAsDelimeter:*/ true); + node.properties = parseDelimitedList(ParsingContext.ObjectLiteralMembers, parseObjectLiteralElement, /*considerSemicolonAsDelimeter*/ true); parseExpected(SyntaxKind.CloseBraceToken); return finishNode(node); } @@ -3352,8 +3496,8 @@ module ts { parseExpected(SyntaxKind.FunctionKeyword); node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); node.name = node.asteriskToken ? doInYieldContext(parseOptionalIdentifier) : parseOptionalIdentifier(); - fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ !!node.asteriskToken, /*requireCompleteParameterList:*/ false, node); - node.body = parseFunctionBlock(/*allowYield:*/ !!node.asteriskToken, /* ignoreMissingOpenBrace */ false); + fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ !!node.asteriskToken, /*requireCompleteParameterList*/ false, node); + node.body = parseFunctionBlock(/*allowYield*/ !!node.asteriskToken, /* ignoreMissingOpenBrace */ false); if (saveDecoratorContext) { setDecoratorContext(true); } @@ -3463,7 +3607,7 @@ module ts { let initializer: VariableDeclarationList | Expression = undefined; if (token !== SyntaxKind.SemicolonToken) { if (token === SyntaxKind.VarKeyword || token === SyntaxKind.LetKeyword || token === SyntaxKind.ConstKeyword) { - initializer = parseVariableDeclarationList(/*inForStatementInitializer:*/ true); + initializer = parseVariableDeclarationList(/*inForStatementInitializer*/ true); } else { initializer = disallowInAnd(parseExpression); @@ -3593,14 +3737,14 @@ module ts { let node = createNode(SyntaxKind.TryStatement); parseExpected(SyntaxKind.TryKeyword); - node.tryBlock = parseBlock(/*ignoreMissingOpenBrace:*/ false, /*checkForStrictMode*/ false); + node.tryBlock = parseBlock(/*ignoreMissingOpenBrace*/ false, /*checkForStrictMode*/ false); node.catchClause = token === SyntaxKind.CatchKeyword ? parseCatchClause() : undefined; // If we don't have a catch clause, then we must have a finally clause. Try to parse // one out no matter what. if (!node.catchClause || token === SyntaxKind.FinallyKeyword) { parseExpected(SyntaxKind.FinallyKeyword); - node.finallyBlock = parseBlock(/*ignoreMissingOpenBrace:*/ false, /*checkForStrictMode*/ false); + node.finallyBlock = parseBlock(/*ignoreMissingOpenBrace*/ false, /*checkForStrictMode*/ false); } return finishNode(node); @@ -3614,7 +3758,7 @@ module ts { } parseExpected(SyntaxKind.CloseParenToken); - result.block = parseBlock(/*ignoreMissingOpenBrace:*/ false, /*checkForStrictMode:*/ false); + result.block = parseBlock(/*ignoreMissingOpenBrace*/ false, /*checkForStrictMode*/ false); return finishNode(result); } @@ -3646,34 +3790,72 @@ module ts { } } - function isStartOfStatement(inErrorRecovery: boolean): boolean { - // Functions, variable statements and classes are allowed as a statement. But as per - // the grammar, they also allow modifiers. So we have to check for those statements - // that might be following modifiers.This ensures that things work properly when - // incrementally parsing as the parser will produce the same FunctionDeclaraiton, - // VariableStatement or ClassDeclaration, if it has the same text regardless of whether - // it is inside a block or not. - if (isModifier(token)) { - let result = lookAhead(parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers); - if (result) { - return true; + function isIdentifierOrKeyword() { + return token >= SyntaxKind.Identifier; + } + + function nextTokenIsIdentifierOrKeywordOnSameLine() { + nextToken(); + return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak(); + } + + function parseDeclarationFlags(): StatementFlags { + while (true) { + switch (token) { + case SyntaxKind.VarKeyword: + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: + case SyntaxKind.FunctionKeyword: + case SyntaxKind.ClassKeyword: + case SyntaxKind.EnumKeyword: + return StatementFlags.Statement; + case SyntaxKind.InterfaceKeyword: + case SyntaxKind.TypeKeyword: + nextToken(); + return isIdentifierOrKeyword() ? StatementFlags.Statement : StatementFlags.None; + case SyntaxKind.ModuleKeyword: + case SyntaxKind.NamespaceKeyword: + nextToken(); + return isIdentifierOrKeyword() || token === SyntaxKind.StringLiteral ? StatementFlags.ModuleElement : StatementFlags.None; + case SyntaxKind.ImportKeyword: + nextToken(); + return token === SyntaxKind.StringLiteral || token === SyntaxKind.AsteriskToken || + token === SyntaxKind.OpenBraceToken || isIdentifierOrKeyword() ? + StatementFlags.ModuleElement : StatementFlags.None; + case SyntaxKind.ExportKeyword: + nextToken(); + if (token === SyntaxKind.EqualsToken || token === SyntaxKind.AsteriskToken || + token === SyntaxKind.OpenBraceToken || token === SyntaxKind.DefaultKeyword) { + return StatementFlags.ModuleElement; + } + continue; + case SyntaxKind.DeclareKeyword: + case SyntaxKind.PublicKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + case SyntaxKind.StaticKeyword: + nextToken(); + continue; + default: + return StatementFlags.None; } } + } + function getDeclarationFlags(): StatementFlags { + return lookAhead(parseDeclarationFlags); + } + + function getStatementFlags(): StatementFlags { switch (token) { + case SyntaxKind.AtToken: case SyntaxKind.SemicolonToken: - // If we're in error recovery, then we don't want to treat ';' as an empty statement. - // The problem is that ';' can show up in far too many contexts, and if we see one - // and assume it's a statement, then we may bail out inappropriately from whatever - // we're parsing. For example, if we have a semicolon in the middle of a class, then - // we really don't want to assume the class is over and we're on a statement in the - // outer module. We just want to consume and move on. - return !inErrorRecovery; case SyntaxKind.OpenBraceToken: case SyntaxKind.VarKeyword: case SyntaxKind.LetKeyword: case SyntaxKind.FunctionKeyword: case SyntaxKind.ClassKeyword: + case SyntaxKind.EnumKeyword: case SyntaxKind.IfKeyword: case SyntaxKind.DoKeyword: case SyntaxKind.WhileKeyword: @@ -3690,62 +3872,84 @@ module ts { // however, we say they are here so that we may gracefully parse them and error later. case SyntaxKind.CatchKeyword: case SyntaxKind.FinallyKeyword: - return true; + return StatementFlags.Statement; + case SyntaxKind.ConstKeyword: - // const keyword can precede enum keyword when defining constant enums - // 'const enum' do not start statement. - // In ES 6 'enum' is a future reserved keyword, so it should not be used as identifier - let isConstEnum = lookAhead(nextTokenIsEnumKeyword); - return !isConstEnum; + case SyntaxKind.ExportKeyword: + case SyntaxKind.ImportKeyword: + return getDeclarationFlags(); + + case SyntaxKind.DeclareKeyword: case SyntaxKind.InterfaceKeyword: case SyntaxKind.ModuleKeyword: case SyntaxKind.NamespaceKeyword: - case SyntaxKind.EnumKeyword: case SyntaxKind.TypeKeyword: - // When followed by an identifier, these do not start a statement but might - // instead be following declarations - if (isDeclarationStart()) { - return false; - } + // When these don't start a declaration, they're an identifier in an expression statement + return getDeclarationFlags() || StatementFlags.Statement; case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: case SyntaxKind.ProtectedKeyword: case SyntaxKind.StaticKeyword: - // When followed by an identifier or keyword, these do not start a statement but - // might instead be following type members - if (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine)) { - return false; - } + // When these don't start a declaration, they may be the start of a class member if an identifier + // immediately follows. Otherwise they're an identifier in an expression statement. + return getDeclarationFlags() || + (lookAhead(nextTokenIsIdentifierOrKeywordOnSameLine) ? StatementFlags.None : StatementFlags.Statement); + default: - return isStartOfExpression(); + return isStartOfExpression() ? StatementFlags.Statement : StatementFlags.None; } } - function nextTokenIsEnumKeyword() { - nextToken(); - return token === SyntaxKind.EnumKeyword + function isStartOfStatement(): boolean { + return (getStatementFlags() & StatementFlags.Statement) !== 0; } - function nextTokenIsIdentifierOrKeywordOnSameLine() { + function isStartOfModuleElement(): boolean { + return (getStatementFlags() & StatementFlags.StatementOrModuleElement) !== 0; + } + + function nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine() { nextToken(); - return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak(); + return !scanner.hasPrecedingLineBreak() && + (isIdentifier() || token === SyntaxKind.OpenBraceToken || token === SyntaxKind.OpenBracketToken); + } + + function isLetDeclaration() { + // It is let declaration if in strict mode or next token is identifier\open bracket\open curly on same line. + // otherwise it needs to be treated like identifier + return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine); } function parseStatement(): Statement { + return parseModuleElementOfKind(StatementFlags.Statement); + } + + function parseModuleElement(): ModuleElement { + return parseModuleElementOfKind(StatementFlags.StatementOrModuleElement); + } + + function parseSourceElement(): ModuleElement { + return parseModuleElementOfKind(StatementFlags.StatementOrModuleElement); + } + + function parseModuleElementOfKind(flags: StatementFlags): ModuleElement { switch (token) { - case SyntaxKind.OpenBraceToken: - return parseBlock(/*ignoreMissingOpenBrace:*/ false, /*checkForStrictMode:*/ false); - case SyntaxKind.VarKeyword: - case SyntaxKind.ConstKeyword: - // const here should always be parsed as const declaration because of check in 'isStatement' - return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined); - case SyntaxKind.FunctionKeyword: - return parseFunctionDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined); - case SyntaxKind.ClassKeyword: - return parseClassDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined); case SyntaxKind.SemicolonToken: return parseEmptyStatement(); + case SyntaxKind.OpenBraceToken: + return parseBlock(/*ignoreMissingOpenBrace*/ false, /*checkForStrictMode*/ false); + case SyntaxKind.VarKeyword: + return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); + case SyntaxKind.LetKeyword: + if (isLetDeclaration()) { + return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); + } + break; + case SyntaxKind.FunctionKeyword: + return parseFunctionDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); + case SyntaxKind.ClassKeyword: + return parseClassDeclaration(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers*/ undefined); case SyntaxKind.IfKeyword: return parseIfStatement(); case SyntaxKind.DoKeyword: @@ -3773,61 +3977,69 @@ module ts { return parseTryStatement(); case SyntaxKind.DebuggerKeyword: return parseDebuggerStatement(); - case SyntaxKind.LetKeyword: - // If let follows identifier on the same line, it is declaration parse it as variable statement - if (isLetDeclaration()) { - return parseVariableStatement(scanner.getStartPos(), /*decorators*/ undefined, /*modifiers:*/ undefined); + case SyntaxKind.AtToken: + return parseDeclaration(); + case SyntaxKind.ConstKeyword: + case SyntaxKind.DeclareKeyword: + case SyntaxKind.EnumKeyword: + case SyntaxKind.ExportKeyword: + case SyntaxKind.ImportKeyword: + case SyntaxKind.InterfaceKeyword: + case SyntaxKind.ModuleKeyword: + case SyntaxKind.NamespaceKeyword: + case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: + case SyntaxKind.PublicKeyword: + case SyntaxKind.StaticKeyword: + case SyntaxKind.TypeKeyword: + if (getDeclarationFlags() & flags) { + return parseDeclaration(); } - // Else parse it like identifier - fall through - default: - // Functions and variable statements are allowed as a statement. But as per - // the grammar, they also allow modifiers. So we have to check for those - // statements that might be following modifiers. This ensures that things - // work properly when incrementally parsing as the parser will produce the - // same FunctionDeclaraiton or VariableStatement if it has the same text - // regardless of whether it is inside a block or not. - // Even though variable statements and function declarations cannot have decorators, - // we parse them here to provide better error recovery. - if (isModifier(token) || token === SyntaxKind.AtToken) { - let result = tryParse(parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers); - if (result) { - return result; - } - } - - return parseExpressionOrLabeledStatement(); + break; } + return parseExpressionOrLabeledStatement(); } - function parseVariableStatementOrFunctionDeclarationOrClassDeclarationWithDecoratorsOrModifiers(): FunctionDeclaration | VariableStatement | ClassDeclaration { - let start = scanner.getStartPos(); + function parseDeclaration(): ModuleElement { + let fullStart = getNodePos(); let decorators = parseDecorators(); let modifiers = parseModifiers(); switch (token) { - case SyntaxKind.ConstKeyword: - let nextTokenIsEnum = lookAhead(nextTokenIsEnumKeyword) - if (nextTokenIsEnum) { - return undefined; - } - return parseVariableStatement(start, decorators, modifiers); - - case SyntaxKind.LetKeyword: - if (!isLetDeclaration()) { - return undefined; - } - return parseVariableStatement(start, decorators, modifiers); - case SyntaxKind.VarKeyword: - return parseVariableStatement(start, decorators, modifiers); - + case SyntaxKind.LetKeyword: + case SyntaxKind.ConstKeyword: + return parseVariableStatement(fullStart, decorators, modifiers); case SyntaxKind.FunctionKeyword: - return parseFunctionDeclaration(start, decorators, modifiers); - + return parseFunctionDeclaration(fullStart, decorators, modifiers); case SyntaxKind.ClassKeyword: - return parseClassDeclaration(start, decorators, modifiers); + return parseClassDeclaration(fullStart, decorators, modifiers); + case SyntaxKind.InterfaceKeyword: + return parseInterfaceDeclaration(fullStart, decorators, modifiers); + case SyntaxKind.TypeKeyword: + return parseTypeAliasDeclaration(fullStart, decorators, modifiers); + case SyntaxKind.EnumKeyword: + return parseEnumDeclaration(fullStart, decorators, modifiers); + case SyntaxKind.ModuleKeyword: + case SyntaxKind.NamespaceKeyword: + return parseModuleDeclaration(fullStart, decorators, modifiers); + case SyntaxKind.ImportKeyword: + return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); + case SyntaxKind.ExportKeyword: + nextToken(); + return token === SyntaxKind.DefaultKeyword || token === SyntaxKind.EqualsToken ? + parseExportAssignment(fullStart, decorators, modifiers) : + parseExportDeclaration(fullStart, decorators, modifiers); + default: + if (decorators) { + // We reached this point because we encountered decorators and/or modifiers and assumed a declaration + // would follow. For recovery and error reporting purposes, return an incomplete declaration. + let node = createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); + node.pos = fullStart; + node.decorators = decorators; + setModifiers(node, modifiers); + return finishNode(node); + } } - - return undefined; } function parseFunctionBlockOrSemicolon(isGenerator: boolean, diagnosticMessage?: DiagnosticMessage): Block { @@ -3836,7 +4048,7 @@ module ts { return; } - return parseFunctionBlock(isGenerator, /*ignoreMissingOpenBrace:*/ false, diagnosticMessage); + return parseFunctionBlock(isGenerator, /*ignoreMissingOpenBrace*/ false, diagnosticMessage); } // DECLARATIONS @@ -3959,7 +4171,7 @@ module ts { let node = createNode(SyntaxKind.VariableStatement, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - node.declarationList = parseVariableDeclarationList(/*inForStatementInitializer:*/ false); + node.declarationList = parseVariableDeclarationList(/*inForStatementInitializer*/ false); parseSemicolon(); return finishNode(node); } @@ -3971,7 +4183,7 @@ module ts { parseExpected(SyntaxKind.FunctionKeyword); node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken); node.name = node.flags & NodeFlags.Default ? parseOptionalIdentifier() : parseIdentifier(); - fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ !!node.asteriskToken, /*requireCompleteParameterList:*/ false, node); + fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ !!node.asteriskToken, /*requireCompleteParameterList*/ false, node); node.body = parseFunctionBlockOrSemicolon(!!node.asteriskToken, Diagnostics.or_expected); return finishNode(node); } @@ -3981,8 +4193,8 @@ module ts { node.decorators = decorators; setModifiers(node, modifiers); parseExpected(SyntaxKind.ConstructorKeyword); - fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, node); - node.body = parseFunctionBlockOrSemicolon(/*isGenerator:*/ false, Diagnostics.or_expected); + fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ false, /*requireCompleteParameterList*/ false, node); + node.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false, Diagnostics.or_expected); return finishNode(node); } @@ -3993,7 +4205,7 @@ module ts { method.asteriskToken = asteriskToken; method.name = name; method.questionToken = questionToken; - fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ !!asteriskToken, /*requireCompleteParameterList:*/ false, method); + fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ !!asteriskToken, /*requireCompleteParameterList*/ false, method); method.body = parseFunctionBlockOrSemicolon(!!asteriskToken, diagnosticMessage); return finishNode(method); } @@ -4005,7 +4217,20 @@ module ts { property.name = name; property.questionToken = questionToken; property.type = parseTypeAnnotation(); - property.initializer = allowInAnd(parseNonParameterInitializer); + + // For instance properties specifically, since they are evaluated inside the constructor, + // we do *not * want to parse yield expressions, so we specifically turn the yield context + // off. The grammar would look something like this: + // + // MemberVariableDeclaration[Yield]: + // AccessibilityModifier_opt PropertyName TypeAnnotation_opt Initialiser_opt[In]; + // AccessibilityModifier_opt static_opt PropertyName TypeAnnotation_opt Initialiser_opt[In, ?Yield]; + // + // The checker may still error in the static case to explicitly disallow the yield expression. + property.initializer = modifiers && modifiers.flags & NodeFlags.Static + ? allowInAnd(parseNonParameterInitializer) + : doOutsideOfContext(ParserContextFlags.Yield | ParserContextFlags.DisallowIn, parseNonParameterInitializer); + parseSemicolon(); return finishNode(property); } @@ -4034,8 +4259,8 @@ module ts { node.decorators = decorators; setModifiers(node, modifiers); node.name = parsePropertyName(); - fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext:*/ false, /*requireCompleteParameterList:*/ false, node); - node.body = parseFunctionBlockOrSemicolon(/*isGenerator:*/ false); + fillSignature(SyntaxKind.ColonToken, /*yieldAndGeneratorParameterContext*/ false, /*requireCompleteParameterList*/ false, node); + node.body = parseFunctionBlockOrSemicolon(/*isGenerator*/ false); return finishNode(node); } @@ -4214,9 +4439,9 @@ module ts { function parseClassExpression(): ClassExpression { return parseClassDeclarationOrExpression( - /*fullStart:*/ scanner.getStartPos(), - /*decorators:*/ undefined, - /*modifiers:*/ undefined, + /*fullStart*/ scanner.getStartPos(), + /*decorators*/ undefined, + /*modifiers*/ undefined, SyntaxKind.ClassExpression); } @@ -4235,7 +4460,7 @@ module ts { parseExpected(SyntaxKind.ClassKeyword); node.name = parseOptionalIdentifier(); node.typeParameters = parseTypeParameters(); - node.heritageClauses = parseHeritageClauses(/*isClassHeritageClause:*/ true); + node.heritageClauses = parseHeritageClauses(/*isClassHeritageClause*/ true); if (parseExpected(SyntaxKind.OpenBraceToken)) { // ClassTail[Yield,GeneratorParameter] : See 14.5 @@ -4271,7 +4496,7 @@ module ts { } function parseHeritageClausesWorker() { - return parseList(ParsingContext.HeritageClauses, /*checkForStrictMode:*/ false, parseHeritageClause); + return parseList(ParsingContext.HeritageClauses, /*checkForStrictMode*/ false, parseHeritageClause); } function parseHeritageClause() { @@ -4311,7 +4536,7 @@ module ts { parseExpected(SyntaxKind.InterfaceKeyword); node.name = parseIdentifier(); node.typeParameters = parseTypeParameters(); - node.heritageClauses = parseHeritageClauses(/*isClassHeritageClause:*/ false); + node.heritageClauses = parseHeritageClauses(/*isClassHeritageClause*/ false); node.members = parseObjectTypeMembers(); return finishNode(node); } @@ -4374,7 +4599,7 @@ module ts { node.flags |= flags; node.name = parseIdentifier(); node.body = parseOptional(SyntaxKind.DotToken) - ? parseModuleOrNamespaceDeclaration(getNodePos(), /*decorators*/ undefined, /*modifiers:*/undefined, NodeFlags.Export) + ? parseModuleOrNamespaceDeclaration(getNodePos(), /*decorators*/ undefined, /*modifiers*/ undefined, NodeFlags.Export) : parseModuleBlock(); return finishNode(node); } @@ -4383,7 +4608,7 @@ module ts { let node = createNode(SyntaxKind.ModuleDeclaration, fullStart); node.decorators = decorators; setModifiers(node, modifiers); - node.name = parseLiteralNode(/*internName:*/ true); + node.name = parseLiteralNode(/*internName*/ true); node.body = parseModuleBlock(); return finishNode(node); } @@ -4610,151 +4835,6 @@ module ts { return finishNode(node); } - function isLetDeclaration() { - // It is let declaration if in strict mode or next token is identifier\open bracket\open curly on same line. - // otherwise it needs to be treated like identifier - return inStrictModeContext() || lookAhead(nextTokenIsIdentifierOrStartOfDestructuringOnTheSameLine); - } - - function isDeclarationStart(followsModifier?: boolean): boolean { - switch (token) { - case SyntaxKind.VarKeyword: - case SyntaxKind.ConstKeyword: - case SyntaxKind.FunctionKeyword: - return true; - case SyntaxKind.LetKeyword: - return isLetDeclaration(); - case SyntaxKind.ClassKeyword: - case SyntaxKind.InterfaceKeyword: - case SyntaxKind.EnumKeyword: - case SyntaxKind.TypeKeyword: - // Not true keywords so ensure an identifier follows - return lookAhead(nextTokenIsIdentifierOrKeyword); - case SyntaxKind.ImportKeyword: - // Not true keywords so ensure an identifier follows or is string literal or asterisk or open brace - return lookAhead(nextTokenCanFollowImportKeyword); - case SyntaxKind.ModuleKeyword: - case SyntaxKind.NamespaceKeyword: - // Not a true keyword so ensure an identifier or string literal follows - return lookAhead(nextTokenIsIdentifierOrKeywordOrStringLiteral); - case SyntaxKind.ExportKeyword: - // Check for export assignment or modifier on source element - return lookAhead(nextTokenCanFollowExportKeyword); - case SyntaxKind.DeclareKeyword: - case SyntaxKind.PublicKeyword: - case SyntaxKind.PrivateKeyword: - case SyntaxKind.ProtectedKeyword: - case SyntaxKind.StaticKeyword: - // Check for modifier on source element - return lookAhead(nextTokenIsDeclarationStart); - case SyntaxKind.AtToken: - // a lookahead here is too costly, and decorators are only valid on a declaration. - // We will assume we are parsing a declaration here and report an error later - return !followsModifier; - } - } - - function isIdentifierOrKeyword() { - return token >= SyntaxKind.Identifier; - } - - function nextTokenIsIdentifierOrKeyword() { - nextToken(); - return isIdentifierOrKeyword(); - } - - function nextTokenIsIdentifierOrKeywordOrStringLiteral() { - nextToken(); - return isIdentifierOrKeyword() || token === SyntaxKind.StringLiteral; - } - - function nextTokenCanFollowImportKeyword() { - nextToken(); - return isIdentifierOrKeyword() || token === SyntaxKind.StringLiteral || - token === SyntaxKind.AsteriskToken || token === SyntaxKind.OpenBraceToken; - } - - function nextTokenCanFollowExportKeyword() { - nextToken(); - return token === SyntaxKind.EqualsToken || token === SyntaxKind.AsteriskToken || - token === SyntaxKind.OpenBraceToken || token === SyntaxKind.DefaultKeyword || isDeclarationStart(/*followsModifier*/ true); - } - - function nextTokenIsDeclarationStart() { - nextToken(); - return isDeclarationStart(/*followsModifier*/ true); - } - - function nextTokenIsAsKeyword() { - return nextToken() === SyntaxKind.AsKeyword; - } - - function parseDeclaration(): ModuleElement { - let fullStart = getNodePos(); - let decorators = parseDecorators(); - let modifiers = parseModifiers(); - if (token === SyntaxKind.ExportKeyword) { - nextToken(); - if (token === SyntaxKind.DefaultKeyword || token === SyntaxKind.EqualsToken) { - return parseExportAssignment(fullStart, decorators, modifiers); - } - if (token === SyntaxKind.AsteriskToken || token === SyntaxKind.OpenBraceToken) { - return parseExportDeclaration(fullStart, decorators, modifiers); - } - } - - switch (token) { - case SyntaxKind.VarKeyword: - case SyntaxKind.LetKeyword: - case SyntaxKind.ConstKeyword: - return parseVariableStatement(fullStart, decorators, modifiers); - case SyntaxKind.FunctionKeyword: - return parseFunctionDeclaration(fullStart, decorators, modifiers); - case SyntaxKind.ClassKeyword: - return parseClassDeclaration(fullStart, decorators, modifiers); - case SyntaxKind.InterfaceKeyword: - return parseInterfaceDeclaration(fullStart, decorators, modifiers); - case SyntaxKind.TypeKeyword: - return parseTypeAliasDeclaration(fullStart, decorators, modifiers); - case SyntaxKind.EnumKeyword: - return parseEnumDeclaration(fullStart, decorators, modifiers); - case SyntaxKind.ModuleKeyword: - case SyntaxKind.NamespaceKeyword: - return parseModuleDeclaration(fullStart, decorators, modifiers); - case SyntaxKind.ImportKeyword: - return parseImportDeclarationOrImportEqualsDeclaration(fullStart, decorators, modifiers); - default: - if (decorators) { - // We reached this point because we encountered an AtToken and assumed a declaration would - // follow. For recovery and error reporting purposes, return an incomplete declaration. - let node = createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected); - node.pos = fullStart; - node.decorators = decorators; - setModifiers(node, modifiers); - return finishNode(node); - } - Debug.fail("Mismatch between isDeclarationStart and parseDeclaration"); - } - } - - function isSourceElement(inErrorRecovery: boolean): boolean { - return isDeclarationStart() || isStartOfStatement(inErrorRecovery); - } - - function parseSourceElement() { - return parseSourceElementOrModuleElement(); - } - - function parseModuleElement() { - return parseSourceElementOrModuleElement(); - } - - function parseSourceElementOrModuleElement(): ModuleElement { - return isDeclarationStart() - ? parseDeclaration() - : parseStatement(); - } - function processReferenceComments(sourceFile: SourceFile): void { let triviaScanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/false, sourceText); let referencedFiles: FileReference[] = []; @@ -4785,7 +4865,7 @@ module ts { referencedFiles.push(fileReference); } if (diagnosticMessage) { - sourceFile.parseDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage)); + parseDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, diagnosticMessage)); } } else { @@ -4793,7 +4873,7 @@ module ts { let amdModuleNameMatchResult = amdModuleNameRegEx.exec(comment); if (amdModuleNameMatchResult) { if (amdModuleName) { - sourceFile.parseDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments)); + parseDiagnostics.push(createFileDiagnostic(sourceFile, range.pos, range.end - range.pos, Diagnostics.An_AMD_module_cannot_have_multiple_name_assignments)); } amdModuleName = amdModuleNameMatchResult[2]; } @@ -4851,6 +4931,10 @@ module ts { TupleElementTypes, // Element types in tuple element type list HeritageClauses, // Heritage clauses for a class or interface declaration. ImportOrExportSpecifiers, // Named import clause's import specifier list + JSDocFunctionParameters, + JSDocTypeArguments, + JSDocRecordMembers, + JSDocTupleTypes, Count // Number of parsing contexts } @@ -4859,6 +4943,652 @@ module ts { True, Unknown } + + export module JSDocParser { + export function isJSDocType() { + switch (token) { + case SyntaxKind.AsteriskToken: + case SyntaxKind.QuestionToken: + case SyntaxKind.OpenParenToken: + case SyntaxKind.OpenBracketToken: + case SyntaxKind.ExclamationToken: + case SyntaxKind.OpenBraceToken: + case SyntaxKind.FunctionKeyword: + case SyntaxKind.DotDotDotToken: + case SyntaxKind.NewKeyword: + case SyntaxKind.ThisKeyword: + return true; + } + + return isIdentifierOrKeyword(); + } + + export function parseJSDocTypeExpressionForTests(content: string, start: number, length: number) { + initializeState("file.js", content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined); + let jsDocTypeExpression = parseJSDocTypeExpression(start, length); + let diagnostics = parseDiagnostics; + clearState(); + + return jsDocTypeExpression ? { jsDocTypeExpression, diagnostics } : undefined; + } + + // Parses out a JSDoc type expression. The starting position should be right at the open + // curly in the type expression. Returns 'undefined' if it encounters any errors while parsing. + /* @internal */ + export function parseJSDocTypeExpression(start: number, length: number): JSDocTypeExpression { + scanner.setText(sourceText, start, length); + + // Prime the first token for us to start processing. + token = nextToken(); + + let result = createNode(SyntaxKind.JSDocTypeExpression); + + parseExpected(SyntaxKind.OpenBraceToken); + result.type = parseJSDocTopLevelType(); + parseExpected(SyntaxKind.CloseBraceToken); + + fixupParentReferences(result); + return finishNode(result); + } + + function parseJSDocTopLevelType(): JSDocType { + var type = parseJSDocType(); + if (token === SyntaxKind.BarToken) { + var unionType = createNode(SyntaxKind.JSDocUnionType, type.pos); + unionType.types = parseJSDocTypeList(type); + type = finishNode(unionType); + } + + if (token === SyntaxKind.EqualsToken) { + var optionalType = createNode(SyntaxKind.JSDocOptionalType, type.pos); + nextToken(); + optionalType.type = type; + type = finishNode(optionalType); + } + + return type; + } + + function parseJSDocType(): JSDocType { + let type = parseBasicTypeExpression(); + + while (true) { + if (token === SyntaxKind.OpenBracketToken) { + let arrayType = createNode(SyntaxKind.JSDocArrayType, type.pos); + arrayType.elementType = type; + + nextToken(); + parseExpected(SyntaxKind.CloseBracketToken); + + type = finishNode(arrayType); + } + else if (token === SyntaxKind.QuestionToken) { + let nullableType = createNode(SyntaxKind.JSDocNullableType, type.pos); + nullableType.type = type; + + nextToken(); + type = finishNode(nullableType); + } + else if (token === SyntaxKind.ExclamationToken) { + let nonNullableType = createNode(SyntaxKind.JSDocNonNullableType, type.pos); + nonNullableType.type = type; + + nextToken(); + type = finishNode(nonNullableType); + } + else { + break; + } + } + + return type; + } + + function parseBasicTypeExpression(): JSDocType { + switch (token) { + case SyntaxKind.AsteriskToken: + return parseJSDocAllType(); + case SyntaxKind.QuestionToken: + return parseJSDocUnknownOrNullableType(); + case SyntaxKind.OpenParenToken: + return parseJSDocUnionType(); + case SyntaxKind.OpenBracketToken: + return parseJSDocTupleType(); + case SyntaxKind.ExclamationToken: + return parseJSDocNonNullableType(); + case SyntaxKind.OpenBraceToken: + return parseJSDocRecordType(); + case SyntaxKind.FunctionKeyword: + return parseJSDocFunctionType(); + case SyntaxKind.DotDotDotToken: + return parseJSDocVariadicType(); + case SyntaxKind.NewKeyword: + return parseJSDocConstructorType(); + case SyntaxKind.ThisKeyword: + return parseJSDocThisType(); + case SyntaxKind.AnyKeyword: + case SyntaxKind.StringKeyword: + case SyntaxKind.NumberKeyword: + case SyntaxKind.BooleanKeyword: + case SyntaxKind.SymbolKeyword: + case SyntaxKind.VoidKeyword: + return parseTokenNode(); + } + + return parseJSDocTypeReference(); + } + + function parseJSDocThisType(): JSDocThisType { + let result = createNode(SyntaxKind.JSDocThisType); + nextToken(); + parseExpected(SyntaxKind.ColonToken); + result.type = parseJSDocType(); + return finishNode(result); + } + + function parseJSDocConstructorType(): JSDocConstructorType { + let result = createNode(SyntaxKind.JSDocConstructorType); + nextToken(); + parseExpected(SyntaxKind.ColonToken); + result.type = parseJSDocType(); + return finishNode(result); + } + + function parseJSDocVariadicType(): JSDocVariadicType { + let result = createNode(SyntaxKind.JSDocVariadicType); + nextToken(); + result.type = parseJSDocType(); + return finishNode(result); + } + + function parseJSDocFunctionType(): JSDocFunctionType { + let result = createNode(SyntaxKind.JSDocFunctionType); + nextToken(); + + parseExpected(SyntaxKind.OpenParenToken); + result.parameters = parseDelimitedList(ParsingContext.JSDocFunctionParameters, parseJSDocParameter); + checkForTrailingComma(result.parameters); + parseExpected(SyntaxKind.CloseParenToken); + + if (token === SyntaxKind.ColonToken) { + nextToken(); + result.type = parseJSDocType(); + } + + return finishNode(result); + } + + function parseJSDocParameter(): ParameterDeclaration { + let parameter = createNode(SyntaxKind.Parameter); + parameter.type = parseJSDocType(); + return finishNode(parameter); + } + + function parseJSDocOptionalType(type: JSDocType): JSDocOptionalType { + let result = createNode(SyntaxKind.JSDocOptionalType, type.pos); + nextToken(); + result.type = type; + return finishNode(result); + } + + function parseJSDocTypeReference(): JSDocTypeReference { + let result = createNode(SyntaxKind.JSDocTypeReference); + result.name = parseSimplePropertyName(); + + while (parseOptional(SyntaxKind.DotToken)) { + if (token === SyntaxKind.LessThanToken) { + result.typeArguments = parseTypeArguments(); + break; + } + else { + result.name = parseQualifiedName(result.name); + } + } + + return finishNode(result); + } + + function parseTypeArguments() { + // Move past the < + nextToken(); + let typeArguments = parseDelimitedList(ParsingContext.JSDocTypeArguments, parseJSDocType); + checkForTrailingComma(typeArguments); + checkForEmptyTypeArgumentList(typeArguments); + parseExpected(SyntaxKind.GreaterThanToken); + + return typeArguments; + } + + function checkForEmptyTypeArgumentList(typeArguments: NodeArray) { + if (parseDiagnostics.length === 0 && typeArguments && typeArguments.length === 0) { + let start = typeArguments.pos - "<".length; + let end = skipTrivia(sourceText, typeArguments.end) + ">".length; + return parseErrorAtPosition(start, end - start, Diagnostics.Type_argument_list_cannot_be_empty); + } + } + + function parseQualifiedName(left: EntityName): QualifiedName { + let result = createNode(SyntaxKind.QualifiedName, left.pos); + result.left = left; + result.right = parseIdentifierName(); + + return finishNode(result); + } + + function parseJSDocRecordType(): JSDocRecordType { + let result = createNode(SyntaxKind.JSDocRecordType); + nextToken(); + result.members = parseDelimitedList(ParsingContext.JSDocRecordMembers, parseJSDocRecordMember); + checkForTrailingComma(result.members); + parseExpected(SyntaxKind.CloseBraceToken); + return finishNode(result); + } + + function parseJSDocRecordMember(): JSDocRecordMember { + let result = createNode(SyntaxKind.JSDocRecordMember); + result.name = parseSimplePropertyName(); + + if (token === SyntaxKind.ColonToken) { + nextToken(); + result.type = parseJSDocType(); + } + + return finishNode(result); + } + + function parseJSDocNonNullableType(): JSDocNonNullableType { + let result = createNode(SyntaxKind.JSDocNonNullableType); + nextToken(); + result.type = parseJSDocType(); + return finishNode(result); + } + + function parseJSDocTupleType(): JSDocTupleType { + let result = createNode(SyntaxKind.JSDocTupleType); + nextToken(); + result.types = parseDelimitedList(ParsingContext.JSDocTupleTypes, parseJSDocType); + checkForTrailingComma(result.types); + parseExpected(SyntaxKind.CloseBracketToken); + + return finishNode(result); + } + + function checkForTrailingComma(list: NodeArray) { + if (parseDiagnostics.length === 0 && list.hasTrailingComma) { + let start = list.end - ",".length; + parseErrorAtPosition(start, ",".length, Diagnostics.Trailing_comma_not_allowed); + } + } + + function parseJSDocUnionType(): JSDocUnionType { + let result = createNode(SyntaxKind.JSDocUnionType); + nextToken(); + result.types = parseJSDocTypeList(parseJSDocType()); + + parseExpected(SyntaxKind.CloseParenToken); + + return finishNode(result); + } + + function parseJSDocTypeList(firstType: JSDocType) { + Debug.assert(!!firstType); + + let types = >[]; + types.pos = firstType.pos; + + types.push(firstType); + while (parseOptional(SyntaxKind.BarToken)) { + types.push(parseJSDocType()); + } + + types.end = scanner.getStartPos(); + return types; + } + + function parseJSDocAllType(): JSDocAllType { + let result = createNode(SyntaxKind.JSDocAllType); + nextToken(); + return finishNode(result); + } + + function parseJSDocUnknownOrNullableType(): JSDocUnknownType | JSDocNullableType { + let pos = scanner.getStartPos(); + // skip the ? + nextToken(); + + // Need to lookahead to decide if this is a nullable or unknown type. + + // Here are cases where we'll pick the unknown type: + // + // Foo(?, + // { a: ? } + // Foo(?) + // Foo + // Foo(?= + // (?| + if (token === SyntaxKind.CommaToken || + token === SyntaxKind.CloseBraceToken || + token === SyntaxKind.CloseParenToken || + token === SyntaxKind.GreaterThanToken || + token === SyntaxKind.EqualsToken || + token === SyntaxKind.BarToken) { + + let result = createNode(SyntaxKind.JSDocUnknownType, pos); + return finishNode(result); + } + else { + let result = createNode(SyntaxKind.JSDocNullableType, pos); + result.type = parseJSDocType(); + return finishNode(result); + } + } + + export function parseIsolatedJSDocComment(content: string, start: number, length: number) { + initializeState("file.js", content, ScriptTarget.Latest, /*_syntaxCursor:*/ undefined); + let jsDocComment = parseJSDocComment(/*parent:*/ undefined, start, length); + let diagnostics = parseDiagnostics; + clearState(); + + return jsDocComment ? { jsDocComment, diagnostics } : undefined; + } + + export function parseJSDocComment(parent: Node, start: number, length: number): JSDocComment { + let comment = parseJSDocCommentWorker(start, length); + if (comment) { + fixupParentReferences(comment); + comment.parent = parent; + } + + return comment; + } + + export function parseJSDocCommentWorker(start: number, length: number): JSDocComment { + let content = sourceText; + start = start || 0; + let end = length === undefined ? content.length : start + length; + length = end - start; + + Debug.assert(start >= 0); + Debug.assert(start <= end); + Debug.assert(end <= content.length); + + let tags: NodeArray; + let pos: number; + + // NOTE(cyrusn): This is essentially a handwritten scanner for JSDocComments. I + // considered using an actual Scanner, but this would complicate things. The + // scanner would need to know it was in a Doc Comment. Otherwise, it would then + // produce comments *inside* the doc comment. In the end it was just easier to + // write a simple scanner rather than go that route. + if (length >= "/** */".length) { + if (content.charCodeAt(start) === CharacterCodes.slash && + content.charCodeAt(start + 1) === CharacterCodes.asterisk && + content.charCodeAt(start + 2) === CharacterCodes.asterisk && + content.charCodeAt(start + 3) !== CharacterCodes.asterisk) { + + // Initially we can parse out a tag. We also have seen a starting asterisk. + // This is so that /** * @type */ doesn't parse. + let canParseTag = true; + let seenAsterisk = true; + + for (pos = start + "/**".length; pos < end;) { + let ch = content.charCodeAt(pos); + pos++; + + if (ch === CharacterCodes.at && canParseTag) { + parseTag(); + + // Once we parse out a tag, we cannot keep parsing out tags on this line. + canParseTag = false; + continue; + } + + if (isLineBreak(ch)) { + // After a line break, we can parse a tag, and we haven't seen as asterisk + // on the next line yet. + canParseTag = true; + seenAsterisk = false; + continue; + } + + if (isWhiteSpace(ch)) { + // Whitespace doesn't affect any of our parsing. + continue; + } + + // Ignore the first asterisk on a line. + if (ch === CharacterCodes.asterisk) { + if (seenAsterisk) { + // If we've already seen an asterisk, then we can no longer parse a tag + // on this line. + canParseTag = false; + } + seenAsterisk = true; + continue; + } + + // Anything else is doc comment text. We can't do anything with it. Because it + // wasn't a tag, we can no longer parse a tag on this line until we hit the next + // line break. + canParseTag = false; + } + } + } + + return createJSDocComment(); + + function createJSDocComment(): JSDocComment { + if (!tags) { + return undefined; + } + + let result = createNode(SyntaxKind.JSDocComment, start); + result.tags = tags; + return finishNode(result, end); + } + + function skipWhitespace(): void { + while (pos < end && isWhiteSpace(content.charCodeAt(pos))) { + pos++; + } + } + + function parseTag(): void { + Debug.assert(content.charCodeAt(pos - 1) === CharacterCodes.at); + let atToken = createNode(SyntaxKind.AtToken, pos - 1); + atToken.end = pos; + + let startPos = pos; + let tagName = scanIdentifier(); + if (!tagName) { + return; + } + + let tag = handleTag(atToken, tagName) || handleUnknownTag(atToken, tagName); + addTag(tag); + } + + function handleTag(atToken: Node, tagName: Identifier): JSDocTag { + if (tagName) { + switch (tagName.text) { + case "param": + return handleParamTag(atToken, tagName); + case "return": + case "returns": + return handleReturnTag(atToken, tagName); + case "template": + return handleTemplateTag(atToken, tagName); + case "type": + return handleTypeTag(atToken, tagName); + } + } + + return undefined; + } + + function handleUnknownTag(atToken: Node, tagName: Identifier) { + let result = createNode(SyntaxKind.JSDocTag, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + return finishNode(result, pos); + } + + function addTag(tag: JSDocTag): void { + if (tag) { + if (!tags) { + tags = >[]; + tags.pos = tag.pos; + } + + tags.push(tag); + tags.end = tag.end; + } + } + + function tryParseTypeExpression(): JSDocTypeExpression { + skipWhitespace(); + + if (content.charCodeAt(pos) !== CharacterCodes.openBrace) { + return undefined; + } + + let typeExpression = parseJSDocTypeExpression(pos, end - pos); + pos = typeExpression.end; + return typeExpression; + } + + function handleParamTag(atToken: Node, tagName: Identifier) { + let typeExpression = tryParseTypeExpression(); + + skipWhitespace(); + let name: Identifier; + let isBracketed: boolean; + if (content.charCodeAt(pos) === CharacterCodes.openBracket) { + pos++; + skipWhitespace(); + name = scanIdentifier(); + isBracketed = true; + } + else { + name = scanIdentifier(); + } + + if (!name) { + parseErrorAtPosition(pos, 0, Diagnostics.Identifier_expected); + return undefined; + } + + let preName: Identifier, postName: Identifier; + if (typeExpression) { + postName = name; + } + else { + preName = name; + } + + if (!typeExpression) { + typeExpression = tryParseTypeExpression(); + } + + let result = createNode(SyntaxKind.JSDocParameterTag, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.preParameterName = preName; + result.typeExpression = typeExpression; + result.postParameterName = postName; + result.isBracketed = isBracketed; + return finishNode(result, pos); + } + + function handleReturnTag(atToken: Node, tagName: Identifier): JSDocReturnTag { + if (forEach(tags, t => t.kind === SyntaxKind.JSDocReturnTag)) { + parseErrorAtPosition(tagName.pos, pos - tagName.pos, Diagnostics._0_tag_already_specified, tagName.text); + } + + let result = createNode(SyntaxKind.JSDocReturnTag, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.typeExpression = tryParseTypeExpression(); + return finishNode(result, pos); + } + + function handleTypeTag(atToken: Node, tagName: Identifier): JSDocTypeTag { + if (forEach(tags, t => t.kind === SyntaxKind.JSDocTypeTag)) { + parseErrorAtPosition(tagName.pos, pos - tagName.pos, Diagnostics._0_tag_already_specified, tagName.text); + } + + let result = createNode(SyntaxKind.JSDocTypeTag, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.typeExpression = tryParseTypeExpression(); + return finishNode(result, pos); + } + + function handleTemplateTag(atToken: Node, tagName: Identifier): JSDocTemplateTag { + if (forEach(tags, t => t.kind === SyntaxKind.JSDocTemplateTag)) { + parseErrorAtPosition(tagName.pos, pos - tagName.pos, Diagnostics._0_tag_already_specified, tagName.text); + } + + let typeParameters = >[]; + typeParameters.pos = pos; + + while (true) { + skipWhitespace(); + + let startPos = pos; + let name = scanIdentifier(); + if (!name) { + parseErrorAtPosition(startPos, 0, Diagnostics.Identifier_expected); + return undefined; + } + + let typeParameter = createNode(SyntaxKind.TypeParameter, name.pos); + typeParameter.name = name; + finishNode(typeParameter, pos); + + typeParameters.push(typeParameter); + + skipWhitespace(); + if (content.charCodeAt(pos) !== CharacterCodes.comma) { + break; + } + + pos++; + } + + typeParameters.end = pos; + + let result = createNode(SyntaxKind.JSDocTemplateTag, atToken.pos); + result.atToken = atToken; + result.tagName = tagName; + result.typeParameters = typeParameters; + return finishNode(result, pos); + } + + function scanIdentifier(): Identifier { + let startPos = pos; + for (; pos < end; pos++) { + let ch = content.charCodeAt(pos); + if (pos === startPos && isIdentifierStart(ch, ScriptTarget.Latest)) { + continue; + } + else if (pos > startPos && isIdentifierPart(ch, ScriptTarget.Latest)) { + continue; + } + + break; + } + + if (startPos === pos) { + return undefined; + } + + let result = createNode(SyntaxKind.Identifier, startPos); + result.text = content.substring(startPos, pos); + return finishNode(result, pos); + } + } + } } module IncrementalParser { @@ -4959,7 +5689,14 @@ module ts { // Ditch any existing LS children we may have created. This way we can avoid // moving them forward. - node._children = undefined; + if (node._children) { + node._children = undefined; + } + + if (node.jsDocComment) { + node.jsDocComment = undefined; + } + node.pos += delta; node.end += delta; @@ -5097,7 +5834,7 @@ module ts { if (child.pos > changeRangeOldEnd) { // Node is entirely past the change range. We need to move both its pos and // end, forward or backward appropriately. - moveElementEntirelyPastChangeRange(child, /*isArray:*/ false, delta, oldText, newText, aggressiveChecks); + moveElementEntirelyPastChangeRange(child, /*isArray*/ false, delta, oldText, newText, aggressiveChecks); return; } @@ -5126,7 +5863,7 @@ module ts { if (array.pos > changeRangeOldEnd) { // Array is entirely after the change range. We need to move it, and move any of // its children. - moveElementEntirelyPastChangeRange(array, /*isArray:*/ true, delta, oldText, newText, aggressiveChecks); + moveElementEntirelyPastChangeRange(array, /*isArray*/ true, delta, oldText, newText, aggressiveChecks); return; } diff --git a/src/compiler/program.ts b/src/compiler/program.ts index 38634f1dea..955e24fd1d 100644 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -8,7 +8,7 @@ module ts { /* @internal */ export let ioWriteTime = 0; /** The version of the TypeScript compiler release */ - export const version = "1.5.2"; + export const version = "1.5.3"; const carriageReturnLineFeed = "\r\n"; const lineFeed = "\n"; @@ -534,21 +534,21 @@ module ts { } function verifyCompilerOptions() { - if (options.separateCompilation) { + if (options.isolatedModules) { if (options.sourceMap) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceMap_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_sourceMap_cannot_be_specified_with_option_isolatedModules)); } if (options.declaration) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_declaration_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_declaration_cannot_be_specified_with_option_isolatedModules)); } if (options.noEmitOnError) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmitOnError_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmitOnError_cannot_be_specified_with_option_isolatedModules)); } if (options.out) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_out_cannot_be_specified_with_option_separateCompilation)); + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_out_cannot_be_specified_with_option_isolatedModules)); } } @@ -585,15 +585,15 @@ module ts { let languageVersion = options.target || ScriptTarget.ES3; let firstExternalModuleSourceFile = forEach(files, f => isExternalModule(f) ? f : undefined); - if (options.separateCompilation) { + if (options.isolatedModules) { if (!options.module && languageVersion < ScriptTarget.ES6) { - diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_separateCompilation_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_isolatedModules_can_only_be_used_when_either_option_module_is_provided_or_option_target_is_ES6_or_higher)); } let firstNonExternalModuleSourceFile = forEach(files, f => !isExternalModule(f) && !isDeclarationFile(f) ? f : undefined); if (firstNonExternalModuleSourceFile) { let span = getErrorSpanForNode(firstNonExternalModuleSourceFile, firstNonExternalModuleSourceFile); - diagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_separateCompilation_flag_is_provided)); + diagnostics.add(createFileDiagnostic(firstNonExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_namespaces_when_the_isolatedModules_flag_is_provided)); } } else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && !options.module) { @@ -640,6 +640,11 @@ module ts { diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration)); } } + + if (options.emitDecoratorMetadata && + !options.experimentalDecorators) { + diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified)); + } } } } \ No newline at end of file diff --git a/src/compiler/scanner.ts b/src/compiler/scanner.ts index 1fc8bff92e..89ac837ab2 100644 --- a/src/compiler/scanner.ts +++ b/src/compiler/scanner.ts @@ -598,12 +598,26 @@ module ts { ch > CharacterCodes.maxAsciiCharacter && isUnicodeIdentifierPart(ch, languageVersion); } - /** Creates a scanner over a (possibly unspecified) range of a piece of text. */ - export function createScanner(languageVersion: ScriptTarget, skipTrivia: boolean, text?: string, onError?: ErrorCallback, start?: number, length?: number): Scanner { - let pos: number; // Current position (end position of text of current token) - let end: number; // end of text - let startPos: number; // Start position of whitespace before current token - let tokenPos: number; // Start position of text of current token + /* @internal */ + // Creates a scanner over a (possibly unspecified) range of a piece of text. + export function createScanner(languageVersion: ScriptTarget, + skipTrivia: boolean, + text?: string, + onError?: ErrorCallback, + start?: number, + length?: number): Scanner { + // Current position (end position of text of current token) + let pos: number; + + // end of text + let end: number; + + // Start position of whitespace before current token + let startPos: number; + + // Start position of text of current token + let tokenPos: number; + let token: SyntaxKind; let tokenValue: string; let precedingLineBreak: boolean; diff --git a/src/compiler/sys.ts b/src/compiler/sys.ts index 8f246540c6..75e8af357b 100644 --- a/src/compiler/sys.ts +++ b/src/compiler/sys.ts @@ -246,7 +246,7 @@ module ts { for (let current of files) { var name = combinePaths(path, current); if (!contains(exclude, getCanonicalPath(name))) { - var stat = _fs.lstatSync(name); + var stat = _fs.statSync(name); if (stat.isFile()) { if (!extension || fileExtensionIs(name, extension)) { result.push(name); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 831cc26eed..304468bb28 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -270,6 +270,32 @@ module ts { // Top-level nodes SourceFile, + // JSDoc nodes. + JSDocTypeExpression, + // The * type. + JSDocAllType, + // The ? type. + JSDocUnknownType, + JSDocArrayType, + JSDocUnionType, + JSDocTupleType, + JSDocNullableType, + JSDocNonNullableType, + JSDocRecordType, + JSDocRecordMember, + JSDocTypeReference, + JSDocOptionalType, + JSDocFunctionType, + JSDocVariadicType, + JSDocConstructorType, + JSDocThisType, + JSDocComment, + JSDocTag, + JSDocParameterTag, + JSDocReturnTag, + JSDocTypeTag, + JSDocTemplateTag, + // Synthesized list SyntaxList, // Enum value count @@ -324,6 +350,8 @@ module ts { /* @internal */ export const enum ParserContextFlags { + None = 0, + // Set if this node was parsed in strict mode. Used for grammar error checks, as well as // checking if the node can be reused in incremental settings. StrictMode = 1 << 0, @@ -345,6 +373,10 @@ module ts { // error. ThisNodeHasError = 1 << 5, + // This node was parsed in a JavaScript file and can be processed differently. For example + // its type can be specified usign a JSDoc comment. + JavaScriptFile = 1 << 6, + // Context flags set directly by the parser. ParserGeneratedFlags = StrictMode | DisallowIn | Yield | GeneratorParameter | Decorator | ThisNodeHasError, @@ -352,10 +384,10 @@ module ts { // Used during incremental parsing to determine if this node or any of its children had an // error. Computed only once and then cached. - ThisNodeOrAnySubNodesHasError = 1 << 6, + ThisNodeOrAnySubNodesHasError = 1 << 7, // Used to know if we've computed data from children and cached it in this node. - HasAggregatedChildData = 1 << 7 + HasAggregatedChildData = 1 << 8 } /* @internal */ @@ -371,14 +403,15 @@ module ts { // Specific context the parser was in when this node was created. Normally undefined. // Only set when the parser was in some interesting context (like async/yield). /* @internal */ parserContextFlags?: ParserContextFlags; - decorators?: NodeArray; // Array of decorators (in document order) - modifiers?: ModifiersArray; // Array of modifiers - /* @internal */ id?: number; // Unique id (used to look up NodeLinks) - parent?: Node; // Parent node (initialized by binding) - /* @internal */ symbol?: Symbol; // Symbol declared by node (initialized by binding) - /* @internal */ locals?: SymbolTable; // Locals associated with node (initialized by binding) - /* @internal */ nextContainer?: Node; // Next container in declaration order (initialized by binding) - /* @internal */ localSymbol?: Symbol; // Local symbol declared by node (initialized by binding only for exported nodes) + decorators?: NodeArray; // Array of decorators (in document order) + modifiers?: ModifiersArray; // Array of modifiers + /* @internal */ id?: number; // Unique id (used to look up NodeLinks) + parent?: Node; // Parent node (initialized by binding + /* @internal */ jsDocComment?: JSDocComment; // JSDoc for the node, if it has any. Only for .js files. + /* @internal */ symbol?: Symbol; // Symbol declared by node (initialized by binding) + /* @internal */ locals?: SymbolTable; // Locals associated with node (initialized by binding) + /* @internal */ nextContainer?: Node; // Next container in declaration order (initialized by binding) + /* @internal */ localSymbol?: Symbol; // Local symbol declared by node (initialized by binding only for exported nodes) } export interface NodeArray extends Array, TextRange { @@ -660,7 +693,7 @@ module ts { export interface YieldExpression extends Expression { asteriskToken?: Node; - expression: Expression; + expression?: Expression; } export interface BinaryExpression extends Expression { @@ -884,7 +917,7 @@ module ts { _classElementBrand: any; } - export interface InterfaceDeclaration extends Declaration, ModuleElement { + export interface InterfaceDeclaration extends Declaration, Statement { name: Identifier; typeParameters?: NodeArray; heritageClauses?: NodeArray; @@ -896,7 +929,7 @@ module ts { types?: NodeArray; } - export interface TypeAliasDeclaration extends Declaration, ModuleElement { + export interface TypeAliasDeclaration extends Declaration, Statement { name: Identifier; type: TypeNode; } @@ -908,7 +941,7 @@ module ts { initializer?: Expression; } - export interface EnumDeclaration extends Declaration, ModuleElement { + export interface EnumDeclaration extends Declaration, Statement { name: Identifier; members: NodeArray; } @@ -992,6 +1025,106 @@ module ts { kind: SyntaxKind; } + // represents a top level: { type } expression in a JSDoc comment. + export interface JSDocTypeExpression extends Node { + type: JSDocType; + } + + export interface JSDocType extends TypeNode { + _jsDocTypeBrand: any; + } + + export interface JSDocAllType extends JSDocType { + _JSDocAllTypeBrand: any; + } + + export interface JSDocUnknownType extends JSDocType { + _JSDocUnknownTypeBrand: any; + } + + export interface JSDocArrayType extends JSDocType { + elementType: JSDocType; + } + + export interface JSDocUnionType extends JSDocType { + types: NodeArray; + } + + export interface JSDocTupleType extends JSDocType { + types: NodeArray; + } + + export interface JSDocNonNullableType extends JSDocType { + type: JSDocType; + } + + export interface JSDocNullableType extends JSDocType { + type: JSDocType; + } + + export interface JSDocRecordType extends JSDocType, TypeLiteralNode { + members: NodeArray; + } + + export interface JSDocTypeReference extends JSDocType { + name: EntityName; + typeArguments: NodeArray + } + + export interface JSDocOptionalType extends JSDocType { + type: JSDocType; + } + + export interface JSDocFunctionType extends JSDocType, SignatureDeclaration { + parameters: NodeArray; + type: JSDocType; + } + + export interface JSDocVariadicType extends JSDocType { + type: JSDocType; + } + + export interface JSDocConstructorType extends JSDocType { + type: JSDocType; + } + + export interface JSDocThisType extends JSDocType { + type: JSDocType; + } + + export interface JSDocRecordMember extends PropertyDeclaration { + name: Identifier | LiteralExpression, + type?: JSDocType + } + + export interface JSDocComment extends Node { + tags: NodeArray; + } + + export interface JSDocTag extends Node { + atToken: Node; + tagName: Identifier; + } + + export interface JSDocTemplateTag extends JSDocTag { + typeParameters: NodeArray; + } + + export interface JSDocReturnTag extends JSDocTag { + typeExpression: JSDocTypeExpression; + } + + export interface JSDocTypeTag extends JSDocTag { + typeExpression: JSDocTypeExpression; + } + + export interface JSDocParameterTag extends JSDocTag { + preParameterName?: Identifier; + typeExpression?: JSDocTypeExpression; + postParameterName?: Identifier; + isBracketed: boolean; + } + // Source files are declarations when they are external modules. export interface SourceFile extends Declaration { statements: NodeArray; @@ -1287,6 +1420,7 @@ module ts { } export const enum SymbolFlags { + None = 0, FunctionScopedVariable = 0x00000001, // Variable (var) or parameter BlockScopedVariable = 0x00000002, // A block-scoped variable (let or const) Property = 0x00000004, // Property or enum member @@ -1356,11 +1490,9 @@ module ts { ExportHasLocal = Function | Class | Enum | ValueModule, - HasLocals = Function | Module | Method | Constructor | Accessor | Signature, HasExports = Class | Enum | Module, HasMembers = Class | Interface | TypeLiteral | ObjectLiteral, - IsContainer = HasLocals | HasExports | HasMembers, PropertyOrAccessor = Property | Accessor, Export = ExportNamespace | ExportType | ExportValue, } @@ -1368,14 +1500,15 @@ module ts { export interface Symbol { flags: SymbolFlags; // Symbol flags name: string; // Name of symbol - /* @internal */ id?: number; // Unique id (used to look up SymbolLinks) - /* @internal */ mergeId?: number; // Merge id (used to look up merged symbol) declarations?: Declaration[]; // Declarations associated with this symbol - /* @internal */ parent?: Symbol; // Parent symbol + valueDeclaration?: Declaration; // First value declaration of the symbol + members?: SymbolTable; // Class, interface or literal instance members exports?: SymbolTable; // Module exports + /* @internal */ id?: number; // Unique id (used to look up SymbolLinks) + /* @internal */ mergeId?: number; // Merge id (used to look up merged symbol) + /* @internal */ parent?: Symbol; // Parent symbol /* @internal */ exportSymbol?: Symbol; // Exported symbol associated with this symbol - valueDeclaration?: Declaration; // First value declaration of the symbol /* @internal */ constEnumOnlyModule?: boolean; // True if module contains only const enums or other modules with only const enums } @@ -1449,14 +1582,15 @@ module ts { Tuple = 0x00002000, // Tuple Union = 0x00004000, // Union Anonymous = 0x00008000, // Anonymous + Instantiated = 0x00010000, // Instantiated anonymous type /* @internal */ - FromSignature = 0x00010000, // Created for signature assignment check - ObjectLiteral = 0x00020000, // Originates in an object literal + FromSignature = 0x00020000, // Created for signature assignment check + ObjectLiteral = 0x00040000, // Originates in an object literal /* @internal */ - ContainsUndefinedOrNull = 0x00040000, // Type is or contains Undefined or Null type + ContainsUndefinedOrNull = 0x00080000, // Type is or contains Undefined or Null type /* @internal */ - ContainsObjectLiteral = 0x00080000, // Type is or contains object literal type - ESSymbol = 0x00100000, // Type of symbol primitive introduced in ES6 + ContainsObjectLiteral = 0x00100000, // Type is or contains object literal type + ESSymbol = 0x00200000, // Type of symbol primitive introduced in ES6 /* @internal */ Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null, @@ -1493,6 +1627,8 @@ module ts { // Class and interface types (TypeFlags.Class and TypeFlags.Interface) export interface InterfaceType extends ObjectType { typeParameters: TypeParameter[]; // Type parameters (undefined if non-generic) + outerTypeParameters: TypeParameter[]; // Outer type parameters (undefined if none) + localTypeParameters: TypeParameter[]; // Local type parameters (undefined if none) } export interface InterfaceTypeWithBaseTypes extends InterfaceType { @@ -1539,8 +1675,15 @@ module ts { properties: Symbol[]; // Properties callSignatures: Signature[]; // Call signatures of type constructSignatures: Signature[]; // Construct signatures of type - stringIndexType: Type; // String index type - numberIndexType: Type; // Numeric index type + stringIndexType?: Type; // String index type + numberIndexType?: Type; // Numeric index type + } + + // Just a place to cache element types of iterables and iterators + /* @internal */ + export interface IterableOrIteratorType extends ObjectType, UnionType { + iterableElementType?: Type; + iteratorElementType?: Type; } // Type parameters (TypeFlags.TypeParameter) @@ -1676,7 +1819,8 @@ module ts { target?: ScriptTarget; version?: boolean; watch?: boolean; - separateCompilation?: boolean; + isolatedModules?: boolean; + experimentalDecorators?: boolean; emitDecoratorMetadata?: boolean; /* @internal */ stripInternal?: boolean; [option: string]: string | number | boolean; diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index 356337e131..133be3d3d8 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -408,6 +408,93 @@ module ts { export let fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*/ + export function isTypeNode(node: Node): boolean { + if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) { + return true; + } + + switch (node.kind) { + case SyntaxKind.AnyKeyword: + case SyntaxKind.NumberKeyword: + case SyntaxKind.StringKeyword: + case SyntaxKind.BooleanKeyword: + case SyntaxKind.SymbolKeyword: + return true; + case SyntaxKind.VoidKeyword: + return node.parent.kind !== SyntaxKind.VoidExpression; + case SyntaxKind.StringLiteral: + // Specialized signatures can have string literals as their parameters' type names + return node.parent.kind === SyntaxKind.Parameter; + case SyntaxKind.ExpressionWithTypeArguments: + return true; + + // Identifiers and qualified names may be type nodes, depending on their context. Climb + // above them to find the lowest container + case SyntaxKind.Identifier: + // If the identifier is the RHS of a qualified name, then it's a type iff its parent is. + if (node.parent.kind === SyntaxKind.QualifiedName && (node.parent).right === node) { + node = node.parent; + } + else if (node.parent.kind === SyntaxKind.PropertyAccessExpression && (node.parent).name === node) { + node = node.parent; + } + // fall through + case SyntaxKind.QualifiedName: + case SyntaxKind.PropertyAccessExpression: + // At this point, node is either a qualified name or an identifier + Debug.assert(node.kind === SyntaxKind.Identifier || node.kind === SyntaxKind.QualifiedName || node.kind === SyntaxKind.PropertyAccessExpression, + "'node' was expected to be a qualified name, identifier or property access in 'isTypeNode'."); + + let parent = node.parent; + if (parent.kind === SyntaxKind.TypeQuery) { + return false; + } + // Do not recursively call isTypeNode on the parent. In the example: + // + // let a: A.B.C; + // + // Calling isTypeNode would consider the qualified name A.B a type node. Only C or + // A.B.C is a type node. + if (SyntaxKind.FirstTypeNode <= parent.kind && parent.kind <= SyntaxKind.LastTypeNode) { + return true; + } + switch (parent.kind) { + case SyntaxKind.ExpressionWithTypeArguments: + return true; + case SyntaxKind.TypeParameter: + return node === (parent).constraint; + case SyntaxKind.PropertyDeclaration: + case SyntaxKind.PropertySignature: + case SyntaxKind.Parameter: + case SyntaxKind.VariableDeclaration: + return node === (parent).type; + case SyntaxKind.FunctionDeclaration: + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.Constructor: + case SyntaxKind.MethodDeclaration: + case SyntaxKind.MethodSignature: + case SyntaxKind.GetAccessor: + case SyntaxKind.SetAccessor: + return node === (parent).type; + case SyntaxKind.CallSignature: + case SyntaxKind.ConstructSignature: + case SyntaxKind.IndexSignature: + return node === (parent).type; + case SyntaxKind.TypeAssertionExpression: + return node === (parent).type; + case SyntaxKind.CallExpression: + case SyntaxKind.NewExpression: + return (parent).typeArguments && indexOf((parent).typeArguments, node) >= 0; + case SyntaxKind.TaggedTemplateExpression: + // TODO (drosen): TaggedTemplateExpressions may eventually support type arguments. + return false; + } + } + + return false; + } + // Warning: This has the same semantics as the forEach family of functions, // in that traversal terminates in the event that 'visitor' supplies a truthy value. export function forEachReturnStatement(body: Block, visitor: (stmt: ReturnStatement) => T): T { @@ -438,6 +525,46 @@ module ts { } } + export function forEachYieldExpression(body: Block, visitor: (expr: YieldExpression) => void): void { + + return traverse(body); + + function traverse(node: Node): void { + switch (node.kind) { + case SyntaxKind.YieldExpression: + visitor(node); + let operand = (node).expression; + if (operand) { + traverse(operand); + } + case SyntaxKind.EnumDeclaration: + case SyntaxKind.InterfaceDeclaration: + case SyntaxKind.ModuleDeclaration: + case SyntaxKind.TypeAliasDeclaration: + case SyntaxKind.ClassDeclaration: + // These are not allowed inside a generator now, but eventually they may be allowed + // as local types. Regardless, any yield statements contained within them should be + // skipped in this traversal. + return; + default: + if (isFunctionLike(node)) { + let name = (node).name; + if (name && name.kind === SyntaxKind.ComputedPropertyName) { + // Note that we will not include methods/accessors of a class because they would require + // first descending into the class. This is by design. + traverse((name).expression); + return; + } + } + else if (!isTypeNode(node)) { + // This is the general case, which should include mostly expressions and statements. + // Also includes NodeArrays. + forEachChild(node, traverse); + } + } + } + } + export function isVariableLike(node: Node): boolean { if (node) { switch (node.kind) { @@ -468,6 +595,12 @@ module ts { return false; } + export function isClassLike(node: Node): boolean { + if (node) { + return node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression; + } + } + export function isFunctionLike(node: Node): boolean { if (node) { switch (node.kind) { @@ -733,6 +866,7 @@ module ts { case SyntaxKind.TemplateExpression: case SyntaxKind.NoSubstitutionTemplateLiteral: case SyntaxKind.OmittedExpression: + case SyntaxKind.YieldExpression: return true; case SyntaxKind.QualifiedName: while (node.parent.kind === SyntaxKind.QualifiedName) { @@ -829,10 +963,6 @@ module ts { } } - export function hasDotDotDotToken(node: Node) { - return node && node.kind === SyntaxKind.Parameter && (node).dotDotDotToken !== undefined; - } - export function hasQuestionToken(node: Node) { if (node) { switch (node.kind) { @@ -852,8 +982,76 @@ module ts { return false; } - export function hasRestParameters(s: SignatureDeclaration): boolean { - return s.parameters.length > 0 && lastOrUndefined(s.parameters).dotDotDotToken !== undefined; + export function isJSDocConstructSignature(node: Node) { + return node.kind === SyntaxKind.JSDocFunctionType && + (node).parameters.length > 0 && + (node).parameters[0].type.kind === SyntaxKind.JSDocConstructorType; + } + + function getJSDocTag(node: Node, kind: SyntaxKind): JSDocTag { + if (node && node.jsDocComment) { + for (let tag of node.jsDocComment.tags) { + if (tag.kind === kind) { + return tag; + } + } + } + } + + export function getJSDocTypeTag(node: Node): JSDocTypeTag { + return getJSDocTag(node, SyntaxKind.JSDocTypeTag); + } + + export function getJSDocReturnTag(node: Node): JSDocReturnTag { + return getJSDocTag(node, SyntaxKind.JSDocReturnTag); + } + + export function getJSDocTemplateTag(node: Node): JSDocTemplateTag { + return getJSDocTag(node, SyntaxKind.JSDocTemplateTag); + } + + export function getCorrespondingJSDocParameterTag(parameter: ParameterDeclaration): JSDocParameterTag { + if (parameter.name && parameter.name.kind === SyntaxKind.Identifier) { + // If it's a parameter, see if the parent has a jsdoc comment with an @param + // annotation. + let parameterName = (parameter.name).text; + + let docComment = parameter.parent.jsDocComment; + if (docComment) { + return forEach(docComment.tags, t => { + if (t.kind === SyntaxKind.JSDocParameterTag) { + let parameterTag = t; + let name = parameterTag.preParameterName || parameterTag.postParameterName; + if (name.text === parameterName) { + return t; + } + } + }); + } + } + } + + export function hasRestParameter(s: SignatureDeclaration): boolean { + return isRestParameter(lastOrUndefined(s.parameters)); + } + + export function isRestParameter(node: ParameterDeclaration) { + if (node) { + if (node.parserContextFlags & ParserContextFlags.JavaScriptFile) { + if (node.type && node.type.kind === SyntaxKind.JSDocVariadicType) { + return true; + } + + let paramTag = getCorrespondingJSDocParameterTag(node); + if (paramTag && paramTag.typeExpression) { + return paramTag.typeExpression.type.kind === SyntaxKind.JSDocVariadicType; + } + } + + return node.dotDotDotToken !== undefined; + } + + return false; } export function isLiteralKind(kind: SyntaxKind): boolean { @@ -1447,7 +1645,7 @@ module ts { if ((isExternalModule(sourceFile) || !compilerOptions.out)) { // 1. in-browser single file compilation scenario // 2. non .js file - return compilerOptions.separateCompilation || !fileExtensionIs(sourceFile.fileName, ".js"); + return compilerOptions.isolatedModules || !fileExtensionIs(sourceFile.fileName, ".js"); } return false; } @@ -1707,6 +1905,10 @@ module ts { return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & NodeFlags.Default) ? symbol.valueDeclaration.localSymbol : undefined; } + export function isJavaScript(fileName: string) { + return fileExtensionIs(fileName, ".js"); + } + /** * Replace each instance of non-ascii characters by one, two, three, or four escape sequences * representing the UTF-8 encoding of the character, and return the expanded char code list. @@ -2000,4 +2202,14 @@ module ts { return createTextChangeRange(createTextSpanFromBounds(oldStartN, oldEndN), /*newLength:*/ newEndN - oldStartN); } + + export function getTypeParameterOwner(d: Declaration): Declaration { + if (d && d.kind === SyntaxKind.TypeParameter) { + for (let current: Node = d; current; current = current.parent) { + if (isFunctionLike(current) || isClassLike(current) || current.kind === SyntaxKind.InterfaceDeclaration) { + return current; + } + } + } + } } diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index ef4410b3e3..8d313c9a1a 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -798,8 +798,17 @@ module FourSlash { return "\nActual " + name + ":\n\t" + actualValue + "\nExpected value:\n\t" + expectedValue; } + public getSyntacticDiagnostics(expected: string) { + var diagnostics = this.languageService.getSyntacticDiagnostics(this.activeFile.fileName); + this.testDiagnostics(expected, diagnostics); + } + public getSemanticDiagnostics(expected: string) { var diagnostics = this.languageService.getSemanticDiagnostics(this.activeFile.fileName); + this.testDiagnostics(expected, diagnostics); + } + + private testDiagnostics(expected: string, diagnostics: ts.Diagnostic[]) { var realized = ts.realizeDiagnostics(diagnostics, "\r\n"); var actual = JSON.stringify(realized, null, " "); assert.equal(actual, expected); @@ -1809,6 +1818,21 @@ module FourSlash { } } + private verifyProjectInfo(expected: string[]) { + if (this.testType == FourSlashTestType.Server) { + let actual = (this.languageService).getProjectInfo( + this.activeFile.fileName, + /* needFileNameList */ true + ); + assert.equal( + expected.join(","), + actual.fileNameList.map( file => { + return file.replace(this.basePath + "/", "") + }).join(",") + ); + } + } + public verifySemanticClassifications(expected: { classificationType: string; text: string }[]) { var actual = this.languageService.getSemanticClassifications(this.activeFile.fileName, ts.createTextSpan(0, this.activeFile.content.length)); diff --git a/src/harness/harness.ts b/src/harness/harness.ts index 23cdfdfb7c..b3791283a6 100644 --- a/src/harness/harness.ts +++ b/src/harness/harness.ts @@ -193,12 +193,16 @@ module Utils { }; } - export function sourceFileToJSON(file: ts.SourceFile): string { + export function sourceFileToJSON(file: ts.Node): string { return JSON.stringify(file,(k, v) => { return isNodeOrArray(v) ? serializeNode(v) : v; }, " "); - function getKindName(k: number): string { + function getKindName(k: number | string): string { + if (typeof k === "string") { + return k; + } + return (ts).SyntaxKind[k] } @@ -231,7 +235,9 @@ module Utils { function serializeNode(n: ts.Node): any { var o: any = { kind: getKindName(n.kind) }; - o.containsParseError = ts.containsParseError(n); + if (ts.containsParseError(n)) { + o.containsParseError = true; + } ts.forEach(Object.getOwnPropertyNames(n), propertyName => { switch (propertyName) { @@ -249,6 +255,10 @@ module Utils { // Blacklist of items we never put in the baseline file. break; + case "originalKeywordKind": + o[propertyName] = getKindName((n)[propertyName]); + break; + case "flags": // Print out flags with their enum names. o[propertyName] = getNodeFlagName(n.flags); @@ -1001,6 +1011,10 @@ module Harness { options.target = setting.value; } break; + + case 'experimentaldecorators': + options.experimentalDecorators = setting.value === 'true'; + break; case 'emitdecoratormetadata': options.emitDecoratorMetadata = setting.value === 'true'; @@ -1095,8 +1109,8 @@ module Harness { options.preserveConstEnums = setting.value === 'true'; break; - case 'separatecompilation': - options.separateCompilation = setting.value === 'true'; + case 'isolatedmodules': + options.isolatedModules = setting.value === 'true'; break; case 'suppressimplicitanyindexerrors': @@ -1512,8 +1526,8 @@ module Harness { "noimplicitany", "noresolve", "newline", "normalizenewline", "emitbom", "errortruncation", "usecasesensitivefilenames", "preserveconstenums", "includebuiltfile", "suppressimplicitanyindexerrors", "stripinternal", - "separatecompilation", "inlinesourcemap", "maproot", "sourceroot", - "inlinesources", "emitdecoratormetadata"]; + "isolatedmodules", "inlinesourcemap", "maproot", "sourceroot", + "inlinesources", "emitdecoratormetadata", "experimentaldecorators"]; function extractCompilerSettings(content: string): CompilerSetting[] { diff --git a/src/lib/es6.d.ts b/src/lib/es6.d.ts index dc082c8f0a..625a4eca9e 100644 --- a/src/lib/es6.d.ts +++ b/src/lib/es6.d.ts @@ -316,6 +316,11 @@ interface Array { copyWithin(target: number, start: number, end?: number): T[]; } +interface IArguments { + /** Iterator */ + [Symbol.iterator](): IterableIterator; +} + interface ArrayConstructor { /** * Creates an array from an array-like object. @@ -500,14 +505,6 @@ interface GeneratorFunctionConstructor { } declare var GeneratorFunction: GeneratorFunctionConstructor; -interface Generator extends IterableIterator { - next(value?: any): IteratorResult; - throw(exception: any): IteratorResult; - return(value: T): IteratorResult; - [Symbol.iterator](): Generator; - [Symbol.toStringTag]: string; -} - interface Math { /** * Returns the number of leading zero bits in the 32-bit binary representation of a number. diff --git a/src/lib/intl.d.ts b/src/lib/intl.d.ts index dfa6f0990d..66e51ddbc5 100644 --- a/src/lib/intl.d.ts +++ b/src/lib/intl.d.ts @@ -62,10 +62,10 @@ declare module Intl { resolvedOptions(): ResolvedNumberFormatOptions; } var NumberFormat: { - new (locales?: string[], options?: NumberFormatOptions): Collator; - new (locale?: string, options?: NumberFormatOptions): Collator; - (locales?: string[], options?: NumberFormatOptions): Collator; - (locale?: string, options?: NumberFormatOptions): Collator; + new (locales?: string[], options?: NumberFormatOptions): NumberFormat; + new (locale?: string, options?: NumberFormatOptions): NumberFormat; + (locales?: string[], options?: NumberFormatOptions): NumberFormat; + (locale?: string, options?: NumberFormatOptions): NumberFormat; supportedLocalesOf(locales: string[], options?: NumberFormatOptions): string[]; supportedLocalesOf(locale: string, options?: NumberFormatOptions): string[]; } @@ -107,10 +107,10 @@ declare module Intl { resolvedOptions(): ResolvedDateTimeFormatOptions; } var DateTimeFormat: { - new (locales?: string[], options?: DateTimeFormatOptions): Collator; - new (locale?: string, options?: DateTimeFormatOptions): Collator; - (locales?: string[], options?: DateTimeFormatOptions): Collator; - (locale?: string, options?: DateTimeFormatOptions): Collator; + new (locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat; + new (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat; + (locales?: string[], options?: DateTimeFormatOptions): DateTimeFormat; + (locale?: string, options?: DateTimeFormatOptions): DateTimeFormat; supportedLocalesOf(locales: string[], options?: DateTimeFormatOptions): string[]; supportedLocalesOf(locale: string, options?: DateTimeFormatOptions): string[]; } diff --git a/src/server/client.ts b/src/server/client.ts index 3582d50832..f1c5e424d4 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -171,6 +171,21 @@ module ts.server { documentation: [{ kind: "text", text: response.body.documentation }] }; } + + getProjectInfo(fileName: string, needFileNameList: boolean): protocol.ProjectInfo { + var args: protocol.ProjectInfoRequestArgs = { + file: fileName, + needFileNameList: needFileNameList + }; + + var request = this.processRequest(CommandNames.ProjectInfo, args); + var response = this.processResponse(request); + + return { + configFileName: response.body.configFileName, + fileNameList: response.body.fileNameList + }; + } getCompletionsAtPosition(fileName: string, position: number): CompletionInfo { var lineOffset = this.positionToOneBasedLineOffset(fileName, position); diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 9c87a20c85..bc9e685825 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -305,6 +305,11 @@ module ts.server { return this.projectService.openFile(filename, false); } + getFileNameList() { + let sourceFiles = this.program.getSourceFiles(); + return sourceFiles.map(sourceFile => sourceFile.fileName); + } + getSourceFile(info: ScriptInfo) { return this.filenameToSourceFile[info.fileName]; } diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index b95d5e9986..ef9ad7984f 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -87,6 +87,45 @@ declare module ts.server.protocol { file: string; } + /** + * Arguments for ProjectInfoRequest request. + */ + export interface ProjectInfoRequestArgs extends FileRequestArgs { + /** + * Indicate if the file name list of the project is needed + */ + needFileNameList: boolean; + } + + /** + * A request to get the project information of the current file + */ + export interface ProjectInfoRequest extends Request { + arguments: ProjectInfoRequestArgs + } + + /** + * Response message body for "projectInfo" request + */ + export interface ProjectInfo { + /** + * For configured project, this is the normalized path of the 'tsconfig.json' file + * For inferred project, this is undefined + */ + configFileName: string; + /** + * The list of normalized file name in the project, including 'lib.d.ts' + */ + fileNameList?: string[]; + } + + /** + * Response message for "projectInfo" request + */ + export interface ProjectInfoResponse extends Response { + body?: ProjectInfo; + } + /** * Request whose sole parameter is a file name. */ diff --git a/src/server/session.ts b/src/server/session.ts index baf0a085ad..a4cb3e59b4 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -76,29 +76,30 @@ module ts.server { } export module CommandNames { - export var Brace = "brace"; - export var Change = "change"; - export var Close = "close"; - export var Completions = "completions"; - export var CompletionDetails = "completionEntryDetails"; - export var Configure = "configure"; - export var Definition = "definition"; - export var Exit = "exit"; - export var Format = "format"; - export var Formatonkey = "formatonkey"; - export var Geterr = "geterr"; - export var NavBar = "navbar"; - export var Navto = "navto"; - export var Occurrences = "occurrences"; - export var Open = "open"; - export var Quickinfo = "quickinfo"; - export var References = "references"; - export var Reload = "reload"; - export var Rename = "rename"; - export var Saveto = "saveto"; - export var SignatureHelp = "signatureHelp"; - export var TypeDefinition = "typeDefinition"; - export var Unknown = "unknown"; + export const Brace = "brace"; + export const Change = "change"; + export const Close = "close"; + export const Completions = "completions"; + export const CompletionDetails = "completionEntryDetails"; + export const Configure = "configure"; + export const Definition = "definition"; + export const Exit = "exit"; + export const Format = "format"; + export const Formatonkey = "formatonkey"; + export const Geterr = "geterr"; + export const NavBar = "navbar"; + export const Navto = "navto"; + export const Occurrences = "occurrences"; + export const Open = "open"; + export const Quickinfo = "quickinfo"; + export const References = "references"; + export const Reload = "reload"; + export const Rename = "rename"; + export const Saveto = "saveto"; + export const SignatureHelp = "signatureHelp"; + export const TypeDefinition = "typeDefinition"; + export const ProjectInfo = "projectInfo"; + export const Unknown = "unknown"; } module Errors { @@ -338,6 +339,21 @@ module ts.server { }); } + getProjectInfo(fileName: string, needFileNameList: boolean): protocol.ProjectInfo { + fileName = ts.normalizePath(fileName) + let project = this.projectService.getProjectForFile(fileName) + + let projectInfo: protocol.ProjectInfo = { + configFileName: project.projectFilename + } + + if (needFileNameList) { + projectInfo.fileNameList = project.getFileNameList(); + } + + return projectInfo; + } + getRenameLocations(line: number, offset: number, fileName: string,findInComments: boolean, findInStrings: boolean): protocol.RenameResponseBody { var file = ts.normalizePath(fileName); var project = this.projectService.getProjectForFile(file); @@ -951,6 +967,11 @@ module ts.server { response = this.getOccurrences(line, offset, fileName); break; } + case CommandNames.ProjectInfo: { + var { file, needFileNameList } = request.arguments; + response = this.getProjectInfo(file, needFileNameList); + break; + } default: { this.projectService.log("Unrecognized JSON command: " + message); this.output(undefined, CommandNames.Unknown, request.seq, "Unrecognized JSON command: " + request.command); diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 0b6a6ad0bd..9cf6d8ff4b 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -193,12 +193,18 @@ module ts.formatting { // Insert space after function keyword for anonymous functions public SpaceAfterAnonymousFunctionKeyword: Rule; public NoSpaceAfterAnonymousFunctionKeyword: Rule; - + // Insert space after @ in decorator public SpaceBeforeAt: Rule; public NoSpaceAfterAt: Rule; public SpaceAfterDecorator: Rule; + // Generator: function* + public NoSpaceBetweenFunctionKeywordAndStar: Rule; + public SpaceAfterStarInGeneratorDeclaration: Rule; + public NoSpaceBetweenYieldKeywordAndStar: Rule; + public SpaceBetweenYieldOrYieldStarAndOperand: Rule; + constructor() { /// /// Common Rules @@ -231,7 +237,7 @@ module ts.formatting { this.NoSpaceBeforeOpenBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); this.NoSpaceAfterOpenBracket = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); this.NoSpaceBeforeCloseBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); - this.NoSpaceAfterCloseBracket = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); + this.NoSpaceAfterCloseBracket = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBeforeBlockInFunctionDeclarationContext), RuleAction.Delete)); // Place a space before open brace in a function declaration this.FunctionOpenBraceLeftTokenRange = Shared.TokenRange.AnyIncludingMultilineComments; @@ -340,6 +346,11 @@ module ts.formatting { this.NoSpaceAfterAt = new Rule(RuleDescriptor.create3(SyntaxKind.AtToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); this.SpaceAfterDecorator = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.ExportKeyword, SyntaxKind.DefaultKeyword, SyntaxKind.ClassKeyword, SyntaxKind.StaticKeyword, SyntaxKind.PublicKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.GetKeyword, SyntaxKind.SetKeyword, SyntaxKind.OpenBracketToken, SyntaxKind.AsteriskToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsEndOfDecoratorContextOnSameLine), RuleAction.Space)); + this.NoSpaceBetweenFunctionKeywordAndStar = new Rule(RuleDescriptor.create1(SyntaxKind.FunctionKeyword, SyntaxKind.AsteriskToken), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), RuleAction.Delete)); + this.SpaceAfterStarInGeneratorDeclaration = new Rule(RuleDescriptor.create3(SyntaxKind.AsteriskToken, Shared.TokenRange.FromTokens([SyntaxKind.Identifier, SyntaxKind.OpenParenToken])), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclarationOrFunctionExpressionContext), RuleAction.Space)); + this.NoSpaceBetweenYieldKeywordAndStar = new Rule(RuleDescriptor.create1(SyntaxKind.YieldKeyword, SyntaxKind.AsteriskToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), RuleAction.Delete)); + this.SpaceBetweenYieldOrYieldStarAndOperand = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.YieldKeyword, SyntaxKind.AsteriskToken]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), RuleAction.Space)); + // These rules are higher in priority than user-configurable rules. this.HighPriorityCommonRules = [ @@ -357,7 +368,9 @@ module ts.formatting { this.NoSpaceAfterCloseBrace, this.SpaceAfterOpenBrace, this.SpaceBeforeCloseBrace, this.NewLineBeforeCloseBraceInBlockContext, this.SpaceAfterCloseBrace, this.SpaceBetweenCloseBraceAndElse, this.SpaceBetweenCloseBraceAndWhile, this.NoSpaceBetweenEmptyBraceBrackets, + this.NoSpaceBetweenFunctionKeywordAndStar, this.SpaceAfterStarInGeneratorDeclaration, this.SpaceAfterFunctionInFuncDecl, this.NewLineAfterOpenBraceInBlockContext, this.SpaceAfterGetSetInMember, + this.NoSpaceBetweenYieldKeywordAndStar, this.SpaceBetweenYieldOrYieldStarAndOperand, this.NoSpaceBetweenReturnAndSemicolon, this.SpaceAfterCertainKeywords, this.SpaceAfterLetConstInVariableDeclaration, @@ -574,6 +587,10 @@ module ts.formatting { return false; } + static IsFunctionDeclarationOrFunctionExpressionContext(context: FormattingContext): boolean { + return context.contextNode.kind === SyntaxKind.FunctionDeclaration || context.contextNode.kind === SyntaxKind.FunctionExpression; + } + static IsTypeScriptDeclWithBlockContext(context: FormattingContext): boolean { return Rules.NodeIsTypeScriptDeclWithBlockContext(context.contextNode); } @@ -650,6 +667,10 @@ module ts.formatting { return context.TokensAreOnSameLine(); } + static IsNotBeforeBlockInFunctionDeclarationContext(context: FormattingContext): boolean { + return !Rules.IsFunctionDeclContext(context) && !Rules.IsBeforeBlockContext(context) + } + static IsEndOfDecoratorContextOnSameLine(context: FormattingContext): boolean { return context.TokensAreOnSameLine() && context.contextNode.decorators && @@ -713,5 +734,9 @@ module ts.formatting { static IsVoidOpContext(context: FormattingContext): boolean { return context.currentTokenSpan.kind === SyntaxKind.VoidKeyword && context.currentTokenParent.kind === SyntaxKind.VoidExpression; } + + static IsYieldOrYieldStarWithOperand(context: FormattingContext): boolean { + return context.contextNode.kind === SyntaxKind.YieldExpression && (context.contextNode).expression !== undefined; + } } } \ No newline at end of file diff --git a/src/services/services.ts b/src/services/services.ts index 9fb495ee93..400bf754a0 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1510,6 +1510,7 @@ module ts { public static typeParameterName = "type parameter name"; public static typeAliasName = "type alias name"; public static parameterName = "parameter name"; + public static docCommentTagName = "doc comment tag name"; } export const enum ClassificationType { @@ -1529,7 +1530,8 @@ module ts { moduleName = 14, typeParameterName = 15, typeAliasName = 16, - parameterName = 17 + parameterName = 17, + docCommentTagName = 18, } /// Language Service @@ -1761,13 +1763,13 @@ module ts { * This function will compile source text from 'input' argument using specified compiler options. * If not options are provided - it will use a set of default compiler options. * Extra compiler options that will unconditionally be used bu this function are: - * - separateCompilation = true + * - isolatedModules = true * - allowNonTsExtensions = true */ export function transpile(input: string, compilerOptions?: CompilerOptions, fileName?: string, diagnostics?: Diagnostic[]): string { let options = compilerOptions ? clone(compilerOptions) : getDefaultCompilerOptions(); - options.separateCompilation = true; + options.isolatedModules = true; // Filename can be non-ts file. options.allowNonTsExtensions = true; @@ -1813,7 +1815,8 @@ module ts { } export function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean): SourceFile { - let sourceFile = createSourceFile(fileName, scriptSnapshot.getText(0, scriptSnapshot.getLength()), scriptTarget, setNodeParents); + let text = scriptSnapshot.getText(0, scriptSnapshot.getLength()); + let sourceFile = createSourceFile(fileName, text, scriptTarget, setNodeParents); setSourceFileFields(sourceFile, scriptSnapshot, version); // after full parsing we can use table with interned strings as name table sourceFile.nameTable = sourceFile.identifiers; @@ -1829,7 +1832,34 @@ module ts { if (version !== sourceFile.version) { // Once incremental parsing is ready, then just call into this function. if (!disableIncrementalParsing) { - let newSourceFile = updateSourceFile(sourceFile, scriptSnapshot.getText(0, scriptSnapshot.getLength()), textChangeRange, aggressiveChecks); + let newText: string; + + // grab the fragment from the beginning of the original text to the beginning of the span + let prefix = textChangeRange.span.start !== 0 + ? sourceFile.text.substr(0, textChangeRange.span.start) + : ""; + + // grab the fragment from the end of the span till the end of the original text + let suffix = textSpanEnd(textChangeRange.span) !== sourceFile.text.length + ? sourceFile.text.substr(textSpanEnd(textChangeRange.span)) + : ""; + + if (textChangeRange.newLength === 0) { + // edit was a deletion - just combine prefix and suffix + newText = prefix && suffix ? prefix + suffix : prefix || suffix; + } + else { + // it was actual edit, fetch the fragment of new text that correspond to new span + let changedText = scriptSnapshot.getText(textChangeRange.span.start, textChangeRange.span.start + textChangeRange.newLength); + // combine prefix, changed text and suffix + newText = prefix && suffix + ? prefix + changedText + suffix + : prefix + ? (prefix + changedText) + : (changedText + suffix); + } + + let newSourceFile = updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks); setSourceFileFields(newSourceFile, scriptSnapshot, version); // after incremental parsing nameTable might not be up-to-date // drop it so it can be lazily recreated later @@ -2448,6 +2478,10 @@ module ts { } } + // hostCache is captured in the closure for 'getOrCreateSourceFile' but it should not be used past this point. + // It needs to be cleared to allow all collected snapshots to be released + hostCache = undefined; + program = newProgram; // Make sure all the nodes in the program are both bound, and have their parent @@ -2456,6 +2490,7 @@ module ts { return; function getOrCreateSourceFile(fileName: string): SourceFile { + Debug.assert(hostCache !== undefined); // The program is asking for this file, check first if the host can locate it. // If the host can not locate the file, then it does not exist. return undefined // to the program to allow reporting of errors for missing files. @@ -2671,7 +2706,7 @@ module ts { return true; } if (parameter.questionToken) { - diagnostics.push(createDiagnosticForNode(parameter.questionToken, Diagnostics.can_only_be_used_in_a_ts_file)); + diagnostics.push(createDiagnosticForNode(parameter.questionToken, Diagnostics._0_can_only_be_used_in_a_ts_file, '?')); return true; } if (parameter.type) { @@ -2805,6 +2840,7 @@ module ts { let typeChecker = program.getTypeChecker(); let syntacticStart = new Date().getTime(); let sourceFile = getValidSourceFile(fileName); + let isJavaScriptFile = isJavaScript(fileName); let start = new Date().getTime(); let currentToken = getTokenAtPosition(sourceFile, position); @@ -2905,13 +2941,29 @@ module ts { } let type = typeChecker.getTypeAtLocation(node); + addTypeProperties(type); + } + + function addTypeProperties(type: Type) { if (type) { // Filter private properties - forEach(type.getApparentProperties(), symbol => { + for (let symbol of type.getApparentProperties()) { if (typeChecker.isValidPropertyAccess((node.parent), symbol.name)) { symbols.push(symbol); } - }); + } + + if (isJavaScriptFile && type.flags & TypeFlags.Union) { + // In javascript files, for union types, we don't just get the members that + // the individual types have in common, we also include all the members that + // each individual type has. This is because we're going to add all identifiers + // anyways. So we might as well elevate the members that were at least part + // of the individual types to a higher status since we know what they are. + let unionType = type; + for (let elementType of unionType.types) { + addTypeProperties(elementType); + } + } } } @@ -3098,16 +3150,20 @@ module ts { if (previousToken.kind === SyntaxKind.StringLiteral || previousToken.kind === SyntaxKind.RegularExpressionLiteral || isTemplateLiteralKind(previousToken.kind)) { - // The position has to be either: 1. entirely within the token text, or - // 2. at the end position of an unterminated token. let start = previousToken.getStart(); let end = previousToken.getEnd(); + // To be "in" one of these literals, the position has to be: + // 1. entirely within the token text. + // 2. at the end position of an unterminated token. + // 3. at the end of a regular expression (due to trailing flags like '/foo/g'). if (start < position && position < end) { return true; } - else if (position === end) { - return !!(previousToken).isUnterminated; + + if (position === end) { + return !!(previousToken).isUnterminated || + previousToken.kind === SyntaxKind.RegularExpressionLiteral; } } @@ -6004,6 +6060,7 @@ module ts { case ClassificationType.typeParameterName: return ClassificationTypeNames.typeParameterName; case ClassificationType.typeAliasName: return ClassificationTypeNames.typeAliasName; case ClassificationType.parameterName: return ClassificationTypeNames.parameterName; + case ClassificationType.docCommentTagName: return ClassificationTypeNames.docCommentTagName; } } @@ -6066,8 +6123,7 @@ module ts { // Only bother with the trivia if it at least intersects the span of interest. if (textSpanIntersectsWith(span, start, width)) { if (isComment(kind)) { - // Simple comment. Just add as is. - pushClassification(start, width, ClassificationType.comment); + classifyComment(token, kind, start, width); continue; } @@ -6091,6 +6147,92 @@ module ts { } } + function classifyComment(token: Node, kind: SyntaxKind, start: number, width: number) { + if (kind === SyntaxKind.MultiLineCommentTrivia) { + // See if this is a doc comment. If so, we'll classify certain portions of it + // specially. + let docCommentAndDiagnostics = parseIsolatedJSDocComment(sourceFile.text, start, width); + if (docCommentAndDiagnostics && docCommentAndDiagnostics.jsDocComment) { + docCommentAndDiagnostics.jsDocComment.parent = token; + classifyJSDocComment(docCommentAndDiagnostics.jsDocComment); + return; + } + } + + // Simple comment. Just add as is. + pushCommentRange(start, width); + } + + function pushCommentRange(start: number, width: number) { + pushClassification(start, width, ClassificationType.comment); + } + + function classifyJSDocComment(docComment: JSDocComment) { + let pos = docComment.pos; + + for (let tag of docComment.tags) { + // As we walk through each tag, classify the portion of text from the end of + // the last tag (or the start of the entire doc comment) as 'comment'. + if (tag.pos !== pos) { + pushCommentRange(pos, tag.pos - pos); + } + + pushClassification(tag.atToken.pos, tag.atToken.end - tag.atToken.pos, ClassificationType.punctuation); + pushClassification(tag.tagName.pos, tag.tagName.end - tag.tagName.pos, ClassificationType.docCommentTagName); + + pos = tag.tagName.end; + + switch (tag.kind) { + case SyntaxKind.JSDocParameterTag: + processJSDocParameterTag(tag); + break; + case SyntaxKind.JSDocTemplateTag: + processJSDocTemplateTag(tag); + break; + case SyntaxKind.JSDocTypeTag: + processElement((tag).typeExpression); + break; + case SyntaxKind.JSDocReturnTag: + processElement((tag).typeExpression); + break; + } + + pos = tag.end; + } + + if (pos !== docComment.end) { + pushCommentRange(pos, docComment.end - pos); + } + + return; + + function processJSDocParameterTag(tag: JSDocParameterTag) { + if (tag.preParameterName) { + pushCommentRange(pos, tag.preParameterName.pos - pos); + pushClassification(tag.preParameterName.pos, tag.preParameterName.end - tag.preParameterName.pos, ClassificationType.parameterName); + pos = tag.preParameterName.end; + } + + if (tag.typeExpression) { + pushCommentRange(pos, tag.typeExpression.pos - pos); + processElement(tag.typeExpression); + pos = tag.typeExpression.end; + } + + if (tag.postParameterName) { + pushCommentRange(pos, tag.postParameterName.pos - pos); + pushClassification(tag.postParameterName.pos, tag.postParameterName.end - tag.postParameterName.pos, ClassificationType.parameterName); + pos = tag.postParameterName.end; + } + } + } + + function processJSDocTemplateTag(tag: JSDocTemplateTag) { + for (let child of tag.getChildren()) { + processElement(child); + } + } + function classifyDisabledMergeCode(text: string, start: number, end: number) { // Classify the line that the ======= marker is on as a comment. Then just lex // all further tokens and add them to the result. @@ -6224,9 +6366,13 @@ module ts { } function processElement(element: Node) { + if (!element) { + return; + } + // Ignore nodes that don't intersect the original span to classify. if (textSpanIntersectsWith(span, element.getFullStart(), element.getFullWidth())) { - let children = element.getChildren(); + let children = element.getChildren(sourceFile); for (let child of children) { if (isToken(child)) { classifyToken(child); diff --git a/src/services/shims.ts b/src/services/shims.ts index 27c70ddc87..d3f5973753 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -989,4 +989,4 @@ module TypeScript.Services { } /* @internal */ -let toolsVersion = "1.4"; +let toolsVersion = "1.5"; diff --git a/src/services/utilities.ts b/src/services/utilities.ts index f2074d43ec..da0a0aa96c 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -652,8 +652,4 @@ module ts { typechecker.getSymbolDisplayBuilder().buildSignatureDisplay(signature, writer, enclosingDeclaration, flags); }); } - - export function isJavaScript(fileName: string) { - return fileExtensionIs(fileName, ".js"); - } } \ No newline at end of file diff --git a/tests/baselines/reference/FunctionDeclaration10_es6.errors.txt b/tests/baselines/reference/FunctionDeclaration10_es6.errors.txt index 8c6b09c82d..35edf48564 100644 --- a/tests/baselines/reference/FunctionDeclaration10_es6.errors.txt +++ b/tests/baselines/reference/FunctionDeclaration10_es6.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,10): error TS9001: Generators are not currently supported. +tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts(1,10): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration10_es6.ts (1 errors) ==== function * foo(a = yield => yield) { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/FunctionDeclaration11_es6.errors.txt b/tests/baselines/reference/FunctionDeclaration11_es6.errors.txt index 1dd8c3f6a1..e24f702213 100644 --- a/tests/baselines/reference/FunctionDeclaration11_es6.errors.txt +++ b/tests/baselines/reference/FunctionDeclaration11_es6.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts(1,10): error TS9001: Generators are not currently supported. +tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts(1,10): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration11_es6.ts (1 errors) ==== function * yield() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/FunctionDeclaration13_es6.errors.txt b/tests/baselines/reference/FunctionDeclaration13_es6.errors.txt index a46097e8a1..2b090f4a73 100644 --- a/tests/baselines/reference/FunctionDeclaration13_es6.errors.txt +++ b/tests/baselines/reference/FunctionDeclaration13_es6.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration13_es6.ts(1,10): error TS9001: Generators are not currently supported. +tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration13_es6.ts(1,10): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration13_es6.ts(3,11): error TS2304: Cannot find name 'yield'. ==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration13_es6.ts (2 errors) ==== function * foo() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. // Legal to use 'yield' in a type context. var v: yield; ~~~~~ diff --git a/tests/baselines/reference/FunctionDeclaration1_es6.errors.txt b/tests/baselines/reference/FunctionDeclaration1_es6.errors.txt index 71b0998393..52bdfbd1af 100644 --- a/tests/baselines/reference/FunctionDeclaration1_es6.errors.txt +++ b/tests/baselines/reference/FunctionDeclaration1_es6.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration1_es6.ts(1,10): error TS9001: Generators are not currently supported. +tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration1_es6.ts(1,10): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration1_es6.ts (1 errors) ==== function * foo() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/FunctionDeclaration6_es6.errors.txt b/tests/baselines/reference/FunctionDeclaration6_es6.errors.txt index b5ea3f494a..9f696e7108 100644 --- a/tests/baselines/reference/FunctionDeclaration6_es6.errors.txt +++ b/tests/baselines/reference/FunctionDeclaration6_es6.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,9): error TS9001: Generators are not currently supported. +tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts(1,18): error TS2304: Cannot find name 'yield'. ==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration6_es6.ts (2 errors) ==== function*foo(a = yield) { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. ~~~~~ !!! error TS2304: Cannot find name 'yield'. } \ No newline at end of file diff --git a/tests/baselines/reference/FunctionDeclaration7_es6.errors.txt b/tests/baselines/reference/FunctionDeclaration7_es6.errors.txt index f129d3fa30..91fab36ed3 100644 --- a/tests/baselines/reference/FunctionDeclaration7_es6.errors.txt +++ b/tests/baselines/reference/FunctionDeclaration7_es6.errors.txt @@ -1,16 +1,16 @@ -tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(1,9): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,11): error TS9001: Generators are not currently supported. +tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(1,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. +tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,11): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts(3,20): error TS2304: Cannot find name 'yield'. ==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration7_es6.ts (3 errors) ==== function*bar() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. // 'yield' here is an identifier, and not a yield expression. function*foo(a = yield) { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. ~~~~~ !!! error TS2304: Cannot find name 'yield'. } diff --git a/tests/baselines/reference/FunctionDeclaration9_es6.errors.txt b/tests/baselines/reference/FunctionDeclaration9_es6.errors.txt index 152b1ffc7c..e4222409a6 100644 --- a/tests/baselines/reference/FunctionDeclaration9_es6.errors.txt +++ b/tests/baselines/reference/FunctionDeclaration9_es6.errors.txt @@ -1,12 +1,9 @@ -tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(1,10): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(2,14): error TS9000: 'yield' expressions are not currently supported. +tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts(1,10): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. -==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts (2 errors) ==== +==== tests/cases/conformance/es6/functionDeclarations/FunctionDeclaration9_es6.ts (1 errors) ==== function * foo() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. var v = { [yield]: foo } - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. } \ No newline at end of file diff --git a/tests/baselines/reference/FunctionExpression1_es6.errors.txt b/tests/baselines/reference/FunctionExpression1_es6.errors.txt index 979178fd4b..cb2ebd7245 100644 --- a/tests/baselines/reference/FunctionExpression1_es6.errors.txt +++ b/tests/baselines/reference/FunctionExpression1_es6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/functionExpressions/FunctionExpression1_es6.ts(1,18): error TS9001: Generators are not currently supported. +tests/cases/conformance/es6/functionExpressions/FunctionExpression1_es6.ts(1,18): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/es6/functionExpressions/FunctionExpression1_es6.ts (1 errors) ==== var v = function * () { } ~ -!!! error TS9001: Generators are not currently supported. \ No newline at end of file +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. \ No newline at end of file diff --git a/tests/baselines/reference/FunctionExpression2_es6.errors.txt b/tests/baselines/reference/FunctionExpression2_es6.errors.txt index ab27947d7c..d5350b5fde 100644 --- a/tests/baselines/reference/FunctionExpression2_es6.errors.txt +++ b/tests/baselines/reference/FunctionExpression2_es6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/functionExpressions/FunctionExpression2_es6.ts(1,18): error TS9001: Generators are not currently supported. +tests/cases/conformance/es6/functionExpressions/FunctionExpression2_es6.ts(1,18): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/es6/functionExpressions/FunctionExpression2_es6.ts (1 errors) ==== var v = function * foo() { } ~ -!!! error TS9001: Generators are not currently supported. \ No newline at end of file +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. \ No newline at end of file diff --git a/tests/baselines/reference/FunctionPropertyAssignments1_es6.errors.txt b/tests/baselines/reference/FunctionPropertyAssignments1_es6.errors.txt index bbabbc9746..a2aa32a9dd 100644 --- a/tests/baselines/reference/FunctionPropertyAssignments1_es6.errors.txt +++ b/tests/baselines/reference/FunctionPropertyAssignments1_es6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments1_es6.ts(1,11): error TS9001: Generators are not currently supported. +tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments1_es6.ts(1,11): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments1_es6.ts (1 errors) ==== var v = { *foo() { } } ~ -!!! error TS9001: Generators are not currently supported. \ No newline at end of file +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. \ No newline at end of file diff --git a/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt b/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt index 596764e58e..8490be5cdc 100644 --- a/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt +++ b/tests/baselines/reference/FunctionPropertyAssignments5_es6.errors.txt @@ -1,10 +1,10 @@ -tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,11): error TS9001: Generators are not currently supported. +tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,11): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts(1,13): error TS2304: Cannot find name 'foo'. ==== tests/cases/conformance/es6/functionPropertyAssignments/FunctionPropertyAssignments5_es6.ts (2 errors) ==== var v = { *[foo()]() { } } ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. ~~~ !!! error TS2304: Cannot find name 'foo'. \ No newline at end of file diff --git a/tests/baselines/reference/MemberFunctionDeclaration1_es6.errors.txt b/tests/baselines/reference/MemberFunctionDeclaration1_es6.errors.txt index 9d4e312ed2..7766ad8d79 100644 --- a/tests/baselines/reference/MemberFunctionDeclaration1_es6.errors.txt +++ b/tests/baselines/reference/MemberFunctionDeclaration1_es6.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration1_es6.ts(2,4): error TS9001: Generators are not currently supported. +tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration1_es6.ts(2,4): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration1_es6.ts (1 errors) ==== class C { *foo() { } ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/MemberFunctionDeclaration2_es6.errors.txt b/tests/baselines/reference/MemberFunctionDeclaration2_es6.errors.txt index 6373c80099..38a761f6db 100644 --- a/tests/baselines/reference/MemberFunctionDeclaration2_es6.errors.txt +++ b/tests/baselines/reference/MemberFunctionDeclaration2_es6.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration2_es6.ts(2,11): error TS9001: Generators are not currently supported. +tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration2_es6.ts(2,11): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration2_es6.ts (1 errors) ==== class C { public * foo() { } ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/MemberFunctionDeclaration3_es6.errors.txt b/tests/baselines/reference/MemberFunctionDeclaration3_es6.errors.txt index 826c1d7fd7..e561954035 100644 --- a/tests/baselines/reference/MemberFunctionDeclaration3_es6.errors.txt +++ b/tests/baselines/reference/MemberFunctionDeclaration3_es6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts(2,4): error TS9001: Generators are not currently supported. +tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts(2,4): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration3_es6.ts(2,6): error TS2304: Cannot find name 'foo'. @@ -6,7 +6,7 @@ tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration class C { *[foo]() { } ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. ~~~ !!! error TS2304: Cannot find name 'foo'. } \ No newline at end of file diff --git a/tests/baselines/reference/MemberFunctionDeclaration7_es6.errors.txt b/tests/baselines/reference/MemberFunctionDeclaration7_es6.errors.txt index ea87da50ed..3eb8f5051a 100644 --- a/tests/baselines/reference/MemberFunctionDeclaration7_es6.errors.txt +++ b/tests/baselines/reference/MemberFunctionDeclaration7_es6.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration7_es6.ts(2,4): error TS9001: Generators are not currently supported. +tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration7_es6.ts(2,4): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. ==== tests/cases/conformance/es6/memberFunctionDeclarations/MemberFunctionDeclaration7_es6.ts (1 errors) ==== class C { *foo() { } ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. } \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression10_es6.errors.txt b/tests/baselines/reference/YieldExpression10_es6.errors.txt index e0d7ea4ad2..99a73c48ba 100644 --- a/tests/baselines/reference/YieldExpression10_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression10_es6.errors.txt @@ -1,14 +1,14 @@ -tests/cases/conformance/es6/yieldExpressions/YieldExpression10_es6.ts(1,11): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/yieldExpressions/YieldExpression10_es6.ts(2,5): error TS9000: 'yield' expressions are not currently supported. +tests/cases/conformance/es6/yieldExpressions/YieldExpression10_es6.ts(1,11): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. +tests/cases/conformance/es6/yieldExpressions/YieldExpression10_es6.ts(2,11): error TS2304: Cannot find name 'foo'. ==== tests/cases/conformance/es6/yieldExpressions/YieldExpression10_es6.ts (2 errors) ==== var v = { * foo() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. yield(foo); - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. + ~~~ +!!! error TS2304: Cannot find name 'foo'. } } \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression11_es6.errors.txt b/tests/baselines/reference/YieldExpression11_es6.errors.txt index 3f322a81f2..c19e8b6cfa 100644 --- a/tests/baselines/reference/YieldExpression11_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression11_es6.errors.txt @@ -1,14 +1,14 @@ -tests/cases/conformance/es6/yieldExpressions/YieldExpression11_es6.ts(2,3): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/yieldExpressions/YieldExpression11_es6.ts(3,5): error TS9000: 'yield' expressions are not currently supported. +tests/cases/conformance/es6/yieldExpressions/YieldExpression11_es6.ts(2,3): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. +tests/cases/conformance/es6/yieldExpressions/YieldExpression11_es6.ts(3,11): error TS2304: Cannot find name 'foo'. ==== tests/cases/conformance/es6/yieldExpressions/YieldExpression11_es6.ts (2 errors) ==== class C { *foo() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. yield(foo); - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. + ~~~ +!!! error TS2304: Cannot find name 'foo'. } } \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression12_es6.errors.txt b/tests/baselines/reference/YieldExpression12_es6.errors.txt index 10843421a3..42d447ed5d 100644 --- a/tests/baselines/reference/YieldExpression12_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression12_es6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/yieldExpressions/YieldExpression12_es6.ts(3,6): error TS1163: 'yield' expression must be contained_within a generator declaration. +tests/cases/conformance/es6/yieldExpressions/YieldExpression12_es6.ts(3,6): error TS1163: A 'yield' expression is only allowed in a generator body. ==== tests/cases/conformance/es6/yieldExpressions/YieldExpression12_es6.ts (1 errors) ==== @@ -6,6 +6,6 @@ tests/cases/conformance/es6/yieldExpressions/YieldExpression12_es6.ts(3,6): erro constructor() { yield foo ~~~~~ -!!! error TS1163: 'yield' expression must be contained_within a generator declaration. +!!! error TS1163: A 'yield' expression is only allowed in a generator body. } } \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression13_es6.errors.txt b/tests/baselines/reference/YieldExpression13_es6.errors.txt index fc2d885d38..3166d742ae 100644 --- a/tests/baselines/reference/YieldExpression13_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression13_es6.errors.txt @@ -1,10 +1,7 @@ -tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts(1,9): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts(1,19): error TS9000: 'yield' expressions are not currently supported. +tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts(1,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. -==== tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts (2 errors) ==== +==== tests/cases/conformance/es6/yieldExpressions/YieldExpression13_es6.ts (1 errors) ==== function* foo() { yield } ~ -!!! error TS9001: Generators are not currently supported. - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. \ No newline at end of file +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression14_es6.errors.txt b/tests/baselines/reference/YieldExpression14_es6.errors.txt index baeaf3ba30..2e32e7a238 100644 --- a/tests/baselines/reference/YieldExpression14_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression14_es6.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/es6/yieldExpressions/YieldExpression14_es6.ts(3,6): error TS1163: 'yield' expression must be contained_within a generator declaration. +tests/cases/conformance/es6/yieldExpressions/YieldExpression14_es6.ts(3,6): error TS1163: A 'yield' expression is only allowed in a generator body. ==== tests/cases/conformance/es6/yieldExpressions/YieldExpression14_es6.ts (1 errors) ==== @@ -6,6 +6,6 @@ tests/cases/conformance/es6/yieldExpressions/YieldExpression14_es6.ts(3,6): erro foo() { yield foo ~~~~~ -!!! error TS1163: 'yield' expression must be contained_within a generator declaration. +!!! error TS1163: A 'yield' expression is only allowed in a generator body. } } \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression15_es6.errors.txt b/tests/baselines/reference/YieldExpression15_es6.errors.txt index 5e548799f5..bb60f6a8f7 100644 --- a/tests/baselines/reference/YieldExpression15_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression15_es6.errors.txt @@ -1,9 +1,9 @@ -tests/cases/conformance/es6/yieldExpressions/YieldExpression15_es6.ts(2,6): error TS1163: 'yield' expression must be contained_within a generator declaration. +tests/cases/conformance/es6/yieldExpressions/YieldExpression15_es6.ts(2,6): error TS1163: A 'yield' expression is only allowed in a generator body. ==== tests/cases/conformance/es6/yieldExpressions/YieldExpression15_es6.ts (1 errors) ==== var v = () => { yield foo ~~~~~ -!!! error TS1163: 'yield' expression must be contained_within a generator declaration. +!!! error TS1163: A 'yield' expression is only allowed in a generator body. } \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression16_es6.errors.txt b/tests/baselines/reference/YieldExpression16_es6.errors.txt index c0d2e4c8fc..e792bc5924 100644 --- a/tests/baselines/reference/YieldExpression16_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression16_es6.errors.txt @@ -1,14 +1,14 @@ -tests/cases/conformance/es6/yieldExpressions/YieldExpression16_es6.ts(1,9): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/yieldExpressions/YieldExpression16_es6.ts(3,5): error TS1163: 'yield' expression must be contained_within a generator declaration. +tests/cases/conformance/es6/yieldExpressions/YieldExpression16_es6.ts(1,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. +tests/cases/conformance/es6/yieldExpressions/YieldExpression16_es6.ts(3,5): error TS1163: A 'yield' expression is only allowed in a generator body. ==== tests/cases/conformance/es6/yieldExpressions/YieldExpression16_es6.ts (2 errors) ==== function* foo() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. function bar() { yield foo; ~~~~~ -!!! error TS1163: 'yield' expression must be contained_within a generator declaration. +!!! error TS1163: A 'yield' expression is only allowed in a generator body. } } \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression17_es6.errors.txt b/tests/baselines/reference/YieldExpression17_es6.errors.txt index b39f47b07f..bc26221252 100644 --- a/tests/baselines/reference/YieldExpression17_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression17_es6.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/es6/yieldExpressions/YieldExpression17_es6.ts(1,15): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/es6/yieldExpressions/YieldExpression17_es6.ts(1,15): error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. -tests/cases/conformance/es6/yieldExpressions/YieldExpression17_es6.ts(1,23): error TS1163: 'yield' expression must be contained_within a generator declaration. +tests/cases/conformance/es6/yieldExpressions/YieldExpression17_es6.ts(1,23): error TS1163: A 'yield' expression is only allowed in a generator body. ==== tests/cases/conformance/es6/yieldExpressions/YieldExpression17_es6.ts (3 errors) ==== @@ -10,4 +10,4 @@ tests/cases/conformance/es6/yieldExpressions/YieldExpression17_es6.ts(1,23): err ~~~ !!! error TS2378: A 'get' accessor must return a value or consist of a single 'throw' statement. ~~~~~ -!!! error TS1163: 'yield' expression must be contained_within a generator declaration. \ No newline at end of file +!!! error TS1163: A 'yield' expression is only allowed in a generator body. \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression18_es6.errors.txt b/tests/baselines/reference/YieldExpression18_es6.errors.txt index 3a67acdebc..056fc0e950 100644 --- a/tests/baselines/reference/YieldExpression18_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression18_es6.errors.txt @@ -1,8 +1,8 @@ -tests/cases/conformance/es6/yieldExpressions/YieldExpression18_es6.ts(2,1): error TS1163: 'yield' expression must be contained_within a generator declaration. +tests/cases/conformance/es6/yieldExpressions/YieldExpression18_es6.ts(2,1): error TS1163: A 'yield' expression is only allowed in a generator body. ==== tests/cases/conformance/es6/yieldExpressions/YieldExpression18_es6.ts (1 errors) ==== "use strict"; yield(foo); ~~~~~ -!!! error TS1163: 'yield' expression must be contained_within a generator declaration. \ No newline at end of file +!!! error TS1163: A 'yield' expression is only allowed in a generator body. \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression19_es6.errors.txt b/tests/baselines/reference/YieldExpression19_es6.errors.txt index 9d04d9559b..02591de78c 100644 --- a/tests/baselines/reference/YieldExpression19_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression19_es6.errors.txt @@ -1,19 +1,16 @@ -tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts(1,9): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts(3,13): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts(4,7): error TS9000: 'yield' expressions are not currently supported. +tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts(1,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. +tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts(3,13): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. -==== tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts (3 errors) ==== +==== tests/cases/conformance/es6/yieldExpressions/YieldExpression19_es6.ts (2 errors) ==== function*foo() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. function bar() { function* quux() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. yield(foo); - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. } } } \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression2_es6.errors.txt b/tests/baselines/reference/YieldExpression2_es6.errors.txt index 553dab51fc..2d1a7082d5 100644 --- a/tests/baselines/reference/YieldExpression2_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression2_es6.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/yieldExpressions/YieldExpression2_es6.ts(1,1): error TS1163: 'yield' expression must be contained_within a generator declaration. +tests/cases/conformance/es6/yieldExpressions/YieldExpression2_es6.ts(1,1): error TS1163: A 'yield' expression is only allowed in a generator body. ==== tests/cases/conformance/es6/yieldExpressions/YieldExpression2_es6.ts (1 errors) ==== yield foo; ~~~~~ -!!! error TS1163: 'yield' expression must be contained_within a generator declaration. \ No newline at end of file +!!! error TS1163: A 'yield' expression is only allowed in a generator body. \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression3_es6.errors.txt b/tests/baselines/reference/YieldExpression3_es6.errors.txt index 1e284c9278..c03a5f1c46 100644 --- a/tests/baselines/reference/YieldExpression3_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression3_es6.errors.txt @@ -1,16 +1,10 @@ -tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts(1,9): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts(2,3): error TS9000: 'yield' expressions are not currently supported. -tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts(3,3): error TS9000: 'yield' expressions are not currently supported. +tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts(1,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. -==== tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts (3 errors) ==== +==== tests/cases/conformance/es6/yieldExpressions/YieldExpression3_es6.ts (1 errors) ==== function* foo() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. yield - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. yield - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. } \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression4_es6.errors.txt b/tests/baselines/reference/YieldExpression4_es6.errors.txt index 2d2a7ca325..cea33eabfa 100644 --- a/tests/baselines/reference/YieldExpression4_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression4_es6.errors.txt @@ -1,16 +1,10 @@ -tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts(1,9): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts(2,3): error TS9000: 'yield' expressions are not currently supported. -tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts(3,3): error TS9000: 'yield' expressions are not currently supported. +tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts(1,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. -==== tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts (3 errors) ==== +==== tests/cases/conformance/es6/yieldExpressions/YieldExpression4_es6.ts (1 errors) ==== function* foo() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. yield; - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. yield; - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. } \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression6_es6.errors.txt b/tests/baselines/reference/YieldExpression6_es6.errors.txt index a3d9481601..fce6583844 100644 --- a/tests/baselines/reference/YieldExpression6_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression6_es6.errors.txt @@ -1,12 +1,12 @@ -tests/cases/conformance/es6/yieldExpressions/YieldExpression6_es6.ts(1,9): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/yieldExpressions/YieldExpression6_es6.ts(2,3): error TS9000: 'yield' expressions are not currently supported. +tests/cases/conformance/es6/yieldExpressions/YieldExpression6_es6.ts(1,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. +tests/cases/conformance/es6/yieldExpressions/YieldExpression6_es6.ts(2,9): error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator. ==== tests/cases/conformance/es6/yieldExpressions/YieldExpression6_es6.ts (2 errors) ==== function* foo() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. yield*foo - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. + ~~~ +!!! error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator. } \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression7_es6.errors.txt b/tests/baselines/reference/YieldExpression7_es6.errors.txt index 393a03ee26..39d085b71f 100644 --- a/tests/baselines/reference/YieldExpression7_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression7_es6.errors.txt @@ -1,12 +1,9 @@ -tests/cases/conformance/es6/yieldExpressions/YieldExpression7_es6.ts(1,9): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/yieldExpressions/YieldExpression7_es6.ts(2,3): error TS9000: 'yield' expressions are not currently supported. +tests/cases/conformance/es6/yieldExpressions/YieldExpression7_es6.ts(1,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. -==== tests/cases/conformance/es6/yieldExpressions/YieldExpression7_es6.ts (2 errors) ==== +==== tests/cases/conformance/es6/yieldExpressions/YieldExpression7_es6.ts (1 errors) ==== function* foo() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. yield foo - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. } \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression8_es6.errors.txt b/tests/baselines/reference/YieldExpression8_es6.errors.txt index 3f7933c5bb..b14fa0872a 100644 --- a/tests/baselines/reference/YieldExpression8_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression8_es6.errors.txt @@ -1,16 +1,13 @@ tests/cases/conformance/es6/yieldExpressions/YieldExpression8_es6.ts(1,1): error TS2304: Cannot find name 'yield'. -tests/cases/conformance/es6/yieldExpressions/YieldExpression8_es6.ts(2,9): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/yieldExpressions/YieldExpression8_es6.ts(3,3): error TS9000: 'yield' expressions are not currently supported. +tests/cases/conformance/es6/yieldExpressions/YieldExpression8_es6.ts(2,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. -==== tests/cases/conformance/es6/yieldExpressions/YieldExpression8_es6.ts (3 errors) ==== +==== tests/cases/conformance/es6/yieldExpressions/YieldExpression8_es6.ts (2 errors) ==== yield(foo); ~~~~~ !!! error TS2304: Cannot find name 'yield'. function* foo() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. yield(foo); - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. } \ No newline at end of file diff --git a/tests/baselines/reference/YieldExpression9_es6.errors.txt b/tests/baselines/reference/YieldExpression9_es6.errors.txt index cd75364732..aceb038320 100644 --- a/tests/baselines/reference/YieldExpression9_es6.errors.txt +++ b/tests/baselines/reference/YieldExpression9_es6.errors.txt @@ -1,12 +1,12 @@ -tests/cases/conformance/es6/yieldExpressions/YieldExpression9_es6.ts(1,17): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/yieldExpressions/YieldExpression9_es6.ts(2,3): error TS9000: 'yield' expressions are not currently supported. +tests/cases/conformance/es6/yieldExpressions/YieldExpression9_es6.ts(1,17): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. +tests/cases/conformance/es6/yieldExpressions/YieldExpression9_es6.ts(2,9): error TS2304: Cannot find name 'foo'. ==== tests/cases/conformance/es6/yieldExpressions/YieldExpression9_es6.ts (2 errors) ==== var v = function*() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. yield(foo); - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. + ~~~ +!!! error TS2304: Cannot find name 'foo'. } \ No newline at end of file diff --git a/tests/baselines/reference/YieldStarExpression1_es6.errors.txt b/tests/baselines/reference/YieldStarExpression1_es6.errors.txt new file mode 100644 index 0000000000..9ba5e44f9a --- /dev/null +++ b/tests/baselines/reference/YieldStarExpression1_es6.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/es6/yieldExpressions/YieldStarExpression1_es6.ts(1,1): error TS2304: Cannot find name 'yield'. +tests/cases/conformance/es6/yieldExpressions/YieldStarExpression1_es6.ts(1,9): error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. + + +==== tests/cases/conformance/es6/yieldExpressions/YieldStarExpression1_es6.ts (2 errors) ==== + yield * []; + ~~~~~ +!!! error TS2304: Cannot find name 'yield'. + ~~ +!!! error TS2363: The right-hand side of an arithmetic operation must be of type 'any', 'number' or an enum type. \ No newline at end of file diff --git a/tests/baselines/reference/YieldStarExpression1_es6.js b/tests/baselines/reference/YieldStarExpression1_es6.js new file mode 100644 index 0000000000..742c5b7d1e --- /dev/null +++ b/tests/baselines/reference/YieldStarExpression1_es6.js @@ -0,0 +1,5 @@ +//// [YieldStarExpression1_es6.ts] +yield * []; + +//// [YieldStarExpression1_es6.js] +yield * []; diff --git a/tests/baselines/reference/YieldStarExpression2_es6.errors.txt b/tests/baselines/reference/YieldStarExpression2_es6.errors.txt new file mode 100644 index 0000000000..3d0c89fd23 --- /dev/null +++ b/tests/baselines/reference/YieldStarExpression2_es6.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/es6/yieldExpressions/YieldStarExpression2_es6.ts(1,1): error TS2304: Cannot find name 'yield'. +tests/cases/conformance/es6/yieldExpressions/YieldStarExpression2_es6.ts(1,8): error TS1109: Expression expected. + + +==== tests/cases/conformance/es6/yieldExpressions/YieldStarExpression2_es6.ts (2 errors) ==== + yield *; + ~~~~~ +!!! error TS2304: Cannot find name 'yield'. + ~ +!!! error TS1109: Expression expected. \ No newline at end of file diff --git a/tests/baselines/reference/YieldStarExpression2_es6.js b/tests/baselines/reference/YieldStarExpression2_es6.js new file mode 100644 index 0000000000..5b40963d9a --- /dev/null +++ b/tests/baselines/reference/YieldStarExpression2_es6.js @@ -0,0 +1,5 @@ +//// [YieldStarExpression2_es6.ts] +yield *; + +//// [YieldStarExpression2_es6.js] +yield * ; diff --git a/tests/baselines/reference/YieldStarExpression3_es6.errors.txt b/tests/baselines/reference/YieldStarExpression3_es6.errors.txt new file mode 100644 index 0000000000..25cecc8044 --- /dev/null +++ b/tests/baselines/reference/YieldStarExpression3_es6.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/es6/yieldExpressions/YieldStarExpression3_es6.ts(2,12): error TS1109: Expression expected. + + +==== tests/cases/conformance/es6/yieldExpressions/YieldStarExpression3_es6.ts (1 errors) ==== + function *g() { + yield *; + ~ +!!! error TS1109: Expression expected. + } \ No newline at end of file diff --git a/tests/baselines/reference/YieldStarExpression3_es6.js b/tests/baselines/reference/YieldStarExpression3_es6.js new file mode 100644 index 0000000000..7463fc01bc --- /dev/null +++ b/tests/baselines/reference/YieldStarExpression3_es6.js @@ -0,0 +1,9 @@ +//// [YieldStarExpression3_es6.ts] +function *g() { + yield *; +} + +//// [YieldStarExpression3_es6.js] +function g() { + yield* ; +} diff --git a/tests/baselines/reference/YieldStarExpression4_es6.errors.txt b/tests/baselines/reference/YieldStarExpression4_es6.errors.txt new file mode 100644 index 0000000000..4935df494d --- /dev/null +++ b/tests/baselines/reference/YieldStarExpression4_es6.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/es6/yieldExpressions/YieldStarExpression4_es6.ts(1,10): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. +tests/cases/conformance/es6/yieldExpressions/YieldStarExpression4_es6.ts(2,13): error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator. + + +==== tests/cases/conformance/es6/yieldExpressions/YieldStarExpression4_es6.ts (2 errors) ==== + function *g() { + ~ +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. + yield * []; + ~~ +!!! error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator. + } \ No newline at end of file diff --git a/tests/baselines/reference/YieldStarExpression4_es6.js b/tests/baselines/reference/YieldStarExpression4_es6.js new file mode 100644 index 0000000000..6283b81cca --- /dev/null +++ b/tests/baselines/reference/YieldStarExpression4_es6.js @@ -0,0 +1,9 @@ +//// [YieldStarExpression4_es6.ts] +function *g() { + yield * []; +} + +//// [YieldStarExpression4_es6.js] +function g() { + yield* []; +} diff --git a/tests/baselines/reference/argumentsObjectIterator01_ES5.errors.txt b/tests/baselines/reference/argumentsObjectIterator01_ES5.errors.txt new file mode 100644 index 0000000000..d607ab65d2 --- /dev/null +++ b/tests/baselines/reference/argumentsObjectIterator01_ES5.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/argumentsObjectIterator01_ES5.ts(4,21): error TS2495: Type 'IArguments' is not an array type or a string type. + + +==== tests/cases/compiler/argumentsObjectIterator01_ES5.ts (1 errors) ==== + + function doubleAndReturnAsArray(x: number, y: number, z: number): [number, number, number] { + let result = []; + for (let arg of arguments) { + ~~~~~~~~~ +!!! error TS2495: Type 'IArguments' is not an array type or a string type. + result.push(arg + arg); + } + return <[any, any, any]>result; + } \ No newline at end of file diff --git a/tests/baselines/reference/argumentsObjectIterator01_ES5.js b/tests/baselines/reference/argumentsObjectIterator01_ES5.js new file mode 100644 index 0000000000..bc51d6f558 --- /dev/null +++ b/tests/baselines/reference/argumentsObjectIterator01_ES5.js @@ -0,0 +1,19 @@ +//// [argumentsObjectIterator01_ES5.ts] + +function doubleAndReturnAsArray(x: number, y: number, z: number): [number, number, number] { + let result = []; + for (let arg of arguments) { + result.push(arg + arg); + } + return <[any, any, any]>result; +} + +//// [argumentsObjectIterator01_ES5.js] +function doubleAndReturnAsArray(x, y, z) { + var result = []; + for (var _i = 0; _i < arguments.length; _i++) { + var arg = arguments[_i]; + result.push(arg + arg); + } + return result; +} diff --git a/tests/baselines/reference/argumentsObjectIterator01_ES6.js b/tests/baselines/reference/argumentsObjectIterator01_ES6.js new file mode 100644 index 0000000000..03744f16b9 --- /dev/null +++ b/tests/baselines/reference/argumentsObjectIterator01_ES6.js @@ -0,0 +1,18 @@ +//// [argumentsObjectIterator01_ES6.ts] + +function doubleAndReturnAsArray(x: number, y: number, z: number): [number, number, number] { + let result = []; + for (let arg of arguments) { + result.push(arg + arg); + } + return <[any, any, any]>result; +} + +//// [argumentsObjectIterator01_ES6.js] +function doubleAndReturnAsArray(x, y, z) { + let result = []; + for (let arg of arguments) { + result.push(arg + arg); + } + return result; +} diff --git a/tests/baselines/reference/argumentsObjectIterator01_ES6.symbols b/tests/baselines/reference/argumentsObjectIterator01_ES6.symbols new file mode 100644 index 0000000000..b4351e579f --- /dev/null +++ b/tests/baselines/reference/argumentsObjectIterator01_ES6.symbols @@ -0,0 +1,25 @@ +=== tests/cases/compiler/argumentsObjectIterator01_ES6.ts === + +function doubleAndReturnAsArray(x: number, y: number, z: number): [number, number, number] { +>doubleAndReturnAsArray : Symbol(doubleAndReturnAsArray, Decl(argumentsObjectIterator01_ES6.ts, 0, 0)) +>x : Symbol(x, Decl(argumentsObjectIterator01_ES6.ts, 1, 32)) +>y : Symbol(y, Decl(argumentsObjectIterator01_ES6.ts, 1, 42)) +>z : Symbol(z, Decl(argumentsObjectIterator01_ES6.ts, 1, 53)) + + let result = []; +>result : Symbol(result, Decl(argumentsObjectIterator01_ES6.ts, 2, 7)) + + for (let arg of arguments) { +>arg : Symbol(arg, Decl(argumentsObjectIterator01_ES6.ts, 3, 12)) +>arguments : Symbol(arguments) + + result.push(arg + arg); +>result.push : Symbol(Array.push, Decl(lib.d.ts, 1016, 29)) +>result : Symbol(result, Decl(argumentsObjectIterator01_ES6.ts, 2, 7)) +>push : Symbol(Array.push, Decl(lib.d.ts, 1016, 29)) +>arg : Symbol(arg, Decl(argumentsObjectIterator01_ES6.ts, 3, 12)) +>arg : Symbol(arg, Decl(argumentsObjectIterator01_ES6.ts, 3, 12)) + } + return <[any, any, any]>result; +>result : Symbol(result, Decl(argumentsObjectIterator01_ES6.ts, 2, 7)) +} diff --git a/tests/baselines/reference/argumentsObjectIterator01_ES6.types b/tests/baselines/reference/argumentsObjectIterator01_ES6.types new file mode 100644 index 0000000000..04e3bfe081 --- /dev/null +++ b/tests/baselines/reference/argumentsObjectIterator01_ES6.types @@ -0,0 +1,29 @@ +=== tests/cases/compiler/argumentsObjectIterator01_ES6.ts === + +function doubleAndReturnAsArray(x: number, y: number, z: number): [number, number, number] { +>doubleAndReturnAsArray : (x: number, y: number, z: number) => [number, number, number] +>x : number +>y : number +>z : number + + let result = []; +>result : any[] +>[] : undefined[] + + for (let arg of arguments) { +>arg : any +>arguments : IArguments + + result.push(arg + arg); +>result.push(arg + arg) : number +>result.push : (...items: any[]) => number +>result : any[] +>push : (...items: any[]) => number +>arg + arg : any +>arg : any +>arg : any + } + return <[any, any, any]>result; +><[any, any, any]>result : [any, any, any] +>result : any[] +} diff --git a/tests/baselines/reference/argumentsObjectIterator02_ES5.errors.txt b/tests/baselines/reference/argumentsObjectIterator02_ES5.errors.txt new file mode 100644 index 0000000000..125f69b90b --- /dev/null +++ b/tests/baselines/reference/argumentsObjectIterator02_ES5.errors.txt @@ -0,0 +1,18 @@ +tests/cases/compiler/argumentsObjectIterator02_ES5.ts(3,26): error TS2304: Cannot find name 'Symbol'. + + +==== tests/cases/compiler/argumentsObjectIterator02_ES5.ts (1 errors) ==== + + function doubleAndReturnAsArray(x: number, y: number, z: number): [number, number, number] { + let blah = arguments[Symbol.iterator]; + ~~~~~~ +!!! error TS2304: Cannot find name 'Symbol'. + + let result = []; + for (let arg of blah()) { + result.push(arg + arg); + } + return <[any, any, any]>result; + } + + \ No newline at end of file diff --git a/tests/baselines/reference/argumentsObjectIterator02_ES5.js b/tests/baselines/reference/argumentsObjectIterator02_ES5.js new file mode 100644 index 0000000000..366bf8de19 --- /dev/null +++ b/tests/baselines/reference/argumentsObjectIterator02_ES5.js @@ -0,0 +1,24 @@ +//// [argumentsObjectIterator02_ES5.ts] + +function doubleAndReturnAsArray(x: number, y: number, z: number): [number, number, number] { + let blah = arguments[Symbol.iterator]; + + let result = []; + for (let arg of blah()) { + result.push(arg + arg); + } + return <[any, any, any]>result; +} + + + +//// [argumentsObjectIterator02_ES5.js] +function doubleAndReturnAsArray(x, y, z) { + var blah = arguments[Symbol.iterator]; + var result = []; + for (var _i = 0, _a = blah(); _i < _a.length; _i++) { + var arg = _a[_i]; + result.push(arg + arg); + } + return result; +} diff --git a/tests/baselines/reference/argumentsObjectIterator02_ES6.js b/tests/baselines/reference/argumentsObjectIterator02_ES6.js new file mode 100644 index 0000000000..9b9415afd2 --- /dev/null +++ b/tests/baselines/reference/argumentsObjectIterator02_ES6.js @@ -0,0 +1,23 @@ +//// [argumentsObjectIterator02_ES6.ts] + +function doubleAndReturnAsArray(x: number, y: number, z: number): [number, number, number] { + let blah = arguments[Symbol.iterator]; + + let result = []; + for (let arg of blah()) { + result.push(arg + arg); + } + return <[any, any, any]>result; +} + + + +//// [argumentsObjectIterator02_ES6.js] +function doubleAndReturnAsArray(x, y, z) { + let blah = arguments[Symbol.iterator]; + let result = []; + for (let arg of blah()) { + result.push(arg + arg); + } + return result; +} diff --git a/tests/baselines/reference/argumentsObjectIterator02_ES6.symbols b/tests/baselines/reference/argumentsObjectIterator02_ES6.symbols new file mode 100644 index 0000000000..9b68573b37 --- /dev/null +++ b/tests/baselines/reference/argumentsObjectIterator02_ES6.symbols @@ -0,0 +1,34 @@ +=== tests/cases/compiler/argumentsObjectIterator02_ES6.ts === + +function doubleAndReturnAsArray(x: number, y: number, z: number): [number, number, number] { +>doubleAndReturnAsArray : Symbol(doubleAndReturnAsArray, Decl(argumentsObjectIterator02_ES6.ts, 0, 0)) +>x : Symbol(x, Decl(argumentsObjectIterator02_ES6.ts, 1, 32)) +>y : Symbol(y, Decl(argumentsObjectIterator02_ES6.ts, 1, 42)) +>z : Symbol(z, Decl(argumentsObjectIterator02_ES6.ts, 1, 53)) + + let blah = arguments[Symbol.iterator]; +>blah : Symbol(blah, Decl(argumentsObjectIterator02_ES6.ts, 2, 7)) +>arguments : Symbol(arguments) +>Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31)) +>Symbol : Symbol(Symbol, Decl(lib.d.ts, 1186, 52), Decl(lib.d.ts, 1292, 11)) +>iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31)) + + let result = []; +>result : Symbol(result, Decl(argumentsObjectIterator02_ES6.ts, 4, 7)) + + for (let arg of blah()) { +>arg : Symbol(arg, Decl(argumentsObjectIterator02_ES6.ts, 5, 12)) +>blah : Symbol(blah, Decl(argumentsObjectIterator02_ES6.ts, 2, 7)) + + result.push(arg + arg); +>result.push : Symbol(Array.push, Decl(lib.d.ts, 1016, 29)) +>result : Symbol(result, Decl(argumentsObjectIterator02_ES6.ts, 4, 7)) +>push : Symbol(Array.push, Decl(lib.d.ts, 1016, 29)) +>arg : Symbol(arg, Decl(argumentsObjectIterator02_ES6.ts, 5, 12)) +>arg : Symbol(arg, Decl(argumentsObjectIterator02_ES6.ts, 5, 12)) + } + return <[any, any, any]>result; +>result : Symbol(result, Decl(argumentsObjectIterator02_ES6.ts, 4, 7)) +} + + diff --git a/tests/baselines/reference/argumentsObjectIterator02_ES6.types b/tests/baselines/reference/argumentsObjectIterator02_ES6.types new file mode 100644 index 0000000000..3812107f3b --- /dev/null +++ b/tests/baselines/reference/argumentsObjectIterator02_ES6.types @@ -0,0 +1,40 @@ +=== tests/cases/compiler/argumentsObjectIterator02_ES6.ts === + +function doubleAndReturnAsArray(x: number, y: number, z: number): [number, number, number] { +>doubleAndReturnAsArray : (x: number, y: number, z: number) => [number, number, number] +>x : number +>y : number +>z : number + + let blah = arguments[Symbol.iterator]; +>blah : () => IterableIterator +>arguments[Symbol.iterator] : () => IterableIterator +>arguments : IArguments +>Symbol.iterator : symbol +>Symbol : SymbolConstructor +>iterator : symbol + + let result = []; +>result : any[] +>[] : undefined[] + + for (let arg of blah()) { +>arg : any +>blah() : IterableIterator +>blah : () => IterableIterator + + result.push(arg + arg); +>result.push(arg + arg) : number +>result.push : (...items: any[]) => number +>result : any[] +>push : (...items: any[]) => number +>arg + arg : any +>arg : any +>arg : any + } + return <[any, any, any]>result; +><[any, any, any]>result : [any, any, any] +>result : any[] +} + + diff --git a/tests/baselines/reference/argumentsObjectIterator03_ES5.errors.txt b/tests/baselines/reference/argumentsObjectIterator03_ES5.errors.txt new file mode 100644 index 0000000000..c39ea23831 --- /dev/null +++ b/tests/baselines/reference/argumentsObjectIterator03_ES5.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/argumentsObjectIterator03_ES5.ts(3,9): error TS2461: Type 'IArguments' is not an array type. + + +==== tests/cases/compiler/argumentsObjectIterator03_ES5.ts (1 errors) ==== + + function asReversedTuple(a: number, b: string, c: boolean): [boolean, string, number] { + let [x, y, z] = arguments; + ~~~~~~~~~ +!!! error TS2461: Type 'IArguments' is not an array type. + + return [z, y, x]; + } + + \ No newline at end of file diff --git a/tests/baselines/reference/argumentsObjectIterator03_ES5.js b/tests/baselines/reference/argumentsObjectIterator03_ES5.js new file mode 100644 index 0000000000..7ea7e7b659 --- /dev/null +++ b/tests/baselines/reference/argumentsObjectIterator03_ES5.js @@ -0,0 +1,15 @@ +//// [argumentsObjectIterator03_ES5.ts] + +function asReversedTuple(a: number, b: string, c: boolean): [boolean, string, number] { + let [x, y, z] = arguments; + + return [z, y, x]; +} + + + +//// [argumentsObjectIterator03_ES5.js] +function asReversedTuple(a, b, c) { + var x = arguments[0], y = arguments[1], z = arguments[2]; + return [z, y, x]; +} diff --git a/tests/baselines/reference/argumentsObjectIterator03_ES6.js b/tests/baselines/reference/argumentsObjectIterator03_ES6.js new file mode 100644 index 0000000000..788887e86e --- /dev/null +++ b/tests/baselines/reference/argumentsObjectIterator03_ES6.js @@ -0,0 +1,15 @@ +//// [argumentsObjectIterator03_ES6.ts] + +function asReversedTuple(a: number, b: string, c: boolean): [boolean, string, number] { + let [x, y, z] = arguments; + + return [z, y, x]; +} + + + +//// [argumentsObjectIterator03_ES6.js] +function asReversedTuple(a, b, c) { + let [x, y, z] = arguments; + return [z, y, x]; +} diff --git a/tests/baselines/reference/argumentsObjectIterator03_ES6.symbols b/tests/baselines/reference/argumentsObjectIterator03_ES6.symbols new file mode 100644 index 0000000000..97677123f3 --- /dev/null +++ b/tests/baselines/reference/argumentsObjectIterator03_ES6.symbols @@ -0,0 +1,21 @@ +=== tests/cases/compiler/argumentsObjectIterator03_ES6.ts === + +function asReversedTuple(a: number, b: string, c: boolean): [boolean, string, number] { +>asReversedTuple : Symbol(asReversedTuple, Decl(argumentsObjectIterator03_ES6.ts, 0, 0)) +>a : Symbol(a, Decl(argumentsObjectIterator03_ES6.ts, 1, 25)) +>b : Symbol(b, Decl(argumentsObjectIterator03_ES6.ts, 1, 35)) +>c : Symbol(c, Decl(argumentsObjectIterator03_ES6.ts, 1, 46)) + + let [x, y, z] = arguments; +>x : Symbol(x, Decl(argumentsObjectIterator03_ES6.ts, 2, 9)) +>y : Symbol(y, Decl(argumentsObjectIterator03_ES6.ts, 2, 11)) +>z : Symbol(z, Decl(argumentsObjectIterator03_ES6.ts, 2, 14)) +>arguments : Symbol(arguments) + + return [z, y, x]; +>z : Symbol(z, Decl(argumentsObjectIterator03_ES6.ts, 2, 14)) +>y : Symbol(y, Decl(argumentsObjectIterator03_ES6.ts, 2, 11)) +>x : Symbol(x, Decl(argumentsObjectIterator03_ES6.ts, 2, 9)) +} + + diff --git a/tests/baselines/reference/argumentsObjectIterator03_ES6.types b/tests/baselines/reference/argumentsObjectIterator03_ES6.types new file mode 100644 index 0000000000..95188dee0c --- /dev/null +++ b/tests/baselines/reference/argumentsObjectIterator03_ES6.types @@ -0,0 +1,22 @@ +=== tests/cases/compiler/argumentsObjectIterator03_ES6.ts === + +function asReversedTuple(a: number, b: string, c: boolean): [boolean, string, number] { +>asReversedTuple : (a: number, b: string, c: boolean) => [boolean, string, number] +>a : number +>b : string +>c : boolean + + let [x, y, z] = arguments; +>x : any +>y : any +>z : any +>arguments : IArguments + + return [z, y, x]; +>[z, y, x] : [any, any, any] +>z : any +>y : any +>x : any +} + + diff --git a/tests/baselines/reference/arrayLiterals2ES6.symbols b/tests/baselines/reference/arrayLiterals2ES6.symbols index 3b435de2e5..d8717c2c6d 100644 --- a/tests/baselines/reference/arrayLiterals2ES6.symbols +++ b/tests/baselines/reference/arrayLiterals2ES6.symbols @@ -79,7 +79,7 @@ interface myArray2 extends Array { } >myArray2 : Symbol(myArray2, Decl(arrayLiterals2ES6.ts, 42, 43)) >Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1439, 1)) >Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) ->String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1538, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1543, 1)) var d0 = [1, true, ...temp, ]; // has type (string|number|boolean)[] >d0 : Symbol(d0, Decl(arrayLiterals2ES6.ts, 44, 3)) diff --git a/tests/baselines/reference/callWithSpread.errors.txt b/tests/baselines/reference/callWithSpread.errors.txt deleted file mode 100644 index a28d4c8b1a..0000000000 --- a/tests/baselines/reference/callWithSpread.errors.txt +++ /dev/null @@ -1,59 +0,0 @@ -tests/cases/conformance/expressions/functionCalls/callWithSpread.ts(52,21): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher. - - -==== tests/cases/conformance/expressions/functionCalls/callWithSpread.ts (1 errors) ==== - interface X { - foo(x: number, y: number, ...z: string[]); - } - - function foo(x: number, y: number, ...z: string[]) { - } - - var a: string[]; - var z: number[]; - var obj: X; - var xa: X[]; - - foo(1, 2, "abc"); - foo(1, 2, ...a); - foo(1, 2, ...a, "abc"); - - obj.foo(1, 2, "abc"); - obj.foo(1, 2, ...a); - obj.foo(1, 2, ...a, "abc"); - - (obj.foo)(1, 2, "abc"); - (obj.foo)(1, 2, ...a); - (obj.foo)(1, 2, ...a, "abc"); - - xa[1].foo(1, 2, "abc"); - xa[1].foo(1, 2, ...a); - xa[1].foo(1, 2, ...a, "abc"); - - (xa[1].foo)(...[1, 2, "abc"]); - - class C { - constructor(x: number, y: number, ...z: string[]) { - this.foo(x, y); - this.foo(x, y, ...z); - } - foo(x: number, y: number, ...z: string[]) { - } - } - - class D extends C { - constructor() { - super(1, 2); - super(1, 2, ...a); - } - foo() { - super.foo(1, 2); - super.foo(1, 2, ...a); - } - } - - // Only supported in when target is ES6 - var c = new C(1, 2, ...a); - ~~~~ -!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 6 and higher. - \ No newline at end of file diff --git a/tests/baselines/reference/callWithSpread.js b/tests/baselines/reference/callWithSpread.js index c9cd5d2adc..d21b4879da 100644 --- a/tests/baselines/reference/callWithSpread.js +++ b/tests/baselines/reference/callWithSpread.js @@ -48,9 +48,6 @@ class D extends C { super.foo(1, 2, ...a); } } - -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); //// [callWithSpread.js] @@ -112,6 +109,4 @@ var D = (function (_super) { }; return D; })(C); -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); var _a, _b, _c; diff --git a/tests/baselines/reference/callWithSpread.symbols b/tests/baselines/reference/callWithSpread.symbols new file mode 100644 index 0000000000..c5ac7fe66b --- /dev/null +++ b/tests/baselines/reference/callWithSpread.symbols @@ -0,0 +1,159 @@ +=== tests/cases/conformance/expressions/functionCalls/callWithSpread.ts === +interface X { +>X : Symbol(X, Decl(callWithSpread.ts, 0, 0)) + + foo(x: number, y: number, ...z: string[]); +>foo : Symbol(foo, Decl(callWithSpread.ts, 0, 13)) +>x : Symbol(x, Decl(callWithSpread.ts, 1, 8)) +>y : Symbol(y, Decl(callWithSpread.ts, 1, 18)) +>z : Symbol(z, Decl(callWithSpread.ts, 1, 29)) +} + +function foo(x: number, y: number, ...z: string[]) { +>foo : Symbol(foo, Decl(callWithSpread.ts, 2, 1)) +>x : Symbol(x, Decl(callWithSpread.ts, 4, 13)) +>y : Symbol(y, Decl(callWithSpread.ts, 4, 23)) +>z : Symbol(z, Decl(callWithSpread.ts, 4, 34)) +} + +var a: string[]; +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +var z: number[]; +>z : Symbol(z, Decl(callWithSpread.ts, 8, 3)) + +var obj: X; +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>X : Symbol(X, Decl(callWithSpread.ts, 0, 0)) + +var xa: X[]; +>xa : Symbol(xa, Decl(callWithSpread.ts, 10, 3)) +>X : Symbol(X, Decl(callWithSpread.ts, 0, 0)) + +foo(1, 2, "abc"); +>foo : Symbol(foo, Decl(callWithSpread.ts, 2, 1)) + +foo(1, 2, ...a); +>foo : Symbol(foo, Decl(callWithSpread.ts, 2, 1)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +foo(1, 2, ...a, "abc"); +>foo : Symbol(foo, Decl(callWithSpread.ts, 2, 1)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +obj.foo(1, 2, "abc"); +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) + +obj.foo(1, 2, ...a); +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +obj.foo(1, 2, ...a, "abc"); +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +(obj.foo)(1, 2, "abc"); +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) + +(obj.foo)(1, 2, ...a); +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +(obj.foo)(1, 2, ...a, "abc"); +>obj.foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>obj : Symbol(obj, Decl(callWithSpread.ts, 9, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +xa[1].foo(1, 2, "abc"); +>xa[1].foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>xa : Symbol(xa, Decl(callWithSpread.ts, 10, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) + +xa[1].foo(1, 2, ...a); +>xa[1].foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>xa : Symbol(xa, Decl(callWithSpread.ts, 10, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +xa[1].foo(1, 2, ...a, "abc"); +>xa[1].foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>xa : Symbol(xa, Decl(callWithSpread.ts, 10, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + +(xa[1].foo)(...[1, 2, "abc"]); +>Function : Symbol(Function, Decl(lib.d.ts, 223, 38), Decl(lib.d.ts, 269, 11)) +>xa[1].foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) +>xa : Symbol(xa, Decl(callWithSpread.ts, 10, 3)) +>foo : Symbol(X.foo, Decl(callWithSpread.ts, 0, 13)) + +class C { +>C : Symbol(C, Decl(callWithSpread.ts, 28, 40)) + + constructor(x: number, y: number, ...z: string[]) { +>x : Symbol(x, Decl(callWithSpread.ts, 31, 16)) +>y : Symbol(y, Decl(callWithSpread.ts, 31, 26)) +>z : Symbol(z, Decl(callWithSpread.ts, 31, 37)) + + this.foo(x, y); +>this.foo : Symbol(foo, Decl(callWithSpread.ts, 34, 5)) +>this : Symbol(C, Decl(callWithSpread.ts, 28, 40)) +>foo : Symbol(foo, Decl(callWithSpread.ts, 34, 5)) +>x : Symbol(x, Decl(callWithSpread.ts, 31, 16)) +>y : Symbol(y, Decl(callWithSpread.ts, 31, 26)) + + this.foo(x, y, ...z); +>this.foo : Symbol(foo, Decl(callWithSpread.ts, 34, 5)) +>this : Symbol(C, Decl(callWithSpread.ts, 28, 40)) +>foo : Symbol(foo, Decl(callWithSpread.ts, 34, 5)) +>x : Symbol(x, Decl(callWithSpread.ts, 31, 16)) +>y : Symbol(y, Decl(callWithSpread.ts, 31, 26)) +>z : Symbol(z, Decl(callWithSpread.ts, 31, 37)) + } + foo(x: number, y: number, ...z: string[]) { +>foo : Symbol(foo, Decl(callWithSpread.ts, 34, 5)) +>x : Symbol(x, Decl(callWithSpread.ts, 35, 8)) +>y : Symbol(y, Decl(callWithSpread.ts, 35, 18)) +>z : Symbol(z, Decl(callWithSpread.ts, 35, 29)) + } +} + +class D extends C { +>D : Symbol(D, Decl(callWithSpread.ts, 37, 1)) +>C : Symbol(C, Decl(callWithSpread.ts, 28, 40)) + + constructor() { + super(1, 2); +>super : Symbol(C, Decl(callWithSpread.ts, 28, 40)) + + super(1, 2, ...a); +>super : Symbol(C, Decl(callWithSpread.ts, 28, 40)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + } + foo() { +>foo : Symbol(foo, Decl(callWithSpread.ts, 43, 5)) + + super.foo(1, 2); +>super.foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) +>super : Symbol(C, Decl(callWithSpread.ts, 28, 40)) +>foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) + + super.foo(1, 2, ...a); +>super.foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) +>super : Symbol(C, Decl(callWithSpread.ts, 28, 40)) +>foo : Symbol(C.foo, Decl(callWithSpread.ts, 34, 5)) +>a : Symbol(a, Decl(callWithSpread.ts, 7, 3)) + } +} + diff --git a/tests/baselines/reference/callWithSpread.types b/tests/baselines/reference/callWithSpread.types new file mode 100644 index 0000000000..f709772720 --- /dev/null +++ b/tests/baselines/reference/callWithSpread.types @@ -0,0 +1,247 @@ +=== tests/cases/conformance/expressions/functionCalls/callWithSpread.ts === +interface X { +>X : X + + foo(x: number, y: number, ...z: string[]); +>foo : (x: number, y: number, ...z: string[]) => any +>x : number +>y : number +>z : string[] +} + +function foo(x: number, y: number, ...z: string[]) { +>foo : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number +>z : string[] +} + +var a: string[]; +>a : string[] + +var z: number[]; +>z : number[] + +var obj: X; +>obj : X +>X : X + +var xa: X[]; +>xa : X[] +>X : X + +foo(1, 2, "abc"); +>foo(1, 2, "abc") : void +>foo : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>"abc" : string + +foo(1, 2, ...a); +>foo(1, 2, ...a) : void +>foo : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] + +foo(1, 2, ...a, "abc"); +>foo(1, 2, ...a, "abc") : void +>foo : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] +>"abc" : string + +obj.foo(1, 2, "abc"); +>obj.foo(1, 2, "abc") : any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"abc" : string + +obj.foo(1, 2, ...a); +>obj.foo(1, 2, ...a) : any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +obj.foo(1, 2, ...a, "abc"); +>obj.foo(1, 2, ...a, "abc") : any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"abc" : string + +(obj.foo)(1, 2, "abc"); +>(obj.foo)(1, 2, "abc") : any +>(obj.foo) : (x: number, y: number, ...z: string[]) => any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"abc" : string + +(obj.foo)(1, 2, ...a); +>(obj.foo)(1, 2, ...a) : any +>(obj.foo) : (x: number, y: number, ...z: string[]) => any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +(obj.foo)(1, 2, ...a, "abc"); +>(obj.foo)(1, 2, ...a, "abc") : any +>(obj.foo) : (x: number, y: number, ...z: string[]) => any +>obj.foo : (x: number, y: number, ...z: string[]) => any +>obj : X +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"abc" : string + +xa[1].foo(1, 2, "abc"); +>xa[1].foo(1, 2, "abc") : any +>xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1] : X +>xa : X[] +>1 : number +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"abc" : string + +xa[1].foo(1, 2, ...a); +>xa[1].foo(1, 2, ...a) : any +>xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1] : X +>xa : X[] +>1 : number +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +xa[1].foo(1, 2, ...a, "abc"); +>xa[1].foo(1, 2, ...a, "abc") : any +>xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1] : X +>xa : X[] +>1 : number +>foo : (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"abc" : string + +(xa[1].foo)(...[1, 2, "abc"]); +>(xa[1].foo)(...[1, 2, "abc"]) : any +>(xa[1].foo) : Function +>xa[1].foo : Function +>Function : Function +>xa[1].foo : (x: number, y: number, ...z: string[]) => any +>xa[1] : X +>xa : X[] +>1 : number +>foo : (x: number, y: number, ...z: string[]) => any +>...[1, 2, "abc"] : string | number +>[1, 2, "abc"] : (string | number)[] +>1 : number +>2 : number +>"abc" : string + +class C { +>C : C + + constructor(x: number, y: number, ...z: string[]) { +>x : number +>y : number +>z : string[] + + this.foo(x, y); +>this.foo(x, y) : void +>this.foo : (x: number, y: number, ...z: string[]) => void +>this : C +>foo : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number + + this.foo(x, y, ...z); +>this.foo(x, y, ...z) : void +>this.foo : (x: number, y: number, ...z: string[]) => void +>this : C +>foo : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number +>...z : string +>z : string[] + } + foo(x: number, y: number, ...z: string[]) { +>foo : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number +>z : string[] + } +} + +class D extends C { +>D : D +>C : C + + constructor() { + super(1, 2); +>super(1, 2) : void +>super : typeof C +>1 : number +>2 : number + + super(1, 2, ...a); +>super(1, 2, ...a) : void +>super : typeof C +>1 : number +>2 : number +>...a : string +>a : string[] + } + foo() { +>foo : () => void + + super.foo(1, 2); +>super.foo(1, 2) : void +>super.foo : (x: number, y: number, ...z: string[]) => void +>super : C +>foo : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number + + super.foo(1, 2, ...a); +>super.foo(1, 2, ...a) : void +>super.foo : (x: number, y: number, ...z: string[]) => void +>super : C +>foo : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] + } +} + diff --git a/tests/baselines/reference/callWithSpreadES6.js b/tests/baselines/reference/callWithSpreadES6.js index d6a915f5f3..11fa8d6edc 100644 --- a/tests/baselines/reference/callWithSpreadES6.js +++ b/tests/baselines/reference/callWithSpreadES6.js @@ -49,9 +49,6 @@ class D extends C { super.foo(1, 2, ...a); } } - -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); //// [callWithSpreadES6.js] @@ -92,5 +89,3 @@ class D extends C { super.foo(1, 2, ...a); } } -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); diff --git a/tests/baselines/reference/callWithSpreadES6.symbols b/tests/baselines/reference/callWithSpreadES6.symbols index 94e0b94b00..008488d0ce 100644 --- a/tests/baselines/reference/callWithSpreadES6.symbols +++ b/tests/baselines/reference/callWithSpreadES6.symbols @@ -158,9 +158,3 @@ class D extends C { } } -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); ->c : Symbol(c, Decl(callWithSpreadES6.ts, 52, 3)) ->C : Symbol(C, Decl(callWithSpreadES6.ts, 29, 40)) ->a : Symbol(a, Decl(callWithSpreadES6.ts, 8, 3)) - diff --git a/tests/baselines/reference/callWithSpreadES6.types b/tests/baselines/reference/callWithSpreadES6.types index 71d3cf9b2d..ba638207e8 100644 --- a/tests/baselines/reference/callWithSpreadES6.types +++ b/tests/baselines/reference/callWithSpreadES6.types @@ -246,13 +246,3 @@ class D extends C { } } -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); ->c : C ->new C(1, 2, ...a) : C ->C : typeof C ->1 : number ->2 : number ->...a : string ->a : string[] - diff --git a/tests/baselines/reference/classDeclarationBlockScoping1.errors.txt b/tests/baselines/reference/classDeclarationBlockScoping1.errors.txt deleted file mode 100644 index 4f15007bb2..0000000000 --- a/tests/baselines/reference/classDeclarationBlockScoping1.errors.txt +++ /dev/null @@ -1,13 +0,0 @@ -tests/cases/compiler/classDeclarationBlockScoping1.ts(5,11): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. - - -==== tests/cases/compiler/classDeclarationBlockScoping1.ts (1 errors) ==== - class C { - } - - { - class C { - ~ -!!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. - } - } \ No newline at end of file diff --git a/tests/baselines/reference/classDeclarationBlockScoping1.symbols b/tests/baselines/reference/classDeclarationBlockScoping1.symbols new file mode 100644 index 0000000000..645d327e25 --- /dev/null +++ b/tests/baselines/reference/classDeclarationBlockScoping1.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/classDeclarationBlockScoping1.ts === +class C { +>C : Symbol(C, Decl(classDeclarationBlockScoping1.ts, 0, 0)) +} + +{ + class C { +>C : Symbol(C, Decl(classDeclarationBlockScoping1.ts, 3, 1)) + } +} diff --git a/tests/baselines/reference/classDeclarationBlockScoping1.types b/tests/baselines/reference/classDeclarationBlockScoping1.types new file mode 100644 index 0000000000..9020ca4a23 --- /dev/null +++ b/tests/baselines/reference/classDeclarationBlockScoping1.types @@ -0,0 +1,10 @@ +=== tests/cases/compiler/classDeclarationBlockScoping1.ts === +class C { +>C : C +} + +{ + class C { +>C : C + } +} diff --git a/tests/baselines/reference/classDeclarationBlockScoping2.errors.txt b/tests/baselines/reference/classDeclarationBlockScoping2.errors.txt deleted file mode 100644 index 2a9885e110..0000000000 --- a/tests/baselines/reference/classDeclarationBlockScoping2.errors.txt +++ /dev/null @@ -1,18 +0,0 @@ -tests/cases/compiler/classDeclarationBlockScoping2.ts(2,11): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. -tests/cases/compiler/classDeclarationBlockScoping2.ts(5,15): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. - - -==== tests/cases/compiler/classDeclarationBlockScoping2.ts (2 errors) ==== - function f() { - class C {} - ~ -!!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. - var c1 = C; - { - class C {} - ~ -!!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. - var c2 = C; - } - return C === c1; - } \ No newline at end of file diff --git a/tests/baselines/reference/classDeclarationBlockScoping2.symbols b/tests/baselines/reference/classDeclarationBlockScoping2.symbols new file mode 100644 index 0000000000..cece47c3ee --- /dev/null +++ b/tests/baselines/reference/classDeclarationBlockScoping2.symbols @@ -0,0 +1,22 @@ +=== tests/cases/compiler/classDeclarationBlockScoping2.ts === +function f() { +>f : Symbol(f, Decl(classDeclarationBlockScoping2.ts, 0, 0)) + + class C {} +>C : Symbol(C, Decl(classDeclarationBlockScoping2.ts, 0, 14)) + + var c1 = C; +>c1 : Symbol(c1, Decl(classDeclarationBlockScoping2.ts, 2, 7)) +>C : Symbol(C, Decl(classDeclarationBlockScoping2.ts, 0, 14)) + { + class C {} +>C : Symbol(C, Decl(classDeclarationBlockScoping2.ts, 3, 5)) + + var c2 = C; +>c2 : Symbol(c2, Decl(classDeclarationBlockScoping2.ts, 5, 11)) +>C : Symbol(C, Decl(classDeclarationBlockScoping2.ts, 3, 5)) + } + return C === c1; +>C : Symbol(C, Decl(classDeclarationBlockScoping2.ts, 0, 14)) +>c1 : Symbol(c1, Decl(classDeclarationBlockScoping2.ts, 2, 7)) +} diff --git a/tests/baselines/reference/classDeclarationBlockScoping2.types b/tests/baselines/reference/classDeclarationBlockScoping2.types new file mode 100644 index 0000000000..0431d4dd2f --- /dev/null +++ b/tests/baselines/reference/classDeclarationBlockScoping2.types @@ -0,0 +1,23 @@ +=== tests/cases/compiler/classDeclarationBlockScoping2.ts === +function f() { +>f : () => boolean + + class C {} +>C : C + + var c1 = C; +>c1 : typeof C +>C : typeof C + { + class C {} +>C : C + + var c2 = C; +>c2 : typeof C +>C : typeof C + } + return C === c1; +>C === c1 : boolean +>C : typeof C +>c1 : typeof C +} diff --git a/tests/baselines/reference/classExpressionTest1.errors.txt b/tests/baselines/reference/classExpressionTest1.errors.txt deleted file mode 100644 index 4d7e1cda63..0000000000 --- a/tests/baselines/reference/classExpressionTest1.errors.txt +++ /dev/null @@ -1,18 +0,0 @@ -tests/cases/compiler/classExpressionTest1.ts(2,11): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. - - -==== tests/cases/compiler/classExpressionTest1.ts (1 errors) ==== - function M() { - class C { - ~ -!!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. - f() { - var t: T; - var x: X; - return { t, x }; - } - } - - var v = new C(); - return v.f(); - } \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionTest1.symbols b/tests/baselines/reference/classExpressionTest1.symbols new file mode 100644 index 0000000000..684ee30289 --- /dev/null +++ b/tests/baselines/reference/classExpressionTest1.symbols @@ -0,0 +1,35 @@ +=== tests/cases/compiler/classExpressionTest1.ts === +function M() { +>M : Symbol(M, Decl(classExpressionTest1.ts, 0, 0)) + + class C { +>C : Symbol(C, Decl(classExpressionTest1.ts, 0, 14)) +>X : Symbol(X, Decl(classExpressionTest1.ts, 1, 12)) + + f() { +>f : Symbol(f, Decl(classExpressionTest1.ts, 1, 16)) +>T : Symbol(T, Decl(classExpressionTest1.ts, 2, 10)) + + var t: T; +>t : Symbol(t, Decl(classExpressionTest1.ts, 3, 15)) +>T : Symbol(T, Decl(classExpressionTest1.ts, 2, 10)) + + var x: X; +>x : Symbol(x, Decl(classExpressionTest1.ts, 4, 15)) +>X : Symbol(X, Decl(classExpressionTest1.ts, 1, 12)) + + return { t, x }; +>t : Symbol(t, Decl(classExpressionTest1.ts, 5, 20)) +>x : Symbol(x, Decl(classExpressionTest1.ts, 5, 23)) + } + } + + var v = new C(); +>v : Symbol(v, Decl(classExpressionTest1.ts, 9, 7)) +>C : Symbol(C, Decl(classExpressionTest1.ts, 0, 14)) + + return v.f(); +>v.f : Symbol(C.f, Decl(classExpressionTest1.ts, 1, 16)) +>v : Symbol(v, Decl(classExpressionTest1.ts, 9, 7)) +>f : Symbol(C.f, Decl(classExpressionTest1.ts, 1, 16)) +} diff --git a/tests/baselines/reference/classExpressionTest1.types b/tests/baselines/reference/classExpressionTest1.types new file mode 100644 index 0000000000..bf1ae0f2f7 --- /dev/null +++ b/tests/baselines/reference/classExpressionTest1.types @@ -0,0 +1,38 @@ +=== tests/cases/compiler/classExpressionTest1.ts === +function M() { +>M : () => { t: string; x: number; } + + class C { +>C : C +>X : X + + f() { +>f : () => { t: T; x: X; } +>T : T + + var t: T; +>t : T +>T : T + + var x: X; +>x : X +>X : X + + return { t, x }; +>{ t, x } : { t: T; x: X; } +>t : T +>x : X + } + } + + var v = new C(); +>v : C +>new C() : C +>C : typeof C + + return v.f(); +>v.f() : { t: string; x: number; } +>v.f : () => { t: T; x: number; } +>v : C +>f : () => { t: T; x: number; } +} diff --git a/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.errors.txt b/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.errors.txt new file mode 100644 index 0000000000..8edc1d8f74 --- /dev/null +++ b/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.errors.txt @@ -0,0 +1,14 @@ +tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts(6,15): error TS9003: 'class' expressions are not currently supported. + + +==== tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts (1 errors) ==== + namespace C { + export interface type { + } + } + + var x = class C { + ~ +!!! error TS9003: 'class' expressions are not currently supported. + prop: C.type; + } \ No newline at end of file diff --git a/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.js b/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.js new file mode 100644 index 0000000000..7c9f25cdfe --- /dev/null +++ b/tests/baselines/reference/classExpressionWithResolutionOfNamespaceOfSameName01.js @@ -0,0 +1,16 @@ +//// [classExpressionWithResolutionOfNamespaceOfSameName01.ts] +namespace C { + export interface type { + } +} + +var x = class C { + prop: C.type; +} + +//// [classExpressionWithResolutionOfNamespaceOfSameName01.js] +var x = (function () { + function C() { + } + return C; +})(); diff --git a/tests/baselines/reference/classInsideBlock.errors.txt b/tests/baselines/reference/classInsideBlock.errors.txt deleted file mode 100644 index 369e77735e..0000000000 --- a/tests/baselines/reference/classInsideBlock.errors.txt +++ /dev/null @@ -1,9 +0,0 @@ -tests/cases/conformance/classes/classDeclarations/classInsideBlock.ts(2,11): error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. - - -==== tests/cases/conformance/classes/classDeclarations/classInsideBlock.ts (1 errors) ==== - function foo() { - class C { } - ~ -!!! error TS9004: 'class' declarations are only supported directly inside a module or as a top level declaration. - } \ No newline at end of file diff --git a/tests/baselines/reference/classInsideBlock.symbols b/tests/baselines/reference/classInsideBlock.symbols new file mode 100644 index 0000000000..5f96dd1b75 --- /dev/null +++ b/tests/baselines/reference/classInsideBlock.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/classes/classDeclarations/classInsideBlock.ts === +function foo() { +>foo : Symbol(foo, Decl(classInsideBlock.ts, 0, 0)) + + class C { } +>C : Symbol(C, Decl(classInsideBlock.ts, 0, 16)) +} diff --git a/tests/baselines/reference/classInsideBlock.types b/tests/baselines/reference/classInsideBlock.types new file mode 100644 index 0000000000..7db5653c47 --- /dev/null +++ b/tests/baselines/reference/classInsideBlock.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/classes/classDeclarations/classInsideBlock.ts === +function foo() { +>foo : () => void + + class C { } +>C : C +} diff --git a/tests/baselines/reference/commentsBeforeVariableStatement1.js b/tests/baselines/reference/commentsBeforeVariableStatement1.js index 1413f8bc41..c82909f8cd 100644 --- a/tests/baselines/reference/commentsBeforeVariableStatement1.js +++ b/tests/baselines/reference/commentsBeforeVariableStatement1.js @@ -5,5 +5,4 @@ export var b: number; //// [commentsBeforeVariableStatement1.js] define(["require", "exports"], function (require, exports) { - /** b's comment*/ }); diff --git a/tests/baselines/reference/commentsExternalModules.js b/tests/baselines/reference/commentsExternalModules.js index 47f24f5357..c982e66bf7 100644 --- a/tests/baselines/reference/commentsExternalModules.js +++ b/tests/baselines/reference/commentsExternalModules.js @@ -66,7 +66,6 @@ define(["require", "exports"], function (require, exports) { /** Module comment*/ var m1; (function (m1) { - /** b's comment*/ /** foo's comment*/ function foo() { return m1.b; @@ -96,7 +95,6 @@ define(["require", "exports"], function (require, exports) { /** Module comment */ var m4; (function (m4) { - /** b's comment */ /** foo's comment */ function foo() { diff --git a/tests/baselines/reference/commentsExternalModules2.js b/tests/baselines/reference/commentsExternalModules2.js index 179d3f9f88..2c8b811d75 100644 --- a/tests/baselines/reference/commentsExternalModules2.js +++ b/tests/baselines/reference/commentsExternalModules2.js @@ -66,7 +66,6 @@ define(["require", "exports"], function (require, exports) { /** Module comment*/ var m1; (function (m1) { - /** b's comment*/ /** foo's comment*/ function foo() { return m1.b; @@ -96,7 +95,6 @@ define(["require", "exports"], function (require, exports) { /** Module comment */ var m4; (function (m4) { - /** b's comment */ /** foo's comment */ function foo() { diff --git a/tests/baselines/reference/commentsExternalModules3.js b/tests/baselines/reference/commentsExternalModules3.js index 2572a153a1..283e07ebc7 100644 --- a/tests/baselines/reference/commentsExternalModules3.js +++ b/tests/baselines/reference/commentsExternalModules3.js @@ -65,7 +65,6 @@ export var newVar2 = new extMod.m4.m2.c(); /** Module comment*/ var m1; (function (m1) { - /** b's comment*/ /** foo's comment*/ function foo() { return m1.b; @@ -95,7 +94,6 @@ var myvar = new m1.m2.c(); /** Module comment */ var m4; (function (m4) { - /** b's comment */ /** foo's comment */ function foo() { diff --git a/tests/baselines/reference/commentsModules.js b/tests/baselines/reference/commentsModules.js index 4406e609ea..aa5cd2fb7f 100644 --- a/tests/baselines/reference/commentsModules.js +++ b/tests/baselines/reference/commentsModules.js @@ -101,7 +101,6 @@ new m7.m8.m9.c(); /** Module comment*/ var m1; (function (m1) { - /** b's comment*/ /** foo's comment*/ function foo() { return m1.b; diff --git a/tests/baselines/reference/cyclicGenericTypeInstantiation.js b/tests/baselines/reference/cyclicGenericTypeInstantiation.js new file mode 100644 index 0000000000..10f52e10d8 --- /dev/null +++ b/tests/baselines/reference/cyclicGenericTypeInstantiation.js @@ -0,0 +1,37 @@ +//// [cyclicGenericTypeInstantiation.ts] +function foo() { + var z = foo(); + var y: { + y2: typeof z + }; + return y; +} + + +function bar() { + var z = bar(); + var y: { + y2: typeof z; + } + return y; +} + +var a = foo(); +var b = bar(); +a = b; + + +//// [cyclicGenericTypeInstantiation.js] +function foo() { + var z = foo(); + var y; + return y; +} +function bar() { + var z = bar(); + var y; + return y; +} +var a = foo(); +var b = bar(); +a = b; diff --git a/tests/baselines/reference/cyclicGenericTypeInstantiation.symbols b/tests/baselines/reference/cyclicGenericTypeInstantiation.symbols new file mode 100644 index 0000000000..a6566b8683 --- /dev/null +++ b/tests/baselines/reference/cyclicGenericTypeInstantiation.symbols @@ -0,0 +1,55 @@ +=== tests/cases/compiler/cyclicGenericTypeInstantiation.ts === +function foo() { +>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0)) +>T : Symbol(T, Decl(cyclicGenericTypeInstantiation.ts, 0, 13)) + + var z = foo(); +>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 1, 7)) +>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0)) +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7)) + + var y: { +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7)) + + y2: typeof z +>y2 : Symbol(y2, Decl(cyclicGenericTypeInstantiation.ts, 2, 12)) +>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 1, 7)) + + }; + return y; +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 2, 7)) +} + + +function bar() { +>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1)) +>T : Symbol(T, Decl(cyclicGenericTypeInstantiation.ts, 9, 13)) + + var z = bar(); +>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 10, 7)) +>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1)) +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7)) + + var y: { +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7)) + + y2: typeof z; +>y2 : Symbol(y2, Decl(cyclicGenericTypeInstantiation.ts, 11, 12)) +>z : Symbol(z, Decl(cyclicGenericTypeInstantiation.ts, 10, 7)) + } + return y; +>y : Symbol(y, Decl(cyclicGenericTypeInstantiation.ts, 11, 7)) +} + +var a = foo(); +>a : Symbol(a, Decl(cyclicGenericTypeInstantiation.ts, 17, 3)) +>foo : Symbol(foo, Decl(cyclicGenericTypeInstantiation.ts, 0, 0)) + +var b = bar(); +>b : Symbol(b, Decl(cyclicGenericTypeInstantiation.ts, 18, 3)) +>bar : Symbol(bar, Decl(cyclicGenericTypeInstantiation.ts, 6, 1)) + +a = b; +>a : Symbol(a, Decl(cyclicGenericTypeInstantiation.ts, 17, 3)) +>b : Symbol(b, Decl(cyclicGenericTypeInstantiation.ts, 18, 3)) + diff --git a/tests/baselines/reference/cyclicGenericTypeInstantiation.types b/tests/baselines/reference/cyclicGenericTypeInstantiation.types new file mode 100644 index 0000000000..69b0955b22 --- /dev/null +++ b/tests/baselines/reference/cyclicGenericTypeInstantiation.types @@ -0,0 +1,60 @@ +=== tests/cases/compiler/cyclicGenericTypeInstantiation.ts === +function foo() { +>foo : () => { y2: any; } +>T : T + + var z = foo(); +>z : { y2: any; } +>foo() : { y2: any; } +>foo : () => { y2: any; } +>y : { y2: any; } + + var y: { +>y : { y2: any; } + + y2: typeof z +>y2 : { y2: any; } +>z : { y2: any; } + + }; + return y; +>y : { y2: any; } +} + + +function bar() { +>bar : () => { y2: any; } +>T : T + + var z = bar(); +>z : { y2: any; } +>bar() : { y2: any; } +>bar : () => { y2: any; } +>y : { y2: any; } + + var y: { +>y : { y2: any; } + + y2: typeof z; +>y2 : { y2: any; } +>z : { y2: any; } + } + return y; +>y : { y2: any; } +} + +var a = foo(); +>a : { y2: any; } +>foo() : { y2: any; } +>foo : () => { y2: any; } + +var b = bar(); +>b : { y2: any; } +>bar() : { y2: any; } +>bar : () => { y2: any; } + +a = b; +>a = b : { y2: any; } +>a : { y2: any; } +>b : { y2: any; } + diff --git a/tests/baselines/reference/cyclicTypeInstantiation.js b/tests/baselines/reference/cyclicTypeInstantiation.js new file mode 100644 index 0000000000..087eb00241 --- /dev/null +++ b/tests/baselines/reference/cyclicTypeInstantiation.js @@ -0,0 +1,36 @@ +//// [cyclicTypeInstantiation.ts] +function foo() { + var x: { + a: T; + b: typeof x; + }; + return x; +} + +function bar() { + var x: { + a: T; + b: typeof x; + }; + return x; +} + +var a = foo(); +var b = bar(); +// Relating types of a and b produces instantiations of the cyclic anonymous types in foo and bar +a = b; + + +//// [cyclicTypeInstantiation.js] +function foo() { + var x; + return x; +} +function bar() { + var x; + return x; +} +var a = foo(); +var b = bar(); +// Relating types of a and b produces instantiations of the cyclic anonymous types in foo and bar +a = b; diff --git a/tests/baselines/reference/cyclicTypeInstantiation.symbols b/tests/baselines/reference/cyclicTypeInstantiation.symbols new file mode 100644 index 0000000000..74e59da188 --- /dev/null +++ b/tests/baselines/reference/cyclicTypeInstantiation.symbols @@ -0,0 +1,54 @@ +=== tests/cases/compiler/cyclicTypeInstantiation.ts === +function foo() { +>foo : Symbol(foo, Decl(cyclicTypeInstantiation.ts, 0, 0)) +>T : Symbol(T, Decl(cyclicTypeInstantiation.ts, 0, 13)) + + var x: { +>x : Symbol(x, Decl(cyclicTypeInstantiation.ts, 1, 7)) + + a: T; +>a : Symbol(a, Decl(cyclicTypeInstantiation.ts, 1, 12)) +>T : Symbol(T, Decl(cyclicTypeInstantiation.ts, 0, 13)) + + b: typeof x; +>b : Symbol(b, Decl(cyclicTypeInstantiation.ts, 2, 13)) +>x : Symbol(x, Decl(cyclicTypeInstantiation.ts, 1, 7)) + + }; + return x; +>x : Symbol(x, Decl(cyclicTypeInstantiation.ts, 1, 7)) +} + +function bar() { +>bar : Symbol(bar, Decl(cyclicTypeInstantiation.ts, 6, 1)) +>T : Symbol(T, Decl(cyclicTypeInstantiation.ts, 8, 13)) + + var x: { +>x : Symbol(x, Decl(cyclicTypeInstantiation.ts, 9, 7)) + + a: T; +>a : Symbol(a, Decl(cyclicTypeInstantiation.ts, 9, 12)) +>T : Symbol(T, Decl(cyclicTypeInstantiation.ts, 8, 13)) + + b: typeof x; +>b : Symbol(b, Decl(cyclicTypeInstantiation.ts, 10, 13)) +>x : Symbol(x, Decl(cyclicTypeInstantiation.ts, 9, 7)) + + }; + return x; +>x : Symbol(x, Decl(cyclicTypeInstantiation.ts, 9, 7)) +} + +var a = foo(); +>a : Symbol(a, Decl(cyclicTypeInstantiation.ts, 16, 3)) +>foo : Symbol(foo, Decl(cyclicTypeInstantiation.ts, 0, 0)) + +var b = bar(); +>b : Symbol(b, Decl(cyclicTypeInstantiation.ts, 17, 3)) +>bar : Symbol(bar, Decl(cyclicTypeInstantiation.ts, 6, 1)) + +// Relating types of a and b produces instantiations of the cyclic anonymous types in foo and bar +a = b; +>a : Symbol(a, Decl(cyclicTypeInstantiation.ts, 16, 3)) +>b : Symbol(b, Decl(cyclicTypeInstantiation.ts, 17, 3)) + diff --git a/tests/baselines/reference/cyclicTypeInstantiation.types b/tests/baselines/reference/cyclicTypeInstantiation.types new file mode 100644 index 0000000000..c3a39fc90a --- /dev/null +++ b/tests/baselines/reference/cyclicTypeInstantiation.types @@ -0,0 +1,57 @@ +=== tests/cases/compiler/cyclicTypeInstantiation.ts === +function foo() { +>foo : () => { a: T; b: any; } +>T : T + + var x: { +>x : { a: T; b: any; } + + a: T; +>a : T +>T : T + + b: typeof x; +>b : { a: T; b: any; } +>x : { a: T; b: any; } + + }; + return x; +>x : { a: T; b: any; } +} + +function bar() { +>bar : () => { a: T; b: any; } +>T : T + + var x: { +>x : { a: T; b: any; } + + a: T; +>a : T +>T : T + + b: typeof x; +>b : { a: T; b: any; } +>x : { a: T; b: any; } + + }; + return x; +>x : { a: T; b: any; } +} + +var a = foo(); +>a : { a: string; b: any; } +>foo() : { a: string; b: any; } +>foo : () => { a: T; b: any; } + +var b = bar(); +>b : { a: string; b: any; } +>bar() : { a: string; b: any; } +>bar : () => { a: T; b: any; } + +// Relating types of a and b produces instantiations of the cyclic anonymous types in foo and bar +a = b; +>a = b : { a: string; b: any; } +>a : { a: string; b: any; } +>b : { a: string; b: any; } + diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeAlias.js b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeAlias.js index 4210cc1392..ebad715661 100644 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeAlias.js +++ b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeAlias.js @@ -52,7 +52,6 @@ var M; return Window; })(); N.Window = Window; - // Should report error that W is private })(N = M.N || (M.N = {})); })(M || (M = {})); var M1; @@ -65,7 +64,6 @@ var M1; return Window; })(); N.Window = Window; - // No error })(N = M1.N || (M1.N = {})); })(M1 || (M1 = {})); var M2; diff --git a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.js b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.js index 959d82917f..19bdce50cd 100644 --- a/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.js +++ b/tests/baselines/reference/declFileTypeAnnotationVisibilityErrorTypeLiteral.js @@ -59,8 +59,6 @@ var m; } }; m.x3 = m.x; - // Function type m.y2 = m.y; - // constructor type m.z2 = m.z; })(m || (m = {})); diff --git a/tests/baselines/reference/declarationEmit_nameConflicts3.js b/tests/baselines/reference/declarationEmit_nameConflicts3.js index db5a0a05cf..ee21d9a408 100644 --- a/tests/baselines/reference/declarationEmit_nameConflicts3.js +++ b/tests/baselines/reference/declarationEmit_nameConflicts3.js @@ -74,7 +74,6 @@ var M; D[D["f"] = 0] = "f"; })(P.D || (P.D = {})); var D = P.D; - // ok P.w = M.D.f; // error, should be typeof M.D.f P.x = M.C.f; // error, should be typeof M.C.f P.x = M.E.f; // error, should be typeof M.E.f diff --git a/tests/baselines/reference/declarationEmit_nameConflictsWithAlias.js b/tests/baselines/reference/declarationEmit_nameConflictsWithAlias.js index 55535e9ec2..e553229194 100644 --- a/tests/baselines/reference/declarationEmit_nameConflictsWithAlias.js +++ b/tests/baselines/reference/declarationEmit_nameConflictsWithAlias.js @@ -9,7 +9,6 @@ export module M { //// [declarationEmit_nameConflictsWithAlias.js] var M; (function (M) { - // Gets emitted as C.I, which is the wrong interface })(M = exports.M || (exports.M = {})); diff --git a/tests/baselines/reference/declareModifierOnTypeAlias.js b/tests/baselines/reference/declareModifierOnTypeAlias.js new file mode 100644 index 0000000000..a9bb3c6363 --- /dev/null +++ b/tests/baselines/reference/declareModifierOnTypeAlias.js @@ -0,0 +1,6 @@ +//// [declareModifierOnTypeAlias.ts] +declare type Foo = string; +type Bar = number; +declare type Baz = Bar; + +//// [declareModifierOnTypeAlias.js] diff --git a/tests/baselines/reference/declareModifierOnTypeAlias.symbols b/tests/baselines/reference/declareModifierOnTypeAlias.symbols new file mode 100644 index 0000000000..32a90fc94d --- /dev/null +++ b/tests/baselines/reference/declareModifierOnTypeAlias.symbols @@ -0,0 +1,11 @@ +=== tests/cases/compiler/declareModifierOnTypeAlias.ts === +declare type Foo = string; +>Foo : Symbol(Foo, Decl(declareModifierOnTypeAlias.ts, 0, 0)) + +type Bar = number; +>Bar : Symbol(Bar, Decl(declareModifierOnTypeAlias.ts, 0, 26)) + +declare type Baz = Bar; +>Baz : Symbol(Baz, Decl(declareModifierOnTypeAlias.ts, 1, 18)) +>Bar : Symbol(Bar, Decl(declareModifierOnTypeAlias.ts, 0, 26)) + diff --git a/tests/baselines/reference/declareModifierOnTypeAlias.types b/tests/baselines/reference/declareModifierOnTypeAlias.types new file mode 100644 index 0000000000..c53616fdff --- /dev/null +++ b/tests/baselines/reference/declareModifierOnTypeAlias.types @@ -0,0 +1,11 @@ +=== tests/cases/compiler/declareModifierOnTypeAlias.ts === +declare type Foo = string; +>Foo : string + +type Bar = number; +>Bar : number + +declare type Baz = Bar; +>Baz : number +>Bar : number + diff --git a/tests/baselines/reference/decoratorChecksFunctionBodies.errors.txt b/tests/baselines/reference/decoratorChecksFunctionBodies.errors.txt new file mode 100644 index 0000000000..c8166b538f --- /dev/null +++ b/tests/baselines/reference/decoratorChecksFunctionBodies.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts(9,14): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. + + +==== tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts (1 errors) ==== + + // from #2971 + function func(s: string): void { + } + + class A { + @(x => { + var a = 3; + func(a); + ~ +!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'. + return x; + }) + m() { + + } + } \ No newline at end of file diff --git a/tests/baselines/reference/decoratorChecksFunctionBodies.js b/tests/baselines/reference/decoratorChecksFunctionBodies.js new file mode 100644 index 0000000000..020bc775ae --- /dev/null +++ b/tests/baselines/reference/decoratorChecksFunctionBodies.js @@ -0,0 +1,44 @@ +//// [decoratorChecksFunctionBodies.ts] + +// from #2971 +function func(s: string): void { +} + +class A { + @(x => { + var a = 3; + func(a); + return x; + }) + m() { + + } +} + +//// [decoratorChecksFunctionBodies.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); + switch (arguments.length) { + case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); + case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); + case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); + } +}; +// from #2971 +function func(s) { +} +var A = (function () { + function A() { + } + A.prototype.m = function () { + }; + Object.defineProperty(A.prototype, "m", + __decorate([ + (function (x) { + var a = 3; + func(a); + return x; + }) + ], A.prototype, "m", Object.getOwnPropertyDescriptor(A.prototype, "m"))); + return A; +})(); diff --git a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js new file mode 100644 index 0000000000..313d77fa5c --- /dev/null +++ b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.js @@ -0,0 +1,53 @@ +//// [tests/cases/conformance/decorators/class/decoratorInstantiateModulesInFunctionBodies.ts] //// + +//// [a.ts] + +// from #3108 +export var test = 'abc'; + +//// [b.ts] +import { test } from './a'; + +function filter(handler: any) { + return function (target: any) { + // ... + }; +} + +class Wat { + @filter(() => test == 'abc') + static whatever() { + // ... + } +} + +//// [a.js] +// from #3108 +exports.test = 'abc'; +//// [b.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); + switch (arguments.length) { + case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); + case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); + case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); + } +}; +var a_1 = require('./a'); +function filter(handler) { + return function (target) { + // ... + }; +} +var Wat = (function () { + function Wat() { + } + Wat.whatever = function () { + // ... + }; + Object.defineProperty(Wat, "whatever", + __decorate([ + filter(function () { return a_1.test == 'abc'; }) + ], Wat, "whatever", Object.getOwnPropertyDescriptor(Wat, "whatever"))); + return Wat; +})(); diff --git a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.symbols b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.symbols new file mode 100644 index 0000000000..5088e740a5 --- /dev/null +++ b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.symbols @@ -0,0 +1,34 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +// from #3108 +export var test = 'abc'; +>test : Symbol(test, Decl(a.ts, 2, 10)) + +=== tests/cases/conformance/decorators/class/b.ts === +import { test } from './a'; +>test : Symbol(test, Decl(b.ts, 0, 8)) + +function filter(handler: any) { +>filter : Symbol(filter, Decl(b.ts, 0, 27)) +>handler : Symbol(handler, Decl(b.ts, 2, 16)) + + return function (target: any) { +>target : Symbol(target, Decl(b.ts, 3, 21)) + + // ... + }; +} + +class Wat { +>Wat : Symbol(Wat, Decl(b.ts, 6, 1)) + + @filter(() => test == 'abc') +>filter : Symbol(filter, Decl(b.ts, 0, 27)) +>test : Symbol(test, Decl(b.ts, 0, 8)) + + static whatever() { +>whatever : Symbol(Wat.whatever, Decl(b.ts, 8, 11)) + + // ... + } +} diff --git a/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.types b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.types new file mode 100644 index 0000000000..18d993af9b --- /dev/null +++ b/tests/baselines/reference/decoratorInstantiateModulesInFunctionBodies.types @@ -0,0 +1,40 @@ +=== tests/cases/conformance/decorators/class/a.ts === + +// from #3108 +export var test = 'abc'; +>test : string +>'abc' : string + +=== tests/cases/conformance/decorators/class/b.ts === +import { test } from './a'; +>test : string + +function filter(handler: any) { +>filter : (handler: any) => (target: any) => void +>handler : any + + return function (target: any) { +>function (target: any) { // ... } : (target: any) => void +>target : any + + // ... + }; +} + +class Wat { +>Wat : Wat + + @filter(() => test == 'abc') +>filter(() => test == 'abc') : (target: any) => void +>filter : (handler: any) => (target: any) => void +>() => test == 'abc' : () => boolean +>test == 'abc' : boolean +>test : string +>'abc' : string + + static whatever() { +>whatever : () => void + + // ... + } +} diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES5.symbols b/tests/baselines/reference/destructuringParameterDeclaration3ES5.symbols index 033ad46ece..6af2560504 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES5.symbols +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES5.symbols @@ -9,17 +9,17 @@ type arrayString = Array >arrayString : Symbol(arrayString, Decl(destructuringParameterDeclaration3ES5.ts, 0, 0)) >Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1439, 1)) ->String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1538, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1543, 1)) type someArray = Array | number[]; >someArray : Symbol(someArray, Decl(destructuringParameterDeclaration3ES5.ts, 7, 32)) >Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1439, 1)) ->String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1538, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1543, 1)) type stringOrNumArray = Array; >stringOrNumArray : Symbol(stringOrNumArray, Decl(destructuringParameterDeclaration3ES5.ts, 8, 42)) >Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1439, 1)) ->String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1538, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1543, 1)) >Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) function a1(...x: (number|string)[]) { } @@ -34,7 +34,7 @@ function a3(...a: Array) { } >a3 : Symbol(a3, Decl(destructuringParameterDeclaration3ES5.ts, 12, 21)) >a : Symbol(a, Decl(destructuringParameterDeclaration3ES5.ts, 13, 12)) >Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1439, 1)) ->String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1538, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1543, 1)) function a4(...a: arrayString) { } >a4 : Symbol(a4, Decl(destructuringParameterDeclaration3ES5.ts, 13, 36)) diff --git a/tests/baselines/reference/destructuringParameterDeclaration3ES6.symbols b/tests/baselines/reference/destructuringParameterDeclaration3ES6.symbols index d23b624a02..84c21ff77e 100644 --- a/tests/baselines/reference/destructuringParameterDeclaration3ES6.symbols +++ b/tests/baselines/reference/destructuringParameterDeclaration3ES6.symbols @@ -9,17 +9,17 @@ type arrayString = Array >arrayString : Symbol(arrayString, Decl(destructuringParameterDeclaration3ES6.ts, 0, 0)) >Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1439, 1)) ->String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1538, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1543, 1)) type someArray = Array | number[]; >someArray : Symbol(someArray, Decl(destructuringParameterDeclaration3ES6.ts, 7, 32)) >Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1439, 1)) ->String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1538, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1543, 1)) type stringOrNumArray = Array; >stringOrNumArray : Symbol(stringOrNumArray, Decl(destructuringParameterDeclaration3ES6.ts, 8, 42)) >Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1439, 1)) ->String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1538, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1543, 1)) >Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) function a1(...x: (number|string)[]) { } @@ -34,7 +34,7 @@ function a3(...a: Array) { } >a3 : Symbol(a3, Decl(destructuringParameterDeclaration3ES6.ts, 12, 21)) >a : Symbol(a, Decl(destructuringParameterDeclaration3ES6.ts, 13, 12)) >Array : Symbol(Array, Decl(lib.d.ts, 1000, 23), Decl(lib.d.ts, 1171, 11), Decl(lib.d.ts, 1439, 1)) ->String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1538, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1543, 1)) function a4(...a: arrayString) { } >a4 : Symbol(a4, Decl(destructuringParameterDeclaration3ES6.ts, 13, 36)) diff --git a/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.js b/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.js index 170740458d..944ef4e3d5 100644 --- a/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.js +++ b/tests/baselines/reference/duplicateIdentifiersAcrossContainerBoundaries.js @@ -117,7 +117,6 @@ var Foo = (function () { })(); var Foo; (function (Foo) { - // error for redeclaring var in a different parent })(Foo || (Foo = {})); var N; (function (N) { diff --git a/tests/baselines/reference/duplicateSymbolsExportMatching.js b/tests/baselines/reference/duplicateSymbolsExportMatching.js index 06e37d0d5b..45aee387cd 100644 --- a/tests/baselines/reference/duplicateSymbolsExportMatching.js +++ b/tests/baselines/reference/duplicateSymbolsExportMatching.js @@ -83,9 +83,7 @@ define(["require", "exports"], function (require, exports) { var M2; (function (M2) { var v; - // one error (visibility) var w; - // two errors (visibility and type mismatch) })(M2 || (M2 = {})); var M; (function (M) { diff --git a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments14_ES6.symbols b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments14_ES6.symbols index 18e1063f1e..48564baf79 100644 --- a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments14_ES6.symbols +++ b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments14_ES6.symbols @@ -5,7 +5,7 @@ function f() { if (Math.random()) { >Math.random : Symbol(Math.random, Decl(lib.d.ts, 608, 38)) ->Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1694, 1)) +>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1691, 60)) >random : Symbol(Math.random, Decl(lib.d.ts, 608, 38)) let arguments = 100; diff --git a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments15_ES6.symbols b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments15_ES6.symbols index 6885b35941..5f62de9bfa 100644 --- a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments15_ES6.symbols +++ b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments15_ES6.symbols @@ -8,7 +8,7 @@ function f() { if (Math.random()) { >Math.random : Symbol(Math.random, Decl(lib.d.ts, 608, 38)) ->Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1694, 1)) +>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1691, 60)) >random : Symbol(Math.random, Decl(lib.d.ts, 608, 38)) const arguments = 100; diff --git a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments16_ES6.symbols b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments16_ES6.symbols index ae6be6f795..b54ac35ba7 100644 --- a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments16_ES6.symbols +++ b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments16_ES6.symbols @@ -8,7 +8,7 @@ function f() { if (Math.random()) { >Math.random : Symbol(Math.random, Decl(lib.d.ts, 608, 38)) ->Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1694, 1)) +>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1691, 60)) >random : Symbol(Math.random, Decl(lib.d.ts, 608, 38)) return () => arguments[0]; diff --git a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments17_ES6.symbols b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments17_ES6.symbols index c8bf211897..df900ac860 100644 --- a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments17_ES6.symbols +++ b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments17_ES6.symbols @@ -9,7 +9,7 @@ function f() { if (Math.random()) { >Math.random : Symbol(Math.random, Decl(lib.d.ts, 608, 38)) ->Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1694, 1)) +>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1691, 60)) >random : Symbol(Math.random, Decl(lib.d.ts, 608, 38)) return () => arguments[0]; diff --git a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments18_ES6.symbols b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments18_ES6.symbols index cc867dd2c7..4d0887c1ff 100644 --- a/tests/baselines/reference/emitArrowFunctionWhenUsingArguments18_ES6.symbols +++ b/tests/baselines/reference/emitArrowFunctionWhenUsingArguments18_ES6.symbols @@ -9,7 +9,7 @@ function f() { if (Math.random()) { >Math.random : Symbol(Math.random, Decl(lib.d.ts, 608, 38)) ->Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1694, 1)) +>Math : Symbol(Math, Decl(lib.d.ts, 522, 1), Decl(lib.d.ts, 633, 11), Decl(lib.d.ts, 1691, 60)) >random : Symbol(Math.random, Decl(lib.d.ts, 608, 38)) return () => arguments; diff --git a/tests/baselines/reference/exportPrivateType.js b/tests/baselines/reference/exportPrivateType.js index 87dc16968f..14267730df 100644 --- a/tests/baselines/reference/exportPrivateType.js +++ b/tests/baselines/reference/exportPrivateType.js @@ -44,6 +44,5 @@ var foo; C2.prototype.test = function () { return true; }; return C2; })(); - // None of the types are exported, so per section 10.3, should all be errors })(foo || (foo = {})); var y = foo.g; // Exported variable 'y' has or is using private type 'foo.C2'. diff --git a/tests/baselines/reference/for-of32.errors.txt b/tests/baselines/reference/for-of32.errors.txt index 4b139d386c..f382ea4098 100644 --- a/tests/baselines/reference/for-of32.errors.txt +++ b/tests/baselines/reference/for-of32.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/es6/for-ofStatements/for-of32.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/conformance/es6/for-ofStatements/for-of32.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. ==== tests/cases/conformance/es6/for-ofStatements/for-of32.ts (1 errors) ==== for (var v of v) { } ~ -!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. \ No newline at end of file +!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. \ No newline at end of file diff --git a/tests/baselines/reference/for-of33.errors.txt b/tests/baselines/reference/for-of33.errors.txt index cd2d48566a..ff1feacd7b 100644 --- a/tests/baselines/reference/for-of33.errors.txt +++ b/tests/baselines/reference/for-of33.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/es6/for-ofStatements/for-of33.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/conformance/es6/for-ofStatements/for-of33.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/conformance/es6/for-ofStatements/for-of33.ts(4,5): error TS7023: '[Symbol.iterator]' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. ==== tests/cases/conformance/es6/for-ofStatements/for-of33.ts (2 errors) ==== for (var v of new StringIterator) { } ~ -!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. class StringIterator { [Symbol.iterator]() { diff --git a/tests/baselines/reference/for-of34.errors.txt b/tests/baselines/reference/for-of34.errors.txt index a4f55ed29b..c378a8f5bb 100644 --- a/tests/baselines/reference/for-of34.errors.txt +++ b/tests/baselines/reference/for-of34.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/es6/for-ofStatements/for-of34.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/conformance/es6/for-ofStatements/for-of34.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/conformance/es6/for-ofStatements/for-of34.ts(4,5): error TS7023: 'next' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. ==== tests/cases/conformance/es6/for-ofStatements/for-of34.ts (2 errors) ==== for (var v of new StringIterator) { } ~ -!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. class StringIterator { next() { diff --git a/tests/baselines/reference/for-of35.errors.txt b/tests/baselines/reference/for-of35.errors.txt index 65529752b9..58fb5056fd 100644 --- a/tests/baselines/reference/for-of35.errors.txt +++ b/tests/baselines/reference/for-of35.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/es6/for-ofStatements/for-of35.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/conformance/es6/for-ofStatements/for-of35.ts(1,10): error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/conformance/es6/for-ofStatements/for-of35.ts(4,5): error TS7023: 'next' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. ==== tests/cases/conformance/es6/for-ofStatements/for-of35.ts (2 errors) ==== for (var v of new StringIterator) { } ~ -!!! error TS7022: 'v' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +!!! error TS7022: 'v' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. class StringIterator { next() { diff --git a/tests/baselines/reference/for-of37.symbols b/tests/baselines/reference/for-of37.symbols index 93f6c4f7dd..739d9be0af 100644 --- a/tests/baselines/reference/for-of37.symbols +++ b/tests/baselines/reference/for-of37.symbols @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/for-ofStatements/for-of37.ts === var map = new Map([["", true]]); >map : Symbol(map, Decl(for-of37.ts, 0, 3)) ->Map : Symbol(Map, Decl(lib.d.ts, 1867, 1), Decl(lib.d.ts, 1889, 11)) +>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11)) for (var v of map) { >v : Symbol(v, Decl(for-of37.ts, 1, 8)) diff --git a/tests/baselines/reference/for-of38.symbols b/tests/baselines/reference/for-of38.symbols index fab42d9172..9322fea69e 100644 --- a/tests/baselines/reference/for-of38.symbols +++ b/tests/baselines/reference/for-of38.symbols @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/for-ofStatements/for-of38.ts === var map = new Map([["", true]]); >map : Symbol(map, Decl(for-of38.ts, 0, 3)) ->Map : Symbol(Map, Decl(lib.d.ts, 1867, 1), Decl(lib.d.ts, 1889, 11)) +>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11)) for (var [k, v] of map) { >k : Symbol(k, Decl(for-of38.ts, 1, 10)) diff --git a/tests/baselines/reference/for-of40.symbols b/tests/baselines/reference/for-of40.symbols index 1cd3538f98..72bbf78884 100644 --- a/tests/baselines/reference/for-of40.symbols +++ b/tests/baselines/reference/for-of40.symbols @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/for-ofStatements/for-of40.ts === var map = new Map([["", true]]); >map : Symbol(map, Decl(for-of40.ts, 0, 3)) ->Map : Symbol(Map, Decl(lib.d.ts, 1867, 1), Decl(lib.d.ts, 1889, 11)) +>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11)) for (var [k = "", v = false] of map) { >k : Symbol(k, Decl(for-of40.ts, 1, 10)) diff --git a/tests/baselines/reference/for-of45.symbols b/tests/baselines/reference/for-of45.symbols index 9fda4cb4e0..e1e7717269 100644 --- a/tests/baselines/reference/for-of45.symbols +++ b/tests/baselines/reference/for-of45.symbols @@ -5,7 +5,7 @@ var k: string, v: boolean; var map = new Map([["", true]]); >map : Symbol(map, Decl(for-of45.ts, 1, 3)) ->Map : Symbol(Map, Decl(lib.d.ts, 1867, 1), Decl(lib.d.ts, 1889, 11)) +>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11)) for ([k = "", v = false] of map) { >k : Symbol(k, Decl(for-of45.ts, 0, 3)) diff --git a/tests/baselines/reference/for-of50.symbols b/tests/baselines/reference/for-of50.symbols index c176e1aca0..571dd9dc38 100644 --- a/tests/baselines/reference/for-of50.symbols +++ b/tests/baselines/reference/for-of50.symbols @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/for-ofStatements/for-of50.ts === var map = new Map([["", true]]); >map : Symbol(map, Decl(for-of50.ts, 0, 3)) ->Map : Symbol(Map, Decl(lib.d.ts, 1867, 1), Decl(lib.d.ts, 1889, 11)) +>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11)) for (const [k, v] of map) { >k : Symbol(k, Decl(for-of50.ts, 1, 12)) diff --git a/tests/baselines/reference/for-of57.symbols b/tests/baselines/reference/for-of57.symbols index 27aed0777b..574d52e4c5 100644 --- a/tests/baselines/reference/for-of57.symbols +++ b/tests/baselines/reference/for-of57.symbols @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/for-ofStatements/for-of57.ts === var iter: Iterable; >iter : Symbol(iter, Decl(for-of57.ts, 0, 3)) ->Iterable : Symbol(Iterable, Decl(lib.d.ts, 1663, 1)) +>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1)) for (let num of iter) { } >num : Symbol(num, Decl(for-of57.ts, 1, 8)) diff --git a/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.js b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.js new file mode 100644 index 0000000000..3659f3fd9f --- /dev/null +++ b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.js @@ -0,0 +1,12 @@ +//// [functionDeclarationWithResolutionOfTypeNamedArguments01.ts] +interface arguments { +} + +function f() { + arguments; +} + +//// [functionDeclarationWithResolutionOfTypeNamedArguments01.js] +function f() { + arguments; +} diff --git a/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.symbols b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.symbols new file mode 100644 index 0000000000..8a36f14600 --- /dev/null +++ b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts === +interface arguments { +>arguments : Symbol(arguments, Decl(functionDeclarationWithResolutionOfTypeNamedArguments01.ts, 0, 0)) +} + +function f() { +>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeNamedArguments01.ts, 1, 1)) + + arguments; +>arguments : Symbol(arguments, Decl(functionDeclarationWithResolutionOfTypeNamedArguments01.ts, 0, 0)) +>arguments : Symbol(arguments) +} diff --git a/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.types b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.types new file mode 100644 index 0000000000..72dbbf8ec6 --- /dev/null +++ b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeNamedArguments01.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts === +interface arguments { +>arguments : arguments +} + +function f() { +>f : () => void + + arguments; +>arguments : arguments +>arguments : arguments +>arguments : IArguments +} diff --git a/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.js b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.js new file mode 100644 index 0000000000..6f5bb2cacf --- /dev/null +++ b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.js @@ -0,0 +1,12 @@ +//// [functionDeclarationWithResolutionOfTypeOfSameName01.ts] +interface f { +} + +function f() { + f; +} + +//// [functionDeclarationWithResolutionOfTypeOfSameName01.js] +function f() { + f; +} diff --git a/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.symbols b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.symbols new file mode 100644 index 0000000000..aa51fad053 --- /dev/null +++ b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.symbols @@ -0,0 +1,12 @@ +=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeOfSameName01.ts === +interface f { +>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1)) +} + +function f() { +>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1)) + + f; +>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1)) +>f : Symbol(f, Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 0, 0), Decl(functionDeclarationWithResolutionOfTypeOfSameName01.ts, 1, 1)) +} diff --git a/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.types b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.types new file mode 100644 index 0000000000..1067b8989c --- /dev/null +++ b/tests/baselines/reference/functionDeclarationWithResolutionOfTypeOfSameName01.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/functionDeclarationWithResolutionOfTypeOfSameName01.ts === +interface f { +>f : f +} + +function f() { +>f : () => void + + f; +>f : f +>f : f +>f : () => void +} diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.js b/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.js new file mode 100644 index 0000000000..43b38f2dd3 --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.js @@ -0,0 +1,12 @@ +//// [functionExpressionWithResolutionOfTypeNamedArguments01.ts] +interface arguments { +} + +var x = function f() { + arguments; +} + +//// [functionExpressionWithResolutionOfTypeNamedArguments01.js] +var x = function f() { + arguments; +}; diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.symbols b/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.symbols new file mode 100644 index 0000000000..d2455fd010 --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/functionExpressionWithResolutionOfTypeNamedArguments01.ts === +interface arguments { +>arguments : Symbol(arguments, Decl(functionExpressionWithResolutionOfTypeNamedArguments01.ts, 0, 0)) +} + +var x = function f() { +>x : Symbol(x, Decl(functionExpressionWithResolutionOfTypeNamedArguments01.ts, 3, 3)) +>f : Symbol(f, Decl(functionExpressionWithResolutionOfTypeNamedArguments01.ts, 3, 7)) + + arguments; +>arguments : Symbol(arguments, Decl(functionExpressionWithResolutionOfTypeNamedArguments01.ts, 0, 0)) +>arguments : Symbol(arguments) +} diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.types b/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.types new file mode 100644 index 0000000000..1a65010a4f --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeNamedArguments01.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/functionExpressionWithResolutionOfTypeNamedArguments01.ts === +interface arguments { +>arguments : arguments +} + +var x = function f() { +>x : () => void +>function f() { arguments;} : () => void +>f : () => void + + arguments; +>arguments : arguments +>arguments : arguments +>arguments : IArguments +} diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.js b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.js new file mode 100644 index 0000000000..c9af7ab329 --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.js @@ -0,0 +1,12 @@ +//// [functionExpressionWithResolutionOfTypeOfSameName01.ts] +interface f { +} + +var x = function f() { + f; +} + +//// [functionExpressionWithResolutionOfTypeOfSameName01.js] +var x = function f() { + f; +}; diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.symbols b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.symbols new file mode 100644 index 0000000000..cd2248c601 --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName01.ts === +interface f { +>f : Symbol(f, Decl(functionExpressionWithResolutionOfTypeOfSameName01.ts, 0, 0)) +} + +var x = function f() { +>x : Symbol(x, Decl(functionExpressionWithResolutionOfTypeOfSameName01.ts, 3, 3)) +>f : Symbol(f, Decl(functionExpressionWithResolutionOfTypeOfSameName01.ts, 3, 7)) + + f; +>f : Symbol(f, Decl(functionExpressionWithResolutionOfTypeOfSameName01.ts, 0, 0)) +>f : Symbol(f, Decl(functionExpressionWithResolutionOfTypeOfSameName01.ts, 3, 7)) +} diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.types b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.types new file mode 100644 index 0000000000..08b51f3522 --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName01.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName01.ts === +interface f { +>f : f +} + +var x = function f() { +>x : () => void +>function f() { f;} : () => void +>f : () => void + + f; +>f : f +>f : f +>f : () => void +} diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.js b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.js new file mode 100644 index 0000000000..ada96c63a5 --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.js @@ -0,0 +1,12 @@ +//// [functionExpressionWithResolutionOfTypeOfSameName02.ts] +interface Foo { +} + +var x = function Foo() { + var x: Foo; +} + +//// [functionExpressionWithResolutionOfTypeOfSameName02.js] +var x = function Foo() { + var x; +}; diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.symbols b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.symbols new file mode 100644 index 0000000000..89b46c99b4 --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName02.ts === +interface Foo { +>Foo : Symbol(Foo, Decl(functionExpressionWithResolutionOfTypeOfSameName02.ts, 0, 0)) +} + +var x = function Foo() { +>x : Symbol(x, Decl(functionExpressionWithResolutionOfTypeOfSameName02.ts, 3, 3)) +>Foo : Symbol(Foo, Decl(functionExpressionWithResolutionOfTypeOfSameName02.ts, 3, 7)) + + var x: Foo; +>x : Symbol(x, Decl(functionExpressionWithResolutionOfTypeOfSameName02.ts, 4, 7)) +>Foo : Symbol(Foo, Decl(functionExpressionWithResolutionOfTypeOfSameName02.ts, 0, 0)) +} diff --git a/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.types b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.types new file mode 100644 index 0000000000..218276a95e --- /dev/null +++ b/tests/baselines/reference/functionExpressionWithResolutionOfTypeOfSameName02.types @@ -0,0 +1,14 @@ +=== tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName02.ts === +interface Foo { +>Foo : Foo +} + +var x = function Foo() { +>x : () => void +>function Foo() { var x: Foo;} : () => void +>Foo : () => void + + var x: Foo; +>x : Foo +>Foo : Foo +} diff --git a/tests/baselines/reference/functionsWithModifiersInBlocks1.errors.txt b/tests/baselines/reference/functionsWithModifiersInBlocks1.errors.txt index 94e246f897..f6240f5e69 100644 --- a/tests/baselines/reference/functionsWithModifiersInBlocks1.errors.txt +++ b/tests/baselines/reference/functionsWithModifiersInBlocks1.errors.txt @@ -4,12 +4,11 @@ tests/cases/compiler/functionsWithModifiersInBlocks1.ts(2,25): error TS1184: An tests/cases/compiler/functionsWithModifiersInBlocks1.ts(3,4): error TS1184: Modifiers cannot appear here. tests/cases/compiler/functionsWithModifiersInBlocks1.ts(3,20): error TS2393: Duplicate function implementation. tests/cases/compiler/functionsWithModifiersInBlocks1.ts(4,4): error TS1184: Modifiers cannot appear here. -tests/cases/compiler/functionsWithModifiersInBlocks1.ts(4,12): error TS1029: 'export' modifier must precede 'declare' modifier. tests/cases/compiler/functionsWithModifiersInBlocks1.ts(4,28): error TS2393: Duplicate function implementation. tests/cases/compiler/functionsWithModifiersInBlocks1.ts(4,32): error TS1184: An implementation cannot be declared in ambient contexts. -==== tests/cases/compiler/functionsWithModifiersInBlocks1.ts (9 errors) ==== +==== tests/cases/compiler/functionsWithModifiersInBlocks1.ts (8 errors) ==== { declare function f() { } ~~~~~~~ @@ -26,8 +25,6 @@ tests/cases/compiler/functionsWithModifiersInBlocks1.ts(4,32): error TS1184: An declare export function f() { } ~~~~~~~ !!! error TS1184: Modifiers cannot appear here. - ~~~~~~ -!!! error TS1029: 'export' modifier must precede 'declare' modifier. ~ !!! error TS2393: Duplicate function implementation. ~ diff --git a/tests/baselines/reference/generatorES6_1.errors.txt b/tests/baselines/reference/generatorES6_1.errors.txt deleted file mode 100644 index b02da7f0b5..0000000000 --- a/tests/baselines/reference/generatorES6_1.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -tests/cases/compiler/generatorES6_1.ts(1,9): error TS9001: Generators are not currently supported. -tests/cases/compiler/generatorES6_1.ts(2,5): error TS9000: 'yield' expressions are not currently supported. - - -==== tests/cases/compiler/generatorES6_1.ts (2 errors) ==== - function* foo() { - ~ -!!! error TS9001: Generators are not currently supported. - yield - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. - } \ No newline at end of file diff --git a/tests/baselines/reference/generatorES6_1.symbols b/tests/baselines/reference/generatorES6_1.symbols new file mode 100644 index 0000000000..fc5aa602e0 --- /dev/null +++ b/tests/baselines/reference/generatorES6_1.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/generatorES6_1.ts === +function* foo() { +>foo : Symbol(foo, Decl(generatorES6_1.ts, 0, 0)) + + yield +} diff --git a/tests/baselines/reference/generatorES6_1.types b/tests/baselines/reference/generatorES6_1.types new file mode 100644 index 0000000000..13ac7c0584 --- /dev/null +++ b/tests/baselines/reference/generatorES6_1.types @@ -0,0 +1,7 @@ +=== tests/cases/compiler/generatorES6_1.ts === +function* foo() { +>foo : () => IterableIterator + + yield +>yield : any +} diff --git a/tests/baselines/reference/generatorES6_2.errors.txt b/tests/baselines/reference/generatorES6_2.errors.txt deleted file mode 100644 index 8d956fc7f6..0000000000 --- a/tests/baselines/reference/generatorES6_2.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -tests/cases/compiler/generatorES6_2.ts(2,12): error TS9001: Generators are not currently supported. -tests/cases/compiler/generatorES6_2.ts(3,9): error TS9000: 'yield' expressions are not currently supported. - - -==== tests/cases/compiler/generatorES6_2.ts (2 errors) ==== - class C { - public * foo() { - ~ -!!! error TS9001: Generators are not currently supported. - yield 1 - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. - } - } \ No newline at end of file diff --git a/tests/baselines/reference/generatorES6_2.symbols b/tests/baselines/reference/generatorES6_2.symbols new file mode 100644 index 0000000000..a64b130469 --- /dev/null +++ b/tests/baselines/reference/generatorES6_2.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/generatorES6_2.ts === +class C { +>C : Symbol(C, Decl(generatorES6_2.ts, 0, 0)) + + public * foo() { +>foo : Symbol(foo, Decl(generatorES6_2.ts, 0, 9)) + + yield 1 + } +} diff --git a/tests/baselines/reference/generatorES6_2.types b/tests/baselines/reference/generatorES6_2.types new file mode 100644 index 0000000000..9c9c869275 --- /dev/null +++ b/tests/baselines/reference/generatorES6_2.types @@ -0,0 +1,12 @@ +=== tests/cases/compiler/generatorES6_2.ts === +class C { +>C : C + + public * foo() { +>foo : () => IterableIterator + + yield 1 +>yield 1 : any +>1 : number + } +} diff --git a/tests/baselines/reference/generatorES6_3.errors.txt b/tests/baselines/reference/generatorES6_3.errors.txt deleted file mode 100644 index e1c1d918ce..0000000000 --- a/tests/baselines/reference/generatorES6_3.errors.txt +++ /dev/null @@ -1,12 +0,0 @@ -tests/cases/compiler/generatorES6_3.ts(1,17): error TS9001: Generators are not currently supported. -tests/cases/compiler/generatorES6_3.ts(2,5): error TS9000: 'yield' expressions are not currently supported. - - -==== tests/cases/compiler/generatorES6_3.ts (2 errors) ==== - var v = function*() { - ~ -!!! error TS9001: Generators are not currently supported. - yield 0 - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. - } \ No newline at end of file diff --git a/tests/baselines/reference/generatorES6_3.symbols b/tests/baselines/reference/generatorES6_3.symbols new file mode 100644 index 0000000000..329c96e6de --- /dev/null +++ b/tests/baselines/reference/generatorES6_3.symbols @@ -0,0 +1,6 @@ +=== tests/cases/compiler/generatorES6_3.ts === +var v = function*() { +>v : Symbol(v, Decl(generatorES6_3.ts, 0, 3)) + + yield 0 +} diff --git a/tests/baselines/reference/generatorES6_3.types b/tests/baselines/reference/generatorES6_3.types new file mode 100644 index 0000000000..e87ad23ba7 --- /dev/null +++ b/tests/baselines/reference/generatorES6_3.types @@ -0,0 +1,9 @@ +=== tests/cases/compiler/generatorES6_3.ts === +var v = function*() { +>v : () => IterableIterator +>function*() { yield 0} : () => IterableIterator + + yield 0 +>yield 0 : any +>0 : number +} diff --git a/tests/baselines/reference/generatorES6_4.errors.txt b/tests/baselines/reference/generatorES6_4.errors.txt deleted file mode 100644 index 37c375e972..0000000000 --- a/tests/baselines/reference/generatorES6_4.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -tests/cases/compiler/generatorES6_4.ts(2,4): error TS9001: Generators are not currently supported. -tests/cases/compiler/generatorES6_4.ts(3,8): error TS9000: 'yield' expressions are not currently supported. - - -==== tests/cases/compiler/generatorES6_4.ts (2 errors) ==== - var v = { - *foo() { - ~ -!!! error TS9001: Generators are not currently supported. - yield 0 - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. - } - } \ No newline at end of file diff --git a/tests/baselines/reference/generatorES6_4.symbols b/tests/baselines/reference/generatorES6_4.symbols new file mode 100644 index 0000000000..fc514dad45 --- /dev/null +++ b/tests/baselines/reference/generatorES6_4.symbols @@ -0,0 +1,10 @@ +=== tests/cases/compiler/generatorES6_4.ts === +var v = { +>v : Symbol(v, Decl(generatorES6_4.ts, 0, 3)) + + *foo() { +>foo : Symbol(foo, Decl(generatorES6_4.ts, 0, 9)) + + yield 0 + } +} diff --git a/tests/baselines/reference/generatorES6_4.types b/tests/baselines/reference/generatorES6_4.types new file mode 100644 index 0000000000..64b0924919 --- /dev/null +++ b/tests/baselines/reference/generatorES6_4.types @@ -0,0 +1,13 @@ +=== tests/cases/compiler/generatorES6_4.ts === +var v = { +>v : { foo(): IterableIterator; } +>{ *foo() { yield 0 }} : { foo(): IterableIterator; } + + *foo() { +>foo : () => IterableIterator + + yield 0 +>yield 0 : any +>0 : number + } +} diff --git a/tests/baselines/reference/generatorES6_5.errors.txt b/tests/baselines/reference/generatorES6_5.errors.txt index f6fa8a5bc1..20e6f3abe9 100644 --- a/tests/baselines/reference/generatorES6_5.errors.txt +++ b/tests/baselines/reference/generatorES6_5.errors.txt @@ -1,12 +1,15 @@ -tests/cases/compiler/generatorES6_5.ts(1,9): error TS9001: Generators are not currently supported. -tests/cases/compiler/generatorES6_5.ts(2,5): error TS9000: 'yield' expressions are not currently supported. +tests/cases/compiler/generatorES6_5.ts(2,11): error TS2304: Cannot find name 'a'. +tests/cases/compiler/generatorES6_5.ts(2,15): error TS2304: Cannot find name 'b'. +tests/cases/compiler/generatorES6_5.ts(2,19): error TS2304: Cannot find name 'c'. -==== tests/cases/compiler/generatorES6_5.ts (2 errors) ==== +==== tests/cases/compiler/generatorES6_5.ts (3 errors) ==== function* foo() { - ~ -!!! error TS9001: Generators are not currently supported. yield a ? b : c; - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. + ~ +!!! error TS2304: Cannot find name 'a'. + ~ +!!! error TS2304: Cannot find name 'b'. + ~ +!!! error TS2304: Cannot find name 'c'. } \ No newline at end of file diff --git a/tests/baselines/reference/generatorES6_6.errors.txt b/tests/baselines/reference/generatorES6_6.errors.txt deleted file mode 100644 index 1f568aeb9e..0000000000 --- a/tests/baselines/reference/generatorES6_6.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -tests/cases/compiler/generatorES6_6.ts(2,3): error TS9001: Generators are not currently supported. -tests/cases/compiler/generatorES6_6.ts(3,13): error TS9000: 'yield' expressions are not currently supported. - - -==== tests/cases/compiler/generatorES6_6.ts (2 errors) ==== - class C { - *[Symbol.iterator]() { - ~ -!!! error TS9001: Generators are not currently supported. - let a = yield 1; - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. - } - } \ No newline at end of file diff --git a/tests/baselines/reference/generatorES6_6.symbols b/tests/baselines/reference/generatorES6_6.symbols new file mode 100644 index 0000000000..4cdac0f12c --- /dev/null +++ b/tests/baselines/reference/generatorES6_6.symbols @@ -0,0 +1,13 @@ +=== tests/cases/compiler/generatorES6_6.ts === +class C { +>C : Symbol(C, Decl(generatorES6_6.ts, 0, 0)) + + *[Symbol.iterator]() { +>Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31)) +>Symbol : Symbol(Symbol, Decl(lib.d.ts, 1186, 52), Decl(lib.d.ts, 1292, 11)) +>iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31)) + + let a = yield 1; +>a : Symbol(a, Decl(generatorES6_6.ts, 2, 7)) + } +} diff --git a/tests/baselines/reference/generatorES6_6.types b/tests/baselines/reference/generatorES6_6.types new file mode 100644 index 0000000000..4e3de8cea1 --- /dev/null +++ b/tests/baselines/reference/generatorES6_6.types @@ -0,0 +1,15 @@ +=== tests/cases/compiler/generatorES6_6.ts === +class C { +>C : C + + *[Symbol.iterator]() { +>Symbol.iterator : symbol +>Symbol : SymbolConstructor +>iterator : symbol + + let a = yield 1; +>a : any +>yield 1 : any +>1 : number + } +} diff --git a/tests/baselines/reference/generatorInAmbientContext1.errors.txt b/tests/baselines/reference/generatorInAmbientContext1.errors.txt new file mode 100644 index 0000000000..f3e458e80c --- /dev/null +++ b/tests/baselines/reference/generatorInAmbientContext1.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext1.ts(2,5): error TS1221: Generators are not allowed in an ambient context. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext1.ts (1 errors) ==== + declare class C { + *generator(): any; + ~ +!!! error TS1221: Generators are not allowed in an ambient context. + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorInAmbientContext1.js b/tests/baselines/reference/generatorInAmbientContext1.js new file mode 100644 index 0000000000..e7b4e03e64 --- /dev/null +++ b/tests/baselines/reference/generatorInAmbientContext1.js @@ -0,0 +1,6 @@ +//// [generatorInAmbientContext1.ts] +declare class C { + *generator(): any; +} + +//// [generatorInAmbientContext1.js] diff --git a/tests/baselines/reference/generatorInAmbientContext2.errors.txt b/tests/baselines/reference/generatorInAmbientContext2.errors.txt new file mode 100644 index 0000000000..d6cd02f72e --- /dev/null +++ b/tests/baselines/reference/generatorInAmbientContext2.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext2.ts(2,14): error TS1221: Generators are not allowed in an ambient context. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext2.ts (1 errors) ==== + declare module M { + function *generator(): any; + ~ +!!! error TS1221: Generators are not allowed in an ambient context. + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorInAmbientContext2.js b/tests/baselines/reference/generatorInAmbientContext2.js new file mode 100644 index 0000000000..f7742ccc23 --- /dev/null +++ b/tests/baselines/reference/generatorInAmbientContext2.js @@ -0,0 +1,6 @@ +//// [generatorInAmbientContext2.ts] +declare module M { + function *generator(): any; +} + +//// [generatorInAmbientContext2.js] diff --git a/tests/baselines/reference/generatorInAmbientContext3.d.errors.txt b/tests/baselines/reference/generatorInAmbientContext3.d.errors.txt new file mode 100644 index 0000000000..d53591ef80 --- /dev/null +++ b/tests/baselines/reference/generatorInAmbientContext3.d.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext3.d.ts(2,5): error TS1221: Generators are not allowed in an ambient context. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext3.d.ts (1 errors) ==== + declare class C { + *generator(): any; + ~ +!!! error TS1221: Generators are not allowed in an ambient context. + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorInAmbientContext4.d.errors.txt b/tests/baselines/reference/generatorInAmbientContext4.d.errors.txt new file mode 100644 index 0000000000..171ad2e664 --- /dev/null +++ b/tests/baselines/reference/generatorInAmbientContext4.d.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext4.d.ts(2,14): error TS1221: Generators are not allowed in an ambient context. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext4.d.ts (1 errors) ==== + declare module M { + function *generator(): any; + ~ +!!! error TS1221: Generators are not allowed in an ambient context. + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorInAmbientContext5.js b/tests/baselines/reference/generatorInAmbientContext5.js new file mode 100644 index 0000000000..044155e8dd --- /dev/null +++ b/tests/baselines/reference/generatorInAmbientContext5.js @@ -0,0 +1,15 @@ +//// [generatorInAmbientContext5.ts] +class C { + *generator(): any { } +} + +//// [generatorInAmbientContext5.js] +class C { + *generator() { } +} + + +//// [generatorInAmbientContext5.d.ts] +declare class C { + generator(): any; +} diff --git a/tests/baselines/reference/generatorInAmbientContext5.symbols b/tests/baselines/reference/generatorInAmbientContext5.symbols new file mode 100644 index 0000000000..78139a7e59 --- /dev/null +++ b/tests/baselines/reference/generatorInAmbientContext5.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext5.ts === +class C { +>C : Symbol(C, Decl(generatorInAmbientContext5.ts, 0, 0)) + + *generator(): any { } +>generator : Symbol(generator, Decl(generatorInAmbientContext5.ts, 0, 9)) +} diff --git a/tests/baselines/reference/generatorInAmbientContext5.types b/tests/baselines/reference/generatorInAmbientContext5.types new file mode 100644 index 0000000000..169aba8201 --- /dev/null +++ b/tests/baselines/reference/generatorInAmbientContext5.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext5.ts === +class C { +>C : C + + *generator(): any { } +>generator : () => any +} diff --git a/tests/baselines/reference/generatorInAmbientContext6.js b/tests/baselines/reference/generatorInAmbientContext6.js new file mode 100644 index 0000000000..10cfa85d93 --- /dev/null +++ b/tests/baselines/reference/generatorInAmbientContext6.js @@ -0,0 +1,17 @@ +//// [generatorInAmbientContext6.ts] +module M { + export function *generator(): any { } +} + +//// [generatorInAmbientContext6.js] +var M; +(function (M) { + function* generator() { } + M.generator = generator; +})(M || (M = {})); + + +//// [generatorInAmbientContext6.d.ts] +declare module M { + function generator(): any; +} diff --git a/tests/baselines/reference/generatorInAmbientContext6.symbols b/tests/baselines/reference/generatorInAmbientContext6.symbols new file mode 100644 index 0000000000..e921a2b1f9 --- /dev/null +++ b/tests/baselines/reference/generatorInAmbientContext6.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext6.ts === +module M { +>M : Symbol(M, Decl(generatorInAmbientContext6.ts, 0, 0)) + + export function *generator(): any { } +>generator : Symbol(generator, Decl(generatorInAmbientContext6.ts, 0, 10)) +} diff --git a/tests/baselines/reference/generatorInAmbientContext6.types b/tests/baselines/reference/generatorInAmbientContext6.types new file mode 100644 index 0000000000..d960126210 --- /dev/null +++ b/tests/baselines/reference/generatorInAmbientContext6.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext6.ts === +module M { +>M : typeof M + + export function *generator(): any { } +>generator : () => any +} diff --git a/tests/baselines/reference/generatorOverloads1.errors.txt b/tests/baselines/reference/generatorOverloads1.errors.txt new file mode 100644 index 0000000000..280ca7c516 --- /dev/null +++ b/tests/baselines/reference/generatorOverloads1.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/es6/yieldExpressions/generatorOverloads1.ts(2,13): error TS1222: An overload signature cannot be declared as a generator. +tests/cases/conformance/es6/yieldExpressions/generatorOverloads1.ts(3,13): error TS1222: An overload signature cannot be declared as a generator. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorOverloads1.ts (2 errors) ==== + module M { + function* f(s: string): Iterable; + ~ +!!! error TS1222: An overload signature cannot be declared as a generator. + function* f(s: number): Iterable; + ~ +!!! error TS1222: An overload signature cannot be declared as a generator. + function* f(s: any): Iterable { } + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorOverloads1.js b/tests/baselines/reference/generatorOverloads1.js new file mode 100644 index 0000000000..0ce5ae10f4 --- /dev/null +++ b/tests/baselines/reference/generatorOverloads1.js @@ -0,0 +1,12 @@ +//// [generatorOverloads1.ts] +module M { + function* f(s: string): Iterable; + function* f(s: number): Iterable; + function* f(s: any): Iterable { } +} + +//// [generatorOverloads1.js] +var M; +(function (M) { + function* f(s) { } +})(M || (M = {})); diff --git a/tests/baselines/reference/generatorOverloads2.errors.txt b/tests/baselines/reference/generatorOverloads2.errors.txt new file mode 100644 index 0000000000..349b9382eb --- /dev/null +++ b/tests/baselines/reference/generatorOverloads2.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts(2,13): error TS1221: Generators are not allowed in an ambient context. +tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts(3,13): error TS1221: Generators are not allowed in an ambient context. +tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts(4,13): error TS1221: Generators are not allowed in an ambient context. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts (3 errors) ==== + declare module M { + function* f(s: string): Iterable; + ~ +!!! error TS1221: Generators are not allowed in an ambient context. + function* f(s: number): Iterable; + ~ +!!! error TS1221: Generators are not allowed in an ambient context. + function* f(s: any): Iterable; + ~ +!!! error TS1221: Generators are not allowed in an ambient context. + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorOverloads2.js b/tests/baselines/reference/generatorOverloads2.js new file mode 100644 index 0000000000..4fa3837ed3 --- /dev/null +++ b/tests/baselines/reference/generatorOverloads2.js @@ -0,0 +1,8 @@ +//// [generatorOverloads2.ts] +declare module M { + function* f(s: string): Iterable; + function* f(s: number): Iterable; + function* f(s: any): Iterable; +} + +//// [generatorOverloads2.js] diff --git a/tests/baselines/reference/generatorOverloads3.errors.txt b/tests/baselines/reference/generatorOverloads3.errors.txt new file mode 100644 index 0000000000..d7ef5da20e --- /dev/null +++ b/tests/baselines/reference/generatorOverloads3.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts(2,5): error TS1222: An overload signature cannot be declared as a generator. +tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts(3,5): error TS1222: An overload signature cannot be declared as a generator. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts (2 errors) ==== + class C { + *f(s: string): Iterable; + ~ +!!! error TS1222: An overload signature cannot be declared as a generator. + *f(s: number): Iterable; + ~ +!!! error TS1222: An overload signature cannot be declared as a generator. + *f(s: any): Iterable { } + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorOverloads3.js b/tests/baselines/reference/generatorOverloads3.js new file mode 100644 index 0000000000..55ba5dcdc9 --- /dev/null +++ b/tests/baselines/reference/generatorOverloads3.js @@ -0,0 +1,11 @@ +//// [generatorOverloads3.ts] +class C { + *f(s: string): Iterable; + *f(s: number): Iterable; + *f(s: any): Iterable { } +} + +//// [generatorOverloads3.js] +class C { + *f(s) { } +} diff --git a/tests/baselines/reference/generatorOverloads4.js b/tests/baselines/reference/generatorOverloads4.js new file mode 100644 index 0000000000..8ebbcb5938 --- /dev/null +++ b/tests/baselines/reference/generatorOverloads4.js @@ -0,0 +1,11 @@ +//// [generatorOverloads4.ts] +class C { + f(s: string): Iterable; + f(s: number): Iterable; + *f(s: any): Iterable { } +} + +//// [generatorOverloads4.js] +class C { + *f(s) { } +} diff --git a/tests/baselines/reference/generatorOverloads4.symbols b/tests/baselines/reference/generatorOverloads4.symbols new file mode 100644 index 0000000000..afae1c1a80 --- /dev/null +++ b/tests/baselines/reference/generatorOverloads4.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorOverloads4.ts === +class C { +>C : Symbol(C, Decl(generatorOverloads4.ts, 0, 0)) + + f(s: string): Iterable; +>f : Symbol(f, Decl(generatorOverloads4.ts, 0, 9), Decl(generatorOverloads4.ts, 1, 32), Decl(generatorOverloads4.ts, 2, 32)) +>s : Symbol(s, Decl(generatorOverloads4.ts, 1, 6)) +>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1)) + + f(s: number): Iterable; +>f : Symbol(f, Decl(generatorOverloads4.ts, 0, 9), Decl(generatorOverloads4.ts, 1, 32), Decl(generatorOverloads4.ts, 2, 32)) +>s : Symbol(s, Decl(generatorOverloads4.ts, 2, 6)) +>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1)) + + *f(s: any): Iterable { } +>f : Symbol(f, Decl(generatorOverloads4.ts, 0, 9), Decl(generatorOverloads4.ts, 1, 32), Decl(generatorOverloads4.ts, 2, 32)) +>s : Symbol(s, Decl(generatorOverloads4.ts, 3, 7)) +>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1)) +} diff --git a/tests/baselines/reference/generatorOverloads4.types b/tests/baselines/reference/generatorOverloads4.types new file mode 100644 index 0000000000..493e0ac307 --- /dev/null +++ b/tests/baselines/reference/generatorOverloads4.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorOverloads4.ts === +class C { +>C : C + + f(s: string): Iterable; +>f : { (s: string): Iterable; (s: number): Iterable; } +>s : string +>Iterable : Iterable + + f(s: number): Iterable; +>f : { (s: string): Iterable; (s: number): Iterable; } +>s : number +>Iterable : Iterable + + *f(s: any): Iterable { } +>f : { (s: string): Iterable; (s: number): Iterable; } +>s : any +>Iterable : Iterable +} diff --git a/tests/baselines/reference/generatorOverloads5.js b/tests/baselines/reference/generatorOverloads5.js new file mode 100644 index 0000000000..c6d928045f --- /dev/null +++ b/tests/baselines/reference/generatorOverloads5.js @@ -0,0 +1,12 @@ +//// [generatorOverloads5.ts] +module M { + function f(s: string): Iterable; + function f(s: number): Iterable; + function* f(s: any): Iterable { } +} + +//// [generatorOverloads5.js] +var M; +(function (M) { + function* f(s) { } +})(M || (M = {})); diff --git a/tests/baselines/reference/generatorOverloads5.symbols b/tests/baselines/reference/generatorOverloads5.symbols new file mode 100644 index 0000000000..0a14548d19 --- /dev/null +++ b/tests/baselines/reference/generatorOverloads5.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorOverloads5.ts === +module M { +>M : Symbol(M, Decl(generatorOverloads5.ts, 0, 0)) + + function f(s: string): Iterable; +>f : Symbol(f, Decl(generatorOverloads5.ts, 0, 10), Decl(generatorOverloads5.ts, 1, 41), Decl(generatorOverloads5.ts, 2, 41)) +>s : Symbol(s, Decl(generatorOverloads5.ts, 1, 15)) +>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1)) + + function f(s: number): Iterable; +>f : Symbol(f, Decl(generatorOverloads5.ts, 0, 10), Decl(generatorOverloads5.ts, 1, 41), Decl(generatorOverloads5.ts, 2, 41)) +>s : Symbol(s, Decl(generatorOverloads5.ts, 2, 15)) +>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1)) + + function* f(s: any): Iterable { } +>f : Symbol(f, Decl(generatorOverloads5.ts, 0, 10), Decl(generatorOverloads5.ts, 1, 41), Decl(generatorOverloads5.ts, 2, 41)) +>s : Symbol(s, Decl(generatorOverloads5.ts, 3, 16)) +>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1)) +} diff --git a/tests/baselines/reference/generatorOverloads5.types b/tests/baselines/reference/generatorOverloads5.types new file mode 100644 index 0000000000..276baf1ff4 --- /dev/null +++ b/tests/baselines/reference/generatorOverloads5.types @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorOverloads5.ts === +module M { +>M : typeof M + + function f(s: string): Iterable; +>f : { (s: string): Iterable; (s: number): Iterable; } +>s : string +>Iterable : Iterable + + function f(s: number): Iterable; +>f : { (s: string): Iterable; (s: number): Iterable; } +>s : number +>Iterable : Iterable + + function* f(s: any): Iterable { } +>f : { (s: string): Iterable; (s: number): Iterable; } +>s : any +>Iterable : Iterable +} diff --git a/tests/baselines/reference/generatorTypeCheck1.js b/tests/baselines/reference/generatorTypeCheck1.js new file mode 100644 index 0000000000..eb3cbcd2fe --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck1.js @@ -0,0 +1,5 @@ +//// [generatorTypeCheck1.ts] +function* g1(): Iterator { } + +//// [generatorTypeCheck1.js] +function* g1() { } diff --git a/tests/baselines/reference/generatorTypeCheck1.symbols b/tests/baselines/reference/generatorTypeCheck1.symbols new file mode 100644 index 0000000000..58ee2aa66f --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck1.symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck1.ts === +function* g1(): Iterator { } +>g1 : Symbol(g1, Decl(generatorTypeCheck1.ts, 0, 0)) +>Iterator : Symbol(Iterator, Decl(lib.d.ts, 1662, 1)) + diff --git a/tests/baselines/reference/generatorTypeCheck1.types b/tests/baselines/reference/generatorTypeCheck1.types new file mode 100644 index 0000000000..3f02fe4b09 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck1.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck1.ts === +function* g1(): Iterator { } +>g1 : () => Iterator +>Iterator : Iterator + diff --git a/tests/baselines/reference/generatorTypeCheck10.js b/tests/baselines/reference/generatorTypeCheck10.js new file mode 100644 index 0000000000..252f301161 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck10.js @@ -0,0 +1,9 @@ +//// [generatorTypeCheck10.ts] +function* g(): IterableIterator { + return; +} + +//// [generatorTypeCheck10.js] +function* g() { + return; +} diff --git a/tests/baselines/reference/generatorTypeCheck10.symbols b/tests/baselines/reference/generatorTypeCheck10.symbols new file mode 100644 index 0000000000..c6eeb6b4a3 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck10.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck10.ts === +function* g(): IterableIterator { +>g : Symbol(g, Decl(generatorTypeCheck10.ts, 0, 0)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.d.ts, 1672, 1)) + + return; +} diff --git a/tests/baselines/reference/generatorTypeCheck10.types b/tests/baselines/reference/generatorTypeCheck10.types new file mode 100644 index 0000000000..f9304e3b16 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck10.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck10.ts === +function* g(): IterableIterator { +>g : () => IterableIterator +>IterableIterator : IterableIterator + + return; +} diff --git a/tests/baselines/reference/generatorTypeCheck11.js b/tests/baselines/reference/generatorTypeCheck11.js new file mode 100644 index 0000000000..4898f661f2 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck11.js @@ -0,0 +1,9 @@ +//// [generatorTypeCheck11.ts] +function* g(): IterableIterator { + return 0; +} + +//// [generatorTypeCheck11.js] +function* g() { + return 0; +} diff --git a/tests/baselines/reference/generatorTypeCheck11.symbols b/tests/baselines/reference/generatorTypeCheck11.symbols new file mode 100644 index 0000000000..b904dfb446 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck11.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck11.ts === +function* g(): IterableIterator { +>g : Symbol(g, Decl(generatorTypeCheck11.ts, 0, 0)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.d.ts, 1672, 1)) + + return 0; +} diff --git a/tests/baselines/reference/generatorTypeCheck11.types b/tests/baselines/reference/generatorTypeCheck11.types new file mode 100644 index 0000000000..ce47d49785 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck11.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck11.ts === +function* g(): IterableIterator { +>g : () => IterableIterator +>IterableIterator : IterableIterator + + return 0; +>0 : number +} diff --git a/tests/baselines/reference/generatorTypeCheck12.js b/tests/baselines/reference/generatorTypeCheck12.js new file mode 100644 index 0000000000..058b0a0772 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck12.js @@ -0,0 +1,9 @@ +//// [generatorTypeCheck12.ts] +function* g(): IterableIterator { + return ""; +} + +//// [generatorTypeCheck12.js] +function* g() { + return ""; +} diff --git a/tests/baselines/reference/generatorTypeCheck12.symbols b/tests/baselines/reference/generatorTypeCheck12.symbols new file mode 100644 index 0000000000..e596203b9e --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck12.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck12.ts === +function* g(): IterableIterator { +>g : Symbol(g, Decl(generatorTypeCheck12.ts, 0, 0)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.d.ts, 1672, 1)) + + return ""; +} diff --git a/tests/baselines/reference/generatorTypeCheck12.types b/tests/baselines/reference/generatorTypeCheck12.types new file mode 100644 index 0000000000..3dd3c20f18 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck12.types @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck12.ts === +function* g(): IterableIterator { +>g : () => IterableIterator +>IterableIterator : IterableIterator + + return ""; +>"" : string +} diff --git a/tests/baselines/reference/generatorTypeCheck13.js b/tests/baselines/reference/generatorTypeCheck13.js new file mode 100644 index 0000000000..26308b0ac7 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck13.js @@ -0,0 +1,11 @@ +//// [generatorTypeCheck13.ts] +function* g(): IterableIterator { + yield 0; + return ""; +} + +//// [generatorTypeCheck13.js] +function* g() { + yield 0; + return ""; +} diff --git a/tests/baselines/reference/generatorTypeCheck13.symbols b/tests/baselines/reference/generatorTypeCheck13.symbols new file mode 100644 index 0000000000..84e42a06cf --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck13.symbols @@ -0,0 +1,8 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck13.ts === +function* g(): IterableIterator { +>g : Symbol(g, Decl(generatorTypeCheck13.ts, 0, 0)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.d.ts, 1672, 1)) + + yield 0; + return ""; +} diff --git a/tests/baselines/reference/generatorTypeCheck13.types b/tests/baselines/reference/generatorTypeCheck13.types new file mode 100644 index 0000000000..d77b630ae7 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck13.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck13.ts === +function* g(): IterableIterator { +>g : () => IterableIterator +>IterableIterator : IterableIterator + + yield 0; +>yield 0 : any +>0 : number + + return ""; +>"" : string +} diff --git a/tests/baselines/reference/generatorTypeCheck14.js b/tests/baselines/reference/generatorTypeCheck14.js new file mode 100644 index 0000000000..a7dcc87a3a --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck14.js @@ -0,0 +1,11 @@ +//// [generatorTypeCheck14.ts] +function* g() { + yield 0; + return ""; +} + +//// [generatorTypeCheck14.js] +function* g() { + yield 0; + return ""; +} diff --git a/tests/baselines/reference/generatorTypeCheck14.symbols b/tests/baselines/reference/generatorTypeCheck14.symbols new file mode 100644 index 0000000000..36d10d8854 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck14.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck14.ts === +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck14.ts, 0, 0)) + + yield 0; + return ""; +} diff --git a/tests/baselines/reference/generatorTypeCheck14.types b/tests/baselines/reference/generatorTypeCheck14.types new file mode 100644 index 0000000000..db1b5bde19 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck14.types @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck14.ts === +function* g() { +>g : () => IterableIterator + + yield 0; +>yield 0 : any +>0 : number + + return ""; +>"" : string +} diff --git a/tests/baselines/reference/generatorTypeCheck15.js b/tests/baselines/reference/generatorTypeCheck15.js new file mode 100644 index 0000000000..d359c10048 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck15.js @@ -0,0 +1,9 @@ +//// [generatorTypeCheck15.ts] +function* g() { + return ""; +} + +//// [generatorTypeCheck15.js] +function* g() { + return ""; +} diff --git a/tests/baselines/reference/generatorTypeCheck15.symbols b/tests/baselines/reference/generatorTypeCheck15.symbols new file mode 100644 index 0000000000..3d914d0bd6 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck15.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck15.ts === +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck15.ts, 0, 0)) + + return ""; +} diff --git a/tests/baselines/reference/generatorTypeCheck15.types b/tests/baselines/reference/generatorTypeCheck15.types new file mode 100644 index 0000000000..4437d78572 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck15.types @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck15.ts === +function* g() { +>g : () => IterableIterator + + return ""; +>"" : string +} diff --git a/tests/baselines/reference/generatorTypeCheck16.js b/tests/baselines/reference/generatorTypeCheck16.js new file mode 100644 index 0000000000..7b8b93deab --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck16.js @@ -0,0 +1,9 @@ +//// [generatorTypeCheck16.ts] +function* g() { + return; +} + +//// [generatorTypeCheck16.js] +function* g() { + return; +} diff --git a/tests/baselines/reference/generatorTypeCheck16.symbols b/tests/baselines/reference/generatorTypeCheck16.symbols new file mode 100644 index 0000000000..bbc22cc4a2 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck16.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck16.ts === +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck16.ts, 0, 0)) + + return; +} diff --git a/tests/baselines/reference/generatorTypeCheck16.types b/tests/baselines/reference/generatorTypeCheck16.types new file mode 100644 index 0000000000..a607ad851c --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck16.types @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck16.ts === +function* g() { +>g : () => IterableIterator + + return; +} diff --git a/tests/baselines/reference/generatorTypeCheck17.js b/tests/baselines/reference/generatorTypeCheck17.js new file mode 100644 index 0000000000..8c3ebb59ea --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck17.js @@ -0,0 +1,17 @@ +//// [generatorTypeCheck17.ts] +class Foo { x: number } +class Bar extends Foo { y: string } +function* g(): IterableIterator { + yield; + yield new Bar; +} + +//// [generatorTypeCheck17.js] +class Foo { +} +class Bar extends Foo { +} +function* g() { + yield; + yield new Bar; +} diff --git a/tests/baselines/reference/generatorTypeCheck17.symbols b/tests/baselines/reference/generatorTypeCheck17.symbols new file mode 100644 index 0000000000..9e689d9df4 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck17.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck17.ts === +class Foo { x: number } +>Foo : Symbol(Foo, Decl(generatorTypeCheck17.ts, 0, 0)) +>x : Symbol(x, Decl(generatorTypeCheck17.ts, 0, 11)) + +class Bar extends Foo { y: string } +>Bar : Symbol(Bar, Decl(generatorTypeCheck17.ts, 0, 23)) +>Foo : Symbol(Foo, Decl(generatorTypeCheck17.ts, 0, 0)) +>y : Symbol(y, Decl(generatorTypeCheck17.ts, 1, 23)) + +function* g(): IterableIterator { +>g : Symbol(g, Decl(generatorTypeCheck17.ts, 1, 35)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.d.ts, 1672, 1)) +>Foo : Symbol(Foo, Decl(generatorTypeCheck17.ts, 0, 0)) + + yield; + yield new Bar; +>Bar : Symbol(Bar, Decl(generatorTypeCheck17.ts, 0, 23)) +} diff --git a/tests/baselines/reference/generatorTypeCheck17.types b/tests/baselines/reference/generatorTypeCheck17.types new file mode 100644 index 0000000000..0ea7212040 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck17.types @@ -0,0 +1,23 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck17.ts === +class Foo { x: number } +>Foo : Foo +>x : number + +class Bar extends Foo { y: string } +>Bar : Bar +>Foo : Foo +>y : string + +function* g(): IterableIterator { +>g : () => IterableIterator +>IterableIterator : IterableIterator +>Foo : Foo + + yield; +>yield : any + + yield new Bar; +>yield new Bar : any +>new Bar : Bar +>Bar : typeof Bar +} diff --git a/tests/baselines/reference/generatorTypeCheck18.errors.txt b/tests/baselines/reference/generatorTypeCheck18.errors.txt new file mode 100644 index 0000000000..2c6deab982 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck18.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck18.ts(5,11): error TS2322: Type 'Baz' is not assignable to type 'Foo'. + Property 'x' is missing in type 'Baz'. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck18.ts (1 errors) ==== + class Foo { x: number } + class Baz { z: number } + function* g(): IterableIterator { + yield; + yield new Baz; + ~~~~~~~ +!!! error TS2322: Type 'Baz' is not assignable to type 'Foo'. +!!! error TS2322: Property 'x' is missing in type 'Baz'. + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck18.js b/tests/baselines/reference/generatorTypeCheck18.js new file mode 100644 index 0000000000..5907dd14b2 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck18.js @@ -0,0 +1,17 @@ +//// [generatorTypeCheck18.ts] +class Foo { x: number } +class Baz { z: number } +function* g(): IterableIterator { + yield; + yield new Baz; +} + +//// [generatorTypeCheck18.js] +class Foo { +} +class Baz { +} +function* g() { + yield; + yield new Baz; +} diff --git a/tests/baselines/reference/generatorTypeCheck19.js b/tests/baselines/reference/generatorTypeCheck19.js new file mode 100644 index 0000000000..375d7b36ec --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck19.js @@ -0,0 +1,17 @@ +//// [generatorTypeCheck19.ts] +class Foo { x: number } +class Bar extends Foo { y: string } +function* g(): IterableIterator { + yield; + yield * [new Bar]; +} + +//// [generatorTypeCheck19.js] +class Foo { +} +class Bar extends Foo { +} +function* g() { + yield; + yield* [new Bar]; +} diff --git a/tests/baselines/reference/generatorTypeCheck19.symbols b/tests/baselines/reference/generatorTypeCheck19.symbols new file mode 100644 index 0000000000..2edec8fd21 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck19.symbols @@ -0,0 +1,19 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck19.ts === +class Foo { x: number } +>Foo : Symbol(Foo, Decl(generatorTypeCheck19.ts, 0, 0)) +>x : Symbol(x, Decl(generatorTypeCheck19.ts, 0, 11)) + +class Bar extends Foo { y: string } +>Bar : Symbol(Bar, Decl(generatorTypeCheck19.ts, 0, 23)) +>Foo : Symbol(Foo, Decl(generatorTypeCheck19.ts, 0, 0)) +>y : Symbol(y, Decl(generatorTypeCheck19.ts, 1, 23)) + +function* g(): IterableIterator { +>g : Symbol(g, Decl(generatorTypeCheck19.ts, 1, 35)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.d.ts, 1672, 1)) +>Foo : Symbol(Foo, Decl(generatorTypeCheck19.ts, 0, 0)) + + yield; + yield * [new Bar]; +>Bar : Symbol(Bar, Decl(generatorTypeCheck19.ts, 0, 23)) +} diff --git a/tests/baselines/reference/generatorTypeCheck19.types b/tests/baselines/reference/generatorTypeCheck19.types new file mode 100644 index 0000000000..2b4f1396c2 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck19.types @@ -0,0 +1,24 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck19.ts === +class Foo { x: number } +>Foo : Foo +>x : number + +class Bar extends Foo { y: string } +>Bar : Bar +>Foo : Foo +>y : string + +function* g(): IterableIterator { +>g : () => IterableIterator +>IterableIterator : IterableIterator +>Foo : Foo + + yield; +>yield : any + + yield * [new Bar]; +>yield * [new Bar] : any +>[new Bar] : Bar[] +>new Bar : Bar +>Bar : typeof Bar +} diff --git a/tests/baselines/reference/generatorTypeCheck2.js b/tests/baselines/reference/generatorTypeCheck2.js new file mode 100644 index 0000000000..559946b0fc --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck2.js @@ -0,0 +1,5 @@ +//// [generatorTypeCheck2.ts] +function* g1(): Iterable { } + +//// [generatorTypeCheck2.js] +function* g1() { } diff --git a/tests/baselines/reference/generatorTypeCheck2.symbols b/tests/baselines/reference/generatorTypeCheck2.symbols new file mode 100644 index 0000000000..e066878659 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck2.symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck2.ts === +function* g1(): Iterable { } +>g1 : Symbol(g1, Decl(generatorTypeCheck2.ts, 0, 0)) +>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1)) + diff --git a/tests/baselines/reference/generatorTypeCheck2.types b/tests/baselines/reference/generatorTypeCheck2.types new file mode 100644 index 0000000000..882367fa3d --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck2.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck2.ts === +function* g1(): Iterable { } +>g1 : () => Iterable +>Iterable : Iterable + diff --git a/tests/baselines/reference/generatorTypeCheck20.errors.txt b/tests/baselines/reference/generatorTypeCheck20.errors.txt new file mode 100644 index 0000000000..c6e8200d10 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck20.errors.txt @@ -0,0 +1,14 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck20.ts(5,13): error TS2322: Type 'Baz' is not assignable to type 'Foo'. + Property 'x' is missing in type 'Baz'. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck20.ts (1 errors) ==== + class Foo { x: number } + class Baz { z: number } + function* g(): IterableIterator { + yield; + yield * [new Baz]; + ~~~~~~~~~ +!!! error TS2322: Type 'Baz' is not assignable to type 'Foo'. +!!! error TS2322: Property 'x' is missing in type 'Baz'. + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck20.js b/tests/baselines/reference/generatorTypeCheck20.js new file mode 100644 index 0000000000..c7336079bf --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck20.js @@ -0,0 +1,17 @@ +//// [generatorTypeCheck20.ts] +class Foo { x: number } +class Baz { z: number } +function* g(): IterableIterator { + yield; + yield * [new Baz]; +} + +//// [generatorTypeCheck20.js] +class Foo { +} +class Baz { +} +function* g() { + yield; + yield* [new Baz]; +} diff --git a/tests/baselines/reference/generatorTypeCheck21.errors.txt b/tests/baselines/reference/generatorTypeCheck21.errors.txt new file mode 100644 index 0000000000..0ef66aa1bd --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck21.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck21.ts(5,13): error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck21.ts (1 errors) ==== + class Foo { x: number } + class Bar extends Foo { y: string } + function* g(): IterableIterator { + yield; + yield * new Bar; + ~~~~~~~ +!!! error TS2488: Type must have a '[Symbol.iterator]()' method that returns an iterator. + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck21.js b/tests/baselines/reference/generatorTypeCheck21.js new file mode 100644 index 0000000000..83d1007a2c --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck21.js @@ -0,0 +1,17 @@ +//// [generatorTypeCheck21.ts] +class Foo { x: number } +class Bar extends Foo { y: string } +function* g(): IterableIterator { + yield; + yield * new Bar; +} + +//// [generatorTypeCheck21.js] +class Foo { +} +class Bar extends Foo { +} +function* g() { + yield; + yield* new Bar; +} diff --git a/tests/baselines/reference/generatorTypeCheck22.errors.txt b/tests/baselines/reference/generatorTypeCheck22.errors.txt new file mode 100644 index 0000000000..ab2b3de4f4 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck22.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck22.ts(4,11): error TS2504: No best common type exists among yield expressions. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck22.ts (1 errors) ==== + class Foo { x: number } + class Bar extends Foo { y: string } + class Baz { z: number } + function* g3() { + ~~ +!!! error TS2504: No best common type exists among yield expressions. + yield; + yield new Bar; + yield new Baz; + yield *[new Bar]; + yield *[new Baz]; + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck22.js b/tests/baselines/reference/generatorTypeCheck22.js new file mode 100644 index 0000000000..0045e115e6 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck22.js @@ -0,0 +1,26 @@ +//// [generatorTypeCheck22.ts] +class Foo { x: number } +class Bar extends Foo { y: string } +class Baz { z: number } +function* g3() { + yield; + yield new Bar; + yield new Baz; + yield *[new Bar]; + yield *[new Baz]; +} + +//// [generatorTypeCheck22.js] +class Foo { +} +class Bar extends Foo { +} +class Baz { +} +function* g3() { + yield; + yield new Bar; + yield new Baz; + yield* [new Bar]; + yield* [new Baz]; +} diff --git a/tests/baselines/reference/generatorTypeCheck23.errors.txt b/tests/baselines/reference/generatorTypeCheck23.errors.txt new file mode 100644 index 0000000000..9e85117a0a --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck23.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck23.ts(4,11): error TS2504: No best common type exists among yield expressions. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck23.ts (1 errors) ==== + class Foo { x: number } + class Bar extends Foo { y: string } + class Baz { z: number } + function* g3() { + ~~ +!!! error TS2504: No best common type exists among yield expressions. + yield; + yield new Foo; + yield new Bar; + yield new Baz; + yield *[new Bar]; + yield *[new Baz]; + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck23.js b/tests/baselines/reference/generatorTypeCheck23.js new file mode 100644 index 0000000000..37c2c239e2 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck23.js @@ -0,0 +1,28 @@ +//// [generatorTypeCheck23.ts] +class Foo { x: number } +class Bar extends Foo { y: string } +class Baz { z: number } +function* g3() { + yield; + yield new Foo; + yield new Bar; + yield new Baz; + yield *[new Bar]; + yield *[new Baz]; +} + +//// [generatorTypeCheck23.js] +class Foo { +} +class Bar extends Foo { +} +class Baz { +} +function* g3() { + yield; + yield new Foo; + yield new Bar; + yield new Baz; + yield* [new Bar]; + yield* [new Baz]; +} diff --git a/tests/baselines/reference/generatorTypeCheck24.errors.txt b/tests/baselines/reference/generatorTypeCheck24.errors.txt new file mode 100644 index 0000000000..b4ca13c14c --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck24.errors.txt @@ -0,0 +1,17 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck24.ts(4,11): error TS2504: No best common type exists among yield expressions. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck24.ts (1 errors) ==== + class Foo { x: number } + class Bar extends Foo { y: string } + class Baz { z: number } + function* g3() { + ~~ +!!! error TS2504: No best common type exists among yield expressions. + yield; + yield * [new Foo]; + yield new Bar; + yield new Baz; + yield *[new Bar]; + yield *[new Baz]; + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck24.js b/tests/baselines/reference/generatorTypeCheck24.js new file mode 100644 index 0000000000..8b6018243c --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck24.js @@ -0,0 +1,28 @@ +//// [generatorTypeCheck24.ts] +class Foo { x: number } +class Bar extends Foo { y: string } +class Baz { z: number } +function* g3() { + yield; + yield * [new Foo]; + yield new Bar; + yield new Baz; + yield *[new Bar]; + yield *[new Baz]; +} + +//// [generatorTypeCheck24.js] +class Foo { +} +class Bar extends Foo { +} +class Baz { +} +function* g3() { + yield; + yield* [new Foo]; + yield new Bar; + yield new Baz; + yield* [new Bar]; + yield* [new Baz]; +} diff --git a/tests/baselines/reference/generatorTypeCheck25.errors.txt b/tests/baselines/reference/generatorTypeCheck25.errors.txt new file mode 100644 index 0000000000..8d414c7c47 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck25.errors.txt @@ -0,0 +1,36 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck25.ts(4,5): error TS2322: Type '() => IterableIterator' is not assignable to type '() => Iterable'. + Type 'IterableIterator' is not assignable to type 'Iterable'. + Types of property '[Symbol.iterator]' are incompatible. + Type '() => IterableIterator' is not assignable to type '() => Iterator'. + Type 'IterableIterator' is not assignable to type 'Iterator'. + Types of property 'next' are incompatible. + Type '(value?: any) => IteratorResult' is not assignable to type '(value?: any) => IteratorResult'. + Type 'IteratorResult' is not assignable to type 'IteratorResult'. + Type 'Bar | Baz' is not assignable to type 'Foo'. + Type 'Baz' is not assignable to type 'Foo'. + Property 'x' is missing in type 'Baz'. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck25.ts (1 errors) ==== + class Foo { x: number } + class Bar extends Foo { y: string } + class Baz { z: number } + var g3: () => Iterable = function* () { + ~~ +!!! error TS2322: Type '() => IterableIterator' is not assignable to type '() => Iterable'. +!!! error TS2322: Type 'IterableIterator' is not assignable to type 'Iterable'. +!!! error TS2322: Types of property '[Symbol.iterator]' are incompatible. +!!! error TS2322: Type '() => IterableIterator' is not assignable to type '() => Iterator'. +!!! error TS2322: Type 'IterableIterator' is not assignable to type 'Iterator'. +!!! error TS2322: Types of property 'next' are incompatible. +!!! error TS2322: Type '(value?: any) => IteratorResult' is not assignable to type '(value?: any) => IteratorResult'. +!!! error TS2322: Type 'IteratorResult' is not assignable to type 'IteratorResult'. +!!! error TS2322: Type 'Bar | Baz' is not assignable to type 'Foo'. +!!! error TS2322: Type 'Baz' is not assignable to type 'Foo'. +!!! error TS2322: Property 'x' is missing in type 'Baz'. + yield; + yield new Bar; + yield new Baz; + yield *[new Bar]; + yield *[new Baz]; + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck25.js b/tests/baselines/reference/generatorTypeCheck25.js new file mode 100644 index 0000000000..894561bcc9 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck25.js @@ -0,0 +1,26 @@ +//// [generatorTypeCheck25.ts] +class Foo { x: number } +class Bar extends Foo { y: string } +class Baz { z: number } +var g3: () => Iterable = function* () { + yield; + yield new Bar; + yield new Baz; + yield *[new Bar]; + yield *[new Baz]; +} + +//// [generatorTypeCheck25.js] +class Foo { +} +class Bar extends Foo { +} +class Baz { +} +var g3 = function* () { + yield; + yield new Bar; + yield new Baz; + yield* [new Bar]; + yield* [new Baz]; +}; diff --git a/tests/baselines/reference/generatorTypeCheck26.js b/tests/baselines/reference/generatorTypeCheck26.js new file mode 100644 index 0000000000..d5c1a4c794 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck26.js @@ -0,0 +1,13 @@ +//// [generatorTypeCheck26.ts] +function* g(): IterableIterator<(x: string) => number> { + yield x => x.length; + yield *[x => x.length]; + return x => x.length; +} + +//// [generatorTypeCheck26.js] +function* g() { + yield x => x.length; + yield* [x => x.length]; + return x => x.length; +} diff --git a/tests/baselines/reference/generatorTypeCheck26.symbols b/tests/baselines/reference/generatorTypeCheck26.symbols new file mode 100644 index 0000000000..4d3ad86256 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck26.symbols @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck26.ts === +function* g(): IterableIterator<(x: string) => number> { +>g : Symbol(g, Decl(generatorTypeCheck26.ts, 0, 0)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.d.ts, 1672, 1)) +>x : Symbol(x, Decl(generatorTypeCheck26.ts, 0, 33)) + + yield x => x.length; +>x : Symbol(x, Decl(generatorTypeCheck26.ts, 1, 9)) +>x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) +>x : Symbol(x, Decl(generatorTypeCheck26.ts, 1, 9)) +>length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) + + yield *[x => x.length]; +>x : Symbol(x, Decl(generatorTypeCheck26.ts, 2, 12)) +>x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) +>x : Symbol(x, Decl(generatorTypeCheck26.ts, 2, 12)) +>length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) + + return x => x.length; +>x : Symbol(x, Decl(generatorTypeCheck26.ts, 3, 10)) +>x : Symbol(x, Decl(generatorTypeCheck26.ts, 3, 10)) +} diff --git a/tests/baselines/reference/generatorTypeCheck26.types b/tests/baselines/reference/generatorTypeCheck26.types new file mode 100644 index 0000000000..8141a866c8 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck26.types @@ -0,0 +1,30 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck26.ts === +function* g(): IterableIterator<(x: string) => number> { +>g : () => IterableIterator<(x: string) => number> +>IterableIterator : IterableIterator +>x : string + + yield x => x.length; +>yield x => x.length : any +>x => x.length : (x: string) => number +>x : string +>x.length : number +>x : string +>length : number + + yield *[x => x.length]; +>yield *[x => x.length] : any +>[x => x.length] : ((x: string) => number)[] +>x => x.length : (x: string) => number +>x : string +>x.length : number +>x : string +>length : number + + return x => x.length; +>x => x.length : (x: any) => any +>x : any +>x.length : any +>x : any +>length : any +} diff --git a/tests/baselines/reference/generatorTypeCheck27.js b/tests/baselines/reference/generatorTypeCheck27.js new file mode 100644 index 0000000000..528d510bed --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck27.js @@ -0,0 +1,13 @@ +//// [generatorTypeCheck27.ts] +function* g(): IterableIterator<(x: string) => number> { + yield * function* () { + yield x => x.length; + } (); +} + +//// [generatorTypeCheck27.js] +function* g() { + yield* function* () { + yield x => x.length; + }(); +} diff --git a/tests/baselines/reference/generatorTypeCheck27.symbols b/tests/baselines/reference/generatorTypeCheck27.symbols new file mode 100644 index 0000000000..bfff5f9e10 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck27.symbols @@ -0,0 +1,13 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck27.ts === +function* g(): IterableIterator<(x: string) => number> { +>g : Symbol(g, Decl(generatorTypeCheck27.ts, 0, 0)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.d.ts, 1672, 1)) +>x : Symbol(x, Decl(generatorTypeCheck27.ts, 0, 33)) + + yield * function* () { + yield x => x.length; +>x : Symbol(x, Decl(generatorTypeCheck27.ts, 2, 13)) +>x : Symbol(x, Decl(generatorTypeCheck27.ts, 2, 13)) + + } (); +} diff --git a/tests/baselines/reference/generatorTypeCheck27.types b/tests/baselines/reference/generatorTypeCheck27.types new file mode 100644 index 0000000000..7b120cfffc --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck27.types @@ -0,0 +1,21 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck27.ts === +function* g(): IterableIterator<(x: string) => number> { +>g : () => IterableIterator<(x: string) => number> +>IterableIterator : IterableIterator +>x : string + + yield * function* () { +>yield * function* () { yield x => x.length; } () : any +>function* () { yield x => x.length; } () : IterableIterator<(x: any) => any> +>function* () { yield x => x.length; } : () => IterableIterator<(x: any) => any> + + yield x => x.length; +>yield x => x.length : any +>x => x.length : (x: any) => any +>x : any +>x.length : any +>x : any +>length : any + + } (); +} diff --git a/tests/baselines/reference/generatorTypeCheck28.js b/tests/baselines/reference/generatorTypeCheck28.js new file mode 100644 index 0000000000..e94fd9b7e3 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck28.js @@ -0,0 +1,17 @@ +//// [generatorTypeCheck28.ts] +function* g(): IterableIterator<(x: string) => number> { + yield * { + *[Symbol.iterator]() { + yield x => x.length; + } + }; +} + +//// [generatorTypeCheck28.js] +function* g() { + yield* { + *[Symbol.iterator]() { + yield x => x.length; + } + }; +} diff --git a/tests/baselines/reference/generatorTypeCheck28.symbols b/tests/baselines/reference/generatorTypeCheck28.symbols new file mode 100644 index 0000000000..e1bbbd96b4 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck28.symbols @@ -0,0 +1,20 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck28.ts === +function* g(): IterableIterator<(x: string) => number> { +>g : Symbol(g, Decl(generatorTypeCheck28.ts, 0, 0)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.d.ts, 1672, 1)) +>x : Symbol(x, Decl(generatorTypeCheck28.ts, 0, 33)) + + yield * { + *[Symbol.iterator]() { +>Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31)) +>Symbol : Symbol(Symbol, Decl(lib.d.ts, 1186, 52), Decl(lib.d.ts, 1292, 11)) +>iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31)) + + yield x => x.length; +>x : Symbol(x, Decl(generatorTypeCheck28.ts, 3, 17)) +>x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) +>x : Symbol(x, Decl(generatorTypeCheck28.ts, 3, 17)) +>length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) + } + }; +} diff --git a/tests/baselines/reference/generatorTypeCheck28.types b/tests/baselines/reference/generatorTypeCheck28.types new file mode 100644 index 0000000000..1afae07275 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck28.types @@ -0,0 +1,25 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck28.ts === +function* g(): IterableIterator<(x: string) => number> { +>g : () => IterableIterator<(x: string) => number> +>IterableIterator : IterableIterator +>x : string + + yield * { +>yield * { *[Symbol.iterator]() { yield x => x.length; } } : any +>{ *[Symbol.iterator]() { yield x => x.length; } } : { [Symbol.iterator](): IterableIterator<(x: string) => number>; } + + *[Symbol.iterator]() { +>Symbol.iterator : symbol +>Symbol : SymbolConstructor +>iterator : symbol + + yield x => x.length; +>yield x => x.length : any +>x => x.length : (x: string) => number +>x : string +>x.length : number +>x : string +>length : number + } + }; +} diff --git a/tests/baselines/reference/generatorTypeCheck29.js b/tests/baselines/reference/generatorTypeCheck29.js new file mode 100644 index 0000000000..4f5204f89f --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck29.js @@ -0,0 +1,13 @@ +//// [generatorTypeCheck29.ts] +function* g2(): Iterator number>> { + yield function* () { + yield x => x.length; + } () +} + +//// [generatorTypeCheck29.js] +function* g2() { + yield function* () { + yield x => x.length; + }(); +} diff --git a/tests/baselines/reference/generatorTypeCheck29.symbols b/tests/baselines/reference/generatorTypeCheck29.symbols new file mode 100644 index 0000000000..57790d5b70 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck29.symbols @@ -0,0 +1,14 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck29.ts === +function* g2(): Iterator number>> { +>g2 : Symbol(g2, Decl(generatorTypeCheck29.ts, 0, 0)) +>Iterator : Symbol(Iterator, Decl(lib.d.ts, 1662, 1)) +>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1)) +>x : Symbol(x, Decl(generatorTypeCheck29.ts, 0, 35)) + + yield function* () { + yield x => x.length; +>x : Symbol(x, Decl(generatorTypeCheck29.ts, 2, 13)) +>x : Symbol(x, Decl(generatorTypeCheck29.ts, 2, 13)) + + } () +} diff --git a/tests/baselines/reference/generatorTypeCheck29.types b/tests/baselines/reference/generatorTypeCheck29.types new file mode 100644 index 0000000000..85cb32e575 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck29.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck29.ts === +function* g2(): Iterator number>> { +>g2 : () => Iterator number>> +>Iterator : Iterator +>Iterable : Iterable +>x : string + + yield function* () { +>yield function* () { yield x => x.length; } () : any +>function* () { yield x => x.length; } () : IterableIterator<(x: any) => any> +>function* () { yield x => x.length; } : () => IterableIterator<(x: any) => any> + + yield x => x.length; +>yield x => x.length : any +>x => x.length : (x: any) => any +>x : any +>x.length : any +>x : any +>length : any + + } () +} diff --git a/tests/baselines/reference/generatorTypeCheck3.js b/tests/baselines/reference/generatorTypeCheck3.js new file mode 100644 index 0000000000..9d884a92f5 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck3.js @@ -0,0 +1,5 @@ +//// [generatorTypeCheck3.ts] +function* g1(): IterableIterator { } + +//// [generatorTypeCheck3.js] +function* g1() { } diff --git a/tests/baselines/reference/generatorTypeCheck3.symbols b/tests/baselines/reference/generatorTypeCheck3.symbols new file mode 100644 index 0000000000..2f5d240550 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck3.symbols @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck3.ts === +function* g1(): IterableIterator { } +>g1 : Symbol(g1, Decl(generatorTypeCheck3.ts, 0, 0)) +>IterableIterator : Symbol(IterableIterator, Decl(lib.d.ts, 1672, 1)) + diff --git a/tests/baselines/reference/generatorTypeCheck3.types b/tests/baselines/reference/generatorTypeCheck3.types new file mode 100644 index 0000000000..9d2fb9d517 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck3.types @@ -0,0 +1,5 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck3.ts === +function* g1(): IterableIterator { } +>g1 : () => IterableIterator +>IterableIterator : IterableIterator + diff --git a/tests/baselines/reference/generatorTypeCheck30.js b/tests/baselines/reference/generatorTypeCheck30.js new file mode 100644 index 0000000000..e652dd1b55 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck30.js @@ -0,0 +1,13 @@ +//// [generatorTypeCheck30.ts] +function* g2(): Iterator number>> { + yield function* () { + yield x => x.length; + } () +} + +//// [generatorTypeCheck30.js] +function* g2() { + yield function* () { + yield x => x.length; + }(); +} diff --git a/tests/baselines/reference/generatorTypeCheck30.symbols b/tests/baselines/reference/generatorTypeCheck30.symbols new file mode 100644 index 0000000000..49c43ce135 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck30.symbols @@ -0,0 +1,14 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck30.ts === +function* g2(): Iterator number>> { +>g2 : Symbol(g2, Decl(generatorTypeCheck30.ts, 0, 0)) +>Iterator : Symbol(Iterator, Decl(lib.d.ts, 1662, 1)) +>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1)) +>x : Symbol(x, Decl(generatorTypeCheck30.ts, 0, 35)) + + yield function* () { + yield x => x.length; +>x : Symbol(x, Decl(generatorTypeCheck30.ts, 2, 13)) +>x : Symbol(x, Decl(generatorTypeCheck30.ts, 2, 13)) + + } () +} diff --git a/tests/baselines/reference/generatorTypeCheck30.types b/tests/baselines/reference/generatorTypeCheck30.types new file mode 100644 index 0000000000..2ed94dff53 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck30.types @@ -0,0 +1,22 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck30.ts === +function* g2(): Iterator number>> { +>g2 : () => Iterator number>> +>Iterator : Iterator +>Iterable : Iterable +>x : string + + yield function* () { +>yield function* () { yield x => x.length; } () : any +>function* () { yield x => x.length; } () : IterableIterator<(x: any) => any> +>function* () { yield x => x.length; } : () => IterableIterator<(x: any) => any> + + yield x => x.length; +>yield x => x.length : any +>x => x.length : (x: any) => any +>x : any +>x.length : any +>x : any +>length : any + + } () +} diff --git a/tests/baselines/reference/generatorTypeCheck31.errors.txt b/tests/baselines/reference/generatorTypeCheck31.errors.txt new file mode 100644 index 0000000000..a0336b464a --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck31.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts(2,11): error TS2322: Type 'IterableIterator<(x: any) => any>' is not assignable to type '() => Iterable<(x: string) => number>'. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts (1 errors) ==== + function* g2(): Iterator<() => Iterable<(x: string) => number>> { + yield function* () { + ~~~~~~~~~~~~~~ + yield x => x.length; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + } () + ~~~~~~~~ +!!! error TS2322: Type 'IterableIterator<(x: any) => any>' is not assignable to type '() => Iterable<(x: string) => number>'. + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck31.js b/tests/baselines/reference/generatorTypeCheck31.js new file mode 100644 index 0000000000..2037b0ec62 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck31.js @@ -0,0 +1,13 @@ +//// [generatorTypeCheck31.ts] +function* g2(): Iterator<() => Iterable<(x: string) => number>> { + yield function* () { + yield x => x.length; + } () +} + +//// [generatorTypeCheck31.js] +function* g2() { + yield function* () { + yield x => x.length; + }(); +} diff --git a/tests/baselines/reference/generatorTypeCheck32.errors.txt b/tests/baselines/reference/generatorTypeCheck32.errors.txt new file mode 100644 index 0000000000..9312371d7e --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck32.errors.txt @@ -0,0 +1,8 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck32.ts(2,29): error TS1163: A 'yield' expression is only allowed in a generator body. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck32.ts (1 errors) ==== + var s: string; + var f: () => number = () => yield s; + ~~~~~ +!!! error TS1163: A 'yield' expression is only allowed in a generator body. \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck32.js b/tests/baselines/reference/generatorTypeCheck32.js new file mode 100644 index 0000000000..5ec8e9214f --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck32.js @@ -0,0 +1,7 @@ +//// [generatorTypeCheck32.ts] +var s: string; +var f: () => number = () => yield s; + +//// [generatorTypeCheck32.js] +var s; +var f = () => yield s; diff --git a/tests/baselines/reference/generatorTypeCheck33.js b/tests/baselines/reference/generatorTypeCheck33.js new file mode 100644 index 0000000000..256e4c94be --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck33.js @@ -0,0 +1,15 @@ +//// [generatorTypeCheck33.ts] +function* g() { + yield 0; + function* g2() { + yield ""; + } +} + +//// [generatorTypeCheck33.js] +function* g() { + yield 0; + function* g2() { + yield ""; + } +} diff --git a/tests/baselines/reference/generatorTypeCheck33.symbols b/tests/baselines/reference/generatorTypeCheck33.symbols new file mode 100644 index 0000000000..b1bda8808f --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck33.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck33.ts === +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck33.ts, 0, 0)) + + yield 0; + function* g2() { +>g2 : Symbol(g2, Decl(generatorTypeCheck33.ts, 1, 12)) + + yield ""; + } +} diff --git a/tests/baselines/reference/generatorTypeCheck33.types b/tests/baselines/reference/generatorTypeCheck33.types new file mode 100644 index 0000000000..f3b8af225d --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck33.types @@ -0,0 +1,16 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck33.ts === +function* g() { +>g : () => IterableIterator + + yield 0; +>yield 0 : any +>0 : number + + function* g2() { +>g2 : () => IterableIterator + + yield ""; +>yield "" : any +>"" : string + } +} diff --git a/tests/baselines/reference/generatorTypeCheck34.js b/tests/baselines/reference/generatorTypeCheck34.js new file mode 100644 index 0000000000..20b88b9a09 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck34.js @@ -0,0 +1,15 @@ +//// [generatorTypeCheck34.ts] +function* g() { + yield 0; + function* g2() { + return ""; + } +} + +//// [generatorTypeCheck34.js] +function* g() { + yield 0; + function* g2() { + return ""; + } +} diff --git a/tests/baselines/reference/generatorTypeCheck34.symbols b/tests/baselines/reference/generatorTypeCheck34.symbols new file mode 100644 index 0000000000..343b68c3bd --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck34.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck34.ts === +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck34.ts, 0, 0)) + + yield 0; + function* g2() { +>g2 : Symbol(g2, Decl(generatorTypeCheck34.ts, 1, 12)) + + return ""; + } +} diff --git a/tests/baselines/reference/generatorTypeCheck34.types b/tests/baselines/reference/generatorTypeCheck34.types new file mode 100644 index 0000000000..35063e988e --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck34.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck34.ts === +function* g() { +>g : () => IterableIterator + + yield 0; +>yield 0 : any +>0 : number + + function* g2() { +>g2 : () => IterableIterator + + return ""; +>"" : string + } +} diff --git a/tests/baselines/reference/generatorTypeCheck35.js b/tests/baselines/reference/generatorTypeCheck35.js new file mode 100644 index 0000000000..e2b1c10850 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck35.js @@ -0,0 +1,15 @@ +//// [generatorTypeCheck35.ts] +function* g() { + yield 0; + function g2() { + return ""; + } +} + +//// [generatorTypeCheck35.js] +function* g() { + yield 0; + function g2() { + return ""; + } +} diff --git a/tests/baselines/reference/generatorTypeCheck35.symbols b/tests/baselines/reference/generatorTypeCheck35.symbols new file mode 100644 index 0000000000..43271b79e9 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck35.symbols @@ -0,0 +1,11 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck35.ts === +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck35.ts, 0, 0)) + + yield 0; + function g2() { +>g2 : Symbol(g2, Decl(generatorTypeCheck35.ts, 1, 12)) + + return ""; + } +} diff --git a/tests/baselines/reference/generatorTypeCheck35.types b/tests/baselines/reference/generatorTypeCheck35.types new file mode 100644 index 0000000000..0bfc22ab3f --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck35.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck35.ts === +function* g() { +>g : () => IterableIterator + + yield 0; +>yield 0 : any +>0 : number + + function g2() { +>g2 : () => string + + return ""; +>"" : string + } +} diff --git a/tests/baselines/reference/generatorTypeCheck36.js b/tests/baselines/reference/generatorTypeCheck36.js new file mode 100644 index 0000000000..a207860603 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck36.js @@ -0,0 +1,9 @@ +//// [generatorTypeCheck36.ts] +function* g() { + yield yield 0; +} + +//// [generatorTypeCheck36.js] +function* g() { + yield yield 0; +} diff --git a/tests/baselines/reference/generatorTypeCheck36.symbols b/tests/baselines/reference/generatorTypeCheck36.symbols new file mode 100644 index 0000000000..dc7eb37fe3 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck36.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck36.ts === +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck36.ts, 0, 0)) + + yield yield 0; +} diff --git a/tests/baselines/reference/generatorTypeCheck36.types b/tests/baselines/reference/generatorTypeCheck36.types new file mode 100644 index 0000000000..110a4d3e02 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck36.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck36.ts === +function* g() { +>g : () => IterableIterator + + yield yield 0; +>yield yield 0 : any +>yield 0 : any +>0 : number +} diff --git a/tests/baselines/reference/generatorTypeCheck37.js b/tests/baselines/reference/generatorTypeCheck37.js new file mode 100644 index 0000000000..4c73dfe558 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck37.js @@ -0,0 +1,9 @@ +//// [generatorTypeCheck37.ts] +function* g() { + return yield yield 0; +} + +//// [generatorTypeCheck37.js] +function* g() { + return yield yield 0; +} diff --git a/tests/baselines/reference/generatorTypeCheck37.symbols b/tests/baselines/reference/generatorTypeCheck37.symbols new file mode 100644 index 0000000000..8939c5382e --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck37.symbols @@ -0,0 +1,6 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck37.ts === +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck37.ts, 0, 0)) + + return yield yield 0; +} diff --git a/tests/baselines/reference/generatorTypeCheck37.types b/tests/baselines/reference/generatorTypeCheck37.types new file mode 100644 index 0000000000..e8611ec167 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck37.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck37.ts === +function* g() { +>g : () => IterableIterator + + return yield yield 0; +>yield yield 0 : any +>yield 0 : any +>0 : number +} diff --git a/tests/baselines/reference/generatorTypeCheck38.js b/tests/baselines/reference/generatorTypeCheck38.js new file mode 100644 index 0000000000..de5258db78 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck38.js @@ -0,0 +1,13 @@ +//// [generatorTypeCheck38.ts] +var yield; +function* g() { + yield 0; + var v: typeof yield; +} + +//// [generatorTypeCheck38.js] +var yield; +function* g() { + yield 0; + var v; +} diff --git a/tests/baselines/reference/generatorTypeCheck38.symbols b/tests/baselines/reference/generatorTypeCheck38.symbols new file mode 100644 index 0000000000..83410159b1 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck38.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck38.ts === +var yield; +>yield : Symbol(yield, Decl(generatorTypeCheck38.ts, 0, 3)) + +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck38.ts, 0, 10)) + + yield 0; + var v: typeof yield; +>v : Symbol(v, Decl(generatorTypeCheck38.ts, 3, 7)) +>yield : Symbol(yield, Decl(generatorTypeCheck38.ts, 0, 3)) +} diff --git a/tests/baselines/reference/generatorTypeCheck38.types b/tests/baselines/reference/generatorTypeCheck38.types new file mode 100644 index 0000000000..08503e8640 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck38.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck38.ts === +var yield; +>yield : any + +function* g() { +>g : () => IterableIterator + + yield 0; +>yield 0 : any +>0 : number + + var v: typeof yield; +>v : any +>yield : any +} diff --git a/tests/baselines/reference/generatorTypeCheck39.errors.txt b/tests/baselines/reference/generatorTypeCheck39.errors.txt new file mode 100644 index 0000000000..ae24837f71 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck39.errors.txt @@ -0,0 +1,21 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(5,16): error TS1163: A 'yield' expression is only allowed in a generator body. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(6,11): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts(7,13): error TS1163: A 'yield' expression is only allowed in a generator body. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts (3 errors) ==== + function decorator(x: any) { + return y => { }; + } + function* g() { + @decorator(yield 0) + ~~~~~ +!!! error TS1163: A 'yield' expression is only allowed in a generator body. + class C { + ~ +!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning. + x = yield 0; + ~~~~~ +!!! error TS1163: A 'yield' expression is only allowed in a generator body. + } + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck39.js b/tests/baselines/reference/generatorTypeCheck39.js new file mode 100644 index 0000000000..e6d25045a7 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck39.js @@ -0,0 +1,33 @@ +//// [generatorTypeCheck39.ts] +function decorator(x: any) { + return y => { }; +} +function* g() { + @decorator(yield 0) + class C { + x = yield 0; + } +} + +//// [generatorTypeCheck39.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); + switch (arguments.length) { + case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); + case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); + case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); + } +}; +function decorator(x) { + return y => { }; +} +function* g() { + let C = class { + constructor() { + this.x = yield 0; + } + }; + C = __decorate([ + decorator(yield 0) + ], C); +} diff --git a/tests/baselines/reference/generatorTypeCheck4.js b/tests/baselines/reference/generatorTypeCheck4.js new file mode 100644 index 0000000000..8c0d7aeddd --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck4.js @@ -0,0 +1,5 @@ +//// [generatorTypeCheck4.ts] +function* g1(): {} { } + +//// [generatorTypeCheck4.js] +function* g1() { } diff --git a/tests/baselines/reference/generatorTypeCheck4.symbols b/tests/baselines/reference/generatorTypeCheck4.symbols new file mode 100644 index 0000000000..fb7cd93e0d --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck4.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck4.ts === +function* g1(): {} { } +>g1 : Symbol(g1, Decl(generatorTypeCheck4.ts, 0, 0)) + diff --git a/tests/baselines/reference/generatorTypeCheck4.types b/tests/baselines/reference/generatorTypeCheck4.types new file mode 100644 index 0000000000..c90fda0c0f --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck4.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck4.ts === +function* g1(): {} { } +>g1 : () => {} + diff --git a/tests/baselines/reference/generatorTypeCheck40.errors.txt b/tests/baselines/reference/generatorTypeCheck40.errors.txt new file mode 100644 index 0000000000..9d9676e5d2 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck40.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck40.ts(2,21): error TS9002: Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck40.ts (1 errors) ==== + function* g() { + class C extends (yield 0) { } + ~~~~~~~~~ +!!! error TS9002: Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses. + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck40.js b/tests/baselines/reference/generatorTypeCheck40.js new file mode 100644 index 0000000000..fe9bb797d7 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck40.js @@ -0,0 +1,10 @@ +//// [generatorTypeCheck40.ts] +function* g() { + class C extends (yield 0) { } +} + +//// [generatorTypeCheck40.js] +function* g() { + class C extends (yield 0) { + } +} diff --git a/tests/baselines/reference/generatorTypeCheck41.js b/tests/baselines/reference/generatorTypeCheck41.js new file mode 100644 index 0000000000..51c5ce3d41 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck41.js @@ -0,0 +1,13 @@ +//// [generatorTypeCheck41.ts] +function* g() { + let x = { + [yield 0]: 0 + } +} + +//// [generatorTypeCheck41.js] +function* g() { + let x = { + [yield 0]: 0 + }; +} diff --git a/tests/baselines/reference/generatorTypeCheck41.symbols b/tests/baselines/reference/generatorTypeCheck41.symbols new file mode 100644 index 0000000000..9111affa87 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck41.symbols @@ -0,0 +1,10 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck41.ts === +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck41.ts, 0, 0)) + + let x = { +>x : Symbol(x, Decl(generatorTypeCheck41.ts, 1, 7)) + + [yield 0]: 0 + } +} diff --git a/tests/baselines/reference/generatorTypeCheck41.types b/tests/baselines/reference/generatorTypeCheck41.types new file mode 100644 index 0000000000..926aef95ce --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck41.types @@ -0,0 +1,14 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck41.ts === +function* g() { +>g : () => IterableIterator + + let x = { +>x : {} +>{ [yield 0]: 0 } : {} + + [yield 0]: 0 +>yield 0 : any +>0 : number +>0 : number + } +} diff --git a/tests/baselines/reference/generatorTypeCheck42.js b/tests/baselines/reference/generatorTypeCheck42.js new file mode 100644 index 0000000000..c58802b1a8 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck42.js @@ -0,0 +1,16 @@ +//// [generatorTypeCheck42.ts] +function* g() { + let x = { + [yield 0]() { + + } + } +} + +//// [generatorTypeCheck42.js] +function* g() { + let x = { + [yield 0]() { + } + }; +} diff --git a/tests/baselines/reference/generatorTypeCheck42.symbols b/tests/baselines/reference/generatorTypeCheck42.symbols new file mode 100644 index 0000000000..a49534fd21 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck42.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck42.ts === +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck42.ts, 0, 0)) + + let x = { +>x : Symbol(x, Decl(generatorTypeCheck42.ts, 1, 7)) + + [yield 0]() { + + } + } +} diff --git a/tests/baselines/reference/generatorTypeCheck42.types b/tests/baselines/reference/generatorTypeCheck42.types new file mode 100644 index 0000000000..855c4697f4 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck42.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck42.ts === +function* g() { +>g : () => IterableIterator + + let x = { +>x : {} +>{ [yield 0]() { } } : {} + + [yield 0]() { +>yield 0 : any +>0 : number + + } + } +} diff --git a/tests/baselines/reference/generatorTypeCheck43.js b/tests/baselines/reference/generatorTypeCheck43.js new file mode 100644 index 0000000000..c7dc2dad39 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck43.js @@ -0,0 +1,16 @@ +//// [generatorTypeCheck43.ts] +function* g() { + let x = { + *[yield 0]() { + + } + } +} + +//// [generatorTypeCheck43.js] +function* g() { + let x = { + *[yield 0]() { + } + }; +} diff --git a/tests/baselines/reference/generatorTypeCheck43.symbols b/tests/baselines/reference/generatorTypeCheck43.symbols new file mode 100644 index 0000000000..f5f7b6c359 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck43.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck43.ts === +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck43.ts, 0, 0)) + + let x = { +>x : Symbol(x, Decl(generatorTypeCheck43.ts, 1, 7)) + + *[yield 0]() { + + } + } +} diff --git a/tests/baselines/reference/generatorTypeCheck43.types b/tests/baselines/reference/generatorTypeCheck43.types new file mode 100644 index 0000000000..50fc7e30c8 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck43.types @@ -0,0 +1,15 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck43.ts === +function* g() { +>g : () => IterableIterator + + let x = { +>x : {} +>{ *[yield 0]() { } } : {} + + *[yield 0]() { +>yield 0 : any +>0 : number + + } + } +} diff --git a/tests/baselines/reference/generatorTypeCheck44.js b/tests/baselines/reference/generatorTypeCheck44.js new file mode 100644 index 0000000000..238998ad97 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck44.js @@ -0,0 +1,17 @@ +//// [generatorTypeCheck44.ts] +function* g() { + let x = { + get [yield 0]() { + return 0; + } + } +} + +//// [generatorTypeCheck44.js] +function* g() { + let x = { + get [yield 0]() { + return 0; + } + }; +} diff --git a/tests/baselines/reference/generatorTypeCheck44.symbols b/tests/baselines/reference/generatorTypeCheck44.symbols new file mode 100644 index 0000000000..b6606064c4 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck44.symbols @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck44.ts === +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck44.ts, 0, 0)) + + let x = { +>x : Symbol(x, Decl(generatorTypeCheck44.ts, 1, 7)) + + get [yield 0]() { + return 0; + } + } +} diff --git a/tests/baselines/reference/generatorTypeCheck44.types b/tests/baselines/reference/generatorTypeCheck44.types new file mode 100644 index 0000000000..2fc67f9055 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck44.types @@ -0,0 +1,17 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck44.ts === +function* g() { +>g : () => IterableIterator + + let x = { +>x : {} +>{ get [yield 0]() { return 0; } } : {} + + get [yield 0]() { +>yield 0 : any +>0 : number + + return 0; +>0 : number + } + } +} diff --git a/tests/baselines/reference/generatorTypeCheck45.js b/tests/baselines/reference/generatorTypeCheck45.js new file mode 100644 index 0000000000..20f64e53c9 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck45.js @@ -0,0 +1,7 @@ +//// [generatorTypeCheck45.ts] +declare function foo(x: T, fun: () => Iterator<(x: T) => U>, fun2: (y: U) => T): T; + +foo("", function* () { yield x => x.length }, p => undefined); // T is fixed, should be string + +//// [generatorTypeCheck45.js] +foo("", function* () { yield x => x.length; }, p => undefined); // T is fixed, should be string diff --git a/tests/baselines/reference/generatorTypeCheck45.symbols b/tests/baselines/reference/generatorTypeCheck45.symbols new file mode 100644 index 0000000000..06340925fe --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck45.symbols @@ -0,0 +1,27 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck45.ts === +declare function foo(x: T, fun: () => Iterator<(x: T) => U>, fun2: (y: U) => T): T; +>foo : Symbol(foo, Decl(generatorTypeCheck45.ts, 0, 0)) +>T : Symbol(T, Decl(generatorTypeCheck45.ts, 0, 21)) +>U : Symbol(U, Decl(generatorTypeCheck45.ts, 0, 23)) +>x : Symbol(x, Decl(generatorTypeCheck45.ts, 0, 27)) +>T : Symbol(T, Decl(generatorTypeCheck45.ts, 0, 21)) +>fun : Symbol(fun, Decl(generatorTypeCheck45.ts, 0, 32)) +>Iterator : Symbol(Iterator, Decl(lib.d.ts, 1662, 1)) +>x : Symbol(x, Decl(generatorTypeCheck45.ts, 0, 54)) +>T : Symbol(T, Decl(generatorTypeCheck45.ts, 0, 21)) +>U : Symbol(U, Decl(generatorTypeCheck45.ts, 0, 23)) +>fun2 : Symbol(fun2, Decl(generatorTypeCheck45.ts, 0, 66)) +>y : Symbol(y, Decl(generatorTypeCheck45.ts, 0, 74)) +>U : Symbol(U, Decl(generatorTypeCheck45.ts, 0, 23)) +>T : Symbol(T, Decl(generatorTypeCheck45.ts, 0, 21)) +>T : Symbol(T, Decl(generatorTypeCheck45.ts, 0, 21)) + +foo("", function* () { yield x => x.length }, p => undefined); // T is fixed, should be string +>foo : Symbol(foo, Decl(generatorTypeCheck45.ts, 0, 0)) +>x : Symbol(x, Decl(generatorTypeCheck45.ts, 2, 28)) +>x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) +>x : Symbol(x, Decl(generatorTypeCheck45.ts, 2, 28)) +>length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) +>p : Symbol(p, Decl(generatorTypeCheck45.ts, 2, 45)) +>undefined : Symbol(undefined) + diff --git a/tests/baselines/reference/generatorTypeCheck45.types b/tests/baselines/reference/generatorTypeCheck45.types new file mode 100644 index 0000000000..7ea442420d --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck45.types @@ -0,0 +1,33 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck45.ts === +declare function foo(x: T, fun: () => Iterator<(x: T) => U>, fun2: (y: U) => T): T; +>foo : (x: T, fun: () => Iterator<(x: T) => U>, fun2: (y: U) => T) => T +>T : T +>U : U +>x : T +>T : T +>fun : () => Iterator<(x: T) => U> +>Iterator : Iterator +>x : T +>T : T +>U : U +>fun2 : (y: U) => T +>y : U +>U : U +>T : T +>T : T + +foo("", function* () { yield x => x.length }, p => undefined); // T is fixed, should be string +>foo("", function* () { yield x => x.length }, p => undefined) : string +>foo : (x: T, fun: () => Iterator<(x: T) => U>, fun2: (y: U) => T) => T +>"" : string +>function* () { yield x => x.length } : () => IterableIterator<(x: string) => number> +>yield x => x.length : any +>x => x.length : (x: string) => number +>x : string +>x.length : number +>x : string +>length : number +>p => undefined : (p: number) => any +>p : number +>undefined : undefined + diff --git a/tests/baselines/reference/generatorTypeCheck46.js b/tests/baselines/reference/generatorTypeCheck46.js new file mode 100644 index 0000000000..0270f9e3a3 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck46.js @@ -0,0 +1,19 @@ +//// [generatorTypeCheck46.ts] +declare function foo(x: T, fun: () => Iterable<(x: T) => U>, fun2: (y: U) => T): T; + +foo("", function* () { + yield* { + *[Symbol.iterator]() { + yield x => x.length + } + } +}, p => undefined); // T is fixed, should be string + +//// [generatorTypeCheck46.js] +foo("", function* () { + yield* { + *[Symbol.iterator]() { + yield x => x.length; + } + }; +}, p => undefined); // T is fixed, should be string diff --git a/tests/baselines/reference/generatorTypeCheck46.symbols b/tests/baselines/reference/generatorTypeCheck46.symbols new file mode 100644 index 0000000000..aa0b237d1f --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck46.symbols @@ -0,0 +1,38 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck46.ts === +declare function foo(x: T, fun: () => Iterable<(x: T) => U>, fun2: (y: U) => T): T; +>foo : Symbol(foo, Decl(generatorTypeCheck46.ts, 0, 0)) +>T : Symbol(T, Decl(generatorTypeCheck46.ts, 0, 21)) +>U : Symbol(U, Decl(generatorTypeCheck46.ts, 0, 23)) +>x : Symbol(x, Decl(generatorTypeCheck46.ts, 0, 27)) +>T : Symbol(T, Decl(generatorTypeCheck46.ts, 0, 21)) +>fun : Symbol(fun, Decl(generatorTypeCheck46.ts, 0, 32)) +>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1)) +>x : Symbol(x, Decl(generatorTypeCheck46.ts, 0, 54)) +>T : Symbol(T, Decl(generatorTypeCheck46.ts, 0, 21)) +>U : Symbol(U, Decl(generatorTypeCheck46.ts, 0, 23)) +>fun2 : Symbol(fun2, Decl(generatorTypeCheck46.ts, 0, 66)) +>y : Symbol(y, Decl(generatorTypeCheck46.ts, 0, 74)) +>U : Symbol(U, Decl(generatorTypeCheck46.ts, 0, 23)) +>T : Symbol(T, Decl(generatorTypeCheck46.ts, 0, 21)) +>T : Symbol(T, Decl(generatorTypeCheck46.ts, 0, 21)) + +foo("", function* () { +>foo : Symbol(foo, Decl(generatorTypeCheck46.ts, 0, 0)) + + yield* { + *[Symbol.iterator]() { +>Symbol.iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31)) +>Symbol : Symbol(Symbol, Decl(lib.d.ts, 1186, 52), Decl(lib.d.ts, 1292, 11)) +>iterator : Symbol(SymbolConstructor.iterator, Decl(lib.d.ts, 1236, 31)) + + yield x => x.length +>x : Symbol(x, Decl(generatorTypeCheck46.ts, 5, 17)) +>x.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) +>x : Symbol(x, Decl(generatorTypeCheck46.ts, 5, 17)) +>length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) + } + } +}, p => undefined); // T is fixed, should be string +>p : Symbol(p, Decl(generatorTypeCheck46.ts, 8, 2)) +>undefined : Symbol(undefined) + diff --git a/tests/baselines/reference/generatorTypeCheck46.types b/tests/baselines/reference/generatorTypeCheck46.types new file mode 100644 index 0000000000..daf0d67b6e --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck46.types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck46.ts === +declare function foo(x: T, fun: () => Iterable<(x: T) => U>, fun2: (y: U) => T): T; +>foo : (x: T, fun: () => Iterable<(x: T) => U>, fun2: (y: U) => T) => T +>T : T +>U : U +>x : T +>T : T +>fun : () => Iterable<(x: T) => U> +>Iterable : Iterable +>x : T +>T : T +>U : U +>fun2 : (y: U) => T +>y : U +>U : U +>T : T +>T : T + +foo("", function* () { +>foo("", function* () { yield* { *[Symbol.iterator]() { yield x => x.length } }}, p => undefined) : string +>foo : (x: T, fun: () => Iterable<(x: T) => U>, fun2: (y: U) => T) => T +>"" : string +>function* () { yield* { *[Symbol.iterator]() { yield x => x.length } }} : () => IterableIterator<(x: string) => number> + + yield* { +>yield* { *[Symbol.iterator]() { yield x => x.length } } : any +>{ *[Symbol.iterator]() { yield x => x.length } } : { [Symbol.iterator](): IterableIterator<(x: string) => number>; } + + *[Symbol.iterator]() { +>Symbol.iterator : symbol +>Symbol : SymbolConstructor +>iterator : symbol + + yield x => x.length +>yield x => x.length : any +>x => x.length : (x: string) => number +>x : string +>x.length : number +>x : string +>length : number + } + } +}, p => undefined); // T is fixed, should be string +>p => undefined : (p: number) => any +>p : number +>undefined : undefined + diff --git a/tests/baselines/reference/generatorTypeCheck47.errors.txt b/tests/baselines/reference/generatorTypeCheck47.errors.txt new file mode 100644 index 0000000000..f5264f7ce9 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck47.errors.txt @@ -0,0 +1,8 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck47.ts(2,9): error TS7025: Generator implicitly has type 'IterableIterator' because it does not yield any values. Consider supplying a return type. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck47.ts (1 errors) ==== + + function* g() { } + ~ +!!! error TS7025: Generator implicitly has type 'IterableIterator' because it does not yield any values. Consider supplying a return type. \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck47.js b/tests/baselines/reference/generatorTypeCheck47.js new file mode 100644 index 0000000000..b06fb96b43 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck47.js @@ -0,0 +1,6 @@ +//// [generatorTypeCheck47.ts] + +function* g() { } + +//// [generatorTypeCheck47.js] +function* g() { } diff --git a/tests/baselines/reference/generatorTypeCheck48.errors.txt b/tests/baselines/reference/generatorTypeCheck48.errors.txt new file mode 100644 index 0000000000..c91626cd81 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck48.errors.txt @@ -0,0 +1,10 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts(2,9): error TS7025: Generator implicitly has type 'IterableIterator' because it does not yield any values. Consider supplying a return type. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts (1 errors) ==== + + function* g() { + ~ +!!! error TS7025: Generator implicitly has type 'IterableIterator' because it does not yield any values. Consider supplying a return type. + yield; + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck48.js b/tests/baselines/reference/generatorTypeCheck48.js new file mode 100644 index 0000000000..579d6dcf0e --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck48.js @@ -0,0 +1,10 @@ +//// [generatorTypeCheck48.ts] + +function* g() { + yield; +} + +//// [generatorTypeCheck48.js] +function* g() { + yield; +} diff --git a/tests/baselines/reference/generatorTypeCheck49.js b/tests/baselines/reference/generatorTypeCheck49.js new file mode 100644 index 0000000000..b544c7e422 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck49.js @@ -0,0 +1,10 @@ +//// [generatorTypeCheck49.ts] + +function* g() { + yield 0; +} + +//// [generatorTypeCheck49.js] +function* g() { + yield 0; +} diff --git a/tests/baselines/reference/generatorTypeCheck49.symbols b/tests/baselines/reference/generatorTypeCheck49.symbols new file mode 100644 index 0000000000..d24deed3d8 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck49.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck49.ts === + +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck49.ts, 0, 0)) + + yield 0; +} diff --git a/tests/baselines/reference/generatorTypeCheck49.types b/tests/baselines/reference/generatorTypeCheck49.types new file mode 100644 index 0000000000..f56cca3343 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck49.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck49.ts === + +function* g() { +>g : () => IterableIterator + + yield 0; +>yield 0 : any +>0 : number +} diff --git a/tests/baselines/reference/generatorTypeCheck5.js b/tests/baselines/reference/generatorTypeCheck5.js new file mode 100644 index 0000000000..1acfc11057 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck5.js @@ -0,0 +1,5 @@ +//// [generatorTypeCheck5.ts] +function* g1(): any { } + +//// [generatorTypeCheck5.js] +function* g1() { } diff --git a/tests/baselines/reference/generatorTypeCheck5.symbols b/tests/baselines/reference/generatorTypeCheck5.symbols new file mode 100644 index 0000000000..3f889e3cad --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck5.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck5.ts === +function* g1(): any { } +>g1 : Symbol(g1, Decl(generatorTypeCheck5.ts, 0, 0)) + diff --git a/tests/baselines/reference/generatorTypeCheck5.types b/tests/baselines/reference/generatorTypeCheck5.types new file mode 100644 index 0000000000..6918a00663 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck5.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck5.ts === +function* g1(): any { } +>g1 : () => any + diff --git a/tests/baselines/reference/generatorTypeCheck50.js b/tests/baselines/reference/generatorTypeCheck50.js new file mode 100644 index 0000000000..856e3867ab --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck50.js @@ -0,0 +1,10 @@ +//// [generatorTypeCheck50.ts] + +function* g() { + yield yield; +} + +//// [generatorTypeCheck50.js] +function* g() { + yield yield; +} diff --git a/tests/baselines/reference/generatorTypeCheck50.symbols b/tests/baselines/reference/generatorTypeCheck50.symbols new file mode 100644 index 0000000000..412a1ac1ea --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck50.symbols @@ -0,0 +1,7 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck50.ts === + +function* g() { +>g : Symbol(g, Decl(generatorTypeCheck50.ts, 0, 0)) + + yield yield; +} diff --git a/tests/baselines/reference/generatorTypeCheck50.types b/tests/baselines/reference/generatorTypeCheck50.types new file mode 100644 index 0000000000..342d7406dc --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck50.types @@ -0,0 +1,9 @@ +=== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck50.ts === + +function* g() { +>g : () => IterableIterator + + yield yield; +>yield yield : any +>yield : any +} diff --git a/tests/baselines/reference/generatorTypeCheck51.errors.txt b/tests/baselines/reference/generatorTypeCheck51.errors.txt new file mode 100644 index 0000000000..f4fc5723a5 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck51.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck51.ts(2,9): error TS7025: Generator implicitly has type 'IterableIterator' because it does not yield any values. Consider supplying a return type. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck51.ts (1 errors) ==== + + function* g() { + ~ +!!! error TS7025: Generator implicitly has type 'IterableIterator' because it does not yield any values. Consider supplying a return type. + function* h() { + yield 0; + } + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck51.js b/tests/baselines/reference/generatorTypeCheck51.js new file mode 100644 index 0000000000..f3519065c3 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck51.js @@ -0,0 +1,14 @@ +//// [generatorTypeCheck51.ts] + +function* g() { + function* h() { + yield 0; + } +} + +//// [generatorTypeCheck51.js] +function* g() { + function* h() { + yield 0; + } +} diff --git a/tests/baselines/reference/generatorTypeCheck52.errors.txt b/tests/baselines/reference/generatorTypeCheck52.errors.txt new file mode 100644 index 0000000000..8dc280bb8c --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck52.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck52.ts(3,11): error TS2504: No best common type exists among yield expressions. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck52.ts (1 errors) ==== + class Foo { x: number } + class Baz { z: number } + function* g() { + ~ +!!! error TS2504: No best common type exists among yield expressions. + yield new Foo; + yield new Baz; + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck52.js b/tests/baselines/reference/generatorTypeCheck52.js new file mode 100644 index 0000000000..751e12c471 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck52.js @@ -0,0 +1,17 @@ +//// [generatorTypeCheck52.ts] +class Foo { x: number } +class Baz { z: number } +function* g() { + yield new Foo; + yield new Baz; +} + +//// [generatorTypeCheck52.js] +class Foo { +} +class Baz { +} +function* g() { + yield new Foo; + yield new Baz; +} diff --git a/tests/baselines/reference/generatorTypeCheck53.errors.txt b/tests/baselines/reference/generatorTypeCheck53.errors.txt new file mode 100644 index 0000000000..ee3512f34c --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck53.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck53.ts(3,11): error TS2504: No best common type exists among yield expressions. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck53.ts (1 errors) ==== + class Foo { x: number } + class Baz { z: number } + function* g() { + ~ +!!! error TS2504: No best common type exists among yield expressions. + yield new Foo; + yield* [new Baz]; + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck53.js b/tests/baselines/reference/generatorTypeCheck53.js new file mode 100644 index 0000000000..f26b3b6080 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck53.js @@ -0,0 +1,17 @@ +//// [generatorTypeCheck53.ts] +class Foo { x: number } +class Baz { z: number } +function* g() { + yield new Foo; + yield* [new Baz]; +} + +//// [generatorTypeCheck53.js] +class Foo { +} +class Baz { +} +function* g() { + yield new Foo; + yield* [new Baz]; +} diff --git a/tests/baselines/reference/generatorTypeCheck54.errors.txt b/tests/baselines/reference/generatorTypeCheck54.errors.txt new file mode 100644 index 0000000000..de22dbfc6e --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck54.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck54.ts(3,11): error TS2504: No best common type exists among yield expressions. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck54.ts (1 errors) ==== + class Foo { x: number } + class Baz { z: number } + function* g() { + ~ +!!! error TS2504: No best common type exists among yield expressions. + yield* [new Foo]; + yield* [new Baz]; + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck54.js b/tests/baselines/reference/generatorTypeCheck54.js new file mode 100644 index 0000000000..f53215404e --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck54.js @@ -0,0 +1,17 @@ +//// [generatorTypeCheck54.ts] +class Foo { x: number } +class Baz { z: number } +function* g() { + yield* [new Foo]; + yield* [new Baz]; +} + +//// [generatorTypeCheck54.js] +class Foo { +} +class Baz { +} +function* g() { + yield* [new Foo]; + yield* [new Baz]; +} diff --git a/tests/baselines/reference/generatorTypeCheck55.errors.txt b/tests/baselines/reference/generatorTypeCheck55.errors.txt new file mode 100644 index 0000000000..0846d1c28a --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck55.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck55.ts(2,19): error TS9003: 'class' expressions are not currently supported. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck55.ts (1 errors) ==== + function* g() { + var x = class C extends (yield) {}; + ~ +!!! error TS9003: 'class' expressions are not currently supported. + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck55.js b/tests/baselines/reference/generatorTypeCheck55.js new file mode 100644 index 0000000000..dd7cd33af2 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck55.js @@ -0,0 +1,11 @@ +//// [generatorTypeCheck55.ts] +function* g() { + var x = class C extends (yield) {}; +} + +//// [generatorTypeCheck55.js] +function* g() { + var x = class C extends (yield) { + } + ; +} diff --git a/tests/baselines/reference/generatorTypeCheck56.errors.txt b/tests/baselines/reference/generatorTypeCheck56.errors.txt new file mode 100644 index 0000000000..99e3b00de4 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck56.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck56.ts(2,19): error TS9003: 'class' expressions are not currently supported. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck56.ts(3,11): error TS1163: A 'yield' expression is only allowed in a generator body. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck56.ts (2 errors) ==== + function* g() { + var x = class C { + ~ +!!! error TS9003: 'class' expressions are not currently supported. + *[yield 0]() { + ~~~~~ +!!! error TS1163: A 'yield' expression is only allowed in a generator body. + yield 0; + } + }; + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck56.js b/tests/baselines/reference/generatorTypeCheck56.js new file mode 100644 index 0000000000..c1b0f98f5e --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck56.js @@ -0,0 +1,18 @@ +//// [generatorTypeCheck56.ts] +function* g() { + var x = class C { + *[yield 0]() { + yield 0; + } + }; +} + +//// [generatorTypeCheck56.js] +function* g() { + var x = class C { + *[yield 0]() { + yield 0; + } + } + ; +} diff --git a/tests/baselines/reference/generatorTypeCheck57.errors.txt b/tests/baselines/reference/generatorTypeCheck57.errors.txt new file mode 100644 index 0000000000..aa39e534d6 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck57.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck57.ts(3,13): error TS1163: A 'yield' expression is only allowed in a generator body. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck57.ts (1 errors) ==== + function* g() { + class C { + x = yield 0; + ~~~~~ +!!! error TS1163: A 'yield' expression is only allowed in a generator body. + }; + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck57.js b/tests/baselines/reference/generatorTypeCheck57.js new file mode 100644 index 0000000000..740df49286 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck57.js @@ -0,0 +1,16 @@ +//// [generatorTypeCheck57.ts] +function* g() { + class C { + x = yield 0; + }; +} + +//// [generatorTypeCheck57.js] +function* g() { + class C { + constructor() { + this.x = yield 0; + } + } + ; +} diff --git a/tests/baselines/reference/generatorTypeCheck58.errors.txt b/tests/baselines/reference/generatorTypeCheck58.errors.txt new file mode 100644 index 0000000000..7407c83b34 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck58.errors.txt @@ -0,0 +1,11 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck58.ts(3,20): error TS1163: A 'yield' expression is only allowed in a generator body. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck58.ts (1 errors) ==== + function* g() { + class C { + static x = yield 0; + ~~~~~ +!!! error TS1163: A 'yield' expression is only allowed in a generator body. + }; + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck58.js b/tests/baselines/reference/generatorTypeCheck58.js new file mode 100644 index 0000000000..925fc2b76d --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck58.js @@ -0,0 +1,14 @@ +//// [generatorTypeCheck58.ts] +function* g() { + class C { + static x = yield 0; + }; +} + +//// [generatorTypeCheck58.js] +function* g() { + class C { + } + C.x = yield 0; + ; +} diff --git a/tests/baselines/reference/generatorTypeCheck59.errors.txt b/tests/baselines/reference/generatorTypeCheck59.errors.txt new file mode 100644 index 0000000000..d8d532a430 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck59.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(3,9): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts(3,11): error TS1163: A 'yield' expression is only allowed in a generator body. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts (2 errors) ==== + function* g() { + class C { + @(yield "") + ~~~~~~~~~~~ + ~~~~~ +!!! error TS1163: A 'yield' expression is only allowed in a generator body. + m() { } + ~~~~~~~~~~~~~~~ +!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning. + }; + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck59.js b/tests/baselines/reference/generatorTypeCheck59.js new file mode 100644 index 0000000000..5b3b70386f --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck59.js @@ -0,0 +1,27 @@ +//// [generatorTypeCheck59.ts] +function* g() { + class C { + @(yield "") + m() { } + }; +} + +//// [generatorTypeCheck59.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); + switch (arguments.length) { + case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); + case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); + case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); + } +}; +function* g() { + class C { + m() { } + } + Object.defineProperty(C.prototype, "m", + __decorate([ + (yield "") + ], C.prototype, "m", Object.getOwnPropertyDescriptor(C.prototype, "m"))); + ; +} diff --git a/tests/baselines/reference/generatorTypeCheck6.errors.txt b/tests/baselines/reference/generatorTypeCheck6.errors.txt new file mode 100644 index 0000000000..35f2cc2016 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck6.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck6.ts(1,17): error TS2322: Type 'IterableIterator' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck6.ts (1 errors) ==== + function* g1(): number { } + ~~~~~~ +!!! error TS2322: Type 'IterableIterator' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck6.js b/tests/baselines/reference/generatorTypeCheck6.js new file mode 100644 index 0000000000..de0f92f77f --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck6.js @@ -0,0 +1,5 @@ +//// [generatorTypeCheck6.ts] +function* g1(): number { } + +//// [generatorTypeCheck6.js] +function* g1() { } diff --git a/tests/baselines/reference/generatorTypeCheck60.errors.txt b/tests/baselines/reference/generatorTypeCheck60.errors.txt new file mode 100644 index 0000000000..d8e5d640bb --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck60.errors.txt @@ -0,0 +1,9 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck60.ts(2,21): error TS9002: Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck60.ts (1 errors) ==== + function* g() { + class C extends (yield) {}; + ~~~~~~~ +!!! error TS9002: Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses. + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck60.js b/tests/baselines/reference/generatorTypeCheck60.js new file mode 100644 index 0000000000..cb7c65cf08 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck60.js @@ -0,0 +1,11 @@ +//// [generatorTypeCheck60.ts] +function* g() { + class C extends (yield) {}; +} + +//// [generatorTypeCheck60.js] +function* g() { + class C extends (yield) { + } + ; +} diff --git a/tests/baselines/reference/generatorTypeCheck61.errors.txt b/tests/baselines/reference/generatorTypeCheck61.errors.txt new file mode 100644 index 0000000000..b38e96d31c --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck61.errors.txt @@ -0,0 +1,13 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(2,7): error TS1163: A 'yield' expression is only allowed in a generator body. +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts(3,11): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts (2 errors) ==== + function * g() { + @(yield 0) + ~~~~~ +!!! error TS1163: A 'yield' expression is only allowed in a generator body. + class C {}; + ~ +!!! error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning. + } \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck61.js b/tests/baselines/reference/generatorTypeCheck61.js new file mode 100644 index 0000000000..9e2f067f9f --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck61.js @@ -0,0 +1,23 @@ +//// [generatorTypeCheck61.ts] +function * g() { + @(yield 0) + class C {}; +} + +//// [generatorTypeCheck61.js] +var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { + if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc); + switch (arguments.length) { + case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target); + case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0); + case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc); + } +}; +function* g() { + let C = class { + }; + C = __decorate([ + (yield 0) + ], C); + ; +} diff --git a/tests/baselines/reference/generatorTypeCheck7.errors.txt b/tests/baselines/reference/generatorTypeCheck7.errors.txt new file mode 100644 index 0000000000..2653ecf8cd --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck7.errors.txt @@ -0,0 +1,12 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck7.ts(4,17): error TS2322: Type 'IterableIterator' is not assignable to type 'WeirdIter'. + Property 'hello' is missing in type 'IterableIterator'. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck7.ts (1 errors) ==== + interface WeirdIter extends IterableIterator { + hello: string; + } + function* g1(): WeirdIter { } + ~~~~~~~~~ +!!! error TS2322: Type 'IterableIterator' is not assignable to type 'WeirdIter'. +!!! error TS2322: Property 'hello' is missing in type 'IterableIterator'. \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck7.js b/tests/baselines/reference/generatorTypeCheck7.js new file mode 100644 index 0000000000..c2d47f9483 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck7.js @@ -0,0 +1,8 @@ +//// [generatorTypeCheck7.ts] +interface WeirdIter extends IterableIterator { + hello: string; +} +function* g1(): WeirdIter { } + +//// [generatorTypeCheck7.js] +function* g1() { } diff --git a/tests/baselines/reference/generatorTypeCheck8.errors.txt b/tests/baselines/reference/generatorTypeCheck8.errors.txt new file mode 100644 index 0000000000..cedfecda60 --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck8.errors.txt @@ -0,0 +1,16 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck8.ts(2,17): error TS2322: Type 'IterableIterator' is not assignable to type 'BadGenerator'. + Types of property 'next' are incompatible. + Type '(value?: any) => IteratorResult' is not assignable to type '(value?: any) => IteratorResult'. + Type 'IteratorResult' is not assignable to type 'IteratorResult'. + Type 'string' is not assignable to type 'number'. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck8.ts (1 errors) ==== + interface BadGenerator extends Iterator, Iterable { } + function* g3(): BadGenerator { } + ~~~~~~~~~~~~ +!!! error TS2322: Type 'IterableIterator' is not assignable to type 'BadGenerator'. +!!! error TS2322: Types of property 'next' are incompatible. +!!! error TS2322: Type '(value?: any) => IteratorResult' is not assignable to type '(value?: any) => IteratorResult'. +!!! error TS2322: Type 'IteratorResult' is not assignable to type 'IteratorResult'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck8.js b/tests/baselines/reference/generatorTypeCheck8.js new file mode 100644 index 0000000000..97058c2eaa --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck8.js @@ -0,0 +1,6 @@ +//// [generatorTypeCheck8.ts] +interface BadGenerator extends Iterator, Iterable { } +function* g3(): BadGenerator { } + +//// [generatorTypeCheck8.js] +function* g3() { } diff --git a/tests/baselines/reference/generatorTypeCheck9.errors.txt b/tests/baselines/reference/generatorTypeCheck9.errors.txt new file mode 100644 index 0000000000..3b4e0c654f --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck9.errors.txt @@ -0,0 +1,7 @@ +tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck9.ts(1,17): error TS2505: A generator cannot have a 'void' type annotation. + + +==== tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck9.ts (1 errors) ==== + function* g3(): void { } + ~~~~ +!!! error TS2505: A generator cannot have a 'void' type annotation. \ No newline at end of file diff --git a/tests/baselines/reference/generatorTypeCheck9.js b/tests/baselines/reference/generatorTypeCheck9.js new file mode 100644 index 0000000000..3bdeec0a4a --- /dev/null +++ b/tests/baselines/reference/generatorTypeCheck9.js @@ -0,0 +1,5 @@ +//// [generatorTypeCheck9.ts] +function* g3(): void { } + +//// [generatorTypeCheck9.js] +function* g3() { } diff --git a/tests/baselines/reference/implicitAnyFromCircularInference.errors.txt b/tests/baselines/reference/implicitAnyFromCircularInference.errors.txt index 8d0aaf04c0..36538aef4f 100644 --- a/tests/baselines/reference/implicitAnyFromCircularInference.errors.txt +++ b/tests/baselines/reference/implicitAnyFromCircularInference.errors.txt @@ -7,7 +7,7 @@ tests/cases/compiler/implicitAnyFromCircularInference.ts(18,10): error TS7024: F tests/cases/compiler/implicitAnyFromCircularInference.ts(23,10): error TS7024: Function implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. tests/cases/compiler/implicitAnyFromCircularInference.ts(26,10): error TS7023: 'h' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. tests/cases/compiler/implicitAnyFromCircularInference.ts(28,14): error TS7023: 'foo' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. -tests/cases/compiler/implicitAnyFromCircularInference.ts(41,5): error TS7022: 's' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +tests/cases/compiler/implicitAnyFromCircularInference.ts(41,5): error TS7022: 's' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. tests/cases/compiler/implicitAnyFromCircularInference.ts(46,5): error TS7023: 'x' implicitly has return type 'any' because it does not have a return type annotation and is referenced directly or indirectly in one of its return expressions. @@ -72,7 +72,7 @@ tests/cases/compiler/implicitAnyFromCircularInference.ts(46,5): error TS7023: 'x // Error expected s = foo(this); ~~~~~~~~~~~~~~ -!!! error TS7022: 's' implicitly has type 'any' because it is does not have a type annotation and is referenced directly or indirectly in its own initializer. +!!! error TS7022: 's' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer. } class D { diff --git a/tests/baselines/reference/inferentialTypingObjectLiteralMethod1.js b/tests/baselines/reference/inferentialTypingObjectLiteralMethod1.js new file mode 100644 index 0000000000..a5cf75ae7f --- /dev/null +++ b/tests/baselines/reference/inferentialTypingObjectLiteralMethod1.js @@ -0,0 +1,9 @@ +//// [inferentialTypingObjectLiteralMethod1.ts] +interface Int { + method(x: T): U; +} +declare function foo(x: T, y: Int, z: Int): T; +foo("", { method(p1) { return p1.length } }, { method(p2) { return undefined } }); + +//// [inferentialTypingObjectLiteralMethod1.js] +foo("", { method: function (p1) { return p1.length; } }, { method: function (p2) { return undefined; } }); diff --git a/tests/baselines/reference/inferentialTypingObjectLiteralMethod1.symbols b/tests/baselines/reference/inferentialTypingObjectLiteralMethod1.symbols new file mode 100644 index 0000000000..3fee48fc83 --- /dev/null +++ b/tests/baselines/reference/inferentialTypingObjectLiteralMethod1.symbols @@ -0,0 +1,39 @@ +=== tests/cases/compiler/inferentialTypingObjectLiteralMethod1.ts === +interface Int { +>Int : Symbol(Int, Decl(inferentialTypingObjectLiteralMethod1.ts, 0, 0)) +>T : Symbol(T, Decl(inferentialTypingObjectLiteralMethod1.ts, 0, 14)) +>U : Symbol(U, Decl(inferentialTypingObjectLiteralMethod1.ts, 0, 16)) + + method(x: T): U; +>method : Symbol(method, Decl(inferentialTypingObjectLiteralMethod1.ts, 0, 21)) +>x : Symbol(x, Decl(inferentialTypingObjectLiteralMethod1.ts, 1, 11)) +>T : Symbol(T, Decl(inferentialTypingObjectLiteralMethod1.ts, 0, 14)) +>U : Symbol(U, Decl(inferentialTypingObjectLiteralMethod1.ts, 0, 16)) +} +declare function foo(x: T, y: Int, z: Int): T; +>foo : Symbol(foo, Decl(inferentialTypingObjectLiteralMethod1.ts, 2, 1)) +>T : Symbol(T, Decl(inferentialTypingObjectLiteralMethod1.ts, 3, 21)) +>U : Symbol(U, Decl(inferentialTypingObjectLiteralMethod1.ts, 3, 23)) +>x : Symbol(x, Decl(inferentialTypingObjectLiteralMethod1.ts, 3, 27)) +>T : Symbol(T, Decl(inferentialTypingObjectLiteralMethod1.ts, 3, 21)) +>y : Symbol(y, Decl(inferentialTypingObjectLiteralMethod1.ts, 3, 32)) +>Int : Symbol(Int, Decl(inferentialTypingObjectLiteralMethod1.ts, 0, 0)) +>T : Symbol(T, Decl(inferentialTypingObjectLiteralMethod1.ts, 3, 21)) +>U : Symbol(U, Decl(inferentialTypingObjectLiteralMethod1.ts, 3, 23)) +>z : Symbol(z, Decl(inferentialTypingObjectLiteralMethod1.ts, 3, 46)) +>Int : Symbol(Int, Decl(inferentialTypingObjectLiteralMethod1.ts, 0, 0)) +>U : Symbol(U, Decl(inferentialTypingObjectLiteralMethod1.ts, 3, 23)) +>T : Symbol(T, Decl(inferentialTypingObjectLiteralMethod1.ts, 3, 21)) +>T : Symbol(T, Decl(inferentialTypingObjectLiteralMethod1.ts, 3, 21)) + +foo("", { method(p1) { return p1.length } }, { method(p2) { return undefined } }); +>foo : Symbol(foo, Decl(inferentialTypingObjectLiteralMethod1.ts, 2, 1)) +>method : Symbol(method, Decl(inferentialTypingObjectLiteralMethod1.ts, 4, 9)) +>p1 : Symbol(p1, Decl(inferentialTypingObjectLiteralMethod1.ts, 4, 17)) +>p1.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) +>p1 : Symbol(p1, Decl(inferentialTypingObjectLiteralMethod1.ts, 4, 17)) +>length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) +>method : Symbol(method, Decl(inferentialTypingObjectLiteralMethod1.ts, 4, 46)) +>p2 : Symbol(p2, Decl(inferentialTypingObjectLiteralMethod1.ts, 4, 54)) +>undefined : Symbol(undefined) + diff --git a/tests/baselines/reference/inferentialTypingObjectLiteralMethod1.types b/tests/baselines/reference/inferentialTypingObjectLiteralMethod1.types new file mode 100644 index 0000000000..da2fa24060 --- /dev/null +++ b/tests/baselines/reference/inferentialTypingObjectLiteralMethod1.types @@ -0,0 +1,43 @@ +=== tests/cases/compiler/inferentialTypingObjectLiteralMethod1.ts === +interface Int { +>Int : Int +>T : T +>U : U + + method(x: T): U; +>method : (x: T) => U +>x : T +>T : T +>U : U +} +declare function foo(x: T, y: Int, z: Int): T; +>foo : (x: T, y: Int, z: Int) => T +>T : T +>U : U +>x : T +>T : T +>y : Int +>Int : Int +>T : T +>U : U +>z : Int +>Int : Int +>U : U +>T : T +>T : T + +foo("", { method(p1) { return p1.length } }, { method(p2) { return undefined } }); +>foo("", { method(p1) { return p1.length } }, { method(p2) { return undefined } }) : string +>foo : (x: T, y: Int, z: Int) => T +>"" : string +>{ method(p1) { return p1.length } } : { method(p1: string): number; } +>method : (p1: string) => number +>p1 : string +>p1.length : number +>p1 : string +>length : number +>{ method(p2) { return undefined } } : { method(p2: number): any; } +>method : (p2: number) => any +>p2 : number +>undefined : undefined + diff --git a/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.js b/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.js new file mode 100644 index 0000000000..fe53a619ac --- /dev/null +++ b/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.js @@ -0,0 +1,9 @@ +//// [inferentialTypingObjectLiteralMethod2.ts] +interface Int { + [s: string]: (x: T) => U; +} +declare function foo(x: T, y: Int, z: Int): T; +foo("", { method(p1) { return p1.length } }, { method(p2) { return undefined } }); + +//// [inferentialTypingObjectLiteralMethod2.js] +foo("", { method: function (p1) { return p1.length; } }, { method: function (p2) { return undefined; } }); diff --git a/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.symbols b/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.symbols new file mode 100644 index 0000000000..fc8d39858b --- /dev/null +++ b/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.symbols @@ -0,0 +1,39 @@ +=== tests/cases/compiler/inferentialTypingObjectLiteralMethod2.ts === +interface Int { +>Int : Symbol(Int, Decl(inferentialTypingObjectLiteralMethod2.ts, 0, 0)) +>T : Symbol(T, Decl(inferentialTypingObjectLiteralMethod2.ts, 0, 14)) +>U : Symbol(U, Decl(inferentialTypingObjectLiteralMethod2.ts, 0, 16)) + + [s: string]: (x: T) => U; +>s : Symbol(s, Decl(inferentialTypingObjectLiteralMethod2.ts, 1, 5)) +>x : Symbol(x, Decl(inferentialTypingObjectLiteralMethod2.ts, 1, 18)) +>T : Symbol(T, Decl(inferentialTypingObjectLiteralMethod2.ts, 0, 14)) +>U : Symbol(U, Decl(inferentialTypingObjectLiteralMethod2.ts, 0, 16)) +} +declare function foo(x: T, y: Int, z: Int): T; +>foo : Symbol(foo, Decl(inferentialTypingObjectLiteralMethod2.ts, 2, 1)) +>T : Symbol(T, Decl(inferentialTypingObjectLiteralMethod2.ts, 3, 21)) +>U : Symbol(U, Decl(inferentialTypingObjectLiteralMethod2.ts, 3, 23)) +>x : Symbol(x, Decl(inferentialTypingObjectLiteralMethod2.ts, 3, 27)) +>T : Symbol(T, Decl(inferentialTypingObjectLiteralMethod2.ts, 3, 21)) +>y : Symbol(y, Decl(inferentialTypingObjectLiteralMethod2.ts, 3, 32)) +>Int : Symbol(Int, Decl(inferentialTypingObjectLiteralMethod2.ts, 0, 0)) +>T : Symbol(T, Decl(inferentialTypingObjectLiteralMethod2.ts, 3, 21)) +>U : Symbol(U, Decl(inferentialTypingObjectLiteralMethod2.ts, 3, 23)) +>z : Symbol(z, Decl(inferentialTypingObjectLiteralMethod2.ts, 3, 46)) +>Int : Symbol(Int, Decl(inferentialTypingObjectLiteralMethod2.ts, 0, 0)) +>U : Symbol(U, Decl(inferentialTypingObjectLiteralMethod2.ts, 3, 23)) +>T : Symbol(T, Decl(inferentialTypingObjectLiteralMethod2.ts, 3, 21)) +>T : Symbol(T, Decl(inferentialTypingObjectLiteralMethod2.ts, 3, 21)) + +foo("", { method(p1) { return p1.length } }, { method(p2) { return undefined } }); +>foo : Symbol(foo, Decl(inferentialTypingObjectLiteralMethod2.ts, 2, 1)) +>method : Symbol(method, Decl(inferentialTypingObjectLiteralMethod2.ts, 4, 9)) +>p1 : Symbol(p1, Decl(inferentialTypingObjectLiteralMethod2.ts, 4, 17)) +>p1.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) +>p1 : Symbol(p1, Decl(inferentialTypingObjectLiteralMethod2.ts, 4, 17)) +>length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) +>method : Symbol(method, Decl(inferentialTypingObjectLiteralMethod2.ts, 4, 46)) +>p2 : Symbol(p2, Decl(inferentialTypingObjectLiteralMethod2.ts, 4, 54)) +>undefined : Symbol(undefined) + diff --git a/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.types b/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.types new file mode 100644 index 0000000000..be937410ce --- /dev/null +++ b/tests/baselines/reference/inferentialTypingObjectLiteralMethod2.types @@ -0,0 +1,43 @@ +=== tests/cases/compiler/inferentialTypingObjectLiteralMethod2.ts === +interface Int { +>Int : Int +>T : T +>U : U + + [s: string]: (x: T) => U; +>s : string +>x : T +>T : T +>U : U +} +declare function foo(x: T, y: Int, z: Int): T; +>foo : (x: T, y: Int, z: Int) => T +>T : T +>U : U +>x : T +>T : T +>y : Int +>Int : Int +>T : T +>U : U +>z : Int +>Int : Int +>U : U +>T : T +>T : T + +foo("", { method(p1) { return p1.length } }, { method(p2) { return undefined } }); +>foo("", { method(p1) { return p1.length } }, { method(p2) { return undefined } }) : string +>foo : (x: T, y: Int, z: Int) => T +>"" : string +>{ method(p1) { return p1.length } } : { [x: string]: (p1: string) => number; method(p1: string): number; } +>method : (p1: string) => number +>p1 : string +>p1.length : number +>p1 : string +>length : number +>{ method(p2) { return undefined } } : { [x: string]: (p2: number) => any; method(p2: number): any; } +>method : (p2: number) => any +>p2 : number +>undefined : undefined + diff --git a/tests/baselines/reference/invalidNestedModules.js b/tests/baselines/reference/invalidNestedModules.js index 5f3a19aaec..bec6491a63 100644 --- a/tests/baselines/reference/invalidNestedModules.js +++ b/tests/baselines/reference/invalidNestedModules.js @@ -73,6 +73,5 @@ var M2; (function (M2) { var X; (function (X) { - // Error })(X = M2.X || (M2.X = {})); })(M2 || (M2 = {})); diff --git a/tests/baselines/reference/isolatedModulesAmbientConstEnum.errors.txt b/tests/baselines/reference/isolatedModulesAmbientConstEnum.errors.txt new file mode 100644 index 0000000000..bb8a5202bc --- /dev/null +++ b/tests/baselines/reference/isolatedModulesAmbientConstEnum.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/isolatedModulesAmbientConstEnum.ts(3,20): error TS1209: Ambient const enums are not allowed when the '--isolatedModules' flag is provided. + + +==== tests/cases/compiler/isolatedModulesAmbientConstEnum.ts (1 errors) ==== + + + declare const enum E { X = 1} + ~ +!!! error TS1209: Ambient const enums are not allowed when the '--isolatedModules' flag is provided. + export var y; \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesAmbientConstEnum.js b/tests/baselines/reference/isolatedModulesAmbientConstEnum.js new file mode 100644 index 0000000000..7742122b68 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesAmbientConstEnum.js @@ -0,0 +1,8 @@ +//// [isolatedModulesAmbientConstEnum.ts] + + +declare const enum E { X = 1} +export var y; + +//// [isolatedModulesAmbientConstEnum.js] +export var y; diff --git a/tests/baselines/reference/separateCompilationDeclaration.errors.txt b/tests/baselines/reference/isolatedModulesDeclaration.errors.txt similarity index 52% rename from tests/baselines/reference/separateCompilationDeclaration.errors.txt rename to tests/baselines/reference/isolatedModulesDeclaration.errors.txt index 8951184584..de5cb97586 100644 --- a/tests/baselines/reference/separateCompilationDeclaration.errors.txt +++ b/tests/baselines/reference/isolatedModulesDeclaration.errors.txt @@ -1,7 +1,7 @@ -error TS5044: Option 'declaration' cannot be specified with option 'separateCompilation'. +error TS5044: Option 'declaration' cannot be specified with option 'isolatedModules'. -!!! error TS5044: Option 'declaration' cannot be specified with option 'separateCompilation'. -==== tests/cases/compiler/separateCompilationDeclaration.ts (0 errors) ==== +!!! error TS5044: Option 'declaration' cannot be specified with option 'isolatedModules'. +==== tests/cases/compiler/isolatedModulesDeclaration.ts (0 errors) ==== export var x; \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesDeclaration.js b/tests/baselines/reference/isolatedModulesDeclaration.js new file mode 100644 index 0000000000..12e6f23f92 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesDeclaration.js @@ -0,0 +1,10 @@ +//// [isolatedModulesDeclaration.ts] + +export var x; + +//// [isolatedModulesDeclaration.js] +export var x; + + +//// [isolatedModulesDeclaration.d.ts] +export declare var x: any; diff --git a/tests/baselines/reference/isolatedModulesES6.js b/tests/baselines/reference/isolatedModulesES6.js new file mode 100644 index 0000000000..eb2ee3ee33 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesES6.js @@ -0,0 +1,5 @@ +//// [isolatedModulesES6.ts] +export var x; + +//// [isolatedModulesES6.js] +export var x; diff --git a/tests/baselines/reference/isolatedModulesES6.symbols b/tests/baselines/reference/isolatedModulesES6.symbols new file mode 100644 index 0000000000..c705cbc5af --- /dev/null +++ b/tests/baselines/reference/isolatedModulesES6.symbols @@ -0,0 +1,4 @@ +=== tests/cases/compiler/isolatedModulesES6.ts === +export var x; +>x : Symbol(x, Decl(isolatedModulesES6.ts, 0, 10)) + diff --git a/tests/baselines/reference/isolatedModulesES6.types b/tests/baselines/reference/isolatedModulesES6.types new file mode 100644 index 0000000000..898b9715ca --- /dev/null +++ b/tests/baselines/reference/isolatedModulesES6.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/isolatedModulesES6.ts === +export var x; +>x : any + diff --git a/tests/baselines/reference/isolatedModulesImportExportElision.errors.txt b/tests/baselines/reference/isolatedModulesImportExportElision.errors.txt new file mode 100644 index 0000000000..8c6881a9bc --- /dev/null +++ b/tests/baselines/reference/isolatedModulesImportExportElision.errors.txt @@ -0,0 +1,28 @@ +tests/cases/compiler/isolatedModulesImportExportElision.ts(2,17): error TS2307: Cannot find module 'module'. +tests/cases/compiler/isolatedModulesImportExportElision.ts(3,18): error TS2307: Cannot find module 'module'. +tests/cases/compiler/isolatedModulesImportExportElision.ts(4,21): error TS2307: Cannot find module 'module'. +tests/cases/compiler/isolatedModulesImportExportElision.ts(12,18): error TS2307: Cannot find module 'module'. + + +==== tests/cases/compiler/isolatedModulesImportExportElision.ts (4 errors) ==== + + import {c} from "module" + ~~~~~~~~ +!!! error TS2307: Cannot find module 'module'. + import {c2} from "module" + ~~~~~~~~ +!!! error TS2307: Cannot find module 'module'. + import * as ns from "module" + ~~~~~~~~ +!!! error TS2307: Cannot find module 'module'. + + class C extends c2.C { + } + + let x = new c(); + let y = ns.value; + + export {c1} from "module"; + ~~~~~~~~ +!!! error TS2307: Cannot find module 'module'. + export var z = x; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationImportExportElision.js b/tests/baselines/reference/isolatedModulesImportExportElision.js similarity index 86% rename from tests/baselines/reference/separateCompilationImportExportElision.js rename to tests/baselines/reference/isolatedModulesImportExportElision.js index cfa5798024..ca3eee0ac2 100644 --- a/tests/baselines/reference/separateCompilationImportExportElision.js +++ b/tests/baselines/reference/isolatedModulesImportExportElision.js @@ -1,4 +1,4 @@ -//// [separateCompilationImportExportElision.ts] +//// [isolatedModulesImportExportElision.ts] import {c} from "module" import {c2} from "module" @@ -13,7 +13,7 @@ let y = ns.value; export {c1} from "module"; export var z = x; -//// [separateCompilationImportExportElision.js] +//// [isolatedModulesImportExportElision.js] var __extends = (this && this.__extends) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; function __() { this.constructor = d; } diff --git a/tests/baselines/reference/separateCompilationNoEmitOnError.errors.txt b/tests/baselines/reference/isolatedModulesNoEmitOnError.errors.txt similarity index 51% rename from tests/baselines/reference/separateCompilationNoEmitOnError.errors.txt rename to tests/baselines/reference/isolatedModulesNoEmitOnError.errors.txt index 61d4f2d6d9..68b2747cf6 100644 --- a/tests/baselines/reference/separateCompilationNoEmitOnError.errors.txt +++ b/tests/baselines/reference/isolatedModulesNoEmitOnError.errors.txt @@ -1,7 +1,7 @@ -error TS5045: Option 'noEmitOnError' cannot be specified with option 'separateCompilation'. +error TS5045: Option 'noEmitOnError' cannot be specified with option 'isolatedModules'. -!!! error TS5045: Option 'noEmitOnError' cannot be specified with option 'separateCompilation'. -==== tests/cases/compiler/separateCompilationNoEmitOnError.ts (0 errors) ==== +!!! error TS5045: Option 'noEmitOnError' cannot be specified with option 'isolatedModules'. +==== tests/cases/compiler/isolatedModulesNoEmitOnError.ts (0 errors) ==== export var x; \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesNoExternalModule.errors.txt b/tests/baselines/reference/isolatedModulesNoExternalModule.errors.txt new file mode 100644 index 0000000000..d00520a061 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesNoExternalModule.errors.txt @@ -0,0 +1,8 @@ +tests/cases/compiler/isolatedModulesNoExternalModule.ts(2,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. + + +==== tests/cases/compiler/isolatedModulesNoExternalModule.ts (1 errors) ==== + + var x; + ~~~ +!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesNoExternalModule.js b/tests/baselines/reference/isolatedModulesNoExternalModule.js new file mode 100644 index 0000000000..dd5d23a538 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesNoExternalModule.js @@ -0,0 +1,6 @@ +//// [isolatedModulesNoExternalModule.ts] + +var x; + +//// [isolatedModulesNoExternalModule.js] +var x; diff --git a/tests/baselines/reference/separateCompilationNonAmbientConstEnum.js b/tests/baselines/reference/isolatedModulesNonAmbientConstEnum.js similarity index 58% rename from tests/baselines/reference/separateCompilationNonAmbientConstEnum.js rename to tests/baselines/reference/isolatedModulesNonAmbientConstEnum.js index 74096adca1..efdba17dc9 100644 --- a/tests/baselines/reference/separateCompilationNonAmbientConstEnum.js +++ b/tests/baselines/reference/isolatedModulesNonAmbientConstEnum.js @@ -1,10 +1,10 @@ -//// [separateCompilationNonAmbientConstEnum.ts] +//// [isolatedModulesNonAmbientConstEnum.ts] const enum E { X = 100 }; var e = E.X; export var x; -//// [separateCompilationNonAmbientConstEnum.js] +//// [isolatedModulesNonAmbientConstEnum.js] var E; (function (E) { E[E["X"] = 100] = "X"; diff --git a/tests/baselines/reference/isolatedModulesNonAmbientConstEnum.symbols b/tests/baselines/reference/isolatedModulesNonAmbientConstEnum.symbols new file mode 100644 index 0000000000..5e30fd0b2f --- /dev/null +++ b/tests/baselines/reference/isolatedModulesNonAmbientConstEnum.symbols @@ -0,0 +1,15 @@ +=== tests/cases/compiler/isolatedModulesNonAmbientConstEnum.ts === + +const enum E { X = 100 }; +>E : Symbol(E, Decl(isolatedModulesNonAmbientConstEnum.ts, 0, 0)) +>X : Symbol(E.X, Decl(isolatedModulesNonAmbientConstEnum.ts, 1, 14)) + +var e = E.X; +>e : Symbol(e, Decl(isolatedModulesNonAmbientConstEnum.ts, 2, 3)) +>E.X : Symbol(E.X, Decl(isolatedModulesNonAmbientConstEnum.ts, 1, 14)) +>E : Symbol(E, Decl(isolatedModulesNonAmbientConstEnum.ts, 0, 0)) +>X : Symbol(E.X, Decl(isolatedModulesNonAmbientConstEnum.ts, 1, 14)) + +export var x; +>x : Symbol(x, Decl(isolatedModulesNonAmbientConstEnum.ts, 3, 10)) + diff --git a/tests/baselines/reference/separateCompilationNonAmbientConstEnum.types b/tests/baselines/reference/isolatedModulesNonAmbientConstEnum.types similarity index 60% rename from tests/baselines/reference/separateCompilationNonAmbientConstEnum.types rename to tests/baselines/reference/isolatedModulesNonAmbientConstEnum.types index ce55b80f41..d7e83b8107 100644 --- a/tests/baselines/reference/separateCompilationNonAmbientConstEnum.types +++ b/tests/baselines/reference/isolatedModulesNonAmbientConstEnum.types @@ -1,4 +1,4 @@ -=== tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts === +=== tests/cases/compiler/isolatedModulesNonAmbientConstEnum.ts === const enum E { X = 100 }; >E : E diff --git a/tests/baselines/reference/separateCompilationOut.errors.txt b/tests/baselines/reference/isolatedModulesOut.errors.txt similarity index 50% rename from tests/baselines/reference/separateCompilationOut.errors.txt rename to tests/baselines/reference/isolatedModulesOut.errors.txt index 9017809901..8234ba9458 100644 --- a/tests/baselines/reference/separateCompilationOut.errors.txt +++ b/tests/baselines/reference/isolatedModulesOut.errors.txt @@ -1,12 +1,12 @@ -error TS5046: Option 'out' cannot be specified with option 'separateCompilation'. -tests/cases/compiler/file2.ts(1,1): error TS1208: Cannot compile namespaces when the '--separateCompilation' flag is provided. +error TS5046: Option 'out' cannot be specified with option 'isolatedModules'. +tests/cases/compiler/file2.ts(1,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. -!!! error TS5046: Option 'out' cannot be specified with option 'separateCompilation'. +!!! error TS5046: Option 'out' cannot be specified with option 'isolatedModules'. ==== tests/cases/compiler/file1.ts (0 errors) ==== export var x; ==== tests/cases/compiler/file2.ts (1 errors) ==== var y; ~~~ -!!! error TS1208: Cannot compile namespaces when the '--separateCompilation' flag is provided. \ No newline at end of file +!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationOut.js b/tests/baselines/reference/isolatedModulesOut.js similarity index 60% rename from tests/baselines/reference/separateCompilationOut.js rename to tests/baselines/reference/isolatedModulesOut.js index 67dd2dcfbf..ca5eb2b757 100644 --- a/tests/baselines/reference/separateCompilationOut.js +++ b/tests/baselines/reference/isolatedModulesOut.js @@ -1,4 +1,4 @@ -//// [tests/cases/compiler/separateCompilationOut.ts] //// +//// [tests/cases/compiler/isolatedModulesOut.ts] //// //// [file1.ts] diff --git a/tests/baselines/reference/isolatedModulesPlainFile-AMD.errors.txt b/tests/baselines/reference/isolatedModulesPlainFile-AMD.errors.txt new file mode 100644 index 0000000000..680070a73c --- /dev/null +++ b/tests/baselines/reference/isolatedModulesPlainFile-AMD.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/isolatedModulesPlainFile-AMD.ts(2,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. + + +==== tests/cases/compiler/isolatedModulesPlainFile-AMD.ts (1 errors) ==== + + declare function run(a: number): void; + ~~~~~~~ +!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. + run(1); + \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationPlainFile-AMD.js b/tests/baselines/reference/isolatedModulesPlainFile-AMD.js similarity index 57% rename from tests/baselines/reference/separateCompilationPlainFile-AMD.js rename to tests/baselines/reference/isolatedModulesPlainFile-AMD.js index e3e9fc1eae..7f4f421912 100644 --- a/tests/baselines/reference/separateCompilationPlainFile-AMD.js +++ b/tests/baselines/reference/isolatedModulesPlainFile-AMD.js @@ -1,10 +1,10 @@ -//// [separateCompilationPlainFile-AMD.ts] +//// [isolatedModulesPlainFile-AMD.ts] declare function run(a: number): void; run(1); -//// [separateCompilationPlainFile-AMD.js] +//// [isolatedModulesPlainFile-AMD.js] define(["require", "exports"], function (require, exports) { run(1); }); diff --git a/tests/baselines/reference/isolatedModulesPlainFile-CommonJS.errors.txt b/tests/baselines/reference/isolatedModulesPlainFile-CommonJS.errors.txt new file mode 100644 index 0000000000..d1f0ca3caa --- /dev/null +++ b/tests/baselines/reference/isolatedModulesPlainFile-CommonJS.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/isolatedModulesPlainFile-CommonJS.ts(2,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. + + +==== tests/cases/compiler/isolatedModulesPlainFile-CommonJS.ts (1 errors) ==== + + declare function run(a: number): void; + ~~~~~~~ +!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. + run(1); + \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesPlainFile-CommonJS.js b/tests/baselines/reference/isolatedModulesPlainFile-CommonJS.js new file mode 100644 index 0000000000..7026a7d9be --- /dev/null +++ b/tests/baselines/reference/isolatedModulesPlainFile-CommonJS.js @@ -0,0 +1,8 @@ +//// [isolatedModulesPlainFile-CommonJS.ts] + +declare function run(a: number): void; +run(1); + + +//// [isolatedModulesPlainFile-CommonJS.js] +run(1); diff --git a/tests/baselines/reference/isolatedModulesPlainFile-ES6.errors.txt b/tests/baselines/reference/isolatedModulesPlainFile-ES6.errors.txt new file mode 100644 index 0000000000..d46fce22fd --- /dev/null +++ b/tests/baselines/reference/isolatedModulesPlainFile-ES6.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/isolatedModulesPlainFile-ES6.ts(2,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. + + +==== tests/cases/compiler/isolatedModulesPlainFile-ES6.ts (1 errors) ==== + + declare function run(a: number): void; + ~~~~~~~ +!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. + run(1); + \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesPlainFile-ES6.js b/tests/baselines/reference/isolatedModulesPlainFile-ES6.js new file mode 100644 index 0000000000..245d3fe668 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesPlainFile-ES6.js @@ -0,0 +1,8 @@ +//// [isolatedModulesPlainFile-ES6.ts] + +declare function run(a: number): void; +run(1); + + +//// [isolatedModulesPlainFile-ES6.js] +run(1); diff --git a/tests/baselines/reference/isolatedModulesPlainFile-System.errors.txt b/tests/baselines/reference/isolatedModulesPlainFile-System.errors.txt new file mode 100644 index 0000000000..fe1a2f8001 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesPlainFile-System.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/isolatedModulesPlainFile-System.ts(2,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. + + +==== tests/cases/compiler/isolatedModulesPlainFile-System.ts (1 errors) ==== + + declare function run(a: number): void; + ~~~~~~~ +!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. + run(1); + \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationPlainFile-System.js b/tests/baselines/reference/isolatedModulesPlainFile-System.js similarity index 65% rename from tests/baselines/reference/separateCompilationPlainFile-System.js rename to tests/baselines/reference/isolatedModulesPlainFile-System.js index c256ed7862..b924a3b21f 100644 --- a/tests/baselines/reference/separateCompilationPlainFile-System.js +++ b/tests/baselines/reference/isolatedModulesPlainFile-System.js @@ -1,10 +1,10 @@ -//// [separateCompilationPlainFile-System.ts] +//// [isolatedModulesPlainFile-System.ts] declare function run(a: number): void; run(1); -//// [separateCompilationPlainFile-System.js] +//// [isolatedModulesPlainFile-System.js] System.register([], function(exports_1) { return { setters:[], diff --git a/tests/baselines/reference/isolatedModulesPlainFile-UMD.errors.txt b/tests/baselines/reference/isolatedModulesPlainFile-UMD.errors.txt new file mode 100644 index 0000000000..24c5c86f8f --- /dev/null +++ b/tests/baselines/reference/isolatedModulesPlainFile-UMD.errors.txt @@ -0,0 +1,10 @@ +tests/cases/compiler/isolatedModulesPlainFile-UMD.ts(2,1): error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. + + +==== tests/cases/compiler/isolatedModulesPlainFile-UMD.ts (1 errors) ==== + + declare function run(a: number): void; + ~~~~~~~ +!!! error TS1208: Cannot compile namespaces when the '--isolatedModules' flag is provided. + run(1); + \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationPlainFile-UMD.js b/tests/baselines/reference/isolatedModulesPlainFile-UMD.js similarity index 80% rename from tests/baselines/reference/separateCompilationPlainFile-UMD.js rename to tests/baselines/reference/isolatedModulesPlainFile-UMD.js index 6a145e7d23..0ed6e83a37 100644 --- a/tests/baselines/reference/separateCompilationPlainFile-UMD.js +++ b/tests/baselines/reference/isolatedModulesPlainFile-UMD.js @@ -1,10 +1,10 @@ -//// [separateCompilationPlainFile-UMD.ts] +//// [isolatedModulesPlainFile-UMD.ts] declare function run(a: number): void; run(1); -//// [separateCompilationPlainFile-UMD.js] +//// [isolatedModulesPlainFile-UMD.js] (function (deps, factory) { if (typeof module === 'object' && typeof module.exports === 'object') { var v = factory(require, exports); if (v !== undefined) module.exports = v; diff --git a/tests/baselines/reference/separateCompilationSourceMap.errors.txt b/tests/baselines/reference/isolatedModulesSourceMap.errors.txt similarity index 53% rename from tests/baselines/reference/separateCompilationSourceMap.errors.txt rename to tests/baselines/reference/isolatedModulesSourceMap.errors.txt index 5274ef3921..6383e85ecd 100644 --- a/tests/baselines/reference/separateCompilationSourceMap.errors.txt +++ b/tests/baselines/reference/isolatedModulesSourceMap.errors.txt @@ -1,7 +1,7 @@ -error TS5043: Option 'sourceMap' cannot be specified with option 'separateCompilation'. +error TS5043: Option 'sourceMap' cannot be specified with option 'isolatedModules'. -!!! error TS5043: Option 'sourceMap' cannot be specified with option 'separateCompilation'. -==== tests/cases/compiler/separateCompilationSourceMap.ts (0 errors) ==== +!!! error TS5043: Option 'sourceMap' cannot be specified with option 'isolatedModules'. +==== tests/cases/compiler/isolatedModulesSourceMap.ts (0 errors) ==== export var x; \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesSourceMap.js b/tests/baselines/reference/isolatedModulesSourceMap.js new file mode 100644 index 0000000000..ca6f4b4190 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesSourceMap.js @@ -0,0 +1,7 @@ +//// [isolatedModulesSourceMap.ts] + +export var x; + +//// [isolatedModulesSourceMap.js] +export var x; +//# sourceMappingURL=isolatedModulesSourceMap.js.map \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesSourceMap.js.map b/tests/baselines/reference/isolatedModulesSourceMap.js.map new file mode 100644 index 0000000000..8e505dcda7 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesSourceMap.js.map @@ -0,0 +1,2 @@ +//// [isolatedModulesSourceMap.js.map] +{"version":3,"file":"isolatedModulesSourceMap.js","sourceRoot":"","sources":["isolatedModulesSourceMap.ts"],"names":[],"mappings":"AACA,WAAW,CAAC,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationSourceMap.sourcemap.txt b/tests/baselines/reference/isolatedModulesSourceMap.sourcemap.txt similarity index 61% rename from tests/baselines/reference/separateCompilationSourceMap.sourcemap.txt rename to tests/baselines/reference/isolatedModulesSourceMap.sourcemap.txt index 74e0d73d7e..5c6b7659bc 100644 --- a/tests/baselines/reference/separateCompilationSourceMap.sourcemap.txt +++ b/tests/baselines/reference/isolatedModulesSourceMap.sourcemap.txt @@ -1,19 +1,19 @@ =================================================================== -JsFile: separateCompilationSourceMap.js -mapUrl: separateCompilationSourceMap.js.map +JsFile: isolatedModulesSourceMap.js +mapUrl: isolatedModulesSourceMap.js.map sourceRoot: -sources: separateCompilationSourceMap.ts +sources: isolatedModulesSourceMap.ts =================================================================== ------------------------------------------------------------------- -emittedFile:tests/cases/compiler/separateCompilationSourceMap.js -sourceFile:separateCompilationSourceMap.ts +emittedFile:tests/cases/compiler/isolatedModulesSourceMap.js +sourceFile:isolatedModulesSourceMap.ts ------------------------------------------------------------------- >>>export var x; 1 > 2 >^^^^^^^^^^^ 3 > ^ 4 > ^ -5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> +5 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-> 1 > > 2 >export var @@ -24,4 +24,4 @@ sourceFile:separateCompilationSourceMap.ts 3 >Emitted(1, 13) Source(2, 13) + SourceIndex(0) 4 >Emitted(1, 14) Source(2, 14) + SourceIndex(0) --- ->>>//# sourceMappingURL=separateCompilationSourceMap.js.map \ No newline at end of file +>>>//# sourceMappingURL=isolatedModulesSourceMap.js.map \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesSpecifiedModule.js b/tests/baselines/reference/isolatedModulesSpecifiedModule.js new file mode 100644 index 0000000000..95e4ec88d9 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesSpecifiedModule.js @@ -0,0 +1,4 @@ +//// [isolatedModulesSpecifiedModule.ts] +export var x; + +//// [isolatedModulesSpecifiedModule.js] diff --git a/tests/baselines/reference/isolatedModulesSpecifiedModule.symbols b/tests/baselines/reference/isolatedModulesSpecifiedModule.symbols new file mode 100644 index 0000000000..91ede682d7 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesSpecifiedModule.symbols @@ -0,0 +1,4 @@ +=== tests/cases/compiler/isolatedModulesSpecifiedModule.ts === +export var x; +>x : Symbol(x, Decl(isolatedModulesSpecifiedModule.ts, 0, 10)) + diff --git a/tests/baselines/reference/isolatedModulesSpecifiedModule.types b/tests/baselines/reference/isolatedModulesSpecifiedModule.types new file mode 100644 index 0000000000..8dee90a199 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesSpecifiedModule.types @@ -0,0 +1,4 @@ +=== tests/cases/compiler/isolatedModulesSpecifiedModule.ts === +export var x; +>x : any + diff --git a/tests/baselines/reference/isolatedModulesUnspecifiedModule.errors.txt b/tests/baselines/reference/isolatedModulesUnspecifiedModule.errors.txt new file mode 100644 index 0000000000..7d290bcae4 --- /dev/null +++ b/tests/baselines/reference/isolatedModulesUnspecifiedModule.errors.txt @@ -0,0 +1,6 @@ +error TS5047: Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher. + + +!!! error TS5047: Option 'isolatedModules' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher. +==== tests/cases/compiler/isolatedModulesUnspecifiedModule.ts (0 errors) ==== + export var x; \ No newline at end of file diff --git a/tests/baselines/reference/isolatedModulesUnspecifiedModule.js b/tests/baselines/reference/isolatedModulesUnspecifiedModule.js new file mode 100644 index 0000000000..68b9bfb62d --- /dev/null +++ b/tests/baselines/reference/isolatedModulesUnspecifiedModule.js @@ -0,0 +1,4 @@ +//// [isolatedModulesUnspecifiedModule.ts] +export var x; + +//// [isolatedModulesUnspecifiedModule.js] diff --git a/tests/baselines/reference/separateCompilationWithDeclarationFile.js b/tests/baselines/reference/isolatedModulesWithDeclarationFile.js similarity index 57% rename from tests/baselines/reference/separateCompilationWithDeclarationFile.js rename to tests/baselines/reference/isolatedModulesWithDeclarationFile.js index 71d7ef4192..42d091b610 100644 --- a/tests/baselines/reference/separateCompilationWithDeclarationFile.js +++ b/tests/baselines/reference/isolatedModulesWithDeclarationFile.js @@ -1,4 +1,4 @@ -//// [tests/cases/compiler/separateCompilationWithDeclarationFile.ts] //// +//// [tests/cases/compiler/isolatedModulesWithDeclarationFile.ts] //// //// [file1.d.ts] diff --git a/tests/baselines/reference/separateCompilationWithDeclarationFile.symbols b/tests/baselines/reference/isolatedModulesWithDeclarationFile.symbols similarity index 100% rename from tests/baselines/reference/separateCompilationWithDeclarationFile.symbols rename to tests/baselines/reference/isolatedModulesWithDeclarationFile.symbols diff --git a/tests/baselines/reference/separateCompilationWithDeclarationFile.types b/tests/baselines/reference/isolatedModulesWithDeclarationFile.types similarity index 100% rename from tests/baselines/reference/separateCompilationWithDeclarationFile.types rename to tests/baselines/reference/isolatedModulesWithDeclarationFile.types diff --git a/tests/baselines/reference/iterableArrayPattern30.symbols b/tests/baselines/reference/iterableArrayPattern30.symbols index 0f50713b43..715dd79c97 100644 --- a/tests/baselines/reference/iterableArrayPattern30.symbols +++ b/tests/baselines/reference/iterableArrayPattern30.symbols @@ -4,5 +4,5 @@ const [[k1, v1], [k2, v2]] = new Map([["", true], ["hello", true]]) >v1 : Symbol(v1, Decl(iterableArrayPattern30.ts, 0, 11)) >k2 : Symbol(k2, Decl(iterableArrayPattern30.ts, 0, 18)) >v2 : Symbol(v2, Decl(iterableArrayPattern30.ts, 0, 21)) ->Map : Symbol(Map, Decl(lib.d.ts, 1867, 1), Decl(lib.d.ts, 1889, 11)) +>Map : Symbol(Map, Decl(lib.d.ts, 1864, 1), Decl(lib.d.ts, 1886, 11)) diff --git a/tests/baselines/reference/iterableContextualTyping1.symbols b/tests/baselines/reference/iterableContextualTyping1.symbols index 76d94dc292..a900c56eca 100644 --- a/tests/baselines/reference/iterableContextualTyping1.symbols +++ b/tests/baselines/reference/iterableContextualTyping1.symbols @@ -1,7 +1,7 @@ === tests/cases/conformance/expressions/contextualTyping/iterableContextualTyping1.ts === var iter: Iterable<(x: string) => number> = [s => s.length]; >iter : Symbol(iter, Decl(iterableContextualTyping1.ts, 0, 3)) ->Iterable : Symbol(Iterable, Decl(lib.d.ts, 1663, 1)) +>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1)) >x : Symbol(x, Decl(iterableContextualTyping1.ts, 0, 20)) >s : Symbol(s, Decl(iterableContextualTyping1.ts, 0, 45)) >s.length : Symbol(String.length, Decl(lib.d.ts, 414, 19)) diff --git a/tests/baselines/reference/iteratorSpreadInArray11.symbols b/tests/baselines/reference/iteratorSpreadInArray11.symbols index b128803aa5..548e026744 100644 --- a/tests/baselines/reference/iteratorSpreadInArray11.symbols +++ b/tests/baselines/reference/iteratorSpreadInArray11.symbols @@ -1,7 +1,7 @@ === tests/cases/conformance/es6/spread/iteratorSpreadInArray11.ts === var iter: Iterable; >iter : Symbol(iter, Decl(iteratorSpreadInArray11.ts, 0, 3)) ->Iterable : Symbol(Iterable, Decl(lib.d.ts, 1663, 1)) +>Iterable : Symbol(Iterable, Decl(lib.d.ts, 1668, 1)) var array = [...iter]; >array : Symbol(array, Decl(iteratorSpreadInArray11.ts, 1, 3)) diff --git a/tests/baselines/reference/localTypes1.js b/tests/baselines/reference/localTypes1.js new file mode 100644 index 0000000000..d1c3758920 --- /dev/null +++ b/tests/baselines/reference/localTypes1.js @@ -0,0 +1,325 @@ +//// [localTypes1.ts] + +function f1() { + enum E { + A, B, C + } + class C { + x: E; + } + interface I { + x: E; + } + type A = I[]; + let a: A = [new C()]; + a[0].x = E.B; + return a; +} + +function f2() { + function g() { + enum E { + A, B, C + } + class C { + x: E; + } + interface I { + x: E; + } + type A = I[]; + let a: A = [new C()]; + a[0].x = E.B; + return a; + } + return g(); +} + +function f3(b: boolean) { + if (true) { + enum E { + A, B, C + } + if (b) { + class C { + x: E; + } + interface I { + x: E; + } + type A = I[]; + let a: A = [new C()]; + a[0].x = E.B; + return a; + } + else { + class A { + x: E; + } + interface J { + x: E; + } + type C = J[]; + let c: C = [new A()]; + c[0].x = E.B; + return c; + } + } +} + +function f5() { + var z1 = function () { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } + var z2 = () => { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } +} + +class A { + constructor() { + enum E { + A, B, C + } + class C { + x: E; + } + } + m() { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } + get p() { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } +} + +function f6() { + class A { + a: string; + } + function g() { + class B extends A { + b: string; + } + function h() { + class C extends B { + c: string; + } + var x = new C(); + x.a = "a"; + x.b = "b"; + x.c = "c"; + return x; + } + return h(); + } + return g(); +} + + +//// [localTypes1.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +function f1() { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + var C = (function () { + function C() { + } + return C; + })(); + var a = [new C()]; + a[0].x = E.B; + return a; +} +function f2() { + function g() { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + var C = (function () { + function C() { + } + return C; + })(); + var a = [new C()]; + a[0].x = E.B; + return a; + } + return g(); +} +function f3(b) { + if (true) { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + if (b) { + var C = (function () { + function C() { + } + return C; + })(); + var a = [new C()]; + a[0].x = E.B; + return a; + } + else { + var A = (function () { + function A() { + } + return A; + })(); + var c = [new A()]; + c[0].x = E.B; + return c; + } + } +} +function f5() { + var z1 = function () { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + var C = (function () { + function C() { + } + return C; + })(); + return new C(); + }; + var z2 = function () { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + var C = (function () { + function C() { + } + return C; + })(); + return new C(); + }; +} +var A = (function () { + function A() { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + var C = (function () { + function C() { + } + return C; + })(); + } + A.prototype.m = function () { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + var C = (function () { + function C() { + } + return C; + })(); + return new C(); + }; + Object.defineProperty(A.prototype, "p", { + get: function () { + var E; + (function (E) { + E[E["A"] = 0] = "A"; + E[E["B"] = 1] = "B"; + E[E["C"] = 2] = "C"; + })(E || (E = {})); + var C = (function () { + function C() { + } + return C; + })(); + return new C(); + }, + enumerable: true, + configurable: true + }); + return A; +})(); +function f6() { + var A = (function () { + function A() { + } + return A; + })(); + function g() { + var B = (function (_super) { + __extends(B, _super); + function B() { + _super.apply(this, arguments); + } + return B; + })(A); + function h() { + var C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + } + return C; + })(B); + var x = new C(); + x.a = "a"; + x.b = "b"; + x.c = "c"; + return x; + } + return h(); + } + return g(); +} diff --git a/tests/baselines/reference/localTypes1.symbols b/tests/baselines/reference/localTypes1.symbols new file mode 100644 index 0000000000..53d4191ae6 --- /dev/null +++ b/tests/baselines/reference/localTypes1.symbols @@ -0,0 +1,357 @@ +=== tests/cases/conformance/types/localTypes/localTypes1.ts === + +function f1() { +>f1 : Symbol(f1, Decl(localTypes1.ts, 0, 0)) + + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 1, 15)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 2, 12)) +>B : Symbol(E.B, Decl(localTypes1.ts, 3, 10)) +>C : Symbol(E.C, Decl(localTypes1.ts, 3, 13)) + } + class C { +>C : Symbol(C, Decl(localTypes1.ts, 4, 5)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 5, 13)) +>E : Symbol(E, Decl(localTypes1.ts, 1, 15)) + } + interface I { +>I : Symbol(I, Decl(localTypes1.ts, 7, 5)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 8, 17)) +>E : Symbol(E, Decl(localTypes1.ts, 1, 15)) + } + type A = I[]; +>A : Symbol(A, Decl(localTypes1.ts, 10, 5)) +>I : Symbol(I, Decl(localTypes1.ts, 7, 5)) + + let a: A = [new C()]; +>a : Symbol(a, Decl(localTypes1.ts, 12, 7)) +>A : Symbol(A, Decl(localTypes1.ts, 10, 5)) +>C : Symbol(C, Decl(localTypes1.ts, 4, 5)) + + a[0].x = E.B; +>a[0].x : Symbol(I.x, Decl(localTypes1.ts, 8, 17)) +>a : Symbol(a, Decl(localTypes1.ts, 12, 7)) +>x : Symbol(I.x, Decl(localTypes1.ts, 8, 17)) +>E.B : Symbol(E.B, Decl(localTypes1.ts, 3, 10)) +>E : Symbol(E, Decl(localTypes1.ts, 1, 15)) +>B : Symbol(E.B, Decl(localTypes1.ts, 3, 10)) + + return a; +>a : Symbol(a, Decl(localTypes1.ts, 12, 7)) +} + +function f2() { +>f2 : Symbol(f2, Decl(localTypes1.ts, 15, 1)) + + function g() { +>g : Symbol(g, Decl(localTypes1.ts, 17, 15)) + + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 18, 18)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 19, 16)) +>B : Symbol(E.B, Decl(localTypes1.ts, 20, 14)) +>C : Symbol(E.C, Decl(localTypes1.ts, 20, 17)) + } + class C { +>C : Symbol(C, Decl(localTypes1.ts, 21, 9)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 22, 17)) +>E : Symbol(E, Decl(localTypes1.ts, 18, 18)) + } + interface I { +>I : Symbol(I, Decl(localTypes1.ts, 24, 9)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 25, 21)) +>E : Symbol(E, Decl(localTypes1.ts, 18, 18)) + } + type A = I[]; +>A : Symbol(A, Decl(localTypes1.ts, 27, 9)) +>I : Symbol(I, Decl(localTypes1.ts, 24, 9)) + + let a: A = [new C()]; +>a : Symbol(a, Decl(localTypes1.ts, 29, 11)) +>A : Symbol(A, Decl(localTypes1.ts, 27, 9)) +>C : Symbol(C, Decl(localTypes1.ts, 21, 9)) + + a[0].x = E.B; +>a[0].x : Symbol(I.x, Decl(localTypes1.ts, 25, 21)) +>a : Symbol(a, Decl(localTypes1.ts, 29, 11)) +>x : Symbol(I.x, Decl(localTypes1.ts, 25, 21)) +>E.B : Symbol(E.B, Decl(localTypes1.ts, 20, 14)) +>E : Symbol(E, Decl(localTypes1.ts, 18, 18)) +>B : Symbol(E.B, Decl(localTypes1.ts, 20, 14)) + + return a; +>a : Symbol(a, Decl(localTypes1.ts, 29, 11)) + } + return g(); +>g : Symbol(g, Decl(localTypes1.ts, 17, 15)) +} + +function f3(b: boolean) { +>f3 : Symbol(f3, Decl(localTypes1.ts, 34, 1)) +>b : Symbol(b, Decl(localTypes1.ts, 36, 12)) + + if (true) { + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 37, 15)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 38, 16)) +>B : Symbol(E.B, Decl(localTypes1.ts, 39, 14)) +>C : Symbol(E.C, Decl(localTypes1.ts, 39, 17)) + } + if (b) { +>b : Symbol(b, Decl(localTypes1.ts, 36, 12)) + + class C { +>C : Symbol(C, Decl(localTypes1.ts, 41, 16)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 42, 21)) +>E : Symbol(E, Decl(localTypes1.ts, 37, 15)) + } + interface I { +>I : Symbol(I, Decl(localTypes1.ts, 44, 13)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 45, 25)) +>E : Symbol(E, Decl(localTypes1.ts, 37, 15)) + } + type A = I[]; +>A : Symbol(A, Decl(localTypes1.ts, 47, 13)) +>I : Symbol(I, Decl(localTypes1.ts, 44, 13)) + + let a: A = [new C()]; +>a : Symbol(a, Decl(localTypes1.ts, 49, 15)) +>A : Symbol(A, Decl(localTypes1.ts, 47, 13)) +>C : Symbol(C, Decl(localTypes1.ts, 41, 16)) + + a[0].x = E.B; +>a[0].x : Symbol(I.x, Decl(localTypes1.ts, 45, 25)) +>a : Symbol(a, Decl(localTypes1.ts, 49, 15)) +>x : Symbol(I.x, Decl(localTypes1.ts, 45, 25)) +>E.B : Symbol(E.B, Decl(localTypes1.ts, 39, 14)) +>E : Symbol(E, Decl(localTypes1.ts, 37, 15)) +>B : Symbol(E.B, Decl(localTypes1.ts, 39, 14)) + + return a; +>a : Symbol(a, Decl(localTypes1.ts, 49, 15)) + } + else { + class A { +>A : Symbol(A, Decl(localTypes1.ts, 53, 14)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 54, 21)) +>E : Symbol(E, Decl(localTypes1.ts, 37, 15)) + } + interface J { +>J : Symbol(J, Decl(localTypes1.ts, 56, 13)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 57, 25)) +>E : Symbol(E, Decl(localTypes1.ts, 37, 15)) + } + type C = J[]; +>C : Symbol(C, Decl(localTypes1.ts, 59, 13)) +>J : Symbol(J, Decl(localTypes1.ts, 56, 13)) + + let c: C = [new A()]; +>c : Symbol(c, Decl(localTypes1.ts, 61, 15)) +>C : Symbol(C, Decl(localTypes1.ts, 59, 13)) +>A : Symbol(A, Decl(localTypes1.ts, 53, 14)) + + c[0].x = E.B; +>c[0].x : Symbol(J.x, Decl(localTypes1.ts, 57, 25)) +>c : Symbol(c, Decl(localTypes1.ts, 61, 15)) +>x : Symbol(J.x, Decl(localTypes1.ts, 57, 25)) +>E.B : Symbol(E.B, Decl(localTypes1.ts, 39, 14)) +>E : Symbol(E, Decl(localTypes1.ts, 37, 15)) +>B : Symbol(E.B, Decl(localTypes1.ts, 39, 14)) + + return c; +>c : Symbol(c, Decl(localTypes1.ts, 61, 15)) + } + } +} + +function f5() { +>f5 : Symbol(f5, Decl(localTypes1.ts, 66, 1)) + + var z1 = function () { +>z1 : Symbol(z1, Decl(localTypes1.ts, 69, 7)) + + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 69, 26)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 70, 16)) +>B : Symbol(E.B, Decl(localTypes1.ts, 71, 14)) +>C : Symbol(E.C, Decl(localTypes1.ts, 71, 17)) + } + class C { +>C : Symbol(C, Decl(localTypes1.ts, 72, 9)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 73, 17)) +>E : Symbol(E, Decl(localTypes1.ts, 69, 26)) + } + return new C(); +>C : Symbol(C, Decl(localTypes1.ts, 72, 9)) + } + var z2 = () => { +>z2 : Symbol(z2, Decl(localTypes1.ts, 78, 7)) + + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 78, 20)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 79, 16)) +>B : Symbol(E.B, Decl(localTypes1.ts, 80, 14)) +>C : Symbol(E.C, Decl(localTypes1.ts, 80, 17)) + } + class C { +>C : Symbol(C, Decl(localTypes1.ts, 81, 9)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 82, 17)) +>E : Symbol(E, Decl(localTypes1.ts, 78, 20)) + } + return new C(); +>C : Symbol(C, Decl(localTypes1.ts, 81, 9)) + } +} + +class A { +>A : Symbol(A, Decl(localTypes1.ts, 87, 1)) + + constructor() { + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 90, 19)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 91, 16)) +>B : Symbol(E.B, Decl(localTypes1.ts, 92, 14)) +>C : Symbol(E.C, Decl(localTypes1.ts, 92, 17)) + } + class C { +>C : Symbol(C, Decl(localTypes1.ts, 93, 9)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 94, 17)) +>E : Symbol(E, Decl(localTypes1.ts, 90, 19)) + } + } + m() { +>m : Symbol(m, Decl(localTypes1.ts, 97, 5)) + + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 98, 9)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 99, 16)) +>B : Symbol(E.B, Decl(localTypes1.ts, 100, 14)) +>C : Symbol(E.C, Decl(localTypes1.ts, 100, 17)) + } + class C { +>C : Symbol(C, Decl(localTypes1.ts, 101, 9)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 102, 17)) +>E : Symbol(E, Decl(localTypes1.ts, 98, 9)) + } + return new C(); +>C : Symbol(C, Decl(localTypes1.ts, 101, 9)) + } + get p() { +>p : Symbol(p, Decl(localTypes1.ts, 106, 5)) + + enum E { +>E : Symbol(E, Decl(localTypes1.ts, 107, 13)) + + A, B, C +>A : Symbol(E.A, Decl(localTypes1.ts, 108, 16)) +>B : Symbol(E.B, Decl(localTypes1.ts, 109, 14)) +>C : Symbol(E.C, Decl(localTypes1.ts, 109, 17)) + } + class C { +>C : Symbol(C, Decl(localTypes1.ts, 110, 9)) + + x: E; +>x : Symbol(x, Decl(localTypes1.ts, 111, 17)) +>E : Symbol(E, Decl(localTypes1.ts, 107, 13)) + } + return new C(); +>C : Symbol(C, Decl(localTypes1.ts, 110, 9)) + } +} + +function f6() { +>f6 : Symbol(f6, Decl(localTypes1.ts, 116, 1)) + + class A { +>A : Symbol(A, Decl(localTypes1.ts, 118, 15)) + + a: string; +>a : Symbol(a, Decl(localTypes1.ts, 119, 13)) + } + function g() { +>g : Symbol(g, Decl(localTypes1.ts, 121, 5)) + + class B extends A { +>B : Symbol(B, Decl(localTypes1.ts, 122, 18)) +>A : Symbol(A, Decl(localTypes1.ts, 118, 15)) + + b: string; +>b : Symbol(b, Decl(localTypes1.ts, 123, 27)) + } + function h() { +>h : Symbol(h, Decl(localTypes1.ts, 125, 9)) + + class C extends B { +>C : Symbol(C, Decl(localTypes1.ts, 126, 22)) +>B : Symbol(B, Decl(localTypes1.ts, 122, 18)) + + c: string; +>c : Symbol(c, Decl(localTypes1.ts, 127, 31)) + } + var x = new C(); +>x : Symbol(x, Decl(localTypes1.ts, 130, 15)) +>C : Symbol(C, Decl(localTypes1.ts, 126, 22)) + + x.a = "a"; +>x.a : Symbol(A.a, Decl(localTypes1.ts, 119, 13)) +>x : Symbol(x, Decl(localTypes1.ts, 130, 15)) +>a : Symbol(A.a, Decl(localTypes1.ts, 119, 13)) + + x.b = "b"; +>x.b : Symbol(B.b, Decl(localTypes1.ts, 123, 27)) +>x : Symbol(x, Decl(localTypes1.ts, 130, 15)) +>b : Symbol(B.b, Decl(localTypes1.ts, 123, 27)) + + x.c = "c"; +>x.c : Symbol(C.c, Decl(localTypes1.ts, 127, 31)) +>x : Symbol(x, Decl(localTypes1.ts, 130, 15)) +>c : Symbol(C.c, Decl(localTypes1.ts, 127, 31)) + + return x; +>x : Symbol(x, Decl(localTypes1.ts, 130, 15)) + } + return h(); +>h : Symbol(h, Decl(localTypes1.ts, 125, 9)) + } + return g(); +>g : Symbol(g, Decl(localTypes1.ts, 121, 5)) +} + diff --git a/tests/baselines/reference/localTypes1.types b/tests/baselines/reference/localTypes1.types new file mode 100644 index 0000000000..1770a36edb --- /dev/null +++ b/tests/baselines/reference/localTypes1.types @@ -0,0 +1,395 @@ +=== tests/cases/conformance/types/localTypes/localTypes1.ts === + +function f1() { +>f1 : () => I[] + + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + class C { +>C : C + + x: E; +>x : E +>E : E + } + interface I { +>I : I + + x: E; +>x : E +>E : E + } + type A = I[]; +>A : I[] +>I : I + + let a: A = [new C()]; +>a : I[] +>A : I[] +>[new C()] : C[] +>new C() : C +>C : typeof C + + a[0].x = E.B; +>a[0].x = E.B : E +>a[0].x : E +>a[0] : I +>a : I[] +>0 : number +>x : E +>E.B : E +>E : typeof E +>B : E + + return a; +>a : I[] +} + +function f2() { +>f2 : () => I[] + + function g() { +>g : () => I[] + + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + class C { +>C : C + + x: E; +>x : E +>E : E + } + interface I { +>I : I + + x: E; +>x : E +>E : E + } + type A = I[]; +>A : I[] +>I : I + + let a: A = [new C()]; +>a : I[] +>A : I[] +>[new C()] : C[] +>new C() : C +>C : typeof C + + a[0].x = E.B; +>a[0].x = E.B : E +>a[0].x : E +>a[0] : I +>a : I[] +>0 : number +>x : E +>E.B : E +>E : typeof E +>B : E + + return a; +>a : I[] + } + return g(); +>g() : I[] +>g : () => I[] +} + +function f3(b: boolean) { +>f3 : (b: boolean) => I[] +>b : boolean + + if (true) { +>true : boolean + + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + if (b) { +>b : boolean + + class C { +>C : C + + x: E; +>x : E +>E : E + } + interface I { +>I : I + + x: E; +>x : E +>E : E + } + type A = I[]; +>A : I[] +>I : I + + let a: A = [new C()]; +>a : I[] +>A : I[] +>[new C()] : C[] +>new C() : C +>C : typeof C + + a[0].x = E.B; +>a[0].x = E.B : E +>a[0].x : E +>a[0] : I +>a : I[] +>0 : number +>x : E +>E.B : E +>E : typeof E +>B : E + + return a; +>a : I[] + } + else { + class A { +>A : A + + x: E; +>x : E +>E : E + } + interface J { +>J : J + + x: E; +>x : E +>E : E + } + type C = J[]; +>C : J[] +>J : J + + let c: C = [new A()]; +>c : J[] +>C : J[] +>[new A()] : A[] +>new A() : A +>A : typeof A + + c[0].x = E.B; +>c[0].x = E.B : E +>c[0].x : E +>c[0] : J +>c : J[] +>0 : number +>x : E +>E.B : E +>E : typeof E +>B : E + + return c; +>c : J[] + } + } +} + +function f5() { +>f5 : () => void + + var z1 = function () { +>z1 : () => C +>function () { enum E { A, B, C } class C { x: E; } return new C(); } : () => C + + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + class C { +>C : C + + x: E; +>x : E +>E : E + } + return new C(); +>new C() : C +>C : typeof C + } + var z2 = () => { +>z2 : () => C +>() => { enum E { A, B, C } class C { x: E; } return new C(); } : () => C + + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + class C { +>C : C + + x: E; +>x : E +>E : E + } + return new C(); +>new C() : C +>C : typeof C + } +} + +class A { +>A : A + + constructor() { + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + class C { +>C : C + + x: E; +>x : E +>E : E + } + } + m() { +>m : () => C + + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + class C { +>C : C + + x: E; +>x : E +>E : E + } + return new C(); +>new C() : C +>C : typeof C + } + get p() { +>p : C + + enum E { +>E : E + + A, B, C +>A : E +>B : E +>C : E + } + class C { +>C : C + + x: E; +>x : E +>E : E + } + return new C(); +>new C() : C +>C : typeof C + } +} + +function f6() { +>f6 : () => C + + class A { +>A : A + + a: string; +>a : string + } + function g() { +>g : () => C + + class B extends A { +>B : B +>A : A + + b: string; +>b : string + } + function h() { +>h : () => C + + class C extends B { +>C : C +>B : B + + c: string; +>c : string + } + var x = new C(); +>x : C +>new C() : C +>C : typeof C + + x.a = "a"; +>x.a = "a" : string +>x.a : string +>x : C +>a : string +>"a" : string + + x.b = "b"; +>x.b = "b" : string +>x.b : string +>x : C +>b : string +>"b" : string + + x.c = "c"; +>x.c = "c" : string +>x.c : string +>x : C +>c : string +>"c" : string + + return x; +>x : C + } + return h(); +>h() : C +>h : () => C + } + return g(); +>g() : C +>g : () => C +} + diff --git a/tests/baselines/reference/localTypes2.js b/tests/baselines/reference/localTypes2.js new file mode 100644 index 0000000000..a95844f079 --- /dev/null +++ b/tests/baselines/reference/localTypes2.js @@ -0,0 +1,92 @@ +//// [localTypes2.ts] +function f1() { + function f() { + class C { + constructor(public x: number, public y: number) { } + } + return C; + } + let C = f(); + let v = new C(10, 20); + let x = v.x; + let y = v.y; +} + +function f2() { + function f(x: number) { + class C { + public x = x; + constructor(public y: number) { } + } + return C; + } + let C = f(10); + let v = new C(20); + let x = v.x; + let y = v.y; +} + +function f3() { + function f(x: number, y: number) { + class C { + public x = x; + public y = y; + } + return C; + } + let C = f(10, 20); + let v = new C(); + let x = v.x; + let y = v.y; +} + + +//// [localTypes2.js] +function f1() { + function f() { + var C = (function () { + function C(x, y) { + this.x = x; + this.y = y; + } + return C; + })(); + return C; + } + var C = f(); + var v = new C(10, 20); + var x = v.x; + var y = v.y; +} +function f2() { + function f(x) { + var C = (function () { + function C(y) { + this.y = y; + this.x = x; + } + return C; + })(); + return C; + } + var C = f(10); + var v = new C(20); + var x = v.x; + var y = v.y; +} +function f3() { + function f(x, y) { + var C = (function () { + function C() { + this.x = x; + this.y = y; + } + return C; + })(); + return C; + } + var C = f(10, 20); + var v = new C(); + var x = v.x; + var y = v.y; +} diff --git a/tests/baselines/reference/localTypes2.symbols b/tests/baselines/reference/localTypes2.symbols new file mode 100644 index 0000000000..3054c6f552 --- /dev/null +++ b/tests/baselines/reference/localTypes2.symbols @@ -0,0 +1,122 @@ +=== tests/cases/conformance/types/localTypes/localTypes2.ts === +function f1() { +>f1 : Symbol(f1, Decl(localTypes2.ts, 0, 0)) + + function f() { +>f : Symbol(f, Decl(localTypes2.ts, 0, 15)) + + class C { +>C : Symbol(C, Decl(localTypes2.ts, 1, 18)) + + constructor(public x: number, public y: number) { } +>x : Symbol(x, Decl(localTypes2.ts, 3, 24)) +>y : Symbol(y, Decl(localTypes2.ts, 3, 41)) + } + return C; +>C : Symbol(C, Decl(localTypes2.ts, 1, 18)) + } + let C = f(); +>C : Symbol(C, Decl(localTypes2.ts, 7, 7)) +>f : Symbol(f, Decl(localTypes2.ts, 0, 15)) + + let v = new C(10, 20); +>v : Symbol(v, Decl(localTypes2.ts, 8, 7)) +>C : Symbol(C, Decl(localTypes2.ts, 7, 7)) + + let x = v.x; +>x : Symbol(x, Decl(localTypes2.ts, 9, 7)) +>v.x : Symbol(C.x, Decl(localTypes2.ts, 3, 24)) +>v : Symbol(v, Decl(localTypes2.ts, 8, 7)) +>x : Symbol(C.x, Decl(localTypes2.ts, 3, 24)) + + let y = v.y; +>y : Symbol(y, Decl(localTypes2.ts, 10, 7)) +>v.y : Symbol(C.y, Decl(localTypes2.ts, 3, 41)) +>v : Symbol(v, Decl(localTypes2.ts, 8, 7)) +>y : Symbol(C.y, Decl(localTypes2.ts, 3, 41)) +} + +function f2() { +>f2 : Symbol(f2, Decl(localTypes2.ts, 11, 1)) + + function f(x: number) { +>f : Symbol(f, Decl(localTypes2.ts, 13, 15)) +>x : Symbol(x, Decl(localTypes2.ts, 14, 15)) + + class C { +>C : Symbol(C, Decl(localTypes2.ts, 14, 27)) + + public x = x; +>x : Symbol(x, Decl(localTypes2.ts, 15, 17)) +>x : Symbol(x, Decl(localTypes2.ts, 14, 15)) + + constructor(public y: number) { } +>y : Symbol(y, Decl(localTypes2.ts, 17, 24)) + } + return C; +>C : Symbol(C, Decl(localTypes2.ts, 14, 27)) + } + let C = f(10); +>C : Symbol(C, Decl(localTypes2.ts, 21, 7)) +>f : Symbol(f, Decl(localTypes2.ts, 13, 15)) + + let v = new C(20); +>v : Symbol(v, Decl(localTypes2.ts, 22, 7)) +>C : Symbol(C, Decl(localTypes2.ts, 21, 7)) + + let x = v.x; +>x : Symbol(x, Decl(localTypes2.ts, 23, 7)) +>v.x : Symbol(C.x, Decl(localTypes2.ts, 15, 17)) +>v : Symbol(v, Decl(localTypes2.ts, 22, 7)) +>x : Symbol(C.x, Decl(localTypes2.ts, 15, 17)) + + let y = v.y; +>y : Symbol(y, Decl(localTypes2.ts, 24, 7)) +>v.y : Symbol(C.y, Decl(localTypes2.ts, 17, 24)) +>v : Symbol(v, Decl(localTypes2.ts, 22, 7)) +>y : Symbol(C.y, Decl(localTypes2.ts, 17, 24)) +} + +function f3() { +>f3 : Symbol(f3, Decl(localTypes2.ts, 25, 1)) + + function f(x: number, y: number) { +>f : Symbol(f, Decl(localTypes2.ts, 27, 15)) +>x : Symbol(x, Decl(localTypes2.ts, 28, 15)) +>y : Symbol(y, Decl(localTypes2.ts, 28, 25)) + + class C { +>C : Symbol(C, Decl(localTypes2.ts, 28, 38)) + + public x = x; +>x : Symbol(x, Decl(localTypes2.ts, 29, 17)) +>x : Symbol(x, Decl(localTypes2.ts, 28, 15)) + + public y = y; +>y : Symbol(y, Decl(localTypes2.ts, 30, 25)) +>y : Symbol(y, Decl(localTypes2.ts, 28, 25)) + } + return C; +>C : Symbol(C, Decl(localTypes2.ts, 28, 38)) + } + let C = f(10, 20); +>C : Symbol(C, Decl(localTypes2.ts, 35, 7)) +>f : Symbol(f, Decl(localTypes2.ts, 27, 15)) + + let v = new C(); +>v : Symbol(v, Decl(localTypes2.ts, 36, 7)) +>C : Symbol(C, Decl(localTypes2.ts, 35, 7)) + + let x = v.x; +>x : Symbol(x, Decl(localTypes2.ts, 37, 7)) +>v.x : Symbol(C.x, Decl(localTypes2.ts, 29, 17)) +>v : Symbol(v, Decl(localTypes2.ts, 36, 7)) +>x : Symbol(C.x, Decl(localTypes2.ts, 29, 17)) + + let y = v.y; +>y : Symbol(y, Decl(localTypes2.ts, 38, 7)) +>v.y : Symbol(C.y, Decl(localTypes2.ts, 30, 25)) +>v : Symbol(v, Decl(localTypes2.ts, 36, 7)) +>y : Symbol(C.y, Decl(localTypes2.ts, 30, 25)) +} + diff --git a/tests/baselines/reference/localTypes2.types b/tests/baselines/reference/localTypes2.types new file mode 100644 index 0000000000..a6b85b7bb1 --- /dev/null +++ b/tests/baselines/reference/localTypes2.types @@ -0,0 +1,134 @@ +=== tests/cases/conformance/types/localTypes/localTypes2.ts === +function f1() { +>f1 : () => void + + function f() { +>f : () => typeof C + + class C { +>C : C + + constructor(public x: number, public y: number) { } +>x : number +>y : number + } + return C; +>C : typeof C + } + let C = f(); +>C : typeof C +>f() : typeof C +>f : () => typeof C + + let v = new C(10, 20); +>v : C +>new C(10, 20) : C +>C : typeof C +>10 : number +>20 : number + + let x = v.x; +>x : number +>v.x : number +>v : C +>x : number + + let y = v.y; +>y : number +>v.y : number +>v : C +>y : number +} + +function f2() { +>f2 : () => void + + function f(x: number) { +>f : (x: number) => typeof C +>x : number + + class C { +>C : C + + public x = x; +>x : number +>x : number + + constructor(public y: number) { } +>y : number + } + return C; +>C : typeof C + } + let C = f(10); +>C : typeof C +>f(10) : typeof C +>f : (x: number) => typeof C +>10 : number + + let v = new C(20); +>v : C +>new C(20) : C +>C : typeof C +>20 : number + + let x = v.x; +>x : number +>v.x : number +>v : C +>x : number + + let y = v.y; +>y : number +>v.y : number +>v : C +>y : number +} + +function f3() { +>f3 : () => void + + function f(x: number, y: number) { +>f : (x: number, y: number) => typeof C +>x : number +>y : number + + class C { +>C : C + + public x = x; +>x : number +>x : number + + public y = y; +>y : number +>y : number + } + return C; +>C : typeof C + } + let C = f(10, 20); +>C : typeof C +>f(10, 20) : typeof C +>f : (x: number, y: number) => typeof C +>10 : number +>20 : number + + let v = new C(); +>v : C +>new C() : C +>C : typeof C + + let x = v.x; +>x : number +>v.x : number +>v : C +>x : number + + let y = v.y; +>y : number +>v.y : number +>v : C +>y : number +} + diff --git a/tests/baselines/reference/localTypes3.js b/tests/baselines/reference/localTypes3.js new file mode 100644 index 0000000000..2d40bc922b --- /dev/null +++ b/tests/baselines/reference/localTypes3.js @@ -0,0 +1,92 @@ +//// [localTypes3.ts] +function f1() { + function f() { + class C { + constructor(public x: X, public y: Y) { } + } + return C; + } + let C = f(); + let v = new C(10, "hello"); + let x = v.x; + let y = v.y; +} + +function f2() { + function f(x: X) { + class C { + public x = x; + constructor(public y: Y) { } + } + return C; + } + let C = f(10); + let v = new C("hello"); + let x = v.x; + let y = v.y; +} + +function f3() { + function f(x: X, y: Y) { + class C { + public x = x; + public y = y; + } + return C; + } + let C = f(10, "hello"); + let v = new C(); + let x = v.x; + let y = v.y; +} + + +//// [localTypes3.js] +function f1() { + function f() { + var C = (function () { + function C(x, y) { + this.x = x; + this.y = y; + } + return C; + })(); + return C; + } + var C = f(); + var v = new C(10, "hello"); + var x = v.x; + var y = v.y; +} +function f2() { + function f(x) { + var C = (function () { + function C(y) { + this.y = y; + this.x = x; + } + return C; + })(); + return C; + } + var C = f(10); + var v = new C("hello"); + var x = v.x; + var y = v.y; +} +function f3() { + function f(x, y) { + var C = (function () { + function C() { + this.x = x; + this.y = y; + } + return C; + })(); + return C; + } + var C = f(10, "hello"); + var v = new C(); + var x = v.x; + var y = v.y; +} diff --git a/tests/baselines/reference/localTypes3.symbols b/tests/baselines/reference/localTypes3.symbols new file mode 100644 index 0000000000..fe7082e457 --- /dev/null +++ b/tests/baselines/reference/localTypes3.symbols @@ -0,0 +1,134 @@ +=== tests/cases/conformance/types/localTypes/localTypes3.ts === +function f1() { +>f1 : Symbol(f1, Decl(localTypes3.ts, 0, 0)) + + function f() { +>f : Symbol(f, Decl(localTypes3.ts, 0, 15)) + + class C { +>C : Symbol(C, Decl(localTypes3.ts, 1, 18)) +>X : Symbol(X, Decl(localTypes3.ts, 2, 16)) +>Y : Symbol(Y, Decl(localTypes3.ts, 2, 18)) + + constructor(public x: X, public y: Y) { } +>x : Symbol(x, Decl(localTypes3.ts, 3, 24)) +>X : Symbol(X, Decl(localTypes3.ts, 2, 16)) +>y : Symbol(y, Decl(localTypes3.ts, 3, 36)) +>Y : Symbol(Y, Decl(localTypes3.ts, 2, 18)) + } + return C; +>C : Symbol(C, Decl(localTypes3.ts, 1, 18)) + } + let C = f(); +>C : Symbol(C, Decl(localTypes3.ts, 7, 7)) +>f : Symbol(f, Decl(localTypes3.ts, 0, 15)) + + let v = new C(10, "hello"); +>v : Symbol(v, Decl(localTypes3.ts, 8, 7)) +>C : Symbol(C, Decl(localTypes3.ts, 7, 7)) + + let x = v.x; +>x : Symbol(x, Decl(localTypes3.ts, 9, 7)) +>v.x : Symbol(C.x, Decl(localTypes3.ts, 3, 24)) +>v : Symbol(v, Decl(localTypes3.ts, 8, 7)) +>x : Symbol(C.x, Decl(localTypes3.ts, 3, 24)) + + let y = v.y; +>y : Symbol(y, Decl(localTypes3.ts, 10, 7)) +>v.y : Symbol(C.y, Decl(localTypes3.ts, 3, 36)) +>v : Symbol(v, Decl(localTypes3.ts, 8, 7)) +>y : Symbol(C.y, Decl(localTypes3.ts, 3, 36)) +} + +function f2() { +>f2 : Symbol(f2, Decl(localTypes3.ts, 11, 1)) + + function f(x: X) { +>f : Symbol(f, Decl(localTypes3.ts, 13, 15)) +>X : Symbol(X, Decl(localTypes3.ts, 14, 15)) +>x : Symbol(x, Decl(localTypes3.ts, 14, 18)) +>X : Symbol(X, Decl(localTypes3.ts, 14, 15)) + + class C { +>C : Symbol(C, Decl(localTypes3.ts, 14, 25)) +>Y : Symbol(Y, Decl(localTypes3.ts, 15, 16)) + + public x = x; +>x : Symbol(x, Decl(localTypes3.ts, 15, 20)) +>x : Symbol(x, Decl(localTypes3.ts, 14, 18)) + + constructor(public y: Y) { } +>y : Symbol(y, Decl(localTypes3.ts, 17, 24)) +>Y : Symbol(Y, Decl(localTypes3.ts, 15, 16)) + } + return C; +>C : Symbol(C, Decl(localTypes3.ts, 14, 25)) + } + let C = f(10); +>C : Symbol(C, Decl(localTypes3.ts, 21, 7)) +>f : Symbol(f, Decl(localTypes3.ts, 13, 15)) + + let v = new C("hello"); +>v : Symbol(v, Decl(localTypes3.ts, 22, 7)) +>C : Symbol(C, Decl(localTypes3.ts, 21, 7)) + + let x = v.x; +>x : Symbol(x, Decl(localTypes3.ts, 23, 7)) +>v.x : Symbol(C.x, Decl(localTypes3.ts, 15, 20)) +>v : Symbol(v, Decl(localTypes3.ts, 22, 7)) +>x : Symbol(C.x, Decl(localTypes3.ts, 15, 20)) + + let y = v.y; +>y : Symbol(y, Decl(localTypes3.ts, 24, 7)) +>v.y : Symbol(C.y, Decl(localTypes3.ts, 17, 24)) +>v : Symbol(v, Decl(localTypes3.ts, 22, 7)) +>y : Symbol(C.y, Decl(localTypes3.ts, 17, 24)) +} + +function f3() { +>f3 : Symbol(f3, Decl(localTypes3.ts, 25, 1)) + + function f(x: X, y: Y) { +>f : Symbol(f, Decl(localTypes3.ts, 27, 15)) +>X : Symbol(X, Decl(localTypes3.ts, 28, 15)) +>Y : Symbol(Y, Decl(localTypes3.ts, 28, 17)) +>x : Symbol(x, Decl(localTypes3.ts, 28, 21)) +>X : Symbol(X, Decl(localTypes3.ts, 28, 15)) +>y : Symbol(y, Decl(localTypes3.ts, 28, 26)) +>Y : Symbol(Y, Decl(localTypes3.ts, 28, 17)) + + class C { +>C : Symbol(C, Decl(localTypes3.ts, 28, 34)) + + public x = x; +>x : Symbol(x, Decl(localTypes3.ts, 29, 17)) +>x : Symbol(x, Decl(localTypes3.ts, 28, 21)) + + public y = y; +>y : Symbol(y, Decl(localTypes3.ts, 30, 25)) +>y : Symbol(y, Decl(localTypes3.ts, 28, 26)) + } + return C; +>C : Symbol(C, Decl(localTypes3.ts, 28, 34)) + } + let C = f(10, "hello"); +>C : Symbol(C, Decl(localTypes3.ts, 35, 7)) +>f : Symbol(f, Decl(localTypes3.ts, 27, 15)) + + let v = new C(); +>v : Symbol(v, Decl(localTypes3.ts, 36, 7)) +>C : Symbol(C, Decl(localTypes3.ts, 35, 7)) + + let x = v.x; +>x : Symbol(x, Decl(localTypes3.ts, 37, 7)) +>v.x : Symbol(C.x, Decl(localTypes3.ts, 29, 17)) +>v : Symbol(v, Decl(localTypes3.ts, 36, 7)) +>x : Symbol(C.x, Decl(localTypes3.ts, 29, 17)) + + let y = v.y; +>y : Symbol(y, Decl(localTypes3.ts, 38, 7)) +>v.y : Symbol(C.y, Decl(localTypes3.ts, 30, 25)) +>v : Symbol(v, Decl(localTypes3.ts, 36, 7)) +>y : Symbol(C.y, Decl(localTypes3.ts, 30, 25)) +} + diff --git a/tests/baselines/reference/localTypes3.types b/tests/baselines/reference/localTypes3.types new file mode 100644 index 0000000000..551096468c --- /dev/null +++ b/tests/baselines/reference/localTypes3.types @@ -0,0 +1,146 @@ +=== tests/cases/conformance/types/localTypes/localTypes3.ts === +function f1() { +>f1 : () => void + + function f() { +>f : () => typeof C + + class C { +>C : C +>X : X +>Y : Y + + constructor(public x: X, public y: Y) { } +>x : X +>X : X +>y : Y +>Y : Y + } + return C; +>C : typeof C + } + let C = f(); +>C : typeof C +>f() : typeof C +>f : () => typeof C + + let v = new C(10, "hello"); +>v : C +>new C(10, "hello") : C +>C : typeof C +>10 : number +>"hello" : string + + let x = v.x; +>x : number +>v.x : number +>v : C +>x : number + + let y = v.y; +>y : string +>v.y : string +>v : C +>y : string +} + +function f2() { +>f2 : () => void + + function f(x: X) { +>f : (x: X) => typeof C +>X : X +>x : X +>X : X + + class C { +>C : C +>Y : Y + + public x = x; +>x : X +>x : X + + constructor(public y: Y) { } +>y : Y +>Y : Y + } + return C; +>C : typeof C + } + let C = f(10); +>C : typeof C +>f(10) : typeof C +>f : (x: X) => typeof C +>10 : number + + let v = new C("hello"); +>v : f.C +>new C("hello") : f.C +>C : typeof C +>"hello" : string + + let x = v.x; +>x : number +>v.x : number +>v : f.C +>x : number + + let y = v.y; +>y : string +>v.y : string +>v : f.C +>y : string +} + +function f3() { +>f3 : () => void + + function f(x: X, y: Y) { +>f : (x: X, y: Y) => typeof C +>X : X +>Y : Y +>x : X +>X : X +>y : Y +>Y : Y + + class C { +>C : C + + public x = x; +>x : X +>x : X + + public y = y; +>y : Y +>y : Y + } + return C; +>C : typeof C + } + let C = f(10, "hello"); +>C : typeof C +>f(10, "hello") : typeof C +>f : (x: X, y: Y) => typeof C +>10 : number +>"hello" : string + + let v = new C(); +>v : f.C +>new C() : f.C +>C : typeof C + + let x = v.x; +>x : number +>v.x : number +>v : f.C +>x : number + + let y = v.y; +>y : string +>v.y : string +>v : f.C +>y : string +} + diff --git a/tests/baselines/reference/localTypes4.errors.txt b/tests/baselines/reference/localTypes4.errors.txt new file mode 100644 index 0000000000..cad9d30c93 --- /dev/null +++ b/tests/baselines/reference/localTypes4.errors.txt @@ -0,0 +1,53 @@ +tests/cases/conformance/types/localTypes/localTypes4.ts(10,19): error TS2304: Cannot find name 'T'. +tests/cases/conformance/types/localTypes/localTypes4.ts(10,23): error TS2304: Cannot find name 'T'. +tests/cases/conformance/types/localTypes/localTypes4.ts(18,16): error TS2300: Duplicate identifier 'T'. +tests/cases/conformance/types/localTypes/localTypes4.ts(19,19): error TS2300: Duplicate identifier 'T'. + + +==== tests/cases/conformance/types/localTypes/localTypes4.ts (4 errors) ==== + function f1() { + // Type parameters are in scope in parameters and return types + function f(x: T): T { + return undefined; + } + } + + function f2() { + // Local types are not in scope in parameters and return types + function f(x: T): T { + ~ +!!! error TS2304: Cannot find name 'T'. + ~ +!!! error TS2304: Cannot find name 'T'. + interface T { } + return undefined; + } + } + + function f3() { + // Type parameters and top-level local types are in same declaration space + function f() { + ~ +!!! error TS2300: Duplicate identifier 'T'. + interface T { } + ~ +!!! error TS2300: Duplicate identifier 'T'. + return undefined; + } + } + + function f4() { + // Local types are block scoped + interface T { x: number } + let v: T; + v.x = 10; + if (true) { + interface T { x: string } + let v: T; + v.x = "hello"; + } + else { + v.x = 20; + } + } + \ No newline at end of file diff --git a/tests/baselines/reference/localTypes4.js b/tests/baselines/reference/localTypes4.js new file mode 100644 index 0000000000..8f51761a65 --- /dev/null +++ b/tests/baselines/reference/localTypes4.js @@ -0,0 +1,70 @@ +//// [localTypes4.ts] +function f1() { + // Type parameters are in scope in parameters and return types + function f(x: T): T { + return undefined; + } +} + +function f2() { + // Local types are not in scope in parameters and return types + function f(x: T): T { + interface T { } + return undefined; + } +} + +function f3() { + // Type parameters and top-level local types are in same declaration space + function f() { + interface T { } + return undefined; + } +} + +function f4() { + // Local types are block scoped + interface T { x: number } + let v: T; + v.x = 10; + if (true) { + interface T { x: string } + let v: T; + v.x = "hello"; + } + else { + v.x = 20; + } +} + + +//// [localTypes4.js] +function f1() { + // Type parameters are in scope in parameters and return types + function f(x) { + return undefined; + } +} +function f2() { + // Local types are not in scope in parameters and return types + function f(x) { + return undefined; + } +} +function f3() { + // Type parameters and top-level local types are in same declaration space + function f() { + return undefined; + } +} +function f4() { + var v; + v.x = 10; + if (true) { + var v_1; + v_1.x = "hello"; + } + else { + v.x = 20; + } +} diff --git a/tests/baselines/reference/localTypes5.js b/tests/baselines/reference/localTypes5.js new file mode 100644 index 0000000000..872629276d --- /dev/null +++ b/tests/baselines/reference/localTypes5.js @@ -0,0 +1,38 @@ +//// [localTypes5.ts] +function foo() { + class X { + m() { + return (function () { + class Y { + } + return new Y(); + })(); + } + } + var x = new X(); + return x.m(); +} +var x = foo(); + + +//// [localTypes5.js] +function foo() { + var X = (function () { + function X() { + } + X.prototype.m = function () { + return (function () { + var Y = (function () { + function Y() { + } + return Y; + })(); + return new Y(); + })(); + }; + return X; + })(); + var x = new X(); + return x.m(); +} +var x = foo(); diff --git a/tests/baselines/reference/localTypes5.symbols b/tests/baselines/reference/localTypes5.symbols new file mode 100644 index 0000000000..4ffe53b3e5 --- /dev/null +++ b/tests/baselines/reference/localTypes5.symbols @@ -0,0 +1,40 @@ +=== tests/cases/conformance/types/localTypes/localTypes5.ts === +function foo() { +>foo : Symbol(foo, Decl(localTypes5.ts, 0, 0)) +>A : Symbol(A, Decl(localTypes5.ts, 0, 13)) + + class X { +>X : Symbol(X, Decl(localTypes5.ts, 0, 19)) + + m() { +>m : Symbol(m, Decl(localTypes5.ts, 1, 13)) +>B : Symbol(B, Decl(localTypes5.ts, 2, 10)) +>C : Symbol(C, Decl(localTypes5.ts, 2, 12)) + + return (function () { +>D : Symbol(D, Decl(localTypes5.ts, 3, 30)) + + class Y { +>Y : Symbol(Y, Decl(localTypes5.ts, 3, 36)) +>E : Symbol(E, Decl(localTypes5.ts, 4, 24)) + } + return new Y(); +>Y : Symbol(Y, Decl(localTypes5.ts, 3, 36)) + + })(); +>Date : Symbol(Date, Decl(lib.d.ts, 633, 23), Decl(lib.d.ts, 815, 11)) + } + } + var x = new X(); +>x : Symbol(x, Decl(localTypes5.ts, 10, 7)) +>X : Symbol(X, Decl(localTypes5.ts, 0, 19)) + + return x.m(); +>x.m : Symbol(X.m, Decl(localTypes5.ts, 1, 13)) +>x : Symbol(x, Decl(localTypes5.ts, 10, 7)) +>m : Symbol(X.m, Decl(localTypes5.ts, 1, 13)) +} +var x = foo(); +>x : Symbol(x, Decl(localTypes5.ts, 13, 3)) +>foo : Symbol(foo, Decl(localTypes5.ts, 0, 0)) + diff --git a/tests/baselines/reference/localTypes5.types b/tests/baselines/reference/localTypes5.types new file mode 100644 index 0000000000..b12e362f75 --- /dev/null +++ b/tests/baselines/reference/localTypes5.types @@ -0,0 +1,47 @@ +=== tests/cases/conformance/types/localTypes/localTypes5.ts === +function foo() { +>foo : () => X.m..Y +>A : A + + class X { +>X : X + + m() { +>m : () => .Y +>B : B +>C : C + + return (function () { +>(function () { class Y { } return new Y(); })() : .Y +>(function () { class Y { } return new Y(); }) : () => Y +>function () { class Y { } return new Y(); } : () => Y +>D : D + + class Y { +>Y : Y +>E : E + } + return new Y(); +>new Y() : Y +>Y : typeof Y + + })(); +>Date : Date + } + } + var x = new X(); +>x : X +>new X() : X +>X : typeof X + + return x.m(); +>x.m() : X.m..Y +>x.m : () => .Y +>x : X +>m : () => .Y +} +var x = foo(); +>x : foo.X.m..Y +>foo() : foo.X.m..Y +>foo : () => X.m..Y + diff --git a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt index 14b7769d22..abf11dc9db 100644 --- a/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt +++ b/tests/baselines/reference/multiLinePropertyAccessAndArrowFunctionIndent1.errors.txt @@ -1,12 +1,15 @@ tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,1): error TS1108: A 'return' statement can only be used within a function body. +tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(1,18): error TS2304: Cannot find name 'role'. tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(2,18): error TS2304: Cannot find name 'Role'. tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts(4,26): error TS2503: Cannot find namespace 'ng'. -==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (3 errors) ==== +==== tests/cases/compiler/multiLinePropertyAccessAndArrowFunctionIndent1.ts (4 errors) ==== return this.edit(role) ~~~~~~ !!! error TS1108: A 'return' statement can only be used within a function body. + ~~~~ +!!! error TS2304: Cannot find name 'role'. .then((role: Role) => ~~~~ !!! error TS2304: Cannot find name 'Role'. diff --git a/tests/baselines/reference/newWithSpread.errors.txt b/tests/baselines/reference/newWithSpread.errors.txt new file mode 100644 index 0000000000..293c7054e4 --- /dev/null +++ b/tests/baselines/reference/newWithSpread.errors.txt @@ -0,0 +1,178 @@ +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(37,13): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(38,13): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(41,8): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(42,13): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(46,13): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(47,13): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(51,15): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(52,15): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(56,17): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(57,17): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(61,18): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(62,18): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(66,22): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(67,22): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(71,13): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(72,13): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(76,20): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(77,20): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(81,22): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(82,22): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(86,23): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(87,23): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(91,27): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(92,27): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(96,23): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/expressions/functionCalls/newWithSpread.ts(97,23): error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + +==== tests/cases/conformance/expressions/functionCalls/newWithSpread.ts (26 errors) ==== + + function f(x: number, y: number, ...z: string[]) { + } + + function f2(...x: string[]) { + } + + interface A { + f: { + new (x: number, y: number, ...z: string[]); + } + } + + class B { + constructor(x: number, y: number, ...z: string[]) {} + } + + interface C { + "a-b": typeof B; + } + + interface D { + 1: typeof B; + } + + var a: string[]; + var b: A; + var c: C; + var d: A[]; + var e: { [key: string]: A }; + var g: C[]; + var h: { [key: string]: C }; + var i: C[][]; + + // Basic expression + new f(1, 2, "string"); + new f(1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new f(1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Multiple spreads arguments + new f2(...a, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new f(1 ,2, ...a, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Call expression + new f(1, 2, "string")(); + new f(1, 2, ...a)(); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new f(1, 2, ...a, "string")(); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Property access expression + new b.f(1, 2, "string"); + new b.f(1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new b.f(1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Parenthesised expression + new (b.f)(1, 2, "string"); + new (b.f)(1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new (b.f)(1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Element access expression + new d[1].f(1, 2, "string"); + new d[1].f(1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new d[1].f(1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Element access expression with a punctuated key + new e["a-b"].f(1, 2, "string"); + new e["a-b"].f(1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new e["a-b"].f(1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Basic expression + new B(1, 2, "string"); + new B(1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new B(1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Property access expression + new c["a-b"](1, 2, "string"); + new c["a-b"](1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new c["a-b"](1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Parenthesised expression + new (c["a-b"])(1, 2, "string"); + new (c["a-b"])(1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new (c["a-b"])(1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Element access expression + new g[1]["a-b"](1, 2, "string"); + new g[1]["a-b"](1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new g[1]["a-b"](1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Element access expression with a punctuated key + new h["a-b"]["a-b"](1, 2, "string"); + new h["a-b"]["a-b"](1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new h["a-b"]["a-b"](1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + + // Element access expression with a number + new i["a-b"][1](1, 2, "string"); + new i["a-b"][1](1, 2, ...a); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. + new i["a-b"][1](1, 2, ...a, "string"); + ~~~~ +!!! error TS2472: Spread operator in 'new' expressions is only available when targeting ECMAScript 5 and higher. \ No newline at end of file diff --git a/tests/baselines/reference/newWithSpread.js b/tests/baselines/reference/newWithSpread.js new file mode 100644 index 0000000000..3161eb9f67 --- /dev/null +++ b/tests/baselines/reference/newWithSpread.js @@ -0,0 +1,180 @@ +//// [newWithSpread.ts] + +function f(x: number, y: number, ...z: string[]) { +} + +function f2(...x: string[]) { +} + +interface A { + f: { + new (x: number, y: number, ...z: string[]); + } +} + +class B { + constructor(x: number, y: number, ...z: string[]) {} +} + +interface C { + "a-b": typeof B; +} + +interface D { + 1: typeof B; +} + +var a: string[]; +var b: A; +var c: C; +var d: A[]; +var e: { [key: string]: A }; +var g: C[]; +var h: { [key: string]: C }; +var i: C[][]; + +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); + +// Multiple spreads arguments +new f2(...a, ...a); +new f(1 ,2, ...a, ...a); + +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); + +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); + +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); + +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); + +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); + +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); + +//// [newWithSpread.js] +function f(x, y) { + var z = []; + for (var _i = 2; _i < arguments.length; _i++) { + z[_i - 2] = arguments[_i]; + } +} +function f2() { + var x = []; + for (var _i = 0; _i < arguments.length; _i++) { + x[_i - 0] = arguments[_i]; + } +} +var B = (function () { + function B(x, y) { + var z = []; + for (var _i = 2; _i < arguments.length; _i++) { + z[_i - 2] = arguments[_i]; + } + } + return B; +})(); +var a; +var b; +var c; +var d; +var e; +var g; +var h; +var i; +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); +// Multiple spreads arguments +new f2(...a, ...a); +new f(1, 2, ...a, ...a); +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); diff --git a/tests/baselines/reference/newWithSpreadES5.js b/tests/baselines/reference/newWithSpreadES5.js new file mode 100644 index 0000000000..f747026627 --- /dev/null +++ b/tests/baselines/reference/newWithSpreadES5.js @@ -0,0 +1,180 @@ +//// [newWithSpreadES5.ts] + +function f(x: number, y: number, ...z: string[]) { +} + +function f2(...x: string[]) {} + +interface A { + f: { + new (x: number, y: number, ...z: string[]); + } +} + +class B { + constructor(x: number, y: number, ...z: string[]) {} +} + +interface C { + "a-b": typeof B; +} + +interface D { + 1: typeof B; +} + +var a: string[]; +var b: A; +var c: C; +var d: A[]; +var e: { [key: string]: A }; +var g: C[]; +var h: { [key: string]: C }; +var i: C[][]; + +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); + +// Multiple spreads arguments +new f2(...a, ...a); +new f(1 ,2, ...a, ...a); + +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); + +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); + +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); + +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); + +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); + +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); + +//// [newWithSpreadES5.js] +function f(x, y) { + var z = []; + for (var _i = 2; _i < arguments.length; _i++) { + z[_i - 2] = arguments[_i]; + } +} +function f2() { + var x = []; + for (var _i = 0; _i < arguments.length; _i++) { + x[_i - 0] = arguments[_i]; + } +} +var B = (function () { + function B(x, y) { + var z = []; + for (var _i = 2; _i < arguments.length; _i++) { + z[_i - 2] = arguments[_i]; + } + } + return B; +})(); +var a; +var b; +var c; +var d; +var e; +var g; +var h; +var i; +// Basic expression +new f(1, 2, "string"); +new (f.bind.apply(f, [void 0].concat([1, 2], a)))(); +new (f.bind.apply(f, [void 0].concat([1, 2], a, ["string"])))(); +// Multiple spreads arguments +new (f2.bind.apply(f2, [void 0].concat(a, a)))(); +new (f.bind.apply(f, [void 0].concat([1, 2], a, a)))(); +// Call expression +new f(1, 2, "string")(); +new (f.bind.apply(f, [void 0].concat([1, 2], a)))()(); +new (f.bind.apply(f, [void 0].concat([1, 2], a, ["string"])))()(); +// Property access expression +new b.f(1, 2, "string"); +new ((_a = b.f).bind.apply(_a, [void 0].concat([1, 2], a)))(); +new ((_b = b.f).bind.apply(_b, [void 0].concat([1, 2], a, ["string"])))(); +// Parenthesised expression +new (b.f)(1, 2, "string"); +new ((_c = (b.f)).bind.apply(_c, [void 0].concat([1, 2], a)))(); +new ((_d = (b.f)).bind.apply(_d, [void 0].concat([1, 2], a, ["string"])))(); +// Element access expression +new d[1].f(1, 2, "string"); +new ((_e = d[1].f).bind.apply(_e, [void 0].concat([1, 2], a)))(); +new ((_f = d[1].f).bind.apply(_f, [void 0].concat([1, 2], a, ["string"])))(); +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new ((_g = e["a-b"].f).bind.apply(_g, [void 0].concat([1, 2], a)))(); +new ((_h = e["a-b"].f).bind.apply(_h, [void 0].concat([1, 2], a, ["string"])))(); +// Basic expression +new B(1, 2, "string"); +new (B.bind.apply(B, [void 0].concat([1, 2], a)))(); +new (B.bind.apply(B, [void 0].concat([1, 2], a, ["string"])))(); +// Property access expression +new c["a-b"](1, 2, "string"); +new ((_j = c["a-b"]).bind.apply(_j, [void 0].concat([1, 2], a)))(); +new ((_k = c["a-b"]).bind.apply(_k, [void 0].concat([1, 2], a, ["string"])))(); +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new ((_l = (c["a-b"])).bind.apply(_l, [void 0].concat([1, 2], a)))(); +new ((_m = (c["a-b"])).bind.apply(_m, [void 0].concat([1, 2], a, ["string"])))(); +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new ((_o = g[1]["a-b"]).bind.apply(_o, [void 0].concat([1, 2], a)))(); +new ((_p = g[1]["a-b"]).bind.apply(_p, [void 0].concat([1, 2], a, ["string"])))(); +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new ((_q = h["a-b"]["a-b"]).bind.apply(_q, [void 0].concat([1, 2], a)))(); +new ((_r = h["a-b"]["a-b"]).bind.apply(_r, [void 0].concat([1, 2], a, ["string"])))(); +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new ((_s = i["a-b"][1]).bind.apply(_s, [void 0].concat([1, 2], a)))(); +new ((_t = i["a-b"][1]).bind.apply(_t, [void 0].concat([1, 2], a, ["string"])))(); +var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t; diff --git a/tests/baselines/reference/newWithSpreadES5.symbols b/tests/baselines/reference/newWithSpreadES5.symbols new file mode 100644 index 0000000000..021674ef33 --- /dev/null +++ b/tests/baselines/reference/newWithSpreadES5.symbols @@ -0,0 +1,273 @@ +=== tests/cases/conformance/expressions/functionCalls/newWithSpreadES5.ts === + +function f(x: number, y: number, ...z: string[]) { +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) +>x : Symbol(x, Decl(newWithSpreadES5.ts, 1, 11)) +>y : Symbol(y, Decl(newWithSpreadES5.ts, 1, 21)) +>z : Symbol(z, Decl(newWithSpreadES5.ts, 1, 32)) +} + +function f2(...x: string[]) {} +>f2 : Symbol(f2, Decl(newWithSpreadES5.ts, 2, 1)) +>x : Symbol(x, Decl(newWithSpreadES5.ts, 4, 12)) + +interface A { +>A : Symbol(A, Decl(newWithSpreadES5.ts, 4, 30)) + + f: { +>f : Symbol(f, Decl(newWithSpreadES5.ts, 6, 13)) + + new (x: number, y: number, ...z: string[]); +>x : Symbol(x, Decl(newWithSpreadES5.ts, 8, 13)) +>y : Symbol(y, Decl(newWithSpreadES5.ts, 8, 23)) +>z : Symbol(z, Decl(newWithSpreadES5.ts, 8, 34)) + } +} + +class B { +>B : Symbol(B, Decl(newWithSpreadES5.ts, 10, 1)) + + constructor(x: number, y: number, ...z: string[]) {} +>x : Symbol(x, Decl(newWithSpreadES5.ts, 13, 16)) +>y : Symbol(y, Decl(newWithSpreadES5.ts, 13, 26)) +>z : Symbol(z, Decl(newWithSpreadES5.ts, 13, 37)) +} + +interface C { +>C : Symbol(C, Decl(newWithSpreadES5.ts, 14, 1)) + + "a-b": typeof B; +>B : Symbol(B, Decl(newWithSpreadES5.ts, 10, 1)) +} + +interface D { +>D : Symbol(D, Decl(newWithSpreadES5.ts, 18, 1)) + + 1: typeof B; +>B : Symbol(B, Decl(newWithSpreadES5.ts, 10, 1)) +} + +var a: string[]; +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +var b: A; +>b : Symbol(b, Decl(newWithSpreadES5.ts, 25, 3)) +>A : Symbol(A, Decl(newWithSpreadES5.ts, 4, 30)) + +var c: C; +>c : Symbol(c, Decl(newWithSpreadES5.ts, 26, 3)) +>C : Symbol(C, Decl(newWithSpreadES5.ts, 14, 1)) + +var d: A[]; +>d : Symbol(d, Decl(newWithSpreadES5.ts, 27, 3)) +>A : Symbol(A, Decl(newWithSpreadES5.ts, 4, 30)) + +var e: { [key: string]: A }; +>e : Symbol(e, Decl(newWithSpreadES5.ts, 28, 3)) +>key : Symbol(key, Decl(newWithSpreadES5.ts, 28, 10)) +>A : Symbol(A, Decl(newWithSpreadES5.ts, 4, 30)) + +var g: C[]; +>g : Symbol(g, Decl(newWithSpreadES5.ts, 29, 3)) +>C : Symbol(C, Decl(newWithSpreadES5.ts, 14, 1)) + +var h: { [key: string]: C }; +>h : Symbol(h, Decl(newWithSpreadES5.ts, 30, 3)) +>key : Symbol(key, Decl(newWithSpreadES5.ts, 30, 10)) +>C : Symbol(C, Decl(newWithSpreadES5.ts, 14, 1)) + +var i: C[][]; +>i : Symbol(i, Decl(newWithSpreadES5.ts, 31, 3)) +>C : Symbol(C, Decl(newWithSpreadES5.ts, 14, 1)) + +// Basic expression +new f(1, 2, "string"); +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) + +new f(1, 2, ...a); +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new f(1, 2, ...a, "string"); +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Multiple spreads arguments +new f2(...a, ...a); +>f2 : Symbol(f2, Decl(newWithSpreadES5.ts, 2, 1)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new f(1 ,2, ...a, ...a); +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Call expression +new f(1, 2, "string")(); +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) + +new f(1, 2, ...a)(); +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new f(1, 2, ...a, "string")(); +>f : Symbol(f, Decl(newWithSpreadES5.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Property access expression +new b.f(1, 2, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>b : Symbol(b, Decl(newWithSpreadES5.ts, 25, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) + +new b.f(1, 2, ...a); +>b.f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>b : Symbol(b, Decl(newWithSpreadES5.ts, 25, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new b.f(1, 2, ...a, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>b : Symbol(b, Decl(newWithSpreadES5.ts, 25, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Parenthesised expression +new (b.f)(1, 2, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>b : Symbol(b, Decl(newWithSpreadES5.ts, 25, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) + +new (b.f)(1, 2, ...a); +>b.f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>b : Symbol(b, Decl(newWithSpreadES5.ts, 25, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new (b.f)(1, 2, ...a, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>b : Symbol(b, Decl(newWithSpreadES5.ts, 25, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Element access expression +new d[1].f(1, 2, "string"); +>d[1].f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>d : Symbol(d, Decl(newWithSpreadES5.ts, 27, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) + +new d[1].f(1, 2, ...a); +>d[1].f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>d : Symbol(d, Decl(newWithSpreadES5.ts, 27, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new d[1].f(1, 2, ...a, "string"); +>d[1].f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>d : Symbol(d, Decl(newWithSpreadES5.ts, 27, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +>e["a-b"].f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>e : Symbol(e, Decl(newWithSpreadES5.ts, 28, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) + +new e["a-b"].f(1, 2, ...a); +>e["a-b"].f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>e : Symbol(e, Decl(newWithSpreadES5.ts, 28, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new e["a-b"].f(1, 2, ...a, "string"); +>e["a-b"].f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>e : Symbol(e, Decl(newWithSpreadES5.ts, 28, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES5.ts, 6, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Basic expression +new B(1, 2, "string"); +>B : Symbol(B, Decl(newWithSpreadES5.ts, 10, 1)) + +new B(1, 2, ...a); +>B : Symbol(B, Decl(newWithSpreadES5.ts, 10, 1)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new B(1, 2, ...a, "string"); +>B : Symbol(B, Decl(newWithSpreadES5.ts, 10, 1)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Property access expression +new c["a-b"](1, 2, "string"); +>c : Symbol(c, Decl(newWithSpreadES5.ts, 26, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) + +new c["a-b"](1, 2, ...a); +>c : Symbol(c, Decl(newWithSpreadES5.ts, 26, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new c["a-b"](1, 2, ...a, "string"); +>c : Symbol(c, Decl(newWithSpreadES5.ts, 26, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +>c : Symbol(c, Decl(newWithSpreadES5.ts, 26, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) + +new (c["a-b"])(1, 2, ...a); +>c : Symbol(c, Decl(newWithSpreadES5.ts, 26, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new (c["a-b"])(1, 2, ...a, "string"); +>c : Symbol(c, Decl(newWithSpreadES5.ts, 26, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +>g : Symbol(g, Decl(newWithSpreadES5.ts, 29, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) + +new g[1]["a-b"](1, 2, ...a); +>g : Symbol(g, Decl(newWithSpreadES5.ts, 29, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new g[1]["a-b"](1, 2, ...a, "string"); +>g : Symbol(g, Decl(newWithSpreadES5.ts, 29, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +>h : Symbol(h, Decl(newWithSpreadES5.ts, 30, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) + +new h["a-b"]["a-b"](1, 2, ...a); +>h : Symbol(h, Decl(newWithSpreadES5.ts, 30, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new h["a-b"]["a-b"](1, 2, ...a, "string"); +>h : Symbol(h, Decl(newWithSpreadES5.ts, 30, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES5.ts, 16, 13)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +>i : Symbol(i, Decl(newWithSpreadES5.ts, 31, 3)) + +new i["a-b"][1](1, 2, ...a); +>i : Symbol(i, Decl(newWithSpreadES5.ts, 31, 3)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + +new i["a-b"][1](1, 2, ...a, "string"); +>i : Symbol(i, Decl(newWithSpreadES5.ts, 31, 3)) +>a : Symbol(a, Decl(newWithSpreadES5.ts, 24, 3)) + diff --git a/tests/baselines/reference/newWithSpreadES5.types b/tests/baselines/reference/newWithSpreadES5.types new file mode 100644 index 0000000000..a2c83ed637 --- /dev/null +++ b/tests/baselines/reference/newWithSpreadES5.types @@ -0,0 +1,494 @@ +=== tests/cases/conformance/expressions/functionCalls/newWithSpreadES5.ts === + +function f(x: number, y: number, ...z: string[]) { +>f : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number +>z : string[] +} + +function f2(...x: string[]) {} +>f2 : (...x: string[]) => void +>x : string[] + +interface A { +>A : A + + f: { +>f : new (x: number, y: number, ...z: string[]) => any + + new (x: number, y: number, ...z: string[]); +>x : number +>y : number +>z : string[] + } +} + +class B { +>B : B + + constructor(x: number, y: number, ...z: string[]) {} +>x : number +>y : number +>z : string[] +} + +interface C { +>C : C + + "a-b": typeof B; +>B : typeof B +} + +interface D { +>D : D + + 1: typeof B; +>B : typeof B +} + +var a: string[]; +>a : string[] + +var b: A; +>b : A +>A : A + +var c: C; +>c : C +>C : C + +var d: A[]; +>d : A[] +>A : A + +var e: { [key: string]: A }; +>e : { [key: string]: A; } +>key : string +>A : A + +var g: C[]; +>g : C[] +>C : C + +var h: { [key: string]: C }; +>h : { [key: string]: C; } +>key : string +>C : C + +var i: C[][]; +>i : C[][] +>C : C + +// Basic expression +new f(1, 2, "string"); +>new f(1, 2, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>"string" : string + +new f(1, 2, ...a); +>new f(1, 2, ...a) : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] + +new f(1, 2, ...a, "string"); +>new f(1, 2, ...a, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Multiple spreads arguments +new f2(...a, ...a); +>new f2(...a, ...a) : any +>f2 : (...x: string[]) => void +>...a : string +>a : string[] +>...a : string +>a : string[] + +new f(1 ,2, ...a, ...a); +>new f(1 ,2, ...a, ...a) : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] +>...a : string +>a : string[] + +// Call expression +new f(1, 2, "string")(); +>new f(1, 2, "string")() : any +>new f(1, 2, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>"string" : string + +new f(1, 2, ...a)(); +>new f(1, 2, ...a)() : any +>new f(1, 2, ...a) : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] + +new f(1, 2, ...a, "string")(); +>new f(1, 2, ...a, "string")() : any +>new f(1, 2, ...a, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Property access expression +new b.f(1, 2, "string"); +>new b.f(1, 2, "string") : any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new b.f(1, 2, ...a); +>new b.f(1, 2, ...a) : any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new b.f(1, 2, ...a, "string"); +>new b.f(1, 2, ...a, "string") : any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Parenthesised expression +new (b.f)(1, 2, "string"); +>new (b.f)(1, 2, "string") : any +>(b.f) : new (x: number, y: number, ...z: string[]) => any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new (b.f)(1, 2, ...a); +>new (b.f)(1, 2, ...a) : any +>(b.f) : new (x: number, y: number, ...z: string[]) => any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new (b.f)(1, 2, ...a, "string"); +>new (b.f)(1, 2, ...a, "string") : any +>(b.f) : new (x: number, y: number, ...z: string[]) => any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression +new d[1].f(1, 2, "string"); +>new d[1].f(1, 2, "string") : any +>d[1].f : new (x: number, y: number, ...z: string[]) => any +>d[1] : A +>d : A[] +>1 : number +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new d[1].f(1, 2, ...a); +>new d[1].f(1, 2, ...a) : any +>d[1].f : new (x: number, y: number, ...z: string[]) => any +>d[1] : A +>d : A[] +>1 : number +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new d[1].f(1, 2, ...a, "string"); +>new d[1].f(1, 2, ...a, "string") : any +>d[1].f : new (x: number, y: number, ...z: string[]) => any +>d[1] : A +>d : A[] +>1 : number +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +>new e["a-b"].f(1, 2, "string") : any +>e["a-b"].f : new (x: number, y: number, ...z: string[]) => any +>e["a-b"] : A +>e : { [key: string]: A; } +>"a-b" : string +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new e["a-b"].f(1, 2, ...a); +>new e["a-b"].f(1, 2, ...a) : any +>e["a-b"].f : new (x: number, y: number, ...z: string[]) => any +>e["a-b"] : A +>e : { [key: string]: A; } +>"a-b" : string +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new e["a-b"].f(1, 2, ...a, "string"); +>new e["a-b"].f(1, 2, ...a, "string") : any +>e["a-b"].f : new (x: number, y: number, ...z: string[]) => any +>e["a-b"] : A +>e : { [key: string]: A; } +>"a-b" : string +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Basic expression +new B(1, 2, "string"); +>new B(1, 2, "string") : B +>B : typeof B +>1 : number +>2 : number +>"string" : string + +new B(1, 2, ...a); +>new B(1, 2, ...a) : B +>B : typeof B +>1 : number +>2 : number +>...a : string +>a : string[] + +new B(1, 2, ...a, "string"); +>new B(1, 2, ...a, "string") : B +>B : typeof B +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Property access expression +new c["a-b"](1, 2, "string"); +>new c["a-b"](1, 2, "string") : B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new c["a-b"](1, 2, ...a); +>new c["a-b"](1, 2, ...a) : B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new c["a-b"](1, 2, ...a, "string"); +>new c["a-b"](1, 2, ...a, "string") : B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +>new (c["a-b"])(1, 2, "string") : B +>(c["a-b"]) : typeof B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new (c["a-b"])(1, 2, ...a); +>new (c["a-b"])(1, 2, ...a) : B +>(c["a-b"]) : typeof B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new (c["a-b"])(1, 2, ...a, "string"); +>new (c["a-b"])(1, 2, ...a, "string") : B +>(c["a-b"]) : typeof B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +>new g[1]["a-b"](1, 2, "string") : B +>g[1]["a-b"] : typeof B +>g[1] : C +>g : C[] +>1 : number +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new g[1]["a-b"](1, 2, ...a); +>new g[1]["a-b"](1, 2, ...a) : B +>g[1]["a-b"] : typeof B +>g[1] : C +>g : C[] +>1 : number +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new g[1]["a-b"](1, 2, ...a, "string"); +>new g[1]["a-b"](1, 2, ...a, "string") : B +>g[1]["a-b"] : typeof B +>g[1] : C +>g : C[] +>1 : number +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +>new h["a-b"]["a-b"](1, 2, "string") : B +>h["a-b"]["a-b"] : typeof B +>h["a-b"] : C +>h : { [key: string]: C; } +>"a-b" : string +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new h["a-b"]["a-b"](1, 2, ...a); +>new h["a-b"]["a-b"](1, 2, ...a) : B +>h["a-b"]["a-b"] : typeof B +>h["a-b"] : C +>h : { [key: string]: C; } +>"a-b" : string +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new h["a-b"]["a-b"](1, 2, ...a, "string"); +>new h["a-b"]["a-b"](1, 2, ...a, "string") : B +>h["a-b"]["a-b"] : typeof B +>h["a-b"] : C +>h : { [key: string]: C; } +>"a-b" : string +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +>new i["a-b"][1](1, 2, "string") : any +>i["a-b"][1] : any +>i["a-b"] : any +>i : C[][] +>"a-b" : string +>1 : number +>1 : number +>2 : number +>"string" : string + +new i["a-b"][1](1, 2, ...a); +>new i["a-b"][1](1, 2, ...a) : any +>i["a-b"][1] : any +>i["a-b"] : any +>i : C[][] +>"a-b" : string +>1 : number +>1 : number +>2 : number +>...a : string +>a : string[] + +new i["a-b"][1](1, 2, ...a, "string"); +>new i["a-b"][1](1, 2, ...a, "string") : any +>i["a-b"][1] : any +>i["a-b"] : any +>i : C[][] +>"a-b" : string +>1 : number +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + diff --git a/tests/baselines/reference/newWithSpreadES6.js b/tests/baselines/reference/newWithSpreadES6.js new file mode 100644 index 0000000000..b712984f05 --- /dev/null +++ b/tests/baselines/reference/newWithSpreadES6.js @@ -0,0 +1,167 @@ +//// [newWithSpreadES6.ts] + +function f(x: number, y: number, ...z: string[]) { +} + +function f2(...x: string[]) { +} + +interface A { + f: { + new (x: number, y: number, ...z: string[]); + } +} + +class B { + constructor(x: number, y: number, ...z: string[]) {} +} + +interface C { + "a-b": typeof B; +} + +interface D { + 1: typeof B; +} + +var a: string[]; +var b: A; +var c: C; +var d: A[]; +var e: { [key: string]: A }; +var g: C[]; +var h: { [key: string]: C }; +var i: C[][]; + +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); + +// Multiple spreads arguments +new f2(...a, ...a); +new f(1 ,2, ...a, ...a); + +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); + +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); + +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); + +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); + +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); + +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); + +//// [newWithSpreadES6.js] +function f(x, y, ...z) { +} +function f2(...x) { +} +class B { + constructor(x, y, ...z) { + } +} +var a; +var b; +var c; +var d; +var e; +var g; +var h; +var i; +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); +// Multiple spreads arguments +new f2(...a, ...a); +new f(1, 2, ...a, ...a); +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); diff --git a/tests/baselines/reference/newWithSpreadES6.symbols b/tests/baselines/reference/newWithSpreadES6.symbols new file mode 100644 index 0000000000..51a34ad73e --- /dev/null +++ b/tests/baselines/reference/newWithSpreadES6.symbols @@ -0,0 +1,274 @@ +=== tests/cases/conformance/expressions/functionCalls/newWithSpreadES6.ts === + +function f(x: number, y: number, ...z: string[]) { +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) +>x : Symbol(x, Decl(newWithSpreadES6.ts, 1, 11)) +>y : Symbol(y, Decl(newWithSpreadES6.ts, 1, 21)) +>z : Symbol(z, Decl(newWithSpreadES6.ts, 1, 32)) +} + +function f2(...x: string[]) { +>f2 : Symbol(f2, Decl(newWithSpreadES6.ts, 2, 1)) +>x : Symbol(x, Decl(newWithSpreadES6.ts, 4, 12)) +} + +interface A { +>A : Symbol(A, Decl(newWithSpreadES6.ts, 5, 1)) + + f: { +>f : Symbol(f, Decl(newWithSpreadES6.ts, 7, 13)) + + new (x: number, y: number, ...z: string[]); +>x : Symbol(x, Decl(newWithSpreadES6.ts, 9, 13)) +>y : Symbol(y, Decl(newWithSpreadES6.ts, 9, 23)) +>z : Symbol(z, Decl(newWithSpreadES6.ts, 9, 34)) + } +} + +class B { +>B : Symbol(B, Decl(newWithSpreadES6.ts, 11, 1)) + + constructor(x: number, y: number, ...z: string[]) {} +>x : Symbol(x, Decl(newWithSpreadES6.ts, 14, 16)) +>y : Symbol(y, Decl(newWithSpreadES6.ts, 14, 26)) +>z : Symbol(z, Decl(newWithSpreadES6.ts, 14, 37)) +} + +interface C { +>C : Symbol(C, Decl(newWithSpreadES6.ts, 15, 1)) + + "a-b": typeof B; +>B : Symbol(B, Decl(newWithSpreadES6.ts, 11, 1)) +} + +interface D { +>D : Symbol(D, Decl(newWithSpreadES6.ts, 19, 1)) + + 1: typeof B; +>B : Symbol(B, Decl(newWithSpreadES6.ts, 11, 1)) +} + +var a: string[]; +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +var b: A; +>b : Symbol(b, Decl(newWithSpreadES6.ts, 26, 3)) +>A : Symbol(A, Decl(newWithSpreadES6.ts, 5, 1)) + +var c: C; +>c : Symbol(c, Decl(newWithSpreadES6.ts, 27, 3)) +>C : Symbol(C, Decl(newWithSpreadES6.ts, 15, 1)) + +var d: A[]; +>d : Symbol(d, Decl(newWithSpreadES6.ts, 28, 3)) +>A : Symbol(A, Decl(newWithSpreadES6.ts, 5, 1)) + +var e: { [key: string]: A }; +>e : Symbol(e, Decl(newWithSpreadES6.ts, 29, 3)) +>key : Symbol(key, Decl(newWithSpreadES6.ts, 29, 10)) +>A : Symbol(A, Decl(newWithSpreadES6.ts, 5, 1)) + +var g: C[]; +>g : Symbol(g, Decl(newWithSpreadES6.ts, 30, 3)) +>C : Symbol(C, Decl(newWithSpreadES6.ts, 15, 1)) + +var h: { [key: string]: C }; +>h : Symbol(h, Decl(newWithSpreadES6.ts, 31, 3)) +>key : Symbol(key, Decl(newWithSpreadES6.ts, 31, 10)) +>C : Symbol(C, Decl(newWithSpreadES6.ts, 15, 1)) + +var i: C[][]; +>i : Symbol(i, Decl(newWithSpreadES6.ts, 32, 3)) +>C : Symbol(C, Decl(newWithSpreadES6.ts, 15, 1)) + +// Basic expression +new f(1, 2, "string"); +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) + +new f(1, 2, ...a); +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new f(1, 2, ...a, "string"); +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Multiple spreads arguments +new f2(...a, ...a); +>f2 : Symbol(f2, Decl(newWithSpreadES6.ts, 2, 1)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new f(1 ,2, ...a, ...a); +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Call expression +new f(1, 2, "string")(); +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) + +new f(1, 2, ...a)(); +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new f(1, 2, ...a, "string")(); +>f : Symbol(f, Decl(newWithSpreadES6.ts, 0, 0)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Property access expression +new b.f(1, 2, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>b : Symbol(b, Decl(newWithSpreadES6.ts, 26, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) + +new b.f(1, 2, ...a); +>b.f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>b : Symbol(b, Decl(newWithSpreadES6.ts, 26, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new b.f(1, 2, ...a, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>b : Symbol(b, Decl(newWithSpreadES6.ts, 26, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Parenthesised expression +new (b.f)(1, 2, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>b : Symbol(b, Decl(newWithSpreadES6.ts, 26, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) + +new (b.f)(1, 2, ...a); +>b.f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>b : Symbol(b, Decl(newWithSpreadES6.ts, 26, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new (b.f)(1, 2, ...a, "string"); +>b.f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>b : Symbol(b, Decl(newWithSpreadES6.ts, 26, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Element access expression +new d[1].f(1, 2, "string"); +>d[1].f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>d : Symbol(d, Decl(newWithSpreadES6.ts, 28, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) + +new d[1].f(1, 2, ...a); +>d[1].f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>d : Symbol(d, Decl(newWithSpreadES6.ts, 28, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new d[1].f(1, 2, ...a, "string"); +>d[1].f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>d : Symbol(d, Decl(newWithSpreadES6.ts, 28, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +>e["a-b"].f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>e : Symbol(e, Decl(newWithSpreadES6.ts, 29, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) + +new e["a-b"].f(1, 2, ...a); +>e["a-b"].f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>e : Symbol(e, Decl(newWithSpreadES6.ts, 29, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new e["a-b"].f(1, 2, ...a, "string"); +>e["a-b"].f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>e : Symbol(e, Decl(newWithSpreadES6.ts, 29, 3)) +>f : Symbol(A.f, Decl(newWithSpreadES6.ts, 7, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Basic expression +new B(1, 2, "string"); +>B : Symbol(B, Decl(newWithSpreadES6.ts, 11, 1)) + +new B(1, 2, ...a); +>B : Symbol(B, Decl(newWithSpreadES6.ts, 11, 1)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new B(1, 2, ...a, "string"); +>B : Symbol(B, Decl(newWithSpreadES6.ts, 11, 1)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Property access expression +new c["a-b"](1, 2, "string"); +>c : Symbol(c, Decl(newWithSpreadES6.ts, 27, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) + +new c["a-b"](1, 2, ...a); +>c : Symbol(c, Decl(newWithSpreadES6.ts, 27, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new c["a-b"](1, 2, ...a, "string"); +>c : Symbol(c, Decl(newWithSpreadES6.ts, 27, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +>c : Symbol(c, Decl(newWithSpreadES6.ts, 27, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) + +new (c["a-b"])(1, 2, ...a); +>c : Symbol(c, Decl(newWithSpreadES6.ts, 27, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new (c["a-b"])(1, 2, ...a, "string"); +>c : Symbol(c, Decl(newWithSpreadES6.ts, 27, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +>g : Symbol(g, Decl(newWithSpreadES6.ts, 30, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) + +new g[1]["a-b"](1, 2, ...a); +>g : Symbol(g, Decl(newWithSpreadES6.ts, 30, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new g[1]["a-b"](1, 2, ...a, "string"); +>g : Symbol(g, Decl(newWithSpreadES6.ts, 30, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +>h : Symbol(h, Decl(newWithSpreadES6.ts, 31, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) + +new h["a-b"]["a-b"](1, 2, ...a); +>h : Symbol(h, Decl(newWithSpreadES6.ts, 31, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new h["a-b"]["a-b"](1, 2, ...a, "string"); +>h : Symbol(h, Decl(newWithSpreadES6.ts, 31, 3)) +>"a-b" : Symbol(C."a-b", Decl(newWithSpreadES6.ts, 17, 13)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +>i : Symbol(i, Decl(newWithSpreadES6.ts, 32, 3)) + +new i["a-b"][1](1, 2, ...a); +>i : Symbol(i, Decl(newWithSpreadES6.ts, 32, 3)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + +new i["a-b"][1](1, 2, ...a, "string"); +>i : Symbol(i, Decl(newWithSpreadES6.ts, 32, 3)) +>a : Symbol(a, Decl(newWithSpreadES6.ts, 25, 3)) + diff --git a/tests/baselines/reference/newWithSpreadES6.types b/tests/baselines/reference/newWithSpreadES6.types new file mode 100644 index 0000000000..52951729e3 --- /dev/null +++ b/tests/baselines/reference/newWithSpreadES6.types @@ -0,0 +1,495 @@ +=== tests/cases/conformance/expressions/functionCalls/newWithSpreadES6.ts === + +function f(x: number, y: number, ...z: string[]) { +>f : (x: number, y: number, ...z: string[]) => void +>x : number +>y : number +>z : string[] +} + +function f2(...x: string[]) { +>f2 : (...x: string[]) => void +>x : string[] +} + +interface A { +>A : A + + f: { +>f : new (x: number, y: number, ...z: string[]) => any + + new (x: number, y: number, ...z: string[]); +>x : number +>y : number +>z : string[] + } +} + +class B { +>B : B + + constructor(x: number, y: number, ...z: string[]) {} +>x : number +>y : number +>z : string[] +} + +interface C { +>C : C + + "a-b": typeof B; +>B : typeof B +} + +interface D { +>D : D + + 1: typeof B; +>B : typeof B +} + +var a: string[]; +>a : string[] + +var b: A; +>b : A +>A : A + +var c: C; +>c : C +>C : C + +var d: A[]; +>d : A[] +>A : A + +var e: { [key: string]: A }; +>e : { [key: string]: A; } +>key : string +>A : A + +var g: C[]; +>g : C[] +>C : C + +var h: { [key: string]: C }; +>h : { [key: string]: C; } +>key : string +>C : C + +var i: C[][]; +>i : C[][] +>C : C + +// Basic expression +new f(1, 2, "string"); +>new f(1, 2, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>"string" : string + +new f(1, 2, ...a); +>new f(1, 2, ...a) : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] + +new f(1, 2, ...a, "string"); +>new f(1, 2, ...a, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Multiple spreads arguments +new f2(...a, ...a); +>new f2(...a, ...a) : any +>f2 : (...x: string[]) => void +>...a : string +>a : string[] +>...a : string +>a : string[] + +new f(1 ,2, ...a, ...a); +>new f(1 ,2, ...a, ...a) : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] +>...a : string +>a : string[] + +// Call expression +new f(1, 2, "string")(); +>new f(1, 2, "string")() : any +>new f(1, 2, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>"string" : string + +new f(1, 2, ...a)(); +>new f(1, 2, ...a)() : any +>new f(1, 2, ...a) : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] + +new f(1, 2, ...a, "string")(); +>new f(1, 2, ...a, "string")() : any +>new f(1, 2, ...a, "string") : any +>f : (x: number, y: number, ...z: string[]) => void +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Property access expression +new b.f(1, 2, "string"); +>new b.f(1, 2, "string") : any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new b.f(1, 2, ...a); +>new b.f(1, 2, ...a) : any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new b.f(1, 2, ...a, "string"); +>new b.f(1, 2, ...a, "string") : any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Parenthesised expression +new (b.f)(1, 2, "string"); +>new (b.f)(1, 2, "string") : any +>(b.f) : new (x: number, y: number, ...z: string[]) => any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new (b.f)(1, 2, ...a); +>new (b.f)(1, 2, ...a) : any +>(b.f) : new (x: number, y: number, ...z: string[]) => any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new (b.f)(1, 2, ...a, "string"); +>new (b.f)(1, 2, ...a, "string") : any +>(b.f) : new (x: number, y: number, ...z: string[]) => any +>b.f : new (x: number, y: number, ...z: string[]) => any +>b : A +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression +new d[1].f(1, 2, "string"); +>new d[1].f(1, 2, "string") : any +>d[1].f : new (x: number, y: number, ...z: string[]) => any +>d[1] : A +>d : A[] +>1 : number +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new d[1].f(1, 2, ...a); +>new d[1].f(1, 2, ...a) : any +>d[1].f : new (x: number, y: number, ...z: string[]) => any +>d[1] : A +>d : A[] +>1 : number +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new d[1].f(1, 2, ...a, "string"); +>new d[1].f(1, 2, ...a, "string") : any +>d[1].f : new (x: number, y: number, ...z: string[]) => any +>d[1] : A +>d : A[] +>1 : number +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +>new e["a-b"].f(1, 2, "string") : any +>e["a-b"].f : new (x: number, y: number, ...z: string[]) => any +>e["a-b"] : A +>e : { [key: string]: A; } +>"a-b" : string +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>"string" : string + +new e["a-b"].f(1, 2, ...a); +>new e["a-b"].f(1, 2, ...a) : any +>e["a-b"].f : new (x: number, y: number, ...z: string[]) => any +>e["a-b"] : A +>e : { [key: string]: A; } +>"a-b" : string +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] + +new e["a-b"].f(1, 2, ...a, "string"); +>new e["a-b"].f(1, 2, ...a, "string") : any +>e["a-b"].f : new (x: number, y: number, ...z: string[]) => any +>e["a-b"] : A +>e : { [key: string]: A; } +>"a-b" : string +>f : new (x: number, y: number, ...z: string[]) => any +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Basic expression +new B(1, 2, "string"); +>new B(1, 2, "string") : B +>B : typeof B +>1 : number +>2 : number +>"string" : string + +new B(1, 2, ...a); +>new B(1, 2, ...a) : B +>B : typeof B +>1 : number +>2 : number +>...a : string +>a : string[] + +new B(1, 2, ...a, "string"); +>new B(1, 2, ...a, "string") : B +>B : typeof B +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Property access expression +new c["a-b"](1, 2, "string"); +>new c["a-b"](1, 2, "string") : B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new c["a-b"](1, 2, ...a); +>new c["a-b"](1, 2, ...a) : B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new c["a-b"](1, 2, ...a, "string"); +>new c["a-b"](1, 2, ...a, "string") : B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +>new (c["a-b"])(1, 2, "string") : B +>(c["a-b"]) : typeof B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new (c["a-b"])(1, 2, ...a); +>new (c["a-b"])(1, 2, ...a) : B +>(c["a-b"]) : typeof B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new (c["a-b"])(1, 2, ...a, "string"); +>new (c["a-b"])(1, 2, ...a, "string") : B +>(c["a-b"]) : typeof B +>c["a-b"] : typeof B +>c : C +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +>new g[1]["a-b"](1, 2, "string") : B +>g[1]["a-b"] : typeof B +>g[1] : C +>g : C[] +>1 : number +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new g[1]["a-b"](1, 2, ...a); +>new g[1]["a-b"](1, 2, ...a) : B +>g[1]["a-b"] : typeof B +>g[1] : C +>g : C[] +>1 : number +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new g[1]["a-b"](1, 2, ...a, "string"); +>new g[1]["a-b"](1, 2, ...a, "string") : B +>g[1]["a-b"] : typeof B +>g[1] : C +>g : C[] +>1 : number +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +>new h["a-b"]["a-b"](1, 2, "string") : B +>h["a-b"]["a-b"] : typeof B +>h["a-b"] : C +>h : { [key: string]: C; } +>"a-b" : string +>"a-b" : string +>1 : number +>2 : number +>"string" : string + +new h["a-b"]["a-b"](1, 2, ...a); +>new h["a-b"]["a-b"](1, 2, ...a) : B +>h["a-b"]["a-b"] : typeof B +>h["a-b"] : C +>h : { [key: string]: C; } +>"a-b" : string +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] + +new h["a-b"]["a-b"](1, 2, ...a, "string"); +>new h["a-b"]["a-b"](1, 2, ...a, "string") : B +>h["a-b"]["a-b"] : typeof B +>h["a-b"] : C +>h : { [key: string]: C; } +>"a-b" : string +>"a-b" : string +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +>new i["a-b"][1](1, 2, "string") : any +>i["a-b"][1] : any +>i["a-b"] : any +>i : C[][] +>"a-b" : string +>1 : number +>1 : number +>2 : number +>"string" : string + +new i["a-b"][1](1, 2, ...a); +>new i["a-b"][1](1, 2, ...a) : any +>i["a-b"][1] : any +>i["a-b"] : any +>i : C[][] +>"a-b" : string +>1 : number +>1 : number +>2 : number +>...a : string +>a : string[] + +new i["a-b"][1](1, 2, ...a, "string"); +>new i["a-b"][1](1, 2, ...a, "string") : any +>i["a-b"][1] : any +>i["a-b"] : any +>i : C[][] +>"a-b" : string +>1 : number +>1 : number +>2 : number +>...a : string +>a : string[] +>"string" : string + diff --git a/tests/baselines/reference/parserInterfaceDeclaration5.errors.txt b/tests/baselines/reference/parserInterfaceDeclaration5.errors.txt deleted file mode 100644 index 2b7ea65e95..0000000000 --- a/tests/baselines/reference/parserInterfaceDeclaration5.errors.txt +++ /dev/null @@ -1,8 +0,0 @@ -tests/cases/conformance/parser/ecmascript5/InterfaceDeclarations/parserInterfaceDeclaration5.ts(1,1): error TS1045: A 'declare' modifier cannot be used with an interface declaration. - - -==== tests/cases/conformance/parser/ecmascript5/InterfaceDeclarations/parserInterfaceDeclaration5.ts (1 errors) ==== - declare interface I { - ~~~~~~~ -!!! error TS1045: A 'declare' modifier cannot be used with an interface declaration. - } \ No newline at end of file diff --git a/tests/baselines/reference/parserInterfaceDeclaration5.symbols b/tests/baselines/reference/parserInterfaceDeclaration5.symbols new file mode 100644 index 0000000000..f9b738347c --- /dev/null +++ b/tests/baselines/reference/parserInterfaceDeclaration5.symbols @@ -0,0 +1,4 @@ +=== tests/cases/conformance/parser/ecmascript5/InterfaceDeclarations/parserInterfaceDeclaration5.ts === +declare interface I { +>I : Symbol(I, Decl(parserInterfaceDeclaration5.ts, 0, 0)) +} diff --git a/tests/baselines/reference/parserInterfaceDeclaration5.types b/tests/baselines/reference/parserInterfaceDeclaration5.types new file mode 100644 index 0000000000..c89559fc5c --- /dev/null +++ b/tests/baselines/reference/parserInterfaceDeclaration5.types @@ -0,0 +1,4 @@ +=== tests/cases/conformance/parser/ecmascript5/InterfaceDeclarations/parserInterfaceDeclaration5.ts === +declare interface I { +>I : I +} diff --git a/tests/baselines/reference/privacyCheckTypeOfInvisibleModuleNoError.js b/tests/baselines/reference/privacyCheckTypeOfInvisibleModuleNoError.js index 0301b7b9e4..6dd486e87d 100644 --- a/tests/baselines/reference/privacyCheckTypeOfInvisibleModuleNoError.js +++ b/tests/baselines/reference/privacyCheckTypeOfInvisibleModuleNoError.js @@ -14,5 +14,4 @@ var Outer; var Inner; (function (Inner) { })(Inner || (Inner = {})); - // Since we dont unwind inner any more, it is error here })(Outer || (Outer = {})); diff --git a/tests/baselines/reference/privacyGloVar.js b/tests/baselines/reference/privacyGloVar.js index 871407428f..e4bda49698 100644 --- a/tests/baselines/reference/privacyGloVar.js +++ b/tests/baselines/reference/privacyGloVar.js @@ -125,7 +125,6 @@ var m1; })(); var m1_v1_private; var m1_v3_private; - // error var m1_v11_private = new C1_public(); m1.m1_v12_public = new C1_public(); var m1_v13_private = new C2_private(); diff --git a/tests/baselines/reference/privacyVar.js b/tests/baselines/reference/privacyVar.js index 2dc78dd3d2..17c7b1a74d 100644 --- a/tests/baselines/reference/privacyVar.js +++ b/tests/baselines/reference/privacyVar.js @@ -219,7 +219,6 @@ var m1; })(); var m1_v1_private; var m1_v3_private; - // error var m1_v11_private = new C1_public(); m1.m1_v12_public = new C1_public(); var m1_v13_private = new C2_private(); @@ -324,7 +323,6 @@ var glo_C4_public = (function () { })(); var glo_v1_private; var glo_v3_private; - // error var glo_v11_private = new glo_C1_public(); exports.glo_v12_public = new glo_C1_public(); var glo_v13_private = new glo_C2_private(); diff --git a/tests/baselines/reference/privacyVarDeclFile.js b/tests/baselines/reference/privacyVarDeclFile.js index d080b9d7b2..4632ef8c60 100644 --- a/tests/baselines/reference/privacyVarDeclFile.js +++ b/tests/baselines/reference/privacyVarDeclFile.js @@ -459,7 +459,6 @@ var privateClassWithWithPublicPropertyTypes = (function () { } return privateClassWithWithPublicPropertyTypes; })(); - // Error var privateVarWithPrivatePropertyTypes; var privateVarWithPublicPropertyTypes; var publicClassWithPrivateModulePropertyTypes = (function () { @@ -468,7 +467,6 @@ var publicClassWithPrivateModulePropertyTypes = (function () { return publicClassWithPrivateModulePropertyTypes; })(); exports.publicClassWithPrivateModulePropertyTypes = publicClassWithPrivateModulePropertyTypes; - // Error var privateClassWithPrivateModulePropertyTypes = (function () { function privateClassWithPrivateModulePropertyTypes() { } @@ -510,7 +508,6 @@ var publicModule; } return privateClassWithWithPublicPropertyTypes; })(); - // Error var privateVarWithPrivatePropertyTypes; var privateVarWithPublicPropertyTypes; var publicClassWithPrivateModulePropertyTypes = (function () { @@ -519,7 +516,6 @@ var publicModule; return publicClassWithPrivateModulePropertyTypes; })(); publicModule.publicClassWithPrivateModulePropertyTypes = publicClassWithPrivateModulePropertyTypes; - // Error var privateClassWithPrivateModulePropertyTypes = (function () { function privateClassWithPrivateModulePropertyTypes() { } @@ -674,7 +670,6 @@ var publicModuleInGlobal; } return privateClassWithWithPublicPropertyTypes; })(); - // Error var privateVarWithPrivatePropertyTypes; var privateVarWithPublicPropertyTypes; var publicClassWithPrivateModulePropertyTypes = (function () { @@ -683,7 +678,6 @@ var publicModuleInGlobal; return publicClassWithPrivateModulePropertyTypes; })(); publicModuleInGlobal.publicClassWithPrivateModulePropertyTypes = publicClassWithPrivateModulePropertyTypes; - // Error var privateClassWithPrivateModulePropertyTypes = (function () { function privateClassWithPrivateModulePropertyTypes() { } diff --git a/tests/baselines/reference/promiseVoidErrorCallback.symbols b/tests/baselines/reference/promiseVoidErrorCallback.symbols index 78faacdb1f..9a6e2ef47b 100644 --- a/tests/baselines/reference/promiseVoidErrorCallback.symbols +++ b/tests/baselines/reference/promiseVoidErrorCallback.symbols @@ -22,13 +22,13 @@ interface T3 { function f1(): Promise { >f1 : Symbol(f1, Decl(promiseVoidErrorCallback.ts, 10, 1)) ->Promise : Symbol(Promise, Decl(lib.d.ts, 4769, 1), Decl(lib.d.ts, 4854, 11)) +>Promise : Symbol(Promise, Decl(lib.d.ts, 4766, 1), Decl(lib.d.ts, 4851, 11)) >T1 : Symbol(T1, Decl(promiseVoidErrorCallback.ts, 0, 0)) return Promise.resolve({ __t1: "foo_t1" }); ->Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.d.ts, 4836, 39), Decl(lib.d.ts, 4843, 54)) ->Promise : Symbol(Promise, Decl(lib.d.ts, 4769, 1), Decl(lib.d.ts, 4854, 11)) ->resolve : Symbol(PromiseConstructor.resolve, Decl(lib.d.ts, 4836, 39), Decl(lib.d.ts, 4843, 54)) +>Promise.resolve : Symbol(PromiseConstructor.resolve, Decl(lib.d.ts, 4833, 39), Decl(lib.d.ts, 4840, 54)) +>Promise : Symbol(Promise, Decl(lib.d.ts, 4766, 1), Decl(lib.d.ts, 4851, 11)) +>resolve : Symbol(PromiseConstructor.resolve, Decl(lib.d.ts, 4833, 39), Decl(lib.d.ts, 4840, 54)) >__t1 : Symbol(__t1, Decl(promiseVoidErrorCallback.ts, 13, 28)) } @@ -47,12 +47,12 @@ function f2(x: T1): T2 { var x3 = f1() >x3 : Symbol(x3, Decl(promiseVoidErrorCallback.ts, 20, 3)) ->f1() .then(f2, (e: Error) => { throw e;}) .then : Symbol(Promise.then, Decl(lib.d.ts, 4774, 22), Decl(lib.d.ts, 4781, 158)) ->f1() .then : Symbol(Promise.then, Decl(lib.d.ts, 4774, 22), Decl(lib.d.ts, 4781, 158)) +>f1() .then(f2, (e: Error) => { throw e;}) .then : Symbol(Promise.then, Decl(lib.d.ts, 4771, 22), Decl(lib.d.ts, 4778, 158)) +>f1() .then : Symbol(Promise.then, Decl(lib.d.ts, 4771, 22), Decl(lib.d.ts, 4778, 158)) >f1 : Symbol(f1, Decl(promiseVoidErrorCallback.ts, 10, 1)) .then(f2, (e: Error) => { ->then : Symbol(Promise.then, Decl(lib.d.ts, 4774, 22), Decl(lib.d.ts, 4781, 158)) +>then : Symbol(Promise.then, Decl(lib.d.ts, 4771, 22), Decl(lib.d.ts, 4778, 158)) >f2 : Symbol(f2, Decl(promiseVoidErrorCallback.ts, 14, 1)) >e : Symbol(e, Decl(promiseVoidErrorCallback.ts, 21, 15)) >Error : Symbol(Error, Decl(lib.d.ts, 876, 38), Decl(lib.d.ts, 889, 11)) @@ -62,7 +62,7 @@ var x3 = f1() }) .then((x: T2) => { ->then : Symbol(Promise.then, Decl(lib.d.ts, 4774, 22), Decl(lib.d.ts, 4781, 158)) +>then : Symbol(Promise.then, Decl(lib.d.ts, 4771, 22), Decl(lib.d.ts, 4778, 158)) >x : Symbol(x, Decl(promiseVoidErrorCallback.ts, 24, 11)) >T2 : Symbol(T2, Decl(promiseVoidErrorCallback.ts, 2, 1)) diff --git a/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType1.js b/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType1.js index d886fb39ea..866a54e964 100644 --- a/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType1.js +++ b/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType1.js @@ -27,5 +27,4 @@ define(["require", "exports"], function (require, exports) { }); //// [recursiveExportAssignmentAndFindAliasedType1_moduleA.js] define(["require", "exports"], function (require, exports) { - // This should result in type ClassB }); diff --git a/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType2.js b/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType2.js index 5b2992b02f..8398d252c8 100644 --- a/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType2.js +++ b/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType2.js @@ -31,5 +31,4 @@ define(["require", "exports"], function (require, exports) { }); //// [recursiveExportAssignmentAndFindAliasedType2_moduleA.js] define(["require", "exports"], function (require, exports) { - // This should result in type ClassB }); diff --git a/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType3.js b/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType3.js index acf9075f6d..9d992596f4 100644 --- a/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType3.js +++ b/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType3.js @@ -35,5 +35,4 @@ define(["require", "exports"], function (require, exports) { }); //// [recursiveExportAssignmentAndFindAliasedType3_moduleA.js] define(["require", "exports"], function (require, exports) { - // This should result in type ClassB }); diff --git a/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType4.js b/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType4.js index 8f6b76aa05..109950d030 100644 --- a/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType4.js +++ b/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType4.js @@ -27,5 +27,4 @@ define(["require", "exports"], function (require, exports) { }); //// [recursiveExportAssignmentAndFindAliasedType4_moduleA.js] define(["require", "exports"], function (require, exports) { - // This should result in type ClassB }); diff --git a/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType5.js b/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType5.js index 1d6e7f729a..2b5353f279 100644 --- a/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType5.js +++ b/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType5.js @@ -34,5 +34,4 @@ define(["require", "exports"], function (require, exports) { }); //// [recursiveExportAssignmentAndFindAliasedType5_moduleA.js] define(["require", "exports"], function (require, exports) { - // This should result in type ClassB }); diff --git a/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType6.js b/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType6.js index c8fd463c2f..6ae03f9c9b 100644 --- a/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType6.js +++ b/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType6.js @@ -41,5 +41,4 @@ define(["require", "exports"], function (require, exports) { }); //// [recursiveExportAssignmentAndFindAliasedType6_moduleA.js] define(["require", "exports"], function (require, exports) { - // This should result in type ClassB }); diff --git a/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType7.js b/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType7.js index aa82e463ce..8e87b0bc3a 100644 --- a/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType7.js +++ b/tests/baselines/reference/recursiveExportAssignmentAndFindAliasedType7.js @@ -46,5 +46,4 @@ define(["require", "exports"], function (require, exports) { }); //// [recursiveExportAssignmentAndFindAliasedType7_moduleA.js] define(["require", "exports"], function (require, exports) { - // This should result in type ClassB }); diff --git a/tests/baselines/reference/separateCompilationAmbientConstEnum.errors.txt b/tests/baselines/reference/separateCompilationAmbientConstEnum.errors.txt deleted file mode 100644 index 6ea2e445e2..0000000000 --- a/tests/baselines/reference/separateCompilationAmbientConstEnum.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -tests/cases/compiler/separateCompilationAmbientConstEnum.ts(3,20): error TS1209: Ambient const enums are not allowed when the '--separateCompilation' flag is provided. - - -==== tests/cases/compiler/separateCompilationAmbientConstEnum.ts (1 errors) ==== - - - declare const enum E { X = 1} - ~ -!!! error TS1209: Ambient const enums are not allowed when the '--separateCompilation' flag is provided. - export var y; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationAmbientConstEnum.js b/tests/baselines/reference/separateCompilationAmbientConstEnum.js deleted file mode 100644 index 5b3af0957e..0000000000 --- a/tests/baselines/reference/separateCompilationAmbientConstEnum.js +++ /dev/null @@ -1,8 +0,0 @@ -//// [separateCompilationAmbientConstEnum.ts] - - -declare const enum E { X = 1} -export var y; - -//// [separateCompilationAmbientConstEnum.js] -export var y; diff --git a/tests/baselines/reference/separateCompilationDeclaration.js b/tests/baselines/reference/separateCompilationDeclaration.js deleted file mode 100644 index 33d64b088d..0000000000 --- a/tests/baselines/reference/separateCompilationDeclaration.js +++ /dev/null @@ -1,10 +0,0 @@ -//// [separateCompilationDeclaration.ts] - -export var x; - -//// [separateCompilationDeclaration.js] -export var x; - - -//// [separateCompilationDeclaration.d.ts] -export declare var x: any; diff --git a/tests/baselines/reference/separateCompilationES6.js b/tests/baselines/reference/separateCompilationES6.js deleted file mode 100644 index cf05e5590a..0000000000 --- a/tests/baselines/reference/separateCompilationES6.js +++ /dev/null @@ -1,5 +0,0 @@ -//// [separateCompilationES6.ts] -export var x; - -//// [separateCompilationES6.js] -export var x; diff --git a/tests/baselines/reference/separateCompilationES6.symbols b/tests/baselines/reference/separateCompilationES6.symbols deleted file mode 100644 index 737d5e4136..0000000000 --- a/tests/baselines/reference/separateCompilationES6.symbols +++ /dev/null @@ -1,4 +0,0 @@ -=== tests/cases/compiler/separateCompilationES6.ts === -export var x; ->x : Symbol(x, Decl(separateCompilationES6.ts, 0, 10)) - diff --git a/tests/baselines/reference/separateCompilationES6.types b/tests/baselines/reference/separateCompilationES6.types deleted file mode 100644 index 7038190680..0000000000 --- a/tests/baselines/reference/separateCompilationES6.types +++ /dev/null @@ -1,4 +0,0 @@ -=== tests/cases/compiler/separateCompilationES6.ts === -export var x; ->x : any - diff --git a/tests/baselines/reference/separateCompilationImportExportElision.errors.txt b/tests/baselines/reference/separateCompilationImportExportElision.errors.txt deleted file mode 100644 index 0bac01d813..0000000000 --- a/tests/baselines/reference/separateCompilationImportExportElision.errors.txt +++ /dev/null @@ -1,28 +0,0 @@ -tests/cases/compiler/separateCompilationImportExportElision.ts(2,17): error TS2307: Cannot find module 'module'. -tests/cases/compiler/separateCompilationImportExportElision.ts(3,18): error TS2307: Cannot find module 'module'. -tests/cases/compiler/separateCompilationImportExportElision.ts(4,21): error TS2307: Cannot find module 'module'. -tests/cases/compiler/separateCompilationImportExportElision.ts(12,18): error TS2307: Cannot find module 'module'. - - -==== tests/cases/compiler/separateCompilationImportExportElision.ts (4 errors) ==== - - import {c} from "module" - ~~~~~~~~ -!!! error TS2307: Cannot find module 'module'. - import {c2} from "module" - ~~~~~~~~ -!!! error TS2307: Cannot find module 'module'. - import * as ns from "module" - ~~~~~~~~ -!!! error TS2307: Cannot find module 'module'. - - class C extends c2.C { - } - - let x = new c(); - let y = ns.value; - - export {c1} from "module"; - ~~~~~~~~ -!!! error TS2307: Cannot find module 'module'. - export var z = x; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationNoExternalModule.errors.txt b/tests/baselines/reference/separateCompilationNoExternalModule.errors.txt deleted file mode 100644 index 71d7da73a8..0000000000 --- a/tests/baselines/reference/separateCompilationNoExternalModule.errors.txt +++ /dev/null @@ -1,8 +0,0 @@ -tests/cases/compiler/separateCompilationNoExternalModule.ts(2,1): error TS1208: Cannot compile namespaces when the '--separateCompilation' flag is provided. - - -==== tests/cases/compiler/separateCompilationNoExternalModule.ts (1 errors) ==== - - var x; - ~~~ -!!! error TS1208: Cannot compile namespaces when the '--separateCompilation' flag is provided. \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationNoExternalModule.js b/tests/baselines/reference/separateCompilationNoExternalModule.js deleted file mode 100644 index 9ddc8bdef2..0000000000 --- a/tests/baselines/reference/separateCompilationNoExternalModule.js +++ /dev/null @@ -1,6 +0,0 @@ -//// [separateCompilationNoExternalModule.ts] - -var x; - -//// [separateCompilationNoExternalModule.js] -var x; diff --git a/tests/baselines/reference/separateCompilationNonAmbientConstEnum.symbols b/tests/baselines/reference/separateCompilationNonAmbientConstEnum.symbols deleted file mode 100644 index da3f7ce645..0000000000 --- a/tests/baselines/reference/separateCompilationNonAmbientConstEnum.symbols +++ /dev/null @@ -1,15 +0,0 @@ -=== tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts === - -const enum E { X = 100 }; ->E : Symbol(E, Decl(separateCompilationNonAmbientConstEnum.ts, 0, 0)) ->X : Symbol(E.X, Decl(separateCompilationNonAmbientConstEnum.ts, 1, 14)) - -var e = E.X; ->e : Symbol(e, Decl(separateCompilationNonAmbientConstEnum.ts, 2, 3)) ->E.X : Symbol(E.X, Decl(separateCompilationNonAmbientConstEnum.ts, 1, 14)) ->E : Symbol(E, Decl(separateCompilationNonAmbientConstEnum.ts, 0, 0)) ->X : Symbol(E.X, Decl(separateCompilationNonAmbientConstEnum.ts, 1, 14)) - -export var x; ->x : Symbol(x, Decl(separateCompilationNonAmbientConstEnum.ts, 3, 10)) - diff --git a/tests/baselines/reference/separateCompilationPlainFile-AMD.errors.txt b/tests/baselines/reference/separateCompilationPlainFile-AMD.errors.txt deleted file mode 100644 index 6b80da30d3..0000000000 --- a/tests/baselines/reference/separateCompilationPlainFile-AMD.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -tests/cases/compiler/separateCompilationPlainFile-AMD.ts(2,1): error TS1208: Cannot compile namespaces when the '--separateCompilation' flag is provided. - - -==== tests/cases/compiler/separateCompilationPlainFile-AMD.ts (1 errors) ==== - - declare function run(a: number): void; - ~~~~~~~ -!!! error TS1208: Cannot compile namespaces when the '--separateCompilation' flag is provided. - run(1); - \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationPlainFile-CommonJS.errors.txt b/tests/baselines/reference/separateCompilationPlainFile-CommonJS.errors.txt deleted file mode 100644 index 48a23a3965..0000000000 --- a/tests/baselines/reference/separateCompilationPlainFile-CommonJS.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -tests/cases/compiler/separateCompilationPlainFile-CommonJS.ts(2,1): error TS1208: Cannot compile namespaces when the '--separateCompilation' flag is provided. - - -==== tests/cases/compiler/separateCompilationPlainFile-CommonJS.ts (1 errors) ==== - - declare function run(a: number): void; - ~~~~~~~ -!!! error TS1208: Cannot compile namespaces when the '--separateCompilation' flag is provided. - run(1); - \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationPlainFile-CommonJS.js b/tests/baselines/reference/separateCompilationPlainFile-CommonJS.js deleted file mode 100644 index cd82cdf20a..0000000000 --- a/tests/baselines/reference/separateCompilationPlainFile-CommonJS.js +++ /dev/null @@ -1,8 +0,0 @@ -//// [separateCompilationPlainFile-CommonJS.ts] - -declare function run(a: number): void; -run(1); - - -//// [separateCompilationPlainFile-CommonJS.js] -run(1); diff --git a/tests/baselines/reference/separateCompilationPlainFile-ES6.errors.txt b/tests/baselines/reference/separateCompilationPlainFile-ES6.errors.txt deleted file mode 100644 index b0b059c73b..0000000000 --- a/tests/baselines/reference/separateCompilationPlainFile-ES6.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -tests/cases/compiler/separateCompilationPlainFile-ES6.ts(2,1): error TS1208: Cannot compile namespaces when the '--separateCompilation' flag is provided. - - -==== tests/cases/compiler/separateCompilationPlainFile-ES6.ts (1 errors) ==== - - declare function run(a: number): void; - ~~~~~~~ -!!! error TS1208: Cannot compile namespaces when the '--separateCompilation' flag is provided. - run(1); - \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationPlainFile-ES6.js b/tests/baselines/reference/separateCompilationPlainFile-ES6.js deleted file mode 100644 index 1cb6082f13..0000000000 --- a/tests/baselines/reference/separateCompilationPlainFile-ES6.js +++ /dev/null @@ -1,8 +0,0 @@ -//// [separateCompilationPlainFile-ES6.ts] - -declare function run(a: number): void; -run(1); - - -//// [separateCompilationPlainFile-ES6.js] -run(1); diff --git a/tests/baselines/reference/separateCompilationPlainFile-System.errors.txt b/tests/baselines/reference/separateCompilationPlainFile-System.errors.txt deleted file mode 100644 index c3161c5727..0000000000 --- a/tests/baselines/reference/separateCompilationPlainFile-System.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -tests/cases/compiler/separateCompilationPlainFile-System.ts(2,1): error TS1208: Cannot compile namespaces when the '--separateCompilation' flag is provided. - - -==== tests/cases/compiler/separateCompilationPlainFile-System.ts (1 errors) ==== - - declare function run(a: number): void; - ~~~~~~~ -!!! error TS1208: Cannot compile namespaces when the '--separateCompilation' flag is provided. - run(1); - \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationPlainFile-UMD.errors.txt b/tests/baselines/reference/separateCompilationPlainFile-UMD.errors.txt deleted file mode 100644 index 6a0fb1ac8d..0000000000 --- a/tests/baselines/reference/separateCompilationPlainFile-UMD.errors.txt +++ /dev/null @@ -1,10 +0,0 @@ -tests/cases/compiler/separateCompilationPlainFile-UMD.ts(2,1): error TS1208: Cannot compile namespaces when the '--separateCompilation' flag is provided. - - -==== tests/cases/compiler/separateCompilationPlainFile-UMD.ts (1 errors) ==== - - declare function run(a: number): void; - ~~~~~~~ -!!! error TS1208: Cannot compile namespaces when the '--separateCompilation' flag is provided. - run(1); - \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationSourceMap.js b/tests/baselines/reference/separateCompilationSourceMap.js deleted file mode 100644 index 1e8f141eb4..0000000000 --- a/tests/baselines/reference/separateCompilationSourceMap.js +++ /dev/null @@ -1,7 +0,0 @@ -//// [separateCompilationSourceMap.ts] - -export var x; - -//// [separateCompilationSourceMap.js] -export var x; -//# sourceMappingURL=separateCompilationSourceMap.js.map \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationSourceMap.js.map b/tests/baselines/reference/separateCompilationSourceMap.js.map deleted file mode 100644 index 68c4e2c78d..0000000000 --- a/tests/baselines/reference/separateCompilationSourceMap.js.map +++ /dev/null @@ -1,2 +0,0 @@ -//// [separateCompilationSourceMap.js.map] -{"version":3,"file":"separateCompilationSourceMap.js","sourceRoot":"","sources":["separateCompilationSourceMap.ts"],"names":[],"mappings":"AACA,WAAW,CAAC,CAAC"} \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationSpecifiedModule.js b/tests/baselines/reference/separateCompilationSpecifiedModule.js deleted file mode 100644 index 02616b7587..0000000000 --- a/tests/baselines/reference/separateCompilationSpecifiedModule.js +++ /dev/null @@ -1,4 +0,0 @@ -//// [separateCompilationSpecifiedModule.ts] -export var x; - -//// [separateCompilationSpecifiedModule.js] diff --git a/tests/baselines/reference/separateCompilationSpecifiedModule.symbols b/tests/baselines/reference/separateCompilationSpecifiedModule.symbols deleted file mode 100644 index a69b579b34..0000000000 --- a/tests/baselines/reference/separateCompilationSpecifiedModule.symbols +++ /dev/null @@ -1,4 +0,0 @@ -=== tests/cases/compiler/separateCompilationSpecifiedModule.ts === -export var x; ->x : Symbol(x, Decl(separateCompilationSpecifiedModule.ts, 0, 10)) - diff --git a/tests/baselines/reference/separateCompilationSpecifiedModule.types b/tests/baselines/reference/separateCompilationSpecifiedModule.types deleted file mode 100644 index 497f63faf6..0000000000 --- a/tests/baselines/reference/separateCompilationSpecifiedModule.types +++ /dev/null @@ -1,4 +0,0 @@ -=== tests/cases/compiler/separateCompilationSpecifiedModule.ts === -export var x; ->x : any - diff --git a/tests/baselines/reference/separateCompilationUnspecifiedModule.errors.txt b/tests/baselines/reference/separateCompilationUnspecifiedModule.errors.txt deleted file mode 100644 index ab0fd7ffe9..0000000000 --- a/tests/baselines/reference/separateCompilationUnspecifiedModule.errors.txt +++ /dev/null @@ -1,6 +0,0 @@ -error TS5047: Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher. - - -!!! error TS5047: Option 'separateCompilation' can only be used when either option'--module' is provided or option 'target' is 'ES6' or higher. -==== tests/cases/compiler/separateCompilationUnspecifiedModule.ts (0 errors) ==== - export var x; \ No newline at end of file diff --git a/tests/baselines/reference/separateCompilationUnspecifiedModule.js b/tests/baselines/reference/separateCompilationUnspecifiedModule.js deleted file mode 100644 index 1525207a93..0000000000 --- a/tests/baselines/reference/separateCompilationUnspecifiedModule.js +++ /dev/null @@ -1,4 +0,0 @@ -//// [separateCompilationUnspecifiedModule.ts] -export var x; - -//// [separateCompilationUnspecifiedModule.js] diff --git a/tests/baselines/reference/templateStringInYieldKeyword.errors.txt b/tests/baselines/reference/templateStringInYieldKeyword.errors.txt index 7b28cf64ae..5761d1464e 100644 --- a/tests/baselines/reference/templateStringInYieldKeyword.errors.txt +++ b/tests/baselines/reference/templateStringInYieldKeyword.errors.txt @@ -1,14 +1,11 @@ -tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(1,9): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(3,13): error TS9000: 'yield' expressions are not currently supported. +tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts(1,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. -==== tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts (2 errors) ==== +==== tests/cases/conformance/es6/templates/templateStringInYieldKeyword.ts (1 errors) ==== function* gen() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. // Once this is supported, the inner expression does not need to be parenthesized. var x = yield `abc${ x }def`; - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. } \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithEmbeddedNewOperatorES6.symbols b/tests/baselines/reference/templateStringWithEmbeddedNewOperatorES6.symbols index 0cfe0d854b..4d7c4d6ac4 100644 --- a/tests/baselines/reference/templateStringWithEmbeddedNewOperatorES6.symbols +++ b/tests/baselines/reference/templateStringWithEmbeddedNewOperatorES6.symbols @@ -1,5 +1,5 @@ === tests/cases/conformance/es6/templates/templateStringWithEmbeddedNewOperatorES6.ts === var x = `abc${ new String("Hi") }def`; >x : Symbol(x, Decl(templateStringWithEmbeddedNewOperatorES6.ts, 0, 3)) ->String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1538, 1)) +>String : Symbol(String, Decl(lib.d.ts, 275, 1), Decl(lib.d.ts, 443, 11), Decl(lib.d.ts, 1543, 1)) diff --git a/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.errors.txt b/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.errors.txt deleted file mode 100644 index 46ca3c74b9..0000000000 --- a/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.errors.txt +++ /dev/null @@ -1,14 +0,0 @@ -tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(1,9): error TS9001: Generators are not currently supported. -tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts(3,20): error TS9000: 'yield' expressions are not currently supported. - - -==== tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts (2 errors) ==== - function* gen() { - ~ -!!! error TS9001: Generators are not currently supported. - // Once this is supported, yield *must* be parenthesized. - var x = `abc${ yield 10 }def`; - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. - } - \ No newline at end of file diff --git a/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.symbols b/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.symbols new file mode 100644 index 0000000000..4248d66fb4 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.symbols @@ -0,0 +1,9 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts === +function* gen() { +>gen : Symbol(gen, Decl(templateStringWithEmbeddedYieldKeywordES6.ts, 0, 0)) + + // Once this is supported, yield *must* be parenthesized. + var x = `abc${ yield 10 }def`; +>x : Symbol(x, Decl(templateStringWithEmbeddedYieldKeywordES6.ts, 2, 7)) +} + diff --git a/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.types b/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.types new file mode 100644 index 0000000000..3a6f5d1672 --- /dev/null +++ b/tests/baselines/reference/templateStringWithEmbeddedYieldKeywordES6.types @@ -0,0 +1,12 @@ +=== tests/cases/conformance/es6/templates/templateStringWithEmbeddedYieldKeywordES6.ts === +function* gen() { +>gen : () => IterableIterator + + // Once this is supported, yield *must* be parenthesized. + var x = `abc${ yield 10 }def`; +>x : string +>`abc${ yield 10 }def` : string +>yield 10 : any +>10 : number +} + diff --git a/tests/baselines/reference/typeCheckObjectLiteralMethodBody.errors.txt b/tests/baselines/reference/typeCheckObjectLiteralMethodBody.errors.txt new file mode 100644 index 0000000000..7db4c2506c --- /dev/null +++ b/tests/baselines/reference/typeCheckObjectLiteralMethodBody.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/typeCheckObjectLiteralMethodBody.ts(1,13): error TS7010: 'bar', which lacks return-type annotation, implicitly has an 'any' return type. + + +==== tests/cases/compiler/typeCheckObjectLiteralMethodBody.ts (1 errors) ==== + var foo = { bar() { return undefined } }; + ~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS7010: 'bar', which lacks return-type annotation, implicitly has an 'any' return type. \ No newline at end of file diff --git a/tests/baselines/reference/typeCheckObjectLiteralMethodBody.js b/tests/baselines/reference/typeCheckObjectLiteralMethodBody.js new file mode 100644 index 0000000000..1339315e93 --- /dev/null +++ b/tests/baselines/reference/typeCheckObjectLiteralMethodBody.js @@ -0,0 +1,5 @@ +//// [typeCheckObjectLiteralMethodBody.ts] +var foo = { bar() { return undefined } }; + +//// [typeCheckObjectLiteralMethodBody.js] +var foo = { bar: function () { return undefined; } }; diff --git a/tests/baselines/reference/typeCheckReturnExpression.errors.txt b/tests/baselines/reference/typeCheckReturnExpression.errors.txt new file mode 100644 index 0000000000..c648c57799 --- /dev/null +++ b/tests/baselines/reference/typeCheckReturnExpression.errors.txt @@ -0,0 +1,7 @@ +tests/cases/compiler/typeCheckReturnExpression.ts(1,11): error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. + + +==== tests/cases/compiler/typeCheckReturnExpression.ts (1 errors) ==== + var foo = () => undefined; + ~~~~~~~~~~~~~~~ +!!! error TS7011: Function expression, which lacks return-type annotation, implicitly has an 'any' return type. \ No newline at end of file diff --git a/tests/baselines/reference/typeCheckReturnExpression.js b/tests/baselines/reference/typeCheckReturnExpression.js new file mode 100644 index 0000000000..ba71780b48 --- /dev/null +++ b/tests/baselines/reference/typeCheckReturnExpression.js @@ -0,0 +1,5 @@ +//// [typeCheckReturnExpression.ts] +var foo = () => undefined; + +//// [typeCheckReturnExpression.js] +var foo = function () { return undefined; }; diff --git a/tests/baselines/reference/typeGuardsInModule.js b/tests/baselines/reference/typeGuardsInModule.js index af87fae17c..6c1ccdbb5a 100644 --- a/tests/baselines/reference/typeGuardsInModule.js +++ b/tests/baselines/reference/typeGuardsInModule.js @@ -107,7 +107,6 @@ var m1; else { num = var2; // number } - // exported variable in the module if (typeof m1.var3 === "string") { strOrNum = m1.var3; // string | number } @@ -135,7 +134,6 @@ var m2; else { num = var4; // number } - // exported variable in the module if (typeof m3.var5 === "string") { strOrNum = m3.var5; // string | number } @@ -159,7 +157,6 @@ var m3; else { num = var2; // number } - // exported variable in the module if (typeof m4.var3 === "string") { strOrNum = m4.var3; // string | number } diff --git a/tests/baselines/reference/typedArrays.symbols b/tests/baselines/reference/typedArrays.symbols index 27b72cc54f..4ea9d0283a 100644 --- a/tests/baselines/reference/typedArrays.symbols +++ b/tests/baselines/reference/typedArrays.symbols @@ -8,39 +8,39 @@ function CreateTypedArrayTypes() { typedArrays[0] = Int8Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2107, 42), Decl(lib.d.ts, 2397, 11)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) typedArrays[1] = Uint8Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2397, 44), Decl(lib.d.ts, 2687, 11)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) typedArrays[2] = Int16Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2977, 60), Decl(lib.d.ts, 3267, 11)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) typedArrays[3] = Uint16Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3267, 46), Decl(lib.d.ts, 3557, 11)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) typedArrays[4] = Int32Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3557, 48), Decl(lib.d.ts, 3847, 11)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) typedArrays[5] = Uint32Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3847, 46), Decl(lib.d.ts, 4137, 11)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) typedArrays[6] = Float32Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4137, 48), Decl(lib.d.ts, 4427, 11)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) typedArrays[7] = Float64Array; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4427, 50), Decl(lib.d.ts, 4717, 11)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) typedArrays[8] = Uint8ClampedArray; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2687, 46), Decl(lib.d.ts, 2977, 11)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) return typedArrays; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 2, 7)) @@ -55,47 +55,47 @@ function CreateTypedArrayInstancesFromLength(obj: number) { typedArrays[0] = new Int8Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2107, 42), Decl(lib.d.ts, 2397, 11)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[1] = new Uint8Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2397, 44), Decl(lib.d.ts, 2687, 11)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[2] = new Int16Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2977, 60), Decl(lib.d.ts, 3267, 11)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[3] = new Uint16Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3267, 46), Decl(lib.d.ts, 3557, 11)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[4] = new Int32Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3557, 48), Decl(lib.d.ts, 3847, 11)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[5] = new Uint32Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3847, 46), Decl(lib.d.ts, 4137, 11)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[6] = new Float32Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4137, 48), Decl(lib.d.ts, 4427, 11)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[7] = new Float64Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4427, 50), Decl(lib.d.ts, 4717, 11)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) typedArrays[8] = new Uint8ClampedArray(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 17, 7)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2687, 46), Decl(lib.d.ts, 2977, 11)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 16, 45)) return typedArrays; @@ -111,47 +111,47 @@ function CreateTypedArrayInstancesFromArray(obj: number[]) { typedArrays[0] = new Int8Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2107, 42), Decl(lib.d.ts, 2397, 11)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[1] = new Uint8Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2397, 44), Decl(lib.d.ts, 2687, 11)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[2] = new Int16Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2977, 60), Decl(lib.d.ts, 3267, 11)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[3] = new Uint16Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3267, 46), Decl(lib.d.ts, 3557, 11)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[4] = new Int32Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3557, 48), Decl(lib.d.ts, 3847, 11)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[5] = new Uint32Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3847, 46), Decl(lib.d.ts, 4137, 11)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[6] = new Float32Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4137, 48), Decl(lib.d.ts, 4427, 11)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[7] = new Float64Array(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4427, 50), Decl(lib.d.ts, 4717, 11)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) typedArrays[8] = new Uint8ClampedArray(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 32, 7)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2687, 46), Decl(lib.d.ts, 2977, 11)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) >obj : Symbol(obj, Decl(typedArrays.ts, 31, 44)) return typedArrays; @@ -167,65 +167,65 @@ function CreateIntegerTypedArraysFromArray2(obj:number[]) { typedArrays[0] = Int8Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2387, 38)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2107, 42), Decl(lib.d.ts, 2397, 11)) ->from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2387, 38)) +>Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) +>from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[1] = Uint8Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2677, 39)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2397, 44), Decl(lib.d.ts, 2687, 11)) ->from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2677, 39)) +>Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) +>from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[2] = Int16Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3257, 39)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2977, 60), Decl(lib.d.ts, 3267, 11)) ->from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3257, 39)) +>Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) +>from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[3] = Uint16Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3547, 40)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3267, 46), Decl(lib.d.ts, 3557, 11)) ->from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3547, 40)) +>Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) +>from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[4] = Int32Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3837, 39)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3557, 48), Decl(lib.d.ts, 3847, 11)) ->from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3837, 39)) +>Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) +>from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[5] = Uint32Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4127, 40)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3847, 46), Decl(lib.d.ts, 4137, 11)) ->from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4127, 40)) +>Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) +>from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[6] = Float32Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4417, 41)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4137, 48), Decl(lib.d.ts, 4427, 11)) ->from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4417, 41)) +>Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) +>from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[7] = Float64Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4707, 41)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4427, 50), Decl(lib.d.ts, 4717, 11)) ->from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4707, 41)) +>Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) +>from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) typedArrays[8] = Uint8ClampedArray.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 47, 7)) ->Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2967, 46)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2687, 46), Decl(lib.d.ts, 2977, 11)) ->from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2967, 46)) +>Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) +>from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) >obj : Symbol(obj, Decl(typedArrays.ts, 46, 44)) return typedArrays; @@ -242,65 +242,65 @@ function CreateIntegerTypedArraysFromArrayLike(obj:ArrayLike) { typedArrays[0] = Int8Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2387, 38)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2107, 42), Decl(lib.d.ts, 2397, 11)) ->from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2387, 38)) +>Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) +>from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[1] = Uint8Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2677, 39)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2397, 44), Decl(lib.d.ts, 2687, 11)) ->from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2677, 39)) +>Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) +>from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[2] = Int16Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3257, 39)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2977, 60), Decl(lib.d.ts, 3267, 11)) ->from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3257, 39)) +>Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) +>from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[3] = Uint16Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3547, 40)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3267, 46), Decl(lib.d.ts, 3557, 11)) ->from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3547, 40)) +>Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) +>from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[4] = Int32Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3837, 39)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3557, 48), Decl(lib.d.ts, 3847, 11)) ->from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3837, 39)) +>Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) +>from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[5] = Uint32Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4127, 40)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3847, 46), Decl(lib.d.ts, 4137, 11)) ->from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4127, 40)) +>Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) +>from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[6] = Float32Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4417, 41)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4137, 48), Decl(lib.d.ts, 4427, 11)) ->from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4417, 41)) +>Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) +>from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[7] = Float64Array.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4707, 41)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4427, 50), Decl(lib.d.ts, 4717, 11)) ->from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4707, 41)) +>Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) +>from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) typedArrays[8] = Uint8ClampedArray.from(obj); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 62, 7)) ->Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2967, 46)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2687, 46), Decl(lib.d.ts, 2977, 11)) ->from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2967, 46)) +>Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) +>from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) >obj : Symbol(obj, Decl(typedArrays.ts, 61, 47)) return typedArrays; @@ -332,57 +332,57 @@ function CreateTypedArraysOf2() { typedArrays[0] = Int8Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Int8Array.of : Symbol(Int8ArrayConstructor.of, Decl(lib.d.ts, 2381, 30)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2107, 42), Decl(lib.d.ts, 2397, 11)) ->of : Symbol(Int8ArrayConstructor.of, Decl(lib.d.ts, 2381, 30)) +>Int8Array.of : Symbol(Int8ArrayConstructor.of, Decl(lib.d.ts, 2378, 30)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) +>of : Symbol(Int8ArrayConstructor.of, Decl(lib.d.ts, 2378, 30)) typedArrays[1] = Uint8Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Uint8Array.of : Symbol(Uint8ArrayConstructor.of, Decl(lib.d.ts, 2671, 30)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2397, 44), Decl(lib.d.ts, 2687, 11)) ->of : Symbol(Uint8ArrayConstructor.of, Decl(lib.d.ts, 2671, 30)) +>Uint8Array.of : Symbol(Uint8ArrayConstructor.of, Decl(lib.d.ts, 2668, 30)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) +>of : Symbol(Uint8ArrayConstructor.of, Decl(lib.d.ts, 2668, 30)) typedArrays[2] = Int16Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Int16Array.of : Symbol(Int16ArrayConstructor.of, Decl(lib.d.ts, 3251, 30)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2977, 60), Decl(lib.d.ts, 3267, 11)) ->of : Symbol(Int16ArrayConstructor.of, Decl(lib.d.ts, 3251, 30)) +>Int16Array.of : Symbol(Int16ArrayConstructor.of, Decl(lib.d.ts, 3248, 30)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) +>of : Symbol(Int16ArrayConstructor.of, Decl(lib.d.ts, 3248, 30)) typedArrays[3] = Uint16Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Uint16Array.of : Symbol(Uint16ArrayConstructor.of, Decl(lib.d.ts, 3541, 30)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3267, 46), Decl(lib.d.ts, 3557, 11)) ->of : Symbol(Uint16ArrayConstructor.of, Decl(lib.d.ts, 3541, 30)) +>Uint16Array.of : Symbol(Uint16ArrayConstructor.of, Decl(lib.d.ts, 3538, 30)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) +>of : Symbol(Uint16ArrayConstructor.of, Decl(lib.d.ts, 3538, 30)) typedArrays[4] = Int32Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Int32Array.of : Symbol(Int32ArrayConstructor.of, Decl(lib.d.ts, 3831, 30)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3557, 48), Decl(lib.d.ts, 3847, 11)) ->of : Symbol(Int32ArrayConstructor.of, Decl(lib.d.ts, 3831, 30)) +>Int32Array.of : Symbol(Int32ArrayConstructor.of, Decl(lib.d.ts, 3828, 30)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) +>of : Symbol(Int32ArrayConstructor.of, Decl(lib.d.ts, 3828, 30)) typedArrays[5] = Uint32Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Uint32Array.of : Symbol(Uint32ArrayConstructor.of, Decl(lib.d.ts, 4121, 30)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3847, 46), Decl(lib.d.ts, 4137, 11)) ->of : Symbol(Uint32ArrayConstructor.of, Decl(lib.d.ts, 4121, 30)) +>Uint32Array.of : Symbol(Uint32ArrayConstructor.of, Decl(lib.d.ts, 4118, 30)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) +>of : Symbol(Uint32ArrayConstructor.of, Decl(lib.d.ts, 4118, 30)) typedArrays[6] = Float32Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Float32Array.of : Symbol(Float32ArrayConstructor.of, Decl(lib.d.ts, 4411, 30)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4137, 48), Decl(lib.d.ts, 4427, 11)) ->of : Symbol(Float32ArrayConstructor.of, Decl(lib.d.ts, 4411, 30)) +>Float32Array.of : Symbol(Float32ArrayConstructor.of, Decl(lib.d.ts, 4408, 30)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) +>of : Symbol(Float32ArrayConstructor.of, Decl(lib.d.ts, 4408, 30)) typedArrays[7] = Float64Array.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Float64Array.of : Symbol(Float64ArrayConstructor.of, Decl(lib.d.ts, 4701, 30)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4427, 50), Decl(lib.d.ts, 4717, 11)) ->of : Symbol(Float64ArrayConstructor.of, Decl(lib.d.ts, 4701, 30)) +>Float64Array.of : Symbol(Float64ArrayConstructor.of, Decl(lib.d.ts, 4698, 30)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) +>of : Symbol(Float64ArrayConstructor.of, Decl(lib.d.ts, 4698, 30)) typedArrays[8] = Uint8ClampedArray.of(1,2,3,4); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) ->Uint8ClampedArray.of : Symbol(Uint8ClampedArrayConstructor.of, Decl(lib.d.ts, 2961, 30)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2687, 46), Decl(lib.d.ts, 2977, 11)) ->of : Symbol(Uint8ClampedArrayConstructor.of, Decl(lib.d.ts, 2961, 30)) +>Uint8ClampedArray.of : Symbol(Uint8ClampedArrayConstructor.of, Decl(lib.d.ts, 2958, 30)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) +>of : Symbol(Uint8ClampedArrayConstructor.of, Decl(lib.d.ts, 2958, 30)) return typedArrays; >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 94, 7)) @@ -401,73 +401,73 @@ function CreateTypedArraysFromMapFn(obj:ArrayLike, mapFn: (n:number, v:n typedArrays[0] = Int8Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2387, 38)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2107, 42), Decl(lib.d.ts, 2397, 11)) ->from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2387, 38)) +>Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) +>from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[1] = Uint8Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2677, 39)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2397, 44), Decl(lib.d.ts, 2687, 11)) ->from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2677, 39)) +>Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) +>from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[2] = Int16Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3257, 39)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2977, 60), Decl(lib.d.ts, 3267, 11)) ->from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3257, 39)) +>Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) +>from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[3] = Uint16Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3547, 40)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3267, 46), Decl(lib.d.ts, 3557, 11)) ->from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3547, 40)) +>Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) +>from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[4] = Int32Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3837, 39)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3557, 48), Decl(lib.d.ts, 3847, 11)) ->from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3837, 39)) +>Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) +>from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[5] = Uint32Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4127, 40)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3847, 46), Decl(lib.d.ts, 4137, 11)) ->from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4127, 40)) +>Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) +>from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[6] = Float32Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4417, 41)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4137, 48), Decl(lib.d.ts, 4427, 11)) ->from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4417, 41)) +>Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) +>from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[7] = Float64Array.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4707, 41)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4427, 50), Decl(lib.d.ts, 4717, 11)) ->from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4707, 41)) +>Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) +>from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) typedArrays[8] = Uint8ClampedArray.from(obj, mapFn); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 109, 7)) ->Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2967, 46)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2687, 46), Decl(lib.d.ts, 2977, 11)) ->from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2967, 46)) +>Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) +>from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) >obj : Symbol(obj, Decl(typedArrays.ts, 108, 36)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 108, 58)) @@ -489,81 +489,81 @@ function CreateTypedArraysFromThisObj(obj:ArrayLike, mapFn: (n:number, v typedArrays[0] = Int8Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2387, 38)) ->Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2107, 42), Decl(lib.d.ts, 2397, 11)) ->from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2387, 38)) +>Int8Array.from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) +>Int8Array : Symbol(Int8Array, Decl(lib.d.ts, 2104, 42), Decl(lib.d.ts, 2394, 11)) +>from : Symbol(Int8ArrayConstructor.from, Decl(lib.d.ts, 2384, 38)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[1] = Uint8Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2677, 39)) ->Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2397, 44), Decl(lib.d.ts, 2687, 11)) ->from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2677, 39)) +>Uint8Array.from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) +>Uint8Array : Symbol(Uint8Array, Decl(lib.d.ts, 2394, 44), Decl(lib.d.ts, 2684, 11)) +>from : Symbol(Uint8ArrayConstructor.from, Decl(lib.d.ts, 2674, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[2] = Int16Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3257, 39)) ->Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2977, 60), Decl(lib.d.ts, 3267, 11)) ->from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3257, 39)) +>Int16Array.from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) +>Int16Array : Symbol(Int16Array, Decl(lib.d.ts, 2974, 60), Decl(lib.d.ts, 3264, 11)) +>from : Symbol(Int16ArrayConstructor.from, Decl(lib.d.ts, 3254, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[3] = Uint16Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3547, 40)) ->Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3267, 46), Decl(lib.d.ts, 3557, 11)) ->from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3547, 40)) +>Uint16Array.from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) +>Uint16Array : Symbol(Uint16Array, Decl(lib.d.ts, 3264, 46), Decl(lib.d.ts, 3554, 11)) +>from : Symbol(Uint16ArrayConstructor.from, Decl(lib.d.ts, 3544, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[4] = Int32Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3837, 39)) ->Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3557, 48), Decl(lib.d.ts, 3847, 11)) ->from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3837, 39)) +>Int32Array.from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) +>Int32Array : Symbol(Int32Array, Decl(lib.d.ts, 3554, 48), Decl(lib.d.ts, 3844, 11)) +>from : Symbol(Int32ArrayConstructor.from, Decl(lib.d.ts, 3834, 39)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[5] = Uint32Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4127, 40)) ->Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3847, 46), Decl(lib.d.ts, 4137, 11)) ->from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4127, 40)) +>Uint32Array.from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) +>Uint32Array : Symbol(Uint32Array, Decl(lib.d.ts, 3844, 46), Decl(lib.d.ts, 4134, 11)) +>from : Symbol(Uint32ArrayConstructor.from, Decl(lib.d.ts, 4124, 40)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[6] = Float32Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4417, 41)) ->Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4137, 48), Decl(lib.d.ts, 4427, 11)) ->from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4417, 41)) +>Float32Array.from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) +>Float32Array : Symbol(Float32Array, Decl(lib.d.ts, 4134, 48), Decl(lib.d.ts, 4424, 11)) +>from : Symbol(Float32ArrayConstructor.from, Decl(lib.d.ts, 4414, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[7] = Float64Array.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4707, 41)) ->Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4427, 50), Decl(lib.d.ts, 4717, 11)) ->from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4707, 41)) +>Float64Array.from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) +>Float64Array : Symbol(Float64Array, Decl(lib.d.ts, 4424, 50), Decl(lib.d.ts, 4714, 11)) +>from : Symbol(Float64ArrayConstructor.from, Decl(lib.d.ts, 4704, 41)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) typedArrays[8] = Uint8ClampedArray.from(obj, mapFn, thisArg); >typedArrays : Symbol(typedArrays, Decl(typedArrays.ts, 124, 7)) ->Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2967, 46)) ->Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2687, 46), Decl(lib.d.ts, 2977, 11)) ->from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2967, 46)) +>Uint8ClampedArray.from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) +>Uint8ClampedArray : Symbol(Uint8ClampedArray, Decl(lib.d.ts, 2684, 46), Decl(lib.d.ts, 2974, 11)) +>from : Symbol(Uint8ClampedArrayConstructor.from, Decl(lib.d.ts, 2964, 46)) >obj : Symbol(obj, Decl(typedArrays.ts, 123, 38)) >mapFn : Symbol(mapFn, Decl(typedArrays.ts, 123, 60)) >thisArg : Symbol(thisArg, Decl(typedArrays.ts, 123, 98)) diff --git a/tests/baselines/reference/withStatementErrors.errors.txt b/tests/baselines/reference/withStatementErrors.errors.txt index ba399f5119..bfea39b542 100644 --- a/tests/baselines/reference/withStatementErrors.errors.txt +++ b/tests/baselines/reference/withStatementErrors.errors.txt @@ -1,5 +1,5 @@ tests/cases/compiler/withStatementErrors.ts(3,7): error TS2410: All symbols within a 'with' block will be resolved to 'any'. -tests/cases/compiler/withStatementErrors.ts(13,5): error TS1129: Statement expected. +tests/cases/compiler/withStatementErrors.ts(15,5): error TS1129: Statement expected. tests/cases/compiler/withStatementErrors.ts(17,1): error TS1128: Declaration or statement expected. @@ -19,10 +19,10 @@ tests/cases/compiler/withStatementErrors.ts(17,1): error TS1128: Declaration or class C {} // error interface I {} // error - ~~~~~~~~~ -!!! error TS1129: Statement expected. module M {} // error + ~~~~~~ +!!! error TS1129: Statement expected. } ~ diff --git a/tests/baselines/reference/withStatementErrors.js b/tests/baselines/reference/withStatementErrors.js index 43236c94d8..65b4599946 100644 --- a/tests/baselines/reference/withStatementErrors.js +++ b/tests/baselines/reference/withStatementErrors.js @@ -28,5 +28,5 @@ with (ooo.eee.oo.ah_ah.ting.tang.walla.walla) { function C() { } return C; - })(); -} // error + })(); // error +} // error diff --git a/tests/baselines/reference/yieldExpression1.errors.txt b/tests/baselines/reference/yieldExpression1.errors.txt index 91a379e617..8eefb9024d 100644 --- a/tests/baselines/reference/yieldExpression1.errors.txt +++ b/tests/baselines/reference/yieldExpression1.errors.txt @@ -1,12 +1,9 @@ -tests/cases/compiler/yieldExpression1.ts(1,9): error TS9001: Generators are not currently supported. -tests/cases/compiler/yieldExpression1.ts(2,5): error TS9000: 'yield' expressions are not currently supported. +tests/cases/compiler/yieldExpression1.ts(1,9): error TS1220: Generators are only available when targeting ECMAScript 6 or higher. -==== tests/cases/compiler/yieldExpression1.ts (2 errors) ==== +==== tests/cases/compiler/yieldExpression1.ts (1 errors) ==== function* foo() { ~ -!!! error TS9001: Generators are not currently supported. +!!! error TS1220: Generators are only available when targeting ECMAScript 6 or higher. yield - ~~~~~ -!!! error TS9000: 'yield' expressions are not currently supported. } \ No newline at end of file diff --git a/tests/cases/compiler/argumentsObjectIterator01_ES5.ts b/tests/cases/compiler/argumentsObjectIterator01_ES5.ts new file mode 100644 index 0000000000..1813eb9a16 --- /dev/null +++ b/tests/cases/compiler/argumentsObjectIterator01_ES5.ts @@ -0,0 +1,9 @@ +//@target: ES5 + +function doubleAndReturnAsArray(x: number, y: number, z: number): [number, number, number] { + let result = []; + for (let arg of arguments) { + result.push(arg + arg); + } + return <[any, any, any]>result; +} \ No newline at end of file diff --git a/tests/cases/compiler/argumentsObjectIterator01_ES6.ts b/tests/cases/compiler/argumentsObjectIterator01_ES6.ts new file mode 100644 index 0000000000..4e566affa3 --- /dev/null +++ b/tests/cases/compiler/argumentsObjectIterator01_ES6.ts @@ -0,0 +1,9 @@ +//@target: ES6 + +function doubleAndReturnAsArray(x: number, y: number, z: number): [number, number, number] { + let result = []; + for (let arg of arguments) { + result.push(arg + arg); + } + return <[any, any, any]>result; +} \ No newline at end of file diff --git a/tests/cases/compiler/argumentsObjectIterator02_ES5.ts b/tests/cases/compiler/argumentsObjectIterator02_ES5.ts new file mode 100644 index 0000000000..b348765827 --- /dev/null +++ b/tests/cases/compiler/argumentsObjectIterator02_ES5.ts @@ -0,0 +1,12 @@ +//@target: ES5 + +function doubleAndReturnAsArray(x: number, y: number, z: number): [number, number, number] { + let blah = arguments[Symbol.iterator]; + + let result = []; + for (let arg of blah()) { + result.push(arg + arg); + } + return <[any, any, any]>result; +} + diff --git a/tests/cases/compiler/argumentsObjectIterator02_ES6.ts b/tests/cases/compiler/argumentsObjectIterator02_ES6.ts new file mode 100644 index 0000000000..10d5b01cc6 --- /dev/null +++ b/tests/cases/compiler/argumentsObjectIterator02_ES6.ts @@ -0,0 +1,12 @@ +//@target: ES6 + +function doubleAndReturnAsArray(x: number, y: number, z: number): [number, number, number] { + let blah = arguments[Symbol.iterator]; + + let result = []; + for (let arg of blah()) { + result.push(arg + arg); + } + return <[any, any, any]>result; +} + diff --git a/tests/cases/compiler/argumentsObjectIterator03_ES5.ts b/tests/cases/compiler/argumentsObjectIterator03_ES5.ts new file mode 100644 index 0000000000..8059ca3aa2 --- /dev/null +++ b/tests/cases/compiler/argumentsObjectIterator03_ES5.ts @@ -0,0 +1,8 @@ +//@target: ES5 + +function asReversedTuple(a: number, b: string, c: boolean): [boolean, string, number] { + let [x, y, z] = arguments; + + return [z, y, x]; +} + diff --git a/tests/cases/compiler/argumentsObjectIterator03_ES6.ts b/tests/cases/compiler/argumentsObjectIterator03_ES6.ts new file mode 100644 index 0000000000..21b4988508 --- /dev/null +++ b/tests/cases/compiler/argumentsObjectIterator03_ES6.ts @@ -0,0 +1,8 @@ +//@target: ES6 + +function asReversedTuple(a: number, b: string, c: boolean): [boolean, string, number] { + let [x, y, z] = arguments; + + return [z, y, x]; +} + diff --git a/tests/cases/compiler/classExpressionWithDecorator1.ts b/tests/cases/compiler/classExpressionWithDecorator1.ts index 74b49456a3..67e9c8aa6c 100644 --- a/tests/cases/compiler/classExpressionWithDecorator1.ts +++ b/tests/cases/compiler/classExpressionWithDecorator1.ts @@ -1 +1,2 @@ +// @experimentaldecorators: true var v = @decorate class C { static p = 1 }; \ No newline at end of file diff --git a/tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts b/tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts new file mode 100644 index 0000000000..ce44c2bca4 --- /dev/null +++ b/tests/cases/compiler/classExpressionWithResolutionOfNamespaceOfSameName01.ts @@ -0,0 +1,8 @@ +namespace C { + export interface type { + } +} + +var x = class C { + prop: C.type; +} \ No newline at end of file diff --git a/tests/cases/compiler/cyclicGenericTypeInstantiation.ts b/tests/cases/compiler/cyclicGenericTypeInstantiation.ts new file mode 100644 index 0000000000..070cc44a63 --- /dev/null +++ b/tests/cases/compiler/cyclicGenericTypeInstantiation.ts @@ -0,0 +1,20 @@ +function foo() { + var z = foo(); + var y: { + y2: typeof z + }; + return y; +} + + +function bar() { + var z = bar(); + var y: { + y2: typeof z; + } + return y; +} + +var a = foo(); +var b = bar(); +a = b; diff --git a/tests/cases/compiler/cyclicTypeInstantiation.ts b/tests/cases/compiler/cyclicTypeInstantiation.ts new file mode 100644 index 0000000000..79a222df08 --- /dev/null +++ b/tests/cases/compiler/cyclicTypeInstantiation.ts @@ -0,0 +1,20 @@ +function foo() { + var x: { + a: T; + b: typeof x; + }; + return x; +} + +function bar() { + var x: { + a: T; + b: typeof x; + }; + return x; +} + +var a = foo(); +var b = bar(); +// Relating types of a and b produces instantiations of the cyclic anonymous types in foo and bar +a = b; diff --git a/tests/cases/compiler/declareModifierOnTypeAlias.ts b/tests/cases/compiler/declareModifierOnTypeAlias.ts new file mode 100644 index 0000000000..0dd23f7eda --- /dev/null +++ b/tests/cases/compiler/declareModifierOnTypeAlias.ts @@ -0,0 +1,3 @@ +declare type Foo = string; +type Bar = number; +declare type Baz = Bar; \ No newline at end of file diff --git a/tests/cases/compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts b/tests/cases/compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts new file mode 100644 index 0000000000..b9ceeb4740 --- /dev/null +++ b/tests/cases/compiler/functionDeclarationWithResolutionOfTypeNamedArguments01.ts @@ -0,0 +1,6 @@ +interface arguments { +} + +function f() { + arguments; +} \ No newline at end of file diff --git a/tests/cases/compiler/functionDeclarationWithResolutionOfTypeOfSameName01.ts b/tests/cases/compiler/functionDeclarationWithResolutionOfTypeOfSameName01.ts new file mode 100644 index 0000000000..9dc0bf8694 --- /dev/null +++ b/tests/cases/compiler/functionDeclarationWithResolutionOfTypeOfSameName01.ts @@ -0,0 +1,6 @@ +interface f { +} + +function f() { + f; +} \ No newline at end of file diff --git a/tests/cases/compiler/functionExpressionWithResolutionOfTypeNamedArguments01.ts b/tests/cases/compiler/functionExpressionWithResolutionOfTypeNamedArguments01.ts new file mode 100644 index 0000000000..c1b99ee8f0 --- /dev/null +++ b/tests/cases/compiler/functionExpressionWithResolutionOfTypeNamedArguments01.ts @@ -0,0 +1,6 @@ +interface arguments { +} + +var x = function f() { + arguments; +} \ No newline at end of file diff --git a/tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName01.ts b/tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName01.ts new file mode 100644 index 0000000000..de4d0e3bb9 --- /dev/null +++ b/tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName01.ts @@ -0,0 +1,6 @@ +interface f { +} + +var x = function f() { + f; +} \ No newline at end of file diff --git a/tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName02.ts b/tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName02.ts new file mode 100644 index 0000000000..041195271f --- /dev/null +++ b/tests/cases/compiler/functionExpressionWithResolutionOfTypeOfSameName02.ts @@ -0,0 +1,6 @@ +interface Foo { +} + +var x = function Foo() { + var x: Foo; +} \ No newline at end of file diff --git a/tests/cases/compiler/inferentialTypingObjectLiteralMethod1.ts b/tests/cases/compiler/inferentialTypingObjectLiteralMethod1.ts new file mode 100644 index 0000000000..85b66f9219 --- /dev/null +++ b/tests/cases/compiler/inferentialTypingObjectLiteralMethod1.ts @@ -0,0 +1,5 @@ +interface Int { + method(x: T): U; +} +declare function foo(x: T, y: Int, z: Int): T; +foo("", { method(p1) { return p1.length } }, { method(p2) { return undefined } }); \ No newline at end of file diff --git a/tests/cases/compiler/inferentialTypingObjectLiteralMethod2.ts b/tests/cases/compiler/inferentialTypingObjectLiteralMethod2.ts new file mode 100644 index 0000000000..dee3db70c2 --- /dev/null +++ b/tests/cases/compiler/inferentialTypingObjectLiteralMethod2.ts @@ -0,0 +1,5 @@ +interface Int { + [s: string]: (x: T) => U; +} +declare function foo(x: T, y: Int, z: Int): T; +foo("", { method(p1) { return p1.length } }, { method(p2) { return undefined } }); \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationAmbientConstEnum.ts b/tests/cases/compiler/isolatedModulesAmbientConstEnum.ts similarity index 70% rename from tests/cases/compiler/separateCompilationAmbientConstEnum.ts rename to tests/cases/compiler/isolatedModulesAmbientConstEnum.ts index aaccfaaf02..59fcdcd1fe 100644 --- a/tests/cases/compiler/separateCompilationAmbientConstEnum.ts +++ b/tests/cases/compiler/isolatedModulesAmbientConstEnum.ts @@ -1,4 +1,4 @@ -// @separateCompilation: true +// @isolatedModules: true // @target: es6 // @filename: file1.ts diff --git a/tests/cases/compiler/separateCompilationDeclaration.ts b/tests/cases/compiler/isolatedModulesDeclaration.ts similarity index 68% rename from tests/cases/compiler/separateCompilationDeclaration.ts rename to tests/cases/compiler/isolatedModulesDeclaration.ts index 11003a1919..3d5e7db9b4 100644 --- a/tests/cases/compiler/separateCompilationDeclaration.ts +++ b/tests/cases/compiler/isolatedModulesDeclaration.ts @@ -1,4 +1,4 @@ -// @separateCompilation: true +// @isolatedModules: true // @declaration: true // @target: es6 diff --git a/tests/cases/compiler/separateCompilationES6.ts b/tests/cases/compiler/isolatedModulesES6.ts similarity index 61% rename from tests/cases/compiler/separateCompilationES6.ts rename to tests/cases/compiler/isolatedModulesES6.ts index a2ac8c8d94..12e8d8adb7 100644 --- a/tests/cases/compiler/separateCompilationES6.ts +++ b/tests/cases/compiler/isolatedModulesES6.ts @@ -1,4 +1,4 @@ -// @separateCompilation: true +// @isolatedModules: true // @target: es6 // @filename: file1.ts export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationImportExportElision.ts b/tests/cases/compiler/isolatedModulesImportExportElision.ts similarity index 84% rename from tests/cases/compiler/separateCompilationImportExportElision.ts rename to tests/cases/compiler/isolatedModulesImportExportElision.ts index d7af74a1a6..e50a0f8eb8 100644 --- a/tests/cases/compiler/separateCompilationImportExportElision.ts +++ b/tests/cases/compiler/isolatedModulesImportExportElision.ts @@ -1,4 +1,4 @@ -// @separateCompilation: true +// @isolatedModules: true // @target: es5 // @module: commonjs diff --git a/tests/cases/compiler/separateCompilationNoEmitOnError.ts b/tests/cases/compiler/isolatedModulesNoEmitOnError.ts similarity index 68% rename from tests/cases/compiler/separateCompilationNoEmitOnError.ts rename to tests/cases/compiler/isolatedModulesNoEmitOnError.ts index fe0f59199f..ce3085dbc3 100644 --- a/tests/cases/compiler/separateCompilationNoEmitOnError.ts +++ b/tests/cases/compiler/isolatedModulesNoEmitOnError.ts @@ -1,4 +1,4 @@ -// @separateCompilation: true +// @isolatedModules: true // @noEmitOnError:true // @target: es6 diff --git a/tests/cases/compiler/separateCompilationNoExternalModule.ts b/tests/cases/compiler/isolatedModulesNoExternalModule.ts similarity index 57% rename from tests/cases/compiler/separateCompilationNoExternalModule.ts rename to tests/cases/compiler/isolatedModulesNoExternalModule.ts index e66ef27c00..37b61fcbc1 100644 --- a/tests/cases/compiler/separateCompilationNoExternalModule.ts +++ b/tests/cases/compiler/isolatedModulesNoExternalModule.ts @@ -1,4 +1,4 @@ -// @separateCompilation: true +// @isolatedModules: true // @target: es6 // @filename: file1.ts diff --git a/tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts b/tests/cases/compiler/isolatedModulesNonAmbientConstEnum.ts similarity index 71% rename from tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts rename to tests/cases/compiler/isolatedModulesNonAmbientConstEnum.ts index 5f3054238d..d5aae618d8 100644 --- a/tests/cases/compiler/separateCompilationNonAmbientConstEnum.ts +++ b/tests/cases/compiler/isolatedModulesNonAmbientConstEnum.ts @@ -1,4 +1,4 @@ -// @separateCompilation: true +// @isolatedModules: true // @target: es6 // @filename: file1.ts diff --git a/tests/cases/compiler/separateCompilationOut.ts b/tests/cases/compiler/isolatedModulesOut.ts similarity index 72% rename from tests/cases/compiler/separateCompilationOut.ts rename to tests/cases/compiler/isolatedModulesOut.ts index 6c0a95f8ae..c977a4b54d 100644 --- a/tests/cases/compiler/separateCompilationOut.ts +++ b/tests/cases/compiler/isolatedModulesOut.ts @@ -1,4 +1,4 @@ -// @separateCompilation: true +// @isolatedModules: true // @out:all.js // @target: es6 diff --git a/tests/cases/compiler/separateCompilationPlainFile-AMD.ts b/tests/cases/compiler/isolatedModulesPlainFile-AMD.ts similarity index 68% rename from tests/cases/compiler/separateCompilationPlainFile-AMD.ts rename to tests/cases/compiler/isolatedModulesPlainFile-AMD.ts index a1010ce3e8..d28aea8625 100644 --- a/tests/cases/compiler/separateCompilationPlainFile-AMD.ts +++ b/tests/cases/compiler/isolatedModulesPlainFile-AMD.ts @@ -1,6 +1,6 @@ // @target: es5 // @module: amd -// @separateCompilation: true +// @isolatedModules: true declare function run(a: number): void; run(1); diff --git a/tests/cases/compiler/separateCompilationPlainFile-CommonJS.ts b/tests/cases/compiler/isolatedModulesPlainFile-CommonJS.ts similarity index 70% rename from tests/cases/compiler/separateCompilationPlainFile-CommonJS.ts rename to tests/cases/compiler/isolatedModulesPlainFile-CommonJS.ts index 532d97f09e..6d07f10c4d 100644 --- a/tests/cases/compiler/separateCompilationPlainFile-CommonJS.ts +++ b/tests/cases/compiler/isolatedModulesPlainFile-CommonJS.ts @@ -1,6 +1,6 @@ // @target: es5 // @module: commonjs -// @separateCompilation: true +// @isolatedModules: true declare function run(a: number): void; run(1); diff --git a/tests/cases/compiler/separateCompilationPlainFile-ES6.ts b/tests/cases/compiler/isolatedModulesPlainFile-ES6.ts similarity index 64% rename from tests/cases/compiler/separateCompilationPlainFile-ES6.ts rename to tests/cases/compiler/isolatedModulesPlainFile-ES6.ts index 20d4e8d79a..051aa54814 100644 --- a/tests/cases/compiler/separateCompilationPlainFile-ES6.ts +++ b/tests/cases/compiler/isolatedModulesPlainFile-ES6.ts @@ -1,5 +1,5 @@ // @target: es6 -// @separateCompilation: true +// @isolatedModules: true declare function run(a: number): void; run(1); diff --git a/tests/cases/compiler/separateCompilationPlainFile-System.ts b/tests/cases/compiler/isolatedModulesPlainFile-System.ts similarity index 69% rename from tests/cases/compiler/separateCompilationPlainFile-System.ts rename to tests/cases/compiler/isolatedModulesPlainFile-System.ts index 6906571825..e16720596d 100644 --- a/tests/cases/compiler/separateCompilationPlainFile-System.ts +++ b/tests/cases/compiler/isolatedModulesPlainFile-System.ts @@ -1,6 +1,6 @@ // @target: es5 // @module: system -// @separateCompilation: true +// @isolatedModules: true declare function run(a: number): void; run(1); diff --git a/tests/cases/compiler/separateCompilationPlainFile-UMD.ts b/tests/cases/compiler/isolatedModulesPlainFile-UMD.ts similarity index 68% rename from tests/cases/compiler/separateCompilationPlainFile-UMD.ts rename to tests/cases/compiler/isolatedModulesPlainFile-UMD.ts index 4ab45686c9..d452bbff96 100644 --- a/tests/cases/compiler/separateCompilationPlainFile-UMD.ts +++ b/tests/cases/compiler/isolatedModulesPlainFile-UMD.ts @@ -1,6 +1,6 @@ // @target: es5 // @module: umd -// @separateCompilation: true +// @isolatedModules: true declare function run(a: number): void; run(1); diff --git a/tests/cases/compiler/separateCompilationSourceMap.ts b/tests/cases/compiler/isolatedModulesSourceMap.ts similarity index 67% rename from tests/cases/compiler/separateCompilationSourceMap.ts rename to tests/cases/compiler/isolatedModulesSourceMap.ts index 84c6290caf..31dd4d9f0c 100644 --- a/tests/cases/compiler/separateCompilationSourceMap.ts +++ b/tests/cases/compiler/isolatedModulesSourceMap.ts @@ -1,4 +1,4 @@ -// @separateCompilation: true +// @isolatedModules: true // @sourceMap:true // @target: es6 diff --git a/tests/cases/compiler/separateCompilationSpecifiedModule.ts b/tests/cases/compiler/isolatedModulesSpecifiedModule.ts similarity index 63% rename from tests/cases/compiler/separateCompilationSpecifiedModule.ts rename to tests/cases/compiler/isolatedModulesSpecifiedModule.ts index 6ba3a0d3bf..0e72e6480b 100644 --- a/tests/cases/compiler/separateCompilationSpecifiedModule.ts +++ b/tests/cases/compiler/isolatedModulesSpecifiedModule.ts @@ -1,4 +1,4 @@ -// @separateCompilation: true +// @isolatedModules: true // @module: commonjs // @filename: file1.ts export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationUnspecifiedModule.ts b/tests/cases/compiler/isolatedModulesUnspecifiedModule.ts similarity index 52% rename from tests/cases/compiler/separateCompilationUnspecifiedModule.ts rename to tests/cases/compiler/isolatedModulesUnspecifiedModule.ts index 38a3fd8286..2435f22e95 100644 --- a/tests/cases/compiler/separateCompilationUnspecifiedModule.ts +++ b/tests/cases/compiler/isolatedModulesUnspecifiedModule.ts @@ -1,3 +1,3 @@ -// @separateCompilation: true +// @isolatedModules: true // @filename: file1.ts export var x; \ No newline at end of file diff --git a/tests/cases/compiler/separateCompilationWithDeclarationFile.ts b/tests/cases/compiler/isolatedModulesWithDeclarationFile.ts similarity index 74% rename from tests/cases/compiler/separateCompilationWithDeclarationFile.ts rename to tests/cases/compiler/isolatedModulesWithDeclarationFile.ts index 121db1702a..01e96b4ec2 100644 --- a/tests/cases/compiler/separateCompilationWithDeclarationFile.ts +++ b/tests/cases/compiler/isolatedModulesWithDeclarationFile.ts @@ -1,4 +1,4 @@ -// @separateCompilation: true +// @isolatedModules: true // @target: es6 // @filename: file1.d.ts diff --git a/tests/cases/compiler/noEmitHelpers2.ts b/tests/cases/compiler/noEmitHelpers2.ts index df71f4fae8..ccc17f7066 100644 --- a/tests/cases/compiler/noEmitHelpers2.ts +++ b/tests/cases/compiler/noEmitHelpers2.ts @@ -1,4 +1,5 @@ // @noemithelpers: true +// @experimentaldecorators: true // @emitdecoratormetadata: true // @target: es5 diff --git a/tests/cases/compiler/sourceMapValidationDecorators.ts b/tests/cases/compiler/sourceMapValidationDecorators.ts index c8bd16be80..898d3f729b 100644 --- a/tests/cases/compiler/sourceMapValidationDecorators.ts +++ b/tests/cases/compiler/sourceMapValidationDecorators.ts @@ -1,5 +1,6 @@ // @sourcemap: true // @target: es5 +// @experimentaldecorators: true declare function ClassDecorator1(target: Function): void; declare function ClassDecorator2(x: number): (target: Function) => void; declare function PropertyDecorator1(target: Object, key: string | symbol, descriptor?: PropertyDescriptor): void; diff --git a/tests/cases/compiler/systemModule10.ts b/tests/cases/compiler/systemModule10.ts index 49e99fb1c6..41aea2c824 100644 --- a/tests/cases/compiler/systemModule10.ts +++ b/tests/cases/compiler/systemModule10.ts @@ -1,5 +1,5 @@ // @module: system -// @separateCompilation: true +// @isolatedModules: true import n, {x} from 'file1' import n2 = require('file2'); diff --git a/tests/cases/compiler/systemModule10_ES5.ts b/tests/cases/compiler/systemModule10_ES5.ts index 6468e4125d..5e51b9152f 100644 --- a/tests/cases/compiler/systemModule10_ES5.ts +++ b/tests/cases/compiler/systemModule10_ES5.ts @@ -1,6 +1,6 @@ // @target: es5 // @module: system -// @separateCompilation: true +// @isolatedModules: true import n, {x} from 'file1' import n2 = require('file2'); diff --git a/tests/cases/compiler/systemModule11.ts b/tests/cases/compiler/systemModule11.ts index 28e88688f8..15784b2f8c 100644 --- a/tests/cases/compiler/systemModule11.ts +++ b/tests/cases/compiler/systemModule11.ts @@ -1,5 +1,5 @@ // @module: system -// @separateCompilation: true +// @isolatedModules: true // set of tests cases that checks generation of local storage for exported names diff --git a/tests/cases/compiler/systemModule9.ts b/tests/cases/compiler/systemModule9.ts index c6ff742b1b..f124a1112c 100644 --- a/tests/cases/compiler/systemModule9.ts +++ b/tests/cases/compiler/systemModule9.ts @@ -1,5 +1,5 @@ // @module: system -// @separateCompilation: true +// @isolatedModules: true import * as ns from 'file1'; import {a, b as c} from 'file2'; diff --git a/tests/cases/compiler/systemModuleAmbientDeclarations.ts b/tests/cases/compiler/systemModuleAmbientDeclarations.ts index 05f7859278..690d0c65c1 100644 --- a/tests/cases/compiler/systemModuleAmbientDeclarations.ts +++ b/tests/cases/compiler/systemModuleAmbientDeclarations.ts @@ -1,5 +1,5 @@ // @module: system -// @separateCompilation: true +// @isolatedModules: true // @filename: file1.ts declare class Promise { } diff --git a/tests/cases/compiler/systemModuleConstEnumsSeparateCompilation.ts b/tests/cases/compiler/systemModuleConstEnumsSeparateCompilation.ts index 2fc4707b78..3813017639 100644 --- a/tests/cases/compiler/systemModuleConstEnumsSeparateCompilation.ts +++ b/tests/cases/compiler/systemModuleConstEnumsSeparateCompilation.ts @@ -1,5 +1,5 @@ // @module: system -// @separateCompilation: true +// @isolatedModules: true declare function use(a: any); const enum TopLevelConstEnum { X } diff --git a/tests/cases/compiler/systemModuleDeclarationMerging.ts b/tests/cases/compiler/systemModuleDeclarationMerging.ts index 45c59c5b5d..ae8b3a8dd0 100644 --- a/tests/cases/compiler/systemModuleDeclarationMerging.ts +++ b/tests/cases/compiler/systemModuleDeclarationMerging.ts @@ -1,5 +1,5 @@ // @module: system -// @separateCompilation: true +// @isolatedModules: true export function F() {} export module F { var x; } diff --git a/tests/cases/compiler/systemModuleNonTopLevelModuleMembers.ts b/tests/cases/compiler/systemModuleNonTopLevelModuleMembers.ts index 756d430a2d..b561797033 100644 --- a/tests/cases/compiler/systemModuleNonTopLevelModuleMembers.ts +++ b/tests/cases/compiler/systemModuleNonTopLevelModuleMembers.ts @@ -1,5 +1,5 @@ // @module: system -// @separateCompilation: true +// @isolatedModules: true export class TopLevelClass {} export module TopLevelModule {var v;} diff --git a/tests/cases/compiler/typeCheckObjectLiteralMethodBody.ts b/tests/cases/compiler/typeCheckObjectLiteralMethodBody.ts new file mode 100644 index 0000000000..316572466d --- /dev/null +++ b/tests/cases/compiler/typeCheckObjectLiteralMethodBody.ts @@ -0,0 +1,2 @@ +//@noImplicitAny: true +var foo = { bar() { return undefined } }; \ No newline at end of file diff --git a/tests/cases/compiler/typeCheckReturnExpression.ts b/tests/cases/compiler/typeCheckReturnExpression.ts new file mode 100644 index 0000000000..00f75912bd --- /dev/null +++ b/tests/cases/compiler/typeCheckReturnExpression.ts @@ -0,0 +1,2 @@ +//@noImplicitAny: true +var foo = () => undefined; \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor1.ts b/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor1.ts index 7e80e9e637..19abd8231d 100644 --- a/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor1.ts +++ b/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor1.ts @@ -1,4 +1,5 @@ // @target:es5 +// @experimentaldecorators: true declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { diff --git a/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor2.ts b/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor2.ts index bbe58e72eb..5250b42929 100644 --- a/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor2.ts +++ b/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor2.ts @@ -1,4 +1,5 @@ // @target:es5 +// @experimentaldecorators: true declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { diff --git a/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts b/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts index bd1ce41bb1..4d7ccc6a82 100644 --- a/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts +++ b/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor3.ts @@ -1,4 +1,5 @@ // @target:es5 +// @experimentaldecorators: true declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { diff --git a/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor4.ts b/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor4.ts index 72259e5d21..35c15ae7a6 100644 --- a/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor4.ts +++ b/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor4.ts @@ -1,4 +1,5 @@ // @target:es5 +// @experimentaldecorators: true declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { diff --git a/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor5.ts b/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor5.ts index ba5f82ab0c..b32dd98ed2 100644 --- a/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor5.ts +++ b/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor5.ts @@ -1,4 +1,5 @@ // @target:es5 +// @experimentaldecorators: true declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { diff --git a/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts b/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts index 686127858b..ffbd271362 100644 --- a/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts +++ b/tests/cases/conformance/decorators/class/accessor/decoratorOnClassAccessor6.ts @@ -1,4 +1,5 @@ // @target:es5 +// @experimentaldecorators: true declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { diff --git a/tests/cases/conformance/decorators/class/constructor/decoratorOnClassConstructor1.ts b/tests/cases/conformance/decorators/class/constructor/decoratorOnClassConstructor1.ts index 4a39536e30..b9ee929574 100644 --- a/tests/cases/conformance/decorators/class/constructor/decoratorOnClassConstructor1.ts +++ b/tests/cases/conformance/decorators/class/constructor/decoratorOnClassConstructor1.ts @@ -1,4 +1,5 @@ // @target:es5 +// @experimentaldecorators: true declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { diff --git a/tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter1.ts b/tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter1.ts index 3f4baabac7..dbfd38c789 100644 --- a/tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter1.ts +++ b/tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter1.ts @@ -1,4 +1,5 @@ // @target:es5 +// @experimentaldecorators: true declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; class C { diff --git a/tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts b/tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts index e58771fbeb..4e0373ff5d 100644 --- a/tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts +++ b/tests/cases/conformance/decorators/class/constructor/parameter/decoratorOnClassConstructorParameter4.ts @@ -1,4 +1,5 @@ // @target:es5 +// @experimentaldecorators: true declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; class C { diff --git a/tests/cases/conformance/decorators/class/decoratedClassFromExternalModule.ts b/tests/cases/conformance/decorators/class/decoratedClassFromExternalModule.ts index cb622265b4..95f8bf4ab9 100644 --- a/tests/cases/conformance/decorators/class/decoratedClassFromExternalModule.ts +++ b/tests/cases/conformance/decorators/class/decoratedClassFromExternalModule.ts @@ -1,4 +1,5 @@ // @target: es6 +// @experimentaldecorators: true // @Filename: decorated.ts function decorate() { } diff --git a/tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts b/tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts new file mode 100644 index 0000000000..b1cbd1a679 --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratorChecksFunctionBodies.ts @@ -0,0 +1,17 @@ +// @target:es5 +// @experimentaldecorators: true + +// from #2971 +function func(s: string): void { +} + +class A { + @(x => { + var a = 3; + func(a); + return x; + }) + m() { + + } +} \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/decoratorInstantiateModulesInFunctionBodies.ts b/tests/cases/conformance/decorators/class/decoratorInstantiateModulesInFunctionBodies.ts new file mode 100644 index 0000000000..9163ed0c38 --- /dev/null +++ b/tests/cases/conformance/decorators/class/decoratorInstantiateModulesInFunctionBodies.ts @@ -0,0 +1,23 @@ +// @target:es5 +// @module:commonjs +// @experimentaldecorators: true +// @filename: a.ts + +// from #3108 +export var test = 'abc'; + +// @filename: b.ts +import { test } from './a'; + +function filter(handler: any) { + return function (target: any) { + // ... + }; +} + +class Wat { + @filter(() => test == 'abc') + static whatever() { + // ... + } +} \ No newline at end of file diff --git a/tests/cases/conformance/decorators/class/decoratorOnClass1.ts b/tests/cases/conformance/decorators/class/decoratorOnClass1.ts index 1d3c87e7a6..c1a729f56f 100644 --- a/tests/cases/conformance/decorators/class/decoratorOnClass1.ts +++ b/tests/cases/conformance/decorators/class/decoratorOnClass1.ts @@ -1,4 +1,5 @@ // @target:es5 +// @experimentaldecorators: true declare function dec(target: T): T; @dec diff --git a/tests/cases/conformance/decorators/class/decoratorOnClass2.ts b/tests/cases/conformance/decorators/class/decoratorOnClass2.ts index c82b9fe04a..062ef39120 100644 --- a/tests/cases/conformance/decorators/class/decoratorOnClass2.ts +++ b/tests/cases/conformance/decorators/class/decoratorOnClass2.ts @@ -1,5 +1,6 @@ // @target:es5 // @module: commonjs +// @experimentaldecorators: true declare function dec(target: T): T; @dec diff --git a/tests/cases/conformance/decorators/class/decoratorOnClass3.ts b/tests/cases/conformance/decorators/class/decoratorOnClass3.ts index cf77838035..e410eaa1b0 100644 --- a/tests/cases/conformance/decorators/class/decoratorOnClass3.ts +++ b/tests/cases/conformance/decorators/class/decoratorOnClass3.ts @@ -1,5 +1,6 @@ // @target:es5 // @module: commonjs +// @experimentaldecorators: true declare function dec(target: T): T; export diff --git a/tests/cases/conformance/decorators/class/decoratorOnClass4.ts b/tests/cases/conformance/decorators/class/decoratorOnClass4.ts index e365df091f..bebf595a17 100644 --- a/tests/cases/conformance/decorators/class/decoratorOnClass4.ts +++ b/tests/cases/conformance/decorators/class/decoratorOnClass4.ts @@ -1,4 +1,5 @@ // @target:es5 +// @experimentaldecorators: true declare function dec(): (target: T) => T; @dec() diff --git a/tests/cases/conformance/decorators/class/decoratorOnClass5.ts b/tests/cases/conformance/decorators/class/decoratorOnClass5.ts index e365df091f..bebf595a17 100644 --- a/tests/cases/conformance/decorators/class/decoratorOnClass5.ts +++ b/tests/cases/conformance/decorators/class/decoratorOnClass5.ts @@ -1,4 +1,5 @@ // @target:es5 +// @experimentaldecorators: true declare function dec(): (target: T) => T; @dec() diff --git a/tests/cases/conformance/decorators/class/decoratorOnClass8.ts b/tests/cases/conformance/decorators/class/decoratorOnClass8.ts index a722796418..bade386a56 100644 --- a/tests/cases/conformance/decorators/class/decoratorOnClass8.ts +++ b/tests/cases/conformance/decorators/class/decoratorOnClass8.ts @@ -1,4 +1,5 @@ // @target:es5 +// @experimentaldecorators: true declare function dec(): (target: Function, paramIndex: number) => void; @dec() diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod1.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod1.ts index 7216be210f..418ace9a0d 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod1.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod1.ts @@ -1,4 +1,5 @@ // @target: ES5 +// @experimentaldecorators: true declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts index 03f75f1655..c4658cc640 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod10.ts @@ -1,4 +1,5 @@ // @target: ES5 +// @experimentaldecorators: true declare function dec(target: Function, paramIndex: number): void; class C { diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts index 6f80fa00bc..058f813488 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod11.ts @@ -1,4 +1,5 @@ // @target: ES5 +// @experimentaldecorators: true module M { class C { decorator(target: Object, key: string): void { } diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts index a9a2607c39..9af80e32c4 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod12.ts @@ -1,4 +1,5 @@ // @target: ES5 +// @experimentaldecorators: true module M { class S { decorator(target: Object, key: string): void { } diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts index df0b847e99..f41481d4ad 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod13.ts @@ -1,4 +1,5 @@ // @target: ES6 +// @experimentaldecorators: true declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; class C { diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod2.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod2.ts index 7b7f089e4d..8305ed1a44 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod2.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod2.ts @@ -1,4 +1,5 @@ // @target: ES5 +// @experimentaldecorators: true declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts index aa80151cf8..b951bd5c8c 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod3.ts @@ -1,4 +1,5 @@ // @target: ES5 +// @experimentaldecorators: true declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod4.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod4.ts index 92b35ae618..3d3ff2c878 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod4.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod4.ts @@ -1,4 +1,5 @@ // @target: ES6 +// @experimentaldecorators: true declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod5.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod5.ts index cd891b4231..d91d4331ce 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod5.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod5.ts @@ -1,4 +1,5 @@ // @target: ES6 +// @experimentaldecorators: true declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; class C { diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts index a1fa700589..b3cd6ee75d 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod6.ts @@ -1,4 +1,5 @@ // @target: ES6 +// @experimentaldecorators: true declare function dec(): (target: any, propertyKey: string, descriptor: TypedPropertyDescriptor) => TypedPropertyDescriptor; class C { diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod7.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod7.ts index 4bf86aa499..16915e9aaa 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod7.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod7.ts @@ -1,4 +1,5 @@ // @target: ES6 +// @experimentaldecorators: true declare function dec(target: any, propertyKey: string, descriptor: TypedPropertyDescriptor): TypedPropertyDescriptor; class C { diff --git a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod8.ts b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod8.ts index 9bd2c192c2..73f5880942 100644 --- a/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod8.ts +++ b/tests/cases/conformance/decorators/class/method/decoratorOnClassMethod8.ts @@ -1,4 +1,5 @@ // @target: ES5 +// @experimentaldecorators: true declare function dec(target: T): T; class C { diff --git a/tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter1.ts b/tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter1.ts index e525933fb6..18a7fff6dd 100644 --- a/tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter1.ts +++ b/tests/cases/conformance/decorators/class/method/parameter/decoratorOnClassMethodParameter1.ts @@ -1,4 +1,5 @@ // @target:es5 +// @experimentaldecorators: true declare function dec(target: Function, propertyKey: string | symbol, parameterIndex: number): void; class C { diff --git a/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty1.ts b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty1.ts index 0d8fd82225..026949fb5b 100644 --- a/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty1.ts +++ b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty1.ts @@ -1,4 +1,5 @@ // @target: ES5 +// @experimentaldecorators: true declare function dec(target: any, propertyKey: string): void; class C { diff --git a/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty10.ts b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty10.ts index 4be7703569..2b10c0aec0 100644 --- a/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty10.ts +++ b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty10.ts @@ -1,4 +1,5 @@ // @target: ES5 +// @experimentaldecorators: true declare function dec(): (target: any, propertyKey: string) => void; class C { diff --git a/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts index 60ea10189e..eb720b20df 100644 --- a/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts +++ b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty11.ts @@ -1,4 +1,5 @@ // @target: ES5 +// @experimentaldecorators: true declare function dec(): (target: any, propertyKey: string) => void; class C { diff --git a/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty2.ts b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty2.ts index dc2886e7db..01af3e6ee8 100644 --- a/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty2.ts +++ b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty2.ts @@ -1,4 +1,5 @@ // @target: ES5 +// @experimentaldecorators: true declare function dec(target: any, propertyKey: string): void; class C { diff --git a/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts index cf58b4b71e..55fd6fe93e 100644 --- a/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts +++ b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty3.ts @@ -1,4 +1,5 @@ // @target: ES5 +// @experimentaldecorators: true declare function dec(target: any, propertyKey: string): void; class C { diff --git a/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty6.ts b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty6.ts index 1dd184419a..412a592ece 100644 --- a/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty6.ts +++ b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty6.ts @@ -1,4 +1,5 @@ // @target: ES5 +// @experimentaldecorators: true declare function dec(target: Function): void; class C { diff --git a/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts index d82ca6eb2e..0e11e103ce 100644 --- a/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts +++ b/tests/cases/conformance/decorators/class/property/decoratorOnClassProperty7.ts @@ -1,4 +1,5 @@ // @target: ES5 +// @experimentaldecorators: true declare function dec(target: Function, propertyKey: string | symbol, paramIndex: number): void; class C { diff --git a/tests/cases/conformance/decorators/missingDecoratorType.ts b/tests/cases/conformance/decorators/missingDecoratorType.ts index 1407e00b7a..905edaf075 100644 --- a/tests/cases/conformance/decorators/missingDecoratorType.ts +++ b/tests/cases/conformance/decorators/missingDecoratorType.ts @@ -1,4 +1,5 @@ -// @target: ES5 +// @target: ES5 +// @experimentaldecorators: true // @noLib: true // @Filename: a.ts @@ -11,8 +12,7 @@ interface Function { } interface RegExp { } interface IArguments { } -// @Filename: b.ts -/// +// @Filename: b.ts declare var dec: any; @dec diff --git a/tests/cases/conformance/es6/yieldExpressions/YieldStarExpression1_es6.ts b/tests/cases/conformance/es6/yieldExpressions/YieldStarExpression1_es6.ts new file mode 100644 index 0000000000..d0b2a17243 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/YieldStarExpression1_es6.ts @@ -0,0 +1 @@ +yield * []; \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/YieldStarExpression2_es6.ts b/tests/cases/conformance/es6/yieldExpressions/YieldStarExpression2_es6.ts new file mode 100644 index 0000000000..9a618df4bd --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/YieldStarExpression2_es6.ts @@ -0,0 +1 @@ +yield *; \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/YieldStarExpression3_es6.ts b/tests/cases/conformance/es6/yieldExpressions/YieldStarExpression3_es6.ts new file mode 100644 index 0000000000..3384d609c1 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/YieldStarExpression3_es6.ts @@ -0,0 +1,3 @@ +function *g() { + yield *; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/YieldStarExpression4_es6.ts b/tests/cases/conformance/es6/yieldExpressions/YieldStarExpression4_es6.ts new file mode 100644 index 0000000000..4e652232e6 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/YieldStarExpression4_es6.ts @@ -0,0 +1,3 @@ +function *g() { + yield * []; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext1.ts b/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext1.ts new file mode 100644 index 0000000000..b4a3108fe3 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext1.ts @@ -0,0 +1,4 @@ +//@target: ES6 +declare class C { + *generator(): any; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext2.ts b/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext2.ts new file mode 100644 index 0000000000..f4d560c521 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext2.ts @@ -0,0 +1,4 @@ +//@target: ES6 +declare module M { + function *generator(): any; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext3.d.ts b/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext3.d.ts new file mode 100644 index 0000000000..b4a3108fe3 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext3.d.ts @@ -0,0 +1,4 @@ +//@target: ES6 +declare class C { + *generator(): any; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext4.d.ts b/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext4.d.ts new file mode 100644 index 0000000000..f4d560c521 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext4.d.ts @@ -0,0 +1,4 @@ +//@target: ES6 +declare module M { + function *generator(): any; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext5.ts b/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext5.ts new file mode 100644 index 0000000000..559b5e8dac --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext5.ts @@ -0,0 +1,5 @@ +//@target: ES6 +//@declaration: true +class C { + *generator(): any { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext6.ts b/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext6.ts new file mode 100644 index 0000000000..fb7c358f18 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorInAmbientContext6.ts @@ -0,0 +1,5 @@ +//@target: ES6 +//@declaration: true +module M { + export function *generator(): any { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorOverloads1.ts b/tests/cases/conformance/es6/yieldExpressions/generatorOverloads1.ts new file mode 100644 index 0000000000..c21ecea782 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorOverloads1.ts @@ -0,0 +1,6 @@ +//@target: ES6 +module M { + function* f(s: string): Iterable; + function* f(s: number): Iterable; + function* f(s: any): Iterable { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts b/tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts new file mode 100644 index 0000000000..de362aedc8 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorOverloads2.ts @@ -0,0 +1,6 @@ +//@target: ES6 +declare module M { + function* f(s: string): Iterable; + function* f(s: number): Iterable; + function* f(s: any): Iterable; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts b/tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts new file mode 100644 index 0000000000..6f48257324 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorOverloads3.ts @@ -0,0 +1,6 @@ +//@target: ES6 +class C { + *f(s: string): Iterable; + *f(s: number): Iterable; + *f(s: any): Iterable { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorOverloads4.ts b/tests/cases/conformance/es6/yieldExpressions/generatorOverloads4.ts new file mode 100644 index 0000000000..7342a49a36 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorOverloads4.ts @@ -0,0 +1,6 @@ +//@target: ES6 +class C { + f(s: string): Iterable; + f(s: number): Iterable; + *f(s: any): Iterable { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorOverloads5.ts b/tests/cases/conformance/es6/yieldExpressions/generatorOverloads5.ts new file mode 100644 index 0000000000..1efa9af083 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorOverloads5.ts @@ -0,0 +1,6 @@ +//@target: ES6 +module M { + function f(s: string): Iterable; + function f(s: number): Iterable; + function* f(s: any): Iterable { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck1.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck1.ts new file mode 100644 index 0000000000..c01d7f5340 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck1.ts @@ -0,0 +1,2 @@ +//@target: ES6 +function* g1(): Iterator { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck10.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck10.ts new file mode 100644 index 0000000000..813ea07075 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck10.ts @@ -0,0 +1,4 @@ +//@target: ES6 +function* g(): IterableIterator { + return; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck11.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck11.ts new file mode 100644 index 0000000000..e77ec3d911 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck11.ts @@ -0,0 +1,4 @@ +//@target: ES6 +function* g(): IterableIterator { + return 0; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck12.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck12.ts new file mode 100644 index 0000000000..6f602a2398 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck12.ts @@ -0,0 +1,4 @@ +//@target: ES6 +function* g(): IterableIterator { + return ""; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck13.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck13.ts new file mode 100644 index 0000000000..a21d9e8ab6 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck13.ts @@ -0,0 +1,5 @@ +//@target: ES6 +function* g(): IterableIterator { + yield 0; + return ""; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck14.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck14.ts new file mode 100644 index 0000000000..74761b1477 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck14.ts @@ -0,0 +1,5 @@ +//@target: ES6 +function* g() { + yield 0; + return ""; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck15.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck15.ts new file mode 100644 index 0000000000..b810a13aa5 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck15.ts @@ -0,0 +1,4 @@ +//@target: ES6 +function* g() { + return ""; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck16.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck16.ts new file mode 100644 index 0000000000..06d3de394e --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck16.ts @@ -0,0 +1,4 @@ +//@target: ES6 +function* g() { + return; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck17.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck17.ts new file mode 100644 index 0000000000..15d760b794 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck17.ts @@ -0,0 +1,7 @@ +//@target: ES6 +class Foo { x: number } +class Bar extends Foo { y: string } +function* g(): IterableIterator { + yield; + yield new Bar; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck18.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck18.ts new file mode 100644 index 0000000000..d63e69d1b8 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck18.ts @@ -0,0 +1,7 @@ +//@target: ES6 +class Foo { x: number } +class Baz { z: number } +function* g(): IterableIterator { + yield; + yield new Baz; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck19.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck19.ts new file mode 100644 index 0000000000..e9b2cc29b2 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck19.ts @@ -0,0 +1,7 @@ +//@target: ES6 +class Foo { x: number } +class Bar extends Foo { y: string } +function* g(): IterableIterator { + yield; + yield * [new Bar]; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck2.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck2.ts new file mode 100644 index 0000000000..b66b3aab35 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck2.ts @@ -0,0 +1,2 @@ +//@target: ES6 +function* g1(): Iterable { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck20.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck20.ts new file mode 100644 index 0000000000..5cb029205d --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck20.ts @@ -0,0 +1,7 @@ +//@target: ES6 +class Foo { x: number } +class Baz { z: number } +function* g(): IterableIterator { + yield; + yield * [new Baz]; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck21.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck21.ts new file mode 100644 index 0000000000..991f082141 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck21.ts @@ -0,0 +1,7 @@ +//@target: ES6 +class Foo { x: number } +class Bar extends Foo { y: string } +function* g(): IterableIterator { + yield; + yield * new Bar; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck22.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck22.ts new file mode 100644 index 0000000000..0359ba3c4c --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck22.ts @@ -0,0 +1,11 @@ +//@target: ES6 +class Foo { x: number } +class Bar extends Foo { y: string } +class Baz { z: number } +function* g3() { + yield; + yield new Bar; + yield new Baz; + yield *[new Bar]; + yield *[new Baz]; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck23.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck23.ts new file mode 100644 index 0000000000..20c98e9e7e --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck23.ts @@ -0,0 +1,12 @@ +//@target: ES6 +class Foo { x: number } +class Bar extends Foo { y: string } +class Baz { z: number } +function* g3() { + yield; + yield new Foo; + yield new Bar; + yield new Baz; + yield *[new Bar]; + yield *[new Baz]; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck24.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck24.ts new file mode 100644 index 0000000000..9b383d8a02 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck24.ts @@ -0,0 +1,12 @@ +//@target: ES6 +class Foo { x: number } +class Bar extends Foo { y: string } +class Baz { z: number } +function* g3() { + yield; + yield * [new Foo]; + yield new Bar; + yield new Baz; + yield *[new Bar]; + yield *[new Baz]; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck25.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck25.ts new file mode 100644 index 0000000000..9a942f174a --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck25.ts @@ -0,0 +1,11 @@ +//@target: ES6 +class Foo { x: number } +class Bar extends Foo { y: string } +class Baz { z: number } +var g3: () => Iterable = function* () { + yield; + yield new Bar; + yield new Baz; + yield *[new Bar]; + yield *[new Baz]; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck26.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck26.ts new file mode 100644 index 0000000000..334d21e383 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck26.ts @@ -0,0 +1,6 @@ +//@target: ES6 +function* g(): IterableIterator<(x: string) => number> { + yield x => x.length; + yield *[x => x.length]; + return x => x.length; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck27.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck27.ts new file mode 100644 index 0000000000..f501aa407f --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck27.ts @@ -0,0 +1,6 @@ +//@target: ES6 +function* g(): IterableIterator<(x: string) => number> { + yield * function* () { + yield x => x.length; + } (); +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck28.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck28.ts new file mode 100644 index 0000000000..7a190e5bd4 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck28.ts @@ -0,0 +1,8 @@ +//@target: ES6 +function* g(): IterableIterator<(x: string) => number> { + yield * { + *[Symbol.iterator]() { + yield x => x.length; + } + }; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck29.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck29.ts new file mode 100644 index 0000000000..be99cf0244 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck29.ts @@ -0,0 +1,6 @@ +//@target: ES6 +function* g2(): Iterator number>> { + yield function* () { + yield x => x.length; + } () +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck3.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck3.ts new file mode 100644 index 0000000000..9b0e6f5ef5 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck3.ts @@ -0,0 +1,2 @@ +//@target: ES6 +function* g1(): IterableIterator { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck30.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck30.ts new file mode 100644 index 0000000000..be99cf0244 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck30.ts @@ -0,0 +1,6 @@ +//@target: ES6 +function* g2(): Iterator number>> { + yield function* () { + yield x => x.length; + } () +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts new file mode 100644 index 0000000000..f4082f7b46 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck31.ts @@ -0,0 +1,6 @@ +//@target: ES6 +function* g2(): Iterator<() => Iterable<(x: string) => number>> { + yield function* () { + yield x => x.length; + } () +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck32.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck32.ts new file mode 100644 index 0000000000..f975eefa84 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck32.ts @@ -0,0 +1,3 @@ +//@target: ES6 +var s: string; +var f: () => number = () => yield s; \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck33.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck33.ts new file mode 100644 index 0000000000..4bb9426383 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck33.ts @@ -0,0 +1,7 @@ +//@target: ES6 +function* g() { + yield 0; + function* g2() { + yield ""; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck34.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck34.ts new file mode 100644 index 0000000000..3afd5617a0 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck34.ts @@ -0,0 +1,7 @@ +//@target: ES6 +function* g() { + yield 0; + function* g2() { + return ""; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck35.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck35.ts new file mode 100644 index 0000000000..9adab4c0ed --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck35.ts @@ -0,0 +1,7 @@ +//@target: ES6 +function* g() { + yield 0; + function g2() { + return ""; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck36.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck36.ts new file mode 100644 index 0000000000..e304dda482 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck36.ts @@ -0,0 +1,4 @@ +//@target: ES6 +function* g() { + yield yield 0; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck37.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck37.ts new file mode 100644 index 0000000000..f9fe46f428 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck37.ts @@ -0,0 +1,4 @@ +//@target: ES6 +function* g() { + return yield yield 0; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck38.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck38.ts new file mode 100644 index 0000000000..03bb28ef0e --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck38.ts @@ -0,0 +1,6 @@ +//@target: ES6 +var yield; +function* g() { + yield 0; + var v: typeof yield; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts new file mode 100644 index 0000000000..b578f8f239 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck39.ts @@ -0,0 +1,10 @@ +//@target: ES6 +function decorator(x: any) { + return y => { }; +} +function* g() { + @decorator(yield 0) + class C { + x = yield 0; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck4.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck4.ts new file mode 100644 index 0000000000..160aee0d70 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck4.ts @@ -0,0 +1,2 @@ +//@target: ES6 +function* g1(): {} { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck40.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck40.ts new file mode 100644 index 0000000000..2dee3dedf0 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck40.ts @@ -0,0 +1,4 @@ +//@target: ES6 +function* g() { + class C extends (yield 0) { } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck41.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck41.ts new file mode 100644 index 0000000000..caa4eed074 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck41.ts @@ -0,0 +1,6 @@ +//@target: ES6 +function* g() { + let x = { + [yield 0]: 0 + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck42.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck42.ts new file mode 100644 index 0000000000..4fe9ddced9 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck42.ts @@ -0,0 +1,8 @@ +//@target: ES6 +function* g() { + let x = { + [yield 0]() { + + } + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck43.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck43.ts new file mode 100644 index 0000000000..e2b72f4b79 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck43.ts @@ -0,0 +1,8 @@ +//@target: ES6 +function* g() { + let x = { + *[yield 0]() { + + } + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck44.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck44.ts new file mode 100644 index 0000000000..e7146fa691 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck44.ts @@ -0,0 +1,8 @@ +//@target: ES6 +function* g() { + let x = { + get [yield 0]() { + return 0; + } + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck45.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck45.ts new file mode 100644 index 0000000000..ce0822da41 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck45.ts @@ -0,0 +1,4 @@ +//@target: ES6 +declare function foo(x: T, fun: () => Iterator<(x: T) => U>, fun2: (y: U) => T): T; + +foo("", function* () { yield x => x.length }, p => undefined); // T is fixed, should be string \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck46.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck46.ts new file mode 100644 index 0000000000..53c5c7131d --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck46.ts @@ -0,0 +1,10 @@ +//@target: ES6 +declare function foo(x: T, fun: () => Iterable<(x: T) => U>, fun2: (y: U) => T): T; + +foo("", function* () { + yield* { + *[Symbol.iterator]() { + yield x => x.length + } + } +}, p => undefined); // T is fixed, should be string \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck47.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck47.ts new file mode 100644 index 0000000000..6eb9fa74a6 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck47.ts @@ -0,0 +1,4 @@ +//@target: ES6 +//@noImplicitAny: true + +function* g() { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts new file mode 100644 index 0000000000..65885f28a5 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck48.ts @@ -0,0 +1,6 @@ +//@target: ES6 +//@noImplicitAny: true + +function* g() { + yield; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck49.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck49.ts new file mode 100644 index 0000000000..956704d8a4 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck49.ts @@ -0,0 +1,6 @@ +//@target: ES6 +//@noImplicitAny: true + +function* g() { + yield 0; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck5.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck5.ts new file mode 100644 index 0000000000..c1b659604b --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck5.ts @@ -0,0 +1,2 @@ +//@target: ES6 +function* g1(): any { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck50.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck50.ts new file mode 100644 index 0000000000..1261d4b268 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck50.ts @@ -0,0 +1,6 @@ +//@target: ES6 +//@noImplicitAny: true + +function* g() { + yield yield; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck51.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck51.ts new file mode 100644 index 0000000000..be88b9b99a --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck51.ts @@ -0,0 +1,8 @@ +//@target: ES6 +//@noImplicitAny: true + +function* g() { + function* h() { + yield 0; + } +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck52.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck52.ts new file mode 100644 index 0000000000..4e985dca92 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck52.ts @@ -0,0 +1,7 @@ +//@target: ES6 +class Foo { x: number } +class Baz { z: number } +function* g() { + yield new Foo; + yield new Baz; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck53.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck53.ts new file mode 100644 index 0000000000..9c75afe9ef --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck53.ts @@ -0,0 +1,7 @@ +//@target: ES6 +class Foo { x: number } +class Baz { z: number } +function* g() { + yield new Foo; + yield* [new Baz]; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck54.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck54.ts new file mode 100644 index 0000000000..b5f47f76b3 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck54.ts @@ -0,0 +1,7 @@ +//@target: ES6 +class Foo { x: number } +class Baz { z: number } +function* g() { + yield* [new Foo]; + yield* [new Baz]; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck55.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck55.ts new file mode 100644 index 0000000000..2041764a2f --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck55.ts @@ -0,0 +1,4 @@ +//@target: ES6 +function* g() { + var x = class C extends (yield) {}; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck56.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck56.ts new file mode 100644 index 0000000000..7aa66480a1 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck56.ts @@ -0,0 +1,8 @@ +//@target: ES6 +function* g() { + var x = class C { + *[yield 0]() { + yield 0; + } + }; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck57.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck57.ts new file mode 100644 index 0000000000..f972a2a60e --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck57.ts @@ -0,0 +1,6 @@ +//@target: ES6 +function* g() { + class C { + x = yield 0; + }; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck58.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck58.ts new file mode 100644 index 0000000000..081979be50 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck58.ts @@ -0,0 +1,6 @@ +//@target: ES6 +function* g() { + class C { + static x = yield 0; + }; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts new file mode 100644 index 0000000000..81aacecd7a --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck59.ts @@ -0,0 +1,7 @@ +//@target: ES6 +function* g() { + class C { + @(yield "") + m() { } + }; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck6.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck6.ts new file mode 100644 index 0000000000..8f61f87db8 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck6.ts @@ -0,0 +1,2 @@ +//@target: ES6 +function* g1(): number { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck60.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck60.ts new file mode 100644 index 0000000000..36747936f1 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck60.ts @@ -0,0 +1,4 @@ +//@target: ES6 +function* g() { + class C extends (yield) {}; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts new file mode 100644 index 0000000000..31c36e2a62 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck61.ts @@ -0,0 +1,5 @@ +//@target: ES6 +function * g() { + @(yield 0) + class C {}; +} \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck7.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck7.ts new file mode 100644 index 0000000000..59e9b489d5 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck7.ts @@ -0,0 +1,5 @@ +//@target: ES6 +interface WeirdIter extends IterableIterator { + hello: string; +} +function* g1(): WeirdIter { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck8.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck8.ts new file mode 100644 index 0000000000..659406ee99 --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck8.ts @@ -0,0 +1,3 @@ +//@target: ES6 +interface BadGenerator extends Iterator, Iterable { } +function* g3(): BadGenerator { } \ No newline at end of file diff --git a/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck9.ts b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck9.ts new file mode 100644 index 0000000000..f4386c70fe --- /dev/null +++ b/tests/cases/conformance/es6/yieldExpressions/generatorTypeCheck9.ts @@ -0,0 +1,2 @@ +//@target: ES6 +function* g3(): void { } \ No newline at end of file diff --git a/tests/cases/conformance/expressions/functionCalls/callWithSpread.ts b/tests/cases/conformance/expressions/functionCalls/callWithSpread.ts index 9acba00697..245028db3d 100644 --- a/tests/cases/conformance/expressions/functionCalls/callWithSpread.ts +++ b/tests/cases/conformance/expressions/functionCalls/callWithSpread.ts @@ -47,6 +47,3 @@ class D extends C { super.foo(1, 2, ...a); } } - -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); diff --git a/tests/cases/conformance/expressions/functionCalls/callWithSpreadES6.ts b/tests/cases/conformance/expressions/functionCalls/callWithSpreadES6.ts index 2f7d16ba36..accb6df135 100644 --- a/tests/cases/conformance/expressions/functionCalls/callWithSpreadES6.ts +++ b/tests/cases/conformance/expressions/functionCalls/callWithSpreadES6.ts @@ -49,6 +49,3 @@ class D extends C { super.foo(1, 2, ...a); } } - -// Only supported in when target is ES6 -var c = new C(1, 2, ...a); diff --git a/tests/cases/conformance/expressions/functionCalls/newWithSpread.ts b/tests/cases/conformance/expressions/functionCalls/newWithSpread.ts new file mode 100644 index 0000000000..d17919a703 --- /dev/null +++ b/tests/cases/conformance/expressions/functionCalls/newWithSpread.ts @@ -0,0 +1,97 @@ + +function f(x: number, y: number, ...z: string[]) { +} + +function f2(...x: string[]) { +} + +interface A { + f: { + new (x: number, y: number, ...z: string[]); + } +} + +class B { + constructor(x: number, y: number, ...z: string[]) {} +} + +interface C { + "a-b": typeof B; +} + +interface D { + 1: typeof B; +} + +var a: string[]; +var b: A; +var c: C; +var d: A[]; +var e: { [key: string]: A }; +var g: C[]; +var h: { [key: string]: C }; +var i: C[][]; + +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); + +// Multiple spreads arguments +new f2(...a, ...a); +new f(1 ,2, ...a, ...a); + +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); + +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); + +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); + +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); + +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); + +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); \ No newline at end of file diff --git a/tests/cases/conformance/expressions/functionCalls/newWithSpreadES5.ts b/tests/cases/conformance/expressions/functionCalls/newWithSpreadES5.ts new file mode 100644 index 0000000000..25ef344466 --- /dev/null +++ b/tests/cases/conformance/expressions/functionCalls/newWithSpreadES5.ts @@ -0,0 +1,97 @@ +//@target: ES5 + +function f(x: number, y: number, ...z: string[]) { +} + +function f2(...x: string[]) {} + +interface A { + f: { + new (x: number, y: number, ...z: string[]); + } +} + +class B { + constructor(x: number, y: number, ...z: string[]) {} +} + +interface C { + "a-b": typeof B; +} + +interface D { + 1: typeof B; +} + +var a: string[]; +var b: A; +var c: C; +var d: A[]; +var e: { [key: string]: A }; +var g: C[]; +var h: { [key: string]: C }; +var i: C[][]; + +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); + +// Multiple spreads arguments +new f2(...a, ...a); +new f(1 ,2, ...a, ...a); + +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); + +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); + +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); + +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); + +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); + +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); \ No newline at end of file diff --git a/tests/cases/conformance/expressions/functionCalls/newWithSpreadES6.ts b/tests/cases/conformance/expressions/functionCalls/newWithSpreadES6.ts new file mode 100644 index 0000000000..0068b6cf80 --- /dev/null +++ b/tests/cases/conformance/expressions/functionCalls/newWithSpreadES6.ts @@ -0,0 +1,98 @@ +//@target: ES6 + +function f(x: number, y: number, ...z: string[]) { +} + +function f2(...x: string[]) { +} + +interface A { + f: { + new (x: number, y: number, ...z: string[]); + } +} + +class B { + constructor(x: number, y: number, ...z: string[]) {} +} + +interface C { + "a-b": typeof B; +} + +interface D { + 1: typeof B; +} + +var a: string[]; +var b: A; +var c: C; +var d: A[]; +var e: { [key: string]: A }; +var g: C[]; +var h: { [key: string]: C }; +var i: C[][]; + +// Basic expression +new f(1, 2, "string"); +new f(1, 2, ...a); +new f(1, 2, ...a, "string"); + +// Multiple spreads arguments +new f2(...a, ...a); +new f(1 ,2, ...a, ...a); + +// Call expression +new f(1, 2, "string")(); +new f(1, 2, ...a)(); +new f(1, 2, ...a, "string")(); + +// Property access expression +new b.f(1, 2, "string"); +new b.f(1, 2, ...a); +new b.f(1, 2, ...a, "string"); + +// Parenthesised expression +new (b.f)(1, 2, "string"); +new (b.f)(1, 2, ...a); +new (b.f)(1, 2, ...a, "string"); + +// Element access expression +new d[1].f(1, 2, "string"); +new d[1].f(1, 2, ...a); +new d[1].f(1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new e["a-b"].f(1, 2, "string"); +new e["a-b"].f(1, 2, ...a); +new e["a-b"].f(1, 2, ...a, "string"); + +// Basic expression +new B(1, 2, "string"); +new B(1, 2, ...a); +new B(1, 2, ...a, "string"); + +// Property access expression +new c["a-b"](1, 2, "string"); +new c["a-b"](1, 2, ...a); +new c["a-b"](1, 2, ...a, "string"); + +// Parenthesised expression +new (c["a-b"])(1, 2, "string"); +new (c["a-b"])(1, 2, ...a); +new (c["a-b"])(1, 2, ...a, "string"); + +// Element access expression +new g[1]["a-b"](1, 2, "string"); +new g[1]["a-b"](1, 2, ...a); +new g[1]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a punctuated key +new h["a-b"]["a-b"](1, 2, "string"); +new h["a-b"]["a-b"](1, 2, ...a); +new h["a-b"]["a-b"](1, 2, ...a, "string"); + +// Element access expression with a number +new i["a-b"][1](1, 2, "string"); +new i["a-b"][1](1, 2, ...a); +new i["a-b"][1](1, 2, ...a, "string"); \ No newline at end of file diff --git a/tests/cases/conformance/types/localTypes/localTypes1.ts b/tests/cases/conformance/types/localTypes/localTypes1.ts new file mode 100644 index 0000000000..bceb9ad32c --- /dev/null +++ b/tests/cases/conformance/types/localTypes/localTypes1.ts @@ -0,0 +1,141 @@ +// @target: es5 + +function f1() { + enum E { + A, B, C + } + class C { + x: E; + } + interface I { + x: E; + } + type A = I[]; + let a: A = [new C()]; + a[0].x = E.B; + return a; +} + +function f2() { + function g() { + enum E { + A, B, C + } + class C { + x: E; + } + interface I { + x: E; + } + type A = I[]; + let a: A = [new C()]; + a[0].x = E.B; + return a; + } + return g(); +} + +function f3(b: boolean) { + if (true) { + enum E { + A, B, C + } + if (b) { + class C { + x: E; + } + interface I { + x: E; + } + type A = I[]; + let a: A = [new C()]; + a[0].x = E.B; + return a; + } + else { + class A { + x: E; + } + interface J { + x: E; + } + type C = J[]; + let c: C = [new A()]; + c[0].x = E.B; + return c; + } + } +} + +function f5() { + var z1 = function () { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } + var z2 = () => { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } +} + +class A { + constructor() { + enum E { + A, B, C + } + class C { + x: E; + } + } + m() { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } + get p() { + enum E { + A, B, C + } + class C { + x: E; + } + return new C(); + } +} + +function f6() { + class A { + a: string; + } + function g() { + class B extends A { + b: string; + } + function h() { + class C extends B { + c: string; + } + var x = new C(); + x.a = "a"; + x.b = "b"; + x.c = "c"; + return x; + } + return h(); + } + return g(); +} diff --git a/tests/cases/conformance/types/localTypes/localTypes2.ts b/tests/cases/conformance/types/localTypes/localTypes2.ts new file mode 100644 index 0000000000..79f1402c70 --- /dev/null +++ b/tests/cases/conformance/types/localTypes/localTypes2.ts @@ -0,0 +1,40 @@ +function f1() { + function f() { + class C { + constructor(public x: number, public y: number) { } + } + return C; + } + let C = f(); + let v = new C(10, 20); + let x = v.x; + let y = v.y; +} + +function f2() { + function f(x: number) { + class C { + public x = x; + constructor(public y: number) { } + } + return C; + } + let C = f(10); + let v = new C(20); + let x = v.x; + let y = v.y; +} + +function f3() { + function f(x: number, y: number) { + class C { + public x = x; + public y = y; + } + return C; + } + let C = f(10, 20); + let v = new C(); + let x = v.x; + let y = v.y; +} diff --git a/tests/cases/conformance/types/localTypes/localTypes3.ts b/tests/cases/conformance/types/localTypes/localTypes3.ts new file mode 100644 index 0000000000..5eb3cf2850 --- /dev/null +++ b/tests/cases/conformance/types/localTypes/localTypes3.ts @@ -0,0 +1,40 @@ +function f1() { + function f() { + class C { + constructor(public x: X, public y: Y) { } + } + return C; + } + let C = f(); + let v = new C(10, "hello"); + let x = v.x; + let y = v.y; +} + +function f2() { + function f(x: X) { + class C { + public x = x; + constructor(public y: Y) { } + } + return C; + } + let C = f(10); + let v = new C("hello"); + let x = v.x; + let y = v.y; +} + +function f3() { + function f(x: X, y: Y) { + class C { + public x = x; + public y = y; + } + return C; + } + let C = f(10, "hello"); + let v = new C(); + let x = v.x; + let y = v.y; +} diff --git a/tests/cases/conformance/types/localTypes/localTypes4.ts b/tests/cases/conformance/types/localTypes/localTypes4.ts new file mode 100644 index 0000000000..bd31e76a80 --- /dev/null +++ b/tests/cases/conformance/types/localTypes/localTypes4.ts @@ -0,0 +1,37 @@ +function f1() { + // Type parameters are in scope in parameters and return types + function f(x: T): T { + return undefined; + } +} + +function f2() { + // Local types are not in scope in parameters and return types + function f(x: T): T { + interface T { } + return undefined; + } +} + +function f3() { + // Type parameters and top-level local types are in same declaration space + function f() { + interface T { } + return undefined; + } +} + +function f4() { + // Local types are block scoped + interface T { x: number } + let v: T; + v.x = 10; + if (true) { + interface T { x: string } + let v: T; + v.x = "hello"; + } + else { + v.x = 20; + } +} diff --git a/tests/cases/conformance/types/localTypes/localTypes5.ts b/tests/cases/conformance/types/localTypes/localTypes5.ts new file mode 100644 index 0000000000..6aec24f183 --- /dev/null +++ b/tests/cases/conformance/types/localTypes/localTypes5.ts @@ -0,0 +1,14 @@ +function foo() { + class X { + m() { + return (function () { + class Y { + } + return new Y(); + })(); + } + } + var x = new X(); + return x.m(); +} +var x = foo(); diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral01.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral01.ts new file mode 100644 index 0000000000..ac8568d13f --- /dev/null +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral01.ts @@ -0,0 +1,8 @@ +/// + +////let v = 100; +/////a/./**/ + +goTo.marker(); +verify.not.memberListContains('v'); +verify.memberListContains('compile'); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral02.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral02.ts new file mode 100644 index 0000000000..2719d747d5 --- /dev/null +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral02.ts @@ -0,0 +1,10 @@ +/// + +////let v = 100; +////let x = /absidey//**/ + +// Should get nothing at the marker since it's +// going to be considered part of the regex flags. + +goTo.marker(); +verify.completionListIsEmpty(); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral03.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral03.ts new file mode 100644 index 0000000000..7c0e4d5144 --- /dev/null +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral03.ts @@ -0,0 +1,11 @@ +/// + +////let v = 100; +////let x = /absidey/ +/////**/ + +// Should not be blocked since there is a +// newline separating us from the regex flags. + +goTo.marker(); +verify.completionListContains("v"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral04.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral04.ts new file mode 100644 index 0000000000..06f31b8175 --- /dev/null +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral04.ts @@ -0,0 +1,10 @@ +/// + +////let v = 100; +////let x = /absidey/ /**/ + +// Should not be blocked since there is a +// space separating us from the regex flags. + +goTo.marker(); +verify.completionListContains("v"); \ No newline at end of file diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral05.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral05.ts new file mode 100644 index 0000000000..7ac0d1cd71 --- /dev/null +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral05.ts @@ -0,0 +1,10 @@ +/// + +////let v = 100; +////let x = /absidey/g/**/ + +// Should get nothing at the marker since it's +// going to be considered part of the regex flags. + +goTo.marker(); +verify.completionListIsEmpty() \ No newline at end of file diff --git a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral1.ts b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral1.ts index 870e83c511..558b4d1e79 100644 --- a/tests/cases/fourslash/completionListAfterRegularExpressionLiteral1.ts +++ b/tests/cases/fourslash/completionListAfterRegularExpressionLiteral1.ts @@ -3,5 +3,5 @@ /////a/./**/ goTo.marker(); -//verify.not.memberListContains('alert'); -//verify.memberListContains('compile'); \ No newline at end of file +verify.not.memberListContains('alert'); +verify.memberListContains('compile'); \ No newline at end of file diff --git a/tests/cases/fourslash/formatOnEnterFunctionDeclaration.ts b/tests/cases/fourslash/formatOnEnterFunctionDeclaration.ts new file mode 100644 index 0000000000..bf3756059d --- /dev/null +++ b/tests/cases/fourslash/formatOnEnterFunctionDeclaration.ts @@ -0,0 +1,8 @@ +/// + +/////*0*/function listAPIFiles(path: string): string[] {/*1*/ } + +goTo.marker("1"); +edit.insertLine(""); +goTo.marker("0"); +verify.currentLineContentIs("function listAPIFiles(path: string): string[] {"); \ No newline at end of file diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 9c6fd814d9..07a1fc4de4 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -448,9 +448,17 @@ module FourSlashInterface { FourSlash.currentTestState.verifyQuickInfoDisplayParts(kind, kindModifiers, textSpan, displayParts, documentation); } + public getSyntacticDiagnostics(expected: string) { + FourSlash.currentTestState.getSyntacticDiagnostics(expected); + } + public getSemanticDiagnostics(expected: string) { FourSlash.currentTestState.getSemanticDiagnostics(expected); } + + public ProjectInfo(expected: string []) { + FourSlash.currentTestState.verifyProjectInfo(expected); + } } export class edit { @@ -639,6 +647,10 @@ module FourSlashInterface { return getClassification("punctuation", text, position); } + export function docCommentTagName(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { + return getClassification("docCommentTagName", text, position); + } + export function className(text: string, position?: number): { classificationType: string; text: string; textSpan?: TextSpan } { return getClassification("className", text, position); } diff --git a/tests/cases/fourslash/generatorDeclarationFormatting.ts b/tests/cases/fourslash/generatorDeclarationFormatting.ts new file mode 100644 index 0000000000..007380fd0d --- /dev/null +++ b/tests/cases/fourslash/generatorDeclarationFormatting.ts @@ -0,0 +1,10 @@ +/// + +//// function *g() { }/*1*/ +//// var v = function *() { };/*2*/ + +format.document(); +goTo.marker('1'); +verify.currentLineContentIs("function* g() { }"); +goTo.marker('2'); +verify.currentLineContentIs("var v = function* () { };"); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts index 2ccac13dbf..1e114532c7 100644 --- a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics16.ts @@ -10,6 +10,6 @@ verify.getSemanticDiagnostics(`[ "start": 12, "length": 1, "category": "error", - "code": 8013 + "code": 8009 } ]`); \ No newline at end of file diff --git a/tests/cases/fourslash/getJavaScriptSemanticDiagnostics22.ts b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics22.ts new file mode 100644 index 0000000000..16c5380189 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSemanticDiagnostics22.ts @@ -0,0 +1,7 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.js +//// function foo(...a) {} + +verify.getSemanticDiagnostics(`[]`); diff --git a/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics1.ts b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics1.ts new file mode 100644 index 0000000000..e409029276 --- /dev/null +++ b/tests/cases/fourslash/getJavaScriptSyntacticDiagnostics1.ts @@ -0,0 +1,19 @@ +/// + +// @allowNonTsExtensions: true +// @Filename: a.js +//// /** +//// * @type {number} +//// * @type {string} +//// */ +//// var v; + +verify.getSyntacticDiagnostics(`[ + { + "message": "\'type\' tag already specified.", + "start": 26, + "length": 4, + "category": "error", + "code": 1223 + } +]`); \ No newline at end of file diff --git a/tests/cases/fourslash/server/projectInfo.ts b/tests/cases/fourslash/server/projectInfo.ts new file mode 100644 index 0000000000..656647715f --- /dev/null +++ b/tests/cases/fourslash/server/projectInfo.ts @@ -0,0 +1,24 @@ +/// + +// @Filename: a.ts +////export var test = "test String" + +// @Filename: b.ts +////import test from "a" + +// @Filename: c.ts +/////// +/////// + +// @Filename: d.ts +////console.log("nothing"); + +goTo.file("a.ts") +verify.ProjectInfo(["lib.d.ts", "a.ts"]) +goTo.file("b.ts") +verify.ProjectInfo(["lib.d.ts", "a.ts", "b.ts"]) +goTo.file("c.ts") +verify.ProjectInfo(["lib.d.ts", "a.ts", "b.ts", "c.ts"]) +goTo.file("d.ts") +verify.ProjectInfo(["lib.d.ts", "d.ts"]) + diff --git a/tests/cases/fourslash/syntacticClassificationsDocComment1.ts b/tests/cases/fourslash/syntacticClassificationsDocComment1.ts new file mode 100644 index 0000000000..fe812b4c78 --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationsDocComment1.ts @@ -0,0 +1,17 @@ +/// + +//// /** @type {number} */ +//// var v; + +var c = classification; +verify.syntacticClassificationsAre( + c.comment("/** "), + c.punctuation("@"), + c.docCommentTagName("type"), + c.punctuation("{"), + c.keyword("number"), + c.punctuation("}"), + c.comment(" */"), + c.keyword("var"), + c.text("v"), + c.punctuation(";")); diff --git a/tests/cases/fourslash/syntacticClassificationsDocComment2.ts b/tests/cases/fourslash/syntacticClassificationsDocComment2.ts new file mode 100644 index 0000000000..201251dde6 --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationsDocComment2.ts @@ -0,0 +1,26 @@ +/// + +//// /** @param foo { function(x): string } */ +//// var v; + + +var c = classification; +verify.syntacticClassificationsAre( + c.comment("/** "), + c.punctuation("@"), + c.docCommentTagName("param"), + c.comment(" "), + c.parameterName("foo"), + c.comment(" "), + c.punctuation("{"), + c.keyword("function"), + c.punctuation("("), + c.text("x"), + c.punctuation(")"), + c.punctuation(":"), + c.keyword("string"), + c.punctuation("}"), + c.comment(" */"), + c.keyword("var"), + c.text("v"), + c.punctuation(";")); diff --git a/tests/cases/fourslash/syntacticClassificationsDocComment3.ts b/tests/cases/fourslash/syntacticClassificationsDocComment3.ts new file mode 100644 index 0000000000..bdc7faa470 --- /dev/null +++ b/tests/cases/fourslash/syntacticClassificationsDocComment3.ts @@ -0,0 +1,20 @@ +/// + +//// /** @param foo { number /* } */ +//// var v; + +var c = classification; +verify.syntacticClassificationsAre( + c.comment("/** "), + c.punctuation("@"), + c.docCommentTagName("param"), + c.comment(" "), + c.parameterName("foo"), + c.comment(" "), + c.punctuation("{"), + c.keyword("number"), + c.comment(" /* } */"), + c.comment("/* } */"), + c.keyword("var"), + c.text("v"), + c.punctuation(";")); diff --git a/tests/cases/fourslash/yieldKeywordFormatting.ts b/tests/cases/fourslash/yieldKeywordFormatting.ts new file mode 100644 index 0000000000..8ea5d86673 --- /dev/null +++ b/tests/cases/fourslash/yieldKeywordFormatting.ts @@ -0,0 +1,28 @@ +/// + +////function* g3() { +/////*1*/ yield ; +/////*2*/ g3().next( yield ); +/////*3*/ yield new Bar; +/////*4*/ yield * new Bar; +/////*5*/ yield * [new Bar]; +/////*6*/ yield+ 1; +/////*7*/ yield++ 1; +////} + +format.document(); +let expected = + [ + " yield;", + " g3().next(yield);", + " yield new Bar;", + " yield* new Bar;", + " yield* [new Bar];", + " yield + 1;", // Should be "yield +1". This case is covered by bug 3028. + " yield ++1;" + ]; + +for (let i = 0; i < expected.length; i++) { + goTo.marker("" + (i + 1)); + verify.currentLineContentIs(expected[i]); +} diff --git a/tests/cases/unittests/jsDocParsing.ts b/tests/cases/unittests/jsDocParsing.ts new file mode 100644 index 0000000000..ebba6e8a1a --- /dev/null +++ b/tests/cases/unittests/jsDocParsing.ts @@ -0,0 +1,2204 @@ +/// +/// +/// + +module ts { + describe("JSDocParsing", () => { + describe("TypeExpressions", () => { + function parsesCorrectly(content: string, expected: string) { + let typeAndDiagnostics = ts.parseJSDocTypeExpressionForTests(content); + assert.isTrue(typeAndDiagnostics && typeAndDiagnostics.diagnostics.length === 0); + + let result = Utils.sourceFileToJSON(typeAndDiagnostics.jsDocTypeExpression.type); + assert.equal(result, expected); + } + + function parsesIncorrectly(content: string) { + let type = ts.parseJSDocTypeExpressionForTests(content); + assert.isTrue(!type || type.diagnostics.length > 0); + } + + describe("parseCorrectly", () => { + it("unknownType", () => { + parsesCorrectly("{?}", + `{ + "kind": "JSDocUnknownType", + "pos": 1, + "end": 2 +}`); + }); + + it("allType", () => { + parsesCorrectly("{*}", + `{ + "kind": "JSDocAllType", + "pos": 1, + "end": 2 +}`); + }); + + it("nullableType", () => { + parsesCorrectly("{?number}", + `{ + "kind": "JSDocNullableType", + "pos": 1, + "end": 8, + "type": { + "kind": "NumberKeyword", + "pos": 2, + "end": 8 + } +}`) + }); + + it("nullableType2", () => { + parsesCorrectly("{number?}", + `{ + "kind": "JSDocNullableType", + "pos": 1, + "end": 8, + "type": { + "kind": "NumberKeyword", + "pos": 1, + "end": 7 + } +}`) + }); + + it("nonNullableType", () => { + parsesCorrectly("{!number}", + `{ + "kind": "JSDocNonNullableType", + "pos": 1, + "end": 8, + "type": { + "kind": "NumberKeyword", + "pos": 2, + "end": 8 + } +}`) + }); + + it("nonNullableType2", () => { + parsesCorrectly("{number!}", + `{ + "kind": "JSDocNonNullableType", + "pos": 1, + "end": 8, + "type": { + "kind": "NumberKeyword", + "pos": 1, + "end": 7 + } +}`) + }); + + it("recordType1", () => { + parsesCorrectly("{{}}", + `{ + "kind": "JSDocRecordType", + "pos": 1, + "end": 3, + "members": { + "length": 0, + "pos": 2, + "end": 2 + } +}`) + }); + + it("recordType2", () => { + parsesCorrectly("{{foo}}", + `{ + "kind": "JSDocRecordType", + "pos": 1, + "end": 6, + "members": { + "0": { + "kind": "JSDocRecordMember", + "pos": 2, + "end": 5, + "name": { + "kind": "Identifier", + "pos": 2, + "end": 5, + "text": "foo" + } + }, + "length": 1, + "pos": 2, + "end": 5 + } +}`) + }); + + it("recordType3", () => { + parsesCorrectly("{{foo: number}}", + `{ + "kind": "JSDocRecordType", + "pos": 1, + "end": 14, + "members": { + "0": { + "kind": "JSDocRecordMember", + "pos": 2, + "end": 13, + "name": { + "kind": "Identifier", + "pos": 2, + "end": 5, + "text": "foo" + }, + "type": { + "kind": "NumberKeyword", + "pos": 6, + "end": 13 + } + }, + "length": 1, + "pos": 2, + "end": 13 + } +}`) + }); + + it("recordType4", () => { + parsesCorrectly("{{foo, bar}}", + `{ + "kind": "JSDocRecordType", + "pos": 1, + "end": 11, + "members": { + "0": { + "kind": "JSDocRecordMember", + "pos": 2, + "end": 5, + "name": { + "kind": "Identifier", + "pos": 2, + "end": 5, + "text": "foo" + } + }, + "1": { + "kind": "JSDocRecordMember", + "pos": 6, + "end": 10, + "name": { + "kind": "Identifier", + "pos": 6, + "end": 10, + "text": "bar" + } + }, + "length": 2, + "pos": 2, + "end": 10 + } +}`) + }); + + it("recordType5", () => { + parsesCorrectly("{{foo: number, bar}}", + `{ + "kind": "JSDocRecordType", + "pos": 1, + "end": 19, + "members": { + "0": { + "kind": "JSDocRecordMember", + "pos": 2, + "end": 13, + "name": { + "kind": "Identifier", + "pos": 2, + "end": 5, + "text": "foo" + }, + "type": { + "kind": "NumberKeyword", + "pos": 6, + "end": 13 + } + }, + "1": { + "kind": "JSDocRecordMember", + "pos": 14, + "end": 18, + "name": { + "kind": "Identifier", + "pos": 14, + "end": 18, + "text": "bar" + } + }, + "length": 2, + "pos": 2, + "end": 18 + } +}`) + }); + + it("recordType6", () => { + parsesCorrectly("{{foo, bar: number}}", + `{ + "kind": "JSDocRecordType", + "pos": 1, + "end": 19, + "members": { + "0": { + "kind": "JSDocRecordMember", + "pos": 2, + "end": 5, + "name": { + "kind": "Identifier", + "pos": 2, + "end": 5, + "text": "foo" + } + }, + "1": { + "kind": "JSDocRecordMember", + "pos": 6, + "end": 18, + "name": { + "kind": "Identifier", + "pos": 6, + "end": 10, + "text": "bar" + }, + "type": { + "kind": "NumberKeyword", + "pos": 11, + "end": 18 + } + }, + "length": 2, + "pos": 2, + "end": 18 + } +}`) + }); + + it("recordType7", () => { + parsesCorrectly("{{foo: number, bar: number}}", + `{ + "kind": "JSDocRecordType", + "pos": 1, + "end": 27, + "members": { + "0": { + "kind": "JSDocRecordMember", + "pos": 2, + "end": 13, + "name": { + "kind": "Identifier", + "pos": 2, + "end": 5, + "text": "foo" + }, + "type": { + "kind": "NumberKeyword", + "pos": 6, + "end": 13 + } + }, + "1": { + "kind": "JSDocRecordMember", + "pos": 14, + "end": 26, + "name": { + "kind": "Identifier", + "pos": 14, + "end": 18, + "text": "bar" + }, + "type": { + "kind": "NumberKeyword", + "pos": 19, + "end": 26 + } + }, + "length": 2, + "pos": 2, + "end": 26 + } +}`) + }); + + it("recordType8", () => { + parsesCorrectly("{{function}}", + `{ + "kind": "JSDocRecordType", + "pos": 1, + "end": 11, + "members": { + "0": { + "kind": "JSDocRecordMember", + "pos": 2, + "end": 10, + "name": { + "kind": "Identifier", + "pos": 2, + "end": 10, + "originalKeywordKind": "FunctionKeyword", + "text": "function" + } + }, + "length": 1, + "pos": 2, + "end": 10 + } +}`) + }); + + it("unionType", () => { + parsesCorrectly("{(number|string)}", + `{ + "kind": "JSDocUnionType", + "pos": 1, + "end": 16, + "types": { + "0": { + "kind": "NumberKeyword", + "pos": 2, + "end": 8 + }, + "1": { + "kind": "StringKeyword", + "pos": 9, + "end": 15 + }, + "length": 2, + "pos": 2, + "end": 15 + } +}`); + }); + + it("topLevelNoParenUnionType", () => { + parsesCorrectly("{number|string}", + `{ + "kind": "JSDocUnionType", + "pos": 1, + "end": 14, + "types": { + "0": { + "kind": "NumberKeyword", + "pos": 1, + "end": 7 + }, + "1": { + "kind": "StringKeyword", + "pos": 8, + "end": 14 + }, + "length": 2, + "pos": 1, + "end": 14 + } +}`); + }); + + it("functionType1", () => { + parsesCorrectly("{function()}", + `{ + "kind": "JSDocFunctionType", + "pos": 1, + "end": 11, + "parameters": { + "length": 0, + "pos": 10, + "end": 10 + } +}`); + }); + + it("functionType2", () => { + parsesCorrectly("{function(string, boolean)}", + `{ + "kind": "JSDocFunctionType", + "pos": 1, + "end": 26, + "parameters": { + "0": { + "kind": "Parameter", + "pos": 10, + "end": 16, + "type": { + "kind": "StringKeyword", + "pos": 10, + "end": 16 + } + }, + "1": { + "kind": "Parameter", + "pos": 17, + "end": 25, + "type": { + "kind": "BooleanKeyword", + "pos": 17, + "end": 25 + } + }, + "length": 2, + "pos": 10, + "end": 25 + } +}`); + }); + + it("functionReturnType1", () => { + parsesCorrectly("{function(string, boolean)}", + `{ + "kind": "JSDocFunctionType", + "pos": 1, + "end": 26, + "parameters": { + "0": { + "kind": "Parameter", + "pos": 10, + "end": 16, + "type": { + "kind": "StringKeyword", + "pos": 10, + "end": 16 + } + }, + "1": { + "kind": "Parameter", + "pos": 17, + "end": 25, + "type": { + "kind": "BooleanKeyword", + "pos": 17, + "end": 25 + } + }, + "length": 2, + "pos": 10, + "end": 25 + } +}`); + }); + + it("thisType1", () => { + parsesCorrectly("{this:a.b}", + `{ + "kind": "JSDocThisType", + "pos": 1, + "end": 9, + "type": { + "kind": "JSDocTypeReference", + "pos": 6, + "end": 9, + "name": { + "kind": "FirstNode", + "pos": 6, + "end": 9, + "left": { + "kind": "Identifier", + "pos": 6, + "end": 7, + "text": "a" + }, + "right": { + "kind": "Identifier", + "pos": 8, + "end": 9, + "text": "b" + } + } + } +}`); + }); + + it("newType1", () => { + parsesCorrectly("{new:a.b}", + `{ + "kind": "JSDocConstructorType", + "pos": 1, + "end": 8, + "type": { + "kind": "JSDocTypeReference", + "pos": 5, + "end": 8, + "name": { + "kind": "FirstNode", + "pos": 5, + "end": 8, + "left": { + "kind": "Identifier", + "pos": 5, + "end": 6, + "text": "a" + }, + "right": { + "kind": "Identifier", + "pos": 7, + "end": 8, + "text": "b" + } + } + } +}`); + }); + + it("variadicType", () => { + parsesCorrectly("{...number}", + `{ + "kind": "JSDocVariadicType", + "pos": 1, + "end": 10, + "type": { + "kind": "NumberKeyword", + "pos": 4, + "end": 10 + } +}`); + }); + + it("optionalType", () => { + parsesCorrectly("{number=}", + `{ + "kind": "JSDocOptionalType", + "pos": 1, + "end": 8, + "type": { + "kind": "NumberKeyword", + "pos": 1, + "end": 7 + } +}`); + }); + + it("optionalNullable", () => { + parsesCorrectly("{?=}", + `{ + "kind": "JSDocOptionalType", + "pos": 1, + "end": 3, + "type": { + "kind": "JSDocUnknownType", + "pos": 1, + "end": 2 + } +}`); + }); + + it("typeReference1", () => { + parsesCorrectly("{a.}", + `{ + "kind": "JSDocTypeReference", + "pos": 1, + "end": 11, + "name": { + "kind": "Identifier", + "pos": 1, + "end": 2, + "text": "a" + }, + "typeArguments": { + "0": { + "kind": "NumberKeyword", + "pos": 4, + "end": 10 + }, + "length": 1, + "pos": 4, + "end": 10 + } +}`); + }); + + it("typeReference2", () => { + parsesCorrectly("{a.}", + `{ + "kind": "JSDocTypeReference", + "pos": 1, + "end": 18, + "name": { + "kind": "Identifier", + "pos": 1, + "end": 2, + "text": "a" + }, + "typeArguments": { + "0": { + "kind": "NumberKeyword", + "pos": 4, + "end": 10 + }, + "1": { + "kind": "StringKeyword", + "pos": 11, + "end": 17 + }, + "length": 2, + "pos": 4, + "end": 17 + } +}`); + }); + + it("typeReference3", () => { + parsesCorrectly("{a.function}", + `{ + "kind": "JSDocTypeReference", + "pos": 1, + "end": 11, + "name": { + "kind": "FirstNode", + "pos": 1, + "end": 11, + "left": { + "kind": "Identifier", + "pos": 1, + "end": 2, + "text": "a" + }, + "right": { + "kind": "Identifier", + "pos": 3, + "end": 11, + "originalKeywordKind": "FunctionKeyword", + "text": "function" + } + } +}`); + }); + + it("arrayType1", () => { + parsesCorrectly( + "{a[]}", + `{ + "kind": "JSDocArrayType", + "pos": 1, + "end": 4, + "elementType": { + "kind": "JSDocTypeReference", + "pos": 1, + "end": 2, + "name": { + "kind": "Identifier", + "pos": 1, + "end": 2, + "text": "a" + } + } +}`); + }); + + it("arrayType2", () => { + parsesCorrectly( + "{a[][]}", + `{ + "kind": "JSDocArrayType", + "pos": 1, + "end": 6, + "elementType": { + "kind": "JSDocArrayType", + "pos": 1, + "end": 4, + "elementType": { + "kind": "JSDocTypeReference", + "pos": 1, + "end": 2, + "name": { + "kind": "Identifier", + "pos": 1, + "end": 2, + "text": "a" + } + } + } +}`); + }); + + it("arrayType3", () => { + parsesCorrectly( + "{a[][]=}", + `{ + "kind": "JSDocOptionalType", + "pos": 1, + "end": 7, + "type": { + "kind": "JSDocArrayType", + "pos": 1, + "end": 6, + "elementType": { + "kind": "JSDocArrayType", + "pos": 1, + "end": 4, + "elementType": { + "kind": "JSDocTypeReference", + "pos": 1, + "end": 2, + "name": { + "kind": "Identifier", + "pos": 1, + "end": 2, + "text": "a" + } + } + } + } +}`); + }); + + it("keyword1", () => { + parsesCorrectly( + "{var}", + `{ + "kind": "JSDocTypeReference", + "pos": 1, + "end": 4, + "name": { + "kind": "Identifier", + "pos": 1, + "end": 4, + "originalKeywordKind": "VarKeyword", + "text": "var" + } +}`); + }); + + it("keyword2", () => { + parsesCorrectly( + "{null}", + `{ + "kind": "JSDocTypeReference", + "pos": 1, + "end": 5, + "name": { + "kind": "Identifier", + "pos": 1, + "end": 5, + "originalKeywordKind": "NullKeyword", + "text": "null" + } +}`); + }); + + it("keyword3", () => { + parsesCorrectly( + "{undefined}", + `{ + "kind": "JSDocTypeReference", + "pos": 1, + "end": 10, + "name": { + "kind": "Identifier", + "pos": 1, + "end": 10, + "text": "undefined" + } +}`); + }); + + it("tupleType0", () => { + parsesCorrectly( + "{[]}", + `{ + "kind": "JSDocTupleType", + "pos": 1, + "end": 3, + "types": { + "length": 0, + "pos": 2, + "end": 2 + } +}`); + }); + + it("tupleType1", () => { + parsesCorrectly( + "{[number]}", + `{ + "kind": "JSDocTupleType", + "pos": 1, + "end": 9, + "types": { + "0": { + "kind": "NumberKeyword", + "pos": 2, + "end": 8 + }, + "length": 1, + "pos": 2, + "end": 8 + } +}`); + }); + + it("tupleType2", () => { + parsesCorrectly( + "{[number,string]}", + `{ + "kind": "JSDocTupleType", + "pos": 1, + "end": 16, + "types": { + "0": { + "kind": "NumberKeyword", + "pos": 2, + "end": 8 + }, + "1": { + "kind": "StringKeyword", + "pos": 9, + "end": 15 + }, + "length": 2, + "pos": 2, + "end": 15 + } +}`); + }); + + it("tupleType3", () => { + parsesCorrectly( + "{[number,string,boolean]}", + `{ + "kind": "JSDocTupleType", + "pos": 1, + "end": 24, + "types": { + "0": { + "kind": "NumberKeyword", + "pos": 2, + "end": 8 + }, + "1": { + "kind": "StringKeyword", + "pos": 9, + "end": 15 + }, + "2": { + "kind": "BooleanKeyword", + "pos": 16, + "end": 23 + }, + "length": 3, + "pos": 2, + "end": 23 + } +}`); + }); + }); + + describe("parsesIncorrectly", () => { + it("emptyType", () => { + parsesIncorrectly("{}"); + }); + + it("trailingCommaInRecordType", () => { + parsesIncorrectly("{{a,}}"); + }); + + it("unionTypeWithTrailingBar", () => { + parsesIncorrectly("{(a|)}"); + }); + + it("unionTypeWithoutTypes", () => { + parsesIncorrectly("{()}"); + }); + + it("nullableTypeWithoutType", () => { + parsesIncorrectly("{!}"); + }); + + it("functionTypeWithTrailingComma", () => { + parsesIncorrectly("{function(a,)}"); + }); + + it("thisWithoutType", () => { + parsesIncorrectly("{this:}"); + }); + + it("newWithoutType", () => { + parsesIncorrectly("{new:}"); + }); + + it("variadicWithoutType", () => { + parsesIncorrectly("{...}"); + }); + + it("optionalWithoutType", () => { + parsesIncorrectly("{=}"); + }); + + it("allWithType", () => { + parsesIncorrectly("{*foo}"); + }); + + it("typeArgumentsNotFollowingDot", () => { + parsesIncorrectly("{a<>}"); + }); + + it("emptyTypeArguments", () => { + parsesIncorrectly("{a.<>}"); + }); + + it("typeArgumentsWithTrailingComma", () => { + parsesIncorrectly("{a.}"); + }); + + it("tsFunctionType", () => { + parsesIncorrectly("{() => string}"); + }); + + it("tsConstructoType", () => { + parsesIncorrectly("{new () => string}"); + }); + + it("typeOfType", () => { + parsesIncorrectly("{typeof M}"); + }); + + it("namedParameter", () => { + parsesIncorrectly("{function(a: number)}"); + }); + + it("callSignatureInRecordType", () => { + parsesIncorrectly("{{(): number}}"); + }); + + it("methodInRecordType", () => { + parsesIncorrectly("{{foo(): number}}"); + }); + + it("tupleTypeWithComma", () => { + parsesIncorrectly( "{[,]}"); + }); + + it("tupleTypeWithTrailingComma", () => { + parsesIncorrectly("{[number,]}"); + }); + + it("tupleTypeWithLeadingComma", () => { + parsesIncorrectly("{[,number]}"); + }); + }); + }); + + describe("DocComments", () => { + function parsesCorrectly(content: string, expected: string) { + let comment = parseIsolatedJSDocComment(content); + Debug.assert(comment && comment.diagnostics.length === 0); + + let result = JSON.stringify(comment.jsDocComment, (k, v) => { + return v && v.pos !== undefined + ? JSON.parse(Utils.sourceFileToJSON(v)) + : v; + }, " "); + + assert.equal(result, expected); + } + + function parsesIncorrectly(content: string) { + let type = parseIsolatedJSDocComment(content); + assert.isTrue(!type || type.diagnostics.length > 0); + } + + describe("parsesIncorrectly", () => { + it("emptyComment", () => { + parsesIncorrectly("/***/"); + }); + + it("threeAsterisks", () => { + parsesIncorrectly("/*** */"); + }); + + it("asteriskAfterPreamble", () => { + parsesIncorrectly("/** * @type {number} */"); + }); + + it("multipleTypes", () => { + parsesIncorrectly( +`/** + * @type {number} + * @type {string} + */`); + }); + + it("multipleReturnTypes", () => { + parsesIncorrectly( +`/** + * @return {number} + * @return {string} + */`); + }); + + it("noTypeParameters", () => { + parsesIncorrectly( +`/** + * @template + */`); + }); + + it("trailingTypeParameterComma", () => { + parsesIncorrectly( +`/** + * @template T, + */`); + }); + + it("paramWithoutName", () => { + parsesIncorrectly( +`/** + * @param {number} + */`); + }); + + it("paramWithoutTypeOrName", () => { + parsesIncorrectly( +`/** + * @param + */`); + }); + }); + + describe("parsesCorrectly", () => { + it("noLeadingAsterisk", () => { + parsesCorrectly( +`/** + @type {number} + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 27, + "tags": { + "0": { + "kind": "JSDocTypeTag", + "pos": 8, + "end": 22, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 13, + "text": "type" + }, + "typeExpression": { + "kind": "JSDocTypeExpression", + "pos": 14, + "end": 22, + "type": { + "kind": "NumberKeyword", + "pos": 15, + "end": 21 + } + } + }, + "length": 1, + "pos": 8, + "end": 22 + } +}`); + }); + + it("noType", () => { + parsesCorrectly( + `/** + * @type + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 18, + "tags": { + "0": { + "kind": "JSDocTypeTag", + "pos": 8, + "end": 13, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 13, + "text": "type" + } + }, + "length": 1, + "pos": 8, + "end": 13 + } +}`); + }); + + it("noReturnType", () => { + parsesCorrectly( + `/** + * @return + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 20, + "tags": { + "0": { + "kind": "JSDocReturnTag", + "pos": 8, + "end": 15, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 15, + "text": "return" + } + }, + "length": 1, + "pos": 8, + "end": 15 + } +}`); + }); + + it("leadingAsterisk", () => { + parsesCorrectly( +`/** + * @type {number} + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 27, + "tags": { + "0": { + "kind": "JSDocTypeTag", + "pos": 8, + "end": 22, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 13, + "text": "type" + }, + "typeExpression": { + "kind": "JSDocTypeExpression", + "pos": 14, + "end": 22, + "type": { + "kind": "NumberKeyword", + "pos": 15, + "end": 21 + } + } + }, + "length": 1, + "pos": 8, + "end": 22 + } +}`); + }); + + it("typeTag", () => { + parsesCorrectly( +`/** + * @type {number} + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 27, + "tags": { + "0": { + "kind": "JSDocTypeTag", + "pos": 8, + "end": 22, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 13, + "text": "type" + }, + "typeExpression": { + "kind": "JSDocTypeExpression", + "pos": 14, + "end": 22, + "type": { + "kind": "NumberKeyword", + "pos": 15, + "end": 21 + } + } + }, + "length": 1, + "pos": 8, + "end": 22 + } +}`); + }); + + it("returnTag1", () => { + parsesCorrectly( +`/** + * @return {number} + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 29, + "tags": { + "0": { + "kind": "JSDocReturnTag", + "pos": 8, + "end": 24, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 15, + "text": "return" + }, + "typeExpression": { + "kind": "JSDocTypeExpression", + "pos": 16, + "end": 24, + "type": { + "kind": "NumberKeyword", + "pos": 17, + "end": 23 + } + } + }, + "length": 1, + "pos": 8, + "end": 24 + } +}`); + }); + + it("returnTag2", () => { + parsesCorrectly( + `/** + * @return {number} Description text follows + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 54, + "tags": { + "0": { + "kind": "JSDocReturnTag", + "pos": 8, + "end": 24, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 15, + "text": "return" + }, + "typeExpression": { + "kind": "JSDocTypeExpression", + "pos": 16, + "end": 24, + "type": { + "kind": "NumberKeyword", + "pos": 17, + "end": 23 + } + } + }, + "length": 1, + "pos": 8, + "end": 24 + } +}`); + }); + + it("returnsTag1", () => { + parsesCorrectly( + `/** + * @returns {number} + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 30, + "tags": { + "0": { + "kind": "JSDocReturnTag", + "pos": 8, + "end": 25, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 16, + "text": "returns" + }, + "typeExpression": { + "kind": "JSDocTypeExpression", + "pos": 17, + "end": 25, + "type": { + "kind": "NumberKeyword", + "pos": 18, + "end": 24 + } + } + }, + "length": 1, + "pos": 8, + "end": 25 + } +}`); + }); + + it("oneParamTag", () => { + parsesCorrectly( +`/** + * @param {number} name1 + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 34, + "tags": { + "0": { + "kind": "JSDocParameterTag", + "pos": 8, + "end": 29, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 14, + "text": "param" + }, + "typeExpression": { + "kind": "JSDocTypeExpression", + "pos": 15, + "end": 23, + "type": { + "kind": "NumberKeyword", + "pos": 16, + "end": 22 + } + }, + "postParameterName": { + "kind": "Identifier", + "pos": 24, + "end": 29, + "text": "name1" + } + }, + "length": 1, + "pos": 8, + "end": 29 + } +}`); + }); + + it("twoParamTag2", () => { + parsesCorrectly( +`/** + * @param {number} name1 + * @param {number} name2 + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 60, + "tags": { + "0": { + "kind": "JSDocParameterTag", + "pos": 8, + "end": 29, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 14, + "text": "param" + }, + "typeExpression": { + "kind": "JSDocTypeExpression", + "pos": 15, + "end": 23, + "type": { + "kind": "NumberKeyword", + "pos": 16, + "end": 22 + } + }, + "postParameterName": { + "kind": "Identifier", + "pos": 24, + "end": 29, + "text": "name1" + } + }, + "1": { + "kind": "JSDocParameterTag", + "pos": 34, + "end": 55, + "atToken": { + "kind": "AtToken", + "pos": 34, + "end": 35 + }, + "tagName": { + "kind": "Identifier", + "pos": 35, + "end": 40, + "text": "param" + }, + "typeExpression": { + "kind": "JSDocTypeExpression", + "pos": 41, + "end": 49, + "type": { + "kind": "NumberKeyword", + "pos": 42, + "end": 48 + } + }, + "postParameterName": { + "kind": "Identifier", + "pos": 50, + "end": 55, + "text": "name2" + } + }, + "length": 2, + "pos": 8, + "end": 55 + } +}`); + }); + + it("paramTag1", () => { + parsesCorrectly( + `/** + * @param {number} name1 Description text follows + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 59, + "tags": { + "0": { + "kind": "JSDocParameterTag", + "pos": 8, + "end": 29, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 14, + "text": "param" + }, + "typeExpression": { + "kind": "JSDocTypeExpression", + "pos": 15, + "end": 23, + "type": { + "kind": "NumberKeyword", + "pos": 16, + "end": 22 + } + }, + "postParameterName": { + "kind": "Identifier", + "pos": 24, + "end": 29, + "text": "name1" + } + }, + "length": 1, + "pos": 8, + "end": 29 + } +}`); + }); + + it("paramTagBracketedName1", () => { + parsesCorrectly( + `/** + * @param {number} [name1] Description text follows + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 61, + "tags": { + "0": { + "kind": "JSDocParameterTag", + "pos": 8, + "end": 30, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 14, + "text": "param" + }, + "typeExpression": { + "kind": "JSDocTypeExpression", + "pos": 15, + "end": 23, + "type": { + "kind": "NumberKeyword", + "pos": 16, + "end": 22 + } + }, + "postParameterName": { + "kind": "Identifier", + "pos": 25, + "end": 30, + "text": "name1" + }, + "isBracketed": true + }, + "length": 1, + "pos": 8, + "end": 30 + } +}`); + }); + + it("paramTagBracketedName2", () => { + parsesCorrectly( + `/** + * @param {number} [ name1 = 1] Description text follows + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 66, + "tags": { + "0": { + "kind": "JSDocParameterTag", + "pos": 8, + "end": 31, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 14, + "text": "param" + }, + "typeExpression": { + "kind": "JSDocTypeExpression", + "pos": 15, + "end": 23, + "type": { + "kind": "NumberKeyword", + "pos": 16, + "end": 22 + } + }, + "postParameterName": { + "kind": "Identifier", + "pos": 26, + "end": 31, + "text": "name1" + }, + "isBracketed": true + }, + "length": 1, + "pos": 8, + "end": 31 + } +}`); + }); + + it("twoParamTagOnSameLine", () => { + parsesCorrectly( +`/** + * @param {number} name1 @param {number} name2 + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 56, + "tags": { + "0": { + "kind": "JSDocParameterTag", + "pos": 8, + "end": 29, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 14, + "text": "param" + }, + "typeExpression": { + "kind": "JSDocTypeExpression", + "pos": 15, + "end": 23, + "type": { + "kind": "NumberKeyword", + "pos": 16, + "end": 22 + } + }, + "postParameterName": { + "kind": "Identifier", + "pos": 24, + "end": 29, + "text": "name1" + } + }, + "length": 1, + "pos": 8, + "end": 29 + } +}`); + }); + + it("paramTagNameThenType1", () => { + parsesCorrectly( + `/** + * @param name1 {number} + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 34, + "tags": { + "0": { + "kind": "JSDocParameterTag", + "pos": 8, + "end": 29, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 14, + "text": "param" + }, + "preParameterName": { + "kind": "Identifier", + "pos": 15, + "end": 20, + "text": "name1" + }, + "typeExpression": { + "kind": "JSDocTypeExpression", + "pos": 21, + "end": 29, + "type": { + "kind": "NumberKeyword", + "pos": 22, + "end": 28 + } + } + }, + "length": 1, + "pos": 8, + "end": 29 + } +}`); + }); + + it("paramTagNameThenType2", () => { + parsesCorrectly( + `/** + * @param name1 {number} Description + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 46, + "tags": { + "0": { + "kind": "JSDocParameterTag", + "pos": 8, + "end": 29, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 14, + "text": "param" + }, + "preParameterName": { + "kind": "Identifier", + "pos": 15, + "end": 20, + "text": "name1" + }, + "typeExpression": { + "kind": "JSDocTypeExpression", + "pos": 21, + "end": 29, + "type": { + "kind": "NumberKeyword", + "pos": 22, + "end": 28 + } + } + }, + "length": 1, + "pos": 8, + "end": 29 + } +}`); + }); + + it("templateTag", () => { + parsesCorrectly( +`/** + * @template T + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 24, + "tags": { + "0": { + "kind": "JSDocTemplateTag", + "pos": 8, + "end": 19, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 17, + "text": "template" + }, + "typeParameters": { + "0": { + "kind": "TypeParameter", + "pos": 18, + "end": 19, + "name": { + "kind": "Identifier", + "pos": 18, + "end": 19, + "text": "T" + } + }, + "length": 1, + "pos": 17, + "end": 19 + } + }, + "length": 1, + "pos": 8, + "end": 19 + } +}`); + }); + + it("templateTag2", () => { + parsesCorrectly( + `/** + * @template K,V + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 26, + "tags": { + "0": { + "kind": "JSDocTemplateTag", + "pos": 8, + "end": 21, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 17, + "text": "template" + }, + "typeParameters": { + "0": { + "kind": "TypeParameter", + "pos": 18, + "end": 19, + "name": { + "kind": "Identifier", + "pos": 18, + "end": 19, + "text": "K" + } + }, + "1": { + "kind": "TypeParameter", + "pos": 20, + "end": 21, + "name": { + "kind": "Identifier", + "pos": 20, + "end": 21, + "text": "V" + } + }, + "length": 2, + "pos": 17, + "end": 21 + } + }, + "length": 1, + "pos": 8, + "end": 21 + } +}`); + }); + + it("templateTag3", () => { + parsesCorrectly( + `/** + * @template K ,V + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 27, + "tags": { + "0": { + "kind": "JSDocTemplateTag", + "pos": 8, + "end": 22, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 17, + "text": "template" + }, + "typeParameters": { + "0": { + "kind": "TypeParameter", + "pos": 18, + "end": 19, + "name": { + "kind": "Identifier", + "pos": 18, + "end": 19, + "text": "K" + } + }, + "1": { + "kind": "TypeParameter", + "pos": 21, + "end": 22, + "name": { + "kind": "Identifier", + "pos": 21, + "end": 22, + "text": "V" + } + }, + "length": 2, + "pos": 17, + "end": 22 + } + }, + "length": 1, + "pos": 8, + "end": 22 + } +}`); + }); + + it("templateTag4", () => { + parsesCorrectly( + `/** + * @template K, V + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 27, + "tags": { + "0": { + "kind": "JSDocTemplateTag", + "pos": 8, + "end": 22, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 17, + "text": "template" + }, + "typeParameters": { + "0": { + "kind": "TypeParameter", + "pos": 18, + "end": 19, + "name": { + "kind": "Identifier", + "pos": 18, + "end": 19, + "text": "K" + } + }, + "1": { + "kind": "TypeParameter", + "pos": 21, + "end": 22, + "name": { + "kind": "Identifier", + "pos": 21, + "end": 22, + "text": "V" + } + }, + "length": 2, + "pos": 17, + "end": 22 + } + }, + "length": 1, + "pos": 8, + "end": 22 + } +}`); + }); + + it("templateTag5", () => { + parsesCorrectly( + `/** + * @template K , V + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 28, + "tags": { + "0": { + "kind": "JSDocTemplateTag", + "pos": 8, + "end": 23, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 17, + "text": "template" + }, + "typeParameters": { + "0": { + "kind": "TypeParameter", + "pos": 18, + "end": 19, + "name": { + "kind": "Identifier", + "pos": 18, + "end": 19, + "text": "K" + } + }, + "1": { + "kind": "TypeParameter", + "pos": 22, + "end": 23, + "name": { + "kind": "Identifier", + "pos": 22, + "end": 23, + "text": "V" + } + }, + "length": 2, + "pos": 17, + "end": 23 + } + }, + "length": 1, + "pos": 8, + "end": 23 + } +}`); + }); + + it("templateTag6", () => { + parsesCorrectly( + `/** + * @template K , V Description of type parameters. + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 60, + "tags": { + "0": { + "kind": "JSDocTemplateTag", + "pos": 8, + "end": 24, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 17, + "text": "template" + }, + "typeParameters": { + "0": { + "kind": "TypeParameter", + "pos": 18, + "end": 19, + "name": { + "kind": "Identifier", + "pos": 18, + "end": 19, + "text": "K" + } + }, + "1": { + "kind": "TypeParameter", + "pos": 22, + "end": 23, + "name": { + "kind": "Identifier", + "pos": 22, + "end": 23, + "text": "V" + } + }, + "length": 2, + "pos": 17, + "end": 24 + } + }, + "length": 1, + "pos": 8, + "end": 24 + } +}`); + }); + + it("paramWithoutType", () => { + parsesCorrectly( + `/** + * @param foo + */`, + `{ + "kind": "JSDocComment", + "pos": 0, + "end": 23, + "tags": { + "0": { + "kind": "JSDocParameterTag", + "pos": 8, + "end": 18, + "atToken": { + "kind": "AtToken", + "pos": 8, + "end": 9 + }, + "tagName": { + "kind": "Identifier", + "pos": 9, + "end": 14, + "text": "param" + }, + "preParameterName": { + "kind": "Identifier", + "pos": 15, + "end": 18, + "text": "foo" + } + }, + "length": 1, + "pos": 8, + "end": 18 + } +}`); + }); + }); + }); + }); +} \ No newline at end of file