Skip to content

Commit

Permalink
fix(rules): proper migration of let (#11)
Browse files Browse the repository at this point in the history
* fix(rules): proper migration of let

Fix #8

* refactor: reuse PIPEABLE_OPERATOR_MAPPING
  • Loading branch information
mgechev authored Apr 18, 2018
1 parent 7d92979 commit c44252a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/migrateToPipeableOperatorsRule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,13 @@ function replaceWithPipeableOperators(
const immediateParentText = immediateParent.getText();
const identifierStart = immediateParentText.lastIndexOf('.');
const identifierText = immediateParentText.slice(identifierStart + 1);
const pipeableOperator = PIPEABLE_OPERATOR_MAPPING[identifierText] || identifierText;
operatorsToImport.add(pipeableOperator);
let pipeableOperator = PIPEABLE_OPERATOR_MAPPING[identifierText];
if (pipeableOperator === undefined) {
pipeableOperator = identifierText;
}
if (identifierText !== 'let') {
operatorsToImport.add(pipeableOperator);
}
// Generates a replacement that would replace .map with map using absolute
// position of the text to be replaced.
const operatorReplacement = Lint.Replacement.replaceFromTo(
Expand Down Expand Up @@ -454,13 +459,15 @@ const RXJS_OPERATORS = new Set([
'flatMap',
'flatMapTo',
'finally',
'switch'
'switch',
'let'
]);
/**
* Represents the mapping for pipeable version of some operators whose name has
* changed due to conflict with JavaScript keyword restrictions.
*/
const PIPEABLE_OPERATOR_MAPPING: { [key: string]: string } = {
let: '',
do: 'tap',
catch: 'catchError',
flatMap: 'mergeMap',
Expand Down

0 comments on commit c44252a

Please sign in to comment.