Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(entries): use all strings for component reference graph
- Loading branch information
1 parent
d928c2c
commit 6629aa1
Showing
11 changed files
with
143 additions
and
120 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
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,58 @@ | ||
import { ComponentReference, ModuleFiles, SourceString } from '../../declarations'; | ||
|
||
|
||
export function getComponentRefsFromSourceStrings(allModuleFiles: ModuleFiles, sourceStrings: SourceString[]) { | ||
const componentRefs: ComponentReference[] = []; | ||
|
||
const tags = Object.keys(allModuleFiles) | ||
.map(filePath => allModuleFiles[filePath].cmpMeta) | ||
.filter(cmpMeta => cmpMeta && cmpMeta.tagNameMeta) | ||
.map(cmpMeta => cmpMeta.tagNameMeta); | ||
|
||
sourceStrings.forEach(src => { | ||
if (typeof src.str !== 'string') { | ||
return; | ||
} | ||
|
||
src.str = src.str.trim().toLowerCase(); | ||
|
||
if (tags.some(tag => src.str === tag)) { | ||
// exact match, we're good | ||
// probably something like h('ion-button') or | ||
// var tag = 'ion-button'; document.createElement(tag); | ||
componentRefs.push({ | ||
tag: src.str, | ||
filePath: src.filePath | ||
}); | ||
|
||
} else if (src.str.includes('<')) { | ||
// string could be HTML | ||
// could be something like elm.innerHTML = '<ion-button>'; | ||
|
||
// replace any whitespace with a ~ character | ||
// this is especially important for newlines and tabs | ||
// for tag with attributes and has a newline in the tag | ||
src.str = src.str.toLowerCase().replace(/\s/g, '~'); | ||
|
||
const foundTags = tags.filter(tag => { | ||
return src.str.includes('<' + tag + '>') || | ||
src.str.includes('</' + tag + '>') || | ||
src.str.includes('<' + tag + '~'); | ||
}); | ||
|
||
foundTags.forEach(foundTag => { | ||
componentRefs.push({ | ||
tag: foundTag, | ||
filePath: src.filePath | ||
}); | ||
}); | ||
} | ||
|
||
// just to free up memory | ||
src.str = src.filePath = null; | ||
}); | ||
|
||
sourceStrings.length = 0; | ||
|
||
return componentRefs; | ||
} |
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
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
Oops, something went wrong.