Skip to content

Commit 536ca78

Browse files
fix: dynamic import then. (#32)
1 parent d9ceac2 commit 536ca78

File tree

5 files changed

+21
-4
lines changed

5 files changed

+21
-4
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@knighted/specifier",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"description": "Node.js tool for updating your ES module and CommonJS specifiers.",
55
"type": "module",
66
"main": "dist",

src/format.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ const format = async (src: string, ast: ParseResult, cb: Callback) => {
164164
}
165165
}
166166

167+
if (
168+
node.type === 'MemberExpression' &&
169+
node.object.type === 'ImportExpression' &&
170+
node.property.type === 'Identifier' &&
171+
node.property.name === 'then'
172+
) {
173+
formatExpression(node.object)
174+
}
175+
167176
if (node.type === 'TSImportType') {
168177
const { argument } = node
169178

test/__fixtures__/complexImportExpression.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ const bar = () => {
2222
}
2323

2424
(() => import('./code.js'))()
25+
26+
const importOther = () => {
27+
import(`./code.js`).then((mod) => {});
28+
}
29+
30+
const importOtherOther = () => {
31+
import(`./code.js`)
32+
}

test/update.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ describe('update', () => {
8989
)
9090

9191
assert.ok(update.indexOf('./other-user.js') > -1)
92-
assert.equal([...update.matchAll(/other-code\.js/g)].length, 3)
92+
assert.equal([...update.matchAll(/other-code\.js/g)].length, 5)
9393
})
9494

9595
it('works with typescript', async () => {

0 commit comments

Comments
 (0)