Skip to content

Commit

Permalink
[JavaScript] Rename TypeScript to TSX, add proper TypeScript syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
wbond committed Sep 18, 2020
1 parent 01ebaf4 commit ec091f8
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion JavaScript/JSX.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: JSX
file_extensions:
- jsx
scope: source.jsx
extends: Packages/JavaScript/JavaScript.sublime-syntax
extends: JavaScript.sublime-syntax

variables:
jsx_identifier_part: (?:{{identifier_part}}|-)
Expand Down
10 changes: 10 additions & 0 deletions JavaScript/TSX.sublime-syntax
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
%YAML 1.2
---
version: 2
name: TSX
file_extensions:
- tsx
scope: source.tsx
extends:
- JSX.sublime-syntax
- TypeScript.sublime-syntax
2 changes: 1 addition & 1 deletion JavaScript/TypeScript.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ name: TypeScript
file_extensions:
- ts
scope: source.ts
extends: Packages/JavaScript/JSX.sublime-syntax
extends: JavaScript.sublime-syntax

variables:
dot_accessor: (?:[?!]?\.)
Expand Down
25 changes: 25 additions & 0 deletions JavaScript/tests/syntax_test_tsx.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SYNTAX TEST "Packages/JavaScript/TSX.sublime-syntax"

<foo />;
// ^^^^^^^ meta.jsx meta.tag
// ^ punctuation.definition.tag.begin
// ^^^ meta.tag.name entity.name.tag
// ^^ punctuation.definition.tag.end

type x < T = Foo > = any;
// ^^^^^^^^^^^^^^^^^^^^^^^^ meta.type-alias
// ^^^^ storage.type
// ^ entity.name.type
// ^^^^^^^^^^^ meta.generic
// ^ punctuation.definition.generic.begin
// ^ variable.parameter.generic
// ^ keyword.operator.assignment
// ^^^ support.class
// ^ punctuation.definition.generic.end
// ^ keyword.operator.assignment
// ^^^ meta.type-alias support.type.any

// This is invalid TSX as the TypeScript type assertion is parsed as a JSX tag
let strLength: number = (<string>someValue).length; // </string>
// ^^^^^^^^ meta.tag - meta.assertion
// ^^^^^^^^^ meta.tag - comment
4 changes: 4 additions & 0 deletions JavaScript/tests/syntax_test_typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,10 @@ x as const;
// ^ keyword.operator.type
// ^ punctuation.terminator.statement

// This is a type assertion that is incompatible with JSX
let strLength: number = (<string>someValue).length; // </string>
// ^^^^^^^^ meta.assertion - meta.tag
// ^^^^^^^^^ comment - meta.tag

/* Types */

Expand Down

0 comments on commit ec091f8

Please sign in to comment.