Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(syntaxes): Allow syntaxes to work in tsx files #2046

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion syntaxes/inline-styles.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scopeName": "inline-styles.ng",
"injectionSelector": "L:source.ts#meta.decorator.ts -comment",
"injectionSelector": "L:(source.ts#meta.decorator.ts | source.tsx#meta.decorator.tsx) -comment",
"patterns": [
{
"include": "#inlineStyles"
Expand Down
2 changes: 1 addition & 1 deletion syntaxes/inline-template.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"scopeName": "inline-template.ng",
"injectionSelector": "L:meta.decorator.ts -comment -text.html",
"injectionSelector": "L:(meta.decorator.ts | meta.decorator.tsx) -comment -text.html",
"patterns": [
{
"include": "#inlineTemplate"
Expand Down
2 changes: 1 addition & 1 deletion syntaxes/src/inline-styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {GrammarDefinition} from './types';

export const InlineStyles: GrammarDefinition = {
scopeName: 'inline-styles.ng',
injectionSelector: 'L:source.ts#meta.decorator.ts -comment',
injectionSelector: 'L:(source.ts#meta.decorator.ts | source.tsx#meta.decorator.tsx) -comment',
patterns: [{include: '#inlineStyles'}],
repository: {
inlineStyles: {
Expand Down
2 changes: 1 addition & 1 deletion syntaxes/src/inline-template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {GrammarDefinition} from './types';

export const InlineTemplate: GrammarDefinition = {
scopeName: 'inline-template.ng',
injectionSelector: 'L:meta.decorator.ts -comment -text.html',
injectionSelector: 'L:(meta.decorator.ts | meta.decorator.tsx) -comment -text.html',
patterns: [{include: '#inlineTemplate'}],
repository: {
inlineTemplate: {
Expand Down
7 changes: 7 additions & 0 deletions syntaxes/test/cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ export const cases = [
['syntaxes/inline-template.json', 'syntaxes/template.json', 'syntaxes/expression.json'],
'testFile': 'syntaxes/test/data/inline-template.ts'
},
{
'name': 'inline template tsx',
'scopeName': 'inline-template.ng',
'grammarFiles':
['syntaxes/inline-template.json', 'syntaxes/template.json', 'syntaxes/expression.json'],
'testFile': 'syntaxes/test/data/inline-template.tsx'
},
{
'name': 'inline styles',
'scopeName': 'inline-styles.ng',
Expand Down
32 changes: 32 additions & 0 deletions syntaxes/test/data/inline-template.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* clang-format off */

/* Inline template recognition tests */
@Component({
//// Property key/value test
template: '<div></div>',

//// String delimiter tests
template: `<div></div>`,
template: "<div></div>",
template: '<div></div>',

//// Parenthesization tests
template: ( (( '<div></div>' )) ),

//// Comments tests
// template: '<div></div>'
/*
* template: '<div></div>'
*/
/**
* template: '<div></div>'
*/
})
export class TMComponent{}

/* Template syntax tests */
@Component({
// Interpolation test
template: '{{property}}',
})
export class TMComponent{}
120 changes: 120 additions & 0 deletions syntaxes/test/data/inline-template.tsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
>/* clang-format off */
#^^^^^^^^^^^^^^^^^^^^^^^ inline-template.ng
>
>/* Inline template recognition tests */
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline-template.ng
>@Component({
#^^^^^^^^^^^^^ inline-template.ng
> //// Property key/value test
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline-template.ng
> template: '<div></div>',
#^^ inline-template.ng
# ^^^^^^^^ inline-template.ng meta.object-literal.key.ts
# ^ inline-template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
# ^ inline-template.ng
# ^ inline-template.ng string
# ^^^^^^^^^^^ inline-template.ng text.html
# ^ inline-template.ng string
# ^^ inline-template.ng
>
> //// String delimiter tests
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline-template.ng
> template: `<div></div>`,
#^^ inline-template.ng
# ^^^^^^^^ inline-template.ng meta.object-literal.key.ts
# ^ inline-template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
# ^ inline-template.ng
# ^ inline-template.ng string
# ^^^^^^^^^^^ inline-template.ng text.html
# ^ inline-template.ng string
# ^^ inline-template.ng
> template: "<div></div>",
#^^ inline-template.ng
# ^^^^^^^^ inline-template.ng meta.object-literal.key.ts
# ^ inline-template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
# ^ inline-template.ng
# ^ inline-template.ng string
# ^^^^^^^^^^^ inline-template.ng text.html
# ^ inline-template.ng string
# ^^ inline-template.ng
> template: '<div></div>',
#^^ inline-template.ng
# ^^^^^^^^ inline-template.ng meta.object-literal.key.ts
# ^ inline-template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
# ^ inline-template.ng
# ^ inline-template.ng string
# ^^^^^^^^^^^ inline-template.ng text.html
# ^ inline-template.ng string
# ^^ inline-template.ng
>
> //// Parenthesization tests
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline-template.ng
> template: ( (( '<div></div>' )) ),
#^^ inline-template.ng
# ^^^^^^^^ inline-template.ng meta.object-literal.key.ts
# ^ inline-template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
# ^ inline-template.ng
# ^ inline-template.ng meta.brace.round.ts
# ^ inline-template.ng
# ^ inline-template.ng meta.brace.round.ts
# ^ inline-template.ng meta.brace.round.ts
# ^ inline-template.ng
# ^ inline-template.ng string
# ^^^^^^^^^^^ inline-template.ng text.html
# ^ inline-template.ng string
# ^ inline-template.ng
# ^ inline-template.ng meta.brace.round.ts
# ^ inline-template.ng meta.brace.round.ts
# ^ inline-template.ng
# ^ inline-template.ng meta.brace.round.ts
# ^^ inline-template.ng
>
> //// Comments tests
#^^^^^^^^^^^^^^^^^^^^^^ inline-template.ng
> // template: '<div></div>'
#^^^^^ inline-template.ng
# ^^^^^^^^ inline-template.ng meta.object-literal.key.ts
# ^ inline-template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
# ^ inline-template.ng
# ^ inline-template.ng string
# ^^^^^^^^^^^ inline-template.ng text.html
# ^ inline-template.ng string
> /*
#^^^^^ inline-template.ng
> * template: '<div></div>'
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline-template.ng
> */
#^^^^^^ inline-template.ng
> /**
#^^^^^^ inline-template.ng
> * template: '<div></div>'
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline-template.ng
> */
#^^^^^^ inline-template.ng
>})
#^^^ inline-template.ng
>export class TMComponent{}
#^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline-template.ng
>
>/* Template syntax tests */
#^^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline-template.ng
>@Component({
#^^^^^^^^^^^^^ inline-template.ng
> // Interpolation test
#^^^^^^^^^^^^^^^^^^^^^^^^ inline-template.ng
> template: '{{property}}',
#^^ inline-template.ng
# ^^^^^^^^ inline-template.ng meta.object-literal.key.ts
# ^ inline-template.ng meta.object-literal.key.ts punctuation.separator.key-value.ts
# ^ inline-template.ng
# ^ inline-template.ng string
# ^^ inline-template.ng text.html punctuation.definition.block.ts
# ^^^^^^^^ inline-template.ng text.html expression.ng variable.other.readwrite.ts
# ^^ inline-template.ng text.html punctuation.definition.block.ts
# ^ inline-template.ng string
# ^^ inline-template.ng
>})
#^^^ inline-template.ng
>export class TMComponent{}
#^^^^^^^^^^^^^^^^^^^^^^^^^^^ inline-template.ng
>
Loading