-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from gitKrystan/cherry-c89b8141f7074e46bf44f7…
…bb3fb58c89c5189067
- Loading branch information
Showing
6 changed files
with
85 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import type { RawGlimmerTemplate } from '../types/glimmer'; | ||
|
||
function replaceRange( | ||
original: string, | ||
range: { start: number; end: number }, | ||
substitute: string, | ||
): string { | ||
return ( | ||
original.slice(0, range.start) + substitute + original.slice(range.end) | ||
); | ||
} | ||
|
||
/** | ||
* Replace the template with a parsable placeholder that takes up the same | ||
* range. | ||
*/ | ||
export function preprocessTemplateRange( | ||
rawTemplate: RawGlimmerTemplate, | ||
originalCode: string, | ||
currentCode: string, | ||
): string { | ||
let prefix: string; | ||
let suffix: string; | ||
|
||
if (rawTemplate.type === 'class-member') { | ||
prefix = 'static{`'; | ||
suffix = '`}'; | ||
} else { | ||
prefix = '{'; | ||
suffix = '}'; | ||
const nextWord = originalCode.slice(rawTemplate.range.end).match(/\S+/); | ||
if (nextWord && nextWord[0] === 'as') { | ||
prefix = '(' + prefix; | ||
suffix = suffix + ')'; | ||
} else if (!nextWord || ![',', ')'].includes(nextWord[0][0] || '')) { | ||
suffix += ';'; | ||
} | ||
} | ||
|
||
const totalLength = rawTemplate.range.end - rawTemplate.range.start; | ||
const placeholderLength = totalLength - prefix.length - suffix.length; | ||
const placeholder = ' '.repeat(placeholderLength); | ||
|
||
return replaceRange( | ||
currentCode, | ||
rawTemplate.range, | ||
`${prefix}${placeholder}${suffix}`, | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters