Skip to content

Attempt to fix #154 #179

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

Closed
wants to merge 1 commit into from
Closed
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 .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Place your settings in this file to overwrite default and user settings.
{
"editor.insertSpaces": true
}
}
4 changes: 2 additions & 2 deletions TypeScript.YAML-tmLanguage
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,15 @@ repository:

method-declaration:
name: meta.method.declaration.ts
begin: '\b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?\b(?:(async)\s+)?(?:(get|set)\s+)?(?:(new)|(?:\b(constructor)\b)|(?:([a-zA-Z_$][\.\w$]*)\s*(\??)))?\s*(?=\(|\<)'
begin: '\b(?:(abstract)\s+)?\b(?:(public|private|protected)\s+)?\b(?:(async)\s+)?(?:(get|set)\s+)?(?:(new)|(?:\b(constructor)\b)|(?:(\[*)(`|'|"*)(.*)(`|'|"*)(\]*)\s*(\??)))?\s*(?=\(|\<)'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still doesn't look correct. For example, the .* would eat everything including the closing quote and bracket (the test case needs to be updated for it). Also, do you need to consider if the two quotes are matching? For example, ["test'] and ['test"] shouldn't be treated the same way as the ["test"]

beginCaptures:
'1': { name: storage.modifier.ts } # captures keyword (abstract)
'2': { name: storage.modifier.ts } # captures keyword (public or private or protected)
'3': { name: storage.modifier.ts } # captures keyword (async)
'4': { name: storage.type.property.ts } # captures keyword (get|set)
'5': { name: keyword.operator.ts } # captures keyword (new)
'6': { name: storage.type.ts } # captures keyword (constructor)
'7': { name: entity.name.function.ts } # captures method name ([a-zA-Z_$][\.\w$]*)
'7': { name: entity.name.function.ts } # captures method name (\[*)(`|'|"*)(.*)(`|'|"*)(\]*)
'8': { name: keyword.operator.ts } # captures (\??)
end: '(?=\}|;|,)|(?<=\})'
patterns:
Expand Down
6 changes: 6 additions & 0 deletions tests/baselines/Issue154.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[2, 1]: source.ts meta.declaration.object.ts meta.object.body.ts meta.indexer.declaration.ts meta.brace.square.ts
[8, 1]: source.ts meta.declaration.object.ts meta.object.body.ts string.single.ts
[14, 1]: source.ts meta.declaration.object.ts meta.object.body.ts meta.indexer.declaration.ts meta.brace.square.ts
[20, 1]: source.ts meta.declaration.object.ts meta.object.body.ts string.double.ts
[26, 1]: source.ts meta.declaration.object.ts meta.object.body.ts meta.indexer.declaration.ts meta.brace.square.ts
[32, 1]: source.ts meta.declaration.object.ts meta.object.body.ts meta.method.declaration.ts entity.name.function.ts
35 changes: 35 additions & 0 deletions tests/cases/Issue154.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
class TestCase0 {
^^['123']() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should also test if the rule ends correctly. e.g.

^^['123']^^()

this.registerComponent('foo-bar');
}
}

class TestCase1 {
^^'$'() {
this.registerComponent('foo-bar');
}
}

class TestCase2 {
^^[`foo`]() {
this.registerComponent('foo-bar');
}
}

class TestCase3 {
^^"foo"() {
this.registerComponent('foo-bar');
}
}

class TestCase4 {
^^["foo"]() {
this.registerComponent('foo-bar');
}
}

class TestCase5 {
^^foo() {
this.registerComponent('foo-bar');
}
}
4 changes: 2 additions & 2 deletions tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ function addTestCase(file: string, generatedText: string, baselinesText: string)
it('should be the same', () => {
chai.expect(compareText(generatedText, baselinesText)).to.true;
})
})
}
})
}