mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into asyncFunctions
This commit is contained in:
@@ -630,7 +630,7 @@ namespace ts {
|
||||
function getStrictModeIdentifierMessage(node: Node) {
|
||||
// Provide specialized messages to help the user understand why we think they're in
|
||||
// strict mode.
|
||||
if (getAncestor(node, SyntaxKind.ClassDeclaration) || getAncestor(node, SyntaxKind.ClassExpression)) {
|
||||
if (getContainingClass(node)) {
|
||||
return Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode;
|
||||
}
|
||||
|
||||
@@ -688,7 +688,7 @@ namespace ts {
|
||||
function getStrictModeEvalOrArgumentsMessage(node: Node) {
|
||||
// Provide specialized messages to help the user understand why we think they're in
|
||||
// strict mode.
|
||||
if (getAncestor(node, SyntaxKind.ClassDeclaration) || getAncestor(node, SyntaxKind.ClassExpression)) {
|
||||
if (getContainingClass(node)) {
|
||||
return Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode;
|
||||
}
|
||||
|
||||
@@ -1031,7 +1031,7 @@ namespace ts {
|
||||
// containing class.
|
||||
if (node.flags & NodeFlags.AccessibilityModifier &&
|
||||
node.parent.kind === SyntaxKind.Constructor &&
|
||||
(node.parent.parent.kind === SyntaxKind.ClassDeclaration || node.parent.parent.kind === SyntaxKind.ClassExpression)) {
|
||||
isClassLike(node.parent.parent)) {
|
||||
|
||||
let classDeclaration = <ClassLikeDeclaration>node.parent.parent;
|
||||
declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
|
||||
|
||||
+1358
-324
File diff suppressed because it is too large
Load Diff
@@ -38,6 +38,16 @@ namespace ts {
|
||||
name: "inlineSources",
|
||||
type: "boolean",
|
||||
},
|
||||
{
|
||||
name: "jsx",
|
||||
type: {
|
||||
"preserve": JsxEmit.Preserve,
|
||||
"react": JsxEmit.React
|
||||
},
|
||||
paramType: Diagnostics.KIND,
|
||||
description: Diagnostics.Specify_JSX_code_generation_Colon_preserve_or_react,
|
||||
error: Diagnostics.Argument_for_jsx_must_be_preserve_or_react
|
||||
},
|
||||
{
|
||||
name: "listFiles",
|
||||
type: "boolean",
|
||||
@@ -110,6 +120,7 @@ namespace ts {
|
||||
{
|
||||
name: "out",
|
||||
type: "string",
|
||||
isFilePath: true,
|
||||
description: Diagnostics.Concatenate_and_emit_output_to_single_file,
|
||||
paramType: Diagnostics.FILE,
|
||||
},
|
||||
@@ -405,18 +416,29 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getFileNames(): string[] {
|
||||
var fileNames: string[] = [];
|
||||
let fileNames: string[] = [];
|
||||
if (hasProperty(json, "files")) {
|
||||
if (json["files"] instanceof Array) {
|
||||
fileNames = map(<string[]>json["files"], s => combinePaths(basePath, s));
|
||||
}
|
||||
}
|
||||
else {
|
||||
var exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;
|
||||
var sysFiles = host.readDirectory(basePath, ".ts", exclude);
|
||||
for (var i = 0; i < sysFiles.length; i++) {
|
||||
var name = sysFiles[i];
|
||||
if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) {
|
||||
let exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;
|
||||
let sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude));
|
||||
for (let i = 0; i < sysFiles.length; i++) {
|
||||
let name = sysFiles[i];
|
||||
if (fileExtensionIs(name, ".d.ts")) {
|
||||
let baseName = name.substr(0, name.length - ".d.ts".length);
|
||||
if (!contains(sysFiles, baseName + ".tsx") && !contains(sysFiles, baseName + ".ts")) {
|
||||
fileNames.push(name);
|
||||
}
|
||||
}
|
||||
else if (fileExtensionIs(name, ".ts")) {
|
||||
if (!contains(sysFiles, name + "x")) {
|
||||
fileNames.push(name)
|
||||
}
|
||||
}
|
||||
else {
|
||||
fileNames.push(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -572,7 +572,7 @@ namespace ts {
|
||||
export function getNormalizedPathComponents(path: string, currentDirectory: string) {
|
||||
path = normalizeSlashes(path);
|
||||
let rootLength = getRootLength(path);
|
||||
if (rootLength == 0) {
|
||||
if (rootLength === 0) {
|
||||
// If the path is not rooted it is relative to current directory
|
||||
path = combinePaths(normalizeSlashes(currentDirectory), path);
|
||||
rootLength = getRootLength(path);
|
||||
@@ -702,9 +702,9 @@ namespace ts {
|
||||
/**
|
||||
* List of supported extensions in order of file resolution precedence.
|
||||
*/
|
||||
export const supportedExtensions = [".ts", ".d.ts"];
|
||||
export const supportedExtensions = [".tsx", ".ts", ".d.ts"];
|
||||
|
||||
const extensionsToRemove = [".d.ts", ".ts", ".js"];
|
||||
const extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"];
|
||||
export function removeFileExtension(path: string): string {
|
||||
for (let ext of extensionsToRemove) {
|
||||
if (fileExtensionIs(path, ext)) {
|
||||
|
||||
@@ -40,7 +40,6 @@ namespace ts {
|
||||
function emitDeclarations(host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[], jsFilePath: string, root?: SourceFile): DeclarationEmit {
|
||||
let newLine = host.getNewLine();
|
||||
let compilerOptions = host.getCompilerOptions();
|
||||
let languageVersion = compilerOptions.target || ScriptTarget.ES3;
|
||||
|
||||
let write: (s: string) => void;
|
||||
let writeLine: () => void;
|
||||
@@ -709,7 +708,12 @@ namespace ts {
|
||||
function writeModuleDeclaration(node: ModuleDeclaration) {
|
||||
emitJsDocComments(node);
|
||||
emitModuleElementDeclarationFlags(node);
|
||||
write("module ");
|
||||
if (node.flags & NodeFlags.Namespace) {
|
||||
write("namespace ");
|
||||
}
|
||||
else {
|
||||
write("module ");
|
||||
}
|
||||
writeTextOfNode(currentSourceFile, node.name);
|
||||
while (node.body.kind !== SyntaxKind.ModuleBlock) {
|
||||
node = <ModuleDeclaration>node.body;
|
||||
|
||||
@@ -20,15 +20,10 @@ namespace ts {
|
||||
An_index_signature_must_have_a_type_annotation: { code: 1021, category: DiagnosticCategory.Error, key: "An index signature must have a type annotation." },
|
||||
An_index_signature_parameter_must_have_a_type_annotation: { code: 1022, category: DiagnosticCategory.Error, key: "An index signature parameter must have a type annotation." },
|
||||
An_index_signature_parameter_type_must_be_string_or_number: { code: 1023, category: DiagnosticCategory.Error, key: "An index signature parameter type must be 'string' or 'number'." },
|
||||
A_class_or_interface_declaration_can_only_have_one_extends_clause: { code: 1024, category: DiagnosticCategory.Error, key: "A class or interface declaration can only have one 'extends' clause." },
|
||||
An_extends_clause_must_precede_an_implements_clause: { code: 1025, category: DiagnosticCategory.Error, key: "An 'extends' clause must precede an 'implements' clause." },
|
||||
A_class_can_only_extend_a_single_class: { code: 1026, category: DiagnosticCategory.Error, key: "A class can only extend a single class." },
|
||||
A_class_declaration_can_only_have_one_implements_clause: { code: 1027, category: DiagnosticCategory.Error, key: "A class declaration can only have one 'implements' clause." },
|
||||
Accessibility_modifier_already_seen: { code: 1028, category: DiagnosticCategory.Error, key: "Accessibility modifier already seen." },
|
||||
_0_modifier_must_precede_1_modifier: { code: 1029, category: DiagnosticCategory.Error, key: "'{0}' modifier must precede '{1}' modifier." },
|
||||
_0_modifier_already_seen: { code: 1030, category: DiagnosticCategory.Error, key: "'{0}' modifier already seen." },
|
||||
_0_modifier_cannot_appear_on_a_class_element: { code: 1031, category: DiagnosticCategory.Error, key: "'{0}' modifier cannot appear on a class element." },
|
||||
An_interface_declaration_cannot_have_an_implements_clause: { code: 1032, category: DiagnosticCategory.Error, key: "An interface declaration cannot have an 'implements' clause." },
|
||||
super_must_be_followed_by_an_argument_list_or_member_access: { code: 1034, category: DiagnosticCategory.Error, key: "'super' must be followed by an argument list or member access." },
|
||||
Only_ambient_modules_can_use_quoted_names: { code: 1035, category: DiagnosticCategory.Error, key: "Only ambient modules can use quoted names." },
|
||||
Statements_are_not_allowed_in_ambient_contexts: { code: 1036, category: DiagnosticCategory.Error, key: "Statements are not allowed in ambient contexts." },
|
||||
@@ -104,7 +99,6 @@ namespace ts {
|
||||
case_or_default_expected: { code: 1130, category: DiagnosticCategory.Error, key: "'case' or 'default' expected." },
|
||||
Property_or_signature_expected: { code: 1131, category: DiagnosticCategory.Error, key: "Property or signature expected." },
|
||||
Enum_member_expected: { code: 1132, category: DiagnosticCategory.Error, key: "Enum member expected." },
|
||||
Type_reference_expected: { code: 1133, category: DiagnosticCategory.Error, key: "Type reference expected." },
|
||||
Variable_declaration_expected: { code: 1134, category: DiagnosticCategory.Error, key: "Variable declaration expected." },
|
||||
Argument_expression_expected: { code: 1135, category: DiagnosticCategory.Error, key: "Argument expression expected." },
|
||||
Property_assignment_expected: { code: 1136, category: DiagnosticCategory.Error, key: "Property assignment expected." },
|
||||
@@ -121,9 +115,6 @@ namespace ts {
|
||||
Cannot_compile_modules_unless_the_module_flag_is_provided: { code: 1148, category: DiagnosticCategory.Error, key: "Cannot compile modules unless the '--module' flag is provided." },
|
||||
File_name_0_differs_from_already_included_file_name_1_only_in_casing: { code: 1149, category: DiagnosticCategory.Error, key: "File name '{0}' differs from already included file name '{1}' only in casing" },
|
||||
new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 1150, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead." },
|
||||
var_let_or_const_expected: { code: 1152, category: DiagnosticCategory.Error, key: "'var', 'let' or 'const' expected." },
|
||||
let_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1153, category: DiagnosticCategory.Error, key: "'let' declarations are only available when targeting ECMAScript 6 and higher." },
|
||||
const_declarations_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1154, category: DiagnosticCategory.Error, key: "'const' declarations are only available when targeting ECMAScript 6 and higher." },
|
||||
const_declarations_must_be_initialized: { code: 1155, category: DiagnosticCategory.Error, key: "'const' declarations must be initialized" },
|
||||
const_declarations_can_only_be_declared_inside_a_block: { code: 1156, category: DiagnosticCategory.Error, key: "'const' declarations can only be declared inside a block." },
|
||||
let_declarations_can_only_be_declared_inside_a_block: { code: 1157, category: DiagnosticCategory.Error, key: "'let' declarations can only be declared inside a block." },
|
||||
@@ -134,7 +125,6 @@ namespace ts {
|
||||
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." },
|
||||
Computed_property_names_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1167, category: DiagnosticCategory.Error, key: "Computed property names are only available when targeting ECMAScript 6 and higher." },
|
||||
A_computed_property_name_in_a_method_overload_must_directly_refer_to_a_built_in_symbol: { code: 1168, category: DiagnosticCategory.Error, key: "A computed property name in a method overload must directly refer to a built-in symbol." },
|
||||
A_computed_property_name_in_an_interface_must_directly_refer_to_a_built_in_symbol: { code: 1169, category: DiagnosticCategory.Error, key: "A computed property name in an interface must directly refer to a built-in symbol." },
|
||||
A_computed_property_name_in_a_type_literal_must_directly_refer_to_a_built_in_symbol: { code: 1170, category: DiagnosticCategory.Error, key: "A computed property name in a type literal must directly refer to a built-in symbol." },
|
||||
@@ -150,7 +140,6 @@ namespace ts {
|
||||
Property_destructuring_pattern_expected: { code: 1180, category: DiagnosticCategory.Error, key: "Property destructuring pattern expected." },
|
||||
Array_element_destructuring_pattern_expected: { code: 1181, category: DiagnosticCategory.Error, key: "Array element destructuring pattern expected." },
|
||||
A_destructuring_declaration_must_have_an_initializer: { code: 1182, category: DiagnosticCategory.Error, key: "A destructuring declaration must have an initializer." },
|
||||
Destructuring_declarations_are_not_allowed_in_ambient_contexts: { code: 1183, category: DiagnosticCategory.Error, key: "Destructuring declarations are not allowed in ambient contexts." },
|
||||
An_implementation_cannot_be_declared_in_ambient_contexts: { code: 1184, category: DiagnosticCategory.Error, key: "An implementation cannot be declared in ambient contexts." },
|
||||
Modifiers_cannot_appear_here: { code: 1184, category: DiagnosticCategory.Error, key: "Modifiers cannot appear here." },
|
||||
Merge_conflict_marker_encountered: { code: 1185, category: DiagnosticCategory.Error, key: "Merge conflict marker encountered." },
|
||||
@@ -205,6 +194,12 @@ namespace ts {
|
||||
with_statements_are_not_allowed_in_an_async_function_block: { code: 1300, category: DiagnosticCategory.Error, key: "'with' statements are not allowed in an async function block." },
|
||||
await_expression_is_only_allowed_within_an_async_function: { code: 1308, category: DiagnosticCategory.Error, key: "'await' expression is only allowed within an async function." },
|
||||
Async_functions_are_only_available_when_targeting_ECMAScript_6_and_higher: { code: 1311, category: DiagnosticCategory.Error, key: "Async functions are only available when targeting ECMAScript 6 and higher." },
|
||||
The_return_type_of_a_property_decorator_function_must_be_either_void_or_any: { code: 1236, category: DiagnosticCategory.Error, key: "The return type of a property decorator function must be either 'void' or 'any'." },
|
||||
The_return_type_of_a_parameter_decorator_function_must_be_either_void_or_any: { code: 1237, category: DiagnosticCategory.Error, key: "The return type of a parameter decorator function must be either 'void' or 'any'." },
|
||||
Unable_to_resolve_signature_of_class_decorator_when_called_as_an_expression: { code: 1238, category: DiagnosticCategory.Error, key: "Unable to resolve signature of class decorator when called as an expression." },
|
||||
Unable_to_resolve_signature_of_parameter_decorator_when_called_as_an_expression: { code: 1239, category: DiagnosticCategory.Error, key: "Unable to resolve signature of parameter decorator when called as an expression." },
|
||||
Unable_to_resolve_signature_of_property_decorator_when_called_as_an_expression: { code: 1240, category: DiagnosticCategory.Error, key: "Unable to resolve signature of property decorator when called as an expression." },
|
||||
Unable_to_resolve_signature_of_method_decorator_when_called_as_an_expression: { code: 1241, category: DiagnosticCategory.Error, key: "Unable to resolve signature of method decorator when called as an expression." },
|
||||
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." },
|
||||
@@ -213,7 +208,6 @@ namespace ts {
|
||||
Module_0_has_no_exported_member_1: { code: 2305, category: DiagnosticCategory.Error, key: "Module '{0}' has no exported member '{1}'." },
|
||||
File_0_is_not_a_module: { code: 2306, category: DiagnosticCategory.Error, key: "File '{0}' is not a module." },
|
||||
Cannot_find_module_0: { code: 2307, category: DiagnosticCategory.Error, key: "Cannot find module '{0}'." },
|
||||
A_module_cannot_have_more_than_one_export_assignment: { code: 2308, category: DiagnosticCategory.Error, key: "A module cannot have more than one export assignment." },
|
||||
An_export_assignment_cannot_be_used_in_a_module_with_other_exported_elements: { code: 2309, category: DiagnosticCategory.Error, key: "An export assignment cannot be used in a module with other exported elements." },
|
||||
Type_0_recursively_references_itself_as_a_base_type: { code: 2310, category: DiagnosticCategory.Error, key: "Type '{0}' recursively references itself as a base type." },
|
||||
A_class_may_only_extend_another_class: { code: 2311, category: DiagnosticCategory.Error, key: "A class may only extend another class." },
|
||||
@@ -398,11 +392,26 @@ namespace ts {
|
||||
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." },
|
||||
_0_is_referenced_directly_or_indirectly_in_its_own_base_expression: { code: 2506, category: DiagnosticCategory.Error, key: "'{0}' is referenced directly or indirectly in its own base expression." },
|
||||
Type_0_is_not_a_constructor_function_type: { code: 2507, category: DiagnosticCategory.Error, key: "Type '{0}' is not a constructor function type." },
|
||||
No_base_constructor_has_the_specified_number_of_type_arguments: { code: 2508, category: DiagnosticCategory.Error, key: "No base constructor has the specified number of type arguments." },
|
||||
Base_constructor_return_type_0_is_not_a_class_or_interface_type: { code: 2509, category: DiagnosticCategory.Error, key: "Base constructor return type '{0}' is not a class or interface type." },
|
||||
Base_constructors_must_all_have_the_same_return_type: { code: 2510, category: DiagnosticCategory.Error, key: "Base constructors must all have the same return type." },
|
||||
Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: { code: 2520, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions." },
|
||||
Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions: { code: 2521, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '{0}' that compiler uses to support async functions." },
|
||||
The_arguments_object_cannot_be_referenced_in_an_async_arrow_function_Consider_using_a_standard_async_function_expression: { code: 2522, category: DiagnosticCategory.Error, key: "The 'arguments' object cannot be referenced in an async arrow function. Consider using a standard async function expression." },
|
||||
yield_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2523, category: DiagnosticCategory.Error, key: "'yield' expressions cannot be used in a parameter initializer." },
|
||||
await_expressions_cannot_be_used_in_a_parameter_initializer: { code: 2524, category: DiagnosticCategory.Error, key: "'await' expressions cannot be used in a parameter initializer." },
|
||||
JSX_element_attributes_type_0_must_be_an_object_type: { code: 2600, category: DiagnosticCategory.Error, key: "JSX element attributes type '{0}' must be an object type." },
|
||||
The_return_type_of_a_JSX_element_constructor_must_return_an_object_type: { code: 2601, category: DiagnosticCategory.Error, key: "The return type of a JSX element constructor must return an object type." },
|
||||
JSX_element_implicitly_has_type_any_because_the_global_type_JSX_Element_does_not_exist: { code: 2602, category: DiagnosticCategory.Error, key: "JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist." },
|
||||
Property_0_in_type_1_is_not_assignable_to_type_2: { code: 2603, category: DiagnosticCategory.Error, key: "Property '{0}' in type '{1}' is not assignable to type '{2}'" },
|
||||
JSX_element_type_0_does_not_have_any_construct_or_call_signatures: { code: 2604, category: DiagnosticCategory.Error, key: "JSX element type '{0}' does not have any construct or call signatures." },
|
||||
JSX_element_type_0_is_not_a_constructor_function_for_JSX_elements: { code: 2605, category: DiagnosticCategory.Error, key: "JSX element type '{0}' is not a constructor function for JSX elements." },
|
||||
Property_0_of_JSX_spread_attribute_is_not_assignable_to_target_property: { code: 2606, category: DiagnosticCategory.Error, key: "Property '{0}' of JSX spread attribute is not assignable to target property." },
|
||||
JSX_element_class_does_not_support_attributes_because_it_does_not_have_a_0_property: { code: 2607, category: DiagnosticCategory.Error, key: "JSX element class does not support attributes because it does not have a '{0}' property" },
|
||||
The_global_type_JSX_0_may_not_have_more_than_one_property: { code: 2608, category: DiagnosticCategory.Error, key: "The global type 'JSX.{0}' may not have more than one property" },
|
||||
Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" },
|
||||
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}'." },
|
||||
@@ -539,12 +548,13 @@ namespace ts {
|
||||
File_0_has_unsupported_extension_The_only_supported_extensions_are_1: { code: 6054, category: DiagnosticCategory.Error, key: "File '{0}' has unsupported extension. The only supported extensions are {1}." },
|
||||
Suppress_noImplicitAny_errors_for_indexing_objects_lacking_index_signatures: { code: 6055, category: DiagnosticCategory.Message, key: "Suppress noImplicitAny errors for indexing objects lacking index signatures." },
|
||||
Do_not_emit_declarations_for_code_that_has_an_internal_annotation: { code: 6056, category: DiagnosticCategory.Message, key: "Do not emit declarations for code that has an '@internal' annotation." },
|
||||
Preserve_new_lines_when_emitting_code: { code: 6057, category: DiagnosticCategory.Message, key: "Preserve new-lines when emitting code." },
|
||||
Specifies_the_root_directory_of_input_files_Use_to_control_the_output_directory_structure_with_outDir: { code: 6058, category: DiagnosticCategory.Message, key: "Specifies the root directory of input files. Use to control the output directory structure with --outDir." },
|
||||
File_0_is_not_under_rootDir_1_rootDir_is_expected_to_contain_all_source_files: { code: 6059, category: DiagnosticCategory.Error, key: "File '{0}' is not under 'rootDir' '{1}'. 'rootDir' is expected to contain all source files." },
|
||||
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'." },
|
||||
Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: DiagnosticCategory.Message, key: "Specify JSX code generation: 'preserve' or 'react'" },
|
||||
Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." },
|
||||
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." },
|
||||
@@ -566,6 +576,7 @@ namespace ts {
|
||||
_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." },
|
||||
JSX_element_implicitly_has_type_any_because_no_interface_JSX_0_exists: { code: 7026, category: DiagnosticCategory.Error, key: "JSX element implicitly has type 'any' because no interface 'JSX.{0}' exists" },
|
||||
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." },
|
||||
@@ -585,5 +596,10 @@ namespace ts {
|
||||
decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." },
|
||||
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." },
|
||||
JSX_attributes_must_only_be_assigned_a_non_empty_expression: { code: 17000, category: DiagnosticCategory.Error, key: "JSX attributes must only be assigned a non-empty 'expression'." },
|
||||
JSX_elements_cannot_have_multiple_attributes_with_the_same_name: { code: 17001, category: DiagnosticCategory.Error, key: "JSX elements cannot have multiple attributes with the same name." },
|
||||
Expected_corresponding_JSX_closing_tag_for_0: { code: 17002, category: DiagnosticCategory.Error, key: "Expected corresponding JSX closing tag for '{0}'." },
|
||||
JSX_attribute_expected: { code: 17003, category: DiagnosticCategory.Error, key: "JSX attribute expected." },
|
||||
Cannot_use_JSX_unless_the_jsx_flag_is_provided: { code: 17004, category: DiagnosticCategory.Error, key: "Cannot use JSX unless the '--jsx' flag is provided." },
|
||||
};
|
||||
}
|
||||
@@ -67,22 +67,6 @@
|
||||
"category": "Error",
|
||||
"code": 1023
|
||||
},
|
||||
"A class or interface declaration can only have one 'extends' clause.": {
|
||||
"category": "Error",
|
||||
"code": 1024
|
||||
},
|
||||
"An 'extends' clause must precede an 'implements' clause.": {
|
||||
"category": "Error",
|
||||
"code": 1025
|
||||
},
|
||||
"A class can only extend a single class.": {
|
||||
"category": "Error",
|
||||
"code": 1026
|
||||
},
|
||||
"A class declaration can only have one 'implements' clause.": {
|
||||
"category": "Error",
|
||||
"code": 1027
|
||||
},
|
||||
"Accessibility modifier already seen.": {
|
||||
"category": "Error",
|
||||
"code": 1028
|
||||
@@ -99,10 +83,6 @@
|
||||
"category": "Error",
|
||||
"code": 1031
|
||||
},
|
||||
"An interface declaration cannot have an 'implements' clause.": {
|
||||
"category": "Error",
|
||||
"code": 1032
|
||||
},
|
||||
"'super' must be followed by an argument list or member access.": {
|
||||
"category": "Error",
|
||||
"code": 1034
|
||||
@@ -403,10 +383,6 @@
|
||||
"category": "Error",
|
||||
"code": 1132
|
||||
},
|
||||
"Type reference expected.": {
|
||||
"category": "Error",
|
||||
"code": 1133
|
||||
},
|
||||
"Variable declaration expected.": {
|
||||
"category": "Error",
|
||||
"code": 1134
|
||||
@@ -471,18 +447,6 @@
|
||||
"category": "Error",
|
||||
"code": 1150
|
||||
},
|
||||
"'var', 'let' or 'const' expected.": {
|
||||
"category": "Error",
|
||||
"code": 1152
|
||||
},
|
||||
"'let' declarations are only available when targeting ECMAScript 6 and higher.": {
|
||||
"category": "Error",
|
||||
"code": 1153
|
||||
},
|
||||
"'const' declarations are only available when targeting ECMAScript 6 and higher.": {
|
||||
"category": "Error",
|
||||
"code": 1154
|
||||
},
|
||||
"'const' declarations must be initialized": {
|
||||
"category": "Error",
|
||||
"code": 1155
|
||||
@@ -523,10 +487,6 @@
|
||||
"category": "Error",
|
||||
"code": 1166
|
||||
},
|
||||
"Computed property names are only available when targeting ECMAScript 6 and higher.": {
|
||||
"category": "Error",
|
||||
"code": 1167
|
||||
},
|
||||
"A computed property name in a method overload must directly refer to a built-in symbol.": {
|
||||
"category": "Error",
|
||||
"code": 1168
|
||||
@@ -587,10 +547,6 @@
|
||||
"category": "Error",
|
||||
"code": 1182
|
||||
},
|
||||
"Destructuring declarations are not allowed in ambient contexts.": {
|
||||
"category": "Error",
|
||||
"code": 1183
|
||||
},
|
||||
"An implementation cannot be declared in ambient contexts.": {
|
||||
"category": "Error",
|
||||
"code": 1184
|
||||
@@ -726,7 +682,7 @@
|
||||
"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
|
||||
@@ -810,6 +766,31 @@
|
||||
"code": 1311
|
||||
},
|
||||
|
||||
"The return type of a property decorator function must be either 'void' or 'any'.": {
|
||||
"category": "Error",
|
||||
"code": 1236
|
||||
},
|
||||
"The return type of a parameter decorator function must be either 'void' or 'any'.": {
|
||||
"category": "Error",
|
||||
"code": 1237
|
||||
},
|
||||
"Unable to resolve signature of class decorator when called as an expression.": {
|
||||
"category": "Error",
|
||||
"code": 1238
|
||||
},
|
||||
"Unable to resolve signature of parameter decorator when called as an expression.": {
|
||||
"category": "Error",
|
||||
"code": 1239
|
||||
},
|
||||
"Unable to resolve signature of property decorator when called as an expression.": {
|
||||
"category": "Error",
|
||||
"code": 1240
|
||||
},
|
||||
"Unable to resolve signature of method decorator when called as an expression.": {
|
||||
"category": "Error",
|
||||
"code": 1241
|
||||
},
|
||||
|
||||
"Duplicate identifier '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 2300
|
||||
@@ -842,10 +823,6 @@
|
||||
"category": "Error",
|
||||
"code": 2307
|
||||
},
|
||||
"A module cannot have more than one export assignment.": {
|
||||
"category": "Error",
|
||||
"code": 2308
|
||||
},
|
||||
"An export assignment cannot be used in a module with other exported elements.": {
|
||||
"category": "Error",
|
||||
"code": 2309
|
||||
@@ -1582,6 +1559,27 @@
|
||||
"category": "Error",
|
||||
"code": 2505
|
||||
},
|
||||
"'{0}' is referenced directly or indirectly in its own base expression.": {
|
||||
"category": "Error",
|
||||
"code": 2506
|
||||
},
|
||||
"Type '{0}' is not a constructor function type.": {
|
||||
"category": "Error",
|
||||
"code": 2507
|
||||
},
|
||||
"No base constructor has the specified number of type arguments.": {
|
||||
"category": "Error",
|
||||
"code": 2508
|
||||
},
|
||||
"Base constructor return type '{0}' is not a class or interface type.": {
|
||||
"category": "Error",
|
||||
"code": 2509
|
||||
},
|
||||
"Base constructors must all have the same return type.": {
|
||||
"category": "Error",
|
||||
"code": 2510
|
||||
},
|
||||
|
||||
"Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions.": {
|
||||
"category": "Error",
|
||||
"code": 2520
|
||||
@@ -1603,6 +1601,47 @@
|
||||
"code": 2524
|
||||
},
|
||||
|
||||
"JSX element attributes type '{0}' must be an object type.": {
|
||||
"category": "Error",
|
||||
"code": 2600
|
||||
},
|
||||
"The return type of a JSX element constructor must return an object type.": {
|
||||
"category": "Error",
|
||||
"code": 2601
|
||||
},
|
||||
"JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist.": {
|
||||
"category": "Error",
|
||||
"code": 2602
|
||||
},
|
||||
"Property '{0}' in type '{1}' is not assignable to type '{2}'": {
|
||||
"category": "Error",
|
||||
"code": 2603
|
||||
},
|
||||
"JSX element type '{0}' does not have any construct or call signatures.": {
|
||||
"category": "Error",
|
||||
"code": 2604
|
||||
},
|
||||
"JSX element type '{0}' is not a constructor function for JSX elements.": {
|
||||
"category": "Error",
|
||||
"code": 2605
|
||||
},
|
||||
"Property '{0}' of JSX spread attribute is not assignable to target property.": {
|
||||
"category": "Error",
|
||||
"code": 2606
|
||||
},
|
||||
"JSX element class does not support attributes because it does not have a '{0}' property": {
|
||||
"category": "Error",
|
||||
"code": 2607
|
||||
},
|
||||
"The global type 'JSX.{0}' may not have more than one property": {
|
||||
"category": "Error",
|
||||
"code": 2608
|
||||
},
|
||||
"Cannot emit namespaced JSX elements in React": {
|
||||
"category": "Error",
|
||||
"code": 2650
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4000
|
||||
@@ -1971,7 +2010,7 @@
|
||||
"category": "Error",
|
||||
"code": 5050
|
||||
},
|
||||
"Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.": {
|
||||
"Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.": {
|
||||
"category": "Error",
|
||||
"code": 5051
|
||||
},
|
||||
@@ -2148,10 +2187,6 @@
|
||||
"category": "Message",
|
||||
"code": 6056
|
||||
},
|
||||
"Preserve new-lines when emitting code.": {
|
||||
"category": "Message",
|
||||
"code": 6057
|
||||
},
|
||||
"Specifies the root directory of input files. Use to control the output directory structure with --outDir.": {
|
||||
"category": "Message",
|
||||
"code": 6058
|
||||
@@ -2164,14 +2199,22 @@
|
||||
"category": "Message",
|
||||
"code": 6060
|
||||
},
|
||||
"NEWLINE": {
|
||||
"category": "Message",
|
||||
"NEWLINE": {
|
||||
"category": "Message",
|
||||
"code": 6061
|
||||
},
|
||||
"Argument for '--newLine' option must be 'CRLF' or 'LF'.": {
|
||||
"category": "Error",
|
||||
"category": "Error",
|
||||
"code": 6062
|
||||
},
|
||||
"Specify JSX code generation: 'preserve' or 'react'": {
|
||||
"category": "Message",
|
||||
"code": 6080
|
||||
},
|
||||
"Argument for '--jsx' must be 'preserve' or 'react'.": {
|
||||
"category": "Message",
|
||||
"code": 6081
|
||||
},
|
||||
"Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified.": {
|
||||
"category": "Error",
|
||||
"code": 6064
|
||||
@@ -2257,6 +2300,12 @@
|
||||
"category": "Error",
|
||||
"code": 7025
|
||||
},
|
||||
"JSX element implicitly has type 'any' because no interface 'JSX.{0}' exists": {
|
||||
"category": "Error",
|
||||
"code": 7026
|
||||
},
|
||||
|
||||
|
||||
"You cannot rename this element.": {
|
||||
"category": "Error",
|
||||
"code": 8000
|
||||
@@ -2333,5 +2382,25 @@
|
||||
"'class' expressions are not currently supported.": {
|
||||
"category": "Error",
|
||||
"code": 9003
|
||||
},
|
||||
"JSX attributes must only be assigned a non-empty 'expression'.": {
|
||||
"category": "Error",
|
||||
"code": 17000
|
||||
},
|
||||
"JSX elements cannot have multiple attributes with the same name.": {
|
||||
"category": "Error",
|
||||
"code": 17001
|
||||
},
|
||||
"Expected corresponding JSX closing tag for '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 17002
|
||||
},
|
||||
"JSX attribute expected.": {
|
||||
"category": "Error",
|
||||
"code": 17003
|
||||
},
|
||||
"Cannot use JSX unless the '--jsx' flag is provided.": {
|
||||
"category": "Error",
|
||||
"code": 17004
|
||||
}
|
||||
}
|
||||
|
||||
+398
-40
@@ -21,8 +21,7 @@ namespace ts {
|
||||
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 __();
|
||||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
||||
};`;
|
||||
|
||||
// emit output for the __decorate helper function
|
||||
@@ -68,11 +67,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
let sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap || compilerOptions.inlineSourceMap ? [] : undefined;
|
||||
let diagnostics: Diagnostic[] = [];
|
||||
let newLine = host.getNewLine();
|
||||
let jsxDesugaring = host.getCompilerOptions().jsx !== JsxEmit.Preserve;
|
||||
let shouldEmitJsx = (s: SourceFile) => (s.languageVariant === LanguageVariant.JSX && !jsxDesugaring);
|
||||
|
||||
if (targetSourceFile === undefined) {
|
||||
forEach(host.getSourceFiles(), sourceFile => {
|
||||
if (shouldEmitToOwnFile(sourceFile, compilerOptions)) {
|
||||
let jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, ".js");
|
||||
let jsFilePath = getOwnEmitOutputFilePath(sourceFile, host, shouldEmitJsx(sourceFile) ? ".jsx" : ".js");
|
||||
emitFile(jsFilePath, sourceFile);
|
||||
}
|
||||
});
|
||||
@@ -84,7 +85,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
else {
|
||||
// targetSourceFile is specified (e.g calling emitter from language service or calling getSemanticDiagnostic from language service)
|
||||
if (shouldEmitToOwnFile(targetSourceFile, compilerOptions)) {
|
||||
let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, ".js");
|
||||
let jsFilePath = getOwnEmitOutputFilePath(targetSourceFile, host, forEach(host.getSourceFiles(), shouldEmitJsx) ? ".jsx" : ".js");
|
||||
emitFile(jsFilePath, targetSourceFile);
|
||||
}
|
||||
else if (!isDeclarationFile(targetSourceFile) && compilerOptions.out) {
|
||||
@@ -281,6 +282,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
return makeUniqueName("default");
|
||||
}
|
||||
|
||||
function generateNameForClassExpression() {
|
||||
return makeUniqueName("class");
|
||||
}
|
||||
|
||||
function generateNameForNode(node: Node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
@@ -293,9 +298,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
return generateNameForImportOrExportDeclaration(<ImportDeclaration | ExportDeclaration>node);
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.ExportAssignment:
|
||||
return generateNameForExportDefault();
|
||||
case SyntaxKind.ClassExpression:
|
||||
return generateNameForClassExpression();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -336,7 +342,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
|
||||
let prevEncodedEmittedColumn = lastEncodedSourceMapSpan.emittedColumn;
|
||||
// Line/Comma delimiters
|
||||
if (lastEncodedSourceMapSpan.emittedLine == lastRecordedSourceMapSpan.emittedLine) {
|
||||
if (lastEncodedSourceMapSpan.emittedLine === lastRecordedSourceMapSpan.emittedLine) {
|
||||
// Emit comma to separate the entry
|
||||
if (sourceMapData.sourceMapMappings) {
|
||||
sourceMapData.sourceMapMappings += ",";
|
||||
@@ -419,8 +425,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
|
||||
// If this location wasn't recorded or the location in source is going backwards, record the span
|
||||
if (!lastRecordedSourceMapSpan ||
|
||||
lastRecordedSourceMapSpan.emittedLine != emittedLine ||
|
||||
lastRecordedSourceMapSpan.emittedColumn != emittedColumn ||
|
||||
lastRecordedSourceMapSpan.emittedLine !== emittedLine ||
|
||||
lastRecordedSourceMapSpan.emittedColumn !== emittedColumn ||
|
||||
(lastRecordedSourceMapSpan.sourceIndex === sourceMapSourceIndex &&
|
||||
(lastRecordedSourceMapSpan.sourceLine > sourceLinePos.line ||
|
||||
(lastRecordedSourceMapSpan.sourceLine === sourceLinePos.line && lastRecordedSourceMapSpan.sourceColumn > sourceLinePos.character)))) {
|
||||
@@ -670,7 +676,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
if (nodeIsSynthesized(node)) {
|
||||
return emitNodeWithoutSourceMap(node);
|
||||
}
|
||||
if (node.kind != SyntaxKind.SourceFile) {
|
||||
if (node.kind !== SyntaxKind.SourceFile) {
|
||||
recordEmitNodeStartSpan(node);
|
||||
emitNodeWithoutSourceMap(node);
|
||||
recordEmitNodeEndSpan(node);
|
||||
@@ -1123,6 +1129,224 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
emit(span.literal);
|
||||
}
|
||||
|
||||
function jsxEmitReact(node: JsxElement|JsxSelfClosingElement) {
|
||||
/// Emit a tag name, which is either '"div"' for lower-cased names, or
|
||||
/// 'Div' for upper-cased or dotted names
|
||||
function emitTagName(name: Identifier|QualifiedName) {
|
||||
if (name.kind === SyntaxKind.Identifier && isIntrinsicJsxName((<Identifier>name).text)) {
|
||||
write('"');
|
||||
emit(name);
|
||||
write('"');
|
||||
}
|
||||
else {
|
||||
emit(name);
|
||||
}
|
||||
}
|
||||
|
||||
/// Emit an attribute name, which is quoted if it needs to be quoted. Because
|
||||
/// these emit into an object literal property name, we don't need to be worried
|
||||
/// about keywords, just non-identifier characters
|
||||
function emitAttributeName(name: Identifier) {
|
||||
if (/[A-Za-z_]+[\w*]/.test(name.text)) {
|
||||
write('"');
|
||||
emit(name);
|
||||
write('"');
|
||||
}
|
||||
else {
|
||||
emit(name);
|
||||
}
|
||||
}
|
||||
|
||||
/// Emit an name/value pair for an attribute (e.g. "x: 3")
|
||||
function emitJsxAttribute(node: JsxAttribute) {
|
||||
emitAttributeName(node.name);
|
||||
write(": ");
|
||||
if (node.initializer) {
|
||||
emit(node.initializer);
|
||||
}
|
||||
else {
|
||||
write("true");
|
||||
}
|
||||
}
|
||||
|
||||
function emitJsxElement(openingNode: JsxOpeningLikeElement, children?: JsxChild[]) {
|
||||
// Call React.createElement(tag, ...
|
||||
emitLeadingComments(openingNode);
|
||||
write("React.createElement(");
|
||||
emitTagName(openingNode.tagName);
|
||||
write(", ");
|
||||
|
||||
// Attribute list
|
||||
if (openingNode.attributes.length === 0) {
|
||||
// When there are no attributes, React wants "null"
|
||||
write("null");
|
||||
}
|
||||
else {
|
||||
// Either emit one big object literal (no spread attribs), or
|
||||
// a call to React.__spread
|
||||
let attrs = openingNode.attributes;
|
||||
if (forEach(attrs, attr => attr.kind === SyntaxKind.JsxSpreadAttribute)) {
|
||||
write("React.__spread(");
|
||||
|
||||
let haveOpenedObjectLiteral = false;
|
||||
for (let i = 0; i < attrs.length; i++) {
|
||||
if (attrs[i].kind === SyntaxKind.JsxSpreadAttribute) {
|
||||
// If this is the first argument, we need to emit a {} as the first argument
|
||||
if (i === 0) {
|
||||
write("{}, ");
|
||||
}
|
||||
|
||||
if (haveOpenedObjectLiteral) {
|
||||
write("}");
|
||||
haveOpenedObjectLiteral = false;
|
||||
}
|
||||
if (i > 0) {
|
||||
write(", ");
|
||||
}
|
||||
emit((<JsxSpreadAttribute>attrs[i]).expression);
|
||||
}
|
||||
else {
|
||||
Debug.assert(attrs[i].kind === SyntaxKind.JsxAttribute);
|
||||
if (haveOpenedObjectLiteral) {
|
||||
write(", ");
|
||||
}
|
||||
else {
|
||||
haveOpenedObjectLiteral = true;
|
||||
if (i > 0) {
|
||||
write(", ");
|
||||
}
|
||||
write("{");
|
||||
}
|
||||
emitJsxAttribute(<JsxAttribute>attrs[i]);
|
||||
}
|
||||
}
|
||||
if (haveOpenedObjectLiteral) write("}");
|
||||
|
||||
write(")"); // closing paren to React.__spread(
|
||||
}
|
||||
else {
|
||||
// One object literal with all the attributes in them
|
||||
write("{");
|
||||
for (var i = 0; i < attrs.length; i++) {
|
||||
if (i > 0) {
|
||||
write(", ");
|
||||
}
|
||||
emitJsxAttribute(<JsxAttribute>attrs[i]);
|
||||
}
|
||||
write("}");
|
||||
}
|
||||
}
|
||||
|
||||
// Children
|
||||
if (children) {
|
||||
for (var i = 0; i < children.length; i++) {
|
||||
// Don't emit empty expressions
|
||||
if (children[i].kind === SyntaxKind.JsxExpression && !((<JsxExpression>children[i]).expression)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Don't emit empty strings
|
||||
if (children[i].kind === SyntaxKind.JsxText) {
|
||||
let text = getTextToEmit(<JsxText>children[i]);
|
||||
if(text !== undefined) {
|
||||
write(', "');
|
||||
write(text);
|
||||
write('"');
|
||||
}
|
||||
}
|
||||
else {
|
||||
write(", ");
|
||||
emit(children[i]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Closing paren
|
||||
write(")"); // closes "React.createElement("
|
||||
emitTrailingComments(openingNode);
|
||||
}
|
||||
|
||||
if (node.kind === SyntaxKind.JsxElement) {
|
||||
emitJsxElement((<JsxElement>node).openingElement, (<JsxElement>node).children);
|
||||
}
|
||||
else {
|
||||
Debug.assert(node.kind === SyntaxKind.JsxSelfClosingElement);
|
||||
emitJsxElement(<JsxSelfClosingElement>node);
|
||||
}
|
||||
}
|
||||
|
||||
function jsxEmitPreserve(node: JsxElement|JsxSelfClosingElement) {
|
||||
function emitJsxAttribute(node: JsxAttribute) {
|
||||
emit(node.name);
|
||||
write("=");
|
||||
emit(node.initializer);
|
||||
}
|
||||
|
||||
function emitJsxSpreadAttribute(node: JsxSpreadAttribute) {
|
||||
write("{...");
|
||||
emit(node.expression);
|
||||
write("}");
|
||||
}
|
||||
|
||||
function emitAttributes(attribs: NodeArray<JsxAttribute|JsxSpreadAttribute>) {
|
||||
for (let i = 0, n = attribs.length; i < n; i++) {
|
||||
if (i > 0) {
|
||||
write(" ");
|
||||
}
|
||||
|
||||
if (attribs[i].kind === SyntaxKind.JsxSpreadAttribute) {
|
||||
emitJsxSpreadAttribute(<JsxSpreadAttribute>attribs[i]);
|
||||
}
|
||||
else {
|
||||
Debug.assert(attribs[i].kind === SyntaxKind.JsxAttribute);
|
||||
emitJsxAttribute(<JsxAttribute>attribs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitJsxOpeningOrSelfClosingElement(node: JsxOpeningElement|JsxSelfClosingElement) {
|
||||
write("<");
|
||||
emit(node.tagName);
|
||||
if (node.attributes.length > 0 || (node.kind === SyntaxKind.JsxSelfClosingElement)) {
|
||||
write(" ");
|
||||
}
|
||||
|
||||
emitAttributes(node.attributes);
|
||||
|
||||
if (node.kind === SyntaxKind.JsxSelfClosingElement) {
|
||||
write("/>");
|
||||
}
|
||||
else {
|
||||
write(">");
|
||||
}
|
||||
}
|
||||
|
||||
function emitJsxClosingElement(node: JsxClosingElement) {
|
||||
write("</");
|
||||
emit(node.tagName);
|
||||
write(">");
|
||||
}
|
||||
|
||||
function emitJsxElement(node: JsxElement) {
|
||||
emitJsxOpeningOrSelfClosingElement(node.openingElement);
|
||||
|
||||
for (var i = 0, n = node.children.length; i < n; i++) {
|
||||
emit(node.children[i]);
|
||||
}
|
||||
|
||||
emitJsxClosingElement(node.closingElement);
|
||||
}
|
||||
|
||||
if (node.kind === SyntaxKind.JsxElement) {
|
||||
emitJsxElement(<JsxElement>node);
|
||||
}
|
||||
else {
|
||||
Debug.assert(node.kind === SyntaxKind.JsxSelfClosingElement);
|
||||
emitJsxOpeningOrSelfClosingElement(<JsxSelfClosingElement>node);
|
||||
}
|
||||
}
|
||||
|
||||
// This function specifically handles numeric/string literals for enum and accessor 'identifiers'.
|
||||
// In a sense, it does not actually emit identifiers as much as it declares a name for a specific property.
|
||||
// For example, this is utilized when feeding in a result to Object.defineProperty.
|
||||
@@ -1199,6 +1423,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
case SyntaxKind.ForInStatement:
|
||||
case SyntaxKind.ForOfStatement:
|
||||
case SyntaxKind.IfStatement:
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
case SyntaxKind.JsxOpeningElement:
|
||||
case SyntaxKind.NewExpression:
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
case SyntaxKind.PostfixUnaryExpression:
|
||||
@@ -1704,8 +1930,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
function parenthesizeForAccess(expr: Expression): LeftHandSideExpression {
|
||||
// When diagnosing whether the expression needs parentheses, the decision should be based
|
||||
// on the innermost expression in a chain of nested type assertions.
|
||||
while (expr.kind === SyntaxKind.TypeAssertionExpression) {
|
||||
expr = (<TypeAssertion>expr).expression;
|
||||
while (expr.kind === SyntaxKind.TypeAssertionExpression || expr.kind === SyntaxKind.AsExpression) {
|
||||
expr = (<AssertionExpression>expr).expression;
|
||||
}
|
||||
|
||||
// isLeftHandSideExpression is almost the correct criterion for when it is not necessary
|
||||
@@ -1824,7 +2050,21 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
|
||||
emit(node.expression);
|
||||
let indentedBeforeDot = indentIfOnDifferentLines(node, node.expression, node.dotToken);
|
||||
write(".");
|
||||
|
||||
// 1 .toString is a valid property access, emit a space after the literal
|
||||
let shouldEmitSpace: boolean;
|
||||
if (!indentedBeforeDot && node.expression.kind === SyntaxKind.NumericLiteral) {
|
||||
let text = getSourceTextOfNodeFromSourceFile(currentSourceFile, node.expression);
|
||||
shouldEmitSpace = text.indexOf(tokenToString(SyntaxKind.DotToken)) < 0;
|
||||
}
|
||||
|
||||
if (shouldEmitSpace) {
|
||||
write(" .");
|
||||
}
|
||||
else {
|
||||
write(".");
|
||||
}
|
||||
|
||||
let indentedAfterDot = indentIfOnDifferentLines(node, node.dotToken, node.name);
|
||||
emit(node.name);
|
||||
decreaseIndentIf(indentedBeforeDot, indentedAfterDot);
|
||||
@@ -1851,8 +2091,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
|
||||
function skipParentheses(node: Expression): Expression {
|
||||
while (node.kind === SyntaxKind.ParenthesizedExpression || node.kind === SyntaxKind.TypeAssertionExpression) {
|
||||
node = (<ParenthesizedExpression | TypeAssertion>node).expression;
|
||||
while (node.kind === SyntaxKind.ParenthesizedExpression || node.kind === SyntaxKind.TypeAssertionExpression || node.kind === SyntaxKind.AsExpression) {
|
||||
node = (<ParenthesizedExpression | AssertionExpression>node).expression;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
@@ -2002,12 +2242,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
// not the user. If we didn't want them, the emitter would not have put them
|
||||
// there.
|
||||
if (!nodeIsSynthesized(node) && node.parent.kind !== SyntaxKind.ArrowFunction) {
|
||||
if (node.expression.kind === SyntaxKind.TypeAssertionExpression) {
|
||||
if (node.expression.kind === SyntaxKind.TypeAssertionExpression || node.expression.kind === SyntaxKind.AsExpression) {
|
||||
let operand = (<TypeAssertion>node.expression).expression;
|
||||
|
||||
// Make sure we consider all nested cast expressions, e.g.:
|
||||
// (<any><number><any>-A).x;
|
||||
while (operand.kind == SyntaxKind.TypeAssertionExpression) {
|
||||
while (operand.kind === SyntaxKind.TypeAssertionExpression || operand.kind === SyntaxKind.AsExpression) {
|
||||
operand = (<TypeAssertion>operand).expression;
|
||||
}
|
||||
|
||||
@@ -3181,33 +3421,49 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
function emitDefaultValueAssignments(node: FunctionLikeDeclaration) {
|
||||
if (languageVersion < ScriptTarget.ES6) {
|
||||
let tempIndex = 0;
|
||||
forEach(node.parameters, p => {
|
||||
forEach(node.parameters, parameter => {
|
||||
// A rest parameter cannot have a binding pattern or an initializer,
|
||||
// so let's just ignore it.
|
||||
if (p.dotDotDotToken) {
|
||||
if (parameter.dotDotDotToken) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isBindingPattern(p.name)) {
|
||||
writeLine();
|
||||
write("var ");
|
||||
emitDestructuring(p, /*isAssignmentExpressionStatement*/ false, tempParameters[tempIndex]);
|
||||
write(";");
|
||||
tempIndex++;
|
||||
let { name: paramName, initializer } = parameter;
|
||||
if (isBindingPattern(paramName)) {
|
||||
// In cases where a binding pattern is simply '[]' or '{}',
|
||||
// we usually don't want to emit a var declaration; however, in the presence
|
||||
// of an initializer, we must emit that expression to preserve side effects.
|
||||
let hasBindingElements = paramName.elements.length > 0;
|
||||
if (hasBindingElements || initializer) {
|
||||
writeLine();
|
||||
write("var ");
|
||||
|
||||
if (hasBindingElements) {
|
||||
emitDestructuring(parameter, /*isAssignmentExpressionStatement*/ false, tempParameters[tempIndex]);
|
||||
}
|
||||
else {
|
||||
emit(tempParameters[tempIndex]);
|
||||
write(" = ");
|
||||
emit(initializer);
|
||||
}
|
||||
|
||||
write(";");
|
||||
tempIndex++;
|
||||
}
|
||||
}
|
||||
else if (p.initializer) {
|
||||
else if (initializer) {
|
||||
writeLine();
|
||||
emitStart(p);
|
||||
emitStart(parameter);
|
||||
write("if (");
|
||||
emitNodeWithoutSourceMap(p.name);
|
||||
emitNodeWithoutSourceMap(paramName);
|
||||
write(" === void 0)");
|
||||
emitEnd(p);
|
||||
emitEnd(parameter);
|
||||
write(" { ");
|
||||
emitStart(p);
|
||||
emitNodeWithoutSourceMap(p.name);
|
||||
emitStart(parameter);
|
||||
emitNodeWithoutSourceMap(paramName);
|
||||
write(" = ");
|
||||
emitNodeWithoutSourceMap(p.initializer);
|
||||
emitEnd(p);
|
||||
emitNodeWithoutSourceMap(initializer);
|
||||
emitEnd(parameter);
|
||||
write("; }");
|
||||
}
|
||||
});
|
||||
@@ -3990,7 +4246,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
emitClassLikeDeclarationForES6AndHigher(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function emitClassLikeDeclarationForES6AndHigher(node: ClassLikeDeclaration) {
|
||||
let thisNodeIsDecorated = nodeIsDecorated(node);
|
||||
if (node.kind === SyntaxKind.ClassDeclaration) {
|
||||
@@ -4249,7 +4505,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
write(".prototype");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function emitDecoratorsOfClass(node: ClassLikeDeclaration) {
|
||||
emitDecoratorsOfMembers(node, /*staticFlag*/ 0);
|
||||
emitDecoratorsOfMembers(node, NodeFlags.Static);
|
||||
@@ -5161,7 +5417,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
let started = false;
|
||||
for (let importNode of externalImports) {
|
||||
// do not create variable declaration for exports and imports that lack import clause
|
||||
let skipNode =
|
||||
let skipNode =
|
||||
importNode.kind === SyntaxKind.ExportDeclaration ||
|
||||
(importNode.kind === SyntaxKind.ImportDeclaration && !(<ImportDeclaration>importNode).importClause)
|
||||
|
||||
@@ -5258,7 +5514,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
write("};");
|
||||
|
||||
return emitExportStarFunction(exportedNamesStorageRef);
|
||||
|
||||
|
||||
function emitExportStarFunction(localNames: string): string {
|
||||
const exportStarFunction = makeUniqueName("exportStar");
|
||||
|
||||
@@ -5285,7 +5541,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
|
||||
return exportStarFunction;
|
||||
}
|
||||
|
||||
|
||||
function writeExportedName(node: Identifier | Declaration): void {
|
||||
// do not record default exports
|
||||
// they are local to module and never overwritten (explicitly skipped) by star export
|
||||
@@ -5530,7 +5786,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
decreaseIndent();
|
||||
writeLine();
|
||||
write("}"); // return
|
||||
emitTempDeclarations(/*newLine*/ true)
|
||||
emitTempDeclarations(/*newLine*/ true);
|
||||
}
|
||||
|
||||
function emitSetters(exportStarFunction: string) {
|
||||
@@ -5581,7 +5837,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
|
||||
if (importNode.kind === SyntaxKind.ImportDeclaration &&
|
||||
(<ImportDeclaration>importNode).importClause.namedBindings) {
|
||||
|
||||
|
||||
let namedBindings = (<ImportDeclaration>importNode).importClause.namedBindings;
|
||||
if (namedBindings.kind === SyntaxKind.NamespaceImport) {
|
||||
// emit re-export for namespace
|
||||
@@ -5840,6 +6096,99 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
}
|
||||
}
|
||||
|
||||
function emitJsxElement(node: JsxElement | JsxSelfClosingElement) {
|
||||
switch (compilerOptions.jsx) {
|
||||
case JsxEmit.React:
|
||||
jsxEmitReact(node);
|
||||
break;
|
||||
case JsxEmit.Preserve:
|
||||
// Fall back to preserve if None was specified (we'll error earlier)
|
||||
default:
|
||||
jsxEmitPreserve(node);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function trimReactWhitespace(node: JsxText): string {
|
||||
let result: string = undefined;
|
||||
let text = getTextOfNode(node);
|
||||
let firstNonWhitespace = 0;
|
||||
let lastNonWhitespace = -1;
|
||||
|
||||
// JSX trims whitespace at the end and beginning of lines, except that the
|
||||
// start/end of a tag is considered a start/end of a line only if that line is
|
||||
// on the same line as the closing tag. See examples in tests/cases/conformance/jsx/tsxReactEmitWhitespace.tsx
|
||||
for (let i = 0; i < text.length; i++) {
|
||||
let c = text.charCodeAt(i);
|
||||
if (isLineBreak(c)) {
|
||||
if (firstNonWhitespace !== -1 && (lastNonWhitespace - firstNonWhitespace + 1 > 0)) {
|
||||
let part = text.substr(firstNonWhitespace, lastNonWhitespace - firstNonWhitespace + 1);
|
||||
result = (result ? result + '" + \' \' + "' : '') + part;
|
||||
}
|
||||
firstNonWhitespace = -1;
|
||||
}
|
||||
else if (!isWhiteSpace(c)) {
|
||||
lastNonWhitespace = i;
|
||||
if (firstNonWhitespace === -1) {
|
||||
firstNonWhitespace = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (firstNonWhitespace !== -1) {
|
||||
let part = text.substr(firstNonWhitespace);
|
||||
result = (result ? result + '" + \' \' + "' : '') + part;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function getTextToEmit(node: JsxText) {
|
||||
switch (compilerOptions.jsx) {
|
||||
case JsxEmit.React:
|
||||
let text = trimReactWhitespace(node);
|
||||
if (text.length === 0) {
|
||||
return undefined;
|
||||
}
|
||||
else {
|
||||
return text;
|
||||
}
|
||||
case JsxEmit.Preserve:
|
||||
default:
|
||||
return getTextOfNode(node, true);
|
||||
}
|
||||
}
|
||||
|
||||
function emitJsxText(node: JsxText) {
|
||||
switch (compilerOptions.jsx) {
|
||||
case JsxEmit.React:
|
||||
write('"');
|
||||
write(trimReactWhitespace(node));
|
||||
write('"');
|
||||
break;
|
||||
|
||||
case JsxEmit.Preserve:
|
||||
default: // Emit JSX-preserve as default when no --jsx flag is specified
|
||||
write(getTextOfNode(node, true));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function emitJsxExpression(node: JsxExpression) {
|
||||
if (node.expression) {
|
||||
switch (compilerOptions.jsx) {
|
||||
case JsxEmit.Preserve:
|
||||
default:
|
||||
write('{');
|
||||
emit(node.expression);
|
||||
write('}');
|
||||
break;
|
||||
case JsxEmit.React:
|
||||
emit(node.expression);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitDirectivePrologues(statements: Node[], startWithNewLine: boolean): number {
|
||||
for (let i = 0; i < statements.length; ++i) {
|
||||
if (isPrologueDirective(statements[i])) {
|
||||
@@ -5987,7 +6336,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
if (node.kind !== SyntaxKind.Block &&
|
||||
node.parent &&
|
||||
node.parent.kind === SyntaxKind.ArrowFunction &&
|
||||
(<ArrowFunction>node.parent).body === node &&
|
||||
(<ArrowFunction>node.parent).body === node &&
|
||||
compilerOptions.target <= ScriptTarget.ES5) {
|
||||
|
||||
return false;
|
||||
@@ -6032,6 +6381,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
return emitTemplateExpression(<TemplateExpression>node);
|
||||
case SyntaxKind.TemplateSpan:
|
||||
return emitTemplateSpan(<TemplateSpan>node);
|
||||
case SyntaxKind.JsxElement:
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
return emitJsxElement(<JsxElement|JsxSelfClosingElement>node);
|
||||
case SyntaxKind.JsxText:
|
||||
return emitJsxText(<JsxText>node);
|
||||
case SyntaxKind.JsxExpression:
|
||||
return emitJsxExpression(<JsxExpression>node);
|
||||
case SyntaxKind.QualifiedName:
|
||||
return emitQualifiedName(<QualifiedName>node);
|
||||
case SyntaxKind.ObjectBindingPattern:
|
||||
@@ -6062,6 +6418,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, Promi
|
||||
return emitTaggedTemplateExpression(<TaggedTemplateExpression>node);
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
return emit((<TypeAssertion>node).expression);
|
||||
case SyntaxKind.AsExpression:
|
||||
return emit((<AsExpression>node).expression);
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
return emitParenExpression(<ParenthesizedExpression>node);
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
|
||||
+269
-7
@@ -164,6 +164,9 @@ namespace ts {
|
||||
return visitNode(cbNode, (<BinaryExpression>node).left) ||
|
||||
visitNode(cbNode, (<BinaryExpression>node).operatorToken) ||
|
||||
visitNode(cbNode, (<BinaryExpression>node).right);
|
||||
case SyntaxKind.AsExpression:
|
||||
return visitNode(cbNode, (<AsExpression>node).expression) ||
|
||||
visitNode(cbNode, (<AsExpression>node).type);
|
||||
case SyntaxKind.ConditionalExpression:
|
||||
return visitNode(cbNode, (<ConditionalExpression>node).condition) ||
|
||||
visitNode(cbNode, (<ConditionalExpression>node).questionToken) ||
|
||||
@@ -321,6 +324,25 @@ namespace ts {
|
||||
return visitNode(cbNode, (<ExternalModuleReference>node).expression);
|
||||
case SyntaxKind.MissingDeclaration:
|
||||
return visitNodes(cbNodes, node.decorators);
|
||||
|
||||
case SyntaxKind.JsxElement:
|
||||
return visitNode(cbNode, (<JsxElement>node).openingElement) ||
|
||||
visitNodes(cbNodes, (<JsxElement>node).children) ||
|
||||
visitNode(cbNode, (<JsxElement>node).closingElement);
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
case SyntaxKind.JsxOpeningElement:
|
||||
return visitNode(cbNode, (<JsxOpeningLikeElement>node).tagName) ||
|
||||
visitNodes(cbNodes, (<JsxOpeningLikeElement>node).attributes);
|
||||
case SyntaxKind.JsxAttribute:
|
||||
return visitNode(cbNode, (<JsxAttribute>node).name) ||
|
||||
visitNode(cbNode, (<JsxAttribute>node).initializer);
|
||||
case SyntaxKind.JsxSpreadAttribute:
|
||||
return visitNode(cbNode, (<JsxSpreadAttribute>node).expression);
|
||||
case SyntaxKind.JsxExpression:
|
||||
return visitNode(cbNode, (<JsxExpression>node).expression);
|
||||
case SyntaxKind.JsxClosingElement:
|
||||
return visitNode(cbNode, (<JsxClosingElement>node).tagName);
|
||||
|
||||
case SyntaxKind.JSDocTypeExpression:
|
||||
return visitNode(cbNode, (<JSDocTypeExpression>node).type);
|
||||
case SyntaxKind.JSDocUnionType:
|
||||
@@ -524,6 +546,7 @@ namespace ts {
|
||||
scanner.setText(sourceText);
|
||||
scanner.setOnError(scanError);
|
||||
scanner.setScriptTarget(languageVersion);
|
||||
scanner.setLanguageVariant(isTsx(fileName) ? LanguageVariant.JSX : LanguageVariant.Standard);
|
||||
}
|
||||
|
||||
function clearState() {
|
||||
@@ -636,6 +659,7 @@ namespace ts {
|
||||
sourceFile.languageVersion = languageVersion;
|
||||
sourceFile.fileName = normalizePath(fileName);
|
||||
sourceFile.flags = fileExtensionIs(sourceFile.fileName, ".d.ts") ? NodeFlags.DeclarationFile : 0;
|
||||
sourceFile.languageVariant = isTsx(sourceFile.fileName) ? LanguageVariant.JSX : LanguageVariant.Standard;
|
||||
|
||||
return sourceFile;
|
||||
}
|
||||
@@ -815,6 +839,10 @@ namespace ts {
|
||||
return token = scanner.reScanTemplateToken();
|
||||
}
|
||||
|
||||
function scanJsxIdentifier(): SyntaxKind {
|
||||
return token = scanner.scanJsxIdentifier();
|
||||
}
|
||||
|
||||
function speculationHelper<T>(callback: () => T, isLookAhead: boolean): T {
|
||||
// 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).
|
||||
@@ -1179,6 +1207,10 @@ namespace ts {
|
||||
return isHeritageClause();
|
||||
case ParsingContext.ImportOrExportSpecifiers:
|
||||
return isIdentifierOrKeyword();
|
||||
case ParsingContext.JsxAttributes:
|
||||
return isIdentifierOrKeyword() || token === SyntaxKind.OpenBraceToken;
|
||||
case ParsingContext.JsxChildren:
|
||||
return true;
|
||||
case ParsingContext.JSDocFunctionParameters:
|
||||
case ParsingContext.JSDocTypeArguments:
|
||||
case ParsingContext.JSDocTupleTypes:
|
||||
@@ -1269,6 +1301,10 @@ namespace ts {
|
||||
return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.OpenParenToken;
|
||||
case ParsingContext.HeritageClauses:
|
||||
return token === SyntaxKind.OpenBraceToken || token === SyntaxKind.CloseBraceToken;
|
||||
case ParsingContext.JsxAttributes:
|
||||
return token === SyntaxKind.GreaterThanToken || token === SyntaxKind.SlashToken;
|
||||
case ParsingContext.JsxChildren:
|
||||
return token === SyntaxKind.LessThanToken && lookAhead(nextTokenIsSlash);
|
||||
case ParsingContext.JSDocFunctionParameters:
|
||||
return token === SyntaxKind.CloseParenToken || token === SyntaxKind.ColonToken || token === SyntaxKind.CloseBraceToken;
|
||||
case ParsingContext.JSDocTypeArguments:
|
||||
@@ -1485,6 +1521,12 @@ namespace ts {
|
||||
// name list, and there can be left hand side expressions (which can have type
|
||||
// arguments.)
|
||||
case ParsingContext.HeritageClauseElement:
|
||||
|
||||
// Perhaps safe to reuse, but it's unlikely we'd see more than a dozen attributes
|
||||
// on any given element. Same for children.
|
||||
case ParsingContext.JsxAttributes:
|
||||
case ParsingContext.JsxChildren:
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -1495,12 +1537,20 @@ namespace ts {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.IndexSignature:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.SemicolonClassElement:
|
||||
return true;
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
// Method declarations are not necessarily reusable. An object-literal
|
||||
// may have a method calls "constructor(...)" and we must reparse that
|
||||
// into an actual .ConstructorDeclaration.
|
||||
let methodDeclaration = <MethodDeclaration>node;
|
||||
let nameIsConstructor = methodDeclaration.name.kind === SyntaxKind.Identifier &&
|
||||
(<Identifier>methodDeclaration.name).originalKeywordKind === SyntaxKind.ConstructorKeyword;
|
||||
|
||||
return !nameIsConstructor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1643,6 +1693,8 @@ namespace 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.JsxAttributes: return Diagnostics.Identifier_expected;
|
||||
case ParsingContext.JsxChildren: 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;
|
||||
@@ -2803,6 +2855,33 @@ namespace ts {
|
||||
return Tristate.False;
|
||||
}
|
||||
|
||||
// JSX overrides
|
||||
if (sourceFile.languageVariant === LanguageVariant.JSX) {
|
||||
let isArrowFunctionInJsx = lookAhead(() => {
|
||||
let third = nextToken();
|
||||
if (third === SyntaxKind.ExtendsKeyword) {
|
||||
let fourth = nextToken();
|
||||
switch (fourth) {
|
||||
case SyntaxKind.EqualsToken:
|
||||
case SyntaxKind.GreaterThanToken:
|
||||
return false;
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (third === SyntaxKind.CommaToken) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
if (isArrowFunctionInJsx) {
|
||||
return Tristate.True;
|
||||
}
|
||||
|
||||
return Tristate.False;
|
||||
}
|
||||
|
||||
// This *could* be a parenthesized arrow function.
|
||||
return Tristate.Unknown;
|
||||
}
|
||||
@@ -2924,7 +3003,23 @@ namespace ts {
|
||||
break;
|
||||
}
|
||||
|
||||
leftOperand = makeBinaryExpression(leftOperand, parseTokenNode(), parseBinaryExpressionOrHigher(newPrecedence));
|
||||
if (token === SyntaxKind.AsKeyword) {
|
||||
// Make sure we *do* perform ASI for constructs like this:
|
||||
// var x = foo
|
||||
// as (Bar)
|
||||
// This should be parsed as an initialized variable, followed
|
||||
// by a function call to 'as' with the argument 'Bar'
|
||||
if (scanner.hasPrecedingLineBreak()) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
nextToken();
|
||||
leftOperand = makeAsExpression(leftOperand, parseType());
|
||||
}
|
||||
}
|
||||
else {
|
||||
leftOperand = makeBinaryExpression(leftOperand, parseTokenNode(), parseBinaryExpressionOrHigher(newPrecedence));
|
||||
}
|
||||
}
|
||||
|
||||
return leftOperand;
|
||||
@@ -2961,6 +3056,7 @@ namespace ts {
|
||||
case SyntaxKind.GreaterThanEqualsToken:
|
||||
case SyntaxKind.InstanceOfKeyword:
|
||||
case SyntaxKind.InKeyword:
|
||||
case SyntaxKind.AsKeyword:
|
||||
return 7;
|
||||
case SyntaxKind.LessThanLessThanToken:
|
||||
case SyntaxKind.GreaterThanGreaterThanToken:
|
||||
@@ -2988,6 +3084,13 @@ namespace ts {
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function makeAsExpression(left: Expression, right: TypeNode): AsExpression {
|
||||
let node = <AsExpression>createNode(SyntaxKind.AsExpression, left.pos);
|
||||
node.expression = left;
|
||||
node.type = right;
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parsePrefixUnaryExpression() {
|
||||
let node = <PrefixUnaryExpression>createNode(SyntaxKind.PrefixUnaryExpression);
|
||||
node.operator = token;
|
||||
@@ -3057,7 +3160,13 @@ namespace ts {
|
||||
case SyntaxKind.VoidKeyword:
|
||||
return parseVoidExpression();
|
||||
case SyntaxKind.LessThanToken:
|
||||
return parseTypeAssertion();
|
||||
if (sourceFile.languageVariant !== LanguageVariant.JSX) {
|
||||
return parseTypeAssertion();
|
||||
}
|
||||
if(lookAhead(nextTokenIsIdentifier)) {
|
||||
return parseJsxElementOrSelfClosingElement();
|
||||
}
|
||||
// Fall through
|
||||
default:
|
||||
return parsePostfixExpressionOrHigher();
|
||||
}
|
||||
@@ -3184,6 +3293,154 @@ namespace ts {
|
||||
node.name = parseRightSideOfDot(/*allowIdentifierNames*/ true);
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseJsxElementOrSelfClosingElement(): JsxElement|JsxSelfClosingElement {
|
||||
let opening = parseJsxOpeningOrSelfClosingElement();
|
||||
if (opening.kind === SyntaxKind.JsxOpeningElement) {
|
||||
let node = <JsxElement>createNode(SyntaxKind.JsxElement, opening.pos);
|
||||
node.openingElement = opening;
|
||||
|
||||
node.children = parseJsxChildren(node.openingElement.tagName);
|
||||
node.closingElement = parseJsxClosingElement();
|
||||
return finishNode(node);
|
||||
}
|
||||
else {
|
||||
Debug.assert(opening.kind === SyntaxKind.JsxSelfClosingElement);
|
||||
// Nothing else to do for self-closing elements
|
||||
return <JsxSelfClosingElement>opening;
|
||||
}
|
||||
}
|
||||
|
||||
function parseJsxText(): JsxText {
|
||||
let node = <JsxText>createNode(SyntaxKind.JsxText, scanner.getStartPos());
|
||||
token = scanner.scanJsxToken();
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseJsxChild(): JsxChild {
|
||||
switch (token) {
|
||||
case SyntaxKind.JsxText:
|
||||
return parseJsxText();
|
||||
case SyntaxKind.OpenBraceToken:
|
||||
return parseJsxExpression();
|
||||
case SyntaxKind.LessThanToken:
|
||||
return parseJsxElementOrSelfClosingElement();
|
||||
}
|
||||
Debug.fail('Unknown JSX child kind ' + token);
|
||||
}
|
||||
|
||||
function parseJsxChildren(openingTagName: EntityName): NodeArray<JsxChild> {
|
||||
let result = <NodeArray<JsxChild>>[];
|
||||
result.pos = scanner.getStartPos();
|
||||
let saveParsingContext = parsingContext;
|
||||
parsingContext |= 1 << ParsingContext.JsxChildren;
|
||||
|
||||
while(true) {
|
||||
token = scanner.reScanJsxToken();
|
||||
if (token === SyntaxKind.LessThanSlashToken) {
|
||||
break;
|
||||
}
|
||||
else if (token === SyntaxKind.EndOfFileToken) {
|
||||
parseErrorAtCurrentToken(Diagnostics.Expected_corresponding_JSX_closing_tag_for_0, getTextOfNodeFromSourceText(sourceText, openingTagName));
|
||||
break;
|
||||
}
|
||||
result.push(parseJsxChild());
|
||||
}
|
||||
|
||||
result.end = scanner.getTokenPos();
|
||||
|
||||
parsingContext = saveParsingContext;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function parseJsxOpeningOrSelfClosingElement(): JsxOpeningElement|JsxSelfClosingElement {
|
||||
let fullStart = scanner.getStartPos();
|
||||
|
||||
parseExpected(SyntaxKind.LessThanToken);
|
||||
|
||||
let tagName = parseJsxElementName();
|
||||
|
||||
let attributes = parseList(ParsingContext.JsxAttributes, parseJsxAttribute);
|
||||
let node: JsxOpeningLikeElement;
|
||||
|
||||
if (parseOptional(SyntaxKind.GreaterThanToken)) {
|
||||
node = <JsxOpeningElement>createNode(SyntaxKind.JsxOpeningElement, fullStart);
|
||||
}
|
||||
else {
|
||||
parseExpected(SyntaxKind.SlashToken);
|
||||
parseExpected(SyntaxKind.GreaterThanToken);
|
||||
node = <JsxSelfClosingElement>createNode(SyntaxKind.JsxSelfClosingElement, fullStart);
|
||||
}
|
||||
|
||||
node.tagName = tagName;
|
||||
node.attributes = attributes;
|
||||
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseJsxElementName(): EntityName {
|
||||
scanJsxIdentifier();
|
||||
let elementName: EntityName = parseIdentifier();
|
||||
while (parseOptional(SyntaxKind.DotToken)) {
|
||||
scanJsxIdentifier();
|
||||
let node = <QualifiedName>createNode(SyntaxKind.QualifiedName, elementName.pos);
|
||||
node.left = elementName;
|
||||
node.right = parseIdentifierName();
|
||||
elementName = finishNode(node);
|
||||
}
|
||||
return elementName;
|
||||
}
|
||||
|
||||
function parseJsxExpression(): JsxExpression {
|
||||
let node = <JsxExpression>createNode(SyntaxKind.JsxExpression);
|
||||
|
||||
parseExpected(SyntaxKind.OpenBraceToken);
|
||||
if (token !== SyntaxKind.CloseBraceToken) {
|
||||
node.expression = parseExpression();
|
||||
}
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseJsxAttribute(): JsxAttribute | JsxSpreadAttribute {
|
||||
if (token === SyntaxKind.OpenBraceToken) {
|
||||
return parseJsxSpreadAttribute();
|
||||
}
|
||||
|
||||
scanJsxIdentifier();
|
||||
let node = <JsxAttribute>createNode(SyntaxKind.JsxAttribute);
|
||||
node.name = parseIdentifierName();
|
||||
if (parseOptional(SyntaxKind.EqualsToken)) {
|
||||
switch (token) {
|
||||
case SyntaxKind.StringLiteral:
|
||||
node.initializer = parseLiteralNode();
|
||||
break;
|
||||
default:
|
||||
node.initializer = parseJsxExpression();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseJsxSpreadAttribute(): JsxSpreadAttribute {
|
||||
let node = <JsxSpreadAttribute>createNode(SyntaxKind.JsxSpreadAttribute);
|
||||
parseExpected(SyntaxKind.OpenBraceToken);
|
||||
parseExpected(SyntaxKind.DotDotDotToken);
|
||||
node.expression = parseExpression();
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseJsxClosingElement(): JsxClosingElement {
|
||||
let node = <JsxClosingElement>createNode(SyntaxKind.JsxClosingElement);
|
||||
parseExpected(SyntaxKind.LessThanSlashToken);
|
||||
node.tagName = parseJsxElementName();
|
||||
parseExpected(SyntaxKind.GreaterThanToken);
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parseTypeAssertion(): TypeAssertion {
|
||||
let node = <TypeAssertion>createNode(SyntaxKind.TypeAssertionExpression);
|
||||
@@ -4060,7 +4317,7 @@ namespace ts {
|
||||
parseExportAssignment(fullStart, decorators, modifiers) :
|
||||
parseExportDeclaration(fullStart, decorators, modifiers);
|
||||
default:
|
||||
if (decorators) {
|
||||
if (decorators || modifiers) {
|
||||
// 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 = <Statement>createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected);
|
||||
@@ -4485,7 +4742,7 @@ namespace ts {
|
||||
return parsePropertyOrMethodDeclaration(fullStart, decorators, modifiers);
|
||||
}
|
||||
|
||||
if (decorators) {
|
||||
if (decorators || modifiers) {
|
||||
// treat this as a property declaration with a missing name.
|
||||
let name = <Identifier>createMissingNode(SyntaxKind.Identifier, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected);
|
||||
return parsePropertyDeclaration(fullStart, decorators, modifiers, name, /*questionToken*/ undefined);
|
||||
@@ -4682,6 +4939,10 @@ namespace ts {
|
||||
return nextToken() === SyntaxKind.OpenParenToken;
|
||||
}
|
||||
|
||||
function nextTokenIsSlash() {
|
||||
return nextToken() === SyntaxKind.SlashToken;
|
||||
}
|
||||
|
||||
function nextTokenIsCommaOrFromKeyword() {
|
||||
nextToken();
|
||||
return token === SyntaxKind.CommaToken ||
|
||||
@@ -4882,7 +5143,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function processReferenceComments(sourceFile: SourceFile): void {
|
||||
let triviaScanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/false, sourceText);
|
||||
let triviaScanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/false, LanguageVariant.Standard, sourceText);
|
||||
let referencedFiles: FileReference[] = [];
|
||||
let amdDependencies: { path: string; name: string }[] = [];
|
||||
let amdModuleName: string;
|
||||
@@ -4969,6 +5230,8 @@ namespace ts {
|
||||
ArrayBindingElements, // Binding elements in array binding list
|
||||
ArgumentExpressions, // Expressions in argument list
|
||||
ObjectLiteralMembers, // Members in object literal
|
||||
JsxAttributes, // Attributes in jsx element
|
||||
JsxChildren, // Things between opening and closing JSX tags
|
||||
ArrayLiteralMembers, // Members in array literal
|
||||
Parameters, // Parameters in parameter list
|
||||
TypeParameters, // Type parameters in type parameter list
|
||||
@@ -5443,7 +5706,6 @@ namespace ts {
|
||||
let atToken = createNode(SyntaxKind.AtToken, pos - 1);
|
||||
atToken.end = pos;
|
||||
|
||||
let startPos = pos;
|
||||
let tagName = scanIdentifier();
|
||||
if (!tagName) {
|
||||
return;
|
||||
|
||||
+8
-10
@@ -105,7 +105,10 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function getPreEmitDiagnostics(program: Program, sourceFile?: SourceFile): Diagnostic[] {
|
||||
let diagnostics = program.getSyntacticDiagnostics(sourceFile).concat(program.getGlobalDiagnostics()).concat(program.getSemanticDiagnostics(sourceFile));
|
||||
let diagnostics = program.getOptionsDiagnostics().concat(
|
||||
program.getSyntacticDiagnostics(sourceFile),
|
||||
program.getGlobalDiagnostics(),
|
||||
program.getSemanticDiagnostics(sourceFile));
|
||||
|
||||
if (program.getCompilerOptions().declaration) {
|
||||
diagnostics.concat(program.getDeclarationDiagnostics(sourceFile));
|
||||
@@ -177,10 +180,10 @@ namespace ts {
|
||||
getSourceFiles: () => files,
|
||||
getCompilerOptions: () => options,
|
||||
getSyntacticDiagnostics,
|
||||
getOptionsDiagnostics,
|
||||
getGlobalDiagnostics,
|
||||
getSemanticDiagnostics,
|
||||
getDeclarationDiagnostics,
|
||||
getCompilerOptionsDiagnostics,
|
||||
getTypeChecker,
|
||||
getClassifiableNames,
|
||||
getDiagnosticsProducingTypeChecker,
|
||||
@@ -311,19 +314,15 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function getCompilerOptionsDiagnostics(): Diagnostic[] {
|
||||
function getOptionsDiagnostics(): Diagnostic[] {
|
||||
let allDiagnostics: Diagnostic[] = [];
|
||||
addRange(allDiagnostics, diagnostics.getGlobalDiagnostics());
|
||||
return sortAndDeduplicateDiagnostics(allDiagnostics);
|
||||
}
|
||||
|
||||
function getGlobalDiagnostics(): Diagnostic[] {
|
||||
let typeChecker = getDiagnosticsProducingTypeChecker();
|
||||
|
||||
let allDiagnostics: Diagnostic[] = [];
|
||||
addRange(allDiagnostics, typeChecker.getGlobalDiagnostics());
|
||||
addRange(allDiagnostics, diagnostics.getGlobalDiagnostics());
|
||||
|
||||
addRange(allDiagnostics, getDiagnosticsProducingTypeChecker().getGlobalDiagnostics());
|
||||
return sortAndDeduplicateDiagnostics(allDiagnostics);
|
||||
}
|
||||
|
||||
@@ -338,7 +337,6 @@ namespace ts {
|
||||
function processSourceFile(fileName: string, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number) {
|
||||
let start: number;
|
||||
let length: number;
|
||||
let extensions: string;
|
||||
let diagnosticArgument: string[];
|
||||
if (refEnd !== undefined && refPos !== undefined) {
|
||||
start = refPos;
|
||||
@@ -683,4 +681,4 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+98
-2
@@ -21,12 +21,16 @@ namespace ts {
|
||||
reScanGreaterToken(): SyntaxKind;
|
||||
reScanSlashToken(): SyntaxKind;
|
||||
reScanTemplateToken(): SyntaxKind;
|
||||
scanJsxIdentifier(): SyntaxKind;
|
||||
reScanJsxToken(): SyntaxKind;
|
||||
scanJsxToken(): SyntaxKind;
|
||||
scan(): SyntaxKind;
|
||||
// Sets the text for the scanner to scan. An optional subrange starting point and length
|
||||
// can be provided to have the scanner only scan a portion of the text.
|
||||
setText(text: string, start?: number, length?: number): void;
|
||||
setOnError(onError: ErrorCallback): void;
|
||||
setScriptTarget(scriptTarget: ScriptTarget): void;
|
||||
setLanguageVariant(variant: LanguageVariant): void;
|
||||
setTextPos(textPos: number): void;
|
||||
// Invokes the provided callback then unconditionally restores the scanner to the state it
|
||||
// was in immediately prior to invoking the callback. The result of invoking the callback
|
||||
@@ -132,6 +136,7 @@ namespace ts {
|
||||
"++": SyntaxKind.PlusPlusToken,
|
||||
"--": SyntaxKind.MinusMinusToken,
|
||||
"<<": SyntaxKind.LessThanLessThanToken,
|
||||
"</": SyntaxKind.LessThanSlashToken,
|
||||
">>": SyntaxKind.GreaterThanGreaterThanToken,
|
||||
">>>": SyntaxKind.GreaterThanGreaterThanGreaterThanToken,
|
||||
"&": SyntaxKind.AmpersandToken,
|
||||
@@ -378,8 +383,31 @@ namespace ts {
|
||||
return ch >= CharacterCodes._0 && ch <= CharacterCodes._7;
|
||||
}
|
||||
|
||||
export function couldStartTrivia(text: string, pos: number): boolean {
|
||||
// Keep in sync with skipTrivia
|
||||
let ch = text.charCodeAt(pos);
|
||||
switch (ch) {
|
||||
case CharacterCodes.carriageReturn:
|
||||
case CharacterCodes.lineFeed:
|
||||
case CharacterCodes.tab:
|
||||
case CharacterCodes.verticalTab:
|
||||
case CharacterCodes.formFeed:
|
||||
case CharacterCodes.space:
|
||||
case CharacterCodes.slash:
|
||||
// starts of normal trivia
|
||||
case CharacterCodes.lessThan:
|
||||
case CharacterCodes.equals:
|
||||
case CharacterCodes.greaterThan:
|
||||
// Starts of conflict marker trivia
|
||||
return true;
|
||||
default:
|
||||
return ch > CharacterCodes.maxAsciiCharacter;
|
||||
}
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function skipTrivia(text: string, pos: number, stopAfterLineBreak?: boolean): number {
|
||||
// Keep in sync with couldStartTrivia
|
||||
while (true) {
|
||||
let ch = text.charCodeAt(pos);
|
||||
switch (ch) {
|
||||
@@ -600,11 +628,12 @@ namespace ts {
|
||||
ch >= CharacterCodes._0 && ch <= CharacterCodes._9 || ch === CharacterCodes.$ || ch === CharacterCodes._ ||
|
||||
ch > CharacterCodes.maxAsciiCharacter && isUnicodeIdentifierPart(ch, languageVersion);
|
||||
}
|
||||
|
||||
|
||||
/* @internal */
|
||||
// Creates a scanner over a (possibly unspecified) range of a piece of text.
|
||||
export function createScanner(languageVersion: ScriptTarget,
|
||||
skipTrivia: boolean,
|
||||
languageVariant = LanguageVariant.Standard,
|
||||
text?: string,
|
||||
onError?: ErrorCallback,
|
||||
start?: number,
|
||||
@@ -644,9 +673,13 @@ namespace ts {
|
||||
reScanGreaterToken,
|
||||
reScanSlashToken,
|
||||
reScanTemplateToken,
|
||||
scanJsxIdentifier,
|
||||
reScanJsxToken,
|
||||
scanJsxToken,
|
||||
scan,
|
||||
setText,
|
||||
setScriptTarget,
|
||||
setLanguageVariant,
|
||||
setOnError,
|
||||
setTextPos,
|
||||
tryScan,
|
||||
@@ -936,7 +969,7 @@ namespace ts {
|
||||
error(Diagnostics.Unexpected_end_of_text);
|
||||
isInvalidExtendedEscape = true;
|
||||
}
|
||||
else if (text.charCodeAt(pos) == CharacterCodes.closeBrace) {
|
||||
else if (text.charCodeAt(pos) === CharacterCodes.closeBrace) {
|
||||
// Only swallow the following character up if it's a '}'.
|
||||
pos++;
|
||||
}
|
||||
@@ -1281,6 +1314,9 @@ namespace ts {
|
||||
if (text.charCodeAt(pos + 1) === CharacterCodes.equals) {
|
||||
return pos += 2, token = SyntaxKind.LessThanEqualsToken;
|
||||
}
|
||||
if (text.charCodeAt(pos + 1) === CharacterCodes.slash && languageVariant === LanguageVariant.JSX) {
|
||||
return pos += 2, token = SyntaxKind.LessThanSlashToken;
|
||||
}
|
||||
return pos++, token = SyntaxKind.LessThanToken;
|
||||
case CharacterCodes.equals:
|
||||
if (isConflictMarkerTrivia(text, pos)) {
|
||||
@@ -1460,6 +1496,62 @@ namespace ts {
|
||||
return token = scanTemplateAndSetTokenValue();
|
||||
}
|
||||
|
||||
function reScanJsxToken(): SyntaxKind {
|
||||
pos = tokenPos = startPos;
|
||||
return token = scanJsxToken();
|
||||
}
|
||||
|
||||
function scanJsxToken(): SyntaxKind {
|
||||
startPos = tokenPos = pos;
|
||||
|
||||
if (pos >= end) {
|
||||
return token = SyntaxKind.EndOfFileToken;
|
||||
}
|
||||
|
||||
let char = text.charCodeAt(pos);
|
||||
if (char === CharacterCodes.lessThan) {
|
||||
if (text.charCodeAt(pos + 1) === CharacterCodes.slash) {
|
||||
pos += 2;
|
||||
return token = SyntaxKind.LessThanSlashToken;
|
||||
}
|
||||
pos++;
|
||||
return token = SyntaxKind.LessThanToken;
|
||||
}
|
||||
|
||||
if (char === CharacterCodes.openBrace) {
|
||||
pos++;
|
||||
return token = SyntaxKind.OpenBraceToken;
|
||||
}
|
||||
|
||||
while (pos < end) {
|
||||
pos++;
|
||||
char = text.charCodeAt(pos);
|
||||
if ((char === CharacterCodes.openBrace) || (char === CharacterCodes.lessThan)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return token = SyntaxKind.JsxText;
|
||||
}
|
||||
|
||||
// Scans a JSX identifier; these differ from normal identifiers in that
|
||||
// they allow dashes
|
||||
function scanJsxIdentifier(): SyntaxKind {
|
||||
if (token === SyntaxKind.Identifier) {
|
||||
let firstCharPosition = pos;
|
||||
while (pos < end) {
|
||||
let ch = text.charCodeAt(pos);
|
||||
if (ch === CharacterCodes.minus || ((firstCharPosition === pos) ? isIdentifierStart(ch) : isIdentifierPart(ch))) {
|
||||
pos++;
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
tokenValue += text.substr(firstCharPosition, pos - firstCharPosition);
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
function speculationHelper<T>(callback: () => T, isLookahead: boolean): T {
|
||||
let savePos = pos;
|
||||
let saveStartPos = startPos;
|
||||
@@ -1504,6 +1596,10 @@ namespace ts {
|
||||
languageVersion = scriptTarget;
|
||||
}
|
||||
|
||||
function setLanguageVariant(variant: LanguageVariant) {
|
||||
languageVariant = variant;
|
||||
}
|
||||
|
||||
function setTextPos(textPos: number) {
|
||||
Debug.assert(textPos >= 0);
|
||||
pos = textPos;
|
||||
|
||||
+2
-1
@@ -191,7 +191,8 @@ namespace ts {
|
||||
return sys.exit(ExitStatus.Success);
|
||||
}
|
||||
|
||||
if (commandLine.options.watch) {
|
||||
// Firefox has Object.prototype.watch
|
||||
if (commandLine.options.watch && commandLine.options.hasOwnProperty("watch")) {
|
||||
if (!sys.watchFile) {
|
||||
reportDiagnostic(createCompilerDiagnostic(Diagnostics.The_current_host_does_not_support_the_0_option, "--watch"));
|
||||
return sys.exit(ExitStatus.DiagnosticsPresent_OutputsSkipped);
|
||||
|
||||
+101
-8
@@ -48,6 +48,7 @@ namespace ts {
|
||||
SemicolonToken,
|
||||
CommaToken,
|
||||
LessThanToken,
|
||||
LessThanSlashToken,
|
||||
GreaterThanToken,
|
||||
LessThanEqualsToken,
|
||||
GreaterThanEqualsToken,
|
||||
@@ -220,6 +221,8 @@ namespace ts {
|
||||
ClassExpression,
|
||||
OmittedExpression,
|
||||
ExpressionWithTypeArguments,
|
||||
AsExpression,
|
||||
|
||||
// Misc
|
||||
TemplateSpan,
|
||||
SemicolonClassElement,
|
||||
@@ -268,6 +271,16 @@ namespace ts {
|
||||
// Module references
|
||||
ExternalModuleReference,
|
||||
|
||||
//JSX
|
||||
JsxElement,
|
||||
JsxSelfClosingElement,
|
||||
JsxOpeningElement,
|
||||
JsxText,
|
||||
JsxClosingElement,
|
||||
JsxAttribute,
|
||||
JsxSpreadAttribute,
|
||||
JsxExpression,
|
||||
|
||||
// Clauses
|
||||
CaseClause,
|
||||
DefaultClause,
|
||||
@@ -403,6 +416,17 @@ namespace ts {
|
||||
HasAggregatedChildData = 1 << 7
|
||||
}
|
||||
|
||||
export const enum JsxFlags {
|
||||
None = 0,
|
||||
IntrinsicNamedElement = 1 << 0,
|
||||
IntrinsicIndexedElement = 1 << 1,
|
||||
ClassElement = 1 << 2,
|
||||
UnknownElement = 1 << 3,
|
||||
|
||||
IntrinsicElement = IntrinsicNamedElement | IntrinsicIndexedElement
|
||||
}
|
||||
|
||||
|
||||
/* @internal */
|
||||
export const enum RelationComparisonResult {
|
||||
Succeeded = 1, // Should be truthy
|
||||
@@ -808,13 +832,66 @@ namespace ts {
|
||||
template: LiteralExpression | TemplateExpression;
|
||||
}
|
||||
|
||||
export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression;
|
||||
export type CallLikeExpression = CallExpression | NewExpression | TaggedTemplateExpression | Decorator;
|
||||
|
||||
export interface AsExpression extends Expression {
|
||||
expression: Expression;
|
||||
type: TypeNode;
|
||||
}
|
||||
|
||||
export interface TypeAssertion extends UnaryExpression {
|
||||
type: TypeNode;
|
||||
expression: UnaryExpression;
|
||||
}
|
||||
|
||||
export type AssertionExpression = TypeAssertion | AsExpression;
|
||||
|
||||
/// A JSX expression of the form <TagName attrs>...</TagName>
|
||||
export interface JsxElement extends PrimaryExpression {
|
||||
openingElement: JsxOpeningElement;
|
||||
children: NodeArray<JsxChild>;
|
||||
closingElement: JsxClosingElement;
|
||||
}
|
||||
|
||||
/// The opening element of a <Tag>...</Tag> JsxElement
|
||||
export interface JsxOpeningElement extends Expression {
|
||||
_openingElementBrand?: any;
|
||||
tagName: EntityName;
|
||||
attributes: NodeArray<JsxAttribute | JsxSpreadAttribute>;
|
||||
}
|
||||
|
||||
/// A JSX expression of the form <TagName attrs />
|
||||
export interface JsxSelfClosingElement extends PrimaryExpression, JsxOpeningElement {
|
||||
_selfClosingElementBrand?: any;
|
||||
}
|
||||
|
||||
/// Either the opening tag in a <Tag>...</Tag> pair, or the lone <Tag /> in a self-closing form
|
||||
export type JsxOpeningLikeElement = JsxSelfClosingElement | JsxOpeningElement;
|
||||
|
||||
export interface JsxAttribute extends Node {
|
||||
name: Identifier;
|
||||
/// JSX attribute initializers are optional; <X y /> is sugar for <X y={true} />
|
||||
initializer?: Expression;
|
||||
}
|
||||
|
||||
export interface JsxSpreadAttribute extends Node {
|
||||
expression: Expression;
|
||||
}
|
||||
|
||||
export interface JsxClosingElement extends Node {
|
||||
tagName: EntityName;
|
||||
}
|
||||
|
||||
export interface JsxExpression extends Expression {
|
||||
expression?: Expression;
|
||||
}
|
||||
|
||||
export interface JsxText extends Node {
|
||||
_jsxTextExpressionBrand: any;
|
||||
}
|
||||
|
||||
export type JsxChild = JsxText | JsxExpression | JsxElement | JsxSelfClosingElement;
|
||||
|
||||
export interface Statement extends Node {
|
||||
_statementBrand: any;
|
||||
}
|
||||
@@ -1155,6 +1232,7 @@ namespace ts {
|
||||
amdDependencies: {path: string; name: string}[];
|
||||
moduleName: string;
|
||||
referencedFiles: FileReference[];
|
||||
languageVariant: LanguageVariant;
|
||||
|
||||
/**
|
||||
* lib.d.ts should have a reference comment like
|
||||
@@ -1223,11 +1301,11 @@ namespace ts {
|
||||
*/
|
||||
emit(targetSourceFile?: SourceFile, writeFile?: WriteFileCallback): EmitResult;
|
||||
|
||||
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getOptionsDiagnostics(): Diagnostic[];
|
||||
getGlobalDiagnostics(): Diagnostic[];
|
||||
getSyntacticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getSemanticDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
/* @internal */ getCompilerOptionsDiagnostics(): Diagnostic[];
|
||||
|
||||
/**
|
||||
* Gets a type checker that can be used to semantically analyze source fils in the program.
|
||||
@@ -1334,6 +1412,9 @@ namespace ts {
|
||||
getAliasedSymbol(symbol: Symbol): Symbol;
|
||||
getExportsOfModule(moduleSymbol: Symbol): Symbol[];
|
||||
|
||||
getJsxElementAttributesType(elementNode: JsxOpeningLikeElement): Type;
|
||||
getJsxIntrinsicTagNames(): Symbol[];
|
||||
|
||||
// Should not be called directly. Should only be accessed through the Program instance.
|
||||
/* @internal */ getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
|
||||
/* @internal */ getGlobalDiagnostics(): Diagnostic[];
|
||||
@@ -1619,6 +1700,8 @@ namespace ts {
|
||||
assignmentChecks?: Map<boolean>; // Cache of assignment checks
|
||||
hasReportedStatementInAmbientContext?: boolean; // Cache boolean if we report statements in ambient context
|
||||
importOnRightSide?: Symbol; // for import declarations - import that appear on the right side
|
||||
jsxFlags?: JsxFlags; // flags for knowning what kind of element/attributes we're dealing with
|
||||
resolvedJsxType?: Type; // resolved element attributes type of a JSX openinglike element
|
||||
}
|
||||
|
||||
export const enum TypeFlags {
|
||||
@@ -1685,10 +1768,8 @@ namespace ts {
|
||||
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 {
|
||||
baseTypes: ObjectType[];
|
||||
resolvedBaseConstructorType?: Type; // Resolved base constructor type of class
|
||||
resolvedBaseTypes: ObjectType[]; // Resolved base types
|
||||
}
|
||||
|
||||
export interface InterfaceTypeWithDeclaredMembers extends InterfaceType {
|
||||
@@ -1852,6 +1933,7 @@ namespace ts {
|
||||
help?: boolean;
|
||||
inlineSourceMap?: boolean;
|
||||
inlineSources?: boolean;
|
||||
jsx?: JsxEmit;
|
||||
listFiles?: boolean;
|
||||
locale?: string;
|
||||
mapRoot?: string;
|
||||
@@ -1896,11 +1978,17 @@ namespace ts {
|
||||
System = 4,
|
||||
}
|
||||
|
||||
export const enum JsxEmit {
|
||||
None = 0,
|
||||
Preserve = 1,
|
||||
React = 2
|
||||
}
|
||||
|
||||
export const enum NewLineKind {
|
||||
CarriageReturnLineFeed = 0,
|
||||
LineFeed = 1,
|
||||
}
|
||||
|
||||
|
||||
export interface LineAndCharacter {
|
||||
line: number;
|
||||
/*
|
||||
@@ -1916,6 +2004,11 @@ namespace ts {
|
||||
Latest = ES6,
|
||||
}
|
||||
|
||||
export const enum LanguageVariant {
|
||||
Standard,
|
||||
JSX
|
||||
}
|
||||
|
||||
export interface ParsedCommandLine {
|
||||
options: CompilerOptions;
|
||||
fileNames: string[];
|
||||
|
||||
+58
-32
@@ -42,7 +42,7 @@ namespace ts {
|
||||
// Pool writers to avoid needing to allocate them for every symbol we write.
|
||||
let stringWriters: StringSymbolWriter[] = [];
|
||||
export function getSingleLineStringWriter(): StringSymbolWriter {
|
||||
if (stringWriters.length == 0) {
|
||||
if (stringWriters.length === 0) {
|
||||
let str = "";
|
||||
|
||||
let writeText: (text: string) => void = text => str += text;
|
||||
@@ -169,13 +169,13 @@ namespace ts {
|
||||
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.decorators.end);
|
||||
}
|
||||
|
||||
export function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node): string {
|
||||
export function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node, includeTrivia = false): string {
|
||||
if (nodeIsMissing(node)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
let text = sourceFile.text;
|
||||
return text.substring(skipTrivia(text, node.pos), node.end);
|
||||
return text.substring(includeTrivia ? node.pos : skipTrivia(text, node.pos), node.end);
|
||||
}
|
||||
|
||||
export function getTextOfNodeFromSourceText(sourceText: string, node: Node): string {
|
||||
@@ -186,8 +186,8 @@ namespace ts {
|
||||
return sourceText.substring(skipTrivia(sourceText, node.pos), node.end);
|
||||
}
|
||||
|
||||
export function getTextOfNode(node: Node): string {
|
||||
return getSourceTextOfNodeFromSourceFile(getSourceFileOfNode(node), node);
|
||||
export function getTextOfNode(node: Node, includeTrivia = false): string {
|
||||
return getSourceTextOfNodeFromSourceFile(getSourceFileOfNode(node), node, includeTrivia);
|
||||
}
|
||||
|
||||
// Add an extra underscore to identifiers that start with two underscores to avoid issues with magic names like '__proto__'
|
||||
@@ -274,7 +274,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function getSpanOfTokenAtPosition(sourceFile: SourceFile, pos: number): TextSpan {
|
||||
let scanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.text, /*onError:*/ undefined, pos);
|
||||
let scanner = createScanner(sourceFile.languageVersion, /*skipTrivia*/ true, sourceFile.languageVariant, sourceFile.text, /*onError:*/ undefined, pos);
|
||||
scanner.scan();
|
||||
let start = scanner.getTokenPos();
|
||||
return createTextSpanFromBounds(start, scanner.getTextPos());
|
||||
@@ -426,7 +426,7 @@ namespace ts {
|
||||
// Specialized signatures can have string literals as their parameters' type names
|
||||
return node.parent.kind === SyntaxKind.Parameter;
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
return true;
|
||||
return !isExpressionWithTypeArgumentsInClassExtendsClause(node);
|
||||
|
||||
// Identifiers and qualified names may be type nodes, depending on their context. Climb
|
||||
// above them to find the lowest container
|
||||
@@ -460,7 +460,7 @@ namespace ts {
|
||||
}
|
||||
switch (parent.kind) {
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
return true;
|
||||
return !isExpressionWithTypeArgumentsInClassExtendsClause(parent);
|
||||
case SyntaxKind.TypeParameter:
|
||||
return node === (<TypeParameterDeclaration>parent).constraint;
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
@@ -542,6 +542,7 @@ namespace ts {
|
||||
case SyntaxKind.ModuleDeclaration:
|
||||
case SyntaxKind.TypeAliasDeclaration:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
// 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.
|
||||
@@ -579,26 +580,15 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function isAccessor(node: Node): boolean {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return node && (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor);
|
||||
}
|
||||
|
||||
export function isClassLike(node: Node): boolean {
|
||||
if (node) {
|
||||
return node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression;
|
||||
}
|
||||
return node && (node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression);
|
||||
}
|
||||
|
||||
export function isFunctionLike(node: Node): boolean {
|
||||
@@ -620,7 +610,6 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -640,7 +629,16 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function getContainingClass(node: Node): ClassLikeDeclaration {
|
||||
while (true) {
|
||||
node = node.parent;
|
||||
if (!node || isClassLike(node)) {
|
||||
return <ClassLikeDeclaration>node;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function getThisContainer(node: Node, includeArrowFunctions: boolean): Node {
|
||||
while (true) {
|
||||
node = node.parent;
|
||||
@@ -653,7 +651,7 @@ namespace ts {
|
||||
// then the computed property is not a 'this' container.
|
||||
// A computed property name in a class needs to be a this container
|
||||
// so that we can error on it.
|
||||
if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
|
||||
if (isClassLike(node.parent.parent)) {
|
||||
return node;
|
||||
}
|
||||
// If this is a computed property, then the parent should not
|
||||
@@ -708,7 +706,7 @@ namespace ts {
|
||||
// then the computed property is not a 'super' container.
|
||||
// A computed property name in a class needs to be a super container
|
||||
// so that we can error on it.
|
||||
if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
|
||||
if (isClassLike(node.parent.parent)) {
|
||||
return node;
|
||||
}
|
||||
// If this is a computed property, then the parent should not
|
||||
@@ -770,8 +768,8 @@ namespace ts {
|
||||
return (<TaggedTemplateExpression>node).tag;
|
||||
}
|
||||
|
||||
// Will either be a CallExpression or NewExpression.
|
||||
return (<CallExpression>node).expression;
|
||||
// Will either be a CallExpression, NewExpression, or Decorator.
|
||||
return (<CallExpression | Decorator>node).expression;
|
||||
}
|
||||
|
||||
export function nodeCanBeDecorated(node: Node): boolean {
|
||||
@@ -866,6 +864,7 @@ namespace ts {
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
case SyntaxKind.TaggedTemplateExpression:
|
||||
case SyntaxKind.AsExpression:
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
@@ -882,13 +881,14 @@ namespace ts {
|
||||
case SyntaxKind.TemplateExpression:
|
||||
case SyntaxKind.NoSubstitutionTemplateLiteral:
|
||||
case SyntaxKind.OmittedExpression:
|
||||
case SyntaxKind.JsxElement:
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
case SyntaxKind.YieldExpression:
|
||||
return true;
|
||||
case SyntaxKind.QualifiedName:
|
||||
while (node.parent.kind === SyntaxKind.QualifiedName) {
|
||||
node = node.parent;
|
||||
}
|
||||
|
||||
return node.parent.kind === SyntaxKind.TypeQuery;
|
||||
case SyntaxKind.Identifier:
|
||||
if (node.parent.kind === SyntaxKind.TypeQuery) {
|
||||
@@ -929,13 +929,16 @@ namespace ts {
|
||||
return (forInStatement.initializer === node && forInStatement.initializer.kind !== SyntaxKind.VariableDeclarationList) ||
|
||||
forInStatement.expression === node;
|
||||
case SyntaxKind.TypeAssertionExpression:
|
||||
return node === (<TypeAssertion>parent).expression;
|
||||
case SyntaxKind.AsExpression:
|
||||
return node === (<AssertionExpression>parent).expression;
|
||||
case SyntaxKind.TemplateSpan:
|
||||
return node === (<TemplateSpan>parent).expression;
|
||||
case SyntaxKind.ComputedPropertyName:
|
||||
return node === (<ComputedPropertyName>parent).expression;
|
||||
case SyntaxKind.Decorator:
|
||||
return true;
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
return (<ExpressionWithTypeArguments>parent).expression === node && isExpressionWithTypeArgumentsInClassExtendsClause(parent);
|
||||
default:
|
||||
if (isExpression(parent)) {
|
||||
return true;
|
||||
@@ -1082,7 +1085,7 @@ namespace ts {
|
||||
return SyntaxKind.FirstTemplateToken <= kind && kind <= SyntaxKind.LastTemplateToken;
|
||||
}
|
||||
|
||||
export function isBindingPattern(node: Node) {
|
||||
export function isBindingPattern(node: Node): node is BindingPattern {
|
||||
return !!node && (node.kind === SyntaxKind.ArrayBindingPattern || node.kind === SyntaxKind.ObjectBindingPattern);
|
||||
}
|
||||
|
||||
@@ -1102,6 +1105,7 @@ namespace ts {
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.BindingElement:
|
||||
case SyntaxKind.ClassDeclaration:
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.EnumDeclaration:
|
||||
case SyntaxKind.EnumMember:
|
||||
@@ -1250,7 +1254,7 @@ namespace ts {
|
||||
return heritageClause && heritageClause.types.length > 0 ? heritageClause.types[0] : undefined;
|
||||
}
|
||||
|
||||
export function getClassImplementsHeritageClauseElements(node: ClassDeclaration) {
|
||||
export function getClassImplementsHeritageClauseElements(node: ClassLikeDeclaration) {
|
||||
let heritageClause = getHeritageClause(node.heritageClauses, SyntaxKind.ImplementsKeyword);
|
||||
return heritageClause ? heritageClause.types : undefined;
|
||||
}
|
||||
@@ -1551,6 +1555,11 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function isIntrinsicJsxName(name: string) {
|
||||
let ch = name.substr(0, 1);
|
||||
return ch.toLowerCase() === ch;
|
||||
}
|
||||
|
||||
function get16BitUnicodeEscapeSequence(charCode: number): string {
|
||||
let hexCharCode = charCode.toString(16).toUpperCase();
|
||||
let paddedHexCode = ("0000" + hexCharCode).slice(-4);
|
||||
@@ -1907,6 +1916,8 @@ namespace ts {
|
||||
case SyntaxKind.ElementAccessExpression:
|
||||
case SyntaxKind.NewExpression:
|
||||
case SyntaxKind.CallExpression:
|
||||
case SyntaxKind.JsxElement:
|
||||
case SyntaxKind.JsxSelfClosingElement:
|
||||
case SyntaxKind.TaggedTemplateExpression:
|
||||
case SyntaxKind.ArrayLiteralExpression:
|
||||
case SyntaxKind.ParenthesizedExpression:
|
||||
@@ -1935,6 +1946,12 @@ namespace ts {
|
||||
return token >= SyntaxKind.FirstAssignment && token <= SyntaxKind.LastAssignment;
|
||||
}
|
||||
|
||||
export function isExpressionWithTypeArgumentsInClassExtendsClause(node: Node): boolean {
|
||||
return node.kind === SyntaxKind.ExpressionWithTypeArguments &&
|
||||
(<HeritageClause>node.parent).token === SyntaxKind.ExtendsKeyword &&
|
||||
isClassLike(node.parent.parent);
|
||||
}
|
||||
|
||||
// Returns false if this heritage clause element's expression contains something unsupported
|
||||
// (i.e. not a name or dotted name).
|
||||
export function isSupportedExpressionWithTypeArguments(node: ExpressionWithTypeArguments): boolean {
|
||||
@@ -1966,6 +1983,10 @@ namespace ts {
|
||||
return fileExtensionIs(fileName, ".js");
|
||||
}
|
||||
|
||||
export function isTsx(fileName: string) {
|
||||
return fileExtensionIs(fileName, ".tsx");
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
@@ -1973,7 +1994,6 @@ namespace ts {
|
||||
function getExpandedCharCodes(input: string): number[] {
|
||||
let output: number[] = [];
|
||||
let length = input.length;
|
||||
let leadSurrogate: number = undefined;
|
||||
|
||||
for (let i = 0; i < length; i++) {
|
||||
let charCode = input.charCodeAt(i);
|
||||
@@ -2105,6 +2125,12 @@ namespace ts {
|
||||
return start <= textSpanEnd(span) && end >= span.start;
|
||||
}
|
||||
|
||||
export function decodedTextSpanIntersectsWith(start1: number, length1: number, start2: number, length2: number) {
|
||||
let end1 = start1 + length1;
|
||||
let end2 = start2 + length2;
|
||||
return start2 <= end1 && end2 >= start1;
|
||||
}
|
||||
|
||||
export function textSpanIntersectsWithPosition(span: TextSpan, position: number) {
|
||||
return position <= textSpanEnd(span) && position >= span.start;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user