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

Incorrect TypeScript conversion #23

Open
charlesr1971 opened this issue Feb 15, 2024 · 1 comment
Open

Incorrect TypeScript conversion #23

charlesr1971 opened this issue Feb 15, 2024 · 1 comment

Comments

@charlesr1971
Copy link

charlesr1971 commented Feb 15, 2024

import { createSelector } from '@ngrx/store';
export const selectShoppingCartItems = createSelector(
(state) => state.shoppingCart,
(shoppingCart) => shoppingCart.items
);
export const selectTotalItems = createSelector{
selectShoppingCartItems,
(items) => items.length
};

This is converted to:

import { createSelector } from '@ngrx/store';
export const selectShoppingCartItems = createSelector(
	(state) => state.shoppingCart,
		(shoppingCart) => shoppingCart.items
);
export const selectTotalItems = createSelector{
	selectShoppingCartItems,
	(items) => items.length
};

And here is the solution:

{
      $languages: "js",
      $name: "=",
      $excludeIf: [HTML_TAG_RULES],
      $startPatterns: [/=/],
      $endPatterns: [/[,;\)\]}]/, NEW_LINE_REGEX]
},

To:

{
      $languages: "js",
      $name: "=",
      $excludeIf: [HTML_TAG_RULES],
      $startPatterns: [/=(?!>)/],
      $endPatterns: [/[,;\)\]}]/, NEW_LINE_REGEX]
},
@charlesr1971
Copy link
Author

charlesr1971 commented Feb 15, 2024

And you need to add a new rule for typescript generics:

{
      $languages: "js",
      $name: "typescript-generics",
      $startPatterns: [/(?<!\w<)<[\w\s,]+(?=>)/i],
      $endPatterns: [/>/],
      $indent: true,
      $consumeEndMatch: true
},

This ensures that it will match the TypeScript Generic, below:

import { Subject } from 'rxjs';
const subject = new Subject()<string>;
const subscription = subject.subscribe(data => {
    console.log(data);
});
subject.next('Hello');
subject.next('World');
subscription.unsubscribe();

But won't match the less than operator, below:

var c,i,l,quitchars;
quitchars=['q','Q'];
charloop:while(c=getc()){
  for (i=0; i < quitchars.length; i++){
    if (c == quitchars[i]) break charloop;
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant