diff --git a/JavaScript/JSX.sublime-syntax b/JavaScript/JSX.sublime-syntax index 4f6f87f7da..3c3c1b667c 100644 --- a/JavaScript/JSX.sublime-syntax +++ b/JavaScript/JSX.sublime-syntax @@ -24,7 +24,7 @@ variables: contexts: expression-begin: - meta_prepend: true - - include: jsx-tag-hack + - include: jsx-tag jsx-interpolation: - match: (?={/\*) @@ -67,9 +67,6 @@ contexts: - meta_scope: meta.jsx.js - include: immediately-pop - jsx-tag-hack: # Ugly hack so that TSX can un-include this in expression-begin - - include: jsx-tag - jsx-tag: - match: <(?=\s*[/>{{jsx_tag_name_start}}]) scope: punctuation.definition.tag.begin.js diff --git a/JavaScript/TSX.sublime-syntax b/JavaScript/TSX.sublime-syntax index 7d79e0c90a..3941e5e75f 100644 --- a/JavaScript/TSX.sublime-syntax +++ b/JavaScript/TSX.sublime-syntax @@ -17,15 +17,23 @@ first_line_match: |- ) contexts: - branch-possible-arrow-function: - - meta_prepend: true - - include: jsx-tag - jsx-tag-hack: [] + ts-old-type-assertion: + # old type assertions are replaced by JSX tags + - match: < + scope: punctuation.definition.tag.begin.js + set: + - jsx-meta + - jsx-tag-begin + + jsx-tag: [] # replaced by `ts-old-type-assertion` jsx-tag-begin: - meta_include_prototype: false - meta_scope: meta.tag.js + # note: type parameter modifiers indicate generic lambda + - match: (?=(?:in|out|const){{identifier_break}}) + fail: arrow-function - match: / scope: punctuation.definition.tag.begin.js set: diff --git a/JavaScript/tests/syntax_test_tsx.tsx b/JavaScript/tests/syntax_test_tsx.tsx index 60ca310b3e..eaea6df57a 100644 --- a/JavaScript/tests/syntax_test_tsx.tsx +++ b/JavaScript/tests/syntax_test_tsx.tsx @@ -232,6 +232,84 @@ if (a < b || c <= d) {} // ^ meta.tag.name entity.name.tag // ^ punctuation.terminator.statement + () => {}; // ; +// ^^^^^^^^^ meta.function meta.generic - meta.function meta.function +// ^^ meta.function.parameters - meta.function meta.function +// ^^^^^^ meta.function - meta.function meta.function +// ^ punctuation.definition.generic.begin +// ^^^^^ storage.modifier.const +// ^ variable.parameter.generic +// ^ punctuation.definition.generic.end +// ^ punctuation.section.group.begin +// ^ punctuation.section.group.end +// ^^ keyword.declaration.function.arrow +// ^^ meta.block +// ^ punctuation.section.block.begin +// ^ punctuation.section.block.end +// ^ punctuation.terminator.statement +// ^^^^^^^^ comment.line.double-slash +// ^^ punctuation.definition.comment + + () => {}; // ; +// ^^^^^^^^^^^^^^^^^ meta.function meta.generic - meta.function meta.function +// ^^ meta.function.parameters - meta.function meta.function +// ^^^^^^ meta.function - meta.function meta.function +// ^ punctuation.definition.generic.begin +// ^^^^^ storage.modifier.const +// ^ variable.parameter.generic +// ^^^^^^^ storage.modifier.extends +// ^ punctuation.definition.generic.end +// ^ punctuation.section.group.begin +// ^ punctuation.section.group.end +// ^^ keyword.declaration.function.arrow +// ^^ meta.block +// ^ punctuation.section.block.begin +// ^ punctuation.section.block.end +// ^ punctuation.terminator.statement +// ^^^^^^^^ comment.line.double-slash +// ^^ punctuation.definition.comment + + () => {x}; // ; +// ^^^^^^^^^^^^^^^^^^^^^ meta.function meta.generic - meta.function meta.function +// ^^ meta.function.parameters - meta.function meta.function +// ^^^^^^^ meta.function - meta.function meta.function +// ^ punctuation.definition.generic.begin +// ^^^^^ storage.modifier.const +// ^ variable.parameter.generic +// ^^^^^^^ storage.modifier.extends +// ^^^ meta.string string.quoted.double +// ^ punctuation.definition.generic.end +// ^ punctuation.section.group.begin +// ^ punctuation.section.group.end +// ^^ keyword.declaration.function.arrow +// ^^^ meta.block +// ^ punctuation.section.block.begin +// ^ punctuation.section.block.end +// ^ punctuation.terminator.statement +// ^^^^^^^^ comment.line.double-slash +// ^^ punctuation.definition.comment + + () => {x}; // ; +// ^^^^^^^^^^^^^^^^^^^^^ meta.function meta.generic - meta.function meta.function +// ^^ meta.function.parameters - meta.function meta.function +// ^^^^^^ meta.function - meta.function meta.function +// ^ punctuation.definition.generic.begin +// ^^^^^ storage.modifier.const +// ^ variable.parameter.generic +// ^^^^^^^ storage.modifier.extends +// ^ keyword.operator.assignment.js +// ^^^ meta.string string.quoted.double +// ^ punctuation.definition.generic.end +// ^ punctuation.section.group.begin +// ^ punctuation.section.group.end +// ^^ keyword.declaration.function.arrow +// ^^^ meta.block +// ^ punctuation.section.block.begin +// ^ punctuation.section.block.end +// ^ punctuation.terminator.statement +// ^^^^^^^^ comment.line.double-slash +// ^^ punctuation.definition.comment + () => {};; // ^^^^^^^^^^^^^^^^^^^^^^ meta.jsx // ^^^^^^^^^ meta.tag diff --git a/JavaScript/tests/syntax_test_typescript.ts b/JavaScript/tests/syntax_test_typescript.ts index 318712df38..6e28541b3c 100644 --- a/JavaScript/tests/syntax_test_typescript.ts +++ b/JavaScript/tests/syntax_test_typescript.ts @@ -1247,12 +1247,66 @@ let x: (this: any) => any; let x: < T > ( ... foo : any ) => any; // ^^^^^ meta.generic +// ^ punctuation.definition.generic.begin // ^ variable.parameter.generic +// ^ punctuation.definition.generic.end // ^^^^^^^^^^^^^^^^^ meta.group +// ^ punctuation.section.group.begin // ^^^ keyword.operator.spread // ^^^ variable.parameter // ^ punctuation.separator.type // ^^^ support.type.any +// ^ punctuation.section.group.end +// ^^ keyword.declaration.function +// ^^^ support.type.any + +let x: < const T > ( ... foo : any ) => any; +// ^^^^^^^^^^^ meta.generic +// ^ punctuation.definition.generic.begin +// ^^^^^ storage.modifier.const +// ^ variable.parameter.generic +// ^ punctuation.definition.generic.end +// ^^^^^^^^^^^^^^^^^ meta.group +// ^ punctuation.section.group.begin +// ^^^ keyword.operator.spread +// ^^^ variable.parameter +// ^ punctuation.separator.type +// ^^^ support.type.any +// ^ punctuation.section.group.end +// ^^ keyword.declaration.function +// ^^^ support.type.any + +let x: < in T > ( ... foo : any ) => any; +// ^^^^^^^^ meta.generic +// ^ punctuation.definition.generic.begin +// ^^ storage.modifier.variance +// ^ variable.parameter.generic +// ^ punctuation.definition.generic.end +// ^^^^^^^^^^^^^^^^^ meta.group +// ^ punctuation.section.group.begin +// ^^^ keyword.operator.spread +// ^^^ variable.parameter +// ^ punctuation.separator.type +// ^^^ support.type.any +// ^ punctuation.section.group.end +// ^^ keyword.declaration.function +// ^^^ support.type.any + +let x: < out T > ( ... foo : any ) => any; +// ^^^^^^^^^ meta.generic +// ^ punctuation.definition.generic.begin +// ^^^ storage.modifier.variance +// ^ variable.parameter.generic +// ^ punctuation.definition.generic.end +// ^^^^^^^^^^^^^^^^^ meta.group +// ^ punctuation.section.group.begin +// ^^^ keyword.operator.spread +// ^^^ variable.parameter +// ^ punctuation.separator.type +// ^^^ support.type.any +// ^ punctuation.section.group.end +// ^^ keyword.declaration.function +// ^^^ support.type.any let x: () => T U @@ -1360,6 +1414,16 @@ let x: T.U []; //<- meta.sequence - meta.type + foo != bar +// ^^^ variable.other.readwrite +// ^^ keyword.operator.comparison +// ^^^ variable.other.readwrite + + foo < bar +// ^^^ variable.other.readwrite +// ^ keyword.operator.comparison +// ^^^ variable.other.readwrite + foo < bar > (); // ^^^ variable.function // ^^^^^^^ meta.generic @@ -1368,12 +1432,6 @@ let x: T.U // ^ punctuation.definition.generic.end // ^^ meta.group - foo < bar -// ^^^ variable.other.readwrite -// ^ keyword.operator.comparison -// ^^^ variable.other.readwrite - ; - new Foo; // ^^^ keyword.operator.word.new // ^^^ variable.other.constant @@ -1420,8 +1478,71 @@ const f = >() => {}; // ^^ keyword.declaration.function.arrow // ^^ meta.block - a != b; -// ^^ keyword.operator.comparison +const f = () => foo; +// ^^^^^^^^^ meta.function meta.generic - meta.function meta.function +// ^^ meta.function.parameters - meta.function meta.function +// ^^^^^^^ meta.function - meta.function meta.function +// ^ punctuation.definition.generic.begin +// ^^^^^ storage.modifier.const +// ^ variable.parameter.generic +// ^ punctuation.definition.generic.end +// ^ punctuation.section.group.begin +// ^ punctuation.section.group.end +// ^^ keyword.declaration.function.arrow +// ^^^ meta.block variable.other.readwrite +// ^ punctuation.terminator.statement + +const f = (a: T,): T => foo; +// ^^^^^^^^^ meta.function meta.generic - meta.function meta.function +// ^^^^^^^ meta.function.parameters - meta.function meta.function +// ^ meta.function - meta.type - meta.function meta.function +// ^^^ meta.function meta.type - meta.function meta.function +// ^^^^^^ meta.function - meta.type - meta.function meta.function +// ^ punctuation.definition.generic.begin +// ^^^^^ storage.modifier.const +// ^ variable.parameter.generic +// ^ punctuation.definition.generic.end +// ^ punctuation.section.group.begin +// ^ variable.parameter.function +// ^ punctuation.separator.type +// ^^ meta.type +// ^ support.class +// ^ punctuation.separator.parameter.function +// ^ punctuation.section.group.end +// ^ punctuation.separator.type +// ^ support.class +// ^^ keyword.declaration.function.arrow +// ^^^ meta.block variable.other.readwrite +// ^ punctuation.terminator.statement + +const f = (a: T,): X => foo; +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.js meta.generic.js +// ^^^^^^^ meta.function.parameters - meta.function meta.function +// ^ meta.function - meta.type - meta.function meta.function +// ^^^ meta.function meta.type - meta.function meta.function +// ^^^^^^ meta.function - meta.type - meta.function meta.function +// ^ punctuation.definition.generic.begin +// ^^^^^ storage.modifier.const +// ^ variable.parameter.generic +// ^^^^^^^ storage.modifier.extends +// ^^^ support.class +// ^ punctuation.separator.comma +// ^ variable.parameter.generic +// ^^^^^^^ storage.modifier.extends +// ^^^ support.class +// ^ punctuation.definition.generic.end +// ^ punctuation.section.group.begin +// ^ meta.binding.name variable.parameter.function +// ^ punctuation.separator.type +// ^^ meta.type +// ^ support.class +// ^ punctuation.separator.parameter.function +// ^ punctuation.section.group.end +// ^ punctuation.separator.type +// ^ support.class +// ^^ keyword.declaration.function.arrow +// ^^^ meta.block variable.other.readwrite +// ^ punctuation.terminator.statement const x = { readonly: true,