Skip to content

Commit

Permalink
Adding type operators satisfies and as (rouge-ruby#2014)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunoia committed May 13, 2024
1 parent 2aac611 commit 9266cbd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rouge/lexers/javascript.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def self.detect?(text)

def self.keywords
@keywords ||= Set.new %w(
as async await break case catch continue debugger default delete
async await break case catch continue debugger default delete
do else export finally from for if import in instanceof new of
return super switch this throw try typeof void while yield
)
Expand Down
9 changes: 9 additions & 0 deletions lib/rouge/lexers/typescript/common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ def self.extended(base)
base.prepend :root do
rule %r/[?][.]/, base::Punctuation
rule %r/[?]{2}/, base::Operator

# Positive Examples:
# const cat = { name: "Garfield" } satisfies Person;
# import {something as thingy} from 'module'
# export { foo as default }
# ...spreadOperator as const;
# Negative Example:
# cy.get('kitten').as('friend')
rule %r{(?<![_$[:alnum:]])(?:(?<=\.\.\.)|(?<!\.))(?:(as)|(satisfies))\s+}, base::Keyword::Declaration
end

base.prepend :statement do
Expand Down
17 changes: 17 additions & 0 deletions spec/visual/samples/typescript
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,23 @@ declare var foo: Foo;
export = foo;
export { foo as default }

cy.get('input').as('text')

cy
.get('input')
.as('text')

import {something as thingy} from 'module'

const applicant = {
myInfo: "John",
myOtherInfo: { id: 123, age: 22 },
} satisfies Person;

const properties = (value.features[0].properties as moreDetails)

...spreadOperator as const;

declare module "foo" {
export interface IFoo {
theObject: any;
Expand Down

0 comments on commit 9266cbd

Please sign in to comment.