Skip to content

Commit

Permalink
Handle aliased, destructured imports in patch script (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
daogrady authored Sep 12, 2024
1 parent fd00005 commit e6e386c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions .github/rollup-patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ function _getImports (src) {
if (what.includes('{')) {
destructured.push({
package: from.trim(),
properties: what.replace('{','').replace('}','').split(',').map(p => p.trim())
properties: what
.replace('{','')
.replace('}','')
.split(',')
.map(p => {
const tokens = p.trim().split(' as ')
return {
property: tokens[0],
alias: tokens[1] ?? tokens[0]
}
})
})
} else {
named.push({
Expand Down Expand Up @@ -63,8 +73,8 @@ function replaceImports (src) {
// v
// x: import('foo').bar
for (const { package, properties } of destructured) {
for (const prop of properties) {
lines = lines.map(l => replace(l, re(prop), `import('${package}').${prop}`))
for (const { alias, property } of properties) {
lines = lines.map(l => replace(l, re(alias), `import('${package}').${property}`))
}
}
return lines.join('\n')
Expand Down

0 comments on commit e6e386c

Please sign in to comment.