-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for extra output in generated TS declarations
Ref #11
- Loading branch information
1 parent
309f048
commit ba9128e
Showing
4 changed files
with
87 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
function parseTypescripExtras(componentString, config) { | ||
const { compiler } = config; | ||
const extras = { | ||
imports: [], | ||
props: [], | ||
instance: [], | ||
}; | ||
|
||
const regExps = [ | ||
new RegExp('/*[ ]*?phenome-dts-([a-z]*)([^\\*]*)\\*/', 'g'), | ||
new RegExp('//[ ]*?phenome-dts-([a-z]*)([^\\n]*)', 'g'), | ||
new RegExp(`/*[ ]*?phenome-${compiler}-dts-([a-z]*)([^\\*]*)\\*/`, 'g'), | ||
new RegExp(`//[ ]*?phenome-${compiler}-dts-([a-z]*)([^\\n]*)`, 'g'), | ||
]; | ||
regExps.forEach((re) => { | ||
let result; | ||
// eslint-disable-next-line | ||
while (result = re.exec(componentString)) { | ||
let type = result[1]; | ||
const data = result[2]; | ||
if (type === 'import') type = 'imports'; | ||
if (type === 'prop') type = 'props'; | ||
extras[type].push(data.trim()); | ||
} | ||
}); | ||
|
||
return extras; | ||
} | ||
module.exports = parseTypescripExtras; |
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