Skip to content

Commit e1c9d28

Browse files
committed
Merge pull request #3564 from RyanCavanaugh/jsxAndAs
JSX and `as` operator
2 parents 591a0db + 3402f35 commit e1c9d28

File tree

244 files changed

+9571
-171
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

244 files changed

+9571
-171
lines changed

Diff for: src/compiler/checker.ts

+562-21
Large diffs are not rendered by default.

Diff for: src/compiler/commandLineParser.ts

+27-6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ namespace ts {
3838
name: "inlineSources",
3939
type: "boolean",
4040
},
41+
{
42+
name: "jsx",
43+
type: {
44+
"preserve": JsxEmit.Preserve,
45+
"react": JsxEmit.React
46+
},
47+
paramType: Diagnostics.KIND,
48+
description: Diagnostics.Specify_JSX_code_generation_Colon_preserve_or_react,
49+
error: Diagnostics.Argument_for_jsx_must_be_preserve_or_react
50+
},
4151
{
4252
name: "listFiles",
4353
type: "boolean",
@@ -401,18 +411,29 @@ namespace ts {
401411
}
402412

403413
function getFileNames(): string[] {
404-
var fileNames: string[] = [];
414+
let fileNames: string[] = [];
405415
if (hasProperty(json, "files")) {
406416
if (json["files"] instanceof Array) {
407417
fileNames = map(<string[]>json["files"], s => combinePaths(basePath, s));
408418
}
409419
}
410420
else {
411-
var exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;
412-
var sysFiles = host.readDirectory(basePath, ".ts", exclude);
413-
for (var i = 0; i < sysFiles.length; i++) {
414-
var name = sysFiles[i];
415-
if (!fileExtensionIs(name, ".d.ts") || !contains(sysFiles, name.substr(0, name.length - 5) + ".ts")) {
421+
let exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;
422+
let sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude));
423+
for (let i = 0; i < sysFiles.length; i++) {
424+
let name = sysFiles[i];
425+
if (fileExtensionIs(name, ".d.ts")) {
426+
let baseName = name.substr(0, name.length - ".d.ts".length);
427+
if (!contains(sysFiles, baseName + ".tsx") && !contains(sysFiles, baseName + ".ts")) {
428+
fileNames.push(name);
429+
}
430+
}
431+
else if (fileExtensionIs(name, ".ts")) {
432+
if (!contains(sysFiles, name + "x")) {
433+
fileNames.push(name)
434+
}
435+
}
436+
else {
416437
fileNames.push(name);
417438
}
418439
}

Diff for: src/compiler/core.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,9 @@ namespace ts {
702702
/**
703703
* List of supported extensions in order of file resolution precedence.
704704
*/
705-
export const supportedExtensions = [".ts", ".d.ts"];
705+
export const supportedExtensions = [".tsx", ".ts", ".d.ts"];
706706

707-
const extensionsToRemove = [".d.ts", ".ts", ".js"];
707+
const extensionsToRemove = [".d.ts", ".ts", ".js", ".tsx", ".jsx"];
708708
export function removeFileExtension(path: string): string {
709709
for (let ext of extensionsToRemove) {
710710
if (fileExtensionIs(path, ext)) {

Diff for: src/compiler/diagnosticInformationMap.generated.ts

+20
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,16 @@ namespace ts {
382382
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." },
383383
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." },
384384
Base_constructors_must_all_have_the_same_return_type: { code: 2510, category: DiagnosticCategory.Error, key: "Base constructors must all have the same return type." },
385+
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." },
386+
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." },
387+
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." },
388+
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}'" },
389+
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." },
390+
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." },
391+
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." },
392+
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" },
393+
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" },
394+
Cannot_emit_namespaced_JSX_elements_in_React: { code: 2650, category: DiagnosticCategory.Error, key: "Cannot emit namespaced JSX elements in React" },
385395
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
386396
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}'." },
387397
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}'." },
@@ -523,6 +533,8 @@ namespace ts {
523533
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)." },
524534
NEWLINE: { code: 6061, category: DiagnosticCategory.Message, key: "NEWLINE" },
525535
Argument_for_newLine_option_must_be_CRLF_or_LF: { code: 6062, category: DiagnosticCategory.Error, key: "Argument for '--newLine' option must be 'CRLF' or 'LF'." },
536+
Specify_JSX_code_generation_Colon_preserve_or_react: { code: 6080, category: DiagnosticCategory.Message, key: "Specify JSX code generation: 'preserve' or 'react'" },
537+
Argument_for_jsx_must_be_preserve_or_react: { code: 6081, category: DiagnosticCategory.Message, key: "Argument for '--jsx' must be 'preserve' or 'react'." },
526538
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." },
527539
Enables_experimental_support_for_ES7_decorators: { code: 6065, category: DiagnosticCategory.Message, key: "Enables experimental support for ES7 decorators." },
528540
Enables_experimental_support_for_emitting_type_metadata_for_decorators: { code: 6066, category: DiagnosticCategory.Message, key: "Enables experimental support for emitting type metadata for decorators." },
@@ -542,6 +554,7 @@ namespace ts {
542554
_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." },
543555
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." },
544556
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." },
557+
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" },
545558
You_cannot_rename_this_element: { code: 8000, category: DiagnosticCategory.Error, key: "You cannot rename this element." },
546559
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." },
547560
import_can_only_be_used_in_a_ts_file: { code: 8002, category: DiagnosticCategory.Error, key: "'import ... =' can only be used in a .ts file." },
@@ -559,5 +572,12 @@ namespace ts {
559572
enum_declarations_can_only_be_used_in_a_ts_file: { code: 8015, category: DiagnosticCategory.Error, key: "'enum declarations' can only be used in a .ts file." },
560573
type_assertion_expressions_can_only_be_used_in_a_ts_file: { code: 8016, category: DiagnosticCategory.Error, key: "'type assertion expressions' can only be used in a .ts file." },
561574
decorators_can_only_be_used_in_a_ts_file: { code: 8017, category: DiagnosticCategory.Error, key: "'decorators' can only be used in a .ts file." },
575+
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." },
576+
class_expressions_are_not_currently_supported: { code: 9003, category: DiagnosticCategory.Error, key: "'class' expressions are not currently supported." },
577+
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'." },
578+
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." },
579+
Expected_corresponding_JSX_closing_tag_for_0: { code: 17002, category: DiagnosticCategory.Error, key: "Expected corresponding JSX closing tag for '{0}'." },
580+
JSX_attribute_expected: { code: 17003, category: DiagnosticCategory.Error, key: "JSX attribute expected." },
581+
Cannot_use_JSX_unless_the_jsx_flag_is_provided: { code: 17004, category: DiagnosticCategory.Error, key: "Cannot use JSX unless the '--jsx' flag is provided." },
562582
};
563583
}

Diff for: src/compiler/diagnosticMessages.json

+89-5
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@
638638
"Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning.": {
639639
"category": "Error",
640640
"code": 1219
641-
},
641+
},
642642
"Generators are only available when targeting ECMAScript 6 or higher.": {
643643
"category": "Error",
644644
"code": 1220
@@ -1519,6 +1519,47 @@
15191519
"code": 2510
15201520
},
15211521

1522+
"JSX element attributes type '{0}' must be an object type.": {
1523+
"category": "Error",
1524+
"code": 2600
1525+
},
1526+
"The return type of a JSX element constructor must return an object type.": {
1527+
"category": "Error",
1528+
"code": 2601
1529+
},
1530+
"JSX element implicitly has type 'any' because the global type 'JSX.Element' does not exist.": {
1531+
"category": "Error",
1532+
"code": 2602
1533+
},
1534+
"Property '{0}' in type '{1}' is not assignable to type '{2}'": {
1535+
"category": "Error",
1536+
"code": 2603
1537+
},
1538+
"JSX element type '{0}' does not have any construct or call signatures.": {
1539+
"category": "Error",
1540+
"code": 2604
1541+
},
1542+
"JSX element type '{0}' is not a constructor function for JSX elements.": {
1543+
"category": "Error",
1544+
"code": 2605
1545+
},
1546+
"Property '{0}' of JSX spread attribute is not assignable to target property.": {
1547+
"category": "Error",
1548+
"code": 2606
1549+
},
1550+
"JSX element class does not support attributes because it does not have a '{0}' property": {
1551+
"category": "Error",
1552+
"code": 2607
1553+
},
1554+
"The global type 'JSX.{0}' may not have more than one property": {
1555+
"category": "Error",
1556+
"code": 2608
1557+
},
1558+
"Cannot emit namespaced JSX elements in React": {
1559+
"category": "Error",
1560+
"code": 2650
1561+
},
1562+
15221563
"Import declaration '{0}' is using private name '{1}'.": {
15231564
"category": "Error",
15241565
"code": 4000
@@ -1887,7 +1928,7 @@
18871928
"category": "Error",
18881929
"code": 5050
18891930
},
1890-
"Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.": {
1931+
"Option 'inlineSources' can only be used when either option '--inlineSourceMap' or option '--sourceMap' is provided.": {
18911932
"category": "Error",
18921933
"code": 5051
18931934
},
@@ -2076,14 +2117,22 @@
20762117
"category": "Message",
20772118
"code": 6060
20782119
},
2079-
"NEWLINE": {
2080-
"category": "Message",
2120+
"NEWLINE": {
2121+
"category": "Message",
20812122
"code": 6061
20822123
},
20832124
"Argument for '--newLine' option must be 'CRLF' or 'LF'.": {
2084-
"category": "Error",
2125+
"category": "Error",
20852126
"code": 6062
20862127
},
2128+
"Specify JSX code generation: 'preserve' or 'react'": {
2129+
"category": "Message",
2130+
"code": 6080
2131+
},
2132+
"Argument for '--jsx' must be 'preserve' or 'react'.": {
2133+
"category": "Message",
2134+
"code": 6081
2135+
},
20872136
"Option 'experimentalDecorators' must also be specified when option 'emitDecoratorMetadata' is specified.": {
20882137
"category": "Error",
20892138
"code": 6064
@@ -2161,6 +2210,12 @@
21612210
"category": "Error",
21622211
"code": 7025
21632212
},
2213+
"JSX element implicitly has type 'any' because no interface 'JSX.{0}' exists": {
2214+
"category": "Error",
2215+
"code": 7026
2216+
},
2217+
2218+
21642219
"You cannot rename this element.": {
21652220
"category": "Error",
21662221
"code": 8000
@@ -2228,5 +2283,34 @@
22282283
"'decorators' can only be used in a .ts file.": {
22292284
"category": "Error",
22302285
"code": 8017
2286+
},
2287+
2288+
"Only identifiers/qualified-names with optional type arguments are currently supported in a class 'extends' clauses.": {
2289+
"category": "Error",
2290+
"code": 9002
2291+
},
2292+
"'class' expressions are not currently supported.": {
2293+
"category": "Error",
2294+
"code": 9003
2295+
},
2296+
"JSX attributes must only be assigned a non-empty 'expression'.": {
2297+
"category": "Error",
2298+
"code": 17000
2299+
},
2300+
"JSX elements cannot have multiple attributes with the same name.": {
2301+
"category": "Error",
2302+
"code": 17001
2303+
},
2304+
"Expected corresponding JSX closing tag for '{0}'.": {
2305+
"category": "Error",
2306+
"code": 17002
2307+
},
2308+
"JSX attribute expected.": {
2309+
"category": "Error",
2310+
"code": 17003
2311+
},
2312+
"Cannot use JSX unless the '--jsx' flag is provided.": {
2313+
"category": "Error",
2314+
"code": 17004
22312315
}
22322316
}

0 commit comments

Comments
 (0)